Engauge Digitizer 2
Loading...
Searching...
No Matches
Public Slots | Signals | Public Member Functions | List of all members
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 30 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 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::canRedo";
30
31 bool canRedo = (m_cmdList.count () > 0);
32
33 return canRedo;
34}
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 36 of file CmdStackShadow.cpp.

39{
40 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::loadCommands";
41
42 // Save pointer to MainWindow
43 m_mainWindow = &mainWindow;
44
45 // Signals for hack that allows script to perform redo/undo
46 connect (this, SIGNAL (signalRedo ()), mainWindow.cmdMediator(), SLOT (redo ()));
47 connect (this, SIGNAL (signalUndo ()), mainWindow.cmdMediator(), SLOT (undo ()));
48
49 // Load commands
51 while (!reader.atEnd() && !reader.hasError()) {
52
53 if ((loadNextFromReader (reader) == QXmlStreamReader::StartElement) &&
54 (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
55
56 // Extract and append new command to command stack
57 m_cmdList.push_back (factory.createCmd (mainWindow,
58 document,
59 reader));
60 }
61 }
62}
const int INNER_RADIUS_MIN
const QString DOCUMENT_SERIALIZE_CMD
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
Factory for CmdAbstractBase objects.
Definition CmdFactory.h:17
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 64 of file CmdStackShadow.cpp.

65{
66 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotRedo";
67
68 if (m_cmdList.count() > 0) {
69
70 // Get the next command from the shadow command stack
71 QUndoCommand *cmd = dynamic_cast<QUndoCommand*> (m_cmdList.front());
72
73 // Remove this command from the shadow command stack
74 m_cmdList.pop_front();
75
76 if (m_mainWindow != nullptr) {
77
80
81 if (cmdRedoForTest != nullptr) {
82
83 // Redo command is a special case. Redo of this command is equivalent to redo of the last command on the command stack
84 // (which will never be CmdRedoForTest or CmdUndoForTest since they are never passed onto that command stack)
85 emit (signalRedo ());
86
87 } else if (cmdUndoForTest != nullptr) {
88
89 // Undo command is a special case. Redo of this command is equivalent to undo of the last command on the command stack
90 // (which will never be CmdRedoForTest or CmdUndoForTest since they are never passed onto that command stack)
91 emit (signalUndo ());
92
93 } else {
94
95 // Normal command is simply pushed onto the primary command stack
96 m_mainWindow->cmdMediator()->push(cmd);
97
98 }
99 }
100 }
101}
Command for performing Redo during testing.
Command for performing Undo during testing.

◆ 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 103 of file CmdStackShadow.cpp.

104{
105 LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotUndo";
106
107 CmdListInternal::iterator itr;
108 for (itr = m_cmdList.begin(); itr != m_cmdList.end(); itr++) {
109
110 CmdAbstract *cmd = *itr;
111 delete cmd;
112 }
113
114 m_cmdList.clear();
115}
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:20

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