Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdStackShadow Class Reference

Command stack that shadows the CmdMediator command stack at startup when reading commands from an error report file. More...

#include <CmdStackShadow.h>

Inheritance diagram for CmdStackShadow:
Inheritance graph
Collaboration diagram for CmdStackShadow:
Collaboration graph

Public Slots

void slotRedo ()
 Move next command from list to CmdMediator. Noop if there are no more commands.
void slotUndo ()
 Throw away every command since trying to reconcile two different command stacks after an undo is too dangerous.

Signals

void signalRedo ()
 Signal used to emulate a shift-control-z redo command from user during testing.
void signalUndo ()
 Signal used to emulate a shift-z undo command from user during testing.

Public Member Functions

 CmdStackShadow ()
 Single constructor.
bool canRedo () const
 Return true if there is a command available.
void loadCommands (MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
 Load commands from serialized xml.

Detailed Description

Command stack that shadows the CmdMediator command stack at startup when reading commands from an error report file.

The commands are loaded into this container rather than CmdMediator, since CmdMediator would try to execute all the commands immediately. For the best debugging, we want to be able to execute each command one by one. This container nicely stores commands until we want to copy them to CmdMediator so they can be executed.

This class is not subclassed from QUndoStack since that class is designed to prevent access to individual commands, to preserve their integrity

This class is not named CmdMediatorShadow since does not maintain a Document like CmdMediator, although in some ways that name might be a useful alias

Definition at line 31 of file CmdStackShadow.h.

Constructor & Destructor Documentation

◆ CmdStackShadow()

CmdStackShadow::CmdStackShadow ( )

Single constructor.

Definition at line 21 of file CmdStackShadow.cpp.

21 :
22 m_mainWindow (nullptr)
23{
24 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::CmdStackShadow";
25}
log4cpp::Category * mainCat
Definition Logger.cpp:14
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

Member Function Documentation

◆ canRedo()

bool CmdStackShadow::canRedo ( ) const

Return true if there is a command available.

Definition at line 27 of file CmdStackShadow.cpp.

28{
29 bool canRedo = (m_cmdList.count () > 0);
30
31 return canRedo;
32}
bool canRedo() const
Return true if there is a command available.

◆ loadCommands()

void CmdStackShadow::loadCommands ( MainWindow & mainWindow,
Document & document,
QXmlStreamReader & reader )

Load commands from serialized xml.

Definition at line 34 of file CmdStackShadow.cpp.

37{
38 LOG4CPP_INFO_S ((*mainCat)) << "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}
const QString DOCUMENT_SERIALIZE_CMD
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
CmdAbstract * createCmd(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Factory method. Input is the xml node from an error report file.
void signalRedo()
Signal used to emulate a shift-control-z redo command from user during testing.
void signalUndo()
Signal used to emulate a shift-z undo command from user during testing.
CmdMediator * cmdMediator()
Accessor for commands to process the Document.

◆ signalRedo

void CmdStackShadow::signalRedo ( )
signal

Signal used to emulate a shift-control-z redo command from user during testing.

◆ signalUndo

void CmdStackShadow::signalUndo ( )
signal

Signal used to emulate a shift-z undo command from user during testing.

◆ slotRedo

void CmdStackShadow::slotRedo ( )
slot

Move next command from list to CmdMediator. Noop if there are no more commands.

Definition at line 62 of file CmdStackShadow.cpp.

63{
64 LOG4CPP_INFO_S ((*mainCat)) << "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}

◆ slotUndo

void CmdStackShadow::slotUndo ( )
slot

Throw away every command since trying to reconcile two different command stacks after an undo is too dangerous.

Definition at line 101 of file CmdStackShadow.cpp.

102{
103 LOG4CPP_INFO_S ((*mainCat)) << "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}

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