##// END OF EJS Templates
Refactor charviewer...
Michal Klocek -
r2127:74495bad3a7b
parent child
Show More
@@ -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 TARGET = chartviewer
3 TARGET = chartviewer
4 QT += opengl
4 QT += opengl
5 INCLUDEPATH += .
5 INCLUDEPATH += .
6 SOURCES += main.cpp window.cpp view.cpp
6 SOURCES += main.cpp window.cpp view.cpp grid.cpp
7 HEADERS += window.h view.h charts.h model.h
7 HEADERS += window.h view.h charts.h model.h grid.h
8
8
@@ -20,6 +20,7
20
20
21 #include "window.h"
21 #include "window.h"
22 #include "view.h"
22 #include "view.h"
23 #include "grid.h"
23 #include "charts.h"
24 #include "charts.h"
24 #include <QChartView>
25 #include <QChartView>
25 #include <QAreaSeries>
26 #include <QAreaSeries>
@@ -32,7 +33,6
32 #include <QGroupBox>
33 #include <QGroupBox>
33 #include <QLabel>
34 #include <QLabel>
34 #include <QGraphicsScene>
35 #include <QGraphicsScene>
35 #include <QGraphicsGridLayout>
36 #include <QGraphicsLinearLayout>
36 #include <QGraphicsLinearLayout>
37 #include <QGraphicsProxyWidget>
37 #include <QGraphicsProxyWidget>
38 #include <QGLWidget>
38 #include <QGLWidget>
@@ -42,12 +42,8
42
42
43 Window::Window(const QVariantHash& parameters,QWidget *parent) :
43 Window::Window(const QVariantHash& parameters,QWidget *parent) :
44 QMainWindow(parent),
44 QMainWindow(parent),
45 m_listCount(3),
46 m_valueMax(10),
47 m_valueCount(7),
48 m_scene(new QGraphicsScene(this)),
45 m_scene(new QGraphicsScene(this)),
49 m_view(0),
46 m_view(0),
50 m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)),
51 m_form(0),
47 m_form(0),
52 m_themeComboBox(0),
48 m_themeComboBox(0),
53 m_antialiasCheckBox(0),
49 m_antialiasCheckBox(0),
@@ -57,12 +53,10 Window::Window(const QVariantHash& parameters,QWidget *parent) :
57 m_openGLCheckBox(0),
53 m_openGLCheckBox(0),
58 m_zoomCheckBox(0),
54 m_zoomCheckBox(0),
59 m_scrollCheckBox(0),
55 m_scrollCheckBox(0),
60 m_rubberBand(new QGraphicsRectItem()),
56 m_baseLayout(new QGraphicsLinearLayout()),
61 m_baseLayout(new QGraphicsGridLayout()),
62 m_menu(createMenu()),
57 m_menu(createMenu()),
63 m_state(NoState),
58 m_template(0),
64 m_currentState(NoState),
59 m_grid(new Grid(3))
65 m_template(0)
66 {
60 {
67 createProxyWidgets();
61 createProxyWidgets();
68 // create layout
62 // create layout
@@ -82,29 +76,16 Window::Window(const QVariantHash& parameters,QWidget *parent) :
82 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
76 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
83 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
77 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
84 settingsLayout->addStretch();
78 settingsLayout->addStretch();
85 m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
86
79
87 //create charts
80 m_grid->createCharts();
88 Charts::ChartList list = Charts::chartList();
89
81
90 for (int i = 0; i < 9; ++i) {
82 m_baseLayout->setOrientation(Qt::Horizontal);
91 QChart *chart = 0;
83 m_baseLayout->addItem(m_grid);
92 if (i < list.size()) {
84 m_baseLayout->addItem(settingsLayout);
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 }
102
85
103 m_form = new QGraphicsWidget();
86 m_form = new QGraphicsWidget();
104 m_form->setLayout(m_baseLayout);
87 m_form->setLayout(m_baseLayout);
105 m_scene->addItem(m_form);
88 m_scene->addItem(m_form);
106 m_scene->addItem(m_rubberBand);
107 m_rubberBand->setVisible(false);
108
89
109 m_view = new View(m_scene, m_form);
90 m_view = new View(m_scene, m_form);
110 m_view->setMinimumSize(m_form->minimumSize().toSize());
91 m_view->setMinimumSize(m_form->minimumSize().toSize());
@@ -133,6 +114,7 void Window::connectSignals()
133 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
114 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
134 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
135 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
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 void Window::createProxyWidgets()
120 void Window::createProxyWidgets()
@@ -270,10 +252,10 void Window::checkLegend()
270 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
252 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
271
253
272 if (!alignment) {
254 if (!alignment) {
273 foreach (QChart *chart, m_chartHash.keys())
255 foreach (QChart *chart, m_grid->charts())
274 chart->legend()->hide();
256 chart->legend()->hide();
275 } else {
257 } else {
276 foreach (QChart *chart, m_chartHash.keys()) {
258 foreach (QChart *chart, m_grid->charts()) {
277 chart->legend()->setAlignment(alignment);
259 chart->legend()->setAlignment(alignment);
278 chart->legend()->show();
260 chart->legend()->show();
279 }
261 }
@@ -304,8 +286,10 void Window::checkAnimationOptions()
304 QChart::AnimationOptions options(
286 QChart::AnimationOptions options(
305 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
287 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
306
288
307 if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) {
289 QList<QChart*> charts = m_grid->charts();
308 foreach (QChart *chart, m_chartHash.keys())
290
291 if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) {
292 foreach (QChart *chart, charts)
309 chart->setAnimationOptions(options);
293 chart->setAnimationOptions(options);
310 }
294 }
311 }
295 }
@@ -314,68 +298,33 void Window::checkState()
314 {
298 {
315 bool scroll = m_scrollCheckBox->isChecked();
299 bool scroll = m_scrollCheckBox->isChecked();
316
300
317 if (m_state != ScrollState && scroll) {
301
318 m_state = ScrollState;
302 if (m_grid->state() != Grid::ScrollState && scroll) {
303 m_grid->setState(Grid::ScrollState);
319 m_zoomCheckBox->setChecked(false);
304 m_zoomCheckBox->setChecked(false);
320 } else if (!scroll && m_state == ScrollState) {
305 } else if (!scroll && m_grid->state() == Grid::ScrollState) {
321 m_state = NoState;
306 m_grid->setState(Grid::NoState);
322 }
307 }
323
308
324 bool zoom = m_zoomCheckBox->isChecked();
309 bool zoom = m_zoomCheckBox->isChecked();
325
310
326 if (m_state != ZoomState && zoom) {
311 if (m_grid->state() != Grid::ZoomState && zoom) {
327 m_state = ZoomState;
312 m_grid->setState(Grid::ZoomState);
328 m_scrollCheckBox->setChecked(false);
313 m_scrollCheckBox->setChecked(false);
329 } else if (!zoom && m_state == ZoomState) {
314 } else if (!zoom && m_grid->state() == Grid::ZoomState) {
330 m_state = NoState;
315 m_grid->setState(Grid::NoState);
331 }
316 }
332 }
317 }
333
318
334 void Window::checkTemplate()
319 void Window::checkTemplate()
335 {
320 {
336
337 int index = m_templateComboBox->currentIndex();
321 int index = m_templateComboBox->currentIndex();
338 if (m_template == index || index == 0)
322 if (m_template == index || index == 0)
339 return;
323 return;
340
324
341 m_template = index;
325 m_template = index;
342
343 QString category = m_templateComboBox->itemData(index).toString();
326 QString category = m_templateComboBox->itemData(index).toString();
344 Charts::ChartList list = Charts::chartList();
327 m_grid->createCharts(category);
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();
379 }
328 }
380
329
381 void Window::checkTheme()
330 void Window::checkTheme()
@@ -383,7 +332,7 void Window::checkTheme()
383 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
332 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
384 m_themeComboBox->currentIndex()).toInt();
333 m_themeComboBox->currentIndex()).toInt();
385
334
386 foreach (QChart *chart, m_chartHash.keys())
335 foreach (QChart *chart, m_grid->charts())
387 chart->setTheme(theme);
336 chart->setTheme(theme);
388
337
389 QPalette pal = window()->palette();
338 QPalette pal = window()->palette();
@@ -415,110 +364,7 void Window::checkTheme()
415 foreach (QGraphicsProxyWidget *widget, m_widgetHash)
364 foreach (QGraphicsProxyWidget *widget, m_widgetHash)
416 widget->setPalette(pal);
365 widget->setPalette(pal);
417 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
366 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
418 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
367 m_grid->setRubberPen(pal.color((QPalette::WindowText)));
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 }
522 }
368 }
523
369
524 void Window::comboBoxFocused(QComboBox *combobox)
370 void Window::comboBoxFocused(QComboBox *combobox)
@@ -531,29 +377,17 void Window::comboBoxFocused(QComboBox *combobox)
531 }
377 }
532 }
378 }
533
379
534 void Window::handleMenu(QChart *qchart)
380 void Window::handleChartSelected(QChart *qchart)
535 {
381 {
382 if(m_templateComboBox->currentIndex() != 0) return;
383
536 QAction *chosen = m_menu->exec(QCursor::pos());
384 QAction *chosen = m_menu->exec(QCursor::pos());
537
385
538 if (chosen) {
386 if (chosen) {
539 Chart *chart = (Chart *) chosen->data().value<void *>();
387 Chart *chart = (Chart *) chosen->data().value<void *>();
540 int index = m_chartHash[qchart];
388 m_grid->replaceChart(qchart,chart);
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;
554 updateUI();
389 updateUI();
555 }
390 }
556
557 }
391 }
558
392
559 QMenu *Window::createMenu()
393 QMenu *Window::createMenu()
@@ -594,7 +428,6 QMenu *Window::createMenu()
594 }
428 }
595 }
429 }
596 }
430 }
597
598 return result;
431 return result;
599 }
432 }
600
433
@@ -20,7 +20,6
20
20
21 #ifndef WINDOW_H
21 #ifndef WINDOW_H
22 #define WINDOW_H
22 #define WINDOW_H
23 #include "model.h"
24 #include <QMainWindow>
23 #include <QMainWindow>
25 #include <QChartGlobal>
24 #include <QChartGlobal>
26 #include <QHash>
25 #include <QHash>
@@ -31,8 +30,9 class QGraphicsRectItem;
31 class QGraphicsScene;
30 class QGraphicsScene;
32 class QGraphicsWidget;
31 class QGraphicsWidget;
33 class View;
32 class View;
34 class QGraphicsGridLayout;
33 class QGraphicsLinearLayout;
35 class Chart;
34 class Chart;
35 class Grid;
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 class QChart;
38 class QChart;
@@ -44,7 +44,6 QTCOMMERCIALCHART_USE_NAMESPACE
44 class Window: public QMainWindow
44 class Window: public QMainWindow
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 enum State { NoState = 0, ZoomState, ScrollState};
48 public:
47 public:
49 explicit Window(const QVariantHash& parameters, QWidget *parent = 0);
48 explicit Window(const QVariantHash& parameters, QWidget *parent = 0);
50 ~Window();
49 ~Window();
@@ -52,6 +51,7 public:
52 private Q_SLOTS:
51 private Q_SLOTS:
53 void updateUI();
52 void updateUI();
54 void handleGeometryChanged();
53 void handleGeometryChanged();
54 void handleChartSelected(QChart *chart);
55 private:
55 private:
56 QComboBox *createThemeBox();
56 QComboBox *createThemeBox();
57 QComboBox *createAnimationBox();
57 QComboBox *createAnimationBox();
@@ -67,24 +67,18 private:
67 inline void checkState();
67 inline void checkState();
68 inline void checkTemplate();
68 inline void checkTemplate();
69 QMenu *createMenu();
69 QMenu *createMenu();
70 void handleMenu(QChart *chart);
71 QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
70 QAction *createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, const QVariant &data);
72 void initializeFromParamaters(const QVariantHash& parameters);
71 void initializeFromParamaters(const QVariantHash& parameters);
73
72
74 protected:
73 protected:
75 void mousePressEvent(QMouseEvent *event);
74 //void mousePressEvent(QMouseEvent *event);
76 void mouseMoveEvent(QMouseEvent *event);
75 //void mouseMoveEvent(QMouseEvent *event);
77 void mouseReleaseEvent(QMouseEvent *event);
76 //void mouseReleaseEvent(QMouseEvent *event);
78
77
79 private:
78 private:
80 int m_listCount;
81 int m_valueMax;
82 int m_valueCount;
83 QGraphicsScene *m_scene;
79 QGraphicsScene *m_scene;
84 View *m_view;
80 View *m_view;
85 QHash<QString, QGraphicsProxyWidget *> m_widgetHash;
81 QHash<QString, QGraphicsProxyWidget *> m_widgetHash;
86 QHash<QChart *, int> m_chartHash;
87 DataTable m_dataTable;
88
82
89 QGraphicsWidget *m_form;
83 QGraphicsWidget *m_form;
90 QComboBox *m_themeComboBox;
84 QComboBox *m_themeComboBox;
@@ -95,13 +89,10 private:
95 QCheckBox *m_openGLCheckBox;
89 QCheckBox *m_openGLCheckBox;
96 QCheckBox *m_zoomCheckBox;
90 QCheckBox *m_zoomCheckBox;
97 QCheckBox *m_scrollCheckBox;
91 QCheckBox *m_scrollCheckBox;
98 QPoint m_origin;
92 QGraphicsLinearLayout *m_baseLayout;
99 QGraphicsRectItem *m_rubberBand;
100 QGraphicsGridLayout *m_baseLayout;
101 QMenu *m_menu;
93 QMenu *m_menu;
102 State m_state;
103 State m_currentState;
104 int m_template;
94 int m_template;
95 Grid* m_grid;
105
96
106 friend class ComboBox;
97 friend class ComboBox;
107 };
98 };
General Comments 0
You need to be logged in to leave comments. Login now