Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
CallbackBoundingRects.cpp
1 #include "CallbackBoundingRects.h"
2 #include "EngaugeAssert.h"
3 #include "Logger.h"
4 #include "Point.h"
5 #include <qmath.h>
6 #include "QtToString.h"
7 #include "Transformation.h"
8 
10  m_isEmpty (true),
11  m_transformation (transformation)
12 {
13 }
14 
15 QRectF CallbackBoundingRects::boundingRectGraph (bool &isEmpty) const
16 {
17  isEmpty = m_isEmpty;
18 
19  return m_boundingRectGraph;
20 }
21 
22 QRectF CallbackBoundingRects::boundingRectScreen (bool &isEmpty) const
23 {
24  isEmpty = m_isEmpty;
25 
26  return m_boundingRectScreen;
27 }
28 
30  const Point &point)
31 {
32  QPointF posGraph;
33  if (curveName == AXIS_CURVE_NAME) {
34  posGraph = point.posGraph(); // Axis point has graph coordinates
35  } else {
36  m_transformation.transformScreenToRawGraph (point.posScreen(),
37  posGraph); // Curve point has undefined graph coordinates, but they can be calculated
38  }
39  mergeCoordinates (posGraph,
40  m_boundingRectGraph);
41  mergeCoordinates (point.posScreen(),
42  m_boundingRectScreen);
43 
44  m_isEmpty = false; // Set this after the calls to mergeCoordinates which uses it
45 
47 }
48 
49 void CallbackBoundingRects::mergeCoordinates (const QPointF &pos,
50  QRectF &boundingRect)
51 {
52  bool newGraphLeft = m_isEmpty;
53  bool newGraphTop = m_isEmpty;
54  bool newGraphRight = m_isEmpty;
55  bool newGraphBottom = m_isEmpty;
56 
57  if (!newGraphLeft) {
58  newGraphLeft = (pos.x() < boundingRect.left());
59  }
60  if (!newGraphTop) {
61  newGraphTop = (pos.y() < boundingRect.top());
62  }
63  if (!newGraphRight) {
64  newGraphRight = (boundingRect.right() < pos.x());
65  }
66  if (!newGraphBottom) {
67  newGraphBottom = (boundingRect.bottom() < pos.y());
68  }
69 
70  if (newGraphLeft) {
71  boundingRect.setLeft (pos.x());
72  }
73  if (newGraphTop) {
74  boundingRect.setTop (pos.y());
75  }
76  if (newGraphRight) {
77  boundingRect.setRight (pos.x());
78  }
79  if (newGraphBottom) {
80  boundingRect.setBottom (pos.y());
81  }
82 }
void transformScreenToRawGraph(const QPointF &coordScreen, QPointF &coordGraph) const
Transform from cartesian pixel screen coordinates to cartesian/polar graph coordinates.
QPointF posGraph(ApplyHasCheck applyHasCheck=KEEP_HAS_CHECK) const
Accessor for graph position. Skip check if copying one instance to another.
Definition: Point.cpp:335
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:17
QPointF posScreen() const
Accessor for screen position.
Definition: Point.cpp:344
CallbackSearchReturn
Return values for search callback methods.
Continue normal execution of the search.
Affine transformation between screen and graph coordinates, based on digitized axis points...
QRectF boundingRectGraph(bool &isEmpty) const
Graph coordinate bounding rectangle.
QRectF boundingRectScreen(bool &isEmpty) const
Screen coordinate bounding rectangle.
CallbackBoundingRects(const Transformation &transformation)
Single constructor.