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