4#include <QtCore/qdebug.h>
6#if QT_CONFIG(undogroup)
96 parent->d->child_list.append(
this);
307#if QT_CONFIG(undostack)
415void QUndoStackPrivate::setIndex(
int idx,
bool clean)
419 bool was_clean =
index == clean_index;
424 emit q->canUndoChanged(
q->canUndo());
425 emit q->undoTextChanged(
q->undoText());
426 emit q->canRedoChanged(
q->canRedo());
427 emit q->redoTextChanged(
q->redoText());
433 bool is_clean =
index == clean_index;
434 if (is_clean != was_clean)
435 emit q->cleanChanged(is_clean);
445bool QUndoStackPrivate::checkUndoLimit()
447 if (undo_limit <= 0 || !macro_stack.isEmpty() || undo_limit >= command_list.size())
450 int del_count = command_list.size() - undo_limit;
452 for (
int i = 0;
i < del_count; ++
i)
453 delete command_list.takeFirst();
456 if (clean_index != -1) {
457 if (clean_index < del_count)
460 clean_index -= del_count;
477#if QT_CONFIG(undogroup)
479 group->addStack(
this);
490QUndoStack::~QUndoStack()
492#if QT_CONFIG(undogroup)
494 if (
d->group !=
nullptr)
495 d->group->removeStack(
this);
513void QUndoStack::clear()
517 if (
d->command_list.isEmpty())
520 bool was_clean = isClean();
522 d->macro_stack.clear();
524 d->command_list.clear();
529 emit indexChanged(0);
530 emit canUndoChanged(
false);
532 emit canRedoChanged(
false);
536 emit cleanChanged(
true);
573 bool macro = !
d->macro_stack.isEmpty();
582 cur =
d->command_list.at(
d->index - 1);
583 while (
d->index <
d->command_list.size())
584 delete d->command_list.takeLast();
585 if (
d->clean_index >
d->index)
589 bool try_merge = cur !=
nullptr
591 && cur->
id() == cmd->
id()
592 && (macro ||
d->index !=
d->clean_index);
599 delete d->macro_stack.constLast()->d->child_list.takeLast();
602 delete d->command_list.takeLast();
604 d->setIndex(
d->index - 1,
false);
606 emit indexChanged(
d->index);
607 emit canUndoChanged(canUndo());
608 emit undoTextChanged(undoText());
609 emit canRedoChanged(canRedo());
610 emit redoTextChanged(redoText());
617 d->macro_stack.constLast()->d->child_list.append(cmd);
619 d->command_list.append(cmd);
621 d->setIndex(
d->index + 1,
false);
639void QUndoStack::setClean()
643 qWarning(
"QUndoStack::setClean(): cannot set clean in the middle of a macro");
647 d->setIndex(
d->index,
true);
667void QUndoStack::resetClean()
670 const bool was_clean = isClean();
673 emit cleanChanged(
false);
693bool QUndoStack::isClean()
const
695 Q_D(
const QUndoStack);
696 if (!
d->macro_stack.isEmpty())
698 return d->clean_index ==
d->index;
713int QUndoStack::cleanIndex()
const
715 Q_D(
const QUndoStack);
716 return d->clean_index;
734void QUndoStack::undo()
741 qWarning(
"QUndoStack::undo(): cannot undo in the middle of a macro");
745 int idx =
d->index - 1;
752 delete d->command_list.takeAt(idx);
754 if (
d->clean_index > idx)
758 d->setIndex(idx,
false);
776void QUndoStack::redo()
779 if (
d->index ==
d->command_list.size())
783 qWarning(
"QUndoStack::redo(): cannot redo in the middle of a macro");
794 delete d->command_list.takeAt(idx);
796 if (
d->clean_index > idx)
799 d->setIndex(
d->index + 1,
false);
810int QUndoStack::count()
const
812 Q_D(
const QUndoStack);
813 return d->command_list.size();
824int QUndoStack::index()
const
826 Q_D(
const QUndoStack);
838void QUndoStack::setIndex(
int idx)
842 qWarning(
"QUndoStack::setIndex(): cannot set index in the middle of a macro");
848 else if (idx >
d->command_list.size())
849 idx =
d->command_list.size();
859 delete d->command_list.takeAt(
i);
861 if (
d->clean_index >
i)
875 delete d->command_list.takeAt(
i);
877 if (
d->clean_index >
i)
882 d->setIndex(idx,
false);
907bool QUndoStack::canUndo()
const
909 Q_D(
const QUndoStack);
910 if (!
d->macro_stack.isEmpty())
937bool QUndoStack::canRedo()
const
939 Q_D(
const QUndoStack);
940 if (!
d->macro_stack.isEmpty())
942 return d->index <
d->command_list.size();
962QString QUndoStack::undoText()
const
964 Q_D(
const QUndoStack);
965 if (!
d->macro_stack.isEmpty())
968 return d->command_list.at(
d->index - 1)->actionText();
989QString QUndoStack::redoText()
const
991 Q_D(
const QUndoStack);
992 if (!
d->macro_stack.isEmpty())
994 if (
d->index <
d->command_list.size())
995 return d->command_list.at(
d->index)->actionText();
1041 QString effectivePrefix = prefix;
1044 effectivePrefix =
tr(
"Undo %1");
1045 defaultText =
tr(
"Undo",
"Default text for undo action");
1048 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText, undoText());
1052 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText,
text);
1078 QString effectivePrefix = prefix;
1081 effectivePrefix =
tr(
"Redo %1");
1082 defaultText =
tr(
"Redo",
"Default text for redo action");
1085 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText, redoText());
1089 QUndoStackPrivate::setPrefixedText(action, effectivePrefix, defaultText,
text);
1134 if (
d->macro_stack.isEmpty()) {
1135 while (
d->index <
d->command_list.size())
1136 delete d->command_list.takeLast();
1137 if (
d->clean_index >
d->index)
1138 d->clean_index = -1;
1139 d->command_list.append(cmd);
1141 d->macro_stack.constLast()->d->child_list.append(cmd);
1143 d->macro_stack.append(cmd);
1145 if (
d->macro_stack.size() == 1) {
1146 emit canUndoChanged(
false);
1148 emit canRedoChanged(
false);
1162void QUndoStack::endMacro()
1166 qWarning(
"QUndoStack::endMacro(): no matching beginMacro()");
1170 d->macro_stack.removeLast();
1172 if (
d->macro_stack.isEmpty()) {
1173 d->checkUndoLimit();
1174 d->setIndex(
d->index + 1,
false);
1192 Q_D(
const QUndoStack);
1194 if (index < 0 || index >=
d->command_list.size())
1196 return d->command_list.at(
index);
1205QString QUndoStack::text(
int idx)
const
1207 Q_D(
const QUndoStack);
1209 if (idx < 0 || idx >=
d->command_list.size())
1211 return d->command_list.at(idx)->text();
1229void QUndoStack::setUndoLimit(
int limit)
1234 qWarning(
"QUndoStack::setUndoLimit(): an undo limit can only be set when the stack is empty");
1238 if (
limit ==
d->undo_limit)
1241 d->checkUndoLimit();
1244int QUndoStack::undoLimit()
const
1246 Q_D(
const QUndoStack);
1248 return d->undo_limit;
1268void QUndoStack::setActive(
bool active)
1270#if !QT_CONFIG(undogroup)
1275 if (
d->group !=
nullptr) {
1277 d->group->setActiveStack(
this);
1278 else if (
d->group->activeStack() ==
this)
1279 d->group->setActiveStack(
nullptr);
1284bool QUndoStack::isActive()
const
1286#if !QT_CONFIG(undogroup)
1289 Q_D(
const QUndoStack);
1290 return d->group ==
nullptr ||
d->group->activeStack() ==
this;
1352#include "moc_qundostack.cpp"
The QAction class provides an abstraction for user commands that can be added to different user inter...
void triggered(bool checked=false)
This signal is emitted when an action is activated by the user; for example, when the user clicks a m...
void setText(const QString &text)
qsizetype size() const noexcept
bool isEmpty() const noexcept
const T & constLast() const noexcept
const_reference at(qsizetype i) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
QString mid(qsizetype position, qsizetype n=-1) const
Returns a string that contains n characters of this string, starting at the specified position index.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString & append(QChar c)
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
static QString static QString qsizetype indexOf(QChar c, qsizetype from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
QList< QUndoCommand * > child_list
virtual int id() const
Returns the ID of this command.
QString actionText() const
virtual bool mergeWith(const QUndoCommand *other)
Attempts to merge this command with command.
virtual ~QUndoCommand()
Destroys the QUndoCommand object and all child commands.
virtual void undo()
Reverts a change to the document.
void setText(const QString &text)
Sets the command's text to be the text specified.
const QUndoCommand * child(int index) const
QString text() const
Returns a short text string describing what this command does; for example, "insert text".
virtual void redo()
Applies a change to the document.
QUndoCommand(QUndoCommand *parent=nullptr)
Constructs a QUndoCommand object with parent parent.
void setObsolete(bool obsolete)
The QUndoGroup class is a group of QUndoStack objects.
qDeleteAll(list.begin(), list.end())
Combined button and popup list for selecting options.
GLdouble GLdouble GLdouble GLdouble q
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent