@@ -1,376 +1,377 | |||||
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 "themewidget.h" |
|
21 | #include "themewidget.h" | |
22 |
|
22 | |||
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPieSeries> |
|
24 | #include <QPieSeries> | |
25 | #include <QPieSlice> |
|
25 | #include <QPieSlice> | |
26 | #include <QBarSeries> |
|
26 | #include <QBarSeries> | |
27 | #include <QPercentBarSeries> |
|
27 | #include <QPercentBarSeries> | |
28 | #include <QStackedBarSeries> |
|
28 | #include <QStackedBarSeries> | |
29 | #include <QBarSet> |
|
29 | #include <QBarSet> | |
30 | #include <QLineSeries> |
|
30 | #include <QLineSeries> | |
31 | #include <QSplineSeries> |
|
31 | #include <QSplineSeries> | |
32 | #include <QScatterSeries> |
|
32 | #include <QScatterSeries> | |
33 | #include <QAreaSeries> |
|
33 | #include <QAreaSeries> | |
34 | #include <QLegend> |
|
34 | #include <QLegend> | |
35 | #include <QGridLayout> |
|
35 | #include <QGridLayout> | |
36 | #include <QFormLayout> |
|
36 | #include <QFormLayout> | |
37 | #include <QComboBox> |
|
37 | #include <QComboBox> | |
38 | #include <QSpinBox> |
|
38 | #include <QSpinBox> | |
39 | #include <QCheckBox> |
|
39 | #include <QCheckBox> | |
40 | #include <QGroupBox> |
|
40 | #include <QGroupBox> | |
41 | #include <QLabel> |
|
41 | #include <QLabel> | |
42 | #include <QTime> |
|
42 | #include <QTime> | |
43 |
|
43 | |||
44 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
44 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
45 | QWidget(parent), |
|
45 | QWidget(parent), | |
46 | m_listCount(3), |
|
46 | m_listCount(3), | |
47 | m_valueMax(10), |
|
47 | m_valueMax(10), | |
48 | m_valueCount(7), |
|
48 | m_valueCount(7), | |
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
49 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
50 | m_themeComboBox(createThemeBox()), |
|
50 | m_themeComboBox(createThemeBox()), | |
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
51 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
52 | m_animatedComboBox(createAnimationBox()), |
|
52 | m_animatedComboBox(createAnimationBox()), | |
53 | m_legendComboBox(createLegendBox()) |
|
53 | m_legendComboBox(createLegendBox()) | |
54 | { |
|
54 | { | |
55 | connectSignals(); |
|
55 | connectSignals(); | |
56 | // create layout |
|
56 | // create layout | |
57 | QGridLayout* baseLayout = new QGridLayout(); |
|
57 | QGridLayout* baseLayout = new QGridLayout(); | |
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
58 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
59 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
59 | settingsLayout->addWidget(new QLabel("Theme:")); | |
60 | settingsLayout->addWidget(m_themeComboBox); |
|
60 | settingsLayout->addWidget(m_themeComboBox); | |
61 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
61 | settingsLayout->addWidget(new QLabel("Animation:")); | |
62 | settingsLayout->addWidget(m_animatedComboBox); |
|
62 | settingsLayout->addWidget(m_animatedComboBox); | |
63 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
63 | settingsLayout->addWidget(new QLabel("Legend:")); | |
64 | settingsLayout->addWidget(m_legendComboBox); |
|
64 | settingsLayout->addWidget(m_legendComboBox); | |
65 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
65 | settingsLayout->addWidget(m_antialiasCheckBox); | |
66 | settingsLayout->addStretch(); |
|
66 | settingsLayout->addStretch(); | |
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
67 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
68 |
|
68 | |||
69 | //create charts |
|
69 | //create charts | |
70 |
|
70 | |||
71 | QChartView *chartView; |
|
71 | QChartView *chartView; | |
72 |
|
72 | |||
73 | chartView = new QChartView(createAreaChart()); |
|
73 | chartView = new QChartView(createAreaChart()); | |
74 | baseLayout->addWidget(chartView, 1, 0); |
|
74 | baseLayout->addWidget(chartView, 1, 0); | |
75 | m_charts << chartView; |
|
75 | m_charts << chartView; | |
76 |
|
76 | |||
77 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
77 | chartView = new QChartView(createBarChart(m_valueCount)); | |
78 | baseLayout->addWidget(chartView, 1, 1); |
|
78 | baseLayout->addWidget(chartView, 1, 1); | |
79 | m_charts << chartView; |
|
79 | m_charts << chartView; | |
80 |
|
80 | |||
81 | chartView = new QChartView(createLineChart()); |
|
81 | chartView = new QChartView(createLineChart()); | |
82 | baseLayout->addWidget(chartView, 1, 2); |
|
82 | baseLayout->addWidget(chartView, 1, 2); | |
83 | m_charts << chartView; |
|
83 | m_charts << chartView; | |
84 |
|
84 | |||
85 | chartView = new QChartView(createPieChart()); |
|
85 | chartView = new QChartView(createPieChart()); | |
86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
86 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
87 | baseLayout->addWidget(chartView, 2, 0); |
|
87 | baseLayout->addWidget(chartView, 2, 0); | |
88 | m_charts << chartView; |
|
88 | m_charts << chartView; | |
89 |
|
89 | |||
90 | chartView = new QChartView(createSplineChart()); |
|
90 | chartView = new QChartView(createSplineChart()); | |
91 | baseLayout->addWidget(chartView, 2, 1); |
|
91 | baseLayout->addWidget(chartView, 2, 1); | |
92 | m_charts << chartView; |
|
92 | m_charts << chartView; | |
93 |
|
93 | |||
94 | chartView = new QChartView(createScatterChart()); |
|
94 | chartView = new QChartView(createScatterChart()); | |
95 | baseLayout->addWidget(chartView, 2, 2); |
|
95 | baseLayout->addWidget(chartView, 2, 2); | |
96 | m_charts << chartView; |
|
96 | m_charts << chartView; | |
97 |
|
97 | |||
98 | setLayout(baseLayout); |
|
98 | setLayout(baseLayout); | |
99 |
|
99 | |||
100 | // Set defaults |
|
100 | // Set defaults | |
101 | m_antialiasCheckBox->setChecked(true); |
|
101 | m_antialiasCheckBox->setChecked(true); | |
102 | updateUI(); |
|
102 | updateUI(); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | ThemeWidget::~ThemeWidget() |
|
105 | ThemeWidget::~ThemeWidget() | |
106 | { |
|
106 | { | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | void ThemeWidget::connectSignals() |
|
109 | void ThemeWidget::connectSignals() | |
110 | { |
|
110 | { | |
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
111 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
112 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
113 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
114 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
117 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
118 | { |
|
118 | { | |
119 | DataTable dataTable; |
|
119 | DataTable dataTable; | |
120 |
|
120 | |||
121 | // set seed for random stuff |
|
121 | // set seed for random stuff | |
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
122 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
123 |
|
123 | |||
124 | // generate random data |
|
124 | // generate random data | |
125 | for (int i(0); i < listCount; i++) { |
|
125 | for (int i(0); i < listCount; i++) { | |
126 | DataList dataList; |
|
126 | DataList dataList; | |
127 | qreal yValue(0); |
|
127 | qreal yValue(0); | |
128 | for (int j(0); j < valueCount; j++) { |
|
128 | for (int j(0); j < valueCount; j++) { | |
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
129 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
130 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
131 | yValue); |
|
131 | yValue); | |
132 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
132 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
133 | dataList << Data(value, label); |
|
133 | dataList << Data(value, label); | |
134 | } |
|
134 | } | |
135 | dataTable << dataList; |
|
135 | dataTable << dataList; | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | return dataTable; |
|
138 | return dataTable; | |
139 | } |
|
139 | } | |
140 |
|
140 | |||
141 | QComboBox* ThemeWidget::createThemeBox() const |
|
141 | QComboBox* ThemeWidget::createThemeBox() const | |
142 | { |
|
142 | { | |
143 | // settings layout |
|
143 | // settings layout | |
144 | QComboBox* themeComboBox = new QComboBox(); |
|
144 | QComboBox* themeComboBox = new QComboBox(); | |
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
145 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
146 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
147 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
148 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
149 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
150 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
151 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
152 | return themeComboBox; |
|
152 | return themeComboBox; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | QComboBox* ThemeWidget::createAnimationBox() const |
|
155 | QComboBox* ThemeWidget::createAnimationBox() const | |
156 | { |
|
156 | { | |
157 | // settings layout |
|
157 | // settings layout | |
158 | QComboBox* animationComboBox = new QComboBox(); |
|
158 | QComboBox* animationComboBox = new QComboBox(); | |
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
159 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
160 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
161 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
162 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
163 | return animationComboBox; |
|
163 | return animationComboBox; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QComboBox* ThemeWidget::createLegendBox() const |
|
166 | QComboBox* ThemeWidget::createLegendBox() const | |
167 | { |
|
167 | { | |
168 | QComboBox* legendComboBox = new QComboBox(); |
|
168 | QComboBox* legendComboBox = new QComboBox(); | |
169 | legendComboBox->addItem("No Legend ", 0); |
|
169 | legendComboBox->addItem("No Legend ", 0); | |
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); |
|
170 | legendComboBox->addItem("Legend Top", QLegend::AlignmentTop); | |
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); |
|
171 | legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom); | |
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); |
|
172 | legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft); | |
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); |
|
173 | legendComboBox->addItem("Legend Right", QLegend::AlignmentRight); | |
174 | return legendComboBox; |
|
174 | return legendComboBox; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | QChart* ThemeWidget::createAreaChart() const |
|
177 | QChart* ThemeWidget::createAreaChart() const | |
178 | { |
|
178 | { | |
179 | QChart *chart = new QChart(); |
|
179 | QChart *chart = new QChart(); | |
180 | chart->axisX()->setNiceNumbersEnabled(true); |
|
180 | chart->axisX()->setNiceNumbersEnabled(true); | |
181 | chart->axisY()->setNiceNumbersEnabled(true); |
|
181 | chart->axisY()->setNiceNumbersEnabled(true); | |
182 | chart->setTitle("Area chart"); |
|
182 | chart->setTitle("Area chart"); | |
183 |
|
183 | |||
184 | // The lower series initialized to zero values |
|
184 | // The lower series initialized to zero values | |
185 | QLineSeries *lowerSeries = 0; |
|
185 | QLineSeries *lowerSeries = 0; | |
186 | QString name("Series "); |
|
186 | QString name("Series "); | |
187 | int nameIndex = 0; |
|
187 | int nameIndex = 0; | |
188 | for (int i(0); i < m_dataTable.count(); i++) { |
|
188 | for (int i(0); i < m_dataTable.count(); i++) { | |
189 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
189 | QLineSeries *upperSeries = new QLineSeries(chart); | |
190 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
190 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
191 | Data data = m_dataTable[i].at(j); |
|
191 | Data data = m_dataTable[i].at(j); | |
192 | if (lowerSeries){ |
|
192 | if (lowerSeries){ | |
193 | const QList<QPointF>& points = lowerSeries->points(); |
|
193 | const QList<QPointF>& points = lowerSeries->points(); | |
194 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
194 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); | |
195 | }else |
|
195 | }else | |
196 | upperSeries->append(QPointF(j, data.first.y())); |
|
196 | upperSeries->append(QPointF(j, data.first.y())); | |
197 | } |
|
197 | } | |
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
198 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
199 | area->setName(name + QString::number(nameIndex)); |
|
199 | area->setName(name + QString::number(nameIndex)); | |
200 | nameIndex++; |
|
200 | nameIndex++; | |
201 | chart->addSeries(area); |
|
201 | chart->addSeries(area); | |
202 | lowerSeries = upperSeries; |
|
202 | lowerSeries = upperSeries; | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | return chart; |
|
205 | return chart; | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
208 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
209 | { |
|
209 | { | |
210 | QChart* chart = new QChart(); |
|
210 | QChart* chart = new QChart(); | |
211 | chart->axisX()->setNiceNumbersEnabled(true); |
|
211 | chart->axisX()->setNiceNumbersEnabled(true); | |
212 | chart->axisY()->setNiceNumbersEnabled(true); |
|
212 | chart->axisY()->setNiceNumbersEnabled(true); | |
213 | chart->setTitle("Bar chart"); |
|
213 | chart->setTitle("Bar chart"); | |
214 |
|
214 | |||
215 |
Q |
|
215 | QStringList categories; | |
216 | for (int i(0); i < valueCount; i++) |
|
216 | for (int i(0); i < valueCount; i++) | |
217 | categories << QString::number(i); |
|
217 | categories << QString::number(i); | |
218 |
|
218 | |||
|
219 | chart->axisX()->categories()->insert(categories); | |||
|
220 | ||||
219 | QStackedBarSeries* series = new QStackedBarSeries(chart); |
|
221 | QStackedBarSeries* series = new QStackedBarSeries(chart); | |
220 | series->setCategories(categories); |
|
|||
221 | for (int i(0); i < m_dataTable.count(); i++) { |
|
222 | for (int i(0); i < m_dataTable.count(); i++) { | |
222 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
223 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
223 | foreach (Data data, m_dataTable[i]) |
|
224 | foreach (Data data, m_dataTable[i]) | |
224 | *set << data.first.y(); |
|
225 | *set << data.first.y(); | |
225 | series->append(set); |
|
226 | series->append(set); | |
226 | } |
|
227 | } | |
227 | chart->addSeries(series); |
|
228 | chart->addSeries(series); | |
228 |
|
229 | |||
229 | return chart; |
|
230 | return chart; | |
230 | } |
|
231 | } | |
231 |
|
232 | |||
232 | QChart* ThemeWidget::createLineChart() const |
|
233 | QChart* ThemeWidget::createLineChart() const | |
233 | { |
|
234 | { | |
234 | QChart* chart = new QChart(); |
|
235 | QChart* chart = new QChart(); | |
235 | chart->axisX()->setNiceNumbersEnabled(true); |
|
236 | chart->axisX()->setNiceNumbersEnabled(true); | |
236 | chart->axisY()->setNiceNumbersEnabled(true); |
|
237 | chart->axisY()->setNiceNumbersEnabled(true); | |
237 | chart->setTitle("Line chart"); |
|
238 | chart->setTitle("Line chart"); | |
238 |
|
239 | |||
239 | QString name("Series "); |
|
240 | QString name("Series "); | |
240 | int nameIndex = 0; |
|
241 | int nameIndex = 0; | |
241 | foreach (DataList list, m_dataTable) { |
|
242 | foreach (DataList list, m_dataTable) { | |
242 | QLineSeries *series = new QLineSeries(chart); |
|
243 | QLineSeries *series = new QLineSeries(chart); | |
243 | foreach (Data data, list) |
|
244 | foreach (Data data, list) | |
244 | series->append(data.first); |
|
245 | series->append(data.first); | |
245 | series->setName(name + QString::number(nameIndex)); |
|
246 | series->setName(name + QString::number(nameIndex)); | |
246 | nameIndex++; |
|
247 | nameIndex++; | |
247 | chart->addSeries(series); |
|
248 | chart->addSeries(series); | |
248 | } |
|
249 | } | |
249 |
|
250 | |||
250 | return chart; |
|
251 | return chart; | |
251 | } |
|
252 | } | |
252 |
|
253 | |||
253 | QChart* ThemeWidget::createPieChart() const |
|
254 | QChart* ThemeWidget::createPieChart() const | |
254 | { |
|
255 | { | |
255 | QChart* chart = new QChart(); |
|
256 | QChart* chart = new QChart(); | |
256 | chart->setTitle("Pie chart"); |
|
257 | chart->setTitle("Pie chart"); | |
257 |
|
258 | |||
258 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
259 | qreal pieSize = 1.0 / m_dataTable.count(); | |
259 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
260 | for (int i = 0; i < m_dataTable.count(); i++) { | |
260 | QPieSeries *series = new QPieSeries(chart); |
|
261 | QPieSeries *series = new QPieSeries(chart); | |
261 | foreach (Data data, m_dataTable[i]) { |
|
262 | foreach (Data data, m_dataTable[i]) { | |
262 | QPieSlice *slice = series->append(data.second, data.first.y()); |
|
263 | QPieSlice *slice = series->append(data.second, data.first.y()); | |
263 | if (data == m_dataTable[i].first()) { |
|
264 | if (data == m_dataTable[i].first()) { | |
264 | slice->setLabelVisible(); |
|
265 | slice->setLabelVisible(); | |
265 | slice->setExploded(); |
|
266 | slice->setExploded(); | |
266 | } |
|
267 | } | |
267 | } |
|
268 | } | |
268 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
269 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
269 | series->setPieSize(pieSize); |
|
270 | series->setPieSize(pieSize); | |
270 | series->setHorizontalPosition(hPos); |
|
271 | series->setHorizontalPosition(hPos); | |
271 | series->setVerticalPosition(0.5); |
|
272 | series->setVerticalPosition(0.5); | |
272 | chart->addSeries(series); |
|
273 | chart->addSeries(series); | |
273 | } |
|
274 | } | |
274 |
|
275 | |||
275 | return chart; |
|
276 | return chart; | |
276 | } |
|
277 | } | |
277 |
|
278 | |||
278 | QChart* ThemeWidget::createSplineChart() const |
|
279 | QChart* ThemeWidget::createSplineChart() const | |
279 | { // spine chart |
|
280 | { // spine chart | |
280 | QChart* chart = new QChart(); |
|
281 | QChart* chart = new QChart(); | |
281 | chart->axisX()->setNiceNumbersEnabled(true); |
|
282 | chart->axisX()->setNiceNumbersEnabled(true); | |
282 | chart->axisY()->setNiceNumbersEnabled(true); |
|
283 | chart->axisY()->setNiceNumbersEnabled(true); | |
283 | chart->setTitle("Spline chart"); |
|
284 | chart->setTitle("Spline chart"); | |
284 | QString name("Series "); |
|
285 | QString name("Series "); | |
285 | int nameIndex = 0; |
|
286 | int nameIndex = 0; | |
286 | foreach (DataList list, m_dataTable) { |
|
287 | foreach (DataList list, m_dataTable) { | |
287 | QSplineSeries *series = new QSplineSeries(chart); |
|
288 | QSplineSeries *series = new QSplineSeries(chart); | |
288 | foreach (Data data, list) |
|
289 | foreach (Data data, list) | |
289 | series->append(data.first); |
|
290 | series->append(data.first); | |
290 | series->setName(name + QString::number(nameIndex)); |
|
291 | series->setName(name + QString::number(nameIndex)); | |
291 | nameIndex++; |
|
292 | nameIndex++; | |
292 | chart->addSeries(series); |
|
293 | chart->addSeries(series); | |
293 | } |
|
294 | } | |
294 | return chart; |
|
295 | return chart; | |
295 | } |
|
296 | } | |
296 |
|
297 | |||
297 | QChart* ThemeWidget::createScatterChart() const |
|
298 | QChart* ThemeWidget::createScatterChart() const | |
298 | { // scatter chart |
|
299 | { // scatter chart | |
299 | QChart* chart = new QChart(); |
|
300 | QChart* chart = new QChart(); | |
300 | chart->axisX()->setNiceNumbersEnabled(true); |
|
301 | chart->axisX()->setNiceNumbersEnabled(true); | |
301 | chart->axisY()->setNiceNumbersEnabled(true); |
|
302 | chart->axisY()->setNiceNumbersEnabled(true); | |
302 | chart->setTitle("Scatter chart"); |
|
303 | chart->setTitle("Scatter chart"); | |
303 | QString name("Series "); |
|
304 | QString name("Series "); | |
304 | int nameIndex = 0; |
|
305 | int nameIndex = 0; | |
305 | foreach (DataList list, m_dataTable) { |
|
306 | foreach (DataList list, m_dataTable) { | |
306 | QScatterSeries *series = new QScatterSeries(chart); |
|
307 | QScatterSeries *series = new QScatterSeries(chart); | |
307 | foreach (Data data, list) |
|
308 | foreach (Data data, list) | |
308 | series->append(data.first); |
|
309 | series->append(data.first); | |
309 | series->setName(name + QString::number(nameIndex)); |
|
310 | series->setName(name + QString::number(nameIndex)); | |
310 | nameIndex++; |
|
311 | nameIndex++; | |
311 | chart->addSeries(series); |
|
312 | chart->addSeries(series); | |
312 | } |
|
313 | } | |
313 | return chart; |
|
314 | return chart; | |
314 | } |
|
315 | } | |
315 |
|
316 | |||
316 | void ThemeWidget::updateUI() |
|
317 | void ThemeWidget::updateUI() | |
317 | { |
|
318 | { | |
318 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
319 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
319 |
|
320 | |||
320 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
321 | if (m_charts.at(0)->chart()->theme() != theme) { | |
321 | foreach (QChartView *chartView, m_charts) |
|
322 | foreach (QChartView *chartView, m_charts) | |
322 | chartView->chart()->setTheme(theme); |
|
323 | chartView->chart()->setTheme(theme); | |
323 |
|
324 | |||
324 | QPalette pal = window()->palette(); |
|
325 | QPalette pal = window()->palette(); | |
325 | if (theme == QChart::ChartThemeLight) { |
|
326 | if (theme == QChart::ChartThemeLight) { | |
326 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
327 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
327 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
328 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
328 | } else if (theme == QChart::ChartThemeDark) { |
|
329 | } else if (theme == QChart::ChartThemeDark) { | |
329 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
330 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
330 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
331 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
331 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
332 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
332 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
333 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
333 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
334 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
334 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
335 | } else if (theme == QChart::ChartThemeBrownSand) { | |
335 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
336 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
336 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
337 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
338 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
338 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
339 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
339 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
340 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
340 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
341 | } else if (theme == QChart::ChartThemeHighContrast) { | |
341 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
342 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
342 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
343 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
343 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
344 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
344 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
345 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
345 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
346 | } else { |
|
347 | } else { | |
347 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
348 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
349 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
349 | } |
|
350 | } | |
350 | window()->setPalette(pal); |
|
351 | window()->setPalette(pal); | |
351 | } |
|
352 | } | |
352 |
|
353 | |||
353 | bool checked = m_antialiasCheckBox->isChecked(); |
|
354 | bool checked = m_antialiasCheckBox->isChecked(); | |
354 | foreach (QChartView *chart, m_charts) |
|
355 | foreach (QChartView *chart, m_charts) | |
355 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
356 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
356 |
|
357 | |||
357 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
358 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
358 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
359 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
359 | foreach (QChartView *chartView, m_charts) |
|
360 | foreach (QChartView *chartView, m_charts) | |
360 | chartView->chart()->setAnimationOptions(options); |
|
361 | chartView->chart()->setAnimationOptions(options); | |
361 | } |
|
362 | } | |
362 |
|
363 | |||
363 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
364 | QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
364 |
|
365 | |||
365 | if (!alignment) { |
|
366 | if (!alignment) { | |
366 | foreach (QChartView *chartView, m_charts) { |
|
367 | foreach (QChartView *chartView, m_charts) { | |
367 | chartView->chart()->legend()->hide(); |
|
368 | chartView->chart()->legend()->hide(); | |
368 | } |
|
369 | } | |
369 | } else { |
|
370 | } else { | |
370 | foreach (QChartView *chartView, m_charts) { |
|
371 | foreach (QChartView *chartView, m_charts) { | |
371 | chartView->chart()->legend()->setAlignment(alignment); |
|
372 | chartView->chart()->legend()->setAlignment(alignment); | |
372 | chartView->chart()->legend()->show(); |
|
373 | chartView->chart()->legend()->show(); | |
373 | } |
|
374 | } | |
374 | } |
|
375 | } | |
375 | } |
|
376 | } | |
376 |
|
377 |
@@ -1,89 +1,90 | |||||
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 <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QGroupedBarSeries> |
|
24 | #include <QGroupedBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
|||
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
|||
37 | //![1] |
|
|||
38 |
|
||||
39 | //![2] |
|
|||
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
35 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
36 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
37 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
38 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
39 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
40 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
41 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
42 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
43 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
44 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
45 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 |
//![ |
|
46 | //![1] | |
52 |
|
47 | |||
53 |
//![ |
|
48 | //![2] | |
54 | QGroupedBarSeries* series = new QGroupedBarSeries(); |
|
49 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
55 | series->setCategories(categories); |
|
50 | // series->setCategories(categories); | |
56 | series->append(set0); |
|
51 | series->append(set0); | |
57 | series->append(set1); |
|
52 | series->append(set1); | |
58 | series->append(set2); |
|
53 | series->append(set2); | |
59 | series->append(set3); |
|
54 | series->append(set3); | |
60 | series->append(set4); |
|
55 | series->append(set4); | |
61 |
|
56 | |||
62 |
//![ |
|
57 | //![2] | |
63 |
|
58 | |||
64 |
//![ |
|
59 | //![3] | |
65 | QChart* chart = new QChart(); |
|
60 | QChart* chart = new QChart(); | |
66 | chart->addSeries(series); |
|
61 | chart->addSeries(series); | |
67 | chart->setTitle("Simple grouped barchart example"); |
|
62 | chart->setTitle("Simple grouped barchart example"); | |
|
63 | //![3] | |||
|
64 | ||||
|
65 | //![4] | |||
|
66 | QStringList categories; | |||
|
67 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |||
|
68 | chart->axisX()->categories()->insert(categories); | |||
68 | //![4] |
|
69 | //![4] | |
69 |
|
70 | |||
70 | //![5] |
|
71 | //![5] | |
71 | chart->legend()->setVisible(true); |
|
72 | chart->legend()->setVisible(true); | |
72 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
73 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
73 | chart->axisY()->setNiceNumbersEnabled(true); |
|
74 | chart->axisY()->setNiceNumbersEnabled(true); | |
74 | //![5] |
|
75 | //![5] | |
75 |
|
76 | |||
76 | //![6] |
|
77 | //![6] | |
77 | QChartView* chartView = new QChartView(chart); |
|
78 | QChartView* chartView = new QChartView(chart); | |
78 | chartView->setRenderHint(QPainter::Antialiasing); |
|
79 | chartView->setRenderHint(QPainter::Antialiasing); | |
79 | //![6] |
|
80 | //![6] | |
80 |
|
81 | |||
81 | //![7] |
|
82 | //![7] | |
82 | QMainWindow window; |
|
83 | QMainWindow window; | |
83 | window.setCentralWidget(chartView); |
|
84 | window.setCentralWidget(chartView); | |
84 | window.resize(400, 300); |
|
85 | window.resize(400, 300); | |
85 | window.show(); |
|
86 | window.show(); | |
86 | //![7] |
|
87 | //![7] | |
87 |
|
88 | |||
88 | return a.exec(); |
|
89 | return a.exec(); | |
89 | } |
|
90 | } |
@@ -1,44 +1,43 | |||||
1 | #ifndef MAINWIDGET_H |
|
1 | #ifndef MAINWIDGET_H | |
2 | #define MAINWIDGET_H |
|
2 | #define MAINWIDGET_H | |
3 |
|
3 | |||
4 | #include "qchartglobal.h" |
|
4 | #include "qchartglobal.h" | |
5 | #include "qchart.h" |
|
5 | #include "qchart.h" | |
6 | #include "qchartview.h" |
|
6 | #include "qchartview.h" | |
7 | #include <QWidget> |
|
7 | #include <QWidget> | |
8 | #include <QGraphicsWidget> |
|
8 | #include <QGraphicsWidget> | |
9 | #include <QGridLayout> |
|
9 | #include <QGridLayout> | |
10 | #include <QGraphicsGridLayout> |
|
10 | #include <QGraphicsGridLayout> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
14 | class MainWidget : public QWidget |
|
14 | class MainWidget : public QWidget | |
15 | //class MainWidget : public QGraphicsWidget |
|
|||
16 | { |
|
15 | { | |
17 | Q_OBJECT |
|
16 | Q_OBJECT | |
18 | public: |
|
17 | public: | |
19 | explicit MainWidget(QWidget *parent = 0); |
|
18 | explicit MainWidget(QWidget *parent = 0); | |
20 |
|
19 | |||
21 | void createSeries(); |
|
20 | void createSeries(); | |
22 |
|
21 | |||
23 | signals: |
|
22 | signals: | |
24 |
|
23 | |||
25 | public slots: |
|
24 | public slots: | |
26 | void detachLegend(); |
|
25 | void detachLegend(); | |
27 | void attachLegend(); |
|
26 | void attachLegend(); | |
28 | void addBarset(); |
|
27 | void addBarset(); | |
29 | void removeBarset(); |
|
28 | void removeBarset(); | |
30 |
|
29 | |||
31 | private: |
|
30 | private: | |
32 |
|
31 | |||
33 | QChart *m_chart; |
|
32 | QChart *m_chart; | |
34 | QBarSeries *m_series; |
|
33 | QBarSeries *m_series; | |
35 |
|
34 | |||
36 | QChartView *m_chartView; |
|
35 | QChartView *m_chartView; | |
37 | QGridLayout *m_mainLayout; |
|
36 | QGridLayout *m_mainLayout; | |
38 | QGridLayout *m_buttonLayout; |
|
37 | QGridLayout *m_buttonLayout; | |
39 |
|
38 | |||
40 | QGraphicsView *m_customView; |
|
39 | QGraphicsView *m_customView; | |
41 | QGraphicsScene *m_customScene; |
|
40 | QGraphicsScene *m_customScene; | |
42 | }; |
|
41 | }; | |
43 |
|
42 | |||
44 | #endif // MAINWIDGET_H |
|
43 | #endif // MAINWIDGET_H |
@@ -1,88 +1,88 | |||||
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 <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QPercentBarSeries> |
|
24 | #include <QPercentBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
|||
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
|||
37 | //![1] |
|
|||
38 |
|
||||
39 | //![2] |
|
|||
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
35 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
36 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
37 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
38 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
39 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
40 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
41 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
42 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
43 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
44 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
45 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 |
//![ |
|
46 | //![1] | |
52 |
|
47 | |||
53 |
//![ |
|
48 | //![2] | |
54 | QPercentBarSeries* series = new QPercentBarSeries(); |
|
49 | QPercentBarSeries* series = new QPercentBarSeries(); | |
55 | series->setCategories(categories); |
|
|||
56 | series->append(set0); |
|
50 | series->append(set0); | |
57 | series->append(set1); |
|
51 | series->append(set1); | |
58 | series->append(set2); |
|
52 | series->append(set2); | |
59 | series->append(set3); |
|
53 | series->append(set3); | |
60 | series->append(set4); |
|
54 | series->append(set4); | |
61 |
//![ |
|
55 | //![2] | |
62 |
|
56 | |||
63 |
//![ |
|
57 | //![3] | |
64 | QChart* chart = new QChart(); |
|
58 | QChart* chart = new QChart(); | |
65 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
66 | chart->setTitle("Simple percentbarchart example"); |
|
60 | chart->setTitle("Simple percentbarchart example"); | |
|
61 | //![3] | |||
|
62 | ||||
|
63 | //![4] | |||
|
64 | QStringList categories; | |||
|
65 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |||
|
66 | chart->axisX()->categories()->insert(categories); | |||
67 | //![4] |
|
67 | //![4] | |
68 |
|
68 | |||
69 | //![5] |
|
69 | //![5] | |
70 | chart->legend()->setVisible(true); |
|
70 | chart->legend()->setVisible(true); | |
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
72 | //![5] |
|
72 | //![5] | |
73 |
|
73 | |||
74 | //![6] |
|
74 | //![6] | |
75 | QChartView* chartView = new QChartView(chart); |
|
75 | QChartView* chartView = new QChartView(chart); | |
76 | chartView->setRenderHint(QPainter::Antialiasing); |
|
76 | chartView->setRenderHint(QPainter::Antialiasing); | |
77 | //![6] |
|
77 | //![6] | |
78 |
|
78 | |||
79 | //![7] |
|
79 | //![7] | |
80 | QMainWindow window; |
|
80 | QMainWindow window; | |
81 | window.setCentralWidget(chartView); |
|
81 | window.setCentralWidget(chartView); | |
82 | window.resize(400, 300); |
|
82 | window.resize(400, 300); | |
83 | window.show(); |
|
83 | window.show(); | |
84 | //![7] |
|
84 | //![7] | |
85 |
|
85 | |||
86 | return a.exec(); |
|
86 | return a.exec(); | |
87 | } |
|
87 | } | |
88 |
|
88 |
@@ -1,89 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QApplication> |
|
21 | #include <QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QStackedBarSeries> |
|
24 | #include <QStackedBarSeries> | |
25 | #include <QBarSet> |
|
25 | #include <QBarSet> | |
26 | #include <QLegend> |
|
26 | #include <QLegend> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | int main(int argc, char *argv[]) |
|
30 | int main(int argc, char *argv[]) | |
31 | { |
|
31 | { | |
32 | QApplication a(argc, argv); |
|
32 | QApplication a(argc, argv); | |
33 |
|
33 | |||
34 | //![1] |
|
34 | //![1] | |
35 | QBarCategories categories; |
|
|||
36 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
|||
37 | //![1] |
|
|||
38 |
|
||||
39 | //![2] |
|
|||
40 | QBarSet *set0 = new QBarSet("Jane"); |
|
35 | QBarSet *set0 = new QBarSet("Jane"); | |
41 | QBarSet *set1 = new QBarSet("John"); |
|
36 | QBarSet *set1 = new QBarSet("John"); | |
42 | QBarSet *set2 = new QBarSet("Axel"); |
|
37 | QBarSet *set2 = new QBarSet("Axel"); | |
43 | QBarSet *set3 = new QBarSet("Mary"); |
|
38 | QBarSet *set3 = new QBarSet("Mary"); | |
44 | QBarSet *set4 = new QBarSet("Samantha"); |
|
39 | QBarSet *set4 = new QBarSet("Samantha"); | |
45 |
|
40 | |||
46 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; |
|
41 | *set0 << 1 << 2 << 3 << 4 << 5 << 6; | |
47 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; |
|
42 | *set1 << 5 << 0 << 0 << 4 << 0 << 7; | |
48 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; |
|
43 | *set2 << 3 << 5 << 8 << 13 << 8 << 5; | |
49 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; |
|
44 | *set3 << 5 << 6 << 7 << 3 << 4 << 5; | |
50 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; |
|
45 | *set4 << 9 << 7 << 5 << 3 << 1 << 2; | |
51 |
//![ |
|
46 | //![1] | |
52 |
|
47 | |||
53 |
//![ |
|
48 | //![2] | |
54 | QStackedBarSeries* series = new QStackedBarSeries(); |
|
49 | QStackedBarSeries* series = new QStackedBarSeries(); | |
55 | series->setCategories(categories); |
|
|||
56 | series->append(set0); |
|
50 | series->append(set0); | |
57 | series->append(set1); |
|
51 | series->append(set1); | |
58 | series->append(set2); |
|
52 | series->append(set2); | |
59 | series->append(set3); |
|
53 | series->append(set3); | |
60 | series->append(set4); |
|
54 | series->append(set4); | |
61 |
//![ |
|
55 | //![2] | |
62 |
|
56 | |||
63 |
//![ |
|
57 | //![3] | |
64 | QChart* chart = new QChart(); |
|
58 | QChart* chart = new QChart(); | |
65 | chart->addSeries(series); |
|
59 | chart->addSeries(series); | |
66 | chart->setTitle("Simple stackedbarchart example"); |
|
60 | chart->setTitle("Simple stackedbarchart example"); | |
|
61 | //![3] | |||
|
62 | ||||
|
63 | //![4] | |||
|
64 | QStringList categories; | |||
|
65 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |||
|
66 | chart->axisX()->categories()->insert(categories); | |||
67 | //![4] |
|
67 | //![4] | |
68 |
|
68 | |||
69 | //![5] |
|
69 | //![5] | |
70 | chart->legend()->setVisible(true); |
|
70 | chart->legend()->setVisible(true); | |
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
71 | chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
72 | chart->axisY()->setNiceNumbersEnabled(true); |
|
72 | chart->axisY()->setNiceNumbersEnabled(true); | |
73 | //![5] |
|
73 | //![5] | |
74 |
|
74 | |||
75 | //![6] |
|
75 | //![6] | |
76 | QChartView* chartView = new QChartView(chart); |
|
76 | QChartView* chartView = new QChartView(chart); | |
77 | chartView->setRenderHint(QPainter::Antialiasing); |
|
77 | chartView->setRenderHint(QPainter::Antialiasing); | |
78 | //![6] |
|
78 | //![6] | |
79 |
|
79 | |||
80 | //![7] |
|
80 | //![7] | |
81 | QMainWindow window; |
|
81 | QMainWindow window; | |
82 | window.setCentralWidget(chartView); |
|
82 | window.setCentralWidget(chartView); | |
83 | window.resize(400, 300); |
|
83 | window.resize(400, 300); | |
84 | window.show(); |
|
84 | window.show(); | |
85 | //![7] |
|
85 | //![7] | |
86 |
|
86 | |||
87 | return a.exec(); |
|
87 | return a.exec(); | |
88 | } |
|
88 | } | |
89 |
|
89 |
@@ -1,49 +1,49 | |||||
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 "drilldownchart.h" |
|
21 | #include "drilldownchart.h" | |
22 | #include <QAxis> |
|
22 | #include <QAxis> | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
24 | QTCOMMERCIALCHART_USE_NAMESPACE | |
25 |
|
25 | |||
26 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | DrilldownChart::DrilldownChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | : QChart(parent, wFlags) |
|
27 | : QChart(parent, wFlags) | |
28 | ,m_currentSeries(0) |
|
28 | ,m_currentSeries(0) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | void DrilldownChart::changeSeries(QAbstractSeries *series) |
|
32 | void DrilldownChart::changeSeries(QAbstractSeries *series) | |
33 | { |
|
33 | { | |
34 | if (m_currentSeries) |
|
34 | if (m_currentSeries) | |
35 | removeSeries(m_currentSeries); |
|
35 | removeSeries(m_currentSeries); | |
36 | m_currentSeries = series; |
|
36 | m_currentSeries = series; | |
37 | addSeries(series); |
|
37 | addSeries(series); | |
38 | setTitle(series->name()); |
|
38 | setTitle(series->name()); | |
39 | axisY()->setNiceNumbersEnabled(true); |
|
39 | axisY()->setNiceNumbersEnabled(true); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 |
void DrilldownChart::handleClicked(QBarSet *barset, |
|
42 | void DrilldownChart::handleClicked(QBarSet *barset, int index) | |
43 | { |
|
43 | { | |
44 | Q_UNUSED(barset) |
|
44 | Q_UNUSED(barset) | |
45 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); |
|
45 | DrilldownBarSeries* series = static_cast<DrilldownBarSeries*> (sender()); | |
46 |
changeSeries(series->drilldownSeries( |
|
46 | changeSeries(series->drilldownSeries(index)); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | #include "moc_drilldownchart.cpp" |
|
49 | #include "moc_drilldownchart.cpp" |
@@ -1,46 +1,46 | |||||
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 DRILLDOWNCHART_H |
|
21 | #ifndef DRILLDOWNCHART_H | |
22 | #define DRILLDOWNCHART_H |
|
22 | #define DRILLDOWNCHART_H | |
23 |
|
23 | |||
24 | #include <QChart> |
|
24 | #include <QChart> | |
25 | #include "drilldownseries.h" |
|
25 | #include "drilldownseries.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | //! [2] |
|
29 | //! [2] | |
30 | class DrilldownChart : public QChart |
|
30 | class DrilldownChart : public QChart | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
34 | explicit DrilldownChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); | |
35 |
|
35 | |||
36 | void changeSeries(QAbstractSeries *series); |
|
36 | void changeSeries(QAbstractSeries *series); | |
37 |
|
37 | |||
38 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
39 |
void handleClicked(QBarSet *barset, |
|
39 | void handleClicked(QBarSet *barset, int index); | |
40 |
|
40 | |||
41 | private: |
|
41 | private: | |
42 | QAbstractSeries* m_currentSeries; |
|
42 | QAbstractSeries* m_currentSeries; | |
43 | }; |
|
43 | }; | |
44 | //! [2] |
|
44 | //! [2] | |
45 |
|
45 | |||
46 | #endif // DRILLDOWNCHART_H |
|
46 | #endif // DRILLDOWNCHART_H |
@@ -1,41 +1,40 | |||||
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 "drilldownseries.h" |
|
21 | #include "drilldownseries.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
23 | QTCOMMERCIALCHART_USE_NAMESPACE | |
24 |
|
24 | |||
25 | DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) |
|
25 | DrilldownBarSeries::DrilldownBarSeries(QStringList categories, QObject *parent) | |
26 | : QStackedBarSeries(parent) |
|
26 | : QStackedBarSeries(parent) | |
27 | { |
|
27 | { | |
28 | setCategories(categories); |
|
|||
29 | } |
|
28 | } | |
30 |
|
29 | |||
31 |
void DrilldownBarSeries::mapDrilldownSeries( |
|
30 | void DrilldownBarSeries::mapDrilldownSeries(int index, DrilldownBarSeries* drilldownSeries) | |
32 | { |
|
31 | { | |
33 |
mDrilldownSeries[ |
|
32 | mDrilldownSeries[index] = drilldownSeries; | |
34 | } |
|
33 | } | |
35 |
|
34 | |||
36 |
DrilldownBarSeries* DrilldownBarSeries::drilldownSeries( |
|
35 | DrilldownBarSeries* DrilldownBarSeries::drilldownSeries(int index) | |
37 | { |
|
36 | { | |
38 |
return mDrilldownSeries[ |
|
37 | return mDrilldownSeries[index]; | |
39 | } |
|
38 | } | |
40 |
|
39 | |||
41 | #include "moc_drilldownseries.cpp" |
|
40 | #include "moc_drilldownseries.cpp" |
@@ -1,45 +1,45 | |||||
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 DRILLDOWNSERIES_H |
|
21 | #ifndef DRILLDOWNSERIES_H | |
22 | #define DRILLDOWNSERIES_H |
|
22 | #define DRILLDOWNSERIES_H | |
23 |
|
23 | |||
24 | #include <QStackedBarSeries> |
|
24 | #include <QStackedBarSeries> | |
25 | #include <QMap> |
|
25 | #include <QMap> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | //! [1] |
|
29 | //! [1] | |
30 | class DrilldownBarSeries : public QStackedBarSeries |
|
30 | class DrilldownBarSeries : public QStackedBarSeries | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 | public: |
|
33 | public: | |
34 | DrilldownBarSeries(QStringList categories, QObject *parent = 0); |
|
34 | DrilldownBarSeries(QStringList categories, QObject *parent = 0); | |
35 |
|
35 | |||
36 |
void mapDrilldownSeries( |
|
36 | void mapDrilldownSeries(int index, DrilldownBarSeries* drilldownSeries); | |
37 |
|
37 | |||
38 |
DrilldownBarSeries* drilldownSeries( |
|
38 | DrilldownBarSeries* drilldownSeries(int index); | |
39 |
|
39 | |||
40 | private: |
|
40 | private: | |
41 |
QMap< |
|
41 | QMap<int, DrilldownBarSeries*> mDrilldownSeries; | |
42 | }; |
|
42 | }; | |
43 | //! [1] |
|
43 | //! [1] | |
44 |
|
44 | |||
45 | #endif // DRILLDOWNSERIES_H |
|
45 | #endif // DRILLDOWNSERIES_H |
@@ -1,116 +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 | #include <QtGui/QApplication> |
|
21 | #include <QtGui/QApplication> | |
22 | #include <QMainWindow> |
|
22 | #include <QMainWindow> | |
23 | #include <QChartView> |
|
23 | #include <QChartView> | |
24 | #include <QBarSet> |
|
24 | #include <QBarSet> | |
25 | #include <QLegend> |
|
25 | #include <QLegend> | |
26 | #include "drilldownseries.h" |
|
26 | #include "drilldownseries.h" | |
27 | #include "drilldownchart.h" |
|
27 | #include "drilldownchart.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | int main(int argc, char *argv[]) |
|
31 | int main(int argc, char *argv[]) | |
32 | { |
|
32 | { | |
33 | //! [1] |
|
33 | //! [1] | |
34 | QApplication a(argc, argv); |
|
34 | QApplication a(argc, argv); | |
35 | QMainWindow window; |
|
35 | QMainWindow window; | |
36 | //! [1] |
|
36 | //! [1] | |
37 |
|
37 | |||
38 | //! [2] |
|
38 | //! [2] | |
39 | DrilldownChart* drilldownChart = new DrilldownChart(); |
|
39 | DrilldownChart* drilldownChart = new DrilldownChart(); | |
40 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); |
|
40 | drilldownChart->setTheme(QChart::ChartThemeBlueIcy); | |
41 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); |
|
41 | drilldownChart->setAnimationOptions(QChart::SeriesAnimations); | |
42 | //! [2] |
|
42 | //! [2] | |
43 |
|
43 | |||
44 | //! [3] |
|
44 | //! [3] | |
45 | // Define categories |
|
45 | // Define categories | |
46 | QStringList months; |
|
46 | QStringList months; | |
47 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; |
|
47 | months << "May" << "Jun" << "Jul" << "Aug" << "Sep"; | |
48 | QStringList weeks; |
|
48 | QStringList weeks; | |
49 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; |
|
49 | weeks << "week 1" << "week 2" << "week 3" << "week 4"; | |
50 | QStringList plants; |
|
50 | QStringList plants; | |
51 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; |
|
51 | plants << "Habanero" << "Lemon Drop" << "Starfish" << "Aji Amarillo"; | |
52 | //! [3] |
|
52 | //! [3] | |
53 |
|
53 | |||
54 | //! [4] |
|
54 | //! [4] | |
55 | // Create drilldown structure |
|
55 | // Create drilldown structure | |
56 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); |
|
56 | DrilldownBarSeries* seasonSeries = new DrilldownBarSeries(months, drilldownChart); | |
57 | seasonSeries->setName("Crop by month - Season"); |
|
57 | seasonSeries->setName("Crop by month - Season"); | |
58 |
|
58 | |||
59 | // Each month in season series has drilldown series for weekly data |
|
59 | // Each month in season series has drilldown series for weekly data | |
60 | foreach (QString month, months) { |
|
60 | for (int month=0; month < months.count(); month++) { | |
61 |
|
61 | |||
62 | // Create drilldown series for every week |
|
62 | // Create drilldown series for every week | |
63 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); |
|
63 | DrilldownBarSeries* weeklySeries = new DrilldownBarSeries(weeks, drilldownChart); | |
64 | seasonSeries->mapDrilldownSeries(month, weeklySeries); |
|
64 | seasonSeries->mapDrilldownSeries(month, weeklySeries); | |
65 |
|
65 | |||
66 | // Drilling down from weekly data brings us back to season data. |
|
66 | // Drilling down from weekly data brings us back to season data. | |
67 |
for |
|
67 | for (int week=0; week < weeks.count(); week++) { | |
68 | weeklySeries->mapDrilldownSeries(week, seasonSeries); |
|
68 | weeklySeries->mapDrilldownSeries(week, seasonSeries); | |
69 | weeklySeries->setName(QString("Crop by week - " + month)); |
|
69 | weeklySeries->setName(QString("Crop by week - " + months.at(month))); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | // Use right click signal to implement drilldown |
|
72 | // Use right click signal to implement drilldown | |
73 |
QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*, |
|
73 | QObject::connect(weeklySeries, SIGNAL(clicked(QBarSet*,int)), drilldownChart, SLOT(handleClicked(QBarSet*,int))); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | // Enable drilldown from season series using right click. |
|
76 | // Enable drilldown from season series using right click. | |
77 |
QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*, |
|
77 | QObject::connect(seasonSeries, SIGNAL(clicked(QBarSet*,int)), drilldownChart, SLOT(handleClicked(QBarSet*,int))); | |
78 | //! [4] |
|
78 | //! [4] | |
79 |
|
79 | |||
80 | //! [5] |
|
80 | //! [5] | |
81 | // Fill monthly and weekly series with data |
|
81 | // Fill monthly and weekly series with data | |
82 | foreach (QString plant, plants) { |
|
82 | foreach (QString plant, plants) { | |
83 | QBarSet* monthlyCrop = new QBarSet(plant); |
|
83 | QBarSet* monthlyCrop = new QBarSet(plant); | |
84 |
for |
|
84 | for (int month=0; month<months.count(); month++) { | |
85 | QBarSet* weeklyCrop = new QBarSet(plant); |
|
85 | QBarSet* weeklyCrop = new QBarSet(plant); | |
86 |
for |
|
86 | for (int week=0; week<weeks.count(); week++) { | |
87 | *weeklyCrop << (qrand() % 20); |
|
87 | *weeklyCrop << (qrand() % 20); | |
|
88 | } | |||
88 | // Get the drilldown series from season series and add crop to it. |
|
89 | // Get the drilldown series from season series and add crop to it. | |
89 | seasonSeries->drilldownSeries(month)->append(weeklyCrop); |
|
90 | seasonSeries->drilldownSeries(month)->append(weeklyCrop); | |
90 | *monthlyCrop << weeklyCrop->sum(); |
|
91 | *monthlyCrop << weeklyCrop->sum(); | |
91 | } |
|
92 | } | |
92 | seasonSeries->append(monthlyCrop); |
|
93 | seasonSeries->append(monthlyCrop); | |
93 | } |
|
94 | } | |
94 | //! [5] |
|
95 | //! [5] | |
95 |
|
96 | |||
96 | //! [6] |
|
97 | //! [6] | |
97 | // Show season series in initial view |
|
98 | // Show season series in initial view | |
98 | drilldownChart->changeSeries(seasonSeries); |
|
99 | drilldownChart->changeSeries(seasonSeries); | |
99 | drilldownChart->setTitle(seasonSeries->name()); |
|
100 | drilldownChart->setTitle(seasonSeries->name()); | |
100 | //! [6] |
|
101 | //! [6] | |
101 |
|
102 | |||
102 | //! [7] |
|
103 | //! [7] | |
103 | drilldownChart->axisX()->setGridLineVisible(false); |
|
104 | drilldownChart->axisX()->setGridLineVisible(false); | |
104 | drilldownChart->axisY()->setNiceNumbersEnabled(true); |
|
105 | drilldownChart->axisY()->setNiceNumbersEnabled(true); | |
105 | drilldownChart->legend()->setVisible(true); |
|
106 | drilldownChart->legend()->setVisible(true); | |
106 | drilldownChart->legend()->setAlignment(QLegend::AlignmentBottom); |
|
107 | drilldownChart->legend()->setAlignment(QLegend::AlignmentBottom); | |
107 | //! [7] |
|
108 | //! [7] | |
108 |
|
109 | |||
109 | QChartView *chartView = new QChartView(drilldownChart); |
|
110 | QChartView *chartView = new QChartView(drilldownChart); | |
110 | window.setCentralWidget(chartView); |
|
111 | window.setCentralWidget(chartView); | |
111 | window.resize(400, 300); |
|
112 | window.resize(400, 300); | |
112 | window.show(); |
|
113 | window.show(); | |
113 |
|
114 | |||
114 | return a.exec(); |
|
115 | return a.exec(); | |
115 | } |
|
116 | } | |
116 |
|
117 |
@@ -1,127 +1,128 | |||||
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 "qaxiscategories.h" |
|
21 | #include "qaxiscategories.h" | |
22 | #include "qaxiscategories_p.h" |
|
22 | #include "qaxiscategories_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QAxisCategories |
|
27 | \class QAxisCategories | |
28 | \brief The QAxisCategoriess class is used for manipulating axis's categories. |
|
28 | \brief The QAxisCategoriess class is used for manipulating axis's categories. | |
29 | \mainclass |
|
29 | \mainclass | |
30 |
|
30 | |||
31 | Each axis can have categories instead of numerical representation. The typical use case |
|
31 | Each axis can have categories instead of numerical representation. The typical use case | |
32 | is bar chart, where categories are always show on X axis. |
|
32 | is bar chart, where categories are always show on X axis. | |
33 | */ |
|
33 | */ | |
34 |
|
34 | |||
35 |
|
35 | |||
36 | QAxisCategories::QAxisCategories(): |
|
36 | QAxisCategories::QAxisCategories(): | |
37 | d_ptr(new QAxisCategoriesPrivate(this)) |
|
37 | d_ptr(new QAxisCategoriesPrivate(this)) | |
38 | { |
|
38 | { | |
39 |
|
39 | |||
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QAxisCategories::~QAxisCategories() |
|
42 | QAxisCategories::~QAxisCategories() | |
43 | { |
|
43 | { | |
44 |
|
44 | |||
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | Inserts bar \a categories. |
|
48 | Inserts \a categories to axis. First item in list is assumed to be at x = 0, next at x = 1 and so on | |
49 | */ |
|
49 | */ | |
50 |
void QAxisCategories::insert(const Q |
|
50 | void QAxisCategories::insert(const QStringList &categories) | |
51 | { |
|
51 | { | |
52 |
int i= |
|
52 | int i=0; | |
53 | foreach (const QString& string , categories) { |
|
53 | foreach (const QString& string , categories) { | |
54 | d_ptr->m_map.insert(i,string); |
|
54 | d_ptr->m_map.insert(i,string); | |
55 | i++; |
|
55 | i++; | |
56 | } |
|
56 | } | |
57 | emit d_ptr->updated(); |
|
57 | emit d_ptr->updated(); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
|
60 | ||||
60 | /*! |
|
61 | /*! | |
61 | Inserts category, instead of \a value on axis a \a label will be shown. |
|
62 | Inserts category, instead of \a value on axis a \a label will be shown. | |
62 | */ |
|
63 | */ | |
63 | void QAxisCategories::insert(qreal value,QString label) |
|
64 | void QAxisCategories::insert(qreal value,QString label) | |
64 | { |
|
65 | { | |
65 | d_ptr->m_map.insert(value,label); |
|
66 | d_ptr->m_map.insert(value,label); | |
66 | emit d_ptr->updated(); |
|
67 | emit d_ptr->updated(); | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | /*! |
|
70 | /*! | |
70 | Removes category for \a value. |
|
71 | Removes category for \a value. | |
71 | */ |
|
72 | */ | |
72 | void QAxisCategories::remove(qreal value) |
|
73 | void QAxisCategories::remove(qreal value) | |
73 | { |
|
74 | { | |
74 | d_ptr->m_map.remove(value); |
|
75 | d_ptr->m_map.remove(value); | |
75 | emit d_ptr->updated(); |
|
76 | emit d_ptr->updated(); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | /*! |
|
79 | /*! | |
79 | Removes all categories. |
|
80 | Removes all categories. | |
80 | */ |
|
81 | */ | |
81 | void QAxisCategories::clear() |
|
82 | void QAxisCategories::clear() | |
82 | { |
|
83 | { | |
83 | d_ptr->m_map.clear(); |
|
84 | d_ptr->m_map.clear(); | |
84 | emit d_ptr->updated(); |
|
85 | emit d_ptr->updated(); | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | /*! |
|
88 | /*! | |
88 | Returns number of categories. |
|
89 | Returns number of categories. | |
89 | */ |
|
90 | */ | |
90 | int QAxisCategories::count() |
|
91 | int QAxisCategories::count() | |
91 | { |
|
92 | { | |
92 | return d_ptr->m_map.count(); |
|
93 | return d_ptr->m_map.count(); | |
93 | } |
|
94 | } | |
94 |
|
95 | |||
95 | /*! |
|
96 | /*! | |
96 | Returns all values of categories. |
|
97 | Returns all values of categories. | |
97 | */ |
|
98 | */ | |
98 | QList<qreal> QAxisCategories::values() const |
|
99 | QList<qreal> QAxisCategories::values() const | |
99 | { |
|
100 | { | |
100 | return d_ptr->m_map.keys(); |
|
101 | return d_ptr->m_map.keys(); | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | /*! |
|
104 | /*! | |
104 | Returns label for given \a value. |
|
105 | Returns label for given \a value. | |
105 | */ |
|
106 | */ | |
106 | QString QAxisCategories::label(qreal value) const |
|
107 | QString QAxisCategories::label(qreal value) const | |
107 | { |
|
108 | { | |
108 | return d_ptr->m_map.value(value); |
|
109 | return d_ptr->m_map.value(value); | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
112 |
|
113 | |||
113 | QAxisCategoriesPrivate::QAxisCategoriesPrivate(QAxisCategories *q): |
|
114 | QAxisCategoriesPrivate::QAxisCategoriesPrivate(QAxisCategories *q): | |
114 | q_ptr(q) |
|
115 | q_ptr(q) | |
115 | { |
|
116 | { | |
116 |
|
117 | |||
117 | } |
|
118 | } | |
118 |
|
119 | |||
119 | QAxisCategoriesPrivate::~QAxisCategoriesPrivate() |
|
120 | QAxisCategoriesPrivate::~QAxisCategoriesPrivate() | |
120 | { |
|
121 | { | |
121 |
|
122 | |||
122 | } |
|
123 | } | |
123 |
|
124 | |||
124 | #include "moc_qaxiscategories.cpp" |
|
125 | #include "moc_qaxiscategories.cpp" | |
125 | #include "moc_qaxiscategories_p.cpp" |
|
126 | #include "moc_qaxiscategories_p.cpp" | |
126 |
|
127 | |||
127 | QTCOMMERCIALCHART_END_NAMESPACE |
|
128 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,56 +1,56 | |||||
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 QAXISCATEGORIES_H |
|
21 | #ifndef QAXISCATEGORIES_H | |
22 | #define QAXISCATEGORIES_H |
|
22 | #define QAXISCATEGORIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 |
#include < |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QAxisCategoriesPrivate; |
|
29 | class QAxisCategoriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QAxisCategories : public QObject |
|
31 | class QTCOMMERCIALCHART_EXPORT QAxisCategories : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | private: |
|
34 | private: | |
35 | QAxisCategories(); |
|
35 | QAxisCategories(); | |
36 | public: |
|
36 | public: | |
37 | ~QAxisCategories(); |
|
37 | ~QAxisCategories(); | |
38 |
|
38 | |||
39 |
void insert(const Q |
|
39 | void insert(const QStringList &category); | |
40 | void insert(qreal value,QString label); |
|
40 | void insert(qreal value,QString label); | |
41 | void remove(qreal value); |
|
41 | void remove(qreal value); | |
42 | QList<qreal> values() const; |
|
42 | QList<qreal> values() const; | |
43 | QString label(qreal value) const; |
|
43 | QString label(qreal value) const; | |
44 | void clear(); |
|
44 | void clear(); | |
45 | int count(); |
|
45 | int count(); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | QScopedPointer<QAxisCategoriesPrivate> d_ptr; |
|
48 | QScopedPointer<QAxisCategoriesPrivate> d_ptr; | |
49 | friend class QAxisPrivate; |
|
49 | friend class QAxisPrivate; | |
50 | friend class ChartAxis; |
|
50 | friend class ChartAxis; | |
51 | }; |
|
51 | }; | |
52 |
|
52 | |||
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_END_NAMESPACE |
|
54 | QTCOMMERCIALCHART_END_NAMESPACE | |
55 |
|
55 | |||
56 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
|
56 | #endif /* QCHARTAXISCATEGORIES_H_ */ |
@@ -1,56 +1,56 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "bar_p.h" |
|
21 | #include "bar_p.h" | |
22 | #include <QDebug> |
|
22 | #include <QDebug> | |
23 | #include <QPainter> |
|
23 | #include <QPainter> | |
24 | #include <QGraphicsSceneEvent> |
|
24 | #include <QGraphicsSceneEvent> | |
25 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 |
Bar::Bar(QBarSet *barset, |
|
28 | Bar::Bar(QBarSet *barset, int index, QGraphicsItem *parent) : QGraphicsRectItem(parent), | |
29 | m_category(category), |
|
29 | m_index(index), | |
30 | m_barset(barset) |
|
30 | m_barset(barset) | |
31 | { |
|
31 | { | |
32 |
setAcceptedMouseButtons(Qt::LeftButton |
|
32 | setAcceptedMouseButtons(Qt::LeftButton | Qt::RightButton); | |
33 | setAcceptHoverEvents(true); |
|
33 | setAcceptHoverEvents(true); | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
36 | void Bar::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
37 | { |
|
37 | { | |
38 | Q_UNUSED(event) |
|
38 | Q_UNUSED(event) | |
39 |
emit clicked(m_barset, m_ |
|
39 | emit clicked(m_barset, m_index); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
42 | void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
43 | { |
|
43 | { | |
44 | Q_UNUSED(event) |
|
44 | Q_UNUSED(event) | |
45 | emit hovered(m_barset, true); |
|
45 | emit hovered(m_barset, true); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
48 | void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
49 | { |
|
49 | { | |
50 | Q_UNUSED(event) |
|
50 | Q_UNUSED(event) | |
51 | emit hovered(m_barset, false); |
|
51 | emit hovered(m_barset, false); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | #include "moc_bar_p.cpp" |
|
54 | #include "moc_bar_p.cpp" | |
55 |
|
55 | |||
56 | QTCOMMERCIALCHART_END_NAMESPACE |
|
56 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,65 +1,63 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef BAR_H |
|
30 | #ifndef BAR_H | |
31 | #define BAR_H |
|
31 | #define BAR_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include <QGraphicsRectItem> |
|
34 | #include <QGraphicsRectItem> | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 | class QBarSet; |
|
38 | class QBarSet; | |
39 |
|
39 | |||
40 | // Single visual bar item of chart |
|
40 | // Single visual bar item of chart | |
41 | class Bar : public QObject, public QGraphicsRectItem |
|
41 | class Bar : public QObject, public QGraphicsRectItem | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 | public: |
|
44 | public: | |
45 |
Bar(QBarSet *barset, |
|
45 | Bar(QBarSet *barset, int index, QGraphicsItem *parent = 0); | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
48 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
49 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); |
|
49 | void hoverEnterEvent(QGraphicsSceneHoverEvent *event); | |
50 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
50 | void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); | |
51 |
|
51 | |||
52 | Q_SIGNALS: |
|
52 | Q_SIGNALS: | |
53 |
void clicked(QSt |
|
53 | void clicked(QBarSet *barset, int index); | |
54 | void clicked(QBarSet *barset, QString category); |
|
|||
55 | void hovered(bool status); |
|
|||
56 | void hovered(QBarSet *barset, bool status); |
|
54 | void hovered(QBarSet *barset, bool status); | |
57 |
|
55 | |||
58 | private: |
|
56 | private: | |
59 | QString m_category; |
|
57 | int m_index; | |
60 | QBarSet *m_barset; |
|
58 | QBarSet *m_barset; | |
61 | }; |
|
59 | }; | |
62 |
|
60 | |||
63 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE | |
64 |
|
62 | |||
65 | #endif // BAR_H |
|
63 | #endif // BAR_H |
@@ -1,216 +1,215 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "barchartitem_p.h" |
|
21 | #include "barchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qbarseries.h" | |
26 | #include "qbarseries_p.h" |
|
26 | #include "qbarseries_p.h" | |
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QPainter> |
|
31 | #include <QPainter> | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
35 | BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
36 | ChartItem(presenter), |
|
36 | ChartItem(presenter), | |
37 | m_series(series) |
|
37 | m_series(series) | |
38 | { |
|
38 | { | |
39 | setFlag(ItemClipsChildrenToShape); |
|
39 | setFlag(ItemClipsChildrenToShape); | |
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); |
|
40 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged())); | |
41 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); |
|
41 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleModelChanged())); | |
42 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool))); |
|
42 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(labelsVisibleChanged(bool))); | |
43 | setZValue(ChartPresenter::BarSeriesZValue); |
|
43 | setZValue(ChartPresenter::BarSeriesZValue); | |
44 | dataChanged(); |
|
44 | dataChanged(); | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | BarChartItem::~BarChartItem() |
|
47 | BarChartItem::~BarChartItem() | |
48 | { |
|
48 | { | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
52 | { |
|
52 | { | |
53 | Q_UNUSED(painter); |
|
53 | Q_UNUSED(painter); | |
54 | Q_UNUSED(option); |
|
54 | Q_UNUSED(option); | |
55 | Q_UNUSED(widget); |
|
55 | Q_UNUSED(widget); | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | QRectF BarChartItem::boundingRect() const |
|
58 | QRectF BarChartItem::boundingRect() const | |
59 | { |
|
59 | { | |
60 | return m_rect; |
|
60 | return m_rect; | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void BarChartItem::dataChanged() |
|
63 | void BarChartItem::dataChanged() | |
64 | { |
|
64 | { | |
65 | foreach(QGraphicsItem *item, childItems()) { |
|
65 | foreach(QGraphicsItem *item, childItems()) { | |
66 | delete item; |
|
66 | delete item; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | m_bars.clear(); |
|
69 | m_bars.clear(); | |
70 | m_labels.clear(); |
|
70 | m_labels.clear(); | |
71 | m_layout.clear(); |
|
71 | m_layout.clear(); | |
72 |
|
72 | |||
73 | bool labelsVisible = m_series->isLabelsVisible(); |
|
73 | bool labelsVisible = m_series->isLabelsVisible(); | |
74 |
|
74 | |||
75 | // Create new graphic items for bars |
|
75 | // Create new graphic items for bars | |
76 | for (int c = 0; c < m_series->categoryCount(); c++) { |
|
76 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
77 | QString category = m_series->d_func()->categoryName(c); |
|
|||
78 | for (int s = 0; s < m_series->barsetCount(); s++) { |
|
77 | for (int s = 0; s < m_series->barsetCount(); s++) { | |
79 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
78 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
80 |
|
79 | |||
81 | // Bars |
|
80 | // Bars | |
82 |
Bar *bar = new Bar(set,c |
|
81 | Bar *bar = new Bar(set,c,this); | |
83 | m_bars.append(bar); |
|
82 | m_bars.append(bar); | |
84 |
connect(bar, SIGNAL(clicked(QBarSet*, |
|
83 | connect(bar, SIGNAL(clicked(QBarSet*,int)), m_series, SIGNAL(clicked(QBarSet*,int))); | |
85 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); |
|
84 | connect(bar, SIGNAL(hovered(QBarSet*,bool)), m_series, SIGNAL(hovered(QBarSet*,bool))); | |
86 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
85 | m_layout.append(QRectF(0, 0, 0, 0)); | |
87 |
|
86 | |||
88 | // Labels |
|
87 | // Labels | |
89 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); |
|
88 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
90 | label->setVisible(labelsVisible); |
|
89 | label->setVisible(labelsVisible); | |
91 | m_labels.append(label); |
|
90 | m_labels.append(label); | |
92 | } |
|
91 | } | |
93 | } |
|
92 | } | |
94 |
|
93 | |||
95 | // TODO: Is this the right place to call it? |
|
94 | // TODO: Is this the right place to call it? | |
96 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
95 | // presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
97 | } |
|
96 | } | |
98 |
|
97 | |||
99 | QVector<QRectF> BarChartItem::calculateLayout() |
|
98 | QVector<QRectF> BarChartItem::calculateLayout() | |
100 | { |
|
99 | { | |
101 | QVector<QRectF> layout; |
|
100 | QVector<QRectF> layout; | |
102 |
|
101 | |||
103 |
// Use temporary qreals for accura |
|
102 | // Use temporary qreals for accuracy | |
104 | qreal categoryCount = m_series->categoryCount(); |
|
103 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
105 | qreal setCount = m_series->barsetCount(); |
|
104 | qreal setCount = m_series->barsetCount(); | |
106 | bool barsVisible = m_series->isVisible(); |
|
105 | bool barsVisible = m_series->isVisible(); | |
107 |
|
106 | |||
108 | // Domain: |
|
107 | // Domain: | |
109 | qreal width = geometry().width(); |
|
108 | qreal width = geometry().width(); | |
110 | qreal height = geometry().height(); |
|
109 | qreal height = geometry().height(); | |
111 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
110 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
112 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
111 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
113 | qreal scaleY = (height / rangeY); |
|
112 | qreal scaleY = (height / rangeY); | |
114 | qreal scaleX = (width / rangeX); |
|
113 | qreal scaleX = (width / rangeX); | |
115 | qreal categoryWidth = width / categoryCount; |
|
114 | qreal categoryWidth = width / categoryCount; | |
116 | qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin(); |
|
115 | qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin(); | |
117 |
|
116 | |||
118 | int itemIndex(0); |
|
117 | int itemIndex(0); | |
119 | for (int category = 0; category < categoryCount; category++) { |
|
118 | for (int category = 0; category < categoryCount; category++) { | |
120 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
119 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
121 | for (int set = 0; set < setCount; set++) { |
|
120 | for (int set = 0; set < setCount; set++) { | |
122 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
121 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
123 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
122 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
124 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
123 | qreal barHeight = barSet->at(category).y() * scaleY; | |
125 |
|
124 | |||
126 | Bar* bar = m_bars.at(itemIndex); |
|
125 | Bar* bar = m_bars.at(itemIndex); | |
127 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
126 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
128 |
|
127 | |||
129 | layout.append(rect); |
|
128 | layout.append(rect); | |
130 | bar->setPen(barSet->pen()); |
|
129 | bar->setPen(barSet->pen()); | |
131 | bar->setBrush(barSet->brush()); |
|
130 | bar->setBrush(barSet->brush()); | |
132 | bar->setVisible(barsVisible); |
|
131 | bar->setVisible(barsVisible); | |
133 |
|
132 | |||
134 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
133 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
135 |
|
134 | |||
136 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
135 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
137 | label->setText(QString::number(barSet->at(category).y())); |
|
136 | label->setText(QString::number(barSet->at(category).y())); | |
138 | } else { |
|
137 | } else { | |
139 | label->setText(QString("")); |
|
138 | label->setText(QString("")); | |
140 | } |
|
139 | } | |
141 |
|
140 | |||
142 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
141 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
143 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
142 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
144 | label->setFont(barSet->labelFont()); |
|
143 | label->setFont(barSet->labelFont()); | |
145 | label->setBrush(barSet->labelBrush()); |
|
144 | label->setBrush(barSet->labelBrush()); | |
146 |
|
145 | |||
147 | itemIndex++; |
|
146 | itemIndex++; | |
148 | } |
|
147 | } | |
149 | } |
|
148 | } | |
150 |
|
149 | |||
151 | return layout; |
|
150 | return layout; | |
152 | } |
|
151 | } | |
153 |
|
152 | |||
154 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
153 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
155 | { |
|
154 | { | |
156 | if (animator()) |
|
155 | if (animator()) | |
157 | animator()->updateLayout(this, m_layout, layout); |
|
156 | animator()->updateLayout(this, m_layout, layout); | |
158 | else |
|
157 | else | |
159 | setLayout(layout); |
|
158 | setLayout(layout); | |
160 | } |
|
159 | } | |
161 |
|
160 | |||
162 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
161 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
163 | { |
|
162 | { | |
164 | m_layout = layout; |
|
163 | m_layout = layout; | |
165 |
|
164 | |||
166 | for (int i=0; i < m_bars.count(); i++) |
|
165 | for (int i=0; i < m_bars.count(); i++) | |
167 | m_bars.at(i)->setRect(layout.at(i)); |
|
166 | m_bars.at(i)->setRect(layout.at(i)); | |
168 |
|
167 | |||
169 | update(); |
|
168 | update(); | |
170 | } |
|
169 | } | |
171 | //handlers |
|
170 | //handlers | |
172 |
|
171 | |||
173 | void BarChartItem::handleModelChanged() |
|
172 | void BarChartItem::handleModelChanged() | |
174 | { |
|
173 | { | |
175 | // dataChanged(); |
|
174 | // dataChanged(); | |
176 | presenter()->resetAllElements(); |
|
175 | presenter()->resetAllElements(); | |
177 | } |
|
176 | } | |
178 |
|
177 | |||
179 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
178 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
180 | { |
|
179 | { | |
181 | m_domainMinX = minX; |
|
180 | m_domainMinX = minX; | |
182 | m_domainMaxX = maxX; |
|
181 | m_domainMaxX = maxX; | |
183 | m_domainMinY = minY; |
|
182 | m_domainMinY = minY; | |
184 | m_domainMaxY = maxY; |
|
183 | m_domainMaxY = maxY; | |
185 | handleLayoutChanged(); |
|
184 | handleLayoutChanged(); | |
186 | } |
|
185 | } | |
187 |
|
186 | |||
188 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
187 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
189 | { |
|
188 | { | |
190 | prepareGeometryChange(); |
|
189 | prepareGeometryChange(); | |
191 | m_rect = rect; |
|
190 | m_rect = rect; | |
192 | handleLayoutChanged(); |
|
191 | handleLayoutChanged(); | |
193 | } |
|
192 | } | |
194 |
|
193 | |||
195 | void BarChartItem::handleLayoutChanged() |
|
194 | void BarChartItem::handleLayoutChanged() | |
196 | { |
|
195 | { | |
197 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
196 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
198 | // rect size zero. |
|
197 | // rect size zero. | |
199 | return; |
|
198 | return; | |
200 | } |
|
199 | } | |
201 | QVector<QRectF> layout = calculateLayout(); |
|
200 | QVector<QRectF> layout = calculateLayout(); | |
202 | applyLayout(layout); |
|
201 | applyLayout(layout); | |
203 | update(); |
|
202 | update(); | |
204 | } |
|
203 | } | |
205 |
|
204 | |||
206 | void BarChartItem::labelsVisibleChanged(bool visible) |
|
205 | void BarChartItem::labelsVisibleChanged(bool visible) | |
207 | { |
|
206 | { | |
208 | foreach (QGraphicsSimpleTextItem* label, m_labels) { |
|
207 | foreach (QGraphicsSimpleTextItem* label, m_labels) { | |
209 | label->setVisible(visible); |
|
208 | label->setVisible(visible); | |
210 | } |
|
209 | } | |
211 | update(); |
|
210 | update(); | |
212 | } |
|
211 | } | |
213 |
|
212 | |||
214 | #include "moc_barchartitem_p.cpp" |
|
213 | #include "moc_barchartitem_p.cpp" | |
215 |
|
214 | |||
216 | QTCOMMERCIALCHART_END_NAMESPACE |
|
215 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,90 +1,90 | |||||
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 "groupedbarchartitem_p.h" |
|
21 | #include "groupedbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset_p.h" |
|
23 | #include "qbarset_p.h" | |
24 | #include "qbarseries_p.h" |
|
24 | #include "qbarseries_p.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | GroupedBarChartItem::GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | GroupedBarChartItem::GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QVector<QRectF> GroupedBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> GroupedBarChartItem::calculateLayout() | |
35 | { |
|
35 | { | |
36 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
37 |
|
37 | |||
38 |
// Use temporary qreals for accura |
|
38 | // Use temporary qreals for accuracy | |
39 | qreal categoryCount = m_series->categoryCount(); |
|
39 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
40 | qreal setCount = m_series->barsetCount(); |
|
40 | qreal setCount = m_series->barsetCount(); | |
41 |
|
41 | |||
42 | // Domain: |
|
42 | // Domain: | |
43 | qreal width = geometry().width(); |
|
43 | qreal width = geometry().width(); | |
44 | qreal height = geometry().height(); |
|
44 | qreal height = geometry().height(); | |
45 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
45 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
46 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
46 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
47 | qreal scaleY = (height / rangeY); |
|
47 | qreal scaleY = (height / rangeY); | |
48 | qreal scaleX = (width / rangeX); |
|
48 | qreal scaleX = (width / rangeX); | |
49 | qreal categoryWidth = width / categoryCount; |
|
49 | qreal categoryWidth = width / categoryCount; | |
50 | qreal barWidth = categoryWidth / setCount - (categoryWidth / setCount) * m_series->d_func()->barMargin(); |
|
50 | qreal barWidth = categoryWidth / setCount - (categoryWidth / setCount) * m_series->d_func()->barMargin(); | |
51 |
|
51 | |||
52 | int itemIndex(0); |
|
52 | int itemIndex(0); | |
53 | for (int category = 0; category < categoryCount; category++) { |
|
53 | for (int category = 0; category < categoryCount; category++) { | |
54 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
54 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
55 | for (int set = 0; set < setCount; set++) { |
|
55 | for (int set = 0; set < setCount; set++) { | |
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
56 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
57 |
|
57 | |||
58 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left(); |
|
58 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left(); | |
59 | xPos -= setCount*barWidth/2; |
|
59 | xPos -= setCount*barWidth/2; | |
60 | xPos += set*barWidth; |
|
60 | xPos += set*barWidth; | |
61 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
61 | qreal barHeight = barSet->at(category).y() * scaleY; | |
62 | Bar* bar = m_bars.at(itemIndex); |
|
62 | Bar* bar = m_bars.at(itemIndex); | |
63 |
|
63 | |||
64 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
64 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
65 | layout.append(rect); |
|
65 | layout.append(rect); | |
66 | bar->setPen(barSet->pen()); |
|
66 | bar->setPen(barSet->pen()); | |
67 | bar->setBrush(barSet->brush()); |
|
67 | bar->setBrush(barSet->brush()); | |
68 |
|
68 | |||
69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
70 |
|
70 | |||
71 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
71 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
72 | label->setText(QString::number(barSet->at(category).y())); |
|
72 | label->setText(QString::number(barSet->at(category).y())); | |
73 | } else { |
|
73 | } else { | |
74 | label->setText(QString("")); |
|
74 | label->setText(QString("")); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
77 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
78 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
78 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
79 | label->setFont(barSet->labelFont()); |
|
79 | label->setFont(barSet->labelFont()); | |
80 | label->setBrush(barSet->labelBrush()); |
|
80 | label->setBrush(barSet->labelBrush()); | |
81 |
|
81 | |||
82 | itemIndex++; |
|
82 | itemIndex++; | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 | return layout; |
|
85 | return layout; | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | #include "moc_groupedbarchartitem_p.cpp" |
|
88 | #include "moc_groupedbarchartitem_p.cpp" | |
89 |
|
89 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,94 +1,94 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "percentbarchartitem_p.h" |
|
21 | #include "percentbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarseries_p.h" |
|
23 | #include "qbarseries_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
35 | { |
|
35 | { | |
36 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
37 |
|
37 | |||
38 |
// Use temporary qreals for accura |
|
38 | // Use temporary qreals for accuracy | |
39 | qreal categoryCount = m_series->categoryCount(); |
|
39 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
40 | qreal setCount = m_series->barsetCount(); |
|
40 | qreal setCount = m_series->barsetCount(); | |
41 |
|
41 | |||
42 | // Domain: |
|
42 | // Domain: | |
43 | qreal width = geometry().width(); |
|
43 | qreal width = geometry().width(); | |
44 | qreal height = geometry().height(); |
|
44 | qreal height = geometry().height(); | |
45 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
45 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
46 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
46 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
47 | qreal scaleY = (height / rangeY); |
|
47 | qreal scaleY = (height / rangeY); | |
48 | qreal scaleX = (width / rangeX); |
|
48 | qreal scaleX = (width / rangeX); | |
49 | qreal categoryWidth = width / categoryCount; |
|
49 | qreal categoryWidth = width / categoryCount; | |
50 | qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin(); |
|
50 | qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin(); | |
51 |
|
51 | |||
52 | int itemIndex(0); |
|
52 | int itemIndex(0); | |
53 | for (int category = 0; category < categoryCount; category++) { |
|
53 | for (int category = 0; category < categoryCount; category++) { | |
54 | qreal colSum = m_series->d_func()->categorySum(category); |
|
54 | qreal colSum = m_series->d_func()->categorySum(category); | |
55 | qreal percentage = (100 / colSum); |
|
55 | qreal percentage = (100 / colSum); | |
56 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
56 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
57 | for (int set=0; set < setCount; set++) { |
|
57 | for (int set=0; set < setCount; set++) { | |
58 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
58 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
59 |
|
59 | |||
60 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
60 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
61 |
|
61 | |||
62 | qreal barHeight = barSet->at(category).y() * percentage * scaleY; |
|
62 | qreal barHeight = barSet->at(category).y() * percentage * scaleY; | |
63 | Bar* bar = m_bars.at(itemIndex); |
|
63 | Bar* bar = m_bars.at(itemIndex); | |
64 | bar->setPen(barSet->pen()); |
|
64 | bar->setPen(barSet->pen()); | |
65 | bar->setBrush(barSet->brush()); |
|
65 | bar->setBrush(barSet->brush()); | |
66 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
66 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
67 | layout.append(rect); |
|
67 | layout.append(rect); | |
68 |
|
68 | |||
69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
69 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
70 |
|
70 | |||
71 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { |
|
71 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { | |
72 | int p = m_series->d_func()->percentageAt(set,category) * 100; |
|
72 | int p = m_series->d_func()->percentageAt(set,category) * 100; | |
73 | QString vString(QString::number(p)); |
|
73 | QString vString(QString::number(p)); | |
74 | vString.truncate(3); |
|
74 | vString.truncate(3); | |
75 | vString.append("%"); |
|
75 | vString.append("%"); | |
76 | label->setText(vString); |
|
76 | label->setText(vString); | |
77 | } else { |
|
77 | } else { | |
78 | label->setText(QString("")); |
|
78 | label->setText(QString("")); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
81 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
82 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
82 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
83 | label->setFont(barSet->labelFont()); |
|
83 | label->setFont(barSet->labelFont()); | |
84 | label->setBrush(barSet->labelBrush()); |
|
84 | label->setBrush(barSet->labelBrush()); | |
85 | itemIndex++; |
|
85 | itemIndex++; | |
86 | yPos -= barHeight; |
|
86 | yPos -= barHeight; | |
87 | } |
|
87 | } | |
88 | } |
|
88 | } | |
89 | return layout; |
|
89 | return layout; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | #include "moc_percentbarchartitem_p.cpp" |
|
92 | #include "moc_percentbarchartitem_p.cpp" | |
93 |
|
93 | |||
94 | QTCOMMERCIALCHART_END_NAMESPACE |
|
94 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,423 +1,424 | |||||
1 | #include "qbarmodelmapper.h" |
|
1 | #include "qbarmodelmapper.h" | |
2 | #include "qbarmodelmapper_p.h" |
|
2 | #include "qbarmodelmapper_p.h" | |
3 | #include "qbarseries.h" |
|
3 | #include "qbarseries.h" | |
4 | #include "qbarset.h" |
|
4 | #include "qbarset.h" | |
5 | #include <QAbstractItemModel> |
|
5 | #include <QAbstractItemModel> | |
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
8 |
|
8 | |||
9 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
9 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
10 | QObject(parent), |
|
10 | QObject(parent), | |
11 | d_ptr(new QBarModelMapperPrivate(this)) |
|
11 | d_ptr(new QBarModelMapperPrivate(this)) | |
12 | { |
|
12 | { | |
13 | } |
|
13 | } | |
14 |
|
14 | |||
15 | QAbstractItemModel* QBarModelMapper::model() const |
|
15 | QAbstractItemModel* QBarModelMapper::model() const | |
16 | { |
|
16 | { | |
17 | Q_D(const QBarModelMapper); |
|
17 | Q_D(const QBarModelMapper); | |
18 | return d->m_model; |
|
18 | return d->m_model; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
21 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
22 | { |
|
22 | { | |
23 | if (model == 0) |
|
23 | if (model == 0) | |
24 | return; |
|
24 | return; | |
25 |
|
25 | |||
26 | Q_D(QBarModelMapper); |
|
26 | Q_D(QBarModelMapper); | |
27 | if (d->m_model) { |
|
27 | if (d->m_model) { | |
28 | disconnect(d->m_model, 0, d, 0); |
|
28 | disconnect(d->m_model, 0, d, 0); | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | d->m_model = model; |
|
31 | d->m_model = model; | |
32 | d->initializeBarFromModel(); |
|
32 | d->initializeBarFromModel(); | |
33 | // connect signals from the model |
|
33 | // connect signals from the model | |
34 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
34 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
35 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
35 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
36 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
36 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
37 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
37 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
38 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
38 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
39 | } |
|
39 | } | |
40 |
|
40 | |||
41 | QBarSeries* QBarModelMapper::series() const |
|
41 | QBarSeries* QBarModelMapper::series() const | |
42 | { |
|
42 | { | |
43 | Q_D(const QBarModelMapper); |
|
43 | Q_D(const QBarModelMapper); | |
44 | return d->m_series; |
|
44 | return d->m_series; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void QBarModelMapper::setSeries(QBarSeries *series) |
|
47 | void QBarModelMapper::setSeries(QBarSeries *series) | |
48 | { |
|
48 | { | |
49 | Q_D(QBarModelMapper); |
|
49 | Q_D(QBarModelMapper); | |
50 | if (d->m_series) { |
|
50 | if (d->m_series) { | |
51 | disconnect(d->m_series, 0, d, 0); |
|
51 | disconnect(d->m_series, 0, d, 0); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | if (series == 0) |
|
54 | if (series == 0) | |
55 | return; |
|
55 | return; | |
56 |
|
56 | |||
57 | d->m_series = series; |
|
57 | d->m_series = series; | |
58 | d->initializeBarFromModel(); |
|
58 | d->initializeBarFromModel(); | |
59 | // connect the signals from the series |
|
59 | // connect the signals from the series | |
60 | // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); |
|
60 | // connect(d->m_series, SIGNAL(pointAdded(int)), d, SLOT(handlePointAdded(int))); | |
61 | // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); |
|
61 | // connect(d->m_series, SIGNAL(pointRemoved(int)), d, SLOT(handlePointRemoved(int))); | |
62 | // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); |
|
62 | // connect(d->m_series, SIGNAL(pointReplaced(int)), d, SLOT(handlePointReplaced(int))); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | int QBarModelMapper::first() const |
|
65 | int QBarModelMapper::first() const | |
66 | { |
|
66 | { | |
67 | Q_D(const QBarModelMapper); |
|
67 | Q_D(const QBarModelMapper); | |
68 | return d->m_first; |
|
68 | return d->m_first; | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void QBarModelMapper::setFirst(int first) |
|
71 | void QBarModelMapper::setFirst(int first) | |
72 | { |
|
72 | { | |
73 | Q_D(QBarModelMapper); |
|
73 | Q_D(QBarModelMapper); | |
74 | d->m_first = qMax(first, 0); |
|
74 | d->m_first = qMax(first, 0); | |
75 | d->initializeBarFromModel(); |
|
75 | d->initializeBarFromModel(); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | int QBarModelMapper::count() const |
|
78 | int QBarModelMapper::count() const | |
79 | { |
|
79 | { | |
80 | Q_D(const QBarModelMapper); |
|
80 | Q_D(const QBarModelMapper); | |
81 | return d->m_count; |
|
81 | return d->m_count; | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | void QBarModelMapper::setCount(int count) |
|
84 | void QBarModelMapper::setCount(int count) | |
85 | { |
|
85 | { | |
86 | Q_D(QBarModelMapper); |
|
86 | Q_D(QBarModelMapper); | |
87 | d->m_count = qMax(count, -1); |
|
87 | d->m_count = qMax(count, -1); | |
88 | d->initializeBarFromModel(); |
|
88 | d->initializeBarFromModel(); | |
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | Qt::Orientation QBarModelMapper::orientation() const |
|
91 | Qt::Orientation QBarModelMapper::orientation() const | |
92 | { |
|
92 | { | |
93 | Q_D(const QBarModelMapper); |
|
93 | Q_D(const QBarModelMapper); | |
94 | return d->m_orientation; |
|
94 | return d->m_orientation; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
97 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
98 | { |
|
98 | { | |
99 | Q_D(QBarModelMapper); |
|
99 | Q_D(QBarModelMapper); | |
100 | d->m_orientation = orientation; |
|
100 | d->m_orientation = orientation; | |
101 | d->initializeBarFromModel(); |
|
101 | d->initializeBarFromModel(); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | int QBarModelMapper::firstBarSetSection() const |
|
104 | int QBarModelMapper::firstBarSetSection() const | |
105 | { |
|
105 | { | |
106 | Q_D(const QBarModelMapper); |
|
106 | Q_D(const QBarModelMapper); | |
107 | return d->m_firstBarSetSection; |
|
107 | return d->m_firstBarSetSection; | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
110 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
111 | { |
|
111 | { | |
112 | Q_D(QBarModelMapper); |
|
112 | Q_D(QBarModelMapper); | |
113 | d->m_firstBarSetSection = firstBarSetSection; |
|
113 | d->m_firstBarSetSection = firstBarSetSection; | |
114 | d->initializeBarFromModel(); |
|
114 | d->initializeBarFromModel(); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | int QBarModelMapper::lastBarSetSection() const |
|
117 | int QBarModelMapper::lastBarSetSection() const | |
118 | { |
|
118 | { | |
119 | Q_D(const QBarModelMapper); |
|
119 | Q_D(const QBarModelMapper); | |
120 | return d->m_lastBarSetSection; |
|
120 | return d->m_lastBarSetSection; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
123 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
124 | { |
|
124 | { | |
125 | Q_D(QBarModelMapper); |
|
125 | Q_D(QBarModelMapper); | |
126 | d->m_lastBarSetSection = lastBarSetSection; |
|
126 | d->m_lastBarSetSection = lastBarSetSection; | |
127 | d->initializeBarFromModel(); |
|
127 | d->initializeBarFromModel(); | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | int QBarModelMapper::categoriesSection() const |
|
130 | int QBarModelMapper::categoriesSection() const | |
131 | { |
|
131 | { | |
132 | Q_D(const QBarModelMapper); |
|
132 | Q_D(const QBarModelMapper); | |
133 | return d->m_categoriesSection; |
|
133 | return d->m_categoriesSection; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void QBarModelMapper::setCategoriesSection(int categoriesSection) |
|
136 | void QBarModelMapper::setCategoriesSection(int categoriesSection) | |
137 | { |
|
137 | { | |
138 | Q_D(QBarModelMapper); |
|
138 | Q_D(QBarModelMapper); | |
139 | d->m_categoriesSection = categoriesSection; |
|
139 | d->m_categoriesSection = categoriesSection; | |
140 | d->initializeBarFromModel(); |
|
140 | d->initializeBarFromModel(); | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | void QBarModelMapper::reset() |
|
143 | void QBarModelMapper::reset() | |
144 | { |
|
144 | { | |
145 | Q_D(QBarModelMapper); |
|
145 | Q_D(QBarModelMapper); | |
146 | d->m_first = 0; |
|
146 | d->m_first = 0; | |
147 | d->m_count = -1; |
|
147 | d->m_count = -1; | |
148 | d->m_orientation = Qt::Vertical; |
|
148 | d->m_orientation = Qt::Vertical; | |
149 | d->m_firstBarSetSection = -1; |
|
149 | d->m_firstBarSetSection = -1; | |
150 | d->m_lastBarSetSection = -1; |
|
150 | d->m_lastBarSetSection = -1; | |
151 | d->m_categoriesSection = -1; |
|
151 | d->m_categoriesSection = -1; | |
152 | d->initializeBarFromModel(); |
|
152 | d->initializeBarFromModel(); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
156 |
|
156 | |||
157 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
157 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
158 | m_series(0), |
|
158 | m_series(0), | |
159 | m_model(0), |
|
159 | m_model(0), | |
160 | m_first(0), |
|
160 | m_first(0), | |
161 | m_count(-1), |
|
161 | m_count(-1), | |
162 | m_orientation(Qt::Vertical), |
|
162 | m_orientation(Qt::Vertical), | |
163 | m_firstBarSetSection(-1), |
|
163 | m_firstBarSetSection(-1), | |
164 | m_lastBarSetSection(-1), |
|
164 | m_lastBarSetSection(-1), | |
165 | m_categoriesSection(-1), |
|
165 | m_categoriesSection(-1), | |
166 | m_seriesSignalsBlock(false), |
|
166 | m_seriesSignalsBlock(false), | |
167 | m_modelSignalsBlock(false), |
|
167 | m_modelSignalsBlock(false), | |
168 | q_ptr(q) |
|
168 | q_ptr(q) | |
169 | { |
|
169 | { | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
172 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
173 | { |
|
173 | { | |
174 | m_modelSignalsBlock = block; |
|
174 | m_modelSignalsBlock = block; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
177 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
178 | { |
|
178 | { | |
179 | m_seriesSignalsBlock = block; |
|
179 | m_seriesSignalsBlock = block; | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
182 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
183 | { |
|
183 | { | |
184 | if (!index.isValid()) |
|
184 | if (!index.isValid()) | |
185 | return 0; |
|
185 | return 0; | |
186 |
|
186 | |||
187 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
187 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
188 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) |
|
188 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) | |
189 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
189 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
190 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
190 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
191 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
191 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
192 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
192 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
193 | } |
|
193 | } | |
194 | return 0; // This part of model has not been mapped to any slice |
|
194 | return 0; // This part of model has not been mapped to any slice | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
197 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
198 | { |
|
198 | { | |
199 | if (m_count != -1 && posInBar >= m_count) |
|
199 | if (m_count != -1 && posInBar >= m_count) | |
200 | return QModelIndex(); // invalid |
|
200 | return QModelIndex(); // invalid | |
201 |
|
201 | |||
202 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
202 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
203 | return QModelIndex(); // invalid |
|
203 | return QModelIndex(); // invalid | |
204 |
|
204 | |||
205 | if (m_orientation == Qt::Vertical) |
|
205 | if (m_orientation == Qt::Vertical) | |
206 | return m_model->index(posInBar + m_first, barSection); |
|
206 | return m_model->index(posInBar + m_first, barSection); | |
207 | else |
|
207 | else | |
208 | return m_model->index(barSection, posInBar + m_first); |
|
208 | return m_model->index(barSection, posInBar + m_first); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories) |
|
211 | QModelIndex QBarModelMapperPrivate::categoriesModelIndex(int posInCategories) | |
212 | { |
|
212 | { | |
213 | if (m_count != -1 && posInCategories >= m_count) |
|
213 | if (m_count != -1 && posInCategories >= m_count) | |
214 | return QModelIndex(); // invalid |
|
214 | return QModelIndex(); // invalid | |
215 |
|
215 | |||
216 | if (m_orientation == Qt::Vertical) |
|
216 | if (m_orientation == Qt::Vertical) | |
217 | return m_model->index(posInCategories + m_first, m_categoriesSection); |
|
217 | return m_model->index(posInCategories + m_first, m_categoriesSection); | |
218 | else |
|
218 | else | |
219 | return m_model->index(m_categoriesSection, posInCategories + m_first); |
|
219 | return m_model->index(m_categoriesSection, posInCategories + m_first); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
222 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
223 | { |
|
223 | { | |
224 | Q_UNUSED(topLeft) |
|
224 | Q_UNUSED(topLeft) | |
225 | Q_UNUSED(bottomRight) |
|
225 | Q_UNUSED(bottomRight) | |
226 |
|
226 | |||
227 | if (m_model == 0 || m_series == 0) |
|
227 | if (m_model == 0 || m_series == 0) | |
228 | return; |
|
228 | return; | |
229 |
|
229 | |||
230 | if (m_modelSignalsBlock) |
|
230 | if (m_modelSignalsBlock) | |
231 | return; |
|
231 | return; | |
232 |
|
232 | |||
233 | blockSeriesSignals(); |
|
233 | blockSeriesSignals(); | |
234 | QModelIndex index; |
|
234 | QModelIndex index; | |
235 | // QPointF oldPoint; |
|
235 | // QPointF oldPoint; | |
236 | // QPointF newPoint; |
|
236 | // QPointF newPoint; | |
237 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
237 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
238 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
238 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
239 | index = topLeft.sibling(row, column); |
|
239 | index = topLeft.sibling(row, column); | |
240 | QBarSet* bar = barSet(index); |
|
240 | QBarSet* bar = barSet(index); | |
241 | if (bar) { |
|
241 | if (bar) { | |
242 | if (m_orientation == Qt::Vertical) |
|
242 | if (m_orientation == Qt::Vertical) | |
243 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
243 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
244 | else |
|
244 | else | |
245 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
245 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
246 | } |
|
246 | } | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 | blockSeriesSignals(false); |
|
249 | blockSeriesSignals(false); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
252 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
253 | { |
|
253 | { | |
254 | Q_UNUSED(parent); |
|
254 | Q_UNUSED(parent); | |
255 | Q_UNUSED(end) |
|
255 | Q_UNUSED(end) | |
256 | if (m_modelSignalsBlock) |
|
256 | if (m_modelSignalsBlock) | |
257 | return; |
|
257 | return; | |
258 |
|
258 | |||
259 | blockSeriesSignals(); |
|
259 | blockSeriesSignals(); | |
260 | if (m_orientation == Qt::Vertical) |
|
260 | if (m_orientation == Qt::Vertical) | |
261 | // insertData(start, end); |
|
261 | // insertData(start, end); | |
262 | initializeBarFromModel(); |
|
262 | initializeBarFromModel(); | |
263 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
263 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize | |
264 | initializeBarFromModel(); |
|
264 | initializeBarFromModel(); | |
265 | blockSeriesSignals(false); |
|
265 | blockSeriesSignals(false); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
268 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
269 | { |
|
269 | { | |
270 | Q_UNUSED(parent); |
|
270 | Q_UNUSED(parent); | |
271 | Q_UNUSED(end) |
|
271 | Q_UNUSED(end) | |
272 | if (m_modelSignalsBlock) |
|
272 | if (m_modelSignalsBlock) | |
273 | return; |
|
273 | return; | |
274 |
|
274 | |||
275 | blockSeriesSignals(); |
|
275 | blockSeriesSignals(); | |
276 | if (m_orientation == Qt::Vertical) |
|
276 | if (m_orientation == Qt::Vertical) | |
277 | // removeData(start, end); |
|
277 | // removeData(start, end); | |
278 | initializeBarFromModel(); |
|
278 | initializeBarFromModel(); | |
279 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
279 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize | |
280 | initializeBarFromModel(); |
|
280 | initializeBarFromModel(); | |
281 | blockSeriesSignals(false); |
|
281 | blockSeriesSignals(false); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
284 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
285 | { |
|
285 | { | |
286 | Q_UNUSED(parent); |
|
286 | Q_UNUSED(parent); | |
287 | Q_UNUSED(end) |
|
287 | Q_UNUSED(end) | |
288 | if (m_modelSignalsBlock) |
|
288 | if (m_modelSignalsBlock) | |
289 | return; |
|
289 | return; | |
290 |
|
290 | |||
291 | blockSeriesSignals(); |
|
291 | blockSeriesSignals(); | |
292 | if (m_orientation == Qt::Horizontal) |
|
292 | if (m_orientation == Qt::Horizontal) | |
293 | // insertData(start, end); |
|
293 | // insertData(start, end); | |
294 | initializeBarFromModel(); |
|
294 | initializeBarFromModel(); | |
295 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
295 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize | |
296 | initializeBarFromModel(); |
|
296 | initializeBarFromModel(); | |
297 | blockSeriesSignals(false); |
|
297 | blockSeriesSignals(false); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
300 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
301 | { |
|
301 | { | |
302 | Q_UNUSED(parent); |
|
302 | Q_UNUSED(parent); | |
303 | Q_UNUSED(end) |
|
303 | Q_UNUSED(end) | |
304 | if (m_modelSignalsBlock) |
|
304 | if (m_modelSignalsBlock) | |
305 | return; |
|
305 | return; | |
306 |
|
306 | |||
307 | blockSeriesSignals(); |
|
307 | blockSeriesSignals(); | |
308 | if (m_orientation == Qt::Horizontal) |
|
308 | if (m_orientation == Qt::Horizontal) | |
309 | // removeData(start, end); |
|
309 | // removeData(start, end); | |
310 | initializeBarFromModel(); |
|
310 | initializeBarFromModel(); | |
311 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize |
|
311 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection || start <= m_categoriesSection) // if the changes affect the map - reinitialize | |
312 | initializeBarFromModel(); |
|
312 | initializeBarFromModel(); | |
313 | blockSeriesSignals(false); |
|
313 | blockSeriesSignals(false); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
316 | void QBarModelMapperPrivate::insertData(int start, int end) | |
317 | { |
|
317 | { | |
318 | Q_UNUSED(end) |
|
318 | Q_UNUSED(end) | |
319 | if (m_model == 0 || m_series == 0) |
|
319 | if (m_model == 0 || m_series == 0) | |
320 | return; |
|
320 | return; | |
321 |
|
321 | |||
322 | if (m_count != -1 && start >= m_first + m_count) { |
|
322 | if (m_count != -1 && start >= m_first + m_count) { | |
323 | return; |
|
323 | return; | |
324 | } /*else { |
|
324 | } /*else { | |
325 | int addedCount = end - start + 1; |
|
325 | int addedCount = end - start + 1; | |
326 | if (m_count != -1 && addedCount > m_count) |
|
326 | if (m_count != -1 && addedCount > m_count) | |
327 | addedCount = m_count; |
|
327 | addedCount = m_count; | |
328 | int first = qMax(start, m_first); |
|
328 | int first = qMax(start, m_first); | |
329 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); |
|
329 | int last = qMin(first + addedCount - 1, m_orientation == Qt::Vertical ? m_model->rowCount() - 1 : m_model->columnCount() - 1); | |
330 | for (int k = 0; k < m_series->barSets().count(); k++) { |
|
330 | for (int k = 0; k < m_series->barSets().count(); k++) { | |
331 | for (int i = first; i <= last; i++) { |
|
331 | for (int i = first; i <= last; i++) { | |
332 | QBar point; |
|
332 | QBar point; | |
333 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
333 | point.setX(m_model->data(xModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
334 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); |
|
334 | point.setY(m_model->data(yModelIndex(i - m_first), Qt::DisplayRole).toDouble()); | |
335 | m_series->insert(i - m_first, point); |
|
335 | m_series->insert(i - m_first, point); | |
336 | } |
|
336 | } | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | // remove excess of slices (abouve m_count) |
|
339 | // remove excess of slices (abouve m_count) | |
340 | if (m_count != -1 && m_series->points().size() > m_count) |
|
340 | if (m_count != -1 && m_series->points().size() > m_count) | |
341 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { |
|
341 | for (int i = m_series->points().size() - 1; i >= m_count; i--) { | |
342 | m_series->remove(m_series->points().at(i)); |
|
342 | m_series->remove(m_series->points().at(i)); | |
343 | } |
|
343 | } | |
344 | }*/ |
|
344 | }*/ | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
347 | void QBarModelMapperPrivate::removeData(int start, int end) | |
348 | { |
|
348 | { | |
349 | Q_UNUSED(end) |
|
349 | Q_UNUSED(end) | |
350 | if (m_model == 0 || m_series == 0) |
|
350 | if (m_model == 0 || m_series == 0) | |
351 | return; |
|
351 | return; | |
352 |
|
352 | |||
353 | // int removedCount = end - start + 1; |
|
353 | // int removedCount = end - start + 1; | |
354 | if (m_count != -1 && start >= m_first + m_count) { |
|
354 | if (m_count != -1 && start >= m_first + m_count) { | |
355 | return; |
|
355 | return; | |
356 | } /*else { |
|
356 | } /*else { | |
357 | int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed |
|
357 | int toRemove = qMin(m_series->count(), removedCount); // first find how many items can actually be removed | |
358 | int first = qMax(start, m_first); // get the index of the first item that will be removed. |
|
358 | int first = qMax(start, m_first); // get the index of the first item that will be removed. | |
359 | int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed. |
|
359 | int last = qMin(first + toRemove - 1, m_series->count() + m_first - 1); // get the index of the last item that will be removed. | |
360 | for (int i = last; i >= first; i--) { |
|
360 | for (int i = last; i >= first; i--) { | |
361 | m_series->remove(m_series->points().at(i - m_first)); |
|
361 | m_series->remove(m_series->points().at(i - m_first)); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | if (m_count != -1) { |
|
364 | if (m_count != -1) { | |
365 | int itemsAvailable; // check how many are available to be added |
|
365 | int itemsAvailable; // check how many are available to be added | |
366 | if (m_orientation == Qt::Vertical) |
|
366 | if (m_orientation == Qt::Vertical) | |
367 | itemsAvailable = m_model->rowCount() - m_first - m_series->count(); |
|
367 | itemsAvailable = m_model->rowCount() - m_first - m_series->count(); | |
368 | else |
|
368 | else | |
369 | itemsAvailable = m_model->columnCount() - m_first - m_series->count(); |
|
369 | itemsAvailable = m_model->columnCount() - m_first - m_series->count(); | |
370 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled. |
|
370 | int toBeAdded = qMin(itemsAvailable, m_count - m_series->count()); // add not more items than there is space left to be filled. | |
371 | int currentSize = m_series->count(); |
|
371 | int currentSize = m_series->count(); | |
372 | if (toBeAdded > 0) |
|
372 | if (toBeAdded > 0) | |
373 | for (int i = m_series->count(); i < currentSize + toBeAdded; i++) { |
|
373 | for (int i = m_series->count(); i < currentSize + toBeAdded; i++) { | |
374 | QPointF point; |
|
374 | QPointF point; | |
375 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); |
|
375 | point.setX(m_model->data(xModelIndex(i), Qt::DisplayRole).toDouble()); | |
376 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); |
|
376 | point.setY(m_model->data(yModelIndex(i), Qt::DisplayRole).toDouble()); | |
377 | m_series->insert(i, point); |
|
377 | m_series->insert(i, point); | |
378 | } |
|
378 | } | |
379 | } |
|
379 | } | |
380 | }*/ |
|
380 | }*/ | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
383 | void QBarModelMapperPrivate::initializeBarFromModel() | |
384 | { |
|
384 | { | |
385 | if (m_model == 0 || m_series == 0) |
|
385 | if (m_model == 0 || m_series == 0) | |
386 | return; |
|
386 | return; | |
387 |
|
387 | |||
388 | blockSeriesSignals(); |
|
388 | blockSeriesSignals(); | |
389 | // clear current content |
|
389 | // clear current content | |
390 | m_series->clear(); |
|
390 | m_series->clear(); | |
391 |
|
391 | |||
392 | // create the initial bar sets |
|
392 | // create the initial bar sets | |
393 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
393 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
394 | int posInBar = 0; |
|
394 | int posInBar = 0; | |
395 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
395 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
396 | QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); |
|
396 | QBarSet *barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal).toString()); | |
397 | // QModelIndex yIndex = yModelIndex(pointPos); |
|
397 | // QModelIndex yIndex = yModelIndex(pointPos); | |
398 | while (barIndex.isValid()) { |
|
398 | while (barIndex.isValid()) { | |
399 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
399 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
400 | posInBar++; |
|
400 | posInBar++; | |
401 | barIndex = barModelIndex(i, posInBar); |
|
401 | barIndex = barModelIndex(i, posInBar); | |
402 | } |
|
402 | } | |
403 | m_series->append(barSet); |
|
403 | m_series->append(barSet); | |
404 | } |
|
404 | } | |
405 |
|
405 | |||
406 | if (m_categoriesSection != -1) { |
|
406 | if (m_categoriesSection != -1) { | |
407 | int posInCategories = 0; |
|
407 | int posInCategories = 0; | |
408 | QStringList categories; |
|
408 | QStringList categories; | |
409 | QModelIndex categoriesIndex = categoriesModelIndex(posInCategories); |
|
409 | QModelIndex categoriesIndex = categoriesModelIndex(posInCategories); | |
410 | while (categoriesIndex.isValid()) { |
|
410 | while (categoriesIndex.isValid()) { | |
411 | categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString()); |
|
411 | categories.append(m_model->data(categoriesIndex, Qt::DisplayRole).toString()); | |
412 | posInCategories++; |
|
412 | posInCategories++; | |
413 | categoriesIndex = categoriesModelIndex(posInCategories); |
|
413 | categoriesIndex = categoriesModelIndex(posInCategories); | |
414 | } |
|
414 | } | |
415 | m_series->setCategories(categories); |
|
415 | // TODO: set the categories to axis | |
|
416 | // m_series->setCategories(categories); | |||
416 | } |
|
417 | } | |
417 | blockSeriesSignals(false); |
|
418 | blockSeriesSignals(false); | |
418 | } |
|
419 | } | |
419 |
|
420 | |||
420 | #include "moc_qbarmodelmapper.cpp" |
|
421 | #include "moc_qbarmodelmapper.cpp" | |
421 | #include "moc_qbarmodelmapper_p.cpp" |
|
422 | #include "moc_qbarmodelmapper_p.cpp" | |
422 |
|
423 | |||
423 | QTCOMMERCIALCHART_END_NAMESPACE |
|
424 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,591 +1,562 | |||||
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 "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "domain_p.h" |
|
25 | #include "domain_p.h" | |
26 | #include "legendmarker_p.h" |
|
26 | #include "legendmarker_p.h" | |
27 | #include "chartdataset_p.h" |
|
27 | #include "chartdataset_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartanimator_p.h" |
|
29 | #include "chartanimator_p.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | /*! |
|
33 | /*! | |
34 | \class QBarSeries |
|
34 | \class QBarSeries | |
35 | \brief part of QtCommercial chart API. |
|
35 | \brief part of QtCommercial chart API. | |
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
38 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
39 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
40 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
41 | shows the x-values. |
|
41 | shows the x-values. | |
42 |
|
42 | |||
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
43 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
44 | \image examples_barchart.png |
|
44 | \image examples_barchart.png | |
45 |
|
45 | |||
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
46 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 |
\fn void QBarSeries::clicked(QBarSet *barset, |
|
50 | \fn void QBarSeries::clicked(QBarSet *barset, int index) | |
51 |
|
51 | |||
52 |
The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset |
|
52 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
53 | contained by the series. |
|
53 | Clicked bar inside set is indexed by \a index | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
57 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
58 |
|
58 | |||
59 | The signal is emitted if mouse is hovered on top of series. |
|
59 | The signal is emitted if mouse is hovered on top of series. | |
60 | Parameter \a barset is the pointer of barset, where hover happened. |
|
60 | Parameter \a barset is the pointer of barset, where hover happened. | |
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
61 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | Constructs empty QBarSeries. |
|
65 | Constructs empty QBarSeries. | |
66 | QBarSeries is QObject which is a child of a \a parent. |
|
66 | QBarSeries is QObject which is a child of a \a parent. | |
67 | */ |
|
67 | */ | |
68 | QBarSeries::QBarSeries(QObject *parent) : |
|
68 | QBarSeries::QBarSeries(QObject *parent) : | |
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
69 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
70 | { |
|
70 | { | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | Destructs barseries and owned barsets. |
|
74 | Destructs barseries and owned barsets. | |
75 | */ |
|
75 | */ | |
76 | QBarSeries::~QBarSeries() |
|
76 | QBarSeries::~QBarSeries() | |
77 | { |
|
77 | { | |
78 | Q_D(QBarSeries); |
|
78 | Q_D(QBarSeries); | |
79 | if(d->m_dataset){ |
|
79 | if(d->m_dataset){ | |
80 | d->m_dataset->removeSeries(this); |
|
80 | d->m_dataset->removeSeries(this); | |
81 | } |
|
81 | } | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | \internal |
|
85 | \internal | |
86 | */ |
|
86 | */ | |
87 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
87 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
88 | QAbstractSeries(d,parent) |
|
88 | QAbstractSeries(d,parent) | |
89 | { |
|
89 | { | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | Returns the type of series. Derived classes override this. |
|
93 | Returns the type of series. Derived classes override this. | |
94 | */ |
|
94 | */ | |
95 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
95 | QAbstractSeries::SeriesType QBarSeries::type() const | |
96 | { |
|
96 | { | |
97 | return QAbstractSeries::SeriesTypeBar; |
|
97 | return QAbstractSeries::SeriesTypeBar; | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | Sets the \a categories, which are used to to group the data. |
|
|||
102 | */ |
|
|||
103 | void QBarSeries::setCategories(QBarCategories categories) |
|
|||
104 | { |
|
|||
105 | Q_D(QBarSeries); |
|
|||
106 | d->setCategories(categories); |
|
|||
107 | emit d->categoriesUpdated(); |
|
|||
108 | } |
|
|||
109 |
|
||||
110 | /*! |
|
|||
111 | Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents |
|
101 | Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents | |
112 | percentage of margin compared to bars |
|
102 | percentage of margin compared to bars | |
113 | */ |
|
103 | */ | |
114 | void QBarSeries::setBarMargin(qreal margin) |
|
104 | void QBarSeries::setBarMargin(qreal margin) | |
115 | { |
|
105 | { | |
116 | Q_D(QBarSeries); |
|
106 | Q_D(QBarSeries); | |
117 | d->setBarMargin(margin); |
|
107 | d->setBarMargin(margin); | |
118 | } |
|
108 | } | |
119 |
|
109 | |||
120 | /*! |
|
110 | /*! | |
121 | Returns the margin around bars |
|
111 | Returns the margin around bars | |
122 | */ |
|
112 | */ | |
123 | qreal QBarSeries::barMargin() const |
|
113 | qreal QBarSeries::barMargin() const | |
124 | { |
|
114 | { | |
125 | Q_D(const QBarSeries); |
|
115 | Q_D(const QBarSeries); | |
126 | return d->barMargin(); |
|
116 | return d->barMargin(); | |
127 | } |
|
117 | } | |
128 |
|
118 | |||
129 | /*! |
|
119 | /*! | |
130 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
120 | Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
131 | Returns true, if appending succeeded. |
|
121 | Returns true, if appending succeeded. | |
132 |
|
122 | |||
133 | */ |
|
123 | */ | |
134 | bool QBarSeries::append(QBarSet *set) |
|
124 | bool QBarSeries::append(QBarSet *set) | |
135 | { |
|
125 | { | |
136 | Q_D(QBarSeries); |
|
126 | Q_D(QBarSeries); | |
137 | return d->append(set); |
|
127 | return d->append(set); | |
138 | } |
|
128 | } | |
139 |
|
129 | |||
140 | /*! |
|
130 | /*! | |
141 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
131 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
142 | Returns true, if set was removed. |
|
132 | Returns true, if set was removed. | |
143 | */ |
|
133 | */ | |
144 | bool QBarSeries::remove(QBarSet *set) |
|
134 | bool QBarSeries::remove(QBarSet *set) | |
145 | { |
|
135 | { | |
146 | Q_D(QBarSeries); |
|
136 | Q_D(QBarSeries); | |
147 | return d->remove(set); |
|
137 | return d->remove(set); | |
148 | } |
|
138 | } | |
149 |
|
139 | |||
150 | /*! |
|
140 | /*! | |
151 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
141 | Adds a list of barsets to series. Takes ownership of \a sets. | |
152 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
142 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
153 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
143 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
154 | and function returns false. |
|
144 | and function returns false. | |
155 | */ |
|
145 | */ | |
156 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
146 | bool QBarSeries::append(QList<QBarSet* > sets) | |
157 | { |
|
147 | { | |
158 | Q_D(QBarSeries); |
|
148 | Q_D(QBarSeries); | |
159 | return d->append(sets); |
|
149 | return d->append(sets); | |
160 | } |
|
150 | } | |
161 |
|
151 | |||
162 | /*! |
|
152 | /*! | |
163 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
153 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. | |
164 | */ |
|
154 | */ | |
165 | bool QBarSeries::remove(QList<QBarSet* > sets) |
|
155 | bool QBarSeries::remove(QList<QBarSet* > sets) | |
166 | { |
|
156 | { | |
167 | Q_D(QBarSeries); |
|
157 | Q_D(QBarSeries); | |
168 | return d->remove(sets); |
|
158 | return d->remove(sets); | |
169 | } |
|
159 | } | |
170 |
|
160 | |||
171 | void QBarSeries::clear() |
|
161 | void QBarSeries::clear() | |
172 | { |
|
162 | { | |
173 | Q_D(QBarSeries); |
|
163 | Q_D(QBarSeries); | |
174 | d->m_barSets.clear(); |
|
164 | d->m_barSets.clear(); | |
175 | d->m_categories.clear(); |
|
|||
176 | } |
|
165 | } | |
177 |
|
166 | |||
178 | /*! |
|
167 | /*! | |
179 | Returns number of sets in series. |
|
168 | Returns number of sets in series. | |
180 | */ |
|
169 | */ | |
181 | int QBarSeries::barsetCount() const |
|
170 | int QBarSeries::barsetCount() const | |
182 | { |
|
171 | { | |
183 | Q_D(const QBarSeries); |
|
172 | Q_D(const QBarSeries); | |
184 | return d->m_barSets.count(); |
|
173 | return d->m_barSets.count(); | |
185 | } |
|
174 | } | |
186 |
|
175 | |||
187 | /*! |
|
176 | /*! | |
188 | Returns number of categories in series |
|
|||
189 | */ |
|
|||
190 | int QBarSeries::categoryCount() const |
|
|||
191 | { |
|
|||
192 | Q_D(const QBarSeries); |
|
|||
193 | return d->categoryCount(); |
|
|||
194 | } |
|
|||
195 |
|
||||
196 | /*! |
|
|||
197 | Returns a list of sets in series. Keeps ownership of sets. |
|
177 | Returns a list of sets in series. Keeps ownership of sets. | |
198 | */ |
|
178 | */ | |
199 | QList<QBarSet*> QBarSeries::barSets() const |
|
179 | QList<QBarSet*> QBarSeries::barSets() const | |
200 | { |
|
180 | { | |
201 | Q_D(const QBarSeries); |
|
181 | Q_D(const QBarSeries); | |
202 | return d->m_barSets; |
|
182 | return d->m_barSets; | |
203 | } |
|
183 | } | |
204 |
|
184 | |||
205 | /*! |
|
185 | /*! | |
206 | Returns the bar categories of the series. |
|
|||
207 | */ |
|
|||
208 | QBarCategories QBarSeries::categories() const |
|
|||
209 | { |
|
|||
210 | Q_D(const QBarSeries); |
|
|||
211 | return d->categories(); |
|
|||
212 | } |
|
|||
213 |
|
||||
214 | /*! |
|
|||
215 | Sets the visibility of series to \a visible |
|
186 | Sets the visibility of series to \a visible | |
216 | */ |
|
187 | */ | |
217 | void QBarSeries::setVisible(bool visible) |
|
188 | void QBarSeries::setVisible(bool visible) | |
218 | { |
|
189 | { | |
219 | Q_D(QBarSeries); |
|
190 | Q_D(QBarSeries); | |
220 | d->setVisible(visible); |
|
191 | d->setVisible(visible); | |
221 | } |
|
192 | } | |
222 |
|
193 | |||
223 | /*! |
|
194 | /*! | |
224 | Returns the visibility of series |
|
195 | Returns the visibility of series | |
225 | */ |
|
196 | */ | |
226 | bool QBarSeries::isVisible() const |
|
197 | bool QBarSeries::isVisible() const | |
227 | { |
|
198 | { | |
228 | Q_D(const QBarSeries); |
|
199 | Q_D(const QBarSeries); | |
229 | return d->isVisible(); |
|
200 | return d->isVisible(); | |
230 | } |
|
201 | } | |
231 |
|
202 | |||
232 | /*! |
|
203 | /*! | |
233 | Sets the visibility of labels in series to \a visible |
|
204 | Sets the visibility of labels in series to \a visible | |
234 | */ |
|
205 | */ | |
235 | void QBarSeries::setLabelsVisible(bool visible) |
|
206 | void QBarSeries::setLabelsVisible(bool visible) | |
236 | { |
|
207 | { | |
237 | Q_D(QBarSeries); |
|
208 | Q_D(QBarSeries); | |
238 | if (d->m_labelsVisible != visible) { |
|
209 | if (d->m_labelsVisible != visible) { | |
239 | d->m_labelsVisible = visible; |
|
210 | d->m_labelsVisible = visible; | |
240 | emit d->labelsVisibleChanged(visible); |
|
211 | emit d->labelsVisibleChanged(visible); | |
241 | } |
|
212 | } | |
242 | } |
|
213 | } | |
243 |
|
214 | |||
244 | /*! |
|
215 | /*! | |
245 | Returns the visibility of labels |
|
216 | Returns the visibility of labels | |
246 | */ |
|
217 | */ | |
247 | bool QBarSeries::isLabelsVisible() const |
|
218 | bool QBarSeries::isLabelsVisible() const | |
248 | { |
|
219 | { | |
249 | Q_D(const QBarSeries); |
|
220 | Q_D(const QBarSeries); | |
250 | return d->m_labelsVisible; |
|
221 | return d->m_labelsVisible; | |
251 | } |
|
222 | } | |
252 |
|
223 | |||
253 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
224 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
254 |
|
225 | |||
255 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
226 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
256 | QAbstractSeriesPrivate(q), |
|
227 | QAbstractSeriesPrivate(q), | |
257 | m_barMargin(0.5), // Default value is 50% of category width |
|
228 | m_barMargin(0.5), // Default value is 50% of category width | |
258 | m_labelsVisible(false), |
|
229 | m_labelsVisible(false), | |
259 | m_visible(true) |
|
230 | m_visible(true) | |
260 | { |
|
231 | { | |
261 | } |
|
232 | } | |
262 |
|
233 | |||
263 |
void QBarSeriesPrivate::setCategories(Q |
|
234 | void QBarSeriesPrivate::setCategories(QStringList categories) | |
264 | { |
|
235 | { | |
265 | m_categories = categories; |
|
236 | m_categories = categories; | |
266 | } |
|
237 | } | |
267 |
|
238 | |||
268 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
239 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |
269 | { |
|
240 | { | |
270 | m_categories.insert(index, category); |
|
241 | m_categories.insert(index, category); | |
271 | emit categoriesUpdated(); |
|
242 | emit categoriesUpdated(); | |
272 | } |
|
243 | } | |
273 |
|
244 | |||
274 | void QBarSeriesPrivate::removeCategory(int index) |
|
245 | void QBarSeriesPrivate::removeCategory(int index) | |
275 | { |
|
246 | { | |
276 | m_categories.removeAt(index); |
|
247 | m_categories.removeAt(index); | |
277 | emit categoriesUpdated(); |
|
248 | emit categoriesUpdated(); | |
278 | } |
|
249 | } | |
279 |
|
250 | |||
280 | int QBarSeriesPrivate::categoryCount() const |
|
251 | int QBarSeriesPrivate::categoryCount() const | |
281 | { |
|
252 | { | |
282 | if (m_categories.count() > 0) { |
|
253 | if (m_categories.count() > 0) { | |
283 | return m_categories.count(); |
|
254 | return m_categories.count(); | |
284 | } |
|
255 | } | |
285 |
|
256 | |||
286 | // No categories defined. return count of longest set. |
|
257 | // No categories defined. return count of longest set. | |
287 | int count = 0; |
|
258 | int count = 0; | |
288 | for (int i=0; i<m_barSets.count(); i++) { |
|
259 | for (int i=0; i<m_barSets.count(); i++) { | |
289 | if (m_barSets.at(i)->count() > count) { |
|
260 | if (m_barSets.at(i)->count() > count) { | |
290 | count = m_barSets.at(i)->count(); |
|
261 | count = m_barSets.at(i)->count(); | |
291 | } |
|
262 | } | |
292 | } |
|
263 | } | |
293 |
|
264 | |||
294 | return count; |
|
265 | return count; | |
295 | } |
|
266 | } | |
296 |
|
267 | |||
297 |
Q |
|
268 | QStringList QBarSeriesPrivate::categories() const | |
298 | { |
|
269 | { | |
299 | if (m_categories.count() > 0) { |
|
270 | if (m_categories.count() > 0) { | |
300 | return m_categories; |
|
271 | return m_categories; | |
301 | } |
|
272 | } | |
302 |
|
273 | |||
303 | // No categories defined. retun list of indices. |
|
274 | // No categories defined. retun list of indices. | |
304 |
Q |
|
275 | QStringList categories; | |
305 |
|
276 | |||
306 | int count = categoryCount(); |
|
277 | int count = categoryCount(); | |
307 | for (int i = 0; i < count; i++) { |
|
278 | for (int i = 0; i < count; i++) { | |
308 | categories.append(QString::number(i)); |
|
279 | categories.append(QString::number(i)); | |
309 | } |
|
280 | } | |
310 | return categories; |
|
281 | return categories; | |
311 | } |
|
282 | } | |
312 |
|
283 | |||
313 | void QBarSeriesPrivate::setBarMargin(qreal margin) |
|
284 | void QBarSeriesPrivate::setBarMargin(qreal margin) | |
314 | { |
|
285 | { | |
315 | if (margin > 1.0) { |
|
286 | if (margin > 1.0) { | |
316 | margin = 1.0; |
|
287 | margin = 1.0; | |
317 | } else if (margin < 0.0) { |
|
288 | } else if (margin < 0.0) { | |
318 | margin = 0.0; |
|
289 | margin = 0.0; | |
319 | } |
|
290 | } | |
320 |
|
291 | |||
321 | m_barMargin = margin; |
|
292 | m_barMargin = margin; | |
322 | emit updatedBars(); |
|
293 | emit updatedBars(); | |
323 | } |
|
294 | } | |
324 |
|
295 | |||
325 | qreal QBarSeriesPrivate::barMargin() const |
|
296 | qreal QBarSeriesPrivate::barMargin() const | |
326 | { |
|
297 | { | |
327 | return m_barMargin; |
|
298 | return m_barMargin; | |
328 | } |
|
299 | } | |
329 |
|
300 | |||
330 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
301 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
331 | { |
|
302 | { | |
332 | return m_barSets.at(index); |
|
303 | return m_barSets.at(index); | |
333 | } |
|
304 | } | |
334 |
|
305 | |||
335 | void QBarSeriesPrivate::setVisible(bool visible) |
|
306 | void QBarSeriesPrivate::setVisible(bool visible) | |
336 | { |
|
307 | { | |
337 | if (m_visible != visible) { |
|
308 | if (m_visible != visible) { | |
338 | m_visible = visible; |
|
309 | m_visible = visible; | |
339 | emit updatedBars(); |
|
310 | emit updatedBars(); | |
340 | } |
|
311 | } | |
341 | } |
|
312 | } | |
342 |
|
313 | |||
343 | bool QBarSeriesPrivate::isVisible() const |
|
314 | bool QBarSeriesPrivate::isVisible() const | |
344 | { |
|
315 | { | |
345 | return m_visible; |
|
316 | return m_visible; | |
346 | } |
|
317 | } | |
347 |
|
318 | |||
348 | QString QBarSeriesPrivate::categoryName(int category) |
|
319 | QString QBarSeriesPrivate::categoryName(int category) | |
349 | { |
|
320 | { | |
350 | if ((category >= 0) && (category < m_categories.count())) { |
|
321 | if ((category >= 0) && (category < m_categories.count())) { | |
351 | return m_categories.at(category); |
|
322 | return m_categories.at(category); | |
352 | } |
|
323 | } | |
353 |
|
324 | |||
354 | return QString::number(category); |
|
325 | return QString::number(category); | |
355 | } |
|
326 | } | |
356 |
|
327 | |||
357 | qreal QBarSeriesPrivate::min() |
|
328 | qreal QBarSeriesPrivate::min() | |
358 | { |
|
329 | { | |
359 | if (m_barSets.count() <= 0) { |
|
330 | if (m_barSets.count() <= 0) { | |
360 | return 0; |
|
331 | return 0; | |
361 | } |
|
332 | } | |
362 | qreal min = INT_MAX; |
|
333 | qreal min = INT_MAX; | |
363 |
|
334 | |||
364 | for (int i = 0; i < m_barSets.count(); i++) { |
|
335 | for (int i = 0; i < m_barSets.count(); i++) { | |
365 | int categoryCount = m_barSets.at(i)->count(); |
|
336 | int categoryCount = m_barSets.at(i)->count(); | |
366 | for (int j = 0; j < categoryCount; j++) { |
|
337 | for (int j = 0; j < categoryCount; j++) { | |
367 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
338 | qreal temp = m_barSets.at(i)->at(j).y(); | |
368 | if (temp < min) |
|
339 | if (temp < min) | |
369 | min = temp; |
|
340 | min = temp; | |
370 | } |
|
341 | } | |
371 | } |
|
342 | } | |
372 | return min; |
|
343 | return min; | |
373 | } |
|
344 | } | |
374 |
|
345 | |||
375 | qreal QBarSeriesPrivate::max() |
|
346 | qreal QBarSeriesPrivate::max() | |
376 | { |
|
347 | { | |
377 | if (m_barSets.count() <= 0) { |
|
348 | if (m_barSets.count() <= 0) { | |
378 | return 0; |
|
349 | return 0; | |
379 | } |
|
350 | } | |
380 | qreal max = INT_MIN; |
|
351 | qreal max = INT_MIN; | |
381 |
|
352 | |||
382 | for (int i = 0; i < m_barSets.count(); i++) { |
|
353 | for (int i = 0; i < m_barSets.count(); i++) { | |
383 | int categoryCount = m_barSets.at(i)->count(); |
|
354 | int categoryCount = m_barSets.at(i)->count(); | |
384 | for (int j = 0; j < categoryCount; j++) { |
|
355 | for (int j = 0; j < categoryCount; j++) { | |
385 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
356 | qreal temp = m_barSets.at(i)->at(j).y(); | |
386 | if (temp > max) |
|
357 | if (temp > max) | |
387 | max = temp; |
|
358 | max = temp; | |
388 | } |
|
359 | } | |
389 | } |
|
360 | } | |
390 |
|
361 | |||
391 | return max; |
|
362 | return max; | |
392 | } |
|
363 | } | |
393 |
|
364 | |||
394 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
365 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
395 | { |
|
366 | { | |
396 | if ((set < 0) || (set >= m_barSets.count())) { |
|
367 | if ((set < 0) || (set >= m_barSets.count())) { | |
397 | // No set, no value. |
|
368 | // No set, no value. | |
398 | return 0; |
|
369 | return 0; | |
399 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
370 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
400 | // No category, no value. |
|
371 | // No category, no value. | |
401 | return 0; |
|
372 | return 0; | |
402 | } |
|
373 | } | |
403 |
|
374 | |||
404 | return m_barSets.at(set)->at(category).y(); |
|
375 | return m_barSets.at(set)->at(category).y(); | |
405 | } |
|
376 | } | |
406 |
|
377 | |||
407 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
378 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
408 | { |
|
379 | { | |
409 | if ((set < 0) || (set >= m_barSets.count())) { |
|
380 | if ((set < 0) || (set >= m_barSets.count())) { | |
410 | // No set, no value. |
|
381 | // No set, no value. | |
411 | return 0; |
|
382 | return 0; | |
412 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
383 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
413 | // No category, no value. |
|
384 | // No category, no value. | |
414 | return 0; |
|
385 | return 0; | |
415 | } |
|
386 | } | |
416 |
|
387 | |||
417 | qreal value = m_barSets.at(set)->at(category).y(); |
|
388 | qreal value = m_barSets.at(set)->at(category).y(); | |
418 | qreal sum = categorySum(category); |
|
389 | qreal sum = categorySum(category); | |
419 | if ( qFuzzyIsNull(sum) ) { |
|
390 | if ( qFuzzyIsNull(sum) ) { | |
420 | return 0; |
|
391 | return 0; | |
421 | } |
|
392 | } | |
422 |
|
393 | |||
423 | return value / sum; |
|
394 | return value / sum; | |
424 | } |
|
395 | } | |
425 |
|
396 | |||
426 | qreal QBarSeriesPrivate::categorySum(int category) |
|
397 | qreal QBarSeriesPrivate::categorySum(int category) | |
427 | { |
|
398 | { | |
428 | qreal sum(0); |
|
399 | qreal sum(0); | |
429 | int count = m_barSets.count(); // Count sets |
|
400 | int count = m_barSets.count(); // Count sets | |
430 | for (int set = 0; set < count; set++) { |
|
401 | for (int set = 0; set < count; set++) { | |
431 | if (category < m_barSets.at(set)->count()) |
|
402 | if (category < m_barSets.at(set)->count()) | |
432 | sum += m_barSets.at(set)->at(category).y(); |
|
403 | sum += m_barSets.at(set)->at(category).y(); | |
433 | } |
|
404 | } | |
434 | return sum; |
|
405 | return sum; | |
435 | } |
|
406 | } | |
436 |
|
407 | |||
437 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
408 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
438 | { |
|
409 | { | |
439 | qreal sum(0); |
|
410 | qreal sum(0); | |
440 | int count = m_barSets.count(); // Count sets |
|
411 | int count = m_barSets.count(); // Count sets | |
441 | for (int set = 0; set < count; set++) { |
|
412 | for (int set = 0; set < count; set++) { | |
442 | if (category < m_barSets.at(set)->count()) |
|
413 | if (category < m_barSets.at(set)->count()) | |
443 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
414 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
444 | } |
|
415 | } | |
445 | return sum; |
|
416 | return sum; | |
446 | } |
|
417 | } | |
447 |
|
418 | |||
448 | qreal QBarSeriesPrivate::maxCategorySum() |
|
419 | qreal QBarSeriesPrivate::maxCategorySum() | |
449 | { |
|
420 | { | |
450 | qreal max = INT_MIN; |
|
421 | qreal max = INT_MIN; | |
451 | int count = categoryCount(); |
|
422 | int count = categoryCount(); | |
452 | for (int i = 0; i < count; i++) { |
|
423 | for (int i = 0; i < count; i++) { | |
453 | qreal sum = categorySum(i); |
|
424 | qreal sum = categorySum(i); | |
454 | if (sum > max) |
|
425 | if (sum > max) | |
455 | max = sum; |
|
426 | max = sum; | |
456 | } |
|
427 | } | |
457 | return max; |
|
428 | return max; | |
458 | } |
|
429 | } | |
459 |
|
430 | |||
460 | void QBarSeriesPrivate::barsetChanged() |
|
431 | void QBarSeriesPrivate::barsetChanged() | |
461 | { |
|
432 | { | |
462 | emit updatedBars(); |
|
433 | emit updatedBars(); | |
463 | } |
|
434 | } | |
464 |
|
435 | |||
465 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
436 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
466 | { |
|
437 | { | |
467 | qreal minX(domain.minX()); |
|
438 | qreal minX(domain.minX()); | |
468 | qreal minY(domain.minY()); |
|
439 | qreal minY(domain.minY()); | |
469 | qreal maxX(domain.maxX()); |
|
440 | qreal maxX(domain.maxX()); | |
470 | qreal maxY(domain.maxY()); |
|
441 | qreal maxY(domain.maxY()); | |
471 | int tickXCount(domain.tickXCount()); |
|
442 | int tickXCount(domain.tickXCount()); | |
472 | int tickYCount(domain.tickYCount()); |
|
443 | int tickYCount(domain.tickYCount()); | |
473 |
|
444 | |||
474 | qreal x = categoryCount(); |
|
445 | qreal x = categoryCount(); | |
475 | qreal y = max(); |
|
446 | qreal y = max(); | |
476 | minX = qMin(minX, x) - 0.5; |
|
447 | minX = qMin(minX, x) - 0.5; | |
477 | minY = qMin(minY, y); |
|
448 | minY = qMin(minY, y); | |
478 | maxX = qMax(maxX, x) - 0.5; |
|
449 | maxX = qMax(maxX, x) - 0.5; | |
479 | maxY = qMax(maxY, y); |
|
450 | maxY = qMax(maxY, y); | |
480 | tickXCount = x+1; |
|
451 | tickXCount = x+1; | |
481 |
|
452 | |||
482 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
453 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
483 | } |
|
454 | } | |
484 |
|
455 | |||
485 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
456 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
486 | { |
|
457 | { | |
487 | Q_Q(QBarSeries); |
|
458 | Q_Q(QBarSeries); | |
488 |
|
459 | |||
489 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
460 | BarChartItem* bar = new BarChartItem(q,presenter); | |
490 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
461 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
491 | presenter->animator()->addAnimation(bar); |
|
462 | presenter->animator()->addAnimation(bar); | |
492 | } |
|
463 | } | |
493 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
464 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
494 | return bar; |
|
465 | return bar; | |
495 |
|
466 | |||
496 | } |
|
467 | } | |
497 |
|
468 | |||
498 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
469 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
499 | { |
|
470 | { | |
500 | Q_Q(QBarSeries); |
|
471 | Q_Q(QBarSeries); | |
501 | QList<LegendMarker*> markers; |
|
472 | QList<LegendMarker*> markers; | |
502 | foreach(QBarSet* set, q->barSets()) { |
|
473 | foreach(QBarSet* set, q->barSets()) { | |
503 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
474 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
504 | markers << marker; |
|
475 | markers << marker; | |
505 | } |
|
476 | } | |
506 |
|
477 | |||
507 | return markers; |
|
478 | return markers; | |
508 | } |
|
479 | } | |
509 |
|
480 | |||
510 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
481 | bool QBarSeriesPrivate::append(QBarSet *set) | |
511 | { |
|
482 | { | |
512 | Q_Q(QBarSeries); |
|
483 | Q_Q(QBarSeries); | |
513 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
484 | if ((m_barSets.contains(set)) || (set == 0)) { | |
514 | // Fail if set is already in list or set is null. |
|
485 | // Fail if set is already in list or set is null. | |
515 | return false; |
|
486 | return false; | |
516 | } |
|
487 | } | |
517 | m_barSets.append(set); |
|
488 | m_barSets.append(set); | |
518 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
489 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
519 | if (m_dataset) { |
|
490 | if (m_dataset) { | |
520 | m_dataset->updateSeries(q); // this notifies legend |
|
491 | m_dataset->updateSeries(q); // this notifies legend | |
521 | } |
|
492 | } | |
522 | emit restructuredBars(); // this notifies barchartitem |
|
493 | emit restructuredBars(); // this notifies barchartitem | |
523 | return true; |
|
494 | return true; | |
524 | } |
|
495 | } | |
525 |
|
496 | |||
526 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
497 | bool QBarSeriesPrivate::remove(QBarSet *set) | |
527 | { |
|
498 | { | |
528 | Q_Q(QBarSeries); |
|
499 | Q_Q(QBarSeries); | |
529 | if (!m_barSets.contains(set)) { |
|
500 | if (!m_barSets.contains(set)) { | |
530 | // Fail if set is not in list |
|
501 | // Fail if set is not in list | |
531 | return false; |
|
502 | return false; | |
532 | } |
|
503 | } | |
533 | m_barSets.removeOne(set); |
|
504 | m_barSets.removeOne(set); | |
534 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
505 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
535 | if (m_dataset) { |
|
506 | if (m_dataset) { | |
536 | m_dataset->updateSeries(q); // this notifies legend |
|
507 | m_dataset->updateSeries(q); // this notifies legend | |
537 | } |
|
508 | } | |
538 | emit restructuredBars(); // this notifies barchartitem |
|
509 | emit restructuredBars(); // this notifies barchartitem | |
539 | return true; |
|
510 | return true; | |
540 | } |
|
511 | } | |
541 |
|
512 | |||
542 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
513 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |
543 | { |
|
514 | { | |
544 | Q_Q(QBarSeries); |
|
515 | Q_Q(QBarSeries); | |
545 | foreach (QBarSet* set, sets) { |
|
516 | foreach (QBarSet* set, sets) { | |
546 | if ((set == 0) || (m_barSets.contains(set))) { |
|
517 | if ((set == 0) || (m_barSets.contains(set))) { | |
547 | // Fail if any of the sets is null or is already appended. |
|
518 | // Fail if any of the sets is null or is already appended. | |
548 | return false; |
|
519 | return false; | |
549 | } |
|
520 | } | |
550 | if (sets.count(set) != 1) { |
|
521 | if (sets.count(set) != 1) { | |
551 | // Also fail if same set is more than once in given list. |
|
522 | // Also fail if same set is more than once in given list. | |
552 | return false; |
|
523 | return false; | |
553 | } |
|
524 | } | |
554 | } |
|
525 | } | |
555 |
|
526 | |||
556 | foreach (QBarSet* set, sets) { |
|
527 | foreach (QBarSet* set, sets) { | |
557 | m_barSets.append(set); |
|
528 | m_barSets.append(set); | |
558 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
529 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
559 | } |
|
530 | } | |
560 | if (m_dataset) { |
|
531 | if (m_dataset) { | |
561 | m_dataset->updateSeries(q); // this notifies legend |
|
532 | m_dataset->updateSeries(q); // this notifies legend | |
562 | } |
|
533 | } | |
563 | emit restructuredBars(); // this notifies barchartitem |
|
534 | emit restructuredBars(); // this notifies barchartitem | |
564 | return true; |
|
535 | return true; | |
565 | } |
|
536 | } | |
566 |
|
537 | |||
567 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
538 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
568 | { |
|
539 | { | |
569 | Q_Q(QBarSeries); |
|
540 | Q_Q(QBarSeries); | |
570 | bool setsRemoved = false; |
|
541 | bool setsRemoved = false; | |
571 | foreach (QBarSet* set, sets) { |
|
542 | foreach (QBarSet* set, sets) { | |
572 | if (m_barSets.contains(set)) { |
|
543 | if (m_barSets.contains(set)) { | |
573 | m_barSets.removeOne(set); |
|
544 | m_barSets.removeOne(set); | |
574 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); |
|
545 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged())); | |
575 | setsRemoved = true; |
|
546 | setsRemoved = true; | |
576 | } |
|
547 | } | |
577 | } |
|
548 | } | |
578 |
|
549 | |||
579 | if (setsRemoved) { |
|
550 | if (setsRemoved) { | |
580 | if (m_dataset) { |
|
551 | if (m_dataset) { | |
581 | m_dataset->updateSeries(q); // this notifies legend |
|
552 | m_dataset->updateSeries(q); // this notifies legend | |
582 | } |
|
553 | } | |
583 | emit restructuredBars(); // this notifies barchartitem |
|
554 | emit restructuredBars(); // this notifies barchartitem | |
584 | } |
|
555 | } | |
585 | return setsRemoved; |
|
556 | return setsRemoved; | |
586 | } |
|
557 | } | |
587 |
|
558 | |||
588 | #include "moc_qbarseries.cpp" |
|
559 | #include "moc_qbarseries.cpp" | |
589 | #include "moc_qbarseries_p.cpp" |
|
560 | #include "moc_qbarseries_p.cpp" | |
590 |
|
561 | |||
591 | QTCOMMERCIALCHART_END_NAMESPACE |
|
562 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,86 +1,80 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef BARSERIES_H |
|
21 | #ifndef BARSERIES_H | |
22 | #define BARSERIES_H |
|
22 | #define BARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | typedef QStringList QBarCategories; |
|
|||
30 |
|
||||
31 | class QBarSet; |
|
29 | class QBarSet; | |
32 | class BarCategory; |
|
|||
33 | class QBarSeriesPrivate; |
|
30 | class QBarSeriesPrivate; | |
34 |
|
31 | |||
35 | // Container for series |
|
32 | // Container for series | |
36 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries |
|
33 | class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries | |
37 | { |
|
34 | { | |
38 | Q_OBJECT |
|
35 | Q_OBJECT | |
39 | Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin) |
|
36 | Q_PROPERTY(qreal barMargin READ barMargin WRITE setBarMargin) | |
40 | Q_PROPERTY(int count READ barsetCount) // TODO: categoryCount to be removed |
|
37 | Q_PROPERTY(int count READ barsetCount) // TODO: categoryCount to be removed | |
41 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible) |
|
38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible) | |
42 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible) |
|
39 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible) | |
43 |
|
40 | |||
44 | public: |
|
41 | public: | |
45 | explicit QBarSeries(QObject *parent = 0); |
|
42 | explicit QBarSeries(QObject *parent = 0); | |
46 | virtual ~QBarSeries(); |
|
43 | virtual ~QBarSeries(); | |
47 |
|
44 | |||
48 | QAbstractSeries::SeriesType type() const; |
|
45 | QAbstractSeries::SeriesType type() const; | |
49 | void setCategories(QBarCategories categories); |
|
|||
50 |
|
46 | |||
51 | void setBarMargin(qreal margin); |
|
47 | void setBarMargin(qreal margin); | |
52 | qreal barMargin() const; |
|
48 | qreal barMargin() const; | |
53 |
|
49 | |||
54 | bool append(QBarSet *set); |
|
50 | bool append(QBarSet *set); | |
55 | bool remove(QBarSet *set); |
|
51 | bool remove(QBarSet *set); | |
56 | bool append(QList<QBarSet* > sets); |
|
52 | bool append(QList<QBarSet* > sets); | |
57 | bool remove(QList<QBarSet* > sets); |
|
53 | bool remove(QList<QBarSet* > sets); | |
58 | int barsetCount() const; |
|
54 | int barsetCount() const; | |
59 | int categoryCount() const; |
|
|||
60 | QList<QBarSet*> barSets() const; |
|
55 | QList<QBarSet*> barSets() const; | |
61 | QBarCategories categories() const; |
|
|||
62 | void clear(); |
|
56 | void clear(); | |
63 |
|
57 | |||
64 | void setVisible(bool visible = true); |
|
58 | void setVisible(bool visible = true); | |
65 | bool isVisible() const; |
|
59 | bool isVisible() const; | |
66 | void setLabelsVisible(bool visible = true); |
|
60 | void setLabelsVisible(bool visible = true); | |
67 | bool isLabelsVisible() const; |
|
61 | bool isLabelsVisible() const; | |
68 |
|
62 | |||
69 | protected: |
|
63 | protected: | |
70 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); |
|
64 | explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0); | |
71 |
|
65 | |||
72 | Q_SIGNALS: |
|
66 | Q_SIGNALS: | |
73 |
void clicked(QBarSet *barset, |
|
67 | void clicked(QBarSet *barset, int index); | |
74 | void hovered(QBarSet* barset, bool status); |
|
68 | void hovered(QBarSet* barset, bool status); | |
75 |
|
69 | |||
76 | protected: |
|
70 | protected: | |
77 | Q_DECLARE_PRIVATE(QBarSeries) |
|
71 | Q_DECLARE_PRIVATE(QBarSeries) | |
78 | friend class BarChartItem; |
|
72 | friend class BarChartItem; | |
79 | friend class PercentBarChartItem; |
|
73 | friend class PercentBarChartItem; | |
80 | friend class StackedBarChartItem; |
|
74 | friend class StackedBarChartItem; | |
81 | friend class GroupedBarChartItem; |
|
75 | friend class GroupedBarChartItem; | |
82 | }; |
|
76 | }; | |
83 |
|
77 | |||
84 | QTCOMMERCIALCHART_END_NAMESPACE |
|
78 | QTCOMMERCIALCHART_END_NAMESPACE | |
85 |
|
79 | |||
86 | #endif // BARSERIES_H |
|
80 | #endif // BARSERIES_H |
@@ -1,101 +1,102 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBARSERIES_P_H |
|
30 | #ifndef QBARSERIES_P_H | |
31 | #define QBARSERIES_P_H |
|
31 | #define QBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries.h" |
|
33 | #include "qbarseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 | #include <QStringList> |
|
35 | #include <QStringList> | |
36 | #include <QAbstractSeries> |
|
36 | #include <QAbstractSeries> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QBarModelMapper; |
|
40 | class QBarModelMapper; | |
41 |
|
41 | |||
42 | class QBarSeriesPrivate : public QAbstractSeriesPrivate |
|
42 | class QBarSeriesPrivate : public QAbstractSeriesPrivate | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | QBarSeriesPrivate(QBarSeries *parent); |
|
46 | QBarSeriesPrivate(QBarSeries *parent); | |
47 | void setCategories(QBarCategories categories); |
|
47 | // TODO: refactor/remove private category stuff | |
|
48 | void setCategories(QStringList categories); | |||
48 | void insertCategory(int index, const QString category); |
|
49 | void insertCategory(int index, const QString category); | |
49 | void removeCategory(int index); |
|
50 | void removeCategory(int index); | |
50 | int categoryCount() const; |
|
51 | int categoryCount() const; | |
51 |
Q |
|
52 | QStringList categories() const; | |
52 |
|
53 | |||
53 | void setBarMargin(qreal margin); |
|
54 | void setBarMargin(qreal margin); | |
54 | qreal barMargin() const; |
|
55 | qreal barMargin() const; | |
55 |
|
56 | |||
56 | void setVisible(bool visible); |
|
57 | void setVisible(bool visible); | |
57 | bool isVisible() const; |
|
58 | bool isVisible() const; | |
58 |
|
59 | |||
59 | void scaleDomain(Domain& domain); |
|
60 | void scaleDomain(Domain& domain); | |
60 | Chart* createGraphics(ChartPresenter* presenter); |
|
61 | Chart* createGraphics(ChartPresenter* presenter); | |
61 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
62 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
62 |
|
63 | |||
63 | bool append(QBarSet *set); |
|
64 | bool append(QBarSet *set); | |
64 | bool remove(QBarSet *set); |
|
65 | bool remove(QBarSet *set); | |
65 | bool append(QList<QBarSet* > sets); |
|
66 | bool append(QList<QBarSet* > sets); | |
66 | bool remove(QList<QBarSet* > sets); |
|
67 | bool remove(QList<QBarSet* > sets); | |
67 |
|
68 | |||
68 | QBarSet* barsetAt(int index); |
|
69 | QBarSet* barsetAt(int index); | |
69 | QString categoryName(int category); |
|
70 | QString categoryName(int category); | |
70 | qreal min(); |
|
71 | qreal min(); | |
71 | qreal max(); |
|
72 | qreal max(); | |
72 | qreal valueAt(int set, int category); |
|
73 | qreal valueAt(int set, int category); | |
73 | qreal percentageAt(int set, int category); |
|
74 | qreal percentageAt(int set, int category); | |
74 | qreal categorySum(int category); |
|
75 | qreal categorySum(int category); | |
75 | qreal absoluteCategorySum(int category); |
|
76 | qreal absoluteCategorySum(int category); | |
76 | qreal maxCategorySum(); |
|
77 | qreal maxCategorySum(); | |
77 |
|
78 | |||
78 | Q_SIGNALS: |
|
79 | Q_SIGNALS: | |
79 |
void clicked(QBarSet *barset, |
|
80 | void clicked(QBarSet *barset, int index); | |
80 | void updatedBars(); |
|
81 | void updatedBars(); | |
81 | void restructuredBars(); |
|
82 | void restructuredBars(); | |
82 | void categoriesUpdated(); |
|
83 | void categoriesUpdated(); | |
83 | void labelsVisibleChanged(bool visible); |
|
84 | void labelsVisibleChanged(bool visible); | |
84 |
|
85 | |||
85 | private Q_SLOTS: |
|
86 | private Q_SLOTS: | |
86 | void barsetChanged(); |
|
87 | void barsetChanged(); | |
87 |
|
88 | |||
88 | protected: |
|
89 | protected: | |
89 | QList<QBarSet *> m_barSets; |
|
90 | QList<QBarSet *> m_barSets; | |
90 |
Q |
|
91 | QStringList m_categories; | |
91 | qreal m_barMargin; |
|
92 | qreal m_barMargin; | |
92 | bool m_labelsVisible; |
|
93 | bool m_labelsVisible; | |
93 | bool m_visible; |
|
94 | bool m_visible; | |
94 |
|
95 | |||
95 | private: |
|
96 | private: | |
96 | Q_DECLARE_PUBLIC(QBarSeries) |
|
97 | Q_DECLARE_PUBLIC(QBarSeries) | |
97 | }; |
|
98 | }; | |
98 |
|
99 | |||
99 | QTCOMMERCIALCHART_END_NAMESPACE |
|
100 | QTCOMMERCIALCHART_END_NAMESPACE | |
100 |
|
101 | |||
101 | #endif // QBARSERIESPRIVATE_P_H |
|
102 | #endif // QBARSERIESPRIVATE_P_H |
@@ -1,323 +1,309 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief part of QtCommercial chart API. |
|
28 | \brief part of QtCommercial chart API. | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 |
|
39 | |||
40 | /*! |
|
40 | /*! | |
41 | \fn void QBarSet::clicked(QString category) |
|
|||
42 | \brief signals that set has been clicked |
|
|||
43 | Parameter \a category describes on which category was clicked |
|
|||
44 | */ |
|
|||
45 |
|
||||
46 | /*! |
|
|||
47 | \fn void QBarSet::hovered(bool status) |
|
|||
48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. |
|
|||
49 |
|
||||
50 | The signal is emitted if mouse is hovered on top of set |
|
|||
51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
|||
52 | */ |
|
|||
53 |
|
||||
54 | /*! |
|
|||
55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
41 | Constructs QBarSet with a name of \a name and with parent of \a parent | |
56 | */ |
|
42 | */ | |
57 | QBarSet::QBarSet(const QString name, QObject *parent) |
|
43 | QBarSet::QBarSet(const QString name, QObject *parent) | |
58 | : QObject(parent) |
|
44 | : QObject(parent) | |
59 | ,d_ptr(new QBarSetPrivate(name,this)) |
|
45 | ,d_ptr(new QBarSetPrivate(name,this)) | |
60 | { |
|
46 | { | |
61 | } |
|
47 | } | |
62 |
|
48 | |||
63 | /*! |
|
49 | /*! | |
64 | Destroys the barset |
|
50 | Destroys the barset | |
65 | */ |
|
51 | */ | |
66 | QBarSet::~QBarSet() |
|
52 | QBarSet::~QBarSet() | |
67 | { |
|
53 | { | |
68 | // NOTE: d_ptr destroyed by QObject |
|
54 | // NOTE: d_ptr destroyed by QObject | |
69 | } |
|
55 | } | |
70 |
|
56 | |||
71 | /*! |
|
57 | /*! | |
72 | Sets new \a name for set. |
|
58 | Sets new \a name for set. | |
73 | */ |
|
59 | */ | |
74 | void QBarSet::setName(const QString name) |
|
60 | void QBarSet::setName(const QString name) | |
75 | { |
|
61 | { | |
76 | d_ptr->m_name = name; |
|
62 | d_ptr->m_name = name; | |
77 | } |
|
63 | } | |
78 |
|
64 | |||
79 | /*! |
|
65 | /*! | |
80 | Returns name of the set. |
|
66 | Returns name of the set. | |
81 | */ |
|
67 | */ | |
82 | QString QBarSet::name() const |
|
68 | QString QBarSet::name() const | |
83 | { |
|
69 | { | |
84 | return d_ptr->m_name; |
|
70 | return d_ptr->m_name; | |
85 | } |
|
71 | } | |
86 |
|
72 | |||
87 | /*! |
|
73 | /*! | |
88 | Appends a point to set. Parameter \a value x coordinate defines the |
|
74 | Appends a point to set. Parameter \a value x coordinate defines the | |
89 | position in x-axis and y coordinate defines the height of bar. |
|
75 | position in x-axis and y coordinate defines the height of bar. | |
90 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) |
|
76 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) | |
91 | the x values are used or ignored. |
|
77 | the x values are used or ignored. | |
92 | */ |
|
78 | */ | |
93 | void QBarSet::append(const QPointF value) |
|
79 | void QBarSet::append(const QPointF value) | |
94 | { |
|
80 | { | |
95 | d_ptr->m_values.append(value); |
|
81 | d_ptr->m_values.append(value); | |
96 | emit d_ptr->restructuredBars(); |
|
82 | emit d_ptr->restructuredBars(); | |
97 | } |
|
83 | } | |
98 |
|
84 | |||
99 | /*! |
|
85 | /*! | |
100 | Appends a list of \a values to set. Works like append with single point. |
|
86 | Appends a list of \a values to set. Works like append with single point. | |
101 | \sa append() |
|
87 | \sa append() | |
102 | */ |
|
88 | */ | |
103 | void QBarSet::append(const QList<QPointF> values) |
|
89 | void QBarSet::append(const QList<QPointF> values) | |
104 | { |
|
90 | { | |
105 | for (int i=0; i<values.count(); i++) { |
|
91 | for (int i=0; i<values.count(); i++) { | |
106 | d_ptr->m_values.append(values.at(i)); |
|
92 | d_ptr->m_values.append(values.at(i)); | |
107 | } |
|
93 | } | |
108 | emit d_ptr->restructuredBars(); |
|
94 | emit d_ptr->restructuredBars(); | |
109 | } |
|
95 | } | |
110 |
|
96 | |||
111 | /*! |
|
97 | /*! | |
112 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, |
|
98 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, | |
113 | with x coordinate being the index of appended value and y coordinate is the value. |
|
99 | with x coordinate being the index of appended value and y coordinate is the value. | |
114 | */ |
|
100 | */ | |
115 | void QBarSet::append(const qreal value) |
|
101 | void QBarSet::append(const qreal value) | |
116 | { |
|
102 | { | |
117 | append(QPointF(d_ptr->m_values.count(), value)); |
|
103 | append(QPointF(d_ptr->m_values.count(), value)); | |
118 | } |
|
104 | } | |
119 |
|
105 | |||
120 | /*! |
|
106 | /*! | |
121 | Appends a list of reals to set. Works like append with single real value. The values in list |
|
107 | Appends a list of reals to set. Works like append with single real value. The values in list | |
122 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. |
|
108 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. | |
123 | \sa append() |
|
109 | \sa append() | |
124 | */ |
|
110 | */ | |
125 | void QBarSet::append(const QList<qreal> values) |
|
111 | void QBarSet::append(const QList<qreal> values) | |
126 | { |
|
112 | { | |
127 | int index = d_ptr->m_values.count(); |
|
113 | int index = d_ptr->m_values.count(); | |
128 | for (int i=0; i<values.count(); i++) { |
|
114 | for (int i=0; i<values.count(); i++) { | |
129 | d_ptr->m_values.append(QPointF(index,values.at(i))); |
|
115 | d_ptr->m_values.append(QPointF(index,values.at(i))); | |
130 | index++; |
|
116 | index++; | |
131 | } |
|
117 | } | |
132 | emit d_ptr->restructuredBars(); |
|
118 | emit d_ptr->restructuredBars(); | |
133 | } |
|
119 | } | |
134 |
|
120 | |||
135 | /*! |
|
121 | /*! | |
136 | Convinience operator. Same as append, with real \a value. |
|
122 | Convinience operator. Same as append, with real \a value. | |
137 | \sa append() |
|
123 | \sa append() | |
138 | */ |
|
124 | */ | |
139 | QBarSet& QBarSet::operator << (const qreal &value) |
|
125 | QBarSet& QBarSet::operator << (const qreal &value) | |
140 | { |
|
126 | { | |
141 | append(value); |
|
127 | append(value); | |
142 | return *this; |
|
128 | return *this; | |
143 | } |
|
129 | } | |
144 |
|
130 | |||
145 | /*! |
|
131 | /*! | |
146 | Convinience operator. Same as append, with QPointF \a value. |
|
132 | Convinience operator. Same as append, with QPointF \a value. | |
147 | \sa append() |
|
133 | \sa append() | |
148 | */ |
|
134 | */ | |
149 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
135 | QBarSet& QBarSet::operator << (const QPointF &value) | |
150 | { |
|
136 | { | |
151 | append(value); |
|
137 | append(value); | |
152 | return *this; |
|
138 | return *this; | |
153 | } |
|
139 | } | |
154 |
|
140 | |||
155 | /*! |
|
141 | /*! | |
156 | Inserts new \a value on the \a index position. |
|
142 | Inserts new \a value on the \a index position. | |
157 | The value that is currently at this postion is moved to postion index + 1 |
|
143 | The value that is currently at this postion is moved to postion index + 1 | |
158 | \sa remove() |
|
144 | \sa remove() | |
159 | */ |
|
145 | */ | |
160 | void QBarSet::insert(const int index, const qreal value) |
|
146 | void QBarSet::insert(const int index, const qreal value) | |
161 | { |
|
147 | { | |
162 | d_ptr->m_values.insert(index, QPointF(index, value)); |
|
148 | d_ptr->m_values.insert(index, QPointF(index, value)); | |
163 | // emit d_ptr->updatedBars(); |
|
149 | // emit d_ptr->updatedBars(); | |
164 | } |
|
150 | } | |
165 |
|
151 | |||
166 | /*! |
|
152 | /*! | |
167 | Removes the value specified by \a index |
|
153 | Removes the value specified by \a index | |
168 | \sa insert() |
|
154 | \sa insert() | |
169 | */ |
|
155 | */ | |
170 | void QBarSet::remove(const int index) |
|
156 | void QBarSet::remove(const int index) | |
171 | { |
|
157 | { | |
172 | d_ptr->m_values.removeAt(index); |
|
158 | d_ptr->m_values.removeAt(index); | |
173 | // emit d_ptr->updatedBars(); |
|
159 | // emit d_ptr->updatedBars(); | |
174 | } |
|
160 | } | |
175 |
|
161 | |||
176 | /*! |
|
162 | /*! | |
177 | Sets a new value \a value to set, indexed by \a index |
|
163 | Sets a new value \a value to set, indexed by \a index | |
178 | */ |
|
164 | */ | |
179 | void QBarSet::replace(const int index, const qreal value) |
|
165 | void QBarSet::replace(const int index, const qreal value) | |
180 | { |
|
166 | { | |
181 | d_ptr->m_values.replace(index,QPointF(index,value)); |
|
167 | d_ptr->m_values.replace(index,QPointF(index,value)); | |
182 | emit d_ptr->updatedBars(); |
|
168 | emit d_ptr->updatedBars(); | |
183 | } |
|
169 | } | |
184 |
|
170 | |||
185 | /*! |
|
171 | /*! | |
186 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. |
|
172 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. | |
187 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
173 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
188 | of the QPointF (if appended with QPointF append). |
|
174 | of the QPointF (if appended with QPointF append). | |
189 | If the index is out of bounds QPointF(0, 0.0) is returned. |
|
175 | If the index is out of bounds QPointF(0, 0.0) is returned. | |
190 | */ |
|
176 | */ | |
191 | QPointF QBarSet::at(const int index) const |
|
177 | QPointF QBarSet::at(const int index) const | |
192 | { |
|
178 | { | |
193 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
179 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
194 | return QPointF(index, 0.0); |
|
180 | return QPointF(index, 0.0); | |
195 | } |
|
181 | } | |
196 |
|
182 | |||
197 | return d_ptr->m_values.at(index); |
|
183 | return d_ptr->m_values.at(index); | |
198 | } |
|
184 | } | |
199 |
|
185 | |||
200 | /*! |
|
186 | /*! | |
201 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. |
|
187 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. | |
202 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
188 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value | |
203 | of the QPointF (if appended with QPointF append). |
|
189 | of the QPointF (if appended with QPointF append). | |
204 | */ |
|
190 | */ | |
205 | QPointF QBarSet::operator [](const int index) const |
|
191 | QPointF QBarSet::operator [](const int index) const | |
206 | { |
|
192 | { | |
207 | return d_ptr->m_values.at(index); |
|
193 | return d_ptr->m_values.at(index); | |
208 | } |
|
194 | } | |
209 |
|
195 | |||
210 | /*! |
|
196 | /*! | |
211 | Returns count of values in set. |
|
197 | Returns count of values in set. | |
212 | */ |
|
198 | */ | |
213 | int QBarSet::count() const |
|
199 | int QBarSet::count() const | |
214 | { |
|
200 | { | |
215 | return d_ptr->m_values.count(); |
|
201 | return d_ptr->m_values.count(); | |
216 | } |
|
202 | } | |
217 |
|
203 | |||
218 | /*! |
|
204 | /*! | |
219 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. |
|
205 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. | |
220 | */ |
|
206 | */ | |
221 | qreal QBarSet::sum() const |
|
207 | qreal QBarSet::sum() const | |
222 | { |
|
208 | { | |
223 | qreal total(0); |
|
209 | qreal total(0); | |
224 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
210 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
225 | //total += d_ptr->m_values.at(i); |
|
211 | //total += d_ptr->m_values.at(i); | |
226 | total += d_ptr->m_values.at(i).y(); |
|
212 | total += d_ptr->m_values.at(i).y(); | |
227 | } |
|
213 | } | |
228 | return total; |
|
214 | return total; | |
229 | } |
|
215 | } | |
230 |
|
216 | |||
231 | /*! |
|
217 | /*! | |
232 | Sets pen for set. Bars of this set are drawn using \a pen |
|
218 | Sets pen for set. Bars of this set are drawn using \a pen | |
233 | */ |
|
219 | */ | |
234 | void QBarSet::setPen(const QPen &pen) |
|
220 | void QBarSet::setPen(const QPen &pen) | |
235 | { |
|
221 | { | |
236 | if(d_ptr->m_pen!=pen){ |
|
222 | if(d_ptr->m_pen!=pen){ | |
237 | d_ptr->m_pen = pen; |
|
223 | d_ptr->m_pen = pen; | |
238 | emit d_ptr->updatedBars(); |
|
224 | emit d_ptr->updatedBars(); | |
239 | } |
|
225 | } | |
240 | } |
|
226 | } | |
241 |
|
227 | |||
242 | /*! |
|
228 | /*! | |
243 | Returns pen of the set. |
|
229 | Returns pen of the set. | |
244 | */ |
|
230 | */ | |
245 | QPen QBarSet::pen() const |
|
231 | QPen QBarSet::pen() const | |
246 | { |
|
232 | { | |
247 | return d_ptr->m_pen; |
|
233 | return d_ptr->m_pen; | |
248 | } |
|
234 | } | |
249 |
|
235 | |||
250 | /*! |
|
236 | /*! | |
251 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
237 | Sets brush for the set. Bars of this set are drawn using \a brush | |
252 | */ |
|
238 | */ | |
253 | void QBarSet::setBrush(const QBrush &brush) |
|
239 | void QBarSet::setBrush(const QBrush &brush) | |
254 | { |
|
240 | { | |
255 | if(d_ptr->m_brush!=brush){ |
|
241 | if(d_ptr->m_brush!=brush){ | |
256 | d_ptr->m_brush = brush; |
|
242 | d_ptr->m_brush = brush; | |
257 | emit d_ptr->updatedBars(); |
|
243 | emit d_ptr->updatedBars(); | |
258 | } |
|
244 | } | |
259 | } |
|
245 | } | |
260 |
|
246 | |||
261 | /*! |
|
247 | /*! | |
262 | Returns brush of the set. |
|
248 | Returns brush of the set. | |
263 | */ |
|
249 | */ | |
264 | QBrush QBarSet::brush() const |
|
250 | QBrush QBarSet::brush() const | |
265 | { |
|
251 | { | |
266 | return d_ptr->m_brush; |
|
252 | return d_ptr->m_brush; | |
267 | } |
|
253 | } | |
268 |
|
254 | |||
269 | /*! |
|
255 | /*! | |
270 | Sets \a brush of the values that are drawn on top of this barset |
|
256 | Sets \a brush of the values that are drawn on top of this barset | |
271 | */ |
|
257 | */ | |
272 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
258 | void QBarSet::setLabelBrush(const QBrush &brush) | |
273 | { |
|
259 | { | |
274 | if(d_ptr->m_labelBrush!=brush){ |
|
260 | if(d_ptr->m_labelBrush!=brush){ | |
275 | d_ptr->m_labelBrush = brush; |
|
261 | d_ptr->m_labelBrush = brush; | |
276 | emit d_ptr->updatedBars(); |
|
262 | emit d_ptr->updatedBars(); | |
277 | } |
|
263 | } | |
278 | } |
|
264 | } | |
279 |
|
265 | |||
280 | /*! |
|
266 | /*! | |
281 | Returns brush of the values that are drawn on top of this barset |
|
267 | Returns brush of the values that are drawn on top of this barset | |
282 | */ |
|
268 | */ | |
283 | QBrush QBarSet::labelBrush() const |
|
269 | QBrush QBarSet::labelBrush() const | |
284 | { |
|
270 | { | |
285 | return d_ptr->m_labelBrush; |
|
271 | return d_ptr->m_labelBrush; | |
286 | } |
|
272 | } | |
287 |
|
273 | |||
288 | /*! |
|
274 | /*! | |
289 | Sets the \a font for values that are drawn on top of this barset |
|
275 | Sets the \a font for values that are drawn on top of this barset | |
290 | */ |
|
276 | */ | |
291 | void QBarSet::setLabelFont(const QFont &font) |
|
277 | void QBarSet::setLabelFont(const QFont &font) | |
292 | { |
|
278 | { | |
293 | if(d_ptr->m_labelFont!=font) { |
|
279 | if(d_ptr->m_labelFont!=font) { | |
294 | d_ptr->m_labelFont = font; |
|
280 | d_ptr->m_labelFont = font; | |
295 | emit d_ptr->updatedBars(); |
|
281 | emit d_ptr->updatedBars(); | |
296 | } |
|
282 | } | |
297 |
|
283 | |||
298 | } |
|
284 | } | |
299 |
|
285 | |||
300 | /*! |
|
286 | /*! | |
301 | Returns the pen for values that are drawn on top of this set |
|
287 | Returns the pen for values that are drawn on top of this set | |
302 | */ |
|
288 | */ | |
303 | QFont QBarSet::labelFont() const |
|
289 | QFont QBarSet::labelFont() const | |
304 | { |
|
290 | { | |
305 | return d_ptr->m_labelFont; |
|
291 | return d_ptr->m_labelFont; | |
306 | } |
|
292 | } | |
307 |
|
293 | |||
308 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
294 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
309 |
|
295 | |||
310 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), |
|
296 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), | |
311 | q_ptr(parent), |
|
297 | q_ptr(parent), | |
312 | m_name(name) |
|
298 | m_name(name) | |
313 | { |
|
299 | { | |
314 | } |
|
300 | } | |
315 |
|
301 | |||
316 | QBarSetPrivate::~QBarSetPrivate() |
|
302 | QBarSetPrivate::~QBarSetPrivate() | |
317 | { |
|
303 | { | |
318 | } |
|
304 | } | |
319 |
|
305 | |||
320 | #include "moc_qbarset.cpp" |
|
306 | #include "moc_qbarset.cpp" | |
321 | #include "moc_qbarset_p.cpp" |
|
307 | #include "moc_qbarset_p.cpp" | |
322 |
|
308 | |||
323 | QTCOMMERCIALCHART_END_NAMESPACE |
|
309 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,91 +1,87 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef QBARSET_H |
|
21 | #ifndef QBARSET_H | |
22 | #define QBARSET_H |
|
22 | #define QBARSET_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QBrush> |
|
26 | #include <QBrush> | |
27 | #include <QFont> |
|
27 | #include <QFont> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | class QBarSetPrivate; |
|
30 | class QBarSetPrivate; | |
31 |
|
31 | |||
32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 | Q_PROPERTY(QString name READ name WRITE setName) |
|
35 | Q_PROPERTY(QString name READ name WRITE setName) | |
36 | Q_PROPERTY(QPen pen READ pen WRITE setPen) |
|
36 | Q_PROPERTY(QPen pen READ pen WRITE setPen) | |
37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush) |
|
37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush) | |
38 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush) |
|
38 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush) | |
39 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) |
|
39 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont) | |
40 |
|
40 | |||
41 | public: |
|
41 | public: | |
42 | explicit QBarSet(const QString name, QObject *parent = 0); |
|
42 | explicit QBarSet(const QString name, QObject *parent = 0); | |
43 | virtual ~QBarSet(); |
|
43 | virtual ~QBarSet(); | |
44 |
|
44 | |||
45 | void setName(const QString name); |
|
45 | void setName(const QString name); | |
46 | QString name() const; |
|
46 | QString name() const; | |
47 |
|
47 | |||
48 | void append(const QPointF value); |
|
48 | void append(const QPointF value); | |
49 | void append(const QList<QPointF> values); |
|
49 | void append(const QList<QPointF> values); | |
50 | void append(const qreal value); |
|
50 | void append(const qreal value); | |
51 | void append(const QList<qreal> values); |
|
51 | void append(const QList<qreal> values); | |
52 |
|
52 | |||
53 | QBarSet& operator << (const qreal &value); |
|
53 | QBarSet& operator << (const qreal &value); | |
54 | QBarSet& operator << (const QPointF &value); |
|
54 | QBarSet& operator << (const QPointF &value); | |
55 |
|
55 | |||
56 | void insert(const int index, const qreal value); |
|
56 | void insert(const int index, const qreal value); | |
57 | void remove(const int index); |
|
57 | void remove(const int index); | |
58 | void replace(const int index, const qreal value); |
|
58 | void replace(const int index, const qreal value); | |
59 | QPointF at(const int index) const; |
|
59 | QPointF at(const int index) const; | |
60 | QPointF operator [] (const int index) const; |
|
60 | QPointF operator [] (const int index) const; | |
61 | int count() const; |
|
61 | int count() const; | |
62 | qreal sum() const; |
|
62 | qreal sum() const; | |
63 |
|
63 | |||
64 | void setPen(const QPen &pen); |
|
64 | void setPen(const QPen &pen); | |
65 | QPen pen() const; |
|
65 | QPen pen() const; | |
66 |
|
66 | |||
67 | void setBrush(const QBrush &brush); |
|
67 | void setBrush(const QBrush &brush); | |
68 | QBrush brush() const; |
|
68 | QBrush brush() const; | |
69 |
|
69 | |||
70 | void setLabelBrush(const QBrush &brush); |
|
70 | void setLabelBrush(const QBrush &brush); | |
71 | QBrush labelBrush() const; |
|
71 | QBrush labelBrush() const; | |
72 |
|
72 | |||
73 | void setLabelFont(const QFont &font); |
|
73 | void setLabelFont(const QFont &font); | |
74 | QFont labelFont() const; |
|
74 | QFont labelFont() const; | |
75 |
|
75 | |||
76 | //Q_SIGNALS: |
|
|||
77 | // void clicked(QString category); |
|
|||
78 | // void hovered(bool status); |
|
|||
79 |
|
||||
80 | private: |
|
76 | private: | |
81 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
77 | QScopedPointer<QBarSetPrivate> d_ptr; | |
82 | Q_DISABLE_COPY(QBarSet) |
|
78 | Q_DISABLE_COPY(QBarSet) | |
83 | friend class QBarSeries; |
|
79 | friend class QBarSeries; | |
84 | friend class BarLegendMarker; |
|
80 | friend class BarLegendMarker; | |
85 | friend class BarChartItem; |
|
81 | friend class BarChartItem; | |
86 | friend class QBarSeriesPrivate; |
|
82 | friend class QBarSeriesPrivate; | |
87 | }; |
|
83 | }; | |
88 |
|
84 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
85 | QTCOMMERCIALCHART_END_NAMESPACE | |
90 |
|
86 | |||
91 | #endif // QBARSET_H |
|
87 | #endif // QBARSET_H |
@@ -1,68 +1,67 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QBARSET_P_H |
|
30 | #ifndef QBARSET_P_H | |
31 | #define QBARSET_P_H |
|
31 | #define QBARSET_P_H | |
32 |
|
32 | |||
33 | #include "qbarset.h" |
|
33 | #include "qbarset.h" | |
34 | #include <QMap> |
|
34 | #include <QMap> | |
35 | #include <QPen> |
|
35 | #include <QPen> | |
36 | #include <QBrush> |
|
36 | #include <QBrush> | |
37 | #include <QFont> |
|
37 | #include <QFont> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class QBarSetPrivate : public QObject |
|
41 | class QBarSetPrivate : public QObject | |
42 | { |
|
42 | { | |
43 | Q_OBJECT |
|
43 | Q_OBJECT | |
44 |
|
44 | |||
45 | public: |
|
45 | public: | |
46 | QBarSetPrivate(const QString name, QBarSet *parent); |
|
46 | QBarSetPrivate(const QString name, QBarSet *parent); | |
47 | ~QBarSetPrivate(); |
|
47 | ~QBarSetPrivate(); | |
48 |
|
48 | |||
49 | Q_SIGNALS: |
|
49 | Q_SIGNALS: | |
50 | void clicked(QString category); |
|
|||
51 | void restructuredBars(); |
|
50 | void restructuredBars(); | |
52 | void updatedBars(); |
|
51 | void updatedBars(); | |
53 |
|
52 | |||
54 | public: |
|
53 | public: | |
55 | QBarSet * const q_ptr; |
|
54 | QBarSet * const q_ptr; | |
56 | QString m_name; |
|
55 | QString m_name; | |
57 | QList<QPointF> m_values; |
|
56 | QList<QPointF> m_values; | |
58 | QPen m_pen; |
|
57 | QPen m_pen; | |
59 | QBrush m_brush; |
|
58 | QBrush m_brush; | |
60 | QBrush m_labelBrush; |
|
59 | QBrush m_labelBrush; | |
61 | QFont m_labelFont; |
|
60 | QFont m_labelFont; | |
62 |
|
61 | |||
63 | friend class QBarSet; |
|
62 | friend class QBarSet; | |
64 | }; |
|
63 | }; | |
65 |
|
64 | |||
66 | QTCOMMERCIALCHART_END_NAMESPACE |
|
65 | QTCOMMERCIALCHART_END_NAMESPACE | |
67 |
|
66 | |||
68 | #endif // QBARSETPRIVATE_P_H |
|
67 | #endif // QBARSETPRIVATE_P_H |
@@ -1,109 +1,108 | |||||
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 "qgroupedbarseries.h" |
|
21 | #include "qgroupedbarseries.h" | |
22 | #include "qgroupedbarseries_p.h" |
|
22 | #include "qgroupedbarseries_p.h" | |
23 | #include "groupedbarchartitem_p.h" |
|
23 | #include "groupedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QGroupedBarSeries |
|
31 | \class QGroupedBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
35 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data |
|
36 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data | |
37 | from sets to categories, which are defined by a QStringList. |
|
37 | from sets to categories, which are defined by a QStringList. | |
38 |
|
38 | |||
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
39 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |
40 | \image examples_groupedbarchart.png |
|
40 | \image examples_groupedbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries |
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn virtual QSeriesType QGroupedBarSeries::type() const |
|
46 | \fn virtual QSeriesType QGroupedBarSeries::type() const | |
47 | \brief Returns type of series. |
|
47 | \brief Returns type of series. | |
48 | \sa QAbstractSeries, QSeriesType |
|
48 | \sa QAbstractSeries, QSeriesType | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | Constructs empty QGroupedBarSeries. |
|
52 | Constructs empty QGroupedBarSeries. | |
53 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
53 | QGroupedBarSeries is QObject which is a child of a \a parent. | |
54 | */ |
|
54 | */ | |
55 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
55 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) | |
56 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
56 | : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent) | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
60 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const | |
61 | { |
|
61 | { | |
62 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
62 | return QAbstractSeries::SeriesTypeGroupedBar; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
66 |
|
66 | |||
67 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q) |
|
67 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q) | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
72 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) | |
73 | { |
|
73 | { | |
74 | Q_Q(QGroupedBarSeries); |
|
|||
75 | qreal minX(domain.minX()); |
|
74 | qreal minX(domain.minX()); | |
76 | qreal minY(domain.minY()); |
|
75 | qreal minY(domain.minY()); | |
77 | qreal maxX(domain.maxX()); |
|
76 | qreal maxX(domain.maxX()); | |
78 | qreal maxY(domain.maxY()); |
|
77 | qreal maxY(domain.maxY()); | |
79 | int tickXCount(domain.tickXCount()); |
|
78 | int tickXCount(domain.tickXCount()); | |
80 | int tickYCount(domain.tickYCount()); |
|
79 | int tickYCount(domain.tickYCount()); | |
81 |
|
80 | |||
82 |
qreal x = |
|
81 | qreal x = categoryCount(); | |
83 | qreal y = max(); |
|
82 | qreal y = max(); | |
84 | minX = qMin(minX, x) - 0.5; |
|
83 | minX = qMin(minX, x) - 0.5; | |
85 | minY = qMin(minY, y); |
|
84 | minY = qMin(minY, y); | |
86 | maxX = qMax(maxX, x) - 0.5; |
|
85 | maxX = qMax(maxX, x) - 0.5; | |
87 | maxY = qMax(maxY, y); |
|
86 | maxY = qMax(maxY, y); | |
88 | tickXCount = x+1; |
|
87 | tickXCount = x+1; | |
89 |
|
88 | |||
90 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
91 | } |
|
90 | } | |
92 |
|
91 | |||
93 |
|
92 | |||
94 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
93 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
95 | { |
|
94 | { | |
96 | Q_Q(QGroupedBarSeries); |
|
95 | Q_Q(QGroupedBarSeries); | |
97 |
|
96 | |||
98 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
97 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |
99 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
100 | presenter->animator()->addAnimation(bar); |
|
99 | presenter->animator()->addAnimation(bar); | |
101 | } |
|
100 | } | |
102 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
103 | return bar; |
|
102 | return bar; | |
104 | } |
|
103 | } | |
105 |
|
104 | |||
106 | #include "moc_qgroupedbarseries.cpp" |
|
105 | #include "moc_qgroupedbarseries.cpp" | |
107 |
|
106 | |||
108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
109 |
|
108 |
@@ -1,108 +1,107 | |||||
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 "qpercentbarseries.h" |
|
21 | #include "qpercentbarseries.h" | |
22 | #include "qpercentbarseries_p.h" |
|
22 | #include "qpercentbarseries_p.h" | |
23 | #include "percentbarchartitem_p.h" |
|
23 | #include "percentbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QPercentBarSeries |
|
31 | \class QPercentBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
35 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
36 | as stacks, where each bar is shown as percentage of all bars in that category. | |
37 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
37 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
38 |
|
38 | |||
39 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
39 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
40 | \image examples_percentbarchart.png |
|
40 | \image examples_percentbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
42 | \sa QBarSet, QStackedBarSeries, QBarSeries | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn virtual QSeriesType QPercentBarSeries::type() const |
|
46 | \fn virtual QSeriesType QPercentBarSeries::type() const | |
47 | \brief Returns type of series. |
|
47 | \brief Returns type of series. | |
48 | \sa QAbstractSeries, QSeriesType |
|
48 | \sa QAbstractSeries, QSeriesType | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | Constructs empty QPercentBarSeries. |
|
52 | Constructs empty QPercentBarSeries. | |
53 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
53 | QPercentBarSeries is QObject which is a child of a \a parent. | |
54 | */ |
|
54 | */ | |
55 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
55 | QPercentBarSeries::QPercentBarSeries(QObject *parent) | |
56 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
56 | : QBarSeries(*new QPercentBarSeriesPrivate(this), parent) | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
60 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
61 | { |
|
61 | { | |
62 | return QAbstractSeries::SeriesTypePercentBar; |
|
62 | return QAbstractSeries::SeriesTypePercentBar; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
66 |
|
66 | |||
67 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) |
|
67 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q) | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
72 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
73 | { |
|
73 | { | |
74 | Q_Q(QPercentBarSeries); |
|
|||
75 | qreal minX(domain.minX()); |
|
74 | qreal minX(domain.minX()); | |
76 | qreal minY(domain.minY()); |
|
75 | qreal minY(domain.minY()); | |
77 | qreal maxX(domain.maxX()); |
|
76 | qreal maxX(domain.maxX()); | |
78 | qreal maxY(domain.maxY()); |
|
77 | qreal maxY(domain.maxY()); | |
79 | int tickXCount(domain.tickXCount()); |
|
78 | int tickXCount(domain.tickXCount()); | |
80 | int tickYCount(domain.tickYCount()); |
|
79 | int tickYCount(domain.tickYCount()); | |
81 |
|
80 | |||
82 |
qreal x = |
|
81 | qreal x = categoryCount(); | |
83 | minX = qMin(minX, x) - 0.5; |
|
82 | minX = qMin(minX, x) - 0.5; | |
84 | maxX = qMax(maxX, x) - 0.5; |
|
83 | maxX = qMax(maxX, x) - 0.5; | |
85 | minY = 0; |
|
84 | minY = 0; | |
86 | maxY = 100; |
|
85 | maxY = 100; | |
87 | tickXCount = x+1; |
|
86 | tickXCount = x+1; | |
88 |
|
87 | |||
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
88 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
90 | } |
|
89 | } | |
91 |
|
90 | |||
92 |
|
91 | |||
93 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
92 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
94 | { |
|
93 | { | |
95 | Q_Q(QPercentBarSeries); |
|
94 | Q_Q(QPercentBarSeries); | |
96 |
|
95 | |||
97 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
96 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
97 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
99 | presenter->animator()->addAnimation(bar); |
|
98 | presenter->animator()->addAnimation(bar); | |
100 | } |
|
99 | } | |
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
100 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
102 | return bar; |
|
101 | return bar; | |
103 | } |
|
102 | } | |
104 |
|
103 | |||
105 | #include "moc_qpercentbarseries.cpp" |
|
104 | #include "moc_qpercentbarseries.cpp" | |
106 |
|
105 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
106 | QTCOMMERCIALCHART_END_NAMESPACE | |
108 |
|
107 |
@@ -1,109 +1,108 | |||||
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 "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | /*! |
|
30 | /*! | |
31 | \class QStackedBarSeries |
|
31 | \class QStackedBarSeries | |
32 | \brief part of QtCommercial chart API. |
|
32 | \brief part of QtCommercial chart API. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
35 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
36 | as stacks, where bars in same category are stacked on top of each other. |
|
36 | as stacks, where bars in same category are stacked on top of each other. | |
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
37 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
38 |
|
38 | |||
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
39 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
40 | \image examples_stackedbarchart.png |
|
40 | \image examples_stackedbarchart.png | |
41 |
|
41 | |||
42 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
42 | \sa QBarSet, QPercentBarSeries, QBarSeries | |
43 | */ |
|
43 | */ | |
44 |
|
44 | |||
45 | /*! |
|
45 | /*! | |
46 | \fn virtual QSeriesType QStackedBarSeries::type() const |
|
46 | \fn virtual QSeriesType QStackedBarSeries::type() const | |
47 | \brief Returns type of series. |
|
47 | \brief Returns type of series. | |
48 | \sa QAbstractSeries, QSeriesType |
|
48 | \sa QAbstractSeries, QSeriesType | |
49 | */ |
|
49 | */ | |
50 |
|
50 | |||
51 | /*! |
|
51 | /*! | |
52 | Constructs empty QStackedBarSeries. |
|
52 | Constructs empty QStackedBarSeries. | |
53 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
53 | QStackedBarSeries is QObject which is a child of a \a parent. | |
54 | */ |
|
54 | */ | |
55 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
55 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
56 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
56 | : QBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
60 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
61 | { |
|
61 | { | |
62 | return QAbstractSeries::SeriesTypeStackedBar; |
|
62 | return QAbstractSeries::SeriesTypeStackedBar; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
66 |
|
66 | |||
67 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) |
|
67 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q) | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
72 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
73 | { |
|
73 | { | |
74 | Q_Q(QStackedBarSeries); |
|
|||
75 | qreal minX(domain.minX()); |
|
74 | qreal minX(domain.minX()); | |
76 | qreal minY(domain.minY()); |
|
75 | qreal minY(domain.minY()); | |
77 | qreal maxX(domain.maxX()); |
|
76 | qreal maxX(domain.maxX()); | |
78 | qreal maxY(domain.maxY()); |
|
77 | qreal maxY(domain.maxY()); | |
79 | int tickXCount(domain.tickXCount()); |
|
78 | int tickXCount(domain.tickXCount()); | |
80 | int tickYCount(domain.tickYCount()); |
|
79 | int tickYCount(domain.tickYCount()); | |
81 |
|
80 | |||
82 |
qreal x = |
|
81 | qreal x = categoryCount(); | |
83 | qreal y = maxCategorySum(); |
|
82 | qreal y = maxCategorySum(); | |
84 | minX = qMin(minX, x) - 0.5; |
|
83 | minX = qMin(minX, x) - 0.5; | |
85 | minY = qMin(minY, y); |
|
84 | minY = qMin(minY, y); | |
86 | maxX = qMax(maxX, x) - 0.5; |
|
85 | maxX = qMax(maxX, x) - 0.5; | |
87 | maxY = qMax(maxY, y); |
|
86 | maxY = qMax(maxY, y); | |
88 | tickXCount = x+1; |
|
87 | tickXCount = x+1; | |
89 |
|
88 | |||
90 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
89 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
91 | } |
|
90 | } | |
92 |
|
91 | |||
93 |
|
92 | |||
94 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
93 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
95 | { |
|
94 | { | |
96 | Q_Q(QStackedBarSeries); |
|
95 | Q_Q(QStackedBarSeries); | |
97 |
|
96 | |||
98 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
97 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
99 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
98 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
100 | presenter->animator()->addAnimation(bar); |
|
99 | presenter->animator()->addAnimation(bar); | |
101 | } |
|
100 | } | |
102 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
101 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
103 | return bar; |
|
102 | return bar; | |
104 | } |
|
103 | } | |
105 |
|
104 | |||
106 | #include "moc_qstackedbarseries.cpp" |
|
105 | #include "moc_qstackedbarseries.cpp" | |
107 |
|
106 | |||
108 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE | |
109 |
|
108 |
@@ -1,88 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "stackedbarchartitem_p.h" |
|
21 | #include "stackedbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset_p.h" |
|
23 | #include "qbarset_p.h" | |
24 | #include "qbarseries_p.h" |
|
24 | #include "qbarseries_p.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : |
|
29 | StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) : | |
30 | BarChartItem(series, presenter) |
|
30 | BarChartItem(series, presenter) | |
31 | { |
|
31 | { | |
32 | } |
|
32 | } | |
33 |
|
33 | |||
34 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
34 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
35 | { |
|
35 | { | |
36 | QVector<QRectF> layout; |
|
36 | QVector<QRectF> layout; | |
37 |
// Use temporary qreals for accura |
|
37 | // Use temporary qreals for accuracy | |
38 | qreal categoryCount = m_series->categoryCount(); |
|
38 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
39 | qreal setCount = m_series->barsetCount(); |
|
39 | qreal setCount = m_series->barsetCount(); | |
40 |
|
40 | |||
41 | // Domain: |
|
41 | // Domain: | |
42 | qreal width = geometry().width(); |
|
42 | qreal width = geometry().width(); | |
43 | qreal height = geometry().height(); |
|
43 | qreal height = geometry().height(); | |
44 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
44 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
45 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
45 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
46 | qreal scaleY = (height / rangeY); |
|
46 | qreal scaleY = (height / rangeY); | |
47 | qreal scaleX = (width / rangeX); |
|
47 | qreal scaleX = (width / rangeX); | |
48 | qreal categoryWidth = width / categoryCount; |
|
48 | qreal categoryWidth = width / categoryCount; | |
49 | qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin(); |
|
49 | qreal barWidth = categoryWidth - categoryWidth * m_series->d_func()->barMargin(); | |
50 |
|
50 | |||
51 | int itemIndex(0); |
|
51 | int itemIndex(0); | |
52 | for (int category = 0; category < categoryCount; category++) { |
|
52 | for (int category = 0; category < categoryCount; category++) { | |
53 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); |
|
53 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); | |
54 | for (int set=0; set < setCount; set++) { |
|
54 | for (int set=0; set < setCount; set++) { | |
55 | QBarSet* barSet = m_series->d_func()->barsetAt(set); |
|
55 | QBarSet* barSet = m_series->d_func()->barsetAt(set); | |
56 |
|
56 | |||
57 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
57 | qreal xPos = (barSet->at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
58 |
|
58 | |||
59 | qreal barHeight = barSet->at(category).y() * scaleY; |
|
59 | qreal barHeight = barSet->at(category).y() * scaleY; | |
60 | Bar* bar = m_bars.at(itemIndex); |
|
60 | Bar* bar = m_bars.at(itemIndex); | |
61 | bar->setPen(barSet->pen()); |
|
61 | bar->setPen(barSet->pen()); | |
62 | bar->setBrush(barSet->brush()); |
|
62 | bar->setBrush(barSet->brush()); | |
63 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
63 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
64 | layout.append(rect); |
|
64 | layout.append(rect); | |
65 |
|
65 | |||
66 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
66 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
67 |
|
67 | |||
68 | if (!qFuzzyIsNull(barSet->at(category).y())) { |
|
68 | if (!qFuzzyIsNull(barSet->at(category).y())) { | |
69 | label->setText(QString::number(barSet->at(category).y())); |
|
69 | label->setText(QString::number(barSet->at(category).y())); | |
70 | } else { |
|
70 | } else { | |
71 | label->setText(QString("")); |
|
71 | label->setText(QString("")); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
74 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
75 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
75 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
76 | label->setFont(barSet->labelFont()); |
|
76 | label->setFont(barSet->labelFont()); | |
77 | label->setBrush(barSet->labelBrush()); |
|
77 | label->setBrush(barSet->labelBrush()); | |
78 | itemIndex++; |
|
78 | itemIndex++; | |
79 | yPos -= barHeight; |
|
79 | yPos -= barHeight; | |
80 | } |
|
80 | } | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | return layout; |
|
83 | return layout; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | #include "moc_stackedbarchartitem_p.cpp" |
|
86 | #include "moc_stackedbarchartitem_p.cpp" | |
87 |
|
87 | |||
88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
88 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,300 +1,285 | |||||
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 "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qaxis.h" |
|
23 | #include "qaxis.h" | |
24 | #include "qaxis_p.h" |
|
24 | #include "qaxis_p.h" | |
25 | #include "qabstractseries_p.h" |
|
25 | #include "qabstractseries_p.h" | |
26 | #include "qbarseries.h" |
|
26 | #include "qbarseries.h" | |
27 | #include "qstackedbarseries.h" |
|
27 | #include "qstackedbarseries.h" | |
28 | #include "qpercentbarseries.h" |
|
28 | #include "qpercentbarseries.h" | |
29 | #include "qpieseries.h" |
|
29 | #include "qpieseries.h" | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
32 | |||
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), |
|
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), | |
34 | m_axisX(new QAxis(this)), |
|
34 | m_axisX(new QAxis(this)), | |
35 | m_axisY(new QAxis(this)), |
|
35 | m_axisY(new QAxis(this)), | |
36 | m_domainIndex(0), |
|
36 | m_domainIndex(0), | |
37 | m_axisXInitialized(false), |
|
37 | m_axisXInitialized(false), | |
38 | m_axisYInitialized(false) |
|
38 | m_axisYInitialized(false) | |
39 | { |
|
39 | { | |
40 | //create main domain |
|
40 | //create main domain | |
41 | Domain* domain = new Domain(m_axisY); |
|
41 | Domain* domain = new Domain(m_axisY); | |
42 | m_axisDomainMap.insert(m_axisY,domain); |
|
42 | m_axisDomainMap.insert(m_axisY,domain); | |
43 | QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
43 | QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
44 | QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
44 | QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
45 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
45 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
46 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
46 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | ChartDataSet::~ChartDataSet() |
|
49 | ChartDataSet::~ChartDataSet() | |
50 | { |
|
50 | { | |
51 | removeAllSeries(); |
|
51 | removeAllSeries(); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) |
|
54 | void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY) | |
55 | { |
|
55 | { | |
56 | if(axisY==0) axisY = m_axisY; |
|
56 | if(axisY==0) axisY = m_axisY; | |
57 |
|
57 | |||
58 | QAxis* axis = m_seriesAxisMap.value(series); |
|
58 | QAxis* axis = m_seriesAxisMap.value(series); | |
59 |
|
59 | |||
60 | if(axis) { |
|
60 | if(axis) { | |
61 | qWarning() << "Can not add series. Series already on the chart"; |
|
61 | qWarning() << "Can not add series. Series already on the chart"; | |
62 | return; |
|
62 | return; | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | series->setParent(this); // take ownership |
|
65 | series->setParent(this); // take ownership | |
66 | axisY->setParent(this); // take ownership |
|
66 | axisY->setParent(this); // take ownership | |
67 |
|
67 | |||
68 | Domain* domain = m_axisDomainMap.value(axisY); |
|
68 | Domain* domain = m_axisDomainMap.value(axisY); | |
69 |
|
69 | |||
70 | if(!domain) { |
|
70 | if(!domain) { | |
71 | domain = new Domain(axisY); |
|
71 | domain = new Domain(axisY); | |
72 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
72 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
73 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); |
|
73 | QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int))); | |
74 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
74 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
75 | //initialize |
|
75 | //initialize | |
76 | m_axisDomainMap.insert(axisY,domain); |
|
76 | m_axisDomainMap.insert(axisY,domain); | |
77 | emit axisAdded(axisY,domain); |
|
77 | emit axisAdded(axisY,domain); | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | if(!m_axisXInitialized){ |
|
80 | if(!m_axisXInitialized){ | |
81 | m_axisXInitialized=true; |
|
81 | m_axisXInitialized=true; | |
82 | emit axisAdded(m_axisX,domain); |
|
82 | emit axisAdded(m_axisX,domain); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | if(!m_axisYInitialized && axisY==m_axisY){ |
|
85 | if(!m_axisYInitialized && axisY==m_axisY){ | |
86 | m_axisYInitialized=true; |
|
86 | m_axisYInitialized=true; | |
87 | emit axisAdded(m_axisY,domain); |
|
87 | emit axisAdded(m_axisY,domain); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | series->d_ptr->scaleDomain(*domain); |
|
90 | series->d_ptr->scaleDomain(*domain); | |
91 |
|
91 | |||
92 | // Note that with SeriesTypeBar we don't set up categories, but use real values on x-asis |
|
|||
93 | if(series->type() == QAbstractSeries::SeriesTypeGroupedBar |
|
|||
94 | || series->type() == QAbstractSeries::SeriesTypeStackedBar |
|
|||
95 | || series->type() == QAbstractSeries::SeriesTypePercentBar) { |
|
|||
96 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
|||
97 | setupCategories(barSeries); |
|
|||
98 | } |
|
|||
99 |
|
||||
100 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { |
|
92 | if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) { | |
101 | axisX()->hide(); |
|
93 | axisX()->hide(); | |
102 | this->axisY()->hide(); |
|
94 | this->axisY()->hide(); | |
103 | } |
|
95 | } | |
104 |
|
96 | |||
105 | m_seriesAxisMap.insert(series,axisY); |
|
97 | m_seriesAxisMap.insert(series,axisY); | |
106 |
|
98 | |||
107 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
99 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
108 |
|
100 | |||
109 | int key=0; |
|
101 | int key=0; | |
110 | while (i.hasNext()) { |
|
102 | while (i.hasNext()) { | |
111 | i.next(); |
|
103 | i.next(); | |
112 | if(i.key()!=key) { |
|
104 | if(i.key()!=key) { | |
113 | break; |
|
105 | break; | |
114 | } |
|
106 | } | |
115 | key++; |
|
107 | key++; | |
116 | } |
|
108 | } | |
117 |
|
109 | |||
118 | m_indexSeriesMap.insert(key,series); |
|
110 | m_indexSeriesMap.insert(key,series); | |
119 |
|
111 | |||
120 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
112 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
121 | series->d_ptr->m_dataset = this; |
|
113 | series->d_ptr->m_dataset = this; | |
122 |
|
114 | |||
123 | emit seriesAdded(series,domain); |
|
115 | emit seriesAdded(series,domain); | |
124 |
|
116 | |||
125 | } |
|
117 | } | |
126 |
|
118 | |||
127 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) |
|
119 | QAxis* ChartDataSet::removeSeries(QAbstractSeries* series) | |
128 | { |
|
120 | { | |
129 | QAxis* axis = m_seriesAxisMap.value(series); |
|
121 | QAxis* axis = m_seriesAxisMap.value(series); | |
130 |
|
122 | |||
131 | if(!axis){ |
|
123 | if(!axis){ | |
132 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
124 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
133 | return 0; |
|
125 | return 0; | |
134 | } |
|
126 | } | |
135 |
|
127 | |||
136 | emit seriesRemoved(series); |
|
128 | emit seriesRemoved(series); | |
137 |
|
129 | |||
138 | m_seriesAxisMap.remove(series); |
|
130 | m_seriesAxisMap.remove(series); | |
139 | int key = seriesIndex(series); |
|
131 | int key = seriesIndex(series); | |
140 | Q_ASSERT(key!=-1); |
|
132 | Q_ASSERT(key!=-1); | |
141 |
|
133 | |||
142 | m_indexSeriesMap.remove(key); |
|
134 | m_indexSeriesMap.remove(key); | |
143 |
|
135 | |||
144 | series->setParent(0); |
|
136 | series->setParent(0); | |
145 | series->d_ptr->m_chart = 0; |
|
137 | series->d_ptr->m_chart = 0; | |
146 | series->d_ptr->m_dataset = 0; |
|
138 | series->d_ptr->m_dataset = 0; | |
147 |
|
139 | |||
148 | QList<QAxis*> axes = m_seriesAxisMap.values(); |
|
140 | QList<QAxis*> axes = m_seriesAxisMap.values(); | |
149 |
|
141 | |||
150 | int i = axes.indexOf(axis); |
|
142 | int i = axes.indexOf(axis); | |
151 |
|
143 | |||
152 | if(i==-1){ |
|
144 | if(i==-1){ | |
153 | Domain* domain = m_axisDomainMap.take(axis); |
|
145 | Domain* domain = m_axisDomainMap.take(axis); | |
154 | emit axisRemoved(axis); |
|
146 | emit axisRemoved(axis); | |
155 | if(axis!=m_axisY){ |
|
147 | if(axis!=m_axisY){ | |
156 | axis->setParent(0); |
|
148 | axis->setParent(0); | |
157 | delete domain; |
|
149 | delete domain; | |
158 | }else{ |
|
150 | }else{ | |
159 | m_axisYInitialized=false; |
|
151 | m_axisYInitialized=false; | |
160 | m_axisDomainMap.insert(m_axisY,domain); |
|
152 | m_axisDomainMap.insert(m_axisY,domain); | |
161 | } |
|
153 | } | |
162 | } |
|
154 | } | |
163 |
|
155 | |||
164 | if(m_seriesAxisMap.values().size()==0) |
|
156 | if(m_seriesAxisMap.values().size()==0) | |
165 | { |
|
157 | { | |
166 | m_axisXInitialized=false; |
|
158 | m_axisXInitialized=false; | |
167 | emit axisRemoved(axisX()); |
|
159 | emit axisRemoved(axisX()); | |
168 | } |
|
160 | } | |
169 |
|
161 | |||
170 | return axis; |
|
162 | return axis; | |
171 | } |
|
163 | } | |
172 |
|
164 | |||
173 | void ChartDataSet::removeAllSeries() |
|
165 | void ChartDataSet::removeAllSeries() | |
174 | { |
|
166 | { | |
175 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); |
|
167 | QList<QAbstractSeries*> series = m_seriesAxisMap.keys(); | |
176 | QList<QAxis*> axes; |
|
168 | QList<QAxis*> axes; | |
177 | foreach(QAbstractSeries *s , series) { |
|
169 | foreach(QAbstractSeries *s , series) { | |
178 | QAxis* axis = removeSeries(s); |
|
170 | QAxis* axis = removeSeries(s); | |
179 | if(axis==axisY()) continue; |
|
171 | if(axis==axisY()) continue; | |
180 | int i = axes.indexOf(axis); |
|
172 | int i = axes.indexOf(axis); | |
181 | if(i==-1){ |
|
173 | if(i==-1){ | |
182 | axes<<axis; |
|
174 | axes<<axis; | |
183 | } |
|
175 | } | |
184 | } |
|
176 | } | |
185 |
|
177 | |||
186 | Q_ASSERT(m_seriesAxisMap.count()==0); |
|
178 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
187 | Q_ASSERT(m_axisDomainMap.count()==1); |
|
179 | Q_ASSERT(m_axisDomainMap.count()==1); | |
188 |
|
180 | |||
189 | qDeleteAll(series); |
|
181 | qDeleteAll(series); | |
190 | qDeleteAll(axes); |
|
182 | qDeleteAll(axes); | |
191 | } |
|
183 | } | |
192 |
|
184 | |||
193 | void ChartDataSet::setupCategories(QBarSeries* series) |
|
|||
194 | { |
|
|||
195 | QAxisCategories* categories = axisX()->categories(); |
|
|||
196 | categories->clear(); |
|
|||
197 | categories->insert(series->categories()); |
|
|||
198 | } |
|
|||
199 |
|
||||
200 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
185 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
201 | { |
|
186 | { | |
202 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
187 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
203 | //main domain has to be the last one; |
|
188 | //main domain has to be the last one; | |
204 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
189 | Domain *domain = m_axisDomainMap.value(axisY()); | |
205 | Q_ASSERT(domain); |
|
190 | Q_ASSERT(domain); | |
206 | while (i.hasNext()) { |
|
191 | while (i.hasNext()) { | |
207 | i.next(); |
|
192 | i.next(); | |
208 | if(i.value()==domain) continue; |
|
193 | if(i.value()==domain) continue; | |
209 | i.value()->zoomIn(rect,size); |
|
194 | i.value()->zoomIn(rect,size); | |
210 | } |
|
195 | } | |
211 | domain->zoomIn(rect,size); |
|
196 | domain->zoomIn(rect,size); | |
212 | } |
|
197 | } | |
213 |
|
198 | |||
214 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
199 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
215 | { |
|
200 | { | |
216 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); |
|
201 | QMapIterator<QAxis*, Domain*> i(m_axisDomainMap); | |
217 | //main domain has to be the last one; |
|
202 | //main domain has to be the last one; | |
218 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
203 | Domain *domain = m_axisDomainMap.value(axisY()); | |
219 | Q_ASSERT(domain); |
|
204 | Q_ASSERT(domain); | |
220 | while (i.hasNext()) { |
|
205 | while (i.hasNext()) { | |
221 | i.next(); |
|
206 | i.next(); | |
222 | if(i.value()==domain) continue; |
|
207 | if(i.value()==domain) continue; | |
223 | i.value()->zoomOut(rect,size); |
|
208 | i.value()->zoomOut(rect,size); | |
224 | } |
|
209 | } | |
225 | domain->zoomOut(rect,size); |
|
210 | domain->zoomOut(rect,size); | |
226 | } |
|
211 | } | |
227 |
|
212 | |||
228 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
213 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
229 | { |
|
214 | { | |
230 | int count=0; |
|
215 | int count=0; | |
231 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); |
|
216 | QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap); | |
232 | while (i.hasNext()) { |
|
217 | while (i.hasNext()) { | |
233 | i.next(); |
|
218 | i.next(); | |
234 | if(i.key()->type()==type) count++; |
|
219 | if(i.key()->type()==type) count++; | |
235 | } |
|
220 | } | |
236 | return count; |
|
221 | return count; | |
237 | } |
|
222 | } | |
238 |
|
223 | |||
239 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
224 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
240 | { |
|
225 | { | |
241 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
226 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
242 | while (i.hasNext()) { |
|
227 | while (i.hasNext()) { | |
243 | i.next(); |
|
228 | i.next(); | |
244 | if (i.value() == series) |
|
229 | if (i.value() == series) | |
245 | return i.key(); |
|
230 | return i.key(); | |
246 | } |
|
231 | } | |
247 | return -1; |
|
232 | return -1; | |
248 | } |
|
233 | } | |
249 |
|
234 | |||
250 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
235 | QAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
251 | { |
|
236 | { | |
252 | if(series == 0) return m_axisY; |
|
237 | if(series == 0) return m_axisY; | |
253 | return m_seriesAxisMap.value(series); |
|
238 | return m_seriesAxisMap.value(series); | |
254 | } |
|
239 | } | |
255 |
|
240 | |||
256 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
241 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
257 | { |
|
242 | { | |
258 | QAxis* axis = m_seriesAxisMap.value(series); |
|
243 | QAxis* axis = m_seriesAxisMap.value(series); | |
259 | if(axis){ |
|
244 | if(axis){ | |
260 | return m_axisDomainMap.value(axis); |
|
245 | return m_axisDomainMap.value(axis); | |
261 | }else |
|
246 | }else | |
262 | return 0; |
|
247 | return 0; | |
263 | } |
|
248 | } | |
264 |
|
249 | |||
265 | Domain* ChartDataSet::domain(QAxis* axis) const |
|
250 | Domain* ChartDataSet::domain(QAxis* axis) const | |
266 | { |
|
251 | { | |
267 | if(!axis || axis==axisX()) { |
|
252 | if(!axis || axis==axisX()) { | |
268 | return m_axisDomainMap.value(axisY()); |
|
253 | return m_axisDomainMap.value(axisY()); | |
269 | } |
|
254 | } | |
270 | else { |
|
255 | else { | |
271 | return m_axisDomainMap.value(axis); |
|
256 | return m_axisDomainMap.value(axis); | |
272 | } |
|
257 | } | |
273 | } |
|
258 | } | |
274 |
|
259 | |||
275 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
260 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
276 | { |
|
261 | { | |
277 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); |
|
262 | QMapIterator<QAxis*, Domain*> i( m_axisDomainMap); | |
278 | //main domain has to be the last one; |
|
263 | //main domain has to be the last one; | |
279 | Domain *domain = m_axisDomainMap.value(axisY()); |
|
264 | Domain *domain = m_axisDomainMap.value(axisY()); | |
280 | while (i.hasNext()) { |
|
265 | while (i.hasNext()) { | |
281 | i.next(); |
|
266 | i.next(); | |
282 | if(i.value()==domain) continue; |
|
267 | if(i.value()==domain) continue; | |
283 | i.value()->move(dx,dy,size); |
|
268 | i.value()->move(dx,dy,size); | |
284 | } |
|
269 | } | |
285 | domain->move(dx,dy,size); |
|
270 | domain->move(dx,dy,size); | |
286 | } |
|
271 | } | |
287 |
|
272 | |||
288 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
273 | QList<QAbstractSeries*> ChartDataSet::series() const | |
289 | { |
|
274 | { | |
290 | return m_seriesAxisMap.keys(); |
|
275 | return m_seriesAxisMap.keys(); | |
291 | } |
|
276 | } | |
292 |
|
277 | |||
293 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
278 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
294 | { |
|
279 | { | |
295 | emit seriesUpdated(series); |
|
280 | emit seriesUpdated(series); | |
296 | } |
|
281 | } | |
297 |
|
282 | |||
298 | #include "moc_chartdataset_p.cpp" |
|
283 | #include "moc_chartdataset_p.cpp" | |
299 |
|
284 | |||
300 | QTCOMMERCIALCHART_END_NAMESPACE |
|
285 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,95 +1,93 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTDATASET_P_H |
|
30 | #ifndef CHARTDATASET_P_H | |
31 | #define CHARTDATASET_P_H |
|
31 | #define CHARTDATASET_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 | #include <QVector> |
|
35 | #include <QVector> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class QAxis; |
|
39 | class QAxis; | |
40 | class QBarSeries; |
|
|||
41 |
|
40 | |||
42 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject |
|
41 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject | |
43 | { |
|
42 | { | |
44 | Q_OBJECT |
|
43 | Q_OBJECT | |
45 | public: |
|
44 | public: | |
46 | ChartDataSet(QChart* parent=0); |
|
45 | ChartDataSet(QChart* parent=0); | |
47 | virtual ~ChartDataSet(); |
|
46 | virtual ~ChartDataSet(); | |
48 |
|
47 | |||
49 | void addSeries(QAbstractSeries* series,QAxis *axisY = 0); |
|
48 | void addSeries(QAbstractSeries* series,QAxis *axisY = 0); | |
50 | QAxis* removeSeries(QAbstractSeries* series); |
|
49 | QAxis* removeSeries(QAbstractSeries* series); | |
51 | void removeAllSeries(); |
|
50 | void removeAllSeries(); | |
52 | void updateSeries(QAbstractSeries* series); |
|
51 | void updateSeries(QAbstractSeries* series); | |
53 |
|
52 | |||
54 | void zoomInDomain(const QRectF& rect, const QSizeF& size); |
|
53 | void zoomInDomain(const QRectF& rect, const QSizeF& size); | |
55 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); |
|
54 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); | |
56 | void scrollDomain(qreal dx,qreal dy,const QSizeF& size); |
|
55 | void scrollDomain(qreal dx,qreal dy,const QSizeF& size); | |
57 |
|
56 | |||
58 | int seriesCount(QAbstractSeries::SeriesType type); |
|
57 | int seriesCount(QAbstractSeries::SeriesType type); | |
59 | int seriesIndex(QAbstractSeries *series); |
|
58 | int seriesIndex(QAbstractSeries *series); | |
60 |
|
59 | |||
61 | Domain* domain(QAbstractSeries* series) const; |
|
60 | Domain* domain(QAbstractSeries* series) const; | |
62 | Domain* domain(QAxis* axis) const; |
|
61 | Domain* domain(QAxis* axis) const; | |
63 |
|
62 | |||
64 | QAxis* axisX() const { return m_axisX; } |
|
63 | QAxis* axisX() const { return m_axisX; } | |
65 | QAxis* axisY(QAbstractSeries *series = 0) const; |
|
64 | QAxis* axisY(QAbstractSeries *series = 0) const; | |
66 |
|
65 | |||
67 | QList<QAbstractSeries*> series() const; |
|
66 | QList<QAbstractSeries*> series() const; | |
68 |
|
67 | |||
69 | Q_SIGNALS: |
|
68 | Q_SIGNALS: | |
70 | void seriesAdded(QAbstractSeries* series, Domain* domain); |
|
69 | void seriesAdded(QAbstractSeries* series, Domain* domain); | |
71 | void seriesRemoved(QAbstractSeries* series); |
|
70 | void seriesRemoved(QAbstractSeries* series); | |
72 | void seriesUpdated(QAbstractSeries* series); |
|
71 | void seriesUpdated(QAbstractSeries* series); | |
73 | void axisAdded(QAxis* axis,Domain* domain); |
|
72 | void axisAdded(QAxis* axis,Domain* domain); | |
74 | void axisRemoved(QAxis* axis); |
|
73 | void axisRemoved(QAxis* axis); | |
75 |
|
74 | |||
76 | private: |
|
75 | private: | |
77 | QStringList createLabels(QAxis* axis,qreal min, qreal max); |
|
76 | QStringList createLabels(QAxis* axis,qreal min, qreal max); | |
78 | void calculateDomain(QAbstractSeries* series,Domain* domain); |
|
77 | void calculateDomain(QAbstractSeries* series,Domain* domain); | |
79 | void setupCategories(QBarSeries* series); |
|
|||
80 |
|
78 | |||
81 | private: |
|
79 | private: | |
82 | QMap<QAbstractSeries *, QAxis *> m_seriesAxisMap; |
|
80 | QMap<QAbstractSeries *, QAxis *> m_seriesAxisMap; | |
83 | QMap<QAxis*, Domain *> m_axisDomainMap; |
|
81 | QMap<QAxis*, Domain *> m_axisDomainMap; | |
84 | QMap<int, QAbstractSeries *> m_indexSeriesMap; |
|
82 | QMap<int, QAbstractSeries *> m_indexSeriesMap; | |
85 | QAxis* m_axisX; |
|
83 | QAxis* m_axisX; | |
86 | QAxis* m_axisY; |
|
84 | QAxis* m_axisY; | |
87 |
|
85 | |||
88 | int m_domainIndex; |
|
86 | int m_domainIndex; | |
89 | bool m_axisXInitialized; |
|
87 | bool m_axisXInitialized; | |
90 | bool m_axisYInitialized; |
|
88 | bool m_axisYInitialized; | |
91 | }; |
|
89 | }; | |
92 |
|
90 | |||
93 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
94 |
|
92 | |||
95 | #endif /* CHARTENGINE_P_H_ */ |
|
93 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,607 +1,534 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | Q_DECLARE_METATYPE(QBarSet*) |
|
29 | Q_DECLARE_METATYPE(QBarSet*) | |
30 |
|
30 | |||
31 | class tst_QBarSeries : public QObject |
|
31 | class tst_QBarSeries : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public slots: |
|
35 | public slots: | |
36 | void initTestCase(); |
|
36 | void initTestCase(); | |
37 | void cleanupTestCase(); |
|
37 | void cleanupTestCase(); | |
38 | void init(); |
|
38 | void init(); | |
39 | void cleanup(); |
|
39 | void cleanup(); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 | void qbarseries_data(); |
|
42 | void qbarseries_data(); | |
43 | void qbarseries(); |
|
43 | void qbarseries(); | |
44 | void type_data(); |
|
44 | void type_data(); | |
45 | void type(); |
|
45 | void type(); | |
46 | void setCategories_data(); |
|
|||
47 | void setCategories(); |
|
|||
48 | void append_data(); |
|
46 | void append_data(); | |
49 | void append(); |
|
47 | void append(); | |
50 | void remove_data(); |
|
48 | void remove_data(); | |
51 | void remove(); |
|
49 | void remove(); | |
52 | void appendList_data(); |
|
50 | void appendList_data(); | |
53 | void appendList(); |
|
51 | void appendList(); | |
54 | void removeList_data(); |
|
52 | void removeList_data(); | |
55 | void removeList(); |
|
53 | void removeList(); | |
56 | void barsetCount_data(); |
|
54 | void barsetCount_data(); | |
57 | void barsetCount(); |
|
55 | void barsetCount(); | |
58 | void categoryCount_data(); |
|
|||
59 | void categoryCount(); |
|
|||
60 | void barSets_data(); |
|
56 | void barSets_data(); | |
61 | void barSets(); |
|
57 | void barSets(); | |
62 | void categories_data(); |
|
|||
63 | void categories(); |
|
|||
64 | void setLabelsVisible_data(); |
|
58 | void setLabelsVisible_data(); | |
65 | void setLabelsVisible(); |
|
59 | void setLabelsVisible(); | |
66 | void mouseclicked_data(); |
|
60 | void mouseclicked_data(); | |
67 | void mouseclicked(); |
|
61 | void mouseclicked(); | |
68 | void mousehovered_data(); |
|
62 | void mousehovered_data(); | |
69 | void mousehovered(); |
|
63 | void mousehovered(); | |
70 |
|
64 | |||
71 | private: |
|
65 | private: | |
72 | QBarSeries* m_barseries; |
|
66 | QBarSeries* m_barseries; | |
73 | QBarSeries* m_barseries_with_sets; |
|
67 | QBarSeries* m_barseries_with_sets; | |
74 |
|
68 | |||
75 | QList<QBarSet*> m_testSets; |
|
69 | QList<QBarSet*> m_testSets; | |
76 |
|
70 | |||
77 | QBarCategories m_categories; |
|
|||
78 | }; |
|
71 | }; | |
79 |
|
72 | |||
80 | void tst_QBarSeries::initTestCase() |
|
73 | void tst_QBarSeries::initTestCase() | |
81 | { |
|
74 | { | |
82 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
75 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
83 | } |
|
76 | } | |
84 |
|
77 | |||
85 | void tst_QBarSeries::cleanupTestCase() |
|
78 | void tst_QBarSeries::cleanupTestCase() | |
86 | { |
|
79 | { | |
87 | } |
|
80 | } | |
88 |
|
81 | |||
89 | void tst_QBarSeries::init() |
|
82 | void tst_QBarSeries::init() | |
90 | { |
|
83 | { | |
91 | m_categories << "category0" << "category1" << "category2"; |
|
|||
92 | m_barseries = new QBarSeries(); |
|
84 | m_barseries = new QBarSeries(); | |
93 | m_barseries->setCategories(m_categories); |
|
|||
94 | m_barseries_with_sets = new QBarSeries(); |
|
85 | m_barseries_with_sets = new QBarSeries(); | |
95 | m_barseries_with_sets->setCategories(m_categories); |
|
|||
96 |
|
86 | |||
97 | for (int i=0; i<5; i++) { |
|
87 | for (int i=0; i<5; i++) { | |
98 | m_testSets.append(new QBarSet("testset")); |
|
88 | m_testSets.append(new QBarSet("testset")); | |
99 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
89 | m_barseries_with_sets->append(m_testSets.at(i)); | |
100 | } |
|
90 | } | |
101 | } |
|
91 | } | |
102 |
|
92 | |||
103 | void tst_QBarSeries::cleanup() |
|
93 | void tst_QBarSeries::cleanup() | |
104 | { |
|
94 | { | |
105 | foreach(QBarSet* s, m_testSets) { |
|
95 | foreach(QBarSet* s, m_testSets) { | |
106 | m_barseries_with_sets->remove(s); |
|
96 | m_barseries_with_sets->remove(s); | |
107 | delete s; |
|
97 | delete s; | |
108 | } |
|
98 | } | |
109 | m_testSets.clear(); |
|
99 | m_testSets.clear(); | |
110 |
|
100 | |||
111 | delete m_barseries; |
|
101 | delete m_barseries; | |
112 | m_barseries = 0; |
|
102 | m_barseries = 0; | |
113 | delete m_barseries_with_sets; |
|
103 | delete m_barseries_with_sets; | |
114 | m_barseries_with_sets = 0; |
|
104 | m_barseries_with_sets = 0; | |
115 | m_categories.clear(); |
|
|||
116 | } |
|
105 | } | |
117 |
|
106 | |||
118 | void tst_QBarSeries::qbarseries_data() |
|
107 | void tst_QBarSeries::qbarseries_data() | |
119 | { |
|
108 | { | |
120 | QTest::addColumn<QBarCategories> ("categories"); |
|
|||
121 | QBarCategories c; |
|
|||
122 | c << "category0" << "category1" << "category2"; |
|
|||
123 | QTest::newRow("categories") << c; |
|
|||
124 | } |
|
109 | } | |
125 |
|
110 | |||
126 | void tst_QBarSeries::qbarseries() |
|
111 | void tst_QBarSeries::qbarseries() | |
127 | { |
|
112 | { | |
128 | QFETCH(QBarCategories, categories); |
|
|||
129 | QBarSeries *barseries = new QBarSeries(); |
|
113 | QBarSeries *barseries = new QBarSeries(); | |
130 | QVERIFY(barseries != 0); |
|
114 | QVERIFY(barseries != 0); | |
131 | barseries->setCategories(categories); |
|
|||
132 | QBarCategories verifyCategories = barseries->categories(); |
|
|||
133 |
|
||||
134 | QVERIFY(verifyCategories.count() == categories.count()); |
|
|||
135 | for (int i=0; i<categories.count(); i++) { |
|
|||
136 | QVERIFY(verifyCategories.at(i).compare(categories.at(i)) == 0); |
|
|||
137 | } |
|
|||
138 | } |
|
115 | } | |
139 |
|
116 | |||
140 | void tst_QBarSeries::type_data() |
|
117 | void tst_QBarSeries::type_data() | |
141 | { |
|
118 | { | |
142 |
|
119 | |||
143 | } |
|
120 | } | |
144 |
|
121 | |||
145 | void tst_QBarSeries::type() |
|
122 | void tst_QBarSeries::type() | |
146 | { |
|
123 | { | |
147 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
124 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
148 | } |
|
125 | } | |
149 |
|
126 | |||
150 | void tst_QBarSeries::setCategories_data() |
|
|||
151 | { |
|
|||
152 | QTest::addColumn<QBarCategories> ("categories"); |
|
|||
153 | QBarCategories categories; |
|
|||
154 | categories << "c1" << "c2" << "c3" << "c4" << "c5" << "c6"; |
|
|||
155 | QTest::newRow("cat") << categories; |
|
|||
156 | } |
|
|||
157 |
|
||||
158 | void tst_QBarSeries::setCategories() |
|
|||
159 | { |
|
|||
160 | QVERIFY(m_barseries->categories().count() == m_categories.count()); |
|
|||
161 |
|
||||
162 | QFETCH(QBarCategories, categories); |
|
|||
163 | m_barseries->setCategories(categories); |
|
|||
164 |
|
||||
165 | QVERIFY(m_barseries->categories().count() == categories.count()); |
|
|||
166 | for (int i=0; i<categories.count(); i++) { |
|
|||
167 | QVERIFY(m_barseries->categories().at(i).compare(categories.at(i)) == 0); |
|
|||
168 | } |
|
|||
169 | } |
|
|||
170 |
|
||||
171 | void tst_QBarSeries::append_data() |
|
127 | void tst_QBarSeries::append_data() | |
172 | { |
|
128 | { | |
173 | } |
|
129 | } | |
174 |
|
130 | |||
175 | void tst_QBarSeries::append() |
|
131 | void tst_QBarSeries::append() | |
176 | { |
|
132 | { | |
177 | QVERIFY(m_barseries->barsetCount() == 0); |
|
133 | QVERIFY(m_barseries->barsetCount() == 0); | |
178 |
|
134 | |||
179 | bool ret = false; |
|
135 | bool ret = false; | |
180 |
|
136 | |||
181 | // Try adding barset |
|
137 | // Try adding barset | |
182 | QBarSet *barset = new QBarSet("testset"); |
|
138 | QBarSet *barset = new QBarSet("testset"); | |
183 | ret = m_barseries->append(barset); |
|
139 | ret = m_barseries->append(barset); | |
184 |
|
140 | |||
185 | QVERIFY(ret == true); |
|
141 | QVERIFY(ret == true); | |
186 | QVERIFY(m_barseries->barsetCount() == 1); |
|
142 | QVERIFY(m_barseries->barsetCount() == 1); | |
187 |
|
143 | |||
188 | // Try adding another set |
|
144 | // Try adding another set | |
189 | QBarSet *barset2 = new QBarSet("testset2"); |
|
145 | QBarSet *barset2 = new QBarSet("testset2"); | |
190 | ret = m_barseries->append(barset2); |
|
146 | ret = m_barseries->append(barset2); | |
191 |
|
147 | |||
192 | QVERIFY(ret == true); |
|
148 | QVERIFY(ret == true); | |
193 | QVERIFY(m_barseries->barsetCount() == 2); |
|
149 | QVERIFY(m_barseries->barsetCount() == 2); | |
194 |
|
150 | |||
195 | // Try adding same set again |
|
151 | // Try adding same set again | |
196 | ret = m_barseries->append(barset2); |
|
152 | ret = m_barseries->append(barset2); | |
197 | QVERIFY(ret == false); |
|
153 | QVERIFY(ret == false); | |
198 | QVERIFY(m_barseries->barsetCount() == 2); |
|
154 | QVERIFY(m_barseries->barsetCount() == 2); | |
199 |
|
155 | |||
200 | // Try adding null set |
|
156 | // Try adding null set | |
201 | ret = m_barseries->append(0); |
|
157 | ret = m_barseries->append(0); | |
202 | QVERIFY(ret == false); |
|
158 | QVERIFY(ret == false); | |
203 | QVERIFY(m_barseries->barsetCount() == 2); |
|
159 | QVERIFY(m_barseries->barsetCount() == 2); | |
204 |
|
160 | |||
205 | } |
|
161 | } | |
206 |
|
162 | |||
207 | void tst_QBarSeries::remove_data() |
|
163 | void tst_QBarSeries::remove_data() | |
208 | { |
|
164 | { | |
209 | } |
|
165 | } | |
210 |
|
166 | |||
211 | void tst_QBarSeries::remove() |
|
167 | void tst_QBarSeries::remove() | |
212 | { |
|
168 | { | |
213 | int count = m_testSets.count(); |
|
169 | int count = m_testSets.count(); | |
214 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
170 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
215 |
|
171 | |||
216 | // Try to remove null pointer (should not remove, should not crash) |
|
172 | // Try to remove null pointer (should not remove, should not crash) | |
217 | bool ret = false; |
|
173 | bool ret = false; | |
218 | ret = m_barseries_with_sets->remove(0); |
|
174 | ret = m_barseries_with_sets->remove(0); | |
219 | QVERIFY(ret == false); |
|
175 | QVERIFY(ret == false); | |
220 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
176 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
221 |
|
177 | |||
222 | // Try to remove invalid pointer (should not remove, should not crash) |
|
178 | // Try to remove invalid pointer (should not remove, should not crash) | |
223 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
179 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); | |
224 | QVERIFY(ret == false); |
|
180 | QVERIFY(ret == false); | |
225 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
181 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
226 |
|
182 | |||
227 | // remove some sets |
|
183 | // remove some sets | |
228 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
184 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); | |
229 | QVERIFY(ret == true); |
|
185 | QVERIFY(ret == true); | |
230 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
186 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); | |
231 | QVERIFY(ret == true); |
|
187 | QVERIFY(ret == true); | |
232 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
188 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); | |
233 | QVERIFY(ret == true); |
|
189 | QVERIFY(ret == true); | |
234 |
|
190 | |||
235 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); |
|
191 | QVERIFY(m_barseries_with_sets->barsetCount() == 2); | |
236 |
|
192 | |||
237 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
193 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
238 |
|
194 | |||
239 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
195 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
240 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
196 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
241 |
|
197 | |||
242 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
198 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
243 | ret = false; |
|
199 | ret = false; | |
244 | for (int i=0; i<count; i++) { |
|
200 | for (int i=0; i<count; i++) { | |
245 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
201 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); | |
246 | } |
|
202 | } | |
247 |
|
203 | |||
248 | QVERIFY(ret == true); |
|
204 | QVERIFY(ret == true); | |
249 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
205 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
250 | } |
|
206 | } | |
251 |
|
207 | |||
252 | void tst_QBarSeries::appendList_data() |
|
208 | void tst_QBarSeries::appendList_data() | |
253 | { |
|
209 | { | |
254 |
|
210 | |||
255 | } |
|
211 | } | |
256 |
|
212 | |||
257 | void tst_QBarSeries::appendList() |
|
213 | void tst_QBarSeries::appendList() | |
258 | { |
|
214 | { | |
259 | int count = 5; |
|
215 | int count = 5; | |
260 | QVERIFY(m_barseries->barsetCount() == 0); |
|
216 | QVERIFY(m_barseries->barsetCount() == 0); | |
261 |
|
217 | |||
262 | QList<QBarSet*> sets; |
|
218 | QList<QBarSet*> sets; | |
263 | for (int i=0; i<count; i++) { |
|
219 | for (int i=0; i<count; i++) { | |
264 | sets.append(new QBarSet("testset")); |
|
220 | sets.append(new QBarSet("testset")); | |
265 | } |
|
221 | } | |
266 |
|
222 | |||
267 | // Append new sets (should succeed, count should match the count of sets) |
|
223 | // Append new sets (should succeed, count should match the count of sets) | |
268 | bool ret = false; |
|
224 | bool ret = false; | |
269 | ret = m_barseries->append(sets); |
|
225 | ret = m_barseries->append(sets); | |
270 | QVERIFY(ret == true); |
|
226 | QVERIFY(ret == true); | |
271 | QVERIFY(m_barseries->barsetCount() == count); |
|
227 | QVERIFY(m_barseries->barsetCount() == count); | |
272 |
|
228 | |||
273 | // Append same sets again (should fail, count should remain same) |
|
229 | // Append same sets again (should fail, count should remain same) | |
274 | ret = m_barseries->append(sets); |
|
230 | ret = m_barseries->append(sets); | |
275 | QVERIFY(ret == false); |
|
231 | QVERIFY(ret == false); | |
276 | QVERIFY(m_barseries->barsetCount() == count); |
|
232 | QVERIFY(m_barseries->barsetCount() == count); | |
277 |
|
233 | |||
278 | // Try append empty list (should succeed, but count should remain same) |
|
234 | // Try append empty list (should succeed, but count should remain same) | |
279 | QList<QBarSet*> invalidList; |
|
235 | QList<QBarSet*> invalidList; | |
280 | ret = m_barseries->append(invalidList); |
|
236 | ret = m_barseries->append(invalidList); | |
281 | QVERIFY(ret == true); |
|
237 | QVERIFY(ret == true); | |
282 | QVERIFY(m_barseries->barsetCount() == count); |
|
238 | QVERIFY(m_barseries->barsetCount() == count); | |
283 |
|
239 | |||
284 | // Try append list with one new and one existing set (should fail, count remains same) |
|
240 | // Try append list with one new and one existing set (should fail, count remains same) | |
285 | invalidList.append(new QBarSet("ok set")); |
|
241 | invalidList.append(new QBarSet("ok set")); | |
286 | invalidList.append(sets.at(0)); |
|
242 | invalidList.append(sets.at(0)); | |
287 | ret = m_barseries->append(invalidList); |
|
243 | ret = m_barseries->append(invalidList); | |
288 | QVERIFY(ret == false); |
|
244 | QVERIFY(ret == false); | |
289 | QVERIFY(m_barseries->barsetCount() == count); |
|
245 | QVERIFY(m_barseries->barsetCount() == count); | |
290 |
|
246 | |||
291 | // Try append list with null pointers (should fail, count remains same) |
|
247 | // Try append list with null pointers (should fail, count remains same) | |
292 | QList<QBarSet*> invalidList2; |
|
248 | QList<QBarSet*> invalidList2; | |
293 | invalidList2.append(0); |
|
249 | invalidList2.append(0); | |
294 | invalidList2.append(0); |
|
250 | invalidList2.append(0); | |
295 | invalidList2.append(0); |
|
251 | invalidList2.append(0); | |
296 | ret = m_barseries->append(invalidList2); |
|
252 | ret = m_barseries->append(invalidList2); | |
297 | QVERIFY(ret == false); |
|
253 | QVERIFY(ret == false); | |
298 | QVERIFY(m_barseries->barsetCount() == count); |
|
254 | QVERIFY(m_barseries->barsetCount() == count); | |
299 | } |
|
255 | } | |
300 |
|
256 | |||
301 | void tst_QBarSeries::removeList_data() |
|
257 | void tst_QBarSeries::removeList_data() | |
302 | { |
|
258 | { | |
303 |
|
259 | |||
304 | } |
|
260 | } | |
305 |
|
261 | |||
306 | void tst_QBarSeries::removeList() |
|
262 | void tst_QBarSeries::removeList() | |
307 | { |
|
263 | { | |
308 | int count = m_testSets.count(); |
|
264 | int count = m_testSets.count(); | |
309 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
265 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
310 |
|
266 | |||
311 | // Try removing empty list of sets (should return false, since no barsets were removed) |
|
267 | // Try removing empty list of sets (should return false, since no barsets were removed) | |
312 | bool ret = false; |
|
268 | bool ret = false; | |
313 | QList<QBarSet*> invalidList; |
|
269 | QList<QBarSet*> invalidList; | |
314 | ret = m_barseries_with_sets->remove(invalidList); |
|
270 | ret = m_barseries_with_sets->remove(invalidList); | |
315 | QVERIFY(ret == false); |
|
271 | QVERIFY(ret == false); | |
316 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
272 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
317 |
|
273 | |||
318 | // Add some null pointers to list |
|
274 | // Add some null pointers to list | |
319 | invalidList.append(0); |
|
275 | invalidList.append(0); | |
320 | invalidList.append(0); |
|
276 | invalidList.append(0); | |
321 | invalidList.append(0); |
|
277 | invalidList.append(0); | |
322 |
|
278 | |||
323 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) |
|
279 | // Try removing null pointers from list (should return false, should not crash, should not remove anything) | |
324 | ret = m_barseries_with_sets->remove(invalidList); |
|
280 | ret = m_barseries_with_sets->remove(invalidList); | |
325 | QVERIFY(ret == false); |
|
281 | QVERIFY(ret == false); | |
326 | QVERIFY(m_barseries_with_sets->barsetCount() == count); |
|
282 | QVERIFY(m_barseries_with_sets->barsetCount() == count); | |
327 |
|
283 | |||
328 | // remove all sets (should return true, since sets were removed) |
|
284 | // remove all sets (should return true, since sets were removed) | |
329 | ret = m_barseries_with_sets->remove(m_testSets); |
|
285 | ret = m_barseries_with_sets->remove(m_testSets); | |
330 | QVERIFY(ret == true); |
|
286 | QVERIFY(ret == true); | |
331 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
287 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
332 |
|
288 | |||
333 | // Try removing invalid list again (should return false, since no barsets were removed) |
|
289 | // Try removing invalid list again (should return false, since no barsets were removed) | |
334 | ret = m_barseries_with_sets->remove(invalidList); |
|
290 | ret = m_barseries_with_sets->remove(invalidList); | |
335 | QVERIFY(ret == false); |
|
291 | QVERIFY(ret == false); | |
336 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
292 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
337 |
|
293 | |||
338 | // remove all sets again (should return false, since barsets were already removed) |
|
294 | // remove all sets again (should return false, since barsets were already removed) | |
339 | ret = m_barseries_with_sets->remove(m_testSets); |
|
295 | ret = m_barseries_with_sets->remove(m_testSets); | |
340 | QVERIFY(ret == false); |
|
296 | QVERIFY(ret == false); | |
341 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); |
|
297 | QVERIFY(m_barseries_with_sets->barsetCount() == 0); | |
342 | } |
|
298 | } | |
343 |
|
299 | |||
344 | void tst_QBarSeries::barsetCount_data() |
|
300 | void tst_QBarSeries::barsetCount_data() | |
345 | { |
|
301 | { | |
346 |
|
302 | |||
347 | } |
|
303 | } | |
348 |
|
304 | |||
349 | void tst_QBarSeries::barsetCount() |
|
305 | void tst_QBarSeries::barsetCount() | |
350 | { |
|
306 | { | |
351 | QVERIFY(m_barseries->barsetCount() == 0); |
|
307 | QVERIFY(m_barseries->barsetCount() == 0); | |
352 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); |
|
308 | QVERIFY(m_barseries_with_sets->barsetCount() == m_testSets.count()); | |
353 | } |
|
309 | } | |
354 |
|
310 | |||
355 | void tst_QBarSeries::categoryCount_data() |
|
|||
356 | { |
|
|||
357 |
|
||||
358 | } |
|
|||
359 |
|
||||
360 | void tst_QBarSeries::categoryCount() |
|
|||
361 | { |
|
|||
362 | QVERIFY(m_barseries->categoryCount() == m_categories.count()); |
|
|||
363 | QVERIFY(m_barseries_with_sets->categoryCount() == m_categories.count()); |
|
|||
364 | } |
|
|||
365 |
|
||||
366 | void tst_QBarSeries::barSets_data() |
|
311 | void tst_QBarSeries::barSets_data() | |
367 | { |
|
312 | { | |
368 |
|
313 | |||
369 | } |
|
314 | } | |
370 |
|
315 | |||
371 | void tst_QBarSeries::barSets() |
|
316 | void tst_QBarSeries::barSets() | |
372 | { |
|
317 | { | |
373 | QVERIFY(m_barseries->barSets().count() == 0); |
|
318 | QVERIFY(m_barseries->barSets().count() == 0); | |
374 |
|
319 | |||
375 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
320 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
376 | QVERIFY(sets.count() == m_testSets.count()); |
|
321 | QVERIFY(sets.count() == m_testSets.count()); | |
377 |
|
322 | |||
378 | for (int i=0; i<m_testSets.count(); i++) { |
|
323 | for (int i=0; i<m_testSets.count(); i++) { | |
379 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
324 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
380 | } |
|
325 | } | |
381 | } |
|
326 | } | |
382 |
|
327 | |||
383 | void tst_QBarSeries::categories_data() |
|
|||
384 | { |
|
|||
385 |
|
||||
386 | } |
|
|||
387 |
|
||||
388 | void tst_QBarSeries::categories() |
|
|||
389 | { |
|
|||
390 | QBarCategories categories = m_barseries->categories(); |
|
|||
391 |
|
||||
392 | QVERIFY(categories.count() == m_categories.count()); |
|
|||
393 | for (int i=0; i<m_categories.count(); i++) { |
|
|||
394 | QVERIFY(categories.at(i).compare(m_categories.at(i)) == 0); |
|
|||
395 | } |
|
|||
396 | } |
|
|||
397 |
|
||||
398 | void tst_QBarSeries::setLabelsVisible_data() |
|
328 | void tst_QBarSeries::setLabelsVisible_data() | |
399 | { |
|
329 | { | |
400 |
|
330 | |||
401 | } |
|
331 | } | |
402 |
|
332 | |||
403 | void tst_QBarSeries::setLabelsVisible() |
|
333 | void tst_QBarSeries::setLabelsVisible() | |
404 | { |
|
334 | { | |
405 | // labels should be invisible by default |
|
335 | // labels should be invisible by default | |
406 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
336 | QVERIFY(m_barseries->isLabelsVisible() == false); | |
407 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
337 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
408 |
|
338 | |||
409 | // turn labels to visible |
|
339 | // turn labels to visible | |
410 | m_barseries_with_sets->setLabelsVisible(true); |
|
340 | m_barseries_with_sets->setLabelsVisible(true); | |
411 | // TODO: test the signal |
|
341 | // TODO: test the signal | |
412 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
342 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
413 |
|
343 | |||
414 | // turn labels to invisible |
|
344 | // turn labels to invisible | |
415 | m_barseries_with_sets->setLabelsVisible(false); |
|
345 | m_barseries_with_sets->setLabelsVisible(false); | |
416 | // TODO: test the signal |
|
346 | // TODO: test the signal | |
417 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
347 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
418 |
|
348 | |||
419 | // without parameter, should turn labels to visible |
|
349 | // without parameter, should turn labels to visible | |
420 | m_barseries_with_sets->setLabelsVisible(); |
|
350 | m_barseries_with_sets->setLabelsVisible(); | |
421 | // TODO: test the signal |
|
351 | // TODO: test the signal | |
422 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
352 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
423 | } |
|
353 | } | |
424 |
|
354 | |||
425 | void tst_QBarSeries::mouseclicked_data() |
|
355 | void tst_QBarSeries::mouseclicked_data() | |
426 | { |
|
356 | { | |
427 |
|
357 | |||
428 | } |
|
358 | } | |
429 |
|
359 | |||
430 | void tst_QBarSeries::mouseclicked() |
|
360 | void tst_QBarSeries::mouseclicked() | |
431 | { |
|
361 | { | |
432 | QBarSeries* series = new QBarSeries(); |
|
362 | QBarSeries* series = new QBarSeries(); | |
433 | QBarCategories categories; |
|
|||
434 | categories << "test1" << "test2" << "test3"; |
|
|||
435 | series->setCategories(categories); |
|
|||
436 |
|
363 | |||
437 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
364 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
438 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
365 | *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
439 | series->append(set1); |
|
366 | series->append(set1); | |
440 |
|
367 | |||
441 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
368 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
442 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
369 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
443 | series->append(set2); |
|
370 | series->append(set2); | |
444 |
|
371 | |||
445 |
QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*, |
|
372 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int))); | |
446 |
|
373 | |||
447 | QChartView view(new QChart()); |
|
374 | QChartView view(new QChart()); | |
448 | view.resize(400,300); |
|
375 | view.resize(400,300); | |
449 | view.chart()->addSeries(series); |
|
376 | view.chart()->addSeries(series); | |
450 | view.show(); |
|
377 | view.show(); | |
451 | QTest::qWaitForWindowShown(&view); |
|
378 | QTest::qWaitForWindowShown(&view); | |
452 |
|
379 | |||
453 | //==================================================================================== |
|
380 | //==================================================================================== | |
454 | // barset 1, category test1 |
|
381 | // barset 1, category test1 | |
455 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,142)); |
|
382 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,142)); | |
456 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
383 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
457 |
|
384 | |||
458 | QCOMPARE(seriesSpy.count(), 1); |
|
385 | QCOMPARE(seriesSpy.count(), 1); | |
459 |
|
386 | |||
460 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
387 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
461 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
388 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
462 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
389 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
463 |
QVERIFY(seriesSpyArg.at(1).to |
|
390 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |
464 |
|
391 | |||
465 | //==================================================================================== |
|
392 | //==================================================================================== | |
466 | // barset 1, category test2 |
|
393 | // barset 1, category test2 | |
467 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,142)); |
|
394 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,142)); | |
468 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
395 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
469 |
|
396 | |||
470 | QCOMPARE(seriesSpy.count(), 1); |
|
397 | QCOMPARE(seriesSpy.count(), 1); | |
471 |
|
398 | |||
472 | seriesSpyArg = seriesSpy.takeFirst(); |
|
399 | seriesSpyArg = seriesSpy.takeFirst(); | |
473 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
400 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
474 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
401 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
475 |
QVERIFY(seriesSpyArg.at(1).to |
|
402 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |
476 |
|
403 | |||
477 | //==================================================================================== |
|
404 | //==================================================================================== | |
478 | // barset 1, category test3 |
|
405 | // barset 1, category test3 | |
479 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(291,142)); |
|
406 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(291,142)); | |
480 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
407 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
481 |
|
408 | |||
482 | QCOMPARE(seriesSpy.count(), 1); |
|
409 | QCOMPARE(seriesSpy.count(), 1); | |
483 |
|
410 | |||
484 | seriesSpyArg = seriesSpy.takeFirst(); |
|
411 | seriesSpyArg = seriesSpy.takeFirst(); | |
485 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
412 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
486 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
413 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
487 |
QVERIFY(seriesSpyArg.at(1).to |
|
414 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |
488 |
|
415 | |||
489 | //==================================================================================== |
|
416 | //==================================================================================== | |
490 | // barset 2, category test1 |
|
417 | // barset 2, category test1 | |
491 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(134,142)); |
|
418 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(134,142)); | |
492 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
419 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
493 |
|
420 | |||
494 | QCOMPARE(seriesSpy.count(), 1); |
|
421 | QCOMPARE(seriesSpy.count(), 1); | |
495 |
|
422 | |||
496 | seriesSpyArg = seriesSpy.takeFirst(); |
|
423 | seriesSpyArg = seriesSpy.takeFirst(); | |
497 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
424 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
498 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
425 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
499 |
QVERIFY(seriesSpyArg.at(1).to |
|
426 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |
500 |
|
427 | |||
501 | //==================================================================================== |
|
428 | //==================================================================================== | |
502 | // barset 2, category test2 |
|
429 | // barset 2, category test2 | |
503 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(227,142)); |
|
430 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(227,142)); | |
504 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
431 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
505 |
|
432 | |||
506 | QCOMPARE(seriesSpy.count(), 1); |
|
433 | QCOMPARE(seriesSpy.count(), 1); | |
507 |
|
434 | |||
508 | seriesSpyArg = seriesSpy.takeFirst(); |
|
435 | seriesSpyArg = seriesSpy.takeFirst(); | |
509 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
436 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
510 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
437 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
511 |
QVERIFY(seriesSpyArg.at(1).to |
|
438 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |
512 |
|
439 | |||
513 | //==================================================================================== |
|
440 | //==================================================================================== | |
514 | // barset 2, category test3 |
|
441 | // barset 2, category test3 | |
515 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(319,142)); |
|
442 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(319,142)); | |
516 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
443 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
517 |
|
444 | |||
518 | QCOMPARE(seriesSpy.count(), 1); |
|
445 | QCOMPARE(seriesSpy.count(), 1); | |
519 |
|
446 | |||
520 | seriesSpyArg = seriesSpy.takeFirst(); |
|
447 | seriesSpyArg = seriesSpy.takeFirst(); | |
521 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
448 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
522 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
449 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
523 |
QVERIFY(seriesSpyArg.at(1).to |
|
450 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |
524 | } |
|
451 | } | |
525 |
|
452 | |||
526 | void tst_QBarSeries::mousehovered_data() |
|
453 | void tst_QBarSeries::mousehovered_data() | |
527 | { |
|
454 | { | |
528 |
|
455 | |||
529 | } |
|
456 | } | |
530 |
|
457 | |||
531 | void tst_QBarSeries::mousehovered() |
|
458 | void tst_QBarSeries::mousehovered() | |
532 | { |
|
459 | { | |
533 | QBarSeries* series = new QBarSeries(); |
|
460 | QBarSeries* series = new QBarSeries(); | |
534 |
Q |
|
461 | QStringList categories; | |
535 | categories << "test1" << "test2" << "test3"; |
|
462 | categories << "test1" << "test2" << "test3"; | |
536 | series->setCategories(categories); |
|
463 | // series->setCategories(categories); | |
537 |
|
464 | |||
538 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
465 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
539 | *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10); |
|
466 | *set1 << QPointF(0.1,10) << QPointF(1.1,10) << QPointF(2.1,10); | |
540 | series->append(set1); |
|
467 | series->append(set1); | |
541 |
|
468 | |||
542 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
469 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
543 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
470 | *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
544 | series->append(set2); |
|
471 | series->append(set2); | |
545 |
|
472 | |||
546 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); |
|
473 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); | |
547 |
|
474 | |||
548 | QChartView view(new QChart()); |
|
475 | QChartView view(new QChart()); | |
549 | view.resize(400,300); |
|
476 | view.resize(400,300); | |
550 | view.chart()->addSeries(series); |
|
477 | view.chart()->addSeries(series); | |
551 | view.show(); |
|
478 | view.show(); | |
552 | QTest::qWaitForWindowShown(&view); |
|
479 | QTest::qWaitForWindowShown(&view); | |
553 |
|
480 | |||
554 | //this is hack since view does not get events otherwise |
|
481 | //this is hack since view does not get events otherwise | |
555 | view.setMouseTracking(true); |
|
482 | view.setMouseTracking(true); | |
556 |
|
483 | |||
557 | //======================================================================= |
|
484 | //======================================================================= | |
558 | // move mouse to left border |
|
485 | // move mouse to left border | |
559 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); |
|
486 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); | |
560 |
|
487 | |||
561 | QVERIFY(seriesSpy.count() == 0); |
|
488 | QVERIFY(seriesSpy.count() == 0); | |
562 |
|
489 | |||
563 | //======================================================================= |
|
490 | //======================================================================= | |
564 | // move mouse on top of set1 |
|
491 | // move mouse on top of set1 | |
565 | QTest::mouseMove(view.viewport(), QPoint(106,142)); |
|
492 | QTest::mouseMove(view.viewport(), QPoint(106,142)); | |
566 |
|
493 | |||
567 | QVERIFY(seriesSpy.count() == 1); |
|
494 | QVERIFY(seriesSpy.count() == 1); | |
568 |
|
495 | |||
569 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
496 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
570 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
497 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
571 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
498 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
572 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
499 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
573 |
|
500 | |||
574 | //======================================================================= |
|
501 | //======================================================================= | |
575 | // move mouse from top of set1 to top of set2 |
|
502 | // move mouse from top of set1 to top of set2 | |
576 | QTest::mouseMove(view.viewport(), QPoint(134,142)); |
|
503 | QTest::mouseMove(view.viewport(), QPoint(134,142)); | |
577 |
|
504 | |||
578 | QVERIFY(seriesSpy.count() == 2); |
|
505 | QVERIFY(seriesSpy.count() == 2); | |
579 |
|
506 | |||
580 | // should leave set1 |
|
507 | // should leave set1 | |
581 | seriesSpyArg = seriesSpy.takeFirst(); |
|
508 | seriesSpyArg = seriesSpy.takeFirst(); | |
582 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
509 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
583 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
510 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
584 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
511 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
585 |
|
512 | |||
586 | // should enter set2 |
|
513 | // should enter set2 | |
587 | seriesSpyArg = seriesSpy.takeFirst(); |
|
514 | seriesSpyArg = seriesSpy.takeFirst(); | |
588 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
515 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
589 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
516 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
590 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
517 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
591 |
|
518 | |||
592 | //======================================================================= |
|
519 | //======================================================================= | |
593 | // move mouse from top of set2 to background |
|
520 | // move mouse from top of set2 to background | |
594 | QTest::mouseMove(view.viewport(), QPoint(134,0)); |
|
521 | QTest::mouseMove(view.viewport(), QPoint(134,0)); | |
595 | QVERIFY(seriesSpy.count() == 1); |
|
522 | QVERIFY(seriesSpy.count() == 1); | |
596 |
|
523 | |||
597 | // should leave set2 |
|
524 | // should leave set2 | |
598 | seriesSpyArg = seriesSpy.takeFirst(); |
|
525 | seriesSpyArg = seriesSpy.takeFirst(); | |
599 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
526 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
600 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
527 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
601 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
528 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
602 | } |
|
529 | } | |
603 |
|
530 | |||
604 | QTEST_MAIN(tst_QBarSeries) |
|
531 | QTEST_MAIN(tst_QBarSeries) | |
605 |
|
532 | |||
606 | #include "tst_qbarseries.moc" |
|
533 | #include "tst_qbarseries.moc" | |
607 |
|
534 |
@@ -1,598 +1,591 | |||||
1 | #include <QtTest/QtTest> |
|
1 | #include <QtTest/QtTest> | |
2 | #include <qchartview.h> |
|
2 | #include <qchartview.h> | |
3 | #include <qlineseries.h> |
|
3 | #include <qlineseries.h> | |
4 | #include <qareaseries.h> |
|
4 | #include <qareaseries.h> | |
5 | #include <qscatterseries.h> |
|
5 | #include <qscatterseries.h> | |
6 | #include <qsplineseries.h> |
|
6 | #include <qsplineseries.h> | |
7 | #include <qpieseries.h> |
|
7 | #include <qpieseries.h> | |
8 | #include <qbarseries.h> |
|
8 | #include <qbarseries.h> | |
9 | #include <qpercentbarseries.h> |
|
9 | #include <qpercentbarseries.h> | |
10 | #include <qstackedbarseries.h> |
|
10 | #include <qstackedbarseries.h> | |
11 |
|
11 | |||
12 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
12 | QTCOMMERCIALCHART_USE_NAMESPACE | |
13 |
|
13 | |||
14 | Q_DECLARE_METATYPE(QAxis *) |
|
14 | Q_DECLARE_METATYPE(QAxis *) | |
15 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
15 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
16 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
17 | Q_DECLARE_METATYPE(QBrush) |
|
17 | Q_DECLARE_METATYPE(QBrush) | |
18 | Q_DECLARE_METATYPE(QPen) |
|
18 | Q_DECLARE_METATYPE(QPen) | |
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
19 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
20 |
|
20 | |||
21 | class tst_QChart : public QObject |
|
21 | class tst_QChart : public QObject | |
22 | { |
|
22 | { | |
23 | Q_OBJECT |
|
23 | Q_OBJECT | |
24 |
|
24 | |||
25 | public slots: |
|
25 | public slots: | |
26 | void initTestCase(); |
|
26 | void initTestCase(); | |
27 | void cleanupTestCase(); |
|
27 | void cleanupTestCase(); | |
28 | void init(); |
|
28 | void init(); | |
29 | void cleanup(); |
|
29 | void cleanup(); | |
30 |
|
30 | |||
31 | private slots: |
|
31 | private slots: | |
32 | void qchart_data(); |
|
32 | void qchart_data(); | |
33 | void qchart(); |
|
33 | void qchart(); | |
34 |
|
34 | |||
35 | void addSeries_data(); |
|
35 | void addSeries_data(); | |
36 | void addSeries(); |
|
36 | void addSeries(); | |
37 | void animationOptions_data(); |
|
37 | void animationOptions_data(); | |
38 | void animationOptions(); |
|
38 | void animationOptions(); | |
39 | void axisX_data(); |
|
39 | void axisX_data(); | |
40 | void axisX(); |
|
40 | void axisX(); | |
41 | void axisY_data(); |
|
41 | void axisY_data(); | |
42 | void axisY(); |
|
42 | void axisY(); | |
43 | void backgroundBrush_data(); |
|
43 | void backgroundBrush_data(); | |
44 | void backgroundBrush(); |
|
44 | void backgroundBrush(); | |
45 | void backgroundPen_data(); |
|
45 | void backgroundPen_data(); | |
46 | void backgroundPen(); |
|
46 | void backgroundPen(); | |
47 | void isBackgroundVisible_data(); |
|
47 | void isBackgroundVisible_data(); | |
48 | void isBackgroundVisible(); |
|
48 | void isBackgroundVisible(); | |
49 | void legend_data(); |
|
49 | void legend_data(); | |
50 | void legend(); |
|
50 | void legend(); | |
51 | void margins_data(); |
|
51 | void margins_data(); | |
52 | void margins(); |
|
52 | void margins(); | |
53 | void removeAllSeries_data(); |
|
53 | void removeAllSeries_data(); | |
54 | void removeAllSeries(); |
|
54 | void removeAllSeries(); | |
55 | void removeSeries_data(); |
|
55 | void removeSeries_data(); | |
56 | void removeSeries(); |
|
56 | void removeSeries(); | |
57 | void scrollDown_data(); |
|
57 | void scrollDown_data(); | |
58 | void scrollDown(); |
|
58 | void scrollDown(); | |
59 | void scrollLeft_data(); |
|
59 | void scrollLeft_data(); | |
60 | void scrollLeft(); |
|
60 | void scrollLeft(); | |
61 | void scrollRight_data(); |
|
61 | void scrollRight_data(); | |
62 | void scrollRight(); |
|
62 | void scrollRight(); | |
63 | void scrollUp_data(); |
|
63 | void scrollUp_data(); | |
64 | void scrollUp(); |
|
64 | void scrollUp(); | |
65 | void theme_data(); |
|
65 | void theme_data(); | |
66 | void theme(); |
|
66 | void theme(); | |
67 | void title_data(); |
|
67 | void title_data(); | |
68 | void title(); |
|
68 | void title(); | |
69 | void titleBrush_data(); |
|
69 | void titleBrush_data(); | |
70 | void titleBrush(); |
|
70 | void titleBrush(); | |
71 | void titleFont_data(); |
|
71 | void titleFont_data(); | |
72 | void titleFont(); |
|
72 | void titleFont(); | |
73 | void zoomIn_data(); |
|
73 | void zoomIn_data(); | |
74 | void zoomIn(); |
|
74 | void zoomIn(); | |
75 | void zoomOut_data(); |
|
75 | void zoomOut_data(); | |
76 | void zoomOut(); |
|
76 | void zoomOut(); | |
77 |
|
77 | |||
78 | private: |
|
78 | private: | |
79 | void createTestData(); |
|
79 | void createTestData(); | |
80 |
|
80 | |||
81 | private: |
|
81 | private: | |
82 | QChartView* m_view; |
|
82 | QChartView* m_view; | |
83 | QChart* m_chart; |
|
83 | QChart* m_chart; | |
84 | }; |
|
84 | }; | |
85 |
|
85 | |||
86 | void tst_QChart::initTestCase() |
|
86 | void tst_QChart::initTestCase() | |
87 | { |
|
87 | { | |
88 |
|
88 | |||
89 | } |
|
89 | } | |
90 |
|
90 | |||
91 | void tst_QChart::cleanupTestCase() |
|
91 | void tst_QChart::cleanupTestCase() | |
92 | { |
|
92 | { | |
93 |
|
93 | |||
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void tst_QChart::init() |
|
96 | void tst_QChart::init() | |
97 | { |
|
97 | { | |
98 | m_view = new QChartView(new QChart()); |
|
98 | m_view = new QChartView(new QChart()); | |
99 | m_chart = m_view->chart(); |
|
99 | m_chart = m_view->chart(); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void tst_QChart::createTestData() |
|
102 | void tst_QChart::createTestData() | |
103 | { |
|
103 | { | |
104 | QLineSeries* series0 = new QLineSeries(this); |
|
104 | QLineSeries* series0 = new QLineSeries(this); | |
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
105 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
106 | m_chart->addSeries(series0); |
|
106 | m_chart->addSeries(series0); | |
107 | m_view->show(); |
|
107 | m_view->show(); | |
108 | QTest::qWaitForWindowShown(m_view); |
|
108 | QTest::qWaitForWindowShown(m_view); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void tst_QChart::cleanup() |
|
111 | void tst_QChart::cleanup() | |
112 | { |
|
112 | { | |
113 | delete m_view; |
|
113 | delete m_view; | |
114 | m_view = 0; |
|
114 | m_view = 0; | |
115 | m_chart = 0; |
|
115 | m_chart = 0; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void tst_QChart::qchart_data() |
|
118 | void tst_QChart::qchart_data() | |
119 | { |
|
119 | { | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_QChart::qchart() |
|
122 | void tst_QChart::qchart() | |
123 | { |
|
123 | { | |
124 | QVERIFY(m_chart); |
|
124 | QVERIFY(m_chart); | |
125 | QVERIFY(m_chart->legend()); |
|
125 | QVERIFY(m_chart->legend()); | |
126 | QVERIFY(m_chart->legend()->isVisible()); |
|
126 | QVERIFY(m_chart->legend()->isVisible()); | |
127 |
|
127 | |||
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
128 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
129 | QVERIFY(m_chart->axisX()); |
|
129 | QVERIFY(m_chart->axisX()); | |
130 | QVERIFY(m_chart->axisY()); |
|
130 | QVERIFY(m_chart->axisY()); | |
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
131 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
132 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
133 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
134 |
|
134 | |||
135 | QVERIFY(m_chart->margins().top()>0); |
|
135 | QVERIFY(m_chart->margins().top()>0); | |
136 | QVERIFY(m_chart->margins().left()>0); |
|
136 | QVERIFY(m_chart->margins().left()>0); | |
137 | QVERIFY(m_chart->margins().right()>0); |
|
137 | QVERIFY(m_chart->margins().right()>0); | |
138 | QVERIFY(m_chart->margins().bottom()>0); |
|
138 | QVERIFY(m_chart->margins().bottom()>0); | |
139 |
|
139 | |||
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
140 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
141 | QCOMPARE(m_chart->title(), QString()); |
|
141 | QCOMPARE(m_chart->title(), QString()); | |
142 |
|
142 | |||
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
143 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
144 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
144 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
145 |
|
145 | |||
146 | m_chart->removeAllSeries(); |
|
146 | m_chart->removeAllSeries(); | |
147 | m_chart->scrollDown(); |
|
147 | m_chart->scrollDown(); | |
148 | m_chart->scrollLeft(); |
|
148 | m_chart->scrollLeft(); | |
149 | m_chart->scrollRight(); |
|
149 | m_chart->scrollRight(); | |
150 | m_chart->scrollUp(); |
|
150 | m_chart->scrollUp(); | |
151 |
|
151 | |||
152 | m_chart->zoomIn(); |
|
152 | m_chart->zoomIn(); | |
153 | m_chart->zoomIn(QRectF()); |
|
153 | m_chart->zoomIn(QRectF()); | |
154 | m_chart->zoomOut(); |
|
154 | m_chart->zoomOut(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void tst_QChart::addSeries_data() |
|
157 | void tst_QChart::addSeries_data() | |
158 | { |
|
158 | { | |
159 | QTest::addColumn<QAbstractSeries *>("series"); |
|
159 | QTest::addColumn<QAbstractSeries *>("series"); | |
160 | QTest::addColumn<QAxis *>("axis"); |
|
160 | QTest::addColumn<QAxis *>("axis"); | |
161 |
|
161 | |||
162 | QAbstractSeries* series0 = new QLineSeries(this); |
|
162 | QAbstractSeries* series0 = new QLineSeries(this); | |
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
163 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); | |
164 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
164 | QAbstractSeries* series2 = new QScatterSeries(this); | |
165 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
165 | QAbstractSeries* series3 = new QSplineSeries(this); | |
166 | QAbstractSeries* series4 = new QPieSeries(this); |
|
166 | QAbstractSeries* series4 = new QPieSeries(this); | |
167 | QAbstractSeries* series5 = new QBarSeries(this); |
|
167 | QAbstractSeries* series5 = new QBarSeries(this); | |
168 | QAbstractSeries* series6 = new QPercentBarSeries(this); |
|
168 | QAbstractSeries* series6 = new QPercentBarSeries(this); | |
169 | QAbstractSeries* series7 = new QStackedBarSeries(this); |
|
169 | QAbstractSeries* series7 = new QStackedBarSeries(this); | |
170 |
|
170 | |||
171 | QBarSeries* s5 = static_cast<QBarSeries*> (series5); |
|
|||
172 | s5->setCategories(QBarCategories()); |
|
|||
173 | QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6); |
|
|||
174 | s6->setCategories(QBarCategories()); |
|
|||
175 | QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7); |
|
|||
176 | s7->setCategories(QBarCategories()); |
|
|||
177 |
|
||||
178 | QAxis* axis = new QAxis(this); |
|
171 | QAxis* axis = new QAxis(this); | |
179 |
|
172 | |||
180 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; |
|
173 | QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0; | |
181 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
174 | QTest::newRow("axis0: lineSeries") << series0 << axis; | |
182 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; |
|
175 | QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0; | |
183 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
176 | QTest::newRow("axis: areaSeries") << series1 << axis; | |
184 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; |
|
177 | QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0; | |
185 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
178 | QTest::newRow("axis1: scatterSeries") << series2 << axis; | |
186 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; |
|
179 | QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0; | |
187 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
180 | QTest::newRow("axis: splineSeries") << series3 << axis; | |
188 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; |
|
181 | QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0; | |
189 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
182 | QTest::newRow("axis: pieSeries") << series4 << axis; | |
190 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; |
|
183 | QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0; | |
191 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
184 | QTest::newRow("axis: barSeries") << series5 << axis; | |
192 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; |
|
185 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0; | |
193 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
186 | QTest::newRow("axis: barSeries") << series6 << axis; | |
194 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; |
|
187 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0; | |
195 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
188 | QTest::newRow("axis: barSeries") << series7 << axis; | |
196 |
|
189 | |||
197 | } |
|
190 | } | |
198 |
|
191 | |||
199 | void tst_QChart::addSeries() |
|
192 | void tst_QChart::addSeries() | |
200 | { |
|
193 | { | |
201 | QFETCH(QAbstractSeries *, series); |
|
194 | QFETCH(QAbstractSeries *, series); | |
202 | QFETCH(QAxis *, axis); |
|
195 | QFETCH(QAxis *, axis); | |
203 | m_view->show(); |
|
196 | m_view->show(); | |
204 | QTest::qWaitForWindowShown(m_view); |
|
197 | QTest::qWaitForWindowShown(m_view); | |
205 | if(!axis) axis = m_chart->axisY(); |
|
198 | if(!axis) axis = m_chart->axisY(); | |
206 | QVERIFY(!series->chart()); |
|
199 | QVERIFY(!series->chart()); | |
207 | QCOMPARE(m_chart->series().count(), 0); |
|
200 | QCOMPARE(m_chart->series().count(), 0); | |
208 | m_chart->addSeries(series,axis); |
|
201 | m_chart->addSeries(series,axis); | |
209 | QCOMPARE(m_chart->series().count(), 1); |
|
202 | QCOMPARE(m_chart->series().count(), 1); | |
210 | QCOMPARE(m_chart->series().first(), series); |
|
203 | QCOMPARE(m_chart->series().first(), series); | |
211 | QVERIFY(series->chart() == m_chart); |
|
204 | QVERIFY(series->chart() == m_chart); | |
212 | QCOMPARE(m_chart->axisY(series),axis); |
|
205 | QCOMPARE(m_chart->axisY(series),axis); | |
213 | m_chart->removeSeries(series); |
|
206 | m_chart->removeSeries(series); | |
214 | QVERIFY(!series->chart()); |
|
207 | QVERIFY(!series->chart()); | |
215 | QCOMPARE(m_chart->series().count(), 0); |
|
208 | QCOMPARE(m_chart->series().count(), 0); | |
216 | } |
|
209 | } | |
217 |
|
210 | |||
218 | void tst_QChart::animationOptions_data() |
|
211 | void tst_QChart::animationOptions_data() | |
219 | { |
|
212 | { | |
220 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
213 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
221 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
214 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
222 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
215 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
223 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
216 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
224 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
217 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
225 | } |
|
218 | } | |
226 |
|
219 | |||
227 | void tst_QChart::animationOptions() |
|
220 | void tst_QChart::animationOptions() | |
228 | { |
|
221 | { | |
229 | createTestData(); |
|
222 | createTestData(); | |
230 | QFETCH(QChart::AnimationOption, animationOptions); |
|
223 | QFETCH(QChart::AnimationOption, animationOptions); | |
231 | m_chart->setAnimationOptions(animationOptions); |
|
224 | m_chart->setAnimationOptions(animationOptions); | |
232 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
225 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
233 | } |
|
226 | } | |
234 |
|
227 | |||
235 | void tst_QChart::axisX_data() |
|
228 | void tst_QChart::axisX_data() | |
236 | { |
|
229 | { | |
237 |
|
230 | |||
238 | } |
|
231 | } | |
239 |
|
232 | |||
240 | void tst_QChart::axisX() |
|
233 | void tst_QChart::axisX() | |
241 | { |
|
234 | { | |
242 | QVERIFY(m_chart->axisX()); |
|
235 | QVERIFY(m_chart->axisX()); | |
243 | QAxis* axis = m_chart->axisX(); |
|
236 | QAxis* axis = m_chart->axisX(); | |
244 | createTestData(); |
|
237 | createTestData(); | |
245 | //it should be the same axis |
|
238 | //it should be the same axis | |
246 | QCOMPARE(axis,m_chart->axisX()); |
|
239 | QCOMPARE(axis,m_chart->axisX()); | |
247 | } |
|
240 | } | |
248 |
|
241 | |||
249 | void tst_QChart::axisY_data() |
|
242 | void tst_QChart::axisY_data() | |
250 | { |
|
243 | { | |
251 | QTest::addColumn<QAxis*>("axis0"); |
|
244 | QTest::addColumn<QAxis*>("axis0"); | |
252 | QTest::addColumn<QAxis*>("axis1"); |
|
245 | QTest::addColumn<QAxis*>("axis1"); | |
253 | QTest::addColumn<QAxis*>("axis2"); |
|
246 | QTest::addColumn<QAxis*>("axis2"); | |
254 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); |
|
247 | QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis(); | |
255 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); |
|
248 | QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis(); | |
256 | } |
|
249 | } | |
257 |
|
250 | |||
258 |
|
251 | |||
259 | void tst_QChart::axisY() |
|
252 | void tst_QChart::axisY() | |
260 | { |
|
253 | { | |
261 | QFETCH(QAxis*, axis0); |
|
254 | QFETCH(QAxis*, axis0); | |
262 | QFETCH(QAxis*, axis1); |
|
255 | QFETCH(QAxis*, axis1); | |
263 | QFETCH(QAxis*, axis2); |
|
256 | QFETCH(QAxis*, axis2); | |
264 |
|
257 | |||
265 | QAxis* defaultAxisY = m_chart->axisY(); |
|
258 | QAxis* defaultAxisY = m_chart->axisY(); | |
266 |
|
259 | |||
267 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
260 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
268 |
|
261 | |||
269 | QLineSeries* series0 = new QLineSeries(); |
|
262 | QLineSeries* series0 = new QLineSeries(); | |
270 | m_chart->addSeries(series0, axis0); |
|
263 | m_chart->addSeries(series0, axis0); | |
271 |
|
264 | |||
272 | QLineSeries* series1 = new QLineSeries(); |
|
265 | QLineSeries* series1 = new QLineSeries(); | |
273 | m_chart->addSeries(series1, axis1); |
|
266 | m_chart->addSeries(series1, axis1); | |
274 |
|
267 | |||
275 | QLineSeries* series2 = new QLineSeries(); |
|
268 | QLineSeries* series2 = new QLineSeries(); | |
276 | m_chart->addSeries(series2, axis2); |
|
269 | m_chart->addSeries(series2, axis2); | |
277 |
|
270 | |||
278 | if (!axis0) |
|
271 | if (!axis0) | |
279 | axis0 = defaultAxisY; |
|
272 | axis0 = defaultAxisY; | |
280 | if (!axis1) |
|
273 | if (!axis1) | |
281 | axis1 = defaultAxisY; |
|
274 | axis1 = defaultAxisY; | |
282 | if (!axis2) |
|
275 | if (!axis2) | |
283 | axis2 = defaultAxisY; |
|
276 | axis2 = defaultAxisY; | |
284 |
|
277 | |||
285 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
278 | QVERIFY(m_chart->axisY(series0) == axis0); | |
286 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
279 | QVERIFY(m_chart->axisY(series1) == axis1); | |
287 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
280 | QVERIFY(m_chart->axisY(series2) == axis2); | |
288 | } |
|
281 | } | |
289 |
|
282 | |||
290 | void tst_QChart::backgroundBrush_data() |
|
283 | void tst_QChart::backgroundBrush_data() | |
291 | { |
|
284 | { | |
292 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
285 | QTest::addColumn<QBrush>("backgroundBrush"); | |
293 | QTest::newRow("null") << QBrush(); |
|
286 | QTest::newRow("null") << QBrush(); | |
294 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
287 | QTest::newRow("blue") << QBrush(Qt::blue); | |
295 | QTest::newRow("white") << QBrush(Qt::white); |
|
288 | QTest::newRow("white") << QBrush(Qt::white); | |
296 | QTest::newRow("black") << QBrush(Qt::black); |
|
289 | QTest::newRow("black") << QBrush(Qt::black); | |
297 | } |
|
290 | } | |
298 |
|
291 | |||
299 | void tst_QChart::backgroundBrush() |
|
292 | void tst_QChart::backgroundBrush() | |
300 | { |
|
293 | { | |
301 | QFETCH(QBrush, backgroundBrush); |
|
294 | QFETCH(QBrush, backgroundBrush); | |
302 | m_chart->setBackgroundBrush(backgroundBrush); |
|
295 | m_chart->setBackgroundBrush(backgroundBrush); | |
303 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
296 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
304 | } |
|
297 | } | |
305 |
|
298 | |||
306 | void tst_QChart::backgroundPen_data() |
|
299 | void tst_QChart::backgroundPen_data() | |
307 | { |
|
300 | { | |
308 | QTest::addColumn<QPen>("backgroundPen"); |
|
301 | QTest::addColumn<QPen>("backgroundPen"); | |
309 | QTest::newRow("null") << QPen(); |
|
302 | QTest::newRow("null") << QPen(); | |
310 | QTest::newRow("blue") << QPen(Qt::blue); |
|
303 | QTest::newRow("blue") << QPen(Qt::blue); | |
311 | QTest::newRow("white") << QPen(Qt::white); |
|
304 | QTest::newRow("white") << QPen(Qt::white); | |
312 | QTest::newRow("black") << QPen(Qt::black); |
|
305 | QTest::newRow("black") << QPen(Qt::black); | |
313 | } |
|
306 | } | |
314 |
|
307 | |||
315 |
|
308 | |||
316 | void tst_QChart::backgroundPen() |
|
309 | void tst_QChart::backgroundPen() | |
317 | { |
|
310 | { | |
318 | QFETCH(QPen, backgroundPen); |
|
311 | QFETCH(QPen, backgroundPen); | |
319 | m_chart->setBackgroundPen(backgroundPen); |
|
312 | m_chart->setBackgroundPen(backgroundPen); | |
320 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
313 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
321 | } |
|
314 | } | |
322 |
|
315 | |||
323 | void tst_QChart::isBackgroundVisible_data() |
|
316 | void tst_QChart::isBackgroundVisible_data() | |
324 | { |
|
317 | { | |
325 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
318 | QTest::addColumn<bool>("isBackgroundVisible"); | |
326 | QTest::newRow("true") << true; |
|
319 | QTest::newRow("true") << true; | |
327 | QTest::newRow("false") << false; |
|
320 | QTest::newRow("false") << false; | |
328 | } |
|
321 | } | |
329 |
|
322 | |||
330 | void tst_QChart::isBackgroundVisible() |
|
323 | void tst_QChart::isBackgroundVisible() | |
331 | { |
|
324 | { | |
332 | QFETCH(bool, isBackgroundVisible); |
|
325 | QFETCH(bool, isBackgroundVisible); | |
333 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
326 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
334 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
327 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
335 | } |
|
328 | } | |
336 |
|
329 | |||
337 | void tst_QChart::legend_data() |
|
330 | void tst_QChart::legend_data() | |
338 | { |
|
331 | { | |
339 |
|
332 | |||
340 | } |
|
333 | } | |
341 |
|
334 | |||
342 | void tst_QChart::legend() |
|
335 | void tst_QChart::legend() | |
343 | { |
|
336 | { | |
344 | QVERIFY(m_chart->legend()); |
|
337 | QVERIFY(m_chart->legend()); | |
345 | } |
|
338 | } | |
346 |
|
339 | |||
347 | void tst_QChart::margins_data() |
|
340 | void tst_QChart::margins_data() | |
348 | { |
|
341 | { | |
349 |
|
342 | |||
350 | } |
|
343 | } | |
351 |
|
344 | |||
352 | void tst_QChart::margins() |
|
345 | void tst_QChart::margins() | |
353 | { |
|
346 | { | |
354 | createTestData(); |
|
347 | createTestData(); | |
355 | QRectF rect = m_chart->geometry(); |
|
348 | QRectF rect = m_chart->geometry(); | |
356 |
|
349 | |||
357 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
350 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); | |
358 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
351 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); | |
359 | } |
|
352 | } | |
360 |
|
353 | |||
361 | void tst_QChart::removeAllSeries_data() |
|
354 | void tst_QChart::removeAllSeries_data() | |
362 | { |
|
355 | { | |
363 |
|
356 | |||
364 | } |
|
357 | } | |
365 |
|
358 | |||
366 | void tst_QChart::removeAllSeries() |
|
359 | void tst_QChart::removeAllSeries() | |
367 | { |
|
360 | { | |
368 | QLineSeries* series0 = new QLineSeries(this); |
|
361 | QLineSeries* series0 = new QLineSeries(this); | |
369 | QLineSeries* series1 = new QLineSeries(this); |
|
362 | QLineSeries* series1 = new QLineSeries(this); | |
370 | QLineSeries* series2 = new QLineSeries(this); |
|
363 | QLineSeries* series2 = new QLineSeries(this); | |
371 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
364 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | |
372 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
365 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | |
373 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
366 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | |
374 |
|
367 | |||
375 | m_chart->addSeries(series0); |
|
368 | m_chart->addSeries(series0); | |
376 | m_chart->addSeries(series1); |
|
369 | m_chart->addSeries(series1); | |
377 | m_chart->addSeries(series2); |
|
370 | m_chart->addSeries(series2); | |
378 | m_view->show(); |
|
371 | m_view->show(); | |
379 | QTest::qWaitForWindowShown(m_view); |
|
372 | QTest::qWaitForWindowShown(m_view); | |
380 |
|
373 | |||
381 | QVERIFY(m_chart->axisY(series0)!=0); |
|
374 | QVERIFY(m_chart->axisY(series0)!=0); | |
382 | QVERIFY(m_chart->axisY(series1)!=0); |
|
375 | QVERIFY(m_chart->axisY(series1)!=0); | |
383 | QVERIFY(m_chart->axisY(series2)!=0); |
|
376 | QVERIFY(m_chart->axisY(series2)!=0); | |
384 |
|
377 | |||
385 | m_chart->removeAllSeries(); |
|
378 | m_chart->removeAllSeries(); | |
386 | QVERIFY(m_chart->axisY(series0)==0); |
|
379 | QVERIFY(m_chart->axisY(series0)==0); | |
387 | QVERIFY(m_chart->axisY(series1)==0); |
|
380 | QVERIFY(m_chart->axisY(series1)==0); | |
388 | QVERIFY(m_chart->axisY(series2)==0); |
|
381 | QVERIFY(m_chart->axisY(series2)==0); | |
389 | QCOMPARE(deleteSpy1.count(), 1); |
|
382 | QCOMPARE(deleteSpy1.count(), 1); | |
390 | QCOMPARE(deleteSpy2.count(), 1); |
|
383 | QCOMPARE(deleteSpy2.count(), 1); | |
391 | QCOMPARE(deleteSpy3.count(), 1); |
|
384 | QCOMPARE(deleteSpy3.count(), 1); | |
392 | } |
|
385 | } | |
393 |
|
386 | |||
394 | void tst_QChart::removeSeries_data() |
|
387 | void tst_QChart::removeSeries_data() | |
395 | { |
|
388 | { | |
396 | addSeries_data(); |
|
389 | addSeries_data(); | |
397 | } |
|
390 | } | |
398 |
|
391 | |||
399 | void tst_QChart::removeSeries() |
|
392 | void tst_QChart::removeSeries() | |
400 | { |
|
393 | { | |
401 | QFETCH(QAbstractSeries *, series); |
|
394 | QFETCH(QAbstractSeries *, series); | |
402 | QFETCH(QAxis *, axis); |
|
395 | QFETCH(QAxis *, axis); | |
403 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
396 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | |
404 | m_view->show(); |
|
397 | m_view->show(); | |
405 | QTest::qWaitForWindowShown(m_view); |
|
398 | QTest::qWaitForWindowShown(m_view); | |
406 | if(!axis) axis = m_chart->axisY(); |
|
399 | if(!axis) axis = m_chart->axisY(); | |
407 | m_chart->addSeries(series,axis); |
|
400 | m_chart->addSeries(series,axis); | |
408 | QCOMPARE(m_chart->axisY(series),axis); |
|
401 | QCOMPARE(m_chart->axisY(series),axis); | |
409 | m_chart->removeSeries(series); |
|
402 | m_chart->removeSeries(series); | |
410 | QVERIFY(m_chart->axisY(series)==0); |
|
403 | QVERIFY(m_chart->axisY(series)==0); | |
411 | QCOMPARE(deleteSpy.count(), 0); |
|
404 | QCOMPARE(deleteSpy.count(), 0); | |
412 | } |
|
405 | } | |
413 |
|
406 | |||
414 | void tst_QChart::scrollDown_data() |
|
407 | void tst_QChart::scrollDown_data() | |
415 | { |
|
408 | { | |
416 |
|
409 | |||
417 | } |
|
410 | } | |
418 |
|
411 | |||
419 | void tst_QChart::scrollDown() |
|
412 | void tst_QChart::scrollDown() | |
420 | { |
|
413 | { | |
421 | createTestData(); |
|
414 | createTestData(); | |
422 | qreal min = m_chart->axisY()->min(); |
|
415 | qreal min = m_chart->axisY()->min(); | |
423 | m_chart->scrollDown(); |
|
416 | m_chart->scrollDown(); | |
424 | QVERIFY(m_chart->axisY()->min()<min); |
|
417 | QVERIFY(m_chart->axisY()->min()<min); | |
425 | } |
|
418 | } | |
426 |
|
419 | |||
427 | void tst_QChart::scrollLeft_data() |
|
420 | void tst_QChart::scrollLeft_data() | |
428 | { |
|
421 | { | |
429 |
|
422 | |||
430 | } |
|
423 | } | |
431 |
|
424 | |||
432 | void tst_QChart::scrollLeft() |
|
425 | void tst_QChart::scrollLeft() | |
433 | { |
|
426 | { | |
434 | createTestData(); |
|
427 | createTestData(); | |
435 | qreal min = m_chart->axisX()->min(); |
|
428 | qreal min = m_chart->axisX()->min(); | |
436 | m_chart->scrollLeft(); |
|
429 | m_chart->scrollLeft(); | |
437 | QVERIFY(m_chart->axisX()->min()<min); |
|
430 | QVERIFY(m_chart->axisX()->min()<min); | |
438 | } |
|
431 | } | |
439 |
|
432 | |||
440 | void tst_QChart::scrollRight_data() |
|
433 | void tst_QChart::scrollRight_data() | |
441 | { |
|
434 | { | |
442 |
|
435 | |||
443 | } |
|
436 | } | |
444 |
|
437 | |||
445 | void tst_QChart::scrollRight() |
|
438 | void tst_QChart::scrollRight() | |
446 | { |
|
439 | { | |
447 | createTestData(); |
|
440 | createTestData(); | |
448 | qreal min = m_chart->axisX()->min(); |
|
441 | qreal min = m_chart->axisX()->min(); | |
449 | m_chart->scrollRight(); |
|
442 | m_chart->scrollRight(); | |
450 | QVERIFY(m_chart->axisX()->min()>min); |
|
443 | QVERIFY(m_chart->axisX()->min()>min); | |
451 | } |
|
444 | } | |
452 |
|
445 | |||
453 | void tst_QChart::scrollUp_data() |
|
446 | void tst_QChart::scrollUp_data() | |
454 | { |
|
447 | { | |
455 |
|
448 | |||
456 | } |
|
449 | } | |
457 |
|
450 | |||
458 | void tst_QChart::scrollUp() |
|
451 | void tst_QChart::scrollUp() | |
459 | { |
|
452 | { | |
460 | createTestData(); |
|
453 | createTestData(); | |
461 | qreal min = m_chart->axisY()->min(); |
|
454 | qreal min = m_chart->axisY()->min(); | |
462 | m_chart->scrollUp(); |
|
455 | m_chart->scrollUp(); | |
463 | QVERIFY(m_chart->axisY()->min()>min); |
|
456 | QVERIFY(m_chart->axisY()->min()>min); | |
464 | } |
|
457 | } | |
465 |
|
458 | |||
466 | void tst_QChart::theme_data() |
|
459 | void tst_QChart::theme_data() | |
467 | { |
|
460 | { | |
468 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
461 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
469 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
462 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
470 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
463 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
471 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
464 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
472 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
465 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
473 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
466 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
474 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
467 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
475 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
468 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
476 | } |
|
469 | } | |
477 |
|
470 | |||
478 | void tst_QChart::theme() |
|
471 | void tst_QChart::theme() | |
479 | { |
|
472 | { | |
480 | QFETCH(QChart::ChartTheme, theme); |
|
473 | QFETCH(QChart::ChartTheme, theme); | |
481 | createTestData(); |
|
474 | createTestData(); | |
482 | m_chart->setTheme(theme); |
|
475 | m_chart->setTheme(theme); | |
483 | QVERIFY(m_chart->theme()==theme); |
|
476 | QVERIFY(m_chart->theme()==theme); | |
484 | } |
|
477 | } | |
485 |
|
478 | |||
486 | void tst_QChart::title_data() |
|
479 | void tst_QChart::title_data() | |
487 | { |
|
480 | { | |
488 | QTest::addColumn<QString>("title"); |
|
481 | QTest::addColumn<QString>("title"); | |
489 | QTest::newRow("null") << QString(); |
|
482 | QTest::newRow("null") << QString(); | |
490 | QTest::newRow("foo") << QString("foo"); |
|
483 | QTest::newRow("foo") << QString("foo"); | |
491 | } |
|
484 | } | |
492 |
|
485 | |||
493 | void tst_QChart::title() |
|
486 | void tst_QChart::title() | |
494 | { |
|
487 | { | |
495 | QFETCH(QString, title); |
|
488 | QFETCH(QString, title); | |
496 | m_chart->setTitle(title); |
|
489 | m_chart->setTitle(title); | |
497 | QCOMPARE(m_chart->title(), title); |
|
490 | QCOMPARE(m_chart->title(), title); | |
498 | } |
|
491 | } | |
499 |
|
492 | |||
500 | void tst_QChart::titleBrush_data() |
|
493 | void tst_QChart::titleBrush_data() | |
501 | { |
|
494 | { | |
502 | QTest::addColumn<QBrush>("titleBrush"); |
|
495 | QTest::addColumn<QBrush>("titleBrush"); | |
503 | QTest::newRow("null") << QBrush(); |
|
496 | QTest::newRow("null") << QBrush(); | |
504 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
497 | QTest::newRow("blue") << QBrush(Qt::blue); | |
505 | QTest::newRow("white") << QBrush(Qt::white); |
|
498 | QTest::newRow("white") << QBrush(Qt::white); | |
506 | QTest::newRow("black") << QBrush(Qt::black); |
|
499 | QTest::newRow("black") << QBrush(Qt::black); | |
507 | } |
|
500 | } | |
508 |
|
501 | |||
509 | void tst_QChart::titleBrush() |
|
502 | void tst_QChart::titleBrush() | |
510 | { |
|
503 | { | |
511 | QFETCH(QBrush, titleBrush); |
|
504 | QFETCH(QBrush, titleBrush); | |
512 | m_chart->setTitleBrush(titleBrush); |
|
505 | m_chart->setTitleBrush(titleBrush); | |
513 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
506 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
514 | } |
|
507 | } | |
515 |
|
508 | |||
516 | void tst_QChart::titleFont_data() |
|
509 | void tst_QChart::titleFont_data() | |
517 | { |
|
510 | { | |
518 | QTest::addColumn<QFont>("titleFont"); |
|
511 | QTest::addColumn<QFont>("titleFont"); | |
519 | QTest::newRow("null") << QFont(); |
|
512 | QTest::newRow("null") << QFont(); | |
520 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
513 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
521 | } |
|
514 | } | |
522 |
|
515 | |||
523 | void tst_QChart::titleFont() |
|
516 | void tst_QChart::titleFont() | |
524 | { |
|
517 | { | |
525 | QFETCH(QFont, titleFont); |
|
518 | QFETCH(QFont, titleFont); | |
526 | m_chart->setTitleFont(titleFont); |
|
519 | m_chart->setTitleFont(titleFont); | |
527 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
520 | QCOMPARE(m_chart->titleFont(), titleFont); | |
528 | } |
|
521 | } | |
529 |
|
522 | |||
530 | void tst_QChart::zoomIn_data() |
|
523 | void tst_QChart::zoomIn_data() | |
531 | { |
|
524 | { | |
532 | QTest::addColumn<QRectF>("rect"); |
|
525 | QTest::addColumn<QRectF>("rect"); | |
533 | QTest::newRow("null") << QRectF(); |
|
526 | QTest::newRow("null") << QRectF(); | |
534 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
527 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
535 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
528 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
536 | } |
|
529 | } | |
537 |
|
530 | |||
538 |
|
531 | |||
539 | void tst_QChart::zoomIn() |
|
532 | void tst_QChart::zoomIn() | |
540 | { |
|
533 | { | |
541 | QFETCH(QRectF, rect); |
|
534 | QFETCH(QRectF, rect); | |
542 | createTestData(); |
|
535 | createTestData(); | |
543 | QRectF marigns = m_chart->margins(); |
|
536 | QRectF marigns = m_chart->margins(); | |
544 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
537 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
545 | qreal minX = m_chart->axisX()->min(); |
|
538 | qreal minX = m_chart->axisX()->min(); | |
546 | qreal minY = m_chart->axisY()->min(); |
|
539 | qreal minY = m_chart->axisY()->min(); | |
547 | qreal maxX = m_chart->axisX()->max(); |
|
540 | qreal maxX = m_chart->axisX()->max(); | |
548 | qreal maxY = m_chart->axisY()->max(); |
|
541 | qreal maxY = m_chart->axisY()->max(); | |
549 | m_chart->zoomIn(rect); |
|
542 | m_chart->zoomIn(rect); | |
550 | if(rect.isValid()){ |
|
543 | if(rect.isValid()){ | |
551 | QVERIFY(minX<m_chart->axisX()->min()); |
|
544 | QVERIFY(minX<m_chart->axisX()->min()); | |
552 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
545 | QVERIFY(maxX>m_chart->axisX()->max()); | |
553 | QVERIFY(minY<m_chart->axisY()->min()); |
|
546 | QVERIFY(minY<m_chart->axisY()->min()); | |
554 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
547 | QVERIFY(maxY>m_chart->axisY()->max()); | |
555 | } |
|
548 | } | |
556 | } |
|
549 | } | |
557 |
|
550 | |||
558 | void tst_QChart::zoomOut_data() |
|
551 | void tst_QChart::zoomOut_data() | |
559 | { |
|
552 | { | |
560 |
|
553 | |||
561 | } |
|
554 | } | |
562 |
|
555 | |||
563 | void tst_QChart::zoomOut() |
|
556 | void tst_QChart::zoomOut() | |
564 | { |
|
557 | { | |
565 | createTestData(); |
|
558 | createTestData(); | |
566 | qreal minX = m_chart->axisX()->min(); |
|
559 | qreal minX = m_chart->axisX()->min(); | |
567 | qreal minY = m_chart->axisY()->min(); |
|
560 | qreal minY = m_chart->axisY()->min(); | |
568 | qreal maxX = m_chart->axisX()->max(); |
|
561 | qreal maxX = m_chart->axisX()->max(); | |
569 | qreal maxY = m_chart->axisY()->max(); |
|
562 | qreal maxY = m_chart->axisY()->max(); | |
570 |
|
563 | |||
571 | m_chart->zoomIn(); |
|
564 | m_chart->zoomIn(); | |
572 |
|
565 | |||
573 | QVERIFY(minX < m_chart->axisX()->min()); |
|
566 | QVERIFY(minX < m_chart->axisX()->min()); | |
574 | QVERIFY(maxX > m_chart->axisX()->max()); |
|
567 | QVERIFY(maxX > m_chart->axisX()->max()); | |
575 | QVERIFY(minY < m_chart->axisY()->min()); |
|
568 | QVERIFY(minY < m_chart->axisY()->min()); | |
576 | QVERIFY(maxY > m_chart->axisY()->max()); |
|
569 | QVERIFY(maxY > m_chart->axisY()->max()); | |
577 |
|
570 | |||
578 | m_chart->zoomOut(); |
|
571 | m_chart->zoomOut(); | |
579 |
|
572 | |||
580 | // min x may be a zero value |
|
573 | // min x may be a zero value | |
581 | if (qFuzzyIsNull(minX)) |
|
574 | if (qFuzzyIsNull(minX)) | |
582 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); |
|
575 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); | |
583 | else |
|
576 | else | |
584 | QCOMPARE(minX, m_chart->axisX()->min()); |
|
577 | QCOMPARE(minX, m_chart->axisX()->min()); | |
585 |
|
578 | |||
586 | // min y may be a zero value |
|
579 | // min y may be a zero value | |
587 | if (qFuzzyIsNull(minY)) |
|
580 | if (qFuzzyIsNull(minY)) | |
588 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); |
|
581 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); | |
589 | else |
|
582 | else | |
590 | QCOMPARE(minY, m_chart->axisY()->min()); |
|
583 | QCOMPARE(minY, m_chart->axisY()->min()); | |
591 |
|
584 | |||
592 | QVERIFY(maxX == m_chart->axisX()->max()); |
|
585 | QVERIFY(maxX == m_chart->axisX()->max()); | |
593 | QVERIFY(maxY == m_chart->axisY()->max()); |
|
586 | QVERIFY(maxY == m_chart->axisY()->max()); | |
594 | } |
|
587 | } | |
595 |
|
588 | |||
596 | QTEST_MAIN(tst_QChart) |
|
589 | QTEST_MAIN(tst_QChart) | |
597 | #include "tst_qchart.moc" |
|
590 | #include "tst_qchart.moc" | |
598 |
|
591 |
@@ -1,289 +1,283 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qgroupedbarseries.h> |
|
22 | #include <qgroupedbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 | #include <QBarModelMapper> |
|
26 | #include <QBarModelMapper> | |
27 | #include <QStandardItemModel> |
|
27 | #include <QStandardItemModel> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
29 | QTCOMMERCIALCHART_USE_NAMESPACE | |
30 |
|
30 | |||
31 | Q_DECLARE_METATYPE(QBarSet*) |
|
31 | Q_DECLARE_METATYPE(QBarSet*) | |
32 |
|
32 | |||
33 | class tst_QGroupedBarSeries : public QObject |
|
33 | class tst_QGroupedBarSeries : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 |
|
36 | |||
37 | public slots: |
|
37 | public slots: | |
38 | void initTestCase(); |
|
38 | void initTestCase(); | |
39 | void cleanupTestCase(); |
|
39 | void cleanupTestCase(); | |
40 | void init(); |
|
40 | void init(); | |
41 | void cleanup(); |
|
41 | void cleanup(); | |
42 |
|
42 | |||
43 | private slots: |
|
43 | private slots: | |
44 | void qgroupedbarseries_data(); |
|
44 | void qgroupedbarseries_data(); | |
45 | void qgroupedbarseries(); |
|
45 | void qgroupedbarseries(); | |
46 | void type_data(); |
|
46 | void type_data(); | |
47 | void type(); |
|
47 | void type(); | |
48 | void mouseclicked_data(); |
|
48 | void mouseclicked_data(); | |
49 | void mouseclicked(); |
|
49 | void mouseclicked(); | |
50 | void mousehovered_data(); |
|
50 | void mousehovered_data(); | |
51 | void mousehovered(); |
|
51 | void mousehovered(); | |
52 |
|
52 | |||
53 | private: |
|
53 | private: | |
54 | QGroupedBarSeries* m_barseries; |
|
54 | QGroupedBarSeries* m_barseries; | |
55 | }; |
|
55 | }; | |
56 |
|
56 | |||
57 | void tst_QGroupedBarSeries::initTestCase() |
|
57 | void tst_QGroupedBarSeries::initTestCase() | |
58 | { |
|
58 | { | |
59 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
59 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void tst_QGroupedBarSeries::cleanupTestCase() |
|
62 | void tst_QGroupedBarSeries::cleanupTestCase() | |
63 | { |
|
63 | { | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void tst_QGroupedBarSeries::init() |
|
66 | void tst_QGroupedBarSeries::init() | |
67 | { |
|
67 | { | |
68 | m_barseries = new QGroupedBarSeries(); |
|
68 | m_barseries = new QGroupedBarSeries(); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 | void tst_QGroupedBarSeries::cleanup() |
|
71 | void tst_QGroupedBarSeries::cleanup() | |
72 | { |
|
72 | { | |
73 | delete m_barseries; |
|
73 | delete m_barseries; | |
74 | m_barseries = 0; |
|
74 | m_barseries = 0; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void tst_QGroupedBarSeries::qgroupedbarseries_data() |
|
77 | void tst_QGroupedBarSeries::qgroupedbarseries_data() | |
78 | { |
|
78 | { | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void tst_QGroupedBarSeries::qgroupedbarseries() |
|
81 | void tst_QGroupedBarSeries::qgroupedbarseries() | |
82 | { |
|
82 | { | |
83 | QGroupedBarSeries *barseries = new QGroupedBarSeries(); |
|
83 | QGroupedBarSeries *barseries = new QGroupedBarSeries(); | |
84 | QVERIFY(barseries != 0); |
|
84 | QVERIFY(barseries != 0); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void tst_QGroupedBarSeries::type_data() |
|
87 | void tst_QGroupedBarSeries::type_data() | |
88 | { |
|
88 | { | |
89 |
|
89 | |||
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void tst_QGroupedBarSeries::type() |
|
92 | void tst_QGroupedBarSeries::type() | |
93 | { |
|
93 | { | |
94 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeGroupedBar); |
|
94 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeGroupedBar); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | void tst_QGroupedBarSeries::mouseclicked_data() |
|
97 | void tst_QGroupedBarSeries::mouseclicked_data() | |
98 | { |
|
98 | { | |
99 |
|
99 | |||
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | void tst_QGroupedBarSeries::mouseclicked() |
|
102 | void tst_QGroupedBarSeries::mouseclicked() | |
103 | { |
|
103 | { | |
104 | QGroupedBarSeries* series = new QGroupedBarSeries(); |
|
104 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
105 | QBarCategories categories; |
|
|||
106 | categories << "test1" << "test2" << "test3"; |
|
|||
107 | series->setCategories(categories); |
|
|||
108 |
|
105 | |||
109 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
106 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
110 | *set1 << 10 << 10 << 10; |
|
107 | *set1 << 10 << 10 << 10; | |
111 | series->append(set1); |
|
108 | series->append(set1); | |
112 |
|
109 | |||
113 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
110 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
114 | *set2 << 10 << 10 << 10; |
|
111 | *set2 << 10 << 10 << 10; | |
115 | series->append(set2); |
|
112 | series->append(set2); | |
116 |
|
113 | |||
117 |
QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*, |
|
114 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int))); | |
118 |
|
115 | |||
119 | QChartView view(new QChart()); |
|
116 | QChartView view(new QChart()); | |
120 | view.resize(400,300); |
|
117 | view.resize(400,300); | |
121 | view.chart()->addSeries(series); |
|
118 | view.chart()->addSeries(series); | |
122 | view.show(); |
|
119 | view.show(); | |
123 | QTest::qWaitForWindowShown(&view); |
|
120 | QTest::qWaitForWindowShown(&view); | |
124 |
|
121 | |||
125 | //==================================================================================== |
|
122 | //==================================================================================== | |
126 | // barset 1, category test1 |
|
123 | // barset 1, category test1 | |
127 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,143)); |
|
124 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(95,143)); | |
128 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
125 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
129 |
|
126 | |||
130 | QCOMPARE(seriesSpy.count(), 1); |
|
127 | QCOMPARE(seriesSpy.count(), 1); | |
131 |
|
128 | |||
132 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
129 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
133 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
130 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
134 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
131 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
135 |
QVERIFY(seriesSpyArg.at(1).to |
|
132 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |
136 |
|
133 | |||
137 | //==================================================================================== |
|
134 | //==================================================================================== | |
138 | // barset 1, category test2 |
|
135 | // barset 1, category test2 | |
139 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(187,143)); |
|
136 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(187,143)); | |
140 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
137 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
141 |
|
138 | |||
142 | QCOMPARE(seriesSpy.count(), 1); |
|
139 | QCOMPARE(seriesSpy.count(), 1); | |
143 |
|
140 | |||
144 | seriesSpyArg = seriesSpy.takeFirst(); |
|
141 | seriesSpyArg = seriesSpy.takeFirst(); | |
145 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
142 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
146 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
143 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
147 |
QVERIFY(seriesSpyArg.at(1).to |
|
144 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |
148 |
|
145 | |||
149 | //==================================================================================== |
|
146 | //==================================================================================== | |
150 | // barset 1, category test3 |
|
147 | // barset 1, category test3 | |
151 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(280,143)); |
|
148 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(280,143)); | |
152 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
149 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
153 |
|
150 | |||
154 | QCOMPARE(seriesSpy.count(), 1); |
|
151 | QCOMPARE(seriesSpy.count(), 1); | |
155 |
|
152 | |||
156 | seriesSpyArg = seriesSpy.takeFirst(); |
|
153 | seriesSpyArg = seriesSpy.takeFirst(); | |
157 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
154 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
158 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
155 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
159 |
QVERIFY(seriesSpyArg.at(1).to |
|
156 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |
160 |
|
157 | |||
161 | //==================================================================================== |
|
158 | //==================================================================================== | |
162 | // barset 2, category test1 |
|
159 | // barset 2, category test1 | |
163 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(118,143)); |
|
160 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(118,143)); | |
164 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
161 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
165 |
|
162 | |||
166 | QCOMPARE(seriesSpy.count(), 1); |
|
163 | QCOMPARE(seriesSpy.count(), 1); | |
167 |
|
164 | |||
168 | seriesSpyArg = seriesSpy.takeFirst(); |
|
165 | seriesSpyArg = seriesSpy.takeFirst(); | |
169 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
166 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
170 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
167 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
171 |
QVERIFY(seriesSpyArg.at(1).to |
|
168 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |
172 |
|
169 | |||
173 | //==================================================================================== |
|
170 | //==================================================================================== | |
174 | // barset 2, category test2 |
|
171 | // barset 2, category test2 | |
175 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(210,143)); |
|
172 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(210,143)); | |
176 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
173 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
177 |
|
174 | |||
178 | QCOMPARE(seriesSpy.count(), 1); |
|
175 | QCOMPARE(seriesSpy.count(), 1); | |
179 |
|
176 | |||
180 | seriesSpyArg = seriesSpy.takeFirst(); |
|
177 | seriesSpyArg = seriesSpy.takeFirst(); | |
181 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
178 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
182 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
179 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
183 |
QVERIFY(seriesSpyArg.at(1).to |
|
180 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |
184 |
|
181 | |||
185 | //==================================================================================== |
|
182 | //==================================================================================== | |
186 | // barset 2, category test3 |
|
183 | // barset 2, category test3 | |
187 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(303,143)); |
|
184 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(303,143)); | |
188 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
185 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
189 |
|
186 | |||
190 | QCOMPARE(seriesSpy.count(), 1); |
|
187 | QCOMPARE(seriesSpy.count(), 1); | |
191 |
|
188 | |||
192 | seriesSpyArg = seriesSpy.takeFirst(); |
|
189 | seriesSpyArg = seriesSpy.takeFirst(); | |
193 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
190 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
194 |
QVERIFY(seriesSpyArg.at(1).type() == QVariant:: |
|
191 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
195 |
QVERIFY(seriesSpyArg.at(1).to |
|
192 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |
196 | } |
|
193 | } | |
197 |
|
194 | |||
198 | void tst_QGroupedBarSeries::mousehovered_data() |
|
195 | void tst_QGroupedBarSeries::mousehovered_data() | |
199 | { |
|
196 | { | |
200 |
|
197 | |||
201 | } |
|
198 | } | |
202 |
|
199 | |||
203 | void tst_QGroupedBarSeries::mousehovered() |
|
200 | void tst_QGroupedBarSeries::mousehovered() | |
204 | { |
|
201 | { | |
205 | QGroupedBarSeries* series = new QGroupedBarSeries(); |
|
202 | QGroupedBarSeries* series = new QGroupedBarSeries(); | |
206 | QBarCategories categories; |
|
|||
207 | categories << "test1" << "test2" << "test3"; |
|
|||
208 | series->setCategories(categories); |
|
|||
209 |
|
203 | |||
210 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
204 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
211 | *set1 << 10 << 10 << 10; |
|
205 | *set1 << 10 << 10 << 10; | |
212 | series->append(set1); |
|
206 | series->append(set1); | |
213 |
|
207 | |||
214 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
208 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
215 | *set2 << 10 << 10 << 10; |
|
209 | *set2 << 10 << 10 << 10; | |
216 | series->append(set2); |
|
210 | series->append(set2); | |
217 |
|
211 | |||
218 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); |
|
212 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); | |
219 |
|
213 | |||
220 | QChartView view(new QChart()); |
|
214 | QChartView view(new QChart()); | |
221 | view.resize(400,300); |
|
215 | view.resize(400,300); | |
222 | view.chart()->addSeries(series); |
|
216 | view.chart()->addSeries(series); | |
223 | view.show(); |
|
217 | view.show(); | |
224 | QTest::qWaitForWindowShown(&view); |
|
218 | QTest::qWaitForWindowShown(&view); | |
225 |
|
219 | |||
226 | //this is hack since view does not get events otherwise |
|
220 | //this is hack since view does not get events otherwise | |
227 | view.setMouseTracking(true); |
|
221 | view.setMouseTracking(true); | |
228 |
|
222 | |||
229 | //======================================================================= |
|
223 | //======================================================================= | |
230 | // move mouse to left border |
|
224 | // move mouse to left border | |
231 | qDebug() << "move mouse to left border"; |
|
225 | qDebug() << "move mouse to left border"; | |
232 | QTest::mouseMove(view.viewport(), QPoint(0, 143)); |
|
226 | QTest::mouseMove(view.viewport(), QPoint(0, 143)); | |
233 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
227 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
234 |
|
228 | |||
235 | QVERIFY(seriesSpy.count() == 0); |
|
229 | QVERIFY(seriesSpy.count() == 0); | |
236 |
|
230 | |||
237 | //======================================================================= |
|
231 | //======================================================================= | |
238 | // move mouse on top of set1 |
|
232 | // move mouse on top of set1 | |
239 | qDebug() << "move mouse on top of set1"; |
|
233 | qDebug() << "move mouse on top of set1"; | |
240 | QTest::mouseMove(view.viewport(), QPoint(95,143)); |
|
234 | QTest::mouseMove(view.viewport(), QPoint(95,143)); | |
241 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
235 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | |
242 |
|
236 | |||
243 | QVERIFY(seriesSpy.count() == 1); |
|
237 | QVERIFY(seriesSpy.count() == 1); | |
244 |
|
238 | |||
245 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
239 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
246 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
240 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
247 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
241 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
248 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
242 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
249 |
|
243 | |||
250 | //======================================================================= |
|
244 | //======================================================================= | |
251 | // move mouse from top of set1 to top of set2 |
|
245 | // move mouse from top of set1 to top of set2 | |
252 | qDebug() << "move mouse from top of set1 to top of set2"; |
|
246 | qDebug() << "move mouse from top of set1 to top of set2"; | |
253 | QTest::mouseMove(view.viewport(), QPoint(118,143)); |
|
247 | QTest::mouseMove(view.viewport(), QPoint(118,143)); | |
254 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
248 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | |
255 |
|
249 | |||
256 | QVERIFY(seriesSpy.count() == 2); |
|
250 | QVERIFY(seriesSpy.count() == 2); | |
257 |
|
251 | |||
258 | // should leave set1 |
|
252 | // should leave set1 | |
259 | seriesSpyArg = seriesSpy.takeFirst(); |
|
253 | seriesSpyArg = seriesSpy.takeFirst(); | |
260 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
254 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
261 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
255 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
262 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
256 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
263 |
|
257 | |||
264 | // should enter set2 |
|
258 | // should enter set2 | |
265 | seriesSpyArg = seriesSpy.takeFirst(); |
|
259 | seriesSpyArg = seriesSpy.takeFirst(); | |
266 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
260 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
267 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
261 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
268 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
262 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
269 |
|
263 | |||
270 | //======================================================================= |
|
264 | //======================================================================= | |
271 | // move mouse from top of set2 to background |
|
265 | // move mouse from top of set2 to background | |
272 | qDebug() << "move mouse from top of set2 to background"; |
|
266 | qDebug() << "move mouse from top of set2 to background"; | |
273 |
|
267 | |||
274 | QTest::mouseMove(view.viewport(), QPoint(118,0)); |
|
268 | QTest::mouseMove(view.viewport(), QPoint(118,0)); | |
275 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
269 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | |
276 |
|
270 | |||
277 | QVERIFY(seriesSpy.count() == 1); |
|
271 | QVERIFY(seriesSpy.count() == 1); | |
278 |
|
272 | |||
279 | // should leave set2 |
|
273 | // should leave set2 | |
280 | seriesSpyArg = seriesSpy.takeFirst(); |
|
274 | seriesSpyArg = seriesSpy.takeFirst(); | |
281 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
275 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
282 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
276 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
283 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
277 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
284 | } |
|
278 | } | |
285 |
|
279 | |||
286 | QTEST_MAIN(tst_QGroupedBarSeries) |
|
280 | QTEST_MAIN(tst_QGroupedBarSeries) | |
287 |
|
281 | |||
288 | #include "tst_qgroupedbarseries.moc" |
|
282 | #include "tst_qgroupedbarseries.moc" | |
289 |
|
283 |
@@ -1,272 +1,272 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qpercentbarseries.h> |
|
22 | #include <qpercentbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | Q_DECLARE_METATYPE(QBarSet*) |
|
29 | Q_DECLARE_METATYPE(QBarSet*) | |
30 |
|
30 | |||
31 | class tst_QPercentBarSeries : public QObject |
|
31 | class tst_QPercentBarSeries : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public slots: |
|
35 | public slots: | |
36 | void initTestCase(); |
|
36 | void initTestCase(); | |
37 | void cleanupTestCase(); |
|
37 | void cleanupTestCase(); | |
38 | void init(); |
|
38 | void init(); | |
39 | void cleanup(); |
|
39 | void cleanup(); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 | void qpercentbarseries_data(); |
|
42 | void qpercentbarseries_data(); | |
43 | void qpercentbarseries(); |
|
43 | void qpercentbarseries(); | |
44 | void type_data(); |
|
44 | void type_data(); | |
45 | void type(); |
|
45 | void type(); | |
46 | void mouseclicked_data(); |
|
46 | void mouseclicked_data(); | |
47 | void mouseclicked(); |
|
47 | void mouseclicked(); | |
48 | void mousehovered_data(); |
|
48 | void mousehovered_data(); | |
49 | void mousehovered(); |
|
49 | void mousehovered(); | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 | QPercentBarSeries* m_barseries; |
|
52 | QPercentBarSeries* m_barseries; | |
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | void tst_QPercentBarSeries::initTestCase() |
|
55 | void tst_QPercentBarSeries::initTestCase() | |
56 | { |
|
56 | { | |
57 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
57 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void tst_QPercentBarSeries::cleanupTestCase() |
|
60 | void tst_QPercentBarSeries::cleanupTestCase() | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void tst_QPercentBarSeries::init() |
|
64 | void tst_QPercentBarSeries::init() | |
65 | { |
|
65 | { | |
66 | m_barseries = new QPercentBarSeries(); |
|
66 | m_barseries = new QPercentBarSeries(); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void tst_QPercentBarSeries::cleanup() |
|
69 | void tst_QPercentBarSeries::cleanup() | |
70 | { |
|
70 | { | |
71 | delete m_barseries; |
|
71 | delete m_barseries; | |
72 | m_barseries = 0; |
|
72 | m_barseries = 0; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void tst_QPercentBarSeries::qpercentbarseries_data() |
|
75 | void tst_QPercentBarSeries::qpercentbarseries_data() | |
76 | { |
|
76 | { | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void tst_QPercentBarSeries::qpercentbarseries() |
|
79 | void tst_QPercentBarSeries::qpercentbarseries() | |
80 | { |
|
80 | { | |
81 | QPercentBarSeries *barseries = new QPercentBarSeries(); |
|
81 | QPercentBarSeries *barseries = new QPercentBarSeries(); | |
82 | QVERIFY(barseries != 0); |
|
82 | QVERIFY(barseries != 0); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void tst_QPercentBarSeries::type_data() |
|
85 | void tst_QPercentBarSeries::type_data() | |
86 | { |
|
86 | { | |
87 |
|
87 | |||
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_QPercentBarSeries::type() |
|
90 | void tst_QPercentBarSeries::type() | |
91 | { |
|
91 | { | |
92 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar); |
|
92 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypePercentBar); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | void tst_QPercentBarSeries::mouseclicked_data() |
|
95 | void tst_QPercentBarSeries::mouseclicked_data() | |
96 | { |
|
96 | { | |
97 |
|
97 | |||
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void tst_QPercentBarSeries::mouseclicked() |
|
100 | void tst_QPercentBarSeries::mouseclicked() | |
101 | { |
|
101 | { | |
102 | QPercentBarSeries* series = new QPercentBarSeries(); |
|
102 | QPercentBarSeries* series = new QPercentBarSeries(); | |
103 | QBarCategories categories; |
|
|||
104 | categories << "test1" << "test2" << "test3"; |
|
|||
105 | series->setCategories(categories); |
|
|||
106 |
|
103 | |||
107 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
104 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
108 | *set1 << 10 << 10 << 10; |
|
105 | *set1 << 10 << 10 << 10; | |
109 | series->append(set1); |
|
106 | series->append(set1); | |
110 |
|
107 | |||
111 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
108 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
112 | *set2 << 10 << 10 << 10; |
|
109 | *set2 << 10 << 10 << 10; | |
113 | series->append(set2); |
|
110 | series->append(set2); | |
114 |
|
111 | |||
115 |
QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*, |
|
112 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int))); | |
116 |
|
113 | |||
117 | QChartView view(new QChart()); |
|
114 | QChartView view(new QChart()); | |
118 | view.resize(400,300); |
|
115 | view.resize(400,300); | |
119 | view.chart()->addSeries(series); |
|
116 | view.chart()->addSeries(series); | |
120 | view.show(); |
|
117 | view.show(); | |
121 | QTest::qWaitForWindowShown(&view); |
|
118 | QTest::qWaitForWindowShown(&view); | |
122 |
|
119 | |||
123 | //==================================================================================== |
|
120 | //==================================================================================== | |
124 | // barset 1, category test1 |
|
121 | // barset 1, category test1 | |
125 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190)); |
|
122 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190)); | |
126 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
123 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
127 |
|
124 | |||
128 | QCOMPARE(seriesSpy.count(), 1); |
|
125 | QCOMPARE(seriesSpy.count(), 1); | |
129 |
|
126 | |||
130 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
127 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
131 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
128 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
132 |
QVERIFY(seriesSpyArg.at(1).t |
|
129 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
130 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |||
133 |
|
131 | |||
134 | //==================================================================================== |
|
132 | //==================================================================================== | |
135 | // barset 1, category test2 |
|
133 | // barset 1, category test2 | |
136 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190)); |
|
134 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190)); | |
137 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
135 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
138 |
|
136 | |||
139 | QCOMPARE(seriesSpy.count(), 1); |
|
137 | QCOMPARE(seriesSpy.count(), 1); | |
140 |
|
138 | |||
141 | seriesSpyArg = seriesSpy.takeFirst(); |
|
139 | seriesSpyArg = seriesSpy.takeFirst(); | |
142 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
140 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
143 |
QVERIFY(seriesSpyArg.at(1).t |
|
141 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
142 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |||
144 |
|
143 | |||
145 | //==================================================================================== |
|
144 | //==================================================================================== | |
146 | // barset 1, category test3 |
|
145 | // barset 1, category test3 | |
147 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190)); |
|
146 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190)); | |
148 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
147 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
149 |
|
148 | |||
150 | QCOMPARE(seriesSpy.count(), 1); |
|
149 | QCOMPARE(seriesSpy.count(), 1); | |
151 |
|
150 | |||
152 | seriesSpyArg = seriesSpy.takeFirst(); |
|
151 | seriesSpyArg = seriesSpy.takeFirst(); | |
153 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
152 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
154 |
QVERIFY(seriesSpyArg.at(1).t |
|
153 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
154 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |||
155 |
|
155 | |||
156 | //==================================================================================== |
|
156 | //==================================================================================== | |
157 | // barset 2, category test1 |
|
157 | // barset 2, category test1 | |
158 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95)); |
|
158 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95)); | |
159 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
159 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
160 |
|
160 | |||
161 | QCOMPARE(seriesSpy.count(), 1); |
|
161 | QCOMPARE(seriesSpy.count(), 1); | |
162 |
|
162 | |||
163 | seriesSpyArg = seriesSpy.takeFirst(); |
|
163 | seriesSpyArg = seriesSpy.takeFirst(); | |
164 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
164 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
165 |
QVERIFY(seriesSpyArg.at(1).t |
|
165 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
166 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |||
166 |
|
167 | |||
167 | //==================================================================================== |
|
168 | //==================================================================================== | |
168 | // barset 2, category test2 |
|
169 | // barset 2, category test2 | |
169 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95)); |
|
170 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95)); | |
170 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
171 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
171 |
|
172 | |||
172 | QCOMPARE(seriesSpy.count(), 1); |
|
173 | QCOMPARE(seriesSpy.count(), 1); | |
173 |
|
174 | |||
174 | seriesSpyArg = seriesSpy.takeFirst(); |
|
175 | seriesSpyArg = seriesSpy.takeFirst(); | |
175 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
176 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
176 |
QVERIFY(seriesSpyArg.at(1).t |
|
177 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
178 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |||
177 |
|
179 | |||
178 | //==================================================================================== |
|
180 | //==================================================================================== | |
179 | // barset 2, category test3 |
|
181 | // barset 2, category test3 | |
180 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95)); |
|
182 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95)); | |
181 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
183 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
182 |
|
184 | |||
183 | QCOMPARE(seriesSpy.count(), 1); |
|
185 | QCOMPARE(seriesSpy.count(), 1); | |
184 |
|
186 | |||
185 | seriesSpyArg = seriesSpy.takeFirst(); |
|
187 | seriesSpyArg = seriesSpy.takeFirst(); | |
186 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
188 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
187 |
QVERIFY(seriesSpyArg.at(1).t |
|
189 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
190 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |||
188 | } |
|
191 | } | |
189 |
|
192 | |||
190 | void tst_QPercentBarSeries::mousehovered_data() |
|
193 | void tst_QPercentBarSeries::mousehovered_data() | |
191 | { |
|
194 | { | |
192 |
|
195 | |||
193 | } |
|
196 | } | |
194 |
|
197 | |||
195 | void tst_QPercentBarSeries::mousehovered() |
|
198 | void tst_QPercentBarSeries::mousehovered() | |
196 | { |
|
199 | { | |
197 | QPercentBarSeries* series = new QPercentBarSeries(); |
|
200 | QPercentBarSeries* series = new QPercentBarSeries(); | |
198 | QBarCategories categories; |
|
|||
199 | categories << "test1" << "test2" << "test3"; |
|
|||
200 | series->setCategories(categories); |
|
|||
201 |
|
201 | |||
202 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
202 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
203 | *set1 << 10 << 10 << 10; |
|
203 | *set1 << 10 << 10 << 10; | |
204 | series->append(set1); |
|
204 | series->append(set1); | |
205 |
|
205 | |||
206 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
206 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
207 | *set2 << 10 << 10 << 10; |
|
207 | *set2 << 10 << 10 << 10; | |
208 | series->append(set2); |
|
208 | series->append(set2); | |
209 |
|
209 | |||
210 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); |
|
210 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); | |
211 |
|
211 | |||
212 | QChartView view(new QChart()); |
|
212 | QChartView view(new QChart()); | |
213 | view.resize(400,300); |
|
213 | view.resize(400,300); | |
214 | view.chart()->addSeries(series); |
|
214 | view.chart()->addSeries(series); | |
215 | view.show(); |
|
215 | view.show(); | |
216 | QTest::qWaitForWindowShown(&view); |
|
216 | QTest::qWaitForWindowShown(&view); | |
217 |
|
217 | |||
218 | //this is hack since view does not get events otherwise |
|
218 | //this is hack since view does not get events otherwise | |
219 | view.setMouseTracking(true); |
|
219 | view.setMouseTracking(true); | |
220 |
|
220 | |||
221 | //======================================================================= |
|
221 | //======================================================================= | |
222 | // move mouse to left border |
|
222 | // move mouse to left border | |
223 | QTest::mouseMove(view.viewport(), QPoint(0, 190)); |
|
223 | QTest::mouseMove(view.viewport(), QPoint(0, 190)); | |
224 |
|
224 | |||
225 | QVERIFY(seriesSpy.count() == 0); |
|
225 | QVERIFY(seriesSpy.count() == 0); | |
226 |
|
226 | |||
227 | //======================================================================= |
|
227 | //======================================================================= | |
228 | // move mouse on top of set1 |
|
228 | // move mouse on top of set1 | |
229 | QTest::mouseMove(view.viewport(), QPoint(106,190)); |
|
229 | QTest::mouseMove(view.viewport(), QPoint(106,190)); | |
230 |
|
230 | |||
231 | QVERIFY(seriesSpy.count() == 1); |
|
231 | QVERIFY(seriesSpy.count() == 1); | |
232 |
|
232 | |||
233 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
233 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
234 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
234 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
235 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
235 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
236 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
236 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
237 |
|
237 | |||
238 | //======================================================================= |
|
238 | //======================================================================= | |
239 | // move mouse from top of set1 to top of set2 |
|
239 | // move mouse from top of set1 to top of set2 | |
240 | QTest::mouseMove(view.viewport(), QPoint(106,95)); |
|
240 | QTest::mouseMove(view.viewport(), QPoint(106,95)); | |
241 |
|
241 | |||
242 | QVERIFY(seriesSpy.count() == 2); |
|
242 | QVERIFY(seriesSpy.count() == 2); | |
243 |
|
243 | |||
244 | // should leave set1 |
|
244 | // should leave set1 | |
245 | seriesSpyArg = seriesSpy.takeFirst(); |
|
245 | seriesSpyArg = seriesSpy.takeFirst(); | |
246 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
246 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
247 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
247 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
248 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
248 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
249 |
|
249 | |||
250 | // should enter set2 |
|
250 | // should enter set2 | |
251 | seriesSpyArg = seriesSpy.takeFirst(); |
|
251 | seriesSpyArg = seriesSpy.takeFirst(); | |
252 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
252 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
253 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
253 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
254 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
254 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
255 |
|
255 | |||
256 | //======================================================================= |
|
256 | //======================================================================= | |
257 | // move mouse from top of set2 to background |
|
257 | // move mouse from top of set2 to background | |
258 | QTest::mouseMove(view.viewport(), QPoint(106,0)); |
|
258 | QTest::mouseMove(view.viewport(), QPoint(106,0)); | |
259 |
|
259 | |||
260 | QVERIFY(seriesSpy.count() == 1); |
|
260 | QVERIFY(seriesSpy.count() == 1); | |
261 |
|
261 | |||
262 | // should leave set2 |
|
262 | // should leave set2 | |
263 | seriesSpyArg = seriesSpy.takeFirst(); |
|
263 | seriesSpyArg = seriesSpy.takeFirst(); | |
264 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
264 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
265 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
265 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
266 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
266 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | QTEST_MAIN(tst_QPercentBarSeries) |
|
269 | QTEST_MAIN(tst_QPercentBarSeries) | |
270 |
|
270 | |||
271 | #include "tst_qpercentbarseries.moc" |
|
271 | #include "tst_qpercentbarseries.moc" | |
272 |
|
272 |
@@ -1,272 +1,272 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qstackedbarseries.h> |
|
22 | #include <qstackedbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 | Q_DECLARE_METATYPE(QBarSet*) |
|
29 | Q_DECLARE_METATYPE(QBarSet*) | |
30 |
|
30 | |||
31 | class tst_QStackedBarSeries : public QObject |
|
31 | class tst_QStackedBarSeries : public QObject | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 |
|
34 | |||
35 | public slots: |
|
35 | public slots: | |
36 | void initTestCase(); |
|
36 | void initTestCase(); | |
37 | void cleanupTestCase(); |
|
37 | void cleanupTestCase(); | |
38 | void init(); |
|
38 | void init(); | |
39 | void cleanup(); |
|
39 | void cleanup(); | |
40 |
|
40 | |||
41 | private slots: |
|
41 | private slots: | |
42 | void qstackedbarseries_data(); |
|
42 | void qstackedbarseries_data(); | |
43 | void qstackedbarseries(); |
|
43 | void qstackedbarseries(); | |
44 | void type_data(); |
|
44 | void type_data(); | |
45 | void type(); |
|
45 | void type(); | |
46 | void mouseclicked_data(); |
|
46 | void mouseclicked_data(); | |
47 | void mouseclicked(); |
|
47 | void mouseclicked(); | |
48 | void mousehovered_data(); |
|
48 | void mousehovered_data(); | |
49 | void mousehovered(); |
|
49 | void mousehovered(); | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 | QStackedBarSeries* m_barseries; |
|
52 | QStackedBarSeries* m_barseries; | |
53 | }; |
|
53 | }; | |
54 |
|
54 | |||
55 | void tst_QStackedBarSeries::initTestCase() |
|
55 | void tst_QStackedBarSeries::initTestCase() | |
56 | { |
|
56 | { | |
57 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
57 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | void tst_QStackedBarSeries::cleanupTestCase() |
|
60 | void tst_QStackedBarSeries::cleanupTestCase() | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | void tst_QStackedBarSeries::init() |
|
64 | void tst_QStackedBarSeries::init() | |
65 | { |
|
65 | { | |
66 | m_barseries = new QStackedBarSeries(); |
|
66 | m_barseries = new QStackedBarSeries(); | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void tst_QStackedBarSeries::cleanup() |
|
69 | void tst_QStackedBarSeries::cleanup() | |
70 | { |
|
70 | { | |
71 | delete m_barseries; |
|
71 | delete m_barseries; | |
72 | m_barseries = 0; |
|
72 | m_barseries = 0; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void tst_QStackedBarSeries::qstackedbarseries_data() |
|
75 | void tst_QStackedBarSeries::qstackedbarseries_data() | |
76 | { |
|
76 | { | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | void tst_QStackedBarSeries::qstackedbarseries() |
|
79 | void tst_QStackedBarSeries::qstackedbarseries() | |
80 | { |
|
80 | { | |
81 | QStackedBarSeries *barseries = new QStackedBarSeries(); |
|
81 | QStackedBarSeries *barseries = new QStackedBarSeries(); | |
82 | QVERIFY(barseries != 0); |
|
82 | QVERIFY(barseries != 0); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | void tst_QStackedBarSeries::type_data() |
|
85 | void tst_QStackedBarSeries::type_data() | |
86 | { |
|
86 | { | |
87 |
|
87 | |||
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void tst_QStackedBarSeries::type() |
|
90 | void tst_QStackedBarSeries::type() | |
91 | { |
|
91 | { | |
92 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); |
|
92 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeStackedBar); | |
93 | } |
|
93 | } | |
94 |
|
94 | |||
95 | void tst_QStackedBarSeries::mouseclicked_data() |
|
95 | void tst_QStackedBarSeries::mouseclicked_data() | |
96 | { |
|
96 | { | |
97 |
|
97 | |||
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void tst_QStackedBarSeries::mouseclicked() |
|
100 | void tst_QStackedBarSeries::mouseclicked() | |
101 | { |
|
101 | { | |
102 | QStackedBarSeries* series = new QStackedBarSeries(); |
|
102 | QStackedBarSeries* series = new QStackedBarSeries(); | |
103 | QBarCategories categories; |
|
|||
104 | categories << "test1" << "test2" << "test3"; |
|
|||
105 | series->setCategories(categories); |
|
|||
106 |
|
103 | |||
107 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
104 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
108 | *set1 << 10 << 10 << 10; |
|
105 | *set1 << 10 << 10 << 10; | |
109 | series->append(set1); |
|
106 | series->append(set1); | |
110 |
|
107 | |||
111 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
108 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
112 | *set2 << 10 << 10 << 10; |
|
109 | *set2 << 10 << 10 << 10; | |
113 | series->append(set2); |
|
110 | series->append(set2); | |
114 |
|
111 | |||
115 |
QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*, |
|
112 | QSignalSpy seriesSpy(series,SIGNAL(clicked(QBarSet*,int))); | |
116 |
|
113 | |||
117 | QChartView view(new QChart()); |
|
114 | QChartView view(new QChart()); | |
118 | view.resize(400,300); |
|
115 | view.resize(400,300); | |
119 | view.chart()->addSeries(series); |
|
116 | view.chart()->addSeries(series); | |
120 | view.show(); |
|
117 | view.show(); | |
121 | QTest::qWaitForWindowShown(&view); |
|
118 | QTest::qWaitForWindowShown(&view); | |
122 |
|
119 | |||
123 | //==================================================================================== |
|
120 | //==================================================================================== | |
124 | // barset 1, category test1 |
|
121 | // barset 1, category test1 | |
125 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190)); |
|
122 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,190)); | |
126 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
123 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
127 |
|
124 | |||
128 | QCOMPARE(seriesSpy.count(), 1); |
|
125 | QCOMPARE(seriesSpy.count(), 1); | |
129 |
|
126 | |||
130 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
127 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
131 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
128 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
132 |
QVERIFY(seriesSpyArg.at(1).t |
|
129 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
130 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |||
133 |
|
131 | |||
134 | //==================================================================================== |
|
132 | //==================================================================================== | |
135 | // barset 1, category test2 |
|
133 | // barset 1, category test2 | |
136 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190)); |
|
134 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,190)); | |
137 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
135 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
138 |
|
136 | |||
139 | QCOMPARE(seriesSpy.count(), 1); |
|
137 | QCOMPARE(seriesSpy.count(), 1); | |
140 |
|
138 | |||
141 | seriesSpyArg = seriesSpy.takeFirst(); |
|
139 | seriesSpyArg = seriesSpy.takeFirst(); | |
142 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
140 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
143 |
QVERIFY(seriesSpyArg.at(1).t |
|
141 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
142 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |||
144 |
|
143 | |||
145 | //==================================================================================== |
|
144 | //==================================================================================== | |
146 | // barset 1, category test3 |
|
145 | // barset 1, category test3 | |
147 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190)); |
|
146 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,190)); | |
148 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
147 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
149 |
|
148 | |||
150 | QCOMPARE(seriesSpy.count(), 1); |
|
149 | QCOMPARE(seriesSpy.count(), 1); | |
151 |
|
150 | |||
152 | seriesSpyArg = seriesSpy.takeFirst(); |
|
151 | seriesSpyArg = seriesSpy.takeFirst(); | |
153 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
152 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
154 |
QVERIFY(seriesSpyArg.at(1).t |
|
153 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
154 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |||
155 |
|
155 | |||
156 | //==================================================================================== |
|
156 | //==================================================================================== | |
157 | // barset 2, category test1 |
|
157 | // barset 2, category test1 | |
158 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95)); |
|
158 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(106,95)); | |
159 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
159 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
160 |
|
160 | |||
161 | QCOMPARE(seriesSpy.count(), 1); |
|
161 | QCOMPARE(seriesSpy.count(), 1); | |
162 |
|
162 | |||
163 | seriesSpyArg = seriesSpy.takeFirst(); |
|
163 | seriesSpyArg = seriesSpy.takeFirst(); | |
164 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
164 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
165 |
QVERIFY(seriesSpyArg.at(1).t |
|
165 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
166 | QVERIFY(seriesSpyArg.at(1).toInt() == 0); | |||
166 |
|
167 | |||
167 | //==================================================================================== |
|
168 | //==================================================================================== | |
168 | // barset 2, category test2 |
|
169 | // barset 2, category test2 | |
169 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95)); |
|
170 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(199,95)); | |
170 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
171 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
171 |
|
172 | |||
172 | QCOMPARE(seriesSpy.count(), 1); |
|
173 | QCOMPARE(seriesSpy.count(), 1); | |
173 |
|
174 | |||
174 | seriesSpyArg = seriesSpy.takeFirst(); |
|
175 | seriesSpyArg = seriesSpy.takeFirst(); | |
175 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
176 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
176 |
QVERIFY(seriesSpyArg.at(1).t |
|
177 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
178 | QVERIFY(seriesSpyArg.at(1).toInt() == 1); | |||
177 |
|
179 | |||
178 | //==================================================================================== |
|
180 | //==================================================================================== | |
179 | // barset 2, category test3 |
|
181 | // barset 2, category test3 | |
180 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95)); |
|
182 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(292,95)); | |
181 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
183 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
182 |
|
184 | |||
183 | QCOMPARE(seriesSpy.count(), 1); |
|
185 | QCOMPARE(seriesSpy.count(), 1); | |
184 |
|
186 | |||
185 | seriesSpyArg = seriesSpy.takeFirst(); |
|
187 | seriesSpyArg = seriesSpy.takeFirst(); | |
186 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
188 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
187 |
QVERIFY(seriesSpyArg.at(1).t |
|
189 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Int); | |
|
190 | QVERIFY(seriesSpyArg.at(1).toInt() == 2); | |||
188 | } |
|
191 | } | |
189 |
|
192 | |||
190 | void tst_QStackedBarSeries::mousehovered_data() |
|
193 | void tst_QStackedBarSeries::mousehovered_data() | |
191 | { |
|
194 | { | |
192 |
|
195 | |||
193 | } |
|
196 | } | |
194 |
|
197 | |||
195 | void tst_QStackedBarSeries::mousehovered() |
|
198 | void tst_QStackedBarSeries::mousehovered() | |
196 | { |
|
199 | { | |
197 | QStackedBarSeries* series = new QStackedBarSeries(); |
|
200 | QStackedBarSeries* series = new QStackedBarSeries(); | |
198 | QBarCategories categories; |
|
|||
199 | categories << "test1" << "test2" << "test3"; |
|
|||
200 | series->setCategories(categories); |
|
|||
201 |
|
201 | |||
202 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
202 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
203 | *set1 << 10 << 10 << 10; |
|
203 | *set1 << 10 << 10 << 10; | |
204 | series->append(set1); |
|
204 | series->append(set1); | |
205 |
|
205 | |||
206 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
206 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
207 | *set2 << 10 << 10 << 10; |
|
207 | *set2 << 10 << 10 << 10; | |
208 | series->append(set2); |
|
208 | series->append(set2); | |
209 |
|
209 | |||
210 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); |
|
210 | QSignalSpy seriesSpy(series,SIGNAL(hovered(QBarSet*,bool))); | |
211 |
|
211 | |||
212 | QChartView view(new QChart()); |
|
212 | QChartView view(new QChart()); | |
213 | view.resize(400,300); |
|
213 | view.resize(400,300); | |
214 | view.chart()->addSeries(series); |
|
214 | view.chart()->addSeries(series); | |
215 | view.show(); |
|
215 | view.show(); | |
216 | QTest::qWaitForWindowShown(&view); |
|
216 | QTest::qWaitForWindowShown(&view); | |
217 |
|
217 | |||
218 | //this is hack since view does not get events otherwise |
|
218 | //this is hack since view does not get events otherwise | |
219 | view.setMouseTracking(true); |
|
219 | view.setMouseTracking(true); | |
220 |
|
220 | |||
221 | //======================================================================= |
|
221 | //======================================================================= | |
222 | // move mouse to left border |
|
222 | // move mouse to left border | |
223 | QTest::mouseMove(view.viewport(), QPoint(0, 190)); |
|
223 | QTest::mouseMove(view.viewport(), QPoint(0, 190)); | |
224 |
|
224 | |||
225 | QVERIFY(seriesSpy.count() == 0); |
|
225 | QVERIFY(seriesSpy.count() == 0); | |
226 |
|
226 | |||
227 | //======================================================================= |
|
227 | //======================================================================= | |
228 | // move mouse on top of set1 |
|
228 | // move mouse on top of set1 | |
229 | QTest::mouseMove(view.viewport(), QPoint(106,190)); |
|
229 | QTest::mouseMove(view.viewport(), QPoint(106,190)); | |
230 |
|
230 | |||
231 | QVERIFY(seriesSpy.count() == 1); |
|
231 | QVERIFY(seriesSpy.count() == 1); | |
232 |
|
232 | |||
233 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
233 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
234 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
234 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
235 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
235 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
236 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
236 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
237 |
|
237 | |||
238 | //======================================================================= |
|
238 | //======================================================================= | |
239 | // move mouse from top of set1 to top of set2 |
|
239 | // move mouse from top of set1 to top of set2 | |
240 | QTest::mouseMove(view.viewport(), QPoint(106,95)); |
|
240 | QTest::mouseMove(view.viewport(), QPoint(106,95)); | |
241 |
|
241 | |||
242 | QVERIFY(seriesSpy.count() == 2); |
|
242 | QVERIFY(seriesSpy.count() == 2); | |
243 |
|
243 | |||
244 | // should leave set1 |
|
244 | // should leave set1 | |
245 | seriesSpyArg = seriesSpy.takeFirst(); |
|
245 | seriesSpyArg = seriesSpy.takeFirst(); | |
246 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); |
|
246 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set1); | |
247 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
247 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
248 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
248 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
249 |
|
249 | |||
250 | // should enter set2 |
|
250 | // should enter set2 | |
251 | seriesSpyArg = seriesSpy.takeFirst(); |
|
251 | seriesSpyArg = seriesSpy.takeFirst(); | |
252 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
252 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
253 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
253 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
254 | QVERIFY(seriesSpyArg.at(1).toBool() == true); |
|
254 | QVERIFY(seriesSpyArg.at(1).toBool() == true); | |
255 |
|
255 | |||
256 | //======================================================================= |
|
256 | //======================================================================= | |
257 | // move mouse from top of set2 to background |
|
257 | // move mouse from top of set2 to background | |
258 | QTest::mouseMove(view.viewport(), QPoint(106,0)); |
|
258 | QTest::mouseMove(view.viewport(), QPoint(106,0)); | |
259 |
|
259 | |||
260 | QVERIFY(seriesSpy.count() == 1); |
|
260 | QVERIFY(seriesSpy.count() == 1); | |
261 |
|
261 | |||
262 | // should leave set2 |
|
262 | // should leave set2 | |
263 | seriesSpyArg = seriesSpy.takeFirst(); |
|
263 | seriesSpyArg = seriesSpy.takeFirst(); | |
264 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); |
|
264 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(0)), set2); | |
265 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); |
|
265 | QVERIFY(seriesSpyArg.at(1).type() == QVariant::Bool); | |
266 | QVERIFY(seriesSpyArg.at(1).toBool() == false); |
|
266 | QVERIFY(seriesSpyArg.at(1).toBool() == false); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | QTEST_MAIN(tst_QStackedBarSeries) |
|
269 | QTEST_MAIN(tst_QStackedBarSeries) | |
270 |
|
270 | |||
271 | #include "tst_qstackedbarseries.moc" |
|
271 | #include "tst_qstackedbarseries.moc" | |
272 |
|
272 |
@@ -1,354 +1,354 | |||||
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 "mainwidget.h" |
|
21 | #include "mainwidget.h" | |
22 | #include "dataseriedialog.h" |
|
22 | #include "dataseriedialog.h" | |
23 | #include "qchartview.h" |
|
23 | #include "qchartview.h" | |
24 | #include "qpieseries.h" |
|
24 | #include "qpieseries.h" | |
25 | #include "qscatterseries.h" |
|
25 | #include "qscatterseries.h" | |
26 | #include "qlineseries.h" |
|
26 | #include "qlineseries.h" | |
27 | #include <qareaseries.h> |
|
27 | #include <qareaseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qbarset.h> |
|
29 | #include <qbarset.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qbarseries.h> | |
31 | #include <qgroupedbarseries.h> |
|
31 | #include <qgroupedbarseries.h> | |
32 | #include <qstackedbarseries.h> |
|
32 | #include <qstackedbarseries.h> | |
33 | #include <qpercentbarseries.h> |
|
33 | #include <qpercentbarseries.h> | |
34 | #include <QPushButton> |
|
34 | #include <QPushButton> | |
35 | #include <QComboBox> |
|
35 | #include <QComboBox> | |
36 | #include <QSpinBox> |
|
36 | #include <QSpinBox> | |
37 | #include <QCheckBox> |
|
37 | #include <QCheckBox> | |
38 | #include <QGridLayout> |
|
38 | #include <QGridLayout> | |
39 | #include <QHBoxLayout> |
|
39 | #include <QHBoxLayout> | |
40 | #include <QLabel> |
|
40 | #include <QLabel> | |
41 | #include <QSpacerItem> |
|
41 | #include <QSpacerItem> | |
42 | #include <QMessageBox> |
|
42 | #include <QMessageBox> | |
43 | #include <cmath> |
|
43 | #include <cmath> | |
44 | #include <QDebug> |
|
44 | #include <QDebug> | |
45 | #include <QStandardItemModel> |
|
45 | #include <QStandardItemModel> | |
46 |
|
46 | |||
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | QTCOMMERCIALCHART_USE_NAMESPACE | |
49 |
|
49 | |||
50 | MainWidget::MainWidget(QWidget *parent) : |
|
50 | MainWidget::MainWidget(QWidget *parent) : | |
51 | QWidget(parent), |
|
51 | QWidget(parent), | |
52 | m_addSerieDialog(0), |
|
52 | m_addSerieDialog(0), | |
53 | m_chart(0) |
|
53 | m_chart(0) | |
54 | { |
|
54 | { | |
55 | m_chart = new QChart(); |
|
55 | m_chart = new QChart(); | |
56 |
|
56 | |||
57 | // Grid layout for the controls for configuring the chart widget |
|
57 | // Grid layout for the controls for configuring the chart widget | |
58 | QGridLayout *grid = new QGridLayout(); |
|
58 | QGridLayout *grid = new QGridLayout(); | |
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
59 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
60 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
61 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | grid->addWidget(addSeriesButton, 0, 1); | |
62 | initBackroundCombo(grid); |
|
62 | initBackroundCombo(grid); | |
63 | initScaleControls(grid); |
|
63 | initScaleControls(grid); | |
64 | initThemeCombo(grid); |
|
64 | initThemeCombo(grid); | |
65 | initCheckboxes(grid); |
|
65 | initCheckboxes(grid); | |
66 |
|
66 | |||
67 | // add row with empty label to make all the other rows static |
|
67 | // add row with empty label to make all the other rows static | |
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
68 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
69 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
69 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
70 |
|
70 | |||
71 | // Create chart view with the chart |
|
71 | // Create chart view with the chart | |
72 | m_chartView = new QChartView(m_chart, this); |
|
72 | m_chartView = new QChartView(m_chart, this); | |
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
73 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
74 |
|
74 | |||
75 | // Another grid layout as a main layout |
|
75 | // Another grid layout as a main layout | |
76 | QGridLayout *mainLayout = new QGridLayout(); |
|
76 | QGridLayout *mainLayout = new QGridLayout(); | |
77 | mainLayout->addLayout(grid, 0, 0); |
|
77 | mainLayout->addLayout(grid, 0, 0); | |
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
78 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
79 | setLayout(mainLayout); |
|
79 | setLayout(mainLayout); | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | // Combo box for selecting the chart's background |
|
82 | // Combo box for selecting the chart's background | |
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
83 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
84 | { |
|
84 | { | |
85 | QComboBox *backgroundCombo = new QComboBox(this); |
|
85 | QComboBox *backgroundCombo = new QComboBox(this); | |
86 | backgroundCombo->addItem("Color"); |
|
86 | backgroundCombo->addItem("Color"); | |
87 | backgroundCombo->addItem("Gradient"); |
|
87 | backgroundCombo->addItem("Gradient"); | |
88 | backgroundCombo->addItem("Image"); |
|
88 | backgroundCombo->addItem("Image"); | |
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
89 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
90 | this, SLOT(backgroundChanged(int))); |
|
90 | this, SLOT(backgroundChanged(int))); | |
91 |
|
91 | |||
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
92 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
93 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | // Scale related controls (auto-scale vs. manual min-max values) |
|
96 | // Scale related controls (auto-scale vs. manual min-max values) | |
97 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
97 | void MainWidget::initScaleControls(QGridLayout *grid) | |
98 | { |
|
98 | { | |
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
99 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
100 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
101 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
102 | m_xMinSpin = new QSpinBox(); |
|
102 | m_xMinSpin = new QSpinBox(); | |
103 | m_xMinSpin->setMinimum(INT_MIN); |
|
103 | m_xMinSpin->setMinimum(INT_MIN); | |
104 | m_xMinSpin->setMaximum(INT_MAX); |
|
104 | m_xMinSpin->setMaximum(INT_MAX); | |
105 | m_xMinSpin->setValue(0); |
|
105 | m_xMinSpin->setValue(0); | |
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
106 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
107 | m_xMaxSpin = new QSpinBox(); |
|
107 | m_xMaxSpin = new QSpinBox(); | |
108 | m_xMaxSpin->setMinimum(INT_MIN); |
|
108 | m_xMaxSpin->setMinimum(INT_MIN); | |
109 | m_xMaxSpin->setMaximum(INT_MAX); |
|
109 | m_xMaxSpin->setMaximum(INT_MAX); | |
110 | m_xMaxSpin->setValue(10); |
|
110 | m_xMaxSpin->setValue(10); | |
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
111 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
112 | m_yMinSpin = new QSpinBox(); |
|
112 | m_yMinSpin = new QSpinBox(); | |
113 | m_yMinSpin->setMinimum(INT_MIN); |
|
113 | m_yMinSpin->setMinimum(INT_MIN); | |
114 | m_yMinSpin->setMaximum(INT_MAX); |
|
114 | m_yMinSpin->setMaximum(INT_MAX); | |
115 | m_yMinSpin->setValue(0); |
|
115 | m_yMinSpin->setValue(0); | |
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
116 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
117 | m_yMaxSpin = new QSpinBox(); |
|
117 | m_yMaxSpin = new QSpinBox(); | |
118 | m_yMaxSpin->setMinimum(INT_MIN); |
|
118 | m_yMaxSpin->setMinimum(INT_MIN); | |
119 | m_yMaxSpin->setMaximum(INT_MAX); |
|
119 | m_yMaxSpin->setMaximum(INT_MAX); | |
120 | m_yMaxSpin->setValue(10); |
|
120 | m_yMaxSpin->setValue(10); | |
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
121 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
122 |
|
122 | |||
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
123 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
124 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
125 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
126 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
127 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
128 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
129 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
130 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
131 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
132 |
|
132 | |||
133 | m_autoScaleCheck->setChecked(true); |
|
133 | m_autoScaleCheck->setChecked(true); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | // Combo box for selecting theme |
|
136 | // Combo box for selecting theme | |
137 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
137 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
138 | { |
|
138 | { | |
139 | QComboBox *chartTheme = new QComboBox(); |
|
139 | QComboBox *chartTheme = new QComboBox(); | |
140 | chartTheme->addItem("Default"); |
|
140 | chartTheme->addItem("Default"); | |
141 | chartTheme->addItem("Light"); |
|
141 | chartTheme->addItem("Light"); | |
142 | chartTheme->addItem("Blue Cerulean"); |
|
142 | chartTheme->addItem("Blue Cerulean"); | |
143 | chartTheme->addItem("Dark"); |
|
143 | chartTheme->addItem("Dark"); | |
144 | chartTheme->addItem("Brown Sand"); |
|
144 | chartTheme->addItem("Brown Sand"); | |
145 | chartTheme->addItem("Blue NCS"); |
|
145 | chartTheme->addItem("Blue NCS"); | |
146 | chartTheme->addItem("High Contrast"); |
|
146 | chartTheme->addItem("High Contrast"); | |
147 | chartTheme->addItem("Blue Icy"); |
|
147 | chartTheme->addItem("Blue Icy"); | |
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
148 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
149 | this, SLOT(changeChartTheme(int))); |
|
149 | this, SLOT(changeChartTheme(int))); | |
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
150 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
151 | grid->addWidget(chartTheme, 8, 1); |
|
151 | grid->addWidget(chartTheme, 8, 1); | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
154 | // Different check boxes for customizing chart |
|
154 | // Different check boxes for customizing chart | |
155 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
155 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
156 | { |
|
156 | { | |
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
157 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
158 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
159 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
160 | zoomCheckBox->setChecked(true); |
|
160 | zoomCheckBox->setChecked(true); | |
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
161 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
162 |
|
162 | |||
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
163 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
164 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
165 | aliasCheckBox->setChecked(false); |
|
165 | aliasCheckBox->setChecked(false); | |
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
166 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void MainWidget::antiAliasToggled(bool enabled) |
|
169 | void MainWidget::antiAliasToggled(bool enabled) | |
170 | { |
|
170 | { | |
171 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
171 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void MainWidget::addSeries() |
|
174 | void MainWidget::addSeries() | |
175 | { |
|
175 | { | |
176 | if (!m_addSerieDialog) { |
|
176 | if (!m_addSerieDialog) { | |
177 | m_addSerieDialog = new DataSerieDialog(this); |
|
177 | m_addSerieDialog = new DataSerieDialog(this); | |
178 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
178 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), | |
179 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
179 | this, SLOT(addSeries(QString,int,int,QString,bool))); | |
180 | } |
|
180 | } | |
181 | m_addSerieDialog->exec(); |
|
181 | m_addSerieDialog->exec(); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
184 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
185 | { |
|
185 | { | |
186 | // TODO: dataCharacteristics |
|
186 | // TODO: dataCharacteristics | |
187 | QList<RealList> testData; |
|
187 | QList<RealList> testData; | |
188 | for (int j(0); j < columnCount; j++) { |
|
188 | for (int j(0); j < columnCount; j++) { | |
189 | QList <qreal> newColumn; |
|
189 | QList <qreal> newColumn; | |
190 | for (int i(0); i < rowCount; i++) { |
|
190 | for (int i(0); i < rowCount; i++) { | |
191 | if (dataCharacteristics == "Sin") { |
|
191 | if (dataCharacteristics == "Sin") { | |
192 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
192 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
193 | } else if (dataCharacteristics == "Sin + random") { |
|
193 | } else if (dataCharacteristics == "Sin + random") { | |
194 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
194 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
195 | } else if (dataCharacteristics == "Random") { |
|
195 | } else if (dataCharacteristics == "Random") { | |
196 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
196 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
197 | } else if (dataCharacteristics == "Linear") { |
|
197 | } else if (dataCharacteristics == "Linear") { | |
198 | //newColumn.append(i * (j + 1.0)); |
|
198 | //newColumn.append(i * (j + 1.0)); | |
199 | // TODO: temporary hack to make pie work; prevent zero values: |
|
199 | // TODO: temporary hack to make pie work; prevent zero values: | |
200 | newColumn.append(i * (j + 1.0) + 0.1); |
|
200 | newColumn.append(i * (j + 1.0) + 0.1); | |
201 | } else { // "constant" |
|
201 | } else { // "constant" | |
202 | newColumn.append((j + 1.0)); |
|
202 | newColumn.append((j + 1.0)); | |
203 | } |
|
203 | } | |
204 | } |
|
204 | } | |
205 | testData.append(newColumn); |
|
205 | testData.append(newColumn); | |
206 | } |
|
206 | } | |
207 | return testData; |
|
207 | return testData; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | QStringList MainWidget::generateLabels(int count) |
|
210 | QStringList MainWidget::generateLabels(int count) | |
211 | { |
|
211 | { | |
212 | QStringList result; |
|
212 | QStringList result; | |
213 | for (int i(0); i < count; i++) |
|
213 | for (int i(0); i < count; i++) | |
214 | result.append("label" + QString::number(i)); |
|
214 | result.append("label" + QString::number(i)); | |
215 | return result; |
|
215 | return result; | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
218 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
219 | { |
|
219 | { | |
220 | qDebug() << "addSeries: " << seriesName |
|
220 | qDebug() << "addSeries: " << seriesName | |
221 | << " columnCount: " << columnCount |
|
221 | << " columnCount: " << columnCount | |
222 | << " rowCount: " << rowCount |
|
222 | << " rowCount: " << rowCount | |
223 | << " dataCharacteristics: " << dataCharacteristics |
|
223 | << " dataCharacteristics: " << dataCharacteristics | |
224 | << " labels enabled: " << labelsEnabled; |
|
224 | << " labels enabled: " << labelsEnabled; | |
225 | m_defaultSeriesName = seriesName; |
|
225 | m_defaultSeriesName = seriesName; | |
226 |
|
226 | |||
227 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
227 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
228 |
|
228 | |||
229 | // Line series and scatter series use similar data |
|
229 | // Line series and scatter series use similar data | |
230 | if (seriesName == "Line") { |
|
230 | if (seriesName == "Line") { | |
231 | for (int j(0); j < data.count(); j ++) { |
|
231 | for (int j(0); j < data.count(); j ++) { | |
232 | QList<qreal> column = data.at(j); |
|
232 | QList<qreal> column = data.at(j); | |
233 | QLineSeries *series = new QLineSeries(); |
|
233 | QLineSeries *series = new QLineSeries(); | |
234 | series->setName("line" + QString::number(j)); |
|
234 | series->setName("line" + QString::number(j)); | |
235 | for (int i(0); i < column.count(); i++) |
|
235 | for (int i(0); i < column.count(); i++) | |
236 | series->append(i, column.at(i)); |
|
236 | series->append(i, column.at(i)); | |
237 | m_chart->addSeries(series); |
|
237 | m_chart->addSeries(series); | |
238 | } |
|
238 | } | |
239 | } else if (seriesName == "Area") { |
|
239 | } else if (seriesName == "Area") { | |
240 | // TODO: lower series for the area? |
|
240 | // TODO: lower series for the area? | |
241 | for (int j(0); j < data.count(); j ++) { |
|
241 | for (int j(0); j < data.count(); j ++) { | |
242 | QList<qreal> column = data.at(j); |
|
242 | QList<qreal> column = data.at(j); | |
243 | QLineSeries *lineSeries = new QLineSeries(); |
|
243 | QLineSeries *lineSeries = new QLineSeries(); | |
244 | for (int i(0); i < column.count(); i++) |
|
244 | for (int i(0); i < column.count(); i++) | |
245 | lineSeries->append(i, column.at(i)); |
|
245 | lineSeries->append(i, column.at(i)); | |
246 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
246 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
247 | areaSeries->setName("area" + QString::number(j)); |
|
247 | areaSeries->setName("area" + QString::number(j)); | |
248 | m_chart->addSeries(areaSeries); |
|
248 | m_chart->addSeries(areaSeries); | |
249 | } |
|
249 | } | |
250 | } else if (seriesName == "Scatter") { |
|
250 | } else if (seriesName == "Scatter") { | |
251 | for (int j(0); j < data.count(); j++) { |
|
251 | for (int j(0); j < data.count(); j++) { | |
252 | QList<qreal> column = data.at(j); |
|
252 | QList<qreal> column = data.at(j); | |
253 | QScatterSeries *series = new QScatterSeries(); |
|
253 | QScatterSeries *series = new QScatterSeries(); | |
254 | series->setName("scatter" + QString::number(j)); |
|
254 | series->setName("scatter" + QString::number(j)); | |
255 | for (int i(0); i < column.count(); i++) |
|
255 | for (int i(0); i < column.count(); i++) | |
256 | series->append(i, column.at(i)); |
|
256 | series->append(i, column.at(i)); | |
257 | m_chart->addSeries(series); |
|
257 | m_chart->addSeries(series); | |
258 | } |
|
258 | } | |
259 | } else if (seriesName == "Pie") { |
|
259 | } else if (seriesName == "Pie") { | |
260 | QStringList labels = generateLabels(rowCount); |
|
260 | QStringList labels = generateLabels(rowCount); | |
261 | for (int j(0); j < data.count(); j++) { |
|
261 | for (int j(0); j < data.count(); j++) { | |
262 | QPieSeries *series = new QPieSeries(); |
|
262 | QPieSeries *series = new QPieSeries(); | |
263 | QList<qreal> column = data.at(j); |
|
263 | QList<qreal> column = data.at(j); | |
264 | for (int i(0); i < column.count(); i++) |
|
264 | for (int i(0); i < column.count(); i++) | |
265 | series->append(labels.at(i), column.at(i)); |
|
265 | series->append(labels.at(i), column.at(i)); | |
266 | m_chart->addSeries(series); |
|
266 | m_chart->addSeries(series); | |
267 | } |
|
267 | } | |
268 | } else if (seriesName == "Bar" |
|
268 | } else if (seriesName == "Bar" | |
269 | || seriesName == "Grouped bar" |
|
269 | || seriesName == "Grouped bar" | |
270 | || seriesName == "Stacked bar" |
|
270 | || seriesName == "Stacked bar" | |
271 | || seriesName == "Percent bar") { |
|
271 | || seriesName == "Percent bar") { | |
272 | QStringList category; |
|
272 | QStringList category; | |
273 | QStringList labels = generateLabels(rowCount); |
|
273 | QStringList labels = generateLabels(rowCount); | |
274 | foreach(QString label, labels) |
|
274 | foreach(QString label, labels) | |
275 | category << label; |
|
275 | category << label; | |
276 | QBarSeries* series = 0; |
|
276 | QBarSeries* series = 0; | |
277 | if (seriesName == "Bar") { |
|
277 | if (seriesName == "Bar") { | |
278 | series = new QBarSeries(this); |
|
278 | series = new QBarSeries(this); | |
279 |
|
|
279 | m_chart->axisX()->categories()->insert(category); | |
280 | } else if (seriesName == "Grouped bar") { |
|
280 | } else if (seriesName == "Grouped bar") { | |
281 | series = new QGroupedBarSeries(this); |
|
281 | series = new QGroupedBarSeries(this); | |
282 |
|
|
282 | m_chart->axisX()->categories()->insert(category); | |
283 | } else if (seriesName == "Stacked bar") { |
|
283 | } else if (seriesName == "Stacked bar") { | |
284 | series = new QStackedBarSeries(this); |
|
284 | series = new QStackedBarSeries(this); | |
285 |
|
|
285 | m_chart->axisX()->categories()->insert(category); | |
286 | } else { |
|
286 | } else { | |
287 | series = new QPercentBarSeries(this); |
|
287 | series = new QPercentBarSeries(this); | |
288 |
|
|
288 | m_chart->axisX()->categories()->insert(category); | |
289 | } |
|
289 | } | |
290 |
|
290 | |||
291 | for (int j(0); j < data.count(); j++) { |
|
291 | for (int j(0); j < data.count(); j++) { | |
292 | QList<qreal> column = data.at(j); |
|
292 | QList<qreal> column = data.at(j); | |
293 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
293 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
294 | for (int i(0); i < column.count(); i++) |
|
294 | for (int i(0); i < column.count(); i++) | |
295 | *set << column.at(i); |
|
295 | *set << column.at(i); | |
296 | series->append(set); |
|
296 | series->append(set); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | m_chart->addSeries(series); |
|
299 | m_chart->addSeries(series); | |
300 | } else if (seriesName == "Spline") { |
|
300 | } else if (seriesName == "Spline") { | |
301 | for (int j(0); j < data.count(); j ++) { |
|
301 | for (int j(0); j < data.count(); j ++) { | |
302 | QList<qreal> column = data.at(j); |
|
302 | QList<qreal> column = data.at(j); | |
303 | QSplineSeries *series = new QSplineSeries(); |
|
303 | QSplineSeries *series = new QSplineSeries(); | |
304 | for (int i(0); i < column.count(); i++) |
|
304 | for (int i(0); i < column.count(); i++) | |
305 | series->append(i, column.at(i)); |
|
305 | series->append(i, column.at(i)); | |
306 | m_chart->addSeries(series); |
|
306 | m_chart->addSeries(series); | |
307 | } |
|
307 | } | |
308 | } |
|
308 | } | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | void MainWidget::backgroundChanged(int itemIndex) |
|
311 | void MainWidget::backgroundChanged(int itemIndex) | |
312 | { |
|
312 | { | |
313 | qDebug() << "backgroundChanged: " << itemIndex; |
|
313 | qDebug() << "backgroundChanged: " << itemIndex; | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void MainWidget::autoScaleChanged(int value) |
|
316 | void MainWidget::autoScaleChanged(int value) | |
317 | { |
|
317 | { | |
318 | if (value) { |
|
318 | if (value) { | |
319 | // TODO: enable auto scaling |
|
319 | // TODO: enable auto scaling | |
320 | } else { |
|
320 | } else { | |
321 | // TODO: set scaling manually (and disable auto scaling) |
|
321 | // TODO: set scaling manually (and disable auto scaling) | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | m_xMinSpin->setEnabled(!value); |
|
324 | m_xMinSpin->setEnabled(!value); | |
325 | m_xMaxSpin->setEnabled(!value); |
|
325 | m_xMaxSpin->setEnabled(!value); | |
326 | m_yMinSpin->setEnabled(!value); |
|
326 | m_yMinSpin->setEnabled(!value); | |
327 | m_yMaxSpin->setEnabled(!value); |
|
327 | m_yMaxSpin->setEnabled(!value); | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | void MainWidget::xMinChanged(int value) |
|
330 | void MainWidget::xMinChanged(int value) | |
331 | { |
|
331 | { | |
332 | qDebug() << "xMinChanged: " << value; |
|
332 | qDebug() << "xMinChanged: " << value; | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | void MainWidget::xMaxChanged(int value) |
|
335 | void MainWidget::xMaxChanged(int value) | |
336 | { |
|
336 | { | |
337 | qDebug() << "xMaxChanged: " << value; |
|
337 | qDebug() << "xMaxChanged: " << value; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | void MainWidget::yMinChanged(int value) |
|
340 | void MainWidget::yMinChanged(int value) | |
341 | { |
|
341 | { | |
342 | qDebug() << "yMinChanged: " << value; |
|
342 | qDebug() << "yMinChanged: " << value; | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | void MainWidget::yMaxChanged(int value) |
|
345 | void MainWidget::yMaxChanged(int value) | |
346 | { |
|
346 | { | |
347 | qDebug() << "yMaxChanged: " << value; |
|
347 | qDebug() << "yMaxChanged: " << value; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | void MainWidget::changeChartTheme(int themeIndex) |
|
350 | void MainWidget::changeChartTheme(int themeIndex) | |
351 | { |
|
351 | { | |
352 | qDebug() << "changeChartTheme: " << themeIndex; |
|
352 | qDebug() << "changeChartTheme: " << themeIndex; | |
353 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
353 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |
354 | } |
|
354 | } |
@@ -1,245 +1,244 | |||||
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 "widget.h" |
|
21 | #include "widget.h" | |
22 |
|
22 | |||
23 | #include <QChart> |
|
23 | #include <QChart> | |
24 | #include <QScatterSeries> |
|
24 | #include <QScatterSeries> | |
25 | #include <QAxis> |
|
25 | #include <QAxis> | |
26 | #include <QBarSet> |
|
26 | #include <QBarSet> | |
27 | #include <QBarSeries> |
|
27 | #include <QBarSeries> | |
28 | #include <QLegend> |
|
28 | #include <QLegend> | |
29 |
|
29 | |||
30 | #include <QGridLayout> |
|
30 | #include <QGridLayout> | |
31 | #include <QPushButton> |
|
31 | #include <QPushButton> | |
32 | #include <QLabel> |
|
32 | #include <QLabel> | |
33 | #include <QListWidget> |
|
33 | #include <QListWidget> | |
34 | #include <QPrinter> |
|
34 | #include <QPrinter> | |
35 | #include <QPrintDialog> |
|
35 | #include <QPrintDialog> | |
36 | #include <QRadioButton> |
|
36 | #include <QRadioButton> | |
37 | #include <QStringList> |
|
37 | #include <QStringList> | |
38 | #include <QSqlQuery> |
|
38 | #include <QSqlQuery> | |
39 | #include <QDebug> |
|
39 | #include <QDebug> | |
40 |
|
40 | |||
41 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
41 | QTCOMMERCIALCHART_USE_NAMESPACE | |
42 |
|
42 | |||
43 | Widget::Widget(QWidget *parent) |
|
43 | Widget::Widget(QWidget *parent) | |
44 | : QWidget(parent) |
|
44 | : QWidget(parent) | |
45 | { |
|
45 | { | |
46 | setGeometry(100, 100, 1000, 600); |
|
46 | setGeometry(100, 100, 1000, 600); | |
47 |
|
47 | |||
48 | // right panel layout |
|
48 | // right panel layout | |
49 | barChartRadioButton = new QRadioButton(tr("Bar chart")); |
|
49 | barChartRadioButton = new QRadioButton(tr("Bar chart")); | |
50 | barChartRadioButton->setChecked(true); |
|
50 | barChartRadioButton->setChecked(true); | |
51 | scatterChartRadioButton = new QRadioButton(tr("Scatter chart")); |
|
51 | scatterChartRadioButton = new QRadioButton(tr("Scatter chart")); | |
52 | scatterChartRadioButton->setChecked(false); |
|
52 | scatterChartRadioButton->setChecked(false); | |
53 | countrieslist = new QListWidget; |
|
53 | countrieslist = new QListWidget; | |
54 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); |
|
54 | countrieslist->setSelectionMode(QAbstractItemView::MultiSelection); | |
55 |
|
55 | |||
56 | //list of years widget |
|
56 | //list of years widget | |
57 | yearslist = new QListWidget; |
|
57 | yearslist = new QListWidget; | |
58 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); |
|
58 | yearslist->setSelectionMode(QAbstractItemView::ExtendedSelection); | |
59 | for (int i = 1990; i < 2011; i++) |
|
59 | for (int i = 1990; i < 2011; i++) | |
60 | yearslist->addItem(QString("%1").arg(i)); |
|
60 | yearslist->addItem(QString("%1").arg(i)); | |
61 |
|
61 | |||
62 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); |
|
62 | QPushButton* refreshButton = new QPushButton(tr("Refresh")); | |
63 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); |
|
63 | connect(refreshButton, SIGNAL(clicked()), this, SLOT(refreshChart())); | |
64 |
|
64 | |||
65 | QPushButton* printButton = new QPushButton(tr("Print to pdf")); |
|
65 | QPushButton* printButton = new QPushButton(tr("Print to pdf")); | |
66 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); |
|
66 | connect(printButton, SIGNAL(clicked()), this, SLOT(printChart())); | |
67 |
|
67 | |||
68 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; |
|
68 | QVBoxLayout* rightPanelLayout = new QVBoxLayout; | |
69 | rightPanelLayout->addWidget(barChartRadioButton); |
|
69 | rightPanelLayout->addWidget(barChartRadioButton); | |
70 | rightPanelLayout->addWidget(scatterChartRadioButton); |
|
70 | rightPanelLayout->addWidget(scatterChartRadioButton); | |
71 | rightPanelLayout->addWidget(countrieslist); |
|
71 | rightPanelLayout->addWidget(countrieslist); | |
72 | rightPanelLayout->addWidget(yearslist); |
|
72 | rightPanelLayout->addWidget(yearslist); | |
73 | rightPanelLayout->addWidget(refreshButton); |
|
73 | rightPanelLayout->addWidget(refreshButton); | |
74 | rightPanelLayout->addWidget(printButton); |
|
74 | rightPanelLayout->addWidget(printButton); | |
75 | rightPanelLayout->setStretch(0, 1); |
|
75 | rightPanelLayout->setStretch(0, 1); | |
76 | rightPanelLayout->setStretch(1, 0); |
|
76 | rightPanelLayout->setStretch(1, 0); | |
77 |
|
77 | |||
78 | QChart *chart = new QChart(); |
|
78 | QChart *chart = new QChart(); | |
79 | chart->setTitle("GDP by country"); |
|
79 | chart->setTitle("GDP by country"); | |
80 | chart->legend()->setVisible(true); |
|
80 | chart->legend()->setVisible(true); | |
81 |
|
81 | |||
82 | // main layout |
|
82 | // main layout | |
83 | chartView = new QChartView(chart); |
|
83 | chartView = new QChartView(chart); | |
84 | QGridLayout* mainLayout = new QGridLayout; |
|
84 | QGridLayout* mainLayout = new QGridLayout; | |
85 | mainLayout->addWidget(chartView, 0, 0); |
|
85 | mainLayout->addWidget(chartView, 0, 0); | |
86 | mainLayout->addLayout(rightPanelLayout, 0, 1); |
|
86 | mainLayout->addLayout(rightPanelLayout, 0, 1); | |
87 | mainLayout->setColumnStretch(0,1); |
|
87 | mainLayout->setColumnStretch(0,1); | |
88 | setLayout(mainLayout); |
|
88 | setLayout(mainLayout); | |
89 |
|
89 | |||
90 | // connect to the database |
|
90 | // connect to the database | |
91 | db = QSqlDatabase::addDatabase("QSQLITE"); |
|
91 | db = QSqlDatabase::addDatabase("QSQLITE"); | |
92 | db.setDatabaseName("gdpData"); |
|
92 | db.setDatabaseName("gdpData"); | |
93 | if(!db.open()) |
|
93 | if(!db.open()) | |
94 | { |
|
94 | { | |
95 | qDebug() << "could not open database. SQLite db file missing (?)"; |
|
95 | qDebug() << "could not open database. SQLite db file missing (?)"; | |
96 | return; |
|
96 | return; | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | // get the list of all countires and regions. |
|
99 | // get the list of all countires and regions. | |
100 | QSqlQuery query; |
|
100 | QSqlQuery query; | |
101 | query.exec("SELECT DISTINCT country FROM gdp2"); |
|
101 | query.exec("SELECT DISTINCT country FROM gdp2"); | |
102 |
|
102 | |||
103 | // add the countries to the country filter |
|
103 | // add the countries to the country filter | |
104 | while (query.next()) { |
|
104 | while (query.next()) { | |
105 | countrieslist->addItem(query.value(0).toString()); |
|
105 | countrieslist->addItem(query.value(0).toString()); | |
106 | } |
|
106 | } | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | Widget::~Widget() |
|
109 | Widget::~Widget() | |
110 | { |
|
110 | { | |
111 | // |
|
111 | // | |
112 | db.close(); |
|
112 | db.close(); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | refreshes the chart |
|
116 | refreshes the chart | |
117 | */ |
|
117 | */ | |
118 | void Widget::refreshChart() |
|
118 | void Widget::refreshChart() | |
119 | { |
|
119 | { | |
120 | chartView->chart()->removeAllSeries(); |
|
120 | chartView->chart()->removeAllSeries(); | |
121 |
|
121 | |||
122 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. |
|
122 | // selected countries items list is not sorted. copy the values to QStringlist and sort them. | |
123 | QStringList selectedCountriesStrings; |
|
123 | QStringList selectedCountriesStrings; | |
124 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); |
|
124 | QList<QListWidgetItem*> selectedCountriesItems = countrieslist->selectedItems(); | |
125 | for (int i = 0; i < selectedCountriesItems.size(); i++) |
|
125 | for (int i = 0; i < selectedCountriesItems.size(); i++) | |
126 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); |
|
126 | selectedCountriesStrings.append(selectedCountriesItems[i]->text()); | |
127 | selectedCountriesStrings.sort(); |
|
127 | selectedCountriesStrings.sort(); | |
128 |
|
128 | |||
129 | QSqlQuery query; |
|
129 | QSqlQuery query; | |
130 | // selected years items list is not sorted. copy the values to QList<int> and sort them. |
|
130 | // selected years items list is not sorted. copy the values to QList<int> and sort them. | |
131 | QList<int> selectedYearsInts; |
|
131 | QList<int> selectedYearsInts; | |
132 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); |
|
132 | QList<QListWidgetItem*> selectedYearsItems = yearslist->selectedItems(); | |
133 | for (int i = 0; i < selectedYearsItems.size(); i++) |
|
133 | for (int i = 0; i < selectedYearsItems.size(); i++) | |
134 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); |
|
134 | selectedYearsInts.append(selectedYearsItems[i]->text().toInt()); | |
135 | qSort(selectedYearsInts.begin(), selectedYearsInts.end()); |
|
135 | qSort(selectedYearsInts.begin(), selectedYearsInts.end()); | |
136 |
|
136 | |||
137 | if (barChartRadioButton->isChecked()) |
|
137 | if (barChartRadioButton->isChecked()) | |
138 | { |
|
138 | { | |
139 | // use the sorted selected coutries list to initialize BarCategory |
|
139 | // use the sorted selected coutries list to initialize BarCategory | |
140 | QStringList category; |
|
140 | QStringList category; | |
141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
141 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
142 | category << selectedCountriesStrings[i]; |
|
142 | category << selectedCountriesStrings[i]; | |
143 | QBarSeries* series0 = new QBarSeries(); |
|
143 | QBarSeries* series0 = new QBarSeries(); | |
144 |
|
|
144 | chartView->chart()->axisX()->categories()->insert(category); | |
145 | // series0 = new QBarSeries(category); |
|
|||
146 |
|
145 | |||
147 | // prepare the selected counries SQL query |
|
146 | // prepare the selected counries SQL query | |
148 | QString countriesQuery = "country IN ("; |
|
147 | QString countriesQuery = "country IN ("; | |
149 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
148 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
150 | { |
|
149 | { | |
151 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); |
|
150 | countriesQuery.append("'" + selectedCountriesStrings[i] + "'"); | |
152 | if ( i < selectedCountriesStrings.size() - 1) |
|
151 | if ( i < selectedCountriesStrings.size() - 1) | |
153 | countriesQuery.append(","); |
|
152 | countriesQuery.append(","); | |
154 | else |
|
153 | else | |
155 | countriesQuery.append(")"); |
|
154 | countriesQuery.append(")"); | |
156 | } |
|
155 | } | |
157 |
|
156 | |||
158 | // perform a query for each selected year |
|
157 | // perform a query for each selected year | |
159 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
158 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
160 | { |
|
159 | { | |
161 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); |
|
160 | query.exec("SELECT country,gdpvalue FROM gdp2 where year=" + QString("%1").arg(selectedYearsInts[i]) + " AND " + countriesQuery); | |
162 | QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i])); |
|
161 | QBarSet* barSet = new QBarSet(QString::number(selectedYearsInts[i])); | |
163 |
|
162 | |||
164 | // while (query.next()) { |
|
163 | // while (query.next()) { | |
165 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); |
|
164 | // qDebug() << query.value(0).toString() << " : " << query.value(1).toString(); | |
166 | // } |
|
165 | // } | |
167 | query.first(); |
|
166 | query.first(); | |
168 |
|
167 | |||
169 | // the data for some of the coutries for some years might be missing. |
|
168 | // the data for some of the coutries for some years might be missing. | |
170 | // QBarChart needs bars to have same size |
|
169 | // QBarChart needs bars to have same size | |
171 | for (int k = 0; k < selectedCountriesStrings.size(); k++) |
|
170 | for (int k = 0; k < selectedCountriesStrings.size(); k++) | |
172 | { |
|
171 | { | |
173 | if (selectedCountriesStrings[k] == query.value(0).toString()) |
|
172 | if (selectedCountriesStrings[k] == query.value(0).toString()) | |
174 | { |
|
173 | { | |
175 | *barSet << query.value(1).toReal(); |
|
174 | *barSet << query.value(1).toReal(); | |
176 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
175 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[i]); | |
177 | query.next(); |
|
176 | query.next(); | |
178 | } |
|
177 | } | |
179 | else |
|
178 | else | |
180 | { |
|
179 | { | |
181 | // data missing, put 0 |
|
180 | // data missing, put 0 | |
182 | *barSet << 0.0f; |
|
181 | *barSet << 0.0f; | |
183 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]); |
|
182 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]); | |
184 | } |
|
183 | } | |
185 | } |
|
184 | } | |
186 | series0->append(barSet); |
|
185 | series0->append(barSet); | |
187 | } |
|
186 | } | |
188 | // add the serie to the chart |
|
187 | // add the serie to the chart | |
189 | chartView->chart()->addSeries(series0); |
|
188 | chartView->chart()->addSeries(series0); | |
190 | } |
|
189 | } | |
191 | else if (scatterChartRadioButton->isChecked()) |
|
190 | else if (scatterChartRadioButton->isChecked()) | |
192 | { |
|
191 | { | |
193 | QString yearsQuery = "year IN ("; |
|
192 | QString yearsQuery = "year IN ("; | |
194 | for (int i = 0; i < selectedYearsInts.size(); i++) |
|
193 | for (int i = 0; i < selectedYearsInts.size(); i++) | |
195 | { |
|
194 | { | |
196 | yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'"); |
|
195 | yearsQuery.append("'" + QString("%1").arg(selectedYearsInts[i]) + "'"); | |
197 | if ( i < selectedYearsInts.size() - 1) |
|
196 | if ( i < selectedYearsInts.size() - 1) | |
198 | yearsQuery.append(","); |
|
197 | yearsQuery.append(","); | |
199 | else |
|
198 | else | |
200 | yearsQuery.append(")"); |
|
199 | yearsQuery.append(")"); | |
201 | } |
|
200 | } | |
202 |
|
201 | |||
203 | // perform a query for each selected country |
|
202 | // perform a query for each selected country | |
204 | for (int i = 0; i < selectedCountriesStrings.size(); i++) |
|
203 | for (int i = 0; i < selectedCountriesStrings.size(); i++) | |
205 | { |
|
204 | { | |
206 | query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery); |
|
205 | query.exec("SELECT year,gdpvalue FROM gdp2 where country='" + selectedCountriesStrings[i] + "' AND " + yearsQuery); | |
207 | query.first(); |
|
206 | query.first(); | |
208 |
|
207 | |||
209 | QScatterSeries* series = new QScatterSeries; |
|
208 | QScatterSeries* series = new QScatterSeries; | |
210 | series->setName(selectedCountriesStrings[i]); |
|
209 | series->setName(selectedCountriesStrings[i]); | |
211 | // the data for some of the coutries for some years might be missing. |
|
210 | // the data for some of the coutries for some years might be missing. | |
212 | for (int k = 0; k < selectedYearsInts.size(); k++) |
|
211 | for (int k = 0; k < selectedYearsInts.size(); k++) | |
213 | { |
|
212 | { | |
214 | if (selectedYearsInts[k] == query.value(0).toInt()) |
|
213 | if (selectedYearsInts[k] == query.value(0).toInt()) | |
215 | { |
|
214 | { | |
216 | *series << QPointF(query.value(0).toInt() , query.value(1).toReal()); |
|
215 | *series << QPointF(query.value(0).toInt() , query.value(1).toReal()); | |
217 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]); |
|
216 | qDebug() << query.value(0).toString() << query.value(1).toReal() << " : " << QString("%1").arg(selectedYearsInts[k]); | |
218 | query.next(); |
|
217 | query.next(); | |
219 | } |
|
218 | } | |
220 | else |
|
219 | else | |
221 | { |
|
220 | { | |
222 | // data missing, put 0 |
|
221 | // data missing, put 0 | |
223 | *series << QPointF(selectedYearsInts[k] , 0.0f); |
|
222 | *series << QPointF(selectedYearsInts[k] , 0.0f); | |
224 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); |
|
223 | qDebug() << "Putting 0 for the missing data" << " : " << QString("%1").arg(selectedYearsInts[i]) << " " << query.value(0).toInt(); | |
225 | } |
|
224 | } | |
226 | } |
|
225 | } | |
227 | // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); |
|
226 | // chartArea->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] + 1, selectedYearsInts[0] - 1); | |
228 | chartView->chart()->addSeries(series); |
|
227 | chartView->chart()->addSeries(series); | |
229 | } |
|
228 | } | |
230 | chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1); |
|
229 | chartView->chart()->axisX()->setRange(selectedYearsInts[selectedYearsInts.size() - 1] - 1, selectedYearsInts[0] + 1); | |
231 | } |
|
230 | } | |
232 | } |
|
231 | } | |
233 |
|
232 | |||
234 | void Widget::printChart() |
|
233 | void Widget::printChart() | |
235 | { |
|
234 | { | |
236 | QPrinter printer; |
|
235 | QPrinter printer; | |
237 | // QPrinter printer(QPrinter::HighResolution); |
|
236 | // QPrinter printer(QPrinter::HighResolution); | |
238 | printer.setOutputFormat(QPrinter::PdfFormat); |
|
237 | printer.setOutputFormat(QPrinter::PdfFormat); | |
239 | printer.setOrientation(QPrinter::Landscape); |
|
238 | printer.setOrientation(QPrinter::Landscape); | |
240 | printer.setOutputFileName("print.pdf"); |
|
239 | printer.setOutputFileName("print.pdf"); | |
241 |
|
240 | |||
242 | QPainter painter; |
|
241 | QPainter painter; | |
243 | painter.begin(&printer); |
|
242 | painter.begin(&printer); | |
244 | chartView->render(&painter); |
|
243 | chartView->render(&painter); | |
245 | } |
|
244 | } |
General Comments 0
You need to be logged in to leave comments.
Login now