Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdSelectCoordSystem.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
8#include "DataKey.h"
9#include "Document.h"
10#include "DocumentSerialize.h"
11#include "EngaugeAssert.h"
12#include "Logger.h"
13#include "MainWindow.h"
14#include <QApplication>
15#include <QClipboard>
16#include <QTextStream>
17#include "QtToString.h"
18#include <QXmlStreamReader>
19#include "Xml.h"
20
21const QString CMD_DESCRIPTION ("Select Coordinate System");
22
24 Document &document,
25 CoordSystemIndex coordSystemIndex) :
26 CmdAbstract(mainWindow,
27 document,
29 m_coordSystemIndexBefore (document.coordSystemIndex()),
30 m_coordSystemIndexAfter (coordSystemIndex)
31{
32 LOG4CPP_INFO_S ((*mainCat)) << "CmdSelectCoordSystem::CmdSelectCoordSystem";
33}
34
36 Document &document,
37 const QString &cmdDescription,
38 QXmlStreamReader &reader) :
39 CmdAbstract (mainWindow,
40 document,
41 cmdDescription)
42{
43 LOG4CPP_INFO_S ((*mainCat)) << "CmdSelectCoordSystem::CmdSelectCoordSystem";
44
45 QXmlStreamAttributes attributes = reader.attributes();
46
47 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_AFTER) ||
48 !attributes.hasAttribute(DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_BEFORE)) {
49 xmlExitWithError (reader,
50 QString ("%1 %2 %3 %4")
51 .arg (QObject::tr ("Missing attribute(s)"))
53 .arg (QObject::tr ("and/or"))
55 }
56
57 m_coordSystemIndexAfter = attributes.value(DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_AFTER).toInt ();
58 m_coordSystemIndexBefore = attributes.value(DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_BEFORE).toInt ();
59}
60
64
66{
67 LOG4CPP_INFO_S ((*mainCat)) << "CmdSelectCoordSystem::cmdRedo"
68 << " index=" << m_coordSystemIndexBefore << "->" << m_coordSystemIndexAfter;
69
71 mainWindow().updateCoordSystem (m_coordSystemIndexAfter);
73}
74
76{
77 LOG4CPP_INFO_S ((*mainCat)) << "CmdSelectCoordSystem::cmdUndo"
78 << " index=" << m_coordSystemIndexAfter << "->" << m_coordSystemIndexBefore;
79
81 mainWindow().updateCoordSystem (m_coordSystemIndexBefore);
83}
84
85void CmdSelectCoordSystem::saveXml (QXmlStreamWriter &writer) const
86{
87 writer.writeStartElement(DOCUMENT_SERIALIZE_CMD);
89 writer.writeAttribute(DOCUMENT_SERIALIZE_CMD_DESCRIPTION, QUndoCommand::text ());
90 writer.writeAttribute(DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_BEFORE, QString::number (m_coordSystemIndexBefore));
91 writer.writeAttribute(DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_AFTER, QString::number (m_coordSystemIndexAfter));
92 writer.writeEndElement();
93}
const QString CMD_DESCRIPTION("Select Coordinate System")
unsigned int CoordSystemIndex
Zero-based index for identifying CoordSystem instantiations.
const QString DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_BEFORE
const QString DOCUMENT_SERIALIZE_COORD_SYSTEM_INDEX_AFTER
const QString DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
const QString DOCUMENT_SERIALIZE_CMD_SELECT_COORD_SYSTEM
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
Wrapper around QUndoCommand. This simplifies the more complicated feature set of QUndoCommand.
Definition CmdAbstract.h:20
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.
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.
CmdSelectCoordSystem(MainWindow &mainWindow, Document &document, CoordSystemIndex coordSystem)
Constructor for normal creation.
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.
virtual void saveXml(QXmlStreamWriter &writer) const
Save commands as xml for later uploading.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition MainWindow.h:96
void updateCoordSystem(CoordSystemIndex coordSystemIndex)
Select a different CoordSystem.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18