7 #include "CmdAddScale.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 scale point");
21 const QPointF &posScreen0,
22 const QPointF &posScreen1,
29 m_posScreen0 (posScreen0),
30 m_posScreen1 (posScreen1),
31 m_scaleLength (scaleLength),
32 m_ordinal0 (ordinal0),
35 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddScale::CmdAddScale" 36 <<
" posScreen0=" << QPointFToString (posScreen0).toLatin1 ().data ()
37 <<
" posScreen1=" << QPointFToString (posScreen1).toLatin1 ().data ()
38 <<
" scaleLength=" << scaleLength
39 <<
" ordinal0=" << ordinal0
40 <<
" ordinal1=" << ordinal1;
45 const QString &cmdDescription,
46 QXmlStreamReader &reader) :
51 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddScale::CmdAddScale";
53 QXmlStreamAttributes attributes = reader.attributes();
55 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X) ||
56 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y) ||
57 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_X1) ||
58 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCREEN_Y1) ||
59 !attributes.hasAttribute(DOCUMENT_SERIALIZE_SCALE_LENGTH) ||
60 !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER) ||
61 !attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER1) ||
62 !attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL) ||
63 !attributes.hasAttribute(DOCUMENT_SERIALIZE_ORDINAL1)) {
64 xmlExitWithError (reader,
65 QString (
"Missing attribute(s) %1, %2, %3, %4, %5, %6, %7, %8 and/or %9")
66 .arg (DOCUMENT_SERIALIZE_SCREEN_X)
67 .arg (DOCUMENT_SERIALIZE_SCREEN_Y)
68 .arg (DOCUMENT_SERIALIZE_SCREEN_X1)
69 .arg (DOCUMENT_SERIALIZE_SCREEN_Y1)
70 .arg (DOCUMENT_SERIALIZE_SCALE_LENGTH)
71 .arg (DOCUMENT_SERIALIZE_IDENTIFIER)
72 .arg (DOCUMENT_SERIALIZE_IDENTIFIER1)
73 .arg (DOCUMENT_SERIALIZE_ORDINAL)
74 .arg (DOCUMENT_SERIALIZE_ORDINAL1));
77 m_posScreen0.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toDouble());
78 m_posScreen0.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toDouble());
79 m_posScreen1.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X1).toDouble());
80 m_posScreen1.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y1).toDouble());
81 m_scaleLength = attributes.value(DOCUMENT_SERIALIZE_SCALE_LENGTH).toDouble();
82 m_identifierAdded0 = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
83 m_identifierAdded1 = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER1).toString();
84 m_ordinal0 = attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
85 m_ordinal1 = attributes.value(DOCUMENT_SERIALIZE_ORDINAL1).toDouble();
88 CmdAddScale::~CmdAddScale ()
94 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddScale::cmdRedo";
112 LOG4CPP_INFO_S ((*mainCat)) <<
"CmdAddScale::cmdUndo";
124 const char FORMAT =
'g';
125 const int PRECISION = 16;
127 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
128 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_ADD_SCALE);
129 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
130 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_posScreen0.x()));
131 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_posScreen0.y()));
132 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X1, QString::number (m_posScreen1.x()));
133 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y1, QString::number (m_posScreen1.y()));
134 writer.writeAttribute(DOCUMENT_SERIALIZE_SCALE_LENGTH, QString::number (m_scaleLength, FORMAT, PRECISION));
135 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_identifierAdded0);
136 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER1, m_identifierAdded1);
137 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinal0));
138 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL1, QString::number (m_ordinal1));
139 writer.writeEndElement();
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
void addScaleWithGeneratedIdentifier(const QPointF &posScreen0, const QPointF &posScreen1, double scaleLength, QString &identifier0, QString &identifier1, double ordinal0, double ordinal1)
Add scale with a generated point identifier.
void saveOrCheckPostCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
CmdAddScale(MainWindow &mainWindow, Document &document, const QPointF &posScreen0, const QPointF &posScreen1, double scaleLength, double ordinal0, double ordinal1)
Constructor for normal creation.
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 cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
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 saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
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.