Engauge Digitizer  2
Document.cpp
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 "CallbackAddPointsInCurvesGraphs.h"
8 #include "CallbackBoundingRects.h"
9 #include "CallbackCheckAddPointAxis.h"
10 #include "CallbackCheckEditPointAxis.h"
11 #include "CallbackNextOrdinal.h"
12 #include "CallbackRemovePointsInCurvesGraphs.h"
13 #include "Curve.h"
14 #include "CurvesGraphs.h"
15 #include "CurveStyle.h"
16 #include "CurveStyles.h"
17 #include "Document.h"
18 #include "DocumentSerialize.h"
19 #include "EngaugeAssert.h"
20 #include "EnumsToQt.h"
21 #include "GridInitializer.h"
22 #include <iostream>
23 #include "Logger.h"
24 #include "OrdinalGenerator.h"
25 #include "Point.h"
26 #include "PointStyle.h"
27 #include <QByteArray>
28 #include <QDataStream>
29 #include <QDebug>
30 #include <QDomDocument>
31 #include <QFile>
32 #include <QImage>
33 #include <qmath.h>
34 #include <QObject>
35 #include <QtToString.h>
36 #include <QXmlStreamReader>
37 #include <QXmlStreamWriter>
38 #include "SettingsForGraph.h"
39 #include "Transformation.h"
40 #include "Version.h"
41 #include "Xml.h"
42 
43 const int FOUR_BYTES = 4;
44 const int NOMINAL_COORD_SYSTEM_COUNT = 1;
45 const int VERSION_6 = 6;
46 const int VERSION_7 = 7;
47 const int VERSION_8 = 8;
48 const int VERSION_9 = 9;
49 const int VERSION_10 = 10;
50 
51 Document::Document (const QImage &image) :
52  m_name ("untitled"),
53  m_documentAxesPointsRequired (DOCUMENT_AXES_POINTS_REQUIRED_3)
54 {
55  LOG4CPP_INFO_S ((*mainCat)) << "Document::Document"
56  << " image=" << image.width() << "x" << image.height();
57 
58  m_coordSystemContext.addCoordSystems(NOMINAL_COORD_SYSTEM_COUNT);
59 
60  m_successfulRead = true; // Reading from QImage always succeeds, resulting in empty Document
61 
62  m_pixmap.convertFromImage (image);
63 }
64 
65 Document::Document (const QString &fileName) :
66  m_name (fileName),
67  m_documentAxesPointsRequired (DOCUMENT_AXES_POINTS_REQUIRED_3)
68 {
69  LOG4CPP_INFO_S ((*mainCat)) << "Document::Document"
70  << " fileName=" << fileName.toLatin1().data();
71 
72  m_successfulRead = true;
73 
74  // Grab first few bytes to determine the version number
75  QFile *file = new QFile (fileName);
76  if (file->open(QIODevice::ReadOnly)) {
77 
78  QByteArray bytesStart = file->read (FOUR_BYTES);
79  file->close ();
80 
81  if (bytesIndicatePreVersion6 (bytesStart)) {
82 
83  QFile *file = new QFile (fileName);
84  if (file->open (QIODevice::ReadOnly)) {
85  QDataStream str (file);
86 
87  m_coordSystemContext.addCoordSystems(NOMINAL_COORD_SYSTEM_COUNT);
88  loadPreVersion6 (str);
89 
90  } else {
91 
92  m_successfulRead = false;
93  m_reasonForUnsuccessfulRead = QObject::tr ("Operating system says file is not readable");
94 
95  }
96  } else {
97 
98  QFile *file = new QFile (fileName);
99  if (file->open (QIODevice::ReadOnly | QIODevice::Text)) {
100 
101  int version = versionFromFile (file);
102  switch (version)
103  {
104  case VERSION_6:
105  loadVersion6 (file);
106  break;
107 
108  case VERSION_7:
109  case VERSION_8:
110  case VERSION_9:
111  case VERSION_10:
112  loadVersions7AndUp (file);
113  break;
114 
115  default:
116  m_successfulRead = false;
117  m_reasonForUnsuccessfulRead = QString ("Engauge %1 %2 %3 %4 Engauge")
118  .arg (VERSION_NUMBER)
119  .arg (QObject::tr ("cannot read newer files from version"))
120  .arg (version)
121  .arg (QObject::tr ("of"));
122  break;
123  }
124 
125  // Close and deactivate
126  file->close ();
127  delete file;
128  file = 0;
129 
130  } else {
131 
132  m_successfulRead = false;
133  m_reasonForUnsuccessfulRead = QObject::tr ("Operating system says file is not readable");
134  }
135  }
136  } else {
137  file->close ();
138  m_successfulRead = false;
139  m_reasonForUnsuccessfulRead = QString ("%1 '%2' %3")
140  .arg (QObject::tr ("File"))
141  .arg (fileName)
142  .arg (QObject::tr ("was not found"));
143 
144  }
145 }
146 
147 void Document::addCoordSystems(unsigned int numberCoordSystemToAdd)
148 {
149  LOG4CPP_INFO_S ((*mainCat)) << "Document::addCoordSystems"
150  << " toAdd=" << numberCoordSystemToAdd;
151 
152  m_coordSystemContext.addCoordSystems(numberCoordSystemToAdd);
153 }
154 
155 void Document::addGraphCurveAtEnd (const QString &curveName)
156 {
157  LOG4CPP_INFO_S ((*mainCat)) << "Document::addGraphCurveAtEnd";
158 
159  m_coordSystemContext.addGraphCurveAtEnd (curveName);
160 }
161 
162 void Document::addPointAxisWithGeneratedIdentifier (const QPointF &posScreen,
163  const QPointF &posGraph,
164  QString &identifier,
165  double ordinal,
166  bool isXOnly)
167 {
168  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointAxisWithGeneratedIdentifier";
169 
170  m_coordSystemContext.addPointAxisWithGeneratedIdentifier(posScreen,
171  posGraph,
172  identifier,
173  ordinal,
174  isXOnly);
175 }
176 
177 void Document::addPointAxisWithSpecifiedIdentifier (const QPointF &posScreen,
178  const QPointF &posGraph,
179  const QString &identifier,
180  double ordinal,
181  bool isXOnly)
182 {
183  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointAxisWithSpecifiedIdentifier";
184 
185  m_coordSystemContext.addPointAxisWithSpecifiedIdentifier(posScreen,
186  posGraph,
187  identifier,
188  ordinal,
189  isXOnly);
190 }
191 
192 void Document::addPointGraphWithGeneratedIdentifier (const QString &curveName,
193  const QPointF &posScreen,
194  QString &identifier,
195  double ordinal)
196 {
197  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointGraphWithGeneratedIdentifier";
198 
199  m_coordSystemContext.addPointGraphWithGeneratedIdentifier(curveName,
200  posScreen,
201  identifier,
202  ordinal);
203 }
204 
205 void Document::addPointGraphWithSpecifiedIdentifier (const QString &curveName,
206  const QPointF &posScreen,
207  const QString &identifier,
208  double ordinal)
209 {
210  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointGraphWithSpecifiedIdentifier";
211 
212  m_coordSystemContext.addPointGraphWithSpecifiedIdentifier(curveName,
213  posScreen,
214  identifier,
215  ordinal);
216 }
217 
219 {
220  LOG4CPP_INFO_S ((*mainCat)) << "Document::addPointsInCurvesGraphs";
221 
222  m_coordSystemContext.addPointsInCurvesGraphs(curvesGraphs);
223 }
224 
225 void Document::addScaleWithGeneratedIdentifier (const QPointF &posScreen0,
226  const QPointF &posScreen1,
227  double scaleLength,
228  QString &identifier0,
229  QString &identifier1,
230  double ordinal0,
231  double ordinal1)
232 {
233  LOG4CPP_INFO_S ((*mainCat)) << "Document::addScaleWithGeneratedIdentifier";
234 
235  const bool IS_X_ONLY = false;
236 
237  m_coordSystemContext.addPointAxisWithGeneratedIdentifier(posScreen0,
238  QPointF (0, 0),
239  identifier0,
240  ordinal0,
241  IS_X_ONLY);
242  m_coordSystemContext.addPointAxisWithGeneratedIdentifier(posScreen1,
243  QPointF (scaleLength, 0),
244  identifier1,
245  ordinal1,
246  IS_X_ONLY);
247 }
248 
249 bool Document::bytesIndicatePreVersion6 (const QByteArray &bytes) const
250 {
251  LOG4CPP_INFO_S ((*mainCat)) << "Document::bytesIndicatePreVersion6";
252 
253  QByteArray preVersion6MagicNumber;
254  preVersion6MagicNumber.resize (FOUR_BYTES);
255 
256  // Windows compiler gives warning if 0x## is used instead of '\x##' below
257  preVersion6MagicNumber[0] = '\x00';
258  preVersion6MagicNumber[1] = '\x00';
259  preVersion6MagicNumber[2] = '\xCA';
260  preVersion6MagicNumber[3] = '\xFE';
261 
262  return (bytes == preVersion6MagicNumber);
263 }
264 
265 void Document::checkAddPointAxis (const QPointF &posScreen,
266  const QPointF &posGraph,
267  bool &isError,
268  QString &errorMessage,
269  bool isXOnly)
270 {
271  LOG4CPP_INFO_S ((*mainCat)) << "Document::checkAddPointAxis";
272 
273  m_coordSystemContext.checkAddPointAxis(posScreen,
274  posGraph,
275  isError,
276  errorMessage,
277  isXOnly,
278  m_documentAxesPointsRequired);
279 }
280 
281 void Document::checkEditPointAxis (const QString &pointIdentifier,
282  const QPointF &posScreen,
283  const QPointF &posGraph,
284  bool &isError,
285  QString &errorMessage)
286 {
287  LOG4CPP_INFO_S ((*mainCat)) << "Document::checkEditPointAxis";
288 
289  m_coordSystemContext.checkEditPointAxis(pointIdentifier,
290  posScreen,
291  posGraph,
292  isError,
293  errorMessage,
294  m_documentAxesPointsRequired);
295 }
296 
298 {
299  LOG4CPP_INFO_S ((*mainCat)) << "Document::coordSystem";
300 
301  return m_coordSystemContext.coordSystem();
302 }
303 
304 unsigned int Document::coordSystemCount () const
305 {
306  LOG4CPP_INFO_S ((*mainCat)) << "Document::coordSystemCount";
307 
308  return m_coordSystemContext.coordSystemCount();
309 }
310 
311 CoordSystemIndex Document::coordSystemIndex() const
312 {
313  LOG4CPP_INFO_S ((*mainCat)) << "Document::coordSystemIndex";
314 
315  return m_coordSystemContext.coordSystemIndex();
316 }
317 
318 const Curve &Document::curveAxes () const
319 {
320  LOG4CPP_INFO_S ((*mainCat)) << "Document::curveAxes";
321 
322  return m_coordSystemContext.curveAxes();
323 }
324 
325 Curve *Document::curveForCurveName (const QString &curveName)
326 {
327  LOG4CPP_INFO_S ((*mainCat)) << "Document::curveForCurveName";
328 
329  return m_coordSystemContext.curveForCurveName(curveName);
330 }
331 
332 const Curve *Document::curveForCurveName (const QString &curveName) const
333 {
334  LOG4CPP_INFO_S ((*mainCat)) << "Document::curveForCurveName";
335 
336  return m_coordSystemContext.curveForCurveName (curveName);
337 }
338 
340 {
341  LOG4CPP_INFO_S ((*mainCat)) << "Document::curvesGraphs";
342 
343  return m_coordSystemContext.curvesGraphs();
344 }
345 
346 QStringList Document::curvesGraphsNames() const
347 {
348  LOG4CPP_INFO_S ((*mainCat)) << "Document::curvesGraphsNames";
349 
350  return m_coordSystemContext.curvesGraphsNames();
351 }
352 
353 int Document::curvesGraphsNumPoints(const QString &curveName) const
354 {
355  LOG4CPP_INFO_S ((*mainCat)) << "Document::curvesGraphsNumPoints";
356 
357  return m_coordSystemContext.curvesGraphsNumPoints(curveName);
358 }
359 
360 DocumentAxesPointsRequired Document::documentAxesPointsRequired () const
361 {
362  return m_documentAxesPointsRequired;
363 }
364 
365 void Document::editPointAxis (const QPointF &posGraph,
366  const QString &identifier)
367 {
368  LOG4CPP_INFO_S ((*mainCat)) << "Document::editPointAxis";
369 
370  m_coordSystemContext.editPointAxis(posGraph,
371  identifier);
372 }
373 
375  bool isY,
376  double x,
377  double y,
378  const QStringList &identifiers,
379  const Transformation &transformation)
380 {
381  LOG4CPP_INFO_S ((*mainCat)) << "Document::editPointCurve";
382 
383  m_coordSystemContext.editPointGraph (isX,
384  isY,
385  x,
386  y,
387  identifiers,
388  transformation);
389 }
390 
391 void Document::generateEmptyPixmap(const QXmlStreamAttributes &attributes)
392 {
393  LOG4CPP_INFO_S ((*mainCat)) << "Document::generateEmptyPixmap";
394 
395  int width = 800, height = 500; // Defaults
396 
397  if (attributes.hasAttribute (DOCUMENT_SERIALIZE_IMAGE_WIDTH) &&
398  attributes.hasAttribute (DOCUMENT_SERIALIZE_IMAGE_HEIGHT)) {
399 
400  width = attributes.value (DOCUMENT_SERIALIZE_IMAGE_WIDTH).toInt();
401  height = attributes.value (DOCUMENT_SERIALIZE_IMAGE_HEIGHT).toInt();
402 
403  }
404 
405  m_pixmap = QPixmap (width, height);
406 }
407 
409 {
410  LOG4CPP_INFO_S ((*mainCat)) << "Document::initializeGridDisplay";
411 
412  ENGAUGE_ASSERT (!m_coordSystemContext.modelGridDisplay().stable());
413 
414  // Get graph coordinate bounds
415  CallbackBoundingRects ftor (transformation);
416 
417  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
419 
420  iterateThroughCurvePointsAxes (ftorWithCallback);
421 
422  // Initialize. Note that if there are no graph points then these next steps have no effect
423  bool isEmpty;
424  QRectF boundingRectGraph = ftor.boundingRectGraph(isEmpty);
425  if (!isEmpty) {
426 
427  GridInitializer gridInitializer;
428 
430  modelCoords(),
431  transformation,
432  m_pixmap.size ());
433 
434  m_coordSystemContext.setModelGridDisplay (modelGridDisplay);
435  }
436 }
437 
438 bool Document::isXOnly (const QString &pointIdentifier) const
439 {
440  return m_coordSystemContext.isXOnly (pointIdentifier);
441 }
442 
443 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
444 {
445  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvePointsAxes";
446 
447  m_coordSystemContext.iterateThroughCurvePointsAxes(ftorWithCallback);
448 }
449 
450 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
451 {
452  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvePointsAxes";
453 
454  m_coordSystemContext.iterateThroughCurvePointsAxes(ftorWithCallback);
455 }
456 
457 void Document::iterateThroughCurveSegments (const QString &curveName,
458  const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
459 {
460  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurveSegments";
461 
462  m_coordSystemContext.iterateThroughCurveSegments(curveName,
463  ftorWithCallback);
464 }
465 
466 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
467 {
468  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvesPointsGraphs";
469 
470  m_coordSystemContext.iterateThroughCurvesPointsGraphs(ftorWithCallback);
471 }
472 
473 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
474 {
475  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvesPointsGraphs";
476 
477  m_coordSystemContext.iterateThroughCurvesPointsGraphs(ftorWithCallback);
478 }
479 
480 void Document::loadImage(QXmlStreamReader &reader)
481 {
482  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadImage";
483 
484  loadNextFromReader(reader); // Read to CDATA
485  if (reader.isCDATA ()) {
486 
487  // Get base64 array
488  QByteArray array64 = reader.text().toString().toUtf8();
489 
490  // Decoded array
491  QByteArray array;
492  array = QByteArray::fromBase64(array64);
493 
494  // Read decoded array into image
495  QDataStream str (&array, QIODevice::ReadOnly);
496  QImage img = m_pixmap.toImage ();
497  str >> img;
498  m_pixmap = QPixmap::fromImage (img);
499 
500  // Read until end of this subtree
501  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
502  (reader.name() != DOCUMENT_SERIALIZE_IMAGE)){
503  loadNextFromReader(reader);
504  }
505 
506  } else {
507 
508  // This point can be reached if:
509  // 1) File is broken
510  // 2) Bad character is in text, and NetworkClient::cleanXml did not do its job
511  reader.raiseError (QObject::tr ("Cannot read image data"));
512  }
513 }
514 
515 void Document::loadPreVersion6 (QDataStream &str)
516 {
517  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadPreVersion6";
518 
519  qint32 int32;
520  double version;
521  QString st;
522 
523  str >> int32; // Magic number
524  str >> version;
525  str >> st; // Version string
526  str >> int32; // Background
527  str >> m_pixmap;
528  str >> m_name;
529 
530  m_coordSystemContext.loadPreVersion6 (str,
531  version,
532  m_documentAxesPointsRequired); // Returns axes points required
533 }
534 
535 void Document::loadVersion6 (QFile *file)
536 {
537  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadVersion6";
538 
539  QXmlStreamReader reader (file);
540 
541  m_documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
542 
543  // Create the single CoordSystem used in versions before version 7
544  m_coordSystemContext.addCoordSystems(NOMINAL_COORD_SYSTEM_COUNT);
545 
546  // If this is purely a serialized Document then we process every node under the root. However, if this is an error report file
547  // then we need to skip the non-Document stuff. The common solution is to skip nodes outside the Document subtree using this flag
548  bool inDocumentSubtree = false;
549 
550  // Import from xml. Loop to end of data or error condition occurs, whichever is first
551  while (!reader.atEnd() &&
552  !reader.hasError()) {
553  QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
554 
555  // Special processing of DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT, for an error report file
556  if ((reader.name() == DOCUMENT_SERIALIZE_IMAGE) &&
557  (tokenType == QXmlStreamReader::StartElement)) {
558 
559  generateEmptyPixmap (reader.attributes());
560  }
561 
562  // Branching to skip non-Document nodes, with the exception of any DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT
563  if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
564  (tokenType == QXmlStreamReader::StartElement)) {
565 
566  inDocumentSubtree = true;
567 
568  } else if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
569  (tokenType == QXmlStreamReader::EndElement)) {
570 
571  // Exit out of loop immediately
572  break;
573  }
574 
575  if (inDocumentSubtree) {
576 
577  // Iterate to next StartElement
578  if (tokenType == QXmlStreamReader::StartElement) {
579 
580  // This is a StartElement, so process it
581  QString tag = reader.name().toString();
582  if (tag == DOCUMENT_SERIALIZE_IMAGE) {
583  // A standard Document file has DOCUMENT_SERIALIZE_IMAGE inside DOCUMENT_SERIALIZE_DOCUMENT, versus an error report file
584  loadImage(reader);
585 
586  // Now that we have the image at the DOCUMENT_SERIALIZE_DOCUMENT level, we read the rest at this level into CoordSystem
587  m_coordSystemContext.loadVersion6 (reader,
588  m_documentAxesPointsRequired); // Returns axes points required
589 
590  // Reading of DOCUMENT_SERIALIZE_DOCUMENT has just finished, so the reading has finished
591  break;
592  }
593  }
594  }
595  }
596  if (reader.hasError ()) {
597 
598  m_successfulRead = false;
599  m_reasonForUnsuccessfulRead = reader.errorString();
600  }
601 
602  // There are already one axes curve and at least one graph curve so we do not need to add any more graph curves
603 }
604 
605 void Document::loadVersions7AndUp (QFile *file)
606 {
607  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadVersions7AndUp";
608 
609  const int ONE_COORDINATE_SYSTEM = 1;
610 
611  QXmlStreamReader reader (file);
612 
613  // If this is purely a serialized Document then we process every node under the root. However, if this is an error report file
614  // then we need to skip the non-Document stuff. The common solution is to skip nodes outside the Document subtree using this flag
615  bool inDocumentSubtree = false;
616 
617  // Import from xml. Loop to end of data or error condition occurs, whichever is first
618  while (!reader.atEnd() &&
619  !reader.hasError()) {
620  QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
621 
622  // Special processing of DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT, for an error report file
623  if ((reader.name() == DOCUMENT_SERIALIZE_IMAGE) &&
624  (tokenType == QXmlStreamReader::StartElement)) {
625 
626  generateEmptyPixmap (reader.attributes());
627  }
628 
629  // Branching to skip non-Document nodes, with the exception of any DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT
630  if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
631  (tokenType == QXmlStreamReader::StartElement)) {
632 
633  inDocumentSubtree = true;
634 
635  QXmlStreamAttributes attributes = reader.attributes();
636  if (attributes.hasAttribute (DOCUMENT_SERIALIZE_AXES_POINTS_REQUIRED)) {
637  m_documentAxesPointsRequired = (DocumentAxesPointsRequired) attributes.value (DOCUMENT_SERIALIZE_AXES_POINTS_REQUIRED).toInt();
638  } else {
639  m_documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
640  }
641 
642  } else if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
643  (tokenType == QXmlStreamReader::EndElement)) {
644 
645  // Exit out of loop immediately
646  break;
647  }
648 
649  if (inDocumentSubtree) {
650 
651  // Iterate to next StartElement
652  if (tokenType == QXmlStreamReader::StartElement) {
653 
654  // This is a StartElement, so process it
655  QString tag = reader.name().toString();
656  if (tag == DOCUMENT_SERIALIZE_COORD_SYSTEM) {
657  m_coordSystemContext.addCoordSystems (ONE_COORDINATE_SYSTEM);
658  m_coordSystemContext.loadVersions7AndUp (reader);
659  } else if (tag == DOCUMENT_SERIALIZE_IMAGE) {
660  // A standard Document file has DOCUMENT_SERIALIZE_IMAGE inside DOCUMENT_SERIALIZE_DOCUMENT, versus an error report file
661  loadImage(reader);
662  }
663  }
664  }
665  }
666  if (reader.hasError ()) {
667 
668  m_successfulRead = false;
669  m_reasonForUnsuccessfulRead = reader.errorString();
670  }
671 
672  // There are already one axes curve and at least one graph curve so we do not need to add any more graph curves
673 }
674 
676 {
677  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelAxesChecker";
678 
679  return m_coordSystemContext.modelAxesChecker();
680 }
681 
683 {
684  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelColorFilter";
685 
686  return m_coordSystemContext.modelColorFilter();
687 }
688 
690 {
691  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelCoords";
692 
693  return m_coordSystemContext.modelCoords();
694 }
695 
697 {
698  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelCurveStyles";
699 
700  return m_coordSystemContext.modelCurveStyles();
701 }
702 
704 {
705  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelDigitizeCurve";
706 
707  return m_coordSystemContext.modelDigitizeCurve();
708 }
709 
711 {
712  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelExport";
713 
714  return m_coordSystemContext.modelExport();
715 }
716 
718 {
719  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelGeneral";
720 
721  return m_coordSystemContext.modelGeneral();
722 }
723 
725 {
726  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelGridDisplay";
727 
728  return m_coordSystemContext.modelGridDisplay();
729 }
730 
732 {
733  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelGridRemoval";
734 
735  return m_coordSystemContext.modelGridRemoval();
736 }
737 
739 {
740  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelPointMatch";
741 
742  return m_coordSystemContext.modelPointMatch();
743 }
744 
746 {
747  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelSegments";
748 
749  return m_coordSystemContext.modelSegments();
750 }
751 
752 void Document::movePoint (const QString &pointIdentifier,
753  const QPointF &deltaScreen)
754 {
755  m_coordSystemContext.movePoint (pointIdentifier,
756  deltaScreen);
757 }
758 
759 int Document::nextOrdinalForCurve (const QString &curveName) const
760 {
761  LOG4CPP_INFO_S ((*mainCat)) << "Document::nextOrdinalForCurve";
762 
763  return m_coordSystemContext.nextOrdinalForCurve(curveName);
764 }
765 
766 void Document::overrideGraphDefaultsWithMapDefaults ()
767 {
768  const int DEFAULT_WIDTH = 1;
769 
770  // Axis style for scale bar is better with transparent-filled circles so user can more accurately place them,
771  // and a visible line between the points also helps to make the points more visible
772  CurveStyles curveStyles = modelCurveStyles ();
773 
774  CurveStyle curveStyle = curveStyles.curveStyle (AXIS_CURVE_NAME);
775 
776  PointStyle pointStyle = curveStyle.pointStyle ();
777  pointStyle.setShape (POINT_SHAPE_CIRCLE);
778  pointStyle.setPaletteColor (COLOR_PALETTE_RED);
779 
780  LineStyle lineStyle = curveStyle.lineStyle ();
781  lineStyle.setCurveConnectAs (CONNECT_AS_RELATION_STRAIGHT);
782  lineStyle.setWidth (DEFAULT_WIDTH);
783  lineStyle.setPaletteColor (COLOR_PALETTE_RED);
784 
785  curveStyle.setPointStyle (pointStyle);
786  curveStyle.setLineStyle (lineStyle);
787 
788  curveStyles.setCurveStyle (AXIS_CURVE_NAME,
789  curveStyle);
790 
791  // Change all graph curves from functions to relations
792  QStringList curveNames = curvesGraphsNames ();
793  QStringList::const_iterator itr;
794  for (itr = curveNames.begin(); itr != curveNames.end(); itr++) {
795  QString curveName = *itr;
796  CurveStyle curveStyle = curveStyles.curveStyle (curveName);
797 
798  LineStyle lineStyle = curveStyle.lineStyle ();
799  lineStyle.setCurveConnectAs (CONNECT_AS_RELATION_STRAIGHT);
800 
801  curveStyle.setLineStyle (lineStyle);
802 
803  curveStyles.setCurveStyle (curveName,
804  curveStyle);
805  }
806 
807  // Save modified curve styles into Document
808  setModelCurveStyles (curveStyles);
809 }
810 
811 QPixmap Document::pixmap () const
812 {
813  return m_pixmap;
814 }
815 
816 QPointF Document::positionGraph (const QString &pointIdentifier) const
817 {
818  return m_coordSystemContext.positionGraph(pointIdentifier);
819 }
820 
821 QPointF Document::positionScreen (const QString &pointIdentifier) const
822 {
823  return m_coordSystemContext.positionScreen(pointIdentifier);
824 }
825 
826 void Document::print () const
827 {
828  QString text;
829  QTextStream str (&text);
830 
831  printStream ("",
832  str);
833  std::cerr << text.toLatin1().data();
834 }
835 
836 void Document::printStream (QString indentation,
837  QTextStream &str) const
838 {
839  str << indentation << "Document\n";
840 
841  indentation += INDENTATION_DELTA;
842 
843  str << indentation << "name=" << m_name << "\n";
844  str << indentation << "pixmap=" << m_pixmap.width() << "x" << m_pixmap.height() << "\n";
845 
846  m_coordSystemContext.printStream(indentation,
847  str);
848 }
849 
851 {
852  ENGAUGE_ASSERT (!m_successfulRead);
853 
854  return m_reasonForUnsuccessfulRead;
855 }
856 
857 void Document::removePointAxis (const QString &identifier)
858 {
859  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointAxis";
860 
861  m_coordSystemContext.removePointAxis(identifier);
862 }
863 
864 void Document::removePointGraph (const QString &identifier)
865 {
866  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointGraph";
867 
868  m_coordSystemContext.removePointGraph(identifier);
869 }
870 
872 {
873  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointsInCurvesGraphs";
874 
875  m_coordSystemContext.removePointsInCurvesGraphs(curvesGraphs);
876 }
877 
878 void Document::saveXml (QXmlStreamWriter &writer) const
879 {
880  writer.writeStartElement(DOCUMENT_SERIALIZE_DOCUMENT);
881 
882  // Version number is tacked onto DOCUMENT_SERIALIZE_DOCUMENT since the alternative (creating a new start element)
883  // causes the code to complain during loading
884  writer.writeAttribute(DOCUMENT_SERIALIZE_APPLICATION_VERSION_NUMBER, VERSION_NUMBER);
885 
886  // Number of axes points required
887  writer.writeAttribute(DOCUMENT_SERIALIZE_AXES_POINTS_REQUIRED, QString::number (m_documentAxesPointsRequired));
888 
889  // Serialize the Document image. That binary data is encoded as base64
890  QByteArray array;
891  QDataStream str (&array, QIODevice::WriteOnly);
892  QImage img = m_pixmap.toImage ();
893  str << img;
894  writer.writeStartElement(DOCUMENT_SERIALIZE_IMAGE);
895 
896  // Image width and height are explicitly inserted for error reports, since the CDATA is removed
897  // but we still want the image size for reconstructing the error(s)
898  writer.writeAttribute(DOCUMENT_SERIALIZE_IMAGE_WIDTH, QString::number (img.width()));
899  writer.writeAttribute(DOCUMENT_SERIALIZE_IMAGE_HEIGHT, QString::number (img.height()));
900 
901  writer.writeCDATA (array.toBase64 ());
902  writer.writeEndElement();
903 
904  m_coordSystemContext.saveXml (writer);
905 }
906 
908 {
909  return m_coordSystemContext.selectedCurveName();
910 }
911 
913 {
914  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCoordSystemIndex";
915 
916  m_coordSystemContext.setCoordSystemIndex (coordSystemIndex);
917 }
918 
920 {
921  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCurveAxes";
922 
923  m_coordSystemContext.setCurveAxes (curveAxes);
924 }
925 
927 {
928  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCurvesGraphs";
929 
930  m_coordSystemContext.setCurvesGraphs(curvesGraphs);
931 }
932 
934 {
935  LOG4CPP_INFO_S ((*mainCat)) << "Document::setDocumentAxesPointsRequired";
936 
937  m_documentAxesPointsRequired = documentAxesPointsRequired;
938 
939  if (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_2) {
940 
941  overrideGraphDefaultsWithMapDefaults ();
942  }
943 }
944 
946 {
947  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelAxesChecker";
948 
949  m_coordSystemContext.setModelAxesChecker(modelAxesChecker);
950 }
951 
953 {
954  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelColorFilter";
955 
956  // Save the CurveFilter for each Curve
957  ColorFilterSettingsList::const_iterator itr;
958  for (itr = modelColorFilter.colorFilterSettingsList().constBegin ();
959  itr != modelColorFilter.colorFilterSettingsList().constEnd();
960  itr++) {
961 
962  QString curveName = itr.key();
963  const ColorFilterSettings &colorFilterSettings = itr.value();
964 
965  Curve *curve = curveForCurveName (curveName);
966  curve->setColorFilterSettings (colorFilterSettings);
967  }
968 }
969 
971 {
972  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelCoords";
973 
974  m_coordSystemContext.setModelCoords(modelCoords);
975 }
976 
978 {
979  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelCurveStyles";
980 
981  // Save the LineStyle and PointStyle for each Curve
982  QStringList curveNames = modelCurveStyles.curveNames();
983  QStringList::iterator itr;
984  for (itr = curveNames.begin(); itr != curveNames.end(); itr++) {
985 
986  QString curveName = *itr;
987  const CurveStyle &curveStyle = modelCurveStyles.curveStyle (curveName);
988 
989  Curve *curve = curveForCurveName (curveName);
990  curve->setCurveStyle (curveStyle);
991  }
992 }
993 
995 {
996  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelDigitizeCurve";
997 
998  m_coordSystemContext.setModelDigitizeCurve(modelDigitizeCurve);
999 }
1000 
1002 {
1003  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelExport";
1004 
1005  m_coordSystemContext.setModelExport (modelExport);
1006 }
1007 
1009 {
1010  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelGeneral";
1011 
1012  m_coordSystemContext.setModelGeneral(modelGeneral);
1013 }
1014 
1016 {
1017  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelGridDisplay";
1018 
1019  m_coordSystemContext.setModelGridDisplay(modelGridDisplay);
1020 }
1021 
1023 {
1024  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelGridRemoval";
1025 
1026  m_coordSystemContext.setModelGridRemoval(modelGridRemoval);
1027 }
1028 
1030 {
1031  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelPointMatch";
1032 
1033  m_coordSystemContext.setModelPointMatch(modelPointMatch);
1034 }
1035 
1037 {
1038  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelSegments";
1039 
1040  m_coordSystemContext.setModelSegments (modelSegments);
1041 }
1042 
1043 void Document::setPixmap(const QImage &image)
1044 {
1045  LOG4CPP_INFO_S ((*mainCat)) << "Document::setPixmap";
1046 
1047  m_pixmap = QPixmap::fromImage (image);
1048 }
1049 
1051 {
1052  m_coordSystemContext.setSelectedCurveName (selectedCurveName);
1053 }
1054 
1056 {
1057  return m_successfulRead;
1058 }
1059 
1060 void Document::updatePointOrdinals (const Transformation &transformation)
1061 {
1062  LOG4CPP_INFO_S ((*mainCat)) << "Document::updatePointOrdinals";
1063 
1064  m_coordSystemContext.updatePointOrdinals(transformation);
1065 }
1066 
1067 int Document::versionFromFile (QFile *file) const
1068 {
1069  LOG4CPP_INFO_S ((*mainCat)) << "Document::versionFromFile";
1070 
1071  int version = VERSION_6; // Use default if tag is missing
1072 
1073  QDomDocument doc;
1074  if (doc.setContent (file)) {
1075 
1076  QDomNodeList nodes = doc.elementsByTagName (DOCUMENT_SERIALIZE_DOCUMENT);
1077  if (nodes.count() > 0) {
1078  QDomNode node = nodes.at (0);
1079 
1080  QDomNamedNodeMap attributes = node.attributes();
1081 
1082  if (attributes.contains (DOCUMENT_SERIALIZE_APPLICATION_VERSION_NUMBER)) {
1083 
1084  QDomElement elem = node.toElement();
1085  version = (int) elem.attribute (DOCUMENT_SERIALIZE_APPLICATION_VERSION_NUMBER).toDouble();
1086  }
1087  }
1088  }
1089 
1090  file->seek (0); // Go back to beginning
1091 
1092  return version;
1093 }
void addCoordSystems(unsigned int numberCoordSystemToAdd)
Add some number (0 or more) of additional coordinate systems.
Definition: Document.cpp:147
void addGraphCurveAtEnd(const QString &curveName)
Add new graph curve to the list of existing graph curves.
Definition: Document.cpp:155
const ColorFilterSettingsList & colorFilterSettingsList() const
Get method for copying all color filters in one step.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
CurveStyle curveStyle(const QString &curveName) const
CurveStyle in specified curve.
Definition: CurveStyles.cpp:79
void addCoordSystems(unsigned int numberCoordSystemToAdd)
Add specified number of coordinate systems to the original one created by the constructor.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
int curvesGraphsNumPoints(const QString &curveName) const
See CurvesGraphs::curvesGraphsNumPoints.
Definition: Document.cpp:353
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
See Curve::movePoint.
Definition: Document.cpp:752
const CoordSystem & coordSystem() const
Currently active CoordSystem.
Definition: Document.cpp:297
virtual int curvesGraphsNumPoints(const QString &curveName) const
See CurvesGraphs::curvesGraphsNumPoints.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void setModelAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
Set method for DocumentModelAxesChecker.
Definition: Document.cpp:945
void setModelGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
Set method for DocumentModelGridRemoval.
Definition: Document.cpp:1022
virtual void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
virtual DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
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:192
virtual DocumentModelGridDisplay modelGridDisplay() const
Get method for DocumentModelGridDisplay.
void setCurveStyle(const CurveStyle &curveStyle)
Set curve style.
Definition: Curve.cpp:563
void setModelPointMatch(const DocumentModelPointMatch &modelPointMatch)
Set method for DocumentModelPointMatch.
Definition: Document.cpp:1029
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
void removePointAxis(const QString &identifier)
Perform the opposite of addPointAxis.
Definition: Document.cpp:857
void setModelGeneral(const DocumentModelGeneral &modelGeneral)
Set method for DocumentModelGeneral.
Definition: Document.cpp:1008
QStringList curveNames() const
List of all curve names.
Definition: CurveStyles.cpp:67
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Definition: CurveStyles.h:22
DocumentModelGridRemoval modelGridRemoval() const
Get method for DocumentModelGridRemoval.
Definition: Document.cpp:731
virtual void editPointAxis(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of a single axis point. Call this after checkAddPointAxis to guarantee suc...
void setModelSegments(const DocumentModelSegments &modelSegments)
Set method for DocumentModelSegments.
Definition: Document.cpp:1036
virtual void saveXml(QXmlStreamWriter &writer) const
Save graph to xml.
virtual DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition: Document.cpp:759
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings)
Set color filter.
Definition: Curve.cpp:546
bool successfulRead() const
Return true if startup loading succeeded. If the loading failed then reasonForUnsuccessfulRed will ex...
Definition: Document.cpp:1055
virtual 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...
virtual DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
Storage of data belonging to one coordinate system.
Definition: CoordSystem.h:42
PointStyle pointStyle() const
Get method for PointStyle.
Definition: CurveStyle.cpp:75
virtual DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
void setModelGridDisplay(const DocumentModelGridDisplay &modelGridDisplay)
Set method for DocumentModelGridDisplay.
Definition: Document.cpp:1015
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:205
void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the axes curve.
Definition: Document.cpp:443
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
Definition: Document.cpp:332
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Definition: Document.cpp:717
virtual void checkAddPointAxis(const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage, bool isXOnly, DocumentAxesPointsRequired documentAxesPointsRequired)
Check before calling addPointAxis. Also returns the next available ordinal number (to prevent clashes...
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition: Document.cpp:360
virtual Curve * curveForCurveName(const QString &curveName)
See CurvesGraphs::curveForCurveName, although this also works for AXIS_CURVE_NAME.
DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
Definition: Document.cpp:682
virtual DocumentModelAxesChecker modelAxesChecker() const
Get method for DocumentModelAxesChecker.
void setModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Set method for DocumentModelDigitizeCurve.
Definition: Document.cpp:994
unsigned int coordSystemCount() const
Number of CoordSystem.
virtual void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
void addScaleWithGeneratedIdentifier(const QPointF &posScreen0, const QPointF &posScreen1, double scaleLength, QString &identifier0, QString &identifier1, double ordinal0, double ordinal1)
Add scale with a generated point identifier.
Definition: Document.cpp:225
void loadVersions7AndUp(QXmlStreamReader &reader)
Load one CoordSystem from file in version 7 format or newer, into the most recent CoordSystem which w...
void setLineStyle(const LineStyle &lineStyle)
Set method for LineStyle.
Definition: CurveStyle.cpp:115
void setModelCoords(const DocumentModelCoords &modelCoords)
Set method for DocumentModelCoords.
Definition: Document.cpp:970
bool stable() const
Get method for stable flag.
DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
Definition: Document.cpp:738
virtual void setModelCoords(const DocumentModelCoords &modelCoords)
Set method for DocumentModelCoords.
CoordSystemIndex coordSystemIndex() const
Index of current CoordSystem.
void checkAddPointAxis(const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage, bool isXOnly)
Check before calling addPointAxis. Also returns the next available ordinal number (to prevent clashes...
Definition: Document.cpp:265
void setPixmap(const QImage &image)
Set method for the background pixmap.
Definition: Document.cpp:1043
virtual CurveStyles modelCurveStyles() const
Get method for CurveStyles.
void checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling editPointAxis.
Definition: Document.cpp:281
virtual void setSelectedCurveName(const QString &selectedCurveName)
Save curve name that is selected for the current coordinate system, for the next time the coordinate ...
virtual void setModelGridDisplay(const DocumentModelGridDisplay &modelGridDisplay)
Set method for DocumentModelGridDisplay.
virtual void addPointAxisWithGeneratedIdentifier(const QPointF &posScreen, const QPointF &posGraph, QString &identifier, double ordinal, bool isXOnly)
Add a single axis point with a generated point identifier.
void setCoordSystemIndex(CoordSystemIndex coordSystemIndex)
Set the index of current active CoordSystem.
Definition: Document.cpp:912
void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
Definition: Document.cpp:864
virtual int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
virtual void setCurvesGraphs(const CurvesGraphs &curvesGraphs)
Let CmdAbstract classes overwrite CurvesGraphs. Applies to current coordinate system.
virtual void setCurveAxes(const Curve &curveAxes)
Let CmdAbstract classes overwrite axes Curve. Applies to current coordinate system.
void setCurveStyle(const QString &curveName, const CurveStyle &curveStyle)
Set method for curve style.
virtual void setModelGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
Set method for DocumentModelGridRemoval.
void setModelExport(const DocumentModelExportFormat &modelExport)
Set method for DocumentModelExportFormat.
Definition: Document.cpp:1001
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition: Document.cpp:703
void setShape(PointShape shape)
Set method for point shape.
Definition: PointStyle.cpp:287
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
bool isXOnly(const QString &pointIdentifier) const
True/false if y/x value is empty.
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:365
virtual void setModelAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
Set method for DocumentModelAxesChecker.
Affine transformation between screen and graph coordinates, based on digitized axis points...
DocumentModelGridDisplay initializeWithWidePolarCoverage(const QRectF &boundingRectGraph, const DocumentModelCoords &modelCoords, const Transformation &transformation, const QSize &imageSize) const
Initialize given the boundaries of the graph coordinates, and then extra processing for polar coordin...
Details for a specific Point.
Definition: PointStyle.h:20
Container for all graph curves. The axes point curve is external to this class.
Definition: CurvesGraphs.h:24
Model for DlgSettingsColorFilter and CmdSettingsColorFilter.
virtual void checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage, DocumentAxesPointsRequired documentAxesPointsRequired)
Check before calling editPointAxis.
virtual void setModelExport(const DocumentModelExportFormat &modelExport)
Set method for DocumentModelExportFormat.
void setModelPointMatch(const DocumentModelPointMatch &modelPointMatch)
Set method for DocumentModelPointMatch.
virtual void addPointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Add all points identified in the specified CurvesGraphs. See also removePointsInCurvesGraphs.
void setModelCurveStyles(const CurveStyles &modelCurveStyles)
Set method for CurveStyles.
Definition: Document.cpp:977
void addPointAxisWithSpecifiedIdentifier(const QPointF &posScreen, const QPointF &posGraph, const QString &identifier, double ordinal, bool isXOnly)
Add a single axis point with the specified point identifier.
Definition: Document.cpp:177
virtual void addGraphCurveAtEnd(const QString &curveName)
Add new graph curve to the list of existing graph curves.
void setCurveAxes(const Curve &curveAxes)
Let CmdAbstract classes overwrite axes Curve.
Definition: Document.cpp:919
CoordSystemIndex coordSystemIndex() const
Index of current active CoordSystem.
Definition: Document.cpp:311
void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
Definition: Document.cpp:871
This class initializes the count, start, step and stop parameters for one coordinate (either x/theta ...
LineStyle lineStyle() const
Get method for LineStyle.
Definition: CurveStyle.cpp:26
virtual void setModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Set method for DocumentModelDigitizeCurve.
DocumentModelSegments modelSegments() const
Get method for DocumentModelSegments.
Definition: Document.cpp:745
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
Definition: Document.cpp:821
virtual void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
DocumentModelGridDisplay modelGridDisplay() const
Get method for DocumentModelGridDisplay.
Definition: Document.cpp:724
virtual void setModelSegments(const DocumentModelSegments &modelSegments)
Set method for DocumentModelSegments.
void setModelColorFilter(const DocumentModelColorFilter &modelColorFilter)
Set method for DocumentModelColorFilter.
Definition: Document.cpp:952
virtual DocumentModelSegments modelSegments() const
Get method for DocumentModelSegments.
Model for DlgSettingsCoords and CmdSettingsCoords.
virtual void removePointAxis(const QString &identifier)
Perform the opposite of addPointAxis.
Container for LineStyle and PointStyle for one Curve.
Definition: CurveStyle.h:18
void setPaletteColor(ColorPalette paletteColor)
Set method for point color.
Definition: PointStyle.cpp:277
Container for one set of digitized Points.
Definition: Curve.h:33
Details for a specific Line.
Definition: LineStyle.h:19
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:836
virtual const Curve & curveAxes() const
Get method for axis curve.
virtual void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
virtual const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
QString reasonForUnsuccessfulRead() const
Return an informative text message explaining why startup loading failed. Applies if successfulRead r...
Definition: Document.cpp:850
Model for DlgSettingsAxesChecker and CmdSettingsAxesChecker.
void addPointAxisWithGeneratedIdentifier(const QPointF &posScreen, const QPointF &posGraph, QString &identifier, double ordinal, bool isXOnly)
Add a single axis point with a generated point identifier.
Definition: Document.cpp:162
virtual void setModelGeneral(const DocumentModelGeneral &modelGeneral)
Set method for DocumentModelGeneral.
unsigned int coordSystemCount() const
Number of CoordSystem.
Definition: Document.cpp:304
virtual void addPointAxisWithSpecifiedIdentifier(const QPointF &posScreen, const QPointF &posGraph, const QString &identifier, double ordinal, bool isXOnly)
Add a single axis point with the specified point identifier.
virtual void editPointGraph(bool isX, bool isY, double x, double y, const QStringList &identifiers, const Transformation &transformation)
Edit the graph coordinates of one or more graph points.
void setDocumentAxesPointsRequired(DocumentAxesPointsRequired documentAxesPointsRequired)
Set the number of axes points required.
Definition: Document.cpp:933
virtual void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the axes curve.
void setCurveConnectAs(CurveConnectAs curveConnectAs)
Set connect as.
Definition: LineStyle.cpp:158
Model for DlgSettingsSegments and CmdSettingsSegments.
virtual DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
virtual QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
Definition: Document.cpp:466
void setCurvesGraphs(const CurvesGraphs &curvesGraphs)
Let CmdAbstract classes overwrite CurvesGraphs.
Definition: Document.cpp:926
virtual DocumentModelGridRemoval modelGridRemoval() const
Get method for DocumentModelGridRemoval.
virtual void iterateThroughCurveSegments(const QString &curveName, const Functor2wRet< const Point &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
See Curve::iterateThroughCurveSegments, for any axes or graph curve.
DocumentModelExportFormat modelExport() const
Get method for DocumentModelExportFormat.
Definition: Document.cpp:710
virtual void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
void saveXml(QXmlStreamWriter &writer) const
Save document to xml.
Definition: Document.cpp:878
QPixmap pixmap() const
Return the image that is being digitized.
Definition: Document.cpp:811
void addPointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Add all points identified in the specified CurvesGraphs. See also removePointsInCurvesGraphs.
Definition: Document.cpp:218
Document(const QImage &image)
Constructor for imported images and dragged images. Only one coordinate system is create - others are...
Definition: Document.cpp:51
void loadPreVersion6(QDataStream &str, double version, DocumentAxesPointsRequired &documentAxesPointsRequired)
Load from file in pre-version 6 format.
void loadVersion6(QXmlStreamReader &reader, DocumentAxesPointsRequired &documentAxesPointsRequired)
Load from file in version 6 format, into the single CoordSystem.
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:457
void setPaletteColor(ColorPalette paletteColor)
Set method for line color.
Definition: LineStyle.cpp:163
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
Definition: Document.cpp:816
void editPointGraph(bool isX, bool isY, double x, double y, const QStringList &identifiers, const Transformation &transformation)
Edit the graph coordinates of one or more graph points.
Definition: Document.cpp:374
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
Definition: Document.cpp:696
void initializeGridDisplay(const Transformation &transformation)
Initialize grid display. This is called immediately after the transformation has been defined for the...
Definition: Document.cpp:408
virtual void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
See Curve::movePoint.
void print() const
Debugging method for printing directly from symbolic debugger.
Definition: Document.cpp:826
void setWidth(int width)
Set width of line.
Definition: LineStyle.cpp:168
void setPointStyle(const PointStyle &pointStyle)
Set method for PointStyle.
Definition: CurveStyle.cpp:145
const CoordSystem & coordSystem() const
Current CoordSystem.
const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
Definition: Document.cpp:339
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
const Curve & curveAxes() const
Get method for axis curve.
Definition: Document.cpp:318
Callback for computing the bounding rectangles of the screen and graph coordinates of the points in t...
virtual DocumentModelExportFormat modelExport() const
Get method for DocumentModelExportFormat.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:689
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Definition: Document.cpp:346
virtual QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:1060
QString selectedCurveName() const
Currently selected curve name. This is used to set the selected curve combobox in MainWindow...
Definition: Document.cpp:907
bool isXOnly(const QString &pointIdentifier) const
See Curve::isXOnly.
Definition: Document.cpp:438
void setCoordSystemIndex(CoordSystemIndex coordSystemIndex)
Index of current CoordSystem.
void setSelectedCurveName(const QString &selectedCurveName)
Save curve name that is selected for the current coordinate system, for the next time the coordinate ...
Definition: Document.cpp:1050
DocumentModelAxesChecker modelAxesChecker() const
Get method for DocumentModelAxesChecker.
Definition: Document.cpp:675
virtual void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
virtual QString selectedCurveName() const
Currently selected curve name. This is used to set the selected curve combobox in MainWindow...
virtual QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.