##// END OF EJS Templates
abstract axis qml documentation. bug fix to setArrowVisible
sauimone -
r1654:746d930ea165
parent child
Show More
@@ -1,391 +1,391
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "chartaxis_p.h"
22 22 #include "qabstractaxis.h"
23 23 #include "qabstractaxis_p.h"
24 24 #include "chartpresenter_p.h"
25 25 #include "chartanimator_p.h"
26 26 #include <QPainter>
27 27 #include <QDebug>
28 28 #include <qmath.h>
29 29
30 30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 31
32 32 ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter),
33 33 m_chartAxis(axis),
34 34 m_labelsAngle(0),
35 35 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
36 36 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
37 37 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
38 38 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
39 39 m_min(0),
40 40 m_max(0),
41 41 m_ticksCount(0),
42 42 m_animation(0),
43 43 m_minWidth(0),
44 44 m_minHeight(0)
45 45 {
46 46 //initial initialization
47 47 m_axis->setZValue(ChartPresenter::AxisZValue);
48 48 m_axis->setHandlesChildEvents(false);
49 49
50 50 m_shades->setZValue(ChartPresenter::ShadesZValue);
51 51 m_grid->setZValue(ChartPresenter::GridZValue);
52 52
53 53 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
54 54
55 55 QGraphicsSimpleTextItem item;
56 56 m_font = item.font();
57 57
58 58 handleAxisUpdated();
59 59 }
60 60
61 61 ChartAxis::~ChartAxis()
62 62 {
63 63 }
64 64
65 65 void ChartAxis::setAnimation(AxisAnimation* animation)
66 66 {
67 67 m_animation=animation;
68 68 }
69 69
70 70 void ChartAxis::setLayout(QVector<qreal> &layout)
71 71 {
72 72 m_layoutVector=layout;
73 73 }
74 74
75 75 void ChartAxis::createItems(int count)
76 76 {
77 77 if (m_axis->children().size() == 0)
78 78 m_axis->addToGroup(new AxisItem(this));
79 79 for (int i = 0; i < count; ++i) {
80 80 m_grid->addToGroup(new QGraphicsLineItem());
81 81 m_labels->addToGroup(new QGraphicsSimpleTextItem());
82 82 m_axis->addToGroup(new QGraphicsLineItem());
83 83 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
84 84 }
85 85 }
86 86
87 87 void ChartAxis::deleteItems(int count)
88 88 {
89 89 QList<QGraphicsItem *> lines = m_grid->childItems();
90 90 QList<QGraphicsItem *> labels = m_labels->childItems();
91 91 QList<QGraphicsItem *> shades = m_shades->childItems();
92 92 QList<QGraphicsItem *> axis = m_axis->childItems();
93 93
94 94 for (int i = 0; i < count; ++i) {
95 95 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
96 96 delete(lines.takeLast());
97 97 delete(labels.takeLast());
98 98 delete(axis.takeLast());
99 99 }
100 100 }
101 101
102 102 void ChartAxis::updateLayout(QVector<qreal> &layout)
103 103 {
104 104 int diff = m_layoutVector.size() - layout.size();
105 105
106 106 if (diff>0) {
107 107 deleteItems(diff);
108 108 }
109 109 else if (diff<0) {
110 110 createItems(-diff);
111 111 }
112 112
113 113 if( diff!=0) handleAxisUpdated();
114 114
115 115 if (m_animation) {
116 116 switch(presenter()->state()){
117 117 case ChartPresenter::ZoomInState:
118 118 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
119 119 m_animation->setAnimationPoint(presenter()->statePoint());
120 120 break;
121 121 case ChartPresenter::ZoomOutState:
122 122 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
123 123 m_animation->setAnimationPoint(presenter()->statePoint());
124 124 break;
125 125 case ChartPresenter::ScrollUpState:
126 126 case ChartPresenter::ScrollLeftState:
127 127 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
128 128 break;
129 129 case ChartPresenter::ScrollDownState:
130 130 case ChartPresenter::ScrollRightState:
131 131 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
132 132 break;
133 133 case ChartPresenter::ShowState:
134 134 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
135 135 break;
136 136 }
137 137 m_animation->setValues(m_layoutVector,layout);
138 138 presenter()->startAnimation(m_animation);
139 139 }
140 140 else {
141 141 setLayout(layout);
142 142 updateGeometry();
143 143 }
144 144 }
145 145
146 146 void ChartAxis::setAxisOpacity(qreal opacity)
147 147 {
148 148 m_axis->setOpacity(opacity);
149 149 }
150 150
151 151 qreal ChartAxis::axisOpacity() const
152 152 {
153 153 return m_axis->opacity();
154 154 }
155 155
156 156 void ChartAxis::setGridOpacity(qreal opacity)
157 157 {
158 158 m_grid->setOpacity(opacity);
159 159 }
160 160
161 161 qreal ChartAxis::gridOpacity() const
162 162 {
163 163 return m_grid->opacity();
164 164 }
165 165
166 166 void ChartAxis::setLabelsOpacity(qreal opacity)
167 167 {
168 168 m_labels->setOpacity(opacity);
169 169 }
170 170
171 171 qreal ChartAxis::labelsOpacity() const
172 172 {
173 173 return m_labels->opacity();
174 174 }
175 175
176 176 void ChartAxis::setShadesOpacity(qreal opacity)
177 177 {
178 178 m_shades->setOpacity(opacity);
179 179 }
180 180
181 181 qreal ChartAxis::shadesOpacity() const
182 182 {
183 183 return m_shades->opacity();
184 184 }
185 185
186 186 void ChartAxis::setLabelsAngle(int angle)
187 187 {
188 188 foreach(QGraphicsItem* item , m_labels->childItems()) {
189 189 item->setRotation(angle);
190 190 }
191 191
192 192 m_labelsAngle=angle;
193 193 }
194 194
195 195 void ChartAxis::setLabelsPen(const QPen &pen)
196 196 {
197 197 foreach(QGraphicsItem* item , m_labels->childItems()) {
198 198 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
199 199 }
200 200 }
201 201
202 202 void ChartAxis::setLabelsBrush(const QBrush &brush)
203 203 {
204 204 foreach(QGraphicsItem* item , m_labels->childItems()) {
205 205 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
206 206 }
207 207 }
208 208
209 209 void ChartAxis::setLabelsFont(const QFont &font)
210 210 {
211 211 foreach(QGraphicsItem* item , m_labels->childItems()) {
212 212 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
213 213 }
214 214 m_font = font;
215 215 }
216 216
217 217 void ChartAxis::setShadesBrush(const QBrush &brush)
218 218 {
219 219 foreach(QGraphicsItem* item , m_shades->childItems()) {
220 220 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
221 221 }
222 222 }
223 223
224 224 void ChartAxis::setShadesPen(const QPen &pen)
225 225 {
226 226 foreach(QGraphicsItem* item , m_shades->childItems()) {
227 227 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
228 228 }
229 229 }
230 230
231 231 void ChartAxis::setAxisPen(const QPen &pen)
232 232 {
233 233 foreach(QGraphicsItem* item , m_axis->childItems()) {
234 234 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
235 235 }
236 236 }
237 237
238 238 void ChartAxis::setGridPen(const QPen &pen)
239 239 {
240 240 foreach(QGraphicsItem* item , m_grid->childItems()) {
241 241 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
242 242 }
243 243 }
244 244
245 245 bool ChartAxis::isEmpty()
246 246 {
247 247 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0;
248 248 }
249 249
250 250 //handlers
251 251
252 252 void ChartAxis::handleAxisCategoriesUpdated()
253 253 {
254 254 if (isEmpty()) return;
255 255 updateLayout(m_layoutVector);
256 256 }
257 257
258 258 void ChartAxis::handleAxisUpdated()
259 259 {
260 260
261 261 if (isEmpty()) return;
262 262
263 263 if (!m_chartAxis->isVisible()) {
264 264 setAxisOpacity(0);
265 265 setGridOpacity(0);
266 266 setLabelsOpacity(0);
267 267 setShadesOpacity(0);
268 268 }
269 269 else {
270 270
271 if (m_chartAxis->isAxisVisible()) {
271 if (m_chartAxis->isArrowVisible()) {
272 272 setAxisOpacity(100);
273 273 }
274 274 else {
275 275 setAxisOpacity(0);
276 276 }
277 277
278 278 if (m_chartAxis->isGridLineVisible()) {
279 279 setGridOpacity(100);
280 280 }
281 281 else {
282 282 setGridOpacity(0);
283 283 }
284 284
285 285 if (m_chartAxis->labelsVisible()) {
286 286 setLabelsOpacity(100);
287 287 }
288 288 else {
289 289 setLabelsOpacity(0);
290 290 }
291 291
292 292 if (m_chartAxis->shadesVisible()) {
293 293 setShadesOpacity(100);
294 294 }
295 295 else {
296 296 setShadesOpacity(0);
297 297 }
298 298 }
299 299 setLabelsAngle(m_chartAxis->labelsAngle());
300 300 setAxisPen(m_chartAxis->axisPen());
301 301 setLabelsPen(m_chartAxis->labelsPen());
302 302 setLabelsBrush(m_chartAxis->labelsBrush());
303 303 setLabelsFont(m_chartAxis->labelsFont());
304 304 setGridPen(m_chartAxis->gridLinePen());
305 305 setShadesPen(m_chartAxis->shadesPen());
306 306 setShadesBrush(m_chartAxis->shadesBrush());
307 307
308 308 }
309 309
310 310 void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount)
311 311 {
312 312 if (qFuzzyIsNull(min - max) || tickCount < 2)
313 313 return;
314 314
315 315 m_min = min;
316 316 m_max = max;
317 317 m_ticksCount= tickCount;
318 318
319 319 if (isEmpty()) return;
320 320 QVector<qreal> layout = calculateLayout();
321 321 updateLayout(layout);
322 322 }
323 323
324 324 void ChartAxis::handleGeometryChanged(const QRectF &rect)
325 325 {
326 326 if(m_rect != rect)
327 327 {
328 328 m_rect = rect;
329 329 if (isEmpty()) return;
330 330 QVector<qreal> layout = calculateLayout();
331 331 updateLayout(layout);
332 332 }
333 333 }
334 334
335 335
336 336 qreal ChartAxis::minimumWidth()
337 337 {
338 338 if(m_minWidth == 0) updateGeometry();
339 339 return m_minWidth;
340 340 }
341 341
342 342 qreal ChartAxis::minimumHeight()
343 343 {
344 344 if(m_minHeight == 0) updateGeometry();
345 345 return m_minHeight;
346 346 }
347 347
348 348
349 349 void ChartAxis::axisSelected()
350 350 {
351 351 qDebug()<<"TODO: axis clicked";
352 352 }
353 353
354 354
355 355 void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const
356 356 {
357 357 Q_ASSERT(max>min);
358 358 Q_ASSERT(ticks>1);
359 359
360 360 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
361 361 n++;
362 362 for (int i=0; i< ticks; i++) {
363 363 qreal value = min + (i * (max - min)/ (ticks-1));
364 364 labels << QString::number(value,'f',n);
365 365 }
366 366 }
367 367
368 368 void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const
369 369 {
370 370 Q_ASSERT(max>min);
371 371 Q_UNUSED(max);
372 372
373 373 int x = qCeil(min);
374 374 int count = 0;
375 375
376 376 // Try to find category for x coordinate
377 377 while (count < m_ticksCount) {
378 378 if ((x < categories.count()) && (x >= 0)) {
379 379 labels << categories.at(x);
380 380 } else {
381 381 // No label for x coordinate
382 382 labels << "";
383 383 }
384 384 x++;
385 385 count++;
386 386 }
387 387 }
388 388
389 389 #include "moc_chartaxis_p.cpp"
390 390
391 391 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,606 +1,627
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qabstractaxis.h"
22 22 #include "qabstractaxis_p.h"
23 23
24 24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 25
26 26 /*!
27 27 \class QAbstractAxis
28 28 \brief The QAbstractAxis class is used for manipulating chart's axis.
29 29 \mainclass
30 30
31 31 There is only one x Axis visible at the time, however there can be multiple y axes.
32 32 Each chart series can be bound to exactly one Y axis and the shared common X axis.
33 33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 34 */
35 35
36 36 /*!
37 37 \qmlclass AbstractAxis QAbstractAxis
38 38 \brief The Axis element is used for manipulating chart's axes
39 39
40 40 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
41 41 Each chart series can be bound to exactly one Y axis and the shared common X axis.
42 42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 ChartView {
47 47 axisX.min: 0
48 48 axisX.max: 3
49 49 axisX.ticksCount: 4
50 50 axisY.min: 0
51 51 axisY.max: 4
52 52 // Add a few series...
53 53 }
54 54 \endcode
55 55 */
56 56
57 57 /*!
58 58 \enum QAbstractAxis::AxisType
59 59
60 60 The type of the series object.
61 61
62 62 \value AxisTypeNoAxis
63 63 \value AxisTypeValues
64 64 \value AxisTypeCategories
65 65 */
66 66
67 67 /*!
68 68 *\fn void QAbstractAxis::type() const
69 69 Returns the type of the axis
70 70 */
71 71
72 72 /*!
73 73 \property QAbstractAxis::arrowVisible
74 74 The visibility of the axis arrow
75 75 */
76 76 /*!
77 77 \qmlproperty bool AbstractAxis::arrrowVisible
78 78 The visibility of the axis arrow
79 79 */
80 80
81 81 /*!
82 82 \property QAbstractAxis::labelsVisible
83 83 Defines if axis labels are visible.
84 84 */
85 85 /*!
86 86 \qmlproperty bool AbstractAxis::labelsVisible
87 87 Defines if axis labels are visible.
88 88 */
89 89
90 90 /*!
91 91 \property QAbstractAxis::visible
92 92 The visibility of the axis.
93 93 */
94 94 /*!
95 95 \qmlproperty bool AbstractAxis::visible
96 96 The visibility of the axis.
97 97 */
98 98
99 99 /*!
100 100 \property QAbstractAxis::gridVisible
101 101 The visibility of the grid lines.
102 102 */
103 103 /*!
104 104 \qmlproperty bool AbstractAxis::gridVisible
105 105 The visibility of the grid lines.
106 106 */
107 107
108 108 /*!
109 109 \property QAbstractAxis::color
110 110 The color of the axis and ticks.
111 111 */
112 112 /*!
113 113 \qmlproperty color AbstractAxis::color
114 114 The color of the axis and ticks.
115 115 */
116 116
117 117 /*!
118 118 \property QAbstractAxis::labelsFont
119 119 The font of the axis labels.
120 120 */
121 121
122 122 /*!
123 123 \qmlproperty Font AbstractAxis::labelsFont
124 124 The font of the axis labels.
125 125
126 126 See the \l {Font} {QML Font Element} for detailed documentation.
127 127 */
128 128
129 129 /*!
130 130 \property QAbstractAxis::labelsColor
131 131 The color of the axis labels.
132 132 */
133 133 /*!
134 134 \qmlproperty color AbstractAxis::labelsColor
135 135 The color of the axis labels.
136 136 */
137 137
138 138 /*!
139 139 \property QAbstractAxis::labelsAngle
140 140 The angle of the axis labels in degrees.
141 141 */
142 142 /*!
143 143 \qmlproperty int AbstractAxis::labelsAngle
144 144 The angle of the axis labels in degrees.
145 145 */
146 146
147 147 /*!
148 148 \property QAbstractAxis::shadesVisible
149 149 The visibility of the axis shades.
150 150 */
151 151 /*!
152 152 \qmlproperty bool AbstractAxis::shadesVisible
153 153 The visibility of the axis shades.
154 154 */
155 155
156 156 /*!
157 157 \property QAbstractAxis::shadesColor
158 158 The fill (brush) color of the axis shades.
159 159 */
160 160 /*!
161 161 \qmlproperty color AbstractAxis::shadesColor
162 162 The fill (brush) color of the axis shades.
163 163 */
164 164
165 165 /*!
166 166 \property QAbstractAxis::shadesBorderColor
167 167 The border (pen) color of the axis shades.
168 168 */
169 169 /*!
170 170 \qmlproperty color AbstractAxis::shadesBorderColor
171 171 The border (pen) color of the axis shades.
172 172 */
173 173
174 174 /*!
175 \fn void QAbstractAxis::visibleChanged(bool)
175 \fn void QAbstractAxis::visibleChanged(bool visible)
176 176 Visiblity of the axis has changed to \a visible.
177 177 */
178
179 178 /*!
180 \fn void QAbstractAxis::labelsVisibleChanged(bool)
181 Visiblity of the labels of the axis has changed to \a visible.
179 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
180 Visiblity of the axis has changed to \a visible.
182 181 */
183 182
184 183 /*!
185 \fn void QAbstractAxis::gridVisibleChanged(bool)
186 Visiblity of the grid lines of the axis has changed to \a visible.
184 \fn void QAbstractAxis::arrowVisibleChanged(bool visible)
185 Visiblity of the axis arrow has changed to \a visible.
187 186 */
188
189 /*
190 \fn void QAbstractAxis::minChanged(qreal min)
191 Axis emits signal when \a min of axis has changed.
187 /*!
188 \qmlsignal AbstractAxis::onArrowVisibleChanged(bool visible)
189 Visiblity of the axis arrow has changed to \a visible.
192 190 */
193 191
194 /*
195 \fn void QAbstractAxis::maxChanged(qreal max)
196 Axis emits signal when \a max of axis has changed.
192 /*!
193 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
194 Visiblity of the labels of the axis has changed to \a visible.
197 195 */
198
199 /*
200 \fn void QAbstractAxis::rangeChanged(qreal min, qreal max)
201 Axis emits signal when \a min or \a max of axis has changed.
196 /*!
197 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
198 Visiblity of the labels of the axis has changed to \a visible.
202 199 */
203 200
204 /*
205 \fn QChartAxisCategories* QAbstractAxis::categories()
206 Returns pointer to the list of categories which correspond to the values on the axis.
201 /*!
202 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
203 Visiblity of the grid lines of the axis has changed to \a visible.
204 */
205 /*!
206 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
207 Visiblity of the grid lines of the axis has changed to \a visible.
207 208 */
208 209
209 210 /*!
210 \fn void QAbstractAxis::colorChanged(QColor)
211 \fn void QAbstractAxis::colorChanged(QColor color)
212 Emitted if the \a color of the axis is changed.
213 */
214 /*!
215 \qmlsignal AbstractAxis::onColorChanged(QColor color)
211 216 Emitted if the \a color of the axis is changed.
212 217 */
213 218
214 219 /*!
215 \fn void QAbstractAxis::labelsColorChanged(QColor)
220 \fn void QAbstractAxis::labelsColorChanged(QColor color)
221 Emitted if the \a color of the axis labels is changed.
222 */
223 /*!
224 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
216 225 Emitted if the \a color of the axis labels is changed.
217 226 */
218 227
219 228 /*!
220 229 \fn void QAbstractAxis::shadesVisibleChanged(bool)
221 230 Emitted if the visibility of the axis shades is changed to \a visible.
222 231 */
232 /*!
233 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
234 Emitted if the visibility of the axis shades is changed to \a visible.
235 */
223 236
224 237 /*!
225 \fn void QAbstractAxis::shadesColorChanged(QColor)
238 \fn void QAbstractAxis::shadesColorChanged(QColor color)
239 Emitted if the \a color of the axis shades is changed.
240 */
241 /*!
242 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
226 243 Emitted if the \a color of the axis shades is changed.
227 244 */
228 245
229 246 /*!
230 247 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
231 248 Emitted if the border \a color of the axis shades is changed.
232 249 */
250 /*!
251 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
252 Emitted if the border \a color of the axis shades is changed.
253 */
233 254
234 255 /*!
235 256 Constructs new axis object which is a child of \a parent. Ownership is taken by
236 257 QChart when axis added.
237 258 */
238 259
239 260 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) :
240 261 QObject(parent),
241 262 d_ptr(&d)
242 263 {
243 264 }
244 265
245 266 /*!
246 267 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
247 268 */
248 269
249 270 QAbstractAxis::~QAbstractAxis()
250 271 {
251 272 }
252 273
253 274 /*!
254 275 Sets \a pen used to draw axis line and ticks.
255 276 */
256 277 void QAbstractAxis::setAxisPen(const QPen &pen)
257 278 {
258 279 if (d_ptr->m_axisPen!=pen) {
259 280 d_ptr->m_axisPen = pen;
260 281 emit d_ptr->updated();
261 282 }
262 283 }
263 284
264 285 /*!
265 286 Returns pen used to draw axis and ticks.
266 287 */
267 288 QPen QAbstractAxis::axisPen() const
268 289 {
269 290 return d_ptr->m_axisPen;
270 291 }
271 292
272 293 void QAbstractAxis::setAxisPenColor(QColor color)
273 294 {
274 295 QPen p = d_ptr->m_axisPen;
275 296 if (p.color() != color) {
276 297 p.setColor(color);
277 298 setAxisPen(p);
278 299 emit colorChanged(color);
279 300 }
280 301 }
281 302
282 303 QColor QAbstractAxis::axisPenColor() const
283 304 {
284 305 return d_ptr->m_axisPen.color();
285 306 }
286 307
287 308 /*!
288 309 Sets if axis and ticks are \a visible.
289 310 */
290 void QAbstractAxis::setAxisVisible(bool visible)
311 void QAbstractAxis::setArrowVisible(bool visible)
291 312 {
292 if (d_ptr->m_axisVisible != visible) {
293 d_ptr->m_axisVisible = visible;
313 if (d_ptr->m_arrowVisible != visible) {
314 d_ptr->m_arrowVisible = visible;
294 315 emit d_ptr->updated();
295 emit visibleChanged(visible);
316 emit arrowVisibleChanged(visible);
296 317 }
297 318 }
298 319
299 bool QAbstractAxis::isAxisVisible() const
320 bool QAbstractAxis::isArrowVisible() const
300 321 {
301 return d_ptr->m_axisVisible;
322 return d_ptr->m_arrowVisible;
302 323 }
303 324
304 325 void QAbstractAxis::setGridLineVisible(bool visible)
305 326 {
306 327 if (d_ptr->m_gridLineVisible != visible) {
307 328 d_ptr->m_gridLineVisible = visible;
308 329 emit d_ptr->updated();
309 330 emit gridVisibleChanged(visible);
310 331 }
311 332 }
312 333
313 334 bool QAbstractAxis::isGridLineVisible() const
314 335 {
315 336 return d_ptr->m_gridLineVisible;
316 337 }
317 338
318 339 /*!
319 340 Sets \a pen used to draw grid line.
320 341 */
321 342 void QAbstractAxis::setGridLinePen(const QPen &pen)
322 343 {
323 344 if (d_ptr->m_gridLinePen != pen) {
324 345 d_ptr->m_gridLinePen = pen;
325 346 emit d_ptr->updated();
326 347 }
327 348 }
328 349
329 350 /*!
330 351 Returns pen used to draw grid.
331 352 */
332 353 QPen QAbstractAxis::gridLinePen() const
333 354 {
334 355 return d_ptr->m_gridLinePen;
335 356 }
336 357
337 358 void QAbstractAxis::setLabelsVisible(bool visible)
338 359 {
339 360 if (d_ptr->m_labelsVisible != visible) {
340 361 d_ptr->m_labelsVisible = visible;
341 362 emit d_ptr->updated();
342 363 emit labelsVisibleChanged(visible);
343 364 }
344 365 }
345 366
346 367 bool QAbstractAxis::labelsVisible() const
347 368 {
348 369 return d_ptr->m_labelsVisible;
349 370 }
350 371
351 372 /*!
352 373 Sets \a pen used to draw labels.
353 374 */
354 375 void QAbstractAxis::setLabelsPen(const QPen &pen)
355 376 {
356 377 if (d_ptr->m_labelsPen != pen) {
357 378 d_ptr->m_labelsPen = pen;
358 379 emit d_ptr->updated();
359 380 }
360 381 }
361 382
362 383 /*!
363 384 Returns the pen used to labels.
364 385 */
365 386 QPen QAbstractAxis::labelsPen() const
366 387 {
367 388 return d_ptr->m_labelsPen;
368 389 }
369 390
370 391 /*!
371 392 Sets \a brush used to draw labels.
372 393 */
373 394 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
374 395 {
375 396 if (d_ptr->m_labelsBrush != brush) {
376 397 d_ptr->m_labelsBrush = brush;
377 398 emit d_ptr->updated();
378 399 }
379 400 }
380 401
381 402 /*!
382 403 Returns brush used to draw labels.
383 404 */
384 405 QBrush QAbstractAxis::labelsBrush() const
385 406 {
386 407 return d_ptr->m_labelsBrush;
387 408 }
388 409
389 410 /*!
390 411 Sets \a font used to draw labels.
391 412 */
392 413 void QAbstractAxis::setLabelsFont(const QFont &font)
393 414 {
394 415 if (d_ptr->m_labelsFont != font) {
395 416 d_ptr->m_labelsFont = font;
396 417 emit d_ptr->updated();
397 418 }
398 419 }
399 420
400 421 /*!
401 422 Returns font used to draw labels.
402 423 */
403 424 QFont QAbstractAxis::labelsFont() const
404 425 {
405 426 return d_ptr->m_labelsFont;
406 427 }
407 428
408 429 void QAbstractAxis::setLabelsAngle(int angle)
409 430 {
410 431 if (d_ptr->m_labelsAngle != angle) {
411 432 d_ptr->m_labelsAngle = angle;
412 433 emit d_ptr->updated();
413 434 }
414 435 }
415 436
416 437 int QAbstractAxis::labelsAngle() const
417 438 {
418 439 return d_ptr->m_labelsAngle;
419 440 }
420 441
421 442 void QAbstractAxis::setLabelsColor(QColor color)
422 443 {
423 444 QBrush b = d_ptr->m_labelsBrush;
424 445 if (b.color() != color) {
425 446 b.setColor(color);
426 447 setLabelsBrush(b);
427 448 emit labelsColorChanged(color);
428 449 }
429 450 }
430 451
431 452 QColor QAbstractAxis::labelsColor() const
432 453 {
433 454 return d_ptr->m_labelsBrush.color();
434 455 }
435 456
436 457 void QAbstractAxis::setShadesVisible(bool visible)
437 458 {
438 459 if (d_ptr->m_shadesVisible != visible) {
439 460 d_ptr->m_shadesVisible = visible;
440 461 emit d_ptr->updated();
441 462 emit shadesVisibleChanged(visible);
442 463 }
443 464 }
444 465
445 466 bool QAbstractAxis::shadesVisible() const
446 467 {
447 468 return d_ptr->m_shadesVisible;
448 469 }
449 470
450 471 /*!
451 472 Sets \a pen used to draw shades.
452 473 */
453 474 void QAbstractAxis::setShadesPen(const QPen &pen)
454 475 {
455 476 if (d_ptr->m_shadesPen != pen) {
456 477 d_ptr->m_shadesPen = pen;
457 478 emit d_ptr->updated();
458 479 }
459 480 }
460 481
461 482 /*!
462 483 Returns pen used to draw shades.
463 484 */
464 485 QPen QAbstractAxis::shadesPen() const
465 486 {
466 487 return d_ptr->m_shadesPen;
467 488 }
468 489
469 490 /*!
470 491 Sets \a brush used to draw shades.
471 492 */
472 493 void QAbstractAxis::setShadesBrush(const QBrush &brush)
473 494 {
474 495 if (d_ptr->m_shadesBrush != brush) {
475 496 d_ptr->m_shadesBrush = brush;
476 497 emit d_ptr->updated();
477 498 emit shadesColorChanged(brush.color());
478 499 }
479 500 }
480 501
481 502 /*!
482 503 Returns brush used to draw shades.
483 504 */
484 505 QBrush QAbstractAxis::shadesBrush() const
485 506 {
486 507 return d_ptr->m_shadesBrush;
487 508 }
488 509
489 510 void QAbstractAxis::setShadesColor(QColor color)
490 511 {
491 512 QBrush b = d_ptr->m_shadesBrush;
492 513 b.setColor(color);
493 514 setShadesBrush(b);
494 515 }
495 516
496 517 QColor QAbstractAxis::shadesColor() const
497 518 {
498 519 return d_ptr->m_shadesBrush.color();
499 520 }
500 521
501 522 void QAbstractAxis::setShadesBorderColor(QColor color)
502 523 {
503 524 QPen p = d_ptr->m_shadesPen;
504 525 p.setColor(color);
505 526 setShadesPen(p);
506 527 }
507 528
508 529 QColor QAbstractAxis::shadesBorderColor() const
509 530 {
510 531 return d_ptr->m_shadesPen.color();
511 532 }
512 533
513 534
514 535 bool QAbstractAxis::isVisible() const
515 536 {
516 537 return d_ptr->m_visible;
517 538 }
518 539
519 540 /*!
520 541 Sets axis, shades, labels and grid lines to be visible.
521 542 */
522 543 void QAbstractAxis::setVisible(bool visible)
523 544 {
524 545 if(d_ptr->m_visible!=visible){
525 546 d_ptr->m_visible=visible;
526 547 emit visibleChanged(visible);
527 548 emit d_ptr->updated();
528 549 }
529 550 }
530 551
531 552
532 553 /*!
533 554 Sets axis, shades, labels and grid lines to be visible.
534 555 */
535 556 void QAbstractAxis::show()
536 557 {
537 558 setVisible(true);
538 559 }
539 560
540 561 /*!
541 562 Sets axis, shades, labels and grid lines to not be visible.
542 563 */
543 564 void QAbstractAxis::hide()
544 565 {
545 566 setVisible(false);
546 567 }
547 568
548 569 /*!
549 570 Sets the minimum value shown on the axis.
550 571 Depending on the actual axis type the \a min paramter is converted to appropriate type.
551 572 If the conversion is impossible then the function call does nothing
552 573 */
553 574 void QAbstractAxis::setMin(const QVariant &min)
554 575 {
555 576 d_ptr->setMin(min);
556 577 }
557 578
558 579 /*!
559 580 Sets the maximum value shown on the axis.
560 581 Depending on the actual axis type the \a max paramter is converted to appropriate type.
561 582 If the conversion is impossible then the function call does nothing
562 583 */
563 584 void QAbstractAxis::setMax(const QVariant &max)
564 585 {
565 586 d_ptr->setMax(max);
566 587 }
567 588
568 589 /*!
569 590 Sets the range shown on the axis.
570 591 Depending on the actual axis type the \a min and \a max paramters are converted to appropriate types.
571 592 If the conversion is impossible then the function call does nothing.
572 593 */
573 594 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
574 595 {
575 596 d_ptr->setRange(min,max);
576 597 }
577 598
578 599 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
579 600
580 601 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q):
581 602 q_ptr(q),
582 603 m_visible(false),
583 m_axisVisible(true),
604 m_arrowVisible(true),
584 605 m_gridLineVisible(true),
585 606 m_labelsVisible(true),
586 607 m_labelsAngle(0),
587 608 m_shadesVisible(false),
588 609 m_shadesBrush(Qt::SolidPattern),
589 610 m_shadesOpacity(1.0),
590 611 m_orientation(Qt::Orientation(0)),
591 612 m_min(0),
592 613 m_max(0),
593 614 m_ticksCount(5)
594 615 {
595 616
596 617 }
597 618
598 619 QAbstractAxisPrivate::~QAbstractAxisPrivate()
599 620 {
600 621
601 622 }
602 623
603 624 #include "moc_qabstractaxis.cpp"
604 625 #include "moc_qabstractaxis_p.cpp"
605 626
606 627 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,139 +1,139
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #ifndef QABSTRACTAXIS_H
22 22 #define QABSTRACTAXIS_H
23 23
24 24 #include <qchartglobal.h>
25 25 #include <QPen>
26 26 #include <QFont>
27 27 #include <QVariant>
28 28
29 29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 30
31 31 class QAbstractAxisPrivate;
32 32
33 33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 34 {
35 35 Q_OBJECT
36 36 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool arrowVisible READ isArrowVisible WRITE setArrowVisible NOTIFY arrowVisibleChanged)
38 38 Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged)
39 39 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
40 40 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle)
41 41 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont)
42 42 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
43 43 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
44 44 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
45 45 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
46 46 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
47 47
48 48 public:
49 49
50 50 enum AxisType {
51 51 AxisTypeNoAxis = 0x0,
52 52 AxisTypeValues = 0x1,
53 53 AxisTypeCategories = 0x2
54 54 };
55 55
56 56 Q_DECLARE_FLAGS(AxisTypes, AxisType)
57 57
58 58 protected:
59 59 explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0);
60 60
61 61 public:
62 62 ~QAbstractAxis();
63 63
64 64 virtual AxisType type() const = 0;
65 65
66 66 //visibilty hadnling
67 67 bool isVisible() const;
68 68 void setVisible(bool visible = true);
69 69
70 70
71 71 //axis handling
72 bool isAxisVisible() const;
73 void setAxisVisible(bool visible = true);
72 bool isArrowVisible() const;
73 void setArrowVisible(bool visible = true);
74 74 void setAxisPen(const QPen &pen);
75 75 QPen axisPen() const;
76 76 void setAxisPenColor(QColor color);
77 77 QColor axisPenColor() const;
78 78
79 79 //grid handling
80 80 bool isGridLineVisible() const;
81 81 void setGridLineVisible(bool visible = true);
82 82 void setGridLinePen(const QPen &pen);
83 83 QPen gridLinePen() const;
84 84
85 85 //labels handling
86 86 bool labelsVisible() const;
87 87 void setLabelsVisible(bool visible = true);
88 88 void setLabelsPen(const QPen &pen);
89 89 QPen labelsPen() const;
90 90 void setLabelsBrush(const QBrush &brush);
91 91 QBrush labelsBrush() const;
92 92 void setLabelsFont(const QFont &font);
93 93 QFont labelsFont() const;
94 94 void setLabelsAngle(int angle);
95 95 int labelsAngle() const;
96 96 void setLabelsColor(QColor color);
97 97 QColor labelsColor() const;
98 98
99 99 //shades handling
100 100 bool shadesVisible() const;
101 101 void setShadesVisible(bool visible = true);
102 102 void setShadesPen(const QPen &pen);
103 103 QPen shadesPen() const;
104 104 void setShadesBrush(const QBrush &brush);
105 105 QBrush shadesBrush() const;
106 106 void setShadesColor(QColor color);
107 107 QColor shadesColor() const;
108 108 void setShadesBorderColor(QColor color);
109 109 QColor shadesBorderColor() const;
110 110
111 111 //range handling
112 112 void setMin(const QVariant &min);
113 113 void setMax(const QVariant &max);
114 114 void setRange(const QVariant &min, const QVariant &max);
115 115
116 116 void show();
117 117 void hide();
118 118
119 119 Q_SIGNALS:
120 120 void visibleChanged(bool visible);
121 void axisVisibleChanged(bool visible);
121 void arrowVisibleChanged(bool visible);
122 122 void labelsVisibleChanged(bool visible);
123 123 void gridVisibleChanged(bool visible);
124 124 void colorChanged(QColor color);
125 125 void labelsColorChanged(QColor color);
126 126 void shadesVisibleChanged(bool visible);
127 127 void shadesColorChanged(QColor color);
128 128 void shadesBorderColorChanged(QColor color);
129 129
130 130 protected:
131 131 QScopedPointer<QAbstractAxisPrivate> d_ptr;
132 132 Q_DISABLE_COPY(QAbstractAxis);
133 133 friend class ChartDataSet;
134 134 friend class ChartAxis;
135 135 friend class ChartPresenter;
136 136 };
137 137
138 138 QTCOMMERCIALCHART_END_NAMESPACE
139 139 #endif
@@ -1,94 +1,94
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 // W A R N I N G
22 22 // -------------
23 23 //
24 24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 25 // implementation detail. This header file may change from version to
26 26 // version without notice, or even be removed.
27 27 //
28 28 // We mean it.
29 29
30 30 #ifndef QABSTRACTAXIS_P_H
31 31 #define QABSTRACTAXIS_P_H
32 32
33 33 #include "qabstractaxis.h"
34 34
35 35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 36
37 37 class ChartPresenter;
38 38 class ChartAxis;
39 39
40 40 class QAbstractAxisPrivate : public QObject
41 41 {
42 42 Q_OBJECT
43 43 public:
44 44 QAbstractAxisPrivate(QAbstractAxis *q);
45 45 ~QAbstractAxisPrivate();
46 46
47 47 Q_SIGNALS:
48 48 void updated();
49 49
50 50 public:
51 51 virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0;
52 52 virtual void emitRange() = 0;
53 53
54 54 protected:
55 55 virtual void setMin(const QVariant &min) = 0;
56 56 virtual void setMax(const QVariant &max) = 0;
57 57 virtual void setRange(const QVariant &min, const QVariant &max) = 0;
58 58 virtual int ticksCount() const = 0;
59 59
60 60 public:
61 61 QAbstractAxis *q_ptr;
62 62 bool m_visible;
63 63
64 bool m_axisVisible;
64 bool m_arrowVisible;
65 65 QPen m_axisPen;
66 66 QBrush m_axisBrush;
67 67
68 68 bool m_gridLineVisible;
69 69 QPen m_gridLinePen;
70 70
71 71 bool m_labelsVisible;
72 72 QPen m_labelsPen;
73 73 QBrush m_labelsBrush;
74 74 QFont m_labelsFont;
75 75 int m_labelsAngle;
76 76
77 77 bool m_shadesVisible;
78 78 QPen m_shadesPen;
79 79 QBrush m_shadesBrush;
80 80 qreal m_shadesOpacity;
81 81
82 82 Qt::Orientation m_orientation;
83 83
84 84 // range
85 85 qreal m_min;
86 86 qreal m_max;
87 87 int m_ticksCount;
88 88
89 89 friend class QAbstractAxis;
90 90 };
91 91
92 92 QTCOMMERCIALCHART_END_NAMESPACE
93 93
94 94 #endif
@@ -1,381 +1,389
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qbarcategoriesaxis.h"
22 22 #include "qbarcategoriesaxis_p.h"
23 23 #include "chartcategoriesaxisx_p.h"
24 24 #include "chartcategoriesaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \class QBarCategoriesAxis
31 31 \brief The QBarCategoriesAxis class is used for manipulating chart's axis.
32 32 \mainclass
33 33
34 34 BarCategoriesAxis can be setup to show axis line with tick marks, grid lines and shades.
35 35 Categories are drawn between ticks. Note that you can use this also with lineseries too.
36 36 See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that.
37 37 */
38 38
39 39 /*!
40 40 \qmlclass BarCategoriesAxis QBarCategoriesAxis
41 41 \brief The Axis element is used for manipulating chart's axes.
42 42
43 43 Axis can be setup to show axis line with tick marks, grid lines and shades.
44 44 Categories are drawn between ticks. Note that you can use this also with lineseries too.
45 45
46 46 To access BarCategoriesAxis you can use ChartView API. For example:
47 47 \code
48 48 ChartView {
49 49 BarCategoriesAxis {
50 50 id: categoryAxis
51 51 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
52 52 }
53 53 // Add a few series...
54 54 }
55 55 \endcode
56 56 */
57 57
58 58 /*!
59 59 \property QBarCategoriesAxis::categories
60 60 Defines the categories of axis
61 61 */
62 62 /*!
63 63 \qmlproperty QStringList BarCategoriesAxis::categories
64 64 Defines the categories of axis
65 65 */
66 66
67 67 /*!
68 68 \property QBarCategoriesAxis::min
69 69 Defines the minimum value on the axis.
70 70 */
71 71 /*!
72 \qmlproperty real BarCategoriesAxis::min
72 \qmlproperty QString BarCategoriesAxis::min
73 73 Defines the minimum value on the axis.
74 74 */
75 75
76 76 /*!
77 77 \property QBarCategoriesAxis::max
78 78 Defines the maximum value on the axis.
79 79 */
80 80 /*!
81 \qmlproperty real BarCategoriesAxis::max
81 \qmlproperty QString BarCategoriesAxis::max
82 82 Defines the maximum value on the axis.
83 83 */
84 84
85 85 /*!
86 86 \fn void QBarCategoriesAxis::minChanged(const QString &min)
87 87 Axis emits signal when \a min of axis has changed.
88 88 */
89 /*!
90 \qmlsignal BarCategoriesAxis::onMinChanged(const QString &min)
91 Axis emits signal when \a min of axis has changed.
92 */
89 93
90 94 /*!
91 95 \fn void QBarCategoriesAxis::maxChanged(const QString &max)
92 96 Axis emits signal when \a max of axis has changed.
93 97 */
98 /*!
99 \qmlsignal BarCategoriesAxis::onMaxChanged(const QString &max)
100 Axis emits signal when \a max of axis has changed.
101 */
94 102
95 103 /*!
96 104 \fn void QBarCategoriesAxis::rangeChanged(const QString &min, const QString &max)
97 105 Axis emits signal when \a min or \a max of axis has changed.
98 106 */
99 107
100 108 /*!
101 109 Constructs an axis object which is a child of \a parent.
102 110 */
103 111 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
104 112 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
105 113 {
106 114 }
107 115
108 116 /*!
109 117 Destroys the object
110 118 */
111 119 QBarCategoriesAxis::~QBarCategoriesAxis()
112 120 {
113 121 }
114 122
115 123 /*!
116 124 \internal
117 125 */
118 126 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
119 127 {
120 128
121 129 }
122 130
123 131 /*!
124 132 Appends \a categories to axis
125 133 */
126 134 void QBarCategoriesAxis::append(const QStringList &categories)
127 135 {
128 136 if(categories.isEmpty()) return;
129 137
130 138 Q_D(QBarCategoriesAxis);
131 139 if (d->m_categories.isEmpty()) {
132 140 d->m_categories.append(categories);
133 141 setRange(categories.first(),categories.last());
134 142 }else{
135 143 d->m_categories.append(categories);
136 144 }
137 145 emit d->updated();
138 146 emit categoriesChanged();
139 147 }
140 148
141 149 /*!
142 150 Appends \a category to axis
143 151 */
144 152 void QBarCategoriesAxis::append(const QString &category)
145 153 {
146 154 Q_D(QBarCategoriesAxis);
147 155 if (d->m_categories.isEmpty()) {
148 156 d->m_categories.append(category);
149 157 setRange(category,category);
150 158 }else{
151 159 d->m_categories.append(category);
152 160 }
153 161 emit d->updated();
154 162 emit categoriesChanged();
155 163 }
156 164
157 165 /*!
158 166 Removes \a category from axis
159 167 */
160 168 void QBarCategoriesAxis::remove(const QString &category)
161 169 {
162 170 Q_D(QBarCategoriesAxis);
163 171 if (d->m_categories.contains(category)) {
164 172 d->m_categories.removeAt(d->m_categories.indexOf(category));
165 173 setRange(d->m_categories.first(),d->m_categories.last());
166 174 emit d->updated();
167 175 emit categoriesChanged();
168 176 }
169 177 }
170 178
171 179 /*!
172 180 Inserts \a category to axis at \a index
173 181 */
174 182 void QBarCategoriesAxis::insert(int index, const QString &category)
175 183 {
176 184 Q_D(QBarCategoriesAxis);
177 185 if (d->m_categories.isEmpty()) {
178 186 d->m_categories.insert(index,category);
179 187 setRange(category,category);
180 188 }else{
181 189 d->m_categories.insert(index,category);
182 190 }
183 191 emit d->updated();
184 192 emit categoriesChanged();
185 193 }
186 194
187 195 /*!
188 196 Removes all categories.
189 197 */
190 198 void QBarCategoriesAxis::clear()
191 199 {
192 200 Q_D(QBarCategoriesAxis);
193 201 d->m_categories.clear();
194 202 setRange(QString::null,QString::null);
195 203 emit d->updated();
196 204 emit categoriesChanged();
197 205 }
198 206
199 207 void QBarCategoriesAxis::setCategories(const QStringList &categories)
200 208 {
201 209 Q_D(QBarCategoriesAxis);
202 210 if(d->m_categories!=categories){
203 211 d->m_categories = categories;
204 212 setRange(categories.first(),categories.last());
205 213 emit d->updated();
206 214 emit categoriesChanged();
207 215 }
208 216 }
209 217
210 218 QStringList QBarCategoriesAxis::categories()
211 219 {
212 220 Q_D(QBarCategoriesAxis);
213 221 return d->m_categories;
214 222 }
215 223
216 224 /*!
217 225 Returns number of categories.
218 226 */
219 227 int QBarCategoriesAxis::count() const
220 228 {
221 229 Q_D(const QBarCategoriesAxis);
222 230 return d->m_categories.count();
223 231 }
224 232
225 233 /*!
226 234 Returns category at \a index. Index must be valid.
227 235 */
228 236 QString QBarCategoriesAxis::at(int index) const
229 237 {
230 238 Q_D(const QBarCategoriesAxis);
231 239 return d->m_categories.at(index);
232 240 }
233 241
234 242 /*!
235 243 Sets minimum category to \a min.
236 244 */
237 245 void QBarCategoriesAxis::setMin(const QString& min)
238 246 {
239 247 Q_D(QBarCategoriesAxis);
240 248 setRange(min,d->m_maxCategory);
241 249 }
242 250
243 251 /*!
244 252 Returns minimum category.
245 253 */
246 254 QString QBarCategoriesAxis::min() const
247 255 {
248 256 Q_D(const QBarCategoriesAxis);
249 257 return d->m_minCategory;
250 258 }
251 259
252 260 /*!
253 261 Sets maximum category to \a max.
254 262 */
255 263 void QBarCategoriesAxis::setMax(const QString& max)
256 264 {
257 265 Q_D(QBarCategoriesAxis);
258 266 setRange(d->m_minCategory,max);
259 267 }
260 268
261 269 /*!
262 270 Returns maximum category
263 271 */
264 272 QString QBarCategoriesAxis::max() const
265 273 {
266 274 Q_D(const QBarCategoriesAxis);
267 275 return d->m_maxCategory;
268 276 }
269 277
270 278 /*!
271 279 Sets range from \a minCategory to \a maxCategory
272 280 */
273 281 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
274 282 {
275 283 Q_D(QBarCategoriesAxis);
276 284
277 285 int minIndex = d->m_categories.indexOf(minCategory);
278 286 if (minIndex == -1) {
279 287 return;
280 288 }
281 289 int maxIndex = d->m_categories.indexOf(maxCategory);
282 290 if (maxIndex == -1) {
283 291 return;
284 292 }
285 293
286 294 if (maxIndex <= minIndex) {
287 295 // max must be greater than min
288 296 return;
289 297 }
290 298
291 299 bool changed = false;
292 300 if (!qFuzzyIsNull(d->m_min - (minIndex))||d->m_minCategory!=minCategory) {
293 301 d->m_minCategory = minCategory;
294 302 d->m_min = minIndex;
295 303 emit minChanged(minCategory);
296 304 changed = true;
297 305 }
298 306
299 307 if (!qFuzzyIsNull(d->m_max - (maxIndex))||d->m_maxCategory!=maxCategory ) {
300 308 d->m_max = maxIndex;
301 309 d->m_maxCategory = maxCategory;
302 310 emit maxChanged(maxCategory);
303 311 changed = true;
304 312 }
305 313
306 314 if (changed) {
307 315 d->emitRange();
308 316 }
309 317 }
310 318
311 319 /*!
312 320 Returns the type of the axis
313 321 */
314 322 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
315 323 {
316 324 return AxisTypeCategories;
317 325 }
318 326
319 327 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
320 328
321 329 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
322 330 QAbstractAxisPrivate(q)
323 331 {
324 332
325 333 }
326 334
327 335 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
328 336 {
329 337
330 338 }
331 339
332 340 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
333 341 {
334 342 setRange(min,m_maxCategory);
335 343 }
336 344
337 345 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
338 346 {
339 347 setRange(m_minCategory,max);
340 348 }
341 349
342 350 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
343 351 {
344 352 Q_Q(QBarCategoriesAxis);
345 353 QString value1 = min.toString();
346 354 QString value2 = max.toString();
347 355 q->setRange(value1,value2);
348 356 }
349 357
350 358 int QBarCategoriesAxisPrivate::ticksCount() const
351 359 {
352 360 return m_categories.count()+1;
353 361 }
354 362
355 363 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
356 364 {
357 365 m_min = min;
358 366 m_max = max;
359 367 m_ticksCount = count;
360 368 }
361 369
362 370 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
363 371 {
364 372 Q_Q( QBarCategoriesAxis);
365 373 if(m_orientation == Qt::Vertical){
366 374 return new ChartCategoriesAxisY(q,presenter);
367 375 }else{
368 376 return new ChartCategoriesAxisX(q,presenter);
369 377 }
370 378 }
371 379
372 380 void QBarCategoriesAxisPrivate::emitRange()
373 381 {
374 382 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
375 383 }
376 384
377 385
378 386 #include "moc_qbarcategoriesaxis.cpp"
379 387 #include "moc_qbarcategoriesaxis_p.cpp"
380 388
381 389 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,178 +1,178
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qintervalaxis.h"
22 22 #include "qintervalaxis_p.h"
23 23 #include "chartcategoriesaxisx_p.h"
24 24 #include "chartcategoriesaxisy_p.h"
25 25 #include <qmath.h>
26 26 #include <QDebug>
27 27
28 28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 29 /*!
30 30 \internal
31 31 \class QIntervalAxis
32 32 \brief The QIntervalAxis class is used for manipulating chart's axis.
33 33 \mainclass
34 34
35 35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 36 */
37 37
38 38 /*!
39 39 \qmlclass Axis QIntervalAxis
40 40 \brief The Axis element is used for manipulating chart's axes.
41 41
42 42 Axis can be setup to show axis line with tick marks, grid lines and shades.
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 // TODO :)
47 47 \endcode
48 48 */
49 49
50 50 /*!
51 51 Constructs an axis object which is a child of \a parent.
52 52 */
53 53 QIntervalAxis::QIntervalAxis(QObject *parent):
54 54 QValuesAxis(*new QIntervalAxisPrivate(this),parent)
55 55 {
56 56 }
57 57
58 58 /*!
59 59 Destroys the object
60 60 */
61 61 QIntervalAxis::~QIntervalAxis()
62 62 {
63 63 }
64 64
65 65 /*!
66 66 \internal
67 67 */
68 68 QIntervalAxis::QIntervalAxis(QIntervalAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
69 69 {
70 70
71 71 }
72 72
73 73 /*!
74 Appends \a categories to axis
74 Appends \a category to axis
75 75 */
76 76 void QIntervalAxis::append(const QString& category, qreal x)
77 77 {
78 78 Q_D(QIntervalAxis);
79 79 if (!d->m_categories.contains(category))
80 80 {
81 81 if(d->m_categories.isEmpty()){
82 82 Range range(d->m_categoryMinimum,x);
83 83 d->m_categoriesMap.insert(category,range);
84 84 d->m_categories.append(category);
85 85 }else{
86 86 Range range = d->m_categoriesMap.value(d->m_categories.last());
87 87 d->m_categoriesMap.insert(category,Range(range.first,x));
88 88 d->m_categories.append(category);
89 89 }
90 90 setRange(d->m_min,x);
91 91 }
92 92 }
93 93
94 94 void QIntervalAxis::setFisrtCategoryMinimum(qreal x)
95 95 {
96 96 Q_D(QIntervalAxis);
97 97 if(d->m_categories.isEmpty()){
98 98 d->m_categoryMinimum=x;
99 99 }else{
100 100 Range range = d->m_categoriesMap.value(d->m_categories.first());
101 101 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
102 102 setRange(x,d->m_min);
103 103 }
104 104 }
105 105
106 106 /*!
107 107 Removes \a category from axis
108 108 */
109 109 void QIntervalAxis::remove(const QString &category)
110 110 {
111 111 Q_UNUSED(category);
112 112 //TODO
113 113 }
114 114
115 115 QStringList QIntervalAxis::categories()
116 116 {
117 117 Q_D(QIntervalAxis);
118 118 return d->m_categories;
119 119 }
120 120
121 121 /*!
122 122 Returns number of categories.
123 123 */
124 124 int QIntervalAxis::count() const
125 125 {
126 126 Q_D(const QIntervalAxis);
127 127 return d->m_categories.count();
128 128 }
129 129
130 130 /*!
131 131 Returns the type of the axis
132 132 */
133 133 QAbstractAxis::AxisType QIntervalAxis::type() const
134 134 {
135 135 return AxisTypeCategories;
136 136 }
137 137
138 138 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
139 139
140 140 QIntervalAxisPrivate::QIntervalAxisPrivate(QIntervalAxis* q):
141 141 QValuesAxisPrivate(q),
142 142 m_categoryMinimum(0)
143 143 {
144 144
145 145 }
146 146
147 147 QIntervalAxisPrivate::~QIntervalAxisPrivate()
148 148 {
149 149
150 150 }
151 151
152 152 int QIntervalAxisPrivate::ticksCount() const
153 153 {
154 154 return m_categories.count()+1;
155 155 }
156 156
157 157 void QIntervalAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
158 158 {
159 159 m_min = min;
160 160 m_max = max;
161 161 m_ticksCount = count;
162 162 }
163 163
164 164 ChartAxis* QIntervalAxisPrivate::createGraphics(ChartPresenter* presenter)
165 165 {
166 166 Q_UNUSED(presenter);
167 167 // Q_Q( QCategoriesAxis);
168 168 if(m_orientation == Qt::Vertical){
169 169 return 0;
170 170 }else{
171 171 return 0;
172 172 }
173 173 }
174 174
175 175 #include "moc_qintervalaxis.cpp"
176 176 #include "moc_qintervalaxis_p.cpp"
177 177
178 178 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,303 +1,311
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "qvaluesaxis.h"
22 22 #include "qvaluesaxis_p.h"
23 23 #include "chartvaluesaxisx_p.h"
24 24 #include "chartvaluesaxisy_p.h"
25 25 #include <QDebug>
26 26
27 27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 28 /*!
29 29 \class QValuesAxis
30 30 \brief The QValuesAxis class is used for manipulating chart's axis.
31 31 \mainclass
32 32
33 33 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
34 34 Values of axis are drawn to position of ticks
35 35 */
36 36
37 37 /*!
38 38 \qmlclass ValuesAxis QValuesAxis
39 39 \brief The ValuesAxis element is used for manipulating chart's axes
40 40
41 41 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
42 42 Values of axis are drawn to position of ticks
43 43
44 44 To access Axes you can use ChartView API. For example:
45 45 \code
46 46 ChartView {
47 47 ValuesAxis {
48 48 id: xAxis
49 49 min: 0
50 50 max: 10
51 51 }
52 52 // Add a few series...
53 53 }
54 54 \endcode
55 55 */
56 56
57 57 /*!
58 58 \property QValuesAxis::min
59 59 Defines the minimum value on the axis.
60 60 */
61 61 /*!
62 62 \qmlproperty real ValuesAxis::min
63 63 Defines the minimum value on the axis.
64 64 */
65 65
66 66 /*!
67 67 \property QValuesAxis::max
68 68 Defines the maximum value on the axis.
69 69 */
70 70 /*!
71 71 \qmlproperty real ValuesAxis::max
72 72 Defines the maximum value on the axis.
73 73 */
74 74
75 75 /*!
76 76 \fn void QValuesAxis::minChanged(qreal min)
77 77 Axis emits signal when \a min of axis has changed.
78 78 */
79 /*!
80 \qmlsignal ValuesAxis::onMinChanged(real min)
81 Axis emits signal when \a min of axis has changed.
82 */
79 83
80 84 /*!
81 85 \fn void QValuesAxis::maxChanged(qreal max)
82 86 Axis emits signal when \a max of axis has changed.
83 87 */
88 /*!
89 \qmlsignal ValuesAxis::onMaxChanged(real max)
90 Axis emits signal when \a max of axis has changed.
91 */
84 92
85 93 /*!
86 94 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
87 95 Axis emits signal when \a min or \a max of axis has changed.
88 96 */
89 97
90 98 /*!
91 99 \property QValuesAxis::ticksCount
92 100 The number of tick marks for the axis.
93 101 */
94 102
95 103 /*!
96 104 \qmlproperty int ValuesAxis::ticksCount
97 105 The number of tick marks for the axis.
98 106 */
99 107
100 108 /*!
101 109 \property QValuesAxis::niceNumbersEnabled
102 110 Whether the nice numbers algorithm is enabled or not for the axis.
103 111 */
104 112
105 113 /*!
106 114 \qmlproperty bool ValuesAxis::niceNumbersEnabled
107 115 Whether the nice numbers algorithm is enabled or not for the axis.
108 116 */
109 117
110 118 /*!
111 119 Constructs an axis object which is a child of \a parent.
112 120 */
113 121 QValuesAxis::QValuesAxis(QObject *parent) :
114 122 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
115 123 {
116 124
117 125 }
118 126
119 127 /*!
120 128 \internal
121 129 */
122 130 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
123 131 {
124 132
125 133 }
126 134
127 135 /*!
128 136 Destroys the object
129 137 */
130 138 QValuesAxis::~QValuesAxis()
131 139 {
132 140
133 141 }
134 142
135 143 void QValuesAxis::setMin(qreal min)
136 144 {
137 145 Q_D(QValuesAxis);
138 146 setRange(min,d->m_max);
139 147 }
140 148
141 149 qreal QValuesAxis::min() const
142 150 {
143 151 Q_D(const QValuesAxis);
144 152 return d->m_min;
145 153 }
146 154
147 155 void QValuesAxis::setMax(qreal max)
148 156 {
149 157 Q_D(QValuesAxis);
150 158 setRange(d->m_min,max);
151 159 }
152 160
153 161 qreal QValuesAxis::max() const
154 162 {
155 163 Q_D(const QValuesAxis);
156 164 return d->m_max;
157 165 }
158 166
159 167 /*!
160 168 Sets range from \a min to \a max on the axis.
161 169 */
162 170 void QValuesAxis::setRange(qreal min, qreal max)
163 171 {
164 172 Q_D(QValuesAxis);
165 173
166 174 bool changed = false;
167 175 if (!qFuzzyIsNull(d->m_min - min)) {
168 176 d->m_min = min;
169 177 changed = true;
170 178 emit minChanged(min);
171 179 }
172 180
173 181 if (!qFuzzyIsNull(d->m_max - max)) {
174 182 d->m_max = max;
175 183 changed = true;
176 184 emit maxChanged(max);
177 185 }
178 186
179 187 if (changed) {
180 188 d->emitRange();
181 189 emit rangeChanged(d->m_min,d->m_max);
182 190 }
183 191 }
184 192
185 193 /*!
186 194 Sets \a count for ticks on the axis.
187 195 */
188 196 void QValuesAxis::setTicksCount(int count)
189 197 {
190 198 Q_D(QValuesAxis);
191 199 if (d->m_ticksCount != count) {
192 200 d->m_ticksCount = count;
193 201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
194 202 }
195 203 }
196 204
197 205 /*!
198 206 \fn int QValuesAxis::ticksCount() const
199 207 Return number of ticks on the axis
200 208 */
201 209 int QValuesAxis::ticksCount() const
202 210 {
203 211 Q_D(const QValuesAxis);
204 212 return d->m_ticksCount;
205 213 }
206 214
207 215 void QValuesAxis::setNiceNumbersEnabled(bool enable)
208 216 {
209 217 Q_D(QValuesAxis);
210 218 if (d->m_niceNumbers != enable){
211 219 d->m_niceNumbers = enable;
212 220 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
213 221 }
214 222 }
215 223
216 224 bool QValuesAxis::niceNumbersEnabled() const
217 225 {
218 226 Q_D(const QValuesAxis);
219 227 return d->m_niceNumbers;
220 228 }
221 229
222 230 /*!
223 231 Returns the type of the axis
224 232 */
225 233 QAbstractAxis::AxisType QValuesAxis::type() const
226 234 {
227 235 return AxisTypeValues;
228 236 }
229 237
230 238 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
231 239
232 240 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
233 241 QAbstractAxisPrivate(q),
234 242 m_niceNumbers(false)
235 243 {
236 244
237 245 }
238 246
239 247 QValuesAxisPrivate::~QValuesAxisPrivate()
240 248 {
241 249
242 250 }
243 251
244 252 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
245 253 {
246 254 Q_Q(QValuesAxis);
247 255 q->setRange(min,max);
248 256 q->setTicksCount(count);
249 257 }
250 258
251 259
252 260 void QValuesAxisPrivate::setMin(const QVariant &min)
253 261 {
254 262 Q_Q(QValuesAxis);
255 263 bool ok;
256 264 qreal value = min.toReal(&ok);
257 265 if(ok) q->setMin(value);
258 266 }
259 267
260 268 void QValuesAxisPrivate::setMax(const QVariant &max)
261 269 {
262 270
263 271 Q_Q(QValuesAxis);
264 272 bool ok;
265 273 qreal value = max.toReal(&ok);
266 274 if(ok) q->setMax(value);
267 275 }
268 276
269 277 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
270 278 {
271 279 Q_Q(QValuesAxis);
272 280 bool ok1;
273 281 bool ok2;
274 282 qreal value1 = min.toReal(&ok1);
275 283 qreal value2 = max.toReal(&ok2);
276 284 if(ok1&&ok2) q->setRange(value1,value2);
277 285 }
278 286
279 287 int QValuesAxisPrivate::ticksCount() const
280 288 {
281 289 return m_ticksCount;
282 290 }
283 291
284 292 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
285 293 {
286 294 Q_Q(QValuesAxis);
287 295 if(m_orientation == Qt::Vertical){
288 296 return new ChartValuesAxisY(q,presenter);
289 297 }else{
290 298 return new ChartValuesAxisX(q,presenter);
291 299 }
292 300
293 301 }
294 302
295 303 void QValuesAxisPrivate::emitRange()
296 304 {
297 305 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
298 306 }
299 307
300 308 #include "moc_qvaluesaxis.cpp"
301 309 #include "moc_qvaluesaxis_p.cpp"
302 310
303 311 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,389 +1,389
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include "charttheme_p.h"
22 22 #include "qchart.h"
23 23 #include "qchart_p.h"
24 24 #include "qchartview.h"
25 25 #include "qlegend.h"
26 26 #include "qabstractaxis.h"
27 27 #include <QTime>
28 28
29 29 //series
30 30 #include "qbarset.h"
31 31 #include "qabstractbarseries.h"
32 32 #include "qstackedbarseries.h"
33 33 #include "qpercentbarseries.h"
34 34 #include "qlineseries.h"
35 35 #include "qareaseries.h"
36 36 #include "qscatterseries.h"
37 37 #include "qpieseries.h"
38 38 #include "qpieslice.h"
39 39 #include "qpieslice_p.h"
40 40 #include "qsplineseries.h"
41 41
42 42 //items
43 43 #include "chartaxis_p.h"
44 44 #include "barchartitem_p.h"
45 45 #include "stackedbarchartitem_p.h"
46 46 #include "percentbarchartitem_p.h"
47 47 #include "linechartitem_p.h"
48 48 #include "areachartitem_p.h"
49 49 #include "scatterchartitem_p.h"
50 50 #include "piechartitem_p.h"
51 51 #include "splinechartitem_p.h"
52 52
53 53 //themes
54 54 #include "chartthemesystem_p.h"
55 55 #include "chartthemelight_p.h"
56 56 #include "chartthemebluecerulean_p.h"
57 57 #include "chartthemedark_p.h"
58 58 #include "chartthemebrownsand_p.h"
59 59 #include "chartthemebluencs_p.h"
60 60 #include "chartthemehighcontrast_p.h"
61 61 #include "chartthemeblueicy_p.h"
62 62
63 63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
64 64
65 65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
66 66 m_masterFont(QFont("arial", 14)),
67 67 m_labelFont(QFont("arial", 10)),
68 68 m_labelBrush(QColor(QRgb(0x000000))),
69 69 m_axisLinePen(QPen(QRgb(0x000000))),
70 70 m_backgroundShadesPen(Qt::NoPen),
71 71 m_backgroundShadesBrush(Qt::NoBrush),
72 72 m_backgroundShades(BackgroundShadesNone),
73 73 m_backgroundDropShadowEnabled(false),
74 74 m_gridLinePen(QPen(QRgb(0x000000))),
75 75 m_force(false)
76 76 {
77 77 m_id = id;
78 78 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
79 79 }
80 80
81 81
82 82 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
83 83 {
84 84 switch(theme) {
85 85 case QChart::ChartThemeLight:
86 86 return new ChartThemeLight();
87 87 case QChart::ChartThemeBlueCerulean:
88 88 return new ChartThemeBlueCerulean();
89 89 case QChart::ChartThemeDark:
90 90 return new ChartThemeDark();
91 91 case QChart::ChartThemeBrownSand:
92 92 return new ChartThemeBrownSand();
93 93 case QChart::ChartThemeBlueNcs:
94 94 return new ChartThemeBlueNcs();
95 95 case QChart::ChartThemeHighContrast:
96 96 return new ChartThemeHighContrast();
97 97 case QChart::ChartThemeBlueIcy:
98 98 return new ChartThemeBlueIcy();
99 99 default:
100 100 return new ChartThemeSystem();
101 101 }
102 102 }
103 103
104 104 void ChartTheme::decorate(QChart *chart)
105 105 {
106 106 QBrush brush;
107 107
108 108 if(brush == chart->backgroundBrush() || m_force)
109 109 chart->setBackgroundBrush(m_chartBackgroundGradient);
110 110 chart->setTitleFont(m_masterFont);
111 111 chart->setTitleBrush(m_labelBrush);
112 112 chart->setDropShadowEnabled(m_backgroundDropShadowEnabled);
113 113 }
114 114
115 115 void ChartTheme::decorate(QLegend *legend)
116 116 {
117 117 QPen pen;
118 118 QBrush brush;
119 119 QFont font;
120 120
121 121 if (pen == legend->pen() || m_force)
122 122 legend->setPen(m_axisLinePen);
123 123
124 124 if (brush == legend->brush() || m_force)
125 125 legend->setBrush(m_chartBackgroundGradient);
126 126
127 127 if (font == legend->font() || m_force)
128 128 legend->setFont(m_labelFont);
129 129
130 130 if (brush == legend->labelBrush() || m_force)
131 131 legend->setLabelBrush(m_labelBrush);
132 132 }
133 133
134 134 void ChartTheme::decorate(QAreaSeries *series, int index)
135 135 {
136 136 QPen pen;
137 137 QBrush brush;
138 138
139 139 if (pen == series->pen() || m_force){
140 140 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
141 141 pen.setWidthF(2);
142 142 series->setPen(pen);
143 143 }
144 144
145 145 if (brush == series->brush() || m_force) {
146 146 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
147 147 series->setBrush(brush);
148 148 }
149 149 }
150 150
151 151
152 152 void ChartTheme::decorate(QLineSeries *series,int index)
153 153 {
154 154 QPen pen;
155 155 if(pen == series->pen() || m_force ){
156 156 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
157 157 pen.setWidthF(2);
158 158 series->setPen(pen);
159 159 }
160 160 }
161 161
162 162 void ChartTheme::decorate(QAbstractBarSeries *series, int index)
163 163 {
164 164 QBrush brush;
165 165 QPen pen;
166 166 QList<QBarSet *> sets = series->barSets();
167 167
168 168 qreal takeAtPos = 0.5;
169 169 qreal step = 0.2;
170 170 if (sets.count() > 1 ) {
171 171 step = 1.0 / (qreal) sets.count();
172 172 if (sets.count() % m_seriesGradients.count())
173 173 step *= m_seriesGradients.count();
174 174 else
175 175 step *= (m_seriesGradients.count() - 1);
176 176 }
177 177
178 178 for (int i(0); i < sets.count(); i++) {
179 179 int colorIndex = (index + i) % m_seriesGradients.count();
180 180 if (i > 0 && i % m_seriesGradients.count() == 0) {
181 181 // There is no dedicated base color for each sets, generate more colors
182 182 takeAtPos += step;
183 183 if (takeAtPos == 1.0)
184 184 takeAtPos += step;
185 185 takeAtPos -= (int) takeAtPos;
186 186 }
187 187 if (brush == sets.at(i)->brush() || m_force )
188 188 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
189 189
190 190 // Pick label color from the opposite end of the gradient.
191 191 // 0.3 as a boundary seems to work well.
192 192 if (takeAtPos < 0.3)
193 193 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
194 194 else
195 195 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
196 196
197 197 if (pen == sets.at(i)->pen() || m_force) {
198 198 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
199 199 sets.at(i)->setPen(c);
200 200 }
201 201 }
202 202 }
203 203
204 204 void ChartTheme::decorate(QScatterSeries *series, int index)
205 205 {
206 206 QPen pen;
207 207 QBrush brush;
208 208
209 209 if (pen == series->pen() || m_force) {
210 210 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
211 211 pen.setWidthF(2);
212 212 series->setPen(pen);
213 213 }
214 214
215 215 if (brush == series->brush() || m_force) {
216 216 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
217 217 series->setBrush(brush);
218 218 }
219 219 }
220 220
221 221 void ChartTheme::decorate(QPieSeries *series, int index)
222 222 {
223 223
224 224 for (int i(0); i < series->slices().count(); i++) {
225 225
226 226 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
227 227
228 228 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
229 229 qreal pos = (qreal) (i + 1) / (qreal) series->count();
230 230 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
231 231
232 232 QPieSlice *s = series->slices().at(i);
233 233 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
234 234
235 235 if (d->m_data.m_slicePen.isThemed() || m_force)
236 236 d->setPen(penColor, true);
237 237
238 238 if (d->m_data.m_sliceBrush.isThemed() || m_force)
239 239 d->setBrush(brushColor, true);
240 240
241 241 if (d->m_data.m_labelBrush.isThemed() || m_force)
242 242 d->setLabelBrush(m_labelBrush.color(), true);
243 243
244 244 if (d->m_data.m_labelFont.isThemed() || m_force)
245 245 d->setLabelFont(m_labelFont, true);
246 246 }
247 247 }
248 248
249 249 void ChartTheme::decorate(QSplineSeries *series, int index)
250 250 {
251 251 QPen pen;
252 252 if(pen == series->pen() || m_force){
253 253 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
254 254 pen.setWidthF(2);
255 255 series->setPen(pen);
256 256 }
257 257 }
258 258
259 259 void ChartTheme::decorate(QAbstractAxis *axis,bool axisX)
260 260 {
261 261 QPen pen;
262 262 QBrush brush;
263 263 QFont font;
264 264
265 if (axis->isAxisVisible()) {
265 if (axis->isArrowVisible()) {
266 266
267 267 if(brush == axis->labelsBrush() || m_force){
268 268 axis->setLabelsBrush(m_labelBrush);
269 269 }
270 270 if(pen == axis->labelsPen() || m_force){
271 271 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
272 272 }
273 273
274 274
275 275 if (axis->shadesVisible() || m_force) {
276 276
277 277 if(brush == axis->shadesBrush() || m_force){
278 278 axis->setShadesBrush(m_backgroundShadesBrush);
279 279 }
280 280
281 281 if(pen == axis->shadesPen() || m_force){
282 282 axis->setShadesPen(m_backgroundShadesPen);
283 283 }
284 284
285 285 if( m_force && (m_backgroundShades == BackgroundShadesBoth
286 286 || (m_backgroundShades == BackgroundShadesVertical && axisX)
287 287 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
288 288 axis->setShadesVisible(true);
289 289
290 290 }
291 291 }
292 292
293 293 if(pen == axis->axisPen() || m_force){
294 294 axis->setAxisPen(m_axisLinePen);
295 295 }
296 296
297 297 if(pen == axis->gridLinePen() || m_force){
298 298 axis->setGridLinePen(m_gridLinePen);
299 299 }
300 300
301 301 if(font == axis->labelsFont() || m_force){
302 302 axis->setLabelsFont(m_labelFont);
303 303 }
304 304 }
305 305 }
306 306
307 307 void ChartTheme::generateSeriesGradients()
308 308 {
309 309 // Generate gradients in HSV color space
310 310 foreach (const QColor& color, m_seriesColors) {
311 311 QLinearGradient g;
312 312 qreal h = color.hsvHueF();
313 313 qreal s = color.hsvSaturationF();
314 314
315 315 // TODO: tune the algorithm to give nice results with most base colors defined in
316 316 // most themes. The rest of the gradients we can define manually in theme specific
317 317 // implementation.
318 318 QColor start = color;
319 319 start.setHsvF(h, 0.0, 1.0);
320 320 g.setColorAt(0.0, start);
321 321
322 322 g.setColorAt(0.5, color);
323 323
324 324 QColor end = color;
325 325 end.setHsvF(h, s, 0.25);
326 326 g.setColorAt(1.0, end);
327 327
328 328 m_seriesGradients << g;
329 329 }
330 330 }
331 331
332 332
333 333 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
334 334 {
335 335 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
336 336 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
337 337 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
338 338 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
339 339 QColor c;
340 340 c.setRgbF(r, g, b);
341 341 return c;
342 342 }
343 343
344 344 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
345 345 {
346 346 Q_ASSERT(pos >= 0 && pos <= 1.0);
347 347
348 348 QGradientStops stops = gradient.stops();
349 349 int count = stops.count();
350 350
351 351 // find previous stop relative to position
352 352 QGradientStop prev = stops.first();
353 353 for (int i = 0; i < count; i++) {
354 354 QGradientStop stop = stops.at(i);
355 355 if (pos > stop.first)
356 356 prev = stop;
357 357
358 358 // given position is actually a stop position?
359 359 if (pos == stop.first) {
360 360 //qDebug() << "stop color" << pos;
361 361 return stop.second;
362 362 }
363 363 }
364 364
365 365 // find next stop relative to position
366 366 QGradientStop next = stops.last();
367 367 for (int i = count - 1; i >= 0; i--) {
368 368 QGradientStop stop = stops.at(i);
369 369 if (pos < stop.first)
370 370 next = stop;
371 371 }
372 372
373 373 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
374 374
375 375 qreal range = next.first - prev.first;
376 376 qreal posDelta = pos - prev.first;
377 377 qreal relativePos = posDelta / range;
378 378
379 379 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
380 380
381 381 return colorAt(prev.second, next.second, relativePos);
382 382 }
383 383
384 384 void ChartTheme::setForced(bool enabled)
385 385 {
386 386 m_force=enabled;
387 387 }
388 388
389 389 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now