##// END OF EJS Templates
minor. fix warning on gcc4.1
Michal Klocek -
r1961:f68af6687512
parent child
Show More
@@ -1,226 +1,226
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 "qchartview_p.h"
22 #include "qchartview_p.h"
23 #include "qchart_p.h"
23 #include "qchart_p.h"
24 #include <QGraphicsScene>
24 #include <QGraphicsScene>
25 #include <QRubberBand>
25 #include <QRubberBand>
26
26
27 /*!
27 /*!
28 \enum QChartView::RubberBand
28 \enum QChartView::RubberBand
29
29
30 This enum describes the different types of rubber bands that can be used for zoom rect selection
30 This enum describes the different types of rubber bands that can be used for zoom rect selection
31
31
32 \value NoRubberBand
32 \value NoRubberBand
33 \value VerticalRubberBand
33 \value VerticalRubberBand
34 \value HorizonalRubberBand
34 \value HorizonalRubberBand
35 \value RectangleRubberBand
35 \value RectangleRubberBand
36 */
36 */
37
37
38 /*!
38 /*!
39 \class QChartView
39 \class QChartView
40 \brief Standalone charting widget.
40 \brief Standalone charting widget.
41
41
42 QChartView is a standalone widget that can display charts. It does not require separate
42 QChartView is a standalone widget that can display charts. It does not require separate
43 QGraphicsScene to work. It manages the graphical representation of different types of
43 QGraphicsScene to work. It manages the graphical representation of different types of
44 series and other chart related objects like QAxis and QLegend. If you want to
44 series and other chart related objects like QAxis and QLegend. If you want to
45 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
45 display a chart in your existing QGraphicsScene, you can use the QChart class instead.
46
46
47 \sa QChart
47 \sa QChart
48 */
48 */
49
49
50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
50 QTCOMMERCIALCHART_BEGIN_NAMESPACE
51
51
52 /*!
52 /*!
53 Constructs a chartView object with parent \a parent.
53 Constructs a chartView object with parent \a parent.
54 */
54 */
55
55
56 QChartView::QChartView(QWidget *parent) :
56 QChartView::QChartView(QWidget *parent) :
57 QGraphicsView(parent),
57 QGraphicsView(parent),
58 d_ptr(new QChartViewPrivate(this))
58 d_ptr(new QChartViewPrivate(this))
59 {
59 {
60
60
61 }
61 }
62
62
63 /*!
63 /*!
64 Constructs a chartView object with parent \a parent to display a \a chart.
64 Constructs a chartView object with parent \a parent to display a \a chart.
65 */
65 */
66
66
67 QChartView::QChartView(QChart *chart,QWidget *parent) :
67 QChartView::QChartView(QChart *chart,QWidget *parent) :
68 QGraphicsView(parent),
68 QGraphicsView(parent),
69 d_ptr(new QChartViewPrivate(this,chart))
69 d_ptr(new QChartViewPrivate(this,chart))
70 {
70 {
71
71
72 }
72 }
73
73
74
74
75 /*!
75 /*!
76 Destroys the object and it's children, like series and axis objects added to it.
76 Destroys the object and it's children, like series and axis objects added to it.
77 */
77 */
78 QChartView::~QChartView()
78 QChartView::~QChartView()
79 {
79 {
80 }
80 }
81
81
82 /*!
82 /*!
83 Returns the pointer to the associated chart
83 Returns the pointer to the associated chart
84 */
84 */
85 QChart* QChartView::chart() const
85 QChart* QChartView::chart() const
86 {
86 {
87 return d_ptr->m_chart;
87 return d_ptr->m_chart;
88 }
88 }
89
89
90 /*!
90 /*!
91 Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
91 Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed.
92 */
92 */
93 void QChartView::setRubberBand(const RubberBands& rubberBand)
93 void QChartView::setRubberBand(const RubberBands& rubberBand)
94 {
94 {
95 d_ptr->m_rubberBandFlags=rubberBand;
95 d_ptr->m_rubberBandFlags=rubberBand;
96
96
97 if (!d_ptr->m_rubberBandFlags) {
97 if (!d_ptr->m_rubberBandFlags) {
98 delete d_ptr->m_rubberBand;
98 delete d_ptr->m_rubberBand;
99 d_ptr->m_rubberBand=0;
99 d_ptr->m_rubberBand=0;
100 return;
100 return;
101 }
101 }
102
102
103 if (!d_ptr->m_rubberBand) {
103 if (!d_ptr->m_rubberBand) {
104 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
104 d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
105 d_ptr->m_rubberBand->setEnabled(true);
105 d_ptr->m_rubberBand->setEnabled(true);
106 }
106 }
107 }
107 }
108
108
109 /*!
109 /*!
110 Returns the RubberBandPolicy that is currently being used by the widget.
110 Returns the RubberBandPolicy that is currently being used by the widget.
111 */
111 */
112 QChartView::RubberBands QChartView::rubberBand() const
112 QChartView::RubberBands QChartView::rubberBand() const
113 {
113 {
114 return d_ptr->m_rubberBandFlags;
114 return d_ptr->m_rubberBandFlags;
115 }
115 }
116
116
117 /*!
117 /*!
118 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.
118 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.
119 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
119 If different mouse button is pressed and/or the RubberBandPolicy is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation.
120 */
120 */
121 void QChartView::mousePressEvent(QMouseEvent *event)
121 void QChartView::mousePressEvent(QMouseEvent *event)
122 {
122 {
123 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
123 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
124
124
125 QRectF plotArea = d_ptr->m_chart->plotArea();
125 QRectF plotArea = d_ptr->m_chart->plotArea();
126
126
127 if (plotArea.contains(event->pos())) {
127 if (plotArea.contains(event->pos())) {
128 d_ptr->m_rubberBandOrigin = event->pos();
128 d_ptr->m_rubberBandOrigin = event->pos();
129 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
129 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize()));
130 d_ptr->m_rubberBand->show();
130 d_ptr->m_rubberBand->show();
131 event->accept();
131 event->accept();
132 }
132 }
133 }
133 }
134 else {
134 else {
135 QGraphicsView::mousePressEvent(event);
135 QGraphicsView::mousePressEvent(event);
136 }
136 }
137 }
137 }
138
138
139 /*!
139 /*!
140 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
140 If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry.
141 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
141 In other case the defualt QGraphicsView::mouseMoveEvent implementation is called.
142 */
142 */
143 void QChartView::mouseMoveEvent(QMouseEvent *event)
143 void QChartView::mouseMoveEvent(QMouseEvent *event)
144 {
144 {
145 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
145 if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) {
146 QRectF rect = d_ptr->m_chart->plotArea();
146 QRect rect = d_ptr->m_chart->plotArea().toRect();
147 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
147 int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x();
148 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
148 int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y();
149 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
149 if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) {
150 d_ptr->m_rubberBandOrigin.setY(rect.top());
150 d_ptr->m_rubberBandOrigin.setY(rect.top());
151 height = rect.height();
151 height = rect.height();
152 }
152 }
153 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
153 if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) {
154 d_ptr->m_rubberBandOrigin.setX(rect.left());
154 d_ptr->m_rubberBandOrigin.setX(rect.left());
155 width= rect.width();
155 width= rect.width();
156 }
156 }
157 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
157 d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized());
158 }
158 }
159 else {
159 else {
160 QGraphicsView::mouseMoveEvent(event);
160 QGraphicsView::mouseMoveEvent(event);
161 }
161 }
162 }
162 }
163
163
164 /*!
164 /*!
165 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
165 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 it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
166 If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled.
167 */
167 */
168 void QChartView::mouseReleaseEvent(QMouseEvent *event)
168 void QChartView::mouseReleaseEvent(QMouseEvent *event)
169 {
169 {
170 if(d_ptr->m_rubberBand) {
170 if(d_ptr->m_rubberBand) {
171 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
171 if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) {
172 d_ptr->m_rubberBand->hide();
172 d_ptr->m_rubberBand->hide();
173 QRect rect = d_ptr->m_rubberBand->geometry();
173 QRect rect = d_ptr->m_rubberBand->geometry();
174 d_ptr->m_chart->zoomIn(rect);
174 d_ptr->m_chart->zoomIn(rect);
175 event->accept();
175 event->accept();
176 }
176 }
177
177
178 if(event->button()==Qt::RightButton){
178 if(event->button()==Qt::RightButton){
179 d_ptr->m_chart->zoomOut();
179 d_ptr->m_chart->zoomOut();
180 event->accept();
180 event->accept();
181 }
181 }
182 }
182 }
183 else {
183 else {
184 QGraphicsView::mouseReleaseEvent(event);
184 QGraphicsView::mouseReleaseEvent(event);
185 }
185 }
186 }
186 }
187
187
188 /*!
188 /*!
189 Resizes and updates the chart area using the \a event data
189 Resizes and updates the chart area using the \a event data
190 */
190 */
191 void QChartView::resizeEvent(QResizeEvent *event)
191 void QChartView::resizeEvent(QResizeEvent *event)
192 {
192 {
193 QGraphicsView::resizeEvent(event);
193 QGraphicsView::resizeEvent(event);
194 d_ptr->m_chart->resize(size());
194 d_ptr->m_chart->resize(size());
195 setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
195 setMinimumSize(d_ptr->m_chart->minimumSize().toSize());
196 setSceneRect(d_ptr->m_chart->geometry());
196 setSceneRect(d_ptr->m_chart->geometry());
197 }
197 }
198
198
199 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
199 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
200
200
201 QChartViewPrivate::QChartViewPrivate(QChartView *q,QChart* chart):
201 QChartViewPrivate::QChartViewPrivate(QChartView *q,QChart* chart):
202 q_ptr(q),
202 q_ptr(q),
203 m_scene(new QGraphicsScene(q)),
203 m_scene(new QGraphicsScene(q)),
204 m_chart(chart),
204 m_chart(chart),
205 m_presenter(0),
205 m_presenter(0),
206 m_rubberBand(0),
206 m_rubberBand(0),
207 m_rubberBandFlags(QChartView::NoRubberBand)
207 m_rubberBandFlags(QChartView::NoRubberBand)
208 {
208 {
209 q_ptr->setFrameShape(QFrame::NoFrame);
209 q_ptr->setFrameShape(QFrame::NoFrame);
210 q_ptr->setBackgroundRole(QPalette::Window);
210 q_ptr->setBackgroundRole(QPalette::Window);
211 q_ptr->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
211 q_ptr->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
212 q_ptr->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
212 q_ptr->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
213 q_ptr->setScene(m_scene);
213 q_ptr->setScene(m_scene);
214 q_ptr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
214 q_ptr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
215 if(!m_chart) m_chart = new QChart();
215 if(!m_chart) m_chart = new QChart();
216 m_scene->addItem(m_chart);
216 m_scene->addItem(m_chart);
217 }
217 }
218
218
219 QChartViewPrivate::~QChartViewPrivate()
219 QChartViewPrivate::~QChartViewPrivate()
220 {
220 {
221
221
222 }
222 }
223
223
224 #include "moc_qchartview.cpp"
224 #include "moc_qchartview.cpp"
225
225
226 QTCOMMERCIALCHART_END_NAMESPACE
226 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now