##// END OF EJS Templates
Fix compilation error...
Miikka Heikkinen -
r2485:b0caebd0eecc
parent child
Show More
@@ -1,111 +1,111
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 "chartview.h"
21 #include "chartview.h"
22 #include <QMouseEvent>
22 #include <QMouseEvent>
23 #include <QDebug>
23 #include <QDebug>
24 #include <QAbstractAxis>
24 #include <QAbstractAxis>
25 #include <QValueAxis>
25 #include <QValueAxis>
26
26
27 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
28
28
29 ChartView::ChartView(QWidget *parent)
29 ChartView::ChartView(QWidget *parent)
30 : QChartView(parent)
30 : QChartView(parent)
31 {
31 {
32 }
32 }
33
33
34 //![1]
34 //![1]
35 void ChartView::keyPressEvent(QKeyEvent *event)
35 void ChartView::keyPressEvent(QKeyEvent *event)
36 {
36 {
37 switch (event->key()) {
37 switch (event->key()) {
38 case Qt::Key_Plus:
38 case Qt::Key_Plus:
39 chart()->zoomIn();
39 chart()->zoomIn();
40 break;
40 break;
41 case Qt::Key_Minus:
41 case Qt::Key_Minus:
42 chart()->zoomOut();
42 chart()->zoomOut();
43 break;
43 break;
44 case Qt::Key_Left:
44 case Qt::Key_Left:
45 chart()->scroll(-1.0, 0);
45 chart()->scroll(-1.0, 0);
46 break;
46 break;
47 case Qt::Key_Right:
47 case Qt::Key_Right:
48 chart()->scroll(1.0, 0);
48 chart()->scroll(1.0, 0);
49 break;
49 break;
50 case Qt::Key_Up:
50 case Qt::Key_Up:
51 chart()->scroll(0, 1.0);
51 chart()->scroll(0, 1.0);
52 break;
52 break;
53 case Qt::Key_Down:
53 case Qt::Key_Down:
54 chart()->scroll(0, -1.0);
54 chart()->scroll(0, -1.0);
55 break;
55 break;
56 case Qt::Key_Space:
56 case Qt::Key_Space:
57 switchChartType();
57 switchChartType();
58 break;
58 break;
59 default:
59 default:
60 QGraphicsView::keyPressEvent(event);
60 QGraphicsView::keyPressEvent(event);
61 break;
61 break;
62 }
62 }
63 }
63 }
64 //![1]
64 //![1]
65
65
66 //![2]
66 //![2]
67 void ChartView::switchChartType()
67 void ChartView::switchChartType()
68 {
68 {
69 QChart *newChart;
69 QChart *newChart;
70 QChart *oldChart = chart();
70 QChart *oldChart = chart();
71
71
72 if (oldChart->chartType() == QChart::ChartTypeCartesian)
72 if (oldChart->chartType() == QChart::ChartTypeCartesian)
73 newChart = new QPolarChart();
73 newChart = new QPolarChart();
74 else
74 else
75 newChart = new QChart();
75 newChart = new QChart();
76
76
77 // Move series and axes from old chart to new one
77 // Move series and axes from old chart to new one
78 QList<QAbstractSeries *> seriesList = oldChart->series();
78 QList<QAbstractSeries *> seriesList = oldChart->series();
79 QList<QAbstractAxis *> axisList = oldChart->axes();
79 QList<QAbstractAxis *> axisList = oldChart->axes();
80 QList<QPair<qreal, qreal>> axisRanges;
80 QList<QPair<qreal, qreal> > axisRanges;
81
81
82 foreach (QAbstractAxis *axis, axisList) {
82 foreach (QAbstractAxis *axis, axisList) {
83 QValueAxis *valueAxis = static_cast<QValueAxis *>(axis);
83 QValueAxis *valueAxis = static_cast<QValueAxis *>(axis);
84 axisRanges.append(QPair<qreal, qreal>(valueAxis->min(), valueAxis->max()));
84 axisRanges.append(QPair<qreal, qreal>(valueAxis->min(), valueAxis->max()));
85 }
85 }
86
86
87 foreach (QAbstractSeries *series, seriesList)
87 foreach (QAbstractSeries *series, seriesList)
88 oldChart->removeSeries(series);
88 oldChart->removeSeries(series);
89
89
90 foreach (QAbstractAxis *axis, axisList) {
90 foreach (QAbstractAxis *axis, axisList) {
91 oldChart->removeAxis(axis);
91 oldChart->removeAxis(axis);
92 newChart->addAxis(axis, axis->alignment());
92 newChart->addAxis(axis, axis->alignment());
93 }
93 }
94
94
95 foreach (QAbstractSeries *series, seriesList) {
95 foreach (QAbstractSeries *series, seriesList) {
96 newChart->addSeries(series);
96 newChart->addSeries(series);
97 foreach (QAbstractAxis *axis, axisList)
97 foreach (QAbstractAxis *axis, axisList)
98 series->attachAxis(axis);
98 series->attachAxis(axis);
99 }
99 }
100
100
101 int count = 0;
101 int count = 0;
102 foreach (QAbstractAxis *axis, axisList) {
102 foreach (QAbstractAxis *axis, axisList) {
103 axis->setRange(axisRanges[count].first, axisRanges[count].second);
103 axis->setRange(axisRanges[count].first, axisRanges[count].second);
104 count++;
104 count++;
105 }
105 }
106
106
107 newChart->setTitle(oldChart->title());
107 newChart->setTitle(oldChart->title());
108 setChart(newChart);
108 setChart(newChart);
109 delete oldChart;
109 delete oldChart;
110 }
110 }
111 //![2]
111 //![2]
General Comments 0
You need to be logged in to leave comments. Login now