Engauge Digitizer  2
CmdAbstract.h
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 #ifndef CMD_ABSTRACT_H
8 #define CMD_ABSTRACT_H
9 
10 #include "DocumentHash.h"
11 #include "PointIdentifiers.h"
12 #include <QUndoCommand>
13 
14 class Document;
15 class MainWindow;
16 class QXmlStreamWriter;
17 
19 class CmdAbstract : public QUndoCommand
20 {
21 public:
25  const QString &cmdDescription);
26 
27  virtual ~CmdAbstract();
28 
30  virtual void cmdRedo () = 0;
31 
33  virtual void cmdUndo () = 0;
34 
36  virtual void saveXml (QXmlStreamWriter &writer) const = 0;
37 
38 protected:
40  Document &document();
41 
43  const Document &document() const;
44 
47 
50  void resetSelection(const PointIdentifiers &pointIdentifiersToSelect);
51 
56 
60  void saveOrCheckPreCommandDocumentStateHash (const Document &document);
61 
62 private:
63  CmdAbstract();
64 
65  virtual void redo (); // Calls cmdRedo
66  virtual void undo (); // Calls cmdUndo
67 
68  MainWindow &m_mainWindow;
69  Document &m_document;
70 
71  // Snapshots of GraphicsPointAbstractBase::identifierIndex before and after redo
72  bool m_isFirstRedo;
73  unsigned int m_identifierIndexBeforeRedo;
74  unsigned int m_identifierIndexAfterRedo;
75 
76  // Hash value that represents Document state before and after CmdAbstract::redo
77  DocumentHash m_documentHashPost;
78  DocumentHash m_documentHashPre;
79 };
80 
81 #endif // CMD_ABSTRACT_H
Hash table class that tracks point identifiers as the key, with a corresponding boolean value...
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:19
virtual void cmdRedo()=0
Redo method that is called when QUndoStack is moved one command forward.
void saveOrCheckPostCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void saveOrCheckPreCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
virtual void cmdUndo()=0
Undo method that is called when QUndoStack is moved one command backward.
virtual void saveXml(QXmlStreamWriter &writer) const =0
Save commands as xml for later uploading.
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
void resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
Since the set of selected points has probably changed, changed that set back to the specified set...
Definition: CmdAbstract.cpp:81
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:89