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