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