@@ -150,7 +150,7 m_shadesOpacity(1.0), | |||||
150 | m_min(0), |
|
150 | m_min(0), | |
151 | m_max(0), |
|
151 | m_max(0), | |
152 | m_ticksCount(5), |
|
152 | m_ticksCount(5), | |
153 | m_selection(NativeLabelsSelection) |
|
153 | m_niceNumbers(false) | |
154 | { |
|
154 | { | |
155 |
|
155 | |||
156 | } |
|
156 | } | |
@@ -344,7 +344,7 void QChartAxis::setRange(qreal min, qreal max) | |||||
344 |
|
344 | |||
345 | if(changed) { |
|
345 | if(changed) { | |
346 | emit rangeChanged(m_min,m_max); |
|
346 | emit rangeChanged(m_min,m_max); | |
347 |
emit this->changed(m_min, m_max, m_ticksCount, m_ |
|
347 | emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers); | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
@@ -356,7 +356,7 void QChartAxis::setTicksCount(int count) | |||||
356 | if(m_ticksCount!=count) { |
|
356 | if(m_ticksCount!=count) { | |
357 | m_ticksCount=count; |
|
357 | m_ticksCount=count; | |
358 | emit ticksCountChanged(count); |
|
358 | emit ticksCountChanged(count); | |
359 |
emit changed(m_min, m_max, m_ticksCount, m_ |
|
359 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); | |
360 | } |
|
360 | } | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
@@ -390,11 +390,11 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count) | |||||
390 | setTicksCount(count); |
|
390 | setTicksCount(count); | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | void QChartAxis::setLabelsSelectionMode(LabelsSelection mode) |
|
393 | void QChartAxis::setNiceNumbers(bool enabled) | |
394 | { |
|
394 | { | |
395 | if(m_selection!=mode){ |
|
395 | if(m_niceNumbers!=enabled){ | |
396 | m_selection=mode; |
|
396 | m_niceNumbers=enabled; | |
397 |
emit changed(m_min, m_max, m_ticksCount, m_ |
|
397 | emit changed(m_min, m_max, m_ticksCount, m_niceNumbers); | |
398 | } |
|
398 | } | |
399 | } |
|
399 | } | |
400 |
|
400 |
@@ -12,7 +12,6 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject | |||||
12 | { |
|
12 | { | |
13 | Q_OBJECT |
|
13 | Q_OBJECT | |
14 | public: |
|
14 | public: | |
15 | enum LabelsSelection{ NativeLabelsSelection, LooseLabelsSelection}; |
|
|||
16 |
|
15 | |||
17 | QChartAxis(QObject* parent =0); |
|
16 | QChartAxis(QObject* parent =0); | |
18 | ~QChartAxis(); |
|
17 | ~QChartAxis(); | |
@@ -62,8 +61,8 public: | |||||
62 | void setTicksCount(int count); |
|
61 | void setTicksCount(int count); | |
63 | int ticksCount() const { return m_ticksCount;} |
|
62 | int ticksCount() const { return m_ticksCount;} | |
64 |
|
63 | |||
65 | void setLabelsSelectionMode(LabelsSelection mode); |
|
64 | void setNiceNumbers(bool enabled); | |
66 | LabelsSelection labelsSelectionMode() const { return m_selection;} |
|
65 | bool niceNumbers() const { return m_niceNumbers;} | |
67 |
|
66 | |||
68 | QChartAxisCategories* categories() { return &m_category; } |
|
67 | QChartAxisCategories* categories() { return &m_category; } | |
69 |
|
68 | |||
@@ -78,7 +77,7 signals: | |||||
78 |
|
77 | |||
79 | //interal signal |
|
78 | //interal signal | |
80 | void updated(); |
|
79 | void updated(); | |
81 |
void changed(qreal min, qreal max, int tickCount, |
|
80 | void changed(qreal min, qreal max, int tickCount,bool niceNumbers); | |
82 | //internal slot |
|
81 | //internal slot | |
83 | public slots: |
|
82 | public slots: | |
84 | void handleAxisRangeChanged(qreal min, qreal max,int count); |
|
83 | void handleAxisRangeChanged(qreal min, qreal max,int count); | |
@@ -108,7 +107,7 private: | |||||
108 | int m_ticksCount; |
|
107 | int m_ticksCount; | |
109 | QChartAxisCategories m_category; |
|
108 | QChartAxisCategories m_category; | |
110 |
|
109 | |||
111 | LabelsSelection m_selection; |
|
110 | bool m_niceNumbers; | |
112 | }; |
|
111 | }; | |
113 |
|
112 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
113 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -10,7 +10,7 m_minY(0), | |||||
10 | m_maxY(0), |
|
10 | m_maxY(0), | |
11 | m_tickXCount(5), |
|
11 | m_tickXCount(5), | |
12 | m_tickYCount(5), |
|
12 | m_tickYCount(5), | |
13 | m_selection(QChartAxis::NativeLabelsSelection) |
|
13 | m_niceNumbers(false) | |
14 | { |
|
14 | { | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
@@ -40,7 +40,7 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCo | |||||
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | if(m_minX!=minX || m_maxX!=maxX) { |
|
42 | if(m_minX!=minX || m_maxX!=maxX) { | |
43 | niceNumbers(minX, maxX, m_tickXCount); |
|
43 | if(m_niceNumbers) looseNiceNumbers(minX, maxX, m_tickXCount); | |
44 | m_minX=minX; |
|
44 | m_minX=minX; | |
45 | m_maxX=maxX; |
|
45 | m_maxX=maxX; | |
46 | domainChanged=true; |
|
46 | domainChanged=true; | |
@@ -49,7 +49,7 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCo | |||||
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | if(m_minY!=minY || m_maxY!=maxY) { |
|
51 | if(m_minY!=minY || m_maxY!=maxY) { | |
52 | niceNumbers(minY, maxY, m_tickYCount); |
|
52 | if(m_niceNumbers) looseNiceNumbers(minY, maxY, m_tickYCount); | |
53 | m_minY=minY; |
|
53 | m_minY=minY; | |
54 | m_maxY=maxY; |
|
54 | m_maxY=maxY; | |
55 | domainChanged=true; |
|
55 | domainChanged=true; | |
@@ -137,8 +137,10 void Domain::zoomIn(const QRectF& rect, const QSizeF& size) | |||||
137 | m_minY = m_maxY - dy * rect.bottom(); |
|
137 | m_minY = m_maxY - dy * rect.bottom(); | |
138 | m_maxY = m_maxY - dy * rect.top(); |
|
138 | m_maxY = m_maxY - dy * rect.top(); | |
139 |
|
139 | |||
140 | niceNumbers(m_minX, m_maxX, m_tickXCount); |
|
140 | if(m_niceNumbers) { | |
141 |
|
|
141 | looseNiceNumbers(m_minX, m_maxX, m_tickXCount); | |
|
142 | looseNiceNumbers(m_minY, m_maxY, m_tickYCount); | |||
|
143 | } | |||
142 |
|
144 | |||
143 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); |
|
145 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); | |
144 | emit rangeXChanged(m_minX, m_maxX, m_tickXCount); |
|
146 | emit rangeXChanged(m_minX, m_maxX, m_tickXCount); | |
@@ -155,8 +157,10 void Domain::zoomOut(const QRectF& rect, const QSizeF& size) | |||||
155 | m_maxY = m_minY + dy * rect.bottom(); |
|
157 | m_maxY = m_minY + dy * rect.bottom(); | |
156 | m_minY = m_maxY - dy * size.height(); |
|
158 | m_minY = m_maxY - dy * size.height(); | |
157 |
|
159 | |||
158 | niceNumbers(m_minX, m_maxX, m_tickXCount); |
|
160 | if(m_niceNumbers) { | |
159 |
|
|
161 | looseNiceNumbers(m_minX, m_maxX, m_tickXCount); | |
|
162 | looseNiceNumbers(m_minY, m_maxY, m_tickYCount); | |||
|
163 | } | |||
160 |
|
164 | |||
161 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); |
|
165 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); | |
162 | emit rangeXChanged(m_minX, m_maxX, m_tickXCount); |
|
166 | emit rangeXChanged(m_minX, m_maxX, m_tickXCount); | |
@@ -182,26 +186,20 void Domain::move(int dx,int dy,const QSizeF& size) | |||||
182 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); |
|
186 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); | |
183 | } |
|
187 | } | |
184 |
|
188 | |||
185 |
void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount, |
|
189 | void Domain::handleAxisXChanged(qreal min,qreal max,int tickXCount,bool niceNumbers) | |
186 | { |
|
190 | { | |
187 | m_selection=mode; |
|
191 | m_niceNumbers=niceNumbers; | |
188 | setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount); |
|
192 | setRange(min,max,m_minY, m_maxY,tickXCount,m_tickYCount); | |
189 | } |
|
193 | } | |
190 |
|
194 | |||
191 |
void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount, |
|
195 | void Domain::handleAxisYChanged(qreal min,qreal max,int tickYCount,bool niceNumbers) | |
192 | { |
|
196 | { | |
193 | m_selection=mode; |
|
197 | m_niceNumbers=niceNumbers; | |
194 | setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount); |
|
198 | setRange(m_minX, m_maxX, min, max,m_tickXCount,tickYCount); | |
195 | } |
|
199 | } | |
196 |
|
200 | |||
197 | //algorithm defined by Paul S.Heckbert GraphicalGems I |
|
201 | //algorithm defined by Paul S.Heckbert GraphicalGems I | |
198 |
|
202 | |||
199 | void Domain::niceNumbers(qreal &min, qreal &max, int &ticksCount) |
|
|||
200 | { |
|
|||
201 | if(m_selection!=QChartAxis::NativeLabelsSelection) |
|
|||
202 | looseNiceNumbers(min,max,ticksCount); |
|
|||
203 | } |
|
|||
204 |
|
||||
205 | void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) |
|
203 | void Domain::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) | |
206 | { |
|
204 | { | |
207 | qreal range = niceNumber(max-min,true); //range with ceiling |
|
205 | qreal range = niceNumber(max-min,true); //range with ceiling |
@@ -1,7 +1,6 | |||||
1 | #ifndef DOMAIN_H_ |
|
1 | #ifndef DOMAIN_H_ | |
2 | #define DOMAIN_H_ |
|
2 | #define DOMAIN_H_ | |
3 | #include "qchartglobal.h" |
|
3 | #include "qchartglobal.h" | |
4 | #include "qchartaxis.h" |
|
|||
5 | #include <QRectF> |
|
4 | #include <QRectF> | |
6 | #include <QSizeF> |
|
5 | #include <QSizeF> | |
7 |
|
6 | |||
@@ -50,11 +49,10 signals: | |||||
50 | void rangeYChanged(qreal min, qreal max, int tickYCount); |
|
49 | void rangeYChanged(qreal min, qreal max, int tickYCount); | |
51 |
|
50 | |||
52 | public slots: |
|
51 | public slots: | |
53 |
void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5, |
|
52 | void handleAxisXChanged(qreal min,qreal max,int tickXCount = 5,bool niceNumbers = false); | |
54 |
void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5, |
|
53 | void handleAxisYChanged(qreal min,qreal max,int tickYCount = 5,bool niceNumbers = false); | |
55 |
|
54 | |||
56 | private: |
|
55 | private: | |
57 | void niceNumbers(qreal &min, qreal &max, int &ticksCount); |
|
|||
58 | void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); |
|
56 | void looseNiceNumbers(qreal &min, qreal &max, int &ticksCount); | |
59 | qreal niceNumber(qreal x,bool celing); |
|
57 | qreal niceNumber(qreal x,bool celing); | |
60 |
|
58 | |||
@@ -65,7 +63,7 private: | |||||
65 | qreal m_maxY; |
|
63 | qreal m_maxY; | |
66 | int m_tickXCount; |
|
64 | int m_tickXCount; | |
67 | int m_tickYCount; |
|
65 | int m_tickYCount; | |
68 | QChartAxis::LabelsSelection m_selection; |
|
66 | bool m_niceNumbers; | |
69 | }; |
|
67 | }; | |
70 |
|
68 | |||
71 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now