7 #include "CmdAddPointsGraph.h" 9 #include "DocumentSerialize.h" 10 #include "EngaugeAssert.h" 12 #include "MainWindow.h" 14 #include "QtToString.h" 15 #include <QXmlStreamReader> 16 #include <QXmlStreamWriter> 19 const QString CMD_DESCRIPTION (
"Add graph points");
23 const QString &curveName,
24 const QList<QPoint> &points,
25 const QList<double> &ordinals) :
29 m_curveName (curveName),
33 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointsGraph::CmdAddPointsGraph";
38 const QString &cmdDescription,
39 QXmlStreamReader &reader) :
44 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointsGraph::CmdAddPointsGraph";
46 QXmlStreamAttributes attributes = reader.attributes();
48 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME)) {
49 xmlExitWithError (reader,
51 .arg (QObject::tr (
"Missing attribute"))
52 .arg (DOCUMENT_SERIALIZE_CURVE_NAME));
55 m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
58 while (loadNextFromReader (reader)) {
60 if (reader.atEnd() || reader.hasError ()) {
65 if ((reader.tokenType() == QXmlStreamReader::EndElement) &
66 (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
71 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
72 (reader.name() == DOCUMENT_SERIALIZE_POINT)) {
75 QXmlStreamAttributes attributes = reader.attributes ();
77 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER) &&
78 attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL) &&
79 attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) &&
80 attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y)) {
82 m_identifiersAdded << attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
83 m_ordinals << attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
85 QPoint point (attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toInt(),
86 attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toInt());
93 reader.raiseError (QObject::tr (
"Cannot read graph points"));
97 CmdAddPointsGraph::~CmdAddPointsGraph ()
103 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointsGraph::cmdRedo";
107 for (
int index = 0; index < m_points.count(); index++) {
109 QString identifierAdded;
113 m_ordinals.at (index));
114 m_identifiersAdded.push_back (identifierAdded);
124 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddPointsGraph::cmdUndo";
134 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
135 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH);
136 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
137 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
139 for (
int index = 0; index < m_points.count(); index++) {
141 writer.writeStartElement (DOCUMENT_SERIALIZE_POINT);
142 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_points.at (index).x()));
143 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_points.at (index).y()));
146 if (index < m_identifiersAdded.count()) {
147 identifier = m_identifiersAdded.at (index);
150 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, identifier);
151 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinals.at (index)));
152 writer.writeEndElement();
154 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 saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
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...
CmdAddPointsGraph(MainWindow &mainWindow, Document &document, const QString &curveName, const QList< QPoint > &points, const QList< double > &ordinals)
Constructor for normal creation.
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.
Document & document()
Return the Document that this command will modify during redo and undo.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
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.