##// END OF EJS Templates
Add/modify license headers
Jani Honkonen -
r830:b345b831b8c1
parent child
Show More
@@ -1,54 +1,35
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include "themewidget.h"
21 #include "themewidget.h"
41 #include <QApplication>
22 #include <QApplication>
42 #include <QMainWindow>
23 #include <QMainWindow>
43
24
44 int main(int argc, char *argv[])
25 int main(int argc, char *argv[])
45 {
26 {
46 QApplication a(argc, argv);
27 QApplication a(argc, argv);
47 QMainWindow window;
28 QMainWindow window;
48 ThemeWidget* widget = new ThemeWidget();
29 ThemeWidget* widget = new ThemeWidget();
49 window.setCentralWidget(widget);
30 window.setCentralWidget(widget);
50 window.resize(900, 600);
31 window.resize(900, 600);
51 window.show();
32 window.show();
52 return a.exec();
33 return a.exec();
53 }
34 }
54
35
@@ -1,366 +1,347
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include "themewidget.h"
21 #include "themewidget.h"
41
22
42 #include <QChartView>
23 #include <QChartView>
43 #include <QPieSeries>
24 #include <QPieSeries>
44 #include <QPieSlice>
25 #include <QPieSlice>
45 #include <QBarSeries>
26 #include <QBarSeries>
46 #include <QPercentBarSeries>
27 #include <QPercentBarSeries>
47 #include <QStackedBarSeries>
28 #include <QStackedBarSeries>
48 #include <QBarSet>
29 #include <QBarSet>
49 #include <QLineSeries>
30 #include <QLineSeries>
50 #include <QSplineSeries>
31 #include <QSplineSeries>
51 #include <QScatterSeries>
32 #include <QScatterSeries>
52 #include <QAreaSeries>
33 #include <QAreaSeries>
53 #include <QLegend>
34 #include <QLegend>
54 #include <QGridLayout>
35 #include <QGridLayout>
55 #include <QFormLayout>
36 #include <QFormLayout>
56 #include <QComboBox>
37 #include <QComboBox>
57 #include <QSpinBox>
38 #include <QSpinBox>
58 #include <QCheckBox>
39 #include <QCheckBox>
59 #include <QGroupBox>
40 #include <QGroupBox>
60 #include <QLabel>
41 #include <QLabel>
61 #include <QTime>
42 #include <QTime>
62
43
63 ThemeWidget::ThemeWidget(QWidget* parent) :
44 ThemeWidget::ThemeWidget(QWidget* parent) :
64 QWidget(parent),
45 QWidget(parent),
65 m_listCount(3),
46 m_listCount(3),
66 m_valueMax(100),
47 m_valueMax(100),
67 m_valueCount(11),
48 m_valueCount(11),
68 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
49 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
69 m_themeComboBox(createThemeBox()),
50 m_themeComboBox(createThemeBox()),
70 m_antialiasCheckBox(new QCheckBox("Anti aliasing")),
51 m_antialiasCheckBox(new QCheckBox("Anti aliasing")),
71 m_animatedComboBox(createAnimationBox()),
52 m_animatedComboBox(createAnimationBox()),
72 m_legendComboBox(createLegendBox())
53 m_legendComboBox(createLegendBox())
73
54
74 {
55 {
75
56
76 connectSignals();
57 connectSignals();
77 // create layout
58 // create layout
78 QGridLayout* baseLayout = new QGridLayout();
59 QGridLayout* baseLayout = new QGridLayout();
79 QHBoxLayout *settingsLayout = new QHBoxLayout();
60 QHBoxLayout *settingsLayout = new QHBoxLayout();
80 settingsLayout->addWidget(new QLabel("Theme:"));
61 settingsLayout->addWidget(new QLabel("Theme:"));
81 settingsLayout->addWidget(m_themeComboBox);
62 settingsLayout->addWidget(m_themeComboBox);
82 settingsLayout->addWidget(new QLabel("Animation:"));
63 settingsLayout->addWidget(new QLabel("Animation:"));
83 settingsLayout->addWidget(m_animatedComboBox);
64 settingsLayout->addWidget(m_animatedComboBox);
84 settingsLayout->addWidget(m_legendComboBox);
65 settingsLayout->addWidget(m_legendComboBox);
85 settingsLayout->addWidget(m_antialiasCheckBox);
66 settingsLayout->addWidget(m_antialiasCheckBox);
86 settingsLayout->addStretch();
67 settingsLayout->addStretch();
87 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
68 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
88
69
89 //create charts
70 //create charts
90
71
91 QChartView *chartView;
72 QChartView *chartView;
92
73
93 chartView = new QChartView(createAreaChart());
74 chartView = new QChartView(createAreaChart());
94 baseLayout->addWidget(chartView, 1, 0);
75 baseLayout->addWidget(chartView, 1, 0);
95 m_charts << chartView;
76 m_charts << chartView;
96
77
97 chartView = new QChartView(createBarChart(m_valueCount));
78 chartView = new QChartView(createBarChart(m_valueCount));
98 baseLayout->addWidget(chartView, 1, 1);
79 baseLayout->addWidget(chartView, 1, 1);
99 m_charts << chartView;
80 m_charts << chartView;
100
81
101 chartView = new QChartView(createLineChart());
82 chartView = new QChartView(createLineChart());
102 baseLayout->addWidget(chartView, 1, 2);
83 baseLayout->addWidget(chartView, 1, 2);
103 m_charts << chartView;
84 m_charts << chartView;
104
85
105 chartView = new QChartView(createPieChart());
86 chartView = new QChartView(createPieChart());
106 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...
107 baseLayout->addWidget(chartView, 2, 0);
88 baseLayout->addWidget(chartView, 2, 0);
108 m_charts << chartView;
89 m_charts << chartView;
109
90
110 chartView = new QChartView(createSplineChart());
91 chartView = new QChartView(createSplineChart());
111 baseLayout->addWidget(chartView, 2, 1);
92 baseLayout->addWidget(chartView, 2, 1);
112 m_charts << chartView;
93 m_charts << chartView;
113
94
114 chartView = new QChartView(createScatterChart());
95 chartView = new QChartView(createScatterChart());
115 baseLayout->addWidget(chartView, 2, 2);
96 baseLayout->addWidget(chartView, 2, 2);
116 m_charts << chartView;
97 m_charts << chartView;
117
98
118 setLayout(baseLayout);
99 setLayout(baseLayout);
119 }
100 }
120
101
121 ThemeWidget::~ThemeWidget()
102 ThemeWidget::~ThemeWidget()
122 {
103 {
123 }
104 }
124
105
125 void ThemeWidget::connectSignals()
106 void ThemeWidget::connectSignals()
126 {
107 {
127 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
108 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
128 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
109 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
129 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
110 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
130 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
111 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
131 }
112 }
132
113
133 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
114 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
134 {
115 {
135 DataTable dataTable;
116 DataTable dataTable;
136
117
137 // set seed for random stuff
118 // set seed for random stuff
138 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
119 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
139
120
140 // generate random data
121 // generate random data
141 for (int i(0); i < listCount; i++) {
122 for (int i(0); i < listCount; i++) {
142 DataList dataList;
123 DataList dataList;
143 for (int j(0); j < valueCount; j++) {
124 for (int j(0); j < valueCount; j++) {
144 QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax);
125 QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax);
145 QString label = "Item " + QString::number(i) + ":" + QString::number(j);
126 QString label = "Item " + QString::number(i) + ":" + QString::number(j);
146 dataList << Data(value, label);
127 dataList << Data(value, label);
147 }
128 }
148 dataTable << dataList;
129 dataTable << dataList;
149 }
130 }
150
131
151 return dataTable;
132 return dataTable;
152 }
133 }
153
134
154 QComboBox* ThemeWidget::createThemeBox() const
135 QComboBox* ThemeWidget::createThemeBox() const
155 {
136 {
156 // settings layout
137 // settings layout
157 QComboBox* themeComboBox = new QComboBox();
138 QComboBox* themeComboBox = new QComboBox();
158 themeComboBox->addItem("Default", QChart::ChartThemeDefault);
139 themeComboBox->addItem("Default", QChart::ChartThemeDefault);
159 themeComboBox->addItem("Light", QChart::ChartThemeLight);
140 themeComboBox->addItem("Light", QChart::ChartThemeLight);
160 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
141 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
161 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
142 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
162 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
143 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
163 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
144 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
164 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
145 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
165 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
146 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
166 return themeComboBox;
147 return themeComboBox;
167 }
148 }
168
149
169 QComboBox* ThemeWidget::createAnimationBox() const
150 QComboBox* ThemeWidget::createAnimationBox() const
170 {
151 {
171 // settings layout
152 // settings layout
172 QComboBox* animationComboBox = new QComboBox();
153 QComboBox* animationComboBox = new QComboBox();
173 animationComboBox->addItem("No Animations", QChart::NoAnimation);
154 animationComboBox->addItem("No Animations", QChart::NoAnimation);
174 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
155 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
175 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
156 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
176 animationComboBox->addItem("All Animations", QChart::AllAnimations);
157 animationComboBox->addItem("All Animations", QChart::AllAnimations);
177 return animationComboBox;
158 return animationComboBox;
178 }
159 }
179
160
180 QComboBox* ThemeWidget::createLegendBox() const
161 QComboBox* ThemeWidget::createLegendBox() const
181 {
162 {
182 QComboBox* legendComboBox = new QComboBox();
163 QComboBox* legendComboBox = new QComboBox();
183 legendComboBox->addItem("Legend Top", QLegend::AlignmentTop);
164 legendComboBox->addItem("Legend Top", QLegend::AlignmentTop);
184 legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom);
165 legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom);
185 legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft);
166 legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft);
186 legendComboBox->addItem("Legend Right", QLegend::AlignmentRight);
167 legendComboBox->addItem("Legend Right", QLegend::AlignmentRight);
187 return legendComboBox;
168 return legendComboBox;
188 }
169 }
189
170
190 QChart* ThemeWidget::createAreaChart() const
171 QChart* ThemeWidget::createAreaChart() const
191 {
172 {
192 // area chart
173 // area chart
193 QChart *chart = new QChart();
174 QChart *chart = new QChart();
194 chart->setTitle("Area chart");
175 chart->setTitle("Area chart");
195 {
176 {
196 QString name("Series ");
177 QString name("Series ");
197 int nameIndex = 0;
178 int nameIndex = 0;
198 for (int i(0); i < m_dataTable.count(); i++) {
179 for (int i(0); i < m_dataTable.count(); i++) {
199 QLineSeries *series1 = new QLineSeries(chart);
180 QLineSeries *series1 = new QLineSeries(chart);
200 QLineSeries *series2 = new QLineSeries(chart);
181 QLineSeries *series2 = new QLineSeries(chart);
201 foreach (Data data, m_dataTable[i]) {
182 foreach (Data data, m_dataTable[i]) {
202 series1->append(data.first);
183 series1->append(data.first);
203 series2->append(QPointF(data.first.x(), 0.0));
184 series2->append(QPointF(data.first.x(), 0.0));
204 }
185 }
205 QAreaSeries *area = new QAreaSeries(series1, series2);
186 QAreaSeries *area = new QAreaSeries(series1, series2);
206 area->setName(name + QString::number(nameIndex));
187 area->setName(name + QString::number(nameIndex));
207 nameIndex++;
188 nameIndex++;
208 chart->addSeries(area);
189 chart->addSeries(area);
209 }
190 }
210 }
191 }
211 return chart;
192 return chart;
212 }
193 }
213
194
214 QChart* ThemeWidget::createBarChart(int valueCount) const
195 QChart* ThemeWidget::createBarChart(int valueCount) const
215 {
196 {
216 // bar chart
197 // bar chart
217 QChart* chart = new QChart();
198 QChart* chart = new QChart();
218 chart->setTitle("Bar chart");
199 chart->setTitle("Bar chart");
219 {
200 {
220 QBarCategories categories;
201 QBarCategories categories;
221 // TODO: categories
202 // TODO: categories
222 for (int i(0); i < valueCount; i++)
203 for (int i(0); i < valueCount; i++)
223 categories << QString::number(i);
204 categories << QString::number(i);
224 // QBarSeries* series = new QBarSeries(categories, chart);
205 // QBarSeries* series = new QBarSeries(categories, chart);
225 // QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
206 // QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
226 QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
207 QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
227 for (int i(0); i < m_dataTable.count(); i++) {
208 for (int i(0); i < m_dataTable.count(); i++) {
228 QBarSet *set = new QBarSet("Set" + QString::number(i));
209 QBarSet *set = new QBarSet("Set" + QString::number(i));
229 foreach (Data data, m_dataTable[i])
210 foreach (Data data, m_dataTable[i])
230 *set << data.first.y();
211 *set << data.first.y();
231 series->appendBarSet(set);
212 series->appendBarSet(set);
232 }
213 }
233 chart->addSeries(series);
214 chart->addSeries(series);
234 }
215 }
235 return chart;
216 return chart;
236 }
217 }
237
218
238 QChart* ThemeWidget::createLineChart() const
219 QChart* ThemeWidget::createLineChart() const
239 {
220 {
240 // line chart
221 // line chart
241 QChart* chart = new QChart();
222 QChart* chart = new QChart();
242 chart->setTitle("Line chart");
223 chart->setTitle("Line chart");
243 QString name("Series ");
224 QString name("Series ");
244 int nameIndex = 0;
225 int nameIndex = 0;
245 foreach (DataList list, m_dataTable) {
226 foreach (DataList list, m_dataTable) {
246 QLineSeries *series = new QLineSeries(chart);
227 QLineSeries *series = new QLineSeries(chart);
247 foreach (Data data, list)
228 foreach (Data data, list)
248 series->append(data.first);
229 series->append(data.first);
249 series->setName(name + QString::number(nameIndex));
230 series->setName(name + QString::number(nameIndex));
250 nameIndex++;
231 nameIndex++;
251 chart->addSeries(series);
232 chart->addSeries(series);
252 }
233 }
253 return chart;
234 return chart;
254 }
235 }
255
236
256 QChart* ThemeWidget::createPieChart() const
237 QChart* ThemeWidget::createPieChart() const
257 {
238 {
258 // pie chart
239 // pie chart
259 QChart* chart = new QChart();
240 QChart* chart = new QChart();
260 chart->setTitle("Pie chart");
241 chart->setTitle("Pie chart");
261 qreal pieSize = 1.0 / m_dataTable.count();
242 qreal pieSize = 1.0 / m_dataTable.count();
262 for (int i = 0; i < m_dataTable.count(); i++) {
243 for (int i = 0; i < m_dataTable.count(); i++) {
263 QPieSeries *series = new QPieSeries(chart);
244 QPieSeries *series = new QPieSeries(chart);
264 foreach (Data data, m_dataTable[i]) {
245 foreach (Data data, m_dataTable[i]) {
265 QPieSlice *slice = series->append(data.first.y(), data.second);
246 QPieSlice *slice = series->append(data.first.y(), data.second);
266 if (data == m_dataTable[i].first()) {
247 if (data == m_dataTable[i].first()) {
267 slice->setLabelVisible();
248 slice->setLabelVisible();
268 slice->setExploded();
249 slice->setExploded();
269 }
250 }
270 }
251 }
271 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
252 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
272 series->setPieSize(pieSize);
253 series->setPieSize(pieSize);
273 series->setPiePosition(hPos, 0.5);
254 series->setPiePosition(hPos, 0.5);
274 chart->addSeries(series);
255 chart->addSeries(series);
275 }
256 }
276
257
277 return chart;
258 return chart;
278 }
259 }
279
260
280 QChart* ThemeWidget::createSplineChart() const
261 QChart* ThemeWidget::createSplineChart() const
281 { // spine chart
262 { // spine chart
282 QChart* chart = new QChart();
263 QChart* chart = new QChart();
283 chart->setTitle("Spline chart");
264 chart->setTitle("Spline chart");
284 QString name("Series ");
265 QString name("Series ");
285 int nameIndex = 0;
266 int nameIndex = 0;
286 foreach (DataList list, m_dataTable) {
267 foreach (DataList list, m_dataTable) {
287 QSplineSeries *series = new QSplineSeries(chart);
268 QSplineSeries *series = new QSplineSeries(chart);
288 foreach (Data data, list)
269 foreach (Data data, list)
289 series->append(data.first);
270 series->append(data.first);
290 series->setName(name + QString::number(nameIndex));
271 series->setName(name + QString::number(nameIndex));
291 nameIndex++;
272 nameIndex++;
292 chart->addSeries(series);
273 chart->addSeries(series);
293 }
274 }
294 return chart;
275 return chart;
295 }
276 }
296
277
297 QChart* ThemeWidget::createScatterChart() const
278 QChart* ThemeWidget::createScatterChart() const
298 { // scatter chart
279 { // scatter chart
299 QChart* chart = new QChart();
280 QChart* chart = new QChart();
300 chart->setTitle("Scatter chart");
281 chart->setTitle("Scatter chart");
301 QString name("Series ");
282 QString name("Series ");
302 int nameIndex = 0;
283 int nameIndex = 0;
303 foreach (DataList list, m_dataTable) {
284 foreach (DataList list, m_dataTable) {
304 QScatterSeries *series = new QScatterSeries(chart);
285 QScatterSeries *series = new QScatterSeries(chart);
305 foreach (Data data, list)
286 foreach (Data data, list)
306 series->append(data.first);
287 series->append(data.first);
307 series->setName(name + QString::number(nameIndex));
288 series->setName(name + QString::number(nameIndex));
308 nameIndex++;
289 nameIndex++;
309 chart->addSeries(series);
290 chart->addSeries(series);
310 }
291 }
311 return chart;
292 return chart;
312 }
293 }
313
294
314 void ThemeWidget::updateUI()
295 void ThemeWidget::updateUI()
315 {
296 {
316 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
297 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
317
298
318 if (m_charts.at(0)->chart()->theme() != theme) {
299 if (m_charts.at(0)->chart()->theme() != theme) {
319 foreach (QChartView *chartView, m_charts)
300 foreach (QChartView *chartView, m_charts)
320 chartView->chart()->setTheme(theme);
301 chartView->chart()->setTheme(theme);
321
302
322 QPalette pal = window()->palette();
303 QPalette pal = window()->palette();
323 if (theme == QChart::ChartThemeLight) {
304 if (theme == QChart::ChartThemeLight) {
324 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
305 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
325 pal.setColor(QPalette::WindowText, QRgb(0x404044));
306 pal.setColor(QPalette::WindowText, QRgb(0x404044));
326 } else if (theme == QChart::ChartThemeDark) {
307 } else if (theme == QChart::ChartThemeDark) {
327 pal.setColor(QPalette::Window, QRgb(0x121218));
308 pal.setColor(QPalette::Window, QRgb(0x121218));
328 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
309 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
329 } else if (theme == QChart::ChartThemeBlueCerulean) {
310 } else if (theme == QChart::ChartThemeBlueCerulean) {
330 pal.setColor(QPalette::Window, QRgb(0x40434a));
311 pal.setColor(QPalette::Window, QRgb(0x40434a));
331 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
312 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
332 } else if (theme == QChart::ChartThemeBrownSand) {
313 } else if (theme == QChart::ChartThemeBrownSand) {
333 pal.setColor(QPalette::Window, QRgb(0x9e8965));
314 pal.setColor(QPalette::Window, QRgb(0x9e8965));
334 pal.setColor(QPalette::WindowText, QRgb(0x404044));
315 pal.setColor(QPalette::WindowText, QRgb(0x404044));
335 } else if (theme == QChart::ChartThemeBlueNcs) {
316 } else if (theme == QChart::ChartThemeBlueNcs) {
336 pal.setColor(QPalette::Window, QRgb(0x018bba));
317 pal.setColor(QPalette::Window, QRgb(0x018bba));
337 pal.setColor(QPalette::WindowText, QRgb(0x404044));
318 pal.setColor(QPalette::WindowText, QRgb(0x404044));
338 } else if (theme == QChart::ChartThemeHighContrast) {
319 } else if (theme == QChart::ChartThemeHighContrast) {
339 pal.setColor(QPalette::Window, QRgb(0xffab03));
320 pal.setColor(QPalette::Window, QRgb(0xffab03));
340 pal.setColor(QPalette::WindowText, QRgb(0x181818));
321 pal.setColor(QPalette::WindowText, QRgb(0x181818));
341 } else if (theme == QChart::ChartThemeBlueIcy) {
322 } else if (theme == QChart::ChartThemeBlueIcy) {
342 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
323 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
343 pal.setColor(QPalette::WindowText, QRgb(0x404044));
324 pal.setColor(QPalette::WindowText, QRgb(0x404044));
344 } else {
325 } else {
345 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
326 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
346 pal.setColor(QPalette::WindowText, QRgb(0x404044));
327 pal.setColor(QPalette::WindowText, QRgb(0x404044));
347 }
328 }
348 window()->setPalette(pal);
329 window()->setPalette(pal);
349 }
330 }
350
331
351 bool checked = m_antialiasCheckBox->isChecked();
332 bool checked = m_antialiasCheckBox->isChecked();
352 foreach (QChartView *chart, m_charts)
333 foreach (QChartView *chart, m_charts)
353 chart->setRenderHint(QPainter::Antialiasing, checked);
334 chart->setRenderHint(QPainter::Antialiasing, checked);
354
335
355 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
336 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
356 if (m_charts.at(0)->chart()->animationOptions() != options) {
337 if (m_charts.at(0)->chart()->animationOptions() != options) {
357 foreach (QChartView *chartView, m_charts)
338 foreach (QChartView *chartView, m_charts)
358 chartView->chart()->setAnimationOptions(options);
339 chartView->chart()->setAnimationOptions(options);
359 }
340 }
360
341
361 QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
342 QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
362 foreach (QChartView *chartView, m_charts) {
343 foreach (QChartView *chartView, m_charts) {
363 chartView->chart()->legend()->setAlignmnent(alignment);
344 chartView->chart()->legend()->setAlignmnent(alignment);
364 }
345 }
365 }
346 }
366
347
@@ -1,95 +1,76
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #ifndef THEMEWINDOW_H_
21 #ifndef THEMEWINDOW_H_
41 #define THEMEWINDOW_H_
22 #define THEMEWINDOW_H_
42 #include <QWidget>
23 #include <QWidget>
43 #include <QChartGlobal>
24 #include <QChartGlobal>
44
25
45 class QComboBox;
26 class QComboBox;
46 class QCheckBox;
27 class QCheckBox;
47
28
48 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
49 class QChartView;
30 class QChartView;
50 class QChart;
31 class QChart;
51 QTCOMMERCIALCHART_END_NAMESPACE
32 QTCOMMERCIALCHART_END_NAMESPACE
52
33
53 typedef QPair<QPointF, QString> Data;
34 typedef QPair<QPointF, QString> Data;
54 typedef QList<Data> DataList;
35 typedef QList<Data> DataList;
55 typedef QList<DataList> DataTable;
36 typedef QList<DataList> DataTable;
56
37
57 QTCOMMERCIALCHART_USE_NAMESPACE
38 QTCOMMERCIALCHART_USE_NAMESPACE
58
39
59 class ThemeWidget: public QWidget
40 class ThemeWidget: public QWidget
60 {
41 {
61 Q_OBJECT
42 Q_OBJECT
62 public:
43 public:
63 explicit ThemeWidget(QWidget *parent = 0);
44 explicit ThemeWidget(QWidget *parent = 0);
64 ~ThemeWidget();
45 ~ThemeWidget();
65
46
66 private Q_SLOTS:
47 private Q_SLOTS:
67 void updateUI();
48 void updateUI();
68
49
69 private:
50 private:
70 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
51 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
71 QComboBox* createThemeBox() const;
52 QComboBox* createThemeBox() const;
72 QComboBox* createAnimationBox() const;
53 QComboBox* createAnimationBox() const;
73 QComboBox* createLegendBox() const;
54 QComboBox* createLegendBox() const;
74 void connectSignals();
55 void connectSignals();
75 QChart* createAreaChart() const;
56 QChart* createAreaChart() const;
76 QChart* createBarChart(int valueCount) const;
57 QChart* createBarChart(int valueCount) const;
77 QChart* createPieChart() const;
58 QChart* createPieChart() const;
78 QChart* createLineChart() const;
59 QChart* createLineChart() const;
79 QChart* createSplineChart() const;
60 QChart* createSplineChart() const;
80 QChart* createScatterChart() const;
61 QChart* createScatterChart() const;
81
62
82 private:
63 private:
83 int m_listCount;
64 int m_listCount;
84 int m_valueMax;
65 int m_valueMax;
85 int m_valueCount;
66 int m_valueCount;
86 QList<QChartView*> m_charts;
67 QList<QChartView*> m_charts;
87 DataTable m_dataTable;
68 DataTable m_dataTable;
88
69
89 QComboBox *m_themeComboBox;
70 QComboBox *m_themeComboBox;
90 QCheckBox *m_antialiasCheckBox;
71 QCheckBox *m_antialiasCheckBox;
91 QComboBox *m_animatedComboBox;
72 QComboBox *m_animatedComboBox;
92 QComboBox *m_legendComboBox;
73 QComboBox *m_legendComboBox;
93 };
74 };
94
75
95 #endif /* THEMEWINDOW_H_ */
76 #endif /* THEMEWINDOW_H_ */
@@ -1,11 +1,31
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include "widget.h"
22 #include "widget.h"
3
23
4 int main(int argc, char *argv[])
24 int main(int argc, char *argv[])
5 {
25 {
6 QApplication a(argc, argv);
26 QApplication a(argc, argv);
7 Widget w;
27 Widget w;
8 w.show();
28 w.show();
9
29
10 return a.exec();
30 return a.exec();
11 }
31 }
@@ -1,233 +1,247
1 /*!
1 /****************************************************************************
2 \class Widget
2 **
3 \brief Ui for the application.
3 ** Copyright (C) 2012 Digia Plc
4 \internal
4 ** All rights reserved.
5 */
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 ****************************************************************************/
6
20
7 #include "widget.h"
21 #include "widget.h"
8
22
9 #include <QChart>
23 #include <QChart>
10 #include <QScatterSeries>
24 #include <QScatterSeries>
11 #include <QChartAxis>
25 #include <QChartAxis>
12 #include <QBarset>
26 #include <QBarset>
13 #include <QBarSeries>
27 #include <QBarSeries>
14
28
15 #include <QGridLayout>
29 #include <QGridLayout>
16 #include <QPushButton>
30 #include <QPushButton>
17 #include <QLabel>
31 #include <QLabel>
18 #include <QListWidget>
32 #include <QListWidget>
19 #include <QPrinter>
33 #include <QPrinter>
20 #include <QPrintDialog>
34 #include <QPrintDialog>
21 #include <QRadioButton>
35 #include <QRadioButton>
22 #include <QStringList>
36 #include <QStringList>
23 #include <QSqlQuery>
37 #include <QSqlQuery>
24
38
25 QTCOMMERCIALCHART_USE_NAMESPACE
39 QTCOMMERCIALCHART_USE_NAMESPACE
26
40
27 Widget::Widget(QWidget *parent)
41 Widget::Widget(QWidget *parent)
28 : QWidget(parent)
42 : QWidget(parent)
29 {
43 {
30 setGeometry(100, 100, 1000, 600);
44 setGeometry(100, 100, 1000, 600);
31
45
32 // right panel layout
46 // right panel layout
33 barChartRadioButton = new QRadioButton(tr("Bar chart"));
47 barChartRadioButton = new QRadioButton(tr("Bar chart"));
34 barChartRadioButton->setChecked(true);
48 barChartRadioButton->setChecked(true);
35 scatterChartRadioButton = new QRadioButton(tr("Scatter chart"));
49 scatterChartRadioButton = new QRadioButton(tr("Scatter chart"));
36 scatterChartRadioButton->setChecked(false);
50 scatterChartRadioButton->setChecked(false);
37 countrieslist = new QListWidget;
51 countrieslist = new QListWidget;
38 countrieslist->setSelectionMode(QAbstractItemView::MultiSelection);
52 countrieslist->setSelectionMode(QAbstractItemView::MultiSelection);
39
53
40 //list of years widget
54 //list of years widget
41 yearslist = new QListWidget;
55 yearslist = new QListWidget;
42 yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
56 yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection);
43 for (int i = 1990; i < 2011; i++)
57 for (int i = 1990; i < 2011; i++)
44 yearslist->addItem(QString("%1").arg(i));
58 yearslist->addItem(QString("%1").arg(i));
45
59
46 QPushButton* refreshButton = new QPushButton(tr("Refresh"));
60 QPushButton* refreshButton = new QPushButton(tr("Refresh"));
47 connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart()));
61 connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart()));
48
62
49 QPushButton* printButton = new QPushButton(tr("Print chart"));
63 QPushButton* printButton = new QPushButton(tr("Print chart"));
50 connect(printButton, SIGNAL(clicked()), this, SLOT(printChart()));
64 connect(printButton, SIGNAL(clicked()), this, SLOT(printChart()));
51
65
52 QVBoxLayout* rightPanelLayout = new QVBoxLayout;
66 QVBoxLayout* rightPanelLayout = new QVBoxLayout;
53 rightPanelLayout->addWidget(barChartRadioButton);
67 rightPanelLayout->addWidget(barChartRadioButton);
54 rightPanelLayout->addWidget(scatterChartRadioButton);
68 rightPanelLayout->addWidget(scatterChartRadioButton);
55 rightPanelLayout->addWidget(countrieslist);
69 rightPanelLayout->addWidget(countrieslist);
56 rightPanelLayout->addWidget(yearslist);
70 rightPanelLayout->addWidget(yearslist);
57 rightPanelLayout->addWidget(refreshButton);
71 rightPanelLayout->addWidget(refreshButton);
58 rightPanelLayout->addWidget(printButton);
72 rightPanelLayout->addWidget(printButton);
59 rightPanelLayout->setStretch(0, 1);
73 rightPanelLayout->setStretch(0, 1);
60 rightPanelLayout->setStretch(1, 0);
74 rightPanelLayout->setStretch(1, 0);
61
75
62 QChart *chart = new QChart();
76 QChart *chart = new QChart();
63 chart->setTitle("GDP by country");
77 chart->setTitle("GDP by country");
64
78
65 // main layout
79 // main layout
66 chartView = new QChartView(chart);
80 chartView = new QChartView(chart);
67 QGridLayout* mainLayout = new QGridLayout;
81 QGridLayout* mainLayout = new QGridLayout;
68 mainLayout->addWidget(chartView, 0, 0);
82 mainLayout->addWidget(chartView, 0, 0);
69 mainLayout->addLayout(rightPanelLayout, 0, 1);
83 mainLayout->addLayout(rightPanelLayout, 0, 1);
70 mainLayout->setColumnStretch(0,1);
84 mainLayout->setColumnStretch(0,1);
71 setLayout(mainLayout);
85 setLayout(mainLayout);
72
86
73 // connect to the database
87 // connect to the database
74 db = QSqlDatabase::addDatabase("QSQLITE");
88 db = QSqlDatabase::addDatabase("QSQLITE");
75 db.setDatabaseName("gdpData");
89 db.setDatabaseName("gdpData");
76 if(!db.open())
90 if(!db.open())
77 {
91 {
78 qDebug() << "could not open database. SQLite db file missing (?)";
92 qDebug() << "could not open database. SQLite db file missing (?)";
79 return;
93 return;
80 }
94 }
81
95
82 // get the list of all countires and regions.
96 // get the list of all countires and regions.
83 QSqlQuery query;
97 QSqlQuery query;
84 query.exec("SELECT DISTINCT country FROM gdp2");
98 query.exec("SELECT DISTINCT country FROM gdp2");
85
99
86 // add the countries to the country filter
100 // add the countries to the country filter
87 while (query.next()) {
101 while (query.next()) {
88 countrieslist->addItem(query.value(0).toString());
102 countrieslist->addItem(query.value(0).toString());
89 }
103 }
90
104
91 // hide axis X labels
105 // hide axis X labels
92 //QChartAxis* axis = chartArea->axisX();
106 //QChartAxis* axis = chartArea->axisX();
93 // axis->
107 // axis->
94 // axis->setLabelsVisible(false);
108 // axis->setLabelsVisible(false);
95 // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide);
109 // newAxis.setLabelsOrientation(QChartAxis::LabelsOrientationSlide);
96
110
97 }
111 }
98
112
99 Widget::~Widget()
113 Widget::~Widget()
100 {
114 {
101 //
115 //
102 db.close();
116 db.close();
103 }
117 }
104
118
105 /*!
119 /*!
106 refreshes the chart
120 refreshes the chart
107 */
121 */
108 void Widget::refreshChart()
122 void Widget::refreshChart()
109 {
123 {
110 chartView->chart()->removeAllSeries();
124 chartView->chart()->removeAllSeries();
111
125
112 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
126 // selected countries items list is not sorted. copy the values to QStringlist and sort them.
113 QStringList selectedCountriesStrings;
127 QStringList selectedCountriesStrings;
114 QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems();
128 QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems();
115 for (int i = 0; i < selectedCountriesItems.size(); i++)
129 for (int i = 0; i < selectedCountriesItems.size(); i++)
116 selectedCountriesStrings.append(selectedCountriesItems[i]->text());
130 selectedCountriesStrings.append(selectedCountriesItems[i]->text());
117 selectedCountriesStrings.sort();
131 selectedCountriesStrings.sort();
118
132
119 QSqlQuery query;
133 QSqlQuery query;
120 // selected years items list is not sorted. copy the values to QList<int> and sort them.
134 // selected years items list is not sorted. copy the values to QList<int> and sort them.
121 QList<int> selectedYearsInts;
135 QList<int> selectedYearsInts;
122 QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems();
136 QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems();
123 for (int i = 0; i < selectedYearsItems.size(); i++)
137 for (int i = 0; i < selectedYearsItems.size(); i++)
124 selectedYearsInts.append(selectedYearsItems[i]->text().toInt());
138 selectedYearsInts.append(selectedYearsItems[i]->text().toInt());
125 qSort(selectedYearsInts.begin(), selectedYearsInts.end(), qGreater<int>());
139 qSort(selectedYearsInts.begin(), selectedYearsInts.end(), qGreater<int>());
126
140
127 if (barChartRadioButton->isChecked())
141 if (barChartRadioButton->isChecked())
128 {
142 {
129 // use the sorted selected coutries list to initialize BarCategory
143 // use the sorted selected coutries list to initialize BarCategory
130 QStringList category;
144 QStringList category;
131 for (int i = 0; i < selectedCountriesStrings.size(); i++)
145 for (int i = 0; i < selectedCountriesStrings.size(); i++)
132 category << selectedCountriesStrings[i];
146 category << selectedCountriesStrings[i];
133 QBarSeries* series0 = new QBarSeries(category);
147 QBarSeries* series0 = new QBarSeries(category);
134 series0 = new QBarSeries(category);
148 series0 = new QBarSeries(category);
135
149
136 // prepare the selected counries SQL query
150 // prepare the selected counries SQL query
137 QString countriesQuery = "country IN (";
151 QString countriesQuery = "country IN (";
138 for (int i = 0; i < selectedCountriesStrings.size(); i++)
152 for (int i = 0; i < selectedCountriesStrings.size(); i++)
139 {
153 {
140 countriesQuery.append("'" + selectedCountriesStrings[i] + "'");
154 countriesQuery.append("'" + selectedCountriesStrings[i] + "'");
141 if ( i < selectedCountriesStrings.size() - 1)
155 if ( i < selectedCountriesStrings.size() - 1)
142 countriesQuery.append(",");
156 countriesQuery.append(",");
143 else
157 else
144 countriesQuery.append(")");
158 countriesQuery.append(")");
145 }
159 }
146
160
147 // perform a query for each selected year
161 // perform a query for each selected year
148 for (int i = 0; i < selectedYearsInts.size(); i++)
162 for (int i = 0; i < selectedYearsInts.size(); i++)
149 {
163 {
150 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
164 query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery);
151 QBarSet* barSet = new QBarSet("Barset" + QString::number(i));
165 QBarSet* barSet = new QBarSet("Barset" + QString::number(i));
152
166
153 // while (query.next()) {
167 // while (query.next()) {
154 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
168 // qDebug() << query.value(0).toString() << " : " << query.value(1).toString();
155 // }
169 // }
156 query.first();
170 query.first();
157
171
158 // the data for some of the coutries for some years might be missing.
172 // the data for some of the coutries for some years might be missing.
159 // QBarChart needs bars to have same size
173 // QBarChart needs bars to have same size
160 for (int k = 0; k < selectedCountriesStrings.size(); k++)
174 for (int k = 0; k < selectedCountriesStrings.size(); k++)
161 {
175 {
162 if (selectedCountriesStrings[k] == query.value(0).toString())
176 if (selectedCountriesStrings[k] == query.value(0).toString())
163 {
177 {
164 *barSet << query.value(1).toReal();
178 *barSet << query.value(1).toReal();
165 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]);
179 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]);
166 query.next();
180 query.next();
167 }
181 }
168 else
182 else
169 {
183 {
170 // data missing, put 0
184 // data missing, put 0
171 *barSet << 0.0f;
185 *barSet << 0.0f;
172 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]);
186 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]);
173 }
187 }
174 }
188 }
175 series0->appendBarSet(barSet);
189 series0->appendBarSet(barSet);
176 }
190 }
177 // add the serie to the chart
191 // add the serie to the chart
178 chartView->chart()->addSeries(series0);
192 chartView->chart()->addSeries(series0);
179 }
193 }
180 else if (scatterChartRadioButton->isChecked())
194 else if (scatterChartRadioButton->isChecked())
181 {
195 {
182 QString yearsQuery = "year IN (";
196 QString yearsQuery = "year IN (";
183 for (int i = 0; i < selectedYearsInts.size(); i++)
197 for (int i = 0; i < selectedYearsInts.size(); i++)
184 {
198 {
185 yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'");
199 yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'");
186 if ( i < selectedYearsInts.size() - 1)
200 if ( i < selectedYearsInts.size() - 1)
187 yearsQuery.append(",");
201 yearsQuery.append(",");
188 else
202 else
189 yearsQuery.append(")");
203 yearsQuery.append(")");
190 }
204 }
191
205
192 // perform a query for each selected country
206 // perform a query for each selected country
193 for (int i = 0; i < selectedCountriesStrings.size(); i++)
207 for (int i = 0; i < selectedCountriesStrings.size(); i++)
194 {
208 {
195 query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery);
209 query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery);
196 query.first();
210 query.first();
197
211
198 QScatterSeries* series = new QScatterSeries;
212 QScatterSeries* series = new QScatterSeries;
199 // the data for some of the coutries for some years might be missing.
213 // the data for some of the coutries for some years might be missing.
200 for (int k = 0; k < selectedYearsInts.size(); k++)
214 for (int k = 0; k < selectedYearsInts.size(); k++)
201 {
215 {
202 if (selectedYearsInts[k] == query.value(0).toInt())
216 if (selectedYearsInts[k] == query.value(0).toInt())
203 {
217 {
204 *series << QPointF(query.value(0).toInt() , query.value(1).toReal());
218 *series << QPointF(query.value(0).toInt() , query.value(1).toReal());
205 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]);
219 qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]);
206 query.next();
220 query.next();
207 }
221 }
208 else
222 else
209 {
223 {
210 // data missing, put 0
224 // data missing, put 0
211 *series << QPointF(selectedYearsInts[k] , 0.0f);
225 *series << QPointF(selectedYearsInts[k] , 0.0f);
212 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
226 qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt();
213 }
227 }
214 }
228 }
215 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
229 // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1);
216 chartView->chart()->addSeries(series);
230 chartView->chart()->addSeries(series);
217 }
231 }
218 chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1);
232 chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1);
219 }
233 }
220 }
234 }
221
235
222 void Widget::printChart()
236 void Widget::printChart()
223 {
237 {
224 QPrinter printer;
238 QPrinter printer;
225 // QPrinter printer(QPrinter::HighResolution);
239 // QPrinter printer(QPrinter::HighResolution);
226 printer.setOutputFormat(QPrinter::PdfFormat);
240 printer.setOutputFormat(QPrinter::PdfFormat);
227 printer.setOrientation(QPrinter::Landscape);
241 printer.setOrientation(QPrinter::Landscape);
228 printer.setOutputFileName("print.pdf");
242 printer.setOutputFileName("print.pdf");
229
243
230 QPainter painter;
244 QPainter painter;
231 painter.begin(&printer);
245 painter.begin(&printer);
232 chartView->render(&painter);
246 chartView->render(&painter);
233 }
247 }
@@ -1,34 +1,54
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
1 #ifndef WIDGET_H
21 #ifndef WIDGET_H
2 #define WIDGET_H
22 #define WIDGET_H
3
23
4 #include <QtGui/QWidget>
24 #include <QtGui/QWidget>
5 #include <QChartview>
25 #include <QChartview>
6 #include <QSqlDatabase>
26 #include <QSqlDatabase>
7
27
8 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
9
29
10 class QListWidget;
30 class QListWidget;
11 class QRadioButton;
31 class QRadioButton;
12
32
13 class Widget : public QWidget
33 class Widget : public QWidget
14 {
34 {
15 Q_OBJECT
35 Q_OBJECT
16
36
17 public:
37 public:
18 Widget(QWidget *parent = 0);
38 Widget(QWidget *parent = 0);
19 ~Widget();
39 ~Widget();
20
40
21 public slots:
41 public slots:
22 void refreshChart();
42 void refreshChart();
23 void printChart();
43 void printChart();
24
44
25 private:
45 private:
26 QChartView* chartView;
46 QChartView* chartView;
27 QListWidget* countrieslist;
47 QListWidget* countrieslist;
28 QListWidget* yearslist;
48 QListWidget* yearslist;
29 QSqlDatabase db;
49 QSqlDatabase db;
30 QRadioButton* barChartRadioButton;
50 QRadioButton* barChartRadioButton;
31 QRadioButton* scatterChartRadioButton;
51 QRadioButton* scatterChartRadioButton;
32 };
52 };
33
53
34 #endif // WIDGET_H
54 #endif // WIDGET_H
@@ -1,611 +1,631
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include <QMainWindow>
22 #include <QMainWindow>
3 #include <qchartglobal.h>
23 #include <qchartglobal.h>
4 #include <qchartview.h>
24 #include <qchartview.h>
5 #include <qpieseries.h>
25 #include <qpieseries.h>
6 #include <qpieslice.h>
26 #include <qpieslice.h>
7 #include <QGridLayout>
27 #include <QGridLayout>
8 #include <QFormLayout>
28 #include <QFormLayout>
9 #include <QComboBox>
29 #include <QComboBox>
10 #include <QSpinBox>
30 #include <QSpinBox>
11 #include <QCheckBox>
31 #include <QCheckBox>
12 #include <QGroupBox>
32 #include <QGroupBox>
13 #include <QLabel>
33 #include <QLabel>
14 #include <QPushButton>
34 #include <QPushButton>
15 #include <QColorDialog>
35 #include <QColorDialog>
16 #include <QFontDialog>
36 #include <QFontDialog>
17
37
18 QTCOMMERCIALCHART_USE_NAMESPACE
38 QTCOMMERCIALCHART_USE_NAMESPACE
19
39
20 class PenTool : public QWidget
40 class PenTool : public QWidget
21 {
41 {
22 Q_OBJECT
42 Q_OBJECT
23
43
24 public:
44 public:
25 explicit PenTool(QString title, QWidget *parent = 0)
45 explicit PenTool(QString title, QWidget *parent = 0)
26 :QWidget(parent)
46 :QWidget(parent)
27 {
47 {
28 setWindowTitle(title);
48 setWindowTitle(title);
29 setWindowFlags(Qt::Tool);
49 setWindowFlags(Qt::Tool);
30
50
31 m_colorButton = new QPushButton();
51 m_colorButton = new QPushButton();
32
52
33 m_widthSpinBox = new QDoubleSpinBox();
53 m_widthSpinBox = new QDoubleSpinBox();
34
54
35 m_styleCombo = new QComboBox();
55 m_styleCombo = new QComboBox();
36 m_styleCombo->addItem("NoPen");
56 m_styleCombo->addItem("NoPen");
37 m_styleCombo->addItem("SolidLine");
57 m_styleCombo->addItem("SolidLine");
38 m_styleCombo->addItem("DashLine");
58 m_styleCombo->addItem("DashLine");
39 m_styleCombo->addItem("DotLine");
59 m_styleCombo->addItem("DotLine");
40 m_styleCombo->addItem("DashDotLine");
60 m_styleCombo->addItem("DashDotLine");
41 m_styleCombo->addItem("DashDotDotLine");
61 m_styleCombo->addItem("DashDotDotLine");
42
62
43 m_capStyleCombo = new QComboBox();
63 m_capStyleCombo = new QComboBox();
44 m_capStyleCombo->addItem("FlatCap", Qt::FlatCap);
64 m_capStyleCombo->addItem("FlatCap", Qt::FlatCap);
45 m_capStyleCombo->addItem("SquareCap", Qt::SquareCap);
65 m_capStyleCombo->addItem("SquareCap", Qt::SquareCap);
46 m_capStyleCombo->addItem("RoundCap", Qt::RoundCap);
66 m_capStyleCombo->addItem("RoundCap", Qt::RoundCap);
47
67
48 m_joinStyleCombo = new QComboBox();
68 m_joinStyleCombo = new QComboBox();
49 m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin);
69 m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin);
50 m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin);
70 m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin);
51 m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin);
71 m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin);
52 m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin);
72 m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin);
53
73
54 QFormLayout *layout = new QFormLayout();
74 QFormLayout *layout = new QFormLayout();
55 layout->addRow("Color", m_colorButton);
75 layout->addRow("Color", m_colorButton);
56 layout->addRow("Width", m_widthSpinBox);
76 layout->addRow("Width", m_widthSpinBox);
57 layout->addRow("Style", m_styleCombo);
77 layout->addRow("Style", m_styleCombo);
58 layout->addRow("Cap style", m_capStyleCombo);
78 layout->addRow("Cap style", m_capStyleCombo);
59 layout->addRow("Join style", m_joinStyleCombo);
79 layout->addRow("Join style", m_joinStyleCombo);
60 setLayout(layout);
80 setLayout(layout);
61
81
62 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
82 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
63 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
83 connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double)));
64 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int)));
84 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int)));
65 connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int)));
85 connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int)));
66 connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int)));
86 connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int)));
67 }
87 }
68
88
69 void setPen(QPen pen)
89 void setPen(QPen pen)
70 {
90 {
71 m_pen = pen;
91 m_pen = pen;
72 m_colorButton->setText(m_pen.color().name());
92 m_colorButton->setText(m_pen.color().name());
73 m_widthSpinBox->setValue(m_pen.widthF());
93 m_widthSpinBox->setValue(m_pen.widthF());
74 m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum
94 m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum
75 m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle()));
95 m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle()));
76 m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle()));
96 m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle()));
77 }
97 }
78
98
79 QPen pen() const
99 QPen pen() const
80 {
100 {
81 return m_pen;
101 return m_pen;
82 }
102 }
83
103
84 QString name()
104 QString name()
85 {
105 {
86 return name(m_pen);
106 return name(m_pen);
87 }
107 }
88
108
89 static QString name(const QPen &pen)
109 static QString name(const QPen &pen)
90 {
110 {
91 return pen.color().name() + ":" + QString::number(pen.widthF());
111 return pen.color().name() + ":" + QString::number(pen.widthF());
92 }
112 }
93
113
94 Q_SIGNALS:
114 Q_SIGNALS:
95 void changed();
115 void changed();
96
116
97 public Q_SLOTS:
117 public Q_SLOTS:
98
118
99 void showColorDialog()
119 void showColorDialog()
100 {
120 {
101 QColorDialog dialog(m_pen.color());
121 QColorDialog dialog(m_pen.color());
102 dialog.show();
122 dialog.show();
103 dialog.exec();
123 dialog.exec();
104 m_pen.setColor(dialog.selectedColor());
124 m_pen.setColor(dialog.selectedColor());
105 m_colorButton->setText(m_pen.color().name());
125 m_colorButton->setText(m_pen.color().name());
106 emit changed();
126 emit changed();
107 }
127 }
108
128
109 void updateWidth(double width)
129 void updateWidth(double width)
110 {
130 {
111 if (!qFuzzyIsNull(width - m_pen.widthF())) {
131 if (!qFuzzyIsNull(width - m_pen.widthF())) {
112 m_pen.setWidthF(width);
132 m_pen.setWidthF(width);
113 emit changed();
133 emit changed();
114 }
134 }
115 }
135 }
116
136
117 void updateStyle(int style)
137 void updateStyle(int style)
118 {
138 {
119 if (m_pen.style() != style) {
139 if (m_pen.style() != style) {
120 m_pen.setStyle((Qt::PenStyle) style);
140 m_pen.setStyle((Qt::PenStyle) style);
121 emit changed();
141 emit changed();
122 }
142 }
123 }
143 }
124
144
125 void updateCapStyle(int index)
145 void updateCapStyle(int index)
126 {
146 {
127 Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt();
147 Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt();
128 if (m_pen.capStyle() != capStyle) {
148 if (m_pen.capStyle() != capStyle) {
129 m_pen.setCapStyle(capStyle);
149 m_pen.setCapStyle(capStyle);
130 emit changed();
150 emit changed();
131 }
151 }
132 }
152 }
133
153
134 void updateJoinStyle(int index)
154 void updateJoinStyle(int index)
135 {
155 {
136 Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt();
156 Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt();
137 if (m_pen.joinStyle() != joinStyle) {
157 if (m_pen.joinStyle() != joinStyle) {
138 m_pen.setJoinStyle(joinStyle);
158 m_pen.setJoinStyle(joinStyle);
139 emit changed();
159 emit changed();
140 }
160 }
141 }
161 }
142
162
143 private:
163 private:
144 QPen m_pen;
164 QPen m_pen;
145 QPushButton *m_colorButton;
165 QPushButton *m_colorButton;
146 QDoubleSpinBox *m_widthSpinBox;
166 QDoubleSpinBox *m_widthSpinBox;
147 QComboBox *m_styleCombo;
167 QComboBox *m_styleCombo;
148 QComboBox *m_capStyleCombo;
168 QComboBox *m_capStyleCombo;
149 QComboBox *m_joinStyleCombo;
169 QComboBox *m_joinStyleCombo;
150 };
170 };
151
171
152 class BrushTool : public QWidget
172 class BrushTool : public QWidget
153 {
173 {
154 Q_OBJECT
174 Q_OBJECT
155
175
156 public:
176 public:
157 explicit BrushTool(QString title, QWidget *parent = 0)
177 explicit BrushTool(QString title, QWidget *parent = 0)
158 :QWidget(parent)
178 :QWidget(parent)
159 {
179 {
160 setWindowTitle(title);
180 setWindowTitle(title);
161 setWindowFlags(Qt::Tool);
181 setWindowFlags(Qt::Tool);
162
182
163 m_colorButton = new QPushButton();
183 m_colorButton = new QPushButton();
164 m_styleCombo = new QComboBox();
184 m_styleCombo = new QComboBox();
165 m_styleCombo->addItem("Nobrush", Qt::NoBrush);
185 m_styleCombo->addItem("Nobrush", Qt::NoBrush);
166 m_styleCombo->addItem("Solidpattern", Qt::SolidPattern);
186 m_styleCombo->addItem("Solidpattern", Qt::SolidPattern);
167 m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern);
187 m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern);
168 m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern);
188 m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern);
169 m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern);
189 m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern);
170 m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern);
190 m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern);
171 m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern);
191 m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern);
172 m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern);
192 m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern);
173 m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern);
193 m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern);
174 m_styleCombo->addItem("HorPattern", Qt::HorPattern);
194 m_styleCombo->addItem("HorPattern", Qt::HorPattern);
175 m_styleCombo->addItem("VerPattern", Qt::VerPattern);
195 m_styleCombo->addItem("VerPattern", Qt::VerPattern);
176 m_styleCombo->addItem("CrossPattern", Qt::CrossPattern);
196 m_styleCombo->addItem("CrossPattern", Qt::CrossPattern);
177 m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern);
197 m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern);
178 m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern);
198 m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern);
179 m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern);
199 m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern);
180
200
181 QFormLayout *layout = new QFormLayout();
201 QFormLayout *layout = new QFormLayout();
182 layout->addRow("Color", m_colorButton);
202 layout->addRow("Color", m_colorButton);
183 layout->addRow("Style", m_styleCombo);
203 layout->addRow("Style", m_styleCombo);
184 setLayout(layout);
204 setLayout(layout);
185
205
186 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
206 connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog()));
187 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle()));
207 connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle()));
188 }
208 }
189
209
190 void setBrush(QBrush brush)
210 void setBrush(QBrush brush)
191 {
211 {
192 m_brush = brush;
212 m_brush = brush;
193 m_colorButton->setText(m_brush.color().name());
213 m_colorButton->setText(m_brush.color().name());
194 m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum
214 m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum
195 }
215 }
196
216
197 QBrush brush() const
217 QBrush brush() const
198 {
218 {
199 return m_brush;
219 return m_brush;
200 }
220 }
201
221
202 QString name()
222 QString name()
203 {
223 {
204 return name(m_brush);
224 return name(m_brush);
205 }
225 }
206
226
207 static QString name(const QBrush &brush)
227 static QString name(const QBrush &brush)
208 {
228 {
209 return brush.color().name();
229 return brush.color().name();
210 }
230 }
211
231
212 Q_SIGNALS:
232 Q_SIGNALS:
213 void changed();
233 void changed();
214
234
215 public Q_SLOTS:
235 public Q_SLOTS:
216
236
217 void showColorDialog()
237 void showColorDialog()
218 {
238 {
219 QColorDialog dialog(m_brush.color());
239 QColorDialog dialog(m_brush.color());
220 dialog.show();
240 dialog.show();
221 dialog.exec();
241 dialog.exec();
222 m_brush.setColor(dialog.selectedColor());
242 m_brush.setColor(dialog.selectedColor());
223 m_colorButton->setText(m_brush.color().name());
243 m_colorButton->setText(m_brush.color().name());
224 emit changed();
244 emit changed();
225 }
245 }
226
246
227 void updateStyle()
247 void updateStyle()
228 {
248 {
229 Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt();
249 Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt();
230 if (m_brush.style() != style) {
250 if (m_brush.style() != style) {
231 m_brush.setStyle(style);
251 m_brush.setStyle(style);
232 emit changed();
252 emit changed();
233 }
253 }
234 }
254 }
235
255
236 private:
256 private:
237 QBrush m_brush;
257 QBrush m_brush;
238 QPushButton *m_colorButton;
258 QPushButton *m_colorButton;
239 QComboBox *m_styleCombo;
259 QComboBox *m_styleCombo;
240 };
260 };
241
261
242 class CustomSlice : public QPieSlice
262 class CustomSlice : public QPieSlice
243 {
263 {
244 Q_OBJECT
264 Q_OBJECT
245 public:
265 public:
246 CustomSlice(qreal value, QString label)
266 CustomSlice(qreal value, QString label)
247 :QPieSlice(value, label)
267 :QPieSlice(value, label)
248 {
268 {
249 connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter()));
269 connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter()));
250 connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave()));
270 connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave()));
251 }
271 }
252
272
253 public:
273 public:
254 QBrush originalBrush()
274 QBrush originalBrush()
255 {
275 {
256 return m_originalBrush;
276 return m_originalBrush;
257 }
277 }
258
278
259 public Q_SLOTS:
279 public Q_SLOTS:
260
280
261 void handleHoverEnter()
281 void handleHoverEnter()
262 {
282 {
263 QBrush brush = this->brush();
283 QBrush brush = this->brush();
264 m_originalBrush = brush;
284 m_originalBrush = brush;
265 brush.setColor(brush.color().lighter());
285 brush.setColor(brush.color().lighter());
266 setBrush(brush);
286 setBrush(brush);
267 }
287 }
268
288
269 void handleHoverLeave()
289 void handleHoverLeave()
270 {
290 {
271 setBrush(m_originalBrush);
291 setBrush(m_originalBrush);
272 }
292 }
273
293
274 private:
294 private:
275 QBrush m_originalBrush;
295 QBrush m_originalBrush;
276 };
296 };
277
297
278 class MainWidget : public QWidget
298 class MainWidget : public QWidget
279 {
299 {
280 Q_OBJECT
300 Q_OBJECT
281
301
282 public:
302 public:
283 explicit MainWidget(QWidget* parent = 0)
303 explicit MainWidget(QWidget* parent = 0)
284 :QWidget(parent),
304 :QWidget(parent),
285 m_slice(0)
305 m_slice(0)
286 {
306 {
287 // create chart
307 // create chart
288 m_chartView = new QChartView(new QChart());
308 m_chartView = new QChartView(new QChart());
289 m_chartView->chart()->setTitle("Piechart customization");
309 m_chartView->chart()->setTitle("Piechart customization");
290 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
310 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
291
311
292 // create series
312 // create series
293 m_series = new QPieSeries();
313 m_series = new QPieSeries();
294 *m_series << new CustomSlice(10.0, "Slice 1");
314 *m_series << new CustomSlice(10.0, "Slice 1");
295 *m_series << new CustomSlice(20.0, "Slice 2");
315 *m_series << new CustomSlice(20.0, "Slice 2");
296 *m_series << new CustomSlice(30.0, "Slice 3");
316 *m_series << new CustomSlice(30.0, "Slice 3");
297 *m_series << new CustomSlice(40.0, "Slice 4");
317 *m_series << new CustomSlice(40.0, "Slice 4");
298 *m_series << new CustomSlice(50.0, "Slice 5");
318 *m_series << new CustomSlice(50.0, "Slice 5");
299 m_series->setLabelsVisible();
319 m_series->setLabelsVisible();
300 m_chartView->chart()->addSeries(m_series);
320 m_chartView->chart()->addSeries(m_series);
301
321
302 connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons)));
322 connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons)));
303
323
304 // chart settings
324 // chart settings
305 m_themeComboBox = new QComboBox();
325 m_themeComboBox = new QComboBox();
306 m_themeComboBox->addItem("Default", QChart::ChartThemeDefault);
326 m_themeComboBox->addItem("Default", QChart::ChartThemeDefault);
307 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
327 m_themeComboBox->addItem("Light", QChart::ChartThemeLight);
308 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
328 m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean);
309 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
329 m_themeComboBox->addItem("Dark", QChart::ChartThemeDark);
310 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
330 m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand);
311 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
331 m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs);
312 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
332 m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
313 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
333 m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
314
334
315 m_aaCheckBox = new QCheckBox();
335 m_aaCheckBox = new QCheckBox();
316 m_animationsCheckBox = new QCheckBox();
336 m_animationsCheckBox = new QCheckBox();
317 m_animationsCheckBox->setCheckState(Qt::Checked);
337 m_animationsCheckBox->setCheckState(Qt::Checked);
318
338
319 QFormLayout* chartSettingsLayout = new QFormLayout();
339 QFormLayout* chartSettingsLayout = new QFormLayout();
320 chartSettingsLayout->addRow("Theme", m_themeComboBox);
340 chartSettingsLayout->addRow("Theme", m_themeComboBox);
321 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
341 chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox);
322 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
342 chartSettingsLayout->addRow("Animations", m_animationsCheckBox);
323 QGroupBox* chartSettings = new QGroupBox("Chart");
343 QGroupBox* chartSettings = new QGroupBox("Chart");
324 chartSettings->setLayout(chartSettingsLayout);
344 chartSettings->setLayout(chartSettingsLayout);
325
345
326 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
346 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings()));
327 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
347 connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
328 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
348 connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings()));
329
349
330 // series settings
350 // series settings
331 m_hPosition = new QDoubleSpinBox();
351 m_hPosition = new QDoubleSpinBox();
332 m_hPosition->setMinimum(0.0);
352 m_hPosition->setMinimum(0.0);
333 m_hPosition->setMaximum(1.0);
353 m_hPosition->setMaximum(1.0);
334 m_hPosition->setSingleStep(0.1);
354 m_hPosition->setSingleStep(0.1);
335 m_hPosition->setValue(m_series->pieHorizontalPosition());
355 m_hPosition->setValue(m_series->pieHorizontalPosition());
336
356
337 m_vPosition = new QDoubleSpinBox();
357 m_vPosition = new QDoubleSpinBox();
338 m_vPosition->setMinimum(0.0);
358 m_vPosition->setMinimum(0.0);
339 m_vPosition->setMaximum(1.0);
359 m_vPosition->setMaximum(1.0);
340 m_vPosition->setSingleStep(0.1);
360 m_vPosition->setSingleStep(0.1);
341 m_vPosition->setValue(m_series->pieVerticalPosition());
361 m_vPosition->setValue(m_series->pieVerticalPosition());
342
362
343 m_sizeFactor = new QDoubleSpinBox();
363 m_sizeFactor = new QDoubleSpinBox();
344 m_sizeFactor->setMinimum(0.0);
364 m_sizeFactor->setMinimum(0.0);
345 m_sizeFactor->setMaximum(1.0);
365 m_sizeFactor->setMaximum(1.0);
346 m_sizeFactor->setSingleStep(0.1);
366 m_sizeFactor->setSingleStep(0.1);
347 m_sizeFactor->setValue(m_series->pieSize());
367 m_sizeFactor->setValue(m_series->pieSize());
348
368
349 m_startAngle = new QDoubleSpinBox();
369 m_startAngle = new QDoubleSpinBox();
350 m_startAngle->setMinimum(0.0);
370 m_startAngle->setMinimum(0.0);
351 m_startAngle->setMaximum(360);
371 m_startAngle->setMaximum(360);
352 m_startAngle->setValue(m_series->pieStartAngle());
372 m_startAngle->setValue(m_series->pieStartAngle());
353 m_startAngle->setSingleStep(1);
373 m_startAngle->setSingleStep(1);
354
374
355 m_endAngle = new QDoubleSpinBox();
375 m_endAngle = new QDoubleSpinBox();
356 m_endAngle->setMinimum(0.0);
376 m_endAngle->setMinimum(0.0);
357 m_endAngle->setMaximum(360);
377 m_endAngle->setMaximum(360);
358 m_endAngle->setValue(m_series->pieEndAngle());
378 m_endAngle->setValue(m_series->pieEndAngle());
359 m_endAngle->setSingleStep(1);
379 m_endAngle->setSingleStep(1);
360
380
361 QPushButton *addSlice = new QPushButton("Add slice");
381 QPushButton *addSlice = new QPushButton("Add slice");
362 QPushButton *insertSlice = new QPushButton("Insert slice");
382 QPushButton *insertSlice = new QPushButton("Insert slice");
363
383
364 QFormLayout* seriesSettingsLayout = new QFormLayout();
384 QFormLayout* seriesSettingsLayout = new QFormLayout();
365 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
385 seriesSettingsLayout->addRow("Horizontal position", m_hPosition);
366 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
386 seriesSettingsLayout->addRow("Vertical position", m_vPosition);
367 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
387 seriesSettingsLayout->addRow("Size factor", m_sizeFactor);
368 seriesSettingsLayout->addRow("Start angle", m_startAngle);
388 seriesSettingsLayout->addRow("Start angle", m_startAngle);
369 seriesSettingsLayout->addRow("End angle", m_endAngle);
389 seriesSettingsLayout->addRow("End angle", m_endAngle);
370 seriesSettingsLayout->addRow(addSlice);
390 seriesSettingsLayout->addRow(addSlice);
371 seriesSettingsLayout->addRow(insertSlice);
391 seriesSettingsLayout->addRow(insertSlice);
372 QGroupBox* seriesSettings = new QGroupBox("Series");
392 QGroupBox* seriesSettings = new QGroupBox("Series");
373 seriesSettings->setLayout(seriesSettingsLayout);
393 seriesSettings->setLayout(seriesSettingsLayout);
374
394
375 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
395 connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
376 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
396 connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
377 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
397 connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
378 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
398 connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
379 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
399 connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings()));
380 connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice()));
400 connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice()));
381 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
401 connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice()));
382
402
383 // slice settings
403 // slice settings
384 m_sliceName = new QLabel("<click a slice>");
404 m_sliceName = new QLabel("<click a slice>");
385 m_sliceValue = new QDoubleSpinBox();
405 m_sliceValue = new QDoubleSpinBox();
386 m_sliceValue->setMaximum(1000);
406 m_sliceValue->setMaximum(1000);
387 m_sliceLabelVisible = new QCheckBox();
407 m_sliceLabelVisible = new QCheckBox();
388 m_sliceLabelArmFactor = new QDoubleSpinBox();
408 m_sliceLabelArmFactor = new QDoubleSpinBox();
389 m_sliceLabelArmFactor->setSingleStep(0.01);
409 m_sliceLabelArmFactor->setSingleStep(0.01);
390 m_sliceExploded = new QCheckBox();
410 m_sliceExploded = new QCheckBox();
391 m_sliceExplodedFactor = new QDoubleSpinBox();
411 m_sliceExplodedFactor = new QDoubleSpinBox();
392 m_sliceExplodedFactor->setSingleStep(0.01);
412 m_sliceExplodedFactor->setSingleStep(0.01);
393 m_pen = new QPushButton();
413 m_pen = new QPushButton();
394 m_penTool = new PenTool("Slice pen", this);
414 m_penTool = new PenTool("Slice pen", this);
395 m_brush = new QPushButton();
415 m_brush = new QPushButton();
396 m_brushTool = new BrushTool("Slice brush", this);
416 m_brushTool = new BrushTool("Slice brush", this);
397 m_font = new QPushButton();
417 m_font = new QPushButton();
398 m_labelPen = new QPushButton();
418 m_labelPen = new QPushButton();
399 m_labelPenTool = new PenTool("Label pen", this);
419 m_labelPenTool = new PenTool("Label pen", this);
400 QPushButton *removeSlice = new QPushButton("Remove slice");
420 QPushButton *removeSlice = new QPushButton("Remove slice");
401
421
402 QFormLayout* sliceSettingsLayout = new QFormLayout();
422 QFormLayout* sliceSettingsLayout = new QFormLayout();
403 sliceSettingsLayout->addRow("Selected", m_sliceName);
423 sliceSettingsLayout->addRow("Selected", m_sliceName);
404 sliceSettingsLayout->addRow("Value", m_sliceValue);
424 sliceSettingsLayout->addRow("Value", m_sliceValue);
405 sliceSettingsLayout->addRow("Pen", m_pen);
425 sliceSettingsLayout->addRow("Pen", m_pen);
406 sliceSettingsLayout->addRow("Brush", m_brush);
426 sliceSettingsLayout->addRow("Brush", m_brush);
407 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
427 sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible);
408 sliceSettingsLayout->addRow("Label font", m_font);
428 sliceSettingsLayout->addRow("Label font", m_font);
409 sliceSettingsLayout->addRow("Label pen", m_labelPen);
429 sliceSettingsLayout->addRow("Label pen", m_labelPen);
410 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
430 sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor);
411 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
431 sliceSettingsLayout->addRow("Exploded", m_sliceExploded);
412 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
432 sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor);
413 sliceSettingsLayout->addRow(removeSlice);
433 sliceSettingsLayout->addRow(removeSlice);
414 QGroupBox* sliceSettings = new QGroupBox("Slice");
434 QGroupBox* sliceSettings = new QGroupBox("Slice");
415 sliceSettings->setLayout(sliceSettingsLayout);
435 sliceSettings->setLayout(sliceSettingsLayout);
416
436
417 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
437 connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
418 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
438 connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show()));
419 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
439 connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
420 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
440 connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show()));
421 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
441 connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
422 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
442 connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog()));
423 connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show()));
443 connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show()));
424 connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
444 connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings()));
425 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
445 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
426 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
446 connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
427 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
447 connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
428 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
448 connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings()));
429 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
449 connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings()));
430 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
450 connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice()));
431
451
432 // create main layout
452 // create main layout
433 QVBoxLayout *settingsLayout = new QVBoxLayout();
453 QVBoxLayout *settingsLayout = new QVBoxLayout();
434 settingsLayout->addWidget(chartSettings);
454 settingsLayout->addWidget(chartSettings);
435 settingsLayout->addWidget(seriesSettings);
455 settingsLayout->addWidget(seriesSettings);
436 settingsLayout->addWidget(sliceSettings);
456 settingsLayout->addWidget(sliceSettings);
437 settingsLayout->addStretch();
457 settingsLayout->addStretch();
438
458
439 QGridLayout* baseLayout = new QGridLayout();
459 QGridLayout* baseLayout = new QGridLayout();
440 baseLayout->addLayout(settingsLayout, 0, 0);
460 baseLayout->addLayout(settingsLayout, 0, 0);
441 baseLayout->addWidget(m_chartView, 0, 1);
461 baseLayout->addWidget(m_chartView, 0, 1);
442 setLayout(baseLayout);
462 setLayout(baseLayout);
443
463
444 updateSerieSettings();
464 updateSerieSettings();
445 }
465 }
446
466
447 public Q_SLOTS:
467 public Q_SLOTS:
448
468
449 void updateChartSettings()
469 void updateChartSettings()
450 {
470 {
451 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
471 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
452 m_chartView->chart()->setTheme(theme);
472 m_chartView->chart()->setTheme(theme);
453 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
473 m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked());
454
474
455 if (m_animationsCheckBox->checkState() == Qt::Checked)
475 if (m_animationsCheckBox->checkState() == Qt::Checked)
456 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
476 m_chartView->chart()->setAnimationOptions(QChart::AllAnimations);
457 else
477 else
458 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
478 m_chartView->chart()->setAnimationOptions(QChart::NoAnimation);
459 }
479 }
460
480
461 void updateSerieSettings()
481 void updateSerieSettings()
462 {
482 {
463 m_series->setPiePosition(m_hPosition->value(), m_vPosition->value());
483 m_series->setPiePosition(m_hPosition->value(), m_vPosition->value());
464 m_series->setPieSize(m_sizeFactor->value());
484 m_series->setPieSize(m_sizeFactor->value());
465 m_series->setPieStartAngle(m_startAngle->value());
485 m_series->setPieStartAngle(m_startAngle->value());
466 m_series->setPieEndAngle(m_endAngle->value());
486 m_series->setPieEndAngle(m_endAngle->value());
467 }
487 }
468
488
469 void updateSliceSettings()
489 void updateSliceSettings()
470 {
490 {
471 if (!m_slice)
491 if (!m_slice)
472 return;
492 return;
473
493
474 m_slice->setValue(m_sliceValue->value());
494 m_slice->setValue(m_sliceValue->value());
475
495
476 m_slice->setPen(m_penTool->pen());
496 m_slice->setPen(m_penTool->pen());
477 m_slice->setBrush(m_brushTool->brush());
497 m_slice->setBrush(m_brushTool->brush());
478
498
479 m_slice->setLabelPen(m_labelPenTool->pen());
499 m_slice->setLabelPen(m_labelPenTool->pen());
480 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
500 m_slice->setLabelVisible(m_sliceLabelVisible->isChecked());
481 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
501 m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value());
482
502
483 m_slice->setExploded(m_sliceExploded->isChecked());
503 m_slice->setExploded(m_sliceExploded->isChecked());
484 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
504 m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value());
485 }
505 }
486
506
487 void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons)
507 void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons)
488 {
508 {
489 Q_UNUSED(buttons);
509 Q_UNUSED(buttons);
490
510
491 m_slice = static_cast<CustomSlice*>(slice);
511 m_slice = static_cast<CustomSlice*>(slice);
492
512
493 // name
513 // name
494 m_sliceName->setText(slice->label());
514 m_sliceName->setText(slice->label());
495
515
496 // value
516 // value
497 m_sliceValue->blockSignals(true);
517 m_sliceValue->blockSignals(true);
498 m_sliceValue->setValue(slice->value());
518 m_sliceValue->setValue(slice->value());
499 m_sliceValue->blockSignals(false);
519 m_sliceValue->blockSignals(false);
500
520
501 // pen
521 // pen
502 m_pen->setText(PenTool::name(m_slice->pen()));
522 m_pen->setText(PenTool::name(m_slice->pen()));
503 m_penTool->setPen(m_slice->pen());
523 m_penTool->setPen(m_slice->pen());
504
524
505 // brush
525 // brush
506 m_brush->setText(m_slice->originalBrush().color().name());
526 m_brush->setText(m_slice->originalBrush().color().name());
507 m_brushTool->setBrush(m_slice->originalBrush());
527 m_brushTool->setBrush(m_slice->originalBrush());
508
528
509 // label
529 // label
510 m_labelPen->setText(PenTool::name(m_slice->labelPen()));
530 m_labelPen->setText(PenTool::name(m_slice->labelPen()));
511 m_labelPenTool->setPen(m_slice->labelPen());
531 m_labelPenTool->setPen(m_slice->labelPen());
512 m_font->setText(slice->labelFont().toString());
532 m_font->setText(slice->labelFont().toString());
513 m_sliceLabelVisible->blockSignals(true);
533 m_sliceLabelVisible->blockSignals(true);
514 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
534 m_sliceLabelVisible->setChecked(slice->isLabelVisible());
515 m_sliceLabelVisible->blockSignals(false);
535 m_sliceLabelVisible->blockSignals(false);
516 m_sliceLabelArmFactor->blockSignals(true);
536 m_sliceLabelArmFactor->blockSignals(true);
517 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
537 m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor());
518 m_sliceLabelArmFactor->blockSignals(false);
538 m_sliceLabelArmFactor->blockSignals(false);
519
539
520 // exploded
540 // exploded
521 m_sliceExploded->blockSignals(true);
541 m_sliceExploded->blockSignals(true);
522 m_sliceExploded->setChecked(slice->isExploded());
542 m_sliceExploded->setChecked(slice->isExploded());
523 m_sliceExploded->blockSignals(false);
543 m_sliceExploded->blockSignals(false);
524 m_sliceExplodedFactor->blockSignals(true);
544 m_sliceExplodedFactor->blockSignals(true);
525 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
545 m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor());
526 m_sliceExplodedFactor->blockSignals(false);
546 m_sliceExplodedFactor->blockSignals(false);
527 }
547 }
528
548
529 void showFontDialog()
549 void showFontDialog()
530 {
550 {
531 if (!m_slice)
551 if (!m_slice)
532 return;
552 return;
533
553
534 QFontDialog dialog(m_slice->labelFont());
554 QFontDialog dialog(m_slice->labelFont());
535 dialog.show();
555 dialog.show();
536 dialog.exec();
556 dialog.exec();
537
557
538 m_slice->setLabelFont(dialog.currentFont());
558 m_slice->setLabelFont(dialog.currentFont());
539 m_font->setText(dialog.currentFont().toString());
559 m_font->setText(dialog.currentFont().toString());
540 }
560 }
541
561
542 void addSlice()
562 void addSlice()
543 {
563 {
544 *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1));
564 *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1));
545 }
565 }
546
566
547 void insertSlice()
567 void insertSlice()
548 {
568 {
549 if (!m_slice)
569 if (!m_slice)
550 return;
570 return;
551
571
552 int i = m_series->slices().indexOf(m_slice);
572 int i = m_series->slices().indexOf(m_slice);
553
573
554 m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)));
574 m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)));
555 }
575 }
556
576
557 void removeSlice()
577 void removeSlice()
558 {
578 {
559 if (!m_slice)
579 if (!m_slice)
560 return;
580 return;
561
581
562 m_series->remove(m_slice);
582 m_series->remove(m_slice);
563 m_slice = 0;
583 m_slice = 0;
564 }
584 }
565
585
566 private:
586 private:
567 QComboBox *m_themeComboBox;
587 QComboBox *m_themeComboBox;
568 QCheckBox *m_aaCheckBox;
588 QCheckBox *m_aaCheckBox;
569 QCheckBox *m_animationsCheckBox;
589 QCheckBox *m_animationsCheckBox;
570
590
571 QChartView* m_chartView;
591 QChartView* m_chartView;
572 QPieSeries* m_series;
592 QPieSeries* m_series;
573 CustomSlice* m_slice;
593 CustomSlice* m_slice;
574
594
575 QDoubleSpinBox* m_hPosition;
595 QDoubleSpinBox* m_hPosition;
576 QDoubleSpinBox* m_vPosition;
596 QDoubleSpinBox* m_vPosition;
577 QDoubleSpinBox* m_sizeFactor;
597 QDoubleSpinBox* m_sizeFactor;
578 QDoubleSpinBox* m_startAngle;
598 QDoubleSpinBox* m_startAngle;
579 QDoubleSpinBox* m_endAngle;
599 QDoubleSpinBox* m_endAngle;
580
600
581 QLabel* m_sliceName;
601 QLabel* m_sliceName;
582 QDoubleSpinBox* m_sliceValue;
602 QDoubleSpinBox* m_sliceValue;
583 QCheckBox* m_sliceLabelVisible;
603 QCheckBox* m_sliceLabelVisible;
584 QDoubleSpinBox* m_sliceLabelArmFactor;
604 QDoubleSpinBox* m_sliceLabelArmFactor;
585 QCheckBox* m_sliceExploded;
605 QCheckBox* m_sliceExploded;
586 QDoubleSpinBox* m_sliceExplodedFactor;
606 QDoubleSpinBox* m_sliceExplodedFactor;
587 QPushButton *m_brush;
607 QPushButton *m_brush;
588 BrushTool *m_brushTool;
608 BrushTool *m_brushTool;
589 QPushButton *m_pen;
609 QPushButton *m_pen;
590 PenTool *m_penTool;
610 PenTool *m_penTool;
591 QPushButton *m_font;
611 QPushButton *m_font;
592 QPushButton *m_labelPen;
612 QPushButton *m_labelPen;
593 PenTool *m_labelPenTool;
613 PenTool *m_labelPenTool;
594 };
614 };
595
615
596 int main(int argc, char *argv[])
616 int main(int argc, char *argv[])
597 {
617 {
598 QApplication a(argc, argv);
618 QApplication a(argc, argv);
599
619
600 QMainWindow window;
620 QMainWindow window;
601
621
602 MainWidget* widget = new MainWidget();
622 MainWidget* widget = new MainWidget();
603
623
604 window.setCentralWidget(widget);
624 window.setCentralWidget(widget);
605 window.resize(900, 600);
625 window.resize(900, 600);
606 window.show();
626 window.show();
607
627
608 return a.exec();
628 return a.exec();
609 }
629 }
610
630
611 #include "main.moc"
631 #include "main.moc"
@@ -1,92 +1,73
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include <QApplication>
21 #include <QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QLineSeries>
24 #include <QLineSeries>
44 #include <QAreaSeries>
25 #include <QAreaSeries>
45
26
46 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
47
28
48 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
49 {
30 {
50 QApplication a(argc, argv);
31 QApplication a(argc, argv);
51 //![1]
32 //![1]
52 QLineSeries* series0 = new QLineSeries();
33 QLineSeries* series0 = new QLineSeries();
53 QLineSeries* series1 = new QLineSeries();
34 QLineSeries* series1 = new QLineSeries();
54 //![1]
35 //![1]
55
36
56 //![2]
37 //![2]
57 *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6)
38 *series0 << QPointF(1, 5) << QPointF(3, 7) << QPointF(7, 6) << QPointF(9, 7) << QPointF(12, 6)
58 << QPointF(16, 7) << QPointF(18, 5);
39 << QPointF(16, 7) << QPointF(18, 5);
59 *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3)
40 *series1 << QPointF(1, 3) << QPointF(3, 4) << QPointF(7, 3) << QPointF(8, 2) << QPointF(12, 3)
60 << QPointF(16, 4) << QPointF(18, 3);
41 << QPointF(16, 4) << QPointF(18, 3);
61 //![2]
42 //![2]
62 //![3]
43 //![3]
63 QAreaSeries* series = new QAreaSeries(series0, series1);
44 QAreaSeries* series = new QAreaSeries(series0, series1);
64 QPen pen(0x059605);
45 QPen pen(0x059605);
65 pen.setWidth(3);
46 pen.setWidth(3);
66 series->setPen(pen);
47 series->setPen(pen);
67
48
68 QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
49 QLinearGradient gradient(QPointF(0, 0), QPointF(0, 1));
69 gradient.setColorAt(0.0, 0x3cc63c);
50 gradient.setColorAt(0.0, 0x3cc63c);
70 gradient.setColorAt(1.0, 0x26f626);
51 gradient.setColorAt(1.0, 0x26f626);
71 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
52 gradient.setCoordinateMode(QGradient::ObjectBoundingMode);
72 series->setBrush(gradient);
53 series->setBrush(gradient);
73 //![3]
54 //![3]
74 //![4]
55 //![4]
75 QChart* chart = new QChart();
56 QChart* chart = new QChart();
76 chart->addSeries(series);
57 chart->addSeries(series);
77 chart->setTitle("Simple areachart example");
58 chart->setTitle("Simple areachart example");
78 chart->axisX()->setRange(0, 20);
59 chart->axisX()->setRange(0, 20);
79 chart->axisY()->setRange(0, 10);
60 chart->axisY()->setRange(0, 10);
80 //![4]
61 //![4]
81 //![5]
62 //![5]
82 QChartView* chartView = new QChartView(chart);
63 QChartView* chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
64 chartView->setRenderHint(QPainter::Antialiasing);
84 //![5]
65 //![5]
85 //![6]
66 //![6]
86 QMainWindow window;
67 QMainWindow window;
87 window.setCentralWidget(chartView);
68 window.setCentralWidget(chartView);
88 window.resize(400, 300);
69 window.resize(400, 300);
89 window.show();
70 window.show();
90 //![6]
71 //![6]
91 return a.exec();
72 return a.exec();
92 }
73 }
@@ -1,92 +1,73
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include <QApplication>
21 #include <QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QBarSeries>
24 #include <QBarSeries>
44 #include <QBarSet>
25 #include <QBarSet>
45
26
46 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
47
28
48 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
49 {
30 {
50 QApplication a(argc, argv);
31 QApplication a(argc, argv);
51 //![1]
32 //![1]
52 QBarCategories categories;
33 QBarCategories categories;
53 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
34 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
54 //![1]
35 //![1]
55 //![2]
36 //![2]
56 QBarSet *set0 = new QBarSet("Bub");
37 QBarSet *set0 = new QBarSet("Bub");
57 QBarSet *set1 = new QBarSet("Bob");
38 QBarSet *set1 = new QBarSet("Bob");
58 QBarSet *set2 = new QBarSet("Guybrush");
39 QBarSet *set2 = new QBarSet("Guybrush");
59 QBarSet *set3 = new QBarSet("Larry");
40 QBarSet *set3 = new QBarSet("Larry");
60 QBarSet *set4 = new QBarSet("Zak");
41 QBarSet *set4 = new QBarSet("Zak");
61
42
62 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
63 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
64 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
65 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
66 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
67 //![2]
48 //![2]
68 //![3]
49 //![3]
69 QBarSeries* series = new QBarSeries(categories);
50 QBarSeries* series = new QBarSeries(categories);
70 series->appendBarSet(set0);
51 series->appendBarSet(set0);
71 series->appendBarSet(set1);
52 series->appendBarSet(set1);
72 series->appendBarSet(set2);
53 series->appendBarSet(set2);
73 series->appendBarSet(set3);
54 series->appendBarSet(set3);
74 series->appendBarSet(set4);
55 series->appendBarSet(set4);
75 //![3]
56 //![3]
76 //![4]
57 //![4]
77 QChart* chart = new QChart();
58 QChart* chart = new QChart();
78 chart->addSeries(series);
59 chart->addSeries(series);
79 chart->setTitle("Simple barchart example");
60 chart->setTitle("Simple barchart example");
80 //![4]
61 //![4]
81 //![5]
62 //![5]
82 QChartView* chartView = new QChartView(chart);
63 QChartView* chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
64 chartView->setRenderHint(QPainter::Antialiasing);
84 //![5]
65 //![5]
85 //![6]
66 //![6]
86 QMainWindow window;
67 QMainWindow window;
87 window.setCentralWidget(chartView);
68 window.setCentralWidget(chartView);
88 window.resize(400, 300);
69 window.resize(400, 300);
89 window.show();
70 window.show();
90 //![6]
71 //![6]
91 return a.exec();
72 return a.exec();
92 }
73 }
@@ -1,83 +1,103
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include <QMainWindow>
22 #include <QMainWindow>
3 #include <qchartglobal.h>
23 #include <qchartglobal.h>
4 #include <qchartview.h>
24 #include <qchartview.h>
5 #include <qlineseries.h>
25 #include <qlineseries.h>
6 #include <qscatterseries.h>
26 #include <qscatterseries.h>
7 #include <qbarseries.h>
27 #include <qbarseries.h>
8 #include <qbarset.h>
28 #include <qbarset.h>
9 #include <qpieseries.h>
29 #include <qpieseries.h>
10 #include <QStringList>
30 #include <QStringList>
11
31
12 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
13
33
14 int main(int argc, char *argv[])
34 int main(int argc, char *argv[])
15 {
35 {
16 QApplication a(argc, argv);
36 QApplication a(argc, argv);
17
37
18 //! [1]
38 //! [1]
19 // Create chart view
39 // Create chart view
20 QChartView *chartView = new QChartView();
40 QChartView *chartView = new QChartView();
21 chartView->setRenderHint(QPainter::Antialiasing);
41 chartView->setRenderHint(QPainter::Antialiasing);
22 chartView->setChartTitle("Simple Line Chart");
42 chartView->setChartTitle("Simple Line Chart");
23 // Add series to the chart
43 // Add series to the chart
24 QLineSeries *line = new QLineSeries();
44 QLineSeries *line = new QLineSeries();
25 line->append(0.0, 0.8);
45 line->append(0.0, 0.8);
26 line->append(1.1, 1.1);
46 line->append(1.1, 1.1);
27 line->append(2.0, 2.5);
47 line->append(2.0, 2.5);
28 chartView->addSeries(line);
48 chartView->addSeries(line);
29 //! [1]
49 //! [1]
30
50
31 chartView->setChartTitle("\'Scietific\' theme");
51 chartView->setChartTitle("\'Scietific\' theme");
32 //! [2]
52 //! [2]
33 // Change theme
53 // Change theme
34 chartView->setChartTheme(QChart::ChartThemeHighContrast);
54 chartView->setChartTheme(QChart::ChartThemeHighContrast);
35 //! [2]
55 //! [2]
36
56
37 chartView->setChartTitle("Simple Pie Chart");
57 chartView->setChartTitle("Simple Pie Chart");
38 //! [3]
58 //! [3]
39 // Add pie series
59 // Add pie series
40 // ...
60 // ...
41 QPieSeries *pie = new QPieSeries();
61 QPieSeries *pie = new QPieSeries();
42 pie->append(3.4, "slice1");
62 pie->append(3.4, "slice1");
43 pie->append(6.7, "slice2");
63 pie->append(6.7, "slice2");
44 chartView->addSeries(pie);
64 chartView->addSeries(pie);
45 //! [3]
65 //! [3]
46
66
47 chartView->setChartTitle("Simple Scatter Chart");
67 chartView->setChartTitle("Simple Scatter Chart");
48 //! [4]
68 //! [4]
49 // Add scatter series
69 // Add scatter series
50 // ...
70 // ...
51 QScatterSeries *scatter = new QScatterSeries();
71 QScatterSeries *scatter = new QScatterSeries();
52 for (qreal x(0); x < 100; x += 0.5) {
72 for (qreal x(0); x < 100; x += 0.5) {
53 qreal y = rand() % 100;
73 qreal y = rand() % 100;
54 *(scatter) << QPointF(x, y);
74 *(scatter) << QPointF(x, y);
55 }
75 }
56 chartView->addSeries(scatter);
76 chartView->addSeries(scatter);
57 //! [4]
77 //! [4]
58
78
59 chartView->setChartTitle("Simple Bar Chart");
79 chartView->setChartTitle("Simple Bar Chart");
60 //! [5]
80 //! [5]
61 // ...
81 // ...
62 // Add bar series
82 // Add bar series
63 QStringList barCategory;
83 QStringList barCategory;
64 barCategory << "Jan"
84 barCategory << "Jan"
65 << "Feb"
85 << "Feb"
66 << "Mar";
86 << "Mar";
67 QBarSeries *bar = new QBarSeries(barCategory);
87 QBarSeries *bar = new QBarSeries(barCategory);
68 QBarSet *barSet = new QBarSet("Sales");
88 QBarSet *barSet = new QBarSet("Sales");
69 *barSet << 123.2
89 *barSet << 123.2
70 << 301.3
90 << 301.3
71 << 285.8;
91 << 285.8;
72 bar->addBarSet(barSet);
92 bar->addBarSet(barSet);
73 chartView->addSeries(bar);
93 chartView->addSeries(bar);
74 //! [5]
94 //! [5]
75
95
76 QMainWindow w;
96 QMainWindow w;
77 w.resize(400, 300);
97 w.resize(400, 300);
78 w.setCentralWidget(chartView);
98 w.setCentralWidget(chartView);
79 w.setWindowFlags(Qt::FramelessWindowHint);
99 w.setWindowFlags(Qt::FramelessWindowHint);
80 w.show();
100 w.show();
81
101
82 return a.exec();
102 return a.exec();
83 }
103 }
@@ -1,122 +1,103
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
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.
11 **
14 **
12 ** "Redistribution and use in source and binary forms, with or without
15 ** If you have questions regarding the use of this file, please use
13 ** modification, are permitted provided that the following conditions are
16 ** contact form at http://qt.digia.com
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
37 **
18 **
38 ****************************************************************************/
19 ****************************************************************************/
39
20
40 #include <QApplication>
21 #include <QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QLineSeries>
24 #include <QLineSeries>
44
25
45 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
46
27
47 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
48 {
29 {
49 QApplication a(argc, argv);
30 QApplication a(argc, argv);
50
31
51 //![1]
32 //![1]
52 QLineSeries* series = new QLineSeries();
33 QLineSeries* series = new QLineSeries();
53 QPen blue(Qt::yellow);
34 QPen blue(Qt::yellow);
54 blue.setWidth(3);
35 blue.setWidth(3);
55 series->setPen(blue);
36 series->setPen(blue);
56 //![1]
37 //![1]
57 //![2]
38 //![2]
58 *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5);
39 *series << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10,5);
59 //![2]
40 //![2]
60 //![3]
41 //![3]
61 QChart* chart = new QChart();
42 QChart* chart = new QChart();
62 chart->addSeries(series);
43 chart->addSeries(series);
63 chart->setTitle("Simple customchart example");
44 chart->setTitle("Simple customchart example");
64 //![3]
45 //![3]
65 //![4]
46 //![4]
66 QFont font;
47 QFont font;
67 font.setPixelSize(18);
48 font.setPixelSize(18);
68 chart->setTitleFont(font);
49 chart->setTitleFont(font);
69 chart->setTitleBrush(Qt::yellow);
50 chart->setTitleBrush(Qt::yellow);
70
51
71 QLinearGradient backgroundGradient;
52 QLinearGradient backgroundGradient;
72 backgroundGradient.setStart(QPointF(0,0));
53 backgroundGradient.setStart(QPointF(0,0));
73 backgroundGradient.setFinalStop(QPointF(0,1));
54 backgroundGradient.setFinalStop(QPointF(0,1));
74 backgroundGradient.setColorAt(0.0, 0x3cc63c);
55 backgroundGradient.setColorAt(0.0, 0x3cc63c);
75 backgroundGradient.setColorAt(1.0, 0x26f626);
56 backgroundGradient.setColorAt(1.0, 0x26f626);
76 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
57 backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
77 chart->setBackgroundBrush(backgroundGradient);
58 chart->setBackgroundBrush(backgroundGradient);
78 //![4]
59 //![4]
79 //![5]
60 //![5]
80 QPen black(Qt::black);
61 QPen black(Qt::black);
81 QChartAxis* axisX = chart->axisX();
62 QChartAxis* axisX = chart->axisX();
82 QChartAxis* axisY = chart->axisY();
63 QChartAxis* axisY = chart->axisY();
83
64
84 axisX->setAxisPen(black);
65 axisX->setAxisPen(black);
85 axisY->setAxisPen(black);
66 axisY->setAxisPen(black);
86 axisX->setGridLineVisible(false);
67 axisX->setGridLineVisible(false);
87 axisY->setGridLineVisible(false);
68 axisY->setGridLineVisible(false);
88
69
89 axisY->setShadesPen(Qt::NoPen);
70 axisY->setShadesPen(Qt::NoPen);
90 axisY->setShadesOpacity(0.5);
71 axisY->setShadesOpacity(0.5);
91 axisY->setShadesBrush(Qt::white);
72 axisY->setShadesBrush(Qt::white);
92 axisY->setShadesVisible(true);
73 axisY->setShadesVisible(true);
93 //![5]
74 //![5]
94 //![6]
75 //![6]
95 QChartAxisCategories* categoriesX = chart->axisX()->categories();
76 QChartAxisCategories* categoriesX = chart->axisX()->categories();
96 categoriesX->insert(1,"low");
77 categoriesX->insert(1,"low");
97 categoriesX->insert(5,"optimal");
78 categoriesX->insert(5,"optimal");
98 categoriesX->insert(10,"high");
79 categoriesX->insert(10,"high");
99
80
100 QChartAxisCategories* categoriesY = chart->axisY()->categories();
81 QChartAxisCategories* categoriesY = chart->axisY()->categories();
101 categoriesY->insert(1,"slow");
82 categoriesY->insert(1,"slow");
102 categoriesY->insert(5,"med");
83 categoriesY->insert(5,"med");
103 categoriesY->insert(10,"fast");
84 categoriesY->insert(10,"fast");
104 //![6]
85 //![6]
105 //![7]
86 //![7]
106 axisX->setRange(0,10);
87 axisX->setRange(0,10);
107 axisX->setTicksCount(4);
88 axisX->setTicksCount(4);
108 axisY->setRange(0,10);
89 axisY->setRange(0,10);
109 axisY->setTicksCount(4);
90 axisY->setTicksCount(4);
110 //![7]
91 //![7]
111 //![8]
92 //![8]
112 QChartView* chartView = new QChartView(chart);
93 QChartView* chartView = new QChartView(chart);
113 chartView->setRenderHint(QPainter::Antialiasing);
94 chartView->setRenderHint(QPainter::Antialiasing);
114 //![8]
95 //![8]
115 //![9]
96 //![9]
116 QMainWindow window;
97 QMainWindow window;
117 window.setCentralWidget(chartView);
98 window.setCentralWidget(chartView);
118 window.resize(400, 300);
99 window.resize(400, 300);
119 window.show();
100 window.show();
120 //![9]
101 //![9]
121 return a.exec();
102 return a.exec();
122 }
103 }
@@ -1,41 +1,61
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
1 #include <QApplication>
21 #include <QApplication>
2 #include <QMainWindow>
22 #include <QMainWindow>
3 #include <qchartview.h>
23 #include <qchartview.h>
4 #include <qlineseries.h>
24 #include <qlineseries.h>
5 #include <qchart.h>
25 #include <qchart.h>
6 #include <cmath>
26 #include <cmath>
7 #include "wavegenerator.h"
27 #include "wavegenerator.h"
8 #include <QGLWidget>
28 #include <QGLWidget>
9
29
10 int main(int argc, char *argv[])
30 int main(int argc, char *argv[])
11 {
31 {
12 QApplication a(argc, argv);
32 QApplication a(argc, argv);
13
33
14 QMainWindow window;
34 QMainWindow window;
15
35
16 QLineSeries* series0 = new QLineSeries();
36 QLineSeries* series0 = new QLineSeries();
17 QPen blue(Qt::blue);
37 QPen blue(Qt::blue);
18 blue.setWidth(3);
38 blue.setWidth(3);
19 series0->setPen(blue);
39 series0->setPen(blue);
20 QLineSeries* series1 = new QLineSeries();
40 QLineSeries* series1 = new QLineSeries();
21 QPen red(Qt::red);
41 QPen red(Qt::red);
22 red.setWidth(3);
42 red.setWidth(3);
23 series1->setPen(red);
43 series1->setPen(red);
24
44
25 WaveGenerator generator(series0,series1);
45 WaveGenerator generator(series0,series1);
26
46
27 QChartView* chartView = new QChartView(&window);
47 QChartView* chartView = new QChartView(&window);
28
48
29 chartView->setViewport( new QGLWidget() );
49 chartView->setViewport( new QGLWidget() );
30 chartView->setRenderHint(QPainter::Antialiasing);
50 chartView->setRenderHint(QPainter::Antialiasing);
31 chartView->setAnimationOptions(QChart::AllAnimations);
51 chartView->setAnimationOptions(QChart::AllAnimations);
32 chartView->setChartTitle("This is wave generator buahha.");
52 chartView->setChartTitle("This is wave generator buahha.");
33 chartView->addSeries(series0);
53 chartView->addSeries(series0);
34 chartView->addSeries(series1);
54 chartView->addSeries(series1);
35
55
36 window.setCentralWidget(chartView);
56 window.setCentralWidget(chartView);
37 window.resize(400, 300);
57 window.resize(400, 300);
38 window.show();
58 window.show();
39
59
40 return a.exec();
60 return a.exec();
41 }
61 }
@@ -1,60 +1,80
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
1 #include <QTimer>
21 #include <QTimer>
2 #include <QTime>
22 #include <QTime>
3 #include <QObject>
23 #include <QObject>
4 #include <cmath>
24 #include <cmath>
5 #include <qlineseries.h>
25 #include <qlineseries.h>
6
26
7 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
8
28
9 #define PI 3.14159265358979
29 #define PI 3.14159265358979
10 static const int numPoints =100;
30 static const int numPoints =100;
11
31
12 class WaveGenerator: public QObject
32 class WaveGenerator: public QObject
13 {
33 {
14 Q_OBJECT
34 Q_OBJECT
15
35
16 public:
36 public:
17 WaveGenerator(QLineSeries* series1, QLineSeries* series2) :
37 WaveGenerator(QLineSeries* series1, QLineSeries* series2) :
18 m_series1(series1),
38 m_series1(series1),
19 m_series2(series2),
39 m_series2(series2),
20 m_wave(0),
40 m_wave(0),
21 m_step(2*PI/numPoints)
41 m_step(2*PI/numPoints)
22 {
42 {
23
43
24 QTime now = QTime::currentTime();
44 QTime now = QTime::currentTime();
25 qsrand((uint)now.msec());
45 qsrand((uint)now.msec());
26
46
27 int fluctuate = 100;
47 int fluctuate = 100;
28
48
29 for (qreal x = 0; x <= 2*PI; x+=m_step) {
49 for (qreal x = 0; x <= 2*PI; x+=m_step) {
30 series1->append(x, fabs(sin(x)*fluctuate));
50 series1->append(x, fabs(sin(x)*fluctuate));
31 series2->append(x, fabs(cos(x)*fluctuate));
51 series2->append(x, fabs(cos(x)*fluctuate));
32 }
52 }
33
53
34 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(update()));
54 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(update()));
35 m_timer.setInterval(5000);
55 m_timer.setInterval(5000);
36 m_timer.start();
56 m_timer.start();
37
57
38 };
58 };
39
59
40 public slots:
60 public slots:
41 void update()
61 void update()
42 {
62 {
43 int fluctuate;
63 int fluctuate;
44
64
45 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
65 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
46 fluctuate = qrand() % 100;
66 fluctuate = qrand() % 100;
47 m_series1->replace(x, fabs(sin(x)*fluctuate));
67 m_series1->replace(x, fabs(sin(x)*fluctuate));
48 fluctuate = qrand() % 100;
68 fluctuate = qrand() % 100;
49 m_series2->replace(x, fabs(cos(x)*fluctuate));
69 m_series2->replace(x, fabs(cos(x)*fluctuate));
50 }
70 }
51
71
52 }
72 }
53
73
54 private:
74 private:
55 QLineSeries* m_series1;
75 QLineSeries* m_series1;
56 QLineSeries* m_series2;
76 QLineSeries* m_series2;
57 int m_wave;
77 int m_wave;
58 qreal m_step;
78 qreal m_step;
59 QTimer m_timer;
79 QTimer m_timer;
60 };
80 };
@@ -1,57 +1,77
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
1 #include "chartview.h"
21 #include "chartview.h"
2 #include <QSplineSeries>
22 #include <QSplineSeries>
3 #include <QTime>
23 #include <QTime>
4
24
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
25 ChartView::ChartView(QWidget* parent):QChartView(parent),
6 m_step(1),
26 m_step(1),
7 m_x(0),
27 m_x(0),
8 m_y(1)
28 m_y(1)
9 {
29 {
10 QTime now = QTime::currentTime();
30 QTime now = QTime::currentTime();
11 qsrand((uint)now.msec());
31 qsrand((uint)now.msec());
12 setChartTitle("Three random line charts");
32 setChartTitle("Three random line charts");
13
33
14 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
34 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
15 m_timer.setInterval(1000);
35 m_timer.setInterval(1000);
16
36
17 m_series0 = new QLineSeries(this);
37 m_series0 = new QLineSeries(this);
18 QPen blue(Qt::blue);
38 QPen blue(Qt::blue);
19 blue.setWidth(3);
39 blue.setWidth(3);
20 m_series0->setPen(blue);
40 m_series0->setPen(blue);
21
41
22
42
23 m_series1 = new QSplineSeries(this);
43 m_series1 = new QSplineSeries(this);
24 QPen green(Qt::red);
44 QPen green(Qt::red);
25 green.setWidth(3);
45 green.setWidth(3);
26 m_series1->setPen(green);
46 m_series1->setPen(green);
27
47
28 m_series0->append(m_x,m_y);
48 m_series0->append(m_x,m_y);
29 m_series1->append(m_x,m_y);
49 m_series1->append(m_x,m_y);
30
50
31 setChartTitle("Simple EKG chart");
51 setChartTitle("Simple EKG chart");
32 addSeries(m_series0);
52 addSeries(m_series0);
33 addSeries(m_series1);
53 addSeries(m_series1);
34 axisY()->setRange(-5,5);
54 axisY()->setRange(-5,5);
35 axisX()->setRange(-9,1);
55 axisX()->setRange(-9,1);
36 axisX()->setTicksCount(11);
56 axisX()->setTicksCount(11);
37 m_timer.start();
57 m_timer.start();
38 }
58 }
39
59
40 ChartView::~ChartView()
60 ChartView::~ChartView()
41 {
61 {
42
62
43 }
63 }
44
64
45 void ChartView::handleTimeout()
65 void ChartView::handleTimeout()
46 {
66 {
47 m_x+=m_step;
67 m_x+=m_step;
48 m_y = qrand() % 5 - 2.5;
68 m_y = qrand() % 5 - 2.5;
49 m_series0->append(m_x,m_y);
69 m_series0->append(m_x,m_y);
50 m_series1->append(m_x,m_y);
70 m_series1->append(m_x,m_y);
51 if(m_x>=10)
71 if(m_x>=10)
52 {
72 {
53 m_series0->remove(m_x-10);
73 m_series0->remove(m_x-10);
54 m_series1->remove(m_x-10);
74 m_series1->remove(m_x-10);
55 }
75 }
56 scrollRight();
76 scrollRight();
57 }
77 }
@@ -1,37 +1,57
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
1 #ifndef CHARTVIEW_H_
21 #ifndef CHARTVIEW_H_
2 #define CHARTVIEW_H_
22 #define CHARTVIEW_H_
3
23
4 #include <QChartView>
24 #include <QChartView>
5 #include <QTimer>
25 #include <QTimer>
6
26
7
27
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 class QSplineSeries;
29 class QSplineSeries;
10 class QLineSeries;
30 class QLineSeries;
11 QTCOMMERCIALCHART_END_NAMESPACE
31 QTCOMMERCIALCHART_END_NAMESPACE
12
32
13 QTCOMMERCIALCHART_USE_NAMESPACE
33 QTCOMMERCIALCHART_USE_NAMESPACE
14
34
15 //![1]
35 //![1]
16 class ChartView: public QChartView
36 class ChartView: public QChartView
17 {
37 {
18 Q_OBJECT
38 Q_OBJECT
19 public:
39 public:
20 ChartView(QWidget* parent = 0);
40 ChartView(QWidget* parent = 0);
21 virtual ~ChartView();
41 virtual ~ChartView();
22
42
23 public slots:
43 public slots:
24 void handleTimeout();
44 void handleTimeout();
25
45
26 private:
46 private:
27 QTimer m_timer;
47 QTimer m_timer;
28 QLineSeries* m_series0;
48 QLineSeries* m_series0;
29 QSplineSeries* m_series1;
49 QSplineSeries* m_series1;
30 QStringList m_titles;
50 QStringList m_titles;
31 qreal m_step;
51 qreal m_step;
32 qreal m_x;
52 qreal m_x;
33 qreal m_y;
53 qreal m_y;
34 };
54 };
35 //![1]
55 //![1]
36
56
37 #endif /* CHARTVIEW_H_ */
57 #endif /* CHARTVIEW_H_ */
@@ -1,16 +1,36
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
1 #include "chartview.h"
21 #include "chartview.h"
2 #include <QApplication>
22 #include <QApplication>
3 #include <QMainWindow>
23 #include <QMainWindow>
4
24
5 int main(int argc, char *argv[])
25 int main(int argc, char *argv[])
6 {
26 {
7 QApplication a(argc, argv);
27 QApplication a(argc, argv);
8 QMainWindow window;
28 QMainWindow window;
9 ChartView chartView(&window);
29 ChartView chartView(&window);
10 chartView.setRenderHint(QPainter::Antialiasing);
30 chartView.setRenderHint(QPainter::Antialiasing);
11 chartView.setAnimationOptions(QChart::AllAnimations);
31 chartView.setAnimationOptions(QChart::AllAnimations);
12 window.setCentralWidget(&chartView);
32 window.setCentralWidget(&chartView);
13 window.resize(400, 300);
33 window.resize(400, 300);
14 window.show();
34 window.show();
15 return a.exec();
35 return a.exec();
16 }
36 }
@@ -1,89 +1,70
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
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.
11 **
14 **
12 ** "Redistribution and use in source and binary forms, with or without
15 ** If you have questions regarding the use of this file, please use
13 ** modification, are permitted provided that the following conditions are
16 ** contact form at http://qt.digia.com
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
37 **
18 **
38 ****************************************************************************/
19 ****************************************************************************/
39
20
40 #include <QApplication>
21 #include <QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QLineSeries>
24 #include <QLineSeries>
44
25
45 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
46
27
47 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
48 {
29 {
49 QApplication a(argc, argv);
30 QApplication a(argc, argv);
50 //![1]
31 //![1]
51 QLineSeries* series0 = new QLineSeries();
32 QLineSeries* series0 = new QLineSeries();
52 QPen blue(Qt::blue);
33 QPen blue(Qt::blue);
53 blue.setWidth(3);
34 blue.setWidth(3);
54 series0->setPen(blue);
35 series0->setPen(blue);
55
36
56 QLineSeries* series1 = new QLineSeries();
37 QLineSeries* series1 = new QLineSeries();
57 QPen red(Qt::red);
38 QPen red(Qt::red);
58 red.setWidth(3);
39 red.setWidth(3);
59 series1->setPen(red);
40 series1->setPen(red);
60 //![1]
41 //![1]
61
42
62 //![2]
43 //![2]
63 series0->append(0, 6);
44 series0->append(0, 6);
64 series0->append(2, 4);
45 series0->append(2, 4);
65 series0->append(3, 8);
46 series0->append(3, 8);
66 series0->append(7, 4);
47 series0->append(7, 4);
67 series0->append(10, 5);
48 series0->append(10, 5);
68
49
69 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
50 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
70 //![2]
51 //![2]
71 //![3]
52 //![3]
72 QChart* chart = new QChart();
53 QChart* chart = new QChart();
73
54
74 chart->addSeries(series0);
55 chart->addSeries(series0);
75 chart->addSeries(series1);
56 chart->addSeries(series1);
76 chart->setTitle("Simple line chart example");
57 chart->setTitle("Simple line chart example");
77 //![3]
58 //![3]
78 //![4]
59 //![4]
79 QChartView* chartView = new QChartView(chart);
60 QChartView* chartView = new QChartView(chart);
80 chartView->setRenderHint(QPainter::Antialiasing);
61 chartView->setRenderHint(QPainter::Antialiasing);
81 //![4]
62 //![4]
82 //![5]
63 //![5]
83 QMainWindow window;
64 QMainWindow window;
84 window.setCentralWidget(chartView);
65 window.setCentralWidget(chartView);
85 window.resize(400, 300);
66 window.resize(400, 300);
86 window.show();
67 window.show();
87 //![5]
68 //![5]
88 return a.exec();
69 return a.exec();
89 }
70 }
@@ -1,18 +1,38
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include <QMainWindow>
22 #include <QMainWindow>
3 #include "multichartwidget.h"
23 #include "multichartwidget.h"
4
24
5 int main(int argc, char *argv[])
25 int main(int argc, char *argv[])
6 {
26 {
7 QApplication a(argc, argv);
27 QApplication a(argc, argv);
8
28
9 MultiChartWidget *multi = new MultiChartWidget();
29 MultiChartWidget *multi = new MultiChartWidget();
10
30
11 // Use the chart widget as the central widget
31 // Use the chart widget as the central widget
12 QMainWindow w;
32 QMainWindow w;
13 w.resize(640, 480);
33 w.resize(640, 480);
14 w.setCentralWidget(multi);
34 w.setCentralWidget(multi);
15 w.show();
35 w.show();
16
36
17 return a.exec();
37 return a.exec();
18 }
38 }
@@ -1,35 +1,55
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
1 #include "multichartwidget.h"
21 #include "multichartwidget.h"
2 #include <QVBoxLayout>
22 #include <QVBoxLayout>
3 #include <qchartglobal.h>
23 #include <qchartglobal.h>
4 #include <qchartview.h>
24 #include <qchartview.h>
5 #include <qscatterseries.h>
25 #include <qscatterseries.h>
6 #include <qpieseries.h>
26 #include <qpieseries.h>
7
27
8 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
9
29
10 MultiChartWidget::MultiChartWidget(QWidget *parent) :
30 MultiChartWidget::MultiChartWidget(QWidget *parent) :
11 QWidget(parent)
31 QWidget(parent)
12 {
32 {
13 QVBoxLayout *l = new QVBoxLayout(this);
33 QVBoxLayout *l = new QVBoxLayout(this);
14
34
15 // Create chart 1 and add a simple pie series onto it
35 // Create chart 1 and add a simple pie series onto it
16 QChartView *chartView1 = new QChartView();
36 QChartView *chartView1 = new QChartView();
17 l->addWidget(chartView1);
37 l->addWidget(chartView1);
18 QPieSeries *pie = new QPieSeries();
38 QPieSeries *pie = new QPieSeries();
19 pie->append(1.1, "label1");
39 pie->append(1.1, "label1");
20 pie->append(1.2, "label2");
40 pie->append(1.2, "label2");
21 chartView1->addSeries(pie);
41 chartView1->addSeries(pie);
22
42
23 // Create chart 2 and add a simple scatter series onto it
43 // Create chart 2 and add a simple scatter series onto it
24 QChartView *chartView2 = new QChartView();
44 QChartView *chartView2 = new QChartView();
25 l->addWidget(chartView2);
45 l->addWidget(chartView2);
26 QScatterSeries *scatter = new QScatterSeries();
46 QScatterSeries *scatter = new QScatterSeries();
27 *scatter << QPointF(0.5, 5.0)
47 *scatter << QPointF(0.5, 5.0)
28 << QPointF(1.0, 4.5)
48 << QPointF(1.0, 4.5)
29 << QPointF(1.0, 5.5)
49 << QPointF(1.0, 5.5)
30 << QPointF(1.5, 5.0)
50 << QPointF(1.5, 5.0)
31 << QPointF(2.0, 4.5)
51 << QPointF(2.0, 4.5)
32 << QPointF(2.0, 5.5)
52 << QPointF(2.0, 5.5)
33 << QPointF(2.5, 5.0);
53 << QPointF(2.5, 5.0);
34 chartView2->addSeries(scatter);
54 chartView2->addSeries(scatter);
35 }
55 }
@@ -1,18 +1,38
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
1 #ifndef MULTICHARTWIDGET_H
21 #ifndef MULTICHARTWIDGET_H
2 #define MULTICHARTWIDGET_H
22 #define MULTICHARTWIDGET_H
3
23
4 #include <QWidget>
24 #include <QWidget>
5
25
6 class MultiChartWidget : public QWidget
26 class MultiChartWidget : public QWidget
7 {
27 {
8 Q_OBJECT
28 Q_OBJECT
9 public:
29 public:
10 explicit MultiChartWidget(QWidget *parent = 0);
30 explicit MultiChartWidget(QWidget *parent = 0);
11
31
12 signals:
32 signals:
13
33
14 public slots:
34 public slots:
15
35
16 };
36 };
17
37
18 #endif // MULTICHARTWIDGET_H
38 #endif // MULTICHARTWIDGET_H
@@ -1,93 +1,74
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include <QApplication>
21 #include <QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QPercentBarSeries>
24 #include <QPercentBarSeries>
44 #include <QBarSet>
25 #include <QBarSet>
45
26
46 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
47
28
48 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
49 {
30 {
50 QApplication a(argc, argv);
31 QApplication a(argc, argv);
51 //![1]
32 //![1]
52 QBarCategories categories;
33 QBarCategories categories;
53 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
34 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
54 //![1]
35 //![1]
55 //![2]
36 //![2]
56 QBarSet *set0 = new QBarSet("Bub");
37 QBarSet *set0 = new QBarSet("Bub");
57 QBarSet *set1 = new QBarSet("Bob");
38 QBarSet *set1 = new QBarSet("Bob");
58 QBarSet *set2 = new QBarSet("Guybrush");
39 QBarSet *set2 = new QBarSet("Guybrush");
59 QBarSet *set3 = new QBarSet("Larry");
40 QBarSet *set3 = new QBarSet("Larry");
60 QBarSet *set4 = new QBarSet("Zak");
41 QBarSet *set4 = new QBarSet("Zak");
61
42
62 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
63 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
64 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
65 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
66 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
67 //![2]
48 //![2]
68 //![3]
49 //![3]
69 QPercentBarSeries* series = new QPercentBarSeries(categories);
50 QPercentBarSeries* series = new QPercentBarSeries(categories);
70 series->appendBarSet(set0);
51 series->appendBarSet(set0);
71 series->appendBarSet(set1);
52 series->appendBarSet(set1);
72 series->appendBarSet(set2);
53 series->appendBarSet(set2);
73 series->appendBarSet(set3);
54 series->appendBarSet(set3);
74 series->appendBarSet(set4);
55 series->appendBarSet(set4);
75 //![3]
56 //![3]
76 //![4]
57 //![4]
77 QChart* chart = new QChart();
58 QChart* chart = new QChart();
78 chart->addSeries(series);
59 chart->addSeries(series);
79 chart->setTitle("Simple precentbarchart example");
60 chart->setTitle("Simple precentbarchart example");
80 //![4]
61 //![4]
81 //![5]
62 //![5]
82 QChartView* chartView = new QChartView(chart);
63 QChartView* chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
64 chartView->setRenderHint(QPainter::Antialiasing);
84 //![5]
65 //![5]
85 //![6]
66 //![6]
86 QMainWindow window;
67 QMainWindow window;
87 window.setCentralWidget(chartView);
68 window.setCentralWidget(chartView);
88 window.resize(400, 300);
69 window.resize(400, 300);
89 window.show();
70 window.show();
90 //![6]
71 //![6]
91 return a.exec();
72 return a.exec();
92 }
73 }
93
74
@@ -1,84 +1,65
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include <QApplication>
21 #include <QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QPieSeries>
24 #include <QPieSeries>
44 #include <QPieSlice>
25 #include <QPieSlice>
45
26
46 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
47
28
48 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
49 {
30 {
50 QApplication a(argc, argv);
31 QApplication a(argc, argv);
51
32
52 //![1]
33 //![1]
53 QPieSeries *series = new QPieSeries();
34 QPieSeries *series = new QPieSeries();
54 series->append(1, "Slice 1");
35 series->append(1, "Slice 1");
55 series->append(2, "Slice 2");
36 series->append(2, "Slice 2");
56 series->append(3, "Slice 3");
37 series->append(3, "Slice 3");
57 series->append(4, "Slice 4");
38 series->append(4, "Slice 4");
58 series->append(5, "Slice 5");
39 series->append(5, "Slice 5");
59 //![1]
40 //![1]
60
41
61 //![2]
42 //![2]
62 QPieSlice *slice = series->slices().first();
43 QPieSlice *slice = series->slices().first();
63 slice->setExploded();
44 slice->setExploded();
64 slice->setLabelVisible();
45 slice->setLabelVisible();
65 slice->setPen(QPen(Qt::darkGreen, 2));
46 slice->setPen(QPen(Qt::darkGreen, 2));
66 slice->setBrush(Qt::green);
47 slice->setBrush(Qt::green);
67 //![2]
48 //![2]
68 //![3]
49 //![3]
69 QChart* chart = new QChart();
50 QChart* chart = new QChart();
70 chart->addSeries(series);
51 chart->addSeries(series);
71 chart->setTitle("Simple piechart example");
52 chart->setTitle("Simple piechart example");
72 //![3]
53 //![3]
73 //![4]
54 //![4]
74 QChartView* chartView = new QChartView(chart);
55 QChartView* chartView = new QChartView(chart);
75 chartView->setRenderHint(QPainter::Antialiasing);
56 chartView->setRenderHint(QPainter::Antialiasing);
76 //![4]
57 //![4]
77 //![5]
58 //![5]
78 QMainWindow window;
59 QMainWindow window;
79 window.setCentralWidget(chartView);
60 window.setCentralWidget(chartView);
80 window.resize(400, 300);
61 window.resize(400, 300);
81 window.show();
62 window.show();
82 //![5]
63 //![5]
83 return a.exec();
64 return a.exec();
84 }
65 }
@@ -1,115 +1,135
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include <QMainWindow>
22 #include <QMainWindow>
3 #include <qchartglobal.h>
23 #include <qchartglobal.h>
4 #include <qchartview.h>
24 #include <qchartview.h>
5 #include <qpieseries.h>
25 #include <qpieseries.h>
6 #include <qpieslice.h>
26 #include <qpieslice.h>
7 #include <QTime>
27 #include <QTime>
8
28
9 QTCOMMERCIALCHART_USE_NAMESPACE
29 QTCOMMERCIALCHART_USE_NAMESPACE
10
30
11 class DrilldownSlice : public QPieSlice
31 class DrilldownSlice : public QPieSlice
12 {
32 {
13 Q_OBJECT
33 Q_OBJECT
14
34
15 public:
35 public:
16 DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries)
36 DrilldownSlice(qreal value, QString prefix, QSeries* drilldownSeries)
17 :m_drilldownSeries(drilldownSeries),
37 :m_drilldownSeries(drilldownSeries),
18 m_prefix(prefix)
38 m_prefix(prefix)
19 {
39 {
20 setValue(value);
40 setValue(value);
21 setLabelVisible(true);
41 setLabelVisible(true);
22 updateLabel();
42 updateLabel();
23 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
43 connect(this, SIGNAL(changed()), this, SLOT(updateLabel()));
24 }
44 }
25
45
26 QSeries* drilldownSeries() const { return m_drilldownSeries; }
46 QSeries* drilldownSeries() const { return m_drilldownSeries; }
27
47
28 public Q_SLOTS:
48 public Q_SLOTS:
29 void updateLabel()
49 void updateLabel()
30 {
50 {
31 QString label = m_prefix;
51 QString label = m_prefix;
32 label += " " + QString::number(this->value())+ "e (";
52 label += " " + QString::number(this->value())+ "e (";
33 label += QString::number(this->percentage()*100, 'f', 1) + "%)";
53 label += QString::number(this->percentage()*100, 'f', 1) + "%)";
34 setLabel(label);
54 setLabel(label);
35 }
55 }
36
56
37 private:
57 private:
38 QSeries* m_drilldownSeries;
58 QSeries* m_drilldownSeries;
39 QString m_prefix;
59 QString m_prefix;
40 };
60 };
41
61
42 class DrilldownChart : public QChart
62 class DrilldownChart : public QChart
43 {
63 {
44 Q_OBJECT
64 Q_OBJECT
45 public:
65 public:
46 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0):QChart(parent, wFlags), m_currentSeries(0) {}
66 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0):QChart(parent, wFlags), m_currentSeries(0) {}
47
67
48 void changeSeries(QSeries* series)
68 void changeSeries(QSeries* series)
49 {
69 {
50 // NOTE: if the series is owned by the chart it will be deleted
70 // NOTE: if the series is owned by the chart it will be deleted
51 // here the "window" owns the series...
71 // here the "window" owns the series...
52 if (m_currentSeries)
72 if (m_currentSeries)
53 removeSeries(m_currentSeries);
73 removeSeries(m_currentSeries);
54 m_currentSeries = series;
74 m_currentSeries = series;
55 addSeries(series);
75 addSeries(series);
56 setTitle(series->name());
76 setTitle(series->name());
57 }
77 }
58
78
59 public Q_SLOTS:
79 public Q_SLOTS:
60 void handleSliceClicked(QPieSlice* slice)
80 void handleSliceClicked(QPieSlice* slice)
61 {
81 {
62 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
82 DrilldownSlice* drilldownSlice = static_cast<DrilldownSlice*>(slice);
63 changeSeries(drilldownSlice->drilldownSeries());
83 changeSeries(drilldownSlice->drilldownSeries());
64 }
84 }
65
85
66 private:
86 private:
67 QSeries* m_currentSeries;
87 QSeries* m_currentSeries;
68 };
88 };
69
89
70 int main(int argc, char *argv[])
90 int main(int argc, char *argv[])
71 {
91 {
72 QApplication a(argc, argv);
92 QApplication a(argc, argv);
73
93
74 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
94 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
75
95
76 QMainWindow window;
96 QMainWindow window;
77
97
78 DrilldownChart* drilldownChart = new DrilldownChart();
98 DrilldownChart* drilldownChart = new DrilldownChart();
79 drilldownChart->setTheme(QChart::ChartThemeLight);
99 drilldownChart->setTheme(QChart::ChartThemeLight);
80 drilldownChart->setAnimationOptions(QChart::AllAnimations);
100 drilldownChart->setAnimationOptions(QChart::AllAnimations);
81
101
82 QPieSeries* yearSeries = new QPieSeries(&window);
102 QPieSeries* yearSeries = new QPieSeries(&window);
83 yearSeries->setName("Sales by year - All");
103 yearSeries->setName("Sales by year - All");
84
104
85 QList<QString> months;
105 QList<QString> months;
86 months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
106 months << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun" << "Jul" << "Aug" << "Sep" << "Oct" << "Nov" << "Dec";
87 QList<QString> names;
107 QList<QString> names;
88 names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob";
108 names << "Jane" << "John" << "Axel" << "Mary" << "Samantha" << "Bob";
89
109
90 foreach (QString name, names) {
110 foreach (QString name, names) {
91 QPieSeries* series = new QPieSeries(&window);
111 QPieSeries* series = new QPieSeries(&window);
92 series->setName("Sales by month - " + name);
112 series->setName("Sales by month - " + name);
93
113
94 foreach (QString month, months)
114 foreach (QString month, months)
95 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
115 *series << new DrilldownSlice(qrand() % 1000, month, yearSeries);
96
116
97 QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
117 QObject::connect(series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
98
118
99 *yearSeries << new DrilldownSlice(series->total(), name, series);
119 *yearSeries << new DrilldownSlice(series->total(), name, series);
100 }
120 }
101
121
102 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
122 QObject::connect(yearSeries, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), drilldownChart, SLOT(handleSliceClicked(QPieSlice*)));
103
123
104 drilldownChart->changeSeries(yearSeries);
124 drilldownChart->changeSeries(yearSeries);
105
125
106 QChartView* chartView = new QChartView(drilldownChart);
126 QChartView* chartView = new QChartView(drilldownChart);
107 chartView->setRenderHint(QPainter::Antialiasing);
127 chartView->setRenderHint(QPainter::Antialiasing);
108 window.setCentralWidget(chartView);
128 window.setCentralWidget(chartView);
109 window.resize(800, 600);
129 window.resize(800, 600);
110 window.show();
130 window.show();
111
131
112 return a.exec();
132 return a.exec();
113 }
133 }
114
134
115 #include "main.moc"
135 #include "main.moc"
@@ -1,97 +1,117
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
1 #include "chartview.h"
21 #include "chartview.h"
2 #include <QLineSeries>
22 #include <QLineSeries>
3 #include <QScatterSeries>
23 #include <QScatterSeries>
4 #include <QSplineSeries>
24 #include <QSplineSeries>
5 #include <QAreaSeries>
25 #include <QAreaSeries>
6 #include <QTime>
26 #include <QTime>
7
27
8 ChartView::ChartView(QWidget* parent):QChartView(parent),
28 ChartView::ChartView(QWidget* parent):QChartView(parent),
9 m_index(0)
29 m_index(0)
10 {
30 {
11 setChartTitle("Charts presenter");
31 setChartTitle("Charts presenter");
12 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
32 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
13 m_timer.setInterval(3000);
33 m_timer.setInterval(3000);
14
34
15 //![1]
35 //![1]
16 QLineSeries* series0 = new QLineSeries(this);
36 QLineSeries* series0 = new QLineSeries(this);
17 QPen blue(Qt::blue);
37 QPen blue(Qt::blue);
18 blue.setWidth(3);
38 blue.setWidth(3);
19 series0->setPen(blue);
39 series0->setPen(blue);
20
40
21 QScatterSeries* series1 = new QScatterSeries(this);
41 QScatterSeries* series1 = new QScatterSeries(this);
22 QPen red(Qt::red);
42 QPen red(Qt::red);
23 red.setWidth(3);
43 red.setWidth(3);
24 series1->setPen(red);
44 series1->setPen(red);
25 series1->setBrush(Qt::white);
45 series1->setBrush(Qt::white);
26
46
27 QSplineSeries* series2 = new QSplineSeries(this);
47 QSplineSeries* series2 = new QSplineSeries(this);
28 QPen green(Qt::green);
48 QPen green(Qt::green);
29 green.setWidth(3);
49 green.setWidth(3);
30 series2->setPen(green);
50 series2->setPen(green);
31
51
32 QAreaSeries* series3 = new QAreaSeries(series0);
52 QAreaSeries* series3 = new QAreaSeries(series0);
33 QPen yellow(Qt::black);
53 QPen yellow(Qt::black);
34 yellow.setWidth(3);
54 yellow.setWidth(3);
35 series3->setPen(yellow);
55 series3->setPen(yellow);
36 series3->setBrush(Qt::yellow);
56 series3->setBrush(Qt::yellow);
37 //![1]
57 //![1]
38
58
39 //![2]
59 //![2]
40 int numPoints = 10;
60 int numPoints = 10;
41
61
42 for (int x = 0; x <= numPoints; ++x) {
62 for (int x = 0; x <= numPoints; ++x) {
43 qreal y = qrand() % 100;
63 qreal y = qrand() % 100;
44 series0->append(x,y);
64 series0->append(x,y);
45 series1->append(x,y);
65 series1->append(x,y);
46 series2->append(x,y);
66 series2->append(x,y);
47 }
67 }
48 //![2]
68 //![2]
49
69
50 //![3]
70 //![3]
51 m_series<<series0;
71 m_series<<series0;
52 m_titles<<chartTitle()+": LineChart";
72 m_titles<<chartTitle()+": LineChart";
53 m_series<<series1;
73 m_series<<series1;
54 m_titles<<chartTitle()+": ScatterChart";
74 m_titles<<chartTitle()+": ScatterChart";
55 m_series<<series2;
75 m_series<<series2;
56 m_titles<<chartTitle()+": SplineChart";
76 m_titles<<chartTitle()+": SplineChart";
57 m_series<<series3;
77 m_series<<series3;
58 m_titles<<chartTitle()+": AreaChart";
78 m_titles<<chartTitle()+": AreaChart";
59 //![3]
79 //![3]
60
80
61 addSeries(series0);
81 addSeries(series0);
62 setChartTitle(m_titles.at(0));
82 setChartTitle(m_titles.at(0));
63
83
64 //![4]
84 //![4]
65 foreach (QSeries* series, m_series) {
85 foreach (QSeries* series, m_series) {
66 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
86 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
67 }
87 }
68 //![4]
88 //![4]
69
89
70 m_timer.start();
90 m_timer.start();
71 }
91 }
72
92
73 ChartView::~ChartView()
93 ChartView::~ChartView()
74 {
94 {
75 if(m_series.size()==0) return;
95 if(m_series.size()==0) return;
76 removeSeries(m_series.at(m_index));
96 removeSeries(m_series.at(m_index));
77 qDeleteAll(m_series);
97 qDeleteAll(m_series);
78 }
98 }
79
99
80 //![5]
100 //![5]
81 void ChartView::handleTimeout()
101 void ChartView::handleTimeout()
82 {
102 {
83 if(m_series.size()==0) return;
103 if(m_series.size()==0) return;
84 removeSeries(m_series.at(m_index));
104 removeSeries(m_series.at(m_index));
85 m_index++;
105 m_index++;
86 m_index=m_index%m_series.size();
106 m_index=m_index%m_series.size();
87 addSeries(m_series.at(m_index));
107 addSeries(m_series.at(m_index));
88 setChartTitle(m_titles.at(m_index));
108 setChartTitle(m_titles.at(m_index));
89 }
109 }
90 //![5]
110 //![5]
91
111
92 //![6]
112 //![6]
93 void ChartView::handlePointClicked(const QPointF& point)
113 void ChartView::handlePointClicked(const QPointF& point)
94 {
114 {
95 setChartTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
115 setChartTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
96 }
116 }
97 //![6]
117 //![6]
@@ -1,29 +1,49
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
1 #ifndef CHARTVIEW_H_
21 #ifndef CHARTVIEW_H_
2 #define CHARTVIEW_H_
22 #define CHARTVIEW_H_
3
23
4 #include <QChartView>
24 #include <QChartView>
5 #include <QTimer>
25 #include <QTimer>
6
26
7 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
8
28
9 //![1]
29 //![1]
10 class ChartView: public QChartView
30 class ChartView: public QChartView
11 {
31 {
12 Q_OBJECT
32 Q_OBJECT
13 public:
33 public:
14 ChartView(QWidget* parent = 0);
34 ChartView(QWidget* parent = 0);
15 virtual ~ChartView();
35 virtual ~ChartView();
16
36
17 public slots:
37 public slots:
18 void handleTimeout();
38 void handleTimeout();
19 void handlePointClicked(const QPointF& point);
39 void handlePointClicked(const QPointF& point);
20
40
21 private:
41 private:
22 QTimer m_timer;
42 QTimer m_timer;
23 QList<QSeries*> m_series;
43 QList<QSeries*> m_series;
24 QStringList m_titles;
44 QStringList m_titles;
25 int m_index;
45 int m_index;
26 };
46 };
27 //![1]
47 //![1]
28
48
29 #endif /* CHARTVIEW_H_ */
49 #endif /* CHARTVIEW_H_ */
@@ -1,16 +1,36
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
1 #include "chartview.h"
21 #include "chartview.h"
2 #include <QApplication>
22 #include <QApplication>
3 #include <QMainWindow>
23 #include <QMainWindow>
4
24
5 int main(int argc, char *argv[])
25 int main(int argc, char *argv[])
6 {
26 {
7 QApplication a(argc, argv);
27 QApplication a(argc, argv);
8 QMainWindow window;
28 QMainWindow window;
9 ChartView chartView(&window);
29 ChartView chartView(&window);
10 chartView.setRenderHint(QPainter::Antialiasing);
30 chartView.setRenderHint(QPainter::Antialiasing);
11 chartView.setAnimationOptions(QChart::AllAnimations);
31 chartView.setAnimationOptions(QChart::AllAnimations);
12 window.setCentralWidget(&chartView);
32 window.setCentralWidget(&chartView);
13 window.resize(400, 300);
33 window.resize(400, 300);
14 window.show();
34 window.show();
15 return a.exec();
35 return a.exec();
16 }
36 }
@@ -1,96 +1,77
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QScatterSeries>
24 #include <QScatterSeries>
44
25
45 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
46
27
47 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
48 {
29 {
49 QApplication a(argc, argv);
30 QApplication a(argc, argv);
50 //![1]
31 //![1]
51 QPen pen(Qt::black);
32 QPen pen(Qt::black);
52 pen.setWidth(2);
33 pen.setWidth(2);
53 QBrush blue(Qt::blue);
34 QBrush blue(Qt::blue);
54 QBrush red(Qt::red);
35 QBrush red(Qt::red);
55
36
56 QScatterSeries *series0 = new QScatterSeries();
37 QScatterSeries *series0 = new QScatterSeries();
57 series0->setPen(pen);
38 series0->setPen(pen);
58 series0->setBrush(blue);
39 series0->setBrush(blue);
59 series0->setShape(QScatterSeries::MarkerShapeCircle);
40 series0->setShape(QScatterSeries::MarkerShapeCircle);
60 series0->setSize(15.0);
41 series0->setSize(15.0);
61
42
62 QScatterSeries *series1 = new QScatterSeries();
43 QScatterSeries *series1 = new QScatterSeries();
63 series1->setPen(pen);
44 series1->setPen(pen);
64 series1->setBrush(red);
45 series1->setBrush(red);
65 series1->setShape(QScatterSeries::MarkerShapeCircle);
46 series1->setShape(QScatterSeries::MarkerShapeCircle);
66 series1->setSize(15.0);
47 series1->setSize(15.0);
67 //![1]
48 //![1]
68
49
69 //![2]
50 //![2]
70 series0->append(0, 6);
51 series0->append(0, 6);
71 series0->append(2, 4);
52 series0->append(2, 4);
72 series0->append(3, 8);
53 series0->append(3, 8);
73 series0->append(7, 4);
54 series0->append(7, 4);
74 series0->append(10, 5);
55 series0->append(10, 5);
75
56
76 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
57 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
77 //![2]
58 //![2]
78 //![3]
59 //![3]
79 QChart* chart = new QChart();
60 QChart* chart = new QChart();
80
61
81 chart->addSeries(series0);
62 chart->addSeries(series0);
82 chart->addSeries(series1);
63 chart->addSeries(series1);
83 chart->setTitle("Simple scatterchart example");
64 chart->setTitle("Simple scatterchart example");
84 //![3]
65 //![3]
85 //![4]
66 //![4]
86 QChartView* chartView = new QChartView(chart);
67 QChartView* chartView = new QChartView(chart);
87 chartView->setRenderHint(QPainter::Antialiasing);
68 chartView->setRenderHint(QPainter::Antialiasing);
88 //![4]
69 //![4]
89 //![5]
70 //![5]
90 QMainWindow window;
71 QMainWindow window;
91 window.setCentralWidget(chartView);
72 window.setCentralWidget(chartView);
92 window.resize(400, 300);
73 window.resize(400, 300);
93 window.show();
74 window.show();
94 //![5]
75 //![5]
95 return a.exec();
76 return a.exec();
96 }
77 }
@@ -1,12 +1,32
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include "mainwindow.h"
22 #include "mainwindow.h"
3
23
4 int main(int argc, char *argv[])
24 int main(int argc, char *argv[])
5 {
25 {
6 QApplication a(argc, argv);
26 QApplication a(argc, argv);
7 MainWindow w;
27 MainWindow w;
8 w.resize(400, 300);
28 w.resize(400, 300);
9 w.show();
29 w.show();
10
30
11 return a.exec();
31 return a.exec();
12 }
32 }
@@ -1,38 +1,58
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
1 #include "mainwindow.h"
21 #include "mainwindow.h"
2 #include <qchartglobal.h>
22 #include <qchartglobal.h>
3 #include <qchartview.h>
23 #include <qchartview.h>
4 #include <qchartaxis.h>
24 #include <qchartaxis.h>
5 #include <QDebug>
25 #include <QDebug>
6
26
7 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
8
28
9 MainWindow::MainWindow(QWidget *parent)
29 MainWindow::MainWindow(QWidget *parent)
10 : QMainWindow(parent)
30 : QMainWindow(parent)
11 {
31 {
12 QChartView *chartView = new QChartView(this);
32 QChartView *chartView = new QChartView(this);
13 chartView->setChartTitle("Click to remove scatter point");
33 chartView->setChartTitle("Click to remove scatter point");
14 chartView->setRenderHint(QPainter::Antialiasing);
34 chartView->setRenderHint(QPainter::Antialiasing);
15 setCentralWidget(chartView);
35 setCentralWidget(chartView);
16
36
17 m_scatter = new QScatterSeries();
37 m_scatter = new QScatterSeries();
18 for(qreal x(0.5); x <= 4.0; x += 0.5) {
38 for(qreal x(0.5); x <= 4.0; x += 0.5) {
19 for(qreal y(0.5); y <= 4.0; y += 0.5) {
39 for(qreal y(0.5); y <= 4.0; y += 0.5) {
20 *m_scatter << QPointF(x, y);
40 *m_scatter << QPointF(x, y);
21 }
41 }
22 }
42 }
23
43
24 chartView->addSeries(m_scatter);
44 chartView->addSeries(m_scatter);
25 chartView->axisX()->setRange(0,4.5);
45 chartView->axisX()->setRange(0,4.5);
26 chartView->axisY()->setRange(0,4.5);
46 chartView->axisY()->setRange(0,4.5);
27
47
28 connect(m_scatter, SIGNAL(clicked(const QPointF&)), this, SLOT(handleClickedPoint(const QPointF&)));
48 connect(m_scatter, SIGNAL(clicked(const QPointF&)), this, SLOT(handleClickedPoint(const QPointF&)));
29 }
49 }
30
50
31 MainWindow::~MainWindow()
51 MainWindow::~MainWindow()
32 {
52 {
33 }
53 }
34
54
35 void MainWindow::handleClickedPoint(const QPointF& point)
55 void MainWindow::handleClickedPoint(const QPointF& point)
36 {
56 {
37 m_scatter->remove(point);
57 m_scatter->remove(point);
38 }
58 }
@@ -1,27 +1,47
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
1 #ifndef MAINWINDOW_H
21 #ifndef MAINWINDOW_H
2 #define MAINWINDOW_H
22 #define MAINWINDOW_H
3
23
4 #include <QtGui/QMainWindow>
24 #include <QtGui/QMainWindow>
5 #include <qchartglobal.h>
25 #include <qchartglobal.h>
6 #include <qscatterseries.h>
26 #include <qscatterseries.h>
7
27
8 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
9
29
10 class MainWindow : public QMainWindow
30 class MainWindow : public QMainWindow
11 {
31 {
12 Q_OBJECT
32 Q_OBJECT
13
33
14 public:
34 public:
15 MainWindow(QWidget *parent = 0);
35 MainWindow(QWidget *parent = 0);
16 ~MainWindow();
36 ~MainWindow();
17
37
18 private Q_SLOTS:
38 private Q_SLOTS:
19 void handleClickedPoint(const QPointF& point);
39 void handleClickedPoint(const QPointF& point);
20
40
21 private:
41 private:
22 QScatterSeries *m_scatter;
42 QScatterSeries *m_scatter;
23 QScatterSeries *m_scatter2;
43 QScatterSeries *m_scatter2;
24 QScatterSeries *m_scatter3;
44 QScatterSeries *m_scatter3;
25 };
45 };
26
46
27 #endif // MAINWINDOW_H
47 #endif // MAINWINDOW_H
@@ -1,11 +1,31
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include "splinewidget.h"
22 #include "splinewidget.h"
3
23
4 int main(int argc, char *argv[])
24 int main(int argc, char *argv[])
5 {
25 {
6 QApplication a(argc, argv);
26 QApplication a(argc, argv);
7 SplineWidget w;
27 SplineWidget w;
8 w.show();
28 w.show();
9
29
10 return a.exec();
30 return a.exec();
11 }
31 }
@@ -1,116 +1,136
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
1 #include "splinewidget.h"
21 #include "splinewidget.h"
2 #include "qchartview.h"
22 #include "qchartview.h"
3 #include "qlineseries.h"
23 #include "qlineseries.h"
4 #include <QGridLayout>
24 #include <QGridLayout>
5 #include <QPushButton>
25 #include <QPushButton>
6 #include "qchartaxis.h"
26 #include "qchartaxis.h"
7 #include <qmath.h>
27 #include <qmath.h>
8 #include <QTime>
28 #include <QTime>
9
29
10 QTCOMMERCIALCHART_USE_NAMESPACE
30 QTCOMMERCIALCHART_USE_NAMESPACE
11
31
12 SplineWidget::SplineWidget(QWidget *parent)
32 SplineWidget::SplineWidget(QWidget *parent)
13 : QWidget(parent)
33 : QWidget(parent)
14 {
34 {
15 // qsrand(time(NULL));
35 // qsrand(time(NULL));
16 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
36 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
17 //! [1]
37 //! [1]
18 //create QSplineSeries
38 //create QSplineSeries
19 series = new QSplineSeries(this);
39 series = new QSplineSeries(this);
20 //! [1]
40 //! [1]
21
41
22 //! [2]
42 //! [2]
23 // customize the series presentation settings
43 // customize the series presentation settings
24 QPen seriesPen(Qt::blue);
44 QPen seriesPen(Qt::blue);
25 seriesPen.setWidth(3);
45 seriesPen.setWidth(3);
26 // series->setPen(seriesPen);
46 // series->setPen(seriesPen);
27 //! [2]
47 //! [2]
28
48
29 //! [add points to series]
49 //! [add points to series]
30 //add data points to the series
50 //add data points to the series
31 series->append(QPointF(150, 100));
51 series->append(QPointF(150, 100));
32 series->append(QPointF(200, 130));
52 series->append(QPointF(200, 130));
33 series->append(QPointF(250, 120));
53 series->append(QPointF(250, 120));
34 series->append(QPointF(300, 140));
54 series->append(QPointF(300, 140));
35 series->append(QPointF(350, 160));
55 series->append(QPointF(350, 160));
36 //! [add points to series]
56 //! [add points to series]
37
57
38 QSplineSeries* series2 = new QSplineSeries;
58 QSplineSeries* series2 = new QSplineSeries;
39
59
40 series2->append(QPointF(400, 120));
60 series2->append(QPointF(400, 120));
41 series2->append(QPointF(450, 150));
61 series2->append(QPointF(450, 150));
42 series2->append(QPointF(500, 145));
62 series2->append(QPointF(500, 145));
43 series2->append(QPointF(550, 170));
63 series2->append(QPointF(550, 170));
44
64
45 // series->append(QPointF(600, 190));
65 // series->append(QPointF(600, 190));
46 // series->append(QPointF(650, 210));
66 // series->append(QPointF(650, 210));
47 // series->append(QPointF(700, 190));
67 // series->append(QPointF(700, 190));
48 // series->append(QPointF(750, 180));
68 // series->append(QPointF(750, 180));
49 // series->append(QPointF(800, 170));
69 // series->append(QPointF(800, 170));
50 QSplineSeries* series3 = new QSplineSeries;
70 QSplineSeries* series3 = new QSplineSeries;
51 series3->append(QPointF(600, 190));
71 series3->append(QPointF(600, 190));
52 series3->append(QPointF(650, 210));
72 series3->append(QPointF(650, 210));
53 series3->append(QPointF(700, 190));
73 series3->append(QPointF(700, 190));
54 series3->append(QPointF(750, 180));
74 series3->append(QPointF(750, 180));
55 series3->append(QPointF(800, 170));
75 series3->append(QPointF(800, 170));
56
76
57 //! [3]
77 //! [3]
58 // create chart view
78 // create chart view
59 QChartView* chart = new QChartView;
79 QChartView* chart = new QChartView;
60 chart->addSeries(series);
80 chart->addSeries(series);
61 chart->addSeries(series2);
81 chart->addSeries(series2);
62 chart->addSeries(series3);
82 chart->addSeries(series3);
63
83
64 chart->setChartTitle("Spline chart example");
84 chart->setChartTitle("Spline chart example");
65 chart->axisX()->setMax(1500);
85 chart->axisX()->setMax(1500);
66 chart->axisY()->setMax(500);
86 chart->axisY()->setMax(500);
67
87
68 chart->setMinimumSize(800,600);
88 chart->setMinimumSize(800,600);
69 //! [3]
89 //! [3]
70
90
71 //! [4]
91 //! [4]
72 //add new data point button
92 //add new data point button
73 QPushButton* addButton = new QPushButton("Add new point");
93 QPushButton* addButton = new QPushButton("Add new point");
74 connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint()));
94 connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint()));
75
95
76 // remove the last data point in the series
96 // remove the last data point in the series
77 QPushButton* removeButton = new QPushButton("Remove point");
97 QPushButton* removeButton = new QPushButton("Remove point");
78 connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint()));
98 connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint()));
79 //! [4]
99 //! [4]
80
100
81 //! [5]
101 //! [5]
82 //butttons layout
102 //butttons layout
83 QVBoxLayout* buttonsLayout = new QVBoxLayout;
103 QVBoxLayout* buttonsLayout = new QVBoxLayout;
84 buttonsLayout->addWidget(addButton);
104 buttonsLayout->addWidget(addButton);
85 buttonsLayout->addWidget(removeButton);
105 buttonsLayout->addWidget(removeButton);
86 buttonsLayout->addStretch();
106 buttonsLayout->addStretch();
87
107
88 QGridLayout* mainLayout = new QGridLayout;
108 QGridLayout* mainLayout = new QGridLayout;
89 mainLayout->addWidget(chart, 1, 0);
109 mainLayout->addWidget(chart, 1, 0);
90 mainLayout->addLayout(buttonsLayout, 1, 1);
110 mainLayout->addLayout(buttonsLayout, 1, 1);
91 setLayout(mainLayout);
111 setLayout(mainLayout);
92 //! [5]
112 //! [5]
93 }
113 }
94
114
95 //! [add point]
115 //! [add point]
96 void SplineWidget::addNewPoint()
116 void SplineWidget::addNewPoint()
97 {
117 {
98 if (series->count() > 0)
118 if (series->count() > 0)
99 series->append(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100)));
119 series->append(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100)));
100 else
120 else
101 series->append(QPointF(50, 50 + qrand()%50));
121 series->append(QPointF(50, 50 + qrand()%50));
102 }
122 }
103 //! [add point]
123 //! [add point]
104
124
105 //! [remove point]
125 //! [remove point]
106 void SplineWidget::removePoint()
126 void SplineWidget::removePoint()
107 {
127 {
108 if (series->count() > 0)
128 if (series->count() > 0)
109 series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1)));
129 series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1)));
110 }
130 }
111 //! [remove point]
131 //! [remove point]
112
132
113 SplineWidget::~SplineWidget()
133 SplineWidget::~SplineWidget()
114 {
134 {
115
135
116 }
136 }
@@ -1,25 +1,45
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
1 #ifndef SPLINEWIDGET_H
21 #ifndef SPLINEWIDGET_H
2 #define SPLINEWIDGET_H
22 #define SPLINEWIDGET_H
3
23
4 #include <QtGui/QWidget>
24 #include <QtGui/QWidget>
5 #include "qsplineseries.h"
25 #include "qsplineseries.h"
6
26
7 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
8
28
9 class SplineWidget : public QWidget
29 class SplineWidget : public QWidget
10 {
30 {
11 Q_OBJECT
31 Q_OBJECT
12
32
13 public:
33 public:
14 SplineWidget(QWidget *parent = 0);
34 SplineWidget(QWidget *parent = 0);
15 ~SplineWidget();
35 ~SplineWidget();
16
36
17 public slots:
37 public slots:
18 void addNewPoint();
38 void addNewPoint();
19 void removePoint();
39 void removePoint();
20
40
21 private:
41 private:
22 QSplineSeries* series;
42 QSplineSeries* series;
23 };
43 };
24
44
25 #endif // SPLINEWIDGET_H
45 #endif // SPLINEWIDGET_H
@@ -1,93 +1,74
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include <QApplication>
21 #include <QApplication>
41 #include <QMainWindow>
22 #include <QMainWindow>
42 #include <QChartView>
23 #include <QChartView>
43 #include <QStackedBarSeries>
24 #include <QStackedBarSeries>
44 #include <QBarSet>
25 #include <QBarSet>
45
26
46 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
47
28
48 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
49 {
30 {
50 QApplication a(argc, argv);
31 QApplication a(argc, argv);
51 //![1]
32 //![1]
52 QBarCategories categories;
33 QBarCategories categories;
53 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
34 categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
54 //![1]
35 //![1]
55 //![2]
36 //![2]
56 QBarSet *set0 = new QBarSet("Bub");
37 QBarSet *set0 = new QBarSet("Bub");
57 QBarSet *set1 = new QBarSet("Bob");
38 QBarSet *set1 = new QBarSet("Bob");
58 QBarSet *set2 = new QBarSet("Guybrush");
39 QBarSet *set2 = new QBarSet("Guybrush");
59 QBarSet *set3 = new QBarSet("Larry");
40 QBarSet *set3 = new QBarSet("Larry");
60 QBarSet *set4 = new QBarSet("Zak");
41 QBarSet *set4 = new QBarSet("Zak");
61
42
62 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
43 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
63 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
44 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
64 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
45 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
65 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
46 *set3 << 5 << 6 << 7 << 3 << 4 << 5;
66 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
47 *set4 << 9 << 7 << 5 << 3 << 1 << 2;
67 //![2]
48 //![2]
68 //![3]
49 //![3]
69 QStackedBarSeries* series = new QStackedBarSeries(categories);
50 QStackedBarSeries* series = new QStackedBarSeries(categories);
70 series->appendBarSet(set0);
51 series->appendBarSet(set0);
71 series->appendBarSet(set1);
52 series->appendBarSet(set1);
72 series->appendBarSet(set2);
53 series->appendBarSet(set2);
73 series->appendBarSet(set3);
54 series->appendBarSet(set3);
74 series->appendBarSet(set4);
55 series->appendBarSet(set4);
75 //![3]
56 //![3]
76 //![4]
57 //![4]
77 QChart* chart = new QChart();
58 QChart* chart = new QChart();
78 chart->addSeries(series);
59 chart->addSeries(series);
79 chart->setTitle("Simple stackedbarchart example");
60 chart->setTitle("Simple stackedbarchart example");
80 //![4]
61 //![4]
81 //![5]
62 //![5]
82 QChartView* chartView = new QChartView(chart);
63 QChartView* chartView = new QChartView(chart);
83 chartView->setRenderHint(QPainter::Antialiasing);
64 chartView->setRenderHint(QPainter::Antialiasing);
84 //![5]
65 //![5]
85 //![6]
66 //![6]
86 QMainWindow window;
67 QMainWindow window;
87 window.setCentralWidget(chartView);
68 window.setCentralWidget(chartView);
88 window.resize(400, 300);
69 window.resize(400, 300);
89 window.show();
70 window.show();
90 //![6]
71 //![6]
91 return a.exec();
72 return a.exec();
92 }
73 }
93
74
@@ -1,147 +1,167
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include <QMainWindow>
22 #include <QMainWindow>
3 #include <qchartglobal.h>
23 #include <qchartglobal.h>
4 #include <qchartview.h>
24 #include <qchartview.h>
5 #include <qstackedbarseries.h>
25 #include <qstackedbarseries.h>
6 #include <qbarset.h>
26 #include <qbarset.h>
7 #include <qchartaxis.h>
27 #include <qchartaxis.h>
8 #include <QStringList>
28 #include <QStringList>
9 #include <QDebug>
29 #include <QDebug>
10
30
11 QTCOMMERCIALCHART_USE_NAMESPACE
31 QTCOMMERCIALCHART_USE_NAMESPACE
12
32
13 //! [1]
33 //! [1]
14 class DrilldownBarSeries : public QStackedBarSeries
34 class DrilldownBarSeries : public QStackedBarSeries
15 {
35 {
16 Q_OBJECT
36 Q_OBJECT
17 public:
37 public:
18 DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {}
38 DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {}
19
39
20 void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries)
40 void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries)
21 {
41 {
22 mDrilldownSeries[category] = drilldownSeries;
42 mDrilldownSeries[category] = drilldownSeries;
23 }
43 }
24
44
25 DrilldownBarSeries* drilldownSeries(QString category)
45 DrilldownBarSeries* drilldownSeries(QString category)
26 {
46 {
27 return mDrilldownSeries[category];
47 return mDrilldownSeries[category];
28 }
48 }
29
49
30 public Q_SLOTS:
50 public Q_SLOTS:
31
51
32 private:
52 private:
33
53
34 QMap<QString, DrilldownBarSeries*> mDrilldownSeries;
54 QMap<QString, DrilldownBarSeries*> mDrilldownSeries;
35 };
55 };
36 //! [1]
56 //! [1]
37
57
38 //! [2]
58 //! [2]
39 class DrilldownChart : public QChart
59 class DrilldownChart : public QChart
40 {
60 {
41 Q_OBJECT
61 Q_OBJECT
42 public:
62 public:
43 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) : QChart(parent, wFlags), m_currentSeries(0) {}
63 explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0) : QChart(parent, wFlags), m_currentSeries(0) {}
44
64
45 void changeSeries(QSeries* series)
65 void changeSeries(QSeries* series)
46 {
66 {
47 if (m_currentSeries)
67 if (m_currentSeries)
48 removeSeries(m_currentSeries);
68 removeSeries(m_currentSeries);
49 m_currentSeries = series;
69 m_currentSeries = series;
50 addSeries(series);
70 addSeries(series);
51 setTitle(series->name());
71 setTitle(series->name());
52 }
72 }
53
73
54 public Q_SLOTS:
74 public Q_SLOTS:
55 void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button)
75 void handleClicked(QBarSet *barset, QString category, Qt::MouseButtons button)
56 {
76 {
57 Q_UNUSED(barset)
77 Q_UNUSED(barset)
58 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
78 DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender());
59 changeSeries(series->drilldownSeries(category));
79 changeSeries(series->drilldownSeries(category));
60 }
80 }
61
81
62 private:
82 private:
63 QSeries* m_currentSeries;
83 QSeries* m_currentSeries;
64 };
84 };
65 //! [2]
85 //! [2]
66
86
67 int main(int argc, char *argv[])
87 int main(int argc, char *argv[])
68 {
88 {
69 QApplication a(argc, argv);
89 QApplication a(argc, argv);
70 QMainWindow window;
90 QMainWindow window;
71
91
72 DrilldownChart* drilldownChart = new DrilldownChart();
92 DrilldownChart* drilldownChart = new DrilldownChart();
73 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
93 drilldownChart->setTheme(QChart::ChartThemeBlueIcy);
74 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
94 drilldownChart->setAnimationOptions(QChart::SeriesAnimations);
75
95
76 //! [3]
96 //! [3]
77 // Define categories
97 // Define categories
78 QStringList months;
98 QStringList months;
79 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
99 months << "May" << "Jun" << "Jul" << "Aug" << "Sep";
80 QStringList weeks;
100 QStringList weeks;
81 weeks << "week 1" << "week 2" << "week 3" << "week 4";
101 weeks << "week 1" << "week 2" << "week 3" << "week 4";
82 QStringList plants;
102 QStringList plants;
83 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
103 plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo";
84 //! [3]
104 //! [3]
85
105
86 //! [4]
106 //! [4]
87 // Create drilldown structure
107 // Create drilldown structure
88 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
108 DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart);
89 seasonSeries->setName("Crop by month - Season");
109 seasonSeries->setName("Crop by month - Season");
90
110
91 // Each month in season series has drilldown series for weekly data
111 // Each month in season series has drilldown series for weekly data
92 foreach (QString month, months) {
112 foreach (QString month, months) {
93
113
94 // Create drilldown series for every week
114 // Create drilldown series for every week
95 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
115 DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart);
96 seasonSeries->mapDrilldownSeries(month, weeklySeries);
116 seasonSeries->mapDrilldownSeries(month, weeklySeries);
97
117
98 // Drilling down from weekly data brings us back to season data.
118 // Drilling down from weekly data brings us back to season data.
99 foreach (QString week, weeks) {
119 foreach (QString week, weeks) {
100 weeklySeries->mapDrilldownSeries(week, seasonSeries);
120 weeklySeries->mapDrilldownSeries(week, seasonSeries);
101 weeklySeries->setName(QString("Crop by week - " + month));
121 weeklySeries->setName(QString("Crop by week - " + month));
102 }
122 }
103
123
104 // Use right click signal to implement drilldown
124 // Use right click signal to implement drilldown
105 QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
125 QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
106 }
126 }
107
127
108 // Enable drilldown from season series using right click.
128 // Enable drilldown from season series using right click.
109 QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
129 QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,QString,Qt::MouseButtons)), drilldownChart, SLOT(handleClicked(QBarSet*,QString,Qt::MouseButtons)));
110 //! [4]
130 //! [4]
111
131
112 //! [5]
132 //! [5]
113 // Fill monthly and weekly series with data
133 // Fill monthly and weekly series with data
114 foreach (QString plant, plants) {
134 foreach (QString plant, plants) {
115 QBarSet* monthlyCrop = new QBarSet(plant);
135 QBarSet* monthlyCrop = new QBarSet(plant);
116 foreach (QString month, months) {
136 foreach (QString month, months) {
117 QBarSet* weeklyCrop = new QBarSet(plant);
137 QBarSet* weeklyCrop = new QBarSet(plant);
118 foreach (QString week, weeks )
138 foreach (QString week, weeks )
119 *weeklyCrop << (qrand() % 20);
139 *weeklyCrop << (qrand() % 20);
120 // Get the drilldown series from season series and add crop to it.
140 // Get the drilldown series from season series and add crop to it.
121 seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop);
141 seasonSeries->drilldownSeries(month)->appendBarSet(weeklyCrop);
122 seasonSeries->drilldownSeries(month)->setToolTipEnabled(true);
142 seasonSeries->drilldownSeries(month)->setToolTipEnabled(true);
123 *monthlyCrop << weeklyCrop->total();
143 *monthlyCrop << weeklyCrop->total();
124 }
144 }
125 seasonSeries->appendBarSet(monthlyCrop);
145 seasonSeries->appendBarSet(monthlyCrop);
126 }
146 }
127 //! [5]
147 //! [5]
128
148
129 seasonSeries->setToolTipEnabled(true);
149 seasonSeries->setToolTipEnabled(true);
130
150
131 //! [6]
151 //! [6]
132 // Show season series in initial view
152 // Show season series in initial view
133 drilldownChart->changeSeries(seasonSeries);
153 drilldownChart->changeSeries(seasonSeries);
134 drilldownChart->setTitle(seasonSeries->name());
154 drilldownChart->setTitle(seasonSeries->name());
135 //! [6]
155 //! [6]
136
156
137 drilldownChart->axisX()->setGridLineVisible(false);
157 drilldownChart->axisX()->setGridLineVisible(false);
138
158
139 QChartView *chartView = new QChartView(drilldownChart);
159 QChartView *chartView = new QChartView(drilldownChart);
140 window.setCentralWidget(chartView);
160 window.setCentralWidget(chartView);
141 window.resize(400, 300);
161 window.resize(400, 300);
142 window.show();
162 window.show();
143
163
144 return a.exec();
164 return a.exec();
145 }
165 }
146
166
147 #include "main.moc"
167 #include "main.moc"
@@ -1,235 +1,255
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
1 #include "customtablemodel.h"
21 #include "customtablemodel.h"
2 #include <QVector>
22 #include <QVector>
3 #include <QTime>
23 #include <QTime>
4
24
5 CustomTableModel::CustomTableModel(QObject *parent) :
25 CustomTableModel::CustomTableModel(QObject *parent) :
6 QAbstractTableModel(parent)
26 QAbstractTableModel(parent)
7 {
27 {
8 // m_points.append(QPointF(10, 50));
28 // m_points.append(QPointF(10, 50));
9 // m_labels.append("Apples");
29 // m_labels.append("Apples");
10 // m_points.append(QPointF(60, 70));
30 // m_points.append(QPointF(60, 70));
11 // m_labels.append("Oranges");
31 // m_labels.append("Oranges");
12 // m_points.append(QPointF(110, 50));
32 // m_points.append(QPointF(110, 50));
13 // m_labels.append("Bananas");
33 // m_labels.append("Bananas");
14 // m_points.append(QPointF(140, 40));
34 // m_points.append(QPointF(140, 40));
15 // m_labels.append("Lemons");
35 // m_labels.append("Lemons");
16 // m_points.append(QPointF(200, 150));
36 // m_points.append(QPointF(200, 150));
17 // m_labels.append("Plums");
37 // m_labels.append("Plums");
18 // m_points.append(QPointF(225, 75));
38 // m_points.append(QPointF(225, 75));
19 // m_labels.append("Pearls");
39 // m_labels.append("Pearls");
20
40
21 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
41 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
22
42
23 // m_data
43 // m_data
24 for (int i = 0; i < 6; i++)
44 for (int i = 0; i < 6; i++)
25 {
45 {
26 QVector<qreal>* dataVec = new QVector<qreal>(6);
46 QVector<qreal>* dataVec = new QVector<qreal>(6);
27 QVector<QColor>* colorVec = new QVector<QColor>(6);
47 QVector<QColor>* colorVec = new QVector<QColor>(6);
28 for (int k = 0; k < dataVec->size(); k++)
48 for (int k = 0; k < dataVec->size(); k++)
29 {
49 {
30 if (k%2 == 0)
50 if (k%2 == 0)
31 dataVec->replace(k, i * 50 + qrand()%20);
51 dataVec->replace(k, i * 50 + qrand()%20);
32 else
52 else
33 dataVec->replace(k, qrand()%100);
53 dataVec->replace(k, qrand()%100);
34 colorVec->replace(k, QColor(Qt::white));
54 colorVec->replace(k, QColor(Qt::white));
35 }
55 }
36 m_data.append(dataVec);
56 m_data.append(dataVec);
37 m_labels.append(QString("Row: %1").arg((i + 1)));
57 m_labels.append(QString("Row: %1").arg((i + 1)));
38 m_rowsColors.append(colorVec);
58 m_rowsColors.append(colorVec);
39 }
59 }
40 }
60 }
41
61
42 int CustomTableModel::rowCount(const QModelIndex & parent) const
62 int CustomTableModel::rowCount(const QModelIndex & parent) const
43 {
63 {
44 Q_UNUSED(parent)
64 Q_UNUSED(parent)
45 // return m_points.count();
65 // return m_points.count();
46 return m_data.count();
66 return m_data.count();
47 }
67 }
48
68
49 int CustomTableModel::columnCount(const QModelIndex & parent) const
69 int CustomTableModel::columnCount(const QModelIndex & parent) const
50 {
70 {
51 Q_UNUSED(parent)
71 Q_UNUSED(parent)
52 // return 3;
72 // return 3;
53 return 6;
73 return 6;
54 }
74 }
55
75
56 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
76 QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const
57 {
77 {
58 if (role != Qt::DisplayRole)
78 if (role != Qt::DisplayRole)
59 return QVariant();
79 return QVariant();
60
80
61 if (orientation == Qt::Horizontal)
81 if (orientation == Qt::Horizontal)
62 {
82 {
63 switch(section)
83 switch(section)
64 {
84 {
65 // case 0:
85 // case 0:
66 // return "x";
86 // return "x";
67 // case 1:
87 // case 1:
68 // return "y";
88 // return "y";
69 // case 2:
89 // case 2:
70 case 6:
90 case 6:
71 return "Fruit";
91 return "Fruit";
72 default:
92 default:
73 if (section%2 == 0)
93 if (section%2 == 0)
74 return "x";
94 return "x";
75 else
95 else
76 return "y";
96 return "y";
77 // return "What?";
97 // return "What?";
78 }
98 }
79 }
99 }
80 else
100 else
81 return QString("%1").arg(section + 1);
101 return QString("%1").arg(section + 1);
82 }
102 }
83
103
84 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
104 QVariant CustomTableModel::data(const QModelIndex & index, int role) const
85 {
105 {
86 if (role == Qt::DisplayRole)
106 if (role == Qt::DisplayRole)
87 {
107 {
88 switch(index.column())
108 switch(index.column())
89 {
109 {
90 // case 0:
110 // case 0:
91 // return m_points[index.row()].x();
111 // return m_points[index.row()].x();
92 // case 1:
112 // case 1:
93 // return m_points[index.row()].y();
113 // return m_points[index.row()].y();
94 // case 2:
114 // case 2:
95 case 6:
115 case 6:
96 return m_labels[index.row()];
116 return m_labels[index.row()];
97 default:
117 default:
98 return m_data[index.row()]->at(index.column());
118 return m_data[index.row()]->at(index.column());
99 break;
119 break;
100 }
120 }
101 }
121 }
102 else if (role == Qt::EditRole)
122 else if (role == Qt::EditRole)
103 {
123 {
104 switch(index.column())
124 switch(index.column())
105 {
125 {
106 // case 0:
126 // case 0:
107 // return m_points[index.row()].x();
127 // return m_points[index.row()].x();
108 // case 1:
128 // case 1:
109 // return m_points[index.row()].y();
129 // return m_points[index.row()].y();
110 // case 2:
130 // case 2:
111 case 6:
131 case 6:
112 return m_labels[index.row()];
132 return m_labels[index.row()];
113 default:
133 default:
114 return m_data[index.row()]->at(index.column());
134 return m_data[index.row()]->at(index.column());
115 break;
135 break;
116 }
136 }
117 }
137 }
118 else if (role == Qt::BackgroundRole)
138 else if (role == Qt::BackgroundRole)
119 {
139 {
120 return m_rowsColors[index.row()]->at(index.column());
140 return m_rowsColors[index.row()]->at(index.column());
121 }
141 }
122 return QVariant();
142 return QVariant();
123 }
143 }
124
144
125 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
145 bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role)
126 {
146 {
127 if (index.isValid() && role == Qt::EditRole)
147 if (index.isValid() && role == Qt::EditRole)
128 {
148 {
129 switch(index.column())
149 switch(index.column())
130 {
150 {
131 // case 0:
151 // case 0:
132 // m_points[index.row()].setX(value.toDouble());
152 // m_points[index.row()].setX(value.toDouble());
133 // break;
153 // break;
134 // case 1:
154 // case 1:
135 // m_points[index.row()].setY(value.toDouble());
155 // m_points[index.row()].setY(value.toDouble());
136 // break;
156 // break;
137 // case 2:
157 // case 2:
138 case 6:
158 case 6:
139 m_labels.replace(index.row(), value.toString());
159 m_labels.replace(index.row(), value.toString());
140 break;
160 break;
141 default:
161 default:
142 m_data[index.row()]->replace(index.column(), value.toDouble());
162 m_data[index.row()]->replace(index.column(), value.toDouble());
143 break;
163 break;
144 // return false;
164 // return false;
145 }
165 }
146 emit dataChanged(index, index);
166 emit dataChanged(index, index);
147 return true;
167 return true;
148 }
168 }
149 else if (role == Qt::BackgroundRole)
169 else if (role == Qt::BackgroundRole)
150 {
170 {
151 m_rowsColors[index.row()]->replace(index.column(), value.value<QColor>());
171 m_rowsColors[index.row()]->replace(index.column(), value.value<QColor>());
152 return true;
172 return true;
153 }
173 }
154 return false;
174 return false;
155 }
175 }
156
176
157 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
177 Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const
158 {
178 {
159 // if (!index.isValid())
179 // if (!index.isValid())
160 // return Qt::ItemIsEnabled;
180 // return Qt::ItemIsEnabled;
161 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
181 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
162 }
182 }
163
183
164 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
184 bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent)
165 {
185 {
166 Q_UNUSED(parent)
186 Q_UNUSED(parent)
167
187
168 if (row < 0)
188 if (row < 0)
169 row = 0;
189 row = 0;
170 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
190 beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1);
171 for (int i = row; i < row + count; i++)
191 for (int i = row; i < row + count; i++)
172 {
192 {
173 // m_points.insert(row, QPointF(10,20));
193 // m_points.insert(row, QPointF(10,20));
174 QVector<qreal>* dataVec = new QVector<qreal>(6);
194 QVector<qreal>* dataVec = new QVector<qreal>(6);
175 QVector<QColor>* colorVec = new QVector<QColor>(6);
195 QVector<QColor>* colorVec = new QVector<QColor>(6);
176 for (int k = 0; k < dataVec->size(); k++)
196 for (int k = 0; k < dataVec->size(); k++)
177 {
197 {
178 if (k%2 == 0)
198 if (k%2 == 0)
179 // dataVec->replace(k, i * 50 + qrand()%20);
199 // dataVec->replace(k, i * 50 + qrand()%20);
180 {
200 {
181 int difference = 0;
201 int difference = 0;
182 if (i < m_data.size())
202 if (i < m_data.size())
183 {
203 {
184 if (i - 1 >= 0)
204 if (i - 1 >= 0)
185 {
205 {
186 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
206 difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count);
187 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
207 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference));
188 }
208 }
189 else
209 else
190 dataVec->replace(k, qrand()%40 + 10);
210 dataVec->replace(k, qrand()%40 + 10);
191 }
211 }
192 else
212 else
193 {
213 {
194 if (i - 1 >= 0)
214 if (i - 1 >= 0)
195 {
215 {
196 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
216 dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10);
197 }
217 }
198 else
218 else
199 {
219 {
200 dataVec->replace(k, qrand()%40 + 10);
220 dataVec->replace(k, qrand()%40 + 10);
201 }
221 }
202 }
222 }
203 }
223 }
204 else
224 else
205 dataVec->replace(k, qrand()%100);
225 dataVec->replace(k, qrand()%100);
206 colorVec->replace(k, QColor(Qt::white));
226 colorVec->replace(k, QColor(Qt::white));
207 }
227 }
208 m_data.insert(i, dataVec);
228 m_data.insert(i, dataVec);
209 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
229 m_labels.insert(i,(QString("Row: %1").arg(i + 1)));
210 m_rowsColors.insert(i, colorVec);
230 m_rowsColors.insert(i, colorVec);
211 }
231 }
212 endInsertRows();
232 endInsertRows();
213 return true;
233 return true;
214 }
234 }
215
235
216 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
236 bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent)
217 {
237 {
218 if (row > this->rowCount() - 1)
238 if (row > this->rowCount() - 1)
219 return false;
239 return false;
220 if (row < 0)
240 if (row < 0)
221 row = 0;
241 row = 0;
222 if (row + count > rowCount())
242 if (row + count > rowCount())
223 return false;
243 return false;
224 beginRemoveRows(parent, row, row + count - 1);
244 beginRemoveRows(parent, row, row + count - 1);
225 for (int i = row; i < row + count; i++)
245 for (int i = row; i < row + count; i++)
226 {
246 {
227 // m_points.removeAt(row);
247 // m_points.removeAt(row);
228 QVector<qreal>* item = m_data.at(row);
248 QVector<qreal>* item = m_data.at(row);
229 m_data.removeAt(row);
249 m_data.removeAt(row);
230 delete item;
250 delete item;
231 m_labels.removeAt(row);
251 m_labels.removeAt(row);
232 }
252 }
233 endRemoveRows();
253 endRemoveRows();
234 return true;
254 return true;
235 }
255 }
@@ -1,36 +1,56
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
1 #ifndef XYPOINTSMODEL_H
21 #ifndef XYPOINTSMODEL_H
2 #define XYPOINTSMODEL_H
22 #define XYPOINTSMODEL_H
3
23
4 #include <QAbstractTableModel>
24 #include <QAbstractTableModel>
5 #include <QPointF>
25 #include <QPointF>
6 #include <QStringList>
26 #include <QStringList>
7 #include <QColor>
27 #include <QColor>
8
28
9 class CustomTableModel : public QAbstractTableModel
29 class CustomTableModel : public QAbstractTableModel
10 {
30 {
11 Q_OBJECT
31 Q_OBJECT
12 public:
32 public:
13 explicit CustomTableModel(QObject *parent = 0);
33 explicit CustomTableModel(QObject *parent = 0);
14
34
15 int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
35 int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
16 int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
36 int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
17 QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
37 QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
18 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
38 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
19 bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
39 bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole );
20 Qt::ItemFlags flags ( const QModelIndex & index ) const;
40 Qt::ItemFlags flags ( const QModelIndex & index ) const;
21 bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
41 bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
22 bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
42 bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
23
43
24 //signals:
44 //signals:
25
45
26 //public slots:
46 //public slots:
27 private:
47 private:
28 QList<QVector<qreal>* > m_data;
48 QList<QVector<qreal>* > m_data;
29 QList<QVector<QColor>* > m_rowsColors;
49 QList<QVector<QColor>* > m_rowsColors;
30 QList<QPointF> m_points;
50 QList<QPointF> m_points;
31 QStringList m_labels;
51 QStringList m_labels;
32
52
33
53
34 };
54 };
35
55
36 #endif // XYPOINTSMODEL_H
56 #endif // XYPOINTSMODEL_H
@@ -1,11 +1,31
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
1 #include <QtGui/QApplication>
21 #include <QtGui/QApplication>
2 #include "tablewidget.h"
22 #include "tablewidget.h"
3
23
4 int main(int argc, char *argv[])
24 int main(int argc, char *argv[])
5 {
25 {
6 QApplication a(argc, argv);
26 QApplication a(argc, argv);
7 TableWidget w;
27 TableWidget w;
8 w.show();
28 w.show();
9
29
10 return a.exec();
30 return a.exec();
11 }
31 }
@@ -1,287 +1,307
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
1 #include "tablewidget.h"
21 #include "tablewidget.h"
2 #include <QGridLayout>
22 #include <QGridLayout>
3 #include <QTableView>
23 #include <QTableView>
4 #include <QStyledItemDelegate>
24 #include <QStyledItemDelegate>
5 #include "qlineseries.h"
25 #include "qlineseries.h"
6 #include "qsplineseries.h"
26 #include "qsplineseries.h"
7 #include "qscatterseries.h"
27 #include "qscatterseries.h"
8 #include "customtablemodel.h"
28 #include "customtablemodel.h"
9 #include "qpieseries.h"
29 #include "qpieseries.h"
10 #include "qareaseries.h"
30 #include "qareaseries.h"
11 #include "qbarseries.h"
31 #include "qbarseries.h"
12 #include <QPushButton>
32 #include <QPushButton>
13 #include <QRadioButton>
33 #include <QRadioButton>
14 #include <QSpinBox>
34 #include <QSpinBox>
15 #include <QTime>
35 #include <QTime>
16
36
17 TableWidget::TableWidget(QWidget *parent)
37 TableWidget::TableWidget(QWidget *parent)
18 : QWidget(parent)
38 : QWidget(parent)
19 {
39 {
20 setGeometry(100, 100, 1000, 600);
40 setGeometry(100, 100, 1000, 600);
21 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
41 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
22 // create simple model for storing data
42 // create simple model for storing data
23 // user's table data model
43 // user's table data model
24 m_model = new CustomTableModel;
44 m_model = new CustomTableModel;
25 tableView = new QTableView;
45 tableView = new QTableView;
26 tableView->setModel(m_model);
46 tableView->setModel(m_model);
27 tableView->setMinimumHeight(240);
47 tableView->setMinimumHeight(240);
28 // tableView->setMinimumSize(340, 480);
48 // tableView->setMinimumSize(340, 480);
29 // tableView->setItemDelegate(new QStyledItemDelegate);
49 // tableView->setItemDelegate(new QStyledItemDelegate);
30 chartView = new QChartView(this);
50 chartView = new QChartView(this);
31 chartView->setRenderHint(QPainter::Antialiasing);
51 chartView->setRenderHint(QPainter::Antialiasing);
32 chartView->setMinimumSize(640, 480);
52 chartView->setMinimumSize(640, 480);
33
53
34 // create
54 // create
35 // QLineSeries* series = new QLineSeries;
55 // QLineSeries* series = new QLineSeries;
36 // QSplineSeries* series = new QSplineSeries;
56 // QSplineSeries* series = new QSplineSeries;
37 // QScatterSeries* series = new QScatterSeries;
57 // QScatterSeries* series = new QScatterSeries;
38 // series->setModel(m_model);
58 // series->setModel(m_model);
39 // series->setModelMapping(0,1, Qt::Vertical);
59 // series->setModelMapping(0,1, Qt::Vertical);
40
60
41 // QPieSeries* pieSeries = new QPieSeries;
61 // QPieSeries* pieSeries = new QPieSeries;
42 // pieSeries->setModel(model);
62 // pieSeries->setModel(model);
43 // pieSeries
63 // pieSeries
44
64
45 // chartView->addSeries(series);
65 // chartView->addSeries(series);
46
66
47 // add, remove data buttons
67 // add, remove data buttons
48 QPushButton* addRowAboveButton = new QPushButton("Add row above");
68 QPushButton* addRowAboveButton = new QPushButton("Add row above");
49 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
69 connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove()));
50
70
51 QPushButton* addRowBelowButton = new QPushButton("Add row below");
71 QPushButton* addRowBelowButton = new QPushButton("Add row below");
52 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
72 connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow()));
53
73
54 QPushButton* removeRowButton = new QPushButton("Remove row");
74 QPushButton* removeRowButton = new QPushButton("Remove row");
55 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
75 connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow()));
56
76
57 linesCountSpinBox = new QSpinBox;
77 linesCountSpinBox = new QSpinBox;
58 linesCountSpinBox->setRange(1, 10);
78 linesCountSpinBox->setRange(1, 10);
59 linesCountSpinBox->setValue(1);
79 linesCountSpinBox->setValue(1);
60
80
61 // buttons layout
81 // buttons layout
62 QVBoxLayout* buttonsLayout = new QVBoxLayout;
82 QVBoxLayout* buttonsLayout = new QVBoxLayout;
63 buttonsLayout->addWidget(linesCountSpinBox);
83 buttonsLayout->addWidget(linesCountSpinBox);
64 buttonsLayout->addWidget(addRowAboveButton);
84 buttonsLayout->addWidget(addRowAboveButton);
65 buttonsLayout->addWidget(addRowBelowButton);
85 buttonsLayout->addWidget(addRowBelowButton);
66 buttonsLayout->addWidget(removeRowButton);
86 buttonsLayout->addWidget(removeRowButton);
67 buttonsLayout->addStretch();
87 buttonsLayout->addStretch();
68
88
69 // chart type radio buttons
89 // chart type radio buttons
70 lineRadioButton = new QRadioButton("Line");
90 lineRadioButton = new QRadioButton("Line");
71 splineRadioButton = new QRadioButton("Spline");
91 splineRadioButton = new QRadioButton("Spline");
72 scatterRadioButton = new QRadioButton("Scatter");
92 scatterRadioButton = new QRadioButton("Scatter");
73 pieRadioButton = new QRadioButton("Pie");
93 pieRadioButton = new QRadioButton("Pie");
74 areaRadioButton = new QRadioButton("Area");
94 areaRadioButton = new QRadioButton("Area");
75 barRadioButton = new QRadioButton("Bar");
95 barRadioButton = new QRadioButton("Bar");
76
96
77 connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
97 connect(lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
78 connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
98 connect(splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
79 connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
99 connect(scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
80 connect(pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
100 connect(pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
81 connect(areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
101 connect(areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
82 connect(barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
102 connect(barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType()));
83 lineRadioButton->setChecked(true);
103 lineRadioButton->setChecked(true);
84
104
85 // radio buttons layout
105 // radio buttons layout
86 QVBoxLayout* radioLayout = new QVBoxLayout;
106 QVBoxLayout* radioLayout = new QVBoxLayout;
87 radioLayout->addWidget(lineRadioButton);
107 radioLayout->addWidget(lineRadioButton);
88 radioLayout->addWidget(splineRadioButton);
108 radioLayout->addWidget(splineRadioButton);
89 radioLayout->addWidget(scatterRadioButton);
109 radioLayout->addWidget(scatterRadioButton);
90 radioLayout->addWidget(pieRadioButton);
110 radioLayout->addWidget(pieRadioButton);
91 radioLayout->addWidget(areaRadioButton);
111 radioLayout->addWidget(areaRadioButton);
92 radioLayout->addWidget(barRadioButton);
112 radioLayout->addWidget(barRadioButton);
93 radioLayout->addStretch();
113 radioLayout->addStretch();
94
114
95 // create main layout
115 // create main layout
96 QGridLayout* mainLayout = new QGridLayout;
116 QGridLayout* mainLayout = new QGridLayout;
97 mainLayout->addLayout(buttonsLayout, 1, 0);
117 mainLayout->addLayout(buttonsLayout, 1, 0);
98 mainLayout->addLayout(radioLayout, 2, 0);
118 mainLayout->addLayout(radioLayout, 2, 0);
99 mainLayout->addWidget(tableView, 1, 1);
119 mainLayout->addWidget(tableView, 1, 1);
100 mainLayout->addWidget(chartView, 2, 1);
120 mainLayout->addWidget(chartView, 2, 1);
101 setLayout(mainLayout);
121 setLayout(mainLayout);
102 lineRadioButton->setFocus();
122 lineRadioButton->setFocus();
103 }
123 }
104
124
105 void TableWidget::addRowAbove()
125 void TableWidget::addRowAbove()
106 {
126 {
107 // m_model->insertRow(m_model->rowCount());
127 // m_model->insertRow(m_model->rowCount());
108 // m_model->insertRow(tableView->currentIndex().row());
128 // m_model->insertRow(tableView->currentIndex().row());
109 m_model->insertRows(tableView->currentIndex().row(), linesCountSpinBox->value());
129 m_model->insertRows(tableView->currentIndex().row(), linesCountSpinBox->value());
110
130
111 }
131 }
112
132
113 void TableWidget::addRowBelow()
133 void TableWidget::addRowBelow()
114 {
134 {
115 // m_model->insertRow(m_model->rowCount());
135 // m_model->insertRow(m_model->rowCount());
116 // m_model->insertRow(tableView->currentIndex().row() + 1);
136 // m_model->insertRow(tableView->currentIndex().row() + 1);
117 m_model->insertRows(tableView->currentIndex().row() + 1, linesCountSpinBox->value());
137 m_model->insertRows(tableView->currentIndex().row() + 1, linesCountSpinBox->value());
118
138
119 }
139 }
120
140
121 void TableWidget::removeRow()
141 void TableWidget::removeRow()
122 {
142 {
123 // m_model->removeRow(m_model->rowCount() - 1);
143 // m_model->removeRow(m_model->rowCount() - 1);
124 // m_model->removeRow(tableView->currentIndex().row());
144 // m_model->removeRow(tableView->currentIndex().row());
125 m_model->removeRows(tableView->currentIndex().row(), qMin(m_model->rowCount() - tableView->currentIndex().row(), linesCountSpinBox->value()));
145 m_model->removeRows(tableView->currentIndex().row(), qMin(m_model->rowCount() - tableView->currentIndex().row(), linesCountSpinBox->value()));
126 }
146 }
127
147
128 void TableWidget::updateChartType()
148 void TableWidget::updateChartType()
129 {
149 {
130 chartView->removeAllSeries();
150 chartView->removeAllSeries();
131
151
132 if (lineRadioButton->isChecked())
152 if (lineRadioButton->isChecked())
133 {
153 {
134 QPen pen;
154 QPen pen;
135 pen.setWidth(2);
155 pen.setWidth(2);
136
156
137 QColor seriesColor("#8FBC8F");
157 QColor seriesColor("#8FBC8F");
138
158
139 // series 1
159 // series 1
140 series = new QLineSeries;
160 series = new QLineSeries;
141 series->setModel(m_model);
161 series->setModel(m_model);
142 series->setModelMapping(0,1, Qt::Vertical);
162 series->setModelMapping(0,1, Qt::Vertical);
143 series->setModelMappingShift(1, 4);
163 series->setModelMappingShift(1, 4);
144 // series->setModelMapping(0,1, Qt::Horizontal);
164 // series->setModelMapping(0,1, Qt::Horizontal);
145
165
146 pen.setColor(seriesColor);
166 pen.setColor(seriesColor);
147 series->setPen(pen);
167 series->setPen(pen);
148 chartView->addSeries(series);
168 chartView->addSeries(series);
149 for (int i = 1; i <=4; i++)
169 for (int i = 1; i <=4; i++)
150 {
170 {
151 m_model->setData(m_model->index(i, 0), seriesColor , Qt::BackgroundRole);
171 m_model->setData(m_model->index(i, 0), seriesColor , Qt::BackgroundRole);
152 m_model->setData(m_model->index(i, 1), seriesColor , Qt::BackgroundRole);
172 m_model->setData(m_model->index(i, 1), seriesColor , Qt::BackgroundRole);
153 }
173 }
154 // tableView->setsetStyleSheet("QTableView { border: 2px solid red }");
174 // tableView->setsetStyleSheet("QTableView { border: 2px solid red }");
155
175
156 seriesColor = QColor("#1E90FF");
176 seriesColor = QColor("#1E90FF");
157
177
158 // series 2
178 // series 2
159 series = new QLineSeries;
179 series = new QLineSeries;
160 series->setModel(m_model);
180 series->setModel(m_model);
161 series->setModelMapping(2,3, Qt::Vertical);
181 series->setModelMapping(2,3, Qt::Vertical);
162 // series->setModelMapping(2,3, Qt::Horizontal);
182 // series->setModelMapping(2,3, Qt::Horizontal);
163 pen.setColor(seriesColor);
183 pen.setColor(seriesColor);
164 series->setPen(pen);
184 series->setPen(pen);
165 chartView->addSeries(series);
185 chartView->addSeries(series);
166
186
167 chartView->axisX()->setRange(0, 500);
187 chartView->axisX()->setRange(0, 500);
168
188
169 for (int i = 0; i < m_model->rowCount(); i++)
189 for (int i = 0; i < m_model->rowCount(); i++)
170 {
190 {
171 m_model->setData(m_model->index(i, 2), seriesColor , Qt::BackgroundRole);
191 m_model->setData(m_model->index(i, 2), seriesColor , Qt::BackgroundRole);
172 m_model->setData(m_model->index(i, 3), seriesColor , Qt::BackgroundRole);
192 m_model->setData(m_model->index(i, 3), seriesColor , Qt::BackgroundRole);
173 }
193 }
174 // // series 3
194 // // series 3
175 // series = new QLineSeries;
195 // series = new QLineSeries;
176 // series->setModel(m_model);
196 // series->setModel(m_model);
177 // series->setModelMapping(4,5, Qt::Vertical);
197 // series->setModelMapping(4,5, Qt::Vertical);
178 //// series->setModelMapping(4,5, Qt::Horizontal);
198 //// series->setModelMapping(4,5, Qt::Horizontal);
179 // chartView->addSeries(series);
199 // chartView->addSeries(series);
180 }
200 }
181 else if (splineRadioButton->isChecked())
201 else if (splineRadioButton->isChecked())
182 {
202 {
183 // series 1
203 // series 1
184 series = new QSplineSeries;
204 series = new QSplineSeries;
185 series->setModel(m_model);
205 series->setModel(m_model);
186 series->setModelMapping(0,1, Qt::Vertical);
206 series->setModelMapping(0,1, Qt::Vertical);
187 series->setModelMappingShift(1, 4);
207 series->setModelMappingShift(1, 4);
188 // series->setModelMapping(0,1, Qt::Horizontal);
208 // series->setModelMapping(0,1, Qt::Horizontal);
189 chartView->addSeries(series);
209 chartView->addSeries(series);
190
210
191 // series 2
211 // series 2
192 series = new QSplineSeries;
212 series = new QSplineSeries;
193 series->setModel(m_model);
213 series->setModel(m_model);
194 series->setModelMapping(2,3, Qt::Vertical);
214 series->setModelMapping(2,3, Qt::Vertical);
195 series->setModelMappingShift(0, 0);
215 series->setModelMappingShift(0, 0);
196 // series->setModelMapping(2,3, Qt::Horizontal);
216 // series->setModelMapping(2,3, Qt::Horizontal);
197 chartView->addSeries(series);
217 chartView->addSeries(series);
198
218
199 // series 3
219 // series 3
200 series = new QSplineSeries;
220 series = new QSplineSeries;
201 series->setModel(m_model);
221 series->setModel(m_model);
202 series->setModelMapping(4,5, Qt::Vertical);
222 series->setModelMapping(4,5, Qt::Vertical);
203 series->setModelMappingShift(0, 0);
223 series->setModelMappingShift(0, 0);
204 // series->setModelMapping(4,5, Qt::Horizontal);
224 // series->setModelMapping(4,5, Qt::Horizontal);
205 chartView->addSeries(series);
225 chartView->addSeries(series);
206 }
226 }
207 else if (scatterRadioButton->isChecked())
227 else if (scatterRadioButton->isChecked())
208 {
228 {
209 // series 1
229 // series 1
210 series = new QScatterSeries;
230 series = new QScatterSeries;
211 series->setModel(m_model);
231 series->setModel(m_model);
212 series->setModelMapping(0,1, Qt::Vertical);
232 series->setModelMapping(0,1, Qt::Vertical);
213 // series->setModelMapping(0,1, Qt::Horizontal);
233 // series->setModelMapping(0,1, Qt::Horizontal);
214 chartView->addSeries(series);
234 chartView->addSeries(series);
215
235
216 // series 2
236 // series 2
217 series = new QScatterSeries;
237 series = new QScatterSeries;
218 series->setModel(m_model);
238 series->setModel(m_model);
219 series->setModelMapping(2,3, Qt::Vertical);
239 series->setModelMapping(2,3, Qt::Vertical);
220 // series->setModelMapping(2,3, Qt::Horizontal);
240 // series->setModelMapping(2,3, Qt::Horizontal);
221 chartView->addSeries(series);
241 chartView->addSeries(series);
222
242
223 // series 3
243 // series 3
224 series = new QScatterSeries;
244 series = new QScatterSeries;
225 series->setModel(m_model);
245 series->setModel(m_model);
226 series->setModelMapping(4,5, Qt::Vertical);
246 series->setModelMapping(4,5, Qt::Vertical);
227 // series->setModelMapping(4,5, Qt::Horizontal);
247 // series->setModelMapping(4,5, Qt::Horizontal);
228 chartView->addSeries(series);
248 chartView->addSeries(series);
229 }
249 }
230 else if (pieRadioButton->isChecked())
250 else if (pieRadioButton->isChecked())
231 {
251 {
232 // pie 1
252 // pie 1
233 QPieSeries* pieSeries = new QPieSeries;
253 QPieSeries* pieSeries = new QPieSeries;
234 pieSeries->setModel(m_model);
254 pieSeries->setModel(m_model);
235 pieSeries->setModelMapping(0,0, Qt::Vertical);
255 pieSeries->setModelMapping(0,0, Qt::Vertical);
236 pieSeries->setLabelsVisible(true);
256 pieSeries->setLabelsVisible(true);
237 pieSeries->setPieSize(0.4);
257 pieSeries->setPieSize(0.4);
238 pieSeries->setPiePosition(0.2, 0.35);
258 pieSeries->setPiePosition(0.2, 0.35);
239 chartView->addSeries(pieSeries);
259 chartView->addSeries(pieSeries);
240
260
241 // pie 2
261 // pie 2
242 pieSeries = new QPieSeries;
262 pieSeries = new QPieSeries;
243 pieSeries->setModel(m_model);
263 pieSeries->setModel(m_model);
244 pieSeries->setModelMapping(1,1, Qt::Vertical);
264 pieSeries->setModelMapping(1,1, Qt::Vertical);
245 pieSeries->setLabelsVisible(true);
265 pieSeries->setLabelsVisible(true);
246 pieSeries->setPieSize(0.4);
266 pieSeries->setPieSize(0.4);
247 pieSeries->setPiePosition(0.8, 0.35);
267 pieSeries->setPiePosition(0.8, 0.35);
248 chartView->addSeries(pieSeries);
268 chartView->addSeries(pieSeries);
249
269
250 // pie 3
270 // pie 3
251 pieSeries = new QPieSeries;
271 pieSeries = new QPieSeries;
252 pieSeries->setModel(m_model);
272 pieSeries->setModel(m_model);
253 pieSeries->setModelMapping(2,2, Qt::Vertical);
273 pieSeries->setModelMapping(2,2, Qt::Vertical);
254 pieSeries->setLabelsVisible(true);
274 pieSeries->setLabelsVisible(true);
255 pieSeries->setPieSize(0.4);
275 pieSeries->setPieSize(0.4);
256 pieSeries->setPiePosition(0.5, 0.65);
276 pieSeries->setPiePosition(0.5, 0.65);
257 chartView->addSeries(pieSeries);
277 chartView->addSeries(pieSeries);
258 }
278 }
259 else if (areaRadioButton->isChecked())
279 else if (areaRadioButton->isChecked())
260 {
280 {
261 QLineSeries* upperLineSeries = new QLineSeries;
281 QLineSeries* upperLineSeries = new QLineSeries;
262 upperLineSeries->setModel(m_model);
282 upperLineSeries->setModel(m_model);
263 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
283 upperLineSeries->setModelMapping(0, 1, Qt::Vertical);
264 QLineSeries* lowerLineSeries = new QLineSeries;
284 QLineSeries* lowerLineSeries = new QLineSeries;
265 lowerLineSeries->setModel(m_model);
285 lowerLineSeries->setModel(m_model);
266 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
286 lowerLineSeries->setModelMapping(2, 3, Qt::Vertical);
267 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
287 QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries);
268 chartView->addSeries(areaSeries);
288 chartView->addSeries(areaSeries);
269 }
289 }
270 else if (barRadioButton->isChecked())
290 else if (barRadioButton->isChecked())
271 {
291 {
272 QBarSeries* barSeries = new QBarSeries(QStringList());
292 QBarSeries* barSeries = new QBarSeries(QStringList());
273 barSeries->setModel(m_model);
293 barSeries->setModel(m_model);
274 barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
294 barSeries->setModelMapping(5, 2, 4, Qt::Vertical);
275 barSeries->setToolTipEnabled(true);
295 barSeries->setToolTipEnabled(true);
276 chartView->addSeries(barSeries);
296 chartView->addSeries(barSeries);
277 }
297 }
278
298
279 // series->setModel(m_model);
299 // series->setModel(m_model);
280 // series->setModelMapping(0,1, Qt::Vertical);
300 // series->setModelMapping(0,1, Qt::Vertical);
281 // chartView->addSeries(series);
301 // chartView->addSeries(series);
282 }
302 }
283
303
284 TableWidget::~TableWidget()
304 TableWidget::~TableWidget()
285 {
305 {
286
306
287 }
307 }
@@ -1,45 +1,65
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
1 #ifndef TABLEWIDGET_H
21 #ifndef TABLEWIDGET_H
2 #define TABLEWIDGET_H
22 #define TABLEWIDGET_H
3
23
4 #include <QtGui/QWidget>
24 #include <QtGui/QWidget>
5 #include "qchartview.h"
25 #include "qchartview.h"
6 #include "qxyseries.h"
26 #include "qxyseries.h"
7
27
8 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
9
29
10 class CustomTableModel;
30 class CustomTableModel;
11 class QTableView;
31 class QTableView;
12 class QRadioButton;
32 class QRadioButton;
13 class QSpinBox;
33 class QSpinBox;
14 //class QSeries;
34 //class QSeries;
15
35
16 class TableWidget : public QWidget
36 class TableWidget : public QWidget
17 {
37 {
18 Q_OBJECT
38 Q_OBJECT
19
39
20 public:
40 public:
21 TableWidget(QWidget *parent = 0);
41 TableWidget(QWidget *parent = 0);
22 ~TableWidget();
42 ~TableWidget();
23
43
24
44
25 public slots:
45 public slots:
26 void addRowAbove();
46 void addRowAbove();
27 void addRowBelow();
47 void addRowBelow();
28 void removeRow();
48 void removeRow();
29 void updateChartType();
49 void updateChartType();
30
50
31 private:
51 private:
32 QChartView* chartView;
52 QChartView* chartView;
33 QXYSeries* series;
53 QXYSeries* series;
34 CustomTableModel* m_model;
54 CustomTableModel* m_model;
35 QTableView* tableView;
55 QTableView* tableView;
36 QRadioButton* lineRadioButton;
56 QRadioButton* lineRadioButton;
37 QRadioButton* splineRadioButton;
57 QRadioButton* splineRadioButton;
38 QRadioButton* scatterRadioButton;
58 QRadioButton* scatterRadioButton;
39 QRadioButton* pieRadioButton;
59 QRadioButton* pieRadioButton;
40 QRadioButton* areaRadioButton;
60 QRadioButton* areaRadioButton;
41 QRadioButton* barRadioButton;
61 QRadioButton* barRadioButton;
42 QSpinBox* linesCountSpinBox;
62 QSpinBox* linesCountSpinBox;
43 };
63 };
44
64
45 #endif // TABLEWIDGET_H
65 #endif // TABLEWIDGET_H
@@ -1,106 +1,87
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include "chartview.h"
21 #include "chartview.h"
41 #include <QMouseEvent>
22 #include <QMouseEvent>
42
23
43 ChartView::ChartView(QChart *chart, QWidget *parent) :
24 ChartView::ChartView(QChart *chart, QWidget *parent) :
44 QChartView(chart, parent), m_rubberBand(QRubberBand::Rectangle, this), m_chart(chart)
25 QChartView(chart, parent), m_rubberBand(QRubberBand::Rectangle, this), m_chart(chart)
45 {
26 {
46 }
27 }
47
28
48 void ChartView::mousePressEvent(QMouseEvent *event)
29 void ChartView::mousePressEvent(QMouseEvent *event)
49 {
30 {
50 if (event->button() != Qt::LeftButton)
31 if (event->button() != Qt::LeftButton)
51 return;
32 return;
52
33
53 m_origin = event->pos();
34 m_origin = event->pos();
54 m_rubberBand.setGeometry(QRect(m_origin, QSize()));
35 m_rubberBand.setGeometry(QRect(m_origin, QSize()));
55 m_rubberBand.show();
36 m_rubberBand.show();
56
37
57 event->accept();
38 event->accept();
58 }
39 }
59
40
60 void ChartView::mouseMoveEvent(QMouseEvent *event)
41 void ChartView::mouseMoveEvent(QMouseEvent *event)
61 {
42 {
62 if (m_rubberBand.isVisible())
43 if (m_rubberBand.isVisible())
63 m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized());
44 m_rubberBand.setGeometry(QRect(m_origin, event->pos()).normalized());
64 }
45 }
65
46
66 void ChartView::mouseReleaseEvent(QMouseEvent *event)
47 void ChartView::mouseReleaseEvent(QMouseEvent *event)
67 {
48 {
68 if (event->button() == Qt::LeftButton && m_rubberBand.isVisible()) {
49 if (event->button() == Qt::LeftButton && m_rubberBand.isVisible()) {
69 m_rubberBand.hide();
50 m_rubberBand.hide();
70
51
71 QRect rect = m_rubberBand.geometry();
52 QRect rect = m_rubberBand.geometry();
72 m_chart->zoomIn(rect);
53 m_chart->zoomIn(rect);
73 event->accept();
54 event->accept();
74 }
55 }
75
56
76 if (event->button() == Qt::RightButton) {
57 if (event->button() == Qt::RightButton) {
77 m_chart->zoomOut();
58 m_chart->zoomOut();
78 }
59 }
79 }
60 }
80
61
81 void ChartView::keyPressEvent(QKeyEvent *event)
62 void ChartView::keyPressEvent(QKeyEvent *event)
82 {
63 {
83 switch (event->key()) {
64 switch (event->key()) {
84 case Qt::Key_Plus:
65 case Qt::Key_Plus:
85 m_chart->zoomIn();
66 m_chart->zoomIn();
86 break;
67 break;
87 case Qt::Key_Minus:
68 case Qt::Key_Minus:
88 m_chart->zoomOut();
69 m_chart->zoomOut();
89 break;
70 break;
90 case Qt::Key_Left:
71 case Qt::Key_Left:
91 m_chart->scrollLeft();
72 m_chart->scrollLeft();
92 break;
73 break;
93 case Qt::Key_Right:
74 case Qt::Key_Right:
94 m_chart->scrollRight();
75 m_chart->scrollRight();
95 break;
76 break;
96 case Qt::Key_Up:
77 case Qt::Key_Up:
97 m_chart->scrollUp();
78 m_chart->scrollUp();
98 break;
79 break;
99 case Qt::Key_Down:
80 case Qt::Key_Down:
100 m_chart->scrollDown();
81 m_chart->scrollDown();
101 break;
82 break;
102 default:
83 default:
103 QGraphicsView::keyPressEvent(event);
84 QGraphicsView::keyPressEvent(event);
104 break;
85 break;
105 }
86 }
106 }
87 }
@@ -1,66 +1,47
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
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.
11 **
14 **
12 ** "Redistribution and use in source and binary forms, with or without
15 ** If you have questions regarding the use of this file, please use
13 ** modification, are permitted provided that the following conditions are
16 ** contact form at http://qt.digia.com
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
37 **
18 **
38 ****************************************************************************/
19 ****************************************************************************/
39
20
40 #ifndef CHARTVIEW_H
21 #ifndef CHARTVIEW_H
41 #define CHARTVIEW_H
22 #define CHARTVIEW_H
42 #include <QChartView>
23 #include <QChartView>
43 #include <QRubberBand>
24 #include <QRubberBand>
44
25
45 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
46
27
47 class ChartView : public QChartView
28 class ChartView : public QChartView
48 {
29 {
49 public:
30 public:
50 ChartView(QChart *chart, QWidget *parent = 0);
31 ChartView(QChart *chart, QWidget *parent = 0);
51
32
52 protected:
33 protected:
53 void mousePressEvent(QMouseEvent *event);
34 void mousePressEvent(QMouseEvent *event);
54 void mouseMoveEvent(QMouseEvent *event);
35 void mouseMoveEvent(QMouseEvent *event);
55 void mouseReleaseEvent(QMouseEvent *event);
36 void mouseReleaseEvent(QMouseEvent *event);
56 void keyPressEvent(QKeyEvent *event);
37 void keyPressEvent(QKeyEvent *event);
57
38
58 private:
39 private:
59 bool rubberBandIsShown;
40 bool rubberBandIsShown;
60 QRubberBand m_rubberBand;
41 QRubberBand m_rubberBand;
61 QPoint m_origin;
42 QPoint m_origin;
62 QChart* m_chart;
43 QChart* m_chart;
63
44
64 };
45 };
65
46
66 #endif
47 #endif
@@ -1,85 +1,66
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:BSD$
9 ** $QT_BEGIN_LICENSE$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 **
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** "Redistribution and use in source and binary forms, with or without
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** modification, are permitted provided that the following conditions are
13 ** a written agreement between you and Digia.
14 ** met:
14 **
15 ** * Redistributions of source code must retain the above copyright
15 ** If you have questions regarding the use of this file, please use
16 ** notice, this list of conditions and the following disclaimer.
16 ** contact form at http://qt.digia.com
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** $QT_END_LICENSE$
18 ** notice, this list of conditions and the following disclaimer in
18 **
19 ** the documentation and/or other materials provided with the
19 ****************************************************************************/
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
20
40 #include "chartview.h"
21 #include "chartview.h"
41 #include <QApplication>
22 #include <QApplication>
42 #include <QMainWindow>
23 #include <QMainWindow>
43 #include <QLineSeries>
24 #include <QLineSeries>
44
25
45 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
46
27
47 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
48 {
29 {
49 QApplication a(argc, argv);
30 QApplication a(argc, argv);
50
31
51 //![1]
32 //![1]
52 QLineSeries* series0 = new QLineSeries();
33 QLineSeries* series0 = new QLineSeries();
53 QPen blue(Qt::blue);
34 QPen blue(Qt::blue);
54 blue.setWidth(3);
35 blue.setWidth(3);
55 series0->setPen(blue);
36 series0->setPen(blue);
56
37
57 QLineSeries* series1 = new QLineSeries();
38 QLineSeries* series1 = new QLineSeries();
58 QPen red(Qt::red);
39 QPen red(Qt::red);
59 red.setWidth(3);
40 red.setWidth(3);
60 series1->setPen(red);
41 series1->setPen(red);
61 //![1]
42 //![1]
62 //![2]
43 //![2]
63 *series0 << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10, 5);
44 *series0 << QPointF(0, 6) << QPointF(2, 4) << QPointF(3, 8) << QPointF(7, 4) << QPointF(10, 5);
64 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
45 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
65 //![2]
46 //![2]
66 //![3]
47 //![3]
67 QChart* chart = new QChart();
48 QChart* chart = new QChart();
68
49
69 chart->addSeries(series0);
50 chart->addSeries(series0);
70 chart->addSeries(series1);
51 chart->addSeries(series1);
71 chart->setTitle("Zoom in/out chart example");
52 chart->setTitle("Zoom in/out chart example");
72 chart->setAnimationOptions(QChart::AllAnimations);
53 chart->setAnimationOptions(QChart::AllAnimations);
73 //![3]
54 //![3]
74 //![4]
55 //![4]
75 ChartView* chartView = new ChartView(chart);
56 ChartView* chartView = new ChartView(chart);
76 chartView->setRenderHint(QPainter::Antialiasing);
57 chartView->setRenderHint(QPainter::Antialiasing);
77 //![4]
58 //![4]
78 //![5]
59 //![5]
79 QMainWindow window;
60 QMainWindow window;
80 window.setCentralWidget(chartView);
61 window.setCentralWidget(chartView);
81 window.resize(400, 300);
62 window.resize(400, 300);
82 window.show();
63 window.show();
83 //![5]
64 //![5]
84 return a.exec();
65 return a.exec();
85 }
66 }
@@ -1,69 +1,89
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
1 #include "declarativebarseries.h"
21 #include "declarativebarseries.h"
2 #include "declarativechart.h"
22 #include "declarativechart.h"
3 #include "qchart.h"
23 #include "qchart.h"
4 #include "qbarseries.h"
24 #include "qbarseries.h"
5 #include "qbarset.h"
25 #include "qbarset.h"
6
26
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
28
9 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
29 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
10 QDeclarativeItem(parent)
30 QDeclarativeItem(parent)
11 {
31 {
12 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 setFlag(QGraphicsItem::ItemHasNoContents, false);
13 }
33 }
14
34
15 void DeclarativeBarSeries::componentComplete()
35 void DeclarativeBarSeries::componentComplete()
16 {
36 {
17 if (!m_series) {
37 if (!m_series) {
18 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
38 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
19
39
20 if (declarativeChart) {
40 if (declarativeChart) {
21 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
41 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
22 Q_ASSERT(chart);
42 Q_ASSERT(chart);
23
43
24 // QStringList categories;
44 // QStringList categories;
25 // categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
45 // categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
26 // m_series = new QBarSeries(categories);
46 // m_series = new QBarSeries(categories);
27 // m_series = new QBarSeries(m_categories);
47 // m_series = new QBarSeries(m_categories);
28 m_series = new QBarSeries(m_categories);
48 m_series = new QBarSeries(m_categories);
29
49
30 // TODO: use data from model
50 // TODO: use data from model
31 QBarSet *set0 = new QBarSet("Bub");
51 QBarSet *set0 = new QBarSet("Bub");
32 QBarSet *set1 = new QBarSet("Bob");
52 QBarSet *set1 = new QBarSet("Bob");
33 QBarSet *set2 = new QBarSet("Guybrush");
53 QBarSet *set2 = new QBarSet("Guybrush");
34
54
35 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
55 *set0 << 1 << 2 << 3 << 4 << 5 << 6;
36 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
56 *set1 << 5 << 0 << 0 << 4 << 0 << 7;
37 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
57 *set2 << 3 << 5 << 8 << 13 << 8 << 5;
38
58
39 m_series->appendBarSet(set0);
59 m_series->appendBarSet(set0);
40 m_series->appendBarSet(set1);
60 m_series->appendBarSet(set1);
41 m_series->appendBarSet(set2);
61 m_series->appendBarSet(set2);
42
62
43 chart->addSeries(m_series);
63 chart->addSeries(m_series);
44 }
64 }
45 }
65 }
46 }
66 }
47
67
48 void DeclarativeBarSeries::setBarCategories(QStringList categories)
68 void DeclarativeBarSeries::setBarCategories(QStringList categories)
49 {
69 {
50 m_categories = categories;
70 m_categories = categories;
51 if (m_series) {
71 if (m_series) {
52 // Replace categories of the QBarSeries with the new categories
72 // Replace categories of the QBarSeries with the new categories
53 for (int i(0); i < m_categories.count(); i++) {
73 for (int i(0); i < m_categories.count(); i++) {
54 if (m_series->categories().at(i) != m_categories.at(i))
74 if (m_series->categories().at(i) != m_categories.at(i))
55 m_series->insertCategory(m_series->categoryCount(), m_categories.at(i));
75 m_series->insertCategory(m_series->categoryCount(), m_categories.at(i));
56 }
76 }
57 while (m_series->categoryCount() > m_categories.count())
77 while (m_series->categoryCount() > m_categories.count())
58 m_series->removeCategory(m_series->categoryCount() - 1);
78 m_series->removeCategory(m_series->categoryCount() - 1);
59 }
79 }
60 }
80 }
61
81
62 QStringList DeclarativeBarSeries::barCategories()
82 QStringList DeclarativeBarSeries::barCategories()
63 {
83 {
64 return m_categories;
84 return m_categories;
65 }
85 }
66
86
67 #include "moc_declarativebarseries.cpp"
87 #include "moc_declarativebarseries.cpp"
68
88
69 QTCOMMERCIALCHART_END_NAMESPACE
89 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,39 +1,59
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
1 #ifndef DECLARATIVEBARSERIES_H
21 #ifndef DECLARATIVEBARSERIES_H
2 #define DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include <QDeclarativeItem>
25 #include <QDeclarativeItem>
6
26
7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8
28
9 class QChart;
29 class QChart;
10 class QBarSeries;
30 class QBarSeries;
11
31
12 class DeclarativeBarSeries : public QDeclarativeItem
32 class DeclarativeBarSeries : public QDeclarativeItem
13 {
33 {
14 Q_OBJECT
34 Q_OBJECT
15 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
35 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
16
36
17 public:
37 public:
18 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
38 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
19
39
20 public: // from QDeclarativeParserStatus
40 public: // from QDeclarativeParserStatus
21 void componentComplete();
41 void componentComplete();
22
42
23 public:
43 public:
24 void setBarCategories(QStringList categories);
44 void setBarCategories(QStringList categories);
25 QStringList barCategories();
45 QStringList barCategories();
26
46
27 Q_SIGNALS:
47 Q_SIGNALS:
28
48
29 public Q_SLOTS:
49 public Q_SLOTS:
30
50
31 public:
51 public:
32 QChart *m_chart;
52 QChart *m_chart;
33 QBarSeries *m_series;
53 QBarSeries *m_series;
34 QStringList m_categories;
54 QStringList m_categories;
35 };
55 };
36
56
37 QTCOMMERCIALCHART_END_NAMESPACE
57 QTCOMMERCIALCHART_END_NAMESPACE
38
58
39 #endif // DECLARATIVEBARSERIES_H
59 #endif // DECLARATIVEBARSERIES_H
@@ -1,45 +1,65
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
1 #include "declarativechart.h"
21 #include "declarativechart.h"
2 #include <QPainter>
22 #include <QPainter>
3
23
4 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5
25
6 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
7 : QDeclarativeItem(parent),
27 : QDeclarativeItem(parent),
8 m_chart(new QChart(this))
28 m_chart(new QChart(this))
9 {
29 {
10 setFlag(QGraphicsItem::ItemHasNoContents, false);
30 setFlag(QGraphicsItem::ItemHasNoContents, false);
11 }
31 }
12
32
13 DeclarativeChart::~DeclarativeChart()
33 DeclarativeChart::~DeclarativeChart()
14 {
34 {
15 delete m_chart;
35 delete m_chart;
16 }
36 }
17
37
18 DeclarativeChart::ChartTheme DeclarativeChart::theme()
38 DeclarativeChart::ChartTheme DeclarativeChart::theme()
19 {
39 {
20 return (ChartTheme) m_chart->theme();
40 return (ChartTheme) m_chart->theme();
21 }
41 }
22
42
23 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
43 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
24 {
44 {
25 Q_UNUSED(oldGeometry)
45 Q_UNUSED(oldGeometry)
26
46
27 if (newGeometry.isValid()) {
47 if (newGeometry.isValid()) {
28 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
48 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
29 m_chart->resize(newGeometry.width(), newGeometry.height());
49 m_chart->resize(newGeometry.width(), newGeometry.height());
30 }
50 }
31 }
51 }
32 }
52 }
33
53
34 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
54 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
35 {
55 {
36 Q_UNUSED(option)
56 Q_UNUSED(option)
37 Q_UNUSED(widget)
57 Q_UNUSED(widget)
38
58
39 // TODO: optimized?
59 // TODO: optimized?
40 painter->setRenderHint(QPainter::Antialiasing, true);
60 painter->setRenderHint(QPainter::Antialiasing, true);
41 }
61 }
42
62
43 #include "moc_declarativechart.cpp"
63 #include "moc_declarativechart.cpp"
44
64
45 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,48 +1,68
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
1 #ifndef DECLARATIVECHART_H
21 #ifndef DECLARATIVECHART_H
2 #define DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
3
23
4 #include <QtCore/QtGlobal>
24 #include <QtCore/QtGlobal>
5 #include <QDeclarativeItem>
25 #include <QDeclarativeItem>
6 #include <qchart.h>
26 #include <qchart.h>
7
27
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
29
10 class DeclarativeChart : public QDeclarativeItem
30 class DeclarativeChart : public QDeclarativeItem
11 // TODO: for QTQUICK2: extend QQuickPainterItem instead
31 // TODO: for QTQUICK2: extend QQuickPainterItem instead
12 //class DeclarativeChart : public QQuickPaintedItem, public Chart
32 //class DeclarativeChart : public QQuickPaintedItem, public Chart
13 {
33 {
14 Q_OBJECT
34 Q_OBJECT
15 Q_ENUMS(ChartTheme)
35 Q_ENUMS(ChartTheme)
16 Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme)
36 Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme)
17
37
18 public:
38 public:
19 enum ChartTheme {
39 enum ChartTheme {
20 ThemeDefault,
40 ThemeDefault,
21 ThemeLight,
41 ThemeLight,
22 ThemeBlueCerulean,
42 ThemeBlueCerulean,
23 ThemeDark,
43 ThemeDark,
24 ThemeBrownSand,
44 ThemeBrownSand,
25 ThemeBlueNcs,
45 ThemeBlueNcs,
26 ThemeHighContrast,
46 ThemeHighContrast,
27 ThemeBlueIcy
47 ThemeBlueIcy
28 };
48 };
29 DeclarativeChart(QDeclarativeItem *parent = 0);
49 DeclarativeChart(QDeclarativeItem *parent = 0);
30 ~DeclarativeChart();
50 ~DeclarativeChart();
31
51
32 public: // From QDeclarativeItem/QGraphicsItem
52 public: // From QDeclarativeItem/QGraphicsItem
33 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
53 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
34 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
54 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
35
55
36 public:
56 public:
37 void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartTheme) theme);}
57 void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartTheme) theme);}
38 ChartTheme theme();
58 ChartTheme theme();
39
59
40 public:
60 public:
41 // Extending QChart with DeclarativeChart is not possible because QObject does not support
61 // Extending QChart with DeclarativeChart is not possible because QObject does not support
42 // multi inheritance, so we now have a QChart as a member instead
62 // multi inheritance, so we now have a QChart as a member instead
43 QChart *m_chart;
63 QChart *m_chart;
44 };
64 };
45
65
46 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
47
67
48 #endif // DECLARATIVECHART_H
68 #endif // DECLARATIVECHART_H
@@ -1,37 +1,57
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
1 #include "declarativelineseries.h"
21 #include "declarativelineseries.h"
2 #include "declarativechart.h"
22 #include "declarativechart.h"
3 #include "qchart.h"
23 #include "qchart.h"
4 #include "qlineseries.h"
24 #include "qlineseries.h"
5
25
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
27
8 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
28 DeclarativeLineSeries::DeclarativeLineSeries(QObject *parent) :
9 QLineSeries(parent)
29 QLineSeries(parent)
10 {
30 {
11 }
31 }
12
32
13 void DeclarativeLineSeries::componentComplete()
33 void DeclarativeLineSeries::componentComplete()
14 {
34 {
15 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
35 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
16
36
17 if (declarativeChart) {
37 if (declarativeChart) {
18 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
38 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
19 Q_ASSERT(chart);
39 Q_ASSERT(chart);
20 chart->addSeries(this);
40 chart->addSeries(this);
21 }
41 }
22 }
42 }
23
43
24 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
44 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeLineSeries::points()
25 {
45 {
26 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
46 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
27 }
47 }
28
48
29 void DeclarativeLineSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
49 void DeclarativeLineSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
30 DeclarativeXyPoint *element)
50 DeclarativeXyPoint *element)
31 {
51 {
32 DeclarativeXySeries::appendPoints(list, element);
52 DeclarativeXySeries::appendPoints(list, element);
33 }
53 }
34
54
35 #include "moc_declarativelineseries.cpp"
55 #include "moc_declarativelineseries.cpp"
36
56
37 QTCOMMERCIALCHART_END_NAMESPACE
57 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,30 +1,50
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
1 #ifndef DECLARATIVELINESERIES_H
21 #ifndef DECLARATIVELINESERIES_H
2 #define DECLARATIVELINESERIES_H
22 #define DECLARATIVELINESERIES_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include "qlineseries.h"
25 #include "qlineseries.h"
6 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
7 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
8
28
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
30
11 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
31 class DeclarativeLineSeries : public QLineSeries, public DeclarativeXySeries
12 {
32 {
13 Q_OBJECT
33 Q_OBJECT
14 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
15
35
16 public:
36 public:
17 explicit DeclarativeLineSeries(QObject *parent = 0);
37 explicit DeclarativeLineSeries(QObject *parent = 0);
18
38
19 public:
39 public:
20 void componentComplete();
40 void componentComplete();
21 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
22
42
23 public Q_SLOTS:
43 public Q_SLOTS:
24 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
44 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
25 DeclarativeXyPoint *element);
45 DeclarativeXyPoint *element);
26 };
46 };
27
47
28 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
29
49
30 #endif // DECLARATIVELINESERIES_H
50 #endif // DECLARATIVELINESERIES_H
@@ -1,43 +1,63
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
1 #include "declarativepieseries.h"
21 #include "declarativepieseries.h"
2 #include "declarativechart.h"
22 #include "declarativechart.h"
3 #include "qchart.h"
23 #include "qchart.h"
4
24
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
26
7 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
27 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
8 QPieSeries(parent),
28 QPieSeries(parent),
9 m_chart(0)
29 m_chart(0)
10 {
30 {
11 }
31 }
12
32
13 void DeclarativePieSeries::classBegin()
33 void DeclarativePieSeries::classBegin()
14 {
34 {
15 }
35 }
16
36
17 void DeclarativePieSeries::componentComplete()
37 void DeclarativePieSeries::componentComplete()
18 {
38 {
19 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
39 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
20 if (declarativeChart) {
40 if (declarativeChart) {
21 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
41 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
22 Q_ASSERT(chart);
42 Q_ASSERT(chart);
23 qDebug() << "parent for pie:" << chart;
43 qDebug() << "parent for pie:" << chart;
24 chart->addSeries(this);
44 chart->addSeries(this);
25 }
45 }
26 }
46 }
27
47
28 QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices()
48 QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices()
29 {
49 {
30 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice);
50 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice);
31 }
51 }
32
52
33 void DeclarativePieSeries::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
53 void DeclarativePieSeries::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
34 QPieSlice *slice)
54 QPieSlice *slice)
35 {
55 {
36 DeclarativePieSeries *series = qobject_cast<DeclarativePieSeries *>(list->object);
56 DeclarativePieSeries *series = qobject_cast<DeclarativePieSeries *>(list->object);
37 if (series)
57 if (series)
38 series->append(slice->value(), slice->label());
58 series->append(slice->value(), slice->label());
39 }
59 }
40
60
41 #include "moc_declarativepieseries.cpp"
61 #include "moc_declarativepieseries.cpp"
42
62
43 QTCOMMERCIALCHART_END_NAMESPACE
63 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,37 +1,57
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
1 #ifndef DECLARATIVEPIESERIES_H
21 #ifndef DECLARATIVEPIESERIES_H
2 #define DECLARATIVEPIESERIES_H
22 #define DECLARATIVEPIESERIES_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include "qpieslice.h"
25 #include "qpieslice.h"
6 #include "qpieseries.h"
26 #include "qpieseries.h"
7 #include <QDeclarativeItem>
27 #include <QDeclarativeItem>
8
28
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
30
11 class QChart;
31 class QChart;
12
32
13 class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus
33 class DeclarativePieSeries : public QPieSeries, public QDeclarativeParserStatus
14 {
34 {
15 Q_OBJECT
35 Q_OBJECT
16 Q_INTERFACES(QDeclarativeParserStatus)
36 Q_INTERFACES(QDeclarativeParserStatus)
17 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
37 Q_PROPERTY(QDeclarativeListProperty<QPieSlice> slices READ slices)
18
38
19 public:
39 public:
20 explicit DeclarativePieSeries(QObject *parent = 0);
40 explicit DeclarativePieSeries(QObject *parent = 0);
21 QDeclarativeListProperty<QPieSlice> slices();
41 QDeclarativeListProperty<QPieSlice> slices();
22
42
23 public: // from QDeclarativeParserStatus
43 public: // from QDeclarativeParserStatus
24 void classBegin();
44 void classBegin();
25 void componentComplete();
45 void componentComplete();
26
46
27 public Q_SLOTS:
47 public Q_SLOTS:
28 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
48 static void appendSlice(QDeclarativeListProperty<QPieSlice> *list,
29 QPieSlice *element);
49 QPieSlice *element);
30
50
31 private:
51 private:
32 QChart *m_chart;
52 QChart *m_chart;
33 };
53 };
34
54
35 QTCOMMERCIALCHART_END_NAMESPACE
55 QTCOMMERCIALCHART_END_NAMESPACE
36
56
37 #endif // DECLARATIVEPIESERIES_H
57 #endif // DECLARATIVEPIESERIES_H
@@ -1,38 +1,58
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
1 #include "declarativescatterseries.h"
21 #include "declarativescatterseries.h"
2 #include "declarativechart.h"
22 #include "declarativechart.h"
3 #include "qchart.h"
23 #include "qchart.h"
4 #include "qscatterseries.h"
24 #include "qscatterseries.h"
5
25
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
27
8 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
28 DeclarativeScatterSeries::DeclarativeScatterSeries(QObject *parent) :
9 QScatterSeries(parent)
29 QScatterSeries(parent)
10 {
30 {
11 }
31 }
12
32
13 void DeclarativeScatterSeries::componentComplete()
33 void DeclarativeScatterSeries::componentComplete()
14 {
34 {
15 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
35 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
16
36
17 if (declarativeChart) {
37 if (declarativeChart) {
18 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
38 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
19 Q_ASSERT(chart);
39 Q_ASSERT(chart);
20 qDebug() << "chart:" << chart;
40 qDebug() << "chart:" << chart;
21 chart->addSeries(this);
41 chart->addSeries(this);
22 }
42 }
23 }
43 }
24
44
25 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
45 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeScatterSeries::points()
26 {
46 {
27 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
47 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
28 }
48 }
29
49
30 void DeclarativeScatterSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
50 void DeclarativeScatterSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
31 DeclarativeXyPoint *element)
51 DeclarativeXyPoint *element)
32 {
52 {
33 DeclarativeXySeries::appendPoints(list, element);
53 DeclarativeXySeries::appendPoints(list, element);
34 }
54 }
35
55
36 #include "moc_declarativescatterseries.cpp"
56 #include "moc_declarativescatterseries.cpp"
37
57
38 QTCOMMERCIALCHART_END_NAMESPACE
58 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,30 +1,50
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
1 #ifndef DECLARATIVESCATTERSERIES_H
21 #ifndef DECLARATIVESCATTERSERIES_H
2 #define DECLARATIVESCATTERSERIES_H
22 #define DECLARATIVESCATTERSERIES_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include "qscatterseries.h"
25 #include "qscatterseries.h"
6 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
7 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
8
28
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
30
11 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
31 class DeclarativeScatterSeries : public QScatterSeries, public DeclarativeXySeries
12 {
32 {
13 Q_OBJECT
33 Q_OBJECT
14 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
15
35
16 public:
36 public:
17 explicit DeclarativeScatterSeries(QObject *parent = 0);
37 explicit DeclarativeScatterSeries(QObject *parent = 0);
18
38
19 public:
39 public:
20 void componentComplete();
40 void componentComplete();
21 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
22
42
23 public Q_SLOTS:
43 public Q_SLOTS:
24 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
44 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
25 DeclarativeXyPoint *element);
45 DeclarativeXyPoint *element);
26 };
46 };
27
47
28 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
29
49
30 #endif // DECLARATIVESCATTERSERIES_H
50 #endif // DECLARATIVESCATTERSERIES_H
@@ -1,36 +1,56
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
1 #include "declarativesplineseries.h"
21 #include "declarativesplineseries.h"
2 #include "declarativechart.h"
22 #include "declarativechart.h"
3 #include "qchart.h"
23 #include "qchart.h"
4
24
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
26
7 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
27 DeclarativeSplineSeries::DeclarativeSplineSeries(QObject *parent) :
8 QSplineSeries(parent)
28 QSplineSeries(parent)
9 {
29 {
10 }
30 }
11
31
12 void DeclarativeSplineSeries::componentComplete()
32 void DeclarativeSplineSeries::componentComplete()
13 {
33 {
14 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
34 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
15
35
16 if (declarativeChart) {
36 if (declarativeChart) {
17 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
37 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
18 Q_ASSERT(chart);
38 Q_ASSERT(chart);
19 chart->addSeries(this);
39 chart->addSeries(this);
20 }
40 }
21 }
41 }
22
42
23 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
43 QDeclarativeListProperty<DeclarativeXyPoint> DeclarativeSplineSeries::points()
24 {
44 {
25 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
45 return QDeclarativeListProperty<DeclarativeXyPoint>(this, 0, &DeclarativeXySeries::appendPoints);
26 }
46 }
27
47
28 void DeclarativeSplineSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
48 void DeclarativeSplineSeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
29 DeclarativeXyPoint *element)
49 DeclarativeXyPoint *element)
30 {
50 {
31 DeclarativeXySeries::appendPoints(list, element);
51 DeclarativeXySeries::appendPoints(list, element);
32 }
52 }
33
53
34 #include "moc_declarativesplineseries.cpp"
54 #include "moc_declarativesplineseries.cpp"
35
55
36 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,30 +1,50
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
1 #ifndef DECLARATIVESPLINESERIES_H
21 #ifndef DECLARATIVESPLINESERIES_H
2 #define DECLARATIVESPLINESERIES_H
22 #define DECLARATIVESPLINESERIES_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include "qsplineseries.h"
25 #include "qsplineseries.h"
6 #include "declarativexyseries.h"
26 #include "declarativexyseries.h"
7 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
8
28
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
30
11 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
31 class DeclarativeSplineSeries : public QSplineSeries, public DeclarativeXySeries
12 {
32 {
13 Q_OBJECT
33 Q_OBJECT
14 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
34 Q_PROPERTY(QDeclarativeListProperty<DeclarativeXyPoint> points READ points)
15
35
16 public:
36 public:
17 explicit DeclarativeSplineSeries(QObject *parent = 0);
37 explicit DeclarativeSplineSeries(QObject *parent = 0);
18
38
19 public:
39 public:
20 virtual void componentComplete();
40 virtual void componentComplete();
21 QDeclarativeListProperty<DeclarativeXyPoint> points();
41 QDeclarativeListProperty<DeclarativeXyPoint> points();
22
42
23 public Q_SLOTS:
43 public Q_SLOTS:
24 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
44 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
25 DeclarativeXyPoint *element);
45 DeclarativeXyPoint *element);
26 };
46 };
27
47
28 QTCOMMERCIALCHART_END_NAMESPACE
48 QTCOMMERCIALCHART_END_NAMESPACE
29
49
30 #endif // DECLARATIVESPLINESERIES_H
50 #endif // DECLARATIVESPLINESERIES_H
@@ -1,14 +1,34
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
1 #include "declarativexypoint.h"
21 #include "declarativexypoint.h"
2
22
3 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
4
24
5 DeclarativeXyPoint::DeclarativeXyPoint(QObject *parent) :
25 DeclarativeXyPoint::DeclarativeXyPoint(QObject *parent) :
6 QObject(parent)
26 QObject(parent)
7 {
27 {
8 setX(0.0);
28 setX(0.0);
9 setY(0.0);
29 setY(0.0);
10 }
30 }
11
31
12 #include "moc_declarativexypoint.cpp"
32 #include "moc_declarativexypoint.cpp"
13
33
14 QTCOMMERCIALCHART_END_NAMESPACE
34 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,22 +1,42
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
1 #ifndef DECLARATIVE_XY_POINT_H
21 #ifndef DECLARATIVE_XY_POINT_H
2 #define DECLARATIVE_XY_POINT_H
22 #define DECLARATIVE_XY_POINT_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include <QObject>
25 #include <QObject>
6 #include <QPointF>
26 #include <QPointF>
7
27
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
29
10 class DeclarativeXyPoint : public QObject, public QPointF
30 class DeclarativeXyPoint : public QObject, public QPointF
11 {
31 {
12 Q_OBJECT
32 Q_OBJECT
13 Q_PROPERTY(qreal x READ x WRITE setX /*NOTIFY dataXChanged*/)
33 Q_PROPERTY(qreal x READ x WRITE setX /*NOTIFY dataXChanged*/)
14 Q_PROPERTY(qreal y READ y WRITE setY /*NOTIFY dataYChanged*/)
34 Q_PROPERTY(qreal y READ y WRITE setY /*NOTIFY dataYChanged*/)
15
35
16 public:
36 public:
17 explicit DeclarativeXyPoint(QObject *parent = 0);
37 explicit DeclarativeXyPoint(QObject *parent = 0);
18 };
38 };
19
39
20 QTCOMMERCIALCHART_END_NAMESPACE
40 QTCOMMERCIALCHART_END_NAMESPACE
21
41
22 #endif // DECLARATIVE_XY_POINT_H
42 #endif // DECLARATIVE_XY_POINT_H
@@ -1,27 +1,47
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
1 //#include "DeclarativeXySeries.h"
21 //#include "DeclarativeXySeries.h"
2 #include "declarativexyseries.h"
22 #include "declarativexyseries.h"
3 #include "qxyseries.h"
23 #include "qxyseries.h"
4
24
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
26
7 DeclarativeXySeries::DeclarativeXySeries()
27 DeclarativeXySeries::DeclarativeXySeries()
8 {
28 {
9 }
29 }
10
30
11 DeclarativeXySeries::~DeclarativeXySeries()
31 DeclarativeXySeries::~DeclarativeXySeries()
12 {
32 {
13 }
33 }
14
34
15 void DeclarativeXySeries::classBegin()
35 void DeclarativeXySeries::classBegin()
16 {
36 {
17 }
37 }
18
38
19 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
39 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
20 DeclarativeXyPoint *element)
40 DeclarativeXyPoint *element)
21 {
41 {
22 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
42 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
23 if (series)
43 if (series)
24 series->append(QPointF(element->x(), element->y()));
44 series->append(QPointF(element->x(), element->y()));
25 }
45 }
26
46
27 QTCOMMERCIALCHART_END_NAMESPACE
47 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,35 +1,55
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
1 #ifndef DECLARATIVE_XY_SERIES_H
21 #ifndef DECLARATIVE_XY_SERIES_H
2 #define DECLARATIVE_XY_SERIES_H
22 #define DECLARATIVE_XY_SERIES_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include "declarativexypoint.h"
25 #include "declarativexypoint.h"
6 #include <QDeclarativeParserStatus>
26 #include <QDeclarativeParserStatus>
7 #include <QDeclarativeListProperty>
27 #include <QDeclarativeListProperty>
8
28
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
30
11 class QChart;
31 class QChart;
12
32
13 class DeclarativeXySeries : public QDeclarativeParserStatus
33 class DeclarativeXySeries : public QDeclarativeParserStatus
14 {
34 {
15 Q_INTERFACES(QDeclarativeParserStatus)
35 Q_INTERFACES(QDeclarativeParserStatus)
16
36
17 public:
37 public:
18 explicit DeclarativeXySeries();
38 explicit DeclarativeXySeries();
19 ~DeclarativeXySeries();
39 ~DeclarativeXySeries();
20
40
21 public: // from QDeclarativeParserStatus
41 public: // from QDeclarativeParserStatus
22 virtual void classBegin();
42 virtual void classBegin();
23 virtual void componentComplete() = 0;
43 virtual void componentComplete() = 0;
24
44
25 public:
45 public:
26 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
46 virtual QDeclarativeListProperty<DeclarativeXyPoint> points() = 0;
27
47
28 public Q_SLOTS:
48 public Q_SLOTS:
29 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
49 static void appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
30 DeclarativeXyPoint *element);
50 DeclarativeXyPoint *element);
31 };
51 };
32
52
33 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
34
54
35 #endif // DECLARATIVE_XY_SERIES_H
55 #endif // DECLARATIVE_XY_SERIES_H
@@ -1,38 +1,58
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
1 #include <QtDeclarative/qdeclarativeextensionplugin.h>
21 #include <QtDeclarative/qdeclarativeextensionplugin.h>
2 #include <QtDeclarative/qdeclarative.h>
22 #include <QtDeclarative/qdeclarative.h>
3 #include "declarativechart.h"
23 #include "declarativechart.h"
4 #include "declarativexypoint.h"
24 #include "declarativexypoint.h"
5 #include "declarativelineseries.h"
25 #include "declarativelineseries.h"
6 #include "declarativesplineseries.h"
26 #include "declarativesplineseries.h"
7 #include "declarativescatterseries.h"
27 #include "declarativescatterseries.h"
8 #include "declarativebarseries.h"
28 #include "declarativebarseries.h"
9 #include "declarativepieseries.h"
29 #include "declarativepieseries.h"
10
30
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
32
13 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
33 class ChartQmlPlugin : public QDeclarativeExtensionPlugin
14 {
34 {
15 Q_OBJECT
35 Q_OBJECT
16 public:
36 public:
17 virtual void registerTypes(const char *uri)
37 virtual void registerTypes(const char *uri)
18 {
38 {
19 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
39 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
20
40
21 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart");
41 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "Chart");
22 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
42 qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint");
23 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
43 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
24 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
44 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
25 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
45 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
26 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
46 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
27 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
47 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
28 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
48 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
29 }
49 }
30 };
50 };
31
51
32 #include "plugin.moc"
52 #include "plugin.moc"
33
53
34 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
35
55
36 QTCOMMERCIALCHART_USE_NAMESPACE
56 QTCOMMERCIALCHART_USE_NAMESPACE
37
57
38 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
58 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
@@ -1,29 +1,49
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
1 import QtQuick 2.0
21 import QtQuick 2.0
2
22
3 Canvas {
23 Canvas {
4 id: canvas
24 id: canvas
5 width: 200
25 width: 200
6 height: 200
26 height: 200
7 smooth:true
27 smooth:true
8 renderTarget:Canvas.Image
28 renderTarget:Canvas.Image
9 renderInThread:false
29 renderInThread:false
10
30
11 onWidthChanged: requestPaint()
31 onWidthChanged: requestPaint()
12 onHeightChanged: requestPaint()
32 onHeightChanged: requestPaint()
13
33
14 onPaint: {
34 onPaint: {
15 var ctx = canvas.getContext('2d')
35 var ctx = canvas.getContext('2d')
16 ctx.reset()
36 ctx.reset()
17 ctx.clearRect(0, 0, canvas.width, canvas.height)
37 ctx.clearRect(0, 0, canvas.width, canvas.height)
18 ctx.strokeStyle = "red"
38 ctx.strokeStyle = "red"
19 ctx.lineWidth = 1
39 ctx.lineWidth = 1
20 ctx.moveTo(10, 10)
40 ctx.moveTo(10, 10)
21 ctx.lineTo(10, canvas.height-10)
41 ctx.lineTo(10, canvas.height-10)
22 ctx.lineTo(canvas.width-10, canvas.height-10)
42 ctx.lineTo(canvas.width-10, canvas.height-10)
23 ctx.text("Axis x", canvas.width / 2, canvas.height)
43 ctx.text("Axis x", canvas.width / 2, canvas.height)
24 ctx.text("Insert chart here", canvas.width / 2, canvas.height / 2)
44 ctx.text("Insert chart here", canvas.width / 2, canvas.height / 2)
25 ctx.stroke();
45 ctx.stroke();
26 }
46 }
27 }
47 }
28
48
29
49
@@ -1,48 +1,68
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
1 #include "separator_p.h"
21 #include "separator_p.h"
2 #include <QDebug>
22 #include <QDebug>
3 #include <QPainter>
23 #include <QPainter>
4
24
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
26
7 Separator::Separator(QGraphicsItem *parent)
27 Separator::Separator(QGraphicsItem *parent)
8 : QGraphicsItem(parent)
28 : QGraphicsItem(parent)
9 {
29 {
10 }
30 }
11
31
12 void Separator::setPos(qreal x, qreal y)
32 void Separator::setPos(qreal x, qreal y)
13 {
33 {
14 mXpos = x;
34 mXpos = x;
15 mYpos = y;
35 mYpos = y;
16 }
36 }
17
37
18 void Separator::setColor(QColor color)
38 void Separator::setColor(QColor color)
19 {
39 {
20 mColor = color;
40 mColor = color;
21 }
41 }
22
42
23 void Separator::setSize(const QSizeF &size)
43 void Separator::setSize(const QSizeF &size)
24 {
44 {
25 mWidth = size.width();
45 mWidth = size.width();
26 mHeight = size.height();
46 mHeight = size.height();
27 }
47 }
28
48
29 void Separator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
49 void Separator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
30 {
50 {
31 Q_UNUSED(option)
51 Q_UNUSED(option)
32 Q_UNUSED(widget)
52 Q_UNUSED(widget)
33
53
34 if (isVisible()) {
54 if (isVisible()) {
35 QPen pen(mColor);
55 QPen pen(mColor);
36 painter->setPen(pen);
56 painter->setPen(pen);
37 painter->drawLine(mXpos,mYpos,mXpos,mHeight);
57 painter->drawLine(mXpos,mYpos,mXpos,mHeight);
38 }
58 }
39 }
59 }
40
60
41 QRectF Separator::boundingRect() const
61 QRectF Separator::boundingRect() const
42 {
62 {
43 QRectF r(mXpos,mYpos,mWidth,mHeight);
63 QRectF r(mXpos,mYpos,mWidth,mHeight);
44 return r;
64 return r;
45 }
65 }
46
66
47
67
48 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,35 +1,55
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
1 #ifndef SEPARATOR_H
21 #ifndef SEPARATOR_H
2 #define SEPARATOR_H
22 #define SEPARATOR_H
3
23
4 #include "chartitem_p.h"
24 #include "chartitem_p.h"
5
25
6 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
7
27
8 class Separator : public QGraphicsItem
28 class Separator : public QGraphicsItem
9 {
29 {
10 public:
30 public:
11 Separator(QGraphicsItem *parent = 0);
31 Separator(QGraphicsItem *parent = 0);
12
32
13 void setPos(qreal x, qreal y);
33 void setPos(qreal x, qreal y);
14 void setColor(QColor color);
34 void setColor(QColor color);
15
35
16 // From ChartItem
36 // From ChartItem
17 void setSize(const QSizeF &size);
37 void setSize(const QSizeF &size);
18
38
19 // From QGraphicsItem
39 // From QGraphicsItem
20 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
40 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
21 QRectF boundingRect() const;
41 QRectF boundingRect() const;
22
42
23 private:
43 private:
24
44
25 QColor mColor;
45 QColor mColor;
26 qreal mXpos;
46 qreal mXpos;
27 qreal mYpos;
47 qreal mYpos;
28 qreal mHeight;
48 qreal mHeight;
29 qreal mWidth;
49 qreal mWidth;
30
50
31 };
51 };
32
52
33 QTCOMMERCIALCHART_END_NAMESPACE
53 QTCOMMERCIALCHART_END_NAMESPACE
34
54
35 #endif // SEPARATOR_H
55 #endif // SEPARATOR_H
@@ -1,168 +1,188
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
1 #include "dataseriedialog.h"
21 #include "dataseriedialog.h"
2 #include <QDialogButtonBox>
22 #include <QDialogButtonBox>
3 #include <QGridLayout>
23 #include <QGridLayout>
4 #include <QCheckBox>
24 #include <QCheckBox>
5 #include <QPushButton>
25 #include <QPushButton>
6 #include <QGroupBox>
26 #include <QGroupBox>
7 #include <QRadioButton>
27 #include <QRadioButton>
8 #include <QLabel>
28 #include <QLabel>
9 #include <QDebug>
29 #include <QDebug>
10
30
11 DataSerieDialog::DataSerieDialog(QWidget *parent) :
31 DataSerieDialog::DataSerieDialog(QWidget *parent) :
12 QDialog(parent)
32 QDialog(parent)
13 {
33 {
14 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
34 QDialogButtonBox *addSeriesBox = new QDialogButtonBox(Qt::Horizontal);
15 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
35 QPushButton *b = addSeriesBox->addButton(QDialogButtonBox::Ok);
16 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
36 connect(b, SIGNAL(clicked()), this, SLOT(accept()));
17 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
37 b = addSeriesBox->addButton(QDialogButtonBox::Cancel);
18 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
38 connect(b, SIGNAL(clicked()), this, SLOT(reject()));
19
39
20 QGridLayout *grid = new QGridLayout();
40 QGridLayout *grid = new QGridLayout();
21
41
22 m_seriesTypeSelector = seriesTypeSelector();
42 m_seriesTypeSelector = seriesTypeSelector();
23 m_columnCountSelector = columnCountSelector();
43 m_columnCountSelector = columnCountSelector();
24 m_rowCountSelector = rowCountSelector();
44 m_rowCountSelector = rowCountSelector();
25 m_dataCharacteristicsSelector = dataCharacteristicsSelector();
45 m_dataCharacteristicsSelector = dataCharacteristicsSelector();
26
46
27 grid->addWidget(m_seriesTypeSelector, 0, 0);
47 grid->addWidget(m_seriesTypeSelector, 0, 0);
28 grid->addWidget(m_columnCountSelector, 0, 1);
48 grid->addWidget(m_columnCountSelector, 0, 1);
29 grid->addWidget(m_rowCountSelector, 1, 1);
49 grid->addWidget(m_rowCountSelector, 1, 1);
30 grid->addWidget(m_dataCharacteristicsSelector, 1, 0);
50 grid->addWidget(m_dataCharacteristicsSelector, 1, 0);
31 m_labelsSelector = new QCheckBox("Labels defined");
51 m_labelsSelector = new QCheckBox("Labels defined");
32 m_labelsSelector->setChecked(true);
52 m_labelsSelector->setChecked(true);
33 grid->addWidget(m_labelsSelector, 2, 0);
53 grid->addWidget(m_labelsSelector, 2, 0);
34 grid->addWidget(addSeriesBox, 3, 1);
54 grid->addWidget(addSeriesBox, 3, 1);
35
55
36 setLayout(grid);
56 setLayout(grid);
37 }
57 }
38
58
39 QGroupBox *DataSerieDialog::seriesTypeSelector()
59 QGroupBox *DataSerieDialog::seriesTypeSelector()
40 {
60 {
41 QVBoxLayout *layout = new QVBoxLayout();
61 QVBoxLayout *layout = new QVBoxLayout();
42
62
43 QRadioButton *line = new QRadioButton("Line");
63 QRadioButton *line = new QRadioButton("Line");
44 line->setChecked(true);
64 line->setChecked(true);
45 layout->addWidget(line);
65 layout->addWidget(line);
46 layout->addWidget(new QRadioButton("Area"));
66 layout->addWidget(new QRadioButton("Area"));
47 layout->addWidget(new QRadioButton("Pie"));
67 layout->addWidget(new QRadioButton("Pie"));
48 layout->addWidget(new QRadioButton("Bar"));
68 layout->addWidget(new QRadioButton("Bar"));
49 layout->addWidget(new QRadioButton("Stacked bar"));
69 layout->addWidget(new QRadioButton("Stacked bar"));
50 layout->addWidget(new QRadioButton("Percent bar"));
70 layout->addWidget(new QRadioButton("Percent bar"));
51 layout->addWidget(new QRadioButton("Scatter"));
71 layout->addWidget(new QRadioButton("Scatter"));
52 layout->addWidget(new QRadioButton("Spline"));
72 layout->addWidget(new QRadioButton("Spline"));
53
73
54 QGroupBox *groupBox = new QGroupBox("Series type");
74 QGroupBox *groupBox = new QGroupBox("Series type");
55 groupBox->setLayout(layout);
75 groupBox->setLayout(layout);
56 selectRadio(groupBox, 0);
76 selectRadio(groupBox, 0);
57
77
58 return groupBox;
78 return groupBox;
59 }
79 }
60
80
61 QGroupBox *DataSerieDialog::columnCountSelector()
81 QGroupBox *DataSerieDialog::columnCountSelector()
62 {
82 {
63 QVBoxLayout *layout = new QVBoxLayout();
83 QVBoxLayout *layout = new QVBoxLayout();
64
84
65 QRadioButton *radio = new QRadioButton("1");
85 QRadioButton *radio = new QRadioButton("1");
66 radio->setChecked(true);
86 radio->setChecked(true);
67 layout->addWidget(radio);
87 layout->addWidget(radio);
68 layout->addWidget(new QRadioButton("2"));
88 layout->addWidget(new QRadioButton("2"));
69 layout->addWidget(new QRadioButton("3"));
89 layout->addWidget(new QRadioButton("3"));
70 layout->addWidget(new QRadioButton("4"));
90 layout->addWidget(new QRadioButton("4"));
71 layout->addWidget(new QRadioButton("5"));
91 layout->addWidget(new QRadioButton("5"));
72 layout->addWidget(new QRadioButton("8"));
92 layout->addWidget(new QRadioButton("8"));
73 layout->addWidget(new QRadioButton("10"));
93 layout->addWidget(new QRadioButton("10"));
74 layout->addWidget(new QRadioButton("100"));
94 layout->addWidget(new QRadioButton("100"));
75
95
76 QGroupBox *groupBox = new QGroupBox("Column count");
96 QGroupBox *groupBox = new QGroupBox("Column count");
77 groupBox->setLayout(layout);
97 groupBox->setLayout(layout);
78 selectRadio(groupBox, 0);
98 selectRadio(groupBox, 0);
79
99
80 return groupBox;
100 return groupBox;
81 }
101 }
82
102
83 QGroupBox *DataSerieDialog::rowCountSelector()
103 QGroupBox *DataSerieDialog::rowCountSelector()
84 {
104 {
85 QVBoxLayout *layout = new QVBoxLayout();
105 QVBoxLayout *layout = new QVBoxLayout();
86
106
87 layout->addWidget(new QRadioButton("1"));
107 layout->addWidget(new QRadioButton("1"));
88 QRadioButton *radio = new QRadioButton("10");
108 QRadioButton *radio = new QRadioButton("10");
89 radio->setChecked(true);
109 radio->setChecked(true);
90 layout->addWidget(radio);
110 layout->addWidget(radio);
91 layout->addWidget(new QRadioButton("50"));
111 layout->addWidget(new QRadioButton("50"));
92 layout->addWidget(new QRadioButton("100"));
112 layout->addWidget(new QRadioButton("100"));
93 layout->addWidget(new QRadioButton("10000"));
113 layout->addWidget(new QRadioButton("10000"));
94 layout->addWidget(new QRadioButton("100000"));
114 layout->addWidget(new QRadioButton("100000"));
95 layout->addWidget(new QRadioButton("1000000"));
115 layout->addWidget(new QRadioButton("1000000"));
96
116
97 QGroupBox *groupBox = new QGroupBox("Row count");
117 QGroupBox *groupBox = new QGroupBox("Row count");
98 groupBox->setLayout(layout);
118 groupBox->setLayout(layout);
99 selectRadio(groupBox, 0);
119 selectRadio(groupBox, 0);
100
120
101 return groupBox;
121 return groupBox;
102 }
122 }
103
123
104 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
124 QGroupBox *DataSerieDialog::dataCharacteristicsSelector()
105 {
125 {
106 QVBoxLayout *layout = new QVBoxLayout();
126 QVBoxLayout *layout = new QVBoxLayout();
107
127
108 layout->addWidget(new QRadioButton("Linear"));
128 layout->addWidget(new QRadioButton("Linear"));
109 layout->addWidget(new QRadioButton("Constant"));
129 layout->addWidget(new QRadioButton("Constant"));
110 layout->addWidget(new QRadioButton("Random"));
130 layout->addWidget(new QRadioButton("Random"));
111 layout->addWidget(new QRadioButton("Sin"));
131 layout->addWidget(new QRadioButton("Sin"));
112 layout->addWidget(new QRadioButton("Sin + random"));
132 layout->addWidget(new QRadioButton("Sin + random"));
113
133
114 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
134 QGroupBox *groupBox = new QGroupBox("Data Characteristics");
115 groupBox->setLayout(layout);
135 groupBox->setLayout(layout);
116 selectRadio(groupBox, 0);
136 selectRadio(groupBox, 0);
117
137
118 return groupBox;
138 return groupBox;
119 }
139 }
120
140
121 void DataSerieDialog::accept()
141 void DataSerieDialog::accept()
122 {
142 {
123 accepted(radioSelection(m_seriesTypeSelector),
143 accepted(radioSelection(m_seriesTypeSelector),
124 radioSelection(m_columnCountSelector).toInt(),
144 radioSelection(m_columnCountSelector).toInt(),
125 radioSelection(m_rowCountSelector).toInt(),
145 radioSelection(m_rowCountSelector).toInt(),
126 radioSelection(m_dataCharacteristicsSelector),
146 radioSelection(m_dataCharacteristicsSelector),
127 m_labelsSelector->isChecked());
147 m_labelsSelector->isChecked());
128 QDialog::accept();
148 QDialog::accept();
129 }
149 }
130
150
131 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
151 void DataSerieDialog::selectRadio(QGroupBox *groupBox, int defaultSelection)
132 {
152 {
133 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
153 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
134 Q_ASSERT(layout);
154 Q_ASSERT(layout);
135 Q_ASSERT(layout->count());
155 Q_ASSERT(layout->count());
136
156
137 QLayoutItem *item = 0;
157 QLayoutItem *item = 0;
138 if (defaultSelection == -1) {
158 if (defaultSelection == -1) {
139 item = layout->itemAt(0);
159 item = layout->itemAt(0);
140 } else if (layout->count() > defaultSelection) {
160 } else if (layout->count() > defaultSelection) {
141 item = layout->itemAt(defaultSelection);
161 item = layout->itemAt(defaultSelection);
142 }
162 }
143 Q_ASSERT(item);
163 Q_ASSERT(item);
144 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
164 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
145 Q_ASSERT(radio);
165 Q_ASSERT(radio);
146 radio->setChecked(true);
166 radio->setChecked(true);
147 }
167 }
148
168
149 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
169 QString DataSerieDialog::radioSelection(QGroupBox *groupBox)
150 {
170 {
151 QString selection;
171 QString selection;
152 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
172 QVBoxLayout *layout = qobject_cast<QVBoxLayout *>(groupBox->layout());
153 Q_ASSERT(layout);
173 Q_ASSERT(layout);
154
174
155 for (int i(0); i < layout->count(); i++) {
175 for (int i(0); i < layout->count(); i++) {
156 QLayoutItem *item = layout->itemAt(i);
176 QLayoutItem *item = layout->itemAt(i);
157 Q_ASSERT(item);
177 Q_ASSERT(item);
158 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
178 QRadioButton *radio = qobject_cast<QRadioButton *>(item->widget());
159 Q_ASSERT(radio);
179 Q_ASSERT(radio);
160 if (radio->isChecked()) {
180 if (radio->isChecked()) {
161 selection = radio->text();
181 selection = radio->text();
162 break;
182 break;
163 }
183 }
164 }
184 }
165
185
166 qDebug() << "radioSelection: " << selection;
186 qDebug() << "radioSelection: " << selection;
167 return selection;
187 return selection;
168 }
188 }
@@ -1,35 +1,55
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
1 #ifndef DATASERIEDIALOG_H
21 #ifndef DATASERIEDIALOG_H
2 #define DATASERIEDIALOG_H
22 #define DATASERIEDIALOG_H
3
23
4 #include <QDialog>
24 #include <QDialog>
5
25
6 class QGroupBox;
26 class QGroupBox;
7 class QCheckBox;
27 class QCheckBox;
8
28
9 class DataSerieDialog : public QDialog
29 class DataSerieDialog : public QDialog
10 {
30 {
11 Q_OBJECT
31 Q_OBJECT
12 public:
32 public:
13 explicit DataSerieDialog(QWidget *parent = 0);
33 explicit DataSerieDialog(QWidget *parent = 0);
14
34
15 signals:
35 signals:
16 void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined);
36 void accepted(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsDefined);
17
37
18 public slots:
38 public slots:
19 void accept();
39 void accept();
20
40
21 private:
41 private:
22 QGroupBox *seriesTypeSelector();
42 QGroupBox *seriesTypeSelector();
23 QGroupBox *columnCountSelector();
43 QGroupBox *columnCountSelector();
24 QGroupBox *rowCountSelector();
44 QGroupBox *rowCountSelector();
25 QGroupBox *dataCharacteristicsSelector();
45 QGroupBox *dataCharacteristicsSelector();
26 void selectRadio(QGroupBox *groupBox, int defaultSelection);
46 void selectRadio(QGroupBox *groupBox, int defaultSelection);
27 QString radioSelection(QGroupBox *groupBox);
47 QString radioSelection(QGroupBox *groupBox);
28 QGroupBox *m_seriesTypeSelector;
48 QGroupBox *m_seriesTypeSelector;
29 QGroupBox *m_columnCountSelector;
49 QGroupBox *m_columnCountSelector;
30 QGroupBox *m_rowCountSelector;
50 QGroupBox *m_rowCountSelector;
31 QCheckBox *m_labelsSelector;
51 QCheckBox *m_labelsSelector;
32 QGroupBox *m_dataCharacteristicsSelector;
52 QGroupBox *m_dataCharacteristicsSelector;
33 };
53 };
34
54
35 #endif // DATASERIEDIALOG_H
55 #endif // DATASERIEDIALOG_H
@@ -1,18 +1,38
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
1 #include <QtCore/QtGlobal>
21 #include <QtCore/QtGlobal>
2 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
22 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
3 #include <QApplication>
23 #include <QApplication>
4 #else
24 #else
5 #include <QtWidgets/QApplication>
25 #include <QtWidgets/QApplication>
6 #endif
26 #endif
7 #include "mainwidget.h"
27 #include "mainwidget.h"
8
28
9 int main(int argc, char *argv[])
29 int main(int argc, char *argv[])
10 {
30 {
11 QApplication a(argc, argv);
31 QApplication a(argc, argv);
12
32
13 MainWidget w;
33 MainWidget w;
14 w.resize(1000,600);
34 w.resize(1000,600);
15 w.show();
35 w.show();
16
36
17 return a.exec();
37 return a.exec();
18 }
38 }
@@ -1,328 +1,348
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
1 #include "mainwidget.h"
21 #include "mainwidget.h"
2 #include "dataseriedialog.h"
22 #include "dataseriedialog.h"
3 #include "qchartview.h"
23 #include "qchartview.h"
4 #include "qpieseries.h"
24 #include "qpieseries.h"
5 #include "qscatterseries.h"
25 #include "qscatterseries.h"
6 #include "qlineseries.h"
26 #include "qlineseries.h"
7 #include <qareaseries.h>
27 #include <qareaseries.h>
8 #include <qsplineseries.h>
28 #include <qsplineseries.h>
9 #include <qbarset.h>
29 #include <qbarset.h>
10 #include <qbarseries.h>
30 #include <qbarseries.h>
11 #include <qstackedbarseries.h>
31 #include <qstackedbarseries.h>
12 #include <qpercentbarseries.h>
32 #include <qpercentbarseries.h>
13 #include <QPushButton>
33 #include <QPushButton>
14 #include <QComboBox>
34 #include <QComboBox>
15 #include <QSpinBox>
35 #include <QSpinBox>
16 #include <QCheckBox>
36 #include <QCheckBox>
17 #include <QGridLayout>
37 #include <QGridLayout>
18 #include <QHBoxLayout>
38 #include <QHBoxLayout>
19 #include <QLabel>
39 #include <QLabel>
20 #include <QSpacerItem>
40 #include <QSpacerItem>
21 #include <QMessageBox>
41 #include <QMessageBox>
22 #include <cmath>
42 #include <cmath>
23 #include <QDebug>
43 #include <QDebug>
24 #include <QStandardItemModel>
44 #include <QStandardItemModel>
25
45
26
46
27 QTCOMMERCIALCHART_USE_NAMESPACE
47 QTCOMMERCIALCHART_USE_NAMESPACE
28
48
29 MainWidget::MainWidget(QWidget *parent) :
49 MainWidget::MainWidget(QWidget *parent) :
30 QWidget(parent),
50 QWidget(parent),
31 m_addSerieDialog(0),
51 m_addSerieDialog(0),
32 m_chart(0)
52 m_chart(0)
33 {
53 {
34 m_chart = new QChart();
54 m_chart = new QChart();
35
55
36 // Grid layout for the controls for configuring the chart widget
56 // Grid layout for the controls for configuring the chart widget
37 QGridLayout *grid = new QGridLayout();
57 QGridLayout *grid = new QGridLayout();
38 QPushButton *addSeriesButton = new QPushButton("Add series");
58 QPushButton *addSeriesButton = new QPushButton("Add series");
39 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
59 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
40 grid->addWidget(addSeriesButton, 0, 1);
60 grid->addWidget(addSeriesButton, 0, 1);
41 initBackroundCombo(grid);
61 initBackroundCombo(grid);
42 initScaleControls(grid);
62 initScaleControls(grid);
43 initThemeCombo(grid);
63 initThemeCombo(grid);
44 initCheckboxes(grid);
64 initCheckboxes(grid);
45
65
46 // add row with empty label to make all the other rows static
66 // add row with empty label to make all the other rows static
47 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
67 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
48 grid->setRowStretch(grid->rowCount() - 1, 1);
68 grid->setRowStretch(grid->rowCount() - 1, 1);
49
69
50 // Create chart view with the chart
70 // Create chart view with the chart
51 m_chartView = new QChartView(m_chart, this);
71 m_chartView = new QChartView(m_chart, this);
52 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
72 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
53
73
54 // Another grid layout as a main layout
74 // Another grid layout as a main layout
55 QGridLayout *mainLayout = new QGridLayout();
75 QGridLayout *mainLayout = new QGridLayout();
56 mainLayout->addLayout(grid, 0, 0);
76 mainLayout->addLayout(grid, 0, 0);
57 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
77 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
58 setLayout(mainLayout);
78 setLayout(mainLayout);
59 }
79 }
60
80
61 // Combo box for selecting the chart's background
81 // Combo box for selecting the chart's background
62 void MainWidget::initBackroundCombo(QGridLayout *grid)
82 void MainWidget::initBackroundCombo(QGridLayout *grid)
63 {
83 {
64 QComboBox *backgroundCombo = new QComboBox(this);
84 QComboBox *backgroundCombo = new QComboBox(this);
65 backgroundCombo->addItem("Color");
85 backgroundCombo->addItem("Color");
66 backgroundCombo->addItem("Gradient");
86 backgroundCombo->addItem("Gradient");
67 backgroundCombo->addItem("Image");
87 backgroundCombo->addItem("Image");
68 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
88 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
69 this, SLOT(backgroundChanged(int)));
89 this, SLOT(backgroundChanged(int)));
70
90
71 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
91 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
72 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
92 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
73 }
93 }
74
94
75 // Scale related controls (auto-scale vs. manual min-max values)
95 // Scale related controls (auto-scale vs. manual min-max values)
76 void MainWidget::initScaleControls(QGridLayout *grid)
96 void MainWidget::initScaleControls(QGridLayout *grid)
77 {
97 {
78 m_autoScaleCheck = new QCheckBox("Automatic scaling");
98 m_autoScaleCheck = new QCheckBox("Automatic scaling");
79 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
99 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
80 // Allow setting also non-sense values (like -2147483648 and 2147483647)
100 // Allow setting also non-sense values (like -2147483648 and 2147483647)
81 m_xMinSpin = new QSpinBox();
101 m_xMinSpin = new QSpinBox();
82 m_xMinSpin->setMinimum(INT_MIN);
102 m_xMinSpin->setMinimum(INT_MIN);
83 m_xMinSpin->setMaximum(INT_MAX);
103 m_xMinSpin->setMaximum(INT_MAX);
84 m_xMinSpin->setValue(0);
104 m_xMinSpin->setValue(0);
85 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
105 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
86 m_xMaxSpin = new QSpinBox();
106 m_xMaxSpin = new QSpinBox();
87 m_xMaxSpin->setMinimum(INT_MIN);
107 m_xMaxSpin->setMinimum(INT_MIN);
88 m_xMaxSpin->setMaximum(INT_MAX);
108 m_xMaxSpin->setMaximum(INT_MAX);
89 m_xMaxSpin->setValue(10);
109 m_xMaxSpin->setValue(10);
90 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
110 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
91 m_yMinSpin = new QSpinBox();
111 m_yMinSpin = new QSpinBox();
92 m_yMinSpin->setMinimum(INT_MIN);
112 m_yMinSpin->setMinimum(INT_MIN);
93 m_yMinSpin->setMaximum(INT_MAX);
113 m_yMinSpin->setMaximum(INT_MAX);
94 m_yMinSpin->setValue(0);
114 m_yMinSpin->setValue(0);
95 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
115 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
96 m_yMaxSpin = new QSpinBox();
116 m_yMaxSpin = new QSpinBox();
97 m_yMaxSpin->setMinimum(INT_MIN);
117 m_yMaxSpin->setMinimum(INT_MIN);
98 m_yMaxSpin->setMaximum(INT_MAX);
118 m_yMaxSpin->setMaximum(INT_MAX);
99 m_yMaxSpin->setValue(10);
119 m_yMaxSpin->setValue(10);
100 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
120 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
101
121
102 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
122 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
103 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
123 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
104 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
124 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
105 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
125 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
106 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
126 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
107 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
127 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
108 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
128 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
109 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
129 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
110 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
130 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
111
131
112 m_autoScaleCheck->setChecked(true);
132 m_autoScaleCheck->setChecked(true);
113 }
133 }
114
134
115 // Combo box for selecting theme
135 // Combo box for selecting theme
116 void MainWidget::initThemeCombo(QGridLayout *grid)
136 void MainWidget::initThemeCombo(QGridLayout *grid)
117 {
137 {
118 QComboBox *chartTheme = new QComboBox();
138 QComboBox *chartTheme = new QComboBox();
119 chartTheme->addItem("Default");
139 chartTheme->addItem("Default");
120 chartTheme->addItem("Light");
140 chartTheme->addItem("Light");
121 chartTheme->addItem("Blue Cerulean");
141 chartTheme->addItem("Blue Cerulean");
122 chartTheme->addItem("Dark");
142 chartTheme->addItem("Dark");
123 chartTheme->addItem("Brown Sand");
143 chartTheme->addItem("Brown Sand");
124 chartTheme->addItem("Blue NCS");
144 chartTheme->addItem("Blue NCS");
125 chartTheme->addItem("High Contrast");
145 chartTheme->addItem("High Contrast");
126 chartTheme->addItem("Blue Icy");
146 chartTheme->addItem("Blue Icy");
127 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
147 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
128 this, SLOT(changeChartTheme(int)));
148 this, SLOT(changeChartTheme(int)));
129 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
149 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
130 grid->addWidget(chartTheme, 8, 1);
150 grid->addWidget(chartTheme, 8, 1);
131 }
151 }
132
152
133 // Different check boxes for customizing chart
153 // Different check boxes for customizing chart
134 void MainWidget::initCheckboxes(QGridLayout *grid)
154 void MainWidget::initCheckboxes(QGridLayout *grid)
135 {
155 {
136 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
156 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
137 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
157 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
138 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
158 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
139 zoomCheckBox->setChecked(true);
159 zoomCheckBox->setChecked(true);
140 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
160 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
141
161
142 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
162 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
143 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
163 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
144 aliasCheckBox->setChecked(false);
164 aliasCheckBox->setChecked(false);
145 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
165 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
146 }
166 }
147
167
148 void MainWidget::antiAliasToggled(bool enabled)
168 void MainWidget::antiAliasToggled(bool enabled)
149 {
169 {
150 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
170 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
151 }
171 }
152
172
153 void MainWidget::addSeries()
173 void MainWidget::addSeries()
154 {
174 {
155 if (!m_addSerieDialog) {
175 if (!m_addSerieDialog) {
156 m_addSerieDialog = new DataSerieDialog(this);
176 m_addSerieDialog = new DataSerieDialog(this);
157 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
177 connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)),
158 this, SLOT(addSeries(QString, int, int, QString, bool)));
178 this, SLOT(addSeries(QString, int, int, QString, bool)));
159 }
179 }
160 m_addSerieDialog->exec();
180 m_addSerieDialog->exec();
161 }
181 }
162
182
163 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
183 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
164 {
184 {
165 // TODO: dataCharacteristics
185 // TODO: dataCharacteristics
166 QList<RealList> testData;
186 QList<RealList> testData;
167 for (int j(0); j < columnCount; j++) {
187 for (int j(0); j < columnCount; j++) {
168 QList <qreal> newColumn;
188 QList <qreal> newColumn;
169 for (int i(0); i < rowCount; i++) {
189 for (int i(0); i < rowCount; i++) {
170 if (dataCharacteristics == "Sin") {
190 if (dataCharacteristics == "Sin") {
171 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
191 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
172 } else if (dataCharacteristics == "Sin + random") {
192 } else if (dataCharacteristics == "Sin + random") {
173 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
193 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
174 } else if (dataCharacteristics == "Random") {
194 } else if (dataCharacteristics == "Random") {
175 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
195 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
176 } else if (dataCharacteristics == "Linear") {
196 } else if (dataCharacteristics == "Linear") {
177 //newColumn.append(i * (j + 1.0));
197 //newColumn.append(i * (j + 1.0));
178 // TODO: temporary hack to make pie work; prevent zero values:
198 // TODO: temporary hack to make pie work; prevent zero values:
179 newColumn.append(i * (j + 1.0) + 0.1);
199 newColumn.append(i * (j + 1.0) + 0.1);
180 } else { // "constant"
200 } else { // "constant"
181 newColumn.append((j + 1.0));
201 newColumn.append((j + 1.0));
182 }
202 }
183 }
203 }
184 testData.append(newColumn);
204 testData.append(newColumn);
185 }
205 }
186 return testData;
206 return testData;
187 }
207 }
188
208
189 QStringList MainWidget::generateLabels(int count)
209 QStringList MainWidget::generateLabels(int count)
190 {
210 {
191 QStringList result;
211 QStringList result;
192 for (int i(0); i < count; i++)
212 for (int i(0); i < count; i++)
193 result.append("label" + QString::number(i));
213 result.append("label" + QString::number(i));
194 return result;
214 return result;
195 }
215 }
196
216
197 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
217 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
198 {
218 {
199 qDebug() << "addSeries: " << seriesName
219 qDebug() << "addSeries: " << seriesName
200 << " columnCount: " << columnCount
220 << " columnCount: " << columnCount
201 << " rowCount: " << rowCount
221 << " rowCount: " << rowCount
202 << " dataCharacteristics: " << dataCharacteristics
222 << " dataCharacteristics: " << dataCharacteristics
203 << " labels enabled: " << labelsEnabled;
223 << " labels enabled: " << labelsEnabled;
204 m_defaultSeriesName = seriesName;
224 m_defaultSeriesName = seriesName;
205
225
206 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
226 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
207
227
208 // Line series and scatter series use similar data
228 // Line series and scatter series use similar data
209 if (seriesName == "Line") {
229 if (seriesName == "Line") {
210 for (int j(0); j < data.count(); j ++) {
230 for (int j(0); j < data.count(); j ++) {
211 QList<qreal> column = data.at(j);
231 QList<qreal> column = data.at(j);
212 QLineSeries *series = new QLineSeries();
232 QLineSeries *series = new QLineSeries();
213 series->setName("line" + QString::number(j));
233 series->setName("line" + QString::number(j));
214 for (int i(0); i < column.count(); i++)
234 for (int i(0); i < column.count(); i++)
215 series->append(i, column.at(i));
235 series->append(i, column.at(i));
216 m_chart->addSeries(series);
236 m_chart->addSeries(series);
217 }
237 }
218 } else if (seriesName == "Area") {
238 } else if (seriesName == "Area") {
219 // TODO: lower series for the area?
239 // TODO: lower series for the area?
220 for (int j(0); j < data.count(); j ++) {
240 for (int j(0); j < data.count(); j ++) {
221 QList<qreal> column = data.at(j);
241 QList<qreal> column = data.at(j);
222 QLineSeries *lineSeries = new QLineSeries();
242 QLineSeries *lineSeries = new QLineSeries();
223 for (int i(0); i < column.count(); i++)
243 for (int i(0); i < column.count(); i++)
224 lineSeries->append(i, column.at(i));
244 lineSeries->append(i, column.at(i));
225 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
245 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
226 areaSeries->setName("area" + QString::number(j));
246 areaSeries->setName("area" + QString::number(j));
227 m_chart->addSeries(areaSeries);
247 m_chart->addSeries(areaSeries);
228 }
248 }
229 } else if (seriesName == "Scatter") {
249 } else if (seriesName == "Scatter") {
230 for (int j(0); j < data.count(); j++) {
250 for (int j(0); j < data.count(); j++) {
231 QList<qreal> column = data.at(j);
251 QList<qreal> column = data.at(j);
232 QScatterSeries *series = new QScatterSeries();
252 QScatterSeries *series = new QScatterSeries();
233 series->setName("scatter" + QString::number(j));
253 series->setName("scatter" + QString::number(j));
234 for (int i(0); i < column.count(); i++)
254 for (int i(0); i < column.count(); i++)
235 series->append(i, column.at(i));
255 series->append(i, column.at(i));
236 m_chart->addSeries(series);
256 m_chart->addSeries(series);
237 }
257 }
238 } else if (seriesName == "Pie") {
258 } else if (seriesName == "Pie") {
239 QStringList labels = generateLabels(rowCount);
259 QStringList labels = generateLabels(rowCount);
240 for (int j(0); j < data.count(); j++) {
260 for (int j(0); j < data.count(); j++) {
241 QPieSeries *series = new QPieSeries();
261 QPieSeries *series = new QPieSeries();
242 QList<qreal> column = data.at(j);
262 QList<qreal> column = data.at(j);
243 for (int i(0); i < column.count(); i++)
263 for (int i(0); i < column.count(); i++)
244 series->append(column.at(i), labels.at(i));
264 series->append(column.at(i), labels.at(i));
245 m_chart->addSeries(series);
265 m_chart->addSeries(series);
246 }
266 }
247 } else if (seriesName == "Bar"
267 } else if (seriesName == "Bar"
248 || seriesName == "Stacked bar"
268 || seriesName == "Stacked bar"
249 || seriesName == "Percent bar") {
269 || seriesName == "Percent bar") {
250 QStringList category;
270 QStringList category;
251 QStringList labels = generateLabels(rowCount);
271 QStringList labels = generateLabels(rowCount);
252 foreach(QString label, labels)
272 foreach(QString label, labels)
253 category << label;
273 category << label;
254 QBarSeries* series = 0;
274 QBarSeries* series = 0;
255 if (seriesName == "Bar")
275 if (seriesName == "Bar")
256 series = new QBarSeries(category, this);
276 series = new QBarSeries(category, this);
257 else if (seriesName == "Stacked bar")
277 else if (seriesName == "Stacked bar")
258 series = new QStackedBarSeries(category, this);
278 series = new QStackedBarSeries(category, this);
259 else
279 else
260 series = new QPercentBarSeries(category, this);
280 series = new QPercentBarSeries(category, this);
261
281
262 for (int j(0); j < data.count(); j++) {
282 for (int j(0); j < data.count(); j++) {
263 QList<qreal> column = data.at(j);
283 QList<qreal> column = data.at(j);
264 QBarSet *set = new QBarSet("set" + QString::number(j));
284 QBarSet *set = new QBarSet("set" + QString::number(j));
265 for (int i(0); i < column.count(); i++)
285 for (int i(0); i < column.count(); i++)
266 *set << column.at(i);
286 *set << column.at(i);
267 series->appendBarSet(set);
287 series->appendBarSet(set);
268 }
288 }
269
289
270 // TODO: new implementation of setFloatingValuesEnabled with signals
290 // TODO: new implementation of setFloatingValuesEnabled with signals
271 //series->setFloatingValuesEnabled(true);
291 //series->setFloatingValuesEnabled(true);
272 series->setToolTipEnabled(true);
292 series->setToolTipEnabled(true);
273 m_chart->addSeries(series);
293 m_chart->addSeries(series);
274 } else if (seriesName == "Spline") {
294 } else if (seriesName == "Spline") {
275 for (int j(0); j < data.count(); j ++) {
295 for (int j(0); j < data.count(); j ++) {
276 QList<qreal> column = data.at(j);
296 QList<qreal> column = data.at(j);
277 QSplineSeries *series = new QSplineSeries();
297 QSplineSeries *series = new QSplineSeries();
278 for (int i(0); i < column.count(); i++)
298 for (int i(0); i < column.count(); i++)
279 series->append(i, column.at(i));
299 series->append(i, column.at(i));
280 m_chart->addSeries(series);
300 m_chart->addSeries(series);
281 }
301 }
282 }
302 }
283 }
303 }
284
304
285 void MainWidget::backgroundChanged(int itemIndex)
305 void MainWidget::backgroundChanged(int itemIndex)
286 {
306 {
287 qDebug() << "backgroundChanged: " << itemIndex;
307 qDebug() << "backgroundChanged: " << itemIndex;
288 }
308 }
289
309
290 void MainWidget::autoScaleChanged(int value)
310 void MainWidget::autoScaleChanged(int value)
291 {
311 {
292 if (value) {
312 if (value) {
293 // TODO: enable auto scaling
313 // TODO: enable auto scaling
294 } else {
314 } else {
295 // TODO: set scaling manually (and disable auto scaling)
315 // TODO: set scaling manually (and disable auto scaling)
296 }
316 }
297
317
298 m_xMinSpin->setEnabled(!value);
318 m_xMinSpin->setEnabled(!value);
299 m_xMaxSpin->setEnabled(!value);
319 m_xMaxSpin->setEnabled(!value);
300 m_yMinSpin->setEnabled(!value);
320 m_yMinSpin->setEnabled(!value);
301 m_yMaxSpin->setEnabled(!value);
321 m_yMaxSpin->setEnabled(!value);
302 }
322 }
303
323
304 void MainWidget::xMinChanged(int value)
324 void MainWidget::xMinChanged(int value)
305 {
325 {
306 qDebug() << "xMinChanged: " << value;
326 qDebug() << "xMinChanged: " << value;
307 }
327 }
308
328
309 void MainWidget::xMaxChanged(int value)
329 void MainWidget::xMaxChanged(int value)
310 {
330 {
311 qDebug() << "xMaxChanged: " << value;
331 qDebug() << "xMaxChanged: " << value;
312 }
332 }
313
333
314 void MainWidget::yMinChanged(int value)
334 void MainWidget::yMinChanged(int value)
315 {
335 {
316 qDebug() << "yMinChanged: " << value;
336 qDebug() << "yMinChanged: " << value;
317 }
337 }
318
338
319 void MainWidget::yMaxChanged(int value)
339 void MainWidget::yMaxChanged(int value)
320 {
340 {
321 qDebug() << "yMaxChanged: " << value;
341 qDebug() << "yMaxChanged: " << value;
322 }
342 }
323
343
324 void MainWidget::changeChartTheme(int themeIndex)
344 void MainWidget::changeChartTheme(int themeIndex)
325 {
345 {
326 qDebug() << "changeChartTheme: " << themeIndex;
346 qDebug() << "changeChartTheme: " << themeIndex;
327 m_chart->setTheme((QChart::ChartTheme) themeIndex);
347 m_chart->setTheme((QChart::ChartTheme) themeIndex);
328 }
348 }
@@ -1,59 +1,79
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
1 #ifndef MAINWIDGET_H
21 #ifndef MAINWIDGET_H
2 #define MAINWIDGET_H
22 #define MAINWIDGET_H
3
23
4 #include "qchartglobal.h"
24 #include "qchartglobal.h"
5 #include "qchart.h"
25 #include "qchart.h"
6 #include "qchartview.h"
26 #include "qchartview.h"
7 #include <QWidget>
27 #include <QWidget>
8
28
9 class QSpinBox;
29 class QSpinBox;
10 class QCheckBox;
30 class QCheckBox;
11 class QGridLayout;
31 class QGridLayout;
12
32
13 QTCOMMERCIALCHART_USE_NAMESPACE
33 QTCOMMERCIALCHART_USE_NAMESPACE
14
34
15 #define RealList QList<qreal>
35 #define RealList QList<qreal>
16 class DataSerieDialog;
36 class DataSerieDialog;
17
37
18 class MainWidget : public QWidget
38 class MainWidget : public QWidget
19 {
39 {
20 Q_OBJECT
40 Q_OBJECT
21 public:
41 public:
22 explicit MainWidget(QWidget *parent = 0);
42 explicit MainWidget(QWidget *parent = 0);
23
43
24 signals:
44 signals:
25
45
26 private:
46 private:
27 void initBackroundCombo(QGridLayout *grid);
47 void initBackroundCombo(QGridLayout *grid);
28 void initScaleControls(QGridLayout *grid);
48 void initScaleControls(QGridLayout *grid);
29 void initThemeCombo(QGridLayout *grid);
49 void initThemeCombo(QGridLayout *grid);
30 void initCheckboxes(QGridLayout *grid);
50 void initCheckboxes(QGridLayout *grid);
31
51
32 private slots:
52 private slots:
33 void addSeries();
53 void addSeries();
34 void addSeries(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled);
54 void addSeries(QString series, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled);
35 void backgroundChanged(int itemIndex);
55 void backgroundChanged(int itemIndex);
36 void autoScaleChanged(int value);
56 void autoScaleChanged(int value);
37 void xMinChanged(int value);
57 void xMinChanged(int value);
38 void xMaxChanged(int value);
58 void xMaxChanged(int value);
39 void yMinChanged(int value);
59 void yMinChanged(int value);
40 void yMaxChanged(int value);
60 void yMaxChanged(int value);
41 void antiAliasToggled(bool enabled);
61 void antiAliasToggled(bool enabled);
42 void changeChartTheme(int themeIndex);
62 void changeChartTheme(int themeIndex);
43 QList<RealList> generateTestData(int columnCount, int rowCount, QString dataCharacteristics);
63 QList<RealList> generateTestData(int columnCount, int rowCount, QString dataCharacteristics);
44 QStringList generateLabels(int count);
64 QStringList generateLabels(int count);
45
65
46 private:
66 private:
47 DataSerieDialog *m_addSerieDialog;
67 DataSerieDialog *m_addSerieDialog;
48 QChart *m_chart;
68 QChart *m_chart;
49 QChartView *m_chartView;
69 QChartView *m_chartView;
50 QCheckBox *m_autoScaleCheck;
70 QCheckBox *m_autoScaleCheck;
51 QSpinBox *m_xMinSpin;
71 QSpinBox *m_xMinSpin;
52 QSpinBox *m_xMaxSpin;
72 QSpinBox *m_xMaxSpin;
53 QSpinBox *m_yMinSpin;
73 QSpinBox *m_yMinSpin;
54 QSpinBox *m_yMaxSpin;
74 QSpinBox *m_yMaxSpin;
55 QString m_defaultSeriesName;
75 QString m_defaultSeriesName;
56 QGridLayout *m_scatterLayout;
76 QGridLayout *m_scatterLayout;
57 };
77 };
58
78
59 #endif // MAINWIDGET_H
79 #endif // MAINWIDGET_H
@@ -1,11 +1,31
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
1 import QtQuick 1.1
21 import QtQuick 1.1
2 //import QtQuick 2.0
22 //import QtQuick 2.0
3 import com.digia.charts 1.0
23 import com.digia.charts 1.0
4
24
5 Chart {
25 Chart {
6 width: 200
26 width: 200
7 height: 200
27 height: 200
8 color: "red"
28 color: "red"
9 }
29 }
10
30
11
31
General Comments 0
You need to be logged in to leave comments. Login now