@@ -1,231 +1,301 | |||||
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 "grid.h" |
|
21 | #include "grid.h" | |
22 | #include "charts.h" |
|
22 | #include "charts.h" | |
23 | #include <qchart.h> |
|
23 | #include <qchart.h> | |
24 | #include <QGraphicsGridLayout> |
|
24 | #include <QGraphicsGridLayout> | |
25 | #include <QGraphicsSceneMouseEvent> |
|
25 | #include <QGraphicsSceneMouseEvent> | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 |
|
27 | |||
28 | Grid::Grid(int size, QGraphicsItem *parent) |
|
28 | Grid::Grid(int size, QGraphicsItem *parent) | |
29 | : QGraphicsWidget(parent), |
|
29 | : QGraphicsWidget(parent), | |
30 | m_listCount(3), |
|
30 | m_listCount(3), | |
31 | m_valueMax(10), |
|
31 | m_valueMax(10), | |
32 | m_valueCount(7), |
|
32 | m_valueCount(7), | |
33 | m_size(size), |
|
33 | m_size(size), | |
34 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), |
|
34 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
35 | m_state(NoState), |
|
35 | m_state(NoState), | |
36 | m_currentState(NoState), |
|
36 | m_currentState(NoState), | |
37 | m_rubberBand(new QGraphicsRectItem()), |
|
37 | m_rubberBand(new QGraphicsRectItem()), | |
38 | m_gridLayout(new QGraphicsGridLayout()) |
|
38 | m_gridLayout(new QGraphicsGridLayout()) | |
39 | { |
|
39 | { | |
40 | setLayout(m_gridLayout); |
|
40 | setLayout(m_gridLayout); | |
41 | m_rubberBand->setParentItem(this); |
|
41 | m_rubberBand->setParentItem(this); | |
42 | m_rubberBand->setVisible(false); |
|
42 | m_rubberBand->setVisible(false); | |
43 | m_rubberBand->setZValue(2); |
|
43 | m_rubberBand->setZValue(2); | |
44 | } |
|
44 | } | |
45 |
|
45 | |||
46 | Grid::~Grid() |
|
46 | Grid::~Grid() | |
47 | { |
|
47 | { | |
48 |
|
48 | |||
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void Grid::createCharts(const QString &category) |
|
51 | void Grid::createCharts(const QString &category) | |
52 | { |
|
52 | { | |
53 | clear(); |
|
53 | clear(); | |
54 |
|
54 | |||
55 | QChart *qchart(0); |
|
55 | QChart *qchart(0); | |
56 | Charts::ChartList list = Charts::chartList(); |
|
56 | Charts::ChartList list = Charts::chartList(); | |
57 |
|
57 | |||
58 | if (category.isEmpty()) { |
|
58 | if (category.isEmpty()) { | |
59 | for (int i = 0; i < m_size * m_size; ++i) { |
|
59 | for (int i = 0; i < m_size * m_size; ++i) { | |
60 |
QChart *chart = |
|
60 | QChart *chart = new QChart(); | |
61 | if (i < list.size()) { |
|
61 | chart->setTitle(QObject::tr("Empty")); | |
62 | chart = list.at(i)->createChart(m_dataTable); |
|
|||
63 | } else { |
|
|||
64 | chart = new QChart(); |
|
|||
65 | chart->setTitle(QObject::tr("Empty")); |
|
|||
66 | } |
|
|||
67 | m_gridLayout->addItem(chart, i / m_size, i % m_size); |
|
62 | m_gridLayout->addItem(chart, i / m_size, i % m_size); | |
68 | m_chartHash[chart] = i; |
|
63 | m_chartHash[chart] = i; | |
|
64 | m_chartHashRev[i] = chart; | |||
69 | } |
|
65 | } | |
70 | } else { |
|
66 | } else { | |
71 | int j = 0; |
|
67 | int j = 0; | |
72 | for (int i = 0; i < list.size(); ++i) { |
|
68 | for (int i = 0; i < list.size(); ++i) { | |
73 | Chart *chart = list.at(i); |
|
69 | Chart *chart = list.at(i); | |
74 | if (chart->category() == category && j < m_size * m_size) { |
|
70 | if (chart->category() == category && j < m_size * m_size) { | |
75 | qchart = list.at(i)->createChart(m_dataTable); |
|
71 | qchart = list.at(i)->createChart(m_dataTable); | |
76 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); |
|
72 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |
77 | m_chartHash[qchart] = j; |
|
73 | m_chartHash[qchart] = j; | |
|
74 | m_chartHashRev[j] = qchart; | |||
78 | j++; |
|
75 | j++; | |
79 | } |
|
76 | } | |
80 | } |
|
77 | } | |
81 | for (; j < m_size * m_size; ++j) { |
|
78 | for (; j < m_size * m_size; ++j) { | |
82 | qchart = new QChart(); |
|
79 | qchart = new QChart(); | |
83 | qchart->setTitle(QObject::tr("Empty")); |
|
80 | qchart->setTitle(QObject::tr("Empty")); | |
84 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); |
|
81 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |
85 | m_chartHash[qchart] = j; |
|
82 | m_chartHash[qchart] = j; | |
|
83 | m_chartHashRev[j] = qchart; | |||
86 | } |
|
84 | } | |
87 | } |
|
85 | } | |
88 | m_category = category; |
|
86 | m_gridLayout->activate(); | |
|
87 | } | |||
|
88 | ||||
|
89 | void Grid::createCharts(const QString &category, const QString &subcategory, const QString &name) | |||
|
90 | { | |||
|
91 | clear(); | |||
|
92 | ||||
|
93 | QChart *qchart(0); | |||
|
94 | Charts::ChartList list = Charts::chartList(); | |||
|
95 | Chart *chart; | |||
|
96 | ||||
|
97 | //find chart | |||
|
98 | for (int i = 0; i < list.size(); ++i) { | |||
|
99 | ||||
|
100 | chart = list.at(i); | |||
|
101 | if (chart->category() == category && | |||
|
102 | chart->subCategory() == subcategory && | |||
|
103 | chart->name() == name) { | |||
|
104 | break; | |||
|
105 | } | |||
|
106 | chart = 0; | |||
|
107 | } | |||
|
108 | ||||
|
109 | //create charts | |||
|
110 | for (int j = 0; j < m_size * m_size; ++j) { | |||
|
111 | ||||
|
112 | if(!chart){ | |||
|
113 | qchart = new QChart(); | |||
|
114 | }else{ | |||
|
115 | qchart = chart->createChart(m_dataTable); | |||
|
116 | } | |||
|
117 | qchart->setTitle(QObject::tr("Empty")); | |||
|
118 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |||
|
119 | m_chartHash[qchart] = j; | |||
|
120 | m_chartHashRev[j] = qchart; | |||
|
121 | } | |||
|
122 | ||||
89 | m_gridLayout->activate(); |
|
123 | m_gridLayout->activate(); | |
90 | } |
|
124 | } | |
91 |
|
125 | |||
92 | void Grid::clear() |
|
126 | void Grid::clear() | |
93 | { |
|
127 | { | |
94 |
|
|
128 | int count = m_gridLayout->count(); | |
95 | m_gridLayout->removeAt(i); |
|
129 | for (int i = 0; i < count; ++i) | |
|
130 | m_gridLayout->removeAt(0); | |||
96 |
|
131 | |||
97 | qDeleteAll(m_chartHash.keys()); |
|
132 | qDeleteAll(m_chartHash.keys()); | |
98 | m_chartHash.clear(); |
|
133 | m_chartHash.clear(); | |
|
134 | m_chartHashRev.clear(); | |||
99 | } |
|
135 | } | |
100 |
|
136 | |||
101 | QList<QChart *> Grid::charts() |
|
137 | QList<QChart *> Grid::charts() | |
102 | { |
|
138 | { | |
103 | return m_chartHash.keys(); |
|
139 | return m_chartHash.keys(); | |
104 | } |
|
140 | } | |
105 |
|
141 | |||
106 | void Grid::setState(State state) |
|
142 | void Grid::setState(State state) | |
107 | { |
|
143 | { | |
108 | m_state = state; |
|
144 | m_state = state; | |
109 | } |
|
145 | } | |
110 |
|
146 | |||
111 | void Grid::setSize(int size) |
|
147 | void Grid::setSize(int size) | |
112 | { |
|
148 | { | |
113 | if (m_size != size) { |
|
149 | if (m_size != size) { | |
|
150 | ||||
|
151 | //remove old; | |||
|
152 | int count = m_gridLayout->count(); | |||
|
153 | for (int i = 0; i < count; ++i) { | |||
|
154 | m_gridLayout->removeAt(0); | |||
|
155 | } | |||
|
156 | ||||
|
157 | ||||
|
158 | QChart* qchart = 0; | |||
|
159 | int j = 0; | |||
|
160 | ||||
|
161 | for (; j < size * size; ++j) { | |||
|
162 | ||||
|
163 | qchart = m_chartHashRev[j]; | |||
|
164 | ||||
|
165 | if (!qchart){ | |||
|
166 | qchart = new QChart(); | |||
|
167 | qchart->setTitle(QObject::tr("Empty")); | |||
|
168 | } | |||
|
169 | ||||
|
170 | m_chartHash[qchart] = j; | |||
|
171 | m_chartHashRev[j] = qchart; | |||
|
172 | m_gridLayout->addItem(qchart, j / size, j % size); | |||
|
173 | } | |||
|
174 | ||||
|
175 | //delete rest | |||
|
176 | while (j < m_size * m_size) { | |||
|
177 | QChart* qchart = m_chartHashRev.take(j); | |||
|
178 | delete(qchart); | |||
|
179 | m_chartHash.remove(qchart); | |||
|
180 | j++; | |||
|
181 | } | |||
|
182 | ||||
114 | m_size = size; |
|
183 | m_size = size; | |
115 | createCharts(m_category); |
|
|||
116 | } |
|
184 | } | |
117 | } |
|
185 | } | |
118 |
|
186 | |||
119 | void Grid::setRubberPen(const QPen &pen) |
|
187 | void Grid::setRubberPen(const QPen &pen) | |
120 | { |
|
188 | { | |
121 | m_rubberBand->setPen(pen); |
|
189 | m_rubberBand->setPen(pen); | |
122 | } |
|
190 | } | |
123 |
|
191 | |||
124 | void Grid::replaceChart(QChart *oldChart, Chart *newChart) |
|
192 | void Grid::replaceChart(QChart *oldChart, Chart *newChart) | |
125 | { |
|
193 | { | |
126 | int index = m_chartHash[oldChart]; |
|
194 | int index = m_chartHash[oldChart]; | |
127 | //not in 4.7.2 m_baseLayout->removeItem(qchart); |
|
195 | //not in 4.7.2 m_baseLayout->removeItem(qchart); | |
128 | for (int i = 0; i < m_gridLayout->count(); ++i) { |
|
196 | for (int i = 0; i < m_gridLayout->count(); ++i) { | |
129 | if (m_gridLayout->itemAt(i) == oldChart) { |
|
197 | if (m_gridLayout->itemAt(i) == oldChart) { | |
130 | m_gridLayout->removeAt(i); |
|
198 | m_gridLayout->removeAt(i); | |
131 | break; |
|
199 | break; | |
132 | } |
|
200 | } | |
133 | } |
|
201 | } | |
134 | m_chartHash.remove(oldChart); |
|
202 | m_chartHash.remove(oldChart); | |
|
203 | m_chartHashRev.remove(index); | |||
135 | QChart *chart = newChart->createChart(m_dataTable); |
|
204 | QChart *chart = newChart->createChart(m_dataTable); | |
136 | m_gridLayout->addItem(chart, index / m_size, index % m_size); |
|
205 | m_gridLayout->addItem(chart, index / m_size, index % m_size); | |
137 | m_chartHash[chart] = index; |
|
206 | m_chartHash[chart] = index; | |
|
207 | m_chartHashRev[index] = chart; | |||
138 | delete oldChart; |
|
208 | delete oldChart; | |
139 | } |
|
209 | } | |
140 |
|
210 | |||
141 | void Grid::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
211 | void Grid::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
142 | { |
|
212 | { | |
143 | if (event->button() == Qt::LeftButton) { |
|
213 | if (event->button() == Qt::LeftButton) { | |
144 |
|
214 | |||
145 | m_origin = event->pos(); |
|
215 | m_origin = event->pos(); | |
146 | m_currentState = NoState; |
|
216 | m_currentState = NoState; | |
147 |
|
217 | |||
148 | foreach (QChart *chart, charts()) { |
|
218 | foreach (QChart *chart, charts()) { | |
149 | QRectF geometryRect = chart->geometry(); |
|
219 | QRectF geometryRect = chart->geometry(); | |
150 | QRectF plotArea = chart->plotArea(); |
|
220 | QRectF plotArea = chart->plotArea(); | |
151 | plotArea.translate(geometryRect.topLeft()); |
|
221 | plotArea.translate(geometryRect.topLeft()); | |
152 | if (plotArea.contains(m_origin)) { |
|
222 | if (plotArea.contains(m_origin)) { | |
153 | m_currentState = m_state; |
|
223 | m_currentState = m_state; | |
154 | if (m_currentState == NoState) emit chartSelected(chart); |
|
224 | if (m_currentState == NoState) emit chartSelected(chart); | |
155 | break; |
|
225 | break; | |
156 | } |
|
226 | } | |
157 | } |
|
227 | } | |
158 | if (m_currentState == ZoomState) { |
|
228 | if (m_currentState == ZoomState) { | |
159 | m_rubberBand->setRect(QRectF(m_origin, QSize())); |
|
229 | m_rubberBand->setRect(QRectF(m_origin, QSize())); | |
160 | m_rubberBand->setVisible(true); |
|
230 | m_rubberBand->setVisible(true); | |
161 | } |
|
231 | } | |
162 |
|
232 | |||
163 | event->accept(); |
|
233 | event->accept(); | |
164 | } |
|
234 | } | |
165 |
|
235 | |||
166 | if (event->button() == Qt::RightButton) { |
|
236 | if (event->button() == Qt::RightButton) { | |
167 | m_origin = event->pos(); |
|
237 | m_origin = event->pos(); | |
168 | m_currentState = m_state; |
|
238 | m_currentState = m_state; | |
169 | } |
|
239 | } | |
170 | } |
|
240 | } | |
171 |
|
241 | |||
172 | void Grid::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
242 | void Grid::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |
173 | { |
|
243 | { | |
174 | if (m_currentState != NoState) { |
|
244 | if (m_currentState != NoState) { | |
175 |
|
245 | |||
176 | foreach (QChart *chart, charts()) { |
|
246 | foreach (QChart *chart, charts()) { | |
177 | QRectF geometryRect = chart->geometry(); |
|
247 | QRectF geometryRect = chart->geometry(); | |
178 | QRectF plotArea = chart->plotArea(); |
|
248 | QRectF plotArea = chart->plotArea(); | |
179 | plotArea.translate(geometryRect.topLeft()); |
|
249 | plotArea.translate(geometryRect.topLeft()); | |
180 | if (plotArea.contains(m_origin)) { |
|
250 | if (plotArea.contains(m_origin)) { | |
181 | if (m_currentState == ScrollState) { |
|
251 | if (m_currentState == ScrollState) { | |
182 | QPointF delta = m_origin - event->pos(); |
|
252 | QPointF delta = m_origin - event->pos(); | |
183 | chart->scroll(delta.x(), -delta.y()); |
|
253 | chart->scroll(delta.x(), -delta.y()); | |
184 | } |
|
254 | } | |
185 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) |
|
255 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) | |
186 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); |
|
256 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); | |
187 | break; |
|
257 | break; | |
188 | } |
|
258 | } | |
189 | } |
|
259 | } | |
190 | if (m_currentState == ScrollState) |
|
260 | if (m_currentState == ScrollState) | |
191 | m_origin = event->pos(); |
|
261 | m_origin = event->pos(); | |
192 | event->accept(); |
|
262 | event->accept(); | |
193 | } |
|
263 | } | |
194 | } |
|
264 | } | |
195 |
|
265 | |||
196 | void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
266 | void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |
197 | { |
|
267 | { | |
198 | if (event->button() == Qt::LeftButton) { |
|
268 | if (event->button() == Qt::LeftButton) { | |
199 | if (m_currentState == ZoomState) { |
|
269 | if (m_currentState == ZoomState) { | |
200 | m_rubberBand->setVisible(false); |
|
270 | m_rubberBand->setVisible(false); | |
201 |
|
271 | |||
202 | foreach (QChart *chart, charts()) { |
|
272 | foreach (QChart *chart, charts()) { | |
203 | QRectF geometryRect = chart->geometry(); |
|
273 | QRectF geometryRect = chart->geometry(); | |
204 | QRectF plotArea = chart->plotArea(); |
|
274 | QRectF plotArea = chart->plotArea(); | |
205 | plotArea.translate(geometryRect.topLeft()); |
|
275 | plotArea.translate(geometryRect.topLeft()); | |
206 | if (plotArea.contains(m_origin)) { |
|
276 | if (plotArea.contains(m_origin)) { | |
207 | QRectF rect = m_rubberBand->rect(); |
|
277 | QRectF rect = m_rubberBand->rect(); | |
208 | rect.translate(-geometryRect.topLeft()); |
|
278 | rect.translate(-geometryRect.topLeft()); | |
209 | chart->zoomIn(rect); |
|
279 | chart->zoomIn(rect); | |
210 | break; |
|
280 | break; | |
211 | } |
|
281 | } | |
212 | } |
|
282 | } | |
213 | } |
|
283 | } | |
214 | m_currentState = NoState; |
|
284 | m_currentState = NoState; | |
215 | event->accept(); |
|
285 | event->accept(); | |
216 | } |
|
286 | } | |
217 |
|
287 | |||
218 | if (event->button() == Qt::RightButton) { |
|
288 | if (event->button() == Qt::RightButton) { | |
219 | if (m_currentState == ZoomState) { |
|
289 | if (m_currentState == ZoomState) { | |
220 | foreach (QChart *chart, charts()) { |
|
290 | foreach (QChart *chart, charts()) { | |
221 | QRectF geometryRect = chart->geometry(); |
|
291 | QRectF geometryRect = chart->geometry(); | |
222 | QRectF plotArea = chart->plotArea(); |
|
292 | QRectF plotArea = chart->plotArea(); | |
223 | plotArea.translate(geometryRect.topLeft()); |
|
293 | plotArea.translate(geometryRect.topLeft()); | |
224 | if (plotArea.contains(m_origin)) { |
|
294 | if (plotArea.contains(m_origin)) { | |
225 | chart->zoomOut(); |
|
295 | chart->zoomOut(); | |
226 | break; |
|
296 | break; | |
227 | } |
|
297 | } | |
228 | } |
|
298 | } | |
229 | } |
|
299 | } | |
230 | } |
|
300 | } | |
231 | } |
|
301 | } |
@@ -1,81 +1,82 | |||||
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 GRID_H_ |
|
21 | #ifndef GRID_H_ | |
22 | #define GRID_H_ |
|
22 | #define GRID_H_ | |
23 |
|
23 | |||
24 | #include "model.h" |
|
24 | #include "model.h" | |
25 | #include <QGraphicsWidget> |
|
25 | #include <QGraphicsWidget> | |
26 | #include <QChartGlobal> |
|
26 | #include <QChartGlobal> | |
27 |
|
27 | |||
28 | class QGraphicsGridLayout; |
|
28 | class QGraphicsGridLayout; | |
29 | class Chart; |
|
29 | class Chart; | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 | class QChart; |
|
32 | class QChart; | |
33 | QTCOMMERCIALCHART_END_NAMESPACE |
|
33 | QTCOMMERCIALCHART_END_NAMESPACE | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
35 | QTCOMMERCIALCHART_USE_NAMESPACE | |
36 |
|
36 | |||
37 | class Grid : public QGraphicsWidget |
|
37 | class Grid : public QGraphicsWidget | |
38 | { |
|
38 | { | |
39 | Q_OBJECT |
|
39 | Q_OBJECT | |
40 | public: |
|
40 | public: | |
41 | enum State { NoState = 0, ZoomState, ScrollState}; |
|
41 | enum State { NoState = 0, ZoomState, ScrollState}; | |
42 |
|
42 | |||
43 | Grid(int size, QGraphicsItem *parent = 0); |
|
43 | Grid(int size, QGraphicsItem *parent = 0); | |
44 | ~Grid(); |
|
44 | ~Grid(); | |
45 |
|
45 | |||
46 | QList<QChart *> charts(); |
|
46 | QList<QChart *> charts(); | |
47 | void createCharts(const QString &category = QString()); |
|
47 | void createCharts(const QString &category = QString()); | |
|
48 | void createCharts(const QString &category, const QString &subcategory, const QString &name); | |||
48 | void replaceChart(QChart *oldChart, Chart *newChart); |
|
49 | void replaceChart(QChart *oldChart, Chart *newChart); | |
49 | void setState(State state); |
|
50 | void setState(State state); | |
50 | State state() const { return m_state; }; |
|
51 | State state() const { return m_state; }; | |
51 | void setRubberPen(const QPen &pen); |
|
52 | void setRubberPen(const QPen &pen); | |
52 | void setSize(int size); |
|
53 | void setSize(int size); | |
53 | int size() const {return m_size;} |
|
54 | int size() const {return m_size;} | |
54 |
|
55 | |||
55 | Q_SIGNALS: |
|
56 | Q_SIGNALS: | |
56 | void chartSelected(QChart *chart); |
|
57 | void chartSelected(QChart *chart); | |
57 |
|
58 | |||
58 | protected: |
|
59 | protected: | |
59 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
60 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
60 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); |
|
61 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); | |
61 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); |
|
62 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); | |
62 |
|
63 | |||
63 | private: |
|
64 | private: | |
64 | void clear(); |
|
65 | void clear(); | |
65 |
|
66 | |||
66 | private: |
|
67 | private: | |
67 | int m_listCount; |
|
68 | int m_listCount; | |
68 | int m_valueMax; |
|
69 | int m_valueMax; | |
69 | int m_valueCount; |
|
70 | int m_valueCount; | |
70 | int m_size; |
|
71 | int m_size; | |
71 | DataTable m_dataTable; |
|
72 | DataTable m_dataTable; | |
72 | QHash<QChart *, int> m_chartHash; |
|
73 | QHash<QChart *, int> m_chartHash; | |
|
74 | QHash<int, QChart *> m_chartHashRev; | |||
73 | State m_state; |
|
75 | State m_state; | |
74 | State m_currentState; |
|
76 | State m_currentState; | |
75 | QPointF m_origin; |
|
77 | QPointF m_origin; | |
76 | QGraphicsRectItem *m_rubberBand; |
|
78 | QGraphicsRectItem *m_rubberBand; | |
77 | QGraphicsGridLayout *m_gridLayout; |
|
79 | QGraphicsGridLayout *m_gridLayout; | |
78 | QString m_category; |
|
|||
79 | }; |
|
80 | }; | |
80 |
|
81 | |||
81 | #endif /* GRID_H_ */ |
|
82 | #endif /* GRID_H_ */ |
@@ -1,484 +1,502 | |||||
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 "window.h" |
|
21 | #include "window.h" | |
22 | #include "view.h" |
|
22 | #include "view.h" | |
23 | #include "grid.h" |
|
23 | #include "grid.h" | |
24 | #include "charts.h" |
|
24 | #include "charts.h" | |
25 | #include <QChartView> |
|
25 | #include <QChartView> | |
26 | #include <QAreaSeries> |
|
26 | #include <QAreaSeries> | |
27 | #include <QLegend> |
|
27 | #include <QLegend> | |
28 | #include <QGridLayout> |
|
28 | #include <QGridLayout> | |
29 | #include <QFormLayout> |
|
29 | #include <QFormLayout> | |
30 | #include <QComboBox> |
|
30 | #include <QComboBox> | |
31 | #include <QSpinBox> |
|
31 | #include <QSpinBox> | |
32 | #include <QCheckBox> |
|
32 | #include <QCheckBox> | |
33 | #include <QGroupBox> |
|
33 | #include <QGroupBox> | |
34 | #include <QLabel> |
|
34 | #include <QLabel> | |
35 | #include <QGraphicsScene> |
|
35 | #include <QGraphicsScene> | |
36 | #include <QGraphicsLinearLayout> |
|
36 | #include <QGraphicsLinearLayout> | |
37 | #include <QGraphicsProxyWidget> |
|
37 | #include <QGraphicsProxyWidget> | |
38 | #include <QGLWidget> |
|
38 | #include <QGLWidget> | |
39 | #include <QApplication> |
|
39 | #include <QApplication> | |
40 | #include <QDebug> |
|
40 | #include <QDebug> | |
41 | #include <QMenu> |
|
41 | #include <QMenu> | |
42 | #include <QPushButton> |
|
42 | #include <QPushButton> | |
43 |
|
43 | |||
44 | Window::Window(const QVariantHash ¶meters, QWidget *parent) |
|
44 | Window::Window(const QVariantHash ¶meters, QWidget *parent) | |
45 | : QMainWindow(parent), |
|
45 | : QMainWindow(parent), | |
46 | m_scene(new QGraphicsScene(this)), |
|
46 | m_scene(new QGraphicsScene(this)), | |
47 | m_view(0), |
|
47 | m_view(0), | |
48 | m_form(0), |
|
48 | m_form(0), | |
49 | m_themeComboBox(0), |
|
49 | m_themeComboBox(0), | |
50 | m_antialiasCheckBox(0), |
|
50 | m_antialiasCheckBox(0), | |
51 | m_animatedComboBox(0), |
|
51 | m_animatedComboBox(0), | |
52 | m_legendComboBox(0), |
|
52 | m_legendComboBox(0), | |
53 | m_templateComboBox(0), |
|
53 | m_templateComboBox(0), | |
54 | m_viewComboBox(0), |
|
54 | m_viewComboBox(0), | |
55 | m_openGLCheckBox(0), |
|
55 | m_openGLCheckBox(0), | |
56 | m_zoomCheckBox(0), |
|
56 | m_zoomCheckBox(0), | |
57 | m_scrollCheckBox(0), |
|
57 | m_scrollCheckBox(0), | |
58 | m_baseLayout(new QGraphicsLinearLayout()), |
|
58 | m_baseLayout(new QGraphicsLinearLayout()), | |
59 | m_menu(createMenu()), |
|
59 | m_menu(createMenu()), | |
60 | m_template(0), |
|
60 | m_template(0), | |
61 | m_grid(new Grid(1)) |
|
61 | m_grid(new Grid(-1)) | |
62 | { |
|
62 | { | |
63 | createProxyWidgets(); |
|
63 | createProxyWidgets(); | |
64 | // create layout |
|
64 | // create layout | |
65 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); |
|
65 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); | |
66 |
|
66 | |||
67 | settingsLayout->setOrientation(Qt::Vertical); |
|
67 | settingsLayout->setOrientation(Qt::Vertical); | |
68 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
68 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
69 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); |
|
69 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); | |
70 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); |
|
70 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); | |
71 | settingsLayout->addItem(m_widgetHash["viewLabel"]); |
|
71 | settingsLayout->addItem(m_widgetHash["viewLabel"]); | |
72 | settingsLayout->addItem(m_widgetHash["viewComboBox"]); |
|
72 | settingsLayout->addItem(m_widgetHash["viewComboBox"]); | |
73 | settingsLayout->addItem(m_widgetHash["themeLabel"]); |
|
73 | settingsLayout->addItem(m_widgetHash["themeLabel"]); | |
74 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); |
|
74 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); | |
75 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); |
|
75 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); | |
76 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); |
|
76 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); | |
77 | settingsLayout->addItem(m_widgetHash["legendLabel"]); |
|
77 | settingsLayout->addItem(m_widgetHash["legendLabel"]); | |
78 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); |
|
78 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); | |
79 | settingsLayout->addItem(m_widgetHash["templateLabel"]); |
|
79 | settingsLayout->addItem(m_widgetHash["templateLabel"]); | |
80 | settingsLayout->addItem(m_widgetHash["templateComboBox"]); |
|
80 | settingsLayout->addItem(m_widgetHash["templateComboBox"]); | |
81 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); |
|
81 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); | |
82 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); |
|
82 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); | |
83 | settingsLayout->addStretch(); |
|
83 | settingsLayout->addStretch(); | |
84 |
|
84 | |||
85 | m_grid->createCharts(); |
|
|||
86 |
|
||||
87 | m_baseLayout->setOrientation(Qt::Horizontal); |
|
85 | m_baseLayout->setOrientation(Qt::Horizontal); | |
88 | m_baseLayout->addItem(m_grid); |
|
86 | m_baseLayout->addItem(m_grid); | |
89 | m_baseLayout->addItem(settingsLayout); |
|
87 | m_baseLayout->addItem(settingsLayout); | |
90 |
|
88 | |||
91 | m_form = new QGraphicsWidget(); |
|
89 | m_form = new QGraphicsWidget(); | |
92 | m_form->setLayout(m_baseLayout); |
|
90 | m_form->setLayout(m_baseLayout); | |
93 | m_scene->addItem(m_form); |
|
91 | m_scene->addItem(m_form); | |
94 |
|
92 | |||
95 | m_view = new View(m_scene, m_form); |
|
93 | m_view = new View(m_scene, m_form); | |
96 | m_view->setMinimumSize(m_form->minimumSize().toSize()); |
|
94 | m_view->setMinimumSize(m_form->minimumSize().toSize()); | |
97 |
|
95 | |||
98 | // Set defaults |
|
96 | // Set defaults | |
99 | m_antialiasCheckBox->setChecked(true); |
|
97 | m_antialiasCheckBox->setChecked(true); | |
100 | initializeFromParamaters(parameters); |
|
98 | initializeFromParamaters(parameters); | |
101 | updateUI(); |
|
99 | updateUI(); | |
|
100 | if(!m_category.isEmpty() && !m_subcategory.isEmpty() && !m_name.isEmpty()) | |||
|
101 | m_grid->createCharts(m_category,m_subcategory,m_name); | |||
|
102 | ||||
|
103 | ||||
102 | handleGeometryChanged(); |
|
104 | handleGeometryChanged(); | |
103 | setCentralWidget(m_view); |
|
105 | setCentralWidget(m_view); | |
104 |
|
106 | |||
105 | connectSignals(); |
|
107 | connectSignals(); | |
106 | } |
|
108 | } | |
107 |
|
109 | |||
108 | Window::~Window() |
|
110 | Window::~Window() | |
109 | { |
|
111 | { | |
110 | } |
|
112 | } | |
111 |
|
113 | |||
112 | void Window::connectSignals() |
|
114 | void Window::connectSignals() | |
113 | { |
|
115 | { | |
114 | QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); |
|
116 | QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged())); | |
115 | QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
117 | QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
116 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
118 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
117 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
119 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
118 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
120 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
119 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
121 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
120 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
122 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
121 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
123 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
122 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
124 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
123 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
125 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
124 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*))); |
|
126 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*))); | |
125 | } |
|
127 | } | |
126 |
|
128 | |||
127 | void Window::createProxyWidgets() |
|
129 | void Window::createProxyWidgets() | |
128 | { |
|
130 | { | |
129 | m_themeComboBox = createThemeBox(); |
|
131 | m_themeComboBox = createThemeBox(); | |
130 | m_viewComboBox = createViewBox(); |
|
132 | m_viewComboBox = createViewBox(); | |
131 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); |
|
133 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); | |
132 | m_animatedComboBox = createAnimationBox(); |
|
134 | m_animatedComboBox = createAnimationBox(); | |
133 | m_legendComboBox = createLegendBox(); |
|
135 | m_legendComboBox = createLegendBox(); | |
134 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); |
|
136 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); | |
135 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
|
137 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); | |
136 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
|
138 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); | |
137 | m_templateComboBox = createTempleteBox(); |
|
139 | m_templateComboBox = createTempleteBox(); | |
138 | m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); |
|
140 | m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View")); | |
139 | m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); |
|
141 | m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox); | |
140 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
|
142 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); | |
141 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
|
143 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); | |
142 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
|
144 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); | |
143 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); |
|
145 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); | |
144 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); |
|
146 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); | |
145 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); |
|
147 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); | |
146 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); |
|
148 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); | |
147 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); |
|
149 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); | |
148 | m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); |
|
150 | m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); | |
149 | m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); |
|
151 | m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); | |
150 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); |
|
152 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); | |
151 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); |
|
153 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); | |
152 | } |
|
154 | } | |
153 |
|
155 | |||
154 | QComboBox *Window::createThemeBox() |
|
156 | QComboBox *Window::createThemeBox() | |
155 | { |
|
157 | { | |
156 | QComboBox *themeComboBox = new ComboBox(this); |
|
158 | QComboBox *themeComboBox = new ComboBox(this); | |
157 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
159 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
158 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
160 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
159 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
161 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
160 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
162 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
161 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
163 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
162 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
164 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
163 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
165 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
164 | return themeComboBox; |
|
166 | return themeComboBox; | |
165 | } |
|
167 | } | |
166 |
|
168 | |||
167 | QComboBox *Window::createViewBox() |
|
169 | QComboBox *Window::createViewBox() | |
168 | { |
|
170 | { | |
169 | QComboBox *viewComboBox = new ComboBox(this); |
|
171 | QComboBox *viewComboBox = new ComboBox(this); | |
170 | viewComboBox->addItem("1 chart", 1); |
|
172 | viewComboBox->addItem("1 chart", 1); | |
171 | viewComboBox->addItem("4 charts", 2); |
|
173 | viewComboBox->addItem("4 charts", 2); | |
172 | viewComboBox->addItem("9 charts", 3); |
|
174 | viewComboBox->addItem("9 charts", 3); | |
173 | viewComboBox->addItem("16 charts", 4); |
|
175 | viewComboBox->addItem("16 charts", 4); | |
174 | return viewComboBox; |
|
176 | return viewComboBox; | |
175 | } |
|
177 | } | |
176 |
|
178 | |||
177 | QComboBox *Window::createAnimationBox() |
|
179 | QComboBox *Window::createAnimationBox() | |
178 | { |
|
180 | { | |
179 | QComboBox *animationComboBox = new ComboBox(this); |
|
181 | QComboBox *animationComboBox = new ComboBox(this); | |
180 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
182 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
181 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
183 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
182 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
184 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
183 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
185 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
184 | return animationComboBox; |
|
186 | return animationComboBox; | |
185 | } |
|
187 | } | |
186 |
|
188 | |||
187 | QComboBox *Window::createLegendBox() |
|
189 | QComboBox *Window::createLegendBox() | |
188 | { |
|
190 | { | |
189 | QComboBox *legendComboBox = new ComboBox(this); |
|
191 | QComboBox *legendComboBox = new ComboBox(this); | |
190 | legendComboBox->addItem("No Legend ", 0); |
|
192 | legendComboBox->addItem("No Legend ", 0); | |
191 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
193 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
192 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
194 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
193 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
195 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); | |
194 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
196 | legendComboBox->addItem("Legend Right", Qt::AlignRight); | |
195 | return legendComboBox; |
|
197 | return legendComboBox; | |
196 | } |
|
198 | } | |
197 |
|
199 | |||
198 | QComboBox *Window::createTempleteBox() |
|
200 | QComboBox *Window::createTempleteBox() | |
199 | { |
|
201 | { | |
200 | QComboBox *templateComboBox = new ComboBox(this); |
|
202 | QComboBox *templateComboBox = new ComboBox(this); | |
201 | templateComboBox->addItem("No Template", 0); |
|
203 | templateComboBox->addItem("No Template", 0); | |
202 |
|
204 | |||
203 | Charts::ChartList list = Charts::chartList(); |
|
205 | Charts::ChartList list = Charts::chartList(); | |
204 | QMultiMap<QString, Chart *> categoryMap; |
|
206 | QMultiMap<QString, Chart *> categoryMap; | |
205 |
|
207 | |||
206 | foreach (Chart *chart, list) |
|
208 | foreach (Chart *chart, list) | |
207 | categoryMap.insertMulti(chart->category(), chart); |
|
209 | categoryMap.insertMulti(chart->category(), chart); | |
208 |
|
210 | |||
209 | foreach (const QString &category, categoryMap.uniqueKeys()) |
|
211 | foreach (const QString &category, categoryMap.uniqueKeys()) | |
210 | templateComboBox->addItem(category, category); |
|
212 | templateComboBox->addItem(category, category); | |
211 |
|
213 | |||
212 | return templateComboBox; |
|
214 | return templateComboBox; | |
213 | } |
|
215 | } | |
214 |
|
216 | |||
215 | void Window::initializeFromParamaters(const QVariantHash ¶meters) |
|
217 | void Window::initializeFromParamaters(const QVariantHash ¶meters) | |
216 | { |
|
218 | { | |
|
219 | if (parameters.contains("view")) { | |||
|
220 | int t = parameters["view"].toInt(); | |||
|
221 | for (int i = 0; i < m_viewComboBox->count(); ++i) { | |||
|
222 | if (m_viewComboBox->itemData(i).toInt() == t) { | |||
|
223 | m_viewComboBox->setCurrentIndex(i); | |||
|
224 | break; | |||
|
225 | } | |||
|
226 | } | |||
|
227 | } | |||
|
228 | ||||
217 | if (parameters.contains("chart")) { |
|
229 | if (parameters.contains("chart")) { | |
218 | QString t = parameters["chart"].toString(); |
|
230 | QString t = parameters["chart"].toString(); | |
219 | for (int i = 0; i < m_templateComboBox->count(); ++i) { |
|
231 | ||
220 | if (m_templateComboBox->itemText(i) == t) { |
|
232 | QRegExp rx("([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)::([a-zA-Z0-9_]*)"); | |
221 | m_templateComboBox->setCurrentIndex(i); |
|
233 | int pos = rx.indexIn(t); | |
222 | break; |
|
234 | ||
|
235 | if (pos > -1) { | |||
|
236 | m_category = rx.cap(1); | |||
|
237 | m_subcategory = rx.cap(2); | |||
|
238 | m_name = rx.cap(3); | |||
|
239 | m_templateComboBox->setCurrentIndex(0); | |||
|
240 | } | |||
|
241 | else { | |||
|
242 | for (int i = 0; i < m_templateComboBox->count(); ++i) { | |||
|
243 | if (m_templateComboBox->itemText(i) == t) { | |||
|
244 | m_templateComboBox->setCurrentIndex(i); | |||
|
245 | break; | |||
|
246 | } | |||
223 | } |
|
247 | } | |
224 | } |
|
248 | } | |
225 | } |
|
249 | } | |
226 | if (parameters.contains("opengl")) { |
|
250 | if (parameters.contains("opengl")) { | |
227 | bool checked = parameters["opengl"].toBool(); |
|
251 | bool checked = parameters["opengl"].toBool(); | |
228 | m_openGLCheckBox->setChecked(checked); |
|
252 | m_openGLCheckBox->setChecked(checked); | |
229 | } |
|
253 | } | |
230 | if (parameters.contains("theme")) { |
|
254 | if (parameters.contains("theme")) { | |
231 | QString t = parameters["theme"].toString(); |
|
255 | QString t = parameters["theme"].toString(); | |
232 | for (int i = 0; i < m_themeComboBox->count(); ++i) { |
|
256 | for (int i = 0; i < m_themeComboBox->count(); ++i) { | |
233 | if (m_themeComboBox->itemText(i) == t) { |
|
257 | if (m_themeComboBox->itemText(i) == t) { | |
234 | m_themeComboBox->setCurrentIndex(i); |
|
258 | m_themeComboBox->setCurrentIndex(i); | |
235 | break; |
|
259 | break; | |
236 | } |
|
260 | } | |
237 | } |
|
261 | } | |
238 | } |
|
262 | } | |
239 | if (parameters.contains("animation")) { |
|
263 | if (parameters.contains("animation")) { | |
240 | QString t = parameters["animation"].toString(); |
|
264 | QString t = parameters["animation"].toString(); | |
241 | for (int i = 0; i < m_animatedComboBox->count(); ++i) { |
|
265 | for (int i = 0; i < m_animatedComboBox->count(); ++i) { | |
242 | if (m_animatedComboBox->itemText(i) == t) { |
|
266 | if (m_animatedComboBox->itemText(i) == t) { | |
243 | m_animatedComboBox->setCurrentIndex(i); |
|
267 | m_animatedComboBox->setCurrentIndex(i); | |
244 | break; |
|
268 | break; | |
245 | } |
|
269 | } | |
246 | } |
|
270 | } | |
247 | } |
|
271 | } | |
248 | if (parameters.contains("legend")) { |
|
272 | if (parameters.contains("legend")) { | |
249 | QString t = parameters["legend"].toString(); |
|
273 | QString t = parameters["legend"].toString(); | |
250 | for (int i = 0; i < m_legendComboBox->count(); ++i) { |
|
274 | for (int i = 0; i < m_legendComboBox->count(); ++i) { | |
251 | if (m_legendComboBox->itemText(i) == t) { |
|
275 | if (m_legendComboBox->itemText(i) == t) { | |
252 | m_legendComboBox->setCurrentIndex(i); |
|
276 | m_legendComboBox->setCurrentIndex(i); | |
253 | break; |
|
277 | break; | |
254 | } |
|
278 | } | |
255 | } |
|
279 | } | |
256 | } |
|
280 | } | |
257 | if (parameters.contains("view")) { |
|
|||
258 | int t = parameters["view"].toInt(); |
|
|||
259 | for (int i = 0; i < m_viewComboBox->count(); ++i) { |
|
|||
260 | if (m_viewComboBox->itemData(i).toInt() == t) { |
|
|||
261 | m_viewComboBox->setCurrentIndex(i); |
|
|||
262 | break; |
|
|||
263 | } |
|
|||
264 | } |
|
|||
265 | } |
|
|||
266 | } |
|
281 | } | |
267 |
|
282 | |||
268 | void Window::updateUI() |
|
283 | void Window::updateUI() | |
269 | { |
|
284 | { | |
270 | checkTemplate(); |
|
|||
271 | checkView(); |
|
285 | checkView(); | |
|
286 | checkTemplate(); | |||
272 | checkOpenGL(); |
|
287 | checkOpenGL(); | |
273 | checkTheme(); |
|
288 | checkTheme(); | |
274 | checkAnimationOptions(); |
|
289 | checkAnimationOptions(); | |
275 | checkLegend(); |
|
290 | checkLegend(); | |
276 | checkState(); |
|
291 | checkState(); | |
277 | } |
|
292 | } | |
278 |
|
293 | |||
279 | void Window::checkView() |
|
294 | void Window::checkView() | |
280 | { |
|
295 | { | |
281 | int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); |
|
296 | int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt()); | |
282 |
m_grid->s |
|
297 | if(m_grid->size()!=count){ | |
|
298 | m_grid->setSize(count); | |||
|
299 | m_template = 0; | |||
|
300 | } | |||
283 | } |
|
301 | } | |
284 |
|
302 | |||
285 | void Window::checkLegend() |
|
303 | void Window::checkLegend() | |
286 | { |
|
304 | { | |
287 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
305 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
288 |
|
306 | |||
289 | if (!alignment) { |
|
307 | if (!alignment) { | |
290 | foreach (QChart *chart, m_grid->charts()) |
|
308 | foreach (QChart *chart, m_grid->charts()) | |
291 | chart->legend()->hide(); |
|
309 | chart->legend()->hide(); | |
292 | } else { |
|
310 | } else { | |
293 | foreach (QChart *chart, m_grid->charts()) { |
|
311 | foreach (QChart *chart, m_grid->charts()) { | |
294 | chart->legend()->setAlignment(alignment); |
|
312 | chart->legend()->setAlignment(alignment); | |
295 | chart->legend()->show(); |
|
313 | chart->legend()->show(); | |
296 | } |
|
314 | } | |
297 | } |
|
315 | } | |
298 | } |
|
316 | } | |
299 |
|
317 | |||
300 | void Window::checkOpenGL() |
|
318 | void Window::checkOpenGL() | |
301 | { |
|
319 | { | |
302 | bool opengl = m_openGLCheckBox->isChecked(); |
|
320 | bool opengl = m_openGLCheckBox->isChecked(); | |
303 | bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport()); |
|
321 | bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport()); | |
304 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
|
322 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { | |
305 | m_view->deleteLater(); |
|
323 | m_view->deleteLater(); | |
306 | m_view = new View(m_scene, m_form); |
|
324 | m_view = new View(m_scene, m_form); | |
307 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); |
|
325 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); | |
308 | setCentralWidget(m_view); |
|
326 | setCentralWidget(m_view); | |
309 | } |
|
327 | } | |
310 |
|
328 | |||
311 | bool antialias = m_antialiasCheckBox->isChecked(); |
|
329 | bool antialias = m_antialiasCheckBox->isChecked(); | |
312 |
|
330 | |||
313 | if (opengl) |
|
331 | if (opengl) | |
314 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); |
|
332 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); | |
315 | else |
|
333 | else | |
316 | m_view->setRenderHint(QPainter::Antialiasing, antialias); |
|
334 | m_view->setRenderHint(QPainter::Antialiasing, antialias); | |
317 | } |
|
335 | } | |
318 |
|
336 | |||
319 | void Window::checkAnimationOptions() |
|
337 | void Window::checkAnimationOptions() | |
320 | { |
|
338 | { | |
321 | QChart::AnimationOptions options( |
|
339 | QChart::AnimationOptions options( | |
322 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
340 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
323 |
|
341 | |||
324 | QList<QChart *> charts = m_grid->charts(); |
|
342 | QList<QChart *> charts = m_grid->charts(); | |
325 |
|
343 | |||
326 | if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { |
|
344 | if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { | |
327 | foreach (QChart *chart, charts) |
|
345 | foreach (QChart *chart, charts) | |
328 | chart->setAnimationOptions(options); |
|
346 | chart->setAnimationOptions(options); | |
329 | } |
|
347 | } | |
330 | } |
|
348 | } | |
331 |
|
349 | |||
332 | void Window::checkState() |
|
350 | void Window::checkState() | |
333 | { |
|
351 | { | |
334 | bool scroll = m_scrollCheckBox->isChecked(); |
|
352 | bool scroll = m_scrollCheckBox->isChecked(); | |
335 |
|
353 | |||
336 |
|
354 | |||
337 | if (m_grid->state() != Grid::ScrollState && scroll) { |
|
355 | if (m_grid->state() != Grid::ScrollState && scroll) { | |
338 | m_grid->setState(Grid::ScrollState); |
|
356 | m_grid->setState(Grid::ScrollState); | |
339 | m_zoomCheckBox->setChecked(false); |
|
357 | m_zoomCheckBox->setChecked(false); | |
340 | } else if (!scroll && m_grid->state() == Grid::ScrollState) { |
|
358 | } else if (!scroll && m_grid->state() == Grid::ScrollState) { | |
341 | m_grid->setState(Grid::NoState); |
|
359 | m_grid->setState(Grid::NoState); | |
342 | } |
|
360 | } | |
343 |
|
361 | |||
344 | bool zoom = m_zoomCheckBox->isChecked(); |
|
362 | bool zoom = m_zoomCheckBox->isChecked(); | |
345 |
|
363 | |||
346 | if (m_grid->state() != Grid::ZoomState && zoom) { |
|
364 | if (m_grid->state() != Grid::ZoomState && zoom) { | |
347 | m_grid->setState(Grid::ZoomState); |
|
365 | m_grid->setState(Grid::ZoomState); | |
348 | m_scrollCheckBox->setChecked(false); |
|
366 | m_scrollCheckBox->setChecked(false); | |
349 | } else if (!zoom && m_grid->state() == Grid::ZoomState) { |
|
367 | } else if (!zoom && m_grid->state() == Grid::ZoomState) { | |
350 | m_grid->setState(Grid::NoState); |
|
368 | m_grid->setState(Grid::NoState); | |
351 | } |
|
369 | } | |
352 | } |
|
370 | } | |
353 |
|
371 | |||
354 | void Window::checkTemplate() |
|
372 | void Window::checkTemplate() | |
355 | { |
|
373 | { | |
356 | int index = m_templateComboBox->currentIndex(); |
|
374 | int index = m_templateComboBox->currentIndex(); | |
357 | if (m_template == index || index == 0) |
|
375 | if (m_template == index || index == 0) | |
358 | return; |
|
376 | return; | |
359 |
|
377 | |||
360 | m_template = index; |
|
378 | m_template = index; | |
361 | QString category = m_templateComboBox->itemData(index).toString(); |
|
379 | QString category = m_templateComboBox->itemData(index).toString(); | |
362 | m_grid->createCharts(category); |
|
380 | m_grid->createCharts(category); | |
363 | } |
|
381 | } | |
364 |
|
382 | |||
365 | void Window::checkTheme() |
|
383 | void Window::checkTheme() | |
366 | { |
|
384 | { | |
367 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
|
385 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( | |
368 | m_themeComboBox->currentIndex()).toInt(); |
|
386 | m_themeComboBox->currentIndex()).toInt(); | |
369 |
|
387 | |||
370 | foreach (QChart *chart, m_grid->charts()) |
|
388 | foreach (QChart *chart, m_grid->charts()) | |
371 | chart->setTheme(theme); |
|
389 | chart->setTheme(theme); | |
372 |
|
390 | |||
373 | QPalette pal = window()->palette(); |
|
391 | QPalette pal = window()->palette(); | |
374 | if (theme == QChart::ChartThemeLight) { |
|
392 | if (theme == QChart::ChartThemeLight) { | |
375 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
393 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
376 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
394 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
377 | } else if (theme == QChart::ChartThemeDark) { |
|
395 | } else if (theme == QChart::ChartThemeDark) { | |
378 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
396 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
379 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
397 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
380 | } else if (theme == QChart::ChartThemeBlueCerulean) { |
|
398 | } else if (theme == QChart::ChartThemeBlueCerulean) { | |
381 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
399 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
382 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
400 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
383 | } else if (theme == QChart::ChartThemeBrownSand) { |
|
401 | } else if (theme == QChart::ChartThemeBrownSand) { | |
384 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
402 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
385 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
403 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
386 | } else if (theme == QChart::ChartThemeBlueNcs) { |
|
404 | } else if (theme == QChart::ChartThemeBlueNcs) { | |
387 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
405 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
388 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
406 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
389 | } else if (theme == QChart::ChartThemeHighContrast) { |
|
407 | } else if (theme == QChart::ChartThemeHighContrast) { | |
390 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
408 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
391 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
409 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
392 | } else if (theme == QChart::ChartThemeBlueIcy) { |
|
410 | } else if (theme == QChart::ChartThemeBlueIcy) { | |
393 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
411 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
394 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
412 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
395 | } else { |
|
413 | } else { | |
396 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
414 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
397 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
415 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
398 | } |
|
416 | } | |
399 | foreach (QGraphicsProxyWidget *widget, m_widgetHash) |
|
417 | foreach (QGraphicsProxyWidget *widget, m_widgetHash) | |
400 | widget->setPalette(pal); |
|
418 | widget->setPalette(pal); | |
401 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
|
419 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); | |
402 | m_grid->setRubberPen(pal.color((QPalette::WindowText))); |
|
420 | m_grid->setRubberPen(pal.color((QPalette::WindowText))); | |
403 | } |
|
421 | } | |
404 |
|
422 | |||
405 | void Window::comboBoxFocused(QComboBox *combobox) |
|
423 | void Window::comboBoxFocused(QComboBox *combobox) | |
406 | { |
|
424 | { | |
407 | foreach (QGraphicsProxyWidget *widget , m_widgetHash) { |
|
425 | foreach (QGraphicsProxyWidget *widget , m_widgetHash) { | |
408 | if (widget->widget() == combobox) |
|
426 | if (widget->widget() == combobox) | |
409 | widget->setZValue(2.0); |
|
427 | widget->setZValue(2.0); | |
410 | else |
|
428 | else | |
411 | widget->setZValue(0.0); |
|
429 | widget->setZValue(0.0); | |
412 | } |
|
430 | } | |
413 | } |
|
431 | } | |
414 |
|
432 | |||
415 | void Window::handleChartSelected(QChart *qchart) |
|
433 | void Window::handleChartSelected(QChart *qchart) | |
416 | { |
|
434 | { | |
417 | if (m_templateComboBox->currentIndex() != 0) |
|
435 | if (m_templateComboBox->currentIndex() != 0) | |
418 | return; |
|
436 | return; | |
419 |
|
437 | |||
420 | QAction *chosen = m_menu->exec(QCursor::pos()); |
|
438 | QAction *chosen = m_menu->exec(QCursor::pos()); | |
421 |
|
439 | |||
422 | if (chosen) { |
|
440 | if (chosen) { | |
423 | Chart *chart = (Chart *) chosen->data().value<void *>(); |
|
441 | Chart *chart = (Chart *) chosen->data().value<void *>(); | |
424 | m_grid->replaceChart(qchart, chart); |
|
442 | m_grid->replaceChart(qchart, chart); | |
425 | updateUI(); |
|
443 | updateUI(); | |
426 | } |
|
444 | } | |
427 | } |
|
445 | } | |
428 |
|
446 | |||
429 | QMenu *Window::createMenu() |
|
447 | QMenu *Window::createMenu() | |
430 | { |
|
448 | { | |
431 | Charts::ChartList list = Charts::chartList(); |
|
449 | Charts::ChartList list = Charts::chartList(); | |
432 | QMultiMap<QString, Chart *> categoryMap; |
|
450 | QMultiMap<QString, Chart *> categoryMap; | |
433 |
|
451 | |||
434 | QMenu *result = new QMenu(this); |
|
452 | QMenu *result = new QMenu(this); | |
435 |
|
453 | |||
436 | foreach (Chart *chart, list) |
|
454 | foreach (Chart *chart, list) | |
437 | categoryMap.insertMulti(chart->category(), chart); |
|
455 | categoryMap.insertMulti(chart->category(), chart); | |
438 |
|
456 | |||
439 | foreach (const QString &category, categoryMap.uniqueKeys()) { |
|
457 | foreach (const QString &category, categoryMap.uniqueKeys()) { | |
440 | QMenu *menu(0); |
|
458 | QMenu *menu(0); | |
441 | QMultiMap<QString, Chart *> subCategoryMap; |
|
459 | QMultiMap<QString, Chart *> subCategoryMap; | |
442 | if (category.isEmpty()) { |
|
460 | if (category.isEmpty()) { | |
443 | menu = result; |
|
461 | menu = result; | |
444 | } else { |
|
462 | } else { | |
445 | menu = new QMenu(category, this); |
|
463 | menu = new QMenu(category, this); | |
446 | result->addMenu(menu); |
|
464 | result->addMenu(menu); | |
447 | } |
|
465 | } | |
448 |
|
466 | |||
449 | foreach (Chart *chart, categoryMap.values(category)) |
|
467 | foreach (Chart *chart, categoryMap.values(category)) | |
450 | subCategoryMap.insert(chart->subCategory(), chart); |
|
468 | subCategoryMap.insert(chart->subCategory(), chart); | |
451 |
|
469 | |||
452 | foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { |
|
470 | foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) { | |
453 | QMenu *subMenu(0); |
|
471 | QMenu *subMenu(0); | |
454 | if (subCategory.isEmpty()) { |
|
472 | if (subCategory.isEmpty()) { | |
455 | subMenu = menu; |
|
473 | subMenu = menu; | |
456 | } else { |
|
474 | } else { | |
457 | subMenu = new QMenu(subCategory, this); |
|
475 | subMenu = new QMenu(subCategory, this); | |
458 | menu->addMenu(subMenu); |
|
476 | menu->addMenu(subMenu); | |
459 | } |
|
477 | } | |
460 |
|
478 | |||
461 | foreach (Chart *chart, subCategoryMap.values(subCategory)) { |
|
479 | foreach (Chart *chart, subCategoryMap.values(subCategory)) { | |
462 | createMenuAction(subMenu, QIcon(), chart->name(), |
|
480 | createMenuAction(subMenu, QIcon(), chart->name(), | |
463 | qVariantFromValue((void *) chart)); |
|
481 | qVariantFromValue((void *) chart)); | |
464 | } |
|
482 | } | |
465 | } |
|
483 | } | |
466 | } |
|
484 | } | |
467 | return result; |
|
485 | return result; | |
468 | } |
|
486 | } | |
469 |
|
487 | |||
470 | QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, |
|
488 | QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, | |
471 | const QVariant &data) |
|
489 | const QVariant &data) | |
472 | { |
|
490 | { | |
473 | QAction *action = menu->addAction(icon, text); |
|
491 | QAction *action = menu->addAction(icon, text); | |
474 | action->setCheckable(false); |
|
492 | action->setCheckable(false); | |
475 | action->setData(data); |
|
493 | action->setData(data); | |
476 | return action; |
|
494 | return action; | |
477 | } |
|
495 | } | |
478 |
|
496 | |||
479 | void Window::handleGeometryChanged() |
|
497 | void Window::handleGeometryChanged() | |
480 | { |
|
498 | { | |
481 | QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); |
|
499 | QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize); | |
482 | m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); |
|
500 | m_view->scene()->setSceneRect(0, 0, this->width(), this->height()); | |
483 | m_view->setMinimumSize(size.toSize()); |
|
501 | m_view->setMinimumSize(size.toSize()); | |
484 | } |
|
502 | } |
@@ -1,114 +1,117 | |||||
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 WINDOW_H |
|
21 | #ifndef WINDOW_H | |
22 | #define WINDOW_H |
|
22 | #define WINDOW_H | |
23 | #include <QMainWindow> |
|
23 | #include <QMainWindow> | |
24 | #include <QChartGlobal> |
|
24 | #include <QChartGlobal> | |
25 | #include <QHash> |
|
25 | #include <QHash> | |
26 | #include <QComboBox> |
|
26 | #include <QComboBox> | |
27 |
|
27 | |||
28 | class QCheckBox; |
|
28 | class QCheckBox; | |
29 | class QGraphicsRectItem; |
|
29 | class QGraphicsRectItem; | |
30 | class QGraphicsScene; |
|
30 | class QGraphicsScene; | |
31 | class QGraphicsWidget; |
|
31 | class QGraphicsWidget; | |
32 | class View; |
|
32 | class View; | |
33 | class QGraphicsLinearLayout; |
|
33 | class QGraphicsLinearLayout; | |
34 | class Chart; |
|
34 | class Chart; | |
35 | class Grid; |
|
35 | class Grid; | |
36 | class QPushButton; |
|
36 | class QPushButton; | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 | class QChart; |
|
39 | class QChart; | |
40 | QTCOMMERCIALCHART_END_NAMESPACE |
|
40 | QTCOMMERCIALCHART_END_NAMESPACE | |
41 |
|
41 | |||
42 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
42 | QTCOMMERCIALCHART_USE_NAMESPACE | |
43 |
|
43 | |||
44 |
|
44 | |||
45 | class Window: public QMainWindow |
|
45 | class Window: public QMainWindow | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | explicit Window(const QVariantHash ¶meters, QWidget *parent = 0); |
|
49 | explicit Window(const QVariantHash ¶meters, QWidget *parent = 0); | |
50 | ~Window(); |
|
50 | ~Window(); | |
51 |
|
51 | |||
52 | private Q_SLOTS: |
|
52 | private Q_SLOTS: | |
53 | void updateUI(); |
|
53 | void updateUI(); | |
54 | void handleGeometryChanged(); |
|
54 | void handleGeometryChanged(); | |
55 | void handleChartSelected(QChart *chart); |
|
55 | void handleChartSelected(QChart *chart); | |
56 | private: |
|
56 | private: | |
57 | QComboBox *createViewBox(); |
|
57 | QComboBox *createViewBox(); | |
58 | QComboBox *createThemeBox(); |
|
58 | QComboBox *createThemeBox(); | |
59 | QComboBox *createAnimationBox(); |
|
59 | QComboBox *createAnimationBox(); | |
60 | QComboBox *createLegendBox(); |
|
60 | QComboBox *createLegendBox(); | |
61 | QComboBox *createTempleteBox(); |
|
61 | QComboBox *createTempleteBox(); | |
62 | void connectSignals(); |
|
62 | void connectSignals(); | |
63 | void createProxyWidgets(); |
|
63 | void createProxyWidgets(); | |
64 | void comboBoxFocused(QComboBox *combox); |
|
64 | void comboBoxFocused(QComboBox *combox); | |
65 | inline void checkAnimationOptions(); |
|
65 | inline void checkAnimationOptions(); | |
66 | inline void checkView(); |
|
66 | inline void checkView(); | |
67 | inline void checkLegend(); |
|
67 | inline void checkLegend(); | |
68 | inline void checkOpenGL(); |
|
68 | inline void checkOpenGL(); | |
69 | inline void checkTheme(); |
|
69 | inline void checkTheme(); | |
70 | inline void checkState(); |
|
70 | inline void checkState(); | |
71 | inline void checkTemplate(); |
|
71 | inline void checkTemplate(); | |
72 | QMenu *createMenu(); |
|
72 | QMenu *createMenu(); | |
73 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); |
|
73 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); | |
74 | void initializeFromParamaters(const QVariantHash ¶meters); |
|
74 | void initializeFromParamaters(const QVariantHash ¶meters); | |
75 |
|
75 | |||
76 | private: |
|
76 | private: | |
77 | QGraphicsScene *m_scene; |
|
77 | QGraphicsScene *m_scene; | |
78 | View *m_view; |
|
78 | View *m_view; | |
79 | QHash<QString, QGraphicsProxyWidget *> m_widgetHash; |
|
79 | QHash<QString, QGraphicsProxyWidget *> m_widgetHash; | |
80 |
|
80 | |||
81 | QGraphicsWidget *m_form; |
|
81 | QGraphicsWidget *m_form; | |
82 | QComboBox *m_themeComboBox; |
|
82 | QComboBox *m_themeComboBox; | |
83 | QCheckBox *m_antialiasCheckBox; |
|
83 | QCheckBox *m_antialiasCheckBox; | |
84 | QComboBox *m_animatedComboBox; |
|
84 | QComboBox *m_animatedComboBox; | |
85 | QComboBox *m_legendComboBox; |
|
85 | QComboBox *m_legendComboBox; | |
86 | QComboBox *m_templateComboBox; |
|
86 | QComboBox *m_templateComboBox; | |
87 | QComboBox *m_viewComboBox; |
|
87 | QComboBox *m_viewComboBox; | |
88 | QCheckBox *m_openGLCheckBox; |
|
88 | QCheckBox *m_openGLCheckBox; | |
89 | QCheckBox *m_zoomCheckBox; |
|
89 | QCheckBox *m_zoomCheckBox; | |
90 | QCheckBox *m_scrollCheckBox; |
|
90 | QCheckBox *m_scrollCheckBox; | |
91 | QGraphicsLinearLayout *m_baseLayout; |
|
91 | QGraphicsLinearLayout *m_baseLayout; | |
92 | QMenu *m_menu; |
|
92 | QMenu *m_menu; | |
93 | int m_template; |
|
93 | int m_template; | |
94 | Grid *m_grid; |
|
94 | Grid *m_grid; | |
|
95 | QString m_category; | |||
|
96 | QString m_subcategory; | |||
|
97 | QString m_name; | |||
95 |
|
98 | |||
96 | friend class ComboBox; |
|
99 | friend class ComboBox; | |
97 | }; |
|
100 | }; | |
98 |
|
101 | |||
99 | class ComboBox: public QComboBox |
|
102 | class ComboBox: public QComboBox | |
100 | { |
|
103 | { | |
101 | public: |
|
104 | public: | |
102 | ComboBox(Window *window, QWidget *parent = 0): QComboBox(parent), m_window(window) |
|
105 | ComboBox(Window *window, QWidget *parent = 0): QComboBox(parent), m_window(window) | |
103 | {} |
|
106 | {} | |
104 |
|
107 | |||
105 | protected: |
|
108 | protected: | |
106 | void focusInEvent(QFocusEvent *e) { |
|
109 | void focusInEvent(QFocusEvent *e) { | |
107 | QComboBox::focusInEvent(e); |
|
110 | QComboBox::focusInEvent(e); | |
108 | m_window->comboBoxFocused(this); |
|
111 | m_window->comboBoxFocused(this); | |
109 | } |
|
112 | } | |
110 | private: |
|
113 | private: | |
111 | Window *m_window; |
|
114 | Window *m_window; | |
112 | }; |
|
115 | }; | |
113 |
|
116 | |||
114 | #endif |
|
117 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now