##// END OF EJS Templates
Adds scroll and zoom to chartviewer
Michal Klocek -
r1748:ee59e61f224b
parent child
Show More
@@ -0,0 +1,55
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 "view.h"
22 #include <QGraphicsWidget>
23 #include <QResizeEvent>
24 #include <QDebug>
25
26 View::View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent):QGraphicsView(scene,parent),
27 m_form(form)
28 {
29 setDragMode(QGraphicsView::NoDrag);
30 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
31 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
32 }
33
34 void View::resizeEvent(QResizeEvent *event)
35 {
36 if (scene())
37 scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
38 if (m_form)
39 m_form->resize(QSizeF(event->size()));
40 QGraphicsView::resizeEvent(event);
41 }
42
43 void View::mouseMoveEvent(QMouseEvent *event)
44 {
45 //BugFix somehow view always eats the mouse move event;
46 event->setAccepted(false);
47 }
48
49 void View::mouseReleaseEvent(QMouseEvent *event)
50 {
51
52 QGraphicsView::mouseReleaseEvent(event);
53 //BugFix somehow view always eats the mouse release event;
54 event->setAccepted(false);
55 }
@@ -0,0 +1,41
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 VIEW_H_
22 #define VIEW_H_
23 #include <QGraphicsView>
24
25 class QGraphicsScene;
26 class QResizeEvent;
27
28 class View: public QGraphicsView
29 {
30 public:
31 View(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent = 0);
32
33 protected:
34 void resizeEvent(QResizeEvent *event);
35 void mouseMoveEvent(QMouseEvent *event);
36 void mouseReleaseEvent(QMouseEvent *event);
37 private:
38 QGraphicsWidget *m_form;
39 };
40
41 #endif
@@ -1,5 +1,5
1 !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" )
1 !include( ../demos.pri ):error( "Couldn't find the demos.pri file!" )
2 TARGET = chartviewer
2 TARGET = chartviewer
3 QT += opengl
3 QT += opengl
4 SOURCES = main.cpp chartwindow.cpp
4 SOURCES = main.cpp window.cpp view.cpp
5 HEADERS = chartwindow.h
5 HEADERS = window.h view.h No newline at end of file
@@ -1,32 +1,32
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartwindow.h"
21 #include "window.h"
22 #include <QApplication>
22 #include <QApplication>
23 #include <QMainWindow>
23 #include <QMainWindow>
24
24
25 int main(int argc, char *argv[])
25 int main(int argc, char *argv[])
26 {
26 {
27 QApplication a(argc, argv);
27 QApplication a(argc, argv);
28 ChartWindow window;
28 Window window;
29 window.show();
29 window.show();
30 return a.exec();
30 return a.exec();
31 }
31 }
32
32
@@ -1,438 +1,584
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartwindow.h"
21 #include "window.h"
22 #include "view.h"
22
23
23 #include <QChartView>
24 #include <QChartView>
24 #include <QPieSeries>
25 #include <QPieSeries>
25 #include <QPieSlice>
26 #include <QPieSlice>
26 #include <QPercentBarSeries>
27 #include <QPercentBarSeries>
27 #include <QStackedBarSeries>
28 #include <QStackedBarSeries>
28 #include <QBarSeries>
29 #include <QBarSeries>
29 #include <QBarSet>
30 #include <QBarSet>
30 #include <QLineSeries>
31 #include <QLineSeries>
31 #include <QSplineSeries>
32 #include <QSplineSeries>
32 #include <QScatterSeries>
33 #include <QScatterSeries>
33 #include <QAreaSeries>
34 #include <QAreaSeries>
34 #include <QLegend>
35 #include <QLegend>
35 #include <QGridLayout>
36 #include <QGridLayout>
36 #include <QFormLayout>
37 #include <QFormLayout>
37 #include <QComboBox>
38 #include <QComboBox>
38 #include <QSpinBox>
39 #include <QSpinBox>
39 #include <QCheckBox>
40 #include <QCheckBox>
40 #include <QGroupBox>
41 #include <QGroupBox>
41 #include <QLabel>
42 #include <QLabel>
42 #include <QTime>
43 #include <QTime>
43 #include <QBarCategoriesAxis>
44 #include <QBarCategoriesAxis>
44 #include <QGraphicsScene>
45 #include <QGraphicsScene>
45 #include <QGraphicsGridLayout>
46 #include <QGraphicsGridLayout>
46 #include <QGraphicsLinearLayout>
47 #include <QGraphicsLinearLayout>
47 #include <QGraphicsProxyWidget>
48 #include <QGraphicsProxyWidget>
48 #include <QGLWidget>
49 #include <QGLWidget>
49 #include <QApplication>
50 #include <QApplication>
50 #include <QDebug>
51 #include <QDebug>
51
52
52 ChartWindow::ChartWindow(QWidget* parent) :
53 Window::Window(QWidget* parent) :
53 QMainWindow(parent), m_listCount(3), m_valueMax(10), m_valueCount(7), m_scene(
54 QMainWindow(parent),
54 new QGraphicsScene(this)), m_view(0), m_dataTable(
55 m_listCount(3),
55 generateRandomData(m_listCount, m_valueMax, m_valueCount)), m_form(0), m_themeComboBox(0), m_antialiasCheckBox(
56 m_valueMax(10),
56 0), m_animatedComboBox(0), m_legendComboBox(0), m_openGLCheckBox(0)
57 m_valueCount(7),
58 m_scene(new QGraphicsScene(this)),
59 m_view(0),
60 m_dataTable(generateRandomData(m_listCount, m_valueMax, m_valueCount)),
61 m_form(0),
62 m_themeComboBox(0),
63 m_antialiasCheckBox(0),
64 m_animatedComboBox(0),
65 m_legendComboBox(0),
66 m_openGLCheckBox(0),
67 m_zoomCheckBox(0),
68 m_scrollCheckBox(0),
69 m_rubberBand(new QGraphicsRectItem()),
70 m_isScrolling(false),
71 m_isZooming(false),
72 m_scroll(false),
73 m_zoom(false)
57 {
74 {
58 createProxyWidgets();
75 createProxyWidgets();
59 connectSignals();
76 connectSignals();
60
77
61 // create layout
78 // create layout
62 QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout();
79 QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout();
63 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
80 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
64 settingsLayout->setOrientation(Qt::Vertical);
81 settingsLayout->setOrientation(Qt::Vertical);
65 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
82 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
66 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
83 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
67 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
84 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
68 settingsLayout->addItem(m_widgetHash["themeLabel"]);
85 settingsLayout->addItem(m_widgetHash["themeLabel"]);
69 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
86 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
70 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
87 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
71 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
88 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
72 settingsLayout->addItem(m_widgetHash["legendLabel"]);
89 settingsLayout->addItem(m_widgetHash["legendLabel"]);
73 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
90 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
91 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
92 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
74 settingsLayout->addStretch();
93 settingsLayout->addStretch();
75 baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
94 baseLayout->addItem(settingsLayout, 0, 3, 2, 1);
76 //create charts
95 //create charts
77
96
78 int i = m_widgetHash.count();
97 int i = m_widgetHash.count();
79 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
98 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
80 widget->setZValue(i--);
99 widget->setZValue(i--);
81 widget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
100 widget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
82 }
101 }
83
102
84 QChart* chart;
103 QChart* chart;
85
104
86 chart = createAreaChart();
105 chart = createAreaChart();
87 baseLayout->addItem(chart, 0, 0);
106 baseLayout->addItem(chart, 0, 0);
88 m_chartList << chart;
107 m_chartList << chart;
89
108
90 chart = createBarChart(m_valueCount);
109 chart = createBarChart(m_valueCount);
91 baseLayout->addItem(chart, 0, 1);
110 baseLayout->addItem(chart, 0, 1);
92 m_chartList << chart;
111 m_chartList << chart;
93
112
94 chart = createLineChart();
113 chart = createLineChart();
95 baseLayout->addItem(chart, 0, 2);
114 baseLayout->addItem(chart, 0, 2);
96 m_chartList << chart;
115 m_chartList << chart;
97
116
98 chart = createPieChart();
117 chart = createPieChart();
99 baseLayout->addItem(chart, 1, 0);
118 baseLayout->addItem(chart, 1, 0);
100 m_chartList << chart;
119 m_chartList << chart;
101
120
102 chart = createSplineChart();
121 chart = createSplineChart();
103 baseLayout->addItem(chart, 1, 1);
122 baseLayout->addItem(chart, 1, 1);
104 m_chartList << chart;
123 m_chartList << chart;
105
124
106 chart = createScatterChart();
125 chart = createScatterChart();
107 baseLayout->addItem(chart, 1, 2);
126 baseLayout->addItem(chart, 1, 2);
108 m_chartList << chart;
127 m_chartList << chart;
109
128
110 // Set defaults
111 //m_antialiasCheckBox->setChecked(true);
112
113 m_form = new QGraphicsWidget();
129 m_form = new QGraphicsWidget();
114 m_form->setLayout(baseLayout);
130 m_form->setLayout(baseLayout);
115 m_scene->addItem(m_form);
131 m_scene->addItem(m_form);
132 m_scene->addItem(m_rubberBand);
133 m_rubberBand->setVisible(false);
116
134
117 m_view = new GraphicsView(m_scene, m_form);
135 m_view = new View(m_scene, m_form);
118 m_view->setMinimumSize(m_form->preferredSize().toSize());
136 m_view->setMinimumSize(m_form->preferredSize().toSize());
119
137
138 // Set defaults
139 m_antialiasCheckBox->setChecked(true);
120 updateUI();
140 updateUI();
121 setCentralWidget(m_view);
141 setCentralWidget(m_view);
122 }
142 }
123
143
124 ChartWindow::~ChartWindow()
144 Window::~Window()
125 {
145 {
126 }
146 }
127
147
128 void ChartWindow::connectSignals()
148 void Window::connectSignals()
129 {
149 {
130 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
150 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
131 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
151 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
132 connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
152 connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
153 connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
154 connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
133 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
155 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
134 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
156 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
135 }
157 }
136
158
137 DataTable ChartWindow::generateRandomData(int listCount, int valueMax, int valueCount) const
159 DataTable Window::generateRandomData(int listCount, int valueMax, int valueCount) const
138 {
160 {
139 DataTable dataTable;
161 DataTable dataTable;
140
162
141 // set seed for random stuff
163 // set seed for random stuff
142 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
164 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
143
165
144 // generate random data
166 // generate random data
145 for (int i(0); i < listCount; i++) {
167 for (int i(0); i < listCount; i++) {
146 DataList dataList;
168 DataList dataList;
147 qreal yValue(0);
169 qreal yValue(0);
148 for (int j(0); j < valueCount; j++) {
170 for (int j(0); j < valueCount; j++) {
149 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
171 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
150 QPointF value(
172 QPointF value(
151 (j + (qreal) qrand() / (qreal) RAND_MAX)
173 (j + (qreal) qrand() / (qreal) RAND_MAX)
152 * ((qreal) m_valueMax / (qreal) valueCount), yValue);
174 * ((qreal) m_valueMax / (qreal) valueCount), yValue);
153 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
175 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
154 dataList << Data(value, label);
176 dataList << Data(value, label);
155 }
177 }
156 dataTable << dataList;
178 dataTable << dataList;
157 }
179 }
158
180
159 return dataTable;
181 return dataTable;
160 }
182 }
161
183
162 void ChartWindow::createProxyWidgets()
184 void Window::createProxyWidgets()
163 {
185 {
164 m_themeComboBox = createThemeBox();
186 m_themeComboBox = createThemeBox();
165 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
187 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
166 m_animatedComboBox = createAnimationBox();
188 m_animatedComboBox = createAnimationBox();
167 m_legendComboBox = createLegendBox();
189 m_legendComboBox = createLegendBox();
168 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
190 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
191 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
192 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
169 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
193 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
170 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
194 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
171 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
195 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
172 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
196 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
173 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
197 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
174 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
198 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
175 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
199 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
176 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
200 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
201 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
202 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
177 }
203 }
178
204
179 QComboBox* ChartWindow::createThemeBox() const
205 QComboBox* Window::createThemeBox() const
180 {
206 {
181 // settings layoutQGLWidget’
207 // settings layoutQGLWidget’
182 QComboBox* themeComboBox = new QComboBox();
208 QComboBox* themeComboBox = new QComboBox();
183 themeComboBox->addItem("Light", QChart::ChartThemeLight);
209 themeComboBox->addItem("Light", QChart::ChartThemeLight);
184 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
210 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
185 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
211 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
186 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
212 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
187 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
213 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
188 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
214 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
189 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
215 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
190 return themeComboBox;
216 return themeComboBox;
191 }
217 }
192
218
193 QComboBox* ChartWindow::createAnimationBox() const
219 QComboBox* Window::createAnimationBox() const
194 {
220 {
195 // settings layout
221 // settings layout
196 QComboBox* animationComboBox = new QComboBox();
222 QComboBox* animationComboBox = new QComboBox();
197 animationComboBox->addItem("No Animations", QChart::NoAnimation);
223 animationComboBox->addItem("No Animations", QChart::NoAnimation);
198 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
224 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
199 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
225 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
200 animationComboBox->addItem("All Animations", QChart::AllAnimations);
226 animationComboBox->addItem("All Animations", QChart::AllAnimations);
201 return animationComboBox;
227 return animationComboBox;
202 }
228 }
203
229
204 QComboBox* ChartWindow::createLegendBox() const
230 QComboBox* Window::createLegendBox() const
205 {
231 {
206 QComboBox* legendComboBox = new QComboBox();
232 QComboBox* legendComboBox = new QComboBox();
207 legendComboBox->addItem("No Legend ", 0);
233 legendComboBox->addItem("No Legend ", 0);
208 legendComboBox->addItem("Legend Top", Qt::AlignTop);
234 legendComboBox->addItem("Legend Top", Qt::AlignTop);
209 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
235 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
210 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
236 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
211 legendComboBox->addItem("Legend Right", Qt::AlignRight);
237 legendComboBox->addItem("Legend Right", Qt::AlignRight);
212 return legendComboBox;
238 return legendComboBox;
213 }
239 }
214
240
215 QChart* ChartWindow::createAreaChart() const
241 QChart* Window::createAreaChart() const
216 {
242 {
217 QChart *chart = new QChart();
243 QChart *chart = new QChart();
218 // chart->axisX()->setNiceNumbersEnabled(true);
244 // chart->axisX()->setNiceNumbersEnabled(true);
219 // chart->axisY()->setNiceNumbersEnabled(true);
245 // chart->axisY()->setNiceNumbersEnabled(true);
220 chart->setTitle("Area chart");
246 chart->setTitle("Area chart");
221
247
222 // The lower series initialized to zero values
248 // The lower series initialized to zero values
223 QLineSeries *lowerSeries = 0;
249 QLineSeries *lowerSeries = 0;
224 QString name("Series ");
250 QString name("Series ");
225 int nameIndex = 0;
251 int nameIndex = 0;
226 for (int i(0); i < m_dataTable.count(); i++) {
252 for (int i(0); i < m_dataTable.count(); i++) {
227 QLineSeries *upperSeries = new QLineSeries(chart);
253 QLineSeries *upperSeries = new QLineSeries(chart);
228 for (int j(0); j < m_dataTable[i].count(); j++) {
254 for (int j(0); j < m_dataTable[i].count(); j++) {
229 Data data = m_dataTable[i].at(j);
255 Data data = m_dataTable[i].at(j);
230 if (lowerSeries) {
256 if (lowerSeries) {
231 const QList<QPointF>& points = lowerSeries->points();
257 const QList<QPointF>& points = lowerSeries->points();
232 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
258 upperSeries->append(QPointF(j, points[i].y() + data.first.y()));
233 }
259 }
234 else
260 else
235 upperSeries->append(QPointF(j, data.first.y()));
261 upperSeries->append(QPointF(j, data.first.y()));
236 }
262 }
237 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
263 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
238 area->setName(name + QString::number(nameIndex));
264 area->setName(name + QString::number(nameIndex));
239 nameIndex++;
265 nameIndex++;
240 chart->addSeries(area);
266 chart->addSeries(area);
241 chart->createDefaultAxes();
267 chart->createDefaultAxes();
242 lowerSeries = upperSeries;
268 lowerSeries = upperSeries;
243 }
269 }
244
270
245 return chart;
271 return chart;
246 }
272 }
247
273
248 QChart* ChartWindow::createBarChart(int valueCount) const
274 QChart* Window::createBarChart(int valueCount) const
249 {
275 {
250 Q_UNUSED(valueCount);
276 Q_UNUSED(valueCount);
251 QChart* chart = new QChart();
277 QChart* chart = new QChart();
252 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
278 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
253 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
279 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
254 chart->setTitle("Bar chart");
280 chart->setTitle("Bar chart");
255
281
256 QStackedBarSeries* series = new QStackedBarSeries(chart);
282 QStackedBarSeries* series = new QStackedBarSeries(chart);
257 for (int i(0); i < m_dataTable.count(); i++) {
283 for (int i(0); i < m_dataTable.count(); i++) {
258 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
284 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
259 foreach (Data data, m_dataTable[i])
285 foreach (Data data, m_dataTable[i])
260 *set << data.first.y();
286 *set << data.first.y();
261 series->append(set);
287 series->append(set);
262 }
288 }
263 chart->addSeries(series);
289 chart->addSeries(series);
264 chart->createDefaultAxes();
290 chart->createDefaultAxes();
265
291
266 return chart;
292 return chart;
267 }
293 }
268
294
269 QChart* ChartWindow::createLineChart() const
295 QChart* Window::createLineChart() const
270 {
296 {
271 QChart* chart = new QChart();
297 QChart* chart = new QChart();
272 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
298 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
273 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
299 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
274 chart->setTitle("Line chart");
300 chart->setTitle("Line chart");
275
301
276 QString name("Series ");
302 QString name("Series ");
277 int nameIndex = 0;
303 int nameIndex = 0;
278 foreach (DataList list, m_dataTable) {
304 foreach (DataList list, m_dataTable) {
279 QLineSeries *series = new QLineSeries(chart);
305 QLineSeries *series = new QLineSeries(chart);
280 foreach (Data data, list)
306 foreach (Data data, list)
281 series->append(data.first);
307 series->append(data.first);
282 series->setName(name + QString::number(nameIndex));
308 series->setName(name + QString::number(nameIndex));
283 nameIndex++;
309 nameIndex++;
284 chart->addSeries(series);
310 chart->addSeries(series);
285 }
311 }
286 chart->createDefaultAxes();
312 chart->createDefaultAxes();
287
313
288 return chart;
314 return chart;
289 }
315 }
290
316
291 QChart* ChartWindow::createPieChart() const
317 QChart* Window::createPieChart() const
292 {
318 {
293 QChart* chart = new QChart();
319 QChart* chart = new QChart();
294 chart->setTitle("Pie chart");
320 chart->setTitle("Pie chart");
295
321
296 qreal pieSize = 1.0 / m_dataTable.count();
322 qreal pieSize = 1.0 / m_dataTable.count();
297 for (int i = 0; i < m_dataTable.count(); i++) {
323 for (int i = 0; i < m_dataTable.count(); i++) {
298 QPieSeries *series = new QPieSeries(chart);
324 QPieSeries *series = new QPieSeries(chart);
299 foreach (Data data, m_dataTable[i]) {
325 foreach (Data data, m_dataTable[i]) {
300 QPieSlice *slice = series->append(data.second, data.first.y());
326 QPieSlice *slice = series->append(data.second, data.first.y());
301 if (data == m_dataTable[i].first()) {
327 if (data == m_dataTable[i].first()) {
302 slice->setLabelVisible();
328 slice->setLabelVisible();
303 slice->setExploded();
329 slice->setExploded();
304 }
330 }
305 }
331 }
306 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
332 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
307 series->setPieSize(pieSize);
333 series->setPieSize(pieSize);
308 series->setHorizontalPosition(hPos);
334 series->setHorizontalPosition(hPos);
309 series->setVerticalPosition(0.5);
335 series->setVerticalPosition(0.5);
310 chart->addSeries(series);
336 chart->addSeries(series);
311 }
337 }
312
338
313 return chart;
339 return chart;
314 }
340 }
315
341
316 QChart* ChartWindow::createSplineChart() const
342 QChart* Window::createSplineChart() const
317 {
343 {
318 QChart* chart = new QChart();
344 QChart* chart = new QChart();
319 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
345 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
320 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
346 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
321 chart->setTitle("Spline chart");
347 chart->setTitle("Spline chart");
322 QString name("Series ");
348 QString name("Series ");
323 int nameIndex = 0;
349 int nameIndex = 0;
324 foreach (DataList list, m_dataTable) {
350 foreach (DataList list, m_dataTable) {
325 QSplineSeries *series = new QSplineSeries(chart);
351 QSplineSeries *series = new QSplineSeries(chart);
326 foreach (Data data, list)
352 foreach (Data data, list)
327 series->append(data.first);
353 series->append(data.first);
328 series->setName(name + QString::number(nameIndex));
354 series->setName(name + QString::number(nameIndex));
329 nameIndex++;
355 nameIndex++;
330 chart->addSeries(series);
356 chart->addSeries(series);
331 }
357 }
332 chart->createDefaultAxes();
358 chart->createDefaultAxes();
333 return chart;
359 return chart;
334 }
360 }
335
361
336 QChart* ChartWindow::createScatterChart() const
362 QChart* Window::createScatterChart() const
337 {
363 {
338 QChart* chart = new QChart();
364 QChart* chart = new QChart();
339 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
365 //TODO: chart->axisX()->setNiceNumbersEnabled(true);
340 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
366 //TODO: chart->axisY()->setNiceNumbersEnabled(true);
341 chart->setTitle("Scatter chart");
367 chart->setTitle("Scatter chart");
342 QString name("Series ");
368 QString name("Series ");
343 int nameIndex = 0;
369 int nameIndex = 0;
344 foreach (DataList list, m_dataTable) {
370 foreach (DataList list, m_dataTable) {
345 QScatterSeries *series = new QScatterSeries(chart);
371 QScatterSeries *series = new QScatterSeries(chart);
346 foreach (Data data, list)
372 foreach (Data data, list)
347 series->append(data.first);
373 series->append(data.first);
348 series->setName(name + QString::number(nameIndex));
374 series->setName(name + QString::number(nameIndex));
349 nameIndex++;
375 nameIndex++;
350 chart->addSeries(series);
376 chart->addSeries(series);
351 }
377 }
352 chart->createDefaultAxes();
378 chart->createDefaultAxes();
353 return chart;
379 return chart;
354 }
380 }
355
381
356 void ChartWindow::updateUI()
382 void Window::updateUI()
357 {
383 {
358 bool opengl = m_openGLCheckBox->isChecked();
384 bool opengl = m_openGLCheckBox->isChecked();
359 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
385 bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport());
360 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
386 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
361 m_view->deleteLater();
387 m_view->deleteLater();
362 m_view = new GraphicsView(m_scene, m_form);
388 m_view = new View(m_scene, m_form);
363 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
389 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
364 setCentralWidget(m_view);
390 setCentralWidget(m_view);
365 }
391 }
366
392
367 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
393 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
368 m_themeComboBox->currentIndex()).toInt();
394 m_themeComboBox->currentIndex()).toInt();
369
395
370 foreach (QChart *chart, m_chartList)
396 foreach (QChart *chart, m_chartList)
371 chart->setTheme(theme);
397 chart->setTheme(theme);
372
398
373 QPalette pal = window()->palette();
399 QPalette pal = window()->palette();
374 if (theme == QChart::ChartThemeLight) {
400 if (theme == QChart::ChartThemeLight) {
375 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
401 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
376 pal.setColor(QPalette::WindowText, QRgb(0x404044));
402 pal.setColor(QPalette::WindowText, QRgb(0x404044));
377 }
403 }
378 else if (theme == QChart::ChartThemeDark) {
404 else if (theme == QChart::ChartThemeDark) {
379 pal.setColor(QPalette::Window, QRgb(0x121218));
405 pal.setColor(QPalette::Window, QRgb(0x121218));
380 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
406 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
381 }
407 }
382 else if (theme == QChart::ChartThemeBlueCerulean) {
408 else if (theme == QChart::ChartThemeBlueCerulean) {
383 pal.setColor(QPalette::Window, QRgb(0x40434a));
409 pal.setColor(QPalette::Window, QRgb(0x40434a));
384 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
410 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
385 }
411 }
386 else if (theme == QChart::ChartThemeBrownSand) {
412 else if (theme == QChart::ChartThemeBrownSand) {
387 pal.setColor(QPalette::Window, QRgb(0x9e8965));
413 pal.setColor(QPalette::Window, QRgb(0x9e8965));
388 pal.setColor(QPalette::WindowText, QRgb(0x404044));
414 pal.setColor(QPalette::WindowText, QRgb(0x404044));
389 }
415 }
390 else if (theme == QChart::ChartThemeBlueNcs) {
416 else if (theme == QChart::ChartThemeBlueNcs) {
391 pal.setColor(QPalette::Window, QRgb(0x018bba));
417 pal.setColor(QPalette::Window, QRgb(0x018bba));
392 pal.setColor(QPalette::WindowText, QRgb(0x404044));
418 pal.setColor(QPalette::WindowText, QRgb(0x404044));
393 }
419 }
394 else if (theme == QChart::ChartThemeHighContrast) {
420 else if (theme == QChart::ChartThemeHighContrast) {
395 pal.setColor(QPalette::Window, QRgb(0xffab03));
421 pal.setColor(QPalette::Window, QRgb(0xffab03));
396 pal.setColor(QPalette::WindowText, QRgb(0x181818));
422 pal.setColor(QPalette::WindowText, QRgb(0x181818));
397 }
423 }
398 else if (theme == QChart::ChartThemeBlueIcy) {
424 else if (theme == QChart::ChartThemeBlueIcy) {
399 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
425 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
400 pal.setColor(QPalette::WindowText, QRgb(0x404044));
426 pal.setColor(QPalette::WindowText, QRgb(0x404044));
401 }
427 }
402 else {
428 else {
403 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
429 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
404 pal.setColor(QPalette::WindowText, QRgb(0x404044));
430 pal.setColor(QPalette::WindowText, QRgb(0x404044));
405 }
431 }
406 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
432 foreach(QGraphicsProxyWidget* widget , m_widgetHash) {
407 widget->setPalette(pal);
433 widget->setPalette(pal);
408 }
434 }
409 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
435 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
436 m_rubberBand->setPen(pal.color((QPalette::WindowText)));
410
437
411 QChart::AnimationOptions options(
438 QChart::AnimationOptions options(
412 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
439 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
413 if (m_chartList.at(0)->animationOptions() != options) {
440 if (m_chartList.at(0)->animationOptions() != options) {
414 foreach (QChart *chart, m_chartList)
441 foreach (QChart *chart, m_chartList)
415 chart->setAnimationOptions(options);
442 chart->setAnimationOptions(options);
416 }
443 }
417
444
418 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
445 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
419
446
420 if (!alignment) {
447 if (!alignment) {
421 foreach (QChart *chart, m_chartList) {
448 foreach (QChart *chart, m_chartList) {
422 chart->legend()->hide();
449 chart->legend()->hide();
423 }
450 }
424 }
451 }
425 else {
452 else {
426 foreach (QChart *chart, m_chartList) {
453 foreach (QChart *chart, m_chartList) {
427 chart->legend()->setAlignment(alignment);
454 chart->legend()->setAlignment(alignment);
428 chart->legend()->show();
455 chart->legend()->show();
429 }
456 }
430 }
457 }
431
458
432 bool checked = m_antialiasCheckBox->isChecked();
459 bool antialias = m_antialiasCheckBox->isChecked();
460
433 if (opengl)
461 if (opengl)
434 m_view->setRenderHint(QPainter::HighQualityAntialiasing, checked);
462 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
435 else
463 else
436 m_view->setRenderHint(QPainter::Antialiasing, checked);
464 m_view->setRenderHint(QPainter::Antialiasing, antialias);
465
466 bool scroll = m_scrollCheckBox->isChecked();
467
468 if(!m_scroll & scroll){
469 m_scroll=true;
470 m_zoom=false;
471 m_zoomCheckBox->setChecked(false);
472 }
473
474 bool zoom = m_zoomCheckBox->isChecked();
475
476 if(!m_zoom & zoom){
477 m_scroll=false;
478 m_zoom=true;
479 m_scrollCheckBox->setChecked(false);
480 }
481
482 }
483
484 void Window::mousePressEvent(QMouseEvent *event)
485 {
486 if (event->button() == Qt::LeftButton) {
487
488 m_origin = event->pos();
489 m_isScrolling = false;
490 m_isZooming = false;
491
492 foreach (QChart *chart, m_chartList) {
493
494 QRectF geometryRect = chart->geometry();
495 QRectF plotArea = chart->plotArea();
496 plotArea.translate(geometryRect.topLeft());
497 if (plotArea.contains(m_origin)) {
498 m_isScrolling = m_scroll;
499 m_isZooming = m_zoom;
500 break;
501 }
502 }
503
504 if (m_isZooming) {
505 m_rubberBand->setRect(QRectF(m_origin, QSize()));
506 m_rubberBand->setVisible(true);
507 }
508 event->accept();
509 }
510
511 if (event->button() == Qt::RightButton) {
512 m_origin = event->pos();
513 m_isZooming = m_zoom;
514 }
515 }
516
517 void Window::mouseMoveEvent(QMouseEvent *event)
518 {
519 if (m_isScrolling || m_isZooming) {
520
521 foreach (QChart *chart, m_chartList) {
522
523 QRectF geometryRect = chart->geometry();
524 QRectF plotArea = chart->plotArea();
525 plotArea.translate(geometryRect.topLeft());
526
527 if (plotArea.contains(m_origin)) {
528 if (m_isScrolling) {
529 QPointF delta = m_origin - event->pos();
530 chart->scroll(delta.x(), -delta.y());
531 }
532 if (m_isZooming && plotArea.contains(event->pos())) {
533 m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized());
534 }
535 break;
536 }
537 }
538 if(m_isScrolling) m_origin = event->pos();
539 event->accept();
540 }
437 }
541 }
438
542
543 void Window::mouseReleaseEvent(QMouseEvent *event)
544 {
545 if (event->button() == Qt::LeftButton) {
546 m_isScrolling = false;
547 if (m_isZooming) {
548 m_isZooming = false;
549 m_rubberBand->setVisible(false);
550
551 foreach (QChart *chart, m_chartList) {
552
553 QRectF geometryRect = chart->geometry();
554 QRectF plotArea = chart->plotArea();
555 plotArea.translate(geometryRect.topLeft());
556
557 if (plotArea.contains(m_origin)) {
558 QRectF rect = m_rubberBand->rect();
559 chart->zoomIn(rect);
560 break;
561 }
562 }
563 }
564 event->accept();
565 }
566
567 if (event->button() == Qt::RightButton) {
568
569 if (m_isZooming) {
570 foreach (QChart *chart, m_chartList) {
571
572 QRectF geometryRect = chart->geometry();
573 QRectF plotArea = chart->plotArea();
574 plotArea.translate(geometryRect.topLeft());
575
576 if (plotArea.contains(m_origin)) {
577 QRectF rect = m_rubberBand->rect();
578 chart->zoomOut();
579 break;
580 }
581 }
582 }
583 }
584 }
@@ -1,110 +1,102
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef CHARTWINDOW_H_
21 #ifndef WINDOW_H_
22 #define CHARTWINDOW_H_
22 #define WINDOW_H_
23 #include <QMainWindow>
23 #include <QMainWindow>
24 #include <QChartGlobal>
24 #include <QChartGlobal>
25 #include <QHash>
25 #include <QHash>
26 #include <QGraphicsView>
27 #include <QResizeEvent>
28 #include <QGraphicsWidget>
29
26
30 class QComboBox;
27 class QComboBox;
31 class QCheckBox;
28 class QCheckBox;
29 class QGraphicsRectItem;
30 class QGraphicsScene;
31 class QGraphicsWidget;
32 class View;
32
33
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 class QChart;
35 class QChart;
35 QTCOMMERCIALCHART_END_NAMESPACE
36 QTCOMMERCIALCHART_END_NAMESPACE
36
37
37 typedef QPair<QPointF, QString> Data;
38 typedef QPair<QPointF, QString> Data;
38 typedef QList<Data> DataList;
39 typedef QList<Data> DataList;
39 typedef QList<DataList> DataTable;
40 typedef QList<DataList> DataTable;
40
41
41 class QGraphicsScene;
42
43 QTCOMMERCIALCHART_USE_NAMESPACE
42 QTCOMMERCIALCHART_USE_NAMESPACE
44
43
45
44 class Window: public QMainWindow
46 class GraphicsView: public QGraphicsView
47 {
48 public:
49 GraphicsView(QGraphicsScene *scene, QGraphicsWidget *form , QWidget *parent = 0):QGraphicsView(scene,parent), m_form(form)
50 {
51 setWindowTitle(tr("Charts"));
52 }
53
54 protected:
55 void resizeEvent(QResizeEvent *event)
56 {
57 if (scene())
58 scene()->setSceneRect(QRect(QPoint(0, 0), event->size()));
59 if (m_form)
60 m_form->resize(QSizeF(event->size()));
61 QGraphicsView::resizeEvent(event);
62 }
63 private:
64 QGraphicsWidget *m_form;
65 };
66
67
68 class ChartWindow: public QMainWindow
69 {
45 {
70 Q_OBJECT
46 Q_OBJECT
71 public:
47 public:
72 explicit ChartWindow(QWidget *parent = 0);
48 explicit Window(QWidget *parent = 0);
73 ~ChartWindow();
49 ~Window();
74
50
75 private Q_SLOTS:
51 private Q_SLOTS:
76 void updateUI();
52 void updateUI();
77
53
54
78 private:
55 private:
79 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
56 DataTable generateRandomData(int listCount,int valueMax,int valueCount) const;
80 QComboBox* createThemeBox() const;
57 QComboBox* createThemeBox() const;
81 QComboBox* createAnimationBox() const;
58 QComboBox* createAnimationBox() const;
82 QComboBox* createLegendBox() const;
59 QComboBox* createLegendBox() const;
83 void connectSignals();
60 void connectSignals();
84 QChart* createAreaChart() const;
61 QChart* createAreaChart() const;
85 QChart* createBarChart(int valueCount) const;
62 QChart* createBarChart(int valueCount) const;
86 QChart* createPieChart() const;
63 QChart* createPieChart() const;
87 QChart* createLineChart() const;
64 QChart* createLineChart() const;
88 QChart* createSplineChart() const;
65 QChart* createSplineChart() const;
89 QChart* createScatterChart() const;
66 QChart* createScatterChart() const;
90 void createProxyWidgets();
67 void createProxyWidgets();
91
68
69 protected:
70 void mousePressEvent(QMouseEvent *event);
71 void mouseMoveEvent(QMouseEvent *event);
72 void mouseReleaseEvent(QMouseEvent *event);
73
74
92 private:
75 private:
93 int m_listCount;
76 int m_listCount;
94 int m_valueMax;
77 int m_valueMax;
95 int m_valueCount;
78 int m_valueCount;
96 QGraphicsScene* m_scene;
79 QGraphicsScene* m_scene;
97 GraphicsView* m_view;
80 View* m_view;
98 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
81 QHash<QString, QGraphicsProxyWidget*> m_widgetHash;
99 QList<QChart*> m_chartList;
82 QList<QChart*> m_chartList;
100 DataTable m_dataTable;
83 DataTable m_dataTable;
101
84
102 QGraphicsWidget *m_form;
85 QGraphicsWidget *m_form;
103 QComboBox *m_themeComboBox;
86 QComboBox *m_themeComboBox;
104 QCheckBox *m_antialiasCheckBox;
87 QCheckBox *m_antialiasCheckBox;
105 QComboBox *m_animatedComboBox;
88 QComboBox *m_animatedComboBox;
106 QComboBox *m_legendComboBox;
89 QComboBox *m_legendComboBox;
107 QCheckBox *m_openGLCheckBox;
90 QCheckBox *m_openGLCheckBox;
91 QCheckBox *m_zoomCheckBox;
92 QCheckBox *m_scrollCheckBox;
93 QPoint m_origin;
94 QGraphicsRectItem* m_rubberBand;
95
96 bool m_isScrolling;
97 bool m_isZooming;
98 bool m_scroll;
99 bool m_zoom;
108 };
100 };
109
101
110 #endif
102 #endif
General Comments 0
You need to be logged in to leave comments. Login now