Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
CmdAddPointGraph.cpp
1 #include "CmdAddPointGraph.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 graph point");
11 
13  Document &document,
14  const QString &curveName,
15  const QPointF &posScreen,
16  double ordinal) :
17  CmdAbstract (mainWindow,
18  document,
19  CMD_DESCRIPTION),
20  m_curveName (curveName),
21  m_posScreen (posScreen),
22  m_ordinal (ordinal)
23 {
24  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph"
25  << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
26  << " ordinal=" << m_ordinal;
27 }
28 
30  Document &document,
31  const QString &cmdDescription,
32  QXmlStreamReader &reader) :
33  CmdAbstract (mainWindow,
34  document,
35  cmdDescription)
36 {
37  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph";
38 
39  QXmlStreamAttributes attributes = reader.attributes();
40 
41  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) ||
42  !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y) ||
43  !attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME) ||
44  !attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL) ||
45  !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER)) {
46  ENGAUGE_ASSERT (false);
47  }
48 
49  m_posScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toDouble());
50  m_posScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toDouble());
51  m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
52  m_identifierAdded = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
53  m_ordinal = attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
54 }
55 
56 CmdAddPointGraph::~CmdAddPointGraph ()
57 {
58 }
59 
61 {
62  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::cmdRedo";
63 
65  m_posScreen,
66  m_identifierAdded,
67  m_ordinal);
68  document().updatePointOrdinals (mainWindow().transformation());
70 }
71 
73 {
74  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::cmdUndo";
75 
76  document().removePointGraph (m_identifierAdded);
77  document().updatePointOrdinals (mainWindow().transformation());
79 }
80 
81 void CmdAddPointGraph::saveXml (QXmlStreamWriter &writer) const
82 {
83  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
84  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH);
85  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
86  writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
87  writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_posScreen.x()));
88  writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_posScreen.y()));
89  writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_identifierAdded);
90  writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinal));
91  writer.writeEndElement();
92 }
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
Definition: Document.cpp:155
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:11
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
Definition: Document.cpp:793
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:29
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
CmdAddPointGraph(MainWindow &mainWindow, Document &document, const QString &curveName, const QPointF &posScreen, double ordinal)
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
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:926