@@ -1,367 +1,366 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE:BSD$ |
|
9 | ** $QT_BEGIN_LICENSE:BSD$ | |
10 | ** You may use this file under the terms of the BSD license as follows: |
|
10 | ** You may use this file under the terms of the BSD license as follows: | |
11 | ** |
|
11 | ** | |
12 | ** "Redistribution and use in source and binary forms, with or without |
|
12 | ** "Redistribution and use in source and binary forms, with or without | |
13 | ** modification, are permitted provided that the following conditions are |
|
13 | ** modification, are permitted provided that the following conditions are | |
14 | ** met: |
|
14 | ** met: | |
15 | ** * Redistributions of source code must retain the above copyright |
|
15 | ** * Redistributions of source code must retain the above copyright | |
16 | ** notice, this list of conditions and the following disclaimer. |
|
16 | ** notice, this list of conditions and the following disclaimer. | |
17 | ** * Redistributions in binary form must reproduce the above copyright |
|
17 | ** * Redistributions in binary form must reproduce the above copyright | |
18 | ** notice, this list of conditions and the following disclaimer in |
|
18 | ** notice, this list of conditions and the following disclaimer in | |
19 | ** the documentation and/or other materials provided with the |
|
19 | ** the documentation and/or other materials provided with the | |
20 | ** distribution. |
|
20 | ** distribution. | |
21 | ** * Neither the name of Digia nor the names of its contributors |
|
21 | ** * Neither the name of Digia nor the names of its contributors | |
22 | ** may be used to endorse or promote products derived from this |
|
22 | ** may be used to endorse or promote products derived from this | |
23 | ** software without specific prior written permission. |
|
23 | ** software without specific prior written permission. | |
24 | ** |
|
24 | ** | |
25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|
35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | |
36 | ** $QT_END_LICENSE$ |
|
36 | ** $QT_END_LICENSE$ | |
37 | ** |
|
37 | ** | |
38 | ****************************************************************************/ |
|
38 | ****************************************************************************/ | |
39 |
|
39 | |||
40 | #include "themewidget.h" |
|
40 | #include "themewidget.h" | |
41 |
|
41 | |||
42 | #include <QChartView> |
|
42 | #include <QChartView> | |
43 | #include <QPieSeries> |
|
43 | #include <QPieSeries> | |
44 | #include <QPieSlice> |
|
44 | #include <QPieSlice> | |
45 | #include <QBarSeries> |
|
45 | #include <QBarSeries> | |
46 | #include <QPercentBarSeries> |
|
46 | #include <QPercentBarSeries> | |
47 | #include <QStackedBarSeries> |
|
47 | #include <QStackedBarSeries> | |
48 | #include <QBarSet> |
|
48 | #include <QBarSet> | |
49 | #include <QLineSeries> |
|
49 | #include <QLineSeries> | |
50 | #include <QSplineSeries> |
|
50 | #include <QSplineSeries> | |
51 | #include <QScatterSeries> |
|
51 | #include <QScatterSeries> | |
52 | #include <QAreaSeries> |
|
52 | #include <QAreaSeries> | |
53 | #include <QLegend> |
|
53 | #include <QLegend> | |
54 | #include <QGridLayout> |
|
54 | #include <QGridLayout> | |
55 | #include <QFormLayout> |
|
55 | #include <QFormLayout> | |
56 | #include <QComboBox> |
|
56 | #include <QComboBox> | |
57 | #include <QSpinBox> |
|
57 | #include <QSpinBox> | |
58 | #include <QCheckBox> |
|
58 | #include <QCheckBox> | |
59 | #include <QGroupBox> |
|
59 | #include <QGroupBox> | |
60 | #include <QLabel> |
|
60 | #include <QLabel> | |
61 | #include <QTime> |
|
61 | #include <QTime> | |
62 |
|
62 | |||
63 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
63 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
64 | QWidget(parent), |
|
64 | QWidget(parent), | |
65 | m_listCount(3), |
|
65 | m_listCount(3), | |
66 | m_valueMax(100), |
|
66 | m_valueMax(100), | |
67 | m_valueCount(11), |
|
67 | m_valueCount(11), | |
68 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
68 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
69 | m_themeComboBox(createThemeBox()), |
|
69 | m_themeComboBox(createThemeBox()), | |
70 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), |
|
70 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), | |
71 | m_animatedComboBox(createAnimationBox()), |
|
71 | m_animatedComboBox(createAnimationBox()), | |
72 | m_legendComboBox(createLegendBox()) |
|
72 | m_legendComboBox(createLegendBox()) | |
73 |
|
73 | |||
74 | { |
|
74 | { | |
75 |
|
75 | |||
76 | connectSignals(); |
|
76 | connectSignals(); | |
77 | // create layout |
|
77 | // create layout | |
78 | QGridLayout* baseLayout = new QGridLayout(); |
|
78 | QGridLayout* baseLayout = new QGridLayout(); | |
79 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
79 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
80 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
80 | settingsLayout->addWidget(new QLabel("Theme:")); | |
81 | settingsLayout->addWidget(m_themeComboBox); |
|
81 | settingsLayout->addWidget(m_themeComboBox); | |
82 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
82 | settingsLayout->addWidget(new QLabel("Animation:")); | |
83 | settingsLayout->addWidget(m_animatedComboBox); |
|
83 | settingsLayout->addWidget(m_animatedComboBox); | |
84 | settingsLayout->addWidget(m_legendComboBox); |
|
84 | settingsLayout->addWidget(m_legendComboBox); | |
85 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
85 | settingsLayout->addWidget(m_antialiasCheckBox); | |
86 | settingsLayout->addStretch(); |
|
86 | settingsLayout->addStretch(); | |
87 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
87 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
88 |
|
88 | |||
89 | //create charts |
|
89 | //create charts | |
90 |
|
90 | |||
91 | QChartView *chartView; |
|
91 | QChartView *chartView; | |
92 |
|
92 | |||
93 | chartView = new QChartView(createAreaChart()); |
|
93 | chartView = new QChartView(createAreaChart()); | |
94 | baseLayout->addWidget(chartView, 1, 0); |
|
94 | baseLayout->addWidget(chartView, 1, 0); | |
95 | m_charts << chartView; |
|
95 | m_charts << chartView; | |
96 |
|
96 | |||
97 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
97 | chartView = new QChartView(createBarChart(m_valueCount)); | |
98 | baseLayout->addWidget(chartView, 1, 1); |
|
98 | baseLayout->addWidget(chartView, 1, 1); | |
99 | m_charts << chartView; |
|
99 | m_charts << chartView; | |
100 |
|
100 | |||
101 | chartView = new QChartView(createLineChart()); |
|
101 | chartView = new QChartView(createLineChart()); | |
102 | baseLayout->addWidget(chartView, 1, 2); |
|
102 | baseLayout->addWidget(chartView, 1, 2); | |
103 | m_charts << chartView; |
|
103 | m_charts << chartView; | |
104 |
|
104 | |||
105 | chartView = new QChartView(createPieChart()); |
|
105 | chartView = new QChartView(createPieChart()); | |
106 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
106 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
107 | baseLayout->addWidget(chartView, 2, 0); |
|
107 | baseLayout->addWidget(chartView, 2, 0); | |
108 | m_charts << chartView; |
|
108 | m_charts << chartView; | |
109 |
|
109 | |||
110 | chartView = new QChartView(createSplineChart()); |
|
110 | chartView = new QChartView(createSplineChart()); | |
111 | baseLayout->addWidget(chartView, 2, 1); |
|
111 | baseLayout->addWidget(chartView, 2, 1); | |
112 | m_charts << chartView; |
|
112 | m_charts << chartView; | |
113 |
|
113 | |||
114 | chartView = new QChartView(createScatterChart()); |
|
114 | chartView = new QChartView(createScatterChart()); | |
115 | baseLayout->addWidget(chartView, 2, 2); |
|
115 | baseLayout->addWidget(chartView, 2, 2); | |
116 | m_charts << chartView; |
|
116 | m_charts << chartView; | |
117 |
|
117 | |||
118 | setLayout(baseLayout); |
|
118 | setLayout(baseLayout); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | ThemeWidget::~ThemeWidget() |
|
121 | ThemeWidget::~ThemeWidget() | |
122 | { |
|
122 | { | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | void ThemeWidget::connectSignals() |
|
125 | void ThemeWidget::connectSignals() | |
126 | { |
|
126 | { | |
127 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
127 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
128 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
128 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
129 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
129 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
130 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
130 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
133 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
134 | { |
|
134 | { | |
135 | DataTable dataTable; |
|
135 | DataTable dataTable; | |
136 |
|
136 | |||
137 | // set seed for random stuff |
|
137 | // set seed for random stuff | |
138 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
138 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
139 |
|
139 | |||
140 | // generate random data |
|
140 | // generate random data | |
141 | for (int i(0); i < listCount; i++) { |
|
141 | for (int i(0); i < listCount; i++) { | |
142 | DataList dataList; |
|
142 | DataList dataList; | |
143 | for (int j(0); j < valueCount; j++) { |
|
143 | for (int j(0); j < valueCount; j++) { | |
144 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); |
|
144 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); | |
145 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); |
|
145 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); | |
146 | dataList << Data(value, label); |
|
146 | dataList << Data(value, label); | |
147 | } |
|
147 | } | |
148 | dataTable << dataList; |
|
148 | dataTable << dataList; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | return dataTable; |
|
151 | return dataTable; | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | QComboBox* ThemeWidget::createThemeBox() const |
|
154 | QComboBox* ThemeWidget::createThemeBox() const | |
155 | { |
|
155 | { | |
156 | // settings layout |
|
156 | // settings layout | |
157 | QComboBox* themeComboBox = new QComboBox(); |
|
157 | QComboBox* themeComboBox = new QComboBox(); | |
158 | themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
158 | themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
159 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
159 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
160 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
160 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
161 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
161 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
162 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
162 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
163 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
163 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
164 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
164 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
165 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
165 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
166 | return themeComboBox; |
|
166 | return themeComboBox; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | QComboBox* ThemeWidget::createAnimationBox() const |
|
169 | QComboBox* ThemeWidget::createAnimationBox() const | |
170 | { |
|
170 | { | |
171 | // settings layout |
|
171 | // settings layout | |
172 | QComboBox* animationComboBox = new QComboBox(); |
|
172 | QComboBox* animationComboBox = new QComboBox(); | |
173 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
173 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
174 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
174 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
175 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
175 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
176 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
176 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
177 | return animationComboBox; |
|
177 | return animationComboBox; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | QComboBox* ThemeWidget::createLegendBox() const |
|
180 | QComboBox* ThemeWidget::createLegendBox() const | |
181 | { |
|
181 | { | |
182 | QComboBox* legendComboBox = new QComboBox(); |
|
182 | QComboBox* legendComboBox = new QComboBox(); | |
183 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
183 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); | |
184 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
184 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); | |
185 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
185 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); | |
186 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
186 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); | |
187 | return legendComboBox; |
|
187 | return legendComboBox; | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | QChart* ThemeWidget::createAreaChart() const |
|
190 | QChart* ThemeWidget::createAreaChart() const | |
191 | { |
|
191 | { | |
192 | // area chart |
|
192 | // area chart | |
193 | QChart *chart = new QChart(); |
|
193 | QChart *chart = new QChart(); | |
194 | chart->setTitle("Area chart"); |
|
194 | chart->setTitle("Area chart"); | |
195 | { |
|
195 | { | |
196 | QString name("Series "); |
|
196 | QString name("Series "); | |
197 | int nameIndex = 0; |
|
197 | int nameIndex = 0; | |
198 | for (int i(0); i < m_dataTable.count(); i++) { |
|
198 | for (int i(0); i < m_dataTable.count(); i++) { | |
199 | QLineSeries *series1 = new QLineSeries(chart); |
|
199 | QLineSeries *series1 = new QLineSeries(chart); | |
200 | QLineSeries *series2 = new QLineSeries(chart); |
|
200 | QLineSeries *series2 = new QLineSeries(chart); | |
201 | foreach (Data data, m_dataTable[i]) { |
|
201 | foreach (Data data, m_dataTable[i]) { | |
202 | series1->append(data.first); |
|
202 | series1->append(data.first); | |
203 | series2->append(QPointF(data.first.x(), 0.0)); |
|
203 | series2->append(QPointF(data.first.x(), 0.0)); | |
204 | } |
|
204 | } | |
205 | QAreaSeries *area = new QAreaSeries(series1, series2); |
|
205 | QAreaSeries *area = new QAreaSeries(series1, series2); | |
206 | area->setName(name + QString::number(nameIndex)); |
|
206 | area->setName(name + QString::number(nameIndex)); | |
207 | nameIndex++; |
|
207 | nameIndex++; | |
208 | chart->addSeries(area); |
|
208 | chart->addSeries(area); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 | return chart; |
|
211 | return chart; | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
214 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
215 | { |
|
215 | { | |
216 | // bar chart |
|
216 | // bar chart | |
217 | QChart* chart = new QChart(); |
|
217 | QChart* chart = new QChart(); | |
218 | chart->setTitle("Bar chart"); |
|
218 | chart->setTitle("Bar chart"); | |
219 | { |
|
219 | { | |
220 | QBarCategories categories; |
|
220 | QBarCategories categories; | |
221 | // TODO: categories |
|
221 | // TODO: categories | |
222 | for (int i(0); i < valueCount; i++) |
|
222 | for (int i(0); i < valueCount; i++) | |
223 | categories << QString::number(i); |
|
223 | categories << QString::number(i); | |
224 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
224 | // QBarSeries* series = new QBarSeries(categories, chart); | |
225 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
225 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
226 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
226 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
227 | for (int i(0); i < m_dataTable.count(); i++) { |
|
227 | for (int i(0); i < m_dataTable.count(); i++) { | |
228 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
228 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
229 | foreach (Data data, m_dataTable[i]) |
|
229 | foreach (Data data, m_dataTable[i]) | |
230 | *set << data.first.y(); |
|
230 | *set << data.first.y(); | |
231 | series->appendBarSet(set); |
|
231 | series->appendBarSet(set); | |
232 | } |
|
232 | } | |
233 | chart->addSeries(series); |
|
233 | chart->addSeries(series); | |
234 | } |
|
234 | } | |
235 | return chart; |
|
235 | return chart; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | QChart* ThemeWidget::createLineChart() const |
|
238 | QChart* ThemeWidget::createLineChart() const | |
239 | { |
|
239 | { | |
240 | // line chart |
|
240 | // line chart | |
241 | QChart* chart = new QChart(); |
|
241 | QChart* chart = new QChart(); | |
242 | chart->setTitle("Line chart"); |
|
242 | chart->setTitle("Line chart"); | |
243 | QString name("Series "); |
|
243 | QString name("Series "); | |
244 | int nameIndex = 0; |
|
244 | int nameIndex = 0; | |
245 | foreach (DataList list, m_dataTable) { |
|
245 | foreach (DataList list, m_dataTable) { | |
246 | QLineSeries *series = new QLineSeries(chart); |
|
246 | QLineSeries *series = new QLineSeries(chart); | |
247 | foreach (Data data, list) |
|
247 | foreach (Data data, list) | |
248 | series->append(data.first); |
|
248 | series->append(data.first); | |
249 | series->setName(name + QString::number(nameIndex)); |
|
249 | series->setName(name + QString::number(nameIndex)); | |
250 | nameIndex++; |
|
250 | nameIndex++; | |
251 | chart->addSeries(series); |
|
251 | chart->addSeries(series); | |
252 | } |
|
252 | } | |
253 | return chart; |
|
253 | return chart; | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | QChart* ThemeWidget::createPieChart() const |
|
256 | QChart* ThemeWidget::createPieChart() const | |
257 | { |
|
257 | { | |
258 | // pie chart |
|
258 | // pie chart | |
259 | QChart* chart = new QChart(); |
|
259 | QChart* chart = new QChart(); | |
260 | chart->setTitle("Pie chart"); |
|
260 | chart->setTitle("Pie chart"); | |
261 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
261 | qreal pieSize = 1.0 / m_dataTable.count(); | |
262 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
262 | for (int i = 0; i < m_dataTable.count(); i++) { | |
263 | QPieSeries *series = new QPieSeries(chart); |
|
263 | QPieSeries *series = new QPieSeries(chart); | |
264 | foreach (Data data, m_dataTable[i]) { |
|
264 | foreach (Data data, m_dataTable[i]) { | |
265 | QPieSlice *slice = series->append(data.first.y(), data.second); |
|
265 | QPieSlice *slice = series->append(data.first.y(), data.second); | |
266 | if (data == m_dataTable[i].first()) { |
|
266 | if (data == m_dataTable[i].first()) { | |
267 | slice->setLabelVisible(); |
|
267 | slice->setLabelVisible(); | |
268 | slice->setExploded(); |
|
268 | slice->setExploded(); | |
269 | } |
|
269 | } | |
270 | } |
|
270 | } | |
271 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
271 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
272 | series->setPieSize(pieSize); |
|
272 | series->setPieSize(pieSize); | |
273 | series->setPiePosition(hPos, 0.5); |
|
273 | series->setPiePosition(hPos, 0.5); | |
274 | chart->addSeries(series); |
|
274 | chart->addSeries(series); | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | return chart; |
|
277 | return chart; | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | QChart* ThemeWidget::createSplineChart() const |
|
280 | QChart* ThemeWidget::createSplineChart() const | |
281 | { // spine chart |
|
281 | { // spine chart | |
282 | QChart* chart = new QChart(); |
|
282 | QChart* chart = new QChart(); | |
283 | chart->setTitle("Spline chart"); |
|
283 | chart->setTitle("Spline chart"); | |
284 | QString name("Series "); |
|
284 | QString name("Series "); | |
285 | int nameIndex = 0; |
|
285 | int nameIndex = 0; | |
286 | foreach (DataList list, m_dataTable) { |
|
286 | foreach (DataList list, m_dataTable) { | |
287 | QSplineSeries *series = new QSplineSeries(chart); |
|
287 | QSplineSeries *series = new QSplineSeries(chart); | |
288 | foreach (Data data, list) |
|
288 | foreach (Data data, list) | |
289 | series->append(data.first); |
|
289 | series->append(data.first); | |
290 | series->setName(name + QString::number(nameIndex)); |
|
290 | series->setName(name + QString::number(nameIndex)); | |
291 | nameIndex++; |
|
291 | nameIndex++; | |
292 | chart->addSeries(series); |
|
292 | chart->addSeries(series); | |
293 | } |
|
293 | } | |
294 | return chart; |
|
294 | return chart; | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | QChart* ThemeWidget::createScatterChart() const |
|
297 | QChart* ThemeWidget::createScatterChart() const | |
298 | { // scatter chart |
|
298 | { // scatter chart | |
299 | QChart* chart = new QChart(); |
|
299 | QChart* chart = new QChart(); | |
300 | chart->setTitle("Scatter chart"); |
|
300 | chart->setTitle("Scatter chart"); | |
301 | QString name("Series "); |
|
301 | QString name("Series "); | |
302 | int nameIndex = 0; |
|
302 | int nameIndex = 0; | |
303 | foreach (DataList list, m_dataTable) { |
|
303 | foreach (DataList list, m_dataTable) { | |
304 | QScatterSeries *series = new QScatterSeries(chart); |
|
304 | QScatterSeries *series = new QScatterSeries(chart); | |
305 | foreach (Data data, list) |
|
305 | foreach (Data data, list) | |
306 | series->append(data.first); |
|
306 | series->append(data.first); | |
307 | series->setName(name + QString::number(nameIndex)); |
|
307 | series->setName(name + QString::number(nameIndex)); | |
308 | nameIndex++; |
|
308 | nameIndex++; | |
309 | chart->addSeries(series); |
|
309 | chart->addSeries(series); | |
310 | } |
|
310 | } | |
311 | return chart; |
|
311 | return chart; | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | void ThemeWidget::updateUI() |
|
314 | void ThemeWidget::updateUI() | |
315 | { |
|
315 | { | |
316 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
316 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
317 |
|
317 | |||
318 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
318 | if (m_charts.at(0)->chart()->theme() != theme) { | |
319 | foreach (QChartView *chartView, m_charts) |
|
319 | foreach (QChartView *chartView, m_charts) | |
320 | chartView->chart()->setTheme(theme); |
|
320 | chartView->chart()->setTheme(theme); | |
321 |
|
321 | |||
322 | QPalette pal = window()->palette(); |
|
322 | QPalette pal = window()->palette(); | |
323 | if (theme == QChart::ChartThemeLight) { |
|
323 | if (theme == QChart::ChartThemeLight) { | |
324 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
324 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
325 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
325 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
326 | } else if (theme == QChart::ChartThemeDark) { |
|
326 | } else if (theme == QChart::ChartThemeDark) { | |
327 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
327 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
328 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
329 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
329 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
330 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
330 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
331 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
331 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
332 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
332 | } else if (theme == QChart::ChartThemeBrownSand) { | |
333 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
333 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
334 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
335 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
335 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
336 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
336 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
338 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
338 | } else if (theme == QChart::ChartThemeHighContrast) { | |
339 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
339 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
340 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
340 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
341 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
341 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
342 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
342 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
343 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
344 | } else { |
|
344 | } else { | |
345 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
345 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
347 | } |
|
347 | } | |
348 | window()->setPalette(pal); |
|
348 | window()->setPalette(pal); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | bool checked = m_antialiasCheckBox->isChecked(); |
|
351 | bool checked = m_antialiasCheckBox->isChecked(); | |
352 | foreach (QChartView *chart, m_charts) |
|
352 | foreach (QChartView *chart, m_charts) | |
353 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
353 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
354 |
|
354 | |||
355 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
355 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
356 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
356 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
357 | foreach (QChartView *chartView, m_charts) |
|
357 | foreach (QChartView *chartView, m_charts) | |
358 | chartView->chart()->setAnimationOptions(options); |
|
358 | chartView->chart()->setAnimationOptions(options); | |
359 | } |
|
359 | } | |
360 |
|
360 | |||
361 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
361 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
362 | foreach (QChartView *chartView, m_charts) { |
|
362 | foreach (QChartView *chartView, m_charts) { | |
363 | qDebug() << alignment; |
|
|||
364 | chartView->chart()->legend()->setAlignmnent(alignment); |
|
363 | chartView->chart()->legend()->setAlignmnent(alignment); | |
365 | } |
|
364 | } | |
366 | } |
|
365 | } | |
367 |
|
366 |
@@ -1,29 +1,29 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/bar.cpp \ |
|
5 | $$PWD/bar.cpp \ | |
6 | $$PWD/barchartmodel.cpp \ |
|
6 | $$PWD/barchartmodel.cpp \ | |
7 | $$PWD/barchartitem.cpp \ |
|
7 | $$PWD/barchartitem.cpp \ | |
8 | $$PWD/percentbarchartitem.cpp \ |
|
8 | $$PWD/percentbarchartitem.cpp \ | |
9 | $$PWD/qbarseries.cpp \ |
|
9 | $$PWD/qbarseries.cpp \ | |
10 | $$PWD/qbarset.cpp \ |
|
10 | $$PWD/qbarset.cpp \ | |
11 | $$PWD/qpercentbarseries.cpp \ |
|
11 | $$PWD/qpercentbarseries.cpp \ | |
12 | $$PWD/qstackedbarseries.cpp \ |
|
12 | $$PWD/qstackedbarseries.cpp \ | |
13 | $$PWD/stackedbarchartitem.cpp \ |
|
13 | $$PWD/stackedbarchartitem.cpp \ | |
14 |
$$PWD/bar |
|
14 | $$PWD/barlabel.cpp | |
15 |
|
15 | |||
16 | PRIVATE_HEADERS += \ |
|
16 | PRIVATE_HEADERS += \ | |
17 | $$PWD/bar_p.h \ |
|
17 | $$PWD/bar_p.h \ | |
18 | $$PWD/barchartmodel_p.h \ |
|
18 | $$PWD/barchartmodel_p.h \ | |
19 | $$PWD/barchartitem_p.h \ |
|
19 | $$PWD/barchartitem_p.h \ | |
20 | $$PWD/percentbarchartitem_p.h \ |
|
20 | $$PWD/percentbarchartitem_p.h \ | |
21 | $$PWD/stackedbarchartitem_p.h \ |
|
21 | $$PWD/stackedbarchartitem_p.h \ | |
22 |
$$PWD/bar |
|
22 | $$PWD/barlabel_p.h | |
23 |
|
23 | |||
24 | PUBLIC_HEADERS += \ |
|
24 | PUBLIC_HEADERS += \ | |
25 | $$PWD/qbarseries.h \ |
|
25 | $$PWD/qbarseries.h \ | |
26 | $$PWD/qbarset.h \ |
|
26 | $$PWD/qbarset.h \ | |
27 | $$PWD/qpercentbarseries.h \ |
|
27 | $$PWD/qpercentbarseries.h \ | |
28 | $$PWD/qstackedbarseries.h |
|
28 | $$PWD/qstackedbarseries.h | |
29 |
|
29 |
@@ -1,222 +1,222 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 |
#include "bar |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qchart.h" |
|
26 | #include "qchart.h" | |
27 | #include "qchartaxis.h" |
|
27 | #include "qchartaxis.h" | |
28 | #include "qchartaxiscategories.h" |
|
28 | #include "qchartaxiscategories.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartanimator_p.h" |
|
30 | #include "chartanimator_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QDebug> |
|
32 | #include <QDebug> | |
33 | #include <QToolTip> |
|
33 | #include <QToolTip> | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
37 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
38 | ChartItem(presenter), |
|
38 | ChartItem(presenter), | |
39 | m_layoutSet(false), |
|
39 | m_layoutSet(false), | |
40 | m_series(series) |
|
40 | m_series(series) | |
41 | { |
|
41 | { | |
42 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); |
|
42 | connect(series, SIGNAL(showToolTip(QPoint,QString)), this, SLOT(showToolTip(QPoint,QString))); | |
43 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
43 | connect(series, SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
44 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); |
|
44 | connect(series, SIGNAL(restructuredBar(int)), this, SLOT(handleModelChanged(int))); | |
45 | setZValue(ChartPresenter::BarSeriesZValue); |
|
45 | setZValue(ChartPresenter::BarSeriesZValue); | |
46 | dataChanged(); |
|
46 | dataChanged(); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | BarChartItem::~BarChartItem() |
|
49 | BarChartItem::~BarChartItem() | |
50 | { |
|
50 | { | |
51 | disconnect(this,SLOT(showToolTip(QPoint,QString))); |
|
51 | disconnect(this,SLOT(showToolTip(QPoint,QString))); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
54 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
55 | { |
|
55 | { | |
56 | if (!m_layoutSet) { |
|
56 | if (!m_layoutSet) { | |
57 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; |
|
57 | qWarning() << "BarChartItem::paint called without layout set. Aborting."; | |
58 | return; |
|
58 | return; | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | foreach(QGraphicsItem* i, childItems()) |
|
61 | foreach(QGraphicsItem* i, childItems()) | |
62 | i->paint(painter,option,widget); |
|
62 | i->paint(painter,option,widget); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | QRectF BarChartItem::boundingRect() const |
|
65 | QRectF BarChartItem::boundingRect() const | |
66 | { |
|
66 | { | |
67 | return m_rect; |
|
67 | return m_rect; | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void BarChartItem::dataChanged() |
|
70 | void BarChartItem::dataChanged() | |
71 | { |
|
71 | { | |
72 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? |
|
72 | // TODO: performance optimizations. Do we really need to delete and create items every time data is changed or can we reuse them? | |
73 | // Delete old bars |
|
73 | // Delete old bars | |
74 | foreach (QGraphicsItem *item, childItems()) |
|
74 | foreach (QGraphicsItem *item, childItems()) | |
75 | delete item; |
|
75 | delete item; | |
76 |
|
76 | |||
77 | m_bars.clear(); |
|
77 | m_bars.clear(); | |
78 |
m_ |
|
78 | m_labels.clear(); | |
79 | m_layout.clear(); |
|
79 | m_layout.clear(); | |
80 |
|
80 | |||
81 | // Create new graphic items for bars |
|
81 | // Create new graphic items for bars | |
82 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
82 | for (int c = 0; c < m_series->categoryCount(); c++) { | |
83 | QString category = m_series->categoryName(c); |
|
83 | QString category = m_series->categoryName(c); | |
84 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
84 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
85 | QBarSet *set = m_series->barsetAt(s); |
|
85 | QBarSet *set = m_series->barsetAt(s); | |
86 | Bar *bar = new Bar(category,this); |
|
86 | Bar *bar = new Bar(category,this); | |
87 | childItems().append(bar); |
|
87 | childItems().append(bar); | |
88 | m_bars.append(bar); |
|
88 | m_bars.append(bar); | |
89 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); |
|
89 | connect(bar, SIGNAL(clicked(QString,Qt::MouseButtons)), set, SIGNAL(clicked(QString,Qt::MouseButtons))); | |
90 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); |
|
90 | connect(bar, SIGNAL(hoverEntered(QPoint)), set, SLOT(barHoverEnterEvent(QPoint))); | |
91 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); |
|
91 | connect(bar, SIGNAL(hoverLeaved()), set, SLOT(barHoverLeaveEvent())); | |
92 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
92 | m_layout.append(QRectF(0, 0, 0, 0)); | |
93 | } |
|
93 | } | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 |
// Create |
|
96 | // Create labels | |
97 | for (int category = 0; category < m_series->categoryCount(); category++) { |
|
97 | for (int category = 0; category < m_series->categoryCount(); category++) { | |
98 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
98 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
99 | QBarSet *set = m_series->barsetAt(s); |
|
99 | QBarSet *set = m_series->barsetAt(s); | |
100 |
Bar |
|
100 | BarLabel *value = new BarLabel(*set, this); | |
101 | childItems().append(value); |
|
101 | childItems().append(value); | |
102 |
m_ |
|
102 | m_labels.append(value); | |
103 |
connect(set,SIGNAL( |
|
103 | connect(set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
104 | } |
|
104 | } | |
105 | } |
|
105 | } | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | QVector<QRectF> BarChartItem::calculateLayout() |
|
108 | QVector<QRectF> BarChartItem::calculateLayout() | |
109 | { |
|
109 | { | |
110 | QVector<QRectF> layout; |
|
110 | QVector<QRectF> layout; | |
111 |
|
111 | |||
112 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
112 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
113 | qreal categoryCount = m_series->categoryCount(); |
|
113 | qreal categoryCount = m_series->categoryCount(); | |
114 | qreal setCount = m_series->barsetCount(); |
|
114 | qreal setCount = m_series->barsetCount(); | |
115 |
|
115 | |||
116 | qreal width = geometry().width(); |
|
116 | qreal width = geometry().width(); | |
117 | qreal height = geometry().height(); |
|
117 | qreal height = geometry().height(); | |
118 |
|
118 | |||
119 | qreal max = m_series->max(); |
|
119 | qreal max = m_series->max(); | |
120 |
|
120 | |||
121 | // Domain: |
|
121 | // Domain: | |
122 | if (m_domainMaxY > max) { |
|
122 | if (m_domainMaxY > max) { | |
123 | max = m_domainMaxY; |
|
123 | max = m_domainMaxY; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | qreal scale = (height / max); |
|
126 | qreal scale = (height / max); | |
127 | qreal categoryWidth = width / categoryCount; |
|
127 | qreal categoryWidth = width / categoryCount; | |
128 | qreal barWidth = categoryWidth / (setCount+1); |
|
128 | qreal barWidth = categoryWidth / (setCount+1); | |
129 |
|
129 | |||
130 | int itemIndex(0); |
|
130 | int itemIndex(0); | |
131 | for (int category = 0; category < categoryCount; category++) { |
|
131 | for (int category = 0; category < categoryCount; category++) { | |
132 | qreal xPos = categoryWidth * category + barWidth / 2; |
|
132 | qreal xPos = categoryWidth * category + barWidth / 2; | |
133 | qreal yPos = height; |
|
133 | qreal yPos = height; | |
134 | for (int set = 0; set < setCount; set++) { |
|
134 | for (int set = 0; set < setCount; set++) { | |
135 | QBarSet* barSet = m_series->barsetAt(set); |
|
135 | QBarSet* barSet = m_series->barsetAt(set); | |
136 |
|
136 | |||
137 | qreal barHeight = barSet->valueAt(category) * scale; |
|
137 | qreal barHeight = barSet->valueAt(category) * scale; | |
138 | Bar* bar = m_bars.at(itemIndex); |
|
138 | Bar* bar = m_bars.at(itemIndex); | |
139 |
|
139 | |||
140 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
140 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
141 | layout.append(rect); |
|
141 | layout.append(rect); | |
142 | bar->setPen(barSet->pen()); |
|
142 | bar->setPen(barSet->pen()); | |
143 | bar->setBrush(barSet->brush()); |
|
143 | bar->setBrush(barSet->brush()); | |
144 |
|
144 | |||
145 |
Bar |
|
145 | BarLabel* label = m_labels.at(itemIndex); | |
146 |
|
146 | |||
147 | if (!qFuzzyIsNull(barSet->valueAt(category))) { |
|
147 | if (!qFuzzyIsNull(barSet->valueAt(category))) { | |
148 |
|
|
148 | label->setText(QString::number(barSet->valueAt(category))); | |
149 | } else { |
|
149 | } else { | |
150 |
|
|
150 | label->setText(QString("")); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 |
|
|
153 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
154 |
,yPos - barHeight/2 - |
|
154 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
155 |
value->set |
|
155 | // value->setFont(barSet->valueFont()); | |
156 |
|
156 | |||
157 | itemIndex++; |
|
157 | itemIndex++; | |
158 | xPos += barWidth; |
|
158 | xPos += barWidth; | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 | return layout; |
|
161 | return layout; | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
164 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
165 | { |
|
165 | { | |
166 | if (animator()) |
|
166 | if (animator()) | |
167 | animator()->updateLayout(this, m_layout, layout); |
|
167 | animator()->updateLayout(this, m_layout, layout); | |
168 | else |
|
168 | else | |
169 | setLayout(layout); |
|
169 | setLayout(layout); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
172 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
173 | { |
|
173 | { | |
174 | m_layout = layout; |
|
174 | m_layout = layout; | |
175 |
|
175 | |||
176 | for (int i=0; i < m_bars.count(); i++) |
|
176 | for (int i=0; i < m_bars.count(); i++) | |
177 | m_bars.at(i)->setRect(layout.at(i)); |
|
177 | m_bars.at(i)->setRect(layout.at(i)); | |
178 |
|
178 | |||
179 | update(); |
|
179 | update(); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | //handlers |
|
182 | //handlers | |
183 |
|
183 | |||
184 | void BarChartItem::handleModelChanged(int index) |
|
184 | void BarChartItem::handleModelChanged(int index) | |
185 | { |
|
185 | { | |
186 | Q_UNUSED(index) |
|
186 | Q_UNUSED(index) | |
187 | dataChanged(); |
|
187 | dataChanged(); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
190 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
191 | { |
|
191 | { | |
192 | m_domainMinX = minX; |
|
192 | m_domainMinX = minX; | |
193 | m_domainMaxX = maxX; |
|
193 | m_domainMaxX = maxX; | |
194 | m_domainMinY = minY; |
|
194 | m_domainMinY = minY; | |
195 | m_domainMaxY = maxY; |
|
195 | m_domainMaxY = maxY; | |
196 | handleLayoutChanged(); |
|
196 | handleLayoutChanged(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
199 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
200 | { |
|
200 | { | |
201 | m_rect = rect; |
|
201 | m_rect = rect; | |
202 | handleLayoutChanged(); |
|
202 | handleLayoutChanged(); | |
203 | m_layoutSet = true; |
|
203 | m_layoutSet = true; | |
204 | setPos(rect.topLeft()); |
|
204 | setPos(rect.topLeft()); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void BarChartItem::handleLayoutChanged() |
|
207 | void BarChartItem::handleLayoutChanged() | |
208 | { |
|
208 | { | |
209 | QVector<QRectF> layout = calculateLayout(); |
|
209 | QVector<QRectF> layout = calculateLayout(); | |
210 | applyLayout(layout); |
|
210 | applyLayout(layout); | |
211 | update(); |
|
211 | update(); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void BarChartItem::showToolTip(QPoint pos, QString tip) |
|
214 | void BarChartItem::showToolTip(QPoint pos, QString tip) | |
215 | { |
|
215 | { | |
216 | // TODO: cool tooltip instead of default |
|
216 | // TODO: cool tooltip instead of default | |
217 | QToolTip::showText(pos, tip); |
|
217 | QToolTip::showText(pos, tip); | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | #include "moc_barchartitem_p.cpp" |
|
220 | #include "moc_barchartitem_p.cpp" | |
221 |
|
221 | |||
222 | QTCOMMERCIALCHART_END_NAMESPACE |
|
222 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,89 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARCHARTITEM_H |
|
21 | #ifndef BARCHARTITEM_H | |
22 | #define BARCHARTITEM_H |
|
22 | #define BARCHARTITEM_H | |
23 |
|
23 | |||
24 | #include "chartitem_p.h" |
|
24 | #include "chartitem_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Bar; |
|
31 | class Bar; | |
32 |
class Bar |
|
32 | class BarLabel; | |
33 | class QChartAxisCategories; |
|
33 | class QChartAxisCategories; | |
34 | class QChart; |
|
34 | class QChart; | |
35 |
|
35 | |||
36 | //typedef QVector<QRectF> BarLayout; |
|
36 | //typedef QVector<QRectF> BarLayout; | |
37 |
|
37 | |||
38 | class BarChartItem : public ChartItem |
|
38 | class BarChartItem : public ChartItem | |
39 | { |
|
39 | { | |
40 | Q_OBJECT |
|
40 | Q_OBJECT | |
41 | public: |
|
41 | public: | |
42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); |
|
42 | BarChartItem(QBarSeries *series, ChartPresenter *presenter); | |
43 | virtual ~BarChartItem(); |
|
43 | virtual ~BarChartItem(); | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | // From QGraphicsItem |
|
46 | // From QGraphicsItem | |
47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
47 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
48 | QRectF boundingRect() const; |
|
48 | QRectF boundingRect() const; | |
49 |
|
49 | |||
50 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it |
|
50 | // TODO: Consider the domain for layoutChanged. May be use case, may not be. If it is, then the derived classes need to implement it | |
51 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes |
|
51 | virtual void dataChanged(); // data of series has changed -> need to recalculate bar sizes | |
52 |
|
52 | |||
53 | virtual QVector<QRectF> calculateLayout(); |
|
53 | virtual QVector<QRectF> calculateLayout(); | |
54 | void applyLayout(const QVector<QRectF> &layout); |
|
54 | void applyLayout(const QVector<QRectF> &layout); | |
55 | void setLayout(const QVector<QRectF> &layout); |
|
55 | void setLayout(const QVector<QRectF> &layout); | |
56 | void updateLayout(const QVector<QRectF> &layout); |
|
56 | void updateLayout(const QVector<QRectF> &layout); | |
57 |
|
57 | |||
58 | QRectF geometry() const { return m_rect;} |
|
58 | QRectF geometry() const { return m_rect;} | |
59 |
|
59 | |||
60 | public Q_SLOTS: |
|
60 | public Q_SLOTS: | |
61 | void handleModelChanged(int index); |
|
61 | void handleModelChanged(int index); | |
62 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
62 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
63 | void handleGeometryChanged(const QRectF &size); |
|
63 | void handleGeometryChanged(const QRectF &size); | |
64 | void handleLayoutChanged(); |
|
64 | void handleLayoutChanged(); | |
65 |
|
65 | |||
66 | // Internal slots |
|
66 | // Internal slots | |
67 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) |
|
67 | void showToolTip(QPoint pos, QString tip); // shows tooltip (if enabled) | |
68 |
|
68 | |||
69 | protected: |
|
69 | protected: | |
70 |
|
70 | |||
71 | // TODO: consider these. |
|
71 | // TODO: consider these. | |
72 | qreal m_domainMinX; |
|
72 | qreal m_domainMinX; | |
73 | qreal m_domainMaxX; |
|
73 | qreal m_domainMaxX; | |
74 | qreal m_domainMinY; |
|
74 | qreal m_domainMinY; | |
75 | qreal m_domainMaxY; |
|
75 | qreal m_domainMaxY; | |
76 |
|
76 | |||
77 | QRectF m_rect; |
|
77 | QRectF m_rect; | |
78 | bool m_layoutSet; // True, if component has been laid out. |
|
78 | bool m_layoutSet; // True, if component has been laid out. | |
79 | QVector<QRectF> m_layout; |
|
79 | QVector<QRectF> m_layout; | |
80 |
|
80 | |||
81 | // Not owned. |
|
81 | // Not owned. | |
82 | QBarSeries *m_series; |
|
82 | QBarSeries *m_series; | |
83 | QList<Bar *> m_bars; |
|
83 | QList<Bar *> m_bars; | |
84 |
QList<Bar |
|
84 | QList<BarLabel *> m_labels; | |
85 | }; |
|
85 | }; | |
86 |
|
86 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
88 |
|
88 | |||
89 | #endif // BARCHARTITEM_H |
|
89 | #endif // BARCHARTITEM_H |
@@ -1,90 +1,104 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "bar |
|
21 | #include "barlabel_p.h" | |
|
22 | #include "chartpresenter_p.h" | |||
|
23 | #include <QBarSet> | |||
22 | #include <QPainter> |
|
24 | #include <QPainter> | |
23 | #include <QPen> |
|
25 | #include <QPen> | |
24 | #include <QGraphicsSimpleTextItem> |
|
26 | #include <QGraphicsSimpleTextItem> | |
25 |
|
27 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
29 | |||
28 |
Bar |
|
30 | BarLabel::BarLabel(QBarSet &barSet, QGraphicsItem *parent) : QGraphicsObject(parent), | |
29 |
m_barSet( |
|
31 | m_barSet(barSet), | |
30 | m_textItem(new QGraphicsSimpleTextItem(this)) |
|
32 | m_textItem(new QGraphicsSimpleTextItem(this)) | |
31 | { |
|
33 | { | |
32 |
// connect(&set,SIGNAL( |
|
34 | // connect(&set,SIGNAL(labelsVisibleChanged(bool)),value,SLOT(labelsVisibleChanged(bool))); | |
33 | setVisible(false); |
|
35 | setZValue(ChartPresenter::BarSeriesZValue + 1); | |
|
36 | setVisible(barSet.labelsVisible()); | |||
|
37 | setPen(Qt::NoPen); | |||
|
38 | setBrush(Qt::SolidPattern); | |||
34 | } |
|
39 | } | |
35 |
|
40 | |||
36 |
void Bar |
|
41 | void BarLabel::setText(QString str) | |
37 | { |
|
42 | { | |
38 | m_textItem->setText(str); |
|
43 | m_textItem->setText(str); | |
39 | } |
|
44 | } | |
40 |
|
45 | |||
41 |
QString Bar |
|
46 | QString BarLabel::text() const | |
42 | { |
|
47 | { | |
43 | return m_textItem->text(); |
|
48 | return m_textItem->text(); | |
44 | } |
|
49 | } | |
45 |
|
50 | |||
46 |
void Bar |
|
51 | void BarLabel::setPen(const QPen &pen) | |
47 | { |
|
52 | { | |
48 | m_textItem->setPen(pen); |
|
53 | m_textItem->setPen(pen); | |
49 | } |
|
54 | } | |
50 |
|
55 | |||
51 |
QPen Bar |
|
56 | QPen BarLabel::pen() const | |
52 | { |
|
57 | { | |
53 | return m_textItem->pen(); |
|
58 | return m_textItem->pen(); | |
54 | } |
|
59 | } | |
55 |
|
60 | |||
56 |
void Bar |
|
61 | void BarLabel::setBrush(const QBrush &brush) | |
|
62 | { | |||
|
63 | m_textItem->setBrush(brush); | |||
|
64 | } | |||
|
65 | ||||
|
66 | QBrush BarLabel::brush() const | |||
|
67 | { | |||
|
68 | return m_textItem->brush(); | |||
|
69 | } | |||
|
70 | ||||
|
71 | void BarLabel::setFont(const QFont &font) | |||
57 | { |
|
72 | { | |
58 | m_textItem->setFont(font); |
|
73 | m_textItem->setFont(font); | |
59 | } |
|
74 | } | |
60 |
|
75 | |||
61 |
QFont Bar |
|
76 | QFont BarLabel::font() const | |
62 | { |
|
77 | { | |
63 | return m_textItem->font(); |
|
78 | return m_textItem->font(); | |
64 | } |
|
79 | } | |
65 |
|
80 | |||
66 |
void Bar |
|
81 | void BarLabel::setPos(qreal x, qreal y) | |
67 | { |
|
82 | { | |
68 | m_textItem->setPos(x,y); |
|
83 | m_textItem->setPos(x,y); | |
69 | } |
|
84 | } | |
70 |
|
85 | |||
71 |
void Bar |
|
86 | void BarLabel::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
72 | { |
|
87 | { | |
73 | Q_UNUSED(painter) |
|
88 | Q_UNUSED(painter) | |
74 | Q_UNUSED(option) |
|
89 | Q_UNUSED(option) | |
75 | Q_UNUSED(widget) |
|
90 | Q_UNUSED(widget) | |
76 | } |
|
91 | } | |
77 |
|
92 | |||
78 |
QRectF Bar |
|
93 | QRectF BarLabel::boundingRect() const | |
79 | { |
|
94 | { | |
80 | return m_textItem->boundingRect(); |
|
95 | return m_textItem->boundingRect(); | |
81 | } |
|
96 | } | |
82 |
|
97 | |||
83 |
void Bar |
|
98 | void BarLabel::labelsVisibleChanged(bool visible) | |
84 | { |
|
99 | { | |
85 | qDebug() << "BarValue visiblle changed:" <<visible; |
|
|||
86 | setVisible(visible); |
|
100 | setVisible(visible); | |
87 | } |
|
101 | } | |
88 |
|
102 | |||
89 |
#include "moc_bar |
|
103 | #include "moc_barlabel_p.cpp" | |
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
104 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,70 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#ifndef BAR |
|
21 | #ifndef BARLABEL_P_H | |
22 |
#define BAR |
|
22 | #define BARLABEL_P_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include <QGraphicsObject> |
|
25 | #include <QGraphicsObject> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | class QGraphicsSimpleTextItem; |
|
27 | class QGraphicsSimpleTextItem; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QBarSet; |
|
31 | class QBarSet; | |
32 |
|
32 | |||
33 | // Visual class for bar values |
|
33 | // Visual class for bar values | |
34 | // By default these are not visible. |
|
34 | // By default these are not visible. | |
35 |
class Bar |
|
35 | class BarLabel : public QGraphicsObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 | public: |
|
38 | public: | |
39 |
Bar |
|
39 | BarLabel(QBarSet &barSet, QGraphicsItem *parent = 0); | |
40 |
|
40 | |||
41 | void setText(QString str); |
|
41 | void setText(QString str); | |
42 | QString text() const; |
|
42 | QString text() const; | |
43 |
|
43 | |||
44 | void setPen(const QPen &pen); |
|
44 | void setPen(const QPen &pen); | |
45 | QPen pen() const; |
|
45 | QPen pen() const; | |
46 |
|
46 | |||
|
47 | void setBrush(const QBrush &brush); | |||
|
48 | QBrush brush() const; | |||
|
49 | ||||
47 | void setFont(const QFont &font); |
|
50 | void setFont(const QFont &font); | |
48 | QFont font() const; |
|
51 | QFont font() const; | |
49 |
|
52 | |||
50 | void setPos(qreal x, qreal y); |
|
53 | void setPos(qreal x, qreal y); | |
51 |
|
54 | |||
52 | // From QGraphicsItem |
|
55 | // From QGraphicsItem | |
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
56 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
54 | QRectF boundingRect() const; |
|
57 | QRectF boundingRect() const; | |
55 |
|
58 | |||
56 | public Q_SLOTS: |
|
59 | public Q_SLOTS: | |
57 |
void |
|
60 | void labelsVisibleChanged(bool visible); | |
58 |
|
61 | |||
59 | private: |
|
62 | private: | |
60 |
|
63 | |||
61 | QBarSet &m_barSet; |
|
64 | QBarSet &m_barSet; | |
62 | QGraphicsSimpleTextItem *m_textItem; |
|
65 | QGraphicsSimpleTextItem *m_textItem; | |
63 | }; |
|
66 | }; | |
64 |
|
67 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
68 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
69 | |||
67 |
#endif // BAR |
|
70 | #endif // BARLABEL_P_H |
@@ -1,86 +1,86 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "percentbarchartitem_p.h" |
|
21 | #include "percentbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 |
#include "bar |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
35 | { |
|
35 | { | |
36 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
37 |
|
37 | |||
38 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
38 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
39 | qreal width = geometry().width(); |
|
39 | qreal width = geometry().width(); | |
40 | qreal height = geometry().height(); |
|
40 | qreal height = geometry().height(); | |
41 |
|
41 | |||
42 | qreal categoryCount = m_series->categoryCount(); |
|
42 | qreal categoryCount = m_series->categoryCount(); | |
43 | qreal barWidth = width / (m_series->categoryCount() * 2); |
|
43 | qreal barWidth = width / (m_series->categoryCount() * 2); | |
44 | qreal xStep = width / categoryCount; |
|
44 | qreal xStep = width / categoryCount; | |
45 | qreal xPos = xStep / 2 - barWidth / 2; |
|
45 | qreal xPos = xStep / 2 - barWidth / 2; | |
46 |
|
46 | |||
47 | int itemIndex(0); |
|
47 | int itemIndex(0); | |
48 | for (int category = 0; category < categoryCount; category++) { |
|
48 | for (int category = 0; category < categoryCount; category++) { | |
49 | qreal colSum = m_series->categorySum(category); |
|
49 | qreal colSum = m_series->categorySum(category); | |
50 | qreal scale = (height / colSum); |
|
50 | qreal scale = (height / colSum); | |
51 | qreal yPos = height; |
|
51 | qreal yPos = height; | |
52 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
52 | for (int set=0; set < m_series->barsetCount(); set++) { | |
53 | QBarSet* barSet = m_series->barsetAt(set); |
|
53 | QBarSet* barSet = m_series->barsetAt(set); | |
54 | qreal barHeight = barSet->valueAt(category) * scale; |
|
54 | qreal barHeight = barSet->valueAt(category) * scale; | |
55 | Bar* bar = m_bars.at(itemIndex); |
|
55 | Bar* bar = m_bars.at(itemIndex); | |
56 | bar->setPen(barSet->pen()); |
|
56 | bar->setPen(barSet->pen()); | |
57 | bar->setBrush(barSet->brush()); |
|
57 | bar->setBrush(barSet->brush()); | |
58 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
58 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
59 | layout.append(rect); |
|
59 | layout.append(rect); | |
60 |
|
60 | |||
61 |
Bar |
|
61 | BarLabel* label = m_labels.at(itemIndex); | |
62 |
|
62 | |||
63 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { |
|
63 | if (!qFuzzyIsNull(m_series->valueAt(set,category))) { | |
64 | int p = m_series->percentageAt(set,category) * 100; |
|
64 | int p = m_series->percentageAt(set,category) * 100; | |
65 | QString vString(QString::number(p)); |
|
65 | QString vString(QString::number(p)); | |
66 | vString.truncate(3); |
|
66 | vString.truncate(3); | |
67 | vString.append("%"); |
|
67 | vString.append("%"); | |
68 |
|
|
68 | label->setText(vString); | |
69 | } else { |
|
69 | } else { | |
70 |
|
|
70 | label->setText(QString("")); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 |
|
|
73 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
74 |
,yPos - barHeight/2 - |
|
74 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
75 |
value->set |
|
75 | // value->setFont(barSet->valueFont()); | |
76 | itemIndex++; |
|
76 | itemIndex++; | |
77 | yPos -= barHeight; |
|
77 | yPos -= barHeight; | |
78 | } |
|
78 | } | |
79 | xPos += xStep; |
|
79 | xPos += xStep; | |
80 | } |
|
80 | } | |
81 | return layout; |
|
81 | return layout; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | #include "moc_percentbarchartitem_p.cpp" |
|
84 | #include "moc_percentbarchartitem_p.cpp" | |
85 |
|
85 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,404 +1,404 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QDebug> |
|
21 | #include <QDebug> | |
22 | #include "qbarseries.h" |
|
22 | #include "qbarseries.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "barchartmodel_p.h" |
|
24 | #include "barchartmodel_p.h" | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QBarSeries |
|
29 | \class QBarSeries | |
30 | \brief part of QtCommercial chart API. |
|
30 | \brief part of QtCommercial chart API. | |
31 |
|
31 | |||
32 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible |
|
32 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multible | |
33 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
33 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined | |
34 | by QStringList. |
|
34 | by QStringList. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \fn virtual QSeriesType QBarSeries::type() const |
|
42 | \fn virtual QSeriesType QBarSeries::type() const | |
43 | \brief Returns type of series. |
|
43 | \brief Returns type of series. | |
44 | \sa QSeries, QSeriesType |
|
44 | \sa QSeries, QSeriesType | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) |
|
48 | \fn void QBarSeries::showToolTip(QPoint pos, QString tip) | |
49 | \brief \internal \a pos \a tip |
|
49 | \brief \internal \a pos \a tip | |
50 | */ |
|
50 | */ | |
51 |
|
51 | |||
52 | /*! |
|
52 | /*! | |
53 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
53 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. | |
54 | QBarSeries is QObject which is a child of a \a parent. |
|
54 | QBarSeries is QObject which is a child of a \a parent. | |
55 | */ |
|
55 | */ | |
56 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), |
|
56 | QBarSeries::QBarSeries(QBarCategories categories, QObject *parent) : QSeries(parent), | |
57 | m_internalModel(new BarChartModel(categories, this)) |
|
57 | m_internalModel(new BarChartModel(categories, this)) | |
58 | { |
|
58 | { | |
59 | m_model = 0; |
|
59 | m_model = 0; | |
60 | m_mapCategories = -1; |
|
60 | m_mapCategories = -1; | |
61 | m_mapBarBottom = -1; |
|
61 | m_mapBarBottom = -1; | |
62 | m_mapBarTop = -1; |
|
62 | m_mapBarTop = -1; | |
63 | m_mapFirst = 0; |
|
63 | m_mapFirst = 0; | |
64 | m_mapCount = 0; |
|
64 | m_mapCount = 0; | |
65 | m_mapOrientation = Qt::Vertical; |
|
65 | m_mapOrientation = Qt::Vertical; | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Adds a set of bars to series. Takes ownership of \a set. |
|
69 | Adds a set of bars to series. Takes ownership of \a set. | |
70 | Connects the clicked(QString, Qt::MouseButtons) signal |
|
70 | Connects the clicked(QString, Qt::MouseButtons) signal | |
71 | of \a set to this series |
|
71 | of \a set to this series | |
72 | */ |
|
72 | */ | |
73 | void QBarSeries::appendBarSet(QBarSet *set) |
|
73 | void QBarSeries::appendBarSet(QBarSet *set) | |
74 | { |
|
74 | { | |
75 | m_internalModel->appendBarSet(set); |
|
75 | m_internalModel->appendBarSet(set); | |
76 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
76 | connect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
77 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); |
|
77 | connect(set, SIGNAL(valueChanged()), this, SLOT(barsetChanged())); | |
78 | emit updatedBars(); |
|
78 | emit updatedBars(); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | /*! |
|
81 | /*! | |
82 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. |
|
82 | Removes a set of bars from series. Releases ownership of \a set. Doesnt delete \a set. | |
83 | Disconnects the clicked(QString, Qt::MouseButtons) signal |
|
83 | Disconnects the clicked(QString, Qt::MouseButtons) signal | |
84 | of \a set from this series |
|
84 | of \a set from this series | |
85 | */ |
|
85 | */ | |
86 | void QBarSeries::removeBarSet(QBarSet *set) |
|
86 | void QBarSeries::removeBarSet(QBarSet *set) | |
87 | { |
|
87 | { | |
88 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); |
|
88 | disconnect(set, SIGNAL(clicked(QString,Qt::MouseButtons)), this, SLOT(barsetClicked(QString,Qt::MouseButtons))); | |
89 | m_internalModel->removeBarSet(set); |
|
89 | m_internalModel->removeBarSet(set); | |
90 | emit updatedBars(); |
|
90 | emit updatedBars(); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void QBarSeries::insertBarSet(int i, QBarSet *set) |
|
93 | void QBarSeries::insertBarSet(int i, QBarSet *set) | |
94 | { |
|
94 | { | |
95 | m_internalModel->insertBarSet(i, set); |
|
95 | m_internalModel->insertBarSet(i, set); | |
96 | // emit barsetChanged(); |
|
96 | // emit barsetChanged(); | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | void QBarSeries::insertCategory(int i, QString category) |
|
99 | void QBarSeries::insertCategory(int i, QString category) | |
100 | { |
|
100 | { | |
101 | m_internalModel->insertCategory(i, category); |
|
101 | m_internalModel->insertCategory(i, category); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void QBarSeries::removeCategory(int i) |
|
104 | void QBarSeries::removeCategory(int i) | |
105 | { |
|
105 | { | |
106 | m_internalModel->removeCategory(i); |
|
106 | m_internalModel->removeCategory(i); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | Returns number of sets in series. |
|
110 | Returns number of sets in series. | |
111 | */ |
|
111 | */ | |
112 | int QBarSeries::barsetCount() const |
|
112 | int QBarSeries::barsetCount() const | |
113 | { |
|
113 | { | |
114 | // if(m_model) |
|
114 | // if(m_model) | |
115 | // return m_mapBarTop - m_mapBarBottom; |
|
115 | // return m_mapBarTop - m_mapBarBottom; | |
116 | // else |
|
116 | // else | |
117 | return m_internalModel->barsetCount(); |
|
117 | return m_internalModel->barsetCount(); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | Returns number of categories in series |
|
121 | Returns number of categories in series | |
122 | */ |
|
122 | */ | |
123 | int QBarSeries::categoryCount() const |
|
123 | int QBarSeries::categoryCount() const | |
124 | { |
|
124 | { | |
125 | return m_internalModel->categoryCount(); |
|
125 | return m_internalModel->categoryCount(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Returns a list of sets in series. Keeps ownership of sets. |
|
129 | Returns a list of sets in series. Keeps ownership of sets. | |
130 | */ |
|
130 | */ | |
131 | QList<QBarSet*> QBarSeries::barSets() const |
|
131 | QList<QBarSet*> QBarSeries::barSets() const | |
132 | { |
|
132 | { | |
133 | return m_internalModel->barSets(); |
|
133 | return m_internalModel->barSets(); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | \internal \a index |
|
137 | \internal \a index | |
138 | */ |
|
138 | */ | |
139 | QBarSet* QBarSeries::barsetAt(int index) |
|
139 | QBarSet* QBarSeries::barsetAt(int index) | |
140 | { |
|
140 | { | |
141 | return m_internalModel->barsetAt(index); |
|
141 | return m_internalModel->barsetAt(index); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \internal \a category |
|
145 | \internal \a category | |
146 | */ |
|
146 | */ | |
147 | QString QBarSeries::categoryName(int category) |
|
147 | QString QBarSeries::categoryName(int category) | |
148 | { |
|
148 | { | |
149 | return m_internalModel->categoryName(category); |
|
149 | return m_internalModel->categoryName(category); | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | Enables or disables tooltip depending on parameter \a enabled. |
|
153 | Enables or disables tooltip depending on parameter \a enabled. | |
154 | Tooltip shows the name of set, when mouse is hovering on top of bar. |
|
154 | Tooltip shows the name of set, when mouse is hovering on top of bar. | |
155 | Calling without parameter \a enabled, enables the tooltip |
|
155 | Calling without parameter \a enabled, enables the tooltip | |
156 | */ |
|
156 | */ | |
157 | void QBarSeries::setToolTipEnabled(bool enabled) |
|
157 | void QBarSeries::setToolTipEnabled(bool enabled) | |
158 | { |
|
158 | { | |
159 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. |
|
159 | // TODO: what if we add sets after call to this function? Those sets won't have tooltip enabled. | |
160 | if (enabled) { |
|
160 | if (enabled) { | |
161 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
161 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
162 | QBarSet *set = m_internalModel->barsetAt(i); |
|
162 | QBarSet *set = m_internalModel->barsetAt(i); | |
163 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
163 | connect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
164 | } |
|
164 | } | |
165 | } else { |
|
165 | } else { | |
166 | for (int i=0; i<m_internalModel->barsetCount(); i++) { |
|
166 | for (int i=0; i<m_internalModel->barsetCount(); i++) { | |
167 | QBarSet *set = m_internalModel->barsetAt(i); |
|
167 | QBarSet *set = m_internalModel->barsetAt(i); | |
168 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); |
|
168 | disconnect(set, SIGNAL(showToolTip(QPoint,QString)), this, SIGNAL(showToolTip(QPoint,QString))); | |
169 | } |
|
169 | } | |
170 | } |
|
170 | } | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | \internal \a category |
|
175 | \internal \a category | |
176 | */ |
|
176 | */ | |
177 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) |
|
177 | void QBarSeries::barsetClicked(QString category, Qt::MouseButtons button) | |
178 | { |
|
178 | { | |
179 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); |
|
179 | emit clicked(qobject_cast<QBarSet*>(sender()), category, button); | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | /*! |
|
182 | /*! | |
183 | \internal |
|
183 | \internal | |
184 | */ |
|
184 | */ | |
185 | qreal QBarSeries::min() |
|
185 | qreal QBarSeries::min() | |
186 | { |
|
186 | { | |
187 | return m_internalModel->min(); |
|
187 | return m_internalModel->min(); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | \internal |
|
191 | \internal | |
192 | */ |
|
192 | */ | |
193 | qreal QBarSeries::max() |
|
193 | qreal QBarSeries::max() | |
194 | { |
|
194 | { | |
195 | return m_internalModel->max(); |
|
195 | return m_internalModel->max(); | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \internal \a set \a category |
|
199 | \internal \a set \a category | |
200 | */ |
|
200 | */ | |
201 | qreal QBarSeries::valueAt(int set, int category) |
|
201 | qreal QBarSeries::valueAt(int set, int category) | |
202 | { |
|
202 | { | |
203 | return m_internalModel->valueAt(set, category); |
|
203 | return m_internalModel->valueAt(set, category); | |
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | \internal \a set \a category |
|
207 | \internal \a set \a category | |
208 | */ |
|
208 | */ | |
209 | qreal QBarSeries::percentageAt(int set, int category) |
|
209 | qreal QBarSeries::percentageAt(int set, int category) | |
210 | { |
|
210 | { | |
211 | return m_internalModel->percentageAt(set, category); |
|
211 | return m_internalModel->percentageAt(set, category); | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | \internal \a category |
|
215 | \internal \a category | |
216 | */ |
|
216 | */ | |
217 | qreal QBarSeries::categorySum(int category) |
|
217 | qreal QBarSeries::categorySum(int category) | |
218 | { |
|
218 | { | |
219 | return m_internalModel->categorySum(category); |
|
219 | return m_internalModel->categorySum(category); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | \internal |
|
223 | \internal | |
224 | */ |
|
224 | */ | |
225 | qreal QBarSeries::maxCategorySum() |
|
225 | qreal QBarSeries::maxCategorySum() | |
226 | { |
|
226 | { | |
227 | return m_internalModel->maxCategorySum(); |
|
227 | return m_internalModel->maxCategorySum(); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | \internal |
|
231 | \internal | |
232 | */ |
|
232 | */ | |
233 | BarChartModel& QBarSeries::model() |
|
233 | BarChartModel& QBarSeries::model() | |
234 | { |
|
234 | { | |
235 | return *m_internalModel; |
|
235 | return *m_internalModel; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | bool QBarSeries::setModel(QAbstractItemModel *model) |
|
238 | bool QBarSeries::setModel(QAbstractItemModel *model) | |
239 | { |
|
239 | { | |
240 | // disconnect signals from old model |
|
240 | // disconnect signals from old model | |
241 | if(m_model) |
|
241 | if(m_model) | |
242 | { |
|
242 | { | |
243 | disconnect(m_model, 0, this, 0); |
|
243 | disconnect(m_model, 0, this, 0); | |
244 | m_mapCategories = -1; |
|
244 | m_mapCategories = -1; | |
245 | m_mapBarBottom = -1; |
|
245 | m_mapBarBottom = -1; | |
246 | m_mapBarTop = -1; |
|
246 | m_mapBarTop = -1; | |
247 | m_mapFirst = 0; |
|
247 | m_mapFirst = 0; | |
248 | m_mapCount = 0; |
|
248 | m_mapCount = 0; | |
249 | m_mapOrientation = Qt::Vertical; |
|
249 | m_mapOrientation = Qt::Vertical; | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | // set new model |
|
252 | // set new model | |
253 | if(model) |
|
253 | if(model) | |
254 | { |
|
254 | { | |
255 | m_model = model; |
|
255 | m_model = model; | |
256 | return true; |
|
256 | return true; | |
257 | } |
|
257 | } | |
258 | else |
|
258 | else | |
259 | { |
|
259 | { | |
260 | m_model = 0; |
|
260 | m_model = 0; | |
261 | return false; |
|
261 | return false; | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | // TODO |
|
265 | // TODO | |
266 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
266 | void QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) | |
267 | { |
|
267 | { | |
268 | if (!m_model) |
|
268 | if (!m_model) | |
269 | return; |
|
269 | return; | |
270 |
|
270 | |||
271 | m_mapCategories = categories; |
|
271 | m_mapCategories = categories; | |
272 | m_mapBarBottom = bottomBoundry; |
|
272 | m_mapBarBottom = bottomBoundry; | |
273 | m_mapBarTop = topBoundry; |
|
273 | m_mapBarTop = topBoundry; | |
274 | // m_mapFirst = 1; |
|
274 | // m_mapFirst = 1; | |
275 | m_mapOrientation = orientation; |
|
275 | m_mapOrientation = orientation; | |
276 |
|
276 | |||
277 | // connect the signals |
|
277 | // connect the signals | |
278 | if (m_mapOrientation == Qt::Vertical) { |
|
278 | if (m_mapOrientation == Qt::Vertical) { | |
279 | m_mapCount = m_model->rowCount() - m_mapFirst; |
|
279 | m_mapCount = m_model->rowCount() - m_mapFirst; | |
280 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
280 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
281 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
281 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
282 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), |
|
282 | connect(m_model,SIGNAL(rowsInserted(QModelIndex, int, int)), | |
283 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
283 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
284 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), |
|
284 | connect(m_model, SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
285 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
285 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
286 | } else { |
|
286 | } else { | |
287 | m_mapCount = m_model->columnCount() - m_mapFirst; |
|
287 | m_mapCount = m_model->columnCount() - m_mapFirst; | |
288 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), |
|
288 | connect(m_model,SIGNAL(dataChanged(QModelIndex,QModelIndex)), | |
289 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); |
|
289 | this, SLOT(modelUpdated(QModelIndex, QModelIndex))); | |
290 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), |
|
290 | connect(m_model,SIGNAL(columnsInserted(QModelIndex, int, int)), | |
291 | this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
291 | this, SLOT(modelDataAdded(QModelIndex,int,int))); | |
292 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), |
|
292 | connect(m_model, SIGNAL(columnsRemoved(QModelIndex, int, int)), | |
293 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
293 | this, SLOT(modelDataRemoved(QModelIndex,int,int))); | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 |
|
296 | |||
297 | // create the initial bars |
|
297 | // create the initial bars | |
298 | delete m_internalModel; |
|
298 | delete m_internalModel; | |
299 | if (m_mapOrientation == Qt::Vertical) { |
|
299 | if (m_mapOrientation == Qt::Vertical) { | |
300 | QStringList categories; |
|
300 | QStringList categories; | |
301 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
301 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
302 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
302 | categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); | |
303 | m_internalModel = new BarChartModel(categories, this); |
|
303 | m_internalModel = new BarChartModel(categories, this); | |
304 |
|
304 | |||
305 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
305 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
306 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); |
|
306 | QBarSet* barSet = new QBarSet(QString("Column: %1").arg(i + 1)); | |
307 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
307 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
308 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
308 | *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); | |
309 | appendBarSet(barSet); |
|
309 | appendBarSet(barSet); | |
310 | } |
|
310 | } | |
311 | } else { |
|
311 | } else { | |
312 | QStringList categories; |
|
312 | QStringList categories; | |
313 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) |
|
313 | for (int k = m_mapFirst; k < m_mapFirst + m_mapCount; k++) | |
314 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
314 | categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); | |
315 | m_internalModel = new BarChartModel(categories, this); |
|
315 | m_internalModel = new BarChartModel(categories, this); | |
316 |
|
316 | |||
317 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
317 | for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { | |
318 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); |
|
318 | QBarSet* barSet = new QBarSet(QString("Row: %1").arg(i + 1)); | |
319 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) |
|
319 | for(int m = m_mapFirst; m < m_mapFirst + m_mapCount; m++) | |
320 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
320 | *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); | |
321 | appendBarSet(barSet); |
|
321 | appendBarSet(barSet); | |
322 | } |
|
322 | } | |
323 | } |
|
323 | } | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | void QBarSeries::setModelMappingShift(int first, int count) |
|
326 | void QBarSeries::setModelMappingShift(int first, int count) | |
327 | { |
|
327 | { | |
328 | m_mapFirst = first; |
|
328 | m_mapFirst = first; | |
329 | m_mapCount = count; |
|
329 | m_mapCount = count; | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
332 | void QBarSeries::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
333 | { |
|
333 | { | |
334 | Q_UNUSED(bottomRight) |
|
334 | Q_UNUSED(bottomRight) | |
335 |
|
335 | |||
336 | if (m_mapOrientation == Qt::Vertical) |
|
336 | if (m_mapOrientation == Qt::Vertical) | |
337 | { |
|
337 | { | |
338 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
338 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
339 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) |
|
339 | if (topLeft.column() >= m_mapBarBottom && topLeft.column() <= m_mapBarTop && topLeft.row() >= m_mapFirst && topLeft.row() < m_mapFirst + m_mapCount) | |
340 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
340 | barsetAt(topLeft.column() - m_mapBarBottom)->setValue(topLeft.row() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
341 | } |
|
341 | } | |
342 | else |
|
342 | else | |
343 | { |
|
343 | { | |
344 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
344 | // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries | |
345 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) |
|
345 | if (topLeft.row() >= m_mapBarBottom && topLeft.row() <= m_mapBarTop && topLeft.column() >= m_mapFirst && topLeft.column() < m_mapFirst + m_mapCount) | |
346 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
346 | barsetAt(topLeft.row() - m_mapBarBottom)->setValue(topLeft.column() - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); | |
347 | } |
|
347 | } | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) |
|
350 | void QBarSeries::modelDataAdded(QModelIndex /*parent*/, int start, int /*end*/) | |
351 | { |
|
351 | { | |
352 | if (m_mapOrientation == Qt::Vertical) { |
|
352 | if (m_mapOrientation == Qt::Vertical) { | |
353 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); |
|
353 | insertCategory(start - m_mapFirst, QString("Row: %1").arg(start + 1)); | |
354 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
354 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
355 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); |
|
355 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(start, i), Qt::DisplayRole).toDouble()); | |
356 | } |
|
356 | } | |
357 | } else { |
|
357 | } else { | |
358 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); |
|
358 | insertCategory(start - m_mapFirst, QString("Column: %1").arg(start + 1)); | |
359 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { |
|
359 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) { | |
360 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); |
|
360 | barsetAt(i)->insertValue(start - m_mapFirst, m_model->data(m_model->index(i, start), Qt::DisplayRole).toDouble()); | |
361 | } |
|
361 | } | |
362 | } |
|
362 | } | |
363 | emit restructuredBar(1); |
|
363 | emit restructuredBar(1); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) |
|
366 | void QBarSeries::modelDataRemoved(QModelIndex parent, int start, int end) | |
367 | { |
|
367 | { | |
368 | Q_UNUSED(parent) |
|
368 | Q_UNUSED(parent) | |
369 | Q_UNUSED(end) |
|
369 | Q_UNUSED(end) | |
370 |
|
370 | |||
371 | removeCategory(start - m_mapFirst); |
|
371 | removeCategory(start - m_mapFirst); | |
372 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) |
|
372 | for (int i = 0; i <= m_mapBarTop - m_mapBarBottom; i++) | |
373 | { |
|
373 | { | |
374 | barsetAt(i)->removeValue(start - m_mapFirst); |
|
374 | barsetAt(i)->removeValue(start - m_mapFirst); | |
375 | } |
|
375 | } | |
376 | emit restructuredBar(1); |
|
376 | emit restructuredBar(1); | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | void QBarSeries::barsetChanged() |
|
379 | void QBarSeries::barsetChanged() | |
380 | { |
|
380 | { | |
381 | emit updatedBars(); |
|
381 | emit updatedBars(); | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | QBarCategories QBarSeries::categories() const |
|
384 | QBarCategories QBarSeries::categories() const | |
385 | { |
|
385 | { | |
386 | QBarCategories categories; |
|
386 | QBarCategories categories; | |
387 | int count = m_internalModel->categoryCount(); |
|
387 | int count = m_internalModel->categoryCount(); | |
388 | for (int i=1; i <= count; i++) { |
|
388 | for (int i=1; i <= count; i++) { | |
389 | categories.insert(i, m_internalModel->categoryName(i - 1)); |
|
389 | categories.insert(i, m_internalModel->categoryName(i - 1)); | |
390 | } |
|
390 | } | |
391 | return categories; |
|
391 | return categories; | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 |
void QBarSeries::set |
|
394 | void QBarSeries::setLabelsVisible(bool visible) | |
395 | { |
|
395 | { | |
396 | foreach (QBarSet* s, barSets()) { |
|
396 | foreach (QBarSet* s, barSets()) { | |
397 |
s->set |
|
397 | s->setLabelsVisible(visible); | |
398 | } |
|
398 | } | |
399 | } |
|
399 | } | |
400 |
|
400 | |||
401 |
|
401 | |||
402 | #include "moc_qbarseries.cpp" |
|
402 | #include "moc_qbarseries.cpp" | |
403 |
|
403 | |||
404 | QTCOMMERCIALCHART_END_NAMESPACE |
|
404 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,116 +1,116 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qseries.h> |
|
24 | #include <qseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | typedef QStringList QBarCategories; |
|
29 | typedef QStringList QBarCategories; | |
30 |
|
30 | |||
31 | class QBarSet; |
|
31 | class QBarSet; | |
32 | class BarChartModel; |
|
32 | class BarChartModel; | |
33 | class BarCategory; |
|
33 | class BarCategory; | |
34 |
|
34 | |||
35 | // Container for series |
|
35 | // Container for series | |
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries |
|
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QSeries | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | public: |
|
39 | public: | |
40 | QBarSeries(QStringList categories, QObject *parent = 0); |
|
40 | QBarSeries(QStringList categories, QObject *parent = 0); | |
41 |
|
41 | |||
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } |
|
42 | virtual QSeriesType type() const { return QSeries::SeriesTypeBar; } | |
43 |
|
43 | |||
44 | void appendBarSet(QBarSet *set); // Takes ownership of set |
|
44 | void appendBarSet(QBarSet *set); // Takes ownership of set | |
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set |
|
45 | void removeBarSet(QBarSet *set); // Releases ownership, doesn't delete set | |
46 | void insertBarSet(int i, QBarSet *set); |
|
46 | void insertBarSet(int i, QBarSet *set); | |
47 | void insertCategory(int i, QString category); |
|
47 | void insertCategory(int i, QString category); | |
48 | void removeCategory(int i); |
|
48 | void removeCategory(int i); | |
49 | int barsetCount() const; |
|
49 | int barsetCount() const; | |
50 | int categoryCount() const; |
|
50 | int categoryCount() const; | |
51 | QList<QBarSet*> barSets() const; |
|
51 | QList<QBarSet*> barSets() const; | |
52 | QBarCategories categories() const; |
|
52 | QBarCategories categories() const; | |
53 |
|
53 | |||
54 |
void set |
|
54 | void setLabelsVisible(bool visible = true); | |
55 |
|
55 | |||
56 | bool setModel(QAbstractItemModel *model); |
|
56 | bool setModel(QAbstractItemModel *model); | |
57 | QAbstractItemModel *modelExt() { return m_model; } |
|
57 | QAbstractItemModel *modelExt() { return m_model; } | |
58 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); |
|
58 | void setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation = Qt::Vertical); | |
59 | void setModelMappingShift(int first, int count); |
|
59 | void setModelMappingShift(int first, int count); | |
60 |
|
60 | |||
61 | public: |
|
61 | public: | |
62 | // TODO: Functions below this are not part of api and will be moved |
|
62 | // TODO: Functions below this are not part of api and will be moved | |
63 | // to private implementation, when we start using it |
|
63 | // to private implementation, when we start using it | |
64 | // TODO: TO PIMPL ---> |
|
64 | // TODO: TO PIMPL ---> | |
65 | QBarSet* barsetAt(int index); |
|
65 | QBarSet* barsetAt(int index); | |
66 | QString categoryName(int category); |
|
66 | QString categoryName(int category); | |
67 | qreal min(); |
|
67 | qreal min(); | |
68 | qreal max(); |
|
68 | qreal max(); | |
69 | qreal valueAt(int set, int category); |
|
69 | qreal valueAt(int set, int category); | |
70 | qreal percentageAt(int set, int category); |
|
70 | qreal percentageAt(int set, int category); | |
71 | qreal categorySum(int category); |
|
71 | qreal categorySum(int category); | |
72 | qreal maxCategorySum(); |
|
72 | qreal maxCategorySum(); | |
73 | BarChartModel& model(); |
|
73 | BarChartModel& model(); | |
74 | // <--- TO PIMPL |
|
74 | // <--- TO PIMPL | |
75 |
|
75 | |||
76 | Q_SIGNALS: |
|
76 | Q_SIGNALS: | |
77 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals |
|
77 | void clicked(QBarSet *barset, QString category, Qt::MouseButtons button); // Up to user of api, what to do with these signals | |
78 |
|
78 | |||
79 | // |
|
79 | // | |
80 | void updatedBars(); |
|
80 | void updatedBars(); | |
81 | void restructuredBar(int); |
|
81 | void restructuredBar(int); | |
82 |
|
82 | |||
83 | // TODO: internal signals, these to private implementation. |
|
83 | // TODO: internal signals, these to private implementation. | |
84 | // TODO: TO PIMPL ---> |
|
84 | // TODO: TO PIMPL ---> | |
85 | void showToolTip(QPoint pos, QString tip); |
|
85 | void showToolTip(QPoint pos, QString tip); | |
86 | // <--- TO PIMPL |
|
86 | // <--- TO PIMPL | |
87 |
|
87 | |||
88 | public Q_SLOTS: |
|
88 | public Q_SLOTS: | |
89 | void setToolTipEnabled(bool enabled = true); // enables tooltips |
|
89 | void setToolTipEnabled(bool enabled = true); // enables tooltips | |
90 |
|
90 | |||
91 | // TODO: TO PIMPL ---> |
|
91 | // TODO: TO PIMPL ---> | |
92 | void barsetClicked(QString category, Qt::MouseButtons button); |
|
92 | void barsetClicked(QString category, Qt::MouseButtons button); | |
93 | // <--- TO PIMPL |
|
93 | // <--- TO PIMPL | |
94 |
|
94 | |||
95 | private Q_SLOTS: |
|
95 | private Q_SLOTS: | |
96 | // slots for updating bars when data in model changes |
|
96 | // slots for updating bars when data in model changes | |
97 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); |
|
97 | void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight); | |
98 | void modelDataAdded(QModelIndex parent, int start, int end); |
|
98 | void modelDataAdded(QModelIndex parent, int start, int end); | |
99 | void modelDataRemoved(QModelIndex parent, int start, int end); |
|
99 | void modelDataRemoved(QModelIndex parent, int start, int end); | |
100 | void barsetChanged(); |
|
100 | void barsetChanged(); | |
101 |
|
101 | |||
102 | protected: |
|
102 | protected: | |
103 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. |
|
103 | BarChartModel *m_internalModel; // TODO: this may change... current "2 models" situation doesn't look good. | |
104 |
|
104 | |||
105 | QAbstractItemModel* m_model; |
|
105 | QAbstractItemModel* m_model; | |
106 | int m_mapCategories; |
|
106 | int m_mapCategories; | |
107 | int m_mapBarBottom; |
|
107 | int m_mapBarBottom; | |
108 | int m_mapBarTop; |
|
108 | int m_mapBarTop; | |
109 | int m_mapFirst; |
|
109 | int m_mapFirst; | |
110 | int m_mapCount; |
|
110 | int m_mapCount; | |
111 | Qt::Orientation m_mapOrientation; |
|
111 | Qt::Orientation m_mapOrientation; | |
112 | }; |
|
112 | }; | |
113 |
|
113 | |||
114 | QTCOMMERCIALCHART_END_NAMESPACE |
|
114 | QTCOMMERCIALCHART_END_NAMESPACE | |
115 |
|
115 | |||
116 | #endif // BARSERIES_H |
|
116 | #endif // BARSERIES_H |
@@ -1,229 +1,274 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QToolTip> |
|
23 | #include <QToolTip> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QBarSet |
|
28 | \class QBarSet | |
29 | \brief part of QtCommercial chart API. |
|
29 | \brief part of QtCommercial chart API. | |
30 |
|
30 | |||
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
32 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | First value of set is assumed to belong to first category, second to second category and so on. | |
33 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | If set has fewer values than there are categories, then the missing values are assumed to be | |
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QBarSeries, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) |
|
42 | \fn void QBarSet::clicked(QString category, Qt::MouseButtons button) | |
43 | \brief signals that set has been clicked |
|
43 | \brief signals that set has been clicked | |
44 | Parameter \a category describes on which category was clicked |
|
44 | Parameter \a category describes on which category was clicked | |
45 | Parameter \a button mouse button |
|
45 | Parameter \a button mouse button | |
46 | */ |
|
46 | */ | |
47 |
|
47 | |||
48 | /*! |
|
48 | /*! | |
49 | \fn void QBarSet::hoverEnter(QPoint pos) |
|
49 | \fn void QBarSet::hoverEnter(QPoint pos) | |
50 | \brief signals that mouse has entered over the set at position \a pos. |
|
50 | \brief signals that mouse has entered over the set at position \a pos. | |
51 | */ |
|
51 | */ | |
52 |
|
52 | |||
53 | /*! |
|
53 | /*! | |
54 | \fn void QBarSet::hoverLeave() |
|
54 | \fn void QBarSet::hoverLeave() | |
55 | \brief signals that mouse has left from the set. |
|
55 | \brief signals that mouse has left from the set. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 |
\fn void QBarSet::set |
|
59 | \fn void QBarSet::setLabelssVisible(bool visible = true) | |
60 |
\brief Sets visibility of bar |
|
60 | \brief Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) |
|
64 | \fn void QBarSet::showToolTip(QPoint pos, QString tip) | |
65 | \brief \internal \a pos \a tip |
|
65 | \brief \internal \a pos \a tip | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
70 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
71 | */ |
|
71 | */ | |
72 | QBarSet::QBarSet(QString name, QObject *parent) |
|
72 | QBarSet::QBarSet(QString name, QObject *parent) | |
73 | : QObject(parent) |
|
73 | : QObject(parent) | |
74 | ,m_name(name) |
|
74 | ,m_name(name) | |
|
75 | ,m_labelsVisible(false) | |||
75 | { |
|
76 | { | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | /*! |
|
79 | /*! | |
79 | Sets new \a name for set. |
|
80 | Sets new \a name for set. | |
80 | */ |
|
81 | */ | |
81 | void QBarSet::setName(QString name) |
|
82 | void QBarSet::setName(QString name) | |
82 | { |
|
83 | { | |
83 | m_name = name; |
|
84 | m_name = name; | |
84 | } |
|
85 | } | |
85 |
|
86 | |||
86 | /*! |
|
87 | /*! | |
87 | Returns name of the set. |
|
88 | Returns name of the set. | |
88 | */ |
|
89 | */ | |
89 | QString QBarSet::name() const |
|
90 | QString QBarSet::name() const | |
90 | { |
|
91 | { | |
91 | return m_name; |
|
92 | return m_name; | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
94 | /*! |
|
95 | /*! | |
95 | Appends new value \a value to the end of set. |
|
96 | Appends new value \a value to the end of set. | |
96 | */ |
|
97 | */ | |
97 | QBarSet& QBarSet::operator << (const qreal &value) |
|
98 | QBarSet& QBarSet::operator << (const qreal &value) | |
98 | { |
|
99 | { | |
99 | m_values.append(value); |
|
100 | m_values.append(value); | |
100 | emit structureChanged(); |
|
101 | emit structureChanged(); | |
101 | return *this; |
|
102 | return *this; | |
102 | } |
|
103 | } | |
103 |
|
104 | |||
104 | void QBarSet::insertValue(int i, qreal value) |
|
105 | void QBarSet::insertValue(int i, qreal value) | |
105 | { |
|
106 | { | |
106 | m_values.insert(i, value); |
|
107 | m_values.insert(i, value); | |
107 | } |
|
108 | } | |
108 |
|
109 | |||
109 | void QBarSet::removeValue(int i) |
|
110 | void QBarSet::removeValue(int i) | |
110 | { |
|
111 | { | |
111 | m_values.removeAt(i); |
|
112 | m_values.removeAt(i); | |
112 | } |
|
113 | } | |
113 |
|
114 | |||
114 | /*! |
|
115 | /*! | |
115 | Returns count of values in set. |
|
116 | Returns count of values in set. | |
116 | */ |
|
117 | */ | |
117 | int QBarSet::count() const |
|
118 | int QBarSet::count() const | |
118 | { |
|
119 | { | |
119 | return m_values.count(); |
|
120 | return m_values.count(); | |
120 | } |
|
121 | } | |
121 |
|
122 | |||
122 | /*! |
|
123 | /*! | |
123 | Returns value of set indexed by \a index |
|
124 | Returns value of set indexed by \a index | |
124 | */ |
|
125 | */ | |
125 | qreal QBarSet::valueAt(int index) const |
|
126 | qreal QBarSet::valueAt(int index) const | |
126 | { |
|
127 | { | |
127 | return m_values.at(index); |
|
128 | return m_values.at(index); | |
128 | } |
|
129 | } | |
129 |
|
130 | |||
130 | /*! |
|
131 | /*! | |
131 | Sets a new value \a value to set, indexed by \a index |
|
132 | Sets a new value \a value to set, indexed by \a index | |
132 | */ |
|
133 | */ | |
133 | void QBarSet::setValue(int index, qreal value) |
|
134 | void QBarSet::setValue(int index, qreal value) | |
134 | { |
|
135 | { | |
135 | m_values.replace(index,value); |
|
136 | m_values.replace(index,value); | |
136 | emit valueChanged(); |
|
137 | emit valueChanged(); | |
137 | } |
|
138 | } | |
138 |
|
139 | |||
139 | /*! |
|
140 | /*! | |
140 | Returns total sum of all values in barset. |
|
141 | Returns total sum of all values in barset. | |
141 | */ |
|
142 | */ | |
142 | qreal QBarSet::total() const |
|
143 | qreal QBarSet::total() const | |
143 | { |
|
144 | { | |
144 | qreal total(0); |
|
145 | qreal total(0); | |
145 | for (int i=0; i < m_values.count(); i++) { |
|
146 | for (int i=0; i < m_values.count(); i++) { | |
146 | total += m_values.at(i); |
|
147 | total += m_values.at(i); | |
147 | } |
|
148 | } | |
148 | return total; |
|
149 | return total; | |
149 | } |
|
150 | } | |
150 |
|
151 | |||
151 | /*! |
|
152 | /*! | |
152 | Sets pen for set. Bars of this set are drawn using \a pen |
|
153 | Sets pen for set. Bars of this set are drawn using \a pen | |
153 | */ |
|
154 | */ | |
154 | void QBarSet::setPen(const QPen &pen) |
|
155 | void QBarSet::setPen(const QPen &pen) | |
155 | { |
|
156 | { | |
156 | m_pen = pen; |
|
157 | m_pen = pen; | |
157 | emit valueChanged(); |
|
158 | emit valueChanged(); | |
158 | } |
|
159 | } | |
159 |
|
160 | |||
160 | /*! |
|
161 | /*! | |
161 | Returns pen of the set. |
|
162 | Returns pen of the set. | |
162 | */ |
|
163 | */ | |
163 | QPen QBarSet::pen() const |
|
164 | QPen QBarSet::pen() const | |
164 | { |
|
165 | { | |
165 | return m_pen; |
|
166 | return m_pen; | |
166 | } |
|
167 | } | |
167 |
|
168 | |||
168 | /*! |
|
169 | /*! | |
169 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
170 | Sets brush for the set. Bars of this set are drawn using \a brush | |
170 | */ |
|
171 | */ | |
171 | void QBarSet::setBrush(const QBrush &brush) |
|
172 | void QBarSet::setBrush(const QBrush &brush) | |
172 | { |
|
173 | { | |
173 | m_brush = brush; |
|
174 | m_brush = brush; | |
174 | emit valueChanged(); |
|
175 | emit valueChanged(); | |
175 | } |
|
176 | } | |
176 |
|
177 | |||
177 | /*! |
|
178 | /*! | |
178 | Returns brush of the set. |
|
179 | Returns brush of the set. | |
179 | */ |
|
180 | */ | |
180 | QBrush QBarSet::brush() const |
|
181 | QBrush QBarSet::brush() const | |
181 | { |
|
182 | { | |
182 | return m_brush; |
|
183 | return m_brush; | |
183 | } |
|
184 | } | |
184 |
|
185 | |||
185 | /*! |
|
186 | /*! | |
186 |
Sets |
|
187 | Sets pen of the values that are drawn on top of this barset | |
187 | */ |
|
188 | */ | |
188 |
void QBarSet::set |
|
189 | void QBarSet::setLabelPen(const QPen &pen) | |
189 | { |
|
190 | { | |
190 |
m_ |
|
191 | m_labelPen = pen; | |
|
192 | emit valueChanged(); | |||
|
193 | } | |||
|
194 | ||||
|
195 | /*! | |||
|
196 | Returns pen of the values that are drawn on top of this barset | |||
|
197 | */ | |||
|
198 | QPen QBarSet::labelPen() const | |||
|
199 | { | |||
|
200 | return m_labelPen; | |||
|
201 | } | |||
|
202 | ||||
|
203 | /*! | |||
|
204 | Sets brush of the values that are drawn on top of this barset | |||
|
205 | */ | |||
|
206 | void QBarSet::setLabelBrush(const QBrush &brush) | |||
|
207 | { | |||
|
208 | m_labelBrush = brush; | |||
|
209 | emit valueChanged(); | |||
|
210 | } | |||
|
211 | ||||
|
212 | /*! | |||
|
213 | Returns brush of the values that are drawn on top of this barset | |||
|
214 | */ | |||
|
215 | QBrush QBarSet::labelBrush() const | |||
|
216 | { | |||
|
217 | return m_labelBrush; | |||
|
218 | } | |||
|
219 | ||||
|
220 | /*! | |||
|
221 | Sets the pen for values that are drawn on top of this barset | |||
|
222 | */ | |||
|
223 | void QBarSet::setLabelFont(const QFont &font) | |||
|
224 | { | |||
|
225 | m_labelFont = font; | |||
|
226 | emit valueChanged(); | |||
191 | } |
|
227 | } | |
192 |
|
228 | |||
193 | /*! |
|
229 | /*! | |
194 | Returns the pen for values that are drawn on top of this set |
|
230 | Returns the pen for values that are drawn on top of this set | |
195 | */ |
|
231 | */ | |
196 |
Q |
|
232 | QFont QBarSet::labelFont() const | |
197 | { |
|
233 | { | |
198 |
return m_ |
|
234 | return m_labelFont; | |
199 | } |
|
235 | } | |
200 |
|
236 | |||
201 | /*! |
|
237 | /*! | |
202 | Sets the visibility of barset values to \a visible |
|
238 | Sets the visibility of barset values to \a visible | |
203 | */ |
|
239 | */ | |
204 |
void QBarSet::set |
|
240 | void QBarSet::setLabelsVisible(bool visible) | |
|
241 | { | |||
|
242 | m_labelsVisible = visible; | |||
|
243 | emit labelsVisibleChanged(visible); | |||
|
244 | } | |||
|
245 | ||||
|
246 | /*! | |||
|
247 | Returns the visibility of values | |||
|
248 | */ | |||
|
249 | bool QBarSet::labelsVisible() const | |||
205 | { |
|
250 | { | |
206 | emit valuesVisibleChanged(visible); |
|
251 | return m_labelsVisible; | |
207 | } |
|
252 | } | |
208 |
|
253 | |||
209 | /*! |
|
254 | /*! | |
210 | \internal \a pos |
|
255 | \internal \a pos | |
211 | */ |
|
256 | */ | |
212 | void QBarSet::barHoverEnterEvent(QPoint pos) |
|
257 | void QBarSet::barHoverEnterEvent(QPoint pos) | |
213 | { |
|
258 | { | |
214 | emit showToolTip(pos, m_name); |
|
259 | emit showToolTip(pos, m_name); | |
215 | emit hoverEnter(pos); |
|
260 | emit hoverEnter(pos); | |
216 | } |
|
261 | } | |
217 |
|
262 | |||
218 | /*! |
|
263 | /*! | |
219 | \internal |
|
264 | \internal | |
220 | */ |
|
265 | */ | |
221 | void QBarSet::barHoverLeaveEvent() |
|
266 | void QBarSet::barHoverLeaveEvent() | |
222 | { |
|
267 | { | |
223 | // Emit signal to user of charts |
|
268 | // Emit signal to user of charts | |
224 | emit hoverLeave(); |
|
269 | emit hoverLeave(); | |
225 | } |
|
270 | } | |
226 |
|
271 | |||
227 | #include "moc_qbarset.cpp" |
|
272 | #include "moc_qbarset.cpp" | |
228 |
|
273 | |||
229 | QTCOMMERCIALCHART_END_NAMESPACE |
|
274 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,94 +1,105 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QBARSET_H |
|
21 | #ifndef QBARSET_H | |
22 | #define QBARSET_H |
|
22 | #define QBARSET_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
|
27 | #include <QFont> | |||
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
30 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
31 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
31 | { |
|
32 | { | |
32 | Q_OBJECT |
|
33 | Q_OBJECT | |
33 | public: |
|
34 | public: | |
34 | QBarSet(QString name, QObject *parent = 0); |
|
35 | QBarSet(QString name, QObject *parent = 0); | |
35 |
|
36 | |||
36 | void setName(QString name); |
|
37 | void setName(QString name); | |
37 | QString name() const; |
|
38 | QString name() const; | |
38 | QBarSet& operator << (const qreal &value); // appends new value to set |
|
39 | QBarSet& operator << (const qreal &value); // appends new value to set | |
39 | void insertValue(int i, qreal value); |
|
40 | void insertValue(int i, qreal value); | |
40 | void removeValue(int i); |
|
41 | void removeValue(int i); | |
41 |
|
42 | |||
42 | // TODO: remove indices eventually. Use as internal? |
|
43 | // TODO: remove indices eventually. Use as internal? | |
43 | int count() const; // count of values in set |
|
44 | int count() const; // count of values in set | |
44 | qreal valueAt(int index) const; // for modifying individual values |
|
45 | qreal valueAt(int index) const; // for modifying individual values | |
45 | void setValue(int index, qreal value); // setter for individual value |
|
46 | void setValue(int index, qreal value); // setter for individual value | |
46 | qreal total() const; // total values in the set |
|
47 | qreal total() const; // total values in the set | |
47 |
|
48 | |||
48 | // TODO: |
|
49 | // TODO: | |
49 | //qreal value(QString category); |
|
50 | //qreal value(QString category); | |
50 | //void setValue(QString category, qreal value); |
|
51 | //void setValue(QString category, qreal value); | |
51 |
|
52 | |||
52 | void setPen(const QPen &pen); |
|
53 | void setPen(const QPen &pen); | |
53 | QPen pen() const; |
|
54 | QPen pen() const; | |
54 |
|
55 | |||
55 | void setBrush(const QBrush &brush); |
|
56 | void setBrush(const QBrush &brush); | |
56 | QBrush brush() const; |
|
57 | QBrush brush() const; | |
57 |
|
58 | |||
58 |
void set |
|
59 | void setLabelPen(const QPen &pen); | |
59 |
QPen |
|
60 | QPen labelPen() const; | |
60 |
|
61 | |||
61 | void setValuesVisible(bool visible = true); |
|
62 | void setLabelBrush(const QBrush &brush); | |
|
63 | QBrush labelBrush() const; | |||
|
64 | ||||
|
65 | void setLabelFont(const QFont &font); | |||
|
66 | QFont labelFont() const; | |||
|
67 | ||||
|
68 | void setLabelsVisible(bool visible = true); | |||
|
69 | bool labelsVisible() const; | |||
62 |
|
70 | |||
63 | Q_SIGNALS: |
|
71 | Q_SIGNALS: | |
64 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user |
|
72 | void clicked(QString category, Qt::MouseButtons button); // Clicked and hover signals exposed to user | |
65 |
|
73 | |||
66 | // TODO: TO PIMPL ---> |
|
74 | // TODO: TO PIMPL ---> | |
67 | void structureChanged(); |
|
75 | void structureChanged(); | |
68 | void valueChanged(); |
|
76 | void valueChanged(); | |
69 | void hoverEnter(QPoint pos); |
|
77 | void hoverEnter(QPoint pos); | |
70 | void hoverLeave(); |
|
78 | void hoverLeave(); | |
71 | void showToolTip(QPoint pos, QString tip); // Private signal |
|
79 | void showToolTip(QPoint pos, QString tip); // Private signal | |
72 |
void |
|
80 | void labelsVisibleChanged(bool visible); | |
73 | // <--- TO PIMPL |
|
81 | // <--- TO PIMPL | |
74 |
|
82 | |||
75 | public Q_SLOTS: |
|
83 | public Q_SLOTS: | |
76 | // These are for internal communication |
|
84 | // These are for internal communication | |
77 | // TODO: TO PIMPL ---> |
|
85 | // TODO: TO PIMPL ---> | |
78 | void barHoverEnterEvent(QPoint pos); |
|
86 | void barHoverEnterEvent(QPoint pos); | |
79 | void barHoverLeaveEvent(); |
|
87 | void barHoverLeaveEvent(); | |
80 | // <--- TO PIMPL |
|
88 | // <--- TO PIMPL | |
81 |
|
89 | |||
82 | private: |
|
90 | private: | |
83 |
|
91 | |||
84 | QString m_name; |
|
92 | QString m_name; | |
85 | QList<qreal> m_values; // TODO: replace with map (category, value) |
|
93 | QList<qreal> m_values; // TODO: replace with map (category, value) | |
86 | QMap<QString, qreal> m_mappedValues; |
|
94 | QMap<QString, qreal> m_mappedValues; | |
87 | QPen m_pen; |
|
95 | QPen m_pen; | |
88 | QBrush m_brush; |
|
96 | QBrush m_brush; | |
89 |
QPen m_ |
|
97 | QPen m_labelPen; | |
|
98 | QBrush m_labelBrush; | |||
|
99 | QFont m_labelFont; | |||
|
100 | bool m_labelsVisible; | |||
90 | }; |
|
101 | }; | |
91 |
|
102 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
103 | QTCOMMERCIALCHART_END_NAMESPACE | |
93 |
|
104 | |||
94 | #endif // QBARSET_H |
|
105 | #endif // QBARSET_H |
@@ -1,93 +1,92 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "stackedbarchartitem_p.h" |
|
21 | #include "stackedbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 |
#include "bar |
|
23 | #include "barlabel_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | StackedBarChartItem::~StackedBarChartItem() |
|
34 | StackedBarChartItem::~StackedBarChartItem() | |
35 | { |
|
35 | { | |
36 | } |
|
36 | } | |
37 |
|
37 | |||
38 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
38 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
39 | { |
|
39 | { | |
40 | QVector<QRectF> layout; |
|
40 | QVector<QRectF> layout; | |
41 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) |
|
41 | // Use temporary qreals for accurancy (we might get some compiler warnings... :) | |
42 |
|
42 | |||
43 | qreal maxSum = m_series->maxCategorySum(); |
|
43 | qreal maxSum = m_series->maxCategorySum(); | |
44 | // Domain: |
|
44 | // Domain: | |
45 | if (m_domainMaxY > maxSum) { |
|
45 | if (m_domainMaxY > maxSum) { | |
46 | maxSum = m_domainMaxY; |
|
46 | maxSum = m_domainMaxY; | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | qreal height = geometry().height(); |
|
49 | qreal height = geometry().height(); | |
50 | qreal width = geometry().width(); |
|
50 | qreal width = geometry().width(); | |
51 | qreal scale = (height / m_series->maxCategorySum()); |
|
51 | qreal scale = (height / m_series->maxCategorySum()); | |
52 | qreal categotyCount = m_series->categoryCount(); |
|
52 | qreal categotyCount = m_series->categoryCount(); | |
53 | qreal barWidth = width / (categotyCount * 2); |
|
53 | qreal barWidth = width / (categotyCount * 2); | |
54 | qreal xStep = width / categotyCount; |
|
54 | qreal xStep = width / categotyCount; | |
55 | qreal xPos = xStep / 2 - barWidth / 2; |
|
55 | qreal xPos = xStep / 2 - barWidth / 2; | |
56 |
|
56 | |||
57 | int itemIndex(0); |
|
57 | int itemIndex(0); | |
58 | for (int category = 0; category < categotyCount; category++) { |
|
58 | for (int category = 0; category < categotyCount; category++) { | |
59 | qreal yPos = height; |
|
59 | qreal yPos = height; | |
60 | for (int set=0; set < m_series->barsetCount(); set++) { |
|
60 | for (int set=0; set < m_series->barsetCount(); set++) { | |
61 | QBarSet* barSet = m_series->barsetAt(set); |
|
61 | QBarSet* barSet = m_series->barsetAt(set); | |
62 |
|
62 | |||
63 |
qreal barHeight = barSet->valueAt(category) * scale; |
|
63 | qreal barHeight = barSet->valueAt(category) * scale; | |
64 | Bar* bar = m_bars.at(itemIndex); |
|
64 | Bar* bar = m_bars.at(itemIndex); | |
65 | bar->setPen(barSet->pen()); |
|
65 | bar->setPen(barSet->pen()); | |
66 | bar->setBrush(barSet->brush()); |
|
66 | bar->setBrush(barSet->brush()); | |
67 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
67 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
68 | layout.append(rect); |
|
68 | layout.append(rect); | |
69 |
|
69 | |||
70 |
Bar |
|
70 | BarLabel* label = m_labels.at(itemIndex); | |
71 |
|
71 | |||
72 | if (!qFuzzyIsNull(barSet->valueAt(category))) { |
|
72 | if (!qFuzzyIsNull(barSet->valueAt(category))) { | |
73 |
|
|
73 | label->setText(QString::number(barSet->valueAt(category))); | |
74 | } else { |
|
74 | } else { | |
75 |
|
|
75 | label->setText(QString("")); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 |
|
|
78 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
79 |
,yPos - barHeight/2 - |
|
79 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
80 |
value->set |
|
80 | // value->setFont(barSet->valueFont()); | |
81 |
|
||||
82 | itemIndex++; |
|
81 | itemIndex++; | |
83 | yPos -= barHeight; |
|
82 | yPos -= barHeight; | |
84 | } |
|
83 | } | |
85 | xPos += xStep; |
|
84 | xPos += xStep; | |
86 | } |
|
85 | } | |
87 |
|
86 | |||
88 | return layout; |
|
87 | return layout; | |
89 | } |
|
88 | } | |
90 |
|
89 | |||
91 | #include "moc_stackedbarchartitem_p.cpp" |
|
90 | #include "moc_stackedbarchartitem_p.cpp" | |
92 |
|
91 | |||
93 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,393 +1,393 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qlegend.h" |
|
24 | #include "qlegend.h" | |
25 | #include "qchartaxis.h" |
|
25 | #include "qchartaxis.h" | |
26 | #include <QTime> |
|
26 | #include <QTime> | |
27 |
|
27 | |||
28 | //series |
|
28 | //series | |
29 | #include "qbarset.h" |
|
29 | #include "qbarset.h" | |
30 | #include "qbarseries.h" |
|
30 | #include "qbarseries.h" | |
31 | #include "qstackedbarseries.h" |
|
31 | #include "qstackedbarseries.h" | |
32 | #include "qpercentbarseries.h" |
|
32 | #include "qpercentbarseries.h" | |
33 | #include "qlineseries.h" |
|
33 | #include "qlineseries.h" | |
34 | #include "qareaseries.h" |
|
34 | #include "qareaseries.h" | |
35 | #include "qscatterseries.h" |
|
35 | #include "qscatterseries.h" | |
36 | #include "qpieseries.h" |
|
36 | #include "qpieseries.h" | |
37 | #include "qpieslice.h" |
|
37 | #include "qpieslice.h" | |
38 | #include "qsplineseries.h" |
|
38 | #include "qsplineseries.h" | |
39 |
|
39 | |||
40 | //items |
|
40 | //items | |
41 | #include "axisitem_p.h" |
|
41 | #include "axisitem_p.h" | |
42 | #include "barchartitem_p.h" |
|
42 | #include "barchartitem_p.h" | |
43 | #include "stackedbarchartitem_p.h" |
|
43 | #include "stackedbarchartitem_p.h" | |
44 | #include "percentbarchartitem_p.h" |
|
44 | #include "percentbarchartitem_p.h" | |
45 | #include "linechartitem_p.h" |
|
45 | #include "linechartitem_p.h" | |
46 | #include "areachartitem_p.h" |
|
46 | #include "areachartitem_p.h" | |
47 | #include "scatterchartitem_p.h" |
|
47 | #include "scatterchartitem_p.h" | |
48 | #include "piechartitem_p.h" |
|
48 | #include "piechartitem_p.h" | |
49 | #include "splinechartitem_p.h" |
|
49 | #include "splinechartitem_p.h" | |
50 |
|
50 | |||
51 | //themes |
|
51 | //themes | |
52 | #include "chartthemedefault_p.h" |
|
52 | #include "chartthemedefault_p.h" | |
53 | #include "chartthemelight_p.h" |
|
53 | #include "chartthemelight_p.h" | |
54 | #include "chartthemebluecerulean_p.h" |
|
54 | #include "chartthemebluecerulean_p.h" | |
55 | #include "chartthemedark_p.h" |
|
55 | #include "chartthemedark_p.h" | |
56 | #include "chartthemebrownsand_p.h" |
|
56 | #include "chartthemebrownsand_p.h" | |
57 | #include "chartthemebluencs_p.h" |
|
57 | #include "chartthemebluencs_p.h" | |
58 | #include "chartthemehighcontrast_p.h" |
|
58 | #include "chartthemehighcontrast_p.h" | |
59 | #include "chartthemeblueicy_p.h" |
|
59 | #include "chartthemeblueicy_p.h" | |
60 |
|
60 | |||
61 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
61 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
62 |
|
62 | |||
63 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
63 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
64 | m_masterFont(QFont("arial", 12)), |
|
64 | m_masterFont(QFont("arial", 12)), | |
65 | m_labelFont(QFont("arial", 10)), |
|
65 | m_labelFont(QFont("arial", 10)), | |
66 | m_titleBrush(QColor(QRgb(0x000000))), |
|
66 | m_titleBrush(QColor(QRgb(0x000000))), | |
67 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
67 | m_axisLinePen(QPen(QRgb(0x000000))), | |
68 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
68 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
69 | m_backgroundShadesPen(Qt::NoPen), |
|
69 | m_backgroundShadesPen(Qt::NoPen), | |
70 | m_backgroundShadesBrush(Qt::NoBrush), |
|
70 | m_backgroundShadesBrush(Qt::NoBrush), | |
71 | m_backgroundShades(BackgroundShadesNone), |
|
71 | m_backgroundShades(BackgroundShadesNone), | |
72 | m_gridLinePen(QPen(QRgb(0x000000))) |
|
72 | m_gridLinePen(QPen(QRgb(0x000000))) | |
73 | { |
|
73 | { | |
74 | m_id = id; |
|
74 | m_id = id; | |
75 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
75 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 |
|
78 | |||
79 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
79 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
80 | { |
|
80 | { | |
81 | switch(theme) { |
|
81 | switch(theme) { | |
82 | case QChart::ChartThemeLight: |
|
82 | case QChart::ChartThemeLight: | |
83 | return new ChartThemeLight(); |
|
83 | return new ChartThemeLight(); | |
84 | case QChart::ChartThemeBlueCerulean: |
|
84 | case QChart::ChartThemeBlueCerulean: | |
85 | return new ChartThemeBlueCerulean(); |
|
85 | return new ChartThemeBlueCerulean(); | |
86 | case QChart::ChartThemeDark: |
|
86 | case QChart::ChartThemeDark: | |
87 | return new ChartThemeDark(); |
|
87 | return new ChartThemeDark(); | |
88 | case QChart::ChartThemeBrownSand: |
|
88 | case QChart::ChartThemeBrownSand: | |
89 | return new ChartThemeBrownSand(); |
|
89 | return new ChartThemeBrownSand(); | |
90 | case QChart::ChartThemeBlueNcs: |
|
90 | case QChart::ChartThemeBlueNcs: | |
91 | return new ChartThemeBlueNcs(); |
|
91 | return new ChartThemeBlueNcs(); | |
92 | case QChart::ChartThemeHighContrast: |
|
92 | case QChart::ChartThemeHighContrast: | |
93 | return new ChartThemeHighContrast(); |
|
93 | return new ChartThemeHighContrast(); | |
94 | case QChart::ChartThemeBlueIcy: |
|
94 | case QChart::ChartThemeBlueIcy: | |
95 | return new ChartThemeBlueIcy(); |
|
95 | return new ChartThemeBlueIcy(); | |
96 | default: |
|
96 | default: | |
97 | return new ChartThemeDefault(); |
|
97 | return new ChartThemeDefault(); | |
98 | } |
|
98 | } | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void ChartTheme::decorate(QChart* chart,bool force) |
|
101 | void ChartTheme::decorate(QChart* chart,bool force) | |
102 | { |
|
102 | { | |
103 | QBrush brush; |
|
103 | QBrush brush; | |
104 |
|
104 | |||
105 | if(brush == chart->backgroundBrush() || force) |
|
105 | if(brush == chart->backgroundBrush() || force) | |
106 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
106 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
107 | chart->setTitleFont(m_masterFont); |
|
107 | chart->setTitleFont(m_masterFont); | |
108 | chart->setTitleBrush(m_titleBrush); |
|
108 | chart->setTitleBrush(m_titleBrush); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void ChartTheme::decorate(QLegend* legend,bool force) |
|
111 | void ChartTheme::decorate(QLegend* legend,bool force) | |
112 | { |
|
112 | { | |
113 | QPen pen; |
|
113 | QPen pen; | |
114 | QBrush brush; |
|
114 | QBrush brush; | |
115 |
|
115 | |||
116 | if (pen == legend->pen() || force){ |
|
116 | if (pen == legend->pen() || force){ | |
117 | legend->setPen(Qt::NoPen); |
|
117 | legend->setPen(Qt::NoPen); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 |
|
120 | |||
121 | if (brush == legend->brush() || force) { |
|
121 | if (brush == legend->brush() || force) { | |
122 | legend->setBrush(m_chartBackgroundGradient); |
|
122 | legend->setBrush(m_chartBackgroundGradient); | |
123 | } |
|
123 | } | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) |
|
126 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |
127 | { |
|
127 | { | |
128 | QPen pen; |
|
128 | QPen pen; | |
129 | QBrush brush; |
|
129 | QBrush brush; | |
130 |
|
130 | |||
131 | if (pen == series->pen() || force){ |
|
131 | if (pen == series->pen() || force){ | |
132 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
132 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
133 | pen.setWidthF(2); |
|
133 | pen.setWidthF(2); | |
134 | series->setPen(pen); |
|
134 | series->setPen(pen); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | if (brush == series->brush() || force) { |
|
137 | if (brush == series->brush() || force) { | |
138 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
138 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
139 | series->setBrush(brush); |
|
139 | series->setBrush(brush); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 |
|
143 | |||
144 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) |
|
144 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |
145 | { |
|
145 | { | |
146 | QPen pen; |
|
146 | QPen pen; | |
147 | if(pen == series->pen() || force ){ |
|
147 | if(pen == series->pen() || force ){ | |
148 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
148 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
149 | pen.setWidthF(2); |
|
149 | pen.setWidthF(2); | |
150 | series->setPen(pen); |
|
150 | series->setPen(pen); | |
151 | } |
|
151 | } | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) |
|
154 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |
155 | { |
|
155 | { | |
156 | QBrush brush; |
|
156 | QBrush brush; | |
157 | QPen pen; |
|
157 | QPen pen; | |
158 | QList<QBarSet*> sets = series->barSets(); |
|
158 | QList<QBarSet*> sets = series->barSets(); | |
159 |
|
159 | |||
160 | qreal takeAtPos = 0.5; |
|
160 | qreal takeAtPos = 0.5; | |
161 | qreal step = 0.2; |
|
161 | qreal step = 0.2; | |
162 | if (sets.count() > 1 ) { |
|
162 | if (sets.count() > 1 ) { | |
163 | step = 1.0 / (qreal) sets.count(); |
|
163 | step = 1.0 / (qreal) sets.count(); | |
164 | if (sets.count() % m_seriesGradients.count()) |
|
164 | if (sets.count() % m_seriesGradients.count()) | |
165 | step *= m_seriesGradients.count(); |
|
165 | step *= m_seriesGradients.count(); | |
166 | else |
|
166 | else | |
167 | step *= (m_seriesGradients.count() - 1); |
|
167 | step *= (m_seriesGradients.count() - 1); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | for (int i(0); i < sets.count(); i++) { |
|
170 | for (int i(0); i < sets.count(); i++) { | |
171 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
171 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
172 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
172 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
173 | // There is no dedicated base color for each sets, generate more colors |
|
173 | // There is no dedicated base color for each sets, generate more colors | |
174 | takeAtPos += step; |
|
174 | takeAtPos += step; | |
175 | if (takeAtPos == 1.0) |
|
175 | if (takeAtPos == 1.0) | |
176 | takeAtPos += step; |
|
176 | takeAtPos += step; | |
177 | takeAtPos -= (int) takeAtPos; |
|
177 | takeAtPos -= (int) takeAtPos; | |
178 | } |
|
178 | } | |
179 | qDebug() << "pos:" << takeAtPos; |
|
179 | qDebug() << "pos:" << takeAtPos; | |
180 | if (brush == sets.at(i)->brush() || force ) |
|
180 | if (brush == sets.at(i)->brush() || force ) | |
181 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
181 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
182 |
|
182 | |||
183 | // Pick label color from the opposite end of the gradient. |
|
183 | // Pick label color from the opposite end of the gradient. | |
184 | // 0.3 as a boundary seems to work well. |
|
184 | // 0.3 as a boundary seems to work well. | |
185 | if (takeAtPos < 0.3) |
|
185 | if (takeAtPos < 0.3) | |
186 |
sets.at(i)->set |
|
186 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
187 | else |
|
187 | else | |
188 |
sets.at(i)->set |
|
188 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
189 |
|
189 | |||
190 | if (pen == sets.at(i)->pen() || force) { |
|
190 | if (pen == sets.at(i)->pen() || force) { | |
191 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
191 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
192 | sets.at(i)->setPen(c); |
|
192 | sets.at(i)->setPen(c); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) |
|
197 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |
198 | { |
|
198 | { | |
199 | QPen pen; |
|
199 | QPen pen; | |
200 | QBrush brush; |
|
200 | QBrush brush; | |
201 |
|
201 | |||
202 | if (pen == series->pen() || force) { |
|
202 | if (pen == series->pen() || force) { | |
203 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
203 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
204 | pen.setWidthF(2); |
|
204 | pen.setWidthF(2); | |
205 | series->setPen(pen); |
|
205 | series->setPen(pen); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | if (brush == series->brush() || force) { |
|
208 | if (brush == series->brush() || force) { | |
209 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
209 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
210 | series->setBrush(brush); |
|
210 | series->setBrush(brush); | |
211 | } |
|
211 | } | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
214 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
215 | { |
|
215 | { | |
216 |
|
216 | |||
217 | for (int i(0); i < series->slices().count(); i++) { |
|
217 | for (int i(0); i < series->slices().count(); i++) { | |
218 |
|
218 | |||
219 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
219 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
220 |
|
220 | |||
221 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
221 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
222 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
222 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
223 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
223 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
224 |
|
224 | |||
225 | QPieSlice *s = series->slices().at(i); |
|
225 | QPieSlice *s = series->slices().at(i); | |
226 | PieSliceData data = *s->data_ptr(); |
|
226 | PieSliceData data = *s->data_ptr(); | |
227 |
|
227 | |||
228 | if (data.m_slicePen.isThemed() || force) { |
|
228 | if (data.m_slicePen.isThemed() || force) { | |
229 | data.m_slicePen = penColor; |
|
229 | data.m_slicePen = penColor; | |
230 | data.m_slicePen.setThemed(true); |
|
230 | data.m_slicePen.setThemed(true); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | if (data.m_sliceBrush.isThemed() || force) { |
|
233 | if (data.m_sliceBrush.isThemed() || force) { | |
234 | data.m_sliceBrush = brushColor; |
|
234 | data.m_sliceBrush = brushColor; | |
235 | data.m_sliceBrush.setThemed(true); |
|
235 | data.m_sliceBrush.setThemed(true); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | if (data.m_labelPen.isThemed() || force) { |
|
238 | if (data.m_labelPen.isThemed() || force) { | |
239 | data.m_labelPen = QPen(m_titleBrush.color()); |
|
239 | data.m_labelPen = QPen(m_titleBrush.color()); | |
240 | data.m_labelPen.setThemed(true); |
|
240 | data.m_labelPen.setThemed(true); | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | if (data.m_labelFont.isThemed() || force) { |
|
243 | if (data.m_labelFont.isThemed() || force) { | |
244 | data.m_labelFont = m_labelFont; |
|
244 | data.m_labelFont = m_labelFont; | |
245 | data.m_labelFont.setThemed(true); |
|
245 | data.m_labelFont.setThemed(true); | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | if (*s->data_ptr() != data) { |
|
248 | if (*s->data_ptr() != data) { | |
249 | *s->data_ptr() = data; |
|
249 | *s->data_ptr() = data; | |
250 | emit s->data_ptr()->emitChangedSignal(s); |
|
250 | emit s->data_ptr()->emitChangedSignal(s); | |
251 | } |
|
251 | } | |
252 | } |
|
252 | } | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) |
|
255 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) | |
256 | { |
|
256 | { | |
257 | QPen pen; |
|
257 | QPen pen; | |
258 | if(pen == series->pen() || force){ |
|
258 | if(pen == series->pen() || force){ | |
259 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
259 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
260 | pen.setWidthF(2); |
|
260 | pen.setWidthF(2); | |
261 | series->setPen(pen); |
|
261 | series->setPen(pen); | |
262 | } |
|
262 | } | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) |
|
265 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) | |
266 | { |
|
266 | { | |
267 | QPen pen; |
|
267 | QPen pen; | |
268 | QBrush brush; |
|
268 | QBrush brush; | |
269 | QFont font; |
|
269 | QFont font; | |
270 |
|
270 | |||
271 | if (axis->isAxisVisible()) { |
|
271 | if (axis->isAxisVisible()) { | |
272 |
|
272 | |||
273 | if(brush == axis->labelsBrush() || force){ |
|
273 | if(brush == axis->labelsBrush() || force){ | |
274 | axis->setLabelsBrush(m_axisLabelBrush); |
|
274 | axis->setLabelsBrush(m_axisLabelBrush); | |
275 | } |
|
275 | } | |
276 | if(pen == axis->labelsPen() || force){ |
|
276 | if(pen == axis->labelsPen() || force){ | |
277 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
277 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 |
|
280 | |||
281 | if (axis->shadesVisible() || force) { |
|
281 | if (axis->shadesVisible() || force) { | |
282 |
|
282 | |||
283 | if(brush == axis->shadesBrush() || force){ |
|
283 | if(brush == axis->shadesBrush() || force){ | |
284 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
284 | axis->setShadesBrush(m_backgroundShadesBrush); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | if(pen == axis->shadesPen() || force){ |
|
287 | if(pen == axis->shadesPen() || force){ | |
288 | axis->setShadesPen(m_backgroundShadesPen); |
|
288 | axis->setShadesPen(m_backgroundShadesPen); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | if(force && (m_backgroundShades == BackgroundShadesBoth |
|
291 | if(force && (m_backgroundShades == BackgroundShadesBoth | |
292 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
292 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
293 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
293 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
294 | axis->setShadesVisible(true); |
|
294 | axis->setShadesVisible(true); | |
295 |
|
295 | |||
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | if(pen == axis->axisPen() || force){ |
|
299 | if(pen == axis->axisPen() || force){ | |
300 | axis->setAxisPen(m_axisLinePen); |
|
300 | axis->setAxisPen(m_axisLinePen); | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | if(pen == axis->gridLinePen() || force){ |
|
303 | if(pen == axis->gridLinePen() || force){ | |
304 | axis->setGridLinePen(m_gridLinePen); |
|
304 | axis->setGridLinePen(m_gridLinePen); | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | if(font == axis->labelsFont() || force){ |
|
307 | if(font == axis->labelsFont() || force){ | |
308 | axis->setLabelsFont(m_labelFont); |
|
308 | axis->setLabelsFont(m_labelFont); | |
309 | } |
|
309 | } | |
310 | } |
|
310 | } | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | void ChartTheme::generateSeriesGradients() |
|
313 | void ChartTheme::generateSeriesGradients() | |
314 | { |
|
314 | { | |
315 | // Generate gradients in HSV color space |
|
315 | // Generate gradients in HSV color space | |
316 | foreach (QColor color, m_seriesColors) { |
|
316 | foreach (QColor color, m_seriesColors) { | |
317 | QLinearGradient g; |
|
317 | QLinearGradient g; | |
318 | qreal h = color.hsvHueF(); |
|
318 | qreal h = color.hsvHueF(); | |
319 | qreal s = color.hsvSaturationF(); |
|
319 | qreal s = color.hsvSaturationF(); | |
320 |
|
320 | |||
321 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
321 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
322 | // most themes. The rest of the gradients we can define manually in theme specific |
|
322 | // most themes. The rest of the gradients we can define manually in theme specific | |
323 | // implementation. |
|
323 | // implementation. | |
324 | QColor start = color; |
|
324 | QColor start = color; | |
325 | start.setHsvF(h, 0.0, 1.0); |
|
325 | start.setHsvF(h, 0.0, 1.0); | |
326 | g.setColorAt(0.0, start); |
|
326 | g.setColorAt(0.0, start); | |
327 |
|
327 | |||
328 | g.setColorAt(0.5, color); |
|
328 | g.setColorAt(0.5, color); | |
329 |
|
329 | |||
330 | QColor end = color; |
|
330 | QColor end = color; | |
331 | end.setHsvF(h, s, 0.25); |
|
331 | end.setHsvF(h, s, 0.25); | |
332 | g.setColorAt(1.0, end); |
|
332 | g.setColorAt(1.0, end); | |
333 |
|
333 | |||
334 | m_seriesGradients << g; |
|
334 | m_seriesGradients << g; | |
335 | } |
|
335 | } | |
336 | } |
|
336 | } | |
337 |
|
337 | |||
338 |
|
338 | |||
339 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
339 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
340 | { |
|
340 | { | |
341 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
341 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
342 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
342 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
343 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
343 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
344 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
344 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
345 | QColor c; |
|
345 | QColor c; | |
346 | c.setRgbF(r, g, b); |
|
346 | c.setRgbF(r, g, b); | |
347 | return c; |
|
347 | return c; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
350 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
351 | { |
|
351 | { | |
352 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
352 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
353 |
|
353 | |||
354 | // another possibility: |
|
354 | // another possibility: | |
355 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
355 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
356 |
|
356 | |||
357 | QGradientStops stops = gradient.stops(); |
|
357 | QGradientStops stops = gradient.stops(); | |
358 | int count = stops.count(); |
|
358 | int count = stops.count(); | |
359 |
|
359 | |||
360 | // find previous stop relative to position |
|
360 | // find previous stop relative to position | |
361 | QGradientStop prev = stops.first(); |
|
361 | QGradientStop prev = stops.first(); | |
362 | for (int i=0; i<count; i++) { |
|
362 | for (int i=0; i<count; i++) { | |
363 | QGradientStop stop = stops.at(i); |
|
363 | QGradientStop stop = stops.at(i); | |
364 | if (pos > stop.first) |
|
364 | if (pos > stop.first) | |
365 | prev = stop; |
|
365 | prev = stop; | |
366 |
|
366 | |||
367 | // given position is actually a stop position? |
|
367 | // given position is actually a stop position? | |
368 | if (pos == stop.first) { |
|
368 | if (pos == stop.first) { | |
369 | //qDebug() << "stop color" << pos; |
|
369 | //qDebug() << "stop color" << pos; | |
370 | return stop.second; |
|
370 | return stop.second; | |
371 | } |
|
371 | } | |
372 | } |
|
372 | } | |
373 |
|
373 | |||
374 | // find next stop relative to position |
|
374 | // find next stop relative to position | |
375 | QGradientStop next = stops.last(); |
|
375 | QGradientStop next = stops.last(); | |
376 | for (int i=count-1; i>=0; i--) { |
|
376 | for (int i=count-1; i>=0; i--) { | |
377 | QGradientStop stop = stops.at(i); |
|
377 | QGradientStop stop = stops.at(i); | |
378 | if (pos < stop.first) |
|
378 | if (pos < stop.first) | |
379 | next = stop; |
|
379 | next = stop; | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
382 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
383 |
|
383 | |||
384 | qreal range = next.first - prev.first; |
|
384 | qreal range = next.first - prev.first; | |
385 | qreal posDelta = pos - prev.first; |
|
385 | qreal posDelta = pos - prev.first; | |
386 | qreal relativePos = posDelta / range; |
|
386 | qreal relativePos = posDelta / range; | |
387 |
|
387 | |||
388 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
388 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
389 |
|
389 | |||
390 | return colorAt(prev.second, next.second, relativePos); |
|
390 | return colorAt(prev.second, next.second, relativePos); | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | QTCOMMERCIALCHART_END_NAMESPACE |
|
393 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now