Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Cmd
CmdStackShadow.cpp
Go to the documentation of this file.
1
/******************************************************************************************************
2
* (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3
* under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4
* LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5
******************************************************************************************************/
6
7
#include "
CmdAbstract.h
"
8
#include "
CmdFactory.h
"
9
#include "
CmdMediator.h
"
10
#include "
CmdRedoForTest.h
"
11
#include "
CmdStackShadow.h
"
12
#include "
CmdUndoForTest.h
"
13
#include "
Document.h
"
14
#include "
DocumentSerialize.h
"
15
#include "
Logger.h
"
16
#include "
MainWindow.h
"
17
#include <QUndoCommand>
18
#include <QXmlStreamReader>
19
#include "
Xml.h
"
20
21
CmdStackShadow::CmdStackShadow
() :
22
m_mainWindow (nullptr)
23
{
24
qCInfo(ENGAUGE_LOG) <<
"CmdStackShadow::CmdStackShadow"
;
25
}
26
27
bool
CmdStackShadow::canRedo
()
const
28
{
29
bool
canRedo
= (m_cmdList.count () > 0);
30
31
return
canRedo
;
32
}
33
34
void
CmdStackShadow::loadCommands
(
MainWindow
&mainWindow,
35
Document
&document,
36
QXmlStreamReader &reader)
37
{
38
qCInfo(ENGAUGE_LOG) <<
"CmdStackShadow::loadCommands"
;
39
40
// Save pointer to MainWindow
41
m_mainWindow = &mainWindow;
42
43
// Signals for hack that allows script to perform redo/undo
44
connect (
this
, SIGNAL (
signalRedo
()), mainWindow.
cmdMediator
(), SLOT (redo ()));
45
connect (
this
, SIGNAL (
signalUndo
()), mainWindow.
cmdMediator
(), SLOT (undo ()));
46
47
// Load commands
48
CmdFactory
factory;
49
while
(!reader.atEnd() && !reader.hasError()) {
50
51
if
((
loadNextFromReader
(reader) == QXmlStreamReader::StartElement) &&
52
(reader.name() ==
DOCUMENT_SERIALIZE_CMD
)) {
53
54
// Extract and append new command to command stack
55
m_cmdList.push_back (factory.
createCmd
(mainWindow,
56
document,
57
reader));
58
}
59
}
60
}
61
62
void
CmdStackShadow::slotRedo
()
63
{
64
qCInfo(ENGAUGE_LOG) <<
"CmdStackShadow::slotRedo"
;
65
66
if
(m_cmdList.count() > 0) {
67
68
// Get the next command from the shadow command stack
69
QUndoCommand *cmd =
dynamic_cast<
QUndoCommand*
>
(m_cmdList.front());
70
71
// Remove this command from the shadow command stack
72
m_cmdList.pop_front();
73
74
if
(m_mainWindow !=
nullptr
) {
75
76
CmdRedoForTest
*cmdRedoForTest =
dynamic_cast<
CmdRedoForTest
*
>
(cmd);
77
CmdUndoForTest
*cmdUndoForTest =
dynamic_cast<
CmdUndoForTest
*
>
(cmd);
78
79
if
(cmdRedoForTest !=
nullptr
) {
80
81
// Redo command is a special case. Redo of this command is equivalent to redo of the last command on the command stack
82
// (which will never be CmdRedoForTest or CmdUndoForTest since they are never passed onto that command stack)
83
emit (
signalRedo
());
84
85
}
else
if
(cmdUndoForTest !=
nullptr
) {
86
87
// Undo command is a special case. Redo of this command is equivalent to undo of the last command on the command stack
88
// (which will never be CmdRedoForTest or CmdUndoForTest since they are never passed onto that command stack)
89
emit (
signalUndo
());
90
91
}
else
{
92
93
// Normal command is simply pushed onto the primary command stack
94
m_mainWindow->cmdMediator()->push(cmd);
95
96
}
97
}
98
}
99
}
100
101
void
CmdStackShadow::slotUndo
()
102
{
103
qCInfo(ENGAUGE_LOG) <<
"CmdStackShadow::slotUndo"
;
104
105
CmdListInternal::iterator itr;
106
for
(itr = m_cmdList.begin(); itr != m_cmdList.end(); itr++) {
107
108
CmdAbstract
*cmd = *itr;
109
delete
cmd;
110
}
111
112
m_cmdList.clear();
113
}
CmdAbstract.h
CmdFactory.h
CmdMediator.h
CmdRedoForTest.h
CmdStackShadow.h
CmdUndoForTest.h
DocumentSerialize.h
DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_CMD
Document.h
Logger.h
MainWindow.h
loadNextFromReader
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition
Xml.cpp:14
Xml.h
CmdAbstract
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition
CmdAbstract.h:24
CmdFactory
Factory for CmdAbstractBase objects from xml. See also GuidelineDragCommandFactory.
Definition
CmdFactory.h:17
CmdFactory::createCmd
CmdAbstract * createCmd(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Factory method. Input is the xml node from an error report file.
Definition
CmdFactory.cpp:50
CmdRedoForTest
Command for performing Redo during testing.
Definition
CmdRedoForTest.h:21
CmdStackShadow::signalRedo
void signalRedo()
Signal used to emulate a shift-control-z redo command from user during testing.
CmdStackShadow::canRedo
bool canRedo() const
Return true if there is a command available.
Definition
CmdStackShadow.cpp:27
CmdStackShadow::slotRedo
void slotRedo()
Move next command from list to CmdMediator. Noop if there are no more commands.
Definition
CmdStackShadow.cpp:62
CmdStackShadow::signalUndo
void signalUndo()
Signal used to emulate a shift-z undo command from user during testing.
CmdStackShadow::loadCommands
void loadCommands(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Load commands from serialized xml.
Definition
CmdStackShadow.cpp:34
CmdStackShadow::slotUndo
void slotUndo()
Throw away every command since trying to reconcile two different command stacks after an undo is too ...
Definition
CmdStackShadow.cpp:101
CmdStackShadow::CmdStackShadow
CmdStackShadow()
Single constructor.
Definition
CmdStackShadow.cpp:21
CmdUndoForTest
Command for performing Undo during testing.
Definition
CmdUndoForTest.h:21
Document
Storage of one imported image and the data attached to that image.
Definition
Document.h:44
MainWindow
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition
MainWindow.h:95
MainWindow::cmdMediator
CmdMediator * cmdMediator()
Accessor for commands to process the Document.
Definition
MainWindow.cpp:368
Generated on
for Engauge Digitizer by
1.17.0