Engauge Digitizer  2
Public Member Functions | List of all members
CmdAddScale Class Reference

Command for adding one scale point. More...

#include <CmdAddScale.h>

Inheritance diagram for CmdAddScale:
Inheritance graph
Collaboration diagram for CmdAddScale:
Collaboration graph

Public Member Functions

 CmdAddScale (MainWindow &mainWindow, Document &document, const QPointF &posScreen0, const QPointF &posScreen1, double scaleLength, double ordinal0, double ordinal1)
 Constructor for normal creation. More...
 
 CmdAddScale (MainWindow &mainWindow, Document &document, const QString &cmdDescription, QXmlStreamReader &reader)
 Constructor for parsing error report file xml. More...
 
virtual ~CmdAddScale ()
 
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 scale point.

Definition at line 16 of file CmdAddScale.h.

Constructor & Destructor Documentation

◆ CmdAddScale() [1/2]

CmdAddScale::CmdAddScale ( MainWindow mainWindow,
Document document,
const QPointF &  posScreen0,
const QPointF &  posScreen1,
double  scaleLength,
double  ordinal0,
double  ordinal1 
)

Constructor for normal creation.

Definition at line 19 of file CmdAddScale.cpp.

25  :
27  document,
29  m_posScreen0 (posScreen0),
30  m_posScreen1 (posScreen1),
31  m_scaleLength (scaleLength),
32  m_ordinal0 (ordinal0),
33  m_ordinal1 (ordinal1)
34 {
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;
41 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
const QString CMD_DESCRIPTION("Add scale point")
QString QPointFToString(const QPointF &pos)
Definition: QtToString.cpp:17
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.
Definition: CmdAbstract.cpp:45
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

◆ CmdAddScale() [2/2]

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

Constructor for parsing error report file xml.

Definition at line 43 of file CmdAddScale.cpp.

46  :
48  document,
49  cmdDescription)
50 {
51  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddScale::CmdAddScale";
52 
53  QXmlStreamAttributes attributes = reader.attributes();
54 
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")
75  }
76 
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();
86 }
const QString DOCUMENT_SERIALIZE_SCREEN_Y1
#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.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
const QString DOCUMENT_SERIALIZE_IDENTIFIER1
const QString DOCUMENT_SERIALIZE_SCALE_LENGTH
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_SCREEN_X
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString DOCUMENT_SERIALIZE_ORDINAL1
void xmlExitWithError(QXmlStreamReader &reader, const QString &message)
Show specified message for an error while reading xml, then quit.
Definition: Xml.cpp:25
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
const QString DOCUMENT_SERIALIZE_SCREEN_X1

◆ ~CmdAddScale()

CmdAddScale::~CmdAddScale ( )
virtual

Definition at line 88 of file CmdAddScale.cpp.

89 {
90 }

Member Function Documentation

◆ cmdRedo()

void CmdAddScale::cmdRedo ( )
virtual

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

Implements CmdAbstract.

Definition at line 92 of file CmdAddScale.cpp.

93 {
94  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddScale::cmdRedo";
95 
99  m_posScreen1,
100  m_scaleLength,
101  m_identifierAdded0,
102  m_identifierAdded1,
103  m_ordinal0,
104  m_ordinal1);
105  document().updatePointOrdinals (mainWindow().transformation());
108 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
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.
Definition: Document.cpp:228
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.

◆ cmdUndo()

void CmdAddScale::cmdUndo ( )
virtual

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

Implements CmdAbstract.

Definition at line 110 of file CmdAddScale.cpp.

111 {
112  LOG4CPP_INFO_S ((*mainCat)) << "CmdAddScale::cmdUndo";
113 
118 }
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
void restoreDocumentState(Document &document) const
Restore the document previously saved by saveDocumentState.
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

◆ saveXml()

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

Save commands as xml for later uploading.

Implements CmdAbstract.

Definition at line 120 of file CmdAddScale.cpp.

121 {
122  // For time coordinates, many digits of precision are needed since a typical date is 1,246,870,000 = July 6, 2009
123  // and we want seconds of precision
124  const char FORMAT = 'g';
125  const int PRECISION = 16;
126 
127  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
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();
140 }
const QString DOCUMENT_SERIALIZE_CMD_ADD_SCALE
const QString DOCUMENT_SERIALIZE_SCREEN_Y1
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_IDENTIFIER1
const QString DOCUMENT_SERIALIZE_SCALE_LENGTH
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_SCREEN_X
const QString DOCUMENT_SERIALIZE_ORDINAL1
const QString DOCUMENT_SERIALIZE_SCREEN_X1
const QString DOCUMENT_SERIALIZE_CMD

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