From d53bcde897b56d5376bdd60ae59830ef8d1ccce8 Mon Sep 17 00:00:00 2001 From: GitAnt Date: Mon, 16 Dec 2013 19:18:02 +0100 Subject: [PATCH 1/2] Consistently added GroupBy_Bitrate enum item --- .gitignore | 1 + src/globalsearch/globalsearchmodel.cpp | 4 ++++ src/library/librarymodel.cpp | 30 ++++++++++++++++++++++++++ src/library/librarymodel.h | 1 + 4 files changed, 36 insertions(+) diff --git a/.gitignore b/.gitignore index b19838473..e7e7164c8 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.dll *.exe *.pyd +build/ 3rdparty/libprojectm/config.inp 3rdparty/libprojectm/libprojectM.pc CMakeLists.txt.user diff --git a/src/globalsearch/globalsearchmodel.cpp b/src/globalsearch/globalsearchmodel.cpp index d1433b228..c422e2aa5 100644 --- a/src/globalsearch/globalsearchmodel.cpp +++ b/src/globalsearch/globalsearchmodel.cpp @@ -145,8 +145,12 @@ QStandardItem* GlobalSearchModel::BuildContainers( sort_text = display_text; break; + case LibraryModel::GroupBy_Bitrate: + return parent; + case LibraryModel::GroupBy_None: return parent; + } // Find a container for this level diff --git a/src/library/librarymodel.cpp b/src/library/librarymodel.cpp index 9bd919522..d2d334d8f 100644 --- a/src/library/librarymodel.cpp +++ b/src/library/librarymodel.cpp @@ -190,6 +190,9 @@ void LibraryModel::SongsDiscovered(const SongList& songs) { case GroupBy_YearAlbum: key = PrettyYearAlbum(qMax(0, song.year()), song.album()); break; case GroupBy_FileType: key = song.filetype(); break; + case GroupBy_Bitrate: + qLog(Error) << "GroupBy_Bitrate"; + break; case GroupBy_None: qLog(Error) << "GroupBy_None"; break; @@ -280,6 +283,9 @@ QString LibraryModel::DividerKey(GroupBy type, LibraryItem* item) const { case GroupBy_YearAlbum: return SortTextForYear(item->metadata.year()); + case GroupBy_Bitrate: + return QString(); + case GroupBy_None: return QString(); } @@ -313,6 +319,10 @@ QString LibraryModel::DividerDisplayText(GroupBy type, const QString& key) const return tr("Unknown"); return QString::number(key.toInt()); // To remove leading 0s + case GroupBy_Bitrate: + // fallthrough + ; + case GroupBy_None: // fallthrough ; @@ -739,6 +749,9 @@ void LibraryModel::InitQuery(GroupBy type, LibraryQuery* q) { case GroupBy_AlbumArtist: q->SetColumnSpec("DISTINCT effective_albumartist"); break; + case GroupBy_Bitrate: + q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec); + break; case GroupBy_None: q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec); break; @@ -796,6 +809,9 @@ void LibraryModel::FilterQuery(GroupBy type, LibraryItem* item, LibraryQuery* q) case GroupBy_FileType: q->AddWhere("filetype", item->metadata.filetype()); break; + case GroupBy_Bitrate: + qLog(Error) << "Unknown GroupBy type" << type << "used in filter"; + break; case GroupBy_None: qLog(Error) << "Unknown GroupBy type" << type << "used in filter"; break; @@ -863,6 +879,13 @@ LibraryItem* LibraryModel::ItemFromQuery(GroupBy type, item->key = item->metadata.TextForFiletype(); break; + case GroupBy_Bitrate: + item->metadata.InitFromQuery(row, true); + item->key = item->metadata.title(); + item->display_text = item->metadata.TitleWithCompilationArtist(); + item->sort_text = SortTextForSong(item->metadata); + break; + case GroupBy_None: item->metadata.InitFromQuery(row, true); item->key = item->metadata.title(); @@ -918,6 +941,13 @@ LibraryItem* LibraryModel::ItemFromSong(GroupBy type, item->key = s.TextForFiletype(); break; + case GroupBy_Bitrate: + item->metadata = s; + item->key = s.title(); + item->display_text = s.TitleWithCompilationArtist(); + item->sort_text = SortTextForSong(s); + break; + case GroupBy_None: item->metadata = s; item->key = s.title(); diff --git a/src/library/librarymodel.h b/src/library/librarymodel.h index b2ad18443..5ec113b06 100644 --- a/src/library/librarymodel.h +++ b/src/library/librarymodel.h @@ -82,6 +82,7 @@ class LibraryModel : public SimpleTreeModel { GroupBy_FileType = 8, GroupBy_Performer = 9, GroupBy_Grouping = 10, + GroupBy_Bitrate = 11, }; struct Grouping { From a39e5594251c0c7a9bd9f240db38124ad4693d45 Mon Sep 17 00:00:00 2001 From: GitAnt Date: Tue, 17 Dec 2013 16:07:20 +0100 Subject: [PATCH 2/2] Implemented sort by bitrate --- src/globalsearch/globalsearchmodel.cpp | 4 ++- src/library/groupbydialog.cpp | 5 ++-- src/library/groupbydialog.ui | 15 +++++++++++ src/library/librarymodel.cpp | 37 +++++++++++++++----------- src/library/librarymodel.h | 1 + 5 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/globalsearch/globalsearchmodel.cpp b/src/globalsearch/globalsearchmodel.cpp index c422e2aa5..4408fa4c3 100644 --- a/src/globalsearch/globalsearchmodel.cpp +++ b/src/globalsearch/globalsearchmodel.cpp @@ -146,7 +146,9 @@ QStandardItem* GlobalSearchModel::BuildContainers( break; case LibraryModel::GroupBy_Bitrate: - return parent; + display_text = QString(s.bitrate(), 1); + sort_text = display_text; + break; case LibraryModel::GroupBy_None: return parent; diff --git a/src/library/groupbydialog.cpp b/src/library/groupbydialog.cpp index eea1dd448..74d17ffb2 100644 --- a/src/library/groupbydialog.cpp +++ b/src/library/groupbydialog.cpp @@ -36,8 +36,9 @@ GroupByDialog::GroupByDialog(QWidget *parent) mapping_.insert(Mapping(LibraryModel::GroupBy_Genre, 6)); mapping_.insert(Mapping(LibraryModel::GroupBy_Year, 7)); mapping_.insert(Mapping(LibraryModel::GroupBy_YearAlbum, 8)); - mapping_.insert(Mapping(LibraryModel::GroupBy_Performer, 9)); - mapping_.insert(Mapping(LibraryModel::GroupBy_Grouping, 10)); + mapping_.insert(Mapping(LibraryModel::GroupBy_Bitrate, 9)); + mapping_.insert(Mapping(LibraryModel::GroupBy_Performer, 10)); + mapping_.insert(Mapping(LibraryModel::GroupBy_Grouping, 11)); connect(ui_->button_box->button(QDialogButtonBox::Reset), SIGNAL(clicked()), SLOT(Reset())); diff --git a/src/library/groupbydialog.ui b/src/library/groupbydialog.ui index d33ed6139..fd6c5f853 100644 --- a/src/library/groupbydialog.ui +++ b/src/library/groupbydialog.ui @@ -88,6 +88,11 @@ Year - Album + + + Bitrate + + @@ -144,6 +149,11 @@ Year - Album + + + Bitrate + + @@ -200,6 +210,11 @@ Year - Album + + + Bitrate + + diff --git a/src/library/librarymodel.cpp b/src/library/librarymodel.cpp index d2d334d8f..6db78f4db 100644 --- a/src/library/librarymodel.cpp +++ b/src/library/librarymodel.cpp @@ -190,9 +190,7 @@ void LibraryModel::SongsDiscovered(const SongList& songs) { case GroupBy_YearAlbum: key = PrettyYearAlbum(qMax(0, song.year()), song.album()); break; case GroupBy_FileType: key = song.filetype(); break; - case GroupBy_Bitrate: - qLog(Error) << "GroupBy_Bitrate"; - break; + case GroupBy_Bitrate: key = song.bitrate(); break; case GroupBy_None: qLog(Error) << "GroupBy_None"; break; @@ -284,7 +282,7 @@ QString LibraryModel::DividerKey(GroupBy type, LibraryItem* item) const { return SortTextForYear(item->metadata.year()); case GroupBy_Bitrate: - return QString(); + return SortTextForBitrate(item->metadata.bitrate()); case GroupBy_None: return QString(); @@ -320,8 +318,9 @@ QString LibraryModel::DividerDisplayText(GroupBy type, const QString& key) const return QString::number(key.toInt()); // To remove leading 0s case GroupBy_Bitrate: - // fallthrough - ; + if (key == "000") + return tr("Unknown"); + return QString::number(key.toInt()); // To remove leading 0s case GroupBy_None: // fallthrough @@ -750,7 +749,7 @@ void LibraryModel::InitQuery(GroupBy type, LibraryQuery* q) { q->SetColumnSpec("DISTINCT effective_albumartist"); break; case GroupBy_Bitrate: - q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec); + q->SetColumnSpec("DISTINCT bitrate"); break; case GroupBy_None: q->SetColumnSpec("%songs_table.ROWID, " + Song::kColumnSpec); @@ -810,7 +809,7 @@ void LibraryModel::FilterQuery(GroupBy type, LibraryItem* item, LibraryQuery* q) q->AddWhere("filetype", item->metadata.filetype()); break; case GroupBy_Bitrate: - qLog(Error) << "Unknown GroupBy type" << type << "used in filter"; + q->AddWhere("bitrate", item->key); break; case GroupBy_None: qLog(Error) << "Unknown GroupBy type" << type << "used in filter"; @@ -841,6 +840,7 @@ LibraryItem* LibraryModel::ItemFromQuery(GroupBy type, int container_level) { LibraryItem* item = InitItem(type, signal, parent, container_level); int year = 0; + int bitrate = 0; switch (type) { case GroupBy_Artist: @@ -880,10 +880,9 @@ LibraryItem* LibraryModel::ItemFromQuery(GroupBy type, break; case GroupBy_Bitrate: - item->metadata.InitFromQuery(row, true); - item->key = item->metadata.title(); - item->display_text = item->metadata.TitleWithCompilationArtist(); - item->sort_text = SortTextForSong(item->metadata); + bitrate = qMax(0, row.value(0).toInt()); + item->key = QString::number(bitrate); + item->sort_text = SortTextForBitrate(bitrate) + " "; break; case GroupBy_None: @@ -904,6 +903,7 @@ LibraryItem* LibraryModel::ItemFromSong(GroupBy type, int container_level) { LibraryItem* item = InitItem(type, signal, parent, container_level); int year = 0; + int bitrate = 0; switch (type) { case GroupBy_Artist: @@ -942,10 +942,9 @@ LibraryItem* LibraryModel::ItemFromSong(GroupBy type, break; case GroupBy_Bitrate: - item->metadata = s; - item->key = s.title(); - item->display_text = s.TitleWithCompilationArtist(); - item->sort_text = SortTextForSong(s); + bitrate = qMax(0, s.bitrate()); + item->key = QString::number(bitrate); + item->sort_text = SortTextForBitrate(bitrate) + " "; break; case GroupBy_None: @@ -1034,6 +1033,12 @@ QString LibraryModel::SortTextForYear(int year) { return QString("0").repeated(qMax(0, 4 - str.length())) + str; } +QString LibraryModel::SortTextForBitrate(int bitrate) { + QString str = QString::number(bitrate); + return QString("0").repeated(qMax(0, 3 - str.length())) + str; +} + + QString LibraryModel::SortTextForSong(const Song& song) { QString ret = QString::number(qMax(0, song.disc()) * 1000 + qMax(0, song.track())); ret.prepend(QString("0").repeated(6 - ret.length())); diff --git a/src/library/librarymodel.h b/src/library/librarymodel.h index 5ec113b06..79a105327 100644 --- a/src/library/librarymodel.h +++ b/src/library/librarymodel.h @@ -160,6 +160,7 @@ class LibraryModel : public SimpleTreeModel { static QString SortText(QString text); static QString SortTextForArtist(QString artist); static QString SortTextForYear(int year); + static QString SortTextForBitrate(int bitrate); static QString SortTextForSong(const Song& song); signals: