From de256e4094f74b0be2ac4190c5f3d6e3833fb345 Mon Sep 17 00:00:00 2001 From: Daniel Poelzleithner Date: Sat, 29 Aug 2020 03:42:20 +0200 Subject: [PATCH 01/10] Library, move selection: query selectionModel for selected rows currentIndex is not necesarry in sync with the selected rows the user sees. Query the selectionModel and using it results fixes those problems. Also implement wrap-around behaviour. Example: Go to Library Tracks, select track. Go to AutoDJ select track, go back to library. Now use moveSelection controlls will always jump back to the first row because currentIndex returns invalid index. The new implementation fixes this bug. co-authored by ronso0@mixxx.org --- src/widget/wlibrarytableview.cpp | 48 +++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp index 707f67b4886..a3ad364bf55 100644 --- a/src/widget/wlibrarytableview.cpp +++ b/src/widget/wlibrarytableview.cpp @@ -92,25 +92,41 @@ void WLibraryTableView::moveSelection(int delta) { return; } - while(delta != 0) { - // TODO(rryan) what happens if there is nothing selected? - QModelIndex current = currentIndex(); - if(delta > 0) { - // i is positive, so we want to move the highlight down - int row = current.row(); - if (row + 1 < pModel->rowCount()) { - selectRow(row + 1); - } + while (delta != 0) { + QItemSelectionModel* currentSelection = selectionModel(); + if (currentSelection->selectedRows().length() > 0) { + if (delta > 0) { + // i is positive, so we want to move the highlight down + int row = currentSelection->selectedRows().last().row(); + if (row + 1 < pModel->rowCount()) { + selectRow(row + 1); + } else { + // we wrap around at the end of the list so it is faster to get + // to the top of the list again + selectRow(0); + } - delta--; + delta--; + } else { + // i is negative, so move down + int row = currentSelection->selectedRows().first().row(); + if (row - 1 >= 0) { + selectRow(row - 1); + } else { + selectRow(pModel->rowCount() - 1); + } + + delta++; + } } else { - // i is negative, so we want to move the highlight up - int row = current.row(); - if (row - 1 >= 0) { - selectRow(row - 1); + // no selection, so select the first or last element depending on delta + if (delta > 0) { + selectRow(0); + delta--; + } else { + selectRow(pModel->rowCount() - 1); + delta++; } - - delta++; } } } From a5ad421a1df6c305603ac5fb65398f09e99f60cc Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 9 Aug 2021 01:52:07 +0200 Subject: [PATCH 02/10] Library features: add signals to initate save/restore the current model state --- src/library/browse/browsefeature.cpp | 6 ++++++ src/library/browse/browsetablemodel.cpp | 1 + src/library/browse/browsetablemodel.h | 3 +++ src/library/library.cpp | 8 ++++++++ src/library/library.h | 2 ++ src/library/libraryfeature.h | 4 ++++ src/library/mixxxlibraryfeature.cpp | 3 +++ src/library/recording/dlgrecording.h | 1 + src/library/recording/recordingfeature.cpp | 4 ++++ src/library/rhythmbox/rhythmboxfeature.cpp | 3 ++- src/library/serato/seratofeature.cpp | 3 ++- src/library/trackset/baseplaylistfeature.cpp | 5 +++++ src/library/trackset/crate/cratefeature.cpp | 2 ++ src/library/traktor/traktorfeature.cpp | 4 +++- 14 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/library/browse/browsefeature.cpp b/src/library/browse/browsefeature.cpp index ef27f7a17b3..d23bee276ec 100644 --- a/src/library/browse/browsefeature.cpp +++ b/src/library/browse/browsefeature.cpp @@ -41,6 +41,10 @@ BrowseFeature::BrowseFeature( &BrowseFeature::requestAddDir, pLibrary, &Library::slotRequestAddDir); + connect(&m_browseModel, + &BrowseTableModel::restoreModelState, + this, + &LibraryFeature::restoreModelState); m_pAddQuickLinkAction = new QAction(tr("Add to Quick Links"),this); connect(m_pAddQuickLinkAction, @@ -245,6 +249,7 @@ void BrowseFeature::activateChild(const QModelIndex& index) { QString path = item->getData().toString(); if (path == QUICK_LINK_NODE || path == DEVICE_NODE) { + emit saveModelState(); m_browseModel.setPath({}); } else { // Open a security token for this path and if we do not have access, ask @@ -260,6 +265,7 @@ void BrowseFeature::activateChild(const QModelIndex& index) { return; } } + emit saveModelState(); m_browseModel.setPath(std::move(dirAccess)); } emit showTrackModel(&m_proxyModel); diff --git a/src/library/browse/browsetablemodel.cpp b/src/library/browse/browsetablemodel.cpp index fa28c26da95..4945020529f 100644 --- a/src/library/browse/browsetablemodel.cpp +++ b/src/library/browse/browsetablemodel.cpp @@ -351,6 +351,7 @@ void BrowseTableModel::slotInsert(const QList >& rows, appendRow(rows.at(i)); } } + emit restoreModelState(); } TrackModel::Capabilities BrowseTableModel::getCapabilities() const { diff --git a/src/library/browse/browsetablemodel.h b/src/library/browse/browsetablemodel.h index aac0cfafa79..407ac9b1086 100644 --- a/src/library/browse/browsetablemodel.h +++ b/src/library/browse/browsetablemodel.h @@ -87,6 +87,9 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo const QString& mood) const override; #endif // __EXTRA_METADATA__ + signals: + void restoreModelState(); + public slots: void slotClear(BrowseTableModel*); void slotInsert(const QList< QList >&, BrowseTableModel*); diff --git a/src/library/library.cpp b/src/library/library.cpp index bf48d9a33f2..ee7fedd79b3 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -425,6 +425,14 @@ void Library::addFeature(LibraryFeature* feature) { &LibraryFeature::trackSelected, this, &Library::trackSelected); + connect(feature, + &LibraryFeature::saveModelState, + this, + &Library::saveModelState); + connect(feature, + &LibraryFeature::restoreModelState, + this, + &Library::restoreModelState); } void Library::onPlayerManagerTrackAnalyzerProgress( diff --git a/src/library/library.h b/src/library/library.h index 3c6cf53291d..e65394491c8 100644 --- a/src/library/library.h +++ b/src/library/library.h @@ -133,6 +133,8 @@ class Library: public QObject { void exportLibrary(); void exportCrate(CrateId crateId); #endif + void saveModelState(); + void restoreModelState(); void setTrackTableFont(const QFont& font); void setTrackTableRowHeight(int rowHeight); diff --git a/src/library/libraryfeature.h b/src/library/libraryfeature.h index a48f59b1b15..b59c0a23e39 100644 --- a/src/library/libraryfeature.h +++ b/src/library/libraryfeature.h @@ -125,6 +125,10 @@ class LibraryFeature : public QObject { void switchToView(const QString& view); void loadTrack(TrackPointer pTrack); void loadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play = false); + /// saves the scroll, selection and current state of the library model + void saveModelState(); + /// restores the scroll, selection and current state of the library model + void restoreModelState(); void restoreSearch(const QString&); void disableSearch(); // emit this signal before you parse a large music collection, e.g., iTunes, Traktor. diff --git a/src/library/mixxxlibraryfeature.cpp b/src/library/mixxxlibraryfeature.cpp index 20e9866caa4..fbfd6f59f96 100644 --- a/src/library/mixxxlibraryfeature.cpp +++ b/src/library/mixxxlibraryfeature.cpp @@ -176,12 +176,15 @@ void MixxxLibraryFeature::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) { #endif void MixxxLibraryFeature::activate() { + //qDebug() << "MixxxLibraryFeature::activate()"; + emit saveModelState(); emit showTrackModel(m_pLibraryTableModel); emit enableCoverArtDisplay(true); } void MixxxLibraryFeature::activateChild(const QModelIndex& index) { QString itemName = index.data().toString(); + emit saveModelState(); emit switchToView(itemName); if (m_pMissingView && itemName == kMissingTitle) { emit restoreSearch(m_pMissingView->currentSearch()); diff --git a/src/library/recording/dlgrecording.h b/src/library/recording/dlgrecording.h index 226d977c23d..fc8653c3ee3 100644 --- a/src/library/recording/dlgrecording.h +++ b/src/library/recording/dlgrecording.h @@ -45,6 +45,7 @@ class DlgRecording : public QWidget, public Ui::DlgRecording, public virtual Lib void loadTrack(TrackPointer tio); void loadTrackToPlayer(TrackPointer tio, const QString& group, bool play); void restoreSearch(const QString& search); + void restoreModelState(); private: UserSettingsPointer m_pConfig; diff --git a/src/library/recording/recordingfeature.cpp b/src/library/recording/recordingfeature.cpp index 8dc87e373b2..fb8645f12b9 100644 --- a/src/library/recording/recordingfeature.cpp +++ b/src/library/recording/recordingfeature.cpp @@ -61,6 +61,10 @@ void RecordingFeature::bindLibraryWidget(WLibrary* pLibraryWidget, &DlgRecording::restoreSearch, this, &RecordingFeature::restoreSearch); + connect(pRecordingView, + &DlgRecording::restoreModelState, + this, + &RecordingFeature::restoreModelState); } diff --git a/src/library/rhythmbox/rhythmboxfeature.cpp b/src/library/rhythmbox/rhythmboxfeature.cpp index a0dacbe3797..74bb88be18c 100644 --- a/src/library/rhythmbox/rhythmboxfeature.cpp +++ b/src/library/rhythmbox/rhythmboxfeature.cpp @@ -123,7 +123,7 @@ void RhythmboxFeature::activate() { //calls a slot in the sidebar model such that 'Rhythmbox (isLoading)' is displayed. emit featureIsLoading(this, true); } - + emit saveModelState(); emit showTrackModel(m_pRhythmboxTrackModel); emit enableCoverArtDisplay(false); } @@ -132,6 +132,7 @@ void RhythmboxFeature::activateChild(const QModelIndex& index) { //qDebug() << "RhythmboxFeature::activateChild()" << index; QString playlist = index.data().toString(); qDebug() << "Activating " << playlist; + emit saveModelState(); m_pRhythmboxPlaylistModel->setPlaylist(playlist); emit showTrackModel(m_pRhythmboxPlaylistModel); emit enableCoverArtDisplay(false); diff --git a/src/library/serato/seratofeature.cpp b/src/library/serato/seratofeature.cpp index f068d9347c0..9d3aaed10a6 100644 --- a/src/library/serato/seratofeature.cpp +++ b/src/library/serato/seratofeature.cpp @@ -1047,6 +1047,7 @@ void SeratoFeature::activateChild(const QModelIndex& index) { item->setData(QVariant(data)); } else { qDebug() << "Activate Serato Playlist: " << playlist; + emit saveModelState(); m_pSeratoPlaylistModel->setPlaylist(playlist); emit showTrackModel(m_pSeratoPlaylistModel); } @@ -1123,7 +1124,7 @@ void SeratoFeature::onTracksFound() { QString databasePlaylist = m_tracksFuture.result(); qDebug() << "Show Serato Database Playlist: " << databasePlaylist; - + emit saveModelState(); m_pSeratoPlaylistModel->setPlaylist(databasePlaylist); emit showTrackModel(m_pSeratoPlaylistModel); } diff --git a/src/library/trackset/baseplaylistfeature.cpp b/src/library/trackset/baseplaylistfeature.cpp index ea98f2cd26b..4e4276aa922 100644 --- a/src/library/trackset/baseplaylistfeature.cpp +++ b/src/library/trackset/baseplaylistfeature.cpp @@ -184,6 +184,7 @@ void BasePlaylistFeature::activateChild(const QModelIndex& index) { // like the year folder in the history feature return; } + emit saveModelState(); m_pPlaylistTableModel->setTableModel(playlistId); emit showTrackModel(m_pPlaylistTableModel); emit enableCoverArtDisplay(true); @@ -198,6 +199,7 @@ void BasePlaylistFeature::activatePlaylist(int playlistId) { VERIFY_OR_DEBUG_ASSERT(index.isValid()) { return; } + emit saveModelState(); m_lastRightClickedIndex = index; m_pPlaylistTableModel->setTableModel(playlistId); emit showTrackModel(m_pPlaylistTableModel); @@ -501,6 +503,7 @@ void BasePlaylistFeature::slotCreateImportPlaylist() { lastPlaylistId = m_playlistDao.createPlaylist(name); if (lastPlaylistId != kInvalidPlaylistId) { + emit saveModelState(); m_pPlaylistTableModel->setTableModel(lastPlaylistId); } else { QMessageBox::warning(nullptr, @@ -560,6 +563,7 @@ void BasePlaylistFeature::slotExportPlaylist() { m_pLibrary->trackCollectionManager(), "mixxx.db.model.playlist_export")); + emit saveModelState(); pPlaylistTableModel->setTableModel(m_pPlaylistTableModel->getPlaylist()); pPlaylistTableModel->setSort( pPlaylistTableModel->fieldIndex( @@ -602,6 +606,7 @@ void BasePlaylistFeature::slotExportTrackFiles() { m_pLibrary->trackCollectionManager(), "mixxx.db.model.playlist_export")); + emit saveModelState(); pPlaylistTableModel->setTableModel(m_pPlaylistTableModel->getPlaylist()); pPlaylistTableModel->setSort(pPlaylistTableModel->fieldIndex( ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION), diff --git a/src/library/trackset/crate/cratefeature.cpp b/src/library/trackset/crate/cratefeature.cpp index 3c9b81b897a..df73a79472c 100644 --- a/src/library/trackset/crate/cratefeature.cpp +++ b/src/library/trackset/crate/cratefeature.cpp @@ -287,6 +287,7 @@ void CrateFeature::activateChild(const QModelIndex& index) { VERIFY_OR_DEBUG_ASSERT(crateId.isValid()) { return; } + emit saveModelState(); m_crateTableModel.selectCrate(crateId); emit showTrackModel(&m_crateTableModel); emit enableCoverArtDisplay(true); @@ -301,6 +302,7 @@ bool CrateFeature::activateCrate(CrateId crateId) { VERIFY_OR_DEBUG_ASSERT(index.isValid()) { return false; } + emit saveModelState(); m_lastRightClickedIndex = index; m_crateTableModel.selectCrate(crateId); emit showTrackModel(&m_crateTableModel); diff --git a/src/library/traktor/traktorfeature.cpp b/src/library/traktor/traktorfeature.cpp index 8a9c716ff6e..11ab98069b6 100644 --- a/src/library/traktor/traktorfeature.cpp +++ b/src/library/traktor/traktorfeature.cpp @@ -167,7 +167,7 @@ void TraktorFeature::activate() { //calls a slot in the sidebar model such that 'iTunes (isLoading)' is displayed. emit featureIsLoading(this, true); } - + emit saveModelState(); emit showTrackModel(m_pTraktorTableModel); emit enableCoverArtDisplay(false); } @@ -182,6 +182,7 @@ void TraktorFeature::activateChild(const QModelIndex& index) { if (!item->hasChildren()) { qDebug() << "Activate Traktor Playlist: " << item->getData().toString(); + emit saveModelState(); m_pTraktorPlaylistModel->setPlaylist(item->getData().toString()); emit showTrackModel(m_pTraktorPlaylistModel); emit enableCoverArtDisplay(false); @@ -620,6 +621,7 @@ void TraktorFeature::onTrackCollectionLoaded() { m_trackSource->buildIndex(); //m_pTraktorTableModel->select(); + emit saveModelState(); emit showTrackModel(m_pTraktorTableModel); qDebug() << "Traktor library loaded successfully"; } else { From 55febc738bbbabbe1de233e67c8da1179ed3b424 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 9 Aug 2021 02:11:55 +0200 Subject: [PATCH 03/10] Library: add unique modelKey descriptor to table models, get it from WTrackTableView --- src/library/baseexternalplaylistmodel.cpp | 15 +++++++++++- src/library/baseexternalplaylistmodel.h | 12 ++++++---- src/library/basesqltablemodel.cpp | 9 +++++++ src/library/basesqltablemodel.h | 4 +++- src/library/browse/browsetablemodel.cpp | 16 +++++++++++++ src/library/browse/browsetablemodel.h | 1 + src/library/hiddentablemodel.cpp | 9 +++++++ src/library/hiddentablemodel.h | 2 ++ src/library/missingtablemodel.cpp | 9 +++++++ src/library/missingtablemodel.h | 2 ++ src/library/playlisttablemodel.cpp | 9 +++++++ src/library/playlisttablemodel.h | 2 ++ src/library/proxytrackmodel.cpp | 4 ++++ src/library/proxytrackmodel.h | 1 + src/library/trackmodel.h | 5 ++++ .../trackset/crate/cratetablemodel.cpp | 24 ++++++++++++++++++- src/library/trackset/crate/cratetablemodel.h | 1 + src/widget/wlibrarytableview.cpp | 18 ++++++++++++++ src/widget/wlibrarytableview.h | 1 + src/widget/wtracktableview.cpp | 13 +++++----- src/widget/wtracktableview.h | 3 +++ 21 files changed, 146 insertions(+), 14 deletions(-) diff --git a/src/library/baseexternalplaylistmodel.cpp b/src/library/baseexternalplaylistmodel.cpp index 44f77ab0905..c944fad4aee 100644 --- a/src/library/baseexternalplaylistmodel.cpp +++ b/src/library/baseexternalplaylistmodel.cpp @@ -17,7 +17,8 @@ BaseExternalPlaylistModel::BaseExternalPlaylistModel(QObject* parent, : BaseSqlTableModel(parent, pTrackCollectionManager, settingsNamespace), m_playlistsTable(playlistsTable), m_playlistTracksTable(playlistTracksTable), - m_trackSource(trackSource) { + m_trackSource(trackSource), + m_currentPlaylistId(-1) { } BaseExternalPlaylistModel::~BaseExternalPlaylistModel() { @@ -134,6 +135,7 @@ void BaseExternalPlaylistModel::setPlaylist(const QString& playlist_path) { return; } + m_currentPlaylistId = playlistId; playlistViewColumns.last() = LIBRARYTABLE_PREVIEW; setTable(playlistViewTable, playlistViewColumns.first(), playlistViewColumns, m_trackSource); setDefaultSort(fieldIndex(ColumnCache::COLUMN_PLAYLISTTRACKSTABLE_POSITION), @@ -163,3 +165,14 @@ TrackModel::Capabilities BaseExternalPlaylistModel::getCapabilities() const { Capability::LoadToPreviewDeck | Capability::LoadToSampler; } + +QString BaseExternalPlaylistModel::modelKey(bool noSearch) const { + if (noSearch) { + return QStringLiteral("external:") + + QString::number(m_currentPlaylistId); + } + return QStringLiteral("external:") + + QString::number(m_currentPlaylistId) + + QStringLiteral("#") + + currentSearch(); +} diff --git a/src/library/baseexternalplaylistmodel.h b/src/library/baseexternalplaylistmodel.h index ba8f8b81b27..38cb0546723 100644 --- a/src/library/baseexternalplaylistmodel.h +++ b/src/library/baseexternalplaylistmodel.h @@ -1,16 +1,16 @@ #pragma once -#include #include -#include -#include #include +#include +#include +#include -#include "library/trackmodel.h" #include "library/basesqltablemodel.h" -#include "library/librarytablemodel.h" #include "library/dao/playlistdao.h" #include "library/dao/trackdao.h" +#include "library/librarytablemodel.h" +#include "library/trackmodel.h" class BaseExternalPlaylistModel : public BaseSqlTableModel { Q_OBJECT @@ -28,6 +28,7 @@ class BaseExternalPlaylistModel : public BaseSqlTableModel { bool isColumnInternal(int column) override; Qt::ItemFlags flags(const QModelIndex &index) const override; Capabilities getCapabilities() const override; + QString modelKey(bool noSearch) const override; private: TrackId doGetTrackId(const TrackPointer& pTrack) const override; @@ -35,4 +36,5 @@ class BaseExternalPlaylistModel : public BaseSqlTableModel { QString m_playlistsTable; QString m_playlistTracksTable; QSharedPointer m_trackSource; + int m_currentPlaylistId; }; diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index fa902614eea..dc482e9808a 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -613,6 +613,15 @@ int BaseSqlTableModel::fieldIndex(const QString& fieldName) const { return tableIndex; } +QString BaseSqlTableModel::modelKey(bool noSearch) const { + if (noSearch) { + return QStringLiteral("table:") + m_tableName; + } + return QStringLiteral("table:") + m_tableName + + QStringLiteral("#") + + currentSearch(); +} + QVariant BaseSqlTableModel::rawValue( const QModelIndex& index) const { DEBUG_ASSERT(index.isValid()); diff --git a/src/library/basesqltablemodel.h b/src/library/basesqltablemodel.h index a7c46f60897..6d013140d58 100644 --- a/src/library/basesqltablemodel.h +++ b/src/library/basesqltablemodel.h @@ -71,6 +71,8 @@ class BaseSqlTableModel : public BaseTrackTableModel { int fieldIndex( ColumnCache::Column column) const final; + QString modelKey(bool noSearch) const override; + protected: /////////////////////////////////////////////////////////////////////////// // Inherited from BaseTrackTableModel @@ -96,6 +98,7 @@ class BaseSqlTableModel : public BaseTrackTableModel { QList getTrackRefs(const QModelIndexList& indices) const; QSqlDatabase m_database; + QString m_tableName; QString m_tableOrderBy; int m_columnIndexBySortColumnId[static_cast(TrackModel::SortColumnId::IdMax)]; @@ -138,7 +141,6 @@ class BaseSqlTableModel : public BaseTrackTableModel { QVector m_rowInfo; - QString m_tableName; QString m_idColumn; QSharedPointer m_trackSource; QStringList m_tableColumns; diff --git a/src/library/browse/browsetablemodel.cpp b/src/library/browse/browsetablemodel.cpp index 4945020529f..35f4edbcf75 100644 --- a/src/library/browse/browsetablemodel.cpp +++ b/src/library/browse/browsetablemodel.cpp @@ -362,6 +362,22 @@ TrackModel::Capabilities BrowseTableModel::getCapabilities() const { Capability::LoadToSampler; } +QString BrowseTableModel::modelKey(bool noSearch) const { + // TODO re-introduce m_current_directory / m_currentPath + // see https://github.com/mixxxdj/mixxx/commit/dcc6f9e71aac3ee56627bb93c4e37e93cf675bfd#diff-12546d29721e9b62bfba012a790de93c1e5c045a9ac4cc47f48d9c7d93b99d70L166 + // or make m_pBrowseThread->m_path public + //m_current_directory.dir().path() + + if (noSearch) { + return QStringLiteral("browse:"); + // + m_current_directory.dir().path(); + } else { + return QStringLiteral("browse:") + + //m_current_directory.dir().path() + + QStringLiteral("#") + + currentSearch(); + } +} + Qt::ItemFlags BrowseTableModel::flags(const QModelIndex& index) const { Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index); diff --git a/src/library/browse/browsetablemodel.h b/src/library/browse/browsetablemodel.h index 407ac9b1086..aa58ff56946 100644 --- a/src/library/browse/browsetablemodel.h +++ b/src/library/browse/browsetablemodel.h @@ -77,6 +77,7 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo bool isColumnSortable(int column) const override; TrackModel::SortColumnId sortColumnIdFromColumnIndex(int index) const override; int columnIndexFromSortColumnId(TrackModel::SortColumnId sortColumn) const override; + QString modelKey(bool noSearch) const override; bool updateTrackGenre( Track* pTrack, diff --git a/src/library/hiddentablemodel.cpp b/src/library/hiddentablemodel.cpp index db1a488d387..297ba469915 100644 --- a/src/library/hiddentablemodel.cpp +++ b/src/library/hiddentablemodel.cpp @@ -91,3 +91,12 @@ Qt::ItemFlags HiddenTableModel::flags(const QModelIndex& index) const { TrackModel::Capabilities HiddenTableModel::getCapabilities() const { return Capability::Purge | Capability::Unhide; } + +QString HiddenTableModel::modelKey(bool noSearch) const { + if (noSearch) { + return QStringLiteral("hidden:") + m_tableName; + } + return QStringLiteral("hidden:") + m_tableName + + QStringLiteral("#") + + currentSearch(); +} diff --git a/src/library/hiddentablemodel.h b/src/library/hiddentablemodel.h index f2fabc9d3e5..64cfcf9be1a 100644 --- a/src/library/hiddentablemodel.h +++ b/src/library/hiddentablemodel.h @@ -15,4 +15,6 @@ class HiddenTableModel final : public BaseSqlTableModel { void unhideTracks(const QModelIndexList& indices) final; Qt::ItemFlags flags(const QModelIndex &index) const final; Capabilities getCapabilities() const final; + + QString modelKey(bool noSearch) const override; }; diff --git a/src/library/missingtablemodel.cpp b/src/library/missingtablemodel.cpp index 59ea189cc71..a2dcd76c269 100644 --- a/src/library/missingtablemodel.cpp +++ b/src/library/missingtablemodel.cpp @@ -89,3 +89,12 @@ Qt::ItemFlags MissingTableModel::flags(const QModelIndex &index) const { TrackModel::Capabilities MissingTableModel::getCapabilities() const { return Capability::Purge; } + +QString MissingTableModel::modelKey(bool noSearch) const { + if (noSearch) { + return QStringLiteral("missing:") + m_tableName; + } + return QStringLiteral("missing:") + m_tableName + + QStringLiteral("#") + + currentSearch(); +} diff --git a/src/library/missingtablemodel.h b/src/library/missingtablemodel.h index c57a16e0dc8..94761a9449e 100644 --- a/src/library/missingtablemodel.h +++ b/src/library/missingtablemodel.h @@ -20,4 +20,6 @@ class MissingTableModel final : public BaseSqlTableModel { void purgeTracks(const QModelIndexList& indices) final; Qt::ItemFlags flags(const QModelIndex &index) const final; Capabilities getCapabilities() const final; + + QString modelKey(bool noSearch) const override; }; diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index d7dd78f28a3..f47aea67452 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -345,6 +345,15 @@ TrackModel::Capabilities PlaylistTableModel::getCapabilities() const { return caps; } +QString PlaylistTableModel::modelKey(bool noSearch) const { + if (noSearch) { + return QStringLiteral("playlist:") + m_tableName; + } + return QStringLiteral("playlist:") + m_tableName + + QStringLiteral("#") + + currentSearch(); +} + void PlaylistTableModel::playlistsChanged(const QSet& playlistIds) { if (playlistIds.contains(m_iPlaylistId)) { select(); // Repopulate the data model. diff --git a/src/library/playlisttablemodel.h b/src/library/playlisttablemodel.h index c2d0b92a470..0b5dce17115 100644 --- a/src/library/playlisttablemodel.h +++ b/src/library/playlisttablemodel.h @@ -30,6 +30,8 @@ class PlaylistTableModel final : public TrackSetTableModel { Capabilities getCapabilities() const final; + QString modelKey(bool noSearch) const override; + private slots: void playlistsChanged(const QSet& playlistIds); diff --git a/src/library/proxytrackmodel.cpp b/src/library/proxytrackmodel.cpp index 8579b4eb9e9..d301c9b9e41 100644 --- a/src/library/proxytrackmodel.cpp +++ b/src/library/proxytrackmodel.cpp @@ -69,6 +69,10 @@ void ProxyTrackModel::search(const QString& searchText, const QString& extraFilt } } +QString ProxyTrackModel::modelKey(bool noSearch) const { + return m_pTrackModel ? m_pTrackModel->modelKey(noSearch) : QString(); +} + const QString ProxyTrackModel::currentSearch() const { if (m_bHandleSearches) { return m_currentSearch; diff --git a/src/library/proxytrackmodel.h b/src/library/proxytrackmodel.h index 9f2b7d05ecb..db211970813 100644 --- a/src/library/proxytrackmodel.h +++ b/src/library/proxytrackmodel.h @@ -54,6 +54,7 @@ class ProxyTrackModel : public QSortFilterProxyModel, public TrackModel { // Inherited from QAbstractItemModel void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) final; + QString modelKey(bool noSearch) const override; private: TrackModel* m_pTrackModel; diff --git a/src/library/trackmodel.h b/src/library/trackmodel.h index 639bf4da4c7..ba1122d27a5 100644 --- a/src/library/trackmodel.h +++ b/src/library/trackmodel.h @@ -203,6 +203,11 @@ class TrackModel { virtual void select() { } + /// @brief modelKey returns a unique identifier for the model + /// @param noSearch don't include the current search in the key + /// @param baseOnly return only a identifier for the whole subsystem + virtual QString modelKey(bool noSearch) const = 0; + virtual bool updateTrackGenre( Track* pTrack, const QString& genre) const = 0; diff --git a/src/library/trackset/crate/cratetablemodel.cpp b/src/library/trackset/crate/cratetablemodel.cpp index e024fc36156..c2145ea7da2 100644 --- a/src/library/trackset/crate/cratetablemodel.cpp +++ b/src/library/trackset/crate/cratetablemodel.cpp @@ -13,7 +13,10 @@ CrateTableModel::CrateTableModel( QObject* pParent, TrackCollectionManager* pTrackCollectionManager) - : TrackSetTableModel(pParent, pTrackCollectionManager, "mixxx.db.model.crate") { + : TrackSetTableModel( + pParent, + pTrackCollectionManager, + "mixxx.db.model.crate") { } void CrateTableModel::selectCrate(CrateId crateId) { @@ -178,3 +181,22 @@ void CrateTableModel::removeTracks(const QModelIndexList& indices) { select(); } + +QString CrateTableModel::modelKey(bool noSearch) const { + if (this->m_selectedCrate.isValid()) { + if (noSearch) { + return QStringLiteral("crate:") + + QString::number(m_selectedCrate.value()); + } + return QStringLiteral("crate:") + + QString::number(m_selectedCrate.value()) + + QStringLiteral("#") + + currentSearch(); + } else { + if (noSearch) { + return QStringLiteral("crate"); + } + return QStringLiteral("crate#") + + currentSearch(); + } +} diff --git a/src/library/trackset/crate/cratetablemodel.h b/src/library/trackset/crate/cratetablemodel.h index 510b2086546..0020b4e06a7 100644 --- a/src/library/trackset/crate/cratetablemodel.h +++ b/src/library/trackset/crate/cratetablemodel.h @@ -23,6 +23,7 @@ class CrateTableModel final : public TrackSetTableModel { int addTracks(const QModelIndex& index, const QList& locations) final; Capabilities getCapabilities() const final; + QString modelKey(bool noSearch) const override; private: CrateId m_selectedCrate; diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp index a3ad364bf55..6047f6128ac 100644 --- a/src/widget/wlibrarytableview.cpp +++ b/src/widget/wlibrarytableview.cpp @@ -176,6 +176,24 @@ void WLibraryTableView::setSelectedClick(bool enable) { } } +void WLibraryTableView::saveCurrentViewState() { + const QAbstractItemModel* currentModel = model(); + QString key = getModelStateKey(); + if (!currentModel || key.isEmpty()) { + return; + } + saveTrackModelState(currentModel, key); +} + +void WLibraryTableView::restoreCurrentViewState() { + const QAbstractItemModel* currentModel = model(); + QString key = getModelStateKey(); + if (!currentModel || key.isEmpty()) { + return; + } + restoreTrackModelState(currentModel, key); +} + void WLibraryTableView::focusInEvent(QFocusEvent* event) { QTableView::focusInEvent(event); diff --git a/src/widget/wlibrarytableview.h b/src/widget/wlibrarytableview.h index 89d4f1bc4ac..32cafe92249 100644 --- a/src/widget/wlibrarytableview.h +++ b/src/widget/wlibrarytableview.h @@ -50,6 +50,7 @@ class WLibraryTableView : public QTableView, public virtual LibraryView { void saveNoSearchVScrollBarPos(); void restoreNoSearchVScrollBarPos(); + virtual QString getModelStateKey() const = 0; private: void loadVScrollBarPosState(); diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index 0b1dced9457..b8918b1d247 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -1022,12 +1022,13 @@ bool WTrackTableView::hasFocus() const { return QWidget::hasFocus(); } -void WTrackTableView::saveCurrentVScrollBarPos() { - saveVScrollBarPos(getTrackModel()); -} - -void WTrackTableView::restoreCurrentVScrollBarPos() { - restoreVScrollBarPos(getTrackModel()); +QString WTrackTableView::getModelStateKey() const { + TrackModel* trackModel = getTrackModel(); + if (trackModel) { + bool noSearch = trackModel->currentSearch().trimmed().isEmpty(); + return trackModel->modelKey(noSearch); + } + return QString(); } void WTrackTableView::keyNotationChanged() { diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h index 9db21a36d23..6ddb84d7a6b 100644 --- a/src/widget/wtracktableview.h +++ b/src/widget/wtracktableview.h @@ -74,6 +74,9 @@ class WTrackTableView : public WLibraryTableView { void slotSortingChanged(int headerSection, Qt::SortOrder order); void keyNotationChanged(); + protected: + QString getModelStateKey() const override; + private: void addToAutoDJ(PlaylistDAO::AutoDJSendLoc loc); void dragMoveEvent(QDragMoveEvent * event) override; From 02e63a83f923ad8f87205a4fbae414bf0f398b43 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sun, 8 Aug 2021 23:05:31 +0200 Subject: [PATCH 04/10] Browsemodel: store current directory, create unique model keys for state save/restore --- src/library/browse/browsetablemodel.cpp | 25 ++++++++++++------------- src/library/browse/browsetablemodel.h | 4 ++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/library/browse/browsetablemodel.cpp b/src/library/browse/browsetablemodel.cpp index 35f4edbcf75..01c70ca3e90 100644 --- a/src/library/browse/browsetablemodel.cpp +++ b/src/library/browse/browsetablemodel.cpp @@ -210,9 +210,18 @@ void BrowseTableModel::addSearchColumn(int index) { } void BrowseTableModel::setPath(mixxx::FileAccess path) { + if (path.info().hasLocation()) { + m_currentDirectory = path.info().locationPath(); + } else { + clearCurrentDir(); + } m_pBrowseThread->executePopulation(std::move(path), this); } +void BrowseTableModel::clearCurrentDir() { + m_currentDirectory = QString(); +} + TrackPointer BrowseTableModel::getTrack(const QModelIndex& index) const { return getTrackByRef(TrackRef::fromFilePath(getTrackLocation(index))); } @@ -363,19 +372,9 @@ TrackModel::Capabilities BrowseTableModel::getCapabilities() const { } QString BrowseTableModel::modelKey(bool noSearch) const { - // TODO re-introduce m_current_directory / m_currentPath - // see https://github.com/mixxxdj/mixxx/commit/dcc6f9e71aac3ee56627bb93c4e37e93cf675bfd#diff-12546d29721e9b62bfba012a790de93c1e5c045a9ac4cc47f48d9c7d93b99d70L166 - // or make m_pBrowseThread->m_path public - //m_current_directory.dir().path() + - if (noSearch) { - return QStringLiteral("browse:"); - // + m_current_directory.dir().path(); - } else { - return QStringLiteral("browse:") + - //m_current_directory.dir().path() + - QStringLiteral("#") + - currentSearch(); - } + // Browse feature does currently not support searching. + Q_UNUSED(noSearch); + return QStringLiteral("browse:") + m_currentDirectory; } Qt::ItemFlags BrowseTableModel::flags(const QModelIndex& index) const { diff --git a/src/library/browse/browsetablemodel.h b/src/library/browse/browsetablemodel.h index aa58ff56946..667f4279dc4 100644 --- a/src/library/browse/browsetablemodel.h +++ b/src/library/browse/browsetablemodel.h @@ -52,7 +52,10 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo BrowseTableModel(QObject* parent, TrackCollectionManager* pTrackCollectionManager, RecordingManager* pRec); virtual ~BrowseTableModel(); + // initiate table population, store path void setPath(mixxx::FileAccess path); + // clear stored path + void clearCurrentDir(); TrackPointer getTrack(const QModelIndex& index) const override; TrackPointer getTrackByRef(const TrackRef& trackRef) const override; @@ -104,6 +107,7 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo QList m_searchColumns; RecordingManager* m_pRecordingManager; BrowseThreadPointer m_pBrowseThread; + QString m_currentDirectory; QString m_previewDeckGroup; int m_columnIndexBySortColumnId[static_cast(TrackModel::SortColumnId::IdMax)]; QMap m_sortColumnIdByColumnIndex; From 96240ac4c81ff1f348559a1e5aeaa1905bf96f46 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 9 Aug 2021 02:55:59 +0200 Subject: [PATCH 05/10] Library: allow views to save/restore the current state library views store states in a QCache in WTrackTableView incl. * track selection * current index (focused track) * scroll positions, horizontal + vertical with a unique key composed of * feature (playlist/crate/browse ...) * child item (playlistId/crateId/directory ...) * current search term Credits for this and the required commits go to https://github.com/poelzi I just boiled down some picks from stalled https://github.com/mixxxdj/mixxx/pull/3063 --- src/library/autodj/dlgautodj.cpp | 8 ++ src/library/autodj/dlgautodj.h | 2 + src/library/dlganalysis.cpp | 8 ++ src/library/dlganalysis.h | 6 +- src/library/dlghidden.cpp | 8 ++ src/library/dlghidden.h | 8 +- src/library/dlgmissing.cpp | 7 ++ src/library/dlgmissing.h | 8 +- src/library/library.cpp | 9 +- src/library/library.h | 2 +- src/library/libraryfeature.h | 2 +- src/library/libraryview.h | 2 + src/library/recording/dlgrecording.cpp | 12 +++ src/library/recording/dlgrecording.h | 2 + src/widget/wlibrary.cpp | 19 ++--- src/widget/wlibrarytableview.cpp | 111 +++++++++++++++---------- src/widget/wlibrarytableview.h | 49 +++++------ src/widget/wtracktableview.cpp | 36 ++++---- src/widget/wtracktableview.h | 10 ++- 19 files changed, 191 insertions(+), 118 deletions(-) diff --git a/src/library/autodj/dlgautodj.cpp b/src/library/autodj/dlgautodj.cpp index a116213549c..d32939e6602 100644 --- a/src/library/autodj/dlgautodj.cpp +++ b/src/library/autodj/dlgautodj.cpp @@ -370,3 +370,11 @@ void DlgAutoDJ::updateSelectionInfo() { bool DlgAutoDJ::hasFocus() const { return m_pTrackTableView->hasFocus(); } + +void DlgAutoDJ::saveCurrentViewState() { + m_pTrackTableView->saveCurrentViewState(); +} + +void DlgAutoDJ::restoreCurrentViewState() { + m_pTrackTableView->restoreCurrentViewState(); +} diff --git a/src/library/autodj/dlgautodj.h b/src/library/autodj/dlgautodj.h index de5a7499d59..372220a984b 100644 --- a/src/library/autodj/dlgautodj.h +++ b/src/library/autodj/dlgautodj.h @@ -33,6 +33,8 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView { void loadSelectedTrack() override; void loadSelectedTrackToGroup(const QString& group, bool play) override; void moveSelection(int delta) override; + void saveCurrentViewState() override; + void restoreCurrentViewState() override; public slots: void shufflePlaylistButton(bool buttonChecked); diff --git a/src/library/dlganalysis.cpp b/src/library/dlganalysis.cpp index 4c34f81ba86..3c7ffe4635e 100644 --- a/src/library/dlganalysis.cpp +++ b/src/library/dlganalysis.cpp @@ -225,3 +225,11 @@ void DlgAnalysis::installEventFilter(QObject* pFilter) { QWidget::installEventFilter(pFilter); m_pAnalysisLibraryTableView->installEventFilter(pFilter); } + +void DlgAnalysis::saveCurrentViewState() { + m_pAnalysisLibraryTableView->saveCurrentViewState(); +} + +void DlgAnalysis::restoreCurrentViewState() { + m_pAnalysisLibraryTableView->restoreCurrentViewState(); +} diff --git a/src/library/dlganalysis.h b/src/library/dlganalysis.h index e279fcfc8a9..c1777251894 100644 --- a/src/library/dlganalysis.h +++ b/src/library/dlganalysis.h @@ -3,11 +3,11 @@ #include #include -#include "preferences/usersettings.h" +#include "analyzer/analyzerprogress.h" #include "library/analysislibrarytablemodel.h" #include "library/libraryview.h" #include "library/ui_dlganalysis.h" -#include "analyzer/analyzerprogress.h" +#include "preferences/usersettings.h" class AnalysisLibraryTableModel; class WAnalysisLibraryTableView; @@ -34,6 +34,8 @@ class DlgAnalysis : public QWidget, public Ui::DlgAnalysis, public virtual Libra inline const QString currentSearch() { return m_pAnalysisLibraryTableModel->currentSearch(); } + void saveCurrentViewState() override; + void restoreCurrentViewState() override; public slots: void tableSelectionChanged(const QItemSelection& selected, diff --git a/src/library/dlghidden.cpp b/src/library/dlghidden.cpp index 266c2c01444..95937ff379c 100644 --- a/src/library/dlghidden.cpp +++ b/src/library/dlghidden.cpp @@ -123,3 +123,11 @@ void DlgHidden::selectionChanged(const QItemSelection &selected, bool DlgHidden::hasFocus() const { return m_pTrackTableView->hasFocus(); } + +void DlgHidden::saveCurrentViewState() { + m_pTrackTableView->saveCurrentViewState(); +} + +void DlgHidden::restoreCurrentViewState() { + m_pTrackTableView->restoreCurrentViewState(); +} diff --git a/src/library/dlghidden.h b/src/library/dlghidden.h index 9e83163997f..1ad201cbaf4 100644 --- a/src/library/dlghidden.h +++ b/src/library/dlghidden.h @@ -2,11 +2,11 @@ #include -#include "library/ui_dlghidden.h" -#include "preferences/usersettings.h" +#include "controllers/keyboard/keyboardeventfilter.h" #include "library/library.h" #include "library/libraryview.h" -#include "controllers/keyboard/keyboardeventfilter.h" +#include "library/ui_dlghidden.h" +#include "preferences/usersettings.h" class WLibrary; class WTrackTableView; @@ -25,6 +25,8 @@ class DlgHidden : public QWidget, public Ui::DlgHidden, public LibraryView { bool hasFocus() const override; void onSearch(const QString& text) override; QString currentSearch(); + void saveCurrentViewState() override; + void restoreCurrentViewState() override; public slots: void clicked(); diff --git a/src/library/dlgmissing.cpp b/src/library/dlgmissing.cpp index 5cdf14b0392..5bd64fb3660 100644 --- a/src/library/dlgmissing.cpp +++ b/src/library/dlgmissing.cpp @@ -92,3 +92,10 @@ void DlgMissing::selectionChanged(const QItemSelection &selected, bool DlgMissing::hasFocus() const { return m_pTrackTableView->hasFocus(); } + +void DlgMissing::saveCurrentViewState() { + m_pTrackTableView->saveCurrentViewState(); +}; +void DlgMissing::restoreCurrentViewState() { + m_pTrackTableView->restoreCurrentViewState(); +}; diff --git a/src/library/dlgmissing.h b/src/library/dlgmissing.h index 9fd5985eec3..c2e44cdb766 100644 --- a/src/library/dlgmissing.h +++ b/src/library/dlgmissing.h @@ -2,11 +2,11 @@ #include -#include "library/ui_dlgmissing.h" -#include "preferences/usersettings.h" +#include "controllers/keyboard/keyboardeventfilter.h" #include "library/library.h" #include "library/libraryview.h" -#include "controllers/keyboard/keyboardeventfilter.h" +#include "library/ui_dlgmissing.h" +#include "preferences/usersettings.h" class WLibrary; class WTrackTableView; @@ -25,6 +25,8 @@ class DlgMissing : public QWidget, public Ui::DlgMissing, public LibraryView { bool hasFocus() const override; void onSearch(const QString& text) override; QString currentSearch(); + void saveCurrentViewState() override; + void restoreCurrentViewState() override; public slots: void clicked(); diff --git a/src/library/library.cpp b/src/library/library.cpp index ee7fedd79b3..85215d022e9 100644 --- a/src/library/library.cpp +++ b/src/library/library.cpp @@ -355,7 +355,14 @@ void Library::bindLibraryWidget( &Library::switchToView, pLibraryWidget, &WLibrary::switchToView); - + connect(this, + &Library::saveModelState, + pTrackTableView, + &WTrackTableView::slotSaveCurrentViewState); + connect(this, + &Library::restoreModelState, + pTrackTableView, + &WTrackTableView::slotRestoreCurrentViewState); connect(pTrackTableView, &WTrackTableView::trackSelected, this, diff --git a/src/library/library.h b/src/library/library.h index e65394491c8..1e9de2531d9 100644 --- a/src/library/library.h +++ b/src/library/library.h @@ -119,7 +119,7 @@ class Library: public QObject { void onSkinLoadFinished(); signals: - void showTrackModel(QAbstractItemModel* model); + void showTrackModel(QAbstractItemModel* model, bool restoreState = true); void switchToView(const QString& view); void loadTrack(TrackPointer pTrack); void loadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play = false); diff --git a/src/library/libraryfeature.h b/src/library/libraryfeature.h index b59c0a23e39..9b4a55eaf28 100644 --- a/src/library/libraryfeature.h +++ b/src/library/libraryfeature.h @@ -121,7 +121,7 @@ class LibraryFeature : public QObject { Q_UNUSED(index); } signals: - void showTrackModel(QAbstractItemModel* model); + void showTrackModel(QAbstractItemModel* model, bool restoreState = true); void switchToView(const QString& view); void loadTrack(TrackPointer pTrack); void loadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play = false); diff --git a/src/library/libraryview.h b/src/library/libraryview.h index 112c294ca2a..5394645e0bf 100644 --- a/src/library/libraryview.h +++ b/src/library/libraryview.h @@ -26,6 +26,8 @@ class LibraryView { virtual void slotAddToAutoDJBottom() {}; virtual void slotAddToAutoDJTop() {}; virtual void slotAddToAutoDJReplace() {}; + virtual void saveCurrentViewState(){}; + virtual void restoreCurrentViewState(){}; /// If applicable, requests that the LibraryView load the selected track to /// the specified group. Does nothing otherwise. diff --git a/src/library/recording/dlgrecording.cpp b/src/library/recording/dlgrecording.cpp index c66373aff93..9d6b685c2a7 100644 --- a/src/library/recording/dlgrecording.cpp +++ b/src/library/recording/dlgrecording.cpp @@ -69,6 +69,10 @@ DlgRecording::DlgRecording( &RecordingManager::durationRecorded, this, &DlgRecording::slotDurationRecorded); + connect(&m_browseModel, + &BrowseTableModel::restoreModelState, + m_pTrackTableView, + &WTrackTableView::restoreCurrentViewState); QBoxLayout* box = qobject_cast(layout()); VERIFY_OR_DEBUG_ASSERT(box) { //Assumes the form layout is a QVBox/QHBoxLayout! @@ -193,3 +197,11 @@ void DlgRecording::refreshLabels() { labelRecFilename->setText(recFile); labelRecStatistics->setText(recData); } + +void DlgRecording::saveCurrentViewState() { + m_pTrackTableView->saveCurrentViewState(); +} + +void DlgRecording::restoreCurrentViewState() { + m_pTrackTableView->restoreCurrentViewState(); +} diff --git a/src/library/recording/dlgrecording.h b/src/library/recording/dlgrecording.h index fc8653c3ee3..e996a433acd 100644 --- a/src/library/recording/dlgrecording.h +++ b/src/library/recording/dlgrecording.h @@ -33,6 +33,8 @@ class DlgRecording : public QWidget, public Ui::DlgRecording, public virtual Lib void loadSelectedTrackToGroup(const QString& group, bool play) override; void moveSelection(int delta) override; inline const QString currentSearch() { return m_proxyModel.currentSearch(); } + void saveCurrentViewState() override; + void restoreCurrentViewState() override; public slots: void slotRecordingStateChanged(bool); diff --git a/src/widget/wlibrary.cpp b/src/widget/wlibrary.cpp index 89b92ddb6ab..ee674c3637b 100644 --- a/src/widget/wlibrary.cpp +++ b/src/widget/wlibrary.cpp @@ -52,14 +52,9 @@ void WLibrary::switchToView(const QString& name) { const auto lock = lockMutex(&m_mutex); //qDebug() << "WLibrary::switchToView" << name; - WTrackTableView* ttView = qobject_cast( + LibraryView* oldLibraryView = dynamic_cast( currentWidget()); - if (ttView != nullptr){ - //qDebug("trying to save position"); - ttView->saveCurrentVScrollBarPos(); - } - QWidget* widget = m_viewMap.value(name, nullptr); if (widget != nullptr) { LibraryView * lview = dynamic_cast(widget); @@ -70,17 +65,13 @@ void WLibrary::switchToView(const QString& name) { return; } if (currentWidget() != widget) { + if (oldLibraryView) { + oldLibraryView->saveCurrentViewState(); + } //qDebug() << "WLibrary::setCurrentWidget" << name; setCurrentWidget(widget); lview->onShow(); - } - - WTrackTableView* ttWidgetView = qobject_cast( - widget); - - if (ttWidgetView != nullptr){ - qDebug("trying to restore position"); - ttWidgetView->restoreCurrentVScrollBarPos(); + lview->restoreCurrentViewState(); } } } diff --git a/src/widget/wlibrarytableview.cpp b/src/widget/wlibrarytableview.cpp index 6047f6128ac..ee2a847981e 100644 --- a/src/widget/wlibrarytableview.cpp +++ b/src/widget/wlibrarytableview.cpp @@ -12,14 +12,16 @@ #include "widget/wskincolor.h" #include "widget/wwidget.h" +namespace { +// number of entries in the model cache +constexpr int kModelCacheSize = 1000; +} // namespace + WLibraryTableView::WLibraryTableView(QWidget* parent, - UserSettingsPointer pConfig, - const ConfigKey& vScrollBarPosKey) + UserSettingsPointer pConfig) : QTableView(parent), m_pConfig(pConfig), - m_vScrollBarPosKey(vScrollBarPosKey) { - loadVScrollBarPosState(); - + m_modelStateCache(kModelCacheSize) { // Setup properties for table // Editing starts when clicking on an already selected item. @@ -55,35 +57,6 @@ WLibraryTableView::WLibraryTableView(QWidget* parent, WLibraryTableView::~WLibraryTableView() { } -void WLibraryTableView::loadVScrollBarPosState() { - // TODO(rryan) I'm not sure I understand the value in saving the v-scrollbar - // position across restarts of Mixxx. Now that we have different views for - // each mode, the views should just maintain their scrollbar position when - // you switch views. We should discuss this. - m_noSearchVScrollBarPos = m_pConfig->getValueString(m_vScrollBarPosKey).toInt(); -} - -void WLibraryTableView::restoreNoSearchVScrollBarPos() { - // Restore the scrollbar's position (scroll to that spot) - // when the search has been cleared - //qDebug() << "restoreNoSearchVScrollBarPos()" << m_noSearchVScrollBarPos; - updateGeometries(); - verticalScrollBar()->setValue(m_noSearchVScrollBarPos); -} - -void WLibraryTableView::saveNoSearchVScrollBarPos() { - // Save the scrollbar's position so we can return here after - // a search is cleared. - //qDebug() << "saveNoSearchVScrollBarPos()" << m_noSearchVScrollBarPos; - m_noSearchVScrollBarPos = verticalScrollBar()->value(); -} - - -void WLibraryTableView::saveVScrollBarPosState() { - //Save the vertical scrollbar position. - int scrollbarPosition = verticalScrollBar()->value(); - m_pConfig->set(m_vScrollBarPosKey, ConfigValue(scrollbarPosition)); -} void WLibraryTableView::moveSelection(int delta) { QAbstractItemModel* pModel = model(); @@ -131,19 +104,73 @@ void WLibraryTableView::moveSelection(int delta) { } } -void WLibraryTableView::saveVScrollBarPos(TrackModel* key){ - m_vScrollBarPosValues[key] = verticalScrollBar()->value(); +void WLibraryTableView::saveTrackModelState( + const QAbstractItemModel* model, const QString& key) { + //qDebug() << "saveTrackModelState:" << model << key; + VERIFY_OR_DEBUG_ASSERT(model) { + return; + } + VERIFY_OR_DEBUG_ASSERT(!key.isEmpty()) { + return; + } + ModelState* state = m_modelStateCache.take(key); + if (!state) { + state = new ModelState(); + } + + state->verticalScrollPosition = verticalScrollBar()->value(); + state->horizontalScrollPosition = horizontalScrollBar()->value(); + + state->selectedRows = selectionModel()->selectedRows(); + + const QModelIndex currIndex = selectionModel()->currentIndex(); + if (currIndex.isValid()) { + state->currentIndex = currIndex; + } else { + state->currentIndex = QModelIndex(); + } + + m_modelStateCache.insert(key, state, 1); } -void WLibraryTableView::restoreVScrollBarPos(TrackModel* key){ - updateGeometries(); +void WLibraryTableView::restoreTrackModelState( + const QAbstractItemModel* model, const QString& key) { + //qDebug() << "restoreTrackModelState:" << model << key; + //qDebug() << m_modelStateCache.keys(); + if (model == nullptr) { + return; + } - if (m_vScrollBarPosValues.contains(key)){ - verticalScrollBar()->setValue(m_vScrollBarPosValues[key]); - }else{ - m_vScrollBarPosValues[key] = 0; + ModelState* state = m_modelStateCache.take(key); + if (!state) { + // No previous state for model key, + // reset scroll bars and current index verticalScrollBar()->setValue(0); + horizontalScrollBar()->setValue(0); + setCurrentIndex(QModelIndex()); + return; } + + verticalScrollBar()->setValue(state->verticalScrollPosition); + horizontalScrollBar()->setValue(state->horizontalScrollPosition); + + auto selection = selectionModel(); + selection->clearSelection(); + QModelIndexList selectedRows = state->selectedRows; + if (!selectedRows.isEmpty()) { + for (auto index : qAsConst(selectedRows)) { + selection->select(index, + QItemSelectionModel::Select | QItemSelectionModel::Rows); + } + } + + QModelIndex currIndex = state->currentIndex; + if (currIndex.isValid()) { + selection->setCurrentIndex(currIndex, QItemSelectionModel::NoUpdate); + } + + // reinsert the state into the cache + m_modelStateCache.insert(key, state, 1); } void WLibraryTableView::setTrackTableFont(const QFont& font) { diff --git a/src/widget/wlibrarytableview.h b/src/widget/wlibrarytableview.h index 32cafe92249..6fde3e9e25e 100644 --- a/src/widget/wlibrarytableview.h +++ b/src/widget/wlibrarytableview.h @@ -1,6 +1,8 @@ #pragma once +#include #include +#include #include #include @@ -13,25 +15,32 @@ class TrackModel; class WLibraryTableView : public QTableView, public virtual LibraryView { Q_OBJECT + struct ModelState { + int horizontalScrollPosition; + int verticalScrollPosition; + QModelIndexList selectedRows; + QModelIndex currentIndex; + }; + public: WLibraryTableView(QWidget* parent, - UserSettingsPointer pConfig, - const ConfigKey& vScrollBarPosKey); + UserSettingsPointer pConfig); ~WLibraryTableView() override; void moveSelection(int delta) override; - /** - * Saves current position of scrollbar using string key - * can be any value but should invariant for model - * @param key unique for trackmodel - */ - void saveVScrollBarPos(TrackModel* key); - /** - * Finds scrollbar value associated with model by given key and restores it - * @param key unique for trackmodel - */ - void restoreVScrollBarPos(TrackModel* key); + /// @brief saveTrackModelState function saves current positions of scrollbars, + /// current item selection and current index in a QCache using a unique + /// string key - can be any value but should invariant for model + /// @param key unique for trackmodel + void saveTrackModelState(const QAbstractItemModel* model, const QString& key); + /// @brief restoreTrackModelState function finds scrollbar positions, + /// item selection and current index values associated with model by given + /// key and restores it + /// @param key unique for trackmodel + void restoreTrackModelState(const QAbstractItemModel* model, const QString& key); + void saveCurrentViewState() override; + void restoreCurrentViewState() override; signals: void loadTrack(TrackPointer pTrack); @@ -47,21 +56,9 @@ class WLibraryTableView : public QTableView, public virtual LibraryView { protected: void focusInEvent(QFocusEvent* event) override; - - void saveNoSearchVScrollBarPos(); - void restoreNoSearchVScrollBarPos(); virtual QString getModelStateKey() const = 0; private: - void loadVScrollBarPosState(); - void saveVScrollBarPosState(); - const UserSettingsPointer m_pConfig; - const ConfigKey m_vScrollBarPosKey; - - QMap m_vScrollBarPosValues; - - // The position of the vertical scrollbar slider, eg. before a search is - // executed - int m_noSearchVScrollBarPos; + QCache m_modelStateCache; }; diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index b8918b1d247..24c946b23f3 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -49,9 +49,7 @@ WTrackTableView::WTrackTableView(QWidget* parent, Library* pLibrary, double backgroundColorOpacity, bool sorting) - : WLibraryTableView(parent, - pConfig, - kVScrollBarPosConfigKey), + : WLibraryTableView(parent, pConfig), m_pConfig(pConfig), m_pLibrary(pLibrary), m_backgroundColorOpacity(backgroundColorOpacity), @@ -150,7 +148,7 @@ void WTrackTableView::slotGuiTick50ms(double /*unused*/) { } // slot -void WTrackTableView::loadTrackModel(QAbstractItemModel* model) { +void WTrackTableView::loadTrackModel(QAbstractItemModel* model, bool restoreState) { qDebug() << "WTrackTableView::loadTrackModel()" << model; TrackModel* trackModel = dynamic_cast(model); @@ -162,21 +160,20 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel* model) { return; } - // If the model has not changed - // there's no need to exchange the headers - // this will cause a small GUI freeze + // If the model has not changed there's no need to exchange the headers + // which would cause a small GUI freeze if (getTrackModel() == trackModel) { // Re-sort the table even if the track model is the same. This triggers // a select() if the table is dirty. doSortByColumn(horizontalHeader()->sortIndicatorSection(), horizontalHeader()->sortIndicatorOrder()); + + if (restoreState) { + restoreCurrentViewState(); + } return; } - // saving current vertical bar position - // using address of track model as key - saveVScrollBarPos(getTrackModel()); - setVisible(false); // Save the previous track model's header state @@ -325,9 +322,10 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel* model) { setVisible(true); - restoreVScrollBarPos(trackModel); - // restoring scrollBar position using model pointer as key - // scrollbar positions with respect to different models are backed by map + // trigger restoring scrollBar position, selection etc. + if (restoreState) { + restoreCurrentViewState(); + } initTrackMenu(); } @@ -474,15 +472,9 @@ void WTrackTableView::contextMenuEvent(QContextMenuEvent* event) { void WTrackTableView::onSearch(const QString& text) { TrackModel* trackModel = getTrackModel(); if (trackModel) { - bool searchWasEmpty = false; - if (trackModel->currentSearch().isEmpty()) { - saveNoSearchVScrollBarPos(); - searchWasEmpty = true; - } + saveCurrentViewState(); trackModel->search(text); - if (!searchWasEmpty && text.isEmpty()) { - restoreNoSearchVScrollBarPos(); - } + restoreCurrentViewState(); } } diff --git a/src/widget/wtracktableview.h b/src/widget/wtracktableview.h index 6ddb84d7a6b..47eaa55b9cc 100644 --- a/src/widget/wtracktableview.h +++ b/src/widget/wtracktableview.h @@ -40,8 +40,6 @@ class WTrackTableView : public WLibraryTableView { TrackModel::SortColumnId getColumnIdFromCurrentIndex() override; QList getSelectedTrackIds() const; void setSelectedTracks(const QList& tracks); - void saveCurrentVScrollBarPos(); - void restoreCurrentVScrollBarPos(); double getBackgroundColorOpacity() const { return m_backgroundColorOpacity; @@ -53,7 +51,7 @@ class WTrackTableView : public WLibraryTableView { } public slots: - void loadTrackModel(QAbstractItemModel* model); + void loadTrackModel(QAbstractItemModel* model, bool restoreState = false); void slotMouseDoubleClicked(const QModelIndex &); void slotUnhide(); void slotPurge(); @@ -61,6 +59,12 @@ class WTrackTableView : public WLibraryTableView { void slotAddToAutoDJBottom() override; void slotAddToAutoDJTop() override; void slotAddToAutoDJReplace() override; + void slotSaveCurrentViewState() { + saveCurrentViewState(); + }; + void slotRestoreCurrentViewState() { + restoreCurrentViewState(); + }; private slots: void doSortByColumn(int headerSection, Qt::SortOrder sortOrder); From 5c04ed15e5ac1cf595c65c5ff0a0f01311d05ab0 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Mon, 9 Aug 2021 03:34:25 +0200 Subject: [PATCH 06/10] WTrackTableView::loadTrackModel: assert earlier --- src/widget/wtracktableview.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp index 24c946b23f3..00d9e31bf7f 100644 --- a/src/widget/wtracktableview.cpp +++ b/src/widget/wtracktableview.cpp @@ -151,11 +151,11 @@ void WTrackTableView::slotGuiTick50ms(double /*unused*/) { void WTrackTableView::loadTrackModel(QAbstractItemModel* model, bool restoreState) { qDebug() << "WTrackTableView::loadTrackModel()" << model; - TrackModel* trackModel = dynamic_cast(model); - VERIFY_OR_DEBUG_ASSERT(model) { return; } + TrackModel* trackModel = dynamic_cast(model); + VERIFY_OR_DEBUG_ASSERT(trackModel) { return; } From f26f1c29dbe77192b9fb23ee058b9c4919d15f2b Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sat, 25 Sep 2021 23:18:25 +0200 Subject: [PATCH 07/10] libraryview.h: remove ; after empty implementations --- src/library/libraryview.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/library/libraryview.h b/src/library/libraryview.h index 5394645e0bf..73813e9eada 100644 --- a/src/library/libraryview.h +++ b/src/library/libraryview.h @@ -12,7 +12,7 @@ class LibraryView { public: - virtual ~LibraryView() {}; + virtual ~LibraryView() {} virtual void onShow() = 0; virtual bool hasFocus() const = 0; @@ -21,13 +21,13 @@ class LibraryView { /// If applicable, requests that the LibraryView load the selected /// track. Does nothing otherwise. - virtual void loadSelectedTrack() {}; + virtual void loadSelectedTrack() {} - virtual void slotAddToAutoDJBottom() {}; - virtual void slotAddToAutoDJTop() {}; - virtual void slotAddToAutoDJReplace() {}; - virtual void saveCurrentViewState(){}; - virtual void restoreCurrentViewState(){}; + virtual void slotAddToAutoDJBottom() {} + virtual void slotAddToAutoDJTop() {} + virtual void slotAddToAutoDJReplace() {} + virtual void saveCurrentViewState(){} + virtual void restoreCurrentViewState(){} /// If applicable, requests that the LibraryView load the selected track to /// the specified group. Does nothing otherwise. @@ -42,9 +42,9 @@ class LibraryView { virtual TrackModel::SortColumnId getColumnIdFromCurrentIndex() { return TrackModel::SortColumnId::Invalid; - }; + } /// If applicable, requests that the LibraryView changes the track color of /// the selected track. Does nothing otherwise. - virtual void assignPreviousTrackColor(){}; - virtual void assignNextTrackColor(){}; + virtual void assignPreviousTrackColor(){} + virtual void assignNextTrackColor(){} }; From 54c7486922be1aa1c95c5fd1e05b8811134a18cb Mon Sep 17 00:00:00 2001 From: ronso0 Date: Tue, 2 Nov 2021 23:38:15 +0100 Subject: [PATCH 08/10] Browse model: inline clearPath() --- src/library/browse/browsetablemodel.cpp | 6 +----- src/library/browse/browsetablemodel.h | 2 -- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/library/browse/browsetablemodel.cpp b/src/library/browse/browsetablemodel.cpp index 260db052d53..77c013a5ecc 100644 --- a/src/library/browse/browsetablemodel.cpp +++ b/src/library/browse/browsetablemodel.cpp @@ -213,15 +213,11 @@ void BrowseTableModel::setPath(mixxx::FileAccess path) { if (path.info().hasLocation()) { m_currentDirectory = path.info().locationPath(); } else { - clearCurrentDir(); + m_currentDirectory = QString(); } m_pBrowseThread->executePopulation(std::move(path), this); } -void BrowseTableModel::clearCurrentDir() { - m_currentDirectory = QString(); -} - TrackPointer BrowseTableModel::getTrack(const QModelIndex& index) const { return getTrackByRef(TrackRef::fromFilePath(getTrackLocation(index))); } diff --git a/src/library/browse/browsetablemodel.h b/src/library/browse/browsetablemodel.h index 30b7adadb70..f4c20d889e5 100644 --- a/src/library/browse/browsetablemodel.h +++ b/src/library/browse/browsetablemodel.h @@ -54,8 +54,6 @@ class BrowseTableModel final : public QStandardItemModel, public virtual TrackMo // initiate table population, store path void setPath(mixxx::FileAccess path); - // clear stored path - void clearCurrentDir(); TrackPointer getTrack(const QModelIndex& index) const override; TrackPointer getTrackByRef(const TrackRef& trackRef) const override; From c1d93016a2e4bb096712a6eeaa28b4b966c59ad9 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Tue, 2 Nov 2021 23:40:04 +0100 Subject: [PATCH 09/10] library models: move modelKey prefixes to namespaces --- src/library/baseexternalplaylistmodel.cpp | 10 ++++++++-- src/library/basesqltablemodel.cpp | 6 ++++-- src/library/hiddentablemodel.cpp | 10 ++++++++-- src/library/missingtablemodel.cpp | 5 +++-- src/library/playlisttablemodel.cpp | 10 ++++++++-- src/library/trackset/crate/cratetablemodel.cpp | 16 +++++++++++----- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/library/baseexternalplaylistmodel.cpp b/src/library/baseexternalplaylistmodel.cpp index c944fad4aee..3382dd24c67 100644 --- a/src/library/baseexternalplaylistmodel.cpp +++ b/src/library/baseexternalplaylistmodel.cpp @@ -8,6 +8,12 @@ #include "moc_baseexternalplaylistmodel.cpp" #include "track/track.h" +namespace { + +const QString kModelName = "external:"; + +} // anonymous namespace + BaseExternalPlaylistModel::BaseExternalPlaylistModel(QObject* parent, TrackCollectionManager* pTrackCollectionManager, const char* settingsNamespace, @@ -168,10 +174,10 @@ TrackModel::Capabilities BaseExternalPlaylistModel::getCapabilities() const { QString BaseExternalPlaylistModel::modelKey(bool noSearch) const { if (noSearch) { - return QStringLiteral("external:") + + return kModelName + QString::number(m_currentPlaylistId); } - return QStringLiteral("external:") + + return kModelName + QString::number(m_currentPlaylistId) + QStringLiteral("#") + currentSearch(); diff --git a/src/library/basesqltablemodel.cpp b/src/library/basesqltablemodel.cpp index 582c3b353b5..ae539e3aa7c 100644 --- a/src/library/basesqltablemodel.cpp +++ b/src/library/basesqltablemodel.cpp @@ -34,6 +34,8 @@ constexpr int kMaxSortColumns = 3; // Constant for getModelSetting(name) const QString COLUMNS_SORTING = QStringLiteral("ColumnsSorting"); +const QString kModelName = "table:"; + } // anonymous namespace BaseSqlTableModel::BaseSqlTableModel( @@ -615,9 +617,9 @@ int BaseSqlTableModel::fieldIndex(const QString& fieldName) const { QString BaseSqlTableModel::modelKey(bool noSearch) const { if (noSearch) { - return QStringLiteral("table:") + m_tableName; + return kModelName + m_tableName; } - return QStringLiteral("table:") + m_tableName + + return kModelName + m_tableName + QStringLiteral("#") + currentSearch(); } diff --git a/src/library/hiddentablemodel.cpp b/src/library/hiddentablemodel.cpp index 297ba469915..2f787e318ca 100644 --- a/src/library/hiddentablemodel.cpp +++ b/src/library/hiddentablemodel.cpp @@ -5,6 +5,12 @@ #include "library/trackcollectionmanager.h" #include "moc_hiddentablemodel.cpp" +namespace { + +const QString kModelName = "hidden:"; + +} // anonymous namespace + HiddenTableModel::HiddenTableModel(QObject* parent, TrackCollectionManager* pTrackCollectionManager) : BaseSqlTableModel(parent, pTrackCollectionManager, "mixxx.db.model.missing") { @@ -94,9 +100,9 @@ TrackModel::Capabilities HiddenTableModel::getCapabilities() const { QString HiddenTableModel::modelKey(bool noSearch) const { if (noSearch) { - return QStringLiteral("hidden:") + m_tableName; + return kModelName + m_tableName; } - return QStringLiteral("hidden:") + m_tableName + + return kModelName + m_tableName + QStringLiteral("#") + currentSearch(); } diff --git a/src/library/missingtablemodel.cpp b/src/library/missingtablemodel.cpp index a2dcd76c269..9c72a6d4509 100644 --- a/src/library/missingtablemodel.cpp +++ b/src/library/missingtablemodel.cpp @@ -8,6 +8,7 @@ namespace { const QString kMissingFilter = "mixxx_deleted=0 AND fs_deleted=1"; +const QString kModelName = "missing:"; } // anonymous namespace @@ -92,9 +93,9 @@ TrackModel::Capabilities MissingTableModel::getCapabilities() const { QString MissingTableModel::modelKey(bool noSearch) const { if (noSearch) { - return QStringLiteral("missing:") + m_tableName; + return kModelName + m_tableName; } - return QStringLiteral("missing:") + m_tableName + + return kModelName + m_tableName + QStringLiteral("#") + currentSearch(); } diff --git a/src/library/playlisttablemodel.cpp b/src/library/playlisttablemodel.cpp index f135be58c16..6052ec012e2 100644 --- a/src/library/playlisttablemodel.cpp +++ b/src/library/playlisttablemodel.cpp @@ -7,6 +7,12 @@ #include "library/trackcollectionmanager.h" #include "moc_playlisttablemodel.cpp" +namespace { + +const QString kModelName = "playlist:"; + +} // anonymous namespace + PlaylistTableModel::PlaylistTableModel(QObject* parent, TrackCollectionManager* pTrackCollectionManager, const char* settingsNamespace, @@ -350,9 +356,9 @@ TrackModel::Capabilities PlaylistTableModel::getCapabilities() const { QString PlaylistTableModel::modelKey(bool noSearch) const { if (noSearch) { - return QStringLiteral("playlist:") + m_tableName; + return kModelName + m_tableName; } - return QStringLiteral("playlist:") + m_tableName + + return kModelName + m_tableName + QStringLiteral("#") + currentSearch(); } diff --git a/src/library/trackset/crate/cratetablemodel.cpp b/src/library/trackset/crate/cratetablemodel.cpp index c2145ea7da2..77a31febba2 100644 --- a/src/library/trackset/crate/cratetablemodel.cpp +++ b/src/library/trackset/crate/cratetablemodel.cpp @@ -10,6 +10,12 @@ #include "track/track.h" #include "util/db/fwdsqlquery.h" +namespace { + +const QString kModelName = "crate"; + +} // anonymous namespace + CrateTableModel::CrateTableModel( QObject* pParent, TrackCollectionManager* pTrackCollectionManager) @@ -183,20 +189,20 @@ void CrateTableModel::removeTracks(const QModelIndexList& indices) { } QString CrateTableModel::modelKey(bool noSearch) const { - if (this->m_selectedCrate.isValid()) { + if (m_selectedCrate.isValid()) { if (noSearch) { - return QStringLiteral("crate:") + + return kModelName + QStringLiteral(":") + QString::number(m_selectedCrate.value()); } - return QStringLiteral("crate:") + + return kModelName + QStringLiteral(":") + QString::number(m_selectedCrate.value()) + QStringLiteral("#") + currentSearch(); } else { if (noSearch) { - return QStringLiteral("crate"); + return kModelName; } - return QStringLiteral("crate#") + + return kModelName + QStringLiteral("#") + currentSearch(); } } From 7bc610fc42d71418602877d77847e0e9f357f4ee Mon Sep 17 00:00:00 2001 From: ronso0 Date: Thu, 4 Nov 2021 13:58:30 +0100 Subject: [PATCH 10/10] libraryvie.h: satisfy clang-format --- src/library/libraryview.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/library/libraryview.h b/src/library/libraryview.h index cc2d8141c91..74c9fa7d3cf 100644 --- a/src/library/libraryview.h +++ b/src/library/libraryview.h @@ -12,7 +12,8 @@ class LibraryView { public: - virtual ~LibraryView() {} + virtual ~LibraryView() { + } virtual void onShow() = 0; virtual bool hasFocus() const = 0; @@ -23,13 +24,19 @@ class LibraryView { /// If applicable, requests that the LibraryView load the selected /// track. Does nothing otherwise. - virtual void loadSelectedTrack() {} + virtual void loadSelectedTrack() { + } - virtual void slotAddToAutoDJBottom() {} - virtual void slotAddToAutoDJTop() {} - virtual void slotAddToAutoDJReplace() {} - virtual void saveCurrentViewState(){} - virtual void restoreCurrentViewState(){} + virtual void slotAddToAutoDJBottom() { + } + virtual void slotAddToAutoDJTop() { + } + virtual void slotAddToAutoDJReplace() { + } + virtual void saveCurrentViewState() { + } + virtual void restoreCurrentViewState() { + } /// If applicable, requests that the LibraryView load the selected track to /// the specified group. Does nothing otherwise. @@ -47,6 +54,8 @@ class LibraryView { } /// If applicable, requests that the LibraryView changes the track color of /// the selected track. Does nothing otherwise. - virtual void assignPreviousTrackColor(){} - virtual void assignNextTrackColor(){} + virtual void assignPreviousTrackColor() { + } + virtual void assignNextTrackColor() { + } };