Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdAbstract Class Referenceabstract

Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand. More...

#include <CmdAbstract.h>

Inheritance diagram for CmdAbstract:
Inheritance graph
Collaboration diagram for CmdAbstract:
Collaboration graph

Public Member Functions

 CmdAbstract (MainWindow &mainWindow, Document &document, const QString &cmdDescription)
 Single constructor.
virtual ~CmdAbstract ()
virtual void cmdRedo ()=0
 Redo method that is called when QUndoStack is moved one command forward.
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.

Protected Member Functions

void baseAttributes (QXmlStreamWriter &writer) const
 After writing leaf class attributes, this writes the base class atributes.
Documentdocument ()
 Return the Document that this command will modify during redo and undo.
const Documentdocument () const
 Return a const copy of the Document for non redo/undo interaction.
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 inherits from another class (e.g.
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 included, then extract the parent class attributes.
MainWindowmainWindow ()
 Return the MainWindow so it can be updated by this command as a last step.
void resetSelection (const PointIdentifiers &pointIdentifiersToSelect)
 Call this (for consistency) after writing leaf class attributes, to write the base class attributes.
void restoreState ()
 Before any other operations associated with a Cmd class are performed, this method is called to restore original states to all relevant state machines.
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.
void selectAddedPointForMoving (const QString &pointAdded)
 Select point that was just added so it can be moved by the user next for convenience.
void selectAddedPointsForMoving (const QStringList &pointsAdded)
 Select points that were just added so they can be moved by the user next for convenience.

Detailed Description

Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.

Definition at line 23 of file CmdAbstract.h.

Constructor & Destructor Documentation

◆ CmdAbstract()

CmdAbstract::CmdAbstract ( MainWindow & mainWindow,
Document & document,
const QString & cmdDescription )

Single constructor.

Definition at line 26 of file CmdAbstract.cpp.

28 :
29 QUndoCommand (cmdDescription),
30 m_mainWindow (mainWindow),
31 m_document (document),
32 m_isFirstRedo (true),
33 m_digitizeState (mainWindow.digitizeState ())
34{
35 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::CmdAbstract";
36}
log4cpp::Category * mainCat
Definition Logger.cpp:14
Document & document()
Return the Document that this command will modify during redo and undo.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ ~CmdAbstract()

CmdAbstract::~CmdAbstract ( )
virtual

Definition at line 38 of file CmdAbstract.cpp.

39{
40}

Member Function Documentation

◆ baseAttributes()

void CmdAbstract::baseAttributes ( QXmlStreamWriter & writer) const
protected

After writing leaf class attributes, this writes the base class atributes.

Definition at line 42 of file CmdAbstract.cpp.

43{
44 writer.writeAttribute(DOCUMENT_SERIALIZE_DIGITIZE_STATE, QString::number (m_digitizeState));
45 writer.writeAttribute(DOCUMENT_SERIALIZE_DIGITIZE_STATE_STRING, digitizeStateAsString (m_digitizeState));
46}
QString digitizeStateAsString(DigitizeState state)
const QString DOCUMENT_SERIALIZE_DIGITIZE_STATE
const QString DOCUMENT_SERIALIZE_DIGITIZE_STATE_STRING

◆ cmdRedo()

◆ cmdUndo()

◆ document() [1/2]

Document & CmdAbstract::document ( )
protected

Return the Document that this command will modify during redo and undo.

Definition at line 48 of file CmdAbstract.cpp.

49{
50 return m_document;
51}

◆ document() [2/2]

const Document & CmdAbstract::document ( ) const
protected

Return a const copy of the Document for non redo/undo interaction.

Definition at line 53 of file CmdAbstract.cpp.

54{
55 return m_document;
56}

◆ leafAndBaseAttributes()

void CmdAbstract::leafAndBaseAttributes ( const QXmlStreamAttributes & attributes,
const QStringList & requiredAttributesLeaf,
QXmlStreamReader & reader )
protected

Before reading leaf class attributes, check all required attributes from leaf and this base class are included, then extract the parent class attributes.

Definition at line 79 of file CmdAbstract.cpp.

82{
83 // Aggregate attributes for leaf and this abstract class
84 QStringList requiredAttributes = requiredAttributesLeaf;
85 requiredAttributes << DOCUMENT_SERIALIZE_DIGITIZE_STATE;
86
87 // Check as if this base class was a leaf class
88 leafAttributes (attributes,
89 requiredAttributes,
90 reader);
91
92 // Extract parent class attributes
93 m_digitizeState = static_cast<DigitizeState> (attributes.value (DOCUMENT_SERIALIZE_DIGITIZE_STATE).toInt());
94}
DigitizeState
Set of possible states of Digitize toolbar.
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...

◆ leafAttributes()

void CmdAbstract::leafAttributes ( const QXmlStreamAttributes & attributes,
const QStringList & requiredAttributesLeaf,
QXmlStreamReader & reader )
protected

Same as often-used leafAndBaseAttributes, except this is used in the special case where a class inherits from another class (e.g.

CmdPointChangeBase) that inherits from the base class. In the three level case, the lowest class calls this method and the midlevel class calls leafAndBaseAttributes

Definition at line 58 of file CmdAbstract.cpp.

61{
62 // Check for leaf class if called directly, or for base class if called indirectly through leafAndBaseAttributes
63 QStringList::const_iterator itr;
64 QStringList missingAttributes;
65 for (itr = requiredAttributesLeaf.begin (); itr != requiredAttributesLeaf.end (); itr++) {
66
67 QString attribute = *itr;
68 if (!attributes.hasAttribute (attribute)) {
69 missingAttributes << attribute;
70 }
71 }
72
73 if (missingAttributes.size () > 0) {
74 xmlExitWithError (reader,
75 QString ("Missing attribute(s) %1"). arg (missingAttributes.join (", ")));
76 }
77}
void xmlExitWithError(QXmlStreamReader &reader, const QString &message)
Show specified message for an error while reading xml, then quit.
Definition Xml.cpp:25

◆ mainWindow()

MainWindow & CmdAbstract::mainWindow ( )
protected

Return the MainWindow so it can be updated by this command as a last step.

Definition at line 96 of file CmdAbstract.cpp.

97{
98 return m_mainWindow;
99}

◆ resetSelection()

void CmdAbstract::resetSelection ( const PointIdentifiers & pointIdentifiersToSelect)
protected

Call this (for consistency) after writing leaf class attributes, to write the base class attributes.

Since the set of selected points has probably changed, changed that set back to the specified set. This lets the user move selected point(s) repeatedly using arrow keys. Also provides expected behavior when pasting

Definition at line 132 of file CmdAbstract.cpp.

133{
134 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::resetSelection";
135
136 QList<QGraphicsItem *> items = mainWindow().view().items();
137 QList<QGraphicsItem *>::iterator itrS;
138 for (itrS = items.begin (); itrS != items.end (); itrS++) {
139
140 QGraphicsItem *item = *itrS;
141 bool selected = false;
142 if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT) {
143
144 QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
145
146 selected = pointIdentifiersToSelect.contains (pointIdentifier);
147 }
148
149 item->setSelected (selected);
150 }
151}
@ DATA_KEY_GRAPHICS_ITEM_TYPE
Definition DataKey.h:15
@ DATA_KEY_IDENTIFIER
Definition DataKey.h:14
@ GRAPHICS_ITEM_TYPE_POINT
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
bool contains(const QString &pointIdentifier) const
True if specified entry exists in the table.

◆ restoreState()

void CmdAbstract::restoreState ( )
protected

Before any other operations associated with a Cmd class are performed, this method is called to restore original states to all relevant state machines.

Definition at line 153 of file CmdAbstract.cpp.

154{
155 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::restoreState";
156
157 m_mainWindow.updateDigitizeStateIfSoftwareTriggered (m_digitizeState);
158}

◆ saveOrCheckPostCommandDocumentStateHash()

void CmdAbstract::saveOrCheckPostCommandDocumentStateHash ( const Document & document)
protected

Save, when called the first time, a hash value representing the state of the Document.

Then on succeeding calls the hash is recomputed and compared to the original value to check for consistency. This "post" method is called immediately after the redo method of the subclass has done its processing. See also saveOrCheckPreCommandDocumentState

Definition at line 160 of file CmdAbstract.cpp.

161{
162 // LOG4CPP_INFO_S is below
163
164 DocumentHashGenerator documentHashGenerator;
165 DocumentHash documentHash = documentHashGenerator.generate (document);
166
167 if (m_documentHashPost.count() == 0) {
168
169 // This is the first time through here so save the initial value
170 m_documentHashPost = documentHash;
171
172 } else {
173
174 // This is not the first time through here so compare the current value to the initial value
175 ENGAUGE_ASSERT (documentHash == m_documentHashPost);
176
177 }
178
179 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::saveOrCheckPostCommandDocumentStateHash stateHash=" << m_documentHashPost.data ();
180
181}
QByteArray DocumentHash
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT.
DocumentHash generate(const Document &document) const
Generate the hash for external storage.

◆ saveOrCheckPreCommandDocumentStateHash()

void CmdAbstract::saveOrCheckPreCommandDocumentStateHash ( const Document & document)
protected

Save, when called the first time, a hash value representing the state of the Document.

Then on succeeding calls the hash is recomputed and compared to the original value to check for consistency. This "pre" method is called immediately after the redo method of the subclass has done its processing. See also saveOrCheckPostCommandDocumentState

Definition at line 183 of file CmdAbstract.cpp.

184{
185 // LOG4CPP_INFO_S is below
186
187 DocumentHashGenerator documentHashGenerator;
188 DocumentHash documentHash = documentHashGenerator.generate (document);
189
190 if (m_documentHashPre.count() == 0) {
191
192 // This is the first time through here so save the initial value
193 m_documentHashPre = documentHash;
194
195 } else {
196
197 // This is not the first time through here so compare the current value to the initial value
198 ENGAUGE_ASSERT (documentHash == m_documentHashPre);
199
200 }
201
202 LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::saveOrCheckPreCommandDocumentStateHash stateHash=" << m_documentHashPre.data ();
203
204}

◆ saveXml()

◆ selectAddedPointForMoving()

void CmdAbstract::selectAddedPointForMoving ( const QString & pointAdded)
protected

Select point that was just added so it can be moved by the user next for convenience.

Definition at line 206 of file CmdAbstract.cpp.

207{
208 // Select added points so they can be moved
209 PointIdentifiers pointIdentifiers;
210 pointIdentifiers.setKeyValue (pointAdded, true);
211 resetSelection(pointIdentifiers);
212}
void resetSelection(const PointIdentifiers &pointIdentifiersToSelect)
Call this (for consistency) after writing leaf class attributes, to write the base class attributes.
void setKeyValue(const QString &pointIdentifier, bool value)
Set key/value pair.

◆ selectAddedPointsForMoving()

void CmdAbstract::selectAddedPointsForMoving ( const QStringList & pointsAdded)
protected

Select points that were just added so they can be moved by the user next for convenience.

Definition at line 214 of file CmdAbstract.cpp.

215{
216 // Select added points so they can be moved
217 PointIdentifiers pointIdentifiers;
218 QStringList::const_iterator itr;
219 for (itr = pointsAdded.begin(); itr != pointsAdded.end(); itr++) {
220 QString pointAdded = *itr;
221 pointIdentifiers.setKeyValue (pointAdded, true);
222 }
223 resetSelection(pointIdentifiers);
224}

The documentation for this class was generated from the following files: