##// END OF EJS Templates
rename functions add() -> append()
Jani Honkonen -
r796:4bbe1f66d4b7
parent child
Show More
@@ -1,346 +1,346
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:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** You may use this file under the terms of the BSD license as follows:
11 **
11 **
12 ** "Redistribution and use in source and binary forms, with or without
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
13 ** modification, are permitted provided that the following conditions are
14 ** met:
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
19 ** the documentation and/or other materials provided with the
20 ** distribution.
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
23 ** software without specific prior written permission.
24 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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."
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
36 ** $QT_END_LICENSE$
37 **
37 **
38 ****************************************************************************/
38 ****************************************************************************/
39
39
40 #include "themewidget.h"
40 #include "themewidget.h"
41
41
42 #include <QChartView>
42 #include <QChartView>
43 #include <QPieSeries>
43 #include <QPieSeries>
44 #include <QPieSlice>
44 #include <QPieSlice>
45 #include <QBarSeries>
45 #include <QBarSeries>
46 #include <QPercentBarSeries>
46 #include <QPercentBarSeries>
47 #include <QStackedBarSeries>
47 #include <QStackedBarSeries>
48 #include <QBarSet>
48 #include <QBarSet>
49 #include <QLineSeries>
49 #include <QLineSeries>
50 #include <QSplineSeries>
50 #include <QSplineSeries>
51 #include <QScatterSeries>
51 #include <QScatterSeries>
52 #include <QAreaSeries>
52 #include <QAreaSeries>
53 #include <QGridLayout>
53 #include <QGridLayout>
54 #include <QFormLayout>
54 #include <QFormLayout>
55 #include <QComboBox>
55 #include <QComboBox>
56 #include <QSpinBox>
56 #include <QSpinBox>
57 #include <QCheckBox>
57 #include <QCheckBox>
58 #include <QGroupBox>
58 #include <QGroupBox>
59 #include <QLabel>
59 #include <QLabel>
60 #include <QTime>
60 #include <QTime>
61
61
62 ThemeWidget::ThemeWidget(QWidget* parent) :
62 ThemeWidget::ThemeWidget(QWidget* parent) :
63 QWidget(parent),
63 QWidget(parent),
64 m_listCount(3),
64 m_listCount(3),
65 m_valueMax(100),
65 m_valueMax(100),
66 m_valueCount(11),
66 m_valueCount(11),
67 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
67 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
68 m_themeComboBox(createThemeBox()),
68 m_themeComboBox(createThemeBox()),
69 m_antialiasCheckBox(new QCheckBox("Anti aliasing")),
69 m_antialiasCheckBox(new QCheckBox("Anti aliasing")),
70 m_animatedComboBox(createAnimationBox())
70 m_animatedComboBox(createAnimationBox())
71 {
71 {
72
72
73 connectSignals();
73 connectSignals();
74 // create layout
74 // create layout
75 QGridLayout* baseLayout = new QGridLayout();
75 QGridLayout* baseLayout = new QGridLayout();
76 QHBoxLayout *settingsLayout = new QHBoxLayout();
76 QHBoxLayout *settingsLayout = new QHBoxLayout();
77 settingsLayout->addWidget(new QLabel("Theme:"));
77 settingsLayout->addWidget(new QLabel("Theme:"));
78 settingsLayout->addWidget(m_themeComboBox);
78 settingsLayout->addWidget(m_themeComboBox);
79 settingsLayout->addWidget(new QLabel("Animation:"));
79 settingsLayout->addWidget(new QLabel("Animation:"));
80 settingsLayout->addWidget(m_animatedComboBox);
80 settingsLayout->addWidget(m_animatedComboBox);
81 settingsLayout->addWidget(m_antialiasCheckBox);
81 settingsLayout->addWidget(m_antialiasCheckBox);
82 settingsLayout->addStretch();
82 settingsLayout->addStretch();
83 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
83 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
84
84
85 //create charts
85 //create charts
86
86
87 QChartView *chartView;
87 QChartView *chartView;
88
88
89 chartView = new QChartView(createAreaChart());
89 chartView = new QChartView(createAreaChart());
90 baseLayout->addWidget(chartView, 1, 0);
90 baseLayout->addWidget(chartView, 1, 0);
91 m_charts << chartView;
91 m_charts << chartView;
92
92
93 chartView = new QChartView(createBarChart(m_valueCount));
93 chartView = new QChartView(createBarChart(m_valueCount));
94 baseLayout->addWidget(chartView, 1, 1);
94 baseLayout->addWidget(chartView, 1, 1);
95 m_charts << chartView;
95 m_charts << chartView;
96
96
97 chartView = new QChartView(createLineChart());
97 chartView = new QChartView(createLineChart());
98 baseLayout->addWidget(chartView, 1, 2);
98 baseLayout->addWidget(chartView, 1, 2);
99 m_charts << chartView;
99 m_charts << chartView;
100
100
101 chartView = new QChartView(createPieChart());
101 chartView = new QChartView(createPieChart());
102 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
102 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
103 baseLayout->addWidget(chartView, 2, 0);
103 baseLayout->addWidget(chartView, 2, 0);
104 m_charts << chartView;
104 m_charts << chartView;
105
105
106 chartView = new QChartView(createSplineChart());
106 chartView = new QChartView(createSplineChart());
107 baseLayout->addWidget(chartView, 2, 1);
107 baseLayout->addWidget(chartView, 2, 1);
108 m_charts << chartView;
108 m_charts << chartView;
109
109
110 chartView = new QChartView(createScatterChart());
110 chartView = new QChartView(createScatterChart());
111 baseLayout->addWidget(chartView, 2, 2);
111 baseLayout->addWidget(chartView, 2, 2);
112 m_charts << chartView;
112 m_charts << chartView;
113
113
114 setLayout(baseLayout);
114 setLayout(baseLayout);
115 }
115 }
116
116
117 ThemeWidget::~ThemeWidget()
117 ThemeWidget::~ThemeWidget()
118 {
118 {
119 }
119 }
120
120
121 void ThemeWidget::connectSignals()
121 void ThemeWidget::connectSignals()
122 {
122 {
123 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
123 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
124 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
124 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
125 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
125 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
126 }
126 }
127
127
128 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
128 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
129 {
129 {
130 DataTable dataTable;
130 DataTable dataTable;
131
131
132 // set seed for random stuff
132 // set seed for random stuff
133 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
133 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
134
134
135 // generate random data
135 // generate random data
136 for (int i(0); i < listCount; i++) {
136 for (int i(0); i < listCount; i++) {
137 DataList dataList;
137 DataList dataList;
138 for (int j(0); j < valueCount; j++) {
138 for (int j(0); j < valueCount; j++) {
139 QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax);
139 QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax);
140 QString label = "Item " + QString::number(i) + ":" + QString::number(j);
140 QString label = "Item " + QString::number(i) + ":" + QString::number(j);
141 dataList << Data(value, label);
141 dataList << Data(value, label);
142 }
142 }
143 dataTable << dataList;
143 dataTable << dataList;
144 }
144 }
145
145
146 return dataTable;
146 return dataTable;
147 }
147 }
148
148
149 QComboBox* ThemeWidget::createThemeBox() const
149 QComboBox* ThemeWidget::createThemeBox() const
150 {
150 {
151 // settings layout
151 // settings layout
152 QComboBox* themeComboBox = new QComboBox();
152 QComboBox* themeComboBox = new QComboBox();
153 themeComboBox->addItem("Default", QChart::ChartThemeDefault);
153 themeComboBox->addItem("Default", QChart::ChartThemeDefault);
154 themeComboBox->addItem("Light", QChart::ChartThemeLight);
154 themeComboBox->addItem("Light", QChart::ChartThemeLight);
155 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
155 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
156 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
156 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
157 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
157 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
158 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
158 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
159 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
159 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
160 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
160 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
161 return themeComboBox;
161 return themeComboBox;
162 }
162 }
163
163
164 QComboBox* ThemeWidget::createAnimationBox() const
164 QComboBox* ThemeWidget::createAnimationBox() const
165 {
165 {
166 // settings layout
166 // settings layout
167 QComboBox* animationComboBox = new QComboBox();
167 QComboBox* animationComboBox = new QComboBox();
168 animationComboBox->addItem("No Animations", QChart::NoAnimation);
168 animationComboBox->addItem("No Animations", QChart::NoAnimation);
169 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
169 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
170 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
170 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
171 animationComboBox->addItem("All Animations", QChart::AllAnimations);
171 animationComboBox->addItem("All Animations", QChart::AllAnimations);
172 return animationComboBox;
172 return animationComboBox;
173 }
173 }
174
174
175 QChart* ThemeWidget::createAreaChart() const
175 QChart* ThemeWidget::createAreaChart() const
176 {
176 {
177 // area chart
177 // area chart
178 QChart *chart = new QChart();
178 QChart *chart = new QChart();
179 chart->setTitle("Area chart");
179 chart->setTitle("Area chart");
180 {
180 {
181 QString name("Series ");
181 QString name("Series ");
182 int nameIndex = 0;
182 int nameIndex = 0;
183 for (int i(0); i < m_dataTable.count(); i++) {
183 for (int i(0); i < m_dataTable.count(); i++) {
184 QLineSeries *series1 = new QLineSeries(chart);
184 QLineSeries *series1 = new QLineSeries(chart);
185 QLineSeries *series2 = new QLineSeries(chart);
185 QLineSeries *series2 = new QLineSeries(chart);
186 foreach (Data data, m_dataTable[i]) {
186 foreach (Data data, m_dataTable[i]) {
187 series1->add(data.first);
187 series1->append(data.first);
188 series2->add(QPointF(data.first.x(), 0.0));
188 series2->append(QPointF(data.first.x(), 0.0));
189 }
189 }
190 QAreaSeries *area = new QAreaSeries(series1, series2);
190 QAreaSeries *area = new QAreaSeries(series1, series2);
191 area->setName(name + QString::number(nameIndex));
191 area->setName(name + QString::number(nameIndex));
192 nameIndex++;
192 nameIndex++;
193 chart->addSeries(area);
193 chart->addSeries(area);
194 }
194 }
195 }
195 }
196 return chart;
196 return chart;
197 }
197 }
198
198
199 QChart* ThemeWidget::createBarChart(int valueCount) const
199 QChart* ThemeWidget::createBarChart(int valueCount) const
200 {
200 {
201 // bar chart
201 // bar chart
202 QChart* chart = new QChart();
202 QChart* chart = new QChart();
203 chart->setTitle("Bar chart");
203 chart->setTitle("Bar chart");
204 {
204 {
205 QBarCategories categories;
205 QBarCategories categories;
206 // TODO: categories
206 // TODO: categories
207 for (int i(0); i < valueCount; i++)
207 for (int i(0); i < valueCount; i++)
208 categories << QString::number(i);
208 categories << QString::number(i);
209 // QBarSeries* series = new QBarSeries(categories, chart);
209 // QBarSeries* series = new QBarSeries(categories, chart);
210 // QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
210 // QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
211 QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
211 QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
212 for (int i(0); i < m_dataTable.count(); i++) {
212 for (int i(0); i < m_dataTable.count(); i++) {
213 QBarSet *set = new QBarSet("Set" + QString::number(i));
213 QBarSet *set = new QBarSet("Set" + QString::number(i));
214 foreach (Data data, m_dataTable[i])
214 foreach (Data data, m_dataTable[i])
215 *set << data.first.y();
215 *set << data.first.y();
216 series->appendBarSet(set);
216 series->appendBarSet(set);
217 }
217 }
218 chart->addSeries(series);
218 chart->addSeries(series);
219 }
219 }
220 return chart;
220 return chart;
221 }
221 }
222
222
223 QChart* ThemeWidget::createLineChart() const
223 QChart* ThemeWidget::createLineChart() const
224 {
224 {
225 // line chart
225 // line chart
226 QChart* chart = new QChart();
226 QChart* chart = new QChart();
227 chart->setTitle("Line chart");
227 chart->setTitle("Line chart");
228 QString name("Series ");
228 QString name("Series ");
229 int nameIndex = 0;
229 int nameIndex = 0;
230 foreach (DataList list, m_dataTable) {
230 foreach (DataList list, m_dataTable) {
231 QLineSeries *series = new QLineSeries(chart);
231 QLineSeries *series = new QLineSeries(chart);
232 foreach (Data data, list)
232 foreach (Data data, list)
233 series->add(data.first);
233 series->append(data.first);
234 series->setName(name + QString::number(nameIndex));
234 series->setName(name + QString::number(nameIndex));
235 nameIndex++;
235 nameIndex++;
236 chart->addSeries(series);
236 chart->addSeries(series);
237 }
237 }
238 return chart;
238 return chart;
239 }
239 }
240
240
241 QChart* ThemeWidget::createPieChart() const
241 QChart* ThemeWidget::createPieChart() const
242 {
242 {
243 // pie chart
243 // pie chart
244 QChart* chart = new QChart();
244 QChart* chart = new QChart();
245 chart->setTitle("Pie chart");
245 chart->setTitle("Pie chart");
246 qreal pieSize = 1.0 / m_dataTable.count();
246 qreal pieSize = 1.0 / m_dataTable.count();
247 for (int i = 0; i < m_dataTable.count(); i++) {
247 for (int i = 0; i < m_dataTable.count(); i++) {
248 QPieSeries *series = new QPieSeries(chart);
248 QPieSeries *series = new QPieSeries(chart);
249 foreach (Data data, m_dataTable[i]) {
249 foreach (Data data, m_dataTable[i]) {
250 QPieSlice *slice = series->add(data.first.y(), data.second);
250 QPieSlice *slice = series->append(data.first.y(), data.second);
251 if (data == m_dataTable[i].first()) {
251 if (data == m_dataTable[i].first()) {
252 slice->setLabelVisible();
252 slice->setLabelVisible();
253 slice->setExploded();
253 slice->setExploded();
254 }
254 }
255 }
255 }
256 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
256 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
257 series->setPieSize(pieSize);
257 series->setPieSize(pieSize);
258 series->setPiePosition(hPos, 0.5);
258 series->setPiePosition(hPos, 0.5);
259 chart->addSeries(series);
259 chart->addSeries(series);
260 }
260 }
261
261
262 return chart;
262 return chart;
263 }
263 }
264
264
265 QChart* ThemeWidget::createSplineChart() const
265 QChart* ThemeWidget::createSplineChart() const
266 { // spine chart
266 { // spine chart
267 QChart* chart = new QChart();
267 QChart* chart = new QChart();
268 chart->setTitle("Spline chart");
268 chart->setTitle("Spline chart");
269 QString name("Series ");
269 QString name("Series ");
270 int nameIndex = 0;
270 int nameIndex = 0;
271 foreach (DataList list, m_dataTable) {
271 foreach (DataList list, m_dataTable) {
272 QSplineSeries *series = new QSplineSeries(chart);
272 QSplineSeries *series = new QSplineSeries(chart);
273 foreach (Data data, list)
273 foreach (Data data, list)
274 series->add(data.first);
274 series->append(data.first);
275 series->setName(name + QString::number(nameIndex));
275 series->setName(name + QString::number(nameIndex));
276 nameIndex++;
276 nameIndex++;
277 chart->addSeries(series);
277 chart->addSeries(series);
278 }
278 }
279 return chart;
279 return chart;
280 }
280 }
281
281
282 QChart* ThemeWidget::createScatterChart() const
282 QChart* ThemeWidget::createScatterChart() const
283 { // scatter chart
283 { // scatter chart
284 QChart* chart = new QChart();
284 QChart* chart = new QChart();
285 chart->setTitle("Scatter chart");
285 chart->setTitle("Scatter chart");
286 QString name("Series ");
286 QString name("Series ");
287 int nameIndex = 0;
287 int nameIndex = 0;
288 foreach (DataList list, m_dataTable) {
288 foreach (DataList list, m_dataTable) {
289 QScatterSeries *series = new QScatterSeries(chart);
289 QScatterSeries *series = new QScatterSeries(chart);
290 foreach (Data data, list)
290 foreach (Data data, list)
291 series->add(data.first);
291 series->append(data.first);
292 series->setName(name + QString::number(nameIndex));
292 series->setName(name + QString::number(nameIndex));
293 nameIndex++;
293 nameIndex++;
294 chart->addSeries(series);
294 chart->addSeries(series);
295 }
295 }
296 return chart;
296 return chart;
297 }
297 }
298
298
299 void ThemeWidget::updateUI()
299 void ThemeWidget::updateUI()
300 {
300 {
301 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
301 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
302
302
303 if (m_charts.at(0)->chart()->theme() != theme) {
303 if (m_charts.at(0)->chart()->theme() != theme) {
304 foreach (QChartView *chartView, m_charts)
304 foreach (QChartView *chartView, m_charts)
305 chartView->chart()->setTheme(theme);
305 chartView->chart()->setTheme(theme);
306
306
307 QPalette pal = window()->palette();
307 QPalette pal = window()->palette();
308 if (theme == QChart::ChartThemeLight) {
308 if (theme == QChart::ChartThemeLight) {
309 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
309 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
310 pal.setColor(QPalette::WindowText, QRgb(0x404044));
310 pal.setColor(QPalette::WindowText, QRgb(0x404044));
311 } else if (theme == QChart::ChartThemeDark) {
311 } else if (theme == QChart::ChartThemeDark) {
312 pal.setColor(QPalette::Window, QRgb(0x121218));
312 pal.setColor(QPalette::Window, QRgb(0x121218));
313 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
313 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
314 } else if (theme == QChart::ChartThemeBlueCerulean) {
314 } else if (theme == QChart::ChartThemeBlueCerulean) {
315 pal.setColor(QPalette::Window, QRgb(0x40434a));
315 pal.setColor(QPalette::Window, QRgb(0x40434a));
316 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
316 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
317 } else if (theme == QChart::ChartThemeBrownSand) {
317 } else if (theme == QChart::ChartThemeBrownSand) {
318 pal.setColor(QPalette::Window, QRgb(0x9e8965));
318 pal.setColor(QPalette::Window, QRgb(0x9e8965));
319 pal.setColor(QPalette::WindowText, QRgb(0x404044));
319 pal.setColor(QPalette::WindowText, QRgb(0x404044));
320 } else if (theme == QChart::ChartThemeBlueNcs) {
320 } else if (theme == QChart::ChartThemeBlueNcs) {
321 pal.setColor(QPalette::Window, QRgb(0x018bba));
321 pal.setColor(QPalette::Window, QRgb(0x018bba));
322 pal.setColor(QPalette::WindowText, QRgb(0x404044));
322 pal.setColor(QPalette::WindowText, QRgb(0x404044));
323 } else if (theme == QChart::ChartThemeHighContrast) {
323 } else if (theme == QChart::ChartThemeHighContrast) {
324 pal.setColor(QPalette::Window, QRgb(0xffab03));
324 pal.setColor(QPalette::Window, QRgb(0xffab03));
325 pal.setColor(QPalette::WindowText, QRgb(0x181818));
325 pal.setColor(QPalette::WindowText, QRgb(0x181818));
326 } else if (theme == QChart::ChartThemeBlueIcy) {
326 } else if (theme == QChart::ChartThemeBlueIcy) {
327 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
327 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
328 pal.setColor(QPalette::WindowText, QRgb(0x404044));
328 pal.setColor(QPalette::WindowText, QRgb(0x404044));
329 } else {
329 } else {
330 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
330 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
331 pal.setColor(QPalette::WindowText, QRgb(0x404044));
331 pal.setColor(QPalette::WindowText, QRgb(0x404044));
332 }
332 }
333 window()->setPalette(pal);
333 window()->setPalette(pal);
334 }
334 }
335
335
336 bool checked = m_antialiasCheckBox->isChecked();
336 bool checked = m_antialiasCheckBox->isChecked();
337 foreach (QChartView *chart, m_charts)
337 foreach (QChartView *chart, m_charts)
338 chart->setRenderHint(QPainter::Antialiasing, checked);
338 chart->setRenderHint(QPainter::Antialiasing, checked);
339
339
340 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
340 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
341 if (m_charts.at(0)->chart()->animationOptions() != options) {
341 if (m_charts.at(0)->chart()->animationOptions() != options) {
342 foreach (QChartView *chartView, m_charts)
342 foreach (QChartView *chartView, m_charts)
343 chartView->chart()->setAnimationOptions(options);
343 chartView->chart()->setAnimationOptions(options);
344 }
344 }
345 }
345 }
346
346
@@ -1,83 +1,83
1 #include <QtGui/QApplication>
1 #include <QtGui/QApplication>
2 #include <QMainWindow>
2 #include <QMainWindow>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qlineseries.h>
5 #include <qlineseries.h>
6 #include <qscatterseries.h>
6 #include <qscatterseries.h>
7 #include <qbarseries.h>
7 #include <qbarseries.h>
8 #include <qbarset.h>
8 #include <qbarset.h>
9 #include <qpieseries.h>
9 #include <qpieseries.h>
10 #include <QStringList>
10 #include <QStringList>
11
11
12 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
13
13
14 int main(int argc, char *argv[])
14 int main(int argc, char *argv[])
15 {
15 {
16 QApplication a(argc, argv);
16 QApplication a(argc, argv);
17
17
18 //! [1]
18 //! [1]
19 // Create chart view
19 // Create chart view
20 QChartView *chartView = new QChartView();
20 QChartView *chartView = new QChartView();
21 chartView->setRenderHint(QPainter::Antialiasing);
21 chartView->setRenderHint(QPainter::Antialiasing);
22 chartView->setChartTitle("Simple Line Chart");
22 chartView->setChartTitle("Simple Line Chart");
23 // Add series to the chart
23 // Add series to the chart
24 QLineSeries *line = new QLineSeries();
24 QLineSeries *line = new QLineSeries();
25 line->add(0.0, 0.8);
25 line->append(0.0, 0.8);
26 line->add(1.1, 1.1);
26 line->append(1.1, 1.1);
27 line->add(2.0, 2.5);
27 line->append(2.0, 2.5);
28 chartView->addSeries(line);
28 chartView->addSeries(line);
29 //! [1]
29 //! [1]
30
30
31 chartView->setChartTitle("\'Scietific\' theme");
31 chartView->setChartTitle("\'Scietific\' theme");
32 //! [2]
32 //! [2]
33 // Change theme
33 // Change theme
34 chartView->setChartTheme(QChart::ChartThemeHighContrast);
34 chartView->setChartTheme(QChart::ChartThemeHighContrast);
35 //! [2]
35 //! [2]
36
36
37 chartView->setChartTitle("Simple Pie Chart");
37 chartView->setChartTitle("Simple Pie Chart");
38 //! [3]
38 //! [3]
39 // Add pie series
39 // Add pie series
40 // ...
40 // ...
41 QPieSeries *pie = new QPieSeries();
41 QPieSeries *pie = new QPieSeries();
42 pie->add(3.4, "slice1");
42 pie->append(3.4, "slice1");
43 pie->add(6.7, "slice2");
43 pie->append(6.7, "slice2");
44 chartView->addSeries(pie);
44 chartView->addSeries(pie);
45 //! [3]
45 //! [3]
46
46
47 chartView->setChartTitle("Simple Scatter Chart");
47 chartView->setChartTitle("Simple Scatter Chart");
48 //! [4]
48 //! [4]
49 // Add scatter series
49 // Add scatter series
50 // ...
50 // ...
51 QScatterSeries *scatter = new QScatterSeries();
51 QScatterSeries *scatter = new QScatterSeries();
52 for (qreal x(0); x < 100; x += 0.5) {
52 for (qreal x(0); x < 100; x += 0.5) {
53 qreal y = rand() % 100;
53 qreal y = rand() % 100;
54 *(scatter) << QPointF(x, y);
54 *(scatter) << QPointF(x, y);
55 }
55 }
56 chartView->addSeries(scatter);
56 chartView->addSeries(scatter);
57 //! [4]
57 //! [4]
58
58
59 chartView->setChartTitle("Simple Bar Chart");
59 chartView->setChartTitle("Simple Bar Chart");
60 //! [5]
60 //! [5]
61 // ...
61 // ...
62 // Add bar series
62 // Add bar series
63 QStringList barCategory;
63 QStringList barCategory;
64 barCategory << "Jan"
64 barCategory << "Jan"
65 << "Feb"
65 << "Feb"
66 << "Mar";
66 << "Mar";
67 QBarSeries *bar = new QBarSeries(barCategory);
67 QBarSeries *bar = new QBarSeries(barCategory);
68 QBarSet *barSet = new QBarSet("Sales");
68 QBarSet *barSet = new QBarSet("Sales");
69 *barSet << 123.2
69 *barSet << 123.2
70 << 301.3
70 << 301.3
71 << 285.8;
71 << 285.8;
72 bar->addBarSet(barSet);
72 bar->addBarSet(barSet);
73 chartView->addSeries(bar);
73 chartView->addSeries(bar);
74 //! [5]
74 //! [5]
75
75
76 QMainWindow w;
76 QMainWindow w;
77 w.resize(400, 300);
77 w.resize(400, 300);
78 w.setCentralWidget(chartView);
78 w.setCentralWidget(chartView);
79 w.setWindowFlags(Qt::FramelessWindowHint);
79 w.setWindowFlags(Qt::FramelessWindowHint);
80 w.show();
80 w.show();
81
81
82 return a.exec();
82 return a.exec();
83 }
83 }
@@ -1,60 +1,60
1 #include <QTimer>
1 #include <QTimer>
2 #include <QTime>
2 #include <QTime>
3 #include <QObject>
3 #include <QObject>
4 #include <cmath>
4 #include <cmath>
5 #include <qlineseries.h>
5 #include <qlineseries.h>
6
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
8
9 #define PI 3.14159265358979
9 #define PI 3.14159265358979
10 static const int numPoints =100;
10 static const int numPoints =100;
11
11
12 class WaveGenerator: public QObject
12 class WaveGenerator: public QObject
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15
15
16 public:
16 public:
17 WaveGenerator(QLineSeries* series1, QLineSeries* series2) :
17 WaveGenerator(QLineSeries* series1, QLineSeries* series2) :
18 m_series1(series1),
18 m_series1(series1),
19 m_series2(series2),
19 m_series2(series2),
20 m_wave(0),
20 m_wave(0),
21 m_step(2*PI/numPoints)
21 m_step(2*PI/numPoints)
22 {
22 {
23
23
24 QTime now = QTime::currentTime();
24 QTime now = QTime::currentTime();
25 qsrand((uint)now.msec());
25 qsrand((uint)now.msec());
26
26
27 int fluctuate = 100;
27 int fluctuate = 100;
28
28
29 for (qreal x = 0; x <= 2*PI; x+=m_step) {
29 for (qreal x = 0; x <= 2*PI; x+=m_step) {
30 series1->add(x, fabs(sin(x)*fluctuate));
30 series1->append(x, fabs(sin(x)*fluctuate));
31 series2->add(x, fabs(cos(x)*fluctuate));
31 series2->append(x, fabs(cos(x)*fluctuate));
32 }
32 }
33
33
34 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(update()));
34 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(update()));
35 m_timer.setInterval(5000);
35 m_timer.setInterval(5000);
36 m_timer.start();
36 m_timer.start();
37
37
38 };
38 };
39
39
40 public slots:
40 public slots:
41 void update()
41 void update()
42 {
42 {
43 int fluctuate;
43 int fluctuate;
44
44
45 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
45 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
46 fluctuate = qrand() % 100;
46 fluctuate = qrand() % 100;
47 m_series1->replace(x, fabs(sin(x)*fluctuate));
47 m_series1->replace(x, fabs(sin(x)*fluctuate));
48 fluctuate = qrand() % 100;
48 fluctuate = qrand() % 100;
49 m_series2->replace(x, fabs(cos(x)*fluctuate));
49 m_series2->replace(x, fabs(cos(x)*fluctuate));
50 }
50 }
51
51
52 }
52 }
53
53
54 private:
54 private:
55 QLineSeries* m_series1;
55 QLineSeries* m_series1;
56 QLineSeries* m_series2;
56 QLineSeries* m_series2;
57 int m_wave;
57 int m_wave;
58 qreal m_step;
58 qreal m_step;
59 QTimer m_timer;
59 QTimer m_timer;
60 };
60 };
@@ -1,57 +1,57
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <QSplineSeries>
2 #include <QSplineSeries>
3 #include <QTime>
3 #include <QTime>
4
4
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
5 ChartView::ChartView(QWidget* parent):QChartView(parent),
6 m_step(1),
6 m_step(1),
7 m_x(0),
7 m_x(0),
8 m_y(1)
8 m_y(1)
9 {
9 {
10 QTime now = QTime::currentTime();
10 QTime now = QTime::currentTime();
11 qsrand((uint)now.msec());
11 qsrand((uint)now.msec());
12 setChartTitle("Three random line charts");
12 setChartTitle("Three random line charts");
13
13
14 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
14 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
15 m_timer.setInterval(1000);
15 m_timer.setInterval(1000);
16
16
17 m_series0 = new QLineSeries(this);
17 m_series0 = new QLineSeries(this);
18 QPen blue(Qt::blue);
18 QPen blue(Qt::blue);
19 blue.setWidth(3);
19 blue.setWidth(3);
20 m_series0->setPen(blue);
20 m_series0->setPen(blue);
21
21
22
22
23 m_series1 = new QSplineSeries(this);
23 m_series1 = new QSplineSeries(this);
24 QPen green(Qt::red);
24 QPen green(Qt::red);
25 green.setWidth(3);
25 green.setWidth(3);
26 m_series1->setPen(green);
26 m_series1->setPen(green);
27
27
28 m_series0->add(m_x,m_y);
28 m_series0->append(m_x,m_y);
29 m_series1->add(m_x,m_y);
29 m_series1->append(m_x,m_y);
30
30
31 setChartTitle("Simple EKG chart");
31 setChartTitle("Simple EKG chart");
32 addSeries(m_series0);
32 addSeries(m_series0);
33 addSeries(m_series1);
33 addSeries(m_series1);
34 axisY()->setRange(-5,5);
34 axisY()->setRange(-5,5);
35 axisX()->setRange(-9,1);
35 axisX()->setRange(-9,1);
36 axisX()->setTicksCount(11);
36 axisX()->setTicksCount(11);
37 m_timer.start();
37 m_timer.start();
38 }
38 }
39
39
40 ChartView::~ChartView()
40 ChartView::~ChartView()
41 {
41 {
42
42
43 }
43 }
44
44
45 void ChartView::handleTimeout()
45 void ChartView::handleTimeout()
46 {
46 {
47 m_x+=m_step;
47 m_x+=m_step;
48 m_y = qrand() % 5 - 2.5;
48 m_y = qrand() % 5 - 2.5;
49 m_series0->add(m_x,m_y);
49 m_series0->append(m_x,m_y);
50 m_series1->add(m_x,m_y);
50 m_series1->append(m_x,m_y);
51 if(m_x>=10)
51 if(m_x>=10)
52 {
52 {
53 m_series0->remove(m_x-10);
53 m_series0->remove(m_x-10);
54 m_series1->remove(m_x-10);
54 m_series1->remove(m_x-10);
55 }
55 }
56 scrollRight();
56 scrollRight();
57 }
57 }
@@ -1,89 +1,89
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:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** You may use this file under the terms of the BSD license as follows:
11 **
11 **
12 ** "Redistribution and use in source and binary forms, with or without
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
13 ** modification, are permitted provided that the following conditions are
14 ** met:
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
19 ** the documentation and/or other materials provided with the
20 ** distribution.
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
23 ** software without specific prior written permission.
24 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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."
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
36 ** $QT_END_LICENSE$
37 **
37 **
38 ****************************************************************************/
38 ****************************************************************************/
39
39
40 #include <QApplication>
40 #include <QApplication>
41 #include <QMainWindow>
41 #include <QMainWindow>
42 #include <QChartView>
42 #include <QChartView>
43 #include <QLineSeries>
43 #include <QLineSeries>
44
44
45 QTCOMMERCIALCHART_USE_NAMESPACE
45 QTCOMMERCIALCHART_USE_NAMESPACE
46
46
47 int main(int argc, char *argv[])
47 int main(int argc, char *argv[])
48 {
48 {
49 QApplication a(argc, argv);
49 QApplication a(argc, argv);
50 //![1]
50 //![1]
51 QLineSeries* series0 = new QLineSeries();
51 QLineSeries* series0 = new QLineSeries();
52 QPen blue(Qt::blue);
52 QPen blue(Qt::blue);
53 blue.setWidth(3);
53 blue.setWidth(3);
54 series0->setPen(blue);
54 series0->setPen(blue);
55
55
56 QLineSeries* series1 = new QLineSeries();
56 QLineSeries* series1 = new QLineSeries();
57 QPen red(Qt::red);
57 QPen red(Qt::red);
58 red.setWidth(3);
58 red.setWidth(3);
59 series1->setPen(red);
59 series1->setPen(red);
60 //![1]
60 //![1]
61
61
62 //![2]
62 //![2]
63 series0->add(0, 6);
63 series0->append(0, 6);
64 series0->add(2, 4);
64 series0->append(2, 4);
65 series0->add(3, 8);
65 series0->append(3, 8);
66 series0->add(7, 4);
66 series0->append(7, 4);
67 series0->add(10, 5);
67 series0->append(10, 5);
68
68
69 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
69 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
70 //![2]
70 //![2]
71 //![3]
71 //![3]
72 QChart* chart = new QChart();
72 QChart* chart = new QChart();
73
73
74 chart->addSeries(series0);
74 chart->addSeries(series0);
75 chart->addSeries(series1);
75 chart->addSeries(series1);
76 chart->setTitle("Simple line chart example");
76 chart->setTitle("Simple line chart example");
77 //![3]
77 //![3]
78 //![4]
78 //![4]
79 QChartView* chartView = new QChartView(chart);
79 QChartView* chartView = new QChartView(chart);
80 chartView->setRenderHint(QPainter::Antialiasing);
80 chartView->setRenderHint(QPainter::Antialiasing);
81 //![4]
81 //![4]
82 //![5]
82 //![5]
83 QMainWindow window;
83 QMainWindow window;
84 window.setCentralWidget(chartView);
84 window.setCentralWidget(chartView);
85 window.resize(400, 300);
85 window.resize(400, 300);
86 window.show();
86 window.show();
87 //![5]
87 //![5]
88 return a.exec();
88 return a.exec();
89 }
89 }
@@ -1,35 +1,35
1 #include "multichartwidget.h"
1 #include "multichartwidget.h"
2 #include <QVBoxLayout>
2 #include <QVBoxLayout>
3 #include <qchartglobal.h>
3 #include <qchartglobal.h>
4 #include <qchartview.h>
4 #include <qchartview.h>
5 #include <qscatterseries.h>
5 #include <qscatterseries.h>
6 #include <qpieseries.h>
6 #include <qpieseries.h>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
10 MultiChartWidget::MultiChartWidget(QWidget *parent) :
10 MultiChartWidget::MultiChartWidget(QWidget *parent) :
11 QWidget(parent)
11 QWidget(parent)
12 {
12 {
13 QVBoxLayout *l = new QVBoxLayout(this);
13 QVBoxLayout *l = new QVBoxLayout(this);
14
14
15 // Create chart 1 and add a simple pie series onto it
15 // Create chart 1 and add a simple pie series onto it
16 QChartView *chartView1 = new QChartView();
16 QChartView *chartView1 = new QChartView();
17 l->addWidget(chartView1);
17 l->addWidget(chartView1);
18 QPieSeries *pie = new QPieSeries();
18 QPieSeries *pie = new QPieSeries();
19 pie->add(1.1, "label1");
19 pie->append(1.1, "label1");
20 pie->add(1.2, "label2");
20 pie->append(1.2, "label2");
21 chartView1->addSeries(pie);
21 chartView1->addSeries(pie);
22
22
23 // Create chart 2 and add a simple scatter series onto it
23 // Create chart 2 and add a simple scatter series onto it
24 QChartView *chartView2 = new QChartView();
24 QChartView *chartView2 = new QChartView();
25 l->addWidget(chartView2);
25 l->addWidget(chartView2);
26 QScatterSeries *scatter = new QScatterSeries();
26 QScatterSeries *scatter = new QScatterSeries();
27 *scatter << QPointF(0.5, 5.0)
27 *scatter << QPointF(0.5, 5.0)
28 << QPointF(1.0, 4.5)
28 << QPointF(1.0, 4.5)
29 << QPointF(1.0, 5.5)
29 << QPointF(1.0, 5.5)
30 << QPointF(1.5, 5.0)
30 << QPointF(1.5, 5.0)
31 << QPointF(2.0, 4.5)
31 << QPointF(2.0, 4.5)
32 << QPointF(2.0, 5.5)
32 << QPointF(2.0, 5.5)
33 << QPointF(2.5, 5.0);
33 << QPointF(2.5, 5.0);
34 chartView2->addSeries(scatter);
34 chartView2->addSeries(scatter);
35 }
35 }
@@ -1,84 +1,84
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:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** You may use this file under the terms of the BSD license as follows:
11 **
11 **
12 ** "Redistribution and use in source and binary forms, with or without
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
13 ** modification, are permitted provided that the following conditions are
14 ** met:
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
19 ** the documentation and/or other materials provided with the
20 ** distribution.
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
23 ** software without specific prior written permission.
24 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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."
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
36 ** $QT_END_LICENSE$
37 **
37 **
38 ****************************************************************************/
38 ****************************************************************************/
39
39
40 #include <QApplication>
40 #include <QApplication>
41 #include <QMainWindow>
41 #include <QMainWindow>
42 #include <QChartView>
42 #include <QChartView>
43 #include <QPieSeries>
43 #include <QPieSeries>
44 #include <QPieSlice>
44 #include <QPieSlice>
45
45
46 QTCOMMERCIALCHART_USE_NAMESPACE
46 QTCOMMERCIALCHART_USE_NAMESPACE
47
47
48 int main(int argc, char *argv[])
48 int main(int argc, char *argv[])
49 {
49 {
50 QApplication a(argc, argv);
50 QApplication a(argc, argv);
51
51
52 //![1]
52 //![1]
53 QPieSeries *series = new QPieSeries();
53 QPieSeries *series = new QPieSeries();
54 series->add(1, "Slice 1");
54 series->append(1, "Slice 1");
55 series->add(2, "Slice 2");
55 series->append(2, "Slice 2");
56 series->add(3, "Slice 3");
56 series->append(3, "Slice 3");
57 series->add(4, "Slice 4");
57 series->append(4, "Slice 4");
58 series->add(5, "Slice 5");
58 series->append(5, "Slice 5");
59 //![1]
59 //![1]
60
60
61 //![2]
61 //![2]
62 QPieSlice *slice = series->slices().first();
62 QPieSlice *slice = series->slices().first();
63 slice->setExploded();
63 slice->setExploded();
64 slice->setLabelVisible();
64 slice->setLabelVisible();
65 slice->setPen(QPen(Qt::darkGreen, 2));
65 slice->setPen(QPen(Qt::darkGreen, 2));
66 slice->setBrush(Qt::green);
66 slice->setBrush(Qt::green);
67 //![2]
67 //![2]
68 //![3]
68 //![3]
69 QChart* chart = new QChart();
69 QChart* chart = new QChart();
70 chart->addSeries(series);
70 chart->addSeries(series);
71 chart->setTitle("Simple piechart example");
71 chart->setTitle("Simple piechart example");
72 //![3]
72 //![3]
73 //![4]
73 //![4]
74 QChartView* chartView = new QChartView(chart);
74 QChartView* chartView = new QChartView(chart);
75 chartView->setRenderHint(QPainter::Antialiasing);
75 chartView->setRenderHint(QPainter::Antialiasing);
76 //![4]
76 //![4]
77 //![5]
77 //![5]
78 QMainWindow window;
78 QMainWindow window;
79 window.setCentralWidget(chartView);
79 window.setCentralWidget(chartView);
80 window.resize(400, 300);
80 window.resize(400, 300);
81 window.show();
81 window.show();
82 //![5]
82 //![5]
83 return a.exec();
83 return a.exec();
84 }
84 }
@@ -1,97 +1,97
1 #include "chartview.h"
1 #include "chartview.h"
2 #include <QLineSeries>
2 #include <QLineSeries>
3 #include <QScatterSeries>
3 #include <QScatterSeries>
4 #include <QSplineSeries>
4 #include <QSplineSeries>
5 #include <QAreaSeries>
5 #include <QAreaSeries>
6 #include <QTime>
6 #include <QTime>
7
7
8 ChartView::ChartView(QWidget* parent):QChartView(parent),
8 ChartView::ChartView(QWidget* parent):QChartView(parent),
9 m_index(0)
9 m_index(0)
10 {
10 {
11 setChartTitle("Charts presenter");
11 setChartTitle("Charts presenter");
12 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
12 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
13 m_timer.setInterval(3000);
13 m_timer.setInterval(3000);
14
14
15 //![1]
15 //![1]
16 QLineSeries* series0 = new QLineSeries(this);
16 QLineSeries* series0 = new QLineSeries(this);
17 QPen blue(Qt::blue);
17 QPen blue(Qt::blue);
18 blue.setWidth(3);
18 blue.setWidth(3);
19 series0->setPen(blue);
19 series0->setPen(blue);
20
20
21 QScatterSeries* series1 = new QScatterSeries(this);
21 QScatterSeries* series1 = new QScatterSeries(this);
22 QPen red(Qt::red);
22 QPen red(Qt::red);
23 red.setWidth(3);
23 red.setWidth(3);
24 series1->setPen(red);
24 series1->setPen(red);
25 series1->setBrush(Qt::white);
25 series1->setBrush(Qt::white);
26
26
27 QSplineSeries* series2 = new QSplineSeries(this);
27 QSplineSeries* series2 = new QSplineSeries(this);
28 QPen green(Qt::green);
28 QPen green(Qt::green);
29 green.setWidth(3);
29 green.setWidth(3);
30 series2->setPen(green);
30 series2->setPen(green);
31
31
32 QAreaSeries* series3 = new QAreaSeries(series0);
32 QAreaSeries* series3 = new QAreaSeries(series0);
33 QPen yellow(Qt::black);
33 QPen yellow(Qt::black);
34 yellow.setWidth(3);
34 yellow.setWidth(3);
35 series3->setPen(yellow);
35 series3->setPen(yellow);
36 series3->setBrush(Qt::yellow);
36 series3->setBrush(Qt::yellow);
37 //![1]
37 //![1]
38
38
39 //![2]
39 //![2]
40 int numPoints = 10;
40 int numPoints = 10;
41
41
42 for (int x = 0; x <= numPoints; ++x) {
42 for (int x = 0; x <= numPoints; ++x) {
43 qreal y = qrand() % 100;
43 qreal y = qrand() % 100;
44 series0->add(x,y);
44 series0->append(x,y);
45 series1->add(x,y);
45 series1->append(x,y);
46 series2->add(x,y);
46 series2->append(x,y);
47 }
47 }
48 //![2]
48 //![2]
49
49
50 //![3]
50 //![3]
51 m_series<<series0;
51 m_series<<series0;
52 m_titles<<chartTitle()+": LineChart";
52 m_titles<<chartTitle()+": LineChart";
53 m_series<<series1;
53 m_series<<series1;
54 m_titles<<chartTitle()+": ScatterChart";
54 m_titles<<chartTitle()+": ScatterChart";
55 m_series<<series2;
55 m_series<<series2;
56 m_titles<<chartTitle()+": SplineChart";
56 m_titles<<chartTitle()+": SplineChart";
57 m_series<<series3;
57 m_series<<series3;
58 m_titles<<chartTitle()+": AreaChart";
58 m_titles<<chartTitle()+": AreaChart";
59 //![3]
59 //![3]
60
60
61 addSeries(series0);
61 addSeries(series0);
62 setChartTitle(m_titles.at(0));
62 setChartTitle(m_titles.at(0));
63
63
64 //![4]
64 //![4]
65 foreach (QSeries* series, m_series) {
65 foreach (QSeries* series, m_series) {
66 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
66 QObject::connect(series,SIGNAL(clicked(const QPointF&)),this,SLOT(handlePointClicked(const QPointF&)));
67 }
67 }
68 //![4]
68 //![4]
69
69
70 m_timer.start();
70 m_timer.start();
71 }
71 }
72
72
73 ChartView::~ChartView()
73 ChartView::~ChartView()
74 {
74 {
75 if(m_series.size()==0) return;
75 if(m_series.size()==0) return;
76 removeSeries(m_series.at(m_index));
76 removeSeries(m_series.at(m_index));
77 qDeleteAll(m_series);
77 qDeleteAll(m_series);
78 }
78 }
79
79
80 //![5]
80 //![5]
81 void ChartView::handleTimeout()
81 void ChartView::handleTimeout()
82 {
82 {
83 if(m_series.size()==0) return;
83 if(m_series.size()==0) return;
84 removeSeries(m_series.at(m_index));
84 removeSeries(m_series.at(m_index));
85 m_index++;
85 m_index++;
86 m_index=m_index%m_series.size();
86 m_index=m_index%m_series.size();
87 addSeries(m_series.at(m_index));
87 addSeries(m_series.at(m_index));
88 setChartTitle(m_titles.at(m_index));
88 setChartTitle(m_titles.at(m_index));
89 }
89 }
90 //![5]
90 //![5]
91
91
92 //![6]
92 //![6]
93 void ChartView::handlePointClicked(const QPointF& point)
93 void ChartView::handlePointClicked(const QPointF& point)
94 {
94 {
95 setChartTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
95 setChartTitle(m_titles.at(m_index) + QString(" x: %1 y: %2").arg(point.x()).arg(point.y()));
96 }
96 }
97 //![6]
97 //![6]
@@ -1,96 +1,96
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:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
10 ** You may use this file under the terms of the BSD license as follows:
11 **
11 **
12 ** "Redistribution and use in source and binary forms, with or without
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
13 ** modification, are permitted provided that the following conditions are
14 ** met:
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
19 ** the documentation and/or other materials provided with the
20 ** distribution.
20 ** distribution.
21 ** * Neither the name of Digia nor the names of its contributors
21 ** * Neither the name of Digia nor the names of its contributors
22 ** may be used to endorse or promote products derived from this
22 ** may be used to endorse or promote products derived from this
23 ** software without specific prior written permission.
23 ** software without specific prior written permission.
24 **
24 **
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
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."
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36 ** $QT_END_LICENSE$
36 ** $QT_END_LICENSE$
37 **
37 **
38 ****************************************************************************/
38 ****************************************************************************/
39
39
40 #include <QtGui/QApplication>
40 #include <QtGui/QApplication>
41 #include <QMainWindow>
41 #include <QMainWindow>
42 #include <QChartView>
42 #include <QChartView>
43 #include <QScatterSeries>
43 #include <QScatterSeries>
44
44
45 QTCOMMERCIALCHART_USE_NAMESPACE
45 QTCOMMERCIALCHART_USE_NAMESPACE
46
46
47 int main(int argc, char *argv[])
47 int main(int argc, char *argv[])
48 {
48 {
49 QApplication a(argc, argv);
49 QApplication a(argc, argv);
50 //![1]
50 //![1]
51 QPen pen(Qt::black);
51 QPen pen(Qt::black);
52 pen.setWidth(2);
52 pen.setWidth(2);
53 QBrush blue(Qt::blue);
53 QBrush blue(Qt::blue);
54 QBrush red(Qt::red);
54 QBrush red(Qt::red);
55
55
56 QScatterSeries *series0 = new QScatterSeries();
56 QScatterSeries *series0 = new QScatterSeries();
57 series0->setPen(pen);
57 series0->setPen(pen);
58 series0->setBrush(blue);
58 series0->setBrush(blue);
59 series0->setShape(QScatterSeries::MarkerShapeCircle);
59 series0->setShape(QScatterSeries::MarkerShapeCircle);
60 series0->setSize(15.0);
60 series0->setSize(15.0);
61
61
62 QScatterSeries *series1 = new QScatterSeries();
62 QScatterSeries *series1 = new QScatterSeries();
63 series1->setPen(pen);
63 series1->setPen(pen);
64 series1->setBrush(red);
64 series1->setBrush(red);
65 series1->setShape(QScatterSeries::MarkerShapeCircle);
65 series1->setShape(QScatterSeries::MarkerShapeCircle);
66 series1->setSize(15.0);
66 series1->setSize(15.0);
67 //![1]
67 //![1]
68
68
69 //![2]
69 //![2]
70 series0->add(0, 6);
70 series0->append(0, 6);
71 series0->add(2, 4);
71 series0->append(2, 4);
72 series0->add(3, 8);
72 series0->append(3, 8);
73 series0->add(7, 4);
73 series0->append(7, 4);
74 series0->add(10, 5);
74 series0->append(10, 5);
75
75
76 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
76 *series1 << QPointF(1, 1) << QPointF(3, 3) << QPointF(7, 6) << QPointF(8, 3) << QPointF(10, 2);
77 //![2]
77 //![2]
78 //![3]
78 //![3]
79 QChart* chart = new QChart();
79 QChart* chart = new QChart();
80
80
81 chart->addSeries(series0);
81 chart->addSeries(series0);
82 chart->addSeries(series1);
82 chart->addSeries(series1);
83 chart->setTitle("Simple scatterchart example");
83 chart->setTitle("Simple scatterchart example");
84 //![3]
84 //![3]
85 //![4]
85 //![4]
86 QChartView* chartView = new QChartView(chart);
86 QChartView* chartView = new QChartView(chart);
87 chartView->setRenderHint(QPainter::Antialiasing);
87 chartView->setRenderHint(QPainter::Antialiasing);
88 //![4]
88 //![4]
89 //![5]
89 //![5]
90 QMainWindow window;
90 QMainWindow window;
91 window.setCentralWidget(chartView);
91 window.setCentralWidget(chartView);
92 window.resize(400, 300);
92 window.resize(400, 300);
93 window.show();
93 window.show();
94 //![5]
94 //![5]
95 return a.exec();
95 return a.exec();
96 }
96 }
@@ -1,116 +1,116
1 #include "splinewidget.h"
1 #include "splinewidget.h"
2 #include "qchartview.h"
2 #include "qchartview.h"
3 #include "qlineseries.h"
3 #include "qlineseries.h"
4 #include <QGridLayout>
4 #include <QGridLayout>
5 #include <QPushButton>
5 #include <QPushButton>
6 #include "qchartaxis.h"
6 #include "qchartaxis.h"
7 #include <qmath.h>
7 #include <qmath.h>
8 #include <QTime>
8 #include <QTime>
9
9
10 QTCOMMERCIALCHART_USE_NAMESPACE
10 QTCOMMERCIALCHART_USE_NAMESPACE
11
11
12 SplineWidget::SplineWidget(QWidget *parent)
12 SplineWidget::SplineWidget(QWidget *parent)
13 : QWidget(parent)
13 : QWidget(parent)
14 {
14 {
15 // qsrand(time(NULL));
15 // qsrand(time(NULL));
16 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
16 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
17 //! [1]
17 //! [1]
18 //create QSplineSeries
18 //create QSplineSeries
19 series = new QSplineSeries(this);
19 series = new QSplineSeries(this);
20 //! [1]
20 //! [1]
21
21
22 //! [2]
22 //! [2]
23 // customize the series presentation settings
23 // customize the series presentation settings
24 QPen seriesPen(Qt::blue);
24 QPen seriesPen(Qt::blue);
25 seriesPen.setWidth(3);
25 seriesPen.setWidth(3);
26 // series->setPen(seriesPen);
26 // series->setPen(seriesPen);
27 //! [2]
27 //! [2]
28
28
29 //! [add points to series]
29 //! [add points to series]
30 //add data points to the series
30 //add data points to the series
31 series->add(QPointF(150, 100));
31 series->append(QPointF(150, 100));
32 series->add(QPointF(200, 130));
32 series->append(QPointF(200, 130));
33 series->add(QPointF(250, 120));
33 series->append(QPointF(250, 120));
34 series->add(QPointF(300, 140));
34 series->append(QPointF(300, 140));
35 series->add(QPointF(350, 160));
35 series->append(QPointF(350, 160));
36 //! [add points to series]
36 //! [add points to series]
37
37
38 QSplineSeries* series2 = new QSplineSeries;
38 QSplineSeries* series2 = new QSplineSeries;
39
39
40 series2->add(QPointF(400, 120));
40 series2->append(QPointF(400, 120));
41 series2->add(QPointF(450, 150));
41 series2->append(QPointF(450, 150));
42 series2->add(QPointF(500, 145));
42 series2->append(QPointF(500, 145));
43 series2->add(QPointF(550, 170));
43 series2->append(QPointF(550, 170));
44
44
45 // series->add(QPointF(600, 190));
45 // series->append(QPointF(600, 190));
46 // series->add(QPointF(650, 210));
46 // series->append(QPointF(650, 210));
47 // series->add(QPointF(700, 190));
47 // series->append(QPointF(700, 190));
48 // series->add(QPointF(750, 180));
48 // series->append(QPointF(750, 180));
49 // series->add(QPointF(800, 170));
49 // series->append(QPointF(800, 170));
50 QSplineSeries* series3 = new QSplineSeries;
50 QSplineSeries* series3 = new QSplineSeries;
51 series3->add(QPointF(600, 190));
51 series3->append(QPointF(600, 190));
52 series3->add(QPointF(650, 210));
52 series3->append(QPointF(650, 210));
53 series3->add(QPointF(700, 190));
53 series3->append(QPointF(700, 190));
54 series3->add(QPointF(750, 180));
54 series3->append(QPointF(750, 180));
55 series3->add(QPointF(800, 170));
55 series3->append(QPointF(800, 170));
56
56
57 //! [3]
57 //! [3]
58 // create chart view
58 // create chart view
59 QChartView* chart = new QChartView;
59 QChartView* chart = new QChartView;
60 chart->addSeries(series);
60 chart->addSeries(series);
61 chart->addSeries(series2);
61 chart->addSeries(series2);
62 chart->addSeries(series3);
62 chart->addSeries(series3);
63
63
64 chart->setChartTitle("Spline chart example");
64 chart->setChartTitle("Spline chart example");
65 chart->axisX()->setMax(1500);
65 chart->axisX()->setMax(1500);
66 chart->axisY()->setMax(500);
66 chart->axisY()->setMax(500);
67
67
68 chart->setMinimumSize(800,600);
68 chart->setMinimumSize(800,600);
69 //! [3]
69 //! [3]
70
70
71 //! [4]
71 //! [4]
72 //add new data point button
72 //add new data point button
73 QPushButton* addButton = new QPushButton("Add new point");
73 QPushButton* addButton = new QPushButton("Add new point");
74 connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint()));
74 connect(addButton, SIGNAL(clicked()), this, SLOT(addNewPoint()));
75
75
76 // remove the last data point in the series
76 // remove the last data point in the series
77 QPushButton* removeButton = new QPushButton("Remove point");
77 QPushButton* removeButton = new QPushButton("Remove point");
78 connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint()));
78 connect(removeButton, SIGNAL(clicked()), this, SLOT(removePoint()));
79 //! [4]
79 //! [4]
80
80
81 //! [5]
81 //! [5]
82 //butttons layout
82 //butttons layout
83 QVBoxLayout* buttonsLayout = new QVBoxLayout;
83 QVBoxLayout* buttonsLayout = new QVBoxLayout;
84 buttonsLayout->addWidget(addButton);
84 buttonsLayout->addWidget(addButton);
85 buttonsLayout->addWidget(removeButton);
85 buttonsLayout->addWidget(removeButton);
86 buttonsLayout->addStretch();
86 buttonsLayout->addStretch();
87
87
88 QGridLayout* mainLayout = new QGridLayout;
88 QGridLayout* mainLayout = new QGridLayout;
89 mainLayout->addWidget(chart, 1, 0);
89 mainLayout->addWidget(chart, 1, 0);
90 mainLayout->addLayout(buttonsLayout, 1, 1);
90 mainLayout->addLayout(buttonsLayout, 1, 1);
91 setLayout(mainLayout);
91 setLayout(mainLayout);
92 //! [5]
92 //! [5]
93 }
93 }
94
94
95 //! [add point]
95 //! [add point]
96 void SplineWidget::addNewPoint()
96 void SplineWidget::addNewPoint()
97 {
97 {
98 if (series->count() > 0)
98 if (series->count() > 0)
99 series->add(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100)));
99 series->append(QPointF(series->x(series->count() - 1) + 40 + qrand()%40, qAbs(series->y(series->count() - 1) - 50 + qrand()%100)));
100 else
100 else
101 series->add(QPointF(50, 50 + qrand()%50));
101 series->append(QPointF(50, 50 + qrand()%50));
102 }
102 }
103 //! [add point]
103 //! [add point]
104
104
105 //! [remove point]
105 //! [remove point]
106 void SplineWidget::removePoint()
106 void SplineWidget::removePoint()
107 {
107 {
108 if (series->count() > 0)
108 if (series->count() > 0)
109 series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1)));
109 series->remove(QPointF(series->x(series->count() - 1), series->y(series->count() - 1)));
110 }
110 }
111 //! [remove point]
111 //! [remove point]
112
112
113 SplineWidget::~SplineWidget()
113 SplineWidget::~SplineWidget()
114 {
114 {
115
115
116 }
116 }
@@ -1,43 +1,43
1 #include "declarativepieseries.h"
1 #include "declarativepieseries.h"
2 #include "declarativechart.h"
2 #include "declarativechart.h"
3 #include "qchart.h"
3 #include "qchart.h"
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
7 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) :
8 QPieSeries(parent),
8 QPieSeries(parent),
9 m_chart(0)
9 m_chart(0)
10 {
10 {
11 }
11 }
12
12
13 void DeclarativePieSeries::classBegin()
13 void DeclarativePieSeries::classBegin()
14 {
14 {
15 }
15 }
16
16
17 void DeclarativePieSeries::componentComplete()
17 void DeclarativePieSeries::componentComplete()
18 {
18 {
19 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
19 DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent());
20 if (declarativeChart) {
20 if (declarativeChart) {
21 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
21 QChart *chart = qobject_cast<QChart *>(declarativeChart->m_chart);
22 Q_ASSERT(chart);
22 Q_ASSERT(chart);
23 qDebug() << "parent for pie:" << chart;
23 qDebug() << "parent for pie:" << chart;
24 chart->addSeries(this);
24 chart->addSeries(this);
25 }
25 }
26 }
26 }
27
27
28 QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices()
28 QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::slices()
29 {
29 {
30 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice);
30 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendSlice);
31 }
31 }
32
32
33 void DeclarativePieSeries::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
33 void DeclarativePieSeries::appendSlice(QDeclarativeListProperty<QPieSlice> *list,
34 QPieSlice *slice)
34 QPieSlice *slice)
35 {
35 {
36 DeclarativePieSeries *series = qobject_cast<DeclarativePieSeries *>(list->object);
36 DeclarativePieSeries *series = qobject_cast<DeclarativePieSeries *>(list->object);
37 if (series)
37 if (series)
38 series->add(slice->value(), slice->label());
38 series->append(slice->value(), slice->label());
39 }
39 }
40
40
41 #include "moc_declarativepieseries.cpp"
41 #include "moc_declarativepieseries.cpp"
42
42
43 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,27 +1,27
1 //#include "DeclarativeXySeries.h"
1 //#include "DeclarativeXySeries.h"
2 #include "declarativexyseries.h"
2 #include "declarativexyseries.h"
3 #include "qxyseries.h"
3 #include "qxyseries.h"
4
4
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
5 QTCOMMERCIALCHART_BEGIN_NAMESPACE
6
6
7 DeclarativeXySeries::DeclarativeXySeries()
7 DeclarativeXySeries::DeclarativeXySeries()
8 {
8 {
9 }
9 }
10
10
11 DeclarativeXySeries::~DeclarativeXySeries()
11 DeclarativeXySeries::~DeclarativeXySeries()
12 {
12 {
13 }
13 }
14
14
15 void DeclarativeXySeries::classBegin()
15 void DeclarativeXySeries::classBegin()
16 {
16 {
17 }
17 }
18
18
19 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
19 void DeclarativeXySeries::appendPoints(QDeclarativeListProperty<DeclarativeXyPoint> *list,
20 DeclarativeXyPoint *element)
20 DeclarativeXyPoint *element)
21 {
21 {
22 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
22 QXYSeries *series = qobject_cast<QXYSeries *>(list->object);
23 if (series)
23 if (series)
24 series->add(QPointF(element->x(), element->y()));
24 series->append(QPointF(element->x(), element->y()));
25 }
25 }
26
26
27 QTCOMMERCIALCHART_END_NAMESPACE
27 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,170 +1,170
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qareaseries.h"
21 #include "qareaseries.h"
22 #include "qlineseries.h"
22 #include "qlineseries.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QAreaSeries
27 \class QAreaSeries
28 \brief The QAreaSeries class is used for making area charts.
28 \brief The QAreaSeries class is used for making area charts.
29
29
30 \mainclass
30 \mainclass
31
31
32 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
32 An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line
33 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
33 is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance,
34 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
34 which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line.
35 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
35 In that case QAreaSeries should be initiated with two QLineSerie instances. Please note terms "upper" and "lower" boundary can be misleading in cases
36 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
36 where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled.
37
37
38 \image areachart.png
38 \image areachart.png
39
39
40 Creating basic area chart is simple:
40 Creating basic area chart is simple:
41 \code
41 \code
42 QLineSeries* lineSeries = new QLineSeries();
42 QLineSeries* lineSeries = new QLineSeries();
43 series->add(0, 6);
43 series->append(0, 6);
44 series->add(2, 4);
44 series->append(2, 4);
45 QAreaSeries* areaSeries = new QAreaSeries(lineSeries);
45 QAreaSeries* areaSeries = new QAreaSeries(lineSeries);
46 ...
46 ...
47 chartView->addSeries(areaSeries);
47 chartView->addSeries(areaSeries);
48 \endcode
48 \endcode
49 */
49 */
50
50
51 /*!
51 /*!
52 \fn virtual QSeriesType QAreaSeries::type() const
52 \fn virtual QSeriesType QAreaSeries::type() const
53 \brief Returns type of series.
53 \brief Returns type of series.
54 \sa QSeries, QSeriesType
54 \sa QSeries, QSeriesType
55 */
55 */
56
56
57 /*!
57 /*!
58 \fn QLineSeries* QAreaSeries::upperSeries() const
58 \fn QLineSeries* QAreaSeries::upperSeries() const
59 \brief Returns upperSeries used to define one of area boundaries.
59 \brief Returns upperSeries used to define one of area boundaries.
60 */
60 */
61
61
62 /*!
62 /*!
63 \fn QLineSeries* QAreaSeries::lowerSeries() const
63 \fn QLineSeries* QAreaSeries::lowerSeries() const
64 \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries
64 \brief Returns lowerSeries used to define one of area boundaries. Note if QAreaSeries where counstucted wihtout a\ lowerSeries
65 this function return Null pointer.
65 this function return Null pointer.
66 */
66 */
67
67
68 /*!
68 /*!
69 \fn QPen QAreaSeries::pen() const
69 \fn QPen QAreaSeries::pen() const
70 \brief Returns the pen used to draw line for this series.
70 \brief Returns the pen used to draw line for this series.
71 \sa setPen()
71 \sa setPen()
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn QPen QAreaSeries::brush() const
75 \fn QPen QAreaSeries::brush() const
76 \brief Returns the brush used to draw line for this series.
76 \brief Returns the brush used to draw line for this series.
77 \sa setBrush()
77 \sa setBrush()
78 */
78 */
79
79
80 /*!
80 /*!
81 \fn bool QAreaSeries::pointsVisible() const
81 \fn bool QAreaSeries::pointsVisible() const
82 \brief Returns if the points are drawn for this series.
82 \brief Returns if the points are drawn for this series.
83 \sa setPointsVisible()
83 \sa setPointsVisible()
84 */
84 */
85
85
86 /*!
86 /*!
87 \fn void QAreaSeries::clicked(const QPointF& point)
87 \fn void QAreaSeries::clicked(const QPointF& point)
88 \brief Signal is emitted when user clicks the \a point on area chart.
88 \brief Signal is emitted when user clicks the \a point on area chart.
89 */
89 */
90
90
91 /*!
91 /*!
92 \fn void QAreaSeries::updated()
92 \fn void QAreaSeries::updated()
93 \brief \internal
93 \brief \internal
94 */
94 */
95
95
96 /*!
96 /*!
97 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
97 Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a
98 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
98 upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead.
99 When series object is added to QChartView or QChart instance ownerships is transfered.
99 When series object is added to QChartView or QChart instance ownerships is transfered.
100 */
100 */
101 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
101 QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries)
102 : QSeries(upperSeries),
102 : QSeries(upperSeries),
103 m_upperSeries(upperSeries),
103 m_upperSeries(upperSeries),
104 m_lowerSeries(lowerSeries),
104 m_lowerSeries(lowerSeries),
105 m_pointsVisible(false)
105 m_pointsVisible(false)
106 {
106 {
107 }
107 }
108
108
109 /*!
109 /*!
110 Destroys the object. Series added to QChartView or QChart instances are owned by those,
110 Destroys the object. Series added to QChartView or QChart instances are owned by those,
111 and are deleted when mentioned object are destroyed.
111 and are deleted when mentioned object are destroyed.
112 */
112 */
113 QAreaSeries::~QAreaSeries()
113 QAreaSeries::~QAreaSeries()
114 {
114 {
115 }
115 }
116
116
117 /*!
117 /*!
118 Sets \a pen used for drawing area outline.
118 Sets \a pen used for drawing area outline.
119 */
119 */
120 void QAreaSeries::setPen(const QPen &pen)
120 void QAreaSeries::setPen(const QPen &pen)
121 {
121 {
122 if (m_pen != pen) {
122 if (m_pen != pen) {
123 m_pen = pen;
123 m_pen = pen;
124 emit updated();
124 emit updated();
125 }
125 }
126 }
126 }
127
127
128 /*!
128 /*!
129 Sets \a brush used for filling the area.
129 Sets \a brush used for filling the area.
130 */
130 */
131 void QAreaSeries::setBrush(const QBrush &brush)
131 void QAreaSeries::setBrush(const QBrush &brush)
132 {
132 {
133 if (m_brush != brush) {
133 if (m_brush != brush) {
134 m_brush = brush;
134 m_brush = brush;
135 emit updated();
135 emit updated();
136 }
136 }
137 }
137 }
138 /*!
138 /*!
139 Sets if data points are \a visible and should be drawn on line.
139 Sets if data points are \a visible and should be drawn on line.
140 */
140 */
141 void QAreaSeries::setPointsVisible(bool visible)
141 void QAreaSeries::setPointsVisible(bool visible)
142 {
142 {
143 if (m_pointsVisible != visible) {
143 if (m_pointsVisible != visible) {
144 m_pointsVisible = visible;
144 m_pointsVisible = visible;
145 emit updated();
145 emit updated();
146 }
146 }
147 }
147 }
148
148
149 //bool QAreaSeries::setModel(QAbstractItemModel* model)
149 //bool QAreaSeries::setModel(QAbstractItemModel* model)
150 //{
150 //{
151 // m_upperSeries->setModel(model);
151 // m_upperSeries->setModel(model);
152 // if (m_lowerSeries)
152 // if (m_lowerSeries)
153 // m_lowerSeries->setModel(model);
153 // m_lowerSeries->setModel(model);
154 // return true;
154 // return true;
155 //}
155 //}
156
156
157 //void QAreaSeries::setModelMappingUpper(int modelX, int modelY, Qt::Orientation orientation)
157 //void QAreaSeries::setModelMappingUpper(int modelX, int modelY, Qt::Orientation orientation)
158 //{
158 //{
159 // m_upperSeries->setModelMapping(modelX, modelY, orientation);
159 // m_upperSeries->setModelMapping(modelX, modelY, orientation);
160 //}
160 //}
161
161
162 //void QAreaSeries::setModelMappingLower(int modelX, int modelY, Qt::Orientation orientation)
162 //void QAreaSeries::setModelMappingLower(int modelX, int modelY, Qt::Orientation orientation)
163 //{
163 //{
164 // if (m_lowerSeries)
164 // if (m_lowerSeries)
165 // m_lowerSeries->setModelMapping(modelX, modelY, orientation);
165 // m_lowerSeries->setModelMapping(modelX, modelY, orientation);
166 //}
166 //}
167
167
168 #include "moc_qareaseries.cpp"
168 #include "moc_qareaseries.cpp"
169
169
170 QTCOMMERCIALCHART_END_NAMESPACE
170 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,105 +1,105
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qlineseries.h"
21 #include "qlineseries.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QLineSeries
26 \class QLineSeries
27 \brief The QLineSeries class is used for making line charts.
27 \brief The QLineSeries class is used for making line charts.
28
28
29 \mainclass
29 \mainclass
30
30
31 A line chart is used to show information as a series of data points
31 A line chart is used to show information as a series of data points
32 connected by straight lines.
32 connected by straight lines.
33
33
34 \image linechart.png
34 \image linechart.png
35
35
36 Creating basic line chart is simple:
36 Creating basic line chart is simple:
37 \code
37 \code
38 QLineSeries* series = new QLineSeries();
38 QLineSeries* series = new QLineSeries();
39 series->add(0, 6);
39 series->append(0, 6);
40 series->add(2, 4);
40 series->append(2, 4);
41 ...
41 ...
42 chartView->addSeries(series);
42 chartView->addSeries(series);
43 \endcode
43 \endcode
44 */
44 */
45
45
46 /*!
46 /*!
47 \fn virtual QSeriesType QLineSeries::type() const
47 \fn virtual QSeriesType QLineSeries::type() const
48 \brief Returns type of series.
48 \brief Returns type of series.
49 \sa QSeries, QSeriesType
49 \sa QSeries, QSeriesType
50 */
50 */
51
51
52 /*!
52 /*!
53 \fn bool QLineSeries::pointsVisible() const
53 \fn bool QLineSeries::pointsVisible() const
54 \brief Returns if the points are drawn for this series.
54 \brief Returns if the points are drawn for this series.
55 \sa setPointsVisible()
55 \sa setPointsVisible()
56 */
56 */
57
57
58 /*!
58 /*!
59 \fn QPen QLineSeries::linePen() const
59 \fn QPen QLineSeries::linePen() const
60 \brief Returns the pen used to draw line connecting points.
60 \brief Returns the pen used to draw line connecting points.
61 \sa setPen()
61 \sa setPen()
62 */
62 */
63
63
64 /*!
64 /*!
65 Constructs empty series object which is a child of \a parent.
65 Constructs empty series object which is a child of \a parent.
66 When series object is added to QChartView or QChart instance ownerships is transfered.
66 When series object is added to QChartView or QChart instance ownerships is transfered.
67 */
67 */
68 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(parent),
68 QLineSeries::QLineSeries(QObject *parent) : QXYSeries(parent),
69 m_pointsVisible(false)
69 m_pointsVisible(false)
70 {
70 {
71
71
72 }
72 }
73 /*!
73 /*!
74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
74 Destroys the object. Series added to QChartView or QChart instances are owned by those,
75 and are deleted when mentioned object are destroyed.
75 and are deleted when mentioned object are destroyed.
76 */
76 */
77 QLineSeries::~QLineSeries()
77 QLineSeries::~QLineSeries()
78 {
78 {
79 }
79 }
80
80
81 /*!
81 /*!
82 Sets if data points are \a visible and should be drawn on line.
82 Sets if data points are \a visible and should be drawn on line.
83 */
83 */
84 void QLineSeries::setPointsVisible(bool visible)
84 void QLineSeries::setPointsVisible(bool visible)
85 {
85 {
86 if (m_pointsVisible != visible){
86 if (m_pointsVisible != visible){
87 m_pointsVisible = visible;
87 m_pointsVisible = visible;
88 emit QXYSeries::updated();
88 emit QXYSeries::updated();
89 }
89 }
90 }
90 }
91
91
92
92
93 QDebug operator<< (QDebug debug, const QLineSeries series)
93 QDebug operator<< (QDebug debug, const QLineSeries series)
94 {
94 {
95 Q_ASSERT(series.m_x.size() == series.m_y.size());
95 Q_ASSERT(series.m_x.size() == series.m_y.size());
96
96
97 int size = series.m_x.size();
97 int size = series.m_x.size();
98
98
99 for (int i=0; i<size; i++) {
99 for (int i=0; i<size; i++) {
100 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
100 debug.nospace() << "(" << series.m_x.at(i) << ','<< series.m_y.at(i) << ") ";
101 }
101 }
102 return debug.space();
102 return debug.space();
103 }
103 }
104
104
105 QTCOMMERCIALCHART_END_NAMESPACE
105 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,657 +1,657
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpieseries.h"
21 #include "qpieseries.h"
22 #include "qpiesliceprivate_p.h"
22 #include "qpiesliceprivate_p.h"
23 #include "qpieseriesprivate_p.h"
23 #include "qpieseriesprivate_p.h"
24 #include <QDebug>
24 #include <QDebug>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent)
28 QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent)
29 :QObject(parent),
29 :QObject(parent),
30 q_ptr(parent),
30 q_ptr(parent),
31 m_pieRelativeHorPos(0.5),
31 m_pieRelativeHorPos(0.5),
32 m_pieRelativeVerPos(0.5),
32 m_pieRelativeVerPos(0.5),
33 m_pieRelativeSize(0.7),
33 m_pieRelativeSize(0.7),
34 m_pieStartAngle(0),
34 m_pieStartAngle(0),
35 m_pieEndAngle(360),
35 m_pieEndAngle(360),
36 m_total(0)
36 m_total(0)
37 {
37 {
38
38
39 }
39 }
40
40
41 QPieSeriesPrivate::~QPieSeriesPrivate()
41 QPieSeriesPrivate::~QPieSeriesPrivate()
42 {
42 {
43
43
44 }
44 }
45
45
46 void QPieSeriesPrivate::updateDerivativeData()
46 void QPieSeriesPrivate::updateDerivativeData()
47 {
47 {
48 m_total = 0;
48 m_total = 0;
49
49
50 // nothing to do?
50 // nothing to do?
51 if (m_slices.count() == 0)
51 if (m_slices.count() == 0)
52 return;
52 return;
53
53
54 // calculate total
54 // calculate total
55 foreach (QPieSlice* s, m_slices)
55 foreach (QPieSlice* s, m_slices)
56 m_total += s->value();
56 m_total += s->value();
57
57
58 // nothing to show..
58 // nothing to show..
59 if (qFuzzyIsNull(m_total))
59 if (qFuzzyIsNull(m_total))
60 return;
60 return;
61
61
62 // update slice attributes
62 // update slice attributes
63 qreal sliceAngle = m_pieStartAngle;
63 qreal sliceAngle = m_pieStartAngle;
64 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
64 qreal pieSpan = m_pieEndAngle - m_pieStartAngle;
65 QVector<QPieSlice*> changed;
65 QVector<QPieSlice*> changed;
66 foreach (QPieSlice* s, m_slices) {
66 foreach (QPieSlice* s, m_slices) {
67
67
68 PieSliceData data = s->data_ptr()->m_data;
68 PieSliceData data = s->data_ptr()->m_data;
69 data.m_percentage = s->value() / m_total;
69 data.m_percentage = s->value() / m_total;
70 data.m_angleSpan = pieSpan * data.m_percentage;
70 data.m_angleSpan = pieSpan * data.m_percentage;
71 data.m_startAngle = sliceAngle;
71 data.m_startAngle = sliceAngle;
72 sliceAngle += data.m_angleSpan;
72 sliceAngle += data.m_angleSpan;
73
73
74 if (s->data_ptr()->m_data != data) {
74 if (s->data_ptr()->m_data != data) {
75 s->data_ptr()->m_data = data;
75 s->data_ptr()->m_data = data;
76 changed << s;
76 changed << s;
77 }
77 }
78 }
78 }
79
79
80 // emit signals
80 // emit signals
81 foreach (QPieSlice* s, changed)
81 foreach (QPieSlice* s, changed)
82 emit s->data_ptr()->changed();
82 emit s->data_ptr()->changed();
83 }
83 }
84
84
85 void QPieSeriesPrivate::sliceChanged()
85 void QPieSeriesPrivate::sliceChanged()
86 {
86 {
87 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
87 Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender())));
88 updateDerivativeData();
88 updateDerivativeData();
89 }
89 }
90
90
91 void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons)
91 void QPieSeriesPrivate::sliceClicked(Qt::MouseButtons buttons)
92 {
92 {
93 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
93 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
94 Q_ASSERT(m_slices.contains(slice));
94 Q_ASSERT(m_slices.contains(slice));
95 Q_Q(QPieSeries);
95 Q_Q(QPieSeries);
96 emit q->clicked(slice, buttons);
96 emit q->clicked(slice, buttons);
97 }
97 }
98
98
99 void QPieSeriesPrivate::sliceHoverEnter()
99 void QPieSeriesPrivate::sliceHoverEnter()
100 {
100 {
101 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
101 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
102 Q_ASSERT(m_slices.contains(slice));
102 Q_ASSERT(m_slices.contains(slice));
103 Q_Q(QPieSeries);
103 Q_Q(QPieSeries);
104 emit q->hoverEnter(slice);
104 emit q->hoverEnter(slice);
105 }
105 }
106
106
107 void QPieSeriesPrivate::sliceHoverLeave()
107 void QPieSeriesPrivate::sliceHoverLeave()
108 {
108 {
109 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
109 QPieSlice* slice = qobject_cast<QPieSlice *>(sender());
110 Q_ASSERT(m_slices.contains(slice));
110 Q_ASSERT(m_slices.contains(slice));
111 Q_Q(QPieSeries);
111 Q_Q(QPieSeries);
112 emit q->hoverLeave(slice);
112 emit q->hoverLeave(slice);
113 }
113 }
114
114
115 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
115 void QPieSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
116 {
116 {
117 Q_UNUSED(bottomRight)
117 Q_UNUSED(bottomRight)
118 Q_Q(QPieSeries);
118 Q_Q(QPieSeries);
119
119
120 if (m_mapOrientation == Qt::Vertical)
120 if (m_mapOrientation == Qt::Vertical)
121 {
121 {
122 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
122 // slices().at(topLeft.row())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
123 if (topLeft.column() == m_mapValues)
123 if (topLeft.column() == m_mapValues)
124 if (m_mapValues == m_mapLabels)
124 if (m_mapValues == m_mapLabels)
125 {
125 {
126 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
126 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
127 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
127 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
128 }
128 }
129 else
129 else
130 {
130 {
131 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
131 m_slices.at(topLeft.row())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
132 }
132 }
133 else if (topLeft.column() == m_mapLabels)
133 else if (topLeft.column() == m_mapLabels)
134 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
134 m_slices.at(topLeft.row())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
135 }
135 }
136 else
136 else
137 {
137 {
138 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
138 // slices().at(topLeft.column())->setValue(m_model->data(m_model->index(topLeft.row(), topLeft.column()), Qt::DisplayRole).toDouble());
139 if (topLeft.row() == m_mapValues)
139 if (topLeft.row() == m_mapValues)
140 if (m_mapValues == m_mapLabels)
140 if (m_mapValues == m_mapLabels)
141 {
141 {
142 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
142 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
143 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
143 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
144 }
144 }
145 else
145 else
146 {
146 {
147 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
147 m_slices.at(topLeft.column())->setValue(q->m_model->data(topLeft, Qt::DisplayRole).toDouble());
148 }
148 }
149 else if (topLeft.row() == m_mapLabels)
149 else if (topLeft.row() == m_mapLabels)
150 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
150 m_slices.at(topLeft.column())->setLabel(q->m_model->data(topLeft, Qt::DisplayRole).toString());
151 }
151 }
152 }
152 }
153
153
154 void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
154 void QPieSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end)
155 {
155 {
156 Q_UNUSED(parent)
156 Q_UNUSED(parent)
157 Q_UNUSED(end)
157 Q_UNUSED(end)
158 Q_Q(QPieSeries);
158 Q_Q(QPieSeries);
159
159
160 QPieSlice* newSlice = new QPieSlice;
160 QPieSlice* newSlice = new QPieSlice;
161 newSlice->setLabelVisible(true);
161 newSlice->setLabelVisible(true);
162 if (m_mapOrientation == Qt::Vertical)
162 if (m_mapOrientation == Qt::Vertical)
163 {
163 {
164 newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
164 newSlice->setValue(q->m_model->data(q->m_model->index(start, m_mapValues), Qt::DisplayRole).toDouble());
165 newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
165 newSlice->setLabel(q->m_model->data(q->m_model->index(start, m_mapLabels), Qt::DisplayRole).toString());
166 }
166 }
167 else
167 else
168 {
168 {
169 newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
169 newSlice->setValue(q->m_model->data(q->m_model->index(m_mapValues, start), Qt::DisplayRole).toDouble());
170 newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
170 newSlice->setLabel(q->m_model->data(q->m_model->index(m_mapLabels, start), Qt::DisplayRole).toString());
171 }
171 }
172
172
173 q->insert(start, newSlice);
173 q->insert(start, newSlice);
174 }
174 }
175
175
176 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
176 void QPieSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end)
177 {
177 {
178 Q_UNUSED(parent)
178 Q_UNUSED(parent)
179 Q_UNUSED(end)
179 Q_UNUSED(end)
180 Q_Q(QPieSeries);
180 Q_Q(QPieSeries);
181 q->remove(m_slices.at(start));
181 q->remove(m_slices.at(start));
182 }
182 }
183
183
184
184
185
185
186 /*!
186 /*!
187 \class QPieSeries
187 \class QPieSeries
188 \brief Pie series API for QtCommercial Charts
188 \brief Pie series API for QtCommercial Charts
189
189
190 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
190 The pie series defines a pie chart which consists of pie slices which are QPieSlice objects.
191 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
191 The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices.
192 The actual slice size is determined by that relative value.
192 The actual slice size is determined by that relative value.
193
193
194 By default the pie is defined as a full pie but it can be a partial pie.
194 By default the pie is defined as a full pie but it can be a partial pie.
195 This can be done by setting a starting angle and angle span to the series.
195 This can be done by setting a starting angle and angle span to the series.
196 */
196 */
197
197
198 /*!
198 /*!
199 Constructs a series object which is a child of \a parent.
199 Constructs a series object which is a child of \a parent.
200 */
200 */
201 QPieSeries::QPieSeries(QObject *parent) :
201 QPieSeries::QPieSeries(QObject *parent) :
202 QSeries(parent),
202 QSeries(parent),
203 d_ptr(new QPieSeriesPrivate(this))
203 d_ptr(new QPieSeriesPrivate(this))
204 {
204 {
205
205
206 }
206 }
207
207
208 /*!
208 /*!
209 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
209 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
210 */
210 */
211 QPieSeries::~QPieSeries()
211 QPieSeries::~QPieSeries()
212 {
212 {
213 // NOTE: d_prt destroyed by QObject
213 // NOTE: d_prt destroyed by QObject
214 }
214 }
215
215
216 /*!
216 /*!
217 Returns QChartSeries::SeriesTypePie.
217 Returns QChartSeries::SeriesTypePie.
218 */
218 */
219 QSeries::QSeriesType QPieSeries::type() const
219 QSeries::QSeriesType QPieSeries::type() const
220 {
220 {
221 return QSeries::SeriesTypePie;
221 return QSeries::SeriesTypePie;
222 }
222 }
223
223
224 /*!
224 /*!
225 Sets an array of \a slices to the series replacing the existing slices.
225 Sets an array of \a slices to the series replacing the existing slices.
226 Slice ownership is passed to the series.
226 Slice ownership is passed to the series.
227 */
227 */
228 void QPieSeries::replace(QList<QPieSlice*> slices)
228 void QPieSeries::replace(QList<QPieSlice*> slices)
229 {
229 {
230 clear();
230 clear();
231 add(slices);
231 append(slices);
232 }
232 }
233
233
234 /*!
234 /*!
235 Adds an array of \a slices to the series.
235 Adds an array of \a slices to the series.
236 Slice ownership is passed to the series.
236 Slice ownership is passed to the series.
237 */
237 */
238 void QPieSeries::add(QList<QPieSlice*> slices)
238 void QPieSeries::append(QList<QPieSlice*> slices)
239 {
239 {
240 Q_D(QPieSeries);
240 Q_D(QPieSeries);
241
241
242 foreach (QPieSlice* s, slices) {
242 foreach (QPieSlice* s, slices) {
243 s->setParent(this);
243 s->setParent(this);
244 d->m_slices << s;
244 d->m_slices << s;
245 }
245 }
246
246
247 d->updateDerivativeData();
247 d->updateDerivativeData();
248
248
249 foreach (QPieSlice* s, slices) {
249 foreach (QPieSlice* s, slices) {
250 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
250 connect(s, SIGNAL(changed()), d, SLOT(sliceChanged()));
251 connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
251 connect(s, SIGNAL(clicked(Qt::MouseButtons)), d, SLOT(sliceClicked(Qt::MouseButtons)));
252 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
252 connect(s, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
253 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
253 connect(s, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
254 }
254 }
255
255
256 emit added(slices);
256 emit added(slices);
257 }
257 }
258
258
259 /*!
259 /*!
260 Adds a single \a slice to the series.
260 Adds a single \a slice to the series.
261 Slice ownership is passed to the series.
261 Slice ownership is passed to the series.
262 */
262 */
263 void QPieSeries::add(QPieSlice* slice)
263 void QPieSeries::append(QPieSlice* slice)
264 {
264 {
265 add(QList<QPieSlice*>() << slice);
265 append(QList<QPieSlice*>() << slice);
266 }
266 }
267
267
268 /*!
268 /*!
269 Adds a single \a slice to the series and returns a reference to the series.
269 Adds a single \a slice to the series and returns a reference to the series.
270 Slice ownership is passed to the series.
270 Slice ownership is passed to the series.
271 */
271 */
272 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
272 QPieSeries& QPieSeries::operator << (QPieSlice* slice)
273 {
273 {
274 add(slice);
274 append(slice);
275 return *this;
275 return *this;
276 }
276 }
277
277
278
278
279 /*!
279 /*!
280 Adds a single slice to the series with give \a value and \a name.
280 Adds a single slice to the series with give \a value and \a name.
281 Slice ownership is passed to the series.
281 Slice ownership is passed to the series.
282 */
282 */
283 QPieSlice* QPieSeries::add(qreal value, QString name)
283 QPieSlice* QPieSeries::append(qreal value, QString name)
284 {
284 {
285 QPieSlice* slice = new QPieSlice(value, name);
285 QPieSlice* slice = new QPieSlice(value, name);
286 add(slice);
286 append(slice);
287 return slice;
287 return slice;
288 }
288 }
289
289
290 void QPieSeries::insert(int i, QPieSlice* slice)
290 void QPieSeries::insert(int i, QPieSlice* slice)
291 {
291 {
292 Q_D(QPieSeries);
292 Q_D(QPieSeries);
293 Q_ASSERT(i <= d->m_slices.count());
293 Q_ASSERT(i <= d->m_slices.count());
294 slice->setParent(this);
294 slice->setParent(this);
295 d->m_slices.insert(i, slice);
295 d->m_slices.insert(i, slice);
296
296
297 d->updateDerivativeData();
297 d->updateDerivativeData();
298
298
299 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
299 connect(slice, SIGNAL(changed()), d, SLOT(sliceChanged()));
300 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
300 connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked()));
301 connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
301 connect(slice, SIGNAL(hoverEnter()), d, SLOT(sliceHoverEnter()));
302 connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
302 connect(slice, SIGNAL(hoverLeave()), d, SLOT(sliceHoverLeave()));
303
303
304 emit added(QList<QPieSlice*>() << slice);
304 emit added(QList<QPieSlice*>() << slice);
305 }
305 }
306
306
307 /*!
307 /*!
308 Removes a single \a slice from the series and deletes the slice.
308 Removes a single \a slice from the series and deletes the slice.
309
309
310 Do not reference this pointer after this call.
310 Do not reference this pointer after this call.
311 */
311 */
312 void QPieSeries::remove(QPieSlice* slice)
312 void QPieSeries::remove(QPieSlice* slice)
313 {
313 {
314 Q_D(QPieSeries);
314 Q_D(QPieSeries);
315 if (!d->m_slices.removeOne(slice)) {
315 if (!d->m_slices.removeOne(slice)) {
316 Q_ASSERT(0); // TODO: how should this be reported?
316 Q_ASSERT(0); // TODO: how should this be reported?
317 return;
317 return;
318 }
318 }
319
319
320 d->updateDerivativeData();
320 d->updateDerivativeData();
321
321
322 emit removed(QList<QPieSlice*>() << slice);
322 emit removed(QList<QPieSlice*>() << slice);
323
323
324 delete slice;
324 delete slice;
325 slice = NULL;
325 slice = NULL;
326 }
326 }
327
327
328 /*!
328 /*!
329 Clears all slices from the series.
329 Clears all slices from the series.
330 */
330 */
331 void QPieSeries::clear()
331 void QPieSeries::clear()
332 {
332 {
333 Q_D(QPieSeries);
333 Q_D(QPieSeries);
334 if (d->m_slices.count() == 0)
334 if (d->m_slices.count() == 0)
335 return;
335 return;
336
336
337 QList<QPieSlice*> slices = d->m_slices;
337 QList<QPieSlice*> slices = d->m_slices;
338 foreach (QPieSlice* s, d->m_slices) {
338 foreach (QPieSlice* s, d->m_slices) {
339 d->m_slices.removeOne(s);
339 d->m_slices.removeOne(s);
340 delete s;
340 delete s;
341 }
341 }
342
342
343 d->updateDerivativeData();
343 d->updateDerivativeData();
344
344
345 emit removed(slices);
345 emit removed(slices);
346 }
346 }
347
347
348 /*!
348 /*!
349 Counts the number of the slices in this series.
349 Counts the number of the slices in this series.
350 */
350 */
351 int QPieSeries::count() const
351 int QPieSeries::count() const
352 {
352 {
353 Q_D(const QPieSeries);
353 Q_D(const QPieSeries);
354 return d->m_slices.count();
354 return d->m_slices.count();
355 }
355 }
356
356
357 /*!
357 /*!
358 Returns true is the series is empty.
358 Returns true is the series is empty.
359 */
359 */
360 bool QPieSeries::isEmpty() const
360 bool QPieSeries::isEmpty() const
361 {
361 {
362 Q_D(const QPieSeries);
362 Q_D(const QPieSeries);
363 return d->m_slices.isEmpty();
363 return d->m_slices.isEmpty();
364 }
364 }
365
365
366 /*!
366 /*!
367 Returns a list of slices that belong to this series.
367 Returns a list of slices that belong to this series.
368 */
368 */
369 QList<QPieSlice*> QPieSeries::slices() const
369 QList<QPieSlice*> QPieSeries::slices() const
370 {
370 {
371 Q_D(const QPieSeries);
371 Q_D(const QPieSeries);
372 return d->m_slices;
372 return d->m_slices;
373 }
373 }
374
374
375 /*!
375 /*!
376 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
376 Sets the center position of the pie by \a relativeHorizontalPosition and \a relativeVerticalPosition.
377
377
378 The factors are relative to the chart rectangle where:
378 The factors are relative to the chart rectangle where:
379
379
380 \a relativeHorizontalPosition 0.0 means the absolute left.
380 \a relativeHorizontalPosition 0.0 means the absolute left.
381 \a relativeHorizontalPosition 1.0 means the absolute right.
381 \a relativeHorizontalPosition 1.0 means the absolute right.
382 \a relativeVerticalPosition 0.0 means the absolute top.
382 \a relativeVerticalPosition 0.0 means the absolute top.
383 \a relativeVerticalPosition 1.0 means the absolute bottom.
383 \a relativeVerticalPosition 1.0 means the absolute bottom.
384
384
385 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
385 By default both values are 0.5 which puts the pie in the middle of the chart rectangle.
386
386
387 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
387 \sa pieHorizontalPosition(), pieVerticalPosition(), setPieSize()
388 */
388 */
389 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
389 void QPieSeries::setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition)
390 {
390 {
391 Q_D(QPieSeries);
391 Q_D(QPieSeries);
392 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
392 if (relativeHorizontalPosition < 0.0 || relativeHorizontalPosition > 1.0 ||
393 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
393 relativeVerticalPosition < 0.0 || relativeVerticalPosition > 1.0)
394 return;
394 return;
395
395
396 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativeHorizontalPosition) ||
396 if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativeHorizontalPosition) ||
397 !qFuzzyIsNull(d->m_pieRelativeVerPos - relativeVerticalPosition)) {
397 !qFuzzyIsNull(d->m_pieRelativeVerPos - relativeVerticalPosition)) {
398 d->m_pieRelativeHorPos = relativeHorizontalPosition;
398 d->m_pieRelativeHorPos = relativeHorizontalPosition;
399 d->m_pieRelativeVerPos = relativeVerticalPosition;
399 d->m_pieRelativeVerPos = relativeVerticalPosition;
400 emit piePositionChanged();
400 emit piePositionChanged();
401 }
401 }
402 }
402 }
403
403
404 /*!
404 /*!
405 Gets the horizontal position of the pie.
405 Gets the horizontal position of the pie.
406
406
407 The returned value is relative to the chart rectangle where:
407 The returned value is relative to the chart rectangle where:
408
408
409 0.0 means the absolute left.
409 0.0 means the absolute left.
410 1.0 means the absolute right.
410 1.0 means the absolute right.
411
411
412 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
412 By default it is 0.5 which puts the pie in the horizontal middle of the chart rectangle.
413
413
414 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
414 \sa setPiePosition(), pieVerticalPosition(), setPieSize()
415 */
415 */
416 qreal QPieSeries::pieHorizontalPosition() const
416 qreal QPieSeries::pieHorizontalPosition() const
417 {
417 {
418 Q_D(const QPieSeries);
418 Q_D(const QPieSeries);
419 return d->m_pieRelativeHorPos;
419 return d->m_pieRelativeHorPos;
420 }
420 }
421
421
422 /*!
422 /*!
423 Gets the vertical position position of the pie.
423 Gets the vertical position position of the pie.
424
424
425 The returned value is relative to the chart rectangle where:
425 The returned value is relative to the chart rectangle where:
426
426
427 0.0 means the absolute top.
427 0.0 means the absolute top.
428 1.0 means the absolute bottom.
428 1.0 means the absolute bottom.
429
429
430 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
430 By default it is 0.5 which puts the pie in the vertical middle of the chart rectangle.
431
431
432 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
432 \sa setPiePosition(), pieHorizontalPosition(), setPieSize()
433 */
433 */
434 qreal QPieSeries::pieVerticalPosition() const
434 qreal QPieSeries::pieVerticalPosition() const
435 {
435 {
436 Q_D(const QPieSeries);
436 Q_D(const QPieSeries);
437 return d->m_pieRelativeVerPos;
437 return d->m_pieRelativeVerPos;
438 }
438 }
439
439
440 /*!
440 /*!
441 Sets the relative size of the pie.
441 Sets the relative size of the pie.
442
442
443 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
443 The \a relativeSize is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
444
444
445 Default value is 0.7.
445 Default value is 0.7.
446
446
447 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
447 \sa pieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
448 */
448 */
449 void QPieSeries::setPieSize(qreal relativeSize)
449 void QPieSeries::setPieSize(qreal relativeSize)
450 {
450 {
451 Q_D(QPieSeries);
451 Q_D(QPieSeries);
452 if (relativeSize < 0.0 || relativeSize > 1.0)
452 if (relativeSize < 0.0 || relativeSize > 1.0)
453 return;
453 return;
454
454
455 if (!qFuzzyIsNull(d->m_pieRelativeSize- relativeSize)) {
455 if (!qFuzzyIsNull(d->m_pieRelativeSize- relativeSize)) {
456 d->m_pieRelativeSize = relativeSize;
456 d->m_pieRelativeSize = relativeSize;
457 emit pieSizeChanged();
457 emit pieSizeChanged();
458 }
458 }
459 }
459 }
460
460
461 /*!
461 /*!
462 Gets the relative size of the pie.
462 Gets the relative size of the pie.
463
463
464 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
464 The size is defined so that the 1.0 is the maximum that can fit the given chart rectangle.
465
465
466 Default value is 0.7.
466 Default value is 0.7.
467
467
468 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
468 \sa setPieSize(), setPiePosition(), pieVerticalPosition(), pieHorizontalPosition()
469 */
469 */
470 qreal QPieSeries::pieSize() const
470 qreal QPieSeries::pieSize() const
471 {
471 {
472 Q_D(const QPieSeries);
472 Q_D(const QPieSeries);
473 return d->m_pieRelativeSize;
473 return d->m_pieRelativeSize;
474 }
474 }
475
475
476
476
477 /*!
477 /*!
478 Sets the end angle of the pie.
478 Sets the end angle of the pie.
479
479
480 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
480 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
481
481
482 \a angle must be less than pie end angle. Default value is 0.
482 \a angle must be less than pie end angle. Default value is 0.
483
483
484 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
484 \sa pieStartAngle(), pieEndAngle(), setPieEndAngle()
485 */
485 */
486 void QPieSeries::setPieStartAngle(qreal angle)
486 void QPieSeries::setPieStartAngle(qreal angle)
487 {
487 {
488 Q_D(QPieSeries);
488 Q_D(QPieSeries);
489
489
490 if (angle < 0 || angle > 360 || angle > d->m_pieEndAngle)
490 if (angle < 0 || angle > 360 || angle > d->m_pieEndAngle)
491 return;
491 return;
492
492
493 if (!qFuzzyIsNull(angle - d->m_pieStartAngle)) {
493 if (!qFuzzyIsNull(angle - d->m_pieStartAngle)) {
494 d->m_pieStartAngle = angle;
494 d->m_pieStartAngle = angle;
495 d->updateDerivativeData();
495 d->updateDerivativeData();
496 }
496 }
497 }
497 }
498
498
499 /*!
499 /*!
500 Gets the start angle of the pie.
500 Gets the start angle of the pie.
501
501
502 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
502 Full pie is 360 degrees where 0 degrees is at 12 a'clock. Default value is 360.
503
503
504 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
504 \sa setPieStartAngle(), pieEndAngle(), setPieEndAngle()
505 */
505 */
506 qreal QPieSeries::pieStartAngle() const
506 qreal QPieSeries::pieStartAngle() const
507 {
507 {
508 Q_D(const QPieSeries);
508 Q_D(const QPieSeries);
509 return d->m_pieStartAngle;
509 return d->m_pieStartAngle;
510 }
510 }
511
511
512 /*!
512 /*!
513 Sets the end angle of the pie.
513 Sets the end angle of the pie.
514
514
515 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
515 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
516
516
517 \a angle must be greater than start angle.
517 \a angle must be greater than start angle.
518
518
519 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
519 \sa pieEndAngle(), pieStartAngle(), setPieStartAngle()
520 */
520 */
521 void QPieSeries::setPieEndAngle(qreal angle)
521 void QPieSeries::setPieEndAngle(qreal angle)
522 {
522 {
523 Q_D(QPieSeries);
523 Q_D(QPieSeries);
524
524
525 if (angle < 0 || angle > 360 || angle < d->m_pieStartAngle)
525 if (angle < 0 || angle > 360 || angle < d->m_pieStartAngle)
526 return;
526 return;
527
527
528 if (!qFuzzyIsNull(angle - d->m_pieEndAngle)) {
528 if (!qFuzzyIsNull(angle - d->m_pieEndAngle)) {
529 d->m_pieEndAngle = angle;
529 d->m_pieEndAngle = angle;
530 d->updateDerivativeData();
530 d->updateDerivativeData();
531 }
531 }
532 }
532 }
533
533
534 /*!
534 /*!
535 Returns the end angle of the pie.
535 Returns the end angle of the pie.
536
536
537 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
537 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
538
538
539 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
539 \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle()
540 */
540 */
541 qreal QPieSeries::pieEndAngle() const
541 qreal QPieSeries::pieEndAngle() const
542 {
542 {
543 Q_D(const QPieSeries);
543 Q_D(const QPieSeries);
544 return d->m_pieEndAngle;
544 return d->m_pieEndAngle;
545 }
545 }
546
546
547 /*!
547 /*!
548 Sets the all the slice labels \a visible or invisible.
548 Sets the all the slice labels \a visible or invisible.
549
549
550 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
550 \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible()
551 */
551 */
552 void QPieSeries::setLabelsVisible(bool visible)
552 void QPieSeries::setLabelsVisible(bool visible)
553 {
553 {
554 Q_D(QPieSeries);
554 Q_D(QPieSeries);
555 foreach (QPieSlice* s, d->m_slices)
555 foreach (QPieSlice* s, d->m_slices)
556 s->setLabelVisible(visible);
556 s->setLabelVisible(visible);
557 }
557 }
558
558
559 /*!
559 /*!
560 Returns the sum of all slice values in this series.
560 Returns the sum of all slice values in this series.
561
561
562 \sa QPieSlice::value(), QPieSlice::setValue()
562 \sa QPieSlice::value(), QPieSlice::setValue()
563 */
563 */
564 qreal QPieSeries::total() const
564 qreal QPieSeries::total() const
565 {
565 {
566 Q_D(const QPieSeries);
566 Q_D(const QPieSeries);
567 return d->m_total;
567 return d->m_total;
568 }
568 }
569
569
570 /*!
570 /*!
571 \fn void QPieSeries::clicked(QPieSlice* slice)
571 \fn void QPieSeries::clicked(QPieSlice* slice)
572
572
573 This signal is emitted when a \a slice has been clicked.
573 This signal is emitted when a \a slice has been clicked.
574
574
575 \sa QPieSlice::clicked()
575 \sa QPieSlice::clicked()
576 */
576 */
577
577
578 /*!
578 /*!
579 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
579 \fn void QPieSeries::hoverEnter(QPieSlice* slice)
580
580
581 This signal is emitted when user has hovered over a \a slice.
581 This signal is emitted when user has hovered over a \a slice.
582
582
583 \sa QPieSlice::hoverEnter()
583 \sa QPieSlice::hoverEnter()
584 */
584 */
585
585
586 /*!
586 /*!
587 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
587 \fn void QPieSeries::hoverLeave(QPieSlice* slice)
588
588
589 This signal is emitted when user has hovered away from a \a slice.
589 This signal is emitted when user has hovered away from a \a slice.
590
590
591 \sa QPieSlice::hoverLeave()
591 \sa QPieSlice::hoverLeave()
592 */
592 */
593
593
594
594
595
595
596
596
597 bool QPieSeries::setModel(QAbstractItemModel* model)
597 bool QPieSeries::setModel(QAbstractItemModel* model)
598 {
598 {
599 Q_D(QPieSeries);
599 Q_D(QPieSeries);
600 // disconnect signals from old model
600 // disconnect signals from old model
601 if(m_model)
601 if(m_model)
602 {
602 {
603 disconnect(m_model, 0, this, 0);
603 disconnect(m_model, 0, this, 0);
604 d->m_mapValues = -1;
604 d->m_mapValues = -1;
605 d->m_mapLabels = -1;
605 d->m_mapLabels = -1;
606 d->m_mapOrientation = Qt::Vertical;
606 d->m_mapOrientation = Qt::Vertical;
607 }
607 }
608
608
609 // set new model
609 // set new model
610 if(model)
610 if(model)
611 {
611 {
612 m_model = model;
612 m_model = model;
613 return true;
613 return true;
614 }
614 }
615 else
615 else
616 {
616 {
617 m_model = NULL;
617 m_model = NULL;
618 return false;
618 return false;
619 }
619 }
620 }
620 }
621
621
622 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
622 void QPieSeries::setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation)
623 {
623 {
624 Q_D(QPieSeries);
624 Q_D(QPieSeries);
625
625
626 if (m_model == NULL)
626 if (m_model == NULL)
627 return;
627 return;
628
628
629 d->m_mapValues = modelValuesLine;
629 d->m_mapValues = modelValuesLine;
630 d->m_mapLabels = modelLabelsLine;
630 d->m_mapLabels = modelLabelsLine;
631 d->m_mapOrientation = orientation;
631 d->m_mapOrientation = orientation;
632
632
633 // connect the signals
633 // connect the signals
634 if (d->m_mapOrientation == Qt::Vertical) {
634 if (d->m_mapOrientation == Qt::Vertical) {
635 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
635 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
636 connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
636 connect(m_model, SIGNAL(rowsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
637 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
637 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
638 } else {
638 } else {
639 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
639 connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex, QModelIndex)));
640 connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
640 connect(m_model, SIGNAL(columnsInserted(QModelIndex, int, int)), d, SLOT(modelDataAdded(QModelIndex,int,int)));
641 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
641 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), d, SLOT(modelDataRemoved(QModelIndex,int,int)));
642 }
642 }
643
643
644 // create the initial slices set
644 // create the initial slices set
645 if (d->m_mapOrientation == Qt::Vertical) {
645 if (d->m_mapOrientation == Qt::Vertical) {
646 for (int i = 0; i < m_model->rowCount(); i++)
646 for (int i = 0; i < m_model->rowCount(); i++)
647 add(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString());
647 append(m_model->data(m_model->index(i, d->m_mapValues), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(i, d->m_mapLabels), Qt::DisplayRole).toString());
648 } else {
648 } else {
649 for (int i = 0; i < m_model->columnCount(); i++)
649 for (int i = 0; i < m_model->columnCount(); i++)
650 add(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString());
650 append(m_model->data(m_model->index(d->m_mapValues, i), Qt::DisplayRole).toDouble(), m_model->data(m_model->index(d->m_mapLabels, i), Qt::DisplayRole).toString());
651 }
651 }
652 }
652 }
653
653
654 #include "moc_qpieseries.cpp"
654 #include "moc_qpieseries.cpp"
655 #include "moc_qpieseriesprivate_p.cpp"
655 #include "moc_qpieseriesprivate_p.cpp"
656
656
657 QTCOMMERCIALCHART_END_NAMESPACE
657 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,100 +1,100
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef PIESERIES_H
21 #ifndef PIESERIES_H
22 #define PIESERIES_H
22 #define PIESERIES_H
23
23
24 #include <qseries.h>
24 #include <qseries.h>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 class QPieSeriesPrivate;
27 class QPieSeriesPrivate;
28 class QPieSlice;
28 class QPieSlice;
29
29
30 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
30 class QTCOMMERCIALCHART_EXPORT QPieSeries : public QSeries
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33
33
34 public:
34 public:
35 QPieSeries(QObject *parent = 0);
35 QPieSeries(QObject *parent = 0);
36 virtual ~QPieSeries();
36 virtual ~QPieSeries();
37
37
38 public: // from QChartSeries
38 public: // from QChartSeries
39 QSeriesType type() const;
39 QSeriesType type() const;
40
40
41 public:
41 public:
42
42
43 // slice setters
43 // slice setters
44 void add(QPieSlice* slice);
44 void append(QPieSlice* slice);
45 void add(QList<QPieSlice*> slices);
45 void append(QList<QPieSlice*> slices);
46 void insert(int i, QPieSlice* slice);
46 void insert(int i, QPieSlice* slice);
47 void replace(QList<QPieSlice*> slices);
47 void replace(QList<QPieSlice*> slices);
48 void remove(QPieSlice* slice);
48 void remove(QPieSlice* slice);
49 void clear();
49 void clear();
50
50
51 // slice getters
51 // slice getters
52 QList<QPieSlice*> slices() const;
52 QList<QPieSlice*> slices() const;
53
53
54 // calculated data
54 // calculated data
55 int count() const;
55 int count() const;
56 bool isEmpty() const;
56 bool isEmpty() const;
57 qreal total() const;
57 qreal total() const;
58
58
59 // pie customization
59 // pie customization
60 void setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition);
60 void setPiePosition(qreal relativeHorizontalPosition, qreal relativeVerticalPosition);
61 qreal pieHorizontalPosition() const;
61 qreal pieHorizontalPosition() const;
62 qreal pieVerticalPosition() const;
62 qreal pieVerticalPosition() const;
63 void setPieSize(qreal relativeSize);
63 void setPieSize(qreal relativeSize);
64 qreal pieSize() const;
64 qreal pieSize() const;
65 void setPieStartAngle(qreal startAngle);
65 void setPieStartAngle(qreal startAngle);
66 qreal pieStartAngle() const;
66 qreal pieStartAngle() const;
67 void setPieEndAngle(qreal endAngle);
67 void setPieEndAngle(qreal endAngle);
68 qreal pieEndAngle() const;
68 qreal pieEndAngle() const;
69
69
70 // convenience function
70 // convenience function
71 QPieSeries& operator << (QPieSlice* slice);
71 QPieSeries& operator << (QPieSlice* slice);
72 QPieSlice* add(qreal value, QString name);
72 QPieSlice* append(qreal value, QString name);
73 void setLabelsVisible(bool visible = true);
73 void setLabelsVisible(bool visible = true);
74
74
75 // data from model
75 // data from model
76 bool setModel(QAbstractItemModel* model);
76 bool setModel(QAbstractItemModel* model);
77 void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical);
77 void setModelMapping(int modelValuesLine, int modelLabelsLine, Qt::Orientation orientation = Qt::Vertical);
78
78
79 Q_SIGNALS:
79 Q_SIGNALS:
80 void clicked(QPieSlice* slice, Qt::MouseButtons buttons);
80 void clicked(QPieSlice* slice, Qt::MouseButtons buttons);
81 void hoverEnter(QPieSlice* slice);
81 void hoverEnter(QPieSlice* slice);
82 void hoverLeave(QPieSlice* slice);
82 void hoverLeave(QPieSlice* slice);
83 void added(QList<QPieSlice*> slices);
83 void added(QList<QPieSlice*> slices);
84 void removed(QList<QPieSlice*> slices);
84 void removed(QList<QPieSlice*> slices);
85 void piePositionChanged();
85 void piePositionChanged();
86 void pieSizeChanged();
86 void pieSizeChanged();
87
87
88 private:
88 private:
89 QPieSeriesPrivate * const d_ptr;
89 QPieSeriesPrivate * const d_ptr;
90 Q_DECLARE_PRIVATE(QPieSeries)
90 Q_DECLARE_PRIVATE(QPieSeries)
91 Q_DISABLE_COPY(QPieSeries)
91 Q_DISABLE_COPY(QPieSeries)
92
92
93 public:
93 public:
94 typedef QPieSeriesPrivate * const DataPtr;
94 typedef QPieSeriesPrivate * const DataPtr;
95 inline DataPtr &data_ptr() { return d_ptr; }
95 inline DataPtr &data_ptr() { return d_ptr; }
96 };
96 };
97
97
98 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
99
99
100 #endif // PIESERIES_H
100 #endif // PIESERIES_H
@@ -1,433 +1,433
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qpieslice.h"
21 #include "qpieslice.h"
22 #include "qpiesliceprivate_p.h"
22 #include "qpiesliceprivate_p.h"
23 #include "qpieseries.h"
23 #include "qpieseries.h"
24 #include "qpieseriesprivate_p.h"
24 #include "qpieseriesprivate_p.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 /*!
28 /*!
29 \class QPieSlice
29 \class QPieSlice
30 \brief Defines a slice in pie series.
30 \brief Defines a slice in pie series.
31
31
32 Holds all the data of a single slice in a QPieSeries and provides the means
32 Holds all the data of a single slice in a QPieSeries and provides the means
33 to modify slice data and customize the visual appearance of the slice.
33 to modify slice data and customize the visual appearance of the slice.
34
34
35 It also provides the means to customize user interaction with the slice by
35 It also provides the means to customize user interaction with the slice by
36 providing signals for clicking and hover events.
36 providing signals for clicking and hover events.
37 */
37 */
38
38
39 /*!
39 /*!
40 \property QPieSlice::label
40 \property QPieSlice::label
41
41
42 Label of the slice.
42 Label of the slice.
43 */
43 */
44
44
45 /*!
45 /*!
46 \property QPieSlice::value
46 \property QPieSlice::value
47
47
48 Value of the slice.
48 Value of the slice.
49 */
49 */
50
50
51 /*!
51 /*!
52 Constructs an empty slice with a \a parent.
52 Constructs an empty slice with a \a parent.
53
53
54 Note that QPieSeries takes ownership of the slice when it is set/added.
54 Note that QPieSeries takes ownership of the slice when it is set/added.
55
55
56 \sa QPieSeries::replace(), QPieSeries::add()
56 \sa QPieSeries::replace(), QPieSeries::append()
57 */
57 */
58 QPieSlice::QPieSlice(QObject *parent)
58 QPieSlice::QPieSlice(QObject *parent)
59 :QObject(parent),
59 :QObject(parent),
60 d_ptr(new QPieSlicePrivate(this))
60 d_ptr(new QPieSlicePrivate(this))
61 {
61 {
62
62
63 }
63 }
64
64
65 /*!
65 /*!
66 Constructs an empty slice with given \a value, \a label and a \a parent.
66 Constructs an empty slice with given \a value, \a label and a \a parent.
67 Note that QPieSeries takes ownership of the slice when it is set/added.
67 Note that QPieSeries takes ownership of the slice when it is set/added.
68 \sa QPieSeries::replace(), QPieSeries::add()
68 \sa QPieSeries::replace(), QPieSeries::append()
69 */
69 */
70 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
70 QPieSlice::QPieSlice(qreal value, QString label, QObject *parent)
71 :QObject(parent),
71 :QObject(parent),
72 d_ptr(new QPieSlicePrivate(this))
72 d_ptr(new QPieSlicePrivate(this))
73 {
73 {
74 Q_D(QPieSlice);
74 Q_D(QPieSlice);
75 d->m_data.m_value = value;
75 d->m_data.m_value = value;
76 d->m_data.m_labelText = label;
76 d->m_data.m_labelText = label;
77 }
77 }
78
78
79 /*!
79 /*!
80 Destroys the slice.
80 Destroys the slice.
81 User should not delete the slice if it has been added to the series.
81 User should not delete the slice if it has been added to the series.
82 */
82 */
83 QPieSlice::~QPieSlice()
83 QPieSlice::~QPieSlice()
84 {
84 {
85 delete d_ptr;
85 delete d_ptr;
86 }
86 }
87
87
88 /*!
88 /*!
89 Gets the value of the slice.
89 Gets the value of the slice.
90 Note that all values in the series
90 Note that all values in the series
91 \sa setValue()
91 \sa setValue()
92 */
92 */
93 qreal QPieSlice::value() const
93 qreal QPieSlice::value() const
94 {
94 {
95 Q_D(const QPieSlice);
95 Q_D(const QPieSlice);
96 return d->m_data.m_value;
96 return d->m_data.m_value;
97 }
97 }
98
98
99 /*!
99 /*!
100 Gets the label of the slice.
100 Gets the label of the slice.
101 \sa setLabel()
101 \sa setLabel()
102 */
102 */
103 QString QPieSlice::label() const
103 QString QPieSlice::label() const
104 {
104 {
105 Q_D(const QPieSlice);
105 Q_D(const QPieSlice);
106 return d->m_data.m_labelText;
106 return d->m_data.m_labelText;
107 }
107 }
108
108
109 /*!
109 /*!
110 Returns true if label is set as visible.
110 Returns true if label is set as visible.
111 \sa setLabelVisible()
111 \sa setLabelVisible()
112 */
112 */
113 bool QPieSlice::isLabelVisible() const
113 bool QPieSlice::isLabelVisible() const
114 {
114 {
115 Q_D(const QPieSlice);
115 Q_D(const QPieSlice);
116 return d->m_data.m_isLabelVisible;
116 return d->m_data.m_isLabelVisible;
117 }
117 }
118
118
119 /*!
119 /*!
120 Returns true if slice is exloded from the pie.
120 Returns true if slice is exloded from the pie.
121 \sa setExploded(), setExplodeDistanceFactor()
121 \sa setExploded(), setExplodeDistanceFactor()
122 */
122 */
123 bool QPieSlice::isExploded() const
123 bool QPieSlice::isExploded() const
124 {
124 {
125 Q_D(const QPieSlice);
125 Q_D(const QPieSlice);
126 return d->m_data.m_isExploded;
126 return d->m_data.m_isExploded;
127 }
127 }
128
128
129 /*!
129 /*!
130 Returns the explode distance factor.
130 Returns the explode distance factor.
131
131
132 The factor is relative to pie radius. For example:
132 The factor is relative to pie radius. For example:
133 1.0 means the distance is the same as the radius.
133 1.0 means the distance is the same as the radius.
134 0.5 means the distance is half of the radius.
134 0.5 means the distance is half of the radius.
135
135
136 Default value is 0.15.
136 Default value is 0.15.
137
137
138 \sa setExplodeDistanceFactor()
138 \sa setExplodeDistanceFactor()
139 */
139 */
140 qreal QPieSlice::explodeDistanceFactor() const
140 qreal QPieSlice::explodeDistanceFactor() const
141 {
141 {
142 Q_D(const QPieSlice);
142 Q_D(const QPieSlice);
143 return d->m_data.m_explodeDistanceFactor;
143 return d->m_data.m_explodeDistanceFactor;
144 }
144 }
145
145
146 /*!
146 /*!
147 Returns the percentage of this slice compared to all slices in the same series.
147 Returns the percentage of this slice compared to all slices in the same series.
148 The returned value ranges from 0 to 1.0.
148 The returned value ranges from 0 to 1.0.
149
149
150 Updated internally after the slice is added to the series.
150 Updated internally after the slice is added to the series.
151 */
151 */
152 qreal QPieSlice::percentage() const
152 qreal QPieSlice::percentage() const
153 {
153 {
154 Q_D(const QPieSlice);
154 Q_D(const QPieSlice);
155 return d->m_data.m_percentage;
155 return d->m_data.m_percentage;
156 }
156 }
157
157
158 /*!
158 /*!
159 Returns the starting angle of this slice in the series it belongs to.
159 Returns the starting angle of this slice in the series it belongs to.
160
160
161 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
161 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
162
162
163 Updated internally after the slice is added to the series.
163 Updated internally after the slice is added to the series.
164 */
164 */
165 qreal QPieSlice::startAngle() const
165 qreal QPieSlice::startAngle() const
166 {
166 {
167 Q_D(const QPieSlice);
167 Q_D(const QPieSlice);
168 return d->m_data.m_startAngle;
168 return d->m_data.m_startAngle;
169 }
169 }
170
170
171 /*!
171 /*!
172 Returns the end angle of this slice in the series it belongs to.
172 Returns the end angle of this slice in the series it belongs to.
173
173
174 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
174 Full pie is 360 degrees where 0 degrees is at 12 a'clock.
175
175
176 Updated internally after the slice is added to the series.
176 Updated internally after the slice is added to the series.
177 */
177 */
178 qreal QPieSlice::endAngle() const
178 qreal QPieSlice::endAngle() const
179 {
179 {
180 Q_D(const QPieSlice);
180 Q_D(const QPieSlice);
181 return d->m_data.m_startAngle + d->m_data.m_angleSpan;
181 return d->m_data.m_startAngle + d->m_data.m_angleSpan;
182 }
182 }
183
183
184 /*!
184 /*!
185 Returns the pen used to draw this slice.
185 Returns the pen used to draw this slice.
186 \sa setSlicePen()
186 \sa setSlicePen()
187 */
187 */
188 QPen QPieSlice::pen() const
188 QPen QPieSlice::pen() const
189 {
189 {
190 Q_D(const QPieSlice);
190 Q_D(const QPieSlice);
191 return d->m_data.m_slicePen;
191 return d->m_data.m_slicePen;
192 }
192 }
193
193
194 /*!
194 /*!
195 Returns the brush used to draw this slice.
195 Returns the brush used to draw this slice.
196 \sa setSliceBrush()
196 \sa setSliceBrush()
197 */
197 */
198 QBrush QPieSlice::brush() const
198 QBrush QPieSlice::brush() const
199 {
199 {
200 Q_D(const QPieSlice);
200 Q_D(const QPieSlice);
201 return d->m_data.m_sliceBrush;
201 return d->m_data.m_sliceBrush;
202 }
202 }
203
203
204 /*!
204 /*!
205 Returns the pen used to draw the label in this slice.
205 Returns the pen used to draw the label in this slice.
206 \sa setLabelArmPen()
206 \sa setLabelArmPen()
207 */
207 */
208 QPen QPieSlice::labelPen() const
208 QPen QPieSlice::labelPen() const
209 {
209 {
210 Q_D(const QPieSlice);
210 Q_D(const QPieSlice);
211 return d->m_data.m_labelPen;
211 return d->m_data.m_labelPen;
212 }
212 }
213
213
214 /*!
214 /*!
215 Returns the font used to draw label in this slice.
215 Returns the font used to draw label in this slice.
216 \sa setLabelFont()
216 \sa setLabelFont()
217 */
217 */
218 QFont QPieSlice::labelFont() const
218 QFont QPieSlice::labelFont() const
219 {
219 {
220 Q_D(const QPieSlice);
220 Q_D(const QPieSlice);
221 return d->m_data.m_labelFont;
221 return d->m_data.m_labelFont;
222 }
222 }
223
223
224 /*!
224 /*!
225 Gets the label arm length factor.
225 Gets the label arm length factor.
226
226
227 The factor is relative to pie radius. For example:
227 The factor is relative to pie radius. For example:
228 1.0 means the length is the same as the radius.
228 1.0 means the length is the same as the radius.
229 0.5 means the length is half of the radius.
229 0.5 means the length is half of the radius.
230
230
231 Default value is 0.15
231 Default value is 0.15
232
232
233 \sa setLabelArmLengthFactor()
233 \sa setLabelArmLengthFactor()
234 */
234 */
235 qreal QPieSlice::labelArmLengthFactor() const
235 qreal QPieSlice::labelArmLengthFactor() const
236 {
236 {
237 Q_D(const QPieSlice);
237 Q_D(const QPieSlice);
238 return d->m_data.m_labelArmLengthFactor;
238 return d->m_data.m_labelArmLengthFactor;
239 }
239 }
240
240
241 /*!
241 /*!
242 \fn void QPieSlice::clicked()
242 \fn void QPieSlice::clicked()
243
243
244 This signal is emitted when user has clicked the slice.
244 This signal is emitted when user has clicked the slice.
245
245
246 \sa QPieSeries::clicked()
246 \sa QPieSeries::clicked()
247 */
247 */
248
248
249 /*!
249 /*!
250 \fn void QPieSlice::hoverEnter()
250 \fn void QPieSlice::hoverEnter()
251
251
252 This signal is emitted when user has hovered over the slice.
252 This signal is emitted when user has hovered over the slice.
253
253
254 \sa QPieSeries::hoverEnter()
254 \sa QPieSeries::hoverEnter()
255 */
255 */
256
256
257 /*!
257 /*!
258 \fn void QPieSlice::hoverLeave()
258 \fn void QPieSlice::hoverLeave()
259
259
260 This signal is emitted when user has hovered away from the slice.
260 This signal is emitted when user has hovered away from the slice.
261
261
262 \sa QPieSeries::hoverLeave()
262 \sa QPieSeries::hoverLeave()
263 */
263 */
264
264
265 /*!
265 /*!
266 \fn void QPieSlice::changed()
266 \fn void QPieSlice::changed()
267
267
268 This signal emitted when something has changed in the slice.
268 This signal emitted when something has changed in the slice.
269
269
270 \sa QPieSeries::changed()
270 \sa QPieSeries::changed()
271 */
271 */
272
272
273 /*!
273 /*!
274 Sets the \a value of this slice.
274 Sets the \a value of this slice.
275 \sa value()
275 \sa value()
276 */
276 */
277 void QPieSlice::setValue(qreal value)
277 void QPieSlice::setValue(qreal value)
278 {
278 {
279 Q_D(QPieSlice);
279 Q_D(QPieSlice);
280 if (!qFuzzyIsNull(d->m_data.m_value - value)) {
280 if (!qFuzzyIsNull(d->m_data.m_value - value)) {
281 d->m_data.m_value = value;
281 d->m_data.m_value = value;
282
282
283 QPieSeries *series = qobject_cast<QPieSeries*>(parent());
283 QPieSeries *series = qobject_cast<QPieSeries*>(parent());
284 if (series)
284 if (series)
285 series->data_ptr()->updateDerivativeData(); // will emit changed()
285 series->data_ptr()->updateDerivativeData(); // will emit changed()
286 else
286 else
287 emit changed();
287 emit changed();
288 }
288 }
289 }
289 }
290
290
291 /*!
291 /*!
292 Sets the \a label of the slice.
292 Sets the \a label of the slice.
293 \sa label()
293 \sa label()
294 */
294 */
295 void QPieSlice::setLabel(QString label)
295 void QPieSlice::setLabel(QString label)
296 {
296 {
297 Q_D(QPieSlice);
297 Q_D(QPieSlice);
298 if (d->m_data.m_labelText != label) {
298 if (d->m_data.m_labelText != label) {
299 d->m_data.m_labelText = label;
299 d->m_data.m_labelText = label;
300 emit changed();
300 emit changed();
301 }
301 }
302 }
302 }
303
303
304 /*!
304 /*!
305 Sets the label \a visible in this slice.
305 Sets the label \a visible in this slice.
306 \sa isLabelVisible(), QPieSeries::setLabelsVisible()
306 \sa isLabelVisible(), QPieSeries::setLabelsVisible()
307 */
307 */
308 void QPieSlice::setLabelVisible(bool visible)
308 void QPieSlice::setLabelVisible(bool visible)
309 {
309 {
310 Q_D(QPieSlice);
310 Q_D(QPieSlice);
311 if (d->m_data.m_isLabelVisible != visible) {
311 if (d->m_data.m_isLabelVisible != visible) {
312 d->m_data.m_isLabelVisible = visible;
312 d->m_data.m_isLabelVisible = visible;
313 emit changed();
313 emit changed();
314 }
314 }
315 }
315 }
316
316
317 /*!
317 /*!
318 Sets this slice \a exploded.
318 Sets this slice \a exploded.
319 \sa isExploded(), explodeDistanceFactor()
319 \sa isExploded(), explodeDistanceFactor()
320 */
320 */
321 void QPieSlice::setExploded(bool exploded)
321 void QPieSlice::setExploded(bool exploded)
322 {
322 {
323 Q_D(QPieSlice);
323 Q_D(QPieSlice);
324 if (d->m_data.m_isExploded != exploded) {
324 if (d->m_data.m_isExploded != exploded) {
325 d->m_data.m_isExploded = exploded;
325 d->m_data.m_isExploded = exploded;
326 emit changed();
326 emit changed();
327 }
327 }
328 }
328 }
329
329
330 /*!
330 /*!
331 Sets the explode distance \a factor.
331 Sets the explode distance \a factor.
332
332
333 The factor is relative to pie radius. For example:
333 The factor is relative to pie radius. For example:
334 1.0 means the distance is the same as the radius.
334 1.0 means the distance is the same as the radius.
335 0.5 means the distance is half of the radius.
335 0.5 means the distance is half of the radius.
336
336
337 Default value is 0.15
337 Default value is 0.15
338
338
339 \sa explodeDistanceFactor()
339 \sa explodeDistanceFactor()
340 */
340 */
341 void QPieSlice::setExplodeDistanceFactor(qreal factor)
341 void QPieSlice::setExplodeDistanceFactor(qreal factor)
342 {
342 {
343 Q_D(QPieSlice);
343 Q_D(QPieSlice);
344 if (!qFuzzyIsNull(d->m_data.m_explodeDistanceFactor - factor)) {
344 if (!qFuzzyIsNull(d->m_data.m_explodeDistanceFactor - factor)) {
345 d->m_data.m_explodeDistanceFactor = factor;
345 d->m_data.m_explodeDistanceFactor = factor;
346 emit changed();
346 emit changed();
347 }
347 }
348 }
348 }
349
349
350 /*!
350 /*!
351 Sets the \a pen used to draw this slice.
351 Sets the \a pen used to draw this slice.
352 Note that applying a theme will override this.
352 Note that applying a theme will override this.
353 \sa slicePen()
353 \sa slicePen()
354 */
354 */
355 void QPieSlice::setPen(const QPen &pen)
355 void QPieSlice::setPen(const QPen &pen)
356 {
356 {
357 Q_D(QPieSlice);
357 Q_D(QPieSlice);
358 if (d->m_data.m_slicePen != pen) {
358 if (d->m_data.m_slicePen != pen) {
359 d->m_data.m_slicePen = pen;
359 d->m_data.m_slicePen = pen;
360 d->m_data.m_slicePen.setThemed(false);
360 d->m_data.m_slicePen.setThemed(false);
361 emit changed();
361 emit changed();
362 }
362 }
363 }
363 }
364
364
365 /*!
365 /*!
366 Sets the \a brush used to draw this slice.
366 Sets the \a brush used to draw this slice.
367 Note that applying a theme will override this.
367 Note that applying a theme will override this.
368 \sa sliceBrush()
368 \sa sliceBrush()
369 */
369 */
370 void QPieSlice::setBrush(const QBrush &brush)
370 void QPieSlice::setBrush(const QBrush &brush)
371 {
371 {
372 Q_D(QPieSlice);
372 Q_D(QPieSlice);
373 if (d->m_data.m_sliceBrush != brush) {
373 if (d->m_data.m_sliceBrush != brush) {
374 d->m_data.m_sliceBrush = brush;
374 d->m_data.m_sliceBrush = brush;
375 d->m_data.m_sliceBrush.setThemed(false);
375 d->m_data.m_sliceBrush.setThemed(false);
376 emit changed();
376 emit changed();
377 }
377 }
378 }
378 }
379
379
380 /*!
380 /*!
381 Sets the \a pen used to draw the label in this slice.
381 Sets the \a pen used to draw the label in this slice.
382 Note that applying a theme will override this.
382 Note that applying a theme will override this.
383 \sa labelArmPen()
383 \sa labelArmPen()
384 */
384 */
385 void QPieSlice::setLabelPen(const QPen &pen)
385 void QPieSlice::setLabelPen(const QPen &pen)
386 {
386 {
387 Q_D(QPieSlice);
387 Q_D(QPieSlice);
388 if (d->m_data.m_labelPen != pen) {
388 if (d->m_data.m_labelPen != pen) {
389 d->m_data.m_labelPen = pen;
389 d->m_data.m_labelPen = pen;
390 d->m_data.m_labelPen.setThemed(false);
390 d->m_data.m_labelPen.setThemed(false);
391 emit changed();
391 emit changed();
392 }
392 }
393 }
393 }
394
394
395 /*!
395 /*!
396 Sets the \a font used to draw the label in this slice.
396 Sets the \a font used to draw the label in this slice.
397 Note that applying a theme will override this.
397 Note that applying a theme will override this.
398 \sa labelFont()
398 \sa labelFont()
399 */
399 */
400 void QPieSlice::setLabelFont(const QFont &font)
400 void QPieSlice::setLabelFont(const QFont &font)
401 {
401 {
402 Q_D(QPieSlice);
402 Q_D(QPieSlice);
403 if (d->m_data.m_labelFont != font) {
403 if (d->m_data.m_labelFont != font) {
404 d->m_data.m_labelFont = font;
404 d->m_data.m_labelFont = font;
405 d->m_data.m_labelFont.setThemed(false);
405 d->m_data.m_labelFont.setThemed(false);
406 emit changed();
406 emit changed();
407 }
407 }
408 }
408 }
409
409
410 /*!
410 /*!
411 Sets the label arm length \a factor.
411 Sets the label arm length \a factor.
412
412
413 The factor is relative to pie radius. For example:
413 The factor is relative to pie radius. For example:
414 1.0 means the length is the same as the radius.
414 1.0 means the length is the same as the radius.
415 0.5 means the length is half of the radius.
415 0.5 means the length is half of the radius.
416
416
417 Default value is 0.15
417 Default value is 0.15
418
418
419 \sa labelArmLengthFactor()
419 \sa labelArmLengthFactor()
420 */
420 */
421 void QPieSlice::setLabelArmLengthFactor(qreal factor)
421 void QPieSlice::setLabelArmLengthFactor(qreal factor)
422 {
422 {
423 Q_D(QPieSlice);
423 Q_D(QPieSlice);
424 if (!qFuzzyIsNull(d->m_data.m_labelArmLengthFactor - factor)) {
424 if (!qFuzzyIsNull(d->m_data.m_labelArmLengthFactor - factor)) {
425 d->m_data.m_labelArmLengthFactor = factor;
425 d->m_data.m_labelArmLengthFactor = factor;
426 emit changed();
426 emit changed();
427 }
427 }
428 }
428 }
429
429
430 #include "moc_qpieslice.cpp"
430 #include "moc_qpieslice.cpp"
431 #include "moc_qpiesliceprivate_p.cpp"
431 #include "moc_qpiesliceprivate_p.cpp"
432
432
433 QTCOMMERCIALCHART_END_NAMESPACE
433 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,118 +1,118
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qchart.h"
22 #include "qchart.h"
23
23
24 /*!
24 /*!
25 \class QScatterSeries
25 \class QScatterSeries
26 \brief The QScatterSeries class is used for making scatter charts.
26 \brief The QScatterSeries class is used for making scatter charts.
27
27
28 \mainclass
28 \mainclass
29
29
30 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
30 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
31 and the vertical axis.
31 and the vertical axis.
32
32
33 \image scatterchart.png
33 \image scatterchart.png
34
34
35 Creating basic scatter chart is simple:
35 Creating basic scatter chart is simple:
36 \code
36 \code
37 QScatterSeries* series = new QScatterSeries();
37 QScatterSeries* series = new QScatterSeries();
38 series->add(0, 6);
38 series->append(0, 6);
39 series->add(2, 4);
39 series->append(2, 4);
40 ...
40 ...
41 chartView->addSeries(series);
41 chartView->addSeries(series);
42 \endcode
42 \endcode
43 */
43 */
44
44
45 /*!
45 /*!
46 \enum QScatterSeries::MarkerShape
46 \enum QScatterSeries::MarkerShape
47
47
48 This enum describes the shape used when rendering marker items.
48 This enum describes the shape used when rendering marker items.
49
49
50 \value MarkerShapeCircle
50 \value MarkerShapeCircle
51 \value MarkerShapeRectangle
51 \value MarkerShapeRectangle
52 */
52 */
53
53
54 /*!
54 /*!
55 \fn QChartSeriesType QScatterSeries::type() const
55 \fn QChartSeriesType QScatterSeries::type() const
56 \brief Returns QChartSeries::SeriesTypeScatter.
56 \brief Returns QChartSeries::SeriesTypeScatter.
57 \sa QSeries, QSeriesType
57 \sa QSeries, QSeriesType
58 */
58 */
59
59
60 QTCOMMERCIALCHART_BEGIN_NAMESPACE
60 QTCOMMERCIALCHART_BEGIN_NAMESPACE
61
61
62 /*!
62 /*!
63 Constructs a series object which is a child of \a parent.
63 Constructs a series object which is a child of \a parent.
64 */
64 */
65 QScatterSeries::QScatterSeries(QObject *parent) :
65 QScatterSeries::QScatterSeries(QObject *parent) :
66 QXYSeries(parent),
66 QXYSeries(parent),
67 m_shape(QScatterSeries::MarkerShapeCircle),
67 m_shape(QScatterSeries::MarkerShapeCircle),
68 m_size(15.0)
68 m_size(15.0)
69 {
69 {
70 }
70 }
71
71
72 /*!
72 /*!
73 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
73 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
74 */
74 */
75 QScatterSeries::~QScatterSeries()
75 QScatterSeries::~QScatterSeries()
76 {
76 {
77 }
77 }
78
78
79 /*!
79 /*!
80 Returns the shape used for drawing markers.
80 Returns the shape used for drawing markers.
81 */
81 */
82 QScatterSeries::MarkerShape QScatterSeries::shape() const
82 QScatterSeries::MarkerShape QScatterSeries::shape() const
83 {
83 {
84 return m_shape;
84 return m_shape;
85 }
85 }
86
86
87 /*!
87 /*!
88 Overrides the default shape of the marker items with a user defined \a shape. The default shape
88 Overrides the default shape of the marker items with a user defined \a shape. The default shape
89 is defined by chart theme setting.
89 is defined by chart theme setting.
90 */
90 */
91 void QScatterSeries::setShape(MarkerShape shape)
91 void QScatterSeries::setShape(MarkerShape shape)
92 {
92 {
93 if (m_shape != shape) {
93 if (m_shape != shape) {
94 m_shape = shape;
94 m_shape = shape;
95 emit QXYSeries::updated();
95 emit QXYSeries::updated();
96 }
96 }
97 }
97 }
98
98
99 /*!
99 /*!
100 Returns the size of the marker items.
100 Returns the size of the marker items.
101 */
101 */
102 qreal QScatterSeries::size() const
102 qreal QScatterSeries::size() const
103 {
103 {
104 return m_size;
104 return m_size;
105 }
105 }
106
106
107 /*!
107 /*!
108 Set the \a size of the marker items. The default size is 9.0.
108 Set the \a size of the marker items. The default size is 9.0.
109 */
109 */
110 void QScatterSeries::setSize(qreal size)
110 void QScatterSeries::setSize(qreal size)
111 {
111 {
112 if (!qFuzzyIsNull(m_size - size)) {
112 if (!qFuzzyIsNull(m_size - size)) {
113 m_size = size;
113 m_size = size;
114 emit updated();
114 emit updated();
115 }
115 }
116 }
116 }
117
117
118 QTCOMMERCIALCHART_END_NAMESPACE
118 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,510 +1,510
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qxyseries.h"
21 #include "qxyseries.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QXYSeries
26 \class QXYSeries
27 \brief The QXYSeries class is a base class for line, spline and scatter series.
27 \brief The QXYSeries class is a base class for line, spline and scatter series.
28 */
28 */
29
29
30 /*!
30 /*!
31 \fn QPen QXYSeries::pen() const
31 \fn QPen QXYSeries::pen() const
32 \brief Returns pen used to draw points for series.
32 \brief Returns pen used to draw points for series.
33 \sa setPen()
33 \sa setPen()
34 */
34 */
35
35
36 /*!
36 /*!
37 \fn QBrush QXYSeries::brush() const
37 \fn QBrush QXYSeries::brush() const
38 \brief Returns brush used to draw points for series.
38 \brief Returns brush used to draw points for series.
39 \sa setBrush()
39 \sa setBrush()
40 */
40 */
41
41
42 /*!
42 /*!
43 \fn void QXYSeries::clicked(const QPointF& point)
43 \fn void QXYSeries::clicked(const QPointF& point)
44 \brief Signal is emitted when user clicks the \a point on chart.
44 \brief Signal is emitted when user clicks the \a point on chart.
45 */
45 */
46
46
47 /*!
47 /*!
48 \fn void QXYSeries::pointReplaced(int index)
48 \fn void QXYSeries::pointReplaced(int index)
49 \brief \internal \a index
49 \brief \internal \a index
50 */
50 */
51
51
52 /*!
52 /*!
53 \fn void QXYSeries::pointAdded(int index)
53 \fn void QXYSeries::pointAdded(int index)
54 \brief \internal \a index
54 \brief \internal \a index
55 */
55 */
56
56
57 /*!
57 /*!
58 \fn void QXYSeries::pointRemoved(int index)
58 \fn void QXYSeries::pointRemoved(int index)
59 \brief \internal \a index
59 \brief \internal \a index
60 */
60 */
61
61
62 /*!
62 /*!
63 \fn void QXYSeries::updated()
63 \fn void QXYSeries::updated()
64 \brief \internal
64 \brief \internal
65 */
65 */
66
66
67 /*!
67 /*!
68 Constructs empty series object which is a child of \a parent.
68 Constructs empty series object which is a child of \a parent.
69 When series object is added to QChartView or QChart instance ownerships is transfered.
69 When series object is added to QChartView or QChart instance ownerships is transfered.
70 */
70 */
71 QXYSeries::QXYSeries(QObject *parent):QSeries(parent)
71 QXYSeries::QXYSeries(QObject *parent):QSeries(parent)
72 {
72 {
73 m_mapX = -1;
73 m_mapX = -1;
74 m_mapY = -1;
74 m_mapY = -1;
75 m_mapFirst = 0;
75 m_mapFirst = 0;
76 m_mapCount = 0;
76 m_mapCount = 0;
77 m_mapLimited = false;
77 m_mapLimited = false;
78 m_mapOrientation = Qt::Vertical;
78 m_mapOrientation = Qt::Vertical;
79 // m_mapYOrientation = Qt::Vertical;
79 // m_mapYOrientation = Qt::Vertical;
80 }
80 }
81 /*!
81 /*!
82 Destroys the object. Series added to QChartView or QChart instances are owned by those,
82 Destroys the object. Series added to QChartView or QChart instances are owned by those,
83 and are deleted when mentioned object are destroyed.
83 and are deleted when mentioned object are destroyed.
84 */
84 */
85 QXYSeries::~QXYSeries()
85 QXYSeries::~QXYSeries()
86 {
86 {
87 }
87 }
88
88
89 /*!
89 /*!
90 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
90 Adds data point \a x \a y to the series. Points are connected with lines on the chart.
91 */
91 */
92 void QXYSeries::add(qreal x,qreal y)
92 void QXYSeries::append(qreal x,qreal y)
93 {
93 {
94 Q_ASSERT(m_x.size() == m_y.size());
94 Q_ASSERT(m_x.size() == m_y.size());
95 m_x<<x;
95 m_x<<x;
96 m_y<<y;
96 m_y<<y;
97 emit pointAdded(m_x.size()-1);
97 emit pointAdded(m_x.size()-1);
98 }
98 }
99
99
100 /*!
100 /*!
101 This is an overloaded function.
101 This is an overloaded function.
102 Adds data \a point to the series. Points are connected with lines on the chart.
102 Adds data \a point to the series. Points are connected with lines on the chart.
103 */
103 */
104 void QXYSeries::add(const QPointF &point)
104 void QXYSeries::append(const QPointF &point)
105 {
105 {
106 add(point.x(),point.y());
106 append(point.x(),point.y());
107 }
107 }
108
108
109 /*!
109 /*!
110 This is an overloaded function.
110 This is an overloaded function.
111 Adds list of data \a points to the series. Points are connected with lines on the chart.
111 Adds list of data \a points to the series. Points are connected with lines on the chart.
112 */
112 */
113 void QXYSeries::add(const QList<QPointF> points)
113 void QXYSeries::append(const QList<QPointF> points)
114 {
114 {
115 foreach(const QPointF& point , points) {
115 foreach(const QPointF& point , points) {
116 add(point.x(),point.y());
116 append(point.x(),point.y());
117 }
117 }
118 }
118 }
119
119
120 /*!
120 /*!
121 Modifies \a y value for given \a x a value.
121 Modifies \a y value for given \a x a value.
122 */
122 */
123 void QXYSeries::replace(qreal x,qreal y)
123 void QXYSeries::replace(qreal x,qreal y)
124 {
124 {
125 int index = m_x.indexOf(x);
125 int index = m_x.indexOf(x);
126 m_x[index] = x;
126 m_x[index] = x;
127 m_y[index] = y;
127 m_y[index] = y;
128 emit pointReplaced(index);
128 emit pointReplaced(index);
129 }
129 }
130
130
131 /*!
131 /*!
132 This is an overloaded function.
132 This is an overloaded function.
133 Replaces current y value of for given \a point x value with \a point y value.
133 Replaces current y value of for given \a point x value with \a point y value.
134 */
134 */
135 void QXYSeries::replace(const QPointF &point)
135 void QXYSeries::replace(const QPointF &point)
136 {
136 {
137 replace(point.x(),point.y());
137 replace(point.x(),point.y());
138 }
138 }
139
139
140 /*!
140 /*!
141 Removes first \a x value and related y value.
141 Removes first \a x value and related y value.
142 */
142 */
143 void QXYSeries::remove(qreal x)
143 void QXYSeries::remove(qreal x)
144 {
144 {
145 int index = m_x.indexOf(x);
145 int index = m_x.indexOf(x);
146
146
147 if (index == -1) return;
147 if (index == -1) return;
148
148
149 m_x.remove(index);
149 m_x.remove(index);
150 m_y.remove(index);
150 m_y.remove(index);
151
151
152 emit pointRemoved(index);
152 emit pointRemoved(index);
153 }
153 }
154
154
155 /*!
155 /*!
156 Removes current \a x and \a y value.
156 Removes current \a x and \a y value.
157 */
157 */
158 void QXYSeries::remove(qreal x,qreal y)
158 void QXYSeries::remove(qreal x,qreal y)
159 {
159 {
160 int index =-1;
160 int index =-1;
161 do {
161 do {
162 index = m_x.indexOf(x,index+1);
162 index = m_x.indexOf(x,index+1);
163 } while (index !=-1 && m_y.at(index)!=y);
163 } while (index !=-1 && m_y.at(index)!=y);
164
164
165 if (index==-1) return;
165 if (index==-1) return;
166
166
167 m_x.remove(index);
167 m_x.remove(index);
168 m_y.remove(index);
168 m_y.remove(index);
169 emit pointRemoved(index);
169 emit pointRemoved(index);
170 }
170 }
171
171
172 /*!
172 /*!
173 Removes current \a point x value. Note \a point y value is ignored.
173 Removes current \a point x value. Note \a point y value is ignored.
174 */
174 */
175 void QXYSeries::remove(const QPointF &point)
175 void QXYSeries::remove(const QPointF &point)
176 {
176 {
177 remove(point.x(),point.y());
177 remove(point.x(),point.y());
178 }
178 }
179
179
180 /*!
180 /*!
181 Removes all data points from the series.
181 Removes all data points from the series.
182 */
182 */
183 void QXYSeries::removeAll()
183 void QXYSeries::removeAll()
184 {
184 {
185 m_x.clear();
185 m_x.clear();
186 m_y.clear();
186 m_y.clear();
187 }
187 }
188
188
189 /*!
189 /*!
190 \internal \a pos
190 \internal \a pos
191 */
191 */
192 qreal QXYSeries::x(int pos) const
192 qreal QXYSeries::x(int pos) const
193 {
193 {
194 if (m_model) {
194 if (m_model) {
195 if (m_mapOrientation == Qt::Vertical)
195 if (m_mapOrientation == Qt::Vertical)
196 // consecutive data is read from model's column
196 // consecutive data is read from model's column
197 return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble();
197 return m_model->data(m_model->index(pos + m_mapFirst, m_mapX), Qt::DisplayRole).toDouble();
198 else
198 else
199 // consecutive data is read from model's row
199 // consecutive data is read from model's row
200 return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble();
200 return m_model->data(m_model->index(m_mapX, pos + m_mapFirst), Qt::DisplayRole).toDouble();
201 } else {
201 } else {
202 // model is not specified, return the data from series' internal data store
202 // model is not specified, return the data from series' internal data store
203 return m_x.at(pos);
203 return m_x.at(pos);
204 }
204 }
205 }
205 }
206
206
207 /*!
207 /*!
208 \internal \a pos
208 \internal \a pos
209 */
209 */
210 qreal QXYSeries::y(int pos) const
210 qreal QXYSeries::y(int pos) const
211 {
211 {
212 if (m_model) {
212 if (m_model) {
213 if (m_mapOrientation == Qt::Vertical)
213 if (m_mapOrientation == Qt::Vertical)
214 // consecutive data is read from model's column
214 // consecutive data is read from model's column
215 return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble();
215 return m_model->data(m_model->index(pos + m_mapFirst, m_mapY), Qt::DisplayRole).toDouble();
216 else
216 else
217 // consecutive data is read from model's row
217 // consecutive data is read from model's row
218 return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble();
218 return m_model->data(m_model->index(m_mapY, pos + m_mapFirst), Qt::DisplayRole).toDouble();
219 } else {
219 } else {
220 // model is not specified, return the data from series' internal data store
220 // model is not specified, return the data from series' internal data store
221 return m_y.at(pos);
221 return m_y.at(pos);
222 }
222 }
223 }
223 }
224
224
225 /*!
225 /*!
226 Returns number of data points within series.
226 Returns number of data points within series.
227 */
227 */
228 int QXYSeries::count() const
228 int QXYSeries::count() const
229 {
229 {
230 Q_ASSERT(m_x.size() == m_y.size());
230 Q_ASSERT(m_x.size() == m_y.size());
231
231
232 if (m_model) {
232 if (m_model) {
233 if (m_mapOrientation == Qt::Vertical) {
233 if (m_mapOrientation == Qt::Vertical) {
234 // data is in a column. Return the number of mapped items if the model's column have enough items
234 // data is in a column. Return the number of mapped items if the model's column have enough items
235 // or the number of items that can be mapped
235 // or the number of items that can be mapped
236 if (m_mapLimited)
236 if (m_mapLimited)
237 return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0));
237 return qMin(m_mapCount, qMax(m_model->rowCount() - m_mapFirst, 0));
238 else
238 else
239 return qMax(m_model->rowCount() - m_mapFirst, 0);
239 return qMax(m_model->rowCount() - m_mapFirst, 0);
240 } else {
240 } else {
241 // data is in a row. Return the number of mapped items if the model's row have enough items
241 // data is in a row. Return the number of mapped items if the model's row have enough items
242 // or the number of items that can be mapped
242 // or the number of items that can be mapped
243 if (m_mapLimited)
243 if (m_mapLimited)
244 return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0));
244 return qMin(m_mapCount, qMax(m_model->columnCount() - m_mapFirst, 0));
245 else
245 else
246 return qMax(m_model->columnCount() - m_mapFirst, 0);
246 return qMax(m_model->columnCount() - m_mapFirst, 0);
247 }
247 }
248 }
248 }
249
249
250 // model is not specified, return the number of points in the series internal data store
250 // model is not specified, return the number of points in the series internal data store
251 return m_x.size();
251 return m_x.size();
252 }
252 }
253
253
254 /*!
254 /*!
255 Returns the data points of the series.
255 Returns the data points of the series.
256 */
256 */
257 QList<QPointF> QXYSeries::data()
257 QList<QPointF> QXYSeries::data()
258 {
258 {
259 QList<QPointF> data;
259 QList<QPointF> data;
260 for (int i(0); i < m_x.count() && i < m_y.count(); i++)
260 for (int i(0); i < m_x.count() && i < m_y.count(); i++)
261 data.append(QPointF(m_x.at(i), m_y.at(i)));
261 data.append(QPointF(m_x.at(i), m_y.at(i)));
262 return data;
262 return data;
263 }
263 }
264
264
265
265
266 /*!
266 /*!
267 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
267 Sets \a pen used for drawing points on the chart. If the pen is not defined, the
268 pen from chart theme is used.
268 pen from chart theme is used.
269 \sa QChart::setChartTheme()
269 \sa QChart::setChartTheme()
270 */
270 */
271 void QXYSeries::setPen(const QPen &pen)
271 void QXYSeries::setPen(const QPen &pen)
272 {
272 {
273 if (pen != m_pen) {
273 if (pen != m_pen) {
274 m_pen = pen;
274 m_pen = pen;
275 emit updated();
275 emit updated();
276 }
276 }
277 }
277 }
278
278
279 /*!
279 /*!
280 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
280 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
281 from chart theme setting is used.
281 from chart theme setting is used.
282 \sa QChart::setChartTheme()
282 \sa QChart::setChartTheme()
283 */
283 */
284
284
285 void QXYSeries::setBrush(const QBrush &brush)
285 void QXYSeries::setBrush(const QBrush &brush)
286 {
286 {
287 if (brush != m_brush) {
287 if (brush != m_brush) {
288 m_brush = brush;
288 m_brush = brush;
289 emit updated();
289 emit updated();
290 }
290 }
291 }
291 }
292
292
293
293
294 /*!
294 /*!
295 Stream operator for adding a data \a point to the series.
295 Stream operator for adding a data \a point to the series.
296 \sa add()
296 \sa append()
297 */
297 */
298
298
299 QXYSeries& QXYSeries::operator<< (const QPointF &point)
299 QXYSeries& QXYSeries::operator<< (const QPointF &point)
300 {
300 {
301 add(point);
301 append(point);
302 return *this;
302 return *this;
303 }
303 }
304
304
305
305
306 /*!
306 /*!
307 Stream operator for adding a list of \a points to the series.
307 Stream operator for adding a list of \a points to the series.
308 \sa add()
308 \sa append()
309 */
309 */
310
310
311 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
311 QXYSeries& QXYSeries::operator<< (const QList<QPointF> points)
312 {
312 {
313 add(points);
313 append(points);
314 return *this;
314 return *this;
315 }
315 }
316
316
317
317
318 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
318 void QXYSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
319 {
319 {
320 Q_UNUSED(bottomRight)
320 Q_UNUSED(bottomRight)
321
321
322 if (m_mapOrientation == Qt::Vertical) {
322 if (m_mapOrientation == Qt::Vertical) {
323 if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount))
323 if (topLeft.row() >= m_mapFirst && (!m_mapLimited || topLeft.row() < m_mapFirst + m_mapCount))
324 emit pointReplaced(topLeft.row() - m_mapFirst);
324 emit pointReplaced(topLeft.row() - m_mapFirst);
325 } else {
325 } else {
326 if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount))
326 if (topLeft.column() >= m_mapFirst && (!m_mapLimited || topLeft.column() < m_mapFirst + m_mapCount))
327 emit pointReplaced(topLeft.column() - m_mapFirst);
327 emit pointReplaced(topLeft.column() - m_mapFirst);
328 }
328 }
329 }
329 }
330
330
331 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end)
331 void QXYSeries::modelDataAboutToBeAdded(QModelIndex parent, int start, int end)
332 {
332 {
333 Q_UNUSED(parent)
333 Q_UNUSED(parent)
334 // Q_UNUSED(end)
334 // Q_UNUSED(end)
335
335
336 if (m_mapLimited) {
336 if (m_mapLimited) {
337 if (start >= m_mapFirst + m_mapCount) {
337 if (start >= m_mapFirst + m_mapCount) {
338 // the added data is below mapped area
338 // the added data is below mapped area
339 // therefore it has no relevance
339 // therefore it has no relevance
340 return;
340 return;
341 } else {
341 } else {
342 // the added data is in the mapped area or before it and update is needed
342 // the added data is in the mapped area or before it and update is needed
343
343
344 // check how many mapped items there is currently (before new items are added)
344 // check how many mapped items there is currently (before new items are added)
345 // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem
345 // if the number of items currently is equal the m_mapCount then some needs to be removed from xychartitem
346 // internal storage before new ones can be added
346 // internal storage before new ones can be added
347
347
348 int itemsToRemove = qMin(count() - (start - m_mapFirst), end - start + 1);
348 int itemsToRemove = qMin(count() - (start - m_mapFirst), end - start + 1);
349 if (m_mapCount == count()) {
349 if (m_mapCount == count()) {
350 for (int i = 0; i < itemsToRemove; i++)
350 for (int i = 0; i < itemsToRemove; i++)
351 emit pointRemoved(count() - 1 - i);
351 emit pointRemoved(count() - 1 - i);
352 }
352 }
353 }
353 }
354 } else {
354 } else {
355 // map is not limited (it includes all the items starting from m_mapFirst till the end of model)
355 // map is not limited (it includes all the items starting from m_mapFirst till the end of model)
356 // nothing to do
356 // nothing to do
357 // emit pointAdded(qMax(start - m_mapFirst, 0));
357 // emit pointAdded(qMax(start - m_mapFirst, 0));
358 }
358 }
359 }
359 }
360
360
361 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
361 void QXYSeries::modelDataAdded(QModelIndex parent, int start, int end)
362 {
362 {
363 Q_UNUSED(parent)
363 Q_UNUSED(parent)
364 // Q_UNUSED(end)
364 // Q_UNUSED(end)
365
365
366 if (m_mapLimited) {
366 if (m_mapLimited) {
367 if (start >= m_mapFirst + m_mapCount) {
367 if (start >= m_mapFirst + m_mapCount) {
368 // the added data is below mapped area
368 // the added data is below mapped area
369 // therefore it has no relevance
369 // therefore it has no relevance
370 return;
370 return;
371 } else {
371 } else {
372 // the added data is in the mapped area or before it
372 // the added data is in the mapped area or before it
373 // update needed
373 // update needed
374 if (count() > 0) {
374 if (count() > 0) {
375 for (int i = 0; i < qMin(m_mapCount - (start - m_mapFirst), end - start + 1); i++)
375 for (int i = 0; i < qMin(m_mapCount - (start - m_mapFirst), end - start + 1); i++)
376 emit pointAdded(qMax(start + i - m_mapFirst, 0));
376 emit pointAdded(qMax(start + i - m_mapFirst, 0));
377 }
377 }
378 }
378 }
379 } else {
379 } else {
380 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
380 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
381 for (int i = 0; i < end - start + 1; i++)
381 for (int i = 0; i < end - start + 1; i++)
382 emit pointAdded(qMax(start + i - m_mapFirst, 0));
382 emit pointAdded(qMax(start + i - m_mapFirst, 0));
383 }
383 }
384 }
384 }
385
385
386 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end)
386 void QXYSeries::modelDataAboutToBeRemoved(QModelIndex parent, int start, int end)
387 {
387 {
388 Q_UNUSED(parent)
388 Q_UNUSED(parent)
389 // Q_UNUSED(end)
389 // Q_UNUSED(end)
390
390
391 if (m_mapLimited) {
391 if (m_mapLimited) {
392 if (start >= m_mapFirst + m_mapCount) {
392 if (start >= m_mapFirst + m_mapCount) {
393 // the removed data is below mapped area
393 // the removed data is below mapped area
394 // therefore it has no relevance
394 // therefore it has no relevance
395 return;
395 return;
396 } else {
396 } else {
397 // the removed data is in the mapped area or before it
397 // the removed data is in the mapped area or before it
398 // update needed
398 // update needed
399
399
400 // check how many items need to be removed from the xychartitem storage
400 // check how many items need to be removed from the xychartitem storage
401 // the number equals the number of items that are removed and that lay before
401 // the number equals the number of items that are removed and that lay before
402 // or in the mapped area. Items that lay beyond the map do not count
402 // or in the mapped area. Items that lay beyond the map do not count
403 // the max is the current number of items in storage (count())
403 // the max is the current number of items in storage (count())
404 int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
404 int itemsToRemove = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - start + 1);
405 for (int i = 0; i < itemsToRemove; i++)
405 for (int i = 0; i < itemsToRemove; i++)
406 emit pointRemoved(qMax(start - m_mapFirst, 0));
406 emit pointRemoved(qMax(start - m_mapFirst, 0));
407 }
407 }
408 } else {
408 } else {
409 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
409 // map is not limited (it included all the items starting from m_mapFirst till the end of model)
410 for (int i = 0; i < end - start + 1; i++)
410 for (int i = 0; i < end - start + 1; i++)
411 emit pointRemoved(qMax(start - m_mapFirst, 0));
411 emit pointRemoved(qMax(start - m_mapFirst, 0));
412 }
412 }
413 }
413 }
414
414
415 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
415 void QXYSeries::modelDataRemoved(QModelIndex parent, int start, int end)
416 {
416 {
417 Q_UNUSED(parent)
417 Q_UNUSED(parent)
418 Q_UNUSED(end)
418 Q_UNUSED(end)
419
419
420 // how many items there were before data was removed
420 // how many items there were before data was removed
421 // int oldCount = count() - 1;
421 // int oldCount = count() - 1;
422
422
423 if (m_mapLimited) {
423 if (m_mapLimited) {
424 if (start >= m_mapFirst + m_mapCount) {
424 if (start >= m_mapFirst + m_mapCount) {
425 // the removed data is below mapped area
425 // the removed data is below mapped area
426 // therefore it has no relevance
426 // therefore it has no relevance
427 return;
427 return;
428 } else {
428 } else {
429 // if the current items count in the whole model is bigger than the index of the last item
429 // if the current items count in the whole model is bigger than the index of the last item
430 // that was removed than it means there are some extra items available
430 // that was removed than it means there are some extra items available
431 int extraItemsAvailable = 0;
431 int extraItemsAvailable = 0;
432 if (m_mapOrientation == Qt::Vertical) {
432 if (m_mapOrientation == Qt::Vertical) {
433 extraItemsAvailable = qMax(m_model->rowCount() - end, 0);
433 extraItemsAvailable = qMax(m_model->rowCount() - end, 0);
434 } else {
434 } else {
435 extraItemsAvailable = qMax(m_model->columnCount() - end, 0);
435 extraItemsAvailable = qMax(m_model->columnCount() - end, 0);
436 }
436 }
437
437
438 // if there are excess items available (below the mapped area) use them to repopulate mapped area
438 // if there are excess items available (below the mapped area) use them to repopulate mapped area
439 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - qMax(start, m_mapFirst) + 1);
439 int removedItemsCount = qMin(count(), qMin(end, m_mapFirst + m_mapCount - 1) - qMax(start, m_mapFirst) + 1);
440 int toBeAdded = qMin(extraItemsAvailable, removedItemsCount);
440 int toBeAdded = qMin(extraItemsAvailable, removedItemsCount);
441 for (int k = 0; k < toBeAdded; k++)
441 for (int k = 0; k < toBeAdded; k++)
442 emit pointAdded(qMax(start - m_mapFirst, m_mapFirst) + k);
442 emit pointAdded(qMax(start - m_mapFirst, m_mapFirst) + k);
443 }
443 }
444 } else {
444 } else {
445 // data was removed from XYSeries interal storage. Nothing more to do
445 // data was removed from XYSeries interal storage. Nothing more to do
446 }
446 }
447 }
447 }
448
448
449 bool QXYSeries::setModel(QAbstractItemModel *model) {
449 bool QXYSeries::setModel(QAbstractItemModel *model) {
450
450
451 // disconnect signals from old model
451 // disconnect signals from old model
452 if (m_model) {
452 if (m_model) {
453 disconnect(m_model, 0, this, 0);
453 disconnect(m_model, 0, this, 0);
454 m_mapX = -1;
454 m_mapX = -1;
455 m_mapY = -1;
455 m_mapY = -1;
456 m_mapFirst = 0;
456 m_mapFirst = 0;
457 m_mapCount = 0;
457 m_mapCount = 0;
458 m_mapLimited = false;
458 m_mapLimited = false;
459 m_mapOrientation = Qt::Vertical;
459 m_mapOrientation = Qt::Vertical;
460 }
460 }
461
461
462 // set new model
462 // set new model
463 if (model) {
463 if (model) {
464 m_model = model;
464 m_model = model;
465 return true;
465 return true;
466 } else {
466 } else {
467 m_model = 0;
467 m_model = 0;
468 return false;
468 return false;
469 }
469 }
470 }
470 }
471
471
472 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
472 void QXYSeries::setModelMapping(int modelX, int modelY, Qt::Orientation orientation)
473 {
473 {
474 if (m_model == 0)
474 if (m_model == 0)
475 return;
475 return;
476 m_mapX = modelX;
476 m_mapX = modelX;
477 m_mapY = modelY;
477 m_mapY = modelY;
478 m_mapFirst = 0;
478 m_mapFirst = 0;
479 m_mapOrientation = orientation;
479 m_mapOrientation = orientation;
480 if (m_mapOrientation == Qt::Vertical) {
480 if (m_mapOrientation == Qt::Vertical) {
481 // m_mapCount = m_model->rowCount();
481 // m_mapCount = m_model->rowCount();
482 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
482 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
483 connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
483 connect(m_model,SIGNAL(rowsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
484 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
484 connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
485 connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
485 connect(m_model, SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
486 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
486 connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
487 } else {
487 } else {
488 // m_mapCount = m_model->columnCount();
488 // m_mapCount = m_model->columnCount();
489 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
489 connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex, QModelIndex)));
490 connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
490 connect(m_model,SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeAdded(QModelIndex,int,int)));
491 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
491 connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), this, SLOT(modelDataAdded(QModelIndex,int,int)));
492 connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
492 connect(m_model, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)), this, SLOT(modelDataAboutToBeRemoved(QModelIndex,int,int)));
493 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
493 connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), this, SLOT(modelDataRemoved(QModelIndex,int,int)));
494 }
494 }
495 }
495 }
496
496
497 void QXYSeries::setModelMappingShift(int first, int count)
497 void QXYSeries::setModelMappingShift(int first, int count)
498 {
498 {
499 m_mapFirst = first;
499 m_mapFirst = first;
500 if (count == 0) {
500 if (count == 0) {
501 m_mapLimited = false;
501 m_mapLimited = false;
502 } else {
502 } else {
503 m_mapCount = count;
503 m_mapCount = count;
504 m_mapLimited = true;
504 m_mapLimited = true;
505 }
505 }
506 }
506 }
507
507
508 #include "moc_qxyseries.cpp"
508 #include "moc_qxyseries.cpp"
509
509
510 QTCOMMERCIALCHART_END_NAMESPACE
510 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,100 +1,100
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QXYSERIES_H_
21 #ifndef QXYSERIES_H_
22 #define QXYSERIES_H_
22 #define QXYSERIES_H_
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <qseries.h>
25 #include <qseries.h>
26 #include <QPen>
26 #include <QPen>
27 #include <QBrush>
27 #include <QBrush>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
31 class QTCOMMERCIALCHART_EXPORT QXYSeries : public QSeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 protected:
34 protected:
35 QXYSeries(QObject *parent = 0);
35 QXYSeries(QObject *parent = 0);
36 virtual ~QXYSeries();
36 virtual ~QXYSeries();
37
37
38 public:
38 public:
39 void add(qreal x, qreal y);
39 void append(qreal x, qreal y);
40 void add(const QPointF &point);
40 void append(const QPointF &point);
41 void add(const QList<QPointF> points);
41 void append(const QList<QPointF> points);
42 void replace(qreal x,qreal y);
42 void replace(qreal x,qreal y);
43 void replace(const QPointF &point);
43 void replace(const QPointF &point);
44 void remove(qreal x);
44 void remove(qreal x);
45 void remove(qreal x, qreal y);
45 void remove(qreal x, qreal y);
46 void remove(const QPointF &point);
46 void remove(const QPointF &point);
47 void removeAll();
47 void removeAll();
48
48
49 int count() const;
49 int count() const;
50 qreal x(int pos) const;
50 qreal x(int pos) const;
51 qreal y(int pos) const;
51 qreal y(int pos) const;
52 QList<QPointF> data();
52 QList<QPointF> data();
53
53
54 QXYSeries& operator << (const QPointF &point);
54 QXYSeries& operator << (const QPointF &point);
55 QXYSeries& operator << (const QList<QPointF> points);
55 QXYSeries& operator << (const QList<QPointF> points);
56
56
57 void setPen(const QPen &pen);
57 void setPen(const QPen &pen);
58 QPen pen() const {return m_pen;}
58 QPen pen() const {return m_pen;}
59 void setBrush(const QBrush &brush);
59 void setBrush(const QBrush &brush);
60 QBrush brush() const {return m_brush;}
60 QBrush brush() const {return m_brush;}
61
61
62 bool setModel(QAbstractItemModel *model);
62 bool setModel(QAbstractItemModel *model);
63 QAbstractItemModel* model() const { return m_model; }
63 QAbstractItemModel* model() const { return m_model; }
64
64
65 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
65 virtual void setModelMapping(int modelX, int modelY, Qt::Orientation orientation = Qt::Vertical);
66 virtual void setModelMappingShift(int first, int count = 0);
66 virtual void setModelMappingShift(int first, int count = 0);
67
67
68 private Q_SLOTS:
68 private Q_SLOTS:
69 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
69 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
70 void modelDataAboutToBeAdded(QModelIndex parent, int start, int end);
70 void modelDataAboutToBeAdded(QModelIndex parent, int start, int end);
71 void modelDataAdded(QModelIndex parent, int start, int end);
71 void modelDataAdded(QModelIndex parent, int start, int end);
72 void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end);
72 void modelDataAboutToBeRemoved(QModelIndex parent, int start, int end);
73 void modelDataRemoved(QModelIndex parent, int start, int end);
73 void modelDataRemoved(QModelIndex parent, int start, int end);
74
74
75 Q_SIGNALS:
75 Q_SIGNALS:
76 void clicked(const QPointF &point);
76 void clicked(const QPointF &point);
77 void updated();
77 void updated();
78 void pointReplaced(int index);
78 void pointReplaced(int index);
79 void pointRemoved(int index);
79 void pointRemoved(int index);
80 void pointAdded(int index);
80 void pointAdded(int index);
81
81
82 protected:
82 protected:
83 QVector<qreal> m_x;
83 QVector<qreal> m_x;
84 QVector<qreal> m_y;
84 QVector<qreal> m_y;
85
85
86 QPen m_pen;
86 QPen m_pen;
87 QBrush m_brush;
87 QBrush m_brush;
88
88
89 int m_mapX;
89 int m_mapX;
90 int m_mapY;
90 int m_mapY;
91 int m_mapFirst;
91 int m_mapFirst;
92 int m_mapCount;
92 int m_mapCount;
93 bool m_mapLimited;
93 bool m_mapLimited;
94 Qt::Orientation m_mapOrientation;
94 Qt::Orientation m_mapOrientation;
95 int tempItemsRemoved;
95 int tempItemsRemoved;
96 };
96 };
97
97
98 QTCOMMERCIALCHART_END_NAMESPACE
98 QTCOMMERCIALCHART_END_NAMESPACE
99
99
100 #endif
100 #endif
General Comments 0
You need to be logged in to leave comments. Login now