@@ -31,8 +31,10 Rectangle { | |||
|
31 | 31 | title: "Custom model example" |
|
32 | 32 | anchors.fill: parent |
|
33 | 33 | theme: ChartView.ChartThemeLight |
|
34 |
axisX.max: |
|
|
34 | axisX.max: 10 | |
|
35 | axisX.min: 0 | |
|
35 | 36 | axisY.max: 20 |
|
37 | axisY.min: 0 | |
|
36 | 38 | |
|
37 | 39 | // For dynamic data we use a custom data model derived from QAbstractiItemModel |
|
38 | 40 | CustomModel { |
@@ -68,7 +70,7 Rectangle { | |||
|
68 | 70 | PieSeries { |
|
69 | 71 | id: pieSeries |
|
70 | 72 | size: 0.4 |
|
71 |
horizontalPosition: 0. |
|
|
73 | horizontalPosition: 0.7 | |
|
72 | 74 | verticalPosition: 0.3 |
|
73 | 75 | } |
|
74 | 76 | |
@@ -92,10 +94,16 Rectangle { | |||
|
92 | 94 | } |
|
93 | 95 | } |
|
94 | 96 | |
|
95 |
|
|
|
96 | // model: customModel | |
|
97 | // modelMapper.first: 0 | |
|
98 | // } | |
|
97 | GroupedBarSeries { | |
|
98 | name: "Skoda and Volvo" | |
|
99 | barCategories: [ "1", "2", "3", "4", "5", "6" ] | |
|
100 | HBarModelMapper { | |
|
101 | model: customModel | |
|
102 | firstBarSetRow: 4 | |
|
103 | lastBarSetRow: 5 | |
|
104 | first: 2 | |
|
105 | } | |
|
106 | } | |
|
99 | 107 |
|
|
100 | 108 | |
|
101 | 109 |
@@ -21,6 +21,8 | |||
|
21 | 21 | #include "declarativebarseries.h" |
|
22 | 22 | #include "declarativechart.h" |
|
23 | 23 | #include <QBarSet> |
|
24 | #include <QVBarModelMapper> | |
|
25 | #include <QHBarModelMapper> | |
|
24 | 26 | |
|
25 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 28 | |
@@ -98,13 +100,26 void DeclarativeBarSeries::componentComplete() | |||
|
98 | 100 | foreach(QObject *child, children()) { |
|
99 | 101 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
100 | 102 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
103 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
|
104 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
|
105 | mapper->setSeries(this); | |
|
106 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
|
107 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
|
108 | mapper->setSeries(this); | |
|
101 | 109 | } |
|
102 | 110 | } |
|
103 | 111 | } |
|
104 | 112 | |
|
105 |
QDeclarativeListProperty< |
|
|
113 | QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren() | |
|
106 | 114 | { |
|
107 |
return QDeclarativeListProperty< |
|
|
115 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
|
116 | } | |
|
117 | ||
|
118 | void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
|
119 | { | |
|
120 | // Empty implementation; the children are parsed in componentComplete instead | |
|
121 | Q_UNUSED(list); | |
|
122 | Q_UNUSED(element); | |
|
108 | 123 | } |
|
109 | 124 | |
|
110 | 125 | void DeclarativeBarSeries::setBarCategories(QStringList categories) |
@@ -140,13 +155,26 void DeclarativeGroupedBarSeries::componentComplete() | |||
|
140 | 155 | foreach(QObject *child, children()) { |
|
141 | 156 | if (qobject_cast<DeclarativeBarSet *>(child)) { |
|
142 | 157 | QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child)); |
|
158 | } else if(qobject_cast<QVBarModelMapper *>(child)) { | |
|
159 | QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child); | |
|
160 | mapper->setSeries(this); | |
|
161 | } else if(qobject_cast<QHBarModelMapper *>(child)) { | |
|
162 | QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child); | |
|
163 | mapper->setSeries(this); | |
|
143 | 164 | } |
|
144 | 165 | } |
|
145 | 166 | } |
|
146 | 167 | |
|
147 |
QDeclarativeListProperty< |
|
|
168 | QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren() | |
|
169 | { | |
|
170 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren); | |
|
171 | } | |
|
172 | ||
|
173 | void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element) | |
|
148 | 174 | { |
|
149 | return QDeclarativeListProperty<DeclarativeBarSet>(this, 0, &DeclarativeGroupedBarSeries::appendInitialBarSets); | |
|
175 | // Empty implementation; the children are parsed in componentComplete instead | |
|
176 | Q_UNUSED(list); | |
|
177 | Q_UNUSED(element); | |
|
150 | 178 | } |
|
151 | 179 | |
|
152 | 180 | void DeclarativeGroupedBarSeries::setBarCategories(QStringList categories) |
@@ -60,12 +60,12 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus | |||
|
60 | 60 | Q_OBJECT |
|
61 | 61 | Q_INTERFACES(QDeclarativeParserStatus) |
|
62 | 62 | Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) |
|
63 |
Q_PROPERTY(QDeclarativeListProperty< |
|
|
64 |
Q_CLASSINFO("DefaultProperty", " |
|
|
63 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
|
64 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
|
65 | 65 | |
|
66 | 66 | public: |
|
67 | 67 | explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0); |
|
68 |
QDeclarativeListProperty< |
|
|
68 | QDeclarativeListProperty<QObject> seriesChildren(); | |
|
69 | 69 | |
|
70 | 70 | void setBarCategories(QStringList categories); |
|
71 | 71 | QStringList barCategories(); |
@@ -77,7 +77,7 public: // from QDeclarativeParserStatus | |||
|
77 | 77 | void componentComplete(); |
|
78 | 78 | |
|
79 | 79 | public Q_SLOTS: |
|
80 |
static void append |
|
|
80 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
|
81 | 81 | }; |
|
82 | 82 | |
|
83 | 83 | class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus |
@@ -85,12 +85,12 class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativ | |||
|
85 | 85 | Q_OBJECT |
|
86 | 86 | Q_INTERFACES(QDeclarativeParserStatus) |
|
87 | 87 | Q_PROPERTY(QStringList barCategories READ barCategories WRITE setBarCategories) |
|
88 |
Q_PROPERTY(QDeclarativeListProperty< |
|
|
89 |
Q_CLASSINFO("DefaultProperty", " |
|
|
88 | Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren) | |
|
89 | Q_CLASSINFO("DefaultProperty", "seriesChildren") | |
|
90 | 90 | |
|
91 | 91 | public: |
|
92 | 92 | explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0); |
|
93 |
QDeclarativeListProperty< |
|
|
93 | QDeclarativeListProperty<QObject> seriesChildren(); | |
|
94 | 94 | |
|
95 | 95 | void setBarCategories(QStringList categories); |
|
96 | 96 | QStringList barCategories(); |
@@ -102,7 +102,7 public: // from QDeclarativeParserStatus | |||
|
102 | 102 | void componentComplete(); |
|
103 | 103 | |
|
104 | 104 | public Q_SLOTS: |
|
105 |
static void append |
|
|
105 | static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element); | |
|
106 | 106 | }; |
|
107 | 107 | |
|
108 | 108 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -34,6 +34,8 | |||
|
34 | 34 | #include <QHXYModelMapper> |
|
35 | 35 | #include <QHPieModelMapper> |
|
36 | 36 | #include <QVPieModelMapper> |
|
37 | #include <QHBarModelMapper> | |
|
38 | #include <QVBarModelMapper> | |
|
37 | 39 | |
|
38 | 40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 41 | |
@@ -60,6 +62,8 public: | |||
|
60 | 62 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
61 | 63 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
62 | 64 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
65 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); | |
|
66 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); | |
|
63 | 67 | |
|
64 | 68 | |
|
65 | 69 | qmlRegisterUncreatableType<QScatterSeries>(uri, 1, 0, "QScatterSeries", |
@@ -72,6 +76,8 public: | |||
|
72 | 76 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
73 | 77 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
74 | 78 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
79 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", | |
|
80 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); | |
|
75 | 81 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
76 | 82 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
77 | 83 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", |
@@ -10,6 +10,7 class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper | |||
|
10 | 10 | Q_OBJECT |
|
11 | 11 | Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow) |
|
12 | 12 | Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow) |
|
13 | Q_PROPERTY(int categoriesRow READ categoriesRow WRITE setCategoriesRow) | |
|
13 | 14 | |
|
14 | 15 | public: |
|
15 | 16 | explicit QHBarModelMapper(QObject *parent = 0); |
@@ -10,6 +10,7 class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper | |||
|
10 | 10 | Q_OBJECT |
|
11 | 11 | Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn) |
|
12 | 12 | Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn) |
|
13 | Q_PROPERTY(int categoriesColumn READ categoriesColumn WRITE setCategoriesColumn) | |
|
13 | 14 | |
|
14 | 15 | public: |
|
15 | 16 | explicit QVBarModelMapper(QObject *parent = 0); |
@@ -488,8 +488,8 void TableWidget::updateChartType(bool toggle) | |||
|
488 | 488 | // int count = 4; |
|
489 | 489 | QVBarModelMapper *mapper = new QVBarModelMapper; |
|
490 | 490 | mapper->setCategoriesSection(5); |
|
491 | mapper->setFirstBarSection(2); | |
|
492 | mapper->setLastBarSection(4); | |
|
491 | mapper->setFirstBarSetSection(2); | |
|
492 | mapper->setLastBarSetSection(4); | |
|
493 | 493 | mapper->setFirst(first); |
|
494 | 494 | // mapper->setCount(count); |
|
495 | 495 | mapper->setSeries(barSeries); |
General Comments 0
You need to be logged in to leave comments.
Login now