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