Engauge Digitizer 2
Loading...
Searching...
No Matches
GridLineLimiter Class Reference

Limit the number of grid lines so a bad combination of start/step/stop value will not lead to extremely long delays when the step size is much too small for the start/stop values. More...

#include <GridLineLimiter.h>

Collaboration diagram for GridLineLimiter:
Collaboration graph

Public Member Functions

 GridLineLimiter ()
 Single constructor.
void limitForXTheta (const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startX, double &stepX, double &stopX, unsigned int numX) const
 Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowModel is not exceeded.
void limitForYRadius (const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, double &startY, double &stepY, double &stopY, unsigned int numY) const
 Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowModel is not exceeded.

Detailed Description

Limit the number of grid lines so a bad combination of start/step/stop value will not lead to extremely long delays when the step size is much too small for the start/stop values.

Definition at line 22 of file GridLineLimiter.h.

Constructor & Destructor Documentation

◆ GridLineLimiter()

GridLineLimiter::GridLineLimiter ( )

Single constructor.

Definition at line 19 of file GridLineLimiter.cpp.

20{
21}

Member Function Documentation

◆ limitForXTheta()

void GridLineLimiter::limitForXTheta ( const Document & document,
const Transformation & transformation,
const DocumentModelCoords & modelCoords,
const MainWindowModel & modelMainWindow,
double & startX,
double & stepX,
double & stopX,
unsigned int numX ) const

Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowModel is not exceeded.

Definition at line 42 of file GridLineLimiter.cpp.

50{
51 bool needReduction = (countX > (unsigned int) modelMainWindow.maximumGridLines());
52
53 if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) {
54
55 // Linear
56 if (!needReduction) {
57 if (stepX <= 0) {
58 stepX = 0;
59 needReduction = true;
60 } else {
61 countX = qFloor (1.0 + (stopX - startX) / stepX);
62 needReduction = (countX > (unsigned int) modelMainWindow.maximumGridLines());
63 }
64 }
65
66 if (needReduction) {
67 stopX = startX + stepX * (modelMainWindow.maximumGridLines() - 1);
68 }
69
70 } else {
71
72 // Log
73 if (startX <= 0) {
74
75 // Start value is invalid so override both start and step
76 QPointF boundingRectGraphMin, boundingRectGraphMax;
77 documentBounds (document,
78 transformation,
79 boundingRectGraphMin,
80 boundingRectGraphMax);
81
82 // Override lower bound
83 startX = boundingRectGraphMin.x ();
84 }
85
86 if (!needReduction) {
87 if (stepX <= 1) {
88 stepX = 1;
89 needReduction = true;
90 } else {
91 countX = qFloor (1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX));
92 needReduction = (countX > (unsigned int) modelMainWindow.maximumGridLines());
93 }
94 }
95
96 if (needReduction) {
97 stopX = qExp (qLn (startX) + qLn (stepX) * (modelMainWindow.maximumGridLines() - 1));
98 }
99 }
100}
@ COORD_SCALE_LINEAR
Definition CoordScale.h:13
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
int maximumGridLines() const
Get method for maximum number of grid lines.

◆ limitForYRadius()

void GridLineLimiter::limitForYRadius ( const Document & document,
const Transformation & transformation,
const DocumentModelCoords & modelCoords,
const MainWindowModel & modelMainWindow,
double & startY,
double & stepY,
double & stopY,
unsigned int numY ) const

Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowModel is not exceeded.

Definition at line 102 of file GridLineLimiter.cpp.

110{
111 bool needReduction = (countY > (unsigned int) modelMainWindow.maximumGridLines());
112
113 if (modelCoords.coordScaleYRadius() == COORD_SCALE_LINEAR) {
114
115 // Linear
116 if (!needReduction) {
117 if (stepY <= 0) {
118 stepY = 0;
119 needReduction = true;
120 } else {
121 countY = qFloor (1.0 + (stopY - startY) / stepY);
122 needReduction = (countY > (unsigned int) modelMainWindow.maximumGridLines());
123 }
124 }
125
126 if (needReduction) {
127 stopY = startY + stepY * (modelMainWindow.maximumGridLines() - 1);
128 }
129
130 } else {
131
132 // Log
133 if (startY <= 0) {
134
135 // Start value is invalid so override both start and step
136 QPointF boundingRectGraphMin, boundingRectGraphMax;
137 documentBounds (document,
138 transformation,
139 boundingRectGraphMin,
140 boundingRectGraphMax);
141
142 // Override lower bound
143 startY = boundingRectGraphMin.y ();
144 }
145
146 if (!needReduction) {
147 if (stepY <= 1) {
148 stepY = 1;
149 needReduction = true;
150 } else {
151 countY = qFloor (1.0 + (qLn (stopY) - qLn (startY)) / qLn (stepY));
152 needReduction = (countY > (unsigned int) modelMainWindow.maximumGridLines());
153 }
154 }
155
156 if (needReduction) {
157 stopY = qExp (qLn (startY) + qLn (stepY) * (modelMainWindow.maximumGridLines() - 1));
158 }
159 }
160}
CoordScale coordScaleYRadius() const
Get method for linear/log scale on y/radius.

The documentation for this class was generated from the following files: