##// END OF EJS Templates
Removed usage of model in QML pie example
Tero Ahola -
r1189:88d7235253d9
parent child
Show More
@@ -39,14 +39,15 Rectangle {
39 // If you have static data, you can simply use the PieSlice API
39 // If you have static data, you can simply use the PieSlice API
40 PieSeries {
40 PieSeries {
41 id: pieSeries
41 id: pieSeries
42 PieSlice { label: "Volkswagen"; value: 13.5 }
42 PieSlice { id: volkswagenSlice; label: "Volkswagen"; value: 13.5 }
43 PieSlice { label: "Toyota"; value: 10.9 }
43 PieSlice { label: "Toyota"; value: 10.9 }
44 PieSlice { label: "Ford"; value: 8.6 }
44 PieSlice { label: "Ford"; value: 8.6 }
45 PieSlice { label: "Skoda"; value: 8.2 }
45 PieSlice { label: "Skoda"; value: 8.2 }
46 PieSlice { label: "Volvo"; value: 6.8 }
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 // ChartModel {
51 // ChartModel {
51 // id: chartModel
52 // id: chartModel
52 // ChartModelRow { values: ["Volkswagen", 13.5] }
53 // ChartModelRow { values: ["Volkswagen", 13.5] }
@@ -55,8 +56,7 Rectangle {
55 // ChartModelRow { values: ["Skoda", 8.2] }
56 // ChartModelRow { values: ["Skoda", 8.2] }
56 // ChartModelRow { values: ["Volvo", 6.8] }
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 // PieSeries {
60 // PieSeries {
61 // id: pieSeries
61 // id: pieSeries
62 // model: chartModel
62 // model: chartModel
@@ -66,11 +66,15 Rectangle {
66 // modelMapper.count: -1 // "Undefined" = -1 by default
66 // modelMapper.count: -1 // "Undefined" = -1 by default
67 // modelMapper.orientation: PieModelMapper.Vertical
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 Component.onCompleted: {
74 Component.onCompleted: {
72 // You can also add data dynamically
75 volkswagenSlice.exploded = true;
73 pieSeries.model.append(["Others", 52.0]);
76 // You can also add slices dynamically
77 var newSlice = pieSeries.append("Others", 52.0);
74 }
78 }
75
79
76 Timer {
80 Timer {
@@ -80,11 +84,15 Rectangle {
80 onTriggered: {
84 onTriggered: {
81 // Set all slices as not exploded
85 // Set all slices as not exploded
82 for (var i = 0; i < pieSeries.count; i++)
86 for (var i = 0; i < pieSeries.count; i++)
83 pieSeries.slice(i).exploded = false;
87 pieSeries.at(i).exploded = false;
84
88
85 // Explode one of the slices
89 // Explode one of the slices
86 __explodedIndex = (__explodedIndex + 1) % pieSeries.count;
90 __explodedIndex = (__explodedIndex + 1) % pieSeries.count;
87 pieSeries.slice(__explodedIndex).exploded = true;
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 } else {
119 } else {
112 pieSeries.modelMapper.count = 5;
120 pieSeries.modelMapper.count = 5;
113 buttonText.text = "Show others";
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 title: "NHL All-Star Team Players"
28 title: "NHL All-Star Team Players"
29 anchors.fill: parent
29 anchors.fill: parent
30 theme: ChartView.ChartThemeHighContrast
30 theme: ChartView.ChartThemeHighContrast
31 legend: ChartView.LegendTop
32 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
31 axisXLabels: ["0", "2000", "1", "2001", "2", "2002", "3", "2003", "4", "2004", "5", "2005",
33 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
32 "6", "2006", "7", "2007", "8", "2008", "9", "2009", "10", "2010", "11", "2011"]
34
33
@@ -26,7 +26,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
27 : QDeclarativeItem(parent),
27 : QDeclarativeItem(parent),
28 m_chart(new QChart(this)),
28 m_chart(new QChart(this)),
29 m_legend(LegendDisabled)
29 m_legend(LegendTop)
30 {
30 {
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 m_chart->axisX()->setNiceNumbersEnabled(false);
32 m_chart->axisX()->setNiceNumbersEnabled(false);
@@ -30,9 +30,9 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 // 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 = new QPieModelMapper();
36 QPieModelMapper *mapper = new QPieModelMapper();
37 mapper->setMapLabels(0);
37 mapper->setMapLabels(0);
38 mapper->setMapValues(1);
38 mapper->setMapValues(1);
@@ -49,15 +49,8 void DeclarativePieSeries::classBegin()
49 void DeclarativePieSeries::componentComplete()
49 void DeclarativePieSeries::componentComplete()
50 {
50 {
51 foreach(QObject *child, children()) {
51 foreach(QObject *child, children()) {
52 qDebug() << "pie child: " << child;
53 if (qobject_cast<QPieSlice *>(child)) {
52 if (qobject_cast<QPieSlice *>(child)) {
54 QPieSlice *slice = qobject_cast<QPieSlice *>(child);
53 QPieSeries::append(qobject_cast<QPieSlice *>(child));
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);
61 }
54 }
62 }
55 }
63 }
56 }
@@ -67,7 +60,7 QDeclarativeListProperty<QPieSlice> DeclarativePieSeries::initialSlices()
67 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendInitialSlices);
60 return QDeclarativeListProperty<QPieSlice>(this, 0, &DeclarativePieSeries::appendInitialSlices);
68 }
61 }
69
62
70 QPieSlice *DeclarativePieSeries::slice(int index)
63 QPieSlice *DeclarativePieSeries::at(int index)
71 {
64 {
72 QList<QPieSlice*> sliceList = slices();
65 QList<QPieSlice*> sliceList = slices();
73 if (index < sliceList.count())
66 if (index < sliceList.count())
@@ -76,6 +69,12 QPieSlice *DeclarativePieSeries::slice(int index)
76 return 0;
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 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model)
78 void DeclarativePieSeries::setPieModel(DeclarativeTableModel *model)
80 {
79 {
81 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
80 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
@@ -47,7 +47,8 public:
47 QDeclarativeListProperty<QPieSlice> initialSlices();
47 QDeclarativeListProperty<QPieSlice> initialSlices();
48 DeclarativeTableModel *pieModel();
48 DeclarativeTableModel *pieModel();
49 void setPieModel(DeclarativeTableModel *model);
49 void setPieModel(DeclarativeTableModel *model);
50 Q_INVOKABLE QPieSlice *slice(int index);
50 Q_INVOKABLE QPieSlice *at(int index);
51 Q_INVOKABLE QPieSlice* append(QString name, qreal value);
51
52
52 public:
53 public:
53 void classBegin();
54 void classBegin();
General Comments 0
You need to be logged in to leave comments. Login now