Warning, file /office/calligra/libs/kundo2/kundo2stack.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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