##// END OF EJS Templates
fix: forgot to restage previous commit
Marek Rosa -
r2269:b003e569935a
parent child
Show More
@@ -1,486 +1,487
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 "chartlayout_p.h"
25 #include "chartlayout_p.h"
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QDateTime>
28 #include <QDateTime>
29 #include <QValueAxis>
29 #include <QValueAxis>
30 #include <QGraphicsLayout>
30 #include <QGraphicsLayout>
31 #include <QFontMetrics>
31 #include <QFontMetrics>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis)
35 ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis)
36 : ChartElement(presenter),
36 : ChartElement(presenter),
37 m_chartAxis(axis),
37 m_chartAxis(axis),
38 m_labelsAngle(0),
38 m_labelsAngle(0),
39 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
39 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
40 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
40 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
41 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
41 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
42 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
42 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
43 m_title(new QGraphicsSimpleTextItem(presenter->rootItem())),
43 m_title(new QGraphicsSimpleTextItem(presenter->rootItem())),
44 m_min(0),
44 m_min(0),
45 m_max(0),
45 m_max(0),
46 m_animation(0),
46 m_animation(0),
47 m_labelPadding(5),
47 m_labelPadding(5),
48 m_intervalAxis(intervalAxis)
48 m_intervalAxis(intervalAxis)
49 {
49 {
50 //initial initialization
50 //initial initialization
51 m_arrow->setZValue(ChartPresenter::AxisZValue);
51 m_arrow->setZValue(ChartPresenter::AxisZValue);
52 m_arrow->setHandlesChildEvents(false);
52 m_arrow->setHandlesChildEvents(false);
53 m_labels->setZValue(ChartPresenter::AxisZValue);
53 m_labels->setZValue(ChartPresenter::AxisZValue);
54 m_shades->setZValue(ChartPresenter::ShadesZValue);
54 m_shades->setZValue(ChartPresenter::ShadesZValue);
55 m_grid->setZValue(ChartPresenter::GridZValue);
55 m_grid->setZValue(ChartPresenter::GridZValue);
56 m_title->setZValue(ChartPresenter::GridZValue);
56 m_title->setZValue(ChartPresenter::GridZValue);
57
57
58 QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated()));
58 QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated()));
59
59
60 QGraphicsSimpleTextItem item;
60 QGraphicsSimpleTextItem item;
61 m_font = item.font();
61 m_font = item.font();
62
62
63 }
63 }
64
64
65 ChartAxis::~ChartAxis()
65 ChartAxis::~ChartAxis()
66 {
66 {
67 }
67 }
68
68
69 void ChartAxis::setAnimation(AxisAnimation *animation)
69 void ChartAxis::setAnimation(AxisAnimation *animation)
70 {
70 {
71 m_animation = animation;
71 m_animation = animation;
72 }
72 }
73
73
74 void ChartAxis::setLayout(QVector<qreal> &layout)
74 void ChartAxis::setLayout(QVector<qreal> &layout)
75 {
75 {
76 m_layoutVector = layout;
76 m_layoutVector = layout;
77 }
77 }
78
78
79 void ChartAxis::createItems(int count)
79 void ChartAxis::createItems(int count)
80 {
80 {
81 if (m_arrow->childItems().size() == 0)
81 if (m_arrow->childItems().size() == 0)
82 m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem()));
82 m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem()));
83
83
84 if (m_intervalAxis && m_grid->childItems().size() == 0) {
84 if (m_intervalAxis && m_grid->childItems().size() == 0) {
85 for (int i = 0 ; i < 2 ; i ++)
85 for (int i = 0 ; i < 2 ; i ++)
86 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
86 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
87 }
87 }
88
88
89 for (int i = 0; i < count; ++i) {
89 for (int i = 0; i < count; ++i) {
90 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
90 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
91 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
91 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
92 label->setFont(m_font);
92 label->setFont(m_font);
93 m_labels->addToGroup(label);
93 m_labels->addToGroup(label);
94 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
94 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
95 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2)
95 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2)
96 m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
96 m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
97 }
97 }
98 }
98 }
99
99
100 void ChartAxis::deleteItems(int count)
100 void ChartAxis::deleteItems(int count)
101 {
101 {
102 QList<QGraphicsItem *> lines = m_grid->childItems();
102 QList<QGraphicsItem *> lines = m_grid->childItems();
103 QList<QGraphicsItem *> labels = m_labels->childItems();
103 QList<QGraphicsItem *> labels = m_labels->childItems();
104 QList<QGraphicsItem *> shades = m_shades->childItems();
104 QList<QGraphicsItem *> shades = m_shades->childItems();
105 QList<QGraphicsItem *> axis = m_arrow->childItems();
105 QList<QGraphicsItem *> axis = m_arrow->childItems();
106
106
107 for (int i = 0; i < count; ++i) {
107 for (int i = 0; i < count; ++i) {
108 if (lines.size() % 2 && lines.size() > 1)
108 if (lines.size() % 2 && lines.size() > 1)
109 delete(shades.takeLast());
109 delete(shades.takeLast());
110 delete(lines.takeLast());
110 delete(lines.takeLast());
111 delete(labels.takeLast());
111 delete(labels.takeLast());
112 delete(axis.takeLast());
112 delete(axis.takeLast());
113 }
113 }
114 }
114 }
115
115
116 void ChartAxis::updateLayout(QVector<qreal> &layout)
116 void ChartAxis::updateLayout(QVector<qreal> &layout)
117 {
117 {
118 int diff = m_layoutVector.size() - layout.size();
118 int diff = m_layoutVector.size() - layout.size();
119
119
120 if (diff > 0)
120 if (diff > 0)
121 deleteItems(diff);
121 deleteItems(diff);
122 else if (diff < 0)
122 else if (diff < 0)
123 createItems(-diff);
123 createItems(-diff);
124
124
125 if (diff < 0) handleAxisUpdated();
125 if (diff < 0) handleAxisUpdated();
126
126
127 if (m_animation) {
127 if (m_animation) {
128 switch (presenter()->state()) {
128 switch (presenter()->state()) {
129 case ChartPresenter::ZoomInState:
129 case ChartPresenter::ZoomInState:
130 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
130 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
131 m_animation->setAnimationPoint(presenter()->statePoint());
131 m_animation->setAnimationPoint(presenter()->statePoint());
132 break;
132 break;
133 case ChartPresenter::ZoomOutState:
133 case ChartPresenter::ZoomOutState:
134 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
134 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
135 m_animation->setAnimationPoint(presenter()->statePoint());
135 m_animation->setAnimationPoint(presenter()->statePoint());
136 break;
136 break;
137 case ChartPresenter::ScrollUpState:
137 case ChartPresenter::ScrollUpState:
138 case ChartPresenter::ScrollLeftState:
138 case ChartPresenter::ScrollLeftState:
139 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
139 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
140 break;
140 break;
141 case ChartPresenter::ScrollDownState:
141 case ChartPresenter::ScrollDownState:
142 case ChartPresenter::ScrollRightState:
142 case ChartPresenter::ScrollRightState:
143 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
143 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
144 break;
144 break;
145 case ChartPresenter::ShowState:
145 case ChartPresenter::ShowState:
146 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
146 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
147 break;
147 break;
148 }
148 }
149 m_animation->setValues(m_layoutVector, layout);
149 m_animation->setValues(m_layoutVector, layout);
150 presenter()->startAnimation(m_animation);
150 presenter()->startAnimation(m_animation);
151 } else {
151 } else {
152 setLayout(layout);
152 setLayout(layout);
153 updateGeometry();
153 updateGeometry();
154 }
154 }
155 }
155 }
156
156
157 void ChartAxis::setArrowOpacity(qreal opacity)
157 void ChartAxis::setArrowOpacity(qreal opacity)
158 {
158 {
159 m_arrow->setOpacity(opacity);
159 m_arrow->setOpacity(opacity);
160 }
160 }
161
161
162 qreal ChartAxis::arrowOpacity() const
162 qreal ChartAxis::arrowOpacity() const
163 {
163 {
164 return m_arrow->opacity();
164 return m_arrow->opacity();
165 }
165 }
166
166
167 void ChartAxis::setArrowVisibility(bool visible)
167 void ChartAxis::setArrowVisibility(bool visible)
168 {
168 {
169 m_arrow->setOpacity(visible);
169 m_arrow->setOpacity(visible);
170 }
170 }
171
171
172 void ChartAxis::setGridOpacity(qreal opacity)
172 void ChartAxis::setGridOpacity(qreal opacity)
173 {
173 {
174 m_grid->setOpacity(opacity);
174 m_grid->setOpacity(opacity);
175 }
175 }
176
176
177 qreal ChartAxis::gridOpacity() const
177 qreal ChartAxis::gridOpacity() const
178 {
178 {
179 return m_grid->opacity();
179 return m_grid->opacity();
180 }
180 }
181
181
182 void ChartAxis::setGridVisibility(bool visible)
182 void ChartAxis::setGridVisibility(bool visible)
183 {
183 {
184 m_grid->setOpacity(visible);
184 m_grid->setOpacity(visible);
185 }
185 }
186
186
187 void ChartAxis::setLabelsOpacity(qreal opacity)
187 void ChartAxis::setLabelsOpacity(qreal opacity)
188 {
188 {
189 m_labels->setOpacity(opacity);
189 m_labels->setOpacity(opacity);
190 }
190 }
191
191
192 qreal ChartAxis::labelsOpacity() const
192 qreal ChartAxis::labelsOpacity() const
193 {
193 {
194 return m_labels->opacity();
194 return m_labels->opacity();
195 }
195 }
196
196
197 void ChartAxis::setLabelsVisibility(bool visible)
197 void ChartAxis::setLabelsVisibility(bool visible)
198 {
198 {
199 m_labels->setOpacity(visible);
199 m_labels->setOpacity(visible);
200 }
200 }
201
201
202 void ChartAxis::setShadesOpacity(qreal opacity)
202 void ChartAxis::setShadesOpacity(qreal opacity)
203 {
203 {
204 m_shades->setOpacity(opacity);
204 m_shades->setOpacity(opacity);
205 }
205 }
206
206
207 qreal ChartAxis::shadesOpacity() const
207 qreal ChartAxis::shadesOpacity() const
208 {
208 {
209 return m_shades->opacity();
209 return m_shades->opacity();
210 }
210 }
211
211
212 void ChartAxis::setShadesVisibility(bool visible)
212 void ChartAxis::setShadesVisibility(bool visible)
213 {
213 {
214 m_shades->setVisible(visible);
214 m_shades->setVisible(visible);
215 }
215 }
216
216
217 void ChartAxis::setLabelsAngle(int angle)
217 void ChartAxis::setLabelsAngle(int angle)
218 {
218 {
219 foreach (QGraphicsItem *item, m_labels->childItems())
219 foreach (QGraphicsItem *item, m_labels->childItems())
220 item->setRotation(angle);
220 item->setRotation(angle);
221
221
222 m_labelsAngle = angle;
222 m_labelsAngle = angle;
223 }
223 }
224
224
225 void ChartAxis::setLabelsPen(const QPen &pen)
225 void ChartAxis::setLabelsPen(const QPen &pen)
226 {
226 {
227 foreach (QGraphicsItem *item , m_labels->childItems())
227 foreach (QGraphicsItem *item , m_labels->childItems())
228 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
228 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
229 }
229 }
230
230
231 void ChartAxis::setLabelsBrush(const QBrush &brush)
231 void ChartAxis::setLabelsBrush(const QBrush &brush)
232 {
232 {
233 foreach (QGraphicsItem *item , m_labels->childItems())
233 foreach (QGraphicsItem *item , m_labels->childItems())
234 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
234 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
235 }
235 }
236
236
237 void ChartAxis::setLabelsFont(const QFont &font)
237 void ChartAxis::setLabelsFont(const QFont &font)
238 {
238 {
239 if (m_font != font) {
239 if (m_font != font) {
240 m_font = font;
240 m_font = font;
241 foreach (QGraphicsItem *item , m_labels->childItems())
241 foreach (QGraphicsItem *item , m_labels->childItems())
242 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
242 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
243 QGraphicsLayoutItem::updateGeometry();
243 QGraphicsLayoutItem::updateGeometry();
244 presenter()->layout()->invalidate();
244 presenter()->layout()->invalidate();
245 }
245 }
246 }
246 }
247
247
248 void ChartAxis::setShadesBrush(const QBrush &brush)
248 void ChartAxis::setShadesBrush(const QBrush &brush)
249 {
249 {
250 foreach (QGraphicsItem *item , m_shades->childItems())
250 foreach (QGraphicsItem *item , m_shades->childItems())
251 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
251 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
252 }
252 }
253
253
254 void ChartAxis::setShadesPen(const QPen &pen)
254 void ChartAxis::setShadesPen(const QPen &pen)
255 {
255 {
256 foreach (QGraphicsItem *item , m_shades->childItems())
256 foreach (QGraphicsItem *item , m_shades->childItems())
257 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
257 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
258 }
258 }
259
259
260 void ChartAxis::setArrowPen(const QPen &pen)
260 void ChartAxis::setArrowPen(const QPen &pen)
261 {
261 {
262 foreach (QGraphicsItem *item , m_arrow->childItems())
262 foreach (QGraphicsItem *item , m_arrow->childItems())
263 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
263 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
264 }
264 }
265
265
266 void ChartAxis::setGridPen(const QPen &pen)
266 void ChartAxis::setGridPen(const QPen &pen)
267 {
267 {
268 foreach (QGraphicsItem *item , m_grid->childItems())
268 foreach (QGraphicsItem *item , m_grid->childItems())
269 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
269 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
270 }
270 }
271
271
272 void ChartAxis::setLabelPadding(int padding)
272 void ChartAxis::setLabelPadding(int padding)
273 {
273 {
274 m_labelPadding = padding;
274 m_labelPadding = padding;
275 }
275 }
276
276
277 bool ChartAxis::isEmpty()
277 bool ChartAxis::isEmpty()
278 {
278 {
279 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(m_min, m_max);
279 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(m_min, m_max);
280 }
280 }
281
281
282 void ChartAxis::handleDomainUpdated()
282 void ChartAxis::handleDomainUpdated()
283 {
283 {
284 Domain *domain = qobject_cast<Domain *>(sender());
284 Domain *domain = qobject_cast<Domain *>(sender());
285 qreal min(0);
285 qreal min(0);
286 qreal max(0);
286 qreal max(0);
287
287
288 if (m_chartAxis->orientation() == Qt::Horizontal) {
288 if (m_chartAxis->orientation() == Qt::Horizontal) {
289 min = domain->minX();
289 min = domain->minX();
290 max = domain->maxX();
290 max = domain->maxX();
291 } else if (m_chartAxis->orientation() == Qt::Vertical) {
291 } else if (m_chartAxis->orientation() == Qt::Vertical) {
292 min = domain->minY();
292 min = domain->minY();
293 max = domain->maxY();
293 max = domain->maxY();
294 }
294 }
295
295
296 if (!qFuzzyCompare(m_min, min) || !qFuzzyCompare(m_max, max)) {
296 if (!qFuzzyCompare(m_min, min) || !qFuzzyCompare(m_max, max)) {
297 m_min = min;
297 m_min = min;
298 m_max = max;
298 m_max = max;
299
299
300 if (!isEmpty()) {
300 if (!isEmpty()) {
301
301
302 QVector<qreal> layout = calculateLayout();
302 QVector<qreal> layout = calculateLayout();
303 updateLayout(layout);
303 updateLayout(layout);
304 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
304 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
305 QSizeF after = sizeHint(Qt::PreferredSize);
305 QSizeF after = sizeHint(Qt::PreferredSize);
306
306
307 if (before != after) {
307 if (before != after) {
308 QGraphicsLayoutItem::updateGeometry();
308 QGraphicsLayoutItem::updateGeometry();
309 //we don't want to call invalidate on layout, since it will change minimum size of component,
309 //we don't want to call invalidate on layout, since it will change minimum size of component,
310 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
310 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
311 //instead recalculate layout and use plotArea for extra space.
311 //instead recalculate layout and use plotArea for extra space.
312 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
312 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
313 }
313 }
314 }
314 }
315 }
315 }
316 }
316 }
317
317
318 void ChartAxis::handleAxisUpdated()
318 void ChartAxis::handleAxisUpdated()
319 {
319 {
320 if (isEmpty())
320 if (isEmpty())
321 return;
321 return;
322
322
323 bool visible = m_chartAxis->isVisible();
323 bool visible = m_chartAxis->isVisible();
324
324
325 //TODO: split this into separate signal/slots ?
325 //TODO: split this into separate signal/slots ?
326 setArrowVisibility(visible && m_chartAxis->isLineVisible());
326 setArrowVisibility(visible && m_chartAxis->isLineVisible());
327 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
327 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
328 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
328 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
329 setShadesVisibility(visible && m_chartAxis->shadesVisible());
329 setShadesVisibility(visible && m_chartAxis->shadesVisible());
330 setLabelsAngle(m_chartAxis->labelsAngle());
330 setLabelsAngle(m_chartAxis->labelsAngle());
331 setArrowPen(m_chartAxis->linePen());
331 setArrowPen(m_chartAxis->linePen());
332 setLabelsPen(m_chartAxis->labelsPen());
332 setLabelsPen(m_chartAxis->labelsPen());
333 setLabelsBrush(m_chartAxis->labelsBrush());
333 setLabelsBrush(m_chartAxis->labelsBrush());
334 setLabelsFont(m_chartAxis->labelsFont());
334 setLabelsFont(m_chartAxis->labelsFont());
335 setGridPen(m_chartAxis->gridLinePen());
335 setGridPen(m_chartAxis->gridLinePen());
336 setShadesPen(m_chartAxis->shadesPen());
336 setShadesPen(m_chartAxis->shadesPen());
337 setShadesBrush(m_chartAxis->shadesBrush());
337 setShadesBrush(m_chartAxis->shadesBrush());
338 setTitleText(m_chartAxis->title());
338 setTitleText(m_chartAxis->title());
339 setTitleFont(m_chartAxis->titleFont());
339 setTitleFont(m_chartAxis->titleFont());
340 setTitlePen(m_chartAxis->titlePen());
340 setTitlePen(m_chartAxis->titlePen());
341 setTitleBrush(m_chartAxis->titleBrush());
341 setTitleBrush(m_chartAxis->titleBrush());
342 }
342 }
343
343
344 void ChartAxis::setTitleText(const QString &title)
344 void ChartAxis::setTitleText(const QString &title)
345 {
345 {
346 if (m_titleText != title) {
346 if (m_titleText != title) {
347 m_titleText = title;
347 m_titleText = title;
348 QGraphicsLayoutItem::updateGeometry();
348 QGraphicsLayoutItem::updateGeometry();
349 presenter()->layout()->invalidate();
349 presenter()->layout()->invalidate();
350 }
350 }
351 }
351 }
352
352
353 void ChartAxis::setTitlePen(const QPen &pen)
353 void ChartAxis::setTitlePen(const QPen &pen)
354 {
354 {
355 m_title->setPen(pen);
355 m_title->setPen(pen);
356 }
356 }
357
357
358 void ChartAxis::setTitleBrush(const QBrush &brush)
358 void ChartAxis::setTitleBrush(const QBrush &brush)
359 {
359 {
360 m_title->setBrush(brush);
360 m_title->setBrush(brush);
361 }
361 }
362
362
363 void ChartAxis::setTitleFont(const QFont &font)
363 void ChartAxis::setTitleFont(const QFont &font)
364 {
364 {
365 if(m_title->font() != font){
365 if(m_title->font() != font){
366 m_title->setFont(font);
366 m_title->setFont(font);
367 QGraphicsLayoutItem::updateGeometry();
367 QGraphicsLayoutItem::updateGeometry();
368 presenter()->layout()->invalidate();
368 presenter()->layout()->invalidate();
369 }
369 }
370 }
370 }
371
371
372 QFont ChartAxis::titleFont() const
372 QFont ChartAxis::titleFont() const
373 {
373 {
374 return m_title->font();
374 return m_title->font();
375 }
375 }
376
376
377 void ChartAxis::hide()
377 void ChartAxis::hide()
378 {
378 {
379 setArrowVisibility(false);
379 setArrowVisibility(false);
380 setGridVisibility(false);
380 setGridVisibility(false);
381 setLabelsVisibility(false);
381 setLabelsVisibility(false);
382 setShadesVisibility(false);
382 setShadesVisibility(false);
383 }
383 }
384
384
385 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
385 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
386 {
386 {
387 m_gridRect = grid;
387 m_gridRect = grid;
388 m_axisRect = axis;
388 m_axisRect = axis;
389
389
390 if (isEmpty())
390 if (isEmpty())
391 return;
391 return;
392
392
393 QVector<qreal> layout = calculateLayout();
393 QVector<qreal> layout = calculateLayout();
394 updateLayout(layout);
394 updateLayout(layout);
395
395
396 }
396 }
397
397
398 void ChartAxis::axisSelected()
398 void ChartAxis::axisSelected()
399 {
399 {
400 //TODO: axis clicked;
400 //TODO: axis clicked;
401 }
401 }
402
402
403 Qt::Orientation ChartAxis::orientation() const
403 Qt::Orientation ChartAxis::orientation() const
404 {
404 {
405 return m_chartAxis->orientation();
405 return m_chartAxis->orientation();
406 }
406 }
407
407
408 Qt::Alignment ChartAxis::alignment() const
408 Qt::Alignment ChartAxis::alignment() const
409 {
409 {
410 return m_chartAxis->alignment();
410 return m_chartAxis->alignment();
411 }
411 }
412
412
413 bool ChartAxis::isVisible()
413 bool ChartAxis::isVisible()
414 {
414 {
415 return m_chartAxis->isVisible();
415 return m_chartAxis->isVisible();
416 }
416 }
417
417
418 void ChartAxis::setLabels(const QStringList &labels)
418 void ChartAxis::setLabels(const QStringList &labels)
419 {
419 {
420 m_labelsList = labels;
420 m_labelsList = labels;
421 }
421 }
422
422
423 QStringList ChartAxis::createValueLabels(int ticks) const
423 QStringList ChartAxis::createValueLabels(int ticks) const
424 {
424 {
425 Q_ASSERT(m_max > m_min);
425 Q_ASSERT(m_max > m_min);
426 Q_ASSERT(ticks > 1);
426 Q_ASSERT(ticks > 1);
427
427
428 QStringList labels;
428 QStringList labels;
429
429
430 int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0);
430 int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0);
431 n++;
431 n++;
432
432
433 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
433 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
434
434
435 QString format = axis->labelFormat();
435 QString format = axis->labelFormat();
436
436
437 if (format.isNull()) {
437 if (format.isNull()) {
438 for (int i = 0; i < ticks; i++) {
438 for (int i = 0; i < ticks; i++) {
439 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
439 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
440 labels << QString::number(value, 'f', n);
440 labels << QString::number(value, 'f', n);
441 }
441 }
442 } else {
442 } else {
443 QByteArray array = format.toLatin1();
443 QByteArray array = format.toLatin1();
444 for (int i = 0; i < ticks; i++) {
444 for (int i = 0; i < ticks; i++) {
445 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
445 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
446 if (format.contains("d")
446 if (format.contains("d")
447 || format.contains("i")
447 || format.contains("i")
448 || format.contains("c"))
448 || format.contains("c"))
449
450 labels << QString().sprintf(array, (qint64)value);
449 labels << QString().sprintf(array, (qint64)value);
451 else if (format.contains("u")
450 else if (format.contains("u")
452 || format.contains("o")
451 || format.contains("o")
453 || format.contains("x", Qt::CaseInsensitive))
452 || format.contains("x", Qt::CaseInsensitive))
454 labels << QString().sprintf(array, (quint64)value);
453 labels << QString().sprintf(array, (quint64)value);
455 else
454 else if (format.contains("f", Qt::CaseInsensitive)
455 || format.contains("e", Qt::CaseInsensitive)
456 || format.contains("g", Qt::CaseInsensitive))
456 labels << QString().sprintf(array, value);
457 labels << QString().sprintf(array, value);
457 }
458 }
458 }
459 }
459
460
460 return labels;
461 return labels;
461 }
462 }
462
463
463 QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const
464 QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const
464 {
465 {
465 Q_ASSERT(m_max > m_min);
466 Q_ASSERT(m_max > m_min);
466 Q_ASSERT(ticks > 1);
467 Q_ASSERT(ticks > 1);
467 QStringList labels;
468 QStringList labels;
468 int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0);
469 int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0);
469 n++;
470 n++;
470 for (int i = 0; i < ticks; i++) {
471 for (int i = 0; i < ticks; i++) {
471 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
472 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
472 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
473 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
473 }
474 }
474 return labels;
475 return labels;
475 }
476 }
476
477
477 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
478 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
478 {
479 {
479 Q_UNUSED(which);
480 Q_UNUSED(which);
480 Q_UNUSED(constraint);
481 Q_UNUSED(constraint);
481 return QSizeF();
482 return QSizeF();
482 }
483 }
483
484
484 #include "moc_chartaxis_p.cpp"
485 #include "moc_chartaxis_p.cpp"
485
486
486 QTCOMMERCIALCHART_END_NAMESPACE
487 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now