@@ -1,403 +1,403 | |||||
1 | #include "qchartaxis.h" |
|
1 | #include "qchartaxis.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | /*! |
|
5 | /*! | |
6 | \class QChartAxis |
|
6 | \class QChartAxis | |
7 | \brief The QChartAxis class is used for manipulating chart's axis |
|
7 | \brief The QChartAxis class is used for manipulating chart's axis | |
8 | and for adding optional axes to the chart. |
|
8 | and for adding optional axes to the chart. | |
9 | \mainclass |
|
9 | \mainclass | |
10 |
|
10 | |||
11 | There is only one x Axis, however there can be multiple y axes. |
|
11 | There is only one x Axis, however there can be multiple y axes. | |
12 | Each chart series can be bound to exactly one Y axis and the share common X axis. |
|
12 | Each chart series can be bound to exactly one Y axis and the share common X axis. | |
13 | Axis can be setup to show axis line with ticks, gird lines and shades. |
|
13 | Axis can be setup to show axis line with ticks, gird lines and shades. | |
14 |
|
14 | |||
15 | */ |
|
15 | */ | |
16 |
|
16 | |||
17 | /*! |
|
17 | /*! | |
18 | \fn bool QChartAxis::isAxisVisible() const |
|
18 | \fn bool QChartAxis::isAxisVisible() const | |
19 | \brief Returns if axis is visible |
|
19 | \brief Returns if axis is visible | |
20 | \sa setAxisVisible() |
|
20 | \sa setAxisVisible() | |
21 | */ |
|
21 | */ | |
22 |
|
22 | |||
23 | /*! |
|
23 | /*! | |
24 | \fn QPen QChartAxis::axisPen() const |
|
24 | \fn QPen QChartAxis::axisPen() const | |
25 | \brief Returns pen used to draw axis and ticks. |
|
25 | \brief Returns pen used to draw axis and ticks. | |
26 | \sa setAxisPen() |
|
26 | \sa setAxisPen() | |
27 | */ |
|
27 | */ | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \fn bool QChartAxis::isGridLineVisible() const |
|
31 | \fn bool QChartAxis::isGridLineVisible() const | |
32 | \brief Returns if grid is visible |
|
32 | \brief Returns if grid is visible | |
33 | \sa setGridLineVisible() |
|
33 | \sa setGridLineVisible() | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \fn QPen QChartAxis::gridLinePen() const |
|
37 | \fn QPen QChartAxis::gridLinePen() const | |
38 | \brief Returns pen used to draw grid. |
|
38 | \brief Returns pen used to draw grid. | |
39 | \sa setGridLinePen() |
|
39 | \sa setGridLinePen() | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \fn bool QChartAxis::labelsVisible() const |
|
43 | \fn bool QChartAxis::labelsVisible() const | |
44 | \brief Returns if grid is visible |
|
44 | \brief Returns if grid is visible | |
45 | \sa setLabelsVisible() |
|
45 | \sa setLabelsVisible() | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn QPen QChartAxis::labelsPen() const |
|
49 | \fn QPen QChartAxis::labelsPen() const | |
50 | \brief Returns the pen used to labels. |
|
50 | \brief Returns the pen used to labels. | |
51 | \sa setLabelsPen() |
|
51 | \sa setLabelsPen() | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \fn QBrush QChartAxis::labelsBrush() const |
|
55 | \fn QBrush QChartAxis::labelsBrush() const | |
56 | \brief Returns brush used to draw labels. |
|
56 | \brief Returns brush used to draw labels. | |
57 | \sa setLabelsBrush() |
|
57 | \sa setLabelsBrush() | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \fn QFont QChartAxis::labelsFont() const |
|
61 | \fn QFont QChartAxis::labelsFont() const | |
62 | \brief Returns font used to draw labels. |
|
62 | \brief Returns font used to draw labels. | |
63 | \sa setLabelsFont() |
|
63 | \sa setLabelsFont() | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \fn QFont QChartAxis::labelsAngle() const |
|
67 | \fn QFont QChartAxis::labelsAngle() const | |
68 | \brief Returns angle used to draw labels. |
|
68 | \brief Returns angle used to draw labels. | |
69 | \sa setLabelsAngle() |
|
69 | \sa setLabelsAngle() | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \fn bool QChartAxis::shadesVisible() const |
|
73 | \fn bool QChartAxis::shadesVisible() const | |
74 | \brief Returns if shades are visible. |
|
74 | \brief Returns if shades are visible. | |
75 | \sa setShadesVisible() |
|
75 | \sa setShadesVisible() | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \fn qreal QChartAxis::shadesOpacity() const |
|
79 | \fn qreal QChartAxis::shadesOpacity() const | |
80 | \brief Returns opacity of shades. |
|
80 | \brief Returns opacity of shades. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \fn QPen QChartAxis::shadesPen() const |
|
84 | \fn QPen QChartAxis::shadesPen() const | |
85 | \brief Returns pen used to draw shades. |
|
85 | \brief Returns pen used to draw shades. | |
86 | \sa setShadesPen() |
|
86 | \sa setShadesPen() | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \fn QBrush QChartAxis::shadesBrush() const |
|
90 | \fn QBrush QChartAxis::shadesBrush() const | |
91 | \brief Returns brush used to draw shades. |
|
91 | \brief Returns brush used to draw shades. | |
92 | \sa setShadesBrush() |
|
92 | \sa setShadesBrush() | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \fn qreal QChartAxis::min() const |
|
96 | \fn qreal QChartAxis::min() const | |
97 | \brief Returns minimum value on the axis. |
|
97 | \brief Returns minimum value on the axis. | |
98 | \sa setMin() |
|
98 | \sa setMin() | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \fn qreal QChartAxis::max() const |
|
102 | \fn qreal QChartAxis::max() const | |
103 | \brief Returns maximim value on the axis. |
|
103 | \brief Returns maximim value on the axis. | |
104 | \sa setMax() |
|
104 | \sa setMax() | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \fn void QChartAxis::minChanged(qreal min) |
|
108 | \fn void QChartAxis::minChanged(qreal min) | |
109 | \brief Axis emits signal when \a min of axis has changed. |
|
109 | \brief Axis emits signal when \a min of axis has changed. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QChartAxis::maxChanged(qreal max) |
|
113 | \fn void QChartAxis::maxChanged(qreal max) | |
114 | \brief Axis emits signal when \a max of axis has changed. |
|
114 | \brief Axis emits signal when \a max of axis has changed. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QChartAxis::rangeChanged(qreal min, qreal max) |
|
118 | \fn void QChartAxis::rangeChanged(qreal min, qreal max) | |
119 | \brief Axis emits signal when \a min or \a max of axis has changed. |
|
119 | \brief Axis emits signal when \a min or \a max of axis has changed. | |
120 | */ |
|
120 | */ | |
121 |
|
121 | |||
122 | /*! |
|
122 | /*! | |
123 | \fn int QChartAxis::ticksCount() const |
|
123 | \fn int QChartAxis::ticksCount() const | |
124 | \brief Return number of ticks on the axis |
|
124 | \brief Return number of ticks on the axis | |
125 | \sa setTicksCount() |
|
125 | \sa setTicksCount() | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \fn void QChartAxis::updated() |
|
129 | \fn void QChartAxis::updated() | |
130 | \brief \internal |
|
130 | \brief \internal | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) |
|
134 | \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) | |
135 | \brief \internal \a min \a max |
|
135 | \brief \internal \a min \a max | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
139 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
140 | QChatView or QChart when axis added. |
|
140 | QChatView or QChart when axis added. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), |
|
143 | QChartAxis::QChartAxis(QObject* parent):QObject(parent), | |
144 | m_axisVisible(true), |
|
144 | m_axisVisible(true), | |
145 | m_gridLineVisible(true), |
|
145 | m_gridLineVisible(true), | |
146 | m_labelsVisible(true), |
|
146 | m_labelsVisible(true), | |
147 | m_labelsAngle(0), |
|
147 | m_labelsAngle(0), | |
148 | m_shadesVisible(false), |
|
148 | m_shadesVisible(false), | |
149 | m_shadesOpacity(1.0), |
|
149 | 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 | } | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
159 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | QChartAxis::~QChartAxis() |
|
162 | QChartAxis::~QChartAxis() | |
163 | { |
|
163 | { | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Sets \a pen used to draw axis line and ticks. |
|
167 | Sets \a pen used to draw axis line and ticks. | |
168 | */ |
|
168 | */ | |
169 | void QChartAxis::setAxisPen(const QPen& pen) |
|
169 | void QChartAxis::setAxisPen(const QPen& pen) | |
170 | { |
|
170 | { | |
171 | if (pen != m_axisPen) { |
|
171 | if (pen != m_axisPen) { | |
172 | m_axisPen=pen; |
|
172 | m_axisPen=pen; | |
173 | emit updated(); |
|
173 | emit updated(); | |
174 | } |
|
174 | } | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Sets if axis and ticks are \a visible. |
|
178 | Sets if axis and ticks are \a visible. | |
179 | */ |
|
179 | */ | |
180 | void QChartAxis::setAxisVisible(bool visible) |
|
180 | void QChartAxis::setAxisVisible(bool visible) | |
181 | { |
|
181 | { | |
182 | if (m_axisVisible!=visible) { |
|
182 | if (m_axisVisible!=visible) { | |
183 | m_axisVisible=visible; |
|
183 | m_axisVisible=visible; | |
184 | emit updated(); |
|
184 | emit updated(); | |
185 | } |
|
185 | } | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | Sets if grid line is \a visible. |
|
189 | Sets if grid line is \a visible. | |
190 | */ |
|
190 | */ | |
191 | void QChartAxis::setGridLineVisible(bool visible) |
|
191 | void QChartAxis::setGridLineVisible(bool visible) | |
192 | { |
|
192 | { | |
193 | if (m_gridLineVisible!=visible) { |
|
193 | if (m_gridLineVisible!=visible) { | |
194 | m_gridLineVisible=visible; |
|
194 | m_gridLineVisible=visible; | |
195 | emit updated(); |
|
195 | emit updated(); | |
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | Sets \a pen used to draw grid line. |
|
200 | Sets \a pen used to draw grid line. | |
201 | */ |
|
201 | */ | |
202 | void QChartAxis::setGridLinePen(const QPen& pen) |
|
202 | void QChartAxis::setGridLinePen(const QPen& pen) | |
203 | { |
|
203 | { | |
204 | if (m_gridLinePen!=pen) { |
|
204 | if (m_gridLinePen!=pen) { | |
205 | m_gridLinePen=pen; |
|
205 | m_gridLinePen=pen; | |
206 | emit updated(); |
|
206 | emit updated(); | |
207 | } |
|
207 | } | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Sets if axis' labels are \a visible. |
|
211 | Sets if axis' labels are \a visible. | |
212 | */ |
|
212 | */ | |
213 | void QChartAxis::setLabelsVisible(bool visible) |
|
213 | void QChartAxis::setLabelsVisible(bool visible) | |
214 | { |
|
214 | { | |
215 | if(m_labelsVisible!=visible) { |
|
215 | if(m_labelsVisible!=visible) { | |
216 | m_labelsVisible=visible; |
|
216 | m_labelsVisible=visible; | |
217 | emit updated(); |
|
217 | emit updated(); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | Sets \a pen used to draw labels. |
|
222 | Sets \a pen used to draw labels. | |
223 | */ |
|
223 | */ | |
224 | void QChartAxis::setLabelsPen(const QPen& pen) |
|
224 | void QChartAxis::setLabelsPen(const QPen& pen) | |
225 | { |
|
225 | { | |
226 | if(m_labelsPen!=pen) { |
|
226 | if(m_labelsPen!=pen) { | |
227 | m_labelsPen=pen; |
|
227 | m_labelsPen=pen; | |
228 | emit updated(); |
|
228 | emit updated(); | |
229 | } |
|
229 | } | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | Sets \a brush used to draw labels. |
|
233 | Sets \a brush used to draw labels. | |
234 | */ |
|
234 | */ | |
235 | void QChartAxis::setLabelsBrush(const QBrush& brush) |
|
235 | void QChartAxis::setLabelsBrush(const QBrush& brush) | |
236 | { |
|
236 | { | |
237 | if(m_labelsBrush!=brush) { |
|
237 | if(m_labelsBrush!=brush) { | |
238 | m_labelsBrush=brush; |
|
238 | m_labelsBrush=brush; | |
239 | emit updated(); |
|
239 | emit updated(); | |
240 | } |
|
240 | } | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | Sets \a font used to draw labels. |
|
244 | Sets \a font used to draw labels. | |
245 | */ |
|
245 | */ | |
246 | void QChartAxis::setLabelsFont(const QFont& font) |
|
246 | void QChartAxis::setLabelsFont(const QFont& font) | |
247 | { |
|
247 | { | |
248 | if(m_labelsFont!=font) { |
|
248 | if(m_labelsFont!=font) { | |
249 | m_labelsFont=font; |
|
249 | m_labelsFont=font; | |
250 | emit updated(); |
|
250 | emit updated(); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | Sets \a angle for all the labels on given axis. |
|
255 | Sets \a angle for all the labels on given axis. | |
256 | */ |
|
256 | */ | |
257 | void QChartAxis::setLabelsAngle(int angle) |
|
257 | void QChartAxis::setLabelsAngle(int angle) | |
258 | { |
|
258 | { | |
259 | if(m_labelsAngle!=angle) { |
|
259 | if(m_labelsAngle!=angle) { | |
260 | m_labelsAngle=angle; |
|
260 | m_labelsAngle=angle; | |
261 | emit updated(); |
|
261 | emit updated(); | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | /*! |
|
265 | /*! | |
266 | Sets if shades are \a visible. |
|
266 | Sets if shades are \a visible. | |
267 | */ |
|
267 | */ | |
268 | void QChartAxis::setShadesVisible(bool visible) |
|
268 | void QChartAxis::setShadesVisible(bool visible) | |
269 | { |
|
269 | { | |
270 | if(m_shadesVisible!=visible) { |
|
270 | if(m_shadesVisible!=visible) { | |
271 | m_shadesVisible=visible; |
|
271 | m_shadesVisible=visible; | |
272 | emit updated(); |
|
272 | emit updated(); | |
273 | } |
|
273 | } | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | /*! |
|
276 | /*! | |
277 | Sets \a pen used to draw shades. |
|
277 | Sets \a pen used to draw shades. | |
278 | */ |
|
278 | */ | |
279 | void QChartAxis::setShadesPen(const QPen& pen) |
|
279 | void QChartAxis::setShadesPen(const QPen& pen) | |
280 | { |
|
280 | { | |
281 | if(m_shadesPen!=pen) { |
|
281 | if(m_shadesPen!=pen) { | |
282 | m_shadesPen=pen; |
|
282 | m_shadesPen=pen; | |
283 | emit updated(); |
|
283 | emit updated(); | |
284 | } |
|
284 | } | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | Sets \a brush used to draw shades. |
|
288 | Sets \a brush used to draw shades. | |
289 | */ |
|
289 | */ | |
290 | void QChartAxis::setShadesBrush(const QBrush& brush) |
|
290 | void QChartAxis::setShadesBrush(const QBrush& brush) | |
291 | { |
|
291 | { | |
292 | if(m_shadesBrush!=brush) { |
|
292 | if(m_shadesBrush!=brush) { | |
293 | m_shadesBrush=brush; |
|
293 | m_shadesBrush=brush; | |
294 | emit updated(); |
|
294 | emit updated(); | |
295 | } |
|
295 | } | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | /*! |
|
298 | /*! | |
299 | Sets \a opacity of the shades. |
|
299 | Sets \a opacity of the shades. | |
300 | */ |
|
300 | */ | |
301 | void QChartAxis::setShadesOpacity(qreal opacity) |
|
301 | void QChartAxis::setShadesOpacity(qreal opacity) | |
302 | { |
|
302 | { | |
303 | if(m_shadesOpacity!=opacity) { |
|
303 | if(m_shadesOpacity!=opacity) { | |
304 | m_shadesOpacity=opacity; |
|
304 | m_shadesOpacity=opacity; | |
305 | emit updated(); |
|
305 | emit updated(); | |
306 | } |
|
306 | } | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Sets \a min value on the axis. |
|
310 | Sets \a min value on the axis. | |
311 | */ |
|
311 | */ | |
312 | void QChartAxis::setMin(qreal min) |
|
312 | void QChartAxis::setMin(qreal min) | |
313 | { |
|
313 | { | |
314 | setRange(min,m_max); |
|
314 | setRange(min,m_max); | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | /*! |
|
317 | /*! | |
318 | Sets \a max value on the axis. |
|
318 | Sets \a max value on the axis. | |
319 | */ |
|
319 | */ | |
320 | void QChartAxis::setMax(qreal max) |
|
320 | void QChartAxis::setMax(qreal max) | |
321 | { |
|
321 | { | |
322 | setRange(m_min,max); |
|
322 | setRange(m_min,max); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | /*! |
|
325 | /*! | |
326 | Sets range from \a min to \a max on the axis. |
|
326 | Sets range from \a min to \a max on the axis. | |
327 | */ |
|
327 | */ | |
328 | void QChartAxis::setRange(qreal min, qreal max) |
|
328 | void QChartAxis::setRange(qreal min, qreal max) | |
329 | { |
|
329 | { | |
330 |
|
330 | |||
331 |
|
331 | |||
332 | bool changed = false; |
|
332 | bool changed = false; | |
333 | if(m_min!=min) { |
|
333 | if(m_min!=min) { | |
334 | m_min=min; |
|
334 | m_min=min; | |
335 | changed=true; |
|
335 | changed=true; | |
336 | emit minChanged(min); |
|
336 | emit minChanged(min); | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | if(m_max!=max) { |
|
339 | if(m_max!=max) { | |
340 | m_max=max; |
|
340 | m_max=max; | |
341 | changed=true; |
|
341 | changed=true; | |
342 | emit maxChanged(max); |
|
342 | emit maxChanged(max); | |
343 | } |
|
343 | } | |
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 | |||
351 | /*! |
|
351 | /*! | |
352 | Sets \a count for ticks on the axis. |
|
352 | Sets \a count for ticks on the axis. | |
353 | */ |
|
353 | */ | |
354 | void QChartAxis::setTicksCount(int count) |
|
354 | void QChartAxis::setTicksCount(int count) | |
355 | { |
|
355 | { | |
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 | |||
363 | /*! |
|
363 | /*! | |
364 | Sets axis, shades, labels and grid lines to be visible. |
|
364 | Sets axis, shades, labels and grid lines to be visible. | |
365 | */ |
|
365 | */ | |
366 | void QChartAxis::show() |
|
366 | void QChartAxis::show() | |
367 | { |
|
367 | { | |
368 | m_axisVisible=true; |
|
368 | m_axisVisible=true; | |
369 | m_gridLineVisible=true; |
|
369 | m_gridLineVisible=true; | |
370 | m_labelsVisible=true; |
|
370 | m_labelsVisible=true; | |
371 | m_shadesVisible=true; |
|
371 | m_shadesVisible=true; | |
372 | emit updated(); |
|
372 | emit updated(); | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | /*! |
|
375 | /*! | |
376 | Sets axis, shades, labels and grid lines to not be visible. |
|
376 | Sets axis, shades, labels and grid lines to not be visible. | |
377 | */ |
|
377 | */ | |
378 | void QChartAxis::hide() |
|
378 | void QChartAxis::hide() | |
379 | { |
|
379 | { | |
380 | m_axisVisible=false; |
|
380 | m_axisVisible=false; | |
381 | m_gridLineVisible=false; |
|
381 | m_gridLineVisible=false; | |
382 | m_labelsVisible=false; |
|
382 | m_labelsVisible=false; | |
383 | m_shadesVisible=false; |
|
383 | m_shadesVisible=false; | |
384 | emit updated(); |
|
384 | emit updated(); | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count) |
|
387 | void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count) | |
388 | { |
|
388 | { | |
389 | setRange(min,max); |
|
389 | setRange(min,max); | |
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 | |||
401 | #include "moc_qchartaxis.cpp" |
|
401 | #include "moc_qchartaxis.cpp" | |
402 |
|
402 | |||
403 | QTCOMMERCIALCHART_END_NAMESPACE |
|
403 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,115 +1,114 | |||||
1 | #ifndef QCHARTAXIS_H_ |
|
1 | #ifndef QCHARTAXIS_H_ | |
2 | #define QCHARTAXIS_H_ |
|
2 | #define QCHARTAXIS_H_ | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchartaxiscategories.h" |
|
5 | #include "qchartaxiscategories.h" | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 | #include <QFont> |
|
7 | #include <QFont> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject |
|
11 | 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(); | |
19 |
|
18 | |||
20 | //axis handling |
|
19 | //axis handling | |
21 | bool isAxisVisible() const { return m_axisVisible;}; |
|
20 | bool isAxisVisible() const { return m_axisVisible;}; | |
22 | void setAxisVisible(bool visible); |
|
21 | void setAxisVisible(bool visible); | |
23 | void setAxisPen(const QPen& pen); |
|
22 | void setAxisPen(const QPen& pen); | |
24 | QPen axisPen() const { return m_axisPen;}; |
|
23 | QPen axisPen() const { return m_axisPen;}; | |
25 |
|
24 | |||
26 | //grid handling |
|
25 | //grid handling | |
27 | bool isGridLineVisible() const { return m_gridLineVisible;}; |
|
26 | bool isGridLineVisible() const { return m_gridLineVisible;}; | |
28 | void setGridLineVisible(bool visible); |
|
27 | void setGridLineVisible(bool visible); | |
29 | void setGridLinePen(const QPen& pen); |
|
28 | void setGridLinePen(const QPen& pen); | |
30 | QPen gridLinePen() const {return m_gridLinePen;} |
|
29 | QPen gridLinePen() const {return m_gridLinePen;} | |
31 |
|
30 | |||
32 | //labels handling |
|
31 | //labels handling | |
33 | bool labelsVisible() const { return m_labelsVisible;}; |
|
32 | bool labelsVisible() const { return m_labelsVisible;}; | |
34 | void setLabelsVisible(bool visible); |
|
33 | void setLabelsVisible(bool visible); | |
35 | void setLabelsPen(const QPen& pen); |
|
34 | void setLabelsPen(const QPen& pen); | |
36 | QPen labelsPen() const { return m_labelsPen;} |
|
35 | QPen labelsPen() const { return m_labelsPen;} | |
37 | void setLabelsBrush(const QBrush& brush); |
|
36 | void setLabelsBrush(const QBrush& brush); | |
38 | QBrush labelsBrush() const { return m_labelsBrush;} |
|
37 | QBrush labelsBrush() const { return m_labelsBrush;} | |
39 | void setLabelsFont(const QFont& font); |
|
38 | void setLabelsFont(const QFont& font); | |
40 | QFont labelsFont() const { return m_labelsFont;} |
|
39 | QFont labelsFont() const { return m_labelsFont;} | |
41 | void setLabelsAngle(int angle); |
|
40 | void setLabelsAngle(int angle); | |
42 | int labelsAngle() const { return m_labelsAngle;}; |
|
41 | int labelsAngle() const { return m_labelsAngle;}; | |
43 |
|
42 | |||
44 | //shades handling |
|
43 | //shades handling | |
45 | bool shadesVisible() const { return m_shadesVisible;}; |
|
44 | bool shadesVisible() const { return m_shadesVisible;}; | |
46 | void setShadesVisible(bool visible); |
|
45 | void setShadesVisible(bool visible); | |
47 | void setShadesPen(const QPen& pen); |
|
46 | void setShadesPen(const QPen& pen); | |
48 | QPen shadesPen() const { return m_shadesPen;} |
|
47 | QPen shadesPen() const { return m_shadesPen;} | |
49 | void setShadesBrush(const QBrush& brush); |
|
48 | void setShadesBrush(const QBrush& brush); | |
50 | QBrush shadesBrush() const { return m_shadesBrush;} |
|
49 | QBrush shadesBrush() const { return m_shadesBrush;} | |
51 | void setShadesOpacity(qreal opacity); |
|
50 | void setShadesOpacity(qreal opacity); | |
52 | qreal shadesOpacity() const { return m_shadesOpacity;} |
|
51 | qreal shadesOpacity() const { return m_shadesOpacity;} | |
53 |
|
52 | |||
54 | //range handling |
|
53 | //range handling | |
55 | void setMin(qreal min); |
|
54 | void setMin(qreal min); | |
56 | qreal min() const { return m_min;}; |
|
55 | qreal min() const { return m_min;}; | |
57 | void setMax(qreal max); |
|
56 | void setMax(qreal max); | |
58 | qreal max() const { return m_max;}; |
|
57 | qreal max() const { return m_max;}; | |
59 | void setRange(qreal min, qreal max); |
|
58 | void setRange(qreal min, qreal max); | |
60 |
|
59 | |||
61 | //ticks handling |
|
60 | //ticks handling | |
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 | |||
70 | void show(); |
|
69 | void show(); | |
71 | void hide(); |
|
70 | void hide(); | |
72 |
|
71 | |||
73 | signals: |
|
72 | signals: | |
74 | void minChanged(qreal min); |
|
73 | void minChanged(qreal min); | |
75 | void maxChanged(qreal max); |
|
74 | void maxChanged(qreal max); | |
76 | void rangeChanged(qreal min, qreal max); |
|
75 | void rangeChanged(qreal min, qreal max); | |
77 | void ticksCountChanged(int count); |
|
76 | void ticksCountChanged(int count); | |
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); | |
85 |
|
84 | |||
86 | private: |
|
85 | private: | |
87 | bool m_axisVisible; |
|
86 | bool m_axisVisible; | |
88 | QPen m_axisPen; |
|
87 | QPen m_axisPen; | |
89 | QBrush m_axisBrush; |
|
88 | QBrush m_axisBrush; | |
90 |
|
89 | |||
91 | bool m_gridLineVisible; |
|
90 | bool m_gridLineVisible; | |
92 | QPen m_gridLinePen; |
|
91 | QPen m_gridLinePen; | |
93 |
|
92 | |||
94 | bool m_labelsVisible; |
|
93 | bool m_labelsVisible; | |
95 | QPen m_labelsPen; |
|
94 | QPen m_labelsPen; | |
96 | QBrush m_labelsBrush; |
|
95 | QBrush m_labelsBrush; | |
97 | QFont m_labelsFont; |
|
96 | QFont m_labelsFont; | |
98 | int m_labelsAngle; |
|
97 | int m_labelsAngle; | |
99 |
|
98 | |||
100 | bool m_shadesVisible; |
|
99 | bool m_shadesVisible; | |
101 | QPen m_shadesPen; |
|
100 | QPen m_shadesPen; | |
102 | QBrush m_shadesBrush; |
|
101 | QBrush m_shadesBrush; | |
103 | qreal m_shadesOpacity; |
|
102 | qreal m_shadesOpacity; | |
104 |
|
103 | |||
105 | qreal m_min; |
|
104 | qreal m_min; | |
106 | qreal m_max; |
|
105 | qreal m_max; | |
107 |
|
106 | |||
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 | |
115 | #endif /* QCHARTAXIS_H_ */ |
|
114 | #endif /* QCHARTAXIS_H_ */ |
@@ -1,259 +1,257 | |||||
1 | #include "domain_p.h" |
|
1 | #include "domain_p.h" | |
2 | #include <cmath> |
|
2 | #include <cmath> | |
3 |
|
3 | |||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | Domain::Domain(QObject* parent):QObject(parent), |
|
6 | Domain::Domain(QObject* parent):QObject(parent), | |
7 | m_minX(0), |
|
7 | m_minX(0), | |
8 | m_maxX(0), |
|
8 | m_maxX(0), | |
9 | m_minY(0), |
|
9 | 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 | |||
17 | Domain::~Domain() |
|
17 | Domain::~Domain() | |
18 | { |
|
18 | { | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
21 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
22 | { |
|
22 | { | |
23 | setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount); |
|
23 | setRange(minX, maxX, minY, maxY,m_tickXCount,m_tickYCount); | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount) |
|
26 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY,int tickXCount,int tickYCount) | |
27 | { |
|
27 | { | |
28 | bool domainChanged = false; |
|
28 | bool domainChanged = false; | |
29 | bool tickXChanged = false; |
|
29 | bool tickXChanged = false; | |
30 | bool tickYChanged = false; |
|
30 | bool tickYChanged = false; | |
31 |
|
31 | |||
32 | if(m_tickXCount!=tickXCount) { |
|
32 | if(m_tickXCount!=tickXCount) { | |
33 | m_tickXCount=tickXCount; |
|
33 | m_tickXCount=tickXCount; | |
34 | tickXChanged=true; |
|
34 | tickXChanged=true; | |
35 | } |
|
35 | } | |
36 |
|
36 | |||
37 | if(m_tickXCount!=tickYCount) { |
|
37 | if(m_tickXCount!=tickYCount) { | |
38 | m_tickYCount=tickYCount; |
|
38 | m_tickYCount=tickYCount; | |
39 | tickYChanged=true; |
|
39 | tickYChanged=true; | |
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; | |
47 | tickXChanged=false; |
|
47 | tickXChanged=false; | |
48 | emit rangeXChanged(minX,maxX, m_tickXCount); |
|
48 | emit rangeXChanged(minX,maxX, m_tickXCount); | |
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; | |
56 | tickYChanged=false; |
|
56 | tickYChanged=false; | |
57 | emit rangeYChanged(minY,maxY, m_tickYCount); |
|
57 | emit rangeYChanged(minY,maxY, m_tickYCount); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | if(domainChanged) { |
|
60 | if(domainChanged) { | |
61 | emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY); |
|
61 | emit this->domainChanged(m_minX, m_maxX, m_minY, m_maxY); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | if(tickXChanged) { |
|
64 | if(tickXChanged) { | |
65 | emit rangeXChanged(minX,maxX, m_tickXCount); |
|
65 | emit rangeXChanged(minX,maxX, m_tickXCount); | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | if(tickYChanged) { |
|
68 | if(tickYChanged) { | |
69 | emit rangeYChanged(minY,maxY, m_tickYCount); |
|
69 | emit rangeYChanged(minY,maxY, m_tickYCount); | |
70 | } |
|
70 | } | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void Domain::setRangeX(qreal min, qreal max) |
|
73 | void Domain::setRangeX(qreal min, qreal max) | |
74 | { |
|
74 | { | |
75 | setRange(min,max,m_minY, m_maxY); |
|
75 | setRange(min,max,m_minY, m_maxY); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void Domain::setRangeX(qreal min, qreal max, int tickCount) |
|
78 | void Domain::setRangeX(qreal min, qreal max, int tickCount) | |
79 | { |
|
79 | { | |
80 | setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount); |
|
80 | setRange(min,max,m_minY, m_maxY,tickCount,m_tickYCount); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void Domain::setRangeY(qreal min, qreal max) |
|
83 | void Domain::setRangeY(qreal min, qreal max) | |
84 | { |
|
84 | { | |
85 | setRange(m_minX, m_maxX, min, max); |
|
85 | setRange(m_minX, m_maxX, min, max); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void Domain::setRangeY(qreal min, qreal max,int tickCount) |
|
88 | void Domain::setRangeY(qreal min, qreal max,int tickCount) | |
89 | { |
|
89 | { | |
90 | setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount); |
|
90 | setRange(m_minX, m_maxX, min, max,m_tickXCount,tickCount); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void Domain::setMinX(qreal min) |
|
93 | void Domain::setMinX(qreal min) | |
94 | { |
|
94 | { | |
95 | setRange(min, m_maxX, m_minY, m_maxY); |
|
95 | setRange(min, m_maxX, m_minY, m_maxY); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void Domain::setMaxX(qreal max) |
|
98 | void Domain::setMaxX(qreal max) | |
99 | { |
|
99 | { | |
100 | setRange(m_minX, max, m_minY, m_maxY); |
|
100 | setRange(m_minX, max, m_minY, m_maxY); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | void Domain::setMinY(qreal min) |
|
103 | void Domain::setMinY(qreal min) | |
104 | { |
|
104 | { | |
105 | setRange(m_minX, m_maxX, min, m_maxY); |
|
105 | setRange(m_minX, m_maxX, min, m_maxY); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | void Domain::setMaxY(qreal max) |
|
108 | void Domain::setMaxY(qreal max) | |
109 | { |
|
109 | { | |
110 | setRange(m_minX, m_maxX, m_minY, max); |
|
110 | setRange(m_minX, m_maxX, m_minY, max); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | qreal Domain::spanX() const |
|
113 | qreal Domain::spanX() const | |
114 | { |
|
114 | { | |
115 | Q_ASSERT(m_maxX >= m_minX); |
|
115 | Q_ASSERT(m_maxX >= m_minX); | |
116 | return m_maxX - m_minX; |
|
116 | return m_maxX - m_minX; | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | qreal Domain::spanY() const |
|
119 | qreal Domain::spanY() const | |
120 | { |
|
120 | { | |
121 | Q_ASSERT(m_maxY >= m_minY); |
|
121 | Q_ASSERT(m_maxY >= m_minY); | |
122 | return m_maxY - m_minY; |
|
122 | return m_maxY - m_minY; | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | bool Domain::isEmpty() const |
|
125 | bool Domain::isEmpty() const | |
126 | { |
|
126 | { | |
127 | return spanX()==0 || spanY()==0; |
|
127 | return spanX()==0 || spanY()==0; | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | void Domain::zoomIn(const QRectF& rect, const QSizeF& size) |
|
130 | void Domain::zoomIn(const QRectF& rect, const QSizeF& size) | |
131 | { |
|
131 | { | |
132 | qreal dx = spanX() / size.width(); |
|
132 | qreal dx = spanX() / size.width(); | |
133 | qreal dy = spanY() / size.height(); |
|
133 | qreal dy = spanY() / size.height(); | |
134 |
|
134 | |||
135 | m_maxX = m_minX + dx * rect.right(); |
|
135 | m_maxX = m_minX + dx * rect.right(); | |
136 | m_minX = m_minX + dx * rect.left(); |
|
136 | m_minX = m_minX + dx * rect.left(); | |
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); | |
145 | emit rangeYChanged(m_minY, m_maxY, m_tickYCount); |
|
147 | emit rangeYChanged(m_minY, m_maxY, m_tickYCount); | |
146 | } |
|
148 | } | |
147 |
|
149 | |||
148 | void Domain::zoomOut(const QRectF& rect, const QSizeF& size) |
|
150 | void Domain::zoomOut(const QRectF& rect, const QSizeF& size) | |
149 | { |
|
151 | { | |
150 | qreal dx = spanX() / rect.width(); |
|
152 | qreal dx = spanX() / rect.width(); | |
151 | qreal dy = spanY() / rect.height(); |
|
153 | qreal dy = spanY() / rect.height(); | |
152 |
|
154 | |||
153 | m_minX = m_maxX - dx * rect.right(); |
|
155 | m_minX = m_maxX - dx * rect.right(); | |
154 | m_maxX = m_minX + dx * size.width(); |
|
156 | m_maxX = m_minX + dx * size.width(); | |
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); | |
163 | emit rangeYChanged(m_minY, m_maxY, m_tickYCount); |
|
167 | emit rangeYChanged(m_minY, m_maxY, m_tickYCount); | |
164 | } |
|
168 | } | |
165 |
|
169 | |||
166 | void Domain::move(int dx,int dy,const QSizeF& size) |
|
170 | void Domain::move(int dx,int dy,const QSizeF& size) | |
167 | { |
|
171 | { | |
168 | qreal x = spanX() / size.width(); |
|
172 | qreal x = spanX() / size.width(); | |
169 | qreal y = spanY() / size.height(); |
|
173 | qreal y = spanY() / size.height(); | |
170 |
|
174 | |||
171 | if(dx!=0) { |
|
175 | if(dx!=0) { | |
172 | m_minX = m_minX + x * dx; |
|
176 | m_minX = m_minX + x * dx; | |
173 | m_maxX = m_maxX + x * dx; |
|
177 | m_maxX = m_maxX + x * dx; | |
174 | emit rangeXChanged(m_minX, m_maxX, m_tickXCount); |
|
178 | emit rangeXChanged(m_minX, m_maxX, m_tickXCount); | |
175 | } |
|
179 | } | |
176 | if(dy!=0) { |
|
180 | if(dy!=0) { | |
177 | m_minY = m_minY + y * dy; |
|
181 | m_minY = m_minY + y * dy; | |
178 | m_maxY = m_maxY + y * dy; |
|
182 | m_maxY = m_maxY + y * dy; | |
179 | emit rangeYChanged(m_minY, m_maxY, m_tickYCount); |
|
183 | emit rangeYChanged(m_minY, m_maxY, m_tickYCount); | |
180 | } |
|
184 | } | |
181 |
|
185 | |||
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 | |
208 | qreal step = niceNumber(range/(ticksCount-1),false); |
|
206 | qreal step = niceNumber(range/(ticksCount-1),false); | |
209 | min = floor(min/step); |
|
207 | min = floor(min/step); | |
210 | max = ceil(max/step); |
|
208 | max = ceil(max/step); | |
211 | ticksCount = int(max-min) +1; |
|
209 | ticksCount = int(max-min) +1; | |
212 | min*=step; |
|
210 | min*=step; | |
213 | max*=step; |
|
211 | max*=step; | |
214 | } |
|
212 | } | |
215 |
|
213 | |||
216 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n |
|
214 | //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n | |
217 |
|
215 | |||
218 | qreal Domain::niceNumber(qreal x,bool ceiling) |
|
216 | qreal Domain::niceNumber(qreal x,bool ceiling) | |
219 | { |
|
217 | { | |
220 | qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x |
|
218 | qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x | |
221 | qreal q = x/z;//q<10 && q>=1; |
|
219 | qreal q = x/z;//q<10 && q>=1; | |
222 |
|
220 | |||
223 | if(ceiling) { |
|
221 | if(ceiling) { | |
224 | if(q <= 1.0) q=1; |
|
222 | if(q <= 1.0) q=1; | |
225 | else if(q <= 2.0) q=2; |
|
223 | else if(q <= 2.0) q=2; | |
226 | else if(q <= 5.0) q=5; |
|
224 | else if(q <= 5.0) q=5; | |
227 | else q=10; |
|
225 | else q=10; | |
228 | } |
|
226 | } | |
229 | else { |
|
227 | else { | |
230 | if(q < 1.5) q=1; |
|
228 | if(q < 1.5) q=1; | |
231 | else if(q < 3.0) q=2; |
|
229 | else if(q < 3.0) q=2; | |
232 | else if(q < 7.0) q=5; |
|
230 | else if(q < 7.0) q=5; | |
233 | else q=10; |
|
231 | else q=10; | |
234 | } |
|
232 | } | |
235 | return q*z; |
|
233 | return q*z; | |
236 | } |
|
234 | } | |
237 |
|
235 | |||
238 | bool operator== (const Domain &domain1, const Domain &domain2) |
|
236 | bool operator== (const Domain &domain1, const Domain &domain2) | |
239 | { |
|
237 | { | |
240 | return (domain1.m_maxX == domain2.m_maxX && |
|
238 | return (domain1.m_maxX == domain2.m_maxX && | |
241 | domain1.m_maxY == domain2.m_maxY && |
|
239 | domain1.m_maxY == domain2.m_maxY && | |
242 | domain1.m_minX == domain2.m_minX && |
|
240 | domain1.m_minX == domain2.m_minX && | |
243 | domain1.m_minY == domain2.m_minY); |
|
241 | domain1.m_minY == domain2.m_minY); | |
244 | } |
|
242 | } | |
245 |
|
243 | |||
246 | bool operator!= (const Domain &domain1, const Domain &domain2) |
|
244 | bool operator!= (const Domain &domain1, const Domain &domain2) | |
247 | { |
|
245 | { | |
248 | return !(domain1 == domain2); |
|
246 | return !(domain1 == domain2); | |
249 | } |
|
247 | } | |
250 |
|
248 | |||
251 | QDebug operator<<(QDebug dbg, const Domain &domain) |
|
249 | QDebug operator<<(QDebug dbg, const Domain &domain) | |
252 | { |
|
250 | { | |
253 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ; |
|
251 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')' << domain.m_tickXCount << "," << domain.m_tickYCount ; | |
254 | return dbg.maybeSpace(); |
|
252 | return dbg.maybeSpace(); | |
255 | } |
|
253 | } | |
256 |
|
254 | |||
257 | #include "moc_domain_p.cpp" |
|
255 | #include "moc_domain_p.cpp" | |
258 |
|
256 | |||
259 | QTCOMMERCIALCHART_END_NAMESPACE |
|
257 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,73 +1,71 | |||||
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 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
8 | |||
10 | class Domain: public QObject { |
|
9 | class Domain: public QObject { | |
11 | Q_OBJECT |
|
10 | Q_OBJECT | |
12 | public: |
|
11 | public: | |
13 | explicit Domain(QObject* object=0); |
|
12 | explicit Domain(QObject* object=0); | |
14 | virtual ~Domain(); |
|
13 | virtual ~Domain(); | |
15 |
|
14 | |||
16 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
15 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
17 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount); |
|
16 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY, int tickXCount, int tickYCount); | |
18 | void setRangeX(qreal min, qreal max); |
|
17 | void setRangeX(qreal min, qreal max); | |
19 | void setRangeX(qreal min, qreal max, int tickCount); |
|
18 | void setRangeX(qreal min, qreal max, int tickCount); | |
20 | void setRangeY(qreal min, qreal max); |
|
19 | void setRangeY(qreal min, qreal max); | |
21 | void setRangeY(qreal min, qreal max, int tickCount); |
|
20 | void setRangeY(qreal min, qreal max, int tickCount); | |
22 | void setMinX(qreal min); |
|
21 | void setMinX(qreal min); | |
23 | void setMaxX(qreal max); |
|
22 | void setMaxX(qreal max); | |
24 | void setMinY(qreal min); |
|
23 | void setMinY(qreal min); | |
25 | void setMaxY(qreal max); |
|
24 | void setMaxY(qreal max); | |
26 |
|
25 | |||
27 | qreal minX() const {return m_minX;}; |
|
26 | qreal minX() const {return m_minX;}; | |
28 | qreal maxX() const {return m_maxX;}; |
|
27 | qreal maxX() const {return m_maxX;}; | |
29 | qreal minY() const {return m_minY;}; |
|
28 | qreal minY() const {return m_minY;}; | |
30 | qreal maxY() const {return m_maxY;}; |
|
29 | qreal maxY() const {return m_maxY;}; | |
31 |
|
30 | |||
32 | qreal spanX() const; |
|
31 | qreal spanX() const; | |
33 | qreal spanY() const; |
|
32 | qreal spanY() const; | |
34 | bool isEmpty() const; |
|
33 | bool isEmpty() const; | |
35 |
|
34 | |||
36 | int tickXCount() const {return m_tickXCount;} |
|
35 | int tickXCount() const {return m_tickXCount;} | |
37 | int tickYCount() const {return m_tickYCount;} |
|
36 | int tickYCount() const {return m_tickYCount;} | |
38 |
|
37 | |||
39 | friend bool operator== (const Domain &domain1, const Domain &domain2); |
|
38 | friend bool operator== (const Domain &domain1, const Domain &domain2); | |
40 | friend bool operator!= (const Domain &domain1, const Domain &domain2); |
|
39 | friend bool operator!= (const Domain &domain1, const Domain &domain2); | |
41 | friend QDebug operator<<(QDebug dbg, const Domain &domain); |
|
40 | friend QDebug operator<<(QDebug dbg, const Domain &domain); | |
42 |
|
41 | |||
43 | void zoomIn(const QRectF& rect, const QSizeF& size); |
|
42 | void zoomIn(const QRectF& rect, const QSizeF& size); | |
44 | void zoomOut(const QRectF& rect, const QSizeF& size); |
|
43 | void zoomOut(const QRectF& rect, const QSizeF& size); | |
45 | void move(int dx,int dy,const QSizeF& size); |
|
44 | void move(int dx,int dy,const QSizeF& size); | |
46 |
|
45 | |||
47 | signals: |
|
46 | signals: | |
48 | void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
47 | void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
49 | void rangeXChanged(qreal min, qreal max, int tickXCount); |
|
48 | void rangeXChanged(qreal min, qreal max, int tickXCount); | |
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 | |||
61 | private: |
|
59 | private: | |
62 | qreal m_minX; |
|
60 | qreal m_minX; | |
63 | qreal m_maxX; |
|
61 | qreal m_maxX; | |
64 | qreal m_minY; |
|
62 | qreal m_minY; | |
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 | |
72 |
|
70 | |||
73 | #endif |
|
71 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now