File indexing completed on 2024-05-12 15:56:14

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