Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DocumentModelDigitizeCurve.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 
7 #include "CmdMediator.h"
9 #include "DocumentSerialize.h"
10 #include "Logger.h"
11 #include <QObject>
12 #include <QTextStream>
13 #include <QXmlStreamWriter>
14 #include "Xml.h"
15 
20 
22  m_cursorStandardCross (DEFAULT_CURSOR_STANDARD_CROSS),
23  m_cursorInnerRadius (DEFAULT_CURSOR_INNER_RADIUS),
24  m_cursorLineWidth (DEFAULT_CURSOR_LINE_WIDTH),
25  m_cursorSize (DEFAULT_CURSOR_SIZE)
26 {
27 }
28 
30  m_cursorStandardCross (document.modelDigitizeCurve().cursorStandardCross()),
31  m_cursorInnerRadius (document.modelDigitizeCurve().cursorInnerRadius()),
32  m_cursorLineWidth (document.modelDigitizeCurve().cursorLineWidth()),
33  m_cursorSize (document.modelDigitizeCurve().cursorSize())
34 {
35 }
36 
38  m_cursorStandardCross (other.cursorStandardCross()),
39  m_cursorInnerRadius (other.cursorInnerRadius()),
40  m_cursorLineWidth (other.cursorLineWidth()),
41  m_cursorSize (other.cursorSize ())
42 {
43 }
44 
46 {
47  m_cursorStandardCross = other.cursorStandardCross();
48  m_cursorInnerRadius = other.cursorInnerRadius();
49  m_cursorLineWidth = other.cursorLineWidth();
50  m_cursorSize = other.cursorSize ();
51 
52  return *this;
53 }
54 
56 {
57  return m_cursorInnerRadius;
58 }
59 
61 {
62  return m_cursorLineWidth;
63 }
64 
66 {
67  return m_cursorSize;
68 }
69 
71 {
72  return m_cursorStandardCross;
73 }
74 
75 void DocumentModelDigitizeCurve::loadXml(QXmlStreamReader &reader)
76 {
77  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelDigitizeCurve::loadXml";
78 
79  bool success = true;
80 
81  QXmlStreamAttributes attributes = reader.attributes();
82 
83  if (attributes.hasAttribute(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_INNER_RADIUS) &&
84  attributes.hasAttribute(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_LINE_WIDTH) &&
85  attributes.hasAttribute(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_SIZE) &&
87 
88  // Boolean values
89  QString standardCrossValue = attributes.value(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_STANDARD_CROSS).toString();
90 
93  setCursorSize (static_cast<CursorSize> (attributes.value(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_SIZE).toInt()));
95 
96  // Read until end of this subtree
97  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
98  (reader.name() != DOCUMENT_SERIALIZE_DIGITIZE_CURVE)){
99  loadNextFromReader(reader);
100  if (reader.atEnd()) {
101  success = false;
102  break;
103  }
104  }
105  }
106 
107  if (!success) {
108  reader.raiseError (QObject::tr ("Cannot read digitize curve data"));
109  }
110 }
111 
113  QTextStream &str) const
114 {
115  str << indentation << "DocumentModelDigitizeCurve\n";
116 
117  indentation += INDENTATION_DELTA;
118 
119  str << indentation << "cursorStandardCross=" << (m_cursorStandardCross ? "true" : "false") << "\n";
120  str << indentation << "cursorInnerRadius=" << m_cursorInnerRadius << "\n";
121  str << indentation << "cursorSize=" << m_cursorSize << "\n";
122  str << indentation << "cursorLineWidth=" << m_cursorLineWidth << "\n";
123 }
124 
125 void DocumentModelDigitizeCurve::saveXml(QXmlStreamWriter &writer) const
126 {
127  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelDigitizeCurve::saveXml";
128 
129  writer.writeStartElement(DOCUMENT_SERIALIZE_DIGITIZE_CURVE);
130  writer.writeAttribute(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_INNER_RADIUS, QString::number (m_cursorInnerRadius));
131  writer.writeAttribute(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_LINE_WIDTH, QString::number (m_cursorLineWidth));
132  writer.writeAttribute(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_SIZE, QString::number (m_cursorSize));
133  writer.writeAttribute(DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_STANDARD_CROSS, m_cursorStandardCross ?
136  writer.writeEndElement();
137 }
138 
140 {
141  m_cursorInnerRadius = cursorInnerRadius;
142 }
143 
145 {
146  m_cursorLineWidth = cursorLineWidth;
147 }
148 
150 {
151  m_cursorSize = cursorSize;
152 }
153 
155 {
156  m_cursorStandardCross = cursorStandardCross;
157 }
int cursorLineWidth() const
Get method for cursor line width.
const QString DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_LINE_WIDTH
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition: Xml.cpp:14
const QString INDENTATION_DELTA
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void setCursorLineWidth(int lineWidth)
Set method for cursor line width.
#define LOG4CPP_INFO_S(logger)
Definition: convenience.h:18
bool cursorStandardCross() const
Get method for cursor type.
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const int DEFAULT_CURSOR_LINE_WIDTH
CursorSize
Custom cursor sizes supported on all platforms for the most part, according to QCursor documentation...
Definition: CursorSize.h:11
void setCursorSize(CursorSize cursorSize)
Set method for cursor size.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
const QString DOCUMENT_SERIALIZE_DIGITIZE_CURVE
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
const bool DEFAULT_CURSOR_STANDARD_CROSS
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
const QString DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_STANDARD_CROSS
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
int cursorInnerRadius() const
Get method for cursor inner radius.
void setCursorInnerRadius(int innerRadius)
Set method for cursor inner radius.
Storage of one imported image and the data attached to that image.
Definition: Document.h:41
log4cpp::Category * mainCat
Definition: Logger.cpp:14
const QString DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_SIZE
CursorSize cursorSize() const
Get method for cursor size.
const int DEFAULT_CURSOR_INNER_RADIUS
DocumentModelDigitizeCurve & operator=(const DocumentModelDigitizeCurve &other)
Assignment constructor.
const CursorSize DEFAULT_CURSOR_SIZE
DocumentModelDigitizeCurve()
Default constructor.
void setCursorStandardCross(bool cursorStandardCross)
Set method for cursor type.
const QString DOCUMENT_SERIALIZE_DIGITIZE_CURVE_CURSOR_INNER_RADIUS