@@ -1,379 +1,391 | |||||
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 "chartaxis_p.h" |
|
21 | #include "chartaxis_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qabstractaxis_p.h" |
|
23 | #include "qabstractaxis_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include "chartanimator_p.h" |
|
25 | #include "chartanimator_p.h" | |
26 | #include <QPainter> |
|
26 | #include <QPainter> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 | #include <qmath.h> |
|
28 | #include <qmath.h> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter), |
|
32 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter), | |
33 | m_chartAxis(axis), |
|
33 | m_chartAxis(axis), | |
34 | m_labelsAngle(0), |
|
34 | m_labelsAngle(0), | |
35 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
35 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
36 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
36 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
37 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
37 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
38 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), |
|
38 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), | |
39 | m_min(0), |
|
39 | m_min(0), | |
40 | m_max(0), |
|
40 | m_max(0), | |
41 | m_ticksCount(0), |
|
41 | m_ticksCount(0), | |
42 | m_animation(0), |
|
42 | m_animation(0), | |
43 | m_minWidth(0), |
|
43 | m_minWidth(0), | |
44 | m_minHeight(0) |
|
44 | m_minHeight(0) | |
45 | { |
|
45 | { | |
46 | //initial initialization |
|
46 | //initial initialization | |
47 | m_axis->setZValue(ChartPresenter::AxisZValue); |
|
47 | m_axis->setZValue(ChartPresenter::AxisZValue); | |
48 | m_axis->setHandlesChildEvents(false); |
|
48 | m_axis->setHandlesChildEvents(false); | |
49 |
|
49 | |||
50 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
50 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
51 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
51 | m_grid->setZValue(ChartPresenter::GridZValue); | |
52 |
|
52 | |||
53 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); |
|
53 | QObject::connect(m_chartAxis->d_ptr.data(),SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |
54 |
|
54 | |||
55 | QGraphicsSimpleTextItem item; |
|
55 | QGraphicsSimpleTextItem item; | |
56 | m_font = item.font(); |
|
56 | m_font = item.font(); | |
57 |
|
57 | |||
58 | handleAxisUpdated(); |
|
58 | handleAxisUpdated(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | ChartAxis::~ChartAxis() |
|
61 | ChartAxis::~ChartAxis() | |
62 | { |
|
62 | { | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void ChartAxis::setAnimation(AxisAnimation* animation) |
|
65 | void ChartAxis::setAnimation(AxisAnimation* animation) | |
66 | { |
|
66 | { | |
67 | m_animation=animation; |
|
67 | m_animation=animation; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
70 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
71 | { |
|
71 | { | |
72 | m_layoutVector=layout; |
|
72 | m_layoutVector=layout; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void ChartAxis::createItems(int count) |
|
75 | void ChartAxis::createItems(int count) | |
76 | { |
|
76 | { | |
77 | if (m_axis->children().size() == 0) |
|
77 | if (m_axis->children().size() == 0) | |
78 | m_axis->addToGroup(new AxisItem(this)); |
|
78 | m_axis->addToGroup(new AxisItem(this)); | |
79 | for (int i = 0; i < count; ++i) { |
|
79 | for (int i = 0; i < count; ++i) { | |
80 | m_grid->addToGroup(new QGraphicsLineItem()); |
|
80 | m_grid->addToGroup(new QGraphicsLineItem()); | |
81 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); |
|
81 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); | |
82 | m_axis->addToGroup(new QGraphicsLineItem()); |
|
82 | m_axis->addToGroup(new QGraphicsLineItem()); | |
83 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); |
|
83 | if ((m_grid->childItems().size())%2 && m_grid->childItems().size()>2) m_shades->addToGroup(new QGraphicsRectItem()); | |
84 | } |
|
84 | } | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void ChartAxis::deleteItems(int count) |
|
87 | void ChartAxis::deleteItems(int count) | |
88 | { |
|
88 | { | |
89 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
89 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
90 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
90 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
91 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
91 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
92 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
92 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
93 |
|
93 | |||
94 | for (int i = 0; i < count; ++i) { |
|
94 | for (int i = 0; i < count; ++i) { | |
95 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); |
|
95 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); | |
96 | delete(lines.takeLast()); |
|
96 | delete(lines.takeLast()); | |
97 | delete(labels.takeLast()); |
|
97 | delete(labels.takeLast()); | |
98 | delete(axis.takeLast()); |
|
98 | delete(axis.takeLast()); | |
99 | } |
|
99 | } | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
102 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
103 | { |
|
103 | { | |
104 | int diff = m_layoutVector.size() - layout.size(); |
|
104 | int diff = m_layoutVector.size() - layout.size(); | |
105 |
|
105 | |||
106 | if (diff>0) { |
|
106 | if (diff>0) { | |
107 | deleteItems(diff); |
|
107 | deleteItems(diff); | |
108 | } |
|
108 | } | |
109 | else if (diff<0) { |
|
109 | else if (diff<0) { | |
110 | createItems(-diff); |
|
110 | createItems(-diff); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | if( diff!=0) handleAxisUpdated(); |
|
113 | if( diff!=0) handleAxisUpdated(); | |
114 |
|
114 | |||
115 | if (m_animation) { |
|
115 | if (m_animation) { | |
116 | switch(presenter()->state()){ |
|
116 | switch(presenter()->state()){ | |
117 | case ChartPresenter::ZoomInState: |
|
117 | case ChartPresenter::ZoomInState: | |
118 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
118 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
119 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
119 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
120 | break; |
|
120 | break; | |
121 | case ChartPresenter::ZoomOutState: |
|
121 | case ChartPresenter::ZoomOutState: | |
122 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
122 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
123 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
123 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
124 | break; |
|
124 | break; | |
125 | case ChartPresenter::ScrollUpState: |
|
125 | case ChartPresenter::ScrollUpState: | |
126 | case ChartPresenter::ScrollLeftState: |
|
126 | case ChartPresenter::ScrollLeftState: | |
127 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
127 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
128 | break; |
|
128 | break; | |
129 | case ChartPresenter::ScrollDownState: |
|
129 | case ChartPresenter::ScrollDownState: | |
130 | case ChartPresenter::ScrollRightState: |
|
130 | case ChartPresenter::ScrollRightState: | |
131 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
131 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
132 | break; |
|
132 | break; | |
133 | case ChartPresenter::ShowState: |
|
133 | case ChartPresenter::ShowState: | |
134 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
134 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
135 | break; |
|
135 | break; | |
136 | } |
|
136 | } | |
137 | m_animation->setValues(m_layoutVector,layout); |
|
137 | m_animation->setValues(m_layoutVector,layout); | |
138 | presenter()->startAnimation(m_animation); |
|
138 | presenter()->startAnimation(m_animation); | |
139 | } |
|
139 | } | |
140 | else { |
|
140 | else { | |
141 | setLayout(layout); |
|
141 | setLayout(layout); | |
142 | updateGeometry(); |
|
142 | updateGeometry(); | |
143 | } |
|
143 | } | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void ChartAxis::setAxisOpacity(qreal opacity) |
|
146 | void ChartAxis::setAxisOpacity(qreal opacity) | |
147 | { |
|
147 | { | |
148 | m_axis->setOpacity(opacity); |
|
148 | m_axis->setOpacity(opacity); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | qreal ChartAxis::axisOpacity() const |
|
151 | qreal ChartAxis::axisOpacity() const | |
152 | { |
|
152 | { | |
153 | return m_axis->opacity(); |
|
153 | return m_axis->opacity(); | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void ChartAxis::setGridOpacity(qreal opacity) |
|
156 | void ChartAxis::setGridOpacity(qreal opacity) | |
157 | { |
|
157 | { | |
158 | m_grid->setOpacity(opacity); |
|
158 | m_grid->setOpacity(opacity); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | qreal ChartAxis::gridOpacity() const |
|
161 | qreal ChartAxis::gridOpacity() const | |
162 | { |
|
162 | { | |
163 | return m_grid->opacity(); |
|
163 | return m_grid->opacity(); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void ChartAxis::setLabelsOpacity(qreal opacity) |
|
166 | void ChartAxis::setLabelsOpacity(qreal opacity) | |
167 | { |
|
167 | { | |
168 | m_labels->setOpacity(opacity); |
|
168 | m_labels->setOpacity(opacity); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | qreal ChartAxis::labelsOpacity() const |
|
171 | qreal ChartAxis::labelsOpacity() const | |
172 | { |
|
172 | { | |
173 | return m_labels->opacity(); |
|
173 | return m_labels->opacity(); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void ChartAxis::setShadesOpacity(qreal opacity) |
|
176 | void ChartAxis::setShadesOpacity(qreal opacity) | |
177 | { |
|
177 | { | |
178 | m_shades->setOpacity(opacity); |
|
178 | m_shades->setOpacity(opacity); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | qreal ChartAxis::shadesOpacity() const |
|
181 | qreal ChartAxis::shadesOpacity() const | |
182 | { |
|
182 | { | |
183 | return m_shades->opacity(); |
|
183 | return m_shades->opacity(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void ChartAxis::setLabelsAngle(int angle) |
|
186 | void ChartAxis::setLabelsAngle(int angle) | |
187 | { |
|
187 | { | |
188 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
188 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
189 | item->setRotation(angle); |
|
189 | item->setRotation(angle); | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | m_labelsAngle=angle; |
|
192 | m_labelsAngle=angle; | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | void ChartAxis::setLabelsPen(const QPen &pen) |
|
195 | void ChartAxis::setLabelsPen(const QPen &pen) | |
196 | { |
|
196 | { | |
197 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
197 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
198 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
198 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
199 | } |
|
199 | } | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | void ChartAxis::setLabelsBrush(const QBrush &brush) |
|
202 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
203 | { |
|
203 | { | |
204 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
204 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
205 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
205 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
206 | } |
|
206 | } | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | void ChartAxis::setLabelsFont(const QFont &font) |
|
209 | void ChartAxis::setLabelsFont(const QFont &font) | |
210 | { |
|
210 | { | |
211 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
211 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
212 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
212 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
213 | } |
|
213 | } | |
214 | m_font = font; |
|
214 | m_font = font; | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void ChartAxis::setShadesBrush(const QBrush &brush) |
|
217 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
218 | { |
|
218 | { | |
219 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
219 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
220 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
220 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | void ChartAxis::setShadesPen(const QPen &pen) |
|
224 | void ChartAxis::setShadesPen(const QPen &pen) | |
225 | { |
|
225 | { | |
226 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
226 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
227 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
227 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
228 | } |
|
228 | } | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | void ChartAxis::setAxisPen(const QPen &pen) |
|
231 | void ChartAxis::setAxisPen(const QPen &pen) | |
232 | { |
|
232 | { | |
233 | foreach(QGraphicsItem* item , m_axis->childItems()) { |
|
233 | foreach(QGraphicsItem* item , m_axis->childItems()) { | |
234 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
234 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
235 | } |
|
235 | } | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | void ChartAxis::setGridPen(const QPen &pen) |
|
238 | void ChartAxis::setGridPen(const QPen &pen) | |
239 | { |
|
239 | { | |
240 | foreach(QGraphicsItem* item , m_grid->childItems()) { |
|
240 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
241 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
241 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | bool ChartAxis::isEmpty() |
|
245 | bool ChartAxis::isEmpty() | |
246 | { |
|
246 | { | |
247 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; |
|
247 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | //handlers |
|
250 | //handlers | |
251 |
|
251 | |||
252 | void ChartAxis::handleAxisCategoriesUpdated() |
|
252 | void ChartAxis::handleAxisCategoriesUpdated() | |
253 | { |
|
253 | { | |
254 | if (isEmpty()) return; |
|
254 | if (isEmpty()) return; | |
255 | updateLayout(m_layoutVector); |
|
255 | updateLayout(m_layoutVector); | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | void ChartAxis::handleAxisUpdated() |
|
258 | void ChartAxis::handleAxisUpdated() | |
259 | { |
|
259 | { | |
260 |
|
260 | |||
261 | if (isEmpty()) return; |
|
261 | if (isEmpty()) return; | |
262 |
|
262 | |||
263 |
if (m_chartAxis-> |
|
263 | if (!m_chartAxis->isVisible()) { | |
264 | setAxisOpacity(100); |
|
|||
265 | } else { |
|
|||
266 | setAxisOpacity(0); |
|
264 | setAxisOpacity(0); | |
267 | } |
|
|||
268 |
|
||||
269 | if (m_chartAxis->isGridLineVisible()) { |
|
|||
270 | setGridOpacity(100); |
|
|||
271 | } else { |
|
|||
272 | setGridOpacity(0); |
|
265 | setGridOpacity(0); | |
273 | } |
|
|||
274 |
|
||||
275 | if (m_chartAxis->labelsVisible()) { |
|
|||
276 | setLabelsOpacity(100); |
|
|||
277 | } else { |
|
|||
278 | setLabelsOpacity(0); |
|
266 | setLabelsOpacity(0); | |
279 | } |
|
|||
280 |
|
||||
281 | if (m_chartAxis->shadesVisible()) { |
|
|||
282 | setShadesOpacity(100); |
|
|||
283 | } else { |
|
|||
284 | setShadesOpacity(0); |
|
267 | setShadesOpacity(0); | |
285 | } |
|
268 | } | |
|
269 | else { | |||
|
270 | ||||
|
271 | if (m_chartAxis->isAxisVisible()) { | |||
|
272 | setAxisOpacity(100); | |||
|
273 | } | |||
|
274 | else { | |||
|
275 | setAxisOpacity(0); | |||
|
276 | } | |||
286 |
|
277 | |||
|
278 | if (m_chartAxis->isGridLineVisible()) { | |||
|
279 | setGridOpacity(100); | |||
|
280 | } | |||
|
281 | else { | |||
|
282 | setGridOpacity(0); | |||
|
283 | } | |||
|
284 | ||||
|
285 | if (m_chartAxis->labelsVisible()) { | |||
|
286 | setLabelsOpacity(100); | |||
|
287 | } | |||
|
288 | else { | |||
|
289 | setLabelsOpacity(0); | |||
|
290 | } | |||
|
291 | ||||
|
292 | if (m_chartAxis->shadesVisible()) { | |||
|
293 | setShadesOpacity(100); | |||
|
294 | } | |||
|
295 | else { | |||
|
296 | setShadesOpacity(0); | |||
|
297 | } | |||
|
298 | } | |||
287 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
299 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
288 | setAxisPen(m_chartAxis->axisPen()); |
|
300 | setAxisPen(m_chartAxis->axisPen()); | |
289 | setLabelsPen(m_chartAxis->labelsPen()); |
|
301 | setLabelsPen(m_chartAxis->labelsPen()); | |
290 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
302 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
291 | setLabelsFont(m_chartAxis->labelsFont()); |
|
303 | setLabelsFont(m_chartAxis->labelsFont()); | |
292 | setGridPen(m_chartAxis->gridLinePen()); |
|
304 | setGridPen(m_chartAxis->gridLinePen()); | |
293 | setShadesPen(m_chartAxis->shadesPen()); |
|
305 | setShadesPen(m_chartAxis->shadesPen()); | |
294 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
306 | setShadesBrush(m_chartAxis->shadesBrush()); | |
295 |
|
307 | |||
296 | } |
|
308 | } | |
297 |
|
309 | |||
298 | void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) |
|
310 | void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) | |
299 | { |
|
311 | { | |
300 | if (qFuzzyIsNull(min - max) || tickCount < 2) |
|
312 | if (qFuzzyIsNull(min - max) || tickCount < 2) | |
301 | return; |
|
313 | return; | |
302 |
|
314 | |||
303 | m_min = min; |
|
315 | m_min = min; | |
304 | m_max = max; |
|
316 | m_max = max; | |
305 | m_ticksCount= tickCount; |
|
317 | m_ticksCount= tickCount; | |
306 |
|
318 | |||
307 | if (isEmpty()) return; |
|
319 | if (isEmpty()) return; | |
308 | QVector<qreal> layout = calculateLayout(); |
|
320 | QVector<qreal> layout = calculateLayout(); | |
309 | updateLayout(layout); |
|
321 | updateLayout(layout); | |
310 | } |
|
322 | } | |
311 |
|
323 | |||
312 | void ChartAxis::handleGeometryChanged(const QRectF &rect) |
|
324 | void ChartAxis::handleGeometryChanged(const QRectF &rect) | |
313 | { |
|
325 | { | |
314 | if(m_rect != rect) |
|
326 | if(m_rect != rect) | |
315 | { |
|
327 | { | |
316 | m_rect = rect; |
|
328 | m_rect = rect; | |
317 | if (isEmpty()) return; |
|
329 | if (isEmpty()) return; | |
318 | QVector<qreal> layout = calculateLayout(); |
|
330 | QVector<qreal> layout = calculateLayout(); | |
319 | updateLayout(layout); |
|
331 | updateLayout(layout); | |
320 | } |
|
332 | } | |
321 | } |
|
333 | } | |
322 |
|
334 | |||
323 |
|
335 | |||
324 | qreal ChartAxis::minimumWidth() |
|
336 | qreal ChartAxis::minimumWidth() | |
325 | { |
|
337 | { | |
326 | if(m_minWidth == 0) updateGeometry(); |
|
338 | if(m_minWidth == 0) updateGeometry(); | |
327 | return m_minWidth; |
|
339 | return m_minWidth; | |
328 | } |
|
340 | } | |
329 |
|
341 | |||
330 | qreal ChartAxis::minimumHeight() |
|
342 | qreal ChartAxis::minimumHeight() | |
331 | { |
|
343 | { | |
332 | if(m_minHeight == 0) updateGeometry(); |
|
344 | if(m_minHeight == 0) updateGeometry(); | |
333 | return m_minHeight; |
|
345 | return m_minHeight; | |
334 | } |
|
346 | } | |
335 |
|
347 | |||
336 |
|
348 | |||
337 | void ChartAxis::axisSelected() |
|
349 | void ChartAxis::axisSelected() | |
338 | { |
|
350 | { | |
339 | qDebug()<<"TODO: axis clicked"; |
|
351 | qDebug()<<"TODO: axis clicked"; | |
340 | } |
|
352 | } | |
341 |
|
353 | |||
342 |
|
354 | |||
343 | void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const |
|
355 | void ChartAxis::createNumberLabels(QStringList &labels,qreal min, qreal max, int ticks) const | |
344 | { |
|
356 | { | |
345 | Q_ASSERT(max>min); |
|
357 | Q_ASSERT(max>min); | |
346 | Q_ASSERT(ticks>1); |
|
358 | Q_ASSERT(ticks>1); | |
347 |
|
359 | |||
348 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
360 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
349 | n++; |
|
361 | n++; | |
350 | for (int i=0; i< ticks; i++) { |
|
362 | for (int i=0; i< ticks; i++) { | |
351 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
363 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
352 | labels << QString::number(value,'f',n); |
|
364 | labels << QString::number(value,'f',n); | |
353 | } |
|
365 | } | |
354 | } |
|
366 | } | |
355 |
|
367 | |||
356 | void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const |
|
368 | void ChartAxis::createCategoryLabels(QStringList &labels,qreal min, qreal max,const QStringList &categories) const | |
357 | { |
|
369 | { | |
358 | Q_ASSERT(max>min); |
|
370 | Q_ASSERT(max>min); | |
359 | Q_UNUSED(max); |
|
371 | Q_UNUSED(max); | |
360 |
|
372 | |||
361 | int x = qCeil(min); |
|
373 | int x = qCeil(min); | |
362 | int count = 0; |
|
374 | int count = 0; | |
363 |
|
375 | |||
364 | // Try to find category for x coordinate |
|
376 | // Try to find category for x coordinate | |
365 | while (count < m_ticksCount) { |
|
377 | while (count < m_ticksCount) { | |
366 | if ((x < categories.count()) && (x >= 0)) { |
|
378 | if ((x < categories.count()) && (x >= 0)) { | |
367 | labels << categories.at(x); |
|
379 | labels << categories.at(x); | |
368 | } else { |
|
380 | } else { | |
369 | // No label for x coordinate |
|
381 | // No label for x coordinate | |
370 | labels << ""; |
|
382 | labels << ""; | |
371 | } |
|
383 | } | |
372 | x++; |
|
384 | x++; | |
373 | count++; |
|
385 | count++; | |
374 | } |
|
386 | } | |
375 | } |
|
387 | } | |
376 |
|
388 | |||
377 | #include "moc_chartaxis_p.cpp" |
|
389 | #include "moc_chartaxis_p.cpp" | |
378 |
|
390 | |||
379 | QTCOMMERCIALCHART_END_NAMESPACE |
|
391 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,587 +1,595 | |||||
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 "qabstractaxis.h" |
|
21 | #include "qabstractaxis.h" | |
22 | #include "qabstractaxis_p.h" |
|
22 | #include "qabstractaxis_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QAbstractAxis |
|
27 | \class QAbstractAxis | |
28 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
28 | \brief The QAbstractAxis class is used for manipulating chart's axis. | |
29 | \mainclass |
|
29 | \mainclass | |
30 |
|
30 | |||
31 | There is only one x Axis, however there can be multiple y axes. |
|
31 | 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 shared common X axis. |
|
32 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
33 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
33 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
34 | */ |
|
34 | */ | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \qmlclass Axis QAbstractAxis |
|
37 | \qmlclass Axis QAbstractAxis | |
38 | \brief The Axis element is used for manipulating chart's axes |
|
38 | \brief The Axis element is used for manipulating chart's axes | |
39 |
|
39 | |||
40 | There is only one x Axis, however there can be multiple y axes on a ChartView. |
|
40 | There is only one x Axis, however there can be multiple y axes on a ChartView. | |
41 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
41 | Each chart series can be bound to exactly one Y axis and the shared common X axis. | |
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
42 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
43 |
|
43 | |||
44 | To access Axes you can use ChartView API. For example: |
|
44 | To access Axes you can use ChartView API. For example: | |
45 | \code |
|
45 | \code | |
46 | ChartView { |
|
46 | ChartView { | |
47 | axisX.min: 0 |
|
47 | axisX.min: 0 | |
48 | axisX.max: 3 |
|
48 | axisX.max: 3 | |
49 | axisX.ticksCount: 4 |
|
49 | axisX.ticksCount: 4 | |
50 | axisY.min: 0 |
|
50 | axisY.min: 0 | |
51 | axisY.max: 4 |
|
51 | axisY.max: 4 | |
52 | // Add a few series... |
|
52 | // Add a few series... | |
53 | } |
|
53 | } | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \enum QAbstractAxis::AxisType |
|
58 | \enum QAbstractAxis::AxisType | |
59 |
|
59 | |||
60 | The type of the series object. |
|
60 | The type of the series object. | |
61 |
|
61 | |||
62 | \value AxisTypeValues |
|
62 | \value AxisTypeValues | |
63 | \value AxisTypeCategories |
|
63 | \value AxisTypeCategories | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /* |
|
66 | /* | |
67 | \property QAbstractAxis::type |
|
67 | \property QAbstractAxis::type | |
68 | The type of the axis. |
|
68 | The type of the axis. | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QAbstractAxis::labelsVisible |
|
72 | \property QAbstractAxis::labelsVisible | |
73 | Defines if axis labels are visible. |
|
73 | Defines if axis labels are visible. | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
76 | \qmlproperty bool Axis::labelsVisible |
|
76 | \qmlproperty bool Axis::labelsVisible | |
77 | Defines if axis labels are visible. |
|
77 | Defines if axis labels are visible. | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /* |
|
80 | /* | |
81 | \property QAbstractAxis::min |
|
81 | \property QAbstractAxis::min | |
82 | Defines the minimum value on the axis. |
|
82 | Defines the minimum value on the axis. | |
83 | */ |
|
83 | */ | |
84 | /* |
|
84 | /* | |
85 | \qmlproperty real Axis::min |
|
85 | \qmlproperty real Axis::min | |
86 | Defines the minimum value on the axis. |
|
86 | Defines the minimum value on the axis. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /* |
|
89 | /* | |
90 | \property QAbstractAxis::max |
|
90 | \property QAbstractAxis::max | |
91 | Defines the maximum value on the axis. |
|
91 | Defines the maximum value on the axis. | |
92 | */ |
|
92 | */ | |
93 | /* |
|
93 | /* | |
94 | \qmlproperty real Axis::max |
|
94 | \qmlproperty real Axis::max | |
95 | Defines the maximum value on the axis. |
|
95 | Defines the maximum value on the axis. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \property QAbstractAxis::visible |
|
99 | \property QAbstractAxis::visible | |
100 | The visibility of the axis. |
|
100 | The visibility of the axis. | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \qmlproperty bool Axis::visible |
|
103 | \qmlproperty bool Axis::visible | |
104 | The visibility of the axis. |
|
104 | The visibility of the axis. | |
105 | */ |
|
105 | */ | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | \property QAbstractAxis::gridVisible |
|
108 | \property QAbstractAxis::gridVisible | |
109 | The visibility of the grid lines. |
|
109 | The visibility of the grid lines. | |
110 | */ |
|
110 | */ | |
111 | /*! |
|
111 | /*! | |
112 | \qmlproperty bool Axis::gridVisible |
|
112 | \qmlproperty bool Axis::gridVisible | |
113 | The visibility of the grid lines. |
|
113 | The visibility of the grid lines. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \property QAbstractAxis::color |
|
117 | \property QAbstractAxis::color | |
118 | The color of the axis and ticks. |
|
118 | The color of the axis and ticks. | |
119 | */ |
|
119 | */ | |
120 | /*! |
|
120 | /*! | |
121 | \qmlproperty color Axis::color |
|
121 | \qmlproperty color Axis::color | |
122 | The color of the axis and ticks. |
|
122 | The color of the axis and ticks. | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | \property QAbstractAxis::labelsFont |
|
126 | \property QAbstractAxis::labelsFont | |
127 | The font of the axis labels. |
|
127 | The font of the axis labels. | |
128 | */ |
|
128 | */ | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | \qmlproperty Font Axis::labelsFont |
|
131 | \qmlproperty Font Axis::labelsFont | |
132 | The font of the axis labels. |
|
132 | The font of the axis labels. | |
133 |
|
133 | |||
134 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
134 | See the \l {Font} {QML Font Element} for detailed documentation. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \property QAbstractAxis::labelsColor |
|
138 | \property QAbstractAxis::labelsColor | |
139 | The color of the axis labels. |
|
139 | The color of the axis labels. | |
140 | */ |
|
140 | */ | |
141 | /*! |
|
141 | /*! | |
142 | \qmlproperty color Axis::labelsColor |
|
142 | \qmlproperty color Axis::labelsColor | |
143 | The color of the axis labels. |
|
143 | The color of the axis labels. | |
144 | */ |
|
144 | */ | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | \property QAbstractAxis::labelsAngle |
|
147 | \property QAbstractAxis::labelsAngle | |
148 | The angle of the axis labels in degrees. |
|
148 | The angle of the axis labels in degrees. | |
149 | */ |
|
149 | */ | |
150 | /*! |
|
150 | /*! | |
151 | \qmlproperty int Axis::labelsAngle |
|
151 | \qmlproperty int Axis::labelsAngle | |
152 | The angle of the axis labels in degrees. |
|
152 | The angle of the axis labels in degrees. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \property QAbstractAxis::shadesVisible |
|
156 | \property QAbstractAxis::shadesVisible | |
157 | The visibility of the axis shades. |
|
157 | The visibility of the axis shades. | |
158 | */ |
|
158 | */ | |
159 | /*! |
|
159 | /*! | |
160 | \qmlproperty bool Axis::shadesVisible |
|
160 | \qmlproperty bool Axis::shadesVisible | |
161 | The visibility of the axis shades. |
|
161 | The visibility of the axis shades. | |
162 | */ |
|
162 | */ | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | \property QAbstractAxis::shadesColor |
|
165 | \property QAbstractAxis::shadesColor | |
166 | The fill (brush) color of the axis shades. |
|
166 | The fill (brush) color of the axis shades. | |
167 | */ |
|
167 | */ | |
168 | /*! |
|
168 | /*! | |
169 | \qmlproperty color Axis::shadesColor |
|
169 | \qmlproperty color Axis::shadesColor | |
170 | The fill (brush) color of the axis shades. |
|
170 | The fill (brush) color of the axis shades. | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | \property QAbstractAxis::shadesBorderColor |
|
174 | \property QAbstractAxis::shadesBorderColor | |
175 | The border (pen) color of the axis shades. |
|
175 | The border (pen) color of the axis shades. | |
176 | */ |
|
176 | */ | |
177 | /*! |
|
177 | /*! | |
178 | \qmlproperty color Axis::shadesBorderColor |
|
178 | \qmlproperty color Axis::shadesBorderColor | |
179 | The border (pen) color of the axis shades. |
|
179 | The border (pen) color of the axis shades. | |
180 | */ |
|
180 | */ | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | \fn void QAbstractAxis::visibleChanged(bool) |
|
183 | \fn void QAbstractAxis::visibleChanged(bool) | |
184 | Visiblity of the axis has changed to \a visible. |
|
184 | Visiblity of the axis has changed to \a visible. | |
185 | */ |
|
185 | */ | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | \fn void QAbstractAxis::labelsVisibleChanged(bool) |
|
188 | \fn void QAbstractAxis::labelsVisibleChanged(bool) | |
189 | Visiblity of the labels of the axis has changed to \a visible. |
|
189 | Visiblity of the labels of the axis has changed to \a visible. | |
190 | */ |
|
190 | */ | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | \fn void QAbstractAxis::gridVisibleChanged(bool) |
|
193 | \fn void QAbstractAxis::gridVisibleChanged(bool) | |
194 | Visiblity of the grid lines of the axis has changed to \a visible. |
|
194 | Visiblity of the grid lines of the axis has changed to \a visible. | |
195 | */ |
|
195 | */ | |
196 |
|
196 | |||
197 | /* |
|
197 | /* | |
198 | \fn void QAbstractAxis::minChanged(qreal min) |
|
198 | \fn void QAbstractAxis::minChanged(qreal min) | |
199 | Axis emits signal when \a min of axis has changed. |
|
199 | Axis emits signal when \a min of axis has changed. | |
200 | */ |
|
200 | */ | |
201 |
|
201 | |||
202 | /* |
|
202 | /* | |
203 | \fn void QAbstractAxis::maxChanged(qreal max) |
|
203 | \fn void QAbstractAxis::maxChanged(qreal max) | |
204 | Axis emits signal when \a max of axis has changed. |
|
204 | Axis emits signal when \a max of axis has changed. | |
205 | */ |
|
205 | */ | |
206 |
|
206 | |||
207 | /* |
|
207 | /* | |
208 | \fn void QAbstractAxis::rangeChanged(qreal min, qreal max) |
|
208 | \fn void QAbstractAxis::rangeChanged(qreal min, qreal max) | |
209 | Axis emits signal when \a min or \a max of axis has changed. |
|
209 | Axis emits signal when \a min or \a max of axis has changed. | |
210 | */ |
|
210 | */ | |
211 |
|
211 | |||
212 | /* |
|
212 | /* | |
213 | \fn QChartAxisCategories* QAbstractAxis::categories() |
|
213 | \fn QChartAxisCategories* QAbstractAxis::categories() | |
214 | Returns pointer to the list of categories which correspond to the values on the axis. |
|
214 | Returns pointer to the list of categories which correspond to the values on the axis. | |
215 | */ |
|
215 | */ | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | \fn void QAbstractAxis::colorChanged(QColor) |
|
218 | \fn void QAbstractAxis::colorChanged(QColor) | |
219 | Emitted if the \a color of the axis is changed. |
|
219 | Emitted if the \a color of the axis is changed. | |
220 | */ |
|
220 | */ | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | \fn void QAbstractAxis::labelsColorChanged(QColor) |
|
223 | \fn void QAbstractAxis::labelsColorChanged(QColor) | |
224 | Emitted if the \a color of the axis labels is changed. |
|
224 | Emitted if the \a color of the axis labels is changed. | |
225 | */ |
|
225 | */ | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
228 | \fn void QAbstractAxis::shadesVisibleChanged(bool) | |
229 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
229 | Emitted if the visibility of the axis shades is changed to \a visible. | |
230 | */ |
|
230 | */ | |
231 |
|
231 | |||
232 | /*! |
|
232 | /*! | |
233 | \fn void QAbstractAxis::shadesColorChanged(QColor) |
|
233 | \fn void QAbstractAxis::shadesColorChanged(QColor) | |
234 | Emitted if the \a color of the axis shades is changed. |
|
234 | Emitted if the \a color of the axis shades is changed. | |
235 | */ |
|
235 | */ | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
238 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) | |
239 | Emitted if the border \a color of the axis shades is changed. |
|
239 | Emitted if the border \a color of the axis shades is changed. | |
240 | */ |
|
240 | */ | |
241 |
|
241 | |||
242 | /*! |
|
242 | /*! | |
243 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
243 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
244 | QChart when axis added. |
|
244 | QChart when axis added. | |
245 | */ |
|
245 | */ | |
246 |
|
246 | |||
247 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : |
|
247 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) : | |
248 | QObject(parent), |
|
248 | QObject(parent), | |
249 | d_ptr(&d) |
|
249 | d_ptr(&d) | |
250 | { |
|
250 | { | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
254 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
255 | */ |
|
255 | */ | |
256 |
|
256 | |||
257 | QAbstractAxis::~QAbstractAxis() |
|
257 | QAbstractAxis::~QAbstractAxis() | |
258 | { |
|
258 | { | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Sets \a pen used to draw axis line and ticks. |
|
262 | Sets \a pen used to draw axis line and ticks. | |
263 | */ |
|
263 | */ | |
264 | void QAbstractAxis::setAxisPen(const QPen &pen) |
|
264 | void QAbstractAxis::setAxisPen(const QPen &pen) | |
265 | { |
|
265 | { | |
266 | if (d_ptr->m_axisPen!=pen) { |
|
266 | if (d_ptr->m_axisPen!=pen) { | |
267 | d_ptr->m_axisPen = pen; |
|
267 | d_ptr->m_axisPen = pen; | |
268 | emit d_ptr->updated(); |
|
268 | emit d_ptr->updated(); | |
269 | } |
|
269 | } | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | /*! |
|
272 | /*! | |
273 | Returns pen used to draw axis and ticks. |
|
273 | Returns pen used to draw axis and ticks. | |
274 | */ |
|
274 | */ | |
275 | QPen QAbstractAxis::axisPen() const |
|
275 | QPen QAbstractAxis::axisPen() const | |
276 | { |
|
276 | { | |
277 | return d_ptr->m_axisPen; |
|
277 | return d_ptr->m_axisPen; | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | void QAbstractAxis::setAxisPenColor(QColor color) |
|
280 | void QAbstractAxis::setAxisPenColor(QColor color) | |
281 | { |
|
281 | { | |
282 | QPen p = d_ptr->m_axisPen; |
|
282 | QPen p = d_ptr->m_axisPen; | |
283 | if (p.color() != color) { |
|
283 | if (p.color() != color) { | |
284 | p.setColor(color); |
|
284 | p.setColor(color); | |
285 | setAxisPen(p); |
|
285 | setAxisPen(p); | |
286 | emit colorChanged(color); |
|
286 | emit colorChanged(color); | |
287 | } |
|
287 | } | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | QColor QAbstractAxis::axisPenColor() const |
|
290 | QColor QAbstractAxis::axisPenColor() const | |
291 | { |
|
291 | { | |
292 | return d_ptr->m_axisPen.color(); |
|
292 | return d_ptr->m_axisPen.color(); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | /*! |
|
295 | /*! | |
296 | Sets if axis and ticks are \a visible. |
|
296 | Sets if axis and ticks are \a visible. | |
297 | */ |
|
297 | */ | |
298 | void QAbstractAxis::setAxisVisible(bool visible) |
|
298 | void QAbstractAxis::setAxisVisible(bool visible) | |
299 | { |
|
299 | { | |
300 | if (d_ptr->m_axisVisible != visible) { |
|
300 | if (d_ptr->m_axisVisible != visible) { | |
301 | d_ptr->m_axisVisible = visible; |
|
301 | d_ptr->m_axisVisible = visible; | |
302 | emit d_ptr->updated(); |
|
302 | emit d_ptr->updated(); | |
303 | emit visibleChanged(visible); |
|
303 | emit visibleChanged(visible); | |
304 | } |
|
304 | } | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | bool QAbstractAxis::isAxisVisible() const |
|
307 | bool QAbstractAxis::isAxisVisible() const | |
308 | { |
|
308 | { | |
309 | return d_ptr->m_axisVisible; |
|
309 | return d_ptr->m_axisVisible; | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
312 | void QAbstractAxis::setGridLineVisible(bool visible) | |
313 | { |
|
313 | { | |
314 | if (d_ptr->m_gridLineVisible != visible) { |
|
314 | if (d_ptr->m_gridLineVisible != visible) { | |
315 | d_ptr->m_gridLineVisible = visible; |
|
315 | d_ptr->m_gridLineVisible = visible; | |
316 | emit d_ptr->updated(); |
|
316 | emit d_ptr->updated(); | |
317 | emit gridVisibleChanged(visible); |
|
317 | emit gridVisibleChanged(visible); | |
318 | } |
|
318 | } | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | bool QAbstractAxis::isGridLineVisible() const |
|
321 | bool QAbstractAxis::isGridLineVisible() const | |
322 | { |
|
322 | { | |
323 | return d_ptr->m_gridLineVisible; |
|
323 | return d_ptr->m_gridLineVisible; | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | /*! |
|
326 | /*! | |
327 | Sets \a pen used to draw grid line. |
|
327 | Sets \a pen used to draw grid line. | |
328 | */ |
|
328 | */ | |
329 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
329 | void QAbstractAxis::setGridLinePen(const QPen &pen) | |
330 | { |
|
330 | { | |
331 | if (d_ptr->m_gridLinePen != pen) { |
|
331 | if (d_ptr->m_gridLinePen != pen) { | |
332 | d_ptr->m_gridLinePen = pen; |
|
332 | d_ptr->m_gridLinePen = pen; | |
333 | emit d_ptr->updated(); |
|
333 | emit d_ptr->updated(); | |
334 | } |
|
334 | } | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | /*! |
|
337 | /*! | |
338 | Returns pen used to draw grid. |
|
338 | Returns pen used to draw grid. | |
339 | */ |
|
339 | */ | |
340 | QPen QAbstractAxis::gridLinePen() const |
|
340 | QPen QAbstractAxis::gridLinePen() const | |
341 | { |
|
341 | { | |
342 | return d_ptr->m_gridLinePen; |
|
342 | return d_ptr->m_gridLinePen; | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
345 | void QAbstractAxis::setLabelsVisible(bool visible) | |
346 | { |
|
346 | { | |
347 | if (d_ptr->m_labelsVisible != visible) { |
|
347 | if (d_ptr->m_labelsVisible != visible) { | |
348 | d_ptr->m_labelsVisible = visible; |
|
348 | d_ptr->m_labelsVisible = visible; | |
349 | emit d_ptr->updated(); |
|
349 | emit d_ptr->updated(); | |
350 | emit labelsVisibleChanged(visible); |
|
350 | emit labelsVisibleChanged(visible); | |
351 | } |
|
351 | } | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | bool QAbstractAxis::labelsVisible() const |
|
354 | bool QAbstractAxis::labelsVisible() const | |
355 | { |
|
355 | { | |
356 | return d_ptr->m_labelsVisible; |
|
356 | return d_ptr->m_labelsVisible; | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Sets \a pen used to draw labels. |
|
360 | Sets \a pen used to draw labels. | |
361 | */ |
|
361 | */ | |
362 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
362 | void QAbstractAxis::setLabelsPen(const QPen &pen) | |
363 | { |
|
363 | { | |
364 | if (d_ptr->m_labelsPen != pen) { |
|
364 | if (d_ptr->m_labelsPen != pen) { | |
365 | d_ptr->m_labelsPen = pen; |
|
365 | d_ptr->m_labelsPen = pen; | |
366 | emit d_ptr->updated(); |
|
366 | emit d_ptr->updated(); | |
367 | } |
|
367 | } | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Returns the pen used to labels. |
|
371 | Returns the pen used to labels. | |
372 | */ |
|
372 | */ | |
373 | QPen QAbstractAxis::labelsPen() const |
|
373 | QPen QAbstractAxis::labelsPen() const | |
374 | { |
|
374 | { | |
375 | return d_ptr->m_labelsPen; |
|
375 | return d_ptr->m_labelsPen; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Sets \a brush used to draw labels. |
|
379 | Sets \a brush used to draw labels. | |
380 | */ |
|
380 | */ | |
381 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
381 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |
382 | { |
|
382 | { | |
383 | if (d_ptr->m_labelsBrush != brush) { |
|
383 | if (d_ptr->m_labelsBrush != brush) { | |
384 | d_ptr->m_labelsBrush = brush; |
|
384 | d_ptr->m_labelsBrush = brush; | |
385 | emit d_ptr->updated(); |
|
385 | emit d_ptr->updated(); | |
386 | } |
|
386 | } | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | /*! |
|
389 | /*! | |
390 | Returns brush used to draw labels. |
|
390 | Returns brush used to draw labels. | |
391 | */ |
|
391 | */ | |
392 | QBrush QAbstractAxis::labelsBrush() const |
|
392 | QBrush QAbstractAxis::labelsBrush() const | |
393 | { |
|
393 | { | |
394 | return d_ptr->m_labelsBrush; |
|
394 | return d_ptr->m_labelsBrush; | |
395 | } |
|
395 | } | |
396 |
|
396 | |||
397 | /*! |
|
397 | /*! | |
398 | Sets \a font used to draw labels. |
|
398 | Sets \a font used to draw labels. | |
399 | */ |
|
399 | */ | |
400 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
400 | void QAbstractAxis::setLabelsFont(const QFont &font) | |
401 | { |
|
401 | { | |
402 | if (d_ptr->m_labelsFont != font) { |
|
402 | if (d_ptr->m_labelsFont != font) { | |
403 | d_ptr->m_labelsFont = font; |
|
403 | d_ptr->m_labelsFont = font; | |
404 | emit d_ptr->updated(); |
|
404 | emit d_ptr->updated(); | |
405 | } |
|
405 | } | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | /*! |
|
408 | /*! | |
409 | Returns font used to draw labels. |
|
409 | Returns font used to draw labels. | |
410 | */ |
|
410 | */ | |
411 | QFont QAbstractAxis::labelsFont() const |
|
411 | QFont QAbstractAxis::labelsFont() const | |
412 | { |
|
412 | { | |
413 | return d_ptr->m_labelsFont; |
|
413 | return d_ptr->m_labelsFont; | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | void QAbstractAxis::setLabelsAngle(int angle) |
|
416 | void QAbstractAxis::setLabelsAngle(int angle) | |
417 | { |
|
417 | { | |
418 | if (d_ptr->m_labelsAngle != angle) { |
|
418 | if (d_ptr->m_labelsAngle != angle) { | |
419 | d_ptr->m_labelsAngle = angle; |
|
419 | d_ptr->m_labelsAngle = angle; | |
420 | emit d_ptr->updated(); |
|
420 | emit d_ptr->updated(); | |
421 | } |
|
421 | } | |
422 | } |
|
422 | } | |
423 |
|
423 | |||
424 | int QAbstractAxis::labelsAngle() const |
|
424 | int QAbstractAxis::labelsAngle() const | |
425 | { |
|
425 | { | |
426 | return d_ptr->m_labelsAngle; |
|
426 | return d_ptr->m_labelsAngle; | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | void QAbstractAxis::setLabelsColor(QColor color) |
|
429 | void QAbstractAxis::setLabelsColor(QColor color) | |
430 | { |
|
430 | { | |
431 | QBrush b = d_ptr->m_labelsBrush; |
|
431 | QBrush b = d_ptr->m_labelsBrush; | |
432 | if (b.color() != color) { |
|
432 | if (b.color() != color) { | |
433 | b.setColor(color); |
|
433 | b.setColor(color); | |
434 | setLabelsBrush(b); |
|
434 | setLabelsBrush(b); | |
435 | emit labelsColorChanged(color); |
|
435 | emit labelsColorChanged(color); | |
436 | } |
|
436 | } | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | QColor QAbstractAxis::labelsColor() const |
|
439 | QColor QAbstractAxis::labelsColor() const | |
440 | { |
|
440 | { | |
441 | return d_ptr->m_labelsBrush.color(); |
|
441 | return d_ptr->m_labelsBrush.color(); | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | void QAbstractAxis::setShadesVisible(bool visible) |
|
444 | void QAbstractAxis::setShadesVisible(bool visible) | |
445 | { |
|
445 | { | |
446 | if (d_ptr->m_shadesVisible != visible) { |
|
446 | if (d_ptr->m_shadesVisible != visible) { | |
447 | d_ptr->m_shadesVisible = visible; |
|
447 | d_ptr->m_shadesVisible = visible; | |
448 | emit d_ptr->updated(); |
|
448 | emit d_ptr->updated(); | |
449 | emit shadesVisibleChanged(visible); |
|
449 | emit shadesVisibleChanged(visible); | |
450 | } |
|
450 | } | |
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | bool QAbstractAxis::shadesVisible() const |
|
453 | bool QAbstractAxis::shadesVisible() const | |
454 | { |
|
454 | { | |
455 | return d_ptr->m_shadesVisible; |
|
455 | return d_ptr->m_shadesVisible; | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | /*! |
|
458 | /*! | |
459 | Sets \a pen used to draw shades. |
|
459 | Sets \a pen used to draw shades. | |
460 | */ |
|
460 | */ | |
461 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
461 | void QAbstractAxis::setShadesPen(const QPen &pen) | |
462 | { |
|
462 | { | |
463 | if (d_ptr->m_shadesPen != pen) { |
|
463 | if (d_ptr->m_shadesPen != pen) { | |
464 | d_ptr->m_shadesPen = pen; |
|
464 | d_ptr->m_shadesPen = pen; | |
465 | emit d_ptr->updated(); |
|
465 | emit d_ptr->updated(); | |
466 | } |
|
466 | } | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | /*! |
|
469 | /*! | |
470 | Returns pen used to draw shades. |
|
470 | Returns pen used to draw shades. | |
471 | */ |
|
471 | */ | |
472 | QPen QAbstractAxis::shadesPen() const |
|
472 | QPen QAbstractAxis::shadesPen() const | |
473 | { |
|
473 | { | |
474 | return d_ptr->m_shadesPen; |
|
474 | return d_ptr->m_shadesPen; | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | /*! |
|
477 | /*! | |
478 | Sets \a brush used to draw shades. |
|
478 | Sets \a brush used to draw shades. | |
479 | */ |
|
479 | */ | |
480 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
480 | void QAbstractAxis::setShadesBrush(const QBrush &brush) | |
481 | { |
|
481 | { | |
482 | if (d_ptr->m_shadesBrush != brush) { |
|
482 | if (d_ptr->m_shadesBrush != brush) { | |
483 | d_ptr->m_shadesBrush = brush; |
|
483 | d_ptr->m_shadesBrush = brush; | |
484 | emit d_ptr->updated(); |
|
484 | emit d_ptr->updated(); | |
485 | emit shadesColorChanged(brush.color()); |
|
485 | emit shadesColorChanged(brush.color()); | |
486 | } |
|
486 | } | |
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | /*! |
|
489 | /*! | |
490 | Returns brush used to draw shades. |
|
490 | Returns brush used to draw shades. | |
491 | */ |
|
491 | */ | |
492 | QBrush QAbstractAxis::shadesBrush() const |
|
492 | QBrush QAbstractAxis::shadesBrush() const | |
493 | { |
|
493 | { | |
494 | return d_ptr->m_shadesBrush; |
|
494 | return d_ptr->m_shadesBrush; | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | void QAbstractAxis::setShadesColor(QColor color) |
|
497 | void QAbstractAxis::setShadesColor(QColor color) | |
498 | { |
|
498 | { | |
499 | QBrush b = d_ptr->m_shadesBrush; |
|
499 | QBrush b = d_ptr->m_shadesBrush; | |
500 | b.setColor(color); |
|
500 | b.setColor(color); | |
501 | setShadesBrush(b); |
|
501 | setShadesBrush(b); | |
502 | } |
|
502 | } | |
503 |
|
503 | |||
504 | QColor QAbstractAxis::shadesColor() const |
|
504 | QColor QAbstractAxis::shadesColor() const | |
505 | { |
|
505 | { | |
506 | return d_ptr->m_shadesBrush.color(); |
|
506 | return d_ptr->m_shadesBrush.color(); | |
507 | } |
|
507 | } | |
508 |
|
508 | |||
509 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
509 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
510 | { |
|
510 | { | |
511 | QPen p = d_ptr->m_shadesPen; |
|
511 | QPen p = d_ptr->m_shadesPen; | |
512 | p.setColor(color); |
|
512 | p.setColor(color); | |
513 | setShadesPen(p); |
|
513 | setShadesPen(p); | |
514 | } |
|
514 | } | |
515 |
|
515 | |||
516 | QColor QAbstractAxis::shadesBorderColor() const |
|
516 | QColor QAbstractAxis::shadesBorderColor() const | |
517 | { |
|
517 | { | |
518 | return d_ptr->m_shadesPen.color(); |
|
518 | return d_ptr->m_shadesPen.color(); | |
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 |
|
521 | |||
|
522 | bool QAbstractAxis::isVisible() const | |||
|
523 | { | |||
|
524 | return d_ptr->m_visible; | |||
|
525 | } | |||
|
526 | ||||
522 | /*! |
|
527 | /*! | |
523 | Sets axis, shades, labels and grid lines to be visible. |
|
528 | Sets axis, shades, labels and grid lines to be visible. | |
524 | */ |
|
529 | */ | |
525 |
void QAbstractAxis::s |
|
530 | void QAbstractAxis::setVisible(bool visible) | |
526 | { |
|
531 | { | |
527 |
d_ptr->m_ |
|
532 | d_ptr->m_visible=visible; | |
528 | d_ptr->m_gridLineVisible=true; |
|
|||
529 | d_ptr->m_labelsVisible=true; |
|
|||
530 | d_ptr->m_shadesVisible=true; |
|
|||
531 | emit d_ptr->updated(); |
|
533 | emit d_ptr->updated(); | |
532 | } |
|
534 | } | |
533 |
|
535 | |||
|
536 | ||||
|
537 | /*! | |||
|
538 | Sets axis, shades, labels and grid lines to be visible. | |||
|
539 | */ | |||
|
540 | void QAbstractAxis::show() | |||
|
541 | { | |||
|
542 | setVisible(true); | |||
|
543 | } | |||
|
544 | ||||
534 | /*! |
|
545 | /*! | |
535 | Sets axis, shades, labels and grid lines to not be visible. |
|
546 | Sets axis, shades, labels and grid lines to not be visible. | |
536 | */ |
|
547 | */ | |
537 | void QAbstractAxis::hide() |
|
548 | void QAbstractAxis::hide() | |
538 | { |
|
549 | { | |
539 |
|
|
550 | setVisible(false); | |
540 | d_ptr->m_gridLineVisible = false; |
|
|||
541 | d_ptr->m_labelsVisible = false; |
|
|||
542 | d_ptr->m_shadesVisible = false; |
|
|||
543 | emit d_ptr->updated(); |
|
|||
544 | } |
|
551 | } | |
545 |
|
552 | |||
546 |
|
553 | |||
547 | void QAbstractAxis::setMin(const QVariant &min) |
|
554 | void QAbstractAxis::setMin(const QVariant &min) | |
548 | { |
|
555 | { | |
549 | d_ptr->setMin(min); |
|
556 | d_ptr->setMin(min); | |
550 | } |
|
557 | } | |
551 | void QAbstractAxis::setMax(const QVariant &max) |
|
558 | void QAbstractAxis::setMax(const QVariant &max) | |
552 | { |
|
559 | { | |
553 | d_ptr->setMax(max); |
|
560 | d_ptr->setMax(max); | |
554 | } |
|
561 | } | |
555 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
562 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
556 | { |
|
563 | { | |
557 | d_ptr->setRange(min,max); |
|
564 | d_ptr->setRange(min,max); | |
558 | } |
|
565 | } | |
559 |
|
566 | |||
560 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
567 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
561 |
|
568 | |||
562 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): |
|
569 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis* q): | |
563 | q_ptr(q), |
|
570 | q_ptr(q), | |
|
571 | m_visible(true), | |||
564 | m_axisVisible(true), |
|
572 | m_axisVisible(true), | |
565 | m_gridLineVisible(true), |
|
573 | m_gridLineVisible(true), | |
566 | m_labelsVisible(true), |
|
574 | m_labelsVisible(true), | |
567 | m_labelsAngle(0), |
|
575 | m_labelsAngle(0), | |
568 | m_shadesVisible(false), |
|
576 | m_shadesVisible(false), | |
569 | m_shadesBrush(Qt::SolidPattern), |
|
577 | m_shadesBrush(Qt::SolidPattern), | |
570 | m_shadesOpacity(1.0), |
|
578 | m_shadesOpacity(1.0), | |
571 | m_orientation(Qt::Orientation(0)), |
|
579 | m_orientation(Qt::Orientation(0)), | |
572 | m_min(0), |
|
580 | m_min(0), | |
573 | m_max(0), |
|
581 | m_max(0), | |
574 | m_ticksCount(5) |
|
582 | m_ticksCount(5) | |
575 | { |
|
583 | { | |
576 |
|
584 | |||
577 | } |
|
585 | } | |
578 |
|
586 | |||
579 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
587 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
580 | { |
|
588 | { | |
581 |
|
589 | |||
582 | } |
|
590 | } | |
583 |
|
591 | |||
584 | #include "moc_qabstractaxis.cpp" |
|
592 | #include "moc_qabstractaxis.cpp" | |
585 | #include "moc_qabstractaxis_p.cpp" |
|
593 | #include "moc_qabstractaxis_p.cpp" | |
586 |
|
594 | |||
587 | QTCOMMERCIALCHART_END_NAMESPACE |
|
595 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,133 +1,139 | |||||
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 QABSTRACTAXIS_H |
|
21 | #ifndef QABSTRACTAXIS_H | |
22 | #define QABSTRACTAXIS_H |
|
22 | #define QABSTRACTAXIS_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QFont> |
|
26 | #include <QFont> | |
27 | #include <QVariant> |
|
27 | #include <QVariant> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAbstractAxisPrivate; |
|
31 | class QAbstractAxisPrivate; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 |
|
36 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | ||
37 |
Q_PROPERTY(bool |
|
37 | Q_PROPERTY(bool axisVisible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged) | |
38 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) |
|
38 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) | |
39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) | |
41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) |
|
41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) | |
42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) | |
43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) | |
44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) | |
45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) | |
46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) | |
47 |
|
47 | |||
48 | public: |
|
48 | public: | |
49 |
|
49 | |||
50 | enum AxisType { |
|
50 | enum AxisType { | |
51 | AxisTypeNoAxis = 0x0, |
|
51 | AxisTypeNoAxis = 0x0, | |
52 | AxisTypeValues = 0x1, |
|
52 | AxisTypeValues = 0x1, | |
53 | AxisTypeCategories = 0x2 |
|
53 | AxisTypeCategories = 0x2 | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | Q_DECLARE_FLAGS(AxisTypes, AxisType) |
|
56 | Q_DECLARE_FLAGS(AxisTypes, AxisType) | |
57 |
|
57 | |||
58 | protected: |
|
58 | protected: | |
59 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); |
|
59 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); | |
60 |
|
60 | |||
61 | public: |
|
61 | public: | |
62 | ~QAbstractAxis(); |
|
62 | ~QAbstractAxis(); | |
63 |
|
63 | |||
64 | virtual AxisType type() const = 0; |
|
64 | virtual AxisType type() const = 0; | |
65 |
|
65 | |||
|
66 | //visibilty hadnling | |||
|
67 | bool isVisible() const; | |||
|
68 | void setVisible(bool visible = true); | |||
|
69 | ||||
|
70 | ||||
66 | //axis handling |
|
71 | //axis handling | |
67 | bool isAxisVisible() const; |
|
72 | bool isAxisVisible() const; | |
68 | void setAxisVisible(bool visible = true); |
|
73 | void setAxisVisible(bool visible = true); | |
69 | void setAxisPen(const QPen &pen); |
|
74 | void setAxisPen(const QPen &pen); | |
70 | QPen axisPen() const; |
|
75 | QPen axisPen() const; | |
71 | void setAxisPenColor(QColor color); |
|
76 | void setAxisPenColor(QColor color); | |
72 | QColor axisPenColor() const; |
|
77 | QColor axisPenColor() const; | |
73 |
|
78 | |||
74 | //grid handling |
|
79 | //grid handling | |
75 | bool isGridLineVisible() const; |
|
80 | bool isGridLineVisible() const; | |
76 | void setGridLineVisible(bool visible = true); |
|
81 | void setGridLineVisible(bool visible = true); | |
77 | void setGridLinePen(const QPen &pen); |
|
82 | void setGridLinePen(const QPen &pen); | |
78 | QPen gridLinePen() const; |
|
83 | QPen gridLinePen() const; | |
79 |
|
84 | |||
80 | //labels handling |
|
85 | //labels handling | |
81 | bool labelsVisible() const; |
|
86 | bool labelsVisible() const; | |
82 | void setLabelsVisible(bool visible = true); |
|
87 | void setLabelsVisible(bool visible = true); | |
83 | void setLabelsPen(const QPen &pen); |
|
88 | void setLabelsPen(const QPen &pen); | |
84 | QPen labelsPen() const; |
|
89 | QPen labelsPen() const; | |
85 | void setLabelsBrush(const QBrush &brush); |
|
90 | void setLabelsBrush(const QBrush &brush); | |
86 | QBrush labelsBrush() const; |
|
91 | QBrush labelsBrush() const; | |
87 | void setLabelsFont(const QFont &font); |
|
92 | void setLabelsFont(const QFont &font); | |
88 | QFont labelsFont() const; |
|
93 | QFont labelsFont() const; | |
89 | void setLabelsAngle(int angle); |
|
94 | void setLabelsAngle(int angle); | |
90 | int labelsAngle() const; |
|
95 | int labelsAngle() const; | |
91 | void setLabelsColor(QColor color); |
|
96 | void setLabelsColor(QColor color); | |
92 | QColor labelsColor() const; |
|
97 | QColor labelsColor() const; | |
93 |
|
98 | |||
94 | //shades handling |
|
99 | //shades handling | |
95 | bool shadesVisible() const; |
|
100 | bool shadesVisible() const; | |
96 | void setShadesVisible(bool visible = true); |
|
101 | void setShadesVisible(bool visible = true); | |
97 | void setShadesPen(const QPen &pen); |
|
102 | void setShadesPen(const QPen &pen); | |
98 | QPen shadesPen() const; |
|
103 | QPen shadesPen() const; | |
99 | void setShadesBrush(const QBrush &brush); |
|
104 | void setShadesBrush(const QBrush &brush); | |
100 | QBrush shadesBrush() const; |
|
105 | QBrush shadesBrush() const; | |
101 | void setShadesColor(QColor color); |
|
106 | void setShadesColor(QColor color); | |
102 | QColor shadesColor() const; |
|
107 | QColor shadesColor() const; | |
103 | void setShadesBorderColor(QColor color); |
|
108 | void setShadesBorderColor(QColor color); | |
104 | QColor shadesBorderColor() const; |
|
109 | QColor shadesBorderColor() const; | |
105 |
|
110 | |||
106 | //range handling |
|
111 | //range handling | |
107 | void setMin(const QVariant &min); |
|
112 | void setMin(const QVariant &min); | |
108 | void setMax(const QVariant &max); |
|
113 | void setMax(const QVariant &max); | |
109 | void setRange(const QVariant &min, const QVariant &max); |
|
114 | void setRange(const QVariant &min, const QVariant &max); | |
110 |
|
115 | |||
111 | void show(); |
|
116 | void show(); | |
112 | void hide(); |
|
117 | void hide(); | |
113 |
|
118 | |||
114 | Q_SIGNALS: |
|
119 | Q_SIGNALS: | |
115 | void visibleChanged(bool visible); |
|
120 | void visibleChanged(bool visible); | |
|
121 | void axisVisibleChanged(bool visible); | |||
116 | void labelsVisibleChanged(bool visible); |
|
122 | void labelsVisibleChanged(bool visible); | |
117 | void gridVisibleChanged(bool visible); |
|
123 | void gridVisibleChanged(bool visible); | |
118 | void colorChanged(QColor color); |
|
124 | void colorChanged(QColor color); | |
119 | void labelsColorChanged(QColor color); |
|
125 | void labelsColorChanged(QColor color); | |
120 | void shadesVisibleChanged(bool visible); |
|
126 | void shadesVisibleChanged(bool visible); | |
121 | void shadesColorChanged(QColor color); |
|
127 | void shadesColorChanged(QColor color); | |
122 | void shadesBorderColorChanged(QColor color); |
|
128 | void shadesBorderColorChanged(QColor color); | |
123 |
|
129 | |||
124 | protected: |
|
130 | protected: | |
125 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
131 | QScopedPointer<QAbstractAxisPrivate> d_ptr; | |
126 | Q_DISABLE_COPY(QAbstractAxis); |
|
132 | Q_DISABLE_COPY(QAbstractAxis); | |
127 | friend class ChartDataSet; |
|
133 | friend class ChartDataSet; | |
128 | friend class ChartAxis; |
|
134 | friend class ChartAxis; | |
129 | friend class ChartPresenter; |
|
135 | friend class ChartPresenter; | |
130 | }; |
|
136 | }; | |
131 |
|
137 | |||
132 | QTCOMMERCIALCHART_END_NAMESPACE |
|
138 | QTCOMMERCIALCHART_END_NAMESPACE | |
133 | #endif |
|
139 | #endif |
@@ -1,93 +1,94 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
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 |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QABSTRACTAXIS_P_H |
|
30 | #ifndef QABSTRACTAXIS_P_H | |
31 | #define QABSTRACTAXIS_P_H |
|
31 | #define QABSTRACTAXIS_P_H | |
32 |
|
32 | |||
33 | #include "qabstractaxis.h" |
|
33 | #include "qabstractaxis.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class ChartPresenter; |
|
37 | class ChartPresenter; | |
38 | class ChartAxis; |
|
38 | class ChartAxis; | |
39 |
|
39 | |||
40 | class QAbstractAxisPrivate : public QObject |
|
40 | class QAbstractAxisPrivate : public QObject | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 | public: |
|
43 | public: | |
44 | QAbstractAxisPrivate(QAbstractAxis *q); |
|
44 | QAbstractAxisPrivate(QAbstractAxis *q); | |
45 | ~QAbstractAxisPrivate(); |
|
45 | ~QAbstractAxisPrivate(); | |
46 |
|
46 | |||
47 | Q_SIGNALS: |
|
47 | Q_SIGNALS: | |
48 | void updated(); |
|
48 | void updated(); | |
49 |
|
49 | |||
50 | public: |
|
50 | public: | |
51 | virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0; |
|
51 | virtual ChartAxis* createGraphics(ChartPresenter* presenter) = 0; | |
52 | virtual void emitRange() = 0; |
|
52 | virtual void emitRange() = 0; | |
53 |
|
53 | |||
54 | protected: |
|
54 | protected: | |
55 | virtual void setMin(const QVariant &min) = 0; |
|
55 | virtual void setMin(const QVariant &min) = 0; | |
56 | virtual void setMax(const QVariant &max) = 0; |
|
56 | virtual void setMax(const QVariant &max) = 0; | |
57 | virtual void setRange(const QVariant &min, const QVariant &max) = 0; |
|
57 | virtual void setRange(const QVariant &min, const QVariant &max) = 0; | |
58 | virtual int ticksCount() const = 0; |
|
58 | virtual int ticksCount() const = 0; | |
59 |
|
59 | |||
60 | public: |
|
60 | public: | |
61 | QAbstractAxis *q_ptr; |
|
61 | QAbstractAxis *q_ptr; | |
|
62 | bool m_visible; | |||
62 |
|
63 | |||
63 | bool m_axisVisible; |
|
64 | bool m_axisVisible; | |
64 | QPen m_axisPen; |
|
65 | QPen m_axisPen; | |
65 | QBrush m_axisBrush; |
|
66 | QBrush m_axisBrush; | |
66 |
|
67 | |||
67 | bool m_gridLineVisible; |
|
68 | bool m_gridLineVisible; | |
68 | QPen m_gridLinePen; |
|
69 | QPen m_gridLinePen; | |
69 |
|
70 | |||
70 | bool m_labelsVisible; |
|
71 | bool m_labelsVisible; | |
71 | QPen m_labelsPen; |
|
72 | QPen m_labelsPen; | |
72 | QBrush m_labelsBrush; |
|
73 | QBrush m_labelsBrush; | |
73 | QFont m_labelsFont; |
|
74 | QFont m_labelsFont; | |
74 | int m_labelsAngle; |
|
75 | int m_labelsAngle; | |
75 |
|
76 | |||
76 | bool m_shadesVisible; |
|
77 | bool m_shadesVisible; | |
77 | QPen m_shadesPen; |
|
78 | QPen m_shadesPen; | |
78 | QBrush m_shadesBrush; |
|
79 | QBrush m_shadesBrush; | |
79 | qreal m_shadesOpacity; |
|
80 | qreal m_shadesOpacity; | |
80 |
|
81 | |||
81 | Qt::Orientation m_orientation; |
|
82 | Qt::Orientation m_orientation; | |
82 |
|
83 | |||
83 | // range |
|
84 | // range | |
84 | qreal m_min; |
|
85 | qreal m_min; | |
85 | qreal m_max; |
|
86 | qreal m_max; | |
86 | int m_ticksCount; |
|
87 | int m_ticksCount; | |
87 |
|
88 | |||
88 | friend class QAbstractAxis; |
|
89 | friend class QAbstractAxis; | |
89 | }; |
|
90 | }; | |
90 |
|
91 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
93 | |||
93 | #endif |
|
94 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now