Skip to content

Commit

Permalink
StarEditor: Fix for race condition of MousePressed/MouseReleased vs. …
Browse files Browse the repository at this point in the history
…focus handling
  • Loading branch information
cr7pt0gr4ph7 committed May 16, 2024
1 parent 775ba60 commit 592ebbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/library/tabledelegates/stareditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ StarEditor::StarEditor(QWidget* parent,
m_index(index),
m_styleOption(option),
m_starCount(StarRating::kMinStarCount),
m_starCountToSave(StarRating::kInvalidStarCount),
m_isKeyboardEditMode(isKeyboardEditMode) {
DEBUG_ASSERT(m_pTableView);
setMouseTracking(true);
Expand Down Expand Up @@ -197,10 +198,23 @@ bool StarEditor::eventFilter(QObject* obj, QEvent* event) {
// Note: it seems with Qt5 we do not reliably get a Leave event when
// invoking the track menu via right click, so reset the rating now.
// The event is forwarded to parent QTableView.
m_starCountToSave = StarRating::kInvalidStarCount;
resetRating();
break;
}
case QEvent::MouseButtonPress: {
// Workaround: The MouseButtonPress can cause a focus change that might
// cause a database reload, which then overwrites m_starRating before
// the MouseButtonRelease event has a chance to commit the new value
// to the model.
m_starCountToSave = m_starRating.starCount();
break;
}
case QEvent::MouseButtonRelease: {
if (m_starCountToSave != StarRating::kInvalidStarCount) {
m_starRating.setStarCount(m_starCountToSave);
m_starCountToSave = StarRating::kInvalidStarCount;
}
emit editingFinished();
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/library/tabledelegates/stareditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ class StarEditor : public QWidget {
QStyleOptionViewItem m_styleOption;
StarRating m_starRating;
int m_starCount;
int m_starCountToSave;
bool m_isKeyboardEditMode;
};

0 comments on commit 592ebbe

Please sign in to comment.