diff options
Diffstat (limited to 'src/gui/util')
-rw-r--r-- | src/gui/util/qundostack.cpp | 12 | ||||
-rw-r--r-- | src/gui/util/qundostack_p.h | 15 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/gui/util/qundostack.cpp b/src/gui/util/qundostack.cpp index 3d1d8a2b788..27b131cd733 100644 --- a/src/gui/util/qundostack.cpp +++ b/src/gui/util/qundostack.cpp @@ -425,16 +425,16 @@ void QUndoStackPrivate::setIndex(int idx, bool clean) emit q->indexChanged(index); } - const ActionState newUndoState{q->canUndo(), q->undoText()}; - if (indexChanged || newUndoState != undoActionState) { - undoActionState = newUndoState; + if (ActionState newUndoState{q->canUndo(), q->undoText()}; + indexChanged || newUndoState != undoActionState) { + undoActionState = std::move(newUndoState); emit q->canUndoChanged(undoActionState.enabled); emit q->undoTextChanged(undoActionState.text); } - const ActionState newRedoState{q->canRedo(), q->redoText()}; - if (indexChanged || newRedoState != redoActionState) { - redoActionState = newRedoState; + if (ActionState newRedoState{q->canRedo(), q->redoText()}; + indexChanged || newRedoState != redoActionState) { + redoActionState = std::move(newRedoState); emit q->canRedoChanged(redoActionState.enabled); emit q->redoTextChanged(redoActionState.text); } diff --git a/src/gui/util/qundostack_p.h b/src/gui/util/qundostack_p.h index fea201ce62d..6bdcf5fb20b 100644 --- a/src/gui/util/qundostack_p.h +++ b/src/gui/util/qundostack_p.h @@ -59,10 +59,17 @@ public: bool enabled = false; QString text; - bool operator!=(const ActionState &other) const noexcept - { - return enabled != other.enabled || text != other.text; - } + friend bool operator==(const ActionState &lhs, const ActionState &rhs) noexcept +#ifdef __cpp_impl_three_way_comparison + = default; +#else + { return lhs.enabled == rhs.enabled && lhs.text == rhs.text; } + friend bool operator!=(const ActionState &lhs, const ActionState &rhs) noexcept + { return !(lhs == rhs); } +#endif + // some compiler's reject seed = 0) = delete, overload instead: + friend void qHash(const ActionState &key, size_t seed) = delete; + friend void qHash(const ActionState &key) = delete; }; QList<QUndoCommand*> command_list; |