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