Krita Source Code Documentation
Loading...
Searching...
No Matches
kundo2group.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** No Commercial Usage
11** This file contains pre-release code and may not be distributed.
12** You may use this file in accordance with the terms and conditions
13** contained in the Technology Preview License Agreement accompanying
14** this package.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** If you have questions regarding the use of this file, please contact
29** Nokia at qt-info@nokia.com.
30**
31**
32**
33**
34**
35**
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "kundo2group.h"
43#include "kundo2stack.h"
44#include "kundo2stack_p.h"
45#include <klocalizedstring.h>
46
47#ifndef QT_NO_UNDOGROUP
48
94 : QObject(parent), m_active(0)
95{
96}
97
102{
103 // Ensure all KUndo2Stacks no longer refer to this group.
106 while (it != end) {
107 (*it)->m_group = 0;
108 ++it;
109 }
110}
111
122{
123 if (m_stack_list.contains(stack))
124 return;
125 m_stack_list.append(stack);
126
127 if (KUndo2Group *other = stack->m_group)
128 other->removeStack(stack);
129 stack->m_group = this;
130}
131
140{
141 if (m_stack_list.removeAll(stack) == 0)
142 return;
143 if (stack == m_active)
145 stack->m_group = 0;
146}
147
158
174{
175 if (m_active == stack)
176 return;
177
178 if (m_active != 0) {
179 disconnect(m_active, SIGNAL(canUndoChanged(bool)),
180 this, SIGNAL(canUndoChanged(bool)));
181 disconnect(m_active, SIGNAL(undoTextChanged(QString)),
182 this, SIGNAL(undoTextChanged(QString)));
183 disconnect(m_active, SIGNAL(canRedoChanged(bool)),
184 this, SIGNAL(canRedoChanged(bool)));
185 disconnect(m_active, SIGNAL(redoTextChanged(QString)),
186 this, SIGNAL(redoTextChanged(QString)));
187 disconnect(m_active, SIGNAL(indexChanged(int)),
188 this, SIGNAL(indexChanged(int)));
189 disconnect(m_active, SIGNAL(cleanChanged(bool)),
190 this, SIGNAL(cleanChanged(bool)));
191 }
192
193 m_active = stack;
194
195 if (m_active == 0) {
196 Q_EMIT canUndoChanged(false);
197 Q_EMIT undoTextChanged(QString());
198 Q_EMIT canRedoChanged(false);
199 Q_EMIT redoTextChanged(QString());
200 Q_EMIT cleanChanged(true);
201 Q_EMIT indexChanged(0);
202 } else {
203 connect(m_active, SIGNAL(canUndoChanged(bool)),
204 this, SIGNAL(canUndoChanged(bool)));
205 connect(m_active, SIGNAL(undoTextChanged(QString)),
206 this, SIGNAL(undoTextChanged(QString)));
207 connect(m_active, SIGNAL(canRedoChanged(bool)),
208 this, SIGNAL(canRedoChanged(bool)));
209 connect(m_active, SIGNAL(redoTextChanged(QString)),
210 this, SIGNAL(redoTextChanged(QString)));
211 connect(m_active, SIGNAL(indexChanged(int)),
212 this, SIGNAL(indexChanged(int)));
213 connect(m_active, SIGNAL(cleanChanged(bool)),
214 this, SIGNAL(cleanChanged(bool)));
219 Q_EMIT cleanChanged(m_active->isClean());
220 Q_EMIT indexChanged(m_active->index());
221 }
222
224}
225
236{
237 return m_active;
238}
239
250{
251 if (m_active != 0)
252 m_active->undo();
253}
254
266{
267 if (m_active != 0)
268 m_active->redo();
269}
270
281{
282 return m_active != 0 && m_active->canUndo();
283}
284
295{
296 return m_active != 0 && m_active->canRedo();
297}
298
309{
310 return m_active == 0 ? QString() : m_active->undoText();
311}
312
323{
324 return m_active == 0 ? QString() : m_active->redoText();
325}
326
337{
338 return m_active == 0 || m_active->isClean();
339}
340
341#ifndef QT_NO_ACTION
342
357QAction *KUndo2Group::createUndoAction(QObject *parent) const
358{
359 KUndo2Action *result = new KUndo2Action(i18n("Undo %1"), i18nc("Default text for undo action", "Undo"), parent);
360 result->setEnabled(canUndo());
361 result->setPrefixedText(undoText());
362 connect(this, SIGNAL(canUndoChanged(bool)),
363 result, SLOT(setEnabled(bool)));
364 connect(this, SIGNAL(undoTextChanged(QString)),
365 result, SLOT(setPrefixedText(QString)));
366 connect(result, SIGNAL(triggered()), this, SLOT(undo()));
367 return result;
368}
369
384QAction *KUndo2Group::createRedoAction(QObject *parent) const
385{
386 KUndo2Action *result = new KUndo2Action(i18n("Redo %1"), i18nc("Default text for redo action", "Redo"), parent);
387 result->setEnabled(canRedo());
388 result->setPrefixedText(redoText());
389 connect(this, SIGNAL(canRedoChanged(bool)),
390 result, SLOT(setEnabled(bool)));
391 connect(this, SIGNAL(redoTextChanged(QString)),
392 result, SLOT(setPrefixedText(QString)));
393 connect(result, SIGNAL(triggered()), this, SLOT(redo()));
394 return result;
395}
396
397#endif // QT_NO_ACTION
398
469#endif // QT_NO_UNDOGROUP
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setPrefixedText(const QString &text)
The KUndo2Group class is a group of KUndo2QStack objects.
Definition kundo2group.h:57
QAction * createUndoAction(QObject *parent) const
KUndo2Group(QObject *parent=0)
bool canRedo() const
void removeStack(KUndo2QStack *stack)
QList< KUndo2QStack * > stacks() const
void undoTextChanged(const QString &undoActionText)
bool isClean() const
void activeStackChanged(KUndo2QStack *stack)
QString undoText() const
void redoTextChanged(const QString &redoActionText)
void canUndoChanged(bool canUndo)
void setActiveStack(KUndo2QStack *stack)
KUndo2QStack * m_active
Definition kundo2group.h:96
KUndo2QStack * activeStack() const
void canRedoChanged(bool canRedo)
QAction * createRedoAction(QObject *parent) const
void indexChanged(int idx)
bool canUndo() const
void addStack(KUndo2QStack *stack)
~KUndo2Group() override
QString redoText() const
QList< KUndo2QStack * > m_stack_list
Definition kundo2group.h:97
void cleanChanged(bool clean)
The KUndo2QStack class is a stack of KUndo2Command objects.
QString redoText() const
QString undoText() const
virtual void undo()
bool canUndo() const
bool canRedo() const
virtual void redo()
bool isClean() const
int index() const
KUndo2Group * m_group