diff options
| author | Ali Kianian <ali.kianian@qt.io> | 2025-10-07 12:30:26 +0300 |
|---|---|---|
| committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2025-10-11 01:16:37 +0000 |
| commit | 31b0dadb0f371fc94652782c28024f135a0b6f4b (patch) | |
| tree | 36d8c0f1dcc29715a96b7f30109a2949d24188b5 /src/gui/util/qundostack.cpp | |
| parent | f0b1caafd8dcc74b7771ee1c451587218075136a (diff) | |
QUndoStack: Notify changes when the command is obsolete within redo
If a command gets obsolete within the redo method, the index is not
changed, but the status of canRedo, canUndo, redoText, and undoText
might change.
We should report them when any of these changes are met.
Fixes: QTBUG-138567
Pick-to: 6.10 6.8
Change-Id: I172a4e0e3df3a3bc40ac6757d79dde7b376ee96a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/util/qundostack.cpp')
| -rw-r--r-- | src/gui/util/qundostack.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/gui/util/qundostack.cpp b/src/gui/util/qundostack.cpp index fdd5b07a8d4..3d1d8a2b788 100644 --- a/src/gui/util/qundostack.cpp +++ b/src/gui/util/qundostack.cpp @@ -419,13 +419,24 @@ void QUndoStackPrivate::setIndex(int idx, bool clean) bool was_clean = index == clean_index; - if (idx != index) { + const bool indexChanged = idx != index; + if (indexChanged) { index = idx; emit q->indexChanged(index); - emit q->canUndoChanged(q->canUndo()); - emit q->undoTextChanged(q->undoText()); - emit q->canRedoChanged(q->canRedo()); - emit q->redoTextChanged(q->redoText()); + } + + const ActionState newUndoState{q->canUndo(), q->undoText()}; + if (indexChanged || newUndoState != undoActionState) { + undoActionState = newUndoState; + emit q->canUndoChanged(undoActionState.enabled); + emit q->undoTextChanged(undoActionState.text); + } + + const ActionState newRedoState{q->canRedo(), q->redoText()}; + if (indexChanged || newRedoState != redoActionState) { + redoActionState = newRedoState; + emit q->canRedoChanged(redoActionState.enabled); + emit q->redoTextChanged(redoActionState.text); } if (clean) @@ -796,6 +807,8 @@ void QUndoStack::redo() if (d->clean_index > idx) resetClean(); + + d->setIndex(idx, false); } else { d->setIndex(d->index + 1, false); } |
