7 #include "CmdAddPointAxis.h" 9 #include "DocumentSerialize.h" 10 #include "EngaugeAssert.h" 12 #include "MainWindow.h" 13 #include "QtToString.h" 14 #include <QXmlStreamReader> 17 const QString CMD_DESCRIPTION (
"Add axis point");
21 const QPointF &posScreen,
22 const QPointF &posGraph,
28 m_posScreen (posScreen),
29 m_posGraph (posGraph),
33 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointAxis::CmdAddPointAxis" 34 <<
" posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
35 <<
" posGraph=" << QPointFToString (posGraph).toLatin1 ().data ()
36 <<
" ordinal=" << ordinal;
41 const QString &cmdDescription,
42 QXmlStreamReader &reader) :
47 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointAxis::CmdAddPointAxis";
49 QXmlStreamAttributes attributes = reader.attributes();
51 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) ||
52 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y) ||
53 !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_X) ||
54 !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_Y) ||
55 !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER) ||
56 !attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL) ||
57 !attributes.hasAttribute(DOCUMENT_SERIALIZE_POINT_IS_X_ONLY)) {
58 xmlExitWithError (reader,
59 QString (
"Missing attribute(s) %1, %2, %3, %4, %5, %6 and/or %7")
60 .arg (DOCUMENT_SERIALIZE_SCREEN_X)
61 .arg (DOCUMENT_SERIALIZE_SCREEN_Y)
62 .arg (DOCUMENT_SERIALIZE_GRAPH_X)
63 .arg (DOCUMENT_SERIALIZE_GRAPH_Y)
64 .arg (DOCUMENT_SERIALIZE_IDENTIFIER)
65 .arg (DOCUMENT_SERIALIZE_ORDINAL)
66 .arg (DOCUMENT_SERIALIZE_POINT_IS_X_ONLY));
70 QString isXOnlyValue = attributes.value(DOCUMENT_SERIALIZE_POINT_IS_X_ONLY).toString();
72 m_posScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toDouble());
73 m_posScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toDouble());
74 m_posGraph.setX(attributes.value(DOCUMENT_SERIALIZE_GRAPH_X).toDouble());
75 m_posGraph.setY(attributes.value(DOCUMENT_SERIALIZE_GRAPH_Y).toDouble());
76 m_identifierAdded = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
77 m_ordinal = attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
78 m_isXOnly = (isXOnlyValue == DOCUMENT_SERIALIZE_BOOL_TRUE);
81 CmdAddPointAxis::~CmdAddPointAxis ()
87 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointAxis::cmdRedo";
100 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointAxis::cmdUndo";
109 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
110 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_POINT_AXIS);
111 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
112 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_posScreen.x()));
113 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_posScreen.y()));
114 writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_X, QString::number (m_posGraph.x()));
115 writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_Y, QString::number (m_posGraph.y()));
116 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_identifierAdded);
117 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinal));
118 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IS_X_ONLY, m_isXOnly ?
119 DOCUMENT_SERIALIZE_BOOL_TRUE :
120 DOCUMENT_SERIALIZE_BOOL_FALSE);
121 writer.writeEndElement();
CmdAddPointAxis(MainWindow &mainWindow, Document &document, const QPointF &posScreen, const QPointF &posGraph, double ordinal, bool isXOnly)
Constructor for normal creation.
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.
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
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.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Storage of one imported image and the data attached to that image.
void addPointAxisWithGeneratedIdentifier(const QPointF &posScreen, const QPointF &posGraph, QString &identifier, double ordinal, bool isXOnly)
Add a single axis point with a generated point identifier.
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...
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.