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 test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | |
30 | #include <QtTest/QtTest> |
31 | #include <QAction> |
32 | #include <QUndoStack> |
33 | |
34 | /****************************************************************************** |
35 | ** Commands |
36 | */ |
37 | |
38 | class InsertCommand : public QUndoCommand |
39 | { |
40 | public: |
41 | InsertCommand(QString *str, int idx, const QString &text, |
42 | QUndoCommand *parent = 0); |
43 | |
44 | virtual void undo(); |
45 | virtual void redo(); |
46 | |
47 | private: |
48 | QString *m_str; |
49 | int m_idx; |
50 | QString m_text; |
51 | }; |
52 | |
53 | class RemoveCommand : public QUndoCommand |
54 | { |
55 | public: |
56 | RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent = 0); |
57 | |
58 | virtual void undo(); |
59 | virtual void redo(); |
60 | |
61 | private: |
62 | QString *m_str; |
63 | int m_idx; |
64 | QString m_text; |
65 | }; |
66 | |
67 | class AppendCommand : public QUndoCommand |
68 | { |
69 | public: |
70 | AppendCommand(QString *str, const QString &text, bool _fail_merge = false, |
71 | QUndoCommand *parent = 0); |
72 | ~AppendCommand(); |
73 | |
74 | virtual void undo(); |
75 | virtual void redo(); |
76 | virtual int id() const; |
77 | virtual bool mergeWith(const QUndoCommand *other); |
78 | |
79 | bool merged; |
80 | bool fail_merge; |
81 | static int delete_cnt; |
82 | |
83 | private: |
84 | QString *m_str; |
85 | QString m_text; |
86 | }; |
87 | |
88 | class IdleCommand : public QUndoCommand |
89 | { |
90 | public: |
91 | IdleCommand(QUndoCommand *parent = 0); |
92 | ~IdleCommand(); |
93 | |
94 | virtual void undo(); |
95 | virtual void redo(); |
96 | }; |
97 | |
98 | class MoveMouseCommand : public QUndoCommand |
99 | { |
100 | public: |
101 | MoveMouseCommand(QPoint *mouse, QPoint oldPoint, QPoint newPoint, QUndoCommand *parent = 0); |
102 | ~MoveMouseCommand(); |
103 | |
104 | virtual void undo(); |
105 | virtual void redo(); |
106 | virtual int id() const; |
107 | virtual bool mergeWith(const QUndoCommand *other); |
108 | |
109 | private: |
110 | QPoint *m_mouse; |
111 | QPoint m_oldPoint; |
112 | QPoint m_newPoint; |
113 | }; |
114 | |
115 | InsertCommand::InsertCommand(QString *str, int idx, const QString &text, |
116 | QUndoCommand *parent) |
117 | : QUndoCommand(parent) |
118 | { |
119 | QVERIFY(str->length() >= idx); |
120 | |
121 | setText("insert" ); |
122 | |
123 | m_str = str; |
124 | m_idx = idx; |
125 | m_text = text; |
126 | } |
127 | |
128 | void InsertCommand::redo() |
129 | { |
130 | QVERIFY(m_str->length() >= m_idx); |
131 | |
132 | m_str->insert(i: m_idx, s: m_text); |
133 | } |
134 | |
135 | void InsertCommand::undo() |
136 | { |
137 | QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); |
138 | |
139 | m_str->remove(i: m_idx, len: m_text.length()); |
140 | } |
141 | |
142 | RemoveCommand::RemoveCommand(QString *str, int idx, int len, QUndoCommand *parent) |
143 | : QUndoCommand(parent) |
144 | { |
145 | QVERIFY(str->length() >= idx + len); |
146 | |
147 | setText("remove" ); |
148 | |
149 | m_str = str; |
150 | m_idx = idx; |
151 | m_text = m_str->mid(position: m_idx, n: len); |
152 | } |
153 | |
154 | void RemoveCommand::redo() |
155 | { |
156 | QCOMPARE(m_str->mid(m_idx, m_text.length()), m_text); |
157 | |
158 | m_str->remove(i: m_idx, len: m_text.length()); |
159 | } |
160 | |
161 | void RemoveCommand::undo() |
162 | { |
163 | QVERIFY(m_str->length() >= m_idx); |
164 | |
165 | m_str->insert(i: m_idx, s: m_text); |
166 | } |
167 | |
168 | int AppendCommand::delete_cnt = 0; |
169 | |
170 | AppendCommand::AppendCommand(QString *str, const QString &text, bool _fail_merge, |
171 | QUndoCommand *parent) |
172 | : QUndoCommand(parent) |
173 | { |
174 | setText("append" ); |
175 | |
176 | m_str = str; |
177 | m_text = text; |
178 | merged = false; |
179 | fail_merge = _fail_merge; |
180 | } |
181 | |
182 | AppendCommand::~AppendCommand() |
183 | { |
184 | ++delete_cnt; |
185 | } |
186 | |
187 | void AppendCommand::redo() |
188 | { |
189 | m_str->append(s: m_text); |
190 | } |
191 | |
192 | void AppendCommand::undo() |
193 | { |
194 | QCOMPARE(m_str->mid(m_str->length() - m_text.length()), m_text); |
195 | |
196 | m_str->truncate(pos: m_str->length() - m_text.length()); |
197 | } |
198 | |
199 | int AppendCommand::id() const |
200 | { |
201 | return 1; |
202 | } |
203 | |
204 | bool AppendCommand::mergeWith(const QUndoCommand *other) |
205 | { |
206 | if (other->id() != id()) |
207 | return false; |
208 | if (fail_merge) |
209 | return false; |
210 | m_text += static_cast<const AppendCommand*>(other)->m_text; |
211 | merged = true; |
212 | return true; |
213 | } |
214 | |
215 | IdleCommand::IdleCommand(QUndoCommand *parent) |
216 | : QUndoCommand(parent) |
217 | { |
218 | // "idle-item" goes to QUndoStack::{redo,undo}Text |
219 | // "idle-action" goes to all other places (e.g. QUndoView) |
220 | setText("idle-item\nidle-action" ); |
221 | } |
222 | |
223 | IdleCommand::~IdleCommand() |
224 | { |
225 | } |
226 | |
227 | void IdleCommand::redo() |
228 | { |
229 | } |
230 | |
231 | void IdleCommand::undo() |
232 | { |
233 | } |
234 | |
235 | MoveMouseCommand::MoveMouseCommand(QPoint *mouse, QPoint oldPoint, QPoint newPoint, QUndoCommand *parent) |
236 | : QUndoCommand(parent) |
237 | { |
238 | setText("move mouse" ); |
239 | |
240 | m_mouse = mouse; |
241 | m_oldPoint = oldPoint; |
242 | m_newPoint = newPoint; |
243 | |
244 | if (m_oldPoint == m_newPoint) |
245 | setObsolete(true); |
246 | } |
247 | |
248 | MoveMouseCommand::~MoveMouseCommand() |
249 | { |
250 | } |
251 | |
252 | void MoveMouseCommand::redo() |
253 | { |
254 | *m_mouse = m_newPoint; |
255 | } |
256 | |
257 | void MoveMouseCommand::undo() |
258 | { |
259 | *m_mouse = m_oldPoint; |
260 | } |
261 | |
262 | int MoveMouseCommand::id() const |
263 | { |
264 | return 2; |
265 | } |
266 | |
267 | bool MoveMouseCommand::mergeWith(const QUndoCommand *other) |
268 | { |
269 | m_newPoint = static_cast<const MoveMouseCommand*>(other)->m_newPoint; |
270 | |
271 | if (m_newPoint == m_oldPoint) |
272 | setObsolete(true); |
273 | |
274 | return true; |
275 | } |
276 | |
277 | /****************************************************************************** |
278 | ** tst_QUndoStack |
279 | */ |
280 | |
281 | class tst_QUndoStack : public QObject |
282 | { |
283 | Q_OBJECT |
284 | public: |
285 | tst_QUndoStack(); |
286 | |
287 | private slots: |
288 | void undoRedo(); |
289 | void setIndex(); |
290 | void setClean(); |
291 | void clear(); |
292 | void childCommand(); |
293 | void macroBeginEnd(); |
294 | void compression(); |
295 | void obsolete(); |
296 | void undoLimit(); |
297 | void commandTextFormat(); |
298 | void separateUndoText(); |
299 | }; |
300 | |
301 | tst_QUndoStack::tst_QUndoStack() |
302 | { |
303 | } |
304 | |
305 | static QString glue(const QString &s1, const QString &s2) |
306 | { |
307 | QString result; |
308 | |
309 | result.append(s: s1); |
310 | if (!s1.isEmpty() && !s2.isEmpty()) |
311 | result.append(c: ' '); |
312 | result.append(s: s2); |
313 | |
314 | return result; |
315 | } |
316 | |
317 | static void checkState(QSignalSpy &redoTextChangedSpy, |
318 | QSignalSpy &canRedoChangedSpy, |
319 | QSignalSpy &undoTextChangedSpy, |
320 | const QScopedPointer<QAction> &redoAction, |
321 | const QScopedPointer<QAction> &undoAction, |
322 | QSignalSpy &canUndoChangedSpy, |
323 | QSignalSpy &cleanChangedSpy, |
324 | QSignalSpy &indexChangedSpy, |
325 | QUndoStack &stack, |
326 | const bool _clean, |
327 | const int _count, |
328 | const int _index, |
329 | const bool _canUndo, |
330 | const QString &_undoText, |
331 | const bool _canRedo, |
332 | const QString &_redoText, |
333 | const bool _cleanChanged, |
334 | const bool _indexChanged, |
335 | const bool _undoChanged, |
336 | const bool _redoChanged) |
337 | { |
338 | QCOMPARE(stack.count(), _count); |
339 | QCOMPARE(stack.isClean(), _clean); |
340 | QCOMPARE(stack.index(), _index); |
341 | QCOMPARE(stack.canUndo(), _canUndo); |
342 | QCOMPARE(stack.undoText(), QString(_undoText)); |
343 | QCOMPARE(stack.canRedo(), _canRedo); |
344 | QCOMPARE(stack.redoText(), QString(_redoText)); |
345 | if (_indexChanged) { |
346 | QCOMPARE(indexChangedSpy.count(), 1); |
347 | QCOMPARE(indexChangedSpy.at(0).at(0).toInt(), _index); |
348 | indexChangedSpy.clear(); |
349 | } else { |
350 | QCOMPARE(indexChangedSpy.count(), 0); |
351 | } |
352 | if (_cleanChanged) { |
353 | QCOMPARE(cleanChangedSpy.count(), 1); |
354 | QCOMPARE(cleanChangedSpy.at(0).at(0).toBool(), _clean); |
355 | cleanChangedSpy.clear(); |
356 | } else { |
357 | QCOMPARE(cleanChangedSpy.count(), 0); |
358 | } |
359 | if (_undoChanged) { |
360 | QCOMPARE(canUndoChangedSpy.count(), 1); |
361 | QCOMPARE(canUndoChangedSpy.at(0).at(0).toBool(), _canUndo); |
362 | QCOMPARE(undoAction->isEnabled(), _canUndo); |
363 | QCOMPARE(undoTextChangedSpy.count(), 1); |
364 | QCOMPARE(undoTextChangedSpy.at(0).at(0).toString(), QString(_undoText)); |
365 | QCOMPARE(undoAction->text(), glue("foo" , _undoText)); |
366 | canUndoChangedSpy.clear(); |
367 | undoTextChangedSpy.clear(); |
368 | } else { |
369 | QCOMPARE(canUndoChangedSpy.count(), 0); |
370 | QCOMPARE(undoTextChangedSpy.count(), 0); |
371 | } |
372 | if (_redoChanged) { |
373 | QCOMPARE(canRedoChangedSpy.count(), 1); |
374 | QCOMPARE(canRedoChangedSpy.at(0).at(0).toBool(), _canRedo); |
375 | QCOMPARE(redoAction->isEnabled(), _canRedo); |
376 | QCOMPARE(redoTextChangedSpy.count(), 1); |
377 | QCOMPARE(redoTextChangedSpy.at(0).at(0).toString(), QString(_redoText)); |
378 | QCOMPARE(redoAction->text(), glue("bar" , _redoText)); |
379 | canRedoChangedSpy.clear(); |
380 | redoTextChangedSpy.clear(); |
381 | } else { |
382 | QCOMPARE(canRedoChangedSpy.count(), 0); |
383 | QCOMPARE(redoTextChangedSpy.count(), 0); |
384 | } |
385 | } |
386 | |
387 | void tst_QUndoStack::undoRedo() |
388 | { |
389 | QUndoStack stack; |
390 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
391 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
392 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
393 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
394 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
395 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
396 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
397 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
398 | QString str; |
399 | |
400 | // push, undo, redo |
401 | |
402 | checkState(redoTextChangedSpy, |
403 | canRedoChangedSpy, |
404 | undoTextChangedSpy, |
405 | redoAction, |
406 | undoAction, |
407 | canUndoChangedSpy, |
408 | cleanChangedSpy, |
409 | indexChangedSpy, |
410 | stack, |
411 | clean: true, // clean |
412 | count: 0, // count |
413 | index: 0, // index |
414 | canUndo: false, // canUndo |
415 | undoText: "" , // undoText |
416 | canRedo: false, // canRedo |
417 | redoText: "" , // redoText |
418 | cleanChanged: false, // cleanChanged |
419 | indexChanged: false, // indexChanged |
420 | undoChanged: false, // undoChanged |
421 | redoChanged: false); // redoChanged |
422 | |
423 | stack.undo(); // nothing to undo |
424 | QCOMPARE(str, QString()); |
425 | checkState(redoTextChangedSpy, |
426 | canRedoChangedSpy, |
427 | undoTextChangedSpy, |
428 | redoAction, |
429 | undoAction, |
430 | canUndoChangedSpy, |
431 | cleanChangedSpy, |
432 | indexChangedSpy, |
433 | stack, |
434 | clean: true, // clean |
435 | count: 0, // count |
436 | index: 0, // index |
437 | canUndo: false, // canUndo |
438 | undoText: "" , // undoText |
439 | canRedo: false, // canRedo |
440 | redoText: "" , // redoText |
441 | cleanChanged: false, // cleanChanged |
442 | indexChanged: false, // indexChanged |
443 | undoChanged: false, // undoChanged |
444 | redoChanged: false); // redoChanged |
445 | |
446 | stack.push(cmd: new InsertCommand(&str, 0, "hello" )); |
447 | QCOMPARE(str, QString("hello" )); |
448 | checkState(redoTextChangedSpy, |
449 | canRedoChangedSpy, |
450 | undoTextChangedSpy, |
451 | redoAction, |
452 | undoAction, |
453 | canUndoChangedSpy, |
454 | cleanChangedSpy, |
455 | indexChangedSpy, |
456 | stack, |
457 | clean: false, // clean |
458 | count: 1, // count |
459 | index: 1, // index |
460 | canUndo: true, // canUndo |
461 | undoText: "insert" , // undoText |
462 | canRedo: false, // canRedo |
463 | redoText: "" , // redoText |
464 | cleanChanged: true, // cleanChanged |
465 | indexChanged: true, // indexChanged |
466 | undoChanged: true, // undoChanged |
467 | redoChanged: true); // redoChanged |
468 | |
469 | stack.push(cmd: new InsertCommand(&str, 2, "123" )); |
470 | QCOMPARE(str, QString("he123llo" )); |
471 | checkState(redoTextChangedSpy, |
472 | canRedoChangedSpy, |
473 | undoTextChangedSpy, |
474 | redoAction, |
475 | undoAction, |
476 | canUndoChangedSpy, |
477 | cleanChangedSpy, |
478 | indexChangedSpy, |
479 | stack, |
480 | clean: false, // clean |
481 | count: 2, // count |
482 | index: 2, // index |
483 | canUndo: true, // canUndo |
484 | undoText: "insert" , // undoText |
485 | canRedo: false, // canRedo |
486 | redoText: "" , // redoText |
487 | cleanChanged: false, // cleanChanged |
488 | indexChanged: true, // indexChanged |
489 | undoChanged: true, // undoChanged |
490 | redoChanged: true); // redoChanged |
491 | |
492 | |
493 | stack.undo(); |
494 | QCOMPARE(str, QString("hello" )); |
495 | checkState(redoTextChangedSpy, |
496 | canRedoChangedSpy, |
497 | undoTextChangedSpy, |
498 | redoAction, |
499 | undoAction, |
500 | canUndoChangedSpy, |
501 | cleanChangedSpy, |
502 | indexChangedSpy, |
503 | stack, |
504 | clean: false, // clean |
505 | count: 2, // count |
506 | index: 1, // index |
507 | canUndo: true, // canUndo |
508 | undoText: "insert" , // undoText |
509 | canRedo: true, // canRedo |
510 | redoText: "insert" , // redoText |
511 | cleanChanged: false, // cleanChanged |
512 | indexChanged: true, // indexChanged |
513 | undoChanged: true, // undoChanged |
514 | redoChanged: true); // redoChanged |
515 | |
516 | stack.redo(); |
517 | QCOMPARE(str, QString("he123llo" )); |
518 | checkState(redoTextChangedSpy, |
519 | canRedoChangedSpy, |
520 | undoTextChangedSpy, |
521 | redoAction, |
522 | undoAction, |
523 | canUndoChangedSpy, |
524 | cleanChangedSpy, |
525 | indexChangedSpy, |
526 | stack, |
527 | clean: false, // clean |
528 | count: 2, // count |
529 | index: 2, // index |
530 | canUndo: true, // canUndo |
531 | undoText: "insert" , // undoText |
532 | canRedo: false, // canRedo |
533 | redoText: "" , // redoText |
534 | cleanChanged: false, // cleanChanged |
535 | indexChanged: true, // indexChanged |
536 | undoChanged: true, // undoChanged |
537 | redoChanged: true); // redoChanged |
538 | |
539 | stack.redo(); // nothing to redo |
540 | QCOMPARE(str, QString("he123llo" )); |
541 | checkState(redoTextChangedSpy, |
542 | canRedoChangedSpy, |
543 | undoTextChangedSpy, |
544 | redoAction, |
545 | undoAction, |
546 | canUndoChangedSpy, |
547 | cleanChangedSpy, |
548 | indexChangedSpy, |
549 | stack, |
550 | clean: false, // clean |
551 | count: 2, // count |
552 | index: 2, // index |
553 | canUndo: true, // canUndo |
554 | undoText: "insert" , // undoText |
555 | canRedo: false, // canRedo |
556 | redoText: "" , // redoText |
557 | cleanChanged: false, // cleanChanged |
558 | indexChanged: false, // indexChanged |
559 | undoChanged: false, // undoChanged |
560 | redoChanged: false); // redoChanged |
561 | |
562 | stack.undo(); |
563 | QCOMPARE(str, QString("hello" )); |
564 | checkState(redoTextChangedSpy, |
565 | canRedoChangedSpy, |
566 | undoTextChangedSpy, |
567 | redoAction, |
568 | undoAction, |
569 | canUndoChangedSpy, |
570 | cleanChangedSpy, |
571 | indexChangedSpy, |
572 | stack, |
573 | clean: false, // clean |
574 | count: 2, // count |
575 | index: 1, // index |
576 | canUndo: true, // canUndo |
577 | undoText: "insert" , // undoText |
578 | canRedo: true, // canRedo |
579 | redoText: "insert" , // redoText |
580 | cleanChanged: false, // cleanChanged |
581 | indexChanged: true, // indexChanged |
582 | undoChanged: true, // undoChanged |
583 | redoChanged: true); // redoChanged |
584 | |
585 | stack.undo(); |
586 | QCOMPARE(str, QString()); |
587 | checkState(redoTextChangedSpy, |
588 | canRedoChangedSpy, |
589 | undoTextChangedSpy, |
590 | redoAction, |
591 | undoAction, |
592 | canUndoChangedSpy, |
593 | cleanChangedSpy, |
594 | indexChangedSpy, |
595 | stack, |
596 | clean: true, // clean |
597 | count: 2, // count |
598 | index: 0, // index |
599 | canUndo: false, // canUndo |
600 | undoText: "" , // undoText |
601 | canRedo: true, // canRedo |
602 | redoText: "insert" , // redoText |
603 | cleanChanged: true, // cleanChanged |
604 | indexChanged: true, // indexChanged |
605 | undoChanged: true, // undoChanged |
606 | redoChanged: true); // redoChanged |
607 | |
608 | stack.undo(); // nothing to undo |
609 | QCOMPARE(str, QString()); |
610 | checkState(redoTextChangedSpy, |
611 | canRedoChangedSpy, |
612 | undoTextChangedSpy, |
613 | redoAction, |
614 | undoAction, |
615 | canUndoChangedSpy, |
616 | cleanChangedSpy, |
617 | indexChangedSpy, |
618 | stack, |
619 | clean: true, // clean |
620 | count: 2, // count |
621 | index: 0, // index |
622 | canUndo: false, // canUndo |
623 | undoText: "" , // undoText |
624 | canRedo: true, // canRedo |
625 | redoText: "insert" , // redoText |
626 | cleanChanged: false, // cleanChanged |
627 | indexChanged: false, // indexChanged |
628 | undoChanged: false, // undoChanged |
629 | redoChanged: false); // redoChanged |
630 | |
631 | // push after undo - check that undone commands get deleted |
632 | |
633 | stack.redo(); |
634 | checkState(redoTextChangedSpy, |
635 | canRedoChangedSpy, |
636 | undoTextChangedSpy, |
637 | redoAction, |
638 | undoAction, |
639 | canUndoChangedSpy, |
640 | cleanChangedSpy, |
641 | indexChangedSpy, |
642 | stack, |
643 | clean: false, // clean |
644 | count: 2, // count |
645 | index: 1, // index |
646 | canUndo: true, // canUndo |
647 | undoText: "insert" , // undoText |
648 | canRedo: true, // canRedo |
649 | redoText: "insert" , // redoText |
650 | cleanChanged: true, // cleanChanged |
651 | indexChanged: true, // indexChanged |
652 | undoChanged: true, // undoChanged |
653 | redoChanged: true); // redoChanged |
654 | |
655 | stack.push(cmd: new RemoveCommand(&str, 2, 2)); |
656 | QCOMPARE(str, QString("heo" )); |
657 | checkState(redoTextChangedSpy, |
658 | canRedoChangedSpy, |
659 | undoTextChangedSpy, |
660 | redoAction, |
661 | undoAction, |
662 | canUndoChangedSpy, |
663 | cleanChangedSpy, |
664 | indexChangedSpy, |
665 | stack, |
666 | clean: false, // clean |
667 | count: 2, // count - still 2, last command got deleted |
668 | index: 2, // index |
669 | canUndo: true, // canUndo |
670 | undoText: "remove" , // undoText |
671 | canRedo: false, // canRedo |
672 | redoText: "" , // redoText |
673 | cleanChanged: false, // cleanChanged |
674 | indexChanged: true, // indexChanged |
675 | undoChanged: true, // undoChanged |
676 | redoChanged: true); // redoChanged |
677 | |
678 | stack.undo(); |
679 | QCOMPARE(str, QString("hello" )); |
680 | checkState(redoTextChangedSpy, |
681 | canRedoChangedSpy, |
682 | undoTextChangedSpy, |
683 | redoAction, |
684 | undoAction, |
685 | canUndoChangedSpy, |
686 | cleanChangedSpy, |
687 | indexChangedSpy, |
688 | stack, |
689 | clean: false, // clean |
690 | count: 2, // count |
691 | index: 1, // index |
692 | canUndo: true, // canUndo |
693 | undoText: "insert" , // undoText |
694 | canRedo: true, // canRedo |
695 | redoText: "remove" , // redoText |
696 | cleanChanged: false, // cleanChanged |
697 | indexChanged: true, // indexChanged |
698 | undoChanged: true, // undoChanged |
699 | redoChanged: true); // redoChanged |
700 | |
701 | stack.undo(); |
702 | QCOMPARE(str, QString()); |
703 | checkState(redoTextChangedSpy, |
704 | canRedoChangedSpy, |
705 | undoTextChangedSpy, |
706 | redoAction, |
707 | undoAction, |
708 | canUndoChangedSpy, |
709 | cleanChangedSpy, |
710 | indexChangedSpy, |
711 | stack, |
712 | clean: true, // clean |
713 | count: 2, // count |
714 | index: 0, // index |
715 | canUndo: false, // canUndo |
716 | undoText: "" , // undoText |
717 | canRedo: true, // canRedo |
718 | redoText: "insert" , // redoText |
719 | cleanChanged: true, // cleanChanged |
720 | indexChanged: true, // indexChanged |
721 | undoChanged: true, // undoChanged |
722 | redoChanged: true); // redoChanged |
723 | |
724 | stack.push(cmd: new InsertCommand(&str, 0, "goodbye" )); |
725 | QCOMPARE(str, QString("goodbye" )); |
726 | checkState(redoTextChangedSpy, |
727 | canRedoChangedSpy, |
728 | undoTextChangedSpy, |
729 | redoAction, |
730 | undoAction, |
731 | canUndoChangedSpy, |
732 | cleanChangedSpy, |
733 | indexChangedSpy, |
734 | stack, |
735 | clean: false, // clean |
736 | count: 1, // count - two commands got deleted |
737 | index: 1, // index |
738 | canUndo: true, // canUndo |
739 | undoText: "insert" , // undoText |
740 | canRedo: false, // canRedo |
741 | redoText: "" , // redoText |
742 | cleanChanged: true, // cleanChanged |
743 | indexChanged: true, // indexChanged |
744 | undoChanged: true, // undoChanged |
745 | redoChanged: true); // redoChanged |
746 | } |
747 | |
748 | void tst_QUndoStack::setIndex() |
749 | { |
750 | QUndoStack stack; |
751 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
752 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
753 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
754 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
755 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
756 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
757 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
758 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
759 | QString str; |
760 | |
761 | stack.setIndex(10); // should do nothing |
762 | checkState(redoTextChangedSpy, |
763 | canRedoChangedSpy, |
764 | undoTextChangedSpy, |
765 | redoAction, |
766 | undoAction, |
767 | canUndoChangedSpy, |
768 | cleanChangedSpy, |
769 | indexChangedSpy, |
770 | stack, |
771 | clean: true, // clean |
772 | count: 0, // count |
773 | index: 0, // index |
774 | canUndo: false, // canUndo |
775 | undoText: "" , // undoText |
776 | canRedo: false, // canRedo |
777 | redoText: "" , // redoText |
778 | cleanChanged: false, // cleanChanged |
779 | indexChanged: false, // indexChanged |
780 | undoChanged: false, // undoChanged |
781 | redoChanged: false); // redoChanged |
782 | |
783 | stack.setIndex(0); // should do nothing |
784 | checkState(redoTextChangedSpy, |
785 | canRedoChangedSpy, |
786 | undoTextChangedSpy, |
787 | redoAction, |
788 | undoAction, |
789 | canUndoChangedSpy, |
790 | cleanChangedSpy, |
791 | indexChangedSpy, |
792 | stack, |
793 | clean: true, // clean |
794 | count: 0, // count |
795 | index: 0, // index |
796 | canUndo: false, // canUndo |
797 | undoText: "" , // undoText |
798 | canRedo: false, // canRedo |
799 | redoText: "" , // redoText |
800 | cleanChanged: false, // cleanChanged |
801 | indexChanged: false, // indexChanged |
802 | undoChanged: false, // undoChanged |
803 | redoChanged: false); // redoChanged |
804 | |
805 | stack.setIndex(-10); // should do nothing |
806 | checkState(redoTextChangedSpy, |
807 | canRedoChangedSpy, |
808 | undoTextChangedSpy, |
809 | redoAction, |
810 | undoAction, |
811 | canUndoChangedSpy, |
812 | cleanChangedSpy, |
813 | indexChangedSpy, |
814 | stack, |
815 | clean: true, // clean |
816 | count: 0, // count |
817 | index: 0, // index |
818 | canUndo: false, // canUndo |
819 | undoText: "" , // undoText |
820 | canRedo: false, // canRedo |
821 | redoText: "" , // redoText |
822 | cleanChanged: false, // cleanChanged |
823 | indexChanged: false, // indexChanged |
824 | undoChanged: false, // undoChanged |
825 | redoChanged: false); // redoChanged |
826 | |
827 | stack.push(cmd: new InsertCommand(&str, 0, "hello" )); |
828 | QCOMPARE(str, QString("hello" )); |
829 | checkState(redoTextChangedSpy, |
830 | canRedoChangedSpy, |
831 | undoTextChangedSpy, |
832 | redoAction, |
833 | undoAction, |
834 | canUndoChangedSpy, |
835 | cleanChangedSpy, |
836 | indexChangedSpy, |
837 | stack, |
838 | clean: false, // clean |
839 | count: 1, // count |
840 | index: 1, // index |
841 | canUndo: true, // canUndo |
842 | undoText: "insert" , // undoText |
843 | canRedo: false, // canRedo |
844 | redoText: "" , // redoText |
845 | cleanChanged: true, // cleanChanged |
846 | indexChanged: true, // indexChanged |
847 | undoChanged: true, // undoChanged |
848 | redoChanged: true); // redoChanged |
849 | |
850 | stack.push(cmd: new InsertCommand(&str, 2, "123" )); |
851 | QCOMPARE(str, QString("he123llo" )); |
852 | checkState(redoTextChangedSpy, |
853 | canRedoChangedSpy, |
854 | undoTextChangedSpy, |
855 | redoAction, |
856 | undoAction, |
857 | canUndoChangedSpy, |
858 | cleanChangedSpy, |
859 | indexChangedSpy, |
860 | stack, |
861 | clean: false, // clean |
862 | count: 2, // count |
863 | index: 2, // index |
864 | canUndo: true, // canUndo |
865 | undoText: "insert" , // undoText |
866 | canRedo: false, // canRedo |
867 | redoText: "" , // redoText |
868 | cleanChanged: false, // cleanChanged |
869 | indexChanged: true, // indexChanged |
870 | undoChanged: true, // undoChanged |
871 | redoChanged: true); // redoChanged |
872 | |
873 | stack.setIndex(2); |
874 | QCOMPARE(str, QString("he123llo" )); |
875 | checkState(redoTextChangedSpy, |
876 | canRedoChangedSpy, |
877 | undoTextChangedSpy, |
878 | redoAction, |
879 | undoAction, |
880 | canUndoChangedSpy, |
881 | cleanChangedSpy, |
882 | indexChangedSpy, |
883 | stack, |
884 | clean: false, // clean |
885 | count: 2, // count |
886 | index: 2, // index |
887 | canUndo: true, // canUndo |
888 | undoText: "insert" , // undoText |
889 | canRedo: false, // canRedo |
890 | redoText: "" , // redoText |
891 | cleanChanged: false, // cleanChanged |
892 | indexChanged: false, // indexChanged |
893 | undoChanged: false, // undoChanged |
894 | redoChanged: false); // redoChanged |
895 | |
896 | stack.setIndex(0); |
897 | QCOMPARE(str, QString()); |
898 | checkState(redoTextChangedSpy, |
899 | canRedoChangedSpy, |
900 | undoTextChangedSpy, |
901 | redoAction, |
902 | undoAction, |
903 | canUndoChangedSpy, |
904 | cleanChangedSpy, |
905 | indexChangedSpy, |
906 | stack, |
907 | clean: true, // clean |
908 | count: 2, // count |
909 | index: 0, // index |
910 | canUndo: false, // canUndo |
911 | undoText: "" , // undoText |
912 | canRedo: true, // canRedo |
913 | redoText: "insert" , // redoText |
914 | cleanChanged: true, // cleanChanged |
915 | indexChanged: true, // indexChanged |
916 | undoChanged: true, // undoChanged |
917 | redoChanged: true); // redoChanged |
918 | |
919 | stack.setIndex(10); // should set index to 2 |
920 | QCOMPARE(str, QString("he123llo" )); |
921 | checkState(redoTextChangedSpy, |
922 | canRedoChangedSpy, |
923 | undoTextChangedSpy, |
924 | redoAction, |
925 | undoAction, |
926 | canUndoChangedSpy, |
927 | cleanChangedSpy, |
928 | indexChangedSpy, |
929 | stack, |
930 | clean: false, // clean |
931 | count: 2, // count |
932 | index: 2, // index |
933 | canUndo: true, // canUndo |
934 | undoText: "insert" , // undoText |
935 | canRedo: false, // canRedo |
936 | redoText: "" , // redoText |
937 | cleanChanged: true, // cleanChanged |
938 | indexChanged: true, // indexChanged |
939 | undoChanged: true, // undoChanged |
940 | redoChanged: true); // redoChanged |
941 | |
942 | stack.setIndex(-10); // should set index to 0 |
943 | QCOMPARE(str, QString()); |
944 | checkState(redoTextChangedSpy, |
945 | canRedoChangedSpy, |
946 | undoTextChangedSpy, |
947 | redoAction, |
948 | undoAction, |
949 | canUndoChangedSpy, |
950 | cleanChangedSpy, |
951 | indexChangedSpy, |
952 | stack, |
953 | clean: true, // clean |
954 | count: 2, // count |
955 | index: 0, // index |
956 | canUndo: false, // canUndo |
957 | undoText: "" , // undoText |
958 | canRedo: true, // canRedo |
959 | redoText: "insert" , // redoText |
960 | cleanChanged: true, // cleanChanged |
961 | indexChanged: true, // indexChanged |
962 | undoChanged: true, // undoChanged |
963 | redoChanged: true); // redoChanged |
964 | |
965 | stack.setIndex(1); |
966 | QCOMPARE(str, QString("hello" )); |
967 | checkState(redoTextChangedSpy, |
968 | canRedoChangedSpy, |
969 | undoTextChangedSpy, |
970 | redoAction, |
971 | undoAction, |
972 | canUndoChangedSpy, |
973 | cleanChangedSpy, |
974 | indexChangedSpy, |
975 | stack, |
976 | clean: false, // clean |
977 | count: 2, // count |
978 | index: 1, // index |
979 | canUndo: true, // canUndo |
980 | undoText: "insert" , // undoText |
981 | canRedo: true, // canRedo |
982 | redoText: "insert" , // redoText |
983 | cleanChanged: true, // cleanChanged |
984 | indexChanged: true, // indexChanged |
985 | undoChanged: true, // undoChanged |
986 | redoChanged: true); // redoChanged |
987 | |
988 | stack.setIndex(2); |
989 | QCOMPARE(str, QString("he123llo" )); |
990 | checkState(redoTextChangedSpy, |
991 | canRedoChangedSpy, |
992 | undoTextChangedSpy, |
993 | redoAction, |
994 | undoAction, |
995 | canUndoChangedSpy, |
996 | cleanChangedSpy, |
997 | indexChangedSpy, |
998 | stack, |
999 | clean: false, // clean |
1000 | count: 2, // count |
1001 | index: 2, // index |
1002 | canUndo: true, // canUndo |
1003 | undoText: "insert" , // undoText |
1004 | canRedo: false, // canRedo |
1005 | redoText: "" , // redoText |
1006 | cleanChanged: false, // cleanChanged |
1007 | indexChanged: true, // indexChanged |
1008 | undoChanged: true, // undoChanged |
1009 | redoChanged: true); // redoChanged |
1010 | } |
1011 | |
1012 | void tst_QUndoStack::setClean() |
1013 | { |
1014 | QUndoStack stack; |
1015 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
1016 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
1017 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
1018 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
1019 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
1020 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
1021 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
1022 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
1023 | QString str; |
1024 | |
1025 | QCOMPARE(stack.cleanIndex(), 0); |
1026 | stack.setClean(); |
1027 | checkState(redoTextChangedSpy, |
1028 | canRedoChangedSpy, |
1029 | undoTextChangedSpy, |
1030 | redoAction, |
1031 | undoAction, |
1032 | canUndoChangedSpy, |
1033 | cleanChangedSpy, |
1034 | indexChangedSpy, |
1035 | stack, |
1036 | clean: true, // clean |
1037 | count: 0, // count |
1038 | index: 0, // index |
1039 | canUndo: false, // canUndo |
1040 | undoText: "" , // undoText |
1041 | canRedo: false, // canRedo |
1042 | redoText: "" , // redoText |
1043 | cleanChanged: false, // cleanChanged |
1044 | indexChanged: false, // indexChanged |
1045 | undoChanged: false, // undoChanged |
1046 | redoChanged: false); // redoChanged |
1047 | QCOMPARE(stack.cleanIndex(), 0); |
1048 | |
1049 | stack.push(cmd: new InsertCommand(&str, 0, "goodbye" )); |
1050 | checkState(redoTextChangedSpy, |
1051 | canRedoChangedSpy, |
1052 | undoTextChangedSpy, |
1053 | redoAction, |
1054 | undoAction, |
1055 | canUndoChangedSpy, |
1056 | cleanChangedSpy, |
1057 | indexChangedSpy, |
1058 | stack, |
1059 | clean: false, // clean |
1060 | count: 1, // count |
1061 | index: 1, // index |
1062 | canUndo: true, // canUndo |
1063 | undoText: "insert" , // undoText |
1064 | canRedo: false, // canRedo |
1065 | redoText: "" , // redoText |
1066 | cleanChanged: true, // cleanChanged |
1067 | indexChanged: true, // indexChanged |
1068 | undoChanged: true, // undoChanged |
1069 | redoChanged: true); // redoChanged |
1070 | QCOMPARE(stack.cleanIndex(), 0); |
1071 | |
1072 | stack.setClean(); |
1073 | QCOMPARE(str, QString("goodbye" )); |
1074 | checkState(redoTextChangedSpy, |
1075 | canRedoChangedSpy, |
1076 | undoTextChangedSpy, |
1077 | redoAction, |
1078 | undoAction, |
1079 | canUndoChangedSpy, |
1080 | cleanChangedSpy, |
1081 | indexChangedSpy, |
1082 | stack, |
1083 | clean: true, // clean |
1084 | count: 1, // count |
1085 | index: 1, // index |
1086 | canUndo: true, // canUndo |
1087 | undoText: "insert" , // undoText |
1088 | canRedo: false, // canRedo |
1089 | redoText: "" , // redoText |
1090 | cleanChanged: true, // cleanChanged |
1091 | indexChanged: false, // indexChanged |
1092 | undoChanged: false, // undoChanged |
1093 | redoChanged: false); // redoChanged |
1094 | QCOMPARE(stack.cleanIndex(), 1); |
1095 | |
1096 | stack.push(cmd: new AppendCommand(&str, " cowboy" )); |
1097 | QCOMPARE(str, QString("goodbye cowboy" )); |
1098 | checkState(redoTextChangedSpy, |
1099 | canRedoChangedSpy, |
1100 | undoTextChangedSpy, |
1101 | redoAction, |
1102 | undoAction, |
1103 | canUndoChangedSpy, |
1104 | cleanChangedSpy, |
1105 | indexChangedSpy, |
1106 | stack, |
1107 | clean: false, // clean |
1108 | count: 2, // count |
1109 | index: 2, // index |
1110 | canUndo: true, // canUndo |
1111 | undoText: "append" , // undoText |
1112 | canRedo: false, // canRedo |
1113 | redoText: "" , // redoText |
1114 | cleanChanged: true, // cleanChanged |
1115 | indexChanged: true, // indexChanged |
1116 | undoChanged: true, // undoChanged |
1117 | redoChanged: true); // redoChanged |
1118 | QCOMPARE(stack.cleanIndex(), 1); |
1119 | |
1120 | stack.undo(); // reaching clean state from above |
1121 | QCOMPARE(str, QString("goodbye" )); |
1122 | checkState(redoTextChangedSpy, |
1123 | canRedoChangedSpy, |
1124 | undoTextChangedSpy, |
1125 | redoAction, |
1126 | undoAction, |
1127 | canUndoChangedSpy, |
1128 | cleanChangedSpy, |
1129 | indexChangedSpy, |
1130 | stack, |
1131 | clean: true, // clean |
1132 | count: 2, // count |
1133 | index: 1, // index |
1134 | canUndo: true, // canUndo |
1135 | undoText: "insert" , // undoText |
1136 | canRedo: true, // canRedo |
1137 | redoText: "append" , // redoText |
1138 | cleanChanged: true, // cleanChanged |
1139 | indexChanged: true, // indexChanged |
1140 | undoChanged: true, // undoChanged |
1141 | redoChanged: true); // redoChanged |
1142 | QCOMPARE(stack.cleanIndex(), 1); |
1143 | |
1144 | stack.undo(); |
1145 | QCOMPARE(str, QString()); |
1146 | checkState(redoTextChangedSpy, |
1147 | canRedoChangedSpy, |
1148 | undoTextChangedSpy, |
1149 | redoAction, |
1150 | undoAction, |
1151 | canUndoChangedSpy, |
1152 | cleanChangedSpy, |
1153 | indexChangedSpy, |
1154 | stack, |
1155 | clean: false, // clean |
1156 | count: 2, // count |
1157 | index: 0, // index |
1158 | canUndo: false, // canUndo |
1159 | undoText: "" , // undoText |
1160 | canRedo: true, // canRedo |
1161 | redoText: "insert" , // redoText |
1162 | cleanChanged: true, // cleanChanged |
1163 | indexChanged: true, // indexChanged |
1164 | undoChanged: true, // undoChanged |
1165 | redoChanged: true); // redoChanged |
1166 | QCOMPARE(stack.cleanIndex(), 1); |
1167 | |
1168 | stack.redo(); // reaching clean state from below |
1169 | QCOMPARE(str, QString("goodbye" )); |
1170 | checkState(redoTextChangedSpy, |
1171 | canRedoChangedSpy, |
1172 | undoTextChangedSpy, |
1173 | redoAction, |
1174 | undoAction, |
1175 | canUndoChangedSpy, |
1176 | cleanChangedSpy, |
1177 | indexChangedSpy, |
1178 | stack, |
1179 | clean: true, // clean |
1180 | count: 2, // count |
1181 | index: 1, // index |
1182 | canUndo: true, // canUndo |
1183 | undoText: "insert" , // undoText |
1184 | canRedo: true, // canRedo |
1185 | redoText: "append" , // redoText |
1186 | cleanChanged: true, // cleanChanged |
1187 | indexChanged: true, // indexChanged |
1188 | undoChanged: true, // undoChanged |
1189 | redoChanged: true); // redoChanged |
1190 | QCOMPARE(stack.cleanIndex(), 1); |
1191 | |
1192 | stack.undo(); |
1193 | QCOMPARE(str, QString()); |
1194 | checkState(redoTextChangedSpy, |
1195 | canRedoChangedSpy, |
1196 | undoTextChangedSpy, |
1197 | redoAction, |
1198 | undoAction, |
1199 | canUndoChangedSpy, |
1200 | cleanChangedSpy, |
1201 | indexChangedSpy, |
1202 | stack, |
1203 | clean: false, // clean |
1204 | count: 2, // count |
1205 | index: 0, // index |
1206 | canUndo: false, // canUndo |
1207 | undoText: "" , // undoText |
1208 | canRedo: true, // canRedo |
1209 | redoText: "insert" , // redoText |
1210 | cleanChanged: true, // cleanChanged |
1211 | indexChanged: true, // indexChanged |
1212 | undoChanged: true, // undoChanged |
1213 | redoChanged: true); // redoChanged |
1214 | QCOMPARE(stack.cleanIndex(), 1); |
1215 | |
1216 | stack.push(cmd: new InsertCommand(&str, 0, "foo" )); // the clean state gets deleted! |
1217 | QCOMPARE(str, QString("foo" )); |
1218 | checkState(redoTextChangedSpy, |
1219 | canRedoChangedSpy, |
1220 | undoTextChangedSpy, |
1221 | redoAction, |
1222 | undoAction, |
1223 | canUndoChangedSpy, |
1224 | cleanChangedSpy, |
1225 | indexChangedSpy, |
1226 | stack, |
1227 | clean: false, // clean |
1228 | count: 1, // count |
1229 | index: 1, // index |
1230 | canUndo: true, // canUndo |
1231 | undoText: "insert" , // undoText |
1232 | canRedo: false, // canRedo |
1233 | redoText: "" , // redoText |
1234 | cleanChanged: false, // cleanChanged |
1235 | indexChanged: true, // indexChanged |
1236 | undoChanged: true, // undoChanged |
1237 | redoChanged: true); // redoChanged |
1238 | QCOMPARE(stack.cleanIndex(), -1); |
1239 | |
1240 | stack.undo(); |
1241 | QCOMPARE(str, QString()); |
1242 | checkState(redoTextChangedSpy, |
1243 | canRedoChangedSpy, |
1244 | undoTextChangedSpy, |
1245 | redoAction, |
1246 | undoAction, |
1247 | canUndoChangedSpy, |
1248 | cleanChangedSpy, |
1249 | indexChangedSpy, |
1250 | stack, |
1251 | clean: false, // clean |
1252 | count: 1, // count |
1253 | index: 0, // index |
1254 | canUndo: false, // canUndo |
1255 | undoText: "" , // undoText |
1256 | canRedo: true, // canRedo |
1257 | redoText: "insert" , // redoText |
1258 | cleanChanged: false, // cleanChanged |
1259 | indexChanged: true, // indexChanged |
1260 | undoChanged: true, // undoChanged |
1261 | redoChanged: true); // redoChanged |
1262 | QCOMPARE(stack.cleanIndex(), -1); |
1263 | |
1264 | stack.setClean(); |
1265 | QCOMPARE(str, QString()); |
1266 | checkState(redoTextChangedSpy, |
1267 | canRedoChangedSpy, |
1268 | undoTextChangedSpy, |
1269 | redoAction, |
1270 | undoAction, |
1271 | canUndoChangedSpy, |
1272 | cleanChangedSpy, |
1273 | indexChangedSpy, |
1274 | stack, |
1275 | clean: true, // clean |
1276 | count: 1, // count |
1277 | index: 0, // index |
1278 | canUndo: false, // canUndo |
1279 | undoText: "" , // undoText |
1280 | canRedo: true, // canRedo |
1281 | redoText: "insert" , // redoText |
1282 | cleanChanged: true, // cleanChanged |
1283 | indexChanged: false, // indexChanged |
1284 | undoChanged: false, // undoChanged |
1285 | redoChanged: false); // redoChanged |
1286 | QCOMPARE(stack.cleanIndex(), 0); |
1287 | |
1288 | stack.resetClean(); |
1289 | QCOMPARE(str, QString()); |
1290 | checkState(redoTextChangedSpy, |
1291 | canRedoChangedSpy, |
1292 | undoTextChangedSpy, |
1293 | redoAction, |
1294 | undoAction, |
1295 | canUndoChangedSpy, |
1296 | cleanChangedSpy, |
1297 | indexChangedSpy, |
1298 | stack, |
1299 | clean: false, // clean |
1300 | count: 1, // count |
1301 | index: 0, // index |
1302 | canUndo: false, // canUndo |
1303 | undoText: "" , // undoText |
1304 | canRedo: true, // canRedo |
1305 | redoText: "insert" , // redoText |
1306 | cleanChanged: true, // cleanChanged |
1307 | indexChanged: false, // indexChanged |
1308 | undoChanged: false, // undoChanged |
1309 | redoChanged: false); // redoChanged |
1310 | QCOMPARE(stack.cleanIndex(), -1); |
1311 | |
1312 | stack.redo(); |
1313 | QCOMPARE(str, QString("foo" )); |
1314 | checkState(redoTextChangedSpy, |
1315 | canRedoChangedSpy, |
1316 | undoTextChangedSpy, |
1317 | redoAction, |
1318 | undoAction, |
1319 | canUndoChangedSpy, |
1320 | cleanChangedSpy, |
1321 | indexChangedSpy, |
1322 | stack, |
1323 | clean: false, // clean |
1324 | count: 1, // count |
1325 | index: 1, // index |
1326 | canUndo: true, // canUndo |
1327 | undoText: "insert" , // undoText |
1328 | canRedo: false, // canRedo |
1329 | redoText: "" , // redoText |
1330 | cleanChanged: false, // cleanChanged |
1331 | indexChanged: true, // indexChanged |
1332 | undoChanged: true, // undoChanged |
1333 | redoChanged: true); // redoChanged |
1334 | QCOMPARE(stack.cleanIndex(), -1); |
1335 | |
1336 | stack.setClean(); |
1337 | QCOMPARE(str, QString("foo" )); |
1338 | checkState(redoTextChangedSpy, |
1339 | canRedoChangedSpy, |
1340 | undoTextChangedSpy, |
1341 | redoAction, |
1342 | undoAction, |
1343 | canUndoChangedSpy, |
1344 | cleanChangedSpy, |
1345 | indexChangedSpy, |
1346 | stack, |
1347 | clean: true, // clean |
1348 | count: 1, // count |
1349 | index: 1, // index |
1350 | canUndo: true, // canUndo |
1351 | undoText: "insert" , // undoText |
1352 | canRedo: false, // canRedo |
1353 | redoText: "" , // redoText |
1354 | cleanChanged: true, // cleanChanged |
1355 | indexChanged: false, // indexChanged |
1356 | undoChanged: false, // undoChanged |
1357 | redoChanged: false); // redoChanged |
1358 | QCOMPARE(stack.cleanIndex(), 1); |
1359 | |
1360 | stack.undo(); |
1361 | QCOMPARE(str, QString()); |
1362 | checkState(redoTextChangedSpy, |
1363 | canRedoChangedSpy, |
1364 | undoTextChangedSpy, |
1365 | redoAction, |
1366 | undoAction, |
1367 | canUndoChangedSpy, |
1368 | cleanChangedSpy, |
1369 | indexChangedSpy, |
1370 | stack, |
1371 | clean: false, // clean |
1372 | count: 1, // count |
1373 | index: 0, // index |
1374 | canUndo: false, // canUndo |
1375 | undoText: "" , // undoText |
1376 | canRedo: true, // canRedo |
1377 | redoText: "insert" , // redoText |
1378 | cleanChanged: true, // cleanChanged |
1379 | indexChanged: true, // indexChanged |
1380 | undoChanged: true, // undoChanged |
1381 | redoChanged: true); // redoChanged |
1382 | QCOMPARE(stack.cleanIndex(), 1); |
1383 | |
1384 | stack.resetClean(); |
1385 | QCOMPARE(str, QString()); |
1386 | checkState(redoTextChangedSpy, |
1387 | canRedoChangedSpy, |
1388 | undoTextChangedSpy, |
1389 | redoAction, |
1390 | undoAction, |
1391 | canUndoChangedSpy, |
1392 | cleanChangedSpy, |
1393 | indexChangedSpy, |
1394 | stack, |
1395 | clean: false, // clean |
1396 | count: 1, // count |
1397 | index: 0, // index |
1398 | canUndo: false, // canUndo |
1399 | undoText: "" , // undoText |
1400 | canRedo: true, // canRedo |
1401 | redoText: "insert" , // redoText |
1402 | cleanChanged: false, // cleanChanged |
1403 | indexChanged: false, // indexChanged |
1404 | undoChanged: false, // undoChanged |
1405 | redoChanged: false); // redoChanged |
1406 | QCOMPARE(stack.cleanIndex(), -1); |
1407 | } |
1408 | |
1409 | void tst_QUndoStack::clear() |
1410 | { |
1411 | QUndoStack stack; |
1412 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
1413 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
1414 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
1415 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
1416 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
1417 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
1418 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
1419 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
1420 | QString str; |
1421 | |
1422 | stack.clear(); |
1423 | checkState(redoTextChangedSpy, |
1424 | canRedoChangedSpy, |
1425 | undoTextChangedSpy, |
1426 | redoAction, |
1427 | undoAction, |
1428 | canUndoChangedSpy, |
1429 | cleanChangedSpy, |
1430 | indexChangedSpy, |
1431 | stack, |
1432 | clean: true, // clean |
1433 | count: 0, // count |
1434 | index: 0, // index |
1435 | canUndo: false, // canUndo |
1436 | undoText: "" , // undoText |
1437 | canRedo: false, // canRedo |
1438 | redoText: "" , // redoText |
1439 | cleanChanged: false, // cleanChanged |
1440 | indexChanged: false, // indexChanged |
1441 | undoChanged: false, // undoChanged |
1442 | redoChanged: false); // redoChanged |
1443 | |
1444 | stack.push(cmd: new InsertCommand(&str, 0, "hello" )); |
1445 | QCOMPARE(str, QString("hello" )); |
1446 | checkState(redoTextChangedSpy, |
1447 | canRedoChangedSpy, |
1448 | undoTextChangedSpy, |
1449 | redoAction, |
1450 | undoAction, |
1451 | canUndoChangedSpy, |
1452 | cleanChangedSpy, |
1453 | indexChangedSpy, |
1454 | stack, |
1455 | clean: false, // clean |
1456 | count: 1, // count |
1457 | index: 1, // index |
1458 | canUndo: true, // canUndo |
1459 | undoText: "insert" , // undoText |
1460 | canRedo: false, // canRedo |
1461 | redoText: "" , // redoText |
1462 | cleanChanged: true, // cleanChanged |
1463 | indexChanged: true, // indexChanged |
1464 | undoChanged: true, // undoChanged |
1465 | redoChanged: true); // redoChanged |
1466 | |
1467 | stack.push(cmd: new InsertCommand(&str, 2, "123" )); |
1468 | QCOMPARE(str, QString("he123llo" )); |
1469 | checkState(redoTextChangedSpy, |
1470 | canRedoChangedSpy, |
1471 | undoTextChangedSpy, |
1472 | redoAction, |
1473 | undoAction, |
1474 | canUndoChangedSpy, |
1475 | cleanChangedSpy, |
1476 | indexChangedSpy, |
1477 | stack, |
1478 | clean: false, // clean |
1479 | count: 2, // count |
1480 | index: 2, // index |
1481 | canUndo: true, // canUndo |
1482 | undoText: "insert" , // undoText |
1483 | canRedo: false, // canRedo |
1484 | redoText: "" , // redoText |
1485 | cleanChanged: false, // cleanChanged |
1486 | indexChanged: true, // indexChanged |
1487 | undoChanged: true, // undoChanged |
1488 | redoChanged: true); // redoChanged |
1489 | |
1490 | stack.clear(); |
1491 | QCOMPARE(str, QString("he123llo" )); |
1492 | checkState(redoTextChangedSpy, |
1493 | canRedoChangedSpy, |
1494 | undoTextChangedSpy, |
1495 | redoAction, |
1496 | undoAction, |
1497 | canUndoChangedSpy, |
1498 | cleanChangedSpy, |
1499 | indexChangedSpy, |
1500 | stack, |
1501 | clean: true, // clean |
1502 | count: 0, // count |
1503 | index: 0, // index |
1504 | canUndo: false, // canUndo |
1505 | undoText: "" , // undoText |
1506 | canRedo: false, // canRedo |
1507 | redoText: "" , // redoText |
1508 | cleanChanged: true, // cleanChanged |
1509 | indexChanged: true, // indexChanged |
1510 | undoChanged: true, // undoChanged |
1511 | redoChanged: true); // redoChanged |
1512 | |
1513 | str.clear(); |
1514 | stack.push(cmd: new InsertCommand(&str, 0, "hello" )); |
1515 | QCOMPARE(str, QString("hello" )); |
1516 | checkState(redoTextChangedSpy, |
1517 | canRedoChangedSpy, |
1518 | undoTextChangedSpy, |
1519 | redoAction, |
1520 | undoAction, |
1521 | canUndoChangedSpy, |
1522 | cleanChangedSpy, |
1523 | indexChangedSpy, |
1524 | stack, |
1525 | clean: false, // clean |
1526 | count: 1, // count |
1527 | index: 1, // index |
1528 | canUndo: true, // canUndo |
1529 | undoText: "insert" , // undoText |
1530 | canRedo: false, // canRedo |
1531 | redoText: "" , // redoText |
1532 | cleanChanged: true, // cleanChanged |
1533 | indexChanged: true, // indexChanged |
1534 | undoChanged: true, // undoChanged |
1535 | redoChanged: true); // redoChanged |
1536 | |
1537 | stack.push(cmd: new InsertCommand(&str, 2, "123" )); |
1538 | QCOMPARE(str, QString("he123llo" )); |
1539 | checkState(redoTextChangedSpy, |
1540 | canRedoChangedSpy, |
1541 | undoTextChangedSpy, |
1542 | redoAction, |
1543 | undoAction, |
1544 | canUndoChangedSpy, |
1545 | cleanChangedSpy, |
1546 | indexChangedSpy, |
1547 | stack, |
1548 | clean: false, // clean |
1549 | count: 2, // count |
1550 | index: 2, // index |
1551 | canUndo: true, // canUndo |
1552 | undoText: "insert" , // undoText |
1553 | canRedo: false, // canRedo |
1554 | redoText: "" , // redoText |
1555 | cleanChanged: false, // cleanChanged |
1556 | indexChanged: true, // indexChanged |
1557 | undoChanged: true, // undoChanged |
1558 | redoChanged: true); // redoChanged |
1559 | |
1560 | stack.setIndex(0); |
1561 | QCOMPARE(str, QString()); |
1562 | checkState(redoTextChangedSpy, |
1563 | canRedoChangedSpy, |
1564 | undoTextChangedSpy, |
1565 | redoAction, |
1566 | undoAction, |
1567 | canUndoChangedSpy, |
1568 | cleanChangedSpy, |
1569 | indexChangedSpy, |
1570 | stack, |
1571 | clean: true, // clean |
1572 | count: 2, // count |
1573 | index: 0, // index |
1574 | canUndo: false, // canUndo |
1575 | undoText: "" , // undoText |
1576 | canRedo: true, // canRedo |
1577 | redoText: "insert" , // redoText |
1578 | cleanChanged: true, // cleanChanged |
1579 | indexChanged: true, // indexChanged |
1580 | undoChanged: true, // undoChanged |
1581 | redoChanged: true); // redoChanged |
1582 | |
1583 | stack.clear(); |
1584 | QCOMPARE(str, QString()); |
1585 | checkState(redoTextChangedSpy, |
1586 | canRedoChangedSpy, |
1587 | undoTextChangedSpy, |
1588 | redoAction, |
1589 | undoAction, |
1590 | canUndoChangedSpy, |
1591 | cleanChangedSpy, |
1592 | indexChangedSpy, |
1593 | stack, |
1594 | clean: true, // clean |
1595 | count: 0, // count |
1596 | index: 0, // index |
1597 | canUndo: false, // canUndo |
1598 | undoText: "" , // undoText |
1599 | canRedo: false, // canRedo |
1600 | redoText: "" , // redoText |
1601 | cleanChanged: false, // cleanChanged |
1602 | indexChanged: true, // indexChanged |
1603 | undoChanged: true, // undoChanged |
1604 | redoChanged: true); // redoChanged |
1605 | } |
1606 | |
1607 | void tst_QUndoStack::childCommand() |
1608 | { |
1609 | QUndoStack stack; |
1610 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
1611 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
1612 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
1613 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
1614 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
1615 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
1616 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
1617 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
1618 | QString str; |
1619 | |
1620 | stack.push(cmd: new InsertCommand(&str, 0, "hello" )); |
1621 | QCOMPARE(str, QString("hello" )); |
1622 | checkState(redoTextChangedSpy, |
1623 | canRedoChangedSpy, |
1624 | undoTextChangedSpy, |
1625 | redoAction, |
1626 | undoAction, |
1627 | canUndoChangedSpy, |
1628 | cleanChangedSpy, |
1629 | indexChangedSpy, |
1630 | stack, |
1631 | clean: false, // clean |
1632 | count: 1, // count |
1633 | index: 1, // index |
1634 | canUndo: true, // canUndo |
1635 | undoText: "insert" , // undoText |
1636 | canRedo: false, // canRedo |
1637 | redoText: "" , // redoText |
1638 | cleanChanged: true, // cleanChanged |
1639 | indexChanged: true, // indexChanged |
1640 | undoChanged: true, // undoChanged |
1641 | redoChanged: true); // redoChanged |
1642 | |
1643 | QUndoCommand *cmd = new QUndoCommand(); |
1644 | cmd->setText("ding" ); |
1645 | new InsertCommand(&str, 5, "world" , cmd); |
1646 | new RemoveCommand(&str, 4, 1, cmd); |
1647 | stack.push(cmd); |
1648 | QCOMPARE(str, QString("hellworld" )); |
1649 | checkState(redoTextChangedSpy, |
1650 | canRedoChangedSpy, |
1651 | undoTextChangedSpy, |
1652 | redoAction, |
1653 | undoAction, |
1654 | canUndoChangedSpy, |
1655 | cleanChangedSpy, |
1656 | indexChangedSpy, |
1657 | stack, |
1658 | clean: false, // clean |
1659 | count: 2, // count |
1660 | index: 2, // index |
1661 | canUndo: true, // canUndo |
1662 | undoText: "ding" , // undoText |
1663 | canRedo: false, // canRedo |
1664 | redoText: "" , // redoText |
1665 | cleanChanged: false, // cleanChanged |
1666 | indexChanged: true, // indexChanged |
1667 | undoChanged: true, // undoChanged |
1668 | redoChanged: true); // redoChanged |
1669 | |
1670 | stack.undo(); |
1671 | QCOMPARE(str, QString("hello" )); |
1672 | checkState(redoTextChangedSpy, |
1673 | canRedoChangedSpy, |
1674 | undoTextChangedSpy, |
1675 | redoAction, |
1676 | undoAction, |
1677 | canUndoChangedSpy, |
1678 | cleanChangedSpy, |
1679 | indexChangedSpy, |
1680 | stack, |
1681 | clean: false, // clean |
1682 | count: 2, // count |
1683 | index: 1, // index |
1684 | canUndo: true, // canUndo |
1685 | undoText: "insert" , // undoText |
1686 | canRedo: true, // canRedo |
1687 | redoText: "ding" , // redoText |
1688 | cleanChanged: false, // cleanChanged |
1689 | indexChanged: true, // indexChanged |
1690 | undoChanged: true, // undoChanged |
1691 | redoChanged: true); // redoChanged |
1692 | |
1693 | stack.redo(); |
1694 | QCOMPARE(str, QString("hellworld" )); |
1695 | checkState(redoTextChangedSpy, |
1696 | canRedoChangedSpy, |
1697 | undoTextChangedSpy, |
1698 | redoAction, |
1699 | undoAction, |
1700 | canUndoChangedSpy, |
1701 | cleanChangedSpy, |
1702 | indexChangedSpy, |
1703 | stack, |
1704 | clean: false, // clean |
1705 | count: 2, // count |
1706 | index: 2, // index |
1707 | canUndo: true, // canUndo |
1708 | undoText: "ding" , // undoText |
1709 | canRedo: false, // canRedo |
1710 | redoText: "" , // redoText |
1711 | cleanChanged: false, // cleanChanged |
1712 | indexChanged: true, // indexChanged |
1713 | undoChanged: true, // undoChanged |
1714 | redoChanged: true); // redoChanged |
1715 | } |
1716 | |
1717 | void tst_QUndoStack::macroBeginEnd() |
1718 | { |
1719 | QUndoStack stack; |
1720 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
1721 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
1722 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
1723 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
1724 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
1725 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
1726 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
1727 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
1728 | QString str; |
1729 | |
1730 | stack.beginMacro(text: "ding" ); |
1731 | checkState(redoTextChangedSpy, |
1732 | canRedoChangedSpy, |
1733 | undoTextChangedSpy, |
1734 | redoAction, |
1735 | undoAction, |
1736 | canUndoChangedSpy, |
1737 | cleanChangedSpy, |
1738 | indexChangedSpy, |
1739 | stack, |
1740 | clean: false, // clean |
1741 | count: 1, // count |
1742 | index: 0, // index |
1743 | canUndo: false, // canUndo |
1744 | undoText: "" , // undoText |
1745 | canRedo: false, // canRedo |
1746 | redoText: "" , // redoText |
1747 | cleanChanged: false, // cleanChanged |
1748 | indexChanged: false, // indexChanged |
1749 | undoChanged: true, // undoChanged |
1750 | redoChanged: true); // redoChanged |
1751 | |
1752 | stack.setClean(); // should do nothing |
1753 | checkState(redoTextChangedSpy, |
1754 | canRedoChangedSpy, |
1755 | undoTextChangedSpy, |
1756 | redoAction, |
1757 | undoAction, |
1758 | canUndoChangedSpy, |
1759 | cleanChangedSpy, |
1760 | indexChangedSpy, |
1761 | stack, |
1762 | clean: false, // clean |
1763 | count: 1, // count |
1764 | index: 0, // index |
1765 | canUndo: false, // canUndo |
1766 | undoText: "" , // undoText |
1767 | canRedo: false, // canRedo |
1768 | redoText: "" , // redoText |
1769 | cleanChanged: false, // cleanChanged |
1770 | indexChanged: false, // indexChanged |
1771 | undoChanged: false, // undoChanged |
1772 | redoChanged: false); // redoChanged |
1773 | |
1774 | stack.undo(); // should do nothing |
1775 | checkState(redoTextChangedSpy, |
1776 | canRedoChangedSpy, |
1777 | undoTextChangedSpy, |
1778 | redoAction, |
1779 | undoAction, |
1780 | canUndoChangedSpy, |
1781 | cleanChangedSpy, |
1782 | indexChangedSpy, |
1783 | stack, |
1784 | clean: false, // clean |
1785 | count: 1, // count |
1786 | index: 0, // index |
1787 | canUndo: false, // canUndo |
1788 | undoText: "" , // undoText |
1789 | canRedo: false, // canRedo |
1790 | redoText: "" , // redoText |
1791 | cleanChanged: false, // cleanChanged |
1792 | indexChanged: false, // indexChanged |
1793 | undoChanged: false, // undoChanged |
1794 | redoChanged: false); // redoChanged |
1795 | |
1796 | stack.redo(); // should do nothing |
1797 | checkState(redoTextChangedSpy, |
1798 | canRedoChangedSpy, |
1799 | undoTextChangedSpy, |
1800 | redoAction, |
1801 | undoAction, |
1802 | canUndoChangedSpy, |
1803 | cleanChangedSpy, |
1804 | indexChangedSpy, |
1805 | stack, |
1806 | clean: false, // clean |
1807 | count: 1, // count |
1808 | index: 0, // index |
1809 | canUndo: false, // canUndo |
1810 | undoText: "" , // undoText |
1811 | canRedo: false, // canRedo |
1812 | redoText: "" , // redoText |
1813 | cleanChanged: false, // cleanChanged |
1814 | indexChanged: false, // indexChanged |
1815 | undoChanged: false, // undoChanged |
1816 | redoChanged: false); // redoChanged |
1817 | |
1818 | stack.setIndex(0); // should do nothing |
1819 | checkState(redoTextChangedSpy, |
1820 | canRedoChangedSpy, |
1821 | undoTextChangedSpy, |
1822 | redoAction, |
1823 | undoAction, |
1824 | canUndoChangedSpy, |
1825 | cleanChangedSpy, |
1826 | indexChangedSpy, |
1827 | stack, |
1828 | clean: false, // clean |
1829 | count: 1, // count |
1830 | index: 0, // index |
1831 | canUndo: false, // canUndo |
1832 | undoText: "" , // undoText |
1833 | canRedo: false, // canRedo |
1834 | redoText: "" , // redoText |
1835 | cleanChanged: false, // cleanChanged |
1836 | indexChanged: false, // indexChanged |
1837 | undoChanged: false, // undoChanged |
1838 | redoChanged: false); // redoChanged |
1839 | |
1840 | stack.endMacro(); |
1841 | checkState(redoTextChangedSpy, |
1842 | canRedoChangedSpy, |
1843 | undoTextChangedSpy, |
1844 | redoAction, |
1845 | undoAction, |
1846 | canUndoChangedSpy, |
1847 | cleanChangedSpy, |
1848 | indexChangedSpy, |
1849 | stack, |
1850 | clean: false, // clean |
1851 | count: 1, // count |
1852 | index: 1, // index - endMacro() increments index |
1853 | canUndo: true, // canUndo |
1854 | undoText: "ding" , // undoText |
1855 | canRedo: false, // canRedo |
1856 | redoText: "" , // redoText |
1857 | cleanChanged: true, // cleanChanged |
1858 | indexChanged: true, // indexChanged |
1859 | undoChanged: true, // undoChanged |
1860 | redoChanged: true); // redoChanged |
1861 | |
1862 | stack.push(cmd: new InsertCommand(&str, 0, "h" )); |
1863 | QCOMPARE(str, QString("h" )); |
1864 | checkState(redoTextChangedSpy, |
1865 | canRedoChangedSpy, |
1866 | undoTextChangedSpy, |
1867 | redoAction, |
1868 | undoAction, |
1869 | canUndoChangedSpy, |
1870 | cleanChangedSpy, |
1871 | indexChangedSpy, |
1872 | stack, |
1873 | clean: false, // clean |
1874 | count: 2, // count |
1875 | index: 2, // index |
1876 | canUndo: true, // canUndo |
1877 | undoText: "insert" , // undoText |
1878 | canRedo: false, // canRedo |
1879 | redoText: "" , // redoText |
1880 | cleanChanged: false, // cleanChanged |
1881 | indexChanged: true, // indexChanged |
1882 | undoChanged: true, // undoChanged |
1883 | redoChanged: true); // redoChanged |
1884 | |
1885 | stack.push(cmd: new InsertCommand(&str, 1, "owdy" )); |
1886 | QCOMPARE(str, QString("howdy" )); |
1887 | checkState(redoTextChangedSpy, |
1888 | canRedoChangedSpy, |
1889 | undoTextChangedSpy, |
1890 | redoAction, |
1891 | undoAction, |
1892 | canUndoChangedSpy, |
1893 | cleanChangedSpy, |
1894 | indexChangedSpy, |
1895 | stack, |
1896 | clean: false, // clean |
1897 | count: 3, // count |
1898 | index: 3, // index |
1899 | canUndo: true, // canUndo |
1900 | undoText: "insert" , // undoText |
1901 | canRedo: false, // canRedo |
1902 | redoText: "" , // redoText |
1903 | cleanChanged: false, // cleanChanged |
1904 | indexChanged: true, // indexChanged |
1905 | undoChanged: true, // undoChanged |
1906 | redoChanged: true); // redoChanged |
1907 | |
1908 | stack.setIndex(2); |
1909 | QCOMPARE(str, QString("h" )); |
1910 | checkState(redoTextChangedSpy, |
1911 | canRedoChangedSpy, |
1912 | undoTextChangedSpy, |
1913 | redoAction, |
1914 | undoAction, |
1915 | canUndoChangedSpy, |
1916 | cleanChangedSpy, |
1917 | indexChangedSpy, |
1918 | stack, |
1919 | clean: false, // clean |
1920 | count: 3, // count |
1921 | index: 2, // index |
1922 | canUndo: true, // canUndo |
1923 | undoText: "insert" , // undoText |
1924 | canRedo: true, // canRedo |
1925 | redoText: "insert" , // redoText |
1926 | cleanChanged: false, // cleanChanged |
1927 | indexChanged: true, // indexChanged |
1928 | undoChanged: true, // undoChanged |
1929 | redoChanged: true); // redoChanged |
1930 | |
1931 | stack.beginMacro(text: "dong" ); // the "owdy" command gets deleted |
1932 | checkState(redoTextChangedSpy, |
1933 | canRedoChangedSpy, |
1934 | undoTextChangedSpy, |
1935 | redoAction, |
1936 | undoAction, |
1937 | canUndoChangedSpy, |
1938 | cleanChangedSpy, |
1939 | indexChangedSpy, |
1940 | stack, |
1941 | clean: false, // clean |
1942 | count: 3, // count |
1943 | index: 2, // index |
1944 | canUndo: false, // canUndo |
1945 | undoText: "" , // undoText |
1946 | canRedo: false, // canRedo |
1947 | redoText: "" , // redoText |
1948 | cleanChanged: false, // cleanChanged |
1949 | indexChanged: false, // indexChanged |
1950 | undoChanged: true, // undoChanged |
1951 | redoChanged: true); // redoChanged |
1952 | |
1953 | stack.push(cmd: new InsertCommand(&str, 1, "ello" )); |
1954 | QCOMPARE(str, QString("hello" )); |
1955 | checkState(redoTextChangedSpy, |
1956 | canRedoChangedSpy, |
1957 | undoTextChangedSpy, |
1958 | redoAction, |
1959 | undoAction, |
1960 | canUndoChangedSpy, |
1961 | cleanChangedSpy, |
1962 | indexChangedSpy, |
1963 | stack, |
1964 | clean: false, // clean |
1965 | count: 3, // count |
1966 | index: 2, // index |
1967 | canUndo: false, // canUndo |
1968 | undoText: "" , // undoText |
1969 | canRedo: false, // canRedo |
1970 | redoText: "" , // redoText |
1971 | cleanChanged: false, // cleanChanged |
1972 | indexChanged: false, // indexChanged |
1973 | undoChanged: false, // undoChanged |
1974 | redoChanged: false); // redoChanged |
1975 | |
1976 | stack.push(cmd: new RemoveCommand(&str, 1, 2)); |
1977 | QCOMPARE(str, QString("hlo" )); |
1978 | checkState(redoTextChangedSpy, |
1979 | canRedoChangedSpy, |
1980 | undoTextChangedSpy, |
1981 | redoAction, |
1982 | undoAction, |
1983 | canUndoChangedSpy, |
1984 | cleanChangedSpy, |
1985 | indexChangedSpy, |
1986 | stack, |
1987 | clean: false, // clean |
1988 | count: 3, // count |
1989 | index: 2, // index |
1990 | canUndo: false, // canUndo |
1991 | undoText: "" , // undoText |
1992 | canRedo: false, // canRedo |
1993 | redoText: "" , // redoText |
1994 | cleanChanged: false, // cleanChanged |
1995 | indexChanged: false, // indexChanged |
1996 | undoChanged: false, // undoChanged |
1997 | redoChanged: false); // redoChanged |
1998 | |
1999 | stack.beginMacro(text: "dong2" ); |
2000 | QCOMPARE(str, QString("hlo" )); |
2001 | checkState(redoTextChangedSpy, |
2002 | canRedoChangedSpy, |
2003 | undoTextChangedSpy, |
2004 | redoAction, |
2005 | undoAction, |
2006 | canUndoChangedSpy, |
2007 | cleanChangedSpy, |
2008 | indexChangedSpy, |
2009 | stack, |
2010 | clean: false, // clean |
2011 | count: 3, // count |
2012 | index: 2, // index |
2013 | canUndo: false, // canUndo |
2014 | undoText: "" , // undoText |
2015 | canRedo: false, // canRedo |
2016 | redoText: "" , // redoText |
2017 | cleanChanged: false, // cleanChanged |
2018 | indexChanged: false, // indexChanged |
2019 | undoChanged: false, // undoChanged |
2020 | redoChanged: false); // redoChanged |
2021 | |
2022 | stack.push(cmd: new RemoveCommand(&str, 1, 1)); |
2023 | QCOMPARE(str, QString("ho" )); |
2024 | checkState(redoTextChangedSpy, |
2025 | canRedoChangedSpy, |
2026 | undoTextChangedSpy, |
2027 | redoAction, |
2028 | undoAction, |
2029 | canUndoChangedSpy, |
2030 | cleanChangedSpy, |
2031 | indexChangedSpy, |
2032 | stack, |
2033 | clean: false, // clean |
2034 | count: 3, // count |
2035 | index: 2, // index |
2036 | canUndo: false, // canUndo |
2037 | undoText: "" , // undoText |
2038 | canRedo: false, // canRedo |
2039 | redoText: "" , // redoText |
2040 | cleanChanged: false, // cleanChanged |
2041 | indexChanged: false, // indexChanged |
2042 | undoChanged: false, // undoChanged |
2043 | redoChanged: false); // redoChanged |
2044 | |
2045 | stack.endMacro(); |
2046 | QCOMPARE(str, QString("ho" )); |
2047 | checkState(redoTextChangedSpy, |
2048 | canRedoChangedSpy, |
2049 | undoTextChangedSpy, |
2050 | redoAction, |
2051 | undoAction, |
2052 | canUndoChangedSpy, |
2053 | cleanChangedSpy, |
2054 | indexChangedSpy, |
2055 | stack, |
2056 | clean: false, // clean |
2057 | count: 3, // count |
2058 | index: 2, // index |
2059 | canUndo: false, // canUndo |
2060 | undoText: "" , // undoText |
2061 | canRedo: false, // canRedo |
2062 | redoText: "" , // redoText |
2063 | cleanChanged: false, // cleanChanged |
2064 | indexChanged: false, // indexChanged |
2065 | undoChanged: false, // undoChanged |
2066 | redoChanged: false); // redoChanged |
2067 | |
2068 | stack.endMacro(); |
2069 | QCOMPARE(str, QString("ho" )); |
2070 | checkState(redoTextChangedSpy, |
2071 | canRedoChangedSpy, |
2072 | undoTextChangedSpy, |
2073 | redoAction, |
2074 | undoAction, |
2075 | canUndoChangedSpy, |
2076 | cleanChangedSpy, |
2077 | indexChangedSpy, |
2078 | stack, |
2079 | clean: false, // clean |
2080 | count: 3, // count |
2081 | index: 3, // index |
2082 | canUndo: true, // canUndo |
2083 | undoText: "dong" , // undoText |
2084 | canRedo: false, // canRedo |
2085 | redoText: "" , // redoText |
2086 | cleanChanged: false, // cleanChanged |
2087 | indexChanged: true, // indexChanged |
2088 | undoChanged: true, // undoChanged |
2089 | redoChanged: true); // redoChanged |
2090 | |
2091 | stack.undo(); |
2092 | QCOMPARE(str, QString("h" )); |
2093 | checkState(redoTextChangedSpy, |
2094 | canRedoChangedSpy, |
2095 | undoTextChangedSpy, |
2096 | redoAction, |
2097 | undoAction, |
2098 | canUndoChangedSpy, |
2099 | cleanChangedSpy, |
2100 | indexChangedSpy, |
2101 | stack, |
2102 | clean: false, // clean |
2103 | count: 3, // count |
2104 | index: 2, // index |
2105 | canUndo: true, // canUndo |
2106 | undoText: "insert" , // undoText |
2107 | canRedo: true, // canRedo |
2108 | redoText: "dong" , // redoText |
2109 | cleanChanged: false, // cleanChanged |
2110 | indexChanged: true, // indexChanged |
2111 | undoChanged: true, // undoChanged |
2112 | redoChanged: true); // redoChanged |
2113 | |
2114 | stack.undo(); |
2115 | QCOMPARE(str, QString("" )); |
2116 | checkState(redoTextChangedSpy, |
2117 | canRedoChangedSpy, |
2118 | undoTextChangedSpy, |
2119 | redoAction, |
2120 | undoAction, |
2121 | canUndoChangedSpy, |
2122 | cleanChangedSpy, |
2123 | indexChangedSpy, |
2124 | stack, |
2125 | clean: false, // clean |
2126 | count: 3, // count |
2127 | index: 1, // index |
2128 | canUndo: true, // canUndo |
2129 | undoText: "ding" , // undoText |
2130 | canRedo: true, // canRedo |
2131 | redoText: "insert" , // redoText |
2132 | cleanChanged: false, // cleanChanged |
2133 | indexChanged: true, // indexChanged |
2134 | undoChanged: true, // undoChanged |
2135 | redoChanged: true); // redoChanged |
2136 | |
2137 | stack.setIndex(3); |
2138 | QCOMPARE(str, QString("ho" )); |
2139 | checkState(redoTextChangedSpy, |
2140 | canRedoChangedSpy, |
2141 | undoTextChangedSpy, |
2142 | redoAction, |
2143 | undoAction, |
2144 | canUndoChangedSpy, |
2145 | cleanChangedSpy, |
2146 | indexChangedSpy, |
2147 | stack, |
2148 | clean: false, // clean |
2149 | count: 3, // count |
2150 | index: 3, // index |
2151 | canUndo: true, // canUndo |
2152 | undoText: "dong" , // undoText |
2153 | canRedo: false, // canRedo |
2154 | redoText: "" , // redoText |
2155 | cleanChanged: false, // cleanChanged |
2156 | indexChanged: true, // indexChanged |
2157 | undoChanged: true, // undoChanged |
2158 | redoChanged: true); // redoChanged |
2159 | |
2160 | stack.setIndex(1); |
2161 | QCOMPARE(str, QString()); |
2162 | checkState(redoTextChangedSpy, |
2163 | canRedoChangedSpy, |
2164 | undoTextChangedSpy, |
2165 | redoAction, |
2166 | undoAction, |
2167 | canUndoChangedSpy, |
2168 | cleanChangedSpy, |
2169 | indexChangedSpy, |
2170 | stack, |
2171 | clean: false, // clean |
2172 | count: 3, // count |
2173 | index: 1, // index |
2174 | canUndo: true, // canUndo |
2175 | undoText: "ding" , // undoText |
2176 | canRedo: true, // canRedo |
2177 | redoText: "insert" , // redoText |
2178 | cleanChanged: false, // cleanChanged |
2179 | indexChanged: true, // indexChanged |
2180 | undoChanged: true, // undoChanged |
2181 | redoChanged: true); // redoChanged |
2182 | } |
2183 | |
2184 | void tst_QUndoStack::compression() |
2185 | { |
2186 | QUndoStack stack; |
2187 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
2188 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
2189 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
2190 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
2191 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
2192 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
2193 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
2194 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
2195 | QString str; |
2196 | |
2197 | AppendCommand::delete_cnt = 0; |
2198 | |
2199 | stack.push(cmd: new InsertCommand(&str, 0, "ene" )); |
2200 | QCOMPARE(str, QString("ene" )); |
2201 | checkState(redoTextChangedSpy, |
2202 | canRedoChangedSpy, |
2203 | undoTextChangedSpy, |
2204 | redoAction, |
2205 | undoAction, |
2206 | canUndoChangedSpy, |
2207 | cleanChangedSpy, |
2208 | indexChangedSpy, |
2209 | stack, |
2210 | clean: false, // clean |
2211 | count: 1, // count |
2212 | index: 1, // index |
2213 | canUndo: true, // canUndo |
2214 | undoText: "insert" , // undoText |
2215 | canRedo: false, // canRedo |
2216 | redoText: "" , // redoText |
2217 | cleanChanged: true, // cleanChanged |
2218 | indexChanged: true, // indexChanged |
2219 | undoChanged: true, // undoChanged |
2220 | redoChanged: true); // redoChanged |
2221 | |
2222 | stack.push(cmd: new AppendCommand(&str, " due" )); // #1 |
2223 | QCOMPARE(str, QString("ene due" )); |
2224 | checkState(redoTextChangedSpy, |
2225 | canRedoChangedSpy, |
2226 | undoTextChangedSpy, |
2227 | redoAction, |
2228 | undoAction, |
2229 | canUndoChangedSpy, |
2230 | cleanChangedSpy, |
2231 | indexChangedSpy, |
2232 | stack, |
2233 | clean: false, // clean |
2234 | count: 2, // count |
2235 | index: 2, // index |
2236 | canUndo: true, // canUndo |
2237 | undoText: "append" , // undoText |
2238 | canRedo: false, // canRedo |
2239 | redoText: "" , // redoText |
2240 | cleanChanged: false, // cleanChanged |
2241 | indexChanged: true, // indexChanged |
2242 | undoChanged: true, // undoChanged |
2243 | redoChanged: true); // redoChanged |
2244 | |
2245 | stack.push(cmd: new AppendCommand(&str, " rike" )); // #2 should merge |
2246 | QCOMPARE(str, QString("ene due rike" )); |
2247 | QCOMPARE(AppendCommand::delete_cnt, 1); // #2 should be deleted |
2248 | checkState(redoTextChangedSpy, |
2249 | canRedoChangedSpy, |
2250 | undoTextChangedSpy, |
2251 | redoAction, |
2252 | undoAction, |
2253 | canUndoChangedSpy, |
2254 | cleanChangedSpy, |
2255 | indexChangedSpy, |
2256 | stack, |
2257 | clean: false, // clean |
2258 | count: 2, // count |
2259 | index: 2, // index |
2260 | canUndo: true, // canUndo |
2261 | undoText: "append" , // undoText |
2262 | canRedo: false, // canRedo |
2263 | redoText: "" , // redoText |
2264 | cleanChanged: false, // cleanChanged |
2265 | indexChanged: true, // indexChanged |
2266 | undoChanged: true, // undoChanged |
2267 | redoChanged: true); // redoChanged |
2268 | |
2269 | stack.setClean(); |
2270 | checkState(redoTextChangedSpy, |
2271 | canRedoChangedSpy, |
2272 | undoTextChangedSpy, |
2273 | redoAction, |
2274 | undoAction, |
2275 | canUndoChangedSpy, |
2276 | cleanChangedSpy, |
2277 | indexChangedSpy, |
2278 | stack, |
2279 | clean: true, // clean |
2280 | count: 2, // count |
2281 | index: 2, // index |
2282 | canUndo: true, // canUndo |
2283 | undoText: "append" , // undoText |
2284 | canRedo: false, // canRedo |
2285 | redoText: "" , // redoText |
2286 | cleanChanged: true, // cleanChanged |
2287 | indexChanged: false, // indexChanged |
2288 | undoChanged: false, // undoChanged |
2289 | redoChanged: false); // redoChanged |
2290 | |
2291 | stack.push(cmd: new AppendCommand(&str, " fake" )); // #3 should NOT merge, since the stack was clean |
2292 | QCOMPARE(str, QString("ene due rike fake" )); // and we want to be able to return to this state |
2293 | QCOMPARE(AppendCommand::delete_cnt, 1); // #3 should not be deleted |
2294 | checkState(redoTextChangedSpy, |
2295 | canRedoChangedSpy, |
2296 | undoTextChangedSpy, |
2297 | redoAction, |
2298 | undoAction, |
2299 | canUndoChangedSpy, |
2300 | cleanChangedSpy, |
2301 | indexChangedSpy, |
2302 | stack, |
2303 | clean: false, // clean |
2304 | count: 3, // count |
2305 | index: 3, // index |
2306 | canUndo: true, // canUndo |
2307 | undoText: "append" , // undoText |
2308 | canRedo: false, // canRedo |
2309 | redoText: "" , // redoText |
2310 | cleanChanged: true, // cleanChanged |
2311 | indexChanged: true, // indexChanged |
2312 | undoChanged: true, // undoChanged |
2313 | redoChanged: true); // redoChanged |
2314 | |
2315 | stack.undo(); |
2316 | QCOMPARE(str, QString("ene due rike" )); |
2317 | checkState(redoTextChangedSpy, |
2318 | canRedoChangedSpy, |
2319 | undoTextChangedSpy, |
2320 | redoAction, |
2321 | undoAction, |
2322 | canUndoChangedSpy, |
2323 | cleanChangedSpy, |
2324 | indexChangedSpy, |
2325 | stack, |
2326 | clean: true, // clean |
2327 | count: 3, // count |
2328 | index: 2, // index |
2329 | canUndo: true, // canUndo |
2330 | undoText: "append" , // undoText |
2331 | canRedo: true, // canRedo |
2332 | redoText: "append" , // redoText |
2333 | cleanChanged: true, // cleanChanged |
2334 | indexChanged: true, // indexChanged |
2335 | undoChanged: true, // undoChanged |
2336 | redoChanged: true); // redoChanged |
2337 | |
2338 | stack.undo(); |
2339 | QCOMPARE(str, QString("ene" )); |
2340 | checkState(redoTextChangedSpy, |
2341 | canRedoChangedSpy, |
2342 | undoTextChangedSpy, |
2343 | redoAction, |
2344 | undoAction, |
2345 | canUndoChangedSpy, |
2346 | cleanChangedSpy, |
2347 | indexChangedSpy, |
2348 | stack, |
2349 | clean: false, // clean |
2350 | count: 3, // count |
2351 | index: 1, // index |
2352 | canUndo: true, // canUndo |
2353 | undoText: "insert" , // undoText |
2354 | canRedo: true, // canRedo |
2355 | redoText: "append" , // redoText |
2356 | cleanChanged: true, // cleanChanged |
2357 | indexChanged: true, // indexChanged |
2358 | undoChanged: true, // undoChanged |
2359 | redoChanged: true); // redoChanged |
2360 | |
2361 | stack.push(cmd: new AppendCommand(&str, "ma" , true)); // #4 clean state gets deleted! |
2362 | QCOMPARE(str, QString("enema" )); |
2363 | QCOMPARE(AppendCommand::delete_cnt, 3); // #1 got deleted |
2364 | checkState(redoTextChangedSpy, |
2365 | canRedoChangedSpy, |
2366 | undoTextChangedSpy, |
2367 | redoAction, |
2368 | undoAction, |
2369 | canUndoChangedSpy, |
2370 | cleanChangedSpy, |
2371 | indexChangedSpy, |
2372 | stack, |
2373 | clean: false, // clean |
2374 | count: 2, // count |
2375 | index: 2, // index |
2376 | canUndo: true, // canUndo |
2377 | undoText: "append" , // undoText |
2378 | canRedo: false, // canRedo |
2379 | redoText: "" , // redoText |
2380 | cleanChanged: false, // cleanChanged |
2381 | indexChanged: true, // indexChanged |
2382 | undoChanged: true, // undoChanged |
2383 | redoChanged: true); // redoChanged |
2384 | |
2385 | stack.push(cmd: new AppendCommand(&str, "trix" )); // #5 should NOT merge |
2386 | QCOMPARE(str, QString("enematrix" )); |
2387 | QCOMPARE(AppendCommand::delete_cnt, 3); |
2388 | checkState(redoTextChangedSpy, |
2389 | canRedoChangedSpy, |
2390 | undoTextChangedSpy, |
2391 | redoAction, |
2392 | undoAction, |
2393 | canUndoChangedSpy, |
2394 | cleanChangedSpy, |
2395 | indexChangedSpy, |
2396 | stack, |
2397 | clean: false, // clean |
2398 | count: 3, // count |
2399 | index: 3, // index |
2400 | canUndo: true, // canUndo |
2401 | undoText: "append" , // undoText |
2402 | canRedo: false, // canRedo |
2403 | redoText: "" , // redoText |
2404 | cleanChanged: false, // cleanChanged |
2405 | indexChanged: true, // indexChanged |
2406 | undoChanged: true, // undoChanged |
2407 | redoChanged: true); // redoChanged |
2408 | |
2409 | stack.undo(); |
2410 | QCOMPARE(str, QString("enema" )); |
2411 | checkState(redoTextChangedSpy, |
2412 | canRedoChangedSpy, |
2413 | undoTextChangedSpy, |
2414 | redoAction, |
2415 | undoAction, |
2416 | canUndoChangedSpy, |
2417 | cleanChangedSpy, |
2418 | indexChangedSpy, |
2419 | stack, |
2420 | clean: false, // clean |
2421 | count: 3, // count |
2422 | index: 2, // index |
2423 | canUndo: true, // canUndo |
2424 | undoText: "append" , // undoText |
2425 | canRedo: true, // canRedo |
2426 | redoText: "append" , // redoText |
2427 | cleanChanged: false, // cleanChanged |
2428 | indexChanged: true, // indexChanged |
2429 | undoChanged: true, // undoChanged |
2430 | redoChanged: true); // redoChanged |
2431 | |
2432 | // and now for command compression inside macros |
2433 | |
2434 | stack.setClean(); |
2435 | QCOMPARE(str, QString("enema" )); |
2436 | checkState(redoTextChangedSpy, |
2437 | canRedoChangedSpy, |
2438 | undoTextChangedSpy, |
2439 | redoAction, |
2440 | undoAction, |
2441 | canUndoChangedSpy, |
2442 | cleanChangedSpy, |
2443 | indexChangedSpy, |
2444 | stack, |
2445 | clean: true, // clean |
2446 | count: 3, // count |
2447 | index: 2, // index |
2448 | canUndo: true, // canUndo |
2449 | undoText: "append" , // undoText |
2450 | canRedo: true, // canRedo |
2451 | redoText: "append" , // redoText |
2452 | cleanChanged: true, // cleanChanged |
2453 | indexChanged: false, // indexChanged |
2454 | undoChanged: false, // undoChanged |
2455 | redoChanged: false); // redoChanged |
2456 | |
2457 | stack.beginMacro(text: "ding" ); |
2458 | QCOMPARE(str, QString("enema" )); |
2459 | QCOMPARE(AppendCommand::delete_cnt, 4); // #5 gets deleted |
2460 | checkState(redoTextChangedSpy, |
2461 | canRedoChangedSpy, |
2462 | undoTextChangedSpy, |
2463 | redoAction, |
2464 | undoAction, |
2465 | canUndoChangedSpy, |
2466 | cleanChangedSpy, |
2467 | indexChangedSpy, |
2468 | stack, |
2469 | clean: false, // clean |
2470 | count: 3, // count |
2471 | index: 2, // index |
2472 | canUndo: false, // canUndo |
2473 | undoText: "" , // undoText |
2474 | canRedo: false, // canRedo |
2475 | redoText: "" , // redoText |
2476 | cleanChanged: false, // cleanChanged |
2477 | indexChanged: false, // indexChanged |
2478 | undoChanged: true, // undoChanged |
2479 | redoChanged: true); // redoChanged |
2480 | |
2481 | AppendCommand *merge_cmd = new AppendCommand(&str, "top" ); |
2482 | stack.push(cmd: merge_cmd); // #6 |
2483 | QCOMPARE(merge_cmd->merged, false); |
2484 | QCOMPARE(str, QString("enematop" )); |
2485 | checkState(redoTextChangedSpy, |
2486 | canRedoChangedSpy, |
2487 | undoTextChangedSpy, |
2488 | redoAction, |
2489 | undoAction, |
2490 | canUndoChangedSpy, |
2491 | cleanChangedSpy, |
2492 | indexChangedSpy, |
2493 | stack, |
2494 | clean: false, // clean |
2495 | count: 3, // count |
2496 | index: 2, // index |
2497 | canUndo: false, // canUndo |
2498 | undoText: "" , // undoText |
2499 | canRedo: false, // canRedo |
2500 | redoText: "" , // redoText |
2501 | cleanChanged: false, // cleanChanged |
2502 | indexChanged: false, // indexChanged |
2503 | undoChanged: false, // undoChanged |
2504 | redoChanged: false); // redoChanged |
2505 | |
2506 | stack.push(cmd: new AppendCommand(&str, "eja" )); // #7 should merge |
2507 | QCOMPARE(str, QString("enematopeja" )); |
2508 | QCOMPARE(merge_cmd->merged, true); |
2509 | QCOMPARE(AppendCommand::delete_cnt, 5); // #7 gets deleted |
2510 | checkState(redoTextChangedSpy, |
2511 | canRedoChangedSpy, |
2512 | undoTextChangedSpy, |
2513 | redoAction, |
2514 | undoAction, |
2515 | canUndoChangedSpy, |
2516 | cleanChangedSpy, |
2517 | indexChangedSpy, |
2518 | stack, |
2519 | clean: false, // clean |
2520 | count: 3, // count |
2521 | index: 2, // index |
2522 | canUndo: false, // canUndo |
2523 | undoText: "" , // undoText |
2524 | canRedo: false, // canRedo |
2525 | redoText: "" , // redoText |
2526 | cleanChanged: false, // cleanChanged |
2527 | indexChanged: false, // indexChanged |
2528 | undoChanged: false, // undoChanged |
2529 | redoChanged: false); // redoChanged |
2530 | merge_cmd->merged = false; |
2531 | |
2532 | stack.push(cmd: new InsertCommand(&str, 2, "123" )); // should not merge |
2533 | QCOMPARE(str, QString("en123ematopeja" )); |
2534 | QCOMPARE(merge_cmd->merged, false); |
2535 | checkState(redoTextChangedSpy, |
2536 | canRedoChangedSpy, |
2537 | undoTextChangedSpy, |
2538 | redoAction, |
2539 | undoAction, |
2540 | canUndoChangedSpy, |
2541 | cleanChangedSpy, |
2542 | indexChangedSpy, |
2543 | stack, |
2544 | clean: false, // clean |
2545 | count: 3, // count |
2546 | index: 2, // index |
2547 | canUndo: false, // canUndo |
2548 | undoText: "" , // undoText |
2549 | canRedo: false, // canRedo |
2550 | redoText: "" , // redoText |
2551 | cleanChanged: false, // cleanChanged |
2552 | indexChanged: false, // indexChanged |
2553 | undoChanged: false, // undoChanged |
2554 | redoChanged: false); // redoChanged |
2555 | |
2556 | stack.endMacro(); |
2557 | QCOMPARE(str, QString("en123ematopeja" )); |
2558 | checkState(redoTextChangedSpy, |
2559 | canRedoChangedSpy, |
2560 | undoTextChangedSpy, |
2561 | redoAction, |
2562 | undoAction, |
2563 | canUndoChangedSpy, |
2564 | cleanChangedSpy, |
2565 | indexChangedSpy, |
2566 | stack, |
2567 | clean: false, // clean |
2568 | count: 3, // count |
2569 | index: 3, // index |
2570 | canUndo: true, // canUndo |
2571 | undoText: "ding" , // undoText |
2572 | canRedo: false, // canRedo |
2573 | redoText: "" , // redoText |
2574 | cleanChanged: true, // cleanChanged |
2575 | indexChanged: true, // indexChanged |
2576 | undoChanged: true, // undoChanged |
2577 | redoChanged: true); // redoChanged |
2578 | |
2579 | stack.undo(); |
2580 | QCOMPARE(str, QString("enema" )); |
2581 | checkState(redoTextChangedSpy, |
2582 | canRedoChangedSpy, |
2583 | undoTextChangedSpy, |
2584 | redoAction, |
2585 | undoAction, |
2586 | canUndoChangedSpy, |
2587 | cleanChangedSpy, |
2588 | indexChangedSpy, |
2589 | stack, |
2590 | clean: true, // clean |
2591 | count: 3, // count |
2592 | index: 2, // index |
2593 | canUndo: true, // canUndo |
2594 | undoText: "append" , // undoText |
2595 | canRedo: true, // canRedo |
2596 | redoText: "ding" , // redoText |
2597 | cleanChanged: true, // cleanChanged |
2598 | indexChanged: true, // indexChanged |
2599 | undoChanged: true, // undoChanged |
2600 | redoChanged: true); // redoChanged |
2601 | |
2602 | stack.redo(); |
2603 | QCOMPARE(str, QString("en123ematopeja" )); |
2604 | checkState(redoTextChangedSpy, |
2605 | canRedoChangedSpy, |
2606 | undoTextChangedSpy, |
2607 | redoAction, |
2608 | undoAction, |
2609 | canUndoChangedSpy, |
2610 | cleanChangedSpy, |
2611 | indexChangedSpy, |
2612 | stack, |
2613 | clean: false, // clean |
2614 | count: 3, // count |
2615 | index: 3, // index |
2616 | canUndo: true, // canUndo |
2617 | undoText: "ding" , // undoText |
2618 | canRedo: false, // canRedo |
2619 | redoText: "" , // redoText |
2620 | cleanChanged: true, // cleanChanged |
2621 | indexChanged: true, // indexChanged |
2622 | undoChanged: true, // undoChanged |
2623 | redoChanged: true); // redoChanged |
2624 | } |
2625 | |
2626 | void tst_QUndoStack::obsolete() |
2627 | { |
2628 | QUndoStack stack; |
2629 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
2630 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
2631 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
2632 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
2633 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
2634 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
2635 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
2636 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
2637 | QPoint mouse(0, 0); |
2638 | QString str; |
2639 | MoveMouseCommand *cmd1 = 0; |
2640 | MoveMouseCommand *cmd2 = 0; |
2641 | |
2642 | stack.resetClean(); |
2643 | checkState(redoTextChangedSpy, |
2644 | canRedoChangedSpy, |
2645 | undoTextChangedSpy, |
2646 | redoAction, |
2647 | undoAction, |
2648 | canUndoChangedSpy, |
2649 | cleanChangedSpy, |
2650 | indexChangedSpy, |
2651 | stack, |
2652 | clean: false, // clean |
2653 | count: 0, // count |
2654 | index: 0, // index |
2655 | canUndo: false, // canUndo |
2656 | undoText: "" , // undoText |
2657 | canRedo: false, // canRedo |
2658 | redoText: "" , // redoText |
2659 | cleanChanged: true, // cleanChanged |
2660 | indexChanged: false, // indexChanged |
2661 | undoChanged: false, // undoChanged |
2662 | redoChanged: false); // redoChanged |
2663 | |
2664 | stack.push(cmd: new MoveMouseCommand(&mouse, mouse, QPoint(0, 0))); // #1 should not merge but will be deleted (b/c oldPoint == newPoint) |
2665 | QCOMPARE(mouse, QPoint(0, 0)); |
2666 | checkState(redoTextChangedSpy, |
2667 | canRedoChangedSpy, |
2668 | undoTextChangedSpy, |
2669 | redoAction, |
2670 | undoAction, |
2671 | canUndoChangedSpy, |
2672 | cleanChangedSpy, |
2673 | indexChangedSpy, |
2674 | stack, |
2675 | clean: false, // clean |
2676 | count: 0, // count |
2677 | index: 0, // index |
2678 | canUndo: false, // canUndo |
2679 | undoText: "" , // undoText |
2680 | canRedo: false, // canRedo |
2681 | redoText: "" , // redoText |
2682 | cleanChanged: false, // cleanChanged |
2683 | indexChanged: false, // indexChanged |
2684 | undoChanged: false, // undoChanged |
2685 | redoChanged: false); // redoChanged |
2686 | |
2687 | stack.push(cmd: new MoveMouseCommand(&mouse, mouse, QPoint(12, 0))); // #2 should not merge or be deleted (b/c oldPoint != newPoint) |
2688 | QCOMPARE(mouse, QPoint(12, 0)); |
2689 | checkState(redoTextChangedSpy, |
2690 | canRedoChangedSpy, |
2691 | undoTextChangedSpy, |
2692 | redoAction, |
2693 | undoAction, |
2694 | canUndoChangedSpy, |
2695 | cleanChangedSpy, |
2696 | indexChangedSpy, |
2697 | stack, |
2698 | clean: false, // clean |
2699 | count: 1, // count |
2700 | index: 1, // index |
2701 | canUndo: true, // canUndo |
2702 | undoText: "move mouse" , // undoText |
2703 | canRedo: false, // canRedo |
2704 | redoText: "" , // redoText |
2705 | cleanChanged: false, // cleanChanged |
2706 | indexChanged: true, // indexChanged |
2707 | undoChanged: true, // undoChanged |
2708 | redoChanged: true); // redoChanged |
2709 | |
2710 | stack.push(cmd: new MoveMouseCommand(&mouse, mouse, QPoint(8, 2))); // #3 should merge and not be deleted (b/c oldPoint != newPoint) |
2711 | QCOMPARE(mouse, QPoint(8, 2)); |
2712 | checkState(redoTextChangedSpy, |
2713 | canRedoChangedSpy, |
2714 | undoTextChangedSpy, |
2715 | redoAction, |
2716 | undoAction, |
2717 | canUndoChangedSpy, |
2718 | cleanChangedSpy, |
2719 | indexChangedSpy, |
2720 | stack, |
2721 | clean: false, // clean |
2722 | count: 1, // count |
2723 | index: 1, // index |
2724 | canUndo: true, // canUndo |
2725 | undoText: "move mouse" , // undoText |
2726 | canRedo: false, // canRedo |
2727 | redoText: "" , // redoText |
2728 | cleanChanged: false, // cleanChanged |
2729 | indexChanged: true, // indexChanged |
2730 | undoChanged: true, // undoChanged |
2731 | redoChanged: true); // redoChanged |
2732 | |
2733 | stack.push(cmd: new MoveMouseCommand(&mouse, mouse, QPoint(0, 0))); // #4 should merge and be deleted (b/c oldPoint == newPoint) |
2734 | QCOMPARE(mouse, QPoint(0, 0)); |
2735 | checkState(redoTextChangedSpy, |
2736 | canRedoChangedSpy, |
2737 | undoTextChangedSpy, |
2738 | redoAction, |
2739 | undoAction, |
2740 | canUndoChangedSpy, |
2741 | cleanChangedSpy, |
2742 | indexChangedSpy, |
2743 | stack, |
2744 | clean: false, // clean |
2745 | count: 0, // count |
2746 | index: 0, // index |
2747 | canUndo: false, // canUndo |
2748 | undoText: "" , // undoText |
2749 | canRedo: false, // canRedo |
2750 | redoText: "" , // redoText |
2751 | cleanChanged: false, // cleanChanged |
2752 | indexChanged: true, // indexChanged |
2753 | undoChanged: true, // undoChanged |
2754 | redoChanged: true); // redoChanged |
2755 | |
2756 | |
2757 | |
2758 | |
2759 | stack.push(cmd: new InsertCommand(&str, 0, "ene" )); // #5 should not merge or be deleted |
2760 | QCOMPARE(str, QString("ene" )); |
2761 | checkState(redoTextChangedSpy, |
2762 | canRedoChangedSpy, |
2763 | undoTextChangedSpy, |
2764 | redoAction, |
2765 | undoAction, |
2766 | canUndoChangedSpy, |
2767 | cleanChangedSpy, |
2768 | indexChangedSpy, |
2769 | stack, |
2770 | clean: false, // clean |
2771 | count: 1, // count |
2772 | index: 1, // index |
2773 | canUndo: true, // canUndo |
2774 | undoText: "insert" , // undoText |
2775 | canRedo: false, // canRedo |
2776 | redoText: "" , // redoText |
2777 | cleanChanged: false, // cleanChanged |
2778 | indexChanged: true, // indexChanged |
2779 | undoChanged: true, // undoChanged |
2780 | redoChanged: true); // redoChanged |
2781 | |
2782 | cmd1 = new MoveMouseCommand(&mouse, mouse, QPoint(6, 5)); |
2783 | stack.push(cmd: cmd1); // #6 should not merge or be deleted (b/c oldPoint != newPoint) |
2784 | QCOMPARE(mouse, QPoint(6, 5)); |
2785 | checkState(redoTextChangedSpy, |
2786 | canRedoChangedSpy, |
2787 | undoTextChangedSpy, |
2788 | redoAction, |
2789 | undoAction, |
2790 | canUndoChangedSpy, |
2791 | cleanChangedSpy, |
2792 | indexChangedSpy, |
2793 | stack, |
2794 | clean: false, // clean |
2795 | count: 2, // count |
2796 | index: 2, // index |
2797 | canUndo: true, // canUndo |
2798 | undoText: "move mouse" , // undoText |
2799 | canRedo: false, // canRedo |
2800 | redoText: "" , // redoText |
2801 | cleanChanged: false, // cleanChanged |
2802 | indexChanged: true, // indexChanged |
2803 | undoChanged: true, // undoChanged |
2804 | redoChanged: true); // redoChanged |
2805 | |
2806 | stack.push(cmd: new InsertCommand(&str, 3, "ma" )); // #7 should not merge or be deleted |
2807 | QCOMPARE(str, QString("enema" )); |
2808 | checkState(redoTextChangedSpy, |
2809 | canRedoChangedSpy, |
2810 | undoTextChangedSpy, |
2811 | redoAction, |
2812 | undoAction, |
2813 | canUndoChangedSpy, |
2814 | cleanChangedSpy, |
2815 | indexChangedSpy, |
2816 | stack, |
2817 | clean: false, // clean |
2818 | count: 3, // count |
2819 | index: 3, // index |
2820 | canUndo: true, // canUndo |
2821 | undoText: "insert" , // undoText |
2822 | canRedo: false, // canRedo |
2823 | redoText: "" , // redoText |
2824 | cleanChanged: false, // cleanChanged |
2825 | indexChanged: true, // indexChanged |
2826 | undoChanged: true, // undoChanged |
2827 | redoChanged: true); // redoChanged |
2828 | |
2829 | cmd2 = new MoveMouseCommand(&mouse, mouse, QPoint(12, 4)); |
2830 | stack.push(cmd: cmd2); // #8 should not merge or be deleted (b/c oldPoint != newPoint) |
2831 | QCOMPARE(mouse, QPoint(12, 4)); |
2832 | checkState(redoTextChangedSpy, |
2833 | canRedoChangedSpy, |
2834 | undoTextChangedSpy, |
2835 | redoAction, |
2836 | undoAction, |
2837 | canUndoChangedSpy, |
2838 | cleanChangedSpy, |
2839 | indexChangedSpy, |
2840 | stack, |
2841 | clean: false, // clean |
2842 | count: 4, // count |
2843 | index: 4, // index |
2844 | canUndo: true, // canUndo |
2845 | undoText: "move mouse" , // undoText |
2846 | canRedo: false, // canRedo |
2847 | redoText: "" , // redoText |
2848 | cleanChanged: false, // cleanChanged |
2849 | indexChanged: true, // indexChanged |
2850 | undoChanged: true, // undoChanged |
2851 | redoChanged: true); // redoChanged |
2852 | |
2853 | stack.setClean(); |
2854 | checkState(redoTextChangedSpy, |
2855 | canRedoChangedSpy, |
2856 | undoTextChangedSpy, |
2857 | redoAction, |
2858 | undoAction, |
2859 | canUndoChangedSpy, |
2860 | cleanChangedSpy, |
2861 | indexChangedSpy, |
2862 | stack, |
2863 | clean: true, // clean |
2864 | count: 4, // count |
2865 | index: 4, // index |
2866 | canUndo: true, // canUndo |
2867 | undoText: "move mouse" , // undoText |
2868 | canRedo: false, // canRedo |
2869 | redoText: "" , // redoText |
2870 | cleanChanged: true, // cleanChanged |
2871 | indexChanged: false, // indexChanged |
2872 | undoChanged: false, // undoChanged |
2873 | redoChanged: false); // redoChanged |
2874 | QCOMPARE(stack.cleanIndex(), 4); |
2875 | |
2876 | cmd2->setObsolete(true); |
2877 | checkState(redoTextChangedSpy, |
2878 | canRedoChangedSpy, |
2879 | undoTextChangedSpy, |
2880 | redoAction, |
2881 | undoAction, |
2882 | canUndoChangedSpy, |
2883 | cleanChangedSpy, |
2884 | indexChangedSpy, |
2885 | stack, |
2886 | clean: true, // clean |
2887 | count: 4, // count |
2888 | index: 4, // index |
2889 | canUndo: true, // canUndo |
2890 | undoText: "move mouse" , // undoText |
2891 | canRedo: false, // canRedo |
2892 | redoText: "" , // redoText |
2893 | cleanChanged: false, // cleanChanged |
2894 | indexChanged: false, // indexChanged |
2895 | undoChanged: false, // undoChanged |
2896 | redoChanged: false); // redoChanged |
2897 | |
2898 | stack.undo(); |
2899 | checkState(redoTextChangedSpy, |
2900 | canRedoChangedSpy, |
2901 | undoTextChangedSpy, |
2902 | redoAction, |
2903 | undoAction, |
2904 | canUndoChangedSpy, |
2905 | cleanChangedSpy, |
2906 | indexChangedSpy, |
2907 | stack, |
2908 | clean: false, // clean |
2909 | count: 3, // count |
2910 | index: 3, // index |
2911 | canUndo: true, // canUndo |
2912 | undoText: "insert" , // undoText |
2913 | canRedo: false, // canRedo |
2914 | redoText: "" , // redoText |
2915 | cleanChanged: true, // cleanChanged |
2916 | indexChanged: true, // indexChanged |
2917 | undoChanged: true, // undoChanged |
2918 | redoChanged: true); // redoChanged |
2919 | QCOMPARE(stack.cleanIndex(), -1); |
2920 | |
2921 | stack.undo(); |
2922 | checkState(redoTextChangedSpy, |
2923 | canRedoChangedSpy, |
2924 | undoTextChangedSpy, |
2925 | redoAction, |
2926 | undoAction, |
2927 | canUndoChangedSpy, |
2928 | cleanChangedSpy, |
2929 | indexChangedSpy, |
2930 | stack, |
2931 | clean: false, // clean |
2932 | count: 3, // count |
2933 | index: 2, // index |
2934 | canUndo: true, // canUndo |
2935 | undoText: "move mouse" , // undoText |
2936 | canRedo: true, // canRedo |
2937 | redoText: "insert" , // redoText |
2938 | cleanChanged: false, // cleanChanged |
2939 | indexChanged: true, // indexChanged |
2940 | undoChanged: true, // undoChanged |
2941 | redoChanged: true); // redoChanged |
2942 | |
2943 | stack.setClean(); |
2944 | checkState(redoTextChangedSpy, |
2945 | canRedoChangedSpy, |
2946 | undoTextChangedSpy, |
2947 | redoAction, |
2948 | undoAction, |
2949 | canUndoChangedSpy, |
2950 | cleanChangedSpy, |
2951 | indexChangedSpy, |
2952 | stack, |
2953 | clean: true, // clean |
2954 | count: 3, // count |
2955 | index: 2, // index |
2956 | canUndo: true, // canUndo |
2957 | undoText: "move mouse" , // undoText |
2958 | canRedo: true, // canRedo |
2959 | redoText: "insert" , // redoText |
2960 | cleanChanged: true, // cleanChanged |
2961 | indexChanged: false, // indexChanged |
2962 | undoChanged: false, // undoChanged |
2963 | redoChanged: false); // redoChanged |
2964 | QCOMPARE(stack.cleanIndex(), 2); |
2965 | |
2966 | stack.undo(); |
2967 | checkState(redoTextChangedSpy, |
2968 | canRedoChangedSpy, |
2969 | undoTextChangedSpy, |
2970 | redoAction, |
2971 | undoAction, |
2972 | canUndoChangedSpy, |
2973 | cleanChangedSpy, |
2974 | indexChangedSpy, |
2975 | stack, |
2976 | clean: false, // clean |
2977 | count: 3, // count |
2978 | index: 1, // index |
2979 | canUndo: true, // canUndo |
2980 | undoText: "insert" , // undoText |
2981 | canRedo: true, // canRedo |
2982 | redoText: "move mouse" , // redoText |
2983 | cleanChanged: true, // cleanChanged |
2984 | indexChanged: true, // indexChanged |
2985 | undoChanged: true, // undoChanged |
2986 | redoChanged: true); // redoChanged |
2987 | |
2988 | cmd1->setObsolete(true); |
2989 | checkState(redoTextChangedSpy, |
2990 | canRedoChangedSpy, |
2991 | undoTextChangedSpy, |
2992 | redoAction, |
2993 | undoAction, |
2994 | canUndoChangedSpy, |
2995 | cleanChangedSpy, |
2996 | indexChangedSpy, |
2997 | stack, |
2998 | clean: false, // clean |
2999 | count: 3, // count |
3000 | index: 1, // index |
3001 | canUndo: true, // canUndo |
3002 | undoText: "insert" , // undoText |
3003 | canRedo: true, // canRedo |
3004 | redoText: "move mouse" , // redoText |
3005 | cleanChanged: false, // cleanChanged |
3006 | indexChanged: false, // indexChanged |
3007 | undoChanged: false, // undoChanged |
3008 | redoChanged: false); // redoChanged |
3009 | |
3010 | stack.redo(); |
3011 | checkState(redoTextChangedSpy, |
3012 | canRedoChangedSpy, |
3013 | undoTextChangedSpy, |
3014 | redoAction, |
3015 | undoAction, |
3016 | canUndoChangedSpy, |
3017 | cleanChangedSpy, |
3018 | indexChangedSpy, |
3019 | stack, |
3020 | clean: false, // clean |
3021 | count: 2, // count |
3022 | index: 1, // index |
3023 | canUndo: true, // canUndo |
3024 | undoText: "insert" , // undoText |
3025 | canRedo: true, // canRedo |
3026 | redoText: "insert" , // redoText |
3027 | cleanChanged: false, // cleanChanged |
3028 | indexChanged: false, // indexChanged |
3029 | undoChanged: false, // undoChanged |
3030 | redoChanged: false); // redoChanged |
3031 | QCOMPARE(stack.cleanIndex(), -1); |
3032 | |
3033 | stack.redo(); |
3034 | checkState(redoTextChangedSpy, |
3035 | canRedoChangedSpy, |
3036 | undoTextChangedSpy, |
3037 | redoAction, |
3038 | undoAction, |
3039 | canUndoChangedSpy, |
3040 | cleanChangedSpy, |
3041 | indexChangedSpy, |
3042 | stack, |
3043 | clean: false, // clean |
3044 | count: 2, // count |
3045 | index: 2, // index |
3046 | canUndo: true, // canUndo |
3047 | undoText: "insert" , // undoText |
3048 | canRedo: false, // canRedo |
3049 | redoText: "" , // redoText |
3050 | cleanChanged: false, // cleanChanged |
3051 | indexChanged: true, // indexChanged |
3052 | undoChanged: true, // undoChanged |
3053 | redoChanged: true); // redoChanged |
3054 | QCOMPARE(stack.cleanIndex(), -1); |
3055 | |
3056 | cmd1 = new MoveMouseCommand(&mouse, mouse, QPoint(13, 2)); |
3057 | stack.push(cmd: cmd1); // #9 should not merge or be deleted (b/c oldPoint != newPoint) |
3058 | QCOMPARE(mouse, QPoint(13, 2)); |
3059 | checkState(redoTextChangedSpy, |
3060 | canRedoChangedSpy, |
3061 | undoTextChangedSpy, |
3062 | redoAction, |
3063 | undoAction, |
3064 | canUndoChangedSpy, |
3065 | cleanChangedSpy, |
3066 | indexChangedSpy, |
3067 | stack, |
3068 | clean: false, // clean |
3069 | count: 3, // count |
3070 | index: 3, // index |
3071 | canUndo: true, // canUndo |
3072 | undoText: "move mouse" , // undoText |
3073 | canRedo: false, // canRedo |
3074 | redoText: "" , // redoText |
3075 | cleanChanged: false, // cleanChanged |
3076 | indexChanged: true, // indexChanged |
3077 | undoChanged: true, // undoChanged |
3078 | redoChanged: true); // redoChanged |
3079 | |
3080 | stack.push(cmd: new InsertCommand(&str, 3, "ma" )); // #10 should not merge or be deleted |
3081 | QCOMPARE(str, QString("enemama" )); |
3082 | checkState(redoTextChangedSpy, |
3083 | canRedoChangedSpy, |
3084 | undoTextChangedSpy, |
3085 | redoAction, |
3086 | undoAction, |
3087 | canUndoChangedSpy, |
3088 | cleanChangedSpy, |
3089 | indexChangedSpy, |
3090 | stack, |
3091 | clean: false, // clean |
3092 | count: 4, // count |
3093 | index: 4, // index |
3094 | canUndo: true, // canUndo |
3095 | undoText: "insert" , // undoText |
3096 | canRedo: false, // canRedo |
3097 | redoText: "" , // redoText |
3098 | cleanChanged: false, // cleanChanged |
3099 | indexChanged: true, // indexChanged |
3100 | undoChanged: true, // undoChanged |
3101 | redoChanged: true); // redoChanged |
3102 | |
3103 | cmd2 = new MoveMouseCommand(&mouse, mouse, QPoint(6, 20)); |
3104 | stack.push(cmd: cmd2); // #11 should not merge or be deleted (b/c oldPoint != newPoint) |
3105 | QCOMPARE(mouse, QPoint(6, 20)); |
3106 | checkState(redoTextChangedSpy, |
3107 | canRedoChangedSpy, |
3108 | undoTextChangedSpy, |
3109 | redoAction, |
3110 | undoAction, |
3111 | canUndoChangedSpy, |
3112 | cleanChangedSpy, |
3113 | indexChangedSpy, |
3114 | stack, |
3115 | clean: false, // clean |
3116 | count: 5, // count |
3117 | index: 5, // index |
3118 | canUndo: true, // canUndo |
3119 | undoText: "move mouse" , // undoText |
3120 | canRedo: false, // canRedo |
3121 | redoText: "" , // redoText |
3122 | cleanChanged: false, // cleanChanged |
3123 | indexChanged: true, // indexChanged |
3124 | undoChanged: true, // undoChanged |
3125 | redoChanged: true); // redoChanged |
3126 | |
3127 | cmd1->setObsolete(true); |
3128 | checkState(redoTextChangedSpy, |
3129 | canRedoChangedSpy, |
3130 | undoTextChangedSpy, |
3131 | redoAction, |
3132 | undoAction, |
3133 | canUndoChangedSpy, |
3134 | cleanChangedSpy, |
3135 | indexChangedSpy, |
3136 | stack, |
3137 | clean: false, // clean |
3138 | count: 5, // count |
3139 | index: 5, // index |
3140 | canUndo: true, // canUndo |
3141 | undoText: "move mouse" , // undoText |
3142 | canRedo: false, // canRedo |
3143 | redoText: "" , // redoText |
3144 | cleanChanged: false, // cleanChanged |
3145 | indexChanged: false, // indexChanged |
3146 | undoChanged: false, // undoChanged |
3147 | redoChanged: false); // redoChanged |
3148 | |
3149 | stack.setClean(); |
3150 | checkState(redoTextChangedSpy, |
3151 | canRedoChangedSpy, |
3152 | undoTextChangedSpy, |
3153 | redoAction, |
3154 | undoAction, |
3155 | canUndoChangedSpy, |
3156 | cleanChangedSpy, |
3157 | indexChangedSpy, |
3158 | stack, |
3159 | clean: true, // clean |
3160 | count: 5, // count |
3161 | index: 5, // index |
3162 | canUndo: true, // canUndo |
3163 | undoText: "move mouse" , // undoText |
3164 | canRedo: false, // canRedo |
3165 | redoText: "" , // redoText |
3166 | cleanChanged: true, // cleanChanged |
3167 | indexChanged: false, // indexChanged |
3168 | undoChanged: false, // undoChanged |
3169 | redoChanged: false); // redoChanged |
3170 | QCOMPARE(stack.cleanIndex(), 5); |
3171 | |
3172 | stack.setIndex(0); |
3173 | checkState(redoTextChangedSpy, |
3174 | canRedoChangedSpy, |
3175 | undoTextChangedSpy, |
3176 | redoAction, |
3177 | undoAction, |
3178 | canUndoChangedSpy, |
3179 | cleanChangedSpy, |
3180 | indexChangedSpy, |
3181 | stack, |
3182 | clean: false, // clean |
3183 | count: 4, // count |
3184 | index: 0, // index |
3185 | canUndo: false, // canUndo |
3186 | undoText: "" , // undoText |
3187 | canRedo: true, // canRedo |
3188 | redoText: "insert" , // redoText |
3189 | cleanChanged: true, // cleanChanged |
3190 | indexChanged: true, // indexChanged |
3191 | undoChanged: true, // undoChanged |
3192 | redoChanged: true); // redoChanged |
3193 | QCOMPARE(stack.cleanIndex(), -1); |
3194 | |
3195 | cmd2->setObsolete(true); |
3196 | checkState(redoTextChangedSpy, |
3197 | canRedoChangedSpy, |
3198 | undoTextChangedSpy, |
3199 | redoAction, |
3200 | undoAction, |
3201 | canUndoChangedSpy, |
3202 | cleanChangedSpy, |
3203 | indexChangedSpy, |
3204 | stack, |
3205 | clean: false, // clean |
3206 | count: 4, // count |
3207 | index: 0, // index |
3208 | canUndo: false, // canUndo |
3209 | undoText: "" , // undoText |
3210 | canRedo: true, // canRedo |
3211 | redoText: "insert" , // redoText |
3212 | cleanChanged: false, // cleanChanged |
3213 | indexChanged: false, // indexChanged |
3214 | undoChanged: false, // undoChanged |
3215 | redoChanged: false); // redoChanged |
3216 | |
3217 | stack.setIndex(stack.count()); |
3218 | checkState(redoTextChangedSpy, |
3219 | canRedoChangedSpy, |
3220 | undoTextChangedSpy, |
3221 | redoAction, |
3222 | undoAction, |
3223 | canUndoChangedSpy, |
3224 | cleanChangedSpy, |
3225 | indexChangedSpy, |
3226 | stack, |
3227 | clean: false, // clean |
3228 | count: 3, // count |
3229 | index: 3, // index |
3230 | canUndo: true, // canUndo |
3231 | undoText: "insert" , // undoText |
3232 | canRedo: false, // canRedo |
3233 | redoText: "" , // redoText |
3234 | cleanChanged: false, // cleanChanged |
3235 | indexChanged: true, // indexChanged |
3236 | undoChanged: true, // undoChanged |
3237 | redoChanged: true); // redoChanged |
3238 | |
3239 | mouse = QPoint(0, 0); // Reset mouse position |
3240 | stack.beginMacro(text: "ding" ); |
3241 | checkState(redoTextChangedSpy, |
3242 | canRedoChangedSpy, |
3243 | undoTextChangedSpy, |
3244 | redoAction, |
3245 | undoAction, |
3246 | canUndoChangedSpy, |
3247 | cleanChangedSpy, |
3248 | indexChangedSpy, |
3249 | stack, |
3250 | clean: false, // clean |
3251 | count: 4, // count |
3252 | index: 3, // index |
3253 | canUndo: false, // canUndo |
3254 | undoText: "" , // undoText |
3255 | canRedo: false, // canRedo |
3256 | redoText: "" , // redoText |
3257 | cleanChanged: false, // cleanChanged |
3258 | indexChanged: false, // indexChanged |
3259 | undoChanged: true, // undoChanged |
3260 | redoChanged: true); // redoChanged |
3261 | |
3262 | stack.push(cmd: new MoveMouseCommand(&mouse, mouse, QPoint(7, 7))); // #12 should not merge or be deleted (b/c oldPoint != newPoint & in macro) |
3263 | QCOMPARE(mouse, QPoint(7, 7)); |
3264 | checkState(redoTextChangedSpy, |
3265 | canRedoChangedSpy, |
3266 | undoTextChangedSpy, |
3267 | redoAction, |
3268 | undoAction, |
3269 | canUndoChangedSpy, |
3270 | cleanChangedSpy, |
3271 | indexChangedSpy, |
3272 | stack, |
3273 | clean: false, // clean |
3274 | count: 4, // count |
3275 | index: 3, // index |
3276 | canUndo: false, // canUndo |
3277 | undoText: "" , // undoText |
3278 | canRedo: false, // canRedo |
3279 | redoText: "" , // redoText |
3280 | cleanChanged: false, // cleanChanged |
3281 | indexChanged: false, // indexChanged |
3282 | undoChanged: false, // undoChanged |
3283 | redoChanged: false); // redoChanged |
3284 | |
3285 | stack.push(cmd: new MoveMouseCommand(&mouse, mouse, QPoint(0, 0))); // #13 should merge and be deleted (b/c oldPoint = newPoint) |
3286 | QCOMPARE(mouse, QPoint(0, 0)); |
3287 | checkState(redoTextChangedSpy, |
3288 | canRedoChangedSpy, |
3289 | undoTextChangedSpy, |
3290 | redoAction, |
3291 | undoAction, |
3292 | canUndoChangedSpy, |
3293 | cleanChangedSpy, |
3294 | indexChangedSpy, |
3295 | stack, |
3296 | clean: false, // clean |
3297 | count: 4, // count |
3298 | index: 3, // index |
3299 | canUndo: false, // canUndo |
3300 | undoText: "" , // undoText |
3301 | canRedo: false, // canRedo |
3302 | redoText: "" , // redoText |
3303 | cleanChanged: false, // cleanChanged |
3304 | indexChanged: false, // indexChanged |
3305 | undoChanged: false, // undoChanged |
3306 | redoChanged: false); // redoChanged |
3307 | |
3308 | stack.endMacro(); |
3309 | checkState(redoTextChangedSpy, |
3310 | canRedoChangedSpy, |
3311 | undoTextChangedSpy, |
3312 | redoAction, |
3313 | undoAction, |
3314 | canUndoChangedSpy, |
3315 | cleanChangedSpy, |
3316 | indexChangedSpy, |
3317 | stack, |
3318 | clean: false, // clean |
3319 | count: 4, // count |
3320 | index: 4, // index |
3321 | canUndo: true, // canUndo |
3322 | undoText: "ding" , // undoText |
3323 | canRedo: false, // canRedo |
3324 | redoText: "" , // redoText |
3325 | cleanChanged: false, // cleanChanged |
3326 | indexChanged: true, // indexChanged |
3327 | undoChanged: true, // undoChanged |
3328 | redoChanged: true); // redoChanged |
3329 | } |
3330 | |
3331 | void tst_QUndoStack::undoLimit() |
3332 | { |
3333 | QUndoStack stack; |
3334 | const QScopedPointer<QAction> undoAction(stack.createUndoAction(parent: 0, prefix: QString("foo" ))); |
3335 | const QScopedPointer<QAction> redoAction(stack.createRedoAction(parent: 0, prefix: QString("bar" ))); |
3336 | QSignalSpy indexChangedSpy(&stack, &QUndoStack::indexChanged); |
3337 | QSignalSpy cleanChangedSpy(&stack, &QUndoStack::cleanChanged); |
3338 | QSignalSpy canUndoChangedSpy(&stack, &QUndoStack::canUndoChanged); |
3339 | QSignalSpy undoTextChangedSpy(&stack, &QUndoStack::undoTextChanged); |
3340 | QSignalSpy canRedoChangedSpy(&stack, &QUndoStack::canRedoChanged); |
3341 | QSignalSpy redoTextChangedSpy(&stack, &QUndoStack::redoTextChanged); |
3342 | AppendCommand::delete_cnt = 0; |
3343 | QString str; |
3344 | |
3345 | QCOMPARE(stack.undoLimit(), 0); |
3346 | stack.setUndoLimit(2); |
3347 | QCOMPARE(stack.undoLimit(), 2); |
3348 | |
3349 | stack.push(cmd: new AppendCommand(&str, "1" , true)); |
3350 | QCOMPARE(str, QString("1" )); |
3351 | QCOMPARE(AppendCommand::delete_cnt, 0); |
3352 | checkState(redoTextChangedSpy, |
3353 | canRedoChangedSpy, |
3354 | undoTextChangedSpy, |
3355 | redoAction, |
3356 | undoAction, |
3357 | canUndoChangedSpy, |
3358 | cleanChangedSpy, |
3359 | indexChangedSpy, |
3360 | stack, |
3361 | clean: false, // clean |
3362 | count: 1, // count |
3363 | index: 1, // index |
3364 | canUndo: true, // canUndo |
3365 | undoText: "append" , // undoText |
3366 | canRedo: false, // canRedo |
3367 | redoText: "" , // redoText |
3368 | cleanChanged: true, // cleanChanged |
3369 | indexChanged: true, // indexChanged |
3370 | undoChanged: true, // undoChanged |
3371 | redoChanged: true); // redoChanged |
3372 | |
3373 | stack.push(cmd: new AppendCommand(&str, "2" , true)); |
3374 | QCOMPARE(str, QString("12" )); |
3375 | QCOMPARE(AppendCommand::delete_cnt, 0); |
3376 | checkState(redoTextChangedSpy, |
3377 | canRedoChangedSpy, |
3378 | undoTextChangedSpy, |
3379 | redoAction, |
3380 | undoAction, |
3381 | canUndoChangedSpy, |
3382 | cleanChangedSpy, |
3383 | indexChangedSpy, |
3384 | stack, |
3385 | clean: false, // clean |
3386 | count: 2, // count |
3387 | index: 2, // index |
3388 | canUndo: true, // canUndo |
3389 | undoText: "append" , // undoText |
3390 | canRedo: false, // canRedo |
3391 | redoText: "" , // redoText |
3392 | cleanChanged: false, // cleanChanged |
3393 | indexChanged: true, // indexChanged |
3394 | undoChanged: true, // undoChanged |
3395 | redoChanged: true); // redoChanged |
3396 | |
3397 | stack.setClean(); |
3398 | QCOMPARE(str, QString("12" )); |
3399 | QCOMPARE(AppendCommand::delete_cnt, 0); |
3400 | checkState(redoTextChangedSpy, |
3401 | canRedoChangedSpy, |
3402 | undoTextChangedSpy, |
3403 | redoAction, |
3404 | undoAction, |
3405 | canUndoChangedSpy, |
3406 | cleanChangedSpy, |
3407 | indexChangedSpy, |
3408 | stack, |
3409 | clean: true, // clean |
3410 | count: 2, // count |
3411 | index: 2, // index |
3412 | canUndo: true, // canUndo |
3413 | undoText: "append" , // undoText |
3414 | canRedo: false, // canRedo |
3415 | redoText: "" , // redoText |
3416 | cleanChanged: true, // cleanChanged |
3417 | indexChanged: false, // indexChanged |
3418 | undoChanged: false, // undoChanged |
3419 | redoChanged: false); // redoChanged |
3420 | |
3421 | stack.push(cmd: new AppendCommand(&str, "3" , true)); |
3422 | QCOMPARE(str, QString("123" )); |
3423 | QCOMPARE(AppendCommand::delete_cnt, 1); |
3424 | checkState(redoTextChangedSpy, |
3425 | canRedoChangedSpy, |
3426 | undoTextChangedSpy, |
3427 | redoAction, |
3428 | undoAction, |
3429 | canUndoChangedSpy, |
3430 | cleanChangedSpy, |
3431 | indexChangedSpy, |
3432 | stack, |
3433 | clean: false, // clean |
3434 | count: 2, // count |
3435 | index: 2, // index |
3436 | canUndo: true, // canUndo |
3437 | undoText: "append" , // undoText |
3438 | canRedo: false, // canRedo |
3439 | redoText: "" , // redoText |
3440 | cleanChanged: true, // cleanChanged |
3441 | indexChanged: true, // indexChanged |
3442 | undoChanged: true, // undoChanged |
3443 | redoChanged: true); // redoChanged |
3444 | |
3445 | stack.push(cmd: new AppendCommand(&str, "4" , true)); |
3446 | QCOMPARE(str, QString("1234" )); |
3447 | QCOMPARE(AppendCommand::delete_cnt, 2); |
3448 | checkState(redoTextChangedSpy, |
3449 | canRedoChangedSpy, |
3450 | undoTextChangedSpy, |
3451 | redoAction, |
3452 | undoAction, |
3453 | canUndoChangedSpy, |
3454 | cleanChangedSpy, |
3455 | indexChangedSpy, |
3456 | stack, |
3457 | clean: false, // clean |
3458 | count: 2, // count |
3459 | index: 2, // index |
3460 | canUndo: true, // canUndo |
3461 | undoText: "append" , // undoText |
3462 | canRedo: false, // canRedo |
3463 | redoText: "" , // redoText |
3464 | cleanChanged: false, // cleanChanged |
3465 | indexChanged: true, // indexChanged |
3466 | undoChanged: true, // undoChanged |
3467 | redoChanged: true); // redoChanged |
3468 | |
3469 | stack.undo(); |
3470 | QCOMPARE(str, QString("123" )); |
3471 | QCOMPARE(AppendCommand::delete_cnt, 2); |
3472 | checkState(redoTextChangedSpy, |
3473 | canRedoChangedSpy, |
3474 | undoTextChangedSpy, |
3475 | redoAction, |
3476 | undoAction, |
3477 | canUndoChangedSpy, |
3478 | cleanChangedSpy, |
3479 | indexChangedSpy, |
3480 | stack, |
3481 | clean: false, // clean |
3482 | count: 2, // count |
3483 | index: 1, // index |
3484 | canUndo: true, // canUndo |
3485 | undoText: "append" , // undoText |
3486 | canRedo: true, // canRedo |
3487 | redoText: "append" , // redoText |
3488 | cleanChanged: false, // cleanChanged |
3489 | indexChanged: true, // indexChanged |
3490 | undoChanged: true, // undoChanged |
3491 | redoChanged: true); // redoChanged |
3492 | |
3493 | stack.undo(); |
3494 | QCOMPARE(str, QString("12" )); |
3495 | QCOMPARE(AppendCommand::delete_cnt, 2); |
3496 | checkState(redoTextChangedSpy, |
3497 | canRedoChangedSpy, |
3498 | undoTextChangedSpy, |
3499 | redoAction, |
3500 | undoAction, |
3501 | canUndoChangedSpy, |
3502 | cleanChangedSpy, |
3503 | indexChangedSpy, |
3504 | stack, |
3505 | clean: true, // clean |
3506 | count: 2, // count |
3507 | index: 0, // index |
3508 | canUndo: false, // canUndo |
3509 | undoText: "" , // undoText |
3510 | canRedo: true, // canRedo |
3511 | redoText: "append" , // redoText |
3512 | cleanChanged: true, // cleanChanged |
3513 | indexChanged: true, // indexChanged |
3514 | undoChanged: true, // undoChanged |
3515 | redoChanged: true); // redoChanged |
3516 | |
3517 | stack.push(cmd: new AppendCommand(&str, "3" , true)); |
3518 | QCOMPARE(str, QString("123" )); |
3519 | QCOMPARE(AppendCommand::delete_cnt, 4); |
3520 | checkState(redoTextChangedSpy, |
3521 | canRedoChangedSpy, |
3522 | undoTextChangedSpy, |
3523 | redoAction, |
3524 | undoAction, |
3525 | canUndoChangedSpy, |
3526 | cleanChangedSpy, |
3527 | indexChangedSpy, |
3528 | stack, |
3529 | clean: false, // clean |
3530 | count: 1, // count |
3531 | index: 1, // index |
3532 | canUndo: true, // canUndo |
3533 | undoText: "append" , // undoText |
3534 | canRedo: false, // canRedo |
3535 | redoText: "" , // redoText |
3536 | cleanChanged: true, // cleanChanged |
3537 | indexChanged: true, // indexChanged |
3538 | undoChanged: true, // undoChanged |
3539 | redoChanged: true); // redoChanged |
3540 | |
3541 | stack.push(cmd: new AppendCommand(&str, "4" , true)); |
3542 | QCOMPARE(str, QString("1234" )); |
3543 | QCOMPARE(AppendCommand::delete_cnt, 4); |
3544 | checkState(redoTextChangedSpy, |
3545 | canRedoChangedSpy, |
3546 | undoTextChangedSpy, |
3547 | redoAction, |
3548 | undoAction, |
3549 | canUndoChangedSpy, |
3550 | cleanChangedSpy, |
3551 | indexChangedSpy, |
3552 | stack, |
3553 | clean: false, // clean |
3554 | count: 2, // count |
3555 | index: 2, // index |
3556 | canUndo: true, // canUndo |
3557 | undoText: "append" , // undoText |
3558 | canRedo: false, // canRedo |
3559 | redoText: "" , // redoText |
3560 | cleanChanged: false, // cleanChanged |
3561 | indexChanged: true, // indexChanged |
3562 | undoChanged: true, // undoChanged |
3563 | redoChanged: true); // redoChanged |
3564 | |
3565 | stack.push(cmd: new AppendCommand(&str, "5" , true)); |
3566 | QCOMPARE(str, QString("12345" )); |
3567 | QCOMPARE(AppendCommand::delete_cnt, 5); |
3568 | checkState(redoTextChangedSpy, |
3569 | canRedoChangedSpy, |
3570 | undoTextChangedSpy, |
3571 | redoAction, |
3572 | undoAction, |
3573 | canUndoChangedSpy, |
3574 | cleanChangedSpy, |
3575 | indexChangedSpy, |
3576 | stack, |
3577 | clean: false, // clean |
3578 | count: 2, // count |
3579 | index: 2, // index |
3580 | canUndo: true, // canUndo |
3581 | undoText: "append" , // undoText |
3582 | canRedo: false, // canRedo |
3583 | redoText: "" , // redoText |
3584 | cleanChanged: false, // cleanChanged |
3585 | indexChanged: true, // indexChanged |
3586 | undoChanged: true, // undoChanged |
3587 | redoChanged: true); // redoChanged |
3588 | |
3589 | stack.undo(); |
3590 | QCOMPARE(str, QString("1234" )); |
3591 | QCOMPARE(AppendCommand::delete_cnt, 5); |
3592 | checkState(redoTextChangedSpy, |
3593 | canRedoChangedSpy, |
3594 | undoTextChangedSpy, |
3595 | redoAction, |
3596 | undoAction, |
3597 | canUndoChangedSpy, |
3598 | cleanChangedSpy, |
3599 | indexChangedSpy, |
3600 | stack, |
3601 | clean: false, // clean |
3602 | count: 2, // count |
3603 | index: 1, // index |
3604 | canUndo: true, // canUndo |
3605 | undoText: "append" , // undoText |
3606 | canRedo: true, // canRedo |
3607 | redoText: "append" , // redoText |
3608 | cleanChanged: false, // cleanChanged |
3609 | indexChanged: true, // indexChanged |
3610 | undoChanged: true, // undoChanged |
3611 | redoChanged: true); // redoChanged |
3612 | |
3613 | stack.undo(); |
3614 | QCOMPARE(str, QString("123" )); |
3615 | QCOMPARE(AppendCommand::delete_cnt, 5); |
3616 | checkState(redoTextChangedSpy, |
3617 | canRedoChangedSpy, |
3618 | undoTextChangedSpy, |
3619 | redoAction, |
3620 | undoAction, |
3621 | canUndoChangedSpy, |
3622 | cleanChangedSpy, |
3623 | indexChangedSpy, |
3624 | stack, |
3625 | clean: false, // clean |
3626 | count: 2, // count |
3627 | index: 0, // index |
3628 | canUndo: false, // canUndo |
3629 | undoText: "" , // undoText |
3630 | canRedo: true, // canRedo |
3631 | redoText: "append" , // redoText |
3632 | cleanChanged: false, // cleanChanged |
3633 | indexChanged: true, // indexChanged |
3634 | undoChanged: true, // undoChanged |
3635 | redoChanged: true); // redoChanged |
3636 | |
3637 | stack.push(cmd: new AppendCommand(&str, "4" , true)); |
3638 | QCOMPARE(str, QString("1234" )); |
3639 | QCOMPARE(AppendCommand::delete_cnt, 7); |
3640 | checkState(redoTextChangedSpy, |
3641 | canRedoChangedSpy, |
3642 | undoTextChangedSpy, |
3643 | redoAction, |
3644 | undoAction, |
3645 | canUndoChangedSpy, |
3646 | cleanChangedSpy, |
3647 | indexChangedSpy, |
3648 | stack, |
3649 | clean: false, // clean |
3650 | count: 1, // count |
3651 | index: 1, // index |
3652 | canUndo: true, // canUndo |
3653 | undoText: "append" , // undoText |
3654 | canRedo: false, // canRedo |
3655 | redoText: "" , // redoText |
3656 | cleanChanged: false, // cleanChanged |
3657 | indexChanged: true, // indexChanged |
3658 | undoChanged: true, // undoChanged |
3659 | redoChanged: true); // redoChanged |
3660 | |
3661 | stack.push(cmd: new AppendCommand(&str, "5" )); |
3662 | QCOMPARE(str, QString("12345" )); |
3663 | QCOMPARE(AppendCommand::delete_cnt, 7); |
3664 | checkState(redoTextChangedSpy, |
3665 | canRedoChangedSpy, |
3666 | undoTextChangedSpy, |
3667 | redoAction, |
3668 | undoAction, |
3669 | canUndoChangedSpy, |
3670 | cleanChangedSpy, |
3671 | indexChangedSpy, |
3672 | stack, |
3673 | clean: false, // clean |
3674 | count: 2, // count |
3675 | index: 2, // index |
3676 | canUndo: true, // canUndo |
3677 | undoText: "append" , // undoText |
3678 | canRedo: false, // canRedo |
3679 | redoText: "" , // redoText |
3680 | cleanChanged: false, // cleanChanged |
3681 | indexChanged: true, // indexChanged |
3682 | undoChanged: true, // undoChanged |
3683 | redoChanged: true); // redoChanged |
3684 | |
3685 | stack.push(cmd: new AppendCommand(&str, "6" , true)); // should be merged |
3686 | QCOMPARE(str, QString("123456" )); |
3687 | QCOMPARE(AppendCommand::delete_cnt, 8); |
3688 | checkState(redoTextChangedSpy, |
3689 | canRedoChangedSpy, |
3690 | undoTextChangedSpy, |
3691 | redoAction, |
3692 | undoAction, |
3693 | canUndoChangedSpy, |
3694 | cleanChangedSpy, |
3695 | indexChangedSpy, |
3696 | stack, |
3697 | clean: false, // clean |
3698 | count: 2, // count |
3699 | index: 2, // index |
3700 | canUndo: true, // canUndo |
3701 | undoText: "append" , // undoText |
3702 | canRedo: false, // canRedo |
3703 | redoText: "" , // redoText |
3704 | cleanChanged: false, // cleanChanged |
3705 | indexChanged: true, // indexChanged |
3706 | undoChanged: true, // undoChanged |
3707 | redoChanged: true); // redoChanged |
3708 | |
3709 | stack.beginMacro(text: "foo" ); |
3710 | QCOMPARE(str, QString("123456" )); |
3711 | QCOMPARE(AppendCommand::delete_cnt, 8); |
3712 | checkState(redoTextChangedSpy, |
3713 | canRedoChangedSpy, |
3714 | undoTextChangedSpy, |
3715 | redoAction, |
3716 | undoAction, |
3717 | canUndoChangedSpy, |
3718 | cleanChangedSpy, |
3719 | indexChangedSpy, |
3720 | stack, |
3721 | clean: false, // clean |
3722 | count: 3, // count |
3723 | index: 2, // index |
3724 | canUndo: false, // canUndo |
3725 | undoText: "" , // undoText |
3726 | canRedo: false, // canRedo |
3727 | redoText: "" , // redoText |
3728 | cleanChanged: false, // cleanChanged |
3729 | indexChanged: false, // indexChanged |
3730 | undoChanged: true, // undoChanged |
3731 | redoChanged: true); // redoChanged |
3732 | |
3733 | stack.push(cmd: new AppendCommand(&str, "7" , true)); |
3734 | QCOMPARE(str, QString("1234567" )); |
3735 | QCOMPARE(AppendCommand::delete_cnt, 8); |
3736 | checkState(redoTextChangedSpy, |
3737 | canRedoChangedSpy, |
3738 | undoTextChangedSpy, |
3739 | redoAction, |
3740 | undoAction, |
3741 | canUndoChangedSpy, |
3742 | cleanChangedSpy, |
3743 | indexChangedSpy, |
3744 | stack, |
3745 | clean: false, // clean |
3746 | count: 3, // count |
3747 | index: 2, // index |
3748 | canUndo: false, // canUndo |
3749 | undoText: "" , // undoText |
3750 | canRedo: false, // canRedo |
3751 | redoText: "" , // redoText |
3752 | cleanChanged: false, // cleanChanged |
3753 | indexChanged: false, // indexChanged |
3754 | undoChanged: false, // undoChanged |
3755 | redoChanged: false); // redoChanged |
3756 | |
3757 | stack.push(cmd: new AppendCommand(&str, "8" )); |
3758 | QCOMPARE(str, QString("12345678" )); |
3759 | QCOMPARE(AppendCommand::delete_cnt, 8); |
3760 | checkState(redoTextChangedSpy, |
3761 | canRedoChangedSpy, |
3762 | undoTextChangedSpy, |
3763 | redoAction, |
3764 | undoAction, |
3765 | canUndoChangedSpy, |
3766 | cleanChangedSpy, |
3767 | indexChangedSpy, |
3768 | stack, |
3769 | clean: false, // clean |
3770 | count: 3, // count |
3771 | index: 2, // index |
3772 | canUndo: false, // canUndo |
3773 | undoText: "" , // undoText |
3774 | canRedo: false, // canRedo |
3775 | redoText: "" , // redoText |
3776 | cleanChanged: false, // cleanChanged |
3777 | indexChanged: false, // indexChanged |
3778 | undoChanged: false, // undoChanged |
3779 | redoChanged: false); // redoChanged |
3780 | |
3781 | stack.endMacro(); |
3782 | QCOMPARE(str, QString("12345678" )); |
3783 | QCOMPARE(AppendCommand::delete_cnt, 9); |
3784 | checkState(redoTextChangedSpy, |
3785 | canRedoChangedSpy, |
3786 | undoTextChangedSpy, |
3787 | redoAction, |
3788 | undoAction, |
3789 | canUndoChangedSpy, |
3790 | cleanChangedSpy, |
3791 | indexChangedSpy, |
3792 | stack, |
3793 | clean: false, // clean |
3794 | count: 2, // count |
3795 | index: 2, // index |
3796 | canUndo: true, // canUndo |
3797 | undoText: "foo" , // undoText |
3798 | canRedo: false, // canRedo |
3799 | redoText: "" , // redoText |
3800 | cleanChanged: false, // cleanChanged |
3801 | indexChanged: true, // indexChanged |
3802 | undoChanged: true, // undoChanged |
3803 | redoChanged: true); // redoChanged |
3804 | |
3805 | stack.undo(); |
3806 | QCOMPARE(str, QString("123456" )); |
3807 | QCOMPARE(AppendCommand::delete_cnt, 9); |
3808 | checkState(redoTextChangedSpy, |
3809 | canRedoChangedSpy, |
3810 | undoTextChangedSpy, |
3811 | redoAction, |
3812 | undoAction, |
3813 | canUndoChangedSpy, |
3814 | cleanChangedSpy, |
3815 | indexChangedSpy, |
3816 | stack, |
3817 | clean: false, // clean |
3818 | count: 2, // count |
3819 | index: 1, // index |
3820 | canUndo: true, // canUndo |
3821 | undoText: "append" , // undoText |
3822 | canRedo: true, // canRedo |
3823 | redoText: "foo" , // redoText |
3824 | cleanChanged: false, // cleanChanged |
3825 | indexChanged: true, // indexChanged |
3826 | undoChanged: true, // undoChanged |
3827 | redoChanged: true); // redoChanged |
3828 | |
3829 | stack.undo(); |
3830 | QCOMPARE(str, QString("1234" )); |
3831 | QCOMPARE(AppendCommand::delete_cnt, 9); |
3832 | checkState(redoTextChangedSpy, |
3833 | canRedoChangedSpy, |
3834 | undoTextChangedSpy, |
3835 | redoAction, |
3836 | undoAction, |
3837 | canUndoChangedSpy, |
3838 | cleanChangedSpy, |
3839 | indexChangedSpy, |
3840 | stack, |
3841 | clean: false, // clean |
3842 | count: 2, // count |
3843 | index: 0, // index |
3844 | canUndo: false, // canUndo |
3845 | undoText: "" , // undoText |
3846 | canRedo: true, // canRedo |
3847 | redoText: "append" , // redoText |
3848 | cleanChanged: false, // cleanChanged |
3849 | indexChanged: true, // indexChanged |
3850 | undoChanged: true, // undoChanged |
3851 | redoChanged: true); // redoChanged |
3852 | } |
3853 | |
3854 | void tst_QUndoStack::commandTextFormat() |
3855 | { |
3856 | #if !QT_CONFIG(process) |
3857 | QSKIP("No QProcess available" ); |
3858 | #else |
3859 | QString binDir = QLibraryInfo::location(QLibraryInfo::BinariesPath); |
3860 | |
3861 | if (QProcess::execute(command: binDir + "/lrelease -version" ) != 0) |
3862 | QSKIP("lrelease is missing or broken" ); |
3863 | |
3864 | const QString tsFile = QFINDTESTDATA("testdata/qundostack.ts" ); |
3865 | QVERIFY(!tsFile.isEmpty()); |
3866 | QFile::remove(fileName: "qundostack.qm" ); // Avoid confusion by strays. |
3867 | QVERIFY(!QProcess::execute(binDir + "/lrelease -silent " + tsFile + " -qm qundostack.qm" )); |
3868 | |
3869 | QTranslator translator; |
3870 | QVERIFY(translator.load("qundostack.qm" )); |
3871 | QFile::remove(fileName: "qundostack.qm" ); |
3872 | qApp->installTranslator(messageFile: &translator); |
3873 | |
3874 | QUndoStack stack; |
3875 | const QScopedPointer<QAction> undo_action(stack.createUndoAction(parent: 0)); |
3876 | const QScopedPointer<QAction> redo_action(stack.createRedoAction(parent: 0)); |
3877 | |
3878 | QCOMPARE(undo_action->text(), QString("Undo-default-text" )); |
3879 | QCOMPARE(redo_action->text(), QString("Redo-default-text" )); |
3880 | |
3881 | QString str; |
3882 | |
3883 | stack.push(cmd: new AppendCommand(&str, "foo" )); |
3884 | QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix" )); |
3885 | QCOMPARE(redo_action->text(), QString("Redo-default-text" )); |
3886 | |
3887 | stack.push(cmd: new InsertCommand(&str, 0, "bar" )); |
3888 | stack.undo(); |
3889 | QCOMPARE(undo_action->text(), QString("undo-prefix append undo-suffix" )); |
3890 | QCOMPARE(redo_action->text(), QString("redo-prefix insert redo-suffix" )); |
3891 | |
3892 | stack.undo(); |
3893 | QCOMPARE(undo_action->text(), QString("Undo-default-text" )); |
3894 | QCOMPARE(redo_action->text(), QString("redo-prefix append redo-suffix" )); |
3895 | |
3896 | qApp->removeTranslator(messageFile: &translator); |
3897 | #endif |
3898 | } |
3899 | |
3900 | void tst_QUndoStack::separateUndoText() |
3901 | { |
3902 | QUndoStack stack; |
3903 | const QScopedPointer<QAction> undo_action(stack.createUndoAction(parent: 0)); |
3904 | const QScopedPointer<QAction> redo_action(stack.createRedoAction(parent: 0)); |
3905 | |
3906 | QUndoCommand *command1 = new IdleCommand(); |
3907 | QUndoCommand *command2 = new IdleCommand(); |
3908 | stack.push(cmd: command1); |
3909 | stack.push(cmd: command2); |
3910 | stack.undo(); |
3911 | |
3912 | QCOMPARE(undo_action->text(), QString("Undo idle-action" )); |
3913 | QCOMPARE(redo_action->text(), QString("Redo idle-action" )); |
3914 | QCOMPARE(command1->actionText(), QString("idle-action" )); |
3915 | |
3916 | QCOMPARE(command1->text(), QString("idle-item" )); |
3917 | QCOMPARE(stack.text(0), QString("idle-item" )); |
3918 | |
3919 | command1->setText("idle" ); |
3920 | QCOMPARE(command1->actionText(), QString("idle" )); |
3921 | QCOMPARE(command1->text(), QString("idle" )); |
3922 | |
3923 | command1->setText("idle-item\nidle-action" ); |
3924 | QCOMPARE(command1->actionText(), QString("idle-action" )); |
3925 | QCOMPARE(command1->text(), QString("idle-item" )); |
3926 | } |
3927 | |
3928 | QTEST_MAIN(tst_QUndoStack) |
3929 | |
3930 | #include "tst_qundostack.moc" |
3931 | |