@@ -1,383 +1,381 | |||||
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 "qaxiscategories_p.h" |
|
|||
25 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
26 | #include "chartanimator_p.h" |
|
25 | #include "chartanimator_p.h" | |
27 | #include <QPainter> |
|
26 | #include <QPainter> | |
28 | #include <QDebug> |
|
27 | #include <QDebug> | |
29 | #include <cmath> |
|
28 | #include <cmath> | |
30 |
|
29 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
31 | |||
33 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter), |
|
32 | ChartAxis::ChartAxis(QAbstractAxis *axis,ChartPresenter *presenter) : Chart(presenter), | |
34 | m_chartAxis(axis), |
|
33 | m_chartAxis(axis), | |
35 | m_labelsAngle(0), |
|
34 | m_labelsAngle(0), | |
36 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), |
|
35 | m_grid(new QGraphicsItemGroup(presenter->rootItem())), | |
37 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), |
|
36 | m_shades(new QGraphicsItemGroup(presenter->rootItem())), | |
38 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), |
|
37 | m_labels(new QGraphicsItemGroup(presenter->rootItem())), | |
39 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), |
|
38 | m_axis(new QGraphicsItemGroup(presenter->rootItem())), | |
40 | m_min(0), |
|
39 | m_min(0), | |
41 | m_max(0), |
|
40 | m_max(0), | |
42 | m_ticksCount(0), |
|
41 | m_ticksCount(0), | |
43 | m_animation(0), |
|
42 | m_animation(0), | |
44 | m_minWidth(0), |
|
43 | m_minWidth(0), | |
45 | m_minHeight(0) |
|
44 | m_minHeight(0) | |
46 | { |
|
45 | { | |
47 | //initial initialization |
|
46 | //initial initialization | |
48 | m_axis->setZValue(ChartPresenter::AxisZValue); |
|
47 | m_axis->setZValue(ChartPresenter::AxisZValue); | |
49 | m_axis->setHandlesChildEvents(false); |
|
48 | m_axis->setHandlesChildEvents(false); | |
50 |
|
49 | |||
51 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
50 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
52 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
51 | m_grid->setZValue(ChartPresenter::GridZValue); | |
53 |
|
52 | |||
54 | 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())); | |
55 |
|
54 | |||
56 | QGraphicsSimpleTextItem item; |
|
55 | QGraphicsSimpleTextItem item; | |
57 | m_font = item.font(); |
|
56 | m_font = item.font(); | |
58 |
|
57 | |||
59 | handleAxisUpdated(); |
|
58 | handleAxisUpdated(); | |
60 | } |
|
59 | } | |
61 |
|
60 | |||
62 | ChartAxis::~ChartAxis() |
|
61 | ChartAxis::~ChartAxis() | |
63 | { |
|
62 | { | |
64 | } |
|
63 | } | |
65 |
|
64 | |||
66 | void ChartAxis::setAnimation(AxisAnimation* animation) |
|
65 | void ChartAxis::setAnimation(AxisAnimation* animation) | |
67 | { |
|
66 | { | |
68 | m_animation=animation; |
|
67 | m_animation=animation; | |
69 | } |
|
68 | } | |
70 |
|
69 | |||
71 | void ChartAxis::setLayout(QVector<qreal> &layout) |
|
70 | void ChartAxis::setLayout(QVector<qreal> &layout) | |
72 | { |
|
71 | { | |
73 | m_layoutVector=layout; |
|
72 | m_layoutVector=layout; | |
74 | } |
|
73 | } | |
75 |
|
74 | |||
76 | void ChartAxis::createItems(int count) |
|
75 | void ChartAxis::createItems(int count) | |
77 | { |
|
76 | { | |
78 | if (m_axis->children().size() == 0) |
|
77 | if (m_axis->children().size() == 0) | |
79 | m_axis->addToGroup(new AxisItem(this)); |
|
78 | m_axis->addToGroup(new AxisItem(this)); | |
80 | for (int i = 0; i < count; ++i) { |
|
79 | for (int i = 0; i < count; ++i) { | |
81 | m_grid->addToGroup(new QGraphicsLineItem()); |
|
80 | m_grid->addToGroup(new QGraphicsLineItem()); | |
82 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); |
|
81 | m_labels->addToGroup(new QGraphicsSimpleTextItem()); | |
83 | m_axis->addToGroup(new QGraphicsLineItem()); |
|
82 | m_axis->addToGroup(new QGraphicsLineItem()); | |
84 | 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()); | |
85 | } |
|
84 | } | |
86 | } |
|
85 | } | |
87 |
|
86 | |||
88 | void ChartAxis::deleteItems(int count) |
|
87 | void ChartAxis::deleteItems(int count) | |
89 | { |
|
88 | { | |
90 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
89 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
91 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
90 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
92 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
91 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
93 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
92 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
94 |
|
93 | |||
95 | for (int i = 0; i < count; ++i) { |
|
94 | for (int i = 0; i < count; ++i) { | |
96 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); |
|
95 | if (lines.size()%2 && lines.size() > 1) delete(shades.takeLast()); | |
97 | delete(lines.takeLast()); |
|
96 | delete(lines.takeLast()); | |
98 | delete(labels.takeLast()); |
|
97 | delete(labels.takeLast()); | |
99 | delete(axis.takeLast()); |
|
98 | delete(axis.takeLast()); | |
100 | } |
|
99 | } | |
101 | } |
|
100 | } | |
102 |
|
101 | |||
103 | void ChartAxis::updateLayout(QVector<qreal> &layout) |
|
102 | void ChartAxis::updateLayout(QVector<qreal> &layout) | |
104 | { |
|
103 | { | |
105 | int diff = m_layoutVector.size() - layout.size(); |
|
104 | int diff = m_layoutVector.size() - layout.size(); | |
106 |
|
105 | |||
107 | if (diff>0) { |
|
106 | if (diff>0) { | |
108 | deleteItems(diff); |
|
107 | deleteItems(diff); | |
109 | } |
|
108 | } | |
110 | else if (diff<0) { |
|
109 | else if (diff<0) { | |
111 | createItems(-diff); |
|
110 | createItems(-diff); | |
112 | } |
|
111 | } | |
113 |
|
112 | |||
114 | if( diff!=0) handleAxisUpdated(); |
|
113 | if( diff!=0) handleAxisUpdated(); | |
115 |
|
114 | |||
116 | if (m_animation) { |
|
115 | if (m_animation) { | |
117 | switch(presenter()->state()){ |
|
116 | switch(presenter()->state()){ | |
118 | case ChartPresenter::ZoomInState: |
|
117 | case ChartPresenter::ZoomInState: | |
119 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); |
|
118 | m_animation->setAnimationType(AxisAnimation::ZoomInAnimation); | |
120 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
119 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
121 | break; |
|
120 | break; | |
122 | case ChartPresenter::ZoomOutState: |
|
121 | case ChartPresenter::ZoomOutState: | |
123 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); |
|
122 | m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation); | |
124 | m_animation->setAnimationPoint(presenter()->statePoint()); |
|
123 | m_animation->setAnimationPoint(presenter()->statePoint()); | |
125 | break; |
|
124 | break; | |
126 | case ChartPresenter::ScrollUpState: |
|
125 | case ChartPresenter::ScrollUpState: | |
127 | case ChartPresenter::ScrollLeftState: |
|
126 | case ChartPresenter::ScrollLeftState: | |
128 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); |
|
127 | m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation); | |
129 | break; |
|
128 | break; | |
130 | case ChartPresenter::ScrollDownState: |
|
129 | case ChartPresenter::ScrollDownState: | |
131 | case ChartPresenter::ScrollRightState: |
|
130 | case ChartPresenter::ScrollRightState: | |
132 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); |
|
131 | m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation); | |
133 | break; |
|
132 | break; | |
134 | case ChartPresenter::ShowState: |
|
133 | case ChartPresenter::ShowState: | |
135 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); |
|
134 | m_animation->setAnimationType(AxisAnimation::DefaultAnimation); | |
136 | break; |
|
135 | break; | |
137 | } |
|
136 | } | |
138 | m_animation->setValues(m_layoutVector,layout); |
|
137 | m_animation->setValues(m_layoutVector,layout); | |
139 | presenter()->startAnimation(m_animation); |
|
138 | presenter()->startAnimation(m_animation); | |
140 | } |
|
139 | } | |
141 | else { |
|
140 | else { | |
142 | setLayout(layout); |
|
141 | setLayout(layout); | |
143 | updateGeometry(); |
|
142 | updateGeometry(); | |
144 | } |
|
143 | } | |
145 | } |
|
144 | } | |
146 |
|
145 | |||
147 | bool ChartAxis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const |
|
146 | bool ChartAxis::createLabels(QStringList &labels,qreal min, qreal max,int ticks) const | |
148 | { |
|
147 | { | |
149 | Q_ASSERT(max>min); |
|
148 | Q_ASSERT(max>min); | |
150 | Q_ASSERT(ticks>1); |
|
149 | Q_ASSERT(ticks>1); | |
151 |
|
150 | |||
152 | //TODO:: QAxisCategories* categories = m_chartAxis->categories(); |
|
151 | //TODO:: QAxisCategories* categories = m_chartAxis->categories(); | |
153 | // QAxisCategories* categories = new QAxisCategories(); |
|
152 | // QAxisCategories* categories = new QAxisCategories(); | |
154 |
|
153 | |||
155 | // bool category = categories->count()>0; |
|
154 | // bool category = categories->count()>0; | |
156 |
|
155 | |||
157 | // if (!category) { |
|
156 | // if (!category) { | |
158 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); |
|
157 | int n = qMax(int(-floor(log10((max-min)/(ticks-1)))),0); | |
159 | n++; |
|
158 | n++; | |
160 | for (int i=0; i< ticks; i++) { |
|
159 | for (int i=0; i< ticks; i++) { | |
161 | qreal value = min + (i * (max - min)/ (ticks-1)); |
|
160 | qreal value = min + (i * (max - min)/ (ticks-1)); | |
162 | Q_UNUSED(value); |
|
161 | Q_UNUSED(value); | |
163 | labels << QString::number(value,'f',n); |
|
162 | labels << QString::number(value,'f',n); | |
164 | } |
|
163 | } | |
165 | // } else { |
|
164 | // } else { | |
166 | // QList<qreal> values = categories->values(); |
|
165 | // QList<qreal> values = categories->values(); | |
167 | // for (int i=0; i< ticks; i++) { |
|
166 | // for (int i=0; i< ticks; i++) { | |
168 | // qreal value = (min + (i * (max - min)/ (ticks-1))); |
|
167 | // qreal value = (min + (i * (max - min)/ (ticks-1))); | |
169 | // int j=0; |
|
168 | // int j=0; | |
170 | // for (; j<values.count(); j++) { |
|
169 | // for (; j<values.count(); j++) { | |
171 | // if (values.at(j) > value) break; |
|
170 | // if (values.at(j) > value) break; | |
172 | // } |
|
171 | // } | |
173 | // if (j!=0) value=values.at(j-1); |
|
172 | // if (j!=0) value=values.at(j-1); | |
174 |
|
173 | |||
175 | // QString label = categories->label(value); |
|
174 | // QString label = categories->label(value); | |
176 | // labels << label; |
|
175 | // labels << label; | |
177 | // } |
|
176 | // } | |
178 | // } |
|
177 | // } | |
179 |
|
178 | |||
180 | // return category; |
|
179 | // return category; | |
181 | return true; |
|
180 | return true; | |
182 | } |
|
181 | } | |
183 |
|
182 | |||
184 | void ChartAxis::setAxisOpacity(qreal opacity) |
|
183 | void ChartAxis::setAxisOpacity(qreal opacity) | |
185 | { |
|
184 | { | |
186 | m_axis->setOpacity(opacity); |
|
185 | m_axis->setOpacity(opacity); | |
187 | } |
|
186 | } | |
188 |
|
187 | |||
189 | qreal ChartAxis::axisOpacity() const |
|
188 | qreal ChartAxis::axisOpacity() const | |
190 | { |
|
189 | { | |
191 | return m_axis->opacity(); |
|
190 | return m_axis->opacity(); | |
192 | } |
|
191 | } | |
193 |
|
192 | |||
194 | void ChartAxis::setGridOpacity(qreal opacity) |
|
193 | void ChartAxis::setGridOpacity(qreal opacity) | |
195 | { |
|
194 | { | |
196 | m_grid->setOpacity(opacity); |
|
195 | m_grid->setOpacity(opacity); | |
197 | } |
|
196 | } | |
198 |
|
197 | |||
199 | qreal ChartAxis::gridOpacity() const |
|
198 | qreal ChartAxis::gridOpacity() const | |
200 | { |
|
199 | { | |
201 | return m_grid->opacity(); |
|
200 | return m_grid->opacity(); | |
202 | } |
|
201 | } | |
203 |
|
202 | |||
204 | void ChartAxis::setLabelsOpacity(qreal opacity) |
|
203 | void ChartAxis::setLabelsOpacity(qreal opacity) | |
205 | { |
|
204 | { | |
206 | m_labels->setOpacity(opacity); |
|
205 | m_labels->setOpacity(opacity); | |
207 | } |
|
206 | } | |
208 | #include "qaxiscategories.h" |
|
|||
209 |
|
207 | |||
210 | qreal ChartAxis::labelsOpacity() const |
|
208 | qreal ChartAxis::labelsOpacity() const | |
211 | { |
|
209 | { | |
212 | return m_labels->opacity(); |
|
210 | return m_labels->opacity(); | |
213 | } |
|
211 | } | |
214 |
|
212 | |||
215 | void ChartAxis::setShadesOpacity(qreal opacity) |
|
213 | void ChartAxis::setShadesOpacity(qreal opacity) | |
216 | { |
|
214 | { | |
217 | m_shades->setOpacity(opacity); |
|
215 | m_shades->setOpacity(opacity); | |
218 | } |
|
216 | } | |
219 |
|
217 | |||
220 | qreal ChartAxis::shadesOpacity() const |
|
218 | qreal ChartAxis::shadesOpacity() const | |
221 | { |
|
219 | { | |
222 | return m_shades->opacity(); |
|
220 | return m_shades->opacity(); | |
223 | } |
|
221 | } | |
224 |
|
222 | |||
225 | void ChartAxis::setLabelsAngle(int angle) |
|
223 | void ChartAxis::setLabelsAngle(int angle) | |
226 | { |
|
224 | { | |
227 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
225 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
228 | item->setRotation(angle); |
|
226 | item->setRotation(angle); | |
229 | } |
|
227 | } | |
230 |
|
228 | |||
231 | m_labelsAngle=angle; |
|
229 | m_labelsAngle=angle; | |
232 | } |
|
230 | } | |
233 |
|
231 | |||
234 | void ChartAxis::setLabelsPen(const QPen &pen) |
|
232 | void ChartAxis::setLabelsPen(const QPen &pen) | |
235 | { |
|
233 | { | |
236 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
234 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
237 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); |
|
235 | static_cast<QGraphicsSimpleTextItem*>(item)->setPen(pen); | |
238 | } |
|
236 | } | |
239 | } |
|
237 | } | |
240 |
|
238 | |||
241 | void ChartAxis::setLabelsBrush(const QBrush &brush) |
|
239 | void ChartAxis::setLabelsBrush(const QBrush &brush) | |
242 | { |
|
240 | { | |
243 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
241 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
244 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); |
|
242 | static_cast<QGraphicsSimpleTextItem*>(item)->setBrush(brush); | |
245 | } |
|
243 | } | |
246 | } |
|
244 | } | |
247 |
|
245 | |||
248 | void ChartAxis::setLabelsFont(const QFont &font) |
|
246 | void ChartAxis::setLabelsFont(const QFont &font) | |
249 | { |
|
247 | { | |
250 | foreach(QGraphicsItem* item , m_labels->childItems()) { |
|
248 | foreach(QGraphicsItem* item , m_labels->childItems()) { | |
251 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); |
|
249 | static_cast<QGraphicsSimpleTextItem*>(item)->setFont(font); | |
252 | } |
|
250 | } | |
253 | m_font = font; |
|
251 | m_font = font; | |
254 | } |
|
252 | } | |
255 |
|
253 | |||
256 | void ChartAxis::setShadesBrush(const QBrush &brush) |
|
254 | void ChartAxis::setShadesBrush(const QBrush &brush) | |
257 | { |
|
255 | { | |
258 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
256 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
259 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); |
|
257 | static_cast<QGraphicsRectItem*>(item)->setBrush(brush); | |
260 | } |
|
258 | } | |
261 | } |
|
259 | } | |
262 |
|
260 | |||
263 | void ChartAxis::setShadesPen(const QPen &pen) |
|
261 | void ChartAxis::setShadesPen(const QPen &pen) | |
264 | { |
|
262 | { | |
265 | foreach(QGraphicsItem* item , m_shades->childItems()) { |
|
263 | foreach(QGraphicsItem* item , m_shades->childItems()) { | |
266 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); |
|
264 | static_cast<QGraphicsRectItem*>(item)->setPen(pen); | |
267 | } |
|
265 | } | |
268 | } |
|
266 | } | |
269 |
|
267 | |||
270 | void ChartAxis::setAxisPen(const QPen &pen) |
|
268 | void ChartAxis::setAxisPen(const QPen &pen) | |
271 | { |
|
269 | { | |
272 | foreach(QGraphicsItem* item , m_axis->childItems()) { |
|
270 | foreach(QGraphicsItem* item , m_axis->childItems()) { | |
273 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
271 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
274 | } |
|
272 | } | |
275 | } |
|
273 | } | |
276 |
|
274 | |||
277 | void ChartAxis::setGridPen(const QPen &pen) |
|
275 | void ChartAxis::setGridPen(const QPen &pen) | |
278 | { |
|
276 | { | |
279 | foreach(QGraphicsItem* item , m_grid->childItems()) { |
|
277 | foreach(QGraphicsItem* item , m_grid->childItems()) { | |
280 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); |
|
278 | static_cast<QGraphicsLineItem*>(item)->setPen(pen); | |
281 | } |
|
279 | } | |
282 | } |
|
280 | } | |
283 |
|
281 | |||
284 | bool ChartAxis::isEmpty() |
|
282 | bool ChartAxis::isEmpty() | |
285 | { |
|
283 | { | |
286 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; |
|
284 | return m_rect.isEmpty() || qFuzzyIsNull(m_min - m_max) || m_ticksCount==0; | |
287 | } |
|
285 | } | |
288 |
|
286 | |||
289 | //handlers |
|
287 | //handlers | |
290 |
|
288 | |||
291 | void ChartAxis::handleAxisCategoriesUpdated() |
|
289 | void ChartAxis::handleAxisCategoriesUpdated() | |
292 | { |
|
290 | { | |
293 | if (isEmpty()) return; |
|
291 | if (isEmpty()) return; | |
294 | updateLayout(m_layoutVector); |
|
292 | updateLayout(m_layoutVector); | |
295 | } |
|
293 | } | |
296 |
|
294 | |||
297 | void ChartAxis::handleAxisUpdated() |
|
295 | void ChartAxis::handleAxisUpdated() | |
298 | { |
|
296 | { | |
299 |
|
297 | |||
300 | if (isEmpty()) return; |
|
298 | if (isEmpty()) return; | |
301 |
|
299 | |||
302 | if (m_chartAxis->isAxisVisible()) { |
|
300 | if (m_chartAxis->isAxisVisible()) { | |
303 | setAxisOpacity(100); |
|
301 | setAxisOpacity(100); | |
304 | } else { |
|
302 | } else { | |
305 | setAxisOpacity(0); |
|
303 | setAxisOpacity(0); | |
306 | } |
|
304 | } | |
307 |
|
305 | |||
308 | if (m_chartAxis->isGridLineVisible()) { |
|
306 | if (m_chartAxis->isGridLineVisible()) { | |
309 | setGridOpacity(100); |
|
307 | setGridOpacity(100); | |
310 | } else { |
|
308 | } else { | |
311 | setGridOpacity(0); |
|
309 | setGridOpacity(0); | |
312 | } |
|
310 | } | |
313 |
|
311 | |||
314 | if (m_chartAxis->labelsVisible()) { |
|
312 | if (m_chartAxis->labelsVisible()) { | |
315 | setLabelsOpacity(100); |
|
313 | setLabelsOpacity(100); | |
316 | } else { |
|
314 | } else { | |
317 | setLabelsOpacity(0); |
|
315 | setLabelsOpacity(0); | |
318 | } |
|
316 | } | |
319 |
|
317 | |||
320 | if (m_chartAxis->shadesVisible()) { |
|
318 | if (m_chartAxis->shadesVisible()) { | |
321 | setShadesOpacity(100); |
|
319 | setShadesOpacity(100); | |
322 | } else { |
|
320 | } else { | |
323 | setShadesOpacity(0); |
|
321 | setShadesOpacity(0); | |
324 | } |
|
322 | } | |
325 |
|
323 | |||
326 | setLabelsAngle(m_chartAxis->labelsAngle()); |
|
324 | setLabelsAngle(m_chartAxis->labelsAngle()); | |
327 | setAxisPen(m_chartAxis->axisPen()); |
|
325 | setAxisPen(m_chartAxis->axisPen()); | |
328 | setLabelsPen(m_chartAxis->labelsPen()); |
|
326 | setLabelsPen(m_chartAxis->labelsPen()); | |
329 | setLabelsBrush(m_chartAxis->labelsBrush()); |
|
327 | setLabelsBrush(m_chartAxis->labelsBrush()); | |
330 | setLabelsFont(m_chartAxis->labelsFont()); |
|
328 | setLabelsFont(m_chartAxis->labelsFont()); | |
331 | setGridPen(m_chartAxis->gridLinePen()); |
|
329 | setGridPen(m_chartAxis->gridLinePen()); | |
332 | setShadesPen(m_chartAxis->shadesPen()); |
|
330 | setShadesPen(m_chartAxis->shadesPen()); | |
333 | setShadesBrush(m_chartAxis->shadesBrush()); |
|
331 | setShadesBrush(m_chartAxis->shadesBrush()); | |
334 |
|
332 | |||
335 | } |
|
333 | } | |
336 |
|
334 | |||
337 | void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) |
|
335 | void ChartAxis::handleRangeChanged(qreal min, qreal max,int tickCount) | |
338 | { |
|
336 | { | |
339 | if (qFuzzyIsNull(min - max) || tickCount < 2) |
|
337 | if (qFuzzyIsNull(min - max) || tickCount < 2) | |
340 | return; |
|
338 | return; | |
341 |
|
339 | |||
342 | m_min = min; |
|
340 | m_min = min; | |
343 | m_max = max; |
|
341 | m_max = max; | |
344 | m_ticksCount= tickCount; |
|
342 | m_ticksCount= tickCount; | |
345 |
|
343 | |||
346 | if (isEmpty()) return; |
|
344 | if (isEmpty()) return; | |
347 | QVector<qreal> layout = calculateLayout(); |
|
345 | QVector<qreal> layout = calculateLayout(); | |
348 | updateLayout(layout); |
|
346 | updateLayout(layout); | |
349 | } |
|
347 | } | |
350 |
|
348 | |||
351 | void ChartAxis::handleGeometryChanged(const QRectF &rect) |
|
349 | void ChartAxis::handleGeometryChanged(const QRectF &rect) | |
352 | { |
|
350 | { | |
353 | if(m_rect != rect) |
|
351 | if(m_rect != rect) | |
354 | { |
|
352 | { | |
355 | m_rect = rect; |
|
353 | m_rect = rect; | |
356 | if (isEmpty()) return; |
|
354 | if (isEmpty()) return; | |
357 | QVector<qreal> layout = calculateLayout(); |
|
355 | QVector<qreal> layout = calculateLayout(); | |
358 | updateLayout(layout); |
|
356 | updateLayout(layout); | |
359 | } |
|
357 | } | |
360 | } |
|
358 | } | |
361 |
|
359 | |||
362 |
|
360 | |||
363 | qreal ChartAxis::minimumWidth() |
|
361 | qreal ChartAxis::minimumWidth() | |
364 | { |
|
362 | { | |
365 | if(m_minWidth == 0) updateGeometry(); |
|
363 | if(m_minWidth == 0) updateGeometry(); | |
366 | return m_minWidth; |
|
364 | return m_minWidth; | |
367 | } |
|
365 | } | |
368 |
|
366 | |||
369 | qreal ChartAxis::minimumHeight() |
|
367 | qreal ChartAxis::minimumHeight() | |
370 | { |
|
368 | { | |
371 | if(m_minHeight == 0) updateGeometry(); |
|
369 | if(m_minHeight == 0) updateGeometry(); | |
372 | return m_minHeight; |
|
370 | return m_minHeight; | |
373 | } |
|
371 | } | |
374 |
|
372 | |||
375 |
|
373 | |||
376 | void ChartAxis::axisSelected() |
|
374 | void ChartAxis::axisSelected() | |
377 | { |
|
375 | { | |
378 | qDebug()<<"TODO: axis clicked"; |
|
376 | qDebug()<<"TODO: axis clicked"; | |
379 | } |
|
377 | } | |
380 |
|
378 | |||
381 | #include "moc_chartaxis_p.cpp" |
|
379 | #include "moc_chartaxis_p.cpp" | |
382 |
|
380 | |||
383 | QTCOMMERCIALCHART_END_NAMESPACE |
|
381 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,123 +1,122 | |||||
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 "chartaxisx_p.h" |
|
21 | #include "chartaxisx_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qaxiscategories_p.h" |
|
|||
24 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
25 | #include "chartanimator_p.h" |
|
24 | #include "chartanimator_p.h" | |
26 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
27 | #include <QDebug> |
|
26 | #include <QDebug> | |
28 | #include <QFontMetrics> |
|
27 | #include <QFontMetrics> | |
29 |
|
28 | |||
30 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
31 |
|
30 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
32 | |||
34 | ChartAxisX::ChartAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
33 | ChartAxisX::ChartAxisX(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
35 | { |
|
34 | { | |
36 | } |
|
35 | } | |
37 |
|
36 | |||
38 | ChartAxisX::~ChartAxisX() |
|
37 | ChartAxisX::~ChartAxisX() | |
39 | { |
|
38 | { | |
40 | } |
|
39 | } | |
41 |
|
40 | |||
42 | QVector<qreal> ChartAxisX::calculateLayout() const |
|
41 | QVector<qreal> ChartAxisX::calculateLayout() const | |
43 | { |
|
42 | { | |
44 | Q_ASSERT(m_ticksCount>=2); |
|
43 | Q_ASSERT(m_ticksCount>=2); | |
45 |
|
44 | |||
46 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
47 | points.resize(m_ticksCount); |
|
46 | points.resize(m_ticksCount); | |
48 |
|
47 | |||
49 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); |
|
48 | const qreal deltaX = m_rect.width()/(m_ticksCount-1); | |
50 | for (int i = 0; i < m_ticksCount; ++i) { |
|
49 | for (int i = 0; i < m_ticksCount; ++i) { | |
51 | int x = i * deltaX + m_rect.left(); |
|
50 | int x = i * deltaX + m_rect.left(); | |
52 | points[i] = x; |
|
51 | points[i] = x; | |
53 | } |
|
52 | } | |
54 | return points; |
|
53 | return points; | |
55 | } |
|
54 | } | |
56 |
|
55 | |||
57 | void ChartAxisX::updateGeometry() |
|
56 | void ChartAxisX::updateGeometry() | |
58 | { |
|
57 | { | |
59 | const QVector<qreal>& layout = ChartAxis::layout(); |
|
58 | const QVector<qreal>& layout = ChartAxis::layout(); | |
60 |
|
59 | |||
61 | m_minWidth = 0; |
|
60 | m_minWidth = 0; | |
62 | m_minHeight = 0; |
|
61 | m_minHeight = 0; | |
63 |
|
62 | |||
64 | if(layout.isEmpty()) return; |
|
63 | if(layout.isEmpty()) return; | |
65 |
|
64 | |||
66 | QStringList ticksList; |
|
65 | QStringList ticksList; | |
67 |
|
66 | |||
68 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); |
|
67 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
69 |
|
68 | |||
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
69 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
70 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
71 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
73 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
72 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
74 |
|
73 | |||
75 | Q_ASSERT(labels.size() == ticksList.size()); |
|
74 | Q_ASSERT(labels.size() == ticksList.size()); | |
76 | Q_ASSERT(layout.size() == ticksList.size()); |
|
75 | Q_ASSERT(layout.size() == ticksList.size()); | |
77 |
|
76 | |||
78 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
77 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
79 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); |
|
78 | lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom()); | |
80 |
|
79 | |||
81 | qreal width = 0; |
|
80 | qreal width = 0; | |
82 | for (int i = 0; i < layout.size(); ++i) { |
|
81 | for (int i = 0; i < layout.size(); ++i) { | |
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
82 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
84 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); |
|
83 | lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom()); | |
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
84 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
86 | if (!categories || i<1) { |
|
85 | if (!categories || i<1) { | |
87 | labelItem->setText(ticksList.at(i)); |
|
86 | labelItem->setText(ticksList.at(i)); | |
88 | const QRectF& rect = labelItem->boundingRect(); |
|
87 | const QRectF& rect = labelItem->boundingRect(); | |
89 | QPointF center = rect.center(); |
|
88 | QPointF center = rect.center(); | |
90 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
89 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
91 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); |
|
90 | labelItem->setPos(layout[i] - center.x(), m_rect.bottom() + label_padding); | |
92 |
|
91 | |||
93 | if(labelItem->pos().x()<=width){ |
|
92 | if(labelItem->pos().x()<=width){ | |
94 | labelItem->setVisible(false); |
|
93 | labelItem->setVisible(false); | |
95 | lineItem->setVisible(false); |
|
94 | lineItem->setVisible(false); | |
96 | }else{ |
|
95 | }else{ | |
97 | labelItem->setVisible(true); |
|
96 | labelItem->setVisible(true); | |
98 | lineItem->setVisible(true); |
|
97 | lineItem->setVisible(true); | |
99 | width=rect.width()+labelItem->pos().x(); |
|
98 | width=rect.width()+labelItem->pos().x(); | |
100 | } |
|
99 | } | |
101 | m_minWidth+=rect.width(); |
|
100 | m_minWidth+=rect.width(); | |
102 | m_minHeight=qMax(rect.height(),m_minHeight); |
|
101 | m_minHeight=qMax(rect.height(),m_minHeight); | |
103 | } |
|
102 | } | |
104 | else { |
|
103 | else { | |
105 | labelItem->setText(ticksList.at(i)); |
|
104 | labelItem->setText(ticksList.at(i)); | |
106 | const QRectF& rect = labelItem->boundingRect(); |
|
105 | const QRectF& rect = labelItem->boundingRect(); | |
107 | QPointF center = rect.center(); |
|
106 | QPointF center = rect.center(); | |
108 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
107 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
109 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); |
|
108 | labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding); | |
110 | m_minWidth+=rect.width(); |
|
109 | m_minWidth+=rect.width(); | |
111 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); |
|
110 | m_minHeight=qMax(rect.height()+label_padding,m_minHeight); | |
112 | } |
|
111 | } | |
113 |
|
112 | |||
114 | if ((i+1)%2 && i>1) { |
|
113 | if ((i+1)%2 && i>1) { | |
115 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
114 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
116 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); |
|
115 | rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height()); | |
117 | } |
|
116 | } | |
118 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
117 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
119 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); |
|
118 | lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5); | |
120 | } |
|
119 | } | |
121 | } |
|
120 | } | |
122 |
|
121 | |||
123 | QTCOMMERCIALCHART_END_NAMESPACE |
|
122 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,129 +1,128 | |||||
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 "chartaxisy_p.h" |
|
21 | #include "chartaxisy_p.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 | #include "qaxiscategories_p.h" |
|
|||
24 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
25 | #include "chartanimator_p.h" |
|
24 | #include "chartanimator_p.h" | |
26 | #include <QGraphicsLayout> |
|
25 | #include <QGraphicsLayout> | |
27 | #include <QFontMetrics> |
|
26 | #include <QFontMetrics> | |
28 | #include <QDebug> |
|
27 | #include <QDebug> | |
29 |
|
28 | |||
30 | static int label_padding = 5; |
|
29 | static int label_padding = 5; | |
31 |
|
30 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
32 | |||
34 | ChartAxisY::ChartAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) |
|
33 | ChartAxisY::ChartAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter) | |
35 | { |
|
34 | { | |
36 | } |
|
35 | } | |
37 |
|
36 | |||
38 | ChartAxisY::~ChartAxisY() |
|
37 | ChartAxisY::~ChartAxisY() | |
39 | { |
|
38 | { | |
40 | } |
|
39 | } | |
41 |
|
40 | |||
42 | QVector<qreal> ChartAxisY::calculateLayout() const |
|
41 | QVector<qreal> ChartAxisY::calculateLayout() const | |
43 | { |
|
42 | { | |
44 | Q_ASSERT(m_ticksCount>=2); |
|
43 | Q_ASSERT(m_ticksCount>=2); | |
45 |
|
44 | |||
46 | QVector<qreal> points; |
|
45 | QVector<qreal> points; | |
47 | points.resize(m_ticksCount); |
|
46 | points.resize(m_ticksCount); | |
48 |
|
47 | |||
49 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); |
|
48 | const qreal deltaY = m_rect.height()/(m_ticksCount-1); | |
50 | for (int i = 0; i < m_ticksCount; ++i) { |
|
49 | for (int i = 0; i < m_ticksCount; ++i) { | |
51 | int y = i * -deltaY + m_rect.bottom(); |
|
50 | int y = i * -deltaY + m_rect.bottom(); | |
52 | points[i] = y; |
|
51 | points[i] = y; | |
53 | } |
|
52 | } | |
54 |
|
53 | |||
55 | return points; |
|
54 | return points; | |
56 | } |
|
55 | } | |
57 |
|
56 | |||
58 | void ChartAxisY::updateGeometry() |
|
57 | void ChartAxisY::updateGeometry() | |
59 | { |
|
58 | { | |
60 | const QVector<qreal> &layout = ChartAxis::layout(); |
|
59 | const QVector<qreal> &layout = ChartAxis::layout(); | |
61 | m_minWidth = 0; |
|
60 | m_minWidth = 0; | |
62 | m_minHeight = 0; |
|
61 | m_minHeight = 0; | |
63 |
|
62 | |||
64 | if(layout.isEmpty()) return; |
|
63 | if(layout.isEmpty()) return; | |
65 |
|
64 | |||
66 | QStringList ticksList; |
|
65 | QStringList ticksList; | |
67 |
|
66 | |||
68 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); |
|
67 | bool categories = createLabels(ticksList,m_min,m_max,layout.size()); | |
69 |
|
68 | |||
70 | QList<QGraphicsItem *> lines = m_grid->childItems(); |
|
69 | QList<QGraphicsItem *> lines = m_grid->childItems(); | |
71 | QList<QGraphicsItem *> labels = m_labels->childItems(); |
|
70 | QList<QGraphicsItem *> labels = m_labels->childItems(); | |
72 | QList<QGraphicsItem *> shades = m_shades->childItems(); |
|
71 | QList<QGraphicsItem *> shades = m_shades->childItems(); | |
73 | QList<QGraphicsItem *> axis = m_axis->childItems(); |
|
72 | QList<QGraphicsItem *> axis = m_axis->childItems(); | |
74 |
|
73 | |||
75 | Q_ASSERT(labels.size() == ticksList.size()); |
|
74 | Q_ASSERT(labels.size() == ticksList.size()); | |
76 | Q_ASSERT(layout.size() == ticksList.size()); |
|
75 | Q_ASSERT(layout.size() == ticksList.size()); | |
77 |
|
76 | |||
78 | qreal height = 2*m_rect.bottom(); |
|
77 | qreal height = 2*m_rect.bottom(); | |
79 |
|
78 | |||
80 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); |
|
79 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0)); | |
81 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); |
|
80 | lineItem->setLine(m_rect.left() , m_rect.top(), m_rect.left(), m_rect.bottom()); | |
82 |
|
81 | |||
83 | for (int i = 0; i < layout.size(); ++i) { |
|
82 | for (int i = 0; i < layout.size(); ++i) { | |
84 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); |
|
83 | QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i)); | |
85 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); |
|
84 | lineItem->setLine(m_rect.left() , layout[i], m_rect.right(), layout[i]); | |
86 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); |
|
85 | QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i)); | |
87 |
|
86 | |||
88 | if (!categories || i<1) { |
|
87 | if (!categories || i<1) { | |
89 | labelItem->setText(ticksList.at(i)); |
|
88 | labelItem->setText(ticksList.at(i)); | |
90 | const QRectF& rect = labelItem->boundingRect(); |
|
89 | const QRectF& rect = labelItem->boundingRect(); | |
91 |
|
90 | |||
92 | QPointF center = rect.center(); |
|
91 | QPointF center = rect.center(); | |
93 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
92 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
94 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); |
|
93 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i]-center.y()); | |
95 |
|
94 | |||
96 | if(labelItem->pos().y()+rect.height()>height) { |
|
95 | if(labelItem->pos().y()+rect.height()>height) { | |
97 | labelItem->setVisible(false); |
|
96 | labelItem->setVisible(false); | |
98 | lineItem->setVisible(false); |
|
97 | lineItem->setVisible(false); | |
99 | } |
|
98 | } | |
100 | else { |
|
99 | else { | |
101 | labelItem->setVisible(true); |
|
100 | labelItem->setVisible(true); | |
102 | lineItem->setVisible(true); |
|
101 | lineItem->setVisible(true); | |
103 | height=labelItem->pos().y(); |
|
102 | height=labelItem->pos().y(); | |
104 | } |
|
103 | } | |
105 |
|
104 | |||
106 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); |
|
105 | m_minWidth=qMax(rect.width()+label_padding,m_minWidth); | |
107 | m_minHeight+=rect.height(); |
|
106 | m_minHeight+=rect.height(); | |
108 | } |
|
107 | } | |
109 | else { |
|
108 | else { | |
110 | labelItem->setText(ticksList.at(i)); |
|
109 | labelItem->setText(ticksList.at(i)); | |
111 | const QRectF& rect = labelItem->boundingRect(); |
|
110 | const QRectF& rect = labelItem->boundingRect(); | |
112 | m_minWidth=qMax(rect.width(),m_minWidth); |
|
111 | m_minWidth=qMax(rect.width(),m_minWidth); | |
113 | m_minHeight+=rect.height(); |
|
112 | m_minHeight+=rect.height(); | |
114 | QPointF center = rect.center(); |
|
113 | QPointF center = rect.center(); | |
115 | labelItem->setTransformOriginPoint(center.x(), center.y()); |
|
114 | labelItem->setTransformOriginPoint(center.x(), center.y()); | |
116 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); |
|
115 | labelItem->setPos(m_rect.left() - rect.width() - label_padding , layout[i] - (layout[i] - layout[i-1])/2 -center.y()); | |
117 | } |
|
116 | } | |
118 |
|
117 | |||
119 | if ((i+1)%2 && i>1) { |
|
118 | if ((i+1)%2 && i>1) { | |
120 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); |
|
119 | QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1)); | |
121 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); |
|
120 | rectItem->setRect(m_rect.left(),layout[i],m_rect.width(),layout[i-1]-layout[i]); | |
122 | } |
|
121 | } | |
123 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); |
|
122 | lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1)); | |
124 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); |
|
123 | lineItem->setLine(m_rect.left()-5,layout[i],m_rect.left(),layout[i]); | |
125 | } |
|
124 | } | |
126 | } |
|
125 | } | |
127 |
|
126 | |||
128 |
|
127 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now