Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
CmdEditPointAxis.cpp
1 #include "CmdEditPointAxis.h"
2 #include "Document.h"
3 #include "DocumentSerialize.h"
4 #include "EngaugeAssert.h"
5 #include "Logger.h"
6 #include "MainWindow.h"
7 #include <QTextStream>
8 #include "QtToString.h"
9 #include <QXmlStreamReader>
10 
11 const QString CMD_DESCRIPTION ("Edit axis point");
12 
14  Document &document,
15  const QString &pointIdentifier,
16  const QPointF &posGraphBefore,
17  const QPointF &posGraphAfter) :
18  CmdAbstract (mainWindow,
19  document,
20  CMD_DESCRIPTION),
21  m_pointIdentifier (pointIdentifier),
22  m_posGraphBefore (posGraphBefore),
23  m_posGraphAfter (posGraphAfter)
24 {
25  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointAxis::CmdEditPointAxis point="
26  << pointIdentifier.toLatin1 ().data ()
27  << " posGraphBefore=" << QPointFToString (posGraphBefore).toLatin1 ().data ()
28  << " posGraphAfter=" << QPointFToString (posGraphAfter).toLatin1 ().data ();
29 }
30 
32  Document &document,
33  const QString &cmdDescription,
34  QXmlStreamReader &reader) :
35  CmdAbstract (mainWindow,
36  document,
37  cmdDescription)
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointAxis::CmdEditPointAxis";
40 
41  QXmlStreamAttributes attributes = reader.attributes();
42 
43  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_X_BEFORE) ||
44  !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_Y_BEFORE) ||
45  !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_X_AFTER) ||
46  !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_Y_AFTER) ||
47  !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER)) {
48  ENGAUGE_ASSERT (false);
49  }
50 
51  m_posGraphBefore.setX(attributes.value(DOCUMENT_SERIALIZE_GRAPH_X_BEFORE).toDouble());
52  m_posGraphBefore.setY(attributes.value(DOCUMENT_SERIALIZE_GRAPH_Y_BEFORE).toDouble());
53  m_posGraphAfter.setX(attributes.value(DOCUMENT_SERIALIZE_GRAPH_X_AFTER).toDouble());
54  m_posGraphAfter.setY(attributes.value(DOCUMENT_SERIALIZE_GRAPH_Y_AFTER).toDouble());
55  m_pointIdentifier = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
56 }
57 
58 CmdEditPointAxis::~CmdEditPointAxis ()
59 {
60 }
61 
63 {
64  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointAxis::cmdRedo";
65 
66  document().editPointAxis (m_posGraphAfter,
67  m_pointIdentifier);
68  document().updatePointOrdinals (mainWindow().transformation());
70 }
71 
73 {
74  LOG4CPP_INFO_S ((*mainCat)) << "CmdEditPointAxis::cmdUndo";
75 
76  document().editPointAxis (m_posGraphBefore,
77  m_pointIdentifier);
78  document().updatePointOrdinals (mainWindow().transformation());
80 }
81 
82 void CmdEditPointAxis::saveXml (QXmlStreamWriter &writer) const
83 {
84  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
85  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_EDIT_POINT_AXIS);
86  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
87  writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_pointIdentifier);
88  writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_X_BEFORE, QString::number (m_posGraphBefore.x()));
89  writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_Y_BEFORE, QString::number (m_posGraphBefore.y()));
90  writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_X_AFTER, QString::number (m_posGraphAfter.x()));
91  writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_Y_AFTER, QString::number (m_posGraphAfter.y()));
92  writer.writeEndElement();
93 }
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:11
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
void editPointAxis(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of a single axis point. Call this after checkAddPointAxis to guarantee suc...
Definition: Document.cpp:303
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:32
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Storage of one imported image and the data attached to that image.
Definition: Document.h:29
CmdEditPointAxis(MainWindow &mainWindow, Document &document, const QString &pointIdentifier, const QPointF &posGraphBefore, const QPointF &posGraphAfter)
Constructor for normal creation.
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:22
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:60
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:926