Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdAbstract.h
Go to the documentation of this file.
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 "DigitizeState.h"
11#include "DocumentHash.h"
12#include "PointIdentifiers.h"
13#include <QString>
14#include <QStringList>
15#include <QUndoCommand>
16
17class Document;
18class MainWindow;
19class QXmlStreamAttributes;
20class QXmlStreamWriter;
21
23class CmdAbstract : public QUndoCommand
24{
25public:
29 const QString &cmdDescription);
30
31 virtual ~CmdAbstract();
32
34 virtual void cmdRedo () = 0;
35
37 virtual void cmdUndo () = 0;
38
40 virtual void saveXml (QXmlStreamWriter &writer) const = 0;
41
42protected:
43
45 void baseAttributes (QXmlStreamWriter &writer) const;
46
49
51 const Document &document() const;
52
56 void leafAttributes (const QXmlStreamAttributes &attributes,
57 const QStringList &requiredAttributesLeaf,
58 QXmlStreamReader &reader);
59
62 void leafAndBaseAttributes (const QXmlStreamAttributes &attributes,
63 const QStringList &requiredAttributesLeaf,
64 QXmlStreamReader &reader);
65
68
70
73 void resetSelection(const PointIdentifiers &pointIdentifiersToSelect);
74
77 void restoreState ();
78
83
88
90 void selectAddedPointForMoving (const QString &pointAdded);
91
93 void selectAddedPointsForMoving (const QStringList &pointsAdded);
94
95private:
97
98 virtual void redo (); // Calls cmdRedo
99 virtual void undo (); // Calls cmdUndo
100
101 MainWindow &m_mainWindow;
102 Document &m_document;
103
104 // Snapshots of GraphicsPointAbstractBase::identifierIndex before and after redo
105 bool m_isFirstRedo;
106 unsigned int m_identifierIndexBeforeRedo;
107 unsigned int m_identifierIndexAfterRedo;
108
109 // Hash value that represents Document state before and after CmdAbstract::redo
110 DocumentHash m_documentHashPost;
111 DocumentHash m_documentHashPre;
112
113 // States that apply throughout the lifetime of the command. In either forward (=redo)
114 // or backward (=undo) direction they will be applied before the command is executed
115 DigitizeState m_digitizeState;
116};
117
118#endif // CMD_ABSTRACT_H
DigitizeState
Set of possible states of Digitize toolbar.
QByteArray DocumentHash
Document & document()
Return the Document that this command will modify during redo and undo.
void selectAddedPointForMoving(const QString &pointAdded)
Select point that was just added so it can be moved by the user next for convenience.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
virtual void cmdUndo()=0
Undo method that is called when QUndoStack is moved one command backward.
void saveOrCheckPostCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void restoreState()
Before any other operations associated with a Cmd class are performed, this method is called to resto...
void leafAttributes(const QXmlStreamAttributes &attributes, const QStringList &requiredAttributesLeaf, QXmlStreamReader &reader)
Same as often-used leafAndBaseAttributes, except this is used in the special case where a class inher...
void saveOrCheckPreCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
Call this (for consistency) after writing leaf class attributes, to write the base class attributes.
virtual void saveXml(QXmlStreamWriter &writer) const =0
Save commands as xml for later uploading.
virtual ~CmdAbstract()
void leafAndBaseAttributes(const QXmlStreamAttributes &attributes, const QStringList &requiredAttributesLeaf, QXmlStreamReader &reader)
Before reading leaf class attributes, check all required attributes from leaf and this base class are...
void baseAttributes(QXmlStreamWriter &writer) const
After writing leaf class attributes, this writes the base class atributes.
CmdAbstract(MainWindow &mainWindow, Document &document, const QString &cmdDescription)
Single constructor.
void selectAddedPointsForMoving(const QStringList &pointsAdded)
Select points that were just added so they can be moved by the user next for convenience.
virtual void cmdRedo()=0
Redo method that is called when QUndoStack is moved one command forward.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95
Hash table class that tracks point identifiers as the key, with a corresponding boolean value.