Skip to content

Commit

Permalink
cleanup state safe/restoration code
Browse files Browse the repository at this point in the history
co-authored by [email protected]
  • Loading branch information
poelzi authored and ronso0 committed Aug 6, 2021
1 parent 60056f4 commit 2299715
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 24 deletions.
8 changes: 2 additions & 6 deletions src/library/libraryview.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ class LibraryView {
virtual void slotAddToAutoDJBottom() {};
virtual void slotAddToAutoDJTop() {};
virtual void slotAddToAutoDJReplace() {};
virtual void saveCurrentViewState() {
qDebug() << "empty save model sate";
};
virtual void restoreCurrentViewState() {
qDebug() << "empty restore model sate";
};
virtual void saveCurrentViewState(){};
virtual void restoreCurrentViewState(){};

/// If applicable, requests that the LibraryView load the selected track to
/// the specified group. Does nothing otherwise.
Expand Down
1 change: 0 additions & 1 deletion src/widget/wlibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void WLibrary::switchToView(const QString& name) {
return;
}
if (currentWidget() != widget) {
qDebug() << "oldLibraryView" << oldLibraryView;
if (oldLibraryView) {
oldLibraryView->saveCurrentViewState();
}
Expand Down
8 changes: 3 additions & 5 deletions src/widget/wlibrarytableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void WLibraryTableView::saveTrackModelState(
}

state->lastChange = QDateTime::currentSecsSinceEpoch();
qDebug() << "save: m_vModelScrollBarPos:" << key << verticalScrollBar()->value() << " | ";
// qDebug() << "save: saveTrackModelState:" << key << model << verticalScrollBar()->value() << " | ";
state->scrollPosition = verticalScrollBar()->value();
const QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
if (!selectedIndexes.isEmpty()) {
Expand All @@ -147,7 +147,7 @@ void WLibraryTableView::saveTrackModelState(
void WLibraryTableView::restoreTrackModelState(
const QAbstractItemModel* model, const QString& key) {
updateGeometries();
qDebug() << "restoreTrackModelState:" << key << model << m_vModelState.keys();
// qDebug() << "restoreTrackModelState:" << key << model << m_vModelState.keys();
if (model == nullptr) {
return;
}
Expand All @@ -157,8 +157,6 @@ void WLibraryTableView::restoreTrackModelState(
return;
}

qDebug() << "restore key found:" << key;

verticalScrollBar()->setValue(state->scrollPosition);

auto selection = selectionModel();
Expand Down Expand Up @@ -236,7 +234,7 @@ void WLibraryTableView::clearStateCache() {

while (m_vModelState.size() > kClearModelStatesLowWatermark) {
const QStringList keys = lru.values(sortKeys.takeFirst());
for (auto key : keys) {
for (const auto& key : keys) {
m_vModelState.take(key);
}
}
Expand Down
18 changes: 8 additions & 10 deletions src/widget/wlibrarytableview.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +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
* @param key unique for trackmodel
*/
/// @brief saveTrackModelState function saves current position of scrollbar
/// using 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
* @param key unique for trackmodel
*/

/// @brief restoreTrackModelState function finds scrollbar value 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 clearStateCache();
void saveCurrentViewState() override;
void restoreCurrentViewState() override;
Expand Down
3 changes: 1 addition & 2 deletions src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,7 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel* model, bool restoreStat

setVisible(true);

// 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();
}
Expand Down

0 comments on commit 2299715

Please sign in to comment.