Engauge Digitizer  2
Document.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "CallbackAddPointsInCurvesGraphs.h"
8 #include "CallbackBoundingRects.h"
9 #include "CallbackCheckAddPointAxis.h"
10 #include "CallbackCheckEditPointAxis.h"
11 #include "CallbackNextOrdinal.h"
12 #include "CallbackRemovePointsInCurvesGraphs.h"
13 #include "Curve.h"
14 #include "CurvesGraphs.h"
15 #include "CurveStyle.h"
16 #include "CurveStyles.h"
17 #include "Document.h"
18 #include "DocumentSerialize.h"
19 #include "EngaugeAssert.h"
20 #include "EnumsToQt.h"
21 #include "GridInitializer.h"
22 #include <iostream>
23 #include "Logger.h"
24 #include "OrdinalGenerator.h"
25 #include "Point.h"
26 #include "PointStyle.h"
27 #include <QByteArray>
28 #include <QDataStream>
29 #include <QDebug>
30 #include <QDomDocument>
31 #include <QFile>
32 #include <QImage>
33 #include <qmath.h>
34 #include <QObject>
35 #include <QtToString.h>
36 #include <QXmlStreamReader>
37 #include <QXmlStreamWriter>
38 #include "SettingsForGraph.h"
39 #include "Transformation.h"
40 #include "Version.h"
41 #include "Xml.h"
42 
43 const int FOUR_BYTES = 4;
44 const int NOMINAL_COORD_SYSTEM_COUNT = 1;
45 const int VERSION_6 = 6;
46 const int VERSION_7 = 7;
47 const int VERSION_8 = 8;
48 const int VERSION_9 = 9;
49 const int VERSION_10 = 10;
50 
51 Document::Document (const QImage &image) :
52  m_name ("untitled"),
53  m_documentAxesPointsRequired (DOCUMENT_AXES_POINTS_REQUIRED_3)
54 {
55  LOG4CPP_INFO_S ((*mainCat)) << "Document::Document"
56  << " image=" << image.width() << "x" << image.height();
57 
58  m_coordSystemContext.addCoordSystems(m_documentAxesPointsRequired,
59  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 *file = new QFile (fileName);
77  if (file->open(QIODevice::ReadOnly)) {
78 
79  QByteArray bytesStart = file->read (FOUR_BYTES);
80  file->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(m_documentAxesPointsRequired,
89  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  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 = 0;
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  file->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 
149 void Document::addCoordSystems(unsigned int numberCoordSystemToAdd)
150 {
151  LOG4CPP_INFO_S ((*mainCat)) << "Document::addCoordSystems"
152  << " toAdd=" << numberCoordSystemToAdd;
153 
154  m_coordSystemContext.addCoordSystems(m_documentAxesPointsRequired,
155  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 }
282 
283 void Document::checkEditPointAxis (const QString &pointIdentifier,
284  const QPointF &posScreen,
285  const QPointF &posGraph,
286  bool &isError,
287  QString &errorMessage)
288 {
289  LOG4CPP_INFO_S ((*mainCat)) << "Document::checkEditPointAxis";
290 
291  m_coordSystemContext.checkEditPointAxis(pointIdentifier,
292  posScreen,
293  posGraph,
294  isError,
295  errorMessage);
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 (transformation);
417 
418  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
420 
421  iterateThroughCurvePointsAxes (ftorWithCallback);
422 
423  // Initialize. Note that if there are no graph points then these next steps have no effect
424  bool isEmpty;
425  QRectF boundingRectGraph = ftor.boundingRectGraph(isEmpty);
426  if (!isEmpty) {
427 
428  GridInitializer gridInitializer;
429 
431  modelCoords(),
432  transformation,
433  m_pixmap.size ());
434 
435  m_coordSystemContext.setModelGridDisplay (modelGridDisplay);
436  }
437 }
438 
439 bool Document::isXOnly (const QString &pointIdentifier) const
440 {
441  return m_coordSystemContext.isXOnly (pointIdentifier);
442 }
443 
444 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
445 {
446  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvePointsAxes";
447 
448  m_coordSystemContext.iterateThroughCurvePointsAxes(ftorWithCallback);
449 }
450 
451 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
452 {
453  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvePointsAxes";
454 
455  m_coordSystemContext.iterateThroughCurvePointsAxes(ftorWithCallback);
456 }
457 
458 void Document::iterateThroughCurveSegments (const QString &curveName,
459  const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
460 {
461  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurveSegments";
462 
463  m_coordSystemContext.iterateThroughCurveSegments(curveName,
464  ftorWithCallback);
465 }
466 
467 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
468 {
469  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvesPointsGraphs";
470 
471  m_coordSystemContext.iterateThroughCurvesPointsGraphs(ftorWithCallback);
472 }
473 
474 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
475 {
476  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvesPointsGraphs";
477 
478  m_coordSystemContext.iterateThroughCurvesPointsGraphs(ftorWithCallback);
479 }
480 
481 void Document::loadImage(QXmlStreamReader &reader)
482 {
483  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadImage";
484 
485  loadNextFromReader(reader); // Read to CDATA
486  if (reader.isCDATA ()) {
487 
488  // Get base64 array
489  QByteArray array64 = reader.text().toString().toUtf8();
490 
491  // Decoded array
492  QByteArray array;
493  array = QByteArray::fromBase64(array64);
494 
495  // Read decoded array into image
496  QDataStream str (&array, QIODevice::ReadOnly);
497  QImage img = m_pixmap.toImage ();
498  str >> img;
499  m_pixmap = QPixmap::fromImage (img);
500 
501  // Read until end of this subtree
502  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
503  (reader.name() != DOCUMENT_SERIALIZE_IMAGE)){
504  loadNextFromReader(reader);
505  }
506 
507  } else {
508 
509  // This point can be reached if:
510  // 1) File is broken
511  // 2) Bad character is in text, and NetworkClient::cleanXml did not do its job
512  reader.raiseError (QObject::tr ("Cannot read image data"));
513  }
514 }
515 
516 void Document::loadPreVersion6 (QDataStream &str)
517 {
518  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadPreVersion6";
519 
520  qint32 int32;
521  double version;
522  QString st;
523 
524  str >> int32; // Magic number
525  str >> version;
526  str >> st; // Version string
527  str >> int32; // Background
528  str >> m_pixmap;
529  str >> m_name;
530 
531  m_coordSystemContext.loadPreVersion6 (str,
532  version);
533 
534  m_documentAxesPointsRequired = m_coordSystemContext.documentAxesPointsRequired ();
535 }
536 
537 void Document::loadVersion6 (QFile *file)
538 {
539  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadVersion6";
540 
541  QXmlStreamReader reader (file);
542 
543  m_documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
544 
545  // Create the single CoordSystem used in versions before version 7
546  m_coordSystemContext.addCoordSystems(m_documentAxesPointsRequired,
547  NOMINAL_COORD_SYSTEM_COUNT);
548 
549  // If this is purely a serialized Document then we process every node under the root. However, if this is an error report file
550  // then we need to skip the non-Document stuff. The common solution is to skip nodes outside the Document subtree using this flag
551  bool inDocumentSubtree = false;
552 
553  // Import from xml. Loop to end of data or error condition occurs, whichever is first
554  while (!reader.atEnd() &&
555  !reader.hasError()) {
556  QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
557 
558  // Special processing of DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT, for an error report file
559  if ((reader.name() == DOCUMENT_SERIALIZE_IMAGE) &&
560  (tokenType == QXmlStreamReader::StartElement)) {
561 
562  generateEmptyPixmap (reader.attributes());
563  }
564 
565  // Branching to skip non-Document nodes, with the exception of any DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT
566  if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
567  (tokenType == QXmlStreamReader::StartElement)) {
568 
569  inDocumentSubtree = true;
570 
571  } else if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
572  (tokenType == QXmlStreamReader::EndElement)) {
573 
574  // Exit out of loop immediately
575  break;
576  }
577 
578  if (inDocumentSubtree) {
579 
580  // Iterate to next StartElement
581  if (tokenType == QXmlStreamReader::StartElement) {
582 
583  // This is a StartElement, so process it
584  QString tag = reader.name().toString();
585  if (tag == DOCUMENT_SERIALIZE_IMAGE) {
586  // A standard Document file has DOCUMENT_SERIALIZE_IMAGE inside DOCUMENT_SERIALIZE_DOCUMENT, versus an error report file
587  loadImage(reader);
588 
589  // Now that we have the image at the DOCUMENT_SERIALIZE_DOCUMENT level, we read the rest at this level into CoordSystem
590  m_coordSystemContext.loadVersion6 (reader);
591 
592  // Reading of DOCUMENT_SERIALIZE_DOCUMENT has just finished, so the reading has finished
593  break;
594  }
595  }
596  }
597  }
598  if (reader.hasError ()) {
599 
600  m_successfulRead = false;
601  m_reasonForUnsuccessfulRead = reader.errorString();
602  }
603 
604  // There are already one axes curve and at least one graph curve so we do not need to add any more graph curves
605 }
606 
607 void Document::loadVersions7AndUp (QFile *file)
608 {
609  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadVersions7AndUp";
610 
611  const int ONE_COORDINATE_SYSTEM = 1;
612 
613  QXmlStreamReader reader (file);
614 
615  // If this is purely a serialized Document then we process every node under the root. However, if this is an error report file
616  // then we need to skip the non-Document stuff. The common solution is to skip nodes outside the Document subtree using this flag
617  bool inDocumentSubtree = false;
618 
619  // Import from xml. Loop to end of data or error condition occurs, whichever is first
620  while (!reader.atEnd() &&
621  !reader.hasError()) {
622  QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
623 
624  // Special processing of DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT, for an error report file
625  if ((reader.name() == DOCUMENT_SERIALIZE_IMAGE) &&
626  (tokenType == QXmlStreamReader::StartElement)) {
627 
628  generateEmptyPixmap (reader.attributes());
629  }
630 
631  // Branching to skip non-Document nodes, with the exception of any DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT
632  if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
633  (tokenType == QXmlStreamReader::StartElement)) {
634 
635  inDocumentSubtree = true;
636 
637  QXmlStreamAttributes attributes = reader.attributes();
638  if (attributes.hasAttribute (DOCUMENT_SERIALIZE_AXES_POINTS_REQUIRED)) {
639  m_documentAxesPointsRequired = (DocumentAxesPointsRequired) attributes.value (DOCUMENT_SERIALIZE_AXES_POINTS_REQUIRED).toInt();
640  } else {
641  m_documentAxesPointsRequired = DOCUMENT_AXES_POINTS_REQUIRED_3;
642  }
643 
644  } else if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
645  (tokenType == QXmlStreamReader::EndElement)) {
646 
647  // Exit out of loop immediately
648  break;
649  }
650 
651  if (inDocumentSubtree) {
652 
653  // Iterate to next StartElement
654  if (tokenType == QXmlStreamReader::StartElement) {
655 
656  // This is a StartElement, so process it
657  QString tag = reader.name().toString();
658  if (tag == DOCUMENT_SERIALIZE_COORD_SYSTEM) {
659  m_coordSystemContext.addCoordSystems (m_documentAxesPointsRequired,
660  ONE_COORDINATE_SYSTEM);
661  m_coordSystemContext.loadVersions7AndUp (reader,
662  m_documentAxesPointsRequired);
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 
917 {
918  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCoordSystemIndex";
919 
920  m_coordSystemContext.setCoordSystemIndex (coordSystemIndex);
921 }
922 
924 {
925  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCurveAxes";
926 
927  m_coordSystemContext.setCurveAxes (curveAxes);
928 }
929 
931 {
932  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCurvesGraphs";
933 
934  m_coordSystemContext.setCurvesGraphs(curvesGraphs);
935 }
936 
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 
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 
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 = (int) 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:149
virtual QString selectedCurveName() const
Currently selected curve name. This is used to set the selected curve combobox in MainWindow...
void addCoordSystems(DocumentAxesPointsRequired documentAxesPointsRequired, unsigned int numberCoordSystemToAdd)
Add specified number of coordinate systems to the original one created by the constructor.
void addGraphCurveAtEnd(const QString &curveName)
Add new graph curve to the list of existing graph curves.
Definition: Document.cpp:158
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.
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:439
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:195
DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
Definition: Document.cpp:742
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 checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling editPointAxis.
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:208
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:444
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 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
virtual 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...
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:228
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:268
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:283
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.
void loadVersions7AndUp(QXmlStreamReader &reader, DocumentAxesPointsRequired documentAxesPointsRequired)
Load one CoordSystem from file in version 7 format or newer, into the most recent CoordSystem which w...
void loadVersion6(QXmlStreamReader &reader)
Load from file in version 6 format, into the single CoordSystem.
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:287
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.
void loadPreVersion6(QDataStream &str, double version)
Load from file in pre-version 6 format.
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 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: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: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:277
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
DocumentModelGridDisplay initializeWithWidePolarCoverage(const QRectF &boundingRectGraph, const DocumentModelCoords &modelCoords, const Transformation &transformation, const QSize &imageSize) const
Initialize given the boundaries of the graph coordinates, and then extra processing for polar coordin...
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
virtual DocumentAxesPointsRequired documentAxesPointsRequired() const
Number of axes points for map or graph. This value is returned after opening a file.
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:165
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:458
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:467
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:221
Document(const QImage &image)
Constructor for imported images and dragged images. Only one coordinate system is create - others are...
Definition: Document.cpp:51
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.