##// END OF EJS Templates
Adds help for chartviewer
Michal Klocek -
r2134:c38d87e11d85
parent child
Show More
@@ -1,65 +1,85
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 #include <iostream>
24
25
25 QVariantHash parseArgs(QStringList args)
26 QVariantHash parseArgs(QStringList args)
26 {
27 {
27 QVariantHash parameters;
28 QVariantHash parameters;
28
29
29 while (!args.isEmpty()) {
30 while (!args.isEmpty()) {
30
31
31 QString param = args.takeFirst();
32 QString param = args.takeFirst();
32 if (param.startsWith("--")) {
33 if (param.startsWith("--")) {
33 param.remove(0, 2);
34 param.remove(0, 2);
34
35
35 if (args.isEmpty() || args.first().startsWith("--")) {
36 if (args.isEmpty() || args.first().startsWith("--")) {
36 parameters[param] = true;
37 parameters[param] = true;
37 } else {
38 } else {
38 QString value = args.takeFirst();
39 QString value = args.takeFirst();
39 if (value == "true" || value == "on" || value == "enabled") {
40 if (value == "true" || value == "on" || value == "enabled") {
40 parameters[param] = true;
41 parameters[param] = true;
41 } else if (value == "false" || value == "off" || value == "disable") {
42 } else if (value == "false" || value == "off" || value == "disable") {
42 parameters[param] = false;
43 parameters[param] = false;
43 } else {
44 } else {
44 if (value.endsWith('"'))
45 if (value.endsWith('"'))
45 value.chop(1);
46 value.chop(1);
46 if (value.startsWith('"'))
47 if (value.startsWith('"'))
47 value.remove(0, 1);
48 value.remove(0, 1);
48 parameters[param] = value;
49 parameters[param] = value;
49 }
50 }
50 }
51 }
51 }
52 }
52 }
53 }
53
54
54 return parameters;
55 return parameters;
55 }
56 }
56
57
58 void printHelp()
59 {
60 std::cout << "chartviewer <options> "<< std::endl;
61 std::cout << " --view <1/2/3/4> - set size of charts' grid" << std::endl;
62 std::cout << " --chart <categoryName::subCategory::chartName> - set template to be show " << std::endl;
63 std::cout << " --opengl <enabled/disbaled> - set opengl mode" << std::endl;
64 std::cout << " --theme <name> - set theme" << std::endl;
65 std::cout << " --legend <alignment> - set legend alignment" << std::endl;
66 std::cout << " --help - prints this help" << std::endl;
67 std::cout << "Examples: " << std::endl;
68 std::cout << " chartviewer --view 4 --chart Axis" << std::endl;
69 std::cout << " chartviewer --view 1 --chart Axis::BarCategoryAxis::Axis " << std::endl;
70 }
71
57 int main(int argc, char *argv[])
72 int main(int argc, char *argv[])
58 {
73 {
59 QApplication a(argc, argv);
74 QApplication a(argc, argv);
60 QVariantHash parameters = parseArgs(QApplication::arguments());
75 QVariantHash parameters = parseArgs(QApplication::arguments());
76 if(parameters.contains("help"))
77 {
78 printHelp();
79 return 0;
80 }
61 Window window(parameters);
81 Window window(parameters);
62 window.show();
82 window.show();
63 return a.exec();
83 return a.exec();
64 }
84 }
65
85
@@ -1,484 +1,484
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 "grid.h"
23 #include "grid.h"
24 #include "charts.h"
24 #include "charts.h"
25 #include <QChartView>
25 #include <QChartView>
26 #include <QAreaSeries>
26 #include <QAreaSeries>
27 #include <QLegend>
27 #include <QLegend>
28 #include <QGridLayout>
28 #include <QGridLayout>
29 #include <QFormLayout>
29 #include <QFormLayout>
30 #include <QComboBox>
30 #include <QComboBox>
31 #include <QSpinBox>
31 #include <QSpinBox>
32 #include <QCheckBox>
32 #include <QCheckBox>
33 #include <QGroupBox>
33 #include <QGroupBox>
34 #include <QLabel>
34 #include <QLabel>
35 #include <QGraphicsScene>
35 #include <QGraphicsScene>
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 #include <QPushButton>
42 #include <QPushButton>
43
43
44 Window::Window(const QVariantHash &parameters, QWidget *parent)
44 Window::Window(const QVariantHash &parameters, QWidget *parent)
45 : QMainWindow(parent),
45 : QMainWindow(parent),
46 m_scene(new QGraphicsScene(this)),
46 m_scene(new QGraphicsScene(this)),
47 m_view(0),
47 m_view(0),
48 m_form(0),
48 m_form(0),
49 m_themeComboBox(0),
49 m_themeComboBox(0),
50 m_antialiasCheckBox(0),
50 m_antialiasCheckBox(0),
51 m_animatedComboBox(0),
51 m_animatedComboBox(0),
52 m_legendComboBox(0),
52 m_legendComboBox(0),
53 m_templateComboBox(0),
53 m_templateComboBox(0),
54 m_viewComboBox(0),
54 m_viewComboBox(0),
55 m_openGLCheckBox(0),
55 m_openGLCheckBox(0),
56 m_zoomCheckBox(0),
56 m_zoomCheckBox(0),
57 m_scrollCheckBox(0),
57 m_scrollCheckBox(0),
58 m_baseLayout(new QGraphicsLinearLayout()),
58 m_baseLayout(new QGraphicsLinearLayout()),
59 m_menu(createMenu()),
59 m_menu(createMenu()),
60 m_template(0),
60 m_template(0),
61 m_grid(new Grid(1))
61 m_grid(new Grid(1))
62 {
62 {
63 createProxyWidgets();
63 createProxyWidgets();
64 // create layout
64 // create layout
65 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
65 QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout();
66
66
67 settingsLayout->setOrientation(Qt::Vertical);
67 settingsLayout->setOrientation(Qt::Vertical);
68 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
68 settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
69 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
69 settingsLayout->addItem(m_widgetHash["openGLCheckBox"]);
70 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
70 settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]);
71 settingsLayout->addItem(m_widgetHash["viewLabel"]);
71 settingsLayout->addItem(m_widgetHash["viewLabel"]);
72 settingsLayout->addItem(m_widgetHash["viewComboBox"]);
72 settingsLayout->addItem(m_widgetHash["viewComboBox"]);
73 settingsLayout->addItem(m_widgetHash["themeLabel"]);
73 settingsLayout->addItem(m_widgetHash["themeLabel"]);
74 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
74 settingsLayout->addItem(m_widgetHash["themeComboBox"]);
75 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
75 settingsLayout->addItem(m_widgetHash["animationsLabel"]);
76 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
76 settingsLayout->addItem(m_widgetHash["animatedComboBox"]);
77 settingsLayout->addItem(m_widgetHash["legendLabel"]);
77 settingsLayout->addItem(m_widgetHash["legendLabel"]);
78 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
78 settingsLayout->addItem(m_widgetHash["legendComboBox"]);
79 settingsLayout->addItem(m_widgetHash["templateLabel"]);
79 settingsLayout->addItem(m_widgetHash["templateLabel"]);
80 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
80 settingsLayout->addItem(m_widgetHash["templateComboBox"]);
81 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
81 settingsLayout->addItem(m_widgetHash["scrollCheckBox"]);
82 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
82 settingsLayout->addItem(m_widgetHash["zoomCheckBox"]);
83 settingsLayout->addStretch();
83 settingsLayout->addStretch();
84
84
85 m_grid->createCharts();
85 m_grid->createCharts();
86
86
87 m_baseLayout->setOrientation(Qt::Horizontal);
87 m_baseLayout->setOrientation(Qt::Horizontal);
88 m_baseLayout->addItem(m_grid);
88 m_baseLayout->addItem(m_grid);
89 m_baseLayout->addItem(settingsLayout);
89 m_baseLayout->addItem(settingsLayout);
90
90
91 m_form = new QGraphicsWidget();
91 m_form = new QGraphicsWidget();
92 m_form->setLayout(m_baseLayout);
92 m_form->setLayout(m_baseLayout);
93 m_scene->addItem(m_form);
93 m_scene->addItem(m_form);
94
94
95 m_view = new View(m_scene, m_form);
95 m_view = new View(m_scene, m_form);
96 m_view->setMinimumSize(m_form->minimumSize().toSize());
96 m_view->setMinimumSize(m_form->minimumSize().toSize());
97
97
98 // Set defaults
98 // Set defaults
99 m_antialiasCheckBox->setChecked(true);
99 m_antialiasCheckBox->setChecked(true);
100 initializeFromParamaters(parameters);
100 initializeFromParamaters(parameters);
101 updateUI();
101 updateUI();
102 handleGeometryChanged();
102 handleGeometryChanged();
103 setCentralWidget(m_view);
103 setCentralWidget(m_view);
104
104
105 connectSignals();
105 connectSignals();
106 }
106 }
107
107
108 Window::~Window()
108 Window::~Window()
109 {
109 {
110 }
110 }
111
111
112 void Window::connectSignals()
112 void Window::connectSignals()
113 {
113 {
114 QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged()));
114 QObject::connect(m_form, SIGNAL(geometryChanged()), this , SLOT(handleGeometryChanged()));
115 QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 QObject::connect(m_viewComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
116 QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
117 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
117 QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
118 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
118 QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
119 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
119 QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
120 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
120 QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
121 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
121 QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
122 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
122 QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
123 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
123 QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
124 QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*)));
124 QObject::connect(m_grid, SIGNAL(chartSelected(QChart*)), this, SLOT(handleChartSelected(QChart*)));
125 }
125 }
126
126
127 void Window::createProxyWidgets()
127 void Window::createProxyWidgets()
128 {
128 {
129 m_themeComboBox = createThemeBox();
129 m_themeComboBox = createThemeBox();
130 m_viewComboBox = createViewBox();
130 m_viewComboBox = createViewBox();
131 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
131 m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing"));
132 m_animatedComboBox = createAnimationBox();
132 m_animatedComboBox = createAnimationBox();
133 m_legendComboBox = createLegendBox();
133 m_legendComboBox = createLegendBox();
134 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
134 m_openGLCheckBox = new QCheckBox(tr("OpenGL"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
135 m_zoomCheckBox = new QCheckBox(tr("Zoom"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
136 m_scrollCheckBox = new QCheckBox(tr("Scroll"));
137 m_templateComboBox = createTempleteBox();
137 m_templateComboBox = createTempleteBox();
138 m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View"));
138 m_widgetHash["viewLabel"] = m_scene->addWidget(new QLabel("View"));
139 m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox);
139 m_widgetHash["viewComboBox"] = m_scene->addWidget(m_viewComboBox);
140 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
140 m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox);
141 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
141 m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox);
142 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
142 m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox);
143 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
143 m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox);
144 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
144 m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox);
145 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
145 m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme"));
146 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
146 m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations"));
147 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
147 m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend"));
148 m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template"));
148 m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template"));
149 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
149 m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox);
150 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
150 m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox);
151 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
151 m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox);
152 }
152 }
153
153
154 QComboBox *Window::createThemeBox()
154 QComboBox *Window::createThemeBox()
155 {
155 {
156 QComboBox *themeComboBox = new ComboBox(this);
156 QComboBox *themeComboBox = new ComboBox(this);
157 themeComboBox->addItem("Light", QChart::ChartThemeLight);
157 themeComboBox->addItem("Light", QChart::ChartThemeLight);
158 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
158 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
159 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
159 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
160 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
160 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
161 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
161 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
162 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
162 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
163 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
163 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
164 return themeComboBox;
164 return themeComboBox;
165 }
165 }
166
166
167 QComboBox *Window::createViewBox()
167 QComboBox *Window::createViewBox()
168 {
168 {
169 QComboBox *viewComboBox = new ComboBox(this);
169 QComboBox *viewComboBox = new ComboBox(this);
170 viewComboBox->addItem("1 chart", 1);
170 viewComboBox->addItem("1 chart", 1);
171 viewComboBox->addItem("4 charts", 2);
171 viewComboBox->addItem("4 charts", 2);
172 viewComboBox->addItem("9 charts", 3);
172 viewComboBox->addItem("9 charts", 3);
173 viewComboBox->addItem("16 charts", 4);
173 viewComboBox->addItem("16 charts", 4);
174 return viewComboBox;
174 return viewComboBox;
175 }
175 }
176
176
177 QComboBox *Window::createAnimationBox()
177 QComboBox *Window::createAnimationBox()
178 {
178 {
179 QComboBox *animationComboBox = new ComboBox(this);
179 QComboBox *animationComboBox = new ComboBox(this);
180 animationComboBox->addItem("No Animations", QChart::NoAnimation);
180 animationComboBox->addItem("No Animations", QChart::NoAnimation);
181 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
181 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
182 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
182 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
183 animationComboBox->addItem("All Animations", QChart::AllAnimations);
183 animationComboBox->addItem("All Animations", QChart::AllAnimations);
184 return animationComboBox;
184 return animationComboBox;
185 }
185 }
186
186
187 QComboBox *Window::createLegendBox()
187 QComboBox *Window::createLegendBox()
188 {
188 {
189 QComboBox *legendComboBox = new ComboBox(this);
189 QComboBox *legendComboBox = new ComboBox(this);
190 legendComboBox->addItem("No Legend ", 0);
190 legendComboBox->addItem("No Legend ", 0);
191 legendComboBox->addItem("Legend Top", Qt::AlignTop);
191 legendComboBox->addItem("Legend Top", Qt::AlignTop);
192 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
192 legendComboBox->addItem("Legend Bottom", Qt::AlignBottom);
193 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
193 legendComboBox->addItem("Legend Left", Qt::AlignLeft);
194 legendComboBox->addItem("Legend Right", Qt::AlignRight);
194 legendComboBox->addItem("Legend Right", Qt::AlignRight);
195 return legendComboBox;
195 return legendComboBox;
196 }
196 }
197
197
198 QComboBox *Window::createTempleteBox()
198 QComboBox *Window::createTempleteBox()
199 {
199 {
200 QComboBox *templateComboBox = new ComboBox(this);
200 QComboBox *templateComboBox = new ComboBox(this);
201 templateComboBox->addItem("No Template", 0);
201 templateComboBox->addItem("No Template", 0);
202
202
203 Charts::ChartList list = Charts::chartList();
203 Charts::ChartList list = Charts::chartList();
204 QMultiMap<QString, Chart *> categoryMap;
204 QMultiMap<QString, Chart *> categoryMap;
205
205
206 foreach (Chart *chart, list)
206 foreach (Chart *chart, list)
207 categoryMap.insertMulti(chart->category(), chart);
207 categoryMap.insertMulti(chart->category(), chart);
208
208
209 foreach (const QString &category, categoryMap.uniqueKeys())
209 foreach (const QString &category, categoryMap.uniqueKeys())
210 templateComboBox->addItem(category, category);
210 templateComboBox->addItem(category, category);
211
211
212 return templateComboBox;
212 return templateComboBox;
213 }
213 }
214
214
215 void Window::initializeFromParamaters(const QVariantHash &parameters)
215 void Window::initializeFromParamaters(const QVariantHash &parameters)
216 {
216 {
217 if (parameters.contains("template")) {
217 if (parameters.contains("chart")) {
218 QString t = parameters["template"].toString();
218 QString t = parameters["chart"].toString();
219 for (int i = 0; i < m_templateComboBox->count(); ++i) {
219 for (int i = 0; i < m_templateComboBox->count(); ++i) {
220 if (m_templateComboBox->itemText(i) == t) {
220 if (m_templateComboBox->itemText(i) == t) {
221 m_templateComboBox->setCurrentIndex(i);
221 m_templateComboBox->setCurrentIndex(i);
222 break;
222 break;
223 }
223 }
224 }
224 }
225 }
225 }
226 if (parameters.contains("opengl")) {
226 if (parameters.contains("opengl")) {
227 bool checked = parameters["opengl"].toBool();
227 bool checked = parameters["opengl"].toBool();
228 m_openGLCheckBox->setChecked(checked);
228 m_openGLCheckBox->setChecked(checked);
229 }
229 }
230 if (parameters.contains("theme")) {
230 if (parameters.contains("theme")) {
231 QString t = parameters["theme"].toString();
231 QString t = parameters["theme"].toString();
232 for (int i = 0; i < m_themeComboBox->count(); ++i) {
232 for (int i = 0; i < m_themeComboBox->count(); ++i) {
233 if (m_themeComboBox->itemText(i) == t) {
233 if (m_themeComboBox->itemText(i) == t) {
234 m_themeComboBox->setCurrentIndex(i);
234 m_themeComboBox->setCurrentIndex(i);
235 break;
235 break;
236 }
236 }
237 }
237 }
238 }
238 }
239 if (parameters.contains("animation")) {
239 if (parameters.contains("animation")) {
240 QString t = parameters["animation"].toString();
240 QString t = parameters["animation"].toString();
241 for (int i = 0; i < m_animatedComboBox->count(); ++i) {
241 for (int i = 0; i < m_animatedComboBox->count(); ++i) {
242 if (m_animatedComboBox->itemText(i) == t) {
242 if (m_animatedComboBox->itemText(i) == t) {
243 m_animatedComboBox->setCurrentIndex(i);
243 m_animatedComboBox->setCurrentIndex(i);
244 break;
244 break;
245 }
245 }
246 }
246 }
247 }
247 }
248 if (parameters.contains("legend")) {
248 if (parameters.contains("legend")) {
249 QString t = parameters["legend"].toString();
249 QString t = parameters["legend"].toString();
250 for (int i = 0; i < m_legendComboBox->count(); ++i) {
250 for (int i = 0; i < m_legendComboBox->count(); ++i) {
251 if (m_legendComboBox->itemText(i) == t) {
251 if (m_legendComboBox->itemText(i) == t) {
252 m_legendComboBox->setCurrentIndex(i);
252 m_legendComboBox->setCurrentIndex(i);
253 break;
253 break;
254 }
254 }
255 }
255 }
256 }
256 }
257 if (parameters.contains("view")) {
257 if (parameters.contains("view")) {
258 int t = parameters["view"].toInt();
258 int t = parameters["view"].toInt();
259 for (int i = 0; i < m_viewComboBox->count(); ++i) {
259 for (int i = 0; i < m_viewComboBox->count(); ++i) {
260 if (m_viewComboBox->itemData(i).toInt() == t) {
260 if (m_viewComboBox->itemData(i).toInt() == t) {
261 m_viewComboBox->setCurrentIndex(i);
261 m_viewComboBox->setCurrentIndex(i);
262 break;
262 break;
263 }
263 }
264 }
264 }
265 }
265 }
266 }
266 }
267
267
268 void Window::updateUI()
268 void Window::updateUI()
269 {
269 {
270 checkTemplate();
270 checkTemplate();
271 checkView();
271 checkView();
272 checkOpenGL();
272 checkOpenGL();
273 checkTheme();
273 checkTheme();
274 checkAnimationOptions();
274 checkAnimationOptions();
275 checkLegend();
275 checkLegend();
276 checkState();
276 checkState();
277 }
277 }
278
278
279 void Window::checkView()
279 void Window::checkView()
280 {
280 {
281 int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt());
281 int count(m_viewComboBox->itemData(m_viewComboBox->currentIndex()).toInt());
282 m_grid->setSize(count);
282 m_grid->setSize(count);
283 }
283 }
284
284
285 void Window::checkLegend()
285 void Window::checkLegend()
286 {
286 {
287 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
287 Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
288
288
289 if (!alignment) {
289 if (!alignment) {
290 foreach (QChart *chart, m_grid->charts())
290 foreach (QChart *chart, m_grid->charts())
291 chart->legend()->hide();
291 chart->legend()->hide();
292 } else {
292 } else {
293 foreach (QChart *chart, m_grid->charts()) {
293 foreach (QChart *chart, m_grid->charts()) {
294 chart->legend()->setAlignment(alignment);
294 chart->legend()->setAlignment(alignment);
295 chart->legend()->show();
295 chart->legend()->show();
296 }
296 }
297 }
297 }
298 }
298 }
299
299
300 void Window::checkOpenGL()
300 void Window::checkOpenGL()
301 {
301 {
302 bool opengl = m_openGLCheckBox->isChecked();
302 bool opengl = m_openGLCheckBox->isChecked();
303 bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport());
303 bool isOpengl = qobject_cast<QGLWidget *>(m_view->viewport());
304 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
304 if ((isOpengl && !opengl) || (!isOpengl && opengl)) {
305 m_view->deleteLater();
305 m_view->deleteLater();
306 m_view = new View(m_scene, m_form);
306 m_view = new View(m_scene, m_form);
307 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
307 m_view->setViewport(!opengl ? new QWidget() : new QGLWidget());
308 setCentralWidget(m_view);
308 setCentralWidget(m_view);
309 }
309 }
310
310
311 bool antialias = m_antialiasCheckBox->isChecked();
311 bool antialias = m_antialiasCheckBox->isChecked();
312
312
313 if (opengl)
313 if (opengl)
314 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
314 m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias);
315 else
315 else
316 m_view->setRenderHint(QPainter::Antialiasing, antialias);
316 m_view->setRenderHint(QPainter::Antialiasing, antialias);
317 }
317 }
318
318
319 void Window::checkAnimationOptions()
319 void Window::checkAnimationOptions()
320 {
320 {
321 QChart::AnimationOptions options(
321 QChart::AnimationOptions options(
322 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
322 m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
323
323
324 QList<QChart *> charts = m_grid->charts();
324 QList<QChart *> charts = m_grid->charts();
325
325
326 if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) {
326 if (!charts.isEmpty() && charts.at(0)->animationOptions() != options) {
327 foreach (QChart *chart, charts)
327 foreach (QChart *chart, charts)
328 chart->setAnimationOptions(options);
328 chart->setAnimationOptions(options);
329 }
329 }
330 }
330 }
331
331
332 void Window::checkState()
332 void Window::checkState()
333 {
333 {
334 bool scroll = m_scrollCheckBox->isChecked();
334 bool scroll = m_scrollCheckBox->isChecked();
335
335
336
336
337 if (m_grid->state() != Grid::ScrollState && scroll) {
337 if (m_grid->state() != Grid::ScrollState && scroll) {
338 m_grid->setState(Grid::ScrollState);
338 m_grid->setState(Grid::ScrollState);
339 m_zoomCheckBox->setChecked(false);
339 m_zoomCheckBox->setChecked(false);
340 } else if (!scroll && m_grid->state() == Grid::ScrollState) {
340 } else if (!scroll && m_grid->state() == Grid::ScrollState) {
341 m_grid->setState(Grid::NoState);
341 m_grid->setState(Grid::NoState);
342 }
342 }
343
343
344 bool zoom = m_zoomCheckBox->isChecked();
344 bool zoom = m_zoomCheckBox->isChecked();
345
345
346 if (m_grid->state() != Grid::ZoomState && zoom) {
346 if (m_grid->state() != Grid::ZoomState && zoom) {
347 m_grid->setState(Grid::ZoomState);
347 m_grid->setState(Grid::ZoomState);
348 m_scrollCheckBox->setChecked(false);
348 m_scrollCheckBox->setChecked(false);
349 } else if (!zoom && m_grid->state() == Grid::ZoomState) {
349 } else if (!zoom && m_grid->state() == Grid::ZoomState) {
350 m_grid->setState(Grid::NoState);
350 m_grid->setState(Grid::NoState);
351 }
351 }
352 }
352 }
353
353
354 void Window::checkTemplate()
354 void Window::checkTemplate()
355 {
355 {
356 int index = m_templateComboBox->currentIndex();
356 int index = m_templateComboBox->currentIndex();
357 if (m_template == index || index == 0)
357 if (m_template == index || index == 0)
358 return;
358 return;
359
359
360 m_template = index;
360 m_template = index;
361 QString category = m_templateComboBox->itemData(index).toString();
361 QString category = m_templateComboBox->itemData(index).toString();
362 m_grid->createCharts(category);
362 m_grid->createCharts(category);
363 }
363 }
364
364
365 void Window::checkTheme()
365 void Window::checkTheme()
366 {
366 {
367 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
367 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(
368 m_themeComboBox->currentIndex()).toInt();
368 m_themeComboBox->currentIndex()).toInt();
369
369
370 foreach (QChart *chart, m_grid->charts())
370 foreach (QChart *chart, m_grid->charts())
371 chart->setTheme(theme);
371 chart->setTheme(theme);
372
372
373 QPalette pal = window()->palette();
373 QPalette pal = window()->palette();
374 if (theme == QChart::ChartThemeLight) {
374 if (theme == QChart::ChartThemeLight) {
375 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
375 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
376 pal.setColor(QPalette::WindowText, QRgb(0x404044));
376 pal.setColor(QPalette::WindowText, QRgb(0x404044));
377 } else if (theme == QChart::ChartThemeDark) {
377 } else if (theme == QChart::ChartThemeDark) {
378 pal.setColor(QPalette::Window, QRgb(0x121218));
378 pal.setColor(QPalette::Window, QRgb(0x121218));
379 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
379 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
380 } else if (theme == QChart::ChartThemeBlueCerulean) {
380 } else if (theme == QChart::ChartThemeBlueCerulean) {
381 pal.setColor(QPalette::Window, QRgb(0x40434a));
381 pal.setColor(QPalette::Window, QRgb(0x40434a));
382 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
382 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
383 } else if (theme == QChart::ChartThemeBrownSand) {
383 } else if (theme == QChart::ChartThemeBrownSand) {
384 pal.setColor(QPalette::Window, QRgb(0x9e8965));
384 pal.setColor(QPalette::Window, QRgb(0x9e8965));
385 pal.setColor(QPalette::WindowText, QRgb(0x404044));
385 pal.setColor(QPalette::WindowText, QRgb(0x404044));
386 } else if (theme == QChart::ChartThemeBlueNcs) {
386 } else if (theme == QChart::ChartThemeBlueNcs) {
387 pal.setColor(QPalette::Window, QRgb(0x018bba));
387 pal.setColor(QPalette::Window, QRgb(0x018bba));
388 pal.setColor(QPalette::WindowText, QRgb(0x404044));
388 pal.setColor(QPalette::WindowText, QRgb(0x404044));
389 } else if (theme == QChart::ChartThemeHighContrast) {
389 } else if (theme == QChart::ChartThemeHighContrast) {
390 pal.setColor(QPalette::Window, QRgb(0xffab03));
390 pal.setColor(QPalette::Window, QRgb(0xffab03));
391 pal.setColor(QPalette::WindowText, QRgb(0x181818));
391 pal.setColor(QPalette::WindowText, QRgb(0x181818));
392 } else if (theme == QChart::ChartThemeBlueIcy) {
392 } else if (theme == QChart::ChartThemeBlueIcy) {
393 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
393 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
394 pal.setColor(QPalette::WindowText, QRgb(0x404044));
394 pal.setColor(QPalette::WindowText, QRgb(0x404044));
395 } else {
395 } else {
396 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
396 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
397 pal.setColor(QPalette::WindowText, QRgb(0x404044));
397 pal.setColor(QPalette::WindowText, QRgb(0x404044));
398 }
398 }
399 foreach (QGraphicsProxyWidget *widget, m_widgetHash)
399 foreach (QGraphicsProxyWidget *widget, m_widgetHash)
400 widget->setPalette(pal);
400 widget->setPalette(pal);
401 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
401 m_view->setBackgroundBrush(pal.color((QPalette::Window)));
402 m_grid->setRubberPen(pal.color((QPalette::WindowText)));
402 m_grid->setRubberPen(pal.color((QPalette::WindowText)));
403 }
403 }
404
404
405 void Window::comboBoxFocused(QComboBox *combobox)
405 void Window::comboBoxFocused(QComboBox *combobox)
406 {
406 {
407 foreach (QGraphicsProxyWidget *widget , m_widgetHash) {
407 foreach (QGraphicsProxyWidget *widget , m_widgetHash) {
408 if (widget->widget() == combobox)
408 if (widget->widget() == combobox)
409 widget->setZValue(2.0);
409 widget->setZValue(2.0);
410 else
410 else
411 widget->setZValue(0.0);
411 widget->setZValue(0.0);
412 }
412 }
413 }
413 }
414
414
415 void Window::handleChartSelected(QChart *qchart)
415 void Window::handleChartSelected(QChart *qchart)
416 {
416 {
417 if (m_templateComboBox->currentIndex() != 0)
417 if (m_templateComboBox->currentIndex() != 0)
418 return;
418 return;
419
419
420 QAction *chosen = m_menu->exec(QCursor::pos());
420 QAction *chosen = m_menu->exec(QCursor::pos());
421
421
422 if (chosen) {
422 if (chosen) {
423 Chart *chart = (Chart *) chosen->data().value<void *>();
423 Chart *chart = (Chart *) chosen->data().value<void *>();
424 m_grid->replaceChart(qchart, chart);
424 m_grid->replaceChart(qchart, chart);
425 updateUI();
425 updateUI();
426 }
426 }
427 }
427 }
428
428
429 QMenu *Window::createMenu()
429 QMenu *Window::createMenu()
430 {
430 {
431 Charts::ChartList list = Charts::chartList();
431 Charts::ChartList list = Charts::chartList();
432 QMultiMap<QString, Chart *> categoryMap;
432 QMultiMap<QString, Chart *> categoryMap;
433
433
434 QMenu *result = new QMenu(this);
434 QMenu *result = new QMenu(this);
435
435
436 foreach (Chart *chart, list)
436 foreach (Chart *chart, list)
437 categoryMap.insertMulti(chart->category(), chart);
437 categoryMap.insertMulti(chart->category(), chart);
438
438
439 foreach (const QString &category, categoryMap.uniqueKeys()) {
439 foreach (const QString &category, categoryMap.uniqueKeys()) {
440 QMenu *menu(0);
440 QMenu *menu(0);
441 QMultiMap<QString, Chart *> subCategoryMap;
441 QMultiMap<QString, Chart *> subCategoryMap;
442 if (category.isEmpty()) {
442 if (category.isEmpty()) {
443 menu = result;
443 menu = result;
444 } else {
444 } else {
445 menu = new QMenu(category, this);
445 menu = new QMenu(category, this);
446 result->addMenu(menu);
446 result->addMenu(menu);
447 }
447 }
448
448
449 foreach (Chart *chart, categoryMap.values(category))
449 foreach (Chart *chart, categoryMap.values(category))
450 subCategoryMap.insert(chart->subCategory(), chart);
450 subCategoryMap.insert(chart->subCategory(), chart);
451
451
452 foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) {
452 foreach (const QString &subCategory, subCategoryMap.uniqueKeys()) {
453 QMenu *subMenu(0);
453 QMenu *subMenu(0);
454 if (subCategory.isEmpty()) {
454 if (subCategory.isEmpty()) {
455 subMenu = menu;
455 subMenu = menu;
456 } else {
456 } else {
457 subMenu = new QMenu(subCategory, this);
457 subMenu = new QMenu(subCategory, this);
458 menu->addMenu(subMenu);
458 menu->addMenu(subMenu);
459 }
459 }
460
460
461 foreach (Chart *chart, subCategoryMap.values(subCategory)) {
461 foreach (Chart *chart, subCategoryMap.values(subCategory)) {
462 createMenuAction(subMenu, QIcon(), chart->name(),
462 createMenuAction(subMenu, QIcon(), chart->name(),
463 qVariantFromValue((void *) chart));
463 qVariantFromValue((void *) chart));
464 }
464 }
465 }
465 }
466 }
466 }
467 return result;
467 return result;
468 }
468 }
469
469
470 QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
470 QAction *Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text,
471 const QVariant &data)
471 const QVariant &data)
472 {
472 {
473 QAction *action = menu->addAction(icon, text);
473 QAction *action = menu->addAction(icon, text);
474 action->setCheckable(false);
474 action->setCheckable(false);
475 action->setData(data);
475 action->setData(data);
476 return action;
476 return action;
477 }
477 }
478
478
479 void Window::handleGeometryChanged()
479 void Window::handleGeometryChanged()
480 {
480 {
481 QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize);
481 QSizeF size = m_baseLayout->sizeHint(Qt::MinimumSize);
482 m_view->scene()->setSceneRect(0, 0, this->width(), this->height());
482 m_view->scene()->setSceneRect(0, 0, this->width(), this->height());
483 m_view->setMinimumSize(size.toSize());
483 m_view->setMinimumSize(size.toSize());
484 }
484 }
General Comments 0
You need to be logged in to leave comments. Login now