|
@@
-1,350
+1,362
|
|
1
|
#include "qchartview.h"
|
|
1
|
#include "qchartview.h"
|
|
2
|
#include "qchart.h"
|
|
2
|
#include "qchart.h"
|
|
3
|
#include "qchartaxis.h"
|
|
3
|
#include "qchartaxis.h"
|
|
4
|
#include <QGraphicsView>
|
|
4
|
#include <QGraphicsView>
|
|
5
|
#include <QGraphicsScene>
|
|
5
|
#include <QGraphicsScene>
|
|
6
|
#include <QRubberBand>
|
|
6
|
#include <QRubberBand>
|
|
7
|
#include <QResizeEvent>
|
|
7
|
#include <QResizeEvent>
|
|
8
|
#include <QDebug>
|
|
8
|
#include <QDebug>
|
|
9
|
|
|
9
|
|
|
10
|
/*!
|
|
10
|
/*!
|
|
11
|
\enum QChartView::RubberBandPolicy
|
|
11
|
\enum QChartView::RubberBandPolicy
|
|
12
|
|
|
12
|
|
|
13
|
This enum describes the different types of rubber bands that can be used for zoom rect selection
|
|
13
|
This enum describes the different types of rubber bands that can be used for zoom rect selection
|
|
14
|
|
|
14
|
|
|
15
|
\value NoRubberBand
|
|
15
|
\value NoRubberBand
|
|
16
|
\value VerticalRubberBand
|
|
16
|
\value VerticalRubberBand
|
|
17
|
\value HorizonalRubberBand
|
|
17
|
\value HorizonalRubberBand
|
|
18
|
\value RectangleRubberBand
|
|
18
|
\value RectangleRubberBand
|
|
19
|
*/
|
|
19
|
*/
|
|
20
|
|
|
20
|
|
|
21
|
/*!
|
|
21
|
/*!
|
|
22
|
\class QChartView
|
|
22
|
\class QChartView
|
|
23
|
\brief Standalone charting widget.
|
|
23
|
\brief Standalone charting widget.
|
|
24
|
|
|
24
|
|
|
25
|
QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. It manages the graphical
|
|
25
|
QChartView is a standalone widget that can display charts. It does not require separate QGraphicsScene to work. It manages the graphical
|
|
26
|
representation of different types of QChartSeries and other chart related objects like
|
|
26
|
representation of different types of QChartSeries and other chart related objects like
|
|
27
|
QChartAxis and QChartLegend. If you want to display a chart in your existing QGraphicsScene, you can use the QChart class instead.
|
|
27
|
QChartAxis and QChartLegend. If you want to display a chart in your existing QGraphicsScene, you can use the QChart class instead.
|
|
28
|
|
|
28
|
|
|
|
|
|
29
|
For example, to create an empty chart in a widget based application:
|
|
|
|
|
30
|
\snippet ../example/chartview/main.cpp 1
|
|
|
|
|
31
|
\image chartview_example.jpg
|
|
|
|
|
32
|
|
|
|
|
|
33
|
To add a line series:
|
|
|
|
|
34
|
\snippet ../example/chartview/main.cpp 2
|
|
|
|
|
35
|
\image chartview_example_series.jpg
|
|
|
|
|
36
|
|
|
|
|
|
37
|
To modify the visual appearance of the chart, you can use the pre-defined themes:
|
|
|
|
|
38
|
\snippet ../example/chartview/main.cpp 3
|
|
|
|
|
39
|
\image chartview_example_theme.jpg
|
|
|
|
|
40
|
|
|
29
|
\sa QChart
|
|
41
|
\sa QChart
|
|
30
|
*/
|
|
42
|
*/
|
|
31
|
|
|
43
|
|
|
32
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
44
|
QTCOMMERCIALCHART_BEGIN_NAMESPACE
|
|
33
|
|
|
45
|
|
|
34
|
/*!
|
|
46
|
/*!
|
|
35
|
Constructs a chartView object which is a child of a\a parent.
|
|
47
|
Constructs a chartView object which is a child of a\a parent.
|
|
36
|
*/
|
|
48
|
*/
|
|
37
|
QChartView::QChartView(QWidget *parent) :
|
|
49
|
QChartView::QChartView(QWidget *parent) :
|
|
38
|
QGraphicsView(parent),
|
|
50
|
QGraphicsView(parent),
|
|
39
|
m_scene(new QGraphicsScene(this)),
|
|
51
|
m_scene(new QGraphicsScene(this)),
|
|
40
|
m_chart(new QChart()),
|
|
52
|
m_chart(new QChart()),
|
|
41
|
m_rubberBand(0),
|
|
53
|
m_rubberBand(0),
|
|
42
|
m_verticalRubberBand(false),
|
|
54
|
m_verticalRubberBand(false),
|
|
43
|
m_horizonalRubberBand(false)
|
|
55
|
m_horizonalRubberBand(false)
|
|
44
|
{
|
|
56
|
{
|
|
45
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
57
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
46
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
58
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
47
|
setScene(m_scene);
|
|
59
|
setScene(m_scene);
|
|
48
|
m_chart->setMargin(50);
|
|
60
|
m_chart->setMargin(50);
|
|
49
|
m_scene->addItem(m_chart);
|
|
61
|
m_scene->addItem(m_chart);
|
|
50
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
62
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
51
|
}
|
|
63
|
}
|
|
52
|
|
|
64
|
|
|
53
|
|
|
65
|
|
|
54
|
/*!
|
|
66
|
/*!
|
|
55
|
Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
|
|
67
|
Destroys the object and it's children, like QChartSeries and QChartAxis object added to it.
|
|
56
|
*/
|
|
68
|
*/
|
|
57
|
QChartView::~QChartView()
|
|
69
|
QChartView::~QChartView()
|
|
58
|
{
|
|
70
|
{
|
|
59
|
}
|
|
71
|
}
|
|
60
|
|
|
72
|
|
|
61
|
/*!
|
|
73
|
/*!
|
|
62
|
Resizes and updates the chart area using the \a event data
|
|
74
|
Resizes and updates the chart area using the \a event data
|
|
63
|
*/
|
|
75
|
*/
|
|
64
|
void QChartView::resizeEvent(QResizeEvent *event)
|
|
76
|
void QChartView::resizeEvent(QResizeEvent *event)
|
|
65
|
{
|
|
77
|
{
|
|
66
|
m_scene->setSceneRect(0,0,size().width(),size().height());
|
|
78
|
m_scene->setSceneRect(0,0,size().width(),size().height());
|
|
67
|
m_chart->resize(size());
|
|
79
|
m_chart->resize(size());
|
|
68
|
QWidget::resizeEvent(event);
|
|
80
|
QWidget::resizeEvent(event);
|
|
69
|
}
|
|
81
|
}
|
|
70
|
|
|
82
|
|
|
71
|
/*!
|
|
83
|
/*!
|
|
72
|
Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
|
|
84
|
Adds the \a series and optional \a axisY onto the chart and takes the ownership of the objects.
|
|
73
|
If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
|
|
85
|
If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and
|
|
74
|
the y axis).
|
|
86
|
the y axis).
|
|
75
|
\sa removeSeries(), removeAllSeries()
|
|
87
|
\sa removeSeries(), removeAllSeries()
|
|
76
|
*/
|
|
88
|
*/
|
|
77
|
void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
|
|
89
|
void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
|
|
78
|
{
|
|
90
|
{
|
|
79
|
m_chart->addSeries(series,axisY);
|
|
91
|
m_chart->addSeries(series,axisY);
|
|
80
|
}
|
|
92
|
}
|
|
81
|
|
|
93
|
|
|
82
|
/*!
|
|
94
|
/*!
|
|
83
|
Removes the \a series specified in a perameter from the QChartView.
|
|
95
|
Removes the \a series specified in a perameter from the QChartView.
|
|
84
|
It releses its ownership of the specified QChartSeries object.
|
|
96
|
It releses its ownership of the specified QChartSeries object.
|
|
85
|
It does not delete the pointed QChartSeries data object
|
|
97
|
It does not delete the pointed QChartSeries data object
|
|
86
|
\sa addSeries(), removeAllSeries()
|
|
98
|
\sa addSeries(), removeAllSeries()
|
|
87
|
*/
|
|
99
|
*/
|
|
88
|
void QChartView::removeSeries(QChartSeries* series)
|
|
100
|
void QChartView::removeSeries(QChartSeries* series)
|
|
89
|
{
|
|
101
|
{
|
|
90
|
m_chart->removeSeries(series);
|
|
102
|
m_chart->removeSeries(series);
|
|
91
|
}
|
|
103
|
}
|
|
92
|
|
|
104
|
|
|
93
|
/*!
|
|
105
|
/*!
|
|
94
|
Removes all the QChartSeries that have been added to the QChartView
|
|
106
|
Removes all the QChartSeries that have been added to the QChartView
|
|
95
|
It also deletes the pointed QChartSeries data objects
|
|
107
|
It also deletes the pointed QChartSeries data objects
|
|
96
|
\sa addSeries(), removeSeries()
|
|
108
|
\sa addSeries(), removeSeries()
|
|
97
|
*/
|
|
109
|
*/
|
|
98
|
void QChartView::removeAllSeries()
|
|
110
|
void QChartView::removeAllSeries()
|
|
99
|
{
|
|
111
|
{
|
|
100
|
m_chart->removeAllSeries();
|
|
112
|
m_chart->removeAllSeries();
|
|
101
|
}
|
|
113
|
}
|
|
102
|
|
|
114
|
|
|
103
|
/*!
|
|
115
|
/*!
|
|
104
|
Zooms in the view by a factor of 2
|
|
116
|
Zooms in the view by a factor of 2
|
|
105
|
*/
|
|
117
|
*/
|
|
106
|
void QChartView::zoomIn()
|
|
118
|
void QChartView::zoomIn()
|
|
107
|
{
|
|
119
|
{
|
|
108
|
m_chart->zoomIn();
|
|
120
|
m_chart->zoomIn();
|
|
109
|
}
|
|
121
|
}
|
|
110
|
|
|
122
|
|
|
111
|
/*!
|
|
123
|
/*!
|
|
112
|
Zooms in the view to a maximum level at which \a rect is still fully visible.
|
|
124
|
Zooms in the view to a maximum level at which \a rect is still fully visible.
|
|
113
|
*/
|
|
125
|
*/
|
|
114
|
void QChartView::zoomIn(const QRect& rect)
|
|
126
|
void QChartView::zoomIn(const QRect& rect)
|
|
115
|
{
|
|
127
|
{
|
|
116
|
m_chart->zoomIn(rect);
|
|
128
|
m_chart->zoomIn(rect);
|
|
117
|
}
|
|
129
|
}
|
|
118
|
|
|
130
|
|
|
119
|
/*!
|
|
131
|
/*!
|
|
120
|
Restores the view zoom level to the previous one.
|
|
132
|
Restores the view zoom level to the previous one.
|
|
121
|
*/
|
|
133
|
*/
|
|
122
|
void QChartView::zoomOut()
|
|
134
|
void QChartView::zoomOut()
|
|
123
|
{
|
|
135
|
{
|
|
124
|
m_chart->zoomOut();
|
|
136
|
m_chart->zoomOut();
|
|
125
|
}
|
|
137
|
}
|
|
126
|
|
|
138
|
|
|
127
|
/*!
|
|
139
|
/*!
|
|
128
|
Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
|
|
140
|
Returns the chart margin, which is the distance between the widget edge and the part of the chart where the actual data can be displayed.
|
|
129
|
*/
|
|
141
|
*/
|
|
130
|
int QChartView::margin() const
|
|
142
|
int QChartView::margin() const
|
|
131
|
{
|
|
143
|
{
|
|
132
|
return m_chart->margin();
|
|
144
|
return m_chart->margin();
|
|
133
|
}
|
|
145
|
}
|
|
134
|
|
|
146
|
|
|
135
|
/*!
|
|
147
|
/*!
|
|
136
|
Sets the chart \a title. A description text that is rendered above the chart.
|
|
148
|
Sets the chart \a title. A description text that is rendered above the chart.
|
|
137
|
*/
|
|
149
|
*/
|
|
138
|
void QChartView::setChartTitle(const QString& title)
|
|
150
|
void QChartView::setChartTitle(const QString& title)
|
|
139
|
{
|
|
151
|
{
|
|
140
|
m_chart->setChartTitle(title);
|
|
152
|
m_chart->setChartTitle(title);
|
|
141
|
}
|
|
153
|
}
|
|
142
|
|
|
154
|
|
|
143
|
/*!
|
|
155
|
/*!
|
|
144
|
Sets the \a font that is used for rendering the description text that is rendered above the chart.
|
|
156
|
Sets the \a font that is used for rendering the description text that is rendered above the chart.
|
|
145
|
*/
|
|
157
|
*/
|
|
146
|
void QChartView::setChartTitleFont(const QFont& font)
|
|
158
|
void QChartView::setChartTitleFont(const QFont& font)
|
|
147
|
{
|
|
159
|
{
|
|
148
|
m_chart->setChartTitleFont(font);
|
|
160
|
m_chart->setChartTitleFont(font);
|
|
149
|
}
|
|
161
|
}
|
|
150
|
|
|
162
|
|
|
151
|
/*!
|
|
163
|
/*!
|
|
152
|
Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
|
|
164
|
Sets the \a brush that is used for painting the background of the chart area of the QChartView widget.
|
|
153
|
*/
|
|
165
|
*/
|
|
154
|
void QChartView::setChartBackgroundBrush(const QBrush& brush)
|
|
166
|
void QChartView::setChartBackgroundBrush(const QBrush& brush)
|
|
155
|
{
|
|
167
|
{
|
|
156
|
m_chart->setChartBackgroundBrush(brush);
|
|
168
|
m_chart->setChartBackgroundBrush(brush);
|
|
157
|
}
|
|
169
|
}
|
|
158
|
|
|
170
|
|
|
159
|
/*!
|
|
171
|
/*!
|
|
160
|
Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
|
|
172
|
Sets the \a pen that is used for painting the background of the chart area of the QChartView widget.
|
|
161
|
*/
|
|
173
|
*/
|
|
162
|
void QChartView::setChartBackgroundPen(const QPen& pen)
|
|
174
|
void QChartView::setChartBackgroundPen(const QPen& pen)
|
|
163
|
{
|
|
175
|
{
|
|
164
|
m_chart->setChartBackgroundPen(pen);
|
|
176
|
m_chart->setChartBackgroundPen(pen);
|
|
165
|
}
|
|
177
|
}
|
|
166
|
|
|
178
|
|
|
167
|
/*!
|
|
179
|
/*!
|
|
168
|
Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
|
|
180
|
Sets the RubberBandPlicy to \a policy. Selected policy determines the way zooming is performed.
|
|
169
|
*/
|
|
181
|
*/
|
|
170
|
void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
|
|
182
|
void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
|
|
171
|
{
|
|
183
|
{
|
|
172
|
switch(policy) {
|
|
184
|
switch(policy) {
|
|
173
|
case VerticalRubberBand:
|
|
185
|
case VerticalRubberBand:
|
|
174
|
m_verticalRubberBand = true;
|
|
186
|
m_verticalRubberBand = true;
|
|
175
|
m_horizonalRubberBand = false;
|
|
187
|
m_horizonalRubberBand = false;
|
|
176
|
break;
|
|
188
|
break;
|
|
177
|
case HorizonalRubberBand:
|
|
189
|
case HorizonalRubberBand:
|
|
178
|
m_verticalRubberBand = false;
|
|
190
|
m_verticalRubberBand = false;
|
|
179
|
m_horizonalRubberBand = true;
|
|
191
|
m_horizonalRubberBand = true;
|
|
180
|
break;
|
|
192
|
break;
|
|
181
|
case RectangleRubberBand:
|
|
193
|
case RectangleRubberBand:
|
|
182
|
m_verticalRubberBand = true;
|
|
194
|
m_verticalRubberBand = true;
|
|
183
|
m_horizonalRubberBand = true;
|
|
195
|
m_horizonalRubberBand = true;
|
|
184
|
break;
|
|
196
|
break;
|
|
185
|
case NoRubberBand:
|
|
197
|
case NoRubberBand:
|
|
186
|
default:
|
|
198
|
default:
|
|
187
|
delete m_rubberBand;
|
|
199
|
delete m_rubberBand;
|
|
188
|
m_rubberBand=0;
|
|
200
|
m_rubberBand=0;
|
|
189
|
m_horizonalRubberBand = false;
|
|
201
|
m_horizonalRubberBand = false;
|
|
190
|
m_verticalRubberBand = false;
|
|
202
|
m_verticalRubberBand = false;
|
|
191
|
return;
|
|
203
|
return;
|
|
192
|
}
|
|
204
|
}
|
|
193
|
if(!m_rubberBand) {
|
|
205
|
if(!m_rubberBand) {
|
|
194
|
m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
|
206
|
m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
|
|
195
|
m_rubberBand->setEnabled(true);
|
|
207
|
m_rubberBand->setEnabled(true);
|
|
196
|
}
|
|
208
|
}
|
|
197
|
}
|
|
209
|
}
|
|
198
|
|
|
210
|
|
|
199
|
/*!
|
|
211
|
/*!
|
|
200
|
Returns the RubberBandPolicy that is currently being used by the widget.
|
|
212
|
Returns the RubberBandPolicy that is currently being used by the widget.
|
|
201
|
*/
|
|
213
|
*/
|
|
202
|
QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
|
|
214
|
QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
|
|
203
|
{
|
|
215
|
{
|
|
204
|
if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
|
|
216
|
if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
|
|
205
|
if(m_horizonalRubberBand) return HorizonalRubberBand;
|
|
217
|
if(m_horizonalRubberBand) return HorizonalRubberBand;
|
|
206
|
if(m_verticalRubberBand) return VerticalRubberBand;
|
|
218
|
if(m_verticalRubberBand) return VerticalRubberBand;
|
|
207
|
return NoRubberBand;
|
|
219
|
return NoRubberBand;
|
|
208
|
}
|
|
220
|
}
|
|
209
|
|
|
221
|
|
|
210
|
/*!
|
|
222
|
/*!
|
|
211
|
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.
|
|
223
|
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.
|
|
212
|
If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called.
|
|
224
|
If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation is called.
|
|
213
|
*/
|
|
225
|
*/
|
|
214
|
void QChartView::mousePressEvent(QMouseEvent *event)
|
|
226
|
void QChartView::mousePressEvent(QMouseEvent *event)
|
|
215
|
{
|
|
227
|
{
|
|
216
|
if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
|
|
228
|
if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
|
|
217
|
|
|
229
|
|
|
218
|
int margin = m_chart->margin();
|
|
230
|
int margin = m_chart->margin();
|
|
219
|
QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
|
|
231
|
QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
|
|
220
|
|
|
232
|
|
|
221
|
if (rect.contains(event->pos())) {
|
|
233
|
if (rect.contains(event->pos())) {
|
|
222
|
m_rubberBandOrigin = event->pos();
|
|
234
|
m_rubberBandOrigin = event->pos();
|
|
223
|
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
|
|
235
|
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
|
|
224
|
m_rubberBand->show();
|
|
236
|
m_rubberBand->show();
|
|
225
|
event->accept();
|
|
237
|
event->accept();
|
|
226
|
}
|
|
238
|
}
|
|
227
|
}
|
|
239
|
}
|
|
228
|
else {
|
|
240
|
else {
|
|
229
|
QGraphicsView::mousePressEvent(event);
|
|
241
|
QGraphicsView::mousePressEvent(event);
|
|
230
|
}
|
|
242
|
}
|
|
231
|
}
|
|
243
|
}
|
|
232
|
|
|
244
|
|
|
233
|
/*!
|
|
245
|
/*!
|
|
234
|
If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
|
|
246
|
If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
|
|
235
|
In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
|
|
247
|
In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
|
|
236
|
*/
|
|
248
|
*/
|
|
237
|
void QChartView::mouseMoveEvent(QMouseEvent *event)
|
|
249
|
void QChartView::mouseMoveEvent(QMouseEvent *event)
|
|
238
|
{
|
|
250
|
{
|
|
239
|
if(m_rubberBand && m_rubberBand->isVisible()) {
|
|
251
|
if(m_rubberBand && m_rubberBand->isVisible()) {
|
|
240
|
int margin = m_chart->margin();
|
|
252
|
int margin = m_chart->margin();
|
|
241
|
QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
|
|
253
|
QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
|
|
242
|
int width = event->pos().x() - m_rubberBandOrigin.x();
|
|
254
|
int width = event->pos().x() - m_rubberBandOrigin.x();
|
|
243
|
int height = event->pos().y() - m_rubberBandOrigin.y();
|
|
255
|
int height = event->pos().y() - m_rubberBandOrigin.y();
|
|
244
|
if(!m_verticalRubberBand) {
|
|
256
|
if(!m_verticalRubberBand) {
|
|
245
|
m_rubberBandOrigin.setY(rect.top());
|
|
257
|
m_rubberBandOrigin.setY(rect.top());
|
|
246
|
height = rect.height();
|
|
258
|
height = rect.height();
|
|
247
|
}
|
|
259
|
}
|
|
248
|
if(!m_horizonalRubberBand) {
|
|
260
|
if(!m_horizonalRubberBand) {
|
|
249
|
m_rubberBandOrigin.setX(rect.left());
|
|
261
|
m_rubberBandOrigin.setX(rect.left());
|
|
250
|
width= rect.width();
|
|
262
|
width= rect.width();
|
|
251
|
}
|
|
263
|
}
|
|
252
|
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
|
|
264
|
m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
|
|
253
|
}
|
|
265
|
}
|
|
254
|
else {
|
|
266
|
else {
|
|
255
|
QGraphicsView::mouseMoveEvent(event);
|
|
267
|
QGraphicsView::mouseMoveEvent(event);
|
|
256
|
}
|
|
268
|
}
|
|
257
|
}
|
|
269
|
}
|
|
258
|
|
|
270
|
|
|
259
|
/*!
|
|
271
|
/*!
|
|
260
|
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
|
|
272
|
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
|
|
261
|
If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
|
|
273
|
If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
|
|
262
|
*/
|
|
274
|
*/
|
|
263
|
void QChartView::mouseReleaseEvent(QMouseEvent *event)
|
|
275
|
void QChartView::mouseReleaseEvent(QMouseEvent *event)
|
|
264
|
{
|
|
276
|
{
|
|
265
|
if(m_rubberBand) {
|
|
277
|
if(m_rubberBand) {
|
|
266
|
if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
|
|
278
|
if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
|
|
267
|
m_rubberBand->hide();
|
|
279
|
m_rubberBand->hide();
|
|
268
|
QRect rect = m_rubberBand->geometry();
|
|
280
|
QRect rect = m_rubberBand->geometry();
|
|
269
|
m_chart->zoomIn(rect);
|
|
281
|
m_chart->zoomIn(rect);
|
|
270
|
event->accept();
|
|
282
|
event->accept();
|
|
271
|
}
|
|
283
|
}
|
|
272
|
|
|
284
|
|
|
273
|
if(event->button()==Qt::RightButton)
|
|
285
|
if(event->button()==Qt::RightButton)
|
|
274
|
m_chart->zoomReset();
|
|
286
|
m_chart->zoomReset();
|
|
275
|
}
|
|
287
|
}
|
|
276
|
else {
|
|
288
|
else {
|
|
277
|
QGraphicsView::mouseReleaseEvent(event);
|
|
289
|
QGraphicsView::mouseReleaseEvent(event);
|
|
278
|
}
|
|
290
|
}
|
|
279
|
}
|
|
291
|
}
|
|
280
|
|
|
292
|
|
|
281
|
/*!
|
|
293
|
/*!
|
|
282
|
Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
|
|
294
|
Pressing + and - keys performs zoomIn() and zoomOut() respectivly.
|
|
283
|
In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
|
|
295
|
In other \a event is passed to the QGraphicsView::keyPressEvent() implementation
|
|
284
|
*/
|
|
296
|
*/
|
|
285
|
void QChartView::keyPressEvent(QKeyEvent *event)
|
|
297
|
void QChartView::keyPressEvent(QKeyEvent *event)
|
|
286
|
{
|
|
298
|
{
|
|
287
|
switch (event->key()) {
|
|
299
|
switch (event->key()) {
|
|
288
|
case Qt::Key_Plus:
|
|
300
|
case Qt::Key_Plus:
|
|
289
|
zoomIn();
|
|
301
|
zoomIn();
|
|
290
|
break;
|
|
302
|
break;
|
|
291
|
case Qt::Key_Minus:
|
|
303
|
case Qt::Key_Minus:
|
|
292
|
zoomOut();
|
|
304
|
zoomOut();
|
|
293
|
break;
|
|
305
|
break;
|
|
294
|
default:
|
|
306
|
default:
|
|
295
|
QGraphicsView::keyPressEvent(event);
|
|
307
|
QGraphicsView::keyPressEvent(event);
|
|
296
|
break;
|
|
308
|
break;
|
|
297
|
}
|
|
309
|
}
|
|
298
|
}
|
|
310
|
}
|
|
299
|
|
|
311
|
|
|
300
|
/*!
|
|
312
|
/*!
|
|
301
|
Sets the \a theme used by the chart for rendering the graphical representation of the data
|
|
313
|
Sets the \a theme used by the chart for rendering the graphical representation of the data
|
|
302
|
\sa QChart::ChartTheme, chartTheme()
|
|
314
|
\sa QChart::ChartTheme, chartTheme()
|
|
303
|
*/
|
|
315
|
*/
|
|
304
|
void QChartView::setChartTheme(QChart::ChartTheme theme)
|
|
316
|
void QChartView::setChartTheme(QChart::ChartTheme theme)
|
|
305
|
{
|
|
317
|
{
|
|
306
|
m_chart->setChartTheme(theme);
|
|
318
|
m_chart->setChartTheme(theme);
|
|
307
|
}
|
|
319
|
}
|
|
308
|
|
|
320
|
|
|
309
|
/*!
|
|
321
|
/*!
|
|
310
|
Returns the theme enum used by the chart.
|
|
322
|
Returns the theme enum used by the chart.
|
|
311
|
\sa setChartTheme()
|
|
323
|
\sa setChartTheme()
|
|
312
|
*/
|
|
324
|
*/
|
|
313
|
QChart::ChartTheme QChartView::chartTheme() const
|
|
325
|
QChart::ChartTheme QChartView::chartTheme() const
|
|
314
|
{
|
|
326
|
{
|
|
315
|
return m_chart->chartTheme();
|
|
327
|
return m_chart->chartTheme();
|
|
316
|
}
|
|
328
|
}
|
|
317
|
|
|
329
|
|
|
318
|
/*!
|
|
330
|
/*!
|
|
319
|
Returns the pointer to the x axis object of the chart
|
|
331
|
Returns the pointer to the x axis object of the chart
|
|
320
|
*/
|
|
332
|
*/
|
|
321
|
QChartAxis* QChartView::axisX() const
|
|
333
|
QChartAxis* QChartView::axisX() const
|
|
322
|
{
|
|
334
|
{
|
|
323
|
return m_chart->axisX();
|
|
335
|
return m_chart->axisX();
|
|
324
|
}
|
|
336
|
}
|
|
325
|
|
|
337
|
|
|
326
|
/*!
|
|
338
|
/*!
|
|
327
|
Returns the pointer to the y axis object of the chart
|
|
339
|
Returns the pointer to the y axis object of the chart
|
|
328
|
*/
|
|
340
|
*/
|
|
329
|
QChartAxis* QChartView::axisY() const
|
|
341
|
QChartAxis* QChartView::axisY() const
|
|
330
|
{
|
|
342
|
{
|
|
331
|
return m_chart->axisY();
|
|
343
|
return m_chart->axisY();
|
|
332
|
}
|
|
344
|
}
|
|
333
|
|
|
345
|
|
|
334
|
/*!
|
|
346
|
/*!
|
|
335
|
Sets animation \a options for the chart
|
|
347
|
Sets animation \a options for the chart
|
|
336
|
*/
|
|
348
|
*/
|
|
337
|
void QChartView::setAnimationOptions(QChart::AnimationOptions options)
|
|
349
|
void QChartView::setAnimationOptions(QChart::AnimationOptions options)
|
|
338
|
{
|
|
350
|
{
|
|
339
|
m_chart->setAnimationOptions(options);
|
|
351
|
m_chart->setAnimationOptions(options);
|
|
340
|
}
|
|
352
|
}
|
|
341
|
|
|
353
|
|
|
342
|
/*!
|
|
354
|
/*!
|
|
343
|
Returns animation options for the chart
|
|
355
|
Returns animation options for the chart
|
|
344
|
*/
|
|
356
|
*/
|
|
345
|
QChart::AnimationOptions QChartView::animationOptions() const
|
|
357
|
QChart::AnimationOptions QChartView::animationOptions() const
|
|
346
|
{
|
|
358
|
{
|
|
347
|
return m_chart->animationOptions();
|
|
359
|
return m_chart->animationOptions();
|
|
348
|
}
|
|
360
|
}
|
|
349
|
|
|
361
|
|
|
350
|
QTCOMMERCIALCHART_END_NAMESPACE
|
|
362
|
QTCOMMERCIALCHART_END_NAMESPACE
|