@@ -1,101 +1,102 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | |
|
24 | 24 | Rectangle { |
|
25 | 25 | width: parent.width |
|
26 | 26 | height: parent.height |
|
27 | 27 | property int __activeIndex: 1 |
|
28 | 28 | property real __intervalCoefficient: 0 |
|
29 | 29 | |
|
30 | 30 | |
|
31 | 31 | //![1] |
|
32 | 32 | ChartView { |
|
33 | 33 | id: chartView |
|
34 | 34 | anchors.fill: parent |
|
35 | 35 | title: "Wheel of fortune" |
|
36 | 36 | legend.visible: false |
|
37 | 37 | |
|
38 | 38 | PieSeries { |
|
39 | 39 | id: wheelOfFortune |
|
40 | horizontalPosition: 0.3 | |
|
40 | 41 | } |
|
41 | 42 | |
|
42 | 43 | SplineSeries { |
|
43 | 44 | id: splineSeries |
|
44 | 45 | } |
|
45 | 46 | |
|
46 | 47 | ScatterSeries { |
|
47 | 48 | id: scatterSeries |
|
48 | 49 | } |
|
49 | 50 | } |
|
50 | 51 | //![1] |
|
51 | 52 | |
|
52 | 53 | //![2] |
|
53 | 54 | Component.onCompleted: { |
|
54 | 55 | __intervalCoefficient = Math.random() + 0.1; |
|
55 | 56 | |
|
56 | 57 | for (var i = 0; i < 20; i++) |
|
57 | 58 | wheelOfFortune.append("", 1); |
|
58 | 59 | |
|
59 | 60 | var interval = 1; |
|
60 | 61 | for (var j = 0; interval < 800; j++) { |
|
61 | 62 | interval = __intervalCoefficient * j * j; |
|
62 | 63 | splineSeries.append(j, interval); |
|
63 | 64 | } |
|
64 | 65 | chartView.axisX.max = j; |
|
65 | 66 | chartView.axisY.max = 1000; |
|
66 | 67 | } |
|
67 | 68 | //![2] |
|
68 | 69 | |
|
69 | 70 | Timer { |
|
70 | 71 | triggeredOnStart: true |
|
71 | 72 | running: true |
|
72 | 73 | repeat: true |
|
73 | 74 | interval: 100 |
|
74 | 75 | onTriggered: { |
|
75 | 76 | var index = __activeIndex % wheelOfFortune.count; |
|
76 | 77 | if (interval < 700) { |
|
77 | 78 | //![3] |
|
78 | 79 | wheelOfFortune.at(index).exploded = false; |
|
79 | 80 | __activeIndex++; |
|
80 | 81 | index = __activeIndex % wheelOfFortune.count; |
|
81 | 82 | wheelOfFortune.at(index).exploded = true; |
|
82 | 83 | //![3] |
|
83 | 84 | interval = splineSeries.at(__activeIndex).y; |
|
84 | 85 | //![4] |
|
85 | 86 | scatterSeries.clear(); |
|
86 | 87 | scatterSeries.append(__activeIndex, interval); |
|
87 | 88 | scatterSeries.color = Qt.tint(scatterSeries.color, "#05FF0000"); |
|
88 | 89 | scatterSeries.markerSize += 0.5; |
|
89 | 90 | //![4] |
|
90 | 91 | } else { |
|
91 | 92 | //![5] |
|
92 | 93 | // Switch the colors of the slice and the border |
|
93 | 94 | wheelOfFortune.at(index).borderWidth = 2; |
|
94 | 95 | var borderColor = wheelOfFortune.at(index).borderColor; |
|
95 | 96 | wheelOfFortune.at(index).borderColor = wheelOfFortune.at(index).color; |
|
96 | 97 | wheelOfFortune.at(index).color = borderColor; |
|
97 | 98 | //![5] |
|
98 | 99 | } |
|
99 | 100 | } |
|
100 | 101 | } |
|
101 | 102 | } |
@@ -1,136 +1,136 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "customtablemodel.h" |
|
22 | 22 | #include <QVector> |
|
23 | 23 | #include <QRect> |
|
24 | 24 | #include <QColor> |
|
25 | 25 | #include <QDebug> |
|
26 | 26 | |
|
27 | 27 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
28 | 28 | QAbstractTableModel(parent), |
|
29 | 29 | m_columnCount(0), |
|
30 | 30 | m_rowCount(0) |
|
31 | 31 | { |
|
32 | 32 | } |
|
33 | 33 | |
|
34 | 34 | int CustomTableModel::rowCount(const QModelIndex & parent) const |
|
35 | 35 | { |
|
36 | 36 | Q_UNUSED(parent) |
|
37 | 37 | return m_data.count(); |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | int CustomTableModel::columnCount(const QModelIndex & parent) const |
|
41 | 41 | { |
|
42 | 42 | Q_UNUSED(parent) |
|
43 | 43 | return m_columnCount; |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | QVariant CustomTableModel::headerData(int section, Qt::Orientation orientation, int role) const |
|
47 | 47 | { |
|
48 | 48 | if (role != Qt::DisplayRole) |
|
49 | 49 | return QVariant(); |
|
50 | 50 | |
|
51 |
if (orientation == Qt:: |
|
|
52 |
if (m_ |
|
|
53 |
return m_ |
|
|
51 | if (orientation == Qt::Vertical) { | |
|
52 | if (m_verticalHeaders.count() > section) | |
|
53 | return m_verticalHeaders[section]; | |
|
54 | 54 | else |
|
55 | 55 | return QAbstractTableModel::headerData(section, orientation, role); |
|
56 | 56 | } else { |
|
57 | 57 | return QAbstractTableModel::headerData(section, orientation, role); |
|
58 | 58 | } |
|
59 | 59 | } |
|
60 | 60 | |
|
61 | 61 | bool CustomTableModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) |
|
62 | 62 | { |
|
63 |
if (orientation == Qt:: |
|
|
64 |
while (m_ |
|
|
65 |
m_ |
|
|
66 |
m_ |
|
|
63 | if (orientation == Qt::Vertical) { | |
|
64 | while (m_verticalHeaders.count() <= section) | |
|
65 | m_verticalHeaders.append(QVariant()); | |
|
66 | m_verticalHeaders.replace(section, value); | |
|
67 | 67 | } else { |
|
68 | 68 | return QAbstractTableModel::setHeaderData(section, orientation, value, role); |
|
69 | 69 | } |
|
70 | 70 | emit headerDataChanged(orientation, section, section); |
|
71 | 71 | return true; |
|
72 | 72 | } |
|
73 | 73 | |
|
74 | 74 | QVariant CustomTableModel::data(const QModelIndex &index, int role) const |
|
75 | 75 | { |
|
76 | 76 | if (role == Qt::DisplayRole) { |
|
77 | 77 | return m_data[index.row()]->at(index.column()); |
|
78 | 78 | } else if (role == Qt::EditRole) { |
|
79 | 79 | return m_data[index.row()]->at(index.column()); |
|
80 | 80 | } |
|
81 | 81 | return QVariant(); |
|
82 | 82 | } |
|
83 | 83 | |
|
84 | 84 | bool CustomTableModel::setData(const QModelIndex &index, const QVariant &value, int role) |
|
85 | 85 | { |
|
86 | 86 | if (index.isValid() && role == Qt::EditRole) { |
|
87 | 87 | m_data[index.row()]->replace(index.column(), value); |
|
88 | 88 | emit dataChanged(index, index); |
|
89 | 89 | return true; |
|
90 | 90 | } |
|
91 | 91 | return false; |
|
92 | 92 | } |
|
93 | 93 | |
|
94 | 94 | QVariant CustomTableModel::at(int row, int column) |
|
95 | 95 | { |
|
96 | 96 | return data(index(row, column)); |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void CustomTableModel::insertColumn(int column, const QModelIndex &parent) |
|
100 | 100 | { |
|
101 | 101 | beginInsertColumns(parent, column, column); |
|
102 | 102 | m_columnCount++; |
|
103 | 103 | endInsertColumns(); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | void CustomTableModel::insertRow(int row, const QModelIndex &parent) |
|
107 | 107 | { |
|
108 | 108 | beginInsertRows(parent, row, row); |
|
109 | 109 | QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount); |
|
110 | 110 | m_data.insert(row, dataVec); |
|
111 | 111 | endInsertRows(); |
|
112 | 112 | } |
|
113 | 113 | |
|
114 | 114 | bool CustomTableModel::removeRow(int row, const QModelIndex &parent) |
|
115 | 115 | { |
|
116 | 116 | return QAbstractTableModel::removeRow(row, parent); |
|
117 | 117 | } |
|
118 | 118 | |
|
119 | 119 | bool CustomTableModel::removeRows(int row, int count, const QModelIndex &parent) |
|
120 | 120 | { |
|
121 | 121 | beginRemoveRows(parent, row, row + count - 1); |
|
122 | 122 | bool removed(false); |
|
123 | 123 | for (int i(row); i < (row + count); i++) { |
|
124 | 124 | m_data.removeAt(i); |
|
125 | 125 | removed = true; |
|
126 | 126 | } |
|
127 | 127 | endRemoveRows(); |
|
128 | 128 | return removed; |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const |
|
132 | 132 | { |
|
133 | 133 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | #include "moc_customtablemodel.cpp" |
@@ -1,56 +1,56 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef CUSTOMTABLEMODEL_H |
|
22 | 22 | #define CUSTOMTABLEMODEL_H |
|
23 | 23 | |
|
24 | 24 | #include <QAbstractTableModel> |
|
25 | 25 | #include <QHash> |
|
26 | 26 | |
|
27 | 27 | class CustomTableModel : public QAbstractTableModel |
|
28 | 28 | { |
|
29 | 29 | Q_OBJECT |
|
30 | 30 | Q_PROPERTY(int rowCount READ rowCount) |
|
31 | 31 | Q_PROPERTY(int columnCount READ columnCount) |
|
32 | 32 | |
|
33 | 33 | public: |
|
34 | 34 | explicit CustomTableModel(QObject *parent = 0); |
|
35 | 35 | |
|
36 | 36 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
37 | 37 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
38 | 38 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
|
39 | 39 | bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole); |
|
40 | 40 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
41 | 41 | bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ); |
|
42 | 42 | Qt::ItemFlags flags ( const QModelIndex & index ) const; |
|
43 | 43 | void insertColumn(int column, const QModelIndex &parent = QModelIndex()); |
|
44 | 44 | void insertRow(int row, const QModelIndex &parent = QModelIndex()); |
|
45 | 45 | Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()); |
|
46 | 46 | Q_INVOKABLE bool removeRow (int row, const QModelIndex &parent = QModelIndex()); |
|
47 | 47 | Q_INVOKABLE QVariant at(int row, int column); |
|
48 | 48 | |
|
49 | 49 | private: |
|
50 | 50 | QList<QVector<QVariant> * > m_data; |
|
51 |
QList<QVariant> m_ |
|
|
51 | QList<QVariant> m_verticalHeaders; | |
|
52 | 52 | int m_columnCount; |
|
53 | 53 | int m_rowCount; |
|
54 | 54 | }; |
|
55 | 55 | |
|
56 | 56 | #endif // CUSTOMTABLEMODEL_H |
@@ -1,109 +1,110 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "declarativemodel.h" |
|
22 | 22 | #include <qdeclarativelist.h> |
|
23 | #include <QStringList> | |
|
23 | 24 | #include <QDebug> |
|
24 | 25 | |
|
25 | 26 | ////////////// Table model element /////////////////// |
|
26 | 27 | |
|
27 | 28 | DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent) |
|
28 | 29 | : QObject(parent) |
|
29 | 30 | { |
|
30 | 31 | } |
|
31 | 32 | |
|
32 | QString DeclarativeTableModelElement::rowHeader() | |
|
33 | { | |
|
34 | return m_rowHeader; | |
|
35 | } | |
|
36 | ||
|
37 | void DeclarativeTableModelElement::setRowHeader(QString header) | |
|
38 | { | |
|
39 | m_rowHeader = header; | |
|
40 | } | |
|
41 | ||
|
42 | 33 | QVariantList DeclarativeTableModelElement::values() |
|
43 | 34 | { |
|
44 | 35 | return m_values; |
|
45 | 36 | } |
|
46 | 37 | |
|
47 | 38 | void DeclarativeTableModelElement::setValues(QVariantList values) |
|
48 | 39 | { |
|
49 | 40 | m_values = values; |
|
50 | 41 | } |
|
51 | 42 | |
|
52 | 43 | ////////////// Table model /////////////////// |
|
53 | 44 | |
|
54 | 45 | DeclarativeTableModel::DeclarativeTableModel(QObject *parent) : |
|
55 | 46 | CustomTableModel(parent) |
|
56 | 47 | { |
|
57 | 48 | } |
|
58 | 49 | |
|
59 | 50 | void DeclarativeTableModel::classBegin() |
|
60 | 51 | { |
|
61 | 52 | } |
|
62 | 53 | |
|
63 | 54 | void DeclarativeTableModel::componentComplete() |
|
64 | 55 | { |
|
65 | 56 | foreach (QObject *child, children()) { |
|
66 | 57 | if (qobject_cast<DeclarativeTableModelElement *>(child)) { |
|
67 | 58 | DeclarativeTableModelElement *element = qobject_cast<DeclarativeTableModelElement *>(child); |
|
68 | 59 | append(element->values()); |
|
69 | setHeaderData(rowCount() - 1, Qt::Horizontal, element->rowHeader()); | |
|
70 | 60 | } |
|
71 | 61 | } |
|
72 | 62 | } |
|
73 | 63 | |
|
64 | void DeclarativeTableModel::setVerticalHeaders(QStringList headers) | |
|
65 | { | |
|
66 | for (int i(0); i < headers.count(); i++) | |
|
67 | setHeaderData(i, Qt::Vertical, headers.at(i)); | |
|
68 | } | |
|
69 | ||
|
70 | QStringList DeclarativeTableModel::verticalHeaders() | |
|
71 | { | |
|
72 | return QStringList(); | |
|
73 | } | |
|
74 | ||
|
74 | 75 | QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren() |
|
75 | 76 | { |
|
76 | 77 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild); |
|
77 | 78 | } |
|
78 | 79 | |
|
79 | 80 | void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list, |
|
80 | 81 | QObject *child) |
|
81 | 82 | { |
|
82 | 83 | // childs are added in componentComplete instead |
|
83 | 84 | Q_UNUSED(list) |
|
84 | 85 | Q_UNUSED(child) |
|
85 | 86 | } |
|
86 | 87 | |
|
87 | 88 | void DeclarativeTableModel::append(QVariantList values) |
|
88 | 89 | { |
|
89 | 90 | // qDebug() << "DeclarativeTableModel::append:" << values; |
|
90 | 91 | |
|
91 | 92 | while (columnCount() < values.count()) |
|
92 | 93 | insertColumn(columnCount()); |
|
93 | 94 | |
|
94 | 95 | insertRow(rowCount()); |
|
95 | 96 | |
|
96 | 97 | QModelIndex beginIndex = QModelIndex(); |
|
97 | 98 | QModelIndex endIndex = QModelIndex(); |
|
98 | 99 | for (int i(0); i < values.count(); i++) { |
|
99 | 100 | QModelIndex modelIndex = createIndex(rowCount() - 1, i); |
|
100 | 101 | if (i == 0) |
|
101 | 102 | beginIndex = modelIndex; |
|
102 | 103 | if (i == (values.count() - 1)) |
|
103 | 104 | endIndex = modelIndex; |
|
104 | 105 | setData(modelIndex, values.at(i)); |
|
105 | 106 | } |
|
106 | 107 | dataChanged(beginIndex, endIndex); |
|
107 | 108 | } |
|
108 | 109 | |
|
109 | 110 | #include "moc_declarativemodel.cpp" |
@@ -1,67 +1,66 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #ifndef DECLARATIVEMODEL_H |
|
22 | 22 | #define DECLARATIVEMODEL_H |
|
23 | 23 | |
|
24 | 24 | #include "customtablemodel.h" |
|
25 | 25 | #include <QDeclarativeListProperty> |
|
26 | 26 | #include <QVariant> |
|
27 | 27 | #include <QDeclarativeParserStatus> |
|
28 | 28 | |
|
29 | 29 | class DeclarativeTableModelElement : public QObject |
|
30 | 30 | { |
|
31 | 31 | Q_OBJECT |
|
32 | Q_PROPERTY(QString rowHeader READ rowHeader WRITE setRowHeader) | |
|
33 | 32 | Q_PROPERTY(QVariantList values READ values WRITE setValues) |
|
34 | 33 | |
|
35 | 34 | public: |
|
36 | 35 | explicit DeclarativeTableModelElement(QObject *parent = 0); |
|
37 | QString rowHeader(); | |
|
38 | void setRowHeader(QString header); | |
|
39 | 36 | QVariantList values(); |
|
40 | 37 | void setValues(QVariantList values); |
|
41 | 38 | private: |
|
42 | QString m_rowHeader; | |
|
43 | 39 | QVariantList m_values; |
|
44 | 40 | }; |
|
45 | 41 | |
|
46 | 42 | class DeclarativeTableModel : public CustomTableModel, public QDeclarativeParserStatus |
|
47 | 43 | { |
|
48 | 44 | Q_OBJECT |
|
49 | 45 | Q_INTERFACES(QDeclarativeParserStatus) |
|
50 | 46 | Q_PROPERTY(QDeclarativeListProperty<QObject> modelChildren READ modelChildren) |
|
47 | Q_PROPERTY(QStringList verticalHeaders READ verticalHeaders WRITE setVerticalHeaders) | |
|
51 | 48 | Q_CLASSINFO("DefaultProperty", "modelChildren") |
|
52 | 49 | |
|
53 | 50 | public: |
|
54 | 51 | explicit DeclarativeTableModel(QObject *parent = 0); |
|
55 | 52 | QDeclarativeListProperty<QObject> modelChildren(); |
|
53 | void setVerticalHeaders(QStringList headers); | |
|
54 | QStringList verticalHeaders(); | |
|
56 | 55 | |
|
57 | 56 | public: // from QDeclarativeParserStatus |
|
58 | 57 | void classBegin(); |
|
59 | 58 | void componentComplete(); |
|
60 | 59 | |
|
61 | 60 | public Q_SLOTS: |
|
62 | 61 | void append(QVariantList slices); |
|
63 | 62 | static void appendModelChild(QDeclarativeListProperty<QObject> *list, |
|
64 | 63 | QObject *element); |
|
65 | 64 | }; |
|
66 | 65 | |
|
67 | 66 | #endif // DECLARATIVEMODEL_H |
@@ -1,154 +1,155 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | import QtQuick 1.0 |
|
22 | 22 | import QtCommercial.Chart 1.0 |
|
23 | 23 | import QmlCustomModel 1.0 |
|
24 | 24 | |
|
25 | 25 | Rectangle { |
|
26 | 26 | anchors.fill: parent |
|
27 | 27 | |
|
28 | 28 | //![1] |
|
29 | 29 | ChartView { |
|
30 | 30 | id: chartView |
|
31 | 31 | title: "Top-5 car brand shares in Finland" |
|
32 | 32 | anchors.fill: parent |
|
33 | 33 | axisX.max: 10 |
|
34 | 34 | axisX.min: 0 |
|
35 | 35 | axisY.max: 20 |
|
36 | 36 | axisY.min: 0 |
|
37 | 37 | animationOptions: ChartView.SeriesAnimations |
|
38 | 38 | axisXLabels: [0, "2007", 1, "2008", 2, "2009", 3, "2010", 4, "2011", 5, "2012"] |
|
39 | 39 | // ... |
|
40 | 40 | //![1] |
|
41 | 41 | |
|
42 | 42 | //![2] |
|
43 | 43 | CustomModel { |
|
44 | 44 | id: customModel |
|
45 | CustomModelElement { rowHeader: ""; values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
|
46 |
CustomModelElement { |
|
|
47 |
CustomModelElement { |
|
|
48 |
CustomModelElement { |
|
|
49 |
CustomModelElement { |
|
|
50 |
CustomModelElement { |
|
|
51 |
CustomModelElement { |
|
|
45 | verticalHeaders: ["Manufacturer", "Volkswagen", "Toyota", "Ford", "Skoda", "Volvo", "Others"] | |
|
46 | CustomModelElement { values: [0, "Manufacturer", 0, 1, 2, 3, 4] } | |
|
47 | CustomModelElement { values: [1, "Volkswagen", 10.3, 12.0, 12.8, 13.0, 13.8] } | |
|
48 | CustomModelElement { values: [2, "Toyota", 13.8, 13.5, 16.2, 13.7, 10.7] } | |
|
49 | CustomModelElement { values: [3, "Ford", 6.4, 7.1, 8.9, 8.2, 8.6] } | |
|
50 | CustomModelElement { values: [4, "Skoda", 4.7, 5.8, 6.9, 8.3, 8.2] } | |
|
51 | CustomModelElement { values: [5, "Volvo", 7.1, 6.7, 6.5, 6.3, 7.0] } | |
|
52 | CustomModelElement { values: [6, "Others", 57.7, 54.9, 48.7, 50.5, 51.7] } | |
|
52 | 53 | } |
|
53 | 54 | //![2] |
|
54 | 55 | |
|
55 | 56 | //![5] |
|
56 | 57 | BarSeries { |
|
57 | 58 | name: "Others" |
|
58 | 59 | barMargin: 0 |
|
59 | 60 | visible: false |
|
60 | 61 | HBarModelMapper { |
|
61 | 62 | model: customModel |
|
62 | 63 | firstBarSetRow: 6 |
|
63 | 64 | lastBarSetRow: 6 |
|
64 | 65 | first: 2 |
|
65 | 66 | } |
|
66 | 67 | } |
|
67 | 68 | //![5] |
|
68 | 69 | |
|
69 | 70 | //![4] |
|
70 | 71 | LineSeries { |
|
71 | 72 | name: "Volkswagen" |
|
72 | 73 | visible: false |
|
73 | 74 | HXYModelMapper { |
|
74 | 75 | model: customModel |
|
75 | 76 | xRow: 0 |
|
76 | 77 | yRow: 1 |
|
77 | 78 | first: 2 |
|
78 | 79 | } |
|
79 | 80 | } |
|
80 | 81 | //![4] |
|
81 | 82 | |
|
82 | 83 | LineSeries { |
|
83 | 84 | name: "Toyota" |
|
84 | 85 | visible: false |
|
85 | 86 | HXYModelMapper { |
|
86 | 87 | model: customModel |
|
87 | 88 | xRow: 0 |
|
88 | 89 | yRow: 2 |
|
89 | 90 | first: 2 |
|
90 | 91 | } |
|
91 | 92 | } |
|
92 | 93 | |
|
93 | 94 | LineSeries { |
|
94 | 95 | name: "Ford" |
|
95 | 96 | visible: false |
|
96 | 97 | HXYModelMapper { |
|
97 | 98 | model: customModel |
|
98 | 99 | xRow: 0 |
|
99 | 100 | yRow: 3 |
|
100 | 101 | first: 2 |
|
101 | 102 | } |
|
102 | 103 | } |
|
103 | 104 | |
|
104 | 105 | LineSeries { |
|
105 | 106 | name: "Skoda" |
|
106 | 107 | visible: false |
|
107 | 108 | HXYModelMapper { |
|
108 | 109 | model: customModel |
|
109 | 110 | xRow: 0 |
|
110 | 111 | yRow: 4 |
|
111 | 112 | first: 2 |
|
112 | 113 | } |
|
113 | 114 | } |
|
114 | 115 | |
|
115 | 116 | LineSeries { |
|
116 | 117 | name: "Volvo" |
|
117 | 118 | visible: false |
|
118 | 119 | HXYModelMapper { |
|
119 | 120 | model: customModel |
|
120 | 121 | xRow: 0 |
|
121 | 122 | yRow: 5 |
|
122 | 123 | first: 2 |
|
123 | 124 | } |
|
124 | 125 | } |
|
125 | 126 | |
|
126 | 127 | //![3] |
|
127 | 128 | PieSeries { |
|
128 | 129 | id: pieSeries |
|
129 | 130 | size: 0.4 |
|
130 | 131 | horizontalPosition: 0.7 |
|
131 | 132 | verticalPosition: 0.4 |
|
132 | 133 | onClicked: { |
|
133 | 134 | // Show the selection by exploding the slice |
|
134 | 135 | slice.exploded = !slice.exploded; |
|
135 | 136 | |
|
136 | 137 | // Update the line series to show the yearly data for this slice |
|
137 | 138 | for (var i = 0; i < chartView.count; i++) { |
|
138 | 139 | if (chartView.series(i).name == slice.label) { |
|
139 | 140 | chartView.series(i).visible = slice.exploded; |
|
140 | 141 | } |
|
141 | 142 | } |
|
142 | 143 | } |
|
143 | 144 | } |
|
144 | 145 | //![3] |
|
145 | 146 | |
|
146 | 147 | VPieModelMapper { |
|
147 | 148 | series: pieSeries |
|
148 | 149 | model: customModel |
|
149 | 150 | labelsColumn: 1 |
|
150 | 151 | valuesColumn: 2 |
|
151 | 152 | first: 1 |
|
152 | 153 | } |
|
153 | 154 | } |
|
154 | 155 | } |
|
1 | NO CONTENT: modified file, binary diff hidden |
General Comments 0
You need to be logged in to leave comments.
Login now