@@ -0,0 +1,238 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #include "grid.h" | |
|
22 | #include "charts.h" | |
|
23 | #include <qchart.h> | |
|
24 | #include <QGraphicsGridLayout> | |
|
25 | #include <QGraphicsSceneMouseEvent> | |
|
26 | #include <QDebug> | |
|
27 | ||
|
28 | Grid::Grid(int size,QGraphicsItem *parent):QGraphicsWidget(parent), | |
|
29 | m_listCount(3), | |
|
30 | m_valueMax(10), | |
|
31 | m_valueCount(7), | |
|
32 | m_size(size), | |
|
33 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
|
34 | m_rubberBand(new QGraphicsRectItem()), | |
|
35 | m_gridLayout(new QGraphicsGridLayout()) | |
|
36 | { | |
|
37 | setLayout(m_gridLayout); | |
|
38 | m_rubberBand->setParentItem(this); | |
|
39 | m_rubberBand->setVisible(false); | |
|
40 | m_rubberBand->setZValue(2); | |
|
41 | } | |
|
42 | ||
|
43 | Grid::~Grid() | |
|
44 | { | |
|
45 | ||
|
46 | } | |
|
47 | ||
|
48 | void Grid::createCharts() | |
|
49 | { | |
|
50 | clear(); | |
|
51 | ||
|
52 | Charts::ChartList list = Charts::chartList(); | |
|
53 | ||
|
54 | for (int i = 0; i < m_size * m_size; ++i) { | |
|
55 | QChart *chart = 0; | |
|
56 | if (i < list.size()) { | |
|
57 | chart = list.at(i)->createChart(m_dataTable); | |
|
58 | } | |
|
59 | else { | |
|
60 | chart = new QChart(); | |
|
61 | chart->setTitle(QObject::tr("Empty")); | |
|
62 | } | |
|
63 | ||
|
64 | m_gridLayout->addItem(chart, i / m_size, i % m_size); | |
|
65 | m_chartHash[chart] = i; | |
|
66 | } | |
|
67 | ||
|
68 | } | |
|
69 | ||
|
70 | void Grid::createCharts(const QString& category) | |
|
71 | { | |
|
72 | clear(); | |
|
73 | ||
|
74 | QChart *qchart(0); | |
|
75 | Charts::ChartList list = Charts::chartList(); | |
|
76 | ||
|
77 | int j = 0; | |
|
78 | for (int i = 0; i < list.size(); ++i) { | |
|
79 | Chart *chart = list.at(i); | |
|
80 | if (chart->category() == category && j < m_size * m_size) { | |
|
81 | qchart = list.at(i)->createChart(m_dataTable); | |
|
82 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |
|
83 | m_chartHash[qchart] = j; | |
|
84 | j++; | |
|
85 | } | |
|
86 | } | |
|
87 | for (; j < m_size * m_size; ++j) { | |
|
88 | qchart = new QChart(); | |
|
89 | qchart->setTitle(QObject::tr("Empty")); | |
|
90 | m_gridLayout->addItem(qchart, j / m_size, j % m_size); | |
|
91 | m_chartHash[qchart] = j; | |
|
92 | } | |
|
93 | ||
|
94 | m_gridLayout->activate(); | |
|
95 | } | |
|
96 | ||
|
97 | void Grid::clear() | |
|
98 | { | |
|
99 | for (int i = 0; i < m_gridLayout->count(); ++i) { | |
|
100 | m_gridLayout->removeAt(i); | |
|
101 | } | |
|
102 | ||
|
103 | qDeleteAll(m_chartHash.keys()); | |
|
104 | m_chartHash.clear(); | |
|
105 | } | |
|
106 | ||
|
107 | QList<QChart*> Grid::charts() | |
|
108 | { | |
|
109 | return m_chartHash.keys(); | |
|
110 | } | |
|
111 | ||
|
112 | void Grid::setState(State state) | |
|
113 | { | |
|
114 | m_state = state; | |
|
115 | } | |
|
116 | ||
|
117 | void Grid::setRubberPen(const QPen& pen) | |
|
118 | { | |
|
119 | m_rubberBand->setPen(pen); | |
|
120 | } | |
|
121 | ||
|
122 | void Grid::replaceChart(QChart* oldChart, Chart* newChart) | |
|
123 | { | |
|
124 | int index = m_chartHash[oldChart]; | |
|
125 | //not in 4.7.2 m_baseLayout->removeItem(qchart); | |
|
126 | for (int i = 0; i < m_gridLayout->count(); ++i) { | |
|
127 | if (m_gridLayout->itemAt(i) == oldChart) { | |
|
128 | m_gridLayout->removeAt(i); | |
|
129 | break; | |
|
130 | } | |
|
131 | } | |
|
132 | m_chartHash.remove(oldChart); | |
|
133 | QChart *chart = newChart->createChart(m_dataTable); | |
|
134 | m_gridLayout->addItem(chart, index / m_size, index % m_size); | |
|
135 | m_chartHash[chart] = index; | |
|
136 | delete oldChart; | |
|
137 | } | |
|
138 | ||
|
139 | void Grid::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
|
140 | { | |
|
141 | if (event->button() == Qt::LeftButton) { | |
|
142 | ||
|
143 | m_origin = event->pos(); | |
|
144 | m_currentState = NoState; | |
|
145 | ||
|
146 | foreach (QChart *chart, charts()) { | |
|
147 | ||
|
148 | QRectF geometryRect = chart->geometry(); | |
|
149 | QRectF plotArea = chart->plotArea(); | |
|
150 | plotArea.translate(geometryRect.topLeft()); | |
|
151 | if (plotArea.contains(m_origin)) { | |
|
152 | m_currentState = m_state; | |
|
153 | if (m_currentState == NoState) emit chartSelected(chart); | |
|
154 | break; | |
|
155 | } | |
|
156 | } | |
|
157 | if (m_currentState == ZoomState) { | |
|
158 | m_rubberBand->setRect(QRectF(m_origin, QSize())); | |
|
159 | m_rubberBand->setVisible(true); | |
|
160 | } | |
|
161 | ||
|
162 | event->accept(); | |
|
163 | } | |
|
164 | ||
|
165 | if (event->button() == Qt::RightButton) { | |
|
166 | m_origin = event->pos(); | |
|
167 | m_currentState = m_state; | |
|
168 | } | |
|
169 | } | |
|
170 | ||
|
171 | void Grid::mouseMoveEvent(QGraphicsSceneMouseEvent *event) | |
|
172 | { | |
|
173 | if (m_currentState != NoState) { | |
|
174 | ||
|
175 | foreach (QChart *chart, charts()) { | |
|
176 | ||
|
177 | QRectF geometryRect = chart->geometry(); | |
|
178 | QRectF plotArea = chart->plotArea(); | |
|
179 | plotArea.translate(geometryRect.topLeft()); | |
|
180 | ||
|
181 | if (plotArea.contains(m_origin)) { | |
|
182 | if (m_currentState == ScrollState) { | |
|
183 | QPointF delta = m_origin - event->pos(); | |
|
184 | chart->scroll(delta.x(), -delta.y()); | |
|
185 | } | |
|
186 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) | |
|
187 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); | |
|
188 | break; | |
|
189 | } | |
|
190 | } | |
|
191 | if (m_currentState == ScrollState) | |
|
192 | m_origin = event->pos(); | |
|
193 | event->accept(); | |
|
194 | } | |
|
195 | } | |
|
196 | ||
|
197 | void Grid::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |
|
198 | { | |
|
199 | if (event->button() == Qt::LeftButton) { | |
|
200 | if (m_currentState == ZoomState) { | |
|
201 | m_rubberBand->setVisible(false); | |
|
202 | ||
|
203 | foreach (QChart *chart, charts()) { | |
|
204 | ||
|
205 | QRectF geometryRect = chart->geometry(); | |
|
206 | QRectF plotArea = chart->plotArea(); | |
|
207 | plotArea.translate(geometryRect.topLeft()); | |
|
208 | ||
|
209 | if (plotArea.contains(m_origin)) { | |
|
210 | QRectF rect = m_rubberBand->rect(); | |
|
211 | rect.translate(-geometryRect.topLeft()); | |
|
212 | chart->zoomIn(rect); | |
|
213 | break; | |
|
214 | } | |
|
215 | } | |
|
216 | } | |
|
217 | ||
|
218 | m_currentState = NoState; | |
|
219 | event->accept(); | |
|
220 | } | |
|
221 | ||
|
222 | if (event->button() == Qt::RightButton) { | |
|
223 | ||
|
224 | if (m_currentState == ZoomState) { | |
|
225 | foreach (QChart *chart, charts()) { | |
|
226 | ||
|
227 | QRectF geometryRect = chart->geometry(); | |
|
228 | QRectF plotArea = chart->plotArea(); | |
|
229 | plotArea.translate(geometryRect.topLeft()); | |
|
230 | ||
|
231 | if (plotArea.contains(m_origin)) { | |
|
232 | chart->zoomOut(); | |
|
233 | break; | |
|
234 | } | |
|
235 | } | |
|
236 | } | |
|
237 | } | |
|
238 | } |
@@ -0,0 +1,75 | |||
|
1 | /**************************************************************************** | |
|
2 | ** | |
|
3 | ** Copyright (C) 2012 Digia Plc | |
|
4 | ** All rights reserved. | |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
|
6 | ** | |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
|
8 | ** | |
|
9 | ** $QT_BEGIN_LICENSE$ | |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
|
13 | ** a written agreement between you and Digia. | |
|
14 | ** | |
|
15 | ** If you have questions regarding the use of this file, please use | |
|
16 | ** contact form at http://qt.digia.com | |
|
17 | ** $QT_END_LICENSE$ | |
|
18 | ** | |
|
19 | ****************************************************************************/ | |
|
20 | ||
|
21 | #ifndef GRID_H_ | |
|
22 | #define GRID_H_ | |
|
23 | ||
|
24 | #include "model.h" | |
|
25 | #include <QGraphicsWidget> | |
|
26 | #include <QChartGlobal> | |
|
27 | ||
|
28 | class QGraphicsGridLayout; | |
|
29 | class GridControl; | |
|
30 | class Chart; | |
|
31 | ||
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
|
33 | class QChart; | |
|
34 | QTCOMMERCIALCHART_END_NAMESPACE | |
|
35 | ||
|
36 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
37 | ||
|
38 | class Grid : public QGraphicsWidget | |
|
39 | { | |
|
40 | Q_OBJECT | |
|
41 | public: | |
|
42 | enum State { NoState = 0, ZoomState, ScrollState}; | |
|
43 | Grid(int size , QGraphicsItem *parent = 0 ); | |
|
44 | ~Grid(); | |
|
45 | QList<QChart*> charts(); | |
|
46 | void createCharts(); | |
|
47 | void createCharts(const QString& category); | |
|
48 | void replaceChart(QChart* oldChart, Chart* newChart); | |
|
49 | void setState(State state); | |
|
50 | State state(){ return m_state; }; | |
|
51 | void setRubberPen(const QPen& pen); | |
|
52 | Q_SIGNAL | |
|
53 | void chartSelected(QChart* chart); | |
|
54 | protected: | |
|
55 | void mousePressEvent(QGraphicsSceneMouseEvent *event); | |
|
56 | void mouseMoveEvent(QGraphicsSceneMouseEvent *event); | |
|
57 | void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); | |
|
58 | private: | |
|
59 | void clear(); | |
|
60 | private: | |
|
61 | int m_listCount; | |
|
62 | int m_valueMax; | |
|
63 | int m_valueCount; | |
|
64 | int m_size; | |
|
65 | DataTable m_dataTable; | |
|
66 | QHash<QChart *, int> m_chartHash; | |
|
67 | GridControl* m_control; | |
|
68 | State m_state; | |
|
69 | State m_currentState; | |
|
70 | QPointF m_origin; | |
|
71 | QGraphicsRectItem *m_rubberBand; | |
|
72 | QGraphicsGridLayout* m_gridLayout; | |
|
73 | }; | |
|
74 | ||
|
75 | #endif /* GRID_H_ */ |
@@ -3,6 +3,6 include(charts/charts.pri) | |||
|
3 | 3 | TARGET = chartviewer |
|
4 | 4 | QT += opengl |
|
5 | 5 | INCLUDEPATH += . |
|
6 |
SOURCES += main.cpp window.cpp view.cpp |
|
|
7 | HEADERS += window.h view.h charts.h model.h | |
|
6 | SOURCES += main.cpp window.cpp view.cpp grid.cpp | |
|
7 | HEADERS += window.h view.h charts.h model.h grid.h | |
|
8 | 8 |
@@ -20,6 +20,7 | |||
|
20 | 20 | |
|
21 | 21 | #include "window.h" |
|
22 | 22 | #include "view.h" |
|
23 | #include "grid.h" | |
|
23 | 24 | #include "charts.h" |
|
24 | 25 | #include <QChartView> |
|
25 | 26 | #include <QAreaSeries> |
@@ -32,7 +33,6 | |||
|
32 | 33 | #include <QGroupBox> |
|
33 | 34 | #include <QLabel> |
|
34 | 35 | #include <QGraphicsScene> |
|
35 | #include <QGraphicsGridLayout> | |
|
36 | 36 | #include <QGraphicsLinearLayout> |
|
37 | 37 | #include <QGraphicsProxyWidget> |
|
38 | 38 | #include <QGLWidget> |
@@ -42,12 +42,8 | |||
|
42 | 42 | |
|
43 | 43 | Window::Window(const QVariantHash& parameters,QWidget *parent) : |
|
44 | 44 | QMainWindow(parent), |
|
45 | m_listCount(3), | |
|
46 | m_valueMax(10), | |
|
47 | m_valueCount(7), | |
|
48 | 45 | m_scene(new QGraphicsScene(this)), |
|
49 | 46 | m_view(0), |
|
50 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
|
51 | 47 | m_form(0), |
|
52 | 48 | m_themeComboBox(0), |
|
53 | 49 | m_antialiasCheckBox(0), |
@@ -57,12 +53,10 Window::Window(const QVariantHash& parameters,QWidget *parent) : | |||
|
57 | 53 | m_openGLCheckBox(0), |
|
58 | 54 | m_zoomCheckBox(0), |
|
59 | 55 | m_scrollCheckBox(0), |
|
60 |
m_ |
|
|
61 | m_baseLayout(new QGraphicsGridLayout()), | |
|
56 | m_baseLayout(new QGraphicsLinearLayout()), | |
|
62 | 57 | m_menu(createMenu()), |
|
63 |
m_ |
|
|
64 | m_currentState(NoState), | |
|
65 | m_template(0) | |
|
58 | m_template(0), | |
|
59 | m_grid(new Grid(3)) | |
|
66 | 60 | { |
|
67 | 61 | createProxyWidgets(); |
|
68 | 62 | // create layout |
@@ -82,29 +76,16 Window::Window(const QVariantHash& parameters,QWidget *parent) : | |||
|
82 | 76 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); |
|
83 | 77 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); |
|
84 | 78 | settingsLayout->addStretch(); |
|
85 | m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1); | |
|
86 | 79 | |
|
87 |
|
|
|
88 | Charts::ChartList list = Charts::chartList(); | |
|
80 | m_grid->createCharts(); | |
|
89 | 81 | |
|
90 | for (int i = 0; i < 9; ++i) { | |
|
91 | QChart *chart = 0; | |
|
92 | if (i < list.size()) { | |
|
93 | chart = list.at(i)->createChart(m_dataTable); | |
|
94 | } else { | |
|
95 | chart = new QChart(); | |
|
96 | chart->setTitle(tr("Empty")); | |
|
97 | } | |
|
98 | ||
|
99 | m_baseLayout->addItem(chart, i / 3, i % 3); | |
|
100 | m_chartHash[chart] = i; | |
|
101 | } | |
|
82 | m_baseLayout->setOrientation(Qt::Horizontal); | |
|
83 | m_baseLayout->addItem(m_grid); | |
|
84 | m_baseLayout->addItem(settingsLayout); | |
|
102 | 85 | |
|
103 | 86 | m_form = new QGraphicsWidget(); |
|
104 | 87 | m_form->setLayout(m_baseLayout); |
|
105 | 88 | m_scene->addItem(m_form); |
|
106 | m_scene->addItem(m_rubberBand); | |
|
107 | m_rubberBand->setVisible(false); | |
|
108 | 89 | |
|
109 | 90 | m_view = new View(m_scene, m_form); |
|
110 | 91 | m_view->setMinimumSize(m_form->minimumSize().toSize()); |
@@ -133,6 +114,7 void Window::connectSignals() | |||
|
133 | 114 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
134 | 115 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
135 | 116 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
117 | QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)),this,SLOT(handleChartSelected(QChart*))); | |
|
136 | 118 | } |
|
137 | 119 | |
|
138 | 120 | void Window::createProxyWidgets() |
@@ -270,10 +252,10 void Window::checkLegend() | |||
|
270 | 252 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
271 | 253 | |
|
272 | 254 | if (!alignment) { |
|
273 |
foreach (QChart *chart, m_chart |
|
|
255 | foreach (QChart *chart, m_grid->charts()) | |
|
274 | 256 | chart->legend()->hide(); |
|
275 | 257 | } else { |
|
276 |
foreach (QChart *chart, m_chart |
|
|
258 | foreach (QChart *chart, m_grid->charts()) { | |
|
277 | 259 | chart->legend()->setAlignment(alignment); |
|
278 | 260 | chart->legend()->show(); |
|
279 | 261 | } |
@@ -304,8 +286,10 void Window::checkAnimationOptions() | |||
|
304 | 286 | QChart::AnimationOptions options( |
|
305 | 287 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
306 | 288 | |
|
307 | if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) { | |
|
308 | foreach (QChart *chart, m_chartHash.keys()) | |
|
289 | QList<QChart*> charts = m_grid->charts(); | |
|
290 | ||
|
291 | if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) { | |
|
292 | foreach (QChart *chart, charts) | |
|
309 | 293 | chart->setAnimationOptions(options); |
|
310 | 294 | } |
|
311 | 295 | } |
@@ -314,68 +298,33 void Window::checkState() | |||
|
314 | 298 | { |
|
315 | 299 | bool scroll = m_scrollCheckBox->isChecked(); |
|
316 | 300 | |
|
317 | if (m_state != ScrollState && scroll) { | |
|
318 | m_state = ScrollState; | |
|
301 | ||
|
302 | if (m_grid->state() != Grid::ScrollState && scroll) { | |
|
303 | m_grid->setState(Grid::ScrollState); | |
|
319 | 304 | m_zoomCheckBox->setChecked(false); |
|
320 | } else if (!scroll && m_state == ScrollState) { | |
|
321 |
m_ |
|
|
305 | } else if (!scroll && m_grid->state() == Grid::ScrollState) { | |
|
306 | m_grid->setState(Grid::NoState); | |
|
322 | 307 | } |
|
323 | 308 | |
|
324 | 309 | bool zoom = m_zoomCheckBox->isChecked(); |
|
325 | 310 | |
|
326 | if (m_state != ZoomState && zoom) { | |
|
327 |
m_ |
|
|
311 | if (m_grid->state() != Grid::ZoomState && zoom) { | |
|
312 | m_grid->setState(Grid::ZoomState); | |
|
328 | 313 | m_scrollCheckBox->setChecked(false); |
|
329 | } else if (!zoom && m_state == ZoomState) { | |
|
330 |
m_ |
|
|
314 | } else if (!zoom && m_grid->state() == Grid::ZoomState) { | |
|
315 | m_grid->setState(Grid::NoState); | |
|
331 | 316 | } |
|
332 | 317 | } |
|
333 | 318 | |
|
334 | 319 | void Window::checkTemplate() |
|
335 | 320 | { |
|
336 | ||
|
337 | 321 | int index = m_templateComboBox->currentIndex(); |
|
338 | 322 | if (m_template == index || index == 0) |
|
339 | 323 | return; |
|
340 | 324 | |
|
341 | 325 | m_template = index; |
|
342 | ||
|
343 | 326 | QString category = m_templateComboBox->itemData(index).toString(); |
|
344 | Charts::ChartList list = Charts::chartList(); | |
|
345 | ||
|
346 | QList<QChart *> qchartList = m_chartHash.keys(); | |
|
347 | ||
|
348 | foreach (QChart *qchart, qchartList) { | |
|
349 | for (int i = 0 ; i < m_baseLayout->count(); ++i) { | |
|
350 | if (m_baseLayout->itemAt(i) == qchart) { | |
|
351 | m_baseLayout->removeAt(i); | |
|
352 | break; | |
|
353 | } | |
|
354 | } | |
|
355 | } | |
|
356 | ||
|
357 | m_chartHash.clear(); | |
|
358 | qDeleteAll(qchartList); | |
|
359 | ||
|
360 | QChart *qchart(0); | |
|
361 | ||
|
362 | int j = 0; | |
|
363 | for (int i = 0; i < list.size(); ++i) { | |
|
364 | Chart *chart = list.at(i); | |
|
365 | if (chart->category() == category && j < 9) { | |
|
366 | qchart = list.at(i)->createChart(m_dataTable); | |
|
367 | m_baseLayout->addItem(qchart, j / 3, j % 3); | |
|
368 | m_chartHash[qchart] = j; | |
|
369 | j++; | |
|
370 | } | |
|
371 | } | |
|
372 | for (; j < 9; ++j) { | |
|
373 | qchart = new QChart(); | |
|
374 | qchart->setTitle(tr("Empty")); | |
|
375 | m_baseLayout->addItem(qchart, j / 3, j % 3); | |
|
376 | m_chartHash[qchart] = j; | |
|
377 | } | |
|
378 | m_baseLayout->activate(); | |
|
327 | m_grid->createCharts(category); | |
|
379 | 328 | } |
|
380 | 329 | |
|
381 | 330 | void Window::checkTheme() |
@@ -383,7 +332,7 void Window::checkTheme() | |||
|
383 | 332 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
|
384 | 333 | m_themeComboBox->currentIndex()).toInt(); |
|
385 | 334 | |
|
386 |
foreach (QChart *chart, m_chart |
|
|
335 | foreach (QChart *chart, m_grid->charts()) | |
|
387 | 336 | chart->setTheme(theme); |
|
388 | 337 | |
|
389 | 338 | QPalette pal = window()->palette(); |
@@ -415,110 +364,7 void Window::checkTheme() | |||
|
415 | 364 | foreach (QGraphicsProxyWidget *widget, m_widgetHash) |
|
416 | 365 | widget->setPalette(pal); |
|
417 | 366 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
|
418 |
m_ |
|
|
419 | } | |
|
420 | ||
|
421 | void Window::mousePressEvent(QMouseEvent *event) | |
|
422 | { | |
|
423 | if (event->button() == Qt::LeftButton) { | |
|
424 | ||
|
425 | m_origin = event->pos(); | |
|
426 | m_currentState = NoState; | |
|
427 | ||
|
428 | foreach (QChart *chart, m_chartHash.keys()) { | |
|
429 | ||
|
430 | QRectF geometryRect = chart->geometry(); | |
|
431 | QRectF plotArea = chart->plotArea(); | |
|
432 | plotArea.translate(geometryRect.topLeft()); | |
|
433 | if (plotArea.contains(m_origin)) { | |
|
434 | m_currentState = m_state; | |
|
435 | if (m_currentState == NoState && m_templateComboBox->currentIndex() == 0) | |
|
436 | handleMenu(chart); | |
|
437 | break; | |
|
438 | } | |
|
439 | } | |
|
440 | ||
|
441 | if (m_currentState == ZoomState) { | |
|
442 | m_rubberBand->setRect(QRectF(m_origin, QSize())); | |
|
443 | m_rubberBand->setVisible(true); | |
|
444 | } | |
|
445 | ||
|
446 | event->accept(); | |
|
447 | } | |
|
448 | ||
|
449 | if (event->button() == Qt::RightButton) { | |
|
450 | m_origin = event->pos(); | |
|
451 | m_currentState = m_state; | |
|
452 | } | |
|
453 | } | |
|
454 | ||
|
455 | void Window::mouseMoveEvent(QMouseEvent *event) | |
|
456 | { | |
|
457 | if (m_currentState != NoState) { | |
|
458 | ||
|
459 | foreach (QChart *chart, m_chartHash.keys()) { | |
|
460 | ||
|
461 | QRectF geometryRect = chart->geometry(); | |
|
462 | QRectF plotArea = chart->plotArea(); | |
|
463 | plotArea.translate(geometryRect.topLeft()); | |
|
464 | ||
|
465 | if (plotArea.contains(m_origin)) { | |
|
466 | if (m_currentState == ScrollState) { | |
|
467 | QPointF delta = m_origin - event->pos(); | |
|
468 | chart->scroll(delta.x(), -delta.y()); | |
|
469 | } | |
|
470 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) | |
|
471 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); | |
|
472 | break; | |
|
473 | } | |
|
474 | } | |
|
475 | if (m_currentState == ScrollState) | |
|
476 | m_origin = event->pos(); | |
|
477 | event->accept(); | |
|
478 | } | |
|
479 | } | |
|
480 | ||
|
481 | void Window::mouseReleaseEvent(QMouseEvent *event) | |
|
482 | { | |
|
483 | if (event->button() == Qt::LeftButton) { | |
|
484 | if (m_currentState == ZoomState) { | |
|
485 | m_rubberBand->setVisible(false); | |
|
486 | ||
|
487 | foreach (QChart *chart, m_chartHash.keys()) { | |
|
488 | ||
|
489 | QRectF geometryRect = chart->geometry(); | |
|
490 | QRectF plotArea = chart->plotArea(); | |
|
491 | plotArea.translate(geometryRect.topLeft()); | |
|
492 | ||
|
493 | if (plotArea.contains(m_origin)) { | |
|
494 | QRectF rect = m_rubberBand->rect(); | |
|
495 | rect.translate(-geometryRect.topLeft()); | |
|
496 | chart->zoomIn(rect); | |
|
497 | break; | |
|
498 | } | |
|
499 | } | |
|
500 | } | |
|
501 | ||
|
502 | m_currentState = NoState; | |
|
503 | event->accept(); | |
|
504 | } | |
|
505 | ||
|
506 | if (event->button() == Qt::RightButton) { | |
|
507 | ||
|
508 | if (m_currentState == ZoomState) { | |
|
509 | foreach (QChart *chart, m_chartHash.keys()) { | |
|
510 | ||
|
511 | QRectF geometryRect = chart->geometry(); | |
|
512 | QRectF plotArea = chart->plotArea(); | |
|
513 | plotArea.translate(geometryRect.topLeft()); | |
|
514 | ||
|
515 | if (plotArea.contains(m_origin)) { | |
|
516 | chart->zoomOut(); | |
|
517 | break; | |
|
518 | } | |
|
519 | } | |
|
520 | } | |
|
521 | } | |
|
367 | m_grid->setRubberPen(pal.color((QPalette::WindowText))); | |
|
522 | 368 | } |
|
523 | 369 | |
|
524 | 370 | void Window::comboBoxFocused(QComboBox *combobox) |
@@ -531,29 +377,17 void Window::comboBoxFocused(QComboBox *combobox) | |||
|
531 | 377 | } |
|
532 | 378 | } |
|
533 | 379 | |
|
534 |
void Window::handle |
|
|
380 | void Window::handleChartSelected(QChart *qchart) | |
|
535 | 381 | { |
|
382 | if(m_templateComboBox->currentIndex() != 0) return; | |
|
383 | ||
|
536 | 384 | QAction *chosen = m_menu->exec(QCursor::pos()); |
|
537 | 385 | |
|
538 | 386 | if (chosen) { |
|
539 | 387 | Chart *chart = (Chart *) chosen->data().value<void *>(); |
|
540 | int index = m_chartHash[qchart]; | |
|
541 | //not in 4.7.2 m_baseLayout->removeItem(qchart); | |
|
542 | for (int i = 0 ; i < m_baseLayout->count(); ++i) { | |
|
543 | if (m_baseLayout->itemAt(i) == qchart) { | |
|
544 | m_baseLayout->removeAt(i); | |
|
545 | break; | |
|
546 | } | |
|
547 | } | |
|
548 | ||
|
549 | m_chartHash.remove(qchart); | |
|
550 | QChart *newChart = chart->createChart(m_dataTable); | |
|
551 | m_baseLayout->addItem(newChart, index / 3, index % 3); | |
|
552 | m_chartHash[newChart] = index; | |
|
553 | delete qchart; | |
|
388 | m_grid->replaceChart(qchart,chart); | |
|
554 | 389 | updateUI(); |
|
555 | 390 | } |
|
556 | ||
|
557 | 391 | } |
|
558 | 392 | |
|
559 | 393 | QMenu *Window::createMenu() |
@@ -594,7 +428,6 QMenu *Window::createMenu() | |||
|
594 | 428 | } |
|
595 | 429 | } |
|
596 | 430 | } |
|
597 | ||
|
598 | 431 | return result; |
|
599 | 432 | } |
|
600 | 433 |
@@ -20,7 +20,6 | |||
|
20 | 20 | |
|
21 | 21 | #ifndef WINDOW_H |
|
22 | 22 | #define WINDOW_H |
|
23 | #include "model.h" | |
|
24 | 23 | #include <QMainWindow> |
|
25 | 24 | #include <QChartGlobal> |
|
26 | 25 | #include <QHash> |
@@ -31,8 +30,9 class QGraphicsRectItem; | |||
|
31 | 30 | class QGraphicsScene; |
|
32 | 31 | class QGraphicsWidget; |
|
33 | 32 | class View; |
|
34 |
class QGraphics |
|
|
33 | class QGraphicsLinearLayout; | |
|
35 | 34 | class Chart; |
|
35 | class Grid; | |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | class QChart; |
@@ -44,7 +44,6 QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
44 | 44 | class Window: public QMainWindow |
|
45 | 45 | { |
|
46 | 46 | Q_OBJECT |
|
47 | enum State { NoState = 0, ZoomState, ScrollState}; | |
|
48 | 47 | public: |
|
49 | 48 | explicit Window(const QVariantHash& parameters, QWidget *parent = 0); |
|
50 | 49 | ~Window(); |
@@ -52,6 +51,7 public: | |||
|
52 | 51 | private Q_SLOTS: |
|
53 | 52 | void updateUI(); |
|
54 | 53 | void handleGeometryChanged(); |
|
54 | void handleChartSelected(QChart *chart); | |
|
55 | 55 | private: |
|
56 | 56 | QComboBox *createThemeBox(); |
|
57 | 57 | QComboBox *createAnimationBox(); |
@@ -67,24 +67,18 private: | |||
|
67 | 67 | inline void checkState(); |
|
68 | 68 | inline void checkTemplate(); |
|
69 | 69 | QMenu *createMenu(); |
|
70 | void handleMenu(QChart *chart); | |
|
71 | 70 | QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data); |
|
72 | 71 | void initializeFromParamaters(const QVariantHash& parameters); |
|
73 | 72 | |
|
74 | 73 | protected: |
|
75 | void mousePressEvent(QMouseEvent *event); | |
|
76 | void mouseMoveEvent(QMouseEvent *event); | |
|
77 | void mouseReleaseEvent(QMouseEvent *event); | |
|
74 | //void mousePressEvent(QMouseEvent *event); | |
|
75 | //void mouseMoveEvent(QMouseEvent *event); | |
|
76 | //void mouseReleaseEvent(QMouseEvent *event); | |
|
78 | 77 | |
|
79 | 78 | private: |
|
80 | int m_listCount; | |
|
81 | int m_valueMax; | |
|
82 | int m_valueCount; | |
|
83 | 79 | QGraphicsScene *m_scene; |
|
84 | 80 | View *m_view; |
|
85 | 81 | QHash<QString, QGraphicsProxyWidget *> m_widgetHash; |
|
86 | QHash<QChart *, int> m_chartHash; | |
|
87 | DataTable m_dataTable; | |
|
88 | 82 | |
|
89 | 83 | QGraphicsWidget *m_form; |
|
90 | 84 | QComboBox *m_themeComboBox; |
@@ -95,13 +89,10 private: | |||
|
95 | 89 | QCheckBox *m_openGLCheckBox; |
|
96 | 90 | QCheckBox *m_zoomCheckBox; |
|
97 | 91 | QCheckBox *m_scrollCheckBox; |
|
98 | QPoint m_origin; | |
|
99 | QGraphicsRectItem *m_rubberBand; | |
|
100 | QGraphicsGridLayout *m_baseLayout; | |
|
92 | QGraphicsLinearLayout *m_baseLayout; | |
|
101 | 93 | QMenu *m_menu; |
|
102 | State m_state; | |
|
103 | State m_currentState; | |
|
104 | 94 | int m_template; |
|
95 | Grid* m_grid; | |
|
105 | 96 | |
|
106 | 97 | friend class ComboBox; |
|
107 | 98 | }; |
General Comments 0
You need to be logged in to leave comments.
Login now