@@ -1,386 +1,386 | |||||
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 <QAbstractBarSeries> | |
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 | #include <QCategoriesAxis> |
|
43 | #include <QCategoriesAxis> | |
44 |
|
44 | |||
45 | ThemeWidget::ThemeWidget(QWidget* parent) : |
|
45 | ThemeWidget::ThemeWidget(QWidget* parent) : | |
46 | QWidget(parent), |
|
46 | QWidget(parent), | |
47 | m_listCount(3), |
|
47 | m_listCount(3), | |
48 | m_valueMax(10), |
|
48 | m_valueMax(10), | |
49 | m_valueCount(7), |
|
49 | m_valueCount(7), | |
50 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), |
|
50 | m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)), | |
51 | m_themeComboBox(createThemeBox()), |
|
51 | m_themeComboBox(createThemeBox()), | |
52 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), |
|
52 | m_antialiasCheckBox(new QCheckBox("Anti-aliasing")), | |
53 | m_animatedComboBox(createAnimationBox()), |
|
53 | m_animatedComboBox(createAnimationBox()), | |
54 | m_legendComboBox(createLegendBox()) |
|
54 | m_legendComboBox(createLegendBox()) | |
55 | { |
|
55 | { | |
56 | connectSignals(); |
|
56 | connectSignals(); | |
57 | // create layout |
|
57 | // create layout | |
58 | QGridLayout* baseLayout = new QGridLayout(); |
|
58 | QGridLayout* baseLayout = new QGridLayout(); | |
59 | QHBoxLayout *settingsLayout = new QHBoxLayout(); |
|
59 | QHBoxLayout *settingsLayout = new QHBoxLayout(); | |
60 | settingsLayout->addWidget(new QLabel("Theme:")); |
|
60 | settingsLayout->addWidget(new QLabel("Theme:")); | |
61 | settingsLayout->addWidget(m_themeComboBox); |
|
61 | settingsLayout->addWidget(m_themeComboBox); | |
62 | settingsLayout->addWidget(new QLabel("Animation:")); |
|
62 | settingsLayout->addWidget(new QLabel("Animation:")); | |
63 | settingsLayout->addWidget(m_animatedComboBox); |
|
63 | settingsLayout->addWidget(m_animatedComboBox); | |
64 | settingsLayout->addWidget(new QLabel("Legend:")); |
|
64 | settingsLayout->addWidget(new QLabel("Legend:")); | |
65 | settingsLayout->addWidget(m_legendComboBox); |
|
65 | settingsLayout->addWidget(m_legendComboBox); | |
66 | settingsLayout->addWidget(m_antialiasCheckBox); |
|
66 | settingsLayout->addWidget(m_antialiasCheckBox); | |
67 | settingsLayout->addStretch(); |
|
67 | settingsLayout->addStretch(); | |
68 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); |
|
68 | baseLayout->addLayout(settingsLayout, 0, 0, 1, 3); | |
69 |
|
69 | |||
70 | //create charts |
|
70 | //create charts | |
71 |
|
71 | |||
72 | QChartView *chartView; |
|
72 | QChartView *chartView; | |
73 |
|
73 | |||
74 | chartView = new QChartView(createAreaChart()); |
|
74 | chartView = new QChartView(createAreaChart()); | |
75 | baseLayout->addWidget(chartView, 1, 0); |
|
75 | baseLayout->addWidget(chartView, 1, 0); | |
76 | m_charts << chartView; |
|
76 | m_charts << chartView; | |
77 |
|
77 | |||
78 | chartView = new QChartView(createBarChart(m_valueCount)); |
|
78 | chartView = new QChartView(createBarChart(m_valueCount)); | |
79 | baseLayout->addWidget(chartView, 1, 1); |
|
79 | baseLayout->addWidget(chartView, 1, 1); | |
80 | m_charts << chartView; |
|
80 | m_charts << chartView; | |
81 |
|
81 | |||
82 | chartView = new QChartView(createLineChart()); |
|
82 | chartView = new QChartView(createLineChart()); | |
83 | baseLayout->addWidget(chartView, 1, 2); |
|
83 | baseLayout->addWidget(chartView, 1, 2); | |
84 | m_charts << chartView; |
|
84 | m_charts << chartView; | |
85 |
|
85 | |||
86 | chartView = new QChartView(createPieChart()); |
|
86 | chartView = new QChartView(createPieChart()); | |
87 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... |
|
87 | chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen... | |
88 | baseLayout->addWidget(chartView, 2, 0); |
|
88 | baseLayout->addWidget(chartView, 2, 0); | |
89 | m_charts << chartView; |
|
89 | m_charts << chartView; | |
90 |
|
90 | |||
91 | chartView = new QChartView(createSplineChart()); |
|
91 | chartView = new QChartView(createSplineChart()); | |
92 | baseLayout->addWidget(chartView, 2, 1); |
|
92 | baseLayout->addWidget(chartView, 2, 1); | |
93 | m_charts << chartView; |
|
93 | m_charts << chartView; | |
94 |
|
94 | |||
95 | chartView = new QChartView(createScatterChart()); |
|
95 | chartView = new QChartView(createScatterChart()); | |
96 | baseLayout->addWidget(chartView, 2, 2); |
|
96 | baseLayout->addWidget(chartView, 2, 2); | |
97 | m_charts << chartView; |
|
97 | m_charts << chartView; | |
98 |
|
98 | |||
99 | setLayout(baseLayout); |
|
99 | setLayout(baseLayout); | |
100 |
|
100 | |||
101 | // Set defaults |
|
101 | // Set defaults | |
102 | m_antialiasCheckBox->setChecked(true); |
|
102 | m_antialiasCheckBox->setChecked(true); | |
103 | updateUI(); |
|
103 | updateUI(); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | ThemeWidget::~ThemeWidget() |
|
106 | ThemeWidget::~ThemeWidget() | |
107 | { |
|
107 | { | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void ThemeWidget::connectSignals() |
|
110 | void ThemeWidget::connectSignals() | |
111 | { |
|
111 | { | |
112 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
112 | connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
113 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
113 | connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
114 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
114 | connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
115 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
115 | connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const |
|
118 | DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const | |
119 | { |
|
119 | { | |
120 | DataTable dataTable; |
|
120 | DataTable dataTable; | |
121 |
|
121 | |||
122 | // set seed for random stuff |
|
122 | // set seed for random stuff | |
123 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); |
|
123 | qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime())); | |
124 |
|
124 | |||
125 | // generate random data |
|
125 | // generate random data | |
126 | for (int i(0); i < listCount; i++) { |
|
126 | for (int i(0); i < listCount; i++) { | |
127 | DataList dataList; |
|
127 | DataList dataList; | |
128 | qreal yValue(0); |
|
128 | qreal yValue(0); | |
129 | for (int j(0); j < valueCount; j++) { |
|
129 | for (int j(0); j < valueCount; j++) { | |
130 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; |
|
130 | yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount; | |
131 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), |
|
131 | QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount), | |
132 | yValue); |
|
132 | yValue); | |
133 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); |
|
133 | QString label = "Slice " + QString::number(i) + ":" + QString::number(j); | |
134 | dataList << Data(value, label); |
|
134 | dataList << Data(value, label); | |
135 | } |
|
135 | } | |
136 | dataTable << dataList; |
|
136 | dataTable << dataList; | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | return dataTable; |
|
139 | return dataTable; | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | QComboBox* ThemeWidget::createThemeBox() const |
|
142 | QComboBox* ThemeWidget::createThemeBox() const | |
143 | { |
|
143 | { | |
144 | // settings layout |
|
144 | // settings layout | |
145 | QComboBox* themeComboBox = new QComboBox(); |
|
145 | QComboBox* themeComboBox = new QComboBox(); | |
146 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
146 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
147 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
147 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
148 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
148 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
149 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
149 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
150 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
150 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
151 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
151 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
152 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
152 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
153 | return themeComboBox; |
|
153 | return themeComboBox; | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | QComboBox* ThemeWidget::createAnimationBox() const |
|
156 | QComboBox* ThemeWidget::createAnimationBox() const | |
157 | { |
|
157 | { | |
158 | // settings layout |
|
158 | // settings layout | |
159 | QComboBox* animationComboBox = new QComboBox(); |
|
159 | QComboBox* animationComboBox = new QComboBox(); | |
160 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
160 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
161 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
161 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
162 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
162 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
163 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
163 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
164 | return animationComboBox; |
|
164 | return animationComboBox; | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | QComboBox* ThemeWidget::createLegendBox() const |
|
167 | QComboBox* ThemeWidget::createLegendBox() const | |
168 | { |
|
168 | { | |
169 | QComboBox* legendComboBox = new QComboBox(); |
|
169 | QComboBox* legendComboBox = new QComboBox(); | |
170 | legendComboBox->addItem("No Legend ", 0); |
|
170 | legendComboBox->addItem("No Legend ", 0); | |
171 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
171 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
172 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
172 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
173 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
173 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); | |
174 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
174 | legendComboBox->addItem("Legend Right", Qt::AlignRight); | |
175 | return legendComboBox; |
|
175 | return legendComboBox; | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | QChart* ThemeWidget::createAreaChart() const |
|
178 | QChart* ThemeWidget::createAreaChart() const | |
179 | { |
|
179 | { | |
180 | QChart *chart = new QChart(); |
|
180 | QChart *chart = new QChart(); | |
181 | // chart->axisX()->setNiceNumbersEnabled(true); |
|
181 | // chart->axisX()->setNiceNumbersEnabled(true); | |
182 | // chart->axisY()->setNiceNumbersEnabled(true); |
|
182 | // chart->axisY()->setNiceNumbersEnabled(true); | |
183 | chart->setTitle("Area chart"); |
|
183 | chart->setTitle("Area chart"); | |
184 |
|
184 | |||
185 | // The lower series initialized to zero values |
|
185 | // The lower series initialized to zero values | |
186 | QLineSeries *lowerSeries = 0; |
|
186 | QLineSeries *lowerSeries = 0; | |
187 | QString name("Series "); |
|
187 | QString name("Series "); | |
188 | int nameIndex = 0; |
|
188 | int nameIndex = 0; | |
189 | for (int i(0); i < m_dataTable.count(); i++) { |
|
189 | for (int i(0); i < m_dataTable.count(); i++) { | |
190 | QLineSeries *upperSeries = new QLineSeries(chart); |
|
190 | QLineSeries *upperSeries = new QLineSeries(chart); | |
191 | for (int j(0); j < m_dataTable[i].count(); j++) { |
|
191 | for (int j(0); j < m_dataTable[i].count(); j++) { | |
192 | Data data = m_dataTable[i].at(j); |
|
192 | Data data = m_dataTable[i].at(j); | |
193 | if (lowerSeries){ |
|
193 | if (lowerSeries){ | |
194 | const QList<QPointF>& points = lowerSeries->points(); |
|
194 | const QList<QPointF>& points = lowerSeries->points(); | |
195 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); |
|
195 | upperSeries->append(QPointF(j, points[i].y() + data.first.y())); | |
196 | }else |
|
196 | }else | |
197 | upperSeries->append(QPointF(j, data.first.y())); |
|
197 | upperSeries->append(QPointF(j, data.first.y())); | |
198 | } |
|
198 | } | |
199 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); |
|
199 | QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries); | |
200 | area->setName(name + QString::number(nameIndex)); |
|
200 | area->setName(name + QString::number(nameIndex)); | |
201 | nameIndex++; |
|
201 | nameIndex++; | |
202 | chart->addSeries(area); |
|
202 | chart->addSeries(area); | |
203 | chart->createDefaultAxes(); |
|
203 | chart->createDefaultAxes(); | |
204 | lowerSeries = upperSeries; |
|
204 | lowerSeries = upperSeries; | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | return chart; |
|
207 | return chart; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | QChart* ThemeWidget::createBarChart(int valueCount) const |
|
210 | QChart* ThemeWidget::createBarChart(int valueCount) const | |
211 | { |
|
211 | { | |
212 | QChart* chart = new QChart(); |
|
212 | QChart* chart = new QChart(); | |
213 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
213 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
214 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
214 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
215 | chart->setTitle("Bar chart"); |
|
215 | chart->setTitle("Bar chart"); | |
216 |
|
216 | |||
217 | QStringList categories; |
|
217 | QStringList categories; | |
218 | for (int i(0); i < valueCount; i++) |
|
218 | for (int i(0); i < valueCount; i++) | |
219 | categories << QString::number(i); |
|
219 | categories << QString::number(i); | |
220 |
|
220 | |||
221 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
221 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
222 | axis->append(categories); |
|
222 | axis->append(categories); | |
223 |
|
223 | |||
224 | QStackedBarSeries* series = new QStackedBarSeries(chart); |
|
224 | QStackedBarSeries* series = new QStackedBarSeries(chart); | |
225 | for (int i(0); i < m_dataTable.count(); i++) { |
|
225 | for (int i(0); i < m_dataTable.count(); i++) { | |
226 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); |
|
226 | QBarSet *set = new QBarSet("Bar set " + QString::number(i)); | |
227 | foreach (Data data, m_dataTable[i]) |
|
227 | foreach (Data data, m_dataTable[i]) | |
228 | *set << data.first.y(); |
|
228 | *set << data.first.y(); | |
229 | series->append(set); |
|
229 | series->append(set); | |
230 | } |
|
230 | } | |
231 | chart->addSeries(series); |
|
231 | chart->addSeries(series); | |
232 | chart->createDefaultAxes(); |
|
232 | chart->createDefaultAxes(); | |
233 | chart->setAxisX(axis, series); |
|
233 | chart->setAxisX(axis, series); | |
234 |
|
234 | |||
235 | return chart; |
|
235 | return chart; | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | QChart* ThemeWidget::createLineChart() const |
|
238 | QChart* ThemeWidget::createLineChart() const | |
239 | { |
|
239 | { | |
240 | QChart* chart = new QChart(); |
|
240 | QChart* chart = new QChart(); | |
241 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
241 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
242 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
242 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
243 | chart->setTitle("Line chart"); |
|
243 | chart->setTitle("Line chart"); | |
244 |
|
244 | |||
245 | QString name("Series "); |
|
245 | QString name("Series "); | |
246 | int nameIndex = 0; |
|
246 | int nameIndex = 0; | |
247 | foreach (DataList list, m_dataTable) { |
|
247 | foreach (DataList list, m_dataTable) { | |
248 | QLineSeries *series = new QLineSeries(chart); |
|
248 | QLineSeries *series = new QLineSeries(chart); | |
249 | foreach (Data data, list) |
|
249 | foreach (Data data, list) | |
250 | series->append(data.first); |
|
250 | series->append(data.first); | |
251 | series->setName(name + QString::number(nameIndex)); |
|
251 | series->setName(name + QString::number(nameIndex)); | |
252 | nameIndex++; |
|
252 | nameIndex++; | |
253 | chart->addSeries(series); |
|
253 | chart->addSeries(series); | |
254 | chart->createDefaultAxes(); |
|
254 | chart->createDefaultAxes(); | |
255 |
|
255 | |||
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | return chart; |
|
258 | return chart; | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | QChart* ThemeWidget::createPieChart() const |
|
261 | QChart* ThemeWidget::createPieChart() const | |
262 | { |
|
262 | { | |
263 | QChart* chart = new QChart(); |
|
263 | QChart* chart = new QChart(); | |
264 | chart->setTitle("Pie chart"); |
|
264 | chart->setTitle("Pie chart"); | |
265 |
|
265 | |||
266 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
266 | qreal pieSize = 1.0 / m_dataTable.count(); | |
267 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
267 | for (int i = 0; i < m_dataTable.count(); i++) { | |
268 | QPieSeries *series = new QPieSeries(chart); |
|
268 | QPieSeries *series = new QPieSeries(chart); | |
269 | foreach (Data data, m_dataTable[i]) { |
|
269 | foreach (Data data, m_dataTable[i]) { | |
270 | QPieSlice *slice = series->append(data.second, data.first.y()); |
|
270 | QPieSlice *slice = series->append(data.second, data.first.y()); | |
271 | if (data == m_dataTable[i].first()) { |
|
271 | if (data == m_dataTable[i].first()) { | |
272 | slice->setLabelVisible(); |
|
272 | slice->setLabelVisible(); | |
273 | slice->setExploded(); |
|
273 | slice->setExploded(); | |
274 | } |
|
274 | } | |
275 | } |
|
275 | } | |
276 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
276 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
277 | series->setPieSize(pieSize); |
|
277 | series->setPieSize(pieSize); | |
278 | series->setHorizontalPosition(hPos); |
|
278 | series->setHorizontalPosition(hPos); | |
279 | series->setVerticalPosition(0.5); |
|
279 | series->setVerticalPosition(0.5); | |
280 | chart->addSeries(series); |
|
280 | chart->addSeries(series); | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | return chart; |
|
283 | return chart; | |
284 | } |
|
284 | } | |
285 |
|
285 | |||
286 | QChart* ThemeWidget::createSplineChart() const |
|
286 | QChart* ThemeWidget::createSplineChart() const | |
287 | { // spine chart |
|
287 | { // spine chart | |
288 | QChart* chart = new QChart(); |
|
288 | QChart* chart = new QChart(); | |
289 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
289 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
290 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
290 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
291 | chart->setTitle("Spline chart"); |
|
291 | chart->setTitle("Spline chart"); | |
292 | QString name("Series "); |
|
292 | QString name("Series "); | |
293 | int nameIndex = 0; |
|
293 | int nameIndex = 0; | |
294 | foreach (DataList list, m_dataTable) { |
|
294 | foreach (DataList list, m_dataTable) { | |
295 | QSplineSeries *series = new QSplineSeries(chart); |
|
295 | QSplineSeries *series = new QSplineSeries(chart); | |
296 | foreach (Data data, list) |
|
296 | foreach (Data data, list) | |
297 | series->append(data.first); |
|
297 | series->append(data.first); | |
298 | series->setName(name + QString::number(nameIndex)); |
|
298 | series->setName(name + QString::number(nameIndex)); | |
299 | nameIndex++; |
|
299 | nameIndex++; | |
300 | chart->addSeries(series); |
|
300 | chart->addSeries(series); | |
301 | chart->createDefaultAxes(); |
|
301 | chart->createDefaultAxes(); | |
302 | } |
|
302 | } | |
303 | return chart; |
|
303 | return chart; | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | QChart* ThemeWidget::createScatterChart() const |
|
306 | QChart* ThemeWidget::createScatterChart() const | |
307 | { // scatter chart |
|
307 | { // scatter chart | |
308 | QChart* chart = new QChart(); |
|
308 | QChart* chart = new QChart(); | |
309 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
309 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
310 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
310 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
311 | chart->setTitle("Scatter chart"); |
|
311 | chart->setTitle("Scatter chart"); | |
312 | QString name("Series "); |
|
312 | QString name("Series "); | |
313 | int nameIndex = 0; |
|
313 | int nameIndex = 0; | |
314 | foreach (DataList list, m_dataTable) { |
|
314 | foreach (DataList list, m_dataTable) { | |
315 | QScatterSeries *series = new QScatterSeries(chart); |
|
315 | QScatterSeries *series = new QScatterSeries(chart); | |
316 | foreach (Data data, list) |
|
316 | foreach (Data data, list) | |
317 | series->append(data.first); |
|
317 | series->append(data.first); | |
318 | series->setName(name + QString::number(nameIndex)); |
|
318 | series->setName(name + QString::number(nameIndex)); | |
319 | nameIndex++; |
|
319 | nameIndex++; | |
320 | chart->addSeries(series); |
|
320 | chart->addSeries(series); | |
321 | chart->createDefaultAxes(); |
|
321 | chart->createDefaultAxes(); | |
322 | } |
|
322 | } | |
323 | return chart; |
|
323 | return chart; | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | void ThemeWidget::updateUI() |
|
326 | void ThemeWidget::updateUI() | |
327 | { |
|
327 | { | |
328 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
328 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
329 |
|
329 | |||
330 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
330 | if (m_charts.at(0)->chart()->theme() != theme) { | |
331 | foreach (QChartView *chartView, m_charts) |
|
331 | foreach (QChartView *chartView, m_charts) | |
332 | chartView->chart()->setTheme(theme); |
|
332 | chartView->chart()->setTheme(theme); | |
333 |
|
333 | |||
334 | QPalette pal = window()->palette(); |
|
334 | QPalette pal = window()->palette(); | |
335 | if (theme == QChart::ChartThemeLight) { |
|
335 | if (theme == QChart::ChartThemeLight) { | |
336 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
336 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
338 | } else if (theme == QChart::ChartThemeDark) { |
|
338 | } else if (theme == QChart::ChartThemeDark) { | |
339 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
339 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
340 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
340 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
341 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
341 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
342 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
342 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
343 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
343 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
344 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
344 | } else if (theme == QChart::ChartThemeBrownSand) { | |
345 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
345 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
347 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
347 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
348 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
348 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
349 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
349 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
350 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
350 | } else if (theme == QChart::ChartThemeHighContrast) { | |
351 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
351 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
352 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
352 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
353 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
353 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
354 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
354 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
355 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
355 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
356 | } else { |
|
356 | } else { | |
357 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
357 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
358 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
358 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
359 | } |
|
359 | } | |
360 | window()->setPalette(pal); |
|
360 | window()->setPalette(pal); | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | bool checked = m_antialiasCheckBox->isChecked(); |
|
363 | bool checked = m_antialiasCheckBox->isChecked(); | |
364 | foreach (QChartView *chart, m_charts) |
|
364 | foreach (QChartView *chart, m_charts) | |
365 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
365 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
366 |
|
366 | |||
367 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
367 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
368 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
368 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
369 | foreach (QChartView *chartView, m_charts) |
|
369 | foreach (QChartView *chartView, m_charts) | |
370 | chartView->chart()->setAnimationOptions(options); |
|
370 | chartView->chart()->setAnimationOptions(options); | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
373 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
374 |
|
374 | |||
375 | if (!alignment) { |
|
375 | if (!alignment) { | |
376 | foreach (QChartView *chartView, m_charts) { |
|
376 | foreach (QChartView *chartView, m_charts) { | |
377 | chartView->chart()->legend()->hide(); |
|
377 | chartView->chart()->legend()->hide(); | |
378 | } |
|
378 | } | |
379 | } else { |
|
379 | } else { | |
380 | foreach (QChartView *chartView, m_charts) { |
|
380 | foreach (QChartView *chartView, m_charts) { | |
381 | chartView->chart()->legend()->setAlignment(alignment); |
|
381 | chartView->chart()->legend()->setAlignment(alignment); | |
382 | chartView->chart()->legend()->show(); |
|
382 | chartView->chart()->legend()->show(); | |
383 | } |
|
383 | } | |
384 | } |
|
384 | } | |
385 | } |
|
385 | } | |
386 |
|
386 |
@@ -1,40 +1,40 | |||||
1 | INCLUDEPATH += $$PWD |
|
1 | INCLUDEPATH += $$PWD | |
2 | DEPENDPATH += $$PWD |
|
2 | DEPENDPATH += $$PWD | |
3 |
|
3 | |||
4 | SOURCES += \ |
|
4 | SOURCES += \ | |
5 | $$PWD/bar.cpp \ |
|
5 | $$PWD/bar.cpp \ | |
6 | $$PWD/barchartitem.cpp \ |
|
6 | $$PWD/barchartitem.cpp \ | |
7 | $$PWD/percentbarchartitem.cpp \ |
|
7 | $$PWD/percentbarchartitem.cpp \ | |
8 | $$PWD/groupedbarchartitem.cpp \ |
|
8 | $$PWD/groupedbarchartitem.cpp \ | |
9 | $$PWD/qbarseries.cpp \ |
|
9 | $$PWD/qabstractbarseries.cpp \ | |
10 | $$PWD/qbarset.cpp \ |
|
10 | $$PWD/qbarset.cpp \ | |
11 | $$PWD/qpercentbarseries.cpp \ |
|
11 | $$PWD/qpercentbarseries.cpp \ | |
12 | $$PWD/qstackedbarseries.cpp \ |
|
12 | $$PWD/qstackedbarseries.cpp \ | |
13 | $$PWD/qgroupedbarseries.cpp \ |
|
13 | $$PWD/qgroupedbarseries.cpp \ | |
14 | $$PWD/stackedbarchartitem.cpp \ |
|
14 | $$PWD/stackedbarchartitem.cpp \ | |
15 | $$PWD/qbarmodelmapper.cpp \ |
|
15 | $$PWD/qbarmodelmapper.cpp \ | |
16 | $$PWD/qvbarmodelmapper.cpp \ |
|
16 | $$PWD/qvbarmodelmapper.cpp \ | |
17 | $$PWD/qhbarmodelmapper.cpp |
|
17 | $$PWD/qhbarmodelmapper.cpp | |
18 |
|
18 | |||
19 | PRIVATE_HEADERS += \ |
|
19 | PRIVATE_HEADERS += \ | |
20 | $$PWD/bar_p.h \ |
|
20 | $$PWD/bar_p.h \ | |
21 | $$PWD/barchartitem_p.h \ |
|
21 | $$PWD/barchartitem_p.h \ | |
22 | $$PWD/percentbarchartitem_p.h \ |
|
22 | $$PWD/percentbarchartitem_p.h \ | |
23 | $$PWD/stackedbarchartitem_p.h \ |
|
23 | $$PWD/stackedbarchartitem_p.h \ | |
24 | $$PWD/groupedbarchartitem_p.h \ |
|
24 | $$PWD/groupedbarchartitem_p.h \ | |
25 | $$PWD/qbarset_p.h \ |
|
25 | $$PWD/qbarset_p.h \ | |
26 | $$PWD/qbarseries_p.h \ |
|
26 | $$PWD/qabstractbarseries_p.h \ | |
27 | $$PWD/qstackedbarseries_p.h\ |
|
27 | $$PWD/qstackedbarseries_p.h\ | |
28 | $$PWD/qpercentbarseries_p.h \ |
|
28 | $$PWD/qpercentbarseries_p.h \ | |
29 | $$PWD/qgroupedbarseries_p.h \ |
|
29 | $$PWD/qgroupedbarseries_p.h \ | |
30 | $$PWD/qbarmodelmapper_p.h |
|
30 | $$PWD/qbarmodelmapper_p.h | |
31 |
|
31 | |||
32 | PUBLIC_HEADERS += \ |
|
32 | PUBLIC_HEADERS += \ | |
33 | $$PWD/qbarseries.h \ |
|
33 | $$PWD/qabstractbarseries.h \ | |
34 | $$PWD/qbarset.h \ |
|
34 | $$PWD/qbarset.h \ | |
35 | $$PWD/qpercentbarseries.h \ |
|
35 | $$PWD/qpercentbarseries.h \ | |
36 | $$PWD/qstackedbarseries.h \ |
|
36 | $$PWD/qstackedbarseries.h \ | |
37 | $$PWD/qgroupedbarseries.h \ |
|
37 | $$PWD/qgroupedbarseries.h \ | |
38 | $$PWD/qbarmodelmapper.h \ |
|
38 | $$PWD/qbarmodelmapper.h \ | |
39 | $$PWD/qvbarmodelmapper.h \ |
|
39 | $$PWD/qvbarmodelmapper.h \ | |
40 | $$PWD/qhbarmodelmapper.h |
|
40 | $$PWD/qhbarmodelmapper.h |
@@ -1,226 +1,226 | |||||
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 "qabstractbarseries.h" | |
26 | #include "qbarseries_p.h" |
|
26 | #include "qabstractbarseries_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(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
35 | BarChartItem::BarChartItem(QAbstractBarSeries *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(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
41 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
42 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
42 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
43 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); |
|
43 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); | |
44 | setZValue(ChartPresenter::BarSeriesZValue); |
|
44 | setZValue(ChartPresenter::BarSeriesZValue); | |
45 | handleDataStructureChanged(); |
|
45 | handleDataStructureChanged(); | |
46 | } |
|
46 | } | |
47 |
|
47 | |||
48 | BarChartItem::~BarChartItem() |
|
48 | BarChartItem::~BarChartItem() | |
49 | { |
|
49 | { | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
52 | void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
53 | { |
|
53 | { | |
54 | Q_UNUSED(painter); |
|
54 | Q_UNUSED(painter); | |
55 | Q_UNUSED(option); |
|
55 | Q_UNUSED(option); | |
56 | Q_UNUSED(widget); |
|
56 | Q_UNUSED(widget); | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | QRectF BarChartItem::boundingRect() const |
|
59 | QRectF BarChartItem::boundingRect() const | |
60 | { |
|
60 | { | |
61 | return m_rect; |
|
61 | return m_rect; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | QVector<QRectF> BarChartItem::calculateLayout() |
|
64 | QVector<QRectF> BarChartItem::calculateLayout() | |
65 | { |
|
65 | { | |
66 | QVector<QRectF> layout; |
|
66 | QVector<QRectF> layout; | |
67 |
|
67 | |||
68 | // Use temporary qreals for accuracy |
|
68 | // Use temporary qreals for accuracy | |
69 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
69 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
70 | qreal setCount = m_series->count(); |
|
70 | qreal setCount = m_series->count(); | |
71 | bool barsVisible = m_series->isVisible(); |
|
71 | bool barsVisible = m_series->isVisible(); | |
72 |
|
72 | |||
73 | // Domain: |
|
73 | // Domain: | |
74 | qreal width = geometry().width(); |
|
74 | qreal width = geometry().width(); | |
75 | qreal height = geometry().height(); |
|
75 | qreal height = geometry().height(); | |
76 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
76 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
77 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
77 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
78 | qreal scaleY = (height / rangeY); |
|
78 | qreal scaleY = (height / rangeY); | |
79 | qreal scaleX = (width / rangeX); |
|
79 | qreal scaleX = (width / rangeX); | |
80 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); |
|
80 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); | |
81 |
|
81 | |||
82 | int itemIndex(0); |
|
82 | int itemIndex(0); | |
83 | for (int category = 0; category < categoryCount; category++) { |
|
83 | for (int category = 0; category < categoryCount; category++) { | |
84 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
84 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
85 | for (int set = 0; set < setCount; set++) { |
|
85 | for (int set = 0; set < setCount; set++) { | |
86 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
86 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
87 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
87 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
88 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; |
|
88 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; | |
89 |
|
89 | |||
90 | Bar* bar = m_bars.at(itemIndex); |
|
90 | Bar* bar = m_bars.at(itemIndex); | |
91 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
91 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
92 |
|
92 | |||
93 | layout.append(rect); |
|
93 | layout.append(rect); | |
94 | bar->setPen(barSet->m_pen); |
|
94 | bar->setPen(barSet->m_pen); | |
95 | bar->setBrush(barSet->m_brush); |
|
95 | bar->setBrush(barSet->m_brush); | |
96 | bar->setVisible(barsVisible); |
|
96 | bar->setVisible(barsVisible); | |
97 |
|
97 | |||
98 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
98 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
99 |
|
99 | |||
100 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { |
|
100 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { | |
101 | label->setText(QString::number(barSet->m_values.at(category).y())); |
|
101 | label->setText(QString::number(barSet->m_values.at(category).y())); | |
102 | } else { |
|
102 | } else { | |
103 | label->setText(QString("")); |
|
103 | label->setText(QString("")); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
106 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
107 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
107 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
108 | label->setFont(barSet->m_labelFont); |
|
108 | label->setFont(barSet->m_labelFont); | |
109 | label->setBrush(barSet->m_labelBrush); |
|
109 | label->setBrush(barSet->m_labelBrush); | |
110 |
|
110 | |||
111 | itemIndex++; |
|
111 | itemIndex++; | |
112 | } |
|
112 | } | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | return layout; |
|
115 | return layout; | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
118 | void BarChartItem::applyLayout(const QVector<QRectF> &layout) | |
119 | { |
|
119 | { | |
120 | if (animator()) { |
|
120 | if (animator()) { | |
121 | animator()->updateLayout(this, m_layout, layout); |
|
121 | animator()->updateLayout(this, m_layout, layout); | |
122 | } else { |
|
122 | } else { | |
123 | setLayout(layout); |
|
123 | setLayout(layout); | |
124 | update(); |
|
124 | update(); | |
125 | } |
|
125 | } | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | void BarChartItem::setLayout(const QVector<QRectF> &layout) |
|
128 | void BarChartItem::setLayout(const QVector<QRectF> &layout) | |
129 | { |
|
129 | { | |
130 | if (layout.count() != m_bars.count()) |
|
130 | if (layout.count() != m_bars.count()) | |
131 | return; |
|
131 | return; | |
132 |
|
132 | |||
133 | m_layout = layout; |
|
133 | m_layout = layout; | |
134 |
|
134 | |||
135 | for (int i=0; i < m_bars.count(); i++) { |
|
135 | for (int i=0; i < m_bars.count(); i++) { | |
136 | m_bars.at(i)->setRect(layout.at(i)); |
|
136 | m_bars.at(i)->setRect(layout.at(i)); | |
137 | } |
|
137 | } | |
138 | } |
|
138 | } | |
139 | //handlers |
|
139 | //handlers | |
140 |
|
140 | |||
141 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
141 | void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
142 | { |
|
142 | { | |
143 | m_domainMinX = minX; |
|
143 | m_domainMinX = minX; | |
144 | m_domainMaxX = maxX; |
|
144 | m_domainMaxX = maxX; | |
145 | m_domainMinY = minY; |
|
145 | m_domainMinY = minY; | |
146 | m_domainMaxY = maxY; |
|
146 | m_domainMaxY = maxY; | |
147 | handleLayoutChanged(); |
|
147 | handleLayoutChanged(); | |
148 | } |
|
148 | } | |
149 |
|
149 | |||
150 | void BarChartItem::handleGeometryChanged(const QRectF &rect) |
|
150 | void BarChartItem::handleGeometryChanged(const QRectF &rect) | |
151 | { |
|
151 | { | |
152 | prepareGeometryChange(); |
|
152 | prepareGeometryChange(); | |
153 | m_rect = rect; |
|
153 | m_rect = rect; | |
154 | handleLayoutChanged(); |
|
154 | handleLayoutChanged(); | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | void BarChartItem::handleLayoutChanged() |
|
157 | void BarChartItem::handleLayoutChanged() | |
158 | { |
|
158 | { | |
159 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
159 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
160 | // rect size zero. |
|
160 | // rect size zero. | |
161 | return; |
|
161 | return; | |
162 | } |
|
162 | } | |
163 | QVector<QRectF> layout = calculateLayout(); |
|
163 | QVector<QRectF> layout = calculateLayout(); | |
164 | applyLayout(layout); |
|
164 | applyLayout(layout); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 |
|
167 | |||
168 |
|
168 | |||
169 | void BarChartItem::handleLabelsVisibleChanged(bool visible) |
|
169 | void BarChartItem::handleLabelsVisibleChanged(bool visible) | |
170 | { |
|
170 | { | |
171 | foreach (QGraphicsSimpleTextItem* label, m_labels) { |
|
171 | foreach (QGraphicsSimpleTextItem* label, m_labels) { | |
172 | label->setVisible(visible); |
|
172 | label->setVisible(visible); | |
173 | } |
|
173 | } | |
174 | update(); |
|
174 | update(); | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void BarChartItem::handleDataStructureChanged() |
|
177 | void BarChartItem::handleDataStructureChanged() | |
178 | { |
|
178 | { | |
179 | foreach(QGraphicsItem *item, childItems()) { |
|
179 | foreach(QGraphicsItem *item, childItems()) { | |
180 | delete item; |
|
180 | delete item; | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | m_bars.clear(); |
|
183 | m_bars.clear(); | |
184 | m_labels.clear(); |
|
184 | m_labels.clear(); | |
185 | m_layout.clear(); |
|
185 | m_layout.clear(); | |
186 |
|
186 | |||
187 | bool labelsVisible = m_series->isLabelsVisible(); |
|
187 | bool labelsVisible = m_series->isLabelsVisible(); | |
188 |
|
188 | |||
189 | // Create new graphic items for bars |
|
189 | // Create new graphic items for bars | |
190 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { |
|
190 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
191 | for (int s = 0; s < m_series->count(); s++) { |
|
191 | for (int s = 0; s < m_series->count(); s++) { | |
192 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
192 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
193 |
|
193 | |||
194 | // Bars |
|
194 | // Bars | |
195 | Bar *bar = new Bar(set,c,this); |
|
195 | Bar *bar = new Bar(set,c,this); | |
196 | m_bars.append(bar); |
|
196 | m_bars.append(bar); | |
197 | connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*))); |
|
197 | connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*))); | |
198 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*))); |
|
198 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*))); | |
199 | connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int))); |
|
199 | connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int))); | |
200 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool))); |
|
200 | connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool))); | |
201 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
201 | m_layout.append(QRectF(0, 0, 0, 0)); | |
202 |
|
202 | |||
203 | // Labels |
|
203 | // Labels | |
204 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); |
|
204 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
205 | label->setVisible(labelsVisible); |
|
205 | label->setVisible(labelsVisible); | |
206 | m_labels.append(label); |
|
206 | m_labels.append(label); | |
207 | } |
|
207 | } | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | // TODO: Is this the right place to call it? |
|
210 | // TODO: Is this the right place to call it? | |
211 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
211 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
212 | handleLayoutChanged(); |
|
212 | handleLayoutChanged(); | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | void BarChartItem::handleVisibleChanged() |
|
215 | void BarChartItem::handleVisibleChanged() | |
216 | { |
|
216 | { | |
217 | bool visible = m_series->isVisible(); |
|
217 | bool visible = m_series->isVisible(); | |
218 | handleLabelsVisibleChanged(visible); |
|
218 | handleLabelsVisibleChanged(visible); | |
219 | foreach(QGraphicsItem *item, childItems()) { |
|
219 | foreach(QGraphicsItem *item, childItems()) { | |
220 | item->setVisible(visible); |
|
220 | item->setVisible(visible); | |
221 | } |
|
221 | } | |
222 | } |
|
222 | } | |
223 |
|
223 | |||
224 | #include "moc_barchartitem_p.cpp" |
|
224 | #include "moc_barchartitem_p.cpp" | |
225 |
|
225 | |||
226 | QTCOMMERCIALCHART_END_NAMESPACE |
|
226 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,89 +1,89 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // 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 |
|
30 | |||
31 | #ifndef BARCHARTITEM_H |
|
31 | #ifndef BARCHARTITEM_H | |
32 | #define BARCHARTITEM_H |
|
32 | #define BARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "qbarseries.h" |
|
35 | #include "qabstractbarseries.h" | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QBrush> |
|
37 | #include <QBrush> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class Bar; |
|
41 | class Bar; | |
42 | class QAxisCategories; |
|
42 | class QAxisCategories; | |
43 | class QChart; |
|
43 | class QChart; | |
44 |
|
44 | |||
45 | class BarChartItem : public ChartItem |
|
45 | class BarChartItem : public ChartItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); |
|
49 | BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); | |
50 | virtual ~BarChartItem(); |
|
50 | virtual ~BarChartItem(); | |
51 |
|
51 | |||
52 | public: |
|
52 | public: | |
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
54 | QRectF boundingRect() const; |
|
54 | QRectF boundingRect() const; | |
55 |
|
55 | |||
56 | virtual QVector<QRectF> calculateLayout(); |
|
56 | virtual QVector<QRectF> calculateLayout(); | |
57 | virtual void applyLayout(const QVector<QRectF> &layout); |
|
57 | virtual void applyLayout(const QVector<QRectF> &layout); | |
58 | void setLayout(const QVector<QRectF> &layout); |
|
58 | void setLayout(const QVector<QRectF> &layout); | |
59 | void updateLayout(const QVector<QRectF> &layout); |
|
59 | void updateLayout(const QVector<QRectF> &layout); | |
60 |
|
60 | |||
61 | QRectF geometry() const { return m_rect;} |
|
61 | QRectF geometry() const { return m_rect;} | |
62 |
|
62 | |||
63 | public Q_SLOTS: |
|
63 | public Q_SLOTS: | |
64 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
64 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
65 | void handleGeometryChanged(const QRectF &size); |
|
65 | void handleGeometryChanged(const QRectF &size); | |
66 | void handleLayoutChanged(); |
|
66 | void handleLayoutChanged(); | |
67 | void handleLabelsVisibleChanged(bool visible); |
|
67 | void handleLabelsVisibleChanged(bool visible); | |
68 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
|
68 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items | |
69 | void handleVisibleChanged(); |
|
69 | void handleVisibleChanged(); | |
70 |
|
70 | |||
71 | protected: |
|
71 | protected: | |
72 |
|
72 | |||
73 | qreal m_domainMinX; |
|
73 | qreal m_domainMinX; | |
74 | qreal m_domainMaxX; |
|
74 | qreal m_domainMaxX; | |
75 | qreal m_domainMinY; |
|
75 | qreal m_domainMinY; | |
76 | qreal m_domainMaxY; |
|
76 | qreal m_domainMaxY; | |
77 |
|
77 | |||
78 | QRectF m_rect; |
|
78 | QRectF m_rect; | |
79 | QVector<QRectF> m_layout; |
|
79 | QVector<QRectF> m_layout; | |
80 |
|
80 | |||
81 | // Not owned. |
|
81 | // Not owned. | |
82 | QAbstractBarSeries *m_series; |
|
82 | QAbstractBarSeries *m_series; | |
83 | QList<Bar *> m_bars; |
|
83 | QList<Bar *> m_bars; | |
84 | QList<QGraphicsSimpleTextItem *> m_labels; |
|
84 | QList<QGraphicsSimpleTextItem *> m_labels; | |
85 | }; |
|
85 | }; | |
86 |
|
86 | |||
87 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
88 |
|
88 | |||
89 | #endif // BARCHARTITEM_H |
|
89 | #endif // BARCHARTITEM_H |
@@ -1,92 +1,92 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "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 "qabstractbarseries_p.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
26 | #include "qbarset_p.h" |
|
26 | #include "qbarset_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | GroupedBarChartItem::GroupedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
30 | GroupedBarChartItem::GroupedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
31 | BarChartItem(series, presenter) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QVector<QRectF> GroupedBarChartItem::calculateLayout() |
|
35 | QVector<QRectF> GroupedBarChartItem::calculateLayout() | |
36 | { |
|
36 | { | |
37 | QVector<QRectF> layout; |
|
37 | QVector<QRectF> layout; | |
38 |
|
38 | |||
39 | // Use temporary qreals for accuracy |
|
39 | // Use temporary qreals for accuracy | |
40 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
40 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
41 | qreal setCount = m_series->count(); |
|
41 | qreal setCount = m_series->count(); | |
42 | bool barsVisible = m_series->isVisible(); |
|
42 | bool barsVisible = m_series->isVisible(); | |
43 |
|
43 | |||
44 | // Domain: |
|
44 | // Domain: | |
45 | qreal width = geometry().width(); |
|
45 | qreal width = geometry().width(); | |
46 | qreal height = geometry().height(); |
|
46 | qreal height = geometry().height(); | |
47 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
47 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
48 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
48 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
49 | qreal scaleY = (height / rangeY); |
|
49 | qreal scaleY = (height / rangeY); | |
50 | qreal scaleX = (width / rangeX); |
|
50 | qreal scaleX = (width / rangeX); | |
51 | qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth(); |
|
51 | qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth(); | |
52 |
|
52 | |||
53 | int itemIndex(0); |
|
53 | int itemIndex(0); | |
54 | for (int category = 0; category < categoryCount; category++) { |
|
54 | for (int category = 0; category < categoryCount; category++) { | |
55 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
55 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
56 | for (int set = 0; set < setCount; set++) { |
|
56 | for (int set = 0; set < setCount; set++) { | |
57 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
57 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
58 |
|
58 | |||
59 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left(); |
|
59 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left(); | |
60 | xPos -= setCount*barWidth/2; |
|
60 | xPos -= setCount*barWidth/2; | |
61 | xPos += set*barWidth; |
|
61 | xPos += set*barWidth; | |
62 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; |
|
62 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; | |
63 | Bar* bar = m_bars.at(itemIndex); |
|
63 | Bar* bar = m_bars.at(itemIndex); | |
64 |
|
64 | |||
65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); |
|
65 | QRectF rect(xPos, yPos - barHeight, barWidth, barHeight); | |
66 | layout.append(rect); |
|
66 | layout.append(rect); | |
67 | bar->setPen(barSet->m_pen); |
|
67 | bar->setPen(barSet->m_pen); | |
68 | bar->setBrush(barSet->m_brush); |
|
68 | bar->setBrush(barSet->m_brush); | |
69 | bar->setVisible(barsVisible); |
|
69 | bar->setVisible(barsVisible); | |
70 |
|
70 | |||
71 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
71 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
72 |
|
72 | |||
73 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { |
|
73 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { | |
74 | label->setText(QString::number(barSet->m_values.at(category).y())); |
|
74 | label->setText(QString::number(barSet->m_values.at(category).y())); | |
75 | } else { |
|
75 | } else { | |
76 | label->setText(QString("")); |
|
76 | label->setText(QString("")); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
79 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
79 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
80 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
80 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
81 | label->setFont(barSet->m_labelFont); |
|
81 | label->setFont(barSet->m_labelFont); | |
82 | label->setBrush(barSet->m_labelBrush); |
|
82 | label->setBrush(barSet->m_labelBrush); | |
83 |
|
83 | |||
84 | itemIndex++; |
|
84 | itemIndex++; | |
85 | } |
|
85 | } | |
86 | } |
|
86 | } | |
87 | return layout; |
|
87 | return layout; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | #include "moc_groupedbarchartitem_p.cpp" |
|
90 | #include "moc_groupedbarchartitem_p.cpp" | |
91 |
|
91 | |||
92 | QTCOMMERCIALCHART_END_NAMESPACE |
|
92 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,107 +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 "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 "qabstractbarseries_p.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "chartanimator_p.h" |
|
25 | #include "chartanimator_p.h" | |
26 | #include "qbarset_p.h" |
|
26 | #include "qbarset_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
30 | PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
31 | BarChartItem(series, presenter) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QVector<QRectF> PercentBarChartItem::calculateLayout() |
|
35 | QVector<QRectF> PercentBarChartItem::calculateLayout() | |
36 | { |
|
36 | { | |
37 | QVector<QRectF> layout; |
|
37 | QVector<QRectF> layout; | |
38 |
|
38 | |||
39 | // Use temporary qreals for accuracy |
|
39 | // Use temporary qreals for accuracy | |
40 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
40 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
41 | qreal setCount = m_series->count(); |
|
41 | qreal setCount = m_series->count(); | |
42 | bool barsVisible = m_series->isVisible(); |
|
42 | bool barsVisible = m_series->isVisible(); | |
43 |
|
43 | |||
44 | // Domain: |
|
44 | // Domain: | |
45 | qreal width = geometry().width(); |
|
45 | qreal width = geometry().width(); | |
46 | qreal height = geometry().height(); |
|
46 | qreal height = geometry().height(); | |
47 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
47 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
48 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
48 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
49 | qreal scaleY = (height / rangeY); |
|
49 | qreal scaleY = (height / rangeY); | |
50 | qreal scaleX = (width / rangeX); |
|
50 | qreal scaleX = (width / rangeX); | |
51 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); |
|
51 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); | |
52 |
|
52 | |||
53 | int itemIndex(0); |
|
53 | int itemIndex(0); | |
54 | for (int category = 0; category < categoryCount; category++) { |
|
54 | for (int category = 0; category < categoryCount; category++) { | |
55 | qreal colSum = m_series->d_func()->categorySum(category); |
|
55 | qreal colSum = m_series->d_func()->categorySum(category); | |
56 | qreal percentage = (100 / colSum); |
|
56 | qreal percentage = (100 / colSum); | |
57 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); |
|
57 | qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y(); | |
58 | for (int set=0; set < setCount; set++) { |
|
58 | for (int set=0; set < setCount; set++) { | |
59 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
59 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
60 |
|
60 | |||
61 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
61 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
62 |
|
62 | |||
63 | qreal barHeight = barSet->m_values.at(category).y() * percentage * scaleY; |
|
63 | qreal barHeight = barSet->m_values.at(category).y() * percentage * scaleY; | |
64 | Bar* bar = m_bars.at(itemIndex); |
|
64 | Bar* bar = m_bars.at(itemIndex); | |
65 | bar->setPen(barSet->m_pen); |
|
65 | bar->setPen(barSet->m_pen); | |
66 | bar->setBrush(barSet->m_brush); |
|
66 | bar->setBrush(barSet->m_brush); | |
67 | bar->setVisible(barsVisible); |
|
67 | bar->setVisible(barsVisible); | |
68 |
|
68 | |||
69 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); |
|
69 | QRectF rect(xPos, yPos-barHeight, barWidth, barHeight); | |
70 | layout.append(rect); |
|
70 | layout.append(rect); | |
71 |
|
71 | |||
72 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
72 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
73 |
|
73 | |||
74 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { |
|
74 | if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) { | |
75 | int p = m_series->d_func()->percentageAt(set,category) * 100; |
|
75 | int p = m_series->d_func()->percentageAt(set,category) * 100; | |
76 | QString vString(QString::number(p)); |
|
76 | QString vString(QString::number(p)); | |
77 | vString.truncate(3); |
|
77 | vString.truncate(3); | |
78 | vString.append("%"); |
|
78 | vString.append("%"); | |
79 | label->setText(vString); |
|
79 | label->setText(vString); | |
80 | } else { |
|
80 | } else { | |
81 | label->setText(QString("")); |
|
81 | label->setText(QString("")); | |
82 | } |
|
82 | } | |
83 |
|
83 | |||
84 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) |
|
84 | label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2) | |
85 | ,yPos - barHeight/2 - label->boundingRect().height()/2); |
|
85 | ,yPos - barHeight/2 - label->boundingRect().height()/2); | |
86 | label->setFont(barSet->m_labelFont); |
|
86 | label->setFont(barSet->m_labelFont); | |
87 | label->setBrush(barSet->m_labelBrush); |
|
87 | label->setBrush(barSet->m_labelBrush); | |
88 |
|
88 | |||
89 | itemIndex++; |
|
89 | itemIndex++; | |
90 | yPos -= barHeight; |
|
90 | yPos -= barHeight; | |
91 | } |
|
91 | } | |
92 | } |
|
92 | } | |
93 | return layout; |
|
93 | return layout; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void PercentBarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
96 | void PercentBarChartItem::applyLayout(const QVector<QRectF> &layout) | |
97 | { |
|
97 | { | |
98 | if (animator()) { |
|
98 | if (animator()) { | |
99 | animator()->updateLayout(this, m_layout, layout); |
|
99 | animator()->updateLayout(this, m_layout, layout); | |
100 | } else { |
|
100 | } else { | |
101 | setLayout(layout); |
|
101 | setLayout(layout); | |
102 | update(); |
|
102 | update(); | |
103 | } |
|
103 | } | |
104 | } |
|
104 | } | |
105 | #include "moc_percentbarchartitem_p.cpp" |
|
105 | #include "moc_percentbarchartitem_p.cpp" | |
106 |
|
106 | |||
107 | QTCOMMERCIALCHART_END_NAMESPACE |
|
107 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,732 +1,732 | |||||
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 "qabstractbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qabstractbarseries_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 | #include "qvaluesaxis.h" |
|
30 | #include "qvaluesaxis.h" | |
31 | #include "qcategoriesaxis.h" |
|
31 | #include "qcategoriesaxis.h" | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QBarSeries |
|
36 | \class QAbstractBarSeries | |
37 | \brief Series for creating a bar chart |
|
37 | \brief Series for creating a bar chart | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
40 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
41 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
42 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
43 | shows the x-values. |
|
43 | shows the x-values. | |
44 |
|
44 | |||
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
46 | \image examples_barchart.png |
|
46 | \image examples_barchart.png | |
47 |
|
47 | |||
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
49 | */ |
|
49 | */ | |
50 | /*! |
|
50 | /*! | |
51 | \qmlclass BarSeries QBarSeries |
|
51 | \qmlclass BarSeries QAbstractBarSeries | |
52 | \inherits AbstractSeries |
|
52 | \inherits AbstractSeries | |
53 |
|
53 | |||
54 | The following QML shows how to create a simple bar chart: |
|
54 | The following QML shows how to create a simple bar chart: | |
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
55 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
56 |
|
56 | |||
57 | \beginfloatleft |
|
57 | \beginfloatleft | |
58 | \image demos_qmlchart6.png |
|
58 | \image demos_qmlchart6.png | |
59 | \endfloat |
|
59 | \endfloat | |
60 | \clearfloat |
|
60 | \clearfloat | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSeries::barWidth |
|
64 | \property QAbstractBarSeries::barWidth | |
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
65 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
66 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
67 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
68 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
69 | \sa QGroupedBarSeries |
|
69 | \sa QGroupedBarSeries | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty real BarSeries::barWidth |
|
72 | \qmlproperty real BarSeries::barWidth | |
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
73 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
74 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
75 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. |
|
76 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QBarSeries::count |
|
80 | \property QAbstractBarSeries::count | |
81 | Holds the number of sets in series. |
|
81 | Holds the number of sets in series. | |
82 | */ |
|
82 | */ | |
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty int BarSeries::count |
|
84 | \qmlproperty int BarSeries::count | |
85 | Holds the number of sets in series. |
|
85 | Holds the number of sets in series. | |
86 | */ |
|
86 | */ | |
87 |
|
87 | |||
88 | /*! |
|
88 | /*! | |
89 | \property QBarSeries::labelsVisible |
|
89 | \property QAbstractBarSeries::labelsVisible | |
90 | Defines the visibility of the labels in series |
|
90 | Defines the visibility of the labels in series | |
91 | */ |
|
91 | */ | |
92 | /*! |
|
92 | /*! | |
93 | \qmlproperty bool BarSeries::labelsVisible |
|
93 | \qmlproperty bool BarSeries::labelsVisible | |
94 | Defines the visibility of the labels in series |
|
94 | Defines the visibility of the labels in series | |
95 | */ |
|
95 | */ | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \fn void QBarSeries::clicked(int index, QBarSet *barset) |
|
98 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
99 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
100 | Clicked bar inside set is indexed by \a index |
|
100 | Clicked bar inside set is indexed by \a index | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \qmlsignal BarSeries::onClicked(int index, BarSet barset) |
|
103 | \qmlsignal BarSeries::onClicked(int index, BarSet barset) | |
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
104 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
105 | Clicked bar inside set is indexed by \a index |
|
105 | Clicked bar inside set is indexed by \a index | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \fn void QBarSeries::hovered(bool status, QBarSet* barset) |
|
109 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
110 |
|
110 | |||
111 | The signal is emitted if mouse is hovered on top of series. |
|
111 | The signal is emitted if mouse is hovered on top of series. | |
112 | Parameter \a barset is the pointer of barset, where hover happened. |
|
112 | Parameter \a barset is the pointer of barset, where hover happened. | |
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
113 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
114 | */ |
|
114 | */ | |
115 | /*! |
|
115 | /*! | |
116 | \qmlsignal BarSeries::onHovered(bool status, BarSet barset) |
|
116 | \qmlsignal BarSeries::onHovered(bool status, BarSet barset) | |
117 |
|
117 | |||
118 | The signal is emitted if mouse is hovered on top of series. |
|
118 | The signal is emitted if mouse is hovered on top of series. | |
119 | Parameter \a barset is the pointer of barset, where hover happened. |
|
119 | Parameter \a barset is the pointer of barset, where hover happened. | |
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
120 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QBarSeries::countChanged() |
|
124 | \fn void QAbstractBarSeries::countChanged() | |
125 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
125 | This signal is emitted when barset count has been changed, for example by append or remove. | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlsignal BarSeries::onCountChanged() |
|
128 | \qmlsignal BarSeries::onCountChanged() | |
129 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
129 | This signal is emitted when barset count has been changed, for example by append or remove. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QBarSeries::labelsVisibleChanged() |
|
133 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
134 | This signal is emitted when labels visibility have changed. |
|
134 | This signal is emitted when labels visibility have changed. | |
135 | \sa isLabelsVisible(), setLabelsVisible() |
|
135 | \sa isLabelsVisible(), setLabelsVisible() | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
139 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
140 | This signal is emitted when \a sets have been added to the series. |
|
140 | This signal is emitted when \a sets have been added to the series. | |
141 | \sa append(), insert() |
|
141 | \sa append(), insert() | |
142 | */ |
|
142 | */ | |
143 | /*! |
|
143 | /*! | |
144 | \qmlsignal BarSeries::onAdded(BarSet barset) |
|
144 | \qmlsignal BarSeries::onAdded(BarSet barset) | |
145 | Emitted when \a barset has been added to the series. |
|
145 | Emitted when \a barset has been added to the series. | |
146 | */ |
|
146 | */ | |
147 |
|
147 | |||
148 | /*! |
|
148 | /*! | |
149 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
149 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
150 | This signal is emitted when \a sets have been removed from the series. |
|
150 | This signal is emitted when \a sets have been removed from the series. | |
151 | \sa remove() |
|
151 | \sa remove() | |
152 | */ |
|
152 | */ | |
153 | /*! |
|
153 | /*! | |
154 | \qmlsignal BarSeries::onRemoved(BarSet barset) |
|
154 | \qmlsignal BarSeries::onRemoved(BarSet barset) | |
155 | Emitted when \a barset has been removed from the series. |
|
155 | Emitted when \a barset has been removed from the series. | |
156 | */ |
|
156 | */ | |
157 |
|
157 | |||
158 | /*! |
|
158 | /*! | |
159 | \qmlmethod BarSet BarSeries::at(int index) |
|
159 | \qmlmethod BarSet BarSeries::at(int index) | |
160 | Returns bar set at \a index. Returns null if the index is not valid. |
|
160 | Returns bar set at \a index. Returns null if the index is not valid. | |
161 | */ |
|
161 | */ | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) |
|
164 | \qmlmethod BarSet BarSeries::append(string label, VariantList values) | |
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
165 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
166 | For example: |
|
166 | For example: | |
167 | \code |
|
167 | \code | |
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
168 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
169 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
170 | \endcode |
|
170 | \endcode | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) |
|
174 | \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values) | |
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
175 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
176 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
177 | appended. |
|
177 | appended. | |
178 | \sa BarSeries::append() |
|
178 | \sa BarSeries::append() | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \qmlmethod bool BarSeries::remove(BarSet barset) |
|
182 | \qmlmethod bool BarSeries::remove(BarSet barset) | |
183 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
183 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
184 | */ |
|
184 | */ | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \qmlmethod BarSeries::clear() |
|
187 | \qmlmethod BarSeries::clear() | |
188 | Removes all barsets from the series. |
|
188 | Removes all barsets from the series. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Constructs empty QBarSeries. |
|
192 | Constructs empty QAbstractBarSeries. | |
193 | QBarSeries is QObject which is a child of a \a parent. |
|
193 | QAbstractBarSeries is QObject which is a child of a \a parent. | |
194 | */ |
|
194 | */ | |
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
195 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : | |
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) |
|
196 | QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent) | |
197 | { |
|
197 | { | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Destructs barseries and owned barsets. |
|
201 | Destructs barseries and owned barsets. | |
202 | */ |
|
202 | */ | |
203 | QAbstractBarSeries::~QAbstractBarSeries() |
|
203 | QAbstractBarSeries::~QAbstractBarSeries() | |
204 | { |
|
204 | { | |
205 | Q_D(QAbstractBarSeries); |
|
205 | Q_D(QAbstractBarSeries); | |
206 | if(d->m_dataset){ |
|
206 | if(d->m_dataset){ | |
207 | d->m_dataset->removeSeries(this); |
|
207 | d->m_dataset->removeSeries(this); | |
208 | } |
|
208 | } | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | /*! |
|
211 | /*! | |
212 | \internal |
|
212 | \internal | |
213 | */ |
|
213 | */ | |
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
214 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
215 | QAbstractSeries(d,parent) |
|
215 | QAbstractSeries(d,parent) | |
216 | { |
|
216 | { | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Returns the type of series. Derived classes override this. |
|
220 | Returns the type of series. Derived classes override this. | |
221 | */ |
|
221 | */ | |
222 | QAbstractSeries::SeriesType QAbstractBarSeries::type() const |
|
222 | QAbstractSeries::SeriesType QAbstractBarSeries::type() const | |
223 | { |
|
223 | { | |
224 | return QAbstractSeries::SeriesTypeBar; |
|
224 | return QAbstractSeries::SeriesTypeBar; | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
228 | Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
229 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
229 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
230 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
230 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
231 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
231 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
232 | */ |
|
232 | */ | |
233 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
233 | void QAbstractBarSeries::setBarWidth(qreal width) | |
234 | { |
|
234 | { | |
235 | Q_D(QAbstractBarSeries); |
|
235 | Q_D(QAbstractBarSeries); | |
236 | d->setBarWidth(width); |
|
236 | d->setBarWidth(width); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | Returns the width of the bars of the series. |
|
240 | Returns the width of the bars of the series. | |
241 | \sa setBarWidth() |
|
241 | \sa setBarWidth() | |
242 | */ |
|
242 | */ | |
243 | qreal QAbstractBarSeries::barWidth() const |
|
243 | qreal QAbstractBarSeries::barWidth() const | |
244 | { |
|
244 | { | |
245 | Q_D(const QAbstractBarSeries); |
|
245 | Q_D(const QAbstractBarSeries); | |
246 | return d->barWidth(); |
|
246 | return d->barWidth(); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | /*! |
|
249 | /*! | |
250 | 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. |
|
250 | 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. | |
251 | Returns true, if appending succeeded. |
|
251 | Returns true, if appending succeeded. | |
252 | */ |
|
252 | */ | |
253 | bool QAbstractBarSeries::append(QBarSet *set) |
|
253 | bool QAbstractBarSeries::append(QBarSet *set) | |
254 | { |
|
254 | { | |
255 | Q_D(QAbstractBarSeries); |
|
255 | Q_D(QAbstractBarSeries); | |
256 | bool success = d->append(set); |
|
256 | bool success = d->append(set); | |
257 | if (success) { |
|
257 | if (success) { | |
258 | QList<QBarSet*> sets; |
|
258 | QList<QBarSet*> sets; | |
259 | sets.append(set); |
|
259 | sets.append(set); | |
260 | emit barsetsAdded(sets); |
|
260 | emit barsetsAdded(sets); | |
261 | emit countChanged(); |
|
261 | emit countChanged(); | |
262 | } |
|
262 | } | |
263 | return success; |
|
263 | return success; | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | /*! |
|
266 | /*! | |
267 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
267 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
268 | Returns true, if set was removed. |
|
268 | Returns true, if set was removed. | |
269 | */ |
|
269 | */ | |
270 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
270 | bool QAbstractBarSeries::remove(QBarSet *set) | |
271 | { |
|
271 | { | |
272 | Q_D(QAbstractBarSeries); |
|
272 | Q_D(QAbstractBarSeries); | |
273 | bool success = d->remove(set); |
|
273 | bool success = d->remove(set); | |
274 | if (success) { |
|
274 | if (success) { | |
275 | QList<QBarSet*> sets; |
|
275 | QList<QBarSet*> sets; | |
276 | sets.append(set); |
|
276 | sets.append(set); | |
277 | emit barsetsRemoved(sets); |
|
277 | emit barsetsRemoved(sets); | |
278 | emit countChanged(); |
|
278 | emit countChanged(); | |
279 | } |
|
279 | } | |
280 | return success; |
|
280 | return success; | |
281 | } |
|
281 | } | |
282 |
|
282 | |||
283 | /*! |
|
283 | /*! | |
284 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
284 | Adds a list of barsets to series. Takes ownership of \a sets. | |
285 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
285 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
286 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
286 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
287 | and function returns false. |
|
287 | and function returns false. | |
288 | */ |
|
288 | */ | |
289 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
289 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
290 | { |
|
290 | { | |
291 | Q_D(QAbstractBarSeries); |
|
291 | Q_D(QAbstractBarSeries); | |
292 | bool success = d->append(sets); |
|
292 | bool success = d->append(sets); | |
293 | if (success) { |
|
293 | if (success) { | |
294 | emit barsetsAdded(sets); |
|
294 | emit barsetsAdded(sets); | |
295 | emit countChanged(); |
|
295 | emit countChanged(); | |
296 | } |
|
296 | } | |
297 | return success; |
|
297 | return success; | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | /*! |
|
300 | /*! | |
301 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. |
|
301 | Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended. | |
302 | Returns true, if inserting succeeded. |
|
302 | Returns true, if inserting succeeded. | |
303 |
|
303 | |||
304 | */ |
|
304 | */ | |
305 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
305 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
306 | { |
|
306 | { | |
307 | Q_D(QAbstractBarSeries); |
|
307 | Q_D(QAbstractBarSeries); | |
308 | bool success = d->insert(index, set); |
|
308 | bool success = d->insert(index, set); | |
309 | if (success) { |
|
309 | if (success) { | |
310 | QList<QBarSet*> sets; |
|
310 | QList<QBarSet*> sets; | |
311 | sets.append(set); |
|
311 | sets.append(set); | |
312 | emit barsetsAdded(sets); |
|
312 | emit barsetsAdded(sets); | |
313 | emit countChanged(); |
|
313 | emit countChanged(); | |
314 | } |
|
314 | } | |
315 | return success; |
|
315 | return success; | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | /*! |
|
318 | /*! | |
319 | Removes all of the bar sets from the series |
|
319 | Removes all of the bar sets from the series | |
320 | */ |
|
320 | */ | |
321 | void QAbstractBarSeries::clear() |
|
321 | void QAbstractBarSeries::clear() | |
322 | { |
|
322 | { | |
323 | Q_D(QAbstractBarSeries); |
|
323 | Q_D(QAbstractBarSeries); | |
324 | QList<QBarSet *> sets = barSets(); |
|
324 | QList<QBarSet *> sets = barSets(); | |
325 | bool success = d->remove(sets); |
|
325 | bool success = d->remove(sets); | |
326 | if (success) { |
|
326 | if (success) { | |
327 | emit barsetsRemoved(sets); |
|
327 | emit barsetsRemoved(sets); | |
328 | emit countChanged(); |
|
328 | emit countChanged(); | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | /*! |
|
332 | /*! | |
333 | Returns number of sets in series. |
|
333 | Returns number of sets in series. | |
334 | */ |
|
334 | */ | |
335 | int QAbstractBarSeries::count() const |
|
335 | int QAbstractBarSeries::count() const | |
336 | { |
|
336 | { | |
337 | Q_D(const QAbstractBarSeries); |
|
337 | Q_D(const QAbstractBarSeries); | |
338 | return d->m_barSets.count(); |
|
338 | return d->m_barSets.count(); | |
339 | } |
|
339 | } | |
340 |
|
340 | |||
341 | /*! |
|
341 | /*! | |
342 | Returns a list of sets in series. Keeps ownership of sets. |
|
342 | Returns a list of sets in series. Keeps ownership of sets. | |
343 | */ |
|
343 | */ | |
344 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
344 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
345 | { |
|
345 | { | |
346 | Q_D(const QAbstractBarSeries); |
|
346 | Q_D(const QAbstractBarSeries); | |
347 | return d->m_barSets; |
|
347 | return d->m_barSets; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | /*! |
|
350 | /*! | |
351 | Sets the visibility of labels in series to \a visible |
|
351 | Sets the visibility of labels in series to \a visible | |
352 | */ |
|
352 | */ | |
353 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
353 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
354 | { |
|
354 | { | |
355 | Q_D(QAbstractBarSeries); |
|
355 | Q_D(QAbstractBarSeries); | |
356 | if (d->m_labelsVisible != visible) { |
|
356 | if (d->m_labelsVisible != visible) { | |
357 | d->setLabelsVisible(visible); |
|
357 | d->setLabelsVisible(visible); | |
358 | emit labelsVisibleChanged(); |
|
358 | emit labelsVisibleChanged(); | |
359 | } |
|
359 | } | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | /*! |
|
362 | /*! | |
363 | Returns the visibility of labels |
|
363 | Returns the visibility of labels | |
364 | */ |
|
364 | */ | |
365 | bool QAbstractBarSeries::isLabelsVisible() const |
|
365 | bool QAbstractBarSeries::isLabelsVisible() const | |
366 | { |
|
366 | { | |
367 | Q_D(const QAbstractBarSeries); |
|
367 | Q_D(const QAbstractBarSeries); | |
368 | return d->m_labelsVisible; |
|
368 | return d->m_labelsVisible; | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
371 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
372 |
|
372 | |||
373 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
373 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
374 | QAbstractSeriesPrivate(q), |
|
374 | QAbstractSeriesPrivate(q), | |
375 | m_barWidth(0.5), // Default value is 50% of category width |
|
375 | m_barWidth(0.5), // Default value is 50% of category width | |
376 | m_labelsVisible(false), |
|
376 | m_labelsVisible(false), | |
377 | m_visible(true) |
|
377 | m_visible(true) | |
378 | { |
|
378 | { | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
381 | int QAbstractBarSeriesPrivate::categoryCount() const | |
382 | { |
|
382 | { | |
383 | // No categories defined. return count of longest set. |
|
383 | // No categories defined. return count of longest set. | |
384 | int count = 0; |
|
384 | int count = 0; | |
385 | for (int i=0; i<m_barSets.count(); i++) { |
|
385 | for (int i=0; i<m_barSets.count(); i++) { | |
386 | if (m_barSets.at(i)->count() > count) { |
|
386 | if (m_barSets.at(i)->count() > count) { | |
387 | count = m_barSets.at(i)->count(); |
|
387 | count = m_barSets.at(i)->count(); | |
388 | } |
|
388 | } | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | return count; |
|
391 | return count; | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
394 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
395 | { |
|
395 | { | |
396 | if (width < 0.0) { |
|
396 | if (width < 0.0) { | |
397 | width = 0.0; |
|
397 | width = 0.0; | |
398 | } |
|
398 | } | |
399 | m_barWidth = width; |
|
399 | m_barWidth = width; | |
400 | emit updatedBars(); |
|
400 | emit updatedBars(); | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
403 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
404 | { |
|
404 | { | |
405 | return m_barWidth; |
|
405 | return m_barWidth; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
408 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
409 | { |
|
409 | { | |
410 | return m_barSets.at(index); |
|
410 | return m_barSets.at(index); | |
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
413 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
414 | { |
|
414 | { | |
415 | m_visible = visible; |
|
415 | m_visible = visible; | |
416 | emit updatedBars(); |
|
416 | emit updatedBars(); | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
419 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
420 | { |
|
420 | { | |
421 | m_labelsVisible = visible; |
|
421 | m_labelsVisible = visible; | |
422 | emit labelsVisibleChanged(visible); |
|
422 | emit labelsVisibleChanged(visible); | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | qreal QAbstractBarSeriesPrivate::min() |
|
425 | qreal QAbstractBarSeriesPrivate::min() | |
426 | { |
|
426 | { | |
427 | if (m_barSets.count() <= 0) { |
|
427 | if (m_barSets.count() <= 0) { | |
428 | return 0; |
|
428 | return 0; | |
429 | } |
|
429 | } | |
430 | qreal min = INT_MAX; |
|
430 | qreal min = INT_MAX; | |
431 |
|
431 | |||
432 | for (int i = 0; i < m_barSets.count(); i++) { |
|
432 | for (int i = 0; i < m_barSets.count(); i++) { | |
433 | int categoryCount = m_barSets.at(i)->count(); |
|
433 | int categoryCount = m_barSets.at(i)->count(); | |
434 | for (int j = 0; j < categoryCount; j++) { |
|
434 | for (int j = 0; j < categoryCount; j++) { | |
435 | qreal temp = m_barSets.at(i)->at(j); |
|
435 | qreal temp = m_barSets.at(i)->at(j); | |
436 | if (temp < min) |
|
436 | if (temp < min) | |
437 | min = temp; |
|
437 | min = temp; | |
438 | } |
|
438 | } | |
439 | } |
|
439 | } | |
440 | return min; |
|
440 | return min; | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | qreal QAbstractBarSeriesPrivate::max() |
|
443 | qreal QAbstractBarSeriesPrivate::max() | |
444 | { |
|
444 | { | |
445 | if (m_barSets.count() <= 0) { |
|
445 | if (m_barSets.count() <= 0) { | |
446 | return 0; |
|
446 | return 0; | |
447 | } |
|
447 | } | |
448 | qreal max = INT_MIN; |
|
448 | qreal max = INT_MIN; | |
449 |
|
449 | |||
450 | for (int i = 0; i < m_barSets.count(); i++) { |
|
450 | for (int i = 0; i < m_barSets.count(); i++) { | |
451 | int categoryCount = m_barSets.at(i)->count(); |
|
451 | int categoryCount = m_barSets.at(i)->count(); | |
452 | for (int j = 0; j < categoryCount; j++) { |
|
452 | for (int j = 0; j < categoryCount; j++) { | |
453 | qreal temp = m_barSets.at(i)->at(j); |
|
453 | qreal temp = m_barSets.at(i)->at(j); | |
454 | if (temp > max) |
|
454 | if (temp > max) | |
455 | max = temp; |
|
455 | max = temp; | |
456 | } |
|
456 | } | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | return max; |
|
459 | return max; | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
462 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
463 | { |
|
463 | { | |
464 | if ((set < 0) || (set >= m_barSets.count())) { |
|
464 | if ((set < 0) || (set >= m_barSets.count())) { | |
465 | // No set, no value. |
|
465 | // No set, no value. | |
466 | return 0; |
|
466 | return 0; | |
467 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
467 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
468 | // No category, no value. |
|
468 | // No category, no value. | |
469 | return 0; |
|
469 | return 0; | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | return m_barSets.at(set)->at(category); |
|
472 | return m_barSets.at(set)->at(category); | |
473 | } |
|
473 | } | |
474 |
|
474 | |||
475 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
475 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
476 | { |
|
476 | { | |
477 | if ((set < 0) || (set >= m_barSets.count())) { |
|
477 | if ((set < 0) || (set >= m_barSets.count())) { | |
478 | // No set, no value. |
|
478 | // No set, no value. | |
479 | return 0; |
|
479 | return 0; | |
480 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
480 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
481 | // No category, no value. |
|
481 | // No category, no value. | |
482 | return 0; |
|
482 | return 0; | |
483 | } |
|
483 | } | |
484 |
|
484 | |||
485 | qreal value = m_barSets.at(set)->at(category); |
|
485 | qreal value = m_barSets.at(set)->at(category); | |
486 | qreal sum = categorySum(category); |
|
486 | qreal sum = categorySum(category); | |
487 | if ( qFuzzyIsNull(sum) ) { |
|
487 | if ( qFuzzyIsNull(sum) ) { | |
488 | return 0; |
|
488 | return 0; | |
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | return value / sum; |
|
491 | return value / sum; | |
492 | } |
|
492 | } | |
493 |
|
493 | |||
494 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
494 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
495 | { |
|
495 | { | |
496 | qreal sum(0); |
|
496 | qreal sum(0); | |
497 | int count = m_barSets.count(); // Count sets |
|
497 | int count = m_barSets.count(); // Count sets | |
498 | for (int set = 0; set < count; set++) { |
|
498 | for (int set = 0; set < count; set++) { | |
499 | if (category < m_barSets.at(set)->count()) |
|
499 | if (category < m_barSets.at(set)->count()) | |
500 | sum += m_barSets.at(set)->at(category); |
|
500 | sum += m_barSets.at(set)->at(category); | |
501 | } |
|
501 | } | |
502 | return sum; |
|
502 | return sum; | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
505 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
506 | { |
|
506 | { | |
507 | qreal sum(0); |
|
507 | qreal sum(0); | |
508 | int count = m_barSets.count(); // Count sets |
|
508 | int count = m_barSets.count(); // Count sets | |
509 | for (int set = 0; set < count; set++) { |
|
509 | for (int set = 0; set < count; set++) { | |
510 | if (category < m_barSets.at(set)->count()) |
|
510 | if (category < m_barSets.at(set)->count()) | |
511 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
511 | sum += qAbs(m_barSets.at(set)->at(category)); | |
512 | } |
|
512 | } | |
513 | return sum; |
|
513 | return sum; | |
514 | } |
|
514 | } | |
515 |
|
515 | |||
516 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
516 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
517 | { |
|
517 | { | |
518 | qreal max = INT_MIN; |
|
518 | qreal max = INT_MIN; | |
519 | int count = categoryCount(); |
|
519 | int count = categoryCount(); | |
520 | for (int i = 0; i < count; i++) { |
|
520 | for (int i = 0; i < count; i++) { | |
521 | qreal sum = categorySum(i); |
|
521 | qreal sum = categorySum(i); | |
522 | if (sum > max) |
|
522 | if (sum > max) | |
523 | max = sum; |
|
523 | max = sum; | |
524 | } |
|
524 | } | |
525 | return max; |
|
525 | return max; | |
526 | } |
|
526 | } | |
527 |
|
527 | |||
528 | qreal QAbstractBarSeriesPrivate::minX() |
|
528 | qreal QAbstractBarSeriesPrivate::minX() | |
529 | { |
|
529 | { | |
530 | if (m_barSets.count() <= 0) { |
|
530 | if (m_barSets.count() <= 0) { | |
531 | return 0; |
|
531 | return 0; | |
532 | } |
|
532 | } | |
533 | qreal min = INT_MAX; |
|
533 | qreal min = INT_MAX; | |
534 |
|
534 | |||
535 | for (int i = 0; i < m_barSets.count(); i++) { |
|
535 | for (int i = 0; i < m_barSets.count(); i++) { | |
536 | int categoryCount = m_barSets.at(i)->count(); |
|
536 | int categoryCount = m_barSets.at(i)->count(); | |
537 | for (int j = 0; j < categoryCount; j++) { |
|
537 | for (int j = 0; j < categoryCount; j++) { | |
538 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
538 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
539 | if (temp < min) |
|
539 | if (temp < min) | |
540 | min = temp; |
|
540 | min = temp; | |
541 | } |
|
541 | } | |
542 | } |
|
542 | } | |
543 | return min; |
|
543 | return min; | |
544 | } |
|
544 | } | |
545 |
|
545 | |||
546 | qreal QAbstractBarSeriesPrivate::maxX() |
|
546 | qreal QAbstractBarSeriesPrivate::maxX() | |
547 | { |
|
547 | { | |
548 | if (m_barSets.count() <= 0) { |
|
548 | if (m_barSets.count() <= 0) { | |
549 | return 0; |
|
549 | return 0; | |
550 | } |
|
550 | } | |
551 | qreal max = INT_MIN; |
|
551 | qreal max = INT_MIN; | |
552 |
|
552 | |||
553 | for (int i = 0; i < m_barSets.count(); i++) { |
|
553 | for (int i = 0; i < m_barSets.count(); i++) { | |
554 | int categoryCount = m_barSets.at(i)->count(); |
|
554 | int categoryCount = m_barSets.at(i)->count(); | |
555 | for (int j = 0; j < categoryCount; j++) { |
|
555 | for (int j = 0; j < categoryCount; j++) { | |
556 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
556 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
557 | if (temp > max) |
|
557 | if (temp > max) | |
558 | max = temp; |
|
558 | max = temp; | |
559 | } |
|
559 | } | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | return max; |
|
562 | return max; | |
563 | } |
|
563 | } | |
564 |
|
564 | |||
565 |
|
565 | |||
566 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
566 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
567 | { |
|
567 | { | |
568 | qreal minX(domain.minX()); |
|
568 | qreal minX(domain.minX()); | |
569 | qreal minY(domain.minY()); |
|
569 | qreal minY(domain.minY()); | |
570 | qreal maxX(domain.maxX()); |
|
570 | qreal maxX(domain.maxX()); | |
571 | qreal maxY(domain.maxY()); |
|
571 | qreal maxY(domain.maxY()); | |
572 | int tickXCount(domain.tickXCount()); |
|
572 | int tickXCount(domain.tickXCount()); | |
573 | int tickYCount(domain.tickYCount()); |
|
573 | int tickYCount(domain.tickYCount()); | |
574 |
|
574 | |||
575 | qreal seriesMinX = this->minX(); |
|
575 | qreal seriesMinX = this->minX(); | |
576 | qreal seriesMaxX = this->maxX(); |
|
576 | qreal seriesMaxX = this->maxX(); | |
577 | qreal y = max(); |
|
577 | qreal y = max(); | |
578 | minX = qMin(minX, seriesMinX - 0.5); |
|
578 | minX = qMin(minX, seriesMinX - 0.5); | |
579 | minY = qMin(minY, y); |
|
579 | minY = qMin(minY, y); | |
580 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
580 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
581 | maxY = qMax(maxY, y); |
|
581 | maxY = qMax(maxY, y); | |
582 | tickXCount = categoryCount()+1; |
|
582 | tickXCount = categoryCount()+1; | |
583 |
|
583 | |||
584 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
584 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
585 | } |
|
585 | } | |
586 |
|
586 | |||
587 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
587 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
588 | { |
|
588 | { | |
589 | Q_Q(QAbstractBarSeries); |
|
589 | Q_Q(QAbstractBarSeries); | |
590 |
|
590 | |||
591 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
591 | BarChartItem* bar = new BarChartItem(q,presenter); | |
592 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
592 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
593 | presenter->animator()->addAnimation(bar); |
|
593 | presenter->animator()->addAnimation(bar); | |
594 | } |
|
594 | } | |
595 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
595 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
596 | return bar; |
|
596 | return bar; | |
597 |
|
597 | |||
598 | } |
|
598 | } | |
599 |
|
599 | |||
600 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
600 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
601 | { |
|
601 | { | |
602 | Q_Q(QAbstractBarSeries); |
|
602 | Q_Q(QAbstractBarSeries); | |
603 | QList<LegendMarker*> markers; |
|
603 | QList<LegendMarker*> markers; | |
604 | foreach(QBarSet* set, q->barSets()) { |
|
604 | foreach(QBarSet* set, q->barSets()) { | |
605 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
605 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
606 | markers << marker; |
|
606 | markers << marker; | |
607 | } |
|
607 | } | |
608 |
|
608 | |||
609 | return markers; |
|
609 | return markers; | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent) |
|
612 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent) | |
613 | { |
|
613 | { | |
614 | return new QCategoriesAxis(parent); |
|
614 | return new QCategoriesAxis(parent); | |
615 | } |
|
615 | } | |
616 |
|
616 | |||
617 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent) |
|
617 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent) | |
618 | { |
|
618 | { | |
619 | return new QValuesAxis(parent); |
|
619 | return new QValuesAxis(parent); | |
620 | } |
|
620 | } | |
621 |
|
621 | |||
622 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
622 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
623 | { |
|
623 | { | |
624 | Q_Q(QAbstractBarSeries); |
|
624 | Q_Q(QAbstractBarSeries); | |
625 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
625 | if ((m_barSets.contains(set)) || (set == 0)) { | |
626 | // Fail if set is already in list or set is null. |
|
626 | // Fail if set is already in list or set is null. | |
627 | return false; |
|
627 | return false; | |
628 | } |
|
628 | } | |
629 | m_barSets.append(set); |
|
629 | m_barSets.append(set); | |
630 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
630 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
631 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
631 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
632 | emit restructuredBars(); // this notifies barchartitem |
|
632 | emit restructuredBars(); // this notifies barchartitem | |
633 | if (m_dataset) { |
|
633 | if (m_dataset) { | |
634 | m_dataset->updateSeries(q); // this notifies legend |
|
634 | m_dataset->updateSeries(q); // this notifies legend | |
635 | } |
|
635 | } | |
636 | return true; |
|
636 | return true; | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
639 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
640 | { |
|
640 | { | |
641 | Q_Q(QAbstractBarSeries); |
|
641 | Q_Q(QAbstractBarSeries); | |
642 | if (!m_barSets.contains(set)) { |
|
642 | if (!m_barSets.contains(set)) { | |
643 | // Fail if set is not in list |
|
643 | // Fail if set is not in list | |
644 | return false; |
|
644 | return false; | |
645 | } |
|
645 | } | |
646 | m_barSets.removeOne(set); |
|
646 | m_barSets.removeOne(set); | |
647 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
647 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
648 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
648 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
649 | emit restructuredBars(); // this notifies barchartitem |
|
649 | emit restructuredBars(); // this notifies barchartitem | |
650 | if (m_dataset) { |
|
650 | if (m_dataset) { | |
651 | m_dataset->updateSeries(q); // this notifies legend |
|
651 | m_dataset->updateSeries(q); // this notifies legend | |
652 | } |
|
652 | } | |
653 | return true; |
|
653 | return true; | |
654 | } |
|
654 | } | |
655 |
|
655 | |||
656 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
656 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
657 | { |
|
657 | { | |
658 | Q_Q(QAbstractBarSeries); |
|
658 | Q_Q(QAbstractBarSeries); | |
659 | foreach (QBarSet* set, sets) { |
|
659 | foreach (QBarSet* set, sets) { | |
660 | if ((set == 0) || (m_barSets.contains(set))) { |
|
660 | if ((set == 0) || (m_barSets.contains(set))) { | |
661 | // Fail if any of the sets is null or is already appended. |
|
661 | // Fail if any of the sets is null or is already appended. | |
662 | return false; |
|
662 | return false; | |
663 | } |
|
663 | } | |
664 | if (sets.count(set) != 1) { |
|
664 | if (sets.count(set) != 1) { | |
665 | // Also fail if same set is more than once in given list. |
|
665 | // Also fail if same set is more than once in given list. | |
666 | return false; |
|
666 | return false; | |
667 | } |
|
667 | } | |
668 | } |
|
668 | } | |
669 |
|
669 | |||
670 | foreach (QBarSet* set, sets) { |
|
670 | foreach (QBarSet* set, sets) { | |
671 | m_barSets.append(set); |
|
671 | m_barSets.append(set); | |
672 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
672 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
673 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
673 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
674 | } |
|
674 | } | |
675 | emit restructuredBars(); // this notifies barchartitem |
|
675 | emit restructuredBars(); // this notifies barchartitem | |
676 | if (m_dataset) { |
|
676 | if (m_dataset) { | |
677 | m_dataset->updateSeries(q); // this notifies legend |
|
677 | m_dataset->updateSeries(q); // this notifies legend | |
678 | } |
|
678 | } | |
679 | return true; |
|
679 | return true; | |
680 | } |
|
680 | } | |
681 |
|
681 | |||
682 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
682 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
683 | { |
|
683 | { | |
684 | Q_Q(QAbstractBarSeries); |
|
684 | Q_Q(QAbstractBarSeries); | |
685 | if (sets.count() == 0) { |
|
685 | if (sets.count() == 0) { | |
686 | return false; |
|
686 | return false; | |
687 | } |
|
687 | } | |
688 | foreach (QBarSet* set, sets) { |
|
688 | foreach (QBarSet* set, sets) { | |
689 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
689 | if ((set == 0) || (!m_barSets.contains(set))) { | |
690 | // Fail if any of the sets is null or is not in series |
|
690 | // Fail if any of the sets is null or is not in series | |
691 | return false; |
|
691 | return false; | |
692 | } |
|
692 | } | |
693 | if (sets.count(set) != 1) { |
|
693 | if (sets.count(set) != 1) { | |
694 | // Also fail if same set is more than once in given list. |
|
694 | // Also fail if same set is more than once in given list. | |
695 | return false; |
|
695 | return false; | |
696 | } |
|
696 | } | |
697 | } |
|
697 | } | |
698 |
|
698 | |||
699 | foreach (QBarSet* set, sets) { |
|
699 | foreach (QBarSet* set, sets) { | |
700 | m_barSets.removeOne(set); |
|
700 | m_barSets.removeOne(set); | |
701 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
701 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
702 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
702 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
703 | } |
|
703 | } | |
704 |
|
704 | |||
705 | emit restructuredBars(); // this notifies barchartitem |
|
705 | emit restructuredBars(); // this notifies barchartitem | |
706 | if (m_dataset) { |
|
706 | if (m_dataset) { | |
707 | m_dataset->updateSeries(q); // this notifies legend |
|
707 | m_dataset->updateSeries(q); // this notifies legend | |
708 | } |
|
708 | } | |
709 | return true; |
|
709 | return true; | |
710 | } |
|
710 | } | |
711 |
|
711 | |||
712 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
712 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
713 | { |
|
713 | { | |
714 | Q_Q(QAbstractBarSeries); |
|
714 | Q_Q(QAbstractBarSeries); | |
715 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
715 | if ((m_barSets.contains(set)) || (set == 0)) { | |
716 | // Fail if set is already in list or set is null. |
|
716 | // Fail if set is already in list or set is null. | |
717 | return false; |
|
717 | return false; | |
718 | } |
|
718 | } | |
719 | m_barSets.insert(index, set); |
|
719 | m_barSets.insert(index, set); | |
720 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
720 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
721 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
721 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
722 | emit restructuredBars(); // this notifies barchartitem |
|
722 | emit restructuredBars(); // this notifies barchartitem | |
723 | if (m_dataset) { |
|
723 | if (m_dataset) { | |
724 | m_dataset->updateSeries(q); // this notifies legend |
|
724 | m_dataset->updateSeries(q); // this notifies legend | |
725 | } |
|
725 | } | |
726 | return true; |
|
726 | return true; | |
727 | } |
|
727 | } | |
728 |
|
728 | |||
729 | #include "moc_qbarseries.cpp" |
|
729 | #include "moc_qabstractbarseries.cpp" | |
730 | #include "moc_qbarseries_p.cpp" |
|
730 | #include "moc_qabstractbarseries_p.cpp" | |
731 |
|
731 | |||
732 | QTCOMMERCIALCHART_END_NAMESPACE |
|
732 | QTCOMMERCIALCHART_END_NAMESPACE |
1 | NO CONTENT: file renamed from src/barchart/qbarseries.h to src/barchart/qabstractbarseries.h |
|
NO CONTENT: file renamed from src/barchart/qbarseries.h to src/barchart/qabstractbarseries.h |
@@ -1,97 +1,97 | |||||
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 QABSTRACTBARSERIES_P_H | |
31 | #define QBARSERIES_P_H |
|
31 | #define QABSTRACTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries.h" |
|
33 | #include "qabstractbarseries.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 QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate |
|
42 | class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate | |
43 | { |
|
43 | { | |
44 | Q_OBJECT |
|
44 | Q_OBJECT | |
45 | public: |
|
45 | public: | |
46 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); |
|
46 | QAbstractBarSeriesPrivate(QAbstractBarSeries *parent); | |
47 | int categoryCount() const; |
|
47 | int categoryCount() const; | |
48 |
|
48 | |||
49 | void setBarWidth(qreal width); |
|
49 | void setBarWidth(qreal width); | |
50 | qreal barWidth() const; |
|
50 | qreal barWidth() const; | |
51 |
|
51 | |||
52 | void setVisible(bool visible); |
|
52 | void setVisible(bool visible); | |
53 | void setLabelsVisible(bool visible); |
|
53 | void setLabelsVisible(bool visible); | |
54 |
|
54 | |||
55 | void scaleDomain(Domain& domain); |
|
55 | void scaleDomain(Domain& domain); | |
56 | Chart* createGraphics(ChartPresenter* presenter); |
|
56 | Chart* createGraphics(ChartPresenter* presenter); | |
57 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
57 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
58 |
|
58 | |||
59 | QAbstractAxis* createAxisX(QObject* parent = 0); |
|
59 | QAbstractAxis* createAxisX(QObject* parent = 0); | |
60 | QAbstractAxis* createAxisY(QObject* parent = 0); |
|
60 | QAbstractAxis* createAxisY(QObject* parent = 0); | |
61 |
|
61 | |||
62 | bool append(QBarSet *set); |
|
62 | bool append(QBarSet *set); | |
63 | bool remove(QBarSet *set); |
|
63 | bool remove(QBarSet *set); | |
64 | bool append(QList<QBarSet* > sets); |
|
64 | bool append(QList<QBarSet* > sets); | |
65 | bool remove(QList<QBarSet* > sets); |
|
65 | bool remove(QList<QBarSet* > sets); | |
66 | bool insert(int index, QBarSet *set); |
|
66 | bool insert(int index, QBarSet *set); | |
67 |
|
67 | |||
68 | QBarSet* barsetAt(int index); |
|
68 | QBarSet* barsetAt(int index); | |
69 | qreal min(); |
|
69 | qreal min(); | |
70 | qreal max(); |
|
70 | qreal max(); | |
71 | qreal valueAt(int set, int category); |
|
71 | qreal valueAt(int set, int category); | |
72 | qreal percentageAt(int set, int category); |
|
72 | qreal percentageAt(int set, int category); | |
73 | qreal categorySum(int category); |
|
73 | qreal categorySum(int category); | |
74 | qreal absoluteCategorySum(int category); |
|
74 | qreal absoluteCategorySum(int category); | |
75 | qreal maxCategorySum(); |
|
75 | qreal maxCategorySum(); | |
76 | qreal minX(); |
|
76 | qreal minX(); | |
77 | qreal maxX(); |
|
77 | qreal maxX(); | |
78 |
|
78 | |||
79 | Q_SIGNALS: |
|
79 | Q_SIGNALS: | |
80 | void clicked(int index, QBarSet *barset); |
|
80 | void clicked(int index, QBarSet *barset); | |
81 | void updatedBars(); |
|
81 | void updatedBars(); | |
82 | void restructuredBars(); |
|
82 | void restructuredBars(); | |
83 | void labelsVisibleChanged(bool visible); |
|
83 | void labelsVisibleChanged(bool visible); | |
84 |
|
84 | |||
85 | protected: |
|
85 | protected: | |
86 | QList<QBarSet *> m_barSets; |
|
86 | QList<QBarSet *> m_barSets; | |
87 | qreal m_barWidth; |
|
87 | qreal m_barWidth; | |
88 | bool m_labelsVisible; |
|
88 | bool m_labelsVisible; | |
89 | bool m_visible; |
|
89 | bool m_visible; | |
90 |
|
90 | |||
91 | private: |
|
91 | private: | |
92 | Q_DECLARE_PUBLIC(QAbstractBarSeries) |
|
92 | Q_DECLARE_PUBLIC(QAbstractBarSeries) | |
93 | }; |
|
93 | }; | |
94 |
|
94 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
95 | QTCOMMERCIALCHART_END_NAMESPACE | |
96 |
|
96 | |||
97 |
#endif // QBARSERIES |
|
97 | #endif // QABSTRACTBARSERIES_P_H |
@@ -1,556 +1,556 | |||||
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 "qbarmodelmapper.h" |
|
21 | #include "qbarmodelmapper.h" | |
22 | #include "qbarmodelmapper_p.h" |
|
22 | #include "qbarmodelmapper_p.h" | |
23 | #include "qbarseries.h" |
|
23 | #include "qabstractbarseries.h" | |
24 | #include "qbarset.h" |
|
24 | #include "qbarset.h" | |
25 | #include "qchart.h" |
|
25 | #include "qchart.h" | |
26 | #include <QAbstractItemModel> |
|
26 | #include <QAbstractItemModel> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | QBarModelMapper::QBarModelMapper(QObject *parent) : |
|
30 | QBarModelMapper::QBarModelMapper(QObject *parent) : | |
31 | QObject(parent), |
|
31 | QObject(parent), | |
32 | d_ptr(new QBarModelMapperPrivate(this)) |
|
32 | d_ptr(new QBarModelMapperPrivate(this)) | |
33 | { |
|
33 | { | |
34 | } |
|
34 | } | |
35 |
|
35 | |||
36 | QAbstractItemModel* QBarModelMapper::model() const |
|
36 | QAbstractItemModel* QBarModelMapper::model() const | |
37 | { |
|
37 | { | |
38 | Q_D(const QBarModelMapper); |
|
38 | Q_D(const QBarModelMapper); | |
39 | return d->m_model; |
|
39 | return d->m_model; | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | void QBarModelMapper::setModel(QAbstractItemModel *model) |
|
42 | void QBarModelMapper::setModel(QAbstractItemModel *model) | |
43 | { |
|
43 | { | |
44 | if (model == 0) |
|
44 | if (model == 0) | |
45 | return; |
|
45 | return; | |
46 |
|
46 | |||
47 | Q_D(QBarModelMapper); |
|
47 | Q_D(QBarModelMapper); | |
48 | if (d->m_model) { |
|
48 | if (d->m_model) { | |
49 | disconnect(d->m_model, 0, d, 0); |
|
49 | disconnect(d->m_model, 0, d, 0); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | d->m_model = model; |
|
52 | d->m_model = model; | |
53 | d->initializeBarFromModel(); |
|
53 | d->initializeBarFromModel(); | |
54 | // connect signals from the model |
|
54 | // connect signals from the model | |
55 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
55 | connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex))); | |
56 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); |
|
56 | connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int))); | |
57 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); |
|
57 | connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int))); | |
58 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); |
|
58 | connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int))); | |
59 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); |
|
59 | connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int))); | |
60 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); |
|
60 | connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int))); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | QAbstractBarSeries* QBarModelMapper::series() const |
|
63 | QAbstractBarSeries* QBarModelMapper::series() const | |
64 | { |
|
64 | { | |
65 | Q_D(const QBarModelMapper); |
|
65 | Q_D(const QBarModelMapper); | |
66 | return d->m_series; |
|
66 | return d->m_series; | |
67 | } |
|
67 | } | |
68 |
|
68 | |||
69 | void QBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
69 | void QBarModelMapper::setSeries(QAbstractBarSeries *series) | |
70 | { |
|
70 | { | |
71 | Q_D(QBarModelMapper); |
|
71 | Q_D(QBarModelMapper); | |
72 | if (d->m_series) { |
|
72 | if (d->m_series) { | |
73 | disconnect(d->m_series, 0, d, 0); |
|
73 | disconnect(d->m_series, 0, d, 0); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | if (series == 0) |
|
76 | if (series == 0) | |
77 | return; |
|
77 | return; | |
78 |
|
78 | |||
79 | d->m_series = series; |
|
79 | d->m_series = series; | |
80 | d->initializeBarFromModel(); |
|
80 | d->initializeBarFromModel(); | |
81 | // connect the signals from the series |
|
81 | // connect the signals from the series | |
82 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); |
|
82 | connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>))); | |
83 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); |
|
83 | connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>))); | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | Returns which row/column of the model contains the first values of the QBarSets in the series. |
|
87 | Returns which row/column of the model contains the first values of the QBarSets in the series. | |
88 | The default value is 0. |
|
88 | The default value is 0. | |
89 | */ |
|
89 | */ | |
90 | int QBarModelMapper::first() const |
|
90 | int QBarModelMapper::first() const | |
91 | { |
|
91 | { | |
92 | Q_D(const QBarModelMapper); |
|
92 | Q_D(const QBarModelMapper); | |
93 | return d->m_first; |
|
93 | return d->m_first; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | Sets which row of the model contains the \a first values of the QBarSets in the series. |
|
97 | Sets which row of the model contains the \a first values of the QBarSets in the series. | |
98 | The default value is 0. |
|
98 | The default value is 0. | |
99 | */ |
|
99 | */ | |
100 | void QBarModelMapper::setFirst(int first) |
|
100 | void QBarModelMapper::setFirst(int first) | |
101 | { |
|
101 | { | |
102 | Q_D(QBarModelMapper); |
|
102 | Q_D(QBarModelMapper); | |
103 | d->m_first = qMax(first, 0); |
|
103 | d->m_first = qMax(first, 0); | |
104 | d->initializeBarFromModel(); |
|
104 | d->initializeBarFromModel(); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | /*! |
|
107 | /*! | |
108 | Returns the number of rows/columns of the model that are mapped as the data for QBarSeries |
|
108 | Returns the number of rows/columns of the model that are mapped as the data for QAbstractBarSeries | |
109 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
109 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
110 | */ |
|
110 | */ | |
111 | int QBarModelMapper::count() const |
|
111 | int QBarModelMapper::count() const | |
112 | { |
|
112 | { | |
113 | Q_D(const QBarModelMapper); |
|
113 | Q_D(const QBarModelMapper); | |
114 | return d->m_count; |
|
114 | return d->m_count; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries |
|
118 | Sets the \a count of rows/columns of the model that are mapped as the data for QAbstractBarSeries | |
119 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) |
|
119 | Minimal and default value is: -1 (count limited by the number of rows/columns in the model) | |
120 | */ |
|
120 | */ | |
121 | void QBarModelMapper::setCount(int count) |
|
121 | void QBarModelMapper::setCount(int count) | |
122 | { |
|
122 | { | |
123 | Q_D(QBarModelMapper); |
|
123 | Q_D(QBarModelMapper); | |
124 | d->m_count = qMax(count, -1); |
|
124 | d->m_count = qMax(count, -1); | |
125 | d->initializeBarFromModel(); |
|
125 | d->initializeBarFromModel(); | |
126 | } |
|
126 | } | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | Returns the orientation that is used when QBarModelMapper accesses the model. |
|
129 | Returns the orientation that is used when QBarModelMapper accesses the model. | |
130 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) |
|
130 | This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal) | |
131 | or from columns (Qt::Vertical) |
|
131 | or from columns (Qt::Vertical) | |
132 | */ |
|
132 | */ | |
133 | Qt::Orientation QBarModelMapper::orientation() const |
|
133 | Qt::Orientation QBarModelMapper::orientation() const | |
134 | { |
|
134 | { | |
135 | Q_D(const QBarModelMapper); |
|
135 | Q_D(const QBarModelMapper); | |
136 | return d->m_orientation; |
|
136 | return d->m_orientation; | |
137 | } |
|
137 | } | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | Returns the \a orientation that is used when QBarModelMapper accesses the model. |
|
140 | Returns the \a orientation that is used when QBarModelMapper accesses the model. | |
141 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) |
|
141 | This mean whether the consecutive values of the pie are read from row (Qt::Horizontal) | |
142 | or from columns (Qt::Vertical) |
|
142 | or from columns (Qt::Vertical) | |
143 | */ |
|
143 | */ | |
144 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) |
|
144 | void QBarModelMapper::setOrientation(Qt::Orientation orientation) | |
145 | { |
|
145 | { | |
146 | Q_D(QBarModelMapper); |
|
146 | Q_D(QBarModelMapper); | |
147 | d->m_orientation = orientation; |
|
147 | d->m_orientation = orientation; | |
148 | d->initializeBarFromModel(); |
|
148 | d->initializeBarFromModel(); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | Returns which section of the model is used as the data source for the first bar set |
|
152 | Returns which section of the model is used as the data source for the first bar set | |
153 | */ |
|
153 | */ | |
154 | int QBarModelMapper::firstBarSetSection() const |
|
154 | int QBarModelMapper::firstBarSetSection() const | |
155 | { |
|
155 | { | |
156 | Q_D(const QBarModelMapper); |
|
156 | Q_D(const QBarModelMapper); | |
157 | return d->m_firstBarSetSection; |
|
157 | return d->m_firstBarSetSection; | |
158 | } |
|
158 | } | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Sets the model section that is used as the data source for the first bar set |
|
161 | Sets the model section that is used as the data source for the first bar set | |
162 | Parameter \a firstBarSetSection specifies the section of the model. |
|
162 | Parameter \a firstBarSetSection specifies the section of the model. | |
163 | */ |
|
163 | */ | |
164 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) |
|
164 | void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection) | |
165 | { |
|
165 | { | |
166 | Q_D(QBarModelMapper); |
|
166 | Q_D(QBarModelMapper); | |
167 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); |
|
167 | d->m_firstBarSetSection = qMax(-1, firstBarSetSection); | |
168 | d->initializeBarFromModel(); |
|
168 | d->initializeBarFromModel(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Returns which section of the model is used as the data source for the last bar set |
|
172 | Returns which section of the model is used as the data source for the last bar set | |
173 | */ |
|
173 | */ | |
174 | int QBarModelMapper::lastBarSetSection() const |
|
174 | int QBarModelMapper::lastBarSetSection() const | |
175 | { |
|
175 | { | |
176 | Q_D(const QBarModelMapper); |
|
176 | Q_D(const QBarModelMapper); | |
177 | return d->m_lastBarSetSection; |
|
177 | return d->m_lastBarSetSection; | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Sets the model section that is used as the data source for the last bar set |
|
181 | Sets the model section that is used as the data source for the last bar set | |
182 | Parameter \a lastBarSetSection specifies the section of the model. |
|
182 | Parameter \a lastBarSetSection specifies the section of the model. | |
183 | */ |
|
183 | */ | |
184 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) |
|
184 | void QBarModelMapper::setLastBarSetSection(int lastBarSetSection) | |
185 | { |
|
185 | { | |
186 | Q_D(QBarModelMapper); |
|
186 | Q_D(QBarModelMapper); | |
187 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); |
|
187 | d->m_lastBarSetSection = qMax(-1, lastBarSetSection); | |
188 | d->initializeBarFromModel(); |
|
188 | d->initializeBarFromModel(); | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
191 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
192 |
|
192 | |||
193 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : |
|
193 | QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) : | |
194 | m_series(0), |
|
194 | m_series(0), | |
195 | m_model(0), |
|
195 | m_model(0), | |
196 | m_first(0), |
|
196 | m_first(0), | |
197 | m_count(-1), |
|
197 | m_count(-1), | |
198 | m_orientation(Qt::Vertical), |
|
198 | m_orientation(Qt::Vertical), | |
199 | m_firstBarSetSection(-1), |
|
199 | m_firstBarSetSection(-1), | |
200 | m_lastBarSetSection(-1), |
|
200 | m_lastBarSetSection(-1), | |
201 | m_seriesSignalsBlock(false), |
|
201 | m_seriesSignalsBlock(false), | |
202 | m_modelSignalsBlock(false), |
|
202 | m_modelSignalsBlock(false), | |
203 | q_ptr(q) |
|
203 | q_ptr(q) | |
204 | { |
|
204 | { | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | void QBarModelMapperPrivate::blockModelSignals(bool block) |
|
207 | void QBarModelMapperPrivate::blockModelSignals(bool block) | |
208 | { |
|
208 | { | |
209 | m_modelSignalsBlock = block; |
|
209 | m_modelSignalsBlock = block; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) |
|
212 | void QBarModelMapperPrivate::blockSeriesSignals(bool block) | |
213 | { |
|
213 | { | |
214 | m_seriesSignalsBlock = block; |
|
214 | m_seriesSignalsBlock = block; | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) |
|
217 | QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index) | |
218 | { |
|
218 | { | |
219 | if (!index.isValid()) |
|
219 | if (!index.isValid()) | |
220 | return 0; |
|
220 | return 0; | |
221 |
|
221 | |||
222 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { |
|
222 | if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) { | |
223 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { |
|
223 | if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) { | |
224 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) |
|
224 | // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid()) | |
225 | return m_series->barSets().at(index.column() - m_firstBarSetSection); |
|
225 | return m_series->barSets().at(index.column() - m_firstBarSetSection); | |
226 | // else |
|
226 | // else | |
227 | // return 0; |
|
227 | // return 0; | |
228 | } |
|
228 | } | |
229 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { |
|
229 | } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) { | |
230 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) |
|
230 | if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count)) | |
231 | return m_series->barSets().at(index.row() - m_firstBarSetSection); |
|
231 | return m_series->barSets().at(index.row() - m_firstBarSetSection); | |
232 | } |
|
232 | } | |
233 | return 0; // This part of model has not been mapped to any slice |
|
233 | return 0; // This part of model has not been mapped to any slice | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) |
|
236 | QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar) | |
237 | { |
|
237 | { | |
238 | if (m_count != -1 && posInBar >= m_count) |
|
238 | if (m_count != -1 && posInBar >= m_count) | |
239 | return QModelIndex(); // invalid |
|
239 | return QModelIndex(); // invalid | |
240 |
|
240 | |||
241 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) |
|
241 | if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection) | |
242 | return QModelIndex(); // invalid |
|
242 | return QModelIndex(); // invalid | |
243 |
|
243 | |||
244 | if (m_orientation == Qt::Vertical) |
|
244 | if (m_orientation == Qt::Vertical) | |
245 | return m_model->index(posInBar + m_first, barSection); |
|
245 | return m_model->index(posInBar + m_first, barSection); | |
246 | else |
|
246 | else | |
247 | return m_model->index(barSection, posInBar + m_first); |
|
247 | return m_model->index(barSection, posInBar + m_first); | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
250 | void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) | |
251 | { |
|
251 | { | |
252 | Q_UNUSED(topLeft) |
|
252 | Q_UNUSED(topLeft) | |
253 | Q_UNUSED(bottomRight) |
|
253 | Q_UNUSED(bottomRight) | |
254 |
|
254 | |||
255 | if (m_model == 0 || m_series == 0) |
|
255 | if (m_model == 0 || m_series == 0) | |
256 | return; |
|
256 | return; | |
257 |
|
257 | |||
258 | if (m_modelSignalsBlock) |
|
258 | if (m_modelSignalsBlock) | |
259 | return; |
|
259 | return; | |
260 |
|
260 | |||
261 | blockSeriesSignals(); |
|
261 | blockSeriesSignals(); | |
262 | QModelIndex index; |
|
262 | QModelIndex index; | |
263 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
263 | for (int row = topLeft.row(); row <= bottomRight.row(); row++) { | |
264 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
264 | for (int column = topLeft.column(); column <= bottomRight.column(); column++) { | |
265 | index = topLeft.sibling(row, column); |
|
265 | index = topLeft.sibling(row, column); | |
266 | QBarSet* bar = barSet(index); |
|
266 | QBarSet* bar = barSet(index); | |
267 | if (bar) { |
|
267 | if (bar) { | |
268 | if (m_orientation == Qt::Vertical) |
|
268 | if (m_orientation == Qt::Vertical) | |
269 | bar->replace(row - m_first, m_model->data(index).toReal()); |
|
269 | bar->replace(row - m_first, m_model->data(index).toReal()); | |
270 | else |
|
270 | else | |
271 | bar->replace(column - m_first, m_model->data(index).toReal()); |
|
271 | bar->replace(column - m_first, m_model->data(index).toReal()); | |
272 | } |
|
272 | } | |
273 | } |
|
273 | } | |
274 | } |
|
274 | } | |
275 | blockSeriesSignals(false); |
|
275 | blockSeriesSignals(false); | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) |
|
278 | void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last) | |
279 | { |
|
279 | { | |
280 | if (m_model == 0 || m_series == 0) |
|
280 | if (m_model == 0 || m_series == 0) | |
281 | return; |
|
281 | return; | |
282 |
|
282 | |||
283 | if (m_modelSignalsBlock) |
|
283 | if (m_modelSignalsBlock) | |
284 | return; |
|
284 | return; | |
285 |
|
285 | |||
286 | blockSeriesSignals(); |
|
286 | blockSeriesSignals(); | |
287 | if (orientation != m_orientation) { |
|
287 | if (orientation != m_orientation) { | |
288 | for (int section = first; section <= last; section++) { |
|
288 | for (int section = first; section <= last; section++) { | |
289 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { |
|
289 | if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) { | |
290 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); |
|
290 | QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection); | |
291 | if (bar) |
|
291 | if (bar) | |
292 | bar->setLabel(m_model->headerData(section, orientation).toString()); |
|
292 | bar->setLabel(m_model->headerData(section, orientation).toString()); | |
293 | } |
|
293 | } | |
294 | } |
|
294 | } | |
295 | } |
|
295 | } | |
296 | blockSeriesSignals(false); |
|
296 | blockSeriesSignals(false); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) |
|
299 | void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end) | |
300 | { |
|
300 | { | |
301 | Q_UNUSED(parent); |
|
301 | Q_UNUSED(parent); | |
302 | Q_UNUSED(end) |
|
302 | Q_UNUSED(end) | |
303 | if (m_modelSignalsBlock) |
|
303 | if (m_modelSignalsBlock) | |
304 | return; |
|
304 | return; | |
305 |
|
305 | |||
306 | blockSeriesSignals(); |
|
306 | blockSeriesSignals(); | |
307 | if (m_orientation == Qt::Vertical) |
|
307 | if (m_orientation == Qt::Vertical) | |
308 | // insertData(start, end); |
|
308 | // insertData(start, end); | |
309 | initializeBarFromModel(); |
|
309 | initializeBarFromModel(); | |
310 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
310 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
311 | initializeBarFromModel(); |
|
311 | initializeBarFromModel(); | |
312 | blockSeriesSignals(false); |
|
312 | blockSeriesSignals(false); | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) |
|
315 | void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end) | |
316 | { |
|
316 | { | |
317 | Q_UNUSED(parent); |
|
317 | Q_UNUSED(parent); | |
318 | Q_UNUSED(end) |
|
318 | Q_UNUSED(end) | |
319 | if (m_modelSignalsBlock) |
|
319 | if (m_modelSignalsBlock) | |
320 | return; |
|
320 | return; | |
321 |
|
321 | |||
322 | blockSeriesSignals(); |
|
322 | blockSeriesSignals(); | |
323 | if (m_orientation == Qt::Vertical) |
|
323 | if (m_orientation == Qt::Vertical) | |
324 | // removeData(start, end); |
|
324 | // removeData(start, end); | |
325 | initializeBarFromModel(); |
|
325 | initializeBarFromModel(); | |
326 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
326 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
327 | initializeBarFromModel(); |
|
327 | initializeBarFromModel(); | |
328 | blockSeriesSignals(false); |
|
328 | blockSeriesSignals(false); | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) |
|
331 | void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end) | |
332 | { |
|
332 | { | |
333 | Q_UNUSED(parent); |
|
333 | Q_UNUSED(parent); | |
334 | Q_UNUSED(end) |
|
334 | Q_UNUSED(end) | |
335 | if (m_modelSignalsBlock) |
|
335 | if (m_modelSignalsBlock) | |
336 | return; |
|
336 | return; | |
337 |
|
337 | |||
338 | blockSeriesSignals(); |
|
338 | blockSeriesSignals(); | |
339 | if (m_orientation == Qt::Horizontal) |
|
339 | if (m_orientation == Qt::Horizontal) | |
340 | // insertData(start, end); |
|
340 | // insertData(start, end); | |
341 | initializeBarFromModel(); |
|
341 | initializeBarFromModel(); | |
342 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
342 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
343 | initializeBarFromModel(); |
|
343 | initializeBarFromModel(); | |
344 | blockSeriesSignals(false); |
|
344 | blockSeriesSignals(false); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) |
|
347 | void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end) | |
348 | { |
|
348 | { | |
349 | Q_UNUSED(parent); |
|
349 | Q_UNUSED(parent); | |
350 | Q_UNUSED(end) |
|
350 | Q_UNUSED(end) | |
351 | if (m_modelSignalsBlock) |
|
351 | if (m_modelSignalsBlock) | |
352 | return; |
|
352 | return; | |
353 |
|
353 | |||
354 | blockSeriesSignals(); |
|
354 | blockSeriesSignals(); | |
355 | if (m_orientation == Qt::Horizontal) |
|
355 | if (m_orientation == Qt::Horizontal) | |
356 | // removeData(start, end); |
|
356 | // removeData(start, end); | |
357 | initializeBarFromModel(); |
|
357 | initializeBarFromModel(); | |
358 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize |
|
358 | else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize | |
359 | initializeBarFromModel(); |
|
359 | initializeBarFromModel(); | |
360 | blockSeriesSignals(false); |
|
360 | blockSeriesSignals(false); | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | void QBarModelMapperPrivate::insertData(int start, int end) |
|
363 | void QBarModelMapperPrivate::insertData(int start, int end) | |
364 | { |
|
364 | { | |
365 | Q_UNUSED(end) |
|
365 | Q_UNUSED(end) | |
366 | Q_UNUSED(start) |
|
366 | Q_UNUSED(start) | |
367 | Q_UNUSED(end) |
|
367 | Q_UNUSED(end) | |
368 | // To be implemented |
|
368 | // To be implemented | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | void QBarModelMapperPrivate::removeData(int start, int end) |
|
371 | void QBarModelMapperPrivate::removeData(int start, int end) | |
372 | { |
|
372 | { | |
373 | Q_UNUSED(end) |
|
373 | Q_UNUSED(end) | |
374 | Q_UNUSED(start) |
|
374 | Q_UNUSED(start) | |
375 | Q_UNUSED(end) |
|
375 | Q_UNUSED(end) | |
376 | // To be implemented |
|
376 | // To be implemented | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) |
|
379 | void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets) | |
380 | { |
|
380 | { | |
381 | if (m_seriesSignalsBlock) |
|
381 | if (m_seriesSignalsBlock) | |
382 | return; |
|
382 | return; | |
383 |
|
383 | |||
384 | if (sets.count() == 0) |
|
384 | if (sets.count() == 0) | |
385 | return; |
|
385 | return; | |
386 |
|
386 | |||
387 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); |
|
387 | int firstIndex = m_series->barSets().indexOf(sets.at(0)); | |
388 | if (firstIndex == -1) |
|
388 | if (firstIndex == -1) | |
389 | return; |
|
389 | return; | |
390 |
|
390 | |||
391 | int maxCount = 0; |
|
391 | int maxCount = 0; | |
392 | for(int i = 0; i < sets.count(); i++) |
|
392 | for(int i = 0; i < sets.count(); i++) | |
393 | if (sets.at(i)->count() > m_count) |
|
393 | if (sets.at(i)->count() > m_count) | |
394 | maxCount = sets.at(i)->count(); |
|
394 | maxCount = sets.at(i)->count(); | |
395 |
|
395 | |||
396 | if (m_count != -1 && m_count < maxCount) |
|
396 | if (m_count != -1 && m_count < maxCount) | |
397 | m_count = maxCount; |
|
397 | m_count = maxCount; | |
398 |
|
398 | |||
399 | m_lastBarSetSection += sets.count(); |
|
399 | m_lastBarSetSection += sets.count(); | |
400 |
|
400 | |||
401 | blockModelSignals(); |
|
401 | blockModelSignals(); | |
402 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; |
|
402 | int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first; | |
403 | if (maxCount > modelCapacity) { |
|
403 | if (maxCount > modelCapacity) { | |
404 | if (m_orientation == Qt::Vertical) |
|
404 | if (m_orientation == Qt::Vertical) | |
405 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); |
|
405 | m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity); | |
406 | else |
|
406 | else | |
407 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); |
|
407 | m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity); | |
408 | } |
|
408 | } | |
409 |
|
409 | |||
410 | if (m_orientation == Qt::Vertical) |
|
410 | if (m_orientation == Qt::Vertical) | |
411 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
411 | m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
412 | else |
|
412 | else | |
413 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
413 | m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count()); | |
414 |
|
414 | |||
415 |
|
415 | |||
416 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { |
|
416 | for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) { | |
417 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); |
|
417 | m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label()); | |
418 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) |
|
418 | for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++) | |
419 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j)); |
|
419 | m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j)); | |
420 | } |
|
420 | } | |
421 | blockModelSignals(false); |
|
421 | blockModelSignals(false); | |
422 | initializeBarFromModel(); |
|
422 | initializeBarFromModel(); | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) |
|
425 | void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets) | |
426 | { |
|
426 | { | |
427 | if (m_seriesSignalsBlock) |
|
427 | if (m_seriesSignalsBlock) | |
428 | return; |
|
428 | return; | |
429 |
|
429 | |||
430 | if (sets.count() == 0) |
|
430 | if (sets.count() == 0) | |
431 | return; |
|
431 | return; | |
432 |
|
432 | |||
433 | int firstIndex = m_barSets.indexOf(sets.at(0)); |
|
433 | int firstIndex = m_barSets.indexOf(sets.at(0)); | |
434 | if (firstIndex == -1) |
|
434 | if (firstIndex == -1) | |
435 | return; |
|
435 | return; | |
436 |
|
436 | |||
437 | m_lastBarSetSection -= sets.count(); |
|
437 | m_lastBarSetSection -= sets.count(); | |
438 |
|
438 | |||
439 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) |
|
439 | for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--) | |
440 | m_barSets.removeAt(i); |
|
440 | m_barSets.removeAt(i); | |
441 |
|
441 | |||
442 | blockModelSignals(); |
|
442 | blockModelSignals(); | |
443 | if (m_orientation == Qt::Vertical) |
|
443 | if (m_orientation == Qt::Vertical) | |
444 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); |
|
444 | m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count()); | |
445 | else |
|
445 | else | |
446 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); |
|
446 | m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count()); | |
447 | blockModelSignals(false); |
|
447 | blockModelSignals(false); | |
448 | initializeBarFromModel(); |
|
448 | initializeBarFromModel(); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | void QBarModelMapperPrivate::valuesAdded(int index, int count) |
|
451 | void QBarModelMapperPrivate::valuesAdded(int index, int count) | |
452 | { |
|
452 | { | |
453 | if (m_seriesSignalsBlock) |
|
453 | if (m_seriesSignalsBlock) | |
454 | return; |
|
454 | return; | |
455 |
|
455 | |||
456 | if (m_count != -1) |
|
456 | if (m_count != -1) | |
457 | m_count += count; |
|
457 | m_count += count; | |
458 |
|
458 | |||
459 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
459 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
460 |
|
460 | |||
461 | blockModelSignals(); |
|
461 | blockModelSignals(); | |
462 | if (m_orientation == Qt::Vertical) |
|
462 | if (m_orientation == Qt::Vertical) | |
463 | m_model->insertRows(index + m_first, count); |
|
463 | m_model->insertRows(index + m_first, count); | |
464 | else |
|
464 | else | |
465 | m_model->insertColumns(index + m_first, count); |
|
465 | m_model->insertColumns(index + m_first, count); | |
466 |
|
466 | |||
467 | for (int j = index; j < index + count; j++) |
|
467 | for (int j = index; j < index + count; j++) | |
468 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j)); |
|
468 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j)); | |
469 |
|
469 | |||
470 | blockModelSignals(false); |
|
470 | blockModelSignals(false); | |
471 | initializeBarFromModel(); |
|
471 | initializeBarFromModel(); | |
472 | } |
|
472 | } | |
473 |
|
473 | |||
474 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) |
|
474 | void QBarModelMapperPrivate::valuesRemoved(int index, int count) | |
475 | { |
|
475 | { | |
476 | if (m_seriesSignalsBlock) |
|
476 | if (m_seriesSignalsBlock) | |
477 | return; |
|
477 | return; | |
478 |
|
478 | |||
479 | if (m_count != -1) |
|
479 | if (m_count != -1) | |
480 | m_count -= count; |
|
480 | m_count -= count; | |
481 |
|
481 | |||
482 | blockModelSignals(); |
|
482 | blockModelSignals(); | |
483 | if (m_orientation == Qt::Vertical) |
|
483 | if (m_orientation == Qt::Vertical) | |
484 | m_model->removeRows(index + m_first, count); |
|
484 | m_model->removeRows(index + m_first, count); | |
485 | else |
|
485 | else | |
486 | m_model->removeColumns(index + m_first, count); |
|
486 | m_model->removeColumns(index + m_first, count); | |
487 |
|
487 | |||
488 | blockModelSignals(false); |
|
488 | blockModelSignals(false); | |
489 | initializeBarFromModel(); |
|
489 | initializeBarFromModel(); | |
490 | } |
|
490 | } | |
491 |
|
491 | |||
492 | void QBarModelMapperPrivate::barLabelChanged() |
|
492 | void QBarModelMapperPrivate::barLabelChanged() | |
493 | { |
|
493 | { | |
494 | if (m_seriesSignalsBlock) |
|
494 | if (m_seriesSignalsBlock) | |
495 | return; |
|
495 | return; | |
496 |
|
496 | |||
497 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
497 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
498 |
|
498 | |||
499 | blockModelSignals(); |
|
499 | blockModelSignals(); | |
500 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); |
|
500 | m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label()); | |
501 | blockModelSignals(false); |
|
501 | blockModelSignals(false); | |
502 | initializeBarFromModel(); |
|
502 | initializeBarFromModel(); | |
503 | } |
|
503 | } | |
504 |
|
504 | |||
505 | void QBarModelMapperPrivate::barValueChanged(int index) |
|
505 | void QBarModelMapperPrivate::barValueChanged(int index) | |
506 | { |
|
506 | { | |
507 | if (m_seriesSignalsBlock) |
|
507 | if (m_seriesSignalsBlock) | |
508 | return; |
|
508 | return; | |
509 |
|
509 | |||
510 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); |
|
510 | int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender())); | |
511 |
|
511 | |||
512 | blockModelSignals(); |
|
512 | blockModelSignals(); | |
513 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index)); |
|
513 | m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index)); | |
514 | blockModelSignals(false); |
|
514 | blockModelSignals(false); | |
515 | initializeBarFromModel(); |
|
515 | initializeBarFromModel(); | |
516 | } |
|
516 | } | |
517 |
|
517 | |||
518 | void QBarModelMapperPrivate::initializeBarFromModel() |
|
518 | void QBarModelMapperPrivate::initializeBarFromModel() | |
519 | { |
|
519 | { | |
520 | if (m_model == 0 || m_series == 0) |
|
520 | if (m_model == 0 || m_series == 0) | |
521 | return; |
|
521 | return; | |
522 |
|
522 | |||
523 | blockSeriesSignals(); |
|
523 | blockSeriesSignals(); | |
524 | // clear current content |
|
524 | // clear current content | |
525 | m_series->clear(); |
|
525 | m_series->clear(); | |
526 | m_barSets.clear(); |
|
526 | m_barSets.clear(); | |
527 |
|
527 | |||
528 | // create the initial bar sets |
|
528 | // create the initial bar sets | |
529 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { |
|
529 | for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) { | |
530 | int posInBar = 0; |
|
530 | int posInBar = 0; | |
531 | QModelIndex barIndex = barModelIndex(i, posInBar); |
|
531 | QModelIndex barIndex = barModelIndex(i, posInBar); | |
532 | // check if there is such model index |
|
532 | // check if there is such model index | |
533 | if (barIndex.isValid()) { |
|
533 | if (barIndex.isValid()) { | |
534 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); |
|
534 | QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString()); | |
535 | while (barIndex.isValid()) { |
|
535 | while (barIndex.isValid()) { | |
536 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); |
|
536 | barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble()); | |
537 | posInBar++; |
|
537 | posInBar++; | |
538 | barIndex = barModelIndex(i, posInBar); |
|
538 | barIndex = barModelIndex(i, posInBar); | |
539 | } |
|
539 | } | |
540 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); |
|
540 | connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int))); | |
541 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); |
|
541 | connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int))); | |
542 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); |
|
542 | connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int))); | |
543 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); |
|
543 | connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged())); | |
544 | m_series->append(barSet); |
|
544 | m_series->append(barSet); | |
545 | m_barSets.append(barSet); |
|
545 | m_barSets.append(barSet); | |
546 | } else { |
|
546 | } else { | |
547 | break; |
|
547 | break; | |
548 | } |
|
548 | } | |
549 | } |
|
549 | } | |
550 | blockSeriesSignals(false); |
|
550 | blockSeriesSignals(false); | |
551 | } |
|
551 | } | |
552 |
|
552 | |||
553 | #include "moc_qbarmodelmapper.cpp" |
|
553 | #include "moc_qbarmodelmapper.cpp" | |
554 | #include "moc_qbarmodelmapper_p.cpp" |
|
554 | #include "moc_qbarmodelmapper_p.cpp" | |
555 |
|
555 | |||
556 | QTCOMMERCIALCHART_END_NAMESPACE |
|
556 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,616 +1,616 | |||||
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 Building block for different bar charts |
|
28 | \brief Building block for different bar charts | |
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 QAbstractBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 | /*! |
|
39 | /*! | |
40 | \qmlclass BarSet QBarSet |
|
40 | \qmlclass BarSet QBarSet | |
41 |
|
41 | |||
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
43 | First value of set is assumed to belong to first category, second to second category and so on. | |
44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
44 | If set has fewer values than there are categories, then the missing values are assumed to be | |
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries |
|
46 | \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarSet::label |
|
50 | \property QBarSet::label | |
51 | Defines the label of the barSet. |
|
51 | Defines the label of the barSet. | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlproperty string BarSet::label |
|
54 | \qmlproperty string BarSet::label | |
55 | Defines the label of the barSet. |
|
55 | Defines the label of the barSet. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QBarSet::pen |
|
59 | \property QBarSet::pen | |
60 | \brief Defines the pen used by the barSet. |
|
60 | \brief Defines the pen used by the barSet. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSet::brush |
|
64 | \property QBarSet::brush | |
65 | \brief Defines the brush used by the barSet. |
|
65 | \brief Defines the brush used by the barSet. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarSet::labelBrush |
|
69 | \property QBarSet::labelBrush | |
70 | \brief Defines the brush used by the barSet's label. |
|
70 | \brief Defines the brush used by the barSet's label. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarSet::labelFont |
|
74 | \property QBarSet::labelFont | |
75 | \brief Defines the font used by the barSet's label. |
|
75 | \brief Defines the font used by the barSet's label. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty Font BarSet::labelFont |
|
79 | \qmlproperty Font BarSet::labelFont | |
80 | Defines the font used by the barSet's label. |
|
80 | Defines the font used by the barSet's label. | |
81 |
|
81 | |||
82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
82 | See the \l {Font} {QML Font Element} for detailed documentation. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSet::color |
|
86 | \property QBarSet::color | |
87 | The fill (brush) color of the bar set. |
|
87 | The fill (brush) color of the bar set. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty color BarSet::color |
|
90 | \qmlproperty color BarSet::color | |
91 | The fill (brush) color of the bar set. |
|
91 | The fill (brush) color of the bar set. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarSet::borderColor |
|
95 | \property QBarSet::borderColor | |
96 | The line (pen) color of the bar set. |
|
96 | The line (pen) color of the bar set. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty color BarSet::borderColor |
|
99 | \qmlproperty color BarSet::borderColor | |
100 | The line (pen) color of the bar set. |
|
100 | The line (pen) color of the bar set. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QBarSet::labelColor |
|
104 | \property QBarSet::labelColor | |
105 | The text (label) color of the bar set. |
|
105 | The text (label) color of the bar set. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty color BarSet::labelColor |
|
108 | \qmlproperty color BarSet::labelColor | |
109 | The text (label) color of the bar set. |
|
109 | The text (label) color of the bar set. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QBarSet::clicked(int index) |
|
113 | \fn void QBarSet::clicked(int index) | |
114 |
|
114 | |||
115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
115 | The signal is emitted if the user clicks with a mouse on top of barset. | |
116 | Clicked bar inside set is indexed by \a index |
|
116 | Clicked bar inside set is indexed by \a index | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \fn void QBarSet::hovered(bool status) |
|
120 | \fn void QBarSet::hovered(bool status) | |
121 |
|
121 | |||
122 | The signal is emitted if mouse is hovered on top of barset. |
|
122 | The signal is emitted if mouse is hovered on top of barset. | |
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QBarSet::labelChanged() |
|
128 | \fn void QBarSet::labelChanged() | |
129 | This signal is emitted when the label of the barSet has changed. |
|
129 | This signal is emitted when the label of the barSet has changed. | |
130 | \sa label |
|
130 | \sa label | |
131 | */ |
|
131 | */ | |
132 | /*! |
|
132 | /*! | |
133 | \qmlsignal BarSet::onLabelChanged() |
|
133 | \qmlsignal BarSet::onLabelChanged() | |
134 | This signal is emitted when the label of the barSet has changed. |
|
134 | This signal is emitted when the label of the barSet has changed. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QBarSet::penChanged() |
|
138 | \fn void QBarSet::penChanged() | |
139 | This signal is emitted when the pen of the barSet has changed. |
|
139 | This signal is emitted when the pen of the barSet has changed. | |
140 | \sa pen |
|
140 | \sa pen | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn void QBarSet::brushChanged() |
|
144 | \fn void QBarSet::brushChanged() | |
145 | This signal is emitted when the brush of the barSet has changed. |
|
145 | This signal is emitted when the brush of the barSet has changed. | |
146 | \sa brush |
|
146 | \sa brush | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QBarSet::labelBrushChanged() |
|
150 | \fn void QBarSet::labelBrushChanged() | |
151 | This signal is emitted when the brush of the barSet's label has changed. |
|
151 | This signal is emitted when the brush of the barSet's label has changed. | |
152 | \sa labelBrush |
|
152 | \sa labelBrush | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QBarSet::labelFontChanged() |
|
156 | \fn void QBarSet::labelFontChanged() | |
157 | This signal is emitted when the font of the barSet's label has changed. |
|
157 | This signal is emitted when the font of the barSet's label has changed. | |
158 | \sa labelBrush |
|
158 | \sa labelBrush | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QBarSet::colorChanged(QColor) |
|
162 | \fn void QBarSet::colorChanged(QColor) | |
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
164 | */ |
|
164 | */ | |
165 | /*! |
|
165 | /*! | |
166 | \qmlsignal BarSet::onColorChanged(color color) |
|
166 | \qmlsignal BarSet::onColorChanged(color color) | |
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | \fn void QBarSet::borderColorChanged(QColor) |
|
171 | \fn void QBarSet::borderColorChanged(QColor) | |
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
173 | */ |
|
173 | */ | |
174 | /*! |
|
174 | /*! | |
175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
175 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
177 | */ |
|
177 | */ | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \fn void QBarSet::labelColorChanged(QColor) |
|
180 | \fn void QBarSet::labelColorChanged(QColor) | |
181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
181 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
182 | */ |
|
182 | */ | |
183 | /*! |
|
183 | /*! | |
184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
184 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
185 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
186 | */ |
|
186 | */ | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
189 | \fn void QBarSet::valuesAdded(int index, int count) | |
190 | This signal is emitted when new values have been added to the set. |
|
190 | This signal is emitted when new values have been added to the set. | |
191 | Parameter \a index indicates the position of the first inserted value. |
|
191 | Parameter \a index indicates the position of the first inserted value. | |
192 | Parameter \a count is the number of iserted values. |
|
192 | Parameter \a count is the number of iserted values. | |
193 | \sa append(), insert() |
|
193 | \sa append(), insert() | |
194 | */ |
|
194 | */ | |
195 | /*! |
|
195 | /*! | |
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
197 | This signal is emitted when new values have been added to the set. |
|
197 | This signal is emitted when new values have been added to the set. | |
198 | Parameter \a index indicates the position of the first inserted value. |
|
198 | Parameter \a index indicates the position of the first inserted value. | |
199 | Parameter \a count is the number of iserted values. |
|
199 | Parameter \a count is the number of iserted values. | |
200 | */ |
|
200 | */ | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
203 | \fn void QBarSet::valuesRemoved(int index, int count) | |
204 | This signal is emitted values have been removed from the set. |
|
204 | This signal is emitted values have been removed from the set. | |
205 | Parameter \a index indicates the position of the first removed value. |
|
205 | Parameter \a index indicates the position of the first removed value. | |
206 | Parameter \a count is the number of removed values. |
|
206 | Parameter \a count is the number of removed values. | |
207 | \sa remove() |
|
207 | \sa remove() | |
208 | */ |
|
208 | */ | |
209 | /*! |
|
209 | /*! | |
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
211 | This signal is emitted values have been removed from the set. |
|
211 | This signal is emitted values have been removed from the set. | |
212 | Parameter \a index indicates the position of the first removed value. |
|
212 | Parameter \a index indicates the position of the first removed value. | |
213 | Parameter \a count is the number of removed values. |
|
213 | Parameter \a count is the number of removed values. | |
214 | */ |
|
214 | */ | |
215 |
|
215 | |||
216 | /*! |
|
216 | /*! | |
217 | \fn void QBarSet::valueChanged(int index) |
|
217 | \fn void QBarSet::valueChanged(int index) | |
218 | This signal is emitted values the value in the set has been modified. |
|
218 | This signal is emitted values the value in the set has been modified. | |
219 | Parameter \a index indicates the position of the modified value. |
|
219 | Parameter \a index indicates the position of the modified value. | |
220 | \sa at() |
|
220 | \sa at() | |
221 | */ |
|
221 | */ | |
222 | /*! |
|
222 | /*! | |
223 | \qmlsignal BarSet::onValueChanged(int index) |
|
223 | \qmlsignal BarSet::onValueChanged(int index) | |
224 | This signal is emitted values the value in the set has been modified. |
|
224 | This signal is emitted values the value in the set has been modified. | |
225 | Parameter \a index indicates the position of the modified value. |
|
225 | Parameter \a index indicates the position of the modified value. | |
226 | */ |
|
226 | */ | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | \qmlproperty int BarSet::count |
|
229 | \qmlproperty int BarSet::count | |
230 | The count of values on the barset |
|
230 | The count of values on the barset | |
231 | */ |
|
231 | */ | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | \qmlproperty QVariantList BarSet::values |
|
234 | \qmlproperty QVariantList BarSet::values | |
235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of | |
236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
236 | reals as values, the values are automatically completed to points by using the index of a value as it's | |
237 | x-coordinate. For example: |
|
237 | x-coordinate. For example: | |
238 | \code |
|
238 | \code | |
239 | myBarSet1.values = [0, 5, 1, 5]; |
|
239 | myBarSet1.values = [0, 5, 1, 5]; | |
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; | |
241 | \endcode |
|
241 | \endcode | |
242 | */ |
|
242 | */ | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
245 | Constructs QBarSet with a label of \a label and with parent of \a parent | |
246 | */ |
|
246 | */ | |
247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
247 | QBarSet::QBarSet(const QString label, QObject *parent) | |
248 | : QObject(parent) |
|
248 | : QObject(parent) | |
249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
249 | ,d_ptr(new QBarSetPrivate(label,this)) | |
250 | { |
|
250 | { | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Destroys the barset |
|
254 | Destroys the barset | |
255 | */ |
|
255 | */ | |
256 | QBarSet::~QBarSet() |
|
256 | QBarSet::~QBarSet() | |
257 | { |
|
257 | { | |
258 | // NOTE: d_ptr destroyed by QObject |
|
258 | // NOTE: d_ptr destroyed by QObject | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Sets new \a label for set. |
|
262 | Sets new \a label for set. | |
263 | */ |
|
263 | */ | |
264 | void QBarSet::setLabel(const QString label) |
|
264 | void QBarSet::setLabel(const QString label) | |
265 | { |
|
265 | { | |
266 | d_ptr->m_label = label; |
|
266 | d_ptr->m_label = label; | |
267 | emit labelChanged(); |
|
267 | emit labelChanged(); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /*! |
|
270 | /*! | |
271 | Returns label of the set. |
|
271 | Returns label of the set. | |
272 | */ |
|
272 | */ | |
273 | QString QBarSet::label() const |
|
273 | QString QBarSet::label() const | |
274 | { |
|
274 | { | |
275 | return d_ptr->m_label; |
|
275 | return d_ptr->m_label; | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Appends new value \a value to the end of set. |
|
279 | Appends new value \a value to the end of set. | |
280 | */ |
|
280 | */ | |
281 | void QBarSet::append(const qreal value) |
|
281 | void QBarSet::append(const qreal value) | |
282 | { |
|
282 | { | |
283 | // Convert to QPointF |
|
283 | // Convert to QPointF | |
284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
284 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
285 | } |
|
285 | } | |
286 |
|
286 | |||
287 | /*! |
|
287 | /*! | |
288 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
288 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
289 | are appended to end of barset |
|
289 | are appended to end of barset | |
290 | \sa append() |
|
290 | \sa append() | |
291 | */ |
|
291 | */ | |
292 | void QBarSet::append(const QList<qreal> &values) |
|
292 | void QBarSet::append(const QList<qreal> &values) | |
293 | { |
|
293 | { | |
294 | int index = d_ptr->m_values.count(); |
|
294 | int index = d_ptr->m_values.count(); | |
295 | d_ptr->append(values); |
|
295 | d_ptr->append(values); | |
296 | emit valuesAdded(index, values.count()); |
|
296 | emit valuesAdded(index, values.count()); | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | Convinience operator. Same as append, with real \a value. |
|
300 | Convinience operator. Same as append, with real \a value. | |
301 | \sa append() |
|
301 | \sa append() | |
302 | */ |
|
302 | */ | |
303 | QBarSet& QBarSet::operator << (const qreal &value) |
|
303 | QBarSet& QBarSet::operator << (const qreal &value) | |
304 | { |
|
304 | { | |
305 | // append(value); |
|
305 | // append(value); | |
306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
306 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
307 | return *this; |
|
307 | return *this; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Inserts new \a value on the \a index position. |
|
311 | Inserts new \a value on the \a index position. | |
312 | The value that is currently at this postion is moved to postion index + 1 |
|
312 | The value that is currently at this postion is moved to postion index + 1 | |
313 | \sa remove() |
|
313 | \sa remove() | |
314 | */ |
|
314 | */ | |
315 | void QBarSet::insert(const int index, const qreal value) |
|
315 | void QBarSet::insert(const int index, const qreal value) | |
316 | { |
|
316 | { | |
317 | d_ptr->insert(index, value); |
|
317 | d_ptr->insert(index, value); | |
318 | emit valuesAdded(index,1); |
|
318 | emit valuesAdded(index,1); | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | /*! |
|
321 | /*! | |
322 | Removes \a count number of values from the set starting at \a index. |
|
322 | Removes \a count number of values from the set starting at \a index. | |
323 | \sa insert() |
|
323 | \sa insert() | |
324 | */ |
|
324 | */ | |
325 | void QBarSet::remove(const int index, const int count) |
|
325 | void QBarSet::remove(const int index, const int count) | |
326 | { |
|
326 | { | |
327 | int removedCount = d_ptr->remove(index,count); |
|
327 | int removedCount = d_ptr->remove(index,count); | |
328 | if (removedCount > 0) { |
|
328 | if (removedCount > 0) { | |
329 | emit valuesRemoved(index,removedCount); |
|
329 | emit valuesRemoved(index,removedCount); | |
330 | } |
|
330 | } | |
331 | return; |
|
331 | return; | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | /*! |
|
334 | /*! | |
335 | Sets a new value \a value to set, indexed by \a index |
|
335 | Sets a new value \a value to set, indexed by \a index | |
336 | */ |
|
336 | */ | |
337 | void QBarSet::replace(const int index, const qreal value) |
|
337 | void QBarSet::replace(const int index, const qreal value) | |
338 | { |
|
338 | { | |
339 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
339 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
340 | d_ptr->replace(index,value); |
|
340 | d_ptr->replace(index,value); | |
341 | emit valueChanged(index); |
|
341 | emit valueChanged(index); | |
342 | } |
|
342 | } | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 |
|
345 | |||
346 | /*! |
|
346 | /*! | |
347 | Returns value of set indexed by \a index. |
|
347 | Returns value of set indexed by \a index. | |
348 | If the index is out of bounds 0.0 is returned. |
|
348 | If the index is out of bounds 0.0 is returned. | |
349 | */ |
|
349 | */ | |
350 | qreal QBarSet::at(const int index) const |
|
350 | qreal QBarSet::at(const int index) const | |
351 | { |
|
351 | { | |
352 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
352 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
353 | return 0; |
|
353 | return 0; | |
354 | } |
|
354 | } | |
355 |
|
355 | |||
356 | return d_ptr->m_values.at(index).y(); |
|
356 | return d_ptr->m_values.at(index).y(); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Returns value of set indexed by \a index. |
|
360 | Returns value of set indexed by \a index. | |
361 | If the index is out of bounds 0.0 is returned. |
|
361 | If the index is out of bounds 0.0 is returned. | |
362 | */ |
|
362 | */ | |
363 | qreal QBarSet::operator [](const int index) const |
|
363 | qreal QBarSet::operator [](const int index) const | |
364 | { |
|
364 | { | |
365 | return at(index); |
|
365 | return at(index); | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | /*! |
|
368 | /*! | |
369 | Returns count of values in set. |
|
369 | Returns count of values in set. | |
370 | */ |
|
370 | */ | |
371 | int QBarSet::count() const |
|
371 | int QBarSet::count() const | |
372 | { |
|
372 | { | |
373 | return d_ptr->m_values.count(); |
|
373 | return d_ptr->m_values.count(); | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | /*! |
|
376 | /*! | |
377 | Returns sum of all values in barset. |
|
377 | Returns sum of all values in barset. | |
378 | */ |
|
378 | */ | |
379 | qreal QBarSet::sum() const |
|
379 | qreal QBarSet::sum() const | |
380 | { |
|
380 | { | |
381 | qreal total(0); |
|
381 | qreal total(0); | |
382 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
382 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
383 | total += d_ptr->m_values.at(i).y(); |
|
383 | total += d_ptr->m_values.at(i).y(); | |
384 | } |
|
384 | } | |
385 | return total; |
|
385 | return total; | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | /*! |
|
388 | /*! | |
389 | Sets pen for set. Bars of this set are drawn using \a pen |
|
389 | Sets pen for set. Bars of this set are drawn using \a pen | |
390 | */ |
|
390 | */ | |
391 | void QBarSet::setPen(const QPen &pen) |
|
391 | void QBarSet::setPen(const QPen &pen) | |
392 | { |
|
392 | { | |
393 | if(d_ptr->m_pen!=pen){ |
|
393 | if(d_ptr->m_pen!=pen){ | |
394 | d_ptr->m_pen = pen; |
|
394 | d_ptr->m_pen = pen; | |
395 | emit d_ptr->updatedBars(); |
|
395 | emit d_ptr->updatedBars(); | |
396 | emit penChanged(); |
|
396 | emit penChanged(); | |
397 | } |
|
397 | } | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | /*! |
|
400 | /*! | |
401 | Returns pen of the set. |
|
401 | Returns pen of the set. | |
402 | */ |
|
402 | */ | |
403 | QPen QBarSet::pen() const |
|
403 | QPen QBarSet::pen() const | |
404 | { |
|
404 | { | |
405 | return d_ptr->m_pen; |
|
405 | return d_ptr->m_pen; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | /*! |
|
408 | /*! | |
409 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
409 | Sets brush for the set. Bars of this set are drawn using \a brush | |
410 | */ |
|
410 | */ | |
411 | void QBarSet::setBrush(const QBrush &brush) |
|
411 | void QBarSet::setBrush(const QBrush &brush) | |
412 | { |
|
412 | { | |
413 | if(d_ptr->m_brush!=brush){ |
|
413 | if(d_ptr->m_brush!=brush){ | |
414 | d_ptr->m_brush = brush; |
|
414 | d_ptr->m_brush = brush; | |
415 | emit d_ptr->updatedBars(); |
|
415 | emit d_ptr->updatedBars(); | |
416 | emit brushChanged(); |
|
416 | emit brushChanged(); | |
417 | } |
|
417 | } | |
418 | } |
|
418 | } | |
419 |
|
419 | |||
420 | /*! |
|
420 | /*! | |
421 | Returns brush of the set. |
|
421 | Returns brush of the set. | |
422 | */ |
|
422 | */ | |
423 | QBrush QBarSet::brush() const |
|
423 | QBrush QBarSet::brush() const | |
424 | { |
|
424 | { | |
425 | return d_ptr->m_brush; |
|
425 | return d_ptr->m_brush; | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | /*! |
|
428 | /*! | |
429 | Sets \a brush of the values that are drawn on top of this barset |
|
429 | Sets \a brush of the values that are drawn on top of this barset | |
430 | */ |
|
430 | */ | |
431 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
431 | void QBarSet::setLabelBrush(const QBrush &brush) | |
432 | { |
|
432 | { | |
433 | if(d_ptr->m_labelBrush!=brush){ |
|
433 | if(d_ptr->m_labelBrush!=brush){ | |
434 | d_ptr->m_labelBrush = brush; |
|
434 | d_ptr->m_labelBrush = brush; | |
435 | emit d_ptr->updatedBars(); |
|
435 | emit d_ptr->updatedBars(); | |
436 | emit labelBrushChanged(); |
|
436 | emit labelBrushChanged(); | |
437 | } |
|
437 | } | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | /*! |
|
440 | /*! | |
441 | Returns brush of the values that are drawn on top of this barset |
|
441 | Returns brush of the values that are drawn on top of this barset | |
442 | */ |
|
442 | */ | |
443 | QBrush QBarSet::labelBrush() const |
|
443 | QBrush QBarSet::labelBrush() const | |
444 | { |
|
444 | { | |
445 | return d_ptr->m_labelBrush; |
|
445 | return d_ptr->m_labelBrush; | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 | /*! |
|
448 | /*! | |
449 | Sets the \a font for values that are drawn on top of this barset |
|
449 | Sets the \a font for values that are drawn on top of this barset | |
450 | */ |
|
450 | */ | |
451 | void QBarSet::setLabelFont(const QFont &font) |
|
451 | void QBarSet::setLabelFont(const QFont &font) | |
452 | { |
|
452 | { | |
453 | if(d_ptr->m_labelFont!=font) { |
|
453 | if(d_ptr->m_labelFont!=font) { | |
454 | d_ptr->m_labelFont = font; |
|
454 | d_ptr->m_labelFont = font; | |
455 | emit d_ptr->updatedBars(); |
|
455 | emit d_ptr->updatedBars(); | |
456 | emit labelFontChanged(); |
|
456 | emit labelFontChanged(); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | /*! |
|
461 | /*! | |
462 | Returns the pen for values that are drawn on top of this barset |
|
462 | Returns the pen for values that are drawn on top of this barset | |
463 | */ |
|
463 | */ | |
464 | QFont QBarSet::labelFont() const |
|
464 | QFont QBarSet::labelFont() const | |
465 | { |
|
465 | { | |
466 | return d_ptr->m_labelFont; |
|
466 | return d_ptr->m_labelFont; | |
467 | } |
|
467 | } | |
468 |
|
468 | |||
469 | /*! |
|
469 | /*! | |
470 | Returns the color of the brush of barset. |
|
470 | Returns the color of the brush of barset. | |
471 | */ |
|
471 | */ | |
472 | QColor QBarSet::color() |
|
472 | QColor QBarSet::color() | |
473 | { |
|
473 | { | |
474 | return brush().color(); |
|
474 | return brush().color(); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | /*! |
|
477 | /*! | |
478 | Sets the \a color of brush for this barset |
|
478 | Sets the \a color of brush for this barset | |
479 | */ |
|
479 | */ | |
480 | void QBarSet::setColor(QColor color) |
|
480 | void QBarSet::setColor(QColor color) | |
481 | { |
|
481 | { | |
482 | QBrush b = brush(); |
|
482 | QBrush b = brush(); | |
483 | if (b.color() != color) { |
|
483 | if (b.color() != color) { | |
484 | b.setColor(color); |
|
484 | b.setColor(color); | |
485 | setBrush(b); |
|
485 | setBrush(b); | |
486 | emit colorChanged(color); |
|
486 | emit colorChanged(color); | |
487 | } |
|
487 | } | |
488 | } |
|
488 | } | |
489 |
|
489 | |||
490 | /*! |
|
490 | /*! | |
491 | Returns the color of pen of this barset |
|
491 | Returns the color of pen of this barset | |
492 | */ |
|
492 | */ | |
493 | QColor QBarSet::borderColor() |
|
493 | QColor QBarSet::borderColor() | |
494 | { |
|
494 | { | |
495 | return pen().color(); |
|
495 | return pen().color(); | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | /*! |
|
498 | /*! | |
499 | Sets the color of pen for this barset |
|
499 | Sets the color of pen for this barset | |
500 | */ |
|
500 | */ | |
501 | void QBarSet::setBorderColor(QColor color) |
|
501 | void QBarSet::setBorderColor(QColor color) | |
502 | { |
|
502 | { | |
503 | QPen p = pen(); |
|
503 | QPen p = pen(); | |
504 | if (p.color() != color) { |
|
504 | if (p.color() != color) { | |
505 | p.setColor(color); |
|
505 | p.setColor(color); | |
506 | setPen(p); |
|
506 | setPen(p); | |
507 | emit borderColorChanged(color); |
|
507 | emit borderColorChanged(color); | |
508 | } |
|
508 | } | |
509 | } |
|
509 | } | |
510 |
|
510 | |||
511 | /*! |
|
511 | /*! | |
512 | Returns the color of labels of this barset |
|
512 | Returns the color of labels of this barset | |
513 | */ |
|
513 | */ | |
514 | QColor QBarSet::labelColor() |
|
514 | QColor QBarSet::labelColor() | |
515 | { |
|
515 | { | |
516 | return labelBrush().color(); |
|
516 | return labelBrush().color(); | |
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | /*! |
|
519 | /*! | |
520 | Sets the color of labels for this barset |
|
520 | Sets the color of labels for this barset | |
521 | */ |
|
521 | */ | |
522 | void QBarSet::setLabelColor(QColor color) |
|
522 | void QBarSet::setLabelColor(QColor color) | |
523 | { |
|
523 | { | |
524 | QBrush b = labelBrush(); |
|
524 | QBrush b = labelBrush(); | |
525 | if (b.color() != color) { |
|
525 | if (b.color() != color) { | |
526 | b.setColor(color); |
|
526 | b.setColor(color); | |
527 | setLabelBrush(b); |
|
527 | setLabelBrush(b); | |
528 | emit labelColorChanged(color); |
|
528 | emit labelColorChanged(color); | |
529 | } |
|
529 | } | |
530 | } |
|
530 | } | |
531 |
|
531 | |||
532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
532 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
533 |
|
533 | |||
534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
534 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
535 | q_ptr(parent), |
|
535 | q_ptr(parent), | |
536 | m_label(label) |
|
536 | m_label(label) | |
537 | { |
|
537 | { | |
538 | } |
|
538 | } | |
539 |
|
539 | |||
540 | QBarSetPrivate::~QBarSetPrivate() |
|
540 | QBarSetPrivate::~QBarSetPrivate() | |
541 | { |
|
541 | { | |
542 | } |
|
542 | } | |
543 |
|
543 | |||
544 | void QBarSetPrivate::append(QPointF value) |
|
544 | void QBarSetPrivate::append(QPointF value) | |
545 | { |
|
545 | { | |
546 | m_values.append(value); |
|
546 | m_values.append(value); | |
547 | emit restructuredBars(); |
|
547 | emit restructuredBars(); | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | void QBarSetPrivate::append(QList<QPointF> values) |
|
550 | void QBarSetPrivate::append(QList<QPointF> values) | |
551 | { |
|
551 | { | |
552 | for (int i=0; i<values.count(); i++) { |
|
552 | for (int i=0; i<values.count(); i++) { | |
553 | m_values.append(values.at(i)); |
|
553 | m_values.append(values.at(i)); | |
554 | } |
|
554 | } | |
555 | emit restructuredBars(); |
|
555 | emit restructuredBars(); | |
556 | } |
|
556 | } | |
557 |
|
557 | |||
558 | void QBarSetPrivate::append(QList<qreal> values) |
|
558 | void QBarSetPrivate::append(QList<qreal> values) | |
559 | { |
|
559 | { | |
560 | int index = m_values.count(); |
|
560 | int index = m_values.count(); | |
561 | for (int i=0; i<values.count(); i++) { |
|
561 | for (int i=0; i<values.count(); i++) { | |
562 | m_values.append(QPointF(index,values.at(i))); |
|
562 | m_values.append(QPointF(index,values.at(i))); | |
563 | index++; |
|
563 | index++; | |
564 | } |
|
564 | } | |
565 | emit restructuredBars(); |
|
565 | emit restructuredBars(); | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
568 | void QBarSetPrivate::insert(const int index, const qreal value) | |
569 | { |
|
569 | { | |
570 | m_values.insert(index, QPointF(index, value)); |
|
570 | m_values.insert(index, QPointF(index, value)); | |
571 | emit restructuredBars(); |
|
571 | emit restructuredBars(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
574 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
575 | { |
|
575 | { | |
576 | m_values.insert(index, value); |
|
576 | m_values.insert(index, value); | |
577 | emit restructuredBars(); |
|
577 | emit restructuredBars(); | |
578 | } |
|
578 | } | |
579 |
|
579 | |||
580 | int QBarSetPrivate::remove(const int index, const int count) |
|
580 | int QBarSetPrivate::remove(const int index, const int count) | |
581 | { |
|
581 | { | |
582 | int removeCount = count; |
|
582 | int removeCount = count; | |
583 |
|
583 | |||
584 | if ((index <0) || (m_values.count() == 0)) { |
|
584 | if ((index <0) || (m_values.count() == 0)) { | |
585 | // Invalid index or not values in list, remove nothing. |
|
585 | // Invalid index or not values in list, remove nothing. | |
586 | return 0; |
|
586 | return 0; | |
587 | } else if ((index + count) > m_values.count()) { |
|
587 | } else if ((index + count) > m_values.count()) { | |
588 | // Trying to remove more items than list has. Limit amount to be removed. |
|
588 | // Trying to remove more items than list has. Limit amount to be removed. | |
589 | removeCount = m_values.count() - index; |
|
589 | removeCount = m_values.count() - index; | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | int c = 0; |
|
592 | int c = 0; | |
593 | while (c < removeCount) { |
|
593 | while (c < removeCount) { | |
594 | m_values.removeAt(index); |
|
594 | m_values.removeAt(index); | |
595 | c++; |
|
595 | c++; | |
596 | } |
|
596 | } | |
597 | emit restructuredBars(); |
|
597 | emit restructuredBars(); | |
598 | return removeCount; |
|
598 | return removeCount; | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
601 | void QBarSetPrivate::replace(const int index, const qreal value) | |
602 | { |
|
602 | { | |
603 | m_values.replace(index,QPointF(index,value)); |
|
603 | m_values.replace(index,QPointF(index,value)); | |
604 | emit updatedBars(); |
|
604 | emit updatedBars(); | |
605 | } |
|
605 | } | |
606 |
|
606 | |||
607 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
607 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
608 | { |
|
608 | { | |
609 | m_values.replace(index,value); |
|
609 | m_values.replace(index,value); | |
610 | emit updatedBars(); |
|
610 | emit updatedBars(); | |
611 | } |
|
611 | } | |
612 |
|
612 | |||
613 | #include "moc_qbarset.cpp" |
|
613 | #include "moc_qbarset.cpp" | |
614 | #include "moc_qbarset_p.cpp" |
|
614 | #include "moc_qbarset_p.cpp" | |
615 |
|
615 | |||
616 | QTCOMMERCIALCHART_END_NAMESPACE |
|
616 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,115 +1,115 | |||||
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 label READ label WRITE setLabel NOTIFY labelChanged) |
|
35 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) | |
36 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
36 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) | |
37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) | |
38 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
38 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) | |
39 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) |
|
39 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) | |
40 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
40 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |
41 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
41 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |
42 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
42 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | explicit QBarSet(const QString label, QObject *parent = 0); |
|
45 | explicit QBarSet(const QString label, QObject *parent = 0); | |
46 | virtual ~QBarSet(); |
|
46 | virtual ~QBarSet(); | |
47 |
|
47 | |||
48 | void setLabel(const QString label); |
|
48 | void setLabel(const QString label); | |
49 | QString label() const; |
|
49 | QString label() const; | |
50 |
|
50 | |||
51 | void append(const qreal value); |
|
51 | void append(const qreal value); | |
52 | void append(const QList<qreal> &values); |
|
52 | void append(const QList<qreal> &values); | |
53 |
|
53 | |||
54 | QBarSet& operator << (const qreal &value); |
|
54 | QBarSet& operator << (const qreal &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, const int count = 1); |
|
57 | void remove(const int index, const int count = 1); | |
58 | void replace(const int index, const qreal value); |
|
58 | void replace(const int index, const qreal value); | |
59 | qreal at(const int index) const; |
|
59 | qreal at(const int index) const; | |
60 | qreal operator [] (const int index) const; |
|
60 | qreal 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 | QColor color(); |
|
76 | QColor color(); | |
77 | void setColor(QColor color); |
|
77 | void setColor(QColor color); | |
78 |
|
78 | |||
79 | QColor borderColor(); |
|
79 | QColor borderColor(); | |
80 | void setBorderColor(QColor color); |
|
80 | void setBorderColor(QColor color); | |
81 |
|
81 | |||
82 | QColor labelColor(); |
|
82 | QColor labelColor(); | |
83 | void setLabelColor(QColor color); |
|
83 | void setLabelColor(QColor color); | |
84 |
|
84 | |||
85 | Q_SIGNALS: |
|
85 | Q_SIGNALS: | |
86 | void clicked(int index); |
|
86 | void clicked(int index); | |
87 | void hovered(bool status); |
|
87 | void hovered(bool status); | |
88 | void penChanged(); |
|
88 | void penChanged(); | |
89 | void brushChanged(); |
|
89 | void brushChanged(); | |
90 | void labelChanged(); |
|
90 | void labelChanged(); | |
91 | void labelBrushChanged(); |
|
91 | void labelBrushChanged(); | |
92 | void labelFontChanged(); |
|
92 | void labelFontChanged(); | |
93 | void colorChanged(QColor color); |
|
93 | void colorChanged(QColor color); | |
94 | void borderColorChanged(QColor color); |
|
94 | void borderColorChanged(QColor color); | |
95 | void labelColorChanged(QColor color); |
|
95 | void labelColorChanged(QColor color); | |
96 |
|
96 | |||
97 | void valuesAdded(int index, int count); |
|
97 | void valuesAdded(int index, int count); | |
98 | void valuesRemoved(int index, int count); |
|
98 | void valuesRemoved(int index, int count); | |
99 | void valueChanged(int index); |
|
99 | void valueChanged(int index); | |
100 |
|
100 | |||
101 | private: |
|
101 | private: | |
102 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
102 | QScopedPointer<QBarSetPrivate> d_ptr; | |
103 | Q_DISABLE_COPY(QBarSet) |
|
103 | Q_DISABLE_COPY(QBarSet) | |
104 | friend class QBarSeries; |
|
104 | friend class QAbstractBarSeries; | |
105 | friend class BarLegendMarker; |
|
105 | friend class BarLegendMarker; | |
106 | friend class BarChartItem; |
|
106 | friend class BarChartItem; | |
107 | friend class QAbstractBarSeriesPrivate; |
|
107 | friend class QAbstractBarSeriesPrivate; | |
108 | friend class StackedBarChartItem; |
|
108 | friend class StackedBarChartItem; | |
109 | friend class PercentBarChartItem; |
|
109 | friend class PercentBarChartItem; | |
110 | friend class GroupedBarChartItem; |
|
110 | friend class GroupedBarChartItem; | |
111 | }; |
|
111 | }; | |
112 |
|
112 | |||
113 | QTCOMMERCIALCHART_END_NAMESPACE |
|
113 | QTCOMMERCIALCHART_END_NAMESPACE | |
114 |
|
114 | |||
115 | #endif // QBARSET_H |
|
115 | #endif // QBARSET_H |
@@ -1,119 +1,119 | |||||
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 | #include "qcategoriesaxis.h" |
|
27 | #include "qcategoriesaxis.h" | |
28 | #include "qvaluesaxis.h" |
|
28 | #include "qvaluesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QGroupedBarSeries |
|
33 | \class QGroupedBarSeries | |
34 | \brief Series for creating grouped bar chart |
|
34 | \brief Series for creating grouped bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data |
|
38 | as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data | |
39 | from sets to categories, which are defined by a QStringList. |
|
39 | from sets to categories, which are defined by a QStringList. | |
40 |
|
40 | |||
41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. |
|
41 | See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart. | |
42 | \image examples_groupedbarchart.png |
|
42 | \image examples_groupedbarchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass GroupedBarSeries QGroupedBarSeries |
|
47 | \qmlclass GroupedBarSeries QGroupedBarSeries | |
48 | \inherits BarSeries |
|
48 | \inherits BarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple grouped bar chart: |
|
50 | The following QML shows how to create a simple grouped bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart7.png |
|
53 | \image demos_qmlchart7.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QGroupedBarSeries. |
|
59 | Constructs empty QGroupedBarSeries. | |
60 | QGroupedBarSeries is QObject which is a child of a \a parent. |
|
60 | QGroupedBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) |
|
62 | QGroupedBarSeries::QGroupedBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QGroupedBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QGroupedBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Returns QChartSeries::SeriesTypeGroupedBar. |
|
68 | Returns QChartSeries::SeriesTypeGroupedBar. | |
69 | */ |
|
69 | */ | |
70 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QGroupedBarSeries::type() const | |
71 | { |
|
71 | { | |
72 | return QAbstractSeries::SeriesTypeGroupedBar; |
|
72 | return QAbstractSeries::SeriesTypeGroupedBar; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
76 |
|
76 | |||
77 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
77 | QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
78 | { |
|
78 | { | |
79 |
|
79 | |||
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
82 | void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain) | |
83 | { |
|
83 | { | |
84 | qreal minX(domain.minX()); |
|
84 | qreal minX(domain.minX()); | |
85 | qreal minY(domain.minY()); |
|
85 | qreal minY(domain.minY()); | |
86 | qreal maxX(domain.maxX()); |
|
86 | qreal maxX(domain.maxX()); | |
87 | qreal maxY(domain.maxY()); |
|
87 | qreal maxY(domain.maxY()); | |
88 | int tickXCount(domain.tickXCount()); |
|
88 | int tickXCount(domain.tickXCount()); | |
89 | int tickYCount(domain.tickYCount()); |
|
89 | int tickYCount(domain.tickYCount()); | |
90 |
|
90 | |||
91 | qreal x = categoryCount(); |
|
91 | qreal x = categoryCount(); | |
92 | qreal y = max(); |
|
92 | qreal y = max(); | |
93 | minX = qMin(minX, -0.5); |
|
93 | minX = qMin(minX, -0.5); | |
94 | minY = qMin(minY, y); |
|
94 | minY = qMin(minY, y); | |
95 | maxX = qMax(maxX, x - 0.5); |
|
95 | maxX = qMax(maxX, x - 0.5); | |
96 | maxY = qMax(maxY, y); |
|
96 | maxY = qMax(maxY, y); | |
97 | tickXCount = x+1; |
|
97 | tickXCount = x+1; | |
98 |
|
98 | |||
99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
99 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 |
|
102 | |||
103 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
103 | Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
104 | { |
|
104 | { | |
105 | Q_Q(QGroupedBarSeries); |
|
105 | Q_Q(QGroupedBarSeries); | |
106 |
|
106 | |||
107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); |
|
107 | GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter); | |
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
108 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
109 | presenter->animator()->addAnimation(bar); |
|
109 | presenter->animator()->addAnimation(bar); | |
110 | } |
|
110 | } | |
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
111 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
112 | return bar; |
|
112 | return bar; | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 |
|
115 | |||
116 | #include "moc_qgroupedbarseries.cpp" |
|
116 | #include "moc_qgroupedbarseries.cpp" | |
117 |
|
117 | |||
118 | QTCOMMERCIALCHART_END_NAMESPACE |
|
118 | QTCOMMERCIALCHART_END_NAMESPACE | |
119 |
|
119 |
@@ -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 GROUPEDBARSERIES_H |
|
21 | #ifndef GROUPEDBARSERIES_H | |
22 | #define GROUPEDBARSERIES_H |
|
22 | #define GROUPEDBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qbarseries.h> |
|
25 | #include <qabstractbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QGroupedBarSeriesPrivate; |
|
29 | class QGroupedBarSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QGroupedBarSeries : public QAbstractBarSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QGroupedBarSeries : public QAbstractBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 | explicit QGroupedBarSeries(QObject *parent = 0); |
|
35 | explicit QGroupedBarSeries(QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
39 | Q_DECLARE_PRIVATE(QGroupedBarSeries) |
|
39 | Q_DECLARE_PRIVATE(QGroupedBarSeries) | |
40 | Q_DISABLE_COPY(QGroupedBarSeries) |
|
40 | Q_DISABLE_COPY(QGroupedBarSeries) | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
44 | |||
45 | #endif // GROUPEDBARSERIES_H |
|
45 | #endif // GROUPEDBARSERIES_H |
@@ -1,52 +1,52 | |||||
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 QGROUPEDBARSERIES_P_H |
|
30 | #ifndef QGROUPEDBARSERIES_P_H | |
31 | #define QGROUPEDBARSERIES_P_H |
|
31 | #define QGROUPEDBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qabstractbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QGroupedBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
39 | class QGroupedBarSeriesPrivate: public QAbstractBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QGroupedBarSeriesPrivate(QGroupedBarSeries* q); |
|
42 | QGroupedBarSeriesPrivate(QGroupedBarSeries* q); | |
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | Q_DECLARE_PUBLIC(QGroupedBarSeries) |
|
47 | Q_DECLARE_PUBLIC(QGroupedBarSeries) | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif // QGROUPEDBARSERIES_P_H |
|
52 | #endif // QGROUPEDBARSERIES_P_H |
@@ -1,249 +1,249 | |||||
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 "qhbarmodelmapper.h" |
|
21 | #include "qhbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHBarModelMapper |
|
26 | \class QHBarModelMapper | |
27 | \brief Horizontal model mapper for bar series |
|
27 | \brief Horizontal model mapper for bar series | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
31 | Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass HBarModelMapper QHBarModelMapper |
|
37 | \qmlclass HBarModelMapper QHBarModelMapper | |
38 |
|
38 | |||
39 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
39 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
40 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
40 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |
41 | HBarModelMapper keeps the series and the model in sync. |
|
41 | HBarModelMapper keeps the series and the model in sync. | |
42 |
|
42 | |||
43 | The following QML example would create a bar series with three bar sets (assuming the model has |
|
43 | The following QML example would create a bar series with three bar sets (assuming the model has | |
44 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by |
|
44 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by | |
45 | the vertical header (of the row). |
|
45 | the vertical header (of the row). | |
46 | \code |
|
46 | \code | |
47 | BarSeries { |
|
47 | BarSeries { | |
48 | HBarModelMapper { |
|
48 | HBarModelMapper { | |
49 | model: myCustomModel // QAbstractItemModel derived implementation |
|
49 | model: myCustomModel // QAbstractItemModel derived implementation | |
50 | firstBarSetRow: 1 |
|
50 | firstBarSetRow: 1 | |
51 | lastBarSetRow: 3 |
|
51 | lastBarSetRow: 3 | |
52 | firstColumn: 1 |
|
52 | firstColumn: 1 | |
53 | } |
|
53 | } | |
54 | } |
|
54 | } | |
55 | \endcode |
|
55 | \endcode | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QHBarModelMapper::series |
|
59 | \property QHBarModelMapper::series | |
60 | \brief Defines the QPieSeries object that is used by the mapper. |
|
60 | \brief Defines the QPieSeries object that is used by the mapper. | |
61 |
|
61 | |||
62 | All the data in the series is discarded when it is set to the mapper. |
|
62 | All the data in the series is discarded when it is set to the mapper. | |
63 | When new series is specified the old series is disconnected (it preserves its data) |
|
63 | When new series is specified the old series is disconnected (it preserves its data) | |
64 | */ |
|
64 | */ | |
65 | /*! |
|
65 | /*! | |
66 | \qmlproperty BarSeries HBarModelMapper::series |
|
66 | \qmlproperty BarSeries HBarModelMapper::series | |
67 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
67 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
68 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
68 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QHBarModelMapper::model |
|
72 | \property QHBarModelMapper::model | |
73 | \brief Defines the model that is used by the mapper. |
|
73 | \brief Defines the model that is used by the mapper. | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
76 | \qmlproperty SomeModel HBarModelMapper::model |
|
76 | \qmlproperty SomeModel HBarModelMapper::model | |
77 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
77 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
78 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
78 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
79 | and modifying the data of the cells. |
|
79 | and modifying the data of the cells. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \property QHBarModelMapper::firstBarSetRow |
|
83 | \property QHBarModelMapper::firstBarSetRow | |
84 | \brief Defines which column of the model is used as the data source for the first bar set |
|
84 | \brief Defines which column of the model is used as the data source for the first bar set | |
85 | Default value is: -1 (invalid mapping) |
|
85 | Default value is: -1 (invalid mapping) | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty int HBarModelMapper::firstBarSetRow |
|
88 | \qmlproperty int HBarModelMapper::firstBarSetRow | |
89 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 |
|
89 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 | |
90 | (invalid mapping). |
|
90 | (invalid mapping). | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QHBarModelMapper::lastBarSetRow |
|
94 | \property QHBarModelMapper::lastBarSetRow | |
95 | \brief Defines which column of the model is used as the data source for the last bar set |
|
95 | \brief Defines which column of the model is used as the data source for the last bar set | |
96 | Default value is: -1 (invalid mapping) |
|
96 | Default value is: -1 (invalid mapping) | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty int HBarModelMapper::lastBarSetRow |
|
99 | \qmlproperty int HBarModelMapper::lastBarSetRow | |
100 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 |
|
100 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 | |
101 | (invalid mapping). |
|
101 | (invalid mapping). | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QHBarModelMapper::firstColumn |
|
105 | \property QHBarModelMapper::firstColumn | |
106 | \brief Defines which column of the model contains the first values of the QBarSets in the series. |
|
106 | \brief Defines which column of the model contains the first values of the QBarSets in the series. | |
107 | Minimal and default value is: 0 |
|
107 | Minimal and default value is: 0 | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty int HBarModelMapper::firstColumn |
|
110 | \qmlproperty int HBarModelMapper::firstColumn | |
111 | Defines which column of the model contains the first values of the QBarSets in the series. |
|
111 | Defines which column of the model contains the first values of the QBarSets in the series. | |
112 | The default value is 0. |
|
112 | The default value is 0. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \property QHBarModelMapper::columnCount |
|
116 | \property QHBarModelMapper::columnCount | |
117 | \brief Defines the number of columns of the model that are mapped as the data for QBarSeries |
|
117 | \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries | |
118 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
118 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
119 | */ |
|
119 | */ | |
120 | /*! |
|
120 | /*! | |
121 | \qmlproperty int HBarModelMapper::columnCount |
|
121 | \qmlproperty int HBarModelMapper::columnCount | |
122 | Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is |
|
122 | Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is | |
123 | -1 (count limited by the number of columns in the model) |
|
123 | -1 (count limited by the number of columns in the model) | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QHBarModelMapper::seriesReplaced() |
|
127 | \fn void QHBarModelMapper::seriesReplaced() | |
128 |
|
128 | |||
129 | Emitted when the series to which mapper is connected to has changed. |
|
129 | Emitted when the series to which mapper is connected to has changed. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QHBarModelMapper::modelReplaced() |
|
133 | \fn void QHBarModelMapper::modelReplaced() | |
134 |
|
134 | |||
135 | Emitted when the model to which mapper is connected to has changed. |
|
135 | Emitted when the model to which mapper is connected to has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
139 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |
140 |
|
140 | |||
141 | Emitted when the firstBarSetRow has changed. |
|
141 | Emitted when the firstBarSetRow has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
145 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |
146 |
|
146 | |||
147 | Emitted when the lastBarSetRow has changed. |
|
147 | Emitted when the lastBarSetRow has changed. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QHBarModelMapper::firstColumnChanged() |
|
151 | \fn void QHBarModelMapper::firstColumnChanged() | |
152 | Emitted when the firstColumn has changed. |
|
152 | Emitted when the firstColumn has changed. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QHBarModelMapper::columnCountChanged() |
|
156 | \fn void QHBarModelMapper::columnCountChanged() | |
157 | Emitted when the columnCount has changed. |
|
157 | Emitted when the columnCount has changed. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Constructs a mapper object which is a child of \a parent. |
|
161 | Constructs a mapper object which is a child of \a parent. | |
162 | */ |
|
162 | */ | |
163 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
163 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
164 | QBarModelMapper(parent) |
|
164 | QBarModelMapper(parent) | |
165 | { |
|
165 | { | |
166 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
166 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | QAbstractItemModel* QHBarModelMapper::model() const |
|
169 | QAbstractItemModel* QHBarModelMapper::model() const | |
170 | { |
|
170 | { | |
171 | return QBarModelMapper::model(); |
|
171 | return QBarModelMapper::model(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void QHBarModelMapper::setModel(QAbstractItemModel *model) |
|
174 | void QHBarModelMapper::setModel(QAbstractItemModel *model) | |
175 | { |
|
175 | { | |
176 | if (model != QBarModelMapper::model()) { |
|
176 | if (model != QBarModelMapper::model()) { | |
177 | QBarModelMapper::setModel(model); |
|
177 | QBarModelMapper::setModel(model); | |
178 | emit modelReplaced(); |
|
178 | emit modelReplaced(); | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | QAbstractBarSeries* QHBarModelMapper::series() const |
|
182 | QAbstractBarSeries* QHBarModelMapper::series() const | |
183 | { |
|
183 | { | |
184 | return QBarModelMapper::series(); |
|
184 | return QBarModelMapper::series(); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
187 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) | |
188 | { |
|
188 | { | |
189 | if (series != QBarModelMapper::series()) { |
|
189 | if (series != QBarModelMapper::series()) { | |
190 | QBarModelMapper::setSeries(series); |
|
190 | QBarModelMapper::setSeries(series); | |
191 | emit seriesReplaced(); |
|
191 | emit seriesReplaced(); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | int QHBarModelMapper::firstBarSetRow() const |
|
195 | int QHBarModelMapper::firstBarSetRow() const | |
196 | { |
|
196 | { | |
197 | return QBarModelMapper::firstBarSetSection(); |
|
197 | return QBarModelMapper::firstBarSetSection(); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
200 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
201 | { |
|
201 | { | |
202 | if (firstBarSetRow != firstBarSetSection()) { |
|
202 | if (firstBarSetRow != firstBarSetSection()) { | |
203 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
203 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |
204 | emit firstBarSetRowChanged(); |
|
204 | emit firstBarSetRowChanged(); | |
205 | } |
|
205 | } | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | int QHBarModelMapper::lastBarSetRow() const |
|
208 | int QHBarModelMapper::lastBarSetRow() const | |
209 | { |
|
209 | { | |
210 | return QBarModelMapper::lastBarSetSection(); |
|
210 | return QBarModelMapper::lastBarSetSection(); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
213 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
214 | { |
|
214 | { | |
215 | if (lastBarSetRow != lastBarSetSection()) { |
|
215 | if (lastBarSetRow != lastBarSetSection()) { | |
216 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
216 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |
217 | emit lastBarSetRowChanged(); |
|
217 | emit lastBarSetRowChanged(); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | int QHBarModelMapper::firstColumn() const |
|
221 | int QHBarModelMapper::firstColumn() const | |
222 | { |
|
222 | { | |
223 | return QBarModelMapper::first(); |
|
223 | return QBarModelMapper::first(); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
|
226 | void QHBarModelMapper::setFirstColumn(int firstColumn) | |
227 | { |
|
227 | { | |
228 | if (firstColumn != first()) { |
|
228 | if (firstColumn != first()) { | |
229 | QBarModelMapper::setFirst(firstColumn); |
|
229 | QBarModelMapper::setFirst(firstColumn); | |
230 | emit firstColumnChanged(); |
|
230 | emit firstColumnChanged(); | |
231 | } |
|
231 | } | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | int QHBarModelMapper::columnCount() const |
|
234 | int QHBarModelMapper::columnCount() const | |
235 | { |
|
235 | { | |
236 | return QBarModelMapper::count(); |
|
236 | return QBarModelMapper::count(); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | void QHBarModelMapper::setColumnCount(int columnCount) |
|
239 | void QHBarModelMapper::setColumnCount(int columnCount) | |
240 | { |
|
240 | { | |
241 | if (columnCount != count()) { |
|
241 | if (columnCount != count()) { | |
242 | QBarModelMapper::setCount(columnCount); |
|
242 | QBarModelMapper::setCount(columnCount); | |
243 | emit firstColumnChanged(); |
|
243 | emit firstColumnChanged(); | |
244 | } |
|
244 | } | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | #include "moc_qhbarmodelmapper.cpp" |
|
247 | #include "moc_qhbarmodelmapper.cpp" | |
248 |
|
248 | |||
249 | QTCOMMERCIALCHART_END_NAMESPACE |
|
249 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,117 +1,117 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #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 | #include "qcategoriesaxis.h" |
|
27 | #include "qcategoriesaxis.h" | |
28 | #include "qvaluesaxis.h" |
|
28 | #include "qvaluesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QPercentBarSeries |
|
33 | \class QPercentBarSeries | |
34 | \brief Series for creating percent bar chart |
|
34 | \brief Series for creating percent bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
38 | as stacks, where each bar is shown as percentage of all bars in that category. | |
39 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
39 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
40 |
|
40 | |||
41 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
41 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
42 | \image examples_percentbarchart.png |
|
42 | \image examples_percentbarchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QStackedBarSeries, QBarSeries |
|
44 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass PercentBarSeries QPercentBarSeries |
|
47 | \qmlclass PercentBarSeries QPercentBarSeries | |
48 | \inherits BarSeries |
|
48 | \inherits BarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple percent bar chart: |
|
50 | The following QML shows how to create a simple percent bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart9.png |
|
53 | \image demos_qmlchart9.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QPercentBarSeries. |
|
59 | Constructs empty QPercentBarSeries. | |
60 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
60 | QPercentBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
62 | QPercentBarSeries::QPercentBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Returns QChartSeries::SeriesTypePercentBar. |
|
68 | Returns QChartSeries::SeriesTypePercentBar. | |
69 | */ |
|
69 | */ | |
70 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
71 | { |
|
71 | { | |
72 | return QAbstractSeries::SeriesTypePercentBar; |
|
72 | return QAbstractSeries::SeriesTypePercentBar; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
76 |
|
76 | |||
77 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
77 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
78 | { |
|
78 | { | |
79 |
|
79 | |||
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
82 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
83 | { |
|
83 | { | |
84 | qreal minX(domain.minX()); |
|
84 | qreal minX(domain.minX()); | |
85 | qreal minY(domain.minY()); |
|
85 | qreal minY(domain.minY()); | |
86 | qreal maxX(domain.maxX()); |
|
86 | qreal maxX(domain.maxX()); | |
87 | qreal maxY(domain.maxY()); |
|
87 | qreal maxY(domain.maxY()); | |
88 | int tickXCount(domain.tickXCount()); |
|
88 | int tickXCount(domain.tickXCount()); | |
89 | int tickYCount(domain.tickYCount()); |
|
89 | int tickYCount(domain.tickYCount()); | |
90 |
|
90 | |||
91 | qreal x = categoryCount(); |
|
91 | qreal x = categoryCount(); | |
92 | minX = qMin(minX, -0.5); |
|
92 | minX = qMin(minX, -0.5); | |
93 | maxX = qMax(maxX, x - 0.5); |
|
93 | maxX = qMax(maxX, x - 0.5); | |
94 | minY = 0; |
|
94 | minY = 0; | |
95 | maxY = 100; |
|
95 | maxY = 100; | |
96 | tickXCount = x+1; |
|
96 | tickXCount = x+1; | |
97 |
|
97 | |||
98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
98 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 |
|
101 | |||
102 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
102 | Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
103 | { |
|
103 | { | |
104 | Q_Q(QPercentBarSeries); |
|
104 | Q_Q(QPercentBarSeries); | |
105 |
|
105 | |||
106 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
106 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
107 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
108 | presenter->animator()->addAnimation(bar); |
|
108 | presenter->animator()->addAnimation(bar); | |
109 | } |
|
109 | } | |
110 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
110 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
111 | return bar; |
|
111 | return bar; | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | #include "moc_qpercentbarseries.cpp" |
|
114 | #include "moc_qpercentbarseries.cpp" | |
115 |
|
115 | |||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | QTCOMMERCIALCHART_END_NAMESPACE | |
117 |
|
117 |
@@ -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 PERCENTBARSERIES_H |
|
21 | #ifndef PERCENTBARSERIES_H | |
22 | #define PERCENTBARSERIES_H |
|
22 | #define PERCENTBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qbarseries.h> |
|
25 | #include <qabstractbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QPercentBarSeriesPrivate; |
|
29 | class QPercentBarSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QAbstractBarSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QAbstractBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 | explicit QPercentBarSeries(QObject *parent = 0); |
|
35 | explicit QPercentBarSeries(QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
39 | Q_DECLARE_PRIVATE(QPercentBarSeries) |
|
39 | Q_DECLARE_PRIVATE(QPercentBarSeries) | |
40 | Q_DISABLE_COPY(QPercentBarSeries) |
|
40 | Q_DISABLE_COPY(QPercentBarSeries) | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
44 | |||
45 | #endif // PERCENTBARSERIES_H |
|
45 | #endif // PERCENTBARSERIES_H |
@@ -1,51 +1,51 | |||||
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 QPERCENTBARSERIES_P_H |
|
30 | #ifndef QPERCENTBARSERIES_P_H | |
31 | #define QPERCENTBARSERIES_P_H |
|
31 | #define QPERCENTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qabstractbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
39 | class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QPercentBarSeriesPrivate(QPercentBarSeries* q); |
|
42 | QPercentBarSeriesPrivate(QPercentBarSeries* q); | |
43 | void scaleDomain(Domain& domain); |
|
43 | void scaleDomain(Domain& domain); | |
44 | Chart* createGraphics(ChartPresenter* presenter); |
|
44 | Chart* createGraphics(ChartPresenter* presenter); | |
45 | private: |
|
45 | private: | |
46 | Q_DECLARE_PUBLIC(QPercentBarSeries) |
|
46 | Q_DECLARE_PUBLIC(QPercentBarSeries) | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | QTCOMMERCIALCHART_END_NAMESPACE | |
50 |
|
50 | |||
51 | #endif |
|
51 | #endif |
@@ -1,120 +1,120 | |||||
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 | #include "qcategoriesaxis.h" |
|
27 | #include "qcategoriesaxis.h" | |
28 | #include "qvaluesaxis.h" |
|
28 | #include "qvaluesaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QStackedBarSeries |
|
33 | \class QStackedBarSeries | |
34 | \brief Series for creating stacked bar chart |
|
34 | \brief Series for creating stacked bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as stacks, where bars in same category are stacked on top of each other. |
|
38 | as stacks, where bars in same category are stacked on top of each other. | |
39 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
39 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
40 |
|
40 | |||
41 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
41 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
42 | \image examples_stackedbarchart.png |
|
42 | \image examples_stackedbarchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \qmlclass StackedBarSeries QStackedBarSeries |
|
48 | \qmlclass StackedBarSeries QStackedBarSeries | |
49 | \inherits BarSeries |
|
49 | \inherits BarSeries | |
50 |
|
50 | |||
51 | The following QML shows how to create a simple stacked bar chart: |
|
51 | The following QML shows how to create a simple stacked bar chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
53 | \beginfloatleft |
|
53 | \beginfloatleft | |
54 | \image demos_qmlchart8.png |
|
54 | \image demos_qmlchart8.png | |
55 | \endfloat |
|
55 | \endfloat | |
56 | \clearfloat |
|
56 | \clearfloat | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | Constructs empty QStackedBarSeries. |
|
60 | Constructs empty QStackedBarSeries. | |
61 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
61 | QStackedBarSeries is QObject which is a child of a \a parent. | |
62 | */ |
|
62 | */ | |
63 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
63 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
64 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
64 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
65 | { |
|
65 | { | |
66 | } |
|
66 | } | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | Returns QChartSeries::SeriesTypeStackedBar. |
|
69 | Returns QChartSeries::SeriesTypeStackedBar. | |
70 | */ |
|
70 | */ | |
71 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
71 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
72 | { |
|
72 | { | |
73 | return QAbstractSeries::SeriesTypeStackedBar; |
|
73 | return QAbstractSeries::SeriesTypeStackedBar; | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
77 |
|
77 | |||
78 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
78 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
79 | { |
|
79 | { | |
80 |
|
80 | |||
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
83 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
84 | { |
|
84 | { | |
85 | qreal minX(domain.minX()); |
|
85 | qreal minX(domain.minX()); | |
86 | qreal minY(domain.minY()); |
|
86 | qreal minY(domain.minY()); | |
87 | qreal maxX(domain.maxX()); |
|
87 | qreal maxX(domain.maxX()); | |
88 | qreal maxY(domain.maxY()); |
|
88 | qreal maxY(domain.maxY()); | |
89 | int tickXCount(domain.tickXCount()); |
|
89 | int tickXCount(domain.tickXCount()); | |
90 | int tickYCount(domain.tickYCount()); |
|
90 | int tickYCount(domain.tickYCount()); | |
91 |
|
91 | |||
92 | qreal x = categoryCount(); |
|
92 | qreal x = categoryCount(); | |
93 | qreal y = maxCategorySum(); |
|
93 | qreal y = maxCategorySum(); | |
94 | minX = qMin(minX, -0.5); |
|
94 | minX = qMin(minX, -0.5); | |
95 | minY = qMin(minY, y); |
|
95 | minY = qMin(minY, y); | |
96 | maxX = qMax(maxX, x - 0.5); |
|
96 | maxX = qMax(maxX, x - 0.5); | |
97 | maxY = qMax(maxY, y); |
|
97 | maxY = qMax(maxY, y); | |
98 | tickXCount = x+1; |
|
98 | tickXCount = x+1; | |
99 |
|
99 | |||
100 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
100 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 |
|
103 | |||
104 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
104 | Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
105 | { |
|
105 | { | |
106 | Q_Q(QStackedBarSeries); |
|
106 | Q_Q(QStackedBarSeries); | |
107 |
|
107 | |||
108 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
108 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
109 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
110 | presenter->animator()->addAnimation(bar); |
|
110 | presenter->animator()->addAnimation(bar); | |
111 | } |
|
111 | } | |
112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
112 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
113 | return bar; |
|
113 | return bar; | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 |
|
116 | |||
117 | #include "moc_qstackedbarseries.cpp" |
|
117 | #include "moc_qstackedbarseries.cpp" | |
118 |
|
118 | |||
119 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE | |
120 |
|
120 |
@@ -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 STACKEDBARSERIES_H |
|
21 | #ifndef STACKEDBARSERIES_H | |
22 | #define STACKEDBARSERIES_H |
|
22 | #define STACKEDBARSERIES_H | |
23 |
|
23 | |||
24 | #include <QStringList> |
|
24 | #include <QStringList> | |
25 | #include <qbarseries.h> |
|
25 | #include <qabstractbarseries.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QStackedBarSeriesPrivate; |
|
29 | class QStackedBarSeriesPrivate; | |
30 |
|
30 | |||
31 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QAbstractBarSeries |
|
31 | class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QAbstractBarSeries | |
32 | { |
|
32 | { | |
33 | Q_OBJECT |
|
33 | Q_OBJECT | |
34 | public: |
|
34 | public: | |
35 | explicit QStackedBarSeries(QObject *parent = 0); |
|
35 | explicit QStackedBarSeries(QObject *parent = 0); | |
36 | QAbstractSeries::SeriesType type() const; |
|
36 | QAbstractSeries::SeriesType type() const; | |
37 |
|
37 | |||
38 | private: |
|
38 | private: | |
39 | Q_DECLARE_PRIVATE(QStackedBarSeries) |
|
39 | Q_DECLARE_PRIVATE(QStackedBarSeries) | |
40 | Q_DISABLE_COPY(QStackedBarSeries) |
|
40 | Q_DISABLE_COPY(QStackedBarSeries) | |
41 | }; |
|
41 | }; | |
42 |
|
42 | |||
43 | QTCOMMERCIALCHART_END_NAMESPACE |
|
43 | QTCOMMERCIALCHART_END_NAMESPACE | |
44 |
|
44 | |||
45 | #endif // STACKEDBARSERIES_H |
|
45 | #endif // STACKEDBARSERIES_H |
@@ -1,52 +1,52 | |||||
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 QSTACKEDBARSERIES_P_H |
|
30 | #ifndef QSTACKEDBARSERIES_P_H | |
31 | #define QSTACKEDBARSERIES_P_H |
|
31 | #define QSTACKEDBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qbarseries_p.h" |
|
33 | #include "qabstractbarseries_p.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 |
|
37 | |||
38 |
|
38 | |||
39 | class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate |
|
39 | class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate | |
40 | { |
|
40 | { | |
41 | public: |
|
41 | public: | |
42 | QStackedBarSeriesPrivate(QStackedBarSeries* q); |
|
42 | QStackedBarSeriesPrivate(QStackedBarSeries* q); | |
43 | Chart* createGraphics(ChartPresenter* presenter); |
|
43 | Chart* createGraphics(ChartPresenter* presenter); | |
44 | void scaleDomain(Domain& domain); |
|
44 | void scaleDomain(Domain& domain); | |
45 |
|
45 | |||
46 | private: |
|
46 | private: | |
47 | Q_DECLARE_PUBLIC(QStackedBarSeries) |
|
47 | Q_DECLARE_PUBLIC(QStackedBarSeries) | |
48 | }; |
|
48 | }; | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE | |
51 |
|
51 | |||
52 | #endif |
|
52 | #endif |
@@ -1,248 +1,248 | |||||
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 "qvbarmodelmapper.h" |
|
21 | #include "qvbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVBarModelMapper |
|
26 | \class QVBarModelMapper | |
27 | \brief Vertical model mapper for bar series |
|
27 | \brief Vertical model mapper for bar series | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object. |
|
31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. |
|
34 | NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass VBarModelMapper |
|
37 | \qmlclass VBarModelMapper | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |
42 | VBarModelMapper keeps the series and the model in sync. |
|
42 | VBarModelMapper keeps the series and the model in sync. | |
43 |
|
43 | |||
44 | The following QML example would create a bar series with three bar sets (assuming the |
|
44 | The following QML example would create a bar series with three bar sets (assuming the | |
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be |
|
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be | |
46 | defined by the horizontal header (of the column). |
|
46 | defined by the horizontal header (of the column). | |
47 | \code |
|
47 | \code | |
48 | GroupedBarSeries { |
|
48 | GroupedBarSeries { | |
49 | VBarModelMapper { |
|
49 | VBarModelMapper { | |
50 | model: myCustomModel // QAbstractItemModel derived implementation |
|
50 | model: myCustomModel // QAbstractItemModel derived implementation | |
51 | firstBarSetColumn: 1 |
|
51 | firstBarSetColumn: 1 | |
52 | lastBarSetColumn: 3 |
|
52 | lastBarSetColumn: 3 | |
53 | firstRow: 1 |
|
53 | firstRow: 1 | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QVBarModelMapper::series |
|
60 | \property QVBarModelMapper::series | |
61 | \brief Defines the QPieSeries object that is used by the mapper. |
|
61 | \brief Defines the QPieSeries object that is used by the mapper. | |
62 |
|
62 | |||
63 | All the data in the series is discarded when it is set to the mapper. |
|
63 | All the data in the series is discarded when it is set to the mapper. | |
64 | When new series is specified the old series is disconnected (it preserves its data) |
|
64 | When new series is specified the old series is disconnected (it preserves its data) | |
65 | */ |
|
65 | */ | |
66 | /*! |
|
66 | /*! | |
67 | \qmlproperty BarSeries VBarModelMapper::series |
|
67 | \qmlproperty BarSeries VBarModelMapper::series | |
68 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
68 | Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QVBarModelMapper::model |
|
73 | \property QVBarModelMapper::model | |
74 | \brief Defines the model that is used by the mapper. |
|
74 | \brief Defines the model that is used by the mapper. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty SomeModel VBarModelMapper::model |
|
77 | \qmlproperty SomeModel VBarModelMapper::model | |
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns |
|
79 | QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns | |
80 | and modifying the data of the cells. |
|
80 | and modifying the data of the cells. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QVBarModelMapper::firstBarSetColumn |
|
84 | \property QVBarModelMapper::firstBarSetColumn | |
85 | \brief Defines which column of the model is used as the data source for the first bar set |
|
85 | \brief Defines which column of the model is used as the data source for the first bar set | |
86 | Default value is: -1 (invalid mapping) |
|
86 | Default value is: -1 (invalid mapping) | |
87 | */ |
|
87 | */ | |
88 | /*! |
|
88 | /*! | |
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |
90 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
90 | Defines which column of the model is used as the data source for the first bar set. Default value | |
91 | is: -1 (invalid mapping). |
|
91 | is: -1 (invalid mapping). | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QVBarModelMapper::lastBarSetColumn |
|
95 | \property QVBarModelMapper::lastBarSetColumn | |
96 | \brief Defines which column of the model is used as the data source for the last bar set |
|
96 | \brief Defines which column of the model is used as the data source for the last bar set | |
97 | Default value is: -1 (invalid mapping) |
|
97 | Default value is: -1 (invalid mapping) | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |
101 | Defines which column of the model is used as the data source for the last bar set. Default |
|
101 | Defines which column of the model is used as the data source for the last bar set. Default | |
102 | value is: -1 (invalid mapping). |
|
102 | value is: -1 (invalid mapping). | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \property QVBarModelMapper::firstRow |
|
106 | \property QVBarModelMapper::firstRow | |
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |
108 | Minimal and default value is: 0 |
|
108 | Minimal and default value is: 0 | |
109 | */ |
|
109 | */ | |
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty int VBarModelMapper::firstRow |
|
111 | \qmlproperty int VBarModelMapper::firstRow | |
112 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
112 | Defines which row of the model contains the first values of the QBarSets in the series. | |
113 | The default value is 0. |
|
113 | The default value is 0. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \property QVBarModelMapper::rowCount |
|
117 | \property QVBarModelMapper::rowCount | |
118 | \brief Defines the number of rows of the model that are mapped as the data for QBarSeries |
|
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries | |
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty int VBarModelMapper::rowCount |
|
122 | \qmlproperty int VBarModelMapper::rowCount | |
123 | Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is |
|
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is | |
124 | -1 (count limited by the number of rows in the model) |
|
124 | -1 (count limited by the number of rows in the model) | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QVBarModelMapper::seriesReplaced() |
|
128 | \fn void QVBarModelMapper::seriesReplaced() | |
129 |
|
129 | |||
130 | Emitted when the series to which mapper is connected to has changed. |
|
130 | Emitted when the series to which mapper is connected to has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QVBarModelMapper::modelReplaced() |
|
134 | \fn void QVBarModelMapper::modelReplaced() | |
135 |
|
135 | |||
136 | Emitted when the model to which mapper is connected to has changed. |
|
136 | Emitted when the model to which mapper is connected to has changed. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
141 | Emitted when the firstBarSetColumn has changed. |
|
141 | Emitted when the firstBarSetColumn has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
146 | Emitted when the lastBarSetColumn has changed. |
|
146 | Emitted when the lastBarSetColumn has changed. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QVBarModelMapper::firstRowChanged() |
|
150 | \fn void QVBarModelMapper::firstRowChanged() | |
151 | Emitted when the firstRow has changed. |
|
151 | Emitted when the firstRow has changed. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QVBarModelMapper::rowCountChanged() |
|
155 | \fn void QVBarModelMapper::rowCountChanged() | |
156 | Emitted when the rowCount has changed. |
|
156 | Emitted when the rowCount has changed. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Constructs a mapper object which is a child of \a parent. |
|
160 | Constructs a mapper object which is a child of \a parent. | |
161 | */ |
|
161 | */ | |
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
163 | QBarModelMapper(parent) |
|
163 | QBarModelMapper(parent) | |
164 | { |
|
164 | { | |
165 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
165 | QBarModelMapper::setOrientation(Qt::Vertical); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QAbstractItemModel* QVBarModelMapper::model() const |
|
168 | QAbstractItemModel* QVBarModelMapper::model() const | |
169 | { |
|
169 | { | |
170 | return QBarModelMapper::model(); |
|
170 | return QBarModelMapper::model(); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) |
|
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) | |
174 | { |
|
174 | { | |
175 | if (model != QBarModelMapper::model()) { |
|
175 | if (model != QBarModelMapper::model()) { | |
176 | QBarModelMapper::setModel(model); |
|
176 | QBarModelMapper::setModel(model); | |
177 | emit modelReplaced(); |
|
177 | emit modelReplaced(); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | QAbstractBarSeries* QVBarModelMapper::series() const |
|
181 | QAbstractBarSeries* QVBarModelMapper::series() const | |
182 | { |
|
182 | { | |
183 | return QBarModelMapper::series(); |
|
183 | return QBarModelMapper::series(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) | |
187 | { |
|
187 | { | |
188 | if (series != QBarModelMapper::series()) { |
|
188 | if (series != QBarModelMapper::series()) { | |
189 | QBarModelMapper::setSeries(series); |
|
189 | QBarModelMapper::setSeries(series); | |
190 | emit seriesReplaced(); |
|
190 | emit seriesReplaced(); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | int QVBarModelMapper::firstBarSetColumn() const |
|
194 | int QVBarModelMapper::firstBarSetColumn() const | |
195 | { |
|
195 | { | |
196 | return QBarModelMapper::firstBarSetSection(); |
|
196 | return QBarModelMapper::firstBarSetSection(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
200 | { |
|
200 | { | |
201 | if (firstBarSetColumn != firstBarSetSection()) { |
|
201 | if (firstBarSetColumn != firstBarSetSection()) { | |
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
203 | emit firstBarSetColumnChanged(); |
|
203 | emit firstBarSetColumnChanged(); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | int QVBarModelMapper::lastBarSetColumn() const |
|
207 | int QVBarModelMapper::lastBarSetColumn() const | |
208 | { |
|
208 | { | |
209 | return QBarModelMapper::lastBarSetSection(); |
|
209 | return QBarModelMapper::lastBarSetSection(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
213 | { |
|
213 | { | |
214 | if (lastBarSetColumn != lastBarSetSection()) { |
|
214 | if (lastBarSetColumn != lastBarSetSection()) { | |
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
216 | emit lastBarSetColumnChanged(); |
|
216 | emit lastBarSetColumnChanged(); | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | int QVBarModelMapper::firstRow() const |
|
220 | int QVBarModelMapper::firstRow() const | |
221 | { |
|
221 | { | |
222 | return QBarModelMapper::first(); |
|
222 | return QBarModelMapper::first(); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
225 | void QVBarModelMapper::setFirstRow(int firstRow) | |
226 | { |
|
226 | { | |
227 | if (firstRow != first()) { |
|
227 | if (firstRow != first()) { | |
228 | QBarModelMapper::setFirst(firstRow); |
|
228 | QBarModelMapper::setFirst(firstRow); | |
229 | emit firstRowChanged(); |
|
229 | emit firstRowChanged(); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | int QVBarModelMapper::rowCount() const |
|
233 | int QVBarModelMapper::rowCount() const | |
234 | { |
|
234 | { | |
235 | return QBarModelMapper::count(); |
|
235 | return QBarModelMapper::count(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | void QVBarModelMapper::setRowCount(int rowCount) |
|
238 | void QVBarModelMapper::setRowCount(int rowCount) | |
239 | { |
|
239 | { | |
240 | if (rowCount != count()) { |
|
240 | if (rowCount != count()) { | |
241 | QBarModelMapper::setCount(rowCount); |
|
241 | QBarModelMapper::setCount(rowCount); | |
242 | emit firstRowChanged(); |
|
242 | emit firstRowChanged(); | |
243 | } |
|
243 | } | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | #include "moc_qvbarmodelmapper.cpp" |
|
246 | #include "moc_qvbarmodelmapper.cpp" | |
247 |
|
247 | |||
248 | QTCOMMERCIALCHART_END_NAMESPACE |
|
248 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,101 +1,101 | |||||
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 "qabstractbarseries_p.h" | |
25 | #include "qbarset.h" |
|
25 | #include "qbarset.h" | |
26 | #include "chartanimator_p.h" |
|
26 | #include "chartanimator_p.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
30 | StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : | |
31 | BarChartItem(series, presenter) |
|
31 | BarChartItem(series, presenter) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QVector<QRectF> StackedBarChartItem::calculateLayout() |
|
35 | QVector<QRectF> StackedBarChartItem::calculateLayout() | |
36 | { |
|
36 | { | |
37 | QVector<QRectF> layout; |
|
37 | QVector<QRectF> layout; | |
38 | // Use temporary qreals for accuracy |
|
38 | // Use temporary qreals for accuracy | |
39 | qreal categoryCount = m_series->d_func()->categoryCount(); |
|
39 | qreal categoryCount = m_series->d_func()->categoryCount(); | |
40 | qreal setCount = m_series->count(); |
|
40 | qreal setCount = m_series->count(); | |
41 | bool barsVisible = m_series->isVisible(); |
|
41 | bool barsVisible = m_series->isVisible(); | |
42 |
|
42 | |||
43 | // Domain: |
|
43 | // Domain: | |
44 | qreal width = geometry().width(); |
|
44 | qreal width = geometry().width(); | |
45 | qreal height = geometry().height(); |
|
45 | qreal height = geometry().height(); | |
46 | qreal rangeY = m_domainMaxY - m_domainMinY; |
|
46 | qreal rangeY = m_domainMaxY - m_domainMinY; | |
47 | qreal rangeX = m_domainMaxX - m_domainMinX; |
|
47 | qreal rangeX = m_domainMaxX - m_domainMinX; | |
48 | qreal scaleY = (height / rangeY); |
|
48 | qreal scaleY = (height / rangeY); | |
49 | qreal scaleX = (width / rangeX); |
|
49 | qreal scaleX = (width / rangeX); | |
50 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); |
|
50 | qreal barWidth = scaleX * m_series->d_func()->barWidth(); | |
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 + rangeY * m_domainMinY + geometry().topLeft().y(); |
|
54 | qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y(); | |
55 | for (int set=0; set < setCount; set++) { |
|
55 | for (int set=0; set < setCount; set++) { | |
56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
56 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
57 |
|
57 | |||
58 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; |
|
58 | qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2; | |
59 |
|
59 | |||
60 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; |
|
60 | qreal barHeight = barSet->m_values.at(category).y() * scaleY; | |
61 | Bar* bar = m_bars.at(itemIndex); |
|
61 | Bar* bar = m_bars.at(itemIndex); | |
62 | bar->setPen(barSet->m_pen); |
|
62 | bar->setPen(barSet->m_pen); | |
63 | bar->setBrush(barSet->m_brush); |
|
63 | bar->setBrush(barSet->m_brush); | |
64 | bar->setVisible(barsVisible); |
|
64 | bar->setVisible(barsVisible); | |
65 |
|
65 | |||
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(barSet->m_values.at(category).y())) { |
|
71 | if (!qFuzzyIsNull(barSet->m_values.at(category).y())) { | |
72 | label->setText(QString::number(barSet->m_values.at(category).y())); |
|
72 | label->setText(QString::number(barSet->m_values.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->m_labelFont); |
|
79 | label->setFont(barSet->m_labelFont); | |
80 | label->setBrush(barSet->m_labelBrush); |
|
80 | label->setBrush(barSet->m_labelBrush); | |
81 | itemIndex++; |
|
81 | itemIndex++; | |
82 | yPos -= barHeight; |
|
82 | yPos -= barHeight; | |
83 | } |
|
83 | } | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | return layout; |
|
86 | return layout; | |
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void StackedBarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
89 | void StackedBarChartItem::applyLayout(const QVector<QRectF> &layout) | |
90 | { |
|
90 | { | |
91 | if (animator()) { |
|
91 | if (animator()) { | |
92 | animator()->updateLayout(this, m_layout, layout); |
|
92 | animator()->updateLayout(this, m_layout, layout); | |
93 | } else { |
|
93 | } else { | |
94 | setLayout(layout); |
|
94 | setLayout(layout); | |
95 | update(); |
|
95 | update(); | |
96 | } |
|
96 | } | |
97 | } |
|
97 | } | |
98 |
|
98 | |||
99 | #include "moc_stackedbarchartitem_p.cpp" |
|
99 | #include "moc_stackedbarchartitem_p.cpp" | |
100 |
|
100 | |||
101 | QTCOMMERCIALCHART_END_NAMESPACE |
|
101 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,339 +1,339 | |||||
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 "qvaluesaxis.h" |
|
23 | #include "qvaluesaxis.h" | |
24 | #include "qvaluesaxis_p.h" |
|
24 | #include "qvaluesaxis_p.h" | |
25 | #include "qabstractseries_p.h" |
|
25 | #include "qabstractseries_p.h" | |
26 | #include "qbarseries.h" |
|
26 | #include "qabstractbarseries.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_domainIndex(0) |
|
34 | m_domainIndex(0) | |
35 | { |
|
35 | { | |
36 |
|
36 | |||
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | ChartDataSet::~ChartDataSet() |
|
39 | ChartDataSet::~ChartDataSet() | |
40 | { |
|
40 | { | |
41 | removeAllSeries(); |
|
41 | removeAllSeries(); | |
42 | } |
|
42 | } | |
43 |
|
43 | |||
44 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
44 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
45 | { |
|
45 | { | |
46 | Domain* domain = m_seriesDomainMap.value(series); |
|
46 | Domain* domain = m_seriesDomainMap.value(series); | |
47 |
|
47 | |||
48 | if(domain) { |
|
48 | if(domain) { | |
49 | qWarning() << "Can not add series. Series already on the chart"; |
|
49 | qWarning() << "Can not add series. Series already on the chart"; | |
50 | return; |
|
50 | return; | |
51 | } |
|
51 | } | |
52 |
|
52 | |||
53 | series->setParent(this); // take ownership |
|
53 | series->setParent(this); // take ownership | |
54 |
|
54 | |||
55 | domain = new Domain(series); |
|
55 | domain = new Domain(series); | |
56 |
|
56 | |||
57 | m_seriesDomainMap.insert(series,domain); |
|
57 | m_seriesDomainMap.insert(series,domain); | |
58 |
|
58 | |||
59 | series->d_ptr->scaleDomain(*domain); |
|
59 | series->d_ptr->scaleDomain(*domain); | |
60 |
|
60 | |||
61 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
61 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
62 |
|
62 | |||
63 | int key=0; |
|
63 | int key=0; | |
64 | while (i.hasNext()) { |
|
64 | while (i.hasNext()) { | |
65 | i.next(); |
|
65 | i.next(); | |
66 | if(i.key()!=key) { |
|
66 | if(i.key()!=key) { | |
67 | break; |
|
67 | break; | |
68 | } |
|
68 | } | |
69 | key++; |
|
69 | key++; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | m_indexSeriesMap.insert(key,series); |
|
72 | m_indexSeriesMap.insert(key,series); | |
73 |
|
73 | |||
74 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
74 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
75 | series->d_ptr->m_dataset = this; |
|
75 | series->d_ptr->m_dataset = this; | |
76 |
|
76 | |||
77 | emit seriesAdded(series,domain); |
|
77 | emit seriesAdded(series,domain); | |
78 |
|
78 | |||
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | void ChartDataSet::createDefaultAxes() |
|
81 | void ChartDataSet::createDefaultAxes() | |
82 | { |
|
82 | { | |
83 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
83 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
84 |
|
84 | |||
85 | while (i.hasNext()) { |
|
85 | while (i.hasNext()) { | |
86 | i.next(); |
|
86 | i.next(); | |
87 |
|
87 | |||
88 | if(!m_seriesAxisXMap.value(i.key())) |
|
88 | if(!m_seriesAxisXMap.value(i.key())) | |
89 | { |
|
89 | { | |
90 |
|
90 | |||
91 | QAbstractAxis* axisX = i.key()->d_ptr->createAxisX(this); |
|
91 | QAbstractAxis* axisX = i.key()->d_ptr->createAxisX(this); | |
92 |
|
92 | |||
93 | if(axisX) { |
|
93 | if(axisX) { | |
94 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
94 | QObject::connect(axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
95 | QObject::connect(i.value(),SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
95 | QObject::connect(i.value(),SIGNAL(rangeXChanged(qreal,qreal,int)),axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
96 | axisX->d_ptr->m_orientation=Qt::Horizontal; |
|
96 | axisX->d_ptr->m_orientation=Qt::Horizontal; | |
97 | emit axisAdded(axisX,i.value()); |
|
97 | emit axisAdded(axisX,i.value()); | |
98 | m_seriesAxisXMap.insert(i.key(),axisX); |
|
98 | m_seriesAxisXMap.insert(i.key(),axisX); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | if(!m_seriesAxisYMap.value(i.key())) |
|
103 | if(!m_seriesAxisYMap.value(i.key())) | |
104 | { |
|
104 | { | |
105 | QAbstractAxis* axisY = i.key()->d_ptr->createAxisY(this); |
|
105 | QAbstractAxis* axisY = i.key()->d_ptr->createAxisY(this); | |
106 |
|
106 | |||
107 | if(axisY) { |
|
107 | if(axisY) { | |
108 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
108 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
109 | QObject::connect(i.value(),SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
109 | QObject::connect(i.value(),SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
110 | axisY->d_ptr->m_orientation=Qt::Vertical; |
|
110 | axisY->d_ptr->m_orientation=Qt::Vertical; | |
111 | emit axisAdded(axisY,i.value()); |
|
111 | emit axisAdded(axisY,i.value()); | |
112 | m_seriesAxisYMap.insert(i.key(),axisY); |
|
112 | m_seriesAxisYMap.insert(i.key(),axisY); | |
113 | } |
|
113 | } | |
114 | } |
|
114 | } | |
115 | } |
|
115 | } | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 |
|
118 | |||
119 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
119 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
120 | { |
|
120 | { | |
121 | Domain* domain = m_seriesDomainMap.take(series); |
|
121 | Domain* domain = m_seriesDomainMap.take(series); | |
122 |
|
122 | |||
123 | if(!domain) { |
|
123 | if(!domain) { | |
124 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
124 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | emit seriesRemoved(series); |
|
127 | emit seriesRemoved(series); | |
128 |
|
128 | |||
129 | delete domain; |
|
129 | delete domain; | |
130 | domain = 0; |
|
130 | domain = 0; | |
131 |
|
131 | |||
132 | int key = seriesIndex(series); |
|
132 | int key = seriesIndex(series); | |
133 | Q_ASSERT(key!=-1); |
|
133 | Q_ASSERT(key!=-1); | |
134 |
|
134 | |||
135 | m_indexSeriesMap.remove(key); |
|
135 | m_indexSeriesMap.remove(key); | |
136 |
|
136 | |||
137 | series->setParent(0); |
|
137 | series->setParent(0); | |
138 | series->d_ptr->m_chart = 0; |
|
138 | series->d_ptr->m_chart = 0; | |
139 | series->d_ptr->m_dataset = 0; |
|
139 | series->d_ptr->m_dataset = 0; | |
140 |
|
140 | |||
141 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
141 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
142 |
|
142 | |||
143 | if(axisX) { |
|
143 | if(axisX) { | |
144 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
144 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
145 | int x = axesX.indexOf(axisX); |
|
145 | int x = axesX.indexOf(axisX); | |
146 |
|
146 | |||
147 | if(x==-1) { |
|
147 | if(x==-1) { | |
148 | emit axisRemoved(axisX); |
|
148 | emit axisRemoved(axisX); | |
149 | axisX->deleteLater(); |
|
149 | axisX->deleteLater(); | |
150 | } |
|
150 | } | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
153 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
154 |
|
154 | |||
155 | if(axisY) { |
|
155 | if(axisY) { | |
156 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
156 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
157 |
|
157 | |||
158 | int y = axesY.indexOf(axisY); |
|
158 | int y = axesY.indexOf(axisY); | |
159 |
|
159 | |||
160 | if(y==-1) { |
|
160 | if(y==-1) { | |
161 | emit axisRemoved(axisY); |
|
161 | emit axisRemoved(axisY); | |
162 | axisY->deleteLater(); |
|
162 | axisY->deleteLater(); | |
163 | } |
|
163 | } | |
164 | } |
|
164 | } | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void ChartDataSet::removeAllSeries() |
|
167 | void ChartDataSet::removeAllSeries() | |
168 | { |
|
168 | { | |
169 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
169 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
170 | foreach(QAbstractSeries *s , series) { |
|
170 | foreach(QAbstractSeries *s , series) { | |
171 | removeSeries(s); |
|
171 | removeSeries(s); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
174 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
175 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
175 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
176 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
176 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
177 |
|
177 | |||
178 | qDeleteAll(series); |
|
178 | qDeleteAll(series); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
181 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
182 | { |
|
182 | { | |
183 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
183 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
184 | while (i.hasNext()) { |
|
184 | while (i.hasNext()) { | |
185 | i.next(); |
|
185 | i.next(); | |
186 | i.value()->zoomIn(rect,size); |
|
186 | i.value()->zoomIn(rect,size); | |
187 | } |
|
187 | } | |
188 | } |
|
188 | } | |
189 |
|
189 | |||
190 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
190 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
191 | { |
|
191 | { | |
192 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
192 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
193 | while (i.hasNext()) { |
|
193 | while (i.hasNext()) { | |
194 | i.next(); |
|
194 | i.next(); | |
195 | i.value()->zoomOut(rect,size); |
|
195 | i.value()->zoomOut(rect,size); | |
196 | } |
|
196 | } | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
199 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
200 | { |
|
200 | { | |
201 | int count=0; |
|
201 | int count=0; | |
202 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
202 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
203 | while (i.hasNext()) { |
|
203 | while (i.hasNext()) { | |
204 | i.next(); |
|
204 | i.next(); | |
205 | if(i.key()->type()==type) count++; |
|
205 | if(i.key()->type()==type) count++; | |
206 | } |
|
206 | } | |
207 | return count; |
|
207 | return count; | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
210 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
211 | { |
|
211 | { | |
212 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
212 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
213 | while (i.hasNext()) { |
|
213 | while (i.hasNext()) { | |
214 | i.next(); |
|
214 | i.next(); | |
215 | if (i.value() == series) |
|
215 | if (i.value() == series) | |
216 | return i.key(); |
|
216 | return i.key(); | |
217 | } |
|
217 | } | |
218 | return -1; |
|
218 | return -1; | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
221 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
222 | { |
|
222 | { | |
223 | if(series == 0) return m_seriesAxisXMap.begin().value(); |
|
223 | if(series == 0) return m_seriesAxisXMap.begin().value(); | |
224 | return m_seriesAxisXMap.value(series); |
|
224 | return m_seriesAxisXMap.value(series); | |
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
227 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
228 | { |
|
228 | { | |
229 | if(series == 0) return m_seriesAxisYMap.begin().value(); |
|
229 | if(series == 0) return m_seriesAxisYMap.begin().value(); | |
230 | return m_seriesAxisYMap.value(series); |
|
230 | return m_seriesAxisYMap.value(series); | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) |
|
233 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) | |
234 | { |
|
234 | { | |
235 | Q_ASSERT(axis); |
|
235 | Q_ASSERT(axis); | |
236 | Domain* domain = m_seriesDomainMap.value(series); |
|
236 | Domain* domain = m_seriesDomainMap.value(series); | |
237 |
|
237 | |||
238 | if(!domain) { |
|
238 | if(!domain) { | |
239 | qWarning() << "Series not found on the chart."; |
|
239 | qWarning() << "Series not found on the chart."; | |
240 | return; |
|
240 | return; | |
241 | } |
|
241 | } | |
242 |
|
242 | |||
243 | if(axis->d_ptr->m_orientation==Qt::Vertical) { |
|
243 | if(axis->d_ptr->m_orientation==Qt::Vertical) { | |
244 | qWarning()<<"Axis already defined as axis Y"; |
|
244 | qWarning()<<"Axis already defined as axis Y"; | |
245 | return; |
|
245 | return; | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); |
|
248 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); | |
249 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
249 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
250 |
|
250 | |||
251 | if(oldAxis) { |
|
251 | if(oldAxis) { | |
252 |
|
252 | |||
253 | int x = axesX.indexOf(oldAxis); |
|
253 | int x = axesX.indexOf(oldAxis); | |
254 | if(x==-1) { |
|
254 | if(x==-1) { | |
255 | emit axisRemoved(oldAxis); |
|
255 | emit axisRemoved(oldAxis); | |
256 | oldAxis->deleteLater(); |
|
256 | oldAxis->deleteLater(); | |
257 | } |
|
257 | } | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
260 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
261 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
261 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
262 |
|
262 | |||
263 | int x = axesX.indexOf(axis); |
|
263 | int x = axesX.indexOf(axis); | |
264 | if(x==-1) { |
|
264 | if(x==-1) { | |
265 | axis->d_ptr->m_orientation=Qt::Horizontal; |
|
265 | axis->d_ptr->m_orientation=Qt::Horizontal; | |
266 | emit axisAdded(axis,domain); |
|
266 | emit axisAdded(axis,domain); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | m_seriesAxisXMap.insert(series,axis); |
|
269 | m_seriesAxisXMap.insert(series,axis); | |
270 |
|
270 | |||
271 | // Force range update |
|
271 | // Force range update | |
272 | axis->d_ptr->updateRange(); |
|
272 | axis->d_ptr->updateRange(); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) |
|
275 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) | |
276 | { |
|
276 | { | |
277 | Q_ASSERT(axis); |
|
277 | Q_ASSERT(axis); | |
278 | Domain* domain = m_seriesDomainMap.value(series); |
|
278 | Domain* domain = m_seriesDomainMap.value(series); | |
279 |
|
279 | |||
280 | if(!domain) { |
|
280 | if(!domain) { | |
281 | qWarning() << "Series not found on the chart."; |
|
281 | qWarning() << "Series not found on the chart."; | |
282 | return; |
|
282 | return; | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { |
|
285 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { | |
286 | qWarning()<<"Axis already defined as axis X"; |
|
286 | qWarning()<<"Axis already defined as axis X"; | |
287 | return; |
|
287 | return; | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); |
|
290 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); | |
291 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
291 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
292 |
|
292 | |||
293 | if(oldAxis) { |
|
293 | if(oldAxis) { | |
294 | int y = axesY.indexOf(oldAxis); |
|
294 | int y = axesY.indexOf(oldAxis); | |
295 | if(y==-1) { |
|
295 | if(y==-1) { | |
296 | emit axisRemoved(oldAxis); |
|
296 | emit axisRemoved(oldAxis); | |
297 | oldAxis->deleteLater(); |
|
297 | oldAxis->deleteLater(); | |
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
301 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
302 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
302 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
303 |
|
303 | |||
304 | int y = axesY.indexOf(axis); |
|
304 | int y = axesY.indexOf(axis); | |
305 | if(y==-1) { |
|
305 | if(y==-1) { | |
306 | axis->d_ptr->m_orientation=Qt::Vertical; |
|
306 | axis->d_ptr->m_orientation=Qt::Vertical; | |
307 | emit axisAdded(axis,domain); |
|
307 | emit axisAdded(axis,domain); | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | m_seriesAxisYMap.insert(series,axis); |
|
310 | m_seriesAxisYMap.insert(series,axis); | |
311 | } |
|
311 | } | |
312 |
|
312 | |||
313 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
313 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
314 | { |
|
314 | { | |
315 | return m_seriesDomainMap.value(series); |
|
315 | return m_seriesDomainMap.value(series); | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
318 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
319 | { |
|
319 | { | |
320 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
320 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
321 | while (i.hasNext()) { |
|
321 | while (i.hasNext()) { | |
322 | i.next(); |
|
322 | i.next(); | |
323 | i.value()->move(dx,dy,size); |
|
323 | i.value()->move(dx,dy,size); | |
324 | } |
|
324 | } | |
325 | } |
|
325 | } | |
326 |
|
326 | |||
327 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
327 | QList<QAbstractSeries*> ChartDataSet::series() const | |
328 | { |
|
328 | { | |
329 | return m_seriesAxisXMap.keys(); |
|
329 | return m_seriesAxisXMap.keys(); | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
332 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
333 | { |
|
333 | { | |
334 | emit seriesUpdated(series); |
|
334 | emit seriesUpdated(series); | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | #include "moc_chartdataset_p.cpp" |
|
337 | #include "moc_chartdataset_p.cpp" | |
338 |
|
338 | |||
339 | QTCOMMERCIALCHART_END_NAMESPACE |
|
339 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,389 +1,389 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qchartview.h" |
|
24 | #include "qchartview.h" | |
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
28 |
|
28 | |||
29 | //series |
|
29 | //series | |
30 | #include "qbarset.h" |
|
30 | #include "qbarset.h" | |
31 | #include "qbarseries.h" |
|
31 | #include "qabstractbarseries.h" | |
32 | #include "qstackedbarseries.h" |
|
32 | #include "qstackedbarseries.h" | |
33 | #include "qpercentbarseries.h" |
|
33 | #include "qpercentbarseries.h" | |
34 | #include "qlineseries.h" |
|
34 | #include "qlineseries.h" | |
35 | #include "qareaseries.h" |
|
35 | #include "qareaseries.h" | |
36 | #include "qscatterseries.h" |
|
36 | #include "qscatterseries.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "qpieslice_p.h" |
|
39 | #include "qpieslice_p.h" | |
40 | #include "qsplineseries.h" |
|
40 | #include "qsplineseries.h" | |
41 |
|
41 | |||
42 | //items |
|
42 | //items | |
43 | #include "chartaxis_p.h" |
|
43 | #include "chartaxis_p.h" | |
44 | #include "barchartitem_p.h" |
|
44 | #include "barchartitem_p.h" | |
45 | #include "stackedbarchartitem_p.h" |
|
45 | #include "stackedbarchartitem_p.h" | |
46 | #include "percentbarchartitem_p.h" |
|
46 | #include "percentbarchartitem_p.h" | |
47 | #include "linechartitem_p.h" |
|
47 | #include "linechartitem_p.h" | |
48 | #include "areachartitem_p.h" |
|
48 | #include "areachartitem_p.h" | |
49 | #include "scatterchartitem_p.h" |
|
49 | #include "scatterchartitem_p.h" | |
50 | #include "piechartitem_p.h" |
|
50 | #include "piechartitem_p.h" | |
51 | #include "splinechartitem_p.h" |
|
51 | #include "splinechartitem_p.h" | |
52 |
|
52 | |||
53 | //themes |
|
53 | //themes | |
54 | #include "chartthemesystem_p.h" |
|
54 | #include "chartthemesystem_p.h" | |
55 | #include "chartthemelight_p.h" |
|
55 | #include "chartthemelight_p.h" | |
56 | #include "chartthemebluecerulean_p.h" |
|
56 | #include "chartthemebluecerulean_p.h" | |
57 | #include "chartthemedark_p.h" |
|
57 | #include "chartthemedark_p.h" | |
58 | #include "chartthemebrownsand_p.h" |
|
58 | #include "chartthemebrownsand_p.h" | |
59 | #include "chartthemebluencs_p.h" |
|
59 | #include "chartthemebluencs_p.h" | |
60 | #include "chartthemehighcontrast_p.h" |
|
60 | #include "chartthemehighcontrast_p.h" | |
61 | #include "chartthemeblueicy_p.h" |
|
61 | #include "chartthemeblueicy_p.h" | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
64 |
|
64 | |||
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
66 | m_masterFont(QFont("arial", 14)), |
|
66 | m_masterFont(QFont("arial", 14)), | |
67 | m_labelFont(QFont("arial", 10)), |
|
67 | m_labelFont(QFont("arial", 10)), | |
68 | m_labelBrush(QColor(QRgb(0x000000))), |
|
68 | m_labelBrush(QColor(QRgb(0x000000))), | |
69 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
69 | m_axisLinePen(QPen(QRgb(0x000000))), | |
70 | m_backgroundShadesPen(Qt::NoPen), |
|
70 | m_backgroundShadesPen(Qt::NoPen), | |
71 | m_backgroundShadesBrush(Qt::NoBrush), |
|
71 | m_backgroundShadesBrush(Qt::NoBrush), | |
72 | m_backgroundShades(BackgroundShadesNone), |
|
72 | m_backgroundShades(BackgroundShadesNone), | |
73 | m_backgroundDropShadowEnabled(false), |
|
73 | m_backgroundDropShadowEnabled(false), | |
74 | m_gridLinePen(QPen(QRgb(0x000000))), |
|
74 | m_gridLinePen(QPen(QRgb(0x000000))), | |
75 | m_force(false) |
|
75 | m_force(false) | |
76 | { |
|
76 | { | |
77 | m_id = id; |
|
77 | m_id = id; | |
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
83 | { |
|
83 | { | |
84 | switch(theme) { |
|
84 | switch(theme) { | |
85 | case QChart::ChartThemeLight: |
|
85 | case QChart::ChartThemeLight: | |
86 | return new ChartThemeLight(); |
|
86 | return new ChartThemeLight(); | |
87 | case QChart::ChartThemeBlueCerulean: |
|
87 | case QChart::ChartThemeBlueCerulean: | |
88 | return new ChartThemeBlueCerulean(); |
|
88 | return new ChartThemeBlueCerulean(); | |
89 | case QChart::ChartThemeDark: |
|
89 | case QChart::ChartThemeDark: | |
90 | return new ChartThemeDark(); |
|
90 | return new ChartThemeDark(); | |
91 | case QChart::ChartThemeBrownSand: |
|
91 | case QChart::ChartThemeBrownSand: | |
92 | return new ChartThemeBrownSand(); |
|
92 | return new ChartThemeBrownSand(); | |
93 | case QChart::ChartThemeBlueNcs: |
|
93 | case QChart::ChartThemeBlueNcs: | |
94 | return new ChartThemeBlueNcs(); |
|
94 | return new ChartThemeBlueNcs(); | |
95 | case QChart::ChartThemeHighContrast: |
|
95 | case QChart::ChartThemeHighContrast: | |
96 | return new ChartThemeHighContrast(); |
|
96 | return new ChartThemeHighContrast(); | |
97 | case QChart::ChartThemeBlueIcy: |
|
97 | case QChart::ChartThemeBlueIcy: | |
98 | return new ChartThemeBlueIcy(); |
|
98 | return new ChartThemeBlueIcy(); | |
99 | default: |
|
99 | default: | |
100 | return new ChartThemeSystem(); |
|
100 | return new ChartThemeSystem(); | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ChartTheme::decorate(QChart *chart) |
|
104 | void ChartTheme::decorate(QChart *chart) | |
105 | { |
|
105 | { | |
106 | QBrush brush; |
|
106 | QBrush brush; | |
107 |
|
107 | |||
108 | if(brush == chart->backgroundBrush() || m_force) |
|
108 | if(brush == chart->backgroundBrush() || m_force) | |
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
110 | chart->setTitleFont(m_masterFont); |
|
110 | chart->setTitleFont(m_masterFont); | |
111 | chart->setTitleBrush(m_labelBrush); |
|
111 | chart->setTitleBrush(m_labelBrush); | |
112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); |
|
112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void ChartTheme::decorate(QLegend *legend) |
|
115 | void ChartTheme::decorate(QLegend *legend) | |
116 | { |
|
116 | { | |
117 | QPen pen; |
|
117 | QPen pen; | |
118 | QBrush brush; |
|
118 | QBrush brush; | |
119 | QFont font; |
|
119 | QFont font; | |
120 |
|
120 | |||
121 | if (pen == legend->pen() || m_force) |
|
121 | if (pen == legend->pen() || m_force) | |
122 | legend->setPen(m_axisLinePen); |
|
122 | legend->setPen(m_axisLinePen); | |
123 |
|
123 | |||
124 | if (brush == legend->brush() || m_force) |
|
124 | if (brush == legend->brush() || m_force) | |
125 | legend->setBrush(m_chartBackgroundGradient); |
|
125 | legend->setBrush(m_chartBackgroundGradient); | |
126 |
|
126 | |||
127 | if (font == legend->font() || m_force) |
|
127 | if (font == legend->font() || m_force) | |
128 | legend->setFont(m_labelFont); |
|
128 | legend->setFont(m_labelFont); | |
129 |
|
129 | |||
130 | if (brush == legend->labelBrush() || m_force) |
|
130 | if (brush == legend->labelBrush() || m_force) | |
131 | legend->setLabelBrush(m_labelBrush); |
|
131 | legend->setLabelBrush(m_labelBrush); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void ChartTheme::decorate(QAreaSeries *series, int index) |
|
134 | void ChartTheme::decorate(QAreaSeries *series, int index) | |
135 | { |
|
135 | { | |
136 | QPen pen; |
|
136 | QPen pen; | |
137 | QBrush brush; |
|
137 | QBrush brush; | |
138 |
|
138 | |||
139 | if (pen == series->pen() || m_force){ |
|
139 | if (pen == series->pen() || m_force){ | |
140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
141 | pen.setWidthF(2); |
|
141 | pen.setWidthF(2); | |
142 | series->setPen(pen); |
|
142 | series->setPen(pen); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | if (brush == series->brush() || m_force) { |
|
145 | if (brush == series->brush() || m_force) { | |
146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
147 | series->setBrush(brush); |
|
147 | series->setBrush(brush); | |
148 | } |
|
148 | } | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 |
|
151 | |||
152 | void ChartTheme::decorate(QLineSeries *series,int index) |
|
152 | void ChartTheme::decorate(QLineSeries *series,int index) | |
153 | { |
|
153 | { | |
154 | QPen pen; |
|
154 | QPen pen; | |
155 | if(pen == series->pen() || m_force ){ |
|
155 | if(pen == series->pen() || m_force ){ | |
156 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
156 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
157 | pen.setWidthF(2); |
|
157 | pen.setWidthF(2); | |
158 | series->setPen(pen); |
|
158 | series->setPen(pen); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartTheme::decorate(QAbstractBarSeries *series, int index) |
|
162 | void ChartTheme::decorate(QAbstractBarSeries *series, int index) | |
163 | { |
|
163 | { | |
164 | QBrush brush; |
|
164 | QBrush brush; | |
165 | QPen pen; |
|
165 | QPen pen; | |
166 | QList<QBarSet *> sets = series->barSets(); |
|
166 | QList<QBarSet *> sets = series->barSets(); | |
167 |
|
167 | |||
168 | qreal takeAtPos = 0.5; |
|
168 | qreal takeAtPos = 0.5; | |
169 | qreal step = 0.2; |
|
169 | qreal step = 0.2; | |
170 | if (sets.count() > 1 ) { |
|
170 | if (sets.count() > 1 ) { | |
171 | step = 1.0 / (qreal) sets.count(); |
|
171 | step = 1.0 / (qreal) sets.count(); | |
172 | if (sets.count() % m_seriesGradients.count()) |
|
172 | if (sets.count() % m_seriesGradients.count()) | |
173 | step *= m_seriesGradients.count(); |
|
173 | step *= m_seriesGradients.count(); | |
174 | else |
|
174 | else | |
175 | step *= (m_seriesGradients.count() - 1); |
|
175 | step *= (m_seriesGradients.count() - 1); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | for (int i(0); i < sets.count(); i++) { |
|
178 | for (int i(0); i < sets.count(); i++) { | |
179 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
179 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
180 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
180 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
181 | // There is no dedicated base color for each sets, generate more colors |
|
181 | // There is no dedicated base color for each sets, generate more colors | |
182 | takeAtPos += step; |
|
182 | takeAtPos += step; | |
183 | if (takeAtPos == 1.0) |
|
183 | if (takeAtPos == 1.0) | |
184 | takeAtPos += step; |
|
184 | takeAtPos += step; | |
185 | takeAtPos -= (int) takeAtPos; |
|
185 | takeAtPos -= (int) takeAtPos; | |
186 | } |
|
186 | } | |
187 | if (brush == sets.at(i)->brush() || m_force ) |
|
187 | if (brush == sets.at(i)->brush() || m_force ) | |
188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
189 |
|
189 | |||
190 | // Pick label color from the opposite end of the gradient. |
|
190 | // Pick label color from the opposite end of the gradient. | |
191 | // 0.3 as a boundary seems to work well. |
|
191 | // 0.3 as a boundary seems to work well. | |
192 | if (takeAtPos < 0.3) |
|
192 | if (takeAtPos < 0.3) | |
193 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
193 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
194 | else |
|
194 | else | |
195 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
195 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
196 |
|
196 | |||
197 | if (pen == sets.at(i)->pen() || m_force) { |
|
197 | if (pen == sets.at(i)->pen() || m_force) { | |
198 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
198 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
199 | sets.at(i)->setPen(c); |
|
199 | sets.at(i)->setPen(c); | |
200 | } |
|
200 | } | |
201 | } |
|
201 | } | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | void ChartTheme::decorate(QScatterSeries *series, int index) |
|
204 | void ChartTheme::decorate(QScatterSeries *series, int index) | |
205 | { |
|
205 | { | |
206 | QPen pen; |
|
206 | QPen pen; | |
207 | QBrush brush; |
|
207 | QBrush brush; | |
208 |
|
208 | |||
209 | if (pen == series->pen() || m_force) { |
|
209 | if (pen == series->pen() || m_force) { | |
210 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
210 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
211 | pen.setWidthF(2); |
|
211 | pen.setWidthF(2); | |
212 | series->setPen(pen); |
|
212 | series->setPen(pen); | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | if (brush == series->brush() || m_force) { |
|
215 | if (brush == series->brush() || m_force) { | |
216 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
216 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
217 | series->setBrush(brush); |
|
217 | series->setBrush(brush); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | void ChartTheme::decorate(QPieSeries *series, int index) |
|
221 | void ChartTheme::decorate(QPieSeries *series, int index) | |
222 | { |
|
222 | { | |
223 |
|
223 | |||
224 | for (int i(0); i < series->slices().count(); i++) { |
|
224 | for (int i(0); i < series->slices().count(); i++) { | |
225 |
|
225 | |||
226 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
226 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
227 |
|
227 | |||
228 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
228 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
229 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
229 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
230 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
230 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
231 |
|
231 | |||
232 | QPieSlice *s = series->slices().at(i); |
|
232 | QPieSlice *s = series->slices().at(i); | |
233 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
233 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
234 |
|
234 | |||
235 | if (d->m_data.m_slicePen.isThemed() || m_force) |
|
235 | if (d->m_data.m_slicePen.isThemed() || m_force) | |
236 | d->setPen(penColor, true); |
|
236 | d->setPen(penColor, true); | |
237 |
|
237 | |||
238 | if (d->m_data.m_sliceBrush.isThemed() || m_force) |
|
238 | if (d->m_data.m_sliceBrush.isThemed() || m_force) | |
239 | d->setBrush(brushColor, true); |
|
239 | d->setBrush(brushColor, true); | |
240 |
|
240 | |||
241 | if (d->m_data.m_labelBrush.isThemed() || m_force) |
|
241 | if (d->m_data.m_labelBrush.isThemed() || m_force) | |
242 | d->setLabelBrush(m_labelBrush.color(), true); |
|
242 | d->setLabelBrush(m_labelBrush.color(), true); | |
243 |
|
243 | |||
244 | if (d->m_data.m_labelFont.isThemed() || m_force) |
|
244 | if (d->m_data.m_labelFont.isThemed() || m_force) | |
245 | d->setLabelFont(m_labelFont, true); |
|
245 | d->setLabelFont(m_labelFont, true); | |
246 | } |
|
246 | } | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void ChartTheme::decorate(QSplineSeries *series, int index) |
|
249 | void ChartTheme::decorate(QSplineSeries *series, int index) | |
250 | { |
|
250 | { | |
251 | QPen pen; |
|
251 | QPen pen; | |
252 | if(pen == series->pen() || m_force){ |
|
252 | if(pen == series->pen() || m_force){ | |
253 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
253 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
254 | pen.setWidthF(2); |
|
254 | pen.setWidthF(2); | |
255 | series->setPen(pen); |
|
255 | series->setPen(pen); | |
256 | } |
|
256 | } | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | void ChartTheme::decorate(QAbstractAxis *axis,bool axisX) |
|
259 | void ChartTheme::decorate(QAbstractAxis *axis,bool axisX) | |
260 | { |
|
260 | { | |
261 | QPen pen; |
|
261 | QPen pen; | |
262 | QBrush brush; |
|
262 | QBrush brush; | |
263 | QFont font; |
|
263 | QFont font; | |
264 |
|
264 | |||
265 | if (axis->isAxisVisible()) { |
|
265 | if (axis->isAxisVisible()) { | |
266 |
|
266 | |||
267 | if(brush == axis->labelsBrush() || m_force){ |
|
267 | if(brush == axis->labelsBrush() || m_force){ | |
268 | axis->setLabelsBrush(m_labelBrush); |
|
268 | axis->setLabelsBrush(m_labelBrush); | |
269 | } |
|
269 | } | |
270 | if(pen == axis->labelsPen() || m_force){ |
|
270 | if(pen == axis->labelsPen() || m_force){ | |
271 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
271 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 |
|
274 | |||
275 | if (axis->shadesVisible() || m_force) { |
|
275 | if (axis->shadesVisible() || m_force) { | |
276 |
|
276 | |||
277 | if(brush == axis->shadesBrush() || m_force){ |
|
277 | if(brush == axis->shadesBrush() || m_force){ | |
278 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
278 | axis->setShadesBrush(m_backgroundShadesBrush); | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | if(pen == axis->shadesPen() || m_force){ |
|
281 | if(pen == axis->shadesPen() || m_force){ | |
282 | axis->setShadesPen(m_backgroundShadesPen); |
|
282 | axis->setShadesPen(m_backgroundShadesPen); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | if( m_force && (m_backgroundShades == BackgroundShadesBoth |
|
285 | if( m_force && (m_backgroundShades == BackgroundShadesBoth | |
286 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
286 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
287 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
287 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
288 | axis->setShadesVisible(true); |
|
288 | axis->setShadesVisible(true); | |
289 |
|
289 | |||
290 | } |
|
290 | } | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | if(pen == axis->axisPen() || m_force){ |
|
293 | if(pen == axis->axisPen() || m_force){ | |
294 | axis->setAxisPen(m_axisLinePen); |
|
294 | axis->setAxisPen(m_axisLinePen); | |
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | if(pen == axis->gridLinePen() || m_force){ |
|
297 | if(pen == axis->gridLinePen() || m_force){ | |
298 | axis->setGridLinePen(m_gridLinePen); |
|
298 | axis->setGridLinePen(m_gridLinePen); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | if(font == axis->labelsFont() || m_force){ |
|
301 | if(font == axis->labelsFont() || m_force){ | |
302 | axis->setLabelsFont(m_labelFont); |
|
302 | axis->setLabelsFont(m_labelFont); | |
303 | } |
|
303 | } | |
304 | } |
|
304 | } | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | void ChartTheme::generateSeriesGradients() |
|
307 | void ChartTheme::generateSeriesGradients() | |
308 | { |
|
308 | { | |
309 | // Generate gradients in HSV color space |
|
309 | // Generate gradients in HSV color space | |
310 | foreach (const QColor& color, m_seriesColors) { |
|
310 | foreach (const QColor& color, m_seriesColors) { | |
311 | QLinearGradient g; |
|
311 | QLinearGradient g; | |
312 | qreal h = color.hsvHueF(); |
|
312 | qreal h = color.hsvHueF(); | |
313 | qreal s = color.hsvSaturationF(); |
|
313 | qreal s = color.hsvSaturationF(); | |
314 |
|
314 | |||
315 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
315 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
316 | // most themes. The rest of the gradients we can define manually in theme specific |
|
316 | // most themes. The rest of the gradients we can define manually in theme specific | |
317 | // implementation. |
|
317 | // implementation. | |
318 | QColor start = color; |
|
318 | QColor start = color; | |
319 | start.setHsvF(h, 0.0, 1.0); |
|
319 | start.setHsvF(h, 0.0, 1.0); | |
320 | g.setColorAt(0.0, start); |
|
320 | g.setColorAt(0.0, start); | |
321 |
|
321 | |||
322 | g.setColorAt(0.5, color); |
|
322 | g.setColorAt(0.5, color); | |
323 |
|
323 | |||
324 | QColor end = color; |
|
324 | QColor end = color; | |
325 | end.setHsvF(h, s, 0.25); |
|
325 | end.setHsvF(h, s, 0.25); | |
326 | g.setColorAt(1.0, end); |
|
326 | g.setColorAt(1.0, end); | |
327 |
|
327 | |||
328 | m_seriesGradients << g; |
|
328 | m_seriesGradients << g; | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 |
|
332 | |||
333 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
333 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
334 | { |
|
334 | { | |
335 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
335 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |
336 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
336 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
337 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
337 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
338 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
338 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
339 | QColor c; |
|
339 | QColor c; | |
340 | c.setRgbF(r, g, b); |
|
340 | c.setRgbF(r, g, b); | |
341 | return c; |
|
341 | return c; | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
344 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
345 | { |
|
345 | { | |
346 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
346 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |
347 |
|
347 | |||
348 | QGradientStops stops = gradient.stops(); |
|
348 | QGradientStops stops = gradient.stops(); | |
349 | int count = stops.count(); |
|
349 | int count = stops.count(); | |
350 |
|
350 | |||
351 | // find previous stop relative to position |
|
351 | // find previous stop relative to position | |
352 | QGradientStop prev = stops.first(); |
|
352 | QGradientStop prev = stops.first(); | |
353 | for (int i = 0; i < count; i++) { |
|
353 | for (int i = 0; i < count; i++) { | |
354 | QGradientStop stop = stops.at(i); |
|
354 | QGradientStop stop = stops.at(i); | |
355 | if (pos > stop.first) |
|
355 | if (pos > stop.first) | |
356 | prev = stop; |
|
356 | prev = stop; | |
357 |
|
357 | |||
358 | // given position is actually a stop position? |
|
358 | // given position is actually a stop position? | |
359 | if (pos == stop.first) { |
|
359 | if (pos == stop.first) { | |
360 | //qDebug() << "stop color" << pos; |
|
360 | //qDebug() << "stop color" << pos; | |
361 | return stop.second; |
|
361 | return stop.second; | |
362 | } |
|
362 | } | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | // find next stop relative to position |
|
365 | // find next stop relative to position | |
366 | QGradientStop next = stops.last(); |
|
366 | QGradientStop next = stops.last(); | |
367 | for (int i = count - 1; i >= 0; i--) { |
|
367 | for (int i = count - 1; i >= 0; i--) { | |
368 | QGradientStop stop = stops.at(i); |
|
368 | QGradientStop stop = stops.at(i); | |
369 | if (pos < stop.first) |
|
369 | if (pos < stop.first) | |
370 | next = stop; |
|
370 | next = stop; | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
373 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
374 |
|
374 | |||
375 | qreal range = next.first - prev.first; |
|
375 | qreal range = next.first - prev.first; | |
376 | qreal posDelta = pos - prev.first; |
|
376 | qreal posDelta = pos - prev.first; | |
377 | qreal relativePos = posDelta / range; |
|
377 | qreal relativePos = posDelta / range; | |
378 |
|
378 | |||
379 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
379 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
380 |
|
380 | |||
381 | return colorAt(prev.second, next.second, relativePos); |
|
381 | return colorAt(prev.second, next.second, relativePos); | |
382 | } |
|
382 | } | |
383 |
|
383 | |||
384 | void ChartTheme::setForced(bool enabled) |
|
384 | void ChartTheme::setForced(bool enabled) | |
385 | { |
|
385 | { | |
386 | m_force=enabled; |
|
386 | m_force=enabled; | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | QTCOMMERCIALCHART_END_NAMESPACE |
|
389 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,237 +1,237 | |||||
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 "legendmarker_p.h" |
|
21 | #include "legendmarker_p.h" | |
22 | #include "qxyseries.h" |
|
22 | #include "qxyseries.h" | |
23 | #include "qxyseries_p.h" |
|
23 | #include "qxyseries_p.h" | |
24 | #include "qlegend.h" |
|
24 | #include "qlegend.h" | |
25 | #include "qbarseries.h" |
|
25 | #include "qabstractbarseries.h" | |
26 | #include "qpieseries.h" |
|
26 | #include "qpieseries.h" | |
27 | #include "qpieslice.h" |
|
27 | #include "qpieslice.h" | |
28 | #include "qbarset.h" |
|
28 | #include "qbarset.h" | |
29 | #include "qbarset_p.h" |
|
29 | #include "qbarset_p.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qareaseries_p.h" |
|
31 | #include "qareaseries_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 | #include <QGraphicsSceneEvent> |
|
33 | #include <QGraphicsSceneEvent> | |
34 | #include <QGraphicsSimpleTextItem> |
|
34 | #include <QGraphicsSimpleTextItem> | |
35 | #include <QDebug> |
|
35 | #include <QDebug> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : |
|
39 | LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) : | |
40 | QGraphicsObject(legend), |
|
40 | QGraphicsObject(legend), | |
41 | m_series(series), |
|
41 | m_series(series), | |
42 | m_markerRect(0,0,10.0,10.0), |
|
42 | m_markerRect(0,0,10.0,10.0), | |
43 | m_boundingRect(0,0,0,0), |
|
43 | m_boundingRect(0,0,0,0), | |
44 | m_legend(legend), |
|
44 | m_legend(legend), | |
45 | m_textItem(new QGraphicsSimpleTextItem(this)), |
|
45 | m_textItem(new QGraphicsSimpleTextItem(this)), | |
46 | m_rectItem(new QGraphicsRectItem(this)), |
|
46 | m_rectItem(new QGraphicsRectItem(this)), | |
47 | m_margin(2), |
|
47 | m_margin(2), | |
48 | m_space(4) |
|
48 | m_space(4) | |
49 | { |
|
49 | { | |
50 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
|
50 | //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); | |
51 | m_rectItem->setRect(m_markerRect); |
|
51 | m_rectItem->setRect(m_markerRect); | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | void LegendMarker::setPen(const QPen &pen) |
|
54 | void LegendMarker::setPen(const QPen &pen) | |
55 | { |
|
55 | { | |
56 | m_rectItem->setPen(pen); |
|
56 | m_rectItem->setPen(pen); | |
57 | m_textItem->setPen(pen); |
|
57 | m_textItem->setPen(pen); | |
58 | } |
|
58 | } | |
59 |
|
59 | |||
60 | QPen LegendMarker::pen() const |
|
60 | QPen LegendMarker::pen() const | |
61 | { |
|
61 | { | |
62 | return m_rectItem->pen(); |
|
62 | return m_rectItem->pen(); | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | void LegendMarker::setBrush(const QBrush &brush) |
|
65 | void LegendMarker::setBrush(const QBrush &brush) | |
66 | { |
|
66 | { | |
67 | m_rectItem->setBrush(brush); |
|
67 | m_rectItem->setBrush(brush); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | QBrush LegendMarker::brush() const |
|
70 | QBrush LegendMarker::brush() const | |
71 | { |
|
71 | { | |
72 | return m_rectItem->brush(); |
|
72 | return m_rectItem->brush(); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | void LegendMarker::setFont(const QFont &font) |
|
75 | void LegendMarker::setFont(const QFont &font) | |
76 | { |
|
76 | { | |
77 | m_textItem->setFont(font); |
|
77 | m_textItem->setFont(font); | |
78 | QFontMetrics fn(font); |
|
78 | QFontMetrics fn(font); | |
79 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); |
|
79 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); | |
80 | updateGeometry(); |
|
80 | updateGeometry(); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | QFont LegendMarker::font() const |
|
83 | QFont LegendMarker::font() const | |
84 | { |
|
84 | { | |
85 | return m_textItem->font(); |
|
85 | return m_textItem->font(); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | void LegendMarker::setLabel(const QString label) |
|
88 | void LegendMarker::setLabel(const QString label) | |
89 | { |
|
89 | { | |
90 | m_textItem->setText(label); |
|
90 | m_textItem->setText(label); | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | QString LegendMarker::label() const |
|
93 | QString LegendMarker::label() const | |
94 | { |
|
94 | { | |
95 | return m_textItem->text(); |
|
95 | return m_textItem->text(); | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | QRectF LegendMarker::boundingRect() const |
|
98 | QRectF LegendMarker::boundingRect() const | |
99 | { |
|
99 | { | |
100 | return m_boundingRect; |
|
100 | return m_boundingRect; | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 | void LegendMarker::setLabelBrush(const QBrush &brush) |
|
103 | void LegendMarker::setLabelBrush(const QBrush &brush) | |
104 | { |
|
104 | { | |
105 | m_textItem->setBrush(brush); |
|
105 | m_textItem->setBrush(brush); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 | QBrush LegendMarker::labelBrush() const |
|
108 | QBrush LegendMarker::labelBrush() const | |
109 | { |
|
109 | { | |
110 | return m_textItem->brush(); |
|
110 | return m_textItem->brush(); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 |
|
113 | |||
114 | void LegendMarker::setGeometry(const QRectF& rect) |
|
114 | void LegendMarker::setGeometry(const QRectF& rect) | |
115 | { |
|
115 | { | |
116 | const QRectF& textRect = m_textItem->boundingRect(); |
|
116 | const QRectF& textRect = m_textItem->boundingRect(); | |
117 |
|
117 | |||
118 | m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2); |
|
118 | m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2); | |
119 | m_rectItem->setRect(m_markerRect); |
|
119 | m_rectItem->setRect(m_markerRect); | |
120 | m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2); |
|
120 | m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2); | |
121 |
|
121 | |||
122 | prepareGeometryChange(); |
|
122 | prepareGeometryChange(); | |
123 | m_boundingRect = rect; |
|
123 | m_boundingRect = rect; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
126 | void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
127 | { |
|
127 | { | |
128 | Q_UNUSED(option) |
|
128 | Q_UNUSED(option) | |
129 | Q_UNUSED(widget) |
|
129 | Q_UNUSED(widget) | |
130 | Q_UNUSED(painter) |
|
130 | Q_UNUSED(painter) | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 |
|
133 | |||
134 | QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
134 | QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |
135 | { |
|
135 | { | |
136 | Q_UNUSED(constraint) |
|
136 | Q_UNUSED(constraint) | |
137 |
|
137 | |||
138 | QFontMetrics fn(m_textItem->font()); |
|
138 | QFontMetrics fn(m_textItem->font()); | |
139 | QSizeF sh; |
|
139 | QSizeF sh; | |
140 |
|
140 | |||
141 | switch (which) { |
|
141 | switch (which) { | |
142 | case Qt::MinimumSize: |
|
142 | case Qt::MinimumSize: | |
143 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); |
|
143 | sh = QSizeF(fn.boundingRect("...").width(),fn.height()); | |
144 | break; |
|
144 | break; | |
145 | case Qt::PreferredSize: |
|
145 | case Qt::PreferredSize: | |
146 | sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); |
|
146 | sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); | |
147 | break; |
|
147 | break; | |
148 | default: |
|
148 | default: | |
149 | break; |
|
149 | break; | |
150 | } |
|
150 | } | |
151 |
|
151 | |||
152 | return sh; |
|
152 | return sh; | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
155 | void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
156 | { |
|
156 | { | |
157 | QGraphicsObject::mousePressEvent(event); |
|
157 | QGraphicsObject::mousePressEvent(event); | |
158 | qDebug()<<"Not implemented"; //TODO: selected signal removed for now |
|
158 | qDebug()<<"Not implemented"; //TODO: selected signal removed for now | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
161 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
162 |
|
162 | |||
163 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), |
|
163 | AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend), | |
164 | m_series(series) |
|
164 | m_series(series) | |
165 | { |
|
165 | { | |
166 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
166 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
167 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
167 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
168 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
168 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
169 | updated(); |
|
169 | updated(); | |
170 | } |
|
170 | } | |
171 |
|
171 | |||
172 | void AreaLegendMarker::updated() |
|
172 | void AreaLegendMarker::updated() | |
173 | { |
|
173 | { | |
174 | setBrush(m_series->brush()); |
|
174 | setBrush(m_series->brush()); | |
175 | setLabel(m_series->name()); |
|
175 | setLabel(m_series->name()); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
178 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
179 |
|
179 | |||
180 | BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), |
|
180 | BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend), | |
181 | m_barset(barset) |
|
181 | m_barset(barset) | |
182 | { |
|
182 | { | |
183 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); |
|
183 | //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected())); | |
184 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); |
|
184 | QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated())); | |
185 | updated(); |
|
185 | updated(); | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | void BarLegendMarker::updated() |
|
188 | void BarLegendMarker::updated() | |
189 | { |
|
189 | { | |
190 | setBrush(m_barset->brush()); |
|
190 | setBrush(m_barset->brush()); | |
191 | setLabel(m_barset->label()); |
|
191 | setLabel(m_barset->label()); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
195 |
|
195 | |||
196 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), |
|
196 | PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend), | |
197 | m_pieslice(pieslice) |
|
197 | m_pieslice(pieslice) | |
198 | { |
|
198 | { | |
199 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); |
|
199 | QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated())); | |
200 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); |
|
200 | QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated())); | |
201 | updated(); |
|
201 | updated(); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | void PieLegendMarker::updated() |
|
204 | void PieLegendMarker::updated() | |
205 | { |
|
205 | { | |
206 | setBrush(m_pieslice->brush()); |
|
206 | setBrush(m_pieslice->brush()); | |
207 | setLabel(m_pieslice->label()); |
|
207 | setLabel(m_pieslice->label()); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
210 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
211 |
|
211 | |||
212 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), |
|
212 | XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend), | |
213 | m_series(series) |
|
213 | m_series(series) | |
214 | { |
|
214 | { | |
215 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); |
|
215 | //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected())); | |
216 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); |
|
216 | QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated())); | |
217 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); |
|
217 | QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated())); | |
218 | updated(); |
|
218 | updated(); | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | void XYLegendMarker::updated() |
|
221 | void XYLegendMarker::updated() | |
222 | { |
|
222 | { | |
223 | setLabel(m_series->name()); |
|
223 | setLabel(m_series->name()); | |
224 |
|
224 | |||
225 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) |
|
225 | if(m_series->type()== QAbstractSeries::SeriesTypeScatter) | |
226 | { |
|
226 | { | |
227 | setBrush(m_series->brush()); |
|
227 | setBrush(m_series->brush()); | |
228 |
|
228 | |||
229 | } |
|
229 | } | |
230 | else { |
|
230 | else { | |
231 | setBrush(QBrush(m_series->pen().color())); |
|
231 | setBrush(QBrush(m_series->pen().color())); | |
232 | } |
|
232 | } | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | #include "moc_legendmarker_p.cpp" |
|
235 | #include "moc_legendmarker_p.cpp" | |
236 |
|
236 | |||
237 | QTCOMMERCIALCHART_END_NAMESPACE |
|
237 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,533 +1,533 | |||||
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 "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "legendlayout_p.h" |
|
26 | #include "legendlayout_p.h" | |
27 | #include "legendmarker_p.h" |
|
27 | #include "legendmarker_p.h" | |
28 | #include "qxyseries.h" |
|
28 | #include "qxyseries.h" | |
29 | #include "qlineseries.h" |
|
29 | #include "qlineseries.h" | |
30 | #include "qareaseries.h" |
|
30 | #include "qareaseries.h" | |
31 | #include "qscatterseries.h" |
|
31 | #include "qscatterseries.h" | |
32 | #include "qsplineseries.h" |
|
32 | #include "qsplineseries.h" | |
33 | #include "qbarseries.h" |
|
33 | #include "qabstractbarseries.h" | |
34 | #include "qstackedbarseries.h" |
|
34 | #include "qstackedbarseries.h" | |
35 | #include "qpercentbarseries.h" |
|
35 | #include "qpercentbarseries.h" | |
36 | #include "qbarset.h" |
|
36 | #include "qbarset.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieseries_p.h" |
|
38 | #include "qpieseries_p.h" | |
39 | #include "qpieslice.h" |
|
39 | #include "qpieslice.h" | |
40 | #include "chartpresenter_p.h" |
|
40 | #include "chartpresenter_p.h" | |
41 | #include <QPainter> |
|
41 | #include <QPainter> | |
42 | #include <QPen> |
|
42 | #include <QPen> | |
43 | #include <QTimer> |
|
43 | #include <QTimer> | |
44 | #include <QGraphicsLayout> |
|
44 | #include <QGraphicsLayout> | |
45 | #include <QGraphicsSceneEvent> |
|
45 | #include <QGraphicsSceneEvent> | |
46 |
|
46 | |||
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
47 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \class QLegend |
|
50 | \class QLegend | |
51 | \brief Legend object |
|
51 | \brief Legend object | |
52 | \mainclass |
|
52 | \mainclass | |
53 |
|
53 | |||
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when |
|
54 | QLegend is a graphical object, whics displays legend of the chart. Legend state is updated by QChart, when | |
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
55 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
56 | handle the drawing manually. |
|
56 | handle the drawing manually. | |
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
57 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
58 |
|
58 | |||
59 | \image examples_percentbarchart_legend.png |
|
59 | \image examples_percentbarchart_legend.png | |
60 |
|
60 | |||
61 | \sa QChart |
|
61 | \sa QChart | |
62 | */ |
|
62 | */ | |
63 | /*! |
|
63 | /*! | |
64 | \qmlclass Legend QLegend |
|
64 | \qmlclass Legend QLegend | |
65 | \brief Legend is part of QtCommercial Chart QML API. |
|
65 | \brief Legend is part of QtCommercial Chart QML API. | |
66 |
|
66 | |||
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
67 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
68 | series have been changed. Legend is used via ChartView class. For example: |
|
68 | series have been changed. Legend is used via ChartView class. For example: | |
69 | \code |
|
69 | \code | |
70 | ChartView { |
|
70 | ChartView { | |
71 | legend.visible: true |
|
71 | legend.visible: true | |
72 | legend.alignment: Qt.AlignBottom |
|
72 | legend.alignment: Qt.AlignBottom | |
73 | // Add a few series... |
|
73 | // Add a few series... | |
74 | } |
|
74 | } | |
75 | \endcode |
|
75 | \endcode | |
76 |
|
76 | |||
77 | \image examples_percentbarchart_legend.png |
|
77 | \image examples_percentbarchart_legend.png | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QLegend::alignment |
|
81 | \property QLegend::alignment | |
82 | \brief The alignment of the legend. |
|
82 | \brief The alignment of the legend. | |
83 |
|
83 | |||
84 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
84 | Legend paints on the defined position in the chart. The following alignments are supported: | |
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
85 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty Qt.Alignment Legend::alignment |
|
88 | \qmlproperty Qt.Alignment Legend::alignment | |
89 | \brief The alignment of the legend. |
|
89 | \brief The alignment of the legend. | |
90 |
|
90 | |||
91 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
91 | Legend paints on the defined position in the chart. The following alignments are supported: | |
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
92 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QLegend::backgroundVisible |
|
96 | \property QLegend::backgroundVisible | |
97 | Whether the legend background is visible or not. |
|
97 | Whether the legend background is visible or not. | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty bool Legend::backgroundVisible |
|
100 | \qmlproperty bool Legend::backgroundVisible | |
101 | Whether the legend background is visible or not. |
|
101 | Whether the legend background is visible or not. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QLegend::color |
|
105 | \property QLegend::color | |
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
106 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
107 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty color Legend::color |
|
110 | \qmlproperty color Legend::color | |
111 | The color of the legend, i.e. the background (brush) color. |
|
111 | The color of the legend, i.e. the background (brush) color. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \property QLegend::borderColor |
|
115 | \property QLegend::borderColor | |
116 | The border color of the legend, i.e. the line color. |
|
116 | The border color of the legend, i.e. the line color. | |
117 | */ |
|
117 | */ | |
118 | /*! |
|
118 | /*! | |
119 | \qmlproperty color Legend::borderColor |
|
119 | \qmlproperty color Legend::borderColor | |
120 | The border color of the legend, i.e. the line color. |
|
120 | The border color of the legend, i.e. the line color. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \property QLegend::font |
|
124 | \property QLegend::font | |
125 | The font of markers used by legend |
|
125 | The font of markers used by legend | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlproperty color Legend::font |
|
128 | \qmlproperty color Legend::font | |
129 | The font of markers used by legend |
|
129 | The font of markers used by legend | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \property QLegend::labelColor |
|
133 | \property QLegend::labelColor | |
134 | The color of brush used to draw labels. |
|
134 | The color of brush used to draw labels. | |
135 | */ |
|
135 | */ | |
136 | /*! |
|
136 | /*! | |
137 | \qmlproperty color QLegend::labelColor |
|
137 | \qmlproperty color QLegend::labelColor | |
138 | The color of brush used to draw labels. |
|
138 | The color of brush used to draw labels. | |
139 | */ |
|
139 | */ | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
142 | \fn void QLegend::backgroundVisibleChanged(bool) | |
143 | The visibility of the legend background changed to \a visible. |
|
143 | The visibility of the legend background changed to \a visible. | |
144 | */ |
|
144 | */ | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | \fn void QLegend::colorChanged(QColor) |
|
147 | \fn void QLegend::colorChanged(QColor) | |
148 | The color of the legend background changed to \a color. |
|
148 | The color of the legend background changed to \a color. | |
149 | */ |
|
149 | */ | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | \fn void QLegend::borderColorChanged(QColor) |
|
152 | \fn void QLegend::borderColorChanged(QColor) | |
153 | The border color of the legend background changed to \a color. |
|
153 | The border color of the legend background changed to \a color. | |
154 | */ |
|
154 | */ | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | \fn void QLegend::fontChanged(QFont) |
|
157 | \fn void QLegend::fontChanged(QFont) | |
158 | The font of markers of the legend changed to \a font. |
|
158 | The font of markers of the legend changed to \a font. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QLegend::labelColorChanged(QColor color) |
|
162 | \fn void QLegend::labelColorChanged(QColor color) | |
163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
163 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
164 | */ |
|
164 | */ | |
165 |
|
165 | |||
166 | /*! |
|
166 | /*! | |
167 | Constructs the legend object and sets the parent to \a parent |
|
167 | Constructs the legend object and sets the parent to \a parent | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), |
|
170 | QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), | |
171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) |
|
171 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter,chart,this)) | |
172 | { |
|
172 | { | |
173 | setZValue(ChartPresenter::LegendZValue); |
|
173 | setZValue(ChartPresenter::LegendZValue); | |
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
174 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
175 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); |
|
175 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesAdded(QAbstractSeries*,Domain*)),d_ptr.data(),SLOT(handleSeriesAdded(QAbstractSeries*,Domain*))); | |
176 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
176 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesRemoved(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
177 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); |
|
177 | QObject::connect(chart->d_ptr->m_dataset,SIGNAL(seriesUpdated(QAbstractSeries*)),d_ptr.data(),SLOT(handleSeriesUpdated(QAbstractSeries*))); | |
178 | setLayout(d_ptr->m_layout); |
|
178 | setLayout(d_ptr->m_layout); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
182 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
183 | */ |
|
183 | */ | |
184 | QLegend::~QLegend() |
|
184 | QLegend::~QLegend() | |
185 | { |
|
185 | { | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \internal |
|
189 | \internal | |
190 | */ |
|
190 | */ | |
191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
191 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
192 | { |
|
192 | { | |
193 | Q_UNUSED(option) |
|
193 | Q_UNUSED(option) | |
194 | Q_UNUSED(widget) |
|
194 | Q_UNUSED(widget) | |
195 | if(!d_ptr->m_backgroundVisible) return; |
|
195 | if(!d_ptr->m_backgroundVisible) return; | |
196 |
|
196 | |||
197 | painter->setOpacity(opacity()); |
|
197 | painter->setOpacity(opacity()); | |
198 | painter->setPen(d_ptr->m_pen); |
|
198 | painter->setPen(d_ptr->m_pen); | |
199 | painter->setBrush(d_ptr->m_brush); |
|
199 | painter->setBrush(d_ptr->m_brush); | |
200 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); |
|
200 | painter->drawRoundRect(rect(),d_ptr->roundness(rect().width()),d_ptr->roundness(rect().height())); | |
201 |
|
201 | |||
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 |
|
204 | |||
205 | /*! |
|
205 | /*! | |
206 | Sets the \a brush of legend. Brush affects the background of legend. |
|
206 | Sets the \a brush of legend. Brush affects the background of legend. | |
207 | */ |
|
207 | */ | |
208 | void QLegend::setBrush(const QBrush &brush) |
|
208 | void QLegend::setBrush(const QBrush &brush) | |
209 | { |
|
209 | { | |
210 | if (d_ptr->m_brush != brush) { |
|
210 | if (d_ptr->m_brush != brush) { | |
211 | d_ptr->m_brush = brush; |
|
211 | d_ptr->m_brush = brush; | |
212 | update(); |
|
212 | update(); | |
213 | emit colorChanged(brush.color()); |
|
213 | emit colorChanged(brush.color()); | |
214 | } |
|
214 | } | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Returns the brush used by legend. |
|
218 | Returns the brush used by legend. | |
219 | */ |
|
219 | */ | |
220 | QBrush QLegend::brush() const |
|
220 | QBrush QLegend::brush() const | |
221 | { |
|
221 | { | |
222 | return d_ptr->m_brush; |
|
222 | return d_ptr->m_brush; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void QLegend::setColor(QColor color) |
|
225 | void QLegend::setColor(QColor color) | |
226 | { |
|
226 | { | |
227 | QBrush b = d_ptr->m_brush; |
|
227 | QBrush b = d_ptr->m_brush; | |
228 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
228 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
229 | b.setStyle(Qt::SolidPattern); |
|
229 | b.setStyle(Qt::SolidPattern); | |
230 | b.setColor(color); |
|
230 | b.setColor(color); | |
231 | setBrush(b); |
|
231 | setBrush(b); | |
232 | } |
|
232 | } | |
233 | } |
|
233 | } | |
234 |
|
234 | |||
235 | QColor QLegend::color() |
|
235 | QColor QLegend::color() | |
236 | { |
|
236 | { | |
237 | return d_ptr->m_brush.color(); |
|
237 | return d_ptr->m_brush.color(); | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | Sets the \a pen of legend. Pen affects the legend borders. |
|
241 | Sets the \a pen of legend. Pen affects the legend borders. | |
242 | */ |
|
242 | */ | |
243 | void QLegend::setPen(const QPen &pen) |
|
243 | void QLegend::setPen(const QPen &pen) | |
244 | { |
|
244 | { | |
245 | if (d_ptr->m_pen != pen) { |
|
245 | if (d_ptr->m_pen != pen) { | |
246 | d_ptr->m_pen = pen; |
|
246 | d_ptr->m_pen = pen; | |
247 | update(); |
|
247 | update(); | |
248 | emit borderColorChanged(pen.color()); |
|
248 | emit borderColorChanged(pen.color()); | |
249 | } |
|
249 | } | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | Returns the pen used by legend |
|
253 | Returns the pen used by legend | |
254 | */ |
|
254 | */ | |
255 |
|
255 | |||
256 | QPen QLegend::pen() const |
|
256 | QPen QLegend::pen() const | |
257 | { |
|
257 | { | |
258 | return d_ptr->m_pen; |
|
258 | return d_ptr->m_pen; | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | void QLegend::setFont(const QFont &font) |
|
261 | void QLegend::setFont(const QFont &font) | |
262 | { |
|
262 | { | |
263 | if (d_ptr->m_font != font) { |
|
263 | if (d_ptr->m_font != font) { | |
264 | d_ptr->m_font = font; |
|
264 | d_ptr->m_font = font; | |
265 |
|
265 | |||
266 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
266 | foreach (LegendMarker *marker, d_ptr->markers()) { | |
267 | marker->setFont(d_ptr->m_font); |
|
267 | marker->setFont(d_ptr->m_font); | |
268 | } |
|
268 | } | |
269 | layout()->invalidate(); |
|
269 | layout()->invalidate(); | |
270 | emit fontChanged(font); |
|
270 | emit fontChanged(font); | |
271 | } |
|
271 | } | |
272 | } |
|
272 | } | |
273 |
|
273 | |||
274 | QFont QLegend::font() const |
|
274 | QFont QLegend::font() const | |
275 | { |
|
275 | { | |
276 | return d_ptr->m_font; |
|
276 | return d_ptr->m_font; | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void QLegend::setBorderColor(QColor color) |
|
279 | void QLegend::setBorderColor(QColor color) | |
280 | { |
|
280 | { | |
281 | QPen p = d_ptr->m_pen; |
|
281 | QPen p = d_ptr->m_pen; | |
282 | if (p.color() != color) { |
|
282 | if (p.color() != color) { | |
283 | p.setColor(color); |
|
283 | p.setColor(color); | |
284 | setPen(p); |
|
284 | setPen(p); | |
285 | } |
|
285 | } | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | QColor QLegend::borderColor() |
|
288 | QColor QLegend::borderColor() | |
289 | { |
|
289 | { | |
290 | return d_ptr->m_pen.color(); |
|
290 | return d_ptr->m_pen.color(); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | /*! |
|
293 | /*! | |
294 | Set brush used to draw labels to \a brush. |
|
294 | Set brush used to draw labels to \a brush. | |
295 | */ |
|
295 | */ | |
296 | void QLegend::setLabelBrush(const QBrush &brush) |
|
296 | void QLegend::setLabelBrush(const QBrush &brush) | |
297 | { |
|
297 | { | |
298 | if (d_ptr->m_labelBrush != brush) { |
|
298 | if (d_ptr->m_labelBrush != brush) { | |
299 | d_ptr->m_labelBrush = brush; |
|
299 | d_ptr->m_labelBrush = brush; | |
300 | foreach (LegendMarker *marker, d_ptr->markers()) { |
|
300 | foreach (LegendMarker *marker, d_ptr->markers()) { | |
301 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
301 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
302 | } |
|
302 | } | |
303 | emit labelColorChanged(brush.color()); |
|
303 | emit labelColorChanged(brush.color()); | |
304 | } |
|
304 | } | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | /*! |
|
307 | /*! | |
308 | Brush used to draw labels. |
|
308 | Brush used to draw labels. | |
309 | */ |
|
309 | */ | |
310 | QBrush QLegend::labelBrush() const |
|
310 | QBrush QLegend::labelBrush() const | |
311 | { |
|
311 | { | |
312 | return d_ptr->m_labelBrush; |
|
312 | return d_ptr->m_labelBrush; | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | void QLegend::setLabelColor(QColor color) |
|
315 | void QLegend::setLabelColor(QColor color) | |
316 | { |
|
316 | { | |
317 | QBrush b = d_ptr->m_labelBrush; |
|
317 | QBrush b = d_ptr->m_labelBrush; | |
318 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
318 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
319 | b.setStyle(Qt::SolidPattern); |
|
319 | b.setStyle(Qt::SolidPattern); | |
320 | b.setColor(color); |
|
320 | b.setColor(color); | |
321 | setLabelBrush(b); |
|
321 | setLabelBrush(b); | |
322 | } |
|
322 | } | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | QColor QLegend::labelColor() const |
|
325 | QColor QLegend::labelColor() const | |
326 | { |
|
326 | { | |
327 | return d_ptr->m_labelBrush.color(); |
|
327 | return d_ptr->m_labelBrush.color(); | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 |
|
330 | |||
331 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
331 | void QLegend::setAlignment(Qt::Alignment alignment) | |
332 | { |
|
332 | { | |
333 | if(d_ptr->m_alignment!=alignment) { |
|
333 | if(d_ptr->m_alignment!=alignment) { | |
334 | d_ptr->m_alignment = alignment; |
|
334 | d_ptr->m_alignment = alignment; | |
335 | updateGeometry(); |
|
335 | updateGeometry(); | |
336 | if(isAttachedToChart()){ |
|
336 | if(isAttachedToChart()){ | |
337 | d_ptr->m_presenter->layout()->invalidate(); |
|
337 | d_ptr->m_presenter->layout()->invalidate(); | |
338 | }else{ |
|
338 | }else{ | |
339 | layout()->invalidate(); |
|
339 | layout()->invalidate(); | |
340 | } |
|
340 | } | |
341 | } |
|
341 | } | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | Qt::Alignment QLegend::alignment() const |
|
344 | Qt::Alignment QLegend::alignment() const | |
345 | { |
|
345 | { | |
346 | return d_ptr->m_alignment; |
|
346 | return d_ptr->m_alignment; | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
350 | Detaches the legend from chart. Chart won't change layout of the legend. | |
351 | */ |
|
351 | */ | |
352 | void QLegend::detachFromChart() |
|
352 | void QLegend::detachFromChart() | |
353 | { |
|
353 | { | |
354 | d_ptr->m_attachedToChart = false; |
|
354 | d_ptr->m_attachedToChart = false; | |
355 | d_ptr->m_layout->invalidate(); |
|
355 | d_ptr->m_layout->invalidate(); | |
356 | setParent(0); |
|
356 | setParent(0); | |
357 |
|
357 | |||
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | /*! |
|
360 | /*! | |
361 | Attaches the legend to chart. Chart may change layout of the legend. |
|
361 | Attaches the legend to chart. Chart may change layout of the legend. | |
362 | */ |
|
362 | */ | |
363 | void QLegend::attachToChart() |
|
363 | void QLegend::attachToChart() | |
364 | { |
|
364 | { | |
365 | d_ptr->m_attachedToChart = true; |
|
365 | d_ptr->m_attachedToChart = true; | |
366 | d_ptr->m_layout->invalidate(); |
|
366 | d_ptr->m_layout->invalidate(); | |
367 | setParent(d_ptr->m_chart); |
|
367 | setParent(d_ptr->m_chart); | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Returns true, if legend is attached to chart. |
|
371 | Returns true, if legend is attached to chart. | |
372 | */ |
|
372 | */ | |
373 | bool QLegend::isAttachedToChart() |
|
373 | bool QLegend::isAttachedToChart() | |
374 | { |
|
374 | { | |
375 | return d_ptr->m_attachedToChart; |
|
375 | return d_ptr->m_attachedToChart; | |
376 | } |
|
376 | } | |
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Sets the visibility of legend background to \a visible |
|
379 | Sets the visibility of legend background to \a visible | |
380 | */ |
|
380 | */ | |
381 | void QLegend::setBackgroundVisible(bool visible) |
|
381 | void QLegend::setBackgroundVisible(bool visible) | |
382 | { |
|
382 | { | |
383 | if(d_ptr->m_backgroundVisible != visible) { |
|
383 | if(d_ptr->m_backgroundVisible != visible) { | |
384 | d_ptr->m_backgroundVisible = visible; |
|
384 | d_ptr->m_backgroundVisible = visible; | |
385 | update(); |
|
385 | update(); | |
386 | emit backgroundVisibleChanged(visible); |
|
386 | emit backgroundVisibleChanged(visible); | |
387 | } |
|
387 | } | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | /*! |
|
390 | /*! | |
391 | Returns the visibility of legend background |
|
391 | Returns the visibility of legend background | |
392 | */ |
|
392 | */ | |
393 | bool QLegend::isBackgroundVisible() const |
|
393 | bool QLegend::isBackgroundVisible() const | |
394 | { |
|
394 | { | |
395 | return d_ptr->m_backgroundVisible; |
|
395 | return d_ptr->m_backgroundVisible; | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | /*! |
|
398 | /*! | |
399 | \internal \a event see QGraphicsWidget for details |
|
399 | \internal \a event see QGraphicsWidget for details | |
400 | */ |
|
400 | */ | |
401 | void QLegend::hideEvent(QHideEvent *event) |
|
401 | void QLegend::hideEvent(QHideEvent *event) | |
402 | { |
|
402 | { | |
403 | QGraphicsWidget::hideEvent(event); |
|
403 | QGraphicsWidget::hideEvent(event); | |
404 | d_ptr->m_presenter->layout()->invalidate(); |
|
404 | d_ptr->m_presenter->layout()->invalidate(); | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 | /*! |
|
407 | /*! | |
408 | \internal \a event see QGraphicsWidget for details |
|
408 | \internal \a event see QGraphicsWidget for details | |
409 | */ |
|
409 | */ | |
410 | void QLegend::showEvent(QShowEvent *event) |
|
410 | void QLegend::showEvent(QShowEvent *event) | |
411 | { |
|
411 | { | |
412 | QGraphicsWidget::showEvent(event); |
|
412 | QGraphicsWidget::showEvent(event); | |
413 | d_ptr->m_presenter->layout()->invalidate(); |
|
413 | d_ptr->m_presenter->layout()->invalidate(); | |
414 | } |
|
414 | } | |
415 |
|
415 | |||
416 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
416 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
417 |
|
417 | |||
418 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): |
|
418 | QLegendPrivate::QLegendPrivate(ChartPresenter* presenter, QChart *chart, QLegend *q): | |
419 | q_ptr(q), |
|
419 | q_ptr(q), | |
420 | m_presenter(presenter), |
|
420 | m_presenter(presenter), | |
421 | m_layout(new LegendLayout(q)), |
|
421 | m_layout(new LegendLayout(q)), | |
422 | m_chart(chart), |
|
422 | m_chart(chart), | |
423 | m_items(new QGraphicsItemGroup(q)), |
|
423 | m_items(new QGraphicsItemGroup(q)), | |
424 | m_alignment(Qt::AlignTop), |
|
424 | m_alignment(Qt::AlignTop), | |
425 | m_brush(QBrush()), |
|
425 | m_brush(QBrush()), | |
426 | m_pen(QPen()), |
|
426 | m_pen(QPen()), | |
427 | m_labelBrush(QBrush()), |
|
427 | m_labelBrush(QBrush()), | |
428 | m_diameter(5), |
|
428 | m_diameter(5), | |
429 | m_attachedToChart(true), |
|
429 | m_attachedToChart(true), | |
430 | m_backgroundVisible(false) |
|
430 | m_backgroundVisible(false) | |
431 | { |
|
431 | { | |
432 |
|
432 | |||
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | QLegendPrivate::~QLegendPrivate() |
|
435 | QLegendPrivate::~QLegendPrivate() | |
436 | { |
|
436 | { | |
437 |
|
437 | |||
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | void QLegendPrivate::setOffset(qreal x, qreal y) |
|
440 | void QLegendPrivate::setOffset(qreal x, qreal y) | |
441 | { |
|
441 | { | |
442 | m_layout->setOffset(x,y); |
|
442 | m_layout->setOffset(x,y); | |
443 | } |
|
443 | } | |
444 |
|
444 | |||
445 | QPointF QLegendPrivate::offset() const |
|
445 | QPointF QLegendPrivate::offset() const | |
446 | { |
|
446 | { | |
447 | return m_layout->offset(); |
|
447 | return m_layout->offset(); | |
448 | } |
|
448 | } | |
449 |
|
449 | |||
450 | int QLegendPrivate::roundness(qreal size) |
|
450 | int QLegendPrivate::roundness(qreal size) | |
451 | { |
|
451 | { | |
452 | return 100*m_diameter/int(size); |
|
452 | return 100*m_diameter/int(size); | |
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) |
|
455 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series, Domain *domain) | |
456 | { |
|
456 | { | |
457 | Q_UNUSED(domain) |
|
457 | Q_UNUSED(domain) | |
458 |
|
458 | |||
459 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); |
|
459 | QList<LegendMarker*> markers = series->d_ptr->createLegendMarker(q_ptr); | |
460 |
|
460 | |||
461 | foreach(LegendMarker* marker, markers) { |
|
461 | foreach(LegendMarker* marker, markers) { | |
462 | marker->setFont(m_font); |
|
462 | marker->setFont(m_font); | |
463 | marker->setLabelBrush(m_labelBrush); |
|
463 | marker->setLabelBrush(m_labelBrush); | |
464 | m_items->addToGroup(marker); |
|
464 | m_items->addToGroup(marker); | |
465 | m_markers<<marker; |
|
465 | m_markers<<marker; | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
468 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
469 |
|
469 | |||
470 | if(series->type() == QAbstractSeries::SeriesTypePie) { |
|
470 | if(series->type() == QAbstractSeries::SeriesTypePie) { | |
471 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
471 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
472 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
472 | QObject::connect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
473 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
473 | QObject::connect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
474 | } |
|
474 | } | |
475 |
|
475 | |||
476 | q_ptr->layout()->invalidate(); |
|
476 | q_ptr->layout()->invalidate(); | |
477 | q_ptr->layout()->activate(); |
|
477 | q_ptr->layout()->activate(); | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
480 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
481 | { |
|
481 | { | |
482 | foreach (LegendMarker *marker, m_markers) { |
|
482 | foreach (LegendMarker *marker, m_markers) { | |
483 | if (marker->series() == series) { |
|
483 | if (marker->series() == series) { | |
484 | delete marker; |
|
484 | delete marker; | |
485 | m_markers.removeAll(marker); |
|
485 | m_markers.removeAll(marker); | |
486 | } |
|
486 | } | |
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | if(series->type() == QAbstractSeries::SeriesTypePie) |
|
489 | if(series->type() == QAbstractSeries::SeriesTypePie) | |
490 | { |
|
490 | { | |
491 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
491 | QPieSeries *pieSeries = static_cast<QPieSeries *>(series); | |
492 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
492 | QObject::disconnect(pieSeries, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
493 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); |
|
493 | QObject::disconnect(pieSeries, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleUpdatePieSeries())); | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 | q_ptr->layout()->invalidate(); |
|
496 | q_ptr->layout()->invalidate(); | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) |
|
499 | void QLegendPrivate::handleSeriesUpdated(QAbstractSeries *series) | |
500 | { |
|
500 | { | |
501 | // TODO: find out which markers are are added or removed. Update them |
|
501 | // TODO: find out which markers are are added or removed. Update them | |
502 | // TODO: better implementation |
|
502 | // TODO: better implementation | |
503 | handleSeriesRemoved(series); |
|
503 | handleSeriesRemoved(series); | |
504 | Domain domain; |
|
504 | Domain domain; | |
505 | handleSeriesAdded(series, &domain); |
|
505 | handleSeriesAdded(series, &domain); | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | void QLegendPrivate::handleUpdatePieSeries() |
|
508 | void QLegendPrivate::handleUpdatePieSeries() | |
509 | { |
|
509 | { | |
510 | //TODO: reimplement to be optimal |
|
510 | //TODO: reimplement to be optimal | |
511 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); |
|
511 | QPieSeries* series = qobject_cast<QPieSeries *> (sender()); | |
512 | Q_ASSERT(series); |
|
512 | Q_ASSERT(series); | |
513 | handleSeriesRemoved(series); |
|
513 | handleSeriesRemoved(series); | |
514 | handleSeriesAdded(series, 0); |
|
514 | handleSeriesAdded(series, 0); | |
515 | } |
|
515 | } | |
516 |
|
516 | |||
517 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
517 | void QLegendPrivate::handleSeriesVisibleChanged() | |
518 | { |
|
518 | { | |
519 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); |
|
519 | QAbstractSeries* series = qobject_cast<QAbstractSeries *> (sender()); | |
520 |
|
520 | |||
521 | foreach (LegendMarker* marker, m_markers) { |
|
521 | foreach (LegendMarker* marker, m_markers) { | |
522 | if (marker->series() == series) { |
|
522 | if (marker->series() == series) { | |
523 | marker->setVisible(!marker->isVisible()); |
|
523 | marker->setVisible(!marker->isVisible()); | |
524 | } |
|
524 | } | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | q_ptr->layout()->invalidate(); |
|
527 | q_ptr->layout()->invalidate(); | |
528 | } |
|
528 | } | |
529 |
|
529 | |||
530 | #include "moc_qlegend.cpp" |
|
530 | #include "moc_qlegend.cpp" | |
531 | #include "moc_qlegend_p.cpp" |
|
531 | #include "moc_qlegend_p.cpp" | |
532 |
|
532 | |||
533 | QTCOMMERCIALCHART_END_NAMESPACE |
|
533 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,111 +1,111 | |||||
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 QLEGEND_H |
|
21 | #ifndef QLEGEND_H | |
22 | #define QLEGEND_H |
|
22 | #define QLEGEND_H | |
23 |
|
23 | |||
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QPen> |
|
26 | #include <QPen> | |
27 | #include <QBrush> |
|
27 | #include <QBrush> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class Domain; |
|
31 | class Domain; | |
32 | class LegendMarker; |
|
32 | class LegendMarker; | |
33 | class QPieSlice; |
|
33 | class QPieSlice; | |
34 | class QXYSeries; |
|
34 | class QXYSeries; | |
35 | class QBarSet; |
|
35 | class QBarSet; | |
36 | class QBarSeries; |
|
36 | class QAbstractBarSeries; | |
37 | class QPieSeries; |
|
37 | class QPieSeries; | |
38 | class QAreaSeries; |
|
38 | class QAreaSeries; | |
39 | class LegendScrollButton; |
|
39 | class LegendScrollButton; | |
40 | class QChart; |
|
40 | class QChart; | |
41 | class QLegendPrivate; |
|
41 | class QLegendPrivate; | |
42 |
|
42 | |||
43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget |
|
43 | class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) |
|
46 | Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment) | |
47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) |
|
47 | Q_PROPERTY(bool backgroundVisible READ isBackgroundVisible WRITE setBackgroundVisible NOTIFY backgroundVisibleChanged) | |
48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
48 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) | |
49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
49 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) | |
50 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) |
|
50 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) | |
51 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
51 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) | |
52 |
|
52 | |||
53 | private: |
|
53 | private: | |
54 | explicit QLegend(QChart *chart); |
|
54 | explicit QLegend(QChart *chart); | |
55 |
|
55 | |||
56 | public: |
|
56 | public: | |
57 | ~QLegend(); |
|
57 | ~QLegend(); | |
58 |
|
58 | |||
59 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
59 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); | |
60 |
|
60 | |||
61 | void setBrush(const QBrush &brush); |
|
61 | void setBrush(const QBrush &brush); | |
62 | QBrush brush() const; |
|
62 | QBrush brush() const; | |
63 | void setColor(QColor color); |
|
63 | void setColor(QColor color); | |
64 | QColor color(); |
|
64 | QColor color(); | |
65 |
|
65 | |||
66 | void setPen(const QPen &pen); |
|
66 | void setPen(const QPen &pen); | |
67 | QPen pen() const; |
|
67 | QPen pen() const; | |
68 | void setBorderColor(QColor color); |
|
68 | void setBorderColor(QColor color); | |
69 | QColor borderColor(); |
|
69 | QColor borderColor(); | |
70 |
|
70 | |||
71 | void setFont(const QFont &font); |
|
71 | void setFont(const QFont &font); | |
72 | QFont font() const; |
|
72 | QFont font() const; | |
73 | void setLabelBrush(const QBrush &brush); |
|
73 | void setLabelBrush(const QBrush &brush); | |
74 | QBrush labelBrush() const; |
|
74 | QBrush labelBrush() const; | |
75 |
|
75 | |||
76 | void setLabelColor(QColor color); |
|
76 | void setLabelColor(QColor color); | |
77 | QColor labelColor() const; |
|
77 | QColor labelColor() const; | |
78 |
|
78 | |||
79 | void setAlignment(Qt::Alignment alignment); |
|
79 | void setAlignment(Qt::Alignment alignment); | |
80 | Qt::Alignment alignment() const; |
|
80 | Qt::Alignment alignment() const; | |
81 |
|
81 | |||
82 | void detachFromChart(); |
|
82 | void detachFromChart(); | |
83 | void attachToChart(); |
|
83 | void attachToChart(); | |
84 | bool isAttachedToChart(); |
|
84 | bool isAttachedToChart(); | |
85 |
|
85 | |||
86 | void setBackgroundVisible(bool visible = true); |
|
86 | void setBackgroundVisible(bool visible = true); | |
87 | bool isBackgroundVisible() const; |
|
87 | bool isBackgroundVisible() const; | |
88 |
|
88 | |||
89 |
|
89 | |||
90 | protected: |
|
90 | protected: | |
91 | void hideEvent(QHideEvent *event); |
|
91 | void hideEvent(QHideEvent *event); | |
92 | void showEvent(QShowEvent *event); |
|
92 | void showEvent(QShowEvent *event); | |
93 |
|
93 | |||
94 | Q_SIGNALS: |
|
94 | Q_SIGNALS: | |
95 | void backgroundVisibleChanged(bool visible); |
|
95 | void backgroundVisibleChanged(bool visible); | |
96 | void colorChanged(QColor color); |
|
96 | void colorChanged(QColor color); | |
97 | void borderColorChanged(QColor color); |
|
97 | void borderColorChanged(QColor color); | |
98 | void fontChanged(QFont font); |
|
98 | void fontChanged(QFont font); | |
99 | void labelColorChanged(QColor color); |
|
99 | void labelColorChanged(QColor color); | |
100 |
|
100 | |||
101 | private: |
|
101 | private: | |
102 | QScopedPointer<QLegendPrivate> d_ptr; |
|
102 | QScopedPointer<QLegendPrivate> d_ptr; | |
103 | Q_DISABLE_COPY(QLegend) |
|
103 | Q_DISABLE_COPY(QLegend) | |
104 | friend class LegendScroller; |
|
104 | friend class LegendScroller; | |
105 | friend class LegendLayout; |
|
105 | friend class LegendLayout; | |
106 | friend class ChartLayout; |
|
106 | friend class ChartLayout; | |
107 | }; |
|
107 | }; | |
108 |
|
108 | |||
109 | QTCOMMERCIALCHART_END_NAMESPACE |
|
109 | QTCOMMERCIALCHART_END_NAMESPACE | |
110 |
|
110 | |||
111 | #endif // QLEGEND_H |
|
111 | #endif // QLEGEND_H |
@@ -1,190 +1,190 | |||||
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 "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QAbstractSeries |
|
28 | \class QAbstractSeries | |
29 | \brief Base class for all QtCommercial Chart series. |
|
29 | \brief Base class for all QtCommercial Chart series. | |
30 | \mainclass |
|
30 | \mainclass | |
31 |
|
31 | |||
32 | Usually you use the series type specific inherited classes instead of the base class. |
|
32 | Usually you use the series type specific inherited classes instead of the base class. | |
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries, |
|
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, | |
34 | QPercentBarSeries, QPieSeries |
|
34 | QPercentBarSeries, QPieSeries | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass AbstractSeries |
|
37 | \qmlclass AbstractSeries | |
38 | AbstractSeries is the base class for all series. |
|
38 | AbstractSeries is the base class for all series. | |
39 | The class cannot be instantiated by the user. |
|
39 | The class cannot be instantiated by the user. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \enum QAbstractSeries::SeriesType |
|
43 | \enum QAbstractSeries::SeriesType | |
44 |
|
44 | |||
45 | The type of the series object. |
|
45 | The type of the series object. | |
46 |
|
46 | |||
47 | \value SeriesTypeLine |
|
47 | \value SeriesTypeLine | |
48 | \value SeriesTypeArea |
|
48 | \value SeriesTypeArea | |
49 | \value SeriesTypeBar |
|
49 | \value SeriesTypeBar | |
50 | \value SeriesTypeStackedBar |
|
50 | \value SeriesTypeStackedBar | |
51 | \value SeriesTypePercentBar |
|
51 | \value SeriesTypePercentBar | |
52 | \value SeriesTypeGroupedBar |
|
52 | \value SeriesTypeGroupedBar | |
53 | \value SeriesTypePie |
|
53 | \value SeriesTypePie | |
54 | \value SeriesTypeScatter |
|
54 | \value SeriesTypeScatter | |
55 | \value SeriesTypeSpline |
|
55 | \value SeriesTypeSpline | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QAbstractSeries::type |
|
59 | \property QAbstractSeries::type | |
60 | The type of the series. |
|
60 | The type of the series. | |
61 | */ |
|
61 | */ | |
62 | /*! |
|
62 | /*! | |
63 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
63 | \qmlproperty ChartView.SeriesType AbstractSeries::type | |
64 | The type of the series. |
|
64 | The type of the series. | |
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | \property QAbstractSeries::name |
|
68 | \property QAbstractSeries::name | |
69 | \brief name of the series property. The name is shown in legend for QXYSeries. |
|
69 | \brief name of the series property. The name is shown in legend for QXYSeries. | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty string AbstractSeries::name |
|
72 | \qmlproperty string AbstractSeries::name | |
73 | Name of the series. The name is shown in legend for QXYSeries. |
|
73 | Name of the series. The name is shown in legend for QXYSeries. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \fn void QAbstractSeries::nameChanged() |
|
77 | \fn void QAbstractSeries::nameChanged() | |
78 | This signal is emitted when the series name changes. |
|
78 | This signal is emitted when the series name changes. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlsignal AbstractSeries::nameChanged() |
|
81 | \qmlsignal AbstractSeries::nameChanged() | |
82 | This signal is emitted when the series name changes. |
|
82 | This signal is emitted when the series name changes. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QAbstractSeries::visible |
|
86 | \property QAbstractSeries::visible | |
87 | \brief whether the series is visible or not; true by default. |
|
87 | \brief whether the series is visible or not; true by default. | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \fn void QAbstractSeries::visibleChanged() |
|
91 | \fn void QAbstractSeries::visibleChanged() | |
92 | Emitted when the series visibility changes. |
|
92 | Emitted when the series visibility changes. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \internal |
|
96 | \internal | |
97 | \brief Constructs ChartSeries object with \a parent. |
|
97 | \brief Constructs ChartSeries object with \a parent. | |
98 | */ |
|
98 | */ | |
99 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
99 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
100 | QObject(parent), |
|
100 | QObject(parent), | |
101 | d_ptr(&d) |
|
101 | d_ptr(&d) | |
102 | { |
|
102 | { | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \brief Virtual destructor for the chart series. |
|
106 | \brief Virtual destructor for the chart series. | |
107 | */ |
|
107 | */ | |
108 | QAbstractSeries::~QAbstractSeries() |
|
108 | QAbstractSeries::~QAbstractSeries() | |
109 | { |
|
109 | { | |
110 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
110 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void QAbstractSeries::setName(const QString& name) |
|
113 | void QAbstractSeries::setName(const QString& name) | |
114 | { |
|
114 | { | |
115 | if (name != d_ptr->m_name) { |
|
115 | if (name != d_ptr->m_name) { | |
116 | d_ptr->m_name = name; |
|
116 | d_ptr->m_name = name; | |
117 | emit nameChanged(); |
|
117 | emit nameChanged(); | |
118 | } |
|
118 | } | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | QString QAbstractSeries::name() const |
|
121 | QString QAbstractSeries::name() const | |
122 | { |
|
122 | { | |
123 | return d_ptr->m_name; |
|
123 | return d_ptr->m_name; | |
124 | } |
|
124 | } | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | Sets the visibility of series to \a visible |
|
127 | Sets the visibility of series to \a visible | |
128 | */ |
|
128 | */ | |
129 | void QAbstractSeries::setVisible(bool visible) |
|
129 | void QAbstractSeries::setVisible(bool visible) | |
130 | { |
|
130 | { | |
131 | if (visible != d_ptr->m_visible) { |
|
131 | if (visible != d_ptr->m_visible) { | |
132 | d_ptr->m_visible = visible; |
|
132 | d_ptr->m_visible = visible; | |
133 | emit visibleChanged(); |
|
133 | emit visibleChanged(); | |
134 | } |
|
134 | } | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | Returns the visibility of series |
|
138 | Returns the visibility of series | |
139 | */ |
|
139 | */ | |
140 | bool QAbstractSeries::isVisible() const |
|
140 | bool QAbstractSeries::isVisible() const | |
141 | { |
|
141 | { | |
142 | return d_ptr->m_visible; |
|
142 | return d_ptr->m_visible; | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \brief Returns the chart where series belongs to. |
|
146 | \brief Returns the chart where series belongs to. | |
147 |
|
147 | |||
148 | Set automatically when the series is added to the chart |
|
148 | Set automatically when the series is added to the chart | |
149 | and unset when the series is removed from the chart. |
|
149 | and unset when the series is removed from the chart. | |
150 | */ |
|
150 | */ | |
151 | QChart* QAbstractSeries::chart() const |
|
151 | QChart* QAbstractSeries::chart() const | |
152 | { |
|
152 | { | |
153 | return d_ptr->m_chart; |
|
153 | return d_ptr->m_chart; | |
154 | } |
|
154 | } | |
155 |
|
155 | |||
156 | void QAbstractSeries::adjustView() |
|
156 | void QAbstractSeries::adjustView() | |
157 | { |
|
157 | { | |
158 | //TODO: |
|
158 | //TODO: | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void QAbstractSeries::show() |
|
161 | void QAbstractSeries::show() | |
162 | { |
|
162 | { | |
163 | setVisible(true); |
|
163 | setVisible(true); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void QAbstractSeries::hide() |
|
166 | void QAbstractSeries::hide() | |
167 | { |
|
167 | { | |
168 | setVisible(false); |
|
168 | setVisible(false); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
171 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
172 |
|
172 | |||
173 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
173 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): | |
174 | q_ptr(q), |
|
174 | q_ptr(q), | |
175 | m_chart(0), |
|
175 | m_chart(0), | |
176 | m_dataset(0), |
|
176 | m_dataset(0), | |
177 | m_visible(true) |
|
177 | m_visible(true) | |
178 | { |
|
178 | { | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
181 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
182 | { |
|
182 | { | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | #include "moc_qabstractseries.cpp" |
|
185 | #include "moc_qabstractseries.cpp" | |
186 | #include "moc_qabstractseries_p.cpp" |
|
186 | #include "moc_qabstractseries_p.cpp" | |
187 |
|
187 | |||
188 | QTCOMMERCIALCHART_END_NAMESPACE |
|
188 | QTCOMMERCIALCHART_END_NAMESPACE | |
189 |
|
189 | |||
190 |
|
190 |
@@ -1,634 +1,634 | |||||
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 <qabstractaxis.h> |
|
22 | #include <qabstractaxis.h> | |
23 | #include <qvaluesaxis.h> |
|
23 | #include <qvaluesaxis.h> | |
24 | #include <qcategoriesaxis.h> |
|
24 | #include <qcategoriesaxis.h> | |
25 | #include <qlineseries.h> |
|
25 | #include <qlineseries.h> | |
26 | #include <qareaseries.h> |
|
26 | #include <qareaseries.h> | |
27 | #include <qscatterseries.h> |
|
27 | #include <qscatterseries.h> | |
28 | #include <qsplineseries.h> |
|
28 | #include <qsplineseries.h> | |
29 | #include <qpieseries.h> |
|
29 | #include <qpieseries.h> | |
30 | #include <qbarseries.h> |
|
30 | #include <qabstractbarseries.h> | |
31 | #include <qpercentbarseries.h> |
|
31 | #include <qpercentbarseries.h> | |
32 | #include <qstackedbarseries.h> |
|
32 | #include <qstackedbarseries.h> | |
33 | #include <private/chartdataset_p.h> |
|
33 | #include <private/chartdataset_p.h> | |
34 | #include <private/domain_p.h> |
|
34 | #include <private/domain_p.h> | |
35 | #include <tst_definitions.h> |
|
35 | #include <tst_definitions.h> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | QTCOMMERCIALCHART_USE_NAMESPACE | |
38 |
|
38 | |||
39 | Q_DECLARE_METATYPE(Domain *) |
|
39 | Q_DECLARE_METATYPE(Domain *) | |
40 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
40 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
41 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) |
|
42 | Q_DECLARE_METATYPE(QList<QAbstractSeries *>) | |
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) |
|
43 | Q_DECLARE_METATYPE(QList<QAbstractAxis *>) | |
44 | Q_DECLARE_METATYPE(QLineSeries *) |
|
44 | Q_DECLARE_METATYPE(QLineSeries *) | |
45 |
|
45 | |||
46 | class tst_ChartDataSet: public QObject { |
|
46 | class tst_ChartDataSet: public QObject { | |
47 |
|
47 | |||
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 |
|
49 | |||
50 | public Q_SLOTS: |
|
50 | public Q_SLOTS: | |
51 | void initTestCase(); |
|
51 | void initTestCase(); | |
52 | void cleanupTestCase(); |
|
52 | void cleanupTestCase(); | |
53 | void init(); |
|
53 | void init(); | |
54 | void cleanup(); |
|
54 | void cleanup(); | |
55 |
|
55 | |||
56 | private Q_SLOTS: |
|
56 | private Q_SLOTS: | |
57 | void chartdataset_data(); |
|
57 | void chartdataset_data(); | |
58 | void chartdataset(); |
|
58 | void chartdataset(); | |
59 | void addSeries_data(); |
|
59 | void addSeries_data(); | |
60 | void addSeries(); |
|
60 | void addSeries(); | |
61 | void setAxisX_data(); |
|
61 | void setAxisX_data(); | |
62 | void setAxisX(); |
|
62 | void setAxisX(); | |
63 | void setAxisY_data(); |
|
63 | void setAxisY_data(); | |
64 | void setAxisY(); |
|
64 | void setAxisY(); | |
65 | void removeSeries_data(); |
|
65 | void removeSeries_data(); | |
66 | void removeSeries(); |
|
66 | void removeSeries(); | |
67 | void removeAllSeries_data(); |
|
67 | void removeAllSeries_data(); | |
68 | void removeAllSeries(); |
|
68 | void removeAllSeries(); | |
69 | void seriesCount_data(); |
|
69 | void seriesCount_data(); | |
70 | void seriesCount(); |
|
70 | void seriesCount(); | |
71 | void seriesIndex_data(); |
|
71 | void seriesIndex_data(); | |
72 | void seriesIndex(); |
|
72 | void seriesIndex(); | |
73 | void domain_data(); |
|
73 | void domain_data(); | |
74 | void domain(); |
|
74 | void domain(); | |
75 | void zoomInDomain_data(); |
|
75 | void zoomInDomain_data(); | |
76 | void zoomInDomain(); |
|
76 | void zoomInDomain(); | |
77 | /* |
|
77 | /* | |
78 | void zoomOutDomain_data(); |
|
78 | void zoomOutDomain_data(); | |
79 | void zoomOutDomain(); |
|
79 | void zoomOutDomain(); | |
80 | void scrollDomain_data(); |
|
80 | void scrollDomain_data(); | |
81 | void scrollDomain(); |
|
81 | void scrollDomain(); | |
82 | */ |
|
82 | */ | |
83 | private: |
|
83 | private: | |
84 | ChartDataSet* m_dataset; |
|
84 | ChartDataSet* m_dataset; | |
85 | }; |
|
85 | }; | |
86 |
|
86 | |||
87 | void tst_ChartDataSet::initTestCase() |
|
87 | void tst_ChartDataSet::initTestCase() | |
88 | { |
|
88 | { | |
89 | qRegisterMetaType<Domain*>(); |
|
89 | qRegisterMetaType<Domain*>(); | |
90 | qRegisterMetaType<QAbstractAxis*>(); |
|
90 | qRegisterMetaType<QAbstractAxis*>(); | |
91 | qRegisterMetaType<QAbstractSeries*>(); |
|
91 | qRegisterMetaType<QAbstractSeries*>(); | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void tst_ChartDataSet::cleanupTestCase() |
|
94 | void tst_ChartDataSet::cleanupTestCase() | |
95 | { |
|
95 | { | |
96 | } |
|
96 | } | |
97 |
|
97 | |||
98 | void tst_ChartDataSet::init() |
|
98 | void tst_ChartDataSet::init() | |
99 | { |
|
99 | { | |
100 | m_dataset = new ChartDataSet(); |
|
100 | m_dataset = new ChartDataSet(); | |
101 | } |
|
101 | } | |
102 |
|
102 | |||
103 |
|
103 | |||
104 | void tst_ChartDataSet::cleanup() |
|
104 | void tst_ChartDataSet::cleanup() | |
105 | { |
|
105 | { | |
106 | QList<QAbstractSeries*> series = m_dataset->series(); |
|
106 | QList<QAbstractSeries*> series = m_dataset->series(); | |
107 | foreach(QAbstractSeries* serie, series) |
|
107 | foreach(QAbstractSeries* serie, series) | |
108 | { |
|
108 | { | |
109 | m_dataset->removeSeries(serie); |
|
109 | m_dataset->removeSeries(serie); | |
110 | } |
|
110 | } | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void tst_ChartDataSet::chartdataset_data() |
|
113 | void tst_ChartDataSet::chartdataset_data() | |
114 | { |
|
114 | { | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_ChartDataSet::chartdataset() |
|
117 | void tst_ChartDataSet::chartdataset() | |
118 | { |
|
118 | { | |
119 | QVERIFY(m_dataset->axisX(0) == 0); |
|
119 | QVERIFY(m_dataset->axisX(0) == 0); | |
120 | QVERIFY(m_dataset->axisY(0) == 0); |
|
120 | QVERIFY(m_dataset->axisY(0) == 0); | |
121 | QLineSeries* series = new QLineSeries(this); |
|
121 | QLineSeries* series = new QLineSeries(this); | |
122 | QCOMPARE(m_dataset->seriesIndex(series),-1); |
|
122 | QCOMPARE(m_dataset->seriesIndex(series),-1); | |
123 | QVERIFY(m_dataset->domain(series) == 0); |
|
123 | QVERIFY(m_dataset->domain(series) == 0); | |
124 | QVERIFY(m_dataset->axisX(series) == 0); |
|
124 | QVERIFY(m_dataset->axisX(series) == 0); | |
125 | QVERIFY(m_dataset->axisY(series) == 0); |
|
125 | QVERIFY(m_dataset->axisY(series) == 0); | |
126 | m_dataset->createDefaultAxes(); |
|
126 | m_dataset->createDefaultAxes(); | |
127 | } |
|
127 | } | |
128 |
|
128 | |||
129 |
|
129 | |||
130 | void tst_ChartDataSet::addSeries_data() |
|
130 | void tst_ChartDataSet::addSeries_data() | |
131 | { |
|
131 | { | |
132 | QTest::addColumn<QAbstractSeries*>("series"); |
|
132 | QTest::addColumn<QAbstractSeries*>("series"); | |
133 |
|
133 | |||
134 | QAbstractSeries* line = new QLineSeries(this); |
|
134 | QAbstractSeries* line = new QLineSeries(this); | |
135 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
135 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
136 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
136 | QAbstractSeries* scatter = new QScatterSeries(this); | |
137 | QAbstractSeries* spline = new QSplineSeries(this); |
|
137 | QAbstractSeries* spline = new QSplineSeries(this); | |
138 | QAbstractSeries* pie = new QPieSeries(this); |
|
138 | QAbstractSeries* pie = new QPieSeries(this); | |
139 | QAbstractSeries* bar = new QAbstractBarSeries(this); |
|
139 | QAbstractSeries* bar = new QAbstractBarSeries(this); | |
140 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
140 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
141 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
141 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
142 |
|
142 | |||
143 | QTest::newRow("line") << line; |
|
143 | QTest::newRow("line") << line; | |
144 | QTest::newRow("area") << area; |
|
144 | QTest::newRow("area") << area; | |
145 | QTest::newRow("scatter") << scatter; |
|
145 | QTest::newRow("scatter") << scatter; | |
146 | QTest::newRow("spline") << spline; |
|
146 | QTest::newRow("spline") << spline; | |
147 | QTest::newRow("pie") << pie; |
|
147 | QTest::newRow("pie") << pie; | |
148 | QTest::newRow("bar") << bar; |
|
148 | QTest::newRow("bar") << bar; | |
149 | QTest::newRow("percent") << percent; |
|
149 | QTest::newRow("percent") << percent; | |
150 | QTest::newRow("stacked") << stacked; |
|
150 | QTest::newRow("stacked") << stacked; | |
151 | } |
|
151 | } | |
152 |
|
152 | |||
153 | void tst_ChartDataSet::addSeries() |
|
153 | void tst_ChartDataSet::addSeries() | |
154 | { |
|
154 | { | |
155 |
|
155 | |||
156 | QFETCH(QAbstractSeries*, series); |
|
156 | QFETCH(QAbstractSeries*, series); | |
157 |
|
157 | |||
158 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
158 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
159 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
159 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
160 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
160 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
161 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
161 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
162 |
|
162 | |||
163 | m_dataset->addSeries(series); |
|
163 | m_dataset->addSeries(series); | |
164 | m_dataset->createDefaultAxes(); |
|
164 | m_dataset->createDefaultAxes(); | |
165 | if(series->type()==QAbstractSeries::SeriesTypePie){ |
|
165 | if(series->type()==QAbstractSeries::SeriesTypePie){ | |
166 | TRY_COMPARE(spy0.count(), 0); |
|
166 | TRY_COMPARE(spy0.count(), 0); | |
167 | }else{ |
|
167 | }else{ | |
168 | TRY_COMPARE(spy0.count(), 2); |
|
168 | TRY_COMPARE(spy0.count(), 2); | |
169 | } |
|
169 | } | |
170 | TRY_COMPARE(spy1.count(), 0); |
|
170 | TRY_COMPARE(spy1.count(), 0); | |
171 | TRY_COMPARE(spy2.count(), 1); |
|
171 | TRY_COMPARE(spy2.count(), 1); | |
172 | TRY_COMPARE(spy3.count(), 0); |
|
172 | TRY_COMPARE(spy3.count(), 0); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 |
|
175 | |||
176 | void tst_ChartDataSet::setAxisX_data() |
|
176 | void tst_ChartDataSet::setAxisX_data() | |
177 | { |
|
177 | { | |
178 |
|
178 | |||
179 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
179 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
180 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
180 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
181 | QTest::addColumn<int>("axisCount"); |
|
181 | QTest::addColumn<int>("axisCount"); | |
182 |
|
182 | |||
183 | QAbstractSeries* line = new QLineSeries(this); |
|
183 | QAbstractSeries* line = new QLineSeries(this); | |
184 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
184 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); | |
185 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
185 | QAbstractSeries* scatter = new QScatterSeries(this); | |
186 | QAbstractSeries* spline = new QSplineSeries(this); |
|
186 | QAbstractSeries* spline = new QSplineSeries(this); | |
187 | QAbstractSeries* pie = new QPieSeries(this); |
|
187 | QAbstractSeries* pie = new QPieSeries(this); | |
188 | QAbstractSeries* bar = new QAbstractBarSeries(this); |
|
188 | QAbstractSeries* bar = new QAbstractBarSeries(this); | |
189 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
189 | QAbstractSeries* percent = new QPercentBarSeries(this); | |
190 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
190 | QAbstractSeries* stacked = new QStackedBarSeries(this); | |
191 |
|
191 | |||
192 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
192 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
193 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
193 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |
194 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; |
|
194 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3; | |
195 |
|
195 | |||
196 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) |
|
196 | QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area) | |
197 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; |
|
197 | << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1; | |
198 |
|
198 | |||
199 | QList<QAbstractAxis*> axes0; |
|
199 | QList<QAbstractAxis*> axes0; | |
200 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); |
|
200 | axes0 << new QValuesAxis(this) << new QValuesAxis(this); | |
201 | axes0 << axes0.last(); |
|
201 | axes0 << axes0.last(); | |
202 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") |
|
202 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1") | |
203 | << (QList<QAbstractSeries*>() << line << spline << scatter) |
|
203 | << (QList<QAbstractSeries*>() << line << spline << scatter) | |
204 | << axes0 << 2; |
|
204 | << axes0 << 2; | |
205 | //TODO: add more test cases |
|
205 | //TODO: add more test cases | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | void tst_ChartDataSet::setAxisX() |
|
208 | void tst_ChartDataSet::setAxisX() | |
209 | { |
|
209 | { | |
210 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
210 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
211 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
211 | QFETCH(QList<QAbstractAxis*>, axisList); | |
212 | QFETCH(int, axisCount); |
|
212 | QFETCH(int, axisCount); | |
213 |
|
213 | |||
214 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
214 | Q_ASSERT(seriesList.count() == axisList.count()); | |
215 |
|
215 | |||
216 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
216 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
217 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
217 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
218 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
218 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
219 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
219 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
220 |
|
220 | |||
221 | foreach(QAbstractSeries* series, seriesList){ |
|
221 | foreach(QAbstractSeries* series, seriesList){ | |
222 | m_dataset->addSeries(series); |
|
222 | m_dataset->addSeries(series); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | TRY_COMPARE(spy0.count(), 0); |
|
225 | TRY_COMPARE(spy0.count(), 0); | |
226 | TRY_COMPARE(spy1.count(), 0); |
|
226 | TRY_COMPARE(spy1.count(), 0); | |
227 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
227 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
228 | TRY_COMPARE(spy3.count(), 0); |
|
228 | TRY_COMPARE(spy3.count(), 0); | |
229 |
|
229 | |||
230 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
230 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
231 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
231 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
232 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
232 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
233 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
233 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
234 |
|
234 | |||
235 | for(int i=0 ; i < seriesList.count(); i++){ |
|
235 | for(int i=0 ; i < seriesList.count(); i++){ | |
236 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); |
|
236 | m_dataset->setAxisX(seriesList.at(i),axisList.at(i)); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | TRY_COMPARE(spy4.count(), axisCount); |
|
239 | TRY_COMPARE(spy4.count(), axisCount); | |
240 | TRY_COMPARE(spy5.count(), 0); |
|
240 | TRY_COMPARE(spy5.count(), 0); | |
241 | TRY_COMPARE(spy6.count(), 0); |
|
241 | TRY_COMPARE(spy6.count(), 0); | |
242 | TRY_COMPARE(spy7.count(), 0); |
|
242 | TRY_COMPARE(spy7.count(), 0); | |
243 |
|
243 | |||
244 | for(int i=0 ; i < seriesList.count(); i++){ |
|
244 | for(int i=0 ; i < seriesList.count(); i++){ | |
245 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); |
|
245 | QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i)); | |
246 | } |
|
246 | } | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | void tst_ChartDataSet::setAxisY_data() |
|
249 | void tst_ChartDataSet::setAxisY_data() | |
250 | { |
|
250 | { | |
251 | setAxisX_data(); |
|
251 | setAxisX_data(); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void tst_ChartDataSet::setAxisY() |
|
254 | void tst_ChartDataSet::setAxisY() | |
255 | { |
|
255 | { | |
256 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
256 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
257 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
257 | QFETCH(QList<QAbstractAxis*>, axisList); | |
258 | QFETCH(int, axisCount); |
|
258 | QFETCH(int, axisCount); | |
259 |
|
259 | |||
260 | Q_ASSERT(seriesList.count() == axisList.count()); |
|
260 | Q_ASSERT(seriesList.count() == axisList.count()); | |
261 |
|
261 | |||
262 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
262 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
263 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
263 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
264 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
264 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
265 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
265 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
266 |
|
266 | |||
267 | foreach(QAbstractSeries* series, seriesList){ |
|
267 | foreach(QAbstractSeries* series, seriesList){ | |
268 | m_dataset->addSeries(series); |
|
268 | m_dataset->addSeries(series); | |
269 | } |
|
269 | } | |
270 |
|
270 | |||
271 | TRY_COMPARE(spy0.count(), 0); |
|
271 | TRY_COMPARE(spy0.count(), 0); | |
272 | TRY_COMPARE(spy1.count(), 0); |
|
272 | TRY_COMPARE(spy1.count(), 0); | |
273 | TRY_COMPARE(spy2.count(), seriesList.count()); |
|
273 | TRY_COMPARE(spy2.count(), seriesList.count()); | |
274 | TRY_COMPARE(spy3.count(), 0); |
|
274 | TRY_COMPARE(spy3.count(), 0); | |
275 |
|
275 | |||
276 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); |
|
276 | QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*))); | |
277 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
277 | QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
278 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); |
|
278 | QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*))); | |
279 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
279 | QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
280 |
|
280 | |||
281 | for(int i=0 ; i < seriesList.count(); i++){ |
|
281 | for(int i=0 ; i < seriesList.count(); i++){ | |
282 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); |
|
282 | m_dataset->setAxisY(seriesList.at(i),axisList.at(i)); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | TRY_COMPARE(spy4.count(), axisCount); |
|
285 | TRY_COMPARE(spy4.count(), axisCount); | |
286 | TRY_COMPARE(spy5.count(), 0); |
|
286 | TRY_COMPARE(spy5.count(), 0); | |
287 | TRY_COMPARE(spy6.count(), 0); |
|
287 | TRY_COMPARE(spy6.count(), 0); | |
288 | TRY_COMPARE(spy7.count(), 0); |
|
288 | TRY_COMPARE(spy7.count(), 0); | |
289 |
|
289 | |||
290 | for(int i=0 ; i < seriesList.count(); i++){ |
|
290 | for(int i=0 ; i < seriesList.count(); i++){ | |
291 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); |
|
291 | QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i)); | |
292 | } |
|
292 | } | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | void tst_ChartDataSet::removeSeries_data() |
|
295 | void tst_ChartDataSet::removeSeries_data() | |
296 | { |
|
296 | { | |
297 | addSeries_data(); |
|
297 | addSeries_data(); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void tst_ChartDataSet::removeSeries() |
|
300 | void tst_ChartDataSet::removeSeries() | |
301 | { |
|
301 | { | |
302 | QFETCH(QAbstractSeries*, series); |
|
302 | QFETCH(QAbstractSeries*, series); | |
303 |
|
303 | |||
304 | m_dataset->addSeries(series); |
|
304 | m_dataset->addSeries(series); | |
305 | m_dataset->createDefaultAxes(); |
|
305 | m_dataset->createDefaultAxes(); | |
306 |
|
306 | |||
307 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); |
|
307 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *))); | |
308 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); |
|
308 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*))); | |
309 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
309 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
310 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
310 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
311 |
|
311 | |||
312 | m_dataset->removeSeries(series); |
|
312 | m_dataset->removeSeries(series); | |
313 |
|
313 | |||
314 | TRY_COMPARE(spy0.count(), 0); |
|
314 | TRY_COMPARE(spy0.count(), 0); | |
315 | if (series->type() == QAbstractSeries::SeriesTypePie) { |
|
315 | if (series->type() == QAbstractSeries::SeriesTypePie) { | |
316 | TRY_COMPARE(spy1.count(), 0); |
|
316 | TRY_COMPARE(spy1.count(), 0); | |
317 | } |
|
317 | } | |
318 | else { |
|
318 | else { | |
319 | TRY_COMPARE(spy1.count(), 2); |
|
319 | TRY_COMPARE(spy1.count(), 2); | |
320 | } |
|
320 | } | |
321 | TRY_COMPARE(spy2.count(), 0); |
|
321 | TRY_COMPARE(spy2.count(), 0); | |
322 | TRY_COMPARE(spy3.count(), 1); |
|
322 | TRY_COMPARE(spy3.count(), 1); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | void tst_ChartDataSet::removeAllSeries_data() |
|
325 | void tst_ChartDataSet::removeAllSeries_data() | |
326 | { |
|
326 | { | |
327 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
327 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
328 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); |
|
328 | QTest::addColumn<QList<QAbstractAxis*> >("axisList"); | |
329 | QTest::addColumn<int>("axisCount"); |
|
329 | QTest::addColumn<int>("axisCount"); | |
330 |
|
330 | |||
331 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") |
|
331 | QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2") | |
332 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) |
|
332 | << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this) | |
333 | << new QScatterSeries(this)) |
|
333 | << new QScatterSeries(this)) | |
334 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) |
|
334 | << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) | |
335 | << new QValuesAxis(this)) << 3; |
|
335 | << new QValuesAxis(this)) << 3; | |
336 | //TODO: |
|
336 | //TODO: | |
337 | } |
|
337 | } | |
338 |
|
338 | |||
339 | void tst_ChartDataSet::removeAllSeries() |
|
339 | void tst_ChartDataSet::removeAllSeries() | |
340 | { |
|
340 | { | |
341 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
341 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
342 | QFETCH(QList<QAbstractAxis*>, axisList); |
|
342 | QFETCH(QList<QAbstractAxis*>, axisList); | |
343 | QFETCH(int, axisCount); |
|
343 | QFETCH(int, axisCount); | |
344 |
|
344 | |||
345 | foreach(QAbstractSeries* series, seriesList) { |
|
345 | foreach(QAbstractSeries* series, seriesList) { | |
346 | m_dataset->addSeries(series); |
|
346 | m_dataset->addSeries(series); | |
347 | } |
|
347 | } | |
348 |
|
348 | |||
349 | for (int i = 0; i < seriesList.count(); i++) { |
|
349 | for (int i = 0; i < seriesList.count(); i++) { | |
350 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); |
|
350 | m_dataset->setAxisX(seriesList.at(i), axisList.at(i)); | |
351 | } |
|
351 | } | |
352 |
|
352 | |||
353 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
353 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
354 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
354 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
355 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
355 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
356 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
356 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
357 |
|
357 | |||
358 | m_dataset->removeAllSeries(); |
|
358 | m_dataset->removeAllSeries(); | |
359 |
|
359 | |||
360 | TRY_COMPARE(spy0.count(), 0); |
|
360 | TRY_COMPARE(spy0.count(), 0); | |
361 | TRY_COMPARE(spy1.count(), axisCount); |
|
361 | TRY_COMPARE(spy1.count(), axisCount); | |
362 | TRY_COMPARE(spy2.count(), 0); |
|
362 | TRY_COMPARE(spy2.count(), 0); | |
363 | TRY_COMPARE(spy3.count(), seriesList.count()); |
|
363 | TRY_COMPARE(spy3.count(), seriesList.count()); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 |
|
366 | |||
367 | void tst_ChartDataSet::seriesCount_data() |
|
367 | void tst_ChartDataSet::seriesCount_data() | |
368 | { |
|
368 | { | |
369 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
369 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
370 | QTest::addColumn<int>("seriesCount"); |
|
370 | QTest::addColumn<int>("seriesCount"); | |
371 |
|
371 | |||
372 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; |
|
372 | QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3; | |
373 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; |
|
373 | QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2; | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | void tst_ChartDataSet::seriesCount() |
|
376 | void tst_ChartDataSet::seriesCount() | |
377 | { |
|
377 | { | |
378 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
378 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
379 | QFETCH(int, seriesCount); |
|
379 | QFETCH(int, seriesCount); | |
380 |
|
380 | |||
381 | foreach(QAbstractSeries* series, seriesList){ |
|
381 | foreach(QAbstractSeries* series, seriesList){ | |
382 | m_dataset->addSeries(series); |
|
382 | m_dataset->addSeries(series); | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
385 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
386 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
386 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
387 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
387 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
388 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
388 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
389 |
|
389 | |||
390 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); |
|
390 | QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount); | |
391 | TRY_COMPARE(spy0.count(), 0); |
|
391 | TRY_COMPARE(spy0.count(), 0); | |
392 | TRY_COMPARE(spy1.count(), 0); |
|
392 | TRY_COMPARE(spy1.count(), 0); | |
393 | TRY_COMPARE(spy2.count(), 0); |
|
393 | TRY_COMPARE(spy2.count(), 0); | |
394 | TRY_COMPARE(spy3.count(), 0); |
|
394 | TRY_COMPARE(spy3.count(), 0); | |
395 | } |
|
395 | } | |
396 |
|
396 | |||
397 | void tst_ChartDataSet::seriesIndex_data() |
|
397 | void tst_ChartDataSet::seriesIndex_data() | |
398 | { |
|
398 | { | |
399 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
399 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
400 |
|
400 | |||
401 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
401 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
402 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); |
|
402 | QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ); | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | void tst_ChartDataSet::seriesIndex() |
|
405 | void tst_ChartDataSet::seriesIndex() | |
406 | { |
|
406 | { | |
407 |
|
407 | |||
408 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
408 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
409 |
|
409 | |||
410 | foreach(QAbstractSeries* series, seriesList) { |
|
410 | foreach(QAbstractSeries* series, seriesList) { | |
411 | m_dataset->addSeries(series); |
|
411 | m_dataset->addSeries(series); | |
412 | } |
|
412 | } | |
413 |
|
413 | |||
414 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); |
|
414 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*))); | |
415 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
415 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
416 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); |
|
416 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*))); | |
417 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); |
|
417 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*))); | |
418 |
|
418 | |||
419 | for (int i = 0; i < seriesList.count(); i++) { |
|
419 | for (int i = 0; i < seriesList.count(); i++) { | |
420 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
420 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | TRY_COMPARE(spy0.count(), 0); |
|
423 | TRY_COMPARE(spy0.count(), 0); | |
424 | TRY_COMPARE(spy1.count(), 0); |
|
424 | TRY_COMPARE(spy1.count(), 0); | |
425 | TRY_COMPARE(spy2.count(), 0); |
|
425 | TRY_COMPARE(spy2.count(), 0); | |
426 | TRY_COMPARE(spy3.count(), 0); |
|
426 | TRY_COMPARE(spy3.count(), 0); | |
427 |
|
427 | |||
428 | foreach(QAbstractSeries* series, seriesList) { |
|
428 | foreach(QAbstractSeries* series, seriesList) { | |
429 | m_dataset->removeSeries(series); |
|
429 | m_dataset->removeSeries(series); | |
430 | } |
|
430 | } | |
431 |
|
431 | |||
432 | for (int i = 0; i < seriesList.count(); i++) { |
|
432 | for (int i = 0; i < seriesList.count(); i++) { | |
433 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
433 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | foreach(QAbstractSeries* series, seriesList) { |
|
436 | foreach(QAbstractSeries* series, seriesList) { | |
437 | m_dataset->addSeries(series); |
|
437 | m_dataset->addSeries(series); | |
438 | } |
|
438 | } | |
439 |
|
439 | |||
440 | for (int i = 0; i < seriesList.count(); i++) { |
|
440 | for (int i = 0; i < seriesList.count(); i++) { | |
441 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
441 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | m_dataset->removeSeries(seriesList.at(1)); |
|
444 | m_dataset->removeSeries(seriesList.at(1)); | |
445 |
|
445 | |||
446 | for (int i = 0; i < seriesList.count(); i++) { |
|
446 | for (int i = 0; i < seriesList.count(); i++) { | |
447 | if (i != 1) |
|
447 | if (i != 1) | |
448 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
448 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
449 | else |
|
449 | else | |
450 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
450 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
451 | } |
|
451 | } | |
452 |
|
452 | |||
453 | m_dataset->addSeries(seriesList.at(1)); |
|
453 | m_dataset->addSeries(seriesList.at(1)); | |
454 |
|
454 | |||
455 | for (int i = 0; i < seriesList.count(); i++) { |
|
455 | for (int i = 0; i < seriesList.count(); i++) { | |
456 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
456 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
457 | } |
|
457 | } | |
458 |
|
458 | |||
459 | m_dataset->removeSeries(seriesList.at(2)); |
|
459 | m_dataset->removeSeries(seriesList.at(2)); | |
460 |
|
460 | |||
461 | for (int i = 0; i < seriesList.count(); i++) { |
|
461 | for (int i = 0; i < seriesList.count(); i++) { | |
462 | if (i != 2) |
|
462 | if (i != 2) | |
463 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
463 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
464 | else |
|
464 | else | |
465 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
465 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
466 | } |
|
466 | } | |
467 |
|
467 | |||
468 | m_dataset->removeSeries(seriesList.at(0)); |
|
468 | m_dataset->removeSeries(seriesList.at(0)); | |
469 |
|
469 | |||
470 | for (int i = 0; i < seriesList.count(); i++) { |
|
470 | for (int i = 0; i < seriesList.count(); i++) { | |
471 | if (i != 2 && i != 0) |
|
471 | if (i != 2 && i != 0) | |
472 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
472 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
473 | else |
|
473 | else | |
474 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); |
|
474 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1); | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | m_dataset->addSeries(seriesList.at(2)); |
|
477 | m_dataset->addSeries(seriesList.at(2)); | |
478 | m_dataset->addSeries(seriesList.at(0)); |
|
478 | m_dataset->addSeries(seriesList.at(0)); | |
479 |
|
479 | |||
480 | for (int i = 0; i < seriesList.count(); i++) { |
|
480 | for (int i = 0; i < seriesList.count(); i++) { | |
481 | if (i == 2) |
|
481 | if (i == 2) | |
482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); |
|
482 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0); | |
483 | else if (i == 0) |
|
483 | else if (i == 0) | |
484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); |
|
484 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2); | |
485 | else |
|
485 | else | |
486 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); |
|
486 | QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i); | |
487 | } |
|
487 | } | |
488 |
|
488 | |||
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | void tst_ChartDataSet::domain_data() |
|
491 | void tst_ChartDataSet::domain_data() | |
492 | { |
|
492 | { | |
493 | addSeries_data(); |
|
493 | addSeries_data(); | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 | void tst_ChartDataSet::domain() |
|
496 | void tst_ChartDataSet::domain() | |
497 | { |
|
497 | { | |
498 | QFETCH(QAbstractSeries*, series); |
|
498 | QFETCH(QAbstractSeries*, series); | |
499 |
|
499 | |||
500 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); |
|
500 | QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *))); | |
501 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); |
|
501 | QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *))); | |
502 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); |
|
502 | QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *))); | |
503 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); |
|
503 | QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *))); | |
504 |
|
504 | |||
505 | m_dataset->addSeries(series); |
|
505 | m_dataset->addSeries(series); | |
506 | QVERIFY(m_dataset->domain(series)); |
|
506 | QVERIFY(m_dataset->domain(series)); | |
507 |
|
507 | |||
508 |
|
508 | |||
509 | TRY_COMPARE(spy0.count(), 0); |
|
509 | TRY_COMPARE(spy0.count(), 0); | |
510 | TRY_COMPARE(spy1.count(), 0); |
|
510 | TRY_COMPARE(spy1.count(), 0); | |
511 | TRY_COMPARE(spy2.count(), 1); |
|
511 | TRY_COMPARE(spy2.count(), 1); | |
512 |
|
512 | |||
513 | QList<QVariant> arguments = spy2.takeFirst(); |
|
513 | QList<QVariant> arguments = spy2.takeFirst(); | |
514 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); |
|
514 | Domain *domain = (Domain *) arguments.at(1).value<Domain *>(); | |
515 | QVERIFY(m_dataset->domain(series) == domain); |
|
515 | QVERIFY(m_dataset->domain(series) == domain); | |
516 |
|
516 | |||
517 | TRY_COMPARE(spy3.count(), 0); |
|
517 | TRY_COMPARE(spy3.count(), 0); | |
518 |
|
518 | |||
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 | void tst_ChartDataSet::zoomInDomain_data() |
|
521 | void tst_ChartDataSet::zoomInDomain_data() | |
522 | { |
|
522 | { | |
523 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); |
|
523 | QTest::addColumn<QList<QAbstractSeries*> >("seriesList"); | |
524 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); |
|
524 | QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ); | |
525 | } |
|
525 | } | |
526 |
|
526 | |||
527 | void tst_ChartDataSet::zoomInDomain() |
|
527 | void tst_ChartDataSet::zoomInDomain() | |
528 | { |
|
528 | { | |
529 | QFETCH(QList<QAbstractSeries*>, seriesList); |
|
529 | QFETCH(QList<QAbstractSeries*>, seriesList); | |
530 |
|
530 | |||
531 | foreach(QAbstractSeries* series, seriesList) { |
|
531 | foreach(QAbstractSeries* series, seriesList) { | |
532 | m_dataset->addSeries(series); |
|
532 | m_dataset->addSeries(series); | |
533 | } |
|
533 | } | |
534 |
|
534 | |||
535 | /* |
|
535 | /* | |
536 | QValuesAxis* axis = new QValuesAxis(); |
|
536 | QValuesAxis* axis = new QValuesAxis(); | |
537 |
|
537 | |||
538 | for (int i = 0; i < seriesList.count(); i++) { |
|
538 | for (int i = 0; i < seriesList.count(); i++) { | |
539 | m_dataset->setAxisX(seriesList.at(i), axis); |
|
539 | m_dataset->setAxisX(seriesList.at(i), axis); | |
540 | } |
|
540 | } | |
541 | */ |
|
541 | */ | |
542 | m_dataset->createDefaultAxes(); |
|
542 | m_dataset->createDefaultAxes(); | |
543 |
|
543 | |||
544 | QList<QSignalSpy*> spyList; |
|
544 | QList<QSignalSpy*> spyList; | |
545 |
|
545 | |||
546 | foreach(QAbstractSeries* series, seriesList) { |
|
546 | foreach(QAbstractSeries* series, seriesList) { | |
547 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
547 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
550 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); | |
551 |
|
551 | |||
552 | foreach(QSignalSpy* spy, spyList) { |
|
552 | foreach(QSignalSpy* spy, spyList) { | |
553 | TRY_COMPARE(spy->count(), 1); |
|
553 | TRY_COMPARE(spy->count(), 1); | |
554 | } |
|
554 | } | |
555 |
|
555 | |||
556 | qDeleteAll(spyList); |
|
556 | qDeleteAll(spyList); | |
557 | } |
|
557 | } | |
558 |
|
558 | |||
559 | /* |
|
559 | /* | |
560 | void tst_ChartDataSet::zoomOutDomain_data() |
|
560 | void tst_ChartDataSet::zoomOutDomain_data() | |
561 | { |
|
561 | { | |
562 | addSeries_data(); |
|
562 | addSeries_data(); | |
563 | } |
|
563 | } | |
564 |
|
564 | |||
565 | void tst_ChartDataSet::zoomOutDomain() |
|
565 | void tst_ChartDataSet::zoomOutDomain() | |
566 | { |
|
566 | { | |
567 | QFETCH(QLineSeries*, series0); |
|
567 | QFETCH(QLineSeries*, series0); | |
568 | QFETCH(QAxis*, axis0); |
|
568 | QFETCH(QAxis*, axis0); | |
569 | QFETCH(QLineSeries*, series1); |
|
569 | QFETCH(QLineSeries*, series1); | |
570 | QFETCH(QAxis*, axis1); |
|
570 | QFETCH(QAxis*, axis1); | |
571 | QFETCH(QLineSeries*, series2); |
|
571 | QFETCH(QLineSeries*, series2); | |
572 | QFETCH(QAxis*, axis2); |
|
572 | QFETCH(QAxis*, axis2); | |
573 | QFETCH(int, axisCount); |
|
573 | QFETCH(int, axisCount); | |
574 |
|
574 | |||
575 | Q_UNUSED(axisCount); |
|
575 | Q_UNUSED(axisCount); | |
576 |
|
576 | |||
577 | m_dataset->addSeries(series0, axis0); |
|
577 | m_dataset->addSeries(series0, axis0); | |
578 | m_dataset->addSeries(series1, axis1); |
|
578 | m_dataset->addSeries(series1, axis1); | |
579 | m_dataset->addSeries(series2, axis2); |
|
579 | m_dataset->addSeries(series2, axis2); | |
580 |
|
580 | |||
581 | Domain* domain0 = m_dataset->domain(series0); |
|
581 | Domain* domain0 = m_dataset->domain(series0); | |
582 | Domain* domain1 = m_dataset->domain(series1); |
|
582 | Domain* domain1 = m_dataset->domain(series1); | |
583 | Domain* domain2 = m_dataset->domain(series2); |
|
583 | Domain* domain2 = m_dataset->domain(series2); | |
584 |
|
584 | |||
585 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
585 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
586 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
586 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
587 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
587 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
588 |
|
588 | |||
589 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
589 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
590 |
|
590 | |||
591 | TRY_COMPARE(spy0.count(), 1); |
|
591 | TRY_COMPARE(spy0.count(), 1); | |
592 | TRY_COMPARE(spy1.count(), 1); |
|
592 | TRY_COMPARE(spy1.count(), 1); | |
593 | TRY_COMPARE(spy2.count(), 1); |
|
593 | TRY_COMPARE(spy2.count(), 1); | |
594 | } |
|
594 | } | |
595 |
|
595 | |||
596 | void tst_ChartDataSet::scrollDomain_data() |
|
596 | void tst_ChartDataSet::scrollDomain_data() | |
597 | { |
|
597 | { | |
598 | addSeries_data(); |
|
598 | addSeries_data(); | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | void tst_ChartDataSet::scrollDomain() |
|
601 | void tst_ChartDataSet::scrollDomain() | |
602 | { |
|
602 | { | |
603 | QFETCH(QLineSeries*, series0); |
|
603 | QFETCH(QLineSeries*, series0); | |
604 | QFETCH(QAxis*, axis0); |
|
604 | QFETCH(QAxis*, axis0); | |
605 | QFETCH(QLineSeries*, series1); |
|
605 | QFETCH(QLineSeries*, series1); | |
606 | QFETCH(QAxis*, axis1); |
|
606 | QFETCH(QAxis*, axis1); | |
607 | QFETCH(QLineSeries*, series2); |
|
607 | QFETCH(QLineSeries*, series2); | |
608 | QFETCH(QAxis*, axis2); |
|
608 | QFETCH(QAxis*, axis2); | |
609 | QFETCH(int, axisCount); |
|
609 | QFETCH(int, axisCount); | |
610 |
|
610 | |||
611 | Q_UNUSED(axisCount); |
|
611 | Q_UNUSED(axisCount); | |
612 |
|
612 | |||
613 | m_dataset->addSeries(series0, axis0); |
|
613 | m_dataset->addSeries(series0, axis0); | |
614 | m_dataset->addSeries(series1, axis1); |
|
614 | m_dataset->addSeries(series1, axis1); | |
615 | m_dataset->addSeries(series2, axis2); |
|
615 | m_dataset->addSeries(series2, axis2); | |
616 |
|
616 | |||
617 | Domain* domain0 = m_dataset->domain(series0); |
|
617 | Domain* domain0 = m_dataset->domain(series0); | |
618 | Domain* domain1 = m_dataset->domain(series1); |
|
618 | Domain* domain1 = m_dataset->domain(series1); | |
619 | Domain* domain2 = m_dataset->domain(series2); |
|
619 | Domain* domain2 = m_dataset->domain(series2); | |
620 |
|
620 | |||
621 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
621 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
622 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
622 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
623 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
623 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
624 |
|
624 | |||
625 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
625 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); | |
626 |
|
626 | |||
627 | TRY_COMPARE(spy0.count(), 1); |
|
627 | TRY_COMPARE(spy0.count(), 1); | |
628 | TRY_COMPARE(spy1.count(), 1); |
|
628 | TRY_COMPARE(spy1.count(), 1); | |
629 | TRY_COMPARE(spy2.count(), 1); |
|
629 | TRY_COMPARE(spy2.count(), 1); | |
630 | } |
|
630 | } | |
631 | */ |
|
631 | */ | |
632 | QTEST_MAIN(tst_ChartDataSet) |
|
632 | QTEST_MAIN(tst_ChartDataSet) | |
633 | #include "tst_chartdataset.moc" |
|
633 | #include "tst_chartdataset.moc" | |
634 |
|
634 |
@@ -1,577 +1,577 | |||||
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 <qabstractbarseries.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 "tst_definitions.h" |
|
26 | #include "tst_definitions.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QBarSet*) |
|
30 | Q_DECLARE_METATYPE(QBarSet*) | |
31 |
|
31 | |||
32 | class tst_QBarSeries : public QObject |
|
32 | class tst_QBarSeries : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 |
|
35 | |||
36 | public slots: |
|
36 | public slots: | |
37 | void initTestCase(); |
|
37 | void initTestCase(); | |
38 | void cleanupTestCase(); |
|
38 | void cleanupTestCase(); | |
39 | void init(); |
|
39 | void init(); | |
40 | void cleanup(); |
|
40 | void cleanup(); | |
41 |
|
41 | |||
42 | private slots: |
|
42 | private slots: | |
43 | void qbarseries_data(); |
|
43 | void qbarseries_data(); | |
44 | void qbarseries(); |
|
44 | void qbarseries(); | |
45 | void type_data(); |
|
45 | void type_data(); | |
46 | void type(); |
|
46 | void type(); | |
47 | void append_data(); |
|
47 | void append_data(); | |
48 | void append(); |
|
48 | void append(); | |
49 | void remove_data(); |
|
49 | void remove_data(); | |
50 | void remove(); |
|
50 | void remove(); | |
51 | void appendList_data(); |
|
51 | void appendList_data(); | |
52 | void appendList(); |
|
52 | void appendList(); | |
53 | void count_data(); |
|
53 | void count_data(); | |
54 | void count(); |
|
54 | void count(); | |
55 | void barSets_data(); |
|
55 | void barSets_data(); | |
56 | void barSets(); |
|
56 | void barSets(); | |
57 | void setLabelsVisible_data(); |
|
57 | void setLabelsVisible_data(); | |
58 | void setLabelsVisible(); |
|
58 | void setLabelsVisible(); | |
59 | void mouseclicked_data(); |
|
59 | void mouseclicked_data(); | |
60 | void mouseclicked(); |
|
60 | void mouseclicked(); | |
61 | void mousehovered_data(); |
|
61 | void mousehovered_data(); | |
62 | void mousehovered(); |
|
62 | void mousehovered(); | |
63 | void clearWithAnimations(); |
|
63 | void clearWithAnimations(); | |
64 |
|
64 | |||
65 | private: |
|
65 | private: | |
66 | QAbstractBarSeries* m_barseries; |
|
66 | QAbstractBarSeries* m_barseries; | |
67 | QAbstractBarSeries* m_barseries_with_sets; |
|
67 | QAbstractBarSeries* m_barseries_with_sets; | |
68 |
|
68 | |||
69 | QList<QBarSet*> m_testSets; |
|
69 | QList<QBarSet*> m_testSets; | |
70 |
|
70 | |||
71 | }; |
|
71 | }; | |
72 |
|
72 | |||
73 | void tst_QBarSeries::initTestCase() |
|
73 | void tst_QBarSeries::initTestCase() | |
74 | { |
|
74 | { | |
75 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
75 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void tst_QBarSeries::cleanupTestCase() |
|
78 | void tst_QBarSeries::cleanupTestCase() | |
79 | { |
|
79 | { | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void tst_QBarSeries::init() |
|
82 | void tst_QBarSeries::init() | |
83 | { |
|
83 | { | |
84 | m_barseries = new QAbstractBarSeries(); |
|
84 | m_barseries = new QAbstractBarSeries(); | |
85 | m_barseries_with_sets = new QAbstractBarSeries(); |
|
85 | m_barseries_with_sets = new QAbstractBarSeries(); | |
86 |
|
86 | |||
87 | for (int i=0; i<5; i++) { |
|
87 | for (int i=0; i<5; i++) { | |
88 | m_testSets.append(new QBarSet("testset")); |
|
88 | m_testSets.append(new QBarSet("testset")); | |
89 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
89 | m_barseries_with_sets->append(m_testSets.at(i)); | |
90 | } |
|
90 | } | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | void tst_QBarSeries::cleanup() |
|
93 | void tst_QBarSeries::cleanup() | |
94 | { |
|
94 | { | |
95 | foreach(QBarSet* s, m_testSets) { |
|
95 | foreach(QBarSet* s, m_testSets) { | |
96 | m_barseries_with_sets->remove(s); |
|
96 | m_barseries_with_sets->remove(s); | |
97 | delete s; |
|
97 | delete s; | |
98 | } |
|
98 | } | |
99 | m_testSets.clear(); |
|
99 | m_testSets.clear(); | |
100 |
|
100 | |||
101 | delete m_barseries; |
|
101 | delete m_barseries; | |
102 | m_barseries = 0; |
|
102 | m_barseries = 0; | |
103 | delete m_barseries_with_sets; |
|
103 | delete m_barseries_with_sets; | |
104 | m_barseries_with_sets = 0; |
|
104 | m_barseries_with_sets = 0; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_QBarSeries::qbarseries_data() |
|
107 | void tst_QBarSeries::qbarseries_data() | |
108 | { |
|
108 | { | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void tst_QBarSeries::qbarseries() |
|
111 | void tst_QBarSeries::qbarseries() | |
112 | { |
|
112 | { | |
113 | QAbstractBarSeries *barseries = new QAbstractBarSeries(); |
|
113 | QAbstractBarSeries *barseries = new QAbstractBarSeries(); | |
114 | QVERIFY(barseries != 0); |
|
114 | QVERIFY(barseries != 0); | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | void tst_QBarSeries::type_data() |
|
117 | void tst_QBarSeries::type_data() | |
118 | { |
|
118 | { | |
119 |
|
119 | |||
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void tst_QBarSeries::type() |
|
122 | void tst_QBarSeries::type() | |
123 | { |
|
123 | { | |
124 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
124 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void tst_QBarSeries::append_data() |
|
127 | void tst_QBarSeries::append_data() | |
128 | { |
|
128 | { | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | void tst_QBarSeries::append() |
|
131 | void tst_QBarSeries::append() | |
132 | { |
|
132 | { | |
133 | QVERIFY(m_barseries->count() == 0); |
|
133 | QVERIFY(m_barseries->count() == 0); | |
134 |
|
134 | |||
135 | bool ret = false; |
|
135 | bool ret = false; | |
136 |
|
136 | |||
137 | // Try adding barset |
|
137 | // Try adding barset | |
138 | QBarSet *barset = new QBarSet("testset"); |
|
138 | QBarSet *barset = new QBarSet("testset"); | |
139 | ret = m_barseries->append(barset); |
|
139 | ret = m_barseries->append(barset); | |
140 |
|
140 | |||
141 | QVERIFY(ret == true); |
|
141 | QVERIFY(ret == true); | |
142 | QVERIFY(m_barseries->count() == 1); |
|
142 | QVERIFY(m_barseries->count() == 1); | |
143 |
|
143 | |||
144 | // Try adding another set |
|
144 | // Try adding another set | |
145 | QBarSet *barset2 = new QBarSet("testset2"); |
|
145 | QBarSet *barset2 = new QBarSet("testset2"); | |
146 | ret = m_barseries->append(barset2); |
|
146 | ret = m_barseries->append(barset2); | |
147 |
|
147 | |||
148 | QVERIFY(ret == true); |
|
148 | QVERIFY(ret == true); | |
149 | QVERIFY(m_barseries->count() == 2); |
|
149 | QVERIFY(m_barseries->count() == 2); | |
150 |
|
150 | |||
151 | // Try adding same set again |
|
151 | // Try adding same set again | |
152 | ret = m_barseries->append(barset2); |
|
152 | ret = m_barseries->append(barset2); | |
153 | QVERIFY(ret == false); |
|
153 | QVERIFY(ret == false); | |
154 | QVERIFY(m_barseries->count() == 2); |
|
154 | QVERIFY(m_barseries->count() == 2); | |
155 |
|
155 | |||
156 | // Try adding null set |
|
156 | // Try adding null set | |
157 | ret = m_barseries->append(0); |
|
157 | ret = m_barseries->append(0); | |
158 | QVERIFY(ret == false); |
|
158 | QVERIFY(ret == false); | |
159 | QVERIFY(m_barseries->count() == 2); |
|
159 | QVERIFY(m_barseries->count() == 2); | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | void tst_QBarSeries::remove_data() |
|
163 | void tst_QBarSeries::remove_data() | |
164 | { |
|
164 | { | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | void tst_QBarSeries::remove() |
|
167 | void tst_QBarSeries::remove() | |
168 | { |
|
168 | { | |
169 | int count = m_testSets.count(); |
|
169 | int count = m_testSets.count(); | |
170 | QVERIFY(m_barseries_with_sets->count() == count); |
|
170 | QVERIFY(m_barseries_with_sets->count() == count); | |
171 |
|
171 | |||
172 | // Try to remove null pointer (should not remove, should not crash) |
|
172 | // Try to remove null pointer (should not remove, should not crash) | |
173 | bool ret = false; |
|
173 | bool ret = false; | |
174 | ret = m_barseries_with_sets->remove(0); |
|
174 | ret = m_barseries_with_sets->remove(0); | |
175 | QVERIFY(ret == false); |
|
175 | QVERIFY(ret == false); | |
176 | QVERIFY(m_barseries_with_sets->count() == count); |
|
176 | QVERIFY(m_barseries_with_sets->count() == count); | |
177 |
|
177 | |||
178 | // Try to remove invalid pointer (should not remove, should not crash) |
|
178 | // Try to remove invalid pointer (should not remove, should not crash) | |
179 | 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) ); | |
180 | QVERIFY(ret == false); |
|
180 | QVERIFY(ret == false); | |
181 | QVERIFY(m_barseries_with_sets->count() == count); |
|
181 | QVERIFY(m_barseries_with_sets->count() == count); | |
182 |
|
182 | |||
183 | // remove some sets |
|
183 | // remove some sets | |
184 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
184 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); | |
185 | QVERIFY(ret == true); |
|
185 | QVERIFY(ret == true); | |
186 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
186 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); | |
187 | QVERIFY(ret == true); |
|
187 | QVERIFY(ret == true); | |
188 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
188 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); | |
189 | QVERIFY(ret == true); |
|
189 | QVERIFY(ret == true); | |
190 |
|
190 | |||
191 | QVERIFY(m_barseries_with_sets->count() == 2); |
|
191 | QVERIFY(m_barseries_with_sets->count() == 2); | |
192 |
|
192 | |||
193 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
193 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
194 |
|
194 | |||
195 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
195 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
196 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
196 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
197 |
|
197 | |||
198 | // 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) | |
199 | ret = false; |
|
199 | ret = false; | |
200 | for (int i=0; i<count; i++) { |
|
200 | for (int i=0; i<count; i++) { | |
201 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
201 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | QVERIFY(ret == true); |
|
204 | QVERIFY(ret == true); | |
205 | QVERIFY(m_barseries_with_sets->count() == 0); |
|
205 | QVERIFY(m_barseries_with_sets->count() == 0); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | void tst_QBarSeries::appendList_data() |
|
208 | void tst_QBarSeries::appendList_data() | |
209 | { |
|
209 | { | |
210 |
|
210 | |||
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void tst_QBarSeries::appendList() |
|
213 | void tst_QBarSeries::appendList() | |
214 | { |
|
214 | { | |
215 | int count = 5; |
|
215 | int count = 5; | |
216 | QVERIFY(m_barseries->count() == 0); |
|
216 | QVERIFY(m_barseries->count() == 0); | |
217 |
|
217 | |||
218 | QList<QBarSet*> sets; |
|
218 | QList<QBarSet*> sets; | |
219 | for (int i=0; i<count; i++) { |
|
219 | for (int i=0; i<count; i++) { | |
220 | sets.append(new QBarSet("testset")); |
|
220 | sets.append(new QBarSet("testset")); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | // 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) | |
224 | bool ret = false; |
|
224 | bool ret = false; | |
225 | ret = m_barseries->append(sets); |
|
225 | ret = m_barseries->append(sets); | |
226 | QVERIFY(ret == true); |
|
226 | QVERIFY(ret == true); | |
227 | QVERIFY(m_barseries->count() == count); |
|
227 | QVERIFY(m_barseries->count() == count); | |
228 |
|
228 | |||
229 | // Append same sets again (should fail, count should remain same) |
|
229 | // Append same sets again (should fail, count should remain same) | |
230 | ret = m_barseries->append(sets); |
|
230 | ret = m_barseries->append(sets); | |
231 | QVERIFY(ret == false); |
|
231 | QVERIFY(ret == false); | |
232 | QVERIFY(m_barseries->count() == count); |
|
232 | QVERIFY(m_barseries->count() == count); | |
233 |
|
233 | |||
234 | // Try append empty list (should succeed, but count should remain same) |
|
234 | // Try append empty list (should succeed, but count should remain same) | |
235 | QList<QBarSet*> invalidList; |
|
235 | QList<QBarSet*> invalidList; | |
236 | ret = m_barseries->append(invalidList); |
|
236 | ret = m_barseries->append(invalidList); | |
237 | QVERIFY(ret == true); |
|
237 | QVERIFY(ret == true); | |
238 | QVERIFY(m_barseries->count() == count); |
|
238 | QVERIFY(m_barseries->count() == count); | |
239 |
|
239 | |||
240 | // 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) | |
241 | invalidList.append(new QBarSet("ok set")); |
|
241 | invalidList.append(new QBarSet("ok set")); | |
242 | invalidList.append(sets.at(0)); |
|
242 | invalidList.append(sets.at(0)); | |
243 | ret = m_barseries->append(invalidList); |
|
243 | ret = m_barseries->append(invalidList); | |
244 | QVERIFY(ret == false); |
|
244 | QVERIFY(ret == false); | |
245 | QVERIFY(m_barseries->count() == count); |
|
245 | QVERIFY(m_barseries->count() == count); | |
246 |
|
246 | |||
247 | // Try append list with null pointers (should fail, count remains same) |
|
247 | // Try append list with null pointers (should fail, count remains same) | |
248 | QList<QBarSet*> invalidList2; |
|
248 | QList<QBarSet*> invalidList2; | |
249 | invalidList2.append(0); |
|
249 | invalidList2.append(0); | |
250 | invalidList2.append(0); |
|
250 | invalidList2.append(0); | |
251 | invalidList2.append(0); |
|
251 | invalidList2.append(0); | |
252 | ret = m_barseries->append(invalidList2); |
|
252 | ret = m_barseries->append(invalidList2); | |
253 | QVERIFY(ret == false); |
|
253 | QVERIFY(ret == false); | |
254 | QVERIFY(m_barseries->count() == count); |
|
254 | QVERIFY(m_barseries->count() == count); | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | void tst_QBarSeries::count_data() |
|
257 | void tst_QBarSeries::count_data() | |
258 | { |
|
258 | { | |
259 |
|
259 | |||
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void tst_QBarSeries::count() |
|
262 | void tst_QBarSeries::count() | |
263 | { |
|
263 | { | |
264 | QVERIFY(m_barseries->count() == 0); |
|
264 | QVERIFY(m_barseries->count() == 0); | |
265 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); |
|
265 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void tst_QBarSeries::barSets_data() |
|
268 | void tst_QBarSeries::barSets_data() | |
269 | { |
|
269 | { | |
270 |
|
270 | |||
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | void tst_QBarSeries::barSets() |
|
273 | void tst_QBarSeries::barSets() | |
274 | { |
|
274 | { | |
275 | QVERIFY(m_barseries->barSets().count() == 0); |
|
275 | QVERIFY(m_barseries->barSets().count() == 0); | |
276 |
|
276 | |||
277 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
277 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
278 | QVERIFY(sets.count() == m_testSets.count()); |
|
278 | QVERIFY(sets.count() == m_testSets.count()); | |
279 |
|
279 | |||
280 | for (int i=0; i<m_testSets.count(); i++) { |
|
280 | for (int i=0; i<m_testSets.count(); i++) { | |
281 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
281 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
282 | } |
|
282 | } | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | void tst_QBarSeries::setLabelsVisible_data() |
|
285 | void tst_QBarSeries::setLabelsVisible_data() | |
286 | { |
|
286 | { | |
287 |
|
287 | |||
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | void tst_QBarSeries::setLabelsVisible() |
|
290 | void tst_QBarSeries::setLabelsVisible() | |
291 | { |
|
291 | { | |
292 | // labels should be invisible by default |
|
292 | // labels should be invisible by default | |
293 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
293 | QVERIFY(m_barseries->isLabelsVisible() == false); | |
294 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
294 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
295 |
|
295 | |||
296 | // turn labels to visible |
|
296 | // turn labels to visible | |
297 | m_barseries_with_sets->setLabelsVisible(true); |
|
297 | m_barseries_with_sets->setLabelsVisible(true); | |
298 | // TODO: test the signal |
|
298 | // TODO: test the signal | |
299 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
299 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
300 |
|
300 | |||
301 | // turn labels to invisible |
|
301 | // turn labels to invisible | |
302 | m_barseries_with_sets->setLabelsVisible(false); |
|
302 | m_barseries_with_sets->setLabelsVisible(false); | |
303 | // TODO: test the signal |
|
303 | // TODO: test the signal | |
304 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
304 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
305 |
|
305 | |||
306 | // without parameter, should turn labels to visible |
|
306 | // without parameter, should turn labels to visible | |
307 | m_barseries_with_sets->setLabelsVisible(); |
|
307 | m_barseries_with_sets->setLabelsVisible(); | |
308 | // TODO: test the signal |
|
308 | // TODO: test the signal | |
309 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
309 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
310 | } |
|
310 | } | |
311 |
|
311 | |||
312 | void tst_QBarSeries::mouseclicked_data() |
|
312 | void tst_QBarSeries::mouseclicked_data() | |
313 | { |
|
313 | { | |
314 |
|
314 | |||
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | void tst_QBarSeries::mouseclicked() |
|
317 | void tst_QBarSeries::mouseclicked() | |
318 | { |
|
318 | { | |
319 | QAbstractBarSeries* series = new QAbstractBarSeries(); |
|
319 | QAbstractBarSeries* series = new QAbstractBarSeries(); | |
320 |
|
320 | |||
321 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
321 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
322 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
322 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
323 | *set1 << 10 << 10 << 10; |
|
323 | *set1 << 10 << 10 << 10; | |
324 | series->append(set1); |
|
324 | series->append(set1); | |
325 |
|
325 | |||
326 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
326 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
327 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
327 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
328 | *set2 << 10 << 10 << 10; |
|
328 | *set2 << 10 << 10 << 10; | |
329 | series->append(set2); |
|
329 | series->append(set2); | |
330 |
|
330 | |||
331 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); |
|
331 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); | |
332 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); |
|
332 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); | |
333 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); |
|
333 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); | |
334 |
|
334 | |||
335 | QChartView view(new QChart()); |
|
335 | QChartView view(new QChart()); | |
336 | view.resize(400,300); |
|
336 | view.resize(400,300); | |
337 | view.chart()->addSeries(series); |
|
337 | view.chart()->addSeries(series); | |
338 | view.show(); |
|
338 | view.show(); | |
339 | QTest::qWaitForWindowShown(&view); |
|
339 | QTest::qWaitForWindowShown(&view); | |
340 |
|
340 | |||
341 | //==================================================================================== |
|
341 | //==================================================================================== | |
342 | // barset 1, bar 0 |
|
342 | // barset 1, bar 0 | |
343 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); |
|
343 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142)); | |
344 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
344 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
345 |
|
345 | |||
346 | QCOMPARE(seriesSpy.count(), 1); |
|
346 | QCOMPARE(seriesSpy.count(), 1); | |
347 | QCOMPARE(setSpy1.count(), 1); |
|
347 | QCOMPARE(setSpy1.count(), 1); | |
348 | QCOMPARE(setSpy2.count(), 0); |
|
348 | QCOMPARE(setSpy2.count(), 0); | |
349 |
|
349 | |||
350 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
350 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
351 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
351 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
352 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
352 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
353 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
353 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
354 |
|
354 | |||
355 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
355 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
356 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
356 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
357 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
357 | QVERIFY(setSpyArg.at(0).toInt() == 0); | |
358 |
|
358 | |||
359 | //==================================================================================== |
|
359 | //==================================================================================== | |
360 | // barset 1, bar 1 |
|
360 | // barset 1, bar 1 | |
361 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); |
|
361 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142)); | |
362 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
362 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
363 |
|
363 | |||
364 | QCOMPARE(seriesSpy.count(), 1); |
|
364 | QCOMPARE(seriesSpy.count(), 1); | |
365 | QCOMPARE(setSpy1.count(), 1); |
|
365 | QCOMPARE(setSpy1.count(), 1); | |
366 | QCOMPARE(setSpy2.count(), 0); |
|
366 | QCOMPARE(setSpy2.count(), 0); | |
367 |
|
367 | |||
368 | seriesSpyArg = seriesSpy.takeFirst(); |
|
368 | seriesSpyArg = seriesSpy.takeFirst(); | |
369 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
369 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
370 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
370 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
371 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
371 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
372 |
|
372 | |||
373 | setSpyArg = setSpy1.takeFirst(); |
|
373 | setSpyArg = setSpy1.takeFirst(); | |
374 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
374 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
375 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
375 | QVERIFY(setSpyArg.at(0).toInt() == 1); | |
376 |
|
376 | |||
377 | //==================================================================================== |
|
377 | //==================================================================================== | |
378 | // barset 1, bar 2 |
|
378 | // barset 1, bar 2 | |
379 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); |
|
379 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142)); | |
380 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
380 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
381 |
|
381 | |||
382 | QCOMPARE(seriesSpy.count(), 1); |
|
382 | QCOMPARE(seriesSpy.count(), 1); | |
383 | QCOMPARE(setSpy1.count(), 1); |
|
383 | QCOMPARE(setSpy1.count(), 1); | |
384 | QCOMPARE(setSpy2.count(), 0); |
|
384 | QCOMPARE(setSpy2.count(), 0); | |
385 |
|
385 | |||
386 | seriesSpyArg = seriesSpy.takeFirst(); |
|
386 | seriesSpyArg = seriesSpy.takeFirst(); | |
387 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
387 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
388 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
388 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
389 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
389 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
390 |
|
390 | |||
391 | setSpyArg = setSpy1.takeFirst(); |
|
391 | setSpyArg = setSpy1.takeFirst(); | |
392 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
392 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
393 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
393 | QVERIFY(setSpyArg.at(0).toInt() == 2); | |
394 |
|
394 | |||
395 | //==================================================================================== |
|
395 | //==================================================================================== | |
396 | // barset 2, bar 0 |
|
396 | // barset 2, bar 0 | |
397 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); |
|
397 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142)); | |
398 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
398 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
399 |
|
399 | |||
400 | QCOMPARE(seriesSpy.count(), 1); |
|
400 | QCOMPARE(seriesSpy.count(), 1); | |
401 | QCOMPARE(setSpy1.count(), 0); |
|
401 | QCOMPARE(setSpy1.count(), 0); | |
402 | QCOMPARE(setSpy2.count(), 1); |
|
402 | QCOMPARE(setSpy2.count(), 1); | |
403 |
|
403 | |||
404 | seriesSpyArg = seriesSpy.takeFirst(); |
|
404 | seriesSpyArg = seriesSpy.takeFirst(); | |
405 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
405 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
406 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
406 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
407 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
407 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
408 |
|
408 | |||
409 | setSpyArg = setSpy2.takeFirst(); |
|
409 | setSpyArg = setSpy2.takeFirst(); | |
410 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
410 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
411 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
411 | QVERIFY(setSpyArg.at(0).toInt() == 0); | |
412 |
|
412 | |||
413 | //==================================================================================== |
|
413 | //==================================================================================== | |
414 | // barset 2, bar 1 |
|
414 | // barset 2, bar 1 | |
415 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); |
|
415 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142)); | |
416 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
416 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
417 |
|
417 | |||
418 | QCOMPARE(seriesSpy.count(), 1); |
|
418 | QCOMPARE(seriesSpy.count(), 1); | |
419 | QCOMPARE(setSpy1.count(), 0); |
|
419 | QCOMPARE(setSpy1.count(), 0); | |
420 | QCOMPARE(setSpy2.count(), 1); |
|
420 | QCOMPARE(setSpy2.count(), 1); | |
421 |
|
421 | |||
422 | seriesSpyArg = seriesSpy.takeFirst(); |
|
422 | seriesSpyArg = seriesSpy.takeFirst(); | |
423 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
423 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
424 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
424 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
425 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
425 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
426 |
|
426 | |||
427 | setSpyArg = setSpy2.takeFirst(); |
|
427 | setSpyArg = setSpy2.takeFirst(); | |
428 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
428 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
429 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
429 | QVERIFY(setSpyArg.at(0).toInt() == 1); | |
430 |
|
430 | |||
431 | //==================================================================================== |
|
431 | //==================================================================================== | |
432 | // barset 2, bar 2 |
|
432 | // barset 2, bar 2 | |
433 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); |
|
433 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142)); | |
434 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
434 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
435 |
|
435 | |||
436 | QCOMPARE(seriesSpy.count(), 1); |
|
436 | QCOMPARE(seriesSpy.count(), 1); | |
437 | QCOMPARE(setSpy1.count(), 0); |
|
437 | QCOMPARE(setSpy1.count(), 0); | |
438 | QCOMPARE(setSpy2.count(), 1); |
|
438 | QCOMPARE(setSpy2.count(), 1); | |
439 |
|
439 | |||
440 | seriesSpyArg = seriesSpy.takeFirst(); |
|
440 | seriesSpyArg = seriesSpy.takeFirst(); | |
441 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
441 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
442 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
442 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
443 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
443 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
444 |
|
444 | |||
445 | setSpyArg = setSpy2.takeFirst(); |
|
445 | setSpyArg = setSpy2.takeFirst(); | |
446 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
446 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
447 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
447 | QVERIFY(setSpyArg.at(0).toInt() == 2); | |
448 | } |
|
448 | } | |
449 |
|
449 | |||
450 | void tst_QBarSeries::mousehovered_data() |
|
450 | void tst_QBarSeries::mousehovered_data() | |
451 | { |
|
451 | { | |
452 |
|
452 | |||
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | void tst_QBarSeries::mousehovered() |
|
455 | void tst_QBarSeries::mousehovered() | |
456 | { |
|
456 | { | |
457 | QAbstractBarSeries* series = new QAbstractBarSeries(); |
|
457 | QAbstractBarSeries* series = new QAbstractBarSeries(); | |
458 |
|
458 | |||
459 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
459 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
460 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
460 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
461 | *set1 << 10 << 10 << 10; |
|
461 | *set1 << 10 << 10 << 10; | |
462 | series->append(set1); |
|
462 | series->append(set1); | |
463 |
|
463 | |||
464 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
464 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
465 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
465 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
466 | *set2 << 10 << 10 << 10; |
|
466 | *set2 << 10 << 10 << 10; | |
467 | series->append(set2); |
|
467 | series->append(set2); | |
468 |
|
468 | |||
469 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); |
|
469 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); | |
470 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); |
|
470 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); | |
471 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); |
|
471 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); | |
472 |
|
472 | |||
473 | QChartView view(new QChart()); |
|
473 | QChartView view(new QChart()); | |
474 | view.resize(400,300); |
|
474 | view.resize(400,300); | |
475 | view.chart()->addSeries(series); |
|
475 | view.chart()->addSeries(series); | |
476 | view.show(); |
|
476 | view.show(); | |
477 | QTest::qWaitForWindowShown(&view); |
|
477 | QTest::qWaitForWindowShown(&view); | |
478 |
|
478 | |||
479 | //this is hack since view does not get events otherwise |
|
479 | //this is hack since view does not get events otherwise | |
480 | view.setMouseTracking(true); |
|
480 | view.setMouseTracking(true); | |
481 |
|
481 | |||
482 | //======================================================================= |
|
482 | //======================================================================= | |
483 | // move mouse to left border |
|
483 | // move mouse to left border | |
484 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); |
|
484 | QTest::mouseMove(view.viewport(), QPoint(0, 142)); | |
485 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
485 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | |
486 | TRY_COMPARE(seriesSpy.count(), 0); |
|
486 | TRY_COMPARE(seriesSpy.count(), 0); | |
487 | TRY_COMPARE(setSpy1.count(), 0); |
|
487 | TRY_COMPARE(setSpy1.count(), 0); | |
488 | TRY_COMPARE(setSpy2.count(), 0); |
|
488 | TRY_COMPARE(setSpy2.count(), 0); | |
489 |
|
489 | |||
490 | //======================================================================= |
|
490 | //======================================================================= | |
491 | // move mouse on top of set1 |
|
491 | // move mouse on top of set1 | |
492 | QTest::mouseMove(view.viewport(), QPoint(102,142)); |
|
492 | QTest::mouseMove(view.viewport(), QPoint(102,142)); | |
493 | TRY_COMPARE(seriesSpy.count(), 1); |
|
493 | TRY_COMPARE(seriesSpy.count(), 1); | |
494 | TRY_COMPARE(setSpy1.count(), 1); |
|
494 | TRY_COMPARE(setSpy1.count(), 1); | |
495 | TRY_COMPARE(setSpy2.count(), 0); |
|
495 | TRY_COMPARE(setSpy2.count(), 0); | |
496 |
|
496 | |||
497 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
497 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
498 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
498 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
499 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
499 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
500 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
500 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
501 |
|
501 | |||
502 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
502 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
503 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
503 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
504 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
504 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
505 |
|
505 | |||
506 | //======================================================================= |
|
506 | //======================================================================= | |
507 | // move mouse from top of set1 to top of set2 |
|
507 | // move mouse from top of set1 to top of set2 | |
508 | QTest::mouseMove(view.viewport(), QPoint(127,142)); |
|
508 | QTest::mouseMove(view.viewport(), QPoint(127,142)); | |
509 | TRY_COMPARE(seriesSpy.count(), 2); |
|
509 | TRY_COMPARE(seriesSpy.count(), 2); | |
510 | TRY_COMPARE(setSpy1.count(), 1); |
|
510 | TRY_COMPARE(setSpy1.count(), 1); | |
511 | TRY_COMPARE(setSpy2.count(), 1); |
|
511 | TRY_COMPARE(setSpy2.count(), 1); | |
512 |
|
512 | |||
513 | // should leave set1 |
|
513 | // should leave set1 | |
514 | seriesSpyArg = seriesSpy.takeFirst(); |
|
514 | seriesSpyArg = seriesSpy.takeFirst(); | |
515 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
515 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
516 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
516 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
517 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
517 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
518 |
|
518 | |||
519 | setSpyArg = setSpy1.takeFirst(); |
|
519 | setSpyArg = setSpy1.takeFirst(); | |
520 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
520 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
521 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
521 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
522 |
|
522 | |||
523 | // should enter set2 |
|
523 | // should enter set2 | |
524 | seriesSpyArg = seriesSpy.takeFirst(); |
|
524 | seriesSpyArg = seriesSpy.takeFirst(); | |
525 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
525 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
526 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
526 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
527 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
527 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
528 |
|
528 | |||
529 | setSpyArg = setSpy2.takeFirst(); |
|
529 | setSpyArg = setSpy2.takeFirst(); | |
530 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
530 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
531 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
531 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
532 |
|
532 | |||
533 | //======================================================================= |
|
533 | //======================================================================= | |
534 | // move mouse from top of set2 to background |
|
534 | // move mouse from top of set2 to background | |
535 | QTest::mouseMove(view.viewport(), QPoint(127,0)); |
|
535 | QTest::mouseMove(view.viewport(), QPoint(127,0)); | |
536 | TRY_COMPARE(seriesSpy.count(), 1); |
|
536 | TRY_COMPARE(seriesSpy.count(), 1); | |
537 | TRY_COMPARE(setSpy1.count(), 0); |
|
537 | TRY_COMPARE(setSpy1.count(), 0); | |
538 | TRY_COMPARE(setSpy2.count(), 1); |
|
538 | TRY_COMPARE(setSpy2.count(), 1); | |
539 |
|
539 | |||
540 | // should leave set2 |
|
540 | // should leave set2 | |
541 | seriesSpyArg = seriesSpy.takeFirst(); |
|
541 | seriesSpyArg = seriesSpy.takeFirst(); | |
542 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
542 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
543 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
543 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
544 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
544 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
545 |
|
545 | |||
546 | setSpyArg = setSpy2.takeFirst(); |
|
546 | setSpyArg = setSpy2.takeFirst(); | |
547 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
547 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
548 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
548 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
549 | } |
|
549 | } | |
550 |
|
550 | |||
551 | void tst_QBarSeries::clearWithAnimations() |
|
551 | void tst_QBarSeries::clearWithAnimations() | |
552 | { |
|
552 | { | |
553 | QAbstractBarSeries* series = new QAbstractBarSeries(); |
|
553 | QAbstractBarSeries* series = new QAbstractBarSeries(); | |
554 |
|
554 | |||
555 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
555 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
556 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); |
|
556 | // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10); | |
557 | *set1 << 10 << 10 << 10; |
|
557 | *set1 << 10 << 10 << 10; | |
558 | series->append(set1); |
|
558 | series->append(set1); | |
559 |
|
559 | |||
560 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
560 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
561 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); |
|
561 | // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10); | |
562 | *set2 << 10 << 10 << 10; |
|
562 | *set2 << 10 << 10 << 10; | |
563 | series->append(set2); |
|
563 | series->append(set2); | |
564 |
|
564 | |||
565 | QChartView view(new QChart()); |
|
565 | QChartView view(new QChart()); | |
566 | view.resize(400,300); |
|
566 | view.resize(400,300); | |
567 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); |
|
567 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); | |
568 | view.chart()->addSeries(series); |
|
568 | view.chart()->addSeries(series); | |
569 | view.show(); |
|
569 | view.show(); | |
570 |
|
570 | |||
571 | series->clear(); |
|
571 | series->clear(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | QTEST_MAIN(tst_QBarSeries) |
|
574 | QTEST_MAIN(tst_QBarSeries) | |
575 |
|
575 | |||
576 | #include "tst_qbarseries.moc" |
|
576 | #include "tst_qbarseries.moc" | |
577 |
|
577 |
@@ -1,614 +1,614 | |||||
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 <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <qareaseries.h> |
|
24 | #include <qareaseries.h> | |
25 | #include <qscatterseries.h> |
|
25 | #include <qscatterseries.h> | |
26 | #include <qsplineseries.h> |
|
26 | #include <qsplineseries.h> | |
27 | #include <qpieseries.h> |
|
27 | #include <qpieseries.h> | |
28 | #include <qbarseries.h> |
|
28 | #include <qabstractbarseries.h> | |
29 | #include <qpercentbarseries.h> |
|
29 | #include <qpercentbarseries.h> | |
30 | #include <qstackedbarseries.h> |
|
30 | #include <qstackedbarseries.h> | |
31 | #include <qvaluesaxis.h> |
|
31 | #include <qvaluesaxis.h> | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
33 | QTCOMMERCIALCHART_USE_NAMESPACE | |
34 |
|
34 | |||
35 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
35 | Q_DECLARE_METATYPE(QAbstractAxis *) | |
36 | Q_DECLARE_METATYPE(QValuesAxis *) |
|
36 | Q_DECLARE_METATYPE(QValuesAxis *) | |
37 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
37 | Q_DECLARE_METATYPE(QAbstractSeries *) | |
38 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
38 | Q_DECLARE_METATYPE(QChart::AnimationOption) | |
39 | Q_DECLARE_METATYPE(QBrush) |
|
39 | Q_DECLARE_METATYPE(QBrush) | |
40 | Q_DECLARE_METATYPE(QPen) |
|
40 | Q_DECLARE_METATYPE(QPen) | |
41 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
41 | Q_DECLARE_METATYPE(QChart::ChartTheme) | |
42 |
|
42 | |||
43 | class tst_QChart : public QObject |
|
43 | class tst_QChart : public QObject | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 |
|
46 | |||
47 | public slots: |
|
47 | public slots: | |
48 | void initTestCase(); |
|
48 | void initTestCase(); | |
49 | void cleanupTestCase(); |
|
49 | void cleanupTestCase(); | |
50 | void init(); |
|
50 | void init(); | |
51 | void cleanup(); |
|
51 | void cleanup(); | |
52 |
|
52 | |||
53 | private slots: |
|
53 | private slots: | |
54 | void qchart_data(); |
|
54 | void qchart_data(); | |
55 | void qchart(); |
|
55 | void qchart(); | |
56 |
|
56 | |||
57 | void addSeries_data(); |
|
57 | void addSeries_data(); | |
58 | void addSeries(); |
|
58 | void addSeries(); | |
59 | void animationOptions_data(); |
|
59 | void animationOptions_data(); | |
60 | void animationOptions(); |
|
60 | void animationOptions(); | |
61 | void axisX_data(); |
|
61 | void axisX_data(); | |
62 | void axisX(); |
|
62 | void axisX(); | |
63 | void axisY_data(); |
|
63 | void axisY_data(); | |
64 | void axisY(); |
|
64 | void axisY(); | |
65 | void backgroundBrush_data(); |
|
65 | void backgroundBrush_data(); | |
66 | void backgroundBrush(); |
|
66 | void backgroundBrush(); | |
67 | void backgroundPen_data(); |
|
67 | void backgroundPen_data(); | |
68 | void backgroundPen(); |
|
68 | void backgroundPen(); | |
69 | void isBackgroundVisible_data(); |
|
69 | void isBackgroundVisible_data(); | |
70 | void isBackgroundVisible(); |
|
70 | void isBackgroundVisible(); | |
71 | void legend_data(); |
|
71 | void legend_data(); | |
72 | void legend(); |
|
72 | void legend(); | |
73 | void margins_data(); |
|
73 | void margins_data(); | |
74 | void margins(); |
|
74 | void margins(); | |
75 | void removeAllSeries_data(); |
|
75 | void removeAllSeries_data(); | |
76 | void removeAllSeries(); |
|
76 | void removeAllSeries(); | |
77 | void removeSeries_data(); |
|
77 | void removeSeries_data(); | |
78 | void removeSeries(); |
|
78 | void removeSeries(); | |
79 | void scroll_data(); |
|
79 | void scroll_data(); | |
80 | void scroll(); |
|
80 | void scroll(); | |
81 | void theme_data(); |
|
81 | void theme_data(); | |
82 | void theme(); |
|
82 | void theme(); | |
83 | void title_data(); |
|
83 | void title_data(); | |
84 | void title(); |
|
84 | void title(); | |
85 | void titleBrush_data(); |
|
85 | void titleBrush_data(); | |
86 | void titleBrush(); |
|
86 | void titleBrush(); | |
87 | void titleFont_data(); |
|
87 | void titleFont_data(); | |
88 | void titleFont(); |
|
88 | void titleFont(); | |
89 | void zoomIn_data(); |
|
89 | void zoomIn_data(); | |
90 | void zoomIn(); |
|
90 | void zoomIn(); | |
91 | void zoomOut_data(); |
|
91 | void zoomOut_data(); | |
92 | void zoomOut(); |
|
92 | void zoomOut(); | |
93 |
|
93 | |||
94 | private: |
|
94 | private: | |
95 | void createTestData(); |
|
95 | void createTestData(); | |
96 |
|
96 | |||
97 | private: |
|
97 | private: | |
98 | QChartView* m_view; |
|
98 | QChartView* m_view; | |
99 | QChart* m_chart; |
|
99 | QChart* m_chart; | |
100 | }; |
|
100 | }; | |
101 |
|
101 | |||
102 | void tst_QChart::initTestCase() |
|
102 | void tst_QChart::initTestCase() | |
103 | { |
|
103 | { | |
104 |
|
104 | |||
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_QChart::cleanupTestCase() |
|
107 | void tst_QChart::cleanupTestCase() | |
108 | { |
|
108 | { | |
109 |
|
109 | |||
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | void tst_QChart::init() |
|
112 | void tst_QChart::init() | |
113 | { |
|
113 | { | |
114 | m_view = new QChartView(new QChart()); |
|
114 | m_view = new QChartView(new QChart()); | |
115 | m_chart = m_view->chart(); |
|
115 | m_chart = m_view->chart(); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | void tst_QChart::createTestData() |
|
118 | void tst_QChart::createTestData() | |
119 | { |
|
119 | { | |
120 | QLineSeries* series0 = new QLineSeries(this); |
|
120 | QLineSeries* series0 = new QLineSeries(this); | |
121 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
121 | *series0 << QPointF(0, 0) << QPointF(100, 100); | |
122 | m_chart->addSeries(series0); |
|
122 | m_chart->addSeries(series0); | |
123 | m_view->show(); |
|
123 | m_view->show(); | |
124 | QTest::qWaitForWindowShown(m_view); |
|
124 | QTest::qWaitForWindowShown(m_view); | |
125 | } |
|
125 | } | |
126 |
|
126 | |||
127 | void tst_QChart::cleanup() |
|
127 | void tst_QChart::cleanup() | |
128 | { |
|
128 | { | |
129 | delete m_view; |
|
129 | delete m_view; | |
130 | m_view = 0; |
|
130 | m_view = 0; | |
131 | m_chart = 0; |
|
131 | m_chart = 0; | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void tst_QChart::qchart_data() |
|
134 | void tst_QChart::qchart_data() | |
135 | { |
|
135 | { | |
136 | } |
|
136 | } | |
137 |
|
137 | |||
138 | void tst_QChart::qchart() |
|
138 | void tst_QChart::qchart() | |
139 | { |
|
139 | { | |
140 | QVERIFY(m_chart); |
|
140 | QVERIFY(m_chart); | |
141 | QVERIFY(m_chart->legend()); |
|
141 | QVERIFY(m_chart->legend()); | |
142 | QVERIFY(m_chart->legend()->isVisible()); |
|
142 | QVERIFY(m_chart->legend()->isVisible()); | |
143 |
|
143 | |||
144 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
144 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); | |
145 | QVERIFY(m_chart->axisX()); |
|
145 | QVERIFY(m_chart->axisX()); | |
146 | QVERIFY(m_chart->axisY()); |
|
146 | QVERIFY(m_chart->axisY()); | |
147 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
147 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); | |
148 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
148 | QVERIFY(m_chart->backgroundPen()!=QPen()); | |
149 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
149 | QCOMPARE(m_chart->isBackgroundVisible(), true); | |
150 |
|
150 | |||
151 | QVERIFY(m_chart->margins().top()>0); |
|
151 | QVERIFY(m_chart->margins().top()>0); | |
152 | QVERIFY(m_chart->margins().left()>0); |
|
152 | QVERIFY(m_chart->margins().left()>0); | |
153 | QVERIFY(m_chart->margins().right()>0); |
|
153 | QVERIFY(m_chart->margins().right()>0); | |
154 | QVERIFY(m_chart->margins().bottom()>0); |
|
154 | QVERIFY(m_chart->margins().bottom()>0); | |
155 |
|
155 | |||
156 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
156 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); | |
157 | QCOMPARE(m_chart->title(), QString()); |
|
157 | QCOMPARE(m_chart->title(), QString()); | |
158 |
|
158 | |||
159 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
159 | //QCOMPARE(m_chart->titleBrush(),QBrush()); | |
160 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
160 | //QCOMPARE(m_chart->titleFont(),QFont()); | |
161 |
|
161 | |||
162 | m_chart->removeAllSeries(); |
|
162 | m_chart->removeAllSeries(); | |
163 | m_chart->scroll(0,0); |
|
163 | m_chart->scroll(0,0); | |
164 |
|
164 | |||
165 | m_chart->zoomIn(); |
|
165 | m_chart->zoomIn(); | |
166 | m_chart->zoomIn(QRectF()); |
|
166 | m_chart->zoomIn(QRectF()); | |
167 | m_chart->zoomOut(); |
|
167 | m_chart->zoomOut(); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void tst_QChart::addSeries_data() |
|
170 | void tst_QChart::addSeries_data() | |
171 | { |
|
171 | { | |
172 | QTest::addColumn<QAbstractSeries *>("series"); |
|
172 | QTest::addColumn<QAbstractSeries *>("series"); | |
173 | QTest::addColumn<QAbstractAxis *>("axis"); |
|
173 | QTest::addColumn<QAbstractAxis *>("axis"); | |
174 |
|
174 | |||
175 | QAbstractSeries* series0 = new QLineSeries(this); |
|
175 | QAbstractSeries* series0 = new QLineSeries(this); | |
176 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); |
|
176 | QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0)); | |
177 | QAbstractSeries* series2 = new QScatterSeries(this); |
|
177 | QAbstractSeries* series2 = new QScatterSeries(this); | |
178 | QAbstractSeries* series3 = new QSplineSeries(this); |
|
178 | QAbstractSeries* series3 = new QSplineSeries(this); | |
179 | QAbstractSeries* series4 = new QPieSeries(this); |
|
179 | QAbstractSeries* series4 = new QPieSeries(this); | |
180 | QAbstractSeries* series5 = new QAbstractBarSeries(this); |
|
180 | QAbstractSeries* series5 = new QAbstractBarSeries(this); | |
181 | QAbstractSeries* series6 = new QPercentBarSeries(this); |
|
181 | QAbstractSeries* series6 = new QPercentBarSeries(this); | |
182 | QAbstractSeries* series7 = new QStackedBarSeries(this); |
|
182 | QAbstractSeries* series7 = new QStackedBarSeries(this); | |
183 |
|
183 | |||
184 | QValuesAxis* axis = new QValuesAxis(this); |
|
184 | QValuesAxis* axis = new QValuesAxis(this); | |
185 |
|
185 | |||
186 | QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0; |
|
186 | QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0; | |
187 | QTest::newRow("axis0: lineSeries") << series0 << axis; |
|
187 | QTest::newRow("axis0: lineSeries") << series0 << axis; | |
188 | QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0; |
|
188 | QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0; | |
189 | QTest::newRow("axis: areaSeries") << series1 << axis; |
|
189 | QTest::newRow("axis: areaSeries") << series1 << axis; | |
190 | QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0; |
|
190 | QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0; | |
191 | QTest::newRow("axis1: scatterSeries") << series2 << axis; |
|
191 | QTest::newRow("axis1: scatterSeries") << series2 << axis; | |
192 | QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0; |
|
192 | QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0; | |
193 | QTest::newRow("axis: splineSeries") << series3 << axis; |
|
193 | QTest::newRow("axis: splineSeries") << series3 << axis; | |
194 | QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0; |
|
194 | QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0; | |
195 | QTest::newRow("axis: pieSeries") << series4 << axis; |
|
195 | QTest::newRow("axis: pieSeries") << series4 << axis; | |
196 | QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0; |
|
196 | QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0; | |
197 | QTest::newRow("axis: barSeries") << series5 << axis; |
|
197 | QTest::newRow("axis: barSeries") << series5 << axis; | |
198 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0; |
|
198 | QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0; | |
199 | QTest::newRow("axis: barSeries") << series6 << axis; |
|
199 | QTest::newRow("axis: barSeries") << series6 << axis; | |
200 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0; |
|
200 | QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0; | |
201 | QTest::newRow("axis: barSeries") << series7 << axis; |
|
201 | QTest::newRow("axis: barSeries") << series7 << axis; | |
202 |
|
202 | |||
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void tst_QChart::addSeries() |
|
205 | void tst_QChart::addSeries() | |
206 | { |
|
206 | { | |
207 | QFETCH(QAbstractSeries *, series); |
|
207 | QFETCH(QAbstractSeries *, series); | |
208 | QFETCH(QAbstractAxis *, axis); |
|
208 | QFETCH(QAbstractAxis *, axis); | |
209 | m_view->show(); |
|
209 | m_view->show(); | |
210 | QTest::qWaitForWindowShown(m_view); |
|
210 | QTest::qWaitForWindowShown(m_view); | |
211 | if(!axis) axis = m_chart->axisY(); |
|
211 | if(!axis) axis = m_chart->axisY(); | |
212 | QVERIFY(!series->chart()); |
|
212 | QVERIFY(!series->chart()); | |
213 | QCOMPARE(m_chart->series().count(), 0); |
|
213 | QCOMPARE(m_chart->series().count(), 0); | |
214 | m_chart->addSeries(series); |
|
214 | m_chart->addSeries(series); | |
215 | m_chart->setAxisY(axis,series); |
|
215 | m_chart->setAxisY(axis,series); | |
216 | QCOMPARE(m_chart->series().count(), 1); |
|
216 | QCOMPARE(m_chart->series().count(), 1); | |
217 | QCOMPARE(m_chart->series().first(), series); |
|
217 | QCOMPARE(m_chart->series().first(), series); | |
218 | QVERIFY(series->chart() == m_chart); |
|
218 | QVERIFY(series->chart() == m_chart); | |
219 | QCOMPARE(m_chart->axisY(series),axis); |
|
219 | QCOMPARE(m_chart->axisY(series),axis); | |
220 | m_chart->removeSeries(series); |
|
220 | m_chart->removeSeries(series); | |
221 | QVERIFY(!series->chart()); |
|
221 | QVERIFY(!series->chart()); | |
222 | QCOMPARE(m_chart->series().count(), 0); |
|
222 | QCOMPARE(m_chart->series().count(), 0); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void tst_QChart::animationOptions_data() |
|
225 | void tst_QChart::animationOptions_data() | |
226 | { |
|
226 | { | |
227 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
227 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); | |
228 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
228 | QTest::newRow("AllAnimations") << QChart::AllAnimations; | |
229 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
229 | QTest::newRow("NoAnimation") << QChart::NoAnimation; | |
230 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
230 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; | |
231 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
231 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | void tst_QChart::animationOptions() |
|
234 | void tst_QChart::animationOptions() | |
235 | { |
|
235 | { | |
236 | createTestData(); |
|
236 | createTestData(); | |
237 | QFETCH(QChart::AnimationOption, animationOptions); |
|
237 | QFETCH(QChart::AnimationOption, animationOptions); | |
238 | m_chart->setAnimationOptions(animationOptions); |
|
238 | m_chart->setAnimationOptions(animationOptions); | |
239 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
239 | QCOMPARE(m_chart->animationOptions(), animationOptions); | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void tst_QChart::axisX_data() |
|
242 | void tst_QChart::axisX_data() | |
243 | { |
|
243 | { | |
244 |
|
244 | |||
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | void tst_QChart::axisX() |
|
247 | void tst_QChart::axisX() | |
248 | { |
|
248 | { | |
249 | QVERIFY(m_chart->axisX()); |
|
249 | QVERIFY(m_chart->axisX()); | |
250 | QAbstractAxis* axis = m_chart->axisX(); |
|
250 | QAbstractAxis* axis = m_chart->axisX(); | |
251 | createTestData(); |
|
251 | createTestData(); | |
252 | //it should be the same axis |
|
252 | //it should be the same axis | |
253 | QCOMPARE(axis,m_chart->axisX()); |
|
253 | QCOMPARE(axis,m_chart->axisX()); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | void tst_QChart::axisY_data() |
|
256 | void tst_QChart::axisY_data() | |
257 | { |
|
257 | { | |
258 | QTest::addColumn<QAbstractAxis*>("axis0"); |
|
258 | QTest::addColumn<QAbstractAxis*>("axis0"); | |
259 | QTest::addColumn<QAbstractAxis*>("axis1"); |
|
259 | QTest::addColumn<QAbstractAxis*>("axis1"); | |
260 | QTest::addColumn<QAbstractAxis*>("axis2"); |
|
260 | QTest::addColumn<QAbstractAxis*>("axis2"); | |
261 | QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis(); |
|
261 | QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis(); | |
262 | QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis(); |
|
262 | QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis(); | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 |
|
265 | |||
266 | void tst_QChart::axisY() |
|
266 | void tst_QChart::axisY() | |
267 | { |
|
267 | { | |
268 | QFETCH(QAbstractAxis*, axis0); |
|
268 | QFETCH(QAbstractAxis*, axis0); | |
269 | QFETCH(QAbstractAxis*, axis1); |
|
269 | QFETCH(QAbstractAxis*, axis1); | |
270 | QFETCH(QAbstractAxis*, axis2); |
|
270 | QFETCH(QAbstractAxis*, axis2); | |
271 |
|
271 | |||
272 | QAbstractAxis* defaultAxisY = m_chart->axisY(); |
|
272 | QAbstractAxis* defaultAxisY = m_chart->axisY(); | |
273 |
|
273 | |||
274 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
274 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
275 |
|
275 | |||
276 | QLineSeries* series0 = new QLineSeries(); |
|
276 | QLineSeries* series0 = new QLineSeries(); | |
277 | m_chart->addSeries(series0); |
|
277 | m_chart->addSeries(series0); | |
278 | m_chart->setAxisY(axis0,series0); |
|
278 | m_chart->setAxisY(axis0,series0); | |
279 |
|
279 | |||
280 | QLineSeries* series1 = new QLineSeries(); |
|
280 | QLineSeries* series1 = new QLineSeries(); | |
281 | m_chart->addSeries(series1); |
|
281 | m_chart->addSeries(series1); | |
282 | m_chart->setAxisY(axis1,series1); |
|
282 | m_chart->setAxisY(axis1,series1); | |
283 |
|
283 | |||
284 | QLineSeries* series2 = new QLineSeries(); |
|
284 | QLineSeries* series2 = new QLineSeries(); | |
285 | m_chart->addSeries(series2); |
|
285 | m_chart->addSeries(series2); | |
286 | m_chart->setAxisY(axis2,series2); |
|
286 | m_chart->setAxisY(axis2,series2); | |
287 |
|
287 | |||
288 | if (!axis0) |
|
288 | if (!axis0) | |
289 | axis0 = defaultAxisY; |
|
289 | axis0 = defaultAxisY; | |
290 | if (!axis1) |
|
290 | if (!axis1) | |
291 | axis1 = defaultAxisY; |
|
291 | axis1 = defaultAxisY; | |
292 | if (!axis2) |
|
292 | if (!axis2) | |
293 | axis2 = defaultAxisY; |
|
293 | axis2 = defaultAxisY; | |
294 |
|
294 | |||
295 | QVERIFY(m_chart->axisY(series0) == axis0); |
|
295 | QVERIFY(m_chart->axisY(series0) == axis0); | |
296 | QVERIFY(m_chart->axisY(series1) == axis1); |
|
296 | QVERIFY(m_chart->axisY(series1) == axis1); | |
297 | QVERIFY(m_chart->axisY(series2) == axis2); |
|
297 | QVERIFY(m_chart->axisY(series2) == axis2); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | void tst_QChart::backgroundBrush_data() |
|
300 | void tst_QChart::backgroundBrush_data() | |
301 | { |
|
301 | { | |
302 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
302 | QTest::addColumn<QBrush>("backgroundBrush"); | |
303 | QTest::newRow("null") << QBrush(); |
|
303 | QTest::newRow("null") << QBrush(); | |
304 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
304 | QTest::newRow("blue") << QBrush(Qt::blue); | |
305 | QTest::newRow("white") << QBrush(Qt::white); |
|
305 | QTest::newRow("white") << QBrush(Qt::white); | |
306 | QTest::newRow("black") << QBrush(Qt::black); |
|
306 | QTest::newRow("black") << QBrush(Qt::black); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | void tst_QChart::backgroundBrush() |
|
309 | void tst_QChart::backgroundBrush() | |
310 | { |
|
310 | { | |
311 | QFETCH(QBrush, backgroundBrush); |
|
311 | QFETCH(QBrush, backgroundBrush); | |
312 | m_chart->setBackgroundBrush(backgroundBrush); |
|
312 | m_chart->setBackgroundBrush(backgroundBrush); | |
313 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
313 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void tst_QChart::backgroundPen_data() |
|
316 | void tst_QChart::backgroundPen_data() | |
317 | { |
|
317 | { | |
318 | QTest::addColumn<QPen>("backgroundPen"); |
|
318 | QTest::addColumn<QPen>("backgroundPen"); | |
319 | QTest::newRow("null") << QPen(); |
|
319 | QTest::newRow("null") << QPen(); | |
320 | QTest::newRow("blue") << QPen(Qt::blue); |
|
320 | QTest::newRow("blue") << QPen(Qt::blue); | |
321 | QTest::newRow("white") << QPen(Qt::white); |
|
321 | QTest::newRow("white") << QPen(Qt::white); | |
322 | QTest::newRow("black") << QPen(Qt::black); |
|
322 | QTest::newRow("black") << QPen(Qt::black); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 |
|
325 | |||
326 | void tst_QChart::backgroundPen() |
|
326 | void tst_QChart::backgroundPen() | |
327 | { |
|
327 | { | |
328 | QFETCH(QPen, backgroundPen); |
|
328 | QFETCH(QPen, backgroundPen); | |
329 | m_chart->setBackgroundPen(backgroundPen); |
|
329 | m_chart->setBackgroundPen(backgroundPen); | |
330 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
330 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | void tst_QChart::isBackgroundVisible_data() |
|
333 | void tst_QChart::isBackgroundVisible_data() | |
334 | { |
|
334 | { | |
335 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
335 | QTest::addColumn<bool>("isBackgroundVisible"); | |
336 | QTest::newRow("true") << true; |
|
336 | QTest::newRow("true") << true; | |
337 | QTest::newRow("false") << false; |
|
337 | QTest::newRow("false") << false; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | void tst_QChart::isBackgroundVisible() |
|
340 | void tst_QChart::isBackgroundVisible() | |
341 | { |
|
341 | { | |
342 | QFETCH(bool, isBackgroundVisible); |
|
342 | QFETCH(bool, isBackgroundVisible); | |
343 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
343 | m_chart->setBackgroundVisible(isBackgroundVisible); | |
344 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
344 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); | |
345 | } |
|
345 | } | |
346 |
|
346 | |||
347 | void tst_QChart::legend_data() |
|
347 | void tst_QChart::legend_data() | |
348 | { |
|
348 | { | |
349 |
|
349 | |||
350 | } |
|
350 | } | |
351 |
|
351 | |||
352 | void tst_QChart::legend() |
|
352 | void tst_QChart::legend() | |
353 | { |
|
353 | { | |
354 | QLegend *legend = m_chart->legend(); |
|
354 | QLegend *legend = m_chart->legend(); | |
355 | QVERIFY(legend); |
|
355 | QVERIFY(legend); | |
356 |
|
356 | |||
357 | // Colors related signals |
|
357 | // Colors related signals | |
358 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
358 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); | |
359 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
359 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); | |
360 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
360 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); | |
361 |
|
361 | |||
362 | // colorChanged |
|
362 | // colorChanged | |
363 | legend->setColor(QColor("aliceblue")); |
|
363 | legend->setColor(QColor("aliceblue")); | |
364 | QCOMPARE(colorSpy.count(), 1); |
|
364 | QCOMPARE(colorSpy.count(), 1); | |
365 | QBrush b = legend->brush(); |
|
365 | QBrush b = legend->brush(); | |
366 | b.setColor(QColor("aqua")); |
|
366 | b.setColor(QColor("aqua")); | |
367 | legend->setBrush(b); |
|
367 | legend->setBrush(b); | |
368 | QCOMPARE(colorSpy.count(), 2); |
|
368 | QCOMPARE(colorSpy.count(), 2); | |
369 |
|
369 | |||
370 | // borderColorChanged |
|
370 | // borderColorChanged | |
371 | legend->setBorderColor(QColor("aliceblue")); |
|
371 | legend->setBorderColor(QColor("aliceblue")); | |
372 | QCOMPARE(borderColorSpy.count(), 1); |
|
372 | QCOMPARE(borderColorSpy.count(), 1); | |
373 | QPen p = legend->pen(); |
|
373 | QPen p = legend->pen(); | |
374 | p.setColor(QColor("aqua")); |
|
374 | p.setColor(QColor("aqua")); | |
375 | legend->setPen(p); |
|
375 | legend->setPen(p); | |
376 | QCOMPARE(borderColorSpy.count(), 2); |
|
376 | QCOMPARE(borderColorSpy.count(), 2); | |
377 |
|
377 | |||
378 | // labelColorChanged |
|
378 | // labelColorChanged | |
379 | legend->setLabelColor(QColor("lightsalmon")); |
|
379 | legend->setLabelColor(QColor("lightsalmon")); | |
380 | QCOMPARE(labelColorSpy.count(), 1); |
|
380 | QCOMPARE(labelColorSpy.count(), 1); | |
381 | b = legend->labelBrush(); |
|
381 | b = legend->labelBrush(); | |
382 | b.setColor(QColor("lightseagreen")); |
|
382 | b.setColor(QColor("lightseagreen")); | |
383 | legend->setLabelBrush(b); |
|
383 | legend->setLabelBrush(b); | |
384 | QCOMPARE(labelColorSpy.count(), 2); |
|
384 | QCOMPARE(labelColorSpy.count(), 2); | |
385 |
|
385 | |||
386 | // fontChanged |
|
386 | // fontChanged | |
387 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
387 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); | |
388 | QFont f = legend->font(); |
|
388 | QFont f = legend->font(); | |
389 | f.setBold(!f.bold()); |
|
389 | f.setBold(!f.bold()); | |
390 | legend->setFont(f); |
|
390 | legend->setFont(f); | |
391 | QCOMPARE(fontSpy.count(), 1); |
|
391 | QCOMPARE(fontSpy.count(), 1); | |
392 | } |
|
392 | } | |
393 |
|
393 | |||
394 | void tst_QChart::margins_data() |
|
394 | void tst_QChart::margins_data() | |
395 | { |
|
395 | { | |
396 |
|
396 | |||
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | void tst_QChart::margins() |
|
399 | void tst_QChart::margins() | |
400 | { |
|
400 | { | |
401 | createTestData(); |
|
401 | createTestData(); | |
402 | QRectF rect = m_chart->geometry(); |
|
402 | QRectF rect = m_chart->geometry(); | |
403 |
|
403 | |||
404 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); |
|
404 | QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height()); | |
405 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); |
|
405 | QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width()); | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | void tst_QChart::removeAllSeries_data() |
|
408 | void tst_QChart::removeAllSeries_data() | |
409 | { |
|
409 | { | |
410 |
|
410 | |||
411 | } |
|
411 | } | |
412 |
|
412 | |||
413 | void tst_QChart::removeAllSeries() |
|
413 | void tst_QChart::removeAllSeries() | |
414 | { |
|
414 | { | |
415 | QLineSeries* series0 = new QLineSeries(this); |
|
415 | QLineSeries* series0 = new QLineSeries(this); | |
416 | QLineSeries* series1 = new QLineSeries(this); |
|
416 | QLineSeries* series1 = new QLineSeries(this); | |
417 | QLineSeries* series2 = new QLineSeries(this); |
|
417 | QLineSeries* series2 = new QLineSeries(this); | |
418 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
418 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); | |
419 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
419 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); | |
420 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
420 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); | |
421 |
|
421 | |||
422 | m_chart->addSeries(series0); |
|
422 | m_chart->addSeries(series0); | |
423 | m_chart->addSeries(series1); |
|
423 | m_chart->addSeries(series1); | |
424 | m_chart->addSeries(series2); |
|
424 | m_chart->addSeries(series2); | |
425 | m_view->show(); |
|
425 | m_view->show(); | |
426 | QTest::qWaitForWindowShown(m_view); |
|
426 | QTest::qWaitForWindowShown(m_view); | |
427 |
|
427 | |||
428 | QVERIFY(m_chart->axisY(series0)!=0); |
|
428 | QVERIFY(m_chart->axisY(series0)!=0); | |
429 | QVERIFY(m_chart->axisY(series1)!=0); |
|
429 | QVERIFY(m_chart->axisY(series1)!=0); | |
430 | QVERIFY(m_chart->axisY(series2)!=0); |
|
430 | QVERIFY(m_chart->axisY(series2)!=0); | |
431 |
|
431 | |||
432 | m_chart->removeAllSeries(); |
|
432 | m_chart->removeAllSeries(); | |
433 | QVERIFY(m_chart->axisY(series0)==0); |
|
433 | QVERIFY(m_chart->axisY(series0)==0); | |
434 | QVERIFY(m_chart->axisY(series1)==0); |
|
434 | QVERIFY(m_chart->axisY(series1)==0); | |
435 | QVERIFY(m_chart->axisY(series2)==0); |
|
435 | QVERIFY(m_chart->axisY(series2)==0); | |
436 | QCOMPARE(deleteSpy1.count(), 1); |
|
436 | QCOMPARE(deleteSpy1.count(), 1); | |
437 | QCOMPARE(deleteSpy2.count(), 1); |
|
437 | QCOMPARE(deleteSpy2.count(), 1); | |
438 | QCOMPARE(deleteSpy3.count(), 1); |
|
438 | QCOMPARE(deleteSpy3.count(), 1); | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | void tst_QChart::removeSeries_data() |
|
441 | void tst_QChart::removeSeries_data() | |
442 | { |
|
442 | { | |
443 | addSeries_data(); |
|
443 | addSeries_data(); | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | void tst_QChart::removeSeries() |
|
446 | void tst_QChart::removeSeries() | |
447 | { |
|
447 | { | |
448 | QFETCH(QAbstractSeries *, series); |
|
448 | QFETCH(QAbstractSeries *, series); | |
449 | QFETCH(QAbstractAxis *, axis); |
|
449 | QFETCH(QAbstractAxis *, axis); | |
450 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
450 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); | |
451 | m_view->show(); |
|
451 | m_view->show(); | |
452 | QTest::qWaitForWindowShown(m_view); |
|
452 | QTest::qWaitForWindowShown(m_view); | |
453 | if(!axis) axis = m_chart->axisY(); |
|
453 | if(!axis) axis = m_chart->axisY(); | |
454 | m_chart->addSeries(series); |
|
454 | m_chart->addSeries(series); | |
455 | m_chart->setAxisY(axis,series); |
|
455 | m_chart->setAxisY(axis,series); | |
456 | QCOMPARE(m_chart->axisY(series),axis); |
|
456 | QCOMPARE(m_chart->axisY(series),axis); | |
457 | m_chart->removeSeries(series); |
|
457 | m_chart->removeSeries(series); | |
458 | QVERIFY(m_chart->axisY(series)==0); |
|
458 | QVERIFY(m_chart->axisY(series)==0); | |
459 | QCOMPARE(deleteSpy.count(), 0); |
|
459 | QCOMPARE(deleteSpy.count(), 0); | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | void tst_QChart::scroll_data() |
|
462 | void tst_QChart::scroll_data() | |
463 | { |
|
463 | { | |
464 |
|
464 | |||
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | void tst_QChart::scroll() |
|
467 | void tst_QChart::scroll() | |
468 | { |
|
468 | { | |
469 | qFatal("implement me"); |
|
469 | qFatal("implement me"); | |
470 | createTestData(); |
|
470 | createTestData(); | |
471 | //TODO qreal min = m_chart->axisY()->min(); |
|
471 | //TODO qreal min = m_chart->axisY()->min(); | |
472 | m_chart->scroll(0,0); |
|
472 | m_chart->scroll(0,0); | |
473 | //TODO QVERIFY(m_chart->axisY()->min()<min); |
|
473 | //TODO QVERIFY(m_chart->axisY()->min()<min); | |
474 | } |
|
474 | } | |
475 |
|
475 | |||
476 | void tst_QChart::theme_data() |
|
476 | void tst_QChart::theme_data() | |
477 | { |
|
477 | { | |
478 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
478 | QTest::addColumn<QChart::ChartTheme>("theme"); | |
479 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
479 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; | |
480 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
480 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; | |
481 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
481 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; | |
482 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
482 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; | |
483 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
483 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; | |
484 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
484 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; | |
485 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
485 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | void tst_QChart::theme() |
|
488 | void tst_QChart::theme() | |
489 | { |
|
489 | { | |
490 | QFETCH(QChart::ChartTheme, theme); |
|
490 | QFETCH(QChart::ChartTheme, theme); | |
491 | createTestData(); |
|
491 | createTestData(); | |
492 | m_chart->setTheme(theme); |
|
492 | m_chart->setTheme(theme); | |
493 | QVERIFY(m_chart->theme()==theme); |
|
493 | QVERIFY(m_chart->theme()==theme); | |
494 | } |
|
494 | } | |
495 |
|
495 | |||
496 | void tst_QChart::title_data() |
|
496 | void tst_QChart::title_data() | |
497 | { |
|
497 | { | |
498 | QTest::addColumn<QString>("title"); |
|
498 | QTest::addColumn<QString>("title"); | |
499 | QTest::newRow("null") << QString(); |
|
499 | QTest::newRow("null") << QString(); | |
500 | QTest::newRow("foo") << QString("foo"); |
|
500 | QTest::newRow("foo") << QString("foo"); | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | void tst_QChart::title() |
|
503 | void tst_QChart::title() | |
504 | { |
|
504 | { | |
505 | QFETCH(QString, title); |
|
505 | QFETCH(QString, title); | |
506 | m_chart->setTitle(title); |
|
506 | m_chart->setTitle(title); | |
507 | QCOMPARE(m_chart->title(), title); |
|
507 | QCOMPARE(m_chart->title(), title); | |
508 | } |
|
508 | } | |
509 |
|
509 | |||
510 | void tst_QChart::titleBrush_data() |
|
510 | void tst_QChart::titleBrush_data() | |
511 | { |
|
511 | { | |
512 | QTest::addColumn<QBrush>("titleBrush"); |
|
512 | QTest::addColumn<QBrush>("titleBrush"); | |
513 | QTest::newRow("null") << QBrush(); |
|
513 | QTest::newRow("null") << QBrush(); | |
514 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
514 | QTest::newRow("blue") << QBrush(Qt::blue); | |
515 | QTest::newRow("white") << QBrush(Qt::white); |
|
515 | QTest::newRow("white") << QBrush(Qt::white); | |
516 | QTest::newRow("black") << QBrush(Qt::black); |
|
516 | QTest::newRow("black") << QBrush(Qt::black); | |
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | void tst_QChart::titleBrush() |
|
519 | void tst_QChart::titleBrush() | |
520 | { |
|
520 | { | |
521 | QFETCH(QBrush, titleBrush); |
|
521 | QFETCH(QBrush, titleBrush); | |
522 | m_chart->setTitleBrush(titleBrush); |
|
522 | m_chart->setTitleBrush(titleBrush); | |
523 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
523 | QCOMPARE(m_chart->titleBrush(), titleBrush); | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 | void tst_QChart::titleFont_data() |
|
526 | void tst_QChart::titleFont_data() | |
527 | { |
|
527 | { | |
528 | QTest::addColumn<QFont>("titleFont"); |
|
528 | QTest::addColumn<QFont>("titleFont"); | |
529 | QTest::newRow("null") << QFont(); |
|
529 | QTest::newRow("null") << QFont(); | |
530 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
530 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); | |
531 | } |
|
531 | } | |
532 |
|
532 | |||
533 | void tst_QChart::titleFont() |
|
533 | void tst_QChart::titleFont() | |
534 | { |
|
534 | { | |
535 | QFETCH(QFont, titleFont); |
|
535 | QFETCH(QFont, titleFont); | |
536 | m_chart->setTitleFont(titleFont); |
|
536 | m_chart->setTitleFont(titleFont); | |
537 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
537 | QCOMPARE(m_chart->titleFont(), titleFont); | |
538 | } |
|
538 | } | |
539 |
|
539 | |||
540 | void tst_QChart::zoomIn_data() |
|
540 | void tst_QChart::zoomIn_data() | |
541 | { |
|
541 | { | |
542 | QTest::addColumn<QRectF>("rect"); |
|
542 | QTest::addColumn<QRectF>("rect"); | |
543 | QTest::newRow("null") << QRectF(); |
|
543 | QTest::newRow("null") << QRectF(); | |
544 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
544 | QTest::newRow("100x100") << QRectF(10,10,100,100); | |
545 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
545 | QTest::newRow("200x200") << QRectF(10,10,200,200); | |
546 | } |
|
546 | } | |
547 |
|
547 | |||
548 |
|
548 | |||
549 | void tst_QChart::zoomIn() |
|
549 | void tst_QChart::zoomIn() | |
550 | { |
|
550 | { | |
551 | qFatal("implement me"); |
|
551 | qFatal("implement me"); | |
552 | /* |
|
552 | /* | |
553 | QFETCH(QRectF, rect); |
|
553 | QFETCH(QRectF, rect); | |
554 | createTestData(); |
|
554 | createTestData(); | |
555 | QRectF marigns = m_chart->margins(); |
|
555 | QRectF marigns = m_chart->margins(); | |
556 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
556 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); | |
557 | qreal minX = m_chart->axisX()->min(); |
|
557 | qreal minX = m_chart->axisX()->min(); | |
558 | qreal minY = m_chart->axisY()->min(); |
|
558 | qreal minY = m_chart->axisY()->min(); | |
559 | qreal maxX = m_chart->axisX()->max(); |
|
559 | qreal maxX = m_chart->axisX()->max(); | |
560 | qreal maxY = m_chart->axisY()->max(); |
|
560 | qreal maxY = m_chart->axisY()->max(); | |
561 | m_chart->zoomIn(rect); |
|
561 | m_chart->zoomIn(rect); | |
562 | if(rect.isValid()){ |
|
562 | if(rect.isValid()){ | |
563 | QVERIFY(minX<m_chart->axisX()->min()); |
|
563 | QVERIFY(minX<m_chart->axisX()->min()); | |
564 | QVERIFY(maxX>m_chart->axisX()->max()); |
|
564 | QVERIFY(maxX>m_chart->axisX()->max()); | |
565 | QVERIFY(minY<m_chart->axisY()->min()); |
|
565 | QVERIFY(minY<m_chart->axisY()->min()); | |
566 | QVERIFY(maxY>m_chart->axisY()->max()); |
|
566 | QVERIFY(maxY>m_chart->axisY()->max()); | |
567 | } |
|
567 | } | |
568 | */ |
|
568 | */ | |
569 | } |
|
569 | } | |
570 |
|
570 | |||
571 | void tst_QChart::zoomOut_data() |
|
571 | void tst_QChart::zoomOut_data() | |
572 | { |
|
572 | { | |
573 |
|
573 | |||
574 | } |
|
574 | } | |
575 |
|
575 | |||
576 | void tst_QChart::zoomOut() |
|
576 | void tst_QChart::zoomOut() | |
577 | { |
|
577 | { | |
578 | qFatal("implement me"); |
|
578 | qFatal("implement me"); | |
579 | createTestData(); |
|
579 | createTestData(); | |
580 | /* |
|
580 | /* | |
581 | qreal minX = m_chart->axisX()->min(); |
|
581 | qreal minX = m_chart->axisX()->min(); | |
582 | qreal minY = m_chart->axisY()->min(); |
|
582 | qreal minY = m_chart->axisY()->min(); | |
583 | qreal maxX = m_chart->axisX()->max(); |
|
583 | qreal maxX = m_chart->axisX()->max(); | |
584 | qreal maxY = m_chart->axisY()->max(); |
|
584 | qreal maxY = m_chart->axisY()->max(); | |
585 |
|
585 | |||
586 | m_chart->zoomIn(); |
|
586 | m_chart->zoomIn(); | |
587 |
|
587 | |||
588 | QVERIFY(minX < m_chart->axisX()->min()); |
|
588 | QVERIFY(minX < m_chart->axisX()->min()); | |
589 | QVERIFY(maxX > m_chart->axisX()->max()); |
|
589 | QVERIFY(maxX > m_chart->axisX()->max()); | |
590 | QVERIFY(minY < m_chart->axisY()->min()); |
|
590 | QVERIFY(minY < m_chart->axisY()->min()); | |
591 | QVERIFY(maxY > m_chart->axisY()->max()); |
|
591 | QVERIFY(maxY > m_chart->axisY()->max()); | |
592 |
|
592 | |||
593 | m_chart->zoomOut(); |
|
593 | m_chart->zoomOut(); | |
594 |
|
594 | |||
595 | // min x may be a zero value |
|
595 | // min x may be a zero value | |
596 | if (qFuzzyIsNull(minX)) |
|
596 | if (qFuzzyIsNull(minX)) | |
597 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); |
|
597 | QVERIFY(qFuzzyIsNull(m_chart->axisX()->min())); | |
598 | else |
|
598 | else | |
599 | QCOMPARE(minX, m_chart->axisX()->min()); |
|
599 | QCOMPARE(minX, m_chart->axisX()->min()); | |
600 |
|
600 | |||
601 | // min y may be a zero value |
|
601 | // min y may be a zero value | |
602 | if (qFuzzyIsNull(minY)) |
|
602 | if (qFuzzyIsNull(minY)) | |
603 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); |
|
603 | QVERIFY(qFuzzyIsNull(m_chart->axisY()->min())); | |
604 | else |
|
604 | else | |
605 | QCOMPARE(minY, m_chart->axisY()->min()); |
|
605 | QCOMPARE(minY, m_chart->axisY()->min()); | |
606 |
|
606 | |||
607 | QVERIFY(maxX == m_chart->axisX()->max()); |
|
607 | QVERIFY(maxX == m_chart->axisX()->max()); | |
608 | QVERIFY(maxY == m_chart->axisY()->max()); |
|
608 | QVERIFY(maxY == m_chart->axisY()->max()); | |
609 | */ |
|
609 | */ | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | QTEST_MAIN(tst_QChart) |
|
612 | QTEST_MAIN(tst_QChart) | |
613 | #include "tst_qchart.moc" |
|
613 | #include "tst_qchart.moc" | |
614 |
|
614 |
@@ -1,364 +1,364 | |||||
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 <qabstractbarseries.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 | #include <QCategoriesAxis> |
|
46 | #include <QCategoriesAxis> | |
47 |
|
47 | |||
48 |
|
48 | |||
49 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
49 | QTCOMMERCIALCHART_USE_NAMESPACE | |
50 |
|
50 | |||
51 | MainWidget::MainWidget(QWidget *parent) : |
|
51 | MainWidget::MainWidget(QWidget *parent) : | |
52 | QWidget(parent), |
|
52 | QWidget(parent), | |
53 | m_addSerieDialog(0), |
|
53 | m_addSerieDialog(0), | |
54 | m_chart(0) |
|
54 | m_chart(0) | |
55 | { |
|
55 | { | |
56 | m_chart = new QChart(); |
|
56 | m_chart = new QChart(); | |
57 |
|
57 | |||
58 | // Grid layout for the controls for configuring the chart widget |
|
58 | // Grid layout for the controls for configuring the chart widget | |
59 | QGridLayout *grid = new QGridLayout(); |
|
59 | QGridLayout *grid = new QGridLayout(); | |
60 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
60 | QPushButton *addSeriesButton = new QPushButton("Add series"); | |
61 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
61 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); | |
62 | grid->addWidget(addSeriesButton, 0, 1); |
|
62 | grid->addWidget(addSeriesButton, 0, 1); | |
63 | initBackroundCombo(grid); |
|
63 | initBackroundCombo(grid); | |
64 | initScaleControls(grid); |
|
64 | initScaleControls(grid); | |
65 | initThemeCombo(grid); |
|
65 | initThemeCombo(grid); | |
66 | initCheckboxes(grid); |
|
66 | initCheckboxes(grid); | |
67 |
|
67 | |||
68 | // add row with empty label to make all the other rows static |
|
68 | // add row with empty label to make all the other rows static | |
69 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
69 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); | |
70 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
70 | grid->setRowStretch(grid->rowCount() - 1, 1); | |
71 |
|
71 | |||
72 | // Create chart view with the chart |
|
72 | // Create chart view with the chart | |
73 | m_chartView = new QChartView(m_chart, this); |
|
73 | m_chartView = new QChartView(m_chart, this); | |
74 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
74 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); | |
75 |
|
75 | |||
76 | // Another grid layout as a main layout |
|
76 | // Another grid layout as a main layout | |
77 | QGridLayout *mainLayout = new QGridLayout(); |
|
77 | QGridLayout *mainLayout = new QGridLayout(); | |
78 | mainLayout->addLayout(grid, 0, 0); |
|
78 | mainLayout->addLayout(grid, 0, 0); | |
79 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
79 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); | |
80 | setLayout(mainLayout); |
|
80 | setLayout(mainLayout); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | // Combo box for selecting the chart's background |
|
83 | // Combo box for selecting the chart's background | |
84 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
84 | void MainWidget::initBackroundCombo(QGridLayout *grid) | |
85 | { |
|
85 | { | |
86 | QComboBox *backgroundCombo = new QComboBox(this); |
|
86 | QComboBox *backgroundCombo = new QComboBox(this); | |
87 | backgroundCombo->addItem("Color"); |
|
87 | backgroundCombo->addItem("Color"); | |
88 | backgroundCombo->addItem("Gradient"); |
|
88 | backgroundCombo->addItem("Gradient"); | |
89 | backgroundCombo->addItem("Image"); |
|
89 | backgroundCombo->addItem("Image"); | |
90 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
90 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), | |
91 | this, SLOT(backgroundChanged(int))); |
|
91 | this, SLOT(backgroundChanged(int))); | |
92 |
|
92 | |||
93 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
93 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); | |
94 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
94 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | // Scale related controls (auto-scale vs. manual min-max values) |
|
97 | // Scale related controls (auto-scale vs. manual min-max values) | |
98 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
98 | void MainWidget::initScaleControls(QGridLayout *grid) | |
99 | { |
|
99 | { | |
100 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
100 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); | |
101 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
101 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); | |
102 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
102 | // Allow setting also non-sense values (like -2147483648 and 2147483647) | |
103 | m_xMinSpin = new QSpinBox(); |
|
103 | m_xMinSpin = new QSpinBox(); | |
104 | m_xMinSpin->setMinimum(INT_MIN); |
|
104 | m_xMinSpin->setMinimum(INT_MIN); | |
105 | m_xMinSpin->setMaximum(INT_MAX); |
|
105 | m_xMinSpin->setMaximum(INT_MAX); | |
106 | m_xMinSpin->setValue(0); |
|
106 | m_xMinSpin->setValue(0); | |
107 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
107 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); | |
108 | m_xMaxSpin = new QSpinBox(); |
|
108 | m_xMaxSpin = new QSpinBox(); | |
109 | m_xMaxSpin->setMinimum(INT_MIN); |
|
109 | m_xMaxSpin->setMinimum(INT_MIN); | |
110 | m_xMaxSpin->setMaximum(INT_MAX); |
|
110 | m_xMaxSpin->setMaximum(INT_MAX); | |
111 | m_xMaxSpin->setValue(10); |
|
111 | m_xMaxSpin->setValue(10); | |
112 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
112 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); | |
113 | m_yMinSpin = new QSpinBox(); |
|
113 | m_yMinSpin = new QSpinBox(); | |
114 | m_yMinSpin->setMinimum(INT_MIN); |
|
114 | m_yMinSpin->setMinimum(INT_MIN); | |
115 | m_yMinSpin->setMaximum(INT_MAX); |
|
115 | m_yMinSpin->setMaximum(INT_MAX); | |
116 | m_yMinSpin->setValue(0); |
|
116 | m_yMinSpin->setValue(0); | |
117 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
117 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); | |
118 | m_yMaxSpin = new QSpinBox(); |
|
118 | m_yMaxSpin = new QSpinBox(); | |
119 | m_yMaxSpin->setMinimum(INT_MIN); |
|
119 | m_yMaxSpin->setMinimum(INT_MIN); | |
120 | m_yMaxSpin->setMaximum(INT_MAX); |
|
120 | m_yMaxSpin->setMaximum(INT_MAX); | |
121 | m_yMaxSpin->setValue(10); |
|
121 | m_yMaxSpin->setValue(10); | |
122 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
122 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); | |
123 |
|
123 | |||
124 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
124 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); | |
125 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
125 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); | |
126 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
126 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); | |
127 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
127 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); | |
128 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
128 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); | |
129 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
129 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); | |
130 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
130 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); | |
131 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
131 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); | |
132 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
132 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); | |
133 |
|
133 | |||
134 | m_autoScaleCheck->setChecked(true); |
|
134 | m_autoScaleCheck->setChecked(true); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | // Combo box for selecting theme |
|
137 | // Combo box for selecting theme | |
138 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
138 | void MainWidget::initThemeCombo(QGridLayout *grid) | |
139 | { |
|
139 | { | |
140 | QComboBox *chartTheme = new QComboBox(); |
|
140 | QComboBox *chartTheme = new QComboBox(); | |
141 | chartTheme->addItem("Default"); |
|
141 | chartTheme->addItem("Default"); | |
142 | chartTheme->addItem("Light"); |
|
142 | chartTheme->addItem("Light"); | |
143 | chartTheme->addItem("Blue Cerulean"); |
|
143 | chartTheme->addItem("Blue Cerulean"); | |
144 | chartTheme->addItem("Dark"); |
|
144 | chartTheme->addItem("Dark"); | |
145 | chartTheme->addItem("Brown Sand"); |
|
145 | chartTheme->addItem("Brown Sand"); | |
146 | chartTheme->addItem("Blue NCS"); |
|
146 | chartTheme->addItem("Blue NCS"); | |
147 | chartTheme->addItem("High Contrast"); |
|
147 | chartTheme->addItem("High Contrast"); | |
148 | chartTheme->addItem("Blue Icy"); |
|
148 | chartTheme->addItem("Blue Icy"); | |
149 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
149 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), | |
150 | this, SLOT(changeChartTheme(int))); |
|
150 | this, SLOT(changeChartTheme(int))); | |
151 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
151 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); | |
152 | grid->addWidget(chartTheme, 8, 1); |
|
152 | grid->addWidget(chartTheme, 8, 1); | |
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | // Different check boxes for customizing chart |
|
155 | // Different check boxes for customizing chart | |
156 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
156 | void MainWidget::initCheckboxes(QGridLayout *grid) | |
157 | { |
|
157 | { | |
158 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
158 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off | |
159 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
159 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); | |
160 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
160 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); | |
161 | zoomCheckBox->setChecked(true); |
|
161 | zoomCheckBox->setChecked(true); | |
162 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
162 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); | |
163 |
|
163 | |||
164 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
164 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); | |
165 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
165 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); | |
166 | aliasCheckBox->setChecked(false); |
|
166 | aliasCheckBox->setChecked(false); | |
167 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
167 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | void MainWidget::antiAliasToggled(bool enabled) |
|
170 | void MainWidget::antiAliasToggled(bool enabled) | |
171 | { |
|
171 | { | |
172 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
172 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); | |
173 | } |
|
173 | } | |
174 |
|
174 | |||
175 | void MainWidget::addSeries() |
|
175 | void MainWidget::addSeries() | |
176 | { |
|
176 | { | |
177 | if (!m_addSerieDialog) { |
|
177 | if (!m_addSerieDialog) { | |
178 | m_addSerieDialog = new DataSerieDialog(this); |
|
178 | m_addSerieDialog = new DataSerieDialog(this); | |
179 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), |
|
179 | connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)), | |
180 | this, SLOT(addSeries(QString,int,int,QString,bool))); |
|
180 | this, SLOT(addSeries(QString,int,int,QString,bool))); | |
181 | } |
|
181 | } | |
182 | m_addSerieDialog->exec(); |
|
182 | m_addSerieDialog->exec(); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
185 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) | |
186 | { |
|
186 | { | |
187 | // TODO: dataCharacteristics |
|
187 | // TODO: dataCharacteristics | |
188 | QList<RealList> testData; |
|
188 | QList<RealList> testData; | |
189 | for (int j(0); j < columnCount; j++) { |
|
189 | for (int j(0); j < columnCount; j++) { | |
190 | QList <qreal> newColumn; |
|
190 | QList <qreal> newColumn; | |
191 | for (int i(0); i < rowCount; i++) { |
|
191 | for (int i(0); i < rowCount; i++) { | |
192 | if (dataCharacteristics == "Sin") { |
|
192 | if (dataCharacteristics == "Sin") { | |
193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); | |
194 | } else if (dataCharacteristics == "Sin + random") { |
|
194 | } else if (dataCharacteristics == "Sin + random") { | |
195 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
195 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); | |
196 | } else if (dataCharacteristics == "Random") { |
|
196 | } else if (dataCharacteristics == "Random") { | |
197 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
197 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); | |
198 | } else if (dataCharacteristics == "Linear") { |
|
198 | } else if (dataCharacteristics == "Linear") { | |
199 | //newColumn.append(i * (j + 1.0)); |
|
199 | //newColumn.append(i * (j + 1.0)); | |
200 | // TODO: temporary hack to make pie work; prevent zero values: |
|
200 | // TODO: temporary hack to make pie work; prevent zero values: | |
201 | newColumn.append(i * (j + 1.0) + 0.1); |
|
201 | newColumn.append(i * (j + 1.0) + 0.1); | |
202 | } else { // "constant" |
|
202 | } else { // "constant" | |
203 | newColumn.append((j + 1.0)); |
|
203 | newColumn.append((j + 1.0)); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 | testData.append(newColumn); |
|
206 | testData.append(newColumn); | |
207 | } |
|
207 | } | |
208 | return testData; |
|
208 | return testData; | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | QStringList MainWidget::generateLabels(int count) |
|
211 | QStringList MainWidget::generateLabels(int count) | |
212 | { |
|
212 | { | |
213 | QStringList result; |
|
213 | QStringList result; | |
214 | for (int i(0); i < count; i++) |
|
214 | for (int i(0); i < count; i++) | |
215 | result.append("label" + QString::number(i)); |
|
215 | result.append("label" + QString::number(i)); | |
216 | return result; |
|
216 | return result; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
219 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) | |
220 | { |
|
220 | { | |
221 | qDebug() << "addSeries: " << seriesName |
|
221 | qDebug() << "addSeries: " << seriesName | |
222 | << " columnCount: " << columnCount |
|
222 | << " columnCount: " << columnCount | |
223 | << " rowCount: " << rowCount |
|
223 | << " rowCount: " << rowCount | |
224 | << " dataCharacteristics: " << dataCharacteristics |
|
224 | << " dataCharacteristics: " << dataCharacteristics | |
225 | << " labels enabled: " << labelsEnabled; |
|
225 | << " labels enabled: " << labelsEnabled; | |
226 | m_defaultSeriesName = seriesName; |
|
226 | m_defaultSeriesName = seriesName; | |
227 |
|
227 | |||
228 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
228 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); | |
229 |
|
229 | |||
230 | // Line series and scatter series use similar data |
|
230 | // Line series and scatter series use similar data | |
231 | if (seriesName == "Line") { |
|
231 | if (seriesName == "Line") { | |
232 | for (int j(0); j < data.count(); j ++) { |
|
232 | for (int j(0); j < data.count(); j ++) { | |
233 | QList<qreal> column = data.at(j); |
|
233 | QList<qreal> column = data.at(j); | |
234 | QLineSeries *series = new QLineSeries(); |
|
234 | QLineSeries *series = new QLineSeries(); | |
235 | series->setName("line" + QString::number(j)); |
|
235 | series->setName("line" + QString::number(j)); | |
236 | for (int i(0); i < column.count(); i++) |
|
236 | for (int i(0); i < column.count(); i++) | |
237 | series->append(i, column.at(i)); |
|
237 | series->append(i, column.at(i)); | |
238 | m_chart->addSeries(series); |
|
238 | m_chart->addSeries(series); | |
239 | } |
|
239 | } | |
240 | } else if (seriesName == "Area") { |
|
240 | } else if (seriesName == "Area") { | |
241 | // TODO: lower series for the area? |
|
241 | // TODO: lower series for the area? | |
242 | for (int j(0); j < data.count(); j ++) { |
|
242 | for (int j(0); j < data.count(); j ++) { | |
243 | QList<qreal> column = data.at(j); |
|
243 | QList<qreal> column = data.at(j); | |
244 | QLineSeries *lineSeries = new QLineSeries(); |
|
244 | QLineSeries *lineSeries = new QLineSeries(); | |
245 | for (int i(0); i < column.count(); i++) |
|
245 | for (int i(0); i < column.count(); i++) | |
246 | lineSeries->append(i, column.at(i)); |
|
246 | lineSeries->append(i, column.at(i)); | |
247 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
247 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); | |
248 | areaSeries->setName("area" + QString::number(j)); |
|
248 | areaSeries->setName("area" + QString::number(j)); | |
249 | m_chart->addSeries(areaSeries); |
|
249 | m_chart->addSeries(areaSeries); | |
250 | } |
|
250 | } | |
251 | } else if (seriesName == "Scatter") { |
|
251 | } else if (seriesName == "Scatter") { | |
252 | for (int j(0); j < data.count(); j++) { |
|
252 | for (int j(0); j < data.count(); j++) { | |
253 | QList<qreal> column = data.at(j); |
|
253 | QList<qreal> column = data.at(j); | |
254 | QScatterSeries *series = new QScatterSeries(); |
|
254 | QScatterSeries *series = new QScatterSeries(); | |
255 | series->setName("scatter" + QString::number(j)); |
|
255 | series->setName("scatter" + QString::number(j)); | |
256 | for (int i(0); i < column.count(); i++) |
|
256 | for (int i(0); i < column.count(); i++) | |
257 | series->append(i, column.at(i)); |
|
257 | series->append(i, column.at(i)); | |
258 | m_chart->addSeries(series); |
|
258 | m_chart->addSeries(series); | |
259 | } |
|
259 | } | |
260 | } else if (seriesName == "Pie") { |
|
260 | } else if (seriesName == "Pie") { | |
261 | QStringList labels = generateLabels(rowCount); |
|
261 | QStringList labels = generateLabels(rowCount); | |
262 | for (int j(0); j < data.count(); j++) { |
|
262 | for (int j(0); j < data.count(); j++) { | |
263 | QPieSeries *series = new QPieSeries(); |
|
263 | QPieSeries *series = new QPieSeries(); | |
264 | QList<qreal> column = data.at(j); |
|
264 | QList<qreal> column = data.at(j); | |
265 | for (int i(0); i < column.count(); i++) |
|
265 | for (int i(0); i < column.count(); i++) | |
266 | series->append(labels.at(i), column.at(i)); |
|
266 | series->append(labels.at(i), column.at(i)); | |
267 | m_chart->addSeries(series); |
|
267 | m_chart->addSeries(series); | |
268 | } |
|
268 | } | |
269 | } else if (seriesName == "Bar" |
|
269 | } else if (seriesName == "Bar" | |
270 | || seriesName == "Grouped bar" |
|
270 | || seriesName == "Grouped bar" | |
271 | || seriesName == "Stacked bar" |
|
271 | || seriesName == "Stacked bar" | |
272 | || seriesName == "Percent bar") { |
|
272 | || seriesName == "Percent bar") { | |
273 | QStringList category; |
|
273 | QStringList category; | |
274 | QStringList labels = generateLabels(rowCount); |
|
274 | QStringList labels = generateLabels(rowCount); | |
275 | foreach(QString label, labels) |
|
275 | foreach(QString label, labels) | |
276 | category << label; |
|
276 | category << label; | |
277 | QAbstractBarSeries* series = 0; |
|
277 | QAbstractBarSeries* series = 0; | |
278 | if (seriesName == "Bar") { |
|
278 | if (seriesName == "Bar") { | |
279 | series = new QAbstractBarSeries(this); |
|
279 | series = new QAbstractBarSeries(this); | |
280 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
280 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
281 | axis->append(category); |
|
281 | axis->append(category); | |
282 | m_chart->setAxisX(axis,series); |
|
282 | m_chart->setAxisX(axis,series); | |
283 | } else if (seriesName == "Grouped bar") { |
|
283 | } else if (seriesName == "Grouped bar") { | |
284 | series = new QGroupedBarSeries(this); |
|
284 | series = new QGroupedBarSeries(this); | |
285 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
285 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
286 | axis->append(category); |
|
286 | axis->append(category); | |
287 | m_chart->setAxisX(axis,series); |
|
287 | m_chart->setAxisX(axis,series); | |
288 | } else if (seriesName == "Stacked bar") { |
|
288 | } else if (seriesName == "Stacked bar") { | |
289 | series = new QStackedBarSeries(this); |
|
289 | series = new QStackedBarSeries(this); | |
290 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
290 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
291 | axis->append(category); |
|
291 | axis->append(category); | |
292 | m_chart->setAxisX(axis,series); |
|
292 | m_chart->setAxisX(axis,series); | |
293 | } else { |
|
293 | } else { | |
294 | series = new QPercentBarSeries(this); |
|
294 | series = new QPercentBarSeries(this); | |
295 | QCategoriesAxis* axis = new QCategoriesAxis(); |
|
295 | QCategoriesAxis* axis = new QCategoriesAxis(); | |
296 | axis->append(category); |
|
296 | axis->append(category); | |
297 | m_chart->setAxisX(axis,series); |
|
297 | m_chart->setAxisX(axis,series); | |
298 | } |
|
298 | } | |
299 |
|
299 | |||
300 | for (int j(0); j < data.count(); j++) { |
|
300 | for (int j(0); j < data.count(); j++) { | |
301 | QList<qreal> column = data.at(j); |
|
301 | QList<qreal> column = data.at(j); | |
302 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
302 | QBarSet *set = new QBarSet("set" + QString::number(j)); | |
303 | for (int i(0); i < column.count(); i++) |
|
303 | for (int i(0); i < column.count(); i++) | |
304 | *set << column.at(i); |
|
304 | *set << column.at(i); | |
305 | series->append(set); |
|
305 | series->append(set); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | m_chart->addSeries(series); |
|
308 | m_chart->addSeries(series); | |
309 | } else if (seriesName == "Spline") { |
|
309 | } else if (seriesName == "Spline") { | |
310 | for (int j(0); j < data.count(); j ++) { |
|
310 | for (int j(0); j < data.count(); j ++) { | |
311 | QList<qreal> column = data.at(j); |
|
311 | QList<qreal> column = data.at(j); | |
312 | QSplineSeries *series = new QSplineSeries(); |
|
312 | QSplineSeries *series = new QSplineSeries(); | |
313 | for (int i(0); i < column.count(); i++) |
|
313 | for (int i(0); i < column.count(); i++) | |
314 | series->append(i, column.at(i)); |
|
314 | series->append(i, column.at(i)); | |
315 | m_chart->addSeries(series); |
|
315 | m_chart->addSeries(series); | |
316 | } |
|
316 | } | |
317 | } |
|
317 | } | |
318 | m_chart->createDefaultAxes(); |
|
318 | m_chart->createDefaultAxes(); | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 | void MainWidget::backgroundChanged(int itemIndex) |
|
321 | void MainWidget::backgroundChanged(int itemIndex) | |
322 | { |
|
322 | { | |
323 | qDebug() << "backgroundChanged: " << itemIndex; |
|
323 | qDebug() << "backgroundChanged: " << itemIndex; | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | void MainWidget::autoScaleChanged(int value) |
|
326 | void MainWidget::autoScaleChanged(int value) | |
327 | { |
|
327 | { | |
328 | if (value) { |
|
328 | if (value) { | |
329 | // TODO: enable auto scaling |
|
329 | // TODO: enable auto scaling | |
330 | } else { |
|
330 | } else { | |
331 | // TODO: set scaling manually (and disable auto scaling) |
|
331 | // TODO: set scaling manually (and disable auto scaling) | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | m_xMinSpin->setEnabled(!value); |
|
334 | m_xMinSpin->setEnabled(!value); | |
335 | m_xMaxSpin->setEnabled(!value); |
|
335 | m_xMaxSpin->setEnabled(!value); | |
336 | m_yMinSpin->setEnabled(!value); |
|
336 | m_yMinSpin->setEnabled(!value); | |
337 | m_yMaxSpin->setEnabled(!value); |
|
337 | m_yMaxSpin->setEnabled(!value); | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | void MainWidget::xMinChanged(int value) |
|
340 | void MainWidget::xMinChanged(int value) | |
341 | { |
|
341 | { | |
342 | qDebug() << "xMinChanged: " << value; |
|
342 | qDebug() << "xMinChanged: " << value; | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | void MainWidget::xMaxChanged(int value) |
|
345 | void MainWidget::xMaxChanged(int value) | |
346 | { |
|
346 | { | |
347 | qDebug() << "xMaxChanged: " << value; |
|
347 | qDebug() << "xMaxChanged: " << value; | |
348 | } |
|
348 | } | |
349 |
|
349 | |||
350 | void MainWidget::yMinChanged(int value) |
|
350 | void MainWidget::yMinChanged(int value) | |
351 | { |
|
351 | { | |
352 | qDebug() << "yMinChanged: " << value; |
|
352 | qDebug() << "yMinChanged: " << value; | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | void MainWidget::yMaxChanged(int value) |
|
355 | void MainWidget::yMaxChanged(int value) | |
356 | { |
|
356 | { | |
357 | qDebug() << "yMaxChanged: " << value; |
|
357 | qDebug() << "yMaxChanged: " << value; | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | void MainWidget::changeChartTheme(int themeIndex) |
|
360 | void MainWidget::changeChartTheme(int themeIndex) | |
361 | { |
|
361 | { | |
362 | qDebug() << "changeChartTheme: " << themeIndex; |
|
362 | qDebug() << "changeChartTheme: " << themeIndex; | |
363 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
363 | m_chart->setTheme((QChart::ChartTheme) themeIndex); | |
364 | } |
|
364 | } |
General Comments 0
You need to be logged in to leave comments.
Login now