Krita Source Code Documentation
Loading...
Searching...
No Matches
kundo2stack.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2014 Dmitry Kazakov <dimula73@gmail.com>
3 * SPDX-FileCopyrightText: 2014 Mohit Goyal <mohit.bits2011@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7/****************************************************************************
8**
9** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
10** All rights reserved.
11** Contact: Nokia Corporation (qt-info@nokia.com)
12**
13** This file is part of the QtGui module of the Qt Toolkit.
14**
15** $QT_BEGIN_LICENSE:LGPL$
16** No Commercial Usage
17** This file contains pre-release code and may not be distributed.
18** You may use this file in accordance with the terms and conditions
19** contained in the Technology Preview License Agreement accompanying
20** this package.
21**
22** GNU Lesser General Public License Usage
23** Alternatively, this file may be used under the terms of the GNU Lesser
24** General Public License version 2.1 as published by the Free Software
25** Foundation and appearing in the file LICENSE.LGPL included in the
26** packaging of this file. Please review the following information to
27** ensure the GNU Lesser General Public License version 2.1 requirements
28** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
29**
30** In addition, as a special exception, Nokia gives you certain additional
31** rights. These rights are described in the Nokia Qt LGPL Exception
32** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
33**
34** If you have questions regarding the use of this file, please contact
35** Nokia at qt-info@nokia.com.
36**
37**
38**
39**
40**
41**
42**
43**
44** $QT_END_LICENSE$
45**
46****************************************************************************/
47
48#ifndef KUNDO2STACK_H
49#define KUNDO2STACK_H
50
51#include <QObject>
52#include <QString>
53#include <QList>
54#include <QAction>
55#include <QTime>
56#include <QVector>
57
58
59#include "kritacommand_export.h"
60
61class QAction;
63class KUndo2Group;
65
66#ifndef QT_NO_UNDOCOMMAND
67
68#include "kundo2magicstring.h"
71
72
86class KRITACOMMAND_EXPORT KUndo2Command
87{
89
90public:
91 explicit KUndo2Command(KUndo2Command *parent = 0);
92 explicit KUndo2Command(const KUndo2MagicString &text, KUndo2Command *parent = 0);
93 virtual ~KUndo2Command();
94
95 virtual void undo();
96 virtual void redo();
97
98 QString actionText() const;
99 KUndo2MagicString text() const;
100 void setText(const KUndo2MagicString &text);
101
102 virtual int id() const;
103 virtual int timedId() const;
104 virtual void setTimedID(int timedID);
105 virtual bool mergeWith(const KUndo2Command *other);
106 virtual bool timedMergeWith(KUndo2Command *other);
107
108 virtual bool canAnnihilateWith(const KUndo2Command *other) const;
109
110 int childCount() const;
111 const KUndo2Command *child(int index) const;
112
113 bool hasParent() const;
114 void setTime();
115 virtual void setTime(const QTime &time);
116 virtual QTime time() const;
117 void setEndTime();
118 virtual void setEndTime(const QTime &time);
119 virtual QTime endTime() const;
120
121 virtual QVector<KUndo2Command*> mergeCommandsVector() const;
122 virtual bool isMerged() const;
123 virtual void undoMergedCommands();
124 virtual void redoMergedCommands();
125
131 KUndo2CommandExtraData* extraData() const;
132
138 void setExtraData(KUndo2CommandExtraData *data);
139
140private:
141 Q_DISABLE_COPY(KUndo2Command)
142 friend class KUndo2QStack;
143
144
145 bool m_hasParent {false};
146 int m_timedID {-1};
147
151};
152
153#endif // QT_NO_UNDOCOMMAND
154
155#ifndef QT_NO_UNDOSTACK
156
157class KRITACOMMAND_EXPORT KUndo2QStack : public QObject
158{
159 Q_OBJECT
160// Q_DECLARE_PRIVATE(KUndo2QStack)
161 Q_PROPERTY(bool active READ isActive WRITE setActive)
162 Q_PROPERTY(int undoLimit READ undoLimit WRITE setUndoLimit)
163
164public:
165 explicit KUndo2QStack(QObject *parent = 0);
166 ~KUndo2QStack() override;
167 void clear();
168
169 void push(KUndo2Command *cmd);
170
171 bool canUndo() const;
172 bool canRedo() const;
173 QString undoText() const;
174 QString redoText() const;
175
176 int count() const;
177 int index() const;
178 QString actionText(int idx) const;
179 QString text(int idx) const;
180
181#ifndef QT_NO_ACTION
182 QAction *createUndoAction(QObject *parent) const;
183 QAction *createRedoAction(QObject *parent) const;
184#endif // QT_NO_ACTION
185
186 bool isActive() const;
187 bool isClean() const;
188 int cleanIndex() const;
189
190 void beginMacro(const KUndo2MagicString &text);
191 void endMacro();
192
193 void setUndoLimit(int limit);
194 int undoLimit() const;
195
196 const KUndo2Command *command(int index) const;
197
198 void setUseCumulativeUndoRedo(bool value);
199 bool useCumulativeUndoRedo() const;
200
201 void setCumulativeUndoData(const KisCumulativeUndoData &data);
202 KisCumulativeUndoData cumulativeUndoData();
203
204public Q_SLOTS:
205 void setClean();
206 virtual void setIndex(int idx);
207 virtual void undo();
208 virtual void redo();
209 void setActive(bool active = true);
210
211 void purgeRedoState();
212
213Q_SIGNALS:
214 void indexChanged(int idx);
215 void cleanChanged(bool clean);
216 void canUndoChanged(bool canUndo);
217 void canRedoChanged(bool canRedo);
218 void undoTextChanged(const QString &undoActionText);
219 void redoTextChanged(const QString &redoActionText);
220
221protected:
222 virtual void notifySetIndexChangedOneCommand();
223
224private:
225 // from QUndoStackPrivate
234
235 // also from QUndoStackPrivate
236 void setIndex(int idx, bool clean);
237 bool checkUndoLimit();
238
239 Q_DISABLE_COPY(KUndo2QStack)
240 friend class KUndo2Group;
241};
242
243class KRITACOMMAND_EXPORT KUndo2Stack : public KUndo2QStack
244{
245public:
246 explicit KUndo2Stack(QObject *parent = 0);
247
248 // functions from KUndoStack
249 QAction* createRedoAction(KisKActionCollection* actionCollection, const QString& actionName = QString());
250 QAction* createUndoAction(KisKActionCollection* actionCollection, const QString& actionName = QString());
251};
252
253#endif // QT_NO_UNDOSTACK
254
255#endif // KUNDO2STACK_H
float value(const T *src, size_t ch)
QVector< KUndo2Command * > m_mergeCommandsVector
QTime m_endOfCommand
QTime m_timeOfCreation
The KUndo2Group class is a group of KUndo2QStack objects.
Definition kundo2group.h:57
The KUndo2QStack class is a stack of KUndo2Command objects.
QList< KUndo2Command * > m_command_list
void cleanChanged(bool clean)
QList< KUndo2Command * > m_macro_stack
void redoTextChanged(const QString &redoActionText)
void indexChanged(int idx)
void canUndoChanged(bool canUndo)
bool m_useCumulativeUndoRedo
void canRedoChanged(bool canRedo)
void undoTextChanged(const QString &undoActionText)
KisCumulativeUndoData m_cumulativeUndoData
KUndo2Group * m_group
A container for a set of QAction objects.