##// END OF EJS Templates
Adds comandline parser for chartviewer
Michal Klocek -
r2119:dc8253ccbb89
parent child
Show More
@@ -22,10 +22,45
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 }
@@ -40,7 +40,7
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),
@@ -111,6 +111,7 Window::Window(QWidget *parent) :
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
@@ -210,6 +211,49 QComboBox *Window::createTempleteBox()
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 {
@@ -46,7 +46,7 class Window: public QMainWindow
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:
@@ -69,6 +69,7 private:
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);
General Comments 0
You need to be logged in to leave comments. Login now