@@ -1,112 +1,114 | |||
|
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 | 23 | #include <QDebug> |
|
24 | 24 | |
|
25 | 25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | ////////////// Table model row /////////////////// |
|
29 | 29 | |
|
30 | 30 | DeclarativeTableModelElement::DeclarativeTableModelElement(QObject *parent) |
|
31 | 31 | : QObject(parent) |
|
32 | 32 | { |
|
33 | 33 | } |
|
34 | 34 | |
|
35 | 35 | QVariantList DeclarativeTableModelElement::values() |
|
36 | 36 | { |
|
37 | 37 | return m_values; |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | 40 | void DeclarativeTableModelElement::setValues(QVariantList values) |
|
41 | 41 | { |
|
42 | 42 | m_values = values; |
|
43 | 43 | } |
|
44 | 44 | |
|
45 | 45 | ////////////// Table model /////////////////// |
|
46 | 46 | |
|
47 | 47 | DeclarativeTableModel::DeclarativeTableModel(QObject *parent) : |
|
48 | 48 | ChartTableModel(parent) |
|
49 | 49 | { |
|
50 | 50 | } |
|
51 | 51 | |
|
52 | 52 | void DeclarativeTableModel::classBegin() |
|
53 | 53 | { |
|
54 | 54 | } |
|
55 | 55 | |
|
56 | 56 | void DeclarativeTableModel::componentComplete() |
|
57 | 57 | { |
|
58 | 58 | foreach (QObject *child, children()) { |
|
59 | 59 | if (qobject_cast<DeclarativeTableModelElement *>(child)) { |
|
60 | 60 | append(qobject_cast<DeclarativeTableModelElement *>(child)->values()); |
|
61 | 61 | } |
|
62 | 62 | } |
|
63 | 63 | } |
|
64 | 64 | |
|
65 | 65 | QDeclarativeListProperty<QObject> DeclarativeTableModel::modelChildren() |
|
66 | 66 | { |
|
67 | 67 | return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeTableModel::appendModelChild); |
|
68 | 68 | } |
|
69 | 69 | |
|
70 | 70 | void DeclarativeTableModel::appendModelChild(QDeclarativeListProperty<QObject> *list, |
|
71 | 71 | QObject *child) |
|
72 | 72 | { |
|
73 | 73 | // childs are added in componentComplete instead |
|
74 | 74 | Q_UNUSED(list) |
|
75 | 75 | Q_UNUSED(child) |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void DeclarativeTableModel::append(QVariantList values) |
|
79 | 79 | { |
|
80 | 80 | // qDebug() << "DeclarativeTableModel::append:" << values; |
|
81 | 81 | |
|
82 | 82 | while (columnCount() < values.count()) |
|
83 | 83 | insertColumn(columnCount()); |
|
84 | 84 | |
|
85 | 85 | insertRow(rowCount()); |
|
86 | 86 | |
|
87 | 87 | QModelIndex beginIndex = QModelIndex(); |
|
88 | 88 | QModelIndex endIndex = QModelIndex(); |
|
89 | 89 | for (int i(0); i < values.count(); i++) { |
|
90 | 90 | QModelIndex modelIndex = createIndex(rowCount() - 1, i); |
|
91 | 91 | if (i == 0) |
|
92 | 92 | beginIndex = modelIndex; |
|
93 | 93 | if (i == (values.count() - 1)) |
|
94 | 94 | endIndex = modelIndex; |
|
95 | 95 | setData(modelIndex, values.at(i)); |
|
96 | 96 | } |
|
97 | 97 | dataChanged(beginIndex, endIndex); |
|
98 | 98 | } |
|
99 | 99 | |
|
100 | 100 | void DeclarativeTableModel::appendPoint(QXYModelMapper *mapper, DeclarativeXyPoint *point) |
|
101 | 101 | { |
|
102 | // qDebug() << "DeclarativeTableModel::appendPoint:" << point; | |
|
103 | QVariantList values; | |
|
102 | Q_UNUSED(mapper) | |
|
103 | Q_UNUSED(point) | |
|
104 | 104 | // TODO: XYModelMapper implementation has change, this code has to be updated. |
|
105 | // qDebug() << "DeclarativeTableModel::appendPoint:" << point; | |
|
106 | // QVariantList values; | |
|
105 | 107 | // values.insert(mapper->mapX(), point->x()); |
|
106 | 108 | // values.insert(mapper->mapY(), point->y()); |
|
107 | append(values); | |
|
109 | // append(values); | |
|
108 | 110 | } |
|
109 | 111 | |
|
110 | 112 | #include "moc_declarativemodel.cpp" |
|
111 | 113 | |
|
112 | 114 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now