@@ -1,582 +1,583 | |||||
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(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 | connectSignals(); |
|
68 | connectSignals(); | |
69 |
|
69 | |||
70 | // create layout |
|
70 | // create layout | |
71 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); |
|
71 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); | |
72 | settingsLayout->setOrientation(Qt::Vertical); |
|
72 | settingsLayout->setOrientation(Qt::Vertical); | |
73 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
73 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
74 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); |
|
74 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); | |
75 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); |
|
75 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); | |
76 | settingsLayout->addItem(m_widgetHash["themeLabel"]); |
|
76 | settingsLayout->addItem(m_widgetHash["themeLabel"]); | |
77 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); |
|
77 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); | |
78 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); |
|
78 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); | |
79 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); |
|
79 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); | |
80 | settingsLayout->addItem(m_widgetHash["legendLabel"]); |
|
80 | settingsLayout->addItem(m_widgetHash["legendLabel"]); | |
81 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); |
|
81 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); | |
82 | settingsLayout->addItem(m_widgetHash["templateLabel"]); |
|
82 | settingsLayout->addItem(m_widgetHash["templateLabel"]); | |
83 | settingsLayout->addItem(m_widgetHash["templateComboBox"]); |
|
83 | settingsLayout->addItem(m_widgetHash["templateComboBox"]); | |
84 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); |
|
84 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); | |
85 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); |
|
85 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); | |
86 | settingsLayout->addStretch(); |
|
86 | settingsLayout->addStretch(); | |
87 | m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1); |
|
87 | m_baseLayout->addItem(settingsLayout, 0, 3, 2, 1); | |
88 |
|
88 | |||
89 | //create charts |
|
89 | //create charts | |
90 | Charts::ChartList list = Charts::chartList(); |
|
90 | Charts::ChartList list = Charts::chartList(); | |
91 |
|
91 | |||
92 | for (int i = 0; i < 9; ++i) { |
|
92 | for (int i = 0; i < 9; ++i) { | |
93 | QChart* chart = 0; |
|
93 | QChart* chart = 0; | |
94 | if(i<list.size()){ |
|
94 | if(i<list.size()){ | |
95 | chart = list.at(i)->createChart(m_dataTable); |
|
95 | chart = list.at(i)->createChart(m_dataTable); | |
96 | }else{ |
|
96 | }else{ | |
97 | chart = new QChart(); |
|
97 | chart = new QChart(); | |
98 | chart->setTitle(tr("Empty")); |
|
98 | chart->setTitle(tr("Empty")); | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | m_baseLayout->addItem(chart, i / 3, i % 3); |
|
101 | m_baseLayout->addItem(chart, i / 3, i % 3); | |
102 | m_chartHash[chart] = i; |
|
102 | m_chartHash[chart] = i; | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | m_form = new QGraphicsWidget(); |
|
105 | m_form = new QGraphicsWidget(); | |
106 | m_form->setLayout(m_baseLayout); |
|
106 | m_form->setLayout(m_baseLayout); | |
107 | m_scene->addItem(m_form); |
|
107 | m_scene->addItem(m_form); | |
108 | m_scene->addItem(m_rubberBand); |
|
108 | m_scene->addItem(m_rubberBand); | |
109 | m_rubberBand->setVisible(false); |
|
109 | m_rubberBand->setVisible(false); | |
110 |
|
110 | |||
111 | m_view = new View(m_scene, m_form); |
|
111 | m_view = new View(m_scene, m_form); | |
112 | m_view->setMinimumSize(m_form->preferredSize().toSize()); |
|
112 | m_view->setMinimumSize(m_form->preferredSize().toSize()); | |
113 |
|
113 | |||
114 | // Set defaults |
|
114 | // Set defaults | |
115 | m_antialiasCheckBox->setChecked(true); |
|
115 | m_antialiasCheckBox->setChecked(true); | |
116 | updateUI(); |
|
116 | updateUI(); | |
117 | setCentralWidget(m_view); |
|
117 | setCentralWidget(m_view); | |
118 | } |
|
118 | } | |
119 |
|
119 | |||
120 | Window::~Window() |
|
120 | Window::~Window() | |
121 | { |
|
121 | { | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void Window::connectSignals() |
|
124 | void Window::connectSignals() | |
125 | { |
|
125 | { | |
126 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
126 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
127 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
127 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
128 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
128 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
129 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
129 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
130 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
130 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
131 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
131 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
132 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
132 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
133 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
133 | QObject::connect(m_templateComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void Window::createProxyWidgets() |
|
136 | void Window::createProxyWidgets() | |
137 | { |
|
137 | { | |
138 | m_themeComboBox = createThemeBox(); |
|
138 | m_themeComboBox = createThemeBox(); | |
139 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); |
|
139 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); | |
140 | m_animatedComboBox = createAnimationBox(); |
|
140 | m_animatedComboBox = createAnimationBox(); | |
141 | m_legendComboBox = createLegendBox(); |
|
141 | m_legendComboBox = createLegendBox(); | |
142 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); |
|
142 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); | |
143 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
|
143 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); | |
144 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
|
144 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); | |
145 | m_templateComboBox= createTempleteBox(); |
|
145 | m_templateComboBox= createTempleteBox(); | |
146 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
|
146 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); | |
147 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
|
147 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); | |
148 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
|
148 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); | |
149 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); |
|
149 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); | |
150 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); |
|
150 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); | |
151 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); |
|
151 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); | |
152 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); |
|
152 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); | |
153 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); |
|
153 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); | |
154 | m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); |
|
154 | m_widgetHash["templateLabel"] = m_scene->addWidget(new QLabel("Chart template")); | |
155 | m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); |
|
155 | m_widgetHash["templateComboBox"] = m_scene->addWidget(m_templateComboBox); | |
156 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); |
|
156 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); | |
157 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); |
|
157 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); | |
158 |
|
158 | |||
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | QComboBox* Window::createThemeBox() |
|
161 | QComboBox* Window::createThemeBox() | |
162 | { |
|
162 | { | |
163 | QComboBox* themeComboBox = new ComboBox(this); |
|
163 | QComboBox* themeComboBox = new ComboBox(this); | |
164 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
164 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
165 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
165 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
166 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
166 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
167 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
167 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
168 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
168 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
169 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
169 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
170 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
170 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
171 | return themeComboBox; |
|
171 | return themeComboBox; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | QComboBox* Window::createAnimationBox() |
|
174 | QComboBox* Window::createAnimationBox() | |
175 | { |
|
175 | { | |
176 | QComboBox* animationComboBox = new ComboBox(this); |
|
176 | QComboBox* animationComboBox = new ComboBox(this); | |
177 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
177 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
178 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
178 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
179 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
179 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
180 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
180 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
181 | return animationComboBox; |
|
181 | return animationComboBox; | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | QComboBox* Window::createLegendBox() |
|
184 | QComboBox* Window::createLegendBox() | |
185 | { |
|
185 | { | |
186 | QComboBox* legendComboBox = new ComboBox(this); |
|
186 | QComboBox* legendComboBox = new ComboBox(this); | |
187 | legendComboBox->addItem("No Legend ", 0); |
|
187 | legendComboBox->addItem("No Legend ", 0); | |
188 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
188 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
189 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
189 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
190 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
190 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); | |
191 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
191 | legendComboBox->addItem("Legend Right", Qt::AlignRight); | |
192 | return legendComboBox; |
|
192 | return legendComboBox; | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | QComboBox* Window::createTempleteBox() |
|
195 | QComboBox* Window::createTempleteBox() | |
196 | { |
|
196 | { | |
197 | QComboBox* templateComboBox = new ComboBox(this); |
|
197 | QComboBox* templateComboBox = new ComboBox(this); | |
198 | templateComboBox->addItem("No Template", 0); |
|
198 | templateComboBox->addItem("No Template", 0); | |
199 |
|
199 | |||
200 | Charts::ChartList list = Charts::chartList(); |
|
200 | Charts::ChartList list = Charts::chartList(); | |
201 | QMultiMap<QString, Chart*> categoryMap; |
|
201 | QMultiMap<QString, Chart*> categoryMap; | |
202 |
|
202 | |||
203 | foreach(Chart* chart, list) { |
|
203 | foreach(Chart* chart, list) { | |
204 | categoryMap.insertMulti(chart->category(), chart); |
|
204 | categoryMap.insertMulti(chart->category(), chart); | |
205 | } |
|
205 | } | |
206 | foreach(const QString& category, categoryMap.uniqueKeys()) { |
|
206 | foreach(const QString& category, categoryMap.uniqueKeys()) { | |
207 | templateComboBox->addItem(category, category); |
|
207 | templateComboBox->addItem(category, category); | |
208 | } |
|
208 | } | |
209 | return templateComboBox; |
|
209 | return templateComboBox; | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 |
|
212 | |||
213 | void Window::updateUI() |
|
213 | void Window::updateUI() | |
214 | { |
|
214 | { | |
215 | checkTemplate(); |
|
215 | checkTemplate(); | |
216 | checkOpenGL(); |
|
216 | checkOpenGL(); | |
217 | checkTheme(); |
|
217 | checkTheme(); | |
218 | checkAnimationOptions(); |
|
218 | checkAnimationOptions(); | |
219 | checkLegend(); |
|
219 | checkLegend(); | |
220 | checkState(); |
|
220 | checkState(); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | void Window::checkLegend() |
|
223 | void Window::checkLegend() | |
224 | { |
|
224 | { | |
225 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
225 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
226 |
|
226 | |||
227 | if (!alignment) { |
|
227 | if (!alignment) { | |
228 | foreach (QChart *chart, m_chartHash.keys()) { |
|
228 | foreach (QChart *chart, m_chartHash.keys()) { | |
229 | chart->legend()->hide(); |
|
229 | chart->legend()->hide(); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 | else { |
|
232 | else { | |
233 | foreach (QChart *chart, m_chartHash.keys()) { |
|
233 | foreach (QChart *chart, m_chartHash.keys()) { | |
234 | chart->legend()->setAlignment(alignment); |
|
234 | chart->legend()->setAlignment(alignment); | |
235 | chart->legend()->show(); |
|
235 | chart->legend()->show(); | |
236 | } |
|
236 | } | |
237 | } |
|
237 | } | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | void Window::checkOpenGL() |
|
240 | void Window::checkOpenGL() | |
241 | { |
|
241 | { | |
242 | bool opengl = m_openGLCheckBox->isChecked(); |
|
242 | bool opengl = m_openGLCheckBox->isChecked(); | |
243 | bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport()); |
|
243 | bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport()); | |
244 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
|
244 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { | |
245 | m_view->deleteLater(); |
|
245 | m_view->deleteLater(); | |
246 | m_view = new View(m_scene, m_form); |
|
246 | m_view = new View(m_scene, m_form); | |
247 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); |
|
247 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); | |
248 | setCentralWidget(m_view); |
|
248 | setCentralWidget(m_view); | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | bool antialias = m_antialiasCheckBox->isChecked(); |
|
251 | bool antialias = m_antialiasCheckBox->isChecked(); | |
252 |
|
252 | |||
253 | if (opengl) |
|
253 | if (opengl) | |
254 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); |
|
254 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); | |
255 | else |
|
255 | else | |
256 | m_view->setRenderHint(QPainter::Antialiasing, antialias); |
|
256 | m_view->setRenderHint(QPainter::Antialiasing, antialias); | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | void Window::checkAnimationOptions() |
|
259 | void Window::checkAnimationOptions() | |
260 | { |
|
260 | { | |
261 | QChart::AnimationOptions options( |
|
261 | QChart::AnimationOptions options( | |
262 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
262 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
263 | if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) { |
|
263 | if (!m_chartHash.isEmpty() && m_chartHash.keys().at(0)->animationOptions() != options) { | |
264 | foreach (QChart *chart, m_chartHash.keys()) |
|
264 | foreach (QChart *chart, m_chartHash.keys()) | |
265 | chart->setAnimationOptions(options); |
|
265 | chart->setAnimationOptions(options); | |
266 | } |
|
266 | } | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | void Window::checkState() |
|
269 | void Window::checkState() | |
270 | { |
|
270 | { | |
271 | bool scroll = m_scrollCheckBox->isChecked(); |
|
271 | bool scroll = m_scrollCheckBox->isChecked(); | |
272 |
|
272 | |||
273 | if (m_state != ScrollState && scroll) { |
|
273 | if (m_state != ScrollState && scroll) { | |
274 | m_state = ScrollState; |
|
274 | m_state = ScrollState; | |
275 | m_zoomCheckBox->setChecked(false); |
|
275 | m_zoomCheckBox->setChecked(false); | |
276 | } |
|
276 | } | |
277 | else if (!scroll && m_state == ScrollState) { |
|
277 | else if (!scroll && m_state == ScrollState) { | |
278 | m_state = NoState; |
|
278 | m_state = NoState; | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | bool zoom = m_zoomCheckBox->isChecked(); |
|
281 | bool zoom = m_zoomCheckBox->isChecked(); | |
282 |
|
282 | |||
283 | if (m_state != ZoomState && zoom) { |
|
283 | if (m_state != ZoomState && zoom) { | |
284 | m_state = ZoomState; |
|
284 | m_state = ZoomState; | |
285 | m_scrollCheckBox->setChecked(false); |
|
285 | m_scrollCheckBox->setChecked(false); | |
286 | } |
|
286 | } | |
287 | else if (!zoom && m_state == ZoomState) { |
|
287 | else if (!zoom && m_state == ZoomState) { | |
288 | m_state = NoState; |
|
288 | m_state = NoState; | |
289 | } |
|
289 | } | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | void Window::checkTemplate() |
|
292 | void Window::checkTemplate() | |
293 | { |
|
293 | { | |
294 |
|
294 | |||
295 | int index = m_templateComboBox->currentIndex(); |
|
295 | int index = m_templateComboBox->currentIndex(); | |
296 | if (m_template == index || index == 0) |
|
296 | if (m_template == index || index == 0) | |
297 | return; |
|
297 | return; | |
298 |
|
298 | |||
299 | m_template = index; |
|
299 | m_template = index; | |
300 |
|
300 | |||
301 | QString category = m_templateComboBox->itemData(index).toString(); |
|
301 | QString category = m_templateComboBox->itemData(index).toString(); | |
302 | Charts::ChartList list = Charts::chartList(); |
|
302 | Charts::ChartList list = Charts::chartList(); | |
303 |
|
303 | |||
304 | QList<QChart*> qchartList = m_chartHash.keys(); |
|
304 | QList<QChart*> qchartList = m_chartHash.keys(); | |
305 |
|
305 | |||
306 | foreach(QChart* qchart,qchartList){ |
|
306 | foreach(QChart* qchart,qchartList){ | |
307 | for(int i = 0 ; i < m_baseLayout->count();++i) |
|
307 | for(int i = 0 ; i < m_baseLayout->count();++i) | |
308 | { |
|
308 | { | |
309 | if(m_baseLayout->itemAt(i)==qchart){ |
|
309 | if(m_baseLayout->itemAt(i)==qchart){ | |
310 | m_baseLayout->removeAt(i); |
|
310 | m_baseLayout->removeAt(i); | |
311 | break; |
|
311 | break; | |
312 | } |
|
312 | } | |
313 | } |
|
313 | } | |
314 | } |
|
314 | } | |
315 |
|
315 | |||
316 | m_chartHash.clear(); |
|
316 | m_chartHash.clear(); | |
317 | qDeleteAll(qchartList); |
|
317 | qDeleteAll(qchartList); | |
318 |
|
318 | |||
319 | QChart* qchart(0); |
|
319 | QChart* qchart(0); | |
320 |
|
320 | |||
321 | int j=0; |
|
321 | int j=0; | |
322 | for (int i = 0; i < list.size(); ++i) { |
|
322 | for (int i = 0; i < list.size(); ++i) { | |
323 | Chart* chart = list.at(i); |
|
323 | Chart* chart = list.at(i); | |
324 | if (chart->category() == category && j < 9) { |
|
324 | if (chart->category() == category && j < 9) { | |
325 | qchart = list.at(i)->createChart(m_dataTable); |
|
325 | qchart = list.at(i)->createChart(m_dataTable); | |
326 | m_baseLayout->addItem(qchart, j / 3, j % 3); |
|
326 | m_baseLayout->addItem(qchart, j / 3, j % 3); | |
327 | m_chartHash[qchart] = j; |
|
327 | m_chartHash[qchart] = j; | |
328 | j++; |
|
328 | j++; | |
329 | } |
|
329 | } | |
330 | } |
|
330 | } | |
331 | for (; j < 9; ++j) { |
|
331 | for (; j < 9; ++j) { | |
332 | qchart = new QChart(); |
|
332 | qchart = new QChart(); | |
333 | qchart->setTitle(tr("Empty")); |
|
333 | qchart->setTitle(tr("Empty")); | |
334 | m_baseLayout->addItem(qchart, j / 3, j % 3); |
|
334 | m_baseLayout->addItem(qchart, j / 3, j % 3); | |
335 | m_chartHash[qchart] = j; |
|
335 | m_chartHash[qchart] = j; | |
336 | } |
|
336 | } | |
|
337 | m_baseLayout->activate(); | |||
337 | } |
|
338 | } | |
338 |
|
339 | |||
339 | void Window::checkTheme() |
|
340 | void Window::checkTheme() | |
340 | { |
|
341 | { | |
341 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
|
342 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( | |
342 | m_themeComboBox->currentIndex()).toInt(); |
|
343 | m_themeComboBox->currentIndex()).toInt(); | |
343 |
|
344 | |||
344 | foreach (QChart *chart, m_chartHash.keys()) |
|
345 | foreach (QChart *chart, m_chartHash.keys()) | |
345 | chart->setTheme(theme); |
|
346 | chart->setTheme(theme); | |
346 |
|
347 | |||
347 | QPalette pal = window()->palette(); |
|
348 | QPalette pal = window()->palette(); | |
348 | if (theme == QChart::ChartThemeLight) { |
|
349 | if (theme == QChart::ChartThemeLight) { | |
349 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
350 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
350 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
351 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
351 | } |
|
352 | } | |
352 | else if (theme == QChart::ChartThemeDark) { |
|
353 | else if (theme == QChart::ChartThemeDark) { | |
353 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
354 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
354 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
355 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
355 | } |
|
356 | } | |
356 | else if (theme == QChart::ChartThemeBlueCerulean) { |
|
357 | else if (theme == QChart::ChartThemeBlueCerulean) { | |
357 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
358 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
358 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
359 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
359 | } |
|
360 | } | |
360 | else if (theme == QChart::ChartThemeBrownSand) { |
|
361 | else if (theme == QChart::ChartThemeBrownSand) { | |
361 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
362 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
362 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
363 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
363 | } |
|
364 | } | |
364 | else if (theme == QChart::ChartThemeBlueNcs) { |
|
365 | else if (theme == QChart::ChartThemeBlueNcs) { | |
365 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
366 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
366 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
367 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
367 | } |
|
368 | } | |
368 | else if (theme == QChart::ChartThemeHighContrast) { |
|
369 | else if (theme == QChart::ChartThemeHighContrast) { | |
369 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
370 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
370 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
371 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
371 | } |
|
372 | } | |
372 | else if (theme == QChart::ChartThemeBlueIcy) { |
|
373 | else if (theme == QChart::ChartThemeBlueIcy) { | |
373 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
374 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
374 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
375 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
375 | } |
|
376 | } | |
376 | else { |
|
377 | else { | |
377 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
378 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
378 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
379 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
379 | } |
|
380 | } | |
380 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { |
|
381 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { | |
381 | widget->setPalette(pal); |
|
382 | widget->setPalette(pal); | |
382 | } |
|
383 | } | |
383 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
|
384 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); | |
384 | m_rubberBand->setPen(pal.color((QPalette::WindowText))); |
|
385 | m_rubberBand->setPen(pal.color((QPalette::WindowText))); | |
385 | } |
|
386 | } | |
386 |
|
387 | |||
387 | void Window::mousePressEvent(QMouseEvent *event) |
|
388 | void Window::mousePressEvent(QMouseEvent *event) | |
388 | { |
|
389 | { | |
389 | if (event->button() == Qt::LeftButton) { |
|
390 | if (event->button() == Qt::LeftButton) { | |
390 |
|
391 | |||
391 | m_origin = event->pos(); |
|
392 | m_origin = event->pos(); | |
392 | m_currentState = NoState; |
|
393 | m_currentState = NoState; | |
393 |
|
394 | |||
394 | foreach (QChart *chart, m_chartHash.keys()) { |
|
395 | foreach (QChart *chart, m_chartHash.keys()) { | |
395 |
|
396 | |||
396 | QRectF geometryRect = chart->geometry(); |
|
397 | QRectF geometryRect = chart->geometry(); | |
397 | QRectF plotArea = chart->plotArea(); |
|
398 | QRectF plotArea = chart->plotArea(); | |
398 | plotArea.translate(geometryRect.topLeft()); |
|
399 | plotArea.translate(geometryRect.topLeft()); | |
399 | if (plotArea.contains(m_origin)) { |
|
400 | if (plotArea.contains(m_origin)) { | |
400 | m_currentState = m_state; |
|
401 | m_currentState = m_state; | |
401 |
|
402 | |||
402 | if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) { |
|
403 | if (m_currentState == NoState && m_templateComboBox->currentIndex()==0) { | |
403 | handleMenu(chart); |
|
404 | handleMenu(chart); | |
404 | } |
|
405 | } | |
405 | break; |
|
406 | break; | |
406 | } |
|
407 | } | |
407 | } |
|
408 | } | |
408 |
|
409 | |||
409 | if (m_currentState == ZoomState) { |
|
410 | if (m_currentState == ZoomState) { | |
410 | m_rubberBand->setRect(QRectF(m_origin, QSize())); |
|
411 | m_rubberBand->setRect(QRectF(m_origin, QSize())); | |
411 | m_rubberBand->setVisible(true); |
|
412 | m_rubberBand->setVisible(true); | |
412 | } |
|
413 | } | |
413 |
|
414 | |||
414 | event->accept(); |
|
415 | event->accept(); | |
415 | } |
|
416 | } | |
416 |
|
417 | |||
417 | if (event->button() == Qt::RightButton) { |
|
418 | if (event->button() == Qt::RightButton) { | |
418 | m_origin = event->pos(); |
|
419 | m_origin = event->pos(); | |
419 | m_currentState = m_state; |
|
420 | m_currentState = m_state; | |
420 | } |
|
421 | } | |
421 | } |
|
422 | } | |
422 |
|
423 | |||
423 | void Window::mouseMoveEvent(QMouseEvent *event) |
|
424 | void Window::mouseMoveEvent(QMouseEvent *event) | |
424 | { |
|
425 | { | |
425 | if ( m_currentState != NoState) { |
|
426 | if ( m_currentState != NoState) { | |
426 |
|
427 | |||
427 | foreach (QChart *chart, m_chartHash.keys()) { |
|
428 | foreach (QChart *chart, m_chartHash.keys()) { | |
428 |
|
429 | |||
429 | QRectF geometryRect = chart->geometry(); |
|
430 | QRectF geometryRect = chart->geometry(); | |
430 | QRectF plotArea = chart->plotArea(); |
|
431 | QRectF plotArea = chart->plotArea(); | |
431 | plotArea.translate(geometryRect.topLeft()); |
|
432 | plotArea.translate(geometryRect.topLeft()); | |
432 |
|
433 | |||
433 | if (plotArea.contains(m_origin)) { |
|
434 | if (plotArea.contains(m_origin)) { | |
434 | if (m_currentState == ScrollState) { |
|
435 | if (m_currentState == ScrollState) { | |
435 | QPointF delta = m_origin - event->pos(); |
|
436 | QPointF delta = m_origin - event->pos(); | |
436 | chart->scroll(delta.x(), -delta.y()); |
|
437 | chart->scroll(delta.x(), -delta.y()); | |
437 | } |
|
438 | } | |
438 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) { |
|
439 | if (m_currentState == ZoomState && plotArea.contains(event->pos())) { | |
439 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); |
|
440 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); | |
440 | } |
|
441 | } | |
441 | break; |
|
442 | break; | |
442 | } |
|
443 | } | |
443 | } |
|
444 | } | |
444 | if(m_currentState == ScrollState) m_origin = event->pos(); |
|
445 | if(m_currentState == ScrollState) m_origin = event->pos(); | |
445 | event->accept(); |
|
446 | event->accept(); | |
446 | } |
|
447 | } | |
447 | } |
|
448 | } | |
448 |
|
449 | |||
449 | void Window::mouseReleaseEvent(QMouseEvent *event) |
|
450 | void Window::mouseReleaseEvent(QMouseEvent *event) | |
450 | { |
|
451 | { | |
451 | if (event->button() == Qt::LeftButton) { |
|
452 | if (event->button() == Qt::LeftButton) { | |
452 | if (m_currentState == ZoomState) { |
|
453 | if (m_currentState == ZoomState) { | |
453 | m_rubberBand->setVisible(false); |
|
454 | m_rubberBand->setVisible(false); | |
454 |
|
455 | |||
455 | foreach (QChart *chart, m_chartHash.keys()) { |
|
456 | foreach (QChart *chart, m_chartHash.keys()) { | |
456 |
|
457 | |||
457 | QRectF geometryRect = chart->geometry(); |
|
458 | QRectF geometryRect = chart->geometry(); | |
458 | QRectF plotArea = chart->plotArea(); |
|
459 | QRectF plotArea = chart->plotArea(); | |
459 | plotArea.translate(geometryRect.topLeft()); |
|
460 | plotArea.translate(geometryRect.topLeft()); | |
460 |
|
461 | |||
461 | if (plotArea.contains(m_origin)) { |
|
462 | if (plotArea.contains(m_origin)) { | |
462 | QRectF rect = m_rubberBand->rect(); |
|
463 | QRectF rect = m_rubberBand->rect(); | |
463 | rect.translate(-geometryRect.topLeft()); |
|
464 | rect.translate(-geometryRect.topLeft()); | |
464 | chart->zoomIn(rect); |
|
465 | chart->zoomIn(rect); | |
465 | break; |
|
466 | break; | |
466 | } |
|
467 | } | |
467 | } |
|
468 | } | |
468 | } |
|
469 | } | |
469 |
|
470 | |||
470 | m_currentState = NoState; |
|
471 | m_currentState = NoState; | |
471 | event->accept(); |
|
472 | event->accept(); | |
472 | } |
|
473 | } | |
473 |
|
474 | |||
474 | if (event->button() == Qt::RightButton) { |
|
475 | if (event->button() == Qt::RightButton) { | |
475 |
|
476 | |||
476 | if (m_currentState == ZoomState) { |
|
477 | if (m_currentState == ZoomState) { | |
477 | foreach (QChart *chart, m_chartHash.keys()) { |
|
478 | foreach (QChart *chart, m_chartHash.keys()) { | |
478 |
|
479 | |||
479 | QRectF geometryRect = chart->geometry(); |
|
480 | QRectF geometryRect = chart->geometry(); | |
480 | QRectF plotArea = chart->plotArea(); |
|
481 | QRectF plotArea = chart->plotArea(); | |
481 | plotArea.translate(geometryRect.topLeft()); |
|
482 | plotArea.translate(geometryRect.topLeft()); | |
482 |
|
483 | |||
483 | if (plotArea.contains(m_origin)) { |
|
484 | if (plotArea.contains(m_origin)) { | |
484 | chart->zoomOut(); |
|
485 | chart->zoomOut(); | |
485 | break; |
|
486 | break; | |
486 | } |
|
487 | } | |
487 | } |
|
488 | } | |
488 | } |
|
489 | } | |
489 | } |
|
490 | } | |
490 | } |
|
491 | } | |
491 |
|
492 | |||
492 | void Window::comboBoxFocused(QComboBox *combobox) |
|
493 | void Window::comboBoxFocused(QComboBox *combobox) | |
493 | { |
|
494 | { | |
494 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { |
|
495 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { | |
495 | if(widget->widget()==combobox) |
|
496 | if(widget->widget()==combobox) | |
496 | widget->setZValue(2.0); |
|
497 | widget->setZValue(2.0); | |
497 | else |
|
498 | else | |
498 | widget->setZValue(0.0); |
|
499 | widget->setZValue(0.0); | |
499 | } |
|
500 | } | |
500 | } |
|
501 | } | |
501 |
|
502 | |||
502 | void Window::handleMenu(QChart* qchart) |
|
503 | void Window::handleMenu(QChart* qchart) | |
503 | { |
|
504 | { | |
504 | QAction *chosen = m_menu->exec(QCursor::pos()); |
|
505 | QAction *chosen = m_menu->exec(QCursor::pos()); | |
505 |
|
506 | |||
506 | if (chosen) { |
|
507 | if (chosen) { | |
507 | Chart* chart = (Chart *) chosen->data().value<void *>(); |
|
508 | Chart* chart = (Chart *) chosen->data().value<void *>(); | |
508 | int index = m_chartHash[qchart]; |
|
509 | int index = m_chartHash[qchart]; | |
509 | //not in 4.7.2 m_baseLayout->removeItem(qchart); |
|
510 | //not in 4.7.2 m_baseLayout->removeItem(qchart); | |
510 | for(int i = 0 ; i < m_baseLayout->count();++i) |
|
511 | for(int i = 0 ; i < m_baseLayout->count();++i) | |
511 | { |
|
512 | { | |
512 | if(m_baseLayout->itemAt(i)==qchart){ |
|
513 | if(m_baseLayout->itemAt(i)==qchart){ | |
513 | m_baseLayout->removeAt(i); |
|
514 | m_baseLayout->removeAt(i); | |
514 | break; |
|
515 | break; | |
515 | } |
|
516 | } | |
516 | } |
|
517 | } | |
517 |
|
518 | |||
518 | m_chartHash.remove(qchart); |
|
519 | m_chartHash.remove(qchart); | |
519 | QChart* newChart = chart->createChart(m_dataTable); |
|
520 | QChart* newChart = chart->createChart(m_dataTable); | |
520 | m_baseLayout->addItem(newChart, index / 3, index % 3); |
|
521 | m_baseLayout->addItem(newChart, index / 3, index % 3); | |
521 | m_chartHash[newChart] = index; |
|
522 | m_chartHash[newChart] = index; | |
522 | delete qchart; |
|
523 | delete qchart; | |
523 | updateUI(); |
|
524 | updateUI(); | |
524 | } |
|
525 | } | |
525 |
|
526 | |||
526 | } |
|
527 | } | |
527 |
|
528 | |||
528 | QMenu* Window::createMenu() |
|
529 | QMenu* Window::createMenu() | |
529 | { |
|
530 | { | |
530 | Charts::ChartList list = Charts::chartList(); |
|
531 | Charts::ChartList list = Charts::chartList(); | |
531 | QMultiMap<QString, Chart*> categoryMap; |
|
532 | QMultiMap<QString, Chart*> categoryMap; | |
532 |
|
533 | |||
533 | QMenu* result = new QMenu(this); |
|
534 | QMenu* result = new QMenu(this); | |
534 |
|
535 | |||
535 | foreach(Chart* chart, list) { |
|
536 | foreach(Chart* chart, list) { | |
536 | categoryMap.insertMulti(chart->category(), chart); |
|
537 | categoryMap.insertMulti(chart->category(), chart); | |
537 | } |
|
538 | } | |
538 |
|
539 | |||
539 | foreach(const QString& category, categoryMap.uniqueKeys()) { |
|
540 | foreach(const QString& category, categoryMap.uniqueKeys()) { | |
540 | QMenu* menu(0); |
|
541 | QMenu* menu(0); | |
541 | QMultiMap<QString, Chart*> subCategoryMap; |
|
542 | QMultiMap<QString, Chart*> subCategoryMap; | |
542 | if (category.isEmpty()) { |
|
543 | if (category.isEmpty()) { | |
543 | menu = result; |
|
544 | menu = result; | |
544 | } |
|
545 | } | |
545 | else { |
|
546 | else { | |
546 | menu = new QMenu(category, this); |
|
547 | menu = new QMenu(category, this); | |
547 | result->addMenu(menu); |
|
548 | result->addMenu(menu); | |
548 | } |
|
549 | } | |
549 |
|
550 | |||
550 | foreach(Chart* chart , categoryMap.values(category)) { |
|
551 | foreach(Chart* chart , categoryMap.values(category)) { | |
551 | subCategoryMap.insert(chart->subCategory(), chart); |
|
552 | subCategoryMap.insert(chart->subCategory(), chart); | |
552 | } |
|
553 | } | |
553 |
|
554 | |||
554 | foreach(const QString& subCategory, subCategoryMap.uniqueKeys()) { |
|
555 | foreach(const QString& subCategory, subCategoryMap.uniqueKeys()) { | |
555 | QMenu* subMenu(0); |
|
556 | QMenu* subMenu(0); | |
556 | if (subCategory.isEmpty()) { |
|
557 | if (subCategory.isEmpty()) { | |
557 | subMenu = menu; |
|
558 | subMenu = menu; | |
558 | } |
|
559 | } | |
559 | else { |
|
560 | else { | |
560 | subMenu = new QMenu(subCategory, this); |
|
561 | subMenu = new QMenu(subCategory, this); | |
561 | menu->addMenu(subMenu); |
|
562 | menu->addMenu(subMenu); | |
562 | } |
|
563 | } | |
563 |
|
564 | |||
564 | foreach(Chart* chart , subCategoryMap.values(subCategory)) { |
|
565 | foreach(Chart* chart , subCategoryMap.values(subCategory)) { | |
565 |
|
566 | |||
566 | createMenuAction(subMenu, QIcon(), chart->name(), |
|
567 | createMenuAction(subMenu, QIcon(), chart->name(), | |
567 | qVariantFromValue((void *) chart)); |
|
568 | qVariantFromValue((void *) chart)); | |
568 | } |
|
569 | } | |
569 | } |
|
570 | } | |
570 | } |
|
571 | } | |
571 |
|
572 | |||
572 | return result; |
|
573 | return result; | |
573 | } |
|
574 | } | |
574 |
|
575 | |||
575 | QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, |
|
576 | QAction* Window::createMenuAction(QMenu *menu, const QIcon &icon, const QString &text, | |
576 | const QVariant &data) |
|
577 | const QVariant &data) | |
577 | { |
|
578 | { | |
578 | QAction *action = menu->addAction(icon, text); |
|
579 | QAction *action = menu->addAction(icon, text); | |
579 | action->setCheckable(false); |
|
580 | action->setCheckable(false); | |
580 | action->setData(data); |
|
581 | action->setData(data); | |
581 | return action; |
|
582 | return action; | |
582 | } |
|
583 | } |
General Comments 0
You need to be logged in to leave comments.
Login now