Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
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. More...
 
 CmdAddPointsGraph (MainWindow &mainWindow, Document &document, const QString &cmdDescription, QXmlStreamReader &reader)
 Constructor for parsing error report file xml. More...
 
virtual ~CmdAddPointsGraph ()
 
virtual void cmdRedo ()
 Redo method that is called when QUndoStack is moved one command forward. More...
 
virtual void cmdUndo ()
 Undo method that is called when QUndoStack is moved one command backward. More...
 
virtual void saveXml (QXmlStreamWriter &writer) const
 Save commands as xml for later uploading. More...
 
- Public Member Functions inherited from CmdPointChangeBase
 CmdPointChangeBase (MainWindow &mainWindow, Document &document, const QString &cmdDescription)
 Single constructor. More...
 
virtual ~CmdPointChangeBase ()
 
- Public Member Functions inherited from CmdAbstract
 CmdAbstract (MainWindow &mainWindow, Document &document, const QString &cmdDescription)
 Single constructor. More...
 
virtual ~CmdAbstract ()
 

Additional Inherited Members

- Protected Member Functions inherited from CmdPointChangeBase
void restoreDocumentState (Document &document) const
 Restore the document previously saved by saveDocumentState. More...
 
void saveDocumentState (const Document &document)
 Save the document state for restoration by restoreDocumentState. More...
 
- Protected Member Functions inherited from CmdAbstract
Documentdocument ()
 Return the Document that this command will modify during redo and undo. More...
 
const Documentdocument () const
 Return a const copy of the Document for non redo/undo interaction. More...
 
MainWindowmainWindow ()
 Return the MainWindow so it can be updated by this command as a last step. More...
 
void resetSelection (const PointIdentifiers &pointIdentifiersToSelect)
 Since the set of selected points has probably changed, changed that set back to the specified set. More...
 
void saveOrCheckPostCommandDocumentStateHash (const Document &document)
 Save, when called the first time, a hash value representing the state of the Document. More...
 
void saveOrCheckPreCommandDocumentStateHash (const Document &document)
 Save, when called the first time, a hash value representing the state of the Document. More...
 

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::CmdAddPointsGraph ( MainWindow mainWindow,
Document document,
const QString &  curveName,
const QList< QPoint > &  points,
const QList< double > &  ordinals 
)

Constructor for normal creation.

Definition at line 21 of file CmdAddPointsGraph.cpp.

25  :
26  CmdPointChangeBase (mainWindow,
27  document,
29  m_curveName (curveName),
30  m_points (points),
31  m_ordinals (ordinals)
32 {
33  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::CmdAddPointsGraph";
34 }
const QString CMD_DESCRIPTION("Add axis point")
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
Base class for CmdBase leaf subclasses that involve point additions, deletions and/or modifications...
log4cpp::Category * mainCat
Definition: Logger.cpp:14
CmdAddPointsGraph::CmdAddPointsGraph ( MainWindow mainWindow,
Document document,
const QString &  cmdDescription,
QXmlStreamReader &  reader 
)

Constructor for parsing error report file xml.

Definition at line 36 of file CmdAddPointsGraph.cpp.

39  :
40  CmdPointChangeBase (mainWindow,
41  document,
42  cmdDescription)
43 {
44  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::CmdAddPointsGraph";
45 
46  QXmlStreamAttributes attributes = reader.attributes();
47 
48  if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_CURVE_NAME)) {
49  xmlExitWithError (reader,
50  QString ("%1 %2")
51  .arg (QObject::tr ("Missing attribute"))
53  }
54 
55  m_curveName = attributes.value(DOCUMENT_SERIALIZE_CURVE_NAME).toString();
56 
57  bool success = true;
58  while (loadNextFromReader (reader)) {
59 
60  if (reader.atEnd() || reader.hasError ()) {
61  success = false;
62  break;
63  }
64 
65  if ((reader.tokenType() == QXmlStreamReader::EndElement) &
66  (reader.name() == DOCUMENT_SERIALIZE_CMD)) {
67  break;
68  }
69 
70  // Not done yet
71  if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
72  (reader.name() == DOCUMENT_SERIALIZE_POINT)) {
73 
74  // This is an entry that we need to add
75  QXmlStreamAttributes attributes = reader.attributes ();
76 
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)) {
81 
82  m_identifiersAdded << attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
83  m_ordinals << attributes.value(DOCUMENT_SERIALIZE_ORDINAL).toDouble();
84 
85  QPoint point (attributes.value(DOCUMENT_SERIALIZE_SCREEN_X).toInt(),
86  attributes.value(DOCUMENT_SERIALIZE_SCREEN_Y).toInt());
87  m_points << point;
88  }
89  }
90  }
91 
92  if (!success) {
93  reader.raiseError (QObject::tr ("Cannot read graph points"));
94  }
95 }
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition: Xml.cpp:14
const QString DOCUMENT_SERIALIZE_POINT
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
const QString DOCUMENT_SERIALIZE_SCREEN_Y
const QString DOCUMENT_SERIALIZE_ORDINAL
Base class for CmdBase leaf subclasses that involve point additions, deletions and/or modifications...
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_SCREEN_X
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void xmlExitWithError(QXmlStreamReader &reader, const QString &message)
Show specified message for an error while reading xml, then quit.
Definition: Xml.cpp:25
const QString DOCUMENT_SERIALIZE_CURVE_NAME
const QString DOCUMENT_SERIALIZE_CMD
CmdAddPointsGraph::~CmdAddPointsGraph ( )
virtual

Definition at line 97 of file CmdAddPointsGraph.cpp.

98 {
99 }

Member Function Documentation

void CmdAddPointsGraph::cmdRedo ( )
virtual

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

Implements CmdAbstract.

Definition at line 101 of file CmdAddPointsGraph.cpp.

102 {
103  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::cmdRedo";
104 
107  for (int index = 0; index < m_points.count(); index++) {
108 
109  QString identifierAdded;
111  m_points.at (index),
112  identifierAdded,
113  m_ordinals.at (index));
114  m_identifiersAdded.push_back (identifierAdded);
115  }
116 
117  document().updatePointOrdinals (mainWindow().transformation());
120 }
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:195
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
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.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:1066
void saveDocumentState(const Document &document)
Save the document state for restoration by restoreDocumentState.
void CmdAddPointsGraph::cmdUndo ( )
virtual

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

Implements CmdAbstract.

Definition at line 122 of file CmdAddPointsGraph.cpp.

123 {
124  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddPointsGraph::cmdUndo";
125 
130 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
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.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
log4cpp::Category * mainCat
Definition: Logger.cpp:14
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
void CmdAddPointsGraph::saveXml ( QXmlStreamWriter &  writer) const
virtual

Save commands as xml for later uploading.

Implements CmdAbstract.

Definition at line 132 of file CmdAddPointsGraph.cpp.

133 {
134  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
136  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
137  writer.writeAttribute(DOCUMENT_SERIALIZE_CURVE_NAME, m_curveName);
138 
139  for (int index = 0; index < m_points.count(); index++) {
140 
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()));
144 
145  QString identifier;
146  if (index < m_identifiersAdded.count()) {
147  identifier = m_identifiersAdded.at (index);
148  }
149 
150  writer.writeAttribute(DOCUMENT_SERIALIZE_IDENTIFIER, identifier);
151  writer.writeAttribute(DOCUMENT_SERIALIZE_ORDINAL, QString::number (m_ordinals.at (index)));
152  writer.writeEndElement();
153  }
154  writer.writeEndElement();
155 }
const QString DOCUMENT_SERIALIZE_POINT
const QString DOCUMENT_SERIALIZE_SCREEN_Y
const QString DOCUMENT_SERIALIZE_ORDINAL
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
const QString DOCUMENT_SERIALIZE_CMD_ADD_POINTS_GRAPH
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_SCREEN_X
const QString DOCUMENT_SERIALIZE_CURVE_NAME
const QString DOCUMENT_SERIALIZE_CMD

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