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 /tests/auto/gui/util/qundostack/tst_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 'tests/auto/gui/util/qundostack/tst_qundostack.cpp')
| -rw-r--r-- | tests/auto/gui/util/qundostack/tst_qundostack.cpp | 98 |
1 files changed, 96 insertions, 2 deletions
diff --git a/tests/auto/gui/util/qundostack/tst_qundostack.cpp b/tests/auto/gui/util/qundostack/tst_qundostack.cpp index 3567bc60975..344003c9328 100644 --- a/tests/auto/gui/util/qundostack/tst_qundostack.cpp +++ b/tests/auto/gui/util/qundostack/tst_qundostack.cpp @@ -93,6 +93,18 @@ private: QPoint m_newPoint; }; +class SingleRedoCommand : public QUndoCommand +{ +public: + SingleRedoCommand(QUndoCommand *parent = nullptr); + ~SingleRedoCommand(); + + void redo() override; + +private: + bool m_firstRun = true; +}; + InsertCommand::InsertCommand(QString *str, int idx, const QString &text, QUndoCommand *parent) : QUndoCommand(parent) @@ -255,6 +267,22 @@ bool MoveMouseCommand::mergeWith(const QUndoCommand *other) return true; } +SingleRedoCommand::SingleRedoCommand(QUndoCommand *parent) + : QUndoCommand(parent) +{ + setText("single redo"); +} + +SingleRedoCommand::~SingleRedoCommand() = default; + +void SingleRedoCommand::redo() +{ + if (m_firstRun) + m_firstRun = false; + else + setObsolete(true); +} + /****************************************************************************** ** tst_QUndoStack */ @@ -2637,11 +2665,77 @@ void tst_QUndoStack::obsolete() "", // undoText false, // canRedo "", // redoText - true, // cleanChanged + true, // cleanChanged false, // indexChanged false, // undoChanged false); // redoChanged + stack.push(new SingleRedoCommand()); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 1, // index + true, // canUndo + "single redo", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.undo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 1, // count + 0, // index + false, // canUndo + "", // undoText + true, // canRedo + "single redo", // redoText + false, // cleanChanged + true, // indexChanged + true, // undoChanged + true); // redoChanged + + stack.redo(); + checkState(redoTextChangedSpy, + canRedoChangedSpy, + undoTextChangedSpy, + redoAction, + undoAction, + canUndoChangedSpy, + cleanChangedSpy, + indexChangedSpy, + stack, + false, // clean + 0, // count + 0, // index + false, // canUndo + "", // undoText + false, // canRedo + "", // redoText + false, // cleanChanged + false, // indexChanged + false, // undoChanged + true); // redoChanged + stack.push(new MoveMouseCommand(&mouse, mouse, QPoint(0, 0))); // #1 should not merge but will be deleted (b/c oldPoint == newPoint) QCOMPARE(mouse, QPoint(0, 0)); checkState(redoTextChangedSpy, @@ -3008,7 +3102,7 @@ void tst_QUndoStack::obsolete() false, // cleanChanged false, // indexChanged false, // undoChanged - false); // redoChanged + true); // redoChanged QCOMPARE(stack.cleanIndex(), -1); stack.redo(); |
