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