Engauge Digitizer  2
Document.cpp
1 #include "CallbackAddPointsInCurvesGraphs.h"
2 #include "CallbackCheckAddPointAxis.h"
3 #include "CallbackCheckEditPointAxis.h"
4 #include "CallbackNextOrdinal.h"
5 #include "CallbackRemovePointsInCurvesGraphs.h"
6 #include "Curve.h"
7 #include "CurveStyles.h"
8 #include "Document.h"
9 #include "DocumentSerialize.h"
10 #include "EngaugeAssert.h"
11 #include "EnumsToQt.h"
12 #include <iostream>
13 #include "Logger.h"
14 #include "OrdinalGenerator.h"
15 #include "Point.h"
16 #include <QByteArray>
17 #include <QDataStream>
18 #include <QDebug>
19 #include <QFile>
20 #include <QImage>
21 #include <QtToString.h>
22 #include <QXmlStreamReader>
23 #include <QXmlStreamWriter>
24 #include "Transformation.h"
25 #include "Xml.h"
26 
27 Document::Document (const QImage &image) :
28  m_name ("untitled"),
29  m_curveAxes (new Curve (AXIS_CURVE_NAME,
30  ColorFilterSettings::defaultFilter (),
31  CurveStyle (LineStyle::defaultAxesCurve(),
32  PointStyle::defaultAxesCurve ())))
33 {
34  m_successfulRead = true; // Reading from QImage always succeeds, resulting in empty Document
35 
36  m_pixmap.convertFromImage (image);
37 
38  m_curvesGraphs.addGraphCurveAtEnd (Curve (DEFAULT_GRAPH_CURVE_NAME,
41  PointStyle::defaultGraphCurve (m_curvesGraphs.numCurves ()))));
42 }
43 
44 Document::Document (const QString &fileName) :
45  m_name (fileName),
46  m_curveAxes (0)
47 {
48  m_successfulRead = true;
49 
50  QFile *file = new QFile (fileName);
51  if (file->open (QIODevice::ReadOnly | QIODevice::Text)) {
52 
53  QXmlStreamReader reader (file);
54 
55  // If this is purely a serialized Document then we process every node under the root. However, if this is an error report file
56  // then we need to skip the non-Document stuff. The common solution is to skip nodes outside the Document subtree using this flag
57  bool inDocumentSubtree = false;
58 
59  // Import from xml. Loop to end of data or error condition occurs, whichever is first
60  while (!reader.atEnd() &&
61  !reader.hasError()) {
62  QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
63 
64  // Special processing of DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT, for an error report file
65  if ((reader.name() == DOCUMENT_SERIALIZE_IMAGE) &&
66  (tokenType == QXmlStreamReader::StartElement)) {
67 
68  generateEmptyPixmap (reader.attributes());
69  }
70 
71  // Branching to skip non-Document nodes, with the exception of any DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT
72  if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
73  (tokenType == QXmlStreamReader::StartElement)) {
74 
75  inDocumentSubtree = true;
76 
77  } else if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
78  (tokenType == QXmlStreamReader::EndElement)) {
79 
80  // Exit out of loop immediately
81  break;
82  }
83 
84  if (inDocumentSubtree) {
85 
86  // Iterate to next StartElement
87  if (tokenType == QXmlStreamReader::StartElement) {
88 
89  // This is a StartElement, so process it
90  QString tag = reader.name().toString();
91  if (tag == DOCUMENT_SERIALIZE_AXES_CHECKER){
92  m_modelAxesChecker.loadXml (reader);
93  } else if (tag == DOCUMENT_SERIALIZE_COMMON) {
94  m_modelCommon.loadXml (reader);
95  } else if (tag == DOCUMENT_SERIALIZE_COORDS) {
96  m_modelCoords.loadXml (reader);
97  } else if (tag == DOCUMENT_SERIALIZE_CURVE) {
98  m_curveAxes = new Curve (reader);
99  } else if (tag == DOCUMENT_SERIALIZE_CURVES_GRAPHS) {
100  m_curvesGraphs.loadXml (reader);
101  } else if (tag == DOCUMENT_SERIALIZE_DIGITIZE_CURVE) {
102  m_modelDigitizeCurve.loadXml (reader);
103  } else if (tag == DOCUMENT_SERIALIZE_DOCUMENT) {
104  // Do nothing. This is the root node
105  } else if (tag == DOCUMENT_SERIALIZE_EXPORT) {
106  m_modelExport.loadXml (reader);
107  } else if (tag == DOCUMENT_SERIALIZE_GRID_REMOVAL) {
108  m_modelGridRemoval.loadXml (reader);
109  } else if (tag == DOCUMENT_SERIALIZE_IMAGE) {
110  // A standard Document file has DOCUMENT_SERIALIZE_IMAGE inside DOCUMENT_SERIALIZE_DOCUMENT, versus an error report file
111  loadImage(reader);
112  } else if (tag == DOCUMENT_SERIALIZE_POINT_MATCH) {
113  m_modelPointMatch.loadXml (reader);
114  } else if (tag == DOCUMENT_SERIALIZE_SEGMENTS) {
115  m_modelSegments.loadXml (reader);
116  } else {
117  m_successfulRead = false;
118  m_reasonForUnsuccessfulRead = QString ("Unexpected xml token '%1' encountered").arg (tokenType);
119  break;
120  }
121  }
122  }
123  }
124  if (reader.hasError ()) {
125 
126  m_successfulRead = false;
127  m_reasonForUnsuccessfulRead = reader.errorString();
128  }
129 
130  // Close and deactivate
131  file->close ();
132  delete file;
133  file = 0;
134 
135  } else {
136 
137  m_successfulRead = false;
138  m_reasonForUnsuccessfulRead = "Operating system says file is not readable";
139  }
140 
141  // There are already one axes curve and at least one graph curve so we do not need to add any more graph curves
142 }
143 
144 void Document::addGraphCurveAtEnd (const QString &curveName)
145 {
146  m_curvesGraphs.addGraphCurveAtEnd (Curve (curveName,
149  PointStyle::defaultGraphCurve(m_curvesGraphs.numCurves()))));
150 }
151 
152 void Document::addPointAxisWithGeneratedIdentifier (const QPointF &posScreen,
153  const QPointF &posGraph,
154  QString &identifier,
155  double ordinal)
156 {
157  Point point (AXIS_CURVE_NAME,
158  posScreen,
159  posGraph,
160  ordinal);
161  m_curveAxes->addPoint (point);
162 
163  identifier = point.identifier();
164 
165  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointAxisWithGeneratedIdentifier"
166  << " ordinal=" << ordinal
167  << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
168  << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ()
169  << " identifier=" << identifier.toLatin1 ().data ();
170 }
171 
172 void Document::addPointAxisWithSpecifiedIdentifier (const QPointF &posScreen,
173  const QPointF &posGraph,
174  const QString &identifier,
175  double ordinal)
176 {
177  Point point (AXIS_CURVE_NAME,
178  identifier,
179  posScreen,
180  posGraph,
181  ordinal);
182  m_curveAxes->addPoint (point);
183 
184  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointAxisWithSpecifiedIdentifier"
185  << " ordinal=" << ordinal
186  << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
187  << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ()
188  << " identifier=" << identifier.toLatin1 ().data ();
189 }
190 
191 void Document::addPointGraphWithGeneratedIdentifier (const QString &curveName,
192  const QPointF &posScreen,
193  QString &identifier,
194  double ordinal)
195 {
196  Point point (curveName,
197  posScreen,
198  ordinal);
199  m_curvesGraphs.addPoint (point);
200 
201  identifier = point.identifier();
202 
203  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointGraphWithGeneratedIdentifier"
204  << " ordinal=" << ordinal
205  << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
206  << " identifier=" << identifier.toLatin1 ().data ();
207 }
208 
209 void Document::addPointGraphWithSpecifiedIdentifier (const QString &curveName,
210  const QPointF &posScreen,
211  const QString &identifier,
212  double ordinal)
213 {
214  Point point (curveName,
215  identifier,
216  posScreen,
217  ordinal);
218  m_curvesGraphs.addPoint (point);
219 
220  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointGraphWithSpecifiedIdentifier"
221  << " ordinal=" << ordinal
222  << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
223  << " identifier=" << identifier.toLatin1 ().data ();
224 }
225 
227 {
228  CallbackAddPointsInCurvesGraphs ftor (*this);
229 
230  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
232 
233  curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
234 }
235 
236 void Document::checkAddPointAxis (const QPointF &posScreen,
237  const QPointF &posGraph,
238  bool &isError,
239  QString &errorMessage)
240 {
241  LOG4CPP_INFO_S ((*mainCat)) << "Document::checkAddPointAxis"
242  << " posScreen=" << QPointFToString (posScreen).toLatin1 ().data ()
243  << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ();
244 
245  CallbackCheckAddPointAxis ftor (m_modelCoords,
246  posScreen,
247  posGraph);
248 
249  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
251  m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
252 
253  isError = ftor.isError ();
254  errorMessage = ftor.errorMessage ();
255 }
256 
257 void Document::checkEditPointAxis (const QString &pointIdentifier,
258  const QPointF &posScreen,
259  const QPointF &posGraph,
260  bool &isError,
261  QString &errorMessage)
262 {
263  LOG4CPP_INFO_S ((*mainCat)) << "Document::checkEditPointAxis"
264  << " posGraph=" << QPointFToString (posGraph).toLatin1 ().data ();
265 
266  CallbackCheckEditPointAxis ftor (m_modelCoords,
267  pointIdentifier,
268  posScreen,
269  posGraph);
270 
271  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
273  m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
274 
275  isError = ftor.isError ();
276  errorMessage = ftor.errorMessage ();
277 }
278 
279 const Curve &Document::curveAxes () const
280 {
281  ENGAUGE_CHECK_PTR (m_curveAxes);
282 
283  return *m_curveAxes;
284 }
285 
286 Curve *Document::curveForCurveName (const QString &curveName)
287 {
288  if (curveName == AXIS_CURVE_NAME) {
289 
290  return m_curveAxes;
291 
292  } else {
293 
294  return m_curvesGraphs.curveForCurveName (curveName);
295 
296  }
297 }
298 
299 const Curve *Document::curveForCurveName (const QString &curveName) const
300 {
301  if (curveName == AXIS_CURVE_NAME) {
302 
303  return m_curveAxes;
304 
305  } else {
306 
307  return m_curvesGraphs.curveForCurveName (curveName);
308 
309  }
310 }
311 
313 {
314  return m_curvesGraphs;
315 }
316 
317 QStringList Document::curvesGraphsNames() const
318 {
319  return m_curvesGraphs.curvesGraphsNames();
320 }
321 
322 int Document::curvesGraphsNumPoints(const QString &curveName) const
323 {
324  return m_curvesGraphs.curvesGraphsNumPoints(curveName);
325 }
326 
327 void Document::editPointAxis (const QPointF &posGraph,
328  const QString &identifier)
329 {
330  LOG4CPP_INFO_S ((*mainCat)) << "Document::editPointAxis posGraph=("
331  << posGraph.x () << ", " << posGraph.y () << ") identifier="
332  << identifier.toLatin1 ().data ();
333 
334  m_curveAxes->editPoint (posGraph,
335  identifier);
336 }
337 
338 void Document::generateEmptyPixmap(const QXmlStreamAttributes &attributes)
339 {
340  LOG4CPP_INFO_S ((*mainCat)) << "Document::generateEmptyPixmap";
341 
342  int width = 800, height = 500; // Defaults
343 
344  if (attributes.hasAttribute (DOCUMENT_SERIALIZE_IMAGE_WIDTH) &&
345  attributes.hasAttribute (DOCUMENT_SERIALIZE_IMAGE_HEIGHT)) {
346 
347  width = attributes.value (DOCUMENT_SERIALIZE_IMAGE_WIDTH).toInt();
348  height = attributes.value (DOCUMENT_SERIALIZE_IMAGE_HEIGHT).toInt();
349 
350  }
351 
352  m_pixmap = QPixmap (width, height);
353 }
354 
355 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
356 {
357  ENGAUGE_CHECK_PTR (m_curveAxes);
358 
359  m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
360 }
361 
362 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
363 {
364  ENGAUGE_CHECK_PTR (m_curveAxes);
365 
366  m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
367 }
368 
369 void Document::iterateThroughCurveSegments (const QString &curveName,
370  const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
371 {
372  if (curveName == AXIS_CURVE_NAME) {
373  m_curveAxes->iterateThroughCurveSegments(ftorWithCallback);
374  } else {
375  m_curvesGraphs.iterateThroughCurveSegments(curveName,
376  ftorWithCallback);
377  }
378 }
379 
380 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
381 {
382  ENGAUGE_CHECK_PTR (m_curveAxes);
383 
384  m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
385 }
386 
387 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
388 {
389  ENGAUGE_CHECK_PTR (m_curveAxes);
390 
391  m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
392 }
393 
394 void Document::loadImage(QXmlStreamReader &reader)
395 {
396  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadImage";
397 
398  loadNextFromReader(reader); // Read to CDATA
399  if (reader.isCDATA ()) {
400 
401  // Get base64 array
402  QByteArray array64 = reader.text().toString().toUtf8();
403 
404  // Decoded array
405  QByteArray array;
406  array = QByteArray::fromBase64(array64);
407 
408  // Read decoded array into image
409  QDataStream str (&array, QIODevice::ReadOnly);
410  QImage img = m_pixmap.toImage ();
411  str >> img;
412  m_pixmap = QPixmap::fromImage (img);
413 
414  // Read until end of this subtree
415  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
416  (reader.name() != DOCUMENT_SERIALIZE_IMAGE)){
417  loadNextFromReader(reader);
418  }
419 
420  } else {
421 
422  // This point can be reached if:
423  // 1) File is broken
424  // 2) Bad character is in text, and NetworkClient::cleanXml did not do its job
425  reader.raiseError ("Cannot read image data");
426  }
427 }
428 
430 {
431  return m_modelAxesChecker;
432 }
433 
435 {
436  // Construct a curve-specific model
438 
439  return modelColorFilter;
440 }
441 
443 {
444  return m_modelCommon;
445 }
446 
448 {
449  return m_modelCoords;
450 }
451 
453 {
454  // Construct a curve-specific model
456 
457  return modelCurveStyles;
458 }
459 
461 {
462  return m_modelDigitizeCurve;
463 }
464 
466 {
467  return m_modelExport;
468 }
469 
471 {
472  return m_modelGridRemoval;
473 }
474 
476 {
477  return m_modelPointMatch;
478 }
479 
481 {
482  return m_modelSegments;
483 }
484 
485 void Document::movePoint (const QString &pointIdentifier,
486  const QPointF &deltaScreen)
487 {
488  QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
489 
490  Curve *curve = curveForCurveName (curveName);
491  curve->movePoint (pointIdentifier,
492  deltaScreen);
493 }
494 
495 int Document::nextOrdinalForCurve (const QString &curveName) const
496 {
497  CallbackNextOrdinal ftor (curveName);
498 
499  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
501 
502  if (curveName == AXIS_CURVE_NAME) {
503  m_curveAxes->iterateThroughCurvePoints (ftorWithCallback);
504  } else {
505  m_curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
506  }
507 
508  return ftor.nextOrdinal ();
509 }
510 
511 QPixmap Document::pixmap () const
512 {
513  return m_pixmap;
514 }
515 
516 QPointF Document::positionGraph (const QString &pointIdentifier) const
517 {
518  QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
519 
520  const Curve *curve = curveForCurveName (curveName);
521  return curve->positionGraph (pointIdentifier);
522 }
523 
524 QPointF Document::positionScreen (const QString &pointIdentifier) const
525 {
526  QString curveName = Point::curveNameFromPointIdentifier (pointIdentifier);
527 
528  const Curve *curve = curveForCurveName (curveName);
529  return curve->positionScreen (pointIdentifier);
530 }
531 
532 void Document::print () const
533 {
534  QString text;
535  QTextStream str (&text);
536 
537  printStream ("",
538  str);
539  std::cerr << text.toLatin1().data();
540 }
541 
542 void Document::printStream (QString indentation,
543  QTextStream &str) const
544 {
545  str << indentation << "Document\n";
546 
547  indentation += INDENTATION_DELTA;
548 
549  str << indentation << "name=" << m_name << "\n";
550  str << indentation << "pixmap=" << m_pixmap.width() << "x" << m_pixmap.height() << "\n";
551 
552  m_curveAxes->printStream (indentation,
553  str);
554  m_curvesGraphs.printStream (indentation,
555  str);
556 
557  m_modelAxesChecker.printStream (indentation,
558  str);
559  m_modelCommon.printStream (indentation,
560  str);
561  m_modelCoords.printStream (indentation,
562  str);
563  m_modelDigitizeCurve.printStream (indentation,
564  str);
565  m_modelExport.printStream (indentation,
566  str);
567  m_modelGridRemoval.printStream (indentation,
568  str);
569  m_modelPointMatch.printStream (indentation,
570  str);
571  m_modelSegments.printStream (indentation,
572  str);
573 }
574 
576 {
577  ENGAUGE_ASSERT (!m_successfulRead);
578 
579  return m_reasonForUnsuccessfulRead;
580 }
581 
582 void Document::removePointAxis (const QString &identifier)
583 {
584  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointAxis identifier=" << identifier.toLatin1 ().data ();
585 
586  m_curveAxes->removePoint (identifier);
587 }
588 
589 void Document::removePointGraph (const QString &identifier)
590 {
591  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointGraph identifier=" << identifier.toLatin1 ().data ();
592 
593  m_curvesGraphs.removePoint (identifier);
594 }
595 
597 {
599 
600  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
602 
603  curvesGraphs.iterateThroughCurvesPoints (ftorWithCallback);
604 }
605 
606 void Document::saveXml (QXmlStreamWriter &writer) const
607 {
608  writer.writeStartElement(DOCUMENT_SERIALIZE_DOCUMENT);
609 
610  // Serialize the Document image. That binary data is encoded as base64
611  QByteArray array;
612  QDataStream str (&array, QIODevice::WriteOnly);
613  QImage img = m_pixmap.toImage ();
614  str << img;
615  writer.writeStartElement(DOCUMENT_SERIALIZE_IMAGE);
616 
617  // Image width and height are explicitly inserted for error reports, since the CDATA is removed
618  // but we still want the image size for reconstructing the error(s)
619  writer.writeAttribute(DOCUMENT_SERIALIZE_IMAGE_WIDTH, QString::number (img.width()));
620  writer.writeAttribute(DOCUMENT_SERIALIZE_IMAGE_HEIGHT, QString::number (img.height()));
621 
622  writer.writeCDATA (array.toBase64 ());
623  writer.writeEndElement();
624 
625  // Serialize the Document variables
626  m_modelCommon.saveXml (writer);
627  m_modelCoords.saveXml (writer);
628  m_modelDigitizeCurve.saveXml (writer);
629  m_modelExport.saveXml (writer);
630  m_modelAxesChecker.saveXml (writer);
631  m_modelGridRemoval.saveXml (writer);
632  m_modelPointMatch.saveXml (writer);
633  m_modelSegments.saveXml (writer);
634  m_curveAxes->saveXml (writer);
635  m_curvesGraphs.saveXml (writer);
636  writer.writeEndElement();
637 }
638 
639 void Document::setCurvesGraphs (const CurvesGraphs &curvesGraphs)
640 {
641  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCurvesGraphs";
642 
643  m_curvesGraphs = curvesGraphs;
644 }
645 
647 {
648  m_modelAxesChecker = modelAxesChecker;
649 }
650 
652 {
653  // Save the CurveFilter for each Curve
654  ColorFilterSettingsList::const_iterator itr;
655  for (itr = modelColorFilter.colorFilterSettingsList().constBegin ();
656  itr != modelColorFilter.colorFilterSettingsList().constEnd();
657  itr++) {
658 
659  QString curveName = itr.key();
660  const ColorFilterSettings &colorFilterSettings = itr.value();
661 
662  Curve *curve = curveForCurveName (curveName);
663  curve->setColorFilterSettings (colorFilterSettings);
664  }
665 }
666 
668 {
669  m_modelCommon = modelCommon;
670 }
671 
673 {
674  m_modelCoords = modelCoords;
675 }
676 
677 void Document::setModelCurveStyles(const CurveStyles &modelCurveStyles)
678 {
679  // Save the LineStyle and PointStyle for each Curve
680  QStringList curveNames = modelCurveStyles.curveNames();
681  QStringList::iterator itr;
682  for (itr = curveNames.begin(); itr != curveNames.end(); itr++) {
683 
684  QString curveName = *itr;
685  const CurveStyle &curveStyle = modelCurveStyles.curveStyle (curveName);
686 
687  Curve *curve = curveForCurveName (curveName);
688  curve->setCurveStyle (curveStyle);
689  }
690 }
691 
693 {
694  m_modelDigitizeCurve = modelDigitizeCurve;
695 }
696 
698 {
699  m_modelExport = modelExport;
700 }
701 
703 {
704  m_modelGridRemoval = modelGridRemoval;
705 }
706 
708 {
709  m_modelPointMatch = modelPointMatch;
710 }
711 
713 {
714  m_modelSegments = modelSegments;
715 }
716 
718 {
719  return m_successfulRead;
720 }
721 
722 void Document::updatePointOrdinals (const Transformation &transformation)
723 {
724  LOG4CPP_INFO_S ((*mainCat)) << "Document::updatePointOrdinals";
725 
726  // The graph coordinates of all points in m_curvesGraphs must have already been updated at this point. See applyTransformation
727  m_curvesGraphs.updatePointOrdinals (transformation);
728 }
DocumentModelCommon modelCommon() const
Get method for DocumentModelCommon.
Definition: Document.cpp:442
void addGraphCurveAtEnd(const QString &curveName)
Add new graph curve to the list of existing graph curves.
Definition: Document.cpp:144
void addPointAxisWithSpecifiedIdentifier(const QPointF &posScreen, const QPointF &posGraph, const QString &identifier, double ordinal)
Add a single axis point with the specified point identifier.
Definition: Document.cpp:172
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
Definition: Document.cpp:524
void removePoint(const QString &identifier)
Perform the opposite of addPointAtEnd.
Definition: Curve.cpp:366
QStringList curveNames() const
List of all curve names.
Definition: CurveStyles.cpp:60
QPointF positionScreen(const QString &pointIdentifier) const
Return the position, in screen coordinates, of the specified Point.
Definition: Curve.cpp:329
static QString curveNameFromPointIdentifier(const QString &pointIdentifier)
Parse the curve name from the specified point identifier. This does the opposite of uniqueIdentifierG...
Definition: Point.cpp:202
void saveXml(QXmlStreamWriter &writer) const
Serialize curves.
QString errorMessage() const
Error message that explains the problem indicated by isError.
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
See Curve::movePoint.
Definition: Document.cpp:485
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Definition: Document.cpp:542
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
Callback for computing the next ordinal for a new point.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
static LineStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
Definition: LineStyle.cpp:55
DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
Definition: Document.cpp:434
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void setModelAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
Set method for DocumentModelAxesChecker.
Definition: Document.cpp:646
void setModelGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
Set method for DocumentModelGridRemoval.
Definition: Document.cpp:702
void loadXml(QXmlStreamReader &reader)
Load from serialized file.
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
Definition: Document.cpp:191
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
Callback that is used when iterating through a read-only CurvesGraphs to remove corresponding points ...
DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
Definition: Document.cpp:475
void setCurveStyle(const CurveStyle &curveStyle)
Set curve style.
Definition: Curve.cpp:411
void setModelPointMatch(const DocumentModelPointMatch &modelPointMatch)
Set method for DocumentModelPointMatch.
Definition: Document.cpp:707
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
void removePointAxis(const QString &identifier)
Perform the opposite of addPointAxis.
Definition: Document.cpp:582
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Definition: CurveStyles.h:16
void setModelSegments(const DocumentModelSegments &modelSegments)
Set method for DocumentModelSegments.
Definition: Document.cpp:712
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void addPoint(Point point)
Add Point to this Curve.
Definition: Curve.cpp:55
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings)
Set color filter.
Definition: Curve.cpp:401
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void iterateThroughCurveSegments(const QString &curveNameWanted, const Functor2wRet< const Point &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to segments on the specified axis or graph Curve.
Model for DlgSettingsCommon and CmdSettingsCommon.
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
Curve * curveForCurveName(const QString &curveName)
Return the axis or graph curve for the specified curve name.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
int numCurves() const
Current number of graphs curves.
QString errorMessage() const
Error message that explains the problem indicated by isError.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void addPointGraphWithSpecifiedIdentifier(const QString &curveName, const QPointF &posScreen, const QString &identifier, double ordinal)
Add a single graph point with the specified point identifer. Note that PointStyle is not applied to t...
Definition: Document.cpp:209
Callback that is used when iterating through a read-only CurvesGraphs to add corresponding points in ...
void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the axes curve.
Definition: Document.cpp:355
const Curve & curveAxes() const
Get method for axis curve.
Definition: Document.cpp:279
bool isError() const
True if an error occurred during iteration.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:447
void addGraphCurveAtEnd(Curve curve)
Append new graph Curve to end of Curve list.
void iterateThroughCurvesPoints(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
Apply functor to Points on all of the Curves.
void setModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Set method for DocumentModelDigitizeCurve.
Definition: Document.cpp:692
int curvesGraphsNumPoints(const QString &curveName) const
See CurvesGraphs::curvesGraphsNumPoints.
Definition: Document.cpp:322
QPixmap pixmap() const
Return the image that is being digitized.
Definition: Document.cpp:511
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:17
QPointF positionGraph(const QString &pointIdentifier) const
Return the position, in graph coordinates, of the specified Point.
Definition: Curve.cpp:312
bool successfulRead() const
Return true if startup loading succeeded. If the loading failed then reasonForUnsuccessfulRed will ex...
Definition: Document.cpp:717
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
bool isError() const
True if an error occurred during iteration.
void setModelCoords(const DocumentModelCoords &modelCoords)
Set method for DocumentModelCoords.
Definition: Document.cpp:672
Callback for sanity checking the screen and graph coordinates of an axis point that is in the axes cu...
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Definition: Curve.cpp:346
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
void checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling editPointAxis.
Definition: Document.cpp:257
void editPoint(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of an axis point. This method does not apply to a graph point...
Definition: Curve.cpp:75
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
QString identifier() const
Unique identifier for a specific Point.
Definition: Point.cpp:218
void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
Definition: Document.cpp:589
double nextOrdinal() const
Computed next ordinal.
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
Translate the position of a point by the specified distance vector.
Definition: Curve.cpp:279
static ColorFilterSettings defaultFilter()
Initial default for any Curve.
void setModelExport(const DocumentModelExportFormat &modelExport)
Set method for DocumentModelExportFormat.
Definition: Document.cpp:697
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
void editPointAxis(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of a single axis point. Call this after checkAddPointAxis to guarantee suc...
Definition: Document.cpp:327
Affine transformation between screen and graph coordinates, based on digitized axis points...
Details for a specific Point.
Definition: PointStyle.h:14
void addPoint(const Point &point)
Append new Point to the specified Curve.
Container for all graph curves. The axes point curve is external to this class.
Definition: CurvesGraphs.h:18
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
void setModelCurveStyles(const CurveStyles &modelCurveStyles)
Set method for CurveStyles.
Definition: Document.cpp:677
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
Definition: Document.cpp:452
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
DocumentModelAxesChecker modelAxesChecker() const
Get method for DocumentModelAxesChecker.
Definition: Document.cpp:429
void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
Definition: Document.cpp:596
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition: Document.cpp:460
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void iterateThroughCurvePoints(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to Points on Curve.
Definition: Curve.cpp:157
void setModelColorFilter(const DocumentModelColorFilter &modelColorFilter)
Set method for DocumentModelColorFilter.
Definition: Document.cpp:651
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
Model for DlgSettingsCoords and CmdSettingsCoords.
int curvesGraphsNumPoints(const QString &curveName) const
Point count.
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
Definition: Document.cpp:516
Container for LineStyle and PointStyle for one Curve.
Definition: CurveStyle.h:12
Container for one set of digitized Points.
Definition: Curve.h:24
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals to be consistent with their CurveStyle and x/theta coordinate.
Details for a specific Line.
Definition: LineStyle.h:13
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Definition: Document.cpp:317
virtual void loadXml(QXmlStreamReader &reader)
Load model from serialized xml.
void addPointAxisWithGeneratedIdentifier(const QPointF &posScreen, const QPointF &posGraph, QString &identifier, double ordinal)
Add a single axis point with a generated point identifier.
Definition: Document.cpp:152
void print() const
Debugging method for printing directly from symbolic debugger.
Definition: Document.cpp:532
Model for DlgSettingsAxesChecker and CmdSettingsAxesChecker.
void iterateThroughCurveSegments(const QString &curveName, const Functor2wRet< const Point &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
See Curve::iterateThroughCurveSegments, for any axes or graph curve.
Definition: Document.cpp:369
CurveStyle curveStyle(const QString &curveName) const
CurveStyle in specified curve.
Definition: CurveStyles.cpp:72
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition: Document.cpp:495
const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
Definition: Document.cpp:312
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
Definition: Document.cpp:299
DocumentModelSegments modelSegments() const
Get method for DocumentModelSegments.
Definition: Document.cpp:480
virtual void saveXml(QXmlStreamWriter &writer) const
Save entire model as xml into stream.
Model for DlgSettingsSegments and CmdSettingsSegments.
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
Definition: Document.cpp:380
void setCurvesGraphs(const CurvesGraphs &curvesGraphs)
Let CmdAbstract classes overwrite CurvesGraphs.
Definition: Document.cpp:639
Callback for sanity checking the screen and graph coordinates of an axis point, before it is added to...
void addPointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Add all points identified in the specified CurvesGraphs. See also removePointsInCurvesGraphs.
Definition: Document.cpp:226
QStringList curvesGraphsNames() const
List of graph curve names.
Document(const QImage &image)
Constructor for imported images and dragged images.
Definition: Document.cpp:27
void removePoint(const QString &pointIdentifier)
Remove the Point from its Curve.
void saveXml(QXmlStreamWriter &writer) const
Save document to xml.
Definition: Document.cpp:606
const ColorFilterSettingsList & colorFilterSettingsList() const
Get method for copying all color filters in one step.
void iterateThroughCurveSegments(const Functor2wRet< const Point &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
Apply functor to successive Points, as line segments, on Curve. This could be a bit slow...
Definition: Curve.cpp:172
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
void setModelCommon(const DocumentModelCommon &modelCommon)
Set method for DocumentModelCommon.
Definition: Document.cpp:667
void saveXml(QXmlStreamWriter &writer) const
Serialize curve.
Definition: Curve.cpp:379
QString reasonForUnsuccessfulRead() const
Return an informative text message explaining why startup loading failed. Applies if successfulRead r...
Definition: Document.cpp:575
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
static PointStyle defaultGraphCurve(int index)
Initial default for index'th graph curve.
Definition: PointStyle.cpp:57
DocumentModelGridRemoval modelGridRemoval() const
Get method for DocumentModelGridRemoval.
Definition: Document.cpp:470
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:722
DocumentModelExportFormat modelExport() const
Get method for DocumentModelExportFormat.
Definition: Document.cpp:465
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
void checkAddPointAxis(const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling addPointAxis. Also returns the next available ordinal number (to prevent clashes...
Definition: Document.cpp:236
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.