@@ -1,258 +1,276 | |||||
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 <QTime> |
|
23 | #include <QTime> | |
|
24 | #include <QRect> | |||
|
25 | #include <QColor> | |||
24 |
|
26 | |||
25 | CustomTableModel::CustomTableModel(QObject *parent) : |
|
27 | CustomTableModel::CustomTableModel(QObject *parent) : | |
26 | QAbstractTableModel(parent) |
|
28 | QAbstractTableModel(parent) | |
27 | { |
|
29 | { | |
28 | // m_points.append(QPointF(10, 50)); |
|
30 | // m_points.append(QPointF(10, 50)); | |
29 | // m_labels.append("Apples"); |
|
31 | // m_labels.append("Apples"); | |
30 | // m_points.append(QPointF(60, 70)); |
|
32 | // m_points.append(QPointF(60, 70)); | |
31 | // m_labels.append("Oranges"); |
|
33 | // m_labels.append("Oranges"); | |
32 | // m_points.append(QPointF(110, 50)); |
|
34 | // m_points.append(QPointF(110, 50)); | |
33 | // m_labels.append("Bananas"); |
|
35 | // m_labels.append("Bananas"); | |
34 | // m_points.append(QPointF(140, 40)); |
|
36 | // m_points.append(QPointF(140, 40)); | |
35 | // m_labels.append("Lemons"); |
|
37 | // m_labels.append("Lemons"); | |
36 | // m_points.append(QPointF(200, 150)); |
|
38 | // m_points.append(QPointF(200, 150)); | |
37 | // m_labels.append("Plums"); |
|
39 | // m_labels.append("Plums"); | |
38 | // m_points.append(QPointF(225, 75)); |
|
40 | // m_points.append(QPointF(225, 75)); | |
39 | // m_labels.append("Pearls"); |
|
41 | // m_labels.append("Pearls"); | |
40 |
|
42 | |||
41 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
43 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
42 |
|
44 | |||
43 | // m_data |
|
45 | // m_data | |
44 | for (int i = 0; i < 6; i++) |
|
46 | for (int i = 0; i < 6; i++) | |
45 | { |
|
47 | { | |
46 | QVector<qreal>* dataVec = new QVector<qreal>(6); |
|
48 | QVector<qreal>* dataVec = new QVector<qreal>(6); | |
47 | QVector<QColor>* colorVec = new QVector<QColor>(6); |
|
49 | // QVector<QColor>* colorVec = new QVector<QColor>(6); | |
48 | for (int k = 0; k < dataVec->size(); k++) |
|
50 | for (int k = 0; k < dataVec->size(); k++) | |
49 | { |
|
51 | { | |
50 | if (k%2 == 0) |
|
52 | if (k%2 == 0) | |
51 | dataVec->replace(k, i * 50 + qrand()%20); |
|
53 | dataVec->replace(k, i * 50 + qrand()%20); | |
52 | else |
|
54 | else | |
53 | dataVec->replace(k, qrand()%100); |
|
55 | dataVec->replace(k, qrand()%100); | |
54 | colorVec->replace(k, QColor(Qt::white)); |
|
56 | // colorVec->replace(k, QColor(Qt::white)); | |
55 | } |
|
57 | } | |
56 | m_data.append(dataVec); |
|
58 | m_data.append(dataVec); | |
57 | m_labels.append(QString("Row: %1").arg((i + 1))); |
|
59 | m_labels.append(QString("Row: %1").arg((i + 1))); | |
58 | m_rowsColors.append(colorVec); |
|
60 | // m_rowsColors.append(colorVec); | |
59 | } |
|
61 | } | |
60 | } |
|
62 | } | |
61 |
|
63 | |||
62 | int CustomTableModel::rowCount(const QModelIndex & parent) const |
|
64 | int CustomTableModel::rowCount(const QModelIndex & parent) const | |
63 | { |
|
65 | { | |
64 | Q_UNUSED(parent) |
|
66 | Q_UNUSED(parent) | |
65 | // return m_points.count(); |
|
67 | // return m_points.count(); | |
66 | return m_data.count(); |
|
68 | return m_data.count(); | |
67 | } |
|
69 | } | |
68 |
|
70 | |||
69 | int CustomTableModel::columnCount(const QModelIndex & parent) const |
|
71 | int CustomTableModel::columnCount(const QModelIndex & parent) const | |
70 | { |
|
72 | { | |
71 | Q_UNUSED(parent) |
|
73 | Q_UNUSED(parent) | |
72 | // return 3; |
|
74 | // return 3; | |
73 | return 6; |
|
75 | return 6; | |
74 | } |
|
76 | } | |
75 |
|
77 | |||
76 | QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const |
|
78 | QVariant CustomTableModel::headerData (int section, Qt::Orientation orientation, int role ) const | |
77 | { |
|
79 | { | |
78 | if (role != Qt::DisplayRole) |
|
80 | if (role != Qt::DisplayRole) | |
79 | return QVariant(); |
|
81 | return QVariant(); | |
80 |
|
82 | |||
81 | if (orientation == Qt::Horizontal) |
|
83 | if (orientation == Qt::Horizontal) | |
82 | { |
|
84 | { | |
83 | switch(section) |
|
85 | switch(section) | |
84 | { |
|
86 | { | |
85 | // case 0: |
|
87 | // case 0: | |
86 | // return "x"; |
|
88 | // return "x"; | |
87 | // case 1: |
|
89 | // case 1: | |
88 | // return "y"; |
|
90 | // return "y"; | |
89 | // case 2: |
|
91 | // case 2: | |
90 | case 6: |
|
92 | case 6: | |
91 | return "Fruit"; |
|
93 | return "Fruit"; | |
92 | default: |
|
94 | default: | |
93 | if (section%2 == 0) |
|
95 | if (section%2 == 0) | |
94 | return "x"; |
|
96 | return "x"; | |
95 | else |
|
97 | else | |
96 | return "y"; |
|
98 | return "y"; | |
97 | // return "What?"; |
|
99 | // return "What?"; | |
98 | } |
|
100 | } | |
99 | } |
|
101 | } | |
100 | else |
|
102 | else | |
101 | return QString("%1").arg(section /*+ 1*/); |
|
103 | return QString("%1").arg(section /*+ 1*/); | |
102 | } |
|
104 | } | |
103 |
|
105 | |||
104 | QVariant CustomTableModel::data(const QModelIndex & index, int role) const |
|
106 | QVariant CustomTableModel::data(const QModelIndex & index, int role) const | |
105 | { |
|
107 | { | |
106 | if (role == Qt::DisplayRole) |
|
108 | if (role == Qt::DisplayRole) | |
107 | { |
|
109 | { | |
108 | switch(index.column()) |
|
110 | switch(index.column()) | |
109 | { |
|
111 | { | |
110 | // case 0: |
|
112 | // case 0: | |
111 | // return m_points[index.row()].x(); |
|
113 | // return m_points[index.row()].x(); | |
112 | // case 1: |
|
114 | // case 1: | |
113 | // return m_points[index.row()].y(); |
|
115 | // return m_points[index.row()].y(); | |
114 | // case 2: |
|
116 | // case 2: | |
115 | case 6: |
|
117 | case 6: | |
116 | return m_labels[index.row()]; |
|
118 | return m_labels[index.row()]; | |
117 | default: |
|
119 | default: | |
118 | return m_data[index.row()]->at(index.column()); |
|
120 | return m_data[index.row()]->at(index.column()); | |
119 | break; |
|
121 | break; | |
120 | } |
|
122 | } | |
121 | } |
|
123 | } | |
122 | else if (role == Qt::EditRole) |
|
124 | else if (role == Qt::EditRole) | |
123 | { |
|
125 | { | |
124 | switch(index.column()) |
|
126 | switch(index.column()) | |
125 | { |
|
127 | { | |
126 | // case 0: |
|
128 | // case 0: | |
127 | // return m_points[index.row()].x(); |
|
129 | // return m_points[index.row()].x(); | |
128 | // case 1: |
|
130 | // case 1: | |
129 | // return m_points[index.row()].y(); |
|
131 | // return m_points[index.row()].y(); | |
130 | // case 2: |
|
132 | // case 2: | |
131 | case 6: |
|
133 | case 6: | |
132 | return m_labels[index.row()]; |
|
134 | return m_labels[index.row()]; | |
133 | default: |
|
135 | default: | |
134 | return m_data[index.row()]->at(index.column()); |
|
136 | return m_data[index.row()]->at(index.column()); | |
135 | break; |
|
137 | break; | |
136 | } |
|
138 | } | |
137 | } |
|
139 | } | |
138 | else if (role == Qt::BackgroundRole) |
|
140 | else if (role == Qt::BackgroundRole) | |
139 | { |
|
141 | { | |
140 | return m_rowsColors[index.row()]->at(index.column()); |
|
142 | QRect rect; | |
|
143 | foreach(rect, m_mapping) | |||
|
144 | if(rect.contains(index.column(), index.row())) | |||
|
145 | return QColor(m_mapping.key(rect)); | |||
|
146 | ||||
|
147 | // cell not mapped return white color | |||
|
148 | return QColor(Qt::white); | |||
141 | } |
|
149 | } | |
142 | return QVariant(); |
|
150 | return QVariant(); | |
143 | } |
|
151 | } | |
144 |
|
152 | |||
145 | bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role) |
|
153 | bool CustomTableModel::setData ( const QModelIndex & index, const QVariant & value, int role) | |
146 | { |
|
154 | { | |
147 | if (index.isValid() && role == Qt::EditRole) |
|
155 | if (index.isValid() && role == Qt::EditRole) | |
148 | { |
|
156 | { | |
149 | switch(index.column()) |
|
157 | switch(index.column()) | |
150 | { |
|
158 | { | |
151 | // case 0: |
|
159 | // case 0: | |
152 | // m_points[index.row()].setX(value.toDouble()); |
|
160 | // m_points[index.row()].setX(value.toDouble()); | |
153 | // break; |
|
161 | // break; | |
154 | // case 1: |
|
162 | // case 1: | |
155 | // m_points[index.row()].setY(value.toDouble()); |
|
163 | // m_points[index.row()].setY(value.toDouble()); | |
156 | // break; |
|
164 | // break; | |
157 | // case 2: |
|
165 | // case 2: | |
158 | case 6: |
|
166 | case 6: | |
159 | m_labels.replace(index.row(), value.toString()); |
|
167 | m_labels.replace(index.row(), value.toString()); | |
160 | break; |
|
168 | break; | |
161 | default: |
|
169 | default: | |
162 | m_data[index.row()]->replace(index.column(), value.toDouble()); |
|
170 | m_data[index.row()]->replace(index.column(), value.toDouble()); | |
163 | break; |
|
171 | break; | |
164 | // return false; |
|
172 | // return false; | |
165 | } |
|
173 | } | |
166 | emit dataChanged(index, index); |
|
174 | emit dataChanged(index, index); | |
167 | return true; |
|
175 | return true; | |
168 | } |
|
176 | } | |
169 | else if (role == Qt::BackgroundRole) |
|
177 | // else if (role == Qt::BackgroundRole) | |
170 | { |
|
178 | // { | |
171 | m_rowsColors[index.row()]->replace(index.column(), value.value<QColor>()); |
|
179 | // m_rowsColors[index.row()]->replace(index.column(), value.value<QColor>()); | |
172 | return true; |
|
180 | // return true; | |
173 | } |
|
181 | // } | |
174 | return false; |
|
182 | return false; | |
175 | } |
|
183 | } | |
176 |
|
184 | |||
177 | Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const |
|
185 | Qt::ItemFlags CustomTableModel::flags ( const QModelIndex & index ) const | |
178 | { |
|
186 | { | |
179 | // if (!index.isValid()) |
|
187 | // if (!index.isValid()) | |
180 | // return Qt::ItemIsEnabled; |
|
188 | // return Qt::ItemIsEnabled; | |
181 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; |
|
189 | return QAbstractItemModel::flags(index) | Qt::ItemIsEditable; | |
182 | } |
|
190 | } | |
183 |
|
191 | |||
184 | bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent) |
|
192 | bool CustomTableModel::insertRows ( int row, int count, const QModelIndex & parent) | |
185 | { |
|
193 | { | |
186 | Q_UNUSED(parent) |
|
194 | Q_UNUSED(parent) | |
187 |
|
195 | |||
188 | if (row < 0) |
|
196 | if (row < 0) | |
189 | row = 0; |
|
197 | row = 0; | |
190 | beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1); |
|
198 | beginInsertRows(QModelIndex(), row /*dataTable.count()*/, row + count - 1); | |
191 | for (int i = row; i < row + count; i++) |
|
199 | for (int i = row; i < row + count; i++) | |
192 | { |
|
200 | { | |
193 | // m_points.insert(row, QPointF(10,20)); |
|
201 | // m_points.insert(row, QPointF(10,20)); | |
194 | QVector<qreal>* dataVec = new QVector<qreal>(6); |
|
202 | QVector<qreal>* dataVec = new QVector<qreal>(6); | |
195 | QVector<QColor>* colorVec = new QVector<QColor>(6); |
|
203 | QVector<QColor>* colorVec = new QVector<QColor>(6); | |
196 | for (int k = 0; k < dataVec->size(); k++) |
|
204 | for (int k = 0; k < dataVec->size(); k++) | |
197 | { |
|
205 | { | |
198 | if (k%2 == 0) |
|
206 | if (k%2 == 0) | |
199 | // dataVec->replace(k, i * 50 + qrand()%20); |
|
207 | // dataVec->replace(k, i * 50 + qrand()%20); | |
200 | { |
|
208 | { | |
201 | int difference = 0; |
|
209 | int difference = 0; | |
202 | if (i < m_data.size()) |
|
210 | if (i < m_data.size()) | |
203 | { |
|
211 | { | |
204 | if (i - 1 >= 0) |
|
212 | if (i - 1 >= 0) | |
205 | { |
|
213 | { | |
206 | if (row > 0) |
|
214 | if (row > 0) | |
207 | difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count); |
|
215 | difference = (int)((qAbs(m_data[i]->at(k) - m_data[row - 1]->at(k)))/count); | |
208 | else |
|
216 | else | |
209 | difference = (int)((qAbs(m_data[i]->at(k)/count))); |
|
217 | difference = (int)((qAbs(m_data[i]->at(k)/count))); | |
210 | dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference)); |
|
218 | dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%qMax(1, difference)); | |
211 | } |
|
219 | } | |
212 | else |
|
220 | else | |
213 | dataVec->replace(k, qrand()%40 + 10); |
|
221 | dataVec->replace(k, qrand()%40 + 10); | |
214 | } |
|
222 | } | |
215 | else |
|
223 | else | |
216 | { |
|
224 | { | |
217 | if (i - 1 >= 0) |
|
225 | if (i - 1 >= 0) | |
218 | { |
|
226 | { | |
219 | dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10); |
|
227 | dataVec->replace(k, m_data[i - 1]->at(k) + qrand()%40 + 10); | |
220 | } |
|
228 | } | |
221 | else |
|
229 | else | |
222 | { |
|
230 | { | |
223 | dataVec->replace(k, qrand()%40 + 10); |
|
231 | dataVec->replace(k, qrand()%40 + 10); | |
224 | } |
|
232 | } | |
225 | } |
|
233 | } | |
226 | } |
|
234 | } | |
227 | else |
|
235 | else | |
228 | dataVec->replace(k, qrand()%100); |
|
236 | dataVec->replace(k, qrand()%100); | |
229 | colorVec->replace(k, QColor(Qt::white)); |
|
237 | colorVec->replace(k, QColor(Qt::white)); | |
230 | } |
|
238 | } | |
231 | m_data.insert(i, dataVec); |
|
239 | m_data.insert(i, dataVec); | |
232 | m_labels.insert(i,(QString("Row: %1").arg(i + 1))); |
|
240 | m_labels.insert(i,(QString("Row: %1").arg(i + 1))); | |
233 | m_rowsColors.insert(i, colorVec); |
|
241 | // m_rowsColors.insert(i, colorVec); | |
234 | } |
|
242 | } | |
235 | endInsertRows(); |
|
243 | endInsertRows(); | |
236 | return true; |
|
244 | return true; | |
237 | } |
|
245 | } | |
238 |
|
246 | |||
239 | bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent) |
|
247 | bool CustomTableModel::removeRows ( int row, int count, const QModelIndex & parent) | |
240 | { |
|
248 | { | |
241 | if (row > this->rowCount() - 1) |
|
249 | if (row > this->rowCount() - 1) | |
242 | return false; |
|
250 | return false; | |
243 | if (row < 0) |
|
251 | if (row < 0) | |
244 | row = 0; |
|
252 | row = 0; | |
245 | if (row + count > rowCount()) |
|
253 | if (row + count > rowCount()) | |
246 | return false; |
|
254 | return false; | |
247 | beginRemoveRows(parent, row, row + count - 1); |
|
255 | beginRemoveRows(parent, row, row + count - 1); | |
248 | for (int i = row; i < row + count; i++) |
|
256 | for (int i = row; i < row + count; i++) | |
249 | { |
|
257 | { | |
250 | // m_points.removeAt(row); |
|
258 | // m_points.removeAt(row); | |
251 | QVector<qreal>* item = m_data.at(row); |
|
259 | QVector<qreal>* item = m_data.at(row); | |
252 | m_data.removeAt(row); |
|
260 | m_data.removeAt(row); | |
253 | delete item; |
|
261 | delete item; | |
254 | m_labels.removeAt(row); |
|
262 | m_labels.removeAt(row); | |
255 | } |
|
263 | } | |
256 | endRemoveRows(); |
|
264 | endRemoveRows(); | |
257 | return true; |
|
265 | return true; | |
258 | } |
|
266 | } | |
|
267 | ||||
|
268 | void CustomTableModel::addMapping(QString color, QRect area) | |||
|
269 | { | |||
|
270 | m_mapping.insert(color, area); | |||
|
271 | } | |||
|
272 | ||||
|
273 | void CustomTableModel::addMapping(QString color, int left, int top, int right, int bottom) | |||
|
274 | { | |||
|
275 | addMapping(color, QRect(QPoint(left, top), QPoint(right, bottom))); | |||
|
276 | } |
@@ -1,56 +1,63 | |||||
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 XYPOINTSMODEL_H |
|
21 | #ifndef XYPOINTSMODEL_H | |
22 | #define XYPOINTSMODEL_H |
|
22 | #define XYPOINTSMODEL_H | |
23 |
|
23 | |||
24 | #include <QAbstractTableModel> |
|
24 | #include <QAbstractTableModel> | |
25 | #include <QPointF> |
|
25 | #include <QPointF> | |
26 | #include <QStringList> |
|
26 | #include <QStringList> | |
27 | #include <QColor> |
|
27 | //#include <QColor> | |
|
28 | #include <QHash> | |||
|
29 | #include <QRect> | |||
28 |
|
30 | |||
29 | class CustomTableModel : public QAbstractTableModel |
|
31 | class CustomTableModel : public QAbstractTableModel | |
30 | { |
|
32 | { | |
31 | Q_OBJECT |
|
33 | Q_OBJECT | |
32 | public: |
|
34 | public: | |
33 | explicit CustomTableModel(QObject *parent = 0); |
|
35 | explicit CustomTableModel(QObject *parent = 0); | |
34 |
|
36 | |||
35 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
37 | int rowCount ( const QModelIndex & parent = QModelIndex() ) const; | |
36 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; |
|
38 | int columnCount ( const QModelIndex & parent = QModelIndex() ) const; | |
37 | QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; |
|
39 | QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; | |
38 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; |
|
40 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | |
39 | 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 ); | |
40 | Qt::ItemFlags flags ( const QModelIndex & index ) const; |
|
42 | Qt::ItemFlags flags ( const QModelIndex & index ) const; | |
41 | bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() ); |
|
43 | bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() ); | |
42 | bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() ); |
|
44 | bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() ); | |
|
45 | ||||
|
46 | void addMapping(QString color, QRect area); | |||
|
47 | void addMapping(QString color, int left, int top, int right, int bottom); | |||
|
48 | void clearMapping() { m_mapping.clear(); } | |||
43 |
|
49 | |||
44 | //signals: |
|
50 | //signals: | |
45 |
|
51 | |||
46 | //public slots: |
|
52 | //public slots: | |
47 | private: |
|
53 | private: | |
48 | QList<QVector<qreal>* > m_data; |
|
54 | QList<QVector<qreal> * > m_data; | |
49 | QList<QVector<QColor>* > m_rowsColors; |
|
55 | // QList<QVector<QColor> * > m_rowsColors; | |
|
56 | QHash<QString, QRect> m_mapping; | |||
50 | QList<QPointF> m_points; |
|
57 | QList<QPointF> m_points; | |
51 | QStringList m_labels; |
|
58 | QStringList m_labels; | |
52 |
|
59 | |||
53 |
|
60 | |||
54 | }; |
|
61 | }; | |
55 |
|
62 | |||
56 | #endif // XYPOINTSMODEL_H |
|
63 | #endif // XYPOINTSMODEL_H |
@@ -1,309 +1,306 | |||||
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 "tablewidget.h" |
|
21 | #include "tablewidget.h" | |
22 | #include <QGridLayout> |
|
22 | #include <QGridLayout> | |
23 | #include <QTableView> |
|
23 | #include <QTableView> | |
24 | #include <QStyledItemDelegate> |
|
24 | #include <QStyledItemDelegate> | |
25 |
#include |
|
25 | #include <QLineSeries> | |
26 |
#include |
|
26 | #include <QSplineSeries> | |
27 |
#include |
|
27 | #include <QScatterSeries> | |
28 | #include "customtablemodel.h" |
|
28 | #include "customtablemodel.h" | |
29 |
#include |
|
29 | #include <QPieSeries> | |
30 | #include "qareaseries.h" |
|
30 | #include <QPieSlice> | |
31 |
#include |
|
31 | #include <QAreaSeries> | |
|
32 | #include <QBarSeries> | |||
|
33 | #include <QBarSet> | |||
32 | #include <QPushButton> |
|
34 | #include <QPushButton> | |
33 | #include <QRadioButton> |
|
35 | #include <QRadioButton> | |
34 | #include <QSpinBox> |
|
36 | #include <QSpinBox> | |
35 | #include <QTime> |
|
37 | #include <QTime> | |
36 |
|
38 | |||
37 | TableWidget::TableWidget(QWidget *parent) |
|
39 | TableWidget::TableWidget(QWidget *parent) | |
38 | : QWidget(parent) |
|
40 | : QWidget(parent) | |
39 | { |
|
41 | { | |
40 | setGeometry(100, 100, 1000, 600); |
|
42 | setGeometry(100, 100, 1000, 600); | |
41 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
43 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
42 | // create simple model for storing data |
|
44 | // create simple model for storing data | |
43 | // user's table data model |
|
45 | // user's table data model | |
44 | m_model = new CustomTableModel; |
|
46 | m_model = new CustomTableModel; | |
45 | m_tableView = new QTableView; |
|
47 | m_tableView = new QTableView; | |
46 | m_tableView->setModel(m_model); |
|
48 | m_tableView->setModel(m_model); | |
47 | m_tableView->setMinimumHeight(240); |
|
49 | m_tableView->setMinimumHeight(240); | |
48 | // tableView->setMinimumSize(340, 480); |
|
50 | // tableView->setMinimumSize(340, 480); | |
49 | // tableView->setItemDelegate(new QStyledItemDelegate); |
|
51 | // tableView->setItemDelegate(new QStyledItemDelegate); | |
50 | m_chart = new QChart; |
|
52 | m_chart = new QChart; | |
51 | m_chartView = new QChartView(m_chart); |
|
53 | m_chartView = new QChartView(m_chart); | |
52 | m_chartView->setRenderHint(QPainter::Antialiasing); |
|
54 | m_chartView->setRenderHint(QPainter::Antialiasing); | |
53 | m_chartView->setMinimumSize(640, 480); |
|
55 | m_chartView->setMinimumSize(640, 480); | |
54 |
|
56 | |||
55 | // create |
|
|||
56 | // QLineSeries* series = new QLineSeries; |
|
|||
57 | // QSplineSeries* series = new QSplineSeries; |
|
|||
58 | // QScatterSeries* series = new QScatterSeries; |
|
|||
59 | // series->setModel(m_model); |
|
|||
60 | // series->setModelMapping(0,1, Qt::Vertical); |
|
|||
61 |
|
||||
62 | // QPieSeries* pieSeries = new QPieSeries; |
|
|||
63 | // pieSeries->setModel(model); |
|
|||
64 | // pieSeries |
|
|||
65 |
|
||||
66 | // chartView->addSeries(series); |
|
|||
67 |
|
||||
68 | // add, remove data buttons |
|
57 | // add, remove data buttons | |
69 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); |
|
58 | QPushButton* addRowAboveButton = new QPushButton("Add row above"); | |
70 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); |
|
59 | connect(addRowAboveButton, SIGNAL(clicked()), this, SLOT(addRowAbove())); | |
71 |
|
60 | |||
72 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); |
|
61 | QPushButton* addRowBelowButton = new QPushButton("Add row below"); | |
73 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); |
|
62 | connect(addRowBelowButton, SIGNAL(clicked()), this, SLOT(addRowBelow())); | |
74 |
|
63 | |||
75 | QPushButton* removeRowButton = new QPushButton("Remove row"); |
|
64 | QPushButton* removeRowButton = new QPushButton("Remove row"); | |
76 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); |
|
65 | connect(removeRowButton, SIGNAL(clicked()), this, SLOT(removeRow())); | |
77 |
|
66 | |||
78 | m_linesCountSpinBox = new QSpinBox; |
|
67 | m_linesCountSpinBox = new QSpinBox; | |
79 | m_linesCountSpinBox->setRange(1, 10); |
|
68 | m_linesCountSpinBox->setRange(1, 10); | |
80 | m_linesCountSpinBox->setValue(1); |
|
69 | m_linesCountSpinBox->setValue(1); | |
81 |
|
70 | |||
82 | // buttons layout |
|
71 | // buttons layout | |
83 | QVBoxLayout* buttonsLayout = new QVBoxLayout; |
|
72 | QVBoxLayout* buttonsLayout = new QVBoxLayout; | |
84 | buttonsLayout->addWidget(m_linesCountSpinBox); |
|
73 | buttonsLayout->addWidget(m_linesCountSpinBox); | |
85 | buttonsLayout->addWidget(addRowAboveButton); |
|
74 | buttonsLayout->addWidget(addRowAboveButton); | |
86 | buttonsLayout->addWidget(addRowBelowButton); |
|
75 | buttonsLayout->addWidget(addRowBelowButton); | |
87 | buttonsLayout->addWidget(removeRowButton); |
|
76 | buttonsLayout->addWidget(removeRowButton); | |
88 | buttonsLayout->addStretch(); |
|
77 | buttonsLayout->addStretch(); | |
89 |
|
78 | |||
90 | // chart type radio buttons |
|
79 | // chart type radio buttons | |
91 | m_lineRadioButton = new QRadioButton("Line"); |
|
80 | m_lineRadioButton = new QRadioButton("Line"); | |
92 | m_splineRadioButton = new QRadioButton("Spline"); |
|
81 | m_splineRadioButton = new QRadioButton("Spline"); | |
93 | m_scatterRadioButton = new QRadioButton("Scatter"); |
|
82 | m_scatterRadioButton = new QRadioButton("Scatter"); | |
94 | m_pieRadioButton = new QRadioButton("Pie"); |
|
83 | m_pieRadioButton = new QRadioButton("Pie"); | |
95 | m_areaRadioButton = new QRadioButton("Area"); |
|
84 | m_areaRadioButton = new QRadioButton("Area"); | |
96 | m_barRadioButton = new QRadioButton("Bar"); |
|
85 | m_barRadioButton = new QRadioButton("Bar"); | |
97 |
|
86 | |||
98 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
87 | connect(m_lineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
99 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
88 | connect(m_splineRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
100 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
89 | connect(m_scatterRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
101 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
90 | connect(m_pieRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
102 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
91 | connect(m_areaRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
103 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); |
|
92 | connect(m_barRadioButton, SIGNAL(toggled(bool)), this, SLOT(updateChartType())); | |
104 | m_lineRadioButton->setChecked(true); |
|
93 | m_lineRadioButton->setChecked(true); | |
105 |
|
94 | |||
106 | // radio buttons layout |
|
95 | // radio buttons layout | |
107 | QVBoxLayout* radioLayout = new QVBoxLayout; |
|
96 | QVBoxLayout* radioLayout = new QVBoxLayout; | |
108 | radioLayout->addWidget(m_lineRadioButton); |
|
97 | radioLayout->addWidget(m_lineRadioButton); | |
109 | radioLayout->addWidget(m_splineRadioButton); |
|
98 | radioLayout->addWidget(m_splineRadioButton); | |
110 | radioLayout->addWidget(m_scatterRadioButton); |
|
99 | radioLayout->addWidget(m_scatterRadioButton); | |
111 | radioLayout->addWidget(m_pieRadioButton); |
|
100 | radioLayout->addWidget(m_pieRadioButton); | |
112 | radioLayout->addWidget(m_areaRadioButton); |
|
101 | radioLayout->addWidget(m_areaRadioButton); | |
113 | radioLayout->addWidget(m_barRadioButton); |
|
102 | radioLayout->addWidget(m_barRadioButton); | |
114 | radioLayout->addStretch(); |
|
103 | radioLayout->addStretch(); | |
115 |
|
104 | |||
116 | // create main layout |
|
105 | // create main layout | |
117 | QGridLayout* mainLayout = new QGridLayout; |
|
106 | QGridLayout* mainLayout = new QGridLayout; | |
118 | mainLayout->addLayout(buttonsLayout, 1, 1); |
|
107 | mainLayout->addLayout(buttonsLayout, 1, 1); | |
119 | mainLayout->addLayout(radioLayout, 2, 1); |
|
108 | mainLayout->addLayout(radioLayout, 2, 1); | |
120 | mainLayout->addWidget(m_tableView, 1, 0); |
|
109 | mainLayout->addWidget(m_tableView, 1, 0); | |
121 | mainLayout->addWidget(m_chartView, 2, 0); |
|
110 | mainLayout->addWidget(m_chartView, 2, 0); | |
122 |
setLayout(mainLayout); |
|
111 | setLayout(mainLayout); | |
123 | m_lineRadioButton->setFocus(); |
|
112 | m_lineRadioButton->setFocus(); | |
124 | } |
|
113 | } | |
125 |
|
114 | |||
126 | void TableWidget::addRowAbove() |
|
115 | void TableWidget::addRowAbove() | |
127 | { |
|
116 | { | |
128 | // m_model->insertRow(m_model->rowCount()); |
|
|||
129 | // m_model->insertRow(tableView->currentIndex().row()); |
|
|||
130 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); |
|
117 | m_model->insertRows(m_tableView->currentIndex().row(), m_linesCountSpinBox->value()); | |
131 |
|
118 | |||
132 | } |
|
119 | } | |
133 |
|
120 | |||
134 | void TableWidget::addRowBelow() |
|
121 | void TableWidget::addRowBelow() | |
135 | { |
|
122 | { | |
136 | // m_model->insertRow(m_model->rowCount()); |
|
|||
137 | // m_model->insertRow(tableView->currentIndex().row() + 1); |
|
|||
138 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); |
|
123 | m_model->insertRows(m_tableView->currentIndex().row() + 1, m_linesCountSpinBox->value()); | |
139 |
|
124 | |||
140 | } |
|
125 | } | |
141 |
|
126 | |||
142 | void TableWidget::removeRow() |
|
127 | void TableWidget::removeRow() | |
143 | { |
|
128 | { | |
144 | // m_model->removeRow(m_model->rowCount() - 1); |
|
|||
145 | // m_model->removeRow(tableView->currentIndex().row()); |
|
|||
146 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); |
|
129 | m_model->removeRows(m_tableView->currentIndex().row(), qMin(m_model->rowCount() - m_tableView->currentIndex().row(), m_linesCountSpinBox->value())); | |
147 | } |
|
130 | } | |
148 |
|
131 | |||
149 | void TableWidget::updateChartType() |
|
132 | void TableWidget::updateChartType() | |
150 | { |
|
133 | { | |
151 | m_chart->removeAllSeries(); |
|
134 | m_chart->removeAllSeries(); | |
|
135 | m_model->clearMapping(); | |||
|
136 | ||||
|
137 | QString seriesColorHex = "#000000"; | |||
|
138 | QPen pen; | |||
|
139 | pen.setWidth(2); | |||
152 |
|
140 | |||
153 | if (m_lineRadioButton->isChecked()) |
|
141 | if (m_lineRadioButton->isChecked()) | |
154 | { |
|
142 | { | |
155 | QPen pen; |
|
|||
156 | pen.setWidth(2); |
|
|||
157 |
|
143 | |||
158 | QColor seriesColor("#8FBC8F"); |
|
144 | m_chart->axisX()->setRange(0, 500); | |
|
145 | m_chart->axisY()->setRange(0, 120); | |||
159 |
|
146 | |||
160 | // series 1 |
|
147 | // series 1 | |
161 | m_series = new QLineSeries; |
|
148 | m_series = new QLineSeries; | |
162 | m_series->setModel(m_model); |
|
149 | m_series->setModel(m_model); | |
163 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
150 | m_series->setModelMapping(0,1, Qt::Vertical); | |
164 |
m_series->setModelMappingShift( |
|
151 | m_series->setModelMappingShift(1, 4); | |
165 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
|||
166 |
|
||||
167 | pen.setColor(seriesColor); |
|
|||
168 | m_series->setPen(pen); |
|
|||
169 | m_chart->addSeries(m_series); |
|
152 | m_chart->addSeries(m_series); | |
170 | for (int i = 1; i <=4; i++) |
|
153 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
171 | { |
|
154 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |
172 | m_model->setData(m_model->index(i, 0), seriesColor , Qt::BackgroundRole); |
|
|||
173 | m_model->setData(m_model->index(i, 1), seriesColor , Qt::BackgroundRole); |
|
|||
174 | } |
|
|||
175 | // tableView->setsetStyleSheet("QTableView { border: 2px solid red }"); |
|
|||
176 |
|
||||
177 | seriesColor = QColor("#1E90FF"); |
|
|||
178 |
|
155 | |||
179 | // series 2 |
|
156 | // series 2 | |
180 | m_series = new QLineSeries; |
|
157 | m_series = new QLineSeries; | |
181 | m_series->setModel(m_model); |
|
158 | m_series->setModel(m_model); | |
182 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
159 | m_series->setModelMapping(2,3, Qt::Vertical); | |
183 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
160 | m_chart->addSeries(m_series); | |
184 | pen.setColor(seriesColor); |
|
161 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
185 | m_series->setPen(pen); |
|
162 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |
186 | // m_chart->addSeries(m_series); |
|
|||
187 |
|
||||
188 | m_chart->axisX()->setRange(0, 500); |
|
|||
189 | m_chart->axisY()->setRange(0, 120); |
|
|||
190 |
|
163 | |||
191 | for (int i = 0; i < m_model->rowCount(); i++) |
|
164 | // series 3 | |
192 | { |
|
165 | m_series = new QLineSeries; | |
193 | m_model->setData(m_model->index(i, 2), seriesColor , Qt::BackgroundRole); |
|
166 | m_series->setModel(m_model); | |
194 | m_model->setData(m_model->index(i, 3), seriesColor , Qt::BackgroundRole); |
|
167 | m_series->setModelMapping(4,5, Qt::Vertical); | |
195 | } |
|
168 | m_series->setModelMappingShift(2, 0); | |
196 | // // series 3 |
|
169 | m_chart->addSeries(m_series); | |
197 | // series = new QLineSeries; |
|
170 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |
198 | // series->setModel(m_model); |
|
171 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |
199 | // series->setModelMapping(4,5, Qt::Vertical); |
|
|||
200 | //// series->setModelMapping(4,5, Qt::Horizontal); |
|
|||
201 | // chartView->addSeries(series); |
|
|||
202 | } |
|
172 | } | |
203 | else if (m_splineRadioButton->isChecked()) |
|
173 | else if (m_splineRadioButton->isChecked()) | |
204 | { |
|
174 | { | |
205 | // series 1 |
|
175 | // series 1 | |
206 | m_series = new QSplineSeries; |
|
176 | m_series = new QSplineSeries; | |
207 | m_series->setModel(m_model); |
|
177 | m_series->setModel(m_model); | |
208 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
178 | m_series->setModelMapping(0,1, Qt::Vertical); | |
209 | m_series->setModelMappingShift(1, 4); |
|
179 | m_series->setModelMappingShift(1, 4); | |
210 | // series->setModelMapping(0,1, Qt::Horizontal); |
|
180 | // series->setModelMapping(0,1, Qt::Horizontal); | |
211 | m_chart->addSeries(m_series); |
|
181 | m_chart->addSeries(m_series); | |
|
182 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |||
|
183 | m_model->addMapping(seriesColorHex, QRect(0, 1, 2, 4)); | |||
212 |
|
184 | |||
213 | // series 2 |
|
185 | // series 2 | |
214 | m_series = new QSplineSeries; |
|
186 | m_series = new QSplineSeries; | |
215 | m_series->setModel(m_model); |
|
187 | m_series->setModel(m_model); | |
216 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
188 | m_series->setModelMapping(2,3, Qt::Vertical); | |
217 | m_series->setModelMappingShift(0, 0); |
|
189 | m_series->setModelMappingShift(0, 0); | |
218 | // series->setModelMapping(2,3, Qt::Horizontal); |
|
190 | // series->setModelMapping(2,3, Qt::Horizontal); | |
219 | m_chart->addSeries(m_series); |
|
191 | m_chart->addSeries(m_series); | |
|
192 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |||
|
193 | m_model->addMapping(seriesColorHex, QRect(2, 0, 2, 1000)); | |||
220 |
|
194 | |||
221 | // series 3 |
|
195 | // series 3 | |
222 | m_series = new QSplineSeries; |
|
196 | m_series = new QSplineSeries; | |
223 | m_series->setModel(m_model); |
|
197 | m_series->setModel(m_model); | |
224 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
198 | m_series->setModelMapping(4,5, Qt::Vertical); | |
225 |
m_series->setModelMappingShift( |
|
199 | m_series->setModelMappingShift(2, 0); | |
226 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
200 | // series->setModelMapping(4,5, Qt::Horizontal); | |
227 | m_chart->addSeries(m_series); |
|
201 | m_chart->addSeries(m_series); | |
|
202 | seriesColorHex = "#" + QString::number(m_series->pen().color().rgb(), 16).right(6).toUpper(); | |||
|
203 | m_model->addMapping(seriesColorHex, QRect(4, 2, 2, 1000)); | |||
228 | } |
|
204 | } | |
229 | else if (m_scatterRadioButton->isChecked()) |
|
205 | else if (m_scatterRadioButton->isChecked()) | |
230 | { |
|
206 | { | |
231 | // series 1 |
|
207 | // series 1 | |
232 | m_series = new QScatterSeries; |
|
208 | m_series = new QScatterSeries; | |
233 | m_series->setModel(m_model); |
|
209 | m_series->setModel(m_model); | |
234 | m_series->setModelMapping(0,1, Qt::Vertical); |
|
210 | m_series->setModelMapping(0,1, Qt::Vertical); | |
235 |
|
|
211 | m_series->setModelMappingShift(2, 0); | |
|
212 | // series->setModelMapping(0,1, Qt::Horizontal); | |||
236 | m_chart->addSeries(m_series); |
|
213 | m_chart->addSeries(m_series); | |
237 |
|
214 | |||
|
215 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
216 | m_model->addMapping(seriesColorHex, QRect(0, 2, 2, 1000)); | |||
|
217 | ||||
238 | // series 2 |
|
218 | // series 2 | |
239 | m_series = new QScatterSeries; |
|
219 | m_series = new QScatterSeries; | |
240 | m_series->setModel(m_model); |
|
220 | m_series->setModel(m_model); | |
241 | m_series->setModelMapping(2,3, Qt::Vertical); |
|
221 | m_series->setModelMapping(2,3, Qt::Vertical); | |
242 |
|
|
222 | m_series->setModelMappingShift(1, 6); | |
|
223 | // series->setModelMapping(2,3, Qt::Horizontal); | |||
243 | m_chart->addSeries(m_series); |
|
224 | m_chart->addSeries(m_series); | |
244 |
|
225 | |||
|
226 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
227 | m_model->addMapping(seriesColorHex, QRect(2, 1, 2, 6)); | |||
|
228 | ||||
245 | // series 3 |
|
229 | // series 3 | |
246 | m_series = new QScatterSeries; |
|
230 | m_series = new QScatterSeries; | |
247 | m_series->setModel(m_model); |
|
231 | m_series->setModel(m_model); | |
248 | m_series->setModelMapping(4,5, Qt::Vertical); |
|
232 | m_series->setModelMapping(4,5, Qt::Vertical); | |
249 | // series->setModelMapping(4,5, Qt::Horizontal); |
|
233 | // series->setModelMapping(4,5, Qt::Horizontal); | |
250 | m_chart->addSeries(m_series); |
|
234 | m_chart->addSeries(m_series); | |
|
235 | seriesColorHex = "#" + QString::number(m_series->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
236 | m_model->addMapping(seriesColorHex, QRect(4, 0, 2, 1000)); | |||
251 | } |
|
237 | } | |
252 | else if (m_pieRadioButton->isChecked()) |
|
238 | else if (m_pieRadioButton->isChecked()) | |
253 | { |
|
239 | { | |
254 | // pie 1 |
|
240 | // pie 1 | |
255 | QPieSeries* pieSeries = new QPieSeries; |
|
241 | QPieSeries* pieSeries = new QPieSeries; | |
256 | pieSeries->setModel(m_model); |
|
242 | pieSeries->setModel(m_model); | |
257 | pieSeries->setModelMapping(0,0, Qt::Vertical); |
|
243 | pieSeries->setModelMapping(0,0, Qt::Vertical); | |
258 | pieSeries->setLabelsVisible(true); |
|
244 | pieSeries->setLabelsVisible(true); | |
259 | pieSeries->setPieSize(0.4); |
|
245 | pieSeries->setPieSize(0.4); | |
260 | pieSeries->setPiePosition(0.2, 0.35); |
|
246 | pieSeries->setPiePosition(0.2, 0.35); | |
|
247 | ||||
261 | m_chart->addSeries(pieSeries); |
|
248 | m_chart->addSeries(pieSeries); | |
|
249 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
250 | m_model->addMapping(seriesColorHex, QRect(0, 0, 1, 1000)); | |||
262 |
|
251 | |||
263 | // pie 2 |
|
252 | // pie 2 | |
264 | pieSeries = new QPieSeries; |
|
253 | pieSeries = new QPieSeries; | |
265 | pieSeries->setModel(m_model); |
|
254 | pieSeries->setModel(m_model); | |
266 | pieSeries->setModelMapping(1,1, Qt::Vertical); |
|
255 | pieSeries->setModelMapping(1,1, Qt::Vertical); | |
267 | pieSeries->setLabelsVisible(true); |
|
256 | pieSeries->setLabelsVisible(true); | |
268 | pieSeries->setPieSize(0.4); |
|
257 | pieSeries->setPieSize(0.4); | |
269 | pieSeries->setPiePosition(0.8, 0.35); |
|
258 | pieSeries->setPiePosition(0.8, 0.35); | |
270 | m_chart->addSeries(pieSeries); |
|
259 | m_chart->addSeries(pieSeries); | |
|
260 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
261 | m_model->addMapping(seriesColorHex, QRect(1, 0, 1, 1000)); | |||
271 |
|
262 | |||
272 | // pie 3 |
|
263 | // pie 3 | |
273 | pieSeries = new QPieSeries; |
|
264 | pieSeries = new QPieSeries; | |
274 | pieSeries->setModel(m_model); |
|
265 | pieSeries->setModel(m_model); | |
275 | pieSeries->setModelMapping(2,2, Qt::Vertical); |
|
266 | pieSeries->setModelMapping(2,2, Qt::Vertical); | |
276 | pieSeries->setLabelsVisible(true); |
|
267 | pieSeries->setLabelsVisible(true); | |
277 | pieSeries->setPieSize(0.4); |
|
268 | pieSeries->setPieSize(0.4); | |
278 | pieSeries->setPiePosition(0.5, 0.65); |
|
269 | pieSeries->setPiePosition(0.5, 0.65); | |
279 | m_chart->addSeries(pieSeries); |
|
270 | m_chart->addSeries(pieSeries); | |
|
271 | seriesColorHex = "#" + QString::number(pieSeries->slices().at(pieSeries->slices().count()/2)->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
272 | m_model->addMapping(seriesColorHex, QRect(2, 0, 1, 1000)); | |||
280 | } |
|
273 | } | |
281 | else if (m_areaRadioButton->isChecked()) |
|
274 | else if (m_areaRadioButton->isChecked()) | |
282 | { |
|
275 | { | |
283 | QLineSeries* upperLineSeries = new QLineSeries; |
|
276 | QLineSeries* upperLineSeries = new QLineSeries; | |
284 | upperLineSeries->setModel(m_model); |
|
277 | upperLineSeries->setModel(m_model); | |
285 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); |
|
278 | upperLineSeries->setModelMapping(0, 1, Qt::Vertical); | |
286 | QLineSeries* lowerLineSeries = new QLineSeries; |
|
279 | QLineSeries* lowerLineSeries = new QLineSeries; | |
287 | lowerLineSeries->setModel(m_model); |
|
280 | lowerLineSeries->setModel(m_model); | |
288 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); |
|
281 | lowerLineSeries->setModelMapping(2, 3, Qt::Vertical); | |
289 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); |
|
282 | QAreaSeries* areaSeries = new QAreaSeries(upperLineSeries, lowerLineSeries); | |
290 | m_chart->addSeries(areaSeries); |
|
283 | m_chart->addSeries(areaSeries); | |
291 | } |
|
284 | } | |
292 | else if (m_barRadioButton->isChecked()) |
|
285 | else if (m_barRadioButton->isChecked()) | |
293 | { |
|
286 | { | |
294 | QBarSeries* barSeries = new QBarSeries(QStringList()); |
|
287 | QBarSeries* barSeries = new QBarSeries(QStringList()); | |
295 | barSeries->setModel(m_model); |
|
288 | barSeries->setModel(m_model); | |
296 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); |
|
289 | barSeries->setModelMapping(5, 2, 4, Qt::Vertical); | |
297 | barSeries->setToolTipEnabled(true); |
|
290 | barSeries->setToolTipEnabled(true); | |
298 | m_chart->addSeries(barSeries); |
|
291 | m_chart->addSeries(barSeries); | |
|
292 | for (int i = 0; i < barSeries->barsetCount(); i++) { | |||
|
293 | seriesColorHex = "#" + QString::number(barSeries->barsetAt(i)->brush().color().rgb(), 16).right(6).toUpper(); | |||
|
294 | m_model->addMapping(seriesColorHex, QRect(2 + i, 0, 1, 1000)); | |||
|
295 | } | |||
299 | } |
|
296 | } | |
300 |
|
297 | |||
301 | // series->setModel(m_model); |
|
298 | // repaint table view colors | |
302 | // series->setModelMapping(0,1, Qt::Vertical); |
|
299 | m_tableView->repaint(); | |
303 | // chartView->addSeries(series); |
|
300 | m_tableView->setFocus(); | |
304 | } |
|
301 | } | |
305 |
|
302 | |||
306 | TableWidget::~TableWidget() |
|
303 | TableWidget::~TableWidget() | |
307 | { |
|
304 | { | |
308 |
|
305 | |||
309 | } |
|
306 | } |
General Comments 0
You need to be logged in to leave comments.
Login now