@@ -1,108 +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 | |
|
28 | 28 | ChartView { |
|
29 | 29 | id: chart |
|
30 | 30 | title: "Custom model example" |
|
31 | 31 | anchors.fill: parent |
|
32 | 32 | theme: ChartView.ChartThemeLight |
|
33 | 33 | |
|
34 | 34 | // For dynamic data you can use the ChartModel API. |
|
35 | 35 | ChartModel { |
|
36 | 36 | id: chartModel |
|
37 | 37 | ChartModelElement { values: ["Volkswagen", 13.5, 4.4] } |
|
38 | 38 | ChartModelElement { values: ["Toyota", 10.9, 4.2] } |
|
39 | 39 | ChartModelElement { values: ["Ford", 8.6, 3.0] } |
|
40 | 40 | ChartModelElement { values: ["Skoda", 8.2, 1.9] } |
|
41 | 41 | ChartModelElement { values: ["Volvo", 6.8, 1.5] } |
|
42 | 42 | } |
|
43 | 43 | |
|
44 | 44 | LineSeries { |
|
45 | 45 | name: "line" |
|
46 | 46 | |
|
47 | 47 | // TODO: the new mapper api |
|
48 | 48 | // VXYModelMapper { |
|
49 | 49 | // model: chartModel |
|
50 | 50 | // xColumn: 0 |
|
51 | 51 | // yColumn: 1 |
|
52 | 52 | // } |
|
53 | 53 | } |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | PieSeries { |
|
57 | 57 | id: pieSeries |
|
58 | 58 | size: 0.4 |
|
59 | 59 | horizontalPosition: 0.2 |
|
60 | 60 | verticalPosition: 0.3 |
|
61 | ||
|
62 | VPieModelMapper { | |
|
63 | model: chartModel | |
|
64 | labelsColumn: 0 | |
|
65 | valuesColumn: 1 | |
|
66 | } | |
|
67 | 61 | } |
|
68 | 62 | |
|
69 |
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
|
63 | VPieModelMapper { | |
|
64 | series: pieSeries | |
|
65 | model: chartModel | |
|
66 | labelsColumn: 0 | |
|
67 | valuesColumn: 1 | |
|
68 | } | |
|
75 | 69 |
|
|
76 | 70 | // AreaSeries { |
|
77 | 71 | // name: "area" |
|
78 | 72 | // upperSeries: LineSeries {} |
|
79 | 73 | // lowerSeries: LineSeries {} |
|
80 | 74 | // } |
|
81 | 75 | |
|
82 | 76 | // TODO: BarSeries with ChartModel base model API |
|
83 | 77 | // BarSeries { |
|
84 | 78 | // model: chartModel |
|
85 | 79 | // modelMapper.first: 0 |
|
86 | 80 | // } |
|
87 | 81 | } |
|
88 | 82 | |
|
89 | 83 | |
|
90 | 84 | // TODO: you could also implement appending to your model, for example: |
|
91 | 85 | // pieSeries.model.append(["Others", 52.0]); |
|
92 | 86 | |
|
93 | 87 | // TODO: show how to use data from a list model in a chart view |
|
94 | 88 | // i.e. copy the data into a chart model |
|
95 | 89 | // ListModel { |
|
96 | 90 | // id: listModel |
|
97 | 91 | // ListElement { |
|
98 | 92 | // label: "Volkswagen" |
|
99 | 93 | // value: 13.5 |
|
100 | 94 | // } |
|
101 | 95 | // ListElement { |
|
102 | 96 | // label: "Toyota" |
|
103 | 97 | // value: 10.9 |
|
104 | 98 | // } |
|
105 | 99 | // // and so on... |
|
106 | 100 | // } |
|
107 | 101 | |
|
108 | 102 | } |
@@ -1,86 +1,88 | |||
|
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 <QtDeclarative/qdeclarativeextensionplugin.h> |
|
22 | 22 | #include <QtDeclarative/qdeclarative.h> |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qaxiscategories.h" |
|
25 | 25 | #include "declarativechart.h" |
|
26 | 26 | #include "declarativexypoint.h" |
|
27 | 27 | #include "declarativelineseries.h" |
|
28 | 28 | #include "declarativesplineseries.h" |
|
29 | 29 | #include "declarativeareaseries.h" |
|
30 | 30 | #include "declarativescatterseries.h" |
|
31 | 31 | #include "declarativebarseries.h" |
|
32 | 32 | #include "declarativepieseries.h" |
|
33 | 33 | #include "declarativemodel.h" |
|
34 | 34 | #include <QHPieModelMapper> |
|
35 | 35 | #include <QVPieModelMapper> |
|
36 | 36 | #include <QXYModelMapper> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
41 | 41 | { |
|
42 | 42 | Q_OBJECT |
|
43 | 43 | public: |
|
44 | 44 | virtual void registerTypes(const char *uri) |
|
45 | 45 | { |
|
46 | 46 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
47 | 47 | |
|
48 | 48 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
49 | 49 | qmlRegisterType<DeclarativeXyPoint>(uri, 1, 0, "XyPoint"); |
|
50 | 50 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
51 | 51 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
52 | 52 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
53 | 53 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
54 | 54 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
55 | 55 | qmlRegisterType<DeclarativeGroupedBarSeries>(uri, 1, 0, "GroupedBarSeries"); |
|
56 | 56 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
57 | 57 | qmlRegisterType<DeclarativePieSlice>(uri, 1, 0, "PieSlice"); |
|
58 | 58 | qmlRegisterType<DeclarativeTableModel>(uri, 1, 0, "ChartModel"); |
|
59 | 59 | qmlRegisterType<DeclarativeTableModelElement>(uri, 1, 0, "ChartModelElement"); |
|
60 | 60 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
61 | 61 | |
|
62 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", | |
|
63 | QLatin1String("Trying to create uncreatable: QPieSeries.")); | |
|
62 | 64 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
63 | 65 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
64 | 66 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
65 | 67 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
66 | 68 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
67 | 69 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
68 | 70 | |
|
69 | 71 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
70 | 72 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
71 | 73 | qmlRegisterUncreatableType<QAxis>(uri, 1, 0, "Axis", |
|
72 | 74 | QLatin1String("Trying to create uncreatable: Axis.")); |
|
73 | 75 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
74 | 76 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
75 | 77 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
76 | 78 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
77 | 79 | } |
|
78 | 80 | }; |
|
79 | 81 | |
|
80 | 82 | #include "plugin.moc" |
|
81 | 83 | |
|
82 | 84 | QTCOMMERCIALCHART_END_NAMESPACE |
|
83 | 85 | |
|
84 | 86 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
85 | 87 | |
|
86 | 88 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
@@ -1,145 +1,130 | |||
|
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 "charttablemodel.h" |
|
22 | 22 | #include <QVector> |
|
23 | #include <QTime> | |
|
24 | 23 | #include <QRect> |
|
25 | 24 | #include <QColor> |
|
26 | 25 | |
|
27 | 26 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | 27 | |
|
29 | 28 | ChartTableModel::ChartTableModel(QObject *parent) : |
|
30 | QAbstractTableModel(parent) | |
|
29 | QAbstractTableModel(parent), | |
|
30 | m_columnCount(0), | |
|
31 | m_rowCount(0) | |
|
31 | 32 | { |
|
32 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
|
33 | ||
|
34 | m_columnCount = 2; | |
|
35 | m_rowCount = 0; | |
|
36 | ||
|
37 | // m_data | |
|
38 | for (int i = 0; i < m_rowCount; i++) { | |
|
39 | QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount); | |
|
40 | for (int k = 0; k < dataVec->size(); k++) { | |
|
41 | if (k%2 == 0) | |
|
42 | dataVec->replace(k, i * 50 + qrand()%20); | |
|
43 | else | |
|
44 | dataVec->replace(k, qrand()%100); | |
|
45 | } | |
|
46 | m_data.append(dataVec); | |
|
47 | } | |
|
48 | 33 | } |
|
49 | 34 | |
|
50 | 35 | int ChartTableModel::rowCount(const QModelIndex & parent) const |
|
51 | 36 | { |
|
52 | 37 | Q_UNUSED(parent) |
|
53 | 38 | return m_data.count(); |
|
54 | 39 | } |
|
55 | 40 | |
|
56 | 41 | int ChartTableModel::columnCount(const QModelIndex & parent) const |
|
57 | 42 | { |
|
58 | 43 | Q_UNUSED(parent) |
|
59 | 44 | return m_columnCount; |
|
60 | 45 | } |
|
61 | 46 | |
|
62 | 47 | QVariant ChartTableModel::headerData (int section, Qt::Orientation orientation, int role ) const |
|
63 | 48 | { |
|
64 | 49 | if (role != Qt::DisplayRole) |
|
65 | 50 | return QVariant(); |
|
66 | 51 | |
|
67 | 52 | if (orientation == Qt::Horizontal) { |
|
68 | 53 | if (section % 2 == 0) |
|
69 | 54 | return "x"; |
|
70 | 55 | else |
|
71 | 56 | return "y"; |
|
72 | 57 | } else { |
|
73 | 58 | return QString("%1").arg(section + 1); |
|
74 | 59 | } |
|
75 | 60 | } |
|
76 | 61 | |
|
77 | 62 | QVariant ChartTableModel::data(const QModelIndex &index, int role) const |
|
78 | 63 | { |
|
79 | 64 | if (role == Qt::DisplayRole) { |
|
80 | 65 | return m_data[index.row()]->at(index.column()); |
|
81 | 66 | } else if (role == Qt::EditRole) { |
|
82 | 67 | return m_data[index.row()]->at(index.column()); |
|
83 | 68 | } |
|
84 | 69 | return QVariant(); |
|
85 | 70 | } |
|
86 | 71 | |
|
87 | 72 | bool ChartTableModel::setData(const QModelIndex &index, const QVariant &value, int role) |
|
88 | 73 | { |
|
89 | 74 | if (index.isValid() && role == Qt::EditRole) { |
|
90 | 75 | m_data[index.row()]->replace(index.column(), value); |
|
91 | 76 | emit dataChanged(index, index); |
|
92 | 77 | return true; |
|
93 | 78 | } |
|
94 | 79 | return false; |
|
95 | 80 | } |
|
96 | 81 | |
|
97 | 82 | void ChartTableModel::insertColumn(int column, const QModelIndex &parent) |
|
98 | 83 | { |
|
99 | 84 | beginInsertColumns(parent, column, column); |
|
100 | 85 | m_columnCount++; |
|
101 | 86 | endInsertColumns(); |
|
102 | 87 | } |
|
103 | 88 | |
|
104 | 89 | void ChartTableModel::insertRow(int row, const QModelIndex &parent) |
|
105 | 90 | { |
|
106 | 91 | beginInsertRows(parent, row, row); |
|
107 | 92 | QVector<QVariant>* dataVec = new QVector<QVariant>(m_columnCount); |
|
108 | 93 | m_data.insert(row, dataVec); |
|
109 | 94 | endInsertRows(); |
|
110 | 95 | } |
|
111 | 96 | |
|
112 | 97 | //bool ChartTableModel::removeRow(int row, const QModelIndex &parent) |
|
113 | 98 | //{ |
|
114 | 99 | // Q_UNUSED(parent) |
|
115 | 100 | // Q_ASSERT(row >= 0 && row < rowCount); |
|
116 | 101 | |
|
117 | 102 | // beginRemoveRows(parent, row, row); |
|
118 | 103 | // m_data.removeAt(row); |
|
119 | 104 | // endRemoveRows(); |
|
120 | 105 | // return true; |
|
121 | 106 | //} |
|
122 | 107 | |
|
123 | 108 | bool ChartTableModel::removeRow(int row, const QModelIndex &parent) |
|
124 | 109 | { |
|
125 | 110 | return QAbstractTableModel::removeRow(row, parent); |
|
126 | 111 | } |
|
127 | 112 | |
|
128 | 113 | bool ChartTableModel::removeRows(int row, int count, const QModelIndex &parent) |
|
129 | 114 | { |
|
130 | 115 | beginRemoveRows(parent, row, row + count - 1); |
|
131 | 116 | bool removed(false); |
|
132 | 117 | for (int i(row); i < (row + count); i++) { |
|
133 | 118 | m_data.removeAt(i); |
|
134 | 119 | removed = true; |
|
135 | 120 | } |
|
136 | 121 | endRemoveRows(); |
|
137 | 122 | return removed; |
|
138 | 123 | } |
|
139 | 124 | |
|
140 | 125 | Qt::ItemFlags ChartTableModel::flags ( const QModelIndex & index ) const |
|
141 | 126 | { |
|
142 | 127 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; |
|
143 | 128 | } |
|
144 | 129 | |
|
145 | 130 | #include "moc_charttablemodel.cpp" |
General Comments 0
You need to be logged in to leave comments.
Login now