##// END OF EJS Templates
Replaced qFuzzyIsNull with qFuzzyCompare. Once qchart test case still uses qFuzzyIsNull becasue it started failing when qFuzzyCompare was used
Marek Rosa -
r2242:2523dbee7254
parent child
Show More
@@ -1,141 +1,141
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 "pentool.h"
21 #include "pentool.h"
22 #include <QPushButton>
22 #include <QPushButton>
23 #include <QDoubleSpinBox>
23 #include <QDoubleSpinBox>
24 #include <QComboBox>
24 #include <QComboBox>
25 #include <QFormLayout>
25 #include <QFormLayout>
26 #include <QColorDialog>
26 #include <QColorDialog>
27
27
28 PenTool::PenTool(QString title, QWidget *parent)
28 PenTool::PenTool(QString title, QWidget *parent)
29 : QWidget(parent)
29 : QWidget(parent)
30 {
30 {
31 setWindowTitle(title);
31 setWindowTitle(title);
32 setWindowFlags(Qt::Tool);
32 setWindowFlags(Qt::Tool);
33
33
34 m_colorButton = new QPushButton();
34 m_colorButton = new QPushButton();
35
35
36 m_widthSpinBox = new QDoubleSpinBox();
36 m_widthSpinBox = new QDoubleSpinBox();
37
37
38 m_styleCombo = new QComboBox();
38 m_styleCombo = new QComboBox();
39 m_styleCombo->addItem("NoPen");
39 m_styleCombo->addItem("NoPen");
40 m_styleCombo->addItem("SolidLine");
40 m_styleCombo->addItem("SolidLine");
41 m_styleCombo->addItem("DashLine");
41 m_styleCombo->addItem("DashLine");
42 m_styleCombo->addItem("DotLine");
42 m_styleCombo->addItem("DotLine");
43 m_styleCombo->addItem("DashDotLine");
43 m_styleCombo->addItem("DashDotLine");
44 m_styleCombo->addItem("DashDotDotLine");
44 m_styleCombo->addItem("DashDotDotLine");
45
45
46 m_capStyleCombo = new QComboBox();
46 m_capStyleCombo = new QComboBox();
47 m_capStyleCombo->addItem("FlatCap", Qt::FlatCap);
47 m_capStyleCombo->addItem("FlatCap", Qt::FlatCap);
48 m_capStyleCombo->addItem("SquareCap", Qt::SquareCap);
48 m_capStyleCombo->addItem("SquareCap", Qt::SquareCap);
49 m_capStyleCombo->addItem("RoundCap", Qt::RoundCap);
49 m_capStyleCombo->addItem("RoundCap", Qt::RoundCap);
50
50
51 m_joinStyleCombo = new QComboBox();
51 m_joinStyleCombo = new QComboBox();
52 m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin);
52 m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin);
53 m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin);
53 m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin);
54 m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin);
54 m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin);
55 m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin);
55 m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin);
56
56
57 QFormLayout *layout = new QFormLayout();
57 QFormLayout *layout = new QFormLayout();
58 layout->addRow("Color", m_colorButton);
58 layout->addRow("Color", m_colorButton);
59 layout->addRow("Width", m_widthSpinBox);
59 layout->addRow("Width", m_widthSpinBox);
60 layout->addRow("Style", m_styleCombo);
60 layout->addRow("Style", m_styleCombo);
61 layout->addRow("Cap style", m_capStyleCombo);
61 layout->addRow("Cap style", m_capStyleCombo);
62 layout->addRow("Join style", m_joinStyleCombo);
62 layout->addRow("Join style", m_joinStyleCombo);
63 setLayout(layout);
63 setLayout(layout);
64
64
65 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
65 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
66 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
66 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
67 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int)));
67 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int)));
68 connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int)));
68 connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int)));
69 connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int)));
69 connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int)));
70 }
70 }
71
71
72 void PenTool::setPen(const QPen &pen)
72 void PenTool::setPen(const QPen &pen)
73 {
73 {
74 m_pen = pen;
74 m_pen = pen;
75 m_colorButton->setText(m_pen.color().name());
75 m_colorButton->setText(m_pen.color().name());
76 m_widthSpinBox->setValue(m_pen.widthF());
76 m_widthSpinBox->setValue(m_pen.widthF());
77 m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum
77 m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum
78 m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle()));
78 m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle()));
79 m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle()));
79 m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle()));
80 }
80 }
81
81
82 QPen PenTool::pen() const
82 QPen PenTool::pen() const
83 {
83 {
84 return m_pen;
84 return m_pen;
85 }
85 }
86
86
87 QString PenTool::name()
87 QString PenTool::name()
88 {
88 {
89 return name(m_pen);
89 return name(m_pen);
90 }
90 }
91
91
92 QString PenTool::name(const QPen &pen)
92 QString PenTool::name(const QPen &pen)
93 {
93 {
94 return pen.color().name() + ":" + QString::number(pen.widthF());
94 return pen.color().name() + ":" + QString::number(pen.widthF());
95 }
95 }
96
96
97 void PenTool::showColorDialog()
97 void PenTool::showColorDialog()
98 {
98 {
99 QColorDialog dialog(m_pen.color());
99 QColorDialog dialog(m_pen.color());
100 dialog.show();
100 dialog.show();
101 dialog.exec();
101 dialog.exec();
102 m_pen.setColor(dialog.selectedColor());
102 m_pen.setColor(dialog.selectedColor());
103 m_colorButton->setText(m_pen.color().name());
103 m_colorButton->setText(m_pen.color().name());
104 emit changed();
104 emit changed();
105 }
105 }
106
106
107 void PenTool::updateWidth(double width)
107 void PenTool::updateWidth(double width)
108 {
108 {
109 if (!qFuzzyIsNull(width - m_pen.widthF())) {
109 if (!qFuzzyCompare(width, m_pen.widthF())) {
110 m_pen.setWidthF(width);
110 m_pen.setWidthF(width);
111 emit changed();
111 emit changed();
112 }
112 }
113 }
113 }
114
114
115 void PenTool::updateStyle(int style)
115 void PenTool::updateStyle(int style)
116 {
116 {
117 if (m_pen.style() != style) {
117 if (m_pen.style() != style) {
118 m_pen.setStyle((Qt::PenStyle) style);
118 m_pen.setStyle((Qt::PenStyle) style);
119 emit changed();
119 emit changed();
120 }
120 }
121 }
121 }
122
122
123 void PenTool::updateCapStyle(int index)
123 void PenTool::updateCapStyle(int index)
124 {
124 {
125 Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt();
125 Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt();
126 if (m_pen.capStyle() != capStyle) {
126 if (m_pen.capStyle() != capStyle) {
127 m_pen.setCapStyle(capStyle);
127 m_pen.setCapStyle(capStyle);
128 emit changed();
128 emit changed();
129 }
129 }
130 }
130 }
131
131
132 void PenTool::updateJoinStyle(int index)
132 void PenTool::updateJoinStyle(int index)
133 {
133 {
134 Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt();
134 Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt();
135 if (m_pen.joinStyle() != joinStyle) {
135 if (m_pen.joinStyle() != joinStyle) {
136 m_pen.setJoinStyle(joinStyle);
136 m_pen.setJoinStyle(joinStyle);
137 emit changed();
137 emit changed();
138 }
138 }
139 }
139 }
140
140
141 #include "moc_pentool.cpp"
141 #include "moc_pentool.cpp"
@@ -1,476 +1,476
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartaxis_p.h"
21 #include "chartaxis_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "qabstractaxis_p.h"
23 #include "qabstractaxis_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "chartlayout_p.h"
25 #include "chartlayout_p.h"
26 #include "domain_p.h"
26 #include "domain_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28 #include <QDateTime>
28 #include <QDateTime>
29 #include <QValueAxis>
29 #include <QValueAxis>
30 #include <QGraphicsLayout>
30 #include <QGraphicsLayout>
31 #include <QFontMetrics>
31 #include <QFontMetrics>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis)
35 ChartAxis::ChartAxis(QAbstractAxis *axis, ChartPresenter *presenter, bool intervalAxis)
36 : ChartElement(presenter),
36 : ChartElement(presenter),
37 m_chartAxis(axis),
37 m_chartAxis(axis),
38 m_labelsAngle(0),
38 m_labelsAngle(0),
39 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
39 m_grid(new QGraphicsItemGroup(presenter->rootItem())),
40 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
40 m_shades(new QGraphicsItemGroup(presenter->rootItem())),
41 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
41 m_labels(new QGraphicsItemGroup(presenter->rootItem())),
42 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
42 m_arrow(new QGraphicsItemGroup(presenter->rootItem())),
43 m_title(new QGraphicsSimpleTextItem(presenter->rootItem())),
43 m_title(new QGraphicsSimpleTextItem(presenter->rootItem())),
44 m_min(0),
44 m_min(0),
45 m_max(0),
45 m_max(0),
46 m_animation(0),
46 m_animation(0),
47 m_labelPadding(5),
47 m_labelPadding(5),
48 m_intervalAxis(intervalAxis)
48 m_intervalAxis(intervalAxis)
49 {
49 {
50 //initial initialization
50 //initial initialization
51 m_arrow->setZValue(ChartPresenter::AxisZValue);
51 m_arrow->setZValue(ChartPresenter::AxisZValue);
52 m_arrow->setHandlesChildEvents(false);
52 m_arrow->setHandlesChildEvents(false);
53 m_labels->setZValue(ChartPresenter::AxisZValue);
53 m_labels->setZValue(ChartPresenter::AxisZValue);
54 m_shades->setZValue(ChartPresenter::ShadesZValue);
54 m_shades->setZValue(ChartPresenter::ShadesZValue);
55 m_grid->setZValue(ChartPresenter::GridZValue);
55 m_grid->setZValue(ChartPresenter::GridZValue);
56 m_title->setZValue(ChartPresenter::GridZValue);
56 m_title->setZValue(ChartPresenter::GridZValue);
57
57
58 QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated()));
58 QObject::connect(m_chartAxis->d_ptr.data(), SIGNAL(updated()), this, SLOT(handleAxisUpdated()));
59
59
60 QGraphicsSimpleTextItem item;
60 QGraphicsSimpleTextItem item;
61 m_font = item.font();
61 m_font = item.font();
62
62
63 }
63 }
64
64
65 ChartAxis::~ChartAxis()
65 ChartAxis::~ChartAxis()
66 {
66 {
67 }
67 }
68
68
69 void ChartAxis::setAnimation(AxisAnimation *animation)
69 void ChartAxis::setAnimation(AxisAnimation *animation)
70 {
70 {
71 m_animation = animation;
71 m_animation = animation;
72 }
72 }
73
73
74 void ChartAxis::setLayout(QVector<qreal> &layout)
74 void ChartAxis::setLayout(QVector<qreal> &layout)
75 {
75 {
76 m_layoutVector = layout;
76 m_layoutVector = layout;
77 }
77 }
78
78
79 void ChartAxis::createItems(int count)
79 void ChartAxis::createItems(int count)
80 {
80 {
81 if (m_arrow->childItems().size() == 0)
81 if (m_arrow->childItems().size() == 0)
82 m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem()));
82 m_arrow->addToGroup(new AxisItem(this, presenter()->rootItem()));
83
83
84 if (m_intervalAxis && m_grid->childItems().size() == 0) {
84 if (m_intervalAxis && m_grid->childItems().size() == 0) {
85 for (int i = 0 ; i < 2 ; i ++)
85 for (int i = 0 ; i < 2 ; i ++)
86 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
86 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
87 }
87 }
88
88
89 for (int i = 0; i < count; ++i) {
89 for (int i = 0; i < count; ++i) {
90 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
90 m_grid->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
91 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
91 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(presenter()->rootItem());
92 label->setFont(m_font);
92 label->setFont(m_font);
93 m_labels->addToGroup(label);
93 m_labels->addToGroup(label);
94 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
94 m_arrow->addToGroup(new QGraphicsLineItem(presenter()->rootItem()));
95 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2)
95 if ((m_grid->childItems().size()) % 2 && m_grid->childItems().size() > 2)
96 m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
96 m_shades->addToGroup(new QGraphicsRectItem(presenter()->rootItem()));
97 }
97 }
98 }
98 }
99
99
100 void ChartAxis::deleteItems(int count)
100 void ChartAxis::deleteItems(int count)
101 {
101 {
102 QList<QGraphicsItem *> lines = m_grid->childItems();
102 QList<QGraphicsItem *> lines = m_grid->childItems();
103 QList<QGraphicsItem *> labels = m_labels->childItems();
103 QList<QGraphicsItem *> labels = m_labels->childItems();
104 QList<QGraphicsItem *> shades = m_shades->childItems();
104 QList<QGraphicsItem *> shades = m_shades->childItems();
105 QList<QGraphicsItem *> axis = m_arrow->childItems();
105 QList<QGraphicsItem *> axis = m_arrow->childItems();
106
106
107 for (int i = 0; i < count; ++i) {
107 for (int i = 0; i < count; ++i) {
108 if (lines.size() % 2 && lines.size() > 1)
108 if (lines.size() % 2 && lines.size() > 1)
109 delete(shades.takeLast());
109 delete(shades.takeLast());
110 delete(lines.takeLast());
110 delete(lines.takeLast());
111 delete(labels.takeLast());
111 delete(labels.takeLast());
112 delete(axis.takeLast());
112 delete(axis.takeLast());
113 }
113 }
114 }
114 }
115
115
116 void ChartAxis::updateLayout(QVector<qreal> &layout)
116 void ChartAxis::updateLayout(QVector<qreal> &layout)
117 {
117 {
118 int diff = m_layoutVector.size() - layout.size();
118 int diff = m_layoutVector.size() - layout.size();
119
119
120 if (diff > 0)
120 if (diff > 0)
121 deleteItems(diff);
121 deleteItems(diff);
122 else if (diff < 0)
122 else if (diff < 0)
123 createItems(-diff);
123 createItems(-diff);
124
124
125 if (diff < 0) handleAxisUpdated();
125 if (diff < 0) handleAxisUpdated();
126
126
127 if (m_animation) {
127 if (m_animation) {
128 switch (presenter()->state()) {
128 switch (presenter()->state()) {
129 case ChartPresenter::ZoomInState:
129 case ChartPresenter::ZoomInState:
130 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
130 m_animation->setAnimationType(AxisAnimation::ZoomInAnimation);
131 m_animation->setAnimationPoint(presenter()->statePoint());
131 m_animation->setAnimationPoint(presenter()->statePoint());
132 break;
132 break;
133 case ChartPresenter::ZoomOutState:
133 case ChartPresenter::ZoomOutState:
134 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
134 m_animation->setAnimationType(AxisAnimation::ZoomOutAnimation);
135 m_animation->setAnimationPoint(presenter()->statePoint());
135 m_animation->setAnimationPoint(presenter()->statePoint());
136 break;
136 break;
137 case ChartPresenter::ScrollUpState:
137 case ChartPresenter::ScrollUpState:
138 case ChartPresenter::ScrollLeftState:
138 case ChartPresenter::ScrollLeftState:
139 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
139 m_animation->setAnimationType(AxisAnimation::MoveBackwordAnimation);
140 break;
140 break;
141 case ChartPresenter::ScrollDownState:
141 case ChartPresenter::ScrollDownState:
142 case ChartPresenter::ScrollRightState:
142 case ChartPresenter::ScrollRightState:
143 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
143 m_animation->setAnimationType(AxisAnimation::MoveForwardAnimation);
144 break;
144 break;
145 case ChartPresenter::ShowState:
145 case ChartPresenter::ShowState:
146 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
146 m_animation->setAnimationType(AxisAnimation::DefaultAnimation);
147 break;
147 break;
148 }
148 }
149 m_animation->setValues(m_layoutVector, layout);
149 m_animation->setValues(m_layoutVector, layout);
150 presenter()->startAnimation(m_animation);
150 presenter()->startAnimation(m_animation);
151 } else {
151 } else {
152 setLayout(layout);
152 setLayout(layout);
153 updateGeometry();
153 updateGeometry();
154 }
154 }
155 }
155 }
156
156
157 void ChartAxis::setArrowOpacity(qreal opacity)
157 void ChartAxis::setArrowOpacity(qreal opacity)
158 {
158 {
159 m_arrow->setOpacity(opacity);
159 m_arrow->setOpacity(opacity);
160 }
160 }
161
161
162 qreal ChartAxis::arrowOpacity() const
162 qreal ChartAxis::arrowOpacity() const
163 {
163 {
164 return m_arrow->opacity();
164 return m_arrow->opacity();
165 }
165 }
166
166
167 void ChartAxis::setArrowVisibility(bool visible)
167 void ChartAxis::setArrowVisibility(bool visible)
168 {
168 {
169 m_arrow->setOpacity(visible);
169 m_arrow->setOpacity(visible);
170 }
170 }
171
171
172 void ChartAxis::setGridOpacity(qreal opacity)
172 void ChartAxis::setGridOpacity(qreal opacity)
173 {
173 {
174 m_grid->setOpacity(opacity);
174 m_grid->setOpacity(opacity);
175 }
175 }
176
176
177 qreal ChartAxis::gridOpacity() const
177 qreal ChartAxis::gridOpacity() const
178 {
178 {
179 return m_grid->opacity();
179 return m_grid->opacity();
180 }
180 }
181
181
182 void ChartAxis::setGridVisibility(bool visible)
182 void ChartAxis::setGridVisibility(bool visible)
183 {
183 {
184 m_grid->setOpacity(visible);
184 m_grid->setOpacity(visible);
185 }
185 }
186
186
187 void ChartAxis::setLabelsOpacity(qreal opacity)
187 void ChartAxis::setLabelsOpacity(qreal opacity)
188 {
188 {
189 m_labels->setOpacity(opacity);
189 m_labels->setOpacity(opacity);
190 }
190 }
191
191
192 qreal ChartAxis::labelsOpacity() const
192 qreal ChartAxis::labelsOpacity() const
193 {
193 {
194 return m_labels->opacity();
194 return m_labels->opacity();
195 }
195 }
196
196
197 void ChartAxis::setLabelsVisibility(bool visible)
197 void ChartAxis::setLabelsVisibility(bool visible)
198 {
198 {
199 m_labels->setOpacity(visible);
199 m_labels->setOpacity(visible);
200 }
200 }
201
201
202 void ChartAxis::setShadesOpacity(qreal opacity)
202 void ChartAxis::setShadesOpacity(qreal opacity)
203 {
203 {
204 m_shades->setOpacity(opacity);
204 m_shades->setOpacity(opacity);
205 }
205 }
206
206
207 qreal ChartAxis::shadesOpacity() const
207 qreal ChartAxis::shadesOpacity() const
208 {
208 {
209 return m_shades->opacity();
209 return m_shades->opacity();
210 }
210 }
211
211
212 void ChartAxis::setShadesVisibility(bool visible)
212 void ChartAxis::setShadesVisibility(bool visible)
213 {
213 {
214 m_shades->setVisible(visible);
214 m_shades->setVisible(visible);
215 }
215 }
216
216
217 void ChartAxis::setLabelsAngle(int angle)
217 void ChartAxis::setLabelsAngle(int angle)
218 {
218 {
219 foreach (QGraphicsItem *item, m_labels->childItems())
219 foreach (QGraphicsItem *item, m_labels->childItems())
220 item->setRotation(angle);
220 item->setRotation(angle);
221
221
222 m_labelsAngle = angle;
222 m_labelsAngle = angle;
223 }
223 }
224
224
225 void ChartAxis::setLabelsPen(const QPen &pen)
225 void ChartAxis::setLabelsPen(const QPen &pen)
226 {
226 {
227 foreach (QGraphicsItem *item , m_labels->childItems())
227 foreach (QGraphicsItem *item , m_labels->childItems())
228 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
228 static_cast<QGraphicsSimpleTextItem *>(item)->setPen(pen);
229 }
229 }
230
230
231 void ChartAxis::setLabelsBrush(const QBrush &brush)
231 void ChartAxis::setLabelsBrush(const QBrush &brush)
232 {
232 {
233 foreach (QGraphicsItem *item , m_labels->childItems())
233 foreach (QGraphicsItem *item , m_labels->childItems())
234 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
234 static_cast<QGraphicsSimpleTextItem *>(item)->setBrush(brush);
235 }
235 }
236
236
237 void ChartAxis::setLabelsFont(const QFont &font)
237 void ChartAxis::setLabelsFont(const QFont &font)
238 {
238 {
239 if (m_font != font) {
239 if (m_font != font) {
240 m_font = font;
240 m_font = font;
241 foreach (QGraphicsItem *item , m_labels->childItems())
241 foreach (QGraphicsItem *item , m_labels->childItems())
242 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
242 static_cast<QGraphicsSimpleTextItem *>(item)->setFont(font);
243 QGraphicsLayoutItem::updateGeometry();
243 QGraphicsLayoutItem::updateGeometry();
244 presenter()->layout()->invalidate();
244 presenter()->layout()->invalidate();
245 }
245 }
246 }
246 }
247
247
248 void ChartAxis::setShadesBrush(const QBrush &brush)
248 void ChartAxis::setShadesBrush(const QBrush &brush)
249 {
249 {
250 foreach (QGraphicsItem *item , m_shades->childItems())
250 foreach (QGraphicsItem *item , m_shades->childItems())
251 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
251 static_cast<QGraphicsRectItem *>(item)->setBrush(brush);
252 }
252 }
253
253
254 void ChartAxis::setShadesPen(const QPen &pen)
254 void ChartAxis::setShadesPen(const QPen &pen)
255 {
255 {
256 foreach (QGraphicsItem *item , m_shades->childItems())
256 foreach (QGraphicsItem *item , m_shades->childItems())
257 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
257 static_cast<QGraphicsRectItem *>(item)->setPen(pen);
258 }
258 }
259
259
260 void ChartAxis::setArrowPen(const QPen &pen)
260 void ChartAxis::setArrowPen(const QPen &pen)
261 {
261 {
262 foreach (QGraphicsItem *item , m_arrow->childItems())
262 foreach (QGraphicsItem *item , m_arrow->childItems())
263 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
263 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
264 }
264 }
265
265
266 void ChartAxis::setGridPen(const QPen &pen)
266 void ChartAxis::setGridPen(const QPen &pen)
267 {
267 {
268 foreach (QGraphicsItem *item , m_grid->childItems())
268 foreach (QGraphicsItem *item , m_grid->childItems())
269 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
269 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
270 }
270 }
271
271
272 void ChartAxis::setLabelPadding(int padding)
272 void ChartAxis::setLabelPadding(int padding)
273 {
273 {
274 m_labelPadding = padding;
274 m_labelPadding = padding;
275 }
275 }
276
276
277 bool ChartAxis::isEmpty()
277 bool ChartAxis::isEmpty()
278 {
278 {
279 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyIsNull(m_min - m_max);
279 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(m_min, m_max);
280 }
280 }
281
281
282 void ChartAxis::handleDomainUpdated()
282 void ChartAxis::handleDomainUpdated()
283 {
283 {
284 Domain *domain = qobject_cast<Domain *>(sender());
284 Domain *domain = qobject_cast<Domain *>(sender());
285 qreal min(0);
285 qreal min(0);
286 qreal max(0);
286 qreal max(0);
287
287
288 if (m_chartAxis->orientation() == Qt::Horizontal) {
288 if (m_chartAxis->orientation() == Qt::Horizontal) {
289 min = domain->minX();
289 min = domain->minX();
290 max = domain->maxX();
290 max = domain->maxX();
291 } else if (m_chartAxis->orientation() == Qt::Vertical) {
291 } else if (m_chartAxis->orientation() == Qt::Vertical) {
292 min = domain->minY();
292 min = domain->minY();
293 max = domain->maxY();
293 max = domain->maxY();
294 }
294 }
295
295
296 if (!qFuzzyIsNull(m_min - min) || !qFuzzyIsNull(m_max - max)) {
296 if (!qFuzzyCompare(m_min, min) || !qFuzzyCompare(m_max, max)) {
297 m_min = min;
297 m_min = min;
298 m_max = max;
298 m_max = max;
299
299
300 if (!isEmpty()) {
300 if (!isEmpty()) {
301
301
302 QVector<qreal> layout = calculateLayout();
302 QVector<qreal> layout = calculateLayout();
303 updateLayout(layout);
303 updateLayout(layout);
304 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
304 QSizeF before = effectiveSizeHint(Qt::PreferredSize);
305 QSizeF after = sizeHint(Qt::PreferredSize);
305 QSizeF after = sizeHint(Qt::PreferredSize);
306
306
307 if (before != after) {
307 if (before != after) {
308 QGraphicsLayoutItem::updateGeometry();
308 QGraphicsLayoutItem::updateGeometry();
309 //we don't want to call invalidate on layout, since it will change minimum size of component,
309 //we don't want to call invalidate on layout, since it will change minimum size of component,
310 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
310 //which we would like to avoid since it causes nasty flips when scrolling or zooming,
311 //instead recalculate layout and use plotArea for extra space.
311 //instead recalculate layout and use plotArea for extra space.
312 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
312 presenter()->layout()->setGeometry(presenter()->layout()->geometry());
313 }
313 }
314 }
314 }
315 }
315 }
316 }
316 }
317
317
318 void ChartAxis::handleAxisUpdated()
318 void ChartAxis::handleAxisUpdated()
319 {
319 {
320 if (isEmpty())
320 if (isEmpty())
321 return;
321 return;
322
322
323 bool visible = m_chartAxis->isVisible();
323 bool visible = m_chartAxis->isVisible();
324
324
325 //TODO: split this into separate signal/slots ?
325 //TODO: split this into separate signal/slots ?
326 setArrowVisibility(visible && m_chartAxis->isLineVisible());
326 setArrowVisibility(visible && m_chartAxis->isLineVisible());
327 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
327 setGridVisibility(visible && m_chartAxis->isGridLineVisible());
328 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
328 setLabelsVisibility(visible && m_chartAxis->labelsVisible());
329 setShadesVisibility(visible && m_chartAxis->shadesVisible());
329 setShadesVisibility(visible && m_chartAxis->shadesVisible());
330 setLabelsAngle(m_chartAxis->labelsAngle());
330 setLabelsAngle(m_chartAxis->labelsAngle());
331 setArrowPen(m_chartAxis->linePen());
331 setArrowPen(m_chartAxis->linePen());
332 setLabelsPen(m_chartAxis->labelsPen());
332 setLabelsPen(m_chartAxis->labelsPen());
333 setLabelsBrush(m_chartAxis->labelsBrush());
333 setLabelsBrush(m_chartAxis->labelsBrush());
334 setLabelsFont(m_chartAxis->labelsFont());
334 setLabelsFont(m_chartAxis->labelsFont());
335 setGridPen(m_chartAxis->gridLinePen());
335 setGridPen(m_chartAxis->gridLinePen());
336 setShadesPen(m_chartAxis->shadesPen());
336 setShadesPen(m_chartAxis->shadesPen());
337 setShadesBrush(m_chartAxis->shadesBrush());
337 setShadesBrush(m_chartAxis->shadesBrush());
338 setTitleText(m_chartAxis->title());
338 setTitleText(m_chartAxis->title());
339 setTitleFont(m_chartAxis->titleFont());
339 setTitleFont(m_chartAxis->titleFont());
340 setTitlePen(m_chartAxis->titlePen());
340 setTitlePen(m_chartAxis->titlePen());
341 setTitleBrush(m_chartAxis->titleBrush());
341 setTitleBrush(m_chartAxis->titleBrush());
342 }
342 }
343
343
344 void ChartAxis::setTitleText(const QString &title)
344 void ChartAxis::setTitleText(const QString &title)
345 {
345 {
346 if (m_titleText != title) {
346 if (m_titleText != title) {
347 m_titleText = title;
347 m_titleText = title;
348 QGraphicsLayoutItem::updateGeometry();
348 QGraphicsLayoutItem::updateGeometry();
349 presenter()->layout()->invalidate();
349 presenter()->layout()->invalidate();
350 }
350 }
351 }
351 }
352
352
353 void ChartAxis::setTitlePen(const QPen &pen)
353 void ChartAxis::setTitlePen(const QPen &pen)
354 {
354 {
355 m_title->setPen(pen);
355 m_title->setPen(pen);
356 }
356 }
357
357
358 void ChartAxis::setTitleBrush(const QBrush &brush)
358 void ChartAxis::setTitleBrush(const QBrush &brush)
359 {
359 {
360 m_title->setBrush(brush);
360 m_title->setBrush(brush);
361 }
361 }
362
362
363 void ChartAxis::setTitleFont(const QFont &font)
363 void ChartAxis::setTitleFont(const QFont &font)
364 {
364 {
365 if(m_title->font() != font){
365 if(m_title->font() != font){
366 m_title->setFont(font);
366 m_title->setFont(font);
367 QGraphicsLayoutItem::updateGeometry();
367 QGraphicsLayoutItem::updateGeometry();
368 presenter()->layout()->invalidate();
368 presenter()->layout()->invalidate();
369 }
369 }
370 }
370 }
371
371
372 QFont ChartAxis::titleFont() const
372 QFont ChartAxis::titleFont() const
373 {
373 {
374 return m_title->font();
374 return m_title->font();
375 }
375 }
376
376
377 void ChartAxis::hide()
377 void ChartAxis::hide()
378 {
378 {
379 setArrowVisibility(false);
379 setArrowVisibility(false);
380 setGridVisibility(false);
380 setGridVisibility(false);
381 setLabelsVisibility(false);
381 setLabelsVisibility(false);
382 setShadesVisibility(false);
382 setShadesVisibility(false);
383 }
383 }
384
384
385 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
385 void ChartAxis::setGeometry(const QRectF &axis, const QRectF &grid)
386 {
386 {
387 m_gridRect = grid;
387 m_gridRect = grid;
388 m_axisRect = axis;
388 m_axisRect = axis;
389
389
390 if (isEmpty())
390 if (isEmpty())
391 return;
391 return;
392
392
393 QVector<qreal> layout = calculateLayout();
393 QVector<qreal> layout = calculateLayout();
394 updateLayout(layout);
394 updateLayout(layout);
395
395
396 }
396 }
397
397
398 void ChartAxis::axisSelected()
398 void ChartAxis::axisSelected()
399 {
399 {
400 //TODO: axis clicked;
400 //TODO: axis clicked;
401 }
401 }
402
402
403 Qt::Orientation ChartAxis::orientation() const
403 Qt::Orientation ChartAxis::orientation() const
404 {
404 {
405 return m_chartAxis->orientation();
405 return m_chartAxis->orientation();
406 }
406 }
407
407
408 Qt::Alignment ChartAxis::alignment() const
408 Qt::Alignment ChartAxis::alignment() const
409 {
409 {
410 return m_chartAxis->alignment();
410 return m_chartAxis->alignment();
411 }
411 }
412
412
413 bool ChartAxis::isVisible()
413 bool ChartAxis::isVisible()
414 {
414 {
415 return m_chartAxis->isVisible();
415 return m_chartAxis->isVisible();
416 }
416 }
417
417
418 void ChartAxis::setLabels(const QStringList &labels)
418 void ChartAxis::setLabels(const QStringList &labels)
419 {
419 {
420 m_labelsList = labels;
420 m_labelsList = labels;
421 }
421 }
422
422
423 QStringList ChartAxis::createValueLabels(int ticks) const
423 QStringList ChartAxis::createValueLabels(int ticks) const
424 {
424 {
425 Q_ASSERT(m_max > m_min);
425 Q_ASSERT(m_max > m_min);
426 Q_ASSERT(ticks > 1);
426 Q_ASSERT(ticks > 1);
427
427
428 QStringList labels;
428 QStringList labels;
429
429
430 int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0);
430 int n = qMax(int(-qFloor(log10((m_max - m_min) / (ticks - 1)))), 0);
431 n++;
431 n++;
432
432
433 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
433 QValueAxis *axis = qobject_cast<QValueAxis *>(m_chartAxis);
434
434
435 QString format = axis->labelFormat();
435 QString format = axis->labelFormat();
436
436
437 if (format.isNull()) {
437 if (format.isNull()) {
438 for (int i = 0; i < ticks; i++) {
438 for (int i = 0; i < ticks; i++) {
439 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
439 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
440 labels << QString::number(value, 'f', n);
440 labels << QString::number(value, 'f', n);
441 }
441 }
442 } else {
442 } else {
443 QByteArray array = format.toLatin1();
443 QByteArray array = format.toLatin1();
444 for (int i = 0; i < ticks; i++) {
444 for (int i = 0; i < ticks; i++) {
445 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
445 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
446 labels << QString().sprintf(array, value);
446 labels << QString().sprintf(array, value);
447 }
447 }
448 }
448 }
449
449
450 return labels;
450 return labels;
451 }
451 }
452
452
453 QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const
453 QStringList ChartAxis::createDateTimeLabels(const QString &format, int ticks) const
454 {
454 {
455 Q_ASSERT(m_max > m_min);
455 Q_ASSERT(m_max > m_min);
456 Q_ASSERT(ticks > 1);
456 Q_ASSERT(ticks > 1);
457 QStringList labels;
457 QStringList labels;
458 int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0);
458 int n = qMax(int(-floor(log10((m_max - m_min) / (ticks - 1)))), 0);
459 n++;
459 n++;
460 for (int i = 0; i < ticks; i++) {
460 for (int i = 0; i < ticks; i++) {
461 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
461 qreal value = m_min + (i * (m_max - m_min) / (ticks - 1));
462 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
462 labels << QDateTime::fromMSecsSinceEpoch(value).toString(format);
463 }
463 }
464 return labels;
464 return labels;
465 }
465 }
466
466
467 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
467 QSizeF ChartAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
468 {
468 {
469 Q_UNUSED(which);
469 Q_UNUSED(which);
470 Q_UNUSED(constraint);
470 Q_UNUSED(constraint);
471 return QSizeF();
471 return QSizeF();
472 }
472 }
473
473
474 #include "moc_chartaxis_p.cpp"
474 #include "moc_chartaxis_p.cpp"
475
475
476 QTCOMMERCIALCHART_END_NAMESPACE
476 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,420 +1,420
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 "qvalueaxis.h"
21 #include "qvalueaxis.h"
22 #include "qvalueaxis_p.h"
22 #include "qvalueaxis_p.h"
23 #include "chartvalueaxisx_p.h"
23 #include "chartvalueaxisx_p.h"
24 #include "chartvalueaxisy_p.h"
24 #include "chartvalueaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 /*!
31 /*!
32 \class QValueAxis
32 \class QValueAxis
33 \brief The QValueAxis class is used for manipulating chart's axis.
33 \brief The QValueAxis class is used for manipulating chart's axis.
34 \mainclass
34 \mainclass
35
35
36 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
36 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
37 Values of axis are drawn to position of ticks.
37 Values of axis are drawn to position of ticks.
38
38
39 Example code on how to use QValueAxis.
39 Example code on how to use QValueAxis.
40 \code
40 \code
41 QChartView *chartView = new QChartView;
41 QChartView *chartView = new QChartView;
42 QLineSeries *series = new QLineSeries;
42 QLineSeries *series = new QLineSeries;
43 // ...
43 // ...
44 chartView->chart()->addSeries(series);
44 chartView->chart()->addSeries(series);
45
45
46 QValueAxis *axisX = new QValueAxis;
46 QValueAxis *axisX = new QValueAxis;
47 axisX->setRange(10, 20.5);
47 axisX->setRange(10, 20.5);
48 axisX->setTickCount(10);
48 axisX->setTickCount(10);
49 axisX->setLabelFormat("%.2f");
49 axisX->setLabelFormat("%.2f");
50 chartView->chart()->setAxisX(axisX, series);
50 chartView->chart()->setAxisX(axisX, series);
51 \endcode
51 \endcode
52 */
52 */
53
53
54 /*!
54 /*!
55 \qmlclass ValueAxis QValueAxis
55 \qmlclass ValueAxis QValueAxis
56 \inherits AbstractAxis
56 \inherits AbstractAxis
57 \brief The ValueAxis element is used for manipulating chart's axes
57 \brief The ValueAxis element is used for manipulating chart's axes
58
58
59 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
59 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
60 Values of axis are drawn to position of ticks
60 Values of axis are drawn to position of ticks
61
61
62 To access Axes you can use ChartView API. For example:
62 To access Axes you can use ChartView API. For example:
63 \code
63 \code
64 ChartView {
64 ChartView {
65 ValueAxis {
65 ValueAxis {
66 id: xAxis
66 id: xAxis
67 min: 0
67 min: 0
68 max: 10
68 max: 10
69 }
69 }
70 // Add a few series...
70 // Add a few series...
71 }
71 }
72 \endcode
72 \endcode
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QValueAxis::min
76 \property QValueAxis::min
77 Defines the minimum value on the axis.
77 Defines the minimum value on the axis.
78 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
78 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty real ValueAxis::min
81 \qmlproperty real ValueAxis::min
82 Defines the minimum value on the axis.
82 Defines the minimum value on the axis.
83 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
83 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
84 */
84 */
85
85
86 /*!
86 /*!
87 \property QValueAxis::max
87 \property QValueAxis::max
88 Defines the maximum value on the axis.
88 Defines the maximum value on the axis.
89 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
89 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty real ValueAxis::max
92 \qmlproperty real ValueAxis::max
93 Defines the maximum value on the axis.
93 Defines the maximum value on the axis.
94 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
94 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
95 */
95 */
96
96
97 /*!
97 /*!
98 \property QValueAxis::labelFormat
98 \property QValueAxis::labelFormat
99 Defines the label format for the axis.
99 Defines the label format for the axis.
100 See QString::sprintf() for the details.
100 See QString::sprintf() for the details.
101 */
101 */
102 /*!
102 /*!
103 \qmlproperty real ValueAxis::labelFormat
103 \qmlproperty real ValueAxis::labelFormat
104 Defines the label format for the axis.
104 Defines the label format for the axis.
105 See QString::sprintf() for the details.
105 See QString::sprintf() for the details.
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QValueAxis::minChanged(qreal min)
109 \fn void QValueAxis::minChanged(qreal min)
110 Axis emits signal when \a min of axis has changed.
110 Axis emits signal when \a min of axis has changed.
111 */
111 */
112 /*!
112 /*!
113 \qmlsignal ValueAxis::onMinChanged(real min)
113 \qmlsignal ValueAxis::onMinChanged(real min)
114 Axis emits signal when \a min of axis has changed.
114 Axis emits signal when \a min of axis has changed.
115 */
115 */
116
116
117 /*!
117 /*!
118 \fn void QValueAxis::maxChanged(qreal max)
118 \fn void QValueAxis::maxChanged(qreal max)
119 Axis emits signal when \a max of axis has changed.
119 Axis emits signal when \a max of axis has changed.
120 */
120 */
121 /*!
121 /*!
122 \qmlsignal ValueAxis::onMaxChanged(real max)
122 \qmlsignal ValueAxis::onMaxChanged(real max)
123 Axis emits signal when \a max of axis has changed.
123 Axis emits signal when \a max of axis has changed.
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
127 \fn void QValueAxis::rangeChanged(qreal min, qreal max)
128 Axis emits signal when \a min or \a max of axis has changed.
128 Axis emits signal when \a min or \a max of axis has changed.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QValueAxis::tickCount
132 \property QValueAxis::tickCount
133 The number of tick marks for the axis.
133 The number of tick marks for the axis.
134 */
134 */
135
135
136 /*!
136 /*!
137 \qmlproperty int ValueAxis::tickCount
137 \qmlproperty int ValueAxis::tickCount
138 The number of tick marks for the axis.
138 The number of tick marks for the axis.
139 */
139 */
140
140
141 /*!
141 /*!
142 \property QValueAxis::niceNumbersEnabled
142 \property QValueAxis::niceNumbersEnabled
143 Whether the nice numbers algorithm is enabled or not for the axis.
143 Whether the nice numbers algorithm is enabled or not for the axis.
144 */
144 */
145
145
146 /*!
146 /*!
147 \qmlproperty bool ValueAxis::niceNumbersEnabled
147 \qmlproperty bool ValueAxis::niceNumbersEnabled
148 Whether the nice numbers algorithm is enabled or not for the axis.
148 Whether the nice numbers algorithm is enabled or not for the axis.
149 */
149 */
150
150
151 /*!
151 /*!
152 Constructs an axis object which is a child of \a parent.
152 Constructs an axis object which is a child of \a parent.
153 */
153 */
154 QValueAxis::QValueAxis(QObject *parent) :
154 QValueAxis::QValueAxis(QObject *parent) :
155 QAbstractAxis(*new QValueAxisPrivate(this), parent)
155 QAbstractAxis(*new QValueAxisPrivate(this), parent)
156 {
156 {
157
157
158 }
158 }
159
159
160 /*!
160 /*!
161 \internal
161 \internal
162 */
162 */
163 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
163 QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent)
164 : QAbstractAxis(d, parent)
164 : QAbstractAxis(d, parent)
165 {
165 {
166
166
167 }
167 }
168
168
169 /*!
169 /*!
170 Destroys the object
170 Destroys the object
171 */
171 */
172 QValueAxis::~QValueAxis()
172 QValueAxis::~QValueAxis()
173 {
173 {
174 Q_D(QValueAxis);
174 Q_D(QValueAxis);
175 if (d->m_dataset)
175 if (d->m_dataset)
176 d->m_dataset->removeAxis(this);
176 d->m_dataset->removeAxis(this);
177 }
177 }
178
178
179 void QValueAxis::setMin(qreal min)
179 void QValueAxis::setMin(qreal min)
180 {
180 {
181 Q_D(QValueAxis);
181 Q_D(QValueAxis);
182 setRange(min, qMax(d->m_max, min));
182 setRange(min, qMax(d->m_max, min));
183 }
183 }
184
184
185 qreal QValueAxis::min() const
185 qreal QValueAxis::min() const
186 {
186 {
187 Q_D(const QValueAxis);
187 Q_D(const QValueAxis);
188 return d->m_min;
188 return d->m_min;
189 }
189 }
190
190
191 void QValueAxis::setMax(qreal max)
191 void QValueAxis::setMax(qreal max)
192 {
192 {
193 Q_D(QValueAxis);
193 Q_D(QValueAxis);
194 setRange(qMin(d->m_min, max), max);
194 setRange(qMin(d->m_min, max), max);
195 }
195 }
196
196
197 qreal QValueAxis::max() const
197 qreal QValueAxis::max() const
198 {
198 {
199 Q_D(const QValueAxis);
199 Q_D(const QValueAxis);
200 return d->m_max;
200 return d->m_max;
201 }
201 }
202
202
203 /*!
203 /*!
204 Sets range from \a min to \a max on the axis.
204 Sets range from \a min to \a max on the axis.
205 If min is greater than max then this function returns without making any changes.
205 If min is greater than max then this function returns without making any changes.
206 */
206 */
207 void QValueAxis::setRange(qreal min, qreal max)
207 void QValueAxis::setRange(qreal min, qreal max)
208 {
208 {
209 Q_D(QValueAxis);
209 Q_D(QValueAxis);
210 bool changed = false;
210 bool changed = false;
211
211
212 if (min > max)
212 if (min > max)
213 return;
213 return;
214
214
215 if (d->m_niceNumbers) {
215 if (d->m_niceNumbers) {
216 int ticks = d->m_tickCount;
216 int ticks = d->m_tickCount;
217 d->looseNiceNumbers(min, max, ticks);
217 d->looseNiceNumbers(min, max, ticks);
218 if (ticks != d->m_tickCount)
218 if (ticks != d->m_tickCount)
219 setTickCount(ticks);
219 setTickCount(ticks);
220 }
220 }
221
221
222 if (!qFuzzyIsNull(d->m_min - min)) {
222 if (!qFuzzyCompare(d->m_min, min)) {
223 d->m_min = min;
223 d->m_min = min;
224 changed = true;
224 changed = true;
225 emit minChanged(min);
225 emit minChanged(min);
226 }
226 }
227
227
228 if (!qFuzzyIsNull(d->m_max - max)) {
228 if (!qFuzzyCompare(d->m_max, max)) {
229 d->m_max = max;
229 d->m_max = max;
230 changed = true;
230 changed = true;
231 emit maxChanged(max);
231 emit maxChanged(max);
232 }
232 }
233
233
234 if (changed) {
234 if (changed) {
235 emit rangeChanged(min, max);
235 emit rangeChanged(min, max);
236 d->emitUpdated();
236 d->emitUpdated();
237 }
237 }
238 }
238 }
239
239
240 /*!
240 /*!
241 Sets \a count for ticks on the axis.
241 Sets \a count for ticks on the axis.
242 */
242 */
243 void QValueAxis::setTickCount(int count)
243 void QValueAxis::setTickCount(int count)
244 {
244 {
245 Q_D(QValueAxis);
245 Q_D(QValueAxis);
246 if (d->m_tickCount != count && count >= 2) {
246 if (d->m_tickCount != count && count >= 2) {
247 d->m_tickCount = count;
247 d->m_tickCount = count;
248 d->emitUpdated();
248 d->emitUpdated();
249 }
249 }
250 }
250 }
251
251
252 /*!
252 /*!
253 \fn int QValueAxis::tickCount() const
253 \fn int QValueAxis::tickCount() const
254 Return number of ticks on the axis
254 Return number of ticks on the axis
255 */
255 */
256 int QValueAxis::tickCount() const
256 int QValueAxis::tickCount() const
257 {
257 {
258 Q_D(const QValueAxis);
258 Q_D(const QValueAxis);
259 return d->m_tickCount;
259 return d->m_tickCount;
260 }
260 }
261
261
262 void QValueAxis::setNiceNumbersEnabled(bool enable)
262 void QValueAxis::setNiceNumbersEnabled(bool enable)
263 {
263 {
264 Q_D(QValueAxis);
264 Q_D(QValueAxis);
265 if (d->m_niceNumbers != enable) {
265 if (d->m_niceNumbers != enable) {
266 d->m_niceNumbers = enable;
266 d->m_niceNumbers = enable;
267 if (enable && !qFuzzyIsNull(d->m_max - d->m_min))
267 if (enable && !qFuzzyCompare(d->m_max, d->m_min))
268 setRange(d->m_min, d->m_max);
268 setRange(d->m_min, d->m_max);
269 }
269 }
270 }
270 }
271
271
272 bool QValueAxis::niceNumbersEnabled() const
272 bool QValueAxis::niceNumbersEnabled() const
273 {
273 {
274 Q_D(const QValueAxis);
274 Q_D(const QValueAxis);
275 return d->m_niceNumbers;
275 return d->m_niceNumbers;
276 }
276 }
277
277
278 void QValueAxis::setLabelFormat(const QString &format)
278 void QValueAxis::setLabelFormat(const QString &format)
279 {
279 {
280 Q_D(QValueAxis);
280 Q_D(QValueAxis);
281 d->m_format = format;
281 d->m_format = format;
282 }
282 }
283
283
284 QString QValueAxis::labelFormat() const
284 QString QValueAxis::labelFormat() const
285 {
285 {
286 Q_D(const QValueAxis);
286 Q_D(const QValueAxis);
287 return d->m_format;
287 return d->m_format;
288 }
288 }
289
289
290 /*!
290 /*!
291 Returns the type of the axis
291 Returns the type of the axis
292 */
292 */
293 QAbstractAxis::AxisType QValueAxis::type() const
293 QAbstractAxis::AxisType QValueAxis::type() const
294 {
294 {
295 return AxisTypeValue;
295 return AxisTypeValue;
296 }
296 }
297
297
298 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
298 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
299
299
300 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
300 QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q)
301 : QAbstractAxisPrivate(q),
301 : QAbstractAxisPrivate(q),
302 m_min(0),
302 m_min(0),
303 m_max(0),
303 m_max(0),
304 m_tickCount(5),
304 m_tickCount(5),
305 m_niceNumbers(false),
305 m_niceNumbers(false),
306 m_format(QString::null)
306 m_format(QString::null)
307 {
307 {
308
308
309 }
309 }
310
310
311 QValueAxisPrivate::~QValueAxisPrivate()
311 QValueAxisPrivate::~QValueAxisPrivate()
312 {
312 {
313
313
314 }
314 }
315
315
316 void QValueAxisPrivate::handleDomainUpdated()
316 void QValueAxisPrivate::handleDomainUpdated()
317 {
317 {
318 Q_Q(QValueAxis);
318 Q_Q(QValueAxis);
319 Domain *domain = qobject_cast<Domain *>(sender());
319 Domain *domain = qobject_cast<Domain *>(sender());
320 Q_ASSERT(domain);
320 Q_ASSERT(domain);
321
321
322 if (orientation() == Qt::Horizontal)
322 if (orientation() == Qt::Horizontal)
323 q->setRange(domain->minX(), domain->maxX());
323 q->setRange(domain->minX(), domain->maxX());
324 else if (orientation() == Qt::Vertical)
324 else if (orientation() == Qt::Vertical)
325 q->setRange(domain->minY(), domain->maxY());
325 q->setRange(domain->minY(), domain->maxY());
326 }
326 }
327
327
328
328
329 void QValueAxisPrivate::setMin(const QVariant &min)
329 void QValueAxisPrivate::setMin(const QVariant &min)
330 {
330 {
331 Q_Q(QValueAxis);
331 Q_Q(QValueAxis);
332 bool ok;
332 bool ok;
333 qreal value = min.toReal(&ok);
333 qreal value = min.toReal(&ok);
334 if (ok)
334 if (ok)
335 q->setMin(value);
335 q->setMin(value);
336 }
336 }
337
337
338 void QValueAxisPrivate::setMax(const QVariant &max)
338 void QValueAxisPrivate::setMax(const QVariant &max)
339 {
339 {
340
340
341 Q_Q(QValueAxis);
341 Q_Q(QValueAxis);
342 bool ok;
342 bool ok;
343 qreal value = max.toReal(&ok);
343 qreal value = max.toReal(&ok);
344 if (ok)
344 if (ok)
345 q->setMax(value);
345 q->setMax(value);
346 }
346 }
347
347
348 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
348 void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max)
349 {
349 {
350 Q_Q(QValueAxis);
350 Q_Q(QValueAxis);
351 bool ok1;
351 bool ok1;
352 bool ok2;
352 bool ok2;
353 qreal value1 = min.toReal(&ok1);
353 qreal value1 = min.toReal(&ok1);
354 qreal value2 = max.toReal(&ok2);
354 qreal value2 = max.toReal(&ok2);
355 if (ok1 && ok2)
355 if (ok1 && ok2)
356 q->setRange(value1, value2);
356 q->setRange(value1, value2);
357 }
357 }
358
358
359 ChartAxis *QValueAxisPrivate::createGraphics(ChartPresenter *presenter)
359 ChartAxis *QValueAxisPrivate::createGraphics(ChartPresenter *presenter)
360 {
360 {
361 Q_Q(QValueAxis);
361 Q_Q(QValueAxis);
362 if (m_orientation == Qt::Vertical)
362 if (m_orientation == Qt::Vertical)
363 return new ChartValueAxisY(q, presenter);
363 return new ChartValueAxisY(q, presenter);
364 return new ChartValueAxisX(q, presenter);
364 return new ChartValueAxisX(q, presenter);
365 }
365 }
366
366
367 void QValueAxisPrivate::intializeDomain(Domain *domain)
367 void QValueAxisPrivate::intializeDomain(Domain *domain)
368 {
368 {
369 Q_Q(QValueAxis);
369 Q_Q(QValueAxis);
370 if (qFuzzyCompare(m_max, m_min)) {
370 if (qFuzzyCompare(m_max, m_min)) {
371 if (m_orientation == Qt::Vertical)
371 if (m_orientation == Qt::Vertical)
372 q->setRange(domain->minY(), domain->maxY());
372 q->setRange(domain->minY(), domain->maxY());
373 else
373 else
374 q->setRange(domain->minX(), domain->maxX());
374 q->setRange(domain->minX(), domain->maxX());
375 } else {
375 } else {
376 if (m_orientation == Qt::Vertical)
376 if (m_orientation == Qt::Vertical)
377 domain->setRangeY(m_min, m_max);
377 domain->setRangeY(m_min, m_max);
378 else
378 else
379 domain->setRangeX(m_min, m_max);
379 domain->setRangeX(m_min, m_max);
380 }
380 }
381 }
381 }
382
382
383 //algorithm defined by Paul S.Heckbert GraphicalGems I
383 //algorithm defined by Paul S.Heckbert GraphicalGems I
384
384
385 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
385 void QValueAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
386 {
386 {
387 qreal range = niceNumber(max - min, true); //range with ceiling
387 qreal range = niceNumber(max - min, true); //range with ceiling
388 qreal step = niceNumber(range / (ticksCount - 1), false);
388 qreal step = niceNumber(range / (ticksCount - 1), false);
389 min = qFloor(min / step);
389 min = qFloor(min / step);
390 max = qCeil(max / step);
390 max = qCeil(max / step);
391 ticksCount = int(max - min) + 1;
391 ticksCount = int(max - min) + 1;
392 min *= step;
392 min *= step;
393 max *= step;
393 max *= step;
394 }
394 }
395
395
396 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
396 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
397
397
398 qreal QValueAxisPrivate::niceNumber(qreal x, bool ceiling) const
398 qreal QValueAxisPrivate::niceNumber(qreal x, bool ceiling) const
399 {
399 {
400 qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
400 qreal z = qPow(10, qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
401 qreal q = x / z; //q<10 && q>=1;
401 qreal q = x / z; //q<10 && q>=1;
402
402
403 if (ceiling) {
403 if (ceiling) {
404 if (q <= 1.0) q = 1;
404 if (q <= 1.0) q = 1;
405 else if (q <= 2.0) q = 2;
405 else if (q <= 2.0) q = 2;
406 else if (q <= 5.0) q = 5;
406 else if (q <= 5.0) q = 5;
407 else q = 10;
407 else q = 10;
408 } else {
408 } else {
409 if (q < 1.5) q = 1;
409 if (q < 1.5) q = 1;
410 else if (q < 3.0) q = 2;
410 else if (q < 3.0) q = 2;
411 else if (q < 7.0) q = 5;
411 else if (q < 7.0) q = 5;
412 else q = 10;
412 else q = 10;
413 }
413 }
414 return q * z;
414 return q * z;
415 }
415 }
416
416
417 #include "moc_qvalueaxis.cpp"
417 #include "moc_qvalueaxis.cpp"
418 #include "moc_qvalueaxis_p.cpp"
418 #include "moc_qvalueaxis_p.cpp"
419
419
420 QTCOMMERCIALCHART_END_NAMESPACE
420 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,95 +1,95
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 "horizontalbarchartitem_p.h"
21 #include "horizontalbarchartitem_p.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset_p.h"
23 #include "qbarset_p.h"
24 #include "bar_p.h"
24 #include "bar_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter)
28 HorizontalBarChartItem::HorizontalBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter)
29 : AbstractBarChartItem(series, presenter)
29 : AbstractBarChartItem(series, presenter)
30 {
30 {
31 }
31 }
32
32
33 QVector<QRectF> HorizontalBarChartItem::calculateLayout()
33 QVector<QRectF> HorizontalBarChartItem::calculateLayout()
34 {
34 {
35 QVector<QRectF> layout;
35 QVector<QRectF> layout;
36
36
37 // Use temporary qreals for accuracy
37 // Use temporary qreals for accuracy
38 qreal categoryCount = m_series->d_func()->categoryCount();
38 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal setCount = m_series->count();
39 qreal setCount = m_series->count();
40 bool barsVisible = m_series->isVisible();
40 bool barsVisible = m_series->isVisible();
41
41
42 // Domain:
42 // Domain:
43 qreal width = geometry().width();
43 qreal width = geometry().width();
44 qreal height = geometry().height();
44 qreal height = geometry().height();
45 qreal rangeY = m_domainMaxY - m_domainMinY;
45 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal scaleY = (height / rangeY);
47 qreal scaleY = (height / rangeY);
48 qreal scaleX = (width / rangeX);
48 qreal scaleX = (width / rangeX);
49
49
50 // On horizontal chart barWidth of the barseries means height of the rect.
50 // On horizontal chart barWidth of the barseries means height of the rect.
51 qreal rectHeight = (scaleY / setCount) * m_series->d_func()->barWidth();
51 qreal rectHeight = (scaleY / setCount) * m_series->d_func()->barWidth();
52
52
53 int itemIndex(0);
53 int itemIndex(0);
54 for (int category = 0; category < categoryCount; category++) {
54 for (int category = 0; category < categoryCount; category++) {
55 qreal xPos = -scaleX * m_domainMinX + geometry().left();
55 qreal xPos = -scaleX * m_domainMinX + geometry().left();
56 for (int set = 0; set < setCount; set++) {
56 for (int set = 0; set < setCount; set++) {
57 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
58
58
59 qreal yPos = geometry().bottom() + (m_domainMinY - barSet->pos(category)) * scaleY;
59 qreal yPos = geometry().bottom() + (m_domainMinY - barSet->pos(category)) * scaleY;
60 yPos += setCount * rectHeight / 2;
60 yPos += setCount * rectHeight / 2;
61 yPos -= set * rectHeight;
61 yPos -= set * rectHeight;
62
62
63 qreal rectWidth = barSet->value(category) * scaleX;
63 qreal rectWidth = barSet->value(category) * scaleX;
64 Bar *bar = m_bars.at(itemIndex);
64 Bar *bar = m_bars.at(itemIndex);
65
65
66 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
66 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
67 layout.append(rect);
67 layout.append(rect);
68 bar->setPen(barSet->m_pen);
68 bar->setPen(barSet->m_pen);
69 bar->setBrush(barSet->m_brush);
69 bar->setBrush(barSet->m_brush);
70 if (qFuzzyIsNull(rectHeight))
70 if (qFuzzyCompare(rectHeight, 0))
71 bar->setVisible(false);
71 bar->setVisible(false);
72 else
72 else
73 bar->setVisible(barsVisible);
73 bar->setVisible(barsVisible);
74
74
75 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
75 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
76
76
77 if (!qFuzzyIsNull(barSet->value(category)))
77 if (!qFuzzyCompare(barSet->value(category), 0))
78 label->setText(QString::number(barSet->value(category)));
78 label->setText(QString::number(barSet->value(category)));
79 else
79 else
80 label->setText(QString(""));
80 label->setText(QString(""));
81
81
82 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
82 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
83 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
83 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
84 label->setFont(barSet->m_labelFont);
84 label->setFont(barSet->m_labelFont);
85 label->setBrush(barSet->m_labelBrush);
85 label->setBrush(barSet->m_labelBrush);
86
86
87 itemIndex++;
87 itemIndex++;
88 }
88 }
89 }
89 }
90 return layout;
90 return layout;
91 }
91 }
92
92
93 #include "moc_horizontalbarchartitem_p.cpp"
93 #include "moc_horizontalbarchartitem_p.cpp"
94
94
95 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,100 +1,100
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 "horizontalpercentbarchartitem_p.h"
21 #include "horizontalpercentbarchartitem_p.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset_p.h"
23 #include "qbarset_p.h"
24 #include "bar_p.h"
24 #include "bar_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter)
28 HorizontalPercentBarChartItem::HorizontalPercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter)
29 : AbstractBarChartItem(series, presenter)
29 : AbstractBarChartItem(series, presenter)
30 {
30 {
31 }
31 }
32
32
33 QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
33 QVector<QRectF> HorizontalPercentBarChartItem::calculateLayout()
34 {
34 {
35 QVector<QRectF> layout;
35 QVector<QRectF> layout;
36
36
37 // Use temporary qreals for accuracy
37 // Use temporary qreals for accuracy
38 qreal categoryCount = m_series->d_func()->categoryCount();
38 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal setCount = m_series->count();
39 qreal setCount = m_series->count();
40 bool barsVisible = m_series->isVisible();
40 bool barsVisible = m_series->isVisible();
41
41
42 // Domain:
42 // Domain:
43 qreal width = geometry().width();
43 qreal width = geometry().width();
44 qreal height = geometry().height();
44 qreal height = geometry().height();
45 qreal rangeY = m_domainMaxY - m_domainMinY;
45 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal scaleY = (height / rangeY);
47 qreal scaleY = (height / rangeY);
48 qreal scaleX = (width / rangeX);
48 qreal scaleX = (width / rangeX);
49 qreal rectHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
49 qreal rectHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
50
50
51 int itemIndex(0);
51 int itemIndex(0);
52 for (int category = 0; category < categoryCount; category++) {
52 for (int category = 0; category < categoryCount; category++) {
53 qreal colSum = m_series->d_func()->categorySum(category);
53 qreal colSum = m_series->d_func()->categorySum(category);
54 qreal percentage = (100 / colSum);
54 qreal percentage = (100 / colSum);
55 qreal xPos = -scaleX * m_domainMinX + geometry().left();
55 qreal xPos = -scaleX * m_domainMinX + geometry().left();
56 for (int set = 0; set < setCount; set++) {
56 for (int set = 0; set < setCount; set++) {
57 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
58
58
59 qreal yPos = (m_domainMinY + 0.5 - barSet->pos(category)) * scaleY + geometry().bottom() - rectHeight / 2;
59 qreal yPos = (m_domainMinY + 0.5 - barSet->pos(category)) * scaleY + geometry().bottom() - rectHeight / 2;
60
60
61 qreal rectWidth = barSet->value(category) * percentage * scaleX;
61 qreal rectWidth = barSet->value(category) * percentage * scaleX;
62 Bar *bar = m_bars.at(itemIndex);
62 Bar *bar = m_bars.at(itemIndex);
63
63
64 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
64 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
65 layout.append(rect);
65 layout.append(rect);
66 bar->setPen(barSet->m_pen);
66 bar->setPen(barSet->m_pen);
67 bar->setBrush(barSet->m_brush);
67 bar->setBrush(barSet->m_brush);
68 if (qFuzzyIsNull(rectHeight))
68 if (qFuzzyCompare(rectHeight, 0))
69 bar->setVisible(false);
69 bar->setVisible(false);
70 else
70 else
71 bar->setVisible(barsVisible);
71 bar->setVisible(barsVisible);
72
72
73 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
73 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
74
74
75 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set, category))) {
75 if (!qFuzzyCompare(m_series->d_func()->valueAt(set, category), 0)) {
76 int p = m_series->d_func()->percentageAt(set, category) * 100;
76 int p = m_series->d_func()->percentageAt(set, category) * 100;
77 QString vString(QString::number(p));
77 QString vString(QString::number(p));
78 vString.truncate(3);
78 vString.truncate(3);
79 vString.append("%");
79 vString.append("%");
80 label->setText(vString);
80 label->setText(vString);
81 } else {
81 } else {
82 label->setText(QString(""));
82 label->setText(QString(""));
83 }
83 }
84
84
85 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
85 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
86 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
86 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
87 label->setFont(barSet->m_labelFont);
87 label->setFont(barSet->m_labelFont);
88 label->setBrush(barSet->m_labelBrush);
88 label->setBrush(barSet->m_labelBrush);
89
89
90 itemIndex++;
90 itemIndex++;
91 xPos += rectWidth;
91 xPos += rectWidth;
92 }
92 }
93 }
93 }
94 return layout;
94 return layout;
95 }
95 }
96
96
97 #include "moc_horizontalpercentbarchartitem_p.cpp"
97 #include "moc_horizontalpercentbarchartitem_p.cpp"
98
98
99 QTCOMMERCIALCHART_END_NAMESPACE
99 QTCOMMERCIALCHART_END_NAMESPACE
100
100
@@ -1,101 +1,101
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 "horizontalstackedbarchartitem_p.h"
21 #include "horizontalstackedbarchartitem_p.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset_p.h"
23 #include "qbarset_p.h"
24 #include "bar_p.h"
24 #include "bar_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter)
28 HorizontalStackedBarChartItem::HorizontalStackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter)
29 : AbstractBarChartItem(series, presenter)
29 : AbstractBarChartItem(series, presenter)
30 {
30 {
31 }
31 }
32
32
33 QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
33 QVector<QRectF> HorizontalStackedBarChartItem::calculateLayout()
34 {
34 {
35 QVector<QRectF> layout;
35 QVector<QRectF> layout;
36
36
37 // Use temporary qreals for accuracy
37 // Use temporary qreals for accuracy
38 qreal categoryCount = m_series->d_func()->categoryCount();
38 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal setCount = m_series->count();
39 qreal setCount = m_series->count();
40 bool barsVisible = m_series->isVisible();
40 bool barsVisible = m_series->isVisible();
41
41
42 // Domain:
42 // Domain:
43 qreal width = geometry().width();
43 qreal width = geometry().width();
44 qreal height = geometry().height();
44 qreal height = geometry().height();
45 qreal rangeY = m_domainMaxY - m_domainMinY;
45 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal scaleY = (height / rangeY);
47 qreal scaleY = (height / rangeY);
48 qreal scaleX = (width / rangeX);
48 qreal scaleX = (width / rangeX);
49 qreal rectHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
49 qreal rectHeight = scaleY * m_series->d_func()->barWidth(); // On horizontal chart barWidth of the barseries means height of the rect.
50
50
51 int itemIndex(0);
51 int itemIndex(0);
52 for (int category = 0; category < categoryCount; category++) {
52 for (int category = 0; category < categoryCount; category++) {
53 qreal xMax = -scaleX * m_domainMinX + geometry().left();
53 qreal xMax = -scaleX * m_domainMinX + geometry().left();
54 qreal xMin = -scaleX * m_domainMinX + geometry().left();
54 qreal xMin = -scaleX * m_domainMinX + geometry().left();
55 for (int set = 0; set < setCount; set++) {
55 for (int set = 0; set < setCount; set++) {
56 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
56 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57
57
58 qreal yPos = (m_domainMinY + 0.5 - barSet->pos(category)) * scaleY + geometry().bottom() - rectHeight / 2;
58 qreal yPos = (m_domainMinY + 0.5 - barSet->pos(category)) * scaleY + geometry().bottom() - rectHeight / 2;
59
59
60 qreal rectWidth = barSet->value(category) * scaleX;
60 qreal rectWidth = barSet->value(category) * scaleX;
61 Bar *bar = m_bars.at(itemIndex);
61 Bar *bar = m_bars.at(itemIndex);
62
62
63 bar->setPen(barSet->m_pen);
63 bar->setPen(barSet->m_pen);
64 bar->setBrush(barSet->m_brush);
64 bar->setBrush(barSet->m_brush);
65 if (qFuzzyIsNull(rectHeight))
65 if (qFuzzyCompare(rectHeight, 0))
66 bar->setVisible(false);
66 bar->setVisible(false);
67 else
67 else
68 bar->setVisible(barsVisible);
68 bar->setVisible(barsVisible);
69
69
70 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
70 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
71
71
72 if (!qFuzzyIsNull(barSet->value(category)))
72 if (!qFuzzyCompare(barSet->value(category), 0))
73 label->setText(QString::number(barSet->value(category)));
73 label->setText(QString::number(barSet->value(category)));
74 else
74 else
75 label->setText(QString(""));
75 label->setText(QString(""));
76 label->setFont(barSet->m_labelFont);
76 label->setFont(barSet->m_labelFont);
77 label->setBrush(barSet->m_labelBrush);
77 label->setBrush(barSet->m_labelBrush);
78
78
79 if (rectWidth > 0) {
79 if (rectWidth > 0) {
80 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
80 QRectF rect(xMax, yPos - rectHeight, rectWidth, rectHeight);
81 layout.append(rect);
81 layout.append(rect);
82 label->setPos(xMax + (rect.width() / 2 - label->boundingRect().width() / 2),
82 label->setPos(xMax + (rect.width() / 2 - label->boundingRect().width() / 2),
83 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
83 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
84 xMax += rectWidth;
84 xMax += rectWidth;
85 } else {
85 } else {
86 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
86 QRectF rect(xMin, yPos - rectHeight, rectWidth, rectHeight);
87 layout.append(rect);
87 layout.append(rect);
88 label->setPos(xMin + (rect.width() / 2 - label->boundingRect().width() / 2),
88 label->setPos(xMin + (rect.width() / 2 - label->boundingRect().width() / 2),
89 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
89 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
90 xMin += rectWidth;
90 xMin += rectWidth;
91 }
91 }
92 itemIndex++;
92 itemIndex++;
93 }
93 }
94 }
94 }
95 return layout;
95 return layout;
96 }
96 }
97
97
98 #include "moc_horizontalstackedbarchartitem_p.cpp"
98 #include "moc_horizontalstackedbarchartitem_p.cpp"
99
99
100 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
101
101
@@ -1,812 +1,812
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 "qabstractbarseries.h"
21 #include "qabstractbarseries.h"
22 #include "qabstractbarseries_p.h"
22 #include "qabstractbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qvalueaxis.h"
28 #include "qvalueaxis.h"
29 #include "qbarcategoryaxis.h"
29 #include "qbarcategoryaxis.h"
30 #include "qbarlegendmarker.h"
30 #include "qbarlegendmarker.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 /*!
34 /*!
35 \class QAbstractBarSeries
35 \class QAbstractBarSeries
36 \brief Series for creating a bar chart
36 \brief Series for creating a bar chart
37 \mainclass
37 \mainclass
38
38
39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 shows the x-values.
42 shows the x-values.
43
43
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 \image examples_barchart.png
45 \image examples_barchart.png
46
46
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 */
48 */
49 /*!
49 /*!
50 \qmlclass AbstractBarSeries QAbstractBarSeries
50 \qmlclass AbstractBarSeries QAbstractBarSeries
51 \inherits QAbstractSeries
51 \inherits QAbstractSeries
52
52
53 The following QML shows how to create a simple bar chart:
53 The following QML shows how to create a simple bar chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
54 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55
55
56 \beginfloatleft
56 \beginfloatleft
57 \image demos_qmlchart6.png
57 \image demos_qmlchart6.png
58 \endfloat
58 \endfloat
59 \clearfloat
59 \clearfloat
60 */
60 */
61
61
62 /*!
62 /*!
63 \property QAbstractBarSeries::barWidth
63 \property QAbstractBarSeries::barWidth
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
64 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
65 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
66 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
67 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 \sa QBarSeries
68 \sa QBarSeries
69 */
69 */
70 /*!
70 /*!
71 \qmlproperty real AbstractBarSeries::barWidth
71 \qmlproperty real AbstractBarSeries::barWidth
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
72 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
73 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
74 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
75 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
76 */
76 */
77
77
78 /*!
78 /*!
79 \property QAbstractBarSeries::count
79 \property QAbstractBarSeries::count
80 Holds the number of sets in series.
80 Holds the number of sets in series.
81 */
81 */
82 /*!
82 /*!
83 \qmlproperty int AbstractBarSeries::count
83 \qmlproperty int AbstractBarSeries::count
84 Holds the number of sets in series.
84 Holds the number of sets in series.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QAbstractBarSeries::labelsVisible
88 \property QAbstractBarSeries::labelsVisible
89 Defines the visibility of the labels in series
89 Defines the visibility of the labels in series
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty bool AbstractBarSeries::labelsVisible
92 \qmlproperty bool AbstractBarSeries::labelsVisible
93 Defines the visibility of the labels in series
93 Defines the visibility of the labels in series
94 */
94 */
95
95
96 /*!
96 /*!
97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
97 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 Clicked bar inside set is indexed by \a index
99 Clicked bar inside set is indexed by \a index
100 */
100 */
101 /*!
101 /*!
102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
102 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
104 Clicked bar inside set is indexed by \a index
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
108 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109
109
110 The signal is emitted if mouse is hovered on top of series.
110 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
111 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
113 */
114 /*!
114 /*!
115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
115 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116
116
117 The signal is emitted if mouse is hovered on top of series.
117 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
118 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QAbstractBarSeries::countChanged()
123 \fn void QAbstractBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal AbstractBarSeries::onCountChanged()
127 \qmlsignal AbstractBarSeries::onCountChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
128 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
129 */
130
130
131 /*!
131 /*!
132 \fn void QAbstractBarSeries::labelsVisibleChanged()
132 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
133 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
134 \sa isLabelsVisible(), setLabelsVisible()
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
138 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
139 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
140 \sa append(), insert()
141 */
141 */
142 /*!
142 /*!
143 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
143 \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset)
144 Emitted when \a barset has been added to the series.
144 Emitted when \a barset has been added to the series.
145 */
145 */
146
146
147 /*!
147 /*!
148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
148 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 This signal is emitted when \a sets have been removed from the series.
149 This signal is emitted when \a sets have been removed from the series.
150 \sa remove()
150 \sa remove()
151 */
151 */
152 /*!
152 /*!
153 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
153 \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset)
154 Emitted when \a barset has been removed from the series.
154 Emitted when \a barset has been removed from the series.
155 */
155 */
156
156
157 /*!
157 /*!
158 \qmlmethod BarSet AbstractBarSeries::at(int index)
158 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 Returns bar set at \a index. Returns null if the index is not valid.
159 Returns bar set at \a index. Returns null if the index is not valid.
160 */
160 */
161
161
162 /*!
162 /*!
163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
163 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
164 Adds a new bar set with \a label and \a values to \a index. Values is a list of reals.
165 For example:
165 For example:
166 \code
166 \code
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
167 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 \endcode
168 \endcode
169 */
169 */
170
170
171 /*!
171 /*!
172 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
172 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
173 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
173 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
174 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
174 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
175 appended.
175 appended.
176 \sa AbstractBarSeries::append()
176 \sa AbstractBarSeries::append()
177 */
177 */
178
178
179 /*!
179 /*!
180 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
180 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
181 Removes the barset from the series. Returns true if successful, false otherwise.
181 Removes the barset from the series. Returns true if successful, false otherwise.
182 */
182 */
183
183
184 /*!
184 /*!
185 \qmlmethod AbstractBarSeries::clear()
185 \qmlmethod AbstractBarSeries::clear()
186 Removes all barsets from the series.
186 Removes all barsets from the series.
187 */
187 */
188
188
189 /*!
189 /*!
190 Destructs abstractbarseries and owned barsets.
190 Destructs abstractbarseries and owned barsets.
191 */
191 */
192 QAbstractBarSeries::~QAbstractBarSeries()
192 QAbstractBarSeries::~QAbstractBarSeries()
193 {
193 {
194
194
195 }
195 }
196
196
197 /*!
197 /*!
198 \internal
198 \internal
199 */
199 */
200 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
200 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
201 : QAbstractSeries(o, parent)
201 : QAbstractSeries(o, parent)
202 {
202 {
203 Q_D(QAbstractSeries);
203 Q_D(QAbstractSeries);
204 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
204 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
205 }
205 }
206
206
207 /*!
207 /*!
208 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
208 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
209 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
209 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
210 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
210 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
211 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
211 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
212 */
212 */
213 void QAbstractBarSeries::setBarWidth(qreal width)
213 void QAbstractBarSeries::setBarWidth(qreal width)
214 {
214 {
215 Q_D(QAbstractBarSeries);
215 Q_D(QAbstractBarSeries);
216 d->setBarWidth(width);
216 d->setBarWidth(width);
217 }
217 }
218
218
219 /*!
219 /*!
220 Returns the width of the bars of the series.
220 Returns the width of the bars of the series.
221 \sa setBarWidth()
221 \sa setBarWidth()
222 */
222 */
223 qreal QAbstractBarSeries::barWidth() const
223 qreal QAbstractBarSeries::barWidth() const
224 {
224 {
225 Q_D(const QAbstractBarSeries);
225 Q_D(const QAbstractBarSeries);
226 return d->barWidth();
226 return d->barWidth();
227 }
227 }
228
228
229 /*!
229 /*!
230 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
230 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
231 Returns true, if appending succeeded.
231 Returns true, if appending succeeded.
232 */
232 */
233 bool QAbstractBarSeries::append(QBarSet *set)
233 bool QAbstractBarSeries::append(QBarSet *set)
234 {
234 {
235 Q_D(QAbstractBarSeries);
235 Q_D(QAbstractBarSeries);
236 bool success = d->append(set);
236 bool success = d->append(set);
237 if (success) {
237 if (success) {
238 QList<QBarSet *> sets;
238 QList<QBarSet *> sets;
239 sets.append(set);
239 sets.append(set);
240 set->setParent(this);
240 set->setParent(this);
241 emit barsetsAdded(sets);
241 emit barsetsAdded(sets);
242 emit countChanged();
242 emit countChanged();
243 }
243 }
244 return success;
244 return success;
245 }
245 }
246
246
247 /*!
247 /*!
248 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
248 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
249 was successful.
249 was successful.
250 Returns true, if set was removed.
250 Returns true, if set was removed.
251 */
251 */
252 bool QAbstractBarSeries::remove(QBarSet *set)
252 bool QAbstractBarSeries::remove(QBarSet *set)
253 {
253 {
254 Q_D(QAbstractBarSeries);
254 Q_D(QAbstractBarSeries);
255 bool success = d->remove(set);
255 bool success = d->remove(set);
256 if (success) {
256 if (success) {
257 QList<QBarSet *> sets;
257 QList<QBarSet *> sets;
258 sets.append(set);
258 sets.append(set);
259 set->setParent(0);
259 set->setParent(0);
260 emit barsetsRemoved(sets);
260 emit barsetsRemoved(sets);
261 emit countChanged();
261 emit countChanged();
262 delete set;
262 delete set;
263 set = 0;
263 set = 0;
264 }
264 }
265 return success;
265 return success;
266 }
266 }
267
267
268 /*!
268 /*!
269 Takes a single \a set from the series. Does not delete the barset object.
269 Takes a single \a set from the series. Does not delete the barset object.
270
270
271 NOTE: The series remains as the barset's parent object. You must set the
271 NOTE: The series remains as the barset's parent object. You must set the
272 parent object to take full ownership.
272 parent object to take full ownership.
273
273
274 Returns true if take was successful.
274 Returns true if take was successful.
275 */
275 */
276 bool QAbstractBarSeries::take(QBarSet *set)
276 bool QAbstractBarSeries::take(QBarSet *set)
277 {
277 {
278 Q_D(QAbstractBarSeries);
278 Q_D(QAbstractBarSeries);
279 bool success = d->remove(set);
279 bool success = d->remove(set);
280 if (success) {
280 if (success) {
281 QList<QBarSet *> sets;
281 QList<QBarSet *> sets;
282 sets.append(set);
282 sets.append(set);
283 emit barsetsRemoved(sets);
283 emit barsetsRemoved(sets);
284 emit countChanged();
284 emit countChanged();
285 }
285 }
286 return success;
286 return success;
287 }
287 }
288
288
289 /*!
289 /*!
290 Adds a list of barsets to series. Takes ownership of \a sets.
290 Adds a list of barsets to series. Takes ownership of \a sets.
291 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
291 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
292 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
292 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
293 and function returns false.
293 and function returns false.
294 */
294 */
295 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
295 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
296 {
296 {
297 Q_D(QAbstractBarSeries);
297 Q_D(QAbstractBarSeries);
298 bool success = d->append(sets);
298 bool success = d->append(sets);
299 if (success) {
299 if (success) {
300 emit barsetsAdded(sets);
300 emit barsetsAdded(sets);
301 emit countChanged();
301 emit countChanged();
302 }
302 }
303 return success;
303 return success;
304 }
304 }
305
305
306 /*!
306 /*!
307 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
307 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
308 Returns true, if inserting succeeded.
308 Returns true, if inserting succeeded.
309
309
310 */
310 */
311 bool QAbstractBarSeries::insert(int index, QBarSet *set)
311 bool QAbstractBarSeries::insert(int index, QBarSet *set)
312 {
312 {
313 Q_D(QAbstractBarSeries);
313 Q_D(QAbstractBarSeries);
314 bool success = d->insert(index, set);
314 bool success = d->insert(index, set);
315 if (success) {
315 if (success) {
316 QList<QBarSet *> sets;
316 QList<QBarSet *> sets;
317 sets.append(set);
317 sets.append(set);
318 emit barsetsAdded(sets);
318 emit barsetsAdded(sets);
319 emit countChanged();
319 emit countChanged();
320 }
320 }
321 return success;
321 return success;
322 }
322 }
323
323
324 /*!
324 /*!
325 Removes all barsets from the series. Deletes removed sets.
325 Removes all barsets from the series. Deletes removed sets.
326 */
326 */
327 void QAbstractBarSeries::clear()
327 void QAbstractBarSeries::clear()
328 {
328 {
329 Q_D(QAbstractBarSeries);
329 Q_D(QAbstractBarSeries);
330 QList<QBarSet *> sets = barSets();
330 QList<QBarSet *> sets = barSets();
331 bool success = d->remove(sets);
331 bool success = d->remove(sets);
332 if (success) {
332 if (success) {
333 emit barsetsRemoved(sets);
333 emit barsetsRemoved(sets);
334 emit countChanged();
334 emit countChanged();
335 foreach (QBarSet *set, sets)
335 foreach (QBarSet *set, sets)
336 delete set;
336 delete set;
337 }
337 }
338 }
338 }
339
339
340 /*!
340 /*!
341 Returns number of sets in series.
341 Returns number of sets in series.
342 */
342 */
343 int QAbstractBarSeries::count() const
343 int QAbstractBarSeries::count() const
344 {
344 {
345 Q_D(const QAbstractBarSeries);
345 Q_D(const QAbstractBarSeries);
346 return d->m_barSets.count();
346 return d->m_barSets.count();
347 }
347 }
348
348
349 /*!
349 /*!
350 Returns a list of sets in series. Keeps ownership of sets.
350 Returns a list of sets in series. Keeps ownership of sets.
351 */
351 */
352 QList<QBarSet *> QAbstractBarSeries::barSets() const
352 QList<QBarSet *> QAbstractBarSeries::barSets() const
353 {
353 {
354 Q_D(const QAbstractBarSeries);
354 Q_D(const QAbstractBarSeries);
355 return d->m_barSets;
355 return d->m_barSets;
356 }
356 }
357
357
358 /*!
358 /*!
359 Sets the visibility of labels in series to \a visible
359 Sets the visibility of labels in series to \a visible
360 */
360 */
361 void QAbstractBarSeries::setLabelsVisible(bool visible)
361 void QAbstractBarSeries::setLabelsVisible(bool visible)
362 {
362 {
363 Q_D(QAbstractBarSeries);
363 Q_D(QAbstractBarSeries);
364 if (d->m_labelsVisible != visible) {
364 if (d->m_labelsVisible != visible) {
365 d->setLabelsVisible(visible);
365 d->setLabelsVisible(visible);
366 emit labelsVisibleChanged();
366 emit labelsVisibleChanged();
367 }
367 }
368 }
368 }
369
369
370 /*!
370 /*!
371 Returns the visibility of labels
371 Returns the visibility of labels
372 */
372 */
373 bool QAbstractBarSeries::isLabelsVisible() const
373 bool QAbstractBarSeries::isLabelsVisible() const
374 {
374 {
375 Q_D(const QAbstractBarSeries);
375 Q_D(const QAbstractBarSeries);
376 return d->m_labelsVisible;
376 return d->m_labelsVisible;
377 }
377 }
378
378
379 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
379 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
380
380
381 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
381 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
382 QAbstractSeriesPrivate(q),
382 QAbstractSeriesPrivate(q),
383 m_barWidth(0.5), // Default value is 50% of category width
383 m_barWidth(0.5), // Default value is 50% of category width
384 m_labelsVisible(false),
384 m_labelsVisible(false),
385 m_visible(true)
385 m_visible(true)
386 {
386 {
387 }
387 }
388
388
389 int QAbstractBarSeriesPrivate::categoryCount() const
389 int QAbstractBarSeriesPrivate::categoryCount() const
390 {
390 {
391 // No categories defined. return count of longest set.
391 // No categories defined. return count of longest set.
392 int count = 0;
392 int count = 0;
393 for (int i = 0; i < m_barSets.count(); i++) {
393 for (int i = 0; i < m_barSets.count(); i++) {
394 if (m_barSets.at(i)->count() > count)
394 if (m_barSets.at(i)->count() > count)
395 count = m_barSets.at(i)->count();
395 count = m_barSets.at(i)->count();
396 }
396 }
397
397
398 return count;
398 return count;
399 }
399 }
400
400
401 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
401 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
402 {
402 {
403 if (width < 0.0)
403 if (width < 0.0)
404 width = 0.0;
404 width = 0.0;
405 m_barWidth = width;
405 m_barWidth = width;
406 emit updatedLayout();
406 emit updatedLayout();
407 }
407 }
408
408
409 qreal QAbstractBarSeriesPrivate::barWidth() const
409 qreal QAbstractBarSeriesPrivate::barWidth() const
410 {
410 {
411 return m_barWidth;
411 return m_barWidth;
412 }
412 }
413
413
414 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
414 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
415 {
415 {
416 return m_barSets.at(index);
416 return m_barSets.at(index);
417 }
417 }
418
418
419 void QAbstractBarSeriesPrivate::setVisible(bool visible)
419 void QAbstractBarSeriesPrivate::setVisible(bool visible)
420 {
420 {
421 m_visible = visible;
421 m_visible = visible;
422 emit visibleChanged();
422 emit visibleChanged();
423 }
423 }
424
424
425 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
425 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
426 {
426 {
427 m_labelsVisible = visible;
427 m_labelsVisible = visible;
428 emit labelsVisibleChanged(visible);
428 emit labelsVisibleChanged(visible);
429 }
429 }
430
430
431 qreal QAbstractBarSeriesPrivate::min()
431 qreal QAbstractBarSeriesPrivate::min()
432 {
432 {
433 if (m_barSets.count() <= 0)
433 if (m_barSets.count() <= 0)
434 return 0;
434 return 0;
435
435
436 qreal min = INT_MAX;
436 qreal min = INT_MAX;
437
437
438 for (int i = 0; i < m_barSets.count(); i++) {
438 for (int i = 0; i < m_barSets.count(); i++) {
439 int categoryCount = m_barSets.at(i)->count();
439 int categoryCount = m_barSets.at(i)->count();
440 for (int j = 0; j < categoryCount; j++) {
440 for (int j = 0; j < categoryCount; j++) {
441 qreal temp = m_barSets.at(i)->at(j);
441 qreal temp = m_barSets.at(i)->at(j);
442 if (temp < min)
442 if (temp < min)
443 min = temp;
443 min = temp;
444 }
444 }
445 }
445 }
446 return min;
446 return min;
447 }
447 }
448
448
449 qreal QAbstractBarSeriesPrivate::max()
449 qreal QAbstractBarSeriesPrivate::max()
450 {
450 {
451 if (m_barSets.count() <= 0)
451 if (m_barSets.count() <= 0)
452 return 0;
452 return 0;
453
453
454 qreal max = INT_MIN;
454 qreal max = INT_MIN;
455
455
456 for (int i = 0; i < m_barSets.count(); i++) {
456 for (int i = 0; i < m_barSets.count(); i++) {
457 int categoryCount = m_barSets.at(i)->count();
457 int categoryCount = m_barSets.at(i)->count();
458 for (int j = 0; j < categoryCount; j++) {
458 for (int j = 0; j < categoryCount; j++) {
459 qreal temp = m_barSets.at(i)->at(j);
459 qreal temp = m_barSets.at(i)->at(j);
460 if (temp > max)
460 if (temp > max)
461 max = temp;
461 max = temp;
462 }
462 }
463 }
463 }
464
464
465 return max;
465 return max;
466 }
466 }
467
467
468 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
468 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
469 {
469 {
470 if ((set < 0) || (set >= m_barSets.count()))
470 if ((set < 0) || (set >= m_barSets.count()))
471 return 0; // No set, no value.
471 return 0; // No set, no value.
472 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
472 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
473 return 0; // No category, no value.
473 return 0; // No category, no value.
474
474
475 return m_barSets.at(set)->at(category);
475 return m_barSets.at(set)->at(category);
476 }
476 }
477
477
478 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
478 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
479 {
479 {
480 if ((set < 0) || (set >= m_barSets.count()))
480 if ((set < 0) || (set >= m_barSets.count()))
481 return 0; // No set, no value.
481 return 0; // No set, no value.
482 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
482 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
483 return 0; // No category, no value.
483 return 0; // No category, no value.
484
484
485 qreal value = m_barSets.at(set)->at(category);
485 qreal value = m_barSets.at(set)->at(category);
486 qreal sum = categorySum(category);
486 qreal sum = categorySum(category);
487 if (qFuzzyIsNull(sum))
487 if (qFuzzyCompare(sum, 0))
488 return 0;
488 return 0;
489
489
490 return value / sum;
490 return value / sum;
491 }
491 }
492
492
493 qreal QAbstractBarSeriesPrivate::categorySum(int category)
493 qreal QAbstractBarSeriesPrivate::categorySum(int category)
494 {
494 {
495 qreal sum(0);
495 qreal sum(0);
496 int count = m_barSets.count(); // Count sets
496 int count = m_barSets.count(); // Count sets
497 for (int set = 0; set < count; set++) {
497 for (int set = 0; set < count; set++) {
498 if (category < m_barSets.at(set)->count())
498 if (category < m_barSets.at(set)->count())
499 sum += m_barSets.at(set)->at(category);
499 sum += m_barSets.at(set)->at(category);
500 }
500 }
501 return sum;
501 return sum;
502 }
502 }
503
503
504 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
504 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
505 {
505 {
506 qreal sum(0);
506 qreal sum(0);
507 int count = m_barSets.count(); // Count sets
507 int count = m_barSets.count(); // Count sets
508 for (int set = 0; set < count; set++) {
508 for (int set = 0; set < count; set++) {
509 if (category < m_barSets.at(set)->count())
509 if (category < m_barSets.at(set)->count())
510 sum += qAbs(m_barSets.at(set)->at(category));
510 sum += qAbs(m_barSets.at(set)->at(category));
511 }
511 }
512 return sum;
512 return sum;
513 }
513 }
514
514
515 qreal QAbstractBarSeriesPrivate::maxCategorySum()
515 qreal QAbstractBarSeriesPrivate::maxCategorySum()
516 {
516 {
517 qreal max = INT_MIN;
517 qreal max = INT_MIN;
518 int count = categoryCount();
518 int count = categoryCount();
519 for (int i = 0; i < count; i++) {
519 for (int i = 0; i < count; i++) {
520 qreal sum = categorySum(i);
520 qreal sum = categorySum(i);
521 if (sum > max)
521 if (sum > max)
522 max = sum;
522 max = sum;
523 }
523 }
524 return max;
524 return max;
525 }
525 }
526
526
527 qreal QAbstractBarSeriesPrivate::minX()
527 qreal QAbstractBarSeriesPrivate::minX()
528 {
528 {
529 if (m_barSets.count() <= 0)
529 if (m_barSets.count() <= 0)
530 return 0;
530 return 0;
531
531
532 qreal min = INT_MAX;
532 qreal min = INT_MAX;
533
533
534 for (int i = 0; i < m_barSets.count(); i++) {
534 for (int i = 0; i < m_barSets.count(); i++) {
535 int categoryCount = m_barSets.at(i)->count();
535 int categoryCount = m_barSets.at(i)->count();
536 for (int j = 0; j < categoryCount; j++) {
536 for (int j = 0; j < categoryCount; j++) {
537 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
537 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
538 if (temp < min)
538 if (temp < min)
539 min = temp;
539 min = temp;
540 }
540 }
541 }
541 }
542 return min;
542 return min;
543 }
543 }
544
544
545 qreal QAbstractBarSeriesPrivate::maxX()
545 qreal QAbstractBarSeriesPrivate::maxX()
546 {
546 {
547 if (m_barSets.count() <= 0)
547 if (m_barSets.count() <= 0)
548 return 0;
548 return 0;
549
549
550 qreal max = INT_MIN;
550 qreal max = INT_MIN;
551
551
552 for (int i = 0; i < m_barSets.count(); i++) {
552 for (int i = 0; i < m_barSets.count(); i++) {
553 int categoryCount = m_barSets.at(i)->count();
553 int categoryCount = m_barSets.at(i)->count();
554 for (int j = 0; j < categoryCount; j++) {
554 for (int j = 0; j < categoryCount; j++) {
555 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
555 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
556 if (temp > max)
556 if (temp > max)
557 max = temp;
557 max = temp;
558 }
558 }
559 }
559 }
560
560
561 return max;
561 return max;
562 }
562 }
563
563
564 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
564 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
565 {
565 {
566 // Returns top (sum of all positive values) of category.
566 // Returns top (sum of all positive values) of category.
567 // Returns 0, if all values are negative
567 // Returns 0, if all values are negative
568 qreal top(0);
568 qreal top(0);
569 int count = m_barSets.count();
569 int count = m_barSets.count();
570 for (int set = 0; set < count; set++) {
570 for (int set = 0; set < count; set++) {
571 if (category < m_barSets.at(set)->count()) {
571 if (category < m_barSets.at(set)->count()) {
572 qreal temp = m_barSets.at(set)->at(category);
572 qreal temp = m_barSets.at(set)->at(category);
573 if (temp > 0) {
573 if (temp > 0) {
574 top += temp;
574 top += temp;
575 }
575 }
576 }
576 }
577 }
577 }
578 return top;
578 return top;
579 }
579 }
580
580
581 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
581 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
582 {
582 {
583 // Returns bottom (sum of all negative values) of category
583 // Returns bottom (sum of all negative values) of category
584 // Returns 0, if all values are positive
584 // Returns 0, if all values are positive
585 qreal bottom(0);
585 qreal bottom(0);
586 int count = m_barSets.count();
586 int count = m_barSets.count();
587 for (int set = 0; set < count; set++) {
587 for (int set = 0; set < count; set++) {
588 if (category < m_barSets.at(set)->count()) {
588 if (category < m_barSets.at(set)->count()) {
589 qreal temp = m_barSets.at(set)->at(category);
589 qreal temp = m_barSets.at(set)->at(category);
590 if (temp < 0) {
590 if (temp < 0) {
591 bottom += temp;
591 bottom += temp;
592 }
592 }
593 }
593 }
594 }
594 }
595 return bottom;
595 return bottom;
596 }
596 }
597
597
598 qreal QAbstractBarSeriesPrivate::top()
598 qreal QAbstractBarSeriesPrivate::top()
599 {
599 {
600 // Returns top of all categories
600 // Returns top of all categories
601 qreal top(0);
601 qreal top(0);
602 int count = categoryCount();
602 int count = categoryCount();
603 for (int i = 0; i < count; i++) {
603 for (int i = 0; i < count; i++) {
604 qreal temp = categoryTop(i);
604 qreal temp = categoryTop(i);
605 if (temp > top)
605 if (temp > top)
606 top = temp;
606 top = temp;
607 }
607 }
608 return top;
608 return top;
609 }
609 }
610
610
611 qreal QAbstractBarSeriesPrivate::bottom()
611 qreal QAbstractBarSeriesPrivate::bottom()
612 {
612 {
613 // Returns bottom of all categories
613 // Returns bottom of all categories
614 qreal bottom(0);
614 qreal bottom(0);
615 int count = categoryCount();
615 int count = categoryCount();
616 for (int i = 0; i < count; i++) {
616 for (int i = 0; i < count; i++) {
617 qreal temp = categoryBottom(i);
617 qreal temp = categoryBottom(i);
618 if (temp < bottom)
618 if (temp < bottom)
619 bottom = temp;
619 bottom = temp;
620 }
620 }
621 return bottom;
621 return bottom;
622 }
622 }
623
623
624
624
625 void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain)
625 void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain)
626 {
626 {
627 qreal minX(domain.minX());
627 qreal minX(domain.minX());
628 qreal minY(domain.minY());
628 qreal minY(domain.minY());
629 qreal maxX(domain.maxX());
629 qreal maxX(domain.maxX());
630 qreal maxY(domain.maxY());
630 qreal maxY(domain.maxY());
631
631
632 qreal seriesMinX = this->minX();
632 qreal seriesMinX = this->minX();
633 qreal seriesMaxX = this->maxX();
633 qreal seriesMaxX = this->maxX();
634 qreal y = max();
634 qreal y = max();
635 minX = qMin(minX, seriesMinX - (qreal)0.5);
635 minX = qMin(minX, seriesMinX - (qreal)0.5);
636 minY = qMin(minY, y);
636 minY = qMin(minY, y);
637 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
637 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
638 maxY = qMax(maxY, y);
638 maxY = qMax(maxY, y);
639
639
640 domain.setRange(minX, maxX, minY, maxY);
640 domain.setRange(minX, maxX, minY, maxY);
641 }
641 }
642
642
643 ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter)
643 ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter)
644 {
644 {
645 Q_UNUSED(presenter);
645 Q_UNUSED(presenter);
646 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
646 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
647 return 0;
647 return 0;
648 }
648 }
649
649
650 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
650 QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend)
651 {
651 {
652 Q_Q(QAbstractBarSeries);
652 Q_Q(QAbstractBarSeries);
653 QList<QLegendMarker*> markers;
653 QList<QLegendMarker*> markers;
654
654
655 foreach(QBarSet* set, q->barSets()) {
655 foreach(QBarSet* set, q->barSets()) {
656 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
656 QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend);
657 markers << marker;
657 markers << marker;
658 }
658 }
659 return markers;
659 return markers;
660 }
660 }
661
661
662
662
663 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
663 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
664 {
664 {
665 if ((m_barSets.contains(set)) || (set == 0))
665 if ((m_barSets.contains(set)) || (set == 0))
666 return false; // Fail if set is already in list or set is null.
666 return false; // Fail if set is already in list or set is null.
667
667
668 m_barSets.append(set);
668 m_barSets.append(set);
669 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
669 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
670 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
670 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
671 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
671 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
672
672
673 emit restructuredBars(); // this notifies barchartitem
673 emit restructuredBars(); // this notifies barchartitem
674 return true;
674 return true;
675 }
675 }
676
676
677 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
677 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
678 {
678 {
679 if (!m_barSets.contains(set))
679 if (!m_barSets.contains(set))
680 return false; // Fail if set is not in list
680 return false; // Fail if set is not in list
681
681
682 m_barSets.removeOne(set);
682 m_barSets.removeOne(set);
683 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
683 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
684 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
684 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
685 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
685 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
686
686
687 emit restructuredBars(); // this notifies barchartitem
687 emit restructuredBars(); // this notifies barchartitem
688 return true;
688 return true;
689 }
689 }
690
690
691 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
691 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
692 {
692 {
693 foreach (QBarSet *set, sets) {
693 foreach (QBarSet *set, sets) {
694 if ((set == 0) || (m_barSets.contains(set)))
694 if ((set == 0) || (m_barSets.contains(set)))
695 return false; // Fail if any of the sets is null or is already appended.
695 return false; // Fail if any of the sets is null or is already appended.
696 if (sets.count(set) != 1)
696 if (sets.count(set) != 1)
697 return false; // Also fail if same set is more than once in given list.
697 return false; // Also fail if same set is more than once in given list.
698 }
698 }
699
699
700 foreach (QBarSet *set, sets) {
700 foreach (QBarSet *set, sets) {
701 m_barSets.append(set);
701 m_barSets.append(set);
702 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
702 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
703 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
703 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
704 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
704 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
705 }
705 }
706
706
707 emit restructuredBars(); // this notifies barchartitem
707 emit restructuredBars(); // this notifies barchartitem
708 return true;
708 return true;
709 }
709 }
710
710
711 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
711 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
712 {
712 {
713 if (sets.count() == 0)
713 if (sets.count() == 0)
714 return false;
714 return false;
715
715
716 foreach (QBarSet *set, sets) {
716 foreach (QBarSet *set, sets) {
717 if ((set == 0) || (!m_barSets.contains(set)))
717 if ((set == 0) || (!m_barSets.contains(set)))
718 return false; // Fail if any of the sets is null or is not in series
718 return false; // Fail if any of the sets is null or is not in series
719 if (sets.count(set) != 1)
719 if (sets.count(set) != 1)
720 return false; // Also fail if same set is more than once in given list.
720 return false; // Also fail if same set is more than once in given list.
721 }
721 }
722
722
723 foreach (QBarSet *set, sets) {
723 foreach (QBarSet *set, sets) {
724 m_barSets.removeOne(set);
724 m_barSets.removeOne(set);
725 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
725 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
726 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
727 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 }
728 }
729
729
730 emit restructuredBars(); // this notifies barchartitem
730 emit restructuredBars(); // this notifies barchartitem
731
731
732 return true;
732 return true;
733 }
733 }
734
734
735 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
735 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
736 {
736 {
737 if ((m_barSets.contains(set)) || (set == 0))
737 if ((m_barSets.contains(set)) || (set == 0))
738 return false; // Fail if set is already in list or set is null.
738 return false; // Fail if set is already in list or set is null.
739
739
740 m_barSets.insert(index, set);
740 m_barSets.insert(index, set);
741 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
741 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
742 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
742 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
743 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
743 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
744
744
745 emit restructuredBars(); // this notifies barchartitem
745 emit restructuredBars(); // this notifies barchartitem
746 return true;
746 return true;
747 }
747 }
748
748
749 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis)
749 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis)
750 {
750 {
751 Q_Q(QAbstractBarSeries);
751 Q_Q(QAbstractBarSeries);
752
752
753 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
753 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
754 switch (q->type()) {
754 switch (q->type()) {
755 case QAbstractSeries::SeriesTypeHorizontalBar:
755 case QAbstractSeries::SeriesTypeHorizontalBar:
756 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
756 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
757 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
757 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
758 if (axis->orientation() == Qt::Vertical)
758 if (axis->orientation() == Qt::Vertical)
759 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
759 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
760 break;
760 break;
761 case QAbstractSeries::SeriesTypeBar:
761 case QAbstractSeries::SeriesTypeBar:
762 case QAbstractSeries::SeriesTypePercentBar:
762 case QAbstractSeries::SeriesTypePercentBar:
763 case QAbstractSeries::SeriesTypeStackedBar:
763 case QAbstractSeries::SeriesTypeStackedBar:
764 if (axis->orientation() == Qt::Horizontal)
764 if (axis->orientation() == Qt::Horizontal)
765 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
765 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
766 break;
766 break;
767 default:
767 default:
768 qWarning() << "Unexpected series type";
768 qWarning() << "Unexpected series type";
769 break;
769 break;
770 }
770 }
771 }
771 }
772 }
772 }
773
773
774 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
774 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
775 {
775 {
776 Q_Q(const QAbstractBarSeries);
776 Q_Q(const QAbstractBarSeries);
777
777
778 switch (q->type()) {
778 switch (q->type()) {
779 case QAbstractSeries::SeriesTypeHorizontalBar:
779 case QAbstractSeries::SeriesTypeHorizontalBar:
780 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
780 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
781 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
781 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
782 if (orientation == Qt::Vertical)
782 if (orientation == Qt::Vertical)
783 return QAbstractAxis::AxisTypeBarCategory;
783 return QAbstractAxis::AxisTypeBarCategory;
784 break;
784 break;
785 case QAbstractSeries::SeriesTypeBar:
785 case QAbstractSeries::SeriesTypeBar:
786 case QAbstractSeries::SeriesTypePercentBar:
786 case QAbstractSeries::SeriesTypePercentBar:
787 case QAbstractSeries::SeriesTypeStackedBar:
787 case QAbstractSeries::SeriesTypeStackedBar:
788 if (orientation == Qt::Horizontal)
788 if (orientation == Qt::Horizontal)
789 return QAbstractAxis::AxisTypeBarCategory;
789 return QAbstractAxis::AxisTypeBarCategory;
790 break;
790 break;
791 default:
791 default:
792 qWarning() << "Unexpected series type";
792 qWarning() << "Unexpected series type";
793 break;
793 break;
794 }
794 }
795 return QAbstractAxis::AxisTypeValue;
795 return QAbstractAxis::AxisTypeValue;
796
796
797 }
797 }
798
798
799 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
799 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
800 {
800 {
801 QStringList categories;
801 QStringList categories;
802 if (axis->categories().isEmpty()) {
802 if (axis->categories().isEmpty()) {
803 for (int i(1); i < categoryCount() + 1; i++)
803 for (int i(1); i < categoryCount() + 1; i++)
804 categories << QString::number(i);
804 categories << QString::number(i);
805 axis->append(categories);
805 axis->append(categories);
806 }
806 }
807 }
807 }
808
808
809 #include "moc_qabstractbarseries.cpp"
809 #include "moc_qabstractbarseries.cpp"
810 #include "moc_qabstractbarseries_p.cpp"
810 #include "moc_qabstractbarseries_p.cpp"
811
811
812 QTCOMMERCIALCHART_END_NAMESPACE
812 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,94 +1,94
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "barchartitem_p.h"
21 #include "barchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qabstractbarseries_p.h"
23 #include "qabstractbarseries_p.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25 #include "qbarset_p.h"
25 #include "qbarset_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
29 BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
30 AbstractBarChartItem(series, presenter)
30 AbstractBarChartItem(series, presenter)
31 {
31 {
32 }
32 }
33
33
34 QVector<QRectF> BarChartItem::calculateLayout()
34 QVector<QRectF> BarChartItem::calculateLayout()
35 {
35 {
36 QVector<QRectF> layout;
36 QVector<QRectF> layout;
37
37
38 // Use temporary qreals for accuracy
38 // Use temporary qreals for accuracy
39 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal setCount = m_series->count();
40 qreal setCount = m_series->count();
41 bool barsVisible = m_series->isVisible();
41 bool barsVisible = m_series->isVisible();
42
42
43 // Domain:
43 // Domain:
44 qreal width = geometry().width();
44 qreal width = geometry().width();
45 qreal height = geometry().height();
45 qreal height = geometry().height();
46 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
49 qreal scaleX = (width / rangeX);
50 qreal rectWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
50 qreal rectWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
51
51
52 int itemIndex(0);
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
53 for (int category = 0; category < categoryCount; category++) {
54 qreal yPos = height + scaleY * m_domainMinY + geometry().top();
54 qreal yPos = height + scaleY * m_domainMinY + geometry().top();
55 for (int set = 0; set < setCount; set++) {
55 for (int set = 0; set < setCount; set++) {
56 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
56 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57
57
58 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left();
58 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left();
59 xPos -= setCount * rectWidth / 2;
59 xPos -= setCount * rectWidth / 2;
60 xPos += set * rectWidth;
60 xPos += set * rectWidth;
61
61
62 qreal rectHeight = barSet->value(category) * scaleY;
62 qreal rectHeight = barSet->value(category) * scaleY;
63 Bar *bar = m_bars.at(itemIndex);
63 Bar *bar = m_bars.at(itemIndex);
64
64
65 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
65 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
66 layout.append(rect);
66 layout.append(rect);
67 bar->setPen(barSet->m_pen);
67 bar->setPen(barSet->m_pen);
68 bar->setBrush(barSet->m_brush);
68 bar->setBrush(barSet->m_brush);
69 if (qFuzzyIsNull(rectHeight))
69 if (qFuzzyCompare(rectHeight, 0))
70 bar->setVisible(false);
70 bar->setVisible(false);
71 else
71 else
72 bar->setVisible(barsVisible);
72 bar->setVisible(barsVisible);
73
73
74 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
74 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
75
75
76 if (!qFuzzyIsNull(barSet->value(category)))
76 if (!qFuzzyCompare(barSet->value(category), 0))
77 label->setText(QString::number(barSet->value(category)));
77 label->setText(QString::number(barSet->value(category)));
78 else
78 else
79 label->setText(QString(""));
79 label->setText(QString(""));
80
80
81 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
81 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
82 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
82 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
83 label->setFont(barSet->m_labelFont);
83 label->setFont(barSet->m_labelFont);
84 label->setBrush(barSet->m_labelBrush);
84 label->setBrush(barSet->m_labelBrush);
85
85
86 itemIndex++;
86 itemIndex++;
87 }
87 }
88 }
88 }
89 return layout;
89 return layout;
90 }
90 }
91
91
92 #include "moc_barchartitem_p.cpp"
92 #include "moc_barchartitem_p.cpp"
93
93
94 QTCOMMERCIALCHART_END_NAMESPACE
94 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,100 +1,100
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 "percentbarchartitem_p.h"
21 #include "percentbarchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qabstractbarseries_p.h"
23 #include "qabstractbarseries_p.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25 #include "qbarset_p.h"
25 #include "qbarset_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
29 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
30 AbstractBarChartItem(series, presenter)
30 AbstractBarChartItem(series, presenter)
31 {
31 {
32 }
32 }
33
33
34 QVector<QRectF> PercentBarChartItem::calculateLayout()
34 QVector<QRectF> PercentBarChartItem::calculateLayout()
35 {
35 {
36 QVector<QRectF> layout;
36 QVector<QRectF> layout;
37
37
38 // Use temporary qreals for accuracy
38 // Use temporary qreals for accuracy
39 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal setCount = m_series->count();
40 qreal setCount = m_series->count();
41 bool barsVisible = m_series->isVisible();
41 bool barsVisible = m_series->isVisible();
42
42
43 // Domain:
43 // Domain:
44 qreal width = geometry().width();
44 qreal width = geometry().width();
45 qreal height = geometry().height();
45 qreal height = geometry().height();
46 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
49 qreal scaleX = (width / rangeX);
50 qreal rectWidth = scaleX * m_series->d_func()->barWidth();
50 qreal rectWidth = scaleX * m_series->d_func()->barWidth();
51
51
52 int itemIndex(0);
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
53 for (int category = 0; category < categoryCount; category++) {
54 qreal colSum = m_series->d_func()->categorySum(category);
54 qreal colSum = m_series->d_func()->categorySum(category);
55 qreal percentage = (100 / colSum);
55 qreal percentage = (100 / colSum);
56 qreal yPos = height + scaleY * m_domainMinY + geometry().top();
56 qreal yPos = height + scaleY * m_domainMinY + geometry().top();
57 for (int set = 0; set < setCount; set++) {
57 for (int set = 0; set < setCount; set++) {
58 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
58 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
59
59
60 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left() - rectWidth / 2;
60 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left() - rectWidth / 2;
61
61
62 qreal rectHeight = barSet->value(category) * percentage * scaleY;
62 qreal rectHeight = barSet->value(category) * percentage * scaleY;
63 Bar *bar = m_bars.at(itemIndex);
63 Bar *bar = m_bars.at(itemIndex);
64 bar->setPen(barSet->m_pen);
64 bar->setPen(barSet->m_pen);
65 bar->setBrush(barSet->m_brush);
65 bar->setBrush(barSet->m_brush);
66 if (qFuzzyIsNull(rectHeight))
66 if (qFuzzyCompare(rectHeight, 0))
67 bar->setVisible(false);
67 bar->setVisible(false);
68 else
68 else
69 bar->setVisible(barsVisible);
69 bar->setVisible(barsVisible);
70
70
71 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
71 QRectF rect(xPos, yPos - rectHeight, rectWidth, rectHeight);
72 layout.append(rect);
72 layout.append(rect);
73
73
74 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
74 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
75
75
76 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set, category))) {
76 if (!qFuzzyCompare(m_series->d_func()->valueAt(set, category), 0)) {
77 int p = m_series->d_func()->percentageAt(set, category) * 100;
77 int p = m_series->d_func()->percentageAt(set, category) * 100;
78 QString vString(QString::number(p));
78 QString vString(QString::number(p));
79 vString.truncate(3);
79 vString.truncate(3);
80 vString.append("%");
80 vString.append("%");
81 label->setText(vString);
81 label->setText(vString);
82 } else {
82 } else {
83 label->setText(QString(""));
83 label->setText(QString(""));
84 }
84 }
85
85
86 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
86 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
87 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
87 yPos - rectHeight / 2 - label->boundingRect().height() / 2);
88 label->setFont(barSet->m_labelFont);
88 label->setFont(barSet->m_labelFont);
89 label->setBrush(barSet->m_labelBrush);
89 label->setBrush(barSet->m_labelBrush);
90
90
91 itemIndex++;
91 itemIndex++;
92 yPos -= rectHeight;
92 yPos -= rectHeight;
93 }
93 }
94 }
94 }
95 return layout;
95 return layout;
96 }
96 }
97
97
98 #include "moc_percentbarchartitem_p.cpp"
98 #include "moc_percentbarchartitem_p.cpp"
99
99
100 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,102 +1,102
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 "stackedbarchartitem_p.h"
21 #include "stackedbarchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarset_p.h"
23 #include "qbarset_p.h"
24 #include "qabstractbarseries_p.h"
24 #include "qabstractbarseries_p.h"
25 #include "qbarset.h"
25 #include "qbarset.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
29 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
30 AbstractBarChartItem(series, presenter)
30 AbstractBarChartItem(series, presenter)
31 {
31 {
32 }
32 }
33
33
34 QVector<QRectF> StackedBarChartItem::calculateLayout()
34 QVector<QRectF> StackedBarChartItem::calculateLayout()
35 {
35 {
36 QVector<QRectF> layout;
36 QVector<QRectF> layout;
37 // Use temporary qreals for accuracy
37 // Use temporary qreals for accuracy
38 qreal categoryCount = m_series->d_func()->categoryCount();
38 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal setCount = m_series->count();
39 qreal setCount = m_series->count();
40 bool barsVisible = m_series->isVisible();
40 bool barsVisible = m_series->isVisible();
41
41
42 // Domain:
42 // Domain:
43 qreal width = geometry().width();
43 qreal width = geometry().width();
44 qreal height = geometry().height();
44 qreal height = geometry().height();
45 qreal rangeY = m_domainMaxY - m_domainMinY;
45 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
46 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal scaleY = (height / rangeY);
47 qreal scaleY = (height / rangeY);
48 qreal scaleX = (width / rangeX);
48 qreal scaleX = (width / rangeX);
49 qreal rectWidth = scaleX * m_series->d_func()->barWidth();
49 qreal rectWidth = scaleX * m_series->d_func()->barWidth();
50
50
51 int itemIndex(0);
51 int itemIndex(0);
52 for (int category = 0; category < categoryCount; category++) {
52 for (int category = 0; category < categoryCount; category++) {
53 qreal yMax = height + scaleY * m_domainMinY + geometry().top();
53 qreal yMax = height + scaleY * m_domainMinY + geometry().top();
54 qreal yMin = height + scaleY * m_domainMinY + geometry().top();
54 qreal yMin = height + scaleY * m_domainMinY + geometry().top();
55 for (int set = 0; set < setCount; set++) {
55 for (int set = 0; set < setCount; set++) {
56 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
56 QBarSetPrivate *barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57
57
58 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left() - rectWidth / 2;
58 qreal xPos = (barSet->pos(category) - m_domainMinX) * scaleX + geometry().left() - rectWidth / 2;
59
59
60 qreal rectHeight = barSet->value(category) * scaleY;
60 qreal rectHeight = barSet->value(category) * scaleY;
61 Bar *bar = m_bars.at(itemIndex);
61 Bar *bar = m_bars.at(itemIndex);
62 bar->setPen(barSet->m_pen);
62 bar->setPen(barSet->m_pen);
63 bar->setBrush(barSet->m_brush);
63 bar->setBrush(barSet->m_brush);
64 if (qFuzzyIsNull(rectHeight))
64 if (qFuzzyCompare(rectHeight, 0))
65 bar->setVisible(false);
65 bar->setVisible(false);
66 else
66 else
67 bar->setVisible(barsVisible);
67 bar->setVisible(barsVisible);
68
68
69 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
69 QGraphicsSimpleTextItem *label = m_labels.at(itemIndex);
70
70
71 if (!qFuzzyIsNull(barSet->value(category)))
71 if (!qFuzzyCompare(barSet->value(category), 0))
72 label->setText(QString::number(barSet->value(category)));
72 label->setText(QString::number(barSet->value(category)));
73 else
73 else
74 label->setText(QString(""));
74 label->setText(QString(""));
75
75
76 label->setFont(barSet->m_labelFont);
76 label->setFont(barSet->m_labelFont);
77 label->setBrush(barSet->m_labelBrush);
77 label->setBrush(barSet->m_labelBrush);
78
78
79 if (rectHeight < 0) {
79 if (rectHeight < 0) {
80 QRectF rect(xPos, yMax - rectHeight, rectWidth, rectHeight);
80 QRectF rect(xPos, yMax - rectHeight, rectWidth, rectHeight);
81 layout.append(rect);
81 layout.append(rect);
82 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
82 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
83 yMax - rectHeight / 2 - label->boundingRect().height() / 2);
83 yMax - rectHeight / 2 - label->boundingRect().height() / 2);
84 yMax -= rectHeight;
84 yMax -= rectHeight;
85 } else {
85 } else {
86 QRectF rect(xPos, yMin - rectHeight, rectWidth, rectHeight);
86 QRectF rect(xPos, yMin - rectHeight, rectWidth, rectHeight);
87 layout.append(rect);
87 layout.append(rect);
88 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
88 label->setPos(xPos + (rect.width() / 2 - label->boundingRect().width() / 2),
89 yMin - rectHeight / 2 - label->boundingRect().height() / 2);
89 yMin - rectHeight / 2 - label->boundingRect().height() / 2);
90 yMin -= rectHeight;
90 yMin -= rectHeight;
91 }
91 }
92
92
93 itemIndex++;
93 itemIndex++;
94 }
94 }
95 }
95 }
96
96
97 return layout;
97 return layout;
98 }
98 }
99
99
100 #include "moc_stackedbarchartitem_p.cpp"
100 #include "moc_stackedbarchartitem_p.cpp"
101
101
102 QTCOMMERCIALCHART_END_NAMESPACE
102 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,101 +1,101
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 "chartbackground_p.h"
21 #include "chartbackground_p.h"
22 #include "chartconfig_p.h"
22 #include "chartconfig_p.h"
23 #include <QPen>
23 #include <QPen>
24 #include <QBrush>
24 #include <QBrush>
25 #include <QPainter>
25 #include <QPainter>
26 #include <QGraphicsDropShadowEffect>
26 #include <QGraphicsDropShadowEffect>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 ChartBackground::ChartBackground(QGraphicsItem *parent)
30 ChartBackground::ChartBackground(QGraphicsItem *parent)
31 : QGraphicsRectItem(parent),
31 : QGraphicsRectItem(parent),
32 m_diameter(15),
32 m_diameter(15),
33 m_dropShadow(0)
33 m_dropShadow(0)
34 {
34 {
35 }
35 }
36
36
37 ChartBackground::~ChartBackground()
37 ChartBackground::~ChartBackground()
38 {
38 {
39
39
40 }
40 }
41
41
42 void ChartBackground::setDropShadowEnabled(bool enabled)
42 void ChartBackground::setDropShadowEnabled(bool enabled)
43 {
43 {
44 if (enabled) {
44 if (enabled) {
45 if (!m_dropShadow) {
45 if (!m_dropShadow) {
46 m_dropShadow = new QGraphicsDropShadowEffect();
46 m_dropShadow = new QGraphicsDropShadowEffect();
47 #ifdef Q_OS_MAC
47 #ifdef Q_OS_MAC
48 m_dropShadow->setBlurRadius(15);
48 m_dropShadow->setBlurRadius(15);
49 m_dropShadow->setOffset(0, 0);
49 m_dropShadow->setOffset(0, 0);
50 #elif defined(Q_OS_WIN)
50 #elif defined(Q_OS_WIN)
51 m_dropShadow->setBlurRadius(10);
51 m_dropShadow->setBlurRadius(10);
52 m_dropShadow->setOffset(0, 0);
52 m_dropShadow->setOffset(0, 0);
53 #else
53 #else
54 m_dropShadow->setBlurRadius(10);
54 m_dropShadow->setBlurRadius(10);
55 m_dropShadow->setOffset(5, 5);
55 m_dropShadow->setOffset(5, 5);
56 #endif
56 #endif
57 setGraphicsEffect(m_dropShadow);
57 setGraphicsEffect(m_dropShadow);
58 }
58 }
59 } else {
59 } else {
60 delete m_dropShadow;
60 delete m_dropShadow;
61 m_dropShadow = 0;
61 m_dropShadow = 0;
62 }
62 }
63 }
63 }
64
64
65 void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
65 void ChartBackground::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
66 {
66 {
67 Q_UNUSED(option);
67 Q_UNUSED(option);
68 Q_UNUSED(widget);
68 Q_UNUSED(widget);
69 painter->save();
69 painter->save();
70 painter->setPen(pen());
70 painter->setPen(pen());
71 painter->setBrush(brush());
71 painter->setBrush(brush());
72 painter->drawRoundRect(rect(), roundness(rect().width()), roundness(rect().height()));
72 painter->drawRoundRect(rect(), roundness(rect().width()), roundness(rect().height()));
73 #ifndef QT_NO_DEBUG
73 #ifndef QT_NO_DEBUG
74 painter->setPen(Qt::black);
74 painter->setPen(Qt::black);
75 QFont font;
75 QFont font;
76 QString build("build %1");
76 QString build("build %1");
77 font.setPointSize(6);
77 font.setPointSize(6);
78 painter->setFont(font);
78 painter->setFont(font);
79 painter->drawText(rect().bottomLeft(), build.arg(ChartConfig::instance()->compilationTime()));
79 painter->drawText(rect().bottomLeft(), build.arg(ChartConfig::instance()->compilationTime()));
80 #endif
80 #endif
81 painter->restore();
81 painter->restore();
82 }
82 }
83
83
84 int ChartBackground::roundness(qreal size) const
84 int ChartBackground::roundness(qreal size) const
85 {
85 {
86 if (qFuzzyIsNull(size))
86 if (qFuzzyCompare(size, 0))
87 return 0;
87 return 0;
88 return 100 * m_diameter / int(size);
88 return 100 * m_diameter / int(size);
89 }
89 }
90
90
91 int ChartBackground::diameter() const
91 int ChartBackground::diameter() const
92 {
92 {
93 return m_diameter;
93 return m_diameter;
94 }
94 }
95
95
96 void ChartBackground::setDiameter(int diameter)
96 void ChartBackground::setDiameter(int diameter)
97 {
97 {
98 m_diameter = diameter;
98 m_diameter = diameter;
99 }
99 }
100
100
101 QTCOMMERCIALCHART_END_NAMESPACE
101 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,205 +1,205
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 "domain_p.h"
21 #include "domain_p.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 Domain::Domain(QObject *parent)
26 Domain::Domain(QObject *parent)
27 : QObject(parent),
27 : QObject(parent),
28 m_minX(0),
28 m_minX(0),
29 m_maxX(0),
29 m_maxX(0),
30 m_minY(0),
30 m_minY(0),
31 m_maxY(0)
31 m_maxY(0)
32 {
32 {
33 }
33 }
34
34
35 Domain::~Domain()
35 Domain::~Domain()
36 {
36 {
37 }
37 }
38
38
39 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
39 void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY)
40 {
40 {
41 bool axisXChanged = false;
41 bool axisXChanged = false;
42 bool axisYChanged = false;
42 bool axisYChanged = false;
43
43
44 if (!qFuzzyIsNull(m_minX - minX) || !qFuzzyIsNull(m_maxX - maxX)) {
44 if (!qFuzzyCompare(m_minX, minX) || !qFuzzyCompare(m_maxX, maxX)) {
45 m_minX = minX;
45 m_minX = minX;
46 m_maxX = maxX;
46 m_maxX = maxX;
47 axisXChanged = true;
47 axisXChanged = true;
48 emit rangeXChanged(m_minX, m_maxX);
48 emit rangeXChanged(m_minX, m_maxX);
49 }
49 }
50
50
51 if (!qFuzzyIsNull(m_minY - minY) || !qFuzzyIsNull(m_maxY - maxY)) {
51 if (!qFuzzyCompare(m_minY, minY) || !qFuzzyCompare(m_maxY, maxY)) {
52 m_minY = minY;
52 m_minY = minY;
53 m_maxY = maxY;
53 m_maxY = maxY;
54 axisYChanged = true;
54 axisYChanged = true;
55 emit rangeYChanged(m_minY, m_maxY);
55 emit rangeYChanged(m_minY, m_maxY);
56 }
56 }
57
57
58 if (axisXChanged || axisYChanged)
58 if (axisXChanged || axisYChanged)
59 emit updated();
59 emit updated();
60 }
60 }
61
61
62 void Domain::setRangeX(qreal min, qreal max)
62 void Domain::setRangeX(qreal min, qreal max)
63 {
63 {
64 setRange(min, max, m_minY, m_maxY);
64 setRange(min, max, m_minY, m_maxY);
65 }
65 }
66
66
67 void Domain::setRangeY(qreal min, qreal max)
67 void Domain::setRangeY(qreal min, qreal max)
68 {
68 {
69 setRange(m_minX, m_maxX, min, max);
69 setRange(m_minX, m_maxX, min, max);
70 }
70 }
71
71
72 void Domain::setMinX(qreal min)
72 void Domain::setMinX(qreal min)
73 {
73 {
74 setRange(min, m_maxX, m_minY, m_maxY);
74 setRange(min, m_maxX, m_minY, m_maxY);
75 }
75 }
76
76
77 void Domain::setMaxX(qreal max)
77 void Domain::setMaxX(qreal max)
78 {
78 {
79 setRange(m_minX, max, m_minY, m_maxY);
79 setRange(m_minX, max, m_minY, m_maxY);
80 }
80 }
81
81
82 void Domain::setMinY(qreal min)
82 void Domain::setMinY(qreal min)
83 {
83 {
84 setRange(m_minX, m_maxX, min, m_maxY);
84 setRange(m_minX, m_maxX, min, m_maxY);
85 }
85 }
86
86
87 void Domain::setMaxY(qreal max)
87 void Domain::setMaxY(qreal max)
88 {
88 {
89 setRange(m_minX, m_maxX, m_minY, max);
89 setRange(m_minX, m_maxX, m_minY, max);
90 }
90 }
91
91
92 qreal Domain::spanX() const
92 qreal Domain::spanX() const
93 {
93 {
94 Q_ASSERT(m_maxX >= m_minX);
94 Q_ASSERT(m_maxX >= m_minX);
95 return m_maxX - m_minX;
95 return m_maxX - m_minX;
96 }
96 }
97
97
98 qreal Domain::spanY() const
98 qreal Domain::spanY() const
99 {
99 {
100 Q_ASSERT(m_maxY >= m_minY);
100 Q_ASSERT(m_maxY >= m_minY);
101 return m_maxY - m_minY;
101 return m_maxY - m_minY;
102 }
102 }
103
103
104 bool Domain::isEmpty() const
104 bool Domain::isEmpty() const
105 {
105 {
106 return qFuzzyIsNull(spanX()) || qFuzzyIsNull(spanY());
106 return qFuzzyCompare(spanX(), 0) || qFuzzyCompare(spanY(), 0);
107 }
107 }
108
108
109 void Domain::zoomIn(const QRectF &rect, const QSizeF &size)
109 void Domain::zoomIn(const QRectF &rect, const QSizeF &size)
110 {
110 {
111 qreal dx = spanX() / size.width();
111 qreal dx = spanX() / size.width();
112 qreal dy = spanY() / size.height();
112 qreal dy = spanY() / size.height();
113
113
114 qreal maxX = m_maxX;
114 qreal maxX = m_maxX;
115 qreal minX = m_minX;
115 qreal minX = m_minX;
116 qreal minY = m_minY;
116 qreal minY = m_minY;
117 qreal maxY = m_maxY;
117 qreal maxY = m_maxY;
118
118
119 maxX = minX + dx * rect.right();
119 maxX = minX + dx * rect.right();
120 minX = minX + dx * rect.left();
120 minX = minX + dx * rect.left();
121 minY = maxY - dy * rect.bottom();
121 minY = maxY - dy * rect.bottom();
122 maxY = maxY - dy * rect.top();
122 maxY = maxY - dy * rect.top();
123
123
124 setRange(minX, maxX, minY, maxY);
124 setRange(minX, maxX, minY, maxY);
125 }
125 }
126
126
127 void Domain::zoomOut(const QRectF &rect, const QSizeF &size)
127 void Domain::zoomOut(const QRectF &rect, const QSizeF &size)
128 {
128 {
129 qreal dx = spanX() / rect.width();
129 qreal dx = spanX() / rect.width();
130 qreal dy = spanY() / rect.height();
130 qreal dy = spanY() / rect.height();
131
131
132 qreal maxX = m_maxX;
132 qreal maxX = m_maxX;
133 qreal minX = m_minX;
133 qreal minX = m_minX;
134 qreal minY = m_minY;
134 qreal minY = m_minY;
135 qreal maxY = m_maxY;
135 qreal maxY = m_maxY;
136
136
137 minX = maxX - dx * rect.right();
137 minX = maxX - dx * rect.right();
138 maxX = minX + dx * size.width();
138 maxX = minX + dx * size.width();
139 maxY = minY + dy * rect.bottom();
139 maxY = minY + dy * rect.bottom();
140 minY = maxY - dy * size.height();
140 minY = maxY - dy * size.height();
141
141
142 setRange(minX, maxX, minY, maxY);
142 setRange(minX, maxX, minY, maxY);
143 }
143 }
144
144
145 void Domain::move(qreal dx, qreal dy, const QSizeF &size)
145 void Domain::move(qreal dx, qreal dy, const QSizeF &size)
146 {
146 {
147 qreal x = spanX() / size.width();
147 qreal x = spanX() / size.width();
148 qreal y = spanY() / size.height();
148 qreal y = spanY() / size.height();
149
149
150 qreal maxX = m_maxX;
150 qreal maxX = m_maxX;
151 qreal minX = m_minX;
151 qreal minX = m_minX;
152 qreal minY = m_minY;
152 qreal minY = m_minY;
153 qreal maxY = m_maxY;
153 qreal maxY = m_maxY;
154
154
155 if (dx != 0) {
155 if (dx != 0) {
156 minX = minX + x * dx;
156 minX = minX + x * dx;
157 maxX = maxX + x * dx;
157 maxX = maxX + x * dx;
158 }
158 }
159 if (dy != 0) {
159 if (dy != 0) {
160 minY = minY + y * dy;
160 minY = minY + y * dy;
161 maxY = maxY + y * dy;
161 maxY = maxY + y * dy;
162 }
162 }
163 setRange(minX, maxX, minY, maxY);
163 setRange(minX, maxX, minY, maxY);
164 }
164 }
165
165
166 void Domain::emitUpdated()
166 void Domain::emitUpdated()
167 {
167 {
168 emit updated();
168 emit updated();
169 }
169 }
170
170
171 void Domain::handleAxisUpdated()
171 void Domain::handleAxisUpdated()
172 {
172 {
173 QAbstractAxisPrivate *axis = qobject_cast<QAbstractAxisPrivate *>(sender());
173 QAbstractAxisPrivate *axis = qobject_cast<QAbstractAxisPrivate *>(sender());
174 Q_ASSERT(axis);
174 Q_ASSERT(axis);
175 axis->setDirty(false);
175 axis->setDirty(false);
176 if (axis->orientation() == Qt::Horizontal)
176 if (axis->orientation() == Qt::Horizontal)
177 setRangeX(axis->min(), axis->max());
177 setRangeX(axis->min(), axis->max());
178 else if (axis->orientation() == Qt::Vertical)
178 else if (axis->orientation() == Qt::Vertical)
179 setRangeY(axis->min(), axis->max());
179 setRangeY(axis->min(), axis->max());
180 }
180 }
181
181
182 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
182 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const Domain &domain1, const Domain &domain2)
183 {
183 {
184 return (qFuzzyIsNull(domain1.m_maxX - domain2.m_maxX) &&
184 return (qFuzzyCompare(domain1.m_maxX, domain2.m_maxX) &&
185 qFuzzyIsNull(domain1.m_maxY - domain2.m_maxY) &&
185 qFuzzyCompare(domain1.m_maxY, domain2.m_maxY) &&
186 qFuzzyIsNull(domain1.m_minX - domain2.m_minX) &&
186 qFuzzyCompare(domain1.m_minX, domain2.m_minX) &&
187 qFuzzyIsNull(domain1.m_minY - domain2.m_minY));
187 qFuzzyCompare(domain1.m_minY, domain2.m_minY));
188 }
188 }
189
189
190
190
191 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
191 bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const Domain &domain1, const Domain &domain2)
192 {
192 {
193 return !(domain1 == domain2);
193 return !(domain1 == domain2);
194 }
194 }
195
195
196
196
197 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
197 QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const Domain &domain)
198 {
198 {
199 dbg.nospace() << "Domain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')';
199 dbg.nospace() << "Domain(" << domain.m_minX << ',' << domain.m_maxX << ',' << domain.m_minY << ',' << domain.m_maxY << ')';
200 return dbg.maybeSpace();
200 return dbg.maybeSpace();
201 }
201 }
202
202
203 #include "moc_domain_p.cpp"
203 #include "moc_domain_p.cpp"
204
204
205 QTCOMMERCIALCHART_END_NAMESPACE
205 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,878 +1,878
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 "qpieseries.h"
21 #include "qpieseries.h"
22 #include "qpieseries_p.h"
22 #include "qpieseries_p.h"
23 #include "qpieslice.h"
23 #include "qpieslice.h"
24 #include "qpieslice_p.h"
24 #include "qpieslice_p.h"
25 #include "pieslicedata_p.h"
25 #include "pieslicedata_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include "charttheme_p.h"
27 #include "charttheme_p.h"
28 #include "qabstractaxis.h"
28 #include "qabstractaxis.h"
29 #include "pieanimation_p.h"
29 #include "pieanimation_p.h"
30
30
31 #include "qpielegendmarker.h"
31 #include "qpielegendmarker.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 \class QPieSeries
36 \class QPieSeries
37 \brief Pie series API for QtCommercial Charts
37 \brief Pie series API for QtCommercial Charts
38
38
39 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
39 The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects.
40 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
40 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
41 The actual slice size is determined by that relative value.
41 The actual slice size is determined by that relative value.
42
42
43 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
43 Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0
44 These relate to the actual chart rectangle.
44 These relate to the actual chart rectangle.
45
45
46 By default the pie is defined as a full pie but it can also be a partial pie.
46 By default the pie is defined as a full pie but it can also be a partial pie.
47 This can be done by setting a starting angle and angle span to the series.
47 This can be done by setting a starting angle and angle span to the series.
48 Full pie is 360 degrees where 0 is at 12 a'clock.
48 Full pie is 360 degrees where 0 is at 12 a'clock.
49
49
50 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
50 See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries.
51 \table 100%
51 \table 100%
52 \row
52 \row
53 \o \image examples_piechart.png
53 \o \image examples_piechart.png
54 \o \image examples_donut.png
54 \o \image examples_donut.png
55 \endtable
55 \endtable
56 */
56 */
57 /*!
57 /*!
58 \qmlclass PieSeries QPieSeries
58 \qmlclass PieSeries QPieSeries
59 \inherits AbstractSeries
59 \inherits AbstractSeries
60
60
61 The following QML shows how to create a simple pie chart.
61 The following QML shows how to create a simple pie chart.
62
62
63 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
63 \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1
64
64
65 \beginfloatleft
65 \beginfloatleft
66 \image demos_qmlchart1.png
66 \image demos_qmlchart1.png
67 \endfloat
67 \endfloat
68 \clearfloat
68 \clearfloat
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QPieSeries::horizontalPosition
72 \property QPieSeries::horizontalPosition
73 \brief Defines the horizontal position of the pie.
73 \brief Defines the horizontal position of the pie.
74
74
75 The value is a relative value to the chart rectangle where:
75 The value is a relative value to the chart rectangle where:
76
76
77 \list
77 \list
78 \o 0.0 is the absolute left.
78 \o 0.0 is the absolute left.
79 \o 1.0 is the absolute right.
79 \o 1.0 is the absolute right.
80 \endlist
80 \endlist
81 Default value is 0.5 (center).
81 Default value is 0.5 (center).
82 \sa verticalPosition
82 \sa verticalPosition
83 */
83 */
84
84
85 /*!
85 /*!
86 \qmlproperty real PieSeries::horizontalPosition
86 \qmlproperty real PieSeries::horizontalPosition
87
87
88 Defines the horizontal position of the pie.
88 Defines the horizontal position of the pie.
89
89
90 The value is a relative value to the chart rectangle where:
90 The value is a relative value to the chart rectangle where:
91
91
92 \list
92 \list
93 \o 0.0 is the absolute left.
93 \o 0.0 is the absolute left.
94 \o 1.0 is the absolute right.
94 \o 1.0 is the absolute right.
95 \endlist
95 \endlist
96 Default value is 0.5 (center).
96 Default value is 0.5 (center).
97 \sa verticalPosition
97 \sa verticalPosition
98 */
98 */
99
99
100 /*!
100 /*!
101 \property QPieSeries::verticalPosition
101 \property QPieSeries::verticalPosition
102 \brief Defines the vertical position of the pie.
102 \brief Defines the vertical position of the pie.
103
103
104 The value is a relative value to the chart rectangle where:
104 The value is a relative value to the chart rectangle where:
105
105
106 \list
106 \list
107 \o 0.0 is the absolute top.
107 \o 0.0 is the absolute top.
108 \o 1.0 is the absolute bottom.
108 \o 1.0 is the absolute bottom.
109 \endlist
109 \endlist
110 Default value is 0.5 (center).
110 Default value is 0.5 (center).
111 \sa horizontalPosition
111 \sa horizontalPosition
112 */
112 */
113
113
114 /*!
114 /*!
115 \qmlproperty real PieSeries::verticalPosition
115 \qmlproperty real PieSeries::verticalPosition
116
116
117 Defines the vertical position of the pie.
117 Defines the vertical position of the pie.
118
118
119 The value is a relative value to the chart rectangle where:
119 The value is a relative value to the chart rectangle where:
120
120
121 \list
121 \list
122 \o 0.0 is the absolute top.
122 \o 0.0 is the absolute top.
123 \o 1.0 is the absolute bottom.
123 \o 1.0 is the absolute bottom.
124 \endlist
124 \endlist
125 Default value is 0.5 (center).
125 Default value is 0.5 (center).
126 \sa horizontalPosition
126 \sa horizontalPosition
127 */
127 */
128
128
129 /*!
129 /*!
130 \property QPieSeries::size
130 \property QPieSeries::size
131 \brief Defines the pie size.
131 \brief Defines the pie size.
132
132
133 The value is a relative value to the chart rectangle where:
133 The value is a relative value to the chart rectangle where:
134
134
135 \list
135 \list
136 \o 0.0 is the minimum size (pie not drawn).
136 \o 0.0 is the minimum size (pie not drawn).
137 \o 1.0 is the maximum size that can fit the chart.
137 \o 1.0 is the maximum size that can fit the chart.
138 \endlist
138 \endlist
139
139
140 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
140 When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size.
141
141
142 Default value is 0.7.
142 Default value is 0.7.
143 */
143 */
144
144
145 /*!
145 /*!
146 \qmlproperty real PieSeries::size
146 \qmlproperty real PieSeries::size
147
147
148 Defines the pie size.
148 Defines the pie size.
149
149
150 The value is a relative value to the chart rectangle where:
150 The value is a relative value to the chart rectangle where:
151
151
152 \list
152 \list
153 \o 0.0 is the minimum size (pie not drawn).
153 \o 0.0 is the minimum size (pie not drawn).
154 \o 1.0 is the maximum size that can fit the chart.
154 \o 1.0 is the maximum size that can fit the chart.
155 \endlist
155 \endlist
156
156
157 Default value is 0.7.
157 Default value is 0.7.
158 */
158 */
159
159
160 /*!
160 /*!
161 \property QPieSeries::holeSize
161 \property QPieSeries::holeSize
162 \brief Defines the donut hole size.
162 \brief Defines the donut hole size.
163
163
164 The value is a relative value to the chart rectangle where:
164 The value is a relative value to the chart rectangle where:
165
165
166 \list
166 \list
167 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
167 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
168 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
168 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
169 \endlist
169 \endlist
170
170
171 The value is never greater then size property.
171 The value is never greater then size property.
172 Default value is 0.0.
172 Default value is 0.0.
173 */
173 */
174
174
175 /*!
175 /*!
176 \qmlproperty real PieSeries::holeSize
176 \qmlproperty real PieSeries::holeSize
177
177
178 Defines the donut hole size.
178 Defines the donut hole size.
179
179
180 The value is a relative value to the chart rectangle where:
180 The value is a relative value to the chart rectangle where:
181
181
182 \list
182 \list
183 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
183 \o 0.0 is the minimum size (full pie drawn, without any hole inside).
184 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
184 \o 1.0 is the maximum size that can fit the chart. (donut has no width)
185 \endlist
185 \endlist
186
186
187 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
187 When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size.
188
188
189 Default value is 0.0.
189 Default value is 0.0.
190 */
190 */
191
191
192 /*!
192 /*!
193 \property QPieSeries::startAngle
193 \property QPieSeries::startAngle
194 \brief Defines the starting angle of the pie.
194 \brief Defines the starting angle of the pie.
195
195
196 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
196 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
197
197
198 Default is value is 0.
198 Default is value is 0.
199 */
199 */
200
200
201 /*!
201 /*!
202 \qmlproperty real PieSeries::startAngle
202 \qmlproperty real PieSeries::startAngle
203
203
204 Defines the starting angle of the pie.
204 Defines the starting angle of the pie.
205
205
206 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
206 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
207
207
208 Default is value is 0.
208 Default is value is 0.
209 */
209 */
210
210
211 /*!
211 /*!
212 \property QPieSeries::endAngle
212 \property QPieSeries::endAngle
213 \brief Defines the ending angle of the pie.
213 \brief Defines the ending angle of the pie.
214
214
215 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
215 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
216
216
217 Default is value is 360.
217 Default is value is 360.
218 */
218 */
219
219
220 /*!
220 /*!
221 \qmlproperty real PieSeries::endAngle
221 \qmlproperty real PieSeries::endAngle
222
222
223 Defines the ending angle of the pie.
223 Defines the ending angle of the pie.
224
224
225 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
225 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
226
226
227 Default is value is 360.
227 Default is value is 360.
228 */
228 */
229
229
230 /*!
230 /*!
231 \property QPieSeries::count
231 \property QPieSeries::count
232
232
233 Number of slices in the series.
233 Number of slices in the series.
234 */
234 */
235
235
236 /*!
236 /*!
237 \qmlproperty int PieSeries::count
237 \qmlproperty int PieSeries::count
238
238
239 Number of slices in the series.
239 Number of slices in the series.
240 */
240 */
241
241
242 /*!
242 /*!
243 \fn void QPieSeries::countChanged()
243 \fn void QPieSeries::countChanged()
244 Emitted when the slice count has changed.
244 Emitted when the slice count has changed.
245 \sa count
245 \sa count
246 */
246 */
247 /*!
247 /*!
248 \qmlsignal PieSeries::onCountChanged()
248 \qmlsignal PieSeries::onCountChanged()
249 Emitted when the slice count has changed.
249 Emitted when the slice count has changed.
250 */
250 */
251
251
252 /*!
252 /*!
253 \property QPieSeries::sum
253 \property QPieSeries::sum
254
254
255 Sum of all slices.
255 Sum of all slices.
256
256
257 The series keeps track of the sum of all slices it holds.
257 The series keeps track of the sum of all slices it holds.
258 */
258 */
259
259
260 /*!
260 /*!
261 \qmlproperty real PieSeries::sum
261 \qmlproperty real PieSeries::sum
262
262
263 Sum of all slices.
263 Sum of all slices.
264
264
265 The series keeps track of the sum of all slices it holds.
265 The series keeps track of the sum of all slices it holds.
266 */
266 */
267
267
268 /*!
268 /*!
269 \fn void QPieSeries::sumChanged()
269 \fn void QPieSeries::sumChanged()
270 Emitted when the sum of all slices has changed.
270 Emitted when the sum of all slices has changed.
271 \sa sum
271 \sa sum
272 */
272 */
273 /*!
273 /*!
274 \qmlsignal PieSeries::onSumChanged()
274 \qmlsignal PieSeries::onSumChanged()
275 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
275 Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you
276 change value of a slice.
276 change value of a slice.
277 */
277 */
278
278
279 /*!
279 /*!
280 \fn void QPieSeries::added(QList<QPieSlice*> slices)
280 \fn void QPieSeries::added(QList<QPieSlice*> slices)
281
281
282 This signal is emitted when \a slices have been added to the series.
282 This signal is emitted when \a slices have been added to the series.
283
283
284 \sa append(), insert()
284 \sa append(), insert()
285 */
285 */
286 /*!
286 /*!
287 \qmlsignal PieSeries::onAdded(PieSlice slice)
287 \qmlsignal PieSeries::onAdded(PieSlice slice)
288 Emitted when \a slice has been added to the series.
288 Emitted when \a slice has been added to the series.
289 */
289 */
290
290
291 /*!
291 /*!
292 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
292 \fn void QPieSeries::removed(QList<QPieSlice*> slices)
293 This signal is emitted when \a slices have been removed from the series.
293 This signal is emitted when \a slices have been removed from the series.
294 \sa remove()
294 \sa remove()
295 */
295 */
296 /*!
296 /*!
297 \qmlsignal PieSeries::onRemoved(PieSlice slice)
297 \qmlsignal PieSeries::onRemoved(PieSlice slice)
298 Emitted when \a slice has been removed from the series.
298 Emitted when \a slice has been removed from the series.
299 */
299 */
300
300
301 /*!
301 /*!
302 \fn void QPieSeries::clicked(QPieSlice* slice)
302 \fn void QPieSeries::clicked(QPieSlice* slice)
303 This signal is emitted when a \a slice has been clicked.
303 This signal is emitted when a \a slice has been clicked.
304 \sa QPieSlice::clicked()
304 \sa QPieSlice::clicked()
305 */
305 */
306 /*!
306 /*!
307 \qmlsignal PieSeries::onClicked(PieSlice slice)
307 \qmlsignal PieSeries::onClicked(PieSlice slice)
308 This signal is emitted when a \a slice has been clicked.
308 This signal is emitted when a \a slice has been clicked.
309 */
309 */
310
310
311 /*!
311 /*!
312 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
312 \fn void QPieSeries::hovered(QPieSlice* slice, bool state)
313 This signal is emitted when user has hovered over or away from the \a slice.
313 This signal is emitted when user has hovered over or away from the \a slice.
314 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
314 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
315 \sa QPieSlice::hovered()
315 \sa QPieSlice::hovered()
316 */
316 */
317 /*!
317 /*!
318 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
318 \qmlsignal PieSeries::onHovered(PieSlice slice, bool state)
319 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
319 This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered
320 over the slice and false when hover has moved away from the slice.
320 over the slice and false when hover has moved away from the slice.
321 */
321 */
322
322
323 /*!
323 /*!
324 \qmlmethod PieSlice PieSeries::at(int index)
324 \qmlmethod PieSlice PieSeries::at(int index)
325 Returns slice at \a index. Returns null if the index is not valid.
325 Returns slice at \a index. Returns null if the index is not valid.
326 */
326 */
327
327
328 /*!
328 /*!
329 \qmlmethod PieSlice PieSeries::find(string label)
329 \qmlmethod PieSlice PieSeries::find(string label)
330 Returns the first slice with \a label. Returns null if the index is not valid.
330 Returns the first slice with \a label. Returns null if the index is not valid.
331 */
331 */
332
332
333 /*!
333 /*!
334 \qmlmethod PieSlice PieSeries::append(string label, real value)
334 \qmlmethod PieSlice PieSeries::append(string label, real value)
335 Adds a new slice with \a label and \a value to the pie.
335 Adds a new slice with \a label and \a value to the pie.
336 */
336 */
337
337
338 /*!
338 /*!
339 \qmlmethod bool PieSeries::remove(PieSlice slice)
339 \qmlmethod bool PieSeries::remove(PieSlice slice)
340 Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise.
340 Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise.
341 */
341 */
342
342
343 /*!
343 /*!
344 \qmlmethod PieSeries::clear()
344 \qmlmethod PieSeries::clear()
345 Removes all slices from the pie.
345 Removes all slices from the pie.
346 */
346 */
347
347
348 /*!
348 /*!
349 Constructs a series object which is a child of \a parent.
349 Constructs a series object which is a child of \a parent.
350 */
350 */
351 QPieSeries::QPieSeries(QObject *parent)
351 QPieSeries::QPieSeries(QObject *parent)
352 : QAbstractSeries(*new QPieSeriesPrivate(this), parent)
352 : QAbstractSeries(*new QPieSeriesPrivate(this), parent)
353 {
353 {
354 Q_D(QPieSeries);
354 Q_D(QPieSeries);
355 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
355 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
356 }
356 }
357
357
358 /*!
358 /*!
359 Destroys the series and its slices.
359 Destroys the series and its slices.
360 */
360 */
361 QPieSeries::~QPieSeries()
361 QPieSeries::~QPieSeries()
362 {
362 {
363 // NOTE: d_prt destroyed by QObject
363 // NOTE: d_prt destroyed by QObject
364 }
364 }
365
365
366 /*!
366 /*!
367 Returns QChartSeries::SeriesTypePie.
367 Returns QChartSeries::SeriesTypePie.
368 */
368 */
369 QAbstractSeries::SeriesType QPieSeries::type() const
369 QAbstractSeries::SeriesType QPieSeries::type() const
370 {
370 {
371 return QAbstractSeries::SeriesTypePie;
371 return QAbstractSeries::SeriesTypePie;
372 }
372 }
373
373
374 /*!
374 /*!
375 Appends a single \a slice to the series.
375 Appends a single \a slice to the series.
376 Slice ownership is passed to the series.
376 Slice ownership is passed to the series.
377
377
378 Returns true if append was succesfull.
378 Returns true if append was succesfull.
379 */
379 */
380 bool QPieSeries::append(QPieSlice *slice)
380 bool QPieSeries::append(QPieSlice *slice)
381 {
381 {
382 return append(QList<QPieSlice *>() << slice);
382 return append(QList<QPieSlice *>() << slice);
383 }
383 }
384
384
385 /*!
385 /*!
386 Appends an array of \a slices to the series.
386 Appends an array of \a slices to the series.
387 Slice ownership is passed to the series.
387 Slice ownership is passed to the series.
388
388
389 Returns true if append was successful.
389 Returns true if append was successful.
390 */
390 */
391 bool QPieSeries::append(QList<QPieSlice *> slices)
391 bool QPieSeries::append(QList<QPieSlice *> slices)
392 {
392 {
393 Q_D(QPieSeries);
393 Q_D(QPieSeries);
394
394
395 if (slices.count() == 0)
395 if (slices.count() == 0)
396 return false;
396 return false;
397
397
398 foreach (QPieSlice *s, slices) {
398 foreach (QPieSlice *s, slices) {
399 if (!s || d->m_slices.contains(s))
399 if (!s || d->m_slices.contains(s))
400 return false;
400 return false;
401 if (s->series()) // already added to some series
401 if (s->series()) // already added to some series
402 return false;
402 return false;
403 }
403 }
404
404
405 foreach (QPieSlice *s, slices) {
405 foreach (QPieSlice *s, slices) {
406 s->setParent(this);
406 s->setParent(this);
407 QPieSlicePrivate::fromSlice(s)->m_series = this;
407 QPieSlicePrivate::fromSlice(s)->m_series = this;
408 d->m_slices << s;
408 d->m_slices << s;
409 }
409 }
410
410
411 d->updateDerivativeData();
411 d->updateDerivativeData();
412
412
413 foreach(QPieSlice * s, slices) {
413 foreach(QPieSlice * s, slices) {
414 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
414 connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
415 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
415 connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked()));
416 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
416 connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
417 }
417 }
418
418
419 emit added(slices);
419 emit added(slices);
420 emit countChanged();
420 emit countChanged();
421
421
422 return true;
422 return true;
423 }
423 }
424
424
425 /*!
425 /*!
426 Appends a single \a slice to the series and returns a reference to the series.
426 Appends a single \a slice to the series and returns a reference to the series.
427 Slice ownership is passed to the series.
427 Slice ownership is passed to the series.
428 */
428 */
429 QPieSeries &QPieSeries::operator << (QPieSlice *slice)
429 QPieSeries &QPieSeries::operator << (QPieSlice *slice)
430 {
430 {
431 append(slice);
431 append(slice);
432 return *this;
432 return *this;
433 }
433 }
434
434
435
435
436 /*!
436 /*!
437 Appends a single slice to the series with give \a value and \a label.
437 Appends a single slice to the series with give \a value and \a label.
438 Slice ownership is passed to the series.
438 Slice ownership is passed to the series.
439 */
439 */
440 QPieSlice *QPieSeries::append(QString label, qreal value)
440 QPieSlice *QPieSeries::append(QString label, qreal value)
441 {
441 {
442 QPieSlice *slice = new QPieSlice(label, value);
442 QPieSlice *slice = new QPieSlice(label, value);
443 append(slice);
443 append(slice);
444 return slice;
444 return slice;
445 }
445 }
446
446
447 /*!
447 /*!
448 Inserts a single \a slice to the series before the slice at \a index position.
448 Inserts a single \a slice to the series before the slice at \a index position.
449 Slice ownership is passed to the series.
449 Slice ownership is passed to the series.
450
450
451 Returns true if insert was successful.
451 Returns true if insert was successful.
452 */
452 */
453 bool QPieSeries::insert(int index, QPieSlice *slice)
453 bool QPieSeries::insert(int index, QPieSlice *slice)
454 {
454 {
455 Q_D(QPieSeries);
455 Q_D(QPieSeries);
456
456
457 if (index < 0 || index > d->m_slices.count())
457 if (index < 0 || index > d->m_slices.count())
458 return false;
458 return false;
459
459
460 if (!slice || d->m_slices.contains(slice))
460 if (!slice || d->m_slices.contains(slice))
461 return false;
461 return false;
462
462
463 if (slice->series()) // already added to some series
463 if (slice->series()) // already added to some series
464 return false;
464 return false;
465
465
466 slice->setParent(this);
466 slice->setParent(this);
467 QPieSlicePrivate::fromSlice(slice)->m_series = this;
467 QPieSlicePrivate::fromSlice(slice)->m_series = this;
468 d->m_slices.insert(index, slice);
468 d->m_slices.insert(index, slice);
469
469
470 d->updateDerivativeData();
470 d->updateDerivativeData();
471
471
472 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
472 connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged()));
473 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
473 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
474 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
474 connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool)));
475
475
476 emit added(QList<QPieSlice *>() << slice);
476 emit added(QList<QPieSlice *>() << slice);
477 emit countChanged();
477 emit countChanged();
478
478
479 return true;
479 return true;
480 }
480 }
481
481
482 /*!
482 /*!
483 Removes a single \a slice from the series and deletes the slice.
483 Removes a single \a slice from the series and deletes the slice.
484
484
485 Do not reference the pointer after this call.
485 Do not reference the pointer after this call.
486
486
487 Returns true if remove was successful.
487 Returns true if remove was successful.
488 */
488 */
489 bool QPieSeries::remove(QPieSlice *slice)
489 bool QPieSeries::remove(QPieSlice *slice)
490 {
490 {
491 Q_D(QPieSeries);
491 Q_D(QPieSeries);
492
492
493 if (!d->m_slices.removeOne(slice))
493 if (!d->m_slices.removeOne(slice))
494 return false;
494 return false;
495
495
496 d->updateDerivativeData();
496 d->updateDerivativeData();
497
497
498 emit removed(QList<QPieSlice *>() << slice);
498 emit removed(QList<QPieSlice *>() << slice);
499 emit countChanged();
499 emit countChanged();
500
500
501 delete slice;
501 delete slice;
502 slice = 0;
502 slice = 0;
503
503
504 return true;
504 return true;
505 }
505 }
506
506
507 /*!
507 /*!
508 Takes a single \a slice from the series. Does not destroy the slice object.
508 Takes a single \a slice from the series. Does not destroy the slice object.
509
509
510 NOTE: The series remains as the slice's parent object. You must set the
510 NOTE: The series remains as the slice's parent object. You must set the
511 parent object to take full ownership.
511 parent object to take full ownership.
512
512
513 Returns true if take was successful.
513 Returns true if take was successful.
514 */
514 */
515 bool QPieSeries::take(QPieSlice *slice)
515 bool QPieSeries::take(QPieSlice *slice)
516 {
516 {
517 Q_D(QPieSeries);
517 Q_D(QPieSeries);
518
518
519 if (!d->m_slices.removeOne(slice))
519 if (!d->m_slices.removeOne(slice))
520 return false;
520 return false;
521
521
522 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
522 QPieSlicePrivate::fromSlice(slice)->m_series = 0;
523 slice->disconnect(d);
523 slice->disconnect(d);
524
524
525 d->updateDerivativeData();
525 d->updateDerivativeData();
526
526
527 emit removed(QList<QPieSlice *>() << slice);
527 emit removed(QList<QPieSlice *>() << slice);
528 emit countChanged();
528 emit countChanged();
529
529
530 return true;
530 return true;
531 }
531 }
532
532
533 /*!
533 /*!
534 Clears all slices from the series.
534 Clears all slices from the series.
535 */
535 */
536 void QPieSeries::clear()
536 void QPieSeries::clear()
537 {
537 {
538 Q_D(QPieSeries);
538 Q_D(QPieSeries);
539 if (d->m_slices.count() == 0)
539 if (d->m_slices.count() == 0)
540 return;
540 return;
541
541
542 QList<QPieSlice *> slices = d->m_slices;
542 QList<QPieSlice *> slices = d->m_slices;
543 foreach (QPieSlice *s, d->m_slices)
543 foreach (QPieSlice *s, d->m_slices)
544 d->m_slices.removeOne(s);
544 d->m_slices.removeOne(s);
545
545
546 d->updateDerivativeData();
546 d->updateDerivativeData();
547
547
548 emit removed(slices);
548 emit removed(slices);
549 emit countChanged();
549 emit countChanged();
550
550
551 foreach (QPieSlice *s, slices)
551 foreach (QPieSlice *s, slices)
552 delete s;
552 delete s;
553 }
553 }
554
554
555 /*!
555 /*!
556 Returns a list of slices that belong to this series.
556 Returns a list of slices that belong to this series.
557 */
557 */
558 QList<QPieSlice *> QPieSeries::slices() const
558 QList<QPieSlice *> QPieSeries::slices() const
559 {
559 {
560 Q_D(const QPieSeries);
560 Q_D(const QPieSeries);
561 return d->m_slices;
561 return d->m_slices;
562 }
562 }
563
563
564 /*!
564 /*!
565 returns the number of the slices in this series.
565 returns the number of the slices in this series.
566 */
566 */
567 int QPieSeries::count() const
567 int QPieSeries::count() const
568 {
568 {
569 Q_D(const QPieSeries);
569 Q_D(const QPieSeries);
570 return d->m_slices.count();
570 return d->m_slices.count();
571 }
571 }
572
572
573 /*!
573 /*!
574 Returns true is the series is empty.
574 Returns true is the series is empty.
575 */
575 */
576 bool QPieSeries::isEmpty() const
576 bool QPieSeries::isEmpty() const
577 {
577 {
578 Q_D(const QPieSeries);
578 Q_D(const QPieSeries);
579 return d->m_slices.isEmpty();
579 return d->m_slices.isEmpty();
580 }
580 }
581
581
582 /*!
582 /*!
583 Returns the sum of all slice values in this series.
583 Returns the sum of all slice values in this series.
584
584
585 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
585 \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage()
586 */
586 */
587 qreal QPieSeries::sum() const
587 qreal QPieSeries::sum() const
588 {
588 {
589 Q_D(const QPieSeries);
589 Q_D(const QPieSeries);
590 return d->m_sum;
590 return d->m_sum;
591 }
591 }
592
592
593 void QPieSeries::setHoleSize(qreal holeSize)
593 void QPieSeries::setHoleSize(qreal holeSize)
594 {
594 {
595 Q_D(QPieSeries);
595 Q_D(QPieSeries);
596 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
596 holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0);
597 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
597 d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize));
598 }
598 }
599
599
600 qreal QPieSeries::holeSize() const
600 qreal QPieSeries::holeSize() const
601 {
601 {
602 Q_D(const QPieSeries);
602 Q_D(const QPieSeries);
603 return d->m_holeRelativeSize;
603 return d->m_holeRelativeSize;
604 }
604 }
605
605
606 void QPieSeries::setHorizontalPosition(qreal relativePosition)
606 void QPieSeries::setHorizontalPosition(qreal relativePosition)
607 {
607 {
608 Q_D(QPieSeries);
608 Q_D(QPieSeries);
609
609
610 if (relativePosition < 0.0)
610 if (relativePosition < 0.0)
611 relativePosition = 0.0;
611 relativePosition = 0.0;
612 if (relativePosition > 1.0)
612 if (relativePosition > 1.0)
613 relativePosition = 1.0;
613 relativePosition = 1.0;
614
614
615 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) {
615 if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) {
616 d->m_pieRelativeHorPos = relativePosition;
616 d->m_pieRelativeHorPos = relativePosition;
617 emit d->horizontalPositionChanged();
617 emit d->horizontalPositionChanged();
618 }
618 }
619 }
619 }
620
620
621 qreal QPieSeries::horizontalPosition() const
621 qreal QPieSeries::horizontalPosition() const
622 {
622 {
623 Q_D(const QPieSeries);
623 Q_D(const QPieSeries);
624 return d->m_pieRelativeHorPos;
624 return d->m_pieRelativeHorPos;
625 }
625 }
626
626
627 void QPieSeries::setVerticalPosition(qreal relativePosition)
627 void QPieSeries::setVerticalPosition(qreal relativePosition)
628 {
628 {
629 Q_D(QPieSeries);
629 Q_D(QPieSeries);
630
630
631 if (relativePosition < 0.0)
631 if (relativePosition < 0.0)
632 relativePosition = 0.0;
632 relativePosition = 0.0;
633 if (relativePosition > 1.0)
633 if (relativePosition > 1.0)
634 relativePosition = 1.0;
634 relativePosition = 1.0;
635
635
636 if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) {
636 if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) {
637 d->m_pieRelativeVerPos = relativePosition;
637 d->m_pieRelativeVerPos = relativePosition;
638 emit d->verticalPositionChanged();
638 emit d->verticalPositionChanged();
639 }
639 }
640 }
640 }
641
641
642 qreal QPieSeries::verticalPosition() const
642 qreal QPieSeries::verticalPosition() const
643 {
643 {
644 Q_D(const QPieSeries);
644 Q_D(const QPieSeries);
645 return d->m_pieRelativeVerPos;
645 return d->m_pieRelativeVerPos;
646 }
646 }
647
647
648 void QPieSeries::setPieSize(qreal relativeSize)
648 void QPieSeries::setPieSize(qreal relativeSize)
649 {
649 {
650 Q_D(QPieSeries);
650 Q_D(QPieSeries);
651 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
651 relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0);
652 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
652 d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize);
653
653
654 }
654 }
655
655
656 qreal QPieSeries::pieSize() const
656 qreal QPieSeries::pieSize() const
657 {
657 {
658 Q_D(const QPieSeries);
658 Q_D(const QPieSeries);
659 return d->m_pieRelativeSize;
659 return d->m_pieRelativeSize;
660 }
660 }
661
661
662
662
663 void QPieSeries::setPieStartAngle(qreal angle)
663 void QPieSeries::setPieStartAngle(qreal angle)
664 {
664 {
665 Q_D(QPieSeries);
665 Q_D(QPieSeries);
666 if (qFuzzyIsNull(d->m_pieStartAngle - angle))
666 if (qFuzzyCompare(d->m_pieStartAngle, angle))
667 return;
667 return;
668 d->m_pieStartAngle = angle;
668 d->m_pieStartAngle = angle;
669 d->updateDerivativeData();
669 d->updateDerivativeData();
670 emit d->pieStartAngleChanged();
670 emit d->pieStartAngleChanged();
671 }
671 }
672
672
673 qreal QPieSeries::pieStartAngle() const
673 qreal QPieSeries::pieStartAngle() const
674 {
674 {
675 Q_D(const QPieSeries);
675 Q_D(const QPieSeries);
676 return d->m_pieStartAngle;
676 return d->m_pieStartAngle;
677 }
677 }
678
678
679 /*!
679 /*!
680 Sets the end angle of the pie.
680 Sets the end angle of the pie.
681
681
682 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
682 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
683
683
684 \a angle must be greater than start angle.
684 \a angle must be greater than start angle.
685
685
686 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
686 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
687 */
687 */
688 void QPieSeries::setPieEndAngle(qreal angle)
688 void QPieSeries::setPieEndAngle(qreal angle)
689 {
689 {
690 Q_D(QPieSeries);
690 Q_D(QPieSeries);
691 if (qFuzzyIsNull(d->m_pieEndAngle - angle))
691 if (qFuzzyCompare(d->m_pieEndAngle, angle))
692 return;
692 return;
693 d->m_pieEndAngle = angle;
693 d->m_pieEndAngle = angle;
694 d->updateDerivativeData();
694 d->updateDerivativeData();
695 emit d->pieEndAngleChanged();
695 emit d->pieEndAngleChanged();
696 }
696 }
697
697
698 /*!
698 /*!
699 Returns the end angle of the pie.
699 Returns the end angle of the pie.
700
700
701 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
701 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
702
702
703 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
703 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
704 */
704 */
705 qreal QPieSeries::pieEndAngle() const
705 qreal QPieSeries::pieEndAngle() const
706 {
706 {
707 Q_D(const QPieSeries);
707 Q_D(const QPieSeries);
708 return d->m_pieEndAngle;
708 return d->m_pieEndAngle;
709 }
709 }
710
710
711 /*!
711 /*!
712 Sets the all the slice labels \a visible or invisible.
712 Sets the all the slice labels \a visible or invisible.
713
713
714 Note that this affects only the current slices in the series.
714 Note that this affects only the current slices in the series.
715 If user adds a new slice the default label visibility is false.
715 If user adds a new slice the default label visibility is false.
716
716
717 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
717 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
718 */
718 */
719 void QPieSeries::setLabelsVisible(bool visible)
719 void QPieSeries::setLabelsVisible(bool visible)
720 {
720 {
721 Q_D(QPieSeries);
721 Q_D(QPieSeries);
722 foreach (QPieSlice *s, d->m_slices)
722 foreach (QPieSlice *s, d->m_slices)
723 s->setLabelVisible(visible);
723 s->setLabelVisible(visible);
724 }
724 }
725
725
726 /*!
726 /*!
727 Sets the all the slice labels \a position
727 Sets the all the slice labels \a position
728
728
729 Note that this affects only the current slices in the series.
729 Note that this affects only the current slices in the series.
730 If user adds a new slice the default label position is LabelOutside
730 If user adds a new slice the default label position is LabelOutside
731
731
732 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
732 \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition()
733 */
733 */
734 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
734 void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position)
735 {
735 {
736 Q_D(QPieSeries);
736 Q_D(QPieSeries);
737 foreach (QPieSlice *s, d->m_slices)
737 foreach (QPieSlice *s, d->m_slices)
738 s->setLabelPosition(position);
738 s->setLabelPosition(position);
739 }
739 }
740
740
741 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
741 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
742
742
743
743
744 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
744 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) :
745 QAbstractSeriesPrivate(parent),
745 QAbstractSeriesPrivate(parent),
746 m_pieRelativeHorPos(0.5),
746 m_pieRelativeHorPos(0.5),
747 m_pieRelativeVerPos(0.5),
747 m_pieRelativeVerPos(0.5),
748 m_pieRelativeSize(0.7),
748 m_pieRelativeSize(0.7),
749 m_pieStartAngle(0),
749 m_pieStartAngle(0),
750 m_pieEndAngle(360),
750 m_pieEndAngle(360),
751 m_sum(0),
751 m_sum(0),
752 m_holeRelativeSize(0.0)
752 m_holeRelativeSize(0.0)
753 {
753 {
754 }
754 }
755
755
756 QPieSeriesPrivate::~QPieSeriesPrivate()
756 QPieSeriesPrivate::~QPieSeriesPrivate()
757 {
757 {
758 }
758 }
759
759
760 void QPieSeriesPrivate::updateDerivativeData()
760 void QPieSeriesPrivate::updateDerivativeData()
761 {
761 {
762 // calculate sum of all slices
762 // calculate sum of all slices
763 qreal sum = 0;
763 qreal sum = 0;
764 foreach (QPieSlice *s, m_slices)
764 foreach (QPieSlice *s, m_slices)
765 sum += s->value();
765 sum += s->value();
766
766
767 if (!qFuzzyIsNull(m_sum - sum)) {
767 if (!qFuzzyCompare(m_sum, sum)) {
768 m_sum = sum;
768 m_sum = sum;
769 emit q_func()->sumChanged();
769 emit q_func()->sumChanged();
770 }
770 }
771
771
772 // nothing to show..
772 // nothing to show..
773 if (qFuzzyIsNull(m_sum))
773 if (qFuzzyCompare(m_sum, 0))
774 return;
774 return;
775
775
776 // update slice attributes
776 // update slice attributes
777 qreal sliceAngle = m_pieStartAngle;
777 qreal sliceAngle = m_pieStartAngle;
778 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
778 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
779 QVector<QPieSlice *> changed;
779 QVector<QPieSlice *> changed;
780 foreach (QPieSlice *s, m_slices) {
780 foreach (QPieSlice *s, m_slices) {
781 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
781 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
782 d->setPercentage(s->value() / m_sum);
782 d->setPercentage(s->value() / m_sum);
783 d->setStartAngle(sliceAngle);
783 d->setStartAngle(sliceAngle);
784 d->setAngleSpan(pieSpan * s->percentage());
784 d->setAngleSpan(pieSpan * s->percentage());
785 sliceAngle += s->angleSpan();
785 sliceAngle += s->angleSpan();
786 }
786 }
787
787
788
788
789 emit calculatedDataChanged();
789 emit calculatedDataChanged();
790 }
790 }
791
791
792 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
792 void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize)
793 {
793 {
794 bool changed = false;
794 bool changed = false;
795
795
796 if (!qFuzzyIsNull(m_holeRelativeSize - innerSize)) {
796 if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) {
797 m_holeRelativeSize = innerSize;
797 m_holeRelativeSize = innerSize;
798 changed = true;
798 changed = true;
799 }
799 }
800
800
801 if (!qFuzzyIsNull(m_pieRelativeSize - outerSize)) {
801 if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) {
802 m_pieRelativeSize = outerSize;
802 m_pieRelativeSize = outerSize;
803 changed = true;
803 changed = true;
804 }
804 }
805
805
806 if (changed)
806 if (changed)
807 emit pieSizeChanged();
807 emit pieSizeChanged();
808 }
808 }
809
809
810 QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series)
810 QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series)
811 {
811 {
812 return series->d_func();
812 return series->d_func();
813 }
813 }
814
814
815 void QPieSeriesPrivate::sliceValueChanged()
815 void QPieSeriesPrivate::sliceValueChanged()
816 {
816 {
817 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
817 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
818 updateDerivativeData();
818 updateDerivativeData();
819 }
819 }
820
820
821 void QPieSeriesPrivate::sliceClicked()
821 void QPieSeriesPrivate::sliceClicked()
822 {
822 {
823 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
823 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
824 Q_ASSERT(m_slices.contains(slice));
824 Q_ASSERT(m_slices.contains(slice));
825 Q_Q(QPieSeries);
825 Q_Q(QPieSeries);
826 emit q->clicked(slice);
826 emit q->clicked(slice);
827 }
827 }
828
828
829 void QPieSeriesPrivate::sliceHovered(bool state)
829 void QPieSeriesPrivate::sliceHovered(bool state)
830 {
830 {
831 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
831 QPieSlice *slice = qobject_cast<QPieSlice *>(sender());
832 Q_ASSERT(m_slices.contains(slice));
832 Q_ASSERT(m_slices.contains(slice));
833 Q_Q(QPieSeries);
833 Q_Q(QPieSeries);
834 emit q->hovered(slice, state);
834 emit q->hovered(slice, state);
835 }
835 }
836
836
837 void QPieSeriesPrivate::scaleDomain(Domain &domain)
837 void QPieSeriesPrivate::scaleDomain(Domain &domain)
838 {
838 {
839 Q_UNUSED(domain);
839 Q_UNUSED(domain);
840 // does not apply to pie
840 // does not apply to pie
841 }
841 }
842
842
843 ChartElement *QPieSeriesPrivate::createGraphics(ChartPresenter *presenter)
843 ChartElement *QPieSeriesPrivate::createGraphics(ChartPresenter *presenter)
844 {
844 {
845 Q_Q(QPieSeries);
845 Q_Q(QPieSeries);
846 PieChartItem *pie = new PieChartItem(q, presenter);
846 PieChartItem *pie = new PieChartItem(q, presenter);
847 if (presenter->animationOptions().testFlag(QChart::SeriesAnimations))
847 if (presenter->animationOptions().testFlag(QChart::SeriesAnimations))
848 pie->setAnimation(new PieAnimation(pie));
848 pie->setAnimation(new PieAnimation(pie));
849 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
849 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
850 return pie;
850 return pie;
851 }
851 }
852
852
853 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
853 QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend)
854 {
854 {
855 Q_Q(QPieSeries);
855 Q_Q(QPieSeries);
856 QList<QLegendMarker*> markers;
856 QList<QLegendMarker*> markers;
857 foreach(QPieSlice* slice, q->slices()) {
857 foreach(QPieSlice* slice, q->slices()) {
858 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
858 QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend);
859 markers << marker;
859 markers << marker;
860 }
860 }
861 return markers;
861 return markers;
862 }
862 }
863
863
864 void QPieSeriesPrivate::initializeAxis(QAbstractAxis *axis)
864 void QPieSeriesPrivate::initializeAxis(QAbstractAxis *axis)
865 {
865 {
866 Q_UNUSED(axis);
866 Q_UNUSED(axis);
867 }
867 }
868
868
869 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
869 QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
870 {
870 {
871 Q_UNUSED(orientation);
871 Q_UNUSED(orientation);
872 return QAbstractAxis::AxisTypeNoAxis;
872 return QAbstractAxis::AxisTypeNoAxis;
873 }
873 }
874
874
875 #include "moc_qpieseries.cpp"
875 #include "moc_qpieseries.cpp"
876 #include "moc_qpieseries_p.cpp"
876 #include "moc_qpieseries_p.cpp"
877
877
878 QTCOMMERCIALCHART_END_NAMESPACE
878 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,783 +1,783
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 "qpieslice.h"
21 #include "qpieslice.h"
22 #include "qpieslice_p.h"
22 #include "qpieslice_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QPieSlice
27 \class QPieSlice
28 \brief Defines a slice in pie series.
28 \brief Defines a slice in pie series.
29
29
30 This object defines the properties of a single slice in a QPieSeries.
30 This object defines the properties of a single slice in a QPieSeries.
31
31
32 In addition to the obvious value and label properties the user can also control
32 In addition to the obvious value and label properties the user can also control
33 the visual appearance of a slice. By modifying the visual appearance also means that
33 the visual appearance of a slice. By modifying the visual appearance also means that
34 the user is overriding the default appearance set by the theme.
34 the user is overriding the default appearance set by the theme.
35
35
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
36 Note that if the user has customized slices and theme is changed all customizations will be lost.
37
37
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
38 To enable user interaction with the pie some basic signals are provided about clicking and hovering.
39 */
39 */
40
40
41 /*!
41 /*!
42 \qmlclass PieSlice QPieSlice
42 \qmlclass PieSlice QPieSlice
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
43 PieSlice defines the properties of a single slice in a PieSeries. The element should be used
44 as a child for a PieSeries. For example:
44 as a child for a PieSeries. For example:
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
45 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
46
46
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
47 An alternative (dynamic) method for adding slices to a PieSeries is using PieSeries.append
48 method.
48 method.
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
49 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 4
50
50
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
51 In that case you may want to use PieSeries.at or PieSeries.find to access the properties of
52 an individual PieSlice instance.
52 an individual PieSlice instance.
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
53 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 5
54 \sa PieSeries
54 \sa PieSeries
55 */
55 */
56
56
57 /*!
57 /*!
58 \enum QPieSlice::LabelPosition
58 \enum QPieSlice::LabelPosition
59
59
60 This enum describes the position of the slice label.
60 This enum describes the position of the slice label.
61
61
62 \value LabelOutside Label is outside the slice with an arm.
62 \value LabelOutside Label is outside the slice with an arm.
63 \value LabelInsideHorizontal Label is centered inside the slice and laid out horizontally.
63 \value LabelInsideHorizontal Label is centered inside the slice and laid out horizontally.
64 \value LabelInsideTangential Label is centered inside the slice and rotated to be parallel to the tangential of the slice's arc.
64 \value LabelInsideTangential Label is centered inside the slice and rotated to be parallel to the tangential of the slice's arc.
65 \value LabelInsideNormal Label is centered inside the slice rotated to be parallel to the normal of the slice's arc.
65 \value LabelInsideNormal Label is centered inside the slice rotated to be parallel to the normal of the slice's arc.
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QPieSlice::label
69 \property QPieSlice::label
70 Label of the slice.
70 Label of the slice.
71 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
71 \sa labelVisible, labelBrush, labelFont, labelArmLengthFactor
72 */
72 */
73 /*!
73 /*!
74 \qmlproperty string PieSlice::label
74 \qmlproperty string PieSlice::label
75 Label (text) of the slice.
75 Label (text) of the slice.
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QPieSlice::labelChanged()
79 \fn void QPieSlice::labelChanged()
80 This signal emitted when the slice label has been changed.
80 This signal emitted when the slice label has been changed.
81 \sa label
81 \sa label
82 */
82 */
83 /*!
83 /*!
84 \qmlsignal PieSlice::onLabelChanged()
84 \qmlsignal PieSlice::onLabelChanged()
85 This signal emitted when the slice label has been changed.
85 This signal emitted when the slice label has been changed.
86 \sa label
86 \sa label
87 */
87 */
88
88
89 /*!
89 /*!
90 \property QPieSlice::value
90 \property QPieSlice::value
91 Value of the slice.
91 Value of the slice.
92 Note that if users sets a negative value it is converted to a positive value.
92 Note that if users sets a negative value it is converted to a positive value.
93 \sa percentage(), QPieSeries::sum()
93 \sa percentage(), QPieSeries::sum()
94 */
94 */
95 /*!
95 /*!
96 \qmlproperty real PieSlice::value
96 \qmlproperty real PieSlice::value
97 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
97 Value of the slice. Note that if users sets a negative value it is converted to a positive value.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QPieSlice::valueChanged()
101 \fn void QPieSlice::valueChanged()
102 This signal is emitted when the slice value changes.
102 This signal is emitted when the slice value changes.
103 \sa value
103 \sa value
104 */
104 */
105 /*!
105 /*!
106 \qmlsignal PieSlice::onValueChanged()
106 \qmlsignal PieSlice::onValueChanged()
107 This signal is emitted when the slice value changes.
107 This signal is emitted when the slice value changes.
108 \sa value
108 \sa value
109 */
109 */
110
110
111 /*!
111 /*!
112 \property QPieSlice::labelVisible
112 \property QPieSlice::labelVisible
113 Defines the visibility of slice label. By default the label is not visible.
113 Defines the visibility of slice label. By default the label is not visible.
114 \sa label, labelBrush, labelFont, labelArmLengthFactor
114 \sa label, labelBrush, labelFont, labelArmLengthFactor
115 */
115 */
116 /*!
116 /*!
117 \qmlproperty bool PieSlice::labelVisible
117 \qmlproperty bool PieSlice::labelVisible
118 Defines the visibility of slice label. By default the label is not visible.
118 Defines the visibility of slice label. By default the label is not visible.
119 */
119 */
120
120
121 /*!
121 /*!
122 \fn void QPieSlice::labelVisibleChanged()
122 \fn void QPieSlice::labelVisibleChanged()
123 This signal emitted when visibility of the slice label has changed.
123 This signal emitted when visibility of the slice label has changed.
124 \sa labelVisible
124 \sa labelVisible
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal PieSlice::onLabelVisibleChanged()
127 \qmlsignal PieSlice::onLabelVisibleChanged()
128 This signal emitted when visibility of the slice label has changed.
128 This signal emitted when visibility of the slice label has changed.
129 \sa labelVisible
129 \sa labelVisible
130 */
130 */
131
131
132 /*!
132 /*!
133 \property QPieSlice::exploded
133 \property QPieSlice::exploded
134 If set to true the slice is "exploded" away from the pie.
134 If set to true the slice is "exploded" away from the pie.
135 \sa explodeDistanceFactor
135 \sa explodeDistanceFactor
136 */
136 */
137 /*!
137 /*!
138 \qmlproperty bool PieSlice::exploded
138 \qmlproperty bool PieSlice::exploded
139 If set to true the slice is "exploded" away from the pie.
139 If set to true the slice is "exploded" away from the pie.
140 \sa explodeDistanceFactor
140 \sa explodeDistanceFactor
141 */
141 */
142
142
143 /*!
143 /*!
144 \property QPieSlice::pen
144 \property QPieSlice::pen
145 Pen used to draw the slice border.
145 Pen used to draw the slice border.
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn void QPieSlice::penChanged()
149 \fn void QPieSlice::penChanged()
150 This signal is emitted when the pen of the slice has changed.
150 This signal is emitted when the pen of the slice has changed.
151 \sa pen
151 \sa pen
152 */
152 */
153
153
154 /*!
154 /*!
155 \property QPieSlice::borderColor
155 \property QPieSlice::borderColor
156 Color used to draw the slice border.
156 Color used to draw the slice border.
157 This is a convenience property for modifying the slice pen.
157 This is a convenience property for modifying the slice pen.
158 \sa pen, borderWidth
158 \sa pen, borderWidth
159 */
159 */
160 /*!
160 /*!
161 \qmlproperty color PieSlice::borderColor
161 \qmlproperty color PieSlice::borderColor
162 Color used to draw the slice border (pen color).
162 Color used to draw the slice border (pen color).
163 \sa borderWidth
163 \sa borderWidth
164 */
164 */
165
165
166 /*!
166 /*!
167 \fn void QPieSlice::borderColorChanged()
167 \fn void QPieSlice::borderColorChanged()
168 This signal is emitted when slice border color changes.
168 This signal is emitted when slice border color changes.
169 \sa pen, borderColor
169 \sa pen, borderColor
170 */
170 */
171 /*!
171 /*!
172 \qmlsignal PieSlice::onBorderColorChanged()
172 \qmlsignal PieSlice::onBorderColorChanged()
173 This signal is emitted when slice border color changes.
173 This signal is emitted when slice border color changes.
174 \sa borderColor
174 \sa borderColor
175 */
175 */
176
176
177 /*!
177 /*!
178 \property QPieSlice::borderWidth
178 \property QPieSlice::borderWidth
179 Width of the slice border.
179 Width of the slice border.
180 This is a convenience property for modifying the slice pen.
180 This is a convenience property for modifying the slice pen.
181 \sa pen, borderColor
181 \sa pen, borderColor
182 */
182 */
183 /*!
183 /*!
184 \qmlproperty int PieSlice::borderWidth
184 \qmlproperty int PieSlice::borderWidth
185 Width of the slice border.
185 Width of the slice border.
186 This is a convenience property for modifying the slice pen.
186 This is a convenience property for modifying the slice pen.
187 \sa borderColor
187 \sa borderColor
188 */
188 */
189
189
190 /*!
190 /*!
191 \fn void QPieSlice::borderWidthChanged()
191 \fn void QPieSlice::borderWidthChanged()
192 This signal is emitted when slice border width changes.
192 This signal is emitted when slice border width changes.
193 \sa pen, borderWidth
193 \sa pen, borderWidth
194 */
194 */
195 /*!
195 /*!
196 \qmlsignal PieSlice::onBorderWidthChanged()
196 \qmlsignal PieSlice::onBorderWidthChanged()
197 This signal is emitted when slice border width changes.
197 This signal is emitted when slice border width changes.
198 \sa borderWidth
198 \sa borderWidth
199 */
199 */
200
200
201 /*!
201 /*!
202 \property QPieSlice::brush
202 \property QPieSlice::brush
203 Brush used to draw the slice.
203 Brush used to draw the slice.
204 */
204 */
205
205
206 /*!
206 /*!
207 \fn void QPieSlice::brushChanged()
207 \fn void QPieSlice::brushChanged()
208 This signal is emitted when the brush of the slice has changed.
208 This signal is emitted when the brush of the slice has changed.
209 \sa brush
209 \sa brush
210 */
210 */
211
211
212 /*!
212 /*!
213 \property QPieSlice::color
213 \property QPieSlice::color
214 Fill (brush) color of the slice.
214 Fill (brush) color of the slice.
215 This is a convenience property for modifying the slice brush.
215 This is a convenience property for modifying the slice brush.
216 \sa brush
216 \sa brush
217 */
217 */
218 /*!
218 /*!
219 \qmlproperty color PieSlice::color
219 \qmlproperty color PieSlice::color
220 Fill (brush) color of the slice.
220 Fill (brush) color of the slice.
221 */
221 */
222
222
223 /*!
223 /*!
224 \fn void QPieSlice::colorChanged()
224 \fn void QPieSlice::colorChanged()
225 This signal is emitted when slice color changes.
225 This signal is emitted when slice color changes.
226 \sa brush
226 \sa brush
227 */
227 */
228 /*!
228 /*!
229 \qmlsignal PieSlice::onColorChanged()
229 \qmlsignal PieSlice::onColorChanged()
230 This signal is emitted when slice color changes.
230 This signal is emitted when slice color changes.
231 */
231 */
232
232
233 /*!
233 /*!
234 \property QPieSlice::labelBrush
234 \property QPieSlice::labelBrush
235 Brush used to draw label and label arm of the slice.
235 Brush used to draw label and label arm of the slice.
236 \sa label, labelVisible, labelFont, labelArmLengthFactor
236 \sa label, labelVisible, labelFont, labelArmLengthFactor
237 */
237 */
238
238
239 /*!
239 /*!
240 \fn void QPieSlice::labelBrushChanged()
240 \fn void QPieSlice::labelBrushChanged()
241 This signal is emitted when the label brush of the slice has changed.
241 This signal is emitted when the label brush of the slice has changed.
242 \sa labelBrush
242 \sa labelBrush
243 */
243 */
244
244
245 /*!
245 /*!
246 \property QPieSlice::labelColor
246 \property QPieSlice::labelColor
247 Color used to draw the slice label.
247 Color used to draw the slice label.
248 This is a convenience property for modifying the slice label brush.
248 This is a convenience property for modifying the slice label brush.
249 \sa labelBrush
249 \sa labelBrush
250 */
250 */
251 /*!
251 /*!
252 \qmlproperty color PieSlice::labelColor
252 \qmlproperty color PieSlice::labelColor
253 Color used to draw the slice label.
253 Color used to draw the slice label.
254 */
254 */
255
255
256 /*!
256 /*!
257 \fn void QPieSlice::labelColorChanged()
257 \fn void QPieSlice::labelColorChanged()
258 This signal is emitted when slice label color changes.
258 This signal is emitted when slice label color changes.
259 \sa labelColor
259 \sa labelColor
260 */
260 */
261 /*!
261 /*!
262 \qmlsignal PieSlice::onLabelColorChanged()
262 \qmlsignal PieSlice::onLabelColorChanged()
263 This signal is emitted when slice label color changes.
263 This signal is emitted when slice label color changes.
264 \sa labelColor
264 \sa labelColor
265 */
265 */
266
266
267 /*!
267 /*!
268 \property QPieSlice::labelFont
268 \property QPieSlice::labelFont
269 Font used for drawing label text.
269 Font used for drawing label text.
270 \sa label, labelVisible, labelArmLengthFactor
270 \sa label, labelVisible, labelArmLengthFactor
271 */
271 */
272
272
273 /*!
273 /*!
274 \fn void QPieSlice::labelFontChanged()
274 \fn void QPieSlice::labelFontChanged()
275 This signal is emitted when the label font of the slice has changed.
275 This signal is emitted when the label font of the slice has changed.
276 \sa labelFont
276 \sa labelFont
277 */
277 */
278
278
279 /*!
279 /*!
280 \qmlproperty Font PieSlice::labelFont
280 \qmlproperty Font PieSlice::labelFont
281
281
282 Defines the font used for slice label.
282 Defines the font used for slice label.
283
283
284 See the \l {Font} {QML Font Element} for detailed documentation.
284 See the \l {Font} {QML Font Element} for detailed documentation.
285
285
286 \sa labelVisible, labelPosition
286 \sa labelVisible, labelPosition
287 */
287 */
288
288
289 /*!
289 /*!
290 \property QPieSlice::labelPosition
290 \property QPieSlice::labelPosition
291 Position of the slice label.
291 Position of the slice label.
292 \sa label, labelVisible
292 \sa label, labelVisible
293 */
293 */
294 /*!
294 /*!
295 \qmlproperty LabelPosition PieSlice::labelPosition
295 \qmlproperty LabelPosition PieSlice::labelPosition
296 Position of the slice label. One of PieSlice.LabelOutside, PieSlice.LabelInsideHorizontal,
296 Position of the slice label. One of PieSlice.LabelOutside, PieSlice.LabelInsideHorizontal,
297 PieSlice.LabelInsideTangential or PieSlice.LabelInsideNormal. By default the position is
297 PieSlice.LabelInsideTangential or PieSlice.LabelInsideNormal. By default the position is
298 PieSlice.LabelOutside.
298 PieSlice.LabelOutside.
299 \sa labelVisible
299 \sa labelVisible
300 */
300 */
301
301
302 /*!
302 /*!
303 \property QPieSlice::labelArmLengthFactor
303 \property QPieSlice::labelArmLengthFactor
304 Defines the length of the label arm.
304 Defines the length of the label arm.
305 The factor is relative to pie radius. For example:
305 The factor is relative to pie radius. For example:
306 1.0 means the length is the same as the radius.
306 1.0 means the length is the same as the radius.
307 0.5 means the length is half of the radius.
307 0.5 means the length is half of the radius.
308 By default the arm length is 0.15
308 By default the arm length is 0.15
309 \sa label, labelVisible, labelBrush, labelFont
309 \sa label, labelVisible, labelBrush, labelFont
310 */
310 */
311 /*!
311 /*!
312 \qmlproperty real PieSlice::labelArmLengthFactor
312 \qmlproperty real PieSlice::labelArmLengthFactor
313 Defines the length of the label arm.
313 Defines the length of the label arm.
314 The factor is relative to pie radius. For example:
314 The factor is relative to pie radius. For example:
315 1.0 means the length is the same as the radius.
315 1.0 means the length is the same as the radius.
316 0.5 means the length is half of the radius.
316 0.5 means the length is half of the radius.
317 By default the arm length is 0.15
317 By default the arm length is 0.15
318 \sa labelVisible
318 \sa labelVisible
319 */
319 */
320
320
321 /*!
321 /*!
322 \property QPieSlice::explodeDistanceFactor
322 \property QPieSlice::explodeDistanceFactor
323 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
323 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
324 The factor is relative to pie radius. For example:
324 The factor is relative to pie radius. For example:
325 1.0 means the distance is the same as the radius.
325 1.0 means the distance is the same as the radius.
326 0.5 means the distance is half of the radius.
326 0.5 means the distance is half of the radius.
327 By default the distance is is 0.15
327 By default the distance is is 0.15
328 \sa exploded
328 \sa exploded
329 */
329 */
330 /*!
330 /*!
331 \qmlproperty real PieSlice::explodeDistanceFactor
331 \qmlproperty real PieSlice::explodeDistanceFactor
332 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
332 When the slice is exploded this factor defines how far the slice is exploded away from the pie.
333 The factor is relative to pie radius. For example:
333 The factor is relative to pie radius. For example:
334 1.0 means the distance is the same as the radius.
334 1.0 means the distance is the same as the radius.
335 0.5 means the distance is half of the radius.
335 0.5 means the distance is half of the radius.
336 By default the distance is is 0.15
336 By default the distance is is 0.15
337 \sa exploded
337 \sa exploded
338 */
338 */
339
339
340 /*!
340 /*!
341 \property QPieSlice::percentage
341 \property QPieSlice::percentage
342 Percentage of the slice compared to the sum of all slices in the series.
342 Percentage of the slice compared to the sum of all slices in the series.
343 The actual value ranges from 0.0 to 1.0.
343 The actual value ranges from 0.0 to 1.0.
344 Updated automatically once the slice is added to the series.
344 Updated automatically once the slice is added to the series.
345 \sa value, QPieSeries::sum
345 \sa value, QPieSeries::sum
346 */
346 */
347 /*!
347 /*!
348 \qmlproperty real PieSlice::percentage
348 \qmlproperty real PieSlice::percentage
349 Percentage of the slice compared to the sum of all slices in the series.
349 Percentage of the slice compared to the sum of all slices in the series.
350 The actual value ranges from 0.0 to 1.0.
350 The actual value ranges from 0.0 to 1.0.
351 Updated automatically once the slice is added to the series.
351 Updated automatically once the slice is added to the series.
352 */
352 */
353
353
354 /*!
354 /*!
355 \fn void QPieSlice::percentageChanged()
355 \fn void QPieSlice::percentageChanged()
356 This signal is emitted when the percentage of the slice has changed.
356 This signal is emitted when the percentage of the slice has changed.
357 \sa percentage
357 \sa percentage
358 */
358 */
359 /*!
359 /*!
360 \qmlsignal void PieSlice::onPercentageChanged()
360 \qmlsignal void PieSlice::onPercentageChanged()
361 This signal is emitted when the percentage of the slice has changed.
361 This signal is emitted when the percentage of the slice has changed.
362 \sa percentage
362 \sa percentage
363 */
363 */
364
364
365 /*!
365 /*!
366 \property QPieSlice::startAngle
366 \property QPieSlice::startAngle
367 Defines the starting angle of this slice in the series it belongs to.
367 Defines the starting angle of this slice in the series it belongs to.
368 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
368 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
369 Updated automatically once the slice is added to the series.
369 Updated automatically once the slice is added to the series.
370 */
370 */
371 /*!
371 /*!
372 \qmlproperty real PieSlice::startAngle
372 \qmlproperty real PieSlice::startAngle
373 Defines the starting angle of this slice in the series it belongs to.
373 Defines the starting angle of this slice in the series it belongs to.
374 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
374 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
375 Updated automatically once the slice is added to the series.
375 Updated automatically once the slice is added to the series.
376 */
376 */
377
377
378 /*!
378 /*!
379 \fn void QPieSlice::startAngleChanged()
379 \fn void QPieSlice::startAngleChanged()
380 This signal is emitted when the starting angle f the slice has changed.
380 This signal is emitted when the starting angle f the slice has changed.
381 \sa startAngle
381 \sa startAngle
382 */
382 */
383 /*!
383 /*!
384 \qmlsignal PieSlice::onStartAngleChanged()
384 \qmlsignal PieSlice::onStartAngleChanged()
385 This signal is emitted when the starting angle f the slice has changed.
385 This signal is emitted when the starting angle f the slice has changed.
386 \sa startAngle
386 \sa startAngle
387 */
387 */
388
388
389 /*!
389 /*!
390 \property QPieSlice::angleSpan
390 \property QPieSlice::angleSpan
391 Span of the slice in degrees.
391 Span of the slice in degrees.
392 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
392 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
393 Updated automatically once the slice is added to the series.
393 Updated automatically once the slice is added to the series.
394 */
394 */
395 /*!
395 /*!
396 \qmlproperty real PieSlice::angleSpan
396 \qmlproperty real PieSlice::angleSpan
397 Span of the slice in degrees.
397 Span of the slice in degrees.
398 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
398 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
399 Updated automatically once the slice is added to the series.
399 Updated automatically once the slice is added to the series.
400 */
400 */
401
401
402 /*!
402 /*!
403 \fn void QPieSlice::angleSpanChanged()
403 \fn void QPieSlice::angleSpanChanged()
404 This signal is emitted when the angle span of the slice has changed.
404 This signal is emitted when the angle span of the slice has changed.
405 \sa angleSpan
405 \sa angleSpan
406 */
406 */
407 /*!
407 /*!
408 \qmlsignal PieSlice::onAngleSpanChanged()
408 \qmlsignal PieSlice::onAngleSpanChanged()
409 This signal is emitted when the angle span of the slice has changed.
409 This signal is emitted when the angle span of the slice has changed.
410 \sa angleSpan
410 \sa angleSpan
411 */
411 */
412
412
413 /*!
413 /*!
414 \fn void QPieSlice::clicked()
414 \fn void QPieSlice::clicked()
415 This signal is emitted when user has clicked the slice.
415 This signal is emitted when user has clicked the slice.
416 \sa QPieSeries::clicked()
416 \sa QPieSeries::clicked()
417 */
417 */
418 /*!
418 /*!
419 \qmlsignal PieSlice::onClicked()
419 \qmlsignal PieSlice::onClicked()
420 This signal is emitted when user has clicked the slice.
420 This signal is emitted when user has clicked the slice.
421 */
421 */
422
422
423 /*!
423 /*!
424 \fn void QPieSlice::hovered(bool state)
424 \fn void QPieSlice::hovered(bool state)
425 This signal is emitted when user has hovered over or away from the slice.
425 This signal is emitted when user has hovered over or away from the slice.
426 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
426 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
427 \sa QPieSeries::hovered()
427 \sa QPieSeries::hovered()
428 */
428 */
429 /*!
429 /*!
430 \qmlsignal PieSlice::onHovered(bool state)
430 \qmlsignal PieSlice::onHovered(bool state)
431 This signal is emitted when user has hovered over or away from the slice.
431 This signal is emitted when user has hovered over or away from the slice.
432 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
432 \a state is true when user has hovered over the slice and false when hover has moved away from the slice.
433 */
433 */
434
434
435 /*!
435 /*!
436 Constructs an empty slice with a \a parent.
436 Constructs an empty slice with a \a parent.
437 \sa QPieSeries::append(), QPieSeries::insert()
437 \sa QPieSeries::append(), QPieSeries::insert()
438 */
438 */
439 QPieSlice::QPieSlice(QObject *parent)
439 QPieSlice::QPieSlice(QObject *parent)
440 : QObject(parent),
440 : QObject(parent),
441 d_ptr(new QPieSlicePrivate(this))
441 d_ptr(new QPieSlicePrivate(this))
442 {
442 {
443
443
444 }
444 }
445
445
446 /*!
446 /*!
447 Constructs an empty slice with given \a value, \a label and a \a parent.
447 Constructs an empty slice with given \a value, \a label and a \a parent.
448 \sa QPieSeries::append(), QPieSeries::insert()
448 \sa QPieSeries::append(), QPieSeries::insert()
449 */
449 */
450 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
450 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
451 : QObject(parent),
451 : QObject(parent),
452 d_ptr(new QPieSlicePrivate(this))
452 d_ptr(new QPieSlicePrivate(this))
453 {
453 {
454 setValue(value);
454 setValue(value);
455 setLabel(label);
455 setLabel(label);
456 }
456 }
457
457
458 /*!
458 /*!
459 Destroys the slice.
459 Destroys the slice.
460 User should not delete the slice if it has been added to the series.
460 User should not delete the slice if it has been added to the series.
461 */
461 */
462 QPieSlice::~QPieSlice()
462 QPieSlice::~QPieSlice()
463 {
463 {
464
464
465 }
465 }
466
466
467 void QPieSlice::setLabel(QString label)
467 void QPieSlice::setLabel(QString label)
468 {
468 {
469 if (d_ptr->m_data.m_labelText != label) {
469 if (d_ptr->m_data.m_labelText != label) {
470 d_ptr->m_data.m_labelText = label;
470 d_ptr->m_data.m_labelText = label;
471 emit labelChanged();
471 emit labelChanged();
472 }
472 }
473 }
473 }
474
474
475 QString QPieSlice::label() const
475 QString QPieSlice::label() const
476 {
476 {
477 return d_ptr->m_data.m_labelText;
477 return d_ptr->m_data.m_labelText;
478 }
478 }
479
479
480 void QPieSlice::setValue(qreal value)
480 void QPieSlice::setValue(qreal value)
481 {
481 {
482 value = qAbs(value); // negative values not allowed
482 value = qAbs(value); // negative values not allowed
483 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
483 if (!qFuzzyCompare(d_ptr->m_data.m_value, value)) {
484 d_ptr->m_data.m_value = value;
484 d_ptr->m_data.m_value = value;
485 emit valueChanged();
485 emit valueChanged();
486 }
486 }
487 }
487 }
488
488
489 qreal QPieSlice::value() const
489 qreal QPieSlice::value() const
490 {
490 {
491 return d_ptr->m_data.m_value;
491 return d_ptr->m_data.m_value;
492 }
492 }
493
493
494 void QPieSlice::setLabelVisible(bool visible)
494 void QPieSlice::setLabelVisible(bool visible)
495 {
495 {
496 if (d_ptr->m_data.m_isLabelVisible != visible) {
496 if (d_ptr->m_data.m_isLabelVisible != visible) {
497 d_ptr->m_data.m_isLabelVisible = visible;
497 d_ptr->m_data.m_isLabelVisible = visible;
498 emit labelVisibleChanged();
498 emit labelVisibleChanged();
499 }
499 }
500 }
500 }
501
501
502 bool QPieSlice::isLabelVisible() const
502 bool QPieSlice::isLabelVisible() const
503 {
503 {
504 return d_ptr->m_data.m_isLabelVisible;
504 return d_ptr->m_data.m_isLabelVisible;
505 }
505 }
506
506
507 void QPieSlice::setExploded(bool exploded)
507 void QPieSlice::setExploded(bool exploded)
508 {
508 {
509 if (d_ptr->m_data.m_isExploded != exploded) {
509 if (d_ptr->m_data.m_isExploded != exploded) {
510 d_ptr->m_data.m_isExploded = exploded;
510 d_ptr->m_data.m_isExploded = exploded;
511 emit d_ptr->explodedChanged();
511 emit d_ptr->explodedChanged();
512 }
512 }
513 }
513 }
514
514
515 QPieSlice::LabelPosition QPieSlice::labelPosition()
515 QPieSlice::LabelPosition QPieSlice::labelPosition()
516 {
516 {
517 return d_ptr->m_data.m_labelPosition;
517 return d_ptr->m_data.m_labelPosition;
518 }
518 }
519
519
520 void QPieSlice::setLabelPosition(LabelPosition position)
520 void QPieSlice::setLabelPosition(LabelPosition position)
521 {
521 {
522 if (d_ptr->m_data.m_labelPosition != position) {
522 if (d_ptr->m_data.m_labelPosition != position) {
523 d_ptr->m_data.m_labelPosition = position;
523 d_ptr->m_data.m_labelPosition = position;
524 emit d_ptr->labelPositionChanged();
524 emit d_ptr->labelPositionChanged();
525 }
525 }
526 }
526 }
527
527
528 bool QPieSlice::isExploded() const
528 bool QPieSlice::isExploded() const
529 {
529 {
530 return d_ptr->m_data.m_isExploded;
530 return d_ptr->m_data.m_isExploded;
531 }
531 }
532
532
533 void QPieSlice::setPen(const QPen &pen)
533 void QPieSlice::setPen(const QPen &pen)
534 {
534 {
535 d_ptr->setPen(pen, false);
535 d_ptr->setPen(pen, false);
536 }
536 }
537
537
538 QPen QPieSlice::pen() const
538 QPen QPieSlice::pen() const
539 {
539 {
540 return d_ptr->m_data.m_slicePen;
540 return d_ptr->m_data.m_slicePen;
541 }
541 }
542
542
543 QColor QPieSlice::borderColor()
543 QColor QPieSlice::borderColor()
544 {
544 {
545 return pen().color();
545 return pen().color();
546 }
546 }
547
547
548 void QPieSlice::setBorderColor(QColor color)
548 void QPieSlice::setBorderColor(QColor color)
549 {
549 {
550 QPen p = pen();
550 QPen p = pen();
551 if (color != p.color()) {
551 if (color != p.color()) {
552 p.setColor(color);
552 p.setColor(color);
553 setPen(p);
553 setPen(p);
554 }
554 }
555 }
555 }
556
556
557 int QPieSlice::borderWidth()
557 int QPieSlice::borderWidth()
558 {
558 {
559 return pen().width();
559 return pen().width();
560 }
560 }
561
561
562 void QPieSlice::setBorderWidth(int width)
562 void QPieSlice::setBorderWidth(int width)
563 {
563 {
564 QPen p = pen();
564 QPen p = pen();
565 if (width != p.width()) {
565 if (width != p.width()) {
566 p.setWidth(width);
566 p.setWidth(width);
567 setPen(p);
567 setPen(p);
568 }
568 }
569 }
569 }
570
570
571 void QPieSlice::setBrush(const QBrush &brush)
571 void QPieSlice::setBrush(const QBrush &brush)
572 {
572 {
573 d_ptr->setBrush(brush, false);
573 d_ptr->setBrush(brush, false);
574 }
574 }
575
575
576 QBrush QPieSlice::brush() const
576 QBrush QPieSlice::brush() const
577 {
577 {
578 return d_ptr->m_data.m_sliceBrush;
578 return d_ptr->m_data.m_sliceBrush;
579 }
579 }
580
580
581 QColor QPieSlice::color()
581 QColor QPieSlice::color()
582 {
582 {
583 return brush().color();
583 return brush().color();
584 }
584 }
585
585
586 void QPieSlice::setColor(QColor color)
586 void QPieSlice::setColor(QColor color)
587 {
587 {
588 QBrush b = brush();
588 QBrush b = brush();
589
589
590 if (b == QBrush())
590 if (b == QBrush())
591 b.setStyle(Qt::SolidPattern);
591 b.setStyle(Qt::SolidPattern);
592 b.setColor(color);
592 b.setColor(color);
593 setBrush(b);
593 setBrush(b);
594 }
594 }
595
595
596 void QPieSlice::setLabelBrush(const QBrush &brush)
596 void QPieSlice::setLabelBrush(const QBrush &brush)
597 {
597 {
598 d_ptr->setLabelBrush(brush, false);
598 d_ptr->setLabelBrush(brush, false);
599 }
599 }
600
600
601 QBrush QPieSlice::labelBrush() const
601 QBrush QPieSlice::labelBrush() const
602 {
602 {
603 return d_ptr->m_data.m_labelBrush;
603 return d_ptr->m_data.m_labelBrush;
604 }
604 }
605
605
606 QColor QPieSlice::labelColor()
606 QColor QPieSlice::labelColor()
607 {
607 {
608 return labelBrush().color();
608 return labelBrush().color();
609 }
609 }
610
610
611 void QPieSlice::setLabelColor(QColor color)
611 void QPieSlice::setLabelColor(QColor color)
612 {
612 {
613 QBrush b = labelBrush();
613 QBrush b = labelBrush();
614 if (color != b.color()) {
614 if (color != b.color()) {
615 b.setColor(color);
615 b.setColor(color);
616 setLabelBrush(b);
616 setLabelBrush(b);
617 }
617 }
618 }
618 }
619
619
620 void QPieSlice::setLabelFont(const QFont &font)
620 void QPieSlice::setLabelFont(const QFont &font)
621 {
621 {
622 d_ptr->setLabelFont(font, false);
622 d_ptr->setLabelFont(font, false);
623 }
623 }
624
624
625 QFont QPieSlice::labelFont() const
625 QFont QPieSlice::labelFont() const
626 {
626 {
627 return d_ptr->m_data.m_labelFont;
627 return d_ptr->m_data.m_labelFont;
628 }
628 }
629
629
630 void QPieSlice::setLabelArmLengthFactor(qreal factor)
630 void QPieSlice::setLabelArmLengthFactor(qreal factor)
631 {
631 {
632 if (!qFuzzyIsNull(d_ptr->m_data.m_labelArmLengthFactor - factor)) {
632 if (!qFuzzyCompare(d_ptr->m_data.m_labelArmLengthFactor, factor)) {
633 d_ptr->m_data.m_labelArmLengthFactor = factor;
633 d_ptr->m_data.m_labelArmLengthFactor = factor;
634 emit d_ptr->labelArmLengthFactorChanged();
634 emit d_ptr->labelArmLengthFactorChanged();
635 }
635 }
636 }
636 }
637
637
638 qreal QPieSlice::labelArmLengthFactor() const
638 qreal QPieSlice::labelArmLengthFactor() const
639 {
639 {
640 return d_ptr->m_data.m_labelArmLengthFactor;
640 return d_ptr->m_data.m_labelArmLengthFactor;
641 }
641 }
642
642
643 void QPieSlice::setExplodeDistanceFactor(qreal factor)
643 void QPieSlice::setExplodeDistanceFactor(qreal factor)
644 {
644 {
645 if (!qFuzzyIsNull(d_ptr->m_data.m_explodeDistanceFactor - factor)) {
645 if (!qFuzzyCompare(d_ptr->m_data.m_explodeDistanceFactor, factor)) {
646 d_ptr->m_data.m_explodeDistanceFactor = factor;
646 d_ptr->m_data.m_explodeDistanceFactor = factor;
647 emit d_ptr->explodeDistanceFactorChanged();
647 emit d_ptr->explodeDistanceFactorChanged();
648 }
648 }
649 }
649 }
650
650
651 qreal QPieSlice::explodeDistanceFactor() const
651 qreal QPieSlice::explodeDistanceFactor() const
652 {
652 {
653 return d_ptr->m_data.m_explodeDistanceFactor;
653 return d_ptr->m_data.m_explodeDistanceFactor;
654 }
654 }
655
655
656 qreal QPieSlice::percentage() const
656 qreal QPieSlice::percentage() const
657 {
657 {
658 return d_ptr->m_data.m_percentage;
658 return d_ptr->m_data.m_percentage;
659 }
659 }
660
660
661 qreal QPieSlice::startAngle() const
661 qreal QPieSlice::startAngle() const
662 {
662 {
663 return d_ptr->m_data.m_startAngle;
663 return d_ptr->m_data.m_startAngle;
664 }
664 }
665
665
666 qreal QPieSlice::angleSpan() const
666 qreal QPieSlice::angleSpan() const
667 {
667 {
668 return d_ptr->m_data.m_angleSpan;
668 return d_ptr->m_data.m_angleSpan;
669 }
669 }
670
670
671 /*!
671 /*!
672 Returns the series that this slice belongs to.
672 Returns the series that this slice belongs to.
673
673
674 \sa QPieSeries::append()
674 \sa QPieSeries::append()
675 */
675 */
676 QPieSeries *QPieSlice::series() const
676 QPieSeries *QPieSlice::series() const
677 {
677 {
678 return d_ptr->m_series;
678 return d_ptr->m_series;
679 }
679 }
680
680
681 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
681 QPieSlicePrivate::QPieSlicePrivate(QPieSlice *parent)
682 : QObject(parent),
682 : QObject(parent),
683 q_ptr(parent),
683 q_ptr(parent),
684 m_series(0)
684 m_series(0)
685 {
685 {
686
686
687 }
687 }
688
688
689 QPieSlicePrivate::~QPieSlicePrivate()
689 QPieSlicePrivate::~QPieSlicePrivate()
690 {
690 {
691
691
692 }
692 }
693
693
694 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
694 QPieSlicePrivate *QPieSlicePrivate::fromSlice(QPieSlice *slice)
695 {
695 {
696 return slice->d_func();
696 return slice->d_func();
697 }
697 }
698
698
699 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
699 void QPieSlicePrivate::setPen(const QPen &pen, bool themed)
700 {
700 {
701 if (m_data.m_slicePen != pen) {
701 if (m_data.m_slicePen != pen) {
702
702
703 QPen oldPen = m_data.m_slicePen;
703 QPen oldPen = m_data.m_slicePen;
704
704
705 m_data.m_slicePen = pen;
705 m_data.m_slicePen = pen;
706 m_data.m_slicePen.setThemed(themed);
706 m_data.m_slicePen.setThemed(themed);
707
707
708 emit q_ptr->penChanged();
708 emit q_ptr->penChanged();
709 if (oldPen.color() != pen.color())
709 if (oldPen.color() != pen.color())
710 emit q_ptr->borderColorChanged();
710 emit q_ptr->borderColorChanged();
711 if (oldPen.width() != pen.width())
711 if (oldPen.width() != pen.width())
712 emit q_ptr->borderWidthChanged();
712 emit q_ptr->borderWidthChanged();
713 }
713 }
714 }
714 }
715
715
716 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
716 void QPieSlicePrivate::setBrush(const QBrush &brush, bool themed)
717 {
717 {
718 if (m_data.m_sliceBrush != brush) {
718 if (m_data.m_sliceBrush != brush) {
719
719
720 QBrush oldBrush = m_data.m_sliceBrush;
720 QBrush oldBrush = m_data.m_sliceBrush;
721
721
722 m_data.m_sliceBrush = brush;
722 m_data.m_sliceBrush = brush;
723 m_data.m_sliceBrush.setThemed(themed);
723 m_data.m_sliceBrush.setThemed(themed);
724
724
725 emit q_ptr->brushChanged();
725 emit q_ptr->brushChanged();
726 if (oldBrush.color() != brush.color())
726 if (oldBrush.color() != brush.color())
727 emit q_ptr->colorChanged();
727 emit q_ptr->colorChanged();
728 }
728 }
729 }
729 }
730
730
731 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
731 void QPieSlicePrivate::setLabelBrush(const QBrush &brush, bool themed)
732 {
732 {
733 if (m_data.m_labelBrush != brush) {
733 if (m_data.m_labelBrush != brush) {
734
734
735 QBrush oldBrush = m_data.m_labelBrush;
735 QBrush oldBrush = m_data.m_labelBrush;
736
736
737 m_data.m_labelBrush = brush;
737 m_data.m_labelBrush = brush;
738 m_data.m_labelBrush.setThemed(themed);
738 m_data.m_labelBrush.setThemed(themed);
739
739
740 emit q_ptr->labelBrushChanged();
740 emit q_ptr->labelBrushChanged();
741 if (oldBrush.color() != brush.color())
741 if (oldBrush.color() != brush.color())
742 emit q_ptr->labelColorChanged();
742 emit q_ptr->labelColorChanged();
743 }
743 }
744 }
744 }
745
745
746 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
746 void QPieSlicePrivate::setLabelFont(const QFont &font, bool themed)
747 {
747 {
748 if (m_data.m_labelFont != font) {
748 if (m_data.m_labelFont != font) {
749 m_data.m_labelFont = font;
749 m_data.m_labelFont = font;
750 m_data.m_labelFont.setThemed(themed);
750 m_data.m_labelFont.setThemed(themed);
751 emit q_ptr->labelFontChanged();
751 emit q_ptr->labelFontChanged();
752 }
752 }
753 }
753 }
754
754
755 void QPieSlicePrivate::setPercentage(qreal percentage)
755 void QPieSlicePrivate::setPercentage(qreal percentage)
756 {
756 {
757 if (!qFuzzyIsNull(m_data.m_percentage - percentage)) {
757 if (!qFuzzyCompare(m_data.m_percentage, percentage)) {
758 m_data.m_percentage = percentage;
758 m_data.m_percentage = percentage;
759 emit q_ptr->percentageChanged();
759 emit q_ptr->percentageChanged();
760 }
760 }
761 }
761 }
762
762
763 void QPieSlicePrivate::setStartAngle(qreal angle)
763 void QPieSlicePrivate::setStartAngle(qreal angle)
764 {
764 {
765 if (!qFuzzyIsNull(m_data.m_startAngle - angle)) {
765 if (!qFuzzyCompare(m_data.m_startAngle, angle)) {
766 m_data.m_startAngle = angle;
766 m_data.m_startAngle = angle;
767 emit q_ptr->startAngleChanged();
767 emit q_ptr->startAngleChanged();
768 }
768 }
769 }
769 }
770
770
771 void QPieSlicePrivate::setAngleSpan(qreal span)
771 void QPieSlicePrivate::setAngleSpan(qreal span)
772 {
772 {
773 if (!qFuzzyIsNull(m_data.m_angleSpan - span)) {
773 if (!qFuzzyCompare(m_data.m_angleSpan, span)) {
774 m_data.m_angleSpan = span;
774 m_data.m_angleSpan = span;
775 emit q_ptr->angleSpanChanged();
775 emit q_ptr->angleSpanChanged();
776 }
776 }
777 }
777 }
778
778
779 QTCOMMERCIALCHART_END_NAMESPACE
779 QTCOMMERCIALCHART_END_NAMESPACE
780
780
781 QTCOMMERCIALCHART_USE_NAMESPACE
781 QTCOMMERCIALCHART_USE_NAMESPACE
782 #include "moc_qpieslice.cpp"
782 #include "moc_qpieslice.cpp"
783 #include "moc_qpieslice_p.cpp"
783 #include "moc_qpieslice_p.cpp"
@@ -1,505 +1,505
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 "qchart.h"
21 #include "qchart.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "legendscroller_p.h"
23 #include "legendscroller_p.h"
24 #include "qlegend_p.h"
24 #include "qlegend_p.h"
25 #include "chartbackground_p.h"
25 #include "chartbackground_p.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include "chartlayout_p.h"
27 #include "chartlayout_p.h"
28 #include <QGraphicsScene>
28 #include <QGraphicsScene>
29 #include <QGraphicsSceneResizeEvent>
29 #include <QGraphicsSceneResizeEvent>
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \enum QChart::ChartTheme
34 \enum QChart::ChartTheme
35
35
36 This enum describes the theme used by the chart.
36 This enum describes the theme used by the chart.
37
37
38 \value ChartThemeLight The default theme
38 \value ChartThemeLight The default theme
39 \value ChartThemeBlueCerulean
39 \value ChartThemeBlueCerulean
40 \value ChartThemeDark
40 \value ChartThemeDark
41 \value ChartThemeBrownSand
41 \value ChartThemeBrownSand
42 \value ChartThemeBlueNcs
42 \value ChartThemeBlueNcs
43 \value ChartThemeHighContrast
43 \value ChartThemeHighContrast
44 \value ChartThemeBlueIcy
44 \value ChartThemeBlueIcy
45 */
45 */
46
46
47 /*!
47 /*!
48 \enum QChart::AnimationOption
48 \enum QChart::AnimationOption
49
49
50 For enabling/disabling animations. Defaults to NoAnimation.
50 For enabling/disabling animations. Defaults to NoAnimation.
51
51
52 \value NoAnimation
52 \value NoAnimation
53 \value GridAxisAnimations
53 \value GridAxisAnimations
54 \value SeriesAnimations
54 \value SeriesAnimations
55 \value AllAnimations
55 \value AllAnimations
56 */
56 */
57
57
58 /*!
58 /*!
59 \class QChart
59 \class QChart
60 \brief QtCommercial chart API.
60 \brief QtCommercial chart API.
61
61
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
62 QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical
63 representation of different types of series and other chart related objects like
63 representation of different types of series and other chart related objects like
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
64 QAxis and QLegend. If you simply want to show a chart in a layout, you can use the
65 convenience class QChartView instead of QChart.
65 convenience class QChartView instead of QChart.
66 \sa QChartView
66 \sa QChartView
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QChart::animationOptions
70 \property QChart::animationOptions
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
71 The animation \a options for the chart. Animations are enabled/disabled based on this setting.
72 */
72 */
73
73
74 /*!
74 /*!
75 \property QChart::backgroundVisible
75 \property QChart::backgroundVisible
76 Whether the chart background is visible or not.
76 Whether the chart background is visible or not.
77 \sa setBackgroundBrush(), setBackgroundPen()
77 \sa setBackgroundBrush(), setBackgroundPen()
78 */
78 */
79
79
80 /*!
80 /*!
81 \property QChart::dropShadowEnabled
81 \property QChart::dropShadowEnabled
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
82 If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
83 shadow effect depends on theme, which means the setting may be changed if you switch to another theme.
84 */
84 */
85
85
86 /*!
86 /*!
87 \property QChart::minimumMargins
87 \property QChart::minimumMargins
88 Minimum margins between the plot area (axes) and the edge of the chart widget.
88 Minimum margins between the plot area (axes) and the edge of the chart widget.
89 */
89 */
90
90
91 /*!
91 /*!
92 \property QChart::theme
92 \property QChart::theme
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
93 Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors,
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
94 pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few
95 different themes.
95 different themes.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
96 Note: changing the theme will overwrite all customizations previously applied to the series.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QChart::title
100 \property QChart::title
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
101 Title is the name (label) of a chart. It is shown as a headline on top of the chart.
102 */
102 */
103
103
104 /*!
104 /*!
105 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
105 Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor.
106 */
106 */
107 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
107 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
108 : QGraphicsWidget(parent, wFlags),
108 : QGraphicsWidget(parent, wFlags),
109 d_ptr(new QChartPrivate())
109 d_ptr(new QChartPrivate())
110 {
110 {
111 d_ptr->m_dataset = new ChartDataSet(this);
111 d_ptr->m_dataset = new ChartDataSet(this);
112 d_ptr->m_presenter = new ChartPresenter(this, d_ptr->m_dataset);
112 d_ptr->m_presenter = new ChartPresenter(this, d_ptr->m_dataset);
113 d_ptr->createConnections();
113 d_ptr->createConnections();
114 d_ptr->m_legend = new LegendScroller(this);
114 d_ptr->m_legend = new LegendScroller(this);
115 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
115 d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false);
116 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
116 //connect(d_ptr->m_presenter, SIGNAL(marginsChanged(QRectF)), this, SIGNAL(marginsChanged(QRectF)));
117 setLayout(d_ptr->m_presenter->layout());
117 setLayout(d_ptr->m_presenter->layout());
118 }
118 }
119
119
120 /*!
120 /*!
121 Destroys the object and it's children, like series and axis objects added to it.
121 Destroys the object and it's children, like series and axis objects added to it.
122 */
122 */
123 QChart::~QChart()
123 QChart::~QChart()
124 {
124 {
125 //delete first presenter , since this is a root of all the graphical items
125 //delete first presenter , since this is a root of all the graphical items
126 setLayout(0);
126 setLayout(0);
127 delete d_ptr->m_presenter;
127 delete d_ptr->m_presenter;
128 d_ptr->m_presenter = 0;
128 d_ptr->m_presenter = 0;
129 }
129 }
130
130
131 /*!
131 /*!
132 Adds the \a series onto the chart and takes the ownership of the object.
132 Adds the \a series onto the chart and takes the ownership of the object.
133 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
133 If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
134 the y axis).
134 the y axis).
135
135
136 \sa removeSeries(), removeAllSeries()
136 \sa removeSeries(), removeAllSeries()
137 */
137 */
138 void QChart::addSeries(QAbstractSeries *series)
138 void QChart::addSeries(QAbstractSeries *series)
139 {
139 {
140 Q_ASSERT(series);
140 Q_ASSERT(series);
141 d_ptr->m_dataset->addSeries(series);
141 d_ptr->m_dataset->addSeries(series);
142 }
142 }
143
143
144 /*!
144 /*!
145 Removes the \a series specified in a perameter from the QChartView.
145 Removes the \a series specified in a perameter from the QChartView.
146 It releses its ownership of the specified QChartSeries object.
146 It releses its ownership of the specified QChartSeries object.
147 It does not delete the pointed QChartSeries data object
147 It does not delete the pointed QChartSeries data object
148 \sa addSeries(), removeAllSeries()
148 \sa addSeries(), removeAllSeries()
149 */
149 */
150 void QChart::removeSeries(QAbstractSeries *series)
150 void QChart::removeSeries(QAbstractSeries *series)
151 {
151 {
152 Q_ASSERT(series);
152 Q_ASSERT(series);
153 d_ptr->m_dataset->removeSeries(series);
153 d_ptr->m_dataset->removeSeries(series);
154 }
154 }
155
155
156 /*!
156 /*!
157 Removes all the QChartSeries that have been added to the QChartView
157 Removes all the QChartSeries that have been added to the QChartView
158 It also deletes the pointed QChartSeries data objects
158 It also deletes the pointed QChartSeries data objects
159 \sa addSeries(), removeSeries()
159 \sa addSeries(), removeSeries()
160 */
160 */
161 void QChart::removeAllSeries()
161 void QChart::removeAllSeries()
162 {
162 {
163 d_ptr->m_dataset->removeAllSeries();
163 d_ptr->m_dataset->removeAllSeries();
164 }
164 }
165
165
166 /*!
166 /*!
167 Sets the \a brush that is used for painting the background of the chart area.
167 Sets the \a brush that is used for painting the background of the chart area.
168 */
168 */
169 void QChart::setBackgroundBrush(const QBrush &brush)
169 void QChart::setBackgroundBrush(const QBrush &brush)
170 {
170 {
171 d_ptr->m_presenter->setBackgroundBrush(brush);
171 d_ptr->m_presenter->setBackgroundBrush(brush);
172 }
172 }
173
173
174 /*!
174 /*!
175 Gets the brush that is used for painting the background of the chart area.
175 Gets the brush that is used for painting the background of the chart area.
176 */
176 */
177 QBrush QChart::backgroundBrush() const
177 QBrush QChart::backgroundBrush() const
178 {
178 {
179 return d_ptr->m_presenter->backgroundBrush();
179 return d_ptr->m_presenter->backgroundBrush();
180 }
180 }
181
181
182 /*!
182 /*!
183 Sets the \a pen that is used for painting the background of the chart area.
183 Sets the \a pen that is used for painting the background of the chart area.
184 */
184 */
185 void QChart::setBackgroundPen(const QPen &pen)
185 void QChart::setBackgroundPen(const QPen &pen)
186 {
186 {
187 d_ptr->m_presenter->setBackgroundPen(pen);
187 d_ptr->m_presenter->setBackgroundPen(pen);
188 }
188 }
189
189
190 /*!
190 /*!
191 Gets the pen that is used for painting the background of the chart area.
191 Gets the pen that is used for painting the background of the chart area.
192 */
192 */
193 QPen QChart::backgroundPen() const
193 QPen QChart::backgroundPen() const
194 {
194 {
195 return d_ptr->m_presenter->backgroundPen();
195 return d_ptr->m_presenter->backgroundPen();
196 }
196 }
197
197
198 /*!
198 /*!
199 Sets the chart \a title. The description text that is drawn above the chart.
199 Sets the chart \a title. The description text that is drawn above the chart.
200 */
200 */
201 void QChart::setTitle(const QString &title)
201 void QChart::setTitle(const QString &title)
202 {
202 {
203 d_ptr->m_presenter->setTitle(title);
203 d_ptr->m_presenter->setTitle(title);
204 }
204 }
205
205
206 /*!
206 /*!
207 Returns the chart title. The description text that is drawn above the chart.
207 Returns the chart title. The description text that is drawn above the chart.
208 */
208 */
209 QString QChart::title() const
209 QString QChart::title() const
210 {
210 {
211 return d_ptr->m_presenter->title();
211 return d_ptr->m_presenter->title();
212 }
212 }
213
213
214 /*!
214 /*!
215 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
215 Sets the \a font that is used for drawing the chart description text that is rendered above the chart.
216 */
216 */
217 void QChart::setTitleFont(const QFont &font)
217 void QChart::setTitleFont(const QFont &font)
218 {
218 {
219 d_ptr->m_presenter->setTitleFont(font);
219 d_ptr->m_presenter->setTitleFont(font);
220 }
220 }
221
221
222 /*!
222 /*!
223 Gets the font that is used for drawing the chart description text that is rendered above the chart.
223 Gets the font that is used for drawing the chart description text that is rendered above the chart.
224 */
224 */
225 QFont QChart::titleFont() const
225 QFont QChart::titleFont() const
226 {
226 {
227 return d_ptr->m_presenter->titleFont();
227 return d_ptr->m_presenter->titleFont();
228 }
228 }
229
229
230 /*!
230 /*!
231 Sets the \a brush used for rendering the title text.
231 Sets the \a brush used for rendering the title text.
232 */
232 */
233 void QChart::setTitleBrush(const QBrush &brush)
233 void QChart::setTitleBrush(const QBrush &brush)
234 {
234 {
235 d_ptr->m_presenter->setTitleBrush(brush);
235 d_ptr->m_presenter->setTitleBrush(brush);
236 }
236 }
237
237
238 /*!
238 /*!
239 Returns the brush used for rendering the title text.
239 Returns the brush used for rendering the title text.
240 */
240 */
241 QBrush QChart::titleBrush() const
241 QBrush QChart::titleBrush() const
242 {
242 {
243 return d_ptr->m_presenter->titleBrush();
243 return d_ptr->m_presenter->titleBrush();
244 }
244 }
245
245
246 void QChart::setTheme(QChart::ChartTheme theme)
246 void QChart::setTheme(QChart::ChartTheme theme)
247 {
247 {
248 d_ptr->m_presenter->setTheme(theme);
248 d_ptr->m_presenter->setTheme(theme);
249 }
249 }
250
250
251 QChart::ChartTheme QChart::theme() const
251 QChart::ChartTheme QChart::theme() const
252 {
252 {
253 return d_ptr->m_presenter->theme();
253 return d_ptr->m_presenter->theme();
254 }
254 }
255
255
256 /*!
256 /*!
257 Zooms in the view by a factor of 2
257 Zooms in the view by a factor of 2
258 */
258 */
259 void QChart::zoomIn()
259 void QChart::zoomIn()
260 {
260 {
261 d_ptr->m_presenter->zoomIn(2.0);
261 d_ptr->m_presenter->zoomIn(2.0);
262 }
262 }
263
263
264 /*!
264 /*!
265 Zooms in the view to a maximum level at which \a rect is still fully visible.
265 Zooms in the view to a maximum level at which \a rect is still fully visible.
266 */
266 */
267 void QChart::zoomIn(const QRectF &rect)
267 void QChart::zoomIn(const QRectF &rect)
268 {
268 {
269 if (!rect.isValid())
269 if (!rect.isValid())
270 return;
270 return;
271 d_ptr->m_presenter->zoomIn(rect);
271 d_ptr->m_presenter->zoomIn(rect);
272 }
272 }
273
273
274 /*!
274 /*!
275 Restores the view zoom level to the previous one.
275 Restores the view zoom level to the previous one.
276 */
276 */
277 void QChart::zoomOut()
277 void QChart::zoomOut()
278 {
278 {
279 d_ptr->m_presenter->zoomOut(2.0);
279 d_ptr->m_presenter->zoomOut(2.0);
280 }
280 }
281
281
282 /*!
282 /*!
283 Zooms in the view by a \a factor.
283 Zooms in the view by a \a factor.
284
284
285 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
285 A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out.
286 */
286 */
287 void QChart::zoom(qreal factor)
287 void QChart::zoom(qreal factor)
288 {
288 {
289 if (qFuzzyIsNull(factor))
289 if (qFuzzyCompare(factor, 0))
290 return;
290 return;
291
291
292 if (qFuzzyCompare(factor, (qreal)1.0))
292 if (qFuzzyCompare(factor, (qreal)1.0))
293 return;
293 return;
294
294
295 if (factor < 0)
295 if (factor < 0)
296 return;
296 return;
297
297
298 if (factor > 1.0)
298 if (factor > 1.0)
299 d_ptr->m_presenter->zoomIn(factor);
299 d_ptr->m_presenter->zoomIn(factor);
300 else
300 else
301 d_ptr->m_presenter->zoomOut(1.0 / factor);
301 d_ptr->m_presenter->zoomOut(1.0 / factor);
302 }
302 }
303
303
304 /*!
304 /*!
305 Returns the pointer to the x axis object of the chart asociated with the specified \a series
305 Returns the pointer to the x axis object of the chart asociated with the specified \a series
306 If no series is provided then pointer to currently visible axis is provided
306 If no series is provided then pointer to currently visible axis is provided
307 */
307 */
308 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
308 QAbstractAxis *QChart::axisX(QAbstractSeries *series) const
309 {
309 {
310 return d_ptr->m_dataset->axisX(series);
310 return d_ptr->m_dataset->axisX(series);
311 }
311 }
312
312
313 /*!
313 /*!
314 Returns the pointer to the y axis object of the chart asociated with the specified \a series
314 Returns the pointer to the y axis object of the chart asociated with the specified \a series
315 If no series is provided then pointer to currently visible axis is provided
315 If no series is provided then pointer to currently visible axis is provided
316 */
316 */
317 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
317 QAbstractAxis *QChart::axisY(QAbstractSeries *series) const
318 {
318 {
319 return d_ptr->m_dataset->axisY(series);
319 return d_ptr->m_dataset->axisY(series);
320 }
320 }
321
321
322 /*!
322 /*!
323 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
323 NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL.
324
324
325 Creates the axes for the chart based on the series that has already been added to the chart.
325 Creates the axes for the chart based on the series that has already been added to the chart.
326
326
327 \table
327 \table
328 \header
328 \header
329 \o Series type
329 \o Series type
330 \o X-axis
330 \o X-axis
331 \o Y-axis
331 \o Y-axis
332 \row
332 \row
333 \o QXYSeries
333 \o QXYSeries
334 \o QValueAxis
334 \o QValueAxis
335 \o QValueAxis
335 \o QValueAxis
336 \row
336 \row
337 \o QBarSeries
337 \o QBarSeries
338 \o QBarCategoryAxis
338 \o QBarCategoryAxis
339 \o QValueAxis
339 \o QValueAxis
340 \row
340 \row
341 \o QPieSeries
341 \o QPieSeries
342 \o None
342 \o None
343 \o None
343 \o None
344 \endtable
344 \endtable
345
345
346 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
346 If there are several QXYSeries derived series added to the chart and no other series type has been added then only one pair of axes is created.
347 If there are sevaral series added of different types then each series gets its own axes pair.
347 If there are sevaral series added of different types then each series gets its own axes pair.
348
348
349 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
349 NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown.
350
350
351 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
351 Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls.
352 QPieSeries does not create any axes.
352 QPieSeries does not create any axes.
353
353
354 \sa axisX(), axisY(), setAxisX(), setAxisY()
354 \sa axisX(), axisY(), setAxisX(), setAxisY()
355 */
355 */
356 void QChart::createDefaultAxes()
356 void QChart::createDefaultAxes()
357 {
357 {
358 d_ptr->m_dataset->createDefaultAxes();
358 d_ptr->m_dataset->createDefaultAxes();
359 }
359 }
360
360
361 /*!
361 /*!
362 Returns the legend object of the chart. Ownership stays in chart.
362 Returns the legend object of the chart. Ownership stays in chart.
363 */
363 */
364 QLegend *QChart::legend() const
364 QLegend *QChart::legend() const
365 {
365 {
366 return d_ptr->m_legend;
366 return d_ptr->m_legend;
367 }
367 }
368
368
369 /*!
369 /*!
370 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
370 Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget.
371 */
371 */
372 void QChart::setMargins(const QMargins &margins)
372 void QChart::setMargins(const QMargins &margins)
373 {
373 {
374 d_ptr->m_presenter->layout()->setMargins(margins);
374 d_ptr->m_presenter->layout()->setMargins(margins);
375 }
375 }
376
376
377 /*!
377 /*!
378 Returns the rect that contains information about margins (distance between chart widget edge and axes).
378 Returns the rect that contains information about margins (distance between chart widget edge and axes).
379 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
379 Individual margins can be obtained by calling left, top, right, bottom on the returned rect.
380 */
380 */
381 QMargins QChart::margins() const
381 QMargins QChart::margins() const
382 {
382 {
383 return d_ptr->m_presenter->layout()->margins();
383 return d_ptr->m_presenter->layout()->margins();
384 }
384 }
385
385
386 /*!
386 /*!
387 Returns the the rect within which the drawing of the chart is done.
387 Returns the the rect within which the drawing of the chart is done.
388 It does not include the area defines by margins.
388 It does not include the area defines by margins.
389 */
389 */
390 QRectF QChart::plotArea() const
390 QRectF QChart::plotArea() const
391 {
391 {
392 return d_ptr->m_presenter->layout()->chartsGeometry();
392 return d_ptr->m_presenter->layout()->chartsGeometry();
393 }
393 }
394
394
395 ///*!
395 ///*!
396 // TODO: Dummy.
396 // TODO: Dummy.
397 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
397 // Adjest the ranges of the axes so that all the data of the specified \a series is visible
398 // */
398 // */
399 //void QChart::adjustViewToSeries(QAbstractSeries* series)
399 //void QChart::adjustViewToSeries(QAbstractSeries* series)
400 //{
400 //{
401 // //
401 // //
402 //}
402 //}
403
403
404 /*!
404 /*!
405 Sets animation \a options for the chart
405 Sets animation \a options for the chart
406 */
406 */
407 void QChart::setAnimationOptions(AnimationOptions options)
407 void QChart::setAnimationOptions(AnimationOptions options)
408 {
408 {
409 d_ptr->m_presenter->setAnimationOptions(options);
409 d_ptr->m_presenter->setAnimationOptions(options);
410 }
410 }
411
411
412 QChart::AnimationOptions QChart::animationOptions() const
412 QChart::AnimationOptions QChart::animationOptions() const
413 {
413 {
414 return d_ptr->m_presenter->animationOptions();
414 return d_ptr->m_presenter->animationOptions();
415 }
415 }
416
416
417 /*!
417 /*!
418 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
418 Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy.
419 */
419 */
420 void QChart::scroll(qreal dx, qreal dy)
420 void QChart::scroll(qreal dx, qreal dy)
421 {
421 {
422 d_ptr->m_presenter->scroll(dx, dy);
422 d_ptr->m_presenter->scroll(dx, dy);
423 }
423 }
424
424
425 void QChart::setBackgroundVisible(bool visible)
425 void QChart::setBackgroundVisible(bool visible)
426 {
426 {
427 d_ptr->m_presenter->setBackgroundVisible(visible);
427 d_ptr->m_presenter->setBackgroundVisible(visible);
428 }
428 }
429
429
430 bool QChart::isBackgroundVisible() const
430 bool QChart::isBackgroundVisible() const
431 {
431 {
432 return d_ptr->m_presenter->isBackgroundVisible();
432 return d_ptr->m_presenter->isBackgroundVisible();
433 }
433 }
434
434
435 void QChart::setDropShadowEnabled(bool enabled)
435 void QChart::setDropShadowEnabled(bool enabled)
436 {
436 {
437 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
437 d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled);
438 }
438 }
439
439
440 bool QChart::isDropShadowEnabled() const
440 bool QChart::isDropShadowEnabled() const
441 {
441 {
442 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
442 return d_ptr->m_presenter->isBackgroundDropShadowEnabled();
443 }
443 }
444
444
445 /*!
445 /*!
446 Returns all the series that are added to the chart.
446 Returns all the series that are added to the chart.
447
447
448 \sa addSeries(), removeSeries(), removeAllSeries()
448 \sa addSeries(), removeSeries(), removeAllSeries()
449 */
449 */
450 QList<QAbstractSeries *> QChart::series() const
450 QList<QAbstractSeries *> QChart::series() const
451 {
451 {
452 return d_ptr->m_dataset->series();
452 return d_ptr->m_dataset->series();
453 }
453 }
454
454
455 /*!
455 /*!
456 Sets \a axis to the chart, which will control the presentation of the \a series
456 Sets \a axis to the chart, which will control the presentation of the \a series
457
457
458 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
458 \sa axisX(), axisY(), setAxisY(), createDefaultAxes()
459 */
459 */
460 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
460 void QChart::setAxisX(QAbstractAxis *axis , QAbstractSeries *series)
461 {
461 {
462 if (axis->alignment() == Qt::AlignLeft || axis->alignment() == Qt::AlignRight)
462 if (axis->alignment() == Qt::AlignLeft || axis->alignment() == Qt::AlignRight)
463 return;
463 return;
464 d_ptr->m_dataset->setAxis(series, axis, Qt::Horizontal);
464 d_ptr->m_dataset->setAxis(series, axis, Qt::Horizontal);
465 }
465 }
466
466
467 /*!
467 /*!
468 Sets \a axis to the chart, which will control the presentation of the \a series
468 Sets \a axis to the chart, which will control the presentation of the \a series
469
469
470 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
470 \sa axisX(), axisY(), setAxisX(), createDefaultAxes()
471 */
471 */
472 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
472 void QChart::setAxisY(QAbstractAxis *axis , QAbstractSeries *series)
473 {
473 {
474 if (axis->alignment() == Qt::AlignTop || axis->alignment() == Qt::AlignBottom)
474 if (axis->alignment() == Qt::AlignTop || axis->alignment() == Qt::AlignBottom)
475 return;
475 return;
476 d_ptr->m_dataset->setAxis(series, axis, Qt::Vertical);
476 d_ptr->m_dataset->setAxis(series, axis, Qt::Vertical);
477 }
477 }
478
478
479 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
479 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
480
480
481 QChartPrivate::QChartPrivate():
481 QChartPrivate::QChartPrivate():
482 m_legend(0),
482 m_legend(0),
483 m_dataset(0),
483 m_dataset(0),
484 m_presenter(0)
484 m_presenter(0)
485 {
485 {
486
486
487 }
487 }
488
488
489 QChartPrivate::~QChartPrivate()
489 QChartPrivate::~QChartPrivate()
490 {
490 {
491
491
492 }
492 }
493
493
494 void QChartPrivate::createConnections()
494 void QChartPrivate::createConnections()
495 {
495 {
496 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
496 QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*,Domain*)));
497 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
497 QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*)));
498 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
498 QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*,Domain*)));
499 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
499 QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*)));
500 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
500 //QObject::connect(m_presenter, SIGNAL(marginsChanged(QRectF)), q_ptr, SIGNAL(marginsChanged(QRectF)));
501 }
501 }
502
502
503 #include "moc_qchart.cpp"
503 #include "moc_qchart.cpp"
504
504
505 QTCOMMERCIALCHART_END_NAMESPACE
505 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,269 +1,269
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 "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qscatterseries_p.h"
22 #include "qscatterseries_p.h"
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26
26
27 /*!
27 /*!
28 \class QScatterSeries
28 \class QScatterSeries
29 \brief The QScatterSeries class is used for making scatter charts.
29 \brief The QScatterSeries class is used for making scatter charts.
30
30
31 \mainclass
31 \mainclass
32
32
33 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
33 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
34 and the vertical axis.
34 and the vertical axis.
35
35
36 \image examples_scatterchart.png
36 \image examples_scatterchart.png
37
37
38 Creating basic scatter chart is simple:
38 Creating basic scatter chart is simple:
39 \code
39 \code
40 QScatterSeries* series = new QScatterSeries();
40 QScatterSeries* series = new QScatterSeries();
41 series->append(0, 6);
41 series->append(0, 6);
42 series->append(2, 4);
42 series->append(2, 4);
43 ...
43 ...
44 chart->addSeries(series);
44 chart->addSeries(series);
45 \endcode
45 \endcode
46 */
46 */
47 /*!
47 /*!
48 \qmlclass ScatterSeries QScatterSeries
48 \qmlclass ScatterSeries QScatterSeries
49 \inherits XYSeries
49 \inherits XYSeries
50
50
51 The following QML shows how to create a chart with two simple scatter series:
51 The following QML shows how to create a chart with two simple scatter series:
52 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
52 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
53
53
54 \beginfloatleft
54 \beginfloatleft
55 \image demos_qmlchart5.png
55 \image demos_qmlchart5.png
56 \endfloat
56 \endfloat
57 \clearfloat
57 \clearfloat
58 */
58 */
59
59
60 /*!
60 /*!
61 \enum QScatterSeries::MarkerShape
61 \enum QScatterSeries::MarkerShape
62
62
63 This enum describes the shape used when rendering marker items.
63 This enum describes the shape used when rendering marker items.
64
64
65 \value MarkerShapeCircle
65 \value MarkerShapeCircle
66 \value MarkerShapeRectangle
66 \value MarkerShapeRectangle
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QScatterSeries::color
70 \property QScatterSeries::color
71 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
71 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
72 \sa QScatterSeries::brush()
72 \sa QScatterSeries::brush()
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QScatterSeries::borderColor
76 \property QScatterSeries::borderColor
77 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
77 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
78 \sa QScatterSeries::pen()
78 \sa QScatterSeries::pen()
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty color ScatterSeries::borderColor
81 \qmlproperty color ScatterSeries::borderColor
82 Border (pen) color of the series.
82 Border (pen) color of the series.
83 */
83 */
84
84
85 /*!
85 /*!
86 \qmlproperty real ScatterSeries::borderWidth
86 \qmlproperty real ScatterSeries::borderWidth
87 The width of the border line. By default the width is 2.0.
87 The width of the border line. By default the width is 2.0.
88 */
88 */
89
89
90 /*!
90 /*!
91 \property QScatterSeries::markerShape
91 \property QScatterSeries::markerShape
92 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
92 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
93 */
93 */
94 /*!
94 /*!
95 \qmlproperty MarkerShape ScatterSeries::markerShape
95 \qmlproperty MarkerShape ScatterSeries::markerShape
96 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
96 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
97 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
97 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
98 The default shape is ScatterSeries.MarkerShapeCircle.
98 The default shape is ScatterSeries.MarkerShapeCircle.
99 */
99 */
100
100
101 /*!
101 /*!
102 \property QScatterSeries::markerSize
102 \property QScatterSeries::markerSize
103 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
103 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
104 */
104 */
105 /*!
105 /*!
106 \qmlproperty real ScatterSeries::markerSize
106 \qmlproperty real ScatterSeries::markerSize
107 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
107 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
108 */
108 */
109
109
110 /*!
110 /*!
111 \fn void QScatterSeries::colorChanged(QColor color)
111 \fn void QScatterSeries::colorChanged(QColor color)
112 Signal is emitted when the fill (brush) color has changed to \a color.
112 Signal is emitted when the fill (brush) color has changed to \a color.
113 */
113 */
114
114
115 /*!
115 /*!
116 \fn void QScatterSeries::borderColorChanged(QColor color)
116 \fn void QScatterSeries::borderColorChanged(QColor color)
117 Signal is emitted when the line (pen) color has changed to \a color.
117 Signal is emitted when the line (pen) color has changed to \a color.
118 */
118 */
119 /*!
119 /*!
120 \qmlsignal ScatterSeries::borderColorChanged(color color)
120 \qmlsignal ScatterSeries::borderColorChanged(color color)
121 Signal is emitted when the line (pen) color has changed to \a color.
121 Signal is emitted when the line (pen) color has changed to \a color.
122 */
122 */
123
123
124 /*!
124 /*!
125 \fn QChartSeriesType QScatterSeries::type() const
125 \fn QChartSeriesType QScatterSeries::type() const
126 Returns QChartSeries::SeriesTypeScatter.
126 Returns QChartSeries::SeriesTypeScatter.
127 \sa QAbstractSeries, SeriesType
127 \sa QAbstractSeries, SeriesType
128 */
128 */
129
129
130 QTCOMMERCIALCHART_BEGIN_NAMESPACE
130 QTCOMMERCIALCHART_BEGIN_NAMESPACE
131
131
132 /*!
132 /*!
133 Constructs a series object which is a child of \a parent.
133 Constructs a series object which is a child of \a parent.
134 */
134 */
135 QScatterSeries::QScatterSeries(QObject *parent)
135 QScatterSeries::QScatterSeries(QObject *parent)
136 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
136 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
137 {
137 {
138 }
138 }
139
139
140 /*!
140 /*!
141 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
141 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
142 */
142 */
143 QScatterSeries::~QScatterSeries()
143 QScatterSeries::~QScatterSeries()
144 {
144 {
145 Q_D(QScatterSeries);
145 Q_D(QScatterSeries);
146 if (d->m_dataset)
146 if (d->m_dataset)
147 d->m_dataset->removeSeries(this);
147 d->m_dataset->removeSeries(this);
148 }
148 }
149
149
150 QAbstractSeries::SeriesType QScatterSeries::type() const
150 QAbstractSeries::SeriesType QScatterSeries::type() const
151 {
151 {
152 return QAbstractSeries::SeriesTypeScatter;
152 return QAbstractSeries::SeriesTypeScatter;
153 }
153 }
154
154
155 /*!
155 /*!
156 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
156 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
157 pen from chart theme is used.
157 pen from chart theme is used.
158 \sa QChart::setTheme()
158 \sa QChart::setTheme()
159 */
159 */
160 void QScatterSeries::setPen(const QPen &pen)
160 void QScatterSeries::setPen(const QPen &pen)
161 {
161 {
162 Q_D(QXYSeries);
162 Q_D(QXYSeries);
163 if (d->m_pen != pen) {
163 if (d->m_pen != pen) {
164 bool emitColorChanged = d->m_pen.color() != pen.color();
164 bool emitColorChanged = d->m_pen.color() != pen.color();
165 d->m_pen = pen;
165 d->m_pen = pen;
166 emit d->updated();
166 emit d->updated();
167 if (emitColorChanged)
167 if (emitColorChanged)
168 emit borderColorChanged(pen.color());
168 emit borderColorChanged(pen.color());
169 }
169 }
170 }
170 }
171
171
172 /*!
172 /*!
173 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
173 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
174 from chart theme setting is used.
174 from chart theme setting is used.
175 \sa QChart::setTheme()
175 \sa QChart::setTheme()
176 */
176 */
177 void QScatterSeries::setBrush(const QBrush &brush)
177 void QScatterSeries::setBrush(const QBrush &brush)
178 {
178 {
179 Q_D(QScatterSeries);
179 Q_D(QScatterSeries);
180 if (d->m_brush != brush) {
180 if (d->m_brush != brush) {
181 bool emitColorChanged = d->m_brush.color() != brush.color();
181 bool emitColorChanged = d->m_brush.color() != brush.color();
182 d->m_brush = brush;
182 d->m_brush = brush;
183 emit d->updated();
183 emit d->updated();
184 if (emitColorChanged)
184 if (emitColorChanged)
185 emit colorChanged(brush.color());
185 emit colorChanged(brush.color());
186 }
186 }
187 }
187 }
188
188
189 void QScatterSeries::setColor(const QColor &color)
189 void QScatterSeries::setColor(const QColor &color)
190 {
190 {
191 QBrush b = brush();
191 QBrush b = brush();
192 if (b == QBrush())
192 if (b == QBrush())
193 b.setStyle(Qt::SolidPattern);
193 b.setStyle(Qt::SolidPattern);
194 b.setColor(color);
194 b.setColor(color);
195 setBrush(b);
195 setBrush(b);
196 }
196 }
197
197
198 QColor QScatterSeries::color() const
198 QColor QScatterSeries::color() const
199 {
199 {
200 return brush().color();
200 return brush().color();
201 }
201 }
202
202
203 void QScatterSeries::setBorderColor(const QColor &color)
203 void QScatterSeries::setBorderColor(const QColor &color)
204 {
204 {
205 QPen p = pen();
205 QPen p = pen();
206 if (p.color() != color) {
206 if (p.color() != color) {
207 p.setColor(color);
207 p.setColor(color);
208 setPen(p);
208 setPen(p);
209 }
209 }
210 }
210 }
211
211
212 QColor QScatterSeries::borderColor() const
212 QColor QScatterSeries::borderColor() const
213 {
213 {
214 return pen().color();
214 return pen().color();
215 }
215 }
216
216
217 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
217 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
218 {
218 {
219 Q_D(const QScatterSeries);
219 Q_D(const QScatterSeries);
220 return d->m_shape;
220 return d->m_shape;
221 }
221 }
222
222
223 void QScatterSeries::setMarkerShape(MarkerShape shape)
223 void QScatterSeries::setMarkerShape(MarkerShape shape)
224 {
224 {
225 Q_D(QScatterSeries);
225 Q_D(QScatterSeries);
226 if (d->m_shape != shape) {
226 if (d->m_shape != shape) {
227 d->m_shape = shape;
227 d->m_shape = shape;
228 emit d->updated();
228 emit d->updated();
229 }
229 }
230 }
230 }
231
231
232 qreal QScatterSeries::markerSize() const
232 qreal QScatterSeries::markerSize() const
233 {
233 {
234 Q_D(const QScatterSeries);
234 Q_D(const QScatterSeries);
235 return d->m_size;
235 return d->m_size;
236 }
236 }
237
237
238 void QScatterSeries::setMarkerSize(qreal size)
238 void QScatterSeries::setMarkerSize(qreal size)
239 {
239 {
240 Q_D(QScatterSeries);
240 Q_D(QScatterSeries);
241
241
242 if (!qFuzzyIsNull(d->m_size - size)) {
242 if (!qFuzzyCompare(d->m_size, size)) {
243 d->m_size = size;
243 d->m_size = size;
244 emit d->updated();
244 emit d->updated();
245 }
245 }
246 }
246 }
247
247
248 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
248 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
249
249
250 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
250 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
251 : QXYSeriesPrivate(q),
251 : QXYSeriesPrivate(q),
252 m_shape(QScatterSeries::MarkerShapeCircle),
252 m_shape(QScatterSeries::MarkerShapeCircle),
253 m_size(15.0)
253 m_size(15.0)
254 {
254 {
255 }
255 }
256
256
257 ChartElement *QScatterSeriesPrivate::createGraphics(ChartPresenter *presenter)
257 ChartElement *QScatterSeriesPrivate::createGraphics(ChartPresenter *presenter)
258 {
258 {
259 Q_Q(QScatterSeries);
259 Q_Q(QScatterSeries);
260 ScatterChartItem *scatter = new ScatterChartItem(q, presenter);
260 ScatterChartItem *scatter = new ScatterChartItem(q, presenter);
261 if (presenter->animationOptions().testFlag(QChart::SeriesAnimations))
261 if (presenter->animationOptions().testFlag(QChart::SeriesAnimations))
262 scatter->setAnimation(new XYAnimation(scatter));
262 scatter->setAnimation(new XYAnimation(scatter));
263 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
263 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
264 return scatter;
264 return scatter;
265 }
265 }
266
266
267 #include "moc_qscatterseries.cpp"
267 #include "moc_qscatterseries.cpp"
268
268
269 QTCOMMERCIALCHART_END_NAMESPACE
269 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,216 +1,216
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 "scroller_p.h"
21 #include "scroller_p.h"
22 #include "qlegend.h"
22 #include "qlegend.h"
23 #include <QGraphicsSceneMouseEvent>
23 #include <QGraphicsSceneMouseEvent>
24 #include <QDebug>
24 #include <QDebug>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 Scroller::Scroller()
28 Scroller::Scroller()
29 : m_ticker(this),
29 : m_ticker(this),
30 m_timeTresholdMin(50),
30 m_timeTresholdMin(50),
31 m_timeTresholdMax(300),
31 m_timeTresholdMax(300),
32 m_state(Idle),
32 m_state(Idle),
33 m_treshold(10)
33 m_treshold(10)
34 {
34 {
35
35
36 }
36 }
37
37
38 Scroller::~Scroller()
38 Scroller::~Scroller()
39 {
39 {
40 }
40 }
41
41
42 void Scroller::move(const QPointF &delta)
42 void Scroller::move(const QPointF &delta)
43 {
43 {
44 switch (m_state) {
44 switch (m_state) {
45 case Pressed:
45 case Pressed:
46 m_timeStamp = QTime::currentTime();
46 m_timeStamp = QTime::currentTime();
47 break;
47 break;
48 case Scroll:
48 case Scroll:
49 stopTicker();
49 stopTicker();
50 m_timeStamp = QTime::currentTime();
50 m_timeStamp = QTime::currentTime();
51 break;
51 break;
52 default:
52 default:
53 break;
53 break;
54 }
54 }
55 setOffset(offset() - delta);
55 setOffset(offset() - delta);
56 }
56 }
57
57
58 void Scroller::scrollTo(const QPointF &delta)
58 void Scroller::scrollTo(const QPointF &delta)
59 {
59 {
60 // Starts scrolling, if at least m_timeTresholdMin msecs has gone since timestamp
60 // Starts scrolling, if at least m_timeTresholdMin msecs has gone since timestamp
61 // current time is no more than m_timeTresholdMax from timestamp
61 // current time is no more than m_timeTresholdMax from timestamp
62
62
63 if ((m_timeStamp.elapsed() > m_timeTresholdMin) && (m_timeStamp.msecsTo(QTime::currentTime()) < m_timeTresholdMax)) {
63 if ((m_timeStamp.elapsed() > m_timeTresholdMin) && (m_timeStamp.msecsTo(QTime::currentTime()) < m_timeTresholdMax)) {
64 // Release was quick enough. Start scrolling.
64 // Release was quick enough. Start scrolling.
65 qreal interval = 25;
65 qreal interval = 25;
66 qreal time = m_timeStamp.msecsTo(QTime::currentTime());
66 qreal time = m_timeStamp.msecsTo(QTime::currentTime());
67 if (qFuzzyIsNull(time)) {
67 if (qFuzzyCompare(time, 0)) {
68 m_speed = delta / 5;
68 m_speed = delta / 5;
69 } else {
69 } else {
70 m_speed = delta * interval / time;
70 m_speed = delta * interval / time;
71 }
71 }
72
72
73 qreal fraction = qMax(qAbs(m_speed.x()), qAbs(m_speed.y()));
73 qreal fraction = qMax(qAbs(m_speed.x()), qAbs(m_speed.y()));
74
74
75 if (!qFuzzyIsNull(fraction)) {
75 if (!qFuzzyCompare(fraction, 0)) {
76 m_fraction.setX(qAbs(m_speed.x() / fraction));
76 m_fraction.setX(qAbs(m_speed.x() / fraction));
77 m_fraction.setY(qAbs(m_speed.y() / fraction));
77 m_fraction.setY(qAbs(m_speed.y() / fraction));
78 } else {
78 } else {
79 m_fraction.setX(1);
79 m_fraction.setX(1);
80 m_fraction.setY(1);
80 m_fraction.setY(1);
81 }
81 }
82 startTicker(interval);
82 startTicker(interval);
83 } else {
83 } else {
84 stopTicker(); // Stop ticker, if one is running.
84 stopTicker(); // Stop ticker, if one is running.
85 }
85 }
86 }
86 }
87
87
88 void Scroller::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
88 void Scroller::handleMousePressEvent(QGraphicsSceneMouseEvent *event)
89 {
89 {
90 stopTicker();
90 stopTicker();
91 m_pressPos = event->screenPos();
91 m_pressPos = event->screenPos();
92 m_lastPos = m_pressPos;
92 m_lastPos = m_pressPos;
93 m_state = Pressed;
93 m_state = Pressed;
94 event->accept();
94 event->accept();
95 }
95 }
96
96
97 void Scroller::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
97 void Scroller::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event)
98 {
98 {
99 QPointF delta = event->screenPos() - m_lastPos;
99 QPointF delta = event->screenPos() - m_lastPos;
100
100
101 switch (m_state) {
101 switch (m_state) {
102 case Pressed: {
102 case Pressed: {
103 // calculate treshold. If enough, change to move state and send out move deltas.
103 // calculate treshold. If enough, change to move state and send out move deltas.
104 if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) {
104 if (qAbs(delta.x()) > m_treshold || qAbs(delta.y()) > m_treshold) {
105 m_lastPos = event->screenPos();
105 m_lastPos = event->screenPos();
106 move(delta);
106 move(delta);
107 m_state = Move;
107 m_state = Move;
108 }
108 }
109 event->accept();
109 event->accept();
110 break;
110 break;
111 }
111 }
112 case Move: {
112 case Move: {
113 m_lastPos = event->screenPos();
113 m_lastPos = event->screenPos();
114 move(delta);
114 move(delta);
115 event->accept();
115 event->accept();
116 break;
116 break;
117 }
117 }
118 case Idle:
118 case Idle:
119 default: {
119 default: {
120 event->ignore();
120 event->ignore();
121 break;
121 break;
122 }
122 }
123 }
123 }
124 }
124 }
125
125
126 void Scroller::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
126 void Scroller::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
127 {
127 {
128 switch (m_state) {
128 switch (m_state) {
129 case Move:
129 case Move:
130 {
130 {
131 scrollTo(m_lastPos - m_pressPos);
131 scrollTo(m_lastPos - m_pressPos);
132 event->accept();
132 event->accept();
133 break;
133 break;
134 }
134 }
135 default:
135 default:
136 {
136 {
137 m_state = Idle;
137 m_state = Idle;
138 event->ignore();
138 event->ignore();
139 break;
139 break;
140 }
140 }
141 }
141 }
142 }
142 }
143
143
144 void Scroller::startTicker(int interval)
144 void Scroller::startTicker(int interval)
145 {
145 {
146 m_state = Scroll;
146 m_state = Scroll;
147 m_ticker.start(interval);
147 m_ticker.start(interval);
148 }
148 }
149
149
150 void Scroller::stopTicker()
150 void Scroller::stopTicker()
151 {
151 {
152 m_state = Idle;
152 m_state = Idle;
153 m_ticker.stop();
153 m_ticker.stop();
154 }
154 }
155
155
156 void Scroller::scrollTick()
156 void Scroller::scrollTick()
157 {
157 {
158 switch (m_state) {
158 switch (m_state) {
159 case Scroll:
159 case Scroll:
160 lowerSpeed(m_speed);
160 lowerSpeed(m_speed);
161 setOffset(offset() - m_speed);
161 setOffset(offset() - m_speed);
162 if (m_speed == QPointF(0, 0)) {
162 if (m_speed == QPointF(0, 0)) {
163 m_state = Idle;
163 m_state = Idle;
164 m_ticker.stop();
164 m_ticker.stop();
165 }
165 }
166 break;
166 break;
167 default:
167 default:
168 qWarning() << __FUNCTION__ << "Scroller unexpected state" << m_state;
168 qWarning() << __FUNCTION__ << "Scroller unexpected state" << m_state;
169 m_ticker.stop();
169 m_ticker.stop();
170 m_state = Idle;
170 m_state = Idle;
171 break;
171 break;
172 }
172 }
173 }
173 }
174
174
175 void Scroller::lowerSpeed(QPointF &speed, qreal maxSpeed)
175 void Scroller::lowerSpeed(QPointF &speed, qreal maxSpeed)
176 {
176 {
177 qreal x = qBound(-maxSpeed, speed.x(), maxSpeed);
177 qreal x = qBound(-maxSpeed, speed.x(), maxSpeed);
178 qreal y = qBound(-maxSpeed, speed.y(), maxSpeed);
178 qreal y = qBound(-maxSpeed, speed.y(), maxSpeed);
179
179
180 x = (x == 0) ? x :
180 x = (x == 0) ? x :
181 (x > 0) ? qMax(qreal(0), x - m_fraction.x()) : qMin(qreal(0), x + m_fraction.x());
181 (x > 0) ? qMax(qreal(0), x - m_fraction.x()) : qMin(qreal(0), x + m_fraction.x());
182 y = (y == 0) ? y :
182 y = (y == 0) ? y :
183 (y > 0) ? qMax(qreal(0), y - m_fraction.y()) : qMin(qreal(0), y + m_fraction.y());
183 (y > 0) ? qMax(qreal(0), y - m_fraction.y()) : qMin(qreal(0), y + m_fraction.y());
184 speed.setX(x);
184 speed.setX(x);
185 speed.setY(y);
185 speed.setY(y);
186 }
186 }
187
187
188 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
188 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
189
189
190 ScrollTicker::ScrollTicker(Scroller *scroller, QObject *parent)
190 ScrollTicker::ScrollTicker(Scroller *scroller, QObject *parent)
191 : QObject(parent),
191 : QObject(parent),
192 m_scroller(scroller)
192 m_scroller(scroller)
193 {
193 {
194
194
195 }
195 }
196
196
197 void ScrollTicker::start(int interval)
197 void ScrollTicker::start(int interval)
198 {
198 {
199 if (!m_timer.isActive())
199 if (!m_timer.isActive())
200 m_timer.start(interval, this);
200 m_timer.start(interval, this);
201 }
201 }
202
202
203 void ScrollTicker::stop()
203 void ScrollTicker::stop()
204 {
204 {
205 m_timer.stop();
205 m_timer.stop();
206 }
206 }
207
207
208 void ScrollTicker::timerEvent(QTimerEvent *event)
208 void ScrollTicker::timerEvent(QTimerEvent *event)
209 {
209 {
210 Q_UNUSED(event);
210 Q_UNUSED(event);
211 m_scroller->scrollTick();
211 m_scroller->scrollTick();
212 }
212 }
213
213
214 #include "moc_scroller_p.cpp"
214 #include "moc_scroller_p.cpp"
215
215
216 QTCOMMERCIALCHART_END_NAMESPACE
216 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,227 +1,227
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 "xychart_p.h"
21 #include "xychart_p.h"
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "qxymodelmapper.h"
26 #include "qxymodelmapper.h"
27 #include <QPainter>
27 #include <QPainter>
28 #include <QAbstractItemModel>
28 #include <QAbstractItemModel>
29
29
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 //TODO: optimize : remove points which are not visible
33 //TODO: optimize : remove points which are not visible
34
34
35 XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter)
35 XYChart::XYChart(QXYSeries *series, ChartPresenter *presenter)
36 : ChartElement(presenter),
36 : ChartElement(presenter),
37 m_minX(0),
37 m_minX(0),
38 m_maxX(0),
38 m_maxX(0),
39 m_minY(0),
39 m_minY(0),
40 m_maxY(0),
40 m_maxY(0),
41 m_series(series),
41 m_series(series),
42 m_animation(0),
42 m_animation(0),
43 m_dirty(true)
43 m_dirty(true)
44 {
44 {
45 QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
45 QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
46 QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
46 QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
47 QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
47 QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
48 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
48 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
49 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
49 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
50 }
50 }
51
51
52 void XYChart::setGeometryPoints(const QVector<QPointF>& points)
52 void XYChart::setGeometryPoints(const QVector<QPointF>& points)
53 {
53 {
54 m_points = points;
54 m_points = points;
55 }
55 }
56
56
57 void XYChart::setClipRect(const QRectF &rect)
57 void XYChart::setClipRect(const QRectF &rect)
58 {
58 {
59 m_clipRect = rect;
59 m_clipRect = rect;
60 }
60 }
61
61
62 void XYChart::setAnimation(XYAnimation *animation)
62 void XYChart::setAnimation(XYAnimation *animation)
63 {
63 {
64 m_animation = animation;
64 m_animation = animation;
65 }
65 }
66
66
67 void XYChart::setDirty(bool dirty)
67 void XYChart::setDirty(bool dirty)
68 {
68 {
69 m_dirty = dirty;
69 m_dirty = dirty;
70 }
70 }
71
71
72 QPointF XYChart::calculateGeometryPoint(const QPointF &point) const
72 QPointF XYChart::calculateGeometryPoint(const QPointF &point) const
73 {
73 {
74 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
74 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
75 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
75 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
76 qreal x = (point.x() - m_minX) * deltaX;
76 qreal x = (point.x() - m_minX) * deltaX;
77 qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
77 qreal y = (point.y() - m_minY) * -deltaY + m_size.height();
78 return QPointF(x, y);
78 return QPointF(x, y);
79 }
79 }
80
80
81 QPointF XYChart::calculateGeometryPoint(int index) const
81 QPointF XYChart::calculateGeometryPoint(int index) const
82 {
82 {
83 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
83 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
84 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
84 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
85 const QList<QPointF>& vector = m_series->points();
85 const QList<QPointF>& vector = m_series->points();
86 qreal x = (vector[index].x() - m_minX) * deltaX;
86 qreal x = (vector[index].x() - m_minX) * deltaX;
87 qreal y = (vector[index].y() - m_minY) * -deltaY + m_size.height();
87 qreal y = (vector[index].y() - m_minY) * -deltaY + m_size.height();
88 return QPointF(x, y);
88 return QPointF(x, y);
89 }
89 }
90
90
91 QVector<QPointF> XYChart::calculateGeometryPoints() const
91 QVector<QPointF> XYChart::calculateGeometryPoints() const
92 {
92 {
93 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
93 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
94 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
94 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
95
95
96 QVector<QPointF> result;
96 QVector<QPointF> result;
97 result.resize(m_series->count());
97 result.resize(m_series->count());
98 const QList<QPointF>& vector = m_series->points();
98 const QList<QPointF>& vector = m_series->points();
99 for (int i = 0; i < m_series->count(); ++i) {
99 for (int i = 0; i < m_series->count(); ++i) {
100 qreal x = (vector[i].x() - m_minX) * deltaX;
100 qreal x = (vector[i].x() - m_minX) * deltaX;
101 qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height();
101 qreal y = (vector[i].y() - m_minY) * -deltaY + m_size.height();
102 result[i].setX(x);
102 result[i].setX(x);
103 result[i].setY(y);
103 result[i].setY(y);
104 }
104 }
105 return result;
105 return result;
106 }
106 }
107
107
108 QPointF XYChart::calculateDomainPoint(const QPointF &point) const
108 QPointF XYChart::calculateDomainPoint(const QPointF &point) const
109 {
109 {
110 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
110 const qreal deltaX = m_size.width() / (m_maxX - m_minX);
111 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
111 const qreal deltaY = m_size.height() / (m_maxY - m_minY);
112 qreal x = point.x() / deltaX + m_minX;
112 qreal x = point.x() / deltaX + m_minX;
113 qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY;
113 qreal y = (point.y() - m_size.height()) / (-deltaY) + m_minY;
114 return QPointF(x, y);
114 return QPointF(x, y);
115 }
115 }
116
116
117 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
117 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
118 {
118 {
119
119
120 if (m_animation) {
120 if (m_animation) {
121 m_animation->setup(oldPoints, newPoints, index);
121 m_animation->setup(oldPoints, newPoints, index);
122 m_points = newPoints;
122 m_points = newPoints;
123 setDirty(false);
123 setDirty(false);
124 presenter()->startAnimation(m_animation);
124 presenter()->startAnimation(m_animation);
125 } else {
125 } else {
126 m_points = newPoints;
126 m_points = newPoints;
127 updateGeometry();
127 updateGeometry();
128 }
128 }
129 }
129 }
130
130
131 //handlers
131 //handlers
132
132
133 void XYChart::handlePointAdded(int index)
133 void XYChart::handlePointAdded(int index)
134 {
134 {
135 Q_ASSERT(index < m_series->count());
135 Q_ASSERT(index < m_series->count());
136 Q_ASSERT(index >= 0);
136 Q_ASSERT(index >= 0);
137
137
138 QVector<QPointF> points;
138 QVector<QPointF> points;
139
139
140 if (m_dirty) {
140 if (m_dirty) {
141 points = calculateGeometryPoints();
141 points = calculateGeometryPoints();
142 } else {
142 } else {
143 points = m_points;
143 points = m_points;
144 QPointF point = calculateGeometryPoint(index);
144 QPointF point = calculateGeometryPoint(index);
145 points.insert(index, point);
145 points.insert(index, point);
146 }
146 }
147
147
148 updateChart(m_points, points, index);
148 updateChart(m_points, points, index);
149 }
149 }
150
150
151 void XYChart::handlePointRemoved(int index)
151 void XYChart::handlePointRemoved(int index)
152 {
152 {
153 Q_ASSERT(index <= m_series->count());
153 Q_ASSERT(index <= m_series->count());
154 Q_ASSERT(index >= 0);
154 Q_ASSERT(index >= 0);
155
155
156 QVector<QPointF> points;
156 QVector<QPointF> points;
157
157
158 if (m_dirty) {
158 if (m_dirty) {
159 points = calculateGeometryPoints();
159 points = calculateGeometryPoints();
160 } else {
160 } else {
161 points = m_points;
161 points = m_points;
162 points.remove(index);
162 points.remove(index);
163 }
163 }
164
164
165 updateChart(m_points, points, index);
165 updateChart(m_points, points, index);
166 }
166 }
167
167
168 void XYChart::handlePointReplaced(int index)
168 void XYChart::handlePointReplaced(int index)
169 {
169 {
170 Q_ASSERT(index < m_series->count());
170 Q_ASSERT(index < m_series->count());
171 Q_ASSERT(index >= 0);
171 Q_ASSERT(index >= 0);
172
172
173 QVector<QPointF> points;
173 QVector<QPointF> points;
174
174
175 if (m_dirty) {
175 if (m_dirty) {
176 points = calculateGeometryPoints();
176 points = calculateGeometryPoints();
177 } else {
177 } else {
178 QPointF point = calculateGeometryPoint(index);
178 QPointF point = calculateGeometryPoint(index);
179 points = m_points;
179 points = m_points;
180 points.replace(index, point);
180 points.replace(index, point);
181 }
181 }
182
182
183 updateChart(m_points, points, index);
183 updateChart(m_points, points, index);
184 }
184 }
185
185
186 void XYChart::handlePointsReplaced()
186 void XYChart::handlePointsReplaced()
187 {
187 {
188 // All the points were replaced -> recalculate
188 // All the points were replaced -> recalculate
189 QVector<QPointF> points = calculateGeometryPoints();
189 QVector<QPointF> points = calculateGeometryPoints();
190 updateChart(m_points, points, -1);
190 updateChart(m_points, points, -1);
191 }
191 }
192
192
193 void XYChart::handleDomainUpdated()
193 void XYChart::handleDomainUpdated()
194 {
194 {
195 m_minX = domain()->minX();
195 m_minX = domain()->minX();
196 m_maxX = domain()->maxX();
196 m_maxX = domain()->maxX();
197 m_minY = domain()->minY();
197 m_minY = domain()->minY();
198 m_maxY = domain()->maxY();
198 m_maxY = domain()->maxY();
199 if (isEmpty()) return;
199 if (isEmpty()) return;
200
200
201 QVector<QPointF> points = calculateGeometryPoints();
201 QVector<QPointF> points = calculateGeometryPoints();
202
202
203 updateChart(m_points, points);
203 updateChart(m_points, points);
204 }
204 }
205
205
206 void XYChart::handleGeometryChanged(const QRectF &rect)
206 void XYChart::handleGeometryChanged(const QRectF &rect)
207 {
207 {
208 Q_ASSERT(rect.isValid());
208 Q_ASSERT(rect.isValid());
209 m_size = rect.size();
209 m_size = rect.size();
210 m_clipRect = rect.translated(-rect.topLeft());
210 m_clipRect = rect.translated(-rect.topLeft());
211 m_origin = rect.topLeft();
211 m_origin = rect.topLeft();
212
212
213 if (isEmpty()) return;
213 if (isEmpty()) return;
214
214
215 QVector<QPointF> points = calculateGeometryPoints();
215 QVector<QPointF> points = calculateGeometryPoints();
216
216
217 updateChart(m_points, points);
217 updateChart(m_points, points);
218 }
218 }
219
219
220 bool XYChart::isEmpty()
220 bool XYChart::isEmpty()
221 {
221 {
222 return !m_clipRect.isValid() || qFuzzyIsNull(m_maxX - m_minX) || qFuzzyIsNull(m_maxY - m_minY) || m_series->points().isEmpty();
222 return !m_clipRect.isValid() || qFuzzyCompare(m_maxX, m_minX) || qFuzzyCompare(m_maxY, m_minY) || m_series->points().isEmpty();
223 }
223 }
224
224
225 #include "moc_xychart_p.cpp"
225 #include "moc_xychart_p.cpp"
226
226
227 QTCOMMERCIALCHART_END_NAMESPACE
227 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,707 +1,707
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 #ifndef BUILD_PRIVATE_UNIT_TESTS
20 #ifndef BUILD_PRIVATE_UNIT_TESTS
21
21
22 #include <QtTest/QtTest>
22 #include <QtTest/QtTest>
23
23
24 class tst_Domain: public QObject {
24 class tst_Domain: public QObject {
25
25
26 Q_OBJECT
26 Q_OBJECT
27
27
28 private Q_SLOTS:
28 private Q_SLOTS:
29 void skip();
29 void skip();
30
30
31 };
31 };
32
32
33 void tst_Domain::skip()
33 void tst_Domain::skip()
34 {
34 {
35 #ifdef QT5_QUICK_1
35 #ifdef QT5_QUICK_1
36 QSKIP("This test requires the debug version of library");
36 QSKIP("This test requires the debug version of library");
37 #else
37 #else
38 QSKIP("This test requires the debug version of library", SkipAll);
38 QSKIP("This test requires the debug version of library", SkipAll);
39 #endif
39 #endif
40 }
40 }
41
41
42 QTEST_MAIN(tst_Domain)
42 QTEST_MAIN(tst_Domain)
43 #include "tst_domain.moc"
43 #include "tst_domain.moc"
44
44
45 #else
45 #else
46
46
47 #include <QtTest/QtTest>
47 #include <QtTest/QtTest>
48 #include <private/domain_p.h>
48 #include <private/domain_p.h>
49 #include <private/qabstractaxis_p.h>
49 #include <private/qabstractaxis_p.h>
50 #include <tst_definitions.h>
50 #include <tst_definitions.h>
51
51
52 QTCOMMERCIALCHART_USE_NAMESPACE
52 QTCOMMERCIALCHART_USE_NAMESPACE
53
53
54 Q_DECLARE_METATYPE(Domain*)
54 Q_DECLARE_METATYPE(Domain*)
55 Q_DECLARE_METATYPE(QSizeF)
55 Q_DECLARE_METATYPE(QSizeF)
56
56
57
57
58 class AxisMock: public QAbstractAxisPrivate
58 class AxisMock: public QAbstractAxisPrivate
59 {
59 {
60 Q_OBJECT
60 Q_OBJECT
61 public:
61 public:
62 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
62 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
63 ChartAxis* createGraphics(ChartPresenter* presenter)
63 ChartAxis* createGraphics(ChartPresenter* presenter)
64 {
64 {
65 Q_UNUSED(presenter);
65 Q_UNUSED(presenter);
66 return 0;
66 return 0;
67 };
67 };
68 void intializeDomain(Domain* domain)
68 void intializeDomain(Domain* domain)
69 {
69 {
70 Q_UNUSED(domain);
70 Q_UNUSED(domain);
71 };
71 };
72 void setMin(const QVariant &min)
72 void setMin(const QVariant &min)
73 {
73 {
74 Q_UNUSED(min);
74 Q_UNUSED(min);
75 }
75 }
76 qreal min() { return m_min;}
76 qreal min() { return m_min;}
77 void setMax(const QVariant &max)
77 void setMax(const QVariant &max)
78 {
78 {
79 Q_UNUSED(max);
79 Q_UNUSED(max);
80 }
80 }
81 qreal max() { return m_max; }
81 qreal max() { return m_max; }
82 void setRange(const QVariant &min, const QVariant &max)
82 void setRange(const QVariant &min, const QVariant &max)
83 {
83 {
84 Q_UNUSED(min);
84 Q_UNUSED(min);
85 Q_UNUSED(max);
85 Q_UNUSED(max);
86 };
86 };
87
87
88 int count () const { return m_count; }
88 int count () const { return m_count; }
89
89
90 void handleDomainUpdated(){};
90 void handleDomainUpdated(){};
91 public:
91 public:
92 int m_count;
92 int m_count;
93 qreal m_min;
93 qreal m_min;
94 qreal m_max;
94 qreal m_max;
95 };
95 };
96
96
97 class tst_Domain: public QObject
97 class tst_Domain: public QObject
98 {
98 {
99 Q_OBJECT
99 Q_OBJECT
100
100
101 public Q_SLOTS:
101 public Q_SLOTS:
102 void initTestCase();
102 void initTestCase();
103 void cleanupTestCase();
103 void cleanupTestCase();
104 void init();
104 void init();
105 void cleanup();
105 void cleanup();
106
106
107 private Q_SLOTS:
107 private Q_SLOTS:
108 void domain();
108 void domain();
109 void handleAxisUpdatedX_data();
109 void handleAxisUpdatedX_data();
110 void handleAxisUpdatedX();
110 void handleAxisUpdatedX();
111 void handleAxisUpdatedY_data();
111 void handleAxisUpdatedY_data();
112 void handleAxisUpdatedY();
112 void handleAxisUpdatedY();
113 void isEmpty_data();
113 void isEmpty_data();
114 void isEmpty();
114 void isEmpty();
115 void maxX_data();
115 void maxX_data();
116 void maxX();
116 void maxX();
117 void maxY_data();
117 void maxY_data();
118 void maxY();
118 void maxY();
119 void minX_data();
119 void minX_data();
120 void minX();
120 void minX();
121 void minY_data();
121 void minY_data();
122 void minY();
122 void minY();
123 void operatorEquals_data();
123 void operatorEquals_data();
124 void operatorEquals();
124 void operatorEquals();
125 void setRange_data();
125 void setRange_data();
126 void setRange();
126 void setRange();
127 void setRangeX_data();
127 void setRangeX_data();
128 void setRangeX();
128 void setRangeX();
129 void setRangeY_data();
129 void setRangeY_data();
130 void setRangeY();
130 void setRangeY();
131 void spanX_data();
131 void spanX_data();
132 void spanX();
132 void spanX();
133 void spanY_data();
133 void spanY_data();
134 void spanY();
134 void spanY();
135 void zoom_data();
135 void zoom_data();
136 void zoom();
136 void zoom();
137 void move_data();
137 void move_data();
138 void move();
138 void move();
139 };
139 };
140
140
141 void tst_Domain::initTestCase()
141 void tst_Domain::initTestCase()
142 {
142 {
143 }
143 }
144
144
145 void tst_Domain::cleanupTestCase()
145 void tst_Domain::cleanupTestCase()
146 {
146 {
147 }
147 }
148
148
149 void tst_Domain::init()
149 void tst_Domain::init()
150 {
150 {
151 }
151 }
152
152
153 void tst_Domain::cleanup()
153 void tst_Domain::cleanup()
154 {
154 {
155 }
155 }
156
156
157 void tst_Domain::domain()
157 void tst_Domain::domain()
158 {
158 {
159 Domain domain;
159 Domain domain;
160
160
161 QCOMPARE(domain.isEmpty(), true);
161 QCOMPARE(domain.isEmpty(), true);
162 QCOMPARE(domain.maxX(), 0.0);
162 QCOMPARE(domain.maxX(), 0.0);
163 QCOMPARE(domain.maxY(), 0.0);
163 QCOMPARE(domain.maxY(), 0.0);
164 QCOMPARE(domain.minX(), 0.0);
164 QCOMPARE(domain.minX(), 0.0);
165 QCOMPARE(domain.minY(), 0.0);
165 QCOMPARE(domain.minY(), 0.0);
166 }
166 }
167
167
168 void tst_Domain::handleAxisUpdatedX_data()
168 void tst_Domain::handleAxisUpdatedX_data()
169 {
169 {
170 QTest::addColumn<qreal>("min");
170 QTest::addColumn<qreal>("min");
171 QTest::addColumn<qreal>("max");
171 QTest::addColumn<qreal>("max");
172 QTest::newRow("-1 1") << -1.0 << 1.0;
172 QTest::newRow("-1 1") << -1.0 << 1.0;
173 QTest::newRow("0 1") << 0.0 << 1.0;
173 QTest::newRow("0 1") << 0.0 << 1.0;
174 QTest::newRow("-1 0") << -1.0 << 0.0;
174 QTest::newRow("-1 0") << -1.0 << 0.0;
175 }
175 }
176
176
177 void tst_Domain::handleAxisUpdatedX()
177 void tst_Domain::handleAxisUpdatedX()
178 {
178 {
179 QFETCH(qreal, min);
179 QFETCH(qreal, min);
180 QFETCH(qreal, max);
180 QFETCH(qreal, max);
181
181
182 Domain domain;
182 Domain domain;
183
183
184 QSignalSpy spy0(&domain, SIGNAL(updated()));
184 QSignalSpy spy0(&domain, SIGNAL(updated()));
185 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
185 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
186 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
186 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
187
187
188 AxisMock axis(Qt::Horizontal);
188 AxisMock axis(Qt::Horizontal);
189 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
189 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
190 axis.m_min=min;
190 axis.m_min=min;
191 axis.m_max=max;
191 axis.m_max=max;
192 axis.emitUpdated();
192 axis.emitUpdated();
193
193
194 QVERIFY(qFuzzyIsNull(domain.minX() - min));
194 QVERIFY(qFuzzyCompare(domain.minX(), min));
195 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
195 QVERIFY(qFuzzyCompare(domain.maxX(), max));
196
196
197 QList<QVariant> arg1 = spy1.first();
197 QList<QVariant> arg1 = spy1.first();
198 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
198 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
199 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
199 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
200
200
201 TRY_COMPARE(spy0.count(), 1);
201 TRY_COMPARE(spy0.count(), 1);
202 TRY_COMPARE(spy1.count(), 1);
202 TRY_COMPARE(spy1.count(), 1);
203 TRY_COMPARE(spy2.count(), 0);
203 TRY_COMPARE(spy2.count(), 0);
204
204
205 }
205 }
206
206
207 void tst_Domain::handleAxisUpdatedY_data()
207 void tst_Domain::handleAxisUpdatedY_data()
208 {
208 {
209 QTest::addColumn<qreal>("min");
209 QTest::addColumn<qreal>("min");
210 QTest::addColumn<qreal>("max");
210 QTest::addColumn<qreal>("max");
211 QTest::newRow("-1 1") << -1.0 << 1.0;
211 QTest::newRow("-1 1") << -1.0 << 1.0;
212 QTest::newRow("0 1") << 0.0 << 1.0;
212 QTest::newRow("0 1") << 0.0 << 1.0;
213 QTest::newRow("-1 0") << -1.0 << 0.0;
213 QTest::newRow("-1 0") << -1.0 << 0.0;
214 }
214 }
215
215
216 void tst_Domain::handleAxisUpdatedY()
216 void tst_Domain::handleAxisUpdatedY()
217 {
217 {
218 QFETCH(qreal, min);
218 QFETCH(qreal, min);
219 QFETCH(qreal, max);
219 QFETCH(qreal, max);
220
220
221 Domain domain;
221 Domain domain;
222
222
223 QSignalSpy spy0(&domain, SIGNAL(updated()));
223 QSignalSpy spy0(&domain, SIGNAL(updated()));
224 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
224 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
225 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
225 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
226
226
227 AxisMock axis(Qt::Vertical);
227 AxisMock axis(Qt::Vertical);
228 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
228 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
229 axis.m_min = min;
229 axis.m_min = min;
230 axis.m_max = max;
230 axis.m_max = max;
231 axis.emitUpdated();
231 axis.emitUpdated();
232
232
233 QVERIFY(qFuzzyIsNull(domain.minY() - min));
233 QVERIFY(qFuzzyCompare(domain.minY(), min));
234 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
234 QVERIFY(qFuzzyCompare(domain.maxY(), max));
235
235
236 QList<QVariant> arg1 = spy2.first();
236 QList<QVariant> arg1 = spy2.first();
237 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
237 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
238 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
238 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
239
239
240 TRY_COMPARE(spy0.count(), 1);
240 TRY_COMPARE(spy0.count(), 1);
241 TRY_COMPARE(spy1.count(), 0);
241 TRY_COMPARE(spy1.count(), 0);
242 TRY_COMPARE(spy2.count(), 1);
242 TRY_COMPARE(spy2.count(), 1);
243 }
243 }
244
244
245 void tst_Domain::isEmpty_data()
245 void tst_Domain::isEmpty_data()
246 {
246 {
247 QTest::addColumn<qreal>("minX");
247 QTest::addColumn<qreal>("minX");
248 QTest::addColumn<qreal>("maxX");
248 QTest::addColumn<qreal>("maxX");
249 QTest::addColumn<qreal>("minY");
249 QTest::addColumn<qreal>("minY");
250 QTest::addColumn<qreal>("maxY");
250 QTest::addColumn<qreal>("maxY");
251 QTest::addColumn<bool>("isEmpty");
251 QTest::addColumn<bool>("isEmpty");
252 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true;
252 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true;
253 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true;
253 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true;
254 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true;
254 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true;
255 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false;
255 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false;
256 }
256 }
257
257
258 void tst_Domain::isEmpty()
258 void tst_Domain::isEmpty()
259 {
259 {
260 QFETCH(qreal, minX);
260 QFETCH(qreal, minX);
261 QFETCH(qreal, maxX);
261 QFETCH(qreal, maxX);
262 QFETCH(qreal, minY);
262 QFETCH(qreal, minY);
263 QFETCH(qreal, maxY);
263 QFETCH(qreal, maxY);
264 QFETCH(bool, isEmpty);
264 QFETCH(bool, isEmpty);
265
265
266 Domain domain;
266 Domain domain;
267 domain.setRange(minX, maxX, minY, maxY);
267 domain.setRange(minX, maxX, minY, maxY);
268 QCOMPARE(domain.isEmpty(), isEmpty);
268 QCOMPARE(domain.isEmpty(), isEmpty);
269 }
269 }
270
270
271 void tst_Domain::maxX_data()
271 void tst_Domain::maxX_data()
272 {
272 {
273 QTest::addColumn<qreal>("maxX1");
273 QTest::addColumn<qreal>("maxX1");
274 QTest::addColumn<qreal>("maxX2");
274 QTest::addColumn<qreal>("maxX2");
275 QTest::addColumn<int>("count");
275 QTest::addColumn<int>("count");
276 QTest::newRow("1") << 0.0 << 1.0 << 1;
276 QTest::newRow("1") << 0.0 << 1.0 << 1;
277 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
277 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
278 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
278 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
279 }
279 }
280
280
281 void tst_Domain::maxX()
281 void tst_Domain::maxX()
282 {
282 {
283 QFETCH(qreal, maxX1);
283 QFETCH(qreal, maxX1);
284 QFETCH(qreal, maxX2);
284 QFETCH(qreal, maxX2);
285 QFETCH(int, count);
285 QFETCH(int, count);
286
286
287 Domain domain;
287 Domain domain;
288
288
289 QSignalSpy spy0(&domain, SIGNAL(updated()));
289 QSignalSpy spy0(&domain, SIGNAL(updated()));
290 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
290 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
291 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
291 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
292
292
293 domain.setMaxX(maxX1);
293 domain.setMaxX(maxX1);
294 QCOMPARE(domain.maxX(), maxX1);
294 QCOMPARE(domain.maxX(), maxX1);
295 domain.setMaxX(maxX2);
295 domain.setMaxX(maxX2);
296 QCOMPARE(domain.maxX(), maxX2);
296 QCOMPARE(domain.maxX(), maxX2);
297
297
298 TRY_COMPARE(spy0.count(), count);
298 TRY_COMPARE(spy0.count(), count);
299 TRY_COMPARE(spy1.count(), count);
299 TRY_COMPARE(spy1.count(), count);
300 TRY_COMPARE(spy2.count(), 0);
300 TRY_COMPARE(spy2.count(), 0);
301
301
302 }
302 }
303
303
304 void tst_Domain::maxY_data()
304 void tst_Domain::maxY_data()
305 {
305 {
306 QTest::addColumn<qreal>("maxY1");
306 QTest::addColumn<qreal>("maxY1");
307 QTest::addColumn<qreal>("maxY2");
307 QTest::addColumn<qreal>("maxY2");
308 QTest::addColumn<int>("count");
308 QTest::addColumn<int>("count");
309 QTest::newRow("1") << 0.0 << 1.0 << 1;
309 QTest::newRow("1") << 0.0 << 1.0 << 1;
310 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
310 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
311 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
311 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
312 }
312 }
313
313
314 void tst_Domain::maxY()
314 void tst_Domain::maxY()
315 {
315 {
316 QFETCH(qreal, maxY1);
316 QFETCH(qreal, maxY1);
317 QFETCH(qreal, maxY2);
317 QFETCH(qreal, maxY2);
318 QFETCH(int, count);
318 QFETCH(int, count);
319
319
320 Domain domain;
320 Domain domain;
321
321
322 QSignalSpy spy0(&domain, SIGNAL(updated()));
322 QSignalSpy spy0(&domain, SIGNAL(updated()));
323 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
323 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
324 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
324 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
325
325
326 domain.setMaxY(maxY1);
326 domain.setMaxY(maxY1);
327 QCOMPARE(domain.maxY(), maxY1);
327 QCOMPARE(domain.maxY(), maxY1);
328 domain.setMaxY(maxY2);
328 domain.setMaxY(maxY2);
329 QCOMPARE(domain.maxY(), maxY2);
329 QCOMPARE(domain.maxY(), maxY2);
330
330
331 TRY_COMPARE(spy0.count(), count);
331 TRY_COMPARE(spy0.count(), count);
332 TRY_COMPARE(spy1.count(), 0);
332 TRY_COMPARE(spy1.count(), 0);
333 TRY_COMPARE(spy2.count(), count);
333 TRY_COMPARE(spy2.count(), count);
334 }
334 }
335
335
336 void tst_Domain::minX_data()
336 void tst_Domain::minX_data()
337 {
337 {
338 QTest::addColumn<qreal>("minX1");
338 QTest::addColumn<qreal>("minX1");
339 QTest::addColumn<qreal>("minX2");
339 QTest::addColumn<qreal>("minX2");
340 QTest::addColumn<int>("count");
340 QTest::addColumn<int>("count");
341 QTest::newRow("1") << 0.0 << 1.0 << 1;
341 QTest::newRow("1") << 0.0 << 1.0 << 1;
342 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
342 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
343 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
343 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
344 }
344 }
345
345
346 void tst_Domain::minX()
346 void tst_Domain::minX()
347 {
347 {
348 QFETCH(qreal, minX1);
348 QFETCH(qreal, minX1);
349 QFETCH(qreal, minX2);
349 QFETCH(qreal, minX2);
350 QFETCH(int, count);
350 QFETCH(int, count);
351
351
352 Domain domain;
352 Domain domain;
353
353
354 QSignalSpy spy0(&domain, SIGNAL(updated()));
354 QSignalSpy spy0(&domain, SIGNAL(updated()));
355 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
355 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
356 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
356 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
357
357
358 domain.setMinX(minX1);
358 domain.setMinX(minX1);
359 QCOMPARE(domain.minX(), minX1);
359 QCOMPARE(domain.minX(), minX1);
360 domain.setMinX(minX2);
360 domain.setMinX(minX2);
361 QCOMPARE(domain.minX(), minX2);
361 QCOMPARE(domain.minX(), minX2);
362
362
363 TRY_COMPARE(spy0.count(), count);
363 TRY_COMPARE(spy0.count(), count);
364 TRY_COMPARE(spy1.count(), count);
364 TRY_COMPARE(spy1.count(), count);
365 TRY_COMPARE(spy2.count(), 0);
365 TRY_COMPARE(spy2.count(), 0);
366 }
366 }
367
367
368 void tst_Domain::minY_data()
368 void tst_Domain::minY_data()
369 {
369 {
370 QTest::addColumn<qreal>("minY1");
370 QTest::addColumn<qreal>("minY1");
371 QTest::addColumn<qreal>("minY2");
371 QTest::addColumn<qreal>("minY2");
372 QTest::addColumn<int>("count");
372 QTest::addColumn<int>("count");
373 QTest::newRow("1") << 0.0 << 1.0 << 1;
373 QTest::newRow("1") << 0.0 << 1.0 << 1;
374 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
374 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
375 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
375 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
376 }
376 }
377
377
378 void tst_Domain::minY()
378 void tst_Domain::minY()
379 {
379 {
380 QFETCH(qreal, minY1);
380 QFETCH(qreal, minY1);
381 QFETCH(qreal, minY2);
381 QFETCH(qreal, minY2);
382 QFETCH(int, count);
382 QFETCH(int, count);
383
383
384 Domain domain;
384 Domain domain;
385
385
386 QSignalSpy spy0(&domain, SIGNAL(updated()));
386 QSignalSpy spy0(&domain, SIGNAL(updated()));
387 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
387 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
388 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
388 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
389
389
390 domain.setMinY(minY1);
390 domain.setMinY(minY1);
391 QCOMPARE(domain.minY(), minY1);
391 QCOMPARE(domain.minY(), minY1);
392 domain.setMinY(minY2);
392 domain.setMinY(minY2);
393 QCOMPARE(domain.minY(), minY2);
393 QCOMPARE(domain.minY(), minY2);
394
394
395 TRY_COMPARE(spy0.count(), count);
395 TRY_COMPARE(spy0.count(), count);
396 TRY_COMPARE(spy1.count(), 0);
396 TRY_COMPARE(spy1.count(), 0);
397 TRY_COMPARE(spy2.count(), count);
397 TRY_COMPARE(spy2.count(), count);
398 }
398 }
399
399
400 void tst_Domain::operatorEquals_data()
400 void tst_Domain::operatorEquals_data()
401 {
401 {
402
402
403 QTest::addColumn<Domain*>("domain1");
403 QTest::addColumn<Domain*>("domain1");
404 QTest::addColumn<Domain*>("domain2");
404 QTest::addColumn<Domain*>("domain2");
405 QTest::addColumn<bool>("equals");
405 QTest::addColumn<bool>("equals");
406 QTest::addColumn<bool>("notEquals");
406 QTest::addColumn<bool>("notEquals");
407 Domain* a;
407 Domain* a;
408 Domain* b;
408 Domain* b;
409 a = new Domain();
409 a = new Domain();
410 a->setRange(0, 100, 0, 100);
410 a->setRange(0, 100, 0, 100);
411 b = new Domain();
411 b = new Domain();
412 b->setRange(0, 100, 0, 100);
412 b->setRange(0, 100, 0, 100);
413 QTest::newRow("equals") << a << b << true << false;
413 QTest::newRow("equals") << a << b << true << false;
414 a = new Domain();
414 a = new Domain();
415 a->setRange(0, 100, 0, 100);
415 a->setRange(0, 100, 0, 100);
416 b = new Domain();
416 b = new Domain();
417 b->setRange(0, 100, 0, 1);
417 b->setRange(0, 100, 0, 1);
418 QTest::newRow("equals") << a << b << false << true;
418 QTest::newRow("equals") << a << b << false << true;
419 a = new Domain();
419 a = new Domain();
420 a->setRange(0, 100, 0, 100);
420 a->setRange(0, 100, 0, 100);
421 b = new Domain();
421 b = new Domain();
422 b->setRange(0, 1, 0, 100);
422 b->setRange(0, 1, 0, 100);
423 QTest::newRow("equals") << a << b << false << true;
423 QTest::newRow("equals") << a << b << false << true;
424
424
425 }
425 }
426
426
427 void tst_Domain::operatorEquals()
427 void tst_Domain::operatorEquals()
428 {
428 {
429 QFETCH(Domain*, domain1);
429 QFETCH(Domain*, domain1);
430 QFETCH(Domain*, domain2);
430 QFETCH(Domain*, domain2);
431 QFETCH(bool, equals);
431 QFETCH(bool, equals);
432 QFETCH(bool, notEquals);
432 QFETCH(bool, notEquals);
433
433
434 Domain domain;
434 Domain domain;
435
435
436 QSignalSpy spy0(&domain, SIGNAL(updated()));
436 QSignalSpy spy0(&domain, SIGNAL(updated()));
437 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
437 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
438 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
438 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
439
439
440 QCOMPARE(*domain1==*domain2, equals);
440 QCOMPARE(*domain1==*domain2, equals);
441 QCOMPARE(*domain1!=*domain2, notEquals);
441 QCOMPARE(*domain1!=*domain2, notEquals);
442
442
443 TRY_COMPARE(spy0.count(), 0);
443 TRY_COMPARE(spy0.count(), 0);
444 TRY_COMPARE(spy1.count(), 0);
444 TRY_COMPARE(spy1.count(), 0);
445 TRY_COMPARE(spy2.count(), 0);
445 TRY_COMPARE(spy2.count(), 0);
446 }
446 }
447
447
448 void tst_Domain::setRange_data()
448 void tst_Domain::setRange_data()
449 {
449 {
450 QTest::addColumn<qreal>("minX");
450 QTest::addColumn<qreal>("minX");
451 QTest::addColumn<qreal>("maxX");
451 QTest::addColumn<qreal>("maxX");
452 QTest::addColumn<qreal>("minY");
452 QTest::addColumn<qreal>("minY");
453 QTest::addColumn<qreal>("maxY");
453 QTest::addColumn<qreal>("maxY");
454 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
454 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
455 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
455 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
456 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
456 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
457 }
457 }
458
458
459 void tst_Domain::setRange()
459 void tst_Domain::setRange()
460 {
460 {
461 QFETCH(qreal, minX);
461 QFETCH(qreal, minX);
462 QFETCH(qreal, maxX);
462 QFETCH(qreal, maxX);
463 QFETCH(qreal, minY);
463 QFETCH(qreal, minY);
464 QFETCH(qreal, maxY);
464 QFETCH(qreal, maxY);
465
465
466 Domain domain;
466 Domain domain;
467
467
468 QSignalSpy spy0(&domain, SIGNAL(updated()));
468 QSignalSpy spy0(&domain, SIGNAL(updated()));
469 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
469 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
470 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
470 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
471
471
472 domain.setRange(minX, maxX, minY, maxY);
472 domain.setRange(minX, maxX, minY, maxY);
473
473
474 QCOMPARE(domain.minX(), minX);
474 QCOMPARE(domain.minX(), minX);
475 QCOMPARE(domain.maxX(), maxX);
475 QCOMPARE(domain.maxX(), maxX);
476 QCOMPARE(domain.minY(), minY);
476 QCOMPARE(domain.minY(), minY);
477 QCOMPARE(domain.maxY(), maxY);
477 QCOMPARE(domain.maxY(), maxY);
478
478
479 TRY_COMPARE(spy0.count(), 1);
479 TRY_COMPARE(spy0.count(), 1);
480 TRY_COMPARE(spy1.count(), 1);
480 TRY_COMPARE(spy1.count(), 1);
481 TRY_COMPARE(spy2.count(), 1);
481 TRY_COMPARE(spy2.count(), 1);
482
482
483 }
483 }
484
484
485 void tst_Domain::setRangeX_data()
485 void tst_Domain::setRangeX_data()
486 {
486 {
487 QTest::addColumn<qreal>("min");
487 QTest::addColumn<qreal>("min");
488 QTest::addColumn<qreal>("max");
488 QTest::addColumn<qreal>("max");
489 QTest::newRow("-1 1") << -1.0 << 1.0;
489 QTest::newRow("-1 1") << -1.0 << 1.0;
490 QTest::newRow("0 1") << 0.0 << 1.0;
490 QTest::newRow("0 1") << 0.0 << 1.0;
491 QTest::newRow("-1 0") << -1.0 << 0.0;
491 QTest::newRow("-1 0") << -1.0 << 0.0;
492 }
492 }
493
493
494 void tst_Domain::setRangeX()
494 void tst_Domain::setRangeX()
495 {
495 {
496 QFETCH(qreal, min);
496 QFETCH(qreal, min);
497 QFETCH(qreal, max);
497 QFETCH(qreal, max);
498
498
499 Domain domain;
499 Domain domain;
500
500
501 QSignalSpy spy0(&domain, SIGNAL(updated()));
501 QSignalSpy spy0(&domain, SIGNAL(updated()));
502 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
502 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
503 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
503 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
504
504
505 domain.setRangeX(min, max);
505 domain.setRangeX(min, max);
506
506
507 QVERIFY(qFuzzyIsNull(domain.minX() - min));
507 QVERIFY(qFuzzyCompare(domain.minX(), min));
508 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
508 QVERIFY(qFuzzyCompare(domain.maxX(), max));
509
509
510 QList<QVariant> arg1 = spy1.first();
510 QList<QVariant> arg1 = spy1.first();
511 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
511 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
512 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
512 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
513
513
514 TRY_COMPARE(spy0.count(), 1);
514 TRY_COMPARE(spy0.count(), 1);
515 TRY_COMPARE(spy1.count(), 1);
515 TRY_COMPARE(spy1.count(), 1);
516 TRY_COMPARE(spy2.count(), 0);
516 TRY_COMPARE(spy2.count(), 0);
517 }
517 }
518
518
519 void tst_Domain::setRangeY_data()
519 void tst_Domain::setRangeY_data()
520 {
520 {
521 QTest::addColumn<qreal>("min");
521 QTest::addColumn<qreal>("min");
522 QTest::addColumn<qreal>("max");
522 QTest::addColumn<qreal>("max");
523 QTest::newRow("-1 1") << -1.0 << 1.0;
523 QTest::newRow("-1 1") << -1.0 << 1.0;
524 QTest::newRow("0 1") << 0.0 << 1.0;
524 QTest::newRow("0 1") << 0.0 << 1.0;
525 QTest::newRow("-1 0") << -1.0 << 0.0;
525 QTest::newRow("-1 0") << -1.0 << 0.0;
526 }
526 }
527
527
528 void tst_Domain::setRangeY()
528 void tst_Domain::setRangeY()
529 {
529 {
530 QFETCH(qreal, min);
530 QFETCH(qreal, min);
531 QFETCH(qreal, max);
531 QFETCH(qreal, max);
532
532
533 Domain domain;
533 Domain domain;
534
534
535 QSignalSpy spy0(&domain, SIGNAL(updated()));
535 QSignalSpy spy0(&domain, SIGNAL(updated()));
536 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
536 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
537 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
537 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
538
538
539 domain.setRangeY(min, max);
539 domain.setRangeY(min, max);
540
540
541 QVERIFY(qFuzzyIsNull(domain.minY() - min));
541 QVERIFY(qFuzzyCompare(domain.minY(), min));
542 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
542 QVERIFY(qFuzzyCompare(domain.maxY(), max));
543
543
544 QList<QVariant> arg1 = spy2.first();
544 QList<QVariant> arg1 = spy2.first();
545 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
545 QVERIFY(qFuzzyCompare(arg1.at(0).toReal(), min));
546 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
546 QVERIFY(qFuzzyCompare(arg1.at(1).toReal(), max));
547
547
548 TRY_COMPARE(spy0.count(), 1);
548 TRY_COMPARE(spy0.count(), 1);
549 TRY_COMPARE(spy1.count(), 0);
549 TRY_COMPARE(spy1.count(), 0);
550 TRY_COMPARE(spy2.count(), 1);
550 TRY_COMPARE(spy2.count(), 1);
551 }
551 }
552
552
553 void tst_Domain::spanX_data()
553 void tst_Domain::spanX_data()
554 {
554 {
555 QTest::addColumn<qreal>("minX");
555 QTest::addColumn<qreal>("minX");
556 QTest::addColumn<qreal>("maxX");
556 QTest::addColumn<qreal>("maxX");
557 QTest::addColumn<qreal>("spanX");
557 QTest::addColumn<qreal>("spanX");
558 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
558 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
559 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
559 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
560 }
560 }
561
561
562 void tst_Domain::spanX()
562 void tst_Domain::spanX()
563 {
563 {
564 QFETCH(qreal, minX);
564 QFETCH(qreal, minX);
565 QFETCH(qreal, maxX);
565 QFETCH(qreal, maxX);
566 QFETCH(qreal, spanX);
566 QFETCH(qreal, spanX);
567
567
568 Domain domain;
568 Domain domain;
569
569
570 domain.setRangeX(minX, maxX);
570 domain.setRangeX(minX, maxX);
571
571
572 QSignalSpy spy0(&domain, SIGNAL(updated()));
572 QSignalSpy spy0(&domain, SIGNAL(updated()));
573 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
573 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
574 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
574 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
575
575
576 QCOMPARE(domain.spanX(), spanX);
576 QCOMPARE(domain.spanX(), spanX);
577
577
578 TRY_COMPARE(spy0.count(), 0);
578 TRY_COMPARE(spy0.count(), 0);
579 TRY_COMPARE(spy1.count(), 0);
579 TRY_COMPARE(spy1.count(), 0);
580 TRY_COMPARE(spy2.count(), 0);
580 TRY_COMPARE(spy2.count(), 0);
581 }
581 }
582
582
583 void tst_Domain::spanY_data()
583 void tst_Domain::spanY_data()
584 {
584 {
585 QTest::addColumn<qreal>("minY");
585 QTest::addColumn<qreal>("minY");
586 QTest::addColumn<qreal>("maxY");
586 QTest::addColumn<qreal>("maxY");
587 QTest::addColumn<qreal>("spanY");
587 QTest::addColumn<qreal>("spanY");
588 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
588 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
589 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
589 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
590 }
590 }
591
591
592 void tst_Domain::spanY()
592 void tst_Domain::spanY()
593 {
593 {
594 QFETCH(qreal, minY);
594 QFETCH(qreal, minY);
595 QFETCH(qreal, maxY);
595 QFETCH(qreal, maxY);
596 QFETCH(qreal, spanY);
596 QFETCH(qreal, spanY);
597
597
598 Domain domain;
598 Domain domain;
599
599
600 domain.setRangeY(minY, maxY);
600 domain.setRangeY(minY, maxY);
601
601
602 QSignalSpy spy0(&domain, SIGNAL(updated()));
602 QSignalSpy spy0(&domain, SIGNAL(updated()));
603 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
603 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
604 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
604 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
605
605
606 QCOMPARE(domain.spanY(), spanY);
606 QCOMPARE(domain.spanY(), spanY);
607
607
608 TRY_COMPARE(spy0.count(), 0);
608 TRY_COMPARE(spy0.count(), 0);
609 TRY_COMPARE(spy1.count(), 0);
609 TRY_COMPARE(spy1.count(), 0);
610 TRY_COMPARE(spy2.count(), 0);
610 TRY_COMPARE(spy2.count(), 0);
611 }
611 }
612
612
613 void tst_Domain::zoom_data()
613 void tst_Domain::zoom_data()
614 {
614 {
615 QTest::addColumn<QRectF>("rect0");
615 QTest::addColumn<QRectF>("rect0");
616 QTest::addColumn<QSizeF>("size0");
616 QTest::addColumn<QSizeF>("size0");
617 QTest::addColumn<QRectF>("rect1");
617 QTest::addColumn<QRectF>("rect1");
618 QTest::addColumn<QSizeF>("size1");
618 QTest::addColumn<QSizeF>("size1");
619 QTest::addColumn<QRectF>("rect2");
619 QTest::addColumn<QRectF>("rect2");
620 QTest::addColumn<QSizeF>("size2");
620 QTest::addColumn<QSizeF>("size2");
621 QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000)
621 QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000)
622 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
622 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
623 << QSizeF(1000, 1000);
623 << QSizeF(1000, 1000);
624 QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000)
624 QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000)
625 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
625 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
626 << QSizeF(1000, 1000);
626 << QSizeF(1000, 1000);
627 QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20)
627 QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20)
628 << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100);
628 << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100);
629 }
629 }
630
630
631 void tst_Domain::zoom()
631 void tst_Domain::zoom()
632 {
632 {
633 QFETCH(QRectF, rect0);
633 QFETCH(QRectF, rect0);
634 QFETCH(QSizeF, size0);
634 QFETCH(QSizeF, size0);
635 QFETCH(QRectF, rect1);
635 QFETCH(QRectF, rect1);
636 QFETCH(QSizeF, size1);
636 QFETCH(QSizeF, size1);
637 QFETCH(QRectF, rect2);
637 QFETCH(QRectF, rect2);
638 QFETCH(QSizeF, size2);
638 QFETCH(QSizeF, size2);
639
639
640 Domain domain;
640 Domain domain;
641
641
642 domain.setRange(0, 1000, 0, 1000);
642 domain.setRange(0, 1000, 0, 1000);
643
643
644 QSignalSpy spy0(&domain, SIGNAL(updated()));
644 QSignalSpy spy0(&domain, SIGNAL(updated()));
645 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
645 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
646 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
646 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
647
647
648 Domain domain0;
648 Domain domain0;
649 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
649 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
650 domain.zoomIn(rect0, size0);
650 domain.zoomIn(rect0, size0);
651 Domain domain1;
651 Domain domain1;
652 domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
652 domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
653 domain.zoomIn(rect1, size1);
653 domain.zoomIn(rect1, size1);
654 Domain domain2;
654 Domain domain2;
655 domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
655 domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
656 domain.zoomIn(rect2, size2);
656 domain.zoomIn(rect2, size2);
657 domain.zoomOut(rect2, size2);
657 domain.zoomOut(rect2, size2);
658 QCOMPARE(domain == domain2, true);
658 QCOMPARE(domain == domain2, true);
659 domain.zoomOut(rect1, size1);
659 domain.zoomOut(rect1, size1);
660 QCOMPARE(domain == domain1, true);
660 QCOMPARE(domain == domain1, true);
661 domain.zoomOut(rect0, size0);
661 domain.zoomOut(rect0, size0);
662 QCOMPARE(domain == domain0, true);
662 QCOMPARE(domain == domain0, true);
663 TRY_COMPARE(spy0.count(), 6);
663 TRY_COMPARE(spy0.count(), 6);
664 TRY_COMPARE(spy1.count(), 6);
664 TRY_COMPARE(spy1.count(), 6);
665 TRY_COMPARE(spy2.count(), 6);
665 TRY_COMPARE(spy2.count(), 6);
666 }
666 }
667
667
668 void tst_Domain::move_data()
668 void tst_Domain::move_data()
669 {
669 {
670 QTest::addColumn<int>("dx");
670 QTest::addColumn<int>("dx");
671 QTest::addColumn<int>("dy");
671 QTest::addColumn<int>("dy");
672 QTest::addColumn<QSizeF>("size");
672 QTest::addColumn<QSizeF>("size");
673 QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000);
673 QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000);
674 QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000);
674 QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000);
675 QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000);
675 QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000);
676 QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000);
676 QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000);
677 QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000);
677 QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000);
678 QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000);
678 QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000);
679 }
679 }
680
680
681 void tst_Domain::move()
681 void tst_Domain::move()
682 {
682 {
683 QFETCH(int, dx);
683 QFETCH(int, dx);
684 QFETCH(int, dy);
684 QFETCH(int, dy);
685 QFETCH(QSizeF, size);
685 QFETCH(QSizeF, size);
686 Domain domain;
686 Domain domain;
687
687
688 domain.setRange(0, size.width(), 0, size.height());
688 domain.setRange(0, size.width(), 0, size.height());
689
689
690 QSignalSpy spy0(&domain, SIGNAL(updated()));
690 QSignalSpy spy0(&domain, SIGNAL(updated()));
691 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
691 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
692 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
692 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
693
693
694 domain.move(dx, dy, size);
694 domain.move(dx, dy, size);
695
695
696 Domain result;
696 Domain result;
697 result.setRange(dx, size.width() + dx, dy, size.height() + dy);
697 result.setRange(dx, size.width() + dx, dy, size.height() + dy);
698
698
699 QCOMPARE(domain == result, true);
699 QCOMPARE(domain == result, true);
700 TRY_COMPARE(spy0.count(), 1);
700 TRY_COMPARE(spy0.count(), 1);
701 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
701 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
702 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
702 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
703 }
703 }
704
704
705 QTEST_MAIN(tst_Domain)
705 QTEST_MAIN(tst_Domain)
706 #include "tst_domain.moc"
706 #include "tst_domain.moc"
707 #endif
707 #endif
@@ -1,520 +1,520
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qbarset.h>
22 #include <qbarset.h>
23 #include <qbarseries.h>
23 #include <qbarseries.h>
24 #include <qchartview.h>
24 #include <qchartview.h>
25 #include "tst_definitions.h"
25 #include "tst_definitions.h"
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 class tst_QBarSet : public QObject
29 class tst_QBarSet : public QObject
30 {
30 {
31 Q_OBJECT
31 Q_OBJECT
32
32
33 public slots:
33 public slots:
34 void initTestCase();
34 void initTestCase();
35 void cleanupTestCase();
35 void cleanupTestCase();
36 void init();
36 void init();
37 void cleanup();
37 void cleanup();
38
38
39 private slots:
39 private slots:
40 void qbarset_data();
40 void qbarset_data();
41 void qbarset();
41 void qbarset();
42 void label_data();
42 void label_data();
43 void label();
43 void label();
44 void append_data();
44 void append_data();
45 void append();
45 void append();
46 void appendOperator_data();
46 void appendOperator_data();
47 void appendOperator();
47 void appendOperator();
48 void insert_data();
48 void insert_data();
49 void insert();
49 void insert();
50 void remove_data();
50 void remove_data();
51 void remove();
51 void remove();
52 void replace_data();
52 void replace_data();
53 void replace();
53 void replace();
54 void at_data();
54 void at_data();
55 void at();
55 void at();
56 void atOperator_data();
56 void atOperator_data();
57 void atOperator();
57 void atOperator();
58 void count_data();
58 void count_data();
59 void count();
59 void count();
60 void sum_data();
60 void sum_data();
61 void sum();
61 void sum();
62 void customize();
62 void customize();
63
63
64 private:
64 private:
65 QBarSet* m_barset;
65 QBarSet* m_barset;
66 };
66 };
67
67
68 void tst_QBarSet::initTestCase()
68 void tst_QBarSet::initTestCase()
69 {
69 {
70 }
70 }
71
71
72 void tst_QBarSet::cleanupTestCase()
72 void tst_QBarSet::cleanupTestCase()
73 {
73 {
74 }
74 }
75
75
76 void tst_QBarSet::init()
76 void tst_QBarSet::init()
77 {
77 {
78 m_barset = new QBarSet(QString("label"));
78 m_barset = new QBarSet(QString("label"));
79 }
79 }
80
80
81 void tst_QBarSet::cleanup()
81 void tst_QBarSet::cleanup()
82 {
82 {
83 delete m_barset;
83 delete m_barset;
84 m_barset = 0;
84 m_barset = 0;
85 }
85 }
86
86
87 void tst_QBarSet::qbarset_data()
87 void tst_QBarSet::qbarset_data()
88 {
88 {
89 }
89 }
90
90
91 void tst_QBarSet::qbarset()
91 void tst_QBarSet::qbarset()
92 {
92 {
93 QBarSet barset(QString("label"));
93 QBarSet barset(QString("label"));
94 QCOMPARE(barset.label(), QString("label"));
94 QCOMPARE(barset.label(), QString("label"));
95 QCOMPARE(barset.count(), 0);
95 QCOMPARE(barset.count(), 0);
96 QVERIFY(qFuzzyIsNull(barset.sum()));
96 QVERIFY(qFuzzyCompare(barset.sum(), 0));
97 }
97 }
98
98
99 void tst_QBarSet::label_data()
99 void tst_QBarSet::label_data()
100 {
100 {
101 QTest::addColumn<QString> ("label");
101 QTest::addColumn<QString> ("label");
102 QTest::addColumn<QString> ("result");
102 QTest::addColumn<QString> ("result");
103 QTest::newRow("label0") << QString("label0") << QString("label0");
103 QTest::newRow("label0") << QString("label0") << QString("label0");
104 QTest::newRow("label1") << QString("label1") << QString("label1");
104 QTest::newRow("label1") << QString("label1") << QString("label1");
105 }
105 }
106
106
107 void tst_QBarSet::label()
107 void tst_QBarSet::label()
108 {
108 {
109 QFETCH(QString, label);
109 QFETCH(QString, label);
110 QFETCH(QString, result);
110 QFETCH(QString, result);
111
111
112 QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged()));
112 QSignalSpy labelSpy(m_barset,SIGNAL(labelChanged()));
113 m_barset->setLabel(label);
113 m_barset->setLabel(label);
114 QCOMPARE(m_barset->label(), result);
114 QCOMPARE(m_barset->label(), result);
115 QVERIFY(labelSpy.count() == 1);
115 QVERIFY(labelSpy.count() == 1);
116 }
116 }
117
117
118 void tst_QBarSet::append_data()
118 void tst_QBarSet::append_data()
119 {
119 {
120 QTest::addColumn<int> ("count");
120 QTest::addColumn<int> ("count");
121 QTest::newRow("0") << 0;
121 QTest::newRow("0") << 0;
122 QTest::newRow("5") << 5;
122 QTest::newRow("5") << 5;
123 QTest::newRow("100") << 100;
123 QTest::newRow("100") << 100;
124 QTest::newRow("1000") << 1000;
124 QTest::newRow("1000") << 1000;
125 }
125 }
126
126
127 void tst_QBarSet::append()
127 void tst_QBarSet::append()
128 {
128 {
129 QFETCH(int, count);
129 QFETCH(int, count);
130
130
131 QCOMPARE(m_barset->count(), 0);
131 QCOMPARE(m_barset->count(), 0);
132 QVERIFY(qFuzzyIsNull(m_barset->sum()));
132 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
133
133
134 QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int)));
134 QSignalSpy valueSpy(m_barset, SIGNAL(valuesAdded(int,int)));
135
135
136 qreal sum(0.0);
136 qreal sum(0.0);
137 qreal value(0.0);
137 qreal value(0.0);
138
138
139 for (int i=0; i<count; i++) {
139 for (int i=0; i<count; i++) {
140 m_barset->append(value);
140 m_barset->append(value);
141 QCOMPARE(m_barset->at(i), value);
141 QCOMPARE(m_barset->at(i), value);
142 sum += value;
142 sum += value;
143 value += 1.0;
143 value += 1.0;
144 }
144 }
145
145
146 QCOMPARE(m_barset->count(), count);
146 QCOMPARE(m_barset->count(), count);
147 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
147 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
148
148
149 QCOMPARE(valueSpy.count(), count);
149 QCOMPARE(valueSpy.count(), count);
150 }
150 }
151
151
152 void tst_QBarSet::appendOperator_data()
152 void tst_QBarSet::appendOperator_data()
153 {
153 {
154 append_data();
154 append_data();
155 }
155 }
156
156
157 void tst_QBarSet::appendOperator()
157 void tst_QBarSet::appendOperator()
158 {
158 {
159 QFETCH(int, count);
159 QFETCH(int, count);
160
160
161 QCOMPARE(m_barset->count(), 0);
161 QCOMPARE(m_barset->count(), 0);
162 QVERIFY(qFuzzyIsNull(m_barset->sum()));
162 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
163
163
164 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
164 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
165
165
166 qreal sum(0.0);
166 qreal sum(0.0);
167 qreal value(0.0);
167 qreal value(0.0);
168
168
169 for (int i=0; i<count; i++) {
169 for (int i=0; i<count; i++) {
170 *m_barset << value;
170 *m_barset << value;
171 QCOMPARE(m_barset->at(i), value);
171 QCOMPARE(m_barset->at(i), value);
172 sum += value;
172 sum += value;
173 value += 1.0;
173 value += 1.0;
174 }
174 }
175
175
176 QCOMPARE(m_barset->count(), count);
176 QCOMPARE(m_barset->count(), count);
177 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
177 QVERIFY(qFuzzyCompare(m_barset->sum(), sum));
178 QCOMPARE(valueSpy.count(), count);
178 QCOMPARE(valueSpy.count(), count);
179 }
179 }
180
180
181 void tst_QBarSet::insert_data()
181 void tst_QBarSet::insert_data()
182 {
182 {
183 }
183 }
184
184
185 void tst_QBarSet::insert()
185 void tst_QBarSet::insert()
186 {
186 {
187 QCOMPARE(m_barset->count(), 0);
187 QCOMPARE(m_barset->count(), 0);
188 QVERIFY(qFuzzyIsNull(m_barset->sum()));
188 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
189 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
189 QSignalSpy valueSpy(m_barset,SIGNAL(valuesAdded(int,int)));
190
190
191 m_barset->insert(0, 1.0); // 1.0
191 m_barset->insert(0, 1.0); // 1.0
192 QCOMPARE(m_barset->at(0), 1.0);
192 QCOMPARE(m_barset->at(0), 1.0);
193 QCOMPARE(m_barset->count(), 1);
193 QCOMPARE(m_barset->count(), 1);
194 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
194 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
195
195
196 m_barset->insert(0, 2.0); // 2.0 1.0
196 m_barset->insert(0, 2.0); // 2.0 1.0
197 QCOMPARE(m_barset->at(0), 2.0);
197 QCOMPARE(m_barset->at(0), 2.0);
198 QCOMPARE(m_barset->at(1), 1.0);
198 QCOMPARE(m_barset->at(1), 1.0);
199 QCOMPARE(m_barset->count(), 2);
199 QCOMPARE(m_barset->count(), 2);
200 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
200 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
201
201
202 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
202 m_barset->insert(1, 3.0); // 2.0 3.0 1.0
203 QCOMPARE(m_barset->at(1), 3.0);
203 QCOMPARE(m_barset->at(1), 3.0);
204 QCOMPARE(m_barset->at(0), 2.0);
204 QCOMPARE(m_barset->at(0), 2.0);
205 QCOMPARE(m_barset->at(2), 1.0);
205 QCOMPARE(m_barset->at(2), 1.0);
206 QCOMPARE(m_barset->count(), 3);
206 QCOMPARE(m_barset->count(), 3);
207 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
207 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
208 QCOMPARE(valueSpy.count(), 3);
208 QCOMPARE(valueSpy.count(), 3);
209 }
209 }
210
210
211 void tst_QBarSet::remove_data()
211 void tst_QBarSet::remove_data()
212 {
212 {
213 }
213 }
214
214
215 void tst_QBarSet::remove()
215 void tst_QBarSet::remove()
216 {
216 {
217 QCOMPARE(m_barset->count(), 0);
217 QCOMPARE(m_barset->count(), 0);
218 QVERIFY(qFuzzyIsNull(m_barset->sum()));
218 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
219
219
220 QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int)));
220 QSignalSpy valueSpy(m_barset,SIGNAL(valuesRemoved(int,int)));
221
221
222 m_barset->append(1.0);
222 m_barset->append(1.0);
223 m_barset->append(2.0);
223 m_barset->append(2.0);
224 m_barset->append(3.0);
224 m_barset->append(3.0);
225 m_barset->append(4.0);
225 m_barset->append(4.0);
226
226
227 QCOMPARE(m_barset->count(), 4);
227 QCOMPARE(m_barset->count(), 4);
228 QCOMPARE(m_barset->sum(), 10.0);
228 QCOMPARE(m_barset->sum(), 10.0);
229
229
230 // Remove middle
230 // Remove middle
231 m_barset->remove(2); // 1.0 2.0 4.0
231 m_barset->remove(2); // 1.0 2.0 4.0
232 QCOMPARE(m_barset->at(0), 1.0);
232 QCOMPARE(m_barset->at(0), 1.0);
233 QCOMPARE(m_barset->at(1), 2.0);
233 QCOMPARE(m_barset->at(1), 2.0);
234 QCOMPARE(m_barset->at(2), 4.0);
234 QCOMPARE(m_barset->at(2), 4.0);
235 QCOMPARE(m_barset->count(), 3);
235 QCOMPARE(m_barset->count(), 3);
236 QCOMPARE(m_barset->sum(), 7.0);
236 QCOMPARE(m_barset->sum(), 7.0);
237 QCOMPARE(valueSpy.count(), 1);
237 QCOMPARE(valueSpy.count(), 1);
238
238
239 QList<QVariant> valueSpyArg = valueSpy.takeFirst();
239 QList<QVariant> valueSpyArg = valueSpy.takeFirst();
240 // Verify index of removed signal
240 // Verify index of removed signal
241 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
241 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
242 QVERIFY(valueSpyArg.at(0).toInt() == 2);
242 QVERIFY(valueSpyArg.at(0).toInt() == 2);
243 // Verify count of removed signal
243 // Verify count of removed signal
244 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
244 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
245 QVERIFY(valueSpyArg.at(1).toInt() == 1);
245 QVERIFY(valueSpyArg.at(1).toInt() == 1);
246
246
247 // Remove first
247 // Remove first
248 m_barset->remove(0); // 2.0 4.0
248 m_barset->remove(0); // 2.0 4.0
249 QCOMPARE(m_barset->at(0), 2.0);
249 QCOMPARE(m_barset->at(0), 2.0);
250 QCOMPARE(m_barset->at(1), 4.0);
250 QCOMPARE(m_barset->at(1), 4.0);
251 QCOMPARE(m_barset->count(), 2);
251 QCOMPARE(m_barset->count(), 2);
252 QCOMPARE(m_barset->sum(), 6.0);
252 QCOMPARE(m_barset->sum(), 6.0);
253
253
254 QCOMPARE(valueSpy.count(), 1);
254 QCOMPARE(valueSpy.count(), 1);
255 valueSpyArg = valueSpy.takeFirst();
255 valueSpyArg = valueSpy.takeFirst();
256 // Verify index of removed signal
256 // Verify index of removed signal
257 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
257 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
258 QVERIFY(valueSpyArg.at(0).toInt() == 0);
258 QVERIFY(valueSpyArg.at(0).toInt() == 0);
259 // Verify count of removed signal
259 // Verify count of removed signal
260 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
260 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
261 QVERIFY(valueSpyArg.at(1).toInt() == 1);
261 QVERIFY(valueSpyArg.at(1).toInt() == 1);
262
262
263
263
264 // Illegal indexes
264 // Illegal indexes
265 m_barset->remove(4);
265 m_barset->remove(4);
266 QCOMPARE(m_barset->count(), 2);
266 QCOMPARE(m_barset->count(), 2);
267 QCOMPARE(m_barset->sum(), 6.0);
267 QCOMPARE(m_barset->sum(), 6.0);
268 m_barset->remove(-1);
268 m_barset->remove(-1);
269 QCOMPARE(m_barset->count(), 2);
269 QCOMPARE(m_barset->count(), 2);
270 QCOMPARE(m_barset->sum(), 6.0);
270 QCOMPARE(m_barset->sum(), 6.0);
271
271
272 // nothing removed, no signals should be emitted
272 // nothing removed, no signals should be emitted
273 QCOMPARE(valueSpy.count(), 0);
273 QCOMPARE(valueSpy.count(), 0);
274
274
275 // Remove more items than list has
275 // Remove more items than list has
276 m_barset->remove(0,312);
276 m_barset->remove(0,312);
277 QCOMPARE(m_barset->count(), 0);
277 QCOMPARE(m_barset->count(), 0);
278 QVERIFY(qFuzzyIsNull(m_barset->sum()));
278 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
279
279
280 QCOMPARE(valueSpy.count(), 1);
280 QCOMPARE(valueSpy.count(), 1);
281 valueSpyArg = valueSpy.takeFirst();
281 valueSpyArg = valueSpy.takeFirst();
282
282
283 // Verify index of removed signal
283 // Verify index of removed signal
284 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
284 QVERIFY(valueSpyArg.at(0).type() == QVariant::Int);
285 QVERIFY(valueSpyArg.at(0).toInt() == 0);
285 QVERIFY(valueSpyArg.at(0).toInt() == 0);
286 // Verify count of removed signal (expect 2 values removed, because list had only 2 items)
286 // Verify count of removed signal (expect 2 values removed, because list had only 2 items)
287 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
287 QVERIFY(valueSpyArg.at(1).type() == QVariant::Int);
288 QVERIFY(valueSpyArg.at(1).toInt() == 2);
288 QVERIFY(valueSpyArg.at(1).toInt() == 2);
289 }
289 }
290
290
291 void tst_QBarSet::replace_data()
291 void tst_QBarSet::replace_data()
292 {
292 {
293
293
294 }
294 }
295
295
296 void tst_QBarSet::replace()
296 void tst_QBarSet::replace()
297 {
297 {
298 QCOMPARE(m_barset->count(), 0);
298 QCOMPARE(m_barset->count(), 0);
299 QVERIFY(qFuzzyIsNull(m_barset->sum()));
299 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
300 QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int)));
300 QSignalSpy valueSpy(m_barset,SIGNAL(valueChanged(int)));
301
301
302 m_barset->append(1.0);
302 m_barset->append(1.0);
303 m_barset->append(2.0);
303 m_barset->append(2.0);
304 m_barset->append(3.0);
304 m_barset->append(3.0);
305 m_barset->append(4.0);
305 m_barset->append(4.0);
306
306
307 QCOMPARE(m_barset->count(), 4);
307 QCOMPARE(m_barset->count(), 4);
308 QCOMPARE(m_barset->sum(), 10.0);
308 QCOMPARE(m_barset->sum(), 10.0);
309
309
310 // Replace first
310 // Replace first
311 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
311 m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0
312 QCOMPARE(m_barset->count(), 4);
312 QCOMPARE(m_barset->count(), 4);
313 QCOMPARE(m_barset->sum(), 14.0);
313 QCOMPARE(m_barset->sum(), 14.0);
314 QCOMPARE(m_barset->at(0), 5.0);
314 QCOMPARE(m_barset->at(0), 5.0);
315
315
316 // Replace last
316 // Replace last
317 m_barset->replace(3, 6.0);
317 m_barset->replace(3, 6.0);
318 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
318 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
319 QCOMPARE(m_barset->sum(), 16.0);
319 QCOMPARE(m_barset->sum(), 16.0);
320 QCOMPARE(m_barset->at(0), 5.0);
320 QCOMPARE(m_barset->at(0), 5.0);
321 QCOMPARE(m_barset->at(1), 2.0);
321 QCOMPARE(m_barset->at(1), 2.0);
322 QCOMPARE(m_barset->at(2), 3.0);
322 QCOMPARE(m_barset->at(2), 3.0);
323 QCOMPARE(m_barset->at(3), 6.0);
323 QCOMPARE(m_barset->at(3), 6.0);
324
324
325 // Illegal indexes
325 // Illegal indexes
326 m_barset->replace(4, 6.0);
326 m_barset->replace(4, 6.0);
327 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
327 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
328 QCOMPARE(m_barset->sum(), 16.0);
328 QCOMPARE(m_barset->sum(), 16.0);
329 m_barset->replace(-1, 6.0);
329 m_barset->replace(-1, 6.0);
330 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
330 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
331 QCOMPARE(m_barset->sum(), 16.0);
331 QCOMPARE(m_barset->sum(), 16.0);
332 m_barset->replace(4, 1.0);
332 m_barset->replace(4, 1.0);
333 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
333 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
334 QCOMPARE(m_barset->sum(), 16.0);
334 QCOMPARE(m_barset->sum(), 16.0);
335 m_barset->replace(-1, 1.0);
335 m_barset->replace(-1, 1.0);
336 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
336 QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0
337 QCOMPARE(m_barset->sum(), 16.0);
337 QCOMPARE(m_barset->sum(), 16.0);
338
338
339 QVERIFY(valueSpy.count() == 2);
339 QVERIFY(valueSpy.count() == 2);
340 }
340 }
341
341
342 void tst_QBarSet::at_data()
342 void tst_QBarSet::at_data()
343 {
343 {
344
344
345 }
345 }
346
346
347 void tst_QBarSet::at()
347 void tst_QBarSet::at()
348 {
348 {
349 QCOMPARE(m_barset->count(), 0);
349 QCOMPARE(m_barset->count(), 0);
350 QVERIFY(qFuzzyIsNull(m_barset->sum()));
350 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
351
351
352 m_barset->append(1.0);
352 m_barset->append(1.0);
353 m_barset->append(2.0);
353 m_barset->append(2.0);
354 m_barset->append(3.0);
354 m_barset->append(3.0);
355 m_barset->append(4.0);
355 m_barset->append(4.0);
356
356
357 QCOMPARE(m_barset->at(0), 1.0);
357 QCOMPARE(m_barset->at(0), 1.0);
358 QCOMPARE(m_barset->at(1), 2.0);
358 QCOMPARE(m_barset->at(1), 2.0);
359 QCOMPARE(m_barset->at(2), 3.0);
359 QCOMPARE(m_barset->at(2), 3.0);
360 QCOMPARE(m_barset->at(3), 4.0);
360 QCOMPARE(m_barset->at(3), 4.0);
361 }
361 }
362
362
363 void tst_QBarSet::atOperator_data()
363 void tst_QBarSet::atOperator_data()
364 {
364 {
365
365
366 }
366 }
367
367
368 void tst_QBarSet::atOperator()
368 void tst_QBarSet::atOperator()
369 {
369 {
370 QCOMPARE(m_barset->count(), 0);
370 QCOMPARE(m_barset->count(), 0);
371 QVERIFY(qFuzzyIsNull(m_barset->sum()));
371 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
372
372
373 m_barset->append(1.0);
373 m_barset->append(1.0);
374 m_barset->append(2.0);
374 m_barset->append(2.0);
375 m_barset->append(3.0);
375 m_barset->append(3.0);
376 m_barset->append(4.0);
376 m_barset->append(4.0);
377
377
378 QCOMPARE(m_barset->operator [](0), 1.0);
378 QCOMPARE(m_barset->operator [](0), 1.0);
379 QCOMPARE(m_barset->operator [](1), 2.0);
379 QCOMPARE(m_barset->operator [](1), 2.0);
380 QCOMPARE(m_barset->operator [](2), 3.0);
380 QCOMPARE(m_barset->operator [](2), 3.0);
381 QCOMPARE(m_barset->operator [](3), 4.0);
381 QCOMPARE(m_barset->operator [](3), 4.0);
382 }
382 }
383
383
384 void tst_QBarSet::count_data()
384 void tst_QBarSet::count_data()
385 {
385 {
386
386
387 }
387 }
388
388
389 void tst_QBarSet::count()
389 void tst_QBarSet::count()
390 {
390 {
391 QCOMPARE(m_barset->count(), 0);
391 QCOMPARE(m_barset->count(), 0);
392 QVERIFY(qFuzzyIsNull(m_barset->sum()));
392 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
393
393
394 m_barset->append(1.0);
394 m_barset->append(1.0);
395 QCOMPARE(m_barset->count(),1);
395 QCOMPARE(m_barset->count(),1);
396 m_barset->append(2.0);
396 m_barset->append(2.0);
397 QCOMPARE(m_barset->count(),2);
397 QCOMPARE(m_barset->count(),2);
398 m_barset->append(3.0);
398 m_barset->append(3.0);
399 QCOMPARE(m_barset->count(),3);
399 QCOMPARE(m_barset->count(),3);
400 m_barset->append(4.0);
400 m_barset->append(4.0);
401 QCOMPARE(m_barset->count(),4);
401 QCOMPARE(m_barset->count(),4);
402 }
402 }
403
403
404 void tst_QBarSet::sum_data()
404 void tst_QBarSet::sum_data()
405 {
405 {
406
406
407 }
407 }
408
408
409 void tst_QBarSet::sum()
409 void tst_QBarSet::sum()
410 {
410 {
411 QCOMPARE(m_barset->count(), 0);
411 QCOMPARE(m_barset->count(), 0);
412 QVERIFY(qFuzzyIsNull(m_barset->sum()));
412 QVERIFY(qFuzzyCompare(m_barset->sum(), 0));
413
413
414 m_barset->append(1.0);
414 m_barset->append(1.0);
415 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
415 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)1.0));
416 m_barset->append(2.0);
416 m_barset->append(2.0);
417 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
417 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)3.0));
418 m_barset->append(3.0);
418 m_barset->append(3.0);
419 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
419 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)6.0));
420 m_barset->append(4.0);
420 m_barset->append(4.0);
421 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0));
421 QVERIFY(qFuzzyCompare(m_barset->sum(), (qreal)10.0));
422 }
422 }
423
423
424 void tst_QBarSet::customize()
424 void tst_QBarSet::customize()
425 {
425 {
426 // Create sets
426 // Create sets
427 QBarSet *set1 = new QBarSet("set1");
427 QBarSet *set1 = new QBarSet("set1");
428 QBarSet *set2 = new QBarSet("set2");
428 QBarSet *set2 = new QBarSet("set2");
429
429
430 // Append set1 to series
430 // Append set1 to series
431 QBarSeries *series = new QBarSeries();
431 QBarSeries *series = new QBarSeries();
432 bool success = series->append(set1);
432 bool success = series->append(set1);
433 QVERIFY(success);
433 QVERIFY(success);
434
434
435 // Add series to the chart
435 // Add series to the chart
436 QChartView view(new QChart());
436 QChartView view(new QChart());
437 view.resize(200, 200);
437 view.resize(200, 200);
438 view.chart()->addSeries(series);
438 view.chart()->addSeries(series);
439 view.show();
439 view.show();
440 QTest::qWaitForWindowShown(&view);
440 QTest::qWaitForWindowShown(&view);
441
441
442 // Test adding data to the sets
442 // Test adding data to the sets
443 *set1 << 1 << 2 << 1 << 3;
443 *set1 << 1 << 2 << 1 << 3;
444 *set2 << 2 << 1 << 3 << 1;
444 *set2 << 2 << 1 << 3 << 1;
445
445
446 // Remove sets from series
446 // Remove sets from series
447 series->take(set1);
447 series->take(set1);
448 series->take(set2);
448 series->take(set2);
449
449
450 // Test pen
450 // Test pen
451 QVERIFY(set1->pen() != QPen());
451 QVERIFY(set1->pen() != QPen());
452 QVERIFY(set2->pen() == QPen());
452 QVERIFY(set2->pen() == QPen());
453 QPen pen(QColor(128,128,128,128));
453 QPen pen(QColor(128,128,128,128));
454 set1->setPen(pen);
454 set1->setPen(pen);
455
455
456 // Add sets back to series
456 // Add sets back to series
457 series->append(set1);
457 series->append(set1);
458 series->append(set2);
458 series->append(set2);
459
459
460 QVERIFY(set1->pen() == pen); // Should be customized
460 QVERIFY(set1->pen() == pen); // Should be customized
461 QVERIFY(set2->pen() != QPen()); // Should be decorated by theme
461 QVERIFY(set2->pen() != QPen()); // Should be decorated by theme
462
462
463 // Remove sets from series
463 // Remove sets from series
464 series->take(set1);
464 series->take(set1);
465 series->take(set2);
465 series->take(set2);
466
466
467 // Test brush
467 // Test brush
468 set2->setBrush(QBrush());
468 set2->setBrush(QBrush());
469 QVERIFY(set1->brush() != QBrush());
469 QVERIFY(set1->brush() != QBrush());
470 QVERIFY(set2->brush() == QBrush());
470 QVERIFY(set2->brush() == QBrush());
471 QBrush brush(QColor(128,128,128,128));
471 QBrush brush(QColor(128,128,128,128));
472 set1->setBrush(brush);
472 set1->setBrush(brush);
473
473
474 // Add sets back to series
474 // Add sets back to series
475 series->append(set1);
475 series->append(set1);
476 series->append(set2);
476 series->append(set2);
477
477
478 QVERIFY(set1->brush() == brush); // Should be customized
478 QVERIFY(set1->brush() == brush); // Should be customized
479 QVERIFY(set2->brush() != QBrush()); // Should be decorated by theme
479 QVERIFY(set2->brush() != QBrush()); // Should be decorated by theme
480
480
481 // Remove sets from series
481 // Remove sets from series
482 series->take(set1);
482 series->take(set1);
483 series->take(set2);
483 series->take(set2);
484
484
485 // Test label brush
485 // Test label brush
486 set2->setLabelBrush(QBrush());
486 set2->setLabelBrush(QBrush());
487 QVERIFY(set1->labelBrush() != QBrush());
487 QVERIFY(set1->labelBrush() != QBrush());
488 QVERIFY(set2->labelBrush() == QBrush());
488 QVERIFY(set2->labelBrush() == QBrush());
489 set1->setLabelBrush(brush);
489 set1->setLabelBrush(brush);
490
490
491 series->append(set1);
491 series->append(set1);
492 series->append(set2);
492 series->append(set2);
493 QVERIFY(set1->labelBrush() == brush); // Should be customized
493 QVERIFY(set1->labelBrush() == brush); // Should be customized
494 QVERIFY(set2->labelBrush() != QBrush()); // Should be decorated by theme
494 QVERIFY(set2->labelBrush() != QBrush()); // Should be decorated by theme
495
495
496 // Test label font
496 // Test label font
497 // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the
497 // Note: QFont empty constructor creates font with application's default font, so the font may or may not be the
498 // same for the set added to the series (depending on the QChart's theme configuration)
498 // same for the set added to the series (depending on the QChart's theme configuration)
499 QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont());
499 QVERIFY(set1->labelFont() != QFont() || set1->labelFont() == QFont());
500 QVERIFY(set2->labelFont() == QFont());
500 QVERIFY(set2->labelFont() == QFont());
501 QFont font;
501 QFont font;
502 font.setBold(true);
502 font.setBold(true);
503 font.setItalic(true);
503 font.setItalic(true);
504 set1->setLabelFont(font);
504 set1->setLabelFont(font);
505 QVERIFY(set1->labelFont() == font);
505 QVERIFY(set1->labelFont() == font);
506 QVERIFY(set2->labelFont() == QFont());
506 QVERIFY(set2->labelFont() == QFont());
507
507
508 // Test adding data to the sets
508 // Test adding data to the sets
509 *set1 << 1 << 2 << 1 << 3;
509 *set1 << 1 << 2 << 1 << 3;
510 *set2 << 2 << 1 << 3 << 1;
510 *set2 << 2 << 1 << 3 << 1;
511
511
512 }
512 }
513
513
514
514
515
515
516
516
517 QTEST_MAIN(tst_QBarSet)
517 QTEST_MAIN(tst_QBarSet)
518
518
519 #include "tst_qbarset.moc"
519 #include "tst_qbarset.moc"
520
520
@@ -1,307 +1,307
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/tst_qabstractaxis.h"
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include "qcategoryaxis.h"
22 #include "qcategoryaxis.h"
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24
24
25 class tst_QCategoryAxis: public tst_QAbstractAxis
25 class tst_QCategoryAxis: public tst_QAbstractAxis
26 {
26 {
27 Q_OBJECT
27 Q_OBJECT
28
28
29 public slots:
29 public slots:
30 void initTestCase();
30 void initTestCase();
31 void cleanupTestCase();
31 void cleanupTestCase();
32 void init();
32 void init();
33 void cleanup();
33 void cleanup();
34
34
35 private slots:
35 private slots:
36 void qcategoryaxis_data();
36 void qcategoryaxis_data();
37 void qcategoryaxis();
37 void qcategoryaxis();
38
38
39 void max_raw_data();
39 void max_raw_data();
40 void max_raw();
40 void max_raw();
41 void max_data();
41 void max_data();
42 void max();
42 void max();
43 void max_animation_data();
43 void max_animation_data();
44 void max_animation();
44 void max_animation();
45 void min_raw_data();
45 void min_raw_data();
46 void min_raw();
46 void min_raw();
47 void min_data();
47 void min_data();
48 void min();
48 void min();
49 void min_animation_data();
49 void min_animation_data();
50 void min_animation();
50 void min_animation();
51 void range_raw_data();
51 void range_raw_data();
52 void range_raw();
52 void range_raw();
53 void range_data();
53 void range_data();
54 void range();
54 void range();
55 void range_animation_data();
55 void range_animation_data();
56 void range_animation();
56 void range_animation();
57
57
58 void interval_data();
58 void interval_data();
59 void interval();
59 void interval();
60
60
61 private:
61 private:
62 QCategoryAxis* m_categoryaxis;
62 QCategoryAxis* m_categoryaxis;
63 QLineSeries* m_series;
63 QLineSeries* m_series;
64 };
64 };
65
65
66 void tst_QCategoryAxis::initTestCase()
66 void tst_QCategoryAxis::initTestCase()
67 {
67 {
68 }
68 }
69
69
70 void tst_QCategoryAxis::cleanupTestCase()
70 void tst_QCategoryAxis::cleanupTestCase()
71 {
71 {
72 }
72 }
73
73
74 void tst_QCategoryAxis::init()
74 void tst_QCategoryAxis::init()
75 {
75 {
76 m_categoryaxis = new QCategoryAxis();
76 m_categoryaxis = new QCategoryAxis();
77 m_series = new QLineSeries();
77 m_series = new QLineSeries();
78 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
78 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
79 tst_QAbstractAxis::init(m_categoryaxis, m_series);
79 tst_QAbstractAxis::init(m_categoryaxis, m_series);
80 m_chart->addSeries(m_series);
80 m_chart->addSeries(m_series);
81 m_chart->createDefaultAxes();
81 m_chart->createDefaultAxes();
82 }
82 }
83
83
84 void tst_QCategoryAxis::cleanup()
84 void tst_QCategoryAxis::cleanup()
85 {
85 {
86 delete m_series;
86 delete m_series;
87 delete m_categoryaxis;
87 delete m_categoryaxis;
88 m_series = 0;
88 m_series = 0;
89 m_categoryaxis = 0;
89 m_categoryaxis = 0;
90 tst_QAbstractAxis::cleanup();
90 tst_QAbstractAxis::cleanup();
91 }
91 }
92
92
93 void tst_QCategoryAxis::qcategoryaxis_data()
93 void tst_QCategoryAxis::qcategoryaxis_data()
94 {
94 {
95 }
95 }
96
96
97 void tst_QCategoryAxis::qcategoryaxis()
97 void tst_QCategoryAxis::qcategoryaxis()
98 {
98 {
99 qabstractaxis();
99 qabstractaxis();
100
100
101 QVERIFY(qFuzzyIsNull(m_categoryaxis->max()));
101 QVERIFY(qFuzzyCompare(m_categoryaxis->max(), 0));
102 QVERIFY(qFuzzyIsNull(m_categoryaxis->min()));
102 QVERIFY(qFuzzyCompare(m_categoryaxis->min(), 0));
103 QCOMPARE(m_categoryaxis->type(), QAbstractAxis::AxisTypeCategory);
103 QCOMPARE(m_categoryaxis->type(), QAbstractAxis::AxisTypeCategory);
104
104
105 m_chart->setAxisX(m_categoryaxis, m_series);
105 m_chart->setAxisX(m_categoryaxis, m_series);
106 m_view->show();
106 m_view->show();
107 QTest::qWaitForWindowShown(m_view);
107 QTest::qWaitForWindowShown(m_view);
108
108
109 QVERIFY(!qFuzzyIsNull(m_categoryaxis->max()));
109 QVERIFY(!qFuzzyCompare(m_categoryaxis->max(), 0));
110 QVERIFY(!qFuzzyIsNull(m_categoryaxis->min()));
110 QVERIFY(!qFuzzyCompare(m_categoryaxis->min(), 0));
111 }
111 }
112
112
113 void tst_QCategoryAxis::max_raw_data()
113 void tst_QCategoryAxis::max_raw_data()
114 {
114 {
115 QTest::addColumn<qreal>("max");
115 QTest::addColumn<qreal>("max");
116 QTest::newRow("1.0") << (qreal)1.0;
116 QTest::newRow("1.0") << (qreal)1.0;
117 QTest::newRow("50.0") << (qreal)50.0;
117 QTest::newRow("50.0") << (qreal)50.0;
118 QTest::newRow("101.0") << (qreal)101.0;
118 QTest::newRow("101.0") << (qreal)101.0;
119 }
119 }
120
120
121 void tst_QCategoryAxis::max_raw()
121 void tst_QCategoryAxis::max_raw()
122 {
122 {
123 QFETCH(qreal, max);
123 QFETCH(qreal, max);
124
124
125 QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal)));
125 QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal)));
126 QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal)));
126 QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal)));
127 QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal)));
127 QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal)));
128
128
129 m_categoryaxis->setMax(max);
129 m_categoryaxis->setMax(max);
130 QVERIFY2(qFuzzyIsNull(m_categoryaxis->max() - max), "Not equal");
130 QVERIFY2(qFuzzyCompare(m_categoryaxis->max(), max), "Not equal");
131
131
132 QCOMPARE(spy0.count(), 1);
132 QCOMPARE(spy0.count(), 1);
133 QCOMPARE(spy1.count(), 0);
133 QCOMPARE(spy1.count(), 0);
134 QCOMPARE(spy2.count(), 1);
134 QCOMPARE(spy2.count(), 1);
135 }
135 }
136
136
137 void tst_QCategoryAxis::max_data()
137 void tst_QCategoryAxis::max_data()
138 {
138 {
139 max_raw_data();
139 max_raw_data();
140 }
140 }
141
141
142 void tst_QCategoryAxis::max()
142 void tst_QCategoryAxis::max()
143 {
143 {
144 m_chart->setAxisX(m_categoryaxis, m_series);
144 m_chart->setAxisX(m_categoryaxis, m_series);
145 m_view->show();
145 m_view->show();
146 QTest::qWaitForWindowShown(m_view);
146 QTest::qWaitForWindowShown(m_view);
147 max_raw();
147 max_raw();
148 }
148 }
149
149
150 void tst_QCategoryAxis::max_animation_data()
150 void tst_QCategoryAxis::max_animation_data()
151 {
151 {
152 max_data();
152 max_data();
153 }
153 }
154
154
155 void tst_QCategoryAxis::max_animation()
155 void tst_QCategoryAxis::max_animation()
156 {
156 {
157 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
157 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
158 max();
158 max();
159 }
159 }
160
160
161 void tst_QCategoryAxis::min_raw_data()
161 void tst_QCategoryAxis::min_raw_data()
162 {
162 {
163 QTest::addColumn<qreal>("min");
163 QTest::addColumn<qreal>("min");
164 QTest::newRow("-1.0") << (qreal)-1.0;
164 QTest::newRow("-1.0") << (qreal)-1.0;
165 QTest::newRow("-50.0") << (qreal)-50.0;
165 QTest::newRow("-50.0") << (qreal)-50.0;
166 QTest::newRow("-101.0") << (qreal)-101.0;
166 QTest::newRow("-101.0") << (qreal)-101.0;
167 }
167 }
168
168
169 void tst_QCategoryAxis::min_raw()
169 void tst_QCategoryAxis::min_raw()
170 {
170 {
171 QFETCH(qreal, min);
171 QFETCH(qreal, min);
172
172
173 QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal)));
173 QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal)));
174 QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal)));
174 QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal)));
175 QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal)));
175 QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal)));
176
176
177 m_categoryaxis->setMin(min);
177 m_categoryaxis->setMin(min);
178 QVERIFY2(qFuzzyIsNull(m_categoryaxis->min() - min), "Not equal");
178 QVERIFY2(qFuzzyCompare(m_categoryaxis->min(), min), "Not equal");
179
179
180 QCOMPARE(spy0.count(), 0);
180 QCOMPARE(spy0.count(), 0);
181 QCOMPARE(spy1.count(), 1);
181 QCOMPARE(spy1.count(), 1);
182 QCOMPARE(spy2.count(), 1);
182 QCOMPARE(spy2.count(), 1);
183 }
183 }
184
184
185 void tst_QCategoryAxis::min_data()
185 void tst_QCategoryAxis::min_data()
186 {
186 {
187 min_raw_data();
187 min_raw_data();
188 }
188 }
189
189
190 void tst_QCategoryAxis::min()
190 void tst_QCategoryAxis::min()
191 {
191 {
192 m_chart->setAxisX(m_categoryaxis, m_series);
192 m_chart->setAxisX(m_categoryaxis, m_series);
193 m_view->show();
193 m_view->show();
194 QTest::qWaitForWindowShown(m_view);
194 QTest::qWaitForWindowShown(m_view);
195 min_raw();
195 min_raw();
196 }
196 }
197
197
198 void tst_QCategoryAxis::min_animation_data()
198 void tst_QCategoryAxis::min_animation_data()
199 {
199 {
200 min_data();
200 min_data();
201 }
201 }
202
202
203 void tst_QCategoryAxis::min_animation()
203 void tst_QCategoryAxis::min_animation()
204 {
204 {
205 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
205 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
206 min();
206 min();
207 }
207 }
208
208
209 void tst_QCategoryAxis::range_raw_data()
209 void tst_QCategoryAxis::range_raw_data()
210 {
210 {
211 QTest::addColumn<qreal>("min");
211 QTest::addColumn<qreal>("min");
212 QTest::addColumn<qreal>("max");
212 QTest::addColumn<qreal>("max");
213 QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0;
213 QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0;
214 QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0;
214 QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0;
215 QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0;
215 QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0;
216 QTest::newRow("-35.0 - 0.0") << (qreal)-35.0 << (qreal)10.0;
216 QTest::newRow("-35.0 - 0.0") << (qreal)-35.0 << (qreal)10.0;
217 QTest::newRow("-35.0 - 0.0") << (qreal)-35.0 << (qreal)-15.0;
217 QTest::newRow("-35.0 - 0.0") << (qreal)-35.0 << (qreal)-15.0;
218 QTest::newRow("0.0 - 0.0") << (qreal)-0.1 << (qreal)0.1;
218 QTest::newRow("0.0 - 0.0") << (qreal)-0.1 << (qreal)0.1;
219 }
219 }
220
220
221 void tst_QCategoryAxis::range_raw()
221 void tst_QCategoryAxis::range_raw()
222 {
222 {
223 QFETCH(qreal, min);
223 QFETCH(qreal, min);
224 QFETCH(qreal, max);
224 QFETCH(qreal, max);
225
225
226 QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal)));
226 QSignalSpy spy0(m_categoryaxis, SIGNAL(maxChanged(qreal)));
227 QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal)));
227 QSignalSpy spy1(m_categoryaxis, SIGNAL(minChanged(qreal)));
228 QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal)));
228 QSignalSpy spy2(m_categoryaxis, SIGNAL(rangeChanged(qreal,qreal)));
229
229
230 m_categoryaxis->setRange(min, max);
230 m_categoryaxis->setRange(min, max);
231 QVERIFY2(qFuzzyIsNull(m_categoryaxis->min() - min), "Min not equal");
231 QVERIFY2(qFuzzyCompare(m_categoryaxis->min(), min), "Min not equal");
232 QVERIFY2(qFuzzyIsNull(m_categoryaxis->max() - max), "Max not equal");
232 QVERIFY2(qFuzzyCompare(m_categoryaxis->max(), max), "Max not equal");
233
233
234 QCOMPARE(spy0.count(), 1);
234 QCOMPARE(spy0.count(), 1);
235 QCOMPARE(spy1.count(), 1);
235 QCOMPARE(spy1.count(), 1);
236 QCOMPARE(spy2.count(), 1);
236 QCOMPARE(spy2.count(), 1);
237 }
237 }
238
238
239 void tst_QCategoryAxis::range_data()
239 void tst_QCategoryAxis::range_data()
240 {
240 {
241 range_raw_data();
241 range_raw_data();
242 }
242 }
243
243
244 void tst_QCategoryAxis::range()
244 void tst_QCategoryAxis::range()
245 {
245 {
246 m_chart->setAxisX(m_categoryaxis, m_series);
246 m_chart->setAxisX(m_categoryaxis, m_series);
247 m_view->show();
247 m_view->show();
248 QTest::qWaitForWindowShown(m_view);
248 QTest::qWaitForWindowShown(m_view);
249 range_raw();
249 range_raw();
250 }
250 }
251
251
252 void tst_QCategoryAxis::range_animation_data()
252 void tst_QCategoryAxis::range_animation_data()
253 {
253 {
254 range_data();
254 range_data();
255 }
255 }
256
256
257 void tst_QCategoryAxis::range_animation()
257 void tst_QCategoryAxis::range_animation()
258 {
258 {
259 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
259 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
260 range();
260 range();
261 }
261 }
262
262
263 void tst_QCategoryAxis::interval_data()
263 void tst_QCategoryAxis::interval_data()
264 {
264 {
265 //
265 //
266 }
266 }
267
267
268 void tst_QCategoryAxis::interval()
268 void tst_QCategoryAxis::interval()
269 {
269 {
270 // append one correct interval
270 // append one correct interval
271 m_categoryaxis->append("first", (qreal)45);
271 m_categoryaxis->append("first", (qreal)45);
272 QCOMPARE(m_categoryaxis->startValue("first"), (qreal)0);
272 QCOMPARE(m_categoryaxis->startValue("first"), (qreal)0);
273 QCOMPARE(m_categoryaxis->endValue("first"), (qreal)45);
273 QCOMPARE(m_categoryaxis->endValue("first"), (qreal)45);
274
274
275 // append one more correct interval
275 // append one more correct interval
276 m_categoryaxis->append("second", (qreal)75);
276 m_categoryaxis->append("second", (qreal)75);
277 QCOMPARE(m_categoryaxis->startValue("second"), (qreal)45);
277 QCOMPARE(m_categoryaxis->startValue("second"), (qreal)45);
278 QCOMPARE(m_categoryaxis->endValue("second"), (qreal)75);
278 QCOMPARE(m_categoryaxis->endValue("second"), (qreal)75);
279
279
280 // append one incorrect interval
280 // append one incorrect interval
281 m_categoryaxis->append("third", (qreal)15);
281 m_categoryaxis->append("third", (qreal)15);
282 QCOMPARE(m_categoryaxis->count(), 2);
282 QCOMPARE(m_categoryaxis->count(), 2);
283 QCOMPARE(m_categoryaxis->endValue(m_categoryaxis->categoriesLabels().last()), (qreal)75);
283 QCOMPARE(m_categoryaxis->endValue(m_categoryaxis->categoriesLabels().last()), (qreal)75);
284 // QCOMPARE(intervalMax("first"), (qreal)75);
284 // QCOMPARE(intervalMax("first"), (qreal)75);
285
285
286 // append one more correct interval
286 // append one more correct interval
287 m_categoryaxis->append("third", (qreal)100);
287 m_categoryaxis->append("third", (qreal)100);
288 QCOMPARE(m_categoryaxis->count(), 3);
288 QCOMPARE(m_categoryaxis->count(), 3);
289 QCOMPARE(m_categoryaxis->startValue("third"), (qreal)75);
289 QCOMPARE(m_categoryaxis->startValue("third"), (qreal)75);
290 QCOMPARE(m_categoryaxis->endValue("third"), (qreal)100);
290 QCOMPARE(m_categoryaxis->endValue("third"), (qreal)100);
291
291
292 // remove one interval
292 // remove one interval
293 m_categoryaxis->remove("first");
293 m_categoryaxis->remove("first");
294 QCOMPARE(m_categoryaxis->count(), 2);
294 QCOMPARE(m_categoryaxis->count(), 2);
295 QCOMPARE(m_categoryaxis->startValue("second"), (qreal)0); // second interval should extend to firstInterval minimum
295 QCOMPARE(m_categoryaxis->startValue("second"), (qreal)0); // second interval should extend to firstInterval minimum
296 QCOMPARE(m_categoryaxis->endValue("second"), (qreal)75);
296 QCOMPARE(m_categoryaxis->endValue("second"), (qreal)75);
297
297
298 // remove one interval
298 // remove one interval
299 m_categoryaxis->replaceLabel("second", "replaced");
299 m_categoryaxis->replaceLabel("second", "replaced");
300 QCOMPARE(m_categoryaxis->count(), 2);
300 QCOMPARE(m_categoryaxis->count(), 2);
301 QCOMPARE(m_categoryaxis->startValue("replaced"), (qreal)0); // second interval should extend to firstInterval minimum
301 QCOMPARE(m_categoryaxis->startValue("replaced"), (qreal)0); // second interval should extend to firstInterval minimum
302 QCOMPARE(m_categoryaxis->endValue("replaced"), (qreal)75);
302 QCOMPARE(m_categoryaxis->endValue("replaced"), (qreal)75);
303 }
303 }
304
304
305 QTEST_MAIN(tst_QCategoryAxis)
305 QTEST_MAIN(tst_QCategoryAxis)
306 #include "tst_qcategoryaxis.moc"
306 #include "tst_qcategoryaxis.moc"
307
307
@@ -1,415 +1,415
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/tst_qabstractaxis.h"
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include "qvalueaxis.h"
22 #include "qvalueaxis.h"
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24
24
25 class tst_QValueAxis: public tst_QAbstractAxis
25 class tst_QValueAxis: public tst_QAbstractAxis
26 {
26 {
27 Q_OBJECT
27 Q_OBJECT
28
28
29 public slots:
29 public slots:
30 void initTestCase();
30 void initTestCase();
31 void cleanupTestCase();
31 void cleanupTestCase();
32 void init();
32 void init();
33 void cleanup();
33 void cleanup();
34
34
35 private slots:
35 private slots:
36 void qvalueaxis_data();
36 void qvalueaxis_data();
37 void qvalueaxis();
37 void qvalueaxis();
38 void max_raw_data();
38 void max_raw_data();
39 void max_raw();
39 void max_raw();
40 void max_data();
40 void max_data();
41 void max();
41 void max();
42 void max_animation_data();
42 void max_animation_data();
43 void max_animation();
43 void max_animation();
44 void min_raw_data();
44 void min_raw_data();
45 void min_raw();
45 void min_raw();
46 void min_data();
46 void min_data();
47 void min();
47 void min();
48 void min_animation_data();
48 void min_animation_data();
49 void min_animation();
49 void min_animation();
50 void niceNumbersEnabled_data();
50 void niceNumbersEnabled_data();
51 void niceNumbersEnabled();
51 void niceNumbersEnabled();
52 void range_raw_data();
52 void range_raw_data();
53 void range_raw();
53 void range_raw();
54 void range_data();
54 void range_data();
55 void range();
55 void range();
56 void range_animation_data();
56 void range_animation_data();
57 void range_animation();
57 void range_animation();
58 void ticksCount_data();
58 void ticksCount_data();
59 void ticksCount();
59 void ticksCount();
60 void noautoscale_data();
60 void noautoscale_data();
61 void noautoscale();
61 void noautoscale();
62 void autoscale_data();
62 void autoscale_data();
63 void autoscale();
63 void autoscale();
64
64
65 private:
65 private:
66 QValueAxis* m_valuesaxis;
66 QValueAxis* m_valuesaxis;
67 QLineSeries* m_series;
67 QLineSeries* m_series;
68 };
68 };
69
69
70 void tst_QValueAxis::initTestCase()
70 void tst_QValueAxis::initTestCase()
71 {
71 {
72 }
72 }
73
73
74 void tst_QValueAxis::cleanupTestCase()
74 void tst_QValueAxis::cleanupTestCase()
75 {
75 {
76 }
76 }
77
77
78 void tst_QValueAxis::init()
78 void tst_QValueAxis::init()
79 {
79 {
80 m_valuesaxis = new QValueAxis();
80 m_valuesaxis = new QValueAxis();
81 m_series = new QLineSeries();
81 m_series = new QLineSeries();
82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
84 m_chart->addSeries(m_series);
84 m_chart->addSeries(m_series);
85 m_chart->createDefaultAxes();
85 m_chart->createDefaultAxes();
86 }
86 }
87
87
88 void tst_QValueAxis::cleanup()
88 void tst_QValueAxis::cleanup()
89 {
89 {
90 delete m_series;
90 delete m_series;
91 delete m_valuesaxis;
91 delete m_valuesaxis;
92 m_series = 0;
92 m_series = 0;
93 m_valuesaxis = 0;
93 m_valuesaxis = 0;
94 tst_QAbstractAxis::cleanup();
94 tst_QAbstractAxis::cleanup();
95 }
95 }
96
96
97 void tst_QValueAxis::qvalueaxis_data()
97 void tst_QValueAxis::qvalueaxis_data()
98 {
98 {
99 }
99 }
100
100
101 void tst_QValueAxis::qvalueaxis()
101 void tst_QValueAxis::qvalueaxis()
102 {
102 {
103 qabstractaxis();
103 qabstractaxis();
104
104
105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
105 QVERIFY(qFuzzyCompare(m_valuesaxis->max(), 0));
106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
106 QVERIFY(qFuzzyCompare(m_valuesaxis->min(), 0));
107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
108 QCOMPARE(m_valuesaxis->tickCount(), 5);
108 QCOMPARE(m_valuesaxis->tickCount(), 5);
109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValue);
109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValue);
110
110
111 m_chart->setAxisX(m_valuesaxis, m_series);
111 m_chart->setAxisX(m_valuesaxis, m_series);
112 m_view->show();
112 m_view->show();
113 QTest::qWaitForWindowShown(m_view);
113 QTest::qWaitForWindowShown(m_view);
114
114
115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
115 QVERIFY(!qFuzzyCompare(m_valuesaxis->max(), 0));
116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
116 QVERIFY(!qFuzzyCompare(m_valuesaxis->min(), 0));
117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
118 QCOMPARE(m_valuesaxis->tickCount(), 5);
118 QCOMPARE(m_valuesaxis->tickCount(), 5);
119 }
119 }
120
120
121 void tst_QValueAxis::max_raw_data()
121 void tst_QValueAxis::max_raw_data()
122 {
122 {
123 QTest::addColumn<qreal>("max");
123 QTest::addColumn<qreal>("max");
124 QTest::newRow("1.0") << (qreal)1.0;
124 QTest::newRow("1.0") << (qreal)1.0;
125 QTest::newRow("50.0") << (qreal)50.0;
125 QTest::newRow("50.0") << (qreal)50.0;
126 QTest::newRow("101.0") << (qreal)101.0;
126 QTest::newRow("101.0") << (qreal)101.0;
127 }
127 }
128
128
129 void tst_QValueAxis::max_raw()
129 void tst_QValueAxis::max_raw()
130 {
130 {
131 QFETCH(qreal, max);
131 QFETCH(qreal, max);
132
132
133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
136
136
137 m_valuesaxis->setMax(max);
137 m_valuesaxis->setMax(max);
138 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
138 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), max), "Not equal");
139
139
140 QCOMPARE(spy0.count(), 1);
140 QCOMPARE(spy0.count(), 1);
141 QCOMPARE(spy1.count(), 0);
141 QCOMPARE(spy1.count(), 0);
142 QCOMPARE(spy2.count(), 1);
142 QCOMPARE(spy2.count(), 1);
143
143
144 }
144 }
145
145
146 void tst_QValueAxis::max_data()
146 void tst_QValueAxis::max_data()
147 {
147 {
148 max_raw_data();
148 max_raw_data();
149 }
149 }
150
150
151 void tst_QValueAxis::max()
151 void tst_QValueAxis::max()
152 {
152 {
153 m_chart->setAxisX(m_valuesaxis, m_series);
153 m_chart->setAxisX(m_valuesaxis, m_series);
154 m_view->show();
154 m_view->show();
155 QTest::qWaitForWindowShown(m_view);
155 QTest::qWaitForWindowShown(m_view);
156 max_raw();
156 max_raw();
157 }
157 }
158
158
159 void tst_QValueAxis::max_animation_data()
159 void tst_QValueAxis::max_animation_data()
160 {
160 {
161 max_data();
161 max_data();
162 }
162 }
163
163
164 void tst_QValueAxis::max_animation()
164 void tst_QValueAxis::max_animation()
165 {
165 {
166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
167 max();
167 max();
168 }
168 }
169
169
170 void tst_QValueAxis::min_raw_data()
170 void tst_QValueAxis::min_raw_data()
171 {
171 {
172 QTest::addColumn<qreal>("min");
172 QTest::addColumn<qreal>("min");
173 QTest::newRow("-1.0") << (qreal)-1.0;
173 QTest::newRow("-1.0") << (qreal)-1.0;
174 QTest::newRow("-50.0") << (qreal)-50.0;
174 QTest::newRow("-50.0") << (qreal)-50.0;
175 QTest::newRow("-101.0") << (qreal)-101.0;
175 QTest::newRow("-101.0") << (qreal)-101.0;
176 }
176 }
177
177
178 void tst_QValueAxis::min_raw()
178 void tst_QValueAxis::min_raw()
179 {
179 {
180 QFETCH(qreal, min);
180 QFETCH(qreal, min);
181
181
182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
185
185
186 m_valuesaxis->setMin(min);
186 m_valuesaxis->setMin(min);
187 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
187 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), min), "Not equal");
188
188
189 QCOMPARE(spy0.count(), 0);
189 QCOMPARE(spy0.count(), 0);
190 QCOMPARE(spy1.count(), 1);
190 QCOMPARE(spy1.count(), 1);
191 QCOMPARE(spy2.count(), 1);
191 QCOMPARE(spy2.count(), 1);
192 }
192 }
193
193
194 void tst_QValueAxis::min_data()
194 void tst_QValueAxis::min_data()
195 {
195 {
196 min_raw_data();
196 min_raw_data();
197 }
197 }
198
198
199 void tst_QValueAxis::min()
199 void tst_QValueAxis::min()
200 {
200 {
201 m_chart->setAxisX(m_valuesaxis, m_series);
201 m_chart->setAxisX(m_valuesaxis, m_series);
202 m_view->show();
202 m_view->show();
203 QTest::qWaitForWindowShown(m_view);
203 QTest::qWaitForWindowShown(m_view);
204 min_raw();
204 min_raw();
205 }
205 }
206
206
207 void tst_QValueAxis::min_animation_data()
207 void tst_QValueAxis::min_animation_data()
208 {
208 {
209 min_data();
209 min_data();
210 }
210 }
211
211
212 void tst_QValueAxis::min_animation()
212 void tst_QValueAxis::min_animation()
213 {
213 {
214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
215 min();
215 min();
216 }
216 }
217
217
218 void tst_QValueAxis::niceNumbersEnabled_data()
218 void tst_QValueAxis::niceNumbersEnabled_data()
219 {
219 {
220 QTest::addColumn<bool>("niceNumbersEnabled");
220 QTest::addColumn<bool>("niceNumbersEnabled");
221 QTest::addColumn<qreal>("min");
221 QTest::addColumn<qreal>("min");
222 QTest::addColumn<qreal>("max");
222 QTest::addColumn<qreal>("max");
223 QTest::addColumn<int>("ticks");
223 QTest::addColumn<int>("ticks");
224 QTest::addColumn<qreal>("expectedMin");
224 QTest::addColumn<qreal>("expectedMin");
225 QTest::addColumn<qreal>("expectedMax");
225 QTest::addColumn<qreal>("expectedMax");
226 QTest::addColumn<int>("expectedTicks");
226 QTest::addColumn<int>("expectedTicks");
227 QTest::newRow("true 0.1 , 99.0 , 5") << true << (qreal)0.1 << (qreal)99.0 << 5 << (qreal)0.0 << (qreal)100.0 << 6;
227 QTest::newRow("true 0.1 , 99.0 , 5") << true << (qreal)0.1 << (qreal)99.0 << 5 << (qreal)0.0 << (qreal)100.0 << 6;
228 QTest::newRow("true 1 , 10.0 , 5") << true << (qreal)1.0 << (qreal)10.0 << 5 << (qreal)0.0 << (qreal)10.0 << 6;
228 QTest::newRow("true 1 , 10.0 , 5") << true << (qreal)1.0 << (qreal)10.0 << 5 << (qreal)0.0 << (qreal)10.0 << 6;
229 QTest::newRow("true 0.1 , 6.6 , 5") << true << (qreal)0.1 << (qreal)6.6 << 5 << (qreal)0.0 << (qreal)8.0 << 5;
229 QTest::newRow("true 0.1 , 6.6 , 5") << true << (qreal)0.1 << (qreal)6.6 << 5 << (qreal)0.0 << (qreal)8.0 << 5;
230 QTest::newRow("false 0.1 , 6.6 , 5") << false << (qreal)0.1 << (qreal)6.6 << 5 << (qreal)0.1 << (qreal)6.6 << 5;
230 QTest::newRow("false 0.1 , 6.6 , 5") << false << (qreal)0.1 << (qreal)6.6 << 5 << (qreal)0.1 << (qreal)6.6 << 5;
231 QTest::newRow("true 0.1, 99, 5") << true << (qreal)0.1 << (qreal)99.0 << 5 << (qreal)0.0 << (qreal)100.0 << 6;
231 QTest::newRow("true 0.1, 99, 5") << true << (qreal)0.1 << (qreal)99.0 << 5 << (qreal)0.0 << (qreal)100.0 << 6;
232 QTest::newRow("true 5, 93.5 , 5") << true << (qreal)5.0 << (qreal)93.5 << 5 << (qreal)0.0 << (qreal)100.0 << 6;
232 QTest::newRow("true 5, 93.5 , 5") << true << (qreal)5.0 << (qreal)93.5 << 5 << (qreal)0.0 << (qreal)100.0 << 6;
233 }
233 }
234
234
235 void tst_QValueAxis::niceNumbersEnabled()
235 void tst_QValueAxis::niceNumbersEnabled()
236 {
236 {
237 QFETCH(bool, niceNumbersEnabled);
237 QFETCH(bool, niceNumbersEnabled);
238 QFETCH(qreal, min);
238 QFETCH(qreal, min);
239 QFETCH(qreal, max);
239 QFETCH(qreal, max);
240 QFETCH(int, ticks);
240 QFETCH(int, ticks);
241 QFETCH(qreal, expectedMin);
241 QFETCH(qreal, expectedMin);
242 QFETCH(qreal, expectedMax);
242 QFETCH(qreal, expectedMax);
243 QFETCH(int, expectedTicks);
243 QFETCH(int, expectedTicks);
244
244
245 m_valuesaxis->setRange(min, max);
245 m_valuesaxis->setRange(min, max);
246 m_valuesaxis->setTickCount(ticks);
246 m_valuesaxis->setTickCount(ticks);
247
247
248 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
248 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), min), "Min not equal");
249 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
249 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), max), "Max not equal");
250
250
251 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
251 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
252 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
252 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
253 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
253 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
254
254
255 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
255 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
256 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
256 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
257
257
258 if(!qFuzzyIsNull(expectedMin - min))
258 if(!qFuzzyCompare(expectedMin, min))
259 QCOMPARE(spy1.count(), 1);
259 QCOMPARE(spy1.count(), 1);
260 if(!qFuzzyIsNull(expectedMax - max))
260 if(!qFuzzyCompare(expectedMax, max))
261 QCOMPARE(spy0.count(), 1);
261 QCOMPARE(spy0.count(), 1);
262 if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max)))
262 if((!qFuzzyCompare(expectedMin, min)) || (!qFuzzyCompare(expectedMax, max)))
263 QCOMPARE(spy2.count(), 1);
263 QCOMPARE(spy2.count(), 1);
264
264
265 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
265 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), expectedMin), "Min not equal");
266 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
266 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), expectedMax), "Max not equal");
267 QCOMPARE(m_valuesaxis->tickCount(), expectedTicks);
267 QCOMPARE(m_valuesaxis->tickCount(), expectedTicks);
268
268
269 }
269 }
270
270
271 void tst_QValueAxis::range_raw_data()
271 void tst_QValueAxis::range_raw_data()
272 {
272 {
273 QTest::addColumn<qreal>("min");
273 QTest::addColumn<qreal>("min");
274 QTest::addColumn<qreal>("max");
274 QTest::addColumn<qreal>("max");
275 QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0;
275 QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0;
276 QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0;
276 QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0;
277 QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0;
277 QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0;
278 }
278 }
279
279
280 void tst_QValueAxis::range_raw()
280 void tst_QValueAxis::range_raw()
281 {
281 {
282 QFETCH(qreal, min);
282 QFETCH(qreal, min);
283 QFETCH(qreal, max);
283 QFETCH(qreal, max);
284
284
285 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
285 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
286 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
286 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
287 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
287 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
288
288
289 m_valuesaxis->setRange(min, max);
289 m_valuesaxis->setRange(min, max);
290 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
290 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), min), "Min not equal");
291 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
291 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), max), "Max not equal");
292
292
293 QCOMPARE(spy0.count(), 1);
293 QCOMPARE(spy0.count(), 1);
294 QCOMPARE(spy1.count(), 1);
294 QCOMPARE(spy1.count(), 1);
295 QCOMPARE(spy2.count(), 1);
295 QCOMPARE(spy2.count(), 1);
296 }
296 }
297
297
298 void tst_QValueAxis::range_data()
298 void tst_QValueAxis::range_data()
299 {
299 {
300 range_raw_data();
300 range_raw_data();
301 }
301 }
302
302
303 void tst_QValueAxis::range()
303 void tst_QValueAxis::range()
304 {
304 {
305 m_chart->setAxisX(m_valuesaxis, m_series);
305 m_chart->setAxisX(m_valuesaxis, m_series);
306 m_view->show();
306 m_view->show();
307 QTest::qWaitForWindowShown(m_view);
307 QTest::qWaitForWindowShown(m_view);
308 range_raw();
308 range_raw();
309 }
309 }
310
310
311 void tst_QValueAxis::range_animation_data()
311 void tst_QValueAxis::range_animation_data()
312 {
312 {
313 range_data();
313 range_data();
314 }
314 }
315
315
316 void tst_QValueAxis::range_animation()
316 void tst_QValueAxis::range_animation()
317 {
317 {
318 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
318 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
319 range();
319 range();
320 }
320 }
321
321
322 void tst_QValueAxis::ticksCount_data()
322 void tst_QValueAxis::ticksCount_data()
323 {
323 {
324 QTest::addColumn<int>("ticksCount");
324 QTest::addColumn<int>("ticksCount");
325 QTest::addColumn<int>("expectedCount");
325 QTest::addColumn<int>("expectedCount");
326 QTest::newRow("0") << 2;
326 QTest::newRow("0") << 2;
327 QTest::newRow("1") << 2;
327 QTest::newRow("1") << 2;
328 QTest::newRow("2") << 2;
328 QTest::newRow("2") << 2;
329 QTest::newRow("3") << 3;
329 QTest::newRow("3") << 3;
330 QTest::newRow("-1") << 2;
330 QTest::newRow("-1") << 2;
331 }
331 }
332
332
333 void tst_QValueAxis::ticksCount()
333 void tst_QValueAxis::ticksCount()
334 {
334 {
335 QFETCH(int, ticksCount);
335 QFETCH(int, ticksCount);
336
336
337 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
337 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
338 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
338 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
339 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
339 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
340
340
341 m_valuesaxis->setTickCount(ticksCount);
341 m_valuesaxis->setTickCount(ticksCount);
342 QCOMPARE(m_valuesaxis->tickCount(), ticksCount);
342 QCOMPARE(m_valuesaxis->tickCount(), ticksCount);
343
343
344 QCOMPARE(spy0.count(), 0);
344 QCOMPARE(spy0.count(), 0);
345 QCOMPARE(spy1.count(), 0);
345 QCOMPARE(spy1.count(), 0);
346 QCOMPARE(spy2.count(), 0);
346 QCOMPARE(spy2.count(), 0);
347
347
348 m_chart->setAxisX(m_valuesaxis, m_series);
348 m_chart->setAxisX(m_valuesaxis, m_series);
349 m_view->show();
349 m_view->show();
350 QTest::qWaitForWindowShown(m_view);
350 QTest::qWaitForWindowShown(m_view);
351
351
352 QCOMPARE(m_valuesaxis->tickCount(), ticksCount);
352 QCOMPARE(m_valuesaxis->tickCount(), ticksCount);
353 }
353 }
354
354
355 void tst_QValueAxis::noautoscale_data()
355 void tst_QValueAxis::noautoscale_data()
356 {
356 {
357 QTest::addColumn<qreal>("min");
357 QTest::addColumn<qreal>("min");
358 QTest::addColumn<qreal>("max");
358 QTest::addColumn<qreal>("max");
359 QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0;
359 QTest::newRow("1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0;
360 QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0;
360 QTest::newRow("25.0 - 75.0") << (qreal)25.0 << (qreal)75.0;
361 QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0;
361 QTest::newRow("101.0") << (qreal)40.0 << (qreal)60.0;
362 }
362 }
363
363
364 void tst_QValueAxis::noautoscale()
364 void tst_QValueAxis::noautoscale()
365 {
365 {
366 QFETCH(qreal, min);
366 QFETCH(qreal, min);
367 QFETCH(qreal, max);
367 QFETCH(qreal, max);
368
368
369 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
369 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
370 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
370 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
371 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
371 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
372
372
373 m_valuesaxis->setRange(min, max);
373 m_valuesaxis->setRange(min, max);
374 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
374 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), min), "Min not equal");
375 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
375 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), max), "Max not equal");
376
376
377 QCOMPARE(spy0.count(), 1);
377 QCOMPARE(spy0.count(), 1);
378 QCOMPARE(spy1.count(), 1);
378 QCOMPARE(spy1.count(), 1);
379 QCOMPARE(spy2.count(), 1);
379 QCOMPARE(spy2.count(), 1);
380
380
381 m_chart->setAxisX(m_valuesaxis, m_series);
381 m_chart->setAxisX(m_valuesaxis, m_series);
382 m_view->show();
382 m_view->show();
383 QTest::qWaitForWindowShown(m_view);
383 QTest::qWaitForWindowShown(m_view);
384 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
384 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), min), "Min not equal");
385 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
385 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), max), "Max not equal");
386 }
386 }
387
387
388 void tst_QValueAxis::autoscale_data()
388 void tst_QValueAxis::autoscale_data()
389 {
389 {
390
390
391 }
391 }
392
392
393 void tst_QValueAxis::autoscale()
393 void tst_QValueAxis::autoscale()
394 {
394 {
395 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
395 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
396 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
396 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
397 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
397 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal,qreal)));
398
398
399 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal");
399 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), 0), "Min not equal");
400 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal");
400 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), 0), "Max not equal");
401 m_chart->setAxisX(m_valuesaxis, m_series);
401 m_chart->setAxisX(m_valuesaxis, m_series);
402
402
403 QCOMPARE(spy0.count(), 1);
403 QCOMPARE(spy0.count(), 1);
404 QCOMPARE(spy1.count(), 1);
404 QCOMPARE(spy1.count(), 1);
405 QCOMPARE(spy2.count(), 1);
405 QCOMPARE(spy2.count(), 1);
406
406
407 m_view->show();
407 m_view->show();
408 QTest::qWaitForWindowShown(m_view);
408 QTest::qWaitForWindowShown(m_view);
409 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal");
409 QVERIFY2(qFuzzyCompare(m_valuesaxis->min(), -100), "Min not equal");
410 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal");
410 QVERIFY2(qFuzzyCompare(m_valuesaxis->max(), 100), "Max not equal");
411 }
411 }
412
412
413 QTEST_MAIN(tst_QValueAxis)
413 QTEST_MAIN(tst_QValueAxis)
414 #include "tst_qvalueaxis.moc"
414 #include "tst_qvalueaxis.moc"
415
415
General Comments 0
You need to be logged in to leave comments. Login now