From 4d904c5ca79ad9b3c41197eb892337e9be1bd11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 21 Jul 2019 12:26:17 +0200 Subject: [PATCH 01/17] use auto and a const iterator in BasePlaylistFeature::slotTrackSelected() --- src/library/baseplaylistfeature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index f67bf4c267f..81f26fd35df 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -708,8 +708,8 @@ void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) { // Set all playlists the track is in bold (or if there is no track selected, // clear all the bolding). int row = 0; - for (QList >::const_iterator it = m_playlistList.begin(); - it != m_playlistList.end(); ++it, ++row) { + for (auto it = m_playlistList.constBegin(); + it != m_playlistList.constEnd(); ++it, ++row) { TreeItem* playlist = rootItem->child(row); if (playlist == nullptr) { continue; From 8dcd5cb1589985cf489765c154af9c0d2e09f18a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 21 Jul 2019 15:43:20 +0200 Subject: [PATCH 02/17] Don't emit a slot --- src/library/setlogfeature.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index 9577aae9a5a..387bf1679c9 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -37,7 +37,7 @@ SetlogFeature::SetlogFeature(QObject* parent, connect(m_pGetNewPlaylist, SIGNAL(triggered()), this, SLOT(slotGetNewPlaylist())); // initialized in a new generic slot(get new history playlist purpose) - emit(slotGetNewPlaylist()); + slotGetNewPlaylist(); } SetlogFeature::~SetlogFeature() { From 57636ce021a96d5ccaffe42efee6f824a599e55f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 21 Jul 2019 20:01:53 +0200 Subject: [PATCH 03/17] Introduce a updatePlaylistList() function to avoid to read the whole playlist table on every update. This fixes lp1837315. --- src/library/baseplaylistfeature.cpp | 9 ++++---- src/library/baseplaylistfeature.h | 1 + src/library/playlistfeature.cpp | 35 +++++++++++++++++++++++++++++ src/library/playlistfeature.h | 5 +++-- src/library/setlogfeature.cpp | 27 ++++++++++++++++++++++ src/library/setlogfeature.h | 5 +++-- 6 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 81f26fd35df..808b0b02a53 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -650,8 +650,10 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { return m_childModel.index(selected_row, 0); } -void BasePlaylistFeature::updateChildModel(int selected_id) { - buildPlaylistList(); +void BasePlaylistFeature::updateChildModel(int playlistId) { + // the following call fetches whole m_playlistList. + // Anything may have change due to a concurrent Mixxx instance. + updatePlaylistList(playlistId); int row = 0; for (QList >::const_iterator it = m_playlistList.begin(); @@ -659,13 +661,12 @@ void BasePlaylistFeature::updateChildModel(int selected_id) { int playlist_id = it->first; QString playlist_name = it->second; - if (selected_id == playlist_id) { + if (playlistId == playlist_id) { TreeItem* item = m_childModel.getItem(indexFromPlaylistId(playlist_id)); item->setLabel(playlist_name); item->setData(playlist_id); decorateChild(item, playlist_id); } - } } diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 4b8583cc22d..4a2b4ae1ed7 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -71,6 +71,7 @@ class BasePlaylistFeature : public LibraryFeature { virtual void updateChildModel(int selected_id); virtual void clearChildModel(); virtual void buildPlaylistList() = 0; + virtual void updatePlaylistList(int playlist_id) = 0; virtual void decorateChild(TreeItem *pChild, int playlist_id) = 0; virtual void addToAutoDJ(bool bTop); diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 4f636f8ceaf..c656d4a5186 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -177,6 +177,41 @@ void PlaylistFeature::buildPlaylistList() { } } +void PlaylistFeature::updatePlaylistList(int playlist_id) { + // Setup the sidebar playlist model + QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); + playlistTableModel.setTable("PlaylistsCountsDurations"); + QString filter = "id=" + QString::number(playlist_id); + playlistTableModel.setFilter(filter); + playlistTableModel.select(); + while (playlistTableModel.canFetchMore()) { + playlistTableModel.fetchMore(); + } + QSqlRecord record = playlistTableModel.record(); + int nameColumn = record.indexOf("name"); + int countColumn = record.indexOf("count"); + int durationColumn = record.indexOf("durationSeconds"); + + for (int row = 0; row < playlistTableModel.rowCount(); ++row) { + QString name = playlistTableModel.data( + playlistTableModel.index(row, nameColumn)).toString(); + int count = playlistTableModel.data( + playlistTableModel.index(row, countColumn)).toInt(); + int duration = playlistTableModel.data( + playlistTableModel.index(row, durationColumn)).toInt(); + for (auto it = m_playlistList.begin(); + it != m_playlistList.end(); ++it) { + if (it->first == playlist_id) { + it->second = QString("%1 (%2) %3").arg(name, + QString::number(count), + mixxx::Duration::formatSeconds(duration)); + break; + } + } + break; + } +} + void PlaylistFeature::decorateChild(TreeItem* item, int playlist_id) { if (m_playlistDao.isPlaylistLocked(playlist_id)) { item->setIcon(QIcon(":/images/library/ic_library_locked_tracklist.svg")); diff --git a/src/library/playlistfeature.h b/src/library/playlistfeature.h index a32548b53f5..15e5ff56372 100644 --- a/src/library/playlistfeature.h +++ b/src/library/playlistfeature.h @@ -40,8 +40,9 @@ class PlaylistFeature : public BasePlaylistFeature { void slotPlaylistTableRenamed(int playlistId, QString a_strName); protected: - void buildPlaylistList(); - void decorateChild(TreeItem *pChild, int playlist_id); + void buildPlaylistList() override; + void updatePlaylistList(int playlist_id) override; + void decorateChild(TreeItem *pChild, int playlist_id) override; private: QString getRootViewHtml() const; diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index 387bf1679c9..d37fbcb34bb 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -145,6 +145,33 @@ void SetlogFeature::buildPlaylistList() { } } +void SetlogFeature::updatePlaylistList(int playlist_id) { + // Setup the sidebar playlist model + QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); + playlistTableModel.setTable("Playlists"); + QString filter = "id=" + QString::number(playlist_id); + playlistTableModel.setFilter(filter); + playlistTableModel.select(); + while (playlistTableModel.canFetchMore()) { + playlistTableModel.fetchMore(); + } + QSqlRecord record = playlistTableModel.record(); + int nameColumn = record.indexOf("name"); + + for (int row = 0; row < playlistTableModel.rowCount(); ++row) { + QString name = playlistTableModel.data( + playlistTableModel.index(row, nameColumn)).toString(); + for (auto it = m_playlistList.begin(); + it != m_playlistList.end(); ++it) { + if (it->first == playlist_id) { + it->second = name; + break; + } + } + break; + } +} + void SetlogFeature::decorateChild(TreeItem* item, int playlist_id) { if (playlist_id == m_playlistId) { item->setIcon(QIcon(":/images/library/ic_library_history_current.svg")); diff --git a/src/library/setlogfeature.h b/src/library/setlogfeature.h index 386ab0bd3f9..718243a5051 100644 --- a/src/library/setlogfeature.h +++ b/src/library/setlogfeature.h @@ -33,8 +33,9 @@ class SetlogFeature : public BasePlaylistFeature { void slotGetNewPlaylist(); protected: - void buildPlaylistList(); - void decorateChild(TreeItem *pChild, int playlist_id); + void buildPlaylistList() override; + void updatePlaylistList(int playlist_id) override; + void decorateChild(TreeItem *pChild, int playlist_id) override; private slots: void slotPlayingTrackChanged(TrackPointer currentPlayingTrack); From 3498726228460e637202e1ea750597defae24197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 21 Jul 2019 20:46:34 +0200 Subject: [PATCH 04/17] Replace DEBUG_ASSERT by VERIFY_OR_DEBUG_ASSERT just to be sure. --- src/library/treeitem.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/library/treeitem.cpp b/src/library/treeitem.cpp index 6736909b266..cec92c468f8 100644 --- a/src/library/treeitem.cpp +++ b/src/library/treeitem.cpp @@ -57,7 +57,9 @@ int TreeItem::parentRow() const { TreeItem* TreeItem::child(int row) const { DEBUG_ASSERT(row >= 0); - DEBUG_ASSERT(row < m_children.size()); + VERIFY_OR_DEBUG_ASSERT(row < m_children.size()) { + return nullptr; + } return m_children[row]; } From a0b263fe2ebc5d789de9c89d492a2e71af4f3144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Mon, 22 Jul 2019 00:07:54 +0200 Subject: [PATCH 05/17] fix some naming and code duplication issues --- src/library/baseplaylistfeature.cpp | 6 ++-- src/library/baseplaylistfeature.h | 2 +- src/library/playlistfeature.cpp | 53 +++++++++++++++++------------ src/library/playlistfeature.h | 2 +- src/library/setlogfeature.cpp | 8 ++--- src/library/setlogfeature.h | 2 +- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 808b0b02a53..ed60da3aac8 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -650,10 +650,10 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { return m_childModel.index(selected_row, 0); } -void BasePlaylistFeature::updateChildModel(int playlistId) { +void BasePlaylistFeature::updateChildModel(int changedPlaylistId) { // the following call fetches whole m_playlistList. // Anything may have change due to a concurrent Mixxx instance. - updatePlaylistList(playlistId); + reloadPlaylistInPlaylistList(changedPlaylistId); int row = 0; for (QList >::const_iterator it = m_playlistList.begin(); @@ -661,7 +661,7 @@ void BasePlaylistFeature::updateChildModel(int playlistId) { int playlist_id = it->first; QString playlist_name = it->second; - if (playlistId == playlist_id) { + if (changedPlaylistId == playlist_id) { TreeItem* item = m_childModel.getItem(indexFromPlaylistId(playlist_id)); item->setLabel(playlist_name); item->setData(playlist_id); diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 4a2b4ae1ed7..c97d3dd79f1 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -71,7 +71,7 @@ class BasePlaylistFeature : public LibraryFeature { virtual void updateChildModel(int selected_id); virtual void clearChildModel(); virtual void buildPlaylistList() = 0; - virtual void updatePlaylistList(int playlist_id) = 0; + virtual void reloadPlaylistInPlaylistList(int playlist_id) = 0; virtual void decorateChild(TreeItem *pChild, int playlist_id) = 0; virtual void addToAutoDJ(bool bTop); diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index c656d4a5186..8f83a033183 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -19,6 +19,28 @@ #include "util/dnd.h" #include "util/duration.h" +namespace { + +QString createPlaylistLable( + const QSqlTableModel& playlistTableModel, + int row, + int nameColumn, + int countColumn, + int durationColumn) { + QString name = playlistTableModel.data( + playlistTableModel.index(row, nameColumn)).toString(); + int count = playlistTableModel.data( + playlistTableModel.index(row, countColumn)).toInt(); + int duration = playlistTableModel.data( + playlistTableModel.index(row, durationColumn)).toInt(); + return QString("%1 (%2) %3").arg(name, QString::number(count), + mixxx::Duration::formatSeconds(duration)); +} + + +} + + PlaylistFeature::PlaylistFeature(QObject* parent, TrackCollection* pTrackCollection, UserSettingsPointer pConfig) @@ -164,20 +186,13 @@ void PlaylistFeature::buildPlaylistList() { for (int row = 0; row < playlistTableModel.rowCount(); ++row) { int id = playlistTableModel.data( - playlistTableModel.index(row, idColumn)).toInt(); - QString name = playlistTableModel.data( - playlistTableModel.index(row, nameColumn)).toString(); - int count = playlistTableModel.data( - playlistTableModel.index(row, countColumn)).toInt(); - int duration = playlistTableModel.data( - playlistTableModel.index(row, durationColumn)).toInt(); - m_playlistList.append(qMakePair(id, QString("%1 (%2) %3") - .arg(name, QString::number(count), - mixxx::Duration::formatSeconds(duration)))); + playlistTableModel.index(row, idColumn)).toInt(); + m_playlistList.append(qMakePair(id, createPlaylistLable( + playlistTableModel, row, nameColumn, countColumn, durationColumn))); } } -void PlaylistFeature::updatePlaylistList(int playlist_id) { +void PlaylistFeature::reloadPlaylistInPlaylistList(int playlist_id) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("PlaylistsCountsDurations"); @@ -192,23 +207,17 @@ void PlaylistFeature::updatePlaylistList(int playlist_id) { int countColumn = record.indexOf("count"); int durationColumn = record.indexOf("durationSeconds"); - for (int row = 0; row < playlistTableModel.rowCount(); ++row) { - QString name = playlistTableModel.data( - playlistTableModel.index(row, nameColumn)).toString(); - int count = playlistTableModel.data( - playlistTableModel.index(row, countColumn)).toInt(); - int duration = playlistTableModel.data( - playlistTableModel.index(row, durationColumn)).toInt(); + DEBUG_ASSERT(playlistTableModel.rowCount() <= 1); + if (playlistTableModel.rowCount() > 0) { for (auto it = m_playlistList.begin(); it != m_playlistList.end(); ++it) { if (it->first == playlist_id) { - it->second = QString("%1 (%2) %3").arg(name, - QString::number(count), - mixxx::Duration::formatSeconds(duration)); + it->second = createPlaylistLable( + playlistTableModel, 0, nameColumn, + countColumn, durationColumn); break; } } - break; } } diff --git a/src/library/playlistfeature.h b/src/library/playlistfeature.h index 15e5ff56372..b8212dae406 100644 --- a/src/library/playlistfeature.h +++ b/src/library/playlistfeature.h @@ -41,7 +41,7 @@ class PlaylistFeature : public BasePlaylistFeature { protected: void buildPlaylistList() override; - void updatePlaylistList(int playlist_id) override; + void reloadPlaylistInPlaylistList(int playlist_id) override; void decorateChild(TreeItem *pChild, int playlist_id) override; private: diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index d37fbcb34bb..53f30046eaa 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -145,7 +145,7 @@ void SetlogFeature::buildPlaylistList() { } } -void SetlogFeature::updatePlaylistList(int playlist_id) { +void SetlogFeature::reloadPlaylistInPlaylistList(int playlist_id) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("Playlists"); @@ -158,9 +158,10 @@ void SetlogFeature::updatePlaylistList(int playlist_id) { QSqlRecord record = playlistTableModel.record(); int nameColumn = record.indexOf("name"); - for (int row = 0; row < playlistTableModel.rowCount(); ++row) { + DEBUG_ASSERT(playlistTableModel.rowCount() <= 1); + if (playlistTableModel.rowCount() > 0) { QString name = playlistTableModel.data( - playlistTableModel.index(row, nameColumn)).toString(); + playlistTableModel.index(0, nameColumn)).toString(); for (auto it = m_playlistList.begin(); it != m_playlistList.end(); ++it) { if (it->first == playlist_id) { @@ -168,7 +169,6 @@ void SetlogFeature::updatePlaylistList(int playlist_id) { break; } } - break; } } diff --git a/src/library/setlogfeature.h b/src/library/setlogfeature.h index 718243a5051..4634f3b49ad 100644 --- a/src/library/setlogfeature.h +++ b/src/library/setlogfeature.h @@ -34,7 +34,7 @@ class SetlogFeature : public BasePlaylistFeature { protected: void buildPlaylistList() override; - void updatePlaylistList(int playlist_id) override; + void reloadPlaylistInPlaylistList(int playlist_id) override; void decorateChild(TreeItem *pChild, int playlist_id) override; private slots: From cab268c46136acf8544d9322ab29d135df54a401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 25 Jul 2019 21:26:52 +0200 Subject: [PATCH 06/17] Move QSqlTableModel out of createPlaylistLable --- src/library/playlistfeature.cpp | 35 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 8f83a033183..a9ad80b39e1 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -22,22 +22,13 @@ namespace { QString createPlaylistLable( - const QSqlTableModel& playlistTableModel, - int row, - int nameColumn, - int countColumn, - int durationColumn) { - QString name = playlistTableModel.data( - playlistTableModel.index(row, nameColumn)).toString(); - int count = playlistTableModel.data( - playlistTableModel.index(row, countColumn)).toInt(); - int duration = playlistTableModel.data( - playlistTableModel.index(row, durationColumn)).toInt(); + QString name, + int count, + int duration) { return QString("%1 (%2) %3").arg(name, QString::number(count), mixxx::Duration::formatSeconds(duration)); } - } @@ -187,8 +178,14 @@ void PlaylistFeature::buildPlaylistList() { for (int row = 0; row < playlistTableModel.rowCount(); ++row) { int id = playlistTableModel.data( playlistTableModel.index(row, idColumn)).toInt(); - m_playlistList.append(qMakePair(id, createPlaylistLable( - playlistTableModel, row, nameColumn, countColumn, durationColumn))); + QString name = playlistTableModel.data( + playlistTableModel.index(row, nameColumn)).toString(); + int count = playlistTableModel.data( + playlistTableModel.index(row, countColumn)).toInt(); + int duration = playlistTableModel.data( + playlistTableModel.index(row, durationColumn)).toInt(); + m_playlistList.append(qMakePair(id, + createPlaylistLable(name, count, duration))); } } @@ -209,12 +206,16 @@ void PlaylistFeature::reloadPlaylistInPlaylistList(int playlist_id) { DEBUG_ASSERT(playlistTableModel.rowCount() <= 1); if (playlistTableModel.rowCount() > 0) { + QString name = playlistTableModel.data( + playlistTableModel.index(0, nameColumn)).toString(); + int count = playlistTableModel.data( + playlistTableModel.index(0, countColumn)).toInt(); + int duration = playlistTableModel.data( + playlistTableModel.index(0, durationColumn)).toInt(); for (auto it = m_playlistList.begin(); it != m_playlistList.end(); ++it) { if (it->first == playlist_id) { - it->second = createPlaylistLable( - playlistTableModel, 0, nameColumn, - countColumn, durationColumn); + it->second = createPlaylistLable(name, count, duration); break; } } From b0842e37f02773d3b21b28ad20abfd861f83efca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 25 Jul 2019 21:36:30 +0200 Subject: [PATCH 07/17] use cammle case for playlistId --- src/library/baseplaylistfeature.h | 4 ++-- src/library/playlistfeature.cpp | 10 +++++----- src/library/setlogfeature.cpp | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index c97d3dd79f1..4965db49902 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -71,8 +71,8 @@ class BasePlaylistFeature : public LibraryFeature { virtual void updateChildModel(int selected_id); virtual void clearChildModel(); virtual void buildPlaylistList() = 0; - virtual void reloadPlaylistInPlaylistList(int playlist_id) = 0; - virtual void decorateChild(TreeItem *pChild, int playlist_id) = 0; + virtual void reloadPlaylistInPlaylistList(int playlistId) = 0; + virtual void decorateChild(TreeItem *pChild, int playlistId) = 0; virtual void addToAutoDJ(bool bTop); int playlistIdFromIndex(QModelIndex index); diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index a9ad80b39e1..627b9144e4c 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -189,11 +189,11 @@ void PlaylistFeature::buildPlaylistList() { } } -void PlaylistFeature::reloadPlaylistInPlaylistList(int playlist_id) { +void PlaylistFeature::reloadPlaylistInPlaylistList(int playlistId) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("PlaylistsCountsDurations"); - QString filter = "id=" + QString::number(playlist_id); + QString filter = "id=" + QString::number(playlistId); playlistTableModel.setFilter(filter); playlistTableModel.select(); while (playlistTableModel.canFetchMore()) { @@ -214,7 +214,7 @@ void PlaylistFeature::reloadPlaylistInPlaylistList(int playlist_id) { playlistTableModel.index(0, durationColumn)).toInt(); for (auto it = m_playlistList.begin(); it != m_playlistList.end(); ++it) { - if (it->first == playlist_id) { + if (it->first == playlistId) { it->second = createPlaylistLable(name, count, duration); break; } @@ -222,8 +222,8 @@ void PlaylistFeature::reloadPlaylistInPlaylistList(int playlist_id) { } } -void PlaylistFeature::decorateChild(TreeItem* item, int playlist_id) { - if (m_playlistDao.isPlaylistLocked(playlist_id)) { +void PlaylistFeature::decorateChild(TreeItem* item, int playlistId) { + if (m_playlistDao.isPlaylistLocked(playlistId)) { item->setIcon(QIcon(":/images/library/ic_library_locked_tracklist.svg")); } else { item->setIcon(QIcon()); diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index 53f30046eaa..fc22fe5a9e4 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -145,11 +145,11 @@ void SetlogFeature::buildPlaylistList() { } } -void SetlogFeature::reloadPlaylistInPlaylistList(int playlist_id) { +void SetlogFeature::reloadPlaylistInPlaylistList(int playlistId) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("Playlists"); - QString filter = "id=" + QString::number(playlist_id); + QString filter = "id=" + QString::number(playlistId); playlistTableModel.setFilter(filter); playlistTableModel.select(); while (playlistTableModel.canFetchMore()) { @@ -164,7 +164,7 @@ void SetlogFeature::reloadPlaylistInPlaylistList(int playlist_id) { playlistTableModel.index(0, nameColumn)).toString(); for (auto it = m_playlistList.begin(); it != m_playlistList.end(); ++it) { - if (it->first == playlist_id) { + if (it->first == playlistId) { it->second = name; break; } @@ -172,10 +172,10 @@ void SetlogFeature::reloadPlaylistInPlaylistList(int playlist_id) { } } -void SetlogFeature::decorateChild(TreeItem* item, int playlist_id) { - if (playlist_id == m_playlistId) { +void SetlogFeature::decorateChild(TreeItem* item, int playlistId) { + if (playlistId == m_playlistId) { item->setIcon(QIcon(":/images/library/ic_library_history_current.svg")); - } else if (m_playlistDao.isPlaylistLocked(playlist_id)) { + } else if (m_playlistDao.isPlaylistLocked(playlistId)) { item->setIcon(QIcon(":/images/library/ic_library_locked.svg")); } else { item->setIcon(QIcon()); From bba569e8fdf0727e5b2e08a103b828c8786f0fab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 25 Jul 2019 22:05:24 +0200 Subject: [PATCH 08/17] Add function replacePlaylistLabel() --- src/library/baseplaylistfeature.cpp | 28 +++++++++++++++++++--------- src/library/baseplaylistfeature.h | 1 + src/library/playlistfeature.cpp | 8 +------- src/library/setlogfeature.cpp | 8 +------- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index ed60da3aac8..6fb11ffeb92 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -626,7 +626,7 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { for (QList >::const_iterator it = m_playlistList.begin(); it != m_playlistList.end(); ++it, ++row) { int playlist_id = it->first; - QString playlist_name = it->second; + QString playlistLabel = it->second; if (selected_id == playlist_id) { // save index for selection @@ -635,7 +635,7 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { } // Create the TreeItem whose parent is the invisible root item - TreeItem* item = new TreeItem(this, playlist_name, playlist_id); + TreeItem* item = new TreeItem(this, playlistLabel, playlist_id); item->setBold(m_playlistsSelectedTrackIsIn.contains(playlist_id)); decorateChild(item, playlist_id); @@ -658,14 +658,14 @@ void BasePlaylistFeature::updateChildModel(int changedPlaylistId) { int row = 0; for (QList >::const_iterator it = m_playlistList.begin(); it != m_playlistList.end(); ++it, ++row) { - int playlist_id = it->first; - QString playlist_name = it->second; + int playlistId = it->first; + QString playlistLable = it->second; - if (changedPlaylistId == playlist_id) { - TreeItem* item = m_childModel.getItem(indexFromPlaylistId(playlist_id)); - item->setLabel(playlist_name); - item->setData(playlist_id); - decorateChild(item, playlist_id); + if (changedPlaylistId == playlistId) { + TreeItem* item = m_childModel.getItem(indexFromPlaylistId(playlistId)); + item->setLabel(playlistLable); + item->setData(playlistId); + decorateChild(item, playlistId); } } } @@ -693,6 +693,16 @@ QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) { return QModelIndex(); } +void BasePlaylistFeature::replacePlaylistLabel(int playlistId, + const QString& label) { + for (auto it = m_playlistList.begin(); it != m_playlistList.end(); ++it) { + if (it->first == playlistId) { + it->second = label; + break; + } + } +} + void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) { m_pSelectedTrack = pTrack; TrackId trackId; diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 4965db49902..29cb03feb20 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -79,6 +79,7 @@ class BasePlaylistFeature : public LibraryFeature { // Get the QModelIndex of a playlist based on its id. Returns QModelIndex() // on failure. QModelIndex indexFromPlaylistId(int playlistId); + void replacePlaylistLabel(int playlistId, const QString& label); TrackCollection* m_pTrackCollection; PlaylistDAO &m_playlistDao; diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 627b9144e4c..36fed72fb19 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -212,13 +212,7 @@ void PlaylistFeature::reloadPlaylistInPlaylistList(int playlistId) { playlistTableModel.index(0, countColumn)).toInt(); int duration = playlistTableModel.data( playlistTableModel.index(0, durationColumn)).toInt(); - for (auto it = m_playlistList.begin(); - it != m_playlistList.end(); ++it) { - if (it->first == playlistId) { - it->second = createPlaylistLable(name, count, duration); - break; - } - } + replacePlaylistLabel(playlistId, createPlaylistLable(name, count, duration)); } } diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index fc22fe5a9e4..38a90eb5628 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -162,13 +162,7 @@ void SetlogFeature::reloadPlaylistInPlaylistList(int playlistId) { if (playlistTableModel.rowCount() > 0) { QString name = playlistTableModel.data( playlistTableModel.index(0, nameColumn)).toString(); - for (auto it = m_playlistList.begin(); - it != m_playlistList.end(); ++it) { - if (it->first == playlistId) { - it->second = name; - break; - } - } + replacePlaylistLabel(playlistId, name); } } From b43f1e6aa80a158e54b2d1fa14e7a33ff953bbc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Thu, 25 Jul 2019 23:57:33 +0200 Subject: [PATCH 09/17] rename m_playlistList to m_playlistLabels and create a struct as store type --- src/library/baseplaylistfeature.cpp | 47 ++++++++++++++--------------- src/library/baseplaylistfeature.h | 9 +++++- src/library/playlistfeature.cpp | 14 +++++---- src/library/setlogfeature.cpp | 7 +++-- 4 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 6fb11ffeb92..527a18c01bb 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -623,22 +623,21 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { int selected_row = -1; int row = 0; - for (QList >::const_iterator it = m_playlistList.begin(); - it != m_playlistList.end(); ++it, ++row) { - int playlist_id = it->first; - QString playlistLabel = it->second; + for (auto it = m_playlistLabels.constBegin(); + it != m_playlistLabels.constEnd(); ++it, ++row) { + int playlistId = it->id; + QString playlistLabel = it->label; - if (selected_id == playlist_id) { + if (selected_id == playlistId) { // save index for selection selected_row = row; - m_childModel.index(selected_row, 0); } // Create the TreeItem whose parent is the invisible root item - TreeItem* item = new TreeItem(this, playlistLabel, playlist_id); - item->setBold(m_playlistsSelectedTrackIsIn.contains(playlist_id)); + TreeItem* item = new TreeItem(this, playlistLabel, playlistId); + item->setBold(m_playlistsSelectedTrackIsIn.contains(playlistId)); - decorateChild(item, playlist_id); + decorateChild(item, playlistId); data_list.append(item); } @@ -656,10 +655,10 @@ void BasePlaylistFeature::updateChildModel(int changedPlaylistId) { reloadPlaylistInPlaylistList(changedPlaylistId); int row = 0; - for (QList >::const_iterator it = m_playlistList.begin(); - it != m_playlistList.end(); ++it, ++row) { - int playlistId = it->first; - QString playlistLable = it->second; + for (auto it = m_playlistLabels.constBegin(); + it != m_playlistLabels.constEnd(); ++it, ++row) { + int playlistId = it->id; + QString playlistLable = it->label; if (changedPlaylistId == playlistId) { TreeItem* item = m_childModel.getItem(indexFromPlaylistId(playlistId)); @@ -676,15 +675,15 @@ void BasePlaylistFeature::updateChildModel(int changedPlaylistId) { * Clears the child model dynamically, but the invisible root item remains */ void BasePlaylistFeature::clearChildModel() { - m_childModel.removeRows(0, m_playlistList.size()); + m_childModel.removeRows(0, m_playlistLabels.size()); } QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) { int row = 0; - for (QList >::const_iterator it = m_playlistList.begin(); - it != m_playlistList.end(); ++it, ++row) { - int current_id = it->first; - QString playlist_name = it->second; + for (auto it = m_playlistLabels.constBegin(); + it != m_playlistLabels.constEnd(); ++it, ++row) { + int current_id = it->id; + QString playlist_name = it->label; if (playlistId == current_id) { return m_childModel.index(row, 0); @@ -695,9 +694,9 @@ QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) { void BasePlaylistFeature::replacePlaylistLabel(int playlistId, const QString& label) { - for (auto it = m_playlistList.begin(); it != m_playlistList.end(); ++it) { - if (it->first == playlistId) { - it->second = label; + for (auto it = m_playlistLabels.begin(); it != m_playlistLabels.end(); ++it) { + if (it->id == playlistId) { + it->label = label; break; } } @@ -719,14 +718,14 @@ void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) { // Set all playlists the track is in bold (or if there is no track selected, // clear all the bolding). int row = 0; - for (auto it = m_playlistList.constBegin(); - it != m_playlistList.constEnd(); ++it, ++row) { + for (auto it = m_playlistLabels.constBegin(); + it != m_playlistLabels.constEnd(); ++it, ++row) { TreeItem* playlist = rootItem->child(row); if (playlist == nullptr) { continue; } - int playlistId = it->first; + int playlistId = it->id; bool shouldBold = m_playlistsSelectedTrackIsIn.contains(playlistId); playlist->setBold(shouldBold); } diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 29cb03feb20..3bdca8a444e 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -67,6 +67,13 @@ class BasePlaylistFeature : public LibraryFeature { void slotAnalyzePlaylist(); protected: + + struct IdAndLabel { + int id; + QString label; + }; + + virtual QModelIndex constructChildModel(int selected_id); virtual void updateChildModel(int selected_id); virtual void clearChildModel(); @@ -97,7 +104,7 @@ class BasePlaylistFeature : public LibraryFeature { QAction *m_pExportTrackFilesAction; QAction *m_pDuplicatePlaylistAction; QAction *m_pAnalyzePlaylistAction; - QList > m_playlistList; + QList m_playlistLabels; QModelIndex m_lastRightClickedIndex; TreeItemModel m_childModel; TrackPointer m_pSelectedTrack; diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 36fed72fb19..bc0eb8a2b77 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -21,7 +21,7 @@ namespace { -QString createPlaylistLable( +QString createPlaylistLabel( QString name, int count, int duration) { @@ -29,7 +29,7 @@ QString createPlaylistLable( mixxx::Duration::formatSeconds(duration)); } -} +} // anonymous namespace PlaylistFeature::PlaylistFeature(QObject* parent, @@ -140,7 +140,7 @@ bool PlaylistFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { } void PlaylistFeature::buildPlaylistList() { - m_playlistList.clear(); + m_playlistLabels.clear(); QString queryString = QString( "CREATE TEMPORARY VIEW IF NOT EXISTS PlaylistsCountsDurations " @@ -184,8 +184,10 @@ void PlaylistFeature::buildPlaylistList() { playlistTableModel.index(row, countColumn)).toInt(); int duration = playlistTableModel.data( playlistTableModel.index(row, durationColumn)).toInt(); - m_playlistList.append(qMakePair(id, - createPlaylistLable(name, count, duration))); + IdAndLabel idAndLabel; + idAndLabel.id = id; + idAndLabel.label = createPlaylistLabel(name, count, duration); + m_playlistLabels.append(idAndLabel); } } @@ -212,7 +214,7 @@ void PlaylistFeature::reloadPlaylistInPlaylistList(int playlistId) { playlistTableModel.index(0, countColumn)).toInt(); int duration = playlistTableModel.data( playlistTableModel.index(0, durationColumn)).toInt(); - replacePlaylistLabel(playlistId, createPlaylistLable(name, count, duration)); + replacePlaylistLabel(playlistId, createPlaylistLabel(name, count, duration)); } } diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index 38a90eb5628..d92647c9ca2 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -121,7 +121,7 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index void SetlogFeature::buildPlaylistList() { - m_playlistList.clear(); + m_playlistLabels.clear(); // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("Playlists"); @@ -141,7 +141,10 @@ void SetlogFeature::buildPlaylistList() { playlistTableModel.index(row, idColumn)).toInt(); QString name = playlistTableModel.data( playlistTableModel.index(row, nameColumn)).toString(); - m_playlistList.append(qMakePair(id, name)); + IdAndLabel idAndLabel; + idAndLabel.id = id; + idAndLabel.label = name; + m_playlistLabels.append(idAndLabel); } } From 60772f3e7be1dafb356dbdec91fe7058589b959c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Fri, 26 Jul 2019 00:12:29 +0200 Subject: [PATCH 10/17] Rename more functions --- src/library/baseplaylistfeature.cpp | 4 ++-- src/library/baseplaylistfeature.h | 4 ++-- src/library/playlistfeature.cpp | 4 ++-- src/library/playlistfeature.h | 4 ++-- src/library/setlogfeature.cpp | 4 ++-- src/library/setlogfeature.h | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 527a18c01bb..c9da97e7e76 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -618,7 +618,7 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) { * This method queries the database and does dynamic insertion */ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { - buildPlaylistList(); + createPlaylistLabels(); QList data_list; int selected_row = -1; @@ -652,7 +652,7 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { void BasePlaylistFeature::updateChildModel(int changedPlaylistId) { // the following call fetches whole m_playlistList. // Anything may have change due to a concurrent Mixxx instance. - reloadPlaylistInPlaylistList(changedPlaylistId); + updatePlaylistLabel(changedPlaylistId); int row = 0; for (auto it = m_playlistLabels.constBegin(); diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 3bdca8a444e..3130162231a 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -77,8 +77,8 @@ class BasePlaylistFeature : public LibraryFeature { virtual QModelIndex constructChildModel(int selected_id); virtual void updateChildModel(int selected_id); virtual void clearChildModel(); - virtual void buildPlaylistList() = 0; - virtual void reloadPlaylistInPlaylistList(int playlistId) = 0; + virtual void createPlaylistLabels() = 0; + virtual void updatePlaylistLabel(int playlistId) = 0; virtual void decorateChild(TreeItem *pChild, int playlistId) = 0; virtual void addToAutoDJ(bool bTop); diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index bc0eb8a2b77..11ee1d8a0eb 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -139,7 +139,7 @@ bool PlaylistFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { return !locked && formatSupported; } -void PlaylistFeature::buildPlaylistList() { +void PlaylistFeature::createPlaylistLabels() { m_playlistLabels.clear(); QString queryString = QString( @@ -191,7 +191,7 @@ void PlaylistFeature::buildPlaylistList() { } } -void PlaylistFeature::reloadPlaylistInPlaylistList(int playlistId) { +void PlaylistFeature::updatePlaylistLabel(int playlistId) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("PlaylistsCountsDurations"); diff --git a/src/library/playlistfeature.h b/src/library/playlistfeature.h index b8212dae406..20410ee5bc8 100644 --- a/src/library/playlistfeature.h +++ b/src/library/playlistfeature.h @@ -40,8 +40,8 @@ class PlaylistFeature : public BasePlaylistFeature { void slotPlaylistTableRenamed(int playlistId, QString a_strName); protected: - void buildPlaylistList() override; - void reloadPlaylistInPlaylistList(int playlist_id) override; + void createPlaylistLabels() override; + void updatePlaylistLabel(int playlist_id) override; void decorateChild(TreeItem *pChild, int playlist_id) override; private: diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index d92647c9ca2..a3cf4da9414 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -120,7 +120,7 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index } -void SetlogFeature::buildPlaylistList() { +void SetlogFeature::createPlaylistLabels() { m_playlistLabels.clear(); // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); @@ -148,7 +148,7 @@ void SetlogFeature::buildPlaylistList() { } } -void SetlogFeature::reloadPlaylistInPlaylistList(int playlistId) { +void SetlogFeature::updatePlaylistLabel(int playlistId) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("Playlists"); diff --git a/src/library/setlogfeature.h b/src/library/setlogfeature.h index 4634f3b49ad..49b9cdc7f0e 100644 --- a/src/library/setlogfeature.h +++ b/src/library/setlogfeature.h @@ -33,8 +33,8 @@ class SetlogFeature : public BasePlaylistFeature { void slotGetNewPlaylist(); protected: - void buildPlaylistList() override; - void reloadPlaylistInPlaylistList(int playlist_id) override; + void createPlaylistLabels() override; + void updatePlaylistLabel(int playlist_id) override; void decorateChild(TreeItem *pChild, int playlist_id) override; private slots: From 3a15f5883e092de40b7fad850b487175eb37b75a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 27 Jul 2019 12:17:59 +0200 Subject: [PATCH 11/17] Simplify names in updateChildModel() and remove outdates comment --- src/library/baseplaylistfeature.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index c9da97e7e76..23bdb57db58 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -649,22 +649,20 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { return m_childModel.index(selected_row, 0); } -void BasePlaylistFeature::updateChildModel(int changedPlaylistId) { - // the following call fetches whole m_playlistList. - // Anything may have change due to a concurrent Mixxx instance. - updatePlaylistLabel(changedPlaylistId); +void BasePlaylistFeature::updateChildModel(int playlistId) { + updatePlaylistLabel(playlistId); int row = 0; for (auto it = m_playlistLabels.constBegin(); it != m_playlistLabels.constEnd(); ++it, ++row) { - int playlistId = it->id; + int id = it->id; QString playlistLable = it->label; - if (changedPlaylistId == playlistId) { - TreeItem* item = m_childModel.getItem(indexFromPlaylistId(playlistId)); + if (playlistId == id) { + TreeItem* item = m_childModel.getItem(indexFromPlaylistId(id)); item->setLabel(playlistLable); - item->setData(playlistId); - decorateChild(item, playlistId); + item->setData(id); + decorateChild(item, id); } } } From f50452234ee067664130a12825ec455b4bedbfca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 27 Jul 2019 12:39:57 +0200 Subject: [PATCH 12/17] Split out fetchPlaylistLabel --- src/library/baseplaylistfeature.cpp | 7 +++++++ src/library/baseplaylistfeature.h | 3 ++- src/library/playlistfeature.cpp | 5 +++-- src/library/playlistfeature.h | 2 +- src/library/setlogfeature.cpp | 6 +++--- src/library/setlogfeature.h | 4 ++-- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 23bdb57db58..124975001e6 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -690,6 +690,13 @@ QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) { return QModelIndex(); } +void BasePlaylistFeature::updatePlaylistLabel(int playlistId) { + QString label = fetchPlaylistLabel(playlistId); + if (!label.isNull()) { + replacePlaylistLabel(playlistId, label); + } +} + void BasePlaylistFeature::replacePlaylistLabel(int playlistId, const QString& label) { for (auto it = m_playlistLabels.begin(); it != m_playlistLabels.end(); ++it) { diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 3130162231a..a4d92ef4da3 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -78,7 +78,8 @@ class BasePlaylistFeature : public LibraryFeature { virtual void updateChildModel(int selected_id); virtual void clearChildModel(); virtual void createPlaylistLabels() = 0; - virtual void updatePlaylistLabel(int playlistId) = 0; + virtual QString fetchPlaylistLabel(int playlistId) = 0; + void updatePlaylistLabel(int playlistId); virtual void decorateChild(TreeItem *pChild, int playlistId) = 0; virtual void addToAutoDJ(bool bTop); diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 11ee1d8a0eb..596747cb237 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -191,7 +191,7 @@ void PlaylistFeature::createPlaylistLabels() { } } -void PlaylistFeature::updatePlaylistLabel(int playlistId) { +QString PlaylistFeature::fetchPlaylistLabel(int playlistId) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("PlaylistsCountsDurations"); @@ -214,8 +214,9 @@ void PlaylistFeature::updatePlaylistLabel(int playlistId) { playlistTableModel.index(0, countColumn)).toInt(); int duration = playlistTableModel.data( playlistTableModel.index(0, durationColumn)).toInt(); - replacePlaylistLabel(playlistId, createPlaylistLabel(name, count, duration)); + return createPlaylistLabel(name, count, duration); } + return QString(); } void PlaylistFeature::decorateChild(TreeItem* item, int playlistId) { diff --git a/src/library/playlistfeature.h b/src/library/playlistfeature.h index 20410ee5bc8..2c412b8b807 100644 --- a/src/library/playlistfeature.h +++ b/src/library/playlistfeature.h @@ -41,7 +41,7 @@ class PlaylistFeature : public BasePlaylistFeature { protected: void createPlaylistLabels() override; - void updatePlaylistLabel(int playlist_id) override; + QString fetchPlaylistLabel(int playlistId) override; void decorateChild(TreeItem *pChild, int playlist_id) override; private: diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index a3cf4da9414..bad4043fcbd 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -148,7 +148,7 @@ void SetlogFeature::createPlaylistLabels() { } } -void SetlogFeature::updatePlaylistLabel(int playlistId) { +QString SetlogFeature::fetchPlaylistLabel(int playlistId) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("Playlists"); @@ -163,10 +163,10 @@ void SetlogFeature::updatePlaylistLabel(int playlistId) { DEBUG_ASSERT(playlistTableModel.rowCount() <= 1); if (playlistTableModel.rowCount() > 0) { - QString name = playlistTableModel.data( + return playlistTableModel.data( playlistTableModel.index(0, nameColumn)).toString(); - replacePlaylistLabel(playlistId, name); } + return QString(); } void SetlogFeature::decorateChild(TreeItem* item, int playlistId) { diff --git a/src/library/setlogfeature.h b/src/library/setlogfeature.h index 49b9cdc7f0e..6bcdb2c3384 100644 --- a/src/library/setlogfeature.h +++ b/src/library/setlogfeature.h @@ -34,8 +34,8 @@ class SetlogFeature : public BasePlaylistFeature { protected: void createPlaylistLabels() override; - void updatePlaylistLabel(int playlist_id) override; - void decorateChild(TreeItem *pChild, int playlist_id) override; + QString fetchPlaylistLabel(int playlistId) override; + void decorateChild(TreeItem *pChild, int playlistId) override; private slots: void slotPlayingTrackChanged(TrackPointer currentPlayingTrack); From bef6c0d1b69bf82b1ecc6d7e3c6fed230a5bd01e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 27 Jul 2019 13:41:33 +0200 Subject: [PATCH 13/17] Make m_playlistLabels private --- src/library/baseplaylistfeature.cpp | 3 ++- src/library/baseplaylistfeature.h | 4 ++-- src/library/playlistfeature.cpp | 6 ++---- src/library/playlistfeature.h | 2 +- src/library/setlogfeature.cpp | 6 ++---- src/library/setlogfeature.h | 2 +- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 124975001e6..941032912de 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -618,7 +618,8 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) { * This method queries the database and does dynamic insertion */ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { - createPlaylistLabels(); + m_playlistLabels.clear(); + createPlaylistLabels(&m_playlistLabels); QList data_list; int selected_row = -1; diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index a4d92ef4da3..06a1065c8d7 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -77,7 +77,7 @@ class BasePlaylistFeature : public LibraryFeature { virtual QModelIndex constructChildModel(int selected_id); virtual void updateChildModel(int selected_id); virtual void clearChildModel(); - virtual void createPlaylistLabels() = 0; + virtual void createPlaylistLabels(QList* pPlaylistLabels) = 0; virtual QString fetchPlaylistLabel(int playlistId) = 0; void updatePlaylistLabel(int playlistId); virtual void decorateChild(TreeItem *pChild, int playlistId) = 0; @@ -105,7 +105,6 @@ class BasePlaylistFeature : public LibraryFeature { QAction *m_pExportTrackFilesAction; QAction *m_pDuplicatePlaylistAction; QAction *m_pAnalyzePlaylistAction; - QList m_playlistLabels; QModelIndex m_lastRightClickedIndex; TreeItemModel m_childModel; TrackPointer m_pSelectedTrack; @@ -117,6 +116,7 @@ class BasePlaylistFeature : public LibraryFeature { private: virtual QString getRootViewHtml() const = 0; + QList m_playlistLabels; QSet m_playlistsSelectedTrackIsIn; QString m_rootViewName; }; diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 596747cb237..6964243f43f 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -139,9 +139,7 @@ bool PlaylistFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { return !locked && formatSupported; } -void PlaylistFeature::createPlaylistLabels() { - m_playlistLabels.clear(); - +void PlaylistFeature::createPlaylistLabels(QList* pPlaylistLabels) { QString queryString = QString( "CREATE TEMPORARY VIEW IF NOT EXISTS PlaylistsCountsDurations " "AS SELECT " @@ -187,7 +185,7 @@ void PlaylistFeature::createPlaylistLabels() { IdAndLabel idAndLabel; idAndLabel.id = id; idAndLabel.label = createPlaylistLabel(name, count, duration); - m_playlistLabels.append(idAndLabel); + pPlaylistLabels->append(idAndLabel); } } diff --git a/src/library/playlistfeature.h b/src/library/playlistfeature.h index 2c412b8b807..664d14cbf2c 100644 --- a/src/library/playlistfeature.h +++ b/src/library/playlistfeature.h @@ -40,7 +40,7 @@ class PlaylistFeature : public BasePlaylistFeature { void slotPlaylistTableRenamed(int playlistId, QString a_strName); protected: - void createPlaylistLabels() override; + void createPlaylistLabels(QList* pPlaylistLabels) override; QString fetchPlaylistLabel(int playlistId) override; void decorateChild(TreeItem *pChild, int playlist_id) override; diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index bad4043fcbd..a7afc0e42fa 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -119,9 +119,7 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index menu.exec(globalPos); } - -void SetlogFeature::createPlaylistLabels() { - m_playlistLabels.clear(); +void SetlogFeature::createPlaylistLabels(QList* pPlaylistLabels) { // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("Playlists"); @@ -144,7 +142,7 @@ void SetlogFeature::createPlaylistLabels() { IdAndLabel idAndLabel; idAndLabel.id = id; idAndLabel.label = name; - m_playlistLabels.append(idAndLabel); + pPlaylistLabels->append(idAndLabel); } } diff --git a/src/library/setlogfeature.h b/src/library/setlogfeature.h index 6bcdb2c3384..5478f6071af 100644 --- a/src/library/setlogfeature.h +++ b/src/library/setlogfeature.h @@ -33,7 +33,7 @@ class SetlogFeature : public BasePlaylistFeature { void slotGetNewPlaylist(); protected: - void createPlaylistLabels() override; + void createPlaylistLabels(QList* pPlaylistLabels) override; QString fetchPlaylistLabel(int playlistId) override; void decorateChild(TreeItem *pChild, int playlistId) override; From 16702fbc484ebed0860c7baccf72a8a4ded598ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sat, 27 Jul 2019 19:32:30 +0200 Subject: [PATCH 14/17] dispose m_playlistLable --- src/library/baseplaylistfeature.cpp | 94 +++++++++++------------------ src/library/baseplaylistfeature.h | 3 - 2 files changed, 36 insertions(+), 61 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 941032912de..9a2beb01fe5 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -618,14 +618,14 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) { * This method queries the database and does dynamic insertion */ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { - m_playlistLabels.clear(); - createPlaylistLabels(&m_playlistLabels); + QList playlistLabels; + createPlaylistLabels(&playlistLabels); QList data_list; int selected_row = -1; int row = 0; - for (auto it = m_playlistLabels.constBegin(); - it != m_playlistLabels.constEnd(); ++it, ++row) { + for (auto it = playlistLabels.constBegin(); + it != playlistLabels.constEnd(); ++it, ++row) { int playlistId = it->id; QString playlistLabel = it->label; @@ -651,19 +651,18 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { } void BasePlaylistFeature::updateChildModel(int playlistId) { - updatePlaylistLabel(playlistId); - - int row = 0; - for (auto it = m_playlistLabels.constBegin(); - it != m_playlistLabels.constEnd(); ++it, ++row) { - int id = it->id; - QString playlistLable = it->label; - - if (playlistId == id) { - TreeItem* item = m_childModel.getItem(indexFromPlaylistId(id)); - item->setLabel(playlistLable); - item->setData(id); - decorateChild(item, id); + QString playlistLable = fetchPlaylistLabel(playlistId); + + QVariant variantId = QVariant(playlistId); + + for (int row = 0; row < m_childModel.rowCount(); ++row) { + QModelIndex index = m_childModel.index(row, 0); + TreeItem* pTreeItem = m_childModel.getItem(index); + DEBUG_ASSERT(pTreeItem != nullptr); + if (!pTreeItem->hasChildren() && // leaf node + pTreeItem->getData() == variantId) { + pTreeItem->setLabel(playlistLable); + decorateChild(pTreeItem, playlistId); } } } @@ -674,40 +673,23 @@ void BasePlaylistFeature::updateChildModel(int playlistId) { * Clears the child model dynamically, but the invisible root item remains */ void BasePlaylistFeature::clearChildModel() { - m_childModel.removeRows(0, m_playlistLabels.size()); + m_childModel.removeRows(0, m_childModel.rowCount()); } QModelIndex BasePlaylistFeature::indexFromPlaylistId(int playlistId) { - int row = 0; - for (auto it = m_playlistLabels.constBegin(); - it != m_playlistLabels.constEnd(); ++it, ++row) { - int current_id = it->id; - QString playlist_name = it->label; - - if (playlistId == current_id) { - return m_childModel.index(row, 0); + QVariant variantId = QVariant(playlistId); + for (int row = 0; row < m_childModel.rowCount(); ++row) { + QModelIndex index = m_childModel.index(row, 0); + TreeItem* pTreeItem = m_childModel.getItem(index); + DEBUG_ASSERT(pTreeItem != nullptr); + if (!pTreeItem->hasChildren() && // leaf node + pTreeItem->getData() == variantId) { + return index; } } return QModelIndex(); } -void BasePlaylistFeature::updatePlaylistLabel(int playlistId) { - QString label = fetchPlaylistLabel(playlistId); - if (!label.isNull()) { - replacePlaylistLabel(playlistId, label); - } -} - -void BasePlaylistFeature::replacePlaylistLabel(int playlistId, - const QString& label) { - for (auto it = m_playlistLabels.begin(); it != m_playlistLabels.end(); ++it) { - if (it->id == playlistId) { - it->label = label; - break; - } - } -} - void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) { m_pSelectedTrack = pTrack; TrackId trackId; @@ -716,24 +698,20 @@ void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) { } m_playlistDao.getPlaylistsTrackIsIn(trackId, &m_playlistsSelectedTrackIsIn); - TreeItem* rootItem = m_childModel.getRootItem(); - if (rootItem == nullptr) { - return; - } - // Set all playlists the track is in bold (or if there is no track selected, // clear all the bolding). - int row = 0; - for (auto it = m_playlistLabels.constBegin(); - it != m_playlistLabels.constEnd(); ++it, ++row) { - TreeItem* playlist = rootItem->child(row); - if (playlist == nullptr) { - continue; + for (int row = 0; row < m_childModel.rowCount(); ++row) { + QModelIndex index = m_childModel.index(row, 0); + TreeItem* pTreeItem = m_childModel.getItem(index); + DEBUG_ASSERT(pTreeItem != nullptr); + if (!pTreeItem->hasChildren()) { // leaf node + bool ok; + int playlistId = pTreeItem->getData().toInt(&ok); + if (ok) { + bool shouldBold = m_playlistsSelectedTrackIsIn.contains(playlistId); + pTreeItem->setBold(shouldBold); + } } - - int playlistId = it->id; - bool shouldBold = m_playlistsSelectedTrackIsIn.contains(playlistId); - playlist->setBold(shouldBold); } m_childModel.triggerRepaint(); diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 06a1065c8d7..70f77cca085 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -79,7 +79,6 @@ class BasePlaylistFeature : public LibraryFeature { virtual void clearChildModel(); virtual void createPlaylistLabels(QList* pPlaylistLabels) = 0; virtual QString fetchPlaylistLabel(int playlistId) = 0; - void updatePlaylistLabel(int playlistId); virtual void decorateChild(TreeItem *pChild, int playlistId) = 0; virtual void addToAutoDJ(bool bTop); @@ -87,7 +86,6 @@ class BasePlaylistFeature : public LibraryFeature { // Get the QModelIndex of a playlist based on its id. Returns QModelIndex() // on failure. QModelIndex indexFromPlaylistId(int playlistId); - void replacePlaylistLabel(int playlistId, const QString& label); TrackCollection* m_pTrackCollection; PlaylistDAO &m_playlistDao; @@ -116,7 +114,6 @@ class BasePlaylistFeature : public LibraryFeature { private: virtual QString getRootViewHtml() const = 0; - QList m_playlistLabels; QSet m_playlistsSelectedTrackIsIn; QString m_rootViewName; }; From 157033aca78edec5b70e037304d79bfa770e75a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 28 Jul 2019 11:02:49 +0200 Subject: [PATCH 15/17] fix typo --- src/library/baseplaylistfeature.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 9a2beb01fe5..937a255a48d 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -651,7 +651,7 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { } void BasePlaylistFeature::updateChildModel(int playlistId) { - QString playlistLable = fetchPlaylistLabel(playlistId); + QString playlistLabel = fetchPlaylistLabel(playlistId); QVariant variantId = QVariant(playlistId); @@ -661,7 +661,7 @@ void BasePlaylistFeature::updateChildModel(int playlistId) { DEBUG_ASSERT(pTreeItem != nullptr); if (!pTreeItem->hasChildren() && // leaf node pTreeItem->getData() == variantId) { - pTreeItem->setLabel(playlistLable); + pTreeItem->setLabel(playlistLabel); decorateChild(pTreeItem, playlistId); } } From f347f00f7fb11cca9ed2800b474c19e8cea25e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 28 Jul 2019 11:28:13 +0200 Subject: [PATCH 16/17] return playlistLabels by value, a QList is implicitly shared. --- src/library/baseplaylistfeature.cpp | 3 +-- src/library/baseplaylistfeature.h | 2 +- src/library/playlistfeature.cpp | 8 +++++--- src/library/playlistfeature.h | 2 +- src/library/setlogfeature.cpp | 8 +++++--- src/library/setlogfeature.h | 2 +- src/library/treeitemmodel.cpp | 5 ++++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 937a255a48d..7f173ac5529 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -618,8 +618,7 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) { * This method queries the database and does dynamic insertion */ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { - QList playlistLabels; - createPlaylistLabels(&playlistLabels); + QList playlistLabels = createPlaylistLabels(); QList data_list; int selected_row = -1; diff --git a/src/library/baseplaylistfeature.h b/src/library/baseplaylistfeature.h index 70f77cca085..90d585f3afc 100644 --- a/src/library/baseplaylistfeature.h +++ b/src/library/baseplaylistfeature.h @@ -77,7 +77,7 @@ class BasePlaylistFeature : public LibraryFeature { virtual QModelIndex constructChildModel(int selected_id); virtual void updateChildModel(int selected_id); virtual void clearChildModel(); - virtual void createPlaylistLabels(QList* pPlaylistLabels) = 0; + virtual QList createPlaylistLabels() = 0; virtual QString fetchPlaylistLabel(int playlistId) = 0; virtual void decorateChild(TreeItem *pChild, int playlistId) = 0; virtual void addToAutoDJ(bool bTop); diff --git a/src/library/playlistfeature.cpp b/src/library/playlistfeature.cpp index 6964243f43f..197f57fb76d 100644 --- a/src/library/playlistfeature.cpp +++ b/src/library/playlistfeature.cpp @@ -139,7 +139,8 @@ bool PlaylistFeature::dragMoveAcceptChild(const QModelIndex& index, QUrl url) { return !locked && formatSupported; } -void PlaylistFeature::createPlaylistLabels(QList* pPlaylistLabels) { +QList PlaylistFeature::createPlaylistLabels() { + QList playlistLabels; QString queryString = QString( "CREATE TEMPORARY VIEW IF NOT EXISTS PlaylistsCountsDurations " "AS SELECT " @@ -182,11 +183,12 @@ void PlaylistFeature::createPlaylistLabels(QList* pPlaylistLabels) { playlistTableModel.index(row, countColumn)).toInt(); int duration = playlistTableModel.data( playlistTableModel.index(row, durationColumn)).toInt(); - IdAndLabel idAndLabel; + BasePlaylistFeature::IdAndLabel idAndLabel; idAndLabel.id = id; idAndLabel.label = createPlaylistLabel(name, count, duration); - pPlaylistLabels->append(idAndLabel); + playlistLabels.append(idAndLabel); } + return playlistLabels; } QString PlaylistFeature::fetchPlaylistLabel(int playlistId) { diff --git a/src/library/playlistfeature.h b/src/library/playlistfeature.h index 664d14cbf2c..ce6a1183aba 100644 --- a/src/library/playlistfeature.h +++ b/src/library/playlistfeature.h @@ -40,7 +40,7 @@ class PlaylistFeature : public BasePlaylistFeature { void slotPlaylistTableRenamed(int playlistId, QString a_strName); protected: - void createPlaylistLabels(QList* pPlaylistLabels) override; + QList createPlaylistLabels() override; QString fetchPlaylistLabel(int playlistId) override; void decorateChild(TreeItem *pChild, int playlist_id) override; diff --git a/src/library/setlogfeature.cpp b/src/library/setlogfeature.cpp index a7afc0e42fa..3e4794b49cf 100644 --- a/src/library/setlogfeature.cpp +++ b/src/library/setlogfeature.cpp @@ -119,7 +119,8 @@ void SetlogFeature::onRightClickChild(const QPoint& globalPos, QModelIndex index menu.exec(globalPos); } -void SetlogFeature::createPlaylistLabels(QList* pPlaylistLabels) { +QList SetlogFeature::createPlaylistLabels() { + QList playlistLabels; // Setup the sidebar playlist model QSqlTableModel playlistTableModel(this, m_pTrackCollection->database()); playlistTableModel.setTable("Playlists"); @@ -139,11 +140,12 @@ void SetlogFeature::createPlaylistLabels(QList* pPlaylistLabels) { playlistTableModel.index(row, idColumn)).toInt(); QString name = playlistTableModel.data( playlistTableModel.index(row, nameColumn)).toString(); - IdAndLabel idAndLabel; + BasePlaylistFeature::IdAndLabel idAndLabel; idAndLabel.id = id; idAndLabel.label = name; - pPlaylistLabels->append(idAndLabel); + playlistLabels.append(idAndLabel); } + return playlistLabels; } QString SetlogFeature::fetchPlaylistLabel(int playlistId) { diff --git a/src/library/setlogfeature.h b/src/library/setlogfeature.h index 5478f6071af..fb460e52246 100644 --- a/src/library/setlogfeature.h +++ b/src/library/setlogfeature.h @@ -33,7 +33,7 @@ class SetlogFeature : public BasePlaylistFeature { void slotGetNewPlaylist(); protected: - void createPlaylistLabels(QList* pPlaylistLabels) override; + QList createPlaylistLabels() override; QString fetchPlaylistLabel(int playlistId) override; void decorateChild(TreeItem *pChild, int playlistId) override; diff --git a/src/library/treeitemmodel.cpp b/src/library/treeitemmodel.cpp index 6f7e646c846..8d4415ad07d 100644 --- a/src/library/treeitemmodel.cpp +++ b/src/library/treeitemmodel.cpp @@ -164,7 +164,10 @@ TreeItem* TreeItemModel::setRootItem(std::unique_ptr pRootItem) { * Before you can resize the data model dynamically by using 'insertRows' and 'removeRows' * make sure you have initialized */ -void TreeItemModel::insertTreeItemRows(QList& rows, int position, const QModelIndex& parent) { +void TreeItemModel::insertTreeItemRows( + QList& rows, + int position, + const QModelIndex& parent) { if (rows.isEmpty()) { return; } From 2c31be17914ce0352c70b775119ed54a043c622d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Sch=C3=BCrmann?= Date: Sun, 28 Jul 2019 23:35:21 +0200 Subject: [PATCH 17/17] user range base loop and a debug assert --- src/library/baseplaylistfeature.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/library/baseplaylistfeature.cpp b/src/library/baseplaylistfeature.cpp index 7f173ac5529..c5e64c61767 100644 --- a/src/library/baseplaylistfeature.cpp +++ b/src/library/baseplaylistfeature.cpp @@ -618,15 +618,13 @@ void BasePlaylistFeature::htmlLinkClicked(const QUrl& link) { * This method queries the database and does dynamic insertion */ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { - QList playlistLabels = createPlaylistLabels(); QList data_list; int selected_row = -1; int row = 0; - for (auto it = playlistLabels.constBegin(); - it != playlistLabels.constEnd(); ++it, ++row) { - int playlistId = it->id; - QString playlistLabel = it->label; + for (const IdAndLabel& idAndLabel : createPlaylistLabels()) { + int playlistId = idAndLabel.id; + QString playlistLabel = idAndLabel.label; if (selected_id == playlistId) { // save index for selection @@ -639,6 +637,8 @@ QModelIndex BasePlaylistFeature::constructChildModel(int selected_id) { decorateChild(item, playlistId); data_list.append(item); + + ++row; } // Append all the newly created TreeItems in a dynamic way to the childmodel @@ -706,10 +706,11 @@ void BasePlaylistFeature::slotTrackSelected(TrackPointer pTrack) { if (!pTreeItem->hasChildren()) { // leaf node bool ok; int playlistId = pTreeItem->getData().toInt(&ok); - if (ok) { - bool shouldBold = m_playlistsSelectedTrackIsIn.contains(playlistId); - pTreeItem->setBold(shouldBold); + VERIFY_OR_DEBUG_ASSERT(ok) { + continue; } + bool shouldBold = m_playlistsSelectedTrackIsIn.contains(playlistId); + pTreeItem->setBold(shouldBold); } }