##// END OF EJS Templates
Removed key zoom/scroll from QChartView
Tero Ahola -
r958:21d46a2d2e69
parent child
Show More
@@ -1,374 +1,374
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 "themewidget.h"
21 #include "themewidget.h"
22
22
23 #include <QChartView>
23 #include <QChartView>
24 #include <QPieSeries>
24 #include <QPieSeries>
25 #include <QPieSlice>
25 #include <QPieSlice>
26 #include <QBarSeries>
26 #include <QBarSeries>
27 #include <QPercentBarSeries>
27 #include <QPercentBarSeries>
28 #include <QStackedBarSeries>
28 #include <QStackedBarSeries>
29 #include <QBarSet>
29 #include <QBarSet>
30 #include <QLineSeries>
30 #include <QLineSeries>
31 #include <QSplineSeries>
31 #include <QSplineSeries>
32 #include <QScatterSeries>
32 #include <QScatterSeries>
33 #include <QAreaSeries>
33 #include <QAreaSeries>
34 #include <QLegend>
34 #include <QLegend>
35 #include <QGridLayout>
35 #include <QGridLayout>
36 #include <QFormLayout>
36 #include <QFormLayout>
37 #include <QComboBox>
37 #include <QComboBox>
38 #include <QSpinBox>
38 #include <QSpinBox>
39 #include <QCheckBox>
39 #include <QCheckBox>
40 #include <QGroupBox>
40 #include <QGroupBox>
41 #include <QLabel>
41 #include <QLabel>
42 #include <QTime>
42 #include <QTime>
43
43
44 ThemeWidget::ThemeWidget(QWidget* parent) :
44 ThemeWidget::ThemeWidget(QWidget* parent) :
45 QWidget(parent),
45 QWidget(parent),
46 m_listCount(3),
46 m_listCount(3),
47 m_valueMax(10),
47 m_valueMax(10),
48 m_valueCount(7),
48 m_valueCount(7),
49 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
49 m_dataTable(generateRandomData(m_listCount,m_valueMax,m_valueCount)),
50 m_themeComboBox(createThemeBox()),
50 m_themeComboBox(createThemeBox()),
51 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
51 m_antialiasCheckBox(new QCheckBox("Anti-aliasing")),
52 m_animatedComboBox(createAnimationBox()),
52 m_animatedComboBox(createAnimationBox()),
53 m_legendComboBox(createLegendBox())
53 m_legendComboBox(createLegendBox())
54 {
54 {
55 connectSignals();
55 connectSignals();
56 // create layout
56 // create layout
57 QGridLayout* baseLayout = new QGridLayout();
57 QGridLayout* baseLayout = new QGridLayout();
58 QHBoxLayout *settingsLayout = new QHBoxLayout();
58 QHBoxLayout *settingsLayout = new QHBoxLayout();
59 settingsLayout->addWidget(new QLabel("Theme:"));
59 settingsLayout->addWidget(new QLabel("Theme:"));
60 settingsLayout->addWidget(m_themeComboBox);
60 settingsLayout->addWidget(m_themeComboBox);
61 settingsLayout->addWidget(new QLabel("Animation:"));
61 settingsLayout->addWidget(new QLabel("Animation:"));
62 settingsLayout->addWidget(m_animatedComboBox);
62 settingsLayout->addWidget(m_animatedComboBox);
63 settingsLayout->addWidget(new QLabel("Legend:"));
63 settingsLayout->addWidget(new QLabel("Legend:"));
64 settingsLayout->addWidget(m_legendComboBox);
64 settingsLayout->addWidget(m_legendComboBox);
65 settingsLayout->addWidget(m_antialiasCheckBox);
65 settingsLayout->addWidget(m_antialiasCheckBox);
66 settingsLayout->addStretch();
66 settingsLayout->addStretch();
67 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
67 baseLayout->addLayout(settingsLayout, 0, 0, 1, 3);
68
68
69 //create charts
69 //create charts
70
70
71 QChartView *chartView;
71 QChartView *chartView;
72
72
73 chartView = new QChartView(createAreaChart());
73 chartView = new QChartView(createAreaChart());
74 baseLayout->addWidget(chartView, 1, 0);
74 baseLayout->addWidget(chartView, 1, 0);
75 m_charts << chartView;
75 m_charts << chartView;
76
76
77 chartView = new QChartView(createBarChart(m_valueCount));
77 chartView = new QChartView(createBarChart(m_valueCount));
78 baseLayout->addWidget(chartView, 1, 1);
78 baseLayout->addWidget(chartView, 1, 1);
79 m_charts << chartView;
79 m_charts << chartView;
80
80
81 chartView = new QChartView(createLineChart());
81 chartView = new QChartView(createLineChart());
82 baseLayout->addWidget(chartView, 1, 2);
82 baseLayout->addWidget(chartView, 1, 2);
83 m_charts << chartView;
83 m_charts << chartView;
84
84
85 chartView = new QChartView(createPieChart());
85 chartView = new QChartView(createPieChart());
86 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
86 chartView->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored); // funny things happen if the pie slice labels no not fit the screen...
87 baseLayout->addWidget(chartView, 2, 0);
87 baseLayout->addWidget(chartView, 2, 0);
88 m_charts << chartView;
88 m_charts << chartView;
89
89
90 chartView = new QChartView(createSplineChart());
90 chartView = new QChartView(createSplineChart());
91 baseLayout->addWidget(chartView, 2, 1);
91 baseLayout->addWidget(chartView, 2, 1);
92 m_charts << chartView;
92 m_charts << chartView;
93
93
94 chartView = new QChartView(createScatterChart());
94 chartView = new QChartView(createScatterChart());
95 baseLayout->addWidget(chartView, 2, 2);
95 baseLayout->addWidget(chartView, 2, 2);
96 m_charts << chartView;
96 m_charts << chartView;
97
97
98 setLayout(baseLayout);
98 setLayout(baseLayout);
99
99
100 // Set defaults
100 // Set defaults
101 m_antialiasCheckBox->setChecked(true);
101 m_antialiasCheckBox->setChecked(true);
102 updateUI();
102 updateUI();
103 }
103 }
104
104
105 ThemeWidget::~ThemeWidget()
105 ThemeWidget::~ThemeWidget()
106 {
106 {
107 }
107 }
108
108
109 void ThemeWidget::connectSignals()
109 void ThemeWidget::connectSignals()
110 {
110 {
111 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
111 connect(m_themeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
112 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
112 connect(m_antialiasCheckBox, SIGNAL(toggled(bool)), this, SLOT(updateUI()));
113 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
113 connect(m_animatedComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
114 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
114 connect(m_legendComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateUI()));
115 }
115 }
116
116
117 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
117 DataTable ThemeWidget::generateRandomData(int listCount,int valueMax,int valueCount) const
118 {
118 {
119 DataTable dataTable;
119 DataTable dataTable;
120
120
121 // set seed for random stuff
121 // set seed for random stuff
122 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
122 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
123
123
124 // generate random data
124 // generate random data
125 for (int i(0); i < listCount; i++) {
125 for (int i(0); i < listCount; i++) {
126 DataList dataList;
126 DataList dataList;
127 qreal yValue(0);
127 qreal yValue(0);
128 for (int j(0); j < valueCount; j++) {
128 for (int j(0); j < valueCount; j++) {
129 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
129 yValue = yValue + (qreal) (qrand() % valueMax) / (qreal) valueCount;
130 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
130 QPointF value((j + (qreal) rand() / (qreal) RAND_MAX) * ((qreal) m_valueMax / (qreal) valueCount),
131 yValue);
131 yValue);
132 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
132 QString label = "Slice " + QString::number(i) + ":" + QString::number(j);
133 dataList << Data(value, label);
133 dataList << Data(value, label);
134 }
134 }
135 dataTable << dataList;
135 dataTable << dataList;
136 }
136 }
137
137
138 return dataTable;
138 return dataTable;
139 }
139 }
140
140
141 QComboBox* ThemeWidget::createThemeBox() const
141 QComboBox* ThemeWidget::createThemeBox() const
142 {
142 {
143 // settings layout
143 // settings layout
144 QComboBox* themeComboBox = new QComboBox();
144 QComboBox* themeComboBox = new QComboBox();
145 themeComboBox->addItem("Light", QChart::ChartThemeLight);
145 themeComboBox->addItem("Light", QChart::ChartThemeLight);
146 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
146 themeComboBox->addItem("Blue Cerulean", QChart::ChartThemeBlueCerulean);
147 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
147 themeComboBox->addItem("Dark", QChart::ChartThemeDark);
148 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
148 themeComboBox->addItem("Brown Sand", QChart::ChartThemeBrownSand);
149 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
149 themeComboBox->addItem("Blue NCS", QChart::ChartThemeBlueNcs);
150 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
150 themeComboBox->addItem("High Contrast", QChart::ChartThemeHighContrast);
151 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
151 themeComboBox->addItem("Blue Icy", QChart::ChartThemeBlueIcy);
152 return themeComboBox;
152 return themeComboBox;
153 }
153 }
154
154
155 QComboBox* ThemeWidget::createAnimationBox() const
155 QComboBox* ThemeWidget::createAnimationBox() const
156 {
156 {
157 // settings layout
157 // settings layout
158 QComboBox* animationComboBox = new QComboBox();
158 QComboBox* animationComboBox = new QComboBox();
159 animationComboBox->addItem("No Animations", QChart::NoAnimation);
159 animationComboBox->addItem("No Animations", QChart::NoAnimation);
160 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
160 animationComboBox->addItem("GridAxis Animations", QChart::GridAxisAnimations);
161 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
161 animationComboBox->addItem("Series Animations", QChart::SeriesAnimations);
162 animationComboBox->addItem("All Animations", QChart::AllAnimations);
162 animationComboBox->addItem("All Animations", QChart::AllAnimations);
163 return animationComboBox;
163 return animationComboBox;
164 }
164 }
165
165
166 QComboBox* ThemeWidget::createLegendBox() const
166 QComboBox* ThemeWidget::createLegendBox() const
167 {
167 {
168 QComboBox* legendComboBox = new QComboBox();
168 QComboBox* legendComboBox = new QComboBox();
169 legendComboBox->addItem("No Legend ", 0);
169 legendComboBox->addItem("No Legend ", 0);
170 legendComboBox->addItem("Legend Top", QLegend::AlignmentTop);
170 legendComboBox->addItem("Legend Top", QLegend::AlignmentTop);
171 legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom);
171 legendComboBox->addItem("Legend Bottom", QLegend::AlignmentBottom);
172 legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft);
172 legendComboBox->addItem("Legend Left", QLegend::AlignmentLeft);
173 legendComboBox->addItem("Legend Right", QLegend::AlignmentRight);
173 legendComboBox->addItem("Legend Right", QLegend::AlignmentRight);
174 return legendComboBox;
174 return legendComboBox;
175 }
175 }
176
176
177 QChart* ThemeWidget::createAreaChart() const
177 QChart* ThemeWidget::createAreaChart() const
178 {
178 {
179 // area chart
180 QChart *chart = new QChart();
179 QChart *chart = new QChart();
181 chart->axisX()->setNiceNumbers(true);
180 chart->axisX()->setNiceNumbers(true);
182 chart->axisY()->setNiceNumbers(true);
181 chart->axisY()->setNiceNumbers(true);
183 chart->setTitle("Area chart");
182 chart->setTitle("Area chart");
184 QString name("Series ");
185 int nameIndex = 0;
186
183
187 // The lower series initialized to zero values
184 // The lower series initialized to zero values
188 QLineSeries *lowerSeries = 0;
185 QLineSeries *lowerSeries = 0;
186 QString name("Series ");
187 int nameIndex = 0;
189 for (int i(0); i < m_dataTable.count(); i++) {
188 for (int i(0); i < m_dataTable.count(); i++) {
190 QLineSeries *upperSeries = new QLineSeries(chart);
189 QLineSeries *upperSeries = new QLineSeries(chart);
191 for (int j(0); j < m_dataTable[i].count(); j++) {
190 for (int j(0); j < m_dataTable[i].count(); j++) {
192 Data data = m_dataTable[i].at(j);
191 Data data = m_dataTable[i].at(j);
193 if (lowerSeries)
192 if (lowerSeries)
194 upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y()));
193 upperSeries->append(QPointF(j, lowerSeries->y(i) + data.first.y()));
195 else
194 else
196 upperSeries->append(QPointF(j, data.first.y()));
195 upperSeries->append(QPointF(j, data.first.y()));
197 }
196 }
198 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
197 QAreaSeries *area = new QAreaSeries(upperSeries, lowerSeries);
199 area->setName(name + QString::number(nameIndex));
198 area->setName(name + QString::number(nameIndex));
200 nameIndex++;
199 nameIndex++;
201 chart->addSeries(area);
200 chart->addSeries(area);
202 lowerSeries = upperSeries;
201 lowerSeries = upperSeries;
203 }
202 }
203
204 return chart;
204 return chart;
205 }
205 }
206
206
207 QChart* ThemeWidget::createBarChart(int valueCount) const
207 QChart* ThemeWidget::createBarChart(int valueCount) const
208 {
208 {
209 // bar chart
210 QChart* chart = new QChart();
209 QChart* chart = new QChart();
211 chart->axisX()->setNiceNumbers(true);
210 chart->axisX()->setNiceNumbers(true);
212 chart->axisY()->setNiceNumbers(true);
211 chart->axisY()->setNiceNumbers(true);
213 chart->setTitle("Bar chart");
212 chart->setTitle("Bar chart");
213
214 QBarCategories categories;
214 QBarCategories categories;
215 // TODO: categories
216 for (int i(0); i < valueCount; i++)
215 for (int i(0); i < valueCount; i++)
217 categories << QString::number(i);
216 categories << QString::number(i);
218 // QBarSeries* series = new QBarSeries(categories, chart);
217
219 // QPercentBarSeries* series = new QPercentBarSeries(categories, chart);
220 QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
218 QStackedBarSeries* series = new QStackedBarSeries(categories, chart);
221 for (int i(0); i < m_dataTable.count(); i++) {
219 for (int i(0); i < m_dataTable.count(); i++) {
222 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
220 QBarSet *set = new QBarSet("Bar set " + QString::number(i));
223 foreach (Data data, m_dataTable[i])
221 foreach (Data data, m_dataTable[i])
224 *set << data.first.y();
222 *set << data.first.y();
225 series->appendBarSet(set);
223 series->appendBarSet(set);
226 }
224 }
227 chart->addSeries(series);
225 chart->addSeries(series);
226
228 return chart;
227 return chart;
229 }
228 }
230
229
231 QChart* ThemeWidget::createLineChart() const
230 QChart* ThemeWidget::createLineChart() const
232 {
231 {
233 // line chart
234 QChart* chart = new QChart();
232 QChart* chart = new QChart();
235 chart->axisX()->setNiceNumbers(true);
233 chart->axisX()->setNiceNumbers(true);
236 chart->axisY()->setNiceNumbers(true);
234 chart->axisY()->setNiceNumbers(true);
237 chart->setTitle("Line chart");
235 chart->setTitle("Line chart");
236
238 QString name("Series ");
237 QString name("Series ");
239 int nameIndex = 0;
238 int nameIndex = 0;
240 foreach (DataList list, m_dataTable) {
239 foreach (DataList list, m_dataTable) {
241 QLineSeries *series = new QLineSeries(chart);
240 QLineSeries *series = new QLineSeries(chart);
242 foreach (Data data, list)
241 foreach (Data data, list)
243 series->append(data.first);
242 series->append(data.first);
244 series->setName(name + QString::number(nameIndex));
243 series->setName(name + QString::number(nameIndex));
245 nameIndex++;
244 nameIndex++;
246 chart->addSeries(series);
245 chart->addSeries(series);
247 }
246 }
247
248 return chart;
248 return chart;
249 }
249 }
250
250
251 QChart* ThemeWidget::createPieChart() const
251 QChart* ThemeWidget::createPieChart() const
252 {
252 {
253 // pie chart
254 QChart* chart = new QChart();
253 QChart* chart = new QChart();
255 chart->setTitle("Pie chart");
254 chart->setTitle("Pie chart");
255
256 qreal pieSize = 1.0 / m_dataTable.count();
256 qreal pieSize = 1.0 / m_dataTable.count();
257 for (int i = 0; i < m_dataTable.count(); i++) {
257 for (int i = 0; i < m_dataTable.count(); i++) {
258 QPieSeries *series = new QPieSeries(chart);
258 QPieSeries *series = new QPieSeries(chart);
259 foreach (Data data, m_dataTable[i]) {
259 foreach (Data data, m_dataTable[i]) {
260 QPieSlice *slice = series->append(data.first.y(), data.second);
260 QPieSlice *slice = series->append(data.first.y(), data.second);
261 if (data == m_dataTable[i].first()) {
261 if (data == m_dataTable[i].first()) {
262 slice->setLabelVisible();
262 slice->setLabelVisible();
263 slice->setExploded();
263 slice->setExploded();
264 }
264 }
265 }
265 }
266 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
266 qreal hPos = (pieSize / 2) + (i / (qreal) m_dataTable.count());
267 series->setPieSize(pieSize);
267 series->setPieSize(pieSize);
268 series->setHorizontalPosition(hPos);
268 series->setHorizontalPosition(hPos);
269 series->setVerticalPosition(0.5);
269 series->setVerticalPosition(0.5);
270 chart->addSeries(series);
270 chart->addSeries(series);
271 }
271 }
272
272
273 return chart;
273 return chart;
274 }
274 }
275
275
276 QChart* ThemeWidget::createSplineChart() const
276 QChart* ThemeWidget::createSplineChart() const
277 { // spine chart
277 { // spine chart
278 QChart* chart = new QChart();
278 QChart* chart = new QChart();
279 chart->axisX()->setNiceNumbers(true);
279 chart->axisX()->setNiceNumbers(true);
280 chart->axisY()->setNiceNumbers(true);
280 chart->axisY()->setNiceNumbers(true);
281 chart->setTitle("Spline chart");
281 chart->setTitle("Spline chart");
282 QString name("Series ");
282 QString name("Series ");
283 int nameIndex = 0;
283 int nameIndex = 0;
284 foreach (DataList list, m_dataTable) {
284 foreach (DataList list, m_dataTable) {
285 QSplineSeries *series = new QSplineSeries(chart);
285 QSplineSeries *series = new QSplineSeries(chart);
286 foreach (Data data, list)
286 foreach (Data data, list)
287 series->append(data.first);
287 series->append(data.first);
288 series->setName(name + QString::number(nameIndex));
288 series->setName(name + QString::number(nameIndex));
289 nameIndex++;
289 nameIndex++;
290 chart->addSeries(series);
290 chart->addSeries(series);
291 }
291 }
292 return chart;
292 return chart;
293 }
293 }
294
294
295 QChart* ThemeWidget::createScatterChart() const
295 QChart* ThemeWidget::createScatterChart() const
296 { // scatter chart
296 { // scatter chart
297 QChart* chart = new QChart();
297 QChart* chart = new QChart();
298 chart->axisX()->setNiceNumbers(true);
298 chart->axisX()->setNiceNumbers(true);
299 chart->axisY()->setNiceNumbers(true);
299 chart->axisY()->setNiceNumbers(true);
300 chart->setTitle("Scatter chart");
300 chart->setTitle("Scatter chart");
301 QString name("Series ");
301 QString name("Series ");
302 int nameIndex = 0;
302 int nameIndex = 0;
303 foreach (DataList list, m_dataTable) {
303 foreach (DataList list, m_dataTable) {
304 QScatterSeries *series = new QScatterSeries(chart);
304 QScatterSeries *series = new QScatterSeries(chart);
305 foreach (Data data, list)
305 foreach (Data data, list)
306 series->append(data.first);
306 series->append(data.first);
307 series->setName(name + QString::number(nameIndex));
307 series->setName(name + QString::number(nameIndex));
308 nameIndex++;
308 nameIndex++;
309 chart->addSeries(series);
309 chart->addSeries(series);
310 }
310 }
311 return chart;
311 return chart;
312 }
312 }
313
313
314 void ThemeWidget::updateUI()
314 void ThemeWidget::updateUI()
315 {
315 {
316 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
316 QChart::ChartTheme theme = (QChart::ChartTheme) m_themeComboBox->itemData(m_themeComboBox->currentIndex()).toInt();
317
317
318 if (m_charts.at(0)->chart()->theme() != theme) {
318 if (m_charts.at(0)->chart()->theme() != theme) {
319 foreach (QChartView *chartView, m_charts)
319 foreach (QChartView *chartView, m_charts)
320 chartView->chart()->setTheme(theme);
320 chartView->chart()->setTheme(theme);
321
321
322 QPalette pal = window()->palette();
322 QPalette pal = window()->palette();
323 if (theme == QChart::ChartThemeLight) {
323 if (theme == QChart::ChartThemeLight) {
324 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
324 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
325 pal.setColor(QPalette::WindowText, QRgb(0x404044));
325 pal.setColor(QPalette::WindowText, QRgb(0x404044));
326 } else if (theme == QChart::ChartThemeDark) {
326 } else if (theme == QChart::ChartThemeDark) {
327 pal.setColor(QPalette::Window, QRgb(0x121218));
327 pal.setColor(QPalette::Window, QRgb(0x121218));
328 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
328 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
329 } else if (theme == QChart::ChartThemeBlueCerulean) {
329 } else if (theme == QChart::ChartThemeBlueCerulean) {
330 pal.setColor(QPalette::Window, QRgb(0x40434a));
330 pal.setColor(QPalette::Window, QRgb(0x40434a));
331 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
331 pal.setColor(QPalette::WindowText, QRgb(0xd6d6d6));
332 } else if (theme == QChart::ChartThemeBrownSand) {
332 } else if (theme == QChart::ChartThemeBrownSand) {
333 pal.setColor(QPalette::Window, QRgb(0x9e8965));
333 pal.setColor(QPalette::Window, QRgb(0x9e8965));
334 pal.setColor(QPalette::WindowText, QRgb(0x404044));
334 pal.setColor(QPalette::WindowText, QRgb(0x404044));
335 } else if (theme == QChart::ChartThemeBlueNcs) {
335 } else if (theme == QChart::ChartThemeBlueNcs) {
336 pal.setColor(QPalette::Window, QRgb(0x018bba));
336 pal.setColor(QPalette::Window, QRgb(0x018bba));
337 pal.setColor(QPalette::WindowText, QRgb(0x404044));
337 pal.setColor(QPalette::WindowText, QRgb(0x404044));
338 } else if (theme == QChart::ChartThemeHighContrast) {
338 } else if (theme == QChart::ChartThemeHighContrast) {
339 pal.setColor(QPalette::Window, QRgb(0xffab03));
339 pal.setColor(QPalette::Window, QRgb(0xffab03));
340 pal.setColor(QPalette::WindowText, QRgb(0x181818));
340 pal.setColor(QPalette::WindowText, QRgb(0x181818));
341 } else if (theme == QChart::ChartThemeBlueIcy) {
341 } else if (theme == QChart::ChartThemeBlueIcy) {
342 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
342 pal.setColor(QPalette::Window, QRgb(0xcee7f0));
343 pal.setColor(QPalette::WindowText, QRgb(0x404044));
343 pal.setColor(QPalette::WindowText, QRgb(0x404044));
344 } else {
344 } else {
345 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
345 pal.setColor(QPalette::Window, QRgb(0xf0f0f0));
346 pal.setColor(QPalette::WindowText, QRgb(0x404044));
346 pal.setColor(QPalette::WindowText, QRgb(0x404044));
347 }
347 }
348 window()->setPalette(pal);
348 window()->setPalette(pal);
349 }
349 }
350
350
351 bool checked = m_antialiasCheckBox->isChecked();
351 bool checked = m_antialiasCheckBox->isChecked();
352 foreach (QChartView *chart, m_charts)
352 foreach (QChartView *chart, m_charts)
353 chart->setRenderHint(QPainter::Antialiasing, checked);
353 chart->setRenderHint(QPainter::Antialiasing, checked);
354
354
355 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
355 QChart::AnimationOptions options(m_animatedComboBox->itemData(m_animatedComboBox->currentIndex()).toInt());
356 if (m_charts.at(0)->chart()->animationOptions() != options) {
356 if (m_charts.at(0)->chart()->animationOptions() != options) {
357 foreach (QChartView *chartView, m_charts)
357 foreach (QChartView *chartView, m_charts)
358 chartView->chart()->setAnimationOptions(options);
358 chartView->chart()->setAnimationOptions(options);
359 }
359 }
360
360
361 QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
361 QLegend::Alignments alignment(m_legendComboBox->itemData(m_legendComboBox->currentIndex()).toInt());
362
362
363 if (!alignment) {
363 if (!alignment) {
364 foreach (QChartView *chartView, m_charts) {
364 foreach (QChartView *chartView, m_charts) {
365 chartView->chart()->legend()->hide();
365 chartView->chart()->legend()->hide();
366 }
366 }
367 }
367 } else {
368 else
369 foreach (QChartView *chartView, m_charts) {
368 foreach (QChartView *chartView, m_charts) {
370 chartView->chart()->legend()->setAlignment(alignment);
369 chartView->chart()->legend()->setAlignment(alignment);
371 chartView->chart()->legend()->show();
370 chartView->chart()->legend()->show();
372 }
371 }
373 }
372 }
373 }
374
374
@@ -1,250 +1,219
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 "qchartview.h"
21 #include "qchartview.h"
22 #include "qchart_p.h"
22 #include "qchart_p.h"
23 #include "qchartview_p.h"
23 #include "qchartview_p.h"
24 #include <QGraphicsScene>
24 #include <QGraphicsScene>
25 #include <QRubberBand>
25 #include <QRubberBand>
26
26
27
27
28 /*!
28 /*!
29 \enum QChartView::RubberBand
29 \enum QChartView::RubberBand
30
30
31 This enum describes the different types of rubber bands that can be used for zoom rect selection
31 This enum describes the different types of rubber bands that can be used for zoom rect selection
32
32
33 \value NoRubberBand
33 \value NoRubberBand
34 \value VerticalRubberBand
34 \value VerticalRubberBand
35 \value HorizonalRubberBand
35 \value HorizonalRubberBand
36 \value RectangleRubberBand
36 \value RectangleRubberBand
37 */
37 */
38
38
39 /*!
39 /*!
40 \class QChartView
40 \class QChartView
41 \brief Standalone charting widget.
41 \brief Standalone charting widget.
42
42
43 QChartView is a standalone widget that can display charts. It does not require separate
43 QChartView is a standalone widget that can display charts. It does not require separate
44 QGraphicsScene to work. It manages the graphical representation of different types of
44 QGraphicsScene to work. It manages the graphical representation of different types of
45 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
45 QChartSeries and other chart related objects like QChartAxis and QChartLegend. If you want to
46 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
46 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
47
47
48 \sa QChart
48 \sa QChart
49 */
49 */
50
50
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51 QTCOMMERCIALCHART_BEGIN_NAMESPACE
52
52
53 /*!
53 /*!
54 Constructs a chartView object which is a child of a\a parent.
54 Constructs a chartView object which is a child of a\a parent.
55 */
55 */
56 QChartView::QChartView(QChart *chart,QWidget *parent) :
56 QChartView::QChartView(QChart *chart,QWidget *parent) :
57 QGraphicsView(parent),
57 QGraphicsView(parent),
58 d_ptr(new QChartViewPrivate())
58 d_ptr(new QChartViewPrivate())
59 {
59 {
60 Q_ASSERT(chart);
60 Q_ASSERT(chart);
61 d_ptr->m_scene = new QGraphicsScene(this);
61 d_ptr->m_scene = new QGraphicsScene(this);
62 d_ptr->m_chart = chart;
62 d_ptr->m_chart = chart;
63 setFrameShape(QFrame::NoFrame);
63 setFrameShape(QFrame::NoFrame);
64 setBackgroundRole(QPalette::Window);
64 setBackgroundRole(QPalette::Window);
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
66 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
67 setScene(d_ptr->m_scene);
67 setScene(d_ptr->m_scene);
68 d_ptr->m_scene->addItem(chart);
68 d_ptr->m_scene->addItem(chart);
69 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
69 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
70 }
70 }
71
71
72
72
73 /*!
73 /*!
74 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
74 Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
75 */
75 */
76 QChartView::~QChartView()
76 QChartView::~QChartView()
77 {
77 {
78 }
78 }
79
79
80 /*!
80 /*!
81 Returns the pointer to the associated chart
81 Returns the pointer to the associated chart
82 */
82 */
83 QChart* QChartView::chart() const
83 QChart* QChartView::chart() const
84 {
84 {
85 return d_ptr->m_chart;
85 return d_ptr->m_chart;
86 }
86 }
87
87
88 /*!
88 /*!
89 Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
89 Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
90 */
90 */
91 void QChartView::setRubberBand(const RubberBands& rubberBand)
91 void QChartView::setRubberBand(const RubberBands& rubberBand)
92 {
92 {
93 d_ptr->m_rubberBandFlags=rubberBand;
93 d_ptr->m_rubberBandFlags=rubberBand;
94
94
95 if (!d_ptr->m_rubberBandFlags) {
95 if (!d_ptr->m_rubberBandFlags) {
96 delete d_ptr->m_rubberBand;
96 delete d_ptr->m_rubberBand;
97 d_ptr->m_rubberBand=0;
97 d_ptr->m_rubberBand=0;
98 return;
98 return;
99 }
99 }
100
100
101 if (!d_ptr->m_rubberBand) {
101 if (!d_ptr->m_rubberBand) {
102 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
102 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
103 d_ptr->m_rubberBand->setEnabled(true);
103 d_ptr->m_rubberBand->setEnabled(true);
104 }
104 }
105 }
105 }
106
106
107 /*!
107 /*!
108 Returns the RubberBandPolicy that is currently being used by the widget.
108 Returns the RubberBandPolicy that is currently being used by the widget.
109 */
109 */
110 QChartView::RubberBands QChartView::rubberBand() const
110 QChartView::RubberBands QChartView::rubberBand() const
111 {
111 {
112 return d_ptr->m_rubberBandFlags;
112 return d_ptr->m_rubberBandFlags;
113 }
113 }
114
114
115 /*!
115 /*!
116 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
116 If Left mouse button is pressed and the RubberBandPolicy is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area.
117 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
117 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
118 */
118 */
119 void QChartView::mousePressEvent(QMouseEvent *event)
119 void QChartView::mousePressEvent(QMouseEvent *event)
120 {
120 {
121 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
121 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
122
122
123 int padding = d_ptr->m_chart->margins().top();
123 int padding = d_ptr->m_chart->margins().top();
124 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
124 QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding);
125
125
126 if (rect.contains(event->pos())) {
126 if (rect.contains(event->pos())) {
127 d_ptr->m_rubberBandOrigin = event->pos();
127 d_ptr->m_rubberBandOrigin = event->pos();
128 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
128 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
129 d_ptr->m_rubberBand->show();
129 d_ptr->m_rubberBand->show();
130 event->accept();
130 event->accept();
131 }
131 }
132 }
132 }
133 else {
133 else {
134 QGraphicsView::mousePressEvent(event);
134 QGraphicsView::mousePressEvent(event);
135 }
135 }
136 }
136 }
137
137
138 /*!
138 /*!
139 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
139 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
140 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
140 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
141 */
141 */
142 void QChartView::mouseMoveEvent(QMouseEvent *event)
142 void QChartView::mouseMoveEvent(QMouseEvent *event)
143 {
143 {
144 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
144 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
145 QRectF margins = d_ptr->m_chart->margins();
145 QRectF margins = d_ptr->m_chart->margins();
146 QRectF geometry = d_ptr->m_chart->geometry();
146 QRectF geometry = d_ptr->m_chart->geometry();
147 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
147 QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom());
148 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
148 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
149 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
149 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
150 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
150 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
151 d_ptr->m_rubberBandOrigin.setY(rect.top());
151 d_ptr->m_rubberBandOrigin.setY(rect.top());
152 height = rect.height();
152 height = rect.height();
153 }
153 }
154 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
154 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
155 d_ptr->m_rubberBandOrigin.setX(rect.left());
155 d_ptr->m_rubberBandOrigin.setX(rect.left());
156 width= rect.width();
156 width= rect.width();
157 }
157 }
158 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
158 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
159 }
159 }
160 else {
160 else {
161 QGraphicsView::mouseMoveEvent(event);
161 QGraphicsView::mouseMoveEvent(event);
162 }
162 }
163 }
163 }
164
164
165 /*!
165 /*!
166 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
166 If left mouse button is release and RubberBand is enabled then \a event is accepted and the view is zoomed in to rect specified by RubberBand
167 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
167 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
168 */
168 */
169 void QChartView::mouseReleaseEvent(QMouseEvent *event)
169 void QChartView::mouseReleaseEvent(QMouseEvent *event)
170 {
170 {
171 if(d_ptr->m_rubberBand) {
171 if(d_ptr->m_rubberBand) {
172 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
172 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
173 d_ptr->m_rubberBand->hide();
173 d_ptr->m_rubberBand->hide();
174 QRect rect = d_ptr->m_rubberBand->geometry();
174 QRect rect = d_ptr->m_rubberBand->geometry();
175 d_ptr->m_chart->zoomIn(rect);
175 d_ptr->m_chart->zoomIn(rect);
176 event->accept();
176 event->accept();
177 }
177 }
178
178
179 if(event->button()==Qt::RightButton){
179 if(event->button()==Qt::RightButton){
180 d_ptr->m_chart->zoomOut();
180 d_ptr->m_chart->zoomOut();
181 event->accept();
181 event->accept();
182 }
182 }
183 }
183 }
184 else {
184 else {
185 QGraphicsView::mouseReleaseEvent(event);
185 QGraphicsView::mouseReleaseEvent(event);
186 }
186 }
187 }
187 }
188
188
189 /*!
189 /*!
190 Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
191 In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
192 */
193 void QChartView::keyPressEvent(QKeyEvent *event)
194 {
195 switch (event->key()) {
196 case Qt::Key_Plus:
197 d_ptr->m_chart->zoomIn();
198 break;
199 case Qt::Key_Minus:
200 d_ptr->m_chart->zoomOut();
201 break;
202 case Qt::Key_Left:
203 d_ptr->m_chart->scrollLeft();
204 break;
205 case Qt::Key_Right:
206 d_ptr->m_chart->scrollRight();
207 break;
208 case Qt::Key_Up:
209 d_ptr->m_chart->scrollUp();
210 break;
211 case Qt::Key_Down:
212 d_ptr->m_chart->scrollDown();
213 break;
214 default:
215 QGraphicsView::keyPressEvent(event);
216 break;
217 }
218 }
219
220 /*!
221 Resizes and updates the chart area using the \a event data
190 Resizes and updates the chart area using the \a event data
222 */
191 */
223 void QChartView::resizeEvent(QResizeEvent *event)
192 void QChartView::resizeEvent(QResizeEvent *event)
224 {
193 {
225 QGraphicsView::resizeEvent(event);
194 QGraphicsView::resizeEvent(event);
226 d_ptr->m_chart->resize(size());
195 d_ptr->m_chart->resize(size());
227 setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
196 setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
228 setSceneRect(d_ptr->m_chart->geometry());
197 setSceneRect(d_ptr->m_chart->geometry());
229 }
198 }
230
199
231 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
232
201
233 QChartViewPrivate::QChartViewPrivate():
202 QChartViewPrivate::QChartViewPrivate():
234 m_scene(0),
203 m_scene(0),
235 m_chart(0),
204 m_chart(0),
236 m_presenter(0),
205 m_presenter(0),
237 m_rubberBand(0),
206 m_rubberBand(0),
238 m_rubberBandFlags(QChartView::NoRubberBand)
207 m_rubberBandFlags(QChartView::NoRubberBand)
239 {
208 {
240
209
241 }
210 }
242
211
243 QChartViewPrivate::~QChartViewPrivate()
212 QChartViewPrivate::~QChartViewPrivate()
244 {
213 {
245
214
246 }
215 }
247
216
248 #include "moc_qchartview.cpp"
217 #include "moc_qchartview.cpp"
249
218
250 QTCOMMERCIALCHART_END_NAMESPACE
219 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,72 +1,71
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QCHARTVIEW_H
21 #ifndef QCHARTVIEW_H
22 #define QCHARTVIEW_H
22 #define QCHARTVIEW_H
23
23
24 #include <QChartAxis>
24 #include <QChartAxis>
25 #include <QSeries>
25 #include <QSeries>
26 #include <QChart>
26 #include <QChart>
27 #include <QGraphicsView>
27 #include <QGraphicsView>
28
28
29 class QGraphicsScene;
29 class QGraphicsScene;
30 class QRubberBand;
30 class QRubberBand;
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 struct QChartViewPrivate;
34 struct QChartViewPrivate;
35
35
36 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
36 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
37 {
37 {
38 Q_OBJECT
38 Q_OBJECT
39
39
40 public:
40 public:
41
41
42 enum RubberBand{
42 enum RubberBand{
43 NoRubberBand = 0x0,
43 NoRubberBand = 0x0,
44 VerticalRubberBand = 0x1,
44 VerticalRubberBand = 0x1,
45 HorizonalRubberBand = 0x2,
45 HorizonalRubberBand = 0x2,
46 RectangleRubberBand = 0x3
46 RectangleRubberBand = 0x3
47 };
47 };
48
48
49 Q_DECLARE_FLAGS(RubberBands, RubberBand)
49 Q_DECLARE_FLAGS(RubberBands, RubberBand)
50
50
51 explicit QChartView(QChart *chart,QWidget *parent = 0);
51 explicit QChartView(QChart *chart,QWidget *parent = 0);
52 ~QChartView();
52 ~QChartView();
53
53
54 void setRubberBand(const RubberBands& rubberBands);
54 void setRubberBand(const RubberBands& rubberBands);
55 RubberBands rubberBand() const;
55 RubberBands rubberBand() const;
56 QChart* chart() const;
56 QChart* chart() const;
57
57
58 protected:
58 protected:
59 void resizeEvent(QResizeEvent *event);
59 void resizeEvent(QResizeEvent *event);
60 void mousePressEvent(QMouseEvent *event);
60 void mousePressEvent(QMouseEvent *event);
61 void mouseMoveEvent(QMouseEvent *event);
61 void mouseMoveEvent(QMouseEvent *event);
62 void mouseReleaseEvent(QMouseEvent *event);
62 void mouseReleaseEvent(QMouseEvent *event);
63 void keyPressEvent(QKeyEvent *event);
64
63
65 protected:
64 protected:
66 QScopedPointer<QChartViewPrivate> d_ptr;
65 QScopedPointer<QChartViewPrivate> d_ptr;
67 Q_DISABLE_COPY(QChartView)
66 Q_DISABLE_COPY(QChartView)
68 };
67 };
69
68
70 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
71
70
72 #endif // QCHARTWIDGET_H
71 #endif // QCHARTWIDGET_H
General Comments 0
You need to be logged in to leave comments. Login now