Engauge Digitizer  2
CmdAbstract.cpp
1 #include "CmdAbstract.h"
2 #include "Document.h"
3 #include "Logger.h"
4 #include "MainWindow.h"
5 #include "Point.h"
6 
8  Document &document,
9  const QString &cmdDescription) :
10  QUndoCommand (cmdDescription),
11  m_mainWindow (mainWindow),
12  m_document (document),
13  m_isFirstRedo (true)
14 {
15  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::CmdAbstract";
16 }
17 
18 CmdAbstract::~CmdAbstract()
19 {
20 }
21 
23 {
24  return m_document;
25 }
26 
28 {
29  return m_document;
30 }
31 
33 {
34  return m_mainWindow;
35 }
36 
37 void CmdAbstract::redo ()
38 {
39  // Note that m_identifierIndexBeforeRedo and m_identifierIndexAfterRedo are not set until below (at which point they are logged)
40  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::redo";
41 
42  if (m_isFirstRedo) {
43 
44  m_identifierIndexBeforeRedo = Point::identifierIndex ();
45 
46  } else {
47 
48  // Reset state. The first time this is called, this is a noop since m_identifierIndex was just set to
49  // GraphicsPointAbstractBase::identifierIndex in the constructor of this class
50  Point::setIdentifierIndex (m_identifierIndexBeforeRedo);
51 
52  }
53 
54  // Invoke the leaf class redo method
55  cmdRedo ();
56 
57  if (m_isFirstRedo) {
58 
59  m_isFirstRedo = false;
60  m_identifierIndexAfterRedo = Point::identifierIndex();
61 
62  }
63 
64  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::redo identifierIndex=" << m_identifierIndexBeforeRedo << "->"
65  << m_identifierIndexAfterRedo;
66 }
67 
68 void CmdAbstract::undo ()
69 {
70  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::undo identifierIndex=" << m_identifierIndexAfterRedo << "->"
71  << m_identifierIndexBeforeRedo;
72 
73  Point::setIdentifierIndex (m_identifierIndexAfterRedo);
74 
75  // Invoke the leaf class undo method
76  cmdUndo ();
77 
78  Point::setIdentifierIndex (m_identifierIndexBeforeRedo);
79 }
static void setIdentifierIndex(unsigned int identifierIndex)
Reset the current index while performing a Redo.
Definition: Point.cpp:401
static unsigned int identifierIndex()
Return the current index for storage in case we need to reset it later while performing a Redo...
Definition: Point.cpp:223
virtual void cmdRedo()=0
Redo method that is called when QUndoStack is moved one command forward.
CmdAbstract(MainWindow &mainWindow, Document &document, const QString &cmdDescription)
Single constructor.
Definition: CmdAbstract.cpp:7
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:32
Storage of one imported image and the data attached to that image.
Definition: Document.h:28
virtual void cmdUndo()=0
Undo method that is called when QUndoStack is moved one command backward.
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:22
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:60