Engauge Digitizer  2
Document.cpp
1 /******************************************************************************************************
2  * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3  * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4  * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5  ******************************************************************************************************/
6 
7 #include "CallbackAddPointsInCurvesGraphs.h"
8 #include "CallbackBoundingRects.h"
9 #include "CallbackCheckAddPointAxis.h"
10 #include "CallbackCheckEditPointAxis.h"
11 #include "CallbackNextOrdinal.h"
12 #include "CallbackRemovePointsInCurvesGraphs.h"
13 #include "Curve.h"
14 #include "CurvesGraphs.h"
15 #include "CurveStyle.h"
16 #include "CurveStyles.h"
17 #include "Document.h"
18 #include "DocumentSerialize.h"
19 #include "EngaugeAssert.h"
20 #include "EnumsToQt.h"
21 #include "GridInitializer.h"
22 #include <iostream>
23 #include "Logger.h"
24 #include "OrdinalGenerator.h"
25 #include "Point.h"
26 #include "PointStyle.h"
27 #include <QByteArray>
28 #include <QDataStream>
29 #include <QDebug>
30 #include <QDomDocument>
31 #include <QFile>
32 #include <QImage>
33 #include <qmath.h>
34 #include <QObject>
35 #include <QtToString.h>
36 #include <QXmlStreamReader>
37 #include <QXmlStreamWriter>
38 #include "SettingsForGraph.h"
39 #include "Transformation.h"
40 #include "Version.h"
41 #include "Xml.h"
42 
43 const int FOUR_BYTES = 4;
44 const int NOMINAL_COORD_SYSTEM_COUNT = 1;
45 const int VERSION_6 = 6;
46 const int VERSION_7 = 7;
47 const int VERSION_8 = 8;
48 const int VERSION_9 = 9;
49 const int VERSION_10 = 10;
50 
51 Document::Document (const QImage &image) :
52  m_name ("untitled"),
53  m_documentAxesPointsRequired (DOCUMENT_AXES_POINTS_REQUIRED_3)
54 {
55  LOG4CPP_INFO_S ((*mainCat)) << "Document::Document"
56  << " image=" << image.width() << "x" << image.height();
57 
58  m_coordSystemContext.addCoordSystems(NOMINAL_COORD_SYSTEM_COUNT);
59 
60  m_successfulRead = true; // Reading from QImage always succeeds, resulting in empty Document
61 
62  m_pixmap.convertFromImage (image);
63 }
64 
65 Document::Document (const QString &fileName) :
66  m_name (fileName),
67  m_documentAxesPointsRequired (DOCUMENT_AXES_POINTS_REQUIRED_3)
68 {
69  LOG4CPP_INFO_S ((*mainCat)) << "Document::Document"
70  << " fileName=" << fileName.toLatin1().data();
71 
72  m_successfulRead = true;
73 
74  // Grab first few bytes to determine the version number
75  QFile *file = new QFile (fileName);
76  if (file->open(QIODevice::ReadOnly)) {
77 
78  QByteArray bytesStart = file->read (FOUR_BYTES);
79  file->close ();
80 
81  if (bytesIndicatePreVersion6 (bytesStart)) {
82 
83  QFile *file = new QFile (fileName);
84  if (file->open (QIODevice::ReadOnly)) {
85  QDataStream str (file);
86 
87  m_coordSystemContext.addCoordSystems(NOMINAL_COORD_SYSTEM_COUNT);
88  loadPreVersion6 (str);
89 
90  } else {
91 
92  m_successfulRead = false;
93  m_reasonForUnsuccessfulRead = QObject::tr ("Operating system says file is not readable");
94 
95  }
96  } else {
97 
98  QFile *file = new QFile (fileName);
99  if (file->open (QIODevice::ReadOnly | QIODevice::Text)) {
100 
101  int version = versionFromFile (file);
102  switch (version)
103  {
104  case VERSION_6:
105  loadVersion6 (file);
106  break;
107 
108  case VERSION_7:
109  case VERSION_8:
110  case VERSION_9:
111  case VERSION_10:
112  loadVersions7AndUp (file);
113  break;
114 
115  default:
116  m_successfulRead = false;
117  m_reasonForUnsuccessfulRead = QString ("Engauge %1 %2 %3 %4 Engauge")
118  .arg (VERSION_NUMBER)
119  .arg (QObject::tr ("cannot read newer files from version"))
120  .arg (version)
121  .arg (QObject::tr ("of"));
122  break;
123  }
124 
125  // Close and deactivate
126  file->close ();
127  delete file;
128  file = 0;
129 
130  } else {
131 
132  m_successfulRead = false;
133  m_reasonForUnsuccessfulRead = QObject::tr ("Operating system says file is not readable");
134  }
135  }
136  } else {
137  file->close ();
138  m_successfulRead = false;
139  m_reasonForUnsuccessfulRead = QString ("%1 '%2' %3")
140  .arg (QObject::tr ("File"))
141  .arg (fileName)
142  .arg (QObject::tr ("was not found"));
143  }
144 }
145 
146 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 (m_documentAxesPointsRequired,
415  transformation);
416 
417  Functor2wRet<const QString &, const Point &, CallbackSearchReturn> ftorWithCallback = functor_ret (ftor,
419 
420  iterateThroughCurvePointsAxes (ftorWithCallback);
421 
422  // Initialize. Note that if there are no graph points then these next steps have no effect
423  bool isEmpty;
424  QPointF boundingRectGraphMin = ftor.boundingRectGraphMin (isEmpty);
425  QPointF boundingRectGraphMax = ftor.boundingRectGraphMax (isEmpty);
426  if (!isEmpty) {
427 
428  GridInitializer gridInitializer;
429 
430  DocumentModelGridDisplay modelGridDisplay = gridInitializer.initializeWithWidePolarCoverage (boundingRectGraphMin,
431  boundingRectGraphMax,
432  modelCoords(),
433  transformation,
434  m_pixmap.size ());
435 
436  m_coordSystemContext.setModelGridDisplay (modelGridDisplay);
437  }
438 }
439 
440 bool Document::isXOnly (const QString &pointIdentifier) const
441 {
442  return m_coordSystemContext.isXOnly (pointIdentifier);
443 }
444 
445 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
446 {
447  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvePointsAxes";
448 
449  m_coordSystemContext.iterateThroughCurvePointsAxes(ftorWithCallback);
450 }
451 
452 void Document::iterateThroughCurvePointsAxes (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
453 {
454  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvePointsAxes";
455 
456  m_coordSystemContext.iterateThroughCurvePointsAxes(ftorWithCallback);
457 }
458 
459 void Document::iterateThroughCurveSegments (const QString &curveName,
460  const Functor2wRet<const Point &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
461 {
462  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurveSegments";
463 
464  m_coordSystemContext.iterateThroughCurveSegments(curveName,
465  ftorWithCallback);
466 }
467 
468 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback)
469 {
470  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvesPointsGraphs";
471 
472  m_coordSystemContext.iterateThroughCurvesPointsGraphs(ftorWithCallback);
473 }
474 
475 void Document::iterateThroughCurvesPointsGraphs (const Functor2wRet<const QString &, const Point &, CallbackSearchReturn> &ftorWithCallback) const
476 {
477  LOG4CPP_INFO_S ((*mainCat)) << "Document::iterateThroughCurvesPointsGraphs";
478 
479  m_coordSystemContext.iterateThroughCurvesPointsGraphs(ftorWithCallback);
480 }
481 
482 void Document::loadImage(QXmlStreamReader &reader)
483 {
484  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadImage";
485 
486  loadNextFromReader(reader); // Read to CDATA
487  if (reader.isCDATA ()) {
488 
489  // Get base64 array
490  QByteArray array64 = reader.text().toString().toUtf8();
491 
492  // Decoded array
493  QByteArray array;
494  array = QByteArray::fromBase64(array64);
495 
496  // Read decoded array into image
497  QDataStream str (&array, QIODevice::ReadOnly);
498  QImage img = m_pixmap.toImage ();
499  str >> img;
500  m_pixmap = QPixmap::fromImage (img);
501 
502  // Read until end of this subtree
503  while ((reader.tokenType() != QXmlStreamReader::EndElement) ||
504  (reader.name() != DOCUMENT_SERIALIZE_IMAGE)){
505  loadNextFromReader(reader);
506  }
507 
508  } else {
509 
510  // This point can be reached if:
511  // 1) File is broken
512  // 2) Bad character is in text, and NetworkClient::cleanXml did not do its job
513  reader.raiseError (QObject::tr ("Cannot read image data"));
514  }
515 }
516 
517 void Document::loadPreVersion6 (QDataStream &str)
518 {
519  LOG4CPP_INFO_S ((*mainCat)) << "Document::loadPreVersion6";
520 
521  qint32 int32;
522  double version;
523  QString st;
524 
525  str >> int32; // Magic number
526  str >> version;
527  str >> st; // Version string
528  str >> int32; // Background
529  str >> m_pixmap;
530  str >> m_name;
531 
532  m_coordSystemContext.loadPreVersion6 (str,
533  version,
534  m_documentAxesPointsRequired); // Returns axes points required
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(NOMINAL_COORD_SYSTEM_COUNT);
547 
548  // If this is purely a serialized Document then we process every node under the root. However, if this is an error report file
549  // then we need to skip the non-Document stuff. The common solution is to skip nodes outside the Document subtree using this flag
550  bool inDocumentSubtree = false;
551 
552  // Import from xml. Loop to end of data or error condition occurs, whichever is first
553  while (!reader.atEnd() &&
554  !reader.hasError()) {
555  QXmlStreamReader::TokenType tokenType = loadNextFromReader(reader);
556 
557  // Special processing of DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT, for an error report file
558  if ((reader.name() == DOCUMENT_SERIALIZE_IMAGE) &&
559  (tokenType == QXmlStreamReader::StartElement)) {
560 
561  generateEmptyPixmap (reader.attributes());
562  }
563 
564  // Branching to skip non-Document nodes, with the exception of any DOCUMENT_SERIALIZE_IMAGE outside DOCUMENT_SERIALIZE_DOCUMENT
565  if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
566  (tokenType == QXmlStreamReader::StartElement)) {
567 
568  inDocumentSubtree = true;
569 
570  } else if ((reader.name() == DOCUMENT_SERIALIZE_DOCUMENT) &&
571  (tokenType == QXmlStreamReader::EndElement)) {
572 
573  // Exit out of loop immediately
574  break;
575  }
576 
577  if (inDocumentSubtree) {
578 
579  // Iterate to next StartElement
580  if (tokenType == QXmlStreamReader::StartElement) {
581 
582  // This is a StartElement, so process it
583  QString tag = reader.name().toString();
584  if (tag == DOCUMENT_SERIALIZE_IMAGE) {
585  // A standard Document file has DOCUMENT_SERIALIZE_IMAGE inside DOCUMENT_SERIALIZE_DOCUMENT, versus an error report file
586  loadImage(reader);
587 
588  // Now that we have the image at the DOCUMENT_SERIALIZE_DOCUMENT level, we read the rest at this level into CoordSystem
589  m_coordSystemContext.loadVersion6 (reader,
590  m_documentAxesPointsRequired); // Returns axes points required
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 (ONE_COORDINATE_SYSTEM);
660  m_coordSystemContext.loadVersions7AndUp (reader);
661  } else if (tag == DOCUMENT_SERIALIZE_IMAGE) {
662  // A standard Document file has DOCUMENT_SERIALIZE_IMAGE inside DOCUMENT_SERIALIZE_DOCUMENT, versus an error report file
663  loadImage(reader);
664  }
665  }
666  }
667  }
668  if (reader.hasError ()) {
669 
670  m_successfulRead = false;
671  m_reasonForUnsuccessfulRead = reader.errorString();
672  }
673 
674  // There are already one axes curve and at least one graph curve so we do not need to add any more graph curves
675 }
676 
678 {
679  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelAxesChecker";
680 
681  return m_coordSystemContext.modelAxesChecker();
682 }
683 
685 {
686  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelColorFilter";
687 
688  return m_coordSystemContext.modelColorFilter();
689 }
690 
692 {
693  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelCoords";
694 
695  return m_coordSystemContext.modelCoords();
696 }
697 
699 {
700  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelCurveStyles";
701 
702  return m_coordSystemContext.modelCurveStyles();
703 }
704 
706 {
707  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelDigitizeCurve";
708 
709  return m_coordSystemContext.modelDigitizeCurve();
710 }
711 
713 {
714  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelExport";
715 
716  return m_coordSystemContext.modelExport();
717 }
718 
720 {
721  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelGeneral";
722 
723  return m_coordSystemContext.modelGeneral();
724 }
725 
727 {
728  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelGridDisplay";
729 
730  return m_coordSystemContext.modelGridDisplay();
731 }
732 
734 {
735  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelGridRemoval";
736 
737  return m_coordSystemContext.modelGridRemoval();
738 }
739 
741 {
742  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelPointMatch";
743 
744  return m_coordSystemContext.modelPointMatch();
745 }
746 
748 {
749  LOG4CPP_DEBUG_S ((*mainCat)) << "Document::modelSegments";
750 
751  return m_coordSystemContext.modelSegments();
752 }
753 
754 void Document::movePoint (const QString &pointIdentifier,
755  const QPointF &deltaScreen)
756 {
757  m_coordSystemContext.movePoint (pointIdentifier,
758  deltaScreen);
759 }
760 
761 int Document::nextOrdinalForCurve (const QString &curveName) const
762 {
763  LOG4CPP_INFO_S ((*mainCat)) << "Document::nextOrdinalForCurve";
764 
765  return m_coordSystemContext.nextOrdinalForCurve(curveName);
766 }
767 
768 void Document::overrideGraphDefaultsWithMapDefaults ()
769 {
770  const int DEFAULT_WIDTH = 1;
771 
772  // Axis style for scale bar is better with transparent-filled circles so user can more accurately place them,
773  // and a visible line between the points also helps to make the points more visible
774  CurveStyles curveStyles = modelCurveStyles ();
775 
776  CurveStyle curveStyle = curveStyles.curveStyle (AXIS_CURVE_NAME);
777 
778  PointStyle pointStyle = curveStyle.pointStyle ();
779  pointStyle.setShape (POINT_SHAPE_CIRCLE);
780  pointStyle.setPaletteColor (COLOR_PALETTE_RED);
781 
782  LineStyle lineStyle = curveStyle.lineStyle ();
783  lineStyle.setCurveConnectAs (CONNECT_AS_RELATION_STRAIGHT);
784  lineStyle.setWidth (DEFAULT_WIDTH);
785  lineStyle.setPaletteColor (COLOR_PALETTE_RED);
786 
787  curveStyle.setPointStyle (pointStyle);
788  curveStyle.setLineStyle (lineStyle);
789 
790  curveStyles.setCurveStyle (AXIS_CURVE_NAME,
791  curveStyle);
792 
793  // Change all graph curves from functions to relations
794  QStringList curveNames = curvesGraphsNames ();
795  QStringList::const_iterator itr;
796  for (itr = curveNames.begin(); itr != curveNames.end(); itr++) {
797  QString curveName = *itr;
798  CurveStyle curveStyle = curveStyles.curveStyle (curveName);
799 
800  LineStyle lineStyle = curveStyle.lineStyle ();
801  lineStyle.setCurveConnectAs (CONNECT_AS_RELATION_STRAIGHT);
802 
803  curveStyle.setLineStyle (lineStyle);
804 
805  curveStyles.setCurveStyle (curveName,
806  curveStyle);
807  }
808 
809  // Save modified curve styles into Document
810  setModelCurveStyles (curveStyles);
811 }
812 
813 QPixmap Document::pixmap () const
814 {
815  return m_pixmap;
816 }
817 
818 QPointF Document::positionGraph (const QString &pointIdentifier) const
819 {
820  return m_coordSystemContext.positionGraph(pointIdentifier);
821 }
822 
823 QPointF Document::positionScreen (const QString &pointIdentifier) const
824 {
825  return m_coordSystemContext.positionScreen(pointIdentifier);
826 }
827 
828 void Document::print () const
829 {
830  QString text;
831  QTextStream str (&text);
832 
833  printStream ("",
834  str);
835  std::cerr << text.toLatin1().data();
836 }
837 
838 void Document::printStream (QString indentation,
839  QTextStream &str) const
840 {
841  str << indentation << "Document\n";
842 
843  indentation += INDENTATION_DELTA;
844 
845  str << indentation << "name=" << m_name << "\n";
846  str << indentation << "pixmap=" << m_pixmap.width() << "x" << m_pixmap.height() << "\n";
847 
848  m_coordSystemContext.printStream(indentation,
849  str);
850 }
851 
853 {
854  ENGAUGE_ASSERT (!m_successfulRead);
855 
856  return m_reasonForUnsuccessfulRead;
857 }
858 
859 void Document::removePointAxis (const QString &identifier)
860 {
861  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointAxis";
862 
863  m_coordSystemContext.removePointAxis(identifier);
864 }
865 
866 void Document::removePointGraph (const QString &identifier)
867 {
868  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointGraph";
869 
870  m_coordSystemContext.removePointGraph(identifier);
871 }
872 
874 {
875  LOG4CPP_INFO_S ((*mainCat)) << "Document::removePointsInCurvesGraphs";
876 
877  m_coordSystemContext.removePointsInCurvesGraphs(curvesGraphs);
878 }
879 
880 void Document::saveXml (QXmlStreamWriter &writer) const
881 {
882  writer.writeStartElement(DOCUMENT_SERIALIZE_DOCUMENT);
883 
884  // Version number is tacked onto DOCUMENT_SERIALIZE_DOCUMENT since the alternative (creating a new start element)
885  // causes the code to complain during loading
886  writer.writeAttribute(DOCUMENT_SERIALIZE_APPLICATION_VERSION_NUMBER, VERSION_NUMBER);
887 
888  // Number of axes points required
889  writer.writeAttribute(DOCUMENT_SERIALIZE_AXES_POINTS_REQUIRED, QString::number (m_documentAxesPointsRequired));
890 
891  // Serialize the Document image. That binary data is encoded as base64
892  QByteArray array;
893  QDataStream str (&array, QIODevice::WriteOnly);
894  QImage img = m_pixmap.toImage ();
895  str << img;
896  writer.writeStartElement(DOCUMENT_SERIALIZE_IMAGE);
897 
898  // Image width and height are explicitly inserted for error reports, since the CDATA is removed
899  // but we still want the image size for reconstructing the error(s)
900  writer.writeAttribute(DOCUMENT_SERIALIZE_IMAGE_WIDTH, QString::number (img.width()));
901  writer.writeAttribute(DOCUMENT_SERIALIZE_IMAGE_HEIGHT, QString::number (img.height()));
902 
903  writer.writeCDATA (array.toBase64 ());
904  writer.writeEndElement();
905 
906  m_coordSystemContext.saveXml (writer);
907 }
908 
910 {
911  return m_coordSystemContext.selectedCurveName();
912 }
913 
914 void Document::setCoordSystemIndex(CoordSystemIndex coordSystemIndex)
915 {
916  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCoordSystemIndex";
917 
918  m_coordSystemContext.setCoordSystemIndex (coordSystemIndex);
919 }
920 
921 void Document::setCurveAxes (const Curve &curveAxes)
922 {
923  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCurveAxes";
924 
925  m_coordSystemContext.setCurveAxes (curveAxes);
926 }
927 
928 void Document::setCurvesGraphs (const CurvesGraphs &curvesGraphs)
929 {
930  LOG4CPP_INFO_S ((*mainCat)) << "Document::setCurvesGraphs";
931 
932  m_coordSystemContext.setCurvesGraphs(curvesGraphs);
933 }
934 
935 void Document::setDocumentAxesPointsRequired(DocumentAxesPointsRequired documentAxesPointsRequired)
936 {
937  LOG4CPP_INFO_S ((*mainCat)) << "Document::setDocumentAxesPointsRequired";
938 
939  m_documentAxesPointsRequired = documentAxesPointsRequired;
940 
941  if (documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_2) {
942 
943  overrideGraphDefaultsWithMapDefaults ();
944  }
945 }
946 
948 {
949  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelAxesChecker";
950 
951  m_coordSystemContext.setModelAxesChecker(modelAxesChecker);
952 }
953 
955 {
956  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelColorFilter";
957 
958  // Save the CurveFilter for each Curve
959  ColorFilterSettingsList::const_iterator itr;
960  for (itr = modelColorFilter.colorFilterSettingsList().constBegin ();
961  itr != modelColorFilter.colorFilterSettingsList().constEnd();
962  itr++) {
963 
964  QString curveName = itr.key();
965  const ColorFilterSettings &colorFilterSettings = itr.value();
966 
967  Curve *curve = curveForCurveName (curveName);
968  curve->setColorFilterSettings (colorFilterSettings);
969  }
970 }
971 
973 {
974  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelCoords";
975 
976  m_coordSystemContext.setModelCoords(modelCoords);
977 }
978 
979 void Document::setModelCurveStyles(const CurveStyles &modelCurveStyles)
980 {
981  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelCurveStyles";
982 
983  // Save the LineStyle and PointStyle for each Curve
984  QStringList curveNames = modelCurveStyles.curveNames();
985  QStringList::iterator itr;
986  for (itr = curveNames.begin(); itr != curveNames.end(); itr++) {
987 
988  QString curveName = *itr;
989  const CurveStyle &curveStyle = modelCurveStyles.curveStyle (curveName);
990 
991  Curve *curve = curveForCurveName (curveName);
992  curve->setCurveStyle (curveStyle);
993  }
994 }
995 
997 {
998  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelDigitizeCurve";
999 
1000  m_coordSystemContext.setModelDigitizeCurve(modelDigitizeCurve);
1001 }
1002 
1004 {
1005  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelExport";
1006 
1007  m_coordSystemContext.setModelExport (modelExport);
1008 }
1009 
1011 {
1012  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelGeneral";
1013 
1014  m_coordSystemContext.setModelGeneral(modelGeneral);
1015 }
1016 
1018 {
1019  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelGridDisplay";
1020 
1021  m_coordSystemContext.setModelGridDisplay(modelGridDisplay);
1022 }
1023 
1025 {
1026  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelGridRemoval";
1027 
1028  m_coordSystemContext.setModelGridRemoval(modelGridRemoval);
1029 }
1030 
1032 {
1033  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelPointMatch";
1034 
1035  m_coordSystemContext.setModelPointMatch(modelPointMatch);
1036 }
1037 
1039 {
1040  LOG4CPP_INFO_S ((*mainCat)) << "Document::setModelSegments";
1041 
1042  m_coordSystemContext.setModelSegments (modelSegments);
1043 }
1044 
1045 void Document::setPixmap(const QImage &image)
1046 {
1047  LOG4CPP_INFO_S ((*mainCat)) << "Document::setPixmap";
1048 
1049  m_pixmap = QPixmap::fromImage (image);
1050 }
1051 
1052 void Document::setSelectedCurveName(const QString &selectedCurveName)
1053 {
1054  m_coordSystemContext.setSelectedCurveName (selectedCurveName);
1055 }
1056 
1058 {
1059  return m_successfulRead;
1060 }
1061 
1062 void Document::updatePointOrdinals (const Transformation &transformation)
1063 {
1064  LOG4CPP_INFO_S ((*mainCat)) << "Document::updatePointOrdinals";
1065 
1066  m_coordSystemContext.updatePointOrdinals(transformation);
1067 }
1068 
1069 int Document::versionFromFile (QFile *file) const
1070 {
1071  LOG4CPP_INFO_S ((*mainCat)) << "Document::versionFromFile";
1072 
1073  int version = VERSION_6; // Use default if tag is missing
1074 
1075  QDomDocument doc;
1076  if (doc.setContent (file)) {
1077 
1078  QDomNodeList nodes = doc.elementsByTagName (DOCUMENT_SERIALIZE_DOCUMENT);
1079  if (nodes.count() > 0) {
1080  QDomNode node = nodes.at (0);
1081 
1082  QDomNamedNodeMap attributes = node.attributes();
1083 
1084  if (attributes.contains (DOCUMENT_SERIALIZE_APPLICATION_VERSION_NUMBER)) {
1085 
1086  QDomElement elem = node.toElement();
1087  version = (int) elem.attribute (DOCUMENT_SERIALIZE_APPLICATION_VERSION_NUMBER).toDouble();
1088  }
1089  }
1090  }
1091 
1092  file->seek (0); // Go back to beginning
1093 
1094  return version;
1095 }
void addCoordSystems(unsigned int numberCoordSystemToAdd)
Add some number (0 or more) of additional coordinate systems.
Definition: Document.cpp:146
void addGraphCurveAtEnd(const QString &curveName)
Add new graph curve to the list of existing graph curves.
Definition: Document.cpp:154
const ColorFilterSettingsList & colorFilterSettingsList() const
Get method for copying all color filters in one step.
Model for DlgSettingsGeneral and CmdSettingsGeneral.
CurveStyle curveStyle(const QString &curveName) const
CurveStyle in specified curve.
Definition: CurveStyles.cpp:79
void addCoordSystems(unsigned int numberCoordSystemToAdd)
Add specified number of coordinate systems to the original one created by the constructor.
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
int curvesGraphsNumPoints(const QString &curveName) const
See CurvesGraphs::curvesGraphsNumPoints.
Definition: Document.cpp:352
void movePoint(const QString &pointIdentifier, const QPointF &deltaScreen)
See Curve::movePoint.
Definition: Document.cpp:754
const CoordSystem & coordSystem() const
Currently active CoordSystem.
Definition: Document.cpp:296
virtual int curvesGraphsNumPoints(const QString &curveName) const
See CurvesGraphs::curvesGraphsNumPoints.
Model for DlgSettingsPointMatch and CmdSettingsPointMatch.
Color filter parameters for one curve. For a class, this is handled the same as LineStyle and PointSt...
Model for DlgSettingsGridDisplay and CmdSettingsGridDisplay.
void setModelAxesChecker(const DocumentModelAxesChecker &modelAxesChecker)
Set method for DocumentModelAxesChecker.
Definition: Document.cpp:947
void setModelGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
Set method for DocumentModelGridRemoval.
Definition: Document.cpp:1024
virtual void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
virtual DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
void addPointGraphWithGeneratedIdentifier(const QString &curveName, const QPointF &posScreen, QString &generatedIentifier, double ordinal)
Add a single graph point with a generated point identifier.
Definition: Document.cpp:191
virtual DocumentModelGridDisplay modelGridDisplay() const
Get method for DocumentModelGridDisplay.
void setCurveStyle(const CurveStyle &curveStyle)
Set curve style.
Definition: Curve.cpp:563
void setModelPointMatch(const DocumentModelPointMatch &modelPointMatch)
Set method for DocumentModelPointMatch.
Definition: Document.cpp:1031
Model for DlgSettingsExportFormat and CmdSettingsExportFormat.
void removePointAxis(const QString &identifier)
Perform the opposite of addPointAxis.
Definition: Document.cpp:859
void setModelGeneral(const DocumentModelGeneral &modelGeneral)
Set method for DocumentModelGeneral.
Definition: Document.cpp:1010
QStringList curveNames() const
List of all curve names.
Definition: CurveStyles.cpp:67
Model for DlgSettingsCurveProperties and CmdSettingsCurveProperties.
Definition: CurveStyles.h:22
DocumentModelGridRemoval modelGridRemoval() const
Get method for DocumentModelGridRemoval.
Definition: Document.cpp:733
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:1038
virtual void saveXml(QXmlStreamWriter &writer) const
Save graph to xml.
virtual DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
Definition: Document.cpp:761
void setColorFilterSettings(const ColorFilterSettings &colorFilterSettings)
Set color filter.
Definition: Curve.cpp:546
bool successfulRead() const
Return true if startup loading succeeded. If the loading failed then reasonForUnsuccessfulRed will ex...
Definition: Document.cpp:1057
virtual void addPointGraphWithSpecifiedIdentifier(const QString &curveName, const QPointF &posScreen, const QString &identifier, double ordinal)
Add a single graph point with the specified point identifer. Note that PointStyle is not applied to t...
virtual DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
Storage of data belonging to one coordinate system.
Definition: CoordSystem.h:42
PointStyle pointStyle() const
Get method for PointStyle.
Definition: CurveStyle.cpp:75
virtual DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
void setModelGridDisplay(const DocumentModelGridDisplay &modelGridDisplay)
Set method for DocumentModelGridDisplay.
Definition: Document.cpp:1017
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
void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the axes curve.
Definition: Document.cpp:445
const Curve * curveForCurveName(const QString &curveName) const
See CurvesGraphs::curveForCurveNames, although this also works for AXIS_CURVE_NAME.
Definition: Document.cpp:331
DocumentModelGeneral modelGeneral() const
Get method for DocumentModelGeneral.
Definition: Document.cpp:719
virtual void checkAddPointAxis(const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage, bool isXOnly, DocumentAxesPointsRequired documentAxesPointsRequired)
Check before calling addPointAxis. Also returns the next available ordinal number (to prevent clashes...
DocumentAxesPointsRequired documentAxesPointsRequired() const
Get method for DocumentAxesPointsRequired.
Definition: Document.cpp:359
virtual Curve * curveForCurveName(const QString &curveName)
See CurvesGraphs::curveForCurveName, although this also works for AXIS_CURVE_NAME.
DocumentModelColorFilter modelColorFilter() const
Get method for DocumentModelColorFilter.
Definition: Document.cpp:684
virtual DocumentModelAxesChecker modelAxesChecker() const
Get method for DocumentModelAxesChecker.
void setModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Set method for DocumentModelDigitizeCurve.
Definition: Document.cpp:996
unsigned int coordSystemCount() const
Number of CoordSystem.
virtual void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
void addScaleWithGeneratedIdentifier(const QPointF &posScreen0, const QPointF &posScreen1, double scaleLength, QString &identifier0, QString &identifier1, double ordinal0, double ordinal1)
Add scale with a generated point identifier.
Definition: Document.cpp: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:972
bool stable() const
Get method for stable flag.
DocumentModelPointMatch modelPointMatch() const
Get method for DocumentModelPointMatch.
Definition: Document.cpp:740
virtual void setModelCoords(const DocumentModelCoords &modelCoords)
Set method for DocumentModelCoords.
CoordSystemIndex coordSystemIndex() const
Index of current CoordSystem.
void checkAddPointAxis(const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage, bool isXOnly)
Check before calling addPointAxis. Also returns the next available ordinal number (to prevent clashes...
Definition: Document.cpp:264
void setPixmap(const QImage &image)
Set method for the background pixmap.
Definition: Document.cpp:1045
virtual CurveStyles modelCurveStyles() const
Get method for CurveStyles.
void checkEditPointAxis(const QString &pointIdentifier, const QPointF &posScreen, const QPointF &posGraph, bool &isError, QString &errorMessage)
Check before calling editPointAxis.
Definition: Document.cpp: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:914
void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
Definition: Document.cpp:866
virtual int nextOrdinalForCurve(const QString &curveName) const
Default next ordinal value for specified curve.
virtual void setCurvesGraphs(const CurvesGraphs &curvesGraphs)
Let CmdAbstract classes overwrite CurvesGraphs. Applies to current coordinate system.
virtual void setCurveAxes(const Curve &curveAxes)
Let CmdAbstract classes overwrite axes Curve. Applies to current coordinate system.
void setCurveStyle(const QString &curveName, const CurveStyle &curveStyle)
Set method for curve style.
virtual void setModelGridRemoval(const DocumentModelGridRemoval &modelGridRemoval)
Set method for DocumentModelGridRemoval.
void setModelExport(const DocumentModelExportFormat &modelExport)
Set method for DocumentModelExportFormat.
Definition: Document.cpp:1003
DocumentModelDigitizeCurve modelDigitizeCurve() const
Get method for DocumentModelDigitizeCurve.
Definition: Document.cpp:705
void setShape(PointShape shape)
Set method for point shape.
Definition: PointStyle.cpp:287
Model for DlgSettingsDigitizeCurve and CmdSettingsDigitizeCurve.
bool isXOnly(const QString &pointIdentifier) const
True/false if y/x value is empty.
void editPointAxis(const QPointF &posGraph, const QString &identifier)
Edit the graph coordinates of a single axis point. Call this after checkAddPointAxis to guarantee suc...
Definition: Document.cpp: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
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:979
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:921
CoordSystemIndex coordSystemIndex() const
Index of current active CoordSystem.
Definition: Document.cpp:310
void removePointsInCurvesGraphs(CurvesGraphs &curvesGraphs)
Remove all points identified in the specified CurvesGraphs. See also addPointsInCurvesGraphs.
Definition: Document.cpp:873
This class initializes the count, start, step and stop parameters for one coordinate (either x/theta ...
LineStyle lineStyle() const
Get method for LineStyle.
Definition: CurveStyle.cpp:26
virtual void setModelDigitizeCurve(const DocumentModelDigitizeCurve &modelDigitizeCurve)
Set method for DocumentModelDigitizeCurve.
DocumentModelSegments modelSegments() const
Get method for DocumentModelSegments.
Definition: Document.cpp:747
QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.
Definition: Document.cpp:823
virtual void removePointGraph(const QString &identifier)
Perform the opposite of addPointGraph.
DocumentModelGridDisplay modelGridDisplay() const
Get method for DocumentModelGridDisplay.
Definition: Document.cpp:726
virtual void setModelSegments(const DocumentModelSegments &modelSegments)
Set method for DocumentModelSegments.
void setModelColorFilter(const DocumentModelColorFilter &modelColorFilter)
Set method for DocumentModelColorFilter.
Definition: Document.cpp:954
virtual DocumentModelSegments modelSegments() const
Get method for DocumentModelSegments.
Model for DlgSettingsCoords and CmdSettingsCoords.
virtual void removePointAxis(const QString &identifier)
Perform the opposite of addPointAxis.
Container for LineStyle and PointStyle for one Curve.
Definition: CurveStyle.h:18
void setPaletteColor(ColorPalette paletteColor)
Set method for point color.
Definition: PointStyle.cpp:277
Container for one set of digitized Points.
Definition: Curve.h:33
Details for a specific Line.
Definition: LineStyle.h:19
void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
Definition: Document.cpp:838
virtual const Curve & curveAxes() const
Get method for axis curve.
virtual void printStream(QString indentation, QTextStream &str) const
Debugging method that supports print method of this class and printStream method of some other class(...
virtual const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
QString reasonForUnsuccessfulRead() const
Return an informative text message explaining why startup loading failed. Applies if successfulRead r...
Definition: Document.cpp:852
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.
unsigned int coordSystemCount() const
Number of CoordSystem.
Definition: Document.cpp:303
virtual void addPointAxisWithSpecifiedIdentifier(const QPointF &posScreen, const QPointF &posGraph, const QString &identifier, double ordinal, bool isXOnly)
Add a single axis point with the specified point identifier.
virtual void editPointGraph(bool isX, bool isY, double x, double y, const QStringList &identifiers, const Transformation &transformation)
Edit the graph coordinates of one or more graph points.
void setDocumentAxesPointsRequired(DocumentAxesPointsRequired documentAxesPointsRequired)
Set the number of axes points required.
Definition: Document.cpp:935
DocumentModelGridDisplay initializeWithWidePolarCoverage(const QPointF &boundingRectGraphMin, const QPointF &boundingRectGraphMax, const DocumentModelCoords &modelCoords, const Transformation &transformation, const QSize &imageSize) const
Initialize given the boundaries of the graph coordinates, and then extra processing for polar coordin...
virtual void iterateThroughCurvePointsAxes(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for the axes curve.
void setCurveConnectAs(CurveConnectAs curveConnectAs)
Set connect as.
Definition: LineStyle.cpp:158
Model for DlgSettingsSegments and CmdSettingsSegments.
virtual DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
virtual QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
Definition: Document.cpp:468
void setCurvesGraphs(const CurvesGraphs &curvesGraphs)
Let CmdAbstract classes overwrite CurvesGraphs.
Definition: Document.cpp:928
virtual DocumentModelGridRemoval modelGridRemoval() const
Get method for DocumentModelGridRemoval.
virtual void iterateThroughCurveSegments(const QString &curveName, const Functor2wRet< const Point &, const Point &, CallbackSearchReturn > &ftorWithCallback) const
See Curve::iterateThroughCurveSegments, for any axes or graph curve.
DocumentModelExportFormat modelExport() const
Get method for DocumentModelExportFormat.
Definition: Document.cpp:712
virtual void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
void saveXml(QXmlStreamWriter &writer) const
Save document to xml.
Definition: Document.cpp:880
QPixmap pixmap() const
Return the image that is being digitized.
Definition: Document.cpp:813
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.
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:459
void setPaletteColor(ColorPalette paletteColor)
Set method for line color.
Definition: LineStyle.cpp:163
QPointF positionGraph(const QString &pointIdentifier) const
See Curve::positionGraph.
Definition: Document.cpp:818
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
CurveStyles modelCurveStyles() const
Get method for CurveStyles.
Definition: Document.cpp:698
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.
void print() const
Debugging method for printing directly from symbolic debugger.
Definition: Document.cpp:828
void setWidth(int width)
Set width of line.
Definition: LineStyle.cpp:168
void setPointStyle(const PointStyle &pointStyle)
Set method for PointStyle.
Definition: CurveStyle.cpp:145
const CoordSystem & coordSystem() const
Current CoordSystem.
const CurvesGraphs & curvesGraphs() const
Make all Curves available, read only, for CmdAbstract classes only.
Definition: Document.cpp:338
Model for DlgSettingsGridRemoval and CmdSettingsGridRemoval. The settings are unstable until the user...
const Curve & curveAxes() const
Get method for axis curve.
Definition: Document.cpp:317
Callback for computing the bounding rectangles of the screen and graph coordinates of the points in t...
virtual DocumentModelExportFormat modelExport() const
Get method for DocumentModelExportFormat.
DocumentModelCoords modelCoords() const
Get method for DocumentModelCoords.
Definition: Document.cpp:691
QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
Definition: Document.cpp:345
virtual QStringList curvesGraphsNames() const
See CurvesGraphs::curvesGraphsNames.
void updatePointOrdinals(const Transformation &transformation)
Update point ordinals after point addition/removal or dragging.
Definition: Document.cpp:1062
QString selectedCurveName() const
Currently selected curve name. This is used to set the selected curve combobox in MainWindow...
Definition: Document.cpp:909
bool isXOnly(const QString &pointIdentifier) const
See Curve::isXOnly.
Definition: Document.cpp:440
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:1052
DocumentModelAxesChecker modelAxesChecker() const
Get method for DocumentModelAxesChecker.
Definition: Document.cpp:677
virtual void iterateThroughCurvesPointsGraphs(const Functor2wRet< const QString &, const Point &, CallbackSearchReturn > &ftorWithCallback)
See Curve::iterateThroughCurvePoints, for all the graphs curves.
virtual QString selectedCurveName() const
Currently selected curve name. This is used to set the selected curve combobox in MainWindow...
virtual QPointF positionScreen(const QString &pointIdentifier) const
See Curve::positionScreen.