Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
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 = 10.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 {
30 }
31 
33  double startY,
34  double stepX,
35  double stepY,
36  int countX,
37  int countY) :
38  m_stable (false),
39  m_removeDefinedGridLines (false),
40  m_closeDistance (CLOSE_DISTANCE_DEFAULT),
41  m_gridCoordDisableX (GRID_COORD_DISABLE_COUNT),
42  m_countX (countX),
43  m_startX (startX),
44  m_stepX (stepX),
45  m_stopX (startX + (countX - 1.0) * stepX),
46  m_gridCoordDisableY (GRID_COORD_DISABLE_COUNT),
47  m_countY (countY),
48  m_startY (startY),
49  m_stepY (stepY),
50  m_stopY (startY + (countY - 1.0) * stepY)
51 {
52 }
53 
55  m_stable (document.modelGridRemoval().stable()),
56  m_removeDefinedGridLines (document.modelGridRemoval().removeDefinedGridLines()),
57  m_closeDistance (document.modelGridRemoval().closeDistance()),
58  m_gridCoordDisableX (document.modelGridRemoval().gridCoordDisableX()),
59  m_countX (document.modelGridRemoval().countX()),
60  m_startX (document.modelGridRemoval().startX()),
61  m_stepX (document.modelGridRemoval().stepX()),
62  m_stopX (document.modelGridRemoval().stopX()),
63  m_gridCoordDisableY (document.modelGridRemoval().gridCoordDisableY()),
64  m_countY (document.modelGridRemoval().countY()),
65  m_startY (document.modelGridRemoval().startY()),
66  m_stepY (document.modelGridRemoval().stepY()),
67  m_stopY (document.modelGridRemoval().stopY())
68 {
69 }
70 
72  m_stable (other.stable()),
73  m_removeDefinedGridLines (other.removeDefinedGridLines()),
74  m_closeDistance (other.closeDistance()),
75  m_gridCoordDisableX (other.gridCoordDisableX()),
76  m_countX (other.countX()),
77  m_startX (other.startX()),
78  m_stepX (other.stepX()),
79  m_stopX (other.stopX()),
80  m_gridCoordDisableY (other.gridCoordDisableX()),
81  m_countY (other.countY()),
82  m_startY (other.startY()),
83  m_stepY (other.stepY()),
84  m_stopY (other.stopY())
85 {
86 }
87 
89 {
90  m_stable = other.stable();
91  m_removeDefinedGridLines = other.removeDefinedGridLines();
92  m_closeDistance = other.closeDistance();
93  m_gridCoordDisableX = other.gridCoordDisableX();
94  m_countX = other.countX();
95  m_startX = other.startX();
96  m_stepX = other.stepX();
97  m_stopX = other.stopX();
98  m_gridCoordDisableY = other.gridCoordDisableY();
99  m_countY = other.countY();
100  m_startY = other.startY();
101  m_stepY = other.stepY();
102  m_stopY = other.stopY();
103 
104  return *this;
105 }
106 
108 {
109  return m_closeDistance;
110 }
111 
113 {
114  return m_countX;
115 }
116 
118 {
119  return m_countY;
120 }
121 
123 {
124  return m_gridCoordDisableX;
125 }
126 
128 {
129  return m_gridCoordDisableY;
130 }
131 
132 void DocumentModelGridRemoval::loadXml(QXmlStreamReader &reader)
133 {
134  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridRemoval::loadXml";
135 
136  bool success = true;
137 
138  QXmlStreamAttributes attributes = reader.attributes();
139 
140  if (attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STABLE) &&
141  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_DEFINED_GRID_LINES) &&
142  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_CLOSE_DISTANCE) &&
143  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X) &&
144  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_X) &&
145  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_X) &&
146  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_X) &&
147  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_X) &&
148  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y) &&
149  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_Y) &&
150  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_Y) &&
151  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_Y) &&
152  attributes.hasAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_Y)) {
153 
154  // Boolean values
155  QString stableValue = attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STABLE).toString();
156  QString definedValue = attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_DEFINED_GRID_LINES).toString();
157 
158  setStable (stableValue == DOCUMENT_SERIALIZE_BOOL_TRUE);
159  setRemoveDefinedGridLines (definedValue == DOCUMENT_SERIALIZE_BOOL_TRUE);
160  setCloseDistance (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_CLOSE_DISTANCE).toDouble());
161  setGridCoordDisableX ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X).toInt());
162  setCountX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_X).toInt());
163  setStartX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_X).toDouble());
164  setStepX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_X).toDouble());
165  setStopX (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_X).toDouble());
166  setGridCoordDisableY ((GridCoordDisable) attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y).toInt());
167  setCountY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_Y).toInt());
168  setStartY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_Y).toDouble());
169  setStepY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_Y).toDouble());
170  setStopY (attributes.value(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_Y).toDouble());
171 
172  // Read until end of this subtree
173  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
174  (reader.name() != DOCUMENT_SERIALIZE_GRID_REMOVAL)){
175  loadNextFromReader(reader);
176  if (reader.atEnd()) {
177  success = false;
178  break;
179  }
180  }
181  }
182 
183  if (!success) {
184  reader.raiseError ("Cannot read grid removal data");
185  }
186 }
187 
188 void DocumentModelGridRemoval::printStream(QString indentation,
189  QTextStream &str) const
190 {
191  str << indentation << "DocumentModelGridRemoval\n";
192 
193  indentation += INDENTATION_DELTA;
194 
195  str << indentation << "stable=" << (m_stable ? "true" : "false") << "\n";
196  str << indentation << "removeDefinedGridLines=" << (m_removeDefinedGridLines ? "true" : "false") << "\n";
197  str << indentation << "closeDistance=" << m_closeDistance << "\n";
198  str << indentation << "gridCoordDisableX=" << gridCoordDisableToString (m_gridCoordDisableX) << "\n";
199  str << indentation << "countX=" << m_countX << "\n";
200  str << indentation << "startX=" << m_startX << "\n";
201  str << indentation << "stepX=" << m_stepX << "\n";
202  str << indentation << "stopX=" << m_stopX << "\n";
203  str << indentation << "gridCoordDisableY=" << gridCoordDisableToString (m_gridCoordDisableY) << "\n";
204  str << indentation << "countY=" << m_countY << "\n";
205  str << indentation << "startY=" << m_startY << "\n";
206  str << indentation << "stepY=" << m_stepY << "\n";
207  str << indentation << "stopY=" << m_stopY << "\n";
208 }
209 
211 {
212  return m_removeDefinedGridLines;
213 }
214 
215 void DocumentModelGridRemoval::saveXml(QXmlStreamWriter &writer) const
216 {
217  LOG4CPP_INFO_S ((*mainCat)) << "DocumentModelGridRemoval::saveXml";
218 
219  writer.writeStartElement(DOCUMENT_SERIALIZE_GRID_REMOVAL);
220  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STABLE, m_stable ?
221  DOCUMENT_SERIALIZE_BOOL_TRUE :
222  DOCUMENT_SERIALIZE_BOOL_FALSE);
223  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_DEFINED_GRID_LINES, m_removeDefinedGridLines ?
224  DOCUMENT_SERIALIZE_BOOL_TRUE :
225  DOCUMENT_SERIALIZE_BOOL_FALSE);
226  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_CLOSE_DISTANCE, QString::number (m_closeDistance));
227  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X, QString::number (m_gridCoordDisableX));
228  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_X_STRING, gridCoordDisableToString (m_gridCoordDisableX));
229  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_X, QString::number (m_countX));
230  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_X, QString::number (m_startX));
231  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_X, QString::number (m_stepX));
232  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_X, QString::number (m_stopX));
233  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y, QString::number (m_gridCoordDisableY));
234  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COORD_DISABLE_Y_STRING, gridCoordDisableToString (m_gridCoordDisableY));
235  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_COUNT_Y, QString::number (m_countY));
236  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_START_Y, QString::number (m_startY));
237  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STEP_Y, QString::number (m_stepY));
238  writer.writeAttribute(DOCUMENT_SERIALIZE_GRID_REMOVAL_STOP_Y, QString::number (m_stopY));
239 
240  writer.writeEndElement();
241 }
242 
244 {
245  m_closeDistance = closeDistance;
246 }
247 
249 {
250  m_countX = countX;
251 }
252 
254 {
255  m_countY = countY;
256 }
257 
258 void DocumentModelGridRemoval::setGridCoordDisableX (GridCoordDisable gridCoordDisable)
259 {
260  m_gridCoordDisableX = gridCoordDisable;
261 }
262 
263 void DocumentModelGridRemoval::setGridCoordDisableY (GridCoordDisable gridCoordDisable)
264 {
265  m_gridCoordDisableY = gridCoordDisable;
266 }
267 
268 void DocumentModelGridRemoval::setRemoveDefinedGridLines (bool removeDefinedGridLines)
269 {
270  m_removeDefinedGridLines = removeDefinedGridLines;
271 }
272 
274 {
275  m_stable = true;
276 }
277 
278 void DocumentModelGridRemoval::setStable (bool stable)
279 {
280  m_stable = stable;
281 }
282 
284 {
285  m_startX = startX;
286 }
287 
289 {
290  m_startY = startY;
291 }
292 
294 {
295  m_stepX = stepX;
296 }
297 
299 {
300  m_stepY = stepY;
301 }
302 
304 {
305  m_stopX = stopX;
306 }
307 
309 {
310  m_stopY = stopY;
311 }
312 
314 {
315  return m_stable;
316 }
317 
319 {
320  return m_startX;
321 }
322 
324 {
325  return m_startY;
326 }
327 
329 {
330  return m_stepX;
331 }
332 
334 {
335  return m_stepY;
336 }
337 
339 {
340  return m_stopX;
341 }
342 
344 {
345  return m_stopY;
346 }
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 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:29
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...
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.