1 #include "CmdAddPointGraph.h"
3 #include "DocumentSerialize.h"
4 #include "EngaugeAssert.h"
6 #include "MainWindow.h"
7 #include "QtToString.h"
8 #include <QXmlStreamReader>
10 const QString CMD_DESCRIPTION (
"Add graph point");
14 const QString &curveName,
15 const QPointF &posScreen,
20 m_curveName (curveName),
21 m_posScreen (posScreen),
24 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::CmdAddPointGraph"
25 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
26 <<
" ordinal=" << m_ordinal;
31 const QString &cmdDescription,
32 QXmlStreamReader &reader) :
37 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::CmdAddPointGraph";
39 QXmlStreamAttributes attributes = reader.attributes();
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);
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();
56 CmdAddPointGraph::~CmdAddPointGraph ()
62 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::cmdRedo";
74 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::cmdUndo";
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();
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
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.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Storage of one imported image and the data attached to that image.
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.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
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.