OpenCoverage

qundogroup.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/util/qundogroup.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the QtWidgets module of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qundogroup.h"-
41#include "qundostack.h"-
42#include "qundostack_p.h"-
43-
44#ifndef QT_NO_UNDOGROUP-
45-
46QT_BEGIN_NAMESPACE-
47-
48class QUndoGroupPrivate : public QObjectPrivate-
49{-
50 Q_DECLARE_PUBLIC(QUndoGroup)-
51public:-
52 QUndoGroupPrivate() : active(0) {}
never executed: end of block
0
53-
54 QUndoStack *active;-
55 QList<QUndoStack*> stack_list;-
56};-
57-
58/*!-
59 \class QUndoGroup-
60 \brief The QUndoGroup class is a group of QUndoStack objects.-
61 \since 4.2-
62 \inmodule QtWidgets-
63-
64 For an overview of the Qt's undo framework, see the-
65 \l{qundo.html}{overview}.-
66-
67 An application often has multiple undo stacks, one for each opened document. At the-
68 same time, an application usually has one undo action and one redo action, which-
69 triggers undo or redo in the active document.-
70-
71 QUndoGroup is a group of QUndoStack objects, one of which may be active. It has-
72 an undo() and redo() slot, which calls QUndoStack::undo() and QUndoStack::redo()-
73 for the active stack. It also has the functions createUndoAction() and createRedoAction().-
74 The actions returned by these functions behave in the same way as those returned by-
75 QUndoStack::createUndoAction() and QUndoStack::createRedoAction() of the active-
76 stack.-
77-
78 Stacks are added to a group with addStack() and removed with removeStack(). A stack-
79 is implicitly added to a group when it is created with the group as its parent-
80 QObject.-
81-
82 It is the programmer's responsibility to specify which stack is active by-
83 calling QUndoStack::setActive(), usually when the associated document window receives focus.-
84 The active stack may also be set with setActiveStack(), and is returned by activeStack().-
85-
86 When a stack is added to a group using addStack(), the group does not take ownership-
87 of the stack. This means the stack has to be deleted separately from the group. When-
88 a stack is deleted, it is automatically removed from a group. A stack may belong to-
89 only one group. Adding it to another group will cause it to be removed from the previous-
90 group.-
91-
92 A QUndoGroup is also useful in conjunction with QUndoView. If a QUndoView is-
93 set to watch a group using QUndoView::setGroup(), it will update itself to display-
94 the active stack.-
95*/-
96-
97/*!-
98 Creates an empty QUndoGroup object with parent \a parent.-
99-
100 \sa addStack()-
101*/-
102-
103QUndoGroup::QUndoGroup(QObject *parent)-
104 : QObject(*new QUndoGroupPrivate(), parent)-
105{-
106}
never executed: end of block
0
107-
108/*!-
109 Destroys the QUndoGroup.-
110*/-
111QUndoGroup::~QUndoGroup()-
112{-
113 // Ensure all QUndoStacks no longer refer to this group.-
114 Q_D(QUndoGroup);-
115 QList<QUndoStack *>::iterator it = d->stack_list.begin();-
116 QList<QUndoStack *>::iterator end = d->stack_list.end();-
117 while (it != end) {
it != endDescription
TRUEnever evaluated
FALSEnever evaluated
0
118 (*it)->d_func()->group = 0;-
119 ++it;-
120 }
never executed: end of block
0
121}
never executed: end of block
0
122-
123/*!-
124 Adds \a stack to this group. The group does not take ownership of the stack. Another-
125 way of adding a stack to a group is by specifying the group as the stack's parent-
126 QObject in QUndoStack::QUndoStack(). In this case, the stack is deleted when the-
127 group is deleted, in the usual manner of QObjects.-
128-
129 \sa removeStack(), stacks(), QUndoStack::QUndoStack()-
130*/-
131-
132void QUndoGroup::addStack(QUndoStack *stack)-
133{-
134 Q_D(QUndoGroup);-
135-
136 if (d->stack_list.contains(stack))
d->stack_list.contains(stack)Description
TRUEnever evaluated
FALSEnever evaluated
0
137 return;
never executed: return;
0
138 d->stack_list.append(stack);-
139-
140 if (QUndoGroup *other = stack->d_func()->group)
QUndoGroup *ot..._func()->groupDescription
TRUEnever evaluated
FALSEnever evaluated
0
141 other->removeStack(stack);
never executed: other->removeStack(stack);
0
142 stack->d_func()->group = this;-
143}
never executed: end of block
0
144-
145/*!-
146 Removes \a stack from this group. If the stack was the active stack in the group,-
147 the active stack becomes 0.-
148-
149 \sa addStack(), stacks(), QUndoStack::~QUndoStack()-
150*/-
151-
152void QUndoGroup::removeStack(QUndoStack *stack)-
153{-
154 Q_D(QUndoGroup);-
155-
156 if (d->stack_list.removeAll(stack) == 0)
d->stack_list....ll(stack) == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
157 return;
never executed: return;
0
158 if (stack == d->active)
stack == d->activeDescription
TRUEnever evaluated
FALSEnever evaluated
0
159 setActiveStack(0);
never executed: setActiveStack(0);
0
160 stack->d_func()->group = 0;-
161}
never executed: end of block
0
162-
163/*!-
164 Returns a list of stacks in this group.-
165-
166 \sa addStack(), removeStack()-
167*/-
168-
169QList<QUndoStack*> QUndoGroup::stacks() const-
170{-
171 Q_D(const QUndoGroup);-
172 return d->stack_list;
never executed: return d->stack_list;
0
173}-
174-
175/*!-
176 Sets the active stack of this group to \a stack.-
177-
178 If the stack is not a member of this group, this function does nothing.-
179-
180 Synonymous with calling QUndoStack::setActive() on \a stack.-
181-
182 The actions returned by createUndoAction() and createRedoAction() will now behave-
183 in the same way as those returned by \a stack's QUndoStack::createUndoAction()-
184 and QUndoStack::createRedoAction().-
185-
186 \sa QUndoStack::setActive(), activeStack()-
187*/-
188-
189void QUndoGroup::setActiveStack(QUndoStack *stack)-
190{-
191 Q_D(QUndoGroup);-
192 if (d->active == stack)
d->active == stackDescription
TRUEnever evaluated
FALSEnever evaluated
0
193 return;
never executed: return;
0
194-
195 if (d->active != 0) {
d->active != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
196 disconnect(d->active, SIGNAL(canUndoChanged(bool)),-
197 this, SIGNAL(canUndoChanged(bool)));-
198 disconnect(d->active, SIGNAL(undoTextChanged(QString)),-
199 this, SIGNAL(undoTextChanged(QString)));-
200 disconnect(d->active, SIGNAL(canRedoChanged(bool)),-
201 this, SIGNAL(canRedoChanged(bool)));-
202 disconnect(d->active, SIGNAL(redoTextChanged(QString)),-
203 this, SIGNAL(redoTextChanged(QString)));-
204 disconnect(d->active, SIGNAL(indexChanged(int)),-
205 this, SIGNAL(indexChanged(int)));-
206 disconnect(d->active, SIGNAL(cleanChanged(bool)),-
207 this, SIGNAL(cleanChanged(bool)));-
208 }
never executed: end of block
0
209-
210 d->active = stack;-
211-
212 if (d->active == 0) {
d->active == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
213 emit canUndoChanged(false);-
214 emit undoTextChanged(QString());-
215 emit canRedoChanged(false);-
216 emit redoTextChanged(QString());-
217 emit cleanChanged(true);-
218 emit indexChanged(0);-
219 } else {
never executed: end of block
0
220 connect(d->active, SIGNAL(canUndoChanged(bool)),-
221 this, SIGNAL(canUndoChanged(bool)));-
222 connect(d->active, SIGNAL(undoTextChanged(QString)),-
223 this, SIGNAL(undoTextChanged(QString)));-
224 connect(d->active, SIGNAL(canRedoChanged(bool)),-
225 this, SIGNAL(canRedoChanged(bool)));-
226 connect(d->active, SIGNAL(redoTextChanged(QString)),-
227 this, SIGNAL(redoTextChanged(QString)));-
228 connect(d->active, SIGNAL(indexChanged(int)),-
229 this, SIGNAL(indexChanged(int)));-
230 connect(d->active, SIGNAL(cleanChanged(bool)),-
231 this, SIGNAL(cleanChanged(bool)));-
232 emit canUndoChanged(d->active->canUndo());-
233 emit undoTextChanged(d->active->undoText());-
234 emit canRedoChanged(d->active->canRedo());-
235 emit redoTextChanged(d->active->redoText());-
236 emit cleanChanged(d->active->isClean());-
237 emit indexChanged(d->active->index());-
238 }
never executed: end of block
0
239-
240 emit activeStackChanged(d->active);-
241}
never executed: end of block
0
242-
243/*!-
244 Returns the active stack of this group.-
245-
246 If none of the stacks are active, or if the group is empty, this function-
247 returns 0.-
248-
249 \sa setActiveStack(), QUndoStack::setActive()-
250*/-
251-
252QUndoStack *QUndoGroup::activeStack() const-
253{-
254 Q_D(const QUndoGroup);-
255 return d->active;
never executed: return d->active;
0
256}-
257-
258/*!-
259 Calls QUndoStack::undo() on the active stack.-
260-
261 If none of the stacks are active, or if the group is empty, this function-
262 does nothing.-
263-
264 \sa redo(), canUndo(), setActiveStack()-
265*/-
266-
267void QUndoGroup::undo()-
268{-
269 Q_D(QUndoGroup);-
270 if (d->active != 0)
d->active != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
271 d->active->undo();
never executed: d->active->undo();
0
272}
never executed: end of block
0
273-
274/*!-
275 Calls QUndoStack::redo() on the active stack.-
276-
277 If none of the stacks are active, or if the group is empty, this function-
278 does nothing.-
279-
280 \sa undo(), canRedo(), setActiveStack()-
281*/-
282-
283-
284void QUndoGroup::redo()-
285{-
286 Q_D(QUndoGroup);-
287 if (d->active != 0)
d->active != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
288 d->active->redo();
never executed: d->active->redo();
0
289}
never executed: end of block
0
290-
291/*!-
292 Returns the value of the active stack's QUndoStack::canUndo().-
293-
294 If none of the stacks are active, or if the group is empty, this function-
295 returns \c false.-
296-
297 \sa canRedo(), setActiveStack()-
298*/-
299-
300bool QUndoGroup::canUndo() const-
301{-
302 Q_D(const QUndoGroup);-
303 return d->active != 0 && d->active->canUndo();
never executed: return d->active != 0 && d->active->canUndo();
0
304}-
305-
306/*!-
307 Returns the value of the active stack's QUndoStack::canRedo().-
308-
309 If none of the stacks are active, or if the group is empty, this function-
310 returns \c false.-
311-
312 \sa canUndo(), setActiveStack()-
313*/-
314-
315bool QUndoGroup::canRedo() const-
316{-
317 Q_D(const QUndoGroup);-
318 return d->active != 0 && d->active->canRedo();
never executed: return d->active != 0 && d->active->canRedo();
0
319}-
320-
321/*!-
322 Returns the value of the active stack's QUndoStack::undoText().-
323-
324 If none of the stacks are active, or if the group is empty, this function-
325 returns an empty string.-
326-
327 \sa redoText(), setActiveStack()-
328*/-
329-
330QString QUndoGroup::undoText() const-
331{-
332 Q_D(const QUndoGroup);-
333 return d->active == 0 ? QString() : d->active->undoText();
never executed: return d->active == 0 ? QString() : d->active->undoText();
0
334}-
335-
336/*!-
337 Returns the value of the active stack's QUndoStack::redoText().-
338-
339 If none of the stacks are active, or if the group is empty, this function-
340 returns an empty string.-
341-
342 \sa undoText(), setActiveStack()-
343*/-
344-
345QString QUndoGroup::redoText() const-
346{-
347 Q_D(const QUndoGroup);-
348 return d->active == 0 ? QString() : d->active->redoText();
never executed: return d->active == 0 ? QString() : d->active->redoText();
0
349}-
350-
351/*!-
352 Returns the value of the active stack's QUndoStack::isClean().-
353-
354 If none of the stacks are active, or if the group is empty, this function-
355 returns \c true.-
356-
357 \sa setActiveStack()-
358*/-
359-
360bool QUndoGroup::isClean() const-
361{-
362 Q_D(const QUndoGroup);-
363 return d->active == 0 || d->active->isClean();
never executed: return d->active == 0 || d->active->isClean();
0
364}-
365-
366#ifndef QT_NO_ACTION-
367-
368/*!-
369 Creates an undo QAction object with parent \a parent.-
370-
371 Triggering this action will cause a call to QUndoStack::undo() on the active stack.-
372 The text of this action will always be the text of the command which will be undone-
373 in the next call to undo(), prefixed by \a prefix. If there is no command available-
374 for undo, if the group is empty or if none of the stacks are active, this action will-
375 be disabled.-
376-
377 If \a prefix is empty, the default template "Undo %1" is used instead of prefix.-
378 Before Qt 4.8, the prefix "Undo" was used by default.-
379-
380 \sa createRedoAction(), canUndo(), QUndoCommand::text()-
381*/-
382-
383QAction *QUndoGroup::createUndoAction(QObject *parent, const QString &prefix) const-
384{-
385 QUndoAction *result = new QUndoAction(prefix, parent);-
386 if (prefix.isEmpty())
prefix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
387 result->setTextFormat(tr("Undo %1"), tr("Undo", "Default text for undo action"));
never executed: result->setTextFormat(tr("Undo %1"), tr("Undo", "Default text for undo action"));
0
388-
389 result->setEnabled(canUndo());-
390 result->setPrefixedText(undoText());-
391 connect(this, SIGNAL(canUndoChanged(bool)),-
392 result, SLOT(setEnabled(bool)));-
393 connect(this, SIGNAL(undoTextChanged(QString)),-
394 result, SLOT(setPrefixedText(QString)));-
395 connect(result, SIGNAL(triggered()), this, SLOT(undo()));-
396 return result;
never executed: return result;
0
397}-
398-
399/*!-
400 Creates an redo QAction object with parent \a parent.-
401-
402 Triggering this action will cause a call to QUndoStack::redo() on the active stack.-
403 The text of this action will always be the text of the command which will be redone-
404 in the next call to redo(), prefixed by \a prefix. If there is no command available-
405 for redo, if the group is empty or if none of the stacks are active, this action will-
406 be disabled.-
407-
408 If \a prefix is empty, the default template "Redo %1" is used instead of prefix.-
409 Before Qt 4.8, the prefix "Redo" was used by default.-
410-
411 \sa createUndoAction(), canRedo(), QUndoCommand::text()-
412*/-
413-
414QAction *QUndoGroup::createRedoAction(QObject *parent, const QString &prefix) const-
415{-
416 QUndoAction *result = new QUndoAction(prefix, parent);-
417 if (prefix.isEmpty())
prefix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
418 result->setTextFormat(tr("Redo %1"), tr("Redo", "Default text for redo action"));
never executed: result->setTextFormat(tr("Redo %1"), tr("Redo", "Default text for redo action"));
0
419-
420 result->setEnabled(canRedo());-
421 result->setPrefixedText(redoText());-
422 connect(this, SIGNAL(canRedoChanged(bool)),-
423 result, SLOT(setEnabled(bool)));-
424 connect(this, SIGNAL(redoTextChanged(QString)),-
425 result, SLOT(setPrefixedText(QString)));-
426 connect(result, SIGNAL(triggered()), this, SLOT(redo()));-
427 return result;
never executed: return result;
0
428}-
429-
430#endif // QT_NO_ACTION-
431-
432/*! \fn void QUndoGroup::activeStackChanged(QUndoStack *stack)-
433-
434 This signal is emitted whenever the active stack of the group changes. This can happen-
435 when setActiveStack() or QUndoStack::setActive() is called, or when the active stack-
436 is removed form the group. \a stack is the new active stack. If no stack is active,-
437 \a stack is 0.-
438-
439 \sa setActiveStack(), QUndoStack::setActive()-
440*/-
441-
442/*! \fn void QUndoGroup::indexChanged(int idx)-
443-
444 This signal is emitted whenever the active stack emits QUndoStack::indexChanged()-
445 or the active stack changes.-
446-
447 \a idx is the new current index, or 0 if the active stack is 0.-
448-
449 \sa QUndoStack::indexChanged(), setActiveStack()-
450*/-
451-
452/*! \fn void QUndoGroup::cleanChanged(bool clean)-
453-
454 This signal is emitted whenever the active stack emits QUndoStack::cleanChanged()-
455 or the active stack changes.-
456-
457 \a clean is the new state, or true if the active stack is 0.-
458-
459 \sa QUndoStack::cleanChanged(), setActiveStack()-
460*/-
461-
462/*! \fn void QUndoGroup::canUndoChanged(bool canUndo)-
463-
464 This signal is emitted whenever the active stack emits QUndoStack::canUndoChanged()-
465 or the active stack changes.-
466-
467 \a canUndo is the new state, or false if the active stack is 0.-
468-
469 \sa QUndoStack::canUndoChanged(), setActiveStack()-
470*/-
471-
472/*! \fn void QUndoGroup::canRedoChanged(bool canRedo)-
473-
474 This signal is emitted whenever the active stack emits QUndoStack::canRedoChanged()-
475 or the active stack changes.-
476-
477 \a canRedo is the new state, or false if the active stack is 0.-
478-
479 \sa QUndoStack::canRedoChanged(), setActiveStack()-
480*/-
481-
482/*! \fn void QUndoGroup::undoTextChanged(const QString &undoText)-
483-
484 This signal is emitted whenever the active stack emits QUndoStack::undoTextChanged()-
485 or the active stack changes.-
486-
487 \a undoText is the new state, or an empty string if the active stack is 0.-
488-
489 \sa QUndoStack::undoTextChanged(), setActiveStack()-
490*/-
491-
492/*! \fn void QUndoGroup::redoTextChanged(const QString &redoText)-
493-
494 This signal is emitted whenever the active stack emits QUndoStack::redoTextChanged()-
495 or the active stack changes.-
496-
497 \a redoText is the new state, or an empty string if the active stack is 0.-
498-
499 \sa QUndoStack::redoTextChanged(), setActiveStack()-
500*/-
501-
502QT_END_NAMESPACE-
503-
504#include "moc_qundogroup.cpp"-
505-
506#endif // QT_NO_UNDOGROUP-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9