Skip to content

Commit 81741b7

Browse files
committed
Add track count to Tracks item in sidebar"
1 parent 6d8fde5 commit 81741b7

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/library/librarytablemodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,8 @@ TrackModel::Capabilities LibraryTableModel::getCapabilities() const {
101101
Capability::Properties |
102102
Capability::Sorting;
103103
}
104+
105+
void LibraryTableModel::select() {
106+
BaseSqlTableModel::select();
107+
emit updateTrackCount();
108+
}

src/library/librarytablemodel.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ class LibraryTableModel : public BaseSqlTableModel {
1616
// number of successful additions.
1717
int addTracks(const QModelIndex& index, const QList<QString>& locations) final;
1818
TrackModel::Capabilities getCapabilities() const final;
19+
20+
void select() override;
21+
22+
signals:
23+
void updateTrackCount();
1924
};

src/library/mixxxlibraryfeature.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ MixxxLibraryFeature::MixxxLibraryFeature(Library* pLibrary,
3232
m_pLibraryTableModel(nullptr),
3333
m_pSidebarModel(make_parented<TreeItemModel>(this)),
3434
m_pMissingView(nullptr),
35-
m_pHiddenView(nullptr) {
35+
m_pHiddenView(nullptr),
36+
m_trackCount{0} {
3637
QString idColumn = LIBRARYTABLE_ID;
3738
QStringList columns = {
3839
LIBRARYTABLE_ID,
@@ -114,6 +115,11 @@ MixxxLibraryFeature::MixxxLibraryFeature(Library* pLibrary,
114115
pLibrary->trackCollectionManager(),
115116
"mixxx.db.model.library");
116117

118+
connect(m_pLibraryTableModel,
119+
&LibraryTableModel::updateTrackCount,
120+
this,
121+
&MixxxLibraryFeature::slotUpdateTrackCount);
122+
117123
std::unique_ptr<TreeItem> pRootItem = TreeItem::newRoot(this);
118124
pRootItem->appendChild(kMissingTitle);
119125
pRootItem->appendChild(kHiddenTitle);
@@ -149,7 +155,8 @@ void MixxxLibraryFeature::bindLibraryWidget(WLibrary* pLibraryWidget,
149155
}
150156

151157
QVariant MixxxLibraryFeature::title() {
152-
return tr("Tracks");
158+
const QString title = tr("Tracks") + QStringLiteral(" (%1)").arg(m_trackCount);
159+
return title;
153160
}
154161

155162
TreeItemModel* MixxxLibraryFeature::sidebarModel() const {
@@ -183,6 +190,14 @@ void MixxxLibraryFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
183190
}
184191
#endif
185192

193+
void MixxxLibraryFeature::slotUpdateTrackCount() {
194+
m_trackCount = m_pLibraryTableModel->rowCount();
195+
196+
// Force updating the Tracks sidebar item.
197+
// `select` must be false as we don't want to select again
198+
emit featureIsLoading(this, false);
199+
}
200+
186201
void MixxxLibraryFeature::activate() {
187202
//qDebug() << "MixxxLibraryFeature::activate()";
188203
emit saveModelState();

src/library/mixxxlibraryfeature.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class MixxxLibraryFeature final : public LibraryFeature {
5050
public slots:
5151
void activate() override;
5252
void activateChild(const QModelIndex& index) override;
53+
void slotUpdateTrackCount();
5354
#ifdef __ENGINEPRIME__
5455
void onRightClick(const QPoint& globalPos) override;
5556
#endif
@@ -74,6 +75,8 @@ class MixxxLibraryFeature final : public LibraryFeature {
7475
DlgMissing* m_pMissingView;
7576
DlgHidden* m_pHiddenView;
7677

78+
int m_trackCount;
79+
7780
#ifdef __ENGINEPRIME__
7881
parented_ptr<QAction> m_pExportLibraryAction;
7982

0 commit comments

Comments
 (0)