-
Notifications
You must be signed in to change notification settings - Fork 0
/
chartroutine.h
232 lines (215 loc) · 7.1 KB
/
chartroutine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#ifndef CHARTROUTINE_H
#define CHARTROUTINE_H
#include <QString>
#include <QStringList>
#include <QDateTime>
#include <QFont>
#include "numeral.h"
struct FloatRange
{
double min;
double max;
FloatRange();
FloatRange(double value);
FloatRange(double aMin, double aMax);
bool operator == (const FloatRange &right) const;
bool operator != (const FloatRange &right) const;
bool isValid() const;
bool isSingleValue() const;
double singleValue() const;
double length() const;
bool contains(double value) const;
bool isSubsetOf(const FloatRange &another) const;
void append(double value);
void append(const FloatRange &another);
void clear();
FloatRange& operator << (double value);
FloatRange& operator << (const FloatRange &another);
QString toString() const;
};
struct DateTimeRange
{
QDateTime min;
QDateTime max;
DateTimeRange();
DateTimeRange(const QDateTime &value);
DateTimeRange(const QDateTime &aMin, const QDateTime &aMax);
bool operator == (const DateTimeRange &right) const;
bool operator != (const DateTimeRange &right) const;
bool isValid() const;
bool isSingleValue() const;
qint64 secondsSpan() const;
bool contains(const QDateTime &value) const;
bool isSubsetOf(const DateTimeRange &another) const;
void append(const QDateTime &value);
void append(const DateTimeRange &another);
void clear();
DateTimeRange& operator << (const QDateTime &value);
DateTimeRange& operator << (const DateTimeRange &another);
DateTimeRange intersected(const DateTimeRange &another) const;
QString toString() const;
};
struct ScreenPoints
{
double pointAtMin;
double pointAtMax;
double minMarkPoint;
double maxMarkPoint;
ScreenPoints();
ScreenPoints(double aPointAtMin, double aPointAtMax);
ScreenPoints(double aPointAtMin, double aPointAtMax, double aMinMarkPoint, double aMaxMarkPoint);
ScreenPoints(const ScreenPoints &another);
bool operator == (const ScreenPoints &right) const;
bool operator != (const ScreenPoints &right) const;
bool isValid() const;
};
class Scale
{
public:
Scale();
void setOrientation(Qt::Orientation value);
Qt::Orientation orientation() const;
void setFont(const QFont &value);
QFont font() const;
void setMinimalMarkSpacing(double value);
double minimalMarkSpacing() const;
void setScreenPoints(const ScreenPoints &value);
ScreenPoints screenPoints() const;
void setLogicRange(const FloatRange &value);
FloatRange logicRange() const;
virtual bool isReady() const;
void setRequestUseExponentialTransformation(bool value);
bool requestUseExponentialTransformation() const;
bool canUseExponentialTransformation() const;
bool useExponentialTransformation() const;
double screenToLogic(double screen) const;
double logicToScreen(double logic) const;
double worstScaleCoef() const;
protected:
void changed();
bool isStepStringAvailable(const QString &stepString, double distanceBetween) const;
virtual void computeParams();
private:
struct LinearTransformation
{
// logic = a*screen + b
double a;
double b;
ScreenPoints screenPoints;
LinearTransformation();
bool allow(const ScreenPoints &aScreenPoints, const FloatRange &aLogicRange) const;
bool initialize(const ScreenPoints &aScreenPoints, const FloatRange &aLogicRange);
bool isReady() const;
double screenToLogic(double screen) const;
double logicToScreen(double logic) const;
double worstScaleCoef() const;
bool isSingleValue() const;
};
struct ExponentialTransformation
{
// logic = b * c^screen
double b;
double c;
FloatRange innerRange;
ExponentialTransformation();
bool allow(const ScreenPoints &aScreenPoints, const FloatRange &aLogicRange) const;
bool initialize(const ScreenPoints &aScreenPoints, const FloatRange &aLogicRange);
bool isReady() const;
double screenToLogic(double screen) const;
double logicToScreen(double logic) const;
double worstScaleCoef() const;
};
LinearTransformation m_linearTransformation;
ExponentialTransformation m_exponentialTransformation;
Qt::Orientation m_orientation;
QFont m_font;
double m_minimalMarkSpacing;
ScreenPoints m_screenPoints;
FloatRange m_logicRange;
bool m_requestUseExponentialTransformation;
};
struct FloatScaleMark
{
double value;
QString text;
double position;
FloatScaleMark();
FloatScaleMark(double aValue, const QString &aText, double aPosition);
bool isValid() const;
};
typedef QList<FloatScaleMark> FloatScaleMarkList;
class FloatScale : public Scale
{
public:
FloatScale();
FloatScaleMarkList markList() const;
protected:
void computeParams() override;
private:
double m_step;
int m_stepPrecision;
NumeralFormat m_stepNumeralFormat;
FloatScaleMarkList m_markList;
int stepPrecision(double step, int tuneDigits) const;
FloatRange stepRange(double step) const;
bool isStepAvailable(double step, int tuneDigits) const;
void findStep(double min, double max);
void computeStep();
void computeMarkList();
};
struct DateTimeScaleStep
{
enum Type {Minute, Hour, Day, Week, Month, Quarter, Year};
Type type;
int count;
DateTimeScaleStep();
DateTimeScaleStep(Type aType, int aCount);
DateTimeScaleStep(const DateTimeScaleStep &another);
bool isIntraday() const;
int seconds() const;
QDateTime floorValue(const QDateTime &baseValue) const;
QDateTime ceilValue(const QDateTime &baseValue) const;
QDateTime add(const QDateTime &startValue, int intervals) const;
QString format(const QDateTime &testValue) const;
QString toString() const;
};
typedef QList<DateTimeScaleStep> DateTimeScaleSteps;
struct DateTimeScaleMark
{
QDateTime value;
QString text;
double position;
DateTimeScaleMark();
DateTimeScaleMark(const QDateTime &aValue, const QString &aText, double aPosition);
bool isValid() const;
};
typedef QList<DateTimeScaleMark> DateTimeScaleMarkList;
class DateTimeScale : public Scale
{
public:
DateTimeScale();
void setValues(const QList<QDateTime> &value);
QList<QDateTime> values() const;
void setIntradayFlag(bool value);
bool intradayFlag() const;
double dateTimeToLogic(const QDateTime &dateTime) const;
double dateTimeToScreen(const QDateTime &dateTime) const;
QDateTime logicToDateTime(double logic) const;
QDateTime screenToDateTime(double screen) const;
DateTimeRange dateTimeRange() const;
DateTimeScaleMarkList markList() const;
protected:
void computeParams() override;
private:
DateTimeScaleSteps m_possibleSteps;
QList<QDateTime> m_values;
bool m_intradayFlag;
DateTimeScaleStep m_step;
DateTimeScaleMarkList m_markList;
void initializePossibleSteps();
DateTimeRange stepRange(const DateTimeScaleStep &step) const;
bool isStepAvailable(const DateTimeScaleStep &step) const;
void computeStep();
void computeMarkList();
};
#endif // CHARTROUTINE_H