Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
CmdStackShadow.cpp
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 "CmdStackShadow.h"
11 #include "Document.h"
12 #include "DocumentSerialize.h"
13 #include "Logger.h"
14 #include "MainWindow.h"
15 #include <QUndoCommand>
16 #include <QXmlStreamReader>
17 #include "Xml.h"
18 
20  m_mainWindow (0)
21 {
22  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::CmdStackShadow";
23 }
24 
26 {
27  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::canRedo";
28 
29  bool canRedo = (m_cmdList.count () > 0);
30 
31  return canRedo;
32 }
33 
35  Document &document,
36  QXmlStreamReader &reader)
37 {
38  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::loadCommands";
39 
40  // Save pointer to MainWindow
41  m_mainWindow = &mainWindow;
42 
43  // Load commands
44  CmdFactory factory;
45  while (!reader.atEnd() && !reader.hasError()) {
46 
47  if ((loadNextFromReader (reader) == QXmlStreamReader::StartElement) &&
48  (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
49 
50  // Extract and append new command to command stack
51  m_cmdList.push_back (factory.createCmd (mainWindow,
52  document,
53  reader));
54  }
55  }
56 }
57 
59 {
60  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotRedo";
61 
62  if (m_cmdList.count() > 0) {
63 
64  QUndoCommand *cmd = dynamic_cast<QUndoCommand*> (m_cmdList.front());
65 
66  m_cmdList.pop_front();
67 
68  if (m_mainWindow != 0) {
69  m_mainWindow->cmdMediator()->push(cmd);
70  }
71  }
72 }
73 
75 {
76  LOG4CPP_INFO_S ((*mainCat)) << "CmdStackShadow::slotUndo";
77 
78  CmdListInternal::iterator itr;
79  for (itr = m_cmdList.begin(); itr != m_cmdList.end(); itr++) {
80 
81  CmdAbstract *cmd = *itr;
82  delete cmd;
83  }
84 
85  m_cmdList.clear();
86 }
Factory for CmdAbstractBase objects.
Definition: CmdFactory.h:16
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:18
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:298
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:40
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:77
CmdAbstract * createCmd(MainWindow &mainWindow, Document &document, QXmlStreamReader &reader)
Factory method. Input is the xml node from an error report file.
Definition: CmdFactory.cpp:39