##// END OF EJS Templates
Bugfix: axis visibily issues...
Michal Klocek -
r2297:bf59b22cf3e9
parent child
Show More
@@ -1,508 +1,530
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 "abstractdomain_p.h"
26 #include "abstractdomain_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QDateTime>
28 #include <QDateTime>
29 #include <QValueAxis>
29 #include <QValueAxis>
30 #include <QLogValueAxis>
30 #include <QLogValueAxis>
31 #include <QGraphicsLayout>
31 #include <QGraphicsLayout>
32 #include <QFontMetrics>
32 #include <QFontMetrics>
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis)
36 ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis)
37 : ChartElement(item),
37 : ChartElement(item),
38 m_axis(axis),
38 m_axis(axis),
39 m_labelsAngle(0),
39 m_labelsAngle(0),
40 m_grid(new QGraphicsItemGroup(item)),
40 m_grid(new QGraphicsItemGroup(item)),
41 m_arrow(new QGraphicsItemGroup(item)),
41 m_arrow(new QGraphicsItemGroup(item)),
42 m_shades(new QGraphicsItemGroup(item)),
42 m_shades(new QGraphicsItemGroup(item)),
43 m_labels(new QGraphicsItemGroup(item)),
43 m_labels(new QGraphicsItemGroup(item)),
44 m_title(new QGraphicsSimpleTextItem(item)),
44 m_title(new QGraphicsSimpleTextItem(item)),
45 m_animation(0),
45 m_animation(0),
46 m_labelPadding(5),
46 m_labelPadding(5),
47 m_intervalAxis(intervalAxis)
47 m_intervalAxis(intervalAxis)
48 {
48 {
49 Q_ASSERT(item);
49 Q_ASSERT(item);
50 //initial initialization
50 //initial initialization
51 m_arrow->setHandlesChildEvents(false);
51 m_arrow->setHandlesChildEvents(false);
52 m_arrow->setZValue(ChartPresenter::AxisZValue);
52 m_arrow->setZValue(ChartPresenter::AxisZValue);
53 m_arrow->setVisible(m_axis->isLineVisible());
53 m_arrow->setVisible(m_axis->isLineVisible());
54 m_labels->setZValue(ChartPresenter::AxisZValue);
54 m_labels->setZValue(ChartPresenter::AxisZValue);
55 m_labels->setVisible(m_axis->labelsVisible());
55 m_labels->setVisible(m_axis->labelsVisible());
56 m_shades->setZValue(ChartPresenter::ShadesZValue);
56 m_shades->setZValue(ChartPresenter::ShadesZValue);
57 m_shades->setVisible(m_axis->shadesVisible());
57 m_shades->setVisible(m_axis->shadesVisible());
58 m_grid->setZValue(ChartPresenter::GridZValue);
58 m_grid->setZValue(ChartPresenter::GridZValue);
59 m_grid->setVisible(m_axis->isGridLineVisible());
59 m_grid->setVisible(m_axis->isGridLineVisible());
60 m_title->setZValue(ChartPresenter::GridZValue);
60 m_title->setZValue(ChartPresenter::GridZValue);
61 connectSlots();
61 connectSlots();
62
62
63 setFlag(QGraphicsItem::ItemHasNoContents,true);
63 setFlag(QGraphicsItem::ItemHasNoContents,true);
64 }
64 }
65
65
66 void ChartAxis::connectSlots()
66 void ChartAxis::connectSlots()
67 {
67 {
68 QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool)));
68 QObject::connect(m_axis,SIGNAL(visibleChanged(bool)),this,SLOT(handleVisibleChanged(bool)));
69 QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool)));
69 QObject::connect(m_axis,SIGNAL(lineVisibleChanged(bool)),this,SLOT(handleArrowVisibleChanged(bool)));
70 QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool)));
70 QObject::connect(m_axis,SIGNAL(gridVisibleChanged(bool)),this,SLOT(handleGridVisibleChanged(bool)));
71 QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool)));
71 QObject::connect(m_axis,SIGNAL(labelsVisibleChanged(bool)),this,SLOT(handleLabelsVisibleChanged(bool)));
72 QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool)));
72 QObject::connect(m_axis,SIGNAL(shadesVisibleChanged(bool)),this,SLOT(handleShadesVisibleChanged(bool)));
73 QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int)));
73 QObject::connect(m_axis,SIGNAL(labelsAngleChanged(int)),this,SLOT(handleLabelsAngleChanged(int)));
74 QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&)));
74 QObject::connect(m_axis,SIGNAL(linePenChanged(const QPen&)),this,SLOT(handleArrowPenChanged(const QPen&)));
75 QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&)));
75 QObject::connect(m_axis,SIGNAL(labelsPenChanged(const QPen&)),this,SLOT(handleLabelsPenChanged(const QPen&)));
76 QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&)));
76 QObject::connect(m_axis,SIGNAL(labelsBrushChanged(const QBrush&)),this,SLOT(handleLabelsBrushChanged(const QBrush&)));
77 QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&)));
77 QObject::connect(m_axis,SIGNAL(labelsFontChanged(const QFont&)),this,SLOT(handleLabelsFontChanged(const QFont&)));
78 QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&)));
78 QObject::connect(m_axis,SIGNAL(gridLinePenChanged(const QPen&)),this,SLOT(handleGridPenChanged(const QPen&)));
79 QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&)));
79 QObject::connect(m_axis,SIGNAL(shadesPenChanged(const QPen&)),this,SLOT(handleShadesPenChanged(const QPen&)));
80 QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&)));
80 QObject::connect(m_axis,SIGNAL(shadesBrushChanged(const QBrush&)),this,SLOT(handleShadesBrushChanged(const QBrush&)));
81 QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&)));
81 QObject::connect(m_axis,SIGNAL(titleTextChanged(const QString&)),this,SLOT(handleTitleTextChanged(const QString&)));
82 QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&)));
82 QObject::connect(m_axis,SIGNAL(titleFontChanged(const QFont&)),this,SLOT(handleTitleFontChanged(const QFont&)));
83 QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&)));
83 QObject::connect(m_axis,SIGNAL(titlePenChanged(const QPen&)),this,SLOT(handleTitlePenChanged(const QPen&)));
84 QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&)));
84 QObject::connect(m_axis,SIGNAL(titleBrushChanged(const QBrush&)),this,SLOT(handleTitleBrushChanged(const QBrush&)));
85 QObject::connect(m_axis,SIGNAL(titleVisibleChanged(bool)),this,SLOT(handleTitleVisibleChanged(bool)));
85 QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal)));
86 QObject::connect(m_axis->d_ptr.data(),SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(handleRangeChanged(qreal,qreal)));
86 }
87 }
87
88
88 ChartAxis::~ChartAxis()
89 ChartAxis::~ChartAxis()
89 {
90 {
90 }
91 }
91
92
92 void ChartAxis::setAnimation(AxisAnimation *animation)
93 void ChartAxis::setAnimation(AxisAnimation *animation)
93 {
94 {
94 m_animation = animation;
95 m_animation = animation;
95 }
96 }
96
97
97 void ChartAxis::setLayout(QVector<qreal> &layout)
98 void ChartAxis::setLayout(QVector<qreal> &layout)
98 {
99 {
99 m_layoutVector = layout;
100 m_layoutVector = layout;
100 }
101 }
101
102
102 void ChartAxis::createItems(int count)
103 void ChartAxis::createItems(int count)
103 {
104 {
104 if (m_arrow->childItems().size() == 0){
105 if (m_arrow->childItems().size() == 0){
105 QGraphicsLineItem* arrow = new ArrowItem(this, this);
106 QGraphicsLineItem* arrow = new ArrowItem(this, this);
106 arrow->setPen(m_axis->linePen());
107 arrow->setPen(m_axis->linePen());
107 m_arrow->addToGroup(arrow);
108 m_arrow->addToGroup(arrow);
108 }
109 }
109
110
110 if (m_intervalAxis && m_grid->childItems().size() == 0) {
111 if (m_intervalAxis && m_grid->childItems().size() == 0) {
111 for (int i = 0 ; i < 2 ; i ++){
112 for (int i = 0 ; i < 2 ; i ++){
112 QGraphicsLineItem* item = new QGraphicsLineItem(this);
113 QGraphicsLineItem* item = new QGraphicsLineItem(this);
113 item->setPen(m_axis->gridLinePen());
114 item->setPen(m_axis->gridLinePen());
114 m_grid->addToGroup(item);
115 m_grid->addToGroup(item);
115 }
116 }
116 }
117 }
117
118
118 for (int i = 0; i < count; ++i) {
119 for (int i = 0; i < count; ++i) {
119 QGraphicsLineItem* arrow = new QGraphicsLineItem(this);
120 QGraphicsLineItem* arrow = new QGraphicsLineItem(this);
120 arrow->setPen(m_axis->linePen());
121 arrow->setPen(m_axis->linePen());
121 QGraphicsLineItem* grid = new QGraphicsLineItem(this);
122 QGraphicsLineItem* grid = new QGraphicsLineItem(this);
122 grid->setPen(m_axis->gridLinePen());
123 grid->setPen(m_axis->gridLinePen());
123 QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this);
124 QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(this);
124 label->setFont(m_axis->labelsFont());
125 label->setFont(m_axis->labelsFont());
125 label->setPen(m_axis->labelsPen());
126 label->setPen(m_axis->labelsPen());
126 label->setBrush(m_axis->labelsBrush());
127 label->setBrush(m_axis->labelsBrush());
127 m_arrow->addToGroup(arrow);
128 m_arrow->addToGroup(arrow);
128 m_grid->addToGroup(grid);
129 m_grid->addToGroup(grid);
129 m_labels->addToGroup(label);
130 m_labels->addToGroup(label);
130
131
131 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){
132 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2){
132 QGraphicsRectItem* shades = new QGraphicsRectItem(this);
133 QGraphicsRectItem* shades = new QGraphicsRectItem(this);
133 shades->setPen(m_axis->shadesPen());
134 shades->setPen(m_axis->shadesPen());
134 shades->setBrush(m_axis->shadesBrush());
135 shades->setBrush(m_axis->shadesBrush());
135 m_shades->addToGroup(shades);
136 m_shades->addToGroup(shades);
136 }
137 }
137 }
138 }
138
139
139 }
140 }
140
141
141 void ChartAxis::deleteItems(int count)
142 void ChartAxis::deleteItems(int count)
142 {
143 {
143 QList<QGraphicsItem *> lines = m_grid->childItems();
144 QList<QGraphicsItem *> lines = m_grid->childItems();
144 QList<QGraphicsItem *> labels = m_labels->childItems();
145 QList<QGraphicsItem *> labels = m_labels->childItems();
145 QList<QGraphicsItem *> shades = m_shades->childItems();
146 QList<QGraphicsItem *> shades = m_shades->childItems();
146 QList<QGraphicsItem *> axis = m_arrow->childItems();
147 QList<QGraphicsItem *> axis = m_arrow->childItems();
147
148
148 for (int i = 0; i < count; ++i) {
149 for (int i = 0; i < count; ++i) {
149 if (lines.size() % 2 && lines.size() > 1)
150 if (lines.size() % 2 && lines.size() > 1)
150 delete(shades.takeLast());
151 delete(shades.takeLast());
151 delete(lines.takeLast());
152 delete(lines.takeLast());
152 delete(labels.takeLast());
153 delete(labels.takeLast());
153 delete(axis.takeLast());
154 delete(axis.takeLast());
154 }
155 }
155 }
156 }
156
157
157 void ChartAxis::updateLayout(QVector<qreal> &layout)
158 void ChartAxis::updateLayout(QVector<qreal> &layout)
158 {
159 {
159 int diff = m_layoutVector.size() - layout.size();
160 int diff = m_layoutVector.size() - layout.size();
160
161
161 if (diff > 0)
162 if (diff > 0)
162 deleteItems(diff);
163 deleteItems(diff);
163 else if (diff < 0)
164 else if (diff < 0)
164 createItems(-diff);
165 createItems(-diff);
165
166
166 if (m_animation) {
167 if (m_animation) {
167 switch (presenter()->state()) {
168 switch (presenter()->state()) {
168 case ChartPresenter::ZoomInState:
169 case ChartPresenter::ZoomInState:
169 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
170 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
170 m_animation->setAnimationPoint(presenter()->statePoint());
171 m_animation->setAnimationPoint(presenter()->statePoint());
171 break;
172 break;
172 case ChartPresenter::ZoomOutState:
173 case ChartPresenter::ZoomOutState:
173 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
174 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
174 m_animation->setAnimationPoint(presenter()->statePoint());
175 m_animation->setAnimationPoint(presenter()->statePoint());
175 break;
176 break;
176 case ChartPresenter::ScrollUpState:
177 case ChartPresenter::ScrollUpState:
177 case ChartPresenter::ScrollLeftState:
178 case ChartPresenter::ScrollLeftState:
178 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
179 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
179 break;
180 break;
180 case ChartPresenter::ScrollDownState:
181 case ChartPresenter::ScrollDownState:
181 case ChartPresenter::ScrollRightState:
182 case ChartPresenter::ScrollRightState:
182 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
183 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
183 break;
184 break;
184 case ChartPresenter::ShowState:
185 case ChartPresenter::ShowState:
185 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
186 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
186 break;
187 break;
187 }
188 }
188 m_animation->setValues(m_layoutVector, layout);
189 m_animation->setValues(m_layoutVector, layout);
189 presenter()->startAnimation(m_animation);
190 presenter()->startAnimation(m_animation);
190 } else {
191 } else {
191 setLayout(layout);
192 setLayout(layout);
192 updateGeometry();
193 updateGeometry();
193 }
194 }
194 }
195 }
195
196
196 void ChartAxis::setLabelPadding(int padding)
197 void ChartAxis::setLabelPadding(int padding)
197 {
198 {
198 m_labelPadding = padding;
199 m_labelPadding = padding;
199 }
200 }
200
201
201 bool ChartAxis::isEmpty()
202 bool ChartAxis::isEmpty()
202 {
203 {
203 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max());
204 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max());
204 }
205 }
205
206
206 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
207 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
207 {
208 {
208 m_gridRect = grid;
209 m_gridRect = grid;
209 m_axisRect = axis;
210 m_axisRect = axis;
210
211
211 if (isEmpty())
212 if (isEmpty())
212 return;
213 return;
213
214
214 QVector<qreal> layout = calculateLayout();
215 QVector<qreal> layout = calculateLayout();
215 updateLayout(layout);
216 updateLayout(layout);
216 }
217 }
217
218
218 qreal ChartAxis::min() const
219 qreal ChartAxis::min() const
219 {
220 {
220 return m_axis->d_ptr->min();
221 return m_axis->d_ptr->min();
221 }
222 }
222
223
223 qreal ChartAxis::max() const
224 qreal ChartAxis::max() const
224 {
225 {
225 return m_axis->d_ptr->max();
226 return m_axis->d_ptr->max();
226 }
227 }
227
228
228 QFont ChartAxis::font() const
229 QFont ChartAxis::font() const
229 {
230 {
230 return m_axis->labelsFont();
231 return m_axis->labelsFont();
231 }
232 }
232
233
233 QFont ChartAxis::titleFont() const
234 QFont ChartAxis::titleFont() const
234 {
235 {
235 return m_axis->titleFont();
236 return m_axis->titleFont();
236 }
237 }
237
238
238 QString ChartAxis::titleText() const
239 QString ChartAxis::titleText() const
239 {
240 {
240 return m_axis->titleText();
241 return m_axis->titleText();
241 }
242 }
242
243
243 void ChartAxis::axisSelected()
244 void ChartAxis::axisSelected()
244 {
245 {
245 emit clicked();
246 emit clicked();
246 }
247 }
247
248
248 Qt::Orientation ChartAxis::orientation() const
249 Qt::Orientation ChartAxis::orientation() const
249 {
250 {
250 return m_axis->orientation();
251 return m_axis->orientation();
251 }
252 }
252
253
253 Qt::Alignment ChartAxis::alignment() const
254 Qt::Alignment ChartAxis::alignment() const
254 {
255 {
255 return m_axis->alignment();
256 return m_axis->alignment();
256 }
257 }
257
258
258 void ChartAxis::setLabels(const QStringList &labels)
259 void ChartAxis::setLabels(const QStringList &labels)
259 {
260 {
260 m_labelsList = labels;
261 m_labelsList = labels;
261 }
262 }
262
263
263 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
264 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
264 {
265 {
265 Q_UNUSED(which);
266 Q_UNUSED(which);
266 Q_UNUSED(constraint);
267 Q_UNUSED(constraint);
267 return QSizeF();
268 return QSizeF();
268 }
269 }
269
270
270 //handlers
271 //handlers
271
272
272 void ChartAxis::handleArrowVisibleChanged(bool visible)
273 void ChartAxis::handleArrowVisibleChanged(bool visible)
273 {
274 {
274 m_arrow->setVisible(visible);
275 m_arrow->setVisible(visible);
275 }
276 }
276
277
277 void ChartAxis::handleGridVisibleChanged(bool visible)
278 void ChartAxis::handleGridVisibleChanged(bool visible)
278 {
279 {
279 m_grid->setVisible(visible);
280 m_grid->setVisible(visible);
280 }
281 }
281
282
282 void ChartAxis::handleLabelsVisibleChanged(bool visible)
283 void ChartAxis::handleLabelsVisibleChanged(bool visible)
283 {
284 {
284 m_labels->setVisible(visible);
285 m_labels->setVisible(visible);
285 }
286 }
286
287
287 void ChartAxis::handleShadesVisibleChanged(bool visible)
288 void ChartAxis::handleShadesVisibleChanged(bool visible)
288 {
289 {
289 m_shades->setVisible(visible);
290 m_shades->setVisible(visible);
290 }
291 }
291
292
293 void ChartAxis::handleTitleVisibleChanged(bool visible)
294 {
295 m_title->setVisible(visible);
296 presenter()->layout()->invalidate();
297 }
298
292 void ChartAxis::handleLabelsAngleChanged(int angle)
299 void ChartAxis::handleLabelsAngleChanged(int angle)
293 {
300 {
294 foreach (QGraphicsItem *item, m_labels->childItems())
301 foreach (QGraphicsItem *item, m_labels->childItems())
295 item->setRotation(angle);
302 item->setRotation(angle);
296
303
297 m_labelsAngle = angle;
304 m_labelsAngle = angle;
298 }
305 }
299
306
300 void ChartAxis::handleLabelsPenChanged(const QPen &pen)
307 void ChartAxis::handleLabelsPenChanged(const QPen &pen)
301 {
308 {
302 foreach (QGraphicsItem *item , m_labels->childItems())
309 foreach (QGraphicsItem *item , m_labels->childItems())
303 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
310 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
304 }
311 }
305
312
306 void ChartAxis::handleLabelsBrushChanged(const QBrush &brush)
313 void ChartAxis::handleLabelsBrushChanged(const QBrush &brush)
307 {
314 {
308 foreach (QGraphicsItem *item , m_labels->childItems())
315 foreach (QGraphicsItem *item , m_labels->childItems())
309 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
316 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
310 }
317 }
311
318
312 void ChartAxis::handleLabelsFontChanged(const QFont &font)
319 void ChartAxis::handleLabelsFontChanged(const QFont &font)
313 {
320 {
314 foreach (QGraphicsItem *item , m_labels->childItems())
321 foreach (QGraphicsItem *item , m_labels->childItems())
315 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
322 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
316 QGraphicsLayoutItem::updateGeometry();
323 QGraphicsLayoutItem::updateGeometry();
317 presenter()->layout()->invalidate();
324 presenter()->layout()->invalidate();
318 }
325 }
319
326
320 void ChartAxis::handleShadesBrushChanged(const QBrush &brush)
327 void ChartAxis::handleShadesBrushChanged(const QBrush &brush)
321 {
328 {
322 foreach (QGraphicsItem *item , m_shades->childItems())
329 foreach (QGraphicsItem *item , m_shades->childItems())
323 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
330 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
324 }
331 }
325
332
326 void ChartAxis::handleShadesPenChanged(const QPen &pen)
333 void ChartAxis::handleShadesPenChanged(const QPen &pen)
327 {
334 {
328 foreach (QGraphicsItem *item , m_shades->childItems())
335 foreach (QGraphicsItem *item , m_shades->childItems())
329 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
336 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
330 }
337 }
331
338
332 void ChartAxis::handleArrowPenChanged(const QPen &pen)
339 void ChartAxis::handleArrowPenChanged(const QPen &pen)
333 {
340 {
334 foreach (QGraphicsItem *item , m_arrow->childItems())
341 foreach (QGraphicsItem *item , m_arrow->childItems())
335 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
342 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
336 }
343 }
337
344
338 void ChartAxis::handleGridPenChanged(const QPen &pen)
345 void ChartAxis::handleGridPenChanged(const QPen &pen)
339 {
346 {
340 foreach (QGraphicsItem *item , m_grid->childItems())
347 foreach (QGraphicsItem *item , m_grid->childItems())
341 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
348 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
342 }
349 }
343
350
344 void ChartAxis::handleTitleTextChanged(const QString &title)
351 void ChartAxis::handleTitleTextChanged(const QString &title)
345 {
352 {
346 Q_UNUSED(title)
353 Q_UNUSED(title)
347 QGraphicsLayoutItem::updateGeometry();
354 QGraphicsLayoutItem::updateGeometry();
348 presenter()->layout()->invalidate();
355 presenter()->layout()->invalidate();
349 }
356 }
350
357
351
358
352 void ChartAxis::handleTitlePenChanged(const QPen &pen)
359 void ChartAxis::handleTitlePenChanged(const QPen &pen)
353 {
360 {
354 m_title->setPen(pen);
361 m_title->setPen(pen);
355 }
362 }
356
363
357 void ChartAxis::handleTitleBrushChanged(const QBrush &brush)
364 void ChartAxis::handleTitleBrushChanged(const QBrush &brush)
358 {
365 {
359 m_title->setBrush(brush);
366 m_title->setBrush(brush);
360 }
367 }
361
368
362 void ChartAxis::handleTitleFontChanged(const QFont &font)
369 void ChartAxis::handleTitleFontChanged(const QFont &font)
363 {
370 {
364 if(m_title->font() != font){
371 if(m_title->font() != font){
365 m_title->setFont(font);
372 m_title->setFont(font);
366 QGraphicsLayoutItem::updateGeometry();
373 QGraphicsLayoutItem::updateGeometry();
367 presenter()->layout()->invalidate();
374 presenter()->layout()->invalidate();
368 }
375 }
369 }
376 }
370
377
371 void ChartAxis::handleVisibleChanged(bool visible)
378 void ChartAxis::handleVisibleChanged(bool visible)
372 {
379 {
373 setVisible(visible);
380 setVisible(visible);
381 if(!visible) {
382 m_grid->setVisible(visible);
383 m_arrow->setVisible(visible);
384 m_shades->setVisible(visible);
385 m_labels->setVisible(visible);
386 m_title->setVisible(visible);
387 }else {
388 m_grid->setVisible(m_axis->isGridLineVisible());
389 m_arrow->setVisible(m_axis->isLineVisible());
390 m_shades->setVisible(m_axis->shadesVisible());
391 m_labels->setVisible(m_axis->labelsVisible());
392 m_title->setVisible(m_axis->isTitleVisible());
393 }
394
395 presenter()->layout()->invalidate();
374 }
396 }
375
397
376 void ChartAxis::handleRangeChanged(qreal min, qreal max)
398 void ChartAxis::handleRangeChanged(qreal min, qreal max)
377 {
399 {
378 Q_UNUSED(min);
400 Q_UNUSED(min);
379 Q_UNUSED(max);
401 Q_UNUSED(max);
380
402
381 if (!isEmpty()) {
403 if (!isEmpty()) {
382
404
383 QVector<qreal> layout = calculateLayout();
405 QVector<qreal> layout = calculateLayout();
384 updateLayout(layout);
406 updateLayout(layout);
385 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
407 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
386 QSizeF after = sizeHint(Qt::PreferredSize);
408 QSizeF after = sizeHint(Qt::PreferredSize);
387
409
388 if (before != after) {
410 if (before != after) {
389 QGraphicsLayoutItem::updateGeometry();
411 QGraphicsLayoutItem::updateGeometry();
390 //we don't want to call invalidate on layout, since it will change minimum size of component,
412 //we don't want to call invalidate on layout, since it will change minimum size of component,
391 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
413 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
392 //instead recalculate layout and use plotArea for extra space.
414 //instead recalculate layout and use plotArea for extra space.
393 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
415 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
394 }
416 }
395 }
417 }
396
418
397 }
419 }
398
420
399 //helpers
421 //helpers
400
422
401 QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format)
423 QStringList ChartAxis::createValueLabels(qreal min, qreal max, int ticks,const QString& format)
402 {
424 {
403 //TODO: Q_ASSERT(m_max > m_min);
425 //TODO: Q_ASSERT(m_max > m_min);
404 //TODO: Q_ASSERT(ticks > 1);
426 //TODO: Q_ASSERT(ticks > 1);
405
427
406 QStringList labels;
428 QStringList labels;
407
429
408 if(max <= min || ticks < 1){
430 if(max <= min || ticks < 1){
409 return labels;
431 return labels;
410 }
432 }
411
433
412 int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
434 int n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
413 n++;
435 n++;
414
436
415 if (format.isNull()) {
437 if (format.isNull()) {
416 for (int i = 0; i < ticks; i++) {
438 for (int i = 0; i < ticks; i++) {
417 qreal value = min + (i * (max - min) / (ticks - 1));
439 qreal value = min + (i * (max - min) / (ticks - 1));
418 labels << QString::number(value, 'f', n);
440 labels << QString::number(value, 'f', n);
419 }
441 }
420 } else {
442 } else {
421 QByteArray array = format.toLatin1();
443 QByteArray array = format.toLatin1();
422 for (int i = 0; i < ticks; i++) {
444 for (int i = 0; i < ticks; i++) {
423 qreal value = min + (i * (max - min) / (ticks - 1));
445 qreal value = min + (i * (max - min) / (ticks - 1));
424 if (format.contains("d")
446 if (format.contains("d")
425 || format.contains("i")
447 || format.contains("i")
426 || format.contains("c"))
448 || format.contains("c"))
427 labels << QString().sprintf(array, (qint64)value);
449 labels << QString().sprintf(array, (qint64)value);
428 else if (format.contains("u")
450 else if (format.contains("u")
429 || format.contains("o")
451 || format.contains("o")
430 || format.contains("x", Qt::CaseInsensitive))
452 || format.contains("x", Qt::CaseInsensitive))
431 labels << QString().sprintf(array, (quint64)value);
453 labels << QString().sprintf(array, (quint64)value);
432 else if (format.contains("f", Qt::CaseInsensitive)
454 else if (format.contains("f", Qt::CaseInsensitive)
433 || format.contains("e", Qt::CaseInsensitive)
455 || format.contains("e", Qt::CaseInsensitive)
434 || format.contains("g", Qt::CaseInsensitive))
456 || format.contains("g", Qt::CaseInsensitive))
435 labels << QString().sprintf(array, value);
457 labels << QString().sprintf(array, value);
436 }
458 }
437 }
459 }
438
460
439 return labels;
461 return labels;
440 }
462 }
441
463
442 QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format)
464 QStringList ChartAxis::createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format)
443 {
465 {
444 // Q_ASSERT(m_max > m_min);
466 // Q_ASSERT(m_max > m_min);
445 // Q_ASSERT(ticks > 1);
467 // Q_ASSERT(ticks > 1);
446
468
447 QStringList labels;
469 QStringList labels;
448
470
449 int n = 0;
471 int n = 0;
450 if (ticks > 1)
472 if (ticks > 1)
451 n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
473 n = qMax(int(-qFloor(log10((max - min) / (ticks - 1)))), 0);
452 n++;
474 n++;
453
475
454 int firstTick;
476 int firstTick;
455 if (base > 1)
477 if (base > 1)
456 firstTick = ceil(log10(min) / log10(base));
478 firstTick = ceil(log10(min) / log10(base));
457 else
479 else
458 firstTick = ceil(log10(max) / log10(base));
480 firstTick = ceil(log10(max) / log10(base));
459
481
460 if (format.isNull()) {
482 if (format.isNull()) {
461 for (int i = firstTick; i < ticks + firstTick; i++) {
483 for (int i = firstTick; i < ticks + firstTick; i++) {
462 qreal value = qPow(base, i);
484 qreal value = qPow(base, i);
463 labels << QString::number(value, 'f', n);
485 labels << QString::number(value, 'f', n);
464 }
486 }
465 } else {
487 } else {
466 QByteArray array = format.toLatin1();
488 QByteArray array = format.toLatin1();
467 for (int i = firstTick; i < ticks + firstTick; i++) {
489 for (int i = firstTick; i < ticks + firstTick; i++) {
468 qreal value = qPow(base, i);
490 qreal value = qPow(base, i);
469 if (format.contains("d")
491 if (format.contains("d")
470 || format.contains("i")
492 || format.contains("i")
471 || format.contains("c"))
493 || format.contains("c"))
472 labels << QString().sprintf(array, (qint64)value);
494 labels << QString().sprintf(array, (qint64)value);
473 else if (format.contains("u")
495 else if (format.contains("u")
474 || format.contains("o")
496 || format.contains("o")
475 || format.contains("x", Qt::CaseInsensitive))
497 || format.contains("x", Qt::CaseInsensitive))
476 labels << QString().sprintf(array, (quint64)value);
498 labels << QString().sprintf(array, (quint64)value);
477 else if (format.contains("f", Qt::CaseInsensitive)
499 else if (format.contains("f", Qt::CaseInsensitive)
478 || format.contains("e", Qt::CaseInsensitive)
500 || format.contains("e", Qt::CaseInsensitive)
479 || format.contains("g", Qt::CaseInsensitive))
501 || format.contains("g", Qt::CaseInsensitive))
480 labels << QString().sprintf(array, value);
502 labels << QString().sprintf(array, value);
481 }
503 }
482 }
504 }
483
505
484 return labels;
506 return labels;
485 }
507 }
486
508
487 QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format)
509 QStringList ChartAxis::createDateTimeLabels(qreal min, qreal max,int ticks,const QString& format)
488 {
510 {
489 //TODO: Q_ASSERT(m_max > m_min);
511 //TODO: Q_ASSERT(m_max > m_min);
490 //TODO: Q_ASSERT(ticks > 1);
512 //TODO: Q_ASSERT(ticks > 1);
491 QStringList labels;
513 QStringList labels;
492
514
493 if(max <= min || ticks < 1) {
515 if(max <= min || ticks < 1) {
494 return labels;
516 return labels;
495 }
517 }
496
518
497 int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0);
519 int n = qMax(int(-floor(log10((max - min) / (ticks - 1)))), 0);
498 n++;
520 n++;
499 for (int i = 0; i < ticks; i++) {
521 for (int i = 0; i < ticks; i++) {
500 qreal value = min + (i * (max - min) / (ticks - 1));
522 qreal value = min + (i * (max - min) / (ticks - 1));
501 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
523 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
502 }
524 }
503 return labels;
525 return labels;
504 }
526 }
505
527
506 #include "moc_chartaxis_p.cpp"
528 #include "moc_chartaxis_p.cpp"
507
529
508 QTCOMMERCIALCHART_END_NAMESPACE
530 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,195 +1,196
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 CHARTAXIS_H
30 #ifndef CHARTAXIS_H
31 #define CHARTAXIS_H
31 #define CHARTAXIS_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "chartelement_p.h"
34 #include "chartelement_p.h"
35 #include "axisanimation_p.h"
35 #include "axisanimation_p.h"
36 #include <QGraphicsItem>
36 #include <QGraphicsItem>
37 #include <QGraphicsLayoutItem>
37 #include <QGraphicsLayoutItem>
38 #include <QFont>
38 #include <QFont>
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class QAbstractAxis;
42 class QAbstractAxis;
43 class ChartPresenter;
43 class ChartPresenter;
44
44
45 class ChartAxis : public ChartElement, public QGraphicsLayoutItem
45 class ChartAxis : public ChartElement, public QGraphicsLayoutItem
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 Q_INTERFACES(QGraphicsLayoutItem)
48 Q_INTERFACES(QGraphicsLayoutItem)
49 public:
49 public:
50
50
51 ChartAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false);
51 ChartAxis(QAbstractAxis *axis, QGraphicsItem* item = 0, bool intervalAxis = false);
52 ~ChartAxis();
52 ~ChartAxis();
53
53
54 QAbstractAxis* axis() const { return m_axis; }
54 QAbstractAxis* axis() const { return m_axis; }
55
55
56 void setLabelPadding(int padding);
56 void setLabelPadding(int padding);
57 int labelPadding() const { return m_labelPadding;};
57 int labelPadding() const { return m_labelPadding;};
58
58
59 QFont titleFont() const;
59 QFont titleFont() const;
60 QString titleText() const;
60 QString titleText() const;
61
61
62 void setLayout(QVector<qreal> &layout);
62 void setLayout(QVector<qreal> &layout);
63 QVector<qreal> layout() const { return m_layoutVector; }
63 QVector<qreal> layout() const { return m_layoutVector; }
64
64
65 void setAnimation(AxisAnimation *animation);
65 void setAnimation(AxisAnimation *animation);
66 ChartAnimation *animation() const { return m_animation; };
66 ChartAnimation *animation() const { return m_animation; };
67
67
68 Qt::Orientation orientation() const;
68 Qt::Orientation orientation() const;
69 Qt::Alignment alignment() const;
69 Qt::Alignment alignment() const;
70
70
71 void setGeometry(const QRectF &axis, const QRectF &grid);
71 void setGeometry(const QRectF &axis, const QRectF &grid);
72 QRectF axisGeometry() const { return m_axisRect; }
72 QRectF axisGeometry() const { return m_axisRect; }
73 QRectF gridGeometry() const { return m_gridRect; }
73 QRectF gridGeometry() const { return m_gridRect; }
74
74
75 void setLabels(const QStringList &labels);
75 void setLabels(const QStringList &labels);
76 QStringList labels() const { return m_labelsList; }
76 QStringList labels() const { return m_labelsList; }
77
77
78 //this flag indicates that axis is used to show intervals it means labels are in between ticks
78 //this flag indicates that axis is used to show intervals it means labels are in between ticks
79 bool intervalAxis() const { return m_intervalAxis; }
79 bool intervalAxis() const { return m_intervalAxis; }
80
80
81 virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
81 virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
82
82
83
83
84 QRectF boundingRect() const{
84 QRectF boundingRect() const{
85 return QRectF();
85 return QRectF();
86 }
86 }
87
87
88 void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
88 void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*)
89 {
89 {
90
90
91 }
91 }
92
92
93 //helpers
93 //helpers
94 static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format);
94 static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format);
95 static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format);
95 static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString& format);
96 static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format);
96 static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format);
97
97
98 protected:
98 protected:
99 void setGeometry(const QRectF &size) { Q_UNUSED(size);};
99 void setGeometry(const QRectF &size) { Q_UNUSED(size);};
100 virtual void updateGeometry() = 0;
100 virtual void updateGeometry() = 0;
101 virtual QVector<qreal> calculateLayout() const = 0;
101 virtual QVector<qreal> calculateLayout() const = 0;
102
102
103 QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); };
103 QList<QGraphicsItem *> lineItems() { return m_grid->childItems(); };
104 QList<QGraphicsItem *> labelItems() { return m_labels->childItems();};
104 QList<QGraphicsItem *> labelItems() { return m_labels->childItems();};
105 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();};
105 QList<QGraphicsItem *> shadeItems() { return m_shades->childItems();};
106 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();};
106 QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems();};
107 QGraphicsSimpleTextItem* titleItem() const { return m_title.data();}
107 QGraphicsSimpleTextItem* titleItem() const { return m_title.data();}
108
108
109 QFont font() const;
109 QFont font() const;
110 qreal min() const;
110 qreal min() const;
111 qreal max() const;
111 qreal max() const;
112
112
113 //handlers
113 //handlers
114 public Q_SLOTS:
114 public Q_SLOTS:
115 void handleVisibleChanged(bool visible);
115 void handleVisibleChanged(bool visible);
116 void handleArrowVisibleChanged(bool visible);
116 void handleArrowVisibleChanged(bool visible);
117 void handleGridVisibleChanged(bool visible);
117 void handleGridVisibleChanged(bool visible);
118 void handleLabelsVisibleChanged(bool visible);
118 void handleLabelsVisibleChanged(bool visible);
119 void handleShadesVisibleChanged(bool visible);
119 void handleShadesVisibleChanged(bool visible);
120 void handleLabelsAngleChanged(int angle);
120 void handleLabelsAngleChanged(int angle);
121 void handleShadesBrushChanged(const QBrush &brush);
121 void handleShadesBrushChanged(const QBrush &brush);
122 void handleShadesPenChanged(const QPen &pen);
122 void handleShadesPenChanged(const QPen &pen);
123 void handleArrowPenChanged(const QPen &pen);
123 void handleArrowPenChanged(const QPen &pen);
124 void handleGridPenChanged(const QPen &pen);
124 void handleGridPenChanged(const QPen &pen);
125 void handleLabelsPenChanged(const QPen &pen);
125 void handleLabelsPenChanged(const QPen &pen);
126 void handleLabelsBrushChanged(const QBrush &brush);
126 void handleLabelsBrushChanged(const QBrush &brush);
127 void handleLabelsFontChanged(const QFont &font);
127 void handleLabelsFontChanged(const QFont &font);
128 void handleTitlePenChanged(const QPen &pen);
128 void handleTitlePenChanged(const QPen &pen);
129 void handleTitleBrushChanged(const QBrush &brush);
129 void handleTitleBrushChanged(const QBrush &brush);
130 void handleTitleFontChanged(const QFont &font);
130 void handleTitleFontChanged(const QFont &font);
131 void handleTitleTextChanged(const QString &title);
131 void handleTitleTextChanged(const QString &title);
132 void handleTitleVisibleChanged(bool visible);
132 void handleRangeChanged(qreal min , qreal max);
133 void handleRangeChanged(qreal min , qreal max);
133
134
134 Q_SIGNALS:
135 Q_SIGNALS:
135 void clicked();
136 void clicked();
136
137
137 private:
138 private:
138 inline bool isEmpty();
139 inline bool isEmpty();
139 void createItems(int count);
140 void createItems(int count);
140 void deleteItems(int count);
141 void deleteItems(int count);
141 void updateLayout(QVector<qreal> &layout);
142 void updateLayout(QVector<qreal> &layout);
142 void axisSelected();
143 void axisSelected();
143 void connectSlots();
144 void connectSlots();
144
145
145 private:
146 private:
146 QAbstractAxis *m_axis;
147 QAbstractAxis *m_axis;
147 int m_labelsAngle;
148 int m_labelsAngle;
148 QRectF m_axisRect;
149 QRectF m_axisRect;
149 QRectF m_gridRect;
150 QRectF m_gridRect;
150 QScopedPointer<QGraphicsItemGroup> m_grid;
151 QScopedPointer<QGraphicsItemGroup> m_grid;
151 QScopedPointer<QGraphicsItemGroup> m_arrow;
152 QScopedPointer<QGraphicsItemGroup> m_arrow;
152 QScopedPointer<QGraphicsItemGroup> m_shades;
153 QScopedPointer<QGraphicsItemGroup> m_shades;
153 QScopedPointer<QGraphicsItemGroup> m_labels;
154 QScopedPointer<QGraphicsItemGroup> m_labels;
154 QScopedPointer<QGraphicsSimpleTextItem> m_title;
155 QScopedPointer<QGraphicsSimpleTextItem> m_title;
155 QVector<qreal> m_layoutVector;
156 QVector<qreal> m_layoutVector;
156 AxisAnimation *m_animation;
157 AxisAnimation *m_animation;
157 int m_labelPadding;
158 int m_labelPadding;
158 QStringList m_labelsList;
159 QStringList m_labelsList;
159 bool m_intervalAxis;
160 bool m_intervalAxis;
160
161
161 friend class AxisAnimation;
162 friend class AxisAnimation;
162 friend class ArrowItem;
163 friend class ArrowItem;
163
164
164 };
165 };
165
166
166 class ArrowItem: public QGraphicsLineItem
167 class ArrowItem: public QGraphicsLineItem
167 {
168 {
168
169
169 public:
170 public:
170 explicit ArrowItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
171 explicit ArrowItem(ChartAxis *axis, QGraphicsItem *parent = 0) : QGraphicsLineItem(parent), m_axis(axis) {}
171
172
172 protected:
173 protected:
173 void mousePressEvent(QGraphicsSceneMouseEvent *event) {
174 void mousePressEvent(QGraphicsSceneMouseEvent *event) {
174 Q_UNUSED(event)
175 Q_UNUSED(event)
175 m_axis->axisSelected();
176 m_axis->axisSelected();
176 }
177 }
177
178
178 QRectF boundingRect() const {
179 QRectF boundingRect() const {
179 return shape().boundingRect();
180 return shape().boundingRect();
180 }
181 }
181
182
182 QPainterPath shape() const {
183 QPainterPath shape() const {
183 QPainterPath path = QGraphicsLineItem::shape();
184 QPainterPath path = QGraphicsLineItem::shape();
184 QRectF rect = path.boundingRect();
185 QRectF rect = path.boundingRect();
185 path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0));
186 path.addRect(rect.adjusted(0, 0, m_axis->orientation() != Qt::Horizontal ? 8 : 0, m_axis->orientation() != Qt::Vertical ? 8 : 0));
186 return path;
187 return path;
187 }
188 }
188
189
189 private:
190 private:
190 ChartAxis *m_axis;
191 ChartAxis *m_axis;
191 };
192 };
192
193
193 QTCOMMERCIALCHART_END_NAMESPACE
194 QTCOMMERCIALCHART_END_NAMESPACE
194
195
195 #endif /* CHARTAXI_H */
196 #endif /* CHARTAXI_H */
@@ -1,210 +1,210
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 "horizontalaxis_p.h"
21 #include "horizontalaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include <QFontMetrics>
23 #include <QFontMetrics>
24 #include <qmath.h>
24 #include <qmath.h>
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis)
29 HorizontalAxis::HorizontalAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxis)
30 : ChartAxis(axis, item, intervalAxis)
30 : ChartAxis(axis, item, intervalAxis)
31 {
31 {
32 }
32 }
33
33
34 HorizontalAxis::~HorizontalAxis()
34 HorizontalAxis::~HorizontalAxis()
35 {
35 {
36 }
36 }
37
37
38 void HorizontalAxis::updateGeometry()
38 void HorizontalAxis::updateGeometry()
39 {
39 {
40 const QVector<qreal>& layout = ChartAxis::layout();
40 const QVector<qreal>& layout = ChartAxis::layout();
41
41
42 if (layout.isEmpty())
42 if (layout.isEmpty())
43 return;
43 return;
44
44
45 QStringList labelList = labels();
45 QStringList labelList = labels();
46
46
47 QList<QGraphicsItem *> lines = lineItems();
47 QList<QGraphicsItem *> lines = lineItems();
48 QList<QGraphicsItem *> labels = labelItems();
48 QList<QGraphicsItem *> labels = labelItems();
49 QList<QGraphicsItem *> shades = shadeItems();
49 QList<QGraphicsItem *> shades = shadeItems();
50 QList<QGraphicsItem *> axis = arrowItems();
50 QList<QGraphicsItem *> axis = arrowItems();
51 QGraphicsSimpleTextItem* title = titleItem();
51 QGraphicsSimpleTextItem* title = titleItem();
52
52
53 Q_ASSERT(labels.size() == labelList.size());
53 Q_ASSERT(labels.size() == labelList.size());
54 Q_ASSERT(layout.size() == labelList.size());
54 Q_ASSERT(layout.size() == labelList.size());
55
55
56 const QRectF &axisRect = axisGeometry();
56 const QRectF &axisRect = axisGeometry();
57 const QRectF &gridRect = gridGeometry();
57 const QRectF &gridRect = gridGeometry();
58
58
59 //arrow
59 //arrow
60 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(axis.at(0));
60 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem *>(axis.at(0));
61
61
62 if (alignment() == Qt::AlignTop)
62 if (alignment() == Qt::AlignTop)
63 arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom());
63 arrowItem->setLine(gridRect.left(), axisRect.bottom(), gridRect.right(), axisRect.bottom());
64 else if (alignment() == Qt::AlignBottom)
64 else if (alignment() == Qt::AlignBottom)
65 arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top());
65 arrowItem->setLine(gridRect.left(), axisRect.top(), gridRect.right(), axisRect.top());
66
66
67 qreal width = 0;
67 qreal width = 0;
68 QFontMetrics fn(font());
68 QFontMetrics fn(font());
69
69
70 //title
70 //title
71
71
72 if (!titleText().isNull()) {
72 if (!titleText().isNull()) {
73 QFontMetrics fn(title->font());
73 QFontMetrics fn(title->font());
74
74
75 int size(0);
75 int size(0);
76
76
77 size = gridRect.width();
77 size = gridRect.width();
78 QString titleText = this->titleText();
78 QString titleText = this->titleText();
79
79
80 if (fn.boundingRect(titleText).width() > size) {
80 if (fn.boundingRect(titleText).width() > size) {
81 QString string = titleText + "...";
81 QString string = titleText + "...";
82 while (fn.boundingRect(string).width() > size && string.length() > 3)
82 while (fn.boundingRect(string).width() > size && string.length() > 3)
83 string.remove(string.length() - 4, 1);
83 string.remove(string.length() - 4, 1);
84 title->setText(string);
84 title->setText(string);
85 } else {
85 } else {
86 title->setText(titleText);
86 title->setText(titleText);
87 }
87 }
88
88
89 QPointF center = gridRect.center() - title->boundingRect().center();
89 QPointF center = gridRect.center() - title->boundingRect().center();
90 if (alignment() == Qt::AlignTop) {
90 if (alignment() == Qt::AlignTop) {
91 title->setPos(center.x(), axisRect.top());
91 title->setPos(center.x(), axisRect.top());
92 } else if (alignment() == Qt::AlignBottom) {
92 } else if (alignment() == Qt::AlignBottom) {
93 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height());
93 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height());
94 }
94 }
95 }
95 }
96
96
97 for (int i = 0; i < layout.size(); ++i) {
97 for (int i = 0; i < layout.size(); ++i) {
98
98
99 //items
99 //items
100 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i));
100 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem*>(lines.at(i));
101 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i + 1));
101 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem*>(axis.at(i + 1));
102 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
102 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
103
103
104 //grid line
104 //grid line
105 gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom());
105 gridItem->setLine(layout[i], gridRect.top(), layout[i], gridRect.bottom());
106
106
107 //label text wrapping
107 //label text wrapping
108 if(intervalAxis()&& i+1!=layout.size()) {
108 if(intervalAxis()&& i+1!=layout.size()) {
109 //wrapping in case of interval axis
109 //wrapping in case of interval axis
110 const qreal delta = layout[i+1] - layout[i];
110 const qreal delta = layout[i+1] - layout[i];
111 QString text = labelList.at(i);
111 QString text = labelList.at(i);
112 if (fn.boundingRect(text).width() + 1 > delta )
112 if (fn.boundingRect(text).width() + 1 > delta )
113 {
113 {
114 QString label = text + "...";
114 QString label = text + "...";
115 while (fn.boundingRect(label).width() >= delta && label.length() > 3)
115 while (fn.boundingRect(label).width() >= delta && label.length() > 3)
116 label.remove(label.length() - 4, 1);
116 label.remove(label.length() - 4, 1);
117 labelItem->setText(label);
117 labelItem->setText(label);
118 }
118 }
119 else {
119 else {
120 labelItem->setText(text);
120 labelItem->setText(text);
121 }
121 }
122 }else{
122 }else{
123 labelItem->setText(labelList.at(i));
123 labelItem->setText(labelList.at(i));
124 }
124 }
125
125
126 //label transformation origin point
126 //label transformation origin point
127 const QRectF& rect = labelItem->boundingRect();
127 const QRectF& rect = labelItem->boundingRect();
128 QPointF center = rect.center();
128 QPointF center = rect.center();
129 labelItem->setTransformOriginPoint(center.x(), center.y());
129 labelItem->setTransformOriginPoint(center.x(), center.y());
130
130
131 //ticks and label position
131 //ticks and label position
132 if (alignment() == Qt::AlignTop) {
132 if (alignment() == Qt::AlignTop) {
133 labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() - labelPadding());
133 labelItem->setPos(layout[i] - center.x(), axisRect.bottom() - rect.height() - labelPadding());
134 tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding());
134 tickItem->setLine(layout[i], axisRect.bottom(), layout[i], axisRect.bottom() - labelPadding());
135 } else if (alignment() == Qt::AlignBottom) {
135 } else if (alignment() == Qt::AlignBottom) {
136 labelItem->setPos(layout[i] - center.x(), axisRect.top() + labelPadding());
136 labelItem->setPos(layout[i] - center.x(), axisRect.top() + labelPadding());
137 tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding());
137 tickItem->setLine(layout[i], axisRect.top(), layout[i], axisRect.top() + labelPadding());
138 }
138 }
139
139
140 //label in beetwen
140 //label in beetwen
141 if(intervalAxis()&& i+1!=layout.size()) {
141 if(intervalAxis()&& i+1!=layout.size()) {
142 const qreal delta = (layout[i+1] - layout[i])/2;
142 const qreal delta = (layout[i+1] - layout[i])/2;
143 labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y());
143 labelItem->setPos(layout[i] + delta - center.x(), labelItem->pos().y());
144 }
144 }
145
145
146 //label overlap detection
146 //label overlap detection
147 if(labelItem->pos().x() < width ||
147 if(labelItem->pos().x() < width ||
148 labelItem->pos().x() < axisRect.left() ||
148 labelItem->pos().x() < axisRect.left() ||
149 labelItem->pos().x() + rect.width() > axisRect.right()) {
149 labelItem->pos().x() + rect.width() > axisRect.right()) {
150 labelItem->setVisible(false);
150 labelItem->setVisible(false);
151 } else {
151 } else {
152 labelItem->setVisible(true);
152 labelItem->setVisible(true);
153 width=rect.width()+labelItem->pos().x();
153 width=rect.width()+labelItem->pos().x();
154 }
154 }
155
155
156 //shades
156 //shades
157 if ((i + 1) % 2 && i > 1) {
157 if ((i + 1) % 2 && i > 1) {
158 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1));
158 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1));
159 rectItem->setRect(layout[i - 1], gridRect.top(), layout[i] - layout[i - 1], gridRect.height());
159 rectItem->setRect(layout[i - 1], gridRect.top(), layout[i] - layout[i - 1], gridRect.height());
160 }
160 }
161
161
162 // check if the grid line and the axis tick should be shown
162 // check if the grid line and the axis tick should be shown
163 qreal x = gridItem->line().p1().x();
163 qreal x = gridItem->line().p1().x();
164 if (x < gridRect.left() || x > gridRect.right()) {
164 if (x < gridRect.left() || x > gridRect.right()) {
165 gridItem->setVisible(false);
165 gridItem->setVisible(false);
166 tickItem->setVisible(false);
166 tickItem->setVisible(false);
167 }else{
167 }else{
168 gridItem->setVisible(true);
168 gridItem->setVisible(true);
169 tickItem->setVisible(true);
169 tickItem->setVisible(true);
170 }
170 }
171
171
172 }
172 }
173
173
174 //begin/end grid line in case labels between
174 //begin/end grid line in case labels between
175 if (intervalAxis()) {
175 if (intervalAxis()) {
176 QGraphicsLineItem *gridLine;
176 QGraphicsLineItem *gridLine;
177 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
177 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
178 gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom());
178 gridLine->setLine(gridRect.right(), gridRect.top(), gridRect.right(), gridRect.bottom());
179 gridLine->setVisible(true);
179 gridLine->setVisible(true);
180 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1));
180 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1));
181 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom());
181 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.left(), gridRect.bottom());
182 gridLine->setVisible(true);
182 gridLine->setVisible(true);
183 }
183 }
184 }
184 }
185
185
186 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
186 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
187 {
187 {
188 Q_UNUSED(constraint);
188 Q_UNUSED(constraint);
189 QFontMetrics fn(titleFont());
189 QFontMetrics fn(titleFont());
190 QSizeF sh;
190 QSizeF sh;
191
191
192 if (titleText().isNull())
192 if (titleText().isNull() || !titleItem()->isVisible())
193 return sh;
193 return sh;
194
194
195 switch (which) {
195 switch (which) {
196 case Qt::MinimumSize:
196 case Qt::MinimumSize:
197 sh = QSizeF(fn.boundingRect("...").width(), fn.height());
197 sh = QSizeF(fn.boundingRect("...").width(), fn.height());
198 break;
198 break;
199 case Qt::MaximumSize:
199 case Qt::MaximumSize:
200 case Qt::PreferredSize:
200 case Qt::PreferredSize:
201 sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height());
201 sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height());
202 break;
202 break;
203 default:
203 default:
204 break;
204 break;
205 }
205 }
206
206
207 return sh;
207 return sh;
208 }
208 }
209
209
210 QTCOMMERCIALCHART_END_NAMESPACE
210 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,869 +1,869
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 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "charttheme_p.h"
24 #include "charttheme_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QAbstractAxis
29 \class QAbstractAxis
30 \brief The QAbstractAxis class is used for manipulating chart's axis.
30 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 There is only one x Axis visible at the time, however there can be multiple y axes.
33 There is only one x Axis visible at the time, however there can be multiple y axes.
34 Each chart series can be bound to exactly one Y axis and the shared common X axis.
34 Each chart series can be bound to exactly one Y axis and the shared common X axis.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
35 Axis can be setup to show axis line with tick marks, grid lines and shades.
36 */
36 */
37
37
38 /*!
38 /*!
39 \qmlclass AbstractAxis QAbstractAxis
39 \qmlclass AbstractAxis QAbstractAxis
40 \brief The Axis element is used for manipulating chart's axes
40 \brief The Axis element is used for manipulating chart's axes
41
41
42 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
42 There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView.
43 Each chart series can be bound to exactly one Y axis and the shared common X axis.
43 Each chart series can be bound to exactly one Y axis and the shared common X axis.
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
44 Axis can be setup to show axis line with tick marks, grid lines and shades.
45
45
46 To access Axes you can use ChartView API. For example:
46 To access Axes you can use ChartView API. For example:
47 \code
47 \code
48 ChartView {
48 ChartView {
49 axisX.min: 0
49 axisX.min: 0
50 axisX.max: 3
50 axisX.max: 3
51 axisX.ticksCount: 4
51 axisX.ticksCount: 4
52 axisY.min: 0
52 axisY.min: 0
53 axisY.max: 4
53 axisY.max: 4
54 // Add a few series...
54 // Add a few series...
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \enum QAbstractAxis::AxisType
60 \enum QAbstractAxis::AxisType
61
61
62 The type of the series object.
62 The type of the series object.
63
63
64 \value AxisTypeNoAxis
64 \value AxisTypeNoAxis
65 \value AxisTypeValue
65 \value AxisTypeValue
66 \value AxisTypeBarCategory
66 \value AxisTypeBarCategory
67 \value AxisTypeCategory
67 \value AxisTypeCategory
68 \value AxisTypeDateTime
68 \value AxisTypeDateTime
69 */
69 */
70
70
71 /*!
71 /*!
72 *\fn void QAbstractAxis::type() const
72 *\fn void QAbstractAxis::type() const
73 Returns the type of the axis
73 Returns the type of the axis
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QAbstractAxis::lineVisible
77 \property QAbstractAxis::lineVisible
78 The visibility of the axis line
78 The visibility of the axis line
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty bool AbstractAxis::lineVisible
81 \qmlproperty bool AbstractAxis::lineVisible
82 The visibility of the axis line
82 The visibility of the axis line
83 */
83 */
84
84
85 /*!
85 /*!
86 \property QAbstractAxis::labelsVisible
86 \property QAbstractAxis::labelsVisible
87 Defines if axis labels are visible.
87 Defines if axis labels are visible.
88 */
88 */
89 /*!
89 /*!
90 \qmlproperty bool AbstractAxis::labelsVisible
90 \qmlproperty bool AbstractAxis::labelsVisible
91 Defines if axis labels are visible.
91 Defines if axis labels are visible.
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QAbstractAxis::visible
95 \property QAbstractAxis::visible
96 The visibility of the axis.
96 The visibility of the axis.
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty bool AbstractAxis::visible
99 \qmlproperty bool AbstractAxis::visible
100 The visibility of the axis.
100 The visibility of the axis.
101 */
101 */
102
102
103 /*!
103 /*!
104 \property QAbstractAxis::gridVisible
104 \property QAbstractAxis::gridVisible
105 The visibility of the grid lines.
105 The visibility of the grid lines.
106 */
106 */
107 /*!
107 /*!
108 \qmlproperty bool AbstractAxis::gridVisible
108 \qmlproperty bool AbstractAxis::gridVisible
109 The visibility of the grid lines.
109 The visibility of the grid lines.
110 */
110 */
111
111
112 /*!
112 /*!
113 \property QAbstractAxis::color
113 \property QAbstractAxis::color
114 The color of the axis and ticks.
114 The color of the axis and ticks.
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty color AbstractAxis::color
117 \qmlproperty color AbstractAxis::color
118 The color of the axis and ticks.
118 The color of the axis and ticks.
119 */
119 */
120
120
121 /*!
121 /*!
122 \property QAbstractAxis::labelsFont
122 \property QAbstractAxis::labelsFont
123 The font of the axis labels.
123 The font of the axis labels.
124 */
124 */
125
125
126 /*!
126 /*!
127 \qmlproperty Font AbstractAxis::labelsFont
127 \qmlproperty Font AbstractAxis::labelsFont
128 The font of the axis labels.
128 The font of the axis labels.
129
129
130 See the \l {Font} {QML Font Element} for detailed documentation.
130 See the \l {Font} {QML Font Element} for detailed documentation.
131 */
131 */
132
132
133 /*!
133 /*!
134 \property QAbstractAxis::labelsColor
134 \property QAbstractAxis::labelsColor
135 The color of the axis labels.
135 The color of the axis labels.
136 */
136 */
137 /*!
137 /*!
138 \qmlproperty color AbstractAxis::labelsColor
138 \qmlproperty color AbstractAxis::labelsColor
139 The color of the axis labels.
139 The color of the axis labels.
140 */
140 */
141
141
142 /*!
142 /*!
143 \property QAbstractAxis::labelsAngle
143 \property QAbstractAxis::labelsAngle
144 The angle of the axis labels in degrees.
144 The angle of the axis labels in degrees.
145 */
145 */
146 /*!
146 /*!
147 \qmlproperty int AbstractAxis::labelsAngle
147 \qmlproperty int AbstractAxis::labelsAngle
148 The angle of the axis labels in degrees.
148 The angle of the axis labels in degrees.
149 */
149 */
150
150
151 /*!
151 /*!
152 \property QAbstractAxis::shadesVisible
152 \property QAbstractAxis::shadesVisible
153 The visibility of the axis shades.
153 The visibility of the axis shades.
154 */
154 */
155 /*!
155 /*!
156 \qmlproperty bool AbstractAxis::shadesVisible
156 \qmlproperty bool AbstractAxis::shadesVisible
157 The visibility of the axis shades.
157 The visibility of the axis shades.
158 */
158 */
159
159
160 /*!
160 /*!
161 \property QAbstractAxis::shadesColor
161 \property QAbstractAxis::shadesColor
162 The fill (brush) color of the axis shades.
162 The fill (brush) color of the axis shades.
163 */
163 */
164 /*!
164 /*!
165 \qmlproperty color AbstractAxis::shadesColor
165 \qmlproperty color AbstractAxis::shadesColor
166 The fill (brush) color of the axis shades.
166 The fill (brush) color of the axis shades.
167 */
167 */
168
168
169 /*!
169 /*!
170 \property QAbstractAxis::shadesBorderColor
170 \property QAbstractAxis::shadesBorderColor
171 The border (pen) color of the axis shades.
171 The border (pen) color of the axis shades.
172 */
172 */
173 /*!
173 /*!
174 \qmlproperty color AbstractAxis::shadesBorderColor
174 \qmlproperty color AbstractAxis::shadesBorderColor
175 The border (pen) color of the axis shades.
175 The border (pen) color of the axis shades.
176 */
176 */
177
177
178 /*!
178 /*!
179 \property QAbstractAxis::titleVisible
179 \property QAbstractAxis::titleVisible
180 The visibility of the axis title. By default the value is true.
180 The visibility of the axis title. By default the value is true.
181 */
181 */
182 /*!
182 /*!
183 \qmlproperty bool AbstractAxis::titleVisible
183 \qmlproperty bool AbstractAxis::titleVisible
184 The visibility of the axis title. By default the value is true.
184 The visibility of the axis title. By default the value is true.
185 */
185 */
186
186
187 /*!
187 /*!
188 \property QAbstractAxis::titleFont
188 \property QAbstractAxis::titleFont
189 The font of the title of the axis.
189 The font of the title of the axis.
190 */
190 */
191 /*!
191 /*!
192 \qmlproperty Font AbstractAxis::title
192 \qmlproperty Font AbstractAxis::title
193 The font of the title of the axis.
193 The font of the title of the axis.
194 */
194 */
195
195
196 /*!
196 /*!
197 \property QAbstractAxis::title
197 \property QAbstractAxis::title
198 The title of the axis. Empty by default.
198 The title of the axis. Empty by default.
199 */
199 */
200 /*!
200 /*!
201 \qmlproperty string AbstractAxis::title
201 \qmlproperty string AbstractAxis::title
202 The title of the axis. Empty string by default.
202 The title of the axis. Empty string by default.
203 */
203 */
204
204
205 /*!
205 /*!
206 \property QAbstractAxis::alignment
206 \property QAbstractAxis::alignment
207 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
207 The alignment of the axis. Either Qt::AlignLeft or Qt::AlignBottom.
208 */
208 */
209 /*!
209 /*!
210 \qmlproperty alignment AbstractAxis::alignment
210 \qmlproperty alignment AbstractAxis::alignment
211 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
211 The alignment of the axis. Either Qt.AlignLeft or Qt.AlignBottom.
212 */
212 */
213
213
214 /*!
214 /*!
215 \fn void QAbstractAxis::visibleChanged(bool visible)
215 \fn void QAbstractAxis::visibleChanged(bool visible)
216 Visibility of the axis has changed to \a visible.
216 Visibility of the axis has changed to \a visible.
217 */
217 */
218 /*!
218 /*!
219 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
219 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
220 Visibility of the axis has changed to \a visible.
220 Visibility of the axis has changed to \a visible.
221 */
221 */
222
222
223 /*!
223 /*!
224 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
224 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
225 Visibility of the axis line has changed to \a visible.
225 Visibility of the axis line has changed to \a visible.
226 */
226 */
227 /*!
227 /*!
228 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
228 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
229 Visibility of the axis line has changed to \a visible.
229 Visibility of the axis line has changed to \a visible.
230 */
230 */
231
231
232 /*!
232 /*!
233 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
233 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
234 Visibility of the labels of the axis has changed to \a visible.
234 Visibility of the labels of the axis has changed to \a visible.
235 */
235 */
236 /*!
236 /*!
237 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
237 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
238 Visibility of the labels of the axis has changed to \a visible.
238 Visibility of the labels of the axis has changed to \a visible.
239 */
239 */
240
240
241 /*!
241 /*!
242 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
242 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
243 Visibility of the grid lines of the axis has changed to \a visible.
243 Visibility of the grid lines of the axis has changed to \a visible.
244 */
244 */
245 /*!
245 /*!
246 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
246 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
247 Visibility of the grid lines of the axis has changed to \a visible.
247 Visibility of the grid lines of the axis has changed to \a visible.
248 */
248 */
249
249
250 /*!
250 /*!
251 \fn void QAbstractAxis::colorChanged(QColor color)
251 \fn void QAbstractAxis::colorChanged(QColor color)
252 Emitted if the \a color of the axis is changed.
252 Emitted if the \a color of the axis is changed.
253 */
253 */
254 /*!
254 /*!
255 \qmlsignal AbstractAxis::onColorChanged(QColor color)
255 \qmlsignal AbstractAxis::onColorChanged(QColor color)
256 Emitted if the \a color of the axis is changed.
256 Emitted if the \a color of the axis is changed.
257 */
257 */
258
258
259 /*!
259 /*!
260 \fn void QAbstractAxis::labelsColorChanged(QColor color)
260 \fn void QAbstractAxis::labelsColorChanged(QColor color)
261 Emitted if the \a color of the axis labels is changed.
261 Emitted if the \a color of the axis labels is changed.
262 */
262 */
263 /*!
263 /*!
264 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
264 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
265 Emitted if the \a color of the axis labels is changed.
265 Emitted if the \a color of the axis labels is changed.
266 */
266 */
267
267
268 /*!
268 /*!
269 \fn void QAbstractAxis::shadesVisibleChanged(bool)
269 \fn void QAbstractAxis::shadesVisibleChanged(bool)
270 Emitted if the visibility of the axis shades is changed to \a visible.
270 Emitted if the visibility of the axis shades is changed to \a visible.
271 */
271 */
272 /*!
272 /*!
273 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
273 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
274 Emitted if the visibility of the axis shades is changed to \a visible.
274 Emitted if the visibility of the axis shades is changed to \a visible.
275 */
275 */
276
276
277 /*!
277 /*!
278 \fn void QAbstractAxis::shadesColorChanged(QColor color)
278 \fn void QAbstractAxis::shadesColorChanged(QColor color)
279 Emitted if the \a color of the axis shades is changed.
279 Emitted if the \a color of the axis shades is changed.
280 */
280 */
281 /*!
281 /*!
282 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
282 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
283 Emitted if the \a color of the axis shades is changed.
283 Emitted if the \a color of the axis shades is changed.
284 */
284 */
285
285
286 /*!
286 /*!
287 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
287 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
288 Emitted if the border \a color of the axis shades is changed.
288 Emitted if the border \a color of the axis shades is changed.
289 */
289 */
290 /*!
290 /*!
291 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
291 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
292 Emitted if the border \a color of the axis shades is changed.
292 Emitted if the border \a color of the axis shades is changed.
293 */
293 */
294
294
295 /*!
295 /*!
296 \internal
296 \internal
297 Constructs new axis object which is a child of \a parent. Ownership is taken by
297 Constructs new axis object which is a child of \a parent. Ownership is taken by
298 QChart when axis added.
298 QChart when axis added.
299 */
299 */
300
300
301 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
301 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
302 : QObject(parent),
302 : QObject(parent),
303 d_ptr(&d)
303 d_ptr(&d)
304 {
304 {
305 }
305 }
306
306
307 /*!
307 /*!
308 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
308 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
309 */
309 */
310
310
311 QAbstractAxis::~QAbstractAxis()
311 QAbstractAxis::~QAbstractAxis()
312 {
312 {
313 if (d_ptr->m_chart)
313 if (d_ptr->m_chart)
314 qFatal("Still binded axis detected !");
314 qFatal("Still binded axis detected !");
315 }
315 }
316
316
317 /*!
317 /*!
318 Sets \a pen used to draw axis line and ticks.
318 Sets \a pen used to draw axis line and ticks.
319 */
319 */
320 void QAbstractAxis::setLinePen(const QPen &pen)
320 void QAbstractAxis::setLinePen(const QPen &pen)
321 {
321 {
322 if (d_ptr->m_axisPen != pen) {
322 if (d_ptr->m_axisPen != pen) {
323 d_ptr->m_axisPen = pen;
323 d_ptr->m_axisPen = pen;
324 emit linePenChanged(pen);
324 emit linePenChanged(pen);
325 }
325 }
326 }
326 }
327
327
328 /*!
328 /*!
329 Returns pen used to draw axis and ticks.
329 Returns pen used to draw axis and ticks.
330 */
330 */
331 QPen QAbstractAxis::linePen() const
331 QPen QAbstractAxis::linePen() const
332 {
332 {
333 return d_ptr->m_axisPen;
333 return d_ptr->m_axisPen;
334 }
334 }
335
335
336 //TODO: remove me
336 //TODO: remove me
337 void QAbstractAxis::setLinePenColor(QColor color)
337 void QAbstractAxis::setLinePenColor(QColor color)
338 {
338 {
339 QPen p = d_ptr->m_axisPen;
339 QPen p = d_ptr->m_axisPen;
340 if (p.color() != color) {
340 if (p.color() != color) {
341 p.setColor(color);
341 p.setColor(color);
342 setLinePen(p);
342 setLinePen(p);
343 emit colorChanged(color);
343 emit colorChanged(color);
344 }
344 }
345 }
345 }
346
346
347 QColor QAbstractAxis::linePenColor() const
347 QColor QAbstractAxis::linePenColor() const
348 {
348 {
349 return d_ptr->m_axisPen.color();
349 return d_ptr->m_axisPen.color();
350 }
350 }
351
351
352 /*!
352 /*!
353 Sets if axis and ticks are \a visible.
353 Sets if axis and ticks are \a visible.
354 */
354 */
355 void QAbstractAxis::setLineVisible(bool visible)
355 void QAbstractAxis::setLineVisible(bool visible)
356 {
356 {
357 if (d_ptr->m_arrowVisible != visible) {
357 if (d_ptr->m_arrowVisible != visible) {
358 d_ptr->m_arrowVisible = visible;
358 d_ptr->m_arrowVisible = visible;
359 emit lineVisibleChanged(visible);
359 emit lineVisibleChanged(visible);
360 }
360 }
361 }
361 }
362
362
363 bool QAbstractAxis::isLineVisible() const
363 bool QAbstractAxis::isLineVisible() const
364 {
364 {
365 return d_ptr->m_arrowVisible;
365 return d_ptr->m_arrowVisible;
366 }
366 }
367
367
368 void QAbstractAxis::setGridLineVisible(bool visible)
368 void QAbstractAxis::setGridLineVisible(bool visible)
369 {
369 {
370 if (d_ptr->m_gridLineVisible != visible) {
370 if (d_ptr->m_gridLineVisible != visible) {
371 d_ptr->m_gridLineVisible = visible;
371 d_ptr->m_gridLineVisible = visible;
372 emit gridVisibleChanged(visible);
372 emit gridVisibleChanged(visible);
373 }
373 }
374 }
374 }
375
375
376 bool QAbstractAxis::isGridLineVisible() const
376 bool QAbstractAxis::isGridLineVisible() const
377 {
377 {
378 return d_ptr->m_gridLineVisible;
378 return d_ptr->m_gridLineVisible;
379 }
379 }
380
380
381 /*!
381 /*!
382 Sets \a pen used to draw grid line.
382 Sets \a pen used to draw grid line.
383 */
383 */
384 void QAbstractAxis::setGridLinePen(const QPen &pen)
384 void QAbstractAxis::setGridLinePen(const QPen &pen)
385 {
385 {
386 if (d_ptr->m_gridLinePen != pen) {
386 if (d_ptr->m_gridLinePen != pen) {
387 d_ptr->m_gridLinePen = pen;
387 d_ptr->m_gridLinePen = pen;
388 emit gridLinePenChanged(pen);
388 emit gridLinePenChanged(pen);
389 }
389 }
390 }
390 }
391
391
392 /*!
392 /*!
393 Returns pen used to draw grid.
393 Returns pen used to draw grid.
394 */
394 */
395 QPen QAbstractAxis::gridLinePen() const
395 QPen QAbstractAxis::gridLinePen() const
396 {
396 {
397 return d_ptr->m_gridLinePen;
397 return d_ptr->m_gridLinePen;
398 }
398 }
399
399
400 void QAbstractAxis::setLabelsVisible(bool visible)
400 void QAbstractAxis::setLabelsVisible(bool visible)
401 {
401 {
402 if (d_ptr->m_labelsVisible != visible) {
402 if (d_ptr->m_labelsVisible != visible) {
403 d_ptr->m_labelsVisible = visible;
403 d_ptr->m_labelsVisible = visible;
404 emit labelsVisibleChanged(visible);
404 emit labelsVisibleChanged(visible);
405 }
405 }
406 }
406 }
407
407
408 bool QAbstractAxis::labelsVisible() const
408 bool QAbstractAxis::labelsVisible() const
409 {
409 {
410 return d_ptr->m_labelsVisible;
410 return d_ptr->m_labelsVisible;
411 }
411 }
412
412
413 /*!
413 /*!
414 Sets \a pen used to draw labels.
414 Sets \a pen used to draw labels.
415 */
415 */
416 void QAbstractAxis::setLabelsPen(const QPen &pen)
416 void QAbstractAxis::setLabelsPen(const QPen &pen)
417 {
417 {
418 if (d_ptr->m_labelsPen != pen) {
418 if (d_ptr->m_labelsPen != pen) {
419 d_ptr->m_labelsPen = pen;
419 d_ptr->m_labelsPen = pen;
420 emit labelsPenChanged(pen);
420 emit labelsPenChanged(pen);
421 }
421 }
422 }
422 }
423
423
424 /*!
424 /*!
425 Returns the pen used to labels.
425 Returns the pen used to labels.
426 */
426 */
427 QPen QAbstractAxis::labelsPen() const
427 QPen QAbstractAxis::labelsPen() const
428 {
428 {
429 return d_ptr->m_labelsPen;
429 return d_ptr->m_labelsPen;
430 }
430 }
431
431
432 /*!
432 /*!
433 Sets \a brush used to draw labels.
433 Sets \a brush used to draw labels.
434 */
434 */
435 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
435 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
436 {
436 {
437 if (d_ptr->m_labelsBrush != brush) {
437 if (d_ptr->m_labelsBrush != brush) {
438 d_ptr->m_labelsBrush = brush;
438 d_ptr->m_labelsBrush = brush;
439 emit labelsBrushChanged(brush);
439 emit labelsBrushChanged(brush);
440 }
440 }
441 }
441 }
442
442
443 /*!
443 /*!
444 Returns brush used to draw labels.
444 Returns brush used to draw labels.
445 */
445 */
446 QBrush QAbstractAxis::labelsBrush() const
446 QBrush QAbstractAxis::labelsBrush() const
447 {
447 {
448 return d_ptr->m_labelsBrush;
448 return d_ptr->m_labelsBrush;
449 }
449 }
450
450
451 /*!
451 /*!
452 Sets \a font used to draw labels.
452 Sets \a font used to draw labels.
453 */
453 */
454 void QAbstractAxis::setLabelsFont(const QFont &font)
454 void QAbstractAxis::setLabelsFont(const QFont &font)
455 {
455 {
456 if (d_ptr->m_labelsFont != font) {
456 if (d_ptr->m_labelsFont != font) {
457 d_ptr->m_labelsFont = font;
457 d_ptr->m_labelsFont = font;
458 emit labelsFontChanged(font);
458 emit labelsFontChanged(font);
459 }
459 }
460 }
460 }
461
461
462 /*!
462 /*!
463 Returns font used to draw labels.
463 Returns font used to draw labels.
464 */
464 */
465 QFont QAbstractAxis::labelsFont() const
465 QFont QAbstractAxis::labelsFont() const
466 {
466 {
467 return d_ptr->m_labelsFont;
467 return d_ptr->m_labelsFont;
468 }
468 }
469
469
470 void QAbstractAxis::setLabelsAngle(int angle)
470 void QAbstractAxis::setLabelsAngle(int angle)
471 {
471 {
472 if (d_ptr->m_labelsAngle != angle) {
472 if (d_ptr->m_labelsAngle != angle) {
473 d_ptr->m_labelsAngle = angle;
473 d_ptr->m_labelsAngle = angle;
474 emit labelsAngleChanged(angle);
474 emit labelsAngleChanged(angle);
475 }
475 }
476 }
476 }
477
477
478 int QAbstractAxis::labelsAngle() const
478 int QAbstractAxis::labelsAngle() const
479 {
479 {
480 return d_ptr->m_labelsAngle;
480 return d_ptr->m_labelsAngle;
481 }
481 }
482 //TODO: remove me
482 //TODO: remove me
483 void QAbstractAxis::setLabelsColor(QColor color)
483 void QAbstractAxis::setLabelsColor(QColor color)
484 {
484 {
485 QBrush b = d_ptr->m_labelsBrush;
485 QBrush b = d_ptr->m_labelsBrush;
486 if (b.color() != color) {
486 if (b.color() != color) {
487 b.setColor(color);
487 b.setColor(color);
488 setLabelsBrush(b);
488 setLabelsBrush(b);
489 emit labelsColorChanged(color);
489 emit labelsColorChanged(color);
490 }
490 }
491 }
491 }
492
492
493 QColor QAbstractAxis::labelsColor() const
493 QColor QAbstractAxis::labelsColor() const
494 {
494 {
495 return d_ptr->m_labelsBrush.color();
495 return d_ptr->m_labelsBrush.color();
496 }
496 }
497
497
498 void QAbstractAxis::setTitleVisible(bool visible)
498 void QAbstractAxis::setTitleVisible(bool visible)
499 {
499 {
500 if (d_ptr->m_titleVisible != visible) {
500 if (d_ptr->m_titleVisible != visible) {
501 d_ptr->m_titleVisible = visible;
501 d_ptr->m_titleVisible = visible;
502 emit labelsVisibleChanged(visible);
502 emit titleVisibleChanged(visible);
503 }
503 }
504 }
504 }
505
505
506 bool QAbstractAxis::titleVisible() const
506 bool QAbstractAxis::isTitleVisible() const
507 {
507 {
508 return d_ptr->m_titleVisible;
508 return d_ptr->m_titleVisible;
509 }
509 }
510
510
511 /*!
511 /*!
512 Sets \a pen used to draw title.
512 Sets \a pen used to draw title.
513 */
513 */
514 void QAbstractAxis::setTitlePen(const QPen &pen)
514 void QAbstractAxis::setTitlePen(const QPen &pen)
515 {
515 {
516 if (d_ptr->m_titlePen != pen) {
516 if (d_ptr->m_titlePen != pen) {
517 d_ptr->m_titlePen = pen;
517 d_ptr->m_titlePen = pen;
518 emit titlePenChanged(pen);
518 emit titlePenChanged(pen);
519 }
519 }
520 }
520 }
521
521
522 /*!
522 /*!
523 Returns the pen used to title.
523 Returns the pen used to title.
524 */
524 */
525 QPen QAbstractAxis::titlePen() const
525 QPen QAbstractAxis::titlePen() const
526 {
526 {
527 return d_ptr->m_titlePen;
527 return d_ptr->m_titlePen;
528 }
528 }
529
529
530 /*!
530 /*!
531 Sets \a brush used to draw title.
531 Sets \a brush used to draw title.
532 */
532 */
533 void QAbstractAxis::setTitleBrush(const QBrush &brush)
533 void QAbstractAxis::setTitleBrush(const QBrush &brush)
534 {
534 {
535 if (d_ptr->m_titleBrush != brush) {
535 if (d_ptr->m_titleBrush != brush) {
536 d_ptr->m_titleBrush = brush;
536 d_ptr->m_titleBrush = brush;
537 emit titleBrushChanged(brush);
537 emit titleBrushChanged(brush);
538 }
538 }
539 }
539 }
540
540
541 /*!
541 /*!
542 Returns brush used to draw title.
542 Returns brush used to draw title.
543 */
543 */
544 QBrush QAbstractAxis::titleBrush() const
544 QBrush QAbstractAxis::titleBrush() const
545 {
545 {
546 return d_ptr->m_titleBrush;
546 return d_ptr->m_titleBrush;
547 }
547 }
548
548
549 /*!
549 /*!
550 Sets \a font used to draw title.
550 Sets \a font used to draw title.
551 */
551 */
552 void QAbstractAxis::setTitleFont(const QFont &font)
552 void QAbstractAxis::setTitleFont(const QFont &font)
553 {
553 {
554 if (d_ptr->m_titleFont != font) {
554 if (d_ptr->m_titleFont != font) {
555 d_ptr->m_titleFont = font;
555 d_ptr->m_titleFont = font;
556 emit titleFontChanged(font);
556 emit titleFontChanged(font);
557 }
557 }
558 }
558 }
559
559
560 /*!
560 /*!
561 Returns font used to draw title.
561 Returns font used to draw title.
562 */
562 */
563 QFont QAbstractAxis::titleFont() const
563 QFont QAbstractAxis::titleFont() const
564 {
564 {
565 return d_ptr->m_titleFont;
565 return d_ptr->m_titleFont;
566 }
566 }
567
567
568 void QAbstractAxis::setTitleText(const QString &title)
568 void QAbstractAxis::setTitleText(const QString &title)
569 {
569 {
570 if (d_ptr->m_title != title) {
570 if (d_ptr->m_title != title) {
571 d_ptr->m_title = title;
571 d_ptr->m_title = title;
572 emit titleTextChanged(title);
572 emit titleTextChanged(title);
573 }
573 }
574 }
574 }
575
575
576 QString QAbstractAxis::titleText() const
576 QString QAbstractAxis::titleText() const
577 {
577 {
578 return d_ptr->m_title;
578 return d_ptr->m_title;
579 }
579 }
580
580
581
581
582 void QAbstractAxis::setShadesVisible(bool visible)
582 void QAbstractAxis::setShadesVisible(bool visible)
583 {
583 {
584 if (d_ptr->m_shadesVisible != visible) {
584 if (d_ptr->m_shadesVisible != visible) {
585 d_ptr->m_shadesVisible = visible;
585 d_ptr->m_shadesVisible = visible;
586 emit shadesVisibleChanged(visible);
586 emit shadesVisibleChanged(visible);
587 }
587 }
588 }
588 }
589
589
590 bool QAbstractAxis::shadesVisible() const
590 bool QAbstractAxis::shadesVisible() const
591 {
591 {
592 return d_ptr->m_shadesVisible;
592 return d_ptr->m_shadesVisible;
593 }
593 }
594
594
595 /*!
595 /*!
596 Sets \a pen used to draw shades.
596 Sets \a pen used to draw shades.
597 */
597 */
598 void QAbstractAxis::setShadesPen(const QPen &pen)
598 void QAbstractAxis::setShadesPen(const QPen &pen)
599 {
599 {
600 if (d_ptr->m_shadesPen != pen) {
600 if (d_ptr->m_shadesPen != pen) {
601 d_ptr->m_shadesPen = pen;
601 d_ptr->m_shadesPen = pen;
602 emit shadesPenChanged(pen);
602 emit shadesPenChanged(pen);
603 }
603 }
604 }
604 }
605
605
606 /*!
606 /*!
607 Returns pen used to draw shades.
607 Returns pen used to draw shades.
608 */
608 */
609 QPen QAbstractAxis::shadesPen() const
609 QPen QAbstractAxis::shadesPen() const
610 {
610 {
611 return d_ptr->m_shadesPen;
611 return d_ptr->m_shadesPen;
612 }
612 }
613
613
614 /*!
614 /*!
615 Sets \a brush used to draw shades.
615 Sets \a brush used to draw shades.
616 */
616 */
617 void QAbstractAxis::setShadesBrush(const QBrush &brush)
617 void QAbstractAxis::setShadesBrush(const QBrush &brush)
618 {
618 {
619 if (d_ptr->m_shadesBrush != brush) {
619 if (d_ptr->m_shadesBrush != brush) {
620 d_ptr->m_shadesBrush = brush;
620 d_ptr->m_shadesBrush = brush;
621 emit shadesBrushChanged(brush);
621 emit shadesBrushChanged(brush);
622 }
622 }
623 }
623 }
624
624
625 /*!
625 /*!
626 Returns brush used to draw shades.
626 Returns brush used to draw shades.
627 */
627 */
628 QBrush QAbstractAxis::shadesBrush() const
628 QBrush QAbstractAxis::shadesBrush() const
629 {
629 {
630 return d_ptr->m_shadesBrush;
630 return d_ptr->m_shadesBrush;
631 }
631 }
632
632
633 void QAbstractAxis::setShadesColor(QColor color)
633 void QAbstractAxis::setShadesColor(QColor color)
634 {
634 {
635 QBrush b = d_ptr->m_shadesBrush;
635 QBrush b = d_ptr->m_shadesBrush;
636 if (b.color() != color) {
636 if (b.color() != color) {
637 b.setColor(color);
637 b.setColor(color);
638 setShadesBrush(b);
638 setShadesBrush(b);
639 emit shadesColorChanged(color);
639 emit shadesColorChanged(color);
640 }
640 }
641 }
641 }
642
642
643 QColor QAbstractAxis::shadesColor() const
643 QColor QAbstractAxis::shadesColor() const
644 {
644 {
645 return d_ptr->m_shadesBrush.color();
645 return d_ptr->m_shadesBrush.color();
646 }
646 }
647
647
648 void QAbstractAxis::setShadesBorderColor(QColor color)
648 void QAbstractAxis::setShadesBorderColor(QColor color)
649 {
649 {
650 QPen p = d_ptr->m_shadesPen;
650 QPen p = d_ptr->m_shadesPen;
651 if (p.color() != color) {
651 if (p.color() != color) {
652 p.setColor(color);
652 p.setColor(color);
653 setShadesPen(p);
653 setShadesPen(p);
654 emit shadesColorChanged(color);
654 emit shadesColorChanged(color);
655 }
655 }
656 }
656 }
657
657
658 QColor QAbstractAxis::shadesBorderColor() const
658 QColor QAbstractAxis::shadesBorderColor() const
659 {
659 {
660 return d_ptr->m_shadesPen.color();
660 return d_ptr->m_shadesPen.color();
661 }
661 }
662
662
663
663
664 bool QAbstractAxis::isVisible() const
664 bool QAbstractAxis::isVisible() const
665 {
665 {
666 return d_ptr->m_visible;
666 return d_ptr->m_visible;
667 }
667 }
668
668
669 /*!
669 /*!
670 Sets axis, shades, labels and grid lines to be visible.
670 Sets axis, shades, labels and grid lines to be visible.
671 */
671 */
672 void QAbstractAxis::setVisible(bool visible)
672 void QAbstractAxis::setVisible(bool visible)
673 {
673 {
674 if (d_ptr->m_visible != visible) {
674 if (d_ptr->m_visible != visible) {
675 d_ptr->m_visible = visible;
675 d_ptr->m_visible = visible;
676 emit visibleChanged(visible);
676 emit visibleChanged(visible);
677 }
677 }
678 }
678 }
679
679
680
680
681 /*!
681 /*!
682 Sets axis, shades, labels and grid lines to be visible.
682 Sets axis, shades, labels and grid lines to be visible.
683 */
683 */
684 void QAbstractAxis::show()
684 void QAbstractAxis::show()
685 {
685 {
686 setVisible(true);
686 setVisible(true);
687 }
687 }
688
688
689 /*!
689 /*!
690 Sets axis, shades, labels and grid lines to not be visible.
690 Sets axis, shades, labels and grid lines to not be visible.
691 */
691 */
692 void QAbstractAxis::hide()
692 void QAbstractAxis::hide()
693 {
693 {
694 setVisible(false);
694 setVisible(false);
695 }
695 }
696
696
697 /*!
697 /*!
698 Sets the minimum value shown on the axis.
698 Sets the minimum value shown on the axis.
699 Depending on the actual axis type the \a min parameter is converted to appropriate type.
699 Depending on the actual axis type the \a min parameter is converted to appropriate type.
700 If the conversion is impossible then the function call does nothing
700 If the conversion is impossible then the function call does nothing
701 */
701 */
702 void QAbstractAxis::setMin(const QVariant &min)
702 void QAbstractAxis::setMin(const QVariant &min)
703 {
703 {
704 d_ptr->setMin(min);
704 d_ptr->setMin(min);
705 }
705 }
706
706
707 /*!
707 /*!
708 Sets the maximum value shown on the axis.
708 Sets the maximum value shown on the axis.
709 Depending on the actual axis type the \a max parameter is converted to appropriate type.
709 Depending on the actual axis type the \a max parameter is converted to appropriate type.
710 If the conversion is impossible then the function call does nothing
710 If the conversion is impossible then the function call does nothing
711 */
711 */
712 void QAbstractAxis::setMax(const QVariant &max)
712 void QAbstractAxis::setMax(const QVariant &max)
713 {
713 {
714 d_ptr->setMax(max);
714 d_ptr->setMax(max);
715 }
715 }
716
716
717 /*!
717 /*!
718 Sets the range shown on the axis.
718 Sets the range shown on the axis.
719 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
719 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
720 If the conversion is impossible then the function call does nothing.
720 If the conversion is impossible then the function call does nothing.
721 */
721 */
722 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
722 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
723 {
723 {
724 d_ptr->setRange(min, max);
724 d_ptr->setRange(min, max);
725 }
725 }
726
726
727
727
728 /*!
728 /*!
729 Returns the orientation in which the axis is being used (Vertical or Horizontal)
729 Returns the orientation in which the axis is being used (Vertical or Horizontal)
730 */
730 */
731 // NOTE: should have const but it breaks BC:
731 // NOTE: should have const but it breaks BC:
732 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
732 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
733 Qt::Orientation QAbstractAxis::orientation()
733 Qt::Orientation QAbstractAxis::orientation()
734 {
734 {
735 return d_ptr->orientation();
735 return d_ptr->orientation();
736 }
736 }
737
737
738 Qt::Alignment QAbstractAxis::alignment() const
738 Qt::Alignment QAbstractAxis::alignment() const
739 {
739 {
740 return d_ptr->alignment();
740 return d_ptr->alignment();
741 }
741 }
742
742
743 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
743 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
744
744
745 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
745 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
746 : q_ptr(q),
746 : q_ptr(q),
747 m_chart(0),
747 m_chart(0),
748 m_orientation(Qt::Orientation(0)),
748 m_orientation(Qt::Orientation(0)),
749 m_alignment(0),
749 m_alignment(0),
750 m_visible(true),
750 m_visible(true),
751 m_arrowVisible(true),
751 m_arrowVisible(true),
752 m_gridLineVisible(true),
752 m_gridLineVisible(true),
753 m_labelsVisible(true),
753 m_labelsVisible(true),
754 m_labelsAngle(0),
754 m_labelsAngle(0),
755 m_shadesVisible(false),
755 m_shadesVisible(false),
756 m_shadesBrush(Qt::SolidPattern),
756 m_shadesBrush(Qt::SolidPattern),
757 m_shadesOpacity(1.0),
757 m_shadesOpacity(1.0),
758 m_dirty(false)
758 m_dirty(false)
759 {
759 {
760
760
761 }
761 }
762
762
763 QAbstractAxisPrivate::~QAbstractAxisPrivate()
763 QAbstractAxisPrivate::~QAbstractAxisPrivate()
764 {
764 {
765 }
765 }
766
766
767 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
767 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
768 {
768 {
769 switch(alignment) {
769 switch(alignment) {
770 case Qt::AlignTop:
770 case Qt::AlignTop:
771 case Qt::AlignBottom:
771 case Qt::AlignBottom:
772 m_orientation = Qt::Horizontal;
772 m_orientation = Qt::Horizontal;
773 break;
773 break;
774 case Qt::AlignLeft:
774 case Qt::AlignLeft:
775 case Qt::AlignRight:
775 case Qt::AlignRight:
776 m_orientation = Qt::Vertical;
776 m_orientation = Qt::Vertical;
777 break;
777 break;
778 default:
778 default:
779 qWarning()<<"No alignment specified !";
779 qWarning()<<"No alignment specified !";
780 break;
780 break;
781 };
781 };
782 m_alignment=alignment;
782 m_alignment=alignment;
783 }
783 }
784
784
785 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
785 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
786 {
786 {
787 QPen pen;
787 QPen pen;
788 QBrush brush;
788 QBrush brush;
789 QFont font;
789 QFont font;
790
790
791 bool axisX = m_orientation == Qt::Horizontal;
791 bool axisX = m_orientation == Qt::Horizontal;
792
792
793 if (m_arrowVisible) {
793 if (m_arrowVisible) {
794
794
795 if (forced || brush == m_labelsBrush){
795 if (forced || brush == m_labelsBrush){
796 q_ptr->setLabelsBrush(theme->labelBrush());
796 q_ptr->setLabelsBrush(theme->labelBrush());
797 }
797 }
798 //TODO: introduce axis brush
798 //TODO: introduce axis brush
799 if (forced || brush == m_titleBrush){
799 if (forced || brush == m_titleBrush){
800 q_ptr->setTitleBrush(theme->labelBrush());
800 q_ptr->setTitleBrush(theme->labelBrush());
801 }
801 }
802 if (forced || pen == m_labelsPen){
802 if (forced || pen == m_labelsPen){
803 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
803 q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons
804 }
804 }
805 if (forced || pen == m_titlePen){
805 if (forced || pen == m_titlePen){
806 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
806 q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons
807 }
807 }
808 if (forced || m_shadesVisible) {
808 if (forced || m_shadesVisible) {
809
809
810 if (forced || brush == m_shadesBrush){
810 if (forced || brush == m_shadesBrush){
811 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
811 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
812 }
812 }
813 if (forced || pen == m_shadesPen){
813 if (forced || pen == m_shadesPen){
814 q_ptr->setShadesPen(theme->backgroundShadesPen());
814 q_ptr->setShadesPen(theme->backgroundShadesPen());
815 }
815 }
816 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
816 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
817 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
817 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
818 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
818 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
819 q_ptr->setShadesVisible(true);
819 q_ptr->setShadesVisible(true);
820 }
820 }
821 }
821 }
822
822
823 if (forced || pen == m_axisPen) {
823 if (forced || pen == m_axisPen) {
824 q_ptr->setLinePen(theme->axisLinePen());
824 q_ptr->setLinePen(theme->axisLinePen());
825 }
825 }
826
826
827 if (forced || pen == m_gridLinePen) {
827 if (forced || pen == m_gridLinePen) {
828 q_ptr->setGridLinePen(theme->girdLinePen());
828 q_ptr->setGridLinePen(theme->girdLinePen());
829 }
829 }
830
830
831 if (forced || font == m_labelsFont){
831 if (forced || font == m_labelsFont){
832 q_ptr->setLabelsFont(theme->labelFont());
832 q_ptr->setLabelsFont(theme->labelFont());
833 }
833 }
834 //TODO: discuss with Tero
834 //TODO: discuss with Tero
835 if (forced || font == m_titleFont){
835 if (forced || font == m_titleFont){
836 QFont font(m_labelsFont);
836 QFont font(m_labelsFont);
837 font.setBold(true);
837 font.setBold(true);
838 q_ptr->setTitleFont(font);
838 q_ptr->setTitleFont(font);
839 }
839 }
840 }
840 }
841 }
841 }
842
842
843 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
843 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
844 {
844 {
845 setRange(min,max);
845 setRange(min,max);
846 }
846 }
847
847
848 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
848 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
849 {
849 {
850 Q_UNUSED(parent);
850 Q_UNUSED(parent);
851 }
851 }
852
852
853 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
853 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
854 {
854 {
855 ChartAxis* axis = m_item.data();
855 ChartAxis* axis = m_item.data();
856 Q_ASSERT(axis);
856 Q_ASSERT(axis);
857 if(options.testFlag(QChart::GridAxisAnimations)) {
857 if(options.testFlag(QChart::GridAxisAnimations)) {
858 axis->setAnimation(new AxisAnimation(axis));
858 axis->setAnimation(new AxisAnimation(axis));
859 }else{
859 }else{
860 axis->setAnimation(0);
860 axis->setAnimation(0);
861 }
861 }
862 }
862 }
863
863
864
864
865
865
866 #include "moc_qabstractaxis.cpp"
866 #include "moc_qabstractaxis.cpp"
867 #include "moc_qabstractaxis_p.cpp"
867 #include "moc_qabstractaxis_p.cpp"
868
868
869 QTCOMMERCIALCHART_END_NAMESPACE
869 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,197 +1,197
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 //visibility
36 //visibility
37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
38 //arrow
38 //arrow
39 Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged)
39 Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged)
40 Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged)
40 Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged)
41 //TODO: make wrapping of color for qml
41 //TODO: make wrapping of color for qml
42 Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged)
42 Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged)
43 //labels
43 //labels
44 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
44 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
45 Q_PROPERTY(QPen lablesPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged)
45 Q_PROPERTY(QPen lablesPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged)
46 Q_PROPERTY(QBrush lablesBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged)
46 Q_PROPERTY(QBrush lablesBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged)
47 //TODO: fix labels angles to work with layout
47 //TODO: fix labels angles to work with layout
48 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged)
48 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged)
49 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged)
49 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged)
50 //TODO: make wrapping of color for qml
50 //TODO: make wrapping of color for qml
51 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
51 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
52 //grid
52 //grid
53 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
53 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
54 Q_PROPERTY(QPen girdLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged)
54 Q_PROPERTY(QPen girdLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged)
55 //shades
55 //shades
56 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
56 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
57 //TODO: make wrapping of color for qml
57 //TODO: make wrapping of color for qml
58 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
58 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
59 //TODO: make wrapping of border for qml
59 //TODO: make wrapping of border for qml
60 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
60 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
61 Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged)
61 Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged)
62 Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged)
62 Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged)
63 //title
63 //title
64 Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged)
64 Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged)
65 Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged)
65 Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged)
66 Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged)
66 Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged)
67 Q_PROPERTY(bool titleVisible READ titleVisible WRITE setTitleVisible)
67 Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged)
68 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont)
68 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged)
69 //orientation
69 //orientation
70 Q_PROPERTY(Qt::Orientation orinetation READ orientation)
70 Q_PROPERTY(Qt::Orientation orinetation READ orientation)
71 //aligment
71 //aligment
72 Q_PROPERTY(Qt::Alignment alignment READ alignment)
72 Q_PROPERTY(Qt::Alignment alignment READ alignment)
73
73
74 public:
74 public:
75
75
76 enum AxisType {
76 enum AxisType {
77 AxisTypeNoAxis = 0x0,
77 AxisTypeNoAxis = 0x0,
78 AxisTypeValue = 0x1,
78 AxisTypeValue = 0x1,
79 AxisTypeBarCategory = 0x2,
79 AxisTypeBarCategory = 0x2,
80 AxisTypeCategory = 0x3,
80 AxisTypeCategory = 0x3,
81 AxisTypeDateTime = 0x4,
81 AxisTypeDateTime = 0x4,
82 AxisTypeLogValue = 0x5
82 AxisTypeLogValue = 0x5
83 };
83 };
84
84
85 Q_DECLARE_FLAGS(AxisTypes, AxisType)
85 Q_DECLARE_FLAGS(AxisTypes, AxisType)
86
86
87 protected:
87 protected:
88 explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0);
88 explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0);
89
89
90 public:
90 public:
91 ~QAbstractAxis();
91 ~QAbstractAxis();
92
92
93 virtual AxisType type() const = 0;
93 virtual AxisType type() const = 0;
94
94
95 //visibility handling
95 //visibility handling
96 bool isVisible() const;
96 bool isVisible() const;
97 void setVisible(bool visible = true);
97 void setVisible(bool visible = true);
98 void show();
98 void show();
99 void hide();
99 void hide();
100
100
101 //arrow handling
101 //arrow handling
102 bool isLineVisible() const;
102 bool isLineVisible() const;
103 void setLineVisible(bool visible = true);
103 void setLineVisible(bool visible = true);
104 void setLinePen(const QPen &pen);
104 void setLinePen(const QPen &pen);
105 QPen linePen() const;
105 QPen linePen() const;
106 void setLinePenColor(QColor color);
106 void setLinePenColor(QColor color);
107 QColor linePenColor() const;
107 QColor linePenColor() const;
108
108
109 //grid handling
109 //grid handling
110 bool isGridLineVisible() const;
110 bool isGridLineVisible() const;
111 void setGridLineVisible(bool visible = true);
111 void setGridLineVisible(bool visible = true);
112 void setGridLinePen(const QPen &pen);
112 void setGridLinePen(const QPen &pen);
113 QPen gridLinePen() const;
113 QPen gridLinePen() const;
114
114
115 //labels handling
115 //labels handling
116 bool labelsVisible() const;
116 bool labelsVisible() const;
117 void setLabelsVisible(bool visible = true);
117 void setLabelsVisible(bool visible = true);
118 void setLabelsPen(const QPen &pen);
118 void setLabelsPen(const QPen &pen);
119 QPen labelsPen() const;
119 QPen labelsPen() const;
120 void setLabelsBrush(const QBrush &brush);
120 void setLabelsBrush(const QBrush &brush);
121 QBrush labelsBrush() const;
121 QBrush labelsBrush() const;
122 void setLabelsFont(const QFont &font);
122 void setLabelsFont(const QFont &font);
123 QFont labelsFont() const;
123 QFont labelsFont() const;
124 void setLabelsAngle(int angle);
124 void setLabelsAngle(int angle);
125 int labelsAngle() const;
125 int labelsAngle() const;
126 void setLabelsColor(QColor color);
126 void setLabelsColor(QColor color);
127 QColor labelsColor() const;
127 QColor labelsColor() const;
128
128
129 //title handling
129 //title handling
130 bool titleVisible() const;
130 bool isTitleVisible() const;
131 void setTitleVisible(bool visible = true);
131 void setTitleVisible(bool visible = true);
132 void setTitlePen(const QPen &pen);
132 void setTitlePen(const QPen &pen);
133 QPen titlePen() const;
133 QPen titlePen() const;
134 void setTitleBrush(const QBrush &brush);
134 void setTitleBrush(const QBrush &brush);
135 QBrush titleBrush() const;
135 QBrush titleBrush() const;
136 void setTitleFont(const QFont &font);
136 void setTitleFont(const QFont &font);
137 QFont titleFont() const;
137 QFont titleFont() const;
138 void setTitleText(const QString &title);
138 void setTitleText(const QString &title);
139 QString titleText() const;
139 QString titleText() const;
140
140
141 //shades handling
141 //shades handling
142 bool shadesVisible() const;
142 bool shadesVisible() const;
143 void setShadesVisible(bool visible = true);
143 void setShadesVisible(bool visible = true);
144 void setShadesPen(const QPen &pen);
144 void setShadesPen(const QPen &pen);
145 QPen shadesPen() const;
145 QPen shadesPen() const;
146 void setShadesBrush(const QBrush &brush);
146 void setShadesBrush(const QBrush &brush);
147 QBrush shadesBrush() const;
147 QBrush shadesBrush() const;
148 void setShadesColor(QColor color);
148 void setShadesColor(QColor color);
149 QColor shadesColor() const;
149 QColor shadesColor() const;
150 void setShadesBorderColor(QColor color);
150 void setShadesBorderColor(QColor color);
151 QColor shadesBorderColor() const;
151 QColor shadesBorderColor() const;
152
152
153 Qt::Orientation orientation(); //TODO: missing const <- BC
153 Qt::Orientation orientation(); //TODO: missing const <- BC
154 Qt::Alignment alignment() const;
154 Qt::Alignment alignment() const;
155
155
156 //range handling
156 //range handling
157 void setMin(const QVariant &min);
157 void setMin(const QVariant &min);
158 void setMax(const QVariant &max);
158 void setMax(const QVariant &max);
159 void setRange(const QVariant &min, const QVariant &max);
159 void setRange(const QVariant &min, const QVariant &max);
160
160
161 Q_SIGNALS:
161 Q_SIGNALS:
162 void visibleChanged(bool visible);
162 void visibleChanged(bool visible);
163 void linePenChanged(const QPen& pen);
163 void linePenChanged(const QPen& pen);
164 void lineVisibleChanged(bool visible);
164 void lineVisibleChanged(bool visible);
165 void labelsVisibleChanged(bool visible);
165 void labelsVisibleChanged(bool visible);
166 void labelsPenChanged(const QPen& pen);
166 void labelsPenChanged(const QPen& pen);
167 void labelsBrushChanged(const QBrush& brush);
167 void labelsBrushChanged(const QBrush& brush);
168 void labelsFontChanged(const QFont& pen);
168 void labelsFontChanged(const QFont& pen);
169 void labelsAngleChanged(int angle);
169 void labelsAngleChanged(int angle);
170 void gridLinePenChanged(const QPen& pen);
170 void gridLinePenChanged(const QPen& pen);
171 void gridVisibleChanged(bool visible);
171 void gridVisibleChanged(bool visible);
172 void colorChanged(QColor color);
172 void colorChanged(QColor color);
173 void labelsColorChanged(QColor color);
173 void labelsColorChanged(QColor color);
174 void titleTextChanged(const QString& title);
174 void titleTextChanged(const QString& title);
175 void titlePenChanged(const QPen& pen);
175 void titlePenChanged(const QPen& pen);
176 void titleBrushChanged(const QBrush brush);
176 void titleBrushChanged(const QBrush brush);
177 void titleVisibleChanged(bool visible);
177 void titleVisibleChanged(bool visible);
178 void titleFontChanged(const QFont& font);
178 void titleFontChanged(const QFont& font);
179 void shadesVisibleChanged(bool visible);
179 void shadesVisibleChanged(bool visible);
180 void shadesColorChanged(QColor color);
180 void shadesColorChanged(QColor color);
181 void shadesBorderColorChanged(QColor color);
181 void shadesBorderColorChanged(QColor color);
182 void shadesPenChanged(const QPen& pen);
182 void shadesPenChanged(const QPen& pen);
183 void shadesBrushChanged(const QBrush brush);
183 void shadesBrushChanged(const QBrush brush);
184
184
185 protected:
185 protected:
186 QScopedPointer<QAbstractAxisPrivate> d_ptr;
186 QScopedPointer<QAbstractAxisPrivate> d_ptr;
187 Q_DISABLE_COPY(QAbstractAxis)
187 Q_DISABLE_COPY(QAbstractAxis)
188 friend class ChartDataSet;
188 friend class ChartDataSet;
189 friend class ChartAxis;
189 friend class ChartAxis;
190 friend class ChartPresenter;
190 friend class ChartPresenter;
191 friend class ChartThemeManager;
191 friend class ChartThemeManager;
192 friend class AbstractDomain;
192 friend class AbstractDomain;
193 };
193 };
194
194
195 QTCOMMERCIALCHART_END_NAMESPACE
195 QTCOMMERCIALCHART_END_NAMESPACE
196
196
197 #endif // QABSTRACTAXIS_H
197 #endif // QABSTRACTAXIS_H
@@ -1,212 +1,212
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 "verticalaxis_p.h"
21 #include "verticalaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include <QFontMetrics>
23 #include <QFontMetrics>
24 #include <QDebug>
24 #include <QDebug>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 VerticalAxis::VerticalAxis(QAbstractAxis *axis, QGraphicsItem* item, bool intervalAxis)
28 VerticalAxis::VerticalAxis(QAbstractAxis *axis, QGraphicsItem* item, bool intervalAxis)
29 : ChartAxis(axis, item, intervalAxis)
29 : ChartAxis(axis, item, intervalAxis)
30 {
30 {
31
31
32 }
32 }
33
33
34 VerticalAxis::~VerticalAxis()
34 VerticalAxis::~VerticalAxis()
35 {
35 {
36
36
37 }
37 }
38
38
39 void VerticalAxis::updateGeometry()
39 void VerticalAxis::updateGeometry()
40 {
40 {
41 const QVector<qreal> &layout = ChartAxis::layout();
41 const QVector<qreal> &layout = ChartAxis::layout();
42
42
43 if (layout.isEmpty())
43 if (layout.isEmpty())
44 return;
44 return;
45
45
46 QStringList labelList = labels();
46 QStringList labelList = labels();
47
47
48 QList<QGraphicsItem *> lines = lineItems();
48 QList<QGraphicsItem *> lines = lineItems();
49 QList<QGraphicsItem *> labels = labelItems();
49 QList<QGraphicsItem *> labels = labelItems();
50 QList<QGraphicsItem *> shades = shadeItems();
50 QList<QGraphicsItem *> shades = shadeItems();
51 QList<QGraphicsItem *> axis = arrowItems();
51 QList<QGraphicsItem *> axis = arrowItems();
52 QGraphicsSimpleTextItem* title = titleItem();
52 QGraphicsSimpleTextItem* title = titleItem();
53
53
54 Q_ASSERT(labels.size() == labelList.size());
54 Q_ASSERT(labels.size() == labelList.size());
55 Q_ASSERT(layout.size() == labelList.size());
55 Q_ASSERT(layout.size() == labelList.size());
56
56
57 const QRectF &axisRect = axisGeometry();
57 const QRectF &axisRect = axisGeometry();
58 const QRectF &gridRect = gridGeometry();
58 const QRectF &gridRect = gridGeometry();
59
59
60 qreal height = axisRect.bottom();
60 qreal height = axisRect.bottom();
61
61
62
62
63 //arrow
63 //arrow
64 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(axis.at(0));
64 QGraphicsLineItem *arrowItem = static_cast<QGraphicsLineItem*>(axis.at(0));
65
65
66 //arrow position
66 //arrow position
67 if (alignment()==Qt::AlignLeft)
67 if (alignment()==Qt::AlignLeft)
68 arrowItem->setLine( axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom());
68 arrowItem->setLine( axisRect.right() , gridRect.top(), axisRect.right(), gridRect.bottom());
69 else if(alignment()==Qt::AlignRight)
69 else if(alignment()==Qt::AlignRight)
70 arrowItem->setLine( axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom());
70 arrowItem->setLine( axisRect.left() , gridRect.top(), axisRect.left(), gridRect.bottom());
71
71
72 QFontMetrics fn(font());
72 QFontMetrics fn(font());
73
73
74 //title
74 //title
75
75
76 if (!titleText().isNull()) {
76 if (!titleText().isNull()) {
77 QFontMetrics fn(title->font());
77 QFontMetrics fn(title->font());
78
78
79 int size(0);
79 int size(0);
80 size = gridRect.height();
80 size = gridRect.height();
81 QString titleText = this->titleText();
81 QString titleText = this->titleText();
82
82
83 if (fn.boundingRect(titleText).width() > size) {
83 if (fn.boundingRect(titleText).width() > size) {
84 QString string = titleText + "...";
84 QString string = titleText + "...";
85 while (fn.boundingRect(string).width() > size && string.length() > 3)
85 while (fn.boundingRect(string).width() > size && string.length() > 3)
86 string.remove(string.length() - 4, 1);
86 string.remove(string.length() - 4, 1);
87 title->setText(string);
87 title->setText(string);
88 }
88 }
89 else {
89 else {
90 title->setText(titleText);
90 title->setText(titleText);
91 }
91 }
92
92
93 QPointF center = gridRect.center() - title->boundingRect().center();
93 QPointF center = gridRect.center() - title->boundingRect().center();
94 if (alignment() == Qt::AlignLeft) {
94 if (alignment() == Qt::AlignLeft) {
95 title->setPos(axisRect.left() - title->boundingRect().width()/2 + title->boundingRect().height()/2 , center.y());
95 title->setPos(axisRect.left() - title->boundingRect().width()/2 + title->boundingRect().height()/2 , center.y());
96 }
96 }
97 else if (alignment() == Qt::AlignRight) {
97 else if (alignment() == Qt::AlignRight) {
98 title->setPos(axisRect.right()- title->boundingRect().width()/2 - title->boundingRect().height()/2, center.y());
98 title->setPos(axisRect.right()- title->boundingRect().width()/2 - title->boundingRect().height()/2, center.y());
99 }
99 }
100 title->setTransformOriginPoint(title->boundingRect().center());
100 title->setTransformOriginPoint(title->boundingRect().center());
101 title->setRotation(270);
101 title->setRotation(270);
102 }
102 }
103
103
104 for (int i = 0; i < layout.size(); ++i) {
104 for (int i = 0; i < layout.size(); ++i) {
105
105
106 //items
106 //items
107 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
107 QGraphicsLineItem *gridItem = static_cast<QGraphicsLineItem *>(lines.at(i));
108 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1));
108 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(axis.at(i + 1));
109 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
109 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem *>(labels.at(i));
110
110
111 //grid line
111 //grid line
112 gridItem->setLine(gridRect.left() , layout[i], gridRect.right(), layout[i]);
112 gridItem->setLine(gridRect.left() , layout[i], gridRect.right(), layout[i]);
113
113
114 //label text wrapping
114 //label text wrapping
115 QString text = labelList.at(i);
115 QString text = labelList.at(i);
116 qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height();
116 qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height();
117 if (fn.boundingRect(text).width() > size) {
117 if (fn.boundingRect(text).width() > size) {
118 QString label = text + "...";
118 QString label = text + "...";
119 while (fn.boundingRect(label).width() > size && label.length() > 3)
119 while (fn.boundingRect(label).width() > size && label.length() > 3)
120 label.remove(label.length() - 4, 1);
120 label.remove(label.length() - 4, 1);
121 labelItem->setText(label);
121 labelItem->setText(label);
122 } else {
122 } else {
123 labelItem->setText(text);
123 labelItem->setText(text);
124 }
124 }
125 //label transformation origin point
125 //label transformation origin point
126 const QRectF &rect = labelItem->boundingRect();
126 const QRectF &rect = labelItem->boundingRect();
127
127
128 QPointF center = rect.center();
128 QPointF center = rect.center();
129 labelItem->setTransformOriginPoint(center.x(), center.y());
129 labelItem->setTransformOriginPoint(center.x(), center.y());
130
130
131 //ticks and label position
131 //ticks and label position
132 if (alignment() == Qt::AlignLeft) {
132 if (alignment() == Qt::AlignLeft) {
133 labelItem->setPos(axisRect.right() - rect.width() - labelPadding() , layout[i] - center.y());
133 labelItem->setPos(axisRect.right() - rect.width() - labelPadding() , layout[i] - center.y());
134 tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]);
134 tickItem->setLine(axisRect.right() - labelPadding(), layout[i], axisRect.right(), layout[i]);
135 } else if (alignment() == Qt::AlignRight) {
135 } else if (alignment() == Qt::AlignRight) {
136 labelItem->setPos(axisRect.left() + labelPadding() , layout[i] - center.y());
136 labelItem->setPos(axisRect.left() + labelPadding() , layout[i] - center.y());
137 tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]);
137 tickItem->setLine(axisRect.left(), layout[i], axisRect.left() + labelPadding(), layout[i]);
138 }
138 }
139
139
140 //label in beetwen
140 //label in beetwen
141 if(intervalAxis()&& i+1!=layout.size()) {
141 if(intervalAxis()&& i+1!=layout.size()) {
142 const qreal delta = (layout[i+1] - layout[i])/2;
142 const qreal delta = (layout[i+1] - layout[i])/2;
143 labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y());
143 labelItem->setPos(labelItem->pos().x() , layout[i] + delta - center.y());
144 }
144 }
145
145
146 //label overlap detection
146 //label overlap detection
147 if(labelItem->pos().y() + rect.height() > height ||
147 if(labelItem->pos().y() + rect.height() > height ||
148 labelItem->pos().y() + rect.height()/2 > gridRect.bottom() ||
148 labelItem->pos().y() + rect.height()/2 > gridRect.bottom() ||
149 labelItem->pos().y() + rect.height()/2 < gridRect.top()) {
149 labelItem->pos().y() + rect.height()/2 < gridRect.top()) {
150 labelItem->setVisible(false);
150 labelItem->setVisible(false);
151 }
151 }
152 else {
152 else {
153 labelItem->setVisible(true);
153 labelItem->setVisible(true);
154 height=labelItem->pos().y();
154 height=labelItem->pos().y();
155 }
155 }
156
156
157 //shades
157 //shades
158 if ((i + 1) % 2 && i > 1) {
158 if ((i + 1) % 2 && i > 1) {
159 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1));
159 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem *>(shades.at(i / 2 - 1));
160 rectItem->setRect(gridRect.left(), layout[i], gridRect.width(), layout[i - 1] - layout[i]);
160 rectItem->setRect(gridRect.left(), layout[i], gridRect.width(), layout[i - 1] - layout[i]);
161 }
161 }
162
162
163 // check if the grid line and the axis tick should be shown
163 // check if the grid line and the axis tick should be shown
164 qreal y = gridItem->line().p1().y();
164 qreal y = gridItem->line().p1().y();
165 if ((y < gridRect.top() || y > gridRect.bottom()))
165 if ((y < gridRect.top() || y > gridRect.bottom()))
166 {
166 {
167 gridItem->setVisible(false);
167 gridItem->setVisible(false);
168 tickItem->setVisible(false);
168 tickItem->setVisible(false);
169 }else{
169 }else{
170 gridItem->setVisible(true);
170 gridItem->setVisible(true);
171 tickItem->setVisible(true);
171 tickItem->setVisible(true);
172 }
172 }
173
173
174 }
174 }
175 //begin/end grid line in case labels between
175 //begin/end grid line in case labels between
176 if (intervalAxis()) {
176 if (intervalAxis()) {
177 QGraphicsLineItem *gridLine;
177 QGraphicsLineItem *gridLine;
178 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
178 gridLine = static_cast<QGraphicsLineItem *>(lines.at(layout.size()));
179 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top());
179 gridLine->setLine(gridRect.left(), gridRect.top(), gridRect.right(), gridRect.top());
180 gridLine->setVisible(true);
180 gridLine->setVisible(true);
181 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1));
181 gridLine = static_cast<QGraphicsLineItem*>(lines.at(layout.size()+1));
182 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
182 gridLine->setLine(gridRect.left(), gridRect.bottom(), gridRect.right(), gridRect.bottom());
183 gridLine->setVisible(true);
183 gridLine->setVisible(true);
184 }
184 }
185 }
185 }
186
186
187 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
187 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
188 {
188 {
189
189
190 Q_UNUSED(constraint);
190 Q_UNUSED(constraint);
191 QFontMetrics fn(titleFont());
191 QFontMetrics fn(titleFont());
192 QSizeF sh;
192 QSizeF sh;
193
193
194 if (titleText().isNull())
194 if (titleText().isNull() || !titleItem()->isVisible())
195 return sh;
195 return sh;
196
196
197 switch (which) {
197 switch (which) {
198 case Qt::MinimumSize:
198 case Qt::MinimumSize:
199 sh = QSizeF(fn.height(), fn.boundingRect("...").width());
199 sh = QSizeF(fn.height(), fn.boundingRect("...").width());
200 break;
200 break;
201 case Qt::MaximumSize:
201 case Qt::MaximumSize:
202 case Qt::PreferredSize:
202 case Qt::PreferredSize:
203 sh = QSizeF(fn.height(), fn.boundingRect(axis()->titleText()).width());
203 sh = QSizeF(fn.height(), fn.boundingRect(axis()->titleText()).width());
204 break;
204 break;
205 default:
205 default:
206 break;
206 break;
207 }
207 }
208
208
209 return sh;
209 return sh;
210 }
210 }
211
211
212 QTCOMMERCIALCHART_END_NAMESPACE
212 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now