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