mirror of
https://github.com/clementine-player/Clementine
synced 2025-02-01 20:06:53 +01:00
Sort items in the library model that don't have track/disc information in a more deterministic way
This commit is contained in:
parent
18f95c205c
commit
a21b7541e5
@ -333,8 +333,6 @@ QVariant LibraryModel::data(const LibraryItem* item, int role) const {
|
||||
return item->metadata.artist();
|
||||
|
||||
case Role_SortText:
|
||||
if (item->type == LibraryItem::Type_Song)
|
||||
return item->metadata.disc() * 1000 + item->metadata.track();
|
||||
return item->SortText();
|
||||
}
|
||||
return QVariant();
|
||||
@ -534,6 +532,7 @@ LibraryItem* LibraryModel::ItemFromQuery(GroupBy type,
|
||||
item->metadata.InitFromQuery(q);
|
||||
item->key = item->metadata.title();
|
||||
item->display_text = item->metadata.PrettyTitleWithArtist();
|
||||
item->sort_text = SortTextForSong(item->metadata);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -581,6 +580,7 @@ LibraryItem* LibraryModel::ItemFromSong(GroupBy type,
|
||||
item->metadata = s;
|
||||
item->key = s.title();
|
||||
item->display_text = s.PrettyTitleWithArtist();
|
||||
item->sort_text = SortTextForSong(s);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -659,6 +659,13 @@ QString LibraryModel::SortTextForYear(int year) const {
|
||||
return QString("0").repeated(qMax(0, 4 - str.length())) + str;
|
||||
}
|
||||
|
||||
QString LibraryModel::SortTextForSong(const Song& song) const {
|
||||
QString ret = QString::number(song.disc() * 1000 + song.track());
|
||||
ret.prepend(QString("0").repeated(6 - ret.length()));
|
||||
ret.append(song.filename());
|
||||
return ret;
|
||||
}
|
||||
|
||||
Qt::ItemFlags LibraryModel::flags(const QModelIndex& index) const {
|
||||
switch (IndexToItem(index)->type) {
|
||||
case LibraryItem::Type_Song:
|
||||
|
@ -154,6 +154,7 @@ class LibraryModel : public SimpleTreeModel<LibraryItem> {
|
||||
QString SortText(QString text) const;
|
||||
QString SortTextForArtist(QString artist) const;
|
||||
QString SortTextForYear(int year) const;
|
||||
QString SortTextForSong(const Song& song) const;
|
||||
|
||||
QString DividerKey(GroupBy type, LibraryItem* item) const;
|
||||
QString DividerDisplayText(GroupBy type, const QString& key) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user