@@ -1,395 +1,392 | |||||
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 |
|
41 | |||
42 | Window::Window(QWidget* parent) : |
|
42 | Window::Window(QWidget* parent) : | |
43 | QMainWindow(parent), |
|
43 | QMainWindow(parent), | |
44 | m_listCount(3), |
|
44 | m_listCount(3), | |
45 | m_valueMax(10), |
|
45 | m_valueMax(10), | |
46 | m_valueCount(7), |
|
46 | m_valueCount(7), | |
47 | m_scene(new QGraphicsScene(this)), |
|
47 | m_scene(new QGraphicsScene(this)), | |
48 | m_view(0), |
|
48 | m_view(0), | |
49 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), |
|
49 | m_dataTable(Model::generateRandomData(m_listCount, m_valueMax, m_valueCount)), | |
50 | m_form(0), |
|
50 | m_form(0), | |
51 | m_themeComboBox(0), |
|
51 | m_themeComboBox(0), | |
52 | m_antialiasCheckBox(0), |
|
52 | m_antialiasCheckBox(0), | |
53 | m_animatedComboBox(0), |
|
53 | m_animatedComboBox(0), | |
54 | m_legendComboBox(0), |
|
54 | m_legendComboBox(0), | |
55 | m_openGLCheckBox(0), |
|
55 | m_openGLCheckBox(0), | |
56 | m_zoomCheckBox(0), |
|
56 | m_zoomCheckBox(0), | |
57 | m_scrollCheckBox(0), |
|
57 | m_scrollCheckBox(0), | |
58 | m_rubberBand(new QGraphicsRectItem()), |
|
58 | m_rubberBand(new QGraphicsRectItem()), | |
59 | m_isScrolling(false), |
|
59 | m_isScrolling(false), | |
60 | m_isZooming(false), |
|
60 | m_isZooming(false), | |
61 | m_scroll(false), |
|
61 | m_scroll(false), | |
62 | m_zoom(false) |
|
62 | m_zoom(false) | |
63 | { |
|
63 | { | |
64 | createProxyWidgets(); |
|
64 | createProxyWidgets(); | |
65 | connectSignals(); |
|
65 | connectSignals(); | |
66 |
|
66 | |||
67 | // create layout |
|
67 | // create layout | |
68 | QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout(); |
|
68 | QGraphicsGridLayout* baseLayout = new QGraphicsGridLayout(); | |
69 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); |
|
69 | QGraphicsLinearLayout *settingsLayout = new QGraphicsLinearLayout(); | |
70 | settingsLayout->setOrientation(Qt::Vertical); |
|
70 | settingsLayout->setOrientation(Qt::Vertical); | |
71 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); |
|
71 | settingsLayout->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); | |
72 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); |
|
72 | settingsLayout->addItem(m_widgetHash["openGLCheckBox"]); | |
73 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); |
|
73 | settingsLayout->addItem(m_widgetHash["antialiasCheckBox"]); | |
74 | settingsLayout->addItem(m_widgetHash["themeLabel"]); |
|
74 | settingsLayout->addItem(m_widgetHash["themeLabel"]); | |
75 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); |
|
75 | settingsLayout->addItem(m_widgetHash["themeComboBox"]); | |
76 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); |
|
76 | settingsLayout->addItem(m_widgetHash["animationsLabel"]); | |
77 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); |
|
77 | settingsLayout->addItem(m_widgetHash["animatedComboBox"]); | |
78 | settingsLayout->addItem(m_widgetHash["legendLabel"]); |
|
78 | settingsLayout->addItem(m_widgetHash["legendLabel"]); | |
79 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); |
|
79 | settingsLayout->addItem(m_widgetHash["legendComboBox"]); | |
80 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); |
|
80 | settingsLayout->addItem(m_widgetHash["scrollCheckBox"]); | |
81 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); |
|
81 | settingsLayout->addItem(m_widgetHash["zoomCheckBox"]); | |
82 | settingsLayout->addStretch(); |
|
82 | settingsLayout->addStretch(); | |
83 | baseLayout->addItem(settingsLayout, 0, 3, 2, 1); |
|
83 | baseLayout->addItem(settingsLayout, 0, 3, 2, 1); | |
84 | //create charts |
|
84 | //create charts | |
85 |
|
||||
86 | Charts::ChartList list = Charts::chartList(); |
|
85 | Charts::ChartList list = Charts::chartList(); | |
87 |
|
86 | |||
88 | for(int i = 0 ; i < 9 && i<list.size() ; ++i) |
|
87 | for(int i = 0 ; i < 9 && i<list.size() ; ++i) | |
89 | { |
|
88 | { | |
90 | QChart* chart = list.at(i)->createChart(m_dataTable); |
|
89 | QChart* chart = list.at(i)->createChart(m_dataTable); | |
91 | baseLayout->addItem(chart, i/3, i%3); |
|
90 | baseLayout->addItem(chart, i/3, i%3); | |
92 | m_chartList << chart; |
|
91 | m_chartList << chart; | |
93 | } |
|
92 | } | |
94 |
|
93 | |||
95 | m_form = new QGraphicsWidget(); |
|
94 | m_form = new QGraphicsWidget(); | |
96 | m_form->setLayout(baseLayout); |
|
95 | m_form->setLayout(baseLayout); | |
97 | m_scene->addItem(m_form); |
|
96 | m_scene->addItem(m_form); | |
98 | m_scene->addItem(m_rubberBand); |
|
97 | m_scene->addItem(m_rubberBand); | |
99 | m_rubberBand->setVisible(false); |
|
98 | m_rubberBand->setVisible(false); | |
100 |
|
99 | |||
101 | m_view = new View(m_scene, m_form); |
|
100 | m_view = new View(m_scene, m_form); | |
102 | m_view->setMinimumSize(m_form->preferredSize().toSize()); |
|
101 | m_view->setMinimumSize(m_form->preferredSize().toSize()); | |
103 |
|
102 | |||
104 | // Set defaults |
|
103 | // Set defaults | |
105 | m_antialiasCheckBox->setChecked(true); |
|
104 | m_antialiasCheckBox->setChecked(true); | |
106 | updateUI(); |
|
105 | updateUI(); | |
107 | setCentralWidget(m_view); |
|
106 | setCentralWidget(m_view); | |
108 | } |
|
107 | } | |
109 |
|
108 | |||
110 | Window::~Window() |
|
109 | Window::~Window() | |
111 | { |
|
110 | { | |
112 | } |
|
111 | } | |
113 |
|
112 | |||
114 | void Window::connectSignals() |
|
113 | void Window::connectSignals() | |
115 | { |
|
114 | { | |
116 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
115 | QObject::connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
117 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
116 | QObject::connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
118 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
117 | QObject::connect(m_openGLCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
119 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
118 | QObject::connect(m_zoomCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
120 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); |
|
119 | QObject::connect(m_scrollCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI())); | |
121 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
120 | QObject::connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
122 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); |
|
121 | QObject::connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI())); | |
123 | } |
|
122 | } | |
124 |
|
123 | |||
125 | void Window::createProxyWidgets() |
|
124 | void Window::createProxyWidgets() | |
126 | { |
|
125 | { | |
127 | m_themeComboBox = createThemeBox(); |
|
126 | m_themeComboBox = createThemeBox(); | |
128 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); |
|
127 | m_antialiasCheckBox = new QCheckBox(tr("Anti-aliasing")); | |
129 | m_animatedComboBox = createAnimationBox(); |
|
128 | m_animatedComboBox = createAnimationBox(); | |
130 | m_legendComboBox = createLegendBox(); |
|
129 | m_legendComboBox = createLegendBox(); | |
131 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); |
|
130 | m_openGLCheckBox = new QCheckBox(tr("OpenGL")); | |
132 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); |
|
131 | m_zoomCheckBox = new QCheckBox(tr("Zoom")); | |
133 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); |
|
132 | m_scrollCheckBox = new QCheckBox(tr("Scroll")); | |
134 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); |
|
133 | m_widgetHash["themeComboBox"] = m_scene->addWidget(m_themeComboBox); | |
135 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); |
|
134 | m_widgetHash["antialiasCheckBox"] = m_scene->addWidget(m_antialiasCheckBox); | |
136 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); |
|
135 | m_widgetHash["animatedComboBox"] = m_scene->addWidget(m_animatedComboBox); | |
137 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); |
|
136 | m_widgetHash["legendComboBox"] = m_scene->addWidget(m_legendComboBox); | |
138 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); |
|
137 | m_widgetHash["openGLCheckBox"] = m_scene->addWidget(m_openGLCheckBox); | |
139 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); |
|
138 | m_widgetHash["themeLabel"] = m_scene->addWidget(new QLabel("Theme")); | |
140 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); |
|
139 | m_widgetHash["animationsLabel"] = m_scene->addWidget(new QLabel("Animations")); | |
141 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); |
|
140 | m_widgetHash["legendLabel"] = m_scene->addWidget(new QLabel("Legend")); | |
142 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); |
|
141 | m_widgetHash["zoomCheckBox"] = m_scene->addWidget(m_zoomCheckBox); | |
143 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); |
|
142 | m_widgetHash["scrollCheckBox"] = m_scene->addWidget(m_scrollCheckBox); | |
144 | } |
|
143 | } | |
145 |
|
144 | |||
146 | QComboBox* Window::createThemeBox() |
|
145 | QComboBox* Window::createThemeBox() | |
147 | { |
|
146 | { | |
148 | // settings layoutQGLWidgetβ |
|
|||
149 | QComboBox* themeComboBox = new ComboBox(this); |
|
147 | QComboBox* themeComboBox = new ComboBox(this); | |
150 | themeComboBox->addItem("Light", QChart::ChartThemeLight); |
|
148 | themeComboBox->addItem("Light", QChart::ChartThemeLight); | |
151 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); |
|
149 | themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean); | |
152 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); |
|
150 | themeComboBox->addItem("Dark", QChart::ChartThemeDark); | |
153 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); |
|
151 | themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand); | |
154 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); |
|
152 | themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs); | |
155 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); |
|
153 | themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast); | |
156 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); |
|
154 | themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy); | |
157 | return themeComboBox; |
|
155 | return themeComboBox; | |
158 | } |
|
156 | } | |
159 |
|
157 | |||
160 | QComboBox* Window::createAnimationBox() |
|
158 | QComboBox* Window::createAnimationBox() | |
161 | { |
|
159 | { | |
162 | // settings layout |
|
|||
163 | QComboBox* animationComboBox = new ComboBox(this); |
|
160 | QComboBox* animationComboBox = new ComboBox(this); | |
164 | animationComboBox->addItem("No Animations", QChart::NoAnimation); |
|
161 | animationComboBox->addItem("No Animations", QChart::NoAnimation); | |
165 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); |
|
162 | animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations); | |
166 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); |
|
163 | animationComboBox->addItem("Series Animations", QChart::SeriesAnimations); | |
167 | animationComboBox->addItem("All Animations", QChart::AllAnimations); |
|
164 | animationComboBox->addItem("All Animations", QChart::AllAnimations); | |
168 | return animationComboBox; |
|
165 | return animationComboBox; | |
169 | } |
|
166 | } | |
170 |
|
167 | |||
171 | QComboBox* Window::createLegendBox() |
|
168 | QComboBox* Window::createLegendBox() | |
172 | { |
|
169 | { | |
173 | QComboBox* legendComboBox = new ComboBox(this); |
|
170 | QComboBox* legendComboBox = new ComboBox(this); | |
174 | legendComboBox->addItem("No Legend ", 0); |
|
171 | legendComboBox->addItem("No Legend ", 0); | |
175 | legendComboBox->addItem("Legend Top", Qt::AlignTop); |
|
172 | legendComboBox->addItem("Legend Top", Qt::AlignTop); | |
176 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); |
|
173 | legendComboBox->addItem("Legend Bottom", Qt::AlignBottom); | |
177 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); |
|
174 | legendComboBox->addItem("Legend Left", Qt::AlignLeft); | |
178 | legendComboBox->addItem("Legend Right", Qt::AlignRight); |
|
175 | legendComboBox->addItem("Legend Right", Qt::AlignRight); | |
179 | return legendComboBox; |
|
176 | return legendComboBox; | |
180 | } |
|
177 | } | |
181 |
|
178 | |||
182 | void Window::updateUI() |
|
179 | void Window::updateUI() | |
183 | { |
|
180 | { | |
184 | bool opengl = m_openGLCheckBox->isChecked(); |
|
181 | bool opengl = m_openGLCheckBox->isChecked(); | |
185 | bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport()); |
|
182 | bool isOpengl = qobject_cast<QGLWidget*>(m_view->viewport()); | |
186 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { |
|
183 | if ((isOpengl && !opengl) || (!isOpengl && opengl)) { | |
187 | m_view->deleteLater(); |
|
184 | m_view->deleteLater(); | |
188 | m_view = new View(m_scene, m_form); |
|
185 | m_view = new View(m_scene, m_form); | |
189 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); |
|
186 | m_view->setViewport(!opengl ? new QWidget() : new QGLWidget()); | |
190 | setCentralWidget(m_view); |
|
187 | setCentralWidget(m_view); | |
191 | } |
|
188 | } | |
192 |
|
189 | |||
193 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( |
|
190 | QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData( | |
194 | m_themeComboBox->currentIndex()).toInt(); |
|
191 | m_themeComboBox->currentIndex()).toInt(); | |
195 |
|
192 | |||
196 | foreach (QChart *chart, m_chartList) |
|
193 | foreach (QChart *chart, m_chartList) | |
197 | chart->setTheme(theme); |
|
194 | chart->setTheme(theme); | |
198 |
|
195 | |||
199 | QPalette pal = window()->palette(); |
|
196 | QPalette pal = window()->palette(); | |
200 | if (theme == QChart::ChartThemeLight) { |
|
197 | if (theme == QChart::ChartThemeLight) { | |
201 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
198 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
202 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
199 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
203 | } |
|
200 | } | |
204 | else if (theme == QChart::ChartThemeDark) { |
|
201 | else if (theme == QChart::ChartThemeDark) { | |
205 | pal.setColor(QPalette::Window, QRgb(0x121218)); |
|
202 | pal.setColor(QPalette::Window, QRgb(0x121218)); | |
206 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
203 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
207 | } |
|
204 | } | |
208 | else if (theme == QChart::ChartThemeBlueCerulean) { |
|
205 | else if (theme == QChart::ChartThemeBlueCerulean) { | |
209 | pal.setColor(QPalette::Window, QRgb(0x40434a)); |
|
206 | pal.setColor(QPalette::Window, QRgb(0x40434a)); | |
210 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); |
|
207 | pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6)); | |
211 | } |
|
208 | } | |
212 | else if (theme == QChart::ChartThemeBrownSand) { |
|
209 | else if (theme == QChart::ChartThemeBrownSand) { | |
213 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); |
|
210 | pal.setColor(QPalette::Window, QRgb(0x9e8965)); | |
214 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
211 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
215 | } |
|
212 | } | |
216 | else if (theme == QChart::ChartThemeBlueNcs) { |
|
213 | else if (theme == QChart::ChartThemeBlueNcs) { | |
217 | pal.setColor(QPalette::Window, QRgb(0x018bba)); |
|
214 | pal.setColor(QPalette::Window, QRgb(0x018bba)); | |
218 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
215 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
219 | } |
|
216 | } | |
220 | else if (theme == QChart::ChartThemeHighContrast) { |
|
217 | else if (theme == QChart::ChartThemeHighContrast) { | |
221 | pal.setColor(QPalette::Window, QRgb(0xffab03)); |
|
218 | pal.setColor(QPalette::Window, QRgb(0xffab03)); | |
222 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); |
|
219 | pal.setColor(QPalette::WindowText, QRgb(0x181818)); | |
223 | } |
|
220 | } | |
224 | else if (theme == QChart::ChartThemeBlueIcy) { |
|
221 | else if (theme == QChart::ChartThemeBlueIcy) { | |
225 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); |
|
222 | pal.setColor(QPalette::Window, QRgb(0xcee7f0)); | |
226 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
223 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
227 | } |
|
224 | } | |
228 | else { |
|
225 | else { | |
229 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); |
|
226 | pal.setColor(QPalette::Window, QRgb(0xf0f0f0)); | |
230 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); |
|
227 | pal.setColor(QPalette::WindowText, QRgb(0x404044)); | |
231 | } |
|
228 | } | |
232 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { |
|
229 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { | |
233 | widget->setPalette(pal); |
|
230 | widget->setPalette(pal); | |
234 | } |
|
231 | } | |
235 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); |
|
232 | m_view->setBackgroundBrush(pal.color((QPalette::Window))); | |
236 | m_rubberBand->setPen(pal.color((QPalette::WindowText))); |
|
233 | m_rubberBand->setPen(pal.color((QPalette::WindowText))); | |
237 |
|
234 | |||
238 | QChart::AnimationOptions options( |
|
235 | QChart::AnimationOptions options( | |
239 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); |
|
236 | m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt()); | |
240 | if (!m_chartList.isEmpty() && m_chartList.at(0)->animationOptions() != options) { |
|
237 | if (!m_chartList.isEmpty() && m_chartList.at(0)->animationOptions() != options) { | |
241 | foreach (QChart *chart, m_chartList) |
|
238 | foreach (QChart *chart, m_chartList) | |
242 | chart->setAnimationOptions(options); |
|
239 | chart->setAnimationOptions(options); | |
243 | } |
|
240 | } | |
244 |
|
241 | |||
245 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); |
|
242 | Qt::Alignment alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt()); | |
246 |
|
243 | |||
247 | if (!alignment) { |
|
244 | if (!alignment) { | |
248 | foreach (QChart *chart, m_chartList) { |
|
245 | foreach (QChart *chart, m_chartList) { | |
249 | chart->legend()->hide(); |
|
246 | chart->legend()->hide(); | |
250 | } |
|
247 | } | |
251 | } |
|
248 | } | |
252 | else { |
|
249 | else { | |
253 | foreach (QChart *chart, m_chartList) { |
|
250 | foreach (QChart *chart, m_chartList) { | |
254 | chart->legend()->setAlignment(alignment); |
|
251 | chart->legend()->setAlignment(alignment); | |
255 | chart->legend()->show(); |
|
252 | chart->legend()->show(); | |
256 | } |
|
253 | } | |
257 | } |
|
254 | } | |
258 |
|
255 | |||
259 | bool antialias = m_antialiasCheckBox->isChecked(); |
|
256 | bool antialias = m_antialiasCheckBox->isChecked(); | |
260 |
|
257 | |||
261 | if (opengl) |
|
258 | if (opengl) | |
262 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); |
|
259 | m_view->setRenderHint(QPainter::HighQualityAntialiasing, antialias); | |
263 | else |
|
260 | else | |
264 | m_view->setRenderHint(QPainter::Antialiasing, antialias); |
|
261 | m_view->setRenderHint(QPainter::Antialiasing, antialias); | |
265 |
|
262 | |||
266 | bool scroll = m_scrollCheckBox->isChecked(); |
|
263 | bool scroll = m_scrollCheckBox->isChecked(); | |
267 |
|
264 | |||
268 | if(!m_scroll & scroll){ |
|
265 | if(!m_scroll & scroll){ | |
269 | m_scroll=true; |
|
266 | m_scroll=true; | |
270 | m_zoom=false; |
|
267 | m_zoom=false; | |
271 | m_zoomCheckBox->setChecked(false); |
|
268 | m_zoomCheckBox->setChecked(false); | |
272 | } |
|
269 | } | |
273 |
|
270 | |||
274 | bool zoom = m_zoomCheckBox->isChecked(); |
|
271 | bool zoom = m_zoomCheckBox->isChecked(); | |
275 |
|
272 | |||
276 | if(!m_zoom & zoom){ |
|
273 | if(!m_zoom & zoom){ | |
277 | m_scroll=false; |
|
274 | m_scroll=false; | |
278 | m_zoom=true; |
|
275 | m_zoom=true; | |
279 | m_scrollCheckBox->setChecked(false); |
|
276 | m_scrollCheckBox->setChecked(false); | |
280 | } |
|
277 | } | |
281 |
|
278 | |||
282 | } |
|
279 | } | |
283 |
|
280 | |||
284 | void Window::mousePressEvent(QMouseEvent *event) |
|
281 | void Window::mousePressEvent(QMouseEvent *event) | |
285 | { |
|
282 | { | |
286 | if (event->button() == Qt::LeftButton) { |
|
283 | if (event->button() == Qt::LeftButton) { | |
287 |
|
284 | |||
288 | m_origin = event->pos(); |
|
285 | m_origin = event->pos(); | |
289 | m_isScrolling = false; |
|
286 | m_isScrolling = false; | |
290 | m_isZooming = false; |
|
287 | m_isZooming = false; | |
291 |
|
288 | |||
292 | foreach (QChart *chart, m_chartList) { |
|
289 | foreach (QChart *chart, m_chartList) { | |
293 |
|
290 | |||
294 | QRectF geometryRect = chart->geometry(); |
|
291 | QRectF geometryRect = chart->geometry(); | |
295 | QRectF plotArea = chart->plotArea(); |
|
292 | QRectF plotArea = chart->plotArea(); | |
296 | plotArea.translate(geometryRect.topLeft()); |
|
293 | plotArea.translate(geometryRect.topLeft()); | |
297 | if (plotArea.contains(m_origin)) { |
|
294 | if (plotArea.contains(m_origin)) { | |
298 | m_isScrolling = m_scroll; |
|
295 | m_isScrolling = m_scroll; | |
299 | m_isZooming = m_zoom; |
|
296 | m_isZooming = m_zoom; | |
300 | break; |
|
297 | break; | |
301 | } |
|
298 | } | |
302 | } |
|
299 | } | |
303 |
|
300 | |||
304 | if (m_isZooming) { |
|
301 | if (m_isZooming) { | |
305 | m_rubberBand->setRect(QRectF(m_origin, QSize())); |
|
302 | m_rubberBand->setRect(QRectF(m_origin, QSize())); | |
306 | m_rubberBand->setVisible(true); |
|
303 | m_rubberBand->setVisible(true); | |
307 | } |
|
304 | } | |
308 | event->accept(); |
|
305 | event->accept(); | |
309 | } |
|
306 | } | |
310 |
|
307 | |||
311 | if (event->button() == Qt::RightButton) { |
|
308 | if (event->button() == Qt::RightButton) { | |
312 | m_origin = event->pos(); |
|
309 | m_origin = event->pos(); | |
313 | m_isZooming = m_zoom; |
|
310 | m_isZooming = m_zoom; | |
314 | } |
|
311 | } | |
315 | } |
|
312 | } | |
316 |
|
313 | |||
317 | void Window::mouseMoveEvent(QMouseEvent *event) |
|
314 | void Window::mouseMoveEvent(QMouseEvent *event) | |
318 | { |
|
315 | { | |
319 | if (m_isScrolling || m_isZooming) { |
|
316 | if (m_isScrolling || m_isZooming) { | |
320 |
|
317 | |||
321 | foreach (QChart *chart, m_chartList) { |
|
318 | foreach (QChart *chart, m_chartList) { | |
322 |
|
319 | |||
323 | QRectF geometryRect = chart->geometry(); |
|
320 | QRectF geometryRect = chart->geometry(); | |
324 | QRectF plotArea = chart->plotArea(); |
|
321 | QRectF plotArea = chart->plotArea(); | |
325 | plotArea.translate(geometryRect.topLeft()); |
|
322 | plotArea.translate(geometryRect.topLeft()); | |
326 |
|
323 | |||
327 | if (plotArea.contains(m_origin)) { |
|
324 | if (plotArea.contains(m_origin)) { | |
328 | if (m_isScrolling) { |
|
325 | if (m_isScrolling) { | |
329 | QPointF delta = m_origin - event->pos(); |
|
326 | QPointF delta = m_origin - event->pos(); | |
330 | chart->scroll(delta.x(), -delta.y()); |
|
327 | chart->scroll(delta.x(), -delta.y()); | |
331 | } |
|
328 | } | |
332 | if (m_isZooming && plotArea.contains(event->pos())) { |
|
329 | if (m_isZooming && plotArea.contains(event->pos())) { | |
333 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); |
|
330 | m_rubberBand->setRect(QRectF(m_origin, event->pos()).normalized()); | |
334 | } |
|
331 | } | |
335 | break; |
|
332 | break; | |
336 | } |
|
333 | } | |
337 | } |
|
334 | } | |
338 | if(m_isScrolling) m_origin = event->pos(); |
|
335 | if(m_isScrolling) m_origin = event->pos(); | |
339 | event->accept(); |
|
336 | event->accept(); | |
340 | } |
|
337 | } | |
341 | } |
|
338 | } | |
342 |
|
339 | |||
343 | void Window::mouseReleaseEvent(QMouseEvent *event) |
|
340 | void Window::mouseReleaseEvent(QMouseEvent *event) | |
344 | { |
|
341 | { | |
345 | if (event->button() == Qt::LeftButton) { |
|
342 | if (event->button() == Qt::LeftButton) { | |
346 | m_isScrolling = false; |
|
343 | m_isScrolling = false; | |
347 | if (m_isZooming) { |
|
344 | if (m_isZooming) { | |
348 | m_isZooming = false; |
|
345 | m_isZooming = false; | |
349 | m_rubberBand->setVisible(false); |
|
346 | m_rubberBand->setVisible(false); | |
350 |
|
347 | |||
351 | foreach (QChart *chart, m_chartList) { |
|
348 | foreach (QChart *chart, m_chartList) { | |
352 |
|
349 | |||
353 | QRectF geometryRect = chart->geometry(); |
|
350 | QRectF geometryRect = chart->geometry(); | |
354 | QRectF plotArea = chart->plotArea(); |
|
351 | QRectF plotArea = chart->plotArea(); | |
355 | plotArea.translate(geometryRect.topLeft()); |
|
352 | plotArea.translate(geometryRect.topLeft()); | |
356 |
|
353 | |||
357 | if (plotArea.contains(m_origin)) { |
|
354 | if (plotArea.contains(m_origin)) { | |
358 | QRectF rect = m_rubberBand->rect(); |
|
355 | QRectF rect = m_rubberBand->rect(); | |
359 | rect.translate(-geometryRect.topLeft()); |
|
356 | rect.translate(-geometryRect.topLeft()); | |
360 | chart->zoomIn(rect); |
|
357 | chart->zoomIn(rect); | |
361 | break; |
|
358 | break; | |
362 | } |
|
359 | } | |
363 | } |
|
360 | } | |
364 | } |
|
361 | } | |
365 | event->accept(); |
|
362 | event->accept(); | |
366 | } |
|
363 | } | |
367 |
|
364 | |||
368 | if (event->button() == Qt::RightButton) { |
|
365 | if (event->button() == Qt::RightButton) { | |
369 |
|
366 | |||
370 | if (m_isZooming) { |
|
367 | if (m_isZooming) { | |
371 | foreach (QChart *chart, m_chartList) { |
|
368 | foreach (QChart *chart, m_chartList) { | |
372 |
|
369 | |||
373 | QRectF geometryRect = chart->geometry(); |
|
370 | QRectF geometryRect = chart->geometry(); | |
374 | QRectF plotArea = chart->plotArea(); |
|
371 | QRectF plotArea = chart->plotArea(); | |
375 | plotArea.translate(geometryRect.topLeft()); |
|
372 | plotArea.translate(geometryRect.topLeft()); | |
376 |
|
373 | |||
377 | if (plotArea.contains(m_origin)) { |
|
374 | if (plotArea.contains(m_origin)) { | |
378 | QRectF rect = m_rubberBand->rect(); |
|
375 | QRectF rect = m_rubberBand->rect(); | |
379 | chart->zoomOut(); |
|
376 | chart->zoomOut(); | |
380 | break; |
|
377 | break; | |
381 | } |
|
378 | } | |
382 | } |
|
379 | } | |
383 | } |
|
380 | } | |
384 | } |
|
381 | } | |
385 | } |
|
382 | } | |
386 |
|
383 | |||
387 | void Window::comboBoxFocused(QComboBox *combobox) |
|
384 | void Window::comboBoxFocused(QComboBox *combobox) | |
388 | { |
|
385 | { | |
389 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { |
|
386 | foreach(QGraphicsProxyWidget* widget , m_widgetHash) { | |
390 | if(widget->widget()==combobox) |
|
387 | if(widget->widget()==combobox) | |
391 | widget->setZValue(2.0); |
|
388 | widget->setZValue(2.0); | |
392 | else |
|
389 | else | |
393 | widget->setZValue(0.0); |
|
390 | widget->setZValue(0.0); | |
394 | } |
|
391 | } | |
395 | } |
|
392 | } |
@@ -1,206 +1,194 | |||||
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 "scatterchartitem_p.h" |
|
21 | #include "scatterchartitem_p.h" | |
22 | #include "qscatterseries.h" |
|
22 | #include "qscatterseries.h" | |
23 | #include "qscatterseries_p.h" |
|
23 | #include "qscatterseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsScene> |
|
26 | #include <QGraphicsScene> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 | #include <QGraphicsSceneMouseEvent> |
|
28 | #include <QGraphicsSceneMouseEvent> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : |
|
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : | |
33 | XYChart(series,presenter), |
|
33 | XYChart(series,presenter), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_items(this), |
|
36 | m_items(this), | |
37 | m_visible(true), |
|
37 | m_visible(true), | |
38 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
38 | m_shape(QScatterSeries::MarkerShapeRectangle), | |
39 | m_size(15) |
|
39 | m_size(15) | |
40 | { |
|
40 | { | |
41 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
41 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); | |
42 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
42 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
43 |
|
43 | |||
44 | setZValue(ChartPresenter::ScatterSeriesZValue); |
|
44 | setZValue(ChartPresenter::ScatterSeriesZValue); | |
45 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
45 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
46 |
|
46 | |||
47 | handleUpdated(); |
|
47 | handleUpdated(); | |
48 |
|
48 | |||
49 | m_items.setHandlesChildEvents(false); |
|
49 | m_items.setHandlesChildEvents(false); | |
50 |
|
||||
51 | // TODO: how to draw a drop shadow? |
|
|||
52 | // QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect(); |
|
|||
53 | // dropShadow->setOffset(2.0); |
|
|||
54 | // dropShadow->setBlurRadius(2.0); |
|
|||
55 | // setGraphicsEffect(dropShadow); |
|
|||
56 | } |
|
50 | } | |
57 |
|
51 | |||
58 | QRectF ScatterChartItem::boundingRect() const |
|
52 | QRectF ScatterChartItem::boundingRect() const | |
59 | { |
|
53 | { | |
60 | return m_rect; |
|
54 | return m_rect; | |
61 | } |
|
55 | } | |
62 |
|
56 | |||
63 | void ScatterChartItem::createPoints(int count) |
|
57 | void ScatterChartItem::createPoints(int count) | |
64 | { |
|
58 | { | |
65 | for (int i = 0; i < count; ++i) { |
|
59 | for (int i = 0; i < count; ++i) { | |
66 |
|
60 | |||
67 | QGraphicsItem *item = 0; |
|
61 | QGraphicsItem *item = 0; | |
68 |
|
62 | |||
69 | switch (m_shape) { |
|
63 | switch (m_shape) { | |
70 | case QScatterSeries::MarkerShapeCircle: { |
|
64 | case QScatterSeries::MarkerShapeCircle: { | |
71 |
|
|
65 | item = new CircleMarker(0,0,m_size,m_size,this); | |
72 | const QRectF& rect = i->boundingRect(); |
|
66 | const QRectF& rect = item->boundingRect(); | |
73 | i->setPos(-rect.width()/2,-rect.height()/2); |
|
67 | item->setPos(-rect.width()/2,-rect.height()/2); | |
74 | item = new Marker(i,this); |
|
|||
75 | break; |
|
68 | break; | |
76 | } |
|
69 | } | |
77 | case QScatterSeries::MarkerShapeRectangle: { |
|
70 | case QScatterSeries::MarkerShapeRectangle: { | |
78 |
|
|
71 | item = new RectangleMarker(0,0,m_size,m_size,this); | |
79 | i->setPos(-m_size/2,-m_size/2); |
|
72 | item->setPos(-m_size/2,-m_size/2); | |
80 | item = new Marker(i,this); |
|
|||
81 | break; |
|
73 | break; | |
82 | } |
|
74 | } | |
83 | default: |
|
75 | default: | |
84 | qWarning()<<"Unsupported marker type"; |
|
76 | qWarning()<<"Unsupported marker type"; | |
85 | break; |
|
77 | break; | |
86 |
|
78 | |||
87 | } |
|
79 | } | |
88 | m_items.addToGroup(item); |
|
80 | m_items.addToGroup(item); | |
89 | } |
|
81 | } | |
90 | } |
|
82 | } | |
91 |
|
83 | |||
92 | void ScatterChartItem::deletePoints(int count) |
|
84 | void ScatterChartItem::deletePoints(int count) | |
93 | { |
|
85 | { | |
94 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
86 | QList<QGraphicsItem *> items = m_items.childItems(); | |
95 |
|
87 | |||
96 | for (int i = 0; i < count; ++i) { |
|
88 | for (int i = 0; i < count; ++i) { | |
97 |
|
|
89 | QGraphicsItem * item = items.takeLast(); | |
|
90 | m_markerMap.remove(item); | |||
|
91 | delete(item); | |||
98 | } |
|
92 | } | |
99 | } |
|
93 | } | |
100 |
|
94 | |||
101 |
void ScatterChartItem::markerSelected( |
|
95 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) | |
102 | { |
|
96 | { | |
103 |
emit XYChart::clicked(calculateDomainPoint(marker |
|
97 | emit XYChart::clicked(calculateDomainPoint(m_markerMap[marker])); | |
104 | } |
|
98 | } | |
105 |
|
99 | |||
106 | void ScatterChartItem::updateGeometry() |
|
100 | void ScatterChartItem::updateGeometry() | |
107 | { |
|
101 | { | |
108 |
|
102 | |||
109 | const QVector<QPointF>& points = geometryPoints(); |
|
103 | const QVector<QPointF>& points = geometryPoints(); | |
110 |
|
104 | |||
111 | if(points.size()==0) |
|
105 | if(points.size()==0) | |
112 | { |
|
106 | { | |
113 | deletePoints(m_items.childItems().count()); |
|
107 | deletePoints(m_items.childItems().count()); | |
114 | return; |
|
108 | return; | |
115 | } |
|
109 | } | |
116 |
|
110 | |||
117 | int diff = m_items.childItems().size() - points.size(); |
|
111 | int diff = m_items.childItems().size() - points.size(); | |
118 |
|
112 | |||
119 | if(diff>0) { |
|
113 | if(diff>0) { | |
120 | deletePoints(diff); |
|
114 | deletePoints(diff); | |
121 | } |
|
115 | } | |
122 | else if(diff<0) { |
|
116 | else if(diff<0) { | |
123 | createPoints(-diff); |
|
117 | createPoints(-diff); | |
124 | } |
|
118 | } | |
125 |
|
119 | |||
126 | if(diff!=0) handleUpdated(); |
|
120 | if(diff!=0) handleUpdated(); | |
127 |
|
121 | |||
128 | QList<QGraphicsItem*> items = m_items.childItems(); |
|
122 | QList<QGraphicsItem*> items = m_items.childItems(); | |
129 |
|
123 | |||
130 | for (int i = 0; i < points.size(); i++) { |
|
124 | for (int i = 0; i < points.size(); i++) { | |
131 |
|
|
125 | QGraphicsItem* item = items.at(i); | |
132 | const QPointF& point = points.at(i); |
|
126 | const QPointF& point = points.at(i); | |
133 | const QRectF& rect = item->boundingRect(); |
|
127 | const QRectF& rect = item->boundingRect(); | |
134 | item->setPoint(point); |
|
128 | m_markerMap[item]=point; | |
135 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); |
|
129 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); | |
136 | if(!m_visible || !clipRect().contains(point)) { |
|
130 | if(!m_visible || !clipRect().contains(point)) { | |
137 | item->setVisible(false); |
|
131 | item->setVisible(false); | |
138 | } |
|
132 | } | |
139 | else { |
|
133 | else { | |
140 | item->setVisible(true); |
|
134 | item->setVisible(true); | |
141 | } |
|
135 | } | |
142 | } |
|
136 | } | |
143 |
|
137 | |||
144 | prepareGeometryChange(); |
|
138 | prepareGeometryChange(); | |
145 | m_rect = clipRect(); |
|
139 | m_rect = clipRect(); | |
146 | setPos(origin()); |
|
140 | setPos(origin()); | |
147 | } |
|
141 | } | |
148 |
|
142 | |||
149 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
143 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
150 | { |
|
144 | { | |
151 | Q_UNUSED(painter) |
|
145 | Q_UNUSED(painter) | |
152 | Q_UNUSED(option) |
|
146 | Q_UNUSED(option) | |
153 | Q_UNUSED(widget) |
|
147 | Q_UNUSED(widget) | |
154 | } |
|
148 | } | |
155 |
|
149 | |||
156 | void ScatterChartItem::setPen(const QPen& pen) |
|
150 | void ScatterChartItem::setPen(const QPen& pen) | |
157 | { |
|
151 | { | |
158 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
152 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
159 |
static_cast< |
|
153 | static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen); | |
160 | } |
|
154 | } | |
161 | } |
|
155 | } | |
162 |
|
156 | |||
163 | void ScatterChartItem::setBrush(const QBrush& brush) |
|
157 | void ScatterChartItem::setBrush(const QBrush& brush) | |
164 | { |
|
158 | { | |
165 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
159 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
166 |
static_cast< |
|
160 | static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush); | |
167 | } |
|
161 | } | |
168 | } |
|
162 | } | |
169 |
|
163 | |||
170 | void ScatterChartItem::handleUpdated() |
|
164 | void ScatterChartItem::handleUpdated() | |
171 | { |
|
165 | { | |
172 | int count = m_items.childItems().count(); |
|
166 | int count = m_items.childItems().count(); | |
173 |
|
167 | |||
174 | if(count==0) return; |
|
168 | if(count==0) return; | |
175 |
|
169 | |||
176 | bool recreate = m_visible != m_series->isVisible() |
|
170 | bool recreate = m_visible != m_series->isVisible() | |
177 | || m_size != m_series->markerSize() |
|
171 | || m_size != m_series->markerSize() | |
178 | || m_shape != m_series->markerShape(); |
|
172 | || m_shape != m_series->markerShape(); | |
179 |
|
173 | |||
180 | m_visible = m_series->isVisible(); |
|
174 | m_visible = m_series->isVisible(); | |
181 | m_size = m_series->markerSize(); |
|
175 | m_size = m_series->markerSize(); | |
182 | m_shape = m_series->markerShape(); |
|
176 | m_shape = m_series->markerShape(); | |
183 |
|
177 | |||
184 | if(recreate) { |
|
178 | if(recreate) { | |
185 | // TODO: optimize handleUpdate to recreate points only in case shape changed |
|
179 | // TODO: optimize handleUpdate to recreate points only in case shape changed | |
186 | deletePoints(count); |
|
180 | deletePoints(count); | |
187 | createPoints(count); |
|
181 | createPoints(count); | |
188 |
|
182 | |||
189 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points |
|
183 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points | |
190 | updateGeometry(); |
|
184 | updateGeometry(); | |
191 | } |
|
185 | } | |
192 |
|
186 | |||
193 | setPen(m_series->pen()); |
|
187 | setPen(m_series->pen()); | |
194 | setBrush(m_series->brush()); |
|
188 | setBrush(m_series->brush()); | |
195 | update(); |
|
189 | update(); | |
196 | } |
|
190 | } | |
197 |
|
191 | |||
198 | void ScatterChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|||
199 | { |
|
|||
200 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
|||
201 | QGraphicsItem::mousePressEvent(event); |
|
|||
202 | } |
|
|||
203 |
|
||||
204 | #include "moc_scatterchartitem_p.cpp" |
|
192 | #include "moc_scatterchartitem_p.cpp" | |
205 |
|
193 | |||
206 | QTCOMMERCIALCHART_END_NAMESPACE |
|
194 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,152 +1,121 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef SCATTERCHARTITEM_H |
|
30 | #ifndef SCATTERCHARTITEM_H | |
31 | #define SCATTERCHARTITEM_H |
|
31 | #define SCATTERCHARTITEM_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "xychart_p.h" |
|
34 | #include "xychart_p.h" | |
35 | #include <QGraphicsEllipseItem> |
|
35 | #include <QGraphicsEllipseItem> | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QScatterSeries; |
|
40 | class QScatterSeries; | |
41 | class Marker; |
|
|||
42 |
|
41 | |||
43 | class ScatterChartItem : public XYChart, public QGraphicsItem |
|
42 | class ScatterChartItem : public XYChart, public QGraphicsItem | |
44 | { |
|
43 | { | |
45 | Q_OBJECT |
|
44 | Q_OBJECT | |
46 | Q_INTERFACES(QGraphicsItem) |
|
45 | Q_INTERFACES(QGraphicsItem) | |
47 | public: |
|
46 | public: | |
48 | explicit ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter); |
|
47 | explicit ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter); | |
49 |
|
48 | |||
50 | public: |
|
49 | public: | |
51 | //from QGraphicsItem |
|
50 | //from QGraphicsItem | |
52 | QRectF boundingRect() const; |
|
51 | QRectF boundingRect() const; | |
53 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
52 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
54 |
|
53 | |||
55 | void setPen(const QPen &pen); |
|
54 | void setPen(const QPen &pen); | |
56 | void setBrush(const QBrush &brush); |
|
55 | void setBrush(const QBrush &brush); | |
57 |
|
56 | |||
58 |
void markerSelected( |
|
57 | void markerSelected(QGraphicsItem *item); | |
59 |
|
58 | |||
60 | public Q_SLOTS: |
|
59 | public Q_SLOTS: | |
61 | void handleUpdated(); |
|
60 | void handleUpdated(); | |
62 |
|
61 | |||
63 | private: |
|
62 | private: | |
64 | void createPoints(int count); |
|
63 | void createPoints(int count); | |
65 | void deletePoints(int count); |
|
64 | void deletePoints(int count); | |
66 |
|
65 | |||
67 | protected: |
|
66 | protected: | |
68 | void updateGeometry(); |
|
67 | void updateGeometry(); | |
69 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
|||
70 |
|
68 | |||
71 | private: |
|
69 | private: | |
72 | QScatterSeries *m_series; |
|
70 | QScatterSeries *m_series; | |
73 | QGraphicsItemGroup m_items; |
|
71 | QGraphicsItemGroup m_items; | |
74 | bool m_visible; |
|
72 | bool m_visible; | |
75 | int m_shape; |
|
73 | int m_shape; | |
76 | int m_size; |
|
74 | int m_size; | |
77 | QRectF m_rect; |
|
75 | QRectF m_rect; | |
|
76 | QMap<QGraphicsItem *, QPointF> m_markerMap; | |||
78 | }; |
|
77 | }; | |
79 |
|
78 | |||
80 |
|
79 | class CircleMarker: public QGraphicsEllipseItem | ||
81 | class Marker: public QAbstractGraphicsShapeItem |
|
|||
82 | { |
|
80 | { | |
83 |
|
81 | |||
84 | public: |
|
82 | public: | |
85 |
|
83 | CircleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent) : QGraphicsEllipseItem(x,y,w,h,parent), | ||
86 | Marker(QAbstractGraphicsShapeItem *item , ScatterChartItem *parent) : QAbstractGraphicsShapeItem(0) ,m_item(item), m_parent(parent) |
|
84 | m_parent(parent) | |
87 | { |
|
|||
88 | } |
|
|||
89 |
|
||||
90 | ~Marker() |
|
|||
91 | { |
|
|||
92 | delete m_item; |
|
|||
93 | } |
|
|||
94 |
|
||||
95 | void setPoint(const QPointF& point) |
|
|||
96 | { |
|
|||
97 | m_point=point; |
|
|||
98 | } |
|
|||
99 |
|
||||
100 | QPointF point() const |
|
|||
101 | { |
|
|||
102 | return m_point; |
|
|||
103 | } |
|
|||
104 |
|
||||
105 | QPainterPath shape() const |
|
|||
106 | { |
|
|||
107 | return m_item->shape(); |
|
|||
108 | } |
|
|||
109 |
|
||||
110 | QRectF boundingRect() const |
|
|||
111 | { |
|
85 | { | |
112 | return m_item->boundingRect(); |
|
|||
113 | } |
|
86 | } | |
114 |
|
87 | |||
115 | bool contains(const QPointF &point) const |
|
88 | protected: | |
|
89 | void mousePressEvent(QGraphicsSceneMouseEvent *event) | |||
116 | { |
|
90 | { | |
117 | return m_item->contains(point); |
|
91 | m_parent->markerSelected(this); | |
|
92 | QGraphicsEllipseItem::mousePressEvent(event); | |||
118 | } |
|
93 | } | |
119 |
|
94 | |||
120 | void setPen(const QPen &pen) |
|
95 | private: | |
121 | { |
|
96 | ScatterChartItem* m_parent; | |
122 | m_item->setPen(pen); |
|
97 | }; | |
123 | } |
|
|||
124 |
|
98 | |||
125 | void setBrush(const QBrush &brush) |
|
99 | class RectangleMarker: public QGraphicsRectItem | |
126 | { |
|
100 | { | |
127 | m_item->setBrush(brush); |
|
|||
128 | } |
|
|||
129 |
|
101 | |||
130 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
102 | public: | |
|
103 | RectangleMarker(qreal x, qreal y, qreal w, qreal h, ScatterChartItem *parent) : QGraphicsRectItem(x,y,w,h,parent), | |||
|
104 | m_parent(parent) | |||
131 | { |
|
105 | { | |
132 | m_item->paint(painter,option,widget); |
|
|||
133 | } |
|
106 | } | |
134 |
|
107 | |||
135 | protected: |
|
108 | protected: | |
136 |
|
||||
137 | void mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
109 | void mousePressEvent(QGraphicsSceneMouseEvent *event) | |
138 | { |
|
110 | { | |
139 | Q_UNUSED(event) |
|
|||
140 | m_parent->markerSelected(this); |
|
111 | m_parent->markerSelected(this); | |
141 |
Q |
|
112 | QGraphicsRectItem::mousePressEvent(event); | |
142 | } |
|
113 | } | |
143 |
|
114 | |||
144 | private: |
|
115 | private: | |
145 | QAbstractGraphicsShapeItem* m_item; |
|
|||
146 | ScatterChartItem* m_parent; |
|
116 | ScatterChartItem* m_parent; | |
147 | QPointF m_point; |
|
|||
148 | }; |
|
117 | }; | |
149 |
|
118 | |||
150 | QTCOMMERCIALCHART_END_NAMESPACE |
|
119 | QTCOMMERCIALCHART_END_NAMESPACE | |
151 |
|
120 | |||
152 | #endif // SCATTERPRESENTER_H |
|
121 | #endif // SCATTERPRESENTER_H |
General Comments 0
You need to be logged in to leave comments.
Login now