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