@@ -1,77 +1,58 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | import QtQuick 1.0 |
|
21 | import QtQuick 1.0 | |
22 | import QtCommercial.Chart 1.0 |
|
22 | import QtCommercial.Chart 1.0 | |
23 |
|
23 | |||
24 | Rectangle { |
|
24 | Rectangle { | |
25 | anchors.fill: parent |
|
25 | anchors.fill: parent | |
26 |
|
26 | |||
27 | ChartView { |
|
27 | ChartView { | |
28 | title: "Bar series" |
|
28 | title: "Bar series" | |
29 | anchors.fill: parent |
|
29 | anchors.fill: parent | |
30 | theme: ChartView.ChartThemeLight |
|
30 | theme: ChartView.ChartThemeLight | |
31 | legend: ChartView.LegendBottom |
|
31 | legend: ChartView.LegendBottom | |
32 | // axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"] |
|
32 | // axisXLabels: ["0", "2008", "1", "2009", "2", "2010", "3", "2012"] | |
33 | axisX.max: 10 |
|
33 | axisX.max: 10 | |
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 |
|
|
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 | // } | |
|
51 | // 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] } | |||
|
56 | // } | |||
58 | } |
|
57 | } | |
59 |
|
||||
60 | // ChartModel { |
|
|||
61 | // id: chartModel |
|
|||
62 | // } |
|
|||
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 | } |
|
|||
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 | } |
@@ -1,97 +1,106 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativebarseries.h" |
|
21 | #include "declarativebarseries.h" | |
22 | #include "declarativechart.h" |
|
22 | #include "declarativechart.h" | |
23 | #include <QBarSet> |
|
23 | #include <QBarSet> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : |
|
27 | DeclarativeBarSet::DeclarativeBarSet(QObject *parent) : | |
28 | QBarSet("", parent) |
|
28 | QBarSet("", parent) | |
29 | { |
|
29 | { | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | QVariantList DeclarativeBarSet::values() |
|
32 | QVariantList DeclarativeBarSet::values() | |
33 | { |
|
33 | { | |
34 | QVariantList values; |
|
34 | QVariantList values; | |
35 | for (int i(0); i < count(); i++) |
|
35 | for (int i(0); i < count(); i++) | |
36 | values.append(QVariant(at(i))); |
|
36 | values.append(QVariant(at(i))); | |
37 | return values; |
|
37 | return values; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void DeclarativeBarSet::setValues(QVariantList values) |
|
40 | void DeclarativeBarSet::setValues(QVariantList values) | |
41 | { |
|
41 | { | |
42 | while (count()) |
|
42 | while (count()) | |
43 | remove(count() - 1); |
|
43 | remove(count() - 1); | |
44 |
|
44 | |||
45 | for (int i(0); i < values.count(); i++) { |
|
45 | for (int i(0); i < values.count(); i++) { | |
46 | if (values.at(i).canConvert(QVariant::Double)) |
|
46 | if (values.at(i).canConvert(QVariant::Double)) | |
47 | append(values[i].toDouble()); |
|
47 | append(values[i].toDouble()); | |
48 | } |
|
48 | } | |
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 | |||
56 | void DeclarativeBarSeries::classBegin() |
|
56 | void DeclarativeBarSeries::classBegin() | |
57 | { |
|
57 | { | |
58 | } |
|
58 | } | |
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(Declarative |
|
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); | |
70 | if (m) { |
|
79 | if (m) { | |
71 | setModel(m); |
|
80 | setModel(m); | |
72 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); |
|
81 | //setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation = Qt::Vertical); | |
73 | // setModelMapping(0, 1, 1, Qt::Vertical); |
|
82 | // setModelMapping(0, 1, 1, Qt::Vertical); | |
74 | } else { |
|
83 | } else { | |
75 | qWarning("DeclarativeBarSeries: Illegal model"); |
|
84 | qWarning("DeclarativeBarSeries: Illegal model"); | |
76 | } |
|
85 | } | |
77 | return value; |
|
86 | return value; | |
78 | } |
|
87 | } | |
79 |
|
88 | |||
80 |
Declarative |
|
89 | DeclarativeTableModel *DeclarativeBarSeries::declarativeModel() | |
81 | { |
|
90 | { | |
82 |
return qobject_cast<Declarative |
|
91 | return qobject_cast<DeclarativeTableModel *>(model()); | |
83 | } |
|
92 | } | |
84 |
|
93 | |||
85 | void DeclarativeBarSeries::setBarCategories(QStringList categories) |
|
94 | void DeclarativeBarSeries::setBarCategories(QStringList categories) | |
86 | { |
|
95 | { | |
87 | setCategories(categories); |
|
96 | setCategories(categories); | |
88 | } |
|
97 | } | |
89 |
|
98 | |||
90 | QStringList DeclarativeBarSeries::barCategories() |
|
99 | QStringList DeclarativeBarSeries::barCategories() | |
91 | { |
|
100 | { | |
92 | return categories(); |
|
101 | return categories(); | |
93 | } |
|
102 | } | |
94 |
|
103 | |||
95 | #include "moc_declarativebarseries.cpp" |
|
104 | #include "moc_declarativebarseries.cpp" | |
96 |
|
105 | |||
97 | QTCOMMERCIALCHART_END_NAMESPACE |
|
106 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,76 +1,75 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVEBARSERIES_H |
|
21 | #ifndef DECLARATIVEBARSERIES_H | |
22 | #define DECLARATIVEBARSERIES_H |
|
22 | #define DECLARATIVEBARSERIES_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
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 | { | |
37 | Q_OBJECT |
|
36 | Q_OBJECT | |
38 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
37 | Q_PROPERTY(QVariantList values READ values WRITE setValues) | |
39 | Q_PROPERTY(QString name READ name WRITE setName) |
|
38 | Q_PROPERTY(QString name READ name WRITE setName) | |
40 |
|
39 | |||
41 | public: |
|
40 | public: | |
42 | explicit DeclarativeBarSet(QObject *parent = 0); |
|
41 | explicit DeclarativeBarSet(QObject *parent = 0); | |
43 | QVariantList values(); |
|
42 | QVariantList values(); | |
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(Declarative |
|
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(Declarative |
|
64 | bool setDeclarativeModel(DeclarativeTableModel *model); | |
63 |
Declarative |
|
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 | |
75 |
|
74 | |||
76 | #endif // DECLARATIVEBARSERIES_H |
|
75 | #endif // DECLARATIVEBARSERIES_H |
@@ -1,132 +1,111 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "declarativemodel.h" |
|
21 | #include "declarativemodel.h" | |
22 | #include <qdeclarativelist.h> |
|
22 | #include <qdeclarativelist.h> | |
23 | #include <QDebug> |
|
23 | #include <QDebug> | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | ////////////// Table model row /////////////////// |
|
28 | ////////////// Table model row /////////////////// | |
29 |
|
29 | |||
30 | DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent) |
|
30 | DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent) | |
31 | : QObject(parent) |
|
31 | : QObject(parent) | |
32 | { |
|
32 | { | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | QVariantList DeclarativeTableModelElement::values() |
|
35 | QVariantList DeclarativeTableModelElement::values() | |
36 | { |
|
36 | { | |
37 | return m_values; |
|
37 | return m_values; | |
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | void DeclarativeTableModelElement::setValues(QVariantList values) |
|
40 | void DeclarativeTableModelElement::setValues(QVariantList values) | |
41 | { |
|
41 | { | |
42 | m_values = values; |
|
42 | m_values = values; | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | ////////////// Table model /////////////////// |
|
45 | ////////////// Table model /////////////////// | |
46 |
|
46 | |||
47 | DeclarativeTableModel::DeclarativeTableModel(QObject *parent) : |
|
47 | DeclarativeTableModel::DeclarativeTableModel(QObject *parent) : | |
48 | ChartTableModel(parent) |
|
48 | ChartTableModel(parent) | |
49 | { |
|
49 | { | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | void DeclarativeTableModel::classBegin() |
|
52 | void DeclarativeTableModel::classBegin() | |
53 | { |
|
53 | { | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void DeclarativeTableModel::componentComplete() |
|
56 | void DeclarativeTableModel::componentComplete() | |
57 | { |
|
57 | { | |
58 | foreach (QObject *child, children()) { |
|
58 | foreach (QObject *child, children()) { | |
59 | if (qobject_cast<DeclarativeTableModelElement *>(child)) { |
|
59 | if (qobject_cast<DeclarativeTableModelElement *>(child)) { | |
60 | append(qobject_cast<DeclarativeTableModelElement *>(child)->values()); |
|
60 | append(qobject_cast<DeclarativeTableModelElement *>(child)->values()); | |
61 | } |
|
61 | } | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren() |
|
65 | QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren() | |
66 | { |
|
66 | { | |
67 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild); |
|
67 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild); | |
68 | } |
|
68 | } | |
69 |
|
69 | |||
70 | void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list, |
|
70 | void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list, | |
71 | QObject *child) |
|
71 | QObject *child) | |
72 | { |
|
72 | { | |
73 | // childs are added in componentComplete instead |
|
73 | // childs are added in componentComplete instead | |
74 | Q_UNUSED(list) |
|
74 | Q_UNUSED(list) | |
75 | Q_UNUSED(child) |
|
75 | Q_UNUSED(child) | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void DeclarativeTableModel::append(QVariantList values) |
|
78 | void DeclarativeTableModel::append(QVariantList values) | |
79 | { |
|
79 | { | |
80 | // qDebug() << "DeclarativeTableModel::append:" << values; |
|
80 | // qDebug() << "DeclarativeTableModel::append:" << values; | |
81 |
|
81 | |||
82 | while (columnCount() < values.count()) |
|
82 | while (columnCount() < values.count()) | |
83 | insertColumn(columnCount()); |
|
83 | insertColumn(columnCount()); | |
84 |
|
84 | |||
85 | insertRow(rowCount()); |
|
85 | insertRow(rowCount()); | |
86 |
|
86 | |||
87 | QModelIndex beginIndex = QModelIndex(); |
|
87 | QModelIndex beginIndex = QModelIndex(); | |
88 | QModelIndex endIndex = QModelIndex(); |
|
88 | QModelIndex endIndex = QModelIndex(); | |
89 | for (int i(0); i < values.count(); i++) { |
|
89 | for (int i(0); i < values.count(); i++) { | |
90 | QModelIndex modelIndex = createIndex(rowCount() - 1, i); |
|
90 | QModelIndex modelIndex = createIndex(rowCount() - 1, i); | |
91 | if (i == 0) |
|
91 | if (i == 0) | |
92 | beginIndex = modelIndex; |
|
92 | beginIndex = modelIndex; | |
93 | if (i == (values.count() - 1)) |
|
93 | if (i == (values.count() - 1)) | |
94 | endIndex = modelIndex; |
|
94 | endIndex = modelIndex; | |
95 | setData(modelIndex, values.at(i)); |
|
95 | setData(modelIndex, values.at(i)); | |
96 | } |
|
96 | } | |
97 | dataChanged(beginIndex, endIndex); |
|
97 | dataChanged(beginIndex, endIndex); | |
98 | } |
|
98 | } | |
99 |
|
99 | |||
100 | void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point) |
|
100 | void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point) | |
101 | { |
|
101 | { | |
102 | // qDebug() << "DeclarativeTableModel::appendPoint:" << point; |
|
102 | // qDebug() << "DeclarativeTableModel::appendPoint:" << point; | |
103 | QVariantList values; |
|
103 | QVariantList values; | |
104 | values.insert(mapper->mapX(), point->x()); |
|
104 | values.insert(mapper->mapX(), point->x()); | |
105 | values.insert(mapper->mapY(), point->y()); |
|
105 | values.insert(mapper->mapY(), point->y()); | |
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 |
@@ -1,84 +1,73 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #ifndef DECLARATIVEMODEL_H |
|
21 | #ifndef DECLARATIVEMODEL_H | |
22 | #define DECLARATIVEMODEL_H |
|
22 | #define DECLARATIVEMODEL_H | |
23 |
|
23 | |||
24 | #include "qchartglobal.h" |
|
24 | #include "qchartglobal.h" | |
25 | #include "declarativexypoint.h" |
|
25 | #include "declarativexypoint.h" | |
26 | #include <QPieSlice> |
|
26 | #include <QPieSlice> | |
27 | #include "../src/charttablemodel.h" // TODO |
|
27 | #include "../src/charttablemodel.h" // TODO | |
28 | #include <QBarSet> |
|
28 | #include <QBarSet> | |
29 | #include <QXYModelMapper> |
|
29 | #include <QXYModelMapper> | |
30 | #include <QDeclarativeListProperty> |
|
30 | #include <QDeclarativeListProperty> | |
31 | #include <QVariant> |
|
31 | #include <QVariant> | |
32 | #include <QDeclarativeParserStatus> |
|
32 | #include <QDeclarativeParserStatus> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | class DeclarativeTableModelElement : public QObject |
|
36 | class DeclarativeTableModelElement : public QObject | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
39 | Q_PROPERTY(QVariantList values READ values WRITE setValues) | |
40 |
|
40 | |||
41 | public: |
|
41 | public: | |
42 | explicit DeclarativeTableModelElement(QObject *parent = 0); |
|
42 | explicit DeclarativeTableModelElement(QObject *parent = 0); | |
43 | QVariantList values(); |
|
43 | QVariantList values(); | |
44 | void setValues(QVariantList values); |
|
44 | void setValues(QVariantList values); | |
45 | private: |
|
45 | private: | |
46 | QVariantList m_values; |
|
46 | QVariantList m_values; | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 | class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus |
|
49 | class DeclarativeTableModel : public ChartTableModel, public QDeclarativeParserStatus | |
50 | { |
|
50 | { | |
51 | Q_OBJECT |
|
51 | Q_OBJECT | |
52 | Q_INTERFACES(QDeclarativeParserStatus) |
|
52 | Q_INTERFACES(QDeclarativeParserStatus) | |
53 | Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren) |
|
53 | Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren) | |
54 | Q_CLASSINFO("DefaultProperty", "modelChildren") |
|
54 | Q_CLASSINFO("DefaultProperty", "modelChildren") | |
55 |
|
55 | |||
56 | public: |
|
56 | public: | |
57 | explicit DeclarativeTableModel(QObject *parent = 0); |
|
57 | explicit DeclarativeTableModel(QObject *parent = 0); | |
58 | QDeclarativeListProperty<QObject> modelChildren(); |
|
58 | QDeclarativeListProperty<QObject> modelChildren(); | |
59 | void appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point); |
|
59 | void appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point); | |
60 |
|
60 | |||
61 | public: // from QDeclarativeParserStatus |
|
61 | public: // from QDeclarativeParserStatus | |
62 | void classBegin(); |
|
62 | void classBegin(); | |
63 | void componentComplete(); |
|
63 | void componentComplete(); | |
64 |
|
64 | |||
65 | public Q_SLOTS: |
|
65 | public Q_SLOTS: | |
66 | void append(QVariantList slices); |
|
66 | void append(QVariantList slices); | |
67 | static void appendModelChild(QDeclarativeListProperty<QObject> *list, |
|
67 | static void appendModelChild(QDeclarativeListProperty<QObject> *list, | |
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 |
@@ -1,79 +1,77 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
21 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |
22 | #include <QtDeclarative/qdeclarative.h> |
|
22 | #include <QtDeclarative/qdeclarative.h> | |
23 | #include "qchart.h" |
|
23 | #include "qchart.h" | |
24 | #include "qaxiscategories.h" |
|
24 | #include "qaxiscategories.h" | |
25 | #include "declarativechart.h" |
|
25 | #include "declarativechart.h" | |
26 | #include "declarativexypoint.h" |
|
26 | #include "declarativexypoint.h" | |
27 | #include "declarativelineseries.h" |
|
27 | #include "declarativelineseries.h" | |
28 | #include "declarativesplineseries.h" |
|
28 | #include "declarativesplineseries.h" | |
29 | #include "declarativeareaseries.h" |
|
29 | #include "declarativeareaseries.h" | |
30 | #include "declarativescatterseries.h" |
|
30 | #include "declarativescatterseries.h" | |
31 | #include "declarativebarseries.h" |
|
31 | #include "declarativebarseries.h" | |
32 | #include "declarativepieseries.h" |
|
32 | #include "declarativepieseries.h" | |
33 | #include "declarativemodel.h" |
|
33 | #include "declarativemodel.h" | |
34 | #include <QPieModelMapper> |
|
34 | #include <QPieModelMapper> | |
35 | #include <QXYModelMapper> |
|
35 | #include <QXYModelMapper> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
39 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
40 | { |
|
40 | { | |
41 | Q_OBJECT |
|
41 | Q_OBJECT | |
42 | public: |
|
42 | public: | |
43 | virtual void registerTypes(const char *uri) |
|
43 | virtual void registerTypes(const char *uri) | |
44 | { |
|
44 | { | |
45 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
45 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
46 |
|
46 | |||
47 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
47 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
48 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", |
|
48 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", | |
49 | QLatin1String("Trying to create uncreatable: Axis.")); |
|
49 | QLatin1String("Trying to create uncreatable: Axis.")); | |
50 | //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory"); |
|
50 | //qmlRegisterType<DeclarativeAxisCategory>(uri, 1, 0, "AxisCategory"); | |
51 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); |
|
51 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); | |
52 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
52 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
53 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
53 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); | |
54 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
54 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); | |
55 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
55 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); | |
56 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
56 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
57 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
57 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
58 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
58 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
59 | qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel"); |
|
59 | qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel"); | |
60 | qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement"); |
|
60 | qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement"); | |
61 | //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping"); |
|
61 | //qmlRegisterType<DeclarativePieMapping>(uri, 1, 0, "PieMapping"); | |
62 | //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper"); |
|
62 | //qmlRegisterType<QPieModelMapper>(uri, 1, 0, "PieModelMapper"); | |
63 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
63 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
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 | }; | |
72 |
|
70 | |||
73 | #include "plugin.moc" |
|
71 | #include "plugin.moc" | |
74 |
|
72 | |||
75 | QTCOMMERCIALCHART_END_NAMESPACE |
|
73 | QTCOMMERCIALCHART_END_NAMESPACE | |
76 |
|
74 | |||
77 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
75 | QTCOMMERCIALCHART_USE_NAMESPACE | |
78 |
|
76 | |||
79 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
77 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
General Comments 0
You need to be logged in to leave comments.
Login now