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