Skip to content

Commit

Permalink
Create independent states only on demand
Browse files Browse the repository at this point in the history
Use a shared state pre feature but have a action to crete/delete
independent states for each feature. This is less confusing to use.

co-authored by ronso0@mixxx.org
  • Loading branch information
poelzi authored and ronso0 committed Aug 8, 2021
1 parent 414febd commit c74d74d
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 27 deletions.
6 changes: 5 additions & 1 deletion src/library/baseexternalplaylistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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("#") +
Expand Down
9 changes: 6 additions & 3 deletions src/library/basesqltablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
15 changes: 10 additions & 5 deletions src/library/browse/browsetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion src/library/hiddentablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion src/library/missingtablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/library/proxytrackmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/library/proxytrackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions src/library/trackmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/library/trackset/crate/cratetablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion src/library/trackset/crate/cratetablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CrateTableModel final : public TrackSetTableModel {
int addTracks(const QModelIndex& index, const QList<QString>& locations) final;

Capabilities getCapabilities() const final;
QString modelKey() const override;
QString modelKey(bool noSearch = false) const override;

private:
CrateId m_selectedCrate;
Expand Down
12 changes: 6 additions & 6 deletions src/widget/wlibrarytableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit c74d74d

Please sign in to comment.