Engauge Digitizer  2
CmdAddPointAxis.cpp
1 #include "CmdAddPointAxis.h"
2 #include "Document.h"
3 #include "DocumentSerialize.h"
4 #include "EngaugeAssert.h"
5 #include "Logger.h"
6 #include "MainWindow.h"
7 #include "QtToString.h"
8 #include <QXmlStreamReader>
9 
10 const QString CMD_DESCRIPTION ("Add axis point");
11 
13  Document &document,
14  const QPointF &posScreen,
15  const QPointF &posGraph,
16  double ordinal) :
17  CmdAbstract (mainWindow,
18  document,
19  CMD_DESCRIPTION),
20  m_posScreen (posScreen),
21  m_posGraph (posGraph),
22  m_ordinal (ordinal)
23 {
24  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointAxis::CmdAddPointAxis"
25  << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
26  << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ()
27  << " ordinal=" << ordinal;
28 }
29 
31  Document &document,
32  const QString &cmdDescription,
33  QXmlStreamReader &reader) :
34  CmdAbstract (mainWindow,
35  document,
36  cmdDescription)
37 {
38  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointAxis::CmdAddPointAxis";
39 
40  QXmlStreamAttributes attributes = reader.attributes();
41 
42  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) ||
43  !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y) ||
44  !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_X) ||
45  !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_Y) ||
46  !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER) ||
47  !attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL)) {
48  ENGAUGE_ASSERT (false);
49  }
50 
51  m_posScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toDouble());
52  m_posScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toDouble());
53  m_posGraph.setX(attributes.value(DOCUMENT_SERIALIZE_GRAPH_X).toDouble());
54  m_posGraph.setY(attributes.value(DOCUMENT_SERIALIZE_GRAPH_Y).toDouble());
55  m_identifierAdded = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
56  m_ordinal = attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
57 }
58 
59 CmdAddPointAxis::~CmdAddPointAxis ()
60 {
61 }
62 
64 {
65  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointAxis::cmdRedo";
66 
68  m_posGraph,
69  m_identifierAdded,
70  m_ordinal);
71  document().updatePointOrdinals (mainWindow().transformation());
73 }
74 
76 {
77  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointAxis::cmdUndo";
78 
79  document().removePointAxis (m_identifierAdded);
80  document().updatePointOrdinals (mainWindow().transformation());
82 }
83 
84 void CmdAddPointAxis::saveXml (QXmlStreamWriter &writer) const
85 {
86  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
87  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_POINT_AXIS);
88  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
89  writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_posScreen.x()));
90  writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_posScreen.y()));
91  writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_X, QString::number (m_posGraph.x()));
92  writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_Y, QString::number (m_posGraph.y()));
93  writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_identifierAdded);
94  writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinal));
95  writer.writeEndElement();
96 }
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
void removePointAxis(const QString &identifier)
Perform the opposite of addPointAxis.
Definition: Document.cpp:582
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:11
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
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
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Storage of one imported image and the data attached to that image.
Definition: Document.h:28
void addPointAxisWithGeneratedIdentifier(const QPointF &posScreen, const QPointF &posGraph, QString &identifier, double ordinal)
Add a single axis point with a generated point identifier.
Definition: Document.cpp:152
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:22
CmdAddPointAxis(MainWindow &mainWindow, Document &document, const QPointF &posScreen, const QPointF &posGraph, double ordinal)
Constructor for normal creation.
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:722