File indexing completed on 2024-05-12 04:35:05

0001 /* This file is part of the TikZKit project.
0002  *
0003  * Copyright (C) 2015 Dominik Haumann <dhaumann@kde.org>
0004  *
0005  * This library is free software; you can redistribute it and/or modify
0006  * it under the terms of the GNU Library General Public License as published
0007  * by the Free Software Foundation, either version 2 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 Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, see
0017  * <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #ifndef TIKZ_CORE_UNDO_GROUP_H
0021 #define TIKZ_CORE_UNDO_GROUP_H
0022 
0023 #include <QObject>
0024 #include <QString>
0025 
0026 namespace tikz {
0027 namespace core {
0028 
0029 class Document;
0030 class UndoManager;
0031 class UndoItem;
0032 class UndoGroupPrivate;
0033 
0034 /**
0035  * Class to manage a group of undo items
0036  */
0037 class UndoGroup
0038 {
0039 public:
0040     /**
0041      * Constructor with undo manager this group belongs to.
0042      */
0043     explicit UndoGroup(const QString & text, UndoManager * manager);
0044 
0045     /**
0046      * Destructor
0047      */
0048     ~UndoGroup();
0049 
0050     /**
0051      * Returns a pointer to the document.
0052      */
0053     Document * document() const;
0054 
0055     /**
0056      * Returns the description of this undo group.
0057      */
0058     QString text() const;
0059 
0060 public:
0061     /**
0062      * is this undogroup empty?
0063      */
0064     bool isEmpty() const;
0065 
0066     /**
0067      * Undo the contained undo items.
0068      */
0069     void undo();
0070 
0071     /**
0072      * Redo the contained undo items.
0073      */
0074     void redo();
0075 
0076 public:
0077     /**
0078      * Add @p item to the undo group.
0079      * If possible, @p item is merged with the last item in this undo group.
0080      * If a merge was performed, the @p item pointer is invalid afterwards,
0081      * so never access @p item after adding an item to a group.
0082      */
0083     void addItem(UndoItem * item);
0084 
0085     /**
0086      * Returns a list of all undo items.
0087      * You must not delete the pointers to the UndoItem%s.
0088      */
0089     QList<UndoItem *> undoItems() const;
0090 
0091     /**
0092      * Returns the number of undo items;
0093      */
0094     int count() const;
0095 
0096 public:
0097     // debugging
0098     void printTree();
0099 
0100 private:
0101     /**
0102      * Pimpl pointer to the held data.
0103      */
0104     UndoGroupPrivate * const d;
0105 };
0106 
0107 }
0108 }
0109 
0110 #endif // TIKZ_CORE_UNDO_GROUP_H
0111 
0112 // kate: indent-width 4; replace-tabs on;