7#include "CmdAddPointGraph.h"
9#include "DocumentSerialize.h"
10#include "EngaugeAssert.h"
12#include "MainWindow.h"
13#include "QtToString.h"
14#include <QXmlStreamReader>
17const QString CMD_DESCRIPTION (
"Add graph point");
21 const QString &curveName,
22 const QPointF &posScreen,
27 m_curveName (curveName),
28 m_posScreen (posScreen),
31 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::CmdAddPointGraph"
32 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
33 <<
" ordinal=" << m_ordinal;
38 const QString &cmdDescription,
39 QXmlStreamReader &reader) :
44 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::CmdAddPointGraph";
46 QXmlStreamAttributes attributes = reader.attributes();
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));
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();
69CmdAddPointGraph::~CmdAddPointGraph ()
75 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::cmdRedo";
87 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::cmdUndo";
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();
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
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.
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.