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