Engauge Digitizer  2
CmdStackShadow.cpp
1 #include "CmdAbstract.h"
2 #include "CmdFactory.h"
3 #include "CmdMediator.h"
4 #include "CmdStackShadow.h"
5 #include "Document.h"
6 #include "DocumentSerialize.h"
7 #include "Logger.h"
8 #include "MainWindow.h"
9 #include <QUndoCommand>
10 #include <QXmlStreamReader>
11 #include "Xml.h"
12 
14  m_mainWindow (0)
15 {
16  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::CmdStackShadow";
17 }
18 
20 {
21  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::canRedo";
22 
23  bool canRedo = (m_cmdList.count () > 0);
24 
25  return canRedo;
26 }
27 
29  Document &document,
30  QXmlStreamReader &reader)
31 {
32  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::loadCommands";
33 
34  // Save pointer to MainWindow
35  m_mainWindow = &mainWindow;
36 
37  // Load commands
38  CmdFactory factory;
39  while (!reader.atEnd() && !reader.hasError()) {
40 
41  if ((loadNextFromReader (reader) == QXmlStreamReader::StartElement) &&
42  (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
43 
44  // Extract and append new command to command stack
45  m_cmdList.push_back (factory.createCmd (mainWindow,
46  document,
47  reader));
48  }
49  }
50 }
51 
53 {
54  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotRedo";
55 
56  if (m_cmdList.count() > 0) {
57 
58  QUndoCommand *cmd = dynamic_cast<QUndoCommand*> (m_cmdList.front());
59 
60  m_cmdList.pop_front();
61 
62  if (m_mainWindow != 0) {
63  m_mainWindow->cmdMediator().push(cmd);
64  }
65  }
66 }
67 
69 {
70  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotUndo";
71 
72  CmdListInternal::iterator itr;
73  for (itr = m_cmdList.begin(); itr != m_cmdList.end(); itr++) {
74 
75  CmdAbstract *cmd = *itr;
76  delete cmd;
77  }
78 
79  m_cmdList.clear();
80 }
Factory for CmdAbstractBase objects.
Definition: CmdFactory.h:10
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:11
void slotRedo()
Move next command from list to CmdMediator. Noop if there are no more commands.
CmdMediator & cmdMediator()
Accessor for commands to process the Document.
Definition: MainWindow.cpp:176
CmdStackShadow()
Single constructor.
bool canRedo() const
Return true if there is a command available.
void slotUndo()
Throw away every command since trying to reconcile two different command stacks after an undo is too ...
Storage of one imported image and the data attached to that image.
Definition: Document.h:28
void loadCommands(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Load commands from serialized xml.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:60
CmdAbstract * createCmd(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Factory method. Input is the xml node from an error report file.
Definition: CmdFactory.cpp:31