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