@@ -1,104 +1,104 | |||||
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 "declarativepieseries.h" |
|
21 | #include "declarativepieseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include <qdeclarativelist.h> |
|
24 | #include <qdeclarativelist.h> | |
25 | #include "qpiemodelmapper.h" |
|
25 | #include "qpiemodelmapper.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : |
|
29 | DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : | |
30 | QPieSeries(parent) |
|
30 | QPieSeries(parent) | |
31 | { |
|
31 | { | |
32 | // TODO: set default model on init? |
|
32 | // TODO: set default model on init? | |
33 | // setModel(new DeclarativeTableModel()); |
|
33 | // setModel(new DeclarativeTableModel()); | |
34 |
|
34 | |||
35 | // TODO: Set default mapper parameters to allow easy to use PieSeries api? |
|
35 | // TODO: Set default mapper parameters to allow easy to use PieSeries api? | |
36 | QPieModelMapper *mapper = modelMapper();//new QPieModelMapper(); |
|
36 | // QPieModelMapper *mapper = modelMapper();//new QPieModelMapper(); | |
37 | mapper->setMapLabels(0); |
|
37 | // mapper->setMapLabels(0); | |
38 | mapper->setMapValues(1); |
|
38 | // mapper->setMapValues(1); | |
39 | mapper->setOrientation(Qt::Vertical); |
|
39 | // mapper->setOrientation(Qt::Vertical); | |
40 | mapper->setFirst(0); |
|
40 | // mapper->setFirst(0); | |
41 | mapper->setCount(-1); |
|
41 | // mapper->setCount(-1); | |
42 | // setModelMapper(mapper); |
|
42 | // setModelMapper(mapper); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void DeclarativePieSeries::classBegin() |
|
45 | void DeclarativePieSeries::classBegin() | |
46 | { |
|
46 | { | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | void DeclarativePieSeries::componentComplete() |
|
49 | void DeclarativePieSeries::componentComplete() | |
50 | { |
|
50 | { | |
51 | foreach(QObject *child, children()) { |
|
51 | foreach(QObject *child, children()) { | |
52 | if (qobject_cast<QPieSlice *>(child)) { |
|
52 | if (qobject_cast<QPieSlice *>(child)) { | |
53 | QPieSeries::append(qobject_cast<QPieSlice *>(child)); |
|
53 | QPieSeries::append(qobject_cast<QPieSlice *>(child)); | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::initialSlices() |
|
58 | QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::initialSlices() | |
59 | { |
|
59 | { | |
60 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendInitialSlices); |
|
60 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendInitialSlices); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | QPieSlice *DeclarativePieSeries::at(int index) |
|
63 | QPieSlice *DeclarativePieSeries::at(int index) | |
64 | { |
|
64 | { | |
65 | QList<QPieSlice*> sliceList = slices(); |
|
65 | QList<QPieSlice*> sliceList = slices(); | |
66 | if (index < sliceList.count()) |
|
66 | if (index < sliceList.count()) | |
67 | return sliceList[index]; |
|
67 | return sliceList[index]; | |
68 |
|
68 | |||
69 | return 0; |
|
69 | return 0; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QPieSlice* DeclarativePieSeries::find(QString label) |
|
72 | QPieSlice* DeclarativePieSeries::find(QString label) | |
73 | { |
|
73 | { | |
74 | foreach (QPieSlice *slice, slices()) { |
|
74 | foreach (QPieSlice *slice, slices()) { | |
75 | if (slice->label() == label) |
|
75 | if (slice->label() == label) | |
76 | return slice; |
|
76 | return slice; | |
77 | } |
|
77 | } | |
78 | return 0; |
|
78 | return 0; | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 | QPieSlice* DeclarativePieSeries::append(QString name, qreal value) |
|
81 | QPieSlice* DeclarativePieSeries::append(QString name, qreal value) | |
82 | { |
|
82 | { | |
83 | // TODO: parameter order is wrong, switch it: |
|
83 | // TODO: parameter order is wrong, switch it: | |
84 | return QPieSeries::append(name, value); |
|
84 | return QPieSeries::append(name, value); | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) |
|
87 | void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) | |
88 | { |
|
88 | { | |
89 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
|
89 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); | |
90 | if (m) { |
|
90 | if (m) { | |
91 | QPieSeries::setModel(m); |
|
91 | QPieSeries::setModel(m); | |
92 | } else { |
|
92 | } else { | |
93 | qWarning("DeclarativePieSeries: Illegal model"); |
|
93 | qWarning("DeclarativePieSeries: Illegal model"); | |
94 | } |
|
94 | } | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | DeclarativeTableModel *DeclarativePieSeries::pieModel() |
|
97 | DeclarativeTableModel *DeclarativePieSeries::pieModel() | |
98 | { |
|
98 | { | |
99 | return qobject_cast<DeclarativeTableModel *>(model()); |
|
99 | return qobject_cast<DeclarativeTableModel *>(model()); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | #include "moc_declarativepieseries.cpp" |
|
102 | #include "moc_declarativepieseries.cpp" | |
103 |
|
103 | |||
104 | QTCOMMERCIALCHART_END_NAMESPACE |
|
104 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now