Engauge Digitizer 2
Loading...
Searching...
No Matches
CmdGuidelineMoveXT.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 "Document.h"
9#include "DocumentSerialize.h"
10#include "Logger.h"
11#include "MainWindow.h"
12#include "Xml.h"
13
14const QString CMD_DESCRIPTION ("GuidelineMoveXT");
15
17 Document &document,
18 const QString &identifier,
19 double valueBefore,
20 double valueAfter) :
21 CmdAbstract(mainWindow,
22 document,
24 m_identifier (identifier),
25 m_valueBefore (valueBefore),
26 m_valueAfter (valueAfter)
27{
28 LOG4CPP_INFO_S ((*mainCat)) << "CmdGuidelineMoveXT::CmdGuidelineMoveXT";
29}
30
32 Document &document,
33 const QString &cmdDescription,
34 QXmlStreamReader &reader) :
35 CmdAbstract (mainWindow,
36 document,
37 cmdDescription)
38{
39 LOG4CPP_INFO_S ((*mainCat)) << "CmdGuidelineMoveXT::CmdGuidelineMoveXT";
40
41 QXmlStreamAttributes attributes = reader.attributes();
42
43 if (!attributes.hasAttribute(DOCUMENT_SERIALIZE_IDENTIFIER) ||
44 !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_BEFORE) ||
45 !attributes.hasAttribute(DOCUMENT_SERIALIZE_GRAPH_AFTER)) {
46 xmlExitWithError (reader,
47 QString ("%1 %2 %3 %4 %5 %6")
48 .arg (QObject::tr ("Missing attribute(s)"))
50 .arg (QObject::tr (","))
52 .arg (QObject::tr ("and/or"))
54 }
55
56 m_identifier = attributes.value(DOCUMENT_SERIALIZE_IDENTIFIER).toString();
57 m_valueBefore = attributes.value(DOCUMENT_SERIALIZE_GRAPH_BEFORE).toDouble();
58 m_valueAfter = attributes.value(DOCUMENT_SERIALIZE_GRAPH_AFTER).toDouble();
59}
60
64
66{
67 LOG4CPP_INFO_S ((*mainCat)) << "CmdGuidelineMoveXT::cmdRedo"
68 << " identifier=" << m_identifier.toLatin1().data()
69 << " value=" << m_valueAfter;
70
71 mainWindow().guidelineMoveXT (m_identifier,
72 m_valueAfter);
73}
74
76{
77 LOG4CPP_INFO_S ((*mainCat)) << "CmdGuidelineMoveXT::cmdUndo"
78 << " identifier=" << m_identifier.toLatin1().data()
79 << " value=" << m_valueBefore;
80
81 mainWindow().guidelineMoveXT (m_identifier,
82 m_valueBefore);
83}
84
85void CmdGuidelineMoveXT::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_IDENTIFIER, m_identifier);
91 writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_BEFORE, QString::number (m_valueBefore));
92 writer.writeAttribute(DOCUMENT_SERIALIZE_GRAPH_AFTER, QString::number (m_valueAfter));
93 writer.writeEndElement();
94}
const QString CMD_DESCRIPTION("GuidelineMoveXT")
const QString DOCUMENT_SERIALIZE_IDENTIFIER
const QString DOCUMENT_SERIALIZE_GRAPH_AFTER
const QString DOCUMENT_SERIALIZE_GRAPH_BEFORE
const QString DOCUMENT_SERIALIZE_CMD_GUIDELINE_MOVE_X_T
const QString DOCUMENT_SERIALIZE_CMD
const QString DOCUMENT_SERIALIZE_CMD_TYPE
const QString DOCUMENT_SERIALIZE_CMD_DESCRIPTION
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
MainWindow & mainWindow()
Return the MainWindow so it can be updated by this command as a last step.
CmdGuidelineMoveXT(MainWindow &mainWindow, Document &document, const QString &identifier, double valueBefore, double valueAfter)
Constructor for normal creation.
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.
virtual void cmdUndo()
Undo method that is called when QUndoStack is moved one command backward.
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 guidelineMoveXT(const QString &identifier, double xTAfter)
Move a X/T Guideline.
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18