##// END OF EJS Templates
Refactor CategoriesAxis to BarCategoriesAxis part 2 of 2
Michal Klocek -
r1613:da4a379949e0
parent child
Show More
@@ -0,0 +1,299
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #include "qbarcategoriesaxis.h"
22 #include "qbarcategoriesaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
26 #include <QDebug>
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
30 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
31 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
32 {
33 }
34
35 QBarCategoriesAxis::~QBarCategoriesAxis()
36 {
37 }
38
39 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
40 {
41
42 }
43
44 /*!
45 Appends \a categories to axis
46 */
47 void QBarCategoriesAxis::append(const QStringList &categories)
48 {
49 Q_D(QBarCategoriesAxis);
50 if (d->m_categories.isEmpty()) {
51 d->m_categories.append(categories);
52 setRange(categories.first(),categories.last());
53 }else{
54 d->m_categories.append(categories);
55 }
56
57 emit categoriesChanged();
58 }
59
60 /*!
61 Appends \a category to axis
62 */
63 void QBarCategoriesAxis::append(const QString &category)
64 {
65 Q_D(QBarCategoriesAxis);
66 if (d->m_categories.isEmpty()) {
67 d->m_categories.append(category);
68 setRange(category,category);
69 }else{
70 d->m_categories.append(category);
71 }
72 emit categoriesChanged();
73 }
74
75 /*!
76 Removes \a category from axis
77 */
78 void QBarCategoriesAxis::remove(const QString &category)
79 {
80 Q_D(QBarCategoriesAxis);
81 if (d->m_categories.contains(category)) {
82 d->m_categories.removeAt(d->m_categories.indexOf(category));
83 setRange(d->m_categories.first(),d->m_categories.last());
84 emit categoriesChanged();
85 }
86 }
87
88 /*!
89 Inserts \a category to axis at \a index
90 */
91 void QBarCategoriesAxis::insert(int index, const QString &category)
92 {
93 Q_D(QBarCategoriesAxis);
94 if (d->m_categories.isEmpty()) {
95 d->m_categories.insert(index,category);
96 setRange(category,category);
97 }else{
98
99 }
100 emit categoriesChanged();
101 }
102
103 /*!
104 Removes all categories.
105 */
106 void QBarCategoriesAxis::clear()
107 {
108 Q_D(QBarCategoriesAxis);
109 d->m_categories.clear();
110 setRange(QString::null,QString::null);
111 emit categoriesChanged();
112 }
113
114 void QBarCategoriesAxis::setCategories(const QStringList &categories)
115 {
116 Q_D(QBarCategoriesAxis);
117 if(d->m_categories!=categories){
118 d->m_categories = categories;
119 setRange(categories.first(),categories.last());
120 emit categoriesChanged();
121 }
122 }
123
124 QStringList QBarCategoriesAxis::categories()
125 {
126 Q_D(QBarCategoriesAxis);
127 return d->m_categories;
128 }
129
130 /*!
131 Returns number of categories.
132 */
133 int QBarCategoriesAxis::count() const
134 {
135 Q_D(const QBarCategoriesAxis);
136 return d->m_categories.count();
137 }
138
139 /*!
140 Returns category at \a index. Index must be valid.
141 */
142 QString QBarCategoriesAxis::at(int index) const
143 {
144 Q_D(const QBarCategoriesAxis);
145 return d->m_categories.at(index);
146 }
147
148 /*!
149 Sets minimum category to \a min.
150 */
151 void QBarCategoriesAxis::setMin(const QString& min)
152 {
153 Q_D(QBarCategoriesAxis);
154 setRange(min,d->m_maxCategory);
155 }
156
157 /*!
158 Returns minimum category.
159 */
160 QString QBarCategoriesAxis::min() const
161 {
162 Q_D(const QBarCategoriesAxis);
163 return d->m_minCategory;
164 }
165
166 /*!
167 Sets maximum category to \a max.
168 */
169 void QBarCategoriesAxis::setMax(const QString& max)
170 {
171 Q_D(QBarCategoriesAxis);
172 setRange(d->m_minCategory,max);
173 }
174
175 /*!
176 Returns maximum category
177 */
178 QString QBarCategoriesAxis::max() const
179 {
180 Q_D(const QBarCategoriesAxis);
181 return d->m_maxCategory;
182 }
183
184 /*!
185 Sets range from \a minCategory to \a maxCategory
186 */
187 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
188 {
189 Q_D(QBarCategoriesAxis);
190
191 int minIndex = d->m_categories.indexOf(minCategory);
192 if (minIndex == -1) {
193 return;
194 }
195 int maxIndex = d->m_categories.indexOf(maxCategory);
196 if (maxIndex == -1) {
197 return;
198 }
199
200 if (maxIndex <= minIndex) {
201 // max must be greater than min
202 return;
203 }
204
205 bool changed = false;
206 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
207 d->m_minCategory = minCategory;
208 d->m_min = minIndex;
209 emit minChanged(minCategory);
210 changed = true;
211 }
212
213 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
214 d->m_max = maxIndex;
215 d->m_maxCategory = maxCategory;
216 emit maxChanged(maxCategory);
217 changed = true;
218 }
219
220 if ((changed)) {
221 d->emitRange();
222 emit categoriesChanged();
223 }
224 }
225
226 /*!
227 Returns the type of axis.
228 */
229 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
230 {
231 return AxisTypeCategories;
232 }
233
234 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
235
236 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
237 QAbstractAxisPrivate(q)
238 {
239
240 }
241
242 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
243 {
244
245 }
246
247 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
248 {
249 setRange(min,m_maxCategory);
250 }
251
252 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
253 {
254 setRange(m_minCategory,max);
255 }
256
257 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
258 {
259 Q_Q(QBarCategoriesAxis);
260 QString value1 = min.toString();
261 QString value2 = max.toString();
262 q->setRange(value1,value2);
263 }
264
265 int QBarCategoriesAxisPrivate::ticksCount() const
266 {
267 return m_categories.count()+1;
268 }
269
270 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
271 {
272 m_min = min;
273 m_max = max;
274 m_ticksCount = count;
275 }
276
277 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
278 {
279 Q_Q( QBarCategoriesAxis);
280 if(m_orientation == Qt::Vertical){
281 return new ChartCategoriesAxisY(q,presenter);
282 }else{
283 return new ChartCategoriesAxisX(q,presenter);
284 }
285 }
286
287 void QBarCategoriesAxisPrivate::emitRange()
288 {
289 Q_Q( QBarCategoriesAxis);
290 if(!q->signalsBlocked()) {
291 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
292 }
293 }
294
295
296 #include "moc_qbarcategoriesaxis.cpp"
297 #include "moc_qbarcategoriesaxis_p.cpp"
298
299 QTCOMMERCIALCHART_END_NAMESPACE
@@ -0,0 +1,76
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 #ifndef QBARCATEGORIESAXIS_H
22 #define QBARCATEGORIESAXIS_H
23
24 #include "qabstractaxis.h"
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28 class QBarCategoriesAxisPrivate;
29
30 class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : public QAbstractAxis
31 {
32 Q_OBJECT
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
36
37 public:
38 explicit QBarCategoriesAxis(QObject *parent = 0);
39 ~QBarCategoriesAxis();
40
41 protected:
42 QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0);
43
44 public:
45 AxisType type() const;
46 void append(const QStringList &categories);
47 void append(const QString &category);
48 void remove(const QString &category);
49 void insert(int index, const QString &category);
50 void clear();
51 void setCategories(const QStringList &categories);
52 QStringList categories();
53 int count() const;
54 QString at(int index) const;
55
56 //range handling
57 void setMin(const QString& minCategory);
58 QString min() const;
59 void setMax(const QString& maxCategory);
60 QString max() const;
61 void setRange(const QString& minCategory, const QString& maxCategory);
62
63 Q_SIGNALS:
64 void categoriesChanged();
65 void minChanged(const QString &min);
66 void maxChanged(const QString &max);
67 void rangeChanged(const QString &min, const QString &max);
68
69 private:
70 Q_DECLARE_PRIVATE(QBarCategoriesAxis)
71 Q_DISABLE_COPY(QBarCategoriesAxis)
72 };
73
74 QTCOMMERCIALCHART_END_NAMESPACE
75
76 #endif // QCATEGORIESAXIS_H
@@ -0,0 +1,74
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
30 #ifndef QBARCATEGORIESAXIS_P_H
31 #define QBARCATEGORIESAXIS_P_H
32
33 #include "qbarcategoriesaxis.h"
34 #include "qabstractaxis_p.h"
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
38 class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate
39 {
40 Q_OBJECT
41
42 public:
43 QBarCategoriesAxisPrivate(QBarCategoriesAxis *q);
44 ~QBarCategoriesAxisPrivate();
45
46 public:
47 ChartAxis* createGraphics(ChartPresenter* presenter);
48 void emitRange();
49
50 private:
51 //range handling
52 void setMin(const QVariant &min);
53 void setMax(const QVariant &max);
54 void setRange(const QVariant &min, const QVariant &max);
55 int ticksCount() const;
56
57 Q_SIGNALS:
58 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
59
60 public Q_SLOTS:
61 void handleAxisRangeChanged(qreal min, qreal max,int count);
62
63 private:
64 QStringList m_categories;
65 QString m_minCategory;
66 QString m_maxCategory;
67
68 private:
69 Q_DECLARE_PUBLIC(QBarCategoriesAxis)
70 };
71
72 QTCOMMERCIALCHART_END_NAMESPACE
73
74 #endif // QBARCATEGORIESAXIS_P_H
@@ -1,377 +1,377
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 "themewidget.h"
21 #include "themewidget.h"
22
22
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPieSeries>
24 #include <QPieSeries>
25 #include <QPieSlice>
25 #include <QPieSlice>
26 #include <QAbstractBarSeries>
26 #include <QAbstractBarSeries>
27 #include <QPercentBarSeries>
27 #include <QPercentBarSeries>
28 #include <QStackedBarSeries>
28 #include <QStackedBarSeries>
29 #include <QBarSet>
29 #include <QBarSet>
30 #include <QLineSeries>
30 #include <QLineSeries>
31 #include <QSplineSeries>
31 #include <QSplineSeries>
32 #include <QScatterSeries>
32 #include <QScatterSeries>
33 #include <QAreaSeries>
33 #include <QAreaSeries>
34 #include <QLegend>
34 #include <QLegend>
35 #include <QGridLayout>
35 #include <QGridLayout>
36 #include <QFormLayout>
36 #include <QFormLayout>
37 #include <QComboBox>
37 #include <QComboBox>
38 #include <QSpinBox>
38 #include <QSpinBox>
39 #include <QCheckBox>
39 #include <QCheckBox>
40 #include <QGroupBox>
40 #include <QGroupBox>
41 #include <QLabel>
41 #include <QLabel>
42 #include <QTime>
42 #include <QTime>
43 #include <QCategoriesAxis>
43 #include <QBarCategoriesAxis>
44
44
45 ThemeWidget::ThemeWidget(QWidget* parent) :
45 ThemeWidget::ThemeWidget(QWidget* parent) :
46 QWidget(parent),
46 QWidget(parent),
47 m_listCount(3),
47 m_listCount(3),
48 m_valueMax(10),
48 m_valueMax(10),
49 m_valueCount(7),
49 m_valueCount(7),
50 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
50 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
51 m_themeComboBox(createThemeBox()),
51 m_themeComboBox(createThemeBox()),
52 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
52 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
53 m_animatedComboBox(createAnimationBox()),
53 m_animatedComboBox(createAnimationBox()),
54 m_legendComboBox(createLegendBox())
54 m_legendComboBox(createLegendBox())
55 {
55 {
56 connectSignals();
56 connectSignals();
57 // create layout
57 // create layout
58 QGridLayout* baseLayout = new QGridLayout();
58 QGridLayout* baseLayout = new QGridLayout();
59 QHBoxLayout *settingsLayout = new QHBoxLayout();
59 QHBoxLayout *settingsLayout = new QHBoxLayout();
60 settingsLayout->addWidget(new QLabel("Theme:"));
60 settingsLayout->addWidget(new QLabel("Theme:"));
61 settingsLayout->addWidget(m_themeComboBox);
61 settingsLayout->addWidget(m_themeComboBox);
62 settingsLayout->addWidget(new QLabel("Animation:"));
62 settingsLayout->addWidget(new QLabel("Animation:"));
63 settingsLayout->addWidget(m_animatedComboBox);
63 settingsLayout->addWidget(m_animatedComboBox);
64 settingsLayout->addWidget(new QLabel("Legend:"));
64 settingsLayout->addWidget(new QLabel("Legend:"));
65 settingsLayout->addWidget(m_legendComboBox);
65 settingsLayout->addWidget(m_legendComboBox);
66 settingsLayout->addWidget(m_antialiasCheckBox);
66 settingsLayout->addWidget(m_antialiasCheckBox);
67 settingsLayout->addStretch();
67 settingsLayout->addStretch();
68 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
68 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
69
69
70 //create charts
70 //create charts
71
71
72 QChartView *chartView;
72 QChartView *chartView;
73
73
74 chartView = new QChartView(createAreaChart());
74 chartView = new QChartView(createAreaChart());
75 baseLayout->addWidget(chartView, 1, 0);
75 baseLayout->addWidget(chartView, 1, 0);
76 m_charts << chartView;
76 m_charts << chartView;
77
77
78 chartView = new QChartView(createBarChart(m_valueCount));
78 chartView = new QChartView(createBarChart(m_valueCount));
79 baseLayout->addWidget(chartView, 1, 1);
79 baseLayout->addWidget(chartView, 1, 1);
80 m_charts << chartView;
80 m_charts << chartView;
81
81
82 chartView = new QChartView(createLineChart());
82 chartView = new QChartView(createLineChart());
83 baseLayout->addWidget(chartView, 1, 2);
83 baseLayout->addWidget(chartView, 1, 2);
84 m_charts << chartView;
84 m_charts << chartView;
85
85
86 chartView = new QChartView(createPieChart());
86 chartView = new QChartView(createPieChart());
87 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
87 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
88 baseLayout->addWidget(chartView, 2, 0);
88 baseLayout->addWidget(chartView, 2, 0);
89 m_charts << chartView;
89 m_charts << chartView;
90
90
91 chartView = new QChartView(createSplineChart());
91 chartView = new QChartView(createSplineChart());
92 baseLayout->addWidget(chartView, 2, 1);
92 baseLayout->addWidget(chartView, 2, 1);
93 m_charts << chartView;
93 m_charts << chartView;
94
94
95 chartView = new QChartView(createScatterChart());
95 chartView = new QChartView(createScatterChart());
96 baseLayout->addWidget(chartView, 2, 2);
96 baseLayout->addWidget(chartView, 2, 2);
97 m_charts << chartView;
97 m_charts << chartView;
98
98
99 setLayout(baseLayout);
99 setLayout(baseLayout);
100
100
101 // Set defaults
101 // Set defaults
102 m_antialiasCheckBox->setChecked(true);
102 m_antialiasCheckBox->setChecked(true);
103 updateUI();
103 updateUI();
104 }
104 }
105
105
106 ThemeWidget::~ThemeWidget()
106 ThemeWidget::~ThemeWidget()
107 {
107 {
108 }
108 }
109
109
110 void ThemeWidget::connectSignals()
110 void ThemeWidget::connectSignals()
111 {
111 {
112 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
112 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
113 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
113 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
114 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
114 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 }
116 }
117
117
118 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
118 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
119 {
119 {
120 DataTable dataTable;
120 DataTable dataTable;
121
121
122 // set seed for random stuff
122 // set seed for random stuff
123 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
123 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
124
124
125 // generate random data
125 // generate random data
126 for (int i(0); i < listCount; i++) {
126 for (int i(0); i < listCount; i++) {
127 DataList dataList;
127 DataList dataList;
128 qreal yValue(0);
128 qreal yValue(0);
129 for (int j(0); j < valueCount; j++) {
129 for (int j(0); j < valueCount; j++) {
130 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
130 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
131 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
131 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
132 yValue);
132 yValue);
133 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
133 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
134 dataList << Data(value, label);
134 dataList << Data(value, label);
135 }
135 }
136 dataTable << dataList;
136 dataTable << dataList;
137 }
137 }
138
138
139 return dataTable;
139 return dataTable;
140 }
140 }
141
141
142 QComboBox* ThemeWidget::createThemeBox() const
142 QComboBox* ThemeWidget::createThemeBox() const
143 {
143 {
144 // settings layout
144 // settings layout
145 QComboBox* themeComboBox = new QComboBox();
145 QComboBox* themeComboBox = new QComboBox();
146 themeComboBox->addItem("Light", QChart::ChartThemeLight);
146 themeComboBox->addItem("Light", QChart::ChartThemeLight);
147 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
147 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
148 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
148 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
149 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
149 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
150 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
150 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
151 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
151 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
152 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
152 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
153 return themeComboBox;
153 return themeComboBox;
154 }
154 }
155
155
156 QComboBox* ThemeWidget::createAnimationBox() const
156 QComboBox* ThemeWidget::createAnimationBox() const
157 {
157 {
158 // settings layout
158 // settings layout
159 QComboBox* animationComboBox = new QComboBox();
159 QComboBox* animationComboBox = new QComboBox();
160 animationComboBox->addItem("No Animations", QChart::NoAnimation);
160 animationComboBox->addItem("No Animations", QChart::NoAnimation);
161 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
161 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
162 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
162 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
163 animationComboBox->addItem("All Animations", QChart::AllAnimations);
163 animationComboBox->addItem("All Animations", QChart::AllAnimations);
164 return animationComboBox;
164 return animationComboBox;
165 }
165 }
166
166
167 QComboBox* ThemeWidget::createLegendBox() const
167 QComboBox* ThemeWidget::createLegendBox() const
168 {
168 {
169 QComboBox* legendComboBox = new QComboBox();
169 QComboBox* legendComboBox = new QComboBox();
170 legendComboBox->addItem("No Legend ", 0);
170 legendComboBox->addItem("No Legend ", 0);
171 legendComboBox->addItem("Legend Top", Qt::AlignTop);
171 legendComboBox->addItem("Legend Top", Qt::AlignTop);
172 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
172 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
173 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
173 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
174 legendComboBox->addItem("Legend Right", Qt::AlignRight);
174 legendComboBox->addItem("Legend Right", Qt::AlignRight);
175 return legendComboBox;
175 return legendComboBox;
176 }
176 }
177
177
178 QChart* ThemeWidget::createAreaChart() const
178 QChart* ThemeWidget::createAreaChart() const
179 {
179 {
180 QChart *chart = new QChart();
180 QChart *chart = new QChart();
181 // chart->axisX()->setNiceNumbersEnabled(true);
181 // chart->axisX()->setNiceNumbersEnabled(true);
182 // chart->axisY()->setNiceNumbersEnabled(true);
182 // chart->axisY()->setNiceNumbersEnabled(true);
183 chart->setTitle("Area chart");
183 chart->setTitle("Area chart");
184
184
185 // The lower series initialized to zero values
185 // The lower series initialized to zero values
186 QLineSeries *lowerSeries = 0;
186 QLineSeries *lowerSeries = 0;
187 QString name("Series ");
187 QString name("Series ");
188 int nameIndex = 0;
188 int nameIndex = 0;
189 for (int i(0); i < m_dataTable.count(); i++) {
189 for (int i(0); i < m_dataTable.count(); i++) {
190 QLineSeries *upperSeries = new QLineSeries(chart);
190 QLineSeries *upperSeries = new QLineSeries(chart);
191 for (int j(0); j < m_dataTable[i].count(); j++) {
191 for (int j(0); j < m_dataTable[i].count(); j++) {
192 Data data = m_dataTable[i].at(j);
192 Data data = m_dataTable[i].at(j);
193 if (lowerSeries){
193 if (lowerSeries){
194 const QList<QPointF>& points = lowerSeries->points();
194 const QList<QPointF>& points = lowerSeries->points();
195 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
195 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
196 }else
196 }else
197 upperSeries->append(QPointF(j, data.first.y()));
197 upperSeries->append(QPointF(j, data.first.y()));
198 }
198 }
199 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
199 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
200 area->setName(name + QString::number(nameIndex));
200 area->setName(name + QString::number(nameIndex));
201 nameIndex++;
201 nameIndex++;
202 chart->addSeries(area);
202 chart->addSeries(area);
203 chart->createDefaultAxes();
203 chart->createDefaultAxes();
204 lowerSeries = upperSeries;
204 lowerSeries = upperSeries;
205 }
205 }
206
206
207 return chart;
207 return chart;
208 }
208 }
209
209
210 QChart* ThemeWidget::createBarChart(int valueCount) const
210 QChart* ThemeWidget::createBarChart(int valueCount) const
211 {
211 {
212 QChart* chart = new QChart();
212 QChart* chart = new QChart();
213 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
213 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
214 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
214 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
215 chart->setTitle("Bar chart");
215 chart->setTitle("Bar chart");
216
216
217 QStackedBarSeries* series = new QStackedBarSeries(chart);
217 QStackedBarSeries* series = new QStackedBarSeries(chart);
218 for (int i(0); i < m_dataTable.count(); i++) {
218 for (int i(0); i < m_dataTable.count(); i++) {
219 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
219 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
220 foreach (Data data, m_dataTable[i])
220 foreach (Data data, m_dataTable[i])
221 *set << data.first.y();
221 *set << data.first.y();
222 series->append(set);
222 series->append(set);
223 }
223 }
224 chart->addSeries(series);
224 chart->addSeries(series);
225 chart->createDefaultAxes();
225 chart->createDefaultAxes();
226
226
227 return chart;
227 return chart;
228 }
228 }
229
229
230 QChart* ThemeWidget::createLineChart() const
230 QChart* ThemeWidget::createLineChart() const
231 {
231 {
232 QChart* chart = new QChart();
232 QChart* chart = new QChart();
233 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
233 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
234 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
234 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
235 chart->setTitle("Line chart");
235 chart->setTitle("Line chart");
236
236
237 QString name("Series ");
237 QString name("Series ");
238 int nameIndex = 0;
238 int nameIndex = 0;
239 foreach (DataList list, m_dataTable) {
239 foreach (DataList list, m_dataTable) {
240 QLineSeries *series = new QLineSeries(chart);
240 QLineSeries *series = new QLineSeries(chart);
241 foreach (Data data, list)
241 foreach (Data data, list)
242 series->append(data.first);
242 series->append(data.first);
243 series->setName(name + QString::number(nameIndex));
243 series->setName(name + QString::number(nameIndex));
244 nameIndex++;
244 nameIndex++;
245 chart->addSeries(series);
245 chart->addSeries(series);
246 }
246 }
247 chart->createDefaultAxes();
247 chart->createDefaultAxes();
248
248
249 return chart;
249 return chart;
250 }
250 }
251
251
252 QChart* ThemeWidget::createPieChart() const
252 QChart* ThemeWidget::createPieChart() const
253 {
253 {
254 QChart* chart = new QChart();
254 QChart* chart = new QChart();
255 chart->setTitle("Pie chart");
255 chart->setTitle("Pie chart");
256
256
257 qreal pieSize = 1.0 / m_dataTable.count();
257 qreal pieSize = 1.0 / m_dataTable.count();
258 for (int i = 0; i < m_dataTable.count(); i++) {
258 for (int i = 0; i < m_dataTable.count(); i++) {
259 QPieSeries *series = new QPieSeries(chart);
259 QPieSeries *series = new QPieSeries(chart);
260 foreach (Data data, m_dataTable[i]) {
260 foreach (Data data, m_dataTable[i]) {
261 QPieSlice *slice = series->append(data.second, data.first.y());
261 QPieSlice *slice = series->append(data.second, data.first.y());
262 if (data == m_dataTable[i].first()) {
262 if (data == m_dataTable[i].first()) {
263 slice->setLabelVisible();
263 slice->setLabelVisible();
264 slice->setExploded();
264 slice->setExploded();
265 }
265 }
266 }
266 }
267 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
267 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
268 series->setPieSize(pieSize);
268 series->setPieSize(pieSize);
269 series->setHorizontalPosition(hPos);
269 series->setHorizontalPosition(hPos);
270 series->setVerticalPosition(0.5);
270 series->setVerticalPosition(0.5);
271 chart->addSeries(series);
271 chart->addSeries(series);
272 }
272 }
273
273
274 return chart;
274 return chart;
275 }
275 }
276
276
277 QChart* ThemeWidget::createSplineChart() const
277 QChart* ThemeWidget::createSplineChart() const
278 { // spine chart
278 { // spine chart
279 QChart* chart = new QChart();
279 QChart* chart = new QChart();
280 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
280 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
281 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
281 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
282 chart->setTitle("Spline chart");
282 chart->setTitle("Spline chart");
283 QString name("Series ");
283 QString name("Series ");
284 int nameIndex = 0;
284 int nameIndex = 0;
285 foreach (DataList list, m_dataTable) {
285 foreach (DataList list, m_dataTable) {
286 QSplineSeries *series = new QSplineSeries(chart);
286 QSplineSeries *series = new QSplineSeries(chart);
287 foreach (Data data, list)
287 foreach (Data data, list)
288 series->append(data.first);
288 series->append(data.first);
289 series->setName(name + QString::number(nameIndex));
289 series->setName(name + QString::number(nameIndex));
290 nameIndex++;
290 nameIndex++;
291 chart->addSeries(series);
291 chart->addSeries(series);
292 }
292 }
293 chart->createDefaultAxes();
293 chart->createDefaultAxes();
294 return chart;
294 return chart;
295 }
295 }
296
296
297 QChart* ThemeWidget::createScatterChart() const
297 QChart* ThemeWidget::createScatterChart() const
298 { // scatter chart
298 { // scatter chart
299 QChart* chart = new QChart();
299 QChart* chart = new QChart();
300 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
300 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
301 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
301 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
302 chart->setTitle("Scatter chart");
302 chart->setTitle("Scatter chart");
303 QString name("Series ");
303 QString name("Series ");
304 int nameIndex = 0;
304 int nameIndex = 0;
305 foreach (DataList list, m_dataTable) {
305 foreach (DataList list, m_dataTable) {
306 QScatterSeries *series = new QScatterSeries(chart);
306 QScatterSeries *series = new QScatterSeries(chart);
307 foreach (Data data, list)
307 foreach (Data data, list)
308 series->append(data.first);
308 series->append(data.first);
309 series->setName(name + QString::number(nameIndex));
309 series->setName(name + QString::number(nameIndex));
310 nameIndex++;
310 nameIndex++;
311 chart->addSeries(series);
311 chart->addSeries(series);
312 }
312 }
313 chart->createDefaultAxes();
313 chart->createDefaultAxes();
314 return chart;
314 return chart;
315 }
315 }
316
316
317 void ThemeWidget::updateUI()
317 void ThemeWidget::updateUI()
318 {
318 {
319 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
319 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
320
320
321 if (m_charts.at(0)->chart()->theme() != theme) {
321 if (m_charts.at(0)->chart()->theme() != theme) {
322 foreach (QChartView *chartView, m_charts)
322 foreach (QChartView *chartView, m_charts)
323 chartView->chart()->setTheme(theme);
323 chartView->chart()->setTheme(theme);
324
324
325 QPalette pal = window()->palette();
325 QPalette pal = window()->palette();
326 if (theme == QChart::ChartThemeLight) {
326 if (theme == QChart::ChartThemeLight) {
327 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
327 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
328 pal.setColor(QPalette::WindowText, QRgb(0x404044));
328 pal.setColor(QPalette::WindowText, QRgb(0x404044));
329 } else if (theme == QChart::ChartThemeDark) {
329 } else if (theme == QChart::ChartThemeDark) {
330 pal.setColor(QPalette::Window, QRgb(0x121218));
330 pal.setColor(QPalette::Window, QRgb(0x121218));
331 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
331 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
332 } else if (theme == QChart::ChartThemeBlueCerulean) {
332 } else if (theme == QChart::ChartThemeBlueCerulean) {
333 pal.setColor(QPalette::Window, QRgb(0x40434a));
333 pal.setColor(QPalette::Window, QRgb(0x40434a));
334 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
334 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
335 } else if (theme == QChart::ChartThemeBrownSand) {
335 } else if (theme == QChart::ChartThemeBrownSand) {
336 pal.setColor(QPalette::Window, QRgb(0x9e8965));
336 pal.setColor(QPalette::Window, QRgb(0x9e8965));
337 pal.setColor(QPalette::WindowText, QRgb(0x404044));
337 pal.setColor(QPalette::WindowText, QRgb(0x404044));
338 } else if (theme == QChart::ChartThemeBlueNcs) {
338 } else if (theme == QChart::ChartThemeBlueNcs) {
339 pal.setColor(QPalette::Window, QRgb(0x018bba));
339 pal.setColor(QPalette::Window, QRgb(0x018bba));
340 pal.setColor(QPalette::WindowText, QRgb(0x404044));
340 pal.setColor(QPalette::WindowText, QRgb(0x404044));
341 } else if (theme == QChart::ChartThemeHighContrast) {
341 } else if (theme == QChart::ChartThemeHighContrast) {
342 pal.setColor(QPalette::Window, QRgb(0xffab03));
342 pal.setColor(QPalette::Window, QRgb(0xffab03));
343 pal.setColor(QPalette::WindowText, QRgb(0x181818));
343 pal.setColor(QPalette::WindowText, QRgb(0x181818));
344 } else if (theme == QChart::ChartThemeBlueIcy) {
344 } else if (theme == QChart::ChartThemeBlueIcy) {
345 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
345 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
346 pal.setColor(QPalette::WindowText, QRgb(0x404044));
346 pal.setColor(QPalette::WindowText, QRgb(0x404044));
347 } else {
347 } else {
348 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
348 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
349 pal.setColor(QPalette::WindowText, QRgb(0x404044));
349 pal.setColor(QPalette::WindowText, QRgb(0x404044));
350 }
350 }
351 window()->setPalette(pal);
351 window()->setPalette(pal);
352 }
352 }
353
353
354 bool checked = m_antialiasCheckBox->isChecked();
354 bool checked = m_antialiasCheckBox->isChecked();
355 foreach (QChartView *chart, m_charts)
355 foreach (QChartView *chart, m_charts)
356 chart->setRenderHint(QPainter::Antialiasing, checked);
356 chart->setRenderHint(QPainter::Antialiasing, checked);
357
357
358 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
358 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
359 if (m_charts.at(0)->chart()->animationOptions() != options) {
359 if (m_charts.at(0)->chart()->animationOptions() != options) {
360 foreach (QChartView *chartView, m_charts)
360 foreach (QChartView *chartView, m_charts)
361 chartView->chart()->setAnimationOptions(options);
361 chartView->chart()->setAnimationOptions(options);
362 }
362 }
363
363
364 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
364 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
365
365
366 if (!alignment) {
366 if (!alignment) {
367 foreach (QChartView *chartView, m_charts) {
367 foreach (QChartView *chartView, m_charts) {
368 chartView->chart()->legend()->hide();
368 chartView->chart()->legend()->hide();
369 }
369 }
370 } else {
370 } else {
371 foreach (QChartView *chartView, m_charts) {
371 foreach (QChartView *chartView, m_charts) {
372 chartView->chart()->legend()->setAlignment(alignment);
372 chartView->chart()->legend()->setAlignment(alignment);
373 chartView->chart()->legend()->show();
373 chartView->chart()->legend()->show();
374 }
374 }
375 }
375 }
376 }
376 }
377
377
@@ -1,92 +1,92
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 <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QBarSeries>
24 #include <QBarSeries>
25 #include <QBarSet>
25 #include <QBarSet>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QCategoriesAxis>
27 #include <QBarCategoriesAxis>
28
28
29 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
30
30
31 int main(int argc, char *argv[])
31 int main(int argc, char *argv[])
32 {
32 {
33 QApplication a(argc, argv);
33 QApplication a(argc, argv);
34
34
35 //![1]
35 //![1]
36 QBarSet *set0 = new QBarSet("Jane");
36 QBarSet *set0 = new QBarSet("Jane");
37 QBarSet *set1 = new QBarSet("John");
37 QBarSet *set1 = new QBarSet("John");
38 QBarSet *set2 = new QBarSet("Axel");
38 QBarSet *set2 = new QBarSet("Axel");
39 QBarSet *set3 = new QBarSet("Mary");
39 QBarSet *set3 = new QBarSet("Mary");
40 QBarSet *set4 = new QBarSet("Samantha");
40 QBarSet *set4 = new QBarSet("Samantha");
41
41
42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 //![1]
47 //![1]
48
48
49 //![2]
49 //![2]
50 QBarSeries* series = new QBarSeries();
50 QBarSeries* series = new QBarSeries();
51 series->append(set0);
51 series->append(set0);
52 series->append(set1);
52 series->append(set1);
53 series->append(set2);
53 series->append(set2);
54 series->append(set3);
54 series->append(set3);
55 series->append(set4);
55 series->append(set4);
56
56
57 //![2]
57 //![2]
58
58
59 //![3]
59 //![3]
60 QChart* chart = new QChart();
60 QChart* chart = new QChart();
61 chart->addSeries(series);
61 chart->addSeries(series);
62 chart->setTitle("Barchart example");
62 chart->setTitle("Barchart example");
63 chart->createDefaultAxes();
63 chart->createDefaultAxes();
64 //![3]
64 //![3]
65
65
66 //![4]
66 //![4]
67 QStringList categories;
67 QStringList categories;
68 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
69 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
69 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
70 axis->append(categories);
70 axis->append(categories);
71 chart->setAxisX(axis,series);
71 chart->setAxisX(axis,series);
72 //![4]
72 //![4]
73
73
74 //![5]
74 //![5]
75 chart->legend()->setVisible(true);
75 chart->legend()->setVisible(true);
76 chart->legend()->setAlignment(Qt::AlignBottom);
76 chart->legend()->setAlignment(Qt::AlignBottom);
77 //![5]
77 //![5]
78
78
79 //![6]
79 //![6]
80 QChartView* chartView = new QChartView(chart);
80 QChartView* chartView = new QChartView(chart);
81 chartView->setRenderHint(QPainter::Antialiasing);
81 chartView->setRenderHint(QPainter::Antialiasing);
82 //![6]
82 //![6]
83
83
84 //![7]
84 //![7]
85 QMainWindow window;
85 QMainWindow window;
86 window.setCentralWidget(chartView);
86 window.setCentralWidget(chartView);
87 window.resize(400, 300);
87 window.resize(400, 300);
88 window.show();
88 window.show();
89 //![7]
89 //![7]
90
90
91 return a.exec();
91 return a.exec();
92 }
92 }
@@ -1,112 +1,112
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 "tablewidget.h"
21 #include "tablewidget.h"
22 #include "customtablemodel.h"
22 #include "customtablemodel.h"
23 #include <QGridLayout>
23 #include <QGridLayout>
24 #include <QTableView>
24 #include <QTableView>
25 #include <QChart>
25 #include <QChart>
26 #include <QChartView>
26 #include <QChartView>
27 #include <QLineSeries>
27 #include <QLineSeries>
28 #include <QVXYModelMapper>
28 #include <QVXYModelMapper>
29 #include <QBarSeries>
29 #include <QBarSeries>
30 #include <QBarSet>
30 #include <QBarSet>
31 #include <QVBarModelMapper>
31 #include <QVBarModelMapper>
32 #include <QHeaderView>
32 #include <QHeaderView>
33 #include <QCategoriesAxis>
33 #include <QBarCategoriesAxis>
34
34
35 QTCOMMERCIALCHART_USE_NAMESPACE
35 QTCOMMERCIALCHART_USE_NAMESPACE
36
36
37 TableWidget::TableWidget(QWidget *parent)
37 TableWidget::TableWidget(QWidget *parent)
38 : QWidget(parent)
38 : QWidget(parent)
39 {
39 {
40 // create simple model for storing data
40 // create simple model for storing data
41 // user's table data model
41 // user's table data model
42 //! [1]
42 //! [1]
43 CustomTableModel *model = new CustomTableModel;
43 CustomTableModel *model = new CustomTableModel;
44 //! [1]
44 //! [1]
45
45
46 //! [2]
46 //! [2]
47 // create table view and add model to it
47 // create table view and add model to it
48 QTableView *tableView = new QTableView;
48 QTableView *tableView = new QTableView;
49 tableView->setModel(model);
49 tableView->setModel(model);
50 tableView->setMinimumWidth(300);
50 tableView->setMinimumWidth(300);
51 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
51 tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
52 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
52 tableView->verticalHeader()->setResizeMode(QHeaderView::Stretch);
53 //! [2]
53 //! [2]
54
54
55 //! [3]
55 //! [3]
56 QChart *chart = new QChart;
56 QChart *chart = new QChart;
57 chart->setAnimationOptions(QChart::AllAnimations);
57 chart->setAnimationOptions(QChart::AllAnimations);
58 //! [3]
58 //! [3]
59
59
60 // series 1
60 // series 1
61 //! [4]
61 //! [4]
62 QBarSeries *series = new QBarSeries;
62 QBarSeries *series = new QBarSeries;
63
63
64 int first = 3;
64 int first = 3;
65 int count = 5;
65 int count = 5;
66 QVBarModelMapper *mapper = new QVBarModelMapper(this);
66 QVBarModelMapper *mapper = new QVBarModelMapper(this);
67 mapper->setFirstBarSetColumn(1);
67 mapper->setFirstBarSetColumn(1);
68 mapper->setLastBarSetColumn(4);
68 mapper->setLastBarSetColumn(4);
69 mapper->setFirstRow(first);
69 mapper->setFirstRow(first);
70 mapper->setRowCount(count);
70 mapper->setRowCount(count);
71 mapper->setSeries(series);
71 mapper->setSeries(series);
72 mapper->setModel(model);
72 mapper->setModel(model);
73 chart->addSeries(series);
73 chart->addSeries(series);
74 //! [4]
74 //! [4]
75
75
76 //! [5]
76 //! [5]
77 // for storing color hex from the series
77 // for storing color hex from the series
78 QString seriesColorHex = "#000000";
78 QString seriesColorHex = "#000000";
79
79
80 // get the color of the series and use it for showing the mapped area
80 // get the color of the series and use it for showing the mapped area
81 QList<QBarSet*> barsets = series->barSets();
81 QList<QBarSet*> barsets = series->barSets();
82 for (int i = 0; i < barsets.count(); i++) {
82 for (int i = 0; i < barsets.count(); i++) {
83 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
83 seriesColorHex = "#" + QString::number(barsets.at(i)->brush().color().rgb(), 16).right(6).toUpper();
84 model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count()));
84 model->addMapping(seriesColorHex, QRect(1 + i, first, 1, barsets.at(i)->count()));
85 }
85 }
86 //! [5]
86 //! [5]
87
87
88 //! [6]
88 //! [6]
89 QStringList categories;
89 QStringList categories;
90 categories << "April" << "May" << "June" << "July" << "August";
90 categories << "April" << "May" << "June" << "July" << "August";
91 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
91 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
92 axis->append(categories);
92 axis->append(categories);
93 chart->createDefaultAxes();
93 chart->createDefaultAxes();
94 chart->setAxisX(axis, series);
94 chart->setAxisX(axis, series);
95 //! [6]
95 //! [6]
96
96
97 //! [7]
97 //! [7]
98 QChartView *chartView = new QChartView(chart);
98 QChartView *chartView = new QChartView(chart);
99 chartView->setRenderHint(QPainter::Antialiasing);
99 chartView->setRenderHint(QPainter::Antialiasing);
100 chartView->setMinimumSize(640, 480);
100 chartView->setMinimumSize(640, 480);
101 //! [7]
101 //! [7]
102
102
103 //! [8]
103 //! [8]
104 // create main layout
104 // create main layout
105 QGridLayout* mainLayout = new QGridLayout;
105 QGridLayout* mainLayout = new QGridLayout;
106 mainLayout->addWidget(tableView, 1, 0);
106 mainLayout->addWidget(tableView, 1, 0);
107 mainLayout->addWidget(chartView, 1, 1);
107 mainLayout->addWidget(chartView, 1, 1);
108 mainLayout->setColumnStretch(1, 1);
108 mainLayout->setColumnStretch(1, 1);
109 mainLayout->setColumnStretch(0, 0);
109 mainLayout->setColumnStretch(0, 0);
110 setLayout(mainLayout);
110 setLayout(mainLayout);
111 //! [8]
111 //! [8]
112 }
112 }
@@ -1,92 +1,92
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 <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPercentBarSeries>
24 #include <QPercentBarSeries>
25 #include <QBarSet>
25 #include <QBarSet>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QCategoriesAxis>
27 #include <QBarCategoriesAxis>
28
28
29 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
30
30
31 int main(int argc, char *argv[])
31 int main(int argc, char *argv[])
32 {
32 {
33 QApplication a(argc, argv);
33 QApplication a(argc, argv);
34
34
35 //![1]
35 //![1]
36 QBarSet *set0 = new QBarSet("Jane");
36 QBarSet *set0 = new QBarSet("Jane");
37 QBarSet *set1 = new QBarSet("John");
37 QBarSet *set1 = new QBarSet("John");
38 QBarSet *set2 = new QBarSet("Axel");
38 QBarSet *set2 = new QBarSet("Axel");
39 QBarSet *set3 = new QBarSet("Mary");
39 QBarSet *set3 = new QBarSet("Mary");
40 QBarSet *set4 = new QBarSet("Samantha");
40 QBarSet *set4 = new QBarSet("Samantha");
41
41
42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 //![1]
47 //![1]
48
48
49 //![2]
49 //![2]
50 QPercentBarSeries* series = new QPercentBarSeries();
50 QPercentBarSeries* series = new QPercentBarSeries();
51 series->append(set0);
51 series->append(set0);
52 series->append(set1);
52 series->append(set1);
53 series->append(set2);
53 series->append(set2);
54 series->append(set3);
54 series->append(set3);
55 series->append(set4);
55 series->append(set4);
56 //![2]
56 //![2]
57
57
58 //![3]
58 //![3]
59 QChart* chart = new QChart();
59 QChart* chart = new QChart();
60 chart->addSeries(series);
60 chart->addSeries(series);
61 chart->setTitle("Percentbarchart example");
61 chart->setTitle("Percentbarchart example");
62 //![3]
62 //![3]
63
63
64 //![4]
64 //![4]
65 QStringList categories;
65 QStringList categories;
66 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
66 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
67 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
68 axis->append(categories);
68 axis->append(categories);
69 chart->createDefaultAxes();
69 chart->createDefaultAxes();
70 chart->setAxisX(axis,series);
70 chart->setAxisX(axis,series);
71 //![4]
71 //![4]
72
72
73 //![5]
73 //![5]
74 chart->legend()->setVisible(true);
74 chart->legend()->setVisible(true);
75 chart->legend()->setAlignment(Qt::AlignBottom);
75 chart->legend()->setAlignment(Qt::AlignBottom);
76 //![5]
76 //![5]
77
77
78 //![6]
78 //![6]
79 QChartView* chartView = new QChartView(chart);
79 QChartView* chartView = new QChartView(chart);
80 chartView->setRenderHint(QPainter::Antialiasing);
80 chartView->setRenderHint(QPainter::Antialiasing);
81 //![6]
81 //![6]
82
82
83 //![7]
83 //![7]
84 QMainWindow window;
84 QMainWindow window;
85 window.setCentralWidget(chartView);
85 window.setCentralWidget(chartView);
86 window.resize(400, 300);
86 window.resize(400, 300);
87 window.show();
87 window.show();
88 //![7]
88 //![7]
89
89
90 return a.exec();
90 return a.exec();
91 }
91 }
92
92
@@ -1,92 +1,92
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 <QApplication>
21 #include <QApplication>
22 #include <QMainWindow>
22 #include <QMainWindow>
23 #include <QChartView>
23 #include <QChartView>
24 #include <QStackedBarSeries>
24 #include <QStackedBarSeries>
25 #include <QBarSet>
25 #include <QBarSet>
26 #include <QLegend>
26 #include <QLegend>
27 #include <QCategoriesAxis>
27 #include <QBarCategoriesAxis>
28
28
29 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
30
30
31 int main(int argc, char *argv[])
31 int main(int argc, char *argv[])
32 {
32 {
33 QApplication a(argc, argv);
33 QApplication a(argc, argv);
34
34
35 //![1]
35 //![1]
36 QBarSet *set0 = new QBarSet("Jane");
36 QBarSet *set0 = new QBarSet("Jane");
37 QBarSet *set1 = new QBarSet("John");
37 QBarSet *set1 = new QBarSet("John");
38 QBarSet *set2 = new QBarSet("Axel");
38 QBarSet *set2 = new QBarSet("Axel");
39 QBarSet *set3 = new QBarSet("Mary");
39 QBarSet *set3 = new QBarSet("Mary");
40 QBarSet *set4 = new QBarSet("Samantha");
40 QBarSet *set4 = new QBarSet("Samantha");
41
41
42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
42 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
43 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
44 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
45 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
46 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 //![1]
47 //![1]
48
48
49 //![2]
49 //![2]
50 QStackedBarSeries* series = new QStackedBarSeries();
50 QStackedBarSeries* series = new QStackedBarSeries();
51 series->append(set0);
51 series->append(set0);
52 series->append(set1);
52 series->append(set1);
53 series->append(set2);
53 series->append(set2);
54 series->append(set3);
54 series->append(set3);
55 series->append(set4);
55 series->append(set4);
56 //![2]
56 //![2]
57
57
58 //![3]
58 //![3]
59 QChart* chart = new QChart();
59 QChart* chart = new QChart();
60 chart->addSeries(series);
60 chart->addSeries(series);
61 chart->setTitle("Stackedbarchart example");
61 chart->setTitle("Stackedbarchart example");
62 chart->createDefaultAxes();
62 chart->createDefaultAxes();
63 //![3]
63 //![3]
64
64
65 //![4]
65 //![4]
66 QStringList categories;
66 QStringList categories;
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
67 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
68 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
68 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
69 axis->append(categories);
69 axis->append(categories);
70 chart->setAxisX(axis,series);
70 chart->setAxisX(axis,series);
71 //![4]
71 //![4]
72
72
73 //![5]
73 //![5]
74 chart->legend()->setVisible(true);
74 chart->legend()->setVisible(true);
75 chart->legend()->setAlignment(Qt::AlignBottom);
75 chart->legend()->setAlignment(Qt::AlignBottom);
76 //![5]
76 //![5]
77
77
78 //![6]
78 //![6]
79 QChartView* chartView = new QChartView(chart);
79 QChartView* chartView = new QChartView(chart);
80 chartView->setRenderHint(QPainter::Antialiasing);
80 chartView->setRenderHint(QPainter::Antialiasing);
81 //![6]
81 //![6]
82
82
83 //![7]
83 //![7]
84 QMainWindow window;
84 QMainWindow window;
85 window.setCentralWidget(chartView);
85 window.setCentralWidget(chartView);
86 window.resize(400, 300);
86 window.resize(400, 300);
87 window.show();
87 window.show();
88 //![7]
88 //![7]
89
89
90 return a.exec();
90 return a.exec();
91 }
91 }
92
92
@@ -1,59 +1,59
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 "drilldownchart.h"
21 #include "drilldownchart.h"
22 #include <QCategoriesAxis>
22 #include <QBarCategoriesAxis>
23
23
24 QTCOMMERCIALCHART_USE_NAMESPACE
24 QTCOMMERCIALCHART_USE_NAMESPACE
25
25
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
26 DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 : QChart(parent, wFlags)
27 : QChart(parent, wFlags)
28 ,m_currentSeries(0)
28 ,m_currentSeries(0)
29 {
29 {
30 }
30 }
31
31
32 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
32 void DrilldownChart::changeSeries(DrilldownBarSeries *series)
33 {
33 {
34 if (m_currentSeries) {
34 if (m_currentSeries) {
35 removeSeries(m_currentSeries);
35 removeSeries(m_currentSeries);
36 }
36 }
37
37
38 m_currentSeries = series;
38 m_currentSeries = series;
39
39
40 // Reset axis
40 // Reset axis
41 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
41 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
42 axis->append(m_currentSeries->categories());
42 axis->append(m_currentSeries->categories());
43
43
44 addSeries(series);
44 addSeries(series);
45
45
46 createDefaultAxes();
46 createDefaultAxes();
47 setAxisX(axis,series);
47 setAxisX(axis,series);
48
48
49 setTitle(series->name());
49 setTitle(series->name());
50 }
50 }
51
51
52 void DrilldownChart::handleClicked(int index, QBarSet *barset)
52 void DrilldownChart::handleClicked(int index, QBarSet *barset)
53 {
53 {
54 Q_UNUSED(barset)
54 Q_UNUSED(barset)
55 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
55 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
56 changeSeries(series->drilldownSeries(index));
56 changeSeries(series->drilldownSeries(index));
57 }
57 }
58
58
59 #include "moc_drilldownchart.cpp"
59 #include "moc_drilldownchart.cpp"
@@ -1,516 +1,516
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 "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23 #include "declarativelineseries.h"
23 #include "declarativelineseries.h"
24 #include "declarativeareaseries.h"
24 #include "declarativeareaseries.h"
25 #include "declarativebarseries.h"
25 #include "declarativebarseries.h"
26 #include "declarativepieseries.h"
26 #include "declarativepieseries.h"
27 #include "declarativesplineseries.h"
27 #include "declarativesplineseries.h"
28 #include "declarativescatterseries.h"
28 #include "declarativescatterseries.h"
29 #include "qcategoriesaxis.h"
29 #include "qbarcategoriesaxis.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \qmlclass ChartView DeclarativeChart
34 \qmlclass ChartView DeclarativeChart
35
35
36 ChartView element is the parent that is responsible for showing different chart series types.
36 ChartView element is the parent that is responsible for showing different chart series types.
37
37
38 The following QML shows how to create a simple chart with one pie series:
38 The following QML shows how to create a simple chart with one pie series:
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
39 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 1
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
40 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 2
41 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
41 \snippet ../examples/qmlpiechart/qml/qmlpiechart/main.qml 3
42
42
43 \beginfloatleft
43 \beginfloatleft
44 \image examples_qmlpiechart.png
44 \image examples_qmlpiechart.png
45 \endfloat
45 \endfloat
46 \clearfloat
46 \clearfloat
47 */
47 */
48
48
49 /*!
49 /*!
50 \qmlproperty Theme ChartView::theme
50 \qmlproperty Theme ChartView::theme
51 Theme defines the visual appearance of the chart, including for example colors, fonts, line
51 Theme defines the visual appearance of the chart, including for example colors, fonts, line
52 widths and chart background.
52 widths and chart background.
53 */
53 */
54
54
55 /*!
55 /*!
56 \qmlproperty Animation ChartView::animation
56 \qmlproperty Animation ChartView::animation
57 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
57 Animation configuration of the chart. One of ChartView.NoAnimation, ChartView.GridAxisAnimations,
58 ChartView.SeriesAnimations or ChartView.AllAnimations.
58 ChartView.SeriesAnimations or ChartView.AllAnimations.
59 */
59 */
60
60
61 /*!
61 /*!
62 \qmlproperty Font ChartView::titleFont
62 \qmlproperty Font ChartView::titleFont
63 The title font of the chart
63 The title font of the chart
64
64
65 See the \l {Font} {QML Font Element} for detailed documentation.
65 See the \l {Font} {QML Font Element} for detailed documentation.
66 */
66 */
67
67
68 /*!
68 /*!
69 \qmlproperty string ChartView::title
69 \qmlproperty string ChartView::title
70 The title of the chart, shown on top of the chart.
70 The title of the chart, shown on top of the chart.
71 \sa ChartView::titleColor
71 \sa ChartView::titleColor
72 */
72 */
73
73
74 /*!
74 /*!
75 \qmlproperty string ChartView::titleColor
75 \qmlproperty string ChartView::titleColor
76 The color of the title text.
76 The color of the title text.
77 */
77 */
78
78
79 /*!
79 /*!
80 \qmlproperty Axis ChartView::axisX
80 \qmlproperty Axis ChartView::axisX
81 The x-axis of the chart.
81 The x-axis of the chart.
82 */
82 */
83
83
84 /*!
84 /*!
85 \qmlproperty Axis ChartView::axisY
85 \qmlproperty Axis ChartView::axisY
86 The default y-axis of the chart.
86 The default y-axis of the chart.
87 */
87 */
88
88
89 /*!
89 /*!
90 \qmlproperty Legend ChartView::legend
90 \qmlproperty Legend ChartView::legend
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
91 The legend of the chart. Legend lists all the series, pie slices and bar sets added on the chart.
92 */
92 */
93
93
94 /*!
94 /*!
95 \qmlproperty int ChartView::count
95 \qmlproperty int ChartView::count
96 The count of series added to the chart.
96 The count of series added to the chart.
97 */
97 */
98
98
99 /*!
99 /*!
100 \qmlproperty color ChartView::backgroundColor
100 \qmlproperty color ChartView::backgroundColor
101 The color of the chart's background. By default background color is defined by chart theme.
101 The color of the chart's background. By default background color is defined by chart theme.
102 \sa ChartView::theme
102 \sa ChartView::theme
103 */
103 */
104
104
105 /*!
105 /*!
106 \qmlproperty bool ChartView::dropShadowEnabled
106 \qmlproperty bool ChartView::dropShadowEnabled
107 The chart's border drop shadow. Set to true to enable drop shadow.
107 The chart's border drop shadow. Set to true to enable drop shadow.
108 */
108 */
109
109
110 /*!
110 /*!
111 \qmlproperty real ChartView::topMargin
111 \qmlproperty real ChartView::topMargin
112 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
112 The space between the top of chart view and the top of the plot area. The title (if non-empty) is drawn on top margin
113 area of the chart view. Top margin area is also used by legend, if aligned to top.
113 area of the chart view. Top margin area is also used by legend, if aligned to top.
114 */
114 */
115
115
116 /*!
116 /*!
117 \qmlproperty real ChartView::bottomMargin
117 \qmlproperty real ChartView::bottomMargin
118 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
118 The space between the bottom of chart view and the bottom of the plot area. The bottom margin area may be used by
119 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
119 legend (if aligned to bottom), x-axis, x-axis labels and x-axis tick marks.
120 */
120 */
121
121
122 /*!
122 /*!
123 \qmlproperty real ChartView::leftMargin
123 \qmlproperty real ChartView::leftMargin
124 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
124 The space between the left side of chart view and the left side of the plot area. The left margin area may be used by
125 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
125 legend (if aligned to left), y-axis, y-axis labels and y-axis tick marks.
126 */
126 */
127
127
128 /*!
128 /*!
129 \qmlproperty real ChartView::rightMargin
129 \qmlproperty real ChartView::rightMargin
130 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
130 The space between the right side of chart view and the right side of the plot area. The right margin area may be used
131 by legend (if aligned to right).
131 by legend (if aligned to right).
132 */
132 */
133
133
134 /*!
134 /*!
135 \qmlmethod AbstractSeries ChartView::series(int index)
135 \qmlmethod AbstractSeries ChartView::series(int index)
136 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
136 Returns the series with \a index on the chart. This allows you to loop through the series of a chart together with
137 the count property of the chart.
137 the count property of the chart.
138 */
138 */
139
139
140 /*!
140 /*!
141 \qmlmethod AbstractSeries ChartView::series(string name)
141 \qmlmethod AbstractSeries ChartView::series(string name)
142 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
142 Returns the first series on the chart with \a name. If there is no series with that name, returns null.
143 */
143 */
144
144
145 /*!
145 /*!
146 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
146 \qmlmethod AbstractSeries ChartView::createSeries(SeriesType type, string name)
147 Creates a series object of \a type to the chart. For example:
147 Creates a series object of \a type to the chart. For example:
148 \code
148 \code
149 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
149 var scatter = chartView.createSeries(ChartView.SeriesTypeScatter, "scatter series");
150 scatter.markerSize = 22;
150 scatter.markerSize = 22;
151 scatter.append(1.1, 2.0);
151 scatter.append(1.1, 2.0);
152 \endcode
152 \endcode
153 */
153 */
154
154
155 /*!
155 /*!
156 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
156 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
157 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
157 The y-axis of the series. This is the same as the default y-axis of the chart as multiple y-axes are not yet supported.
158 */
158 */
159
159
160 /*!
160 /*!
161 \qmlmethod ChartView::zoomY(real factor)
161 \qmlmethod ChartView::zoomY(real factor)
162 Zooms in by \a factor on the center of the chart.
162 Zooms in by \a factor on the center of the chart.
163 */
163 */
164
164
165 /*!
165 /*!
166 \qmlmethod ChartView::scrollLeft(real pixels)
166 \qmlmethod ChartView::scrollLeft(real pixels)
167 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
167 Scrolls to left by \a pixels. This is a convenience function that suits for example for key navigation.
168 \sa Axis::min, Axis::max
168 \sa Axis::min, Axis::max
169 */
169 */
170
170
171 /*!
171 /*!
172 \qmlmethod ChartView::scrollRight(real pixels)
172 \qmlmethod ChartView::scrollRight(real pixels)
173 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
173 Scrolls to right by \a pixels. This is a convenience function that suits for example for key navigation.
174 \sa Axis::min, Axis::max
174 \sa Axis::min, Axis::max
175 */
175 */
176
176
177 /*!
177 /*!
178 \qmlmethod ChartView::scrollUp(real pixels)
178 \qmlmethod ChartView::scrollUp(real pixels)
179 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
179 Scrolls up by \a pixels. This is a convenience function that suits for example for key navigation.
180 \sa Axis::min, Axis::max
180 \sa Axis::min, Axis::max
181 */
181 */
182
182
183 /*!
183 /*!
184 \qmlmethod ChartView::scrollDown(real pixels)
184 \qmlmethod ChartView::scrollDown(real pixels)
185 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
185 Scrolls down by \a pixels. This is a convenience function that suits for example for key navigation.
186 \sa Axis::min, Axis::max
186 \sa Axis::min, Axis::max
187 */
187 */
188
188
189 /*!
189 /*!
190 \qmlsignal ChartView::onTopMarginChanged(real margin)
190 \qmlsignal ChartView::onTopMarginChanged(real margin)
191 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
191 The top margin of the chart view has changed to \a margin. This may happen for example if you modify font size
192 related properties of the legend or chart title.
192 related properties of the legend or chart title.
193 */
193 */
194
194
195 /*!
195 /*!
196 \qmlsignal ChartView::onBottomMarginChanged(real margin)
196 \qmlsignal ChartView::onBottomMarginChanged(real margin)
197 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
197 The bottom margin of the chart view has changed to \a margin. This may happen for example if you modify font size
198 related properties of the legend or chart title.
198 related properties of the legend or chart title.
199 */
199 */
200
200
201 /*!
201 /*!
202 \qmlsignal ChartView::onLeftMarginChanged(real margin)
202 \qmlsignal ChartView::onLeftMarginChanged(real margin)
203 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
203 The left margin of the chart view has changed to \a margin. This may happen for example if you modify font size
204 related properties of the legend or chart title.
204 related properties of the legend or chart title.
205 */
205 */
206
206
207 /*!
207 /*!
208 \qmlsignal ChartView::onRightMarginChanged(real margin)
208 \qmlsignal ChartView::onRightMarginChanged(real margin)
209 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
209 The right margin of the chart view has changed to \a margin. This may happen for example if you modify font size
210 related properties of the legend or chart title.
210 related properties of the legend or chart title.
211 */
211 */
212
212
213 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
213 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
214 : QDeclarativeItem(parent),
214 : QDeclarativeItem(parent),
215 m_chart(new QChart(this))
215 m_chart(new QChart(this))
216 {
216 {
217 setFlag(QGraphicsItem::ItemHasNoContents, false);
217 setFlag(QGraphicsItem::ItemHasNoContents, false);
218 // m_chart->axisX()->setNiceNumbersEnabled(false);
218 // m_chart->axisX()->setNiceNumbersEnabled(false);
219 m_chartMargins = m_chart->margins();
219 m_chartMargins = m_chart->margins();
220 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
220 connect(m_chart, SIGNAL(marginsChanged(QRectF)), this, SLOT(handleMarginsChanged(QRectF)));
221 }
221 }
222
222
223 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
223 void DeclarativeChart::handleMarginsChanged(QRectF newMargins)
224 {
224 {
225 if (m_chartMargins.top() != newMargins.top())
225 if (m_chartMargins.top() != newMargins.top())
226 topMarginChanged(m_chart->margins().top());
226 topMarginChanged(m_chart->margins().top());
227 if (m_chartMargins.bottom() != newMargins.bottom())
227 if (m_chartMargins.bottom() != newMargins.bottom())
228 bottomMarginChanged(m_chart->margins().bottom());
228 bottomMarginChanged(m_chart->margins().bottom());
229 if (m_chartMargins.left() != newMargins.left())
229 if (m_chartMargins.left() != newMargins.left())
230 leftMarginChanged(m_chart->margins().left());
230 leftMarginChanged(m_chart->margins().left());
231 if (m_chartMargins.right() != newMargins.right())
231 if (m_chartMargins.right() != newMargins.right())
232 rightMarginChanged(m_chart->margins().right());
232 rightMarginChanged(m_chart->margins().right());
233
233
234 m_chartMargins = m_chart->margins();
234 m_chartMargins = m_chart->margins();
235 }
235 }
236
236
237 DeclarativeChart::~DeclarativeChart()
237 DeclarativeChart::~DeclarativeChart()
238 {
238 {
239 delete m_chart;
239 delete m_chart;
240 }
240 }
241
241
242 void DeclarativeChart::childEvent(QChildEvent *event)
242 void DeclarativeChart::childEvent(QChildEvent *event)
243 {
243 {
244 if (event->type() == QEvent::ChildAdded) {
244 if (event->type() == QEvent::ChildAdded) {
245 if (qobject_cast<QAbstractSeries *>(event->child())) {
245 if (qobject_cast<QAbstractSeries *>(event->child())) {
246 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
246 m_chart->addSeries(qobject_cast<QAbstractSeries *>(event->child()));
247 }
247 }
248 }
248 }
249 }
249 }
250
250
251 void DeclarativeChart::componentComplete()
251 void DeclarativeChart::componentComplete()
252 {
252 {
253 foreach(QObject *child, children()) {
253 foreach(QObject *child, children()) {
254 if (qobject_cast<QAbstractSeries *>(child)) {
254 if (qobject_cast<QAbstractSeries *>(child)) {
255 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
255 // qDebug() << "DeclarativeChart::componentComplete(), add: " << child;
256 // TODO: how about optional y-axis?
256 // TODO: how about optional y-axis?
257 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
257 m_chart->addSeries(qobject_cast<QAbstractSeries *>(child));
258 }else if(qobject_cast<QAbstractAxis *>(child)){
258 }else if(qobject_cast<QAbstractAxis *>(child)){
259
259
260 }
260 }
261 }
261 }
262 QDeclarativeItem::componentComplete();
262 QDeclarativeItem::componentComplete();
263 }
263 }
264
264
265 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
265 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
266 {
266 {
267 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
267 // qDebug() << "DeclarativeChart::geometryChanged" << newGeometry.width() << newGeometry.height();
268 if (newGeometry.isValid()) {
268 if (newGeometry.isValid()) {
269 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
269 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
270 m_chart->resize(newGeometry.width(), newGeometry.height());
270 m_chart->resize(newGeometry.width(), newGeometry.height());
271 }
271 }
272 }
272 }
273 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
273 QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
274 }
274 }
275
275
276 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
276 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
277 {
277 {
278 Q_UNUSED(option)
278 Q_UNUSED(option)
279 Q_UNUSED(widget)
279 Q_UNUSED(widget)
280
280
281 // TODO: optimized?
281 // TODO: optimized?
282 painter->setRenderHint(QPainter::Antialiasing, true);
282 painter->setRenderHint(QPainter::Antialiasing, true);
283 }
283 }
284
284
285 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
285 void DeclarativeChart::setTheme(DeclarativeChart::Theme theme)
286 {
286 {
287 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
287 QChart::ChartTheme chartTheme = (QChart::ChartTheme) theme;
288 if (chartTheme != m_chart->theme())
288 if (chartTheme != m_chart->theme())
289 m_chart->setTheme(chartTheme);
289 m_chart->setTheme(chartTheme);
290 }
290 }
291
291
292 DeclarativeChart::Theme DeclarativeChart::theme()
292 DeclarativeChart::Theme DeclarativeChart::theme()
293 {
293 {
294 return (DeclarativeChart::Theme) m_chart->theme();
294 return (DeclarativeChart::Theme) m_chart->theme();
295 }
295 }
296
296
297 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
297 void DeclarativeChart::setAnimationOptions(DeclarativeChart::Animation animations)
298 {
298 {
299 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
299 QChart::AnimationOption animationOptions = (QChart::AnimationOption) animations;
300 if (animationOptions != m_chart->animationOptions())
300 if (animationOptions != m_chart->animationOptions())
301 m_chart->setAnimationOptions(animationOptions);
301 m_chart->setAnimationOptions(animationOptions);
302 }
302 }
303
303
304 DeclarativeChart::Animation DeclarativeChart::animationOptions()
304 DeclarativeChart::Animation DeclarativeChart::animationOptions()
305 {
305 {
306 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
306 if (m_chart->animationOptions().testFlag(QChart::AllAnimations))
307 return DeclarativeChart::AllAnimations;
307 return DeclarativeChart::AllAnimations;
308 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
308 else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations))
309 return DeclarativeChart::GridAxisAnimations;
309 return DeclarativeChart::GridAxisAnimations;
310 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
310 else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations))
311 return DeclarativeChart::SeriesAnimations;
311 return DeclarativeChart::SeriesAnimations;
312 else
312 else
313 return DeclarativeChart::NoAnimation;
313 return DeclarativeChart::NoAnimation;
314 }
314 }
315
315
316 void DeclarativeChart::setTitle(QString title)
316 void DeclarativeChart::setTitle(QString title)
317 {
317 {
318 if (title != m_chart->title())
318 if (title != m_chart->title())
319 m_chart->setTitle(title);
319 m_chart->setTitle(title);
320 }
320 }
321 QString DeclarativeChart::title()
321 QString DeclarativeChart::title()
322 {
322 {
323 return m_chart->title();
323 return m_chart->title();
324 }
324 }
325
325
326 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
326 QAbstractAxis *DeclarativeChart::axisX(QAbstractSeries *series)
327 {
327 {
328 return m_chart->axisX(series);
328 return m_chart->axisX(series);
329 }
329 }
330
330
331 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
331 QAbstractAxis *DeclarativeChart::axisY(QAbstractSeries *series)
332 {
332 {
333 return m_chart->axisY(series);
333 return m_chart->axisY(series);
334 }
334 }
335
335
336 QLegend *DeclarativeChart::legend()
336 QLegend *DeclarativeChart::legend()
337 {
337 {
338 return m_chart->legend();
338 return m_chart->legend();
339 }
339 }
340
340
341 void DeclarativeChart::setTitleColor(QColor color)
341 void DeclarativeChart::setTitleColor(QColor color)
342 {
342 {
343 QBrush b = m_chart->titleBrush();
343 QBrush b = m_chart->titleBrush();
344 if (color != b.color()) {
344 if (color != b.color()) {
345 b.setColor(color);
345 b.setColor(color);
346 m_chart->setTitleBrush(b);
346 m_chart->setTitleBrush(b);
347 emit titleColorChanged(color);
347 emit titleColorChanged(color);
348 }
348 }
349 }
349 }
350
350
351 QFont DeclarativeChart::titleFont() const
351 QFont DeclarativeChart::titleFont() const
352 {
352 {
353 return m_chart->titleFont();
353 return m_chart->titleFont();
354 }
354 }
355
355
356 void DeclarativeChart::setTitleFont(const QFont& font)
356 void DeclarativeChart::setTitleFont(const QFont& font)
357 {
357 {
358 m_chart->setTitleFont(font);
358 m_chart->setTitleFont(font);
359 }
359 }
360
360
361 QColor DeclarativeChart::titleColor()
361 QColor DeclarativeChart::titleColor()
362 {
362 {
363 return m_chart->titleBrush().color();
363 return m_chart->titleBrush().color();
364 }
364 }
365
365
366 void DeclarativeChart::setBackgroundColor(QColor color)
366 void DeclarativeChart::setBackgroundColor(QColor color)
367 {
367 {
368 QBrush b = m_chart->backgroundBrush();
368 QBrush b = m_chart->backgroundBrush();
369 if (b.style() != Qt::SolidPattern || color != b.color()) {
369 if (b.style() != Qt::SolidPattern || color != b.color()) {
370 b.setStyle(Qt::SolidPattern);
370 b.setStyle(Qt::SolidPattern);
371 b.setColor(color);
371 b.setColor(color);
372 m_chart->setBackgroundBrush(b);
372 m_chart->setBackgroundBrush(b);
373 emit backgroundColorChanged();
373 emit backgroundColorChanged();
374 }
374 }
375 }
375 }
376
376
377 QColor DeclarativeChart::backgroundColor()
377 QColor DeclarativeChart::backgroundColor()
378 {
378 {
379 return m_chart->backgroundBrush().color();
379 return m_chart->backgroundBrush().color();
380 }
380 }
381
381
382 int DeclarativeChart::count()
382 int DeclarativeChart::count()
383 {
383 {
384 return m_chart->series().count();
384 return m_chart->series().count();
385 }
385 }
386
386
387 void DeclarativeChart::setDropShadowEnabled(bool enabled)
387 void DeclarativeChart::setDropShadowEnabled(bool enabled)
388 {
388 {
389 if (enabled != m_chart->isDropShadowEnabled()) {
389 if (enabled != m_chart->isDropShadowEnabled()) {
390 m_chart->setDropShadowEnabled(enabled);
390 m_chart->setDropShadowEnabled(enabled);
391 dropShadowEnabledChanged(enabled);
391 dropShadowEnabledChanged(enabled);
392 }
392 }
393 }
393 }
394
394
395 bool DeclarativeChart::dropShadowEnabled()
395 bool DeclarativeChart::dropShadowEnabled()
396 {
396 {
397 return m_chart->isDropShadowEnabled();
397 return m_chart->isDropShadowEnabled();
398 }
398 }
399
399
400 qreal DeclarativeChart::topMargin()
400 qreal DeclarativeChart::topMargin()
401 {
401 {
402 return m_chart->margins().top();
402 return m_chart->margins().top();
403 }
403 }
404
404
405 qreal DeclarativeChart::bottomMargin()
405 qreal DeclarativeChart::bottomMargin()
406 {
406 {
407 return m_chart->margins().bottom();
407 return m_chart->margins().bottom();
408 }
408 }
409
409
410 qreal DeclarativeChart::leftMargin()
410 qreal DeclarativeChart::leftMargin()
411 {
411 {
412 return m_chart->margins().left();
412 return m_chart->margins().left();
413 }
413 }
414
414
415 qreal DeclarativeChart::rightMargin()
415 qreal DeclarativeChart::rightMargin()
416 {
416 {
417 return m_chart->margins().right();
417 return m_chart->margins().right();
418 }
418 }
419
419
420 void DeclarativeChart::zoom(qreal factor)
420 void DeclarativeChart::zoom(qreal factor)
421 {
421 {
422 m_chart->zoom(factor);
422 m_chart->zoom(factor);
423 }
423 }
424
424
425 void DeclarativeChart::scrollLeft(qreal pixels)
425 void DeclarativeChart::scrollLeft(qreal pixels)
426 {
426 {
427 m_chart->scroll(pixels, 0);
427 m_chart->scroll(pixels, 0);
428 }
428 }
429
429
430 void DeclarativeChart::scrollRight(qreal pixels)
430 void DeclarativeChart::scrollRight(qreal pixels)
431 {
431 {
432 m_chart->scroll(-pixels, 0);
432 m_chart->scroll(-pixels, 0);
433 }
433 }
434
434
435 void DeclarativeChart::scrollUp(qreal pixels)
435 void DeclarativeChart::scrollUp(qreal pixels)
436 {
436 {
437 m_chart->scroll(0, pixels);
437 m_chart->scroll(0, pixels);
438 }
438 }
439
439
440 void DeclarativeChart::scrollDown(qreal pixels)
440 void DeclarativeChart::scrollDown(qreal pixels)
441 {
441 {
442 m_chart->scroll(0, -pixels);
442 m_chart->scroll(0, -pixels);
443 }
443 }
444
444
445 QAbstractSeries *DeclarativeChart::series(int index)
445 QAbstractSeries *DeclarativeChart::series(int index)
446 {
446 {
447 if (index < m_chart->series().count()) {
447 if (index < m_chart->series().count()) {
448 return m_chart->series().at(index);
448 return m_chart->series().at(index);
449 }
449 }
450 return 0;
450 return 0;
451 }
451 }
452
452
453 QAbstractSeries *DeclarativeChart::series(QString seriesName)
453 QAbstractSeries *DeclarativeChart::series(QString seriesName)
454 {
454 {
455 foreach(QAbstractSeries *series, m_chart->series()) {
455 foreach(QAbstractSeries *series, m_chart->series()) {
456 if (series->name() == seriesName)
456 if (series->name() == seriesName)
457 return series;
457 return series;
458 }
458 }
459 return 0;
459 return 0;
460 }
460 }
461
461
462 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
462 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType type, QString name)
463 {
463 {
464 QAbstractSeries *series = 0;
464 QAbstractSeries *series = 0;
465 switch (type) {
465 switch (type) {
466 case DeclarativeChart::SeriesTypeLine:
466 case DeclarativeChart::SeriesTypeLine:
467 series = new DeclarativeLineSeries();
467 series = new DeclarativeLineSeries();
468 break;
468 break;
469 case DeclarativeChart::SeriesTypeArea:
469 case DeclarativeChart::SeriesTypeArea:
470 series = new DeclarativeAreaSeries();
470 series = new DeclarativeAreaSeries();
471 break;
471 break;
472 case DeclarativeChart::SeriesTypeStackedBar:
472 case DeclarativeChart::SeriesTypeStackedBar:
473 // TODO
473 // TODO
474 break;
474 break;
475 case DeclarativeChart::SeriesTypePercentBar:
475 case DeclarativeChart::SeriesTypePercentBar:
476 // TODO
476 // TODO
477 break;
477 break;
478 case DeclarativeChart::SeriesTypeBar:
478 case DeclarativeChart::SeriesTypeBar:
479 series = new DeclarativeBarSeries();
479 series = new DeclarativeBarSeries();
480 break;
480 break;
481 case DeclarativeChart::SeriesTypePie:
481 case DeclarativeChart::SeriesTypePie:
482 series = new DeclarativePieSeries();
482 series = new DeclarativePieSeries();
483 break;
483 break;
484 case DeclarativeChart::SeriesTypeScatter:
484 case DeclarativeChart::SeriesTypeScatter:
485 series = new DeclarativeScatterSeries();
485 series = new DeclarativeScatterSeries();
486 break;
486 break;
487 case DeclarativeChart::SeriesTypeSpline:
487 case DeclarativeChart::SeriesTypeSpline:
488 series = new DeclarativeSplineSeries();
488 series = new DeclarativeSplineSeries();
489 break;
489 break;
490 default:
490 default:
491 qWarning() << "Illegal series type";
491 qWarning() << "Illegal series type";
492 }
492 }
493 series->setName(name);
493 series->setName(name);
494 m_chart->addSeries(series);
494 m_chart->addSeries(series);
495 m_chart->createDefaultAxes();
495 m_chart->createDefaultAxes();
496 return series;
496 return series;
497 }
497 }
498
498
499 void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series)
499 void DeclarativeChart::setAxisX(QAbstractAxis* axis, QAbstractSeries *series)
500 {
500 {
501 m_chart->setAxisX(axis,series);
501 m_chart->setAxisX(axis,series);
502 }
502 }
503
503
504 void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series)
504 void DeclarativeChart::setAxisY(QAbstractAxis* axis, QAbstractSeries *series)
505 {
505 {
506 m_chart->setAxisY(axis,series);
506 m_chart->setAxisY(axis,series);
507 }
507 }
508
508
509 void DeclarativeChart::createDefaultAxes()
509 void DeclarativeChart::createDefaultAxes()
510 {
510 {
511 m_chart->createDefaultAxes();
511 m_chart->createDefaultAxes();
512 }
512 }
513
513
514 #include "moc_declarativechart.cpp"
514 #include "moc_declarativechart.cpp"
515
515
516 QTCOMMERCIALCHART_END_NAMESPACE
516 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,104 +1,104
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 <QtDeclarative/qdeclarativeextensionplugin.h>
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
22 #include <QtDeclarative/qdeclarative.h>
22 #include <QtDeclarative/qdeclarative.h>
23 #include "qchart.h"
23 #include "qchart.h"
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qvaluesaxis.h"
25 #include "qvaluesaxis.h"
26 #include "qcategoriesaxis.h"
26 #include "qbarcategoriesaxis.h"
27 #include "declarativechart.h"
27 #include "declarativechart.h"
28 #include "declarativexypoint.h"
28 #include "declarativexypoint.h"
29 #include "declarativelineseries.h"
29 #include "declarativelineseries.h"
30 #include "declarativesplineseries.h"
30 #include "declarativesplineseries.h"
31 #include "declarativeareaseries.h"
31 #include "declarativeareaseries.h"
32 #include "declarativescatterseries.h"
32 #include "declarativescatterseries.h"
33 #include "declarativebarseries.h"
33 #include "declarativebarseries.h"
34 #include "declarativepieseries.h"
34 #include "declarativepieseries.h"
35 #include <QVXYModelMapper>
35 #include <QVXYModelMapper>
36 #include <QHXYModelMapper>
36 #include <QHXYModelMapper>
37 #include <QHPieModelMapper>
37 #include <QHPieModelMapper>
38 #include <QVPieModelMapper>
38 #include <QVPieModelMapper>
39 #include <QHBarModelMapper>
39 #include <QHBarModelMapper>
40 #include <QVBarModelMapper>
40 #include <QVBarModelMapper>
41
41
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
42 QTCOMMERCIALCHART_BEGIN_NAMESPACE
43
43
44 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
44 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 virtual void registerTypes(const char *uri)
48 virtual void registerTypes(const char *uri)
49 {
49 {
50 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
50 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
51
51
52 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
52 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
53 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
53 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
54 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
54 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
55 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
55 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
56 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
56 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
57 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
57 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
58 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
58 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
59 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
59 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
60 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
60 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
61 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
61 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
62 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
62 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
63 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
63 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
64 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
64 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
65 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
65 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
66 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
66 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
67 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
67 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
68 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
68 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
69 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
69 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
70 qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis");
70 qmlRegisterType<QValuesAxis>(uri, 1, 0, "ValuesAxis");
71 qmlRegisterType<QBarCategoriesAxis>(uri, 1, 0, "BarCategoriesAxis");
71 qmlRegisterType<QBarCategoriesAxis>(uri, 1, 0, "BarCategoriesAxis");
72
72
73 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
73 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
74 QLatin1String("Trying to create uncreatable: Legend."));
74 QLatin1String("Trying to create uncreatable: Legend."));
75 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
75 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
76 QLatin1String("Trying to create uncreatable: XYSeries."));
76 QLatin1String("Trying to create uncreatable: XYSeries."));
77 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
77 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
78 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
78 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
79 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
79 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
80 QLatin1String("Trying to create uncreatable: XYModelMapper."));
80 QLatin1String("Trying to create uncreatable: XYModelMapper."));
81 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
81 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
82 QLatin1String("Trying to create uncreatable: PieModelMapper."));
82 QLatin1String("Trying to create uncreatable: PieModelMapper."));
83 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
83 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
84 QLatin1String("Trying to create uncreatable: BarModelMapper."));
84 QLatin1String("Trying to create uncreatable: BarModelMapper."));
85 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
85 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
86 QLatin1String("Trying to create uncreatable: AbstractSeries."));
86 QLatin1String("Trying to create uncreatable: AbstractSeries."));
87 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
87 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
88 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
88 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
89 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
89 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
90 QLatin1String("Trying to create uncreatable: AbstractAxis."));
90 QLatin1String("Trying to create uncreatable: AbstractAxis."));
91 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
91 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
92 QLatin1String("Trying to create uncreatable: PieModelMapper."));
92 QLatin1String("Trying to create uncreatable: PieModelMapper."));
93 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
93 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
94 QLatin1String("Trying to create uncreatable: XYModelMapper."));
94 QLatin1String("Trying to create uncreatable: XYModelMapper."));
95 }
95 }
96 };
96 };
97
97
98 #include "plugin.moc"
98 #include "plugin.moc"
99
99
100 QTCOMMERCIALCHART_END_NAMESPACE
100 QTCOMMERCIALCHART_END_NAMESPACE
101
101
102 QTCOMMERCIALCHART_USE_NAMESPACE
102 QTCOMMERCIALCHART_USE_NAMESPACE
103
103
104 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
104 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,31 +1,30
1 INCLUDEPATH += $$PWD
1 INCLUDEPATH += $$PWD
2 DEPENDPATH += $$PWD
2 DEPENDPATH += $$PWD
3
3
4 SOURCES += \
4 SOURCES += \
5 $$PWD/chartaxis.cpp \
5 $$PWD/chartaxis.cpp \
6 # $$PWD/chartaxisx.cpp \
7 # $$PWD/chartaxisy.cpp \
8 $$PWD/chartvaluesaxisx.cpp \
6 $$PWD/chartvaluesaxisx.cpp \
9 $$PWD/chartvaluesaxisy.cpp \
7 $$PWD/chartvaluesaxisy.cpp \
10 $$PWD/chartcategoriesaxisx.cpp \
8 $$PWD/chartcategoriesaxisx.cpp \
11 $$PWD/chartcategoriesaxisy.cpp \
9 $$PWD/chartcategoriesaxisy.cpp \
10 $$PWD/qbarcategoriesaxis.cpp \
12 $$PWD/qcategoriesaxis.cpp \
11 $$PWD/qcategoriesaxis.cpp \
13 $$PWD/qvaluesaxis.cpp \
12 $$PWD/qvaluesaxis.cpp \
14 $$PWD/qabstractaxis.cpp
13 $$PWD/qabstractaxis.cpp
15
14
16 PRIVATE_HEADERS += \
15 PRIVATE_HEADERS += \
17 $$PWD/chartaxis_p.h \
16 $$PWD/chartaxis_p.h \
18 # $$PWD/chartaxisx_p.h \
19 # $$PWD/chartaxisy_p.h \
20 $$PWD/chartvaluesaxisx_p.h \
17 $$PWD/chartvaluesaxisx_p.h \
21 $$PWD/chartvaluesaxisy_p.h \
18 $$PWD/chartvaluesaxisy_p.h \
22 $$PWD/chartcategoriesaxisx_p.h \
19 $$PWD/chartcategoriesaxisx_p.h \
23 $$PWD/chartcategoriesaxisy_p.h \
20 $$PWD/chartcategoriesaxisy_p.h \
21 $$PWD/qbarcategoriesaxis_p.h \
24 $$PWD/qcategoriesaxis_p.h \
22 $$PWD/qcategoriesaxis_p.h \
25 $$PWD/qvaluesaxis_p.h \
23 $$PWD/qvaluesaxis_p.h \
26 $$PWD/qabstractaxis_p.h
24 $$PWD/qabstractaxis_p.h
27
25
28 PUBLIC_HEADERS += \
26 PUBLIC_HEADERS += \
27 $$PWD/qbarcategoriesaxis.h \
29 $$PWD/qcategoriesaxis.h \
28 $$PWD/qcategoriesaxis.h \
30 $$PWD/qvaluesaxis.h \
29 $$PWD/qvaluesaxis.h \
31 $$PWD/qabstractaxis.h
30 $$PWD/qabstractaxis.h
@@ -1,106 +1,106
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 "chartcategoriesaxisx_p.h"
21 #include "chartcategoriesaxisx_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QCategoriesAxis>
28 #include <QBarCategoriesAxis>
29
29
30 static int label_padding = 5;
30 static int label_padding = 5;
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
34 ChartCategoriesAxisX::ChartCategoriesAxisX(QBarCategoriesAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter),
35 m_categoriesAxis(axis)
35 m_categoriesAxis(axis)
36 {
36 {
37
37
38 }
38 }
39
39
40 ChartCategoriesAxisX::~ChartCategoriesAxisX()
40 ChartCategoriesAxisX::~ChartCategoriesAxisX()
41 {
41 {
42 }
42 }
43
43
44 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
44 QVector<qreal> ChartCategoriesAxisX::calculateLayout() const
45 {
45 {
46 Q_ASSERT(m_ticksCount>=2);
46 Q_ASSERT(m_ticksCount>=2);
47
47
48 QVector<qreal> points;
48 QVector<qreal> points;
49 points.resize(m_ticksCount);
49 points.resize(m_ticksCount);
50
50
51 // TODO: shift logic
51 // TODO: shift logic
52 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
52 const qreal deltaX = m_rect.width()/(m_ticksCount-1);
53 for (int i = 0; i < m_ticksCount; ++i) {
53 for (int i = 0; i < m_ticksCount; ++i) {
54 int x = i * deltaX + m_rect.left();
54 int x = i * deltaX + m_rect.left();
55 points[i] = x;
55 points[i] = x;
56 }
56 }
57 return points;
57 return points;
58 }
58 }
59
59
60 void ChartCategoriesAxisX::updateGeometry()
60 void ChartCategoriesAxisX::updateGeometry()
61 {
61 {
62 const QVector<qreal>& layout = ChartAxis::layout();
62 const QVector<qreal>& layout = ChartAxis::layout();
63
63
64 m_minWidth = 0;
64 m_minWidth = 0;
65 m_minHeight = 0;
65 m_minHeight = 0;
66
66
67 if(layout.isEmpty()) return;
67 if(layout.isEmpty()) return;
68
68
69 QStringList ticksList;
69 QStringList ticksList;
70
70
71 createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories());
71 createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories());
72
72
73 QList<QGraphicsItem *> lines = m_grid->childItems();
73 QList<QGraphicsItem *> lines = m_grid->childItems();
74 QList<QGraphicsItem *> labels = m_labels->childItems();
74 QList<QGraphicsItem *> labels = m_labels->childItems();
75 QList<QGraphicsItem *> shades = m_shades->childItems();
75 QList<QGraphicsItem *> shades = m_shades->childItems();
76 QList<QGraphicsItem *> axis = m_axis->childItems();
76 QList<QGraphicsItem *> axis = m_axis->childItems();
77
77
78 Q_ASSERT(labels.size() == ticksList.size());
78 Q_ASSERT(labels.size() == ticksList.size());
79 Q_ASSERT(layout.size() == ticksList.size());
79 Q_ASSERT(layout.size() == ticksList.size());
80
80
81 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
81 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
82 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
82 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
83
83
84 for (int i = 1; i < layout.size(); ++i) {
84 for (int i = 1; i < layout.size(); ++i) {
85 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
85 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
86 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
86 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
87 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i-1));
87 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i-1));
88
88
89 labelItem->setText(ticksList.at(i-1));
89 labelItem->setText(ticksList.at(i-1));
90 const QRectF& rect = labelItem->boundingRect();
90 const QRectF& rect = labelItem->boundingRect();
91 QPointF center = rect.center();
91 QPointF center = rect.center();
92 labelItem->setTransformOriginPoint(center.x(), center.y());
92 labelItem->setTransformOriginPoint(center.x(), center.y());
93 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
93 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
94 m_minWidth+=rect.width();
94 m_minWidth+=rect.width();
95 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
95 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
96
96
97 if ((i+1)%2 && i>1) {
97 if ((i+1)%2 && i>1) {
98 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
98 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
99 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
99 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
100 }
100 }
101 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
101 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
102 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
102 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
103 }
103 }
104 }
104 }
105
105
106 QTCOMMERCIALCHART_END_NAMESPACE
106 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,104 +1,104
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 "chartcategoriesaxisy_p.h"
21 #include "chartcategoriesaxisy_p.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "chartpresenter_p.h"
23 #include "chartpresenter_p.h"
24 #include "chartanimator_p.h"
24 #include "chartanimator_p.h"
25 #include <QGraphicsLayout>
25 #include <QGraphicsLayout>
26 #include <QDebug>
26 #include <QDebug>
27 #include <QFontMetrics>
27 #include <QFontMetrics>
28 #include <QCategoriesAxis>
28 #include <QBarCategoriesAxis>
29
29
30 static int label_padding = 5;
30 static int label_padding = 5;
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 ChartCategoriesAxisY::ChartCategoriesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
34 ChartCategoriesAxisY::ChartCategoriesAxisY(QAbstractAxis *axis,ChartPresenter *presenter) : ChartAxis(axis,presenter)
35 {
35 {
36 }
36 }
37
37
38 ChartCategoriesAxisY::~ChartCategoriesAxisY()
38 ChartCategoriesAxisY::~ChartCategoriesAxisY()
39 {
39 {
40 }
40 }
41
41
42 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
42 QVector<qreal> ChartCategoriesAxisY::calculateLayout() const
43 {
43 {
44 Q_ASSERT(m_ticksCount>=2);
44 Q_ASSERT(m_ticksCount>=2);
45
45
46 QVector<qreal> points;
46 QVector<qreal> points;
47 points.resize(m_ticksCount);
47 points.resize(m_ticksCount);
48
48
49 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
49 const qreal deltaY = m_rect.height()/(m_ticksCount-1);
50 for (int i = 0; i < m_ticksCount; ++i) {
50 for (int i = 0; i < m_ticksCount; ++i) {
51 int y = i * -deltaY + m_rect.bottom();
51 int y = i * -deltaY + m_rect.bottom();
52 points[i] = y;
52 points[i] = y;
53 }
53 }
54
54
55 return points;
55 return points;
56 }
56 }
57
57
58 void ChartCategoriesAxisY::updateGeometry()
58 void ChartCategoriesAxisY::updateGeometry()
59 {
59 {
60 const QVector<qreal>& layout = ChartAxis::layout();
60 const QVector<qreal>& layout = ChartAxis::layout();
61
61
62 m_minWidth = 0;
62 m_minWidth = 0;
63 m_minHeight = 0;
63 m_minHeight = 0;
64
64
65 if(layout.isEmpty()) return;
65 if(layout.isEmpty()) return;
66
66
67 QStringList ticksList;
67 QStringList ticksList;
68
68
69 createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories());
69 createCategoryLabels(ticksList,m_min,m_max,m_categoriesAxis->categories());
70
70
71 QList<QGraphicsItem *> lines = m_grid->childItems();
71 QList<QGraphicsItem *> lines = m_grid->childItems();
72 QList<QGraphicsItem *> labels = m_labels->childItems();
72 QList<QGraphicsItem *> labels = m_labels->childItems();
73 QList<QGraphicsItem *> shades = m_shades->childItems();
73 QList<QGraphicsItem *> shades = m_shades->childItems();
74 QList<QGraphicsItem *> axis = m_axis->childItems();
74 QList<QGraphicsItem *> axis = m_axis->childItems();
75
75
76 Q_ASSERT(labels.size() == ticksList.size());
76 Q_ASSERT(labels.size() == ticksList.size());
77 Q_ASSERT(layout.size() == ticksList.size());
77 Q_ASSERT(layout.size() == ticksList.size());
78
78
79 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
79 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(axis.at(0));
80 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
80 lineItem->setLine(m_rect.left(), m_rect.bottom(), m_rect.right(), m_rect.bottom());
81
81
82 for (int i = 1; i < layout.size(); ++i) {
82 for (int i = 1; i < layout.size(); ++i) {
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
83 QGraphicsLineItem *lineItem = static_cast<QGraphicsLineItem*>(lines.at(i));
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
84 lineItem->setLine(layout[i], m_rect.top(), layout[i], m_rect.bottom());
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
85 QGraphicsSimpleTextItem *labelItem = static_cast<QGraphicsSimpleTextItem*>(labels.at(i));
86
86
87 labelItem->setText(ticksList.at(i));
87 labelItem->setText(ticksList.at(i));
88 const QRectF& rect = labelItem->boundingRect();
88 const QRectF& rect = labelItem->boundingRect();
89 QPointF center = rect.center();
89 QPointF center = rect.center();
90 labelItem->setTransformOriginPoint(center.x(), center.y());
90 labelItem->setTransformOriginPoint(center.x(), center.y());
91 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
91 labelItem->setPos(layout[i] - (layout[i] - layout[i-1])/2 - center.x(), m_rect.bottom() + label_padding);
92 m_minWidth+=rect.width();
92 m_minWidth+=rect.width();
93 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
93 m_minHeight=qMax(rect.height()+label_padding,m_minHeight);
94
94
95 if ((i+1)%2 && i>1) {
95 if ((i+1)%2 && i>1) {
96 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
96 QGraphicsRectItem *rectItem = static_cast<QGraphicsRectItem*>(shades.at(i/2-1));
97 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
97 rectItem->setRect(layout[i-1],m_rect.top(),layout[i]-layout[i-1],m_rect.height());
98 }
98 }
99 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
99 lineItem = static_cast<QGraphicsLineItem*>(axis.at(i+1));
100 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
100 lineItem->setLine(layout[i],m_rect.bottom(),layout[i],m_rect.bottom()+5);
101 }
101 }
102 }
102 }
103
103
104 QTCOMMERCIALCHART_END_NAMESPACE
104 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,297 +1,149
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 "qcategoriesaxis.h"
21 #include "qcategoriesaxis.h"
22 #include "qcategoriesaxis_p.h"
22 #include "qcategoriesaxis_p.h"
23 #include "chartcategoriesaxisx_p.h"
23 #include "chartcategoriesaxisx_p.h"
24 #include "chartcategoriesaxisy_p.h"
24 #include "chartcategoriesaxisy_p.h"
25 #include <qmath.h>
25 #include <qmath.h>
26 #include <QDebug>
26 #include <QDebug>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 QBarCategoriesAxis::QBarCategoriesAxis(QObject *parent):
30 QCategoriesAxis::QCategoriesAxis(QObject *parent):
31 QAbstractAxis(*new QBarCategoriesAxisPrivate(this),parent)
31 QValuesAxis(*new QCategoriesAxisPrivate(this),parent)
32 {
32 {
33 }
33 }
34
34
35 QBarCategoriesAxis::~QBarCategoriesAxis()
35 QCategoriesAxis::~QCategoriesAxis()
36 {
36 {
37 }
37 }
38
38
39 QBarCategoriesAxis::QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent):QAbstractAxis(d,parent)
39 QCategoriesAxis::QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent):QValuesAxis(d,parent)
40 {
40 {
41
41
42 }
42 }
43
43
44 /*!
44 /*!
45 Appends \a categories to axis
45 Appends \a categories to axis
46 */
46 */
47 void QBarCategoriesAxis::append(const QStringList &categories)
47 void QCategoriesAxis::append(const QString& category, qreal x)
48 {
48 {
49 Q_D(QBarCategoriesAxis);
49 Q_D(QCategoriesAxis);
50 if (d->m_categories.isEmpty()) {
50 if (!d->m_categories.contains(category))
51 d->m_categories.append(categories);
51 {
52 setRange(categories.first(),categories.last());
52 if(d->m_categories.isEmpty()){
53 }else{
53 Range range(d->m_categoryMinimum,x);
54 d->m_categories.append(categories);
54 d->m_categoriesMap.insert(category,range);
55 d->m_categories.append(category);
56 }else{
57 Range range = d->m_categoriesMap.value(d->m_categories.last());
58 d->m_categoriesMap.insert(category,Range(range.first,x));
59 d->m_categories.append(category);
60 }
61 setRange(d->m_min,x);
55 }
62 }
56
57 emit categoriesChanged();
58 }
63 }
59
64
60 /*!
65 void QCategoriesAxis::setFisrtCategoryMinimum(qreal x)
61 Appends \a category to axis
62 */
63 void QBarCategoriesAxis::append(const QString &category)
64 {
66 {
65 Q_D(QBarCategoriesAxis);
67 Q_D(QCategoriesAxis);
66 if (d->m_categories.isEmpty()) {
68 if(d->m_categories.isEmpty()){
67 d->m_categories.append(category);
69 d->m_categoryMinimum=x;
68 setRange(category,category);
70 }else{
69 }else{
71 Range range = d->m_categoriesMap.value(d->m_categories.first());
70 d->m_categories.append(category);
72 d->m_categoriesMap.insert(d->m_categories.first(),Range(x,range.second));
71 }
73 setRange(x,d->m_min);
72 emit categoriesChanged();
74 }
73 }
75 }
74
76
75 /*!
77 /*!
76 Removes \a category from axis
78 Removes \a category from axis
77 */
79 */
78 void QBarCategoriesAxis::remove(const QString &category)
80 void QCategoriesAxis::remove(const QString &category)
79 {
80 Q_D(QBarCategoriesAxis);
81 if (d->m_categories.contains(category)) {
82 d->m_categories.removeAt(d->m_categories.indexOf(category));
83 setRange(d->m_categories.first(),d->m_categories.last());
84 emit categoriesChanged();
85 }
86 }
87
88 /*!
89 Inserts \a category to axis at \a index
90 */
91 void QBarCategoriesAxis::insert(int index, const QString &category)
92 {
93 Q_D(QBarCategoriesAxis);
94 if (d->m_categories.isEmpty()) {
95 d->m_categories.insert(index,category);
96 setRange(category,category);
97 }else{
98
99 }
100 emit categoriesChanged();
101 }
102
103 /*!
104 Removes all categories.
105 */
106 void QBarCategoriesAxis::clear()
107 {
81 {
108 Q_D(QBarCategoriesAxis);
82 Q_UNUSED(category);
109 d->m_categories.clear();
83 //TODO
110 setRange(QString::null,QString::null);
111 emit categoriesChanged();
112 }
84 }
113
85
114 void QBarCategoriesAxis::setCategories(const QStringList &categories)
86 QStringList QCategoriesAxis::categories()
115 {
87 {
116 Q_D(QBarCategoriesAxis);
88 Q_D(QCategoriesAxis);
117 if(d->m_categories!=categories){
118 d->m_categories = categories;
119 setRange(categories.first(),categories.last());
120 emit categoriesChanged();
121 }
122 }
123
124 QStringList QBarCategoriesAxis::categories()
125 {
126 Q_D(QBarCategoriesAxis);
127 return d->m_categories;
89 return d->m_categories;
128 }
90 }
129
91
130 /*!
92 /*!
131 Returns number of categories.
93 Returns number of categories.
132 */
94 */
133 int QBarCategoriesAxis::count() const
95 int QCategoriesAxis::count() const
134 {
96 {
135 Q_D(const QBarCategoriesAxis);
97 Q_D(const QCategoriesAxis);
136 return d->m_categories.count();
98 return d->m_categories.count();
137 }
99 }
138
100
139 /*!
101 /*!
140 Returns category at \a index. Index must be valid.
141 */
142 QString QBarCategoriesAxis::at(int index) const
143 {
144 Q_D(const QBarCategoriesAxis);
145 return d->m_categories.at(index);
146 }
147
148 /*!
149 Sets minimum category to \a min.
150 */
151 void QBarCategoriesAxis::setMin(const QString& min)
152 {
153 Q_D(QBarCategoriesAxis);
154 setRange(min,d->m_maxCategory);
155 }
156
157 /*!
158 Returns minimum category.
159 */
160 QString QBarCategoriesAxis::min() const
161 {
162 Q_D(const QBarCategoriesAxis);
163 return d->m_minCategory;
164 }
165
166 /*!
167 Sets maximum category to \a max.
168 */
169 void QBarCategoriesAxis::setMax(const QString& max)
170 {
171 Q_D(QBarCategoriesAxis);
172 setRange(d->m_minCategory,max);
173 }
174
175 /*!
176 Returns maximum category
177 */
178 QString QBarCategoriesAxis::max() const
179 {
180 Q_D(const QBarCategoriesAxis);
181 return d->m_maxCategory;
182 }
183
184 /*!
185 Sets range from \a minCategory to \a maxCategory
186 */
187 void QBarCategoriesAxis::setRange(const QString& minCategory, const QString& maxCategory)
188 {
189 Q_D(QBarCategoriesAxis);
190
191 int minIndex = d->m_categories.indexOf(minCategory);
192 if (minIndex == -1) {
193 return;
194 }
195 int maxIndex = d->m_categories.indexOf(maxCategory);
196 if (maxIndex == -1) {
197 return;
198 }
199
200 if (maxIndex <= minIndex) {
201 // max must be greater than min
202 return;
203 }
204
205 bool changed = false;
206 if (!qFuzzyIsNull(d->m_min - (minIndex))) {
207 d->m_minCategory = minCategory;
208 d->m_min = minIndex;
209 changed = true;
210 }
211
212 if (!qFuzzyIsNull(d->m_max - (maxIndex))) {
213 d->m_max = maxIndex;
214 d->m_maxCategory = maxCategory;
215 changed = true;
216 }
217
218 if ((changed)) {
219 d->emitRange();
220 emit categoriesChanged();
221 }
222 }
223
224 /*!
225 Returns the type of axis.
102 Returns the type of axis.
226 */
103 */
227 QAbstractAxis::AxisType QBarCategoriesAxis::type() const
104 QAbstractAxis::AxisType QCategoriesAxis::type() const
228 {
105 {
229 return AxisTypeCategories;
106 return AxisTypeCategories;
230 }
107 }
231
108
232 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
109 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
233
110
234 QBarCategoriesAxisPrivate::QBarCategoriesAxisPrivate(QBarCategoriesAxis* q):
111 QCategoriesAxisPrivate::QCategoriesAxisPrivate(QCategoriesAxis* q):
235 QAbstractAxisPrivate(q)
112 QValuesAxisPrivate(q),
113 m_categoryMinimum(0)
236 {
114 {
237
115
238 }
116 }
239
117
240 QBarCategoriesAxisPrivate::~QBarCategoriesAxisPrivate()
118 QCategoriesAxisPrivate::~QCategoriesAxisPrivate()
241 {
119 {
242
120
243 }
121 }
244
122
245 void QBarCategoriesAxisPrivate::setMin(const QVariant &min)
123 int QCategoriesAxisPrivate::ticksCount() const
246 {
247 setRange(min,m_maxCategory);
248 }
249
250 void QBarCategoriesAxisPrivate::setMax(const QVariant &max)
251 {
252 setRange(m_minCategory,max);
253 }
254
255 void QBarCategoriesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
256 {
257 Q_Q(QBarCategoriesAxis);
258 QString value1 = min.toString();
259 QString value2 = max.toString();
260 q->setRange(value1,value2);
261 }
262
263 int QBarCategoriesAxisPrivate::ticksCount() const
264 {
124 {
265 return m_categories.count()+1;
125 return m_categories.count()+1;
266 }
126 }
267
127
268 void QBarCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
128 void QCategoriesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
269 {
129 {
270 m_min = min;
130 m_min = min;
271 m_max = max;
131 m_max = max;
272 m_ticksCount = count;
132 m_ticksCount = count;
273 }
133 }
274
134
275 ChartAxis* QBarCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
135 ChartAxis* QCategoriesAxisPrivate::createGraphics(ChartPresenter* presenter)
276 {
136 {
277 Q_Q( QBarCategoriesAxis);
137 Q_UNUSED(presenter);
138 // Q_Q( QCategoriesAxis);
278 if(m_orientation == Qt::Vertical){
139 if(m_orientation == Qt::Vertical){
279 return new ChartCategoriesAxisY(q,presenter);
140 return 0;
280 }else{
141 }else{
281 return new ChartCategoriesAxisX(q,presenter);
142 return 0;
282 }
143 }
283 }
144 }
284
145
285 void QBarCategoriesAxisPrivate::emitRange()
286 {
287 Q_Q( QBarCategoriesAxis);
288 if(!q->signalsBlocked()) {
289 emit changed(m_min -0.5, m_max +0.5, qCeil(m_max + 0.5) -qCeil(m_min - 0.5) +1, false);
290 }
291 }
292
293
294 #include "moc_qcategoriesaxis.cpp"
146 #include "moc_qcategoriesaxis.cpp"
295 #include "moc_qcategoriesaxis_p.cpp"
147 #include "moc_qcategoriesaxis_p.cpp"
296
148
297 QTCOMMERCIALCHART_END_NAMESPACE
149 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,76 +1,64
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCATEGORIESAXIS_H
21 #ifndef QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
22 #define QCATEGORIESAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qvaluesaxis.h"
25
26
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
28
28 class QBarCategoriesAxisPrivate;
29 class QCategoriesAxisPrivate;
29
30
30 class QTCOMMERCIALCHART_EXPORT QBarCategoriesAxis : public QAbstractAxis
31 class QTCOMMERCIALCHART_EXPORT QCategoriesAxis : public QValuesAxis
31 {
32 {
32 Q_OBJECT
33 Q_OBJECT
33 Q_PROPERTY(QStringList categories READ categories WRITE setCategories NOTIFY categoriesChanged)
34 Q_PROPERTY(QString min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(QString max READ max WRITE setMax NOTIFY maxChanged)
36
34
37 public:
35 public:
38 explicit QBarCategoriesAxis(QObject *parent = 0);
36 explicit QCategoriesAxis(QObject *parent = 0);
39 ~QBarCategoriesAxis();
37 ~QCategoriesAxis();
40
38
41 protected:
39 protected:
42 QBarCategoriesAxis(QBarCategoriesAxisPrivate &d,QObject *parent = 0);
40 QCategoriesAxis(QCategoriesAxisPrivate &d,QObject *parent = 0);
43
41
44 public:
42 public:
45 AxisType type() const;
43 AxisType type() const;
46 void append(const QStringList &categories);
44
47 void append(const QString &category);
45 void append(const QString& category, qreal interval = 1);
48 void remove(const QString &category);
46 void remove(const QString& category);
49 void insert(int index, const QString &category);
47
50 void clear();
48 void setFisrtCategoryMinimum(qreal x);
51 void setCategories(const QStringList &categories);
49
50 qreal categoryMin(const QString& category) const;
51 qreal categoryMax(const QString& category) const;
52
52 QStringList categories();
53 QStringList categories();
53 int count() const;
54 int count() const;
54 QString at(int index) const;
55
56 //range handling
57 void setMin(const QString& minCategory);
58 QString min() const;
59 void setMax(const QString& maxCategory);
60 QString max() const;
61 void setRange(const QString& minCategory, const QString& maxCategory);
62
55
63 Q_SIGNALS:
64 void categoriesChanged();
65 void minChanged(const QString &min);
66 void maxChanged(const QString &max);
67 void rangeChanged(const QString &min, const QString &max);
68
56
69 private:
57 private:
70 Q_DECLARE_PRIVATE(QBarCategoriesAxis)
58 Q_DECLARE_PRIVATE(QCategoriesAxis)
71 Q_DISABLE_COPY(QBarCategoriesAxis)
59 Q_DISABLE_COPY(QCategoriesAxis)
72 };
60 };
73
61
74 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
75
63
76 #endif // QCATEGORIESAXIS_H
64 #endif // QCATEGORIESAXIS_H
@@ -1,74 +1,71
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QCATEGORIESAXIS_P_H
30 #ifndef QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
31 #define QCATEGORIESAXIS_P_H
32
32
33 #include "qcategoriesaxis.h"
33 #include "qcategoriesaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qvaluesaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QBarCategoriesAxisPrivate : public QAbstractAxisPrivate
38
39 typedef QPair<qreal, qreal> Range;
40
41 class QCategoriesAxisPrivate : public QValuesAxisPrivate
39 {
42 {
40 Q_OBJECT
43 Q_OBJECT
41
44
42 public:
45 public:
43 QBarCategoriesAxisPrivate(QBarCategoriesAxis *q);
46 QCategoriesAxisPrivate(QCategoriesAxis *q);
44 ~QBarCategoriesAxisPrivate();
47 ~QCategoriesAxisPrivate();
48
45
49
46 public:
50 public:
47 ChartAxis* createGraphics(ChartPresenter* presenter);
51 ChartAxis* createGraphics(ChartPresenter* presenter);
48 void emitRange();
49
50 private:
51 //range handling
52 void setMin(const QVariant &min);
53 void setMax(const QVariant &max);
54 void setRange(const QVariant &min, const QVariant &max);
55 int ticksCount() const;
52 int ticksCount() const;
56
53
57 Q_SIGNALS:
54 Q_SIGNALS:
58 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
55 void changed(qreal min, qreal max, int tickCount,bool niceNumbers);
59
56
60 public Q_SLOTS:
57 public Q_SLOTS:
61 void handleAxisRangeChanged(qreal min, qreal max,int count);
58 void handleAxisRangeChanged(qreal min, qreal max,int count);
62
59
63 private:
60 private:
61 QMap<QString , Range> m_categoriesMap;
64 QStringList m_categories;
62 QStringList m_categories;
65 QString m_minCategory;
63 qreal m_categoryMinimum;
66 QString m_maxCategory;
67
64
68 private:
65 private:
69 Q_DECLARE_PUBLIC(QBarCategoriesAxis)
66 Q_DECLARE_PUBLIC(QCategoriesAxis)
70 };
67 };
71
68
72 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
73
70
74 #endif // QCATEGORIESAXIS_P_H
71 #endif // QCATEGORIESAXIS_P_H
@@ -1,743 +1,743
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 "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include "qvaluesaxis.h"
30 #include "qvaluesaxis.h"
31 #include "qcategoriesaxis.h"
31 #include "qbarcategoriesaxis.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 \class QAbstractBarSeries
36 \class QAbstractBarSeries
37 \brief Series for creating a bar chart
37 \brief Series for creating a bar chart
38 \mainclass
38 \mainclass
39
39
40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 shows the x-values.
43 shows the x-values.
44
44
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 \image examples_barchart.png
46 \image examples_barchart.png
47
47
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 */
49 */
50 /*!
50 /*!
51 \qmlclass AbstractBarSeries QAbstractBarSeries
51 \qmlclass AbstractBarSeries QAbstractBarSeries
52 \inherits QAbstractSeries
52 \inherits QAbstractSeries
53
53
54 The following QML shows how to create a simple bar chart:
54 The following QML shows how to create a simple bar chart:
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56
56
57 \beginfloatleft
57 \beginfloatleft
58 \image demos_qmlchart6.png
58 \image demos_qmlchart6.png
59 \endfloat
59 \endfloat
60 \clearfloat
60 \clearfloat
61 */
61 */
62
62
63 /*!
63 /*!
64 \property QAbstractBarSeries::barWidth
64 \property QAbstractBarSeries::barWidth
65 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 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
68 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
69 \sa QBarSeries
69 \sa QBarSeries
70 */
70 */
71 /*!
71 /*!
72 \qmlproperty real AbstractBarSeries::barWidth
72 \qmlproperty real AbstractBarSeries::barWidth
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
76 Note that with QBarSeries this value means the width of one group of bars instead of just one bar.
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QAbstractBarSeries::count
80 \property QAbstractBarSeries::count
81 Holds the number of sets in series.
81 Holds the number of sets in series.
82 */
82 */
83 /*!
83 /*!
84 \qmlproperty int AbstractBarSeries::count
84 \qmlproperty int AbstractBarSeries::count
85 Holds the number of sets in series.
85 Holds the number of sets in series.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QAbstractBarSeries::labelsVisible
89 \property QAbstractBarSeries::labelsVisible
90 Defines the visibility of the labels in series
90 Defines the visibility of the labels in series
91 */
91 */
92 /*!
92 /*!
93 \qmlproperty bool AbstractBarSeries::labelsVisible
93 \qmlproperty bool AbstractBarSeries::labelsVisible
94 Defines the visibility of the labels in series
94 Defines the visibility of the labels in series
95 */
95 */
96
96
97 /*!
97 /*!
98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
98 \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset)
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 Clicked bar inside set is indexed by \a index
100 Clicked bar inside set is indexed by \a index
101 */
101 */
102 /*!
102 /*!
103 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
103 \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset)
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 Clicked bar inside set is indexed by \a index
105 Clicked bar inside set is indexed by \a index
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
109 \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset)
110
110
111 The signal is emitted if mouse is hovered on top of series.
111 The signal is emitted if mouse is hovered on top of series.
112 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a barset is the pointer of barset, where hover happened.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 */
114 */
115 /*!
115 /*!
116 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
116 \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset)
117
117
118 The signal is emitted if mouse is hovered on top of series.
118 The signal is emitted if mouse is hovered on top of series.
119 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a barset is the pointer of barset, where hover happened.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 */
121 */
122
122
123 /*!
123 /*!
124 \fn void QAbstractBarSeries::countChanged()
124 \fn void QAbstractBarSeries::countChanged()
125 This signal is emitted when barset count has been changed, for example by append or remove.
125 This signal is emitted when barset count has been changed, for example by append or remove.
126 */
126 */
127 /*!
127 /*!
128 \qmlsignal AbstractBarSeries::onCountChanged()
128 \qmlsignal AbstractBarSeries::onCountChanged()
129 This signal is emitted when barset count has been changed, for example by append or remove.
129 This signal is emitted when barset count has been changed, for example by append or remove.
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QAbstractBarSeries::labelsVisibleChanged()
133 \fn void QAbstractBarSeries::labelsVisibleChanged()
134 This signal is emitted when labels visibility have changed.
134 This signal is emitted when labels visibility have changed.
135 \sa isLabelsVisible(), setLabelsVisible()
135 \sa isLabelsVisible(), setLabelsVisible()
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 This signal is emitted when \a sets have been added to the series.
140 This signal is emitted when \a sets have been added to the series.
141 \sa append(), insert()
141 \sa append(), insert()
142 */
142 */
143 /*!
143 /*!
144 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
144 \qmlsignal AbstractBarSeries::onAdded(BarSet barset)
145 Emitted when \a barset has been added to the series.
145 Emitted when \a barset has been added to the series.
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 This signal is emitted when \a sets have been removed from the series.
150 This signal is emitted when \a sets have been removed from the series.
151 \sa remove()
151 \sa remove()
152 */
152 */
153 /*!
153 /*!
154 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
154 \qmlsignal AbstractBarSeries::onRemoved(BarSet barset)
155 Emitted when \a barset has been removed from the series.
155 Emitted when \a barset has been removed from the series.
156 */
156 */
157
157
158 /*!
158 /*!
159 \qmlmethod BarSet AbstractBarSeries::at(int index)
159 \qmlmethod BarSet AbstractBarSeries::at(int index)
160 Returns bar set at \a index. Returns null if the index is not valid.
160 Returns bar set at \a index. Returns null if the index is not valid.
161 */
161 */
162
162
163 /*!
163 /*!
164 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
164 \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values)
165 Adds 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.
165 Adds 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.
166 For example:
166 For example:
167 \code
167 \code
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 \endcode
170 \endcode
171 */
171 */
172
172
173 /*!
173 /*!
174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
174 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
175 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.
175 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.
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 appended.
177 appended.
178 \sa AbstractBarSeries::append()
178 \sa AbstractBarSeries::append()
179 */
179 */
180
180
181 /*!
181 /*!
182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
182 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
183 Removes the barset from the series. Returns true if successfull, false otherwise.
183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 */
184 */
185
185
186 /*!
186 /*!
187 \qmlmethod AbstractBarSeries::clear()
187 \qmlmethod AbstractBarSeries::clear()
188 Removes all barsets from the series.
188 Removes all barsets from the series.
189 */
189 */
190
190
191 /*!
191 /*!
192 Constructs empty QAbstractBarSeries.
192 Constructs empty QAbstractBarSeries.
193 QAbstractBarSeries is QObject which is a child of a \a parent.
193 QAbstractBarSeries is QObject which is a child of a \a parent.
194 */
194 */
195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
197 {
197 {
198 }
198 }
199
199
200 /*!
200 /*!
201 Destructs abstractbarseries and owned barsets.
201 Destructs abstractbarseries and owned barsets.
202 */
202 */
203 QAbstractBarSeries::~QAbstractBarSeries()
203 QAbstractBarSeries::~QAbstractBarSeries()
204 {
204 {
205 Q_D(QAbstractBarSeries);
205 Q_D(QAbstractBarSeries);
206 if(d->m_dataset){
206 if(d->m_dataset){
207 d->m_dataset->removeSeries(this);
207 d->m_dataset->removeSeries(this);
208 }
208 }
209 }
209 }
210
210
211 /*!
211 /*!
212 \internal
212 \internal
213 */
213 */
214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
215 QAbstractSeries(d,parent)
215 QAbstractSeries(d,parent)
216 {
216 {
217 }
217 }
218
218
219 /*!
219 /*!
220 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
220 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
221 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
221 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
222 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
222 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
223 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
223 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
224 */
224 */
225 void QAbstractBarSeries::setBarWidth(qreal width)
225 void QAbstractBarSeries::setBarWidth(qreal width)
226 {
226 {
227 Q_D(QAbstractBarSeries);
227 Q_D(QAbstractBarSeries);
228 d->setBarWidth(width);
228 d->setBarWidth(width);
229 }
229 }
230
230
231 /*!
231 /*!
232 Returns the width of the bars of the series.
232 Returns the width of the bars of the series.
233 \sa setBarWidth()
233 \sa setBarWidth()
234 */
234 */
235 qreal QAbstractBarSeries::barWidth() const
235 qreal QAbstractBarSeries::barWidth() const
236 {
236 {
237 Q_D(const QAbstractBarSeries);
237 Q_D(const QAbstractBarSeries);
238 return d->barWidth();
238 return d->barWidth();
239 }
239 }
240
240
241 /*!
241 /*!
242 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.
242 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.
243 Returns true, if appending succeeded.
243 Returns true, if appending succeeded.
244 */
244 */
245 bool QAbstractBarSeries::append(QBarSet *set)
245 bool QAbstractBarSeries::append(QBarSet *set)
246 {
246 {
247 Q_D(QAbstractBarSeries);
247 Q_D(QAbstractBarSeries);
248 bool success = d->append(set);
248 bool success = d->append(set);
249 if (success) {
249 if (success) {
250 QList<QBarSet*> sets;
250 QList<QBarSet*> sets;
251 sets.append(set);
251 sets.append(set);
252 emit barsetsAdded(sets);
252 emit barsetsAdded(sets);
253 emit countChanged();
253 emit countChanged();
254 }
254 }
255 return success;
255 return success;
256 }
256 }
257
257
258 /*!
258 /*!
259 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
259 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
260 Returns true, if set was removed.
260 Returns true, if set was removed.
261 */
261 */
262 bool QAbstractBarSeries::remove(QBarSet *set)
262 bool QAbstractBarSeries::remove(QBarSet *set)
263 {
263 {
264 Q_D(QAbstractBarSeries);
264 Q_D(QAbstractBarSeries);
265 bool success = d->remove(set);
265 bool success = d->remove(set);
266 if (success) {
266 if (success) {
267 QList<QBarSet*> sets;
267 QList<QBarSet*> sets;
268 sets.append(set);
268 sets.append(set);
269 emit barsetsRemoved(sets);
269 emit barsetsRemoved(sets);
270 emit countChanged();
270 emit countChanged();
271 }
271 }
272 return success;
272 return success;
273 }
273 }
274
274
275 /*!
275 /*!
276 Adds a list of barsets to series. Takes ownership of \a sets.
276 Adds a list of barsets to series. Takes ownership of \a sets.
277 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
277 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
278 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
278 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
279 and function returns false.
279 and function returns false.
280 */
280 */
281 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
281 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
282 {
282 {
283 Q_D(QAbstractBarSeries);
283 Q_D(QAbstractBarSeries);
284 bool success = d->append(sets);
284 bool success = d->append(sets);
285 if (success) {
285 if (success) {
286 emit barsetsAdded(sets);
286 emit barsetsAdded(sets);
287 emit countChanged();
287 emit countChanged();
288 }
288 }
289 return success;
289 return success;
290 }
290 }
291
291
292 /*!
292 /*!
293 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.
293 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.
294 Returns true, if inserting succeeded.
294 Returns true, if inserting succeeded.
295
295
296 */
296 */
297 bool QAbstractBarSeries::insert(int index, QBarSet *set)
297 bool QAbstractBarSeries::insert(int index, QBarSet *set)
298 {
298 {
299 Q_D(QAbstractBarSeries);
299 Q_D(QAbstractBarSeries);
300 bool success = d->insert(index, set);
300 bool success = d->insert(index, set);
301 if (success) {
301 if (success) {
302 QList<QBarSet*> sets;
302 QList<QBarSet*> sets;
303 sets.append(set);
303 sets.append(set);
304 emit barsetsAdded(sets);
304 emit barsetsAdded(sets);
305 emit countChanged();
305 emit countChanged();
306 }
306 }
307 return success;
307 return success;
308 }
308 }
309
309
310 /*!
310 /*!
311 Removes all of the bar sets from the series
311 Removes all of the bar sets from the series
312 */
312 */
313 void QAbstractBarSeries::clear()
313 void QAbstractBarSeries::clear()
314 {
314 {
315 Q_D(QAbstractBarSeries);
315 Q_D(QAbstractBarSeries);
316 QList<QBarSet *> sets = barSets();
316 QList<QBarSet *> sets = barSets();
317 bool success = d->remove(sets);
317 bool success = d->remove(sets);
318 if (success) {
318 if (success) {
319 emit barsetsRemoved(sets);
319 emit barsetsRemoved(sets);
320 emit countChanged();
320 emit countChanged();
321 }
321 }
322 }
322 }
323
323
324 /*!
324 /*!
325 Returns number of sets in series.
325 Returns number of sets in series.
326 */
326 */
327 int QAbstractBarSeries::count() const
327 int QAbstractBarSeries::count() const
328 {
328 {
329 Q_D(const QAbstractBarSeries);
329 Q_D(const QAbstractBarSeries);
330 return d->m_barSets.count();
330 return d->m_barSets.count();
331 }
331 }
332
332
333 /*!
333 /*!
334 Returns a list of sets in series. Keeps ownership of sets.
334 Returns a list of sets in series. Keeps ownership of sets.
335 */
335 */
336 QList<QBarSet*> QAbstractBarSeries::barSets() const
336 QList<QBarSet*> QAbstractBarSeries::barSets() const
337 {
337 {
338 Q_D(const QAbstractBarSeries);
338 Q_D(const QAbstractBarSeries);
339 return d->m_barSets;
339 return d->m_barSets;
340 }
340 }
341
341
342 /*!
342 /*!
343 Sets the visibility of labels in series to \a visible
343 Sets the visibility of labels in series to \a visible
344 */
344 */
345 void QAbstractBarSeries::setLabelsVisible(bool visible)
345 void QAbstractBarSeries::setLabelsVisible(bool visible)
346 {
346 {
347 Q_D(QAbstractBarSeries);
347 Q_D(QAbstractBarSeries);
348 if (d->m_labelsVisible != visible) {
348 if (d->m_labelsVisible != visible) {
349 d->setLabelsVisible(visible);
349 d->setLabelsVisible(visible);
350 emit labelsVisibleChanged();
350 emit labelsVisibleChanged();
351 }
351 }
352 }
352 }
353
353
354 /*!
354 /*!
355 Returns the visibility of labels
355 Returns the visibility of labels
356 */
356 */
357 bool QAbstractBarSeries::isLabelsVisible() const
357 bool QAbstractBarSeries::isLabelsVisible() const
358 {
358 {
359 Q_D(const QAbstractBarSeries);
359 Q_D(const QAbstractBarSeries);
360 return d->m_labelsVisible;
360 return d->m_labelsVisible;
361 }
361 }
362
362
363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
363 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
364
364
365 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
365 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
366 QAbstractSeriesPrivate(q),
366 QAbstractSeriesPrivate(q),
367 m_barWidth(0.5), // Default value is 50% of category width
367 m_barWidth(0.5), // Default value is 50% of category width
368 m_labelsVisible(false),
368 m_labelsVisible(false),
369 m_visible(true)
369 m_visible(true)
370 {
370 {
371 }
371 }
372
372
373 int QAbstractBarSeriesPrivate::categoryCount() const
373 int QAbstractBarSeriesPrivate::categoryCount() const
374 {
374 {
375 // No categories defined. return count of longest set.
375 // No categories defined. return count of longest set.
376 int count = 0;
376 int count = 0;
377 for (int i=0; i<m_barSets.count(); i++) {
377 for (int i=0; i<m_barSets.count(); i++) {
378 if (m_barSets.at(i)->count() > count) {
378 if (m_barSets.at(i)->count() > count) {
379 count = m_barSets.at(i)->count();
379 count = m_barSets.at(i)->count();
380 }
380 }
381 }
381 }
382
382
383 return count;
383 return count;
384 }
384 }
385
385
386 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
386 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
387 {
387 {
388 if (width < 0.0) {
388 if (width < 0.0) {
389 width = 0.0;
389 width = 0.0;
390 }
390 }
391 m_barWidth = width;
391 m_barWidth = width;
392 emit updatedBars();
392 emit updatedBars();
393 }
393 }
394
394
395 qreal QAbstractBarSeriesPrivate::barWidth() const
395 qreal QAbstractBarSeriesPrivate::barWidth() const
396 {
396 {
397 return m_barWidth;
397 return m_barWidth;
398 }
398 }
399
399
400 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
400 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
401 {
401 {
402 return m_barSets.at(index);
402 return m_barSets.at(index);
403 }
403 }
404
404
405 void QAbstractBarSeriesPrivate::setVisible(bool visible)
405 void QAbstractBarSeriesPrivate::setVisible(bool visible)
406 {
406 {
407 m_visible = visible;
407 m_visible = visible;
408 emit updatedBars();
408 emit updatedBars();
409 }
409 }
410
410
411 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
411 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
412 {
412 {
413 m_labelsVisible = visible;
413 m_labelsVisible = visible;
414 emit labelsVisibleChanged(visible);
414 emit labelsVisibleChanged(visible);
415 }
415 }
416
416
417 qreal QAbstractBarSeriesPrivate::min()
417 qreal QAbstractBarSeriesPrivate::min()
418 {
418 {
419 if (m_barSets.count() <= 0) {
419 if (m_barSets.count() <= 0) {
420 return 0;
420 return 0;
421 }
421 }
422 qreal min = INT_MAX;
422 qreal min = INT_MAX;
423
423
424 for (int i = 0; i < m_barSets.count(); i++) {
424 for (int i = 0; i < m_barSets.count(); i++) {
425 int categoryCount = m_barSets.at(i)->count();
425 int categoryCount = m_barSets.at(i)->count();
426 for (int j = 0; j < categoryCount; j++) {
426 for (int j = 0; j < categoryCount; j++) {
427 qreal temp = m_barSets.at(i)->at(j);
427 qreal temp = m_barSets.at(i)->at(j);
428 if (temp < min)
428 if (temp < min)
429 min = temp;
429 min = temp;
430 }
430 }
431 }
431 }
432 return min;
432 return min;
433 }
433 }
434
434
435 qreal QAbstractBarSeriesPrivate::max()
435 qreal QAbstractBarSeriesPrivate::max()
436 {
436 {
437 if (m_barSets.count() <= 0) {
437 if (m_barSets.count() <= 0) {
438 return 0;
438 return 0;
439 }
439 }
440 qreal max = INT_MIN;
440 qreal max = INT_MIN;
441
441
442 for (int i = 0; i < m_barSets.count(); i++) {
442 for (int i = 0; i < m_barSets.count(); i++) {
443 int categoryCount = m_barSets.at(i)->count();
443 int categoryCount = m_barSets.at(i)->count();
444 for (int j = 0; j < categoryCount; j++) {
444 for (int j = 0; j < categoryCount; j++) {
445 qreal temp = m_barSets.at(i)->at(j);
445 qreal temp = m_barSets.at(i)->at(j);
446 if (temp > max)
446 if (temp > max)
447 max = temp;
447 max = temp;
448 }
448 }
449 }
449 }
450
450
451 return max;
451 return max;
452 }
452 }
453
453
454 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
454 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
455 {
455 {
456 if ((set < 0) || (set >= m_barSets.count())) {
456 if ((set < 0) || (set >= m_barSets.count())) {
457 // No set, no value.
457 // No set, no value.
458 return 0;
458 return 0;
459 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
459 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
460 // No category, no value.
460 // No category, no value.
461 return 0;
461 return 0;
462 }
462 }
463
463
464 return m_barSets.at(set)->at(category);
464 return m_barSets.at(set)->at(category);
465 }
465 }
466
466
467 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
467 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
468 {
468 {
469 if ((set < 0) || (set >= m_barSets.count())) {
469 if ((set < 0) || (set >= m_barSets.count())) {
470 // No set, no value.
470 // No set, no value.
471 return 0;
471 return 0;
472 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
472 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
473 // No category, no value.
473 // No category, no value.
474 return 0;
474 return 0;
475 }
475 }
476
476
477 qreal value = m_barSets.at(set)->at(category);
477 qreal value = m_barSets.at(set)->at(category);
478 qreal sum = categorySum(category);
478 qreal sum = categorySum(category);
479 if ( qFuzzyIsNull(sum) ) {
479 if ( qFuzzyIsNull(sum) ) {
480 return 0;
480 return 0;
481 }
481 }
482
482
483 return value / sum;
483 return value / sum;
484 }
484 }
485
485
486 qreal QAbstractBarSeriesPrivate::categorySum(int category)
486 qreal QAbstractBarSeriesPrivate::categorySum(int category)
487 {
487 {
488 qreal sum(0);
488 qreal sum(0);
489 int count = m_barSets.count(); // Count sets
489 int count = m_barSets.count(); // Count sets
490 for (int set = 0; set < count; set++) {
490 for (int set = 0; set < count; set++) {
491 if (category < m_barSets.at(set)->count())
491 if (category < m_barSets.at(set)->count())
492 sum += m_barSets.at(set)->at(category);
492 sum += m_barSets.at(set)->at(category);
493 }
493 }
494 return sum;
494 return sum;
495 }
495 }
496
496
497 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
497 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
498 {
498 {
499 qreal sum(0);
499 qreal sum(0);
500 int count = m_barSets.count(); // Count sets
500 int count = m_barSets.count(); // Count sets
501 for (int set = 0; set < count; set++) {
501 for (int set = 0; set < count; set++) {
502 if (category < m_barSets.at(set)->count())
502 if (category < m_barSets.at(set)->count())
503 sum += qAbs(m_barSets.at(set)->at(category));
503 sum += qAbs(m_barSets.at(set)->at(category));
504 }
504 }
505 return sum;
505 return sum;
506 }
506 }
507
507
508 qreal QAbstractBarSeriesPrivate::maxCategorySum()
508 qreal QAbstractBarSeriesPrivate::maxCategorySum()
509 {
509 {
510 qreal max = INT_MIN;
510 qreal max = INT_MIN;
511 int count = categoryCount();
511 int count = categoryCount();
512 for (int i = 0; i < count; i++) {
512 for (int i = 0; i < count; i++) {
513 qreal sum = categorySum(i);
513 qreal sum = categorySum(i);
514 if (sum > max)
514 if (sum > max)
515 max = sum;
515 max = sum;
516 }
516 }
517 return max;
517 return max;
518 }
518 }
519
519
520 qreal QAbstractBarSeriesPrivate::minX()
520 qreal QAbstractBarSeriesPrivate::minX()
521 {
521 {
522 if (m_barSets.count() <= 0) {
522 if (m_barSets.count() <= 0) {
523 return 0;
523 return 0;
524 }
524 }
525 qreal min = INT_MAX;
525 qreal min = INT_MAX;
526
526
527 for (int i = 0; i < m_barSets.count(); i++) {
527 for (int i = 0; i < m_barSets.count(); i++) {
528 int categoryCount = m_barSets.at(i)->count();
528 int categoryCount = m_barSets.at(i)->count();
529 for (int j = 0; j < categoryCount; j++) {
529 for (int j = 0; j < categoryCount; j++) {
530 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
530 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
531 if (temp < min)
531 if (temp < min)
532 min = temp;
532 min = temp;
533 }
533 }
534 }
534 }
535 return min;
535 return min;
536 }
536 }
537
537
538 qreal QAbstractBarSeriesPrivate::maxX()
538 qreal QAbstractBarSeriesPrivate::maxX()
539 {
539 {
540 if (m_barSets.count() <= 0) {
540 if (m_barSets.count() <= 0) {
541 return 0;
541 return 0;
542 }
542 }
543 qreal max = INT_MIN;
543 qreal max = INT_MIN;
544
544
545 for (int i = 0; i < m_barSets.count(); i++) {
545 for (int i = 0; i < m_barSets.count(); i++) {
546 int categoryCount = m_barSets.at(i)->count();
546 int categoryCount = m_barSets.at(i)->count();
547 for (int j = 0; j < categoryCount; j++) {
547 for (int j = 0; j < categoryCount; j++) {
548 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
548 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
549 if (temp > max)
549 if (temp > max)
550 max = temp;
550 max = temp;
551 }
551 }
552 }
552 }
553
553
554 return max;
554 return max;
555 }
555 }
556
556
557
557
558 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
558 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
559 {
559 {
560 qreal minX(domain.minX());
560 qreal minX(domain.minX());
561 qreal minY(domain.minY());
561 qreal minY(domain.minY());
562 qreal maxX(domain.maxX());
562 qreal maxX(domain.maxX());
563 qreal maxY(domain.maxY());
563 qreal maxY(domain.maxY());
564 int tickXCount(domain.tickXCount());
564 int tickXCount(domain.tickXCount());
565 int tickYCount(domain.tickYCount());
565 int tickYCount(domain.tickYCount());
566
566
567 qreal seriesMinX = this->minX();
567 qreal seriesMinX = this->minX();
568 qreal seriesMaxX = this->maxX();
568 qreal seriesMaxX = this->maxX();
569 qreal y = max();
569 qreal y = max();
570 minX = qMin(minX, seriesMinX - 0.5);
570 minX = qMin(minX, seriesMinX - 0.5);
571 minY = qMin(minY, y);
571 minY = qMin(minY, y);
572 maxX = qMax(maxX, seriesMaxX + 0.5);
572 maxX = qMax(maxX, seriesMaxX + 0.5);
573 maxY = qMax(maxY, y);
573 maxY = qMax(maxY, y);
574 tickXCount = categoryCount()+1;
574 tickXCount = categoryCount()+1;
575
575
576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
576 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
577 }
577 }
578
578
579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
579 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
580 {
580 {
581 Q_Q(QAbstractBarSeries);
581 Q_Q(QAbstractBarSeries);
582
582
583 BarChartItem* bar = new BarChartItem(q,presenter);
583 BarChartItem* bar = new BarChartItem(q,presenter);
584 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
584 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
585 presenter->animator()->addAnimation(bar);
585 presenter->animator()->addAnimation(bar);
586 }
586 }
587 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
587 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
588 return bar;
588 return bar;
589
589
590 }
590 }
591
591
592 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
592 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
593 {
593 {
594 Q_Q(QAbstractBarSeries);
594 Q_Q(QAbstractBarSeries);
595 QList<LegendMarker*> markers;
595 QList<LegendMarker*> markers;
596 foreach(QBarSet* set, q->barSets()) {
596 foreach(QBarSet* set, q->barSets()) {
597 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
597 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
598 markers << marker;
598 markers << marker;
599 }
599 }
600
600
601 return markers;
601 return markers;
602 }
602 }
603
603
604 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
604 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
605 {
605 {
606 Q_Q(QAbstractBarSeries);
606 Q_Q(QAbstractBarSeries);
607 if ((m_barSets.contains(set)) || (set == 0)) {
607 if ((m_barSets.contains(set)) || (set == 0)) {
608 // Fail if set is already in list or set is null.
608 // Fail if set is already in list or set is null.
609 return false;
609 return false;
610 }
610 }
611 m_barSets.append(set);
611 m_barSets.append(set);
612 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
612 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
613 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
613 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
614 emit restructuredBars(); // this notifies barchartitem
614 emit restructuredBars(); // this notifies barchartitem
615 if (m_dataset) {
615 if (m_dataset) {
616 m_dataset->updateSeries(q); // this notifies legend
616 m_dataset->updateSeries(q); // this notifies legend
617 }
617 }
618 return true;
618 return true;
619 }
619 }
620
620
621 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
621 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
622 {
622 {
623 Q_Q(QAbstractBarSeries);
623 Q_Q(QAbstractBarSeries);
624 if (!m_barSets.contains(set)) {
624 if (!m_barSets.contains(set)) {
625 // Fail if set is not in list
625 // Fail if set is not in list
626 return false;
626 return false;
627 }
627 }
628 m_barSets.removeOne(set);
628 m_barSets.removeOne(set);
629 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
629 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
630 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
630 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
631 emit restructuredBars(); // this notifies barchartitem
631 emit restructuredBars(); // this notifies barchartitem
632 if (m_dataset) {
632 if (m_dataset) {
633 m_dataset->updateSeries(q); // this notifies legend
633 m_dataset->updateSeries(q); // this notifies legend
634 }
634 }
635 return true;
635 return true;
636 }
636 }
637
637
638 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
638 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
639 {
639 {
640 Q_Q(QAbstractBarSeries);
640 Q_Q(QAbstractBarSeries);
641 foreach (QBarSet* set, sets) {
641 foreach (QBarSet* set, sets) {
642 if ((set == 0) || (m_barSets.contains(set))) {
642 if ((set == 0) || (m_barSets.contains(set))) {
643 // Fail if any of the sets is null or is already appended.
643 // Fail if any of the sets is null or is already appended.
644 return false;
644 return false;
645 }
645 }
646 if (sets.count(set) != 1) {
646 if (sets.count(set) != 1) {
647 // Also fail if same set is more than once in given list.
647 // Also fail if same set is more than once in given list.
648 return false;
648 return false;
649 }
649 }
650 }
650 }
651
651
652 foreach (QBarSet* set, sets) {
652 foreach (QBarSet* set, sets) {
653 m_barSets.append(set);
653 m_barSets.append(set);
654 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
654 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
655 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
655 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
656 }
656 }
657 emit restructuredBars(); // this notifies barchartitem
657 emit restructuredBars(); // this notifies barchartitem
658 if (m_dataset) {
658 if (m_dataset) {
659 m_dataset->updateSeries(q); // this notifies legend
659 m_dataset->updateSeries(q); // this notifies legend
660 }
660 }
661 return true;
661 return true;
662 }
662 }
663
663
664 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
664 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
665 {
665 {
666 Q_Q(QAbstractBarSeries);
666 Q_Q(QAbstractBarSeries);
667 if (sets.count() == 0) {
667 if (sets.count() == 0) {
668 return false;
668 return false;
669 }
669 }
670 foreach (QBarSet* set, sets) {
670 foreach (QBarSet* set, sets) {
671 if ((set == 0) || (!m_barSets.contains(set))) {
671 if ((set == 0) || (!m_barSets.contains(set))) {
672 // Fail if any of the sets is null or is not in series
672 // Fail if any of the sets is null or is not in series
673 return false;
673 return false;
674 }
674 }
675 if (sets.count(set) != 1) {
675 if (sets.count(set) != 1) {
676 // Also fail if same set is more than once in given list.
676 // Also fail if same set is more than once in given list.
677 return false;
677 return false;
678 }
678 }
679 }
679 }
680
680
681 foreach (QBarSet* set, sets) {
681 foreach (QBarSet* set, sets) {
682 m_barSets.removeOne(set);
682 m_barSets.removeOne(set);
683 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
683 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
684 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
684 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
685 }
685 }
686
686
687 emit restructuredBars(); // this notifies barchartitem
687 emit restructuredBars(); // this notifies barchartitem
688 if (m_dataset) {
688 if (m_dataset) {
689 m_dataset->updateSeries(q); // this notifies legend
689 m_dataset->updateSeries(q); // this notifies legend
690 }
690 }
691 return true;
691 return true;
692 }
692 }
693
693
694 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
694 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
695 {
695 {
696 Q_Q(QAbstractBarSeries);
696 Q_Q(QAbstractBarSeries);
697 if ((m_barSets.contains(set)) || (set == 0)) {
697 if ((m_barSets.contains(set)) || (set == 0)) {
698 // Fail if set is already in list or set is null.
698 // Fail if set is already in list or set is null.
699 return false;
699 return false;
700 }
700 }
701 m_barSets.insert(index, set);
701 m_barSets.insert(index, set);
702 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
702 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
703 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
703 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
704 emit restructuredBars(); // this notifies barchartitem
704 emit restructuredBars(); // this notifies barchartitem
705 if (m_dataset) {
705 if (m_dataset) {
706 m_dataset->updateSeries(q); // this notifies legend
706 m_dataset->updateSeries(q); // this notifies legend
707 }
707 }
708 return true;
708 return true;
709 }
709 }
710
710
711 void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
711 void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis)
712 {
712 {
713 if(axis->type()==QAbstractAxis::AxisTypeCategories)
713 if(axis->type()==QAbstractAxis::AxisTypeCategories)
714 {
714 {
715 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
715 QBarCategoriesAxis* cataxis = qobject_cast<QBarCategoriesAxis*>(axis);
716 Q_ASSERT(cataxis);
716 Q_ASSERT(cataxis);
717 QStringList categories;
717 QStringList categories;
718 for (int i(1); i < categoryCount()+1; i++)
718 for (int i(1); i < categoryCount()+1; i++)
719 categories << QString::number(i);
719 categories << QString::number(i);
720 cataxis->append(categories);
720 cataxis->append(categories);
721 }
721 }
722 }
722 }
723
723
724 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
724 void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis)
725 {
725 {
726 Q_UNUSED(axis)
726 Q_UNUSED(axis)
727 }
727 }
728
728
729 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
729 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const
730 {
730 {
731 return QAbstractAxis::AxisTypeCategories;
731 return QAbstractAxis::AxisTypeCategories;
732 }
732 }
733
733
734 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
734 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const
735 {
735 {
736 return QAbstractAxis::AxisTypeValues;
736 return QAbstractAxis::AxisTypeValues;
737 }
737 }
738
738
739 #include "moc_qabstractbarseries.cpp"
739 #include "moc_qabstractbarseries.cpp"
740 #include "moc_qabstractbarseries_p.cpp"
740 #include "moc_qabstractbarseries_p.cpp"
741
741
742
742
743 QTCOMMERCIALCHART_END_NAMESPACE
743 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,446 +1,446
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 "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvaluesaxis.h"
24 #include "qcategoriesaxis.h"
24 #include "qbarcategoriesaxis.h"
25 #include "qvaluesaxis_p.h"
25 #include "qvaluesaxis_p.h"
26 #include "qabstractseries_p.h"
26 #include "qabstractseries_p.h"
27 #include "qabstractbarseries.h"
27 #include "qabstractbarseries.h"
28 #include "qstackedbarseries.h"
28 #include "qstackedbarseries.h"
29 #include "qpercentbarseries.h"
29 #include "qpercentbarseries.h"
30 #include "qpieseries.h"
30 #include "qpieseries.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
35 m_domainIndex(0)
35 m_domainIndex(0)
36 {
36 {
37
37
38 }
38 }
39
39
40 ChartDataSet::~ChartDataSet()
40 ChartDataSet::~ChartDataSet()
41 {
41 {
42 removeAllSeries();
42 removeAllSeries();
43 }
43 }
44
44
45 void ChartDataSet::addSeries(QAbstractSeries* series)
45 void ChartDataSet::addSeries(QAbstractSeries* series)
46 {
46 {
47 Domain* domain = m_seriesDomainMap.value(series);
47 Domain* domain = m_seriesDomainMap.value(series);
48
48
49 if(domain) {
49 if(domain) {
50 qWarning() << "Can not add series. Series already on the chart";
50 qWarning() << "Can not add series. Series already on the chart";
51 return;
51 return;
52 }
52 }
53
53
54 series->setParent(this); // take ownership
54 series->setParent(this); // take ownership
55
55
56 domain = new Domain(series);
56 domain = new Domain(series);
57
57
58 m_seriesDomainMap.insert(series,domain);
58 m_seriesDomainMap.insert(series,domain);
59
59
60 series->d_ptr->scaleDomain(*domain);
60 series->d_ptr->scaleDomain(*domain);
61
61
62 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
62 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
63
63
64 int key=0;
64 int key=0;
65 while (i.hasNext()) {
65 while (i.hasNext()) {
66 i.next();
66 i.next();
67 if(i.key()!=key) {
67 if(i.key()!=key) {
68 break;
68 break;
69 }
69 }
70 key++;
70 key++;
71 }
71 }
72
72
73 m_indexSeriesMap.insert(key,series);
73 m_indexSeriesMap.insert(key,series);
74
74
75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
76 series->d_ptr->m_dataset = this;
76 series->d_ptr->m_dataset = this;
77
77
78 emit seriesAdded(series,domain);
78 emit seriesAdded(series,domain);
79
79
80 }
80 }
81
81
82 void ChartDataSet::createDefaultAxes()
82 void ChartDataSet::createDefaultAxes()
83 {
83 {
84
84
85 if(m_seriesDomainMap.isEmpty()) return;
85 if(m_seriesDomainMap.isEmpty()) return;
86
86
87 QAbstractAxis::AxisTypes typeX(0);
87 QAbstractAxis::AxisTypes typeX(0);
88 QAbstractAxis::AxisTypes typeY(0);
88 QAbstractAxis::AxisTypes typeY(0);
89
89
90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
91 while (i.hasNext()) {
91 while (i.hasNext()) {
92 i.next();
92 i.next();
93 removeAxes(i.key());
93 removeAxes(i.key());
94 }
94 }
95
95
96 i.toFront();
96 i.toFront();
97
97
98 while (i.hasNext()) {
98 while (i.hasNext()) {
99 i.next();
99 i.next();
100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
102 if(axisX) typeX&=axisX->type();
102 if(axisX) typeX&=axisX->type();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
104 if(axisY) typeY&=axisY->type();
104 if(axisY) typeY&=axisY->type();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
106 }
106 }
107
107
108
108
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
110 {
110 {
111 i.toFront();
111 i.toFront();
112 while (i.hasNext()) {
112 while (i.hasNext()) {
113 i.next();
113 i.next();
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
115 i.key()->d_ptr->initializeAxisX(axis);
115 i.key()->d_ptr->initializeAxisX(axis);
116 addAxisX(axis,i.key());
116 addAxisX(axis,i.key());
117 emit axisAdded(axis,i.value());
117 emit axisAdded(axis,i.value());
118 }
118 }
119
119
120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
122 i.toFront();
122 i.toFront();
123 while (i.hasNext()) {
123 while (i.hasNext()) {
124 i.next();
124 i.next();
125 i.key()->d_ptr->initializeAxisX(axis);
125 i.key()->d_ptr->initializeAxisX(axis);
126 addAxisX(axis,i.key());
126 addAxisX(axis,i.key());
127 }
127 }
128 emit axisAdded(axis,i.value());
128 emit axisAdded(axis,i.value());
129
129
130 }
130 }
131
131
132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
133 {
133 {
134 i.toFront();
134 i.toFront();
135 while (i.hasNext()) {
135 while (i.hasNext()) {
136 i.next();
136 i.next();
137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
138 i.key()->d_ptr->initializeAxisY(axis);
138 i.key()->d_ptr->initializeAxisY(axis);
139 addAxisY(axis,i.key());
139 addAxisY(axis,i.key());
140 emit axisAdded(axis,i.value());
140 emit axisAdded(axis,i.value());
141 }
141 }
142
142
143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
145 i.toFront();
145 i.toFront();
146 while (i.hasNext()) {
146 while (i.hasNext()) {
147 i.next();
147 i.next();
148 i.key()->d_ptr->initializeAxisY(axis);
148 i.key()->d_ptr->initializeAxisY(axis);
149 addAxisY(axis,i.key());
149 addAxisY(axis,i.key());
150 }
150 }
151 emit axisAdded(axis,i.value());
151 emit axisAdded(axis,i.value());
152
152
153 }
153 }
154 }
154 }
155
155
156
156
157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
158 {
158 {
159 QAbstractAxis* axis =0;
159 QAbstractAxis* axis =0;
160
160
161 switch(type) {
161 switch(type) {
162 case QAbstractAxis::AxisTypeValues:
162 case QAbstractAxis::AxisTypeValues:
163 axis = new QValuesAxis(this);
163 axis = new QValuesAxis(this);
164 break;
164 break;
165 case QAbstractAxis::AxisTypeCategories:
165 case QAbstractAxis::AxisTypeCategories:
166 axis = new QBarCategoriesAxis(this);
166 axis = new QBarCategoriesAxis(this);
167 break;
167 break;
168 default:
168 default:
169 axis = 0;
169 axis = 0;
170 break;
170 break;
171 }
171 }
172
172
173 return axis;
173 return axis;
174 }
174 }
175
175
176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
177 Domain* domain = m_seriesDomainMap.value(series);
177 Domain* domain = m_seriesDomainMap.value(series);
178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
180 axis->d_ptr->m_orientation=Qt::Horizontal;
180 axis->d_ptr->m_orientation=Qt::Horizontal;
181 m_seriesAxisXMap.insert(series,axis);
181 m_seriesAxisXMap.insert(series,axis);
182 }
182 }
183
183
184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
185 Domain* domain = m_seriesDomainMap.value(series);
185 Domain* domain = m_seriesDomainMap.value(series);
186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
188 axis->d_ptr->m_orientation=Qt::Vertical;
188 axis->d_ptr->m_orientation=Qt::Vertical;
189 m_seriesAxisYMap.insert(series,axis);
189 m_seriesAxisYMap.insert(series,axis);
190 }
190 }
191
191
192 void ChartDataSet::removeSeries(QAbstractSeries* series)
192 void ChartDataSet::removeSeries(QAbstractSeries* series)
193 {
193 {
194 Domain* domain = m_seriesDomainMap.take(series);
194 Domain* domain = m_seriesDomainMap.take(series);
195
195
196 if(!domain) {
196 if(!domain) {
197 qWarning()<<"Can not remove series. Series not found on the chart.";
197 qWarning()<<"Can not remove series. Series not found on the chart.";
198 }
198 }
199
199
200 emit seriesRemoved(series);
200 emit seriesRemoved(series);
201
201
202 delete domain;
202 delete domain;
203 domain = 0;
203 domain = 0;
204
204
205 int key = seriesIndex(series);
205 int key = seriesIndex(series);
206 Q_ASSERT(key!=-1);
206 Q_ASSERT(key!=-1);
207
207
208 m_indexSeriesMap.remove(key);
208 m_indexSeriesMap.remove(key);
209
209
210 series->setParent(0);
210 series->setParent(0);
211 series->d_ptr->m_chart = 0;
211 series->d_ptr->m_chart = 0;
212 series->d_ptr->m_dataset = 0;
212 series->d_ptr->m_dataset = 0;
213
213
214 removeAxes(series);
214 removeAxes(series);
215 }
215 }
216
216
217 void ChartDataSet::removeAxes(QAbstractSeries* series)
217 void ChartDataSet::removeAxes(QAbstractSeries* series)
218 {
218 {
219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
220
220
221 if(axisX) {
221 if(axisX) {
222 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
222 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
223 int x = axesX.indexOf(axisX);
223 int x = axesX.indexOf(axisX);
224
224
225 if(x==-1) {
225 if(x==-1) {
226 emit axisRemoved(axisX);
226 emit axisRemoved(axisX);
227 axisX->deleteLater();
227 axisX->deleteLater();
228 }
228 }
229 }
229 }
230
230
231 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
231 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
232
232
233 if(axisY) {
233 if(axisY) {
234 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
234 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
235
235
236 int y = axesY.indexOf(axisY);
236 int y = axesY.indexOf(axisY);
237
237
238 if(y==-1) {
238 if(y==-1) {
239 emit axisRemoved(axisY);
239 emit axisRemoved(axisY);
240 axisY->deleteLater();
240 axisY->deleteLater();
241 }
241 }
242 }
242 }
243 }
243 }
244
244
245 void ChartDataSet::removeAllSeries()
245 void ChartDataSet::removeAllSeries()
246 {
246 {
247 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
247 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
248 foreach(QAbstractSeries *s , series) {
248 foreach(QAbstractSeries *s , series) {
249 removeSeries(s);
249 removeSeries(s);
250 }
250 }
251
251
252 Q_ASSERT(m_seriesAxisXMap.count()==0);
252 Q_ASSERT(m_seriesAxisXMap.count()==0);
253 Q_ASSERT(m_seriesAxisXMap.count()==0);
253 Q_ASSERT(m_seriesAxisXMap.count()==0);
254 Q_ASSERT(m_seriesDomainMap.count()==0);
254 Q_ASSERT(m_seriesDomainMap.count()==0);
255
255
256 qDeleteAll(series);
256 qDeleteAll(series);
257 }
257 }
258
258
259 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
259 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
260 {
260 {
261 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
261 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
262
262
263 blockAxisSignals(true);
263 blockAxisSignals(true);
264
264
265 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
265 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
266
266
267 while (i.hasNext()) {
267 while (i.hasNext()) {
268 i.next();
268 i.next();
269 i.value()->zoomIn(rect,size);
269 i.value()->zoomIn(rect,size);
270 }
270 }
271
271
272 blockAxisSignals(false);
272 blockAxisSignals(false);
273
273
274 }
274 }
275
275
276 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
276 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
277 {
277 {
278 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
278 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
279
279
280 blockAxisSignals(true);
280 blockAxisSignals(true);
281
281
282 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
282 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
283
283
284 while (i.hasNext()) {
284 while (i.hasNext()) {
285 i.next();
285 i.next();
286 i.value()->zoomOut(rect,size);
286 i.value()->zoomOut(rect,size);
287 }
287 }
288
288
289 blockAxisSignals(false);
289 blockAxisSignals(false);
290 }
290 }
291
291
292 void ChartDataSet::blockAxisSignals(bool enabled)
292 void ChartDataSet::blockAxisSignals(bool enabled)
293 {
293 {
294 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
294 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
295
295
296 while (i.hasNext()) {
296 while (i.hasNext()) {
297 i.next();
297 i.next();
298 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
298 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
299 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
299 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
300 if(axisX) axisX->blockSignals(enabled);
300 if(axisX) axisX->blockSignals(enabled);
301 if(axisY) axisY->blockSignals(enabled);
301 if(axisY) axisY->blockSignals(enabled);
302 }
302 }
303 }
303 }
304
304
305 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
305 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
306 {
306 {
307 int count=0;
307 int count=0;
308 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
308 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
309 while (i.hasNext()) {
309 while (i.hasNext()) {
310 i.next();
310 i.next();
311 if(i.key()->type()==type) count++;
311 if(i.key()->type()==type) count++;
312 }
312 }
313 return count;
313 return count;
314 }
314 }
315
315
316 int ChartDataSet::seriesIndex(QAbstractSeries *series)
316 int ChartDataSet::seriesIndex(QAbstractSeries *series)
317 {
317 {
318 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
318 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
319 while (i.hasNext()) {
319 while (i.hasNext()) {
320 i.next();
320 i.next();
321 if (i.value() == series)
321 if (i.value() == series)
322 return i.key();
322 return i.key();
323 }
323 }
324 return -1;
324 return -1;
325 }
325 }
326
326
327 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
327 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
328 {
328 {
329 if(series == 0) return m_seriesAxisXMap.begin().value();
329 if(series == 0) return m_seriesAxisXMap.begin().value();
330 return m_seriesAxisXMap.value(series);
330 return m_seriesAxisXMap.value(series);
331 }
331 }
332
332
333 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
333 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
334 {
334 {
335 if(series == 0) return m_seriesAxisYMap.begin().value();
335 if(series == 0) return m_seriesAxisYMap.begin().value();
336 return m_seriesAxisYMap.value(series);
336 return m_seriesAxisYMap.value(series);
337 }
337 }
338
338
339 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
339 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
340 {
340 {
341 Q_ASSERT(axis);
341 Q_ASSERT(axis);
342 Domain* domain = m_seriesDomainMap.value(series);
342 Domain* domain = m_seriesDomainMap.value(series);
343
343
344 if(!domain) {
344 if(!domain) {
345 qWarning() << "Series not found on the chart.";
345 qWarning() << "Series not found on the chart.";
346 return;
346 return;
347 }
347 }
348
348
349 if(axis->d_ptr->m_orientation==Qt::Vertical) {
349 if(axis->d_ptr->m_orientation==Qt::Vertical) {
350 qWarning()<<"Axis already defined as axis Y";
350 qWarning()<<"Axis already defined as axis Y";
351 return;
351 return;
352 }
352 }
353
353
354 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
354 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
355 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
355 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
356
356
357 if(oldAxis) {
357 if(oldAxis) {
358
358
359 int x = axesX.indexOf(oldAxis);
359 int x = axesX.indexOf(oldAxis);
360 if(x==-1) {
360 if(x==-1) {
361 emit axisRemoved(oldAxis);
361 emit axisRemoved(oldAxis);
362 oldAxis->deleteLater();
362 oldAxis->deleteLater();
363 }
363 }
364 }
364 }
365
365
366 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
366 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
367 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
367 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
368
368
369 int x = axesX.indexOf(axis);
369 int x = axesX.indexOf(axis);
370 if(x==-1) {
370 if(x==-1) {
371 axis->d_ptr->m_orientation=Qt::Horizontal;
371 axis->d_ptr->m_orientation=Qt::Horizontal;
372 emit axisAdded(axis,domain);
372 emit axisAdded(axis,domain);
373 }
373 }
374
374
375 m_seriesAxisXMap.insert(series,axis);
375 m_seriesAxisXMap.insert(series,axis);
376 axis->d_ptr->emitRange();
376 axis->d_ptr->emitRange();
377 }
377 }
378
378
379 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
379 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
380 {
380 {
381 Q_ASSERT(axis);
381 Q_ASSERT(axis);
382 Domain* domain = m_seriesDomainMap.value(series);
382 Domain* domain = m_seriesDomainMap.value(series);
383
383
384 if(!domain) {
384 if(!domain) {
385 qWarning() << "Series not found on the chart.";
385 qWarning() << "Series not found on the chart.";
386 return;
386 return;
387 }
387 }
388
388
389 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
389 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
390 qWarning()<<"Axis already defined as axis X";
390 qWarning()<<"Axis already defined as axis X";
391 return;
391 return;
392 }
392 }
393
393
394 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
394 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
395 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
395 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
396
396
397 if(oldAxis) {
397 if(oldAxis) {
398 int y = axesY.indexOf(oldAxis);
398 int y = axesY.indexOf(oldAxis);
399 if(y==-1) {
399 if(y==-1) {
400 emit axisRemoved(oldAxis);
400 emit axisRemoved(oldAxis);
401 oldAxis->deleteLater();
401 oldAxis->deleteLater();
402 }
402 }
403 }
403 }
404
404
405 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
405 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
406 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
406 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
407
407
408 int y = axesY.indexOf(axis);
408 int y = axesY.indexOf(axis);
409 if(y==-1) {
409 if(y==-1) {
410 axis->d_ptr->m_orientation=Qt::Vertical;
410 axis->d_ptr->m_orientation=Qt::Vertical;
411 emit axisAdded(axis,domain);
411 emit axisAdded(axis,domain);
412 }
412 }
413
413
414 m_seriesAxisYMap.insert(series,axis);
414 m_seriesAxisYMap.insert(series,axis);
415 axis->d_ptr->emitRange();
415 axis->d_ptr->emitRange();
416 }
416 }
417
417
418 Domain* ChartDataSet::domain(QAbstractSeries *series) const
418 Domain* ChartDataSet::domain(QAbstractSeries *series) const
419 {
419 {
420 return m_seriesDomainMap.value(series);
420 return m_seriesDomainMap.value(series);
421 }
421 }
422
422
423 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
423 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
424 {
424 {
425 blockAxisSignals(true);
425 blockAxisSignals(true);
426 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
426 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
427 while (i.hasNext()) {
427 while (i.hasNext()) {
428 i.next();
428 i.next();
429 i.value()->move(dx,dy,size);
429 i.value()->move(dx,dy,size);
430 }
430 }
431 blockAxisSignals(false);
431 blockAxisSignals(false);
432 }
432 }
433
433
434 QList<QAbstractSeries*> ChartDataSet::series() const
434 QList<QAbstractSeries*> ChartDataSet::series() const
435 {
435 {
436 return m_seriesAxisXMap.keys();
436 return m_seriesAxisXMap.keys();
437 }
437 }
438
438
439 void ChartDataSet::updateSeries(QAbstractSeries *series)
439 void ChartDataSet::updateSeries(QAbstractSeries *series)
440 {
440 {
441 emit seriesUpdated(series);
441 emit seriesUpdated(series);
442 }
442 }
443
443
444 #include "moc_chartdataset_p.cpp"
444 #include "moc_chartdataset_p.cpp"
445
445
446 QTCOMMERCIALCHART_END_NAMESPACE
446 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,624 +1,624
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 <qabstractaxis.h>
22 #include <qabstractaxis.h>
23 #include <qvaluesaxis.h>
23 #include <qvaluesaxis.h>
24 #include <qcategoriesaxis.h>
24 #include <qbarcategoriesaxis.h>
25 #include <qlineseries.h>
25 #include <qlineseries.h>
26 #include <qareaseries.h>
26 #include <qareaseries.h>
27 #include <qscatterseries.h>
27 #include <qscatterseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qpieseries.h>
29 #include <qpieseries.h>
30 #include <qbarseries.h>
30 #include <qbarseries.h>
31 #include <qpercentbarseries.h>
31 #include <qpercentbarseries.h>
32 #include <qstackedbarseries.h>
32 #include <qstackedbarseries.h>
33 #include <private/chartdataset_p.h>
33 #include <private/chartdataset_p.h>
34 #include <private/domain_p.h>
34 #include <private/domain_p.h>
35 #include <tst_definitions.h>
35 #include <tst_definitions.h>
36
36
37 QTCOMMERCIALCHART_USE_NAMESPACE
37 QTCOMMERCIALCHART_USE_NAMESPACE
38
38
39 Q_DECLARE_METATYPE(Domain *)
39 Q_DECLARE_METATYPE(Domain *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
44 Q_DECLARE_METATYPE(QLineSeries *)
44 Q_DECLARE_METATYPE(QLineSeries *)
45
45
46 class tst_ChartDataSet: public QObject {
46 class tst_ChartDataSet: public QObject {
47
47
48 Q_OBJECT
48 Q_OBJECT
49
49
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void initTestCase();
51 void initTestCase();
52 void cleanupTestCase();
52 void cleanupTestCase();
53 void init();
53 void init();
54 void cleanup();
54 void cleanup();
55
55
56 private Q_SLOTS:
56 private Q_SLOTS:
57 void chartdataset_data();
57 void chartdataset_data();
58 void chartdataset();
58 void chartdataset();
59 void addSeries_data();
59 void addSeries_data();
60 void addSeries();
60 void addSeries();
61 void setAxisX_data();
61 void setAxisX_data();
62 void setAxisX();
62 void setAxisX();
63 void setAxisY_data();
63 void setAxisY_data();
64 void setAxisY();
64 void setAxisY();
65 void removeSeries_data();
65 void removeSeries_data();
66 void removeSeries();
66 void removeSeries();
67 void removeAllSeries_data();
67 void removeAllSeries_data();
68 void removeAllSeries();
68 void removeAllSeries();
69 void seriesCount_data();
69 void seriesCount_data();
70 void seriesCount();
70 void seriesCount();
71 void seriesIndex_data();
71 void seriesIndex_data();
72 void seriesIndex();
72 void seriesIndex();
73 void domain_data();
73 void domain_data();
74 void domain();
74 void domain();
75 void zoomInDomain_data();
75 void zoomInDomain_data();
76 void zoomInDomain();
76 void zoomInDomain();
77 void zoomOutDomain_data();
77 void zoomOutDomain_data();
78 void zoomOutDomain();
78 void zoomOutDomain();
79 void scrollDomain_data();
79 void scrollDomain_data();
80 void scrollDomain();
80 void scrollDomain();
81
81
82 private:
82 private:
83 ChartDataSet* m_dataset;
83 ChartDataSet* m_dataset;
84 };
84 };
85
85
86 void tst_ChartDataSet::initTestCase()
86 void tst_ChartDataSet::initTestCase()
87 {
87 {
88 qRegisterMetaType<Domain*>();
88 qRegisterMetaType<Domain*>();
89 qRegisterMetaType<QAbstractAxis*>();
89 qRegisterMetaType<QAbstractAxis*>();
90 qRegisterMetaType<QAbstractSeries*>();
90 qRegisterMetaType<QAbstractSeries*>();
91 }
91 }
92
92
93 void tst_ChartDataSet::cleanupTestCase()
93 void tst_ChartDataSet::cleanupTestCase()
94 {
94 {
95 }
95 }
96
96
97 void tst_ChartDataSet::init()
97 void tst_ChartDataSet::init()
98 {
98 {
99 m_dataset = new ChartDataSet();
99 m_dataset = new ChartDataSet();
100 }
100 }
101
101
102
102
103 void tst_ChartDataSet::cleanup()
103 void tst_ChartDataSet::cleanup()
104 {
104 {
105 QList<QAbstractSeries*> series = m_dataset->series();
105 QList<QAbstractSeries*> series = m_dataset->series();
106 foreach(QAbstractSeries* serie, series)
106 foreach(QAbstractSeries* serie, series)
107 {
107 {
108 m_dataset->removeSeries(serie);
108 m_dataset->removeSeries(serie);
109 }
109 }
110 }
110 }
111
111
112 void tst_ChartDataSet::chartdataset_data()
112 void tst_ChartDataSet::chartdataset_data()
113 {
113 {
114 }
114 }
115
115
116 void tst_ChartDataSet::chartdataset()
116 void tst_ChartDataSet::chartdataset()
117 {
117 {
118 QVERIFY(m_dataset->axisX(0) == 0);
118 QVERIFY(m_dataset->axisX(0) == 0);
119 QVERIFY(m_dataset->axisY(0) == 0);
119 QVERIFY(m_dataset->axisY(0) == 0);
120 QLineSeries* series = new QLineSeries(this);
120 QLineSeries* series = new QLineSeries(this);
121 QCOMPARE(m_dataset->seriesIndex(series),-1);
121 QCOMPARE(m_dataset->seriesIndex(series),-1);
122 QVERIFY(m_dataset->domain(series) == 0);
122 QVERIFY(m_dataset->domain(series) == 0);
123 QVERIFY(m_dataset->axisX(series) == 0);
123 QVERIFY(m_dataset->axisX(series) == 0);
124 QVERIFY(m_dataset->axisY(series) == 0);
124 QVERIFY(m_dataset->axisY(series) == 0);
125 m_dataset->createDefaultAxes();
125 m_dataset->createDefaultAxes();
126 }
126 }
127
127
128
128
129 void tst_ChartDataSet::addSeries_data()
129 void tst_ChartDataSet::addSeries_data()
130 {
130 {
131 QTest::addColumn<QAbstractSeries*>("series");
131 QTest::addColumn<QAbstractSeries*>("series");
132
132
133 QAbstractSeries* line = new QLineSeries(this);
133 QAbstractSeries* line = new QLineSeries(this);
134 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
134 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
135 QAbstractSeries* scatter = new QScatterSeries(this);
135 QAbstractSeries* scatter = new QScatterSeries(this);
136 QAbstractSeries* spline = new QSplineSeries(this);
136 QAbstractSeries* spline = new QSplineSeries(this);
137 QAbstractSeries* pie = new QPieSeries(this);
137 QAbstractSeries* pie = new QPieSeries(this);
138 QAbstractSeries* bar = new QBarSeries(this);
138 QAbstractSeries* bar = new QBarSeries(this);
139 QAbstractSeries* percent = new QPercentBarSeries(this);
139 QAbstractSeries* percent = new QPercentBarSeries(this);
140 QAbstractSeries* stacked = new QStackedBarSeries(this);
140 QAbstractSeries* stacked = new QStackedBarSeries(this);
141
141
142 QTest::newRow("line") << line;
142 QTest::newRow("line") << line;
143 QTest::newRow("area") << area;
143 QTest::newRow("area") << area;
144 QTest::newRow("scatter") << scatter;
144 QTest::newRow("scatter") << scatter;
145 QTest::newRow("spline") << spline;
145 QTest::newRow("spline") << spline;
146 QTest::newRow("pie") << pie;
146 QTest::newRow("pie") << pie;
147 QTest::newRow("bar") << bar;
147 QTest::newRow("bar") << bar;
148 QTest::newRow("percent") << percent;
148 QTest::newRow("percent") << percent;
149 QTest::newRow("stacked") << stacked;
149 QTest::newRow("stacked") << stacked;
150 }
150 }
151
151
152 void tst_ChartDataSet::addSeries()
152 void tst_ChartDataSet::addSeries()
153 {
153 {
154
154
155 QFETCH(QAbstractSeries*, series);
155 QFETCH(QAbstractSeries*, series);
156
156
157 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
157 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
158 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
158 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
159 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
159 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161
161
162 m_dataset->addSeries(series);
162 m_dataset->addSeries(series);
163 m_dataset->createDefaultAxes();
163 m_dataset->createDefaultAxes();
164 if(series->type()==QAbstractSeries::SeriesTypePie){
164 if(series->type()==QAbstractSeries::SeriesTypePie){
165 TRY_COMPARE(spy0.count(), 0);
165 TRY_COMPARE(spy0.count(), 0);
166 }else{
166 }else{
167 TRY_COMPARE(spy0.count(), 2);
167 TRY_COMPARE(spy0.count(), 2);
168 }
168 }
169 TRY_COMPARE(spy1.count(), 0);
169 TRY_COMPARE(spy1.count(), 0);
170 TRY_COMPARE(spy2.count(), 1);
170 TRY_COMPARE(spy2.count(), 1);
171 TRY_COMPARE(spy3.count(), 0);
171 TRY_COMPARE(spy3.count(), 0);
172 }
172 }
173
173
174
174
175 void tst_ChartDataSet::setAxisX_data()
175 void tst_ChartDataSet::setAxisX_data()
176 {
176 {
177
177
178 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
178 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
179 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
179 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
180 QTest::addColumn<int>("axisCount");
180 QTest::addColumn<int>("axisCount");
181
181
182 QAbstractSeries* line = new QLineSeries(this);
182 QAbstractSeries* line = new QLineSeries(this);
183 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
183 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
184 QAbstractSeries* scatter = new QScatterSeries(this);
184 QAbstractSeries* scatter = new QScatterSeries(this);
185 QAbstractSeries* spline = new QSplineSeries(this);
185 QAbstractSeries* spline = new QSplineSeries(this);
186 QAbstractSeries* pie = new QPieSeries(this);
186 QAbstractSeries* pie = new QPieSeries(this);
187 QAbstractSeries* bar = new QBarSeries(this);
187 QAbstractSeries* bar = new QBarSeries(this);
188 QAbstractSeries* percent = new QPercentBarSeries(this);
188 QAbstractSeries* percent = new QPercentBarSeries(this);
189 QAbstractSeries* stacked = new QStackedBarSeries(this);
189 QAbstractSeries* stacked = new QStackedBarSeries(this);
190
190
191 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
191 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
192 << (QList<QAbstractSeries*>() << line << spline << scatter)
192 << (QList<QAbstractSeries*>() << line << spline << scatter)
193 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
193 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
194
194
195 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
195 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
196 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
196 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
197
197
198 QList<QAbstractAxis*> axes0;
198 QList<QAbstractAxis*> axes0;
199 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
199 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
200 axes0 << axes0.last();
200 axes0 << axes0.last();
201 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
201 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
202 << (QList<QAbstractSeries*>() << line << spline << scatter)
202 << (QList<QAbstractSeries*>() << line << spline << scatter)
203 << axes0 << 2;
203 << axes0 << 2;
204 //TODO: add more test cases
204 //TODO: add more test cases
205 }
205 }
206
206
207 void tst_ChartDataSet::setAxisX()
207 void tst_ChartDataSet::setAxisX()
208 {
208 {
209 QFETCH(QList<QAbstractSeries*>, seriesList);
209 QFETCH(QList<QAbstractSeries*>, seriesList);
210 QFETCH(QList<QAbstractAxis*>, axisList);
210 QFETCH(QList<QAbstractAxis*>, axisList);
211 QFETCH(int, axisCount);
211 QFETCH(int, axisCount);
212
212
213 Q_ASSERT(seriesList.count() == axisList.count());
213 Q_ASSERT(seriesList.count() == axisList.count());
214
214
215 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
215 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
216 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
216 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
217 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
217 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
218 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
218 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
219
219
220 foreach(QAbstractSeries* series, seriesList){
220 foreach(QAbstractSeries* series, seriesList){
221 m_dataset->addSeries(series);
221 m_dataset->addSeries(series);
222 }
222 }
223
223
224 TRY_COMPARE(spy0.count(), 0);
224 TRY_COMPARE(spy0.count(), 0);
225 TRY_COMPARE(spy1.count(), 0);
225 TRY_COMPARE(spy1.count(), 0);
226 TRY_COMPARE(spy2.count(), seriesList.count());
226 TRY_COMPARE(spy2.count(), seriesList.count());
227 TRY_COMPARE(spy3.count(), 0);
227 TRY_COMPARE(spy3.count(), 0);
228
228
229 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
229 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
230 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
230 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
231 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
231 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
232 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
232 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
233
233
234 for(int i=0 ; i < seriesList.count(); i++){
234 for(int i=0 ; i < seriesList.count(); i++){
235 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
235 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
236 }
236 }
237
237
238 TRY_COMPARE(spy4.count(), axisCount);
238 TRY_COMPARE(spy4.count(), axisCount);
239 TRY_COMPARE(spy5.count(), 0);
239 TRY_COMPARE(spy5.count(), 0);
240 TRY_COMPARE(spy6.count(), 0);
240 TRY_COMPARE(spy6.count(), 0);
241 TRY_COMPARE(spy7.count(), 0);
241 TRY_COMPARE(spy7.count(), 0);
242
242
243 for(int i=0 ; i < seriesList.count(); i++){
243 for(int i=0 ; i < seriesList.count(); i++){
244 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
244 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
245 }
245 }
246 }
246 }
247
247
248 void tst_ChartDataSet::setAxisY_data()
248 void tst_ChartDataSet::setAxisY_data()
249 {
249 {
250 setAxisX_data();
250 setAxisX_data();
251 }
251 }
252
252
253 void tst_ChartDataSet::setAxisY()
253 void tst_ChartDataSet::setAxisY()
254 {
254 {
255 QFETCH(QList<QAbstractSeries*>, seriesList);
255 QFETCH(QList<QAbstractSeries*>, seriesList);
256 QFETCH(QList<QAbstractAxis*>, axisList);
256 QFETCH(QList<QAbstractAxis*>, axisList);
257 QFETCH(int, axisCount);
257 QFETCH(int, axisCount);
258
258
259 Q_ASSERT(seriesList.count() == axisList.count());
259 Q_ASSERT(seriesList.count() == axisList.count());
260
260
261 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
261 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
262 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
262 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
263 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
263 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
264 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
264 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
265
265
266 foreach(QAbstractSeries* series, seriesList){
266 foreach(QAbstractSeries* series, seriesList){
267 m_dataset->addSeries(series);
267 m_dataset->addSeries(series);
268 }
268 }
269
269
270 TRY_COMPARE(spy0.count(), 0);
270 TRY_COMPARE(spy0.count(), 0);
271 TRY_COMPARE(spy1.count(), 0);
271 TRY_COMPARE(spy1.count(), 0);
272 TRY_COMPARE(spy2.count(), seriesList.count());
272 TRY_COMPARE(spy2.count(), seriesList.count());
273 TRY_COMPARE(spy3.count(), 0);
273 TRY_COMPARE(spy3.count(), 0);
274
274
275 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
275 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
276 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
276 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
277 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
277 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
278 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
278 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
279
279
280 for(int i=0 ; i < seriesList.count(); i++){
280 for(int i=0 ; i < seriesList.count(); i++){
281 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
281 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
282 }
282 }
283
283
284 TRY_COMPARE(spy4.count(), axisCount);
284 TRY_COMPARE(spy4.count(), axisCount);
285 TRY_COMPARE(spy5.count(), 0);
285 TRY_COMPARE(spy5.count(), 0);
286 TRY_COMPARE(spy6.count(), 0);
286 TRY_COMPARE(spy6.count(), 0);
287 TRY_COMPARE(spy7.count(), 0);
287 TRY_COMPARE(spy7.count(), 0);
288
288
289 for(int i=0 ; i < seriesList.count(); i++){
289 for(int i=0 ; i < seriesList.count(); i++){
290 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
290 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
291 }
291 }
292 }
292 }
293
293
294 void tst_ChartDataSet::removeSeries_data()
294 void tst_ChartDataSet::removeSeries_data()
295 {
295 {
296 addSeries_data();
296 addSeries_data();
297 }
297 }
298
298
299 void tst_ChartDataSet::removeSeries()
299 void tst_ChartDataSet::removeSeries()
300 {
300 {
301 QFETCH(QAbstractSeries*, series);
301 QFETCH(QAbstractSeries*, series);
302
302
303 m_dataset->addSeries(series);
303 m_dataset->addSeries(series);
304 m_dataset->createDefaultAxes();
304 m_dataset->createDefaultAxes();
305
305
306 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
306 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
307 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
307 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
308 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
308 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
309 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
309 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
310
310
311 m_dataset->removeSeries(series);
311 m_dataset->removeSeries(series);
312
312
313 TRY_COMPARE(spy0.count(), 0);
313 TRY_COMPARE(spy0.count(), 0);
314 if (series->type() == QAbstractSeries::SeriesTypePie) {
314 if (series->type() == QAbstractSeries::SeriesTypePie) {
315 TRY_COMPARE(spy1.count(), 0);
315 TRY_COMPARE(spy1.count(), 0);
316 }
316 }
317 else {
317 else {
318 TRY_COMPARE(spy1.count(), 2);
318 TRY_COMPARE(spy1.count(), 2);
319 }
319 }
320 TRY_COMPARE(spy2.count(), 0);
320 TRY_COMPARE(spy2.count(), 0);
321 TRY_COMPARE(spy3.count(), 1);
321 TRY_COMPARE(spy3.count(), 1);
322 }
322 }
323
323
324 void tst_ChartDataSet::removeAllSeries_data()
324 void tst_ChartDataSet::removeAllSeries_data()
325 {
325 {
326 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
326 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
327 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
327 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
328 QTest::addColumn<int>("axisCount");
328 QTest::addColumn<int>("axisCount");
329
329
330 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
330 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
331 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
331 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
332 << new QScatterSeries(this))
332 << new QScatterSeries(this))
333 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
333 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
334 << new QValuesAxis(this)) << 3;
334 << new QValuesAxis(this)) << 3;
335 //TODO:
335 //TODO:
336 }
336 }
337
337
338 void tst_ChartDataSet::removeAllSeries()
338 void tst_ChartDataSet::removeAllSeries()
339 {
339 {
340 QFETCH(QList<QAbstractSeries*>, seriesList);
340 QFETCH(QList<QAbstractSeries*>, seriesList);
341 QFETCH(QList<QAbstractAxis*>, axisList);
341 QFETCH(QList<QAbstractAxis*>, axisList);
342 QFETCH(int, axisCount);
342 QFETCH(int, axisCount);
343
343
344 foreach(QAbstractSeries* series, seriesList) {
344 foreach(QAbstractSeries* series, seriesList) {
345 m_dataset->addSeries(series);
345 m_dataset->addSeries(series);
346 }
346 }
347
347
348 for (int i = 0; i < seriesList.count(); i++) {
348 for (int i = 0; i < seriesList.count(); i++) {
349 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
349 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
350 }
350 }
351
351
352 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
352 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
353 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
353 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
354 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
354 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
355 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
355 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
356
356
357 m_dataset->removeAllSeries();
357 m_dataset->removeAllSeries();
358
358
359 TRY_COMPARE(spy0.count(), 0);
359 TRY_COMPARE(spy0.count(), 0);
360 TRY_COMPARE(spy1.count(), axisCount);
360 TRY_COMPARE(spy1.count(), axisCount);
361 TRY_COMPARE(spy2.count(), 0);
361 TRY_COMPARE(spy2.count(), 0);
362 TRY_COMPARE(spy3.count(), seriesList.count());
362 TRY_COMPARE(spy3.count(), seriesList.count());
363 }
363 }
364
364
365
365
366 void tst_ChartDataSet::seriesCount_data()
366 void tst_ChartDataSet::seriesCount_data()
367 {
367 {
368 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
368 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
369 QTest::addColumn<int>("seriesCount");
369 QTest::addColumn<int>("seriesCount");
370
370
371 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
371 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
372 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
372 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
373 }
373 }
374
374
375 void tst_ChartDataSet::seriesCount()
375 void tst_ChartDataSet::seriesCount()
376 {
376 {
377 QFETCH(QList<QAbstractSeries*>, seriesList);
377 QFETCH(QList<QAbstractSeries*>, seriesList);
378 QFETCH(int, seriesCount);
378 QFETCH(int, seriesCount);
379
379
380 foreach(QAbstractSeries* series, seriesList){
380 foreach(QAbstractSeries* series, seriesList){
381 m_dataset->addSeries(series);
381 m_dataset->addSeries(series);
382 }
382 }
383
383
384 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
384 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
385 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
385 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
386 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
386 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
387 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
387 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
388
388
389 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
389 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
390 TRY_COMPARE(spy0.count(), 0);
390 TRY_COMPARE(spy0.count(), 0);
391 TRY_COMPARE(spy1.count(), 0);
391 TRY_COMPARE(spy1.count(), 0);
392 TRY_COMPARE(spy2.count(), 0);
392 TRY_COMPARE(spy2.count(), 0);
393 TRY_COMPARE(spy3.count(), 0);
393 TRY_COMPARE(spy3.count(), 0);
394 }
394 }
395
395
396 void tst_ChartDataSet::seriesIndex_data()
396 void tst_ChartDataSet::seriesIndex_data()
397 {
397 {
398 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
398 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
399
399
400 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
400 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
401 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
401 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
402 }
402 }
403
403
404 void tst_ChartDataSet::seriesIndex()
404 void tst_ChartDataSet::seriesIndex()
405 {
405 {
406
406
407 QFETCH(QList<QAbstractSeries*>, seriesList);
407 QFETCH(QList<QAbstractSeries*>, seriesList);
408
408
409 foreach(QAbstractSeries* series, seriesList) {
409 foreach(QAbstractSeries* series, seriesList) {
410 m_dataset->addSeries(series);
410 m_dataset->addSeries(series);
411 }
411 }
412
412
413 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
413 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
414 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
414 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
415 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
415 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
416 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
416 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
417
417
418 for (int i = 0; i < seriesList.count(); i++) {
418 for (int i = 0; i < seriesList.count(); i++) {
419 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
419 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
420 }
420 }
421
421
422 TRY_COMPARE(spy0.count(), 0);
422 TRY_COMPARE(spy0.count(), 0);
423 TRY_COMPARE(spy1.count(), 0);
423 TRY_COMPARE(spy1.count(), 0);
424 TRY_COMPARE(spy2.count(), 0);
424 TRY_COMPARE(spy2.count(), 0);
425 TRY_COMPARE(spy3.count(), 0);
425 TRY_COMPARE(spy3.count(), 0);
426
426
427 foreach(QAbstractSeries* series, seriesList) {
427 foreach(QAbstractSeries* series, seriesList) {
428 m_dataset->removeSeries(series);
428 m_dataset->removeSeries(series);
429 }
429 }
430
430
431 for (int i = 0; i < seriesList.count(); i++) {
431 for (int i = 0; i < seriesList.count(); i++) {
432 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
432 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
433 }
433 }
434
434
435 foreach(QAbstractSeries* series, seriesList) {
435 foreach(QAbstractSeries* series, seriesList) {
436 m_dataset->addSeries(series);
436 m_dataset->addSeries(series);
437 }
437 }
438
438
439 for (int i = 0; i < seriesList.count(); i++) {
439 for (int i = 0; i < seriesList.count(); i++) {
440 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
440 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
441 }
441 }
442
442
443 m_dataset->removeSeries(seriesList.at(1));
443 m_dataset->removeSeries(seriesList.at(1));
444
444
445 for (int i = 0; i < seriesList.count(); i++) {
445 for (int i = 0; i < seriesList.count(); i++) {
446 if (i != 1)
446 if (i != 1)
447 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
447 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
448 else
448 else
449 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
449 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
450 }
450 }
451
451
452 m_dataset->addSeries(seriesList.at(1));
452 m_dataset->addSeries(seriesList.at(1));
453
453
454 for (int i = 0; i < seriesList.count(); i++) {
454 for (int i = 0; i < seriesList.count(); i++) {
455 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
455 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
456 }
456 }
457
457
458 m_dataset->removeSeries(seriesList.at(2));
458 m_dataset->removeSeries(seriesList.at(2));
459
459
460 for (int i = 0; i < seriesList.count(); i++) {
460 for (int i = 0; i < seriesList.count(); i++) {
461 if (i != 2)
461 if (i != 2)
462 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
462 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
463 else
463 else
464 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
464 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
465 }
465 }
466
466
467 m_dataset->removeSeries(seriesList.at(0));
467 m_dataset->removeSeries(seriesList.at(0));
468
468
469 for (int i = 0; i < seriesList.count(); i++) {
469 for (int i = 0; i < seriesList.count(); i++) {
470 if (i != 2 && i != 0)
470 if (i != 2 && i != 0)
471 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
471 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
472 else
472 else
473 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
473 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
474 }
474 }
475
475
476 m_dataset->addSeries(seriesList.at(2));
476 m_dataset->addSeries(seriesList.at(2));
477 m_dataset->addSeries(seriesList.at(0));
477 m_dataset->addSeries(seriesList.at(0));
478
478
479 for (int i = 0; i < seriesList.count(); i++) {
479 for (int i = 0; i < seriesList.count(); i++) {
480 if (i == 2)
480 if (i == 2)
481 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
481 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
482 else if (i == 0)
482 else if (i == 0)
483 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
483 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
484 else
484 else
485 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
485 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
486 }
486 }
487
487
488 }
488 }
489
489
490 void tst_ChartDataSet::domain_data()
490 void tst_ChartDataSet::domain_data()
491 {
491 {
492 addSeries_data();
492 addSeries_data();
493 }
493 }
494
494
495 void tst_ChartDataSet::domain()
495 void tst_ChartDataSet::domain()
496 {
496 {
497 QFETCH(QAbstractSeries*, series);
497 QFETCH(QAbstractSeries*, series);
498
498
499 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
499 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
500 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
500 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
501 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
501 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
502 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
502 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
503
503
504 m_dataset->addSeries(series);
504 m_dataset->addSeries(series);
505 QVERIFY(m_dataset->domain(series));
505 QVERIFY(m_dataset->domain(series));
506
506
507
507
508 TRY_COMPARE(spy0.count(), 0);
508 TRY_COMPARE(spy0.count(), 0);
509 TRY_COMPARE(spy1.count(), 0);
509 TRY_COMPARE(spy1.count(), 0);
510 TRY_COMPARE(spy2.count(), 1);
510 TRY_COMPARE(spy2.count(), 1);
511
511
512 QList<QVariant> arguments = spy2.takeFirst();
512 QList<QVariant> arguments = spy2.takeFirst();
513 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
513 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
514 QVERIFY(m_dataset->domain(series) == domain);
514 QVERIFY(m_dataset->domain(series) == domain);
515
515
516 TRY_COMPARE(spy3.count(), 0);
516 TRY_COMPARE(spy3.count(), 0);
517
517
518 }
518 }
519
519
520 void tst_ChartDataSet::zoomInDomain_data()
520 void tst_ChartDataSet::zoomInDomain_data()
521 {
521 {
522 QTest::addColumn<bool >("sameAxis");
522 QTest::addColumn<bool >("sameAxis");
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
524 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
526 }
526 }
527
527
528 void tst_ChartDataSet::zoomInDomain()
528 void tst_ChartDataSet::zoomInDomain()
529 {
529 {
530 QFETCH(bool, sameAxis);
530 QFETCH(bool, sameAxis);
531 QFETCH(QList<QAbstractSeries*>, seriesList);
531 QFETCH(QList<QAbstractSeries*>, seriesList);
532
532
533 foreach(QAbstractSeries* series, seriesList) {
533 foreach(QAbstractSeries* series, seriesList) {
534 m_dataset->addSeries(series);
534 m_dataset->addSeries(series);
535 }
535 }
536
536
537 if(sameAxis) m_dataset->createDefaultAxes();
537 if(sameAxis) m_dataset->createDefaultAxes();
538
538
539 QList<QSignalSpy*> spyList;
539 QList<QSignalSpy*> spyList;
540
540
541 foreach(QAbstractSeries* series, seriesList) {
541 foreach(QAbstractSeries* series, seriesList) {
542 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
542 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
543 }
543 }
544
544
545 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
545 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
546
546
547 foreach(QSignalSpy* spy, spyList) {
547 foreach(QSignalSpy* spy, spyList) {
548 TRY_COMPARE(spy->count(), 1);
548 TRY_COMPARE(spy->count(), 1);
549 }
549 }
550
550
551 qDeleteAll(spyList);
551 qDeleteAll(spyList);
552 }
552 }
553
553
554
554
555
555
556 void tst_ChartDataSet::zoomOutDomain_data()
556 void tst_ChartDataSet::zoomOutDomain_data()
557 {
557 {
558 zoomInDomain_data();
558 zoomInDomain_data();
559 }
559 }
560
560
561 void tst_ChartDataSet::zoomOutDomain()
561 void tst_ChartDataSet::zoomOutDomain()
562 {
562 {
563 QFETCH(bool, sameAxis);
563 QFETCH(bool, sameAxis);
564 QFETCH(QList<QAbstractSeries*>, seriesList);
564 QFETCH(QList<QAbstractSeries*>, seriesList);
565
565
566 foreach(QAbstractSeries* series, seriesList) {
566 foreach(QAbstractSeries* series, seriesList) {
567 m_dataset->addSeries(series);
567 m_dataset->addSeries(series);
568 }
568 }
569
569
570 if (sameAxis)
570 if (sameAxis)
571 m_dataset->createDefaultAxes();
571 m_dataset->createDefaultAxes();
572
572
573 QList<QSignalSpy*> spyList;
573 QList<QSignalSpy*> spyList;
574
574
575 foreach(QAbstractSeries* series, seriesList) {
575 foreach(QAbstractSeries* series, seriesList) {
576 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
576 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
577 }
577 }
578
578
579 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
579 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
580
580
581 foreach(QSignalSpy* spy, spyList) {
581 foreach(QSignalSpy* spy, spyList) {
582 TRY_COMPARE(spy->count(), 1);
582 TRY_COMPARE(spy->count(), 1);
583 }
583 }
584
584
585 qDeleteAll (spyList);
585 qDeleteAll (spyList);
586 }
586 }
587
587
588 void tst_ChartDataSet::scrollDomain_data()
588 void tst_ChartDataSet::scrollDomain_data()
589 {
589 {
590 zoomInDomain_data();
590 zoomInDomain_data();
591 }
591 }
592
592
593 void tst_ChartDataSet::scrollDomain()
593 void tst_ChartDataSet::scrollDomain()
594 {
594 {
595 QFETCH(bool, sameAxis);
595 QFETCH(bool, sameAxis);
596 QFETCH(QList<QAbstractSeries*>, seriesList);
596 QFETCH(QList<QAbstractSeries*>, seriesList);
597
597
598 foreach(QAbstractSeries* series, seriesList) {
598 foreach(QAbstractSeries* series, seriesList) {
599 m_dataset->addSeries(series);
599 m_dataset->addSeries(series);
600 }
600 }
601
601
602 if (sameAxis)
602 if (sameAxis)
603 m_dataset->createDefaultAxes();
603 m_dataset->createDefaultAxes();
604
604
605 QList<QSignalSpy*> spyList;
605 QList<QSignalSpy*> spyList;
606
606
607 foreach(QAbstractSeries* series, seriesList) {
607 foreach(QAbstractSeries* series, seriesList) {
608 spyList
608 spyList
609 << new QSignalSpy(m_dataset->domain(series),
609 << new QSignalSpy(m_dataset->domain(series),
610 SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
610 SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
611 }
611 }
612
612
613 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
613 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
614
614
615 foreach(QSignalSpy* spy, spyList) {
615 foreach(QSignalSpy* spy, spyList) {
616 TRY_COMPARE(spy->count(), 1);
616 TRY_COMPARE(spy->count(), 1);
617 }
617 }
618
618
619 qDeleteAll(spyList);
619 qDeleteAll(spyList);
620 }
620 }
621
621
622 QTEST_MAIN(tst_ChartDataSet)
622 QTEST_MAIN(tst_ChartDataSet)
623 #include "tst_chartdataset.moc"
623 #include "tst_chartdataset.moc"
624
624
@@ -1,357 +1,357
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 "mainwidget.h"
21 #include "mainwidget.h"
22 #include "dataseriedialog.h"
22 #include "dataseriedialog.h"
23 #include "qchartview.h"
23 #include "qchartview.h"
24 #include "qpieseries.h"
24 #include "qpieseries.h"
25 #include "qscatterseries.h"
25 #include "qscatterseries.h"
26 #include "qlineseries.h"
26 #include "qlineseries.h"
27 #include <qareaseries.h>
27 #include <qareaseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qbarset.h>
29 #include <qbarset.h>
30 #include <qbarseries.h>
30 #include <qbarseries.h>
31 #include <qstackedbarseries.h>
31 #include <qstackedbarseries.h>
32 #include <qpercentbarseries.h>
32 #include <qpercentbarseries.h>
33 #include <QPushButton>
33 #include <QPushButton>
34 #include <QComboBox>
34 #include <QComboBox>
35 #include <QSpinBox>
35 #include <QSpinBox>
36 #include <QCheckBox>
36 #include <QCheckBox>
37 #include <QGridLayout>
37 #include <QGridLayout>
38 #include <QHBoxLayout>
38 #include <QHBoxLayout>
39 #include <QLabel>
39 #include <QLabel>
40 #include <QSpacerItem>
40 #include <QSpacerItem>
41 #include <QMessageBox>
41 #include <QMessageBox>
42 #include <cmath>
42 #include <cmath>
43 #include <QDebug>
43 #include <QDebug>
44 #include <QStandardItemModel>
44 #include <QStandardItemModel>
45 #include <QCategoriesAxis>
45 #include <QBarCategoriesAxis>
46
46
47
47
48 QTCOMMERCIALCHART_USE_NAMESPACE
48 QTCOMMERCIALCHART_USE_NAMESPACE
49
49
50 MainWidget::MainWidget(QWidget *parent) :
50 MainWidget::MainWidget(QWidget *parent) :
51 QWidget(parent),
51 QWidget(parent),
52 m_addSerieDialog(0),
52 m_addSerieDialog(0),
53 m_chart(0)
53 m_chart(0)
54 {
54 {
55 m_chart = new QChart();
55 m_chart = new QChart();
56
56
57 // Grid layout for the controls for configuring the chart widget
57 // Grid layout for the controls for configuring the chart widget
58 QGridLayout *grid = new QGridLayout();
58 QGridLayout *grid = new QGridLayout();
59 QPushButton *addSeriesButton = new QPushButton("Add series");
59 QPushButton *addSeriesButton = new QPushButton("Add series");
60 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
60 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
61 grid->addWidget(addSeriesButton, 0, 1);
61 grid->addWidget(addSeriesButton, 0, 1);
62 initBackroundCombo(grid);
62 initBackroundCombo(grid);
63 initScaleControls(grid);
63 initScaleControls(grid);
64 initThemeCombo(grid);
64 initThemeCombo(grid);
65 initCheckboxes(grid);
65 initCheckboxes(grid);
66
66
67 // add row with empty label to make all the other rows static
67 // add row with empty label to make all the other rows static
68 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
68 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
69 grid->setRowStretch(grid->rowCount() - 1, 1);
69 grid->setRowStretch(grid->rowCount() - 1, 1);
70
70
71 // Create chart view with the chart
71 // Create chart view with the chart
72 m_chartView = new QChartView(m_chart, this);
72 m_chartView = new QChartView(m_chart, this);
73 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
73 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
74
74
75 // Another grid layout as a main layout
75 // Another grid layout as a main layout
76 QGridLayout *mainLayout = new QGridLayout();
76 QGridLayout *mainLayout = new QGridLayout();
77 mainLayout->addLayout(grid, 0, 0);
77 mainLayout->addLayout(grid, 0, 0);
78 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
78 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
79 setLayout(mainLayout);
79 setLayout(mainLayout);
80 }
80 }
81
81
82 // Combo box for selecting the chart's background
82 // Combo box for selecting the chart's background
83 void MainWidget::initBackroundCombo(QGridLayout *grid)
83 void MainWidget::initBackroundCombo(QGridLayout *grid)
84 {
84 {
85 QComboBox *backgroundCombo = new QComboBox(this);
85 QComboBox *backgroundCombo = new QComboBox(this);
86 backgroundCombo->addItem("Color");
86 backgroundCombo->addItem("Color");
87 backgroundCombo->addItem("Gradient");
87 backgroundCombo->addItem("Gradient");
88 backgroundCombo->addItem("Image");
88 backgroundCombo->addItem("Image");
89 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
89 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
90 this, SLOT(backgroundChanged(int)));
90 this, SLOT(backgroundChanged(int)));
91
91
92 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
92 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
93 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
93 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
94 }
94 }
95
95
96 // Scale related controls (auto-scale vs. manual min-max values)
96 // Scale related controls (auto-scale vs. manual min-max values)
97 void MainWidget::initScaleControls(QGridLayout *grid)
97 void MainWidget::initScaleControls(QGridLayout *grid)
98 {
98 {
99 m_autoScaleCheck = new QCheckBox("Automatic scaling");
99 m_autoScaleCheck = new QCheckBox("Automatic scaling");
100 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
100 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
101 // Allow setting also non-sense values (like -2147483648 and 2147483647)
101 // Allow setting also non-sense values (like -2147483648 and 2147483647)
102 m_xMinSpin = new QSpinBox();
102 m_xMinSpin = new QSpinBox();
103 m_xMinSpin->setMinimum(INT_MIN);
103 m_xMinSpin->setMinimum(INT_MIN);
104 m_xMinSpin->setMaximum(INT_MAX);
104 m_xMinSpin->setMaximum(INT_MAX);
105 m_xMinSpin->setValue(0);
105 m_xMinSpin->setValue(0);
106 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
106 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
107 m_xMaxSpin = new QSpinBox();
107 m_xMaxSpin = new QSpinBox();
108 m_xMaxSpin->setMinimum(INT_MIN);
108 m_xMaxSpin->setMinimum(INT_MIN);
109 m_xMaxSpin->setMaximum(INT_MAX);
109 m_xMaxSpin->setMaximum(INT_MAX);
110 m_xMaxSpin->setValue(10);
110 m_xMaxSpin->setValue(10);
111 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
111 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
112 m_yMinSpin = new QSpinBox();
112 m_yMinSpin = new QSpinBox();
113 m_yMinSpin->setMinimum(INT_MIN);
113 m_yMinSpin->setMinimum(INT_MIN);
114 m_yMinSpin->setMaximum(INT_MAX);
114 m_yMinSpin->setMaximum(INT_MAX);
115 m_yMinSpin->setValue(0);
115 m_yMinSpin->setValue(0);
116 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
116 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
117 m_yMaxSpin = new QSpinBox();
117 m_yMaxSpin = new QSpinBox();
118 m_yMaxSpin->setMinimum(INT_MIN);
118 m_yMaxSpin->setMinimum(INT_MIN);
119 m_yMaxSpin->setMaximum(INT_MAX);
119 m_yMaxSpin->setMaximum(INT_MAX);
120 m_yMaxSpin->setValue(10);
120 m_yMaxSpin->setValue(10);
121 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
121 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
122
122
123 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
123 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
124 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
124 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
125 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
125 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
126 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
126 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
127 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
127 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
128 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
128 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
129 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
129 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
130 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
130 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
131 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
131 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
132
132
133 m_autoScaleCheck->setChecked(true);
133 m_autoScaleCheck->setChecked(true);
134 }
134 }
135
135
136 // Combo box for selecting theme
136 // Combo box for selecting theme
137 void MainWidget::initThemeCombo(QGridLayout *grid)
137 void MainWidget::initThemeCombo(QGridLayout *grid)
138 {
138 {
139 QComboBox *chartTheme = new QComboBox();
139 QComboBox *chartTheme = new QComboBox();
140 chartTheme->addItem("Default");
140 chartTheme->addItem("Default");
141 chartTheme->addItem("Light");
141 chartTheme->addItem("Light");
142 chartTheme->addItem("Blue Cerulean");
142 chartTheme->addItem("Blue Cerulean");
143 chartTheme->addItem("Dark");
143 chartTheme->addItem("Dark");
144 chartTheme->addItem("Brown Sand");
144 chartTheme->addItem("Brown Sand");
145 chartTheme->addItem("Blue NCS");
145 chartTheme->addItem("Blue NCS");
146 chartTheme->addItem("High Contrast");
146 chartTheme->addItem("High Contrast");
147 chartTheme->addItem("Blue Icy");
147 chartTheme->addItem("Blue Icy");
148 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
148 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
149 this, SLOT(changeChartTheme(int)));
149 this, SLOT(changeChartTheme(int)));
150 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
150 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
151 grid->addWidget(chartTheme, 8, 1);
151 grid->addWidget(chartTheme, 8, 1);
152 }
152 }
153
153
154 // Different check boxes for customizing chart
154 // Different check boxes for customizing chart
155 void MainWidget::initCheckboxes(QGridLayout *grid)
155 void MainWidget::initCheckboxes(QGridLayout *grid)
156 {
156 {
157 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
157 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
158 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
158 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
159 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
159 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
160 zoomCheckBox->setChecked(true);
160 zoomCheckBox->setChecked(true);
161 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
161 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
162
162
163 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
163 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
164 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
164 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
165 aliasCheckBox->setChecked(false);
165 aliasCheckBox->setChecked(false);
166 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
166 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
167 }
167 }
168
168
169 void MainWidget::antiAliasToggled(bool enabled)
169 void MainWidget::antiAliasToggled(bool enabled)
170 {
170 {
171 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
171 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
172 }
172 }
173
173
174 void MainWidget::addSeries()
174 void MainWidget::addSeries()
175 {
175 {
176 if (!m_addSerieDialog) {
176 if (!m_addSerieDialog) {
177 m_addSerieDialog = new DataSerieDialog(this);
177 m_addSerieDialog = new DataSerieDialog(this);
178 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
178 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
179 this, SLOT(addSeries(QString,int,int,QString,bool)));
179 this, SLOT(addSeries(QString,int,int,QString,bool)));
180 }
180 }
181 m_addSerieDialog->exec();
181 m_addSerieDialog->exec();
182 }
182 }
183
183
184 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
184 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
185 {
185 {
186 // TODO: dataCharacteristics
186 // TODO: dataCharacteristics
187 QList<RealList> testData;
187 QList<RealList> testData;
188 for (int j(0); j < columnCount; j++) {
188 for (int j(0); j < columnCount; j++) {
189 QList <qreal> newColumn;
189 QList <qreal> newColumn;
190 for (int i(0); i < rowCount; i++) {
190 for (int i(0); i < rowCount; i++) {
191 if (dataCharacteristics == "Sin") {
191 if (dataCharacteristics == "Sin") {
192 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
192 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
193 } else if (dataCharacteristics == "Sin + random") {
193 } else if (dataCharacteristics == "Sin + random") {
194 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
194 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
195 } else if (dataCharacteristics == "Random") {
195 } else if (dataCharacteristics == "Random") {
196 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
196 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
197 } else if (dataCharacteristics == "Linear") {
197 } else if (dataCharacteristics == "Linear") {
198 //newColumn.append(i * (j + 1.0));
198 //newColumn.append(i * (j + 1.0));
199 // TODO: temporary hack to make pie work; prevent zero values:
199 // TODO: temporary hack to make pie work; prevent zero values:
200 newColumn.append(i * (j + 1.0) + 0.1);
200 newColumn.append(i * (j + 1.0) + 0.1);
201 } else { // "constant"
201 } else { // "constant"
202 newColumn.append((j + 1.0));
202 newColumn.append((j + 1.0));
203 }
203 }
204 }
204 }
205 testData.append(newColumn);
205 testData.append(newColumn);
206 }
206 }
207 return testData;
207 return testData;
208 }
208 }
209
209
210 QStringList MainWidget::generateLabels(int count)
210 QStringList MainWidget::generateLabels(int count)
211 {
211 {
212 QStringList result;
212 QStringList result;
213 for (int i(0); i < count; i++)
213 for (int i(0); i < count; i++)
214 result.append("label" + QString::number(i));
214 result.append("label" + QString::number(i));
215 return result;
215 return result;
216 }
216 }
217
217
218 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
218 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
219 {
219 {
220 qDebug() << "addSeries: " << seriesName
220 qDebug() << "addSeries: " << seriesName
221 << " columnCount: " << columnCount
221 << " columnCount: " << columnCount
222 << " rowCount: " << rowCount
222 << " rowCount: " << rowCount
223 << " dataCharacteristics: " << dataCharacteristics
223 << " dataCharacteristics: " << dataCharacteristics
224 << " labels enabled: " << labelsEnabled;
224 << " labels enabled: " << labelsEnabled;
225 m_defaultSeriesName = seriesName;
225 m_defaultSeriesName = seriesName;
226
226
227 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
227 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
228
228
229 // Line series and scatter series use similar data
229 // Line series and scatter series use similar data
230 if (seriesName == "Line") {
230 if (seriesName == "Line") {
231 for (int j(0); j < data.count(); j ++) {
231 for (int j(0); j < data.count(); j ++) {
232 QList<qreal> column = data.at(j);
232 QList<qreal> column = data.at(j);
233 QLineSeries *series = new QLineSeries();
233 QLineSeries *series = new QLineSeries();
234 series->setName("line" + QString::number(j));
234 series->setName("line" + QString::number(j));
235 for (int i(0); i < column.count(); i++)
235 for (int i(0); i < column.count(); i++)
236 series->append(i, column.at(i));
236 series->append(i, column.at(i));
237 m_chart->addSeries(series);
237 m_chart->addSeries(series);
238 }
238 }
239 } else if (seriesName == "Area") {
239 } else if (seriesName == "Area") {
240 // TODO: lower series for the area?
240 // TODO: lower series for the area?
241 for (int j(0); j < data.count(); j ++) {
241 for (int j(0); j < data.count(); j ++) {
242 QList<qreal> column = data.at(j);
242 QList<qreal> column = data.at(j);
243 QLineSeries *lineSeries = new QLineSeries();
243 QLineSeries *lineSeries = new QLineSeries();
244 for (int i(0); i < column.count(); i++)
244 for (int i(0); i < column.count(); i++)
245 lineSeries->append(i, column.at(i));
245 lineSeries->append(i, column.at(i));
246 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
246 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
247 areaSeries->setName("area" + QString::number(j));
247 areaSeries->setName("area" + QString::number(j));
248 m_chart->addSeries(areaSeries);
248 m_chart->addSeries(areaSeries);
249 }
249 }
250 } else if (seriesName == "Scatter") {
250 } else if (seriesName == "Scatter") {
251 for (int j(0); j < data.count(); j++) {
251 for (int j(0); j < data.count(); j++) {
252 QList<qreal> column = data.at(j);
252 QList<qreal> column = data.at(j);
253 QScatterSeries *series = new QScatterSeries();
253 QScatterSeries *series = new QScatterSeries();
254 series->setName("scatter" + QString::number(j));
254 series->setName("scatter" + QString::number(j));
255 for (int i(0); i < column.count(); i++)
255 for (int i(0); i < column.count(); i++)
256 series->append(i, column.at(i));
256 series->append(i, column.at(i));
257 m_chart->addSeries(series);
257 m_chart->addSeries(series);
258 }
258 }
259 } else if (seriesName == "Pie") {
259 } else if (seriesName == "Pie") {
260 QStringList labels = generateLabels(rowCount);
260 QStringList labels = generateLabels(rowCount);
261 for (int j(0); j < data.count(); j++) {
261 for (int j(0); j < data.count(); j++) {
262 QPieSeries *series = new QPieSeries();
262 QPieSeries *series = new QPieSeries();
263 QList<qreal> column = data.at(j);
263 QList<qreal> column = data.at(j);
264 for (int i(0); i < column.count(); i++)
264 for (int i(0); i < column.count(); i++)
265 series->append(labels.at(i), column.at(i));
265 series->append(labels.at(i), column.at(i));
266 m_chart->addSeries(series);
266 m_chart->addSeries(series);
267 }
267 }
268 } else if (seriesName == "Bar"
268 } else if (seriesName == "Bar"
269 || seriesName == "Stacked bar"
269 || seriesName == "Stacked bar"
270 || seriesName == "Percent bar") {
270 || seriesName == "Percent bar") {
271 QStringList category;
271 QStringList category;
272 QStringList labels = generateLabels(rowCount);
272 QStringList labels = generateLabels(rowCount);
273 foreach(QString label, labels)
273 foreach(QString label, labels)
274 category << label;
274 category << label;
275 QAbstractBarSeries* series = 0;
275 QAbstractBarSeries* series = 0;
276 if (seriesName == "Bar") {
276 if (seriesName == "Bar") {
277 series = new QBarSeries(this);
277 series = new QBarSeries(this);
278 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
278 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
279 axis->append(category);
279 axis->append(category);
280 m_chart->setAxisX(axis,series);
280 m_chart->setAxisX(axis,series);
281 } else if (seriesName == "Stacked bar") {
281 } else if (seriesName == "Stacked bar") {
282 series = new QStackedBarSeries(this);
282 series = new QStackedBarSeries(this);
283 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
283 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
284 axis->append(category);
284 axis->append(category);
285 m_chart->setAxisX(axis,series);
285 m_chart->setAxisX(axis,series);
286 } else {
286 } else {
287 series = new QPercentBarSeries(this);
287 series = new QPercentBarSeries(this);
288 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
288 QBarCategoriesAxis* axis = new QBarCategoriesAxis();
289 axis->append(category);
289 axis->append(category);
290 m_chart->setAxisX(axis,series);
290 m_chart->setAxisX(axis,series);
291 }
291 }
292
292
293 for (int j(0); j < data.count(); j++) {
293 for (int j(0); j < data.count(); j++) {
294 QList<qreal> column = data.at(j);
294 QList<qreal> column = data.at(j);
295 QBarSet *set = new QBarSet("set" + QString::number(j));
295 QBarSet *set = new QBarSet("set" + QString::number(j));
296 for (int i(0); i < column.count(); i++)
296 for (int i(0); i < column.count(); i++)
297 *set << column.at(i);
297 *set << column.at(i);
298 series->append(set);
298 series->append(set);
299 }
299 }
300
300
301 m_chart->addSeries(series);
301 m_chart->addSeries(series);
302 } else if (seriesName == "Spline") {
302 } else if (seriesName == "Spline") {
303 for (int j(0); j < data.count(); j ++) {
303 for (int j(0); j < data.count(); j ++) {
304 QList<qreal> column = data.at(j);
304 QList<qreal> column = data.at(j);
305 QSplineSeries *series = new QSplineSeries();
305 QSplineSeries *series = new QSplineSeries();
306 for (int i(0); i < column.count(); i++)
306 for (int i(0); i < column.count(); i++)
307 series->append(i, column.at(i));
307 series->append(i, column.at(i));
308 m_chart->addSeries(series);
308 m_chart->addSeries(series);
309 }
309 }
310 }
310 }
311 m_chart->createDefaultAxes();
311 m_chart->createDefaultAxes();
312 }
312 }
313
313
314 void MainWidget::backgroundChanged(int itemIndex)
314 void MainWidget::backgroundChanged(int itemIndex)
315 {
315 {
316 qDebug() << "backgroundChanged: " << itemIndex;
316 qDebug() << "backgroundChanged: " << itemIndex;
317 }
317 }
318
318
319 void MainWidget::autoScaleChanged(int value)
319 void MainWidget::autoScaleChanged(int value)
320 {
320 {
321 if (value) {
321 if (value) {
322 // TODO: enable auto scaling
322 // TODO: enable auto scaling
323 } else {
323 } else {
324 // TODO: set scaling manually (and disable auto scaling)
324 // TODO: set scaling manually (and disable auto scaling)
325 }
325 }
326
326
327 m_xMinSpin->setEnabled(!value);
327 m_xMinSpin->setEnabled(!value);
328 m_xMaxSpin->setEnabled(!value);
328 m_xMaxSpin->setEnabled(!value);
329 m_yMinSpin->setEnabled(!value);
329 m_yMinSpin->setEnabled(!value);
330 m_yMaxSpin->setEnabled(!value);
330 m_yMaxSpin->setEnabled(!value);
331 }
331 }
332
332
333 void MainWidget::xMinChanged(int value)
333 void MainWidget::xMinChanged(int value)
334 {
334 {
335 qDebug() << "xMinChanged: " << value;
335 qDebug() << "xMinChanged: " << value;
336 }
336 }
337
337
338 void MainWidget::xMaxChanged(int value)
338 void MainWidget::xMaxChanged(int value)
339 {
339 {
340 qDebug() << "xMaxChanged: " << value;
340 qDebug() << "xMaxChanged: " << value;
341 }
341 }
342
342
343 void MainWidget::yMinChanged(int value)
343 void MainWidget::yMinChanged(int value)
344 {
344 {
345 qDebug() << "yMinChanged: " << value;
345 qDebug() << "yMinChanged: " << value;
346 }
346 }
347
347
348 void MainWidget::yMaxChanged(int value)
348 void MainWidget::yMaxChanged(int value)
349 {
349 {
350 qDebug() << "yMaxChanged: " << value;
350 qDebug() << "yMaxChanged: " << value;
351 }
351 }
352
352
353 void MainWidget::changeChartTheme(int themeIndex)
353 void MainWidget::changeChartTheme(int themeIndex)
354 {
354 {
355 qDebug() << "changeChartTheme: " << themeIndex;
355 qDebug() << "changeChartTheme: " << themeIndex;
356 m_chart->setTheme((QChart::ChartTheme) themeIndex);
356 m_chart->setTheme((QChart::ChartTheme) themeIndex);
357 }
357 }
General Comments 0
You need to be logged in to leave comments. Login now