##// END OF EJS Templates
Adds pimpl for qchartaxis and qchartaxiscategories
Michal Klocek -
r963:1ec42cbed063
parent child
Show More
@@ -0,0 +1,85
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef QCHARTAXIS_P_H_
31 #define QCHARTAXIS_P_H_
32
33 #include "qchartaxis.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QChartAxisPrivate : public QObject
38 {
39 Q_OBJECT
40 public:
41 QChartAxisPrivate(QChartAxis *q);
42 ~QChartAxisPrivate();
43
44 Q_SIGNALS:
45 void updated();
46 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
47
48 public Q_SLOTS:
49 void handleAxisRangeChanged(qreal min, qreal max,int count);
50
51 private:
52 QChartAxis *q_ptr;
53
54 bool m_axisVisible;
55 QPen m_axisPen;
56 QBrush m_axisBrush;
57
58 bool m_gridLineVisible;
59 QPen m_gridLinePen;
60
61 bool m_labelsVisible;
62 QPen m_labelsPen;
63 QBrush m_labelsBrush;
64 QFont m_labelsFont;
65 int m_labelsAngle;
66
67 bool m_shadesVisible;
68 QPen m_shadesPen;
69 QBrush m_shadesBrush;
70 qreal m_shadesOpacity;
71
72 qreal m_min;
73 qreal m_max;
74
75 int m_ticksCount;
76 QChartAxisCategories m_category;
77
78 bool m_niceNumbers;
79
80 friend class QChartAxis;
81 };
82
83 QTCOMMERCIALCHART_END_NAMESPACE
84
85 #endif
@@ -0,0 +1,56
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef QCHARTAXISCATEGORIES_P_H_
31 #define QCHARTAXISCATEGORIES_P_H_
32
33 #include "qchartaxiscategories.h"
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
37 class QChartAxisCategoriesPrivate : public QObject
38 {
39 Q_OBJECT
40 public:
41 QChartAxisCategoriesPrivate(QChartAxisCategories *q);
42 ~QChartAxisCategoriesPrivate();
43
44 Q_SIGNALS:
45 void updated();
46
47 private:
48 QChartAxisCategories *q_ptr;
49 QMap<qreal,QString> m_map;
50 friend class QChartAxisCategories;
51
52 };
53
54 QTCOMMERCIALCHART_END_NAMESPACE
55
56 #endif
@@ -1,464 +1,465
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "axis_p.h"
21 #include "axis_p.h"
22 #include "qchartaxis.h"
22 #include "qchartaxis.h"
23 #include "qchartaxis_p.h"
24 #include "qchartaxiscategories_p.h"
23 #include "chartpresenter_p.h"
25 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
25 #include <QPainter>
27 #include <QPainter>
26 #include <cmath>
28 #include <cmath>
27
29
28 static int label_padding = 5;
30 static int label_padding = 5;
29
31
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
33
32 Axis::Axis(QChartAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter),
34 Axis::Axis(QChartAxis *axis,ChartPresenter *presenter,AxisType type) : Chart(presenter),
33 m_chartAxis(axis),
35 m_chartAxis(axis),
34 m_type(type),
36 m_type(type),
35 m_labelsAngle(0),
37 m_labelsAngle(0),
36 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
38 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
37 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
39 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
38 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
40 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
39 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
41 m_axis(new QGraphicsItemGroup(presenter->rootItem())),
40 m_min(0),
42 m_min(0),
41 m_max(0),
43 m_max(0),
42 m_ticksCount(0)
44 m_ticksCount(0)
43 {
45 {
44 //initial initialization
46 //initial initialization
45 m_axis->setZValue(ChartPresenter::AxisZValue);
47 m_axis->setZValue(ChartPresenter::AxisZValue);
46 m_axis->setHandlesChildEvents(false);
48 m_axis->setHandlesChildEvents(false);
47
49
48 m_shades->setZValue(ChartPresenter::ShadesZValue);
50 m_shades->setZValue(ChartPresenter::ShadesZValue);
49 m_grid->setZValue(ChartPresenter::GridZValue);
51 m_grid->setZValue(ChartPresenter::GridZValue);
50
52
51 connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
53 QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated()));
52 connect(m_chartAxis->categories(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
54 QObject::connect(m_chartAxis->categories()->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisCategoriesUpdated()));
53
55
54 handleAxisUpdated();
56 handleAxisUpdated();
55 }
57 }
56
58
57 Axis::~Axis()
59 Axis::~Axis()
58 {
60 {
59 }
61 }
60
62
61 void Axis::createItems(int count)
63 void Axis::createItems(int count)
62 {
64 {
63
65
64 if (m_axis->children().size() == 0)
66 if (m_axis->children().size() == 0)
65 m_axis->addToGroup(new AxisItem(this));
67 m_axis->addToGroup(new AxisItem(this));
66 for (int i = 0; i < count; ++i) {
68 for (int i = 0; i < count; ++i) {
67 m_grid->addToGroup(new QGraphicsLineItem());
69 m_grid->addToGroup(new QGraphicsLineItem());
68 m_labels->addToGroup(new QGraphicsSimpleTextItem());
70 m_labels->addToGroup(new QGraphicsSimpleTextItem());
69 m_axis->addToGroup(new QGraphicsLineItem());
71 m_axis->addToGroup(new QGraphicsLineItem());
70 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
72 if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem());
71 }
73 }
72 }
74 }
73
75
74 void Axis::deleteItems(int count)
76 void Axis::deleteItems(int count)
75 {
77 {
76 QList<QGraphicsItem *> lines = m_grid->childItems();
78 QList<QGraphicsItem *> lines = m_grid->childItems();
77 QList<QGraphicsItem *> labels = m_labels->childItems();
79 QList<QGraphicsItem *> labels = m_labels->childItems();
78 QList<QGraphicsItem *> shades = m_shades->childItems();
80 QList<QGraphicsItem *> shades = m_shades->childItems();
79 QList<QGraphicsItem *> axis = m_axis->childItems();
81 QList<QGraphicsItem *> axis = m_axis->childItems();
80
82
81 for (int i = 0; i < count; ++i) {
83 for (int i = 0; i < count; ++i) {
82 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
84 if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast());
83 delete(lines.takeLast());
85 delete(lines.takeLast());
84 delete(labels.takeLast());
86 delete(labels.takeLast());
85 delete(axis.takeLast());
87 delete(axis.takeLast());
86 }
88 }
87 }
89 }
88
90
89 void Axis::updateLayout(QVector<qreal> &layout)
91 void Axis::updateLayout(QVector<qreal> &layout)
90 {
92 {
91 if (animator()) {
93 if (animator()) {
92 animator()->updateLayout(this,layout);
94 animator()->updateLayout(this,layout);
93 } else {
95 } else {
94 setLayout(layout);
96 setLayout(layout);
95 }
97 }
96 }
98 }
97
99
98 bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
100 bool Axis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const
99 {
101 {
100 Q_ASSERT(max>=min);
102 Q_ASSERT(max>=min);
101 Q_ASSERT(ticks>1);
103 Q_ASSERT(ticks>1);
102
104
103 QChartAxisCategories* categories = m_chartAxis->categories();
105 QChartAxisCategories* categories = m_chartAxis->categories();
104
106
105 bool category = categories->count()>0;
107 bool category = categories->count()>0;
106
108
107 if (!category) {
109 if (!category) {
108 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
110 int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0);
109 n++;
111 n++;
110 for (int i=0; i< ticks; i++) {
112 for (int i=0; i< ticks; i++) {
111 qreal value = min + (i * (max - min)/ (ticks-1));
113 qreal value = min + (i * (max - min)/ (ticks-1));
112 labels << QString::number(value,'f',n);
114 labels << QString::number(value,'f',n);
113 }
115 }
114 } else {
116 } else {
115 QList<qreal> values = categories->values();
117 QList<qreal> values = categories->values();
116 for (int i=0; i< ticks; i++) {
118 for (int i=0; i< ticks; i++) {
117 qreal value = (min + (i * (max - min)/ (ticks-1)));
119 qreal value = (min + (i * (max - min)/ (ticks-1)));
118 int j=0;
120 int j=0;
119 for (; j<values.count(); j++) {
121 for (; j<values.count(); j++) {
120 if (values.at(j) > value) break;
122 if (values.at(j) > value) break;
121 }
123 }
122 if (j!=0) value=values.at(j-1);
124 if (j!=0) value=values.at(j-1);
123
125
124 QString label = categories->label(value);
126 QString label = categories->label(value);
125 labels << label;
127 labels << label;
126 }
128 }
127 }
129 }
128
130
129 return category;
131 return category;
130 }
132 }
131
133
132 void Axis::setAxisOpacity(qreal opacity)
134 void Axis::setAxisOpacity(qreal opacity)
133 {
135 {
134 m_axis->setOpacity(opacity);
136 m_axis->setOpacity(opacity);
135 }
137 }
136
138
137 qreal Axis::axisOpacity() const
139 qreal Axis::axisOpacity() const
138 {
140 {
139 return m_axis->opacity();
141 return m_axis->opacity();
140 }
142 }
141
143
142 void Axis::setGridOpacity(qreal opacity)
144 void Axis::setGridOpacity(qreal opacity)
143 {
145 {
144 m_grid->setOpacity(opacity);
146 m_grid->setOpacity(opacity);
145 }
147 }
146
148
147 qreal Axis::gridOpacity() const
149 qreal Axis::gridOpacity() const
148 {
150 {
149 return m_grid->opacity();
151 return m_grid->opacity();
150 }
152 }
151
153
152 void Axis::setLabelsOpacity(qreal opacity)
154 void Axis::setLabelsOpacity(qreal opacity)
153 {
155 {
154 m_labels->setOpacity(opacity);
156 m_labels->setOpacity(opacity);
155 }
157 }
156
158
157 qreal Axis::labelsOpacity() const
159 qreal Axis::labelsOpacity() const
158 {
160 {
159 return m_labels->opacity();
161 return m_labels->opacity();
160 }
162 }
161
163
162 void Axis::setShadesOpacity(qreal opacity)
164 void Axis::setShadesOpacity(qreal opacity)
163 {
165 {
164 m_shades->setOpacity(opacity);
166 m_shades->setOpacity(opacity);
165 }
167 }
166
168
167 qreal Axis::shadesOpacity() const
169 qreal Axis::shadesOpacity() const
168 {
170 {
169 return m_shades->opacity();
171 return m_shades->opacity();
170 }
172 }
171
173
172 void Axis::setLabelsAngle(int angle)
174 void Axis::setLabelsAngle(int angle)
173 {
175 {
174 foreach(QGraphicsItem* item , m_labels->childItems()) {
176 foreach(QGraphicsItem* item , m_labels->childItems()) {
175 item->setRotation(angle);
177 item->setRotation(angle);
176 }
178 }
177
179
178 m_labelsAngle=angle;
180 m_labelsAngle=angle;
179 }
181 }
180
182
181 void Axis::setLabelsPen(const QPen &pen)
183 void Axis::setLabelsPen(const QPen &pen)
182 {
184 {
183 foreach(QGraphicsItem* item , m_labels->childItems()) {
185 foreach(QGraphicsItem* item , m_labels->childItems()) {
184 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
186 static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen);
185 }
187 }
186 }
188 }
187
189
188 void Axis::setLabelsBrush(const QBrush &brush)
190 void Axis::setLabelsBrush(const QBrush &brush)
189 {
191 {
190 foreach(QGraphicsItem* item , m_labels->childItems()) {
192 foreach(QGraphicsItem* item , m_labels->childItems()) {
191 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
193 static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush);
192 }
194 }
193 }
195 }
194
196
195 void Axis::setLabelsFont(const QFont &font)
197 void Axis::setLabelsFont(const QFont &font)
196 {
198 {
197 foreach(QGraphicsItem* item , m_labels->childItems()) {
199 foreach(QGraphicsItem* item , m_labels->childItems()) {
198 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
200 static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font);
199 }
201 }
200 }
202 }
201
203
202 void Axis::setShadesBrush(const QBrush &brush)
204 void Axis::setShadesBrush(const QBrush &brush)
203 {
205 {
204 foreach(QGraphicsItem* item , m_shades->childItems()) {
206 foreach(QGraphicsItem* item , m_shades->childItems()) {
205 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
207 static_cast<QGraphicsRectItem*>(item)->setBrush(brush);
206 }
208 }
207 }
209 }
208
210
209 void Axis::setShadesPen(const QPen &pen)
211 void Axis::setShadesPen(const QPen &pen)
210 {
212 {
211 foreach(QGraphicsItem* item , m_shades->childItems()) {
213 foreach(QGraphicsItem* item , m_shades->childItems()) {
212 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
214 static_cast<QGraphicsRectItem*>(item)->setPen(pen);
213 }
215 }
214 }
216 }
215
217
216 void Axis::setAxisPen(const QPen &pen)
218 void Axis::setAxisPen(const QPen &pen)
217 {
219 {
218 foreach(QGraphicsItem* item , m_axis->childItems()) {
220 foreach(QGraphicsItem* item , m_axis->childItems()) {
219 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
221 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
220 }
222 }
221 }
223 }
222
224
223 void Axis::setGridPen(const QPen &pen)
225 void Axis::setGridPen(const QPen &pen)
224 {
226 {
225 foreach(QGraphicsItem* item , m_grid->childItems()) {
227 foreach(QGraphicsItem* item , m_grid->childItems()) {
226 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
228 static_cast<QGraphicsLineItem*>(item)->setPen(pen);
227 }
229 }
228 }
230 }
229
231
230 QVector<qreal> Axis::calculateLayout() const
232 QVector<qreal> Axis::calculateLayout() const
231 {
233 {
232 Q_ASSERT(m_ticksCount>=2);
234 Q_ASSERT(m_ticksCount>=2);
233
235
234 QVector<qreal> points;
236 QVector<qreal> points;
235 points.resize(m_ticksCount);
237 points.resize(m_ticksCount);
236
238
237 switch (m_type)
239 switch (m_type)
238 {
240 {
239 case X_AXIS:
241 case X_AXIS:
240 {
242 {
241 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
243 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
242 for (int i = 0; i < m_ticksCount; ++i) {
244 for (int i = 0; i < m_ticksCount; ++i) {
243 int x = i * deltaX + m_rect.left();
245 int x = i * deltaX + m_rect.left();
244 points[i] = x;
246 points[i] = x;
245 }
247 }
246 }
248 }
247 break;
249 break;
248 case Y_AXIS:
250 case Y_AXIS:
249 {
251 {
250 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
252 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
251 for (int i = 0; i < m_ticksCount; ++i) {
253 for (int i = 0; i < m_ticksCount; ++i) {
252 int y = i * -deltaY + m_rect.bottom();
254 int y = i * -deltaY + m_rect.bottom();
253 points[i] = y;
255 points[i] = y;
254 }
256 }
255 }
257 }
256 break;
258 break;
257 }
259 }
258 return points;
260 return points;
259 }
261 }
260
262
261 void Axis::setLayout(QVector<qreal> &layout)
263 void Axis::setLayout(QVector<qreal> &layout)
262 {
264 {
263 int diff = m_layoutVector.size() - layout.size();
265 int diff = m_layoutVector.size() - layout.size();
264
266
265 if (diff>0) {
267 if (diff>0) {
266 deleteItems(diff);
268 deleteItems(diff);
267 } else if (diff<0) {
269 } else if (diff<0) {
268 createItems(-diff);
270 createItems(-diff);
269 }
271 }
270
272
271 if( diff!=0) handleAxisUpdated();
273 if( diff!=0) handleAxisUpdated();
272
274
273 QStringList ticksList;
275 QStringList ticksList;
274
276
275 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
277 bool categories = createLabels(ticksList,m_min,m_max,layout.size());
276
278
277 QList<QGraphicsItem *> lines = m_grid->childItems();
279 QList<QGraphicsItem *> lines = m_grid->childItems();
278 QList<QGraphicsItem *> labels = m_labels->childItems();
280 QList<QGraphicsItem *> labels = m_labels->childItems();
279 QList<QGraphicsItem *> shades = m_shades->childItems();
281 QList<QGraphicsItem *> shades = m_shades->childItems();
280 QList<QGraphicsItem *> axis = m_axis->childItems();
282 QList<QGraphicsItem *> axis = m_axis->childItems();
281
283
282 Q_ASSERT(labels.size() == ticksList.size());
284 Q_ASSERT(labels.size() == ticksList.size());
283 Q_ASSERT(layout.size() == ticksList.size());
285 Q_ASSERT(layout.size() == ticksList.size());
284
286
285 qreal minWidth = 0;
287 qreal minWidth = 0;
286 qreal minHeight = 0;
288 qreal minHeight = 0;
287
289
288 switch (m_type)
290 switch (m_type)
289 {
291 {
290 case X_AXIS:
292 case X_AXIS:
291 {
293 {
292 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
294 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
293 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
295 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
294
296
295 for (int i = 0; i < layout.size(); ++i) {
297 for (int i = 0; i < layout.size(); ++i) {
296 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
298 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
297 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
299 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
298 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
300 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
299 if (!categories || i<1) {
301 if (!categories || i<1) {
300 labelItem->setText(ticksList.at(i));
302 labelItem->setText(ticksList.at(i));
301 const QRectF& rect = labelItem->boundingRect();
303 const QRectF& rect = labelItem->boundingRect();
302 minWidth+=rect.width();
304 minWidth+=rect.width();
303 minHeight=qMax(rect.height(),minHeight);
305 minHeight=qMax(rect.height(),minHeight);
304 QPointF center = rect.center();
306 QPointF center = rect.center();
305 labelItem->setTransformOriginPoint(center.x(), center.y());
307 labelItem->setTransformOriginPoint(center.x(), center.y());
306 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
308 labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding);
307 } else {
309 } else {
308 labelItem->setText(ticksList.at(i));
310 labelItem->setText(ticksList.at(i));
309 const QRectF& rect = labelItem->boundingRect();
311 const QRectF& rect = labelItem->boundingRect();
310 minWidth+=rect.width();
312 minWidth+=rect.width();
311 minHeight=qMax(rect.height()+label_padding,minHeight);
313 minHeight=qMax(rect.height()+label_padding,minHeight);
312 QPointF center = rect.center();
314 QPointF center = rect.center();
313 labelItem->setTransformOriginPoint(center.x(), center.y());
315 labelItem->setTransformOriginPoint(center.x(), center.y());
314 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
316 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
315 }
317 }
316
318
317 if ((i+1)%2 && i>1) {
319 if ((i+1)%2 && i>1) {
318 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
320 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
319 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
321 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
320 }
322 }
321 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
323 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
322 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
324 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
323 }
325 }
324
326
325 }
327 }
326 break;
328 break;
327
329
328 case Y_AXIS:
330 case Y_AXIS:
329 {
331 {
330 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
332 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
331 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
333 lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom());
332
334
333 for (int i = 0; i < layout.size(); ++i) {
335 for (int i = 0; i < layout.size(); ++i) {
334 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
336 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
335 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
337 lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]);
336 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
338 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
337
339
338 if (!categories || i<1) {
340 if (!categories || i<1) {
339 labelItem->setText(ticksList.at(i));
341 labelItem->setText(ticksList.at(i));
340 const QRectF& rect = labelItem->boundingRect();
342 const QRectF& rect = labelItem->boundingRect();
341 minWidth=qMax(rect.width()+label_padding,minWidth);
343 minWidth=qMax(rect.width()+label_padding,minWidth);
342 minHeight+=rect.height();
344 minHeight+=rect.height();
343 QPointF center = rect.center();
345 QPointF center = rect.center();
344 labelItem->setTransformOriginPoint(center.x(), center.y());
346 labelItem->setTransformOriginPoint(center.x(), center.y());
345 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
347 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y());
346 } else {
348 } else {
347 labelItem->setText(ticksList.at(i));
349 labelItem->setText(ticksList.at(i));
348 const QRectF& rect = labelItem->boundingRect();
350 const QRectF& rect = labelItem->boundingRect();
349 minWidth=qMax(rect.width(),minWidth);
351 minWidth=qMax(rect.width(),minWidth);
350 minHeight+=rect.height();
352 minHeight+=rect.height();
351 QPointF center = rect.center();
353 QPointF center = rect.center();
352 labelItem->setTransformOriginPoint(center.x(), center.y());
354 labelItem->setTransformOriginPoint(center.x(), center.y());
353 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
355 labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y());
354 }
356 }
355
357
356 if ((i+1)%2 && i>1) {
358 if ((i+1)%2 && i>1) {
357 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
359 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
358 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
360 rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]);
359 }
361 }
360 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
362 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
361 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
363 lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]);
362 }
364 }
363 }
365 }
364 break;
366 break;
365 default:
367 default:
366 qDebug()<<"Unknown axis type";
368 qDebug()<<"Unknown axis type";
367 break;
369 break;
368 }
370 }
369
371
370 m_layoutVector=layout;
372 m_layoutVector=layout;
371
373
372 presenter()->setMinimumMarginWidth(this,minWidth);
374 presenter()->setMinimumMarginWidth(this,minWidth);
373 presenter()->setMinimumMarginHeight(this,minHeight);
375 presenter()->setMinimumMarginHeight(this,minHeight);
374
376
375 }
377 }
376
378
377 bool Axis::isEmpty()
379 bool Axis::isEmpty()
378 {
380 {
379 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0;
381 return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0;
380 }
382 }
381
383
382 //handlers
384 //handlers
383
385
384 void Axis::handleAxisCategoriesUpdated()
386 void Axis::handleAxisCategoriesUpdated()
385 {
387 {
386 if (isEmpty()) return;
388 if (isEmpty()) return;
387 updateLayout(m_layoutVector);
389 updateLayout(m_layoutVector);
388 }
390 }
389
391
390 void Axis::handleAxisUpdated()
392 void Axis::handleAxisUpdated()
391 {
393 {
392
394
393 if (isEmpty()) return;
395 if (isEmpty()) return;
394
396
395 if (m_chartAxis->isAxisVisible()) {
397 if (m_chartAxis->isAxisVisible()) {
396 setAxisOpacity(100);
398 setAxisOpacity(100);
397 } else {
399 } else {
398 setAxisOpacity(0);
400 setAxisOpacity(0);
399 }
401 }
400
402
401 if (m_chartAxis->isGridLineVisible()) {
403 if (m_chartAxis->isGridLineVisible()) {
402 setGridOpacity(100);
404 setGridOpacity(100);
403 } else {
405 } else {
404 setGridOpacity(0);
406 setGridOpacity(0);
405 }
407 }
406
408
407 if (m_chartAxis->labelsVisible()) {
409 if (m_chartAxis->labelsVisible()) {
408 setLabelsOpacity(100);
410 setLabelsOpacity(100);
409 } else {
411 } else {
410 setLabelsOpacity(0);
412 setLabelsOpacity(0);
411 }
413 }
412
414
413 if (m_chartAxis->shadesVisible()) {
415 if (m_chartAxis->shadesVisible()) {
414 setShadesOpacity(m_chartAxis->shadesOpacity());
416 setShadesOpacity(m_chartAxis->shadesOpacity());
415 } else {
417 } else {
416 setShadesOpacity(0);
418 setShadesOpacity(0);
417 }
419 }
418
420
419 setLabelsAngle(m_chartAxis->labelsAngle());
421 setLabelsAngle(m_chartAxis->labelsAngle());
420 setAxisPen(m_chartAxis->axisPen());
422 setAxisPen(m_chartAxis->axisPen());
421 setLabelsPen(m_chartAxis->labelsPen());
423 setLabelsPen(m_chartAxis->labelsPen());
422 setLabelsBrush(m_chartAxis->labelsBrush());
424 setLabelsBrush(m_chartAxis->labelsBrush());
423 setLabelsFont(m_chartAxis->labelsFont());
425 setLabelsFont(m_chartAxis->labelsFont());
424 setGridPen(m_chartAxis->gridLinePen());
426 setGridPen(m_chartAxis->gridLinePen());
425 setShadesPen(m_chartAxis->shadesPen());
427 setShadesPen(m_chartAxis->shadesPen());
426 setShadesBrush(m_chartAxis->shadesBrush());
428 setShadesBrush(m_chartAxis->shadesBrush());
427
429
428 }
430 }
429
431
430 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
432 void Axis::handleRangeChanged(qreal min, qreal max,int tickCount)
431 {
433 {
432 if (qFuzzyIsNull(min - max) || tickCount < 2)
434 if (qFuzzyIsNull(min - max) || tickCount < 2)
433 return;
435 return;
434
436
435 m_min = min;
437 m_min = min;
436 m_max = max;
438 m_max = max;
437 m_ticksCount= tickCount;
439 m_ticksCount= tickCount;
438
440
439 if (isEmpty()) return;
441 if (isEmpty()) return;
440 QVector<qreal> layout = calculateLayout();
442 QVector<qreal> layout = calculateLayout();
441 updateLayout(layout);
443 updateLayout(layout);
442
444
443 }
445 }
444
446
445 void Axis::handleGeometryChanged(const QRectF &rect)
447 void Axis::handleGeometryChanged(const QRectF &rect)
446 {
448 {
447 if(m_rect != rect)
449 if(m_rect != rect)
448 {
450 {
449 m_rect = rect;
451 m_rect = rect;
450 if (isEmpty()) return;
452 if (isEmpty()) return;
451 QVector<qreal> layout = calculateLayout();
453 QVector<qreal> layout = calculateLayout();
452 updateLayout(layout);
454 updateLayout(layout);
453 }
455 }
454 }
456 }
455
457
456 void Axis::axisSelected()
458 void Axis::axisSelected()
457 {
459 {
458 qDebug()<<"TODO axis clicked";
460 qDebug()<<"TODO: axis clicked";
459 }
461 }
460
462
461 //TODO "nice numbers algorithm"
462 #include "moc_axis_p.cpp"
463 #include "moc_axis_p.cpp"
463
464
464 QTCOMMERCIALCHART_END_NAMESPACE
465 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,14 +1,16
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/axis.cpp \
5 $$PWD/axis.cpp \
6 $$PWD/qchartaxis.cpp \
6 $$PWD/qchartaxis.cpp \
7 $$PWD/qchartaxiscategories.cpp
7 $$PWD/qchartaxiscategories.cpp
8
8
9 PRIVATE_HEADERS += \
9 PRIVATE_HEADERS += \
10 $$PWD/axis_p.h
10 $$PWD/axis_p.h \
11 $$PWD/qchartaxis_p.h \
12 $$PWD/qchartaxiscategories_p.h
11
13
12 PUBLIC_HEADERS += \
14 PUBLIC_HEADERS += \
13 $$PWD/qchartaxis.h \
15 $$PWD/qchartaxis.h \
14 $$PWD/qchartaxiscategories.h No newline at end of file
16 $$PWD/qchartaxiscategories.h
@@ -1,444 +1,545
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchartaxis.h"
21 #include "qchartaxis.h"
22 #include "qchartaxis_p.h"
22
23
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
25
25 /*!
26 /*!
26 \class QChartAxis
27 \class QChartAxis
27 \brief The QChartAxis class is used for manipulating chart's axis
28 \brief The QChartAxis class is used for manipulating chart's axis
28 and for adding optional axes to the chart.
29 and for adding optional axes to the chart.
29 \mainclass
30 \mainclass
30
31
31 There is only one x Axis, however there can be multiple y axes.
32 There is only one x Axis, however there can be multiple y axes.
32 Each chart series can be bound to exactly one Y axis and the share common X axis.
33 Each chart series can be bound to exactly one Y axis and the share common X axis.
33 Axis can be setup to show axis line with ticks, gird lines and shades.
34 Axis can be setup to show axis line with ticks, gird lines and shades.
34
35
35 */
36 */
36
37
37 /*!
38 /*!
38 \fn bool QChartAxis::isAxisVisible() const
39 \fn bool QChartAxis::isAxisVisible() const
39 \brief Returns if axis is visible
40 \brief Returns if axis is visible
40 \sa setAxisVisible()
41 \sa setAxisVisible()
41 */
42 */
42
43
43 /*!
44 /*!
44 \fn QPen QChartAxis::axisPen() const
45 \fn QPen QChartAxis::axisPen() const
45 \brief Returns pen used to draw axis and ticks.
46 \brief Returns pen used to draw axis and ticks.
46 \sa setAxisPen()
47 \sa setAxisPen()
47 */
48 */
48
49
49
50
50 /*!
51 /*!
51 \fn bool QChartAxis::isGridLineVisible() const
52 \fn bool QChartAxis::isGridLineVisible() const
52 \brief Returns if grid is visible
53 \brief Returns if grid is visible
53 \sa setGridLineVisible()
54 \sa setGridLineVisible()
54 */
55 */
55
56
56 /*!
57 /*!
57 \fn QPen QChartAxis::gridLinePen() const
58 \fn QPen QChartAxis::gridLinePen() const
58 \brief Returns pen used to draw grid.
59 \brief Returns pen used to draw grid.
59 \sa setGridLinePen()
60 \sa setGridLinePen()
60 */
61 */
61
62
62 /*!
63 /*!
63 \fn bool QChartAxis::labelsVisible() const
64 \fn bool QChartAxis::labelsVisible() const
64 \brief Returns if grid is visible
65 \brief Returns if grid is visible
65 \sa setLabelsVisible()
66 \sa setLabelsVisible()
66 */
67 */
67
68
68 /*!
69 /*!
69 \fn QPen QChartAxis::labelsPen() const
70 \fn QPen QChartAxis::labelsPen() const
70 \brief Returns the pen used to labels.
71 \brief Returns the pen used to labels.
71 \sa setLabelsPen()
72 \sa setLabelsPen()
72 */
73 */
73
74
74 /*!
75 /*!
75 \fn QBrush QChartAxis::labelsBrush() const
76 \fn QBrush QChartAxis::labelsBrush() const
76 \brief Returns brush used to draw labels.
77 \brief Returns brush used to draw labels.
77 \sa setLabelsBrush()
78 \sa setLabelsBrush()
78 */
79 */
79
80
80 /*!
81 /*!
81 \fn QFont QChartAxis::labelsFont() const
82 \fn QFont QChartAxis::labelsFont() const
82 \brief Returns font used to draw labels.
83 \brief Returns font used to draw labels.
83 \sa setLabelsFont()
84 \sa setLabelsFont()
84 */
85 */
85
86
86 /*!
87 /*!
87 \fn QFont QChartAxis::labelsAngle() const
88 \fn QFont QChartAxis::labelsAngle() const
88 \brief Returns angle used to draw labels.
89 \brief Returns angle used to draw labels.
89 \sa setLabelsAngle()
90 \sa setLabelsAngle()
90 */
91 */
91
92
92 /*!
93 /*!
93 \fn bool QChartAxis::shadesVisible() const
94 \fn bool QChartAxis::shadesVisible() const
94 \brief Returns if shades are visible.
95 \brief Returns if shades are visible.
95 \sa setShadesVisible()
96 \sa setShadesVisible()
96 */
97 */
97
98
98 /*!
99 /*!
99 \fn qreal QChartAxis::shadesOpacity() const
100 \fn qreal QChartAxis::shadesOpacity() const
100 \brief Returns opacity of shades.
101 \brief Returns opacity of shades.
101 */
102 */
102
103
103 /*!
104 /*!
104 \fn QPen QChartAxis::shadesPen() const
105 \fn QPen QChartAxis::shadesPen() const
105 \brief Returns pen used to draw shades.
106 \brief Returns pen used to draw shades.
106 \sa setShadesPen()
107 \sa setShadesPen()
107 */
108 */
108
109
109 /*!
110 /*!
110 \fn QBrush QChartAxis::shadesBrush() const
111 \fn QBrush QChartAxis::shadesBrush() const
111 \brief Returns brush used to draw shades.
112 \brief Returns brush used to draw shades.
112 \sa setShadesBrush()
113 \sa setShadesBrush()
113 */
114 */
114
115
115 /*!
116 /*!
116 \fn qreal QChartAxis::min() const
117 \fn qreal QChartAxis::min() const
117 \brief Returns minimum value on the axis.
118 \brief Returns minimum value on the axis.
118 \sa setMin()
119 \sa setMin()
119 */
120 */
120
121
121 /*!
122 /*!
122 \fn qreal QChartAxis::max() const
123 \fn qreal QChartAxis::max() const
123 \brief Returns maximim value on the axis.
124 \brief Returns maximim value on the axis.
124 \sa setMax()
125 \sa setMax()
125 */
126 */
126
127
127 /*!
128 /*!
128 \fn void QChartAxis::minChanged(qreal min)
129 \fn void QChartAxis::minChanged(qreal min)
129 \brief Axis emits signal when \a min of axis has changed.
130 \brief Axis emits signal when \a min of axis has changed.
130 */
131 */
131
132
132 /*!
133 /*!
133 \fn void QChartAxis::maxChanged(qreal max)
134 \fn void QChartAxis::maxChanged(qreal max)
134 \brief Axis emits signal when \a max of axis has changed.
135 \brief Axis emits signal when \a max of axis has changed.
135 */
136 */
136
137
137 /*!
138 /*!
138 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
139 \fn void QChartAxis::rangeChanged(qreal min, qreal max)
139 \brief Axis emits signal when \a min or \a max of axis has changed.
140 \brief Axis emits signal when \a min or \a max of axis has changed.
140 */
141 */
141
142
142 /*!
143 /*!
143 \fn int QChartAxis::ticksCount() const
144 \fn int QChartAxis::ticksCount() const
144 \brief Return number of ticks on the axis
145 \brief Return number of ticks on the axis
145 \sa setTicksCount()
146 \sa setTicksCount()
146 */
147 */
147
148
148 /*!
149 /*!
149 \fn void QChartAxis::updated()
150 \fn void QChartAxis::updated()
150 \brief \internal
151 \brief \internal
151 */
152 */
152
153
153 /*!
154 /*!
154 \fn void QChartAxis::changed(qreal min, qreal max, int tickCount,bool niceNumbers)
155 \fn void QChartAxis::changed(qreal min, qreal max, int tickCount,bool niceNumbers)
155 \brief \internal
156 \brief \internal
156 */
157 */
157
158
158 /*!
159 /*!
159 \fn bool QChartAxis::niceNumbers() const
160 \fn bool QChartAxis::niceNumbers() const
160 \brief Returns whether nice numbers are enabled or not.
161 \brief Returns whether nice numbers are enabled or not.
161 */
162 */
162
163
163 /*!
164 /*!
164 \fn QChartAxisCategories* QChartAxis::categories()
165 \fn QChartAxisCategories* QChartAxis::categories()
165 \brief Returns pointer to the list of categories which correspond to the values on the axis.
166 \brief Returns pointer to the list of categories which correspond to the values on the axis.
166 */
167 */
167
168
168 /*!
169 /*!
169 \fn void QChartAxis::ticksCountChanged(int count)
170 \fn void QChartAxis::ticksCountChanged(int count)
170 \brief Emits the new \a count of ticks on the axis
171 \brief Emits the new \a count of ticks on the axis
171 Signal is emitted when the number of the ticks on the axis has been changed to a different value.
172 Signal is emitted when the number of the ticks on the axis has been changed to a different value.
172 Parementer count\a count is the new number of ticks on the axis.
173 Parementer count\a count is the new number of ticks on the axis.
173 */
174 */
174
175
175 /*!
176 /*!
176 Constructs new axis object which is a child of \a parent. Ownership is taken by
177 Constructs new axis object which is a child of \a parent. Ownership is taken by
177 QChatView or QChart when axis added.
178 QChatView or QChart when axis added.
178 */
179 */
179
180
180 QChartAxis::QChartAxis(QObject *parent) : QObject(parent),
181 QChartAxis::QChartAxis(QObject *parent) : QObject(parent),
181 m_axisVisible(true),
182 d_ptr(new QChartAxisPrivate(this))
182 m_gridLineVisible(true),
183 m_labelsVisible(true),
184 m_labelsAngle(0),
185 m_shadesVisible(false),
186 m_shadesOpacity(1.0),
187 m_min(0),
188 m_max(0),
189 m_ticksCount(5),
190 m_niceNumbers(false)
191 {
183 {
192
184
193 }
185 }
194
186
195 /*!
187 /*!
196 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
188 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
197 */
189 */
198
190
199 QChartAxis::~QChartAxis()
191 QChartAxis::~QChartAxis()
200 {
192 {
201 }
193 }
202
194
203 /*!
195 /*!
204 Sets \a pen used to draw axis line and ticks.
196 Sets \a pen used to draw axis line and ticks.
205 */
197 */
206 void QChartAxis::setAxisPen(const QPen &pen)
198 void QChartAxis::setAxisPen(const QPen &pen)
207 {
199 {
208 if (pen != m_axisPen) {
200 if (d_ptr->m_axisPen!=pen) {
209 m_axisPen = pen;
201 d_ptr->m_axisPen = pen;
210 emit updated();
202 emit d_ptr->updated();
203 }
211 }
204 }
205
206 QPen QChartAxis::axisPen() const
207 {
208 return d_ptr->m_axisPen;
212 }
209 }
213
210
214 /*!
211 /*!
215 Sets if axis and ticks are \a visible.
212 Sets if axis and ticks are \a visible.
216 */
213 */
217 void QChartAxis::setAxisVisible(bool visible)
214 void QChartAxis::setAxisVisible(bool visible)
218 {
215 {
219 if (m_axisVisible != visible) {
216 if (d_ptr->m_axisVisible != visible) {
220 m_axisVisible = visible;
217 d_ptr->m_axisVisible = visible;
221 emit updated();
218 emit d_ptr->updated();
219 }
222 }
220 }
221
222 bool QChartAxis::isAxisVisible() const
223 {
224 return d_ptr->m_axisVisible;
223 }
225 }
224
226
225 /*!
227 /*!
226 Sets if grid line is \a visible.
228 Sets if grid line is \a visible.
227 */
229 */
228 void QChartAxis::setGridLineVisible(bool visible)
230 void QChartAxis::setGridLineVisible(bool visible)
229 {
231 {
230 if (m_gridLineVisible != visible) {
232 if (d_ptr->m_gridLineVisible != visible) {
231 m_gridLineVisible = visible;
233 d_ptr->m_gridLineVisible = visible;
232 emit updated();
234 emit d_ptr->updated();
233 }
235 }
234 }
236 }
235
237
238 bool QChartAxis::isGridLineVisible() const
239 {
240 return d_ptr->m_gridLineVisible;
241 }
236 /*!
242 /*!
237 Sets \a pen used to draw grid line.
243 Sets \a pen used to draw grid line.
238 */
244 */
239 void QChartAxis::setGridLinePen(const QPen &pen)
245 void QChartAxis::setGridLinePen(const QPen &pen)
240 {
246 {
241 if (m_gridLinePen != pen) {
247 if (d_ptr->m_gridLinePen != pen) {
242 m_gridLinePen = pen;
248 d_ptr->m_gridLinePen = pen;
243 emit updated();
249 emit d_ptr->updated();
244 }
250 }
245 }
251 }
246
252
253 QPen QChartAxis::gridLinePen() const
254 {
255 return d_ptr->m_gridLinePen;
256 }
257
247 /*!
258 /*!
248 Sets if axis' labels are \a visible.
259 Sets if axis' labels are \a visible.
249 */
260 */
250 void QChartAxis::setLabelsVisible(bool visible)
261 void QChartAxis::setLabelsVisible(bool visible)
251 {
262 {
252 if (m_labelsVisible != visible) {
263 if (d_ptr->m_labelsVisible != visible) {
253 m_labelsVisible = visible;
264 d_ptr->m_labelsVisible = visible;
254 emit updated();
265 emit d_ptr->updated();
255 }
266 }
256 }
267 }
257
268
269 bool QChartAxis::labelsVisible() const
270 {
271 return d_ptr->m_labelsVisible;
272 }
258 /*!
273 /*!
259 Sets \a pen used to draw labels.
274 Sets \a pen used to draw labels.
260 */
275 */
261 void QChartAxis::setLabelsPen(const QPen &pen)
276 void QChartAxis::setLabelsPen(const QPen &pen)
262 {
277 {
263 if (m_labelsPen != pen) {
278 if (d_ptr->m_labelsPen != pen) {
264 m_labelsPen = pen;
279 d_ptr->m_labelsPen = pen;
265 emit updated();
280 emit d_ptr->updated();
281 }
266 }
282 }
283
284 QPen QChartAxis::labelsPen() const
285 {
286 return d_ptr->m_labelsPen;
267 }
287 }
268
288
269 /*!
289 /*!
270 Sets \a brush used to draw labels.
290 Sets \a brush used to draw labels.
271 */
291 */
272 void QChartAxis::setLabelsBrush(const QBrush &brush)
292 void QChartAxis::setLabelsBrush(const QBrush &brush)
273 {
293 {
274 if (m_labelsBrush != brush) {
294 if (d_ptr->m_labelsBrush != brush) {
275 m_labelsBrush = brush;
295 d_ptr->m_labelsBrush = brush;
276 emit updated();
296 emit d_ptr->updated();
277 }
297 }
278 }
298 }
279
299
300 QBrush QChartAxis::labelsBrush() const
301 {
302 return d_ptr->m_labelsBrush;
303 }
304
280 /*!
305 /*!
281 Sets \a font used to draw labels.
306 Sets \a font used to draw labels.
282 */
307 */
283 void QChartAxis::setLabelsFont(const QFont &font)
308 void QChartAxis::setLabelsFont(const QFont &font)
284 {
309 {
285 if (m_labelsFont != font) {
310 if (d_ptr->m_labelsFont != font) {
286 m_labelsFont = font;
311 d_ptr->m_labelsFont = font;
287 emit updated();
312 emit d_ptr->updated();
288 }
313 }
289 }
314 }
290
315
316 QFont QChartAxis::labelsFont() const
317 {
318 return d_ptr->m_labelsFont;
319 }
320
291 /*!
321 /*!
292 Sets \a angle for all the labels on given axis.
322 Sets \a angle for all the labels on given axis.
293 */
323 */
294 void QChartAxis::setLabelsAngle(int angle)
324 void QChartAxis::setLabelsAngle(int angle)
295 {
325 {
296 if (m_labelsAngle != angle) {
326 if (d_ptr->m_labelsAngle != angle) {
297 m_labelsAngle = angle;
327 d_ptr->m_labelsAngle = angle;
298 emit updated();
328 emit d_ptr->updated();
329 }
299 }
330 }
331
332 int QChartAxis::labelsAngle() const
333 {
334 return d_ptr->m_labelsAngle;
300 }
335 }
301
336
302 /*!
337 /*!
303 Sets if shades are \a visible.
338 Sets if shades are \a visible.
304 */
339 */
305 void QChartAxis::setShadesVisible(bool visible)
340 void QChartAxis::setShadesVisible(bool visible)
306 {
341 {
307 if (m_shadesVisible != visible) {
342 if (d_ptr->m_shadesVisible != visible) {
308 m_shadesVisible = visible;
343 d_ptr->m_shadesVisible = visible;
309 emit updated();
344 emit d_ptr->updated();
345 }
310 }
346 }
347
348 bool QChartAxis::shadesVisible() const
349 {
350 return d_ptr->m_shadesVisible;
311 }
351 }
312
352
313 /*!
353 /*!
314 Sets \a pen used to draw shades.
354 Sets \a pen used to draw shades.
315 */
355 */
316 void QChartAxis::setShadesPen(const QPen &pen)
356 void QChartAxis::setShadesPen(const QPen &pen)
317 {
357 {
318 if (m_shadesPen != pen) {
358 if (d_ptr->m_shadesPen != pen) {
319 m_shadesPen = pen;
359 d_ptr->m_shadesPen = pen;
320 emit updated();
360 emit d_ptr->updated();
321 }
361 }
322 }
362 }
323
363
364 QPen QChartAxis::shadesPen() const
365 {
366 return d_ptr->m_shadesPen;
367 }
368
324 /*!
369 /*!
325 Sets \a brush used to draw shades.
370 Sets \a brush used to draw shades.
326 */
371 */
327 void QChartAxis::setShadesBrush(const QBrush &brush)
372 void QChartAxis::setShadesBrush(const QBrush &brush)
328 {
373 {
329 if (m_shadesBrush != brush) {
374 if (d_ptr->m_shadesBrush != brush) {
330 m_shadesBrush = brush;
375 d_ptr->m_shadesBrush = brush;
331 emit updated();
376 emit d_ptr->updated();
377 }
332 }
378 }
379
380 QBrush QChartAxis::shadesBrush() const
381 {
382 return d_ptr->m_shadesBrush;
333 }
383 }
334
384
335 /*!
385 /*!
336 Sets \a opacity of the shades.
386 Sets \a opacity of the shades.
337 */
387 */
338 void QChartAxis::setShadesOpacity(qreal opacity)
388 void QChartAxis::setShadesOpacity(qreal opacity)
339 {
389 {
340 if (m_shadesOpacity != opacity) {
390 if (d_ptr->m_shadesOpacity != opacity) {
341 m_shadesOpacity=opacity;
391 d_ptr->m_shadesOpacity=opacity;
342 emit updated();
392 emit d_ptr->updated();
343 }
393 }
344 }
394 }
345
395
396 qreal QChartAxis::shadesOpacity() const
397 {
398 return d_ptr->m_shadesOpacity;
399 }
400
346 /*!
401 /*!
347 Sets \a min value on the axis.
402 Sets \a min value on the axis.
348 */
403 */
349 void QChartAxis::setMin(qreal min)
404 void QChartAxis::setMin(qreal min)
350 {
405 {
351 setRange(min,m_max);
406 setRange(min,d_ptr->m_max);
407 }
408
409 qreal QChartAxis::min() const
410 {
411 return d_ptr->m_min;
352 }
412 }
353
413
354 /*!
414 /*!
355 Sets \a max value on the axis.
415 Sets \a max value on the axis.
356 */
416 */
357 void QChartAxis::setMax(qreal max)
417 void QChartAxis::setMax(qreal max)
358 {
418 {
359 setRange(m_min,max);
419 setRange(d_ptr->m_min,max);
420 }
421
422 qreal QChartAxis::max() const
423 {
424 return d_ptr->m_max;
360 }
425 }
361
426
362 /*!
427 /*!
363 Sets range from \a min to \a max on the axis.
428 Sets range from \a min to \a max on the axis.
364 */
429 */
365 void QChartAxis::setRange(qreal min, qreal max)
430 void QChartAxis::setRange(qreal min, qreal max)
366 {
431 {
367 bool changed = false;
432 bool changed = false;
368 if (!qFuzzyIsNull(m_min - min)) {
433 if (!qFuzzyIsNull(d_ptr->m_min - min)) {
369 m_min = min;
434 d_ptr->m_min = min;
370 changed = true;
435 changed = true;
371 emit minChanged(min);
436 emit minChanged(min);
372 }
437 }
373
438
374 if (!qFuzzyIsNull(m_max - max)) {
439 if (!qFuzzyIsNull(d_ptr->m_max - max)) {
375 m_max = max;
440 d_ptr->m_max = max;
376 changed = true;
441 changed = true;
377 emit maxChanged(max);
442 emit maxChanged(max);
378 }
443 }
379
444
380 if (changed) {
445 if (changed) {
381 emit rangeChanged(m_min,m_max);
446 emit rangeChanged(d_ptr->m_min,d_ptr->m_max);
382 emit this->changed(m_min, m_max, m_ticksCount, m_niceNumbers);
447 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
383 }
448 }
384 }
449 }
385
450
386 /*!
451 /*!
387 Sets \a count for ticks on the axis.
452 Sets \a count for ticks on the axis.
388 */
453 */
389 void QChartAxis::setTicksCount(int count)
454 void QChartAxis::setTicksCount(int count)
390 {
455 {
391 if (m_ticksCount != count) {
456 if (d_ptr->m_ticksCount != count) {
392 m_ticksCount = count;
457 d_ptr->m_ticksCount = count;
393 emit ticksCountChanged(count);
458 emit ticksCountChanged(count);
394 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
459 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
395 }
460 }
396 }
461 }
397
462
463 int QChartAxis::ticksCount() const
464 {
465 return d_ptr->m_ticksCount;
466 }
467
398 /*!
468 /*!
399 Sets axis, shades, labels and grid lines to be visible.
469 Sets axis, shades, labels and grid lines to be visible.
400 */
470 */
401 void QChartAxis::show()
471 void QChartAxis::show()
402 {
472 {
403 m_axisVisible=true;
473 d_ptr->m_axisVisible=true;
404 m_gridLineVisible=true;
474 d_ptr->m_gridLineVisible=true;
405 m_labelsVisible=true;
475 d_ptr->m_labelsVisible=true;
406 m_shadesVisible=true;
476 d_ptr->m_shadesVisible=true;
407 emit updated();
477 emit d_ptr->updated();
408 }
478 }
409
479
410 /*!
480 /*!
411 Sets axis, shades, labels and grid lines to not be visible.
481 Sets axis, shades, labels and grid lines to not be visible.
412 */
482 */
413 void QChartAxis::hide()
483 void QChartAxis::hide()
414 {
484 {
415 m_axisVisible = false;
485 d_ptr->m_axisVisible = false;
416 m_gridLineVisible = false;
486 d_ptr->m_gridLineVisible = false;
417 m_labelsVisible = false;
487 d_ptr->m_labelsVisible = false;
418 m_shadesVisible = false;
488 d_ptr->m_shadesVisible = false;
419 emit updated();
489 emit d_ptr->updated();
420 }
490 }
421
491
422 /*!
492 /*!
423 \internal
493 Sets the nice numbers state to \a enable
424 */
494 */
425 void QChartAxis::handleAxisRangeChanged(qreal min, qreal max,int count)
495 void QChartAxis::setNiceNumbers(bool enable)
426 {
496 {
427 setRange(min,max);
497 if (d_ptr->m_niceNumbers != enable){
428 setTicksCount(count);
498 d_ptr->m_niceNumbers = enable;
499 emit d_ptr->changed(d_ptr->m_min, d_ptr->m_max, d_ptr->m_ticksCount, d_ptr->m_niceNumbers);
500 }
429 }
501 }
430
502
431 /*!
503 bool QChartAxis::niceNumbers() const
432 Sets the nice numbers state to \a enable
504 {
433 */
505 return d_ptr->m_niceNumbers;
434 void QChartAxis::setNiceNumbers(bool enable)
506 }
507
508 QChartAxisCategories* QChartAxis::categories()
435 {
509 {
436 if (m_niceNumbers != enable){
510 return &d_ptr->m_category;
437 m_niceNumbers = enable;
438 emit changed(m_min, m_max, m_ticksCount, m_niceNumbers);
439 }
511 }
512
513 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
514
515 QChartAxisPrivate::QChartAxisPrivate(QChartAxis* q):
516 q_ptr(q),
517 m_axisVisible(true),
518 m_gridLineVisible(true),
519 m_labelsVisible(true),
520 m_labelsAngle(0),
521 m_shadesVisible(false),
522 m_shadesOpacity(1.0),
523 m_min(0),
524 m_max(0),
525 m_ticksCount(5),
526 m_niceNumbers(false)
527 {
528
529 }
530
531 QChartAxisPrivate::~QChartAxisPrivate()
532 {
533
534 }
535
536 void QChartAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
537 {
538 q_ptr->setRange(min,max);
539 q_ptr->setTicksCount(count);
440 }
540 }
441
541
442 #include "moc_qchartaxis.cpp"
542 #include "moc_qchartaxis.cpp"
543 #include "moc_qchartaxis_p.cpp"
443
544
444 QTCOMMERCIALCHART_END_NAMESPACE
545 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,134 +1,108
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCHARTAXIS_H_
21 #ifndef QCHARTAXIS_H_
22 #define QCHARTAXIS_H_
22 #define QCHARTAXIS_H_
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qchartaxiscategories.h>
25 #include <qchartaxiscategories.h>
26 #include <QPen>
26 #include <QPen>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QChartAxisPrivate;
32
31 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QChartAxis : public QObject
32 {
34 {
33 Q_OBJECT
35 Q_OBJECT
34 public:
36 public:
35
37
36 QChartAxis(QObject *parent =0);
38 QChartAxis(QObject *parent =0);
37 ~QChartAxis();
39 ~QChartAxis();
38
40
39 //axis handling
41 //axis handling
40 bool isAxisVisible() const { return m_axisVisible; }
42 bool isAxisVisible() const;
41 void setAxisVisible(bool visible);
43 void setAxisVisible(bool visible);
42 void setAxisPen(const QPen &pen);
44 void setAxisPen(const QPen &pen);
43 QPen axisPen() const { return m_axisPen; }
45 QPen axisPen() const;
44
46
45 //grid handling
47 //grid handling
46 bool isGridLineVisible() const { return m_gridLineVisible; }
48 bool isGridLineVisible() const;
47 void setGridLineVisible(bool visible);
49 void setGridLineVisible(bool visible);
48 void setGridLinePen(const QPen &pen);
50 void setGridLinePen(const QPen &pen);
49 QPen gridLinePen() const { return m_gridLinePen; }
51 QPen gridLinePen() const;
50
52
51 //labels handling
53 //labels handling
52 bool labelsVisible() const { return m_labelsVisible; }
54 bool labelsVisible() const;
53 void setLabelsVisible(bool visible);
55 void setLabelsVisible(bool visible);
54 void setLabelsPen(const QPen &pen);
56 void setLabelsPen(const QPen &pen);
55 QPen labelsPen() const { return m_labelsPen;}
57 QPen labelsPen() const;
56 void setLabelsBrush(const QBrush &brush);
58 void setLabelsBrush(const QBrush &brush);
57 QBrush labelsBrush() const { return m_labelsBrush; }
59 QBrush labelsBrush() const;
58 void setLabelsFont(const QFont &font);
60 void setLabelsFont(const QFont &font);
59 QFont labelsFont() const { return m_labelsFont; }
61 QFont labelsFont() const;
60 void setLabelsAngle(int angle);
62 void setLabelsAngle(int angle);
61 int labelsAngle() const { return m_labelsAngle; }
63 int labelsAngle() const;
62
64
63 //shades handling
65 //shades handling
64 bool shadesVisible() const { return m_shadesVisible; }
66 bool shadesVisible() const;
65 void setShadesVisible(bool visible);
67 void setShadesVisible(bool visible);
66 void setShadesPen(const QPen &pen);
68 void setShadesPen(const QPen &pen);
67 QPen shadesPen() const { return m_shadesPen; }
69 QPen shadesPen() const;
68 void setShadesBrush(const QBrush &brush);
70 void setShadesBrush(const QBrush &brush);
69 QBrush shadesBrush() const { return m_shadesBrush; }
71 QBrush shadesBrush() const;
70 void setShadesOpacity(qreal opacity);
72 void setShadesOpacity(qreal opacity);
71 qreal shadesOpacity() const { return m_shadesOpacity; }
73 qreal shadesOpacity() const;
72
74
73 //range handling
75 //range handling
74 void setMin(qreal min);
76 void setMin(qreal min);
75 qreal min() const { return m_min; }
77 qreal min() const;
76 void setMax(qreal max);
78 void setMax(qreal max);
77 qreal max() const { return m_max; }
79 qreal max() const;
78 void setRange(qreal min, qreal max);
80 void setRange(qreal min, qreal max);
79
81
80 //ticks handling
82 //ticks handling
81 void setTicksCount(int count);
83 void setTicksCount(int count);
82 int ticksCount() const { return m_ticksCount;}
84 int ticksCount() const;
83
85
84 void setNiceNumbers(bool enable);
86 void setNiceNumbers(bool enable);
85 bool niceNumbers() const { return m_niceNumbers;}
87 bool niceNumbers() const;
86
88
87 QChartAxisCategories* categories() { return &m_category; }
89 QChartAxisCategories* categories();
88
90
89 void show();
91 void show();
90 void hide();
92 void hide();
91
93
92 Q_SIGNALS:
94 Q_SIGNALS:
93 void minChanged(qreal min);
95 void minChanged(qreal min);
94 void maxChanged(qreal max);
96 void maxChanged(qreal max);
95 void rangeChanged(qreal min, qreal max);
97 void rangeChanged(qreal min, qreal max);
96 void ticksCountChanged(int count);
98 void ticksCountChanged(int count);
97
99
98 //interal signal
99 void updated();
100 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
101 //internal slot
102 public Q_SLOTS:
103 void handleAxisRangeChanged(qreal min, qreal max,int count);
104
105 private:
100 private:
106 bool m_axisVisible;
101 QScopedPointer<QChartAxisPrivate> d_ptr;
107 QPen m_axisPen;
102 Q_DISABLE_COPY(QChartAxis);
108 QBrush m_axisBrush;
103 friend class ChartDataSet;
109
104 friend class Axis;
110 bool m_gridLineVisible;
111 QPen m_gridLinePen;
112
113 bool m_labelsVisible;
114 QPen m_labelsPen;
115 QBrush m_labelsBrush;
116 QFont m_labelsFont;
117 int m_labelsAngle;
118
119 bool m_shadesVisible;
120 QPen m_shadesPen;
121 QBrush m_shadesBrush;
122 qreal m_shadesOpacity;
123
124 qreal m_min;
125 qreal m_max;
126
127 int m_ticksCount;
128 QChartAxisCategories m_category;
129
130 bool m_niceNumbers;
131 };
105 };
132
106
133 QTCOMMERCIALCHART_END_NAMESPACE
107 QTCOMMERCIALCHART_END_NAMESPACE
134 #endif /* QCHARTAXIS_H_ */
108 #endif /* QCHARTAXIS_H_ */
@@ -1,81 +1,96
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qchartaxiscategories.h"
21 #include "qchartaxiscategories.h"
22 #include "qchartaxiscategories_p.h"
22
23
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
25
25 QChartAxisCategories::QChartAxisCategories()
26 QChartAxisCategories::QChartAxisCategories():
27 d_ptr(new QChartAxisCategoriesPrivate(this))
26 {
28 {
27 // TODO Auto-generated constructor stub
28
29
29 }
30 }
30
31
31 QChartAxisCategories::~QChartAxisCategories()
32 QChartAxisCategories::~QChartAxisCategories()
32 {
33 {
33 // TODO Auto-generated destructor stub
34
34 }
35 }
35
36
36 void QChartAxisCategories::insert(const QBarCategories &categories)
37 void QChartAxisCategories::insert(const QBarCategories &categories)
37 {
38 {
38 int i=1;
39 int i=1;
39 foreach (QString string , categories) {
40 foreach (QString string , categories) {
40 m_map.insert(i,string);
41 d_ptr->m_map.insert(i,string);
41 i++;
42 i++;
42 }
43 }
43 emit updated();
44 emit d_ptr->updated();
44 }
45 }
45
46
46 void QChartAxisCategories::insert(qreal value,QString label)
47 void QChartAxisCategories::insert(qreal value,QString label)
47 {
48 {
48 m_map.insert(value,label);
49 d_ptr->m_map.insert(value,label);
49 emit updated();
50 emit d_ptr->updated();
50 }
51 }
51
52
52 void QChartAxisCategories::remove(qreal value)
53 void QChartAxisCategories::remove(qreal value)
53 {
54 {
54 m_map.remove(value);
55 d_ptr->m_map.remove(value);
55 emit updated();
56 emit d_ptr->updated();
56 }
57 }
57
58
58 void QChartAxisCategories::clear()
59 void QChartAxisCategories::clear()
59 {
60 {
60 m_map.clear();
61 d_ptr->m_map.clear();
61 emit updated();
62 emit d_ptr->updated();
62 }
63 }
63
64
64 int QChartAxisCategories::count()
65 int QChartAxisCategories::count()
65 {
66 {
66 return m_map.count();
67 return d_ptr->m_map.count();
67 }
68 }
68
69
69 QList<qreal> QChartAxisCategories::values() const
70 QList<qreal> QChartAxisCategories::values() const
70 {
71 {
71 return m_map.keys();
72 return d_ptr->m_map.keys();
72 }
73 }
73
74
74 QString QChartAxisCategories::label(qreal value) const
75 QString QChartAxisCategories::label(qreal value) const
75 {
76 {
76 return m_map.value(value);
77 return d_ptr->m_map.value(value);
78 }
79
80 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
81
82 QChartAxisCategoriesPrivate::QChartAxisCategoriesPrivate(QChartAxisCategories *q):
83 q_ptr(q)
84 {
85
86 }
87
88 QChartAxisCategoriesPrivate::~QChartAxisCategoriesPrivate()
89 {
90
77 }
91 }
78
92
79 #include "moc_qchartaxiscategories.cpp"
93 #include "moc_qchartaxiscategories.cpp"
94 #include "moc_qchartaxiscategories_p.cpp"
80
95
81 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,58 +1,56
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCHARTAXISCATEGORIES_H_
21 #ifndef QCHARTAXISCATEGORIES_H_
22 #define QCHARTAXISCATEGORIES_H_
22 #define QCHARTAXISCATEGORIES_H_
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qbarseries.h>
25 #include <qbarseries.h>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QChartAxisCategoriesPrivate;
30
29 class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject
31 class QTCOMMERCIALCHART_EXPORT QChartAxisCategories : public QObject
30 {
32 {
31 Q_OBJECT
33 Q_OBJECT
32 private:
34 private:
33 QChartAxisCategories();
35 QChartAxisCategories();
34 public:
36 public:
35 ~QChartAxisCategories();
37 ~QChartAxisCategories();
36
38
37 void insert(const QBarCategories &category);
39 void insert(const QBarCategories &category);
38 void insert(qreal value,QString label);
40 void insert(qreal value,QString label);
39 void remove(qreal value);
41 void remove(qreal value);
40 QList<qreal> values() const;
42 QList<qreal> values() const;
41 QString label(qreal value) const;
43 QString label(qreal value) const;
42 void clear();
44 void clear();
43 int count();
45 int count();
44
46
45 //internal signal
46 Q_SIGNALS:
47 void updated();
48
49 private:
47 private:
50 QMap<qreal,QString> m_map;
48 QScopedPointer<QChartAxisCategoriesPrivate> d_ptr;
51
49 friend class QChartAxisPrivate;
52 friend class QChartAxis;
50 friend class Axis;
53 };
51 };
54
52
55
53
56 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
57
55
58 #endif /* QCHARTAXISCATEGORIES_H_ */
56 #endif /* QCHARTAXISCATEGORIES_H_ */
@@ -1,259 +1,255
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchartaxis.h"
22 #include "qchartaxis.h"
23 //series
23 #include "qchartaxis_p.h"
24 #include "qseries_p.h"
24 #include "qseries_p.h"
25 #include "qlineseries.h"
26 #include "qareaseries.h"
27 #include "qbarseries.h"
25 #include "qbarseries.h"
28 #include "qstackedbarseries.h"
26 #include "qstackedbarseries.h"
29 #include "qpercentbarseries.h"
27 #include "qpercentbarseries.h"
30 #include "qpieseries.h"
28 #include "qpieseries.h"
31 #include "qscatterseries.h"
32 #include "qsplineseries.h"
33
29
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
31
36 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
32 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
37 m_axisX(new QChartAxis(this)),
33 m_axisX(new QChartAxis(this)),
38 m_axisY(new QChartAxis(this)),
34 m_axisY(new QChartAxis(this)),
39 m_domainIndex(0),
35 m_domainIndex(0),
40 m_axisXInitialized(false)
36 m_axisXInitialized(false)
41 {
37 {
42 }
38 }
43
39
44 ChartDataSet::~ChartDataSet()
40 ChartDataSet::~ChartDataSet()
45 {
41 {
46 }
42 }
47
43
48 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
44 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
49 {
45 {
50 if(axisY==0) axisY = m_axisY;
46 if(axisY==0) axisY = m_axisY;
51
47
52 QChartAxis* axis = m_seriesAxisMap.value(series);
48 QChartAxis* axis = m_seriesAxisMap.value(series);
53
49
54 if(axis) {
50 if(axis) {
55 qWarning() << "Can not add series. Series already on the chart";
51 qWarning() << "Can not add series. Series already on the chart";
56 return;
52 return;
57 }
53 }
58
54
59 if(!series->parent()){
55 if(!series->parent()){
60 series->setParent(this); // take ownership
56 series->setParent(this); // take ownership
61 };
57 };
62
58
63 if(!axisY->parent()){
59 if(!axisY->parent()){
64 axisY->setParent(this); // take ownership
60 axisY->setParent(this); // take ownership
65 }
61 }
66
62
67 Domain* domain = m_axisDomainMap.value(axisY);
63 Domain* domain = m_axisDomainMap.value(axisY);
68
64
69 if(!domain) {
65 if(!domain) {
70 domain = new Domain(axisY);
66 domain = new Domain(axisY);
71 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
67 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
72 QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
68 QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
73 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int)));
69 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
74 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
70 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX()->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
75 //initialize
71 //initialize
76 m_axisDomainMap.insert(axisY,domain);
72 m_axisDomainMap.insert(axisY,domain);
77 emit axisAdded(axisY,domain);
73 emit axisAdded(axisY,domain);
78 }
74 }
79
75
80 if(!m_axisXInitialized){
76 if(!m_axisXInitialized){
81 emit axisAdded(axisX(),domain);
77 emit axisAdded(axisX(),domain);
82 m_axisXInitialized=true;
78 m_axisXInitialized=true;
83 }
79 }
84
80
85 series->d_ptr->scaleDomain(*domain);
81 series->d_ptr->scaleDomain(*domain);
86
82
87 if(series->type() == QSeries::SeriesTypeBar || series->type() == QSeries::SeriesTypeStackedBar || series->type() == QSeries::SeriesTypePercentBar)
83 if(series->type() == QSeries::SeriesTypeBar || series->type() == QSeries::SeriesTypeStackedBar || series->type() == QSeries::SeriesTypePercentBar)
88 {
84 {
89 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
85 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
90 setupCategories(barSeries);
86 setupCategories(barSeries);
91 }
87 }
92
88
93 if (series->type()== QSeries::SeriesTypePie && m_seriesAxisMap.count()==0)
89 if (series->type()== QSeries::SeriesTypePie && m_seriesAxisMap.count()==0)
94 {
90 {
95 axisX()->hide();
91 axisX()->hide();
96 this->axisY()->hide();
92 this->axisY()->hide();
97 }
93 }
98
94
99 m_seriesAxisMap.insert(series,axisY);
95 m_seriesAxisMap.insert(series,axisY);
100
96
101 QMapIterator<int, QSeries*> i(m_indexSeriesMap);
97 QMapIterator<int, QSeries*> i(m_indexSeriesMap);
102
98
103 int key=0;
99 int key=0;
104 while (i.hasNext()) {
100 while (i.hasNext()) {
105 i.next();
101 i.next();
106 if(i.key()!=key) {
102 if(i.key()!=key) {
107 break;
103 break;
108 }
104 }
109 key++;
105 key++;
110 }
106 }
111
107
112 m_indexSeriesMap.insert(key,series);
108 m_indexSeriesMap.insert(key,series);
113
109
114 emit seriesAdded(series,domain);
110 emit seriesAdded(series,domain);
115
111
116 }
112 }
117
113
118 void ChartDataSet::removeSeries(QSeries* series)
114 void ChartDataSet::removeSeries(QSeries* series)
119 {
115 {
120
116
121 QChartAxis* axis = m_seriesAxisMap.value(series);
117 QChartAxis* axis = m_seriesAxisMap.value(series);
122
118
123 if(!axis){
119 if(!axis){
124 qWarning()<<"Can not remove series. Series not found on the chart.";
120 qWarning()<<"Can not remove series. Series not found on the chart.";
125 return;
121 return;
126 }
122 }
127 emit seriesRemoved(series);
123 emit seriesRemoved(series);
128 m_seriesAxisMap.remove(series);
124 m_seriesAxisMap.remove(series);
129 int key = seriesIndex(series);
125 int key = seriesIndex(series);
130 Q_ASSERT(key!=-1);
126 Q_ASSERT(key!=-1);
131
127
132 m_indexSeriesMap.remove(key);
128 m_indexSeriesMap.remove(key);
133
129
134 if(series->parent()==this){
130 if(series->parent()==this){
135 delete series;
131 delete series;
136 series=0;
132 series=0;
137 }
133 }
138
134
139 QList<QChartAxis*> axes = m_seriesAxisMap.values();
135 QList<QChartAxis*> axes = m_seriesAxisMap.values();
140
136
141 int i = axes.indexOf(axis);
137 int i = axes.indexOf(axis);
142
138
143 if(i==-1){
139 if(i==-1){
144 Domain* domain = m_axisDomainMap.take(axis);
140 Domain* domain = m_axisDomainMap.take(axis);
145 emit axisRemoved(axis);
141 emit axisRemoved(axis);
146 if(axis!=axisY()){
142 if(axis!=axisY()){
147 if(axis->parent()==this){
143 if(axis->parent()==this){
148 delete axis;
144 delete axis;
149 axis=0;
145 axis=0;
150 }
146 }
151 }
147 }
152 delete domain;
148 delete domain;
153 }
149 }
154
150
155 if(m_seriesAxisMap.values().size()==0)
151 if(m_seriesAxisMap.values().size()==0)
156 {
152 {
157 m_axisXInitialized=false;
153 m_axisXInitialized=false;
158 emit axisRemoved(axisX());
154 emit axisRemoved(axisX());
159 }
155 }
160 }
156 }
161
157
162 void ChartDataSet::removeAllSeries()
158 void ChartDataSet::removeAllSeries()
163 {
159 {
164
160
165 QList<QSeries*> series = m_seriesAxisMap.keys();
161 QList<QSeries*> series = m_seriesAxisMap.keys();
166
162
167 foreach(QSeries* s , series) {
163 foreach(QSeries* s , series) {
168 removeSeries(s);
164 removeSeries(s);
169 }
165 }
170
166
171 Q_ASSERT(m_seriesAxisMap.count()==0);
167 Q_ASSERT(m_seriesAxisMap.count()==0);
172 Q_ASSERT(m_axisDomainMap.count()==0);
168 Q_ASSERT(m_axisDomainMap.count()==0);
173
169
174 }
170 }
175
171
176 void ChartDataSet::setupCategories(QBarSeries* series)
172 void ChartDataSet::setupCategories(QBarSeries* series)
177 {
173 {
178 QChartAxisCategories* categories = axisX()->categories();
174 QChartAxisCategories* categories = axisX()->categories();
179 categories->clear();
175 categories->clear();
180 categories->insert(series->categories());
176 categories->insert(series->categories());
181 }
177 }
182
178
183 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
179 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
184 {
180 {
185 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
181 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
186 while (i.hasNext()) {
182 while (i.hasNext()) {
187 i.next();
183 i.next();
188 i.value()->zoomIn(rect,size);
184 i.value()->zoomIn(rect,size);
189 }
185 }
190 }
186 }
191
187
192 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
188 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
193 {
189 {
194 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
190 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
195 while (i.hasNext()) {
191 while (i.hasNext()) {
196 i.next();
192 i.next();
197 i.value()->zoomOut(rect,size);
193 i.value()->zoomOut(rect,size);
198 }
194 }
199 }
195 }
200
196
201 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
197 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
202 {
198 {
203 int count=0;
199 int count=0;
204 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
200 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
205 while (i.hasNext()) {
201 while (i.hasNext()) {
206 i.next();
202 i.next();
207 if(i.key()->type()==type) count++;
203 if(i.key()->type()==type) count++;
208 }
204 }
209 return count;
205 return count;
210 }
206 }
211
207
212 int ChartDataSet::seriesIndex(QSeries *series)
208 int ChartDataSet::seriesIndex(QSeries *series)
213 {
209 {
214 QMapIterator<int, QSeries*> i(m_indexSeriesMap);
210 QMapIterator<int, QSeries*> i(m_indexSeriesMap);
215 while (i.hasNext()) {
211 while (i.hasNext()) {
216 i.next();
212 i.next();
217 if (i.value() == series)
213 if (i.value() == series)
218 return i.key();
214 return i.key();
219 }
215 }
220 return -1;
216 return -1;
221 }
217 }
222
218
223 QChartAxis* ChartDataSet::axisY(QSeries* series) const
219 QChartAxis* ChartDataSet::axisY(QSeries* series) const
224 {
220 {
225 if(series == 0) return m_axisY;
221 if(series == 0) return m_axisY;
226 return m_seriesAxisMap.value(series);
222 return m_seriesAxisMap.value(series);
227 }
223 }
228
224
229 Domain* ChartDataSet::domain(QSeries* series) const
225 Domain* ChartDataSet::domain(QSeries* series) const
230 {
226 {
231 QChartAxis* axis = m_seriesAxisMap.value(series);
227 QChartAxis* axis = m_seriesAxisMap.value(series);
232 if(axis){
228 if(axis){
233 return m_axisDomainMap.value(axis);
229 return m_axisDomainMap.value(axis);
234 }else
230 }else
235 return 0;
231 return 0;
236 }
232 }
237
233
238 Domain* ChartDataSet::domain(QChartAxis* axis) const
234 Domain* ChartDataSet::domain(QChartAxis* axis) const
239 {
235 {
240 if(!axis || axis==axisX()) {
236 if(!axis || axis==axisX()) {
241 return m_axisDomainMap.value(axisY());
237 return m_axisDomainMap.value(axisY());
242 }
238 }
243 else {
239 else {
244 return m_axisDomainMap.value(axis);
240 return m_axisDomainMap.value(axis);
245 }
241 }
246 }
242 }
247
243
248 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
244 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
249 {
245 {
250 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
246 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
251 while (i.hasNext()) {
247 while (i.hasNext()) {
252 i.next();
248 i.next();
253 i.value()->move(dx,dy,size);
249 i.value()->move(dx,dy,size);
254 }
250 }
255 }
251 }
256
252
257 #include "moc_chartdataset_p.cpp"
253 #include "moc_chartdataset_p.cpp"
258
254
259 QTCOMMERCIALCHART_END_NAMESPACE
255 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now