@@ -1,632 +1,625 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "chartpresenter_p.h" |
|
22 | #include "chartpresenter_p.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qchart_p.h" |
|
24 | #include "qchart_p.h" | |
25 | #include "qvalueaxis.h" |
|
25 | #include "qvalueaxis.h" | |
26 | #include "qbarcategoryaxis.h" |
|
26 | #include "qbarcategoryaxis.h" | |
27 | #include "qvalueaxis_p.h" |
|
27 | #include "qvalueaxis_p.h" | |
28 | #include "qcategoryaxis.h" |
|
28 | #include "qcategoryaxis.h" | |
29 | #include "qabstractseries_p.h" |
|
29 | #include "qabstractseries_p.h" | |
30 | #include "qabstractbarseries.h" |
|
30 | #include "qabstractbarseries.h" | |
31 | #include "qstackedbarseries.h" |
|
31 | #include "qstackedbarseries.h" | |
32 | #include "qpercentbarseries.h" |
|
32 | #include "qpercentbarseries.h" | |
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "xydomain_p.h" |
|
35 | #include "xydomain_p.h" | |
36 | #include "xypolardomain_p.h" |
|
36 | #include "xypolardomain_p.h" | |
37 | #include "xlogydomain_p.h" |
|
37 | #include "xlogydomain_p.h" | |
38 | #include "logxydomain_p.h" |
|
38 | #include "logxydomain_p.h" | |
39 | #include "logxlogydomain_p.h" |
|
39 | #include "logxlogydomain_p.h" | |
40 | #include "xlogypolardomain_p.h" |
|
40 | #include "xlogypolardomain_p.h" | |
41 | #include "logxypolardomain_p.h" |
|
41 | #include "logxypolardomain_p.h" | |
42 | #include "logxlogypolardomain_p.h" |
|
42 | #include "logxlogypolardomain_p.h" | |
43 |
|
43 | |||
44 | #ifndef QT_ON_ARM |
|
44 | #ifndef QT_ON_ARM | |
45 | #include "qdatetimeaxis.h" |
|
45 | #include "qdatetimeaxis.h" | |
46 | #endif |
|
46 | #endif | |
47 |
|
47 | |||
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
49 |
|
49 | |||
50 | ChartDataSet::ChartDataSet(QChart *chart) |
|
50 | ChartDataSet::ChartDataSet(QChart *chart) | |
51 | : QObject(chart), |
|
51 | : QObject(chart), | |
52 | m_chart(chart) |
|
52 | m_chart(chart) | |
53 | { |
|
53 | { | |
54 |
|
54 | |||
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | ChartDataSet::~ChartDataSet() |
|
57 | ChartDataSet::~ChartDataSet() | |
58 | { |
|
58 | { | |
59 | deleteAllSeries(); |
|
59 | deleteAllSeries(); | |
60 | deleteAllAxes(); |
|
60 | deleteAllAxes(); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /* |
|
63 | /* | |
64 | * This method adds series to chartdataset, series ownership is taken from caller. |
|
64 | * This method adds series to chartdataset, series ownership is taken from caller. | |
65 | */ |
|
65 | */ | |
66 | void ChartDataSet::addSeries(QAbstractSeries *series) |
|
66 | void ChartDataSet::addSeries(QAbstractSeries *series) | |
67 | { |
|
67 | { | |
68 | if (m_seriesList.contains(series)) { |
|
68 | if (m_seriesList.contains(series)) { | |
69 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); |
|
69 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); | |
70 | return; |
|
70 | return; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | // Ignore unsupported series added to polar chart |
|
73 | // Ignore unsupported series added to polar chart | |
74 | if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) { |
|
74 | if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) { | |
75 | if (!(series->type() == QAbstractSeries::SeriesTypeArea |
|
75 | if (!(series->type() == QAbstractSeries::SeriesTypeArea | |
76 | || series->type() == QAbstractSeries::SeriesTypeLine |
|
76 | || series->type() == QAbstractSeries::SeriesTypeLine | |
77 | || series->type() == QAbstractSeries::SeriesTypeScatter |
|
77 | || series->type() == QAbstractSeries::SeriesTypeScatter | |
78 | || series->type() == QAbstractSeries::SeriesTypeSpline)) { |
|
78 | || series->type() == QAbstractSeries::SeriesTypeSpline)) { | |
79 | qWarning() << QObject::tr("Can not add series. Series type is not supported by a polar chart."); |
|
79 | qWarning() << QObject::tr("Can not add series. Series type is not supported by a polar chart."); | |
80 | return; |
|
80 | return; | |
81 | } |
|
81 | } | |
82 | series->d_ptr->setDomain(new XYPolarDomain()); |
|
82 | series->d_ptr->setDomain(new XYPolarDomain()); | |
83 | } else { |
|
83 | } else { | |
84 | series->d_ptr->setDomain(new XYDomain()); |
|
84 | series->d_ptr->setDomain(new XYDomain()); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | series->d_ptr->initializeDomain(); |
|
87 | series->d_ptr->initializeDomain(); | |
88 | m_seriesList.append(series); |
|
88 | m_seriesList.append(series); | |
89 |
|
89 | |||
90 | series->setParent(this); // take ownership |
|
90 | series->setParent(this); // take ownership | |
91 | series->d_ptr->m_chart = m_chart; |
|
91 | series->d_ptr->m_chart = m_chart; | |
92 |
|
92 | |||
93 | emit seriesAdded(series); |
|
93 | emit seriesAdded(series); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | /* |
|
96 | /* | |
97 | * This method adds axis to chartdataset, axis ownership is taken from caller. |
|
97 | * This method adds axis to chartdataset, axis ownership is taken from caller. | |
98 | */ |
|
98 | */ | |
99 | void ChartDataSet::addAxis(QAbstractAxis *axis, Qt::Alignment aligment) |
|
99 | void ChartDataSet::addAxis(QAbstractAxis *axis, Qt::Alignment aligment) | |
100 | { |
|
100 | { | |
101 | if (m_axisList.contains(axis)) { |
|
101 | if (m_axisList.contains(axis)) { | |
102 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); |
|
102 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); | |
103 | return; |
|
103 | return; | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | axis->d_ptr->setAlignment(aligment); |
|
106 | axis->d_ptr->setAlignment(aligment); | |
107 |
|
107 | |||
108 | if (!axis->alignment()) { |
|
108 | if (!axis->alignment()) { | |
109 | qWarning() << QObject::tr("No alignment specified !"); |
|
109 | qWarning() << QObject::tr("No alignment specified !"); | |
110 | return; |
|
110 | return; | |
111 | }; |
|
111 | }; | |
112 |
|
112 | |||
113 | AbstractDomain *newDomain; |
|
113 | AbstractDomain *newDomain; | |
114 |
if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) |
|
114 | if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) | |
115 | foreach (QAbstractAxis *existingAxis, axes()) { |
|
|||
116 | if (existingAxis->orientation() == axis->orientation()) { |
|
|||
117 | qWarning() << QObject::tr("Cannot add multiple axes of same orientation to a polar chart!"); |
|
|||
118 | return; |
|
|||
119 | } |
|
|||
120 | } |
|
|||
121 | newDomain = new XYPolarDomain(); |
|
115 | newDomain = new XYPolarDomain(); | |
122 |
|
|
116 | else | |
123 | newDomain = new XYDomain(); |
|
117 | newDomain = new XYDomain(); | |
124 | } |
|
|||
125 |
|
118 | |||
126 | QSharedPointer<AbstractDomain> domain(newDomain); |
|
119 | QSharedPointer<AbstractDomain> domain(newDomain); | |
127 | axis->d_ptr->initializeDomain(domain.data()); |
|
120 | axis->d_ptr->initializeDomain(domain.data()); | |
128 |
|
121 | |||
129 | axis->setParent(this); |
|
122 | axis->setParent(this); | |
130 | axis->d_ptr->m_chart = m_chart; |
|
123 | axis->d_ptr->m_chart = m_chart; | |
131 | m_axisList.append(axis); |
|
124 | m_axisList.append(axis); | |
132 |
|
125 | |||
133 | emit axisAdded(axis); |
|
126 | emit axisAdded(axis); | |
134 | } |
|
127 | } | |
135 |
|
128 | |||
136 | /* |
|
129 | /* | |
137 | * This method removes series form chartdataset, series ownership is passed back to caller. |
|
130 | * This method removes series form chartdataset, series ownership is passed back to caller. | |
138 | */ |
|
131 | */ | |
139 | void ChartDataSet::removeSeries(QAbstractSeries *series) |
|
132 | void ChartDataSet::removeSeries(QAbstractSeries *series) | |
140 | { |
|
133 | { | |
141 |
|
134 | |||
142 | if (! m_seriesList.contains(series)) { |
|
135 | if (! m_seriesList.contains(series)) { | |
143 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); |
|
136 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); | |
144 | return; |
|
137 | return; | |
145 | } |
|
138 | } | |
146 |
|
139 | |||
147 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; |
|
140 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; | |
148 |
|
141 | |||
149 | foreach(QAbstractAxis* axis, axes) { |
|
142 | foreach(QAbstractAxis* axis, axes) { | |
150 | detachAxis(series,axis); |
|
143 | detachAxis(series,axis); | |
151 | } |
|
144 | } | |
152 |
|
145 | |||
153 | emit seriesRemoved(series); |
|
146 | emit seriesRemoved(series); | |
154 | m_seriesList.removeAll(series); |
|
147 | m_seriesList.removeAll(series); | |
155 |
|
148 | |||
156 | // Reset domain to default |
|
149 | // Reset domain to default | |
157 | series->d_ptr->setDomain(new XYDomain()); |
|
150 | series->d_ptr->setDomain(new XYDomain()); | |
158 | series->setParent(0); |
|
151 | series->setParent(0); | |
159 | series->d_ptr->m_chart = 0; |
|
152 | series->d_ptr->m_chart = 0; | |
160 | } |
|
153 | } | |
161 |
|
154 | |||
162 | /* |
|
155 | /* | |
163 | * This method removes axis form chartdataset, series ownership is passed back to caller. |
|
156 | * This method removes axis form chartdataset, series ownership is passed back to caller. | |
164 | */ |
|
157 | */ | |
165 | void ChartDataSet::removeAxis(QAbstractAxis *axis) |
|
158 | void ChartDataSet::removeAxis(QAbstractAxis *axis) | |
166 | { |
|
159 | { | |
167 | if (! m_axisList.contains(axis)) { |
|
160 | if (! m_axisList.contains(axis)) { | |
168 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); |
|
161 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); | |
169 | return; |
|
162 | return; | |
170 | } |
|
163 | } | |
171 |
|
164 | |||
172 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; |
|
165 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; | |
173 |
|
166 | |||
174 | foreach(QAbstractSeries* s, series) { |
|
167 | foreach(QAbstractSeries* s, series) { | |
175 | detachAxis(s,axis); |
|
168 | detachAxis(s,axis); | |
176 | } |
|
169 | } | |
177 |
|
170 | |||
178 | emit axisRemoved(axis); |
|
171 | emit axisRemoved(axis); | |
179 | m_axisList.removeAll(axis); |
|
172 | m_axisList.removeAll(axis); | |
180 |
|
173 | |||
181 | axis->setParent(0); |
|
174 | axis->setParent(0); | |
182 | axis->d_ptr->m_chart = 0; |
|
175 | axis->d_ptr->m_chart = 0; | |
183 | } |
|
176 | } | |
184 |
|
177 | |||
185 | /* |
|
178 | /* | |
186 | * This method attaches axis to series, return true if success. |
|
179 | * This method attaches axis to series, return true if success. | |
187 | */ |
|
180 | */ | |
188 | bool ChartDataSet::attachAxis(QAbstractSeries *series,QAbstractAxis *axis) |
|
181 | bool ChartDataSet::attachAxis(QAbstractSeries *series,QAbstractAxis *axis) | |
189 | { |
|
182 | { | |
190 | Q_ASSERT(series); |
|
183 | Q_ASSERT(series); | |
191 | Q_ASSERT(axis); |
|
184 | Q_ASSERT(axis); | |
192 |
|
185 | |||
193 | QList<QAbstractSeries *> attachedSeriesList = axis->d_ptr->m_series; |
|
186 | QList<QAbstractSeries *> attachedSeriesList = axis->d_ptr->m_series; | |
194 | QList<QAbstractAxis *> attachedAxisList = series->d_ptr->m_axes; |
|
187 | QList<QAbstractAxis *> attachedAxisList = series->d_ptr->m_axes; | |
195 |
|
188 | |||
196 | if (!m_seriesList.contains(series)) { |
|
189 | if (!m_seriesList.contains(series)) { | |
197 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
190 | qWarning() << QObject::tr("Can not find series on the chart."); | |
198 | return false; |
|
191 | return false; | |
199 | } |
|
192 | } | |
200 |
|
193 | |||
201 | if (axis && !m_axisList.contains(axis)) { |
|
194 | if (axis && !m_axisList.contains(axis)) { | |
202 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
195 | qWarning() << QObject::tr("Can not find axis on the chart."); | |
203 | return false; |
|
196 | return false; | |
204 | } |
|
197 | } | |
205 |
|
198 | |||
206 | if (attachedAxisList.contains(axis)) { |
|
199 | if (attachedAxisList.contains(axis)) { | |
207 | qWarning() << QObject::tr("Axis already attached to series."); |
|
200 | qWarning() << QObject::tr("Axis already attached to series."); | |
208 | return false; |
|
201 | return false; | |
209 | } |
|
202 | } | |
210 |
|
203 | |||
211 | if (attachedSeriesList.contains(series)) { |
|
204 | if (attachedSeriesList.contains(series)) { | |
212 | qWarning() << QObject::tr("Axis already attached to series."); |
|
205 | qWarning() << QObject::tr("Axis already attached to series."); | |
213 | return false; |
|
206 | return false; | |
214 | } |
|
207 | } | |
215 |
|
208 | |||
216 | AbstractDomain *domain = series->d_ptr->domain(); |
|
209 | AbstractDomain *domain = series->d_ptr->domain(); | |
217 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); |
|
210 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); | |
218 |
|
211 | |||
219 | if (type == AbstractDomain::UndefinedDomain) return false; |
|
212 | if (type == AbstractDomain::UndefinedDomain) return false; | |
220 |
|
213 | |||
221 | if (domain->type() != type) { |
|
214 | if (domain->type() != type) { | |
222 | AbstractDomain *old = domain; |
|
215 | AbstractDomain *old = domain; | |
223 | domain = createDomain(type); |
|
216 | domain = createDomain(type); | |
224 | domain->setRange(old->minX(), old->maxX(), old->minY(), old->maxY()); |
|
217 | domain->setRange(old->minX(), old->maxX(), old->minY(), old->maxY()); | |
225 | // Initialize domain size to old domain size, as it won't get updated |
|
218 | // Initialize domain size to old domain size, as it won't get updated | |
226 | // unless geometry changes. |
|
219 | // unless geometry changes. | |
227 | domain->setSize(old->size()); |
|
220 | domain->setSize(old->size()); | |
228 | } |
|
221 | } | |
229 |
|
222 | |||
230 | if (!domain) |
|
223 | if (!domain) | |
231 | return false; |
|
224 | return false; | |
232 |
|
225 | |||
233 | if (!domain->attachAxis(axis)) |
|
226 | if (!domain->attachAxis(axis)) | |
234 | return false; |
|
227 | return false; | |
235 |
|
228 | |||
236 | QList<AbstractDomain *> blockedDomains; |
|
229 | QList<AbstractDomain *> blockedDomains; | |
237 | domain->blockRangeSignals(true); |
|
230 | domain->blockRangeSignals(true); | |
238 | blockedDomains << domain; |
|
231 | blockedDomains << domain; | |
239 |
|
232 | |||
240 | if (domain != series->d_ptr->domain()) { |
|
233 | if (domain != series->d_ptr->domain()) { | |
241 | foreach (QAbstractAxis *axis, series->d_ptr->m_axes) { |
|
234 | foreach (QAbstractAxis *axis, series->d_ptr->m_axes) { | |
242 | series->d_ptr->domain()->detachAxis(axis); |
|
235 | series->d_ptr->domain()->detachAxis(axis); | |
243 | domain->attachAxis(axis); |
|
236 | domain->attachAxis(axis); | |
244 | foreach (QAbstractSeries *otherSeries, axis->d_ptr->m_series) { |
|
237 | foreach (QAbstractSeries *otherSeries, axis->d_ptr->m_series) { | |
245 | if (otherSeries != series && otherSeries->d_ptr->domain()) { |
|
238 | if (otherSeries != series && otherSeries->d_ptr->domain()) { | |
246 | if (!otherSeries->d_ptr->domain()->rangeSignalsBlocked()) { |
|
239 | if (!otherSeries->d_ptr->domain()->rangeSignalsBlocked()) { | |
247 | otherSeries->d_ptr->domain()->blockRangeSignals(true); |
|
240 | otherSeries->d_ptr->domain()->blockRangeSignals(true); | |
248 | blockedDomains << otherSeries->d_ptr->domain(); |
|
241 | blockedDomains << otherSeries->d_ptr->domain(); | |
249 | } |
|
242 | } | |
250 | } |
|
243 | } | |
251 | } |
|
244 | } | |
252 | } |
|
245 | } | |
253 | series->d_ptr->setDomain(domain); |
|
246 | series->d_ptr->setDomain(domain); | |
254 | series->d_ptr->initializeDomain(); |
|
247 | series->d_ptr->initializeDomain(); | |
255 | } |
|
248 | } | |
256 |
|
249 | |||
257 | series->d_ptr->m_axes<<axis; |
|
250 | series->d_ptr->m_axes<<axis; | |
258 | axis->d_ptr->m_series<<series; |
|
251 | axis->d_ptr->m_series<<series; | |
259 |
|
252 | |||
260 | series->d_ptr->initializeAxes(); |
|
253 | series->d_ptr->initializeAxes(); | |
261 | axis->d_ptr->initializeDomain(domain); |
|
254 | axis->d_ptr->initializeDomain(domain); | |
262 |
|
255 | |||
263 | foreach (AbstractDomain *blockedDomain, blockedDomains) |
|
256 | foreach (AbstractDomain *blockedDomain, blockedDomains) | |
264 | blockedDomain->blockRangeSignals(false); |
|
257 | blockedDomain->blockRangeSignals(false); | |
265 |
|
258 | |||
266 | return true; |
|
259 | return true; | |
267 | } |
|
260 | } | |
268 |
|
261 | |||
269 | /* |
|
262 | /* | |
270 | * This method detaches axis to series, return true if success. |
|
263 | * This method detaches axis to series, return true if success. | |
271 | */ |
|
264 | */ | |
272 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
265 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) | |
273 | { |
|
266 | { | |
274 | Q_ASSERT(series); |
|
267 | Q_ASSERT(series); | |
275 | Q_ASSERT(axis); |
|
268 | Q_ASSERT(axis); | |
276 |
|
269 | |||
277 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
270 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; | |
278 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
271 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; | |
279 | AbstractDomain* domain = series->d_ptr->domain(); |
|
272 | AbstractDomain* domain = series->d_ptr->domain(); | |
280 |
|
273 | |||
281 | if (!m_seriesList.contains(series)) { |
|
274 | if (!m_seriesList.contains(series)) { | |
282 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
275 | qWarning() << QObject::tr("Can not find series on the chart."); | |
283 | return false; |
|
276 | return false; | |
284 | } |
|
277 | } | |
285 |
|
278 | |||
286 | if (axis && !m_axisList.contains(axis)) { |
|
279 | if (axis && !m_axisList.contains(axis)) { | |
287 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
280 | qWarning() << QObject::tr("Can not find axis on the chart."); | |
288 | return false; |
|
281 | return false; | |
289 | } |
|
282 | } | |
290 |
|
283 | |||
291 | if (!attachedAxisList.contains(axis)) { |
|
284 | if (!attachedAxisList.contains(axis)) { | |
292 | qWarning() << QObject::tr("Axis not attached to series."); |
|
285 | qWarning() << QObject::tr("Axis not attached to series."); | |
293 | return false; |
|
286 | return false; | |
294 | } |
|
287 | } | |
295 |
|
288 | |||
296 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); |
|
289 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); | |
297 |
|
290 | |||
298 | domain->detachAxis(axis); |
|
291 | domain->detachAxis(axis); | |
299 | series->d_ptr->m_axes.removeAll(axis); |
|
292 | series->d_ptr->m_axes.removeAll(axis); | |
300 | axis->d_ptr->m_series.removeAll(series); |
|
293 | axis->d_ptr->m_series.removeAll(series); | |
301 |
|
294 | |||
302 | return true; |
|
295 | return true; | |
303 | } |
|
296 | } | |
304 |
|
297 | |||
305 | void ChartDataSet::createDefaultAxes() |
|
298 | void ChartDataSet::createDefaultAxes() | |
306 | { |
|
299 | { | |
307 | if (m_seriesList.isEmpty()) |
|
300 | if (m_seriesList.isEmpty()) | |
308 | return; |
|
301 | return; | |
309 |
|
302 | |||
310 | QAbstractAxis::AxisTypes typeX(0); |
|
303 | QAbstractAxis::AxisTypes typeX(0); | |
311 | QAbstractAxis::AxisTypes typeY(0); |
|
304 | QAbstractAxis::AxisTypes typeY(0); | |
312 |
|
305 | |||
313 | // Remove possibly existing axes |
|
306 | // Remove possibly existing axes | |
314 | deleteAllAxes(); |
|
307 | deleteAllAxes(); | |
315 |
|
308 | |||
316 | Q_ASSERT(m_axisList.isEmpty()); |
|
309 | Q_ASSERT(m_axisList.isEmpty()); | |
317 |
|
310 | |||
318 | // Select the required axis x and axis y types based on the types of the current series |
|
311 | // Select the required axis x and axis y types based on the types of the current series | |
319 | foreach(QAbstractSeries* s, m_seriesList) { |
|
312 | foreach(QAbstractSeries* s, m_seriesList) { | |
320 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); |
|
313 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); | |
321 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); |
|
314 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); | |
322 | } |
|
315 | } | |
323 |
|
316 | |||
324 | // Create the axes of the types selected |
|
317 | // Create the axes of the types selected | |
325 | createAxes(typeX, Qt::Horizontal); |
|
318 | createAxes(typeX, Qt::Horizontal); | |
326 | createAxes(typeY, Qt::Vertical); |
|
319 | createAxes(typeY, Qt::Vertical); | |
327 |
|
320 | |||
328 | } |
|
321 | } | |
329 |
|
322 | |||
330 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
323 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) | |
331 | { |
|
324 | { | |
332 | QAbstractAxis *axis = 0; |
|
325 | QAbstractAxis *axis = 0; | |
333 | //decide what axis should be created |
|
326 | //decide what axis should be created | |
334 |
|
327 | |||
335 | switch (type) { |
|
328 | switch (type) { | |
336 | case QAbstractAxis::AxisTypeValue: |
|
329 | case QAbstractAxis::AxisTypeValue: | |
337 | axis = new QValueAxis(this); |
|
330 | axis = new QValueAxis(this); | |
338 | break; |
|
331 | break; | |
339 | case QAbstractAxis::AxisTypeBarCategory: |
|
332 | case QAbstractAxis::AxisTypeBarCategory: | |
340 | axis = new QBarCategoryAxis(this); |
|
333 | axis = new QBarCategoryAxis(this); | |
341 | break; |
|
334 | break; | |
342 | case QAbstractAxis::AxisTypeCategory: |
|
335 | case QAbstractAxis::AxisTypeCategory: | |
343 | axis = new QCategoryAxis(this); |
|
336 | axis = new QCategoryAxis(this); | |
344 | break; |
|
337 | break; | |
345 | #ifndef Q_WS_QWS |
|
338 | #ifndef Q_WS_QWS | |
346 | case QAbstractAxis::AxisTypeDateTime: |
|
339 | case QAbstractAxis::AxisTypeDateTime: | |
347 | axis = new QDateTimeAxis(this); |
|
340 | axis = new QDateTimeAxis(this); | |
348 | break; |
|
341 | break; | |
349 | #endif |
|
342 | #endif | |
350 | default: |
|
343 | default: | |
351 | axis = 0; |
|
344 | axis = 0; | |
352 | break; |
|
345 | break; | |
353 | } |
|
346 | } | |
354 |
|
347 | |||
355 | if (axis) { |
|
348 | if (axis) { | |
356 | //create one axis for all |
|
349 | //create one axis for all | |
357 |
|
350 | |||
358 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
351 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); | |
359 | qreal min = 0; |
|
352 | qreal min = 0; | |
360 | qreal max = 0; |
|
353 | qreal max = 0; | |
361 | findMinMaxForSeries(m_seriesList,orientation,min,max); |
|
354 | findMinMaxForSeries(m_seriesList,orientation,min,max); | |
362 | foreach(QAbstractSeries *s, m_seriesList) { |
|
355 | foreach(QAbstractSeries *s, m_seriesList) { | |
363 | attachAxis(s,axis); |
|
356 | attachAxis(s,axis); | |
364 | } |
|
357 | } | |
365 | axis->setRange(min,max); |
|
358 | axis->setRange(min,max); | |
366 | } |
|
359 | } | |
367 | else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
360 | else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { | |
368 | //create separate axis |
|
361 | //create separate axis | |
369 | foreach(QAbstractSeries *s, m_seriesList) { |
|
362 | foreach(QAbstractSeries *s, m_seriesList) { | |
370 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); |
|
363 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); | |
371 | if(axis) { |
|
364 | if(axis) { | |
372 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
365 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); | |
373 | attachAxis(s,axis); |
|
366 | attachAxis(s,axis); | |
374 | } |
|
367 | } | |
375 | } |
|
368 | } | |
376 | } |
|
369 | } | |
377 | } |
|
370 | } | |
378 |
|
371 | |||
379 | void ChartDataSet::findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max) |
|
372 | void ChartDataSet::findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max) | |
380 | { |
|
373 | { | |
381 | Q_ASSERT(!series.isEmpty()); |
|
374 | Q_ASSERT(!series.isEmpty()); | |
382 |
|
375 | |||
383 | AbstractDomain *domain = series.first()->d_ptr->domain(); |
|
376 | AbstractDomain *domain = series.first()->d_ptr->domain(); | |
384 | min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX(); |
|
377 | min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX(); | |
385 | max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(); |
|
378 | max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(); | |
386 |
|
379 | |||
387 | for (int i = 1; i< series.size(); i++) { |
|
380 | for (int i = 1; i< series.size(); i++) { | |
388 | AbstractDomain *domain = series[i]->d_ptr->domain(); |
|
381 | AbstractDomain *domain = series[i]->d_ptr->domain(); | |
389 | min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min); |
|
382 | min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min); | |
390 | max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max); |
|
383 | max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max); | |
391 | } |
|
384 | } | |
392 | if (min == max) { |
|
385 | if (min == max) { | |
393 | min -= 0.5; |
|
386 | min -= 0.5; | |
394 | max += 0.5; |
|
387 | max += 0.5; | |
395 | } |
|
388 | } | |
396 | } |
|
389 | } | |
397 |
|
390 | |||
398 | void ChartDataSet::deleteAllSeries() |
|
391 | void ChartDataSet::deleteAllSeries() | |
399 | { |
|
392 | { | |
400 | foreach (QAbstractSeries *s , m_seriesList){ |
|
393 | foreach (QAbstractSeries *s , m_seriesList){ | |
401 | removeSeries(s); |
|
394 | removeSeries(s); | |
402 | s->deleteLater(); |
|
395 | s->deleteLater(); | |
403 | } |
|
396 | } | |
404 | Q_ASSERT(m_seriesList.count() == 0); |
|
397 | Q_ASSERT(m_seriesList.count() == 0); | |
405 | } |
|
398 | } | |
406 |
|
399 | |||
407 | void ChartDataSet::deleteAllAxes() |
|
400 | void ChartDataSet::deleteAllAxes() | |
408 | { |
|
401 | { | |
409 | foreach (QAbstractAxis *a , m_axisList){ |
|
402 | foreach (QAbstractAxis *a , m_axisList){ | |
410 | removeAxis(a); |
|
403 | removeAxis(a); | |
411 | a->deleteLater(); |
|
404 | a->deleteLater(); | |
412 | } |
|
405 | } | |
413 | Q_ASSERT(m_axisList.count() == 0); |
|
406 | Q_ASSERT(m_axisList.count() == 0); | |
414 | } |
|
407 | } | |
415 |
|
408 | |||
416 | void ChartDataSet::zoomInDomain(const QRectF &rect) |
|
409 | void ChartDataSet::zoomInDomain(const QRectF &rect) | |
417 | { |
|
410 | { | |
418 | QList<AbstractDomain*> domains; |
|
411 | QList<AbstractDomain*> domains; | |
419 | foreach(QAbstractSeries *s, m_seriesList) { |
|
412 | foreach(QAbstractSeries *s, m_seriesList) { | |
420 | AbstractDomain* domain = s->d_ptr->domain(); |
|
413 | AbstractDomain* domain = s->d_ptr->domain(); | |
421 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
414 | s->d_ptr->m_domain->blockRangeSignals(true); | |
422 | domains<<domain; |
|
415 | domains<<domain; | |
423 | } |
|
416 | } | |
424 |
|
417 | |||
425 | foreach(AbstractDomain *domain, domains) |
|
418 | foreach(AbstractDomain *domain, domains) | |
426 | domain->zoomIn(rect); |
|
419 | domain->zoomIn(rect); | |
427 |
|
420 | |||
428 | foreach(AbstractDomain *domain, domains) |
|
421 | foreach(AbstractDomain *domain, domains) | |
429 | domain->blockRangeSignals(false); |
|
422 | domain->blockRangeSignals(false); | |
430 | } |
|
423 | } | |
431 |
|
424 | |||
432 | void ChartDataSet::zoomOutDomain(const QRectF &rect) |
|
425 | void ChartDataSet::zoomOutDomain(const QRectF &rect) | |
433 | { |
|
426 | { | |
434 | QList<AbstractDomain*> domains; |
|
427 | QList<AbstractDomain*> domains; | |
435 | foreach(QAbstractSeries *s, m_seriesList) { |
|
428 | foreach(QAbstractSeries *s, m_seriesList) { | |
436 | AbstractDomain* domain = s->d_ptr->domain(); |
|
429 | AbstractDomain* domain = s->d_ptr->domain(); | |
437 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
430 | s->d_ptr->m_domain->blockRangeSignals(true); | |
438 | domains<<domain; |
|
431 | domains<<domain; | |
439 | } |
|
432 | } | |
440 |
|
433 | |||
441 | foreach(AbstractDomain *domain, domains) |
|
434 | foreach(AbstractDomain *domain, domains) | |
442 | domain->zoomOut(rect); |
|
435 | domain->zoomOut(rect); | |
443 |
|
436 | |||
444 | foreach(AbstractDomain *domain, domains) |
|
437 | foreach(AbstractDomain *domain, domains) | |
445 | domain->blockRangeSignals(false); |
|
438 | domain->blockRangeSignals(false); | |
446 | } |
|
439 | } | |
447 |
|
440 | |||
448 | void ChartDataSet::zoomResetDomain() |
|
441 | void ChartDataSet::zoomResetDomain() | |
449 | { |
|
442 | { | |
450 | QList<AbstractDomain*> domains; |
|
443 | QList<AbstractDomain*> domains; | |
451 | foreach (QAbstractSeries *s, m_seriesList) { |
|
444 | foreach (QAbstractSeries *s, m_seriesList) { | |
452 | AbstractDomain *domain = s->d_ptr->domain(); |
|
445 | AbstractDomain *domain = s->d_ptr->domain(); | |
453 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
446 | s->d_ptr->m_domain->blockRangeSignals(true); | |
454 | domains << domain; |
|
447 | domains << domain; | |
455 | } |
|
448 | } | |
456 |
|
449 | |||
457 | foreach (AbstractDomain *domain, domains) |
|
450 | foreach (AbstractDomain *domain, domains) | |
458 | domain->zoomReset(); |
|
451 | domain->zoomReset(); | |
459 |
|
452 | |||
460 | foreach (AbstractDomain *domain, domains) |
|
453 | foreach (AbstractDomain *domain, domains) | |
461 | domain->blockRangeSignals(false); |
|
454 | domain->blockRangeSignals(false); | |
462 | } |
|
455 | } | |
463 |
|
456 | |||
464 | bool ChartDataSet::isZoomedDomain() |
|
457 | bool ChartDataSet::isZoomedDomain() | |
465 | { |
|
458 | { | |
466 | foreach (QAbstractSeries *s, m_seriesList) { |
|
459 | foreach (QAbstractSeries *s, m_seriesList) { | |
467 | if (s->d_ptr->domain()->isZoomed()) |
|
460 | if (s->d_ptr->domain()->isZoomed()) | |
468 | return true; |
|
461 | return true; | |
469 | } |
|
462 | } | |
470 | return false; |
|
463 | return false; | |
471 | } |
|
464 | } | |
472 |
|
465 | |||
473 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) |
|
466 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) | |
474 | { |
|
467 | { | |
475 | QList<AbstractDomain*> domains; |
|
468 | QList<AbstractDomain*> domains; | |
476 | foreach(QAbstractSeries *s, m_seriesList) { |
|
469 | foreach(QAbstractSeries *s, m_seriesList) { | |
477 | AbstractDomain* domain = s->d_ptr->domain(); |
|
470 | AbstractDomain* domain = s->d_ptr->domain(); | |
478 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
471 | s->d_ptr->m_domain->blockRangeSignals(true); | |
479 | domains<<domain; |
|
472 | domains<<domain; | |
480 | } |
|
473 | } | |
481 |
|
474 | |||
482 | foreach(AbstractDomain *domain, domains) |
|
475 | foreach(AbstractDomain *domain, domains) | |
483 | domain->move(dx, dy); |
|
476 | domain->move(dx, dy); | |
484 |
|
477 | |||
485 | foreach(AbstractDomain *domain, domains) |
|
478 | foreach(AbstractDomain *domain, domains) | |
486 | domain->blockRangeSignals(false); |
|
479 | domain->blockRangeSignals(false); | |
487 | } |
|
480 | } | |
488 |
|
481 | |||
489 | QPointF ChartDataSet::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
482 | QPointF ChartDataSet::mapToValue(const QPointF &position, QAbstractSeries *series) | |
490 | { |
|
483 | { | |
491 | QPointF point; |
|
484 | QPointF point; | |
492 | if (series == 0 && !m_seriesList.isEmpty()) |
|
485 | if (series == 0 && !m_seriesList.isEmpty()) | |
493 | series = m_seriesList.first(); |
|
486 | series = m_seriesList.first(); | |
494 |
|
487 | |||
495 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
488 | if (series && series->type() == QAbstractSeries::SeriesTypePie) | |
496 | return point; |
|
489 | return point; | |
497 |
|
490 | |||
498 | if (series && m_seriesList.contains(series)) |
|
491 | if (series && m_seriesList.contains(series)) | |
499 | point = series->d_ptr->m_domain->calculateDomainPoint(position - m_chart->plotArea().topLeft()); |
|
492 | point = series->d_ptr->m_domain->calculateDomainPoint(position - m_chart->plotArea().topLeft()); | |
500 | return point; |
|
493 | return point; | |
501 | } |
|
494 | } | |
502 |
|
495 | |||
503 | QPointF ChartDataSet::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
496 | QPointF ChartDataSet::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
504 | { |
|
497 | { | |
505 | QPointF point = m_chart->plotArea().topLeft(); |
|
498 | QPointF point = m_chart->plotArea().topLeft(); | |
506 | if (series == 0 && !m_seriesList.isEmpty()) |
|
499 | if (series == 0 && !m_seriesList.isEmpty()) | |
507 | series = m_seriesList.first(); |
|
500 | series = m_seriesList.first(); | |
508 |
|
501 | |||
509 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
502 | if (series && series->type() == QAbstractSeries::SeriesTypePie) | |
510 | return QPoint(0, 0); |
|
503 | return QPoint(0, 0); | |
511 |
|
504 | |||
512 | bool ok; |
|
505 | bool ok; | |
513 | if (series && m_seriesList.contains(series)) |
|
506 | if (series && m_seriesList.contains(series)) | |
514 | point += series->d_ptr->m_domain->calculateGeometryPoint(value, ok); |
|
507 | point += series->d_ptr->m_domain->calculateGeometryPoint(value, ok); | |
515 | return point; |
|
508 | return point; | |
516 | } |
|
509 | } | |
517 |
|
510 | |||
518 | QList<QAbstractAxis *> ChartDataSet::axes() const |
|
511 | QList<QAbstractAxis *> ChartDataSet::axes() const | |
519 | { |
|
512 | { | |
520 | return m_axisList; |
|
513 | return m_axisList; | |
521 | } |
|
514 | } | |
522 |
|
515 | |||
523 | QList<QAbstractSeries *> ChartDataSet::series() const |
|
516 | QList<QAbstractSeries *> ChartDataSet::series() const | |
524 | { |
|
517 | { | |
525 | return m_seriesList; |
|
518 | return m_seriesList; | |
526 | } |
|
519 | } | |
527 |
|
520 | |||
528 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis *> axes) |
|
521 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis *> axes) | |
529 | { |
|
522 | { | |
530 | enum Type { |
|
523 | enum Type { | |
531 | Undefined = 0, |
|
524 | Undefined = 0, | |
532 | LogType = 0x1, |
|
525 | LogType = 0x1, | |
533 | ValueType = 0x2 |
|
526 | ValueType = 0x2 | |
534 | }; |
|
527 | }; | |
535 |
|
528 | |||
536 | int horizontal(Undefined); |
|
529 | int horizontal(Undefined); | |
537 | int vertical(Undefined); |
|
530 | int vertical(Undefined); | |
538 |
|
531 | |||
539 | // Assume cartesian chart type, unless chart is set |
|
532 | // Assume cartesian chart type, unless chart is set | |
540 | QChart::ChartType chartType(QChart::ChartTypeCartesian); |
|
533 | QChart::ChartType chartType(QChart::ChartTypeCartesian); | |
541 | if (m_chart) |
|
534 | if (m_chart) | |
542 | chartType = m_chart->chartType(); |
|
535 | chartType = m_chart->chartType(); | |
543 |
|
536 | |||
544 | foreach (QAbstractAxis *axis, axes) |
|
537 | foreach (QAbstractAxis *axis, axes) | |
545 | { |
|
538 | { | |
546 | switch (axis->type()) { |
|
539 | switch (axis->type()) { | |
547 | case QAbstractAxis::AxisTypeLogValue: |
|
540 | case QAbstractAxis::AxisTypeLogValue: | |
548 | if (axis->orientation() == Qt::Horizontal) |
|
541 | if (axis->orientation() == Qt::Horizontal) | |
549 | horizontal |= LogType; |
|
542 | horizontal |= LogType; | |
550 | if (axis->orientation() == Qt::Vertical) |
|
543 | if (axis->orientation() == Qt::Vertical) | |
551 | vertical |= LogType; |
|
544 | vertical |= LogType; | |
552 | break; |
|
545 | break; | |
553 | case QAbstractAxis::AxisTypeValue: |
|
546 | case QAbstractAxis::AxisTypeValue: | |
554 | case QAbstractAxis::AxisTypeBarCategory: |
|
547 | case QAbstractAxis::AxisTypeBarCategory: | |
555 | case QAbstractAxis::AxisTypeCategory: |
|
548 | case QAbstractAxis::AxisTypeCategory: | |
556 | case QAbstractAxis::AxisTypeDateTime: |
|
549 | case QAbstractAxis::AxisTypeDateTime: | |
557 | if (axis->orientation() == Qt::Horizontal) |
|
550 | if (axis->orientation() == Qt::Horizontal) | |
558 | horizontal |= ValueType; |
|
551 | horizontal |= ValueType; | |
559 | if (axis->orientation() == Qt::Vertical) |
|
552 | if (axis->orientation() == Qt::Vertical) | |
560 | vertical |= ValueType; |
|
553 | vertical |= ValueType; | |
561 | break; |
|
554 | break; | |
562 | default: |
|
555 | default: | |
563 | qWarning() << "Undefined type"; |
|
556 | qWarning() << "Undefined type"; | |
564 | break; |
|
557 | break; | |
565 | } |
|
558 | } | |
566 | } |
|
559 | } | |
567 |
|
560 | |||
568 | if (vertical == Undefined) |
|
561 | if (vertical == Undefined) | |
569 | vertical = ValueType; |
|
562 | vertical = ValueType; | |
570 | if (horizontal == Undefined) |
|
563 | if (horizontal == Undefined) | |
571 | horizontal = ValueType; |
|
564 | horizontal = ValueType; | |
572 |
|
565 | |||
573 | if (vertical == ValueType && horizontal == ValueType) { |
|
566 | if (vertical == ValueType && horizontal == ValueType) { | |
574 | if (chartType == QChart::ChartTypeCartesian) |
|
567 | if (chartType == QChart::ChartTypeCartesian) | |
575 | return AbstractDomain::XYDomain; |
|
568 | return AbstractDomain::XYDomain; | |
576 | else if (chartType == QChart::ChartTypePolar) |
|
569 | else if (chartType == QChart::ChartTypePolar) | |
577 | return AbstractDomain::XYPolarDomain; |
|
570 | return AbstractDomain::XYPolarDomain; | |
578 | } |
|
571 | } | |
579 |
|
572 | |||
580 | if (vertical == LogType && horizontal == ValueType) { |
|
573 | if (vertical == LogType && horizontal == ValueType) { | |
581 | if (chartType == QChart::ChartTypeCartesian) |
|
574 | if (chartType == QChart::ChartTypeCartesian) | |
582 | return AbstractDomain::XLogYDomain; |
|
575 | return AbstractDomain::XLogYDomain; | |
583 | if (chartType == QChart::ChartTypePolar) |
|
576 | if (chartType == QChart::ChartTypePolar) | |
584 | return AbstractDomain::XLogYPolarDomain; |
|
577 | return AbstractDomain::XLogYPolarDomain; | |
585 | } |
|
578 | } | |
586 |
|
579 | |||
587 | if (vertical == ValueType && horizontal == LogType) { |
|
580 | if (vertical == ValueType && horizontal == LogType) { | |
588 | if (chartType == QChart::ChartTypeCartesian) |
|
581 | if (chartType == QChart::ChartTypeCartesian) | |
589 | return AbstractDomain::LogXYDomain; |
|
582 | return AbstractDomain::LogXYDomain; | |
590 | else if (chartType == QChart::ChartTypePolar) |
|
583 | else if (chartType == QChart::ChartTypePolar) | |
591 | return AbstractDomain::LogXYPolarDomain; |
|
584 | return AbstractDomain::LogXYPolarDomain; | |
592 | } |
|
585 | } | |
593 |
|
586 | |||
594 | if (vertical == LogType && horizontal == LogType) { |
|
587 | if (vertical == LogType && horizontal == LogType) { | |
595 | if (chartType == QChart::ChartTypeCartesian) |
|
588 | if (chartType == QChart::ChartTypeCartesian) | |
596 | return AbstractDomain::LogXLogYDomain; |
|
589 | return AbstractDomain::LogXLogYDomain; | |
597 | else if (chartType == QChart::ChartTypePolar) |
|
590 | else if (chartType == QChart::ChartTypePolar) | |
598 | return AbstractDomain::LogXLogYPolarDomain; |
|
591 | return AbstractDomain::LogXLogYPolarDomain; | |
599 | } |
|
592 | } | |
600 |
|
593 | |||
601 | return AbstractDomain::UndefinedDomain; |
|
594 | return AbstractDomain::UndefinedDomain; | |
602 | } |
|
595 | } | |
603 |
|
596 | |||
604 | //refactor create factory |
|
597 | //refactor create factory | |
605 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) |
|
598 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) | |
606 | { |
|
599 | { | |
607 | switch (type) |
|
600 | switch (type) | |
608 | { |
|
601 | { | |
609 | case AbstractDomain::LogXLogYDomain: |
|
602 | case AbstractDomain::LogXLogYDomain: | |
610 | return new LogXLogYDomain(); |
|
603 | return new LogXLogYDomain(); | |
611 | case AbstractDomain::XYDomain: |
|
604 | case AbstractDomain::XYDomain: | |
612 | return new XYDomain(); |
|
605 | return new XYDomain(); | |
613 | case AbstractDomain::XLogYDomain: |
|
606 | case AbstractDomain::XLogYDomain: | |
614 | return new XLogYDomain(); |
|
607 | return new XLogYDomain(); | |
615 | case AbstractDomain::LogXYDomain: |
|
608 | case AbstractDomain::LogXYDomain: | |
616 | return new LogXYDomain(); |
|
609 | return new LogXYDomain(); | |
617 | case AbstractDomain::XYPolarDomain: |
|
610 | case AbstractDomain::XYPolarDomain: | |
618 | return new XYPolarDomain(); |
|
611 | return new XYPolarDomain(); | |
619 | case AbstractDomain::XLogYPolarDomain: |
|
612 | case AbstractDomain::XLogYPolarDomain: | |
620 | return new XLogYPolarDomain(); |
|
613 | return new XLogYPolarDomain(); | |
621 | case AbstractDomain::LogXYPolarDomain: |
|
614 | case AbstractDomain::LogXYPolarDomain: | |
622 | return new LogXYPolarDomain(); |
|
615 | return new LogXYPolarDomain(); | |
623 | case AbstractDomain::LogXLogYPolarDomain: |
|
616 | case AbstractDomain::LogXLogYPolarDomain: | |
624 | return new LogXLogYPolarDomain(); |
|
617 | return new LogXLogYPolarDomain(); | |
625 | default: |
|
618 | default: | |
626 | return 0; |
|
619 | return 0; | |
627 | } |
|
620 | } | |
628 | } |
|
621 | } | |
629 |
|
622 | |||
630 | #include "moc_chartdataset_p.cpp" |
|
623 | #include "moc_chartdataset_p.cpp" | |
631 |
|
624 | |||
632 | QTCOMMERCIALCHART_END_NAMESPACE |
|
625 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,129 +1,132 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "qpolarchart.h" |
|
21 | #include "qpolarchart.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \enum QPolarChart::PolarOrientation |
|
27 | \enum QPolarChart::PolarOrientation | |
28 |
|
28 | |||
29 | This type is used to specify the polar orientation of an axis. |
|
29 | This type is used to specify the polar orientation of an axis. | |
30 |
|
30 | |||
31 | \value PolarOrientationRadial |
|
31 | \value PolarOrientationRadial | |
32 | \value PolarOrientationAngular |
|
32 | \value PolarOrientationAngular | |
33 | */ |
|
33 | */ | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QPolarChart |
|
36 | \class QPolarChart | |
37 | \brief QtCommercial chart API. |
|
37 | \brief QtCommercial chart API. | |
38 |
|
38 | |||
39 | QPolarChart is a specialization of QChart to show a polar chart. |
|
39 | QPolarChart is a specialization of QChart to show a polar chart. | |
40 |
|
40 | |||
41 | Polar charts support line, spline, area, and scatter series, and all axis types |
|
41 | Polar charts support line, spline, area, and scatter series, and all axis types | |
42 | supported by those series. |
|
42 | supported by those series. | |
43 |
|
43 | |||
44 | \note When setting ticks to an angular QValueAxis, keep in mind that the first and last tick |
|
44 | \note When setting ticks to an angular QValueAxis, keep in mind that the first and last tick | |
45 | are co-located at 0/360 degree angle. |
|
45 | are co-located at 0/360 degree angle. | |
46 |
|
46 | |||
47 | \note If the angular distance between two consecutive points in a series is more than 180 degrees, |
|
47 | \note If the angular distance between two consecutive points in a series is more than 180 degrees, | |
48 | any line connecting the two points becomes meaningless, so choose the axis ranges accordingly |
|
48 | any line connecting the two points becomes meaningless, so choose the axis ranges accordingly | |
49 | when displaying line, spline, or area series. In such case series don't draw a direct line between |
|
49 | when displaying line, spline, or area series. In such case series don't draw a direct line between | |
50 | the two points, but instead draw a line to and from the center of the chart. |
|
50 | the two points, but instead draw a line to and from the center of the chart. | |
51 |
|
51 | |||
52 |
\note Polar charts d |
|
52 | \note Polar charts draw all axes of same orientation in the same position, so using multiple | |
|
53 | axes of same orientation can be confusing, unless the extra axes are only used to customize the | |||
|
54 | grid (e.g. you can display a highlighted range with a secondary shaded QCategoryAxis or provide | |||
|
55 | unlabeled subticks with a secondary QValueAxis that has its labels hidden). | |||
53 |
|
56 | |||
54 | \sa QChart |
|
57 | \sa QChart | |
55 | */ |
|
58 | */ | |
56 |
|
59 | |||
57 | /*! |
|
60 | /*! | |
58 | Constructs a polar chart as a child of the \a parent. |
|
61 | Constructs a polar chart as a child of the \a parent. | |
59 | Parameter \a wFlags is passed to the QChart constructor. |
|
62 | Parameter \a wFlags is passed to the QChart constructor. | |
60 | */ |
|
63 | */ | |
61 | QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
64 | QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
62 | : QChart(QChart::ChartTypePolar, parent, wFlags) |
|
65 | : QChart(QChart::ChartTypePolar, parent, wFlags) | |
63 | { |
|
66 | { | |
64 | } |
|
67 | } | |
65 |
|
68 | |||
66 | /*! |
|
69 | /*! | |
67 | Destroys the polar chart object and its children, like series and axis objects added to it. |
|
70 | Destroys the polar chart object and its children, like series and axis objects added to it. | |
68 | */ |
|
71 | */ | |
69 | QPolarChart::~QPolarChart() |
|
72 | QPolarChart::~QPolarChart() | |
70 | { |
|
73 | { | |
71 | } |
|
74 | } | |
72 |
|
75 | |||
73 | /*! |
|
76 | /*! | |
74 | Returns the axes added for the \a series with \a polarOrientation. If no series is provided, then any axis with the |
|
77 | Returns the axes added for the \a series with \a polarOrientation. If no series is provided, then any axis with the | |
75 | specified polar orientation is returned. |
|
78 | specified polar orientation is returned. | |
76 |
|
79 | |||
77 | \sa addAxis() |
|
80 | \sa addAxis() | |
78 | */ |
|
81 | */ | |
79 | QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const |
|
82 | QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const | |
80 | { |
|
83 | { | |
81 | Qt::Orientations orientation(0); |
|
84 | Qt::Orientations orientation(0); | |
82 | if (polarOrientation.testFlag(PolarOrientationAngular)) |
|
85 | if (polarOrientation.testFlag(PolarOrientationAngular)) | |
83 | orientation |= Qt::Horizontal; |
|
86 | orientation |= Qt::Horizontal; | |
84 | if (polarOrientation.testFlag(PolarOrientationRadial)) |
|
87 | if (polarOrientation.testFlag(PolarOrientationRadial)) | |
85 | orientation |= Qt::Vertical; |
|
88 | orientation |= Qt::Vertical; | |
86 |
|
89 | |||
87 | return QChart::axes(orientation, series); |
|
90 | return QChart::axes(orientation, series); | |
88 | } |
|
91 | } | |
89 |
|
92 | |||
90 | /*! |
|
93 | /*! | |
91 | This convenience method adds \a axis to the polar chart with \a polarOrientation. |
|
94 | This convenience method adds \a axis to the polar chart with \a polarOrientation. | |
92 | The chart takes the ownership of the axis. |
|
95 | The chart takes the ownership of the axis. | |
93 |
|
96 | |||
94 | \note Axes can be added to a polar chart also with QChart::addAxis() instead of this method. |
|
97 | \note Axes can be added to a polar chart also with QChart::addAxis() instead of this method. | |
95 | The specified alignment determines the polar orientation: horizontal alignments indicate angular |
|
98 | The specified alignment determines the polar orientation: horizontal alignments indicate angular | |
96 | axis and vertical alignments indicate radial axis. |
|
99 | axis and vertical alignments indicate radial axis. | |
97 |
|
100 | |||
98 | \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis() |
|
101 | \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis() | |
99 | */ |
|
102 | */ | |
100 | void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation) |
|
103 | void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation) | |
101 | { |
|
104 | { | |
102 | if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
105 | if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
103 | qWarning("QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts."); |
|
106 | qWarning("QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts."); | |
104 | } else { |
|
107 | } else { | |
105 | Qt::Alignment alignment = Qt::AlignLeft; |
|
108 | Qt::Alignment alignment = Qt::AlignLeft; | |
106 | if (polarOrientation == PolarOrientationAngular) |
|
109 | if (polarOrientation == PolarOrientationAngular) | |
107 | alignment = Qt::AlignBottom; |
|
110 | alignment = Qt::AlignBottom; | |
108 | QChart::addAxis(axis, alignment); |
|
111 | QChart::addAxis(axis, alignment); | |
109 | } |
|
112 | } | |
110 | } |
|
113 | } | |
111 |
|
114 | |||
112 | /*! |
|
115 | /*! | |
113 | Angular axes of a polar chart report horizontal orientation and radial axes report |
|
116 | Angular axes of a polar chart report horizontal orientation and radial axes report | |
114 | vertical orientation. |
|
117 | vertical orientation. | |
115 | This function is a convenience function for converting the orientation of an \a axis to |
|
118 | This function is a convenience function for converting the orientation of an \a axis to | |
116 | corresponding polar orientation. If the \a axis is NULL or not added to a polar chart, |
|
119 | corresponding polar orientation. If the \a axis is NULL or not added to a polar chart, | |
117 | the return value is meaningless. |
|
120 | the return value is meaningless. | |
118 | */ |
|
121 | */ | |
119 | QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis) |
|
122 | QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis) | |
120 | { |
|
123 | { | |
121 | if (axis && axis->orientation() == Qt::Horizontal) |
|
124 | if (axis && axis->orientation() == Qt::Horizontal) | |
122 | return PolarOrientationAngular; |
|
125 | return PolarOrientationAngular; | |
123 | else |
|
126 | else | |
124 | return PolarOrientationRadial; |
|
127 | return PolarOrientationRadial; | |
125 | } |
|
128 | } | |
126 |
|
129 | |||
127 | #include "moc_qpolarchart.cpp" |
|
130 | #include "moc_qpolarchart.cpp" | |
128 |
|
131 | |||
129 | QTCOMMERCIALCHART_END_NAMESPACE |
|
132 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now