7 #include "CmdEditPointGraph.h" 9 #include "DocumentSerialize.h" 10 #include "EngaugeAssert.h" 12 #include "MainWindow.h" 13 #include <QTextStream> 14 #include "QtToString.h" 15 #include <QXmlStreamReader> 18 const QString CMD_DESCRIPTION (
"Edit curve points");
22 const QStringList &pointIdentifiers,
30 m_pointIdentifiers (pointIdentifiers),
36 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdEditPointGraph::CmdEditPointGraph point=" 37 << pointIdentifiers.join(
" ").toLatin1 ().data ()
38 <<
" x=" << (m_isX ? QString::number (x).toLatin1().data() :
"")
39 <<
" y=" << (m_isY ? QString::number (y).toLatin1().data() :
"");
44 const QString &cmdDescription,
45 QXmlStreamReader &reader) :
50 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdEditPointGraph::CmdEditPointGraph";
52 QXmlStreamAttributes attributes = reader.attributes();
54 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X) ||
55 !attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y) ||
56 !attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_X) ||
57 !attributes.hasAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_Y) ) {
58 xmlExitWithError (reader,
59 QString (
"%1 %2, %3, %4 %5 %6")
60 .arg (QObject::tr (
"Missing attribute(s)"))
61 .arg (DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X)
62 .arg (DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y)
63 .arg (DOCUMENT_SERIALIZE_EDIT_GRAPH_X)
64 .arg (QObject::tr (
"and/or"))
65 .arg (DOCUMENT_SERIALIZE_EDIT_GRAPH_Y));
69 QString isX = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X).toString();
70 QString isY = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y).toString();
72 m_isX = (isX == DOCUMENT_SERIALIZE_BOOL_TRUE);
73 m_isY = (isY == DOCUMENT_SERIALIZE_BOOL_TRUE);
74 m_x = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_X).toDouble();
75 m_y = attributes.value(DOCUMENT_SERIALIZE_EDIT_GRAPH_Y).toDouble();
78 while (loadNextFromReader (reader)) {
80 if (reader.atEnd() || reader.hasError ()) {
85 if ((reader.tokenType() == QXmlStreamReader::EndElement) &
86 (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
91 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
92 (reader.name() == DOCUMENT_SERIALIZE_POINT)) {
95 QXmlStreamAttributes attributes = reader.attributes ();
97 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER)) {
99 m_pointIdentifiers << attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
105 reader.raiseError (QObject::tr (
"Cannot read graph points"));
110 CmdEditPointGraph::~CmdEditPointGraph ()
116 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdEditPointGraph::cmdRedo";
133 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdEditPointGraph::cmdUndo";
143 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
144 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_EDIT_POINT_GRAPH);
145 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
146 writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_X, m_isX ?
147 DOCUMENT_SERIALIZE_BOOL_TRUE :
148 DOCUMENT_SERIALIZE_BOOL_FALSE);
149 writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_IS_Y, m_isY ?
150 DOCUMENT_SERIALIZE_BOOL_TRUE :
151 DOCUMENT_SERIALIZE_BOOL_FALSE);
152 writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_X, QString::number (m_x));
153 writer.writeAttribute(DOCUMENT_SERIALIZE_EDIT_GRAPH_Y, QString::number (m_y));
155 for (
int index = 0; index < m_pointIdentifiers.count(); index++) {
157 writer.writeStartElement (DOCUMENT_SERIALIZE_POINT);
158 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_pointIdentifiers.at (index));
159 writer.writeEndElement();
161 writer.writeEndElement();
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
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.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
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.
Document & document()
Return the Document that this command will modify during redo and undo.
void editPointGraph(bool isX, bool isY, double x, double y, const QStringList &identifiers, const Transformation &transformation)
Edit the graph coordinates of one or more graph points.
CmdEditPointGraph(MainWindow &mainWindow, Document &document, const QStringList &pointIdentifiers, bool isX, bool isY, double x, double y)
Constructor for normal creation.
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.