Skip to content

Commit

Permalink
make restoreCurrentViewState() return true at success
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Nov 22, 2021
1 parent 758fdbd commit a5a01ce
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/library/autodj/dlgautodj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,6 @@ void DlgAutoDJ::saveCurrentViewState() {
m_pTrackTableView->saveCurrentViewState();
}

void DlgAutoDJ::restoreCurrentViewState() {
m_pTrackTableView->restoreCurrentViewState();
bool DlgAutoDJ::restoreCurrentViewState() {
return m_pTrackTableView->restoreCurrentViewState();
}
2 changes: 1 addition & 1 deletion src/library/autodj/dlgautodj.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DlgAutoDJ : public QWidget, public Ui::DlgAutoDJ, public LibraryView {
void loadSelectedTrackToGroup(const QString& group, bool play) override;
void moveSelection(int delta) override;
void saveCurrentViewState() override;
void restoreCurrentViewState() override;
bool restoreCurrentViewState() override;

public slots:
void shufflePlaylistButton(bool buttonChecked);
Expand Down
4 changes: 2 additions & 2 deletions src/library/dlganalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,6 @@ void DlgAnalysis::saveCurrentViewState() {
m_pAnalysisLibraryTableView->saveCurrentViewState();
}

void DlgAnalysis::restoreCurrentViewState() {
m_pAnalysisLibraryTableView->restoreCurrentViewState();
bool DlgAnalysis::restoreCurrentViewState() {
return m_pAnalysisLibraryTableView->restoreCurrentViewState();
}
2 changes: 1 addition & 1 deletion src/library/dlganalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DlgAnalysis : public QWidget, public Ui::DlgAnalysis, public virtual Libra
return m_pAnalysisLibraryTableModel->currentSearch();
}
void saveCurrentViewState() override;
void restoreCurrentViewState() override;
bool restoreCurrentViewState() override;

public slots:
void tableSelectionChanged(const QItemSelection& selected,
Expand Down
4 changes: 2 additions & 2 deletions src/library/dlghidden.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void DlgHidden::saveCurrentViewState() {
m_pTrackTableView->saveCurrentViewState();
}

void DlgHidden::restoreCurrentViewState() {
m_pTrackTableView->restoreCurrentViewState();
bool DlgHidden::restoreCurrentViewState() {
return m_pTrackTableView->restoreCurrentViewState();
}

void DlgHidden::setFocus() {
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlghidden.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DlgHidden : public QWidget, public Ui::DlgHidden, public LibraryView {
void onSearch(const QString& text) override;
QString currentSearch();
void saveCurrentViewState() override;
void restoreCurrentViewState() override;
bool restoreCurrentViewState() override;

public slots:
void clicked();
Expand Down
5 changes: 3 additions & 2 deletions src/library/dlgmissing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ bool DlgMissing::hasFocus() const {
void DlgMissing::saveCurrentViewState() {
m_pTrackTableView->saveCurrentViewState();
};
void DlgMissing::restoreCurrentViewState() {
m_pTrackTableView->restoreCurrentViewState();

bool DlgMissing::restoreCurrentViewState() {
return m_pTrackTableView->restoreCurrentViewState();
};

void DlgMissing::setFocus() {
Expand Down
2 changes: 1 addition & 1 deletion src/library/dlgmissing.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DlgMissing : public QWidget, public Ui::DlgMissing, public LibraryView {
void onSearch(const QString& text) override;
QString currentSearch();
void saveCurrentViewState() override;
void restoreCurrentViewState() override;
bool restoreCurrentViewState() override;

public slots:
void clicked();
Expand Down
5 changes: 3 additions & 2 deletions src/library/libraryview.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class LibraryView {
}
virtual void saveCurrentViewState() {
}
virtual void restoreCurrentViewState() {
}
virtual bool restoreCurrentViewState() {
return false;
};

/// If applicable, requests that the LibraryView load the selected track to
/// the specified group. Does nothing otherwise.
Expand Down
4 changes: 2 additions & 2 deletions src/library/recording/dlgrecording.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,6 @@ void DlgRecording::saveCurrentViewState() {
m_pTrackTableView->saveCurrentViewState();
}

void DlgRecording::restoreCurrentViewState() {
m_pTrackTableView->restoreCurrentViewState();
bool DlgRecording::restoreCurrentViewState() {
return m_pTrackTableView->restoreCurrentViewState();
}
2 changes: 1 addition & 1 deletion src/library/recording/dlgrecording.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class DlgRecording : public QWidget, public Ui::DlgRecording, public virtual Lib
void moveSelection(int delta) override;
inline const QString currentSearch() { return m_proxyModel.currentSearch(); }
void saveCurrentViewState() override;
void restoreCurrentViewState() override;
bool restoreCurrentViewState() override;

public slots:
void slotRecordingStateChanged(bool);
Expand Down
13 changes: 7 additions & 6 deletions src/widget/wlibrarytableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ void WLibraryTableView::saveTrackModelState(
m_modelStateCache.insert(key, state, 1);
}

void WLibraryTableView::restoreTrackModelState(
bool WLibraryTableView::restoreTrackModelState(
const QAbstractItemModel* model, const QString& key) {
//qDebug() << "restoreTrackModelState:" << model << key;
//qDebug() << m_modelStateCache.keys();
if (model == nullptr) {
return;
return false;
}

ModelState* state = m_modelStateCache.take(key);
Expand All @@ -148,7 +148,7 @@ void WLibraryTableView::restoreTrackModelState(
verticalScrollBar()->setValue(0);
horizontalScrollBar()->setValue(0);
setCurrentIndex(QModelIndex());
return;
return false;
}

verticalScrollBar()->setValue(state->verticalScrollPosition);
Expand All @@ -171,6 +171,7 @@ void WLibraryTableView::restoreTrackModelState(

// reinsert the state into the cache
m_modelStateCache.insert(key, state, 1);
return true;
}

void WLibraryTableView::setTrackTableFont(const QFont& font) {
Expand Down Expand Up @@ -212,13 +213,13 @@ void WLibraryTableView::saveCurrentViewState() {
saveTrackModelState(currentModel, key);
}

void WLibraryTableView::restoreCurrentViewState() {
bool WLibraryTableView::restoreCurrentViewState() {
const QAbstractItemModel* currentModel = model();
QString key = getModelStateKey();
if (!currentModel || key.isEmpty()) {
return;
return false;
}
restoreTrackModelState(currentModel, key);
return restoreTrackModelState(currentModel, key);
}

void WLibraryTableView::focusInEvent(QFocusEvent* event) {
Expand Down
7 changes: 5 additions & 2 deletions src/widget/wlibrarytableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ class WLibraryTableView : public QTableView, public virtual LibraryView {
/// 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);
/// @return true if restore succeeded
bool restoreTrackModelState(const QAbstractItemModel* model, const QString& key);
void saveCurrentViewState() override;
void restoreCurrentViewState() override;
/// @brief restores current view state.
/// @return true if restore succeeded
bool restoreCurrentViewState() override;

signals:
void loadTrack(TrackPointer pTrack);
Expand Down
4 changes: 2 additions & 2 deletions src/widget/wtracktableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class WTrackTableView : public WLibraryTableView {
void slotSaveCurrentViewState() {
saveCurrentViewState();
};
void slotRestoreCurrentViewState() {
restoreCurrentViewState();
bool slotRestoreCurrentViewState() {
return restoreCurrentViewState();
};

protected:
Expand Down

0 comments on commit a5a01ce

Please sign in to comment.