##// END OF EJS Templates
QML BarSeries API to support BarSet children
Tero Ahola -
r1193:62e3aa7546c6
parent child
Show More
@@ -34,44 +34,25 Rectangle {
34
34
35 BarSeries {
35 BarSeries {
36 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
36 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
37 model: barModel
37 BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] }
38 BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] }
39 BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] }
38 }
40 }
39
41
40 // // TODO: optional syntax with ChartModel base model API
42 // TODO: optional syntax with ChartModel base model API
41 // BarSeries {
43 // BarSeries {
42 // model: chartModel
44 // model: chartModel
43 // modelMapping: BarSeriesMapping {
45 // modelMapping: BarSeriesMapping {
44 // // Giving "undefined" x mapping value means that the indexes are used as x-values
46 // ?
45 // setIndexes: [BarSeriesMapping.Undefined, 0,
46 // BarSeriesMapping.Undefined, 1,
47 // BarSeriesMapping.Undefined, 2] // defaults to []
48 //// setValues: [
49 //// BarSetMapping {x: BarSetMapping.Undefined; y: 0},
50 //// BarSetMapping {x: BarSetMapping.Undefined; y: 1},
51 //// BarSetMapping {x: BarSetMapping.Undefined; y: 2}
52 //// ]
53 // orientation: BarSeriesMapping.Vertical // defaults to Vertical
54 // startIndex: 0 // defaults to 0
47 // startIndex: 0 // defaults to 0
55 // count: BarSeriesMapping.Undefined // defaults to "Undefined"
48 // count: BarSeriesMapping.Undefined // defaults to "Undefined"
56 // }
49 // }
57 // }
50 // }
58 }
59
60 // ChartModel {
51 // ChartModel {
61 // id: chartModel
52 // id: chartModel
53 // ChartModelElement { values: ["Bob", 2, 2, 3, 4, 5, 6] }
54 // ChartModelElement { values: ["Susan", 5, 1, 2, 4, 1, 7] }
55 // ChartModelElement { values: ["James", 3, 5, 8, 13, 5, 8] }
62 // }
56 // }
63
64 BarModel {
65 id: barModel
66 BarSet { name: "Bob"; values: [2, 2, 3, 4, 5, 6] }
67 BarSet { name: "Susan"; values: [5, 1, 2, 4, 1, 7] }
68 BarSet { name: "James"; values: [3, 5, 8, 13, 5, 8] }
69 }
57 }
70
71 // TODO
72 // Component.onCompleted: {
73 // bobBars.append(1.2);
74 // bobBars.append(1.5);
75 // bobBars.append([1.5, 1.4, 1.9]);
76 // }
77 }
58 }
@@ -49,7 +49,7 void DeclarativeBarSet::setValues(QVariantList values)
49 }
49 }
50
50
51 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
51 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
52 QBarSeries(parent)
52 QGroupedBarSeries(parent)
53 {
53 {
54 }
54 }
55
55
@@ -59,11 +59,20 void DeclarativeBarSeries::classBegin()
59
59
60 void DeclarativeBarSeries::componentComplete()
60 void DeclarativeBarSeries::componentComplete()
61 {
61 {
62 // if (model())
62 foreach(QObject *child, children()) {
63 // setModelMapping(0, 1, 1, Qt::Vertical);
63 if (qobject_cast<QBarSet *>(child)) {
64 qDebug() << "append bar set:" << child;
65 QBarSeries::appendBarSet(qobject_cast<QBarSet *>(child));
66 }
67 }
68 }
69
70 QDeclarativeListProperty<DeclarativeBarSet> DeclarativeBarSeries::initialBarSets()
71 {
72 return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeBarSeries::appendInitialBarSets);
64 }
73 }
65
74
66 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeBarModel *model)
75 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeTableModel *model)
67 {
76 {
68 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
77 QAbstractItemModel *m = qobject_cast<QAbstractItemModel *>(model);
69 bool value(false);
78 bool value(false);
@@ -77,9 +86,9 bool DeclarativeBarSeries::setDeclarativeModel(DeclarativeBarModel *model)
77 return value;
86 return value;
78 }
87 }
79
88
80 DeclarativeBarModel *DeclarativeBarSeries::declarativeModel()
89 DeclarativeTableModel *DeclarativeBarSeries::declarativeModel()
81 {
90 {
82 return qobject_cast<DeclarativeBarModel *>(model());
91 return qobject_cast<DeclarativeTableModel *>(model());
83 }
92 }
84
93
85 void DeclarativeBarSeries::setBarCategories(QStringList categories)
94 void DeclarativeBarSeries::setBarCategories(QStringList categories)
@@ -25,12 +25,11
25 #include "declarativemodel.h"
25 #include "declarativemodel.h"
26 #include <QDeclarativeItem>
26 #include <QDeclarativeItem>
27 #include <QDeclarativeParserStatus>
27 #include <QDeclarativeParserStatus>
28 #include <QBarSeries>
28 #include <QGroupedBarSeries>
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 class QChart;
32 class QChart;
33 class QBarSeries;
34
33
35 class DeclarativeBarSet : public QBarSet
34 class DeclarativeBarSet : public QBarSet
36 {
35 {
@@ -44,31 +43,31 public:
44 void setValues(QVariantList values);
43 void setValues(QVariantList values);
45 };
44 };
46
45
47 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
46 class DeclarativeBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus
48 {
47 {
49 Q_OBJECT
48 Q_OBJECT
50 Q_INTERFACES(QDeclarativeParserStatus)
49 Q_INTERFACES(QDeclarativeParserStatus)
51 Q_PROPERTY(DeclarativeBarModel *model READ declarativeModel WRITE setDeclarativeModel)
50 Q_PROPERTY(DeclarativeTableModel *model READ declarativeModel WRITE setDeclarativeModel)
52 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
51 Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories)
52 Q_PROPERTY(QDeclarativeListProperty<DeclarativeBarSet> initialBarSets READ initialBarSets)
53 Q_CLASSINFO("DefaultProperty", "initialBarSets")
53
54
54 public:
55 public:
55 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
56 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
57 QDeclarativeListProperty<DeclarativeBarSet> initialBarSets();
56
58
57 public: // from QDeclarativeParserStatus
59 public: // from QDeclarativeParserStatus
58 void classBegin();
60 void classBegin();
59 void componentComplete();
61 void componentComplete();
60
62
61 public:
63 public:
62 bool setDeclarativeModel(DeclarativeBarModel *model);
64 bool setDeclarativeModel(DeclarativeTableModel *model);
63 DeclarativeBarModel *declarativeModel();
65 DeclarativeTableModel *declarativeModel();
64 void setBarCategories(QStringList categories);
66 void setBarCategories(QStringList categories);
65 QStringList barCategories();
67 QStringList barCategories();
66
68
67 Q_SIGNALS:
68
69 public Q_SLOTS:
69 public Q_SLOTS:
70
70 static void appendInitialBarSets(QDeclarativeListProperty<DeclarativeBarSet> */*list*/, DeclarativeBarSet */*element*/) {}
71 public:
72 };
71 };
73
72
74 QTCOMMERCIALCHART_END_NAMESPACE
73 QTCOMMERCIALCHART_END_NAMESPACE
@@ -106,27 +106,6 void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoi
106 append(values);
106 append(values);
107 }
107 }
108
108
109 ////////////// Bar model ///////////////////////
110
111 DeclarativeBarModel::DeclarativeBarModel(QObject *parent) :
112 DeclarativeTableModel(parent)
113 {
114 }
115
116 void DeclarativeBarModel::append(QBarSet* barSet)
117 {
118 insertColumn(columnCount());
119 for (int i(0); i < barSet->count(); i++) {
120 if (rowCount() < (i + 1))
121 insertRow(rowCount());
122 setData(createIndex(i, columnCount() - 1), barSet->at(i));
123 // insertRow(rowCount());
124 // setData(createIndex(rowCount() - 1, 0), );
125 // setData(createIndex(rowCount() - 1, 1), barSet->at(i));
126 }
127 // TODO: setModelMapping(0, 1, columnCount(), Qt::Vertical);
128 }
129
130 #include "moc_declarativemodel.cpp"
109 #include "moc_declarativemodel.cpp"
131
110
132 QTCOMMERCIALCHART_END_NAMESPACE
111 QTCOMMERCIALCHART_END_NAMESPACE
@@ -68,17 +68,6 public Q_SLOTS:
68 QObject *element);
68 QObject *element);
69 };
69 };
70
70
71 class DeclarativeBarModel : public DeclarativeTableModel
72 {
73 Q_OBJECT
74
75 public:
76 explicit DeclarativeBarModel(QObject *parent = 0);
77
78 public Q_SLOTS:
79 void append(QBarSet* barSet);
80 };
81
82 QTCOMMERCIALCHART_END_NAMESPACE
71 QTCOMMERCIALCHART_END_NAMESPACE
83
72
84 #endif // DECLARATIVEMODEL_H
73 #endif // DECLARATIVEMODEL_H
@@ -64,8 +64,6 public:
64 QLatin1String("Trying to create uncreatable: PieModelMapper."));
64 QLatin1String("Trying to create uncreatable: PieModelMapper."));
65 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
65 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
66 QLatin1String("Trying to create uncreatable: PieModelMapper."));
66 QLatin1String("Trying to create uncreatable: PieModelMapper."));
67
68 qmlRegisterType<DeclarativeBarModel>(uri, 1, 0, "BarModel");
69 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
67 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
70 }
68 }
71 };
69 };
General Comments 0
You need to be logged in to leave comments. Login now