Engauge Digitizer  2
Public Member Functions | List of all members
CmdEditPointGraph Class Reference

Command for editing the graph coordinates of one or more graph points. More...

#include <CmdEditPointGraph.h>

Inheritance diagram for CmdEditPointGraph:
Inheritance graph
Collaboration diagram for CmdEditPointGraph:
Collaboration graph

Public Member Functions

 CmdEditPointGraph (MainWindow &mainWindow, Document &document, const QStringList &pointIdentifiers, bool isX, bool isY, double x, double y)
 Constructor for normal creation. More...
 
 CmdEditPointGraph (MainWindow &mainWindow, Document &document, const QString &cmdDescription, QXmlStreamReader &reader)
 Constructor for parsing error report file xml. More...
 
virtual ~CmdEditPointGraph ()
 
virtual void cmdRedo ()
 Redo method that is called when QUndoStack is moved one command forward. More...
 
virtual void cmdUndo ()
 Undo method that is called when QUndoStack is moved one command backward. More...
 
virtual void saveXml (QXmlStreamWriter &writer) const
 Save commands as xml for later uploading. More...
 
- Public Member Functions inherited from CmdPointChangeBase
 CmdPointChangeBase (MainWindow &mainWindow, Document &document, const QString &cmdDescription)
 Single constructor. More...
 
virtual ~CmdPointChangeBase ()
 
- Public Member Functions inherited from CmdAbstract
 CmdAbstract (MainWindow &mainWindow, Document &document, const QString &cmdDescription)
 Single constructor. More...
 
virtual ~CmdAbstract ()
 

Additional Inherited Members

- Protected Member Functions inherited from CmdPointChangeBase
void restoreDocumentState (Document &document) const
 Restore the document previously saved by saveDocumentState. More...
 
void saveDocumentState (const Document &document)
 Save the document state for restoration by restoreDocumentState. More...
 
- Protected Member Functions inherited from CmdAbstract
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

Command for editing the graph coordinates of one or more graph points.

The screen coordinates are handled by another command

Definition at line 18 of file CmdEditPointGraph.h.

Constructor & Destructor Documentation

◆ CmdEditPointGraph() [1/2]

CmdEditPointGraph::CmdEditPointGraph ( MainWindow mainWindow,
Document document,
const QStringList &  pointIdentifiers,
bool  isX,
bool  isY,
double  x,
double  y 
)

Constructor for normal creation.

Definition at line 20 of file CmdEditPointGraph.cpp.

26  :
28  document,
30  m_pointIdentifiers (pointIdentifiers),
31  m_isX (isX),
32  m_isY (isY),
33  m_x (x),
34  m_y (y)
35 {
36  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointGraph::CmdEditPointGraph point="
37  << pointIdentifiers.join(" ").toLatin1 ().data ()
38  << " x=" << (m_isX ? QString::number (x).toLatin1().data() : "")
39  << " y=" << (m_isY ? QString::number (y).toLatin1().data() : "");
40 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Base class for CmdBase leaf subclasses that involve point additions, deletions and/or modifications.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
const QString CMD_DESCRIPTION("Edit curve points")
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

◆ CmdEditPointGraph() [2/2]

CmdEditPointGraph::CmdEditPointGraph ( MainWindow mainWindow,
Document document,
const QString &  cmdDescription,
QXmlStreamReader &  reader 
)

Constructor for parsing error report file xml.

Definition at line 42 of file CmdEditPointGraph.cpp.

45  :
47  document,
48  cmdDescription)
49 {
50  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointGraph::CmdEditPointGraph";
51 
52  QXmlStreamAttributes attributes = reader.attributes();
53 
54  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X) ||
55  !attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y) ||
56  !attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_X) ||
57  !attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_Y) ) {
58  xmlExitWithError (reader,
59  QString ("%1 %2, %3, %4 %5 %6")
60  .arg (QObject::tr ("Missing attribute(s)"))
64  .arg (QObject::tr ("and/or"))
66  } else {
67 
68  // Boolean attributes
69  QString isX = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X).toString();
70  QString isY = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y).toString();
71 
72  m_isX = (isX == DOCUMENT_SERIALIZE_BOOL_TRUE);
73  m_isY = (isY == DOCUMENT_SERIALIZE_BOOL_TRUE);
74  m_x = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_X).toDouble();
75  m_y = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_Y).toDouble();
76 
77  bool success = true;
78  while (loadNextFromReader (reader)) {
79 
80  if (reader.atEnd() || reader.hasError ()) {
81  success = false;
82  break;
83  }
84 
85  if ((reader.tokenType() == QXmlStreamReader::EndElement) &
86  (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
87  break;
88  }
89 
90  // Not done yet
91  if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
92  (reader.name() == DOCUMENT_SERIALIZE_POINT)) {
93 
94  // This is an entry that we need to add
95  QXmlStreamAttributes attributes = reader.attributes ();
96 
97  if (attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER)) {
98 
99  m_pointIdentifiers << attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
100  }
101  }
102  }
103 
104  if (!success) {
105  reader.raiseError (QObject::tr ("Cannot read graph points"));
106  }
107  }
108 }
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition: Xml.cpp:14
const QString DOCUMENT_SERIALIZE_POINT
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
Base class for CmdBase leaf subclasses that involve point additions, deletions and/or modifications.
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_Y
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
const QString DOCUMENT_SERIALIZE_IDENTIFIER
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_X
void xmlExitWithError(QXmlStreamReader &reader, const QString &message)
Show specified message for an error while reading xml, then quit.
Definition: Xml.cpp:25
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
const QString DOCUMENT_SERIALIZE_CMD

◆ ~CmdEditPointGraph()

CmdEditPointGraph::~CmdEditPointGraph ( )
virtual

Definition at line 110 of file CmdEditPointGraph.cpp.

111 {
112 }

Member Function Documentation

◆ cmdRedo()

void CmdEditPointGraph::cmdRedo ( )
virtual

Redo method that is called when QUndoStack is moved one command forward.

Implements CmdAbstract.

Definition at line 114 of file CmdEditPointGraph.cpp.

115 {
116  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointGraph::cmdRedo";
117 
120  document().editPointGraph (m_isX,
121  m_isY,
122  m_x,
123  m_y,
124  m_pointIdentifiers,
125  mainWindow().transformation());
126  document().updatePointOrdinals (mainWindow().transformation());
129 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
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
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
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
void editPointGraph(bool isX, bool isY, double x, double y, const QStringList &identifiers, const Transformation &transformation)
Edit the graph coordinates of one or more graph points.
Definition: Document.cpp:377
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:1066
void saveDocumentState(const Document &document)
Save the document state for restoration by restoreDocumentState.

◆ cmdUndo()

void CmdEditPointGraph::cmdUndo ( )
virtual

Undo method that is called when QUndoStack is moved one command backward.

Implements CmdAbstract.

Definition at line 131 of file CmdEditPointGraph.cpp.

132 {
133  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointGraph::cmdUndo";
134 
139 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
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
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
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

◆ saveXml()

void CmdEditPointGraph::saveXml ( QXmlStreamWriter &  writer) const
virtual

Save commands as xml for later uploading.

Implements CmdAbstract.

Definition at line 141 of file CmdEditPointGraph.cpp.

142 {
143  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
145  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
146  writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X, m_isX ?
149  writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y, m_isY ?
152  writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_X, QString::number (m_x));
153  writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_Y, QString::number (m_y));
154 
155  for (int index = 0; index < m_pointIdentifiers.count(); index++) {
156 
157  writer.writeStartElement (DOCUMENT_SERIALIZE_POINT);
158  writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_pointIdentifiers.at (index));
159  writer.writeEndElement();
160  }
161  writer.writeEndElement();
162 }
const QString DOCUMENT_SERIALIZE_POINT
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_CMD_EDIT_POINT_GRAPH
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_Y
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X
const QString DOCUMENT_SERIALIZE_EDIT_GRAPH_X
const QString DOCUMENT_SERIALIZE_CMD

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