Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdAddPointGraph.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "CmdAddPointGraph.h"
8#include "Document.h"
9#include "DocumentSerialize.h"
10#include "EngaugeAssert.h"
11#include "Logger.h"
12#include "MainWindow.h"
13#include <QStringList>
14#include "QtToString.h"
15#include <QXmlStreamReader>
16#include "Xml.h"
17
18const QString CMD_DESCRIPTION ("Add graph point");
19
22 const QString &curveName,
23 const QPointF &posScreen,
24 double ordinal) :
28 m_curveName (curveName),
29 m_posScreen (posScreen),
30 m_ordinal (ordinal)
31{
32 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph"
33 << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
34 << " ordinal=" << m_ordinal;
35}
36
39 const QString &cmdDescription,
40 QXmlStreamReader &reader) :
43 cmdDescription)
44{
45 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::CmdAddPointGraph";
46
47 QXmlStreamAttributes attributes = reader.attributes();
48
49 // Base attributes are handled by CmdPointChangeBase
50 QStringList requiredAttributesLeaf;
51 requiredAttributesLeaf << DOCUMENT_SERIALIZE_SCREEN_X
56 leafAttributes (attributes,
57 requiredAttributesLeaf,
58 reader);
59
60 m_posScreen.setX(attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toDouble());
61 m_posScreen.setY(attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toDouble());
62 m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
63 m_identifierAdded = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
64 m_ordinal = attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
65}
66
70
72{
73 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointGraph::cmdRedo";
74
75 restoreState ();
79 m_posScreen,
80 m_identifierAdded,
81 m_ordinal);
82 document().updatePointOrdinals (mainWindow().transformation());
84 selectAddedPointForMoving(m_identifierAdded);
86}
87
98
99void CmdAddPointGraph::saveXml (QXmlStreamWriter &writer) const
100{
101 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
103 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
104 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
105 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_posScreen.x()));
106 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_posScreen.y()));
107 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, m_identifierAdded);
108 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinal));
109 baseAttributes (writer);
110 writer.writeEndElement();
111}
const QString CMD_DESCRIPTION("Add axis point")
const QString CMD_DESCRIPTION("Add graph point")
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_CURVE_NAME
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINT_GRAPH
const QString DOCUMENT_SERIALIZE_SCREEN_Y
const QString DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_ORDINAL
const QString DOCUMENT_SERIALIZE_SCREEN_X
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
log4cpp::Category * mainCat
Definition Logger.cpp:14
QString QPointFToString(const QPointF &pos)
Document & document()
Return the Document that this command will modify during redo and undo.
void selectAddedPointForMoving(const QString &pointAdded)
Select point that was just added so it can be moved by the user next for convenience.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
void saveOrCheckPostCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void restoreState()
Before any other operations associated with a Cmd class are performed, this method is called to resto...
void leafAttributes(const QXmlStreamAttributes &attributes, const QStringList &requiredAttributesLeaf, QXmlStreamReader &reader)
Same as often-used leafAndBaseAttributes, except this is used in the special case where a class inher...
void saveOrCheckPreCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void baseAttributes(QXmlStreamWriter &writer) const
After writing leaf class attributes, this writes the base class atributes.
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.
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
void saveDocumentState(const Document &document)
Save the document state for restoration by restoreDocumentState.
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
CmdPointChangeBase(MainWindow &mainWindow, Document &document, const QString &cmdDescription)
Single constructor.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
Definition Document.cpp:201
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:95
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18