Engauge Digitizer  2
CallbackDocumentHash.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 "CallbackDocumentHash.h"
8 #include "EngaugeAssert.h"
9 #include "Logger.h"
10 #include "Point.h"
11 #include <QCryptographicHash>
12 #include "QtToString.h"
13 #include "Transformation.h"
14 
15 CallbackDocumentHash::CallbackDocumentHash(DocumentAxesPointsRequired documentAxesPointsRequired) :
16  m_documentAxesPointsRequired (documentAxesPointsRequired),
17  m_documentHash (QCryptographicHash::Md5)
18 {
19 }
20 
22  const Point &point)
23 {
24  // LOG4CPP_DEBUG_S is below
25 
26  // Capture all important information about the point into the hash. A single string representing all of the point's details is
27  // created, which can be logged, and then that string is added to the hash
28 
29  QString details;
30 
31  details += curveName.toLatin1();
32  details += " " + point.identifier ();
33  details += " " + QPointFToString (point.posScreen());
34 
35  if (point.hasOrdinal ()) {
36  details += " " + QString::number (point.ordinal ());
37  }
38 
39  if (point.isAxisPoint()) {
40 
41  if (m_documentAxesPointsRequired == DOCUMENT_AXES_POINTS_REQUIRED_3) {
42 
43  // Axis point has one or coordinate
44  if (point.isXOnly()) {
45 
46  details += " " + QString::number (point.posGraph().x());
47 
48  } else {
49 
50  details += " " + QString::number (point.posGraph().y());
51 
52  }
53 
54  } else {
55 
56  // Axis point has two coordinates
57  details += " " + QPointFToString (point.posGraph());
58 
59  }
60  }
61 
62  LOG4CPP_DEBUG_S ((*mainCat)) << "CallbackDocumentHash::callback details=" << details.toLatin1().data();
63 
64  // Add details to hash
65  m_documentHash.addData (details.toLatin1());
66 
68 }
69 
70 DocumentHash CallbackDocumentHash::hash () const
71 {
72  return m_documentHash.result ();
73 }
bool isXOnly() const
In DOCUMENT_AXES_POINTS_REQUIRED_4 modes, this is true/false if y/x coordinate is undefined...
Definition: Point.cpp:274
bool isAxisPoint() const
True if point is an axis point. This is used only for sanity checks.
Definition: Point.cpp:269
CallbackSearchReturn callback(const QString &curveName, const Point &point)
Callback method.
Class that represents one digitized point. The screen-to-graph coordinate transformation is always ex...
Definition: Point.h:23
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:392
double ordinal(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Get method for ordinal. Skip check if copying one instance to another.
Definition: Point.cpp:374
CallbackSearchReturn
Return values for search callback methods.
Continue normal execution of the search.
QString identifier() const
Unique identifier for a specific Point.
Definition: Point.cpp:256
bool hasOrdinal() const
True if ordinal is defined.
Definition: Point.cpp:246
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
Definition: Point.cpp:383
CallbackDocumentHash(DocumentAxesPointsRequired documentAxesPointsRequired)
Single constructor.
DocumentHash hash() const
Computed hash value.