Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdAddPointGraph.cpp
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "CmdAddPointGraph.h"
8#include "Document.h"
9#include "DocumentSerialize.h"
10#include "EngaugeAssert.h"
11#include "Logger.h"
12#include "MainWindow.h"
13#include "QtToString.h"
14#include <QXmlStreamReader>
15#include "Xml.h"
16
17const QString CMD_DESCRIPTION ("Add graph point");
18
20 Document &document,
21 const QString &curveName,
22 const QPointF &posScreen,
23 double ordinal) :
24 CmdAbstract (mainWindow,
25 document,
26 CMD_DESCRIPTION),
27 m_curveName (curveName),
28 m_posScreen (posScreen),
29 m_ordinal (ordinal)
30{
31 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph"
32 << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
33 << " ordinal=" << m_ordinal;
34}
35
37 Document &document,
38 const QString &cmdDescription,
39 QXmlStreamReader &reader) :
40 CmdAbstract (mainWindow,
41 document,
42 cmdDescription)
43{
44 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph";
45
46 QXmlStreamAttributes attributes = reader.attributes();
47
48 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) ||
49 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y) ||
50 !attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME) ||
51 !attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL) ||
52 !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER)) {
53 xmlExitWithError (reader,
54 QString ("Missing attribute(s) %1, %2, %3, %4 and/or %5")
55 .arg (DOCUMENT_SERIALIZE_SCREEN_X)
56 .arg (DOCUMENT_SERIALIZE_SCREEN_Y)
57 .arg (DOCUMENT_SERIALIZE_CURVE_NAME)
58 .arg (DOCUMENT_SERIALIZE_ORDINAL)
59 .arg (DOCUMENT_SERIALIZE_IDENTIFIER));
60 }
61
62 m_posScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toDouble());
63 m_posScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toDouble());
64 m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
65 m_identifierAdded = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
66 m_ordinal = attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
67}
68
69CmdAddPointGraph::~CmdAddPointGraph ()
70{
71}
72
74{
75 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::cmdRedo";
76
78 m_posScreen,
79 m_identifierAdded,
80 m_ordinal);
81 document().updatePointOrdinals (mainWindow().transformation());
83}
84
86{
87 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::cmdUndo";
88
89 document().removePointGraph (m_identifierAdded);
90 document().updatePointOrdinals (mainWindow().transformation());
92}
93
94void CmdAddPointGraph::saveXml (QXmlStreamWriter &writer) const
95{
96 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
97 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH);
98 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
99 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
100 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_posScreen.x()));
101 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_posScreen.y()));
102 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_identifierAdded);
103 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinal));
104 writer.writeEndElement();
105}
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:19
Document & document()
Return the Document that this command will modify during redo and undo.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
CmdAddPointGraph(MainWindow &mainWindow, Document &document, const QString &curveName, const QPointF &posScreen, double ordinal)
Constructor for normal creation.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
Storage of one imported image and the data attached to that image.
Definition Document.h:41
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition Document.cpp:903
void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
Definition Document.cpp:734
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:184
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:78
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.