@@ -1,332 +1,332 | |||||
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 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). |
|
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | |
39 | ** |
|
39 | ** | |
40 | ****************************************************************************/ |
|
40 | ****************************************************************************/ | |
41 |
|
41 | |||
42 | #include "themewidget.h" |
|
42 | #include "themewidget.h" | |
43 |
|
43 | |||
44 | #include <QChartView> |
|
44 | #include <QChartView> | |
45 | #include <QPieSeries> |
|
45 | #include <QPieSeries> | |
46 | #include <QPieSlice> |
|
46 | #include <QPieSlice> | |
47 | #include <QBarSeries> |
|
47 | #include <QBarSeries> | |
48 | #include <QPercentBarSeries> |
|
48 | #include <QPercentBarSeries> | |
49 | #include <QStackedBarSeries> |
|
49 | #include <QStackedBarSeries> | |
50 | #include <QBarSet> |
|
50 | #include <QBarSet> | |
51 | #include <QLineSeries> |
|
51 | #include <QLineSeries> | |
52 | #include <QSplineSeries> |
|
52 | #include <QSplineSeries> | |
53 | #include <QScatterSeries> |
|
53 | #include <QScatterSeries> | |
54 | #include <QAreaSeries> |
|
54 | #include <QAreaSeries> | |
55 | #include <QGridLayout> |
|
55 | #include <QGridLayout> | |
56 | #include <QFormLayout> |
|
56 | #include <QFormLayout> | |
57 | #include <QComboBox> |
|
57 | #include <QComboBox> | |
58 | #include <QSpinBox> |
|
58 | #include <QSpinBox> | |
59 | #include <QCheckBox> |
|
59 | #include <QCheckBox> | |
60 | #include <QGroupBox> |
|
60 | #include <QGroupBox> | |
61 | #include <QLabel> |
|
61 | #include <QLabel> | |
62 | #include <QTime> |
|
62 | #include <QTime> | |
63 |
|
63 | |||
64 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
64 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
65 | QWidget(parent), |
|
65 | QWidget(parent), | |
66 | m_listCount(3), |
|
66 | m_listCount(3), | |
67 | m_valueMax(100), |
|
67 | m_valueMax(100), | |
68 | m_valueCount(11), |
|
68 | m_valueCount(11), | |
69 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
69 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
70 | m_themeComboBox(createThemeBox()), |
|
70 | m_themeComboBox(createThemeBox()), | |
71 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), |
|
71 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), | |
72 | m_animatedComboBox(createAnimationBox()) |
|
72 | m_animatedComboBox(createAnimationBox()) | |
73 | { |
|
73 | { | |
74 |
|
74 | |||
75 | connectSignals(); |
|
75 | connectSignals(); | |
76 | // create layout |
|
76 | // create layout | |
77 | QGridLayout* baseLayout = new QGridLayout(); |
|
77 | QGridLayout* baseLayout = new QGridLayout(); | |
78 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
78 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
79 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
79 | settingsLayout->addWidget(new QLabel("Theme:")); | |
80 | settingsLayout->addWidget(m_themeComboBox); |
|
80 | settingsLayout->addWidget(m_themeComboBox); | |
81 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
81 | settingsLayout->addWidget(new QLabel("Animation:")); | |
82 | settingsLayout->addWidget(m_animatedComboBox); |
|
82 | settingsLayout->addWidget(m_animatedComboBox); | |
83 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
83 | settingsLayout->addWidget(m_antialiasCheckBox); | |
84 | settingsLayout->addStretch(); |
|
84 | settingsLayout->addStretch(); | |
85 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
85 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
86 |
|
86 | |||
87 | //create charts |
|
87 | //create charts | |
88 |
|
88 | |||
89 | QChartView *chartView; |
|
89 | QChartView *chartView; | |
90 |
|
90 | |||
91 | chartView = new QChartView(createAreaChart()); |
|
91 | chartView = new QChartView(createAreaChart()); | |
92 | baseLayout->addWidget(chartView, 1, 0); |
|
92 | baseLayout->addWidget(chartView, 1, 0); | |
93 | m_charts << chartView; |
|
93 | m_charts << chartView; | |
94 |
|
94 | |||
95 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
95 | chartView = new QChartView(createBarChart(m_valueCount)); | |
96 | baseLayout->addWidget(chartView, 1, 1); |
|
96 | baseLayout->addWidget(chartView, 1, 1); | |
97 | m_charts << chartView; |
|
97 | m_charts << chartView; | |
98 |
|
98 | |||
99 | chartView = new QChartView(createLineChart()); |
|
99 | chartView = new QChartView(createLineChart()); | |
100 | baseLayout->addWidget(chartView, 1, 2); |
|
100 | baseLayout->addWidget(chartView, 1, 2); | |
101 | m_charts << chartView; |
|
101 | m_charts << chartView; | |
102 |
|
102 | |||
103 | chartView = new QChartView(createPieChart()); |
|
103 | chartView = new QChartView(createPieChart()); | |
104 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
104 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
105 | baseLayout->addWidget(chartView, 2, 0); |
|
105 | baseLayout->addWidget(chartView, 2, 0); | |
106 | m_charts << chartView; |
|
106 | m_charts << chartView; | |
107 |
|
107 | |||
108 | chartView = new QChartView(createSplineChart()); |
|
108 | chartView = new QChartView(createSplineChart()); | |
109 | baseLayout->addWidget(chartView, 2, 1); |
|
109 | baseLayout->addWidget(chartView, 2, 1); | |
110 | m_charts << chartView; |
|
110 | m_charts << chartView; | |
111 |
|
111 | |||
112 | chartView = new QChartView(createScatterChart()); |
|
112 | chartView = new QChartView(createScatterChart()); | |
113 | baseLayout->addWidget(chartView, 2, 2); |
|
113 | baseLayout->addWidget(chartView, 2, 2); | |
114 | m_charts << chartView; |
|
114 | m_charts << chartView; | |
115 |
|
115 | |||
116 | setLayout(baseLayout); |
|
116 | setLayout(baseLayout); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | ThemeWidget::~ThemeWidget() |
|
119 | ThemeWidget::~ThemeWidget() | |
120 | { |
|
120 | { | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void ThemeWidget::connectSignals() |
|
123 | void ThemeWidget::connectSignals() | |
124 | { |
|
124 | { | |
125 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
125 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
126 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
126 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
127 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
127 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
130 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
131 | { |
|
131 | { | |
132 | DataTable dataTable; |
|
132 | DataTable dataTable; | |
133 |
|
133 | |||
134 | // set seed for random stuff |
|
134 | // set seed for random stuff | |
135 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
135 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
136 |
|
136 | |||
137 | // generate random data |
|
137 | // generate random data | |
138 | for (int i(0); i < listCount; i++) { |
|
138 | for (int i(0); i < listCount; i++) { | |
139 | DataList dataList; |
|
139 | DataList dataList; | |
140 | for (int j(0); j < valueCount; j++) { |
|
140 | for (int j(0); j < valueCount; j++) { | |
141 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); |
|
141 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); | |
142 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); |
|
142 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); | |
143 | dataList << Data(value, label); |
|
143 | dataList << Data(value, label); | |
144 | } |
|
144 | } | |
145 | dataTable << dataList; |
|
145 | dataTable << dataList; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | return dataTable; |
|
148 | return dataTable; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | QComboBox* ThemeWidget::createThemeBox() const |
|
151 | QComboBox* ThemeWidget::createThemeBox() const | |
152 | { |
|
152 | { | |
153 | // settings layout |
|
153 | // settings layout | |
154 | QComboBox* themeComboBox = new QComboBox(); |
|
154 | QComboBox* themeComboBox = new QComboBox(); | |
155 | themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
155 | themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
156 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
156 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
157 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
157 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
158 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
158 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
159 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
159 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
160 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
160 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
161 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
161 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
162 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
162 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
163 | return themeComboBox; |
|
163 | return themeComboBox; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QComboBox* ThemeWidget::createAnimationBox() const |
|
166 | QComboBox* ThemeWidget::createAnimationBox() const | |
167 | { |
|
167 | { | |
168 | // settings layout |
|
168 | // settings layout | |
169 | QComboBox* animationComboBox = new QComboBox(); |
|
169 | QComboBox* animationComboBox = new QComboBox(); | |
170 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
170 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
171 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
171 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
172 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
172 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
173 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
173 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
174 | return animationComboBox; |
|
174 | return animationComboBox; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QChart* ThemeWidget::createAreaChart() const |
|
177 | QChart* ThemeWidget::createAreaChart() const | |
178 | { |
|
178 | { | |
179 | // area chart |
|
179 | // area chart | |
180 | QChart *chart = new QChart(); |
|
180 | QChart *chart = new QChart(); | |
181 | chart->setTitle("Area chart"); |
|
181 | chart->setTitle("Area chart"); | |
182 | { |
|
182 | { | |
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->add(data.first); | |
188 | series2->add(QPointF(data.first.x(), 0.0)); |
|
188 | series2->add(QPointF(data.first.x(), 0.0)); | |
189 | } |
|
189 | } | |
190 | QAreaSeries *area = new QAreaSeries(series1, series2); |
|
190 | QAreaSeries *area = new QAreaSeries(series1, series2); | |
191 | chart->addSeries(area); |
|
191 | chart->addSeries(area); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 | return chart; |
|
194 | return chart; | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
197 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
198 | { |
|
198 | { | |
199 | // bar chart |
|
199 | // bar chart | |
200 | QChart* chart = new QChart(); |
|
200 | QChart* chart = new QChart(); | |
201 | chart->setTitle("Bar chart"); |
|
201 | chart->setTitle("Bar chart"); | |
202 | { |
|
202 | { | |
203 | QBarCategories categories; |
|
203 | QBarCategories categories; | |
204 | // TODO: categories |
|
204 | // TODO: categories | |
205 | for (int i(0); i < valueCount; i++) |
|
205 | for (int i(0); i < valueCount; i++) | |
206 | categories << QString::number(i); |
|
206 | categories << QString::number(i); | |
207 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
207 | // QBarSeries* series = new QBarSeries(categories, chart); | |
208 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
208 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
209 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
209 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
210 | for (int i(0); i < m_dataTable.count(); i++) { |
|
210 | for (int i(0); i < m_dataTable.count(); i++) { | |
211 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
211 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
212 | foreach (Data data, m_dataTable[i]) |
|
212 | foreach (Data data, m_dataTable[i]) | |
213 | *set << data.first.y(); |
|
213 | *set << data.first.y(); | |
214 |
series->a |
|
214 | series->appendBarSet(set); | |
215 | } |
|
215 | } | |
216 | chart->addSeries(series); |
|
216 | chart->addSeries(series); | |
217 | } |
|
217 | } | |
218 | return chart; |
|
218 | return chart; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | QChart* ThemeWidget::createLineChart() const |
|
221 | QChart* ThemeWidget::createLineChart() const | |
222 | { |
|
222 | { | |
223 | // line chart |
|
223 | // line chart | |
224 | QChart* chart = new QChart(); |
|
224 | QChart* chart = new QChart(); | |
225 | chart->setTitle("Line chart"); |
|
225 | chart->setTitle("Line chart"); | |
226 | foreach (DataList list, m_dataTable) { |
|
226 | foreach (DataList list, m_dataTable) { | |
227 | QLineSeries *series = new QLineSeries(chart); |
|
227 | QLineSeries *series = new QLineSeries(chart); | |
228 | foreach (Data data, list) |
|
228 | foreach (Data data, list) | |
229 | series->add(data.first); |
|
229 | series->add(data.first); | |
230 | chart->addSeries(series); |
|
230 | chart->addSeries(series); | |
231 | } |
|
231 | } | |
232 | return chart; |
|
232 | return chart; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | QChart* ThemeWidget::createPieChart() const |
|
235 | QChart* ThemeWidget::createPieChart() const | |
236 | { |
|
236 | { | |
237 | // pie chart |
|
237 | // pie chart | |
238 | QChart* chart = new QChart(); |
|
238 | QChart* chart = new QChart(); | |
239 | chart->setTitle("Pie chart"); |
|
239 | chart->setTitle("Pie chart"); | |
240 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
240 | qreal pieSize = 1.0 / m_dataTable.count(); | |
241 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
241 | for (int i = 0; i < m_dataTable.count(); i++) { | |
242 | QPieSeries *series = new QPieSeries(chart); |
|
242 | QPieSeries *series = new QPieSeries(chart); | |
243 | foreach (Data data, m_dataTable[i]) { |
|
243 | foreach (Data data, m_dataTable[i]) { | |
244 | QPieSlice *slice = series->add(data.first.y(), data.second); |
|
244 | QPieSlice *slice = series->add(data.first.y(), data.second); | |
245 | if (data == m_dataTable[i].first()) { |
|
245 | if (data == m_dataTable[i].first()) { | |
246 | slice->setLabelVisible(); |
|
246 | slice->setLabelVisible(); | |
247 | slice->setExploded(); |
|
247 | slice->setExploded(); | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
250 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
251 | series->setPieSize(pieSize); |
|
251 | series->setPieSize(pieSize); | |
252 | series->setPiePosition(hPos, 0.5); |
|
252 | series->setPiePosition(hPos, 0.5); | |
253 | chart->addSeries(series); |
|
253 | chart->addSeries(series); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | return chart; |
|
256 | return chart; | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | QChart* ThemeWidget::createSplineChart() const |
|
259 | QChart* ThemeWidget::createSplineChart() const | |
260 | { // spine chart |
|
260 | { // spine chart | |
261 | QChart* chart = new QChart(); |
|
261 | QChart* chart = new QChart(); | |
262 | chart->setTitle("Spline chart"); |
|
262 | chart->setTitle("Spline chart"); | |
263 | foreach (DataList list, m_dataTable) { |
|
263 | foreach (DataList list, m_dataTable) { | |
264 | QSplineSeries *series = new QSplineSeries(chart); |
|
264 | QSplineSeries *series = new QSplineSeries(chart); | |
265 | foreach (Data data, list) |
|
265 | foreach (Data data, list) | |
266 | series->add(data.first); |
|
266 | series->add(data.first); | |
267 | chart->addSeries(series); |
|
267 | chart->addSeries(series); | |
268 | } |
|
268 | } | |
269 | return chart; |
|
269 | return chart; | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | QChart* ThemeWidget::createScatterChart() const |
|
272 | QChart* ThemeWidget::createScatterChart() const | |
273 | { // scatter chart |
|
273 | { // scatter chart | |
274 | QChart* chart = new QChart(); |
|
274 | QChart* chart = new QChart(); | |
275 | chart->setTitle("Scatter chart"); |
|
275 | chart->setTitle("Scatter chart"); | |
276 | foreach (DataList list, m_dataTable) { |
|
276 | foreach (DataList list, m_dataTable) { | |
277 | QScatterSeries *series = new QScatterSeries(chart); |
|
277 | QScatterSeries *series = new QScatterSeries(chart); | |
278 | foreach (Data data, list) |
|
278 | foreach (Data data, list) | |
279 | series->add(data.first); |
|
279 | series->add(data.first); | |
280 | chart->addSeries(series); |
|
280 | chart->addSeries(series); | |
281 | } |
|
281 | } | |
282 | return chart; |
|
282 | return chart; | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | void ThemeWidget::updateUI() |
|
285 | void ThemeWidget::updateUI() | |
286 | { |
|
286 | { | |
287 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
287 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
288 |
|
288 | |||
289 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
289 | if (m_charts.at(0)->chart()->theme() != theme) { | |
290 | foreach (QChartView *chartView, m_charts) |
|
290 | foreach (QChartView *chartView, m_charts) | |
291 | chartView->chart()->setTheme(theme); |
|
291 | chartView->chart()->setTheme(theme); | |
292 |
|
292 | |||
293 | QPalette pal = window()->palette(); |
|
293 | QPalette pal = window()->palette(); | |
294 | if (theme == QChart::ChartThemeLight) { |
|
294 | if (theme == QChart::ChartThemeLight) { | |
295 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
295 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
296 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
296 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
297 | } else if (theme == QChart::ChartThemeDark) { |
|
297 | } else if (theme == QChart::ChartThemeDark) { | |
298 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
298 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
299 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
299 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
300 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
300 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
301 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
301 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
302 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
302 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
303 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
303 | } else if (theme == QChart::ChartThemeBrownSand) { | |
304 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
304 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
305 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
305 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
306 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
306 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
307 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
307 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
308 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
308 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
309 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
309 | } else if (theme == QChart::ChartThemeHighContrast) { | |
310 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
310 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
311 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
311 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
312 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
312 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
313 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
313 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
314 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
314 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
315 | } else { |
|
315 | } else { | |
316 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
316 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
317 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
317 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
318 | } |
|
318 | } | |
319 | window()->setPalette(pal); |
|
319 | window()->setPalette(pal); | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | bool checked = m_antialiasCheckBox->isChecked(); |
|
322 | bool checked = m_antialiasCheckBox->isChecked(); | |
323 | foreach (QChartView *chart, m_charts) |
|
323 | foreach (QChartView *chart, m_charts) | |
324 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
324 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
325 |
|
325 | |||
326 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
326 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
327 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
327 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
328 | foreach (QChartView *chartView, m_charts) |
|
328 | foreach (QChartView *chartView, m_charts) | |
329 | chartView->chart()->setAnimationOptions(options); |
|
329 | chartView->chart()->setAnimationOptions(options); | |
330 | } |
|
330 | } | |
331 | } |
|
331 | } | |
332 |
|
332 |
@@ -1,94 +1,94 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE: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 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). |
|
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | |
39 | ** |
|
39 | ** | |
40 | ****************************************************************************/ |
|
40 | ****************************************************************************/ | |
41 |
|
41 | |||
42 | #include <QApplication> |
|
42 | #include <QApplication> | |
43 | #include <QMainWindow> |
|
43 | #include <QMainWindow> | |
44 | #include <QChartView> |
|
44 | #include <QChartView> | |
45 | #include <QBarSeries> |
|
45 | #include <QBarSeries> | |
46 | #include <QBarSet> |
|
46 | #include <QBarSet> | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | int main(int argc, char *argv[]) |
|
50 | int main(int argc, char *argv[]) | |
51 | { |
|
51 | { | |
52 | QApplication a(argc, argv); |
|
52 | QApplication a(argc, argv); | |
53 | //![1] |
|
53 | //![1] | |
54 | QBarCategories categories; |
|
54 | QBarCategories categories; | |
55 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
55 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
56 | //![1] |
|
56 | //![1] | |
57 | //![2] |
|
57 | //![2] | |
58 | QBarSet *set0 = new QBarSet("Bub"); |
|
58 | QBarSet *set0 = new QBarSet("Bub"); | |
59 | QBarSet *set1 = new QBarSet("Bob"); |
|
59 | QBarSet *set1 = new QBarSet("Bob"); | |
60 | QBarSet *set2 = new QBarSet("Guybrush"); |
|
60 | QBarSet *set2 = new QBarSet("Guybrush"); | |
61 | QBarSet *set3 = new QBarSet("Larry"); |
|
61 | QBarSet *set3 = new QBarSet("Larry"); | |
62 | QBarSet *set4 = new QBarSet("Zak"); |
|
62 | QBarSet *set4 = new QBarSet("Zak"); | |
63 |
|
63 | |||
64 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
64 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
65 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
65 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
66 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
66 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
67 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
67 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
68 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
68 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
69 | //![2] |
|
69 | //![2] | |
70 | //![3] |
|
70 | //![3] | |
71 | QBarSeries* series = new QBarSeries(categories); |
|
71 | QBarSeries* series = new QBarSeries(categories); | |
72 |
series->a |
|
72 | series->appendBarSet(set0); | |
73 |
series->a |
|
73 | series->appendBarSet(set1); | |
74 |
series->a |
|
74 | series->appendBarSet(set2); | |
75 |
series->a |
|
75 | series->appendBarSet(set3); | |
76 |
series->a |
|
76 | series->appendBarSet(set4); | |
77 | //![3] |
|
77 | //![3] | |
78 | //![4] |
|
78 | //![4] | |
79 | QChart* chart = new QChart(); |
|
79 | QChart* chart = new QChart(); | |
80 | chart->addSeries(series); |
|
80 | chart->addSeries(series); | |
81 | chart->setTitle("Simple barchart example"); |
|
81 | chart->setTitle("Simple barchart example"); | |
82 | //![4] |
|
82 | //![4] | |
83 | //![5] |
|
83 | //![5] | |
84 | QChartView* chartView = new QChartView(chart); |
|
84 | QChartView* chartView = new QChartView(chart); | |
85 | chartView->setRenderHint(QPainter::Antialiasing); |
|
85 | chartView->setRenderHint(QPainter::Antialiasing); | |
86 | //![5] |
|
86 | //![5] | |
87 | //![6] |
|
87 | //![6] | |
88 | QMainWindow window; |
|
88 | QMainWindow window; | |
89 | window.setCentralWidget(chartView); |
|
89 | window.setCentralWidget(chartView); | |
90 | window.resize(400, 300); |
|
90 | window.resize(400, 300); | |
91 | window.show(); |
|
91 | window.show(); | |
92 | //![6] |
|
92 | //![6] | |
93 | return a.exec(); |
|
93 | return a.exec(); | |
94 | } |
|
94 | } |
@@ -1,95 +1,95 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE: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 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). |
|
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | |
39 | ** |
|
39 | ** | |
40 | ****************************************************************************/ |
|
40 | ****************************************************************************/ | |
41 |
|
41 | |||
42 | #include <QApplication> |
|
42 | #include <QApplication> | |
43 | #include <QMainWindow> |
|
43 | #include <QMainWindow> | |
44 | #include <QChartView> |
|
44 | #include <QChartView> | |
45 | #include <QPercentBarSeries> |
|
45 | #include <QPercentBarSeries> | |
46 | #include <QBarSet> |
|
46 | #include <QBarSet> | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | int main(int argc, char *argv[]) |
|
50 | int main(int argc, char *argv[]) | |
51 | { |
|
51 | { | |
52 | QApplication a(argc, argv); |
|
52 | QApplication a(argc, argv); | |
53 | //![1] |
|
53 | //![1] | |
54 | QBarCategories categories; |
|
54 | QBarCategories categories; | |
55 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
55 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
56 | //![1] |
|
56 | //![1] | |
57 | //![2] |
|
57 | //![2] | |
58 | QBarSet *set0 = new QBarSet("Bub"); |
|
58 | QBarSet *set0 = new QBarSet("Bub"); | |
59 | QBarSet *set1 = new QBarSet("Bob"); |
|
59 | QBarSet *set1 = new QBarSet("Bob"); | |
60 | QBarSet *set2 = new QBarSet("Guybrush"); |
|
60 | QBarSet *set2 = new QBarSet("Guybrush"); | |
61 | QBarSet *set3 = new QBarSet("Larry"); |
|
61 | QBarSet *set3 = new QBarSet("Larry"); | |
62 | QBarSet *set4 = new QBarSet("Zak"); |
|
62 | QBarSet *set4 = new QBarSet("Zak"); | |
63 |
|
63 | |||
64 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
64 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
65 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
65 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
66 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
66 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
67 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
67 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
68 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
68 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
69 | //![2] |
|
69 | //![2] | |
70 | //![3] |
|
70 | //![3] | |
71 | QPercentBarSeries* series = new QPercentBarSeries(categories); |
|
71 | QPercentBarSeries* series = new QPercentBarSeries(categories); | |
72 |
series->a |
|
72 | series->appendBarSet(set0); | |
73 |
series->a |
|
73 | series->appendBarSet(set1); | |
74 |
series->a |
|
74 | series->appendBarSet(set2); | |
75 |
series->a |
|
75 | series->appendBarSet(set3); | |
76 |
series->a |
|
76 | series->appendBarSet(set4); | |
77 | //![3] |
|
77 | //![3] | |
78 | //![4] |
|
78 | //![4] | |
79 | QChart* chart = new QChart(); |
|
79 | QChart* chart = new QChart(); | |
80 | chart->addSeries(series); |
|
80 | chart->addSeries(series); | |
81 | chart->setTitle("Simple precentbarchart example"); |
|
81 | chart->setTitle("Simple precentbarchart example"); | |
82 | //![4] |
|
82 | //![4] | |
83 | //![5] |
|
83 | //![5] | |
84 | QChartView* chartView = new QChartView(chart); |
|
84 | QChartView* chartView = new QChartView(chart); | |
85 | chartView->setRenderHint(QPainter::Antialiasing); |
|
85 | chartView->setRenderHint(QPainter::Antialiasing); | |
86 | //![5] |
|
86 | //![5] | |
87 | //![6] |
|
87 | //![6] | |
88 | QMainWindow window; |
|
88 | QMainWindow window; | |
89 | window.setCentralWidget(chartView); |
|
89 | window.setCentralWidget(chartView); | |
90 | window.resize(400, 300); |
|
90 | window.resize(400, 300); | |
91 | window.show(); |
|
91 | window.show(); | |
92 | //![6] |
|
92 | //![6] | |
93 | return a.exec(); |
|
93 | return a.exec(); | |
94 | } |
|
94 | } | |
95 |
|
95 |
@@ -1,95 +1,95 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE: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 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). |
|
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | |
39 | ** |
|
39 | ** | |
40 | ****************************************************************************/ |
|
40 | ****************************************************************************/ | |
41 |
|
41 | |||
42 | #include <QApplication> |
|
42 | #include <QApplication> | |
43 | #include <QMainWindow> |
|
43 | #include <QMainWindow> | |
44 | #include <QChartView> |
|
44 | #include <QChartView> | |
45 | #include <QStackedBarSeries> |
|
45 | #include <QStackedBarSeries> | |
46 | #include <QBarSet> |
|
46 | #include <QBarSet> | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | int main(int argc, char *argv[]) |
|
50 | int main(int argc, char *argv[]) | |
51 | { |
|
51 | { | |
52 | QApplication a(argc, argv); |
|
52 | QApplication a(argc, argv); | |
53 | //![1] |
|
53 | //![1] | |
54 | QBarCategories categories; |
|
54 | QBarCategories categories; | |
55 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
55 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
56 | //![1] |
|
56 | //![1] | |
57 | //![2] |
|
57 | //![2] | |
58 | QBarSet *set0 = new QBarSet("Bub"); |
|
58 | QBarSet *set0 = new QBarSet("Bub"); | |
59 | QBarSet *set1 = new QBarSet("Bob"); |
|
59 | QBarSet *set1 = new QBarSet("Bob"); | |
60 | QBarSet *set2 = new QBarSet("Guybrush"); |
|
60 | QBarSet *set2 = new QBarSet("Guybrush"); | |
61 | QBarSet *set3 = new QBarSet("Larry"); |
|
61 | QBarSet *set3 = new QBarSet("Larry"); | |
62 | QBarSet *set4 = new QBarSet("Zak"); |
|
62 | QBarSet *set4 = new QBarSet("Zak"); | |
63 |
|
63 | |||
64 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
64 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
65 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
65 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
66 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
66 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
67 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
67 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
68 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
68 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
69 | //![2] |
|
69 | //![2] | |
70 | //![3] |
|
70 | //![3] | |
71 | QStackedBarSeries* series = new QStackedBarSeries(categories); |
|
71 | QStackedBarSeries* series = new QStackedBarSeries(categories); | |
72 |
series->a |
|
72 | series->appendBarSet(set0); | |
73 |
series->a |
|
73 | series->appendBarSet(set1); | |
74 |
series->a |
|
74 | series->appendBarSet(set2); | |
75 |
series->a |
|
75 | series->appendBarSet(set3); | |
76 |
series->a |
|
76 | series->appendBarSet(set4); | |
77 | //![3] |
|
77 | //![3] | |
78 | //![4] |
|
78 | //![4] | |
79 | QChart* chart = new QChart(); |
|
79 | QChart* chart = new QChart(); | |
80 | chart->addSeries(series); |
|
80 | chart->addSeries(series); | |
81 | chart->setTitle("Simple stackedbarchart example"); |
|
81 | chart->setTitle("Simple stackedbarchart example"); | |
82 | //![4] |
|
82 | //![4] | |
83 | //![5] |
|
83 | //![5] | |
84 | QChartView* chartView = new QChartView(chart); |
|
84 | QChartView* chartView = new QChartView(chart); | |
85 | chartView->setRenderHint(QPainter::Antialiasing); |
|
85 | chartView->setRenderHint(QPainter::Antialiasing); | |
86 | //![5] |
|
86 | //![5] | |
87 | //![6] |
|
87 | //![6] | |
88 | QMainWindow window; |
|
88 | QMainWindow window; | |
89 | window.setCentralWidget(chartView); |
|
89 | window.setCentralWidget(chartView); | |
90 | window.resize(400, 300); |
|
90 | window.resize(400, 300); | |
91 | window.show(); |
|
91 | window.show(); | |
92 | //![6] |
|
92 | //![6] | |
93 | return a.exec(); |
|
93 | return a.exec(); | |
94 | } |
|
94 | } | |
95 |
|
95 |
@@ -1,69 +1,69 | |||||
1 | #include "declarativebarseries.h" |
|
1 | #include "declarativebarseries.h" | |
2 | #include "declarativechart.h" |
|
2 | #include "declarativechart.h" | |
3 | #include "qchart.h" |
|
3 | #include "qchart.h" | |
4 | #include "qbarseries.h" |
|
4 | #include "qbarseries.h" | |
5 | #include "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : |
|
9 | DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) : | |
10 | QDeclarativeItem(parent) |
|
10 | QDeclarativeItem(parent) | |
11 | { |
|
11 | { | |
12 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
12 | setFlag(QGraphicsItem::ItemHasNoContents, false); | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | void DeclarativeBarSeries::componentComplete() |
|
15 | void DeclarativeBarSeries::componentComplete() | |
16 | { |
|
16 | { | |
17 | if (!m_series) { |
|
17 | if (!m_series) { | |
18 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); |
|
18 | DeclarativeChart *declarativeChart = qobject_cast<DeclarativeChart *>(parent()); | |
19 |
|
19 | |||
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 |
|
23 | |||
24 | // QStringList categories; |
|
24 | // QStringList categories; | |
25 | // categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
25 | // categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
26 | // m_series = new QBarSeries(categories); |
|
26 | // m_series = new QBarSeries(categories); | |
27 | // m_series = new QBarSeries(m_categories); |
|
27 | // m_series = new QBarSeries(m_categories); | |
28 | m_series = new QBarSeries(m_categories); |
|
28 | m_series = new QBarSeries(m_categories); | |
29 |
|
29 | |||
30 | // TODO: use data from model |
|
30 | // TODO: use data from model | |
31 | QBarSet *set0 = new QBarSet("Bub"); |
|
31 | QBarSet *set0 = new QBarSet("Bub"); | |
32 | QBarSet *set1 = new QBarSet("Bob"); |
|
32 | QBarSet *set1 = new QBarSet("Bob"); | |
33 | QBarSet *set2 = new QBarSet("Guybrush"); |
|
33 | QBarSet *set2 = new QBarSet("Guybrush"); | |
34 |
|
34 | |||
35 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
35 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
36 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
36 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
37 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
37 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
38 |
|
38 | |||
39 |
m_series->a |
|
39 | m_series->appendBarSet(set0); | |
40 |
m_series->a |
|
40 | m_series->appendBarSet(set1); | |
41 |
m_series->a |
|
41 | m_series->appendBarSet(set2); | |
42 |
|
42 | |||
43 | chart->addSeries(m_series); |
|
43 | chart->addSeries(m_series); | |
44 | } |
|
44 | } | |
45 | } |
|
45 | } | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void DeclarativeBarSeries::setBarCategories(QStringList categories) |
|
48 | void DeclarativeBarSeries::setBarCategories(QStringList categories) | |
49 | { |
|
49 | { | |
50 | m_categories = categories; |
|
50 | m_categories = categories; | |
51 | if (m_series) { |
|
51 | if (m_series) { | |
52 | // Replace categories of the QBarSeries with the new categories |
|
52 | // Replace categories of the QBarSeries with the new categories | |
53 | for (int i(0); i < m_categories.count(); i++) { |
|
53 | for (int i(0); i < m_categories.count(); i++) { | |
54 | if (m_series->categories().at(i) != m_categories.at(i)) |
|
54 | if (m_series->categories().at(i) != m_categories.at(i)) | |
55 | m_series->insertCategory(m_series->categoryCount(), m_categories.at(i)); |
|
55 | m_series->insertCategory(m_series->categoryCount(), m_categories.at(i)); | |
56 | } |
|
56 | } | |
57 | while (m_series->categoryCount() > m_categories.count()) |
|
57 | while (m_series->categoryCount() > m_categories.count()) | |
58 | m_series->removeCategory(m_series->categoryCount() - 1); |
|
58 | m_series->removeCategory(m_series->categoryCount() - 1); | |
59 | } |
|
59 | } | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | QStringList DeclarativeBarSeries::barCategories() |
|
62 | QStringList DeclarativeBarSeries::barCategories() | |
63 | { |
|
63 | { | |
64 | return m_categories; |
|
64 | return m_categories; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | #include "moc_declarativebarseries.cpp" |
|
67 | #include "moc_declarativebarseries.cpp" | |
68 |
|
68 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
69 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,215 +1,215 | |||||
1 | #include "barchartitem_p.h" |
|
1 | #include "barchartitem_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include "qbarseries.h" |
|
5 | #include "qbarseries.h" | |
6 | #include "qchart.h" |
|
6 | #include "qchart.h" | |
7 | #include "qchartaxis.h" |
|
7 | #include "qchartaxis.h" | |
8 | #include "qchartaxiscategories.h" |
|
8 | #include "qchartaxiscategories.h" | |
9 | #include "chartpresenter_p.h" |
|
9 | #include "chartpresenter_p.h" | |
10 | #include "chartanimator_p.h" |
|
10 | #include "chartanimator_p.h" | |
11 | #include "chartdataset_p.h" |
|
11 | #include "chartdataset_p.h" | |
12 | #include <QDebug> |
|
12 | #include <QDebug> | |
13 | #include <QToolTip> |
|
13 | #include <QToolTip> | |
14 |
|
14 | |||
15 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
15 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
16 |
|
16 | |||
17 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
17 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
18 | ChartItem(presenter), |
|
18 | ChartItem(presenter), | |
19 | m_layoutSet(false), |
|
19 | m_layoutSet(false), | |
20 | m_series(series) |
|
20 | m_series(series) | |
21 | { |
|
21 | { | |
22 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); |
|
22 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); | |
23 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
23 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); |
|
24 | //TODO: connect(series,SIGNAL("position or size has changed"), this, SLOT(handleLayoutChanged())); | |
25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
25 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
26 | setZValue(ChartPresenter::BarSeriesZValue); |
|
26 | setZValue(ChartPresenter::BarSeriesZValue); | |
27 | dataChanged(); |
|
27 | dataChanged(); | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | BarChartItem::~BarChartItem() |
|
30 | BarChartItem::~BarChartItem() | |
31 | { |
|
31 | { | |
32 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
32 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
35 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
36 | { |
|
36 | { | |
37 | if (!m_layoutSet) { |
|
37 | if (!m_layoutSet) { | |
38 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; |
|
38 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; | |
39 | return; |
|
39 | return; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | foreach(QGraphicsItem* i, childItems()) |
|
42 | foreach(QGraphicsItem* i, childItems()) | |
43 | i->paint(painter,option,widget); |
|
43 | i->paint(painter,option,widget); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QRectF BarChartItem::boundingRect() const |
|
46 | QRectF BarChartItem::boundingRect() const | |
47 | { |
|
47 | { | |
48 | return m_rect; |
|
48 | return m_rect; | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void BarChartItem::dataChanged() |
|
51 | void BarChartItem::dataChanged() | |
52 | { |
|
52 | { | |
53 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
53 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
54 | // Delete old bars |
|
54 | // Delete old bars | |
55 | foreach (QGraphicsItem *item, childItems()) |
|
55 | foreach (QGraphicsItem *item, childItems()) | |
56 | delete item; |
|
56 | delete item; | |
57 |
|
57 | |||
58 | m_bars.clear(); |
|
58 | m_bars.clear(); | |
59 | m_floatingValues.clear(); |
|
59 | m_floatingValues.clear(); | |
60 | m_layout.clear(); |
|
60 | m_layout.clear(); | |
61 |
|
61 | |||
62 | // Create new graphic items for bars |
|
62 | // Create new graphic items for bars | |
63 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
63 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
64 | QString category = m_series->categoryName(c); |
|
64 | QString category = m_series->categoryName(c); | |
65 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
65 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
66 | QBarSet *set = m_series->barsetAt(s); |
|
66 | QBarSet *set = m_series->barsetAt(s); | |
67 | Bar *bar = new Bar(category,this); |
|
67 | Bar *bar = new Bar(category,this); | |
68 | childItems().append(bar); |
|
68 | childItems().append(bar); | |
69 | m_bars.append(bar); |
|
69 | m_bars.append(bar); | |
70 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); |
|
70 | connect(bar, SIGNAL(clicked(QString)), set, SIGNAL(clicked(QString))); | |
71 | connect(bar, SIGNAL(rightClicked(QString)), set, SIGNAL(rightClicked(QString))); |
|
71 | connect(bar, SIGNAL(rightClicked(QString)), set, SIGNAL(rightClicked(QString))); | |
72 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); |
|
72 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); | |
73 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); |
|
73 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); | |
74 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
74 | m_layout.append(QRectF(0, 0, 0, 0)); | |
75 | } |
|
75 | } | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | // Create floating values |
|
78 | // Create floating values | |
79 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
79 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
80 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
80 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
81 | QBarSet *set = m_series->barsetAt(s); |
|
81 | QBarSet *set = m_series->barsetAt(s); | |
82 | BarValue *value = new BarValue(*set, this); |
|
82 | BarValue *value = new BarValue(*set, this); | |
83 | childItems().append(value); |
|
83 | childItems().append(value); | |
84 | m_floatingValues.append(value); |
|
84 | m_floatingValues.append(value); | |
85 | connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible())); |
|
85 | connect(set, SIGNAL(toggleFloatingValues()), value, SLOT(toggleVisible())); | |
86 | } |
|
86 | } | |
87 | } |
|
87 | } | |
88 | } |
|
88 | } | |
89 | QVector<QRectF> BarChartItem::calculateLayout() |
|
89 | QVector<QRectF> BarChartItem::calculateLayout() | |
90 | { |
|
90 | { | |
91 | QVector<QRectF> layout; |
|
91 | QVector<QRectF> layout; | |
92 |
|
92 | |||
93 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
93 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
94 | qreal categoryCount = m_series->categoryCount(); |
|
94 | qreal categoryCount = m_series->categoryCount(); | |
95 | qreal setCount = m_series->barsetCount(); |
|
95 | qreal setCount = m_series->barsetCount(); | |
96 |
|
96 | |||
97 | qreal width = geometry().width(); |
|
97 | qreal width = geometry().width(); | |
98 | qreal height = geometry().height(); |
|
98 | qreal height = geometry().height(); | |
99 |
|
99 | |||
100 | qreal max = m_series->max(); |
|
100 | qreal max = m_series->max(); | |
101 |
|
101 | |||
102 | // Domain: |
|
102 | // Domain: | |
103 | if (m_domainMaxY > max) { |
|
103 | if (m_domainMaxY > max) { | |
104 | max = m_domainMaxY; |
|
104 | max = m_domainMaxY; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | qreal scale = (height / max); |
|
107 | qreal scale = (height / max); | |
108 | qreal categoryWidth = width / categoryCount; |
|
108 | qreal categoryWidth = width / categoryCount; | |
109 | qreal barWidth = categoryWidth / (setCount+1); |
|
109 | qreal barWidth = categoryWidth / (setCount+1); | |
110 |
|
110 | |||
111 | int itemIndex(0); |
|
111 | int itemIndex(0); | |
112 | for (int category = 0; category < categoryCount; category++) { |
|
112 | for (int category = 0; category < categoryCount; category++) { | |
113 | qreal xPos = categoryWidth * category + barWidth / 2; |
|
113 | qreal xPos = categoryWidth * category + barWidth / 2; | |
114 | qreal yPos = height; |
|
114 | qreal yPos = height; | |
115 | for (int set = 0; set < setCount; set++) { |
|
115 | for (int set = 0; set < setCount; set++) { | |
116 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
116 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
117 | Bar* bar = m_bars.at(itemIndex); |
|
117 | Bar* bar = m_bars.at(itemIndex); | |
118 |
|
118 | |||
119 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
119 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
120 | layout.append(rect); |
|
120 | layout.append(rect); | |
121 | bar->setPen(m_series->barsetAt(set)->pen()); |
|
121 | bar->setPen(m_series->barsetAt(set)->pen()); | |
122 | bar->setBrush(m_series->barsetAt(set)->brush()); |
|
122 | bar->setBrush(m_series->barsetAt(set)->brush()); | |
123 | itemIndex++; |
|
123 | itemIndex++; | |
124 | xPos += barWidth; |
|
124 | xPos += barWidth; | |
125 | } |
|
125 | } | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | // Position floating values |
|
128 | // Position floating values | |
129 | itemIndex = 0; |
|
129 | itemIndex = 0; | |
130 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
130 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
131 | qreal xPos = categoryWidth * category + barWidth; |
|
131 | qreal xPos = categoryWidth * category + barWidth; | |
132 | qreal yPos = height; |
|
132 | qreal yPos = height; | |
133 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
133 | for (int set=0; set < m_series->barsetCount(); set++) { | |
134 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
134 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
135 | BarValue* value = m_floatingValues.at(itemIndex); |
|
135 | BarValue* value = m_floatingValues.at(itemIndex); | |
136 |
|
136 | |||
137 | QBarSet* barSet = m_series->barsetAt(set); |
|
137 | QBarSet* barSet = m_series->barsetAt(set); | |
138 | value->resize(100, 50); // TODO: proper layout for this. |
|
138 | value->resize(100, 50); // TODO: proper layout for this. | |
139 | value->setPos(xPos, yPos-barHeight / 2); |
|
139 | value->setPos(xPos, yPos-barHeight / 2); | |
140 | value->setPen(barSet->floatingValuePen()); |
|
140 | value->setPen(barSet->floatingValuePen()); | |
141 |
|
141 | |||
142 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
142 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
143 |
value->set |
|
143 | value->setText(QString::number(m_series->valueAt(set, category))); | |
144 | } else { |
|
144 | } else { | |
145 |
value->set |
|
145 | value->setText(QString("")); | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | itemIndex++; |
|
148 | itemIndex++; | |
149 | xPos += barWidth; |
|
149 | xPos += barWidth; | |
150 | } |
|
150 | } | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | return layout; |
|
153 | return layout; | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
156 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
157 | { |
|
157 | { | |
158 | if (animator()) |
|
158 | if (animator()) | |
159 | animator()->updateLayout(this, m_layout, layout); |
|
159 | animator()->updateLayout(this, m_layout, layout); | |
160 | else |
|
160 | else | |
161 | setLayout(layout); |
|
161 | setLayout(layout); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
164 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
165 | { |
|
165 | { | |
166 | m_layout = layout; |
|
166 | m_layout = layout; | |
167 |
|
167 | |||
168 | for (int i=0; i < m_bars.count(); i++) |
|
168 | for (int i=0; i < m_bars.count(); i++) | |
169 | m_bars.at(i)->setRect(layout.at(i)); |
|
169 | m_bars.at(i)->setRect(layout.at(i)); | |
170 |
|
170 | |||
171 | update(); |
|
171 | update(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | //handlers |
|
174 | //handlers | |
175 |
|
175 | |||
176 | void BarChartItem::handleModelChanged(int index) |
|
176 | void BarChartItem::handleModelChanged(int index) | |
177 | { |
|
177 | { | |
178 | Q_UNUSED(index) |
|
178 | Q_UNUSED(index) | |
179 | dataChanged(); |
|
179 | dataChanged(); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
182 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
183 | { |
|
183 | { | |
184 | m_domainMinX = minX; |
|
184 | m_domainMinX = minX; | |
185 | m_domainMaxX = maxX; |
|
185 | m_domainMaxX = maxX; | |
186 | m_domainMinY = minY; |
|
186 | m_domainMinY = minY; | |
187 | m_domainMaxY = maxY; |
|
187 | m_domainMaxY = maxY; | |
188 | handleLayoutChanged(); |
|
188 | handleLayoutChanged(); | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
191 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
192 | { |
|
192 | { | |
193 | m_rect = rect; |
|
193 | m_rect = rect; | |
194 | handleLayoutChanged(); |
|
194 | handleLayoutChanged(); | |
195 | m_layoutSet = true; |
|
195 | m_layoutSet = true; | |
196 | setPos(rect.topLeft()); |
|
196 | setPos(rect.topLeft()); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void BarChartItem::handleLayoutChanged() |
|
199 | void BarChartItem::handleLayoutChanged() | |
200 | { |
|
200 | { | |
201 | QVector<QRectF> layout = calculateLayout(); |
|
201 | QVector<QRectF> layout = calculateLayout(); | |
202 | applyLayout(layout); |
|
202 | applyLayout(layout); | |
203 | update(); |
|
203 | update(); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 |
|
206 | |||
207 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
207 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
208 | { |
|
208 | { | |
209 | // TODO: cool tooltip instead of default |
|
209 | // TODO: cool tooltip instead of default | |
210 | QToolTip::showText(pos, tip); |
|
210 | QToolTip::showText(pos, tip); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | #include "moc_barchartitem_p.cpp" |
|
213 | #include "moc_barchartitem_p.cpp" | |
214 |
|
214 | |||
215 | QTCOMMERCIALCHART_END_NAMESPACE |
|
215 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,168 +1,168 | |||||
1 | #include <limits.h> |
|
1 | #include <limits.h> | |
2 | #include <QVector> |
|
2 | #include <QVector> | |
3 | #include <QDebug> |
|
3 | #include <QDebug> | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 | #include "qbarset.h" |
|
5 | #include "qbarset.h" | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : QObject(parent), |
|
9 | BarChartModel::BarChartModel(QStringList categories, QObject *parent) : QObject(parent), | |
10 | m_category(categories) |
|
10 | m_category(categories) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | QStringList BarChartModel::category() |
|
14 | QStringList BarChartModel::category() | |
15 | { |
|
15 | { | |
16 | return m_category; |
|
16 | return m_category; | |
17 | } |
|
17 | } | |
18 |
|
18 | |||
19 |
void BarChartModel::a |
|
19 | void BarChartModel::appendBarSet(QBarSet *set) | |
20 | { |
|
20 | { | |
21 | m_dataModel.append(set); |
|
21 | m_dataModel.append(set); | |
22 | } |
|
22 | } | |
23 |
|
23 | |||
24 | void BarChartModel::removeBarSet(QBarSet *set) |
|
24 | void BarChartModel::removeBarSet(QBarSet *set) | |
25 | { |
|
25 | { | |
26 | if (m_dataModel.contains(set)) { |
|
26 | if (m_dataModel.contains(set)) { | |
27 | m_dataModel.removeOne(set); |
|
27 | m_dataModel.removeOne(set); | |
28 | } |
|
28 | } | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | void BarChartModel::insertBarSet(int i, QBarSet *set) |
|
31 | void BarChartModel::insertBarSet(int i, QBarSet *set) | |
32 | { |
|
32 | { | |
33 | m_dataModel.insert(i, set); |
|
33 | m_dataModel.insert(i, set); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void BarChartModel::insertCategory(int i, QString category) |
|
36 | void BarChartModel::insertCategory(int i, QString category) | |
37 | { |
|
37 | { | |
38 | m_category.insert(i, category); |
|
38 | m_category.insert(i, category); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | void BarChartModel::removeCategory(int i) |
|
41 | void BarChartModel::removeCategory(int i) | |
42 | { |
|
42 | { | |
43 | m_category.removeAt(i); |
|
43 | m_category.removeAt(i); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | QBarSet* BarChartModel::setAt(int index) |
|
46 | QBarSet* BarChartModel::barsetAt(int index) const | |
47 | { |
|
47 | { | |
48 | return m_dataModel.at(index); |
|
48 | return m_dataModel.at(index); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | QList<QBarSet*> BarChartModel::barSets() |
|
51 | QList<QBarSet*> BarChartModel::barSets() const | |
52 | { |
|
52 | { | |
53 | return m_dataModel; |
|
53 | return m_dataModel; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | int BarChartModel::barsetCount() |
|
56 | int BarChartModel::barsetCount() const | |
57 | { |
|
57 | { | |
58 | return m_dataModel.count(); |
|
58 | return m_dataModel.count(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | int BarChartModel::categoryCount() |
|
61 | int BarChartModel::categoryCount() const | |
62 | { |
|
62 | { | |
63 | return m_category.count(); |
|
63 | return m_category.count(); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | qreal BarChartModel::min() |
|
66 | qreal BarChartModel::min() const | |
67 | { |
|
67 | { | |
68 | Q_ASSERT(m_dataModel.count() > 0); |
|
68 | Q_ASSERT(m_dataModel.count() > 0); | |
69 | // TODO: make min and max members and update them when data changes. |
|
69 | // TODO: make min and max members and update them when data changes. | |
70 | // This is slower since they are checked every time, even if data is same since previous call. |
|
70 | // This is slower since they are checked every time, even if data is same since previous call. | |
71 | qreal min = INT_MAX; |
|
71 | qreal min = INT_MAX; | |
72 |
|
72 | |||
73 | for (int i = 0; i < m_dataModel.count(); i++) { |
|
73 | for (int i = 0; i < m_dataModel.count(); i++) { | |
74 | int itemCount = m_dataModel.at(i)->count(); |
|
74 | int itemCount = m_dataModel.at(i)->count(); | |
75 | for (int j = 0; j < itemCount; j++) { |
|
75 | for (int j = 0; j < itemCount; j++) { | |
76 | qreal temp = m_dataModel.at(i)->valueAt(j); |
|
76 | qreal temp = m_dataModel.at(i)->valueAt(j); | |
77 | if (temp < min) |
|
77 | if (temp < min) | |
78 | min = temp; |
|
78 | min = temp; | |
79 | } |
|
79 | } | |
80 | } |
|
80 | } | |
81 | return min; |
|
81 | return min; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | qreal BarChartModel::max() |
|
84 | qreal BarChartModel::max() const | |
85 | { |
|
85 | { | |
86 | Q_ASSERT(m_dataModel.count() > 0); |
|
86 | Q_ASSERT(m_dataModel.count() > 0); | |
87 |
|
87 | |||
88 | // TODO: make min and max members and update them when data changes. |
|
88 | // TODO: make min and max members and update them when data changes. | |
89 | // This is slower since they are checked every time, even if data is same since previous call. |
|
89 | // This is slower since they are checked every time, even if data is same since previous call. | |
90 | qreal max = INT_MIN; |
|
90 | qreal max = INT_MIN; | |
91 |
|
91 | |||
92 | for (int i = 0; i < m_dataModel.count(); i++) { |
|
92 | for (int i = 0; i < m_dataModel.count(); i++) { | |
93 | int itemCount = m_dataModel.at(i)->count(); |
|
93 | int itemCount = m_dataModel.at(i)->count(); | |
94 | for (int j = 0; j < itemCount; j++) { |
|
94 | for (int j = 0; j < itemCount; j++) { | |
95 | qreal temp = m_dataModel.at(i)->valueAt(j); |
|
95 | qreal temp = m_dataModel.at(i)->valueAt(j); | |
96 | if (temp > max) |
|
96 | if (temp > max) | |
97 | max = temp; |
|
97 | max = temp; | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | return max; |
|
101 | return max; | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | qreal BarChartModel::valueAt(int set, int category) |
|
104 | qreal BarChartModel::valueAt(int set, int category) const | |
105 | { |
|
105 | { | |
106 | if ((set < 0) || (set >= m_dataModel.count())) { |
|
106 | if ((set < 0) || (set >= m_dataModel.count())) { | |
107 | // No set, no value. |
|
107 | // No set, no value. | |
108 | return 0; |
|
108 | return 0; | |
109 | } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) { |
|
109 | } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) { | |
110 | // No category, no value. |
|
110 | // No category, no value. | |
111 | return 0; |
|
111 | return 0; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | return m_dataModel.at(set)->valueAt(category); |
|
114 | return m_dataModel.at(set)->valueAt(category); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | qreal BarChartModel::percentageAt(int set, int category) |
|
117 | qreal BarChartModel::percentageAt(int set, int category) const | |
118 | { |
|
118 | { | |
119 | if ((set < 0) || (set >= m_dataModel.count())) { |
|
119 | if ((set < 0) || (set >= m_dataModel.count())) { | |
120 | // No set, no value. |
|
120 | // No set, no value. | |
121 | return 0; |
|
121 | return 0; | |
122 | } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) { |
|
122 | } else if ((category < 0) || (category >= m_dataModel.at(set)->count())) { | |
123 | // No category, no value. |
|
123 | // No category, no value. | |
124 | return 0; |
|
124 | return 0; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | qreal value = m_dataModel.at(set)->valueAt(category); |
|
127 | qreal value = m_dataModel.at(set)->valueAt(category); | |
128 | qreal total = categorySum(category); |
|
128 | qreal total = categorySum(category); | |
129 | if ( qFuzzyCompare(total, 0) ) |
|
129 | if ( qFuzzyCompare(total, 0) ) | |
130 | return 0; |
|
130 | return 0; | |
131 |
|
131 | |||
132 | return value / total; |
|
132 | return value / total; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 |
|
135 | |||
136 | qreal BarChartModel::categorySum(int category) |
|
136 | qreal BarChartModel::categorySum(int category) const | |
137 | { |
|
137 | { | |
138 | qreal sum(0); |
|
138 | qreal sum(0); | |
139 | int count = m_dataModel.count(); // Count sets |
|
139 | int count = m_dataModel.count(); // Count sets | |
140 |
|
140 | |||
141 | for (int set = 0; set < count; set++) { |
|
141 | for (int set = 0; set < count; set++) { | |
142 | if (category < m_dataModel.at(set)->count()) |
|
142 | if (category < m_dataModel.at(set)->count()) | |
143 | sum += m_dataModel.at(set)->valueAt(category); |
|
143 | sum += m_dataModel.at(set)->valueAt(category); | |
144 | } |
|
144 | } | |
145 | return sum; |
|
145 | return sum; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | qreal BarChartModel::maxCategorySum() |
|
148 | qreal BarChartModel::maxCategorySum() const | |
149 | { |
|
149 | { | |
150 | qreal max = INT_MIN; |
|
150 | qreal max = INT_MIN; | |
151 | int count = categoryCount(); |
|
151 | int count = categoryCount(); | |
152 |
|
152 | |||
153 | for (int col = 0; col < count; col++) { |
|
153 | for (int col = 0; col < count; col++) { | |
154 | qreal sum = categorySum(col); |
|
154 | qreal sum = categorySum(col); | |
155 | if (sum > max) |
|
155 | if (sum > max) | |
156 | max = sum; |
|
156 | max = sum; | |
157 | } |
|
157 | } | |
158 | return max; |
|
158 | return max; | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | QString BarChartModel::categoryName(int category) |
|
161 | QString BarChartModel::categoryName(int category) | |
162 | { |
|
162 | { | |
163 | return m_category.at(category); |
|
163 | return m_category.at(category); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | #include "moc_barchartmodel_p.cpp" |
|
166 | #include "moc_barchartmodel_p.cpp" | |
167 |
|
167 | |||
168 | QTCOMMERCIALCHART_END_NAMESPACE |
|
168 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,57 +1,57 | |||||
1 | #ifndef BARCHARTMODEL_H |
|
1 | #ifndef BARCHARTMODEL_H | |
2 | #define BARCHARTMODEL_H |
|
2 | #define BARCHARTMODEL_H | |
3 |
|
3 | |||
4 | #include <QObject> |
|
4 | #include <QObject> | |
5 | #include <QStringList> |
|
5 | #include <QStringList> | |
6 | #include "qchartglobal.h" |
|
6 | #include "qchartglobal.h" | |
7 | #include <qseries.h> |
|
7 | #include <qseries.h> | |
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | // Model for bar chart. Internal class. |
|
11 | // Model for bar chart. Internal class. | |
12 | // TODO: Implement as QAbstractItemModel? |
|
12 | // TODO: Implement as QAbstractItemModel? | |
13 |
|
13 | |||
14 | class QBarSet; |
|
14 | class QBarSet; | |
15 |
|
15 | |||
16 | class BarChartModel : public QObject //, public QAbstractItemModel |
|
16 | class BarChartModel : public QObject //, public QAbstractItemModel | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | explicit BarChartModel(QStringList categories, QObject *parent = 0); |
|
20 | explicit BarChartModel(QStringList categories, QObject *parent = 0); | |
21 |
|
21 | |||
22 | QStringList category(); |
|
22 | QStringList category(); | |
23 |
void a |
|
23 | void appendBarSet(QBarSet *set); | |
24 | void removeBarSet(QBarSet *set); |
|
24 | void removeBarSet(QBarSet *set); | |
25 | void insertBarSet(int i, QBarSet *set); |
|
25 | void insertBarSet(int i, QBarSet *set); | |
26 | void insertCategory(int i, QString category); |
|
26 | void insertCategory(int i, QString category); | |
27 | void removeCategory(int i); |
|
27 | void removeCategory(int i); | |
28 | QBarSet *setAt(int index); |
|
28 | QBarSet *barsetAt(int index) const; | |
29 | QList<QBarSet *> barSets(); |
|
29 | QList<QBarSet *> barSets() const; | |
30 |
|
30 | |||
31 | int barsetCount(); // Number of sets in model |
|
31 | int barsetCount() const; // Number of sets in model | |
32 | int categoryCount(); // Number of categories |
|
32 | int categoryCount() const; // Number of categories | |
33 |
|
33 | |||
34 | qreal max(); // Maximum value of all sets |
|
34 | qreal max() const; // Maximum value of all sets | |
35 | qreal min(); // Minimum value of all sets |
|
35 | qreal min() const; // Minimum value of all sets | |
36 | qreal valueAt(int set, int category); |
|
36 | qreal valueAt(int set, int category) const; | |
37 | qreal percentageAt(int set, int category); |
|
37 | qreal percentageAt(int set, int category) const; | |
38 |
|
38 | |||
39 | qreal categorySum(int category); |
|
39 | qreal categorySum(int category) const; | |
40 | qreal maxCategorySum(); // returns maximum sum of sets in all categories. |
|
40 | qreal maxCategorySum() const; // returns maximum sum of sets in all categories. | |
41 |
|
41 | |||
42 | QString categoryName(int category); |
|
42 | QString categoryName(int category); | |
43 |
|
43 | |||
44 | Q_SIGNALS: |
|
44 | Q_SIGNALS: | |
45 | void modelUpdated(); |
|
45 | void modelUpdated(); | |
46 |
|
46 | |||
47 | public Q_SLOTS: |
|
47 | public Q_SLOTS: | |
48 |
|
48 | |||
49 | private: |
|
49 | private: | |
50 |
|
50 | |||
51 | QList<QBarSet *> m_dataModel; |
|
51 | QList<QBarSet *> m_dataModel; | |
52 | QStringList m_category; |
|
52 | QStringList m_category; | |
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
55 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 |
|
56 | |||
57 | #endif // BARCHARTMODEL_H |
|
57 | #endif // BARCHARTMODEL_H |
@@ -1,73 +1,73 | |||||
1 | #include "barvalue_p.h" |
|
1 | #include "barvalue_p.h" | |
2 | #include <QPainter> |
|
2 | #include <QPainter> | |
3 | #include <QPen> |
|
3 | #include <QPen> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) |
|
7 | BarValue::BarValue(QBarSet &set, QGraphicsItem *parent) | |
8 | : QGraphicsObject(parent), |
|
8 | : QGraphicsObject(parent), | |
9 | m_barSet(set), |
|
9 | m_barSet(set), | |
10 | m_xPos(0), |
|
10 | m_xPos(0), | |
11 | m_yPos(0), |
|
11 | m_yPos(0), | |
12 | m_width(0), |
|
12 | m_width(0), | |
13 | m_height(0) |
|
13 | m_height(0) | |
14 | { |
|
14 | { | |
15 | setVisible(false); |
|
15 | setVisible(false); | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 |
void BarValue::set |
|
18 | void BarValue::setText(QString str) | |
19 | { |
|
19 | { | |
20 | m_valueString = str; |
|
20 | m_valueString = str; | |
21 | } |
|
21 | } | |
22 |
|
22 | |||
23 |
QString BarValue:: |
|
23 | QString BarValue::text() const | |
24 | { |
|
24 | { | |
25 | return m_valueString; |
|
25 | return m_valueString; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void BarValue::setPen(const QPen pen) |
|
28 | void BarValue::setPen(const QPen &pen) | |
29 | { |
|
29 | { | |
30 | m_pen = pen; |
|
30 | m_pen = pen; | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | QPen BarValue::pen() const |
|
33 | QPen BarValue::pen() const | |
34 | { |
|
34 | { | |
35 | return m_pen; |
|
35 | return m_pen; | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | void BarValue::resize(qreal w, qreal h) |
|
38 | void BarValue::resize(qreal w, qreal h) | |
39 | { |
|
39 | { | |
40 | m_width = w; |
|
40 | m_width = w; | |
41 | m_height = h; |
|
41 | m_height = h; | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void BarValue::setPos(qreal x, qreal y) |
|
44 | void BarValue::setPos(qreal x, qreal y) | |
45 | { |
|
45 | { | |
46 | m_xPos = x; |
|
46 | m_xPos = x; | |
47 | m_yPos = y; |
|
47 | m_yPos = y; | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
50 | void BarValue::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
51 | { |
|
51 | { | |
52 | Q_UNUSED(option) |
|
52 | Q_UNUSED(option) | |
53 | Q_UNUSED(widget) |
|
53 | Q_UNUSED(widget) | |
54 |
|
54 | |||
55 | if (isVisible()) { |
|
55 | if (isVisible()) { | |
56 | painter->setPen(m_pen); |
|
56 | painter->setPen(m_pen); | |
57 | painter->drawText(boundingRect(), m_valueString); |
|
57 | painter->drawText(boundingRect(), m_valueString); | |
58 | } |
|
58 | } | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | QRectF BarValue::boundingRect() const |
|
61 | QRectF BarValue::boundingRect() const | |
62 | { |
|
62 | { | |
63 | QRectF r(m_xPos, m_yPos, m_width, m_height); |
|
63 | QRectF r(m_xPos, m_yPos, m_width, m_height); | |
64 | return r; |
|
64 | return r; | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void BarValue::toggleVisible() |
|
67 | void BarValue::toggleVisible() | |
68 | { |
|
68 | { | |
69 | setVisible(!isVisible()); |
|
69 | setVisible(!isVisible()); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | #include "moc_barvalue_p.cpp" |
|
72 | #include "moc_barvalue_p.cpp" | |
73 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,50 +1,50 | |||||
1 | #ifndef BARVALUE_P_H |
|
1 | #ifndef BARVALUE_P_H | |
2 | #define BARVALUE_P_H |
|
2 | #define BARVALUE_P_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include <QGraphicsObject> |
|
5 | #include <QGraphicsObject> | |
6 | #include <QPen> |
|
6 | #include <QPen> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QBarSet; |
|
10 | class QBarSet; | |
11 |
|
11 | |||
12 | // Visual class for floating bar values |
|
12 | // Visual class for floating bar values | |
13 | // By default these are not visible. |
|
13 | // By default these are not visible. | |
14 | class BarValue : public QGraphicsObject |
|
14 | class BarValue : public QGraphicsObject | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | BarValue(QBarSet &set, QGraphicsItem *parent = 0); |
|
18 | BarValue(QBarSet &set, QGraphicsItem *parent = 0); | |
19 |
|
19 | |||
20 |
void set |
|
20 | void setText(QString str); | |
21 |
QString |
|
21 | QString text() const; | |
22 |
|
22 | |||
23 | void setPen(const QPen pen); |
|
23 | void setPen(const QPen &pen); | |
24 | QPen pen() const; |
|
24 | QPen pen() const; | |
25 |
|
25 | |||
26 | void resize(qreal w, qreal h); |
|
26 | void resize(qreal w, qreal h); | |
27 | void setPos(qreal x, qreal y); |
|
27 | void setPos(qreal x, qreal y); | |
28 |
|
28 | |||
29 | // From QGraphicsItem |
|
29 | // From QGraphicsItem | |
30 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
30 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
31 | QRectF boundingRect() const; |
|
31 | QRectF boundingRect() const; | |
32 |
|
32 | |||
33 | public Q_SLOTS: |
|
33 | public Q_SLOTS: | |
34 | void toggleVisible(); |
|
34 | void toggleVisible(); | |
35 |
|
35 | |||
36 | private: |
|
36 | private: | |
37 |
|
37 | |||
38 | QBarSet &m_barSet; |
|
38 | QBarSet &m_barSet; | |
39 | QPen m_pen; |
|
39 | QPen m_pen; | |
40 | QString m_valueString; |
|
40 | QString m_valueString; | |
41 |
|
41 | |||
42 | qreal m_xPos; |
|
42 | qreal m_xPos; | |
43 | qreal m_yPos; |
|
43 | qreal m_yPos; | |
44 | qreal m_width; |
|
44 | qreal m_width; | |
45 | qreal m_height; |
|
45 | qreal m_height; | |
46 | }; |
|
46 | }; | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_END_NAMESPACE |
|
48 | QTCOMMERCIALCHART_END_NAMESPACE | |
49 |
|
49 | |||
50 | #endif // BARVALUE_P_H |
|
50 | #endif // BARVALUE_P_H |
@@ -1,81 +1,81 | |||||
1 | #include "percentbarchartitem_p.h" |
|
1 | #include "percentbarchartitem_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
9 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
10 | BarChartItem(series, presenter) |
|
10 | BarChartItem(series, presenter) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
14 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
15 | { |
|
15 | { | |
16 | QVector<QRectF> layout; |
|
16 | QVector<QRectF> layout; | |
17 |
|
17 | |||
18 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
18 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
19 | qreal width = geometry().width(); |
|
19 | qreal width = geometry().width(); | |
20 | qreal height = geometry().height(); |
|
20 | qreal height = geometry().height(); | |
21 |
|
21 | |||
22 | qreal categoryCount = m_series->categoryCount(); |
|
22 | qreal categoryCount = m_series->categoryCount(); | |
23 | qreal barWidth = width / (m_series->categoryCount() * 2); |
|
23 | qreal barWidth = width / (m_series->categoryCount() * 2); | |
24 | qreal xStep = width / categoryCount; |
|
24 | qreal xStep = width / categoryCount; | |
25 | qreal xPos = xStep / 2 - barWidth / 2; |
|
25 | qreal xPos = xStep / 2 - barWidth / 2; | |
26 |
|
26 | |||
27 | int itemIndex(0); |
|
27 | int itemIndex(0); | |
28 | for (int category = 0; category < categoryCount; category++) { |
|
28 | for (int category = 0; category < categoryCount; category++) { | |
29 | qreal colSum = m_series->categorySum(category); |
|
29 | qreal colSum = m_series->categorySum(category); | |
30 | qreal scale = (height / colSum); |
|
30 | qreal scale = (height / colSum); | |
31 | qreal yPos = height; |
|
31 | qreal yPos = height; | |
32 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
32 | for (int set=0; set < m_series->barsetCount(); set++) { | |
33 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
33 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
34 | Bar* bar = m_bars.at(itemIndex); |
|
34 | Bar* bar = m_bars.at(itemIndex); | |
35 | bar->setPen(m_series->barsetAt(set)->pen()); |
|
35 | bar->setPen(m_series->barsetAt(set)->pen()); | |
36 | bar->setBrush(m_series->barsetAt(set)->brush()); |
|
36 | bar->setBrush(m_series->barsetAt(set)->brush()); | |
37 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
37 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
38 | layout.append(rect); |
|
38 | layout.append(rect); | |
39 | itemIndex++; |
|
39 | itemIndex++; | |
40 | yPos -= barHeight; |
|
40 | yPos -= barHeight; | |
41 | } |
|
41 | } | |
42 | xPos += xStep; |
|
42 | xPos += xStep; | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | // Position floating values |
|
45 | // Position floating values | |
46 | itemIndex = 0; |
|
46 | itemIndex = 0; | |
47 | xPos = (width/categoryCount); |
|
47 | xPos = (width/categoryCount); | |
48 | for (int category=0; category < m_series->categoryCount(); category++) { |
|
48 | for (int category=0; category < m_series->categoryCount(); category++) { | |
49 | qreal yPos = height; |
|
49 | qreal yPos = height; | |
50 | qreal colSum = m_series->categorySum(category); |
|
50 | qreal colSum = m_series->categorySum(category); | |
51 | qreal scale = (height / colSum); |
|
51 | qreal scale = (height / colSum); | |
52 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
52 | for (int set=0; set < m_series->barsetCount(); set++) { | |
53 | qreal barHeight = m_series->valueAt(set,category) * scale; |
|
53 | qreal barHeight = m_series->valueAt(set,category) * scale; | |
54 | BarValue* value = m_floatingValues.at(itemIndex); |
|
54 | BarValue* value = m_floatingValues.at(itemIndex); | |
55 |
|
55 | |||
56 | QBarSet* barSet = m_series->barsetAt(set); |
|
56 | QBarSet* barSet = m_series->barsetAt(set); | |
57 | value->resize(100, 50); // TODO: proper layout for this. |
|
57 | value->resize(100, 50); // TODO: proper layout for this. | |
58 | value->setPos(xPos, yPos-barHeight / 2); |
|
58 | value->setPos(xPos, yPos-barHeight / 2); | |
59 | value->setPen(barSet->floatingValuePen()); |
|
59 | value->setPen(barSet->floatingValuePen()); | |
60 |
|
60 | |||
61 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
61 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
62 | int p = m_series->percentageAt(set,category) * 100; |
|
62 | int p = m_series->percentageAt(set,category) * 100; | |
63 | QString vString(QString::number(p)); |
|
63 | QString vString(QString::number(p)); | |
64 | vString.truncate(3); |
|
64 | vString.truncate(3); | |
65 | vString.append("%"); |
|
65 | vString.append("%"); | |
66 |
value->set |
|
66 | value->setText(vString); | |
67 | } else { |
|
67 | } else { | |
68 |
value->set |
|
68 | value->setText(QString("")); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | itemIndex++; |
|
71 | itemIndex++; | |
72 | yPos -= barHeight; |
|
72 | yPos -= barHeight; | |
73 | } |
|
73 | } | |
74 | xPos += xStep; |
|
74 | xPos += xStep; | |
75 | } |
|
75 | } | |
76 | return layout; |
|
76 | return layout; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | #include "moc_percentbarchartitem_p.cpp" |
|
79 | #include "moc_percentbarchartitem_p.cpp" | |
80 |
|
80 | |||
81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
81 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,387 +1,387 | |||||
1 | #include <QDebug> |
|
1 | #include <QDebug> | |
2 | #include "qbarseries.h" |
|
2 | #include "qbarseries.h" | |
3 | #include "qbarset.h" |
|
3 | #include "qbarset.h" | |
4 | #include "barchartmodel_p.h" |
|
4 | #include "barchartmodel_p.h" | |
5 |
|
5 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
7 | |||
8 | /*! |
|
8 | /*! | |
9 | \class QBarSeries |
|
9 | \class QBarSeries | |
10 | \brief part of QtCommercial chart API. |
|
10 | \brief part of QtCommercial chart API. | |
11 |
|
11 | |||
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
12 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
13 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
14 | by QStringList. |
|
14 | by QStringList. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn virtual QSeriesType QBarSeries::type() const |
|
22 | \fn virtual QSeriesType QBarSeries::type() const | |
23 | \brief Returns type of series. |
|
23 | \brief Returns type of series. | |
24 | \sa QSeries, QSeriesType |
|
24 | \sa QSeries, QSeriesType | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
28 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
29 | \brief \internal \a pos \a tip |
|
29 | \brief \internal \a pos \a tip | |
30 | */ |
|
30 | */ | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
33 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
34 | QBarSeries is QObject which is a child of a \a parent. |
|
34 | QBarSeries is QObject which is a child of a \a parent. | |
35 | */ |
|
35 | */ | |
36 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), |
|
36 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
37 | m_internalModel(new BarChartModel(categories, this)) |
|
37 | m_internalModel(new BarChartModel(categories, this)) | |
38 | { |
|
38 | { | |
39 | m_model = 0; |
|
39 | m_model = 0; | |
40 | m_mapCategories = -1; |
|
40 | m_mapCategories = -1; | |
41 | m_mapBarBottom = -1; |
|
41 | m_mapBarBottom = -1; | |
42 | m_mapBarTop = -1; |
|
42 | m_mapBarTop = -1; | |
43 | m_mapFirst = 0; |
|
43 | m_mapFirst = 0; | |
44 | m_mapCount = 0; |
|
44 | m_mapCount = 0; | |
45 | m_mapOrientation = Qt::Vertical; |
|
45 | m_mapOrientation = Qt::Vertical; | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | Adds a set of bars to series. Takes ownership of \a set. |
|
49 | Adds a set of bars to series. Takes ownership of \a set. | |
50 | Connects the clicked(QString) and rightClicked(QString) signals |
|
50 | Connects the clicked(QString) and rightClicked(QString) signals | |
51 | of \a set to this series |
|
51 | of \a set to this series | |
52 | */ |
|
52 | */ | |
53 |
void QBarSeries::a |
|
53 | void QBarSeries::appendBarSet(QBarSet *set) | |
54 | { |
|
54 | { | |
55 |
m_internalModel->a |
|
55 | m_internalModel->appendBarSet(set); | |
56 | connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); |
|
56 | connect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); | |
57 | connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); |
|
57 | connect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); | |
58 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
58 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
59 | emit updatedBars(); |
|
59 | emit updatedBars(); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
63 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
64 | Disconnects the clicked(QString) and rightClicked(QString) signals |
|
64 | Disconnects the clicked(QString) and rightClicked(QString) signals | |
65 | of \a set from this series |
|
65 | of \a set from this series | |
66 | */ |
|
66 | */ | |
67 | void QBarSeries::removeBarSet(QBarSet *set) |
|
67 | void QBarSeries::removeBarSet(QBarSet *set) | |
68 | { |
|
68 | { | |
69 | disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); |
|
69 | disconnect(set, SIGNAL(clicked(QString)), this, SLOT(barsetClicked(QString))); | |
70 | disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); |
|
70 | disconnect(set, SIGNAL(rightClicked(QString)), this, SLOT(barsetRightClicked(QString))); | |
71 | m_internalModel->removeBarSet(set); |
|
71 | m_internalModel->removeBarSet(set); | |
72 | emit updatedBars(); |
|
72 | emit updatedBars(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
75 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
76 | { |
|
76 | { | |
77 | m_internalModel->insertBarSet(i, set); |
|
77 | m_internalModel->insertBarSet(i, set); | |
78 | // emit barsetChanged(); |
|
78 | // emit barsetChanged(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void QBarSeries::insertCategory(int i, QString category) |
|
81 | void QBarSeries::insertCategory(int i, QString category) | |
82 | { |
|
82 | { | |
83 | m_internalModel->insertCategory(i, category); |
|
83 | m_internalModel->insertCategory(i, category); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | void QBarSeries::removeCategory(int i) |
|
86 | void QBarSeries::removeCategory(int i) | |
87 | { |
|
87 | { | |
88 | m_internalModel->removeCategory(i); |
|
88 | m_internalModel->removeCategory(i); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | Returns number of sets in series. |
|
92 | Returns number of sets in series. | |
93 | */ |
|
93 | */ | |
94 | int QBarSeries::barsetCount() |
|
94 | int QBarSeries::barsetCount() const | |
95 | { |
|
95 | { | |
96 | // if(m_model) |
|
96 | // if(m_model) | |
97 | // return m_mapBarTop - m_mapBarBottom; |
|
97 | // return m_mapBarTop - m_mapBarBottom; | |
98 | // else |
|
98 | // else | |
99 | return m_internalModel->barsetCount(); |
|
99 | return m_internalModel->barsetCount(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | /*! |
|
102 | /*! | |
103 | Returns number of categories in series |
|
103 | Returns number of categories in series | |
104 | */ |
|
104 | */ | |
105 | int QBarSeries::categoryCount() |
|
105 | int QBarSeries::categoryCount() const | |
106 | { |
|
106 | { | |
107 | return m_internalModel->categoryCount(); |
|
107 | return m_internalModel->categoryCount(); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | Returns a list of sets in series. Keeps ownership of sets. |
|
111 | Returns a list of sets in series. Keeps ownership of sets. | |
112 | */ |
|
112 | */ | |
113 | QList<QBarSet*> QBarSeries::barSets() |
|
113 | QList<QBarSet*> QBarSeries::barSets() const | |
114 | { |
|
114 | { | |
115 | return m_internalModel->barSets(); |
|
115 | return m_internalModel->barSets(); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | /*! |
|
118 | /*! | |
119 | \internal \a index |
|
119 | \internal \a index | |
120 | */ |
|
120 | */ | |
121 | QBarSet* QBarSeries::barsetAt(int index) |
|
121 | QBarSet* QBarSeries::barsetAt(int index) | |
122 | { |
|
122 | { | |
123 | return m_internalModel->setAt(index); |
|
123 | return m_internalModel->barsetAt(index); | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \internal \a category |
|
127 | \internal \a category | |
128 | */ |
|
128 | */ | |
129 | QString QBarSeries::categoryName(int category) |
|
129 | QString QBarSeries::categoryName(int category) | |
130 | { |
|
130 | { | |
131 | return m_internalModel->categoryName(category); |
|
131 | return m_internalModel->categoryName(category); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | Enables or disables tooltip depending on parameter \a enabled. |
|
135 | Enables or disables tooltip depending on parameter \a enabled. | |
136 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
136 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
137 | Calling without parameter \a enabled, enables the tooltip |
|
137 | Calling without parameter \a enabled, enables the tooltip | |
138 | */ |
|
138 | */ | |
139 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
139 | void QBarSeries::setToolTipEnabled(bool enabled) | |
140 | { |
|
140 | { | |
141 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
141 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
142 | if (enabled) { |
|
142 | if (enabled) { | |
143 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
143 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
144 | QBarSet *set = m_internalModel->setAt(i); |
|
144 | QBarSet *set = m_internalModel->barsetAt(i); | |
145 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
145 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
146 | } |
|
146 | } | |
147 | } else { |
|
147 | } else { | |
148 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
148 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
149 | QBarSet *set = m_internalModel->setAt(i); |
|
149 | QBarSet *set = m_internalModel->barsetAt(i); | |
150 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
150 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
151 | } |
|
151 | } | |
152 | } |
|
152 | } | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | \internal \a category |
|
157 | \internal \a category | |
158 | */ |
|
158 | */ | |
159 | void QBarSeries::barsetClicked(QString category) |
|
159 | void QBarSeries::barsetClicked(QString category) | |
160 | { |
|
160 | { | |
161 | emit clicked(qobject_cast<QBarSet*>(sender()), category); |
|
161 | emit clicked(qobject_cast<QBarSet*>(sender()), category); | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | \internal \a category |
|
165 | \internal \a category | |
166 | */ |
|
166 | */ | |
167 | void QBarSeries::barsetRightClicked(QString category) |
|
167 | void QBarSeries::barsetRightClicked(QString category) | |
168 | { |
|
168 | { | |
169 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); |
|
169 | emit rightClicked(qobject_cast<QBarSet*>(sender()), category); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | \internal |
|
174 | \internal | |
175 | */ |
|
175 | */ | |
176 | qreal QBarSeries::min() |
|
176 | qreal QBarSeries::min() | |
177 | { |
|
177 | { | |
178 | return m_internalModel->min(); |
|
178 | return m_internalModel->min(); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \internal |
|
182 | \internal | |
183 | */ |
|
183 | */ | |
184 | qreal QBarSeries::max() |
|
184 | qreal QBarSeries::max() | |
185 | { |
|
185 | { | |
186 | return m_internalModel->max(); |
|
186 | return m_internalModel->max(); | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | \internal \a set \a category |
|
190 | \internal \a set \a category | |
191 | */ |
|
191 | */ | |
192 | qreal QBarSeries::valueAt(int set, int category) |
|
192 | qreal QBarSeries::valueAt(int set, int category) | |
193 | { |
|
193 | { | |
194 | return m_internalModel->valueAt(set, category); |
|
194 | return m_internalModel->valueAt(set, category); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | \internal \a set \a category |
|
198 | \internal \a set \a category | |
199 | */ |
|
199 | */ | |
200 | qreal QBarSeries::percentageAt(int set, int category) |
|
200 | qreal QBarSeries::percentageAt(int set, int category) | |
201 | { |
|
201 | { | |
202 | return m_internalModel->percentageAt(set, category); |
|
202 | return m_internalModel->percentageAt(set, category); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | /*! |
|
205 | /*! | |
206 | \internal \a category |
|
206 | \internal \a category | |
207 | */ |
|
207 | */ | |
208 | qreal QBarSeries::categorySum(int category) |
|
208 | qreal QBarSeries::categorySum(int category) | |
209 | { |
|
209 | { | |
210 | return m_internalModel->categorySum(category); |
|
210 | return m_internalModel->categorySum(category); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | /*! |
|
213 | /*! | |
214 | \internal |
|
214 | \internal | |
215 | */ |
|
215 | */ | |
216 | qreal QBarSeries::maxCategorySum() |
|
216 | qreal QBarSeries::maxCategorySum() | |
217 | { |
|
217 | { | |
218 | return m_internalModel->maxCategorySum(); |
|
218 | return m_internalModel->maxCategorySum(); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \internal |
|
222 | \internal | |
223 | */ |
|
223 | */ | |
224 | BarChartModel& QBarSeries::model() |
|
224 | BarChartModel& QBarSeries::model() | |
225 | { |
|
225 | { | |
226 | return *m_internalModel; |
|
226 | return *m_internalModel; | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
229 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
230 | { |
|
230 | { | |
231 | // disconnect signals from old model |
|
231 | // disconnect signals from old model | |
232 | if(m_model) |
|
232 | if(m_model) | |
233 | { |
|
233 | { | |
234 | disconnect(m_model, 0, this, 0); |
|
234 | disconnect(m_model, 0, this, 0); | |
235 | m_mapCategories = -1; |
|
235 | m_mapCategories = -1; | |
236 | m_mapBarBottom = -1; |
|
236 | m_mapBarBottom = -1; | |
237 | m_mapBarTop = -1; |
|
237 | m_mapBarTop = -1; | |
238 | m_mapFirst = 0; |
|
238 | m_mapFirst = 0; | |
239 | m_mapCount = 0; |
|
239 | m_mapCount = 0; | |
240 | m_mapOrientation = Qt::Vertical; |
|
240 | m_mapOrientation = Qt::Vertical; | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | // set new model |
|
243 | // set new model | |
244 | if(model) |
|
244 | if(model) | |
245 | { |
|
245 | { | |
246 | m_model = model; |
|
246 | m_model = model; | |
247 | return true; |
|
247 | return true; | |
248 | } |
|
248 | } | |
249 | else |
|
249 | else | |
250 | { |
|
250 | { | |
251 | m_model = 0; |
|
251 | m_model = 0; | |
252 | return false; |
|
252 | return false; | |
253 | } |
|
253 | } | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | // TODO |
|
256 | // TODO | |
257 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
257 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
258 | { |
|
258 | { | |
259 | if (!m_model) |
|
259 | if (!m_model) | |
260 | return; |
|
260 | return; | |
261 |
|
261 | |||
262 | m_mapCategories = categories; |
|
262 | m_mapCategories = categories; | |
263 | m_mapBarBottom = bottomBoundry; |
|
263 | m_mapBarBottom = bottomBoundry; | |
264 | m_mapBarTop = topBoundry; |
|
264 | m_mapBarTop = topBoundry; | |
265 | // m_mapFirst = 1; |
|
265 | // m_mapFirst = 1; | |
266 | m_mapOrientation = orientation; |
|
266 | m_mapOrientation = orientation; | |
267 |
|
267 | |||
268 | // connect the signals |
|
268 | // connect the signals | |
269 | if (m_mapOrientation == Qt::Vertical) { |
|
269 | if (m_mapOrientation == Qt::Vertical) { | |
270 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
270 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
271 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
271 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
272 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
272 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
273 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
273 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
274 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
274 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
275 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
275 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
276 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
276 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
277 | } else { |
|
277 | } else { | |
278 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
278 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
279 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
279 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
280 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
280 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
281 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
281 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
282 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
282 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
283 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
283 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
284 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
284 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 |
|
287 | |||
288 | // create the initial bars |
|
288 | // create the initial bars | |
289 | delete m_internalModel; |
|
289 | delete m_internalModel; | |
290 | if (m_mapOrientation == Qt::Vertical) { |
|
290 | if (m_mapOrientation == Qt::Vertical) { | |
291 | QStringList categories; |
|
291 | QStringList categories; | |
292 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
292 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
293 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
293 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
294 | m_internalModel = new BarChartModel(categories, this); |
|
294 | m_internalModel = new BarChartModel(categories, this); | |
295 |
|
295 | |||
296 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
296 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
297 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
297 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
298 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
298 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
299 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
299 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
300 |
a |
|
300 | appendBarSet(barSet); | |
301 | } |
|
301 | } | |
302 | } else { |
|
302 | } else { | |
303 | QStringList categories; |
|
303 | QStringList categories; | |
304 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
304 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
305 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
305 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
306 | m_internalModel = new BarChartModel(categories, this); |
|
306 | m_internalModel = new BarChartModel(categories, this); | |
307 |
|
307 | |||
308 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
308 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
309 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
309 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
310 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
310 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
311 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
311 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
312 |
a |
|
312 | appendBarSet(barSet); | |
313 | } |
|
313 | } | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void QBarSeries::setModelMappingShift(int first, int count) |
|
317 | void QBarSeries::setModelMappingShift(int first, int count) | |
318 | { |
|
318 | { | |
319 | m_mapFirst = first; |
|
319 | m_mapFirst = first; | |
320 | m_mapCount = count; |
|
320 | m_mapCount = count; | |
321 | } |
|
321 | } | |
322 |
|
322 | |||
323 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
323 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
324 | { |
|
324 | { | |
325 | Q_UNUSED(bottomRight) |
|
325 | Q_UNUSED(bottomRight) | |
326 |
|
326 | |||
327 | if (m_mapOrientation == Qt::Vertical) |
|
327 | if (m_mapOrientation == Qt::Vertical) | |
328 | { |
|
328 | { | |
329 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
329 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
330 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
330 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
331 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
331 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
332 | } |
|
332 | } | |
333 | else |
|
333 | else | |
334 | { |
|
334 | { | |
335 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
335 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
336 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
336 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
337 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
337 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
338 | } |
|
338 | } | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
341 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
342 | { |
|
342 | { | |
343 | if (m_mapOrientation == Qt::Vertical) { |
|
343 | if (m_mapOrientation == Qt::Vertical) { | |
344 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
344 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
345 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
345 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
346 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
346 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
347 | } |
|
347 | } | |
348 | } else { |
|
348 | } else { | |
349 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
349 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
350 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
350 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
351 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
351 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
352 | } |
|
352 | } | |
353 | } |
|
353 | } | |
354 | emit restructuredBar(1); |
|
354 | emit restructuredBar(1); | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
357 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
358 | { |
|
358 | { | |
359 | Q_UNUSED(parent) |
|
359 | Q_UNUSED(parent) | |
360 | Q_UNUSED(end) |
|
360 | Q_UNUSED(end) | |
361 |
|
361 | |||
362 | removeCategory(start - m_mapFirst); |
|
362 | removeCategory(start - m_mapFirst); | |
363 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
363 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
364 | { |
|
364 | { | |
365 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
365 | barsetAt(i)->removeValue(start - m_mapFirst); | |
366 | } |
|
366 | } | |
367 | emit restructuredBar(1); |
|
367 | emit restructuredBar(1); | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | void QBarSeries::barsetChanged() |
|
370 | void QBarSeries::barsetChanged() | |
371 | { |
|
371 | { | |
372 | emit updatedBars(); |
|
372 | emit updatedBars(); | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | QBarCategories QBarSeries::categories() const |
|
375 | QBarCategories QBarSeries::categories() const | |
376 | { |
|
376 | { | |
377 | QBarCategories categories; |
|
377 | QBarCategories categories; | |
378 | int count = m_internalModel->categoryCount(); |
|
378 | int count = m_internalModel->categoryCount(); | |
379 | for (int i=1; i <= count; i++) { |
|
379 | for (int i=1; i <= count; i++) { | |
380 | categories.insert(i, m_internalModel->categoryName(i - 1)); |
|
380 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
381 | } |
|
381 | } | |
382 | return categories; |
|
382 | return categories; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | #include "moc_qbarseries.cpp" |
|
385 | #include "moc_qbarseries.cpp" | |
386 |
|
386 | |||
387 | QTCOMMERCIALCHART_END_NAMESPACE |
|
387 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,97 +1,97 | |||||
1 | #ifndef BARSERIES_H |
|
1 | #ifndef BARSERIES_H | |
2 | #define BARSERIES_H |
|
2 | #define BARSERIES_H | |
3 |
|
3 | |||
4 | #include <qseries.h> |
|
4 | #include <qseries.h> | |
5 | #include <QStringList> |
|
5 | #include <QStringList> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | typedef QStringList QBarCategories; |
|
9 | typedef QStringList QBarCategories; | |
10 |
|
10 | |||
11 | class QBarSet; |
|
11 | class QBarSet; | |
12 | class BarChartModel; |
|
12 | class BarChartModel; | |
13 | class BarCategory; |
|
13 | class BarCategory; | |
14 |
|
14 | |||
15 | // Container for series |
|
15 | // Container for series | |
16 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
16 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
17 | { |
|
17 | { | |
18 | Q_OBJECT |
|
18 | Q_OBJECT | |
19 | public: |
|
19 | public: | |
20 | QBarSeries(QStringList categories, QObject *parent = 0); |
|
20 | QBarSeries(QStringList categories, QObject *parent = 0); | |
21 |
|
21 | |||
22 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
22 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
23 |
|
23 | |||
24 |
void a |
|
24 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
25 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
25 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
26 | void insertBarSet(int i, QBarSet *set); |
|
26 | void insertBarSet(int i, QBarSet *set); | |
27 | void insertCategory(int i, QString category); |
|
27 | void insertCategory(int i, QString category); | |
28 | void removeCategory(int i); |
|
28 | void removeCategory(int i); | |
29 | int barsetCount(); |
|
29 | int barsetCount() const; | |
30 | int categoryCount(); |
|
30 | int categoryCount() const; | |
31 | QList<QBarSet*> barSets(); |
|
31 | QList<QBarSet*> barSets() const; | |
32 | QBarCategories categories() const; |
|
32 | QBarCategories categories() const; | |
33 |
|
33 | |||
34 | bool setModel(QAbstractItemModel *model); |
|
34 | bool setModel(QAbstractItemModel *model); | |
35 | QAbstractItemModel *modelExt() { return m_model; } |
|
35 | QAbstractItemModel *modelExt() { return m_model; } | |
36 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
36 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
37 | void setModelMappingShift(int first, int count); |
|
37 | void setModelMappingShift(int first, int count); | |
38 |
|
38 | |||
39 | public: |
|
39 | public: | |
40 | // TODO: Functions below this are not part of api and will be moved |
|
40 | // TODO: Functions below this are not part of api and will be moved | |
41 | // to private implementation, when we start using it |
|
41 | // to private implementation, when we start using it | |
42 | // TODO: TO PIMPL ---> |
|
42 | // TODO: TO PIMPL ---> | |
43 | QBarSet* barsetAt(int index); |
|
43 | QBarSet* barsetAt(int index); | |
44 | QString categoryName(int category); |
|
44 | QString categoryName(int category); | |
45 | qreal min(); |
|
45 | qreal min(); | |
46 | qreal max(); |
|
46 | qreal max(); | |
47 | qreal valueAt(int set, int category); |
|
47 | qreal valueAt(int set, int category); | |
48 | qreal percentageAt(int set, int category); |
|
48 | qreal percentageAt(int set, int category); | |
49 | qreal categorySum(int category); |
|
49 | qreal categorySum(int category); | |
50 | qreal maxCategorySum(); |
|
50 | qreal maxCategorySum(); | |
51 | BarChartModel& model(); |
|
51 | BarChartModel& model(); | |
52 | // <--- TO PIMPL |
|
52 | // <--- TO PIMPL | |
53 |
|
53 | |||
54 | Q_SIGNALS: |
|
54 | Q_SIGNALS: | |
55 | //void changed(int index); |
|
55 | //void changed(int index); | |
56 | void clicked(QBarSet *barset, QString category); // Up to user of api, what to do with these signals |
|
56 | void clicked(QBarSet *barset, QString category); // Up to user of api, what to do with these signals | |
57 | void rightClicked(QBarSet *barset, QString category); |
|
57 | void rightClicked(QBarSet *barset, QString category); | |
58 |
|
58 | |||
59 | // |
|
59 | // | |
60 | void updatedBars(); |
|
60 | void updatedBars(); | |
61 | void restructuredBar(int); |
|
61 | void restructuredBar(int); | |
62 |
|
62 | |||
63 | // TODO: internal signals, these to private implementation. |
|
63 | // TODO: internal signals, these to private implementation. | |
64 | // TODO: TO PIMPL ---> |
|
64 | // TODO: TO PIMPL ---> | |
65 | void showToolTip(QPoint pos, QString tip); |
|
65 | void showToolTip(QPoint pos, QString tip); | |
66 | // <--- TO PIMPL |
|
66 | // <--- TO PIMPL | |
67 |
|
67 | |||
68 | public Q_SLOTS: |
|
68 | public Q_SLOTS: | |
69 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
69 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
70 |
|
70 | |||
71 | // TODO: TO PIMPL ---> |
|
71 | // TODO: TO PIMPL ---> | |
72 | void barsetClicked(QString category); |
|
72 | void barsetClicked(QString category); | |
73 | void barsetRightClicked(QString category); |
|
73 | void barsetRightClicked(QString category); | |
74 | // <--- TO PIMPL |
|
74 | // <--- TO PIMPL | |
75 |
|
75 | |||
76 | private Q_SLOTS: |
|
76 | private Q_SLOTS: | |
77 | // slots for updating bars when data in model changes |
|
77 | // slots for updating bars when data in model changes | |
78 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
78 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
79 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
79 | void modelDataAdded(QModelIndex parent, int start, int end); | |
80 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
80 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
81 | void barsetChanged(); |
|
81 | void barsetChanged(); | |
82 |
|
82 | |||
83 | protected: |
|
83 | protected: | |
84 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
84 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
85 |
|
85 | |||
86 | QAbstractItemModel* m_model; |
|
86 | QAbstractItemModel* m_model; | |
87 | int m_mapCategories; |
|
87 | int m_mapCategories; | |
88 | int m_mapBarBottom; |
|
88 | int m_mapBarBottom; | |
89 | int m_mapBarTop; |
|
89 | int m_mapBarTop; | |
90 | int m_mapFirst; |
|
90 | int m_mapFirst; | |
91 | int m_mapCount; |
|
91 | int m_mapCount; | |
92 | Qt::Orientation m_mapOrientation; |
|
92 | Qt::Orientation m_mapOrientation; | |
93 | }; |
|
93 | }; | |
94 |
|
94 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
95 | QTCOMMERCIALCHART_END_NAMESPACE | |
96 |
|
96 | |||
97 | #endif // BARSERIES_H |
|
97 | #endif // BARSERIES_H |
@@ -1,206 +1,206 | |||||
1 | #include "qbarset.h" |
|
1 | #include "qbarset.h" | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 | #include <QToolTip> |
|
3 | #include <QToolTip> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | /*! |
|
7 | /*! | |
8 | \class QBarSet |
|
8 | \class QBarSet | |
9 | \brief part of QtCommercial chart API. |
|
9 | \brief part of QtCommercial chart API. | |
10 |
|
10 | |||
11 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
11 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
12 | First value of set is assumed to belong to first category, second to second category and so on. |
|
12 | First value of set is assumed to belong to first category, second to second category and so on. | |
13 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
13 | If set has fewer values than there are categories, then the missing values are assumed to be | |
14 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
14 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
15 |
|
15 | |||
16 | \mainclass |
|
16 | \mainclass | |
17 |
|
17 | |||
18 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
18 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
19 | */ |
|
19 | */ | |
20 |
|
20 | |||
21 | /*! |
|
21 | /*! | |
22 | \fn void QBarSet::clicked(QString category) |
|
22 | \fn void QBarSet::clicked(QString category) | |
23 | \brief signals that set has been clicked |
|
23 | \brief signals that set has been clicked | |
24 | Parameter \a category describes on which category was clicked |
|
24 | Parameter \a category describes on which category was clicked | |
25 | */ |
|
25 | */ | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \fn void QBarSet::rightClicked(QString category) |
|
28 | \fn void QBarSet::rightClicked(QString category) | |
29 | \brief signals that set has been clicked with right mouse button |
|
29 | \brief signals that set has been clicked with right mouse button | |
30 | Parameter \a category describes on which category was clicked |
|
30 | Parameter \a category describes on which category was clicked | |
31 | */ |
|
31 | */ | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
34 | \fn void QBarSet::hoverEnter(QPoint pos) | |
35 | \brief signals that mouse has entered over the set at position \a pos. |
|
35 | \brief signals that mouse has entered over the set at position \a pos. | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \fn void QBarSet::hoverLeave() |
|
39 | \fn void QBarSet::hoverLeave() | |
40 | \brief signals that mouse has left from the set. |
|
40 | \brief signals that mouse has left from the set. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \fn void QBarSet::toggleFloatingValues() |
|
44 | \fn void QBarSet::toggleFloatingValues() | |
45 | \brief \internal |
|
45 | \brief \internal | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
49 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
50 | \brief \internal \a pos \a tip |
|
50 | \brief \internal \a pos \a tip | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
55 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
56 | */ |
|
56 | */ | |
57 | QBarSet::QBarSet(QString name, QObject *parent) |
|
57 | QBarSet::QBarSet(QString name, QObject *parent) | |
58 | : QObject(parent) |
|
58 | : QObject(parent) | |
59 | ,m_name(name) |
|
59 | ,m_name(name) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Sets new \a name for set. |
|
64 | Sets new \a name for set. | |
65 | */ |
|
65 | */ | |
66 | void QBarSet::setName(QString name) |
|
66 | void QBarSet::setName(QString name) | |
67 | { |
|
67 | { | |
68 | m_name = name; |
|
68 | m_name = name; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | Returns name of the set. |
|
72 | Returns name of the set. | |
73 | */ |
|
73 | */ | |
74 | QString QBarSet::name() |
|
74 | QString QBarSet::name() const | |
75 | { |
|
75 | { | |
76 | return m_name; |
|
76 | return m_name; | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | Appends new value \a value to the end of set. |
|
80 | Appends new value \a value to the end of set. | |
81 | */ |
|
81 | */ | |
82 | QBarSet& QBarSet::operator << (const qreal &value) |
|
82 | QBarSet& QBarSet::operator << (const qreal &value) | |
83 | { |
|
83 | { | |
84 | m_values.append(value); |
|
84 | m_values.append(value); | |
85 | emit structureChanged(); |
|
85 | emit structureChanged(); | |
86 | return *this; |
|
86 | return *this; | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QBarSet::insertValue(int i, qreal value) |
|
89 | void QBarSet::insertValue(int i, qreal value) | |
90 | { |
|
90 | { | |
91 | m_values.insert(i, value); |
|
91 | m_values.insert(i, value); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void QBarSet::removeValue(int i) |
|
94 | void QBarSet::removeValue(int i) | |
95 | { |
|
95 | { | |
96 | m_values.removeAt(i); |
|
96 | m_values.removeAt(i); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | Returns count of values in set. |
|
100 | Returns count of values in set. | |
101 | */ |
|
101 | */ | |
102 | int QBarSet::count() |
|
102 | int QBarSet::count() const | |
103 | { |
|
103 | { | |
104 | return m_values.count(); |
|
104 | return m_values.count(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | Returns value of set indexed by \a index |
|
108 | Returns value of set indexed by \a index | |
109 | */ |
|
109 | */ | |
110 | qreal QBarSet::valueAt(int index) |
|
110 | qreal QBarSet::valueAt(int index) const | |
111 | { |
|
111 | { | |
112 | return m_values.at(index); |
|
112 | return m_values.at(index); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | Sets a new value \a value to set, indexed by \a index |
|
116 | Sets a new value \a value to set, indexed by \a index | |
117 | */ |
|
117 | */ | |
118 | void QBarSet::setValue(int index, qreal value) |
|
118 | void QBarSet::setValue(int index, qreal value) | |
119 | { |
|
119 | { | |
120 | m_values.replace(index,value); |
|
120 | m_values.replace(index,value); | |
121 | emit valueChanged(); |
|
121 | emit valueChanged(); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | Returns total sum of all values in barset. |
|
125 | Returns total sum of all values in barset. | |
126 | */ |
|
126 | */ | |
127 | qreal QBarSet::total() |
|
127 | qreal QBarSet::total() const | |
128 | { |
|
128 | { | |
129 | qreal total(0); |
|
129 | qreal total(0); | |
130 | for (int i=0; i < m_values.count(); i++) { |
|
130 | for (int i=0; i < m_values.count(); i++) { | |
131 | total += m_values.at(i); |
|
131 | total += m_values.at(i); | |
132 | } |
|
132 | } | |
133 | return total; |
|
133 | return total; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | Sets pen for set. Bars of this set are drawn using \a pen |
|
137 | Sets pen for set. Bars of this set are drawn using \a pen | |
138 | */ |
|
138 | */ | |
139 | void QBarSet::setPen(const QPen &pen) |
|
139 | void QBarSet::setPen(const QPen &pen) | |
140 | { |
|
140 | { | |
141 | m_pen = pen; |
|
141 | m_pen = pen; | |
142 | emit valueChanged(); |
|
142 | emit valueChanged(); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | Returns pen of the set. |
|
146 | Returns pen of the set. | |
147 | */ |
|
147 | */ | |
148 | QPen QBarSet::pen() const |
|
148 | QPen QBarSet::pen() const | |
149 | { |
|
149 | { | |
150 | return m_pen; |
|
150 | return m_pen; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
154 | Sets brush for the set. Bars of this set are drawn using \a brush | |
155 | */ |
|
155 | */ | |
156 | void QBarSet::setBrush(const QBrush &brush) |
|
156 | void QBarSet::setBrush(const QBrush &brush) | |
157 | { |
|
157 | { | |
158 | m_brush = brush; |
|
158 | m_brush = brush; | |
159 | emit valueChanged(); |
|
159 | emit valueChanged(); | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | Returns brush of the set. |
|
163 | Returns brush of the set. | |
164 | */ |
|
164 | */ | |
165 | QBrush QBarSet::brush() const |
|
165 | QBrush QBarSet::brush() const | |
166 | { |
|
166 | { | |
167 | return m_brush; |
|
167 | return m_brush; | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Sets the pen for floating values that are drawn on top of this set |
|
171 | Sets the pen for floating values that are drawn on top of this set | |
172 | */ |
|
172 | */ | |
173 | void QBarSet::setFloatingValuePen(const QPen &pen) |
|
173 | void QBarSet::setFloatingValuePen(const QPen &pen) | |
174 | { |
|
174 | { | |
175 | m_floatingValuePen = pen; |
|
175 | m_floatingValuePen = pen; | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | /*! |
|
178 | /*! | |
179 | Returns the pen for floating values that are drawn on top of this set |
|
179 | Returns the pen for floating values that are drawn on top of this set | |
180 | */ |
|
180 | */ | |
181 | QPen QBarSet::floatingValuePen() const |
|
181 | QPen QBarSet::floatingValuePen() const | |
182 | { |
|
182 | { | |
183 | return m_floatingValuePen; |
|
183 | return m_floatingValuePen; | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \internal \a pos |
|
187 | \internal \a pos | |
188 | */ |
|
188 | */ | |
189 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
189 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
190 | { |
|
190 | { | |
191 | emit showToolTip(pos, m_name); |
|
191 | emit showToolTip(pos, m_name); | |
192 | emit hoverEnter(pos); |
|
192 | emit hoverEnter(pos); | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | \internal |
|
196 | \internal | |
197 | */ |
|
197 | */ | |
198 | void QBarSet::barHoverLeaveEvent() |
|
198 | void QBarSet::barHoverLeaveEvent() | |
199 | { |
|
199 | { | |
200 | // Emit signal to user of charts |
|
200 | // Emit signal to user of charts | |
201 | emit hoverLeave(); |
|
201 | emit hoverLeave(); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | #include "moc_qbarset.cpp" |
|
204 | #include "moc_qbarset.cpp" | |
205 |
|
205 | |||
206 | QTCOMMERCIALCHART_END_NAMESPACE |
|
206 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,74 +1,74 | |||||
1 | #ifndef QBARSET_H |
|
1 | #ifndef QBARSET_H | |
2 | #define QBARSET_H |
|
2 | #define QBARSET_H | |
3 |
|
3 | |||
4 | #include <qchartglobal.h> |
|
4 | #include <qchartglobal.h> | |
5 | #include <QPen> |
|
5 | #include <QPen> | |
6 | #include <QBrush> |
|
6 | #include <QBrush> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
10 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
11 | { |
|
11 | { | |
12 | Q_OBJECT |
|
12 | Q_OBJECT | |
13 | public: |
|
13 | public: | |
14 | QBarSet(QString name, QObject *parent = 0); |
|
14 | QBarSet(QString name, QObject *parent = 0); | |
15 |
|
15 | |||
16 | void setName(QString name); |
|
16 | void setName(QString name); | |
17 | QString name(); |
|
17 | QString name() const; | |
18 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
18 | QBarSet& operator << (const qreal &value); // appends new value to set | |
19 | void insertValue(int i, qreal value); |
|
19 | void insertValue(int i, qreal value); | |
20 | void removeValue(int i); |
|
20 | void removeValue(int i); | |
21 |
|
21 | |||
22 | // TODO: remove indices eventually. Use as internal? |
|
22 | // TODO: remove indices eventually. Use as internal? | |
23 |
int count(); |
|
23 | int count() const; // count of values in set | |
24 | qreal valueAt(int index); // for modifying individual values |
|
24 | qreal valueAt(int index) const; // for modifying individual values | |
25 | void setValue(int index, qreal value); // setter for individual value |
|
25 | void setValue(int index, qreal value); // setter for individual value | |
26 | qreal total(); // total values in the set |
|
26 | qreal total() const; // total values in the set | |
27 |
|
27 | |||
28 | // TODO: |
|
28 | // TODO: | |
29 | //qreal value(QString category); |
|
29 | //qreal value(QString category); | |
30 | //void setValue(QString category, qreal value); |
|
30 | //void setValue(QString category, qreal value); | |
31 |
|
31 | |||
32 | void setPen(const QPen &pen); |
|
32 | void setPen(const QPen &pen); | |
33 | QPen pen() const; |
|
33 | QPen pen() const; | |
34 |
|
34 | |||
35 | void setBrush(const QBrush &brush); |
|
35 | void setBrush(const QBrush &brush); | |
36 | QBrush brush() const; |
|
36 | QBrush brush() const; | |
37 |
|
37 | |||
38 | void setFloatingValuePen(const QPen &pen); |
|
38 | void setFloatingValuePen(const QPen &pen); | |
39 | QPen floatingValuePen() const; |
|
39 | QPen floatingValuePen() const; | |
40 |
|
40 | |||
41 | Q_SIGNALS: |
|
41 | Q_SIGNALS: | |
42 | void clicked(QString category); // Clicked and hover signals exposed to user |
|
42 | void clicked(QString category); // Clicked and hover signals exposed to user | |
43 | void rightClicked(QString category); |
|
43 | void rightClicked(QString category); | |
44 | void toggleFloatingValues(); |
|
44 | void toggleFloatingValues(); | |
45 |
|
45 | |||
46 | // TODO: Expose this to user or not? |
|
46 | // TODO: Expose this to user or not? | |
47 | // TODO: TO PIMPL ---> |
|
47 | // TODO: TO PIMPL ---> | |
48 | void structureChanged(); |
|
48 | void structureChanged(); | |
49 | void valueChanged(); |
|
49 | void valueChanged(); | |
50 | void hoverEnter(QPoint pos); |
|
50 | void hoverEnter(QPoint pos); | |
51 | void hoverLeave(); |
|
51 | void hoverLeave(); | |
52 | void showToolTip(QPoint pos, QString tip); // Private signal |
|
52 | void showToolTip(QPoint pos, QString tip); // Private signal | |
53 | // <--- TO PIMPL |
|
53 | // <--- TO PIMPL | |
54 |
|
54 | |||
55 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
56 | // These are for internal communication |
|
56 | // These are for internal communication | |
57 | // TODO: TO PIMPL ---> |
|
57 | // TODO: TO PIMPL ---> | |
58 | void barHoverEnterEvent(QPoint pos); |
|
58 | void barHoverEnterEvent(QPoint pos); | |
59 | void barHoverLeaveEvent(); |
|
59 | void barHoverLeaveEvent(); | |
60 | // <--- TO PIMPL |
|
60 | // <--- TO PIMPL | |
61 |
|
61 | |||
62 | private: |
|
62 | private: | |
63 |
|
63 | |||
64 | QString m_name; |
|
64 | QString m_name; | |
65 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
65 | QList<qreal> m_values; // TODO: replace with map (category, value) | |
66 | QMap<QString, qreal> m_mappedValues; |
|
66 | QMap<QString, qreal> m_mappedValues; | |
67 | QPen m_pen; |
|
67 | QPen m_pen; | |
68 | QBrush m_brush; |
|
68 | QBrush m_brush; | |
69 | QPen m_floatingValuePen; |
|
69 | QPen m_floatingValuePen; | |
70 | }; |
|
70 | }; | |
71 |
|
71 | |||
72 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | QTCOMMERCIALCHART_END_NAMESPACE | |
73 |
|
73 | |||
74 | #endif // QBARSET_H |
|
74 | #endif // QBARSET_H |
@@ -1,83 +1,83 | |||||
1 | #include "stackedbarchartitem_p.h" |
|
1 | #include "stackedbarchartitem_p.h" | |
2 | #include "bar_p.h" |
|
2 | #include "bar_p.h" | |
3 | #include "barvalue_p.h" |
|
3 | #include "barvalue_p.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QDebug> |
|
5 | #include <QDebug> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
9 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
10 | BarChartItem(series, presenter) |
|
10 | BarChartItem(series, presenter) | |
11 | { |
|
11 | { | |
12 | } |
|
12 | } | |
13 |
|
13 | |||
14 | StackedBarChartItem::~StackedBarChartItem() |
|
14 | StackedBarChartItem::~StackedBarChartItem() | |
15 | { |
|
15 | { | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
18 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
19 | { |
|
19 | { | |
20 | QVector<QRectF> layout; |
|
20 | QVector<QRectF> layout; | |
21 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
21 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
22 |
|
22 | |||
23 | qreal maxSum = m_series->maxCategorySum(); |
|
23 | qreal maxSum = m_series->maxCategorySum(); | |
24 | // Domain: |
|
24 | // Domain: | |
25 | if (m_domainMaxY > maxSum) { |
|
25 | if (m_domainMaxY > maxSum) { | |
26 | maxSum = m_domainMaxY; |
|
26 | maxSum = m_domainMaxY; | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | qreal height = geometry().height(); |
|
29 | qreal height = geometry().height(); | |
30 | qreal width = geometry().width(); |
|
30 | qreal width = geometry().width(); | |
31 | qreal scale = (height / m_series->maxCategorySum()); |
|
31 | qreal scale = (height / m_series->maxCategorySum()); | |
32 | qreal categotyCount = m_series->categoryCount(); |
|
32 | qreal categotyCount = m_series->categoryCount(); | |
33 | qreal barWidth = width / (categotyCount * 2); |
|
33 | qreal barWidth = width / (categotyCount * 2); | |
34 | qreal xStep = width / categotyCount; |
|
34 | qreal xStep = width / categotyCount; | |
35 | qreal xPos = xStep / 2 - barWidth / 2; |
|
35 | qreal xPos = xStep / 2 - barWidth / 2; | |
36 |
|
36 | |||
37 | int itemIndex(0); |
|
37 | int itemIndex(0); | |
38 | for (int category = 0; category < categotyCount; category++) { |
|
38 | for (int category = 0; category < categotyCount; category++) { | |
39 | qreal yPos = height; |
|
39 | qreal yPos = height; | |
40 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
40 | for (int set=0; set < m_series->barsetCount(); set++) { | |
41 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
41 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
42 | Bar* bar = m_bars.at(itemIndex); |
|
42 | Bar* bar = m_bars.at(itemIndex); | |
43 | bar->setPen(m_series->barsetAt(set)->pen()); |
|
43 | bar->setPen(m_series->barsetAt(set)->pen()); | |
44 | bar->setBrush(m_series->barsetAt(set)->brush()); |
|
44 | bar->setBrush(m_series->barsetAt(set)->brush()); | |
45 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
45 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
46 | layout.append(rect); |
|
46 | layout.append(rect); | |
47 | itemIndex++; |
|
47 | itemIndex++; | |
48 | yPos -= barHeight; |
|
48 | yPos -= barHeight; | |
49 | } |
|
49 | } | |
50 | xPos += xStep; |
|
50 | xPos += xStep; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | // Position floating values |
|
53 | // Position floating values | |
54 | itemIndex = 0; |
|
54 | itemIndex = 0; | |
55 | xPos = (width/categotyCount); |
|
55 | xPos = (width/categotyCount); | |
56 | for (int category=0; category < m_series->categoryCount(); category++) { |
|
56 | for (int category=0; category < m_series->categoryCount(); category++) { | |
57 | qreal yPos = height; |
|
57 | qreal yPos = height; | |
58 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
58 | for (int set=0; set < m_series->barsetCount(); set++) { | |
59 | qreal barHeight = m_series->valueAt(set, category) * scale; |
|
59 | qreal barHeight = m_series->valueAt(set, category) * scale; | |
60 | BarValue* value = m_floatingValues.at(itemIndex); |
|
60 | BarValue* value = m_floatingValues.at(itemIndex); | |
61 |
|
61 | |||
62 | QBarSet* barSet = m_series->barsetAt(set); |
|
62 | QBarSet* barSet = m_series->barsetAt(set); | |
63 | value->resize(100, 50); // TODO: proper layout for this. |
|
63 | value->resize(100, 50); // TODO: proper layout for this. | |
64 | value->setPos(xPos, yPos-barHeight / 2); |
|
64 | value->setPos(xPos, yPos-barHeight / 2); | |
65 | value->setPen(barSet->floatingValuePen()); |
|
65 | value->setPen(barSet->floatingValuePen()); | |
66 |
|
66 | |||
67 | if (!qFuzzyIsNull(m_series->valueAt(set, category))) { |
|
67 | if (!qFuzzyIsNull(m_series->valueAt(set, category))) { | |
68 |
value->set |
|
68 | value->setText(QString::number(m_series->valueAt(set,category))); | |
69 | } else { |
|
69 | } else { | |
70 |
value->set |
|
70 | value->setText(QString("")); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | itemIndex++; |
|
73 | itemIndex++; | |
74 | yPos -= barHeight; |
|
74 | yPos -= barHeight; | |
75 | } |
|
75 | } | |
76 | xPos += xStep; |
|
76 | xPos += xStep; | |
77 | } |
|
77 | } | |
78 | return layout; |
|
78 | return layout; | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | #include "moc_stackedbarchartitem_p.cpp" |
|
81 | #include "moc_stackedbarchartitem_p.cpp" | |
82 |
|
82 | |||
83 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now