Engauge Digitizer  2
CmdSettingsCoords.cpp
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 "CmdSettingsCoords.h"
8 #include "DocumentModelCoords.h"
9 #include "Document.h"
10 #include "DocumentSerialize.h"
11 #include "Logger.h"
12 #include "MainWindow.h"
13 #include <QXmlStreamReader>
14 #include "Xml.h"
15 
16 const QString CMD_DESCRIPTION ("Coordinate settings");
17 
19  Document &document,
20  const DocumentModelCoords &modelCoordsBefore,
21  const DocumentModelCoords &modelCoordsAfter) :
22  CmdAbstract(mainWindow,
23  document,
24  CMD_DESCRIPTION),
25  m_modelCoordsBefore (modelCoordsBefore),
26  m_modelCoordsAfter (modelCoordsAfter)
27 {
28  LOG4CPP_INFO_S ((*mainCat)) << "CmdSettingsCoords::CmdSettingsCoords";
29 }
30 
33  const QString &cmdDescription,
34  QXmlStreamReader &reader) :
35  CmdAbstract (mainWindow,
36  document,
37  cmdDescription)
38 {
39  LOG4CPP_INFO_S ((*mainCat)) << "CmdSettingsCoords::CmdSettingsCoords";
40 
41  bool success = true;
42 
43  // Read until end of this subtree
44  bool isBefore = true;
45  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
46  (reader.name() != DOCUMENT_SERIALIZE_CMD)){
47  loadNextFromReader(reader);
48  if (reader.atEnd()) {
49  xmlExitWithError (reader,
50  QString ("%1 %2")
51  .arg (QObject::tr ("Reached end of file before finding end element for"))
52  .arg (DOCUMENT_SERIALIZE_CMD));
53  success = false;
54  break;
55  }
56 
57  if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
58  (reader.name() == DOCUMENT_SERIALIZE_COORDS)) {
59 
60  if (isBefore) {
61 
62  m_modelCoordsBefore.loadXml (reader);
63  isBefore = false;
64 
65  } else {
66 
67  m_modelCoordsAfter.loadXml (reader);
68 
69  }
70  }
71  }
72 
73  if (!success) {
74  reader.raiseError ("Cannot read coordinates data settings");
75  }
76 }
77 
78 CmdSettingsCoords::~CmdSettingsCoords ()
79 {
80 }
81 
83 {
84  LOG4CPP_INFO_S ((*mainCat)) << "CmdSettingsCoords::cmdRedo";
85 
87  mainWindow().updateSettingsCoords(m_modelCoordsAfter);
90 }
91 
93 {
94  LOG4CPP_INFO_S ((*mainCat)) << "CmdSettingsCoords::cmdUndo";
95 
97  mainWindow().updateSettingsCoords(m_modelCoordsBefore);
100 }
101 
102 void CmdSettingsCoords::saveXml (QXmlStreamWriter &writer) const
103 {
104  writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
105  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_TYPE, DOCUMENT_SERIALIZE_CMD_SETTINGS_COORDS);
106  writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
107  m_modelCoordsBefore.saveXml(writer);
108  m_modelCoordsAfter.saveXml(writer);
109  writer.writeEndElement();
110 }
virtual void cmdRedo()
Redo method that is called when QUndoStack is moved one command forward.
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition: CmdAbstract.h:19
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
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.
CmdSettingsCoords(MainWindow &mainWindow, Document &document, const DocumentModelCoords &modelCoordsBefore, const DocumentModelCoords &modelCoordsAfter)
Constructor for normal creation.
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
Definition: CmdAbstract.cpp:45
Model for DlgSettingsCoords and CmdSettingsCoords.
void updateAfterCommand()
See GraphicsScene::updateAfterCommand.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
void updateSettingsCoords(const DocumentModelCoords &modelCoords)
Update with new coordinate properties.
Document & document()
Return the Document that this command will modify during redo and undo.
Definition: CmdAbstract.cpp:35
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:89