Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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. More...
 
void slotUndo ()
 Throw away every command since trying to reconcile two different command stacks after an undo is too dangerous. More...
 

Signals

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

Public Member Functions

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

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 ( )

Single constructor.

Definition at line 21 of file CmdStackShadow.cpp.

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

Member Function Documentation

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 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
bool canRedo() const
Return true if there is a command available.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
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
50  CmdFactory factory;
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 }
Factory for CmdAbstractBase objects.
Definition: CmdFactory.h:16
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition: Xml.cpp:14
void signalRedo()
Signal used to emulate a shift-control-z redo command from user during testing.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
CmdMediator * cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:350
void signalUndo()
Signal used to emulate a shift-z undo command from user during testing.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString DOCUMENT_SERIALIZE_CMD
void CmdStackShadow::signalRedo ( )
signal

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

void CmdStackShadow::signalUndo ( )
signal

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

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 
78  CmdRedoForTest *cmdRedoForTest = dynamic_cast<CmdRedoForTest*> (cmd);
79  CmdUndoForTest *cmdUndoForTest = dynamic_cast<CmdUndoForTest*> (cmd);
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 }
void signalRedo()
Signal used to emulate a shift-control-z redo command from user during testing.
Command for performing Undo during testing.
Command for performing Redo during testing.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
CmdMediator * cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:350
void signalUndo()
Signal used to emulate a shift-z undo command from user during testing.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
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:19
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
log4cpp::Category * mainCat
Definition: Logger.cpp:14

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