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