Skip to content

Commit

Permalink
Make QCache usage safe against concurrent deletion
Browse files Browse the repository at this point in the history
co-authored by ronso0@mixxx.org
  • Loading branch information
poelzi authored and ronso0 committed Aug 7, 2021
1 parent 17e31cb commit 9d27ba4
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/widget/wlibrarytableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,24 @@ void WLibraryTableView::saveTrackModelState(
VERIFY_OR_DEBUG_ASSERT(!key.isEmpty()) {
return;
}
ModelState* state = m_modelStateCache[key];
ModelState* state = m_modelStateCache.take(key);
if (!state) {
state = new ModelState();
}
// qDebug() << "save: saveTrackModelState:" << key << model << verticalScrollBar()->value() << " | ";
state->verticalScrollPosition = verticalScrollBar()->value();
state->horizontalScrollPosition = horizontalScrollBar()->value();
const QModelIndexList selectedIndexes = selectionModel()->selectedIndexes();
if (!selectedIndexes.isEmpty()) {
state->selectionIndex = selectedIndexes;
if (!selectionModel()->selectedIndexes().isEmpty()) {
state->selectionIndex = selectionModel()->selectedIndexes();
} else {
state->selectionIndex = QModelIndexList();
}
state->currentIndex = selectionModel()->currentIndex();
const QModelIndex currIndex = selectionModel()->currentIndex();
if (currIndex.isValid()) {
state->currentIndex = currIndex;
} else {
state->currentIndex = QModelIndex();
}
m_modelStateCache.insert(key, state, 1);
}

Expand All @@ -146,7 +150,7 @@ void WLibraryTableView::restoreTrackModelState(
return;
}

ModelState* state = m_modelStateCache[key];
ModelState* state = m_modelStateCache.take(key);
if (!state) {
return;
}
Expand All @@ -164,6 +168,8 @@ void WLibraryTableView::restoreTrackModelState(
if (state->currentIndex.isValid()) {
selection->setCurrentIndex(state->currentIndex, QItemSelectionModel::NoUpdate);
}
// reinsert the state into the cache
m_modelStateCache.insert(key, state, 1);
}

void WLibraryTableView::setTrackTableFont(const QFont& font) {
Expand Down

0 comments on commit 9d27ba4

Please sign in to comment.