##// END OF EJS Templates
Adds logdomains to factory method
Michal Klocek -
r2287:bd4b63e492b8
parent child
Show More
@@ -1,465 +1,465
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 "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 "xlogydomain_p.h"
36 #include "xlogydomain_p.h"
37 #include "logxydomain_p.h"
37 #include "logxydomain_p.h"
38 #include "logxlogydomain_p.h"
38 #include "logxlogydomain_p.h"
39
39
40 #ifndef QT_ON_ARM
40 #ifndef QT_ON_ARM
41 #include "qdatetimeaxis.h"
41 #include "qdatetimeaxis.h"
42 #endif
42 #endif
43
43
44 QTCOMMERCIALCHART_BEGIN_NAMESPACE
44 QTCOMMERCIALCHART_BEGIN_NAMESPACE
45
45
46 ChartDataSet::ChartDataSet(QChart *chart)
46 ChartDataSet::ChartDataSet(QChart *chart)
47 : QObject(chart),
47 : QObject(chart),
48 m_chart(chart)
48 m_chart(chart)
49 {
49 {
50
50
51 }
51 }
52
52
53 ChartDataSet::~ChartDataSet()
53 ChartDataSet::~ChartDataSet()
54 {
54 {
55 deleteAllSeries();
55 deleteAllSeries();
56 deleteAllAxes();
56 deleteAllAxes();
57 }
57 }
58
58
59 /*
59 /*
60 * This method adds series to chartdataset, series ownership is taken from caller.
60 * This method adds series to chartdataset, series ownership is taken from caller.
61 */
61 */
62 void ChartDataSet::addSeries(QAbstractSeries *series)
62 void ChartDataSet::addSeries(QAbstractSeries *series)
63 {
63 {
64 if (m_seriesList.contains(series)) {
64 if (m_seriesList.contains(series)) {
65 qWarning() << QObject::tr("Can not add series. Series already on the chart.");
65 qWarning() << QObject::tr("Can not add series. Series already on the chart.");
66 return;
66 return;
67 }
67 }
68
68
69 series->d_ptr->initializeDomain();
69 series->d_ptr->initializeDomain();
70 m_seriesList.append(series);
70 m_seriesList.append(series);
71
71
72 series->setParent(this); // take ownership
72 series->setParent(this); // take ownership
73 series->d_ptr->m_chart = m_chart;
73 series->d_ptr->m_chart = m_chart;
74
74
75 emit seriesAdded(series);
75 emit seriesAdded(series);
76 }
76 }
77
77
78 /*
78 /*
79 * This method adds axis to chartdataset, axis ownership is taken from caller.
79 * This method adds axis to chartdataset, axis ownership is taken from caller.
80 */
80 */
81 void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
81 void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment)
82 {
82 {
83 if (m_axisList.contains(axis)) {
83 if (m_axisList.contains(axis)) {
84 qWarning() << QObject::tr("Can not add axis. Axis already on the chart.");
84 qWarning() << QObject::tr("Can not add axis. Axis already on the chart.");
85 return;
85 return;
86 }
86 }
87
87
88 axis->d_ptr->setAlignment(aligment);
88 axis->d_ptr->setAlignment(aligment);
89
89
90 if(!axis->alignment()) {
90 if(!axis->alignment()) {
91 qWarning()<< QObject::tr("No alignment specified !");
91 qWarning()<< QObject::tr("No alignment specified !");
92 return;
92 return;
93 };
93 };
94
94
95 QSharedPointer<AbstractDomain> domain(new XYDomain());
95 QSharedPointer<AbstractDomain> domain(new XYDomain());
96 axis->d_ptr->initializeDomain(domain.data());
96 axis->d_ptr->initializeDomain(domain.data());
97
97
98 axis->setParent(this);
98 axis->setParent(this);
99 axis->d_ptr->m_chart = m_chart;
99 axis->d_ptr->m_chart = m_chart;
100 m_axisList.append(axis);
100 m_axisList.append(axis);
101
101
102 emit axisAdded(axis);
102 emit axisAdded(axis);
103 }
103 }
104
104
105 /*
105 /*
106 * This method removes series form chartdataset, series ownership is passed back to caller.
106 * This method removes series form chartdataset, series ownership is passed back to caller.
107 */
107 */
108 void ChartDataSet::removeSeries(QAbstractSeries *series)
108 void ChartDataSet::removeSeries(QAbstractSeries *series)
109 {
109 {
110
110
111 if (! m_seriesList.contains(series)) {
111 if (! m_seriesList.contains(series)) {
112 qWarning() << QObject::tr("Can not remove series. Series not found on the chart.");
112 qWarning() << QObject::tr("Can not remove series. Series not found on the chart.");
113 return;
113 return;
114 }
114 }
115
115
116 emit seriesRemoved(series);
116 emit seriesRemoved(series);
117 m_seriesList.removeAll(series);
117 m_seriesList.removeAll(series);
118
118
119 series->setParent(0);
119 series->setParent(0);
120 series->d_ptr->m_chart = 0;
120 series->d_ptr->m_chart = 0;
121 series->d_ptr->m_domain.reset(0);
121 series->d_ptr->m_domain.reset(0);
122
122
123 QList<QAbstractAxis*> axes = series->d_ptr->m_axes;
123 QList<QAbstractAxis*> axes = series->d_ptr->m_axes;
124
124
125 foreach(QAbstractAxis* axis, axes) {
125 foreach(QAbstractAxis* axis, axes) {
126 axis->d_ptr->m_series.removeAll(series);
126 axis->d_ptr->m_series.removeAll(series);
127 series->d_ptr->m_axes.removeAll(axis);
127 series->d_ptr->m_axes.removeAll(axis);
128 }
128 }
129
129
130 }
130 }
131
131
132 /*
132 /*
133 * This method removes axis form chartdataset, series ownership is passed back to caller.
133 * This method removes axis form chartdataset, series ownership is passed back to caller.
134 */
134 */
135 void ChartDataSet::removeAxis(QAbstractAxis *axis)
135 void ChartDataSet::removeAxis(QAbstractAxis *axis)
136 {
136 {
137 if (! m_axisList.contains(axis)) {
137 if (! m_axisList.contains(axis)) {
138 qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart.");
138 qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart.");
139 return;
139 return;
140 }
140 }
141
141
142 emit axisRemoved(axis);
142 emit axisRemoved(axis);
143 m_axisList.removeAll(axis);
143 m_axisList.removeAll(axis);
144
144
145 axis->setParent(0);
145 axis->setParent(0);
146 axis->d_ptr->m_chart = 0;
146 axis->d_ptr->m_chart = 0;
147
147
148 QList<QAbstractSeries*> series = axis->d_ptr->m_series;
148 QList<QAbstractSeries*> series = axis->d_ptr->m_series;
149
149
150 foreach(QAbstractSeries* s, series) {
150 foreach(QAbstractSeries* s, series) {
151 s->d_ptr->m_axes.removeAll(axis);
151 s->d_ptr->m_axes.removeAll(axis);
152 axis->d_ptr->m_series.removeAll(s);
152 axis->d_ptr->m_series.removeAll(s);
153 }
153 }
154 }
154 }
155
155
156 /*
156 /*
157 * This method attaches axis to series, return true if success.
157 * This method attaches axis to series, return true if success.
158 */
158 */
159 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
159 bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis)
160 {
160 {
161 Q_ASSERT(series);
161 Q_ASSERT(series);
162 Q_ASSERT(axis);
162 Q_ASSERT(axis);
163
163
164 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
164 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
165 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
165 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
166
166
167 if (!m_seriesList.contains(series)) {
167 if (!m_seriesList.contains(series)) {
168 qWarning() << QObject::tr("Can not find series on the chart.");
168 qWarning() << QObject::tr("Can not find series on the chart.");
169 return false;
169 return false;
170 }
170 }
171
171
172 if (axis && !m_axisList.contains(axis)) {
172 if (axis && !m_axisList.contains(axis)) {
173 qWarning() << QObject::tr("Can not find axis on the chart.");
173 qWarning() << QObject::tr("Can not find axis on the chart.");
174 return false;
174 return false;
175 }
175 }
176
176
177 if (attachedAxisList.contains(axis)) {
177 if (attachedAxisList.contains(axis)) {
178 qWarning() << QObject::tr("Axis already attached to series.");
178 qWarning() << QObject::tr("Axis already attached to series.");
179 return false;
179 return false;
180 }
180 }
181
181
182 if (attachedSeriesList.contains(series)) {
182 if (attachedSeriesList.contains(series)) {
183 qWarning() << QObject::tr("Axis already attached to series.");
183 qWarning() << QObject::tr("Axis already attached to series.");
184 return false;
184 return false;
185 }
185 }
186
186
187 AbstractDomain* domain = series->d_ptr->domain();
187 AbstractDomain* domain = series->d_ptr->domain();
188 AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis);
188 AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis);
189
189
190 if(type == AbstractDomain::UndefinedDomain) return false;
190 if(type == AbstractDomain::UndefinedDomain) return false;
191
191
192
192
193 if(domain->type()!=type){
193 if(domain->type()!=type){
194 domain = createDomain(type);
194 domain = createDomain(type);
195 }
195 }
196
196
197 if(!domain) return false;
197 if(!domain) return false;
198
198
199 if(!domain->attachAxis(axis)) return false;
199 if(!domain->attachAxis(axis)) return false;
200
200
201 series->d_ptr->m_axes<<axis;
201 series->d_ptr->m_axes<<axis;
202 axis->d_ptr->m_series<<series;
202 axis->d_ptr->m_series<<series;
203
203
204 series->d_ptr->setDomain(domain);
204 series->d_ptr->setDomain(domain);
205 series->d_ptr->initializeDomain();
205 series->d_ptr->initializeDomain();
206 series->d_ptr->initializeAxes();
206 series->d_ptr->initializeAxes();
207 axis->d_ptr->initializeDomain(domain);
207 axis->d_ptr->initializeDomain(domain);
208
208
209 return true;
209 return true;
210 }
210 }
211
211
212 /*
212 /*
213 * This method detaches axis to series, return true if success.
213 * This method detaches axis to series, return true if success.
214 */
214 */
215 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis)
215 bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis)
216 {
216 {
217 Q_ASSERT(series);
217 Q_ASSERT(series);
218 Q_ASSERT(axis);
218 Q_ASSERT(axis);
219
219
220 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
220 QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series;
221 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
221 QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes;
222 AbstractDomain* domain = series->d_ptr->domain();
222 AbstractDomain* domain = series->d_ptr->domain();
223
223
224 if (!m_seriesList.contains(series)) {
224 if (!m_seriesList.contains(series)) {
225 qWarning() << QObject::tr("Can not find series on the chart.");
225 qWarning() << QObject::tr("Can not find series on the chart.");
226 return false;
226 return false;
227 }
227 }
228
228
229 if (axis && !m_axisList.contains(axis)) {
229 if (axis && !m_axisList.contains(axis)) {
230 qWarning() << QObject::tr("Can not find axis on the chart.");
230 qWarning() << QObject::tr("Can not find axis on the chart.");
231 return false;
231 return false;
232 }
232 }
233
233
234 if (!attachedAxisList.contains(axis)) {
234 if (!attachedAxisList.contains(axis)) {
235 qWarning() << QObject::tr("Axis not attached to series.");
235 qWarning() << QObject::tr("Axis not attached to series.");
236 return false;
236 return false;
237 }
237 }
238
238
239 Q_ASSERT(axis->d_ptr->m_series.contains(series));
239 Q_ASSERT(axis->d_ptr->m_series.contains(series));
240
240
241 domain->detachAxis(axis);
241 domain->detachAxis(axis);
242 series->d_ptr->m_axes.removeAll(axis);
242 series->d_ptr->m_axes.removeAll(axis);
243 axis->d_ptr->m_series.removeAll(series);
243 axis->d_ptr->m_series.removeAll(series);
244
244
245 return true;
245 return true;
246 }
246 }
247
247
248 void ChartDataSet::createDefaultAxes()
248 void ChartDataSet::createDefaultAxes()
249 {
249 {
250 if (m_seriesList.isEmpty())
250 if (m_seriesList.isEmpty())
251 return;
251 return;
252
252
253 QAbstractAxis::AxisTypes typeX(0);
253 QAbstractAxis::AxisTypes typeX(0);
254 QAbstractAxis::AxisTypes typeY(0);
254 QAbstractAxis::AxisTypes typeY(0);
255
255
256 // Remove possibly existing axes
256 // Remove possibly existing axes
257 deleteAllAxes();
257 deleteAllAxes();
258
258
259 Q_ASSERT(m_axisList.isEmpty());
259 Q_ASSERT(m_axisList.isEmpty());
260
260
261 // Select the required axis x and axis y types based on the types of the current series
261 // Select the required axis x and axis y types based on the types of the current series
262 foreach(QAbstractSeries* s, m_seriesList) {
262 foreach(QAbstractSeries* s, m_seriesList) {
263 typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal);
263 typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal);
264 typeY |= s->d_ptr->defaultAxisType(Qt::Vertical);
264 typeY |= s->d_ptr->defaultAxisType(Qt::Vertical);
265 }
265 }
266
266
267 // Create the axes of the types selected
267 // Create the axes of the types selected
268 createAxes(typeX, Qt::Horizontal);
268 createAxes(typeX, Qt::Horizontal);
269 createAxes(typeY, Qt::Vertical);
269 createAxes(typeY, Qt::Vertical);
270
270
271 }
271 }
272
272
273 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation)
273 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation)
274 {
274 {
275 QAbstractAxis *axis = 0;
275 QAbstractAxis *axis = 0;
276 //decide what axis should be created
276 //decide what axis should be created
277
277
278 switch (type) {
278 switch (type) {
279 case QAbstractAxis::AxisTypeValue:
279 case QAbstractAxis::AxisTypeValue:
280 axis = new QValueAxis(this);
280 axis = new QValueAxis(this);
281 break;
281 break;
282 case QAbstractAxis::AxisTypeBarCategory:
282 case QAbstractAxis::AxisTypeBarCategory:
283 axis = new QBarCategoryAxis(this);
283 axis = new QBarCategoryAxis(this);
284 break;
284 break;
285 case QAbstractAxis::AxisTypeCategory:
285 case QAbstractAxis::AxisTypeCategory:
286 axis = new QCategoryAxis(this);
286 axis = new QCategoryAxis(this);
287 break;
287 break;
288 #ifndef Q_WS_QWS
288 #ifndef Q_WS_QWS
289 case QAbstractAxis::AxisTypeDateTime:
289 case QAbstractAxis::AxisTypeDateTime:
290 axis = new QDateTimeAxis(this);
290 axis = new QDateTimeAxis(this);
291 break;
291 break;
292 #endif
292 #endif
293 default:
293 default:
294 axis = 0;
294 axis = 0;
295 break;
295 break;
296 }
296 }
297
297
298 if (axis) {
298 if (axis) {
299 //create one axis for all
299 //create one axis for all
300
300
301 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
301 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
302
302
303 foreach(QAbstractSeries *s, m_seriesList) {
303 foreach(QAbstractSeries *s, m_seriesList) {
304 attachAxis(s,axis);
304 attachAxis(s,axis);
305 }
305 }
306
306
307 }
307 }
308 else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
308 else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
309 //create separate axis
309 //create separate axis
310 foreach(QAbstractSeries *s, m_seriesList) {
310 foreach(QAbstractSeries *s, m_seriesList) {
311 QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation);
311 QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation);
312 if(axis) {
312 if(axis) {
313 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
313 addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft);
314 attachAxis(s,axis);
314 attachAxis(s,axis);
315 }
315 }
316 }
316 }
317 }
317 }
318 }
318 }
319
319
320 void ChartDataSet::deleteAllSeries()
320 void ChartDataSet::deleteAllSeries()
321 {
321 {
322 foreach (QAbstractSeries *s , m_seriesList){
322 foreach (QAbstractSeries *s , m_seriesList){
323 removeSeries(s);
323 removeSeries(s);
324 delete s;
324 delete s;
325 }
325 }
326 Q_ASSERT(m_seriesList.count() == 0);
326 Q_ASSERT(m_seriesList.count() == 0);
327 }
327 }
328
328
329 void ChartDataSet::deleteAllAxes()
329 void ChartDataSet::deleteAllAxes()
330 {
330 {
331 foreach (QAbstractAxis *a , m_axisList){
331 foreach (QAbstractAxis *a , m_axisList){
332 removeAxis(a);
332 removeAxis(a);
333 delete a;
333 delete a;
334 }
334 }
335 Q_ASSERT(m_axisList.count() == 0);
335 Q_ASSERT(m_axisList.count() == 0);
336 }
336 }
337
337
338 void ChartDataSet::zoomInDomain(const QRectF &rect)
338 void ChartDataSet::zoomInDomain(const QRectF &rect)
339 {
339 {
340 QList<AbstractDomain*> domains;
340 QList<AbstractDomain*> domains;
341 foreach(QAbstractSeries *s, m_seriesList) {
341 foreach(QAbstractSeries *s, m_seriesList) {
342 AbstractDomain* domain = s->d_ptr->domain();
342 AbstractDomain* domain = s->d_ptr->domain();
343 s->d_ptr->m_domain->blockAxisSignals(true);
343 s->d_ptr->m_domain->blockAxisSignals(true);
344 domains<<domain;
344 domains<<domain;
345 }
345 }
346
346
347 foreach(AbstractDomain *domain, domains)
347 foreach(AbstractDomain *domain, domains)
348 domain->zoomIn(rect);
348 domain->zoomIn(rect);
349
349
350 foreach(AbstractDomain *domain, domains)
350 foreach(AbstractDomain *domain, domains)
351 domain->blockAxisSignals(false);
351 domain->blockAxisSignals(false);
352 }
352 }
353
353
354 void ChartDataSet::zoomOutDomain(const QRectF &rect)
354 void ChartDataSet::zoomOutDomain(const QRectF &rect)
355 {
355 {
356 QList<AbstractDomain*> domains;
356 QList<AbstractDomain*> domains;
357 foreach(QAbstractSeries *s, m_seriesList) {
357 foreach(QAbstractSeries *s, m_seriesList) {
358 AbstractDomain* domain = s->d_ptr->domain();
358 AbstractDomain* domain = s->d_ptr->domain();
359 s->d_ptr->m_domain->blockAxisSignals(true);
359 s->d_ptr->m_domain->blockAxisSignals(true);
360 domains<<domain;
360 domains<<domain;
361 }
361 }
362
362
363 foreach(AbstractDomain *domain, domains)
363 foreach(AbstractDomain *domain, domains)
364 domain->zoomOut(rect);
364 domain->zoomOut(rect);
365
365
366 foreach(AbstractDomain *domain, domains)
366 foreach(AbstractDomain *domain, domains)
367 domain->blockAxisSignals(false);
367 domain->blockAxisSignals(false);
368 }
368 }
369
369
370 void ChartDataSet::scrollDomain(qreal dx, qreal dy)
370 void ChartDataSet::scrollDomain(qreal dx, qreal dy)
371 {
371 {
372 QList<AbstractDomain*> domains;
372 QList<AbstractDomain*> domains;
373 foreach(QAbstractSeries *s, m_seriesList) {
373 foreach(QAbstractSeries *s, m_seriesList) {
374 AbstractDomain* domain = s->d_ptr->m_domain.data();
374 AbstractDomain* domain = s->d_ptr->m_domain.data();
375 if(domains.contains(domain)) continue;
375 if(domains.contains(domain)) continue;
376 s->d_ptr->m_domain->blockAxisSignals(true);
376 s->d_ptr->m_domain->blockAxisSignals(true);
377 domains<<domain;
377 domains<<domain;
378 }
378 }
379
379
380 foreach(AbstractDomain *domain, domains)
380 foreach(AbstractDomain *domain, domains)
381 domain->move(dx, dy);
381 domain->move(dx, dy);
382
382
383 foreach(AbstractDomain *domain, domains)
383 foreach(AbstractDomain *domain, domains)
384 domain->blockAxisSignals(false);
384 domain->blockAxisSignals(false);
385 }
385 }
386
386
387 QList<QAbstractAxis*> ChartDataSet::axes() const
387 QList<QAbstractAxis*> ChartDataSet::axes() const
388 {
388 {
389 return m_axisList;
389 return m_axisList;
390 }
390 }
391
391
392 QList<QAbstractSeries *> ChartDataSet::series() const
392 QList<QAbstractSeries *> ChartDataSet::series() const
393 {
393 {
394 return m_seriesList;
394 return m_seriesList;
395 }
395 }
396
396
397 AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes)
397 AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes)
398 {
398 {
399 enum Type {
399 enum Type {
400 LogType = 0x1,
400 LogType = 0x1,
401 ValueType = 0x2
401 ValueType = 0x2
402 };
402 };
403
403
404 int horizontal(ValueType);
404 int horizontal(ValueType);
405 int vertical(ValueType);
405 int vertical(ValueType);
406
406
407 foreach(QAbstractAxis* axis, axes)
407 foreach(QAbstractAxis* axis, axes)
408 {
408 {
409 switch(axis->type()) {
409 switch(axis->type()) {
410 case QAbstractAxis::AxisTypeLogValue:
410 case QAbstractAxis::AxisTypeLogValue:
411 axis->orientation()==Qt::Horizontal?horizontal:vertical|=LogType;
411 axis->orientation()==Qt::Horizontal?horizontal:vertical|=LogType;
412 break;
412 break;
413 case QAbstractAxis::AxisTypeValue:
413 case QAbstractAxis::AxisTypeValue:
414 case QAbstractAxis::AxisTypeBarCategory:
414 case QAbstractAxis::AxisTypeBarCategory:
415 case QAbstractAxis::AxisTypeCategory:
415 case QAbstractAxis::AxisTypeCategory:
416 case QAbstractAxis::AxisTypeDateTime:
416 case QAbstractAxis::AxisTypeDateTime:
417 axis->orientation()==Qt::Horizontal?horizontal:vertical|=ValueType;
417 axis->orientation()==Qt::Horizontal?horizontal:vertical|=ValueType;
418 break;
418 break;
419 default:
419 default:
420 qWarning()<<"Undefined type";
420 qWarning()<<"Undefined type";
421 break;
421 break;
422 }
422 }
423 }
423 }
424
424
425 if(vertical==ValueType && horizontal== ValueType) {
425 if(vertical==ValueType && horizontal== ValueType) {
426 return AbstractDomain::XYDomain;
426 return AbstractDomain::XYDomain;
427 }
427 }
428
428
429 if(vertical==LogType && horizontal== ValueType) {
429 if(vertical==LogType && horizontal== ValueType) {
430 return AbstractDomain::XLogYDomain;
430 return AbstractDomain::XLogYDomain;
431 }
431 }
432
432
433 if(vertical==ValueType && horizontal== LogType) {
433 if(vertical==ValueType && horizontal== LogType) {
434 return AbstractDomain::LogXYDomain;
434 return AbstractDomain::LogXYDomain;
435 }
435 }
436
436
437 if(vertical==LogType && horizontal== LogType) {
437 if(vertical==LogType && horizontal== LogType) {
438 return AbstractDomain::XLogYLogDomain;
438 return AbstractDomain::LogXLogYDomain;
439 }
439 }
440
440
441 return AbstractDomain::UndefinedDomain;
441 return AbstractDomain::UndefinedDomain;
442 }
442 }
443
443
444
444
445 //refactor create factory
445 //refactor create factory
446 AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type)
446 AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type)
447 {
447 {
448 switch(type)
448 switch(type)
449 {
449 {
450 case AbstractDomain::XLogYLogDomain:
450 case AbstractDomain::LogXLogYDomain:
451 return 0;
451 return new LogXLogYDomain();
452 case AbstractDomain::XYDomain:
452 case AbstractDomain::XYDomain:
453 return new XYDomain();
453 return new XYDomain();
454 case AbstractDomain::XLogYDomain:
454 case AbstractDomain::XLogYDomain:
455 return 0;
455 return new XLogYDomain();
456 case AbstractDomain::LogXYDomain:
456 case AbstractDomain::LogXYDomain:
457 return 0;
457 return new LogXYDomain();
458 default:
458 default:
459 return 0;
459 return 0;
460 }
460 }
461 }
461 }
462
462
463 #include "moc_chartdataset_p.cpp"
463 #include "moc_chartdataset_p.cpp"
464
464
465 QTCOMMERCIALCHART_END_NAMESPACE
465 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,72
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 LOGXLOGYDOMAIN_H
30 #ifndef LOGXLOGYDOMAIN_H
31 #define LOGXLOGYDOMAIN_H
31 #define LOGXLOGYDOMAIN_H
32 #include "abstractdomain_p.h"
32 #include "abstractdomain_p.h"
33 #include <QRectF>
33 #include <QRectF>
34 #include <QSizeF>
34 #include <QSizeF>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT LogXLogYDomain: public AbstractDomain
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT LogXLogYDomain: public AbstractDomain
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 explicit LogXLogYDomain(QObject *object = 0);
42 explicit LogXLogYDomain(QObject *object = 0);
43 virtual ~LogXLogYDomain();
43 virtual ~LogXLogYDomain();
44
44
45 DomainType type(){ return AbstractDomain::XLogYLogDomain;}
45 DomainType type(){ return AbstractDomain::LogXLogYDomain;}
46
46
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48
48
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2);
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const LogXLogYDomain &domain1, const LogXLogYDomain &domain2);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const LogXLogYDomain &domain);
52
52
53 void zoomIn(const QRectF &rect);
53 void zoomIn(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
55 void move(qreal dx, qreal dy);
55 void move(qreal dx, qreal dy);
56
56
57 QPointF calculateGeometryPoint(const QPointF &point) const;
57 QPointF calculateGeometryPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
60
60
61 private:
61 private:
62 qreal m_logMinX;
62 qreal m_logMinX;
63 qreal m_logMaxX;
63 qreal m_logMaxX;
64 qreal m_logBaseX;
64 qreal m_logBaseX;
65 qreal m_logMinY;
65 qreal m_logMinY;
66 qreal m_logMaxY;
66 qreal m_logMaxY;
67 qreal m_logBaseY;
67 qreal m_logBaseY;
68 };
68 };
69
69
70 QTCOMMERCIALCHART_END_NAMESPACE
70 QTCOMMERCIALCHART_END_NAMESPACE
71
71
72 #endif // LOGXLOGYDOMAIN_H
72 #endif // LOGXLOGYDOMAIN_H
@@ -1,69 +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 XLOGYDOMAIN_H
30 #ifndef XLOGYDOMAIN_H
31 #define XLOGYDOMAIN_H
31 #define XLOGYDOMAIN_H
32 #include "abstractdomain_p.h"
32 #include "abstractdomain_p.h"
33 #include <QRectF>
33 #include <QRectF>
34 #include <QSizeF>
34 #include <QSizeF>
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT XLogYDomain: public AbstractDomain
38 class QTCOMMERCIALCHART_AUTOTEST_EXPORT XLogYDomain: public AbstractDomain
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 explicit XLogYDomain(QObject *object = 0);
42 explicit XLogYDomain(QObject *object = 0);
43 virtual ~XLogYDomain();
43 virtual ~XLogYDomain();
44
44
45 DomainType type(){ return AbstractDomain::XLogYDomain;}
45 DomainType type(){ return AbstractDomain::XLogYDomain;};
46
46
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
47 void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY);
48
48
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2);
49 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator== (const XLogYDomain &domain1, const XLogYDomain &domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2);
50 friend bool QTCOMMERCIALCHART_AUTOTEST_EXPORT operator!= (const XLogYDomain &domain1, const XLogYDomain &domain2);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain);
51 friend QDebug QTCOMMERCIALCHART_AUTOTEST_EXPORT operator<<(QDebug dbg, const XLogYDomain &domain);
52
52
53 void zoomIn(const QRectF &rect);
53 void zoomIn(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
54 void zoomOut(const QRectF &rect);
55 void move(qreal dx, qreal dy);
55 void move(qreal dx, qreal dy);
56
56
57 QPointF calculateGeometryPoint(const QPointF &point) const;
57 QPointF calculateGeometryPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
58 QPointF calculateDomainPoint(const QPointF &point) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
59 QVector<QPointF> calculateGeometryPoints(const QList<QPointF>& vector) const;
60
60
61 private:
61 private:
62 qreal m_logMinY;
62 qreal m_logMinY;
63 qreal m_logMaxY;
63 qreal m_logMaxY;
64 qreal m_logBaseY;
64 qreal m_logBaseY;
65 };
65 };
66
66
67 QTCOMMERCIALCHART_END_NAMESPACE
67 QTCOMMERCIALCHART_END_NAMESPACE
68
68
69 #endif // XLOGYDOMAIN_H
69 #endif // XLOGYDOMAIN_H
General Comments 0
You need to be logged in to leave comments. Login now