@@ -1,331 +1,332 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE:BSD$ |
|
9 | ** $QT_BEGIN_LICENSE:BSD$ | |
10 | ** You may use this file under the terms of the BSD license as follows: |
|
10 | ** You may use this file under the terms of the BSD license as follows: | |
11 | ** |
|
11 | ** | |
12 | ** "Redistribution and use in source and binary forms, with or without |
|
12 | ** "Redistribution and use in source and binary forms, with or without | |
13 | ** modification, are permitted provided that the following conditions are |
|
13 | ** modification, are permitted provided that the following conditions are | |
14 | ** met: |
|
14 | ** met: | |
15 | ** * Redistributions of source code must retain the above copyright |
|
15 | ** * Redistributions of source code must retain the above copyright | |
16 | ** notice, this list of conditions and the following disclaimer. |
|
16 | ** notice, this list of conditions and the following disclaimer. | |
17 | ** * Redistributions in binary form must reproduce the above copyright |
|
17 | ** * Redistributions in binary form must reproduce the above copyright | |
18 | ** notice, this list of conditions and the following disclaimer in |
|
18 | ** notice, this list of conditions and the following disclaimer in | |
19 | ** the documentation and/or other materials provided with the |
|
19 | ** the documentation and/or other materials provided with the | |
20 | ** distribution. |
|
20 | ** distribution. | |
21 | ** * Neither the name of Digia nor the names of its contributors |
|
21 | ** * Neither the name of Digia nor the names of its contributors | |
22 | ** may be used to endorse or promote products derived from this |
|
22 | ** may be used to endorse or promote products derived from this | |
23 | ** software without specific prior written permission. |
|
23 | ** software without specific prior written permission. | |
24 | ** |
|
24 | ** | |
25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
25 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
26 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
27 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
28 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
29 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
30 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
31 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
32 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
33 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
34 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
|
35 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | |
36 | ** $QT_END_LICENSE$ |
|
36 | ** $QT_END_LICENSE$ | |
37 | ** |
|
37 | ** | |
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). |
|
38 | ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies). | |
39 | ** |
|
39 | ** | |
40 | ****************************************************************************/ |
|
40 | ****************************************************************************/ | |
41 |
|
41 | |||
42 | #include "themewidget.h" |
|
42 | #include "themewidget.h" | |
43 |
|
43 | |||
44 | #include <QChartView> |
|
44 | #include <QChartView> | |
45 | #include <QPieSeries> |
|
45 | #include <QPieSeries> | |
46 | #include <QPieSlice> |
|
46 | #include <QPieSlice> | |
47 | #include <QBarSeries> |
|
47 | #include <QBarSeries> | |
48 | #include <QPercentBarSeries> |
|
48 | #include <QPercentBarSeries> | |
49 | #include <QStackedBarSeries> |
|
49 | #include <QStackedBarSeries> | |
50 | #include <QBarSet> |
|
50 | #include <QBarSet> | |
51 | #include <QLineSeries> |
|
51 | #include <QLineSeries> | |
52 | #include <QSplineSeries> |
|
52 | #include <QSplineSeries> | |
53 | #include <QScatterSeries> |
|
53 | #include <QScatterSeries> | |
54 | #include <QAreaSeries> |
|
54 | #include <QAreaSeries> | |
55 | #include <QGridLayout> |
|
55 | #include <QGridLayout> | |
56 | #include <QFormLayout> |
|
56 | #include <QFormLayout> | |
57 | #include <QComboBox> |
|
57 | #include <QComboBox> | |
58 | #include <QSpinBox> |
|
58 | #include <QSpinBox> | |
59 | #include <QCheckBox> |
|
59 | #include <QCheckBox> | |
60 | #include <QGroupBox> |
|
60 | #include <QGroupBox> | |
61 | #include <QLabel> |
|
61 | #include <QLabel> | |
62 | #include <QTime> |
|
62 | #include <QTime> | |
63 |
|
63 | |||
64 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
64 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
65 | QWidget(parent), |
|
65 | QWidget(parent), | |
66 | m_listCount(3), |
|
66 | m_listCount(3), | |
67 | m_valueMax(100), |
|
67 | m_valueMax(100), | |
68 | m_valueCount(11), |
|
68 | m_valueCount(11), | |
69 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
69 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
70 | m_themeComboBox(createThemeBox()), |
|
70 | m_themeComboBox(createThemeBox()), | |
71 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), |
|
71 | m_antialiasCheckBox(new QCheckBox("Anti aliasing")), | |
72 | m_animatedComboBox(createAnimationBox()) |
|
72 | m_animatedComboBox(createAnimationBox()) | |
73 | { |
|
73 | { | |
74 |
|
74 | |||
75 | connectSignals(); |
|
75 | connectSignals(); | |
76 | // create layout |
|
76 | // create layout | |
77 | QGridLayout* baseLayout = new QGridLayout(); |
|
77 | QGridLayout* baseLayout = new QGridLayout(); | |
78 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
78 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
79 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
79 | settingsLayout->addWidget(new QLabel("Theme:")); | |
80 | settingsLayout->addWidget(m_themeComboBox); |
|
80 | settingsLayout->addWidget(m_themeComboBox); | |
81 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
81 | settingsLayout->addWidget(new QLabel("Animation:")); | |
82 | settingsLayout->addWidget(m_animatedComboBox); |
|
82 | settingsLayout->addWidget(m_animatedComboBox); | |
83 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
83 | settingsLayout->addWidget(m_antialiasCheckBox); | |
84 | settingsLayout->addStretch(); |
|
84 | settingsLayout->addStretch(); | |
85 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
85 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
86 |
|
86 | |||
87 | //create charts |
|
87 | //create charts | |
88 |
|
88 | |||
89 | QChartView *chartView; |
|
89 | QChartView *chartView; | |
90 |
|
90 | |||
91 | chartView = new QChartView(createAreaChart()); |
|
91 | chartView = new QChartView(createAreaChart()); | |
92 | baseLayout->addWidget(chartView, 1, 0); |
|
92 | baseLayout->addWidget(chartView, 1, 0); | |
93 | m_charts << chartView; |
|
93 | m_charts << chartView; | |
94 |
|
94 | |||
95 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
95 | chartView = new QChartView(createBarChart(m_valueCount)); | |
96 | baseLayout->addWidget(chartView, 1, 1); |
|
96 | baseLayout->addWidget(chartView, 1, 1); | |
97 | m_charts << chartView; |
|
97 | m_charts << chartView; | |
98 |
|
98 | |||
99 | chartView = new QChartView(createLineChart()); |
|
99 | chartView = new QChartView(createLineChart()); | |
100 | baseLayout->addWidget(chartView, 1, 2); |
|
100 | baseLayout->addWidget(chartView, 1, 2); | |
101 | m_charts << chartView; |
|
101 | m_charts << chartView; | |
102 |
|
102 | |||
103 | chartView = new QChartView(createPieChart()); |
|
103 | chartView = new QChartView(createPieChart()); | |
104 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
104 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
105 | baseLayout->addWidget(chartView, 2, 0); |
|
105 | baseLayout->addWidget(chartView, 2, 0); | |
106 | m_charts << chartView; |
|
106 | m_charts << chartView; | |
107 |
|
107 | |||
108 | chartView = new QChartView(createSplineChart()); |
|
108 | chartView = new QChartView(createSplineChart()); | |
109 | baseLayout->addWidget(chartView, 2, 1); |
|
109 | baseLayout->addWidget(chartView, 2, 1); | |
110 | m_charts << chartView; |
|
110 | m_charts << chartView; | |
111 |
|
111 | |||
112 | chartView = new QChartView(createScatterChart()); |
|
112 | chartView = new QChartView(createScatterChart()); | |
113 | baseLayout->addWidget(chartView, 2, 2); |
|
113 | baseLayout->addWidget(chartView, 2, 2); | |
114 | m_charts << chartView; |
|
114 | m_charts << chartView; | |
115 |
|
115 | |||
116 | setLayout(baseLayout); |
|
116 | setLayout(baseLayout); | |
117 | } |
|
117 | } | |
118 |
|
118 | |||
119 | ThemeWidget::~ThemeWidget() |
|
119 | ThemeWidget::~ThemeWidget() | |
120 | { |
|
120 | { | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void ThemeWidget::connectSignals() |
|
123 | void ThemeWidget::connectSignals() | |
124 | { |
|
124 | { | |
125 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
125 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
126 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
126 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
127 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
127 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
130 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
131 | { |
|
131 | { | |
132 | DataTable dataTable; |
|
132 | DataTable dataTable; | |
133 |
|
133 | |||
134 | // set seed for random stuff |
|
134 | // set seed for random stuff | |
135 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
135 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
136 |
|
136 | |||
137 | // generate random data |
|
137 | // generate random data | |
138 | for (int i(0); i < listCount; i++) { |
|
138 | for (int i(0); i < listCount; i++) { | |
139 | DataList dataList; |
|
139 | DataList dataList; | |
140 | for (int j(0); j < valueCount; j++) { |
|
140 | for (int j(0); j < valueCount; j++) { | |
141 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); |
|
141 | QPointF value(j + (qreal) rand() / (qreal) RAND_MAX, qrand() % valueMax); | |
142 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); |
|
142 | QString label = "Item " + QString::number(i) + ":" + QString::number(j); | |
143 | dataList << Data(value, label); |
|
143 | dataList << Data(value, label); | |
144 | } |
|
144 | } | |
145 | dataTable << dataList; |
|
145 | dataTable << dataList; | |
146 | } |
|
146 | } | |
147 |
|
147 | |||
148 | return dataTable; |
|
148 | return dataTable; | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | QComboBox* ThemeWidget::createThemeBox() const |
|
151 | QComboBox* ThemeWidget::createThemeBox() const | |
152 | { |
|
152 | { | |
153 | // settings layout |
|
153 | // settings layout | |
154 | QComboBox* themeComboBox = new QComboBox(); |
|
154 | QComboBox* themeComboBox = new QComboBox(); | |
155 | themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
155 | themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
156 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
156 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
157 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
157 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
158 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
158 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
159 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
159 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
160 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
160 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
161 |
themeComboBox->addItem(" |
|
161 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
162 |
themeComboBox->addItem(" |
|
162 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
163 | return themeComboBox; |
|
163 | return themeComboBox; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QComboBox* ThemeWidget::createAnimationBox() const |
|
166 | QComboBox* ThemeWidget::createAnimationBox() const | |
167 | { |
|
167 | { | |
168 | // settings layout |
|
168 | // settings layout | |
169 | QComboBox* animationComboBox = new QComboBox(); |
|
169 | QComboBox* animationComboBox = new QComboBox(); | |
170 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
170 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
171 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
171 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
172 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
172 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
173 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
173 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
174 | return animationComboBox; |
|
174 | return animationComboBox; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QChart* ThemeWidget::createAreaChart() const |
|
177 | QChart* ThemeWidget::createAreaChart() const | |
178 | { |
|
178 | { | |
179 | // area chart |
|
179 | // area chart | |
180 | QChart *chart = new QChart(); |
|
180 | QChart *chart = new QChart(); | |
181 | chart->setTitle("Area chart"); |
|
181 | chart->setTitle("Area chart"); | |
182 | { |
|
182 | { | |
183 | for (int i(0); i < m_dataTable.count(); i++) { |
|
183 | for (int i(0); i < m_dataTable.count(); i++) { | |
184 | QLineSeries *series1 = new QLineSeries(chart); |
|
184 | QLineSeries *series1 = new QLineSeries(chart); | |
185 | QLineSeries *series2 = new QLineSeries(chart); |
|
185 | QLineSeries *series2 = new QLineSeries(chart); | |
186 | foreach (Data data, m_dataTable[i]) { |
|
186 | foreach (Data data, m_dataTable[i]) { | |
187 | series1->add(data.first); |
|
187 | series1->add(data.first); | |
188 | series2->add(QPointF(data.first.x(), 0.0)); |
|
188 | series2->add(QPointF(data.first.x(), 0.0)); | |
189 | } |
|
189 | } | |
190 | QAreaSeries *area = new QAreaSeries(series1, series2); |
|
190 | QAreaSeries *area = new QAreaSeries(series1, series2); | |
191 | chart->addSeries(area); |
|
191 | chart->addSeries(area); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 | return chart; |
|
194 | return chart; | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
197 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
198 | { |
|
198 | { | |
199 | // bar chart |
|
199 | // bar chart | |
200 | QChart* chart = new QChart(); |
|
200 | QChart* chart = new QChart(); | |
201 | chart->setTitle("Bar chart"); |
|
201 | chart->setTitle("Bar chart"); | |
202 | { |
|
202 | { | |
203 | QBarCategories categories; |
|
203 | QBarCategories categories; | |
204 | // TODO: categories |
|
204 | // TODO: categories | |
205 | for (int i(0); i < valueCount; i++) |
|
205 | for (int i(0); i < valueCount; i++) | |
206 | categories << QString::number(i); |
|
206 | categories << QString::number(i); | |
207 | // QBarSeries* series = new QBarSeries(categories, chart); |
|
207 | // QBarSeries* series = new QBarSeries(categories, chart); | |
208 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); |
|
208 | // QPercentBarSeries* series = new QPercentBarSeries(categories, chart); | |
209 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); |
|
209 | QStackedBarSeries* series = new QStackedBarSeries(categories, chart); | |
210 | for (int i(0); i < m_dataTable.count(); i++) { |
|
210 | for (int i(0); i < m_dataTable.count(); i++) { | |
211 | QBarSet *set = new QBarSet("Set" + QString::number(i)); |
|
211 | QBarSet *set = new QBarSet("Set" + QString::number(i)); | |
212 | foreach (Data data, m_dataTable[i]) |
|
212 | foreach (Data data, m_dataTable[i]) | |
213 | *set << data.first.y(); |
|
213 | *set << data.first.y(); | |
214 | series->addBarSet(set); |
|
214 | series->addBarSet(set); | |
215 | } |
|
215 | } | |
216 | chart->addSeries(series); |
|
216 | chart->addSeries(series); | |
217 | } |
|
217 | } | |
218 | return chart; |
|
218 | return chart; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | QChart* ThemeWidget::createLineChart() const |
|
221 | QChart* ThemeWidget::createLineChart() const | |
222 | { |
|
222 | { | |
223 | // line chart |
|
223 | // line chart | |
224 | QChart* chart = new QChart(); |
|
224 | QChart* chart = new QChart(); | |
225 | chart->setTitle("Line chart"); |
|
225 | chart->setTitle("Line chart"); | |
226 | foreach (DataList list, m_dataTable) { |
|
226 | foreach (DataList list, m_dataTable) { | |
227 | QLineSeries *series = new QLineSeries(chart); |
|
227 | QLineSeries *series = new QLineSeries(chart); | |
228 | foreach (Data data, list) |
|
228 | foreach (Data data, list) | |
229 | series->add(data.first); |
|
229 | series->add(data.first); | |
230 | chart->addSeries(series); |
|
230 | chart->addSeries(series); | |
231 | } |
|
231 | } | |
232 | return chart; |
|
232 | return chart; | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | QChart* ThemeWidget::createPieChart() const |
|
235 | QChart* ThemeWidget::createPieChart() const | |
236 | { |
|
236 | { | |
237 | // pie chart |
|
237 | // pie chart | |
238 | QChart* chart = new QChart(); |
|
238 | QChart* chart = new QChart(); | |
239 | chart->setTitle("Pie chart"); |
|
239 | chart->setTitle("Pie chart"); | |
240 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
240 | qreal pieSize = 1.0 / m_dataTable.count(); | |
241 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
241 | for (int i = 0; i < m_dataTable.count(); i++) { | |
242 | QPieSeries *series = new QPieSeries(chart); |
|
242 | QPieSeries *series = new QPieSeries(chart); | |
243 | foreach (Data data, m_dataTable[i]) { |
|
243 | foreach (Data data, m_dataTable[i]) { | |
244 | QPieSlice *slice = series->add(data.first.y(), data.second); |
|
244 | QPieSlice *slice = series->add(data.first.y(), data.second); | |
245 | if (data == m_dataTable[i].first()) { |
|
245 | if (data == m_dataTable[i].first()) { | |
246 | slice->setLabelVisible(); |
|
246 | slice->setLabelVisible(); | |
247 | slice->setExploded(); |
|
247 | slice->setExploded(); | |
248 | } |
|
248 | } | |
249 | } |
|
249 | } | |
250 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
250 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
251 | series->setPieSize(pieSize); |
|
251 | series->setPieSize(pieSize); | |
252 | series->setPiePosition(hPos, 0.5); |
|
252 | series->setPiePosition(hPos, 0.5); | |
253 | chart->addSeries(series); |
|
253 | chart->addSeries(series); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | return chart; |
|
256 | return chart; | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | QChart* ThemeWidget::createSplineChart() const |
|
259 | QChart* ThemeWidget::createSplineChart() const | |
260 | { // spine chart |
|
260 | { // spine chart | |
261 | QChart* chart = new QChart(); |
|
261 | QChart* chart = new QChart(); | |
262 | chart->setTitle("Spline chart"); |
|
262 | chart->setTitle("Spline chart"); | |
263 | foreach (DataList list, m_dataTable) { |
|
263 | foreach (DataList list, m_dataTable) { | |
264 | QSplineSeries *series = new QSplineSeries(chart); |
|
264 | QSplineSeries *series = new QSplineSeries(chart); | |
265 | foreach (Data data, list) |
|
265 | foreach (Data data, list) | |
266 | series->add(data.first); |
|
266 | series->add(data.first); | |
267 | chart->addSeries(series); |
|
267 | chart->addSeries(series); | |
268 | } |
|
268 | } | |
269 | return chart; |
|
269 | return chart; | |
270 | } |
|
270 | } | |
271 |
|
271 | |||
272 | QChart* ThemeWidget::createScatterChart() const |
|
272 | QChart* ThemeWidget::createScatterChart() const | |
273 | { // scatter chart |
|
273 | { // scatter chart | |
274 | QChart* chart = new QChart(); |
|
274 | QChart* chart = new QChart(); | |
275 | chart->setTitle("Scatter chart"); |
|
275 | chart->setTitle("Scatter chart"); | |
276 | foreach (DataList list, m_dataTable) { |
|
276 | foreach (DataList list, m_dataTable) { | |
277 | QScatterSeries *series = new QScatterSeries(chart); |
|
277 | QScatterSeries *series = new QScatterSeries(chart); | |
278 | foreach (Data data, list) |
|
278 | foreach (Data data, list) | |
279 | series->add(data.first); |
|
279 | series->add(data.first); | |
280 | chart->addSeries(series); |
|
280 | chart->addSeries(series); | |
281 | } |
|
281 | } | |
282 | return chart; |
|
282 | return chart; | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | void ThemeWidget::updateUI() |
|
285 | void ThemeWidget::updateUI() | |
286 | { |
|
286 | { | |
287 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
287 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
288 |
|
288 | |||
289 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
289 | if (m_charts.at(0)->chart()->theme() != theme) { | |
290 | foreach (QChartView *chartView, m_charts) |
|
290 | foreach (QChartView *chartView, m_charts) | |
291 | chartView->chart()->setTheme(theme); |
|
291 | chartView->chart()->setTheme(theme); | |
292 |
|
292 | |||
293 | QPalette pal = window()->palette(); |
|
293 | QPalette pal = window()->palette(); | |
294 | if (theme == QChart::ChartThemeLight) { |
|
294 | if (theme == QChart::ChartThemeLight) { | |
295 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
295 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
296 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
296 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
297 | } |
|
297 | } else if (theme == QChart::ChartThemeDark) { | |
298 | else if (theme == QChart::ChartThemeDark) { |
|
|||
299 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
298 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
300 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
299 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
301 | } |
|
300 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
302 | else if (theme == QChart::ChartThemeBlueCerulean) { |
|
|||
303 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
301 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
304 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
302 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
305 | } |
|
303 | } else if (theme == QChart::ChartThemeBrownSand) { | |
306 | else if (theme == QChart::ChartThemeBrownSand) { |
|
|||
307 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
304 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
308 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
305 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
309 | } |
|
306 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
310 | else if (theme == QChart::ChartThemeBlueNcs) { |
|
|||
311 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
307 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
312 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
308 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
313 | } |
|
309 | } else if (theme == QChart::ChartThemeHighContrast) { | |
314 | else { |
|
310 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
|
311 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |||
|
312 | } else if (theme == QChart::ChartThemeBlueIcy) { | |||
|
313 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |||
|
314 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |||
|
315 | } else { | |||
315 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
316 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
316 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
317 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
317 | } |
|
318 | } | |
318 | window()->setPalette(pal); |
|
319 | window()->setPalette(pal); | |
319 | } |
|
320 | } | |
320 |
|
321 | |||
321 | bool checked = m_antialiasCheckBox->isChecked(); |
|
322 | bool checked = m_antialiasCheckBox->isChecked(); | |
322 | foreach (QChartView *chart, m_charts) |
|
323 | foreach (QChartView *chart, m_charts) | |
323 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
324 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
324 |
|
325 | |||
325 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
326 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
326 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
327 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
327 | foreach (QChartView *chartView, m_charts) |
|
328 | foreach (QChartView *chartView, m_charts) | |
328 | chartView->chart()->setAnimationOptions(options); |
|
329 | chartView->chart()->setAnimationOptions(options); | |
329 | } |
|
330 | } | |
330 | } |
|
331 | } | |
331 |
|
332 |
@@ -1,611 +1,611 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qpieseries.h> |
|
5 | #include <qpieseries.h> | |
6 | #include <qpieslice.h> |
|
6 | #include <qpieslice.h> | |
7 | #include <QGridLayout> |
|
7 | #include <QGridLayout> | |
8 | #include <QFormLayout> |
|
8 | #include <QFormLayout> | |
9 | #include <QComboBox> |
|
9 | #include <QComboBox> | |
10 | #include <QSpinBox> |
|
10 | #include <QSpinBox> | |
11 | #include <QCheckBox> |
|
11 | #include <QCheckBox> | |
12 | #include <QGroupBox> |
|
12 | #include <QGroupBox> | |
13 | #include <QLabel> |
|
13 | #include <QLabel> | |
14 | #include <QPushButton> |
|
14 | #include <QPushButton> | |
15 | #include <QColorDialog> |
|
15 | #include <QColorDialog> | |
16 | #include <QFontDialog> |
|
16 | #include <QFontDialog> | |
17 |
|
17 | |||
18 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
18 | QTCOMMERCIALCHART_USE_NAMESPACE | |
19 |
|
19 | |||
20 | class PenTool : public QWidget |
|
20 | class PenTool : public QWidget | |
21 | { |
|
21 | { | |
22 | Q_OBJECT |
|
22 | Q_OBJECT | |
23 |
|
23 | |||
24 | public: |
|
24 | public: | |
25 | explicit PenTool(QString title, QWidget *parent = 0) |
|
25 | explicit PenTool(QString title, QWidget *parent = 0) | |
26 | :QWidget(parent) |
|
26 | :QWidget(parent) | |
27 | { |
|
27 | { | |
28 | setWindowTitle(title); |
|
28 | setWindowTitle(title); | |
29 | setWindowFlags(Qt::Tool); |
|
29 | setWindowFlags(Qt::Tool); | |
30 |
|
30 | |||
31 | m_colorButton = new QPushButton(); |
|
31 | m_colorButton = new QPushButton(); | |
32 |
|
32 | |||
33 | m_widthSpinBox = new QDoubleSpinBox(); |
|
33 | m_widthSpinBox = new QDoubleSpinBox(); | |
34 |
|
34 | |||
35 | m_styleCombo = new QComboBox(); |
|
35 | m_styleCombo = new QComboBox(); | |
36 | m_styleCombo->addItem("NoPen"); |
|
36 | m_styleCombo->addItem("NoPen"); | |
37 | m_styleCombo->addItem("SolidLine"); |
|
37 | m_styleCombo->addItem("SolidLine"); | |
38 | m_styleCombo->addItem("DashLine"); |
|
38 | m_styleCombo->addItem("DashLine"); | |
39 | m_styleCombo->addItem("DotLine"); |
|
39 | m_styleCombo->addItem("DotLine"); | |
40 | m_styleCombo->addItem("DashDotLine"); |
|
40 | m_styleCombo->addItem("DashDotLine"); | |
41 | m_styleCombo->addItem("DashDotDotLine"); |
|
41 | m_styleCombo->addItem("DashDotDotLine"); | |
42 |
|
42 | |||
43 | m_capStyleCombo = new QComboBox(); |
|
43 | m_capStyleCombo = new QComboBox(); | |
44 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); |
|
44 | m_capStyleCombo->addItem("FlatCap", Qt::FlatCap); | |
45 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); |
|
45 | m_capStyleCombo->addItem("SquareCap", Qt::SquareCap); | |
46 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); |
|
46 | m_capStyleCombo->addItem("RoundCap", Qt::RoundCap); | |
47 |
|
47 | |||
48 | m_joinStyleCombo = new QComboBox(); |
|
48 | m_joinStyleCombo = new QComboBox(); | |
49 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); |
|
49 | m_joinStyleCombo->addItem("MiterJoin", Qt::MiterJoin); | |
50 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); |
|
50 | m_joinStyleCombo->addItem("BevelJoin", Qt::BevelJoin); | |
51 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); |
|
51 | m_joinStyleCombo->addItem("RoundJoin", Qt::RoundJoin); | |
52 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); |
|
52 | m_joinStyleCombo->addItem("SvgMiterJoin", Qt::SvgMiterJoin); | |
53 |
|
53 | |||
54 | QFormLayout *layout = new QFormLayout(); |
|
54 | QFormLayout *layout = new QFormLayout(); | |
55 | layout->addRow("Color", m_colorButton); |
|
55 | layout->addRow("Color", m_colorButton); | |
56 | layout->addRow("Width", m_widthSpinBox); |
|
56 | layout->addRow("Width", m_widthSpinBox); | |
57 | layout->addRow("Style", m_styleCombo); |
|
57 | layout->addRow("Style", m_styleCombo); | |
58 | layout->addRow("Cap style", m_capStyleCombo); |
|
58 | layout->addRow("Cap style", m_capStyleCombo); | |
59 | layout->addRow("Join style", m_joinStyleCombo); |
|
59 | layout->addRow("Join style", m_joinStyleCombo); | |
60 | setLayout(layout); |
|
60 | setLayout(layout); | |
61 |
|
61 | |||
62 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); |
|
62 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | |
63 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); |
|
63 | connect(m_widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(updateWidth(double))); | |
64 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); |
|
64 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle(int))); | |
65 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); |
|
65 | connect(m_capStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateCapStyle(int))); | |
66 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); |
|
66 | connect(m_joinStyleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateJoinStyle(int))); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void setPen(QPen pen) |
|
69 | void setPen(QPen pen) | |
70 | { |
|
70 | { | |
71 | m_pen = pen; |
|
71 | m_pen = pen; | |
72 | m_colorButton->setText(m_pen.color().name()); |
|
72 | m_colorButton->setText(m_pen.color().name()); | |
73 | m_widthSpinBox->setValue(m_pen.widthF()); |
|
73 | m_widthSpinBox->setValue(m_pen.widthF()); | |
74 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum |
|
74 | m_styleCombo->setCurrentIndex(m_pen.style()); // index matches the enum | |
75 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); |
|
75 | m_capStyleCombo->setCurrentIndex(m_capStyleCombo->findData(m_pen.capStyle())); | |
76 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); |
|
76 | m_joinStyleCombo->setCurrentIndex(m_joinStyleCombo->findData(m_pen.joinStyle())); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | QPen pen() const |
|
79 | QPen pen() const | |
80 | { |
|
80 | { | |
81 | return m_pen; |
|
81 | return m_pen; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | QString name() |
|
84 | QString name() | |
85 | { |
|
85 | { | |
86 | return name(m_pen); |
|
86 | return name(m_pen); | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | static QString name(const QPen &pen) |
|
89 | static QString name(const QPen &pen) | |
90 | { |
|
90 | { | |
91 | return pen.color().name() + ":" + QString::number(pen.widthF()); |
|
91 | return pen.color().name() + ":" + QString::number(pen.widthF()); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | Q_SIGNALS: |
|
94 | Q_SIGNALS: | |
95 | void changed(); |
|
95 | void changed(); | |
96 |
|
96 | |||
97 | public Q_SLOTS: |
|
97 | public Q_SLOTS: | |
98 |
|
98 | |||
99 | void showColorDialog() |
|
99 | void showColorDialog() | |
100 | { |
|
100 | { | |
101 | QColorDialog dialog(m_pen.color()); |
|
101 | QColorDialog dialog(m_pen.color()); | |
102 | dialog.show(); |
|
102 | dialog.show(); | |
103 | dialog.exec(); |
|
103 | dialog.exec(); | |
104 | m_pen.setColor(dialog.selectedColor()); |
|
104 | m_pen.setColor(dialog.selectedColor()); | |
105 | m_colorButton->setText(m_pen.color().name()); |
|
105 | m_colorButton->setText(m_pen.color().name()); | |
106 | emit changed(); |
|
106 | emit changed(); | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void updateWidth(double width) |
|
109 | void updateWidth(double width) | |
110 | { |
|
110 | { | |
111 | if (width != m_pen.widthF()) { |
|
111 | if (width != m_pen.widthF()) { | |
112 | m_pen.setWidthF(width); |
|
112 | m_pen.setWidthF(width); | |
113 | emit changed(); |
|
113 | emit changed(); | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void updateStyle(int style) |
|
117 | void updateStyle(int style) | |
118 | { |
|
118 | { | |
119 | if (m_pen.style() != style) { |
|
119 | if (m_pen.style() != style) { | |
120 | m_pen.setStyle((Qt::PenStyle) style); |
|
120 | m_pen.setStyle((Qt::PenStyle) style); | |
121 | emit changed(); |
|
121 | emit changed(); | |
122 | } |
|
122 | } | |
123 | } |
|
123 | } | |
124 |
|
124 | |||
125 | void updateCapStyle(int index) |
|
125 | void updateCapStyle(int index) | |
126 | { |
|
126 | { | |
127 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); |
|
127 | Qt::PenCapStyle capStyle = (Qt::PenCapStyle) m_capStyleCombo->itemData(index).toInt(); | |
128 | if (m_pen.capStyle() != capStyle) { |
|
128 | if (m_pen.capStyle() != capStyle) { | |
129 | m_pen.setCapStyle(capStyle); |
|
129 | m_pen.setCapStyle(capStyle); | |
130 | emit changed(); |
|
130 | emit changed(); | |
131 | } |
|
131 | } | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void updateJoinStyle(int index) |
|
134 | void updateJoinStyle(int index) | |
135 | { |
|
135 | { | |
136 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); |
|
136 | Qt::PenJoinStyle joinStyle = (Qt::PenJoinStyle) m_joinStyleCombo->itemData(index).toInt(); | |
137 | if (m_pen.joinStyle() != joinStyle) { |
|
137 | if (m_pen.joinStyle() != joinStyle) { | |
138 | m_pen.setJoinStyle(joinStyle); |
|
138 | m_pen.setJoinStyle(joinStyle); | |
139 | emit changed(); |
|
139 | emit changed(); | |
140 | } |
|
140 | } | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | private: |
|
143 | private: | |
144 | QPen m_pen; |
|
144 | QPen m_pen; | |
145 | QPushButton *m_colorButton; |
|
145 | QPushButton *m_colorButton; | |
146 | QDoubleSpinBox *m_widthSpinBox; |
|
146 | QDoubleSpinBox *m_widthSpinBox; | |
147 | QComboBox *m_styleCombo; |
|
147 | QComboBox *m_styleCombo; | |
148 | QComboBox *m_capStyleCombo; |
|
148 | QComboBox *m_capStyleCombo; | |
149 | QComboBox *m_joinStyleCombo; |
|
149 | QComboBox *m_joinStyleCombo; | |
150 | }; |
|
150 | }; | |
151 |
|
151 | |||
152 | class BrushTool : public QWidget |
|
152 | class BrushTool : public QWidget | |
153 | { |
|
153 | { | |
154 | Q_OBJECT |
|
154 | Q_OBJECT | |
155 |
|
155 | |||
156 | public: |
|
156 | public: | |
157 | explicit BrushTool(QString title, QWidget *parent = 0) |
|
157 | explicit BrushTool(QString title, QWidget *parent = 0) | |
158 | :QWidget(parent) |
|
158 | :QWidget(parent) | |
159 | { |
|
159 | { | |
160 | setWindowTitle(title); |
|
160 | setWindowTitle(title); | |
161 | setWindowFlags(Qt::Tool); |
|
161 | setWindowFlags(Qt::Tool); | |
162 |
|
162 | |||
163 | m_colorButton = new QPushButton(); |
|
163 | m_colorButton = new QPushButton(); | |
164 | m_styleCombo = new QComboBox(); |
|
164 | m_styleCombo = new QComboBox(); | |
165 | m_styleCombo->addItem("Nobrush", Qt::NoBrush); |
|
165 | m_styleCombo->addItem("Nobrush", Qt::NoBrush); | |
166 | m_styleCombo->addItem("Solidpattern", Qt::SolidPattern); |
|
166 | m_styleCombo->addItem("Solidpattern", Qt::SolidPattern); | |
167 | m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern); |
|
167 | m_styleCombo->addItem("Dense1pattern", Qt::Dense1Pattern); | |
168 | m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern); |
|
168 | m_styleCombo->addItem("Dense2attern", Qt::Dense2Pattern); | |
169 | m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern); |
|
169 | m_styleCombo->addItem("Dense3Pattern", Qt::Dense3Pattern); | |
170 | m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern); |
|
170 | m_styleCombo->addItem("Dense4Pattern", Qt::Dense4Pattern); | |
171 | m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern); |
|
171 | m_styleCombo->addItem("Dense5Pattern", Qt::Dense5Pattern); | |
172 | m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern); |
|
172 | m_styleCombo->addItem("Dense6Pattern", Qt::Dense6Pattern); | |
173 | m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern); |
|
173 | m_styleCombo->addItem("Dense7Pattern", Qt::Dense7Pattern); | |
174 | m_styleCombo->addItem("HorPattern", Qt::HorPattern); |
|
174 | m_styleCombo->addItem("HorPattern", Qt::HorPattern); | |
175 | m_styleCombo->addItem("VerPattern", Qt::VerPattern); |
|
175 | m_styleCombo->addItem("VerPattern", Qt::VerPattern); | |
176 | m_styleCombo->addItem("CrossPattern", Qt::CrossPattern); |
|
176 | m_styleCombo->addItem("CrossPattern", Qt::CrossPattern); | |
177 | m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern); |
|
177 | m_styleCombo->addItem("BDiagPattern", Qt::BDiagPattern); | |
178 | m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern); |
|
178 | m_styleCombo->addItem("FDiagPattern", Qt::FDiagPattern); | |
179 | m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern); |
|
179 | m_styleCombo->addItem("DiagCrossPattern", Qt::DiagCrossPattern); | |
180 |
|
180 | |||
181 | QFormLayout *layout = new QFormLayout(); |
|
181 | QFormLayout *layout = new QFormLayout(); | |
182 | layout->addRow("Color", m_colorButton); |
|
182 | layout->addRow("Color", m_colorButton); | |
183 | layout->addRow("Style", m_styleCombo); |
|
183 | layout->addRow("Style", m_styleCombo); | |
184 | setLayout(layout); |
|
184 | setLayout(layout); | |
185 |
|
185 | |||
186 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); |
|
186 | connect(m_colorButton, SIGNAL(clicked()), this, SLOT(showColorDialog())); | |
187 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); |
|
187 | connect(m_styleCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateStyle())); | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void setBrush(QBrush brush) |
|
190 | void setBrush(QBrush brush) | |
191 | { |
|
191 | { | |
192 | m_brush = brush; |
|
192 | m_brush = brush; | |
193 | m_colorButton->setText(m_brush.color().name()); |
|
193 | m_colorButton->setText(m_brush.color().name()); | |
194 | m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum |
|
194 | m_styleCombo->setCurrentIndex(m_brush.style()); // index matches the enum | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QBrush brush() const |
|
197 | QBrush brush() const | |
198 | { |
|
198 | { | |
199 | return m_brush; |
|
199 | return m_brush; | |
200 | } |
|
200 | } | |
201 |
|
201 | |||
202 | QString name() |
|
202 | QString name() | |
203 | { |
|
203 | { | |
204 | return name(m_brush); |
|
204 | return name(m_brush); | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | static QString name(const QBrush &brush) |
|
207 | static QString name(const QBrush &brush) | |
208 | { |
|
208 | { | |
209 | return brush.color().name(); |
|
209 | return brush.color().name(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | Q_SIGNALS: |
|
212 | Q_SIGNALS: | |
213 | void changed(); |
|
213 | void changed(); | |
214 |
|
214 | |||
215 | public Q_SLOTS: |
|
215 | public Q_SLOTS: | |
216 |
|
216 | |||
217 | void showColorDialog() |
|
217 | void showColorDialog() | |
218 | { |
|
218 | { | |
219 | QColorDialog dialog(m_brush.color()); |
|
219 | QColorDialog dialog(m_brush.color()); | |
220 | dialog.show(); |
|
220 | dialog.show(); | |
221 | dialog.exec(); |
|
221 | dialog.exec(); | |
222 | m_brush.setColor(dialog.selectedColor()); |
|
222 | m_brush.setColor(dialog.selectedColor()); | |
223 | m_colorButton->setText(m_brush.color().name()); |
|
223 | m_colorButton->setText(m_brush.color().name()); | |
224 | emit changed(); |
|
224 | emit changed(); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | void updateStyle() |
|
227 | void updateStyle() | |
228 | { |
|
228 | { | |
229 | Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); |
|
229 | Qt::BrushStyle style = (Qt::BrushStyle) m_styleCombo->itemData(m_styleCombo->currentIndex()).toInt(); | |
230 | if (m_brush.style() != style) { |
|
230 | if (m_brush.style() != style) { | |
231 | m_brush.setStyle(style); |
|
231 | m_brush.setStyle(style); | |
232 | emit changed(); |
|
232 | emit changed(); | |
233 | } |
|
233 | } | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | private: |
|
236 | private: | |
237 | QBrush m_brush; |
|
237 | QBrush m_brush; | |
238 | QPushButton *m_colorButton; |
|
238 | QPushButton *m_colorButton; | |
239 | QComboBox *m_styleCombo; |
|
239 | QComboBox *m_styleCombo; | |
240 | }; |
|
240 | }; | |
241 |
|
241 | |||
242 | class CustomSlice : public QPieSlice |
|
242 | class CustomSlice : public QPieSlice | |
243 | { |
|
243 | { | |
244 | Q_OBJECT |
|
244 | Q_OBJECT | |
245 | public: |
|
245 | public: | |
246 | CustomSlice(qreal value, QString label) |
|
246 | CustomSlice(qreal value, QString label) | |
247 | :QPieSlice(value, label) |
|
247 | :QPieSlice(value, label) | |
248 | { |
|
248 | { | |
249 | connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter())); |
|
249 | connect(this, SIGNAL(hoverEnter()), this, SLOT(handleHoverEnter())); | |
250 | connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave())); |
|
250 | connect(this, SIGNAL(hoverLeave()), this, SLOT(handleHoverLeave())); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | public: |
|
253 | public: | |
254 | QBrush originalBrush() |
|
254 | QBrush originalBrush() | |
255 | { |
|
255 | { | |
256 | return m_originalBrush; |
|
256 | return m_originalBrush; | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | public Q_SLOTS: |
|
259 | public Q_SLOTS: | |
260 |
|
260 | |||
261 | void handleHoverEnter() |
|
261 | void handleHoverEnter() | |
262 | { |
|
262 | { | |
263 | QBrush brush = this->brush(); |
|
263 | QBrush brush = this->brush(); | |
264 | m_originalBrush = brush; |
|
264 | m_originalBrush = brush; | |
265 | brush.setColor(brush.color().lighter()); |
|
265 | brush.setColor(brush.color().lighter()); | |
266 | setBrush(brush); |
|
266 | setBrush(brush); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void handleHoverLeave() |
|
269 | void handleHoverLeave() | |
270 | { |
|
270 | { | |
271 | setBrush(m_originalBrush); |
|
271 | setBrush(m_originalBrush); | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | private: |
|
274 | private: | |
275 | QBrush m_originalBrush; |
|
275 | QBrush m_originalBrush; | |
276 | }; |
|
276 | }; | |
277 |
|
277 | |||
278 | class MainWidget : public QWidget |
|
278 | class MainWidget : public QWidget | |
279 | { |
|
279 | { | |
280 | Q_OBJECT |
|
280 | Q_OBJECT | |
281 |
|
281 | |||
282 | public: |
|
282 | public: | |
283 | explicit MainWidget(QWidget* parent = 0) |
|
283 | explicit MainWidget(QWidget* parent = 0) | |
284 | :QWidget(parent), |
|
284 | :QWidget(parent), | |
285 | m_slice(0) |
|
285 | m_slice(0) | |
286 | { |
|
286 | { | |
287 | // create chart |
|
287 | // create chart | |
288 | m_chartView = new QChartView(new QChart()); |
|
288 | m_chartView = new QChartView(new QChart()); | |
289 | m_chartView->chart()->setTitle("Piechart customization"); |
|
289 | m_chartView->chart()->setTitle("Piechart customization"); | |
290 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); |
|
290 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); | |
291 |
|
291 | |||
292 | // create series |
|
292 | // create series | |
293 | m_series = new QPieSeries(); |
|
293 | m_series = new QPieSeries(); | |
294 | *m_series << new CustomSlice(10.0, "Slice 1"); |
|
294 | *m_series << new CustomSlice(10.0, "Slice 1"); | |
295 | *m_series << new CustomSlice(20.0, "Slice 2"); |
|
295 | *m_series << new CustomSlice(20.0, "Slice 2"); | |
296 | *m_series << new CustomSlice(30.0, "Slice 3"); |
|
296 | *m_series << new CustomSlice(30.0, "Slice 3"); | |
297 | *m_series << new CustomSlice(40.0, "Slice 4"); |
|
297 | *m_series << new CustomSlice(40.0, "Slice 4"); | |
298 | *m_series << new CustomSlice(50.0, "Slice 5"); |
|
298 | *m_series << new CustomSlice(50.0, "Slice 5"); | |
299 | m_series->setLabelsVisible(); |
|
299 | m_series->setLabelsVisible(); | |
300 | m_chartView->chart()->addSeries(m_series); |
|
300 | m_chartView->chart()->addSeries(m_series); | |
301 |
|
301 | |||
302 | connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons))); |
|
302 | connect(m_series, SIGNAL(clicked(QPieSlice*, Qt::MouseButtons)), this, SLOT(handleSliceClicked(QPieSlice*, Qt::MouseButtons))); | |
303 |
|
303 | |||
304 | // chart settings |
|
304 | // chart settings | |
305 | m_themeComboBox = new QComboBox(); |
|
305 | m_themeComboBox = new QComboBox(); | |
306 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); |
|
306 | m_themeComboBox->addItem("Default", QChart::ChartThemeDefault); | |
307 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
307 | m_themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
308 | m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); |
|
308 | m_themeComboBox->addItem("BlueCerulean", QChart::ChartThemeBlueCerulean); | |
309 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
309 | m_themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
310 | m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand); |
|
310 | m_themeComboBox->addItem("BrownSand", QChart::ChartThemeBrownSand); | |
311 | m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs); |
|
311 | m_themeComboBox->addItem("BlueNcs", QChart::ChartThemeBlueNcs); | |
312 |
m_themeComboBox->addItem(" |
|
312 | m_themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
313 |
m_themeComboBox->addItem(" |
|
313 | m_themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
314 |
|
314 | |||
315 | m_aaCheckBox = new QCheckBox(); |
|
315 | m_aaCheckBox = new QCheckBox(); | |
316 | m_animationsCheckBox = new QCheckBox(); |
|
316 | m_animationsCheckBox = new QCheckBox(); | |
317 | m_animationsCheckBox->setCheckState(Qt::Checked); |
|
317 | m_animationsCheckBox->setCheckState(Qt::Checked); | |
318 |
|
318 | |||
319 | QFormLayout* chartSettingsLayout = new QFormLayout(); |
|
319 | QFormLayout* chartSettingsLayout = new QFormLayout(); | |
320 | chartSettingsLayout->addRow("Theme", m_themeComboBox); |
|
320 | chartSettingsLayout->addRow("Theme", m_themeComboBox); | |
321 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); |
|
321 | chartSettingsLayout->addRow("Antialiasing", m_aaCheckBox); | |
322 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); |
|
322 | chartSettingsLayout->addRow("Animations", m_animationsCheckBox); | |
323 | QGroupBox* chartSettings = new QGroupBox("Chart"); |
|
323 | QGroupBox* chartSettings = new QGroupBox("Chart"); | |
324 | chartSettings->setLayout(chartSettingsLayout); |
|
324 | chartSettings->setLayout(chartSettingsLayout); | |
325 |
|
325 | |||
326 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); |
|
326 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this ,SLOT(updateChartSettings())); | |
327 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); |
|
327 | connect(m_aaCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | |
328 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); |
|
328 | connect(m_animationsCheckBox, SIGNAL(toggled(bool)), this ,SLOT(updateChartSettings())); | |
329 |
|
329 | |||
330 | // series settings |
|
330 | // series settings | |
331 | m_hPosition = new QDoubleSpinBox(); |
|
331 | m_hPosition = new QDoubleSpinBox(); | |
332 | m_hPosition->setMinimum(0.0); |
|
332 | m_hPosition->setMinimum(0.0); | |
333 | m_hPosition->setMaximum(1.0); |
|
333 | m_hPosition->setMaximum(1.0); | |
334 | m_hPosition->setSingleStep(0.1); |
|
334 | m_hPosition->setSingleStep(0.1); | |
335 | m_hPosition->setValue(m_series->pieHorizontalPosition()); |
|
335 | m_hPosition->setValue(m_series->pieHorizontalPosition()); | |
336 |
|
336 | |||
337 | m_vPosition = new QDoubleSpinBox(); |
|
337 | m_vPosition = new QDoubleSpinBox(); | |
338 | m_vPosition->setMinimum(0.0); |
|
338 | m_vPosition->setMinimum(0.0); | |
339 | m_vPosition->setMaximum(1.0); |
|
339 | m_vPosition->setMaximum(1.0); | |
340 | m_vPosition->setSingleStep(0.1); |
|
340 | m_vPosition->setSingleStep(0.1); | |
341 | m_vPosition->setValue(m_series->pieVerticalPosition()); |
|
341 | m_vPosition->setValue(m_series->pieVerticalPosition()); | |
342 |
|
342 | |||
343 | m_sizeFactor = new QDoubleSpinBox(); |
|
343 | m_sizeFactor = new QDoubleSpinBox(); | |
344 | m_sizeFactor->setMinimum(0.0); |
|
344 | m_sizeFactor->setMinimum(0.0); | |
345 | m_sizeFactor->setMaximum(1.0); |
|
345 | m_sizeFactor->setMaximum(1.0); | |
346 | m_sizeFactor->setSingleStep(0.1); |
|
346 | m_sizeFactor->setSingleStep(0.1); | |
347 | m_sizeFactor->setValue(m_series->pieSize()); |
|
347 | m_sizeFactor->setValue(m_series->pieSize()); | |
348 |
|
348 | |||
349 | m_startAngle = new QDoubleSpinBox(); |
|
349 | m_startAngle = new QDoubleSpinBox(); | |
350 | m_startAngle->setMinimum(0.0); |
|
350 | m_startAngle->setMinimum(0.0); | |
351 | m_startAngle->setMaximum(360); |
|
351 | m_startAngle->setMaximum(360); | |
352 | m_startAngle->setValue(m_series->pieStartAngle()); |
|
352 | m_startAngle->setValue(m_series->pieStartAngle()); | |
353 | m_startAngle->setSingleStep(1); |
|
353 | m_startAngle->setSingleStep(1); | |
354 |
|
354 | |||
355 | m_endAngle = new QDoubleSpinBox(); |
|
355 | m_endAngle = new QDoubleSpinBox(); | |
356 | m_endAngle->setMinimum(0.0); |
|
356 | m_endAngle->setMinimum(0.0); | |
357 | m_endAngle->setMaximum(360); |
|
357 | m_endAngle->setMaximum(360); | |
358 | m_endAngle->setValue(m_series->pieEndAngle()); |
|
358 | m_endAngle->setValue(m_series->pieEndAngle()); | |
359 | m_endAngle->setSingleStep(1); |
|
359 | m_endAngle->setSingleStep(1); | |
360 |
|
360 | |||
361 | QPushButton *addSlice = new QPushButton("Add slice"); |
|
361 | QPushButton *addSlice = new QPushButton("Add slice"); | |
362 | QPushButton *insertSlice = new QPushButton("Insert slice"); |
|
362 | QPushButton *insertSlice = new QPushButton("Insert slice"); | |
363 |
|
363 | |||
364 | QFormLayout* seriesSettingsLayout = new QFormLayout(); |
|
364 | QFormLayout* seriesSettingsLayout = new QFormLayout(); | |
365 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); |
|
365 | seriesSettingsLayout->addRow("Horizontal position", m_hPosition); | |
366 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); |
|
366 | seriesSettingsLayout->addRow("Vertical position", m_vPosition); | |
367 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); |
|
367 | seriesSettingsLayout->addRow("Size factor", m_sizeFactor); | |
368 | seriesSettingsLayout->addRow("Start angle", m_startAngle); |
|
368 | seriesSettingsLayout->addRow("Start angle", m_startAngle); | |
369 | seriesSettingsLayout->addRow("End angle", m_endAngle); |
|
369 | seriesSettingsLayout->addRow("End angle", m_endAngle); | |
370 | seriesSettingsLayout->addRow(addSlice); |
|
370 | seriesSettingsLayout->addRow(addSlice); | |
371 | seriesSettingsLayout->addRow(insertSlice); |
|
371 | seriesSettingsLayout->addRow(insertSlice); | |
372 | QGroupBox* seriesSettings = new QGroupBox("Series"); |
|
372 | QGroupBox* seriesSettings = new QGroupBox("Series"); | |
373 | seriesSettings->setLayout(seriesSettingsLayout); |
|
373 | seriesSettings->setLayout(seriesSettingsLayout); | |
374 |
|
374 | |||
375 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
375 | connect(m_vPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
376 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
376 | connect(m_hPosition, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
377 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
377 | connect(m_sizeFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
378 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
378 | connect(m_startAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
379 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); |
|
379 | connect(m_endAngle, SIGNAL(valueChanged(double)), this, SLOT(updateSerieSettings())); | |
380 | connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice())); |
|
380 | connect(addSlice, SIGNAL(clicked()), this, SLOT(addSlice())); | |
381 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); |
|
381 | connect(insertSlice, SIGNAL(clicked()), this, SLOT(insertSlice())); | |
382 |
|
382 | |||
383 | // slice settings |
|
383 | // slice settings | |
384 | m_sliceName = new QLabel("<click a slice>"); |
|
384 | m_sliceName = new QLabel("<click a slice>"); | |
385 | m_sliceValue = new QDoubleSpinBox(); |
|
385 | m_sliceValue = new QDoubleSpinBox(); | |
386 | m_sliceValue->setMaximum(1000); |
|
386 | m_sliceValue->setMaximum(1000); | |
387 | m_sliceLabelVisible = new QCheckBox(); |
|
387 | m_sliceLabelVisible = new QCheckBox(); | |
388 | m_sliceLabelArmFactor = new QDoubleSpinBox(); |
|
388 | m_sliceLabelArmFactor = new QDoubleSpinBox(); | |
389 | m_sliceLabelArmFactor->setSingleStep(0.01); |
|
389 | m_sliceLabelArmFactor->setSingleStep(0.01); | |
390 | m_sliceExploded = new QCheckBox(); |
|
390 | m_sliceExploded = new QCheckBox(); | |
391 | m_sliceExplodedFactor = new QDoubleSpinBox(); |
|
391 | m_sliceExplodedFactor = new QDoubleSpinBox(); | |
392 | m_sliceExplodedFactor->setSingleStep(0.01); |
|
392 | m_sliceExplodedFactor->setSingleStep(0.01); | |
393 | m_pen = new QPushButton(); |
|
393 | m_pen = new QPushButton(); | |
394 | m_penTool = new PenTool("Slice pen", this); |
|
394 | m_penTool = new PenTool("Slice pen", this); | |
395 | m_brush = new QPushButton(); |
|
395 | m_brush = new QPushButton(); | |
396 | m_brushTool = new BrushTool("Slice brush", this); |
|
396 | m_brushTool = new BrushTool("Slice brush", this); | |
397 | m_font = new QPushButton(); |
|
397 | m_font = new QPushButton(); | |
398 | m_labelPen = new QPushButton(); |
|
398 | m_labelPen = new QPushButton(); | |
399 | m_labelPenTool = new PenTool("Label pen", this); |
|
399 | m_labelPenTool = new PenTool("Label pen", this); | |
400 | QPushButton *removeSlice = new QPushButton("Remove slice"); |
|
400 | QPushButton *removeSlice = new QPushButton("Remove slice"); | |
401 |
|
401 | |||
402 | QFormLayout* sliceSettingsLayout = new QFormLayout(); |
|
402 | QFormLayout* sliceSettingsLayout = new QFormLayout(); | |
403 | sliceSettingsLayout->addRow("Selected", m_sliceName); |
|
403 | sliceSettingsLayout->addRow("Selected", m_sliceName); | |
404 | sliceSettingsLayout->addRow("Value", m_sliceValue); |
|
404 | sliceSettingsLayout->addRow("Value", m_sliceValue); | |
405 | sliceSettingsLayout->addRow("Pen", m_pen); |
|
405 | sliceSettingsLayout->addRow("Pen", m_pen); | |
406 | sliceSettingsLayout->addRow("Brush", m_brush); |
|
406 | sliceSettingsLayout->addRow("Brush", m_brush); | |
407 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); |
|
407 | sliceSettingsLayout->addRow("Label visible", m_sliceLabelVisible); | |
408 | sliceSettingsLayout->addRow("Label font", m_font); |
|
408 | sliceSettingsLayout->addRow("Label font", m_font); | |
409 | sliceSettingsLayout->addRow("Label pen", m_labelPen); |
|
409 | sliceSettingsLayout->addRow("Label pen", m_labelPen); | |
410 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); |
|
410 | sliceSettingsLayout->addRow("Label arm length", m_sliceLabelArmFactor); | |
411 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); |
|
411 | sliceSettingsLayout->addRow("Exploded", m_sliceExploded); | |
412 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); |
|
412 | sliceSettingsLayout->addRow("Explode distance", m_sliceExplodedFactor); | |
413 | sliceSettingsLayout->addRow(removeSlice); |
|
413 | sliceSettingsLayout->addRow(removeSlice); | |
414 | QGroupBox* sliceSettings = new QGroupBox("Slice"); |
|
414 | QGroupBox* sliceSettings = new QGroupBox("Slice"); | |
415 | sliceSettings->setLayout(sliceSettingsLayout); |
|
415 | sliceSettings->setLayout(sliceSettingsLayout); | |
416 |
|
416 | |||
417 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
417 | connect(m_sliceValue, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
418 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); |
|
418 | connect(m_pen, SIGNAL(clicked()), m_penTool, SLOT(show())); | |
419 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
419 | connect(m_penTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
420 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); |
|
420 | connect(m_brush, SIGNAL(clicked()), m_brushTool, SLOT(show())); | |
421 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
421 | connect(m_brushTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
422 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); |
|
422 | connect(m_font, SIGNAL(clicked()), this, SLOT(showFontDialog())); | |
423 | connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show())); |
|
423 | connect(m_labelPen, SIGNAL(clicked()), m_labelPenTool, SLOT(show())); | |
424 | connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); |
|
424 | connect(m_labelPenTool, SIGNAL(changed()), this, SLOT(updateSliceSettings())); | |
425 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
425 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
426 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
426 | connect(m_sliceLabelVisible, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
427 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
427 | connect(m_sliceLabelArmFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
428 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); |
|
428 | connect(m_sliceExploded, SIGNAL(toggled(bool)), this, SLOT(updateSliceSettings())); | |
429 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); |
|
429 | connect(m_sliceExplodedFactor, SIGNAL(valueChanged(double)), this, SLOT(updateSliceSettings())); | |
430 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); |
|
430 | connect(removeSlice, SIGNAL(clicked()), this, SLOT(removeSlice())); | |
431 |
|
431 | |||
432 | // create main layout |
|
432 | // create main layout | |
433 | QVBoxLayout *settingsLayout = new QVBoxLayout(); |
|
433 | QVBoxLayout *settingsLayout = new QVBoxLayout(); | |
434 | settingsLayout->addWidget(chartSettings); |
|
434 | settingsLayout->addWidget(chartSettings); | |
435 | settingsLayout->addWidget(seriesSettings); |
|
435 | settingsLayout->addWidget(seriesSettings); | |
436 | settingsLayout->addWidget(sliceSettings); |
|
436 | settingsLayout->addWidget(sliceSettings); | |
437 | settingsLayout->addStretch(); |
|
437 | settingsLayout->addStretch(); | |
438 |
|
438 | |||
439 | QGridLayout* baseLayout = new QGridLayout(); |
|
439 | QGridLayout* baseLayout = new QGridLayout(); | |
440 | baseLayout->addLayout(settingsLayout, 0, 0); |
|
440 | baseLayout->addLayout(settingsLayout, 0, 0); | |
441 | baseLayout->addWidget(m_chartView, 0, 1); |
|
441 | baseLayout->addWidget(m_chartView, 0, 1); | |
442 | setLayout(baseLayout); |
|
442 | setLayout(baseLayout); | |
443 |
|
443 | |||
444 | updateSerieSettings(); |
|
444 | updateSerieSettings(); | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | public Q_SLOTS: |
|
447 | public Q_SLOTS: | |
448 |
|
448 | |||
449 | void updateChartSettings() |
|
449 | void updateChartSettings() | |
450 | { |
|
450 | { | |
451 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
451 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
452 | m_chartView->chart()->setTheme(theme); |
|
452 | m_chartView->chart()->setTheme(theme); | |
453 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); |
|
453 | m_chartView->setRenderHint(QPainter::Antialiasing, m_aaCheckBox->isChecked()); | |
454 |
|
454 | |||
455 | if (m_animationsCheckBox->checkState() == Qt::Checked) |
|
455 | if (m_animationsCheckBox->checkState() == Qt::Checked) | |
456 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); |
|
456 | m_chartView->chart()->setAnimationOptions(QChart::AllAnimations); | |
457 | else |
|
457 | else | |
458 | m_chartView->chart()->setAnimationOptions(QChart::NoAnimation); |
|
458 | m_chartView->chart()->setAnimationOptions(QChart::NoAnimation); | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | void updateSerieSettings() |
|
461 | void updateSerieSettings() | |
462 | { |
|
462 | { | |
463 | m_series->setPiePosition(m_hPosition->value(), m_vPosition->value()); |
|
463 | m_series->setPiePosition(m_hPosition->value(), m_vPosition->value()); | |
464 | m_series->setPieSize(m_sizeFactor->value()); |
|
464 | m_series->setPieSize(m_sizeFactor->value()); | |
465 | m_series->setPieStartAngle(m_startAngle->value()); |
|
465 | m_series->setPieStartAngle(m_startAngle->value()); | |
466 | m_series->setPieEndAngle(m_endAngle->value()); |
|
466 | m_series->setPieEndAngle(m_endAngle->value()); | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | void updateSliceSettings() |
|
469 | void updateSliceSettings() | |
470 | { |
|
470 | { | |
471 | if (!m_slice) |
|
471 | if (!m_slice) | |
472 | return; |
|
472 | return; | |
473 |
|
473 | |||
474 | m_slice->setValue(m_sliceValue->value()); |
|
474 | m_slice->setValue(m_sliceValue->value()); | |
475 |
|
475 | |||
476 | m_slice->setPen(m_penTool->pen()); |
|
476 | m_slice->setPen(m_penTool->pen()); | |
477 | m_slice->setBrush(m_brushTool->brush()); |
|
477 | m_slice->setBrush(m_brushTool->brush()); | |
478 |
|
478 | |||
479 | m_slice->setLabelPen(m_labelPenTool->pen()); |
|
479 | m_slice->setLabelPen(m_labelPenTool->pen()); | |
480 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); |
|
480 | m_slice->setLabelVisible(m_sliceLabelVisible->isChecked()); | |
481 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); |
|
481 | m_slice->setLabelArmLengthFactor(m_sliceLabelArmFactor->value()); | |
482 |
|
482 | |||
483 | m_slice->setExploded(m_sliceExploded->isChecked()); |
|
483 | m_slice->setExploded(m_sliceExploded->isChecked()); | |
484 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); |
|
484 | m_slice->setExplodeDistanceFactor(m_sliceExplodedFactor->value()); | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons) |
|
487 | void handleSliceClicked(QPieSlice* slice, Qt::MouseButtons buttons) | |
488 | { |
|
488 | { | |
489 | Q_UNUSED(buttons); |
|
489 | Q_UNUSED(buttons); | |
490 |
|
490 | |||
491 | m_slice = static_cast<CustomSlice*>(slice); |
|
491 | m_slice = static_cast<CustomSlice*>(slice); | |
492 |
|
492 | |||
493 | // name |
|
493 | // name | |
494 | m_sliceName->setText(slice->label()); |
|
494 | m_sliceName->setText(slice->label()); | |
495 |
|
495 | |||
496 | // value |
|
496 | // value | |
497 | m_sliceValue->blockSignals(true); |
|
497 | m_sliceValue->blockSignals(true); | |
498 | m_sliceValue->setValue(slice->value()); |
|
498 | m_sliceValue->setValue(slice->value()); | |
499 | m_sliceValue->blockSignals(false); |
|
499 | m_sliceValue->blockSignals(false); | |
500 |
|
500 | |||
501 | // pen |
|
501 | // pen | |
502 | m_pen->setText(PenTool::name(m_slice->pen())); |
|
502 | m_pen->setText(PenTool::name(m_slice->pen())); | |
503 | m_penTool->setPen(m_slice->pen()); |
|
503 | m_penTool->setPen(m_slice->pen()); | |
504 |
|
504 | |||
505 | // brush |
|
505 | // brush | |
506 | m_brush->setText(m_slice->originalBrush().color().name()); |
|
506 | m_brush->setText(m_slice->originalBrush().color().name()); | |
507 | m_brushTool->setBrush(m_slice->originalBrush()); |
|
507 | m_brushTool->setBrush(m_slice->originalBrush()); | |
508 |
|
508 | |||
509 | // label |
|
509 | // label | |
510 | m_labelPen->setText(PenTool::name(m_slice->labelPen())); |
|
510 | m_labelPen->setText(PenTool::name(m_slice->labelPen())); | |
511 | m_labelPenTool->setPen(m_slice->labelPen()); |
|
511 | m_labelPenTool->setPen(m_slice->labelPen()); | |
512 | m_font->setText(slice->labelFont().toString()); |
|
512 | m_font->setText(slice->labelFont().toString()); | |
513 | m_sliceLabelVisible->blockSignals(true); |
|
513 | m_sliceLabelVisible->blockSignals(true); | |
514 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); |
|
514 | m_sliceLabelVisible->setChecked(slice->isLabelVisible()); | |
515 | m_sliceLabelVisible->blockSignals(false); |
|
515 | m_sliceLabelVisible->blockSignals(false); | |
516 | m_sliceLabelArmFactor->blockSignals(true); |
|
516 | m_sliceLabelArmFactor->blockSignals(true); | |
517 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); |
|
517 | m_sliceLabelArmFactor->setValue(slice->labelArmLengthFactor()); | |
518 | m_sliceLabelArmFactor->blockSignals(false); |
|
518 | m_sliceLabelArmFactor->blockSignals(false); | |
519 |
|
519 | |||
520 | // exploded |
|
520 | // exploded | |
521 | m_sliceExploded->blockSignals(true); |
|
521 | m_sliceExploded->blockSignals(true); | |
522 | m_sliceExploded->setChecked(slice->isExploded()); |
|
522 | m_sliceExploded->setChecked(slice->isExploded()); | |
523 | m_sliceExploded->blockSignals(false); |
|
523 | m_sliceExploded->blockSignals(false); | |
524 | m_sliceExplodedFactor->blockSignals(true); |
|
524 | m_sliceExplodedFactor->blockSignals(true); | |
525 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); |
|
525 | m_sliceExplodedFactor->setValue(slice->explodeDistanceFactor()); | |
526 | m_sliceExplodedFactor->blockSignals(false); |
|
526 | m_sliceExplodedFactor->blockSignals(false); | |
527 | } |
|
527 | } | |
528 |
|
528 | |||
529 | void showFontDialog() |
|
529 | void showFontDialog() | |
530 | { |
|
530 | { | |
531 | if (!m_slice) |
|
531 | if (!m_slice) | |
532 | return; |
|
532 | return; | |
533 |
|
533 | |||
534 | QFontDialog dialog(m_slice->labelFont()); |
|
534 | QFontDialog dialog(m_slice->labelFont()); | |
535 | dialog.show(); |
|
535 | dialog.show(); | |
536 | dialog.exec(); |
|
536 | dialog.exec(); | |
537 |
|
537 | |||
538 | m_slice->setLabelFont(dialog.currentFont()); |
|
538 | m_slice->setLabelFont(dialog.currentFont()); | |
539 | m_font->setText(dialog.currentFont().toString()); |
|
539 | m_font->setText(dialog.currentFont().toString()); | |
540 | } |
|
540 | } | |
541 |
|
541 | |||
542 | void addSlice() |
|
542 | void addSlice() | |
543 | { |
|
543 | { | |
544 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); |
|
544 | *m_series << new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1)); | |
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | void insertSlice() |
|
547 | void insertSlice() | |
548 | { |
|
548 | { | |
549 | if (!m_slice) |
|
549 | if (!m_slice) | |
550 | return; |
|
550 | return; | |
551 |
|
551 | |||
552 | int i = m_series->slices().indexOf(m_slice); |
|
552 | int i = m_series->slices().indexOf(m_slice); | |
553 |
|
553 | |||
554 | m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1))); |
|
554 | m_series->insert(i, new CustomSlice(10.0, "Slice " + QString::number(m_series->count()+1))); | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | void removeSlice() |
|
557 | void removeSlice() | |
558 | { |
|
558 | { | |
559 | if (!m_slice) |
|
559 | if (!m_slice) | |
560 | return; |
|
560 | return; | |
561 |
|
561 | |||
562 | m_series->remove(m_slice); |
|
562 | m_series->remove(m_slice); | |
563 | m_slice = 0; |
|
563 | m_slice = 0; | |
564 | } |
|
564 | } | |
565 |
|
565 | |||
566 | private: |
|
566 | private: | |
567 | QComboBox *m_themeComboBox; |
|
567 | QComboBox *m_themeComboBox; | |
568 | QCheckBox *m_aaCheckBox; |
|
568 | QCheckBox *m_aaCheckBox; | |
569 | QCheckBox *m_animationsCheckBox; |
|
569 | QCheckBox *m_animationsCheckBox; | |
570 |
|
570 | |||
571 | QChartView* m_chartView; |
|
571 | QChartView* m_chartView; | |
572 | QPieSeries* m_series; |
|
572 | QPieSeries* m_series; | |
573 | CustomSlice* m_slice; |
|
573 | CustomSlice* m_slice; | |
574 |
|
574 | |||
575 | QDoubleSpinBox* m_hPosition; |
|
575 | QDoubleSpinBox* m_hPosition; | |
576 | QDoubleSpinBox* m_vPosition; |
|
576 | QDoubleSpinBox* m_vPosition; | |
577 | QDoubleSpinBox* m_sizeFactor; |
|
577 | QDoubleSpinBox* m_sizeFactor; | |
578 | QDoubleSpinBox* m_startAngle; |
|
578 | QDoubleSpinBox* m_startAngle; | |
579 | QDoubleSpinBox* m_endAngle; |
|
579 | QDoubleSpinBox* m_endAngle; | |
580 |
|
580 | |||
581 | QLabel* m_sliceName; |
|
581 | QLabel* m_sliceName; | |
582 | QDoubleSpinBox* m_sliceValue; |
|
582 | QDoubleSpinBox* m_sliceValue; | |
583 | QCheckBox* m_sliceLabelVisible; |
|
583 | QCheckBox* m_sliceLabelVisible; | |
584 | QDoubleSpinBox* m_sliceLabelArmFactor; |
|
584 | QDoubleSpinBox* m_sliceLabelArmFactor; | |
585 | QCheckBox* m_sliceExploded; |
|
585 | QCheckBox* m_sliceExploded; | |
586 | QDoubleSpinBox* m_sliceExplodedFactor; |
|
586 | QDoubleSpinBox* m_sliceExplodedFactor; | |
587 | QPushButton *m_brush; |
|
587 | QPushButton *m_brush; | |
588 | BrushTool *m_brushTool; |
|
588 | BrushTool *m_brushTool; | |
589 | QPushButton *m_pen; |
|
589 | QPushButton *m_pen; | |
590 | PenTool *m_penTool; |
|
590 | PenTool *m_penTool; | |
591 | QPushButton *m_font; |
|
591 | QPushButton *m_font; | |
592 | QPushButton *m_labelPen; |
|
592 | QPushButton *m_labelPen; | |
593 | PenTool *m_labelPenTool; |
|
593 | PenTool *m_labelPenTool; | |
594 | }; |
|
594 | }; | |
595 |
|
595 | |||
596 | int main(int argc, char *argv[]) |
|
596 | int main(int argc, char *argv[]) | |
597 | { |
|
597 | { | |
598 | QApplication a(argc, argv); |
|
598 | QApplication a(argc, argv); | |
599 |
|
599 | |||
600 | QMainWindow window; |
|
600 | QMainWindow window; | |
601 |
|
601 | |||
602 | MainWidget* widget = new MainWidget(); |
|
602 | MainWidget* widget = new MainWidget(); | |
603 |
|
603 | |||
604 | window.setCentralWidget(widget); |
|
604 | window.setCentralWidget(widget); | |
605 | window.resize(900, 600); |
|
605 | window.resize(900, 600); | |
606 | window.show(); |
|
606 | window.show(); | |
607 |
|
607 | |||
608 | return a.exec(); |
|
608 | return a.exec(); | |
609 | } |
|
609 | } | |
610 |
|
610 | |||
611 | #include "main.moc" |
|
611 | #include "main.moc" |
@@ -1,83 +1,83 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qlineseries.h> |
|
5 | #include <qlineseries.h> | |
6 | #include <qscatterseries.h> |
|
6 | #include <qscatterseries.h> | |
7 | #include <qbarseries.h> |
|
7 | #include <qbarseries.h> | |
8 | #include <qbarset.h> |
|
8 | #include <qbarset.h> | |
9 | #include <qpieseries.h> |
|
9 | #include <qpieseries.h> | |
10 | #include <QStringList> |
|
10 | #include <QStringList> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
14 | int main(int argc, char *argv[]) |
|
14 | int main(int argc, char *argv[]) | |
15 | { |
|
15 | { | |
16 | QApplication a(argc, argv); |
|
16 | QApplication a(argc, argv); | |
17 |
|
17 | |||
18 | //! [1] |
|
18 | //! [1] | |
19 | // Create chart view |
|
19 | // Create chart view | |
20 | QChartView *chartView = new QChartView(); |
|
20 | QChartView *chartView = new QChartView(); | |
21 | chartView->setRenderHint(QPainter::Antialiasing); |
|
21 | chartView->setRenderHint(QPainter::Antialiasing); | |
22 | chartView->setChartTitle("Simple Line Chart"); |
|
22 | chartView->setChartTitle("Simple Line Chart"); | |
23 | // Add series to the chart |
|
23 | // Add series to the chart | |
24 | QLineSeries *line = new QLineSeries(); |
|
24 | QLineSeries *line = new QLineSeries(); | |
25 | line->add(0.0, 0.8); |
|
25 | line->add(0.0, 0.8); | |
26 | line->add(1.1, 1.1); |
|
26 | line->add(1.1, 1.1); | |
27 | line->add(2.0, 2.5); |
|
27 | line->add(2.0, 2.5); | |
28 | chartView->addSeries(line); |
|
28 | chartView->addSeries(line); | |
29 | //! [1] |
|
29 | //! [1] | |
30 |
|
30 | |||
31 | chartView->setChartTitle("\'Scietific\' theme"); |
|
31 | chartView->setChartTitle("\'Scietific\' theme"); | |
32 | //! [2] |
|
32 | //! [2] | |
33 | // Change theme |
|
33 | // Change theme | |
34 |
chartView->setChartTheme(QChart::ChartTheme |
|
34 | chartView->setChartTheme(QChart::ChartThemeHighContrast); | |
35 | //! [2] |
|
35 | //! [2] | |
36 |
|
36 | |||
37 | chartView->setChartTitle("Simple Pie Chart"); |
|
37 | chartView->setChartTitle("Simple Pie Chart"); | |
38 | //! [3] |
|
38 | //! [3] | |
39 | // Add pie series |
|
39 | // Add pie series | |
40 | // ... |
|
40 | // ... | |
41 | QPieSeries *pie = new QPieSeries(); |
|
41 | QPieSeries *pie = new QPieSeries(); | |
42 | pie->add(3.4, "slice1"); |
|
42 | pie->add(3.4, "slice1"); | |
43 | pie->add(6.7, "slice2"); |
|
43 | pie->add(6.7, "slice2"); | |
44 | chartView->addSeries(pie); |
|
44 | chartView->addSeries(pie); | |
45 | //! [3] |
|
45 | //! [3] | |
46 |
|
46 | |||
47 | chartView->setChartTitle("Simple Scatter Chart"); |
|
47 | chartView->setChartTitle("Simple Scatter Chart"); | |
48 | //! [4] |
|
48 | //! [4] | |
49 | // Add scatter series |
|
49 | // Add scatter series | |
50 | // ... |
|
50 | // ... | |
51 | QScatterSeries *scatter = new QScatterSeries(); |
|
51 | QScatterSeries *scatter = new QScatterSeries(); | |
52 | for (qreal x(0); x < 100; x += 0.5) { |
|
52 | for (qreal x(0); x < 100; x += 0.5) { | |
53 | qreal y = rand() % 100; |
|
53 | qreal y = rand() % 100; | |
54 | *(scatter) << QPointF(x, y); |
|
54 | *(scatter) << QPointF(x, y); | |
55 | } |
|
55 | } | |
56 | chartView->addSeries(scatter); |
|
56 | chartView->addSeries(scatter); | |
57 | //! [4] |
|
57 | //! [4] | |
58 |
|
58 | |||
59 | chartView->setChartTitle("Simple Bar Chart"); |
|
59 | chartView->setChartTitle("Simple Bar Chart"); | |
60 | //! [5] |
|
60 | //! [5] | |
61 | // ... |
|
61 | // ... | |
62 | // Add bar series |
|
62 | // Add bar series | |
63 | QStringList barCategory; |
|
63 | QStringList barCategory; | |
64 | barCategory << "Jan" |
|
64 | barCategory << "Jan" | |
65 | << "Feb" |
|
65 | << "Feb" | |
66 | << "Mar"; |
|
66 | << "Mar"; | |
67 | QBarSeries *bar = new QBarSeries(barCategory); |
|
67 | QBarSeries *bar = new QBarSeries(barCategory); | |
68 | QBarSet *barSet = new QBarSet("Sales"); |
|
68 | QBarSet *barSet = new QBarSet("Sales"); | |
69 | *barSet << 123.2 |
|
69 | *barSet << 123.2 | |
70 | << 301.3 |
|
70 | << 301.3 | |
71 | << 285.8; |
|
71 | << 285.8; | |
72 | bar->addBarSet(barSet); |
|
72 | bar->addBarSet(barSet); | |
73 | chartView->addSeries(bar); |
|
73 | chartView->addSeries(bar); | |
74 | //! [5] |
|
74 | //! [5] | |
75 |
|
75 | |||
76 | QMainWindow w; |
|
76 | QMainWindow w; | |
77 | w.resize(400, 300); |
|
77 | w.resize(400, 300); | |
78 | w.setCentralWidget(chartView); |
|
78 | w.setCentralWidget(chartView); | |
79 | w.setWindowFlags(Qt::FramelessWindowHint); |
|
79 | w.setWindowFlags(Qt::FramelessWindowHint); | |
80 | w.show(); |
|
80 | w.show(); | |
81 |
|
81 | |||
82 | return a.exec(); |
|
82 | return a.exec(); | |
83 | } |
|
83 | } |
@@ -1,107 +1,107 | |||||
1 | #include "mainwindow.h" |
|
1 | #include "mainwindow.h" | |
2 | #include <qchartview.h> |
|
2 | #include <qchartview.h> | |
3 | #include <qpieseries.h> |
|
3 | #include <qpieseries.h> | |
4 | #include <qpieslice.h> |
|
4 | #include <qpieslice.h> | |
5 | #include <qlineseries.h> |
|
5 | #include <qlineseries.h> | |
6 | #include <qscatterseries.h> |
|
6 | #include <qscatterseries.h> | |
7 | #include <qchartaxis.h> |
|
7 | #include <qchartaxis.h> | |
8 | #include <QDebug> |
|
8 | #include <QDebug> | |
9 |
|
9 | |||
10 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
10 | QTCOMMERCIALCHART_USE_NAMESPACE | |
11 |
|
11 | |||
12 | MainWindow::MainWindow(QWidget *parent) |
|
12 | MainWindow::MainWindow(QWidget *parent) | |
13 | : QMainWindow(parent) |
|
13 | : QMainWindow(parent) | |
14 | { |
|
14 | { | |
15 | // Here's the set of company's colors used throughout the example |
|
15 | // Here's the set of company's colors used throughout the example | |
16 | m_companyColor1 = "#b90020"; |
|
16 | m_companyColor1 = "#b90020"; | |
17 | m_companyColor2 = "#6d0013"; |
|
17 | m_companyColor2 = "#6d0013"; | |
18 | m_companyColor3 = "#f5d5d5"; |
|
18 | m_companyColor3 = "#f5d5d5"; | |
19 | m_companyColor4 = "#fcfcfc"; |
|
19 | m_companyColor4 = "#fcfcfc"; | |
20 |
|
20 | |||
21 | resize(400, 300); |
|
21 | resize(400, 300); | |
22 | setWindowFlags(Qt::FramelessWindowHint); |
|
22 | setWindowFlags(Qt::FramelessWindowHint); | |
23 |
|
23 | |||
24 | // Create chart view |
|
24 | // Create chart view | |
25 | //! [4] |
|
25 | //! [4] | |
26 | m_chartView = new QChartView(this); |
|
26 | m_chartView = new QChartView(this); | |
27 |
m_chartView->setChartTheme(QChart::ChartTheme |
|
27 | m_chartView->setChartTheme(QChart::ChartThemeHighContrast); | |
28 | //! [4] |
|
28 | //! [4] | |
29 | setCentralWidget(m_chartView); |
|
29 | setCentralWidget(m_chartView); | |
30 | m_chartView->setChartTitle("Custom colors example"); |
|
30 | m_chartView->setChartTitle("Custom colors example"); | |
31 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
31 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
32 |
|
32 | |||
33 | // Create line series |
|
33 | // Create line series | |
34 | m_line = new QLineSeries(); |
|
34 | m_line = new QLineSeries(); | |
35 | m_line->add(0.0, 1.1); |
|
35 | m_line->add(0.0, 1.1); | |
36 | m_line->add(1.0, 2.3); |
|
36 | m_line->add(1.0, 2.3); | |
37 | m_line->add(2.0, 2.1); |
|
37 | m_line->add(2.0, 2.1); | |
38 | m_line->add(3.0, 3.3); |
|
38 | m_line->add(3.0, 3.3); | |
39 | m_chartView->addSeries(m_line); |
|
39 | m_chartView->addSeries(m_line); | |
40 |
|
40 | |||
41 | // Create scatter series with the same data |
|
41 | // Create scatter series with the same data | |
42 | m_scatter = new QScatterSeries(); |
|
42 | m_scatter = new QScatterSeries(); | |
43 | m_scatter->add(m_line->data()); |
|
43 | m_scatter->add(m_line->data()); | |
44 | m_chartView->addSeries(m_scatter); |
|
44 | m_chartView->addSeries(m_scatter); | |
45 |
|
45 | |||
46 | // Create pie series with different data |
|
46 | // Create pie series with different data | |
47 | m_pie = new QPieSeries(); |
|
47 | m_pie = new QPieSeries(); | |
48 | m_pie->add(1.1, "1"); |
|
48 | m_pie->add(1.1, "1"); | |
49 | m_pie->add(2.1, "2"); |
|
49 | m_pie->add(2.1, "2"); | |
50 | m_pie->add(3.0, "3"); |
|
50 | m_pie->add(3.0, "3"); | |
51 | m_pie->setPiePosition(0.7, 0.7); |
|
51 | m_pie->setPiePosition(0.7, 0.7); | |
52 | m_pie->setPieSize(0.5); |
|
52 | m_pie->setPieSize(0.5); | |
53 | m_chartView->addSeries(m_pie); |
|
53 | m_chartView->addSeries(m_pie); | |
54 |
|
54 | |||
55 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize())); |
|
55 | connect(&m_timer, SIGNAL(timeout()), this, SLOT(customize())); | |
56 | m_timer.setInterval(1500); |
|
56 | m_timer.setInterval(1500); | |
57 | m_timer.setSingleShot(false); |
|
57 | m_timer.setSingleShot(false); | |
58 | m_timer.start(); |
|
58 | m_timer.start(); | |
59 | } |
|
59 | } | |
60 |
|
60 | |||
61 | MainWindow::~MainWindow() |
|
61 | MainWindow::~MainWindow() | |
62 | { |
|
62 | { | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void MainWindow::customize() |
|
65 | void MainWindow::customize() | |
66 | { |
|
66 | { | |
67 | //! [1] |
|
67 | //! [1] | |
68 | // Use a gradient from "color 3" to "color 4" for chart background |
|
68 | // Use a gradient from "color 3" to "color 4" for chart background | |
69 | QLinearGradient chartGradient(0, 0, 0, 300); |
|
69 | QLinearGradient chartGradient(0, 0, 0, 300); | |
70 | chartGradient.setColorAt(0.0, m_companyColor3); |
|
70 | chartGradient.setColorAt(0.0, m_companyColor3); | |
71 | chartGradient.setColorAt(0.5, m_companyColor4); |
|
71 | chartGradient.setColorAt(0.5, m_companyColor4); | |
72 | chartGradient.setColorAt(1.0, m_companyColor3); |
|
72 | chartGradient.setColorAt(1.0, m_companyColor3); | |
73 | m_chartView->setChartBackgroundBrush(chartGradient); |
|
73 | m_chartView->setChartBackgroundBrush(chartGradient); | |
74 | m_chartView->setBackgroundBrush(m_companyColor4); |
|
74 | m_chartView->setBackgroundBrush(m_companyColor4); | |
75 | m_chartView->setChartTitleBrush(m_companyColor1); |
|
75 | m_chartView->setChartTitleBrush(m_companyColor1); | |
76 | //! [1] |
|
76 | //! [1] | |
77 |
|
77 | |||
78 | //! [2] |
|
78 | //! [2] | |
79 | QPen color1Pen(m_companyColor1, 4.0); |
|
79 | QPen color1Pen(m_companyColor1, 4.0); | |
80 | m_chartView->axisX()->setAxisPen(color1Pen); |
|
80 | m_chartView->axisX()->setAxisPen(color1Pen); | |
81 | m_chartView->axisY()->setAxisPen(color1Pen); |
|
81 | m_chartView->axisY()->setAxisPen(color1Pen); | |
82 | //! [2] |
|
82 | //! [2] | |
83 |
|
83 | |||
84 | //! [3] |
|
84 | //! [3] | |
85 | // Customize pen of the line series |
|
85 | // Customize pen of the line series | |
86 | m_line->setPen(color1Pen); |
|
86 | m_line->setPen(color1Pen); | |
87 |
|
87 | |||
88 | // Customize pen and brush for the scatter |
|
88 | // Customize pen and brush for the scatter | |
89 | m_scatter->setPen(color1Pen); |
|
89 | m_scatter->setPen(color1Pen); | |
90 | m_scatter->setBrush(m_companyColor3); |
|
90 | m_scatter->setBrush(m_companyColor3); | |
91 |
|
91 | |||
92 | // Customize pen and brush for the pie |
|
92 | // Customize pen and brush for the pie | |
93 | for (int i(0); i < m_pie->slices().count(); i++) { |
|
93 | for (int i(0); i < m_pie->slices().count(); i++) { | |
94 | Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1); |
|
94 | Qt::BrushStyle style = static_cast<Qt::BrushStyle>(i + 1); | |
95 | m_pie->slices().at(i)->setBrush(QBrush(m_companyColor2, style)); |
|
95 | m_pie->slices().at(i)->setBrush(QBrush(m_companyColor2, style)); | |
96 | m_pie->slices().at(i)->setPen(color1Pen); |
|
96 | m_pie->slices().at(i)->setPen(color1Pen); | |
97 | } |
|
97 | } | |
98 | //! [3] |
|
98 | //! [3] | |
99 |
|
99 | |||
100 | // Calculate new colors to be used on the next update for the series |
|
100 | // Calculate new colors to be used on the next update for the series | |
101 | m_companyColor1.setRed((m_companyColor1.red() + 25) % 255); |
|
101 | m_companyColor1.setRed((m_companyColor1.red() + 25) % 255); | |
102 | m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255); |
|
102 | m_companyColor1.setGreen((m_companyColor1.green() + 25) % 255); | |
103 | m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255); |
|
103 | m_companyColor1.setBlue((m_companyColor1.blue() + 25) % 255); | |
104 | m_companyColor2.setRed((m_companyColor2.red() + 25) % 255); |
|
104 | m_companyColor2.setRed((m_companyColor2.red() + 25) % 255); | |
105 | m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255); |
|
105 | m_companyColor2.setGreen((m_companyColor2.green() + 25) % 255); | |
106 | m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255); |
|
106 | m_companyColor2.setBlue((m_companyColor2.blue() + 25) % 255); | |
107 | } |
|
107 | } |
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -1,149 +1,149 | |||||
1 | #include <QtGui/QApplication> |
|
1 | #include <QtGui/QApplication> | |
2 | #include <QMainWindow> |
|
2 | #include <QMainWindow> | |
3 | #include <qchartglobal.h> |
|
3 | #include <qchartglobal.h> | |
4 | #include <qchartview.h> |
|
4 | #include <qchartview.h> | |
5 | #include <qstackedbarseries.h> |
|
5 | #include <qstackedbarseries.h> | |
6 | #include <qbarset.h> |
|
6 | #include <qbarset.h> | |
7 | #include <qchartaxis.h> |
|
7 | #include <qchartaxis.h> | |
8 | #include <QStringList> |
|
8 | #include <QStringList> | |
9 | #include <QDebug> |
|
9 | #include <QDebug> | |
10 |
|
10 | |||
11 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
11 | QTCOMMERCIALCHART_USE_NAMESPACE | |
12 |
|
12 | |||
13 | //! [1] |
|
13 | //! [1] | |
14 | class DrilldownBarSeries : public QStackedBarSeries |
|
14 | class DrilldownBarSeries : public QStackedBarSeries | |
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 | DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {} |
|
18 | DrilldownBarSeries(QStringList categories, QObject *parent = 0) : QStackedBarSeries(categories,parent) {} | |
19 |
|
19 | |||
20 | void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) |
|
20 | void mapDrilldownSeries(QString category, DrilldownBarSeries* drilldownSeries) | |
21 | { |
|
21 | { | |
22 | mDrilldownSeries[category] = drilldownSeries; |
|
22 | mDrilldownSeries[category] = drilldownSeries; | |
23 | } |
|
23 | } | |
24 |
|
24 | |||
25 | DrilldownBarSeries* drilldownSeries(QString category) |
|
25 | DrilldownBarSeries* drilldownSeries(QString category) | |
26 | { |
|
26 | { | |
27 | return mDrilldownSeries[category]; |
|
27 | return mDrilldownSeries[category]; | |
28 | } |
|
28 | } | |
29 |
|
29 | |||
30 | public Q_SLOTS: |
|
30 | public Q_SLOTS: | |
31 |
|
31 | |||
32 | private: |
|
32 | private: | |
33 |
|
33 | |||
34 | QMap<QString, DrilldownBarSeries*> mDrilldownSeries; |
|
34 | QMap<QString, DrilldownBarSeries*> mDrilldownSeries; | |
35 | }; |
|
35 | }; | |
36 | //! [1] |
|
36 | //! [1] | |
37 |
|
37 | |||
38 | //! [2] |
|
38 | //! [2] | |
39 | class DrilldownChart : public QChartView |
|
39 | class DrilldownChart : public QChartView | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 | public: |
|
42 | public: | |
43 | explicit DrilldownChart(QWidget *parent = 0) : QChartView(parent), m_currentSeries(0) {} |
|
43 | explicit DrilldownChart(QWidget *parent = 0) : QChartView(parent), m_currentSeries(0) {} | |
44 |
|
44 | |||
45 | void changeSeries(QSeries* series) |
|
45 | void changeSeries(QSeries* series) | |
46 | { |
|
46 | { | |
47 | if (m_currentSeries) |
|
47 | if (m_currentSeries) | |
48 | removeSeries(m_currentSeries); |
|
48 | removeSeries(m_currentSeries); | |
49 | m_currentSeries = series; |
|
49 | m_currentSeries = series; | |
50 | addSeries(series); |
|
50 | addSeries(series); | |
51 | setChartTitle(series->name()); |
|
51 | setChartTitle(series->name()); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | public Q_SLOTS: |
|
54 | public Q_SLOTS: | |
55 | void handleRightClick(QBarSet *barset, QString category) |
|
55 | void handleRightClick(QBarSet *barset, QString category) | |
56 | { |
|
56 | { | |
57 | Q_UNUSED(barset) |
|
57 | Q_UNUSED(barset) | |
58 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); |
|
58 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); | |
59 | changeSeries(series->drilldownSeries(category)); |
|
59 | changeSeries(series->drilldownSeries(category)); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | private: |
|
62 | private: | |
63 | QSeries* m_currentSeries; |
|
63 | QSeries* m_currentSeries; | |
64 | }; |
|
64 | }; | |
65 | //! [2] |
|
65 | //! [2] | |
66 |
|
66 | |||
67 | int main(int argc, char *argv[]) |
|
67 | int main(int argc, char *argv[]) | |
68 | { |
|
68 | { | |
69 | QApplication a(argc, argv); |
|
69 | QApplication a(argc, argv); | |
70 | QMainWindow window; |
|
70 | QMainWindow window; | |
71 |
|
71 | |||
72 | DrilldownChart* drilldownChart = new DrilldownChart(&window); |
|
72 | DrilldownChart* drilldownChart = new DrilldownChart(&window); | |
73 | drilldownChart->setChartTheme(QChart::ChartThemeIcy); |
|
73 | drilldownChart->setChartTheme(QChart::ChartThemeBlueIcy); | |
74 |
|
74 | |||
75 | //! [3] |
|
75 | //! [3] | |
76 | // Define categories |
|
76 | // Define categories | |
77 | QStringList months; |
|
77 | QStringList months; | |
78 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; |
|
78 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; | |
79 | QStringList weeks; |
|
79 | QStringList weeks; | |
80 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
80 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; | |
81 | QStringList plants; |
|
81 | QStringList plants; | |
82 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
82 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; | |
83 | //! [3] |
|
83 | //! [3] | |
84 |
|
84 | |||
85 | //! [4] |
|
85 | //! [4] | |
86 | // Create drilldown structure |
|
86 | // Create drilldown structure | |
87 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); |
|
87 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); | |
88 | seasonSeries->setName("Crop by month - Season"); |
|
88 | seasonSeries->setName("Crop by month - Season"); | |
89 |
|
89 | |||
90 | // Each month in season series has drilldown series for weekly data |
|
90 | // Each month in season series has drilldown series for weekly data | |
91 | foreach (QString month, months) { |
|
91 | foreach (QString month, months) { | |
92 |
|
92 | |||
93 | // Create drilldown series for every week |
|
93 | // Create drilldown series for every week | |
94 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
94 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
95 | seasonSeries->mapDrilldownSeries(month, weeklySeries); |
|
95 | seasonSeries->mapDrilldownSeries(month, weeklySeries); | |
96 |
|
96 | |||
97 | // Drilling down from weekly data brings us back to season data. |
|
97 | // Drilling down from weekly data brings us back to season data. | |
98 | foreach (QString week, weeks) { |
|
98 | foreach (QString week, weeks) { | |
99 | weeklySeries->mapDrilldownSeries(week, seasonSeries); |
|
99 | weeklySeries->mapDrilldownSeries(week, seasonSeries); | |
100 | weeklySeries->setName(QString("Crop by week - " + month)); |
|
100 | weeklySeries->setName(QString("Crop by week - " + month)); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | // Use right click signal to implement drilldown |
|
103 | // Use right click signal to implement drilldown | |
104 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); |
|
104 | QObject::connect(weeklySeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | // Enable drilldown from season series using right click. |
|
107 | // Enable drilldown from season series using right click. | |
108 | QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); |
|
108 | QObject::connect(seasonSeries,SIGNAL(rightClicked(QBarSet*,QString)),drilldownChart,SLOT(handleRightClick(QBarSet*,QString))); | |
109 | //! [4] |
|
109 | //! [4] | |
110 |
|
110 | |||
111 | //! [5] |
|
111 | //! [5] | |
112 | // Fill monthly and weekly series with data |
|
112 | // Fill monthly and weekly series with data | |
113 | foreach (QString plant, plants) { |
|
113 | foreach (QString plant, plants) { | |
114 | QBarSet* monthlyCrop = new QBarSet(plant); |
|
114 | QBarSet* monthlyCrop = new QBarSet(plant); | |
115 | foreach (QString month, months) { |
|
115 | foreach (QString month, months) { | |
116 | QBarSet* weeklyCrop = new QBarSet(plant); |
|
116 | QBarSet* weeklyCrop = new QBarSet(plant); | |
117 | foreach (QString week, weeks ) { |
|
117 | foreach (QString week, weeks ) { | |
118 | *weeklyCrop << (qrand() % 20); |
|
118 | *weeklyCrop << (qrand() % 20); | |
119 | } |
|
119 | } | |
120 | // Get the drilldown series from season series and add crop to it. |
|
120 | // Get the drilldown series from season series and add crop to it. | |
121 | seasonSeries->drilldownSeries(month)->addBarSet(weeklyCrop); |
|
121 | seasonSeries->drilldownSeries(month)->addBarSet(weeklyCrop); | |
122 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); |
|
122 | seasonSeries->drilldownSeries(month)->setToolTipEnabled(true); | |
123 | *monthlyCrop << weeklyCrop->total(); |
|
123 | *monthlyCrop << weeklyCrop->total(); | |
124 |
|
124 | |||
125 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); |
|
125 | QObject::connect(weeklyCrop,SIGNAL(clicked(QString)),weeklyCrop,SIGNAL(toggleFloatingValues())); | |
126 | } |
|
126 | } | |
127 | seasonSeries->addBarSet(monthlyCrop); |
|
127 | seasonSeries->addBarSet(monthlyCrop); | |
128 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); |
|
128 | QObject::connect(monthlyCrop,SIGNAL(clicked(QString)),monthlyCrop,SIGNAL(toggleFloatingValues())); | |
129 | } |
|
129 | } | |
130 | //! [5] |
|
130 | //! [5] | |
131 |
|
131 | |||
132 | seasonSeries->setToolTipEnabled(true); |
|
132 | seasonSeries->setToolTipEnabled(true); | |
133 |
|
133 | |||
134 | //! [6] |
|
134 | //! [6] | |
135 | // Show season series in initial view |
|
135 | // Show season series in initial view | |
136 | drilldownChart->changeSeries(seasonSeries); |
|
136 | drilldownChart->changeSeries(seasonSeries); | |
137 | drilldownChart->setChartTitle(seasonSeries->name()); |
|
137 | drilldownChart->setChartTitle(seasonSeries->name()); | |
138 | //! [6] |
|
138 | //! [6] | |
139 |
|
139 | |||
140 | drilldownChart->axisX()->setGridLineVisible(false); |
|
140 | drilldownChart->axisX()->setGridLineVisible(false); | |
141 |
|
141 | |||
142 | window.setCentralWidget(drilldownChart); |
|
142 | window.setCentralWidget(drilldownChart); | |
143 | window.resize(400, 300); |
|
143 | window.resize(400, 300); | |
144 | window.show(); |
|
144 | window.show(); | |
145 |
|
145 | |||
146 | return a.exec(); |
|
146 | return a.exec(); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | #include "main.moc" |
|
149 | #include "main.moc" |
@@ -1,48 +1,48 | |||||
1 | #ifndef DECLARATIVECHART_H |
|
1 | #ifndef DECLARATIVECHART_H | |
2 | #define DECLARATIVECHART_H |
|
2 | #define DECLARATIVECHART_H | |
3 |
|
3 | |||
4 | #include <QtCore/QtGlobal> |
|
4 | #include <QtCore/QtGlobal> | |
5 | #include <QDeclarativeItem> |
|
5 | #include <QDeclarativeItem> | |
6 | #include <qchart.h> |
|
6 | #include <qchart.h> | |
7 |
|
7 | |||
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
9 |
|
9 | |||
10 | class DeclarativeChart : public QDeclarativeItem |
|
10 | class DeclarativeChart : public QDeclarativeItem | |
11 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
11 | // TODO: for QTQUICK2: extend QQuickPainterItem instead | |
12 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
12 | //class DeclarativeChart : public QQuickPaintedItem, public Chart | |
13 | { |
|
13 | { | |
14 | Q_OBJECT |
|
14 | Q_OBJECT | |
15 | Q_ENUMS(ChartTheme) |
|
15 | Q_ENUMS(ChartTheme) | |
16 | Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme) |
|
16 | Q_PROPERTY(ChartTheme theme READ theme WRITE setTheme) | |
17 |
|
17 | |||
18 | public: |
|
18 | public: | |
19 | enum ChartTheme { |
|
19 | enum ChartTheme { | |
20 | ThemeDefault, |
|
20 | ThemeDefault, | |
21 | ThemeLight, |
|
21 | ThemeLight, | |
22 | ThemeBlueCerulean, |
|
22 | ThemeBlueCerulean, | |
23 | ThemeDark, |
|
23 | ThemeDark, | |
24 | ThemeBrownSand, |
|
24 | ThemeBrownSand, | |
25 | ThemeBlueNcs, |
|
25 | ThemeBlueNcs, | |
26 |
Theme |
|
26 | ThemeHighContrast, | |
27 |
Theme |
|
27 | ThemeBlueIcy | |
28 | }; |
|
28 | }; | |
29 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
29 | DeclarativeChart(QDeclarativeItem *parent = 0); | |
30 | ~DeclarativeChart(); |
|
30 | ~DeclarativeChart(); | |
31 |
|
31 | |||
32 | public: // From QDeclarativeItem/QGraphicsItem |
|
32 | public: // From QDeclarativeItem/QGraphicsItem | |
33 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
33 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); | |
34 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
34 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
37 | void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartTheme) theme);} |
|
37 | void setTheme(ChartTheme theme) {m_chart->setTheme((QChart::ChartTheme) theme);} | |
38 | ChartTheme theme(); |
|
38 | ChartTheme theme(); | |
39 |
|
39 | |||
40 | public: |
|
40 | public: | |
41 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
41 | // Extending QChart with DeclarativeChart is not possible because QObject does not support | |
42 | // multi inheritance, so we now have a QChart as a member instead |
|
42 | // multi inheritance, so we now have a QChart as a member instead | |
43 | QChart *m_chart; |
|
43 | QChart *m_chart; | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
46 | QTCOMMERCIALCHART_END_NAMESPACE |
|
46 | QTCOMMERCIALCHART_END_NAMESPACE | |
47 |
|
47 | |||
48 | #endif // DECLARATIVECHART_H |
|
48 | #endif // DECLARATIVECHART_H |
@@ -1,380 +1,372 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 | #include "qchart.h" |
|
2 | #include "qchart.h" | |
3 | #include "qchartview.h" |
|
3 | #include "qchartview.h" | |
4 | #include "qlegend.h" |
|
4 | #include "qlegend.h" | |
5 | #include "qchartaxis.h" |
|
5 | #include "qchartaxis.h" | |
6 | #include <QTime> |
|
6 | #include <QTime> | |
7 |
|
7 | |||
8 | //series |
|
8 | //series | |
9 | #include "qbarset.h" |
|
9 | #include "qbarset.h" | |
10 | #include "qbarseries.h" |
|
10 | #include "qbarseries.h" | |
11 | #include "qstackedbarseries.h" |
|
11 | #include "qstackedbarseries.h" | |
12 | #include "qpercentbarseries.h" |
|
12 | #include "qpercentbarseries.h" | |
13 | #include "qlineseries.h" |
|
13 | #include "qlineseries.h" | |
14 | #include "qareaseries.h" |
|
14 | #include "qareaseries.h" | |
15 | #include "qscatterseries.h" |
|
15 | #include "qscatterseries.h" | |
16 | #include "qpieseries.h" |
|
16 | #include "qpieseries.h" | |
17 | #include "qpieslice.h" |
|
17 | #include "qpieslice.h" | |
18 | #include "qsplineseries.h" |
|
18 | #include "qsplineseries.h" | |
19 |
|
19 | |||
20 | //items |
|
20 | //items | |
21 | #include "axisitem_p.h" |
|
21 | #include "axisitem_p.h" | |
22 | #include "barchartitem_p.h" |
|
22 | #include "barchartitem_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "percentbarchartitem_p.h" |
|
24 | #include "percentbarchartitem_p.h" | |
25 | #include "linechartitem_p.h" |
|
25 | #include "linechartitem_p.h" | |
26 | #include "areachartitem_p.h" |
|
26 | #include "areachartitem_p.h" | |
27 | #include "scatterchartitem_p.h" |
|
27 | #include "scatterchartitem_p.h" | |
28 | #include "piechartitem_p.h" |
|
28 | #include "piechartitem_p.h" | |
29 | #include "splinechartitem_p.h" |
|
29 | #include "splinechartitem_p.h" | |
30 |
|
30 | |||
31 | //themes |
|
31 | //themes | |
32 | #include "chartthemedefault_p.h" |
|
32 | #include "chartthemedefault_p.h" | |
33 | #include "chartthemelight_p.h" |
|
33 | #include "chartthemelight_p.h" | |
34 | #include "chartthemebluecerulean_p.h" |
|
34 | #include "chartthemebluecerulean_p.h" | |
35 | #include "chartthemedark_p.h" |
|
35 | #include "chartthemedark_p.h" | |
36 | #include "chartthemebrownsand_p.h" |
|
36 | #include "chartthemebrownsand_p.h" | |
37 | #include "chartthemebluencs_p.h" |
|
37 | #include "chartthemebluencs_p.h" | |
38 |
#include "charttheme |
|
38 | #include "chartthemehighcontrast_p.h" | |
39 |
#include "charttheme |
|
39 | #include "chartthemeblueicy_p.h" | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
41 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
42 |
|
42 | |||
43 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
43 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
44 | m_masterFont(QFont("arial", 12)), |
|
44 | m_masterFont(QFont("arial", 12)), | |
45 | m_labelFont(QFont("arial", 10)), |
|
45 | m_labelFont(QFont("arial", 10)), | |
46 | m_titleBrush(QColor(QRgb(0x000000))), |
|
46 | m_titleBrush(QColor(QRgb(0x000000))), | |
47 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
47 | m_axisLinePen(QPen(QRgb(0x000000))), | |
48 | m_axisLabelBrush(QColor(QRgb(0x000000))), |
|
48 | m_axisLabelBrush(QColor(QRgb(0x000000))), | |
49 | m_backgroundShadesPen(Qt::NoPen), |
|
49 | m_backgroundShadesPen(Qt::NoPen), | |
50 | m_backgroundShadesBrush(Qt::NoBrush), |
|
50 | m_backgroundShadesBrush(Qt::NoBrush), | |
51 | m_backgroundShades(BackgroundShadesNone), |
|
51 | m_backgroundShades(BackgroundShadesNone), | |
52 | m_gridLinePen(QPen(QRgb(0x000000))) |
|
52 | m_gridLinePen(QPen(QRgb(0x000000))) | |
53 | { |
|
53 | { | |
54 | m_id = id; |
|
54 | m_id = id; | |
55 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
55 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 |
|
58 | |||
59 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
59 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
60 | { |
|
60 | { | |
61 | switch(theme) { |
|
61 | switch(theme) { | |
62 | case QChart::ChartThemeLight: |
|
62 | case QChart::ChartThemeLight: | |
63 | return new ChartThemeLight(); |
|
63 | return new ChartThemeLight(); | |
64 | case QChart::ChartThemeBlueCerulean: |
|
64 | case QChart::ChartThemeBlueCerulean: | |
65 | return new ChartThemeBlueCerulean(); |
|
65 | return new ChartThemeBlueCerulean(); | |
66 | case QChart::ChartThemeDark: |
|
66 | case QChart::ChartThemeDark: | |
67 | return new ChartThemeDark(); |
|
67 | return new ChartThemeDark(); | |
68 | case QChart::ChartThemeBrownSand: |
|
68 | case QChart::ChartThemeBrownSand: | |
69 | return new ChartThemeBrownSand(); |
|
69 | return new ChartThemeBrownSand(); | |
70 | case QChart::ChartThemeBlueNcs: |
|
70 | case QChart::ChartThemeBlueNcs: | |
71 | return new ChartThemeBlueNcs(); |
|
71 | return new ChartThemeBlueNcs(); | |
72 |
case QChart::ChartTheme |
|
72 | case QChart::ChartThemeHighContrast: | |
73 |
return new ChartTheme |
|
73 | return new ChartThemeHighContrast(); | |
74 |
case QChart::ChartTheme |
|
74 | case QChart::ChartThemeBlueIcy: | |
75 |
return new ChartTheme |
|
75 | return new ChartThemeBlueIcy(); | |
76 | default: |
|
76 | default: | |
77 | return new ChartThemeDefault(); |
|
77 | return new ChartThemeDefault(); | |
78 | } |
|
78 | } | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void ChartTheme::decorate(QChart* chart,bool force) |
|
81 | void ChartTheme::decorate(QChart* chart,bool force) | |
82 | { |
|
82 | { | |
83 | QPen pen; |
|
|||
84 | QBrush brush; |
|
83 | QBrush brush; | |
85 |
|
84 | |||
86 | if(brush == chart->backgroundBrush() || force) |
|
85 | if(brush == chart->backgroundBrush() || force) | |
87 | { |
|
|||
88 | if (m_backgroundShades == BackgroundShadesNone) { |
|
|||
89 |
|
|
86 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
90 | } |
|
|||
91 | else { |
|
|||
92 | chart->setBackgroundBrush(Qt::NoBrush); |
|
|||
93 | } |
|
|||
94 | } |
|
|||
95 | chart->setTitleFont(m_masterFont); |
|
87 | chart->setTitleFont(m_masterFont); | |
96 | chart->setTitleBrush(m_titleBrush); |
|
88 | chart->setTitleBrush(m_titleBrush); | |
97 | } |
|
89 | } | |
98 |
|
90 | |||
99 | void ChartTheme::decorate(QLegend* legend,bool force) |
|
91 | void ChartTheme::decorate(QLegend* legend,bool force) | |
100 | { |
|
92 | { | |
101 | QPen pen; |
|
93 | QPen pen; | |
102 | QBrush brush; |
|
94 | QBrush brush; | |
103 |
|
95 | |||
104 | if (pen == legend->pen() || force){ |
|
96 | if (pen == legend->pen() || force){ | |
105 | //TODO:: legend->setPen(); |
|
97 | //TODO:: legend->setPen(); | |
106 | } |
|
98 | } | |
107 |
|
99 | |||
108 |
|
100 | |||
109 | if (brush == legend->brush() || force) { |
|
101 | if (brush == legend->brush() || force) { | |
110 | legend->setBrush(m_chartBackgroundGradient); |
|
102 | legend->setBrush(m_chartBackgroundGradient); | |
111 | } |
|
103 | } | |
112 | } |
|
104 | } | |
113 |
|
105 | |||
114 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) |
|
106 | void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |
115 | { |
|
107 | { | |
116 | QPen pen; |
|
108 | QPen pen; | |
117 | QBrush brush; |
|
109 | QBrush brush; | |
118 |
|
110 | |||
119 | if (pen == series->pen() || force){ |
|
111 | if (pen == series->pen() || force){ | |
120 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
112 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
121 | pen.setWidthF(2); |
|
113 | pen.setWidthF(2); | |
122 | series->setPen(pen); |
|
114 | series->setPen(pen); | |
123 | } |
|
115 | } | |
124 |
|
116 | |||
125 | if (brush == series->brush() || force) { |
|
117 | if (brush == series->brush() || force) { | |
126 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
118 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
127 | series->setBrush(brush); |
|
119 | series->setBrush(brush); | |
128 | } |
|
120 | } | |
129 | } |
|
121 | } | |
130 |
|
122 | |||
131 |
|
123 | |||
132 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) |
|
124 | void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |
133 | { |
|
125 | { | |
134 | QPen pen; |
|
126 | QPen pen; | |
135 | if(pen == series->pen() || force ){ |
|
127 | if(pen == series->pen() || force ){ | |
136 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
128 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
137 | pen.setWidthF(2); |
|
129 | pen.setWidthF(2); | |
138 | series->setPen(pen); |
|
130 | series->setPen(pen); | |
139 | } |
|
131 | } | |
140 | } |
|
132 | } | |
141 |
|
133 | |||
142 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) |
|
134 | void ChartTheme::decorate(QBarSeries* series, int index, bool force) | |
143 | { |
|
135 | { | |
144 | QBrush brush; |
|
136 | QBrush brush; | |
145 | QPen pen; |
|
137 | QPen pen; | |
146 | QList<QBarSet*> sets = series->barSets(); |
|
138 | QList<QBarSet*> sets = series->barSets(); | |
147 |
|
139 | |||
148 | qreal takeAtPos = 0.5; |
|
140 | qreal takeAtPos = 0.5; | |
149 | qreal step = 0.2; |
|
141 | qreal step = 0.2; | |
150 | if (sets.count() > 1 ) { |
|
142 | if (sets.count() > 1 ) { | |
151 | step = 1.0 / (qreal) sets.count(); |
|
143 | step = 1.0 / (qreal) sets.count(); | |
152 | if (sets.count() % m_seriesGradients.count()) |
|
144 | if (sets.count() % m_seriesGradients.count()) | |
153 | step *= m_seriesGradients.count(); |
|
145 | step *= m_seriesGradients.count(); | |
154 | else |
|
146 | else | |
155 | step *= (m_seriesGradients.count() - 1); |
|
147 | step *= (m_seriesGradients.count() - 1); | |
156 | } |
|
148 | } | |
157 |
|
149 | |||
158 | for (int i(0); i < sets.count(); i++) { |
|
150 | for (int i(0); i < sets.count(); i++) { | |
159 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
151 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
160 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
152 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
161 | // There is no dedicated base color for each sets, generate more colors |
|
153 | // There is no dedicated base color for each sets, generate more colors | |
162 | takeAtPos += step; |
|
154 | takeAtPos += step; | |
163 | if (takeAtPos == 1.0) |
|
155 | if (takeAtPos == 1.0) | |
164 | takeAtPos += step; |
|
156 | takeAtPos += step; | |
165 | takeAtPos -= (int) takeAtPos; |
|
157 | takeAtPos -= (int) takeAtPos; | |
166 | } |
|
158 | } | |
167 | qDebug() << "pos:" << takeAtPos; |
|
159 | qDebug() << "pos:" << takeAtPos; | |
168 | if (brush == sets.at(i)->brush() || force ) |
|
160 | if (brush == sets.at(i)->brush() || force ) | |
169 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
161 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
170 |
|
162 | |||
171 | // Pick label color from the opposite end of the gradient. |
|
163 | // Pick label color from the opposite end of the gradient. | |
172 | // 0.3 as a boundary seems to work well. |
|
164 | // 0.3 as a boundary seems to work well. | |
173 | if (takeAtPos < 0.3) |
|
165 | if (takeAtPos < 0.3) | |
174 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
166 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
175 | else |
|
167 | else | |
176 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
168 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
177 |
|
169 | |||
178 | if (pen == sets.at(i)->pen() || force) { |
|
170 | if (pen == sets.at(i)->pen() || force) { | |
179 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
171 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
180 | sets.at(i)->setPen(c); |
|
172 | sets.at(i)->setPen(c); | |
181 | } |
|
173 | } | |
182 | } |
|
174 | } | |
183 | } |
|
175 | } | |
184 |
|
176 | |||
185 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) |
|
177 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |
186 | { |
|
178 | { | |
187 | QPen pen; |
|
179 | QPen pen; | |
188 | QBrush brush; |
|
180 | QBrush brush; | |
189 |
|
181 | |||
190 | if (pen == series->pen() || force) { |
|
182 | if (pen == series->pen() || force) { | |
191 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
183 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
192 | pen.setWidthF(2); |
|
184 | pen.setWidthF(2); | |
193 | series->setPen(pen); |
|
185 | series->setPen(pen); | |
194 | } |
|
186 | } | |
195 |
|
187 | |||
196 | if (brush == series->brush() || force) { |
|
188 | if (brush == series->brush() || force) { | |
197 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
189 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
198 | series->setBrush(brush); |
|
190 | series->setBrush(brush); | |
199 | } |
|
191 | } | |
200 | } |
|
192 | } | |
201 |
|
193 | |||
202 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
194 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) | |
203 | { |
|
195 | { | |
204 | for (int i(0); i < series->slices().count(); i++) { |
|
196 | for (int i(0); i < series->slices().count(); i++) { | |
205 |
|
197 | |||
206 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
198 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
207 |
|
199 | |||
208 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
200 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
209 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
201 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
210 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
202 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
211 |
|
203 | |||
212 | QPieSlice::DataPtr s = series->slices().at(i)->data_ptr(); |
|
204 | QPieSlice::DataPtr s = series->slices().at(i)->data_ptr(); | |
213 | PieSliceData data = s->m_data; |
|
205 | PieSliceData data = s->m_data; | |
214 |
|
206 | |||
215 | if (data.m_slicePen.isThemed() || force) { |
|
207 | if (data.m_slicePen.isThemed() || force) { | |
216 | data.m_slicePen = penColor; |
|
208 | data.m_slicePen = penColor; | |
217 | data.m_slicePen.setThemed(true); |
|
209 | data.m_slicePen.setThemed(true); | |
218 | } |
|
210 | } | |
219 |
|
211 | |||
220 | if (data.m_sliceBrush.isThemed() || force) { |
|
212 | if (data.m_sliceBrush.isThemed() || force) { | |
221 | data.m_sliceBrush = brushColor; |
|
213 | data.m_sliceBrush = brushColor; | |
222 | data.m_sliceBrush.setThemed(true); |
|
214 | data.m_sliceBrush.setThemed(true); | |
223 | } |
|
215 | } | |
224 |
|
216 | |||
225 | if (data.m_labelPen.isThemed() || force) { |
|
217 | if (data.m_labelPen.isThemed() || force) { | |
226 | data.m_labelPen = QPen(m_titleBrush.color()); |
|
218 | data.m_labelPen = QPen(m_titleBrush.color()); | |
227 | data.m_labelPen.setThemed(true); |
|
219 | data.m_labelPen.setThemed(true); | |
228 | } |
|
220 | } | |
229 |
|
221 | |||
230 | if (data.m_labelFont.isThemed() || force) { |
|
222 | if (data.m_labelFont.isThemed() || force) { | |
231 | data.m_labelFont = m_labelFont; |
|
223 | data.m_labelFont = m_labelFont; | |
232 | data.m_labelFont.setThemed(true); |
|
224 | data.m_labelFont.setThemed(true); | |
233 | } |
|
225 | } | |
234 |
|
226 | |||
235 | if (s->m_data != data) { |
|
227 | if (s->m_data != data) { | |
236 | s->m_data = data; |
|
228 | s->m_data = data; | |
237 | emit s->changed(); |
|
229 | emit s->changed(); | |
238 | } |
|
230 | } | |
239 | } |
|
231 | } | |
240 | } |
|
232 | } | |
241 |
|
233 | |||
242 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) |
|
234 | void ChartTheme::decorate(QSplineSeries* series, int index, bool force) | |
243 | { |
|
235 | { | |
244 | QPen pen; |
|
236 | QPen pen; | |
245 | if(pen == series->pen() || force){ |
|
237 | if(pen == series->pen() || force){ | |
246 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
238 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
247 | pen.setWidthF(2); |
|
239 | pen.setWidthF(2); | |
248 | series->setPen(pen); |
|
240 | series->setPen(pen); | |
249 | } |
|
241 | } | |
250 | } |
|
242 | } | |
251 |
|
243 | |||
252 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) |
|
244 | void ChartTheme::decorate(QChartAxis* axis,bool axisX, bool force) | |
253 | { |
|
245 | { | |
254 | QPen pen; |
|
246 | QPen pen; | |
255 | QBrush brush; |
|
247 | QBrush brush; | |
256 | QFont font; |
|
248 | QFont font; | |
257 |
|
249 | |||
258 | if (axis->isAxisVisible()) { |
|
250 | if (axis->isAxisVisible()) { | |
259 |
|
251 | |||
260 | if(brush == axis->labelsBrush() || force){ |
|
252 | if(brush == axis->labelsBrush() || force){ | |
261 | axis->setLabelsBrush(m_axisLabelBrush); |
|
253 | axis->setLabelsBrush(m_axisLabelBrush); | |
262 | } |
|
254 | } | |
263 | if(pen == axis->labelsPen() || force){ |
|
255 | if(pen == axis->labelsPen() || force){ | |
264 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
256 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
265 | } |
|
257 | } | |
266 |
|
258 | |||
267 |
|
259 | |||
268 | if (axis->shadesVisible() || force) { |
|
260 | if (axis->shadesVisible() || force) { | |
269 |
|
261 | |||
270 | if(brush == axis->shadesBrush() || force){ |
|
262 | if(brush == axis->shadesBrush() || force){ | |
271 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
263 | axis->setShadesBrush(m_backgroundShadesBrush); | |
272 | } |
|
264 | } | |
273 |
|
265 | |||
274 | if(pen == axis->shadesPen() || force){ |
|
266 | if(pen == axis->shadesPen() || force){ | |
275 | axis->setShadesPen(m_backgroundShadesPen); |
|
267 | axis->setShadesPen(m_backgroundShadesPen); | |
276 | } |
|
268 | } | |
277 |
|
269 | |||
278 | if(force && (m_backgroundShades == BackgroundShadesBoth |
|
270 | if(force && (m_backgroundShades == BackgroundShadesBoth | |
279 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
271 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
280 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
272 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
281 | axis->setShadesVisible(true); |
|
273 | axis->setShadesVisible(true); | |
282 |
|
274 | |||
283 | } |
|
275 | } | |
284 | } |
|
276 | } | |
285 |
|
277 | |||
286 | if(pen == axis->axisPen() || force){ |
|
278 | if(pen == axis->axisPen() || force){ | |
287 | axis->setAxisPen(m_axisLinePen); |
|
279 | axis->setAxisPen(m_axisLinePen); | |
288 | } |
|
280 | } | |
289 |
|
281 | |||
290 | if(pen == axis->gridLinePen() || force){ |
|
282 | if(pen == axis->gridLinePen() || force){ | |
291 | axis->setGridLinePen(m_gridLinePen); |
|
283 | axis->setGridLinePen(m_gridLinePen); | |
292 | } |
|
284 | } | |
293 |
|
285 | |||
294 | if(font == axis->labelsFont() || force){ |
|
286 | if(font == axis->labelsFont() || force){ | |
295 | axis->setLabelsFont(m_labelFont); |
|
287 | axis->setLabelsFont(m_labelFont); | |
296 | } |
|
288 | } | |
297 | } |
|
289 | } | |
298 | } |
|
290 | } | |
299 |
|
291 | |||
300 | void ChartTheme::generateSeriesGradients() |
|
292 | void ChartTheme::generateSeriesGradients() | |
301 | { |
|
293 | { | |
302 | // Generate gradients in HSV color space |
|
294 | // Generate gradients in HSV color space | |
303 | foreach (QColor color, m_seriesColors) { |
|
295 | foreach (QColor color, m_seriesColors) { | |
304 | QLinearGradient g; |
|
296 | QLinearGradient g; | |
305 | qreal h = color.hsvHueF(); |
|
297 | qreal h = color.hsvHueF(); | |
306 | qreal s = color.hsvSaturationF(); |
|
298 | qreal s = color.hsvSaturationF(); | |
307 |
|
299 | |||
308 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
300 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
309 | // most themes. The rest of the gradients we can define manually in theme specific |
|
301 | // most themes. The rest of the gradients we can define manually in theme specific | |
310 | // implementation. |
|
302 | // implementation. | |
311 | QColor start = color; |
|
303 | QColor start = color; | |
312 | start.setHsvF(h, 0.0, 1.0); |
|
304 | start.setHsvF(h, 0.0, 1.0); | |
313 | g.setColorAt(0.0, start); |
|
305 | g.setColorAt(0.0, start); | |
314 |
|
306 | |||
315 | g.setColorAt(0.5, color); |
|
307 | g.setColorAt(0.5, color); | |
316 |
|
308 | |||
317 | QColor end = color; |
|
309 | QColor end = color; | |
318 | end.setHsvF(h, s, 0.25); |
|
310 | end.setHsvF(h, s, 0.25); | |
319 | g.setColorAt(1.0, end); |
|
311 | g.setColorAt(1.0, end); | |
320 |
|
312 | |||
321 | m_seriesGradients << g; |
|
313 | m_seriesGradients << g; | |
322 | } |
|
314 | } | |
323 | } |
|
315 | } | |
324 |
|
316 | |||
325 |
|
317 | |||
326 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
318 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
327 | { |
|
319 | { | |
328 | Q_ASSERT(pos >=0.0 && pos <= 1.0); |
|
320 | Q_ASSERT(pos >=0.0 && pos <= 1.0); | |
329 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
321 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
330 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
322 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
331 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
323 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
332 | QColor c; |
|
324 | QColor c; | |
333 | c.setRgbF(r, g, b); |
|
325 | c.setRgbF(r, g, b); | |
334 | return c; |
|
326 | return c; | |
335 | } |
|
327 | } | |
336 |
|
328 | |||
337 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
329 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
338 | { |
|
330 | { | |
339 | Q_ASSERT(pos >=0 && pos <= 1.0); |
|
331 | Q_ASSERT(pos >=0 && pos <= 1.0); | |
340 |
|
332 | |||
341 | // another possibility: |
|
333 | // another possibility: | |
342 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient |
|
334 | // http://stackoverflow.com/questions/3306786/get-intermediate-color-from-a-gradient | |
343 |
|
335 | |||
344 | QGradientStops stops = gradient.stops(); |
|
336 | QGradientStops stops = gradient.stops(); | |
345 | int count = stops.count(); |
|
337 | int count = stops.count(); | |
346 |
|
338 | |||
347 | // find previous stop relative to position |
|
339 | // find previous stop relative to position | |
348 | QGradientStop prev = stops.first(); |
|
340 | QGradientStop prev = stops.first(); | |
349 | for (int i=0; i<count; i++) { |
|
341 | for (int i=0; i<count; i++) { | |
350 | QGradientStop stop = stops.at(i); |
|
342 | QGradientStop stop = stops.at(i); | |
351 | if (pos > stop.first) |
|
343 | if (pos > stop.first) | |
352 | prev = stop; |
|
344 | prev = stop; | |
353 |
|
345 | |||
354 | // given position is actually a stop position? |
|
346 | // given position is actually a stop position? | |
355 | if (pos == stop.first) { |
|
347 | if (pos == stop.first) { | |
356 | //qDebug() << "stop color" << pos; |
|
348 | //qDebug() << "stop color" << pos; | |
357 | return stop.second; |
|
349 | return stop.second; | |
358 | } |
|
350 | } | |
359 | } |
|
351 | } | |
360 |
|
352 | |||
361 | // find next stop relative to position |
|
353 | // find next stop relative to position | |
362 | QGradientStop next = stops.last(); |
|
354 | QGradientStop next = stops.last(); | |
363 | for (int i=count-1; i>=0; i--) { |
|
355 | for (int i=count-1; i>=0; i--) { | |
364 | QGradientStop stop = stops.at(i); |
|
356 | QGradientStop stop = stops.at(i); | |
365 | if (pos < stop.first) |
|
357 | if (pos < stop.first) | |
366 | next = stop; |
|
358 | next = stop; | |
367 | } |
|
359 | } | |
368 |
|
360 | |||
369 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
361 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
370 |
|
362 | |||
371 | qreal range = next.first - prev.first; |
|
363 | qreal range = next.first - prev.first; | |
372 | qreal posDelta = pos - prev.first; |
|
364 | qreal posDelta = pos - prev.first; | |
373 | qreal relativePos = posDelta / range; |
|
365 | qreal relativePos = posDelta / range; | |
374 |
|
366 | |||
375 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
367 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
376 |
|
368 | |||
377 | return colorAt(prev.second, next.second, relativePos); |
|
369 | return colorAt(prev.second, next.second, relativePos); | |
378 | } |
|
370 | } | |
379 |
|
371 | |||
380 | QTCOMMERCIALCHART_END_NAMESPACE |
|
372 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,459 +1,459 | |||||
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 "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include <QGraphicsScene> |
|
23 | #include <QGraphicsScene> | |
24 | #include <QGraphicsSceneResizeEvent> |
|
24 | #include <QGraphicsSceneResizeEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \enum QChart::ChartTheme |
|
29 | \enum QChart::ChartTheme | |
30 |
|
30 | |||
31 | This enum describes the theme used by the chart. |
|
31 | This enum describes the theme used by the chart. | |
32 |
|
32 | |||
33 | \value ChartThemeDefault Follows the GUI style of the Operating System |
|
33 | \value ChartThemeDefault Follows the GUI style of the Operating System | |
34 | \value ChartThemeLight |
|
34 | \value ChartThemeLight | |
35 | \value ChartThemeBlueCerulean |
|
35 | \value ChartThemeBlueCerulean | |
36 | \value ChartThemeDark |
|
36 | \value ChartThemeDark | |
37 | \value ChartThemeBrownSand |
|
37 | \value ChartThemeBrownSand | |
38 | \value ChartThemeBlueNcs |
|
38 | \value ChartThemeBlueNcs | |
39 |
\value ChartTheme |
|
39 | \value ChartThemeHighContrast | |
40 |
\value ChartTheme |
|
40 | \value ChartThemeBlueIcy | |
41 | \value ChartThemeCount Not really a theme; the total count of themes. |
|
41 | \value ChartThemeCount Not really a theme; the total count of themes. | |
42 | */ |
|
42 | */ | |
43 |
|
43 | |||
44 | /*! |
|
44 | /*! | |
45 | \enum QChart::AnimationOption |
|
45 | \enum QChart::AnimationOption | |
46 |
|
46 | |||
47 | For enabling/disabling animations. Defaults to NoAnimation. |
|
47 | For enabling/disabling animations. Defaults to NoAnimation. | |
48 |
|
48 | |||
49 | \value NoAnimation |
|
49 | \value NoAnimation | |
50 | \value GridAxisAnimations |
|
50 | \value GridAxisAnimations | |
51 | \value SeriesAnimations |
|
51 | \value SeriesAnimations | |
52 | \value AllAnimations |
|
52 | \value AllAnimations | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \class QChart |
|
56 | \class QChart | |
57 | \brief QtCommercial chart API. |
|
57 | \brief QtCommercial chart API. | |
58 |
|
58 | |||
59 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
59 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
60 | representation of different types of QChartSeries and other chart related objects like |
|
60 | representation of different types of QChartSeries and other chart related objects like | |
61 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the |
|
61 | QChartAxis and QChartLegend. If you simply want to show a chart in a layout, you can use the | |
62 | convenience class QChartView instead of QChart. |
|
62 | convenience class QChartView instead of QChart. | |
63 | \sa QChartView |
|
63 | \sa QChartView | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
67 | Constructs a chart object which is a child of a\a parent. Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
68 | */ |
|
68 | */ | |
69 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), |
|
69 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), | |
70 | d_ptr(new QChartPrivate(this)) |
|
70 | d_ptr(new QChartPrivate(this)) | |
71 | { |
|
71 | { | |
72 | d_ptr->m_legend = new QLegend(this); |
|
72 | d_ptr->m_legend = new QLegend(this); | |
73 | d_ptr->m_dataset = new ChartDataSet(this); |
|
73 | d_ptr->m_dataset = new ChartDataSet(this); | |
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); |
|
74 | d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); | |
75 |
|
75 | |||
76 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
76 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
77 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
77 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. |
|
81 | Destroys the object and it's children, like QChartSeries and QChartAxis object added to it. | |
82 | */ |
|
82 | */ | |
83 | QChart::~QChart() |
|
83 | QChart::~QChart() | |
84 | { |
|
84 | { | |
85 | //delete first presenter , since this is a root of all the graphical items |
|
85 | //delete first presenter , since this is a root of all the graphical items | |
86 | delete d_ptr->m_presenter; |
|
86 | delete d_ptr->m_presenter; | |
87 | d_ptr->m_presenter=0; |
|
87 | d_ptr->m_presenter=0; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. |
|
91 | Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects. | |
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
92 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and | |
93 | the y axis). |
|
93 | the y axis). | |
94 | */ |
|
94 | */ | |
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) |
|
95 | void QChart::addSeries(QSeries* series, QChartAxis* axisY) | |
96 | { |
|
96 | { | |
97 | d_ptr->m_dataset->addSeries(series, axisY); |
|
97 | d_ptr->m_dataset->addSeries(series, axisY); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | Removes the \a series specified in a perameter from the QChartView. |
|
101 | Removes the \a series specified in a perameter from the QChartView. | |
102 | It releses its ownership of the specified QChartSeries object. |
|
102 | It releses its ownership of the specified QChartSeries object. | |
103 | It does not delete the pointed QChartSeries data object |
|
103 | It does not delete the pointed QChartSeries data object | |
104 | \sa addSeries(), removeAllSeries() |
|
104 | \sa addSeries(), removeAllSeries() | |
105 | */ |
|
105 | */ | |
106 | void QChart::removeSeries(QSeries* series) |
|
106 | void QChart::removeSeries(QSeries* series) | |
107 | { |
|
107 | { | |
108 | d_ptr->m_dataset->removeSeries(series); |
|
108 | d_ptr->m_dataset->removeSeries(series); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | Removes all the QChartSeries that have been added to the QChartView |
|
112 | Removes all the QChartSeries that have been added to the QChartView | |
113 | It also deletes the pointed QChartSeries data objects |
|
113 | It also deletes the pointed QChartSeries data objects | |
114 | \sa addSeries(), removeSeries() |
|
114 | \sa addSeries(), removeSeries() | |
115 | */ |
|
115 | */ | |
116 | void QChart::removeAllSeries() |
|
116 | void QChart::removeAllSeries() | |
117 | { |
|
117 | { | |
118 | d_ptr->m_dataset->removeAllSeries(); |
|
118 | d_ptr->m_dataset->removeAllSeries(); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | Sets the \a brush that is used for painting the background of the chart area. |
|
122 | Sets the \a brush that is used for painting the background of the chart area. | |
123 | */ |
|
123 | */ | |
124 | void QChart::setBackgroundBrush(const QBrush& brush) |
|
124 | void QChart::setBackgroundBrush(const QBrush& brush) | |
125 | { |
|
125 | { | |
126 | d_ptr->createChartBackgroundItem(); |
|
126 | d_ptr->createChartBackgroundItem(); | |
127 | d_ptr->m_backgroundItem->setBrush(brush); |
|
127 | d_ptr->m_backgroundItem->setBrush(brush); | |
128 | d_ptr->m_backgroundItem->update(); |
|
128 | d_ptr->m_backgroundItem->update(); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | QBrush QChart::backgroundBrush() const |
|
131 | QBrush QChart::backgroundBrush() const | |
132 | { |
|
132 | { | |
133 | if (!d_ptr->m_backgroundItem) return QBrush(); |
|
133 | if (!d_ptr->m_backgroundItem) return QBrush(); | |
134 | return (d_ptr->m_backgroundItem)->brush(); |
|
134 | return (d_ptr->m_backgroundItem)->brush(); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | Sets the \a pen that is used for painting the background of the chart area. |
|
138 | Sets the \a pen that is used for painting the background of the chart area. | |
139 | */ |
|
139 | */ | |
140 | void QChart::setBackgroundPen(const QPen& pen) |
|
140 | void QChart::setBackgroundPen(const QPen& pen) | |
141 | { |
|
141 | { | |
142 | d_ptr->createChartBackgroundItem(); |
|
142 | d_ptr->createChartBackgroundItem(); | |
143 | d_ptr->m_backgroundItem->setPen(pen); |
|
143 | d_ptr->m_backgroundItem->setPen(pen); | |
144 | d_ptr->m_backgroundItem->update(); |
|
144 | d_ptr->m_backgroundItem->update(); | |
145 | } |
|
145 | } | |
146 |
|
146 | |||
147 | QPen QChart::backgroundPen() const |
|
147 | QPen QChart::backgroundPen() const | |
148 | { |
|
148 | { | |
149 | if (!d_ptr->m_backgroundItem) return QPen(); |
|
149 | if (!d_ptr->m_backgroundItem) return QPen(); | |
150 | return d_ptr->m_backgroundItem->pen(); |
|
150 | return d_ptr->m_backgroundItem->pen(); | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | Sets the chart \a title. The description text that is drawn above the chart. |
|
154 | Sets the chart \a title. The description text that is drawn above the chart. | |
155 | */ |
|
155 | */ | |
156 | void QChart::setTitle(const QString& title) |
|
156 | void QChart::setTitle(const QString& title) | |
157 | { |
|
157 | { | |
158 | d_ptr->createChartTitleItem(); |
|
158 | d_ptr->createChartTitleItem(); | |
159 | d_ptr->m_titleItem->setText(title); |
|
159 | d_ptr->m_titleItem->setText(title); | |
160 | d_ptr->updateLayout(); |
|
160 | d_ptr->updateLayout(); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | Returns the chart title. The description text that is drawn above the chart. |
|
164 | Returns the chart title. The description text that is drawn above the chart. | |
165 | */ |
|
165 | */ | |
166 | QString QChart::title() const |
|
166 | QString QChart::title() const | |
167 | { |
|
167 | { | |
168 | if (d_ptr->m_titleItem) |
|
168 | if (d_ptr->m_titleItem) | |
169 | return d_ptr->m_titleItem->text(); |
|
169 | return d_ptr->m_titleItem->text(); | |
170 | else |
|
170 | else | |
171 | return QString(); |
|
171 | return QString(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | Sets the \a font that is used for rendering the description text that is rendered above the chart. |
|
175 | Sets the \a font that is used for rendering the description text that is rendered above the chart. | |
176 | */ |
|
176 | */ | |
177 | void QChart::setTitleFont(const QFont& font) |
|
177 | void QChart::setTitleFont(const QFont& font) | |
178 | { |
|
178 | { | |
179 | d_ptr->createChartTitleItem(); |
|
179 | d_ptr->createChartTitleItem(); | |
180 | d_ptr->m_titleItem->setFont(font); |
|
180 | d_ptr->m_titleItem->setFont(font); | |
181 | d_ptr->updateLayout(); |
|
181 | d_ptr->updateLayout(); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | Sets the \a brush used for rendering the title text. |
|
185 | Sets the \a brush used for rendering the title text. | |
186 | */ |
|
186 | */ | |
187 | void QChart::setTitleBrush(const QBrush &brush) |
|
187 | void QChart::setTitleBrush(const QBrush &brush) | |
188 | { |
|
188 | { | |
189 | d_ptr->createChartTitleItem(); |
|
189 | d_ptr->createChartTitleItem(); | |
190 | d_ptr->m_titleItem->setBrush(brush); |
|
190 | d_ptr->m_titleItem->setBrush(brush); | |
191 | d_ptr->updateLayout(); |
|
191 | d_ptr->updateLayout(); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | Returns the brush used for rendering the title text. |
|
195 | Returns the brush used for rendering the title text. | |
196 | */ |
|
196 | */ | |
197 | QBrush QChart::titleBrush() const |
|
197 | QBrush QChart::titleBrush() const | |
198 | { |
|
198 | { | |
199 | if (!d_ptr->m_titleItem) return QBrush(); |
|
199 | if (!d_ptr->m_titleItem) return QBrush(); | |
200 | return d_ptr->m_titleItem->brush(); |
|
200 | return d_ptr->m_titleItem->brush(); | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Sets the \a theme used by the chart for rendering the graphical representation of the data |
|
204 | Sets the \a theme used by the chart for rendering the graphical representation of the data | |
205 | \sa ChartTheme, chartTheme() |
|
205 | \sa ChartTheme, chartTheme() | |
206 | */ |
|
206 | */ | |
207 | void QChart::setTheme(QChart::ChartTheme theme) |
|
207 | void QChart::setTheme(QChart::ChartTheme theme) | |
208 | { |
|
208 | { | |
209 | d_ptr->m_presenter->setTheme(theme); |
|
209 | d_ptr->m_presenter->setTheme(theme); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Returns the theme enum used by the chart. |
|
213 | Returns the theme enum used by the chart. | |
214 | \sa ChartTheme, setChartTheme() |
|
214 | \sa ChartTheme, setChartTheme() | |
215 | */ |
|
215 | */ | |
216 | QChart::ChartTheme QChart::theme() const |
|
216 | QChart::ChartTheme QChart::theme() const | |
217 | { |
|
217 | { | |
218 | return d_ptr->m_presenter->theme(); |
|
218 | return d_ptr->m_presenter->theme(); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | Zooms in the view by a factor of 2 |
|
222 | Zooms in the view by a factor of 2 | |
223 | */ |
|
223 | */ | |
224 | void QChart::zoomIn() |
|
224 | void QChart::zoomIn() | |
225 | { |
|
225 | { | |
226 | d_ptr->m_presenter->zoomIn(); |
|
226 | d_ptr->m_presenter->zoomIn(); | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
230 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
231 | */ |
|
231 | */ | |
232 | void QChart::zoomIn(const QRectF& rect) |
|
232 | void QChart::zoomIn(const QRectF& rect) | |
233 | { |
|
233 | { | |
234 | if (!rect.isValid()) return; |
|
234 | if (!rect.isValid()) return; | |
235 | d_ptr->m_presenter->zoomIn(rect); |
|
235 | d_ptr->m_presenter->zoomIn(rect); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | /*! |
|
238 | /*! | |
239 | Restores the view zoom level to the previous one. |
|
239 | Restores the view zoom level to the previous one. | |
240 | */ |
|
240 | */ | |
241 | void QChart::zoomOut() |
|
241 | void QChart::zoomOut() | |
242 | { |
|
242 | { | |
243 | d_ptr->m_presenter->zoomOut(); |
|
243 | d_ptr->m_presenter->zoomOut(); | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | /*! |
|
246 | /*! | |
247 | Returns the pointer to the x axis object of the chart |
|
247 | Returns the pointer to the x axis object of the chart | |
248 | */ |
|
248 | */ | |
249 | QChartAxis* QChart::axisX() const |
|
249 | QChartAxis* QChart::axisX() const | |
250 | { |
|
250 | { | |
251 | return d_ptr->m_dataset->axisX(); |
|
251 | return d_ptr->m_dataset->axisX(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | Returns the pointer to the y axis object of the chart |
|
255 | Returns the pointer to the y axis object of the chart | |
256 | */ |
|
256 | */ | |
257 | QChartAxis* QChart::axisY() const |
|
257 | QChartAxis* QChart::axisY() const | |
258 | { |
|
258 | { | |
259 | return d_ptr->m_dataset->axisY(); |
|
259 | return d_ptr->m_dataset->axisY(); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | /*! |
|
262 | /*! | |
263 | Returns the legend object of the chart. Ownership stays in chart. |
|
263 | Returns the legend object of the chart. Ownership stays in chart. | |
264 | */ |
|
264 | */ | |
265 | QLegend& QChart::legend() const |
|
265 | QLegend& QChart::legend() const | |
266 | { |
|
266 | { | |
267 | return *d_ptr->m_legend; |
|
267 | return *d_ptr->m_legend; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /*! |
|
270 | /*! | |
271 | Gives ownership of legend to user. |
|
271 | Gives ownership of legend to user. | |
272 | */ |
|
272 | */ | |
273 | QLegend* QChart::takeLegend() |
|
273 | QLegend* QChart::takeLegend() | |
274 | { |
|
274 | { | |
275 | QLegend* l = d_ptr->m_legend; |
|
275 | QLegend* l = d_ptr->m_legend; | |
276 | d_ptr->m_legend = 0; |
|
276 | d_ptr->m_legend = 0; | |
277 | return l; |
|
277 | return l; | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | /*! |
|
280 | /*! | |
281 | Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one |
|
281 | Gives ownership of legend back to chart. QChart takes ownership of \a legend and deletes existing one | |
282 | */ |
|
282 | */ | |
283 | void QChart::giveLegend(QLegend *legend) |
|
283 | void QChart::giveLegend(QLegend *legend) | |
284 | { |
|
284 | { | |
285 | if (d_ptr->m_legend) { |
|
285 | if (d_ptr->m_legend) { | |
286 | // Should not happen. |
|
286 | // Should not happen. | |
287 | qDebug() << "Warning! Giving more than one legend to chart."; |
|
287 | qDebug() << "Warning! Giving more than one legend to chart."; | |
288 | delete d_ptr->m_legend; |
|
288 | delete d_ptr->m_legend; | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | d_ptr->m_legend = legend; |
|
291 | d_ptr->m_legend = legend; | |
292 |
|
292 | |||
293 | // Reconnect legend, in case not already connected. |
|
293 | // Reconnect legend, in case not already connected. | |
294 | disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
294 | disconnect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
295 | disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
295 | disconnect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
296 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); |
|
296 | connect(d_ptr->m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),d_ptr->m_legend,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
297 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); |
|
297 | connect(d_ptr->m_dataset,SIGNAL(seriesRemoved(QSeries*)),d_ptr->m_legend,SLOT(handleSeriesRemoved(QSeries*))); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | /*! |
|
300 | /*! | |
301 | Resizes and updates the chart area using the \a event data |
|
301 | Resizes and updates the chart area using the \a event data | |
302 | */ |
|
302 | */ | |
303 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
303 | void QChart::resizeEvent(QGraphicsSceneResizeEvent *event) | |
304 | { |
|
304 | { | |
305 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); |
|
305 | d_ptr->m_rect = QRectF(QPoint(0,0),event->newSize()); | |
306 | d_ptr->updateLayout(); |
|
306 | d_ptr->updateLayout(); | |
307 | QGraphicsWidget::resizeEvent(event); |
|
307 | QGraphicsWidget::resizeEvent(event); | |
308 | update(); |
|
308 | update(); | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | /*! |
|
311 | /*! | |
312 | Sets animation \a options for the chart |
|
312 | Sets animation \a options for the chart | |
313 | */ |
|
313 | */ | |
314 | void QChart::setAnimationOptions(AnimationOptions options) |
|
314 | void QChart::setAnimationOptions(AnimationOptions options) | |
315 | { |
|
315 | { | |
316 | d_ptr->m_presenter->setAnimationOptions(options); |
|
316 | d_ptr->m_presenter->setAnimationOptions(options); | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | /*! |
|
319 | /*! | |
320 | Returns animation options for the chart |
|
320 | Returns animation options for the chart | |
321 | */ |
|
321 | */ | |
322 | QChart::AnimationOptions QChart::animationOptions() const |
|
322 | QChart::AnimationOptions QChart::animationOptions() const | |
323 | { |
|
323 | { | |
324 | return d_ptr->m_presenter->animationOptions(); |
|
324 | return d_ptr->m_presenter->animationOptions(); | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | void QChart::scrollLeft() |
|
327 | void QChart::scrollLeft() | |
328 | { |
|
328 | { | |
329 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
329 | d_ptr->m_presenter->scroll(-d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void QChart::scrollRight() |
|
332 | void QChart::scrollRight() | |
333 | { |
|
333 | { | |
334 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); |
|
334 | d_ptr->m_presenter->scroll(d_ptr->m_presenter->geometry().width()/(axisX()->ticksCount()-1),0); | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void QChart::scrollUp() |
|
337 | void QChart::scrollUp() | |
338 | { |
|
338 | { | |
339 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
339 | d_ptr->m_presenter->scroll(0,d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | void QChart::scrollDown() |
|
342 | void QChart::scrollDown() | |
343 | { |
|
343 | { | |
344 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); |
|
344 | d_ptr->m_presenter->scroll(0,-d_ptr->m_presenter->geometry().width()/(axisY()->ticksCount()-1)); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void QChart::setBackgroundVisible(bool visible) |
|
347 | void QChart::setBackgroundVisible(bool visible) | |
348 | { |
|
348 | { | |
349 | d_ptr->createChartBackgroundItem(); |
|
349 | d_ptr->createChartBackgroundItem(); | |
350 | d_ptr->m_backgroundItem->setVisible(visible); |
|
350 | d_ptr->m_backgroundItem->setVisible(visible); | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | bool QChart::isBackgroundVisible() const |
|
353 | bool QChart::isBackgroundVisible() const | |
354 | { |
|
354 | { | |
355 | if (!d_ptr->m_backgroundItem) return false; |
|
355 | if (!d_ptr->m_backgroundItem) return false; | |
356 | return d_ptr->m_backgroundItem->isVisible(); |
|
356 | return d_ptr->m_backgroundItem->isVisible(); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
359 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
360 |
|
360 | |||
361 | QChartPrivate::QChartPrivate(QChart *parent): |
|
361 | QChartPrivate::QChartPrivate(QChart *parent): | |
362 | q_ptr(parent), |
|
362 | q_ptr(parent), | |
363 | m_backgroundItem(0), |
|
363 | m_backgroundItem(0), | |
364 | m_titleItem(0), |
|
364 | m_titleItem(0), | |
365 | m_legend(0), |
|
365 | m_legend(0), | |
366 | m_dataset(0), |
|
366 | m_dataset(0), | |
367 | m_presenter(0) |
|
367 | m_presenter(0) | |
368 | { |
|
368 | { | |
369 |
|
369 | |||
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | QChartPrivate::~QChartPrivate() |
|
372 | QChartPrivate::~QChartPrivate() | |
373 | { |
|
373 | { | |
374 |
|
374 | |||
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | void QChartPrivate::createChartBackgroundItem() |
|
377 | void QChartPrivate::createChartBackgroundItem() | |
378 | { |
|
378 | { | |
379 | if (!m_backgroundItem) { |
|
379 | if (!m_backgroundItem) { | |
380 | m_backgroundItem = new ChartBackground(q_ptr); |
|
380 | m_backgroundItem = new ChartBackground(q_ptr); | |
381 | m_backgroundItem->setPen(Qt::NoPen); |
|
381 | m_backgroundItem->setPen(Qt::NoPen); | |
382 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); |
|
382 | m_backgroundItem->setZValue(ChartPresenter::BackgroundZValue); | |
383 | } |
|
383 | } | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | void QChartPrivate::createChartTitleItem() |
|
386 | void QChartPrivate::createChartTitleItem() | |
387 | { |
|
387 | { | |
388 | if (!m_titleItem) { |
|
388 | if (!m_titleItem) { | |
389 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); |
|
389 | m_titleItem = new QGraphicsSimpleTextItem(q_ptr); | |
390 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); |
|
390 | m_titleItem->setZValue(ChartPresenter::BackgroundZValue); | |
391 | } |
|
391 | } | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | void QChartPrivate::updateLegendLayout() |
|
394 | void QChartPrivate::updateLegendLayout() | |
395 | { |
|
395 | { | |
396 | int padding = m_presenter->padding(); |
|
396 | int padding = m_presenter->padding(); | |
397 | QRectF plotRect = m_rect.adjusted(padding,padding,-padding,-padding); |
|
397 | QRectF plotRect = m_rect.adjusted(padding,padding,-padding,-padding); | |
398 | QRectF legendRect; |
|
398 | QRectF legendRect; | |
399 |
|
399 | |||
400 | switch (m_legend->preferredLayout()) |
|
400 | switch (m_legend->preferredLayout()) | |
401 | { |
|
401 | { | |
402 | case QLegend::PreferredLayoutTop: { |
|
402 | case QLegend::PreferredLayoutTop: { | |
403 | // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height()); |
|
403 | // legendRect = plotRect.adjusted(m_padding,0,-m_padding,-m_padding - plotRect.height()); | |
404 | legendRect = plotRect.adjusted(0,0,0,-padding - plotRect.height()); |
|
404 | legendRect = plotRect.adjusted(0,0,0,-padding - plotRect.height()); | |
405 | break; |
|
405 | break; | |
406 | } |
|
406 | } | |
407 | case QLegend::PreferredLayoutBottom: { |
|
407 | case QLegend::PreferredLayoutBottom: { | |
408 | legendRect = plotRect.adjusted(padding,padding + plotRect.height(),-padding,0); |
|
408 | legendRect = plotRect.adjusted(padding,padding + plotRect.height(),-padding,0); | |
409 | break; |
|
409 | break; | |
410 | } |
|
410 | } | |
411 | case QLegend::PreferredLayoutLeft: { |
|
411 | case QLegend::PreferredLayoutLeft: { | |
412 | legendRect = plotRect.adjusted(0,padding,-padding - plotRect.width(),-padding); |
|
412 | legendRect = plotRect.adjusted(0,padding,-padding - plotRect.width(),-padding); | |
413 | break; |
|
413 | break; | |
414 | } |
|
414 | } | |
415 | case QLegend::PreferredLayoutRight: { |
|
415 | case QLegend::PreferredLayoutRight: { | |
416 | legendRect = plotRect.adjusted(padding + plotRect.width(),padding,0,-padding); |
|
416 | legendRect = plotRect.adjusted(padding + plotRect.width(),padding,0,-padding); | |
417 | break; |
|
417 | break; | |
418 | } |
|
418 | } | |
419 | default: { |
|
419 | default: { | |
420 | legendRect = plotRect; |
|
420 | legendRect = plotRect; | |
421 | break; |
|
421 | break; | |
422 | } |
|
422 | } | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | m_legend->setMaximumSize(legendRect.size()); |
|
425 | m_legend->setMaximumSize(legendRect.size()); | |
426 | m_legend->setPos(legendRect.topLeft()); |
|
426 | m_legend->setPos(legendRect.topLeft()); | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | void QChartPrivate::updateLayout() |
|
429 | void QChartPrivate::updateLayout() | |
430 | { |
|
430 | { | |
431 | if (!m_rect.isValid()) return; |
|
431 | if (!m_rect.isValid()) return; | |
432 |
|
432 | |||
433 | int padding = m_presenter->padding(); |
|
433 | int padding = m_presenter->padding(); | |
434 | int backgroundPadding = m_presenter->backgroundPadding(); |
|
434 | int backgroundPadding = m_presenter->backgroundPadding(); | |
435 |
|
435 | |||
436 | QRectF rect = m_rect.adjusted(padding,padding,-padding,-padding); |
|
436 | QRectF rect = m_rect.adjusted(padding,padding,-padding,-padding); | |
437 |
|
437 | |||
438 | // recalculate title position |
|
438 | // recalculate title position | |
439 | if (m_titleItem) { |
|
439 | if (m_titleItem) { | |
440 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); |
|
440 | QPointF center = m_rect.center() -m_titleItem->boundingRect().center(); | |
441 | m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2); |
|
441 | m_titleItem->setPos(center.x(),m_rect.top()/2 + padding/2); | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | //recalculate background gradient |
|
444 | //recalculate background gradient | |
445 | if (m_backgroundItem) { |
|
445 | if (m_backgroundItem) { | |
446 | m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding)); |
|
446 | m_backgroundItem->setRect(m_rect.adjusted(backgroundPadding,backgroundPadding, -backgroundPadding, -backgroundPadding)); | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | // recalculate legend position |
|
449 | // recalculate legend position | |
450 | if (m_legend) { |
|
450 | if (m_legend) { | |
451 | if (m_legend->parentObject() == q_ptr) { |
|
451 | if (m_legend->parentObject() == q_ptr) { | |
452 | updateLegendLayout(); |
|
452 | updateLegendLayout(); | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | #include "moc_qchart.cpp" |
|
457 | #include "moc_qchart.cpp" | |
458 |
|
458 | |||
459 | QTCOMMERCIALCHART_END_NAMESPACE |
|
459 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,117 +1,117 | |||||
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 QCHART_H |
|
21 | #ifndef QCHART_H | |
22 | #define QCHART_H |
|
22 | #define QCHART_H | |
23 |
|
23 | |||
24 | #include <QSeries> |
|
24 | #include <QSeries> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 |
|
26 | |||
27 | class QGraphicsSceneResizeEvent; |
|
27 | class QGraphicsSceneResizeEvent; | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QSeries; |
|
31 | class QSeries; | |
32 | class QChartAxis; |
|
32 | class QChartAxis; | |
33 | class QLegend; |
|
33 | class QLegend; | |
34 | class QChartPrivate; |
|
34 | class QChartPrivate; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget |
|
36 | class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | public: |
|
39 | public: | |
40 | enum ChartTheme { |
|
40 | enum ChartTheme { | |
41 | ChartThemeDefault, |
|
41 | ChartThemeDefault, | |
42 | ChartThemeLight, |
|
42 | ChartThemeLight, | |
43 | ChartThemeBlueCerulean, |
|
43 | ChartThemeBlueCerulean, | |
44 | ChartThemeDark, |
|
44 | ChartThemeDark, | |
45 | ChartThemeBrownSand, |
|
45 | ChartThemeBrownSand, | |
46 | ChartThemeBlueNcs, |
|
46 | ChartThemeBlueNcs, | |
47 |
ChartTheme |
|
47 | ChartThemeHighContrast, | |
48 |
ChartTheme |
|
48 | ChartThemeBlueIcy, | |
49 | ChartThemeCount |
|
49 | ChartThemeCount | |
50 | }; |
|
50 | }; | |
51 |
|
51 | |||
52 | enum AnimationOption { |
|
52 | enum AnimationOption { | |
53 | NoAnimation = 0x0, |
|
53 | NoAnimation = 0x0, | |
54 | GridAxisAnimations = 0x1, |
|
54 | GridAxisAnimations = 0x1, | |
55 | SeriesAnimations =0x2, |
|
55 | SeriesAnimations =0x2, | |
56 | AllAnimations = 0x3 |
|
56 | AllAnimations = 0x3 | |
57 | }; |
|
57 | }; | |
58 |
|
58 | |||
59 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) |
|
59 | Q_DECLARE_FLAGS(AnimationOptions, AnimationOption) | |
60 |
|
60 | |||
61 | public: |
|
61 | public: | |
62 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
62 | explicit QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
63 | ~QChart(); |
|
63 | ~QChart(); | |
64 |
|
64 | |||
65 | void addSeries(QSeries *series, QChartAxis *axisY = 0); |
|
65 | void addSeries(QSeries *series, QChartAxis *axisY = 0); | |
66 | void removeSeries(QSeries *series); |
|
66 | void removeSeries(QSeries *series); | |
67 | void removeAllSeries(); |
|
67 | void removeAllSeries(); | |
68 |
|
68 | |||
69 | void setTheme(QChart::ChartTheme theme); |
|
69 | void setTheme(QChart::ChartTheme theme); | |
70 | QChart::ChartTheme theme() const; |
|
70 | QChart::ChartTheme theme() const; | |
71 |
|
71 | |||
72 | void setTitle(const QString& title); |
|
72 | void setTitle(const QString& title); | |
73 | QString title() const; |
|
73 | QString title() const; | |
74 | void setTitleFont(const QFont& font); |
|
74 | void setTitleFont(const QFont& font); | |
75 | QFont titleFont() const; |
|
75 | QFont titleFont() const; | |
76 | void setTitleBrush(const QBrush &brush); |
|
76 | void setTitleBrush(const QBrush &brush); | |
77 | QBrush titleBrush() const; |
|
77 | QBrush titleBrush() const; | |
78 | void setBackgroundBrush(const QBrush& brush); |
|
78 | void setBackgroundBrush(const QBrush& brush); | |
79 | QBrush backgroundBrush() const; |
|
79 | QBrush backgroundBrush() const; | |
80 | void setBackgroundPen(const QPen& pen); |
|
80 | void setBackgroundPen(const QPen& pen); | |
81 | QPen backgroundPen() const; |
|
81 | QPen backgroundPen() const; | |
82 |
|
82 | |||
83 | void setBackgroundVisible(bool visible); |
|
83 | void setBackgroundVisible(bool visible); | |
84 | bool isBackgroundVisible() const; |
|
84 | bool isBackgroundVisible() const; | |
85 |
|
85 | |||
86 | void setAnimationOptions(AnimationOptions options); |
|
86 | void setAnimationOptions(AnimationOptions options); | |
87 | AnimationOptions animationOptions() const; |
|
87 | AnimationOptions animationOptions() const; | |
88 |
|
88 | |||
89 | void zoomIn(); |
|
89 | void zoomIn(); | |
90 | void zoomIn(const QRectF& rect); |
|
90 | void zoomIn(const QRectF& rect); | |
91 | void zoomOut(); |
|
91 | void zoomOut(); | |
92 | void scrollLeft(); |
|
92 | void scrollLeft(); | |
93 | void scrollRight(); |
|
93 | void scrollRight(); | |
94 | void scrollUp(); |
|
94 | void scrollUp(); | |
95 | void scrollDown(); |
|
95 | void scrollDown(); | |
96 |
|
96 | |||
97 | QChartAxis* axisX() const; |
|
97 | QChartAxis* axisX() const; | |
98 | QChartAxis* axisY() const; |
|
98 | QChartAxis* axisY() const; | |
99 |
|
99 | |||
100 | QLegend& legend() const; |
|
100 | QLegend& legend() const; | |
101 | QLegend* takeLegend(); |
|
101 | QLegend* takeLegend(); | |
102 | void giveLegend(QLegend* legend); |
|
102 | void giveLegend(QLegend* legend); | |
103 |
|
103 | |||
104 | protected: |
|
104 | protected: | |
105 | void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
105 | void resizeEvent(QGraphicsSceneResizeEvent *event); | |
106 |
|
106 | |||
107 | protected: |
|
107 | protected: | |
108 | QScopedPointer<QChartPrivate> d_ptr; |
|
108 | QScopedPointer<QChartPrivate> d_ptr; | |
109 | friend class QChartView; |
|
109 | friend class QChartView; | |
110 | Q_DISABLE_COPY(QChart); |
|
110 | Q_DISABLE_COPY(QChart); | |
111 | }; |
|
111 | }; | |
112 |
|
112 | |||
113 | QTCOMMERCIALCHART_END_NAMESPACE |
|
113 | QTCOMMERCIALCHART_END_NAMESPACE | |
114 |
|
114 | |||
115 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) |
|
115 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions) | |
116 |
|
116 | |||
117 | #endif |
|
117 | #endif |
@@ -1,34 +1,36 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | class ChartThemeIcy: public ChartTheme |
|
5 | class ChartThemeBlueIcy: public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 | ChartThemeIcy() : ChartTheme(QChart::ChartThemeIcy) |
|
8 | ChartThemeBlueIcy() : ChartTheme(QChart::ChartThemeBlueIcy) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series colors | |
11 |
m_seriesColors << QRgb(0x |
|
11 | m_seriesColors << QRgb(0x3daeda); | |
12 | m_seriesColors << QRgb(0x2685bf); |
|
12 | m_seriesColors << QRgb(0x2685bf); | |
13 |
m_seriesColors << QRgb(0x3 |
|
13 | m_seriesColors << QRgb(0x0c2673); | |
14 |
m_seriesColors << QRgb(0x |
|
14 | m_seriesColors << QRgb(0x5f3dba); | |
|
15 | m_seriesColors << QRgb(0x2fa3b4); | |||
15 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
16 |
|
17 | |||
17 | // Background |
|
18 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
19 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
19 |
backgroundGradient.setColorAt(0.0, QRgb(0x |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
20 |
backgroundGradient.setColorAt(1.0, QRgb(0xf |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 | m_chartBackgroundGradient = backgroundGradient; |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
23 |
|
24 | |||
24 | // Axes and other |
|
25 | // Axes and other | |
25 |
m_ |
|
26 | m_titleBrush = QBrush(QRgb(0x404044)); | |
|
27 | m_axisLinePen = QPen(QRgb(0xd6d6d6)); | |||
26 | m_axisLinePen.setWidth(2); |
|
28 | m_axisLinePen.setWidth(2); | |
27 |
m_axisLabelBrush = QBrush(QRgb(0x |
|
29 | m_axisLabelBrush = QBrush(QRgb(0x404044)); | |
28 |
m_gridLinePen = QPen(QRgb(0x |
|
30 | m_gridLinePen = QPen(QRgb(0xe2e2e2)); | |
29 |
m_gridLinePen.setWidth( |
|
31 | m_gridLinePen.setWidth(1); | |
30 | m_backgroundShades = BackgroundShadesNone; |
|
32 | m_backgroundShades = BackgroundShadesNone; | |
31 | } |
|
33 | } | |
32 | }; |
|
34 | }; | |
33 |
|
35 | |||
34 | QTCOMMERCIALCHART_END_NAMESPACE |
|
36 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,35 +1,37 | |||||
1 | #include "charttheme_p.h" |
|
1 | #include "charttheme_p.h" | |
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 |
class ChartTheme |
|
5 | class ChartThemeHighContrast : public ChartTheme | |
6 | { |
|
6 | { | |
7 | public: |
|
7 | public: | |
8 |
ChartTheme |
|
8 | ChartThemeHighContrast() : ChartTheme(QChart::ChartThemeHighContrast) | |
9 | { |
|
9 | { | |
10 | // Series |
|
10 | // Series colors | |
11 | m_seriesColors << QRgb(0xFFAD00); |
|
|||
12 | m_seriesColors << QRgb(0x596A75); |
|
|||
13 | m_seriesColors << QRgb(0x202020); |
|
11 | m_seriesColors << QRgb(0x202020); | |
14 |
m_seriesColors << QRgb(0x |
|
12 | m_seriesColors << QRgb(0x596a74); | |
|
13 | m_seriesColors << QRgb(0xffab03); | |||
|
14 | m_seriesColors << QRgb(0x038e9b); | |||
|
15 | m_seriesColors << QRgb(0xff4a41); | |||
15 | generateSeriesGradients(); |
|
16 | generateSeriesGradients(); | |
16 |
|
17 | |||
17 | // Background |
|
18 | // Background | |
18 | QLinearGradient backgroundGradient; |
|
19 | QLinearGradient backgroundGradient(0.5, 0.0, 0.5, 1.0); | |
19 |
backgroundGradient.setColorAt(0.0, QRgb(0xfff |
|
20 | backgroundGradient.setColorAt(0.0, QRgb(0xffffff)); | |
20 |
backgroundGradient.setColorAt(1.0, QRgb(0xfff |
|
21 | backgroundGradient.setColorAt(1.0, QRgb(0xffffff)); | |
21 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); |
|
22 | backgroundGradient.setCoordinateMode(QGradient::ObjectBoundingMode); | |
22 | m_chartBackgroundGradient = backgroundGradient; |
|
23 | m_chartBackgroundGradient = backgroundGradient; | |
23 |
|
24 | |||
24 | // Axes and other |
|
25 | // Axes and other | |
25 | m_axisLinePen = QPen(QRgb(0x0f0f0f)); |
|
26 | m_titleBrush = QBrush(QRgb(0x181818)); | |
|
27 | m_axisLinePen = QPen(QRgb(0x8c8c8c)); | |||
26 | m_axisLinePen.setWidth(2); |
|
28 | m_axisLinePen.setWidth(2); | |
27 |
m_axisLabelBrush = QBrush(QRgb(0x |
|
29 | m_axisLabelBrush = QBrush(QRgb(0x181818)); | |
28 |
m_gridLinePen = QPen(QRgb(0x |
|
30 | m_gridLinePen = QPen(QRgb(0x8c8c8c)); | |
29 |
m_gridLinePen.setWidth( |
|
31 | m_gridLinePen.setWidth(1); | |
30 |
m_backgroundShadesBrush = QBrush(Q |
|
32 | m_backgroundShadesBrush = QBrush(QRgb(0xffeecd)); | |
31 | m_backgroundShades = BackgroundShadesHorizontal; |
|
33 | m_backgroundShades = BackgroundShadesHorizontal; | |
32 | } |
|
34 | } | |
33 | }; |
|
35 | }; | |
34 |
|
36 | |||
35 | QTCOMMERCIALCHART_END_NAMESPACE |
|
37 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,12 +1,12 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | THEMES += \ |
|
4 | THEMES += \ | |
5 | $$PWD/chartthemedefault_p.h \ |
|
5 | $$PWD/chartthemedefault_p.h \ | |
6 | $$PWD/chartthemelight_p.h \ |
|
6 | $$PWD/chartthemelight_p.h \ | |
7 | $$PWD/chartthemebluecerulean_p.h \ |
|
7 | $$PWD/chartthemebluecerulean_p.h \ | |
8 | $$PWD/chartthemedark_p.h \ |
|
8 | $$PWD/chartthemedark_p.h \ | |
9 | $$PWD/chartthemebrownsand_p.h \ |
|
9 | $$PWD/chartthemebrownsand_p.h \ | |
10 | $$PWD/chartthemebluencs_p.h \ |
|
10 | $$PWD/chartthemebluencs_p.h \ | |
11 |
$$PWD/charttheme |
|
11 | $$PWD/chartthemehighcontrast_p.h \ | |
12 |
$$PWD/charttheme |
|
12 | $$PWD/chartthemeblueicy_p.h |
@@ -1,333 +1,333 | |||||
1 | #include "mainwidget.h" |
|
1 | #include "mainwidget.h" | |
2 | #include "dataseriedialog.h" |
|
2 | #include "dataseriedialog.h" | |
3 | #include <qpieseries.h> |
|
3 | #include <qpieseries.h> | |
4 | #include <qscatterseries.h> |
|
4 | #include <qscatterseries.h> | |
5 | #include <qlineseries.h> |
|
5 | #include <qlineseries.h> | |
6 | #include <qareaseries.h> |
|
6 | #include <qareaseries.h> | |
7 | #include <qsplineseries.h> |
|
7 | #include <qsplineseries.h> | |
8 | #include <qbarset.h> |
|
8 | #include <qbarset.h> | |
9 | #include <qbarseries.h> |
|
9 | #include <qbarseries.h> | |
10 | #include <qstackedbarseries.h> |
|
10 | #include <qstackedbarseries.h> | |
11 | #include <qpercentbarseries.h> |
|
11 | #include <qpercentbarseries.h> | |
12 | #include <QPushButton> |
|
12 | #include <QPushButton> | |
13 | #include <QComboBox> |
|
13 | #include <QComboBox> | |
14 | #include <QSpinBox> |
|
14 | #include <QSpinBox> | |
15 | #include <QCheckBox> |
|
15 | #include <QCheckBox> | |
16 | #include <QGridLayout> |
|
16 | #include <QGridLayout> | |
17 | #include <QHBoxLayout> |
|
17 | #include <QHBoxLayout> | |
18 | #include <QLabel> |
|
18 | #include <QLabel> | |
19 | #include <QSpacerItem> |
|
19 | #include <QSpacerItem> | |
20 | #include <QMessageBox> |
|
20 | #include <QMessageBox> | |
21 | #include <cmath> |
|
21 | #include <cmath> | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QStandardItemModel> |
|
23 | #include <QStandardItemModel> | |
24 |
|
24 | |||
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
26 | QTCOMMERCIALCHART_USE_NAMESPACE | |
27 |
|
27 | |||
28 | MainWidget::MainWidget(QWidget *parent) : |
|
28 | MainWidget::MainWidget(QWidget *parent) : | |
29 | QWidget(parent), |
|
29 | QWidget(parent), | |
30 | m_addSerieDialog(0), |
|
30 | m_addSerieDialog(0), | |
31 | m_chartView(0) |
|
31 | m_chartView(0) | |
32 | { |
|
32 | { | |
33 | m_chartView = new QChartView(this); |
|
33 | m_chartView = new QChartView(this); | |
34 | m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand); |
|
34 | m_chartView->setRubberBandPolicy(QChartView::HorizonalRubberBand); | |
35 |
|
35 | |||
36 | // Grid layout for the controls for configuring the chart widget |
|
36 | // Grid layout for the controls for configuring the chart widget | |
37 | QGridLayout *grid = new QGridLayout(); |
|
37 | QGridLayout *grid = new QGridLayout(); | |
38 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
38 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
39 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
39 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
40 | grid->addWidget(addSeriesButton, 0, 1); |
|
40 | grid->addWidget(addSeriesButton, 0, 1); | |
41 | initBackroundCombo(grid); |
|
41 | initBackroundCombo(grid); | |
42 | initScaleControls(grid); |
|
42 | initScaleControls(grid); | |
43 | initThemeCombo(grid); |
|
43 | initThemeCombo(grid); | |
44 | initCheckboxes(grid); |
|
44 | initCheckboxes(grid); | |
45 |
|
45 | |||
46 | // add row with empty label to make all the other rows static |
|
46 | // add row with empty label to make all the other rows static | |
47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
47 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
48 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
48 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
49 |
|
49 | |||
50 | // Another grid layout as a main layout |
|
50 | // Another grid layout as a main layout | |
51 | QGridLayout *mainLayout = new QGridLayout(); |
|
51 | QGridLayout *mainLayout = new QGridLayout(); | |
52 | mainLayout->addLayout(grid, 0, 0); |
|
52 | mainLayout->addLayout(grid, 0, 0); | |
53 |
|
53 | |||
54 | // Add layouts and the chart widget to the main layout |
|
54 | // Add layouts and the chart widget to the main layout | |
55 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
55 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
56 | setLayout(mainLayout); |
|
56 | setLayout(mainLayout); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | // Combo box for selecting the chart's background |
|
59 | // Combo box for selecting the chart's background | |
60 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
60 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
61 | { |
|
61 | { | |
62 | QComboBox *backgroundCombo = new QComboBox(this); |
|
62 | QComboBox *backgroundCombo = new QComboBox(this); | |
63 | backgroundCombo->addItem("Color"); |
|
63 | backgroundCombo->addItem("Color"); | |
64 | backgroundCombo->addItem("Gradient"); |
|
64 | backgroundCombo->addItem("Gradient"); | |
65 | backgroundCombo->addItem("Image"); |
|
65 | backgroundCombo->addItem("Image"); | |
66 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
66 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
67 | this, SLOT(backgroundChanged(int))); |
|
67 | this, SLOT(backgroundChanged(int))); | |
68 |
|
68 | |||
69 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
69 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
70 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
70 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | // Scale related controls (auto-scale vs. manual min-max values) |
|
73 | // Scale related controls (auto-scale vs. manual min-max values) | |
74 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
74 | void MainWidget::initScaleControls(QGridLayout *grid) | |
75 | { |
|
75 | { | |
76 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
76 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
77 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
77 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
78 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
78 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
79 | m_xMinSpin = new QSpinBox(); |
|
79 | m_xMinSpin = new QSpinBox(); | |
80 | m_xMinSpin->setMinimum(INT_MIN); |
|
80 | m_xMinSpin->setMinimum(INT_MIN); | |
81 | m_xMinSpin->setMaximum(INT_MAX); |
|
81 | m_xMinSpin->setMaximum(INT_MAX); | |
82 | m_xMinSpin->setValue(0); |
|
82 | m_xMinSpin->setValue(0); | |
83 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
83 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
84 | m_xMaxSpin = new QSpinBox(); |
|
84 | m_xMaxSpin = new QSpinBox(); | |
85 | m_xMaxSpin->setMinimum(INT_MIN); |
|
85 | m_xMaxSpin->setMinimum(INT_MIN); | |
86 | m_xMaxSpin->setMaximum(INT_MAX); |
|
86 | m_xMaxSpin->setMaximum(INT_MAX); | |
87 | m_xMaxSpin->setValue(10); |
|
87 | m_xMaxSpin->setValue(10); | |
88 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
88 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
89 | m_yMinSpin = new QSpinBox(); |
|
89 | m_yMinSpin = new QSpinBox(); | |
90 | m_yMinSpin->setMinimum(INT_MIN); |
|
90 | m_yMinSpin->setMinimum(INT_MIN); | |
91 | m_yMinSpin->setMaximum(INT_MAX); |
|
91 | m_yMinSpin->setMaximum(INT_MAX); | |
92 | m_yMinSpin->setValue(0); |
|
92 | m_yMinSpin->setValue(0); | |
93 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
93 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
94 | m_yMaxSpin = new QSpinBox(); |
|
94 | m_yMaxSpin = new QSpinBox(); | |
95 | m_yMaxSpin->setMinimum(INT_MIN); |
|
95 | m_yMaxSpin->setMinimum(INT_MIN); | |
96 | m_yMaxSpin->setMaximum(INT_MAX); |
|
96 | m_yMaxSpin->setMaximum(INT_MAX); | |
97 | m_yMaxSpin->setValue(10); |
|
97 | m_yMaxSpin->setValue(10); | |
98 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
98 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
99 |
|
99 | |||
100 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
100 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
101 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
101 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
102 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
102 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
103 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
103 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
104 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
104 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
105 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
105 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
106 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
106 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
107 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
107 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
108 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
108 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
109 |
|
109 | |||
110 | m_autoScaleCheck->setChecked(true); |
|
110 | m_autoScaleCheck->setChecked(true); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | // Combo box for selecting theme |
|
113 | // Combo box for selecting theme | |
114 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
114 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
115 | { |
|
115 | { | |
116 | QComboBox *chartTheme = new QComboBox(); |
|
116 | QComboBox *chartTheme = new QComboBox(); | |
117 | chartTheme->addItem("Default"); |
|
117 | chartTheme->addItem("Default"); | |
118 | chartTheme->addItem("Light"); |
|
118 | chartTheme->addItem("Light"); | |
119 | chartTheme->addItem("Blue Cerulean"); |
|
119 | chartTheme->addItem("Blue Cerulean"); | |
120 | chartTheme->addItem("Dark"); |
|
120 | chartTheme->addItem("Dark"); | |
121 | chartTheme->addItem("Brown Sand"); |
|
121 | chartTheme->addItem("Brown Sand"); | |
122 | chartTheme->addItem("Blue NCS"); |
|
122 | chartTheme->addItem("Blue NCS"); | |
123 |
chartTheme->addItem(" |
|
123 | chartTheme->addItem("High Contrast"); | |
124 |
chartTheme->addItem(" |
|
124 | chartTheme->addItem("Blue Icy"); | |
125 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
125 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
126 | this, SLOT(changeChartTheme(int))); |
|
126 | this, SLOT(changeChartTheme(int))); | |
127 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
127 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
128 | grid->addWidget(chartTheme, 8, 1); |
|
128 | grid->addWidget(chartTheme, 8, 1); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | // Different check boxes for customizing chart |
|
131 | // Different check boxes for customizing chart | |
132 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
132 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
133 | { |
|
133 | { | |
134 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
134 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
135 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
135 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
136 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
136 | connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
137 | zoomCheckBox->setChecked(true); |
|
137 | zoomCheckBox->setChecked(true); | |
138 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
138 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
139 |
|
139 | |||
140 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
140 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
141 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
141 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
142 | aliasCheckBox->setChecked(false); |
|
142 | aliasCheckBox->setChecked(false); | |
143 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
143 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | void MainWidget::antiAliasToggled(bool enabled) |
|
146 | void MainWidget::antiAliasToggled(bool enabled) | |
147 | { |
|
147 | { | |
148 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
148 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void MainWidget::addSeries() |
|
151 | void MainWidget::addSeries() | |
152 | { |
|
152 | { | |
153 | if (!m_addSerieDialog) { |
|
153 | if (!m_addSerieDialog) { | |
154 | m_addSerieDialog = new DataSerieDialog(this); |
|
154 | m_addSerieDialog = new DataSerieDialog(this); | |
155 | connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)), |
|
155 | connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)), | |
156 | this, SLOT(addSeries(QString, int, int, QString, bool))); |
|
156 | this, SLOT(addSeries(QString, int, int, QString, bool))); | |
157 | } |
|
157 | } | |
158 | m_addSerieDialog->exec(); |
|
158 | m_addSerieDialog->exec(); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
161 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
162 | { |
|
162 | { | |
163 | // TODO: dataCharacteristics |
|
163 | // TODO: dataCharacteristics | |
164 | QList<RealList> testData; |
|
164 | QList<RealList> testData; | |
165 | for (int j(0); j < columnCount; j++) { |
|
165 | for (int j(0); j < columnCount; j++) { | |
166 | QList <qreal> newColumn; |
|
166 | QList <qreal> newColumn; | |
167 | for (int i(0); i < rowCount; i++) { |
|
167 | for (int i(0); i < rowCount; i++) { | |
168 | if (dataCharacteristics == "Sin") { |
|
168 | if (dataCharacteristics == "Sin") { | |
169 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
169 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
170 | } else if (dataCharacteristics == "Sin + random") { |
|
170 | } else if (dataCharacteristics == "Sin + random") { | |
171 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
171 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
172 | } else if (dataCharacteristics == "Random") { |
|
172 | } else if (dataCharacteristics == "Random") { | |
173 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
173 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
174 | } else if (dataCharacteristics == "Linear") { |
|
174 | } else if (dataCharacteristics == "Linear") { | |
175 | //newColumn.append(i * (j + 1.0)); |
|
175 | //newColumn.append(i * (j + 1.0)); | |
176 | // TODO: temporary hack to make pie work; prevent zero values: |
|
176 | // TODO: temporary hack to make pie work; prevent zero values: | |
177 | newColumn.append(i * (j + 1.0) + 0.1); |
|
177 | newColumn.append(i * (j + 1.0) + 0.1); | |
178 | } else { // "constant" |
|
178 | } else { // "constant" | |
179 | newColumn.append((j + 1.0)); |
|
179 | newColumn.append((j + 1.0)); | |
180 | } |
|
180 | } | |
181 | } |
|
181 | } | |
182 | testData.append(newColumn); |
|
182 | testData.append(newColumn); | |
183 | } |
|
183 | } | |
184 | return testData; |
|
184 | return testData; | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | QStringList MainWidget::generateLabels(int count) |
|
187 | QStringList MainWidget::generateLabels(int count) | |
188 | { |
|
188 | { | |
189 | QStringList result; |
|
189 | QStringList result; | |
190 | for (int i(0); i < count; i++) |
|
190 | for (int i(0); i < count; i++) | |
191 | result.append("label" + QString::number(i)); |
|
191 | result.append("label" + QString::number(i)); | |
192 | return result; |
|
192 | return result; | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
195 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
196 | { |
|
196 | { | |
197 | qDebug() << "addSeries: " << seriesName |
|
197 | qDebug() << "addSeries: " << seriesName | |
198 | << " columnCount: " << columnCount |
|
198 | << " columnCount: " << columnCount | |
199 | << " rowCount: " << rowCount |
|
199 | << " rowCount: " << rowCount | |
200 | << " dataCharacteristics: " << dataCharacteristics |
|
200 | << " dataCharacteristics: " << dataCharacteristics | |
201 | << " labels enabled: " << labelsEnabled; |
|
201 | << " labels enabled: " << labelsEnabled; | |
202 | m_defaultSeriesName = seriesName; |
|
202 | m_defaultSeriesName = seriesName; | |
203 |
|
203 | |||
204 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
204 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
205 |
|
205 | |||
206 | // Line series and scatter series use similar data |
|
206 | // Line series and scatter series use similar data | |
207 | if (seriesName == "Line") { |
|
207 | if (seriesName == "Line") { | |
208 | for (int j(0); j < data.count(); j ++) { |
|
208 | for (int j(0); j < data.count(); j ++) { | |
209 | QList<qreal> column = data.at(j); |
|
209 | QList<qreal> column = data.at(j); | |
210 | QLineSeries *series = new QLineSeries(); |
|
210 | QLineSeries *series = new QLineSeries(); | |
211 | for (int i(0); i < column.count(); i++) { |
|
211 | for (int i(0); i < column.count(); i++) { | |
212 | series->add(i, column.at(i)); |
|
212 | series->add(i, column.at(i)); | |
213 | } |
|
213 | } | |
214 | m_chartView->addSeries(series); |
|
214 | m_chartView->addSeries(series); | |
215 | } |
|
215 | } | |
216 | } else if (seriesName == "Area") { |
|
216 | } else if (seriesName == "Area") { | |
217 | // TODO: lower series for the area? |
|
217 | // TODO: lower series for the area? | |
218 | for (int j(0); j < data.count(); j ++) { |
|
218 | for (int j(0); j < data.count(); j ++) { | |
219 | QList<qreal> column = data.at(j); |
|
219 | QList<qreal> column = data.at(j); | |
220 | QLineSeries *lineSeries = new QLineSeries(); |
|
220 | QLineSeries *lineSeries = new QLineSeries(); | |
221 | for (int i(0); i < column.count(); i++) { |
|
221 | for (int i(0); i < column.count(); i++) { | |
222 | lineSeries->add(i, column.at(i)); |
|
222 | lineSeries->add(i, column.at(i)); | |
223 | } |
|
223 | } | |
224 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
224 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
225 | m_chartView->addSeries(areaSeries); |
|
225 | m_chartView->addSeries(areaSeries); | |
226 | } |
|
226 | } | |
227 | } else if (seriesName == "Scatter") { |
|
227 | } else if (seriesName == "Scatter") { | |
228 | for (int j(0); j < data.count(); j++) { |
|
228 | for (int j(0); j < data.count(); j++) { | |
229 | QList<qreal> column = data.at(j); |
|
229 | QList<qreal> column = data.at(j); | |
230 | QScatterSeries *series = new QScatterSeries(); |
|
230 | QScatterSeries *series = new QScatterSeries(); | |
231 | for (int i(0); i < column.count(); i++) { |
|
231 | for (int i(0); i < column.count(); i++) { | |
232 | (*series) << QPointF(i, column.at(i)); |
|
232 | (*series) << QPointF(i, column.at(i)); | |
233 | } |
|
233 | } | |
234 | m_chartView->addSeries(series); |
|
234 | m_chartView->addSeries(series); | |
235 | } |
|
235 | } | |
236 | } else if (seriesName == "Pie") { |
|
236 | } else if (seriesName == "Pie") { | |
237 | QStringList labels = generateLabels(rowCount); |
|
237 | QStringList labels = generateLabels(rowCount); | |
238 | for (int j(0); j < data.count(); j++) { |
|
238 | for (int j(0); j < data.count(); j++) { | |
239 | QPieSeries *series = new QPieSeries(); |
|
239 | QPieSeries *series = new QPieSeries(); | |
240 | QList<qreal> column = data.at(j); |
|
240 | QList<qreal> column = data.at(j); | |
241 | for (int i(0); i < column.count(); i++) { |
|
241 | for (int i(0); i < column.count(); i++) { | |
242 | series->add(column.at(i), labels.at(i)); |
|
242 | series->add(column.at(i), labels.at(i)); | |
243 | } |
|
243 | } | |
244 | m_chartView->addSeries(series); |
|
244 | m_chartView->addSeries(series); | |
245 | } |
|
245 | } | |
246 | } else if (seriesName == "Bar" |
|
246 | } else if (seriesName == "Bar" | |
247 | || seriesName == "Stacked bar" |
|
247 | || seriesName == "Stacked bar" | |
248 | || seriesName == "Percent bar") { |
|
248 | || seriesName == "Percent bar") { | |
249 | QStringList category; |
|
249 | QStringList category; | |
250 | QStringList labels = generateLabels(rowCount); |
|
250 | QStringList labels = generateLabels(rowCount); | |
251 | foreach(QString label, labels) |
|
251 | foreach(QString label, labels) | |
252 | category << label; |
|
252 | category << label; | |
253 | QBarSeries* series = 0; |
|
253 | QBarSeries* series = 0; | |
254 | if (seriesName == "Bar") |
|
254 | if (seriesName == "Bar") | |
255 | series = new QBarSeries(category, this); |
|
255 | series = new QBarSeries(category, this); | |
256 | else if (seriesName == "Stacked bar") |
|
256 | else if (seriesName == "Stacked bar") | |
257 | series = new QStackedBarSeries(category, this); |
|
257 | series = new QStackedBarSeries(category, this); | |
258 | else |
|
258 | else | |
259 | series = new QPercentBarSeries(category, this); |
|
259 | series = new QPercentBarSeries(category, this); | |
260 |
|
260 | |||
261 | for (int j(0); j < data.count(); j++) { |
|
261 | for (int j(0); j < data.count(); j++) { | |
262 | QList<qreal> column = data.at(j); |
|
262 | QList<qreal> column = data.at(j); | |
263 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
263 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
264 | for (int i(0); i < column.count(); i++) { |
|
264 | for (int i(0); i < column.count(); i++) { | |
265 | *set << column.at(i); |
|
265 | *set << column.at(i); | |
266 | } |
|
266 | } | |
267 | series->addBarSet(set); |
|
267 | series->addBarSet(set); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | // TODO: new implementation of setFloatingValuesEnabled with signals |
|
270 | // TODO: new implementation of setFloatingValuesEnabled with signals | |
271 | //series->setFloatingValuesEnabled(true); |
|
271 | //series->setFloatingValuesEnabled(true); | |
272 | series->setToolTipEnabled(true); |
|
272 | series->setToolTipEnabled(true); | |
273 | m_chartView->addSeries(series); |
|
273 | m_chartView->addSeries(series); | |
274 | } else if (seriesName == "Spline") { |
|
274 | } else if (seriesName == "Spline") { | |
275 | for (int j(0); j < data.count(); j ++) { |
|
275 | for (int j(0); j < data.count(); j ++) { | |
276 | QList<qreal> column = data.at(j); |
|
276 | QList<qreal> column = data.at(j); | |
277 | QSplineSeries *series = new QSplineSeries(); |
|
277 | QSplineSeries *series = new QSplineSeries(); | |
278 | for (int i(0); i < column.count(); i++) { |
|
278 | for (int i(0); i < column.count(); i++) { | |
279 | series->add(i, column.at(i)); |
|
279 | series->add(i, column.at(i)); | |
280 | } |
|
280 | } | |
281 | m_chartView->addSeries(series); |
|
281 | m_chartView->addSeries(series); | |
282 | } |
|
282 | } | |
283 | } |
|
283 | } | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | void MainWidget::backgroundChanged(int itemIndex) |
|
286 | void MainWidget::backgroundChanged(int itemIndex) | |
287 | { |
|
287 | { | |
288 | qDebug() << "backgroundChanged: " << itemIndex; |
|
288 | qDebug() << "backgroundChanged: " << itemIndex; | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | void MainWidget::autoScaleChanged(int value) |
|
291 | void MainWidget::autoScaleChanged(int value) | |
292 | { |
|
292 | { | |
293 | if (value) { |
|
293 | if (value) { | |
294 | // TODO: enable auto scaling |
|
294 | // TODO: enable auto scaling | |
295 | } else { |
|
295 | } else { | |
296 | // TODO: set scaling manually (and disable auto scaling) |
|
296 | // TODO: set scaling manually (and disable auto scaling) | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | m_xMinSpin->setEnabled(!value); |
|
299 | m_xMinSpin->setEnabled(!value); | |
300 | m_xMaxSpin->setEnabled(!value); |
|
300 | m_xMaxSpin->setEnabled(!value); | |
301 | m_yMinSpin->setEnabled(!value); |
|
301 | m_yMinSpin->setEnabled(!value); | |
302 | m_yMaxSpin->setEnabled(!value); |
|
302 | m_yMaxSpin->setEnabled(!value); | |
303 | } |
|
303 | } | |
304 |
|
304 | |||
305 | void MainWidget::xMinChanged(int value) |
|
305 | void MainWidget::xMinChanged(int value) | |
306 | { |
|
306 | { | |
307 | qDebug() << "xMinChanged: " << value; |
|
307 | qDebug() << "xMinChanged: " << value; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | void MainWidget::xMaxChanged(int value) |
|
310 | void MainWidget::xMaxChanged(int value) | |
311 | { |
|
311 | { | |
312 | qDebug() << "xMaxChanged: " << value; |
|
312 | qDebug() << "xMaxChanged: " << value; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | void MainWidget::yMinChanged(int value) |
|
315 | void MainWidget::yMinChanged(int value) | |
316 | { |
|
316 | { | |
317 | qDebug() << "yMinChanged: " << value; |
|
317 | qDebug() << "yMinChanged: " << value; | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | void MainWidget::yMaxChanged(int value) |
|
320 | void MainWidget::yMaxChanged(int value) | |
321 | { |
|
321 | { | |
322 | qDebug() << "yMaxChanged: " << value; |
|
322 | qDebug() << "yMaxChanged: " << value; | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void MainWidget::changeChartTheme(int themeIndex) |
|
325 | void MainWidget::changeChartTheme(int themeIndex) | |
326 | { |
|
326 | { | |
327 | qDebug() << "changeChartTheme: " << themeIndex; |
|
327 | qDebug() << "changeChartTheme: " << themeIndex; | |
328 | m_chartView->setChartTheme((QChart::ChartTheme) themeIndex); |
|
328 | m_chartView->setChartTheme((QChart::ChartTheme) themeIndex); | |
329 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. |
|
329 | //TODO: remove this hack. This is just to make it so that theme change is seen immediately. | |
330 | QSize s = size(); |
|
330 | QSize s = size(); | |
331 | s.setWidth(s.width()+1); |
|
331 | s.setWidth(s.width()+1); | |
332 | resize(s); |
|
332 | resize(s); | |
333 | } |
|
333 | } |
General Comments 0
You need to be logged in to leave comments.
Login now