diff --git a/src/library/baseexternalplaylistmodel.h b/src/library/baseexternalplaylistmodel.h index bdfdbbb4c993..d35b70f8b2f1 100644 --- a/src/library/baseexternalplaylistmodel.h +++ b/src/library/baseexternalplaylistmodel.h @@ -29,7 +29,11 @@ class BaseExternalPlaylistModel : public BaseSqlTableModel { bool isColumnInternal(int column) override; Qt::ItemFlags flags(const QModelIndex &index) const override; Capabilities getCapabilities() const override; - QString modelKey() const override { + QString modelKey(bool noSearch = false) const override { + if (noSearch) { + return QStringLiteral("external/") + + QString::number(m_currentPlaylistId); + } return QStringLiteral("external/") + QString::number(m_currentPlaylistId) + QStringLiteral("#") + diff --git a/src/library/basesqltablemodel.h b/src/library/basesqltablemodel.h index 5435283c75e6..a2b4cc64fc99 100644 --- a/src/library/basesqltablemodel.h +++ b/src/library/basesqltablemodel.h @@ -71,9 +71,12 @@ class BaseSqlTableModel : public BaseTrackTableModel { int fieldIndex( ColumnCache::Column column) const final; - virtual QString modelKey() const override { - return QLatin1String("table:") + m_tableName + - QLatin1String("#") + + virtual QString modelKey(bool noSearch = false) const override { + if (noSearch) { + return QStringLiteral("table:") + m_tableName; + } + return QStringLiteral("table:") + m_tableName + + QStringLiteral("#") + currentSearch(); } diff --git a/src/library/browse/browsetablemodel.h b/src/library/browse/browsetablemodel.h index 750a87de376c..e5515b4ab848 100644 --- a/src/library/browse/browsetablemodel.h +++ b/src/library/browse/browsetablemodel.h @@ -77,15 +77,20 @@ 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() const override { + QString modelKey(bool noSearch = false) const override { // 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() + - return QStringLiteral("browse/") + - QString("directory Unknown") + - QStringLiteral("#") + - currentSearch(); + if (noSearch) { + return QStringLiteral("browse/"); + // + m_current_directory.dir().path(); + } else { + return QStringLiteral("browse/") + + //m_current_directory.dir().path() + + QStringLiteral("#") + + currentSearch(); + } } signals: diff --git a/src/library/hiddentablemodel.h b/src/library/hiddentablemodel.h index c220192c2506..36208c04b733 100644 --- a/src/library/hiddentablemodel.h +++ b/src/library/hiddentablemodel.h @@ -16,7 +16,10 @@ class HiddenTableModel final : public BaseSqlTableModel { Qt::ItemFlags flags(const QModelIndex &index) const final; Capabilities getCapabilities() const final; - virtual QString modelKey() const override { + virtual QString modelKey(bool noSearch = false) const override { + if (noSearch) { + return QStringLiteral("hidden:") + m_tableName; + } return QStringLiteral("hidden:") + m_tableName + QStringLiteral("#") + currentSearch(); diff --git a/src/library/missingtablemodel.h b/src/library/missingtablemodel.h index c3298c762078..0526170cf219 100644 --- a/src/library/missingtablemodel.h +++ b/src/library/missingtablemodel.h @@ -21,7 +21,10 @@ class MissingTableModel final : public BaseSqlTableModel { Qt::ItemFlags flags(const QModelIndex &index) const final; Capabilities getCapabilities() const final; - virtual QString modelKey() const override { + virtual QString modelKey(bool noSearch = false) const override { + if (noSearch) { + return QStringLiteral("missing:") + m_tableName; + } return QStringLiteral("missing:") + m_tableName + QStringLiteral("#") + currentSearch(); diff --git a/src/library/proxytrackmodel.cpp b/src/library/proxytrackmodel.cpp index 6ca7af7ac6b6..e368367fdc64 100644 --- a/src/library/proxytrackmodel.cpp +++ b/src/library/proxytrackmodel.cpp @@ -69,8 +69,8 @@ void ProxyTrackModel::search(const QString& searchText, const QString& extraFilt } } -QString ProxyTrackModel::modelKey() const { - return m_pTrackModel ? m_pTrackModel->modelKey() : QString(); +QString ProxyTrackModel::modelKey(bool noSearch) const { + return m_pTrackModel ? m_pTrackModel->modelKey(noSearch) : QString(); } const QString ProxyTrackModel::currentSearch() const { diff --git a/src/library/proxytrackmodel.h b/src/library/proxytrackmodel.h index 56d8ecd545b1..dd7e9cd5f00f 100644 --- a/src/library/proxytrackmodel.h +++ b/src/library/proxytrackmodel.h @@ -46,7 +46,7 @@ class ProxyTrackModel : public QSortFilterProxyModel, public TrackModel { // Inherited from QAbstractItemModel void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) final; - QString modelKey() const override; + QString modelKey(bool noSearch = false) const override; private: TrackModel* m_pTrackModel; diff --git a/src/library/trackmodel.h b/src/library/trackmodel.h index c0d45a1a99eb..1fcc31cb9043 100644 --- a/src/library/trackmodel.h +++ b/src/library/trackmodel.h @@ -204,11 +204,10 @@ class TrackModel { virtual void select() { } - virtual QString modelKey() const { - return pointerToQString(this) + - QLatin1String("#") + - currentSearch(); - } + /// @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 = false) const = 0; private: QSqlDatabase m_db; diff --git a/src/library/trackset/crate/cratetablemodel.cpp b/src/library/trackset/crate/cratetablemodel.cpp index d3a2d781fc47..f9ddac7dad39 100644 --- a/src/library/trackset/crate/cratetablemodel.cpp +++ b/src/library/trackset/crate/cratetablemodel.cpp @@ -182,13 +182,20 @@ void CrateTableModel::removeTracks(const QModelIndexList& indices) { select(); } -QString CrateTableModel::modelKey() const { +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 2450c6ff6a4c..94e6dd39e393 100644 --- a/src/library/trackset/crate/cratetablemodel.h +++ b/src/library/trackset/crate/cratetablemodel.h @@ -23,7 +23,7 @@ class CrateTableModel final : public TrackSetTableModel { int addTracks(const QModelIndex& index, const QList& locations) final; Capabilities getCapabilities() const final; - QString modelKey() const override; + QString modelKey(bool noSearch = false) const override; private: CrateId m_selectedCrate; diff --git a/src/widget/wlibrarytableview.h b/src/widget/wlibrarytableview.h index 662b11ccabbc..c2c41aa9af21 100644 --- a/src/widget/wlibrarytableview.h +++ b/src/widget/wlibrarytableview.h @@ -30,16 +30,16 @@ class WLibraryTableView : public QTableView, public virtual LibraryView { void moveSelection(int delta) override; - /// @brief saveTrackModelState function saves current position of scrollbar - /// using string key - can be any value but should invariant for model + /// @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 value associated with model - /// by given key and restores it + /// @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); - /// @brief clears the state cache until it's size is = kClearModelStatesLowWatermark void saveCurrentViewState() override; void restoreCurrentViewState() override;