diff --git a/src/library/librarytablemodel.cpp b/src/library/librarytablemodel.cpp index 4ed18d3c2dc8..3c3bf4b2dc5d 100644 --- a/src/library/librarytablemodel.cpp +++ b/src/library/librarytablemodel.cpp @@ -101,3 +101,8 @@ TrackModel::Capabilities LibraryTableModel::getCapabilities() const { Capability::Properties | Capability::Sorting; } + +void LibraryTableModel::select() { + BaseSqlTableModel::select(); + emit updateTrackCount(); +} diff --git a/src/library/librarytablemodel.h b/src/library/librarytablemodel.h index b5a6c359cbad..299e4f42de06 100644 --- a/src/library/librarytablemodel.h +++ b/src/library/librarytablemodel.h @@ -16,4 +16,9 @@ class LibraryTableModel : public BaseSqlTableModel { // number of successful additions. int addTracks(const QModelIndex& index, const QList& locations) final; TrackModel::Capabilities getCapabilities() const final; + + void select() override; + + signals: + void updateTrackCount(); }; diff --git a/src/library/mixxxlibraryfeature.cpp b/src/library/mixxxlibraryfeature.cpp index 519f80f86790..e449c5304c34 100644 --- a/src/library/mixxxlibraryfeature.cpp +++ b/src/library/mixxxlibraryfeature.cpp @@ -32,7 +32,8 @@ MixxxLibraryFeature::MixxxLibraryFeature(Library* pLibrary, m_pLibraryTableModel(nullptr), m_pSidebarModel(make_parented(this)), m_pMissingView(nullptr), - m_pHiddenView(nullptr) { + m_pHiddenView(nullptr), + m_trackCount{0} { QString idColumn = LIBRARYTABLE_ID; QStringList columns = { LIBRARYTABLE_ID, @@ -114,6 +115,11 @@ MixxxLibraryFeature::MixxxLibraryFeature(Library* pLibrary, pLibrary->trackCollectionManager(), "mixxx.db.model.library"); + connect(m_pLibraryTableModel, + &LibraryTableModel::updateTrackCount, + this, + &MixxxLibraryFeature::slotUpdateTrackCount); + std::unique_ptr pRootItem = TreeItem::newRoot(this); pRootItem->appendChild(kMissingTitle); pRootItem->appendChild(kHiddenTitle); @@ -149,7 +155,8 @@ void MixxxLibraryFeature::bindLibraryWidget(WLibrary* pLibraryWidget, } QVariant MixxxLibraryFeature::title() { - return tr("Tracks"); + const QString title = tr("Tracks") + QStringLiteral(" (%1)").arg(m_trackCount); + return title; } TreeItemModel* MixxxLibraryFeature::sidebarModel() const { @@ -183,6 +190,14 @@ void MixxxLibraryFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) { } #endif +void MixxxLibraryFeature::slotUpdateTrackCount() { + m_trackCount = m_pLibraryTableModel->rowCount(); + + // Force updating the Tracks sidebar item. + // `select` must be false as we don't want to select again + emit featureIsLoading(this, false); +} + void MixxxLibraryFeature::activate() { //qDebug() << "MixxxLibraryFeature::activate()"; emit saveModelState(); diff --git a/src/library/mixxxlibraryfeature.h b/src/library/mixxxlibraryfeature.h index 50eb06258a7c..69f4da83fefe 100644 --- a/src/library/mixxxlibraryfeature.h +++ b/src/library/mixxxlibraryfeature.h @@ -50,6 +50,7 @@ class MixxxLibraryFeature final : public LibraryFeature { public slots: void activate() override; void activateChild(const QModelIndex& index) override; + void slotUpdateTrackCount(); #ifdef __ENGINEPRIME__ void onRightClick(const QPoint& globalPos) override; #endif @@ -74,6 +75,8 @@ class MixxxLibraryFeature final : public LibraryFeature { DlgMissing* m_pMissingView; DlgHidden* m_pHiddenView; + int m_trackCount; + #ifdef __ENGINEPRIME__ parented_ptr m_pExportLibraryAction;