Engauge Digitizer  2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | List of all members
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. More...
 
void limitForXTheta (const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startX, double &stepX, double &stopX) const
 Limit step value for x/theta coordinate. This is a noop if the maximum grid line limit in MainWindowModel is not exceeded. More...
 
void limitForYRadius (const Document &document, const Transformation &transformation, const DocumentModelCoords &modelCoords, const MainWindowModel &modelMainWindow, const DocumentModelGridDisplay &modelGrid, double &startY, double &stepY, double &stopY) const
 Limit step value for y/range coordinate. This is a noop if the maximum grid line limit in MainWindowModel is not exceeded. More...
 

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 23 of file GridLineLimiter.h.

Constructor & Destructor Documentation

GridLineLimiter::GridLineLimiter ( )

Single constructor.

Definition at line 19 of file GridLineLimiter.cpp.

20 {
21 }

Member Function Documentation

void GridLineLimiter::limitForXTheta ( const Document document,
const Transformation transformation,
const DocumentModelCoords modelCoords,
const MainWindowModel modelMainWindow,
const DocumentModelGridDisplay modelGrid,
double &  startX,
double &  stepX,
double &  stopX 
) 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  startX = modelGrid.startX();
52  stopX = modelGrid.stopX();
53  stepX = modelGrid.stepX();
54  int countX = signed (modelGrid.countX());
55 
56  bool needReduction = (countX > modelMainWindow.maximumGridLines());
57 
58  if (modelCoords.coordScaleXTheta() == COORD_SCALE_LINEAR) {
59 
60  // Linear
61  if (!needReduction) {
62  if (stepX <= 0) {
63  stepX = 0;
64  needReduction = true;
65  } else {
66  countX = qFloor (1.0 + (stopX - startX) / stepX);
67  needReduction = (countX > modelMainWindow.maximumGridLines());
68  }
69  }
70 
71  if (needReduction) {
72  stopX = startX + stepX * (modelMainWindow.maximumGridLines() - 1);
73  }
74 
75  } else {
76 
77  // Log
78  if (startX <= 0) {
79 
80  // Start value is invalid so override both start and step
81  QPointF boundingRectGraphMin, boundingRectGraphMax;
82  documentBounds (document,
83  transformation,
84  boundingRectGraphMin,
85  boundingRectGraphMax);
86 
87  // Override lower bound
88  startX = boundingRectGraphMin.x ();
89  }
90 
91  if (!needReduction) {
92  if (stepX <= 1) {
93  stepX = 1;
94  needReduction = true;
95  } else {
96  countX = qFloor (1.0 + (qLn (stopX) - qLn (startX)) / qLn (stepX));
97  needReduction = (countX > modelMainWindow.maximumGridLines());
98  }
99  }
100 
101  if (needReduction) {
102  stopX = qExp (qLn (startX) + qLn (stepX) * (modelMainWindow.maximumGridLines() - 1));
103  }
104  }
105 }
double stopX() const
Get method for x grid line upper bound (inclusive).
double stepX() const
Get method for x grid line increment.
double startX() const
Get method for x grid line lower bound (inclusive).
int maximumGridLines() const
Maximum number of grid lines.
CoordScale coordScaleXTheta() const
Get method for linear/log scale on x/theta.
unsigned int countX() const
Get method for x grid line count.
void GridLineLimiter::limitForYRadius ( const Document document,
const Transformation transformation,
const DocumentModelCoords modelCoords,
const MainWindowModel modelMainWindow,
const DocumentModelGridDisplay modelGrid,
double &  startY,
double &  stepY,
double &  stopY 
) 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 107 of file GridLineLimiter.cpp.

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

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