File indexing completed on 2024-05-19 04:24:19
0001 /* 0002 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com> 0003 * SPDX-FileCopyrightText: 2014 Mohit Goyal <mohit.bits2011@gmail.com> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 /**************************************************************************** 0008 ** 0009 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 0010 ** All rights reserved. 0011 ** Contact: Nokia Corporation (qt-info@nokia.com) 0012 ** 0013 ** This file is part of the QtGui module of the Qt Toolkit. 0014 ** 0015 ** $QT_BEGIN_LICENSE:LGPL$ 0016 ** No Commercial Usage 0017 ** This file contains pre-release code and may not be distributed. 0018 ** You may use this file in accordance with the terms and conditions 0019 ** contained in the Technology Preview License Agreement accompanying 0020 ** this package. 0021 ** 0022 ** GNU Lesser General Public License Usage 0023 ** Alternatively, this file may be used under the terms of the GNU Lesser 0024 ** General Public License version 2.1 as published by the Free Software 0025 ** Foundation and appearing in the file LICENSE.LGPL included in the 0026 ** packaging of this file. Please review the following information to 0027 ** ensure the GNU Lesser General Public License version 2.1 requirements 0028 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 0029 ** 0030 ** In addition, as a special exception, Nokia gives you certain additional 0031 ** rights. These rights are described in the Nokia Qt LGPL Exception 0032 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 0033 ** 0034 ** If you have questions regarding the use of this file, please contact 0035 ** Nokia at qt-info@nokia.com. 0036 ** 0037 ** 0038 ** 0039 ** 0040 ** 0041 ** 0042 ** 0043 ** 0044 ** $QT_END_LICENSE$ 0045 ** 0046 ****************************************************************************/ 0047 0048 #include <QDebug> 0049 #include <klocalizedstring.h> 0050 #include <kstandardaction.h> 0051 #include <kactioncollection.h> 0052 #include "kundo2stack.h" 0053 #include "kundo2stack_p.h" 0054 #include "kundo2group.h" 0055 #include <KoIcon.h> 0056 #include <QtGlobal> 0057 #include "kis_assert.h" 0058 0059 0060 #ifndef QT_NO_UNDOCOMMAND 0061 0062 /*! 0063 \class KUndo2Command 0064 \brief The KUndo2Command class is the base class of all commands stored on a KUndo2QStack. 0065 \since 4.2 0066 0067 For an overview of Qt's Undo Framework, see the 0068 \l{Overview of Qt's Undo Framework}{overview document}. 0069 0070 A KUndo2Command represents a single editing action on a document; for example, 0071 inserting or deleting a block of text in a text editor. KUndo2Command can apply 0072 a change to the document with redo() and undo the change with undo(). The 0073 implementations for these functions must be provided in a derived class. 0074 0075 \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 0 0076 0077 A KUndo2Command has an associated text(). This is a short string 0078 describing what the command does. It is used to update the text 0079 properties of the stack's undo and redo actions; see 0080 KUndo2QStack::createUndoAction() and KUndo2QStack::createRedoAction(). 0081 0082 KUndo2Command objects are owned by the stack they were pushed on. 0083 KUndo2QStack deletes a command if it has been undone and a new command is pushed. For example: 0084 0085 \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 1 0086 0087 In effect, when a command is pushed, it becomes the top-most command 0088 on the stack. 0089 0090 To support command compression, KUndo2Command has an id() and the virtual function 0091 mergeWith(). These functions are used by KUndo2QStack::push(). 0092 0093 To support command macros, a KUndo2Command object can have any number of child 0094 commands. Undoing or redoing the parent command will cause the child 0095 commands to be undone or redone. A command can be assigned 0096 to a parent explicitly in the constructor. In this case, the command 0097 will be owned by the parent. 0098 0099 The parent in this case is usually an empty command, in that it doesn't 0100 provide its own implementation of undo() and redo(). Instead, it uses 0101 the base implementations of these functions, which simply call undo() or 0102 redo() on all its children. The parent should, however, have a meaningful 0103 text(). 0104 0105 \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 2 0106 0107 Another way to create macros is to use the convenience functions 0108 KUndo2QStack::beginMacro() and KUndo2QStack::endMacro(). 0109 0110 \sa KUndo2QStack 0111 */ 0112 0113 /*! 0114 Constructs a KUndo2Command object with the given \a parent and \a text. 0115 0116 If \a parent is not 0, this command is appended to parent's child list. 0117 The parent command then owns this command and will delete it in its 0118 destructor. 0119 0120 \sa ~KUndo2Command() 0121 */ 0122 0123 KUndo2Command::KUndo2Command(const KUndo2MagicString &text, KUndo2Command *parent) 0124 : m_hasParent(parent != 0) 0125 , m_endOfCommand(QTime::currentTime()) 0126 { 0127 d = new KUndo2CommandPrivate; 0128 if (parent != 0) { 0129 parent->d->child_list.append(this); 0130 } 0131 setText(text); 0132 setTime(); 0133 } 0134 0135 /*! 0136 Constructs a KUndo2Command object with parent \a parent. 0137 0138 If \a parent is not 0, this command is appended to parent's child list. 0139 The parent command then owns this command and will delete it in its 0140 destructor. 0141 0142 \sa ~KUndo2Command() 0143 */ 0144 0145 KUndo2Command::KUndo2Command(KUndo2Command *parent) 0146 : m_hasParent(parent != 0) 0147 { 0148 d = new KUndo2CommandPrivate; 0149 if (parent != 0) 0150 parent->d->child_list.append(this); 0151 setTime(); 0152 } 0153 0154 /*! 0155 Destroys the KUndo2Command object and all child commands. 0156 0157 \sa KUndo2Command() 0158 */ 0159 0160 KUndo2Command::~KUndo2Command() 0161 { 0162 qDeleteAll(d->child_list); 0163 delete d; 0164 } 0165 0166 /*! 0167 Returns the ID of this command. 0168 0169 A command ID is used in command compression. It must be an integer unique to 0170 this command's class, or -1 if the command doesn't support compression. 0171 0172 If the command supports compression this function must be overridden in the 0173 derived class to return the correct ID. The base implementation returns -1. 0174 0175 KUndo2QStack::push() will only try to merge two commands if they have the 0176 same ID, and the ID is not -1. 0177 0178 \sa mergeWith(), KUndo2QStack::push() 0179 */ 0180 0181 int KUndo2Command::id() const 0182 { 0183 return -1; 0184 } 0185 0186 /*! 0187 Attempts to merge this command with \a command. Returns true on 0188 success; otherwise returns false. 0189 0190 If this function returns true, calling this command's redo() must have the same 0191 effect as redoing both this command and \a command. 0192 Similarly, calling this command's undo() must have the same effect as undoing 0193 \a command and this command. 0194 0195 KUndo2QStack will only try to merge two commands if they have the same id, and 0196 the id is not -1. 0197 0198 The default implementation returns false. 0199 0200 \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 3 0201 0202 \sa id() KUndo2QStack::push() 0203 */ 0204 0205 bool KUndo2Command::mergeWith(const KUndo2Command *command) 0206 { 0207 Q_UNUSED(command); 0208 return false; 0209 } 0210 0211 /*! 0212 Applies a change to the document. This function must be implemented in 0213 the derived class. Calling KUndo2QStack::push(), 0214 KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to 0215 undefined behavior. 0216 0217 The default implementation calls redo() on all child commands. 0218 0219 \sa undo() 0220 */ 0221 0222 void KUndo2Command::redo() 0223 { 0224 for (int i = 0; i < d->child_list.size(); ++i) 0225 d->child_list.at(i)->redo(); 0226 } 0227 0228 /*! 0229 Reverts a change to the document. After undo() is called, the state of 0230 the document should be the same as before redo() was called. This function must 0231 be implemented in the derived class. Calling KUndo2QStack::push(), 0232 KUndo2QStack::undo() or KUndo2QStack::redo() from this function leads to 0233 undefined behavior. 0234 0235 The default implementation calls undo() on all child commands in reverse order. 0236 0237 \sa redo() 0238 */ 0239 0240 void KUndo2Command::undo() 0241 { 0242 for (int i = d->child_list.size() - 1; i >= 0; --i) 0243 d->child_list.at(i)->undo(); 0244 } 0245 0246 /*! 0247 Returns a short text string describing what this command does; for example, 0248 "insert text". 0249 0250 The text is used when the text properties of the stack's undo and redo 0251 actions are updated. 0252 0253 \sa setText(), KUndo2QStack::createUndoAction(), KUndo2QStack::createRedoAction() 0254 */ 0255 0256 QString KUndo2Command::actionText() const 0257 { 0258 if(d->actionText!=0) 0259 return d->actionText; 0260 else 0261 return QString(); 0262 } 0263 0264 /*! 0265 Returns a short text string describing what this command does; for example, 0266 "insert text". 0267 0268 The text is used when the text properties of the stack's undo and redo 0269 actions are updated. 0270 0271 \sa setText(), KUndo2QStack::createUndoAction(), KUndo2QStack::createRedoAction() 0272 */ 0273 0274 KUndo2MagicString KUndo2Command::text() const 0275 { 0276 return d->text; 0277 } 0278 0279 /*! 0280 Sets the command's text to be the \a text specified. 0281 0282 The specified text should be a short user-readable string describing what this 0283 command does. 0284 0285 \sa text() KUndo2QStack::createUndoAction() KUndo2QStack::createRedoAction() 0286 */ 0287 0288 void KUndo2Command::setText(const KUndo2MagicString &undoText) 0289 { 0290 d->text = undoText; 0291 d->actionText = undoText.toSecondaryString(); 0292 } 0293 0294 /*! 0295 \since 4.4 0296 0297 Returns the number of child commands in this command. 0298 0299 \sa child() 0300 */ 0301 0302 int KUndo2Command::childCount() const 0303 { 0304 return d->child_list.count(); 0305 } 0306 0307 /*! 0308 \since 4.4 0309 0310 Returns the child command at \a index. 0311 0312 \sa childCount(), KUndo2QStack::command() 0313 */ 0314 0315 const KUndo2Command *KUndo2Command::child(int index) const 0316 { 0317 if (index < 0 || index >= d->child_list.count()) 0318 return 0; 0319 return d->child_list.at(index); 0320 } 0321 0322 bool KUndo2Command::hasParent() const 0323 { 0324 return m_hasParent; 0325 } 0326 0327 int KUndo2Command::timedId() const 0328 { 0329 return m_timedID; 0330 } 0331 void KUndo2Command::setTimedID(int value) 0332 { 0333 m_timedID = value; 0334 } 0335 0336 bool KUndo2Command::timedMergeWith(KUndo2Command *other) 0337 { 0338 if(other->timedId() == this->timedId() && other->timedId() != -1 ) { 0339 m_mergeCommandsVector.append(other); 0340 m_timeOfCreation = other->time(); 0341 } else { 0342 return false; 0343 } 0344 return true; 0345 } 0346 /*! 0347 Attempts to merge this command with \a command and checks if the two commands 0348 compensate each other. If the function returns true, both commands are removed 0349 from the stack. 0350 0351 If this function returns true, calling this command's redo() followed by 0352 \p other redo() must have no effect. 0353 0354 The function itself shouldn't do any changes to the command, because 0355 after returning true, the command will be deleted as a "noop" 0356 0357 KUndo2QStack will only try to merge two commands if they have the same id, and 0358 the id is not -1. 0359 0360 The default implementation returns false. 0361 0362 \sa id() KUndo2QStack::push() 0363 */ 0364 bool KUndo2Command::canAnnihilateWith(const KUndo2Command *other) const 0365 { 0366 Q_UNUSED(other) 0367 return false; 0368 } 0369 0370 void KUndo2Command::setTime() 0371 { 0372 setTime(QTime::currentTime()); 0373 } 0374 0375 void KUndo2Command::setTime(const QTime &time) 0376 { 0377 m_timeOfCreation = time; 0378 } 0379 0380 QTime KUndo2Command::time() const 0381 { 0382 return m_timeOfCreation; 0383 } 0384 0385 void KUndo2Command::setEndTime() 0386 { 0387 setEndTime(QTime::currentTime()); 0388 } 0389 void KUndo2Command::setEndTime(const QTime &time) 0390 { 0391 m_endOfCommand = time; 0392 } 0393 QTime KUndo2Command::endTime() const 0394 { 0395 return m_endOfCommand; 0396 } 0397 0398 void KUndo2Command::undoMergedCommands() 0399 { 0400 0401 undo(); 0402 if (!mergeCommandsVector().isEmpty()) { 0403 QVectorIterator<KUndo2Command*> it(mergeCommandsVector()); 0404 it.toFront(); 0405 while (it.hasNext()) { 0406 KUndo2Command* cmd = it.next(); 0407 cmd->undoMergedCommands(); 0408 } 0409 } 0410 } 0411 0412 void KUndo2Command::redoMergedCommands() 0413 { 0414 if (!mergeCommandsVector().isEmpty()) { 0415 0416 QVectorIterator<KUndo2Command*> it(mergeCommandsVector()); 0417 it.toBack(); 0418 while (it.hasPrevious()) { 0419 KUndo2Command* cmd = it.previous(); 0420 cmd->redoMergedCommands(); 0421 } 0422 } 0423 redo(); 0424 } 0425 QVector<KUndo2Command*> KUndo2Command::mergeCommandsVector() const 0426 { 0427 return m_mergeCommandsVector; 0428 } 0429 bool KUndo2Command::isMerged() const 0430 { 0431 return !m_mergeCommandsVector.isEmpty(); 0432 } 0433 0434 KUndo2CommandExtraData* KUndo2Command::extraData() const 0435 { 0436 return d->extraData.data(); 0437 } 0438 0439 void KUndo2Command::setExtraData(KUndo2CommandExtraData *data) 0440 { 0441 d->extraData.reset(data); 0442 } 0443 0444 0445 #endif // QT_NO_UNDOCOMMAND 0446 0447 #ifndef QT_NO_UNDOSTACK 0448 0449 /*! 0450 \class KUndo2QStack 0451 \brief The KUndo2QStack class is a stack of KUndo2Command objects. 0452 \since 4.2 0453 0454 For an overview of Qt's Undo Framework, see the 0455 \l{Overview of Qt's Undo Framework}{overview document}. 0456 0457 An undo stack maintains a stack of commands that have been applied to a 0458 document. 0459 0460 New commands are pushed on the stack using push(). Commands can be 0461 undone and redone using undo() and redo(), or by triggering the 0462 actions returned by createUndoAction() and createRedoAction(). 0463 0464 KUndo2QStack keeps track of the \a current command. This is the command 0465 which will be executed by the next call to redo(). The index of this 0466 command is returned by index(). The state of the edited object can be 0467 rolled forward or back using setIndex(). If the top-most command on the 0468 stack has already been redone, index() is equal to count(). 0469 0470 KUndo2QStack provides support for undo and redo actions, command 0471 compression, command macros, and supports the concept of a 0472 \e{clean state}. 0473 0474 \section1 Undo and Redo Actions 0475 0476 KUndo2QStack provides convenient undo and redo QAction objects, which 0477 can be inserted into a menu or a toolbar. When commands are undone or 0478 redone, KUndo2QStack updates the text properties of these actions 0479 to reflect what change they will trigger. The actions are also disabled 0480 when no command is available for undo or redo. These actions 0481 are returned by KUndo2QStack::createUndoAction() and KUndo2QStack::createRedoAction(). 0482 0483 \section1 Command Compression and Macros 0484 0485 Command compression is useful when several commands can be compressed 0486 into a single command that can be undone and redone in a single operation. 0487 For example, when a user types a character in a text editor, a new command 0488 is created. This command inserts the character into the document at the 0489 cursor position. However, it is more convenient for the user to be able 0490 to undo or redo typing of whole words, sentences, or paragraphs. 0491 Command compression allows these single-character commands to be merged 0492 into a single command which inserts or deletes sections of text. 0493 For more information, see KUndo2Command::mergeWith() and push(). 0494 0495 A command macro is a sequence of commands, all of which are undone and 0496 redone in one go. Command macros are created by giving a command a list 0497 of child commands. 0498 Undoing or redoing the parent command will cause the child commands to 0499 be undone or redone. Command macros may be created explicitly 0500 by specifying a parent in the KUndo2Command constructor, or by using the 0501 convenience functions beginMacro() and endMacro(). 0502 0503 Although command compression and macros appear to have the same effect to the 0504 user, they often have different uses in an application. Commands that 0505 perform small changes to a document may be usefully compressed if there is 0506 no need to individually record them, and if only larger changes are relevant 0507 to the user. 0508 However, for commands that need to be recorded individually, or those that 0509 cannot be compressed, it is useful to use macros to provide a more convenient 0510 user experience while maintaining a record of each command. 0511 0512 \section1 Clean State 0513 0514 KUndo2QStack supports the concept of a clean state. When the 0515 document is saved to disk, the stack can be marked as clean using 0516 setClean(). Whenever the stack returns to this state through undoing and 0517 redoing commands, it emits the signal cleanChanged(). This signal 0518 is also emitted when the stack leaves the clean state. This signal is 0519 usually used to enable and disable the save actions in the application, 0520 and to update the document's title to reflect that it contains unsaved 0521 changes. 0522 0523 \sa KUndo2Command, KUndo2View 0524 */ 0525 0526 #ifndef QT_NO_ACTION 0527 0528 KUndo2Action::KUndo2Action(const QString &textTemplate, const QString &defaultText, QObject *parent) 0529 : QAction(parent) 0530 , m_textTemplate(textTemplate) 0531 , m_defaultText(defaultText) 0532 { 0533 } 0534 0535 void KUndo2Action::setPrefixedText(const QString &text) 0536 { 0537 if (text.isEmpty()) 0538 setText(m_defaultText); 0539 else 0540 setText(m_textTemplate.arg(text)); 0541 } 0542 0543 #endif // QT_NO_ACTION 0544 0545 /*! \internal 0546 Sets the current index to \a idx, emitting appropriate signals. If \a clean is true, 0547 makes \a idx the clean index as well. 0548 */ 0549 0550 void KUndo2QStack::setIndex(int idx, bool clean) 0551 { 0552 bool was_clean = m_index == m_clean_index; 0553 0554 if (idx != m_index) { 0555 m_index = idx; 0556 emit indexChanged(m_index); 0557 emit canUndoChanged(canUndo()); 0558 emit undoTextChanged(undoText()); 0559 emit canRedoChanged(canRedo()); 0560 emit redoTextChanged(redoText()); 0561 } 0562 0563 if (clean) 0564 m_clean_index = m_index; 0565 0566 bool is_clean = m_index == m_clean_index; 0567 if (is_clean != was_clean) 0568 emit cleanChanged(is_clean); 0569 } 0570 0571 void KUndo2QStack::purgeRedoState() 0572 { 0573 bool macro = !m_macro_stack.isEmpty(); 0574 if (macro) return; 0575 0576 bool redoStateChanged = false; 0577 bool cleanStateChanged = false; 0578 0579 while (m_index < m_command_list.size()) { 0580 delete m_command_list.takeLast(); 0581 redoStateChanged = true; 0582 } 0583 0584 if (m_clean_index > m_index) { 0585 m_clean_index = -1; // we've deleted the clean state 0586 cleanStateChanged = true; 0587 } 0588 0589 if (redoStateChanged) { 0590 emit canRedoChanged(canRedo()); 0591 emit redoTextChanged(redoText()); 0592 } 0593 0594 if (cleanStateChanged) { 0595 emit cleanChanged(isClean()); 0596 } 0597 } 0598 0599 /*! \internal 0600 If the number of commands on the stack exceeds the undo limit, deletes commands from 0601 the bottom of the stack. 0602 0603 Returns true if commands were deleted. 0604 */ 0605 0606 bool KUndo2QStack::checkUndoLimit() 0607 { 0608 if (m_undo_limit <= 0 || !m_macro_stack.isEmpty() || m_undo_limit >= m_command_list.count()) 0609 return false; 0610 0611 int del_count = m_command_list.count() - m_undo_limit; 0612 0613 for (int i = 0; i < del_count; ++i) 0614 delete m_command_list.takeFirst(); 0615 0616 m_index -= del_count; 0617 if (m_clean_index != -1) { 0618 if (m_clean_index < del_count) 0619 m_clean_index = -1; // we've deleted the clean command 0620 else 0621 m_clean_index -= del_count; 0622 } 0623 return true; 0624 } 0625 0626 /*! 0627 Constructs an empty undo stack with the parent \a parent. The 0628 stack will initially be in the clean state. If \a parent is a 0629 KUndo2Group object, the stack is automatically added to the group. 0630 0631 \sa push() 0632 */ 0633 0634 KUndo2QStack::KUndo2QStack(QObject *parent) 0635 : QObject(parent), m_index(0), m_clean_index(0), m_group(0), m_undo_limit(0) 0636 , m_useCumulativeUndoRedo(false) 0637 { 0638 #ifndef QT_NO_UNDOGROUP 0639 if (KUndo2Group *group = qobject_cast<KUndo2Group*>(parent)) 0640 group->addStack(this); 0641 #endif 0642 } 0643 0644 /*! 0645 Destroys the undo stack, deleting any commands that are on it. If the 0646 stack is in a KUndo2Group, the stack is automatically removed from the group. 0647 0648 \sa KUndo2QStack()The number of last strokes which Krita should store separately 0649 */ 0650 0651 KUndo2QStack::~KUndo2QStack() 0652 { 0653 #ifndef QT_NO_UNDOGROUP 0654 if (m_group != 0) 0655 m_group->removeStack(this); 0656 #endif 0657 clear(); 0658 } 0659 0660 /*! 0661 Clears the command stack by deleting all commands on it, and returns the stack 0662 to the clean state.{ 0663 0664 } 0665 0666 Commands are not undone or redone; the state of the edited object remains 0667 unchanged. 0668 0669 This function is usually used when the contents of the document are 0670 abandoned. 0671 0672 \sa KUndo2QStack() 0673 */ 0674 0675 void KUndo2QStack::clear() 0676 { 0677 if (m_command_list.isEmpty()) 0678 return; 0679 0680 bool was_clean = isClean(); 0681 0682 m_macro_stack.clear(); 0683 qDeleteAll(m_command_list); 0684 m_command_list.clear(); 0685 0686 m_index = 0; 0687 m_clean_index = 0; 0688 0689 emit indexChanged(0); 0690 emit canUndoChanged(false); 0691 emit undoTextChanged(QString()); 0692 emit canRedoChanged(false); 0693 emit redoTextChanged(QString()); 0694 0695 if (!was_clean) 0696 emit cleanChanged(true); 0697 } 0698 0699 /*! 0700 Pushes \a cmd on the stack or merges it with the most recently executed command. 0701 In either case, executes \a cmd by calling its redo() function. 0702 0703 If \a cmd's id is not -1, and if the id is the same as that of the 0704 most recently executed command, KUndo2QStack will attempt to merge the two 0705 commands by calling KUndo2Command::mergeWith() on the most recently executed 0706 command. If KUndo2Command::mergeWith() returns true, \a cmd is deleted. 0707 0708 In all other cases \a cmd is simply pushed on the stack. 0709 0710 If commands were undone before \a cmd was pushed, the current command and 0711 all commands above it are deleted. Hence \a cmd always ends up being the 0712 top-most on the stack. 0713 0714 Once a command is pushed, the stack takes ownership of it. There 0715 are no getters to return the command, since modifying it after it has 0716 been executed will almost always lead to corruption of the document's 0717 state. 0718 0719 \sa KUndo2Command::id() KUndo2Command::mergeWith() 0720 */ 0721 0722 void KUndo2QStack::push(KUndo2Command *cmd) 0723 { 0724 cmd->redoMergedCommands(); 0725 0726 if (cmd->endTime().isNull()) { 0727 cmd->setEndTime(); 0728 } 0729 0730 bool macro = !m_macro_stack.isEmpty(); 0731 0732 KUndo2Command *cur = 0; 0733 if (macro) { 0734 KUndo2Command *macro_cmd = m_macro_stack.last(); 0735 if (!macro_cmd->d->child_list.isEmpty()) 0736 cur = macro_cmd->d->child_list.last(); 0737 } else { 0738 if (m_index > 0) 0739 cur = m_command_list.at(m_index - 1); 0740 while (m_index < m_command_list.size()) 0741 delete m_command_list.takeLast(); 0742 if (m_clean_index > m_index) 0743 m_clean_index = -1; // we've deleted the clean state 0744 } 0745 0746 bool try_merge = cur != 0 0747 && cur->id() != -1 0748 && cur->id() == cmd->id() 0749 && (macro || m_index != m_clean_index); 0750 0751 /** 0752 * Here we are going to try to merge several commands together using the 0753 * QVector field in the commands using 3 parameters. 0754 * 0755 * N : Number of commands that should remain individual at the top of the 0756 * stack. 0757 * 0758 * T1 : Timeout for the commands to be outdated and merged 0759 * 0760 * T2 : Time separation between two commands to be considered as belonging 0761 * to the same group 0762 * 0763 */ 0764 0765 if (!macro && m_command_list.size() > 1 && cmd->timedId() != -1 && m_useCumulativeUndoRedo) { 0766 KUndo2Command* lastcmd = m_command_list.last(); 0767 0768 auto tryMergeBack = 0769 [this] (auto revIt, bool *isMerged) { 0770 /// we have a guarantee that std::next(revIt) exists, 0771 /// so we can safely iterate back in the forward order 0772 auto dst = std::prev(revIt.base()); 0773 auto src = std::prev(dst); 0774 0775 if ((*dst)->timedId() != -1 && 0776 (*dst)->timedId() == (*src)->timedId() && 0777 (*src)->time().msecsTo((*dst)->endTime()) <= m_cumulativeUndoData.maxGroupDuration && 0778 (*src)->endTime().msecsTo((*dst)->time()) <= m_cumulativeUndoData.maxGroupSeparation && 0779 (*dst)->timedMergeWith(*src)) { 0780 0781 const int removedIndex = std::distance(m_command_list.begin(), src); 0782 0783 /// index and clean_index are one off the real index in the 0784 /// commands list 0785 if (m_clean_index - 1 == removedIndex) { 0786 m_clean_index = -1; 0787 } else if (m_clean_index - 1 > removedIndex) { 0788 m_clean_index--; 0789 } 0790 m_index--; 0791 0792 dst = m_command_list.erase(src); 0793 *isMerged = true; 0794 } else { 0795 *isMerged = false; 0796 } 0797 0798 return std::make_reverse_iterator(std::next(dst)); 0799 }; 0800 0801 int extraCheckDepth = 0; 0802 int newDepth = 1; // `cmd` will be added soon and will increase the total depth! 0803 QTime oldTimeBase = lastcmd->time(); // needed to calculate already processed items 0804 QTime newTimeBase = cmd->time(); 0805 0806 auto it = std::make_reverse_iterator(m_command_list.end()); 0807 auto next = std::next(it); 0808 0809 while (next != std::make_reverse_iterator(m_command_list.begin())) { 0810 0811 if (newDepth < m_cumulativeUndoData.excludeFromMerge) { 0812 ++it; 0813 ++newDepth; 0814 next = std::next(it); 0815 continue; 0816 } 0817 0818 int oldTime = (*it)->endTime().msecsTo(oldTimeBase); 0819 int newTime = (*it)->endTime().msecsTo(newTimeBase); 0820 0821 /// we have reached the element processed when 0822 /// the previous command was added, now we need to 0823 /// count m_strokesN to make sure that "pinned" jobs 0824 /// are also process 0825 if (oldTime > m_cumulativeUndoData.mergeTimeout && 0826 extraCheckDepth++ >= m_cumulativeUndoData.excludeFromMerge) break; 0827 0828 if (newTime >= m_cumulativeUndoData.mergeTimeout) { 0829 bool merged = true; 0830 0831 KUndo2Command *debugOldCmd = *it; 0832 0833 it = tryMergeBack(it, &merged); 0834 0835 KUndo2Command *debugNewCmd = *it; 0836 0837 KIS_SAFE_ASSERT_RECOVER_BREAK(it != std::make_reverse_iterator(m_command_list.begin())); 0838 KIS_SAFE_ASSERT_RECOVER_BREAK(debugOldCmd == debugNewCmd); 0839 0840 if (!merged) { 0841 ++it; 0842 ++newDepth; 0843 } 0844 0845 } else { 0846 ++it; 0847 ++newDepth; 0848 } 0849 0850 next = std::next(it); 0851 } 0852 } 0853 0854 if (try_merge && !macro && cur->canAnnihilateWith(cmd)) { 0855 delete cmd; 0856 if (!macro) { 0857 // this condition must be ruled out by try_merge check 0858 // otherwise we would have to do cleanup for the clean state 0859 Q_ASSERT(m_clean_index != m_index); 0860 0861 delete m_command_list.takeLast(); 0862 m_index--; 0863 0864 emit indexChanged(m_index); 0865 emit canUndoChanged(canUndo()); 0866 emit undoTextChanged(undoText()); 0867 emit canRedoChanged(canRedo()); 0868 emit redoTextChanged(redoText()); 0869 } else { 0870 delete m_macro_stack.takeLast(); 0871 } 0872 0873 } else if (try_merge && cur->mergeWith(cmd)) { 0874 delete cmd; 0875 if (!macro) { 0876 emit indexChanged(m_index); 0877 emit canUndoChanged(canUndo()); 0878 emit undoTextChanged(undoText()); 0879 emit canRedoChanged(canRedo()); 0880 emit redoTextChanged(redoText()); 0881 } 0882 } else { 0883 if (macro) { 0884 m_macro_stack.last()->d->child_list.append(cmd); 0885 } else { 0886 m_command_list.append(cmd); 0887 0888 checkUndoLimit(); 0889 setIndex(m_index + 1, false); 0890 } 0891 } 0892 } 0893 0894 /*! 0895 Marks the stack as clean and emits cleanChanged() if the stack was 0896 not already clean. 0897 0898 Whenever the stack returns to this state through the use of undo/redo 0899 commands, it emits the signal cleanChanged(). This signal is also 0900 emitted when the stack leaves the clean state. 0901 0902 \sa isClean(), cleanIndex() 0903 */ 0904 0905 void KUndo2QStack::setClean() 0906 { 0907 if (!m_macro_stack.isEmpty()) { 0908 qWarning("KUndo2QStack::setClean(): cannot set clean in the middle of a macro"); 0909 return; 0910 } 0911 0912 setIndex(m_index, true); 0913 } 0914 0915 /*! 0916 If the stack is in the clean state, returns true; otherwise returns false. 0917 0918 \sa setClean() cleanIndex() 0919 */ 0920 0921 bool KUndo2QStack::isClean() const 0922 { 0923 if (!m_macro_stack.isEmpty()) 0924 return false; 0925 return m_clean_index == m_index; 0926 } 0927 0928 /*! 0929 Returns the clean index. This is the index at which setClean() was called. 0930 0931 A stack may not have a clean index. This happens if a document is saved, 0932 some commands are undone, then a new command is pushed. Since 0933 push() deletes all the undone commands before pushing the new command, the stack 0934 can't return to the clean state again. In this case, this function returns -1. 0935 0936 \sa isClean() setClean() 0937 */ 0938 0939 int KUndo2QStack::cleanIndex() const 0940 { 0941 return m_clean_index; 0942 } 0943 0944 /*! 0945 Undoes the command below the current command by calling KUndo2Command::undo(). 0946 Decrements the current command index. 0947 0948 If the stack is empty, or if the bottom command on the stack has already been 0949 undone, this function does nothing. 0950 0951 \sa redo() index() 0952 */ 0953 0954 void KUndo2QStack::undo() 0955 { 0956 if (m_index == 0) 0957 return; 0958 0959 if (!m_macro_stack.isEmpty()) { 0960 qWarning("KUndo2QStack::undo(): cannot undo in the middle of a macro"); 0961 return; 0962 } 0963 0964 int idx = m_index - 1; 0965 m_command_list.at(idx)->undoMergedCommands(); 0966 setIndex(idx, false); 0967 } 0968 0969 /*! 0970 Redoes the current command by calling KUndo2Command::redo(). Increments the current 0971 command index. 0972 0973 If the stack is empty, or if the top command on the stack has already been 0974 redone, this function does nothing. 0975 0976 \sa undo() index() 0977 */ 0978 0979 void KUndo2QStack::redo() 0980 { 0981 if (m_index == m_command_list.size()) 0982 return; 0983 0984 if (!m_macro_stack.isEmpty()) { 0985 qWarning("KUndo2QStack::redo(): cannot redo in the middle of a macro"); 0986 return; 0987 } 0988 0989 m_command_list.at(m_index)->redoMergedCommands(); 0990 setIndex(m_index + 1, false); 0991 } 0992 0993 /*! 0994 Returns the number of commands on the stack. Macro commands are counted as 0995 one command. 0996 0997 \sa index() setIndex() command() 0998 */ 0999 1000 int KUndo2QStack::count() const 1001 { 1002 return m_command_list.size(); 1003 } 1004 1005 /*! 1006 Returns the index of the current command. This is the command that will be 1007 executed on the next call to redo(). It is not always the top-most command 1008 on the stack, since a number of commands may have been undone. 1009 1010 \sa undo() redo() count() 1011 */ 1012 1013 int KUndo2QStack::index() const 1014 { 1015 return m_index; 1016 } 1017 1018 /*! 1019 Repeatedly calls undo() or redo() until the current command index reaches 1020 \a idx. This function can be used to roll the state of the document forwards 1021 of backwards. indexChanged() is emitted only once. 1022 1023 \sa index() count() undo() redo() 1024 */ 1025 1026 void KUndo2QStack::setIndex(int idx) 1027 { 1028 if (!m_macro_stack.isEmpty()) { 1029 qWarning("KUndo2QStack::setIndex(): cannot set index in the middle of a macro"); 1030 return; 1031 } 1032 1033 if (idx < 0) 1034 idx = 0; 1035 else if (idx > m_command_list.size()) 1036 idx = m_command_list.size(); 1037 1038 int i = m_index; 1039 while (i < idx) { 1040 m_command_list.at(i++)->redoMergedCommands(); 1041 notifySetIndexChangedOneCommand(); 1042 } 1043 while (i > idx) { 1044 m_command_list.at(--i)->undoMergedCommands(); 1045 notifySetIndexChangedOneCommand(); 1046 } 1047 1048 setIndex(idx, false); 1049 } 1050 1051 1052 /** 1053 * Called by setIndex after every command execution. It is needed by 1054 * Krita to insert barriers between different kind of commands 1055 */ 1056 void KUndo2QStack::notifySetIndexChangedOneCommand() 1057 { 1058 } 1059 1060 /*! 1061 Returns true if there is a command available for undo; otherwise returns false. 1062 1063 This function returns false if the stack is empty, or if the bottom command 1064 on the stack has already been undone. 1065 1066 Synonymous with index() == 0. 1067 1068 \sa index() canRedo() 1069 */ 1070 1071 bool KUndo2QStack::canUndo() const 1072 { 1073 if (!m_macro_stack.isEmpty()) 1074 return false; 1075 return m_index > 0; 1076 } 1077 1078 /*! 1079 Returns true if there is a command available for redo; otherwise returns false. 1080 1081 This function returns false if the stack is empty or if the top command 1082 on the stack has already been redone. 1083 1084 Synonymous with index() == count(). 1085 1086 \sa index() canUndo() 1087 */ 1088 1089 bool KUndo2QStack::canRedo() const 1090 { 1091 if (!m_macro_stack.isEmpty()) 1092 return false; 1093 return m_index < m_command_list.size(); 1094 } 1095 1096 /*! 1097 Returns the text of the command which will be undone in the next call to undo(). 1098 1099 \sa KUndo2Command::text() redoActionText() undoItemText() 1100 */ 1101 1102 QString KUndo2QStack::undoText() const 1103 { 1104 if (!m_macro_stack.isEmpty()) { 1105 return QString(); 1106 } 1107 if (m_index > 0 && m_command_list.count() >= m_index -1 && m_command_list.at(m_index - 1) != 0) { 1108 return m_command_list.at(m_index - 1)->actionText(); 1109 } 1110 return QString(); 1111 } 1112 1113 /*! 1114 Returns the text of the command which will be redone in the next call to redo(). 1115 1116 \sa KUndo2Command::text() undoActionText() redoItemText() 1117 */ 1118 1119 QString KUndo2QStack::redoText() const 1120 { 1121 if (!m_macro_stack.isEmpty()) 1122 return QString(); 1123 if (m_index < m_command_list.size()) 1124 return m_command_list.at(m_index)->actionText(); 1125 return QString(); 1126 } 1127 1128 #ifndef QT_NO_ACTION 1129 1130 /*! 1131 Creates an undo QAction object with the given \a parent. 1132 1133 Triggering this action will cause a call to undo(). The text of this action 1134 is the text of the command which will be undone in the next call to undo(), 1135 prefixed by the specified \a prefix. If there is no command available for undo, 1136 this action will be disabled. 1137 1138 If \a prefix is empty, the default prefix "Undo" is used. 1139 1140 \sa createRedoAction(), canUndo(), KUndo2Command::text() 1141 */ 1142 1143 QAction *KUndo2QStack::createUndoAction(QObject *parent) const 1144 { 1145 KUndo2Action *result = new KUndo2Action(i18n("Undo %1"), i18nc("Default text for undo action", "Undo"), parent); 1146 result->setEnabled(canUndo()); 1147 result->setPrefixedText(undoText()); 1148 connect(this, SIGNAL(canUndoChanged(bool)), 1149 result, SLOT(setEnabled(bool))); 1150 connect(this, SIGNAL(undoTextChanged(QString)), 1151 result, SLOT(setPrefixedText(QString))); 1152 connect(result, SIGNAL(triggered()), this, SLOT(undo())); 1153 return result; 1154 } 1155 1156 /*! 1157 Creates an redo QAction object with the given \a parent. 1158 1159 Triggering this action will cause a call to redo(). The text of this action 1160 is the text of the command which will be redone in the next call to redo(), 1161 prefixed by the specified \a prefix. If there is no command available for redo, 1162 this action will be disabled. 1163 1164 If \a prefix is empty, the default prefix "Redo" is used. 1165 1166 \sa createUndoAction(), canRedo(), KUndo2Command::text() 1167 */ 1168 1169 QAction *KUndo2QStack::createRedoAction(QObject *parent) const 1170 { 1171 KUndo2Action *result = new KUndo2Action(i18n("Redo %1"), i18nc("Default text for redo action", "Redo"), parent); 1172 result->setEnabled(canRedo()); 1173 result->setPrefixedText(redoText()); 1174 connect(this, SIGNAL(canRedoChanged(bool)), 1175 result, SLOT(setEnabled(bool))); 1176 connect(this, SIGNAL(redoTextChanged(QString)), 1177 result, SLOT(setPrefixedText(QString))); 1178 connect(result, SIGNAL(triggered()), this, SLOT(redo())); 1179 return result; 1180 } 1181 1182 #endif // QT_NO_ACTION 1183 1184 /*! 1185 Begins composition of a macro command with the given \a text description. 1186 1187 An empty command described by the specified \a text is pushed on the stack. 1188 Any subsequent commands pushed on the stack will be appended to the empty 1189 command's children until endMacro() is called. 1190 1191 Calls to beginMacro() and endMacro() may be nested, but every call to 1192 beginMacro() must have a matching call to endMacro(). 1193 1194 While a macro is composed, the stack is disabled. This means that: 1195 \list 1196 \i indexChanged() and cleanChanged() are not emitted, 1197 \i canUndo() and canRedo() return false, 1198 \i calling undo() or redo() has no effect, 1199 \i the undo/redo actions are disabled. 1200 \endlist 1201 1202 The stack becomes enabled and appropriate signals are emitted when endMacro() 1203 is called for the outermost macro. 1204 1205 \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 4 1206 1207 This code is equivalent to: 1208 1209 \snippet doc/src/snippets/code/src_gui_util_qundostack.cpp 5 1210 1211 \sa endMacro() 1212 */ 1213 1214 void KUndo2QStack::beginMacro(const KUndo2MagicString &text) 1215 { 1216 KUndo2Command *cmd = new KUndo2Command(); 1217 cmd->setText(text); 1218 1219 if (m_macro_stack.isEmpty()) { 1220 while (m_index < m_command_list.size()) 1221 delete m_command_list.takeLast(); 1222 if (m_clean_index > m_index) 1223 m_clean_index = -1; // we've deleted the clean state 1224 m_command_list.append(cmd); 1225 } else { 1226 m_macro_stack.last()->d->child_list.append(cmd); 1227 } 1228 m_macro_stack.append(cmd); 1229 1230 if (m_macro_stack.count() == 1) { 1231 emit canUndoChanged(false); 1232 emit undoTextChanged(QString()); 1233 emit canRedoChanged(false); 1234 emit redoTextChanged(QString()); 1235 } 1236 } 1237 1238 /*! 1239 Ends composition of a macro command. 1240 1241 If this is the outermost macro in a set nested macros, this function emits 1242 indexChanged() once for the entire macro command. 1243 1244 \sa beginMacro() 1245 */ 1246 1247 void KUndo2QStack::endMacro() 1248 { 1249 if (m_macro_stack.isEmpty()) { 1250 qWarning("KUndo2QStack::endMacro(): no matching beginMacro()"); 1251 return; 1252 } 1253 1254 m_macro_stack.removeLast(); 1255 1256 if (m_macro_stack.isEmpty()) { 1257 checkUndoLimit(); 1258 setIndex(m_index + 1, false); 1259 } 1260 } 1261 1262 /*! 1263 \since 4.4 1264 1265 Returns a const pointer to the command at \a index. 1266 1267 This function returns a const pointer, because modifying a command, 1268 once it has been pushed onto the stack and executed, almost always 1269 causes corruption of the state of the document, if the command is 1270 later undone or redone. 1271 1272 \sa KUndo2Command::child() 1273 */ 1274 const KUndo2Command *KUndo2QStack::command(int index) const 1275 { 1276 if (index < 0 || index >= m_command_list.count()) 1277 return 0; 1278 return m_command_list.at(index); 1279 } 1280 1281 /*! 1282 Returns the text of the command at index \a idx. 1283 1284 \sa beginMacro() 1285 */ 1286 1287 QString KUndo2QStack::text(int idx) const 1288 { 1289 if (idx < 0 || idx >= m_command_list.size()) 1290 return QString(); 1291 return m_command_list.at(idx)->text().toString(); 1292 } 1293 1294 /*! 1295 \property KUndo2QStack::undoLimit 1296 \brief the maximum number of commands on this stack. 1297 \since 4.3 1298 1299 When the number of commands on a stack exceeds the stack's undoLimit, commands are 1300 deleted from the bottom of the stack. Macro commands (commands with child commands) 1301 are treated as one command. The default value is 0, which means that there is no 1302 limit. 1303 1304 This property may only be set when the undo stack is empty, since setting it on a 1305 non-empty stack might delete the command at the current index. Calling setUndoLimit() 1306 on a non-empty stack prints a warning and does nothing. 1307 */ 1308 1309 void KUndo2QStack::setUndoLimit(int limit) 1310 { 1311 if (!m_command_list.isEmpty()) { 1312 qWarning("KUndo2QStack::setUndoLimit(): an undo limit can only be set when the stack is empty"); 1313 return; 1314 } 1315 1316 if (limit == m_undo_limit) 1317 return; 1318 m_undo_limit = limit; 1319 checkUndoLimit(); 1320 } 1321 1322 int KUndo2QStack::undoLimit() const 1323 { 1324 return m_undo_limit; 1325 } 1326 1327 /*! 1328 \property KUndo2QStack::active 1329 \brief the active status of this stack. 1330 1331 An application often has multiple undo stacks, one for each opened document. The active 1332 stack is the one associated with the currently active document. If the stack belongs 1333 to a KUndo2Group, calls to KUndo2Group::undo() or KUndo2Group::redo() will be forwarded 1334 to this stack when it is active. If the KUndo2Group is watched by a KUndo2View, the view 1335 will display the contents of this stack when it is active. If the stack does not belong to 1336 a KUndo2Group, making it active has no effect. 1337 1338 It is the programmer's responsibility to specify which stack is active by 1339 calling setActive(), usually when the associated document window receives focus. 1340 1341 \sa KUndo2Group 1342 */ 1343 1344 void KUndo2QStack::setActive(bool active) 1345 { 1346 #ifdef QT_NO_UNDOGROUP 1347 Q_UNUSED(active); 1348 #else 1349 if (m_group != 0) { 1350 if (active) 1351 m_group->setActiveStack(this); 1352 else if (m_group->activeStack() == this) 1353 m_group->setActiveStack(0); 1354 } 1355 #endif 1356 } 1357 1358 bool KUndo2QStack::isActive() const 1359 { 1360 #ifdef QT_NO_UNDOGROUP 1361 return true; 1362 #else 1363 return m_group == 0 || m_group->activeStack() == this; 1364 #endif 1365 } 1366 void KUndo2QStack::setUseCumulativeUndoRedo(bool value) 1367 { 1368 m_useCumulativeUndoRedo = value; 1369 } 1370 1371 bool KUndo2QStack::useCumulativeUndoRedo() const 1372 { 1373 return m_useCumulativeUndoRedo; 1374 } 1375 1376 void KUndo2QStack::setCumulativeUndoData(const KisCumulativeUndoData &data) 1377 { 1378 m_cumulativeUndoData = data; 1379 } 1380 1381 KisCumulativeUndoData KUndo2QStack::cumulativeUndoData() 1382 { 1383 return m_cumulativeUndoData; 1384 } 1385 1386 QAction* KUndo2Stack::createRedoAction(KisKActionCollection* actionCollection, const QString& actionName) 1387 { 1388 QAction* action = KUndo2QStack::createRedoAction(actionCollection); 1389 1390 if (actionName.isEmpty()) { 1391 action->setObjectName(KStandardAction::name(KStandardAction::Redo)); 1392 } else { 1393 action->setObjectName(actionName); 1394 } 1395 1396 action->setIcon(koIcon("edit-redo")); 1397 action->setIconText(i18n("Redo")); 1398 action->setShortcuts(KStandardShortcut::redo()); 1399 1400 actionCollection->addAction(action->objectName(), action); 1401 1402 return action; 1403 } 1404 1405 QAction* KUndo2Stack::createUndoAction(KisKActionCollection* actionCollection, const QString& actionName) 1406 { 1407 QAction* action = KUndo2QStack::createUndoAction(actionCollection); 1408 1409 if (actionName.isEmpty()) { 1410 action->setObjectName(KStandardAction::name(KStandardAction::Undo)); 1411 } else { 1412 action->setObjectName(actionName); 1413 } 1414 1415 action->setIcon(koIcon("edit-undo")); 1416 action->setIconText(i18n("Undo")); 1417 action->setShortcuts(KStandardShortcut::undo()); 1418 1419 actionCollection->addAction(action->objectName(), action); 1420 1421 return action; 1422 } 1423 1424 /*! 1425 \fn void KUndo2QStack::indexChanged(int idx) 1426 1427 This signal is emitted whenever a command modifies the state of the document. 1428 This happens when a command is undone or redone. When a macro 1429 command is undone or redone, or setIndex() is called, this signal 1430 is emitted only once. 1431 1432 \a idx specifies the index of the current command, ie. the command which will be 1433 executed on the next call to redo(). 1434 1435 \sa index() setIndex() 1436 */ 1437 1438 /*! 1439 \fn void KUndo2QStack::cleanChanged(bool clean) 1440 1441 This signal is emitted whenever the stack enters or leaves the clean state. 1442 If \a clean is true, the stack is in a clean state; otherwise this signal 1443 indicates that it has left the clean state. 1444 1445 \sa isClean() setClean() 1446 */ 1447 1448 /*! 1449 \fn void KUndo2QStack::undoTextChanged(const QString &undoText) 1450 1451 This signal is emitted whenever the value of undoText() changes. It is 1452 used to update the text property of the undo action returned by createUndoAction(). 1453 \a undoText specifies the new text. 1454 */ 1455 1456 /*! 1457 \fn void KUndo2QStack::canUndoChanged(bool canUndo) 1458 1459 This signal is emitted whenever the value of canUndo() changes. It is 1460 used to enable or disable the undo action returned by createUndoAction(). 1461 \a canUndo specifies the new value. 1462 */ 1463 1464 /*! 1465 \fn void KUndo2QStack::redoTextChanged(const QString &redoText) 1466 1467 This signal is emitted whenever the value of redoText() changes. It is 1468 used to update the text property of the redo action returned by createRedoAction(). 1469 \a redoText specifies the new text. 1470 */ 1471 1472 /*! 1473 \fn void KUndo2QStack::canRedoChanged(bool canRedo) 1474 1475 This signal is emitted whenever the value of canRedo() changes. It is 1476 used to enable or disable the redo action returned by createRedoAction(). 1477 \a canRedo specifies the new value. 1478 */ 1479 1480 KUndo2Stack::KUndo2Stack(QObject *parent): 1481 KUndo2QStack(parent) 1482 { 1483 } 1484 1485 #endif // QT_NO_UNDOSTACK