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