Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdAddPointsGraph Class Reference

Command for adding one or more graph points. This is for Segment Fill mode. More...

#include <CmdAddPointsGraph.h>

Inheritance diagram for CmdAddPointsGraph:
Inheritance graph
Collaboration diagram for CmdAddPointsGraph:
Collaboration graph

Public Member Functions

 CmdAddPointsGraph (MainWindow &mainWindow, Document &document, const QString &curveName, const QList< QPoint > &points, const QList< double > &ordinals)
 Constructor for normal creation.
 CmdAddPointsGraph (MainWindow &mainWindow, Document &document, const QString &cmdDescription, QXmlStreamReader &reader)
 Constructor for parsing error report file xml.
virtual ~CmdAddPointsGraph ()
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.
virtual void saveXml (QXmlStreamWriter &writer) const
 Save commands as xml for later uploading.
Public Member Functions inherited from CmdPointChangeBase
 CmdPointChangeBase (MainWindow &mainWindow, Document &document, const QString &cmdDescription)
 Single constructor.
virtual ~CmdPointChangeBase ()
Public Member Functions inherited from CmdAbstract
 CmdAbstract (MainWindow &mainWindow, Document &document, const QString &cmdDescription)
 Single constructor.
virtual ~CmdAbstract ()

Additional Inherited Members

Protected Member Functions inherited from CmdPointChangeBase
void restoreDocumentState (Document &document) const
 Restore the document previously saved by saveDocumentState.
void saveDocumentState (const Document &document)
 Save the document state for restoration by restoreDocumentState.
Protected Member Functions inherited from CmdAbstract
void baseAttributes (QXmlStreamWriter &writer) const
 After writing leaf class attributes, this writes the base class atributes.
Documentdocument ()
 Return the Document that this command will modify during redo and undo.
const Documentdocument () const
 Return a const copy of the Document for non redo/undo interaction.
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 inherits from another class (e.g.
void leafAndBaseAttributes (const QXmlStreamAttributes &attributes, const QStringList &requiredAttributesLeaf, QXmlStreamReader &reader)
 Before reading leaf class attributes, check all required attributes from leaf and this base class are included, then extract the parent class attributes.
MainWindowmainWindow ()
 Return the MainWindow so it can be updated by this command as a last step.
void resetSelection (const PointIdentifiers &pointIdentifiersToSelect)
 Call this (for consistency) after writing leaf class attributes, to write the base class attributes.
void restoreState ()
 Before any other operations associated with a Cmd class are performed, this method is called to restore original states to all relevant state machines.
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.
void selectAddedPointForMoving (const QString &pointAdded)
 Select point that was just added so it can be moved by the user next for convenience.
void selectAddedPointsForMoving (const QStringList &pointsAdded)
 Select points that were just added so they can be moved by the user next for convenience.

Detailed Description

Command for adding one or more graph points. This is for Segment Fill mode.

Definition at line 19 of file CmdAddPointsGraph.h.

Constructor & Destructor Documentation

◆ CmdAddPointsGraph() [1/2]

CmdAddPointsGraph::CmdAddPointsGraph ( MainWindow & mainWindow,
Document & document,
const QString & curveName,
const QList< QPoint > & points,
const QList< double > & ordinals )

Constructor for normal creation.

Definition at line 22 of file CmdAddPointsGraph.cpp.

26 :
30 m_curveName (curveName),
31 m_points (points),
32 m_ordinals (ordinals)
33{
34 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::CmdAddPointsGraph";
35}
const QString CMD_DESCRIPTION("Add axis point")
log4cpp::Category * mainCat
Definition Logger.cpp:14
Document & document()
Return the Document that this command will modify during redo and undo.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
CmdPointChangeBase(MainWindow &mainWindow, Document &document, const QString &cmdDescription)
Single constructor.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18

◆ CmdAddPointsGraph() [2/2]

CmdAddPointsGraph::CmdAddPointsGraph ( MainWindow & mainWindow,
Document & document,
const QString & cmdDescription,
QXmlStreamReader & reader )

Constructor for parsing error report file xml.

Definition at line 37 of file CmdAddPointsGraph.cpp.

40 :
43 cmdDescription)
44{
45 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::CmdAddPointsGraph";
46
47 QXmlStreamAttributes attributes = reader.attributes();
48
49 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME)) {
50 xmlExitWithError (reader,
51 QString ("%1 %2")
52 .arg (QObject::tr ("Missing attribute"))
54 }
55
56 m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
57
58 bool success = true;
59 while (loadNextFromReader (reader)) {
60
61 if (reader.atEnd() || reader.hasError ()) {
62 success = false;
63 break;
64 }
65
66 if ((reader.tokenType() == QXmlStreamReader::EndElement) &
67 (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
68 break;
69 }
70
71 // Not done yet
72 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
73 (reader.name() == DOCUMENT_SERIALIZE_POINT)) {
74
75 // This is an entry that we need to add
76 QXmlStreamAttributes attributes = reader.attributes ();
77
78 QStringList requiredAttributesLeaf;
79 requiredAttributesLeaf << DOCUMENT_SERIALIZE_IDENTIFIER
83 leafAttributes (attributes,
84 requiredAttributesLeaf,
85 reader);
86
87 m_identifiersAdded << attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
88 m_ordinals << attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
89
90 QPoint point (attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toInt(),
91 attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toInt());
92 m_points << point;
93 }
94 }
95
96 if (!success) {
97 reader.raiseError (QObject::tr ("Cannot read graph points"));
98 }
99}
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_CURVE_NAME
const QString DOCUMENT_SERIALIZE_SCREEN_Y
const QString DOCUMENT_SERIALIZE_POINT
const QString DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_ORDINAL
const QString DOCUMENT_SERIALIZE_SCREEN_X
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
void xmlExitWithError(QXmlStreamReader &reader, const QString &message)
Show specified message for an error while reading xml, then quit.
Definition Xml.cpp:25
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...

◆ ~CmdAddPointsGraph()

CmdAddPointsGraph::~CmdAddPointsGraph ( )
virtual

Definition at line 101 of file CmdAddPointsGraph.cpp.

102{
103}

Member Function Documentation

◆ cmdRedo()

void CmdAddPointsGraph::cmdRedo ( )
virtual

Redo method that is called when QUndoStack is moved one command forward.

Implements CmdAbstract.

Definition at line 105 of file CmdAddPointsGraph.cpp.

106{
107 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::cmdRedo";
108
109 restoreState ();
112
113 int index;
114 for (index = 0; index < m_points.count(); index++) {
115
116 QString identifierAdded;
118 m_points.at (index),
119 identifierAdded,
120 m_ordinals.at (index));
121 m_identifiersAdded.push_back (identifierAdded);
122 }
123
124 document().updatePointOrdinals (mainWindow().transformation());
126 selectAddedPointsForMoving(m_identifiersAdded);
128}
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 saveOrCheckPreCommandDocumentStateHash(const Document &document)
Save, when called the first time, a hash value representing the state of the Document.
void selectAddedPointsForMoving(const QStringList &pointsAdded)
Select points that were just added so they can be moved by the user next for convenience.
void saveDocumentState(const Document &document)
Save the document state for restoration by restoreDocumentState.
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
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.

◆ cmdUndo()

void CmdAddPointsGraph::cmdUndo ( )
virtual

Undo method that is called when QUndoStack is moved one command backward.

Implements CmdAbstract.

Definition at line 130 of file CmdAddPointsGraph.cpp.

131{
132 LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::cmdUndo";
133
134 restoreState ();
139}
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.

◆ saveXml()

void CmdAddPointsGraph::saveXml ( QXmlStreamWriter & writer) const
virtual

Save commands as xml for later uploading.

Implements CmdAbstract.

Definition at line 141 of file CmdAddPointsGraph.cpp.

142{
143 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
145 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
146 writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
147
148 for (int index = 0; index < m_points.count(); index++) {
149
150 writer.writeStartElement (DOCUMENT_SERIALIZE_POINT);
151 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_X, QString::number (m_points.at (index).x()));
152 writer.writeAttribute(DOCUMENT_SERIALIZE_SCREEN_Y, QString::number (m_points.at (index).y()));
153
154 QString identifier;
155 if (index < m_identifiersAdded.count()) {
156 identifier = m_identifiersAdded.at (index);
157 }
158
159 writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, identifier);
160 writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinals.at (index)));
161 writer.writeEndElement();
162 }
163 baseAttributes (writer);
164 writer.writeEndElement();
165}
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
void baseAttributes(QXmlStreamWriter &writer) const
After writing leaf class attributes, this writes the base class atributes.

The documentation for this class was generated from the following files: