@@ -1,386 +1,385 | |||||
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 <QAbstractBarSeries> |
|
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(); |
|
|||
255 |
|
||||
256 | } |
|
254 | } | |
|
255 | chart->createDefaultAxes(); | |||
257 |
|
256 | |||
258 | return chart; |
|
257 | return chart; | |
259 | } |
|
258 | } | |
260 |
|
259 | |||
261 | QChart* ThemeWidget::createPieChart() const |
|
260 | QChart* ThemeWidget::createPieChart() const | |
262 | { |
|
261 | { | |
263 | QChart* chart = new QChart(); |
|
262 | QChart* chart = new QChart(); | |
264 | chart->setTitle("Pie chart"); |
|
263 | chart->setTitle("Pie chart"); | |
265 |
|
264 | |||
266 | qreal pieSize = 1.0 / m_dataTable.count(); |
|
265 | qreal pieSize = 1.0 / m_dataTable.count(); | |
267 | for (int i = 0; i < m_dataTable.count(); i++) { |
|
266 | for (int i = 0; i < m_dataTable.count(); i++) { | |
268 | QPieSeries *series = new QPieSeries(chart); |
|
267 | QPieSeries *series = new QPieSeries(chart); | |
269 | foreach (Data data, m_dataTable[i]) { |
|
268 | foreach (Data data, m_dataTable[i]) { | |
270 | QPieSlice *slice = series->append(data.second, data.first.y()); |
|
269 | QPieSlice *slice = series->append(data.second, data.first.y()); | |
271 | if (data == m_dataTable[i].first()) { |
|
270 | if (data == m_dataTable[i].first()) { | |
272 | slice->setLabelVisible(); |
|
271 | slice->setLabelVisible(); | |
273 | slice->setExploded(); |
|
272 | slice->setExploded(); | |
274 | } |
|
273 | } | |
275 | } |
|
274 | } | |
276 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); |
|
275 | qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count()); | |
277 | series->setPieSize(pieSize); |
|
276 | series->setPieSize(pieSize); | |
278 | series->setHorizontalPosition(hPos); |
|
277 | series->setHorizontalPosition(hPos); | |
279 | series->setVerticalPosition(0.5); |
|
278 | series->setVerticalPosition(0.5); | |
280 | chart->addSeries(series); |
|
279 | chart->addSeries(series); | |
281 | } |
|
280 | } | |
282 |
|
281 | |||
283 | return chart; |
|
282 | return chart; | |
284 | } |
|
283 | } | |
285 |
|
284 | |||
286 | QChart* ThemeWidget::createSplineChart() const |
|
285 | QChart* ThemeWidget::createSplineChart() const | |
287 | { // spine chart |
|
286 | { // spine chart | |
288 | QChart* chart = new QChart(); |
|
287 | QChart* chart = new QChart(); | |
289 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
288 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
290 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
289 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
291 | chart->setTitle("Spline chart"); |
|
290 | chart->setTitle("Spline chart"); | |
292 | QString name("Series "); |
|
291 | QString name("Series "); | |
293 | int nameIndex = 0; |
|
292 | int nameIndex = 0; | |
294 | foreach (DataList list, m_dataTable) { |
|
293 | foreach (DataList list, m_dataTable) { | |
295 | QSplineSeries *series = new QSplineSeries(chart); |
|
294 | QSplineSeries *series = new QSplineSeries(chart); | |
296 | foreach (Data data, list) |
|
295 | foreach (Data data, list) | |
297 | series->append(data.first); |
|
296 | series->append(data.first); | |
298 | series->setName(name + QString::number(nameIndex)); |
|
297 | series->setName(name + QString::number(nameIndex)); | |
299 | nameIndex++; |
|
298 | nameIndex++; | |
300 | chart->addSeries(series); |
|
299 | chart->addSeries(series); | |
301 | chart->createDefaultAxes(); |
|
|||
302 | } |
|
300 | } | |
|
301 | chart->createDefaultAxes(); | |||
303 | return chart; |
|
302 | return chart; | |
304 | } |
|
303 | } | |
305 |
|
304 | |||
306 | QChart* ThemeWidget::createScatterChart() const |
|
305 | QChart* ThemeWidget::createScatterChart() const | |
307 | { // scatter chart |
|
306 | { // scatter chart | |
308 | QChart* chart = new QChart(); |
|
307 | QChart* chart = new QChart(); | |
309 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); |
|
308 | //TODO: chart->axisX()->setNiceNumbersEnabled(true); | |
310 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); |
|
309 | //TODO: chart->axisY()->setNiceNumbersEnabled(true); | |
311 | chart->setTitle("Scatter chart"); |
|
310 | chart->setTitle("Scatter chart"); | |
312 | QString name("Series "); |
|
311 | QString name("Series "); | |
313 | int nameIndex = 0; |
|
312 | int nameIndex = 0; | |
314 | foreach (DataList list, m_dataTable) { |
|
313 | foreach (DataList list, m_dataTable) { | |
315 | QScatterSeries *series = new QScatterSeries(chart); |
|
314 | QScatterSeries *series = new QScatterSeries(chart); | |
316 | foreach (Data data, list) |
|
315 | foreach (Data data, list) | |
317 | series->append(data.first); |
|
316 | series->append(data.first); | |
318 | series->setName(name + QString::number(nameIndex)); |
|
317 | series->setName(name + QString::number(nameIndex)); | |
319 | nameIndex++; |
|
318 | nameIndex++; | |
320 | chart->addSeries(series); |
|
319 | chart->addSeries(series); | |
321 | chart->createDefaultAxes(); |
|
|||
322 | } |
|
320 | } | |
|
321 | chart->createDefaultAxes(); | |||
323 | return chart; |
|
322 | return chart; | |
324 | } |
|
323 | } | |
325 |
|
324 | |||
326 | void ThemeWidget::updateUI() |
|
325 | void ThemeWidget::updateUI() | |
327 | { |
|
326 | { | |
328 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); |
|
327 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt(); | |
329 |
|
328 | |||
330 | if (m_charts.at(0)->chart()->theme() != theme) { |
|
329 | if (m_charts.at(0)->chart()->theme() != theme) { | |
331 | foreach (QChartView *chartView, m_charts) |
|
330 | foreach (QChartView *chartView, m_charts) | |
332 | chartView->chart()->setTheme(theme); |
|
331 | chartView->chart()->setTheme(theme); | |
333 |
|
332 | |||
334 | QPalette pal = window()->palette(); |
|
333 | QPalette pal = window()->palette(); | |
335 | if (theme == QChart::ChartThemeLight) { |
|
334 | if (theme == QChart::ChartThemeLight) { | |
336 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
335 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
337 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
336 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
338 | } else if (theme == QChart::ChartThemeDark) { |
|
337 | } else if (theme == QChart::ChartThemeDark) { | |
339 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
338 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
340 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
339 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
341 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
340 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
342 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
341 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
343 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
342 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
344 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
343 | } else if (theme == QChart::ChartThemeBrownSand) { | |
345 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
344 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
346 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
345 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
347 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
346 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
348 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
347 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
349 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
348 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
350 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
349 | } else if (theme == QChart::ChartThemeHighContrast) { | |
351 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
350 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
352 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
351 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
353 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
352 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
354 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
353 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
355 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
354 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
356 | } else { |
|
355 | } else { | |
357 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
356 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
358 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
357 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
359 | } |
|
358 | } | |
360 | window()->setPalette(pal); |
|
359 | window()->setPalette(pal); | |
361 | } |
|
360 | } | |
362 |
|
361 | |||
363 | bool checked = m_antialiasCheckBox->isChecked(); |
|
362 | bool checked = m_antialiasCheckBox->isChecked(); | |
364 | foreach (QChartView *chart, m_charts) |
|
363 | foreach (QChartView *chart, m_charts) | |
365 | chart->setRenderHint(QPainter::Antialiasing, checked); |
|
364 | chart->setRenderHint(QPainter::Antialiasing, checked); | |
366 |
|
365 | |||
367 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
366 | QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
368 | if (m_charts.at(0)->chart()->animationOptions() != options) { |
|
367 | if (m_charts.at(0)->chart()->animationOptions() != options) { | |
369 | foreach (QChartView *chartView, m_charts) |
|
368 | foreach (QChartView *chartView, m_charts) | |
370 | chartView->chart()->setAnimationOptions(options); |
|
369 | chartView->chart()->setAnimationOptions(options); | |
371 | } |
|
370 | } | |
372 |
|
371 | |||
373 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
372 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
374 |
|
373 | |||
375 | if (!alignment) { |
|
374 | if (!alignment) { | |
376 | foreach (QChartView *chartView, m_charts) { |
|
375 | foreach (QChartView *chartView, m_charts) { | |
377 | chartView->chart()->legend()->hide(); |
|
376 | chartView->chart()->legend()->hide(); | |
378 | } |
|
377 | } | |
379 | } else { |
|
378 | } else { | |
380 | foreach (QChartView *chartView, m_charts) { |
|
379 | foreach (QChartView *chartView, m_charts) { | |
381 | chartView->chart()->legend()->setAlignment(alignment); |
|
380 | chartView->chart()->legend()->setAlignment(alignment); | |
382 | chartView->chart()->legend()->show(); |
|
381 | chartView->chart()->legend()->show(); | |
383 | } |
|
382 | } | |
384 | } |
|
383 | } | |
385 | } |
|
384 | } | |
386 |
|
385 |
@@ -1,396 +1,406 | |||||
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 "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "legendmarker_p.h" |
|
25 | #include "legendmarker_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_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 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAreaSeries |
|
35 | \class QAreaSeries | |
36 | \brief The QAreaSeries class is used for making area charts. |
|
36 | \brief The QAreaSeries class is used for making area charts. | |
37 |
|
37 | |||
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
45 |
|
45 | |||
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
47 | \image examples_areachart.png |
|
47 | \image examples_areachart.png | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AreaSeries QAreaSeries |
|
50 | \qmlclass AreaSeries QAreaSeries | |
51 |
|
51 | |||
52 | The following QML shows how to create a simple area chart: |
|
52 | The following QML shows how to create a simple area chart: | |
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
54 | \beginfloatleft |
|
54 | \beginfloatleft | |
55 | \image demos_qmlchart4.png |
|
55 | \image demos_qmlchart4.png | |
56 | \endfloat |
|
56 | \endfloat | |
57 | \clearfloat |
|
57 | \clearfloat | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QAreaSeries::upperSeries |
|
61 | \property QAreaSeries::upperSeries | |
62 | \brief The upper one of the two line series used to define area series boundaries. |
|
62 | \brief The upper one of the two line series used to define area series boundaries. | |
63 | */ |
|
63 | */ | |
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
65 | \qmlproperty LineSeries AreaSeries::upperSeries | |
66 | The upper one of the two line series used to define area series boundaries. |
|
66 | The upper one of the two line series used to define area series boundaries. | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QAreaSeries::lowerSeries |
|
70 | \property QAreaSeries::lowerSeries | |
71 | The lower one of the two line series used to define are series boundaries. Note if |
|
71 | The lower one of the two line series used to define are series boundaries. Note if | |
72 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
72 | QAreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
73 | */ |
|
73 | */ | |
74 | /*! |
|
74 | /*! | |
75 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
75 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
76 | The lower one of the two line series used to define are series boundaries. Note if |
|
76 | The lower one of the two line series used to define are series boundaries. Note if | |
77 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. |
|
77 | AreaSeries was counstucted wihtout a\ lowerSeries this is null. | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QAreaSeries::color |
|
81 | \property QAreaSeries::color | |
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
83 | \sa QAreaSeries::brush() |
|
83 | \sa QAreaSeries::brush() | |
84 | */ |
|
84 | */ | |
85 | /*! |
|
85 | /*! | |
86 | \qmlproperty color AreaSeries::color |
|
86 | \qmlproperty color AreaSeries::color | |
87 | Fill (brush) color of the series. |
|
87 | Fill (brush) color of the series. | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \property QAreaSeries::borderColor |
|
91 | \property QAreaSeries::borderColor | |
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
93 | \sa QAreaSeries::pen() |
|
93 | \sa QAreaSeries::pen() | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlproperty color AreaSeries::borderColor |
|
96 | \qmlproperty color AreaSeries::borderColor | |
97 | Line (pen) color of the series. |
|
97 | Line (pen) color of the series. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn QPen QAreaSeries::pen() const |
|
101 | \fn QPen QAreaSeries::pen() const | |
102 | \brief Returns the pen used to draw line for this series. |
|
102 | \brief Returns the pen used to draw line for this series. | |
103 | \sa setPen() |
|
103 | \sa setPen() | |
104 | */ |
|
104 | */ | |
105 |
|
105 | |||
106 | /*! |
|
106 | /*! | |
107 | \fn QPen QAreaSeries::brush() const |
|
107 | \fn QPen QAreaSeries::brush() const | |
108 | \brief Returns the brush used to draw line for this series. |
|
108 | \brief Returns the brush used to draw line for this series. | |
109 | \sa setBrush() |
|
109 | \sa setBrush() | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QAreaSeries::colorChanged(QColor color) |
|
113 | \fn void QAreaSeries::colorChanged(QColor color) | |
114 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
114 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
115 | */ |
|
115 | */ | |
116 | /*! |
|
116 | /*! | |
117 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
117 | \qmlsignal AreaSeries::onColorChanged(color color) | |
118 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
118 | Signal is emitted when the fill (brush) color has changed to \a color. | |
119 | */ |
|
119 | */ | |
120 |
|
120 | |||
121 | /*! |
|
121 | /*! | |
122 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
122 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
123 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
123 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
124 | */ |
|
124 | */ | |
125 | /*! |
|
125 | /*! | |
126 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
126 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
127 | Signal is emitted when the line (pen) color has changed to \a color. |
|
127 | Signal is emitted when the line (pen) color has changed to \a color. | |
128 | */ |
|
128 | */ | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
131 | \fn void QAreaSeries::clicked(const QPointF& point) | |
132 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
132 | \brief Signal is emitted when user clicks the \a point on area chart. | |
133 | */ |
|
133 | */ | |
134 | /*! |
|
134 | /*! | |
135 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
135 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
136 | Signal is emitted when user clicks the \a point on area chart. |
|
136 | Signal is emitted when user clicks the \a point on area chart. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \fn void QAreaSeries::selected() |
|
140 | \fn void QAreaSeries::selected() | |
141 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
141 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
142 | implemented by the user of QAreaSeries API. |
|
142 | implemented by the user of QAreaSeries API. | |
143 | */ |
|
143 | */ | |
144 | /*! |
|
144 | /*! | |
145 | \qmlsignal AreaSeries::onSelected() |
|
145 | \qmlsignal AreaSeries::onSelected() | |
146 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
146 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
147 | implemented by the user of AreaSeries API. |
|
147 | implemented by the user of AreaSeries API. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QAreaSeriesPrivate::updated() |
|
151 | \fn void QAreaSeriesPrivate::updated() | |
152 | \brief \internal |
|
152 | \brief \internal | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
156 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
157 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
157 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
158 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
158 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
159 | */ |
|
159 | */ | |
160 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
160 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
161 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) |
|
161 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries,lowerSeries,this),upperSeries) | |
162 | { |
|
162 | { | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | Constructs area series object without upper or lower series with \a parent object. |
|
166 | Constructs area series object without upper or lower series with \a parent object. | |
167 | */ |
|
167 | */ | |
168 | QAreaSeries::QAreaSeries(QObject *parent) |
|
168 | QAreaSeries::QAreaSeries(QObject *parent) | |
169 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
169 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
170 | { |
|
170 | { | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | Destroys the object. |
|
174 | Destroys the object. | |
175 | */ |
|
175 | */ | |
176 | QAreaSeries::~QAreaSeries() |
|
176 | QAreaSeries::~QAreaSeries() | |
177 | { |
|
177 | { | |
178 | } |
|
178 | } | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | Returns QChartSeries::SeriesTypeArea. |
|
181 | Returns QChartSeries::SeriesTypeArea. | |
182 | */ |
|
182 | */ | |
183 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
183 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
184 | { |
|
184 | { | |
185 | return QAbstractSeries::SeriesTypeArea; |
|
185 | return QAbstractSeries::SeriesTypeArea; | |
186 | } |
|
186 | } | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | Sets the \a series that is to be used as the area chart upper series. |
|
189 | Sets the \a series that is to be used as the area chart upper series. | |
190 | */ |
|
190 | */ | |
191 | void QAreaSeries::setUpperSeries(QLineSeries* series) |
|
191 | void QAreaSeries::setUpperSeries(QLineSeries* series) | |
192 | { |
|
192 | { | |
193 | Q_D(QAreaSeries); |
|
193 | Q_D(QAreaSeries); | |
194 | d->m_upperSeries = series; |
|
194 | d->m_upperSeries = series; | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | QLineSeries* QAreaSeries::upperSeries() const |
|
197 | QLineSeries* QAreaSeries::upperSeries() const | |
198 | { |
|
198 | { | |
199 | Q_D(const QAreaSeries); |
|
199 | Q_D(const QAreaSeries); | |
200 | return d->m_upperSeries; |
|
200 | return d->m_upperSeries; | |
201 | } |
|
201 | } | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | Sets the \a series that is to be used as the area chart lower series. |
|
204 | Sets the \a series that is to be used as the area chart lower series. | |
205 | */ |
|
205 | */ | |
206 | void QAreaSeries::setLowerSeries(QLineSeries* series) |
|
206 | void QAreaSeries::setLowerSeries(QLineSeries* series) | |
207 | { |
|
207 | { | |
208 | Q_D(QAreaSeries); |
|
208 | Q_D(QAreaSeries); | |
209 | d->m_lowerSeries = series; |
|
209 | d->m_lowerSeries = series; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | QLineSeries* QAreaSeries::lowerSeries() const |
|
212 | QLineSeries* QAreaSeries::lowerSeries() const | |
213 | { |
|
213 | { | |
214 | Q_D(const QAreaSeries); |
|
214 | Q_D(const QAreaSeries); | |
215 | return d->m_lowerSeries; |
|
215 | return d->m_lowerSeries; | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Sets \a pen used for drawing area outline. |
|
219 | Sets \a pen used for drawing area outline. | |
220 | */ |
|
220 | */ | |
221 | void QAreaSeries::setPen(const QPen &pen) |
|
221 | void QAreaSeries::setPen(const QPen &pen) | |
222 | { |
|
222 | { | |
223 | Q_D(QAreaSeries); |
|
223 | Q_D(QAreaSeries); | |
224 | if (d->m_pen != pen) { |
|
224 | if (d->m_pen != pen) { | |
225 | d->m_pen = pen; |
|
225 | d->m_pen = pen; | |
226 | emit d->updated(); |
|
226 | emit d->updated(); | |
227 | } |
|
227 | } | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | QPen QAreaSeries::pen() const |
|
230 | QPen QAreaSeries::pen() const | |
231 | { |
|
231 | { | |
232 | Q_D(const QAreaSeries); |
|
232 | Q_D(const QAreaSeries); | |
233 | return d->m_pen; |
|
233 | return d->m_pen; | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | Sets \a brush used for filling the area. |
|
237 | Sets \a brush used for filling the area. | |
238 | */ |
|
238 | */ | |
239 | void QAreaSeries::setBrush(const QBrush &brush) |
|
239 | void QAreaSeries::setBrush(const QBrush &brush) | |
240 | { |
|
240 | { | |
241 | Q_D(QAreaSeries); |
|
241 | Q_D(QAreaSeries); | |
242 | if (d->m_brush != brush) { |
|
242 | if (d->m_brush != brush) { | |
243 | d->m_brush = brush; |
|
243 | d->m_brush = brush; | |
244 | emit d->updated(); |
|
244 | emit d->updated(); | |
245 | } |
|
245 | } | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | QBrush QAreaSeries::brush() const |
|
248 | QBrush QAreaSeries::brush() const | |
249 | { |
|
249 | { | |
250 | Q_D(const QAreaSeries); |
|
250 | Q_D(const QAreaSeries); | |
251 | return d->m_brush; |
|
251 | return d->m_brush; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void QAreaSeries::setColor(const QColor &color) |
|
254 | void QAreaSeries::setColor(const QColor &color) | |
255 | { |
|
255 | { | |
256 | QBrush b = brush(); |
|
256 | QBrush b = brush(); | |
257 | if (b.color() != color) { |
|
257 | if (b.color() != color) { | |
258 | b.setColor(color); |
|
258 | b.setColor(color); | |
259 | setBrush(b); |
|
259 | setBrush(b); | |
260 | emit colorChanged(color); |
|
260 | emit colorChanged(color); | |
261 | } |
|
261 | } | |
262 | } |
|
262 | } | |
263 |
|
263 | |||
264 | QColor QAreaSeries::color() const |
|
264 | QColor QAreaSeries::color() const | |
265 | { |
|
265 | { | |
266 | return brush().color(); |
|
266 | return brush().color(); | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void QAreaSeries::setBorderColor(const QColor &color) |
|
269 | void QAreaSeries::setBorderColor(const QColor &color) | |
270 | { |
|
270 | { | |
271 | QPen p = pen(); |
|
271 | QPen p = pen(); | |
272 | if (p.color() != color) { |
|
272 | if (p.color() != color) { | |
273 | p.setColor(color); |
|
273 | p.setColor(color); | |
274 | setPen(p); |
|
274 | setPen(p); | |
275 | emit borderColorChanged(color); |
|
275 | emit borderColorChanged(color); | |
276 | } |
|
276 | } | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | QColor QAreaSeries::borderColor() const |
|
279 | QColor QAreaSeries::borderColor() const | |
280 | { |
|
280 | { | |
281 | return pen().color(); |
|
281 | return pen().color(); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | Sets if data points are \a visible and should be drawn on line. |
|
285 | Sets if data points are \a visible and should be drawn on line. | |
286 | */ |
|
286 | */ | |
287 | void QAreaSeries::setPointsVisible(bool visible) |
|
287 | void QAreaSeries::setPointsVisible(bool visible) | |
288 | { |
|
288 | { | |
289 | Q_D(QAreaSeries); |
|
289 | Q_D(QAreaSeries); | |
290 | if (d->m_pointsVisible != visible) { |
|
290 | if (d->m_pointsVisible != visible) { | |
291 | d->m_pointsVisible = visible; |
|
291 | d->m_pointsVisible = visible; | |
292 | emit d->updated(); |
|
292 | emit d->updated(); | |
293 | } |
|
293 | } | |
294 | } |
|
294 | } | |
295 |
|
295 | |||
296 | /*! |
|
296 | /*! | |
297 | Returns if the points are drawn for this series. |
|
297 | Returns if the points are drawn for this series. | |
298 | \sa setPointsVisible() |
|
298 | \sa setPointsVisible() | |
299 | */ |
|
299 | */ | |
300 | bool QAreaSeries::pointsVisible() const |
|
300 | bool QAreaSeries::pointsVisible() const | |
301 | { |
|
301 | { | |
302 | Q_D(const QAreaSeries); |
|
302 | Q_D(const QAreaSeries); | |
303 | return d->m_pointsVisible; |
|
303 | return d->m_pointsVisible; | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
306 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
307 |
|
307 | |||
308 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : |
|
308 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q) : | |
309 | QAbstractSeriesPrivate(q), |
|
309 | QAbstractSeriesPrivate(q), | |
310 | m_upperSeries(upperSeries), |
|
310 | m_upperSeries(upperSeries), | |
311 | m_lowerSeries(lowerSeries), |
|
311 | m_lowerSeries(lowerSeries), | |
312 | m_pointsVisible(false) |
|
312 | m_pointsVisible(false) | |
313 | { |
|
313 | { | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) |
|
316 | void QAreaSeriesPrivate::scaleDomain(Domain& domain) | |
317 | { |
|
317 | { | |
318 | Q_Q(QAreaSeries); |
|
318 | Q_Q(QAreaSeries); | |
319 |
|
319 | |||
320 | qreal minX(domain.minX()); |
|
320 | qreal minX(domain.minX()); | |
321 | qreal minY(domain.minY()); |
|
321 | qreal minY(domain.minY()); | |
322 | qreal maxX(domain.maxX()); |
|
322 | qreal maxX(domain.maxX()); | |
323 | qreal maxY(domain.maxY()); |
|
323 | qreal maxY(domain.maxY()); | |
324 | int tickXCount(domain.tickXCount()); |
|
324 | int tickXCount(domain.tickXCount()); | |
325 | int tickYCount(domain.tickYCount()); |
|
325 | int tickYCount(domain.tickYCount()); | |
326 |
|
326 | |||
327 | QLineSeries* upperSeries = q->upperSeries(); |
|
327 | QLineSeries* upperSeries = q->upperSeries(); | |
328 | QLineSeries* lowerSeries = q->lowerSeries(); |
|
328 | QLineSeries* lowerSeries = q->lowerSeries(); | |
329 |
|
329 | |||
330 | const QList<QPointF>& points = upperSeries->points(); |
|
330 | const QList<QPointF>& points = upperSeries->points(); | |
331 |
|
331 | |||
332 | for (int i = 0; i < points.count(); i++) |
|
332 | for (int i = 0; i < points.count(); i++) | |
333 | { |
|
333 | { | |
334 | qreal x = points[i].x(); |
|
334 | qreal x = points[i].x(); | |
335 | qreal y = points[i].y(); |
|
335 | qreal y = points[i].y(); | |
336 | minX = qMin(minX, x); |
|
336 | minX = qMin(minX, x); | |
337 | minY = qMin(minY, y); |
|
337 | minY = qMin(minY, y); | |
338 | maxX = qMax(maxX, x); |
|
338 | maxX = qMax(maxX, x); | |
339 | maxY = qMax(maxY, y); |
|
339 | maxY = qMax(maxY, y); | |
340 | } |
|
340 | } | |
341 | if(lowerSeries) { |
|
341 | if(lowerSeries) { | |
342 |
|
342 | |||
343 | const QList<QPointF>& points = lowerSeries->points(); |
|
343 | const QList<QPointF>& points = lowerSeries->points(); | |
344 |
|
344 | |||
345 | for (int i = 0; i < points.count(); i++) |
|
345 | for (int i = 0; i < points.count(); i++) | |
346 | { |
|
346 | { | |
347 | qreal x = points[i].x(); |
|
347 | qreal x = points[i].x(); | |
348 | qreal y = points[i].y(); |
|
348 | qreal y = points[i].y(); | |
349 | minX = qMin(minX, x); |
|
349 | minX = qMin(minX, x); | |
350 | minY = qMin(minY, y); |
|
350 | minY = qMin(minY, y); | |
351 | maxX = qMax(maxX, x); |
|
351 | maxX = qMax(maxX, x); | |
352 | maxY = qMax(maxY, y); |
|
352 | maxY = qMax(maxY, y); | |
353 | }} |
|
353 | }} | |
354 |
|
354 | |||
355 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
355 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
358 | Chart* QAreaSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
359 | { |
|
359 | { | |
360 | Q_Q(QAreaSeries); |
|
360 | Q_Q(QAreaSeries); | |
361 |
|
361 | |||
362 | AreaChartItem* area = new AreaChartItem(q,presenter); |
|
362 | AreaChartItem* area = new AreaChartItem(q,presenter); | |
363 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
363 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
364 | area->upperLineItem()->setAnimator(presenter->animator()); |
|
364 | area->upperLineItem()->setAnimator(presenter->animator()); | |
365 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
365 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
366 | if(q->lowerSeries()) { |
|
366 | if(q->lowerSeries()) { | |
367 | area->lowerLineItem()->setAnimator(presenter->animator()); |
|
367 | area->lowerLineItem()->setAnimator(presenter->animator()); | |
368 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
368 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
369 | } |
|
369 | } | |
370 | } |
|
370 | } | |
371 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
371 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
372 | return area; |
|
372 | return area; | |
373 | } |
|
373 | } | |
374 |
|
374 | |||
375 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) |
|
375 | QList<LegendMarker*> QAreaSeriesPrivate::createLegendMarker(QLegend* legend) | |
376 | { |
|
376 | { | |
377 | Q_Q(QAreaSeries); |
|
377 | Q_Q(QAreaSeries); | |
378 | QList<LegendMarker*> list; |
|
378 | QList<LegendMarker*> list; | |
379 | return list << new AreaLegendMarker(q,legend); |
|
379 | return list << new AreaLegendMarker(q,legend); | |
380 | } |
|
380 | } | |
381 |
|
381 | |||
382 |
|
382 | |||
383 |
|
|
383 | void QAreaSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
384 | { |
|
384 | { | |
385 | return new QValuesAxis(parent); |
|
385 | Q_UNUSED(axis); | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 |
|
|
388 | void QAreaSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
389 | { |
|
389 | { | |
390 | return new QValuesAxis(parent); |
|
390 | Q_UNUSED(axis); | |
|
391 | } | |||
|
392 | ||||
|
393 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisXType() const | |||
|
394 | { | |||
|
395 | return QAbstractAxis::AxisTypeValues; | |||
|
396 | } | |||
|
397 | ||||
|
398 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisYType() const | |||
|
399 | { | |||
|
400 | return QAbstractAxis::AxisTypeValues; | |||
391 | } |
|
401 | } | |
392 |
|
402 | |||
393 | #include "moc_qareaseries.cpp" |
|
403 | #include "moc_qareaseries.cpp" | |
394 | #include "moc_qareaseries_p.cpp" |
|
404 | #include "moc_qareaseries_p.cpp" | |
395 |
|
405 | |||
396 | QTCOMMERCIALCHART_END_NAMESPACE |
|
406 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,67 +1,69 | |||||
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 QAREASERIES_P_H |
|
30 | #ifndef QAREASERIES_P_H | |
31 | #define QAREASERIES_P_H |
|
31 | #define QAREASERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QAreaSeries; |
|
37 | class QAreaSeries; | |
38 |
|
38 | |||
39 | class QAreaSeriesPrivate: public QAbstractSeriesPrivate |
|
39 | class QAreaSeriesPrivate: public QAbstractSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); |
|
44 | QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries,QAreaSeries* q); | |
45 |
|
45 | |||
46 | void scaleDomain(Domain& domain); |
|
46 | void scaleDomain(Domain& domain); | |
47 | Chart* createGraphics(ChartPresenter* presenter); |
|
47 | Chart* createGraphics(ChartPresenter* presenter); | |
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
49 | QAbstractAxis* createAxisX(QObject* parent = 0); |
|
49 | void initializeAxisX(QAbstractAxis* axis); | |
50 | QAbstractAxis* createAxisY(QObject* parent = 0); |
|
50 | void initializeAxisY(QAbstractAxis* axis); | |
|
51 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
52 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
51 |
|
53 | |||
52 | Q_SIGNALS: |
|
54 | Q_SIGNALS: | |
53 | void updated(); |
|
55 | void updated(); | |
54 |
|
56 | |||
55 | protected: |
|
57 | protected: | |
56 | QBrush m_brush; |
|
58 | QBrush m_brush; | |
57 | QPen m_pen; |
|
59 | QPen m_pen; | |
58 | QLineSeries* m_upperSeries; |
|
60 | QLineSeries* m_upperSeries; | |
59 | QLineSeries* m_lowerSeries; |
|
61 | QLineSeries* m_lowerSeries; | |
60 | bool m_pointsVisible; |
|
62 | bool m_pointsVisible; | |
61 | private: |
|
63 | private: | |
62 | Q_DECLARE_PUBLIC(QAreaSeries); |
|
64 | Q_DECLARE_PUBLIC(QAreaSeries); | |
63 | }; |
|
65 | }; | |
64 |
|
66 | |||
65 | QTCOMMERCIALCHART_END_NAMESPACE |
|
67 | QTCOMMERCIALCHART_END_NAMESPACE | |
66 |
|
68 | |||
67 | #endif |
|
69 | #endif |
@@ -1,130 +1,133 | |||||
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 QABSTRACTAXIS_H |
|
21 | #ifndef QABSTRACTAXIS_H | |
22 | #define QABSTRACTAXIS_H |
|
22 | #define QABSTRACTAXIS_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <QPen> |
|
25 | #include <QPen> | |
26 | #include <QFont> |
|
26 | #include <QFont> | |
27 | #include <QVariant> |
|
27 | #include <QVariant> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAbstractAxisPrivate; |
|
31 | class QAbstractAxisPrivate; | |
32 |
|
32 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 |
|
36 | |||
37 | Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged) |
|
37 | Q_PROPERTY(bool visible READ isAxisVisible WRITE setAxisVisible NOTIFY visibleChanged) | |
38 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) |
|
38 | Q_PROPERTY(QColor color READ axisPenColor WRITE setAxisPenColor NOTIFY colorChanged) | |
39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
39 | Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) |
|
40 | Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle) | |
41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) |
|
41 | Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont) | |
42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) |
|
42 | Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged) | |
43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) |
|
43 | Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged) | |
44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) |
|
44 | Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged) | |
45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) |
|
45 | Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged) | |
46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) |
|
46 | Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged) | |
47 |
|
47 | |||
48 | public: |
|
48 | public: | |
49 |
|
49 | |||
50 | enum AxisType { |
|
50 | enum AxisType { | |
51 |
AxisType |
|
51 | AxisTypeNoAxis = 0x0, | |
52 |
AxisType |
|
52 | AxisTypeValues = 0x1, | |
|
53 | AxisTypeCategories = 0x2 | |||
53 | }; |
|
54 | }; | |
54 |
|
55 | |||
|
56 | Q_DECLARE_FLAGS(AxisTypes, AxisType) | |||
|
57 | ||||
55 | protected: |
|
58 | protected: | |
56 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); |
|
59 | explicit QAbstractAxis(QAbstractAxisPrivate &d,QObject *parent = 0); | |
57 |
|
60 | |||
58 | public: |
|
61 | public: | |
59 | ~QAbstractAxis(); |
|
62 | ~QAbstractAxis(); | |
60 |
|
63 | |||
61 | virtual AxisType type() const = 0; |
|
64 | virtual AxisType type() const = 0; | |
62 |
|
65 | |||
63 | //axis handling |
|
66 | //axis handling | |
64 | bool isAxisVisible() const; |
|
67 | bool isAxisVisible() const; | |
65 | void setAxisVisible(bool visible = true); |
|
68 | void setAxisVisible(bool visible = true); | |
66 | void setAxisPen(const QPen &pen); |
|
69 | void setAxisPen(const QPen &pen); | |
67 | QPen axisPen() const; |
|
70 | QPen axisPen() const; | |
68 | void setAxisPenColor(QColor color); |
|
71 | void setAxisPenColor(QColor color); | |
69 | QColor axisPenColor() const; |
|
72 | QColor axisPenColor() const; | |
70 |
|
73 | |||
71 | //grid handling |
|
74 | //grid handling | |
72 | bool isGridLineVisible() const; |
|
75 | bool isGridLineVisible() const; | |
73 | void setGridLineVisible(bool visible = true); |
|
76 | void setGridLineVisible(bool visible = true); | |
74 | void setGridLinePen(const QPen &pen); |
|
77 | void setGridLinePen(const QPen &pen); | |
75 | QPen gridLinePen() const; |
|
78 | QPen gridLinePen() const; | |
76 |
|
79 | |||
77 | //labels handling |
|
80 | //labels handling | |
78 | bool labelsVisible() const; |
|
81 | bool labelsVisible() const; | |
79 | void setLabelsVisible(bool visible = true); |
|
82 | void setLabelsVisible(bool visible = true); | |
80 | void setLabelsPen(const QPen &pen); |
|
83 | void setLabelsPen(const QPen &pen); | |
81 | QPen labelsPen() const; |
|
84 | QPen labelsPen() const; | |
82 | void setLabelsBrush(const QBrush &brush); |
|
85 | void setLabelsBrush(const QBrush &brush); | |
83 | QBrush labelsBrush() const; |
|
86 | QBrush labelsBrush() const; | |
84 | void setLabelsFont(const QFont &font); |
|
87 | void setLabelsFont(const QFont &font); | |
85 | QFont labelsFont() const; |
|
88 | QFont labelsFont() const; | |
86 | void setLabelsAngle(int angle); |
|
89 | void setLabelsAngle(int angle); | |
87 | int labelsAngle() const; |
|
90 | int labelsAngle() const; | |
88 | void setLabelsColor(QColor color); |
|
91 | void setLabelsColor(QColor color); | |
89 | QColor labelsColor() const; |
|
92 | QColor labelsColor() const; | |
90 |
|
93 | |||
91 | //shades handling |
|
94 | //shades handling | |
92 | bool shadesVisible() const; |
|
95 | bool shadesVisible() const; | |
93 | void setShadesVisible(bool visible = true); |
|
96 | void setShadesVisible(bool visible = true); | |
94 | void setShadesPen(const QPen &pen); |
|
97 | void setShadesPen(const QPen &pen); | |
95 | QPen shadesPen() const; |
|
98 | QPen shadesPen() const; | |
96 | void setShadesBrush(const QBrush &brush); |
|
99 | void setShadesBrush(const QBrush &brush); | |
97 | QBrush shadesBrush() const; |
|
100 | QBrush shadesBrush() const; | |
98 | void setShadesColor(QColor color); |
|
101 | void setShadesColor(QColor color); | |
99 | QColor shadesColor() const; |
|
102 | QColor shadesColor() const; | |
100 | void setShadesBorderColor(QColor color); |
|
103 | void setShadesBorderColor(QColor color); | |
101 | QColor shadesBorderColor() const; |
|
104 | QColor shadesBorderColor() const; | |
102 |
|
105 | |||
103 | //range handling |
|
106 | //range handling | |
104 | void setMin(const QVariant &min); |
|
107 | void setMin(const QVariant &min); | |
105 | void setMax(const QVariant &max); |
|
108 | void setMax(const QVariant &max); | |
106 | void setRange(const QVariant &min, const QVariant &max); |
|
109 | void setRange(const QVariant &min, const QVariant &max); | |
107 |
|
110 | |||
108 | void show(); |
|
111 | void show(); | |
109 | void hide(); |
|
112 | void hide(); | |
110 |
|
113 | |||
111 | Q_SIGNALS: |
|
114 | Q_SIGNALS: | |
112 | void visibleChanged(bool visible); |
|
115 | void visibleChanged(bool visible); | |
113 | void labelsVisibleChanged(bool visible); |
|
116 | void labelsVisibleChanged(bool visible); | |
114 | void gridVisibleChanged(bool visible); |
|
117 | void gridVisibleChanged(bool visible); | |
115 | void colorChanged(QColor color); |
|
118 | void colorChanged(QColor color); | |
116 | void labelsColorChanged(QColor color); |
|
119 | void labelsColorChanged(QColor color); | |
117 | void shadesVisibleChanged(bool visible); |
|
120 | void shadesVisibleChanged(bool visible); | |
118 | void shadesColorChanged(QColor color); |
|
121 | void shadesColorChanged(QColor color); | |
119 | void shadesBorderColorChanged(QColor color); |
|
122 | void shadesBorderColorChanged(QColor color); | |
120 |
|
123 | |||
121 | protected: |
|
124 | protected: | |
122 | QScopedPointer<QAbstractAxisPrivate> d_ptr; |
|
125 | QScopedPointer<QAbstractAxisPrivate> d_ptr; | |
123 | Q_DISABLE_COPY(QAbstractAxis); |
|
126 | Q_DISABLE_COPY(QAbstractAxis); | |
124 | friend class ChartDataSet; |
|
127 | friend class ChartDataSet; | |
125 | friend class ChartAxis; |
|
128 | friend class ChartAxis; | |
126 | friend class ChartPresenter; |
|
129 | friend class ChartPresenter; | |
127 | }; |
|
130 | }; | |
128 |
|
131 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
132 | QTCOMMERCIALCHART_END_NAMESPACE | |
130 | #endif |
|
133 | #endif |
@@ -1,724 +1,735 | |||||
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 "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_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 QAbstractBarSeries |
|
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 | QAbstractBarSeries 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 QAbstractBarSeries |
|
51 | \qmlclass BarSeries QAbstractBarSeries | |
52 | \inherits AbstractSeries |
|
52 | \inherits QAbstractSeries | |
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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries::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 QAbstractBarSeries. |
|
192 | Constructs empty QAbstractBarSeries. | |
193 | QAbstractBarSeries 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 | 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 |
|
220 | 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 | |
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
221 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
222 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
223 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
223 | Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
224 | */ |
|
224 | */ | |
225 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
225 | void QAbstractBarSeries::setBarWidth(qreal width) | |
226 | { |
|
226 | { | |
227 | Q_D(QAbstractBarSeries); |
|
227 | Q_D(QAbstractBarSeries); | |
228 | d->setBarWidth(width); |
|
228 | d->setBarWidth(width); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Returns the width of the bars of the series. |
|
232 | Returns the width of the bars of the series. | |
233 | \sa setBarWidth() |
|
233 | \sa setBarWidth() | |
234 | */ |
|
234 | */ | |
235 | qreal QAbstractBarSeries::barWidth() const |
|
235 | qreal QAbstractBarSeries::barWidth() const | |
236 | { |
|
236 | { | |
237 | Q_D(const QAbstractBarSeries); |
|
237 | Q_D(const QAbstractBarSeries); | |
238 | return d->barWidth(); |
|
238 | return d->barWidth(); | |
239 | } |
|
239 | } | |
240 |
|
240 | |||
241 | /*! |
|
241 | /*! | |
242 | 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. |
|
242 | 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. | |
243 | Returns true, if appending succeeded. |
|
243 | Returns true, if appending succeeded. | |
244 | */ |
|
244 | */ | |
245 | bool QAbstractBarSeries::append(QBarSet *set) |
|
245 | bool QAbstractBarSeries::append(QBarSet *set) | |
246 | { |
|
246 | { | |
247 | Q_D(QAbstractBarSeries); |
|
247 | Q_D(QAbstractBarSeries); | |
248 | bool success = d->append(set); |
|
248 | bool success = d->append(set); | |
249 | if (success) { |
|
249 | if (success) { | |
250 | QList<QBarSet*> sets; |
|
250 | QList<QBarSet*> sets; | |
251 | sets.append(set); |
|
251 | sets.append(set); | |
252 | emit barsetsAdded(sets); |
|
252 | emit barsetsAdded(sets); | |
253 | emit countChanged(); |
|
253 | emit countChanged(); | |
254 | } |
|
254 | } | |
255 | return success; |
|
255 | return success; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
259 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
260 | Returns true, if set was removed. |
|
260 | Returns true, if set was removed. | |
261 | */ |
|
261 | */ | |
262 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
262 | bool QAbstractBarSeries::remove(QBarSet *set) | |
263 | { |
|
263 | { | |
264 | Q_D(QAbstractBarSeries); |
|
264 | Q_D(QAbstractBarSeries); | |
265 | bool success = d->remove(set); |
|
265 | bool success = d->remove(set); | |
266 | if (success) { |
|
266 | if (success) { | |
267 | QList<QBarSet*> sets; |
|
267 | QList<QBarSet*> sets; | |
268 | sets.append(set); |
|
268 | sets.append(set); | |
269 | emit barsetsRemoved(sets); |
|
269 | emit barsetsRemoved(sets); | |
270 | emit countChanged(); |
|
270 | emit countChanged(); | |
271 | } |
|
271 | } | |
272 | return success; |
|
272 | return success; | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
276 | Adds a list of barsets to series. Takes ownership of \a sets. | |
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
277 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
278 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
279 | and function returns false. |
|
279 | and function returns false. | |
280 | */ |
|
280 | */ | |
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
281 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
282 | { |
|
282 | { | |
283 | Q_D(QAbstractBarSeries); |
|
283 | Q_D(QAbstractBarSeries); | |
284 | bool success = d->append(sets); |
|
284 | bool success = d->append(sets); | |
285 | if (success) { |
|
285 | if (success) { | |
286 | emit barsetsAdded(sets); |
|
286 | emit barsetsAdded(sets); | |
287 | emit countChanged(); |
|
287 | emit countChanged(); | |
288 | } |
|
288 | } | |
289 | return success; |
|
289 | return success; | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | 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. |
|
293 | 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. | |
294 | Returns true, if inserting succeeded. |
|
294 | Returns true, if inserting succeeded. | |
295 |
|
295 | |||
296 | */ |
|
296 | */ | |
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
297 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
298 | { |
|
298 | { | |
299 | Q_D(QAbstractBarSeries); |
|
299 | Q_D(QAbstractBarSeries); | |
300 | bool success = d->insert(index, set); |
|
300 | bool success = d->insert(index, set); | |
301 | if (success) { |
|
301 | if (success) { | |
302 | QList<QBarSet*> sets; |
|
302 | QList<QBarSet*> sets; | |
303 | sets.append(set); |
|
303 | sets.append(set); | |
304 | emit barsetsAdded(sets); |
|
304 | emit barsetsAdded(sets); | |
305 | emit countChanged(); |
|
305 | emit countChanged(); | |
306 | } |
|
306 | } | |
307 | return success; |
|
307 | return success; | |
308 | } |
|
308 | } | |
309 |
|
309 | |||
310 | /*! |
|
310 | /*! | |
311 | Removes all of the bar sets from the series |
|
311 | Removes all of the bar sets from the series | |
312 | */ |
|
312 | */ | |
313 | void QAbstractBarSeries::clear() |
|
313 | void QAbstractBarSeries::clear() | |
314 | { |
|
314 | { | |
315 | Q_D(QAbstractBarSeries); |
|
315 | Q_D(QAbstractBarSeries); | |
316 | QList<QBarSet *> sets = barSets(); |
|
316 | QList<QBarSet *> sets = barSets(); | |
317 | bool success = d->remove(sets); |
|
317 | bool success = d->remove(sets); | |
318 | if (success) { |
|
318 | if (success) { | |
319 | emit barsetsRemoved(sets); |
|
319 | emit barsetsRemoved(sets); | |
320 | emit countChanged(); |
|
320 | emit countChanged(); | |
321 | } |
|
321 | } | |
322 | } |
|
322 | } | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | Returns number of sets in series. |
|
325 | Returns number of sets in series. | |
326 | */ |
|
326 | */ | |
327 | int QAbstractBarSeries::count() const |
|
327 | int QAbstractBarSeries::count() const | |
328 | { |
|
328 | { | |
329 | Q_D(const QAbstractBarSeries); |
|
329 | Q_D(const QAbstractBarSeries); | |
330 | return d->m_barSets.count(); |
|
330 | return d->m_barSets.count(); | |
331 | } |
|
331 | } | |
332 |
|
332 | |||
333 | /*! |
|
333 | /*! | |
334 | Returns a list of sets in series. Keeps ownership of sets. |
|
334 | Returns a list of sets in series. Keeps ownership of sets. | |
335 | */ |
|
335 | */ | |
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
336 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
337 | { |
|
337 | { | |
338 | Q_D(const QAbstractBarSeries); |
|
338 | Q_D(const QAbstractBarSeries); | |
339 | return d->m_barSets; |
|
339 | return d->m_barSets; | |
340 | } |
|
340 | } | |
341 |
|
341 | |||
342 | /*! |
|
342 | /*! | |
343 | Sets the visibility of labels in series to \a visible |
|
343 | Sets the visibility of labels in series to \a visible | |
344 | */ |
|
344 | */ | |
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
345 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
346 | { |
|
346 | { | |
347 | Q_D(QAbstractBarSeries); |
|
347 | Q_D(QAbstractBarSeries); | |
348 | if (d->m_labelsVisible != visible) { |
|
348 | if (d->m_labelsVisible != visible) { | |
349 | d->setLabelsVisible(visible); |
|
349 | d->setLabelsVisible(visible); | |
350 | emit labelsVisibleChanged(); |
|
350 | emit labelsVisibleChanged(); | |
351 | } |
|
351 | } | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Returns the visibility of labels |
|
355 | Returns the visibility of labels | |
356 | */ |
|
356 | */ | |
357 | bool QAbstractBarSeries::isLabelsVisible() const |
|
357 | bool QAbstractBarSeries::isLabelsVisible() const | |
358 | { |
|
358 | { | |
359 | Q_D(const QAbstractBarSeries); |
|
359 | Q_D(const QAbstractBarSeries); | |
360 | return d->m_labelsVisible; |
|
360 | return d->m_labelsVisible; | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
363 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
364 |
|
364 | |||
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
365 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
366 | QAbstractSeriesPrivate(q), |
|
366 | QAbstractSeriesPrivate(q), | |
367 | m_barWidth(0.5), // Default value is 50% of category width |
|
367 | m_barWidth(0.5), // Default value is 50% of category width | |
368 | m_labelsVisible(false), |
|
368 | m_labelsVisible(false), | |
369 | m_visible(true) |
|
369 | m_visible(true) | |
370 | { |
|
370 | { | |
371 | } |
|
371 | } | |
372 |
|
372 | |||
373 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
373 | int QAbstractBarSeriesPrivate::categoryCount() const | |
374 | { |
|
374 | { | |
375 | // No categories defined. return count of longest set. |
|
375 | // No categories defined. return count of longest set. | |
376 | int count = 0; |
|
376 | int count = 0; | |
377 | for (int i=0; i<m_barSets.count(); i++) { |
|
377 | for (int i=0; i<m_barSets.count(); i++) { | |
378 | if (m_barSets.at(i)->count() > count) { |
|
378 | if (m_barSets.at(i)->count() > count) { | |
379 | count = m_barSets.at(i)->count(); |
|
379 | count = m_barSets.at(i)->count(); | |
380 | } |
|
380 | } | |
381 | } |
|
381 | } | |
382 |
|
382 | |||
383 | return count; |
|
383 | return count; | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
386 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
387 | { |
|
387 | { | |
388 | if (width < 0.0) { |
|
388 | if (width < 0.0) { | |
389 | width = 0.0; |
|
389 | width = 0.0; | |
390 | } |
|
390 | } | |
391 | m_barWidth = width; |
|
391 | m_barWidth = width; | |
392 | emit updatedBars(); |
|
392 | emit updatedBars(); | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
395 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
396 | { |
|
396 | { | |
397 | return m_barWidth; |
|
397 | return m_barWidth; | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
400 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
401 | { |
|
401 | { | |
402 | return m_barSets.at(index); |
|
402 | return m_barSets.at(index); | |
403 | } |
|
403 | } | |
404 |
|
404 | |||
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
405 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
406 | { |
|
406 | { | |
407 | m_visible = visible; |
|
407 | m_visible = visible; | |
408 | emit updatedBars(); |
|
408 | emit updatedBars(); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
411 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
412 | { |
|
412 | { | |
413 | m_labelsVisible = visible; |
|
413 | m_labelsVisible = visible; | |
414 | emit labelsVisibleChanged(visible); |
|
414 | emit labelsVisibleChanged(visible); | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | qreal QAbstractBarSeriesPrivate::min() |
|
417 | qreal QAbstractBarSeriesPrivate::min() | |
418 | { |
|
418 | { | |
419 | if (m_barSets.count() <= 0) { |
|
419 | if (m_barSets.count() <= 0) { | |
420 | return 0; |
|
420 | return 0; | |
421 | } |
|
421 | } | |
422 | qreal min = INT_MAX; |
|
422 | qreal min = INT_MAX; | |
423 |
|
423 | |||
424 | for (int i = 0; i < m_barSets.count(); i++) { |
|
424 | for (int i = 0; i < m_barSets.count(); i++) { | |
425 | int categoryCount = m_barSets.at(i)->count(); |
|
425 | int categoryCount = m_barSets.at(i)->count(); | |
426 | for (int j = 0; j < categoryCount; j++) { |
|
426 | for (int j = 0; j < categoryCount; j++) { | |
427 | qreal temp = m_barSets.at(i)->at(j); |
|
427 | qreal temp = m_barSets.at(i)->at(j); | |
428 | if (temp < min) |
|
428 | if (temp < min) | |
429 | min = temp; |
|
429 | min = temp; | |
430 | } |
|
430 | } | |
431 | } |
|
431 | } | |
432 | return min; |
|
432 | return min; | |
433 | } |
|
433 | } | |
434 |
|
434 | |||
435 | qreal QAbstractBarSeriesPrivate::max() |
|
435 | qreal QAbstractBarSeriesPrivate::max() | |
436 | { |
|
436 | { | |
437 | if (m_barSets.count() <= 0) { |
|
437 | if (m_barSets.count() <= 0) { | |
438 | return 0; |
|
438 | return 0; | |
439 | } |
|
439 | } | |
440 | qreal max = INT_MIN; |
|
440 | qreal max = INT_MIN; | |
441 |
|
441 | |||
442 | for (int i = 0; i < m_barSets.count(); i++) { |
|
442 | for (int i = 0; i < m_barSets.count(); i++) { | |
443 | int categoryCount = m_barSets.at(i)->count(); |
|
443 | int categoryCount = m_barSets.at(i)->count(); | |
444 | for (int j = 0; j < categoryCount; j++) { |
|
444 | for (int j = 0; j < categoryCount; j++) { | |
445 | qreal temp = m_barSets.at(i)->at(j); |
|
445 | qreal temp = m_barSets.at(i)->at(j); | |
446 | if (temp > max) |
|
446 | if (temp > max) | |
447 | max = temp; |
|
447 | max = temp; | |
448 | } |
|
448 | } | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | return max; |
|
451 | return max; | |
452 | } |
|
452 | } | |
453 |
|
453 | |||
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
454 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
455 | { |
|
455 | { | |
456 | if ((set < 0) || (set >= m_barSets.count())) { |
|
456 | if ((set < 0) || (set >= m_barSets.count())) { | |
457 | // No set, no value. |
|
457 | // No set, no value. | |
458 | return 0; |
|
458 | return 0; | |
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
460 | // No category, no value. |
|
460 | // No category, no value. | |
461 | return 0; |
|
461 | return 0; | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | return m_barSets.at(set)->at(category); |
|
464 | return m_barSets.at(set)->at(category); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
467 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
468 | { |
|
468 | { | |
469 | if ((set < 0) || (set >= m_barSets.count())) { |
|
469 | if ((set < 0) || (set >= m_barSets.count())) { | |
470 | // No set, no value. |
|
470 | // No set, no value. | |
471 | return 0; |
|
471 | return 0; | |
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
472 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
473 | // No category, no value. |
|
473 | // No category, no value. | |
474 | return 0; |
|
474 | return 0; | |
475 | } |
|
475 | } | |
476 |
|
476 | |||
477 | qreal value = m_barSets.at(set)->at(category); |
|
477 | qreal value = m_barSets.at(set)->at(category); | |
478 | qreal sum = categorySum(category); |
|
478 | qreal sum = categorySum(category); | |
479 | if ( qFuzzyIsNull(sum) ) { |
|
479 | if ( qFuzzyIsNull(sum) ) { | |
480 | return 0; |
|
480 | return 0; | |
481 | } |
|
481 | } | |
482 |
|
482 | |||
483 | return value / sum; |
|
483 | return value / sum; | |
484 | } |
|
484 | } | |
485 |
|
485 | |||
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
486 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
487 | { |
|
487 | { | |
488 | qreal sum(0); |
|
488 | qreal sum(0); | |
489 | int count = m_barSets.count(); // Count sets |
|
489 | int count = m_barSets.count(); // Count sets | |
490 | for (int set = 0; set < count; set++) { |
|
490 | for (int set = 0; set < count; set++) { | |
491 | if (category < m_barSets.at(set)->count()) |
|
491 | if (category < m_barSets.at(set)->count()) | |
492 | sum += m_barSets.at(set)->at(category); |
|
492 | sum += m_barSets.at(set)->at(category); | |
493 | } |
|
493 | } | |
494 | return sum; |
|
494 | return sum; | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
497 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
498 | { |
|
498 | { | |
499 | qreal sum(0); |
|
499 | qreal sum(0); | |
500 | int count = m_barSets.count(); // Count sets |
|
500 | int count = m_barSets.count(); // Count sets | |
501 | for (int set = 0; set < count; set++) { |
|
501 | for (int set = 0; set < count; set++) { | |
502 | if (category < m_barSets.at(set)->count()) |
|
502 | if (category < m_barSets.at(set)->count()) | |
503 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
503 | sum += qAbs(m_barSets.at(set)->at(category)); | |
504 | } |
|
504 | } | |
505 | return sum; |
|
505 | return sum; | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
508 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
509 | { |
|
509 | { | |
510 | qreal max = INT_MIN; |
|
510 | qreal max = INT_MIN; | |
511 | int count = categoryCount(); |
|
511 | int count = categoryCount(); | |
512 | for (int i = 0; i < count; i++) { |
|
512 | for (int i = 0; i < count; i++) { | |
513 | qreal sum = categorySum(i); |
|
513 | qreal sum = categorySum(i); | |
514 | if (sum > max) |
|
514 | if (sum > max) | |
515 | max = sum; |
|
515 | max = sum; | |
516 | } |
|
516 | } | |
517 | return max; |
|
517 | return max; | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | qreal QAbstractBarSeriesPrivate::minX() |
|
520 | qreal QAbstractBarSeriesPrivate::minX() | |
521 | { |
|
521 | { | |
522 | if (m_barSets.count() <= 0) { |
|
522 | if (m_barSets.count() <= 0) { | |
523 | return 0; |
|
523 | return 0; | |
524 | } |
|
524 | } | |
525 | qreal min = INT_MAX; |
|
525 | qreal min = INT_MAX; | |
526 |
|
526 | |||
527 | for (int i = 0; i < m_barSets.count(); i++) { |
|
527 | for (int i = 0; i < m_barSets.count(); i++) { | |
528 | int categoryCount = m_barSets.at(i)->count(); |
|
528 | int categoryCount = m_barSets.at(i)->count(); | |
529 | for (int j = 0; j < categoryCount; j++) { |
|
529 | for (int j = 0; j < categoryCount; j++) { | |
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
530 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
531 | if (temp < min) |
|
531 | if (temp < min) | |
532 | min = temp; |
|
532 | min = temp; | |
533 | } |
|
533 | } | |
534 | } |
|
534 | } | |
535 | return min; |
|
535 | return min; | |
536 | } |
|
536 | } | |
537 |
|
537 | |||
538 | qreal QAbstractBarSeriesPrivate::maxX() |
|
538 | qreal QAbstractBarSeriesPrivate::maxX() | |
539 | { |
|
539 | { | |
540 | if (m_barSets.count() <= 0) { |
|
540 | if (m_barSets.count() <= 0) { | |
541 | return 0; |
|
541 | return 0; | |
542 | } |
|
542 | } | |
543 | qreal max = INT_MIN; |
|
543 | qreal max = INT_MIN; | |
544 |
|
544 | |||
545 | for (int i = 0; i < m_barSets.count(); i++) { |
|
545 | for (int i = 0; i < m_barSets.count(); i++) { | |
546 | int categoryCount = m_barSets.at(i)->count(); |
|
546 | int categoryCount = m_barSets.at(i)->count(); | |
547 | for (int j = 0; j < categoryCount; j++) { |
|
547 | for (int j = 0; j < categoryCount; j++) { | |
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
548 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
549 | if (temp > max) |
|
549 | if (temp > max) | |
550 | max = temp; |
|
550 | max = temp; | |
551 | } |
|
551 | } | |
552 | } |
|
552 | } | |
553 |
|
553 | |||
554 | return max; |
|
554 | return max; | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 |
|
557 | |||
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
558 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
559 | { |
|
559 | { | |
560 | qreal minX(domain.minX()); |
|
560 | qreal minX(domain.minX()); | |
561 | qreal minY(domain.minY()); |
|
561 | qreal minY(domain.minY()); | |
562 | qreal maxX(domain.maxX()); |
|
562 | qreal maxX(domain.maxX()); | |
563 | qreal maxY(domain.maxY()); |
|
563 | qreal maxY(domain.maxY()); | |
564 | int tickXCount(domain.tickXCount()); |
|
564 | int tickXCount(domain.tickXCount()); | |
565 | int tickYCount(domain.tickYCount()); |
|
565 | int tickYCount(domain.tickYCount()); | |
566 |
|
566 | |||
567 | qreal seriesMinX = this->minX(); |
|
567 | qreal seriesMinX = this->minX(); | |
568 | qreal seriesMaxX = this->maxX(); |
|
568 | qreal seriesMaxX = this->maxX(); | |
569 | qreal y = max(); |
|
569 | qreal y = max(); | |
570 | minX = qMin(minX, seriesMinX - 0.5); |
|
570 | minX = qMin(minX, seriesMinX - 0.5); | |
571 | minY = qMin(minY, y); |
|
571 | minY = qMin(minY, y); | |
572 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
572 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
573 | maxY = qMax(maxY, y); |
|
573 | maxY = qMax(maxY, y); | |
574 | tickXCount = categoryCount()+1; |
|
574 | tickXCount = categoryCount()+1; | |
575 |
|
575 | |||
576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
576 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
577 | } |
|
577 | } | |
578 |
|
578 | |||
579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
579 | Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
580 | { |
|
580 | { | |
581 | Q_Q(QAbstractBarSeries); |
|
581 | Q_Q(QAbstractBarSeries); | |
582 |
|
582 | |||
583 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
583 | BarChartItem* bar = new BarChartItem(q,presenter); | |
584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
584 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
585 | presenter->animator()->addAnimation(bar); |
|
585 | presenter->animator()->addAnimation(bar); | |
586 | } |
|
586 | } | |
587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
587 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
588 | return bar; |
|
588 | return bar; | |
589 |
|
589 | |||
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
592 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
593 | { |
|
593 | { | |
594 | Q_Q(QAbstractBarSeries); |
|
594 | Q_Q(QAbstractBarSeries); | |
595 | QList<LegendMarker*> markers; |
|
595 | QList<LegendMarker*> markers; | |
596 | foreach(QBarSet* set, q->barSets()) { |
|
596 | foreach(QBarSet* set, q->barSets()) { | |
597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
597 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
598 | markers << marker; |
|
598 | markers << marker; | |
599 | } |
|
599 | } | |
600 |
|
600 | |||
601 | return markers; |
|
601 | return markers; | |
602 | } |
|
602 | } | |
603 |
|
603 | |||
604 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent) |
|
|||
605 | { |
|
|||
606 | return new QCategoriesAxis(parent); |
|
|||
607 | } |
|
|||
608 |
|
||||
609 | QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent) |
|
|||
610 | { |
|
|||
611 | return new QValuesAxis(parent); |
|
|||
612 | } |
|
|||
613 |
|
||||
614 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
604 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
615 | { |
|
605 | { | |
616 | Q_Q(QAbstractBarSeries); |
|
606 | Q_Q(QAbstractBarSeries); | |
617 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
607 | if ((m_barSets.contains(set)) || (set == 0)) { | |
618 | // Fail if set is already in list or set is null. |
|
608 | // Fail if set is already in list or set is null. | |
619 | return false; |
|
609 | return false; | |
620 | } |
|
610 | } | |
621 | m_barSets.append(set); |
|
611 | m_barSets.append(set); | |
622 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
612 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
623 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
613 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
624 | emit restructuredBars(); // this notifies barchartitem |
|
614 | emit restructuredBars(); // this notifies barchartitem | |
625 | if (m_dataset) { |
|
615 | if (m_dataset) { | |
626 | m_dataset->updateSeries(q); // this notifies legend |
|
616 | m_dataset->updateSeries(q); // this notifies legend | |
627 | } |
|
617 | } | |
628 | return true; |
|
618 | return true; | |
629 | } |
|
619 | } | |
630 |
|
620 | |||
631 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
621 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
632 | { |
|
622 | { | |
633 | Q_Q(QAbstractBarSeries); |
|
623 | Q_Q(QAbstractBarSeries); | |
634 | if (!m_barSets.contains(set)) { |
|
624 | if (!m_barSets.contains(set)) { | |
635 | // Fail if set is not in list |
|
625 | // Fail if set is not in list | |
636 | return false; |
|
626 | return false; | |
637 | } |
|
627 | } | |
638 | m_barSets.removeOne(set); |
|
628 | m_barSets.removeOne(set); | |
639 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
629 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
640 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
630 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
641 | emit restructuredBars(); // this notifies barchartitem |
|
631 | emit restructuredBars(); // this notifies barchartitem | |
642 | if (m_dataset) { |
|
632 | if (m_dataset) { | |
643 | m_dataset->updateSeries(q); // this notifies legend |
|
633 | m_dataset->updateSeries(q); // this notifies legend | |
644 | } |
|
634 | } | |
645 | return true; |
|
635 | return true; | |
646 | } |
|
636 | } | |
647 |
|
637 | |||
648 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
638 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
649 | { |
|
639 | { | |
650 | Q_Q(QAbstractBarSeries); |
|
640 | Q_Q(QAbstractBarSeries); | |
651 | foreach (QBarSet* set, sets) { |
|
641 | foreach (QBarSet* set, sets) { | |
652 | if ((set == 0) || (m_barSets.contains(set))) { |
|
642 | if ((set == 0) || (m_barSets.contains(set))) { | |
653 | // Fail if any of the sets is null or is already appended. |
|
643 | // Fail if any of the sets is null or is already appended. | |
654 | return false; |
|
644 | return false; | |
655 | } |
|
645 | } | |
656 | if (sets.count(set) != 1) { |
|
646 | if (sets.count(set) != 1) { | |
657 | // Also fail if same set is more than once in given list. |
|
647 | // Also fail if same set is more than once in given list. | |
658 | return false; |
|
648 | return false; | |
659 | } |
|
649 | } | |
660 | } |
|
650 | } | |
661 |
|
651 | |||
662 | foreach (QBarSet* set, sets) { |
|
652 | foreach (QBarSet* set, sets) { | |
663 | m_barSets.append(set); |
|
653 | m_barSets.append(set); | |
664 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
654 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
665 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
655 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
666 | } |
|
656 | } | |
667 | emit restructuredBars(); // this notifies barchartitem |
|
657 | emit restructuredBars(); // this notifies barchartitem | |
668 | if (m_dataset) { |
|
658 | if (m_dataset) { | |
669 | m_dataset->updateSeries(q); // this notifies legend |
|
659 | m_dataset->updateSeries(q); // this notifies legend | |
670 | } |
|
660 | } | |
671 | return true; |
|
661 | return true; | |
672 | } |
|
662 | } | |
673 |
|
663 | |||
674 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
664 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
675 | { |
|
665 | { | |
676 | Q_Q(QAbstractBarSeries); |
|
666 | Q_Q(QAbstractBarSeries); | |
677 | if (sets.count() == 0) { |
|
667 | if (sets.count() == 0) { | |
678 | return false; |
|
668 | return false; | |
679 | } |
|
669 | } | |
680 | foreach (QBarSet* set, sets) { |
|
670 | foreach (QBarSet* set, sets) { | |
681 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
671 | if ((set == 0) || (!m_barSets.contains(set))) { | |
682 | // Fail if any of the sets is null or is not in series |
|
672 | // Fail if any of the sets is null or is not in series | |
683 | return false; |
|
673 | return false; | |
684 | } |
|
674 | } | |
685 | if (sets.count(set) != 1) { |
|
675 | if (sets.count(set) != 1) { | |
686 | // Also fail if same set is more than once in given list. |
|
676 | // Also fail if same set is more than once in given list. | |
687 | return false; |
|
677 | return false; | |
688 | } |
|
678 | } | |
689 | } |
|
679 | } | |
690 |
|
680 | |||
691 | foreach (QBarSet* set, sets) { |
|
681 | foreach (QBarSet* set, sets) { | |
692 | m_barSets.removeOne(set); |
|
682 | m_barSets.removeOne(set); | |
693 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
683 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
694 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
684 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
695 | } |
|
685 | } | |
696 |
|
686 | |||
697 | emit restructuredBars(); // this notifies barchartitem |
|
687 | emit restructuredBars(); // this notifies barchartitem | |
698 | if (m_dataset) { |
|
688 | if (m_dataset) { | |
699 | m_dataset->updateSeries(q); // this notifies legend |
|
689 | m_dataset->updateSeries(q); // this notifies legend | |
700 | } |
|
690 | } | |
701 | return true; |
|
691 | return true; | |
702 | } |
|
692 | } | |
703 |
|
693 | |||
704 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
694 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
705 | { |
|
695 | { | |
706 | Q_Q(QAbstractBarSeries); |
|
696 | Q_Q(QAbstractBarSeries); | |
707 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
697 | if ((m_barSets.contains(set)) || (set == 0)) { | |
708 | // Fail if set is already in list or set is null. |
|
698 | // Fail if set is already in list or set is null. | |
709 | return false; |
|
699 | return false; | |
710 | } |
|
700 | } | |
711 | m_barSets.insert(index, set); |
|
701 | m_barSets.insert(index, set); | |
712 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
702 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
713 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
703 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
714 | emit restructuredBars(); // this notifies barchartitem |
|
704 | emit restructuredBars(); // this notifies barchartitem | |
715 | if (m_dataset) { |
|
705 | if (m_dataset) { | |
716 | m_dataset->updateSeries(q); // this notifies legend |
|
706 | m_dataset->updateSeries(q); // this notifies legend | |
717 | } |
|
707 | } | |
718 | return true; |
|
708 | return true; | |
719 | } |
|
709 | } | |
720 |
|
710 | |||
|
711 | void QAbstractBarSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |||
|
712 | { | |||
|
713 | Q_UNUSED(axis); | |||
|
714 | } | |||
|
715 | ||||
|
716 | void QAbstractBarSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |||
|
717 | { | |||
|
718 | Q_UNUSED(axis) | |||
|
719 | } | |||
|
720 | ||||
|
721 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisXType() const | |||
|
722 | { | |||
|
723 | return QAbstractAxis::AxisTypeCategories; | |||
|
724 | } | |||
|
725 | ||||
|
726 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisYType() const | |||
|
727 | { | |||
|
728 | return QAbstractAxis::AxisTypeValues; | |||
|
729 | } | |||
|
730 | ||||
721 | #include "moc_qabstractbarseries.cpp" |
|
731 | #include "moc_qabstractbarseries.cpp" | |
722 | #include "moc_qabstractbarseries_p.cpp" |
|
732 | #include "moc_qabstractbarseries_p.cpp" | |
723 |
|
733 | |||
|
734 | ||||
724 | QTCOMMERCIALCHART_END_NAMESPACE |
|
735 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,97 +1,99 | |||||
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 QABSTRACTBARSERIES_P_H |
|
30 | #ifndef QABSTRACTBARSERIES_P_H | |
31 | #define QABSTRACTBARSERIES_P_H |
|
31 | #define QABSTRACTBARSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractbarseries.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 | void initializeAxisX(QAbstractAxis* axis); | |
60 | QAbstractAxis* createAxisY(QObject* parent = 0); |
|
60 | void initializeAxisY(QAbstractAxis* axis); | |
|
61 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
62 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
61 |
|
63 | |||
62 | bool append(QBarSet *set); |
|
64 | bool append(QBarSet *set); | |
63 | bool remove(QBarSet *set); |
|
65 | bool remove(QBarSet *set); | |
64 | bool append(QList<QBarSet* > sets); |
|
66 | bool append(QList<QBarSet* > sets); | |
65 | bool remove(QList<QBarSet* > sets); |
|
67 | bool remove(QList<QBarSet* > sets); | |
66 | bool insert(int index, QBarSet *set); |
|
68 | bool insert(int index, QBarSet *set); | |
67 |
|
69 | |||
68 | QBarSet* barsetAt(int index); |
|
70 | QBarSet* barsetAt(int index); | |
69 | qreal min(); |
|
71 | qreal min(); | |
70 | qreal max(); |
|
72 | qreal max(); | |
71 | qreal valueAt(int set, int category); |
|
73 | qreal valueAt(int set, int category); | |
72 | qreal percentageAt(int set, int category); |
|
74 | qreal percentageAt(int set, int category); | |
73 | qreal categorySum(int category); |
|
75 | qreal categorySum(int category); | |
74 | qreal absoluteCategorySum(int category); |
|
76 | qreal absoluteCategorySum(int category); | |
75 | qreal maxCategorySum(); |
|
77 | qreal maxCategorySum(); | |
76 | qreal minX(); |
|
78 | qreal minX(); | |
77 | qreal maxX(); |
|
79 | qreal maxX(); | |
78 |
|
80 | |||
79 | Q_SIGNALS: |
|
81 | Q_SIGNALS: | |
80 | void clicked(int index, QBarSet *barset); |
|
82 | void clicked(int index, QBarSet *barset); | |
81 | void updatedBars(); |
|
83 | void updatedBars(); | |
82 | void restructuredBars(); |
|
84 | void restructuredBars(); | |
83 | void labelsVisibleChanged(bool visible); |
|
85 | void labelsVisibleChanged(bool visible); | |
84 |
|
86 | |||
85 | protected: |
|
87 | protected: | |
86 | QList<QBarSet *> m_barSets; |
|
88 | QList<QBarSet *> m_barSets; | |
87 | qreal m_barWidth; |
|
89 | qreal m_barWidth; | |
88 | bool m_labelsVisible; |
|
90 | bool m_labelsVisible; | |
89 | bool m_visible; |
|
91 | bool m_visible; | |
90 |
|
92 | |||
91 | private: |
|
93 | private: | |
92 | Q_DECLARE_PUBLIC(QAbstractBarSeries) |
|
94 | Q_DECLARE_PUBLIC(QAbstractBarSeries) | |
93 | }; |
|
95 | }; | |
94 |
|
96 | |||
95 | QTCOMMERCIALCHART_END_NAMESPACE |
|
97 | QTCOMMERCIALCHART_END_NAMESPACE | |
96 |
|
98 | |||
97 | #endif // QABSTRACTBARSERIES_P_H |
|
99 | #endif // QABSTRACTBARSERIES_P_H |
@@ -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, QAbstractBarSeries |
|
44 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass PercentBarSeries QPercentBarSeries |
|
47 | \qmlclass PercentBarSeries QPercentBarSeries | |
48 | \inherits BarSeries |
|
48 | \inherits QAbstractBarSeries | |
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,339 +1,417 | |||||
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 "qcategoriesaxis.h" | |||
24 | #include "qvaluesaxis_p.h" |
|
25 | #include "qvaluesaxis_p.h" | |
25 | #include "qabstractseries_p.h" |
|
26 | #include "qabstractseries_p.h" | |
26 | #include "qabstractbarseries.h" |
|
27 | #include "qabstractbarseries.h" | |
27 | #include "qstackedbarseries.h" |
|
28 | #include "qstackedbarseries.h" | |
28 | #include "qpercentbarseries.h" |
|
29 | #include "qpercentbarseries.h" | |
29 | #include "qpieseries.h" |
|
30 | #include "qpieseries.h" | |
30 |
|
31 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 |
|
33 | |||
33 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), |
|
34 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), | |
34 | m_domainIndex(0) |
|
35 | m_domainIndex(0) | |
35 | { |
|
36 | { | |
36 |
|
37 | |||
37 | } |
|
38 | } | |
38 |
|
39 | |||
39 | ChartDataSet::~ChartDataSet() |
|
40 | ChartDataSet::~ChartDataSet() | |
40 | { |
|
41 | { | |
41 | removeAllSeries(); |
|
42 | removeAllSeries(); | |
42 | } |
|
43 | } | |
43 |
|
44 | |||
44 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
45 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
45 | { |
|
46 | { | |
46 | Domain* domain = m_seriesDomainMap.value(series); |
|
47 | Domain* domain = m_seriesDomainMap.value(series); | |
47 |
|
48 | |||
48 | if(domain) { |
|
49 | if(domain) { | |
49 | qWarning() << "Can not add series. Series already on the chart"; |
|
50 | qWarning() << "Can not add series. Series already on the chart"; | |
50 | return; |
|
51 | return; | |
51 | } |
|
52 | } | |
52 |
|
53 | |||
53 | series->setParent(this); // take ownership |
|
54 | series->setParent(this); // take ownership | |
54 |
|
55 | |||
55 | domain = new Domain(series); |
|
56 | domain = new Domain(series); | |
56 |
|
57 | |||
57 | m_seriesDomainMap.insert(series,domain); |
|
58 | m_seriesDomainMap.insert(series,domain); | |
58 |
|
59 | |||
59 | series->d_ptr->scaleDomain(*domain); |
|
60 | series->d_ptr->scaleDomain(*domain); | |
60 |
|
61 | |||
61 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
62 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
62 |
|
63 | |||
63 | int key=0; |
|
64 | int key=0; | |
64 | while (i.hasNext()) { |
|
65 | while (i.hasNext()) { | |
65 | i.next(); |
|
66 | i.next(); | |
66 | if(i.key()!=key) { |
|
67 | if(i.key()!=key) { | |
67 | break; |
|
68 | break; | |
68 | } |
|
69 | } | |
69 | key++; |
|
70 | key++; | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | m_indexSeriesMap.insert(key,series); |
|
73 | m_indexSeriesMap.insert(key,series); | |
73 |
|
74 | |||
74 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
75 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
75 | series->d_ptr->m_dataset = this; |
|
76 | series->d_ptr->m_dataset = this; | |
76 |
|
77 | |||
77 | emit seriesAdded(series,domain); |
|
78 | emit seriesAdded(series,domain); | |
78 |
|
79 | |||
79 | } |
|
80 | } | |
80 |
|
81 | |||
81 | void ChartDataSet::createDefaultAxes() |
|
82 | void ChartDataSet::createDefaultAxes() | |
82 | { |
|
83 | { | |
83 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
|||
84 |
|
84 | |||
|
85 | if(m_seriesDomainMap.isEmpty()) return; | |||
|
86 | ||||
|
87 | QAbstractAxis::AxisTypes typeX(0); | |||
|
88 | QAbstractAxis::AxisTypes typeY(0); | |||
|
89 | ||||
|
90 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |||
85 | while (i.hasNext()) { |
|
91 | while (i.hasNext()) { | |
86 | i.next(); |
|
92 | i.next(); | |
|
93 | removeAxes(i.key()); | |||
|
94 | } | |||
87 |
|
95 | |||
88 | if(!m_seriesAxisXMap.value(i.key())) |
|
96 | i.toFront(); | |
89 | { |
|
|||
90 |
|
97 | |||
91 | QAbstractAxis* axisX = i.key()->d_ptr->createAxisX(this); |
|
98 | while (i.hasNext()) { | |
|
99 | i.next(); | |||
|
100 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |||
|
101 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |||
|
102 | if(axisX) typeX&=axisX->type(); | |||
|
103 | else typeX|=i.key()->d_ptr->defaultAxisXType(); | |||
|
104 | if(axisY) typeY&=axisY->type(); | |||
|
105 | else typeY|=i.key()->d_ptr->defaultAxisYType(); | |||
|
106 | } | |||
92 |
|
107 | |||
93 | if(axisX) { |
|
|||
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))); |
|
|||
96 | axisX->d_ptr->m_orientation=Qt::Horizontal; |
|
|||
97 | emit axisAdded(axisX,i.value()); |
|
|||
98 | m_seriesAxisXMap.insert(i.key(),axisX); |
|
|||
99 | } |
|
|||
100 |
|
108 | |||
|
109 | if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories)) | |||
|
110 | { | |||
|
111 | i.toFront(); | |||
|
112 | while (i.hasNext()) { | |||
|
113 | i.next(); | |||
|
114 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType()); | |||
|
115 | i.key()->d_ptr->initializeAxisX(axis); | |||
|
116 | addAxisX(axis,i.key()); | |||
|
117 | emit axisAdded(axis,i.value()); | |||
101 | } |
|
118 | } | |
102 |
|
119 | |||
103 | if(!m_seriesAxisYMap.value(i.key())) |
|
120 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ | |
104 | { |
|
121 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX))); | |
105 | QAbstractAxis* axisY = i.key()->d_ptr->createAxisY(this); |
|
122 | i.toFront(); | |
106 |
|
123 | while (i.hasNext()) { | ||
107 | if(axisY) { |
|
124 | i.next(); | |
108 | QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),i.value(),SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
125 | i.key()->d_ptr->initializeAxisX(axis); | |
109 | QObject::connect(i.value(),SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
126 | addAxisX(axis,i.key()); | |
110 | axisY->d_ptr->m_orientation=Qt::Vertical; |
|
127 | } | |
111 |
|
|
128 | emit axisAdded(axis,i.value()); | |
112 | m_seriesAxisYMap.insert(i.key(),axisY); |
|
129 | ||
113 | } |
|
130 | } | |
|
131 | ||||
|
132 | if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories)) | |||
|
133 | { | |||
|
134 | i.toFront(); | |||
|
135 | while (i.hasNext()) { | |||
|
136 | i.next(); | |||
|
137 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType()); | |||
|
138 | i.key()->d_ptr->initializeAxisY(axis); | |||
|
139 | addAxisY(axis,i.key()); | |||
|
140 | emit axisAdded(axis,i.value()); | |||
114 | } |
|
141 | } | |
|
142 | ||||
|
143 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ | |||
|
144 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY))); | |||
|
145 | i.toFront(); | |||
|
146 | while (i.hasNext()) { | |||
|
147 | i.next(); | |||
|
148 | i.key()->d_ptr->initializeAxisY(axis); | |||
|
149 | addAxisY(axis,i.key()); | |||
|
150 | } | |||
|
151 | emit axisAdded(axis,i.value()); | |||
|
152 | ||||
115 | } |
|
153 | } | |
116 | } |
|
154 | } | |
117 |
|
155 | |||
118 |
|
156 | |||
|
157 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type) | |||
|
158 | { | |||
|
159 | QAbstractAxis* axis =0; | |||
|
160 | ||||
|
161 | switch(type) { | |||
|
162 | case QAbstractAxis::AxisTypeValues: | |||
|
163 | axis = new QValuesAxis(this); | |||
|
164 | break; | |||
|
165 | case QAbstractAxis::AxisTypeCategories: | |||
|
166 | axis = new QCategoriesAxis(this); | |||
|
167 | break; | |||
|
168 | default: | |||
|
169 | axis = 0; | |||
|
170 | break; | |||
|
171 | } | |||
|
172 | ||||
|
173 | return axis; | |||
|
174 | } | |||
|
175 | ||||
|
176 | void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) { | |||
|
177 | Domain* domain = m_seriesDomainMap.value(series); | |||
|
178 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |||
|
179 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |||
|
180 | axis->d_ptr->m_orientation=Qt::Horizontal; | |||
|
181 | m_seriesAxisXMap.insert(series,axis); | |||
|
182 | } | |||
|
183 | ||||
|
184 | void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) { | |||
|
185 | Domain* domain = m_seriesDomainMap.value(series); | |||
|
186 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |||
|
187 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |||
|
188 | axis->d_ptr->m_orientation=Qt::Vertical; | |||
|
189 | m_seriesAxisYMap.insert(series,axis); | |||
|
190 | } | |||
|
191 | ||||
119 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
192 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
120 | { |
|
193 | { | |
121 | Domain* domain = m_seriesDomainMap.take(series); |
|
194 | Domain* domain = m_seriesDomainMap.take(series); | |
122 |
|
195 | |||
123 | if(!domain) { |
|
196 | if(!domain) { | |
124 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
197 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
125 | } |
|
198 | } | |
126 |
|
199 | |||
127 | emit seriesRemoved(series); |
|
200 | emit seriesRemoved(series); | |
128 |
|
201 | |||
129 | delete domain; |
|
202 | delete domain; | |
130 | domain = 0; |
|
203 | domain = 0; | |
131 |
|
204 | |||
132 | int key = seriesIndex(series); |
|
205 | int key = seriesIndex(series); | |
133 | Q_ASSERT(key!=-1); |
|
206 | Q_ASSERT(key!=-1); | |
134 |
|
207 | |||
135 | m_indexSeriesMap.remove(key); |
|
208 | m_indexSeriesMap.remove(key); | |
136 |
|
209 | |||
137 | series->setParent(0); |
|
210 | series->setParent(0); | |
138 | series->d_ptr->m_chart = 0; |
|
211 | series->d_ptr->m_chart = 0; | |
139 | series->d_ptr->m_dataset = 0; |
|
212 | series->d_ptr->m_dataset = 0; | |
140 |
|
213 | |||
|
214 | removeAxes(series); | |||
|
215 | } | |||
|
216 | ||||
|
217 | void ChartDataSet::removeAxes(QAbstractSeries* series) | |||
|
218 | { | |||
141 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
219 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
142 |
|
220 | |||
143 | if(axisX) { |
|
221 | if(axisX) { | |
144 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
222 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
145 | int x = axesX.indexOf(axisX); |
|
223 | int x = axesX.indexOf(axisX); | |
146 |
|
224 | |||
147 | if(x==-1) { |
|
225 | if(x==-1) { | |
148 | emit axisRemoved(axisX); |
|
226 | emit axisRemoved(axisX); | |
149 | axisX->deleteLater(); |
|
227 | axisX->deleteLater(); | |
150 | } |
|
228 | } | |
151 | } |
|
229 | } | |
152 |
|
230 | |||
153 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
231 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
154 |
|
232 | |||
155 | if(axisY) { |
|
233 | if(axisY) { | |
156 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
234 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
157 |
|
235 | |||
158 | int y = axesY.indexOf(axisY); |
|
236 | int y = axesY.indexOf(axisY); | |
159 |
|
237 | |||
160 | if(y==-1) { |
|
238 | if(y==-1) { | |
161 | emit axisRemoved(axisY); |
|
239 | emit axisRemoved(axisY); | |
162 | axisY->deleteLater(); |
|
240 | axisY->deleteLater(); | |
163 | } |
|
241 | } | |
164 | } |
|
242 | } | |
165 | } |
|
243 | } | |
166 |
|
244 | |||
167 | void ChartDataSet::removeAllSeries() |
|
245 | void ChartDataSet::removeAllSeries() | |
168 | { |
|
246 | { | |
169 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
247 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
170 | foreach(QAbstractSeries *s , series) { |
|
248 | foreach(QAbstractSeries *s , series) { | |
171 | removeSeries(s); |
|
249 | removeSeries(s); | |
172 | } |
|
250 | } | |
173 |
|
251 | |||
174 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
252 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
175 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
253 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
176 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
254 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
177 |
|
255 | |||
178 | qDeleteAll(series); |
|
256 | qDeleteAll(series); | |
179 | } |
|
257 | } | |
180 |
|
258 | |||
181 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
259 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
182 | { |
|
260 | { | |
183 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
261 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
184 | while (i.hasNext()) { |
|
262 | while (i.hasNext()) { | |
185 | i.next(); |
|
263 | i.next(); | |
186 | i.value()->zoomIn(rect,size); |
|
264 | i.value()->zoomIn(rect,size); | |
187 | } |
|
265 | } | |
188 | } |
|
266 | } | |
189 |
|
267 | |||
190 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
268 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
191 | { |
|
269 | { | |
192 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
270 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
193 | while (i.hasNext()) { |
|
271 | while (i.hasNext()) { | |
194 | i.next(); |
|
272 | i.next(); | |
195 | i.value()->zoomOut(rect,size); |
|
273 | i.value()->zoomOut(rect,size); | |
196 | } |
|
274 | } | |
197 | } |
|
275 | } | |
198 |
|
276 | |||
199 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
277 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
200 | { |
|
278 | { | |
201 | int count=0; |
|
279 | int count=0; | |
202 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
280 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
203 | while (i.hasNext()) { |
|
281 | while (i.hasNext()) { | |
204 | i.next(); |
|
282 | i.next(); | |
205 | if(i.key()->type()==type) count++; |
|
283 | if(i.key()->type()==type) count++; | |
206 | } |
|
284 | } | |
207 | return count; |
|
285 | return count; | |
208 | } |
|
286 | } | |
209 |
|
287 | |||
210 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
288 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
211 | { |
|
289 | { | |
212 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
290 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
213 | while (i.hasNext()) { |
|
291 | while (i.hasNext()) { | |
214 | i.next(); |
|
292 | i.next(); | |
215 | if (i.value() == series) |
|
293 | if (i.value() == series) | |
216 | return i.key(); |
|
294 | return i.key(); | |
217 | } |
|
295 | } | |
218 | return -1; |
|
296 | return -1; | |
219 | } |
|
297 | } | |
220 |
|
298 | |||
221 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
299 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
222 | { |
|
300 | { | |
223 | if(series == 0) return m_seriesAxisXMap.begin().value(); |
|
301 | if(series == 0) return m_seriesAxisXMap.begin().value(); | |
224 | return m_seriesAxisXMap.value(series); |
|
302 | return m_seriesAxisXMap.value(series); | |
225 | } |
|
303 | } | |
226 |
|
304 | |||
227 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
305 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
228 | { |
|
306 | { | |
229 | if(series == 0) return m_seriesAxisYMap.begin().value(); |
|
307 | if(series == 0) return m_seriesAxisYMap.begin().value(); | |
230 | return m_seriesAxisYMap.value(series); |
|
308 | return m_seriesAxisYMap.value(series); | |
231 | } |
|
309 | } | |
232 |
|
310 | |||
233 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) |
|
311 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) | |
234 | { |
|
312 | { | |
235 | Q_ASSERT(axis); |
|
313 | Q_ASSERT(axis); | |
236 | Domain* domain = m_seriesDomainMap.value(series); |
|
314 | Domain* domain = m_seriesDomainMap.value(series); | |
237 |
|
315 | |||
238 | if(!domain) { |
|
316 | if(!domain) { | |
239 | qWarning() << "Series not found on the chart."; |
|
317 | qWarning() << "Series not found on the chart."; | |
240 | return; |
|
318 | return; | |
241 | } |
|
319 | } | |
242 |
|
320 | |||
243 | if(axis->d_ptr->m_orientation==Qt::Vertical) { |
|
321 | if(axis->d_ptr->m_orientation==Qt::Vertical) { | |
244 | qWarning()<<"Axis already defined as axis Y"; |
|
322 | qWarning()<<"Axis already defined as axis Y"; | |
245 | return; |
|
323 | return; | |
246 | } |
|
324 | } | |
247 |
|
325 | |||
248 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); |
|
326 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); | |
249 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
327 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
250 |
|
328 | |||
251 | if(oldAxis) { |
|
329 | if(oldAxis) { | |
252 |
|
330 | |||
253 | int x = axesX.indexOf(oldAxis); |
|
331 | int x = axesX.indexOf(oldAxis); | |
254 | if(x==-1) { |
|
332 | if(x==-1) { | |
255 | emit axisRemoved(oldAxis); |
|
333 | emit axisRemoved(oldAxis); | |
256 | oldAxis->deleteLater(); |
|
334 | oldAxis->deleteLater(); | |
257 | } |
|
335 | } | |
258 | } |
|
336 | } | |
259 |
|
337 | |||
260 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
338 | 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))); |
|
339 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
262 |
|
340 | |||
263 | int x = axesX.indexOf(axis); |
|
341 | int x = axesX.indexOf(axis); | |
264 | if(x==-1) { |
|
342 | if(x==-1) { | |
265 | axis->d_ptr->m_orientation=Qt::Horizontal; |
|
343 | axis->d_ptr->m_orientation=Qt::Horizontal; | |
266 | emit axisAdded(axis,domain); |
|
344 | emit axisAdded(axis,domain); | |
267 | } |
|
345 | } | |
268 |
|
346 | |||
269 | m_seriesAxisXMap.insert(series,axis); |
|
347 | m_seriesAxisXMap.insert(series,axis); | |
270 |
|
348 | |||
271 | // Force range update |
|
349 | // Force range update | |
272 | axis->d_ptr->updateRange(); |
|
350 | axis->d_ptr->updateRange(); | |
273 | } |
|
351 | } | |
274 |
|
352 | |||
275 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) |
|
353 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) | |
276 | { |
|
354 | { | |
277 | Q_ASSERT(axis); |
|
355 | Q_ASSERT(axis); | |
278 | Domain* domain = m_seriesDomainMap.value(series); |
|
356 | Domain* domain = m_seriesDomainMap.value(series); | |
279 |
|
357 | |||
280 | if(!domain) { |
|
358 | if(!domain) { | |
281 | qWarning() << "Series not found on the chart."; |
|
359 | qWarning() << "Series not found on the chart."; | |
282 | return; |
|
360 | return; | |
283 | } |
|
361 | } | |
284 |
|
362 | |||
285 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { |
|
363 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { | |
286 | qWarning()<<"Axis already defined as axis X"; |
|
364 | qWarning()<<"Axis already defined as axis X"; | |
287 | return; |
|
365 | return; | |
288 | } |
|
366 | } | |
289 |
|
367 | |||
290 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); |
|
368 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); | |
291 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
369 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
292 |
|
370 | |||
293 | if(oldAxis) { |
|
371 | if(oldAxis) { | |
294 | int y = axesY.indexOf(oldAxis); |
|
372 | int y = axesY.indexOf(oldAxis); | |
295 | if(y==-1) { |
|
373 | if(y==-1) { | |
296 | emit axisRemoved(oldAxis); |
|
374 | emit axisRemoved(oldAxis); | |
297 | oldAxis->deleteLater(); |
|
375 | oldAxis->deleteLater(); | |
298 | } |
|
376 | } | |
299 | } |
|
377 | } | |
300 |
|
378 | |||
301 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
379 | 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))); |
|
380 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
303 |
|
381 | |||
304 | int y = axesY.indexOf(axis); |
|
382 | int y = axesY.indexOf(axis); | |
305 | if(y==-1) { |
|
383 | if(y==-1) { | |
306 | axis->d_ptr->m_orientation=Qt::Vertical; |
|
384 | axis->d_ptr->m_orientation=Qt::Vertical; | |
307 | emit axisAdded(axis,domain); |
|
385 | emit axisAdded(axis,domain); | |
308 | } |
|
386 | } | |
309 |
|
387 | |||
310 | m_seriesAxisYMap.insert(series,axis); |
|
388 | m_seriesAxisYMap.insert(series,axis); | |
311 | } |
|
389 | } | |
312 |
|
390 | |||
313 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
391 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
314 | { |
|
392 | { | |
315 | return m_seriesDomainMap.value(series); |
|
393 | return m_seriesDomainMap.value(series); | |
316 | } |
|
394 | } | |
317 |
|
395 | |||
318 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
396 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
319 | { |
|
397 | { | |
320 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
398 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
321 | while (i.hasNext()) { |
|
399 | while (i.hasNext()) { | |
322 | i.next(); |
|
400 | i.next(); | |
323 | i.value()->move(dx,dy,size); |
|
401 | i.value()->move(dx,dy,size); | |
324 | } |
|
402 | } | |
325 | } |
|
403 | } | |
326 |
|
404 | |||
327 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
405 | QList<QAbstractSeries*> ChartDataSet::series() const | |
328 | { |
|
406 | { | |
329 | return m_seriesAxisXMap.keys(); |
|
407 | return m_seriesAxisXMap.keys(); | |
330 | } |
|
408 | } | |
331 |
|
409 | |||
332 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
410 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
333 | { |
|
411 | { | |
334 | emit seriesUpdated(series); |
|
412 | emit seriesUpdated(series); | |
335 | } |
|
413 | } | |
336 |
|
414 | |||
337 | #include "moc_chartdataset_p.cpp" |
|
415 | #include "moc_chartdataset_p.cpp" | |
338 |
|
416 | |||
339 | QTCOMMERCIALCHART_END_NAMESPACE |
|
417 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,93 +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 CHARTDATASET_P_H |
|
30 | #ifndef CHARTDATASET_P_H | |
31 | #define CHARTDATASET_P_H |
|
31 | #define CHARTDATASET_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 | #include "domain_p.h" |
|
34 | #include "domain_p.h" | |
|
35 | #include "qabstractaxis_p.h" | |||
35 | #include <QVector> |
|
36 | #include <QVector> | |
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
39 | |||
39 | class QAbstractAxis; |
|
40 | class QAbstractAxis; | |
40 |
|
41 | |||
41 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject |
|
42 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject | |
42 | { |
|
43 | { | |
43 | Q_OBJECT |
|
44 | Q_OBJECT | |
44 | public: |
|
45 | public: | |
45 | ChartDataSet(QChart* parent=0); |
|
46 | ChartDataSet(QChart* parent=0); | |
46 | virtual ~ChartDataSet(); |
|
47 | virtual ~ChartDataSet(); | |
47 |
|
48 | |||
48 | void addSeries(QAbstractSeries* series); |
|
49 | void addSeries(QAbstractSeries* series); | |
49 | void removeSeries(QAbstractSeries* series); |
|
50 | void removeSeries(QAbstractSeries* series); | |
50 | void removeAllSeries(); |
|
51 | void removeAllSeries(); | |
51 | void updateSeries(QAbstractSeries* series); |
|
52 | void updateSeries(QAbstractSeries* series); | |
52 |
|
53 | |||
53 | void zoomInDomain(const QRectF& rect, const QSizeF& size); |
|
54 | void zoomInDomain(const QRectF& rect, const QSizeF& size); | |
54 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); |
|
55 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); | |
55 | void scrollDomain(qreal dx,qreal dy,const QSizeF& size); |
|
56 | void scrollDomain(qreal dx,qreal dy,const QSizeF& size); | |
56 |
|
57 | |||
57 | int seriesCount(QAbstractSeries::SeriesType type); |
|
58 | int seriesCount(QAbstractSeries::SeriesType type); | |
58 | int seriesIndex(QAbstractSeries *series); |
|
59 | int seriesIndex(QAbstractSeries *series); | |
59 |
|
60 | |||
60 | QAbstractAxis* axisX(QAbstractSeries *series) const; |
|
61 | QAbstractAxis* axisX(QAbstractSeries *series) const; | |
61 | QAbstractAxis* axisY(QAbstractSeries *series) const; |
|
62 | QAbstractAxis* axisY(QAbstractSeries *series) const; | |
62 |
|
63 | |||
63 | void setAxisX(QAbstractSeries *series, QAbstractAxis *axis); |
|
64 | void setAxisX(QAbstractSeries *series, QAbstractAxis *axis); | |
64 | void setAxisY(QAbstractSeries *series, QAbstractAxis *axis); |
|
65 | void setAxisY(QAbstractSeries *series, QAbstractAxis *axis); | |
65 |
|
66 | |||
66 | QList<QAbstractSeries*> series() const; |
|
67 | QList<QAbstractSeries*> series() const; | |
67 | Domain* domain(QAbstractSeries *series) const; |
|
68 | Domain* domain(QAbstractSeries *series) const; | |
68 |
|
69 | |||
69 | void createDefaultAxes(); |
|
70 | void createDefaultAxes(); | |
70 |
|
71 | |||
71 | Q_SIGNALS: |
|
72 | Q_SIGNALS: | |
72 | void seriesAdded(QAbstractSeries* series, Domain* domain); |
|
73 | void seriesAdded(QAbstractSeries* series, Domain* domain); | |
73 | void seriesRemoved(QAbstractSeries* series); |
|
74 | void seriesRemoved(QAbstractSeries* series); | |
74 | void seriesUpdated(QAbstractSeries* series); |
|
75 | void seriesUpdated(QAbstractSeries* series); | |
75 | void axisAdded(QAbstractAxis* axis,Domain* domain); |
|
76 | void axisAdded(QAbstractAxis* axis,Domain* domain); | |
76 | void axisRemoved(QAbstractAxis* axis); |
|
77 | void axisRemoved(QAbstractAxis* axis); | |
77 |
|
78 | |||
78 | private: |
|
79 | private: | |
79 | QStringList createLabels(QAbstractAxis* axis,qreal min, qreal max); |
|
|||
80 | void calculateDomain(QAbstractSeries* series,Domain* domain); |
|
80 | void calculateDomain(QAbstractSeries* series,Domain* domain); | |
|
81 | QAbstractAxis* createAxis(QAbstractAxis::AxisType type); | |||
|
82 | void addAxisX(QAbstractAxis* axis,QAbstractSeries* series); | |||
|
83 | void addAxisY(QAbstractAxis* axis,QAbstractSeries* series); | |||
|
84 | void removeAxes(QAbstractSeries* series); | |||
81 |
|
85 | |||
82 | private: |
|
86 | private: | |
83 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap; |
|
87 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap; | |
84 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap; |
|
88 | QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap; | |
85 | QMap<QAbstractSeries*, Domain*> m_seriesDomainMap; |
|
89 | QMap<QAbstractSeries*, Domain*> m_seriesDomainMap; | |
86 | QMap<int, QAbstractSeries*> m_indexSeriesMap; |
|
90 | QMap<int, QAbstractSeries*> m_indexSeriesMap; | |
87 | int m_domainIndex; |
|
91 | int m_domainIndex; | |
88 |
|
92 | |||
89 | }; |
|
93 | }; | |
90 |
|
94 | |||
91 | QTCOMMERCIALCHART_END_NAMESPACE |
|
95 | QTCOMMERCIALCHART_END_NAMESPACE | |
92 |
|
96 | |||
93 | #endif /* CHARTENGINE_P_H_ */ |
|
97 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,773 +1,781 | |||||
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 "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "pieslicedata_p.h" |
|
25 | #include "pieslicedata_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "chartanimator_p.h" |
|
28 | #include "chartanimator_p.h" | |
29 | #include "legendmarker_p.h" |
|
29 | #include "legendmarker_p.h" | |
30 | #include "qabstractaxis.h" |
|
30 | #include "qabstractaxis.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QPieSeries |
|
35 | \class QPieSeries | |
36 | \brief Pie series API for QtCommercial Charts |
|
36 | \brief Pie series API for QtCommercial Charts | |
37 |
|
37 | |||
38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
38 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
39 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
40 | The actual slice size is determined by that relative value. |
|
40 | The actual slice size is determined by that relative value. | |
41 |
|
41 | |||
42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
42 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 | |
43 | These relate to the actual chart rectangle. |
|
43 | These relate to the actual chart rectangle. | |
44 |
|
44 | |||
45 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
45 | By default the pie is defined as a full pie but it can also be a partial pie. | |
46 | This can be done by setting a starting angle and angle span to the series. |
|
46 | This can be done by setting a starting angle and angle span to the series. | |
47 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
47 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
48 |
|
48 | |||
49 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. |
|
49 | See the \l {PieChart Example} {pie chart example} to learn how to create a simple pie chart. | |
50 | \image examples_piechart.png |
|
50 | \image examples_piechart.png | |
51 | */ |
|
51 | */ | |
52 | /*! |
|
52 | /*! | |
53 | \qmlclass PieSeries QPieSeries |
|
53 | \qmlclass PieSeries QPieSeries | |
54 | \inherits AbstractSeries |
|
54 | \inherits AbstractSeries | |
55 |
|
55 | |||
56 | The following QML shows how to create a simple pie chart. |
|
56 | The following QML shows how to create a simple pie chart. | |
57 |
|
57 | |||
58 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
58 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
59 |
|
59 | |||
60 | \beginfloatleft |
|
60 | \beginfloatleft | |
61 | \image demos_qmlchart1.png |
|
61 | \image demos_qmlchart1.png | |
62 | \endfloat |
|
62 | \endfloat | |
63 | \clearfloat |
|
63 | \clearfloat | |
64 | */ |
|
64 | */ | |
65 |
|
65 | |||
66 | /*! |
|
66 | /*! | |
67 | \property QPieSeries::horizontalPosition |
|
67 | \property QPieSeries::horizontalPosition | |
68 | \brief Defines the horizontal position of the pie. |
|
68 | \brief Defines the horizontal position of the pie. | |
69 |
|
69 | |||
70 | The value is a relative value to the chart rectangle where: |
|
70 | The value is a relative value to the chart rectangle where: | |
71 |
|
71 | |||
72 | \list |
|
72 | \list | |
73 | \o 0.0 is the absolute left. |
|
73 | \o 0.0 is the absolute left. | |
74 | \o 1.0 is the absolute right. |
|
74 | \o 1.0 is the absolute right. | |
75 | \endlist |
|
75 | \endlist | |
76 | Default value is 0.5 (center). |
|
76 | Default value is 0.5 (center). | |
77 | \sa verticalPosition |
|
77 | \sa verticalPosition | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty real PieSeries::horizontalPosition |
|
81 | \qmlproperty real PieSeries::horizontalPosition | |
82 |
|
82 | |||
83 | Defines the horizontal position of the pie. |
|
83 | Defines the horizontal position of the pie. | |
84 |
|
84 | |||
85 | The value is a relative value to the chart rectangle where: |
|
85 | The value is a relative value to the chart rectangle where: | |
86 |
|
86 | |||
87 | \list |
|
87 | \list | |
88 | \o 0.0 is the absolute left. |
|
88 | \o 0.0 is the absolute left. | |
89 | \o 1.0 is the absolute right. |
|
89 | \o 1.0 is the absolute right. | |
90 | \endlist |
|
90 | \endlist | |
91 | Default value is 0.5 (center). |
|
91 | Default value is 0.5 (center). | |
92 | \sa verticalPosition |
|
92 | \sa verticalPosition | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QPieSeries::verticalPosition |
|
96 | \property QPieSeries::verticalPosition | |
97 | \brief Defines the vertical position of the pie. |
|
97 | \brief Defines the vertical position of the pie. | |
98 |
|
98 | |||
99 | The value is a relative value to the chart rectangle where: |
|
99 | The value is a relative value to the chart rectangle where: | |
100 |
|
100 | |||
101 | \list |
|
101 | \list | |
102 | \o 0.0 is the absolute top. |
|
102 | \o 0.0 is the absolute top. | |
103 | \o 1.0 is the absolute bottom. |
|
103 | \o 1.0 is the absolute bottom. | |
104 | \endlist |
|
104 | \endlist | |
105 | Default value is 0.5 (center). |
|
105 | Default value is 0.5 (center). | |
106 | \sa horizontalPosition |
|
106 | \sa horizontalPosition | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty real PieSeries::verticalPosition |
|
110 | \qmlproperty real PieSeries::verticalPosition | |
111 |
|
111 | |||
112 | Defines the vertical position of the pie. |
|
112 | Defines the vertical position of the pie. | |
113 |
|
113 | |||
114 | The value is a relative value to the chart rectangle where: |
|
114 | The value is a relative value to the chart rectangle where: | |
115 |
|
115 | |||
116 | \list |
|
116 | \list | |
117 | \o 0.0 is the absolute top. |
|
117 | \o 0.0 is the absolute top. | |
118 | \o 1.0 is the absolute bottom. |
|
118 | \o 1.0 is the absolute bottom. | |
119 | \endlist |
|
119 | \endlist | |
120 | Default value is 0.5 (center). |
|
120 | Default value is 0.5 (center). | |
121 | \sa horizontalPosition |
|
121 | \sa horizontalPosition | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \property QPieSeries::size |
|
125 | \property QPieSeries::size | |
126 | \brief Defines the pie size. |
|
126 | \brief Defines the pie size. | |
127 |
|
127 | |||
128 | The value is a relative value to the chart rectangle where: |
|
128 | The value is a relative value to the chart rectangle where: | |
129 |
|
129 | |||
130 | \list |
|
130 | \list | |
131 | \o 0.0 is the minimum size (pie not drawn). |
|
131 | \o 0.0 is the minimum size (pie not drawn). | |
132 | \o 1.0 is the maximum size that can fit the chart. |
|
132 | \o 1.0 is the maximum size that can fit the chart. | |
133 | \endlist |
|
133 | \endlist | |
134 |
|
134 | |||
135 | Default value is 0.7. |
|
135 | Default value is 0.7. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \qmlproperty real PieSeries::size |
|
139 | \qmlproperty real PieSeries::size | |
140 |
|
140 | |||
141 | Defines the pie size. |
|
141 | Defines the pie size. | |
142 |
|
142 | |||
143 | The value is a relative value to the chart rectangle where: |
|
143 | The value is a relative value to the chart rectangle where: | |
144 |
|
144 | |||
145 | \list |
|
145 | \list | |
146 | \o 0.0 is the minimum size (pie not drawn). |
|
146 | \o 0.0 is the minimum size (pie not drawn). | |
147 | \o 1.0 is the maximum size that can fit the chart. |
|
147 | \o 1.0 is the maximum size that can fit the chart. | |
148 | \endlist |
|
148 | \endlist | |
149 |
|
149 | |||
150 | Default value is 0.7. |
|
150 | Default value is 0.7. | |
151 | */ |
|
151 | */ | |
152 |
|
152 | |||
153 | /*! |
|
153 | /*! | |
154 | \property QPieSeries::startAngle |
|
154 | \property QPieSeries::startAngle | |
155 | \brief Defines the starting angle of the pie. |
|
155 | \brief Defines the starting angle of the pie. | |
156 |
|
156 | |||
157 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
157 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
158 |
|
158 | |||
159 | Default is value is 0. |
|
159 | Default is value is 0. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | \qmlproperty real PieSeries::startAngle |
|
163 | \qmlproperty real PieSeries::startAngle | |
164 |
|
164 | |||
165 | Defines the starting angle of the pie. |
|
165 | Defines the starting angle of the pie. | |
166 |
|
166 | |||
167 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
167 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
168 |
|
168 | |||
169 | Default is value is 0. |
|
169 | Default is value is 0. | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \property QPieSeries::endAngle |
|
173 | \property QPieSeries::endAngle | |
174 | \brief Defines the ending angle of the pie. |
|
174 | \brief Defines the ending angle of the pie. | |
175 |
|
175 | |||
176 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
176 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
177 |
|
177 | |||
178 | Default is value is 360. |
|
178 | Default is value is 360. | |
179 | */ |
|
179 | */ | |
180 |
|
180 | |||
181 | /*! |
|
181 | /*! | |
182 | \qmlproperty real PieSeries::endAngle |
|
182 | \qmlproperty real PieSeries::endAngle | |
183 |
|
183 | |||
184 | Defines the ending angle of the pie. |
|
184 | Defines the ending angle of the pie. | |
185 |
|
185 | |||
186 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
186 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
187 |
|
187 | |||
188 | Default is value is 360. |
|
188 | Default is value is 360. | |
189 | */ |
|
189 | */ | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | \property QPieSeries::count |
|
192 | \property QPieSeries::count | |
193 |
|
193 | |||
194 | Number of slices in the series. |
|
194 | Number of slices in the series. | |
195 | */ |
|
195 | */ | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | \qmlproperty int PieSeries::count |
|
198 | \qmlproperty int PieSeries::count | |
199 |
|
199 | |||
200 | Number of slices in the series. |
|
200 | Number of slices in the series. | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \fn void QPieSeries::countChanged() |
|
204 | \fn void QPieSeries::countChanged() | |
205 | Emitted when the slice count has changed. |
|
205 | Emitted when the slice count has changed. | |
206 | \sa count |
|
206 | \sa count | |
207 | */ |
|
207 | */ | |
208 | /*! |
|
208 | /*! | |
209 | \qmlsignal PieSeries::onCountChanged() |
|
209 | \qmlsignal PieSeries::onCountChanged() | |
210 | Emitted when the slice count has changed. |
|
210 | Emitted when the slice count has changed. | |
211 | */ |
|
211 | */ | |
212 |
|
212 | |||
213 | /*! |
|
213 | /*! | |
214 | \property QPieSeries::sum |
|
214 | \property QPieSeries::sum | |
215 |
|
215 | |||
216 | Sum of all slices. |
|
216 | Sum of all slices. | |
217 |
|
217 | |||
218 | The series keeps track of the sum of all slices it holds. |
|
218 | The series keeps track of the sum of all slices it holds. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \qmlproperty real PieSeries::sum |
|
222 | \qmlproperty real PieSeries::sum | |
223 |
|
223 | |||
224 | Sum of all slices. |
|
224 | Sum of all slices. | |
225 |
|
225 | |||
226 | The series keeps track of the sum of all slices it holds. |
|
226 | The series keeps track of the sum of all slices it holds. | |
227 | */ |
|
227 | */ | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | \fn void QPieSeries::sumChanged() |
|
230 | \fn void QPieSeries::sumChanged() | |
231 | Emitted when the sum of all slices has changed. |
|
231 | Emitted when the sum of all slices has changed. | |
232 | \sa sum |
|
232 | \sa sum | |
233 | */ |
|
233 | */ | |
234 | /*! |
|
234 | /*! | |
235 | \qmlsignal PieSeries::onSumChanged() |
|
235 | \qmlsignal PieSeries::onSumChanged() | |
236 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
236 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
237 | change value of a slice. |
|
237 | change value of a slice. | |
238 | */ |
|
238 | */ | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
241 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
242 |
|
242 | |||
243 | This signal is emitted when \a slices have been added to the series. |
|
243 | This signal is emitted when \a slices have been added to the series. | |
244 |
|
244 | |||
245 | \sa append(), insert() |
|
245 | \sa append(), insert() | |
246 | */ |
|
246 | */ | |
247 | /*! |
|
247 | /*! | |
248 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
248 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
249 | Emitted when \a slice has been added to the series. |
|
249 | Emitted when \a slice has been added to the series. | |
250 | */ |
|
250 | */ | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
253 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
254 | This signal is emitted when \a slices have been removed from the series. |
|
254 | This signal is emitted when \a slices have been removed from the series. | |
255 | \sa remove() |
|
255 | \sa remove() | |
256 | */ |
|
256 | */ | |
257 | /*! |
|
257 | /*! | |
258 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
258 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
259 | Emitted when \a slice has been removed from the series. |
|
259 | Emitted when \a slice has been removed from the series. | |
260 | */ |
|
260 | */ | |
261 |
|
261 | |||
262 | /*! |
|
262 | /*! | |
263 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
263 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
264 | This signal is emitted when a \a slice has been clicked. |
|
264 | This signal is emitted when a \a slice has been clicked. | |
265 | \sa QPieSlice::clicked() |
|
265 | \sa QPieSlice::clicked() | |
266 | */ |
|
266 | */ | |
267 | /*! |
|
267 | /*! | |
268 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
268 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
269 | This signal is emitted when a \a slice has been clicked. |
|
269 | This signal is emitted when a \a slice has been clicked. | |
270 | */ |
|
270 | */ | |
271 |
|
271 | |||
272 | /*! |
|
272 | /*! | |
273 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
273 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
274 | This signal is emitted when user has hovered over or away from the \a slice. |
|
274 | This signal is emitted when user has hovered over or away from the \a slice. | |
275 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
275 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
276 | \sa QPieSlice::hovered() |
|
276 | \sa QPieSlice::hovered() | |
277 | */ |
|
277 | */ | |
278 | /*! |
|
278 | /*! | |
279 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
279 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
280 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
280 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
281 | over the slice and false when hover has moved away from the slice. |
|
281 | over the slice and false when hover has moved away from the slice. | |
282 | */ |
|
282 | */ | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | \qmlmethod PieSlice PieSeries::at(int index) |
|
285 | \qmlmethod PieSlice PieSeries::at(int index) | |
286 | Returns slice at \a index. Returns null if the index is not valid. |
|
286 | Returns slice at \a index. Returns null if the index is not valid. | |
287 | */ |
|
287 | */ | |
288 |
|
288 | |||
289 | /*! |
|
289 | /*! | |
290 | \qmlmethod PieSlice PieSeries::find(string label) |
|
290 | \qmlmethod PieSlice PieSeries::find(string label) | |
291 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
291 | Returns the first slice with \a label. Returns null if the index is not valid. | |
292 | */ |
|
292 | */ | |
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
295 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
296 | Adds a new slice with \a label and \a value to the pie. |
|
296 | Adds a new slice with \a label and \a value to the pie. | |
297 | */ |
|
297 | */ | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
300 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
301 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. |
|
301 | Removes the \a slice from the pie. Returns true if the removal was successfull, false otherwise. | |
302 | */ |
|
302 | */ | |
303 |
|
303 | |||
304 | /*! |
|
304 | /*! | |
305 | \qmlmethod PieSeries::clear() |
|
305 | \qmlmethod PieSeries::clear() | |
306 | Removes all slices from the pie. |
|
306 | Removes all slices from the pie. | |
307 | */ |
|
307 | */ | |
308 |
|
308 | |||
309 | /*! |
|
309 | /*! | |
310 | Constructs a series object which is a child of \a parent. |
|
310 | Constructs a series object which is a child of \a parent. | |
311 | */ |
|
311 | */ | |
312 | QPieSeries::QPieSeries(QObject *parent) : |
|
312 | QPieSeries::QPieSeries(QObject *parent) : | |
313 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) |
|
313 | QAbstractSeries(*new QPieSeriesPrivate(this),parent) | |
314 | { |
|
314 | { | |
315 |
|
315 | |||
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | /*! |
|
318 | /*! | |
319 | Destroys the series and its slices. |
|
319 | Destroys the series and its slices. | |
320 | */ |
|
320 | */ | |
321 | QPieSeries::~QPieSeries() |
|
321 | QPieSeries::~QPieSeries() | |
322 | { |
|
322 | { | |
323 | // NOTE: d_prt destroyed by QObject |
|
323 | // NOTE: d_prt destroyed by QObject | |
324 | } |
|
324 | } | |
325 |
|
325 | |||
326 | /*! |
|
326 | /*! | |
327 | Returns QChartSeries::SeriesTypePie. |
|
327 | Returns QChartSeries::SeriesTypePie. | |
328 | */ |
|
328 | */ | |
329 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
329 | QAbstractSeries::SeriesType QPieSeries::type() const | |
330 | { |
|
330 | { | |
331 | return QAbstractSeries::SeriesTypePie; |
|
331 | return QAbstractSeries::SeriesTypePie; | |
332 | } |
|
332 | } | |
333 |
|
333 | |||
334 | /*! |
|
334 | /*! | |
335 | Appends a single \a slice to the series. |
|
335 | Appends a single \a slice to the series. | |
336 | Slice ownership is passed to the series. |
|
336 | Slice ownership is passed to the series. | |
337 |
|
337 | |||
338 | Returns true if append was succesfull. |
|
338 | Returns true if append was succesfull. | |
339 | */ |
|
339 | */ | |
340 | bool QPieSeries::append(QPieSlice* slice) |
|
340 | bool QPieSeries::append(QPieSlice* slice) | |
341 | { |
|
341 | { | |
342 | return append(QList<QPieSlice*>() << slice); |
|
342 | return append(QList<QPieSlice*>() << slice); | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | /*! |
|
345 | /*! | |
346 | Appends an array of \a slices to the series. |
|
346 | Appends an array of \a slices to the series. | |
347 | Slice ownership is passed to the series. |
|
347 | Slice ownership is passed to the series. | |
348 |
|
348 | |||
349 | Returns true if append was successfull. |
|
349 | Returns true if append was successfull. | |
350 | */ |
|
350 | */ | |
351 | bool QPieSeries::append(QList<QPieSlice*> slices) |
|
351 | bool QPieSeries::append(QList<QPieSlice*> slices) | |
352 | { |
|
352 | { | |
353 | Q_D(QPieSeries); |
|
353 | Q_D(QPieSeries); | |
354 |
|
354 | |||
355 | if (slices.count() == 0) |
|
355 | if (slices.count() == 0) | |
356 | return false; |
|
356 | return false; | |
357 |
|
357 | |||
358 | foreach (QPieSlice* s, slices) { |
|
358 | foreach (QPieSlice* s, slices) { | |
359 | if (!s || d->m_slices.contains(s)) |
|
359 | if (!s || d->m_slices.contains(s)) | |
360 | return false; |
|
360 | return false; | |
361 | if (s->series()) // already added to some series |
|
361 | if (s->series()) // already added to some series | |
362 | return false; |
|
362 | return false; | |
363 | } |
|
363 | } | |
364 |
|
364 | |||
365 | foreach (QPieSlice* s, slices) { |
|
365 | foreach (QPieSlice* s, slices) { | |
366 | s->setParent(this); |
|
366 | s->setParent(this); | |
367 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
367 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
368 | d->m_slices << s; |
|
368 | d->m_slices << s; | |
369 | } |
|
369 | } | |
370 |
|
370 | |||
371 | d->updateDerivativeData(); |
|
371 | d->updateDerivativeData(); | |
372 |
|
372 | |||
373 | foreach (QPieSlice* s, slices) { |
|
373 | foreach (QPieSlice* s, slices) { | |
374 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
374 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
375 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
375 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
376 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
376 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | emit added(slices); |
|
379 | emit added(slices); | |
380 | emit countChanged(); |
|
380 | emit countChanged(); | |
381 |
|
381 | |||
382 | return true; |
|
382 | return true; | |
383 | } |
|
383 | } | |
384 |
|
384 | |||
385 | /*! |
|
385 | /*! | |
386 | Appends a single \a slice to the series and returns a reference to the series. |
|
386 | Appends a single \a slice to the series and returns a reference to the series. | |
387 | Slice ownership is passed to the series. |
|
387 | Slice ownership is passed to the series. | |
388 | */ |
|
388 | */ | |
389 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) |
|
389 | QPieSeries& QPieSeries::operator << (QPieSlice* slice) | |
390 | { |
|
390 | { | |
391 | append(slice); |
|
391 | append(slice); | |
392 | return *this; |
|
392 | return *this; | |
393 | } |
|
393 | } | |
394 |
|
394 | |||
395 |
|
395 | |||
396 | /*! |
|
396 | /*! | |
397 | Appends a single slice to the series with give \a value and \a label. |
|
397 | Appends a single slice to the series with give \a value and \a label. | |
398 | Slice ownership is passed to the series. |
|
398 | Slice ownership is passed to the series. | |
399 | */ |
|
399 | */ | |
400 | QPieSlice* QPieSeries::append(QString label, qreal value) |
|
400 | QPieSlice* QPieSeries::append(QString label, qreal value) | |
401 | { |
|
401 | { | |
402 | QPieSlice* slice = new QPieSlice(label, value); |
|
402 | QPieSlice* slice = new QPieSlice(label, value); | |
403 | append(slice); |
|
403 | append(slice); | |
404 | return slice; |
|
404 | return slice; | |
405 | } |
|
405 | } | |
406 |
|
406 | |||
407 | /*! |
|
407 | /*! | |
408 | Inserts a single \a slice to the series before the slice at \a index position. |
|
408 | Inserts a single \a slice to the series before the slice at \a index position. | |
409 | Slice ownership is passed to the series. |
|
409 | Slice ownership is passed to the series. | |
410 |
|
410 | |||
411 | Returns true if insert was successfull. |
|
411 | Returns true if insert was successfull. | |
412 | */ |
|
412 | */ | |
413 | bool QPieSeries::insert(int index, QPieSlice* slice) |
|
413 | bool QPieSeries::insert(int index, QPieSlice* slice) | |
414 | { |
|
414 | { | |
415 | Q_D(QPieSeries); |
|
415 | Q_D(QPieSeries); | |
416 |
|
416 | |||
417 | if (index < 0 || index > d->m_slices.count()) |
|
417 | if (index < 0 || index > d->m_slices.count()) | |
418 | return false; |
|
418 | return false; | |
419 |
|
419 | |||
420 | if (!slice || d->m_slices.contains(slice)) |
|
420 | if (!slice || d->m_slices.contains(slice)) | |
421 | return false; |
|
421 | return false; | |
422 |
|
422 | |||
423 | if (slice->series()) // already added to some series |
|
423 | if (slice->series()) // already added to some series | |
424 | return false; |
|
424 | return false; | |
425 |
|
425 | |||
426 | slice->setParent(this); |
|
426 | slice->setParent(this); | |
427 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
427 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
428 | d->m_slices.insert(index, slice); |
|
428 | d->m_slices.insert(index, slice); | |
429 |
|
429 | |||
430 | d->updateDerivativeData(); |
|
430 | d->updateDerivativeData(); | |
431 |
|
431 | |||
432 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
432 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
433 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
433 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
434 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
434 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
435 |
|
435 | |||
436 | emit added(QList<QPieSlice*>() << slice); |
|
436 | emit added(QList<QPieSlice*>() << slice); | |
437 | emit countChanged(); |
|
437 | emit countChanged(); | |
438 |
|
438 | |||
439 | return true; |
|
439 | return true; | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | /*! |
|
442 | /*! | |
443 | Removes a single \a slice from the series and deletes the slice. |
|
443 | Removes a single \a slice from the series and deletes the slice. | |
444 |
|
444 | |||
445 | Do not reference the pointer after this call. |
|
445 | Do not reference the pointer after this call. | |
446 |
|
446 | |||
447 | Returns true if remove was successfull. |
|
447 | Returns true if remove was successfull. | |
448 | */ |
|
448 | */ | |
449 | bool QPieSeries::remove(QPieSlice* slice) |
|
449 | bool QPieSeries::remove(QPieSlice* slice) | |
450 | { |
|
450 | { | |
451 | Q_D(QPieSeries); |
|
451 | Q_D(QPieSeries); | |
452 |
|
452 | |||
453 | if (!d->m_slices.removeOne(slice)) |
|
453 | if (!d->m_slices.removeOne(slice)) | |
454 | return false; |
|
454 | return false; | |
455 |
|
455 | |||
456 | d->updateDerivativeData(); |
|
456 | d->updateDerivativeData(); | |
457 |
|
457 | |||
458 | emit removed(QList<QPieSlice*>() << slice); |
|
458 | emit removed(QList<QPieSlice*>() << slice); | |
459 | emit countChanged(); |
|
459 | emit countChanged(); | |
460 |
|
460 | |||
461 | delete slice; |
|
461 | delete slice; | |
462 | slice = 0; |
|
462 | slice = 0; | |
463 |
|
463 | |||
464 | return true; |
|
464 | return true; | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | /*! |
|
467 | /*! | |
468 | Clears all slices from the series. |
|
468 | Clears all slices from the series. | |
469 | */ |
|
469 | */ | |
470 | void QPieSeries::clear() |
|
470 | void QPieSeries::clear() | |
471 | { |
|
471 | { | |
472 | Q_D(QPieSeries); |
|
472 | Q_D(QPieSeries); | |
473 | if (d->m_slices.count() == 0) |
|
473 | if (d->m_slices.count() == 0) | |
474 | return; |
|
474 | return; | |
475 |
|
475 | |||
476 | QList<QPieSlice*> slices = d->m_slices; |
|
476 | QList<QPieSlice*> slices = d->m_slices; | |
477 | foreach (QPieSlice* s, d->m_slices) { |
|
477 | foreach (QPieSlice* s, d->m_slices) { | |
478 | d->m_slices.removeOne(s); |
|
478 | d->m_slices.removeOne(s); | |
479 | delete s; |
|
479 | delete s; | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | d->updateDerivativeData(); |
|
482 | d->updateDerivativeData(); | |
483 |
|
483 | |||
484 | emit removed(slices); |
|
484 | emit removed(slices); | |
485 | emit countChanged(); |
|
485 | emit countChanged(); | |
486 | } |
|
486 | } | |
487 |
|
487 | |||
488 | /*! |
|
488 | /*! | |
489 | Returns a list of slices that belong to this series. |
|
489 | Returns a list of slices that belong to this series. | |
490 | */ |
|
490 | */ | |
491 | QList<QPieSlice*> QPieSeries::slices() const |
|
491 | QList<QPieSlice*> QPieSeries::slices() const | |
492 | { |
|
492 | { | |
493 | Q_D(const QPieSeries); |
|
493 | Q_D(const QPieSeries); | |
494 | return d->m_slices; |
|
494 | return d->m_slices; | |
495 | } |
|
495 | } | |
496 |
|
496 | |||
497 | /*! |
|
497 | /*! | |
498 | returns the number of the slices in this series. |
|
498 | returns the number of the slices in this series. | |
499 | */ |
|
499 | */ | |
500 | int QPieSeries::count() const |
|
500 | int QPieSeries::count() const | |
501 | { |
|
501 | { | |
502 | Q_D(const QPieSeries); |
|
502 | Q_D(const QPieSeries); | |
503 | return d->m_slices.count(); |
|
503 | return d->m_slices.count(); | |
504 | } |
|
504 | } | |
505 |
|
505 | |||
506 | /*! |
|
506 | /*! | |
507 | Returns true is the series is empty. |
|
507 | Returns true is the series is empty. | |
508 | */ |
|
508 | */ | |
509 | bool QPieSeries::isEmpty() const |
|
509 | bool QPieSeries::isEmpty() const | |
510 | { |
|
510 | { | |
511 | Q_D(const QPieSeries); |
|
511 | Q_D(const QPieSeries); | |
512 | return d->m_slices.isEmpty(); |
|
512 | return d->m_slices.isEmpty(); | |
513 | } |
|
513 | } | |
514 |
|
514 | |||
515 | /*! |
|
515 | /*! | |
516 | Returns the sum of all slice values in this series. |
|
516 | Returns the sum of all slice values in this series. | |
517 |
|
517 | |||
518 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
518 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
519 | */ |
|
519 | */ | |
520 | qreal QPieSeries::sum() const |
|
520 | qreal QPieSeries::sum() const | |
521 | { |
|
521 | { | |
522 | Q_D(const QPieSeries); |
|
522 | Q_D(const QPieSeries); | |
523 | return d->m_sum; |
|
523 | return d->m_sum; | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
526 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
527 | { |
|
527 | { | |
528 | Q_D(QPieSeries); |
|
528 | Q_D(QPieSeries); | |
529 |
|
529 | |||
530 | if (relativePosition < 0.0) |
|
530 | if (relativePosition < 0.0) | |
531 | relativePosition = 0.0; |
|
531 | relativePosition = 0.0; | |
532 | if (relativePosition > 1.0) |
|
532 | if (relativePosition > 1.0) | |
533 | relativePosition = 1.0; |
|
533 | relativePosition = 1.0; | |
534 |
|
534 | |||
535 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { |
|
535 | if (!qFuzzyIsNull(d->m_pieRelativeHorPos - relativePosition)) { | |
536 | d->m_pieRelativeHorPos = relativePosition; |
|
536 | d->m_pieRelativeHorPos = relativePosition; | |
537 | emit d->horizontalPositionChanged(); |
|
537 | emit d->horizontalPositionChanged(); | |
538 | } |
|
538 | } | |
539 | } |
|
539 | } | |
540 |
|
540 | |||
541 | qreal QPieSeries::horizontalPosition() const |
|
541 | qreal QPieSeries::horizontalPosition() const | |
542 | { |
|
542 | { | |
543 | Q_D(const QPieSeries); |
|
543 | Q_D(const QPieSeries); | |
544 | return d->m_pieRelativeHorPos; |
|
544 | return d->m_pieRelativeHorPos; | |
545 | } |
|
545 | } | |
546 |
|
546 | |||
547 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
547 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
548 | { |
|
548 | { | |
549 | Q_D(QPieSeries); |
|
549 | Q_D(QPieSeries); | |
550 |
|
550 | |||
551 | if (relativePosition < 0.0) |
|
551 | if (relativePosition < 0.0) | |
552 | relativePosition = 0.0; |
|
552 | relativePosition = 0.0; | |
553 | if (relativePosition > 1.0) |
|
553 | if (relativePosition > 1.0) | |
554 | relativePosition = 1.0; |
|
554 | relativePosition = 1.0; | |
555 |
|
555 | |||
556 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { |
|
556 | if (!qFuzzyIsNull(d->m_pieRelativeVerPos - relativePosition)) { | |
557 | d->m_pieRelativeVerPos = relativePosition; |
|
557 | d->m_pieRelativeVerPos = relativePosition; | |
558 | emit d->verticalPositionChanged(); |
|
558 | emit d->verticalPositionChanged(); | |
559 | } |
|
559 | } | |
560 | } |
|
560 | } | |
561 |
|
561 | |||
562 | qreal QPieSeries::verticalPosition() const |
|
562 | qreal QPieSeries::verticalPosition() const | |
563 | { |
|
563 | { | |
564 | Q_D(const QPieSeries); |
|
564 | Q_D(const QPieSeries); | |
565 | return d->m_pieRelativeVerPos; |
|
565 | return d->m_pieRelativeVerPos; | |
566 | } |
|
566 | } | |
567 |
|
567 | |||
568 | void QPieSeries::setPieSize(qreal relativeSize) |
|
568 | void QPieSeries::setPieSize(qreal relativeSize) | |
569 | { |
|
569 | { | |
570 | Q_D(QPieSeries); |
|
570 | Q_D(QPieSeries); | |
571 |
|
571 | |||
572 | if (relativeSize < 0.0) |
|
572 | if (relativeSize < 0.0) | |
573 | relativeSize = 0.0; |
|
573 | relativeSize = 0.0; | |
574 | if (relativeSize > 1.0) |
|
574 | if (relativeSize > 1.0) | |
575 | relativeSize = 1.0; |
|
575 | relativeSize = 1.0; | |
576 |
|
576 | |||
577 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { |
|
577 | if (!qFuzzyIsNull(d->m_pieRelativeSize - relativeSize)) { | |
578 | d->m_pieRelativeSize = relativeSize; |
|
578 | d->m_pieRelativeSize = relativeSize; | |
579 | emit d->pieSizeChanged(); |
|
579 | emit d->pieSizeChanged(); | |
580 | } |
|
580 | } | |
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 | qreal QPieSeries::pieSize() const |
|
583 | qreal QPieSeries::pieSize() const | |
584 | { |
|
584 | { | |
585 | Q_D(const QPieSeries); |
|
585 | Q_D(const QPieSeries); | |
586 | return d->m_pieRelativeSize; |
|
586 | return d->m_pieRelativeSize; | |
587 | } |
|
587 | } | |
588 |
|
588 | |||
589 |
|
589 | |||
590 | void QPieSeries::setPieStartAngle(qreal angle) |
|
590 | void QPieSeries::setPieStartAngle(qreal angle) | |
591 | { |
|
591 | { | |
592 | Q_D(QPieSeries); |
|
592 | Q_D(QPieSeries); | |
593 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) |
|
593 | if (qFuzzyIsNull(d->m_pieStartAngle - angle)) | |
594 | return; |
|
594 | return; | |
595 | d->m_pieStartAngle = angle; |
|
595 | d->m_pieStartAngle = angle; | |
596 | d->updateDerivativeData(); |
|
596 | d->updateDerivativeData(); | |
597 | emit d->pieStartAngleChanged(); |
|
597 | emit d->pieStartAngleChanged(); | |
598 | } |
|
598 | } | |
599 |
|
599 | |||
600 | qreal QPieSeries::pieStartAngle() const |
|
600 | qreal QPieSeries::pieStartAngle() const | |
601 | { |
|
601 | { | |
602 | Q_D(const QPieSeries); |
|
602 | Q_D(const QPieSeries); | |
603 | return d->m_pieStartAngle; |
|
603 | return d->m_pieStartAngle; | |
604 | } |
|
604 | } | |
605 |
|
605 | |||
606 | /*! |
|
606 | /*! | |
607 | Sets the end angle of the pie. |
|
607 | Sets the end angle of the pie. | |
608 |
|
608 | |||
609 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
609 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
610 |
|
610 | |||
611 | \a angle must be greater than start angle. |
|
611 | \a angle must be greater than start angle. | |
612 |
|
612 | |||
613 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
613 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
614 | */ |
|
614 | */ | |
615 | void QPieSeries::setPieEndAngle(qreal angle) |
|
615 | void QPieSeries::setPieEndAngle(qreal angle) | |
616 | { |
|
616 | { | |
617 | Q_D(QPieSeries); |
|
617 | Q_D(QPieSeries); | |
618 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) |
|
618 | if (qFuzzyIsNull(d->m_pieEndAngle - angle)) | |
619 | return; |
|
619 | return; | |
620 | d->m_pieEndAngle = angle; |
|
620 | d->m_pieEndAngle = angle; | |
621 | d->updateDerivativeData(); |
|
621 | d->updateDerivativeData(); | |
622 | emit d->pieEndAngleChanged(); |
|
622 | emit d->pieEndAngleChanged(); | |
623 | } |
|
623 | } | |
624 |
|
624 | |||
625 | /*! |
|
625 | /*! | |
626 | Returns the end angle of the pie. |
|
626 | Returns the end angle of the pie. | |
627 |
|
627 | |||
628 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
628 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
629 |
|
629 | |||
630 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
630 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
631 | */ |
|
631 | */ | |
632 | qreal QPieSeries::pieEndAngle() const |
|
632 | qreal QPieSeries::pieEndAngle() const | |
633 | { |
|
633 | { | |
634 | Q_D(const QPieSeries); |
|
634 | Q_D(const QPieSeries); | |
635 | return d->m_pieEndAngle; |
|
635 | return d->m_pieEndAngle; | |
636 | } |
|
636 | } | |
637 |
|
637 | |||
638 | /*! |
|
638 | /*! | |
639 | Sets the all the slice labels \a visible or invisible. |
|
639 | Sets the all the slice labels \a visible or invisible. | |
640 |
|
640 | |||
641 | Note that this affects only the current slices in the series. |
|
641 | Note that this affects only the current slices in the series. | |
642 | If user adds a new slice the default label visibility is false. |
|
642 | If user adds a new slice the default label visibility is false. | |
643 |
|
643 | |||
644 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
644 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
645 | */ |
|
645 | */ | |
646 | void QPieSeries::setLabelsVisible(bool visible) |
|
646 | void QPieSeries::setLabelsVisible(bool visible) | |
647 | { |
|
647 | { | |
648 | Q_D(QPieSeries); |
|
648 | Q_D(QPieSeries); | |
649 | foreach (QPieSlice* s, d->m_slices) |
|
649 | foreach (QPieSlice* s, d->m_slices) | |
650 | s->setLabelVisible(visible); |
|
650 | s->setLabelVisible(visible); | |
651 | } |
|
651 | } | |
652 |
|
652 | |||
653 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
653 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
654 |
|
654 | |||
655 |
|
655 | |||
656 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
656 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
657 | QAbstractSeriesPrivate(parent), |
|
657 | QAbstractSeriesPrivate(parent), | |
658 | m_pieRelativeHorPos(0.5), |
|
658 | m_pieRelativeHorPos(0.5), | |
659 | m_pieRelativeVerPos(0.5), |
|
659 | m_pieRelativeVerPos(0.5), | |
660 | m_pieRelativeSize(0.7), |
|
660 | m_pieRelativeSize(0.7), | |
661 | m_pieStartAngle(0), |
|
661 | m_pieStartAngle(0), | |
662 | m_pieEndAngle(360), |
|
662 | m_pieEndAngle(360), | |
663 | m_sum(0) |
|
663 | m_sum(0) | |
664 | { |
|
664 | { | |
665 | } |
|
665 | } | |
666 |
|
666 | |||
667 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
667 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
668 | { |
|
668 | { | |
669 | } |
|
669 | } | |
670 |
|
670 | |||
671 | void QPieSeriesPrivate::updateDerivativeData() |
|
671 | void QPieSeriesPrivate::updateDerivativeData() | |
672 | { |
|
672 | { | |
673 | // calculate sum of all slices |
|
673 | // calculate sum of all slices | |
674 | qreal sum = 0; |
|
674 | qreal sum = 0; | |
675 | foreach (QPieSlice* s, m_slices) |
|
675 | foreach (QPieSlice* s, m_slices) | |
676 | sum += s->value(); |
|
676 | sum += s->value(); | |
677 |
|
677 | |||
678 | if (!qFuzzyIsNull(m_sum - sum)) { |
|
678 | if (!qFuzzyIsNull(m_sum - sum)) { | |
679 | m_sum = sum; |
|
679 | m_sum = sum; | |
680 | emit q_func()->sumChanged(); |
|
680 | emit q_func()->sumChanged(); | |
681 | } |
|
681 | } | |
682 |
|
682 | |||
683 | // nothing to show.. |
|
683 | // nothing to show.. | |
684 | if (qFuzzyIsNull(m_sum)) |
|
684 | if (qFuzzyIsNull(m_sum)) | |
685 | return; |
|
685 | return; | |
686 |
|
686 | |||
687 | // update slice attributes |
|
687 | // update slice attributes | |
688 | qreal sliceAngle = m_pieStartAngle; |
|
688 | qreal sliceAngle = m_pieStartAngle; | |
689 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
689 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
690 | QVector<QPieSlice*> changed; |
|
690 | QVector<QPieSlice*> changed; | |
691 | foreach (QPieSlice* s, m_slices) { |
|
691 | foreach (QPieSlice* s, m_slices) { | |
692 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
692 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
693 | d->setPercentage(s->value() / m_sum); |
|
693 | d->setPercentage(s->value() / m_sum); | |
694 | d->setStartAngle(sliceAngle); |
|
694 | d->setStartAngle(sliceAngle); | |
695 | d->setAngleSpan(pieSpan * s->percentage()); |
|
695 | d->setAngleSpan(pieSpan * s->percentage()); | |
696 | sliceAngle += s->angleSpan(); |
|
696 | sliceAngle += s->angleSpan(); | |
697 | } |
|
697 | } | |
698 |
|
698 | |||
699 |
|
699 | |||
700 | emit calculatedDataChanged(); |
|
700 | emit calculatedDataChanged(); | |
701 | } |
|
701 | } | |
702 |
|
702 | |||
703 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
703 | QPieSeriesPrivate* QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
704 | { |
|
704 | { | |
705 | return series->d_func(); |
|
705 | return series->d_func(); | |
706 | } |
|
706 | } | |
707 |
|
707 | |||
708 | void QPieSeriesPrivate::sliceValueChanged() |
|
708 | void QPieSeriesPrivate::sliceValueChanged() | |
709 | { |
|
709 | { | |
710 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
710 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
711 | updateDerivativeData(); |
|
711 | updateDerivativeData(); | |
712 | } |
|
712 | } | |
713 |
|
713 | |||
714 | void QPieSeriesPrivate::sliceClicked() |
|
714 | void QPieSeriesPrivate::sliceClicked() | |
715 | { |
|
715 | { | |
716 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
716 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
717 | Q_ASSERT(m_slices.contains(slice)); |
|
717 | Q_ASSERT(m_slices.contains(slice)); | |
718 | Q_Q(QPieSeries); |
|
718 | Q_Q(QPieSeries); | |
719 | emit q->clicked(slice); |
|
719 | emit q->clicked(slice); | |
720 | } |
|
720 | } | |
721 |
|
721 | |||
722 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
722 | void QPieSeriesPrivate::sliceHovered(bool state) | |
723 | { |
|
723 | { | |
724 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
724 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
725 | Q_ASSERT(m_slices.contains(slice)); |
|
725 | Q_ASSERT(m_slices.contains(slice)); | |
726 | Q_Q(QPieSeries); |
|
726 | Q_Q(QPieSeries); | |
727 | emit q->hovered(slice, state); |
|
727 | emit q->hovered(slice, state); | |
728 | } |
|
728 | } | |
729 |
|
729 | |||
730 | void QPieSeriesPrivate::scaleDomain(Domain& domain) |
|
730 | void QPieSeriesPrivate::scaleDomain(Domain& domain) | |
731 | { |
|
731 | { | |
732 | Q_UNUSED(domain); |
|
732 | Q_UNUSED(domain); | |
733 | // does not apply to pie |
|
733 | // does not apply to pie | |
734 | } |
|
734 | } | |
735 |
|
735 | |||
736 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
736 | Chart* QPieSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
737 | { |
|
737 | { | |
738 | Q_Q(QPieSeries); |
|
738 | Q_Q(QPieSeries); | |
739 | PieChartItem* pie = new PieChartItem(q,presenter); |
|
739 | PieChartItem* pie = new PieChartItem(q,presenter); | |
740 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
740 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
741 | presenter->animator()->addAnimation(pie); |
|
741 | presenter->animator()->addAnimation(pie); | |
742 | } |
|
742 | } | |
743 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
743 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
744 | return pie; |
|
744 | return pie; | |
745 | } |
|
745 | } | |
746 |
|
746 | |||
747 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) |
|
747 | QList<LegendMarker*> QPieSeriesPrivate::createLegendMarker(QLegend* legend) | |
748 | { |
|
748 | { | |
749 | Q_Q(QPieSeries); |
|
749 | Q_Q(QPieSeries); | |
750 | QList<LegendMarker*> markers; |
|
750 | QList<LegendMarker*> markers; | |
751 | foreach(QPieSlice* slice, q->slices()) { |
|
751 | foreach(QPieSlice* slice, q->slices()) { | |
752 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); |
|
752 | PieLegendMarker* marker = new PieLegendMarker(q,slice,legend); | |
753 | markers << marker; |
|
753 | markers << marker; | |
754 | } |
|
754 | } | |
755 | return markers; |
|
755 | return markers; | |
756 | } |
|
756 | } | |
757 |
|
757 | |||
758 |
|
|
758 | void QPieSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
759 | { |
|
759 | { | |
760 |
Q_UNUSED( |
|
760 | Q_UNUSED(axis); | |
761 | return 0; |
|
|||
762 | } |
|
761 | } | |
763 |
|
762 | |||
764 |
|
|
763 | void QPieSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
765 | { |
|
764 | { | |
766 |
Q_UNUSED( |
|
765 | Q_UNUSED(axis); | |
767 | return 0; |
|
766 | } | |
|
767 | ||||
|
768 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisXType() const | |||
|
769 | { | |||
|
770 | return QAbstractAxis::AxisTypeNoAxis; | |||
|
771 | } | |||
|
772 | ||||
|
773 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisYType() const | |||
|
774 | { | |||
|
775 | return QAbstractAxis::AxisTypeNoAxis; | |||
768 | } |
|
776 | } | |
769 |
|
777 | |||
770 | #include "moc_qpieseries.cpp" |
|
778 | #include "moc_qpieseries.cpp" | |
771 | #include "moc_qpieseries_p.cpp" |
|
779 | #include "moc_qpieseries_p.cpp" | |
772 |
|
780 | |||
773 | QTCOMMERCIALCHART_END_NAMESPACE |
|
781 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,86 +1,88 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // 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 QPIESERIES_P_H |
|
30 | #ifndef QPIESERIES_P_H | |
31 | #define QPIESERIES_P_H |
|
31 | #define QPIESERIES_P_H | |
32 |
|
32 | |||
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "qabstractseries_p.h" |
|
34 | #include "qabstractseries_p.h" | |
35 |
|
35 | |||
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
36 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
37 | class QLegendPrivate; |
|
37 | class QLegendPrivate; | |
38 |
|
38 | |||
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate |
|
39 | class QPieSeriesPrivate : public QAbstractSeriesPrivate | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 |
|
42 | |||
43 | public: |
|
43 | public: | |
44 | QPieSeriesPrivate(QPieSeries *parent); |
|
44 | QPieSeriesPrivate(QPieSeries *parent); | |
45 | ~QPieSeriesPrivate(); |
|
45 | ~QPieSeriesPrivate(); | |
46 |
|
46 | |||
47 | void scaleDomain(Domain& domain); |
|
47 | void scaleDomain(Domain& domain); | |
48 | Chart* createGraphics(ChartPresenter *presenter); |
|
48 | Chart* createGraphics(ChartPresenter *presenter); | |
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); |
|
49 | QList<LegendMarker*> createLegendMarker(QLegend *legend); | |
50 | QAbstractAxis* createAxisX(QObject* parent); |
|
50 | void initializeAxisX(QAbstractAxis* axis); | |
51 | QAbstractAxis* createAxisY(QObject* parent); |
|
51 | void initializeAxisY(QAbstractAxis* axis); | |
|
52 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
53 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
52 |
|
54 | |||
53 | void updateDerivativeData(); |
|
55 | void updateDerivativeData(); | |
54 |
|
56 | |||
55 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); |
|
57 | static QPieSeriesPrivate* fromSeries(QPieSeries *series); | |
56 |
|
58 | |||
57 | signals: |
|
59 | signals: | |
58 | void calculatedDataChanged(); |
|
60 | void calculatedDataChanged(); | |
59 | void pieSizeChanged(); |
|
61 | void pieSizeChanged(); | |
60 | void pieStartAngleChanged(); |
|
62 | void pieStartAngleChanged(); | |
61 | void pieEndAngleChanged(); |
|
63 | void pieEndAngleChanged(); | |
62 | void horizontalPositionChanged(); |
|
64 | void horizontalPositionChanged(); | |
63 | void verticalPositionChanged(); |
|
65 | void verticalPositionChanged(); | |
64 |
|
66 | |||
65 | public Q_SLOTS: |
|
67 | public Q_SLOTS: | |
66 | void sliceValueChanged(); |
|
68 | void sliceValueChanged(); | |
67 | void sliceClicked(); |
|
69 | void sliceClicked(); | |
68 | void sliceHovered(bool state); |
|
70 | void sliceHovered(bool state); | |
69 |
|
71 | |||
70 | private: |
|
72 | private: | |
71 | QList<QPieSlice*> m_slices; |
|
73 | QList<QPieSlice*> m_slices; | |
72 | qreal m_pieRelativeHorPos; |
|
74 | qreal m_pieRelativeHorPos; | |
73 | qreal m_pieRelativeVerPos; |
|
75 | qreal m_pieRelativeVerPos; | |
74 | qreal m_pieRelativeSize; |
|
76 | qreal m_pieRelativeSize; | |
75 | qreal m_pieStartAngle; |
|
77 | qreal m_pieStartAngle; | |
76 | qreal m_pieEndAngle; |
|
78 | qreal m_pieEndAngle; | |
77 | qreal m_sum; |
|
79 | qreal m_sum; | |
78 |
|
80 | |||
79 | private: |
|
81 | private: | |
80 | friend class QLegendPrivate; |
|
82 | friend class QLegendPrivate; | |
81 | Q_DECLARE_PUBLIC(QPieSeries) |
|
83 | Q_DECLARE_PUBLIC(QPieSeries) | |
82 | }; |
|
84 | }; | |
83 |
|
85 | |||
84 | QTCOMMERCIALCHART_END_NAMESPACE |
|
86 | QTCOMMERCIALCHART_END_NAMESPACE | |
85 |
|
87 | |||
86 | #endif // QPIESERIES_P_H |
|
88 | #endif // QPIESERIES_P_H |
@@ -1,83 +1,85 | |||||
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 QABSTRACTSERIES_H |
|
21 | #ifndef QABSTRACTSERIES_H | |
22 | #define QABSTRACTSERIES_H |
|
22 | #define QABSTRACTSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
|
25 | #include <qabstractaxis.h> | |||
25 | #include <QObject> |
|
26 | #include <QObject> | |
26 | #include <QPen> |
|
27 | #include <QPen> | |
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
30 | class QAbstractSeriesPrivate; |
|
31 | class QAbstractSeriesPrivate; | |
31 | class QChart; |
|
32 | class QChart; | |
32 |
|
33 | |||
33 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject | |
34 | { |
|
35 | { | |
35 | Q_OBJECT |
|
36 | Q_OBJECT | |
36 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | |
37 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
38 | Q_PROPERTY(SeriesType type READ type) |
|
39 | Q_PROPERTY(SeriesType type READ type) | |
39 | Q_ENUMS(SeriesType) |
|
40 | Q_ENUMS(SeriesType) | |
40 |
|
41 | |||
41 | public: |
|
42 | public: | |
42 | enum SeriesType { |
|
43 | enum SeriesType { | |
43 | SeriesTypeLine, |
|
44 | SeriesTypeLine, | |
44 | SeriesTypeArea, |
|
45 | SeriesTypeArea, | |
45 | SeriesTypeBar, |
|
46 | SeriesTypeBar, | |
46 | SeriesTypeStackedBar, |
|
47 | SeriesTypeStackedBar, | |
47 | SeriesTypePercentBar, |
|
48 | SeriesTypePercentBar, | |
48 | SeriesTypeGroupedBar, |
|
49 | SeriesTypeGroupedBar, | |
49 | SeriesTypePie, |
|
50 | SeriesTypePie, | |
50 | SeriesTypeScatter, |
|
51 | SeriesTypeScatter, | |
51 | SeriesTypeSpline |
|
52 | SeriesTypeSpline | |
52 | }; |
|
53 | }; | |
53 |
|
54 | |||
54 | protected: |
|
55 | protected: | |
55 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
56 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); | |
56 |
|
57 | |||
57 | public: |
|
58 | public: | |
58 | ~QAbstractSeries(); |
|
59 | ~QAbstractSeries(); | |
59 | virtual SeriesType type() const = 0; |
|
60 | virtual SeriesType type() const = 0; | |
|
61 | ||||
60 | void setName(const QString& name); |
|
62 | void setName(const QString& name); | |
61 | QString name() const; |
|
63 | QString name() const; | |
62 | void setVisible(bool visible = true); |
|
64 | void setVisible(bool visible = true); | |
63 | bool isVisible() const; |
|
65 | bool isVisible() const; | |
64 | QChart* chart() const; |
|
66 | QChart* chart() const; | |
65 |
|
67 | |||
66 | void adjustView(); |
|
68 | void adjustView(); | |
67 | void show(); |
|
69 | void show(); | |
68 | void hide(); |
|
70 | void hide(); | |
69 |
|
71 | |||
70 | Q_SIGNALS: |
|
72 | Q_SIGNALS: | |
71 | void nameChanged(); |
|
73 | void nameChanged(); | |
72 | void visibleChanged(); |
|
74 | void visibleChanged(); | |
73 |
|
75 | |||
74 | protected: |
|
76 | protected: | |
75 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
77 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; | |
76 | friend class ChartDataSet; |
|
78 | friend class ChartDataSet; | |
77 | friend class ChartPresenter; |
|
79 | friend class ChartPresenter; | |
78 | friend class QLegendPrivate; |
|
80 | friend class QLegendPrivate; | |
79 | }; |
|
81 | }; | |
80 |
|
82 | |||
81 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | QTCOMMERCIALCHART_END_NAMESPACE | |
82 |
|
84 | |||
83 | #endif |
|
85 | #endif |
@@ -1,71 +1,73 | |||||
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 QABSTRACTSERIES_P_H |
|
30 | #ifndef QABSTRACTSERIES_P_H | |
31 | #define QABSTRACTSERIES_P_H |
|
31 | #define QABSTRACTSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class Domain; |
|
37 | class Domain; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class Chart; |
|
39 | class Chart; | |
40 | class LegendMarker; |
|
40 | class LegendMarker; | |
41 | class QLegend; |
|
41 | class QLegend; | |
42 | class ChartDataSet; |
|
42 | class ChartDataSet; | |
43 | class QAbstractAxis; |
|
43 | class QAbstractAxis; | |
44 |
|
44 | |||
45 | class QAbstractSeriesPrivate : public QObject |
|
45 | class QAbstractSeriesPrivate : public QObject | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | QAbstractSeriesPrivate(QAbstractSeries *q); |
|
49 | QAbstractSeriesPrivate(QAbstractSeries *q); | |
50 | ~QAbstractSeriesPrivate(); |
|
50 | ~QAbstractSeriesPrivate(); | |
51 |
|
51 | |||
52 | virtual void scaleDomain(Domain& domain) = 0; |
|
52 | virtual void scaleDomain(Domain& domain) = 0; | |
53 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; |
|
53 | virtual Chart* createGraphics(ChartPresenter* presenter) = 0; | |
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; |
|
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; | |
55 |
virtual QAbstractAxis* |
|
55 | virtual void initializeAxisX(QAbstractAxis* axis) = 0; | |
56 |
virtual QAbstractAxis* |
|
56 | virtual void initializeAxisY(QAbstractAxis* axis) = 0; | |
|
57 | virtual QAbstractAxis::AxisType defaultAxisXType() const = 0; | |||
|
58 | virtual QAbstractAxis::AxisType defaultAxisYType() const = 0; | |||
57 |
|
59 | |||
58 | protected: |
|
60 | protected: | |
59 | QAbstractSeries *q_ptr; |
|
61 | QAbstractSeries *q_ptr; | |
60 | QChart *m_chart; |
|
62 | QChart *m_chart; | |
61 | ChartDataSet *m_dataset; |
|
63 | ChartDataSet *m_dataset; | |
62 | QString m_name; |
|
64 | QString m_name; | |
63 | bool m_visible; |
|
65 | bool m_visible; | |
64 |
|
66 | |||
65 | friend class QAbstractSeries; |
|
67 | friend class QAbstractSeries; | |
66 | friend class ChartDataSet; |
|
68 | friend class ChartDataSet; | |
67 | }; |
|
69 | }; | |
68 |
|
70 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
71 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
72 | |||
71 | #endif |
|
73 | #endif |
@@ -1,451 +1,461 | |||||
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 "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "domain_p.h" |
|
23 | #include "domain_p.h" | |
24 | #include "legendmarker_p.h" |
|
24 | #include "legendmarker_p.h" | |
25 | #include "qvaluesaxis.h" |
|
25 | #include "qvaluesaxis.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QXYSeries |
|
30 | \class QXYSeries | |
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
31 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
32 | */ |
|
32 | */ | |
33 | /*! |
|
33 | /*! | |
34 | \qmlclass XYSeries |
|
34 | \qmlclass XYSeries | |
35 | \inherits AbstractSeries |
|
35 | \inherits AbstractSeries | |
36 | The XYSeries class is a base class for line, spline and scatter series. |
|
36 | The XYSeries class is a base class for line, spline and scatter series. | |
37 |
|
37 | |||
38 | The class cannot be instantiated directly. |
|
38 | The class cannot be instantiated directly. | |
39 | */ |
|
39 | */ | |
40 |
|
40 | |||
41 | /*! |
|
41 | /*! | |
42 | \property QXYSeries::pointsVisible |
|
42 | \property QXYSeries::pointsVisible | |
43 | Controls if the data points are visible and should be drawn. |
|
43 | Controls if the data points are visible and should be drawn. | |
44 | */ |
|
44 | */ | |
45 | /*! |
|
45 | /*! | |
46 | \qmlproperty bool XYSeries::pointsVisible |
|
46 | \qmlproperty bool XYSeries::pointsVisible | |
47 | Controls if the data points are visible and should be drawn. |
|
47 | Controls if the data points are visible and should be drawn. | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \fn QPen QXYSeries::pen() const |
|
51 | \fn QPen QXYSeries::pen() const | |
52 | \brief Returns pen used to draw points for series. |
|
52 | \brief Returns pen used to draw points for series. | |
53 | \sa setPen() |
|
53 | \sa setPen() | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \fn QBrush QXYSeries::brush() const |
|
57 | \fn QBrush QXYSeries::brush() const | |
58 | \brief Returns brush used to draw points for series. |
|
58 | \brief Returns brush used to draw points for series. | |
59 | \sa setBrush() |
|
59 | \sa setBrush() | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QXYSeries::color |
|
63 | \property QXYSeries::color | |
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
64 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and | |
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
65 | fill (brush) color in case of QScatterSeries or QAreaSeries. | |
66 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
66 | \sa QXYSeries::pen(), QXYSeries::brush() | |
67 | */ |
|
67 | */ | |
68 | /*! |
|
68 | /*! | |
69 | \qmlproperty color XYSeries::color |
|
69 | \qmlproperty color XYSeries::color | |
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
70 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and | |
71 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
71 | fill (brush) color in case of ScatterSeries or AreaSeries. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \fn void QXYSeries::clicked(const QPointF& point) |
|
75 | \fn void QXYSeries::clicked(const QPointF& point) | |
76 | \brief Signal is emitted when user clicks the \a point on chart. |
|
76 | \brief Signal is emitted when user clicks the \a point on chart. | |
77 | */ |
|
77 | */ | |
78 | /*! |
|
78 | /*! | |
79 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
79 | \qmlsignal XYSeries::onClicked(QPointF point) | |
80 | Signal is emitted when user clicks the \a point on chart. For example: |
|
80 | Signal is emitted when user clicks the \a point on chart. For example: | |
81 | \code |
|
81 | \code | |
82 | LineSeries { |
|
82 | LineSeries { | |
83 | XYPoint { x: 0; y: 0 } |
|
83 | XYPoint { x: 0; y: 0 } | |
84 | XYPoint { x: 1.1; y: 2.1 } |
|
84 | XYPoint { x: 1.1; y: 2.1 } | |
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
85 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); | |
86 | } |
|
86 | } | |
87 | \endcode |
|
87 | \endcode | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \fn void QXYSeries::pointReplaced(int index) |
|
91 | \fn void QXYSeries::pointReplaced(int index) | |
92 | Signal is emitted when a point has been replaced at \a index. |
|
92 | Signal is emitted when a point has been replaced at \a index. | |
93 | \sa replace() |
|
93 | \sa replace() | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
96 | \qmlsignal XYSeries::onPointReplaced(int index) | |
97 | Signal is emitted when a point has been replaced at \a index. |
|
97 | Signal is emitted when a point has been replaced at \a index. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \fn void QXYSeries::pointAdded(int index) |
|
101 | \fn void QXYSeries::pointAdded(int index) | |
102 | Signal is emitted when a point has been added at \a index. |
|
102 | Signal is emitted when a point has been added at \a index. | |
103 | \sa append(), insert() |
|
103 | \sa append(), insert() | |
104 | */ |
|
104 | */ | |
105 | /*! |
|
105 | /*! | |
106 | \qmlsignal XYSeries::onPointAdded(int index) |
|
106 | \qmlsignal XYSeries::onPointAdded(int index) | |
107 | Signal is emitted when a point has been added at \a index. |
|
107 | Signal is emitted when a point has been added at \a index. | |
108 | */ |
|
108 | */ | |
109 |
|
109 | |||
110 | /*! |
|
110 | /*! | |
111 | \fn void QXYSeries::pointRemoved(int index) |
|
111 | \fn void QXYSeries::pointRemoved(int index) | |
112 | Signal is emitted when a point has been removed from \a index. |
|
112 | Signal is emitted when a point has been removed from \a index. | |
113 | \sa remove() |
|
113 | \sa remove() | |
114 | */ |
|
114 | */ | |
115 | /*! |
|
115 | /*! | |
116 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
116 | \qmlsignal XYSeries::onPointRemoved(int index) | |
117 | Signal is emitted when a point has been removed from \a index. |
|
117 | Signal is emitted when a point has been removed from \a index. | |
118 | */ |
|
118 | */ | |
119 |
|
119 | |||
120 | /*! |
|
120 | /*! | |
121 | \fn void QXYSeries::colorChanged(QColor color) |
|
121 | \fn void QXYSeries::colorChanged(QColor color) | |
122 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
122 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
123 | */ |
|
123 | */ | |
124 | /*! |
|
124 | /*! | |
125 | \qmlsignal XYSeries::onColorChanged(color color) |
|
125 | \qmlsignal XYSeries::onColorChanged(color color) | |
126 | Signal is emitted when the line (pen) color has changed to \a color. |
|
126 | Signal is emitted when the line (pen) color has changed to \a color. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QXYSeriesPrivate::updated() |
|
130 | \fn void QXYSeriesPrivate::updated() | |
131 | \brief \internal |
|
131 | \brief \internal | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \qmlmethod XYSeries::append(real x, real y) |
|
135 | \qmlmethod XYSeries::append(real x, real y) | |
136 | Append point (\a x, \a y) to the series |
|
136 | Append point (\a x, \a y) to the series | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
140 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
141 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
141 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
142 | exist. |
|
142 | exist. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \qmlmethod XYSeries::remove(real x, real y) |
|
146 | \qmlmethod XYSeries::remove(real x, real y) | |
147 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
147 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
151 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
152 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
152 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of | |
153 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
153 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
154 | */ |
|
154 | */ | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | \qmlmethod QPointF XYSeries::at(int index) |
|
157 | \qmlmethod QPointF XYSeries::at(int index) | |
158 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
158 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \internal |
|
162 | \internal | |
163 |
|
163 | |||
164 | Constructs empty series object which is a child of \a parent. |
|
164 | Constructs empty series object which is a child of \a parent. | |
165 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
165 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
166 | */ |
|
166 | */ | |
167 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) |
|
167 | QXYSeries::QXYSeries(QXYSeriesPrivate &d,QObject *parent) : QAbstractSeries(d, parent) | |
168 | { |
|
168 | { | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | Destroys the object. Series added to QChartView or QChart instances are owned by those, |
|
172 | Destroys the object. Series added to QChartView or QChart instances are owned by those, | |
173 | and are deleted when mentioned object are destroyed. |
|
173 | and are deleted when mentioned object are destroyed. | |
174 | */ |
|
174 | */ | |
175 | QXYSeries::~QXYSeries() |
|
175 | QXYSeries::~QXYSeries() | |
176 | { |
|
176 | { | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. |
|
180 | Adds data point \a x \a y to the series. Points are connected with lines on the chart. | |
181 | */ |
|
181 | */ | |
182 | void QXYSeries::append(qreal x,qreal y) |
|
182 | void QXYSeries::append(qreal x,qreal y) | |
183 | { |
|
183 | { | |
184 | append(QPointF(x,y)); |
|
184 | append(QPointF(x,y)); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | This is an overloaded function. |
|
188 | This is an overloaded function. | |
189 | Adds data \a point to the series. Points are connected with lines on the chart. |
|
189 | Adds data \a point to the series. Points are connected with lines on the chart. | |
190 | */ |
|
190 | */ | |
191 | void QXYSeries::append(const QPointF &point) |
|
191 | void QXYSeries::append(const QPointF &point) | |
192 | { |
|
192 | { | |
193 | Q_D(QXYSeries); |
|
193 | Q_D(QXYSeries); | |
194 | d->m_points<<point; |
|
194 | d->m_points<<point; | |
195 | // emit d->pointAdded(d->m_points.count()-1); |
|
195 | // emit d->pointAdded(d->m_points.count()-1); | |
196 | emit pointAdded(d->m_points.count()-1); |
|
196 | emit pointAdded(d->m_points.count()-1); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | /*! |
|
199 | /*! | |
200 | This is an overloaded function. |
|
200 | This is an overloaded function. | |
201 | Adds list of data \a points to the series. Points are connected with lines on the chart. |
|
201 | Adds list of data \a points to the series. Points are connected with lines on the chart. | |
202 | */ |
|
202 | */ | |
203 | void QXYSeries::append(const QList<QPointF> &points) |
|
203 | void QXYSeries::append(const QList<QPointF> &points) | |
204 | { |
|
204 | { | |
205 | foreach(const QPointF& point , points) { |
|
205 | foreach(const QPointF& point , points) { | |
206 | append(point); |
|
206 | append(point); | |
207 | } |
|
207 | } | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | /*! |
|
210 | /*! | |
211 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
211 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. | |
212 | */ |
|
212 | */ | |
213 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) |
|
213 | void QXYSeries::replace(qreal oldX,qreal oldY,qreal newX,qreal newY) | |
214 | { |
|
214 | { | |
215 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); |
|
215 | replace(QPointF(oldX,oldY),QPointF(newX,newY)); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | /*! |
|
218 | /*! | |
219 | Replaces \a oldPoint with \a newPoint. |
|
219 | Replaces \a oldPoint with \a newPoint. | |
220 | */ |
|
220 | */ | |
221 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) |
|
221 | void QXYSeries::replace(const QPointF &oldPoint,const QPointF &newPoint) | |
222 | { |
|
222 | { | |
223 | Q_D(QXYSeries); |
|
223 | Q_D(QXYSeries); | |
224 | int index = d->m_points.indexOf(oldPoint); |
|
224 | int index = d->m_points.indexOf(oldPoint); | |
225 | if(index==-1) return; |
|
225 | if(index==-1) return; | |
226 | d->m_points[index] = newPoint; |
|
226 | d->m_points[index] = newPoint; | |
227 | // emit d->pointReplaced(index); |
|
227 | // emit d->pointReplaced(index); | |
228 | emit pointReplaced(index); |
|
228 | emit pointReplaced(index); | |
229 | } |
|
229 | } | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | Removes current \a x and \a y value. |
|
232 | Removes current \a x and \a y value. | |
233 | */ |
|
233 | */ | |
234 | void QXYSeries::remove(qreal x,qreal y) |
|
234 | void QXYSeries::remove(qreal x,qreal y) | |
235 | { |
|
235 | { | |
236 | remove(QPointF(x,y)); |
|
236 | remove(QPointF(x,y)); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | Removes current \a point x value. |
|
240 | Removes current \a point x value. | |
241 |
|
241 | |||
242 | Note: point y value is ignored. |
|
242 | Note: point y value is ignored. | |
243 | */ |
|
243 | */ | |
244 | void QXYSeries::remove(const QPointF &point) |
|
244 | void QXYSeries::remove(const QPointF &point) | |
245 | { |
|
245 | { | |
246 | Q_D(QXYSeries); |
|
246 | Q_D(QXYSeries); | |
247 | int index = d->m_points.indexOf(point); |
|
247 | int index = d->m_points.indexOf(point); | |
248 | if(index==-1) return; |
|
248 | if(index==-1) return; | |
249 | d->m_points.remove(index); |
|
249 | d->m_points.remove(index); | |
250 | // emit d->pointRemoved(index); |
|
250 | // emit d->pointRemoved(index); | |
251 | emit pointRemoved(index); |
|
251 | emit pointRemoved(index); | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | /*! |
|
254 | /*! | |
255 | Inserts a \a point in the series at \a index position. |
|
255 | Inserts a \a point in the series at \a index position. | |
256 | */ |
|
256 | */ | |
257 | void QXYSeries::insert(int index, const QPointF &point) |
|
257 | void QXYSeries::insert(int index, const QPointF &point) | |
258 | { |
|
258 | { | |
259 | Q_D(QXYSeries); |
|
259 | Q_D(QXYSeries); | |
260 | d->m_points.insert(index, point); |
|
260 | d->m_points.insert(index, point); | |
261 | // emit d->pointAdded(index); |
|
261 | // emit d->pointAdded(index); | |
262 | emit pointAdded(index); |
|
262 | emit pointAdded(index); | |
263 | } |
|
263 | } | |
264 |
|
264 | |||
265 | /*! |
|
265 | /*! | |
266 | Removes all points from the series. |
|
266 | Removes all points from the series. | |
267 | */ |
|
267 | */ | |
268 | void QXYSeries::clear() |
|
268 | void QXYSeries::clear() | |
269 | { |
|
269 | { | |
270 | Q_D(QXYSeries); |
|
270 | Q_D(QXYSeries); | |
271 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
271 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
272 | remove(d->m_points.at(i)); |
|
272 | remove(d->m_points.at(i)); | |
273 | } |
|
273 | } | |
274 |
|
274 | |||
275 | /*! |
|
275 | /*! | |
276 | \internal \a pos |
|
276 | \internal \a pos | |
277 | */ |
|
277 | */ | |
278 | QList<QPointF> QXYSeries::points() const |
|
278 | QList<QPointF> QXYSeries::points() const | |
279 | { |
|
279 | { | |
280 | Q_D(const QXYSeries); |
|
280 | Q_D(const QXYSeries); | |
281 | return d->m_points.toList(); |
|
281 | return d->m_points.toList(); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | Returns number of data points within series. |
|
285 | Returns number of data points within series. | |
286 | */ |
|
286 | */ | |
287 | int QXYSeries::count() const |
|
287 | int QXYSeries::count() const | |
288 | { |
|
288 | { | |
289 | Q_D(const QXYSeries); |
|
289 | Q_D(const QXYSeries); | |
290 | return d->m_points.count(); |
|
290 | return d->m_points.count(); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 |
|
293 | |||
294 | /*! |
|
294 | /*! | |
295 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
295 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
296 | pen from chart theme is used. |
|
296 | pen from chart theme is used. | |
297 | \sa QChart::setTheme() |
|
297 | \sa QChart::setTheme() | |
298 | */ |
|
298 | */ | |
299 | void QXYSeries::setPen(const QPen &pen) |
|
299 | void QXYSeries::setPen(const QPen &pen) | |
300 | { |
|
300 | { | |
301 | Q_D(QXYSeries); |
|
301 | Q_D(QXYSeries); | |
302 | if (d->m_pen != pen) { |
|
302 | if (d->m_pen != pen) { | |
303 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
303 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
304 | d->m_pen = pen; |
|
304 | d->m_pen = pen; | |
305 | emit d->updated(); |
|
305 | emit d->updated(); | |
306 | if (emitColorChanged) |
|
306 | if (emitColorChanged) | |
307 | emit colorChanged(pen.color()); |
|
307 | emit colorChanged(pen.color()); | |
308 | } |
|
308 | } | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | QPen QXYSeries::pen() const |
|
311 | QPen QXYSeries::pen() const | |
312 | { |
|
312 | { | |
313 | Q_D(const QXYSeries); |
|
313 | Q_D(const QXYSeries); | |
314 | return d->m_pen; |
|
314 | return d->m_pen; | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | /*! |
|
317 | /*! | |
318 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
318 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
319 | from chart theme setting is used. |
|
319 | from chart theme setting is used. | |
320 | \sa QChart::setTheme() |
|
320 | \sa QChart::setTheme() | |
321 | */ |
|
321 | */ | |
322 | void QXYSeries::setBrush(const QBrush &brush) |
|
322 | void QXYSeries::setBrush(const QBrush &brush) | |
323 | { |
|
323 | { | |
324 | Q_D(QXYSeries); |
|
324 | Q_D(QXYSeries); | |
325 | if (d->m_brush!=brush) { |
|
325 | if (d->m_brush!=brush) { | |
326 | d->m_brush = brush; |
|
326 | d->m_brush = brush; | |
327 | emit d->updated(); |
|
327 | emit d->updated(); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | QBrush QXYSeries::brush() const |
|
331 | QBrush QXYSeries::brush() const | |
332 | { |
|
332 | { | |
333 | Q_D(const QXYSeries); |
|
333 | Q_D(const QXYSeries); | |
334 | return d->m_brush; |
|
334 | return d->m_brush; | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void QXYSeries::setColor(const QColor &color) |
|
337 | void QXYSeries::setColor(const QColor &color) | |
338 | { |
|
338 | { | |
339 | QPen p = pen(); |
|
339 | QPen p = pen(); | |
340 | if (p.color() != color) { |
|
340 | if (p.color() != color) { | |
341 | p.setColor(color); |
|
341 | p.setColor(color); | |
342 | setPen(p); |
|
342 | setPen(p); | |
343 | } |
|
343 | } | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | QColor QXYSeries::color() const |
|
346 | QColor QXYSeries::color() const | |
347 | { |
|
347 | { | |
348 | return pen().color(); |
|
348 | return pen().color(); | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 | void QXYSeries::setPointsVisible(bool visible) |
|
351 | void QXYSeries::setPointsVisible(bool visible) | |
352 | { |
|
352 | { | |
353 | Q_D(QXYSeries); |
|
353 | Q_D(QXYSeries); | |
354 | if (d->m_pointsVisible != visible){ |
|
354 | if (d->m_pointsVisible != visible){ | |
355 | d->m_pointsVisible = visible; |
|
355 | d->m_pointsVisible = visible; | |
356 | emit d->updated(); |
|
356 | emit d->updated(); | |
357 | } |
|
357 | } | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | bool QXYSeries::pointsVisible() const |
|
360 | bool QXYSeries::pointsVisible() const | |
361 | { |
|
361 | { | |
362 | Q_D(const QXYSeries); |
|
362 | Q_D(const QXYSeries); | |
363 | return d->m_pointsVisible; |
|
363 | return d->m_pointsVisible; | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 |
|
366 | |||
367 | /*! |
|
367 | /*! | |
368 | Stream operator for adding a data \a point to the series. |
|
368 | Stream operator for adding a data \a point to the series. | |
369 | \sa append() |
|
369 | \sa append() | |
370 | */ |
|
370 | */ | |
371 | QXYSeries& QXYSeries::operator<< (const QPointF &point) |
|
371 | QXYSeries& QXYSeries::operator<< (const QPointF &point) | |
372 | { |
|
372 | { | |
373 | append(point); |
|
373 | append(point); | |
374 | return *this; |
|
374 | return *this; | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 |
|
377 | |||
378 | /*! |
|
378 | /*! | |
379 | Stream operator for adding a list of \a points to the series. |
|
379 | Stream operator for adding a list of \a points to the series. | |
380 | \sa append() |
|
380 | \sa append() | |
381 | */ |
|
381 | */ | |
382 |
|
382 | |||
383 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) |
|
383 | QXYSeries& QXYSeries::operator<< (const QList<QPointF>& points) | |
384 | { |
|
384 | { | |
385 | append(points); |
|
385 | append(points); | |
386 | return *this; |
|
386 | return *this; | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
389 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
390 |
|
390 | |||
391 |
|
391 | |||
392 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : |
|
392 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) : | |
393 | QAbstractSeriesPrivate(q), |
|
393 | QAbstractSeriesPrivate(q), | |
394 | m_pointsVisible(false) |
|
394 | m_pointsVisible(false) | |
395 | { |
|
395 | { | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | void QXYSeriesPrivate::scaleDomain(Domain& domain) |
|
398 | void QXYSeriesPrivate::scaleDomain(Domain& domain) | |
399 | { |
|
399 | { | |
400 | qreal minX(domain.minX()); |
|
400 | qreal minX(domain.minX()); | |
401 | qreal minY(domain.minY()); |
|
401 | qreal minY(domain.minY()); | |
402 | qreal maxX(domain.maxX()); |
|
402 | qreal maxX(domain.maxX()); | |
403 | qreal maxY(domain.maxY()); |
|
403 | qreal maxY(domain.maxY()); | |
404 | int tickXCount(domain.tickXCount()); |
|
404 | int tickXCount(domain.tickXCount()); | |
405 | int tickYCount(domain.tickYCount()); |
|
405 | int tickYCount(domain.tickYCount()); | |
406 |
|
406 | |||
407 | Q_Q(QXYSeries); |
|
407 | Q_Q(QXYSeries); | |
408 |
|
408 | |||
409 | const QList<QPointF>& points = q->points(); |
|
409 | const QList<QPointF>& points = q->points(); | |
410 |
|
410 | |||
411 |
|
411 | |||
412 | if (points.isEmpty()){ |
|
412 | if (points.isEmpty()){ | |
413 | minX = qMin(minX, 0.0); |
|
413 | minX = qMin(minX, 0.0); | |
414 | minY = qMin(minY, 0.0); |
|
414 | minY = qMin(minY, 0.0); | |
415 | maxX = qMax(maxX, 1.0); |
|
415 | maxX = qMax(maxX, 1.0); | |
416 | maxY = qMax(maxY, 1.0); |
|
416 | maxY = qMax(maxY, 1.0); | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | for (int i = 0; i < points.count(); i++) { |
|
419 | for (int i = 0; i < points.count(); i++) { | |
420 | qreal x = points[i].x(); |
|
420 | qreal x = points[i].x(); | |
421 | qreal y = points[i].y(); |
|
421 | qreal y = points[i].y(); | |
422 | minX = qMin(minX, x); |
|
422 | minX = qMin(minX, x); | |
423 | minY = qMin(minY, y); |
|
423 | minY = qMin(minY, y); | |
424 | maxX = qMax(maxX, x); |
|
424 | maxX = qMax(maxX, x); | |
425 | maxY = qMax(maxY, y); |
|
425 | maxY = qMax(maxY, y); | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
428 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) |
|
431 | QList<LegendMarker*> QXYSeriesPrivate::createLegendMarker(QLegend* legend) | |
432 | { |
|
432 | { | |
433 | Q_Q(QXYSeries); |
|
433 | Q_Q(QXYSeries); | |
434 | QList<LegendMarker*> list; |
|
434 | QList<LegendMarker*> list; | |
435 | return list << new XYLegendMarker(q,legend); |
|
435 | return list << new XYLegendMarker(q,legend); | |
436 | } |
|
436 | } | |
437 |
|
437 | |||
438 |
|
|
438 | void QXYSeriesPrivate::initializeAxisX(QAbstractAxis* axis) | |
439 | { |
|
439 | { | |
440 | return new QValuesAxis(parent); |
|
440 | Q_UNUSED(axis); | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 |
|
|
443 | void QXYSeriesPrivate::initializeAxisY(QAbstractAxis* axis) | |
444 | { |
|
444 | { | |
445 | return new QValuesAxis(parent); |
|
445 | Q_UNUSED(axis); | |
|
446 | } | |||
|
447 | ||||
|
448 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisXType() const | |||
|
449 | { | |||
|
450 | return QAbstractAxis::AxisTypeValues; | |||
|
451 | } | |||
|
452 | ||||
|
453 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisYType() const | |||
|
454 | { | |||
|
455 | return QAbstractAxis::AxisTypeValues; | |||
446 | } |
|
456 | } | |
447 |
|
457 | |||
448 | #include "moc_qxyseries.cpp" |
|
458 | #include "moc_qxyseries.cpp" | |
449 | #include "moc_qxyseries_p.cpp" |
|
459 | #include "moc_qxyseries_p.cpp" | |
450 |
|
460 | |||
451 | QTCOMMERCIALCHART_END_NAMESPACE |
|
461 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,72 +1,74 | |||||
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 QXYSERIES_P_H |
|
30 | #ifndef QXYSERIES_P_H | |
31 | #define QXYSERIES_P_H |
|
31 | #define QXYSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries_p.h" |
|
33 | #include "qabstractseries_p.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class QXYSeries; |
|
37 | class QXYSeries; | |
38 | class QAbstractAxis; |
|
38 | class QAbstractAxis; | |
39 |
|
39 | |||
40 | class QXYSeriesPrivate: public QAbstractSeriesPrivate |
|
40 | class QXYSeriesPrivate: public QAbstractSeriesPrivate | |
41 | { |
|
41 | { | |
42 | Q_OBJECT |
|
42 | Q_OBJECT | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | QXYSeriesPrivate(QXYSeries* q); |
|
45 | QXYSeriesPrivate(QXYSeries* q); | |
46 |
|
46 | |||
47 | void scaleDomain(Domain& domain); |
|
47 | void scaleDomain(Domain& domain); | |
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); |
|
48 | QList<LegendMarker*> createLegendMarker(QLegend* legend); | |
49 |
|
49 | |||
50 | QAbstractAxis* createAxisX(QObject* parent); |
|
50 | void initializeAxisX(QAbstractAxis* axis); | |
51 | QAbstractAxis* createAxisY(QObject* parent); |
|
51 | void initializeAxisY(QAbstractAxis* axis); | |
|
52 | QAbstractAxis::AxisType defaultAxisXType() const; | |||
|
53 | QAbstractAxis::AxisType defaultAxisYType() const; | |||
52 |
|
54 | |||
53 | Q_SIGNALS: |
|
55 | Q_SIGNALS: | |
54 | void updated(); |
|
56 | void updated(); | |
55 | // void pointReplaced(int index); |
|
57 | // void pointReplaced(int index); | |
56 | // void pointRemoved(int index); |
|
58 | // void pointRemoved(int index); | |
57 | // void pointAdded(int index); |
|
59 | // void pointAdded(int index); | |
58 |
|
60 | |||
59 | protected: |
|
61 | protected: | |
60 | QVector<QPointF> m_points; |
|
62 | QVector<QPointF> m_points; | |
61 | QPen m_pen; |
|
63 | QPen m_pen; | |
62 | QBrush m_brush; |
|
64 | QBrush m_brush; | |
63 | bool m_pointsVisible; |
|
65 | bool m_pointsVisible; | |
64 |
|
66 | |||
65 | private: |
|
67 | private: | |
66 | Q_DECLARE_PUBLIC(QXYSeries) |
|
68 | Q_DECLARE_PUBLIC(QXYSeries) | |
67 | friend class QScatterSeries; |
|
69 | friend class QScatterSeries; | |
68 | }; |
|
70 | }; | |
69 |
|
71 | |||
70 | QTCOMMERCIALCHART_END_NAMESPACE |
|
72 | QTCOMMERCIALCHART_END_NAMESPACE | |
71 |
|
73 | |||
72 | #endif |
|
74 | #endif |
@@ -1,634 +1,636 | |||||
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 <qgroupedbarseries.h> |
|
30 | #include <qgroupedbarseries.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 QGroupedBarSeries(this); |
|
139 | QAbstractSeries* bar = new QGroupedBarSeries(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 QGroupedBarSeries(this); |
|
188 | QAbstractSeries* bar = new QGroupedBarSeries(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 | ||||
|
545 | ||||
544 | QList<QSignalSpy*> spyList; |
|
546 | QList<QSignalSpy*> spyList; | |
545 |
|
547 | |||
546 | foreach(QAbstractSeries* series, seriesList) { |
|
548 | foreach(QAbstractSeries* series, seriesList) { | |
547 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
549 | spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
548 | } |
|
550 | } | |
549 |
|
551 | |||
550 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); |
|
552 | m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000)); | |
551 |
|
553 | |||
552 | foreach(QSignalSpy* spy, spyList) { |
|
554 | foreach(QSignalSpy* spy, spyList) { | |
553 | TRY_COMPARE(spy->count(), 1); |
|
555 | TRY_COMPARE(spy->count(), 1); | |
554 | } |
|
556 | } | |
555 |
|
557 | |||
556 | qDeleteAll(spyList); |
|
558 | qDeleteAll(spyList); | |
557 | } |
|
559 | } | |
558 |
|
560 | |||
559 | /* |
|
561 | /* | |
560 | void tst_ChartDataSet::zoomOutDomain_data() |
|
562 | void tst_ChartDataSet::zoomOutDomain_data() | |
561 | { |
|
563 | { | |
562 | addSeries_data(); |
|
564 | addSeries_data(); | |
563 | } |
|
565 | } | |
564 |
|
566 | |||
565 | void tst_ChartDataSet::zoomOutDomain() |
|
567 | void tst_ChartDataSet::zoomOutDomain() | |
566 | { |
|
568 | { | |
567 | QFETCH(QLineSeries*, series0); |
|
569 | QFETCH(QLineSeries*, series0); | |
568 | QFETCH(QAxis*, axis0); |
|
570 | QFETCH(QAxis*, axis0); | |
569 | QFETCH(QLineSeries*, series1); |
|
571 | QFETCH(QLineSeries*, series1); | |
570 | QFETCH(QAxis*, axis1); |
|
572 | QFETCH(QAxis*, axis1); | |
571 | QFETCH(QLineSeries*, series2); |
|
573 | QFETCH(QLineSeries*, series2); | |
572 | QFETCH(QAxis*, axis2); |
|
574 | QFETCH(QAxis*, axis2); | |
573 | QFETCH(int, axisCount); |
|
575 | QFETCH(int, axisCount); | |
574 |
|
576 | |||
575 | Q_UNUSED(axisCount); |
|
577 | Q_UNUSED(axisCount); | |
576 |
|
578 | |||
577 | m_dataset->addSeries(series0, axis0); |
|
579 | m_dataset->addSeries(series0, axis0); | |
578 | m_dataset->addSeries(series1, axis1); |
|
580 | m_dataset->addSeries(series1, axis1); | |
579 | m_dataset->addSeries(series2, axis2); |
|
581 | m_dataset->addSeries(series2, axis2); | |
580 |
|
582 | |||
581 | Domain* domain0 = m_dataset->domain(series0); |
|
583 | Domain* domain0 = m_dataset->domain(series0); | |
582 | Domain* domain1 = m_dataset->domain(series1); |
|
584 | Domain* domain1 = m_dataset->domain(series1); | |
583 | Domain* domain2 = m_dataset->domain(series2); |
|
585 | Domain* domain2 = m_dataset->domain(series2); | |
584 |
|
586 | |||
585 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
587 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
586 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
588 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
587 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
589 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
588 |
|
590 | |||
589 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
591 | m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); | |
590 |
|
592 | |||
591 | TRY_COMPARE(spy0.count(), 1); |
|
593 | TRY_COMPARE(spy0.count(), 1); | |
592 | TRY_COMPARE(spy1.count(), 1); |
|
594 | TRY_COMPARE(spy1.count(), 1); | |
593 | TRY_COMPARE(spy2.count(), 1); |
|
595 | TRY_COMPARE(spy2.count(), 1); | |
594 | } |
|
596 | } | |
595 |
|
597 | |||
596 | void tst_ChartDataSet::scrollDomain_data() |
|
598 | void tst_ChartDataSet::scrollDomain_data() | |
597 | { |
|
599 | { | |
598 | addSeries_data(); |
|
600 | addSeries_data(); | |
599 | } |
|
601 | } | |
600 |
|
602 | |||
601 | void tst_ChartDataSet::scrollDomain() |
|
603 | void tst_ChartDataSet::scrollDomain() | |
602 | { |
|
604 | { | |
603 | QFETCH(QLineSeries*, series0); |
|
605 | QFETCH(QLineSeries*, series0); | |
604 | QFETCH(QAxis*, axis0); |
|
606 | QFETCH(QAxis*, axis0); | |
605 | QFETCH(QLineSeries*, series1); |
|
607 | QFETCH(QLineSeries*, series1); | |
606 | QFETCH(QAxis*, axis1); |
|
608 | QFETCH(QAxis*, axis1); | |
607 | QFETCH(QLineSeries*, series2); |
|
609 | QFETCH(QLineSeries*, series2); | |
608 | QFETCH(QAxis*, axis2); |
|
610 | QFETCH(QAxis*, axis2); | |
609 | QFETCH(int, axisCount); |
|
611 | QFETCH(int, axisCount); | |
610 |
|
612 | |||
611 | Q_UNUSED(axisCount); |
|
613 | Q_UNUSED(axisCount); | |
612 |
|
614 | |||
613 | m_dataset->addSeries(series0, axis0); |
|
615 | m_dataset->addSeries(series0, axis0); | |
614 | m_dataset->addSeries(series1, axis1); |
|
616 | m_dataset->addSeries(series1, axis1); | |
615 | m_dataset->addSeries(series2, axis2); |
|
617 | m_dataset->addSeries(series2, axis2); | |
616 |
|
618 | |||
617 | Domain* domain0 = m_dataset->domain(series0); |
|
619 | Domain* domain0 = m_dataset->domain(series0); | |
618 | Domain* domain1 = m_dataset->domain(series1); |
|
620 | Domain* domain1 = m_dataset->domain(series1); | |
619 | Domain* domain2 = m_dataset->domain(series2); |
|
621 | Domain* domain2 = m_dataset->domain(series2); | |
620 |
|
622 | |||
621 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
623 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
622 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
624 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
623 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
625 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); | |
624 |
|
626 | |||
625 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); |
|
627 | m_dataset->scrollDomain(10,10,QSize(1000,1000)); | |
626 |
|
628 | |||
627 | TRY_COMPARE(spy0.count(), 1); |
|
629 | TRY_COMPARE(spy0.count(), 1); | |
628 | TRY_COMPARE(spy1.count(), 1); |
|
630 | TRY_COMPARE(spy1.count(), 1); | |
629 | TRY_COMPARE(spy2.count(), 1); |
|
631 | TRY_COMPARE(spy2.count(), 1); | |
630 | } |
|
632 | } | |
631 | */ |
|
633 | */ | |
632 | QTEST_MAIN(tst_ChartDataSet) |
|
634 | QTEST_MAIN(tst_ChartDataSet) | |
633 | #include "tst_chartdataset.moc" |
|
635 | #include "tst_chartdataset.moc" | |
634 |
|
636 |
General Comments 0
You need to be logged in to leave comments.
Login now