Krita Source Code Documentation
Loading...
Searching...
No Matches
KUndo2Group Class Reference

The KUndo2Group class is a group of KUndo2QStack objects. More...

#include <kundo2group.h>

+ Inheritance diagram for KUndo2Group:

Public Slots

void redo ()
 
void setActiveStack (KUndo2QStack *stack)
 
void undo ()
 

Signals

void activeStackChanged (KUndo2QStack *stack)
 
void canRedoChanged (bool canRedo)
 
void canUndoChanged (bool canUndo)
 
void cleanChanged (bool clean)
 
void indexChanged (int idx)
 
void redoTextChanged (const QString &redoActionText)
 
void undoTextChanged (const QString &undoActionText)
 

Public Member Functions

KUndo2QStackactiveStack () const
 
void addStack (KUndo2QStack *stack)
 
bool canRedo () const
 
bool canUndo () const
 
QAction * createRedoAction (QObject *parent) const
 
QAction * createUndoAction (QObject *parent) const
 
bool isClean () const
 
 KUndo2Group (QObject *parent=0)
 
QString redoText () const
 
void removeStack (KUndo2QStack *stack)
 
QList< KUndo2QStack * > stacks () const
 
QString undoText () const
 
 ~KUndo2Group () override
 

Private Attributes

KUndo2QStackm_active
 
QList< KUndo2QStack * > m_stack_list
 

Detailed Description

The KUndo2Group class is a group of KUndo2QStack objects.

Since
4.2

For an overview of the Qt's undo framework, see the overview.

An application often has multiple undo stacks, one for each opened document. At the same time, an application usually has one undo action and one redo action, which triggers undo or redo in the active document.

KUndo2Group is a group of KUndo2QStack objects, one of which may be active. It has an undo() and redo() slot, which calls KUndo2QStack::undo() and KUndo2QStack::redo() for the active stack. It also has the functions createUndoAction() and createRedoAction(). The actions returned by these functions behave in the same way as those returned by KUndo2QStack::createUndoAction() and KUndo2QStack::createRedoAction() of the active stack.

Stacks are added to a group with addStack() and removed with removeStack(). A stack is implicitly added to a group when it is created with the group as its parent QObject.

It is the programmer's responsibility to specify which stack is active by calling KUndo2QStack::setActive(), usually when the associated document window receives focus. The active stack may also be set with setActiveStack(), and is returned by activeStack().

When a stack is added to a group using addStack(), the group does not take ownership of the stack. This means the stack has to be deleted separately from the group. When a stack is deleted, it is automatically removed from a group. A stack may belong to only one group. Adding it to another group will cause it to be removed from the previous group.

A KUndo2Group is also useful in conjunction with KUndo2View. If a KUndo2View is set to watch a group using KUndo2View::setGroup(), it will update itself to display the active stack.

Definition at line 56 of file kundo2group.h.

Constructor & Destructor Documentation

◆ KUndo2Group()

KUndo2Group::KUndo2Group ( QObject * parent = 0)
explicit

Creates an empty KUndo2Group object with parent parent.

See also
addStack()

Definition at line 93 of file kundo2group.cpp.

94 : QObject(parent), m_active(0)
95{
96}
KUndo2QStack * m_active
Definition kundo2group.h:96

◆ ~KUndo2Group()

KUndo2Group::~KUndo2Group ( )
override

Destroys the KUndo2Group.

Definition at line 101 of file kundo2group.cpp.

102{
103 // Ensure all KUndo2Stacks no longer refer to this group.
106 while (it != end) {
107 (*it)->m_group = 0;
108 ++it;
109 }
110}
QList< KUndo2QStack * > m_stack_list
Definition kundo2group.h:97

References m_stack_list.

Member Function Documentation

◆ activeStack()

KUndo2QStack * KUndo2Group::activeStack ( ) const

Returns the active stack of this group.

If none of the stacks are active, or if the group is empty, this function returns 0.

See also
setActiveStack() KUndo2QStack::setActive()

Definition at line 235 of file kundo2group.cpp.

236{
237 return m_active;
238}

References m_active.

◆ activeStackChanged

void KUndo2Group::activeStackChanged ( KUndo2QStack * stack)
signal

This signal is emitted whenever the active stack of the group changes. This can happen when setActiveStack() or KUndo2QStack::setActive() is called, or when the active stack is removed form the group. stack is the new active stack. If no stack is active, stack is 0.

See also
setActiveStack() KUndo2QStack::setActive()

◆ addStack()

void KUndo2Group::addStack ( KUndo2QStack * stack)

Adds stack to this group. The group does not take ownership of the stack. Another way of adding a stack to a group is by specifying the group as the stack's parent QObject in KUndo2QStack::KUndo2QStack(). In this case, the stack is deleted when the group is deleted, in the usual manner of QObjects.

See also
removeStack() stacks() KUndo2QStack::KUndo2QStack()

Definition at line 121 of file kundo2group.cpp.

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}
The KUndo2Group class is a group of KUndo2QStack objects.
Definition kundo2group.h:57
KUndo2Group * m_group

References KUndo2QStack::m_group, and m_stack_list.

◆ canRedo()

bool KUndo2Group::canRedo ( ) const

Returns the value of the active stack's KUndo2QStack::canRedo().

If none of the stacks are active, or if the group is empty, this function returns false.

See also
canUndo() setActiveStack()

Definition at line 294 of file kundo2group.cpp.

295{
296 return m_active != 0 && m_active->canRedo();
297}
bool canRedo() const

References KUndo2QStack::canRedo(), and m_active.

◆ canRedoChanged

void KUndo2Group::canRedoChanged ( bool canRedo)
signal

This signal is emitted whenever the active stack emits KUndo2QStack::canRedoChanged() or the active stack changes.

canRedo is the new state, or false if the active stack is 0.

See also
KUndo2QStack::canRedoChanged() setActiveStack()

◆ canUndo()

bool KUndo2Group::canUndo ( ) const

Returns the value of the active stack's KUndo2QStack::canUndo().

If none of the stacks are active, or if the group is empty, this function returns false.

See also
canRedo() setActiveStack()

Definition at line 280 of file kundo2group.cpp.

281{
282 return m_active != 0 && m_active->canUndo();
283}
bool canUndo() const

References KUndo2QStack::canUndo(), and m_active.

◆ canUndoChanged

void KUndo2Group::canUndoChanged ( bool canUndo)
signal

This signal is emitted whenever the active stack emits KUndo2QStack::canUndoChanged() or the active stack changes.

canUndo is the new state, or false if the active stack is 0.

See also
KUndo2QStack::canUndoChanged() setActiveStack()

◆ cleanChanged

void KUndo2Group::cleanChanged ( bool clean)
signal

This signal is emitted whenever the active stack emits KUndo2QStack::cleanChanged() or the active stack changes.

clean is the new state, or true if the active stack is 0.

See also
KUndo2QStack::cleanChanged() setActiveStack()

◆ createRedoAction()

QAction * KUndo2Group::createRedoAction ( QObject * parent) const

Creates an redo QAction object with parent parent.

Triggering this action will cause a call to KUndo2QStack::redo() on the active stack. The text of this action will always be the text of the command which will be redone in the next call to redo(), prefixed by prefix. If there is no command available for redo, if the group is empty or if none of the stacks are active, this action will be disabled.

If prefix is empty, the default prefix "Undo" is used.

See also
createUndoAction() canRedo() KUndo2Command::text()

Definition at line 384 of file kundo2group.cpp.

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}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setPrefixedText(const QString &text)
bool canRedo() const
void redoTextChanged(const QString &redoActionText)
void canRedoChanged(bool canRedo)
QString redoText() const

References canRedo(), canRedoChanged(), connect(), redo(), redoText(), redoTextChanged(), and KUndo2Action::setPrefixedText().

◆ createUndoAction()

QAction * KUndo2Group::createUndoAction ( QObject * parent) const

Creates an undo QAction object with parent parent.

Triggering this action will cause a call to KUndo2QStack::undo() on the active stack. The text of this action will always be the text of the command which will be undone in the next call to undo(), prefixed by prefix. If there is no command available for undo, if the group is empty or if none of the stacks are active, this action will be disabled.

If prefix is empty, the default prefix "Undo" is used.

See also
createRedoAction() canUndo() KUndo2Command::text()

Definition at line 357 of file kundo2group.cpp.

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}
void undoTextChanged(const QString &undoActionText)
QString undoText() const
void canUndoChanged(bool canUndo)
bool canUndo() const

References canUndo(), canUndoChanged(), connect(), KUndo2Action::setPrefixedText(), undo(), undoText(), and undoTextChanged().

◆ indexChanged

void KUndo2Group::indexChanged ( int idx)
signal

This signal is emitted whenever the active stack emits KUndo2QStack::indexChanged() or the active stack changes.

idx is the new current index, or 0 if the active stack is 0.

See also
KUndo2QStack::indexChanged() setActiveStack()

◆ isClean()

bool KUndo2Group::isClean ( ) const

Returns the value of the active stack's KUndo2QStack::isClean().

If none of the stacks are active, or if the group is empty, this function returns true.

See also
setActiveStack()

Definition at line 336 of file kundo2group.cpp.

337{
338 return m_active == 0 || m_active->isClean();
339}
bool isClean() const

References KUndo2QStack::isClean(), and m_active.

◆ redo

void KUndo2Group::redo ( )
slot

Calls KUndo2QStack::redo() on the active stack.

If none of the stacks are active, or if the group is empty, this function does nothing.

See also
undo() canRedo() setActiveStack()

Definition at line 265 of file kundo2group.cpp.

266{
267 if (m_active != 0)
268 m_active->redo();
269}
virtual void redo()

References m_active, and KUndo2QStack::redo().

◆ redoText()

QString KUndo2Group::redoText ( ) const

Returns the value of the active stack's KUndo2QStack::redoActionText().

If none of the stacks are active, or if the group is empty, this function returns an empty string.

See also
redoItemText() undoActionText() setActiveStack()

Definition at line 322 of file kundo2group.cpp.

323{
324 return m_active == 0 ? QString() : m_active->redoText();
325}

References m_active, and KUndo2QStack::redoText().

◆ redoTextChanged

void KUndo2Group::redoTextChanged ( const QString & redoText)
signal

This signal is emitted whenever the active stack emits KUndo2QStack::redoTextChanged() or the active stack changes.

redoText is the new state, or an empty string if the active stack is 0.

See also
KUndo2QStack::redoTextChanged() setActiveStack()

◆ removeStack()

void KUndo2Group::removeStack ( KUndo2QStack * stack)

Removes stack from this group. If the stack was the active stack in the group, the active stack becomes 0.

See also
addStack() stacks() KUndo2QStack::~KUndo2QStack()

Definition at line 139 of file kundo2group.cpp.

140{
141 if (m_stack_list.removeAll(stack) == 0)
142 return;
143 if (stack == m_active)
145 stack->m_group = 0;
146}
void setActiveStack(KUndo2QStack *stack)

References m_active, KUndo2QStack::m_group, m_stack_list, and setActiveStack().

◆ setActiveStack

void KUndo2Group::setActiveStack ( KUndo2QStack * stack)
slot

Sets the active stack of this group to stack.

If the stack is not a member of this group, this function does nothing.

Synonymous with calling KUndo2QStack::setActive() on stack.

The actions returned by createUndoAction() and createRedoAction() will now behave in the same way as those returned by stack's KUndo2QStack::createUndoAction() and KUndo2QStack::createRedoAction().

See also
KUndo2QStack::setActive() activeStack()

Definition at line 173 of file kundo2group.cpp.

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}
void activeStackChanged(KUndo2QStack *stack)
void indexChanged(int idx)
void cleanChanged(bool clean)
QString redoText() const
QString undoText() const
int index() const

References activeStackChanged(), KUndo2QStack::canRedo(), canRedoChanged(), KUndo2QStack::canUndo(), canUndoChanged(), cleanChanged(), connect(), KUndo2QStack::index(), indexChanged(), KUndo2QStack::isClean(), m_active, KUndo2QStack::redoText(), redoTextChanged(), KUndo2QStack::undoText(), and undoTextChanged().

◆ stacks()

QList< KUndo2QStack * > KUndo2Group::stacks ( ) const

Returns a list of stacks in this group.

See also
addStack() removeStack()

Definition at line 154 of file kundo2group.cpp.

155{
156 return m_stack_list;
157}

References m_stack_list.

◆ undo

void KUndo2Group::undo ( )
slot

Calls KUndo2QStack::undo() on the active stack.

If none of the stacks are active, or if the group is empty, this function does nothing.

See also
redo() canUndo() setActiveStack()

Definition at line 249 of file kundo2group.cpp.

250{
251 if (m_active != 0)
252 m_active->undo();
253}
virtual void undo()

References m_active, and KUndo2QStack::undo().

◆ undoText()

QString KUndo2Group::undoText ( ) const

Returns the value of the active stack's KUndo2QStack::undoActionText().

If none of the stacks are active, or if the group is empty, this function returns an empty string.

See also
undoItemText() redoActionText() setActiveStack()

Definition at line 308 of file kundo2group.cpp.

309{
310 return m_active == 0 ? QString() : m_active->undoText();
311}

References m_active, and KUndo2QStack::undoText().

◆ undoTextChanged

void KUndo2Group::undoTextChanged ( const QString & undoText)
signal

This signal is emitted whenever the active stack emits KUndo2QStack::undoTextChanged() or the active stack changes.

undoText is the new state, or an empty string if the active stack is 0.

See also
KUndo2QStack::undoTextChanged() setActiveStack()

Member Data Documentation

◆ m_active

KUndo2QStack* KUndo2Group::m_active
private

Definition at line 96 of file kundo2group.h.

◆ m_stack_list

QList<KUndo2QStack*> KUndo2Group::m_stack_list
private

Definition at line 97 of file kundo2group.h.


The documentation for this class was generated from the following files: