Engauge Digitizer 2
Loading...
Searching...
No Matches
DocumentModelGridDisplay.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 "EngaugeAssert.h"
11#include "Logger.h"
12#include <QObject>
13#include <QTextStream>
14#include "QtToString.h"
15#include <QXmlStreamWriter>
16#include "Xml.h"
17
19const int DEFAULT_LINE_WIDTH = 1;
20
22 m_stable (false),
23 m_disableX (GRID_COORD_DISABLE_COUNT),
24 m_countX (2),
25 m_startX (0.0),
26 m_stepX (1.0),
27 m_stopX (1.0),
28 m_disableY (GRID_COORD_DISABLE_COUNT),
29 m_countY (2),
30 m_startY (0.0),
31 m_stepY (1.0),
32 m_stopY (1.0),
33 m_paletteColor (DEFAULT_COLOR),
34 m_lineWidth (DEFAULT_LINE_WIDTH)
35{
36}
37
39 m_stable (document.modelGridDisplay().stable()),
40 m_disableX (document.modelGridDisplay().disableX()),
41 m_countX (document.modelGridDisplay().countX()),
42 m_startX (document.modelGridDisplay().startX()),
43 m_stepX (document.modelGridDisplay().stepX()),
44 m_stopX (document.modelGridDisplay().stopX()),
45 m_disableY (document.modelGridDisplay().disableY()),
46 m_countY (document.modelGridDisplay().countY()),
47 m_startY (document.modelGridDisplay().startY()),
48 m_stepY (document.modelGridDisplay().stepY()),
49 m_stopY (document.modelGridDisplay().stopY()),
50 m_paletteColor (document.modelGridDisplay().paletteColor()),
51 m_lineWidth (document.modelGridDisplay().lineWidth())
52{
53}
54
56 m_stable(other.stable()),
57 m_disableX (other.disableX()),
58 m_countX (other.countX()),
59 m_startX (other.startX()),
60 m_stepX (other.stepX()),
61 m_stopX (other.stopX()),
62 m_disableY (other.disableY()),
63 m_countY (other.countY()),
64 m_startY (other.startY()),
65 m_stepY (other.stepY()),
66 m_stopY (other.stopY()),
67 m_paletteColor (other.paletteColor()),
68 m_lineWidth (other.lineWidth())
69{
70}
71
73{
74 m_stable = other.stable();
75 m_disableX = other.disableX();
76 m_countX = other.countX();
77 m_startX = other.startX();
78 m_stepX = other.stepX();
79 m_stopX = other.stopX();
80 m_disableY = other.disableY();
81 m_countY = other.countY();
82 m_startY = other.startY();
83 m_stepY = other.stepY();
84 m_stopY = other.stopY();
85 m_paletteColor = other.paletteColor();
86 m_lineWidth = other.lineWidth();
87
88 return *this;
89}
90
92{
93 return m_countX;
94}
95
97{
98 return m_countY;
99}
100
102{
103 return m_disableX;
104}
105
107{
108 return m_disableY;
109}
110
112{
113 return m_lineWidth;
114}
115
116void DocumentModelGridDisplay::loadXml(QXmlStreamReader &reader)
117{
118 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridDisplay::loadXml";
119
120 bool success = true;
121
122 QXmlStreamAttributes attributes = reader.attributes();
123
124 // Line width is optional
125 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STABLE) &&
126 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_X) &&
127 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_X) &&
128 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_X) &&
129 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_X) &&
130 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_X) &&
131 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_Y) &&
132 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_Y) &&
133 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_Y) &&
134 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_Y) &&
135 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_Y) &&
136 attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR)) {
137
138 // Boolean values
139 QString stableValue = attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STABLE).toString();
140
142 setDisableX (static_cast<GridCoordDisable> (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_X).toInt()));
143 setCountX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_X).toUInt());
144 setStartX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_X).toDouble());
145 setStepX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_X).toDouble());
146 setStopX (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_X).toDouble());
147 setDisableY (static_cast<GridCoordDisable> (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_Y).toUInt()));
148 setCountY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_Y).toUInt());
149 setStartY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_Y).toDouble());
150 setStepY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_Y).toDouble());
151 setStopY (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_Y).toDouble());
152 setPaletteColor (static_cast<ColorPalette> (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR).toInt()));
153
154 // Optional values
155 if (attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_LINE_WIDTH)) {
156 setLineWidth (attributes.value(DOCUMENT_SERIALIZE_GRID_DISPLAY_LINE_WIDTH).toUInt());
157 } else {
159 }
160
161 // Read until end of this subtree
162 while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
163 (reader.name() != DOCUMENT_SERIALIZE_GRID_DISPLAY)){
164 loadNextFromReader(reader);
165 if (reader.atEnd()) {
166 success = false;
167 break;
168 }
169 }
170 }
171
172 if (!success) {
173 reader.raiseError (QObject::tr ("Cannot read grid display data"));
174 }
175}
176
178{
179 return m_paletteColor;
180}
181
183 QTextStream &str) const
184{
185 str << indentation << "DocumentModelGridDisplay\n";
186
187 indentation += INDENTATION_DELTA;
188
189 str << indentation << "stable=" << (m_stable ? "true" : "false") << "\n";
190 str << indentation << "disableX=" << m_disableX << "\n";
191 str << indentation << "countX=" << m_countX << "\n";
192 str << indentation << "startX=" << m_startX << "\n";
193 str << indentation << "stepX=" << m_stepX << "\n";
194 str << indentation << "stopX=" << m_stopX << "\n";
195 str << indentation << "disableY=" << m_disableY << "\n";
196 str << indentation << "countY=" << m_countY << "\n";
197 str << indentation << "startY=" << m_startY << "\n";
198 str << indentation << "stepY=" << m_stepY << "\n";
199 str << indentation << "stopY=" << m_stopY << "\n";
200 str << indentation << "color=" << colorPaletteToString (m_paletteColor) << "\n";
201 str << indentation << "lineWidth=" << m_lineWidth << "\n";
202}
203
204void DocumentModelGridDisplay::saveXml(QXmlStreamWriter &writer) const
205{
206 LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridDisplay::saveXml";
207
208 writer.writeStartElement(DOCUMENT_SERIALIZE_GRID_DISPLAY);
209 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STABLE, m_stable ?
212 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_X, QString::number (m_disableX));
213 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_X, QString::number (m_countX));
214 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_X, QString::number (m_startX));
215 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_X, QString::number (m_stepX));
216 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_X, QString::number (m_stopX));
217 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_Y, QString::number (m_disableY));
218 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_Y, QString::number (m_countY));
219 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_START_Y, QString::number (m_startY));
220 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_Y, QString::number (m_stepY));
221 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_Y, QString::number (m_stopY));
222 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR, QString::number (m_paletteColor));
223 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR_STRING, colorPaletteToString (m_paletteColor));
224 writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_DISPLAY_LINE_WIDTH, QString::number (m_lineWidth));
225 writer.writeEndElement();
226}
227
229{
230 m_countX = countX;
231}
232
234{
235 m_countY = countY;
236}
237
242
247
249{
250 m_lineWidth = lineWidth;
251}
252
257
259{
260 m_stable = stable;
261}
262
264{
265 m_startX = startX;
266}
267
269{
270 m_startY = startY;
271}
272
274{
275 m_stepX = stepX;
276}
277
279{
280 m_stepY = stepY;
281}
282
284{
285 m_stopX = stopX;
286}
287
289{
290 m_stopY = stopY;
291}
292
294{
295 return m_stable;
296}
297
299{
300 return m_startX;
301}
302
304{
305 return m_startY;
306}
307
309{
310 return m_stepX;
311}
312
314{
315 return m_stepY;
316}
317
319{
320 return m_stopX;
321}
322
324{
325 return m_stopY;
326}
QString colorPaletteToString(ColorPalette colorPalette)
ColorPalette
@ COLOR_PALETTE_BLACK
const ColorPalette DEFAULT_COLOR
const int DEFAULT_LINE_WIDTH
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_LINE_WIDTH
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_Y
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_Y
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_STABLE
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_START_Y
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_Y
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_COUNT_X
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_Y
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_STEP_X
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_STOP_X
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_START_X
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_COLOR_STRING
const QString DOCUMENT_SERIALIZE_GRID_DISPLAY_DISABLE_X
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
GridCoordDisable
@ GRID_COORD_DISABLE_COUNT
log4cpp::Category * mainCat
Definition Logger.cpp:14
const QString INDENTATION_DELTA
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
GridCoordDisable disableY() const
Get method for y grid line disabled variable.
unsigned int countX() const
Get method for x grid line count.
void setPaletteColor(ColorPalette paletteColor)
Set method for color.
double startX() const
Get method for x grid line lower bound (inclusive).
GridCoordDisable disableX() const
Get method for x grid line disabled variable.
unsigned int countY() const
Get method for y grid line count.
double stepX() const
Get method for x grid line increment.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
DocumentModelGridDisplay & operator=(const DocumentModelGridDisplay &other)
Assignment constructor.
void setStepX(double stepX)
Set method for x grid line increment.
double stopX() const
Get method for x grid line upper bound (inclusive).
double stopY() const
Get method for y grid line upper bound (inclusive).
bool stable() const
Get method for stable flag.
void setStepY(double yStep)
Set method for y grid line increment.
void setStopX(double stopX)
Set method for x grid line upper bound (inclusive).
void setLineWidth(unsigned int lineWidth)
Set method for line width.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void setDisableX(GridCoordDisable disableX)
Set method for x grid line disabled variable.
ColorPalette paletteColor() const
Get method for color.
void setStopY(double yStop)
Set method for y grid line upper bound (inclusive).
void setDisableY(GridCoordDisable disableY)
Set method for y grid line disabled variable.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
double stepY() const
Get method for y grid line increment.
void setCountX(unsigned int countX)
Set method for x grid line count.
void setStartX(double startX)
Set method for x grid line lower bound (inclusive).
void setStable(bool stable)
Set method for stable flag.
double startY() const
Get method for y grid line lower bound (inclusive).
DocumentModelGridDisplay()
Default constructor.
void setStartY(double yStart)
Set method for y grid line lower bound (inclusive).
void setCountY(unsigned int countY)
Set method for y grid line count.
unsigned int lineWidth() const
Get method for line width.
Storage of one imported image and the data attached to that image.
Definition Document.h:44
#define LOG4CPP_INFO_S(logger)
Definition convenience.h:18