Engauge Digitizer  2
Public Member Functions | Protected Member Functions | List of all members
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. More...
 
virtual ~CmdAbstract ()
 
virtual void cmdRedo ()=0
 Redo method that is called when QUndoStack is moved one command forward. More...
 
virtual void cmdUndo ()=0
 Undo method that is called when QUndoStack is moved one command backward. More...
 
virtual void saveXml (QXmlStreamWriter &writer) const =0
 Save commands as xml for later uploading. More...
 

Protected Member Functions

Documentdocument ()
 Return the Document that this command will modify during redo and undo. More...
 
const Documentdocument () const
 Return a const copy of the Document for non redo/undo interaction. More...
 
MainWindowmainWindow ()
 Return the MainWindow so it can be updated by this command as a last step. More...
 
void resetSelection (const PointIdentifiers &pointIdentifiersToSelect)
 Since the set of selected points has probably changed, changed that set back to the specified set. More...
 
void saveOrCheckPostCommandDocumentStateHash (const Document &document)
 Save, when called the first time, a hash value representing the state of the Document. More...
 
void saveOrCheckPreCommandDocumentStateHash (const Document &document)
 Save, when called the first time, a hash value representing the state of the Document. More...
 

Detailed Description

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

Definition at line 19 of file CmdAbstract.h.

Constructor & Destructor Documentation

◆ CmdAbstract()

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

Single constructor.

Definition at line 20 of file CmdAbstract.cpp.

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

◆ ~CmdAbstract()

CmdAbstract::~CmdAbstract ( )
virtual

Definition at line 31 of file CmdAbstract.cpp.

32 {
33 }

Member Function Documentation

◆ cmdRedo()

virtual void CmdAbstract::cmdRedo ( )
pure virtual

◆ cmdUndo()

virtual void CmdAbstract::cmdUndo ( )
pure virtual

◆ document() [1/2]

Document & CmdAbstract::document ( )
protected

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

Definition at line 35 of file CmdAbstract.cpp.

36 {
37  return m_document;
38 }

◆ document() [2/2]

const Document & CmdAbstract::document ( ) const
protected

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

Definition at line 40 of file CmdAbstract.cpp.

41 {
42  return m_document;
43 }

◆ mainWindow()

MainWindow & CmdAbstract::mainWindow ( )
protected

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

Definition at line 45 of file CmdAbstract.cpp.

46 {
47  return m_mainWindow;
48 }

◆ resetSelection()

void CmdAbstract::resetSelection ( const PointIdentifiers pointIdentifiersToSelect)
protected

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 81 of file CmdAbstract.cpp.

82 {
83  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::resetSelection";
84 
85  QList<QGraphicsItem *> items = mainWindow().view().items();
86  QList<QGraphicsItem *>::iterator itrS;
87  for (itrS = items.begin (); itrS != items.end (); itrS++) {
88 
89  QGraphicsItem *item = *itrS;
90  bool selected = false;
91  if (item->data (DATA_KEY_GRAPHICS_ITEM_TYPE).toInt () == GRAPHICS_ITEM_TYPE_POINT) {
92 
93  QString pointIdentifier = item->data (DATA_KEY_IDENTIFIER).toString ();
94 
95  selected = pointIdentifiersToSelect.contains (pointIdentifier);
96  }
97 
98  item->setSelected (selected);
99  }
100 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Unique identifier for QGraphicsItem object
Definition: DataKey.h:15
GraphicsView & view()
View for the QImage and QGraphicsItems, without const.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
log4cpp::Category * mainCat
Definition: Logger.cpp:14
bool contains(const QString &pointIdentifier) const
True if specified entry exists in the table.

◆ 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 102 of file CmdAbstract.cpp.

103 {
104  // LOG4CPP_INFO_S is below
105 
106  DocumentHashGenerator documentHashGenerator;
107  DocumentHash documentHash = documentHashGenerator.generate (document);
108 
109  if (m_documentHashPost.count() == 0) {
110 
111  // This is the first time through here so save the initial value
112  m_documentHashPost = documentHash;
113 
114  } else {
115 
116  // This is not the first time through here so compare the current value to the initial value
117  ENGAUGE_ASSERT (documentHash == m_documentHashPost);
118 
119  }
120 
121  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::saveOrCheckPostCommandDocumentStateHash stateHash=" << m_documentHashPost.data ();
122 
123 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Generates a DocumentHash value representing the state of the entire Document.
DocumentHash generate(const Document &document) const
Generate the hash for external storage.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
QByteArray DocumentHash
Definition: DocumentHash.h:12
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20

◆ 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 125 of file CmdAbstract.cpp.

126 {
127  // LOG4CPP_INFO_S is below
128 
129  DocumentHashGenerator documentHashGenerator;
130  DocumentHash documentHash = documentHashGenerator.generate (document);
131 
132  if (m_documentHashPre.count() == 0) {
133 
134  // This is the first time through here so save the initial value
135  m_documentHashPre = documentHash;
136 
137  } else {
138 
139  // This is not the first time through here so compare the current value to the initial value
140  ENGAUGE_ASSERT (documentHash == m_documentHashPre);
141 
142  }
143 
144  LOG4CPP_INFO_S ((*mainCat)) << "CmdAbstract::saveOrCheckPreCommandDocumentStateHash stateHash=" << m_documentHashPre.data ();
145 
146 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Generates a DocumentHash value representing the state of the entire Document.
DocumentHash generate(const Document &document) const
Generate the hash for external storage.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
QByteArray DocumentHash
Definition: DocumentHash.h:12
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
Definition: EngaugeAssert.h:20

◆ saveXml()

virtual void CmdAbstract::saveXml ( QXmlStreamWriter &  writer) const
pure virtual

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