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