Engauge Digitizer  2
DocumentModelGridRemoval.cpp
1 #include "CmdMediator.h"
2 #include "DocumentModelGridRemoval.h"
3 #include "DocumentSerialize.h"
4 #include "Logger.h"
5 #include <QTextStream>
6 #include <QXmlStreamWriter>
7 #include "Xml.h"
8 
9 const double CLOSE_DISTANCE_DEFAULT = 1.0;
10 
11 // These defaults should always be overwritten when Document coordinates are defined
12 const int DEFAULT_COUNT = 2;
13 const double DEFAULT_NON_COUNT = 0.0;
14 
16  m_stable (false),
17  m_removeDefinedGridLines (false),
18  m_closeDistance (CLOSE_DISTANCE_DEFAULT),
19  m_gridCoordDisableX (GRID_COORD_DISABLE_COUNT),
20  m_countX (DEFAULT_COUNT),
21  m_startX (DEFAULT_NON_COUNT),
22  m_stepX (DEFAULT_NON_COUNT),
23  m_stopX (DEFAULT_NON_COUNT),
24  m_gridCoordDisableY (GRID_COORD_DISABLE_COUNT),
25  m_countY (DEFAULT_COUNT),
26  m_startY (DEFAULT_NON_COUNT),
27  m_stepY (DEFAULT_NON_COUNT),
28  m_stopY (DEFAULT_NON_COUNT),
29  m_removeParallelToAxes (false)
30 {
31 }
32 
34  double startY,
35  double stepX,
36  double stepY,
37  int countX,
38  int countY) :
39  m_stable (false),
40  m_removeDefinedGridLines (false),
41  m_closeDistance (CLOSE_DISTANCE_DEFAULT),
42  m_gridCoordDisableX (GRID_COORD_DISABLE_COUNT),
43  m_countX (countX),
44  m_startX (startX),
45  m_stepX (stepX),
46  m_stopX (startX + (countX - 1.0) * stepX),
47  m_gridCoordDisableY (GRID_COORD_DISABLE_COUNT),
48  m_countY (countY),
49  m_startY (startY),
50  m_stepY (stepY),
51  m_stopY (startY + (countY - 1.0) * stepY),
52  m_removeParallelToAxes (false)
53 {
54 }
55 
57  m_stable (document.modelGridRemoval().stable()),
58  m_removeDefinedGridLines (document.modelGridRemoval().removeDefinedGridLines()),
59  m_closeDistance (document.modelGridRemoval().closeDistance()),
60  m_gridCoordDisableX (document.modelGridRemoval().gridCoordDisableX()),
61  m_countX (document.modelGridRemoval().countX()),
62  m_startX (document.modelGridRemoval().startX()),
63  m_stepX (document.modelGridRemoval().stepX()),
64  m_stopX (document.modelGridRemoval().stopX()),
65  m_gridCoordDisableY (document.modelGridRemoval().gridCoordDisableY()),
66  m_countY (document.modelGridRemoval().countY()),
67  m_startY (document.modelGridRemoval().startY()),
68  m_stepY (document.modelGridRemoval().stepY()),
69  m_stopY (document.modelGridRemoval().stopY()),
70  m_removeParallelToAxes (document.modelGridRemoval().removeParallelToAxes())
71 {
72 }
73 
75  m_stable (other.stable()),
76  m_removeDefinedGridLines (other.removeDefinedGridLines()),
77  m_closeDistance (other.closeDistance()),
78  m_gridCoordDisableX (other.gridCoordDisableX()),
79  m_countX (other.countX()),
80  m_startX (other.startX()),
81  m_stepX (other.stepX()),
82  m_stopX (other.stopX()),
83  m_gridCoordDisableY (other.gridCoordDisableX()),
84  m_countY (other.countY()),
85  m_startY (other.startY()),
86  m_stepY (other.stepY()),
87  m_stopY (other.stopY()),
88  m_removeParallelToAxes (other.removeParallelToAxes())
89 {
90 }
91 
93 {
94  m_stable = other.stable();
95  m_removeDefinedGridLines = other.removeDefinedGridLines();
96  m_closeDistance = other.closeDistance();
97  m_gridCoordDisableX = other.gridCoordDisableX();
98  m_countX = other.countX();
99  m_startX = other.startX();
100  m_stepX = other.stepX();
101  m_stopX = other.stopX();
102  m_gridCoordDisableY = other.gridCoordDisableY();
103  m_countY = other.countY();
104  m_startY = other.startY();
105  m_stepY = other.stepY();
106  m_stopY = other.stopY();
107  m_removeParallelToAxes = other.removeParallelToAxes();
108 
109  return *this;
110 }
111 
113 {
114  return m_closeDistance;
115 }
116 
118 {
119  return m_countX;
120 }
121 
123 {
124  return m_countY;
125 }
126 
128 {
129  return m_gridCoordDisableX;
130 }
131 
133 {
134  return m_gridCoordDisableY;
135 }
136 
137 void DocumentModelGridRemoval::loadXml(QXmlStreamReader &reader)
138 {
139  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridRemoval::loadXml";
140 
141  bool success = true;
142 
143  QXmlStreamAttributes attributes = reader.attributes();
144 
145  if (attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STABLE) &&
146  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_DEFINED_GRID_LINES) &&
147  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_CLOSE_DISTANCE) &&
148  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X) &&
149  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_X) &&
150  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_X) &&
151  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_X) &&
152  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_X) &&
153  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y) &&
154  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_Y) &&
155  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_Y) &&
156  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_Y) &&
157  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_Y) &&
158  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_REMOVE_PARALLEL_TO_AXES)) {
159 
160  // Boolean values
161  QString stableValue = attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STABLE).toString();
162  QString definedValue = attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_DEFINED_GRID_LINES).toString();
163  QString parallelValue = attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_REMOVE_PARALLEL_TO_AXES).toString();
164 
165  setStable (stableValue == DOCUMENT_SERIALIZE_BOOL_TRUE);
166  setRemoveDefinedGridLines (definedValue == DOCUMENT_SERIALIZE_BOOL_TRUE);
167  setCloseDistance (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_CLOSE_DISTANCE).toDouble());
168  setGridCoordDisableX ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X).toInt());
169  setCountX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_X).toInt());
170  setStartX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_X).toDouble());
171  setStepX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_X).toDouble());
172  setStopX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_X).toDouble());
173  setGridCoordDisableY ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y).toInt());
174  setCountY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_Y).toInt());
175  setStartY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_Y).toDouble());
176  setStepY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_Y).toDouble());
177  setStopY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_Y).toDouble());
178  setRemoveParallelToAxes (parallelValue == DOCUMENT_SERIALIZE_BOOL_TRUE);
179 
180  // Read until end of this subtree
181  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
182  (reader.name() != DOCUMENT_SERIALIZE_GRID_REMOVAL)){
183  loadNextFromReader(reader);
184  if (reader.atEnd()) {
185  success = false;
186  break;
187  }
188  }
189  }
190 
191  if (!success) {
192  reader.raiseError ("Cannot read grid removal data");
193  }
194 }
195 
196 void DocumentModelGridRemoval::printStream(QString indentation,
197  QTextStream &str) const
198 {
199  str << indentation << "DocumentModelGridRemoval\n";
200 
201  indentation += INDENTATION_DELTA;
202 
203  str << indentation << "stable=" << (m_stable ? "true" : "false") << "\n";
204  str << indentation << "removeDefinedGridLines=" << (m_removeDefinedGridLines ? "true" : "false") << "\n";
205  str << indentation << "closeDistance=" << m_closeDistance << "\n";
206  str << indentation << "gridCoordDisableX=" << gridCoordDisableToString (m_gridCoordDisableX) << "\n";
207  str << indentation << "countX=" << m_countX << "\n";
208  str << indentation << "startX=" << m_startX << "\n";
209  str << indentation << "stepX=" << m_stepX << "\n";
210  str << indentation << "stopX=" << m_stopX << "\n";
211  str << indentation << "gridCoordDisableY=" << gridCoordDisableToString (m_gridCoordDisableY) << "\n";
212  str << indentation << "countY=" << m_countY << "\n";
213  str << indentation << "startY=" << m_startY << "\n";
214  str << indentation << "stepY=" << m_stepY << "\n";
215  str << indentation << "stopY=" << m_stopY << "\n";
216  str << indentation << "removeParallelToAxes=" << (m_removeParallelToAxes ? "true" : "false") << "\n";
217 }
218 
220 {
221  return m_removeDefinedGridLines;
222 }
223 
225 {
226  return m_removeParallelToAxes;
227 }
228 
229 void DocumentModelGridRemoval::saveXml(QXmlStreamWriter &writer) const
230 {
231  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridRemoval::saveXml";
232 
233  writer.writeStartElement(DOCUMENT_SERIALIZE_GRID_REMOVAL);
234  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STABLE, m_stable ?
235  DOCUMENT_SERIALIZE_BOOL_TRUE :
236  DOCUMENT_SERIALIZE_BOOL_FALSE);
237  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_DEFINED_GRID_LINES, m_removeDefinedGridLines ?
238  DOCUMENT_SERIALIZE_BOOL_TRUE :
239  DOCUMENT_SERIALIZE_BOOL_FALSE);
240  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_CLOSE_DISTANCE, QString::number (m_closeDistance));
241  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X, QString::number (m_gridCoordDisableX));
242  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X_STRING, gridCoordDisableToString (m_gridCoordDisableX));
243  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_X, QString::number (m_countX));
244  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_X, QString::number (m_startX));
245  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_X, QString::number (m_stepX));
246  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_X, QString::number (m_stopX));
247  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y, QString::number (m_gridCoordDisableY));
248  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y_STRING, gridCoordDisableToString (m_gridCoordDisableY));
249  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_Y, QString::number (m_countY));
250  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_Y, QString::number (m_startY));
251  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_Y, QString::number (m_stepY));
252  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_Y, QString::number (m_stopY));
253  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_REMOVE_PARALLEL_TO_AXES, m_removeParallelToAxes ?
254  DOCUMENT_SERIALIZE_BOOL_TRUE :
255  DOCUMENT_SERIALIZE_BOOL_FALSE);
256 
257  writer.writeEndElement();
258 }
259 
261 {
262  m_closeDistance = closeDistance;
263 }
264 
266 {
267  m_countX = countX;
268 }
269 
271 {
272  m_countY = countY;
273 }
274 
275 void DocumentModelGridRemoval::setGridCoordDisableX (GridCoordDisable gridCoordDisable)
276 {
277  m_gridCoordDisableX = gridCoordDisable;
278 }
279 
280 void DocumentModelGridRemoval::setGridCoordDisableY (GridCoordDisable gridCoordDisable)
281 {
282  m_gridCoordDisableY = gridCoordDisable;
283 }
284 
285 void DocumentModelGridRemoval::setRemoveDefinedGridLines (bool removeDefinedGridLines)
286 {
287  m_removeDefinedGridLines = removeDefinedGridLines;
288 }
289 
291 {
292  m_removeParallelToAxes = removeParallelToAxes;
293 }
294 
296 {
297  m_stable = true;
298 }
299 
300 void DocumentModelGridRemoval::setStable (bool stable)
301 {
302  m_stable = stable;
303 }
304 
306 {
307  m_startX = startX;
308 }
309 
311 {
312  m_startY = startY;
313 }
314 
316 {
317  m_stepX = stepX;
318 }
319 
321 {
322  m_stepY = stepY;
323 }
324 
326 {
327  m_stopX = stopX;
328 }
329 
331 {
332  m_stopY = stopY;
333 }
334 
336 {
337  return m_stable;
338 }
339 
341 {
342  return m_startX;
343 }
344 
346 {
347  return m_startY;
348 }
349 
351 {
352  return m_stepX;
353 }
354 
356 {
357  return m_stepY;
358 }
359 
361 {
362  return m_stopX;
363 }
364 
366 {
367  return m_stopY;
368 }
double closeDistance() const
Get method for close distance.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
DocumentModelGridRemoval()
Default constructor.
bool removeDefinedGridLines() const
Get method for removing defined grid lines.
void setCloseDistance(double closeDistance)
Set method for close distance.
double startY() const
Get method for y start.
void setCountX(int countX)
Set method for x count.
void setStopY(double stopY)
Set method for y stop.
void setRemoveParallelToAxes(bool removeParallelToAxes)
Set method for removing lines parallel to axes.
void setStartY(double startY)
Set method for y start.
GridCoordDisable gridCoordDisableX() const
Get method for x coord parameter to disable.
void setStepY(double stepY)
Set method for y step.
bool stable() const
Get method for stable flag.
double stepY() const
Get method for y step.
GridCoordDisable gridCoordDisableY() const
Get method for y coord parameter to disable.
void setStartX(double startX)
Set method for x start.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
DocumentModelGridRemoval & operator=(const DocumentModelGridRemoval &other)
Assignment constructor.
void setCountY(int countY)
Set method for y count.
void setStepX(double stepX)
Set method for x step.
double stopX() const
Get method for x stop.
void setRemoveDefinedGridLines(bool removeDefinedGridLines)
Set method for removing defined grid lines.
double startX() const
Get method for x start.
double stopY() const
Get method for y stop.
Storage of one imported image and the data attached to that image.
Definition: Document.h:28
void setGridCoordDisableY(GridCoordDisable gridCoordDisable)
Set method for y coord parameter to disable.
void setGridCoordDisableX(GridCoordDisable gridCoordDisable)
Set method for x coord parameter to disable.
int countX() const
Get method for x count.
int countY() const
Get method for y count.
double stepX() const
Get method for x step.
void setStable()
Set the stable flag to true. This public version has no argument since it cannot be undone...
bool removeParallelToAxes() const
Get method for removing lines parallel to axes.
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setStopX(double stopX)
Set method for x stop.