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