7 #include "CmdAddPointGraph.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 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();
69 CmdAddPointGraph::~CmdAddPointGraph ()
75 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::cmdRedo";
90 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointGraph::cmdUndo";
100 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
101 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH);
102 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
103 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
104 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_posScreen.x()));
105 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_posScreen.y()));
106 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_identifierAdded);
107 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinal));
108 writer.writeEndElement();
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
void saveOrCheckPostCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void saveOrCheckPreCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
Base class for CmdBase leaf subclasses that involve point additions, deletions and/or modifications...
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.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
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.
void saveDocumentState(const Document &document)
Save the document state for restoration by restoreDocumentState.