@@ -39,14 +39,15 Rectangle { | |||
|
39 | 39 | // If you have static data, you can simply use the PieSlice API |
|
40 | 40 | PieSeries { |
|
41 | 41 | id: pieSeries |
|
42 | PieSlice { label: "Volkswagen"; value: 13.5 } | |
|
42 | PieSlice { id: volkswagenSlice; label: "Volkswagen"; value: 13.5 } | |
|
43 | 43 | PieSlice { label: "Toyota"; value: 10.9 } |
|
44 | 44 | PieSlice { label: "Ford"; value: 8.6 } |
|
45 | 45 | PieSlice { label: "Skoda"; value: 8.2 } |
|
46 | 46 | PieSlice { label: "Volvo"; value: 6.8 } |
|
47 | 47 | } |
|
48 | 48 | |
|
49 | // For dynamic data you can use the ChartModel API. | |
|
49 | // TODO: move ChartModel API into a demo application instead of making it a public API | |
|
50 | // // For dynamic data you can use the ChartModel API. | |
|
50 | 51 |
|
|
51 | 52 | // id: chartModel |
|
52 | 53 | // ChartModelRow { values: ["Volkswagen", 13.5] } |
@@ -55,8 +56,7 Rectangle { | |||
|
55 | 56 | // ChartModelRow { values: ["Skoda", 8.2] } |
|
56 | 57 | // ChartModelRow { values: ["Volvo", 6.8] } |
|
57 | 58 | // } |
|
58 | ||
|
59 | // In this case you need to define how the data maps to pie slices with the ModelMapper API of the pie series. | |
|
59 | // // In this case you need to define how the data maps to pie slices with the ModelMapper API of the pie series. | |
|
60 | 60 | // PieSeries { |
|
61 | 61 | // id: pieSeries |
|
62 | 62 | // model: chartModel |
@@ -66,11 +66,15 Rectangle { | |||
|
66 | 66 | // modelMapper.count: -1 // "Undefined" = -1 by default |
|
67 | 67 | // modelMapper.orientation: PieModelMapper.Vertical |
|
68 | 68 | // } |
|
69 | ||
|
70 | // TODO: you could also append to your model, for example: | |
|
71 | // pieSeries.model.append(["Others", 52.0]); | |
|
69 | 72 | } |
|
70 | 73 | |
|
71 | 74 | Component.onCompleted: { |
|
72 | // You can also add data dynamically | |
|
73 | pieSeries.model.append(["Others", 52.0]); | |
|
75 | volkswagenSlice.exploded = true; | |
|
76 | // You can also add slices dynamically | |
|
77 | var newSlice = pieSeries.append("Others", 52.0); | |
|
74 | 78 | } |
|
75 | 79 | |
|
76 | 80 | Timer { |
@@ -80,11 +84,15 Rectangle { | |||
|
80 | 84 | onTriggered: { |
|
81 | 85 | // Set all slices as not exploded |
|
82 | 86 | for (var i = 0; i < pieSeries.count; i++) |
|
83 |
pieSeries. |
|
|
87 | pieSeries.at(i).exploded = false; | |
|
84 | 88 | |
|
85 | 89 | // Explode one of the slices |
|
86 | 90 | __explodedIndex = (__explodedIndex + 1) % pieSeries.count; |
|
87 |
pieSeries. |
|
|
91 | pieSeries.at(__explodedIndex).exploded = true; | |
|
92 | ||
|
93 | // TODO: implement for convenience | |
|
94 | // pieSeries.find("Ford").exploded = true; | |
|
95 | // pieSeries.removeAll("Ford") | |
|
88 | 96 | } |
|
89 | 97 | } |
|
90 | 98 | |
@@ -111,8 +119,6 Rectangle { | |||
|
111 | 119 | } else { |
|
112 | 120 | pieSeries.modelMapper.count = 5; |
|
113 | 121 | buttonText.text = "Show others"; |
|
114 | //pieModel.removeRow(pieModel.count - 1); | |
|
115 | // TODO: removeAll("label") ? | |
|
116 | 122 |
|
|
117 | 123 | } |
|
118 | 124 | } |
@@ -28,7 +28,6 Rectangle { | |||
|
28 | 28 | title: "NHL All-Star Team Players" |
|
29 | 29 | anchors.fill: parent |
|
30 | 30 | theme: ChartView.ChartThemeHighContrast |
|
31 | legend: ChartView.LegendTop | |
|
32 | 31 | axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005", |
|
33 | 32 | "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"] |
|
34 | 33 |
@@ -26,7 +26,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
26 | 26 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
27 | 27 | : QDeclarativeItem(parent), |
|
28 | 28 | m_chart(new QChart(this)), |
|
29 |
m_legend(Legend |
|
|
29 | m_legend(LegendTop) | |
|
30 | 30 | { |
|
31 | 31 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
32 | 32 | m_chart->axisX()->setNiceNumbersEnabled(false); |
@@ -30,9 +30,9 DeclarativePieSeries::DeclarativePieSeries(QObject *parent) : | |||
|
30 | 30 | QPieSeries(parent) |
|
31 | 31 | { |
|
32 | 32 | // TODO: set default model on init? |
|
33 | setModel(new DeclarativeTableModel()); | |
|
33 | // setModel(new DeclarativeTableModel()); | |
|
34 | 34 | |
|
35 | // 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 | 36 | QPieModelMapper *mapper = new QPieModelMapper(); |
|
37 | 37 | mapper->setMapLabels(0); |
|
38 | 38 | mapper->setMapValues(1); |
@@ -49,15 +49,8 void DeclarativePieSeries::classBegin() | |||
|
49 | 49 | void DeclarativePieSeries::componentComplete() |
|
50 | 50 | { |
|
51 | 51 | foreach(QObject *child, children()) { |
|
52 | qDebug() << "pie child: " << child; | |
|
53 | 52 | if (qobject_cast<QPieSlice *>(child)) { |
|
54 |
QPieS |
|
|
55 | QVariantList values; | |
|
56 | values.insert(modelMapper()->mapLabels(), slice->label()); | |
|
57 | values.insert(modelMapper()->mapValues(), slice->value()); | |
|
58 | DeclarativeTableModel *m = qobject_cast<DeclarativeTableModel *>(model()); | |
|
59 | Q_ASSERT(m); | |
|
60 | m->append(values); | |
|
53 | QPieSeries::append(qobject_cast<QPieSlice *>(child)); | |
|
61 | 54 | } |
|
62 | 55 | } |
|
63 | 56 | } |
@@ -67,7 +60,7 QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::initialSlices() | |||
|
67 | 60 | return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendInitialSlices); |
|
68 | 61 | } |
|
69 | 62 | |
|
70 |
QPieSlice *DeclarativePieSeries:: |
|
|
63 | QPieSlice *DeclarativePieSeries::at(int index) | |
|
71 | 64 | { |
|
72 | 65 | QList<QPieSlice*> sliceList = slices(); |
|
73 | 66 | if (index < sliceList.count()) |
@@ -76,6 +69,12 QPieSlice *DeclarativePieSeries::slice(int index) | |||
|
76 | 69 | return 0; |
|
77 | 70 | } |
|
78 | 71 | |
|
72 | QPieSlice* DeclarativePieSeries::append(QString name, qreal value) | |
|
73 | { | |
|
74 | // TODO: parameter order is wrong, switch it: | |
|
75 | return QPieSeries::append(value, name); | |
|
76 | } | |
|
77 | ||
|
79 | 78 | void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model) |
|
80 | 79 | { |
|
81 | 80 | QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model); |
@@ -47,7 +47,8 public: | |||
|
47 | 47 | QDeclarativeListProperty<QPieSlice> initialSlices(); |
|
48 | 48 | DeclarativeTableModel *pieModel(); |
|
49 | 49 | void setPieModel(DeclarativeTableModel *model); |
|
50 |
Q_INVOKABLE QPieSlice * |
|
|
50 | Q_INVOKABLE QPieSlice *at(int index); | |
|
51 | Q_INVOKABLE QPieSlice* append(QString name, qreal value); | |
|
51 | 52 | |
|
52 | 53 | public: |
|
53 | 54 | void classBegin(); |
General Comments 0
You need to be logged in to leave comments.
Login now