@@ -1,218 +1,229 | |||||
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. | |||
|
54 | */ | |||
|
55 | ||||
|
56 | QChartView::QChartView(QWidget *parent) : | |||
|
57 | QGraphicsView(parent), | |||
|
58 | d_ptr(new QChartViewPrivate(this)) | |||
|
59 | { | |||
|
60 | ||||
|
61 | } | |||
|
62 | ||||
|
63 | /*! | |||
53 | 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. | |
54 | */ |
|
65 | */ | |
|
66 | ||||
55 | QChartView::QChartView(QChart *chart,QWidget *parent) : |
|
67 | QChartView::QChartView(QChart *chart,QWidget *parent) : | |
56 | QGraphicsView(parent), |
|
68 | QGraphicsView(parent), | |
57 | d_ptr(new QChartViewPrivate()) |
|
69 | d_ptr(new QChartViewPrivate(this,chart)) | |
58 | { |
|
70 | { | |
59 | Q_ASSERT(chart); |
|
71 | ||
60 | d_ptr->m_scene = new QGraphicsScene(this); |
|
|||
61 | d_ptr->m_chart = chart; |
|
|||
62 | setFrameShape(QFrame::NoFrame); |
|
|||
63 | setBackgroundRole(QPalette::Window); |
|
|||
64 | setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|||
65 | setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|||
66 | setScene(d_ptr->m_scene); |
|
|||
67 | d_ptr->m_scene->addItem(chart); |
|
|||
68 | setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
|||
69 | } |
|
72 | } | |
70 |
|
73 | |||
71 |
|
74 | |||
72 | /*! |
|
75 | /*! | |
73 | 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. | |
74 | */ |
|
77 | */ | |
75 | QChartView::~QChartView() |
|
78 | QChartView::~QChartView() | |
76 | { |
|
79 | { | |
77 | } |
|
80 | } | |
78 |
|
81 | |||
79 | /*! |
|
82 | /*! | |
80 | Returns the pointer to the associated chart |
|
83 | Returns the pointer to the associated chart | |
81 | */ |
|
84 | */ | |
82 | QChart* QChartView::chart() const |
|
85 | QChart* QChartView::chart() const | |
83 | { |
|
86 | { | |
84 | return d_ptr->m_chart; |
|
87 | return d_ptr->m_chart; | |
85 | } |
|
88 | } | |
86 |
|
89 | |||
87 | /*! |
|
90 | /*! | |
88 | 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. | |
89 | */ |
|
92 | */ | |
90 | void QChartView::setRubberBand(const RubberBands& rubberBand) |
|
93 | void QChartView::setRubberBand(const RubberBands& rubberBand) | |
91 | { |
|
94 | { | |
92 | d_ptr->m_rubberBandFlags=rubberBand; |
|
95 | d_ptr->m_rubberBandFlags=rubberBand; | |
93 |
|
96 | |||
94 | if (!d_ptr->m_rubberBandFlags) { |
|
97 | if (!d_ptr->m_rubberBandFlags) { | |
95 | delete d_ptr->m_rubberBand; |
|
98 | delete d_ptr->m_rubberBand; | |
96 | d_ptr->m_rubberBand=0; |
|
99 | d_ptr->m_rubberBand=0; | |
97 | return; |
|
100 | return; | |
98 | } |
|
101 | } | |
99 |
|
102 | |||
100 | if (!d_ptr->m_rubberBand) { |
|
103 | if (!d_ptr->m_rubberBand) { | |
101 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
104 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
102 | d_ptr->m_rubberBand->setEnabled(true); |
|
105 | d_ptr->m_rubberBand->setEnabled(true); | |
103 | } |
|
106 | } | |
104 | } |
|
107 | } | |
105 |
|
108 | |||
106 | /*! |
|
109 | /*! | |
107 | Returns the RubberBandPolicy that is currently being used by the widget. |
|
110 | Returns the RubberBandPolicy that is currently being used by the widget. | |
108 | */ |
|
111 | */ | |
109 | QChartView::RubberBands QChartView::rubberBand() const |
|
112 | QChartView::RubberBands QChartView::rubberBand() const | |
110 | { |
|
113 | { | |
111 | return d_ptr->m_rubberBandFlags; |
|
114 | return d_ptr->m_rubberBandFlags; | |
112 | } |
|
115 | } | |
113 |
|
116 | |||
114 | /*! |
|
117 | /*! | |
115 | 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. | |
116 | 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. | |
117 | */ |
|
120 | */ | |
118 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
121 | void QChartView::mousePressEvent(QMouseEvent *event) | |
119 | { |
|
122 | { | |
120 | 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) { | |
121 |
|
124 | |||
122 | int padding = d_ptr->m_chart->margins().top(); |
|
125 | int padding = d_ptr->m_chart->margins().top(); | |
123 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); |
|
126 | QRect rect(padding, padding, width() - 2 * padding, height() - 2 * padding); | |
124 |
|
127 | |||
125 | if (rect.contains(event->pos())) { |
|
128 | if (rect.contains(event->pos())) { | |
126 | d_ptr->m_rubberBandOrigin = event->pos(); |
|
129 | d_ptr->m_rubberBandOrigin = event->pos(); | |
127 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); |
|
130 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
128 | d_ptr->m_rubberBand->show(); |
|
131 | d_ptr->m_rubberBand->show(); | |
129 | event->accept(); |
|
132 | event->accept(); | |
130 | } |
|
133 | } | |
131 | } |
|
134 | } | |
132 | else { |
|
135 | else { | |
133 | QGraphicsView::mousePressEvent(event); |
|
136 | QGraphicsView::mousePressEvent(event); | |
134 | } |
|
137 | } | |
135 | } |
|
138 | } | |
136 |
|
139 | |||
137 | /*! |
|
140 | /*! | |
138 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. |
|
141 | If RubberBand rectange specification has been initiated in pressEvent then \a event data is used to update RubberBand geometry. | |
139 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. |
|
142 | In other case the defualt QGraphicsView::mouseMoveEvent implementation is called. | |
140 | */ |
|
143 | */ | |
141 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
144 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
142 | { |
|
145 | { | |
143 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
146 | if(d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
144 | QRectF margins = d_ptr->m_chart->margins(); |
|
147 | QRectF margins = d_ptr->m_chart->margins(); | |
145 | QRectF geometry = d_ptr->m_chart->geometry(); |
|
148 | QRectF geometry = d_ptr->m_chart->geometry(); | |
146 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); |
|
149 | QRectF rect =geometry.adjusted(margins.left(),margins.top(),-margins.right(),-margins.bottom()); | |
147 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); |
|
150 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
148 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); |
|
151 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
149 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { |
|
152 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
150 | d_ptr->m_rubberBandOrigin.setY(rect.top()); |
|
153 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
151 | height = rect.height(); |
|
154 | height = rect.height(); | |
152 | } |
|
155 | } | |
153 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { |
|
156 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
154 | d_ptr->m_rubberBandOrigin.setX(rect.left()); |
|
157 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
155 | width= rect.width(); |
|
158 | width= rect.width(); | |
156 | } |
|
159 | } | |
157 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); |
|
160 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(),d_ptr->m_rubberBandOrigin.y(), width,height).normalized()); | |
158 | } |
|
161 | } | |
159 | else { |
|
162 | else { | |
160 | QGraphicsView::mouseMoveEvent(event); |
|
163 | QGraphicsView::mouseMoveEvent(event); | |
161 | } |
|
164 | } | |
162 | } |
|
165 | } | |
163 |
|
166 | |||
164 | /*! |
|
167 | /*! | |
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 |
|
168 | 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. |
|
169 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. | |
167 | */ |
|
170 | */ | |
168 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
171 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
169 | { |
|
172 | { | |
170 | if(d_ptr->m_rubberBand) { |
|
173 | if(d_ptr->m_rubberBand) { | |
171 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { |
|
174 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
172 | d_ptr->m_rubberBand->hide(); |
|
175 | d_ptr->m_rubberBand->hide(); | |
173 | QRect rect = d_ptr->m_rubberBand->geometry(); |
|
176 | QRect rect = d_ptr->m_rubberBand->geometry(); | |
174 | d_ptr->m_chart->zoomIn(rect); |
|
177 | d_ptr->m_chart->zoomIn(rect); | |
175 | event->accept(); |
|
178 | event->accept(); | |
176 | } |
|
179 | } | |
177 |
|
180 | |||
178 | if(event->button()==Qt::RightButton){ |
|
181 | if(event->button()==Qt::RightButton){ | |
179 | d_ptr->m_chart->zoomOut(); |
|
182 | d_ptr->m_chart->zoomOut(); | |
180 | event->accept(); |
|
183 | event->accept(); | |
181 | } |
|
184 | } | |
182 | } |
|
185 | } | |
183 | else { |
|
186 | else { | |
184 | QGraphicsView::mouseReleaseEvent(event); |
|
187 | QGraphicsView::mouseReleaseEvent(event); | |
185 | } |
|
188 | } | |
186 | } |
|
189 | } | |
187 |
|
190 | |||
188 | /*! |
|
191 | /*! | |
189 | Resizes and updates the chart area using the \a event data |
|
192 | Resizes and updates the chart area using the \a event data | |
190 | */ |
|
193 | */ | |
191 | void QChartView::resizeEvent(QResizeEvent *event) |
|
194 | void QChartView::resizeEvent(QResizeEvent *event) | |
192 | { |
|
195 | { | |
193 | QGraphicsView::resizeEvent(event); |
|
196 | QGraphicsView::resizeEvent(event); | |
194 | d_ptr->m_chart->resize(size()); |
|
197 | d_ptr->m_chart->resize(size()); | |
195 | setMinimumSize(d_ptr->m_chart->minimumSize().toSize()); |
|
198 | setMinimumSize(d_ptr->m_chart->minimumSize().toSize()); | |
196 | setSceneRect(d_ptr->m_chart->geometry()); |
|
199 | setSceneRect(d_ptr->m_chart->geometry()); | |
197 | } |
|
200 | } | |
198 |
|
201 | |||
199 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
202 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
200 |
|
203 | |||
201 | QChartViewPrivate::QChartViewPrivate(): |
|
204 | QChartViewPrivate::QChartViewPrivate(QChartView *q,QChart* chart): | |
202 | m_scene(0), |
|
205 | q_ptr(q), | |
203 | m_chart(0), |
|
206 | m_scene(new QGraphicsScene(q)), | |
|
207 | m_chart(chart), | |||
204 | m_presenter(0), |
|
208 | m_presenter(0), | |
205 | m_rubberBand(0), |
|
209 | m_rubberBand(0), | |
206 | m_rubberBandFlags(QChartView::NoRubberBand) |
|
210 | m_rubberBandFlags(QChartView::NoRubberBand) | |
207 | { |
|
211 | { | |
208 |
|
212 | q_ptr->setFrameShape(QFrame::NoFrame); | ||
|
213 | q_ptr->setBackgroundRole(QPalette::Window); | |||
|
214 | q_ptr->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |||
|
215 | q_ptr->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |||
|
216 | q_ptr->setScene(m_scene); | |||
|
217 | q_ptr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |||
|
218 | if(!m_chart) m_chart = new QChart(); | |||
|
219 | m_scene->addItem(m_chart); | |||
209 | } |
|
220 | } | |
210 |
|
221 | |||
211 | QChartViewPrivate::~QChartViewPrivate() |
|
222 | QChartViewPrivate::~QChartViewPrivate() | |
212 | { |
|
223 | { | |
213 |
|
224 | |||
214 | } |
|
225 | } | |
215 |
|
226 | |||
216 | #include "moc_qchartview.cpp" |
|
227 | #include "moc_qchartview.cpp" | |
217 |
|
228 | |||
218 | QTCOMMERCIALCHART_END_NAMESPACE |
|
229 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,71 +1,72 | |||||
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 | #ifndef QCHARTVIEW_H |
|
21 | #ifndef QCHARTVIEW_H | |
22 | #define QCHARTVIEW_H |
|
22 | #define QCHARTVIEW_H | |
23 |
|
23 | |||
24 | #include <QAxis> |
|
24 | #include <QAxis> | |
25 | #include <QAbstractSeries> |
|
25 | #include <QAbstractSeries> | |
26 | #include <QChart> |
|
26 | #include <QChart> | |
27 | #include <QGraphicsView> |
|
27 | #include <QGraphicsView> | |
28 |
|
28 | |||
29 | class QGraphicsScene; |
|
29 | class QGraphicsScene; | |
30 | class QRubberBand; |
|
30 | class QRubberBand; | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | struct QChartViewPrivate; |
|
34 | struct QChartViewPrivate; | |
35 |
|
35 | |||
36 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView |
|
36 | class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView | |
37 | { |
|
37 | { | |
38 | Q_OBJECT |
|
38 | Q_OBJECT | |
39 | Q_ENUMS(RubberBand) |
|
39 | Q_ENUMS(RubberBand) | |
40 | public: |
|
40 | public: | |
41 |
|
41 | |||
42 | enum RubberBand{ |
|
42 | enum RubberBand{ | |
43 | NoRubberBand = 0x0, |
|
43 | NoRubberBand = 0x0, | |
44 | VerticalRubberBand = 0x1, |
|
44 | VerticalRubberBand = 0x1, | |
45 | HorizonalRubberBand = 0x2, |
|
45 | HorizonalRubberBand = 0x2, | |
46 | RectangleRubberBand = 0x3 |
|
46 | RectangleRubberBand = 0x3 | |
47 | }; |
|
47 | }; | |
48 |
|
48 | |||
49 | Q_DECLARE_FLAGS(RubberBands, RubberBand) |
|
49 | Q_DECLARE_FLAGS(RubberBands, RubberBand) | |
50 |
|
50 | |||
|
51 | explicit QChartView(QWidget *parent = 0); | |||
51 | explicit QChartView(QChart *chart,QWidget *parent = 0); |
|
52 | explicit QChartView(QChart *chart,QWidget *parent = 0); | |
52 | ~QChartView(); |
|
53 | ~QChartView(); | |
53 |
|
54 | |||
54 | void setRubberBand(const RubberBands& rubberBands); |
|
55 | void setRubberBand(const RubberBands& rubberBands); | |
55 | RubberBands rubberBand() const; |
|
56 | RubberBands rubberBand() const; | |
56 | QChart* chart() const; |
|
57 | QChart* chart() const; | |
57 |
|
58 | |||
58 | protected: |
|
59 | protected: | |
59 | void resizeEvent(QResizeEvent *event); |
|
60 | void resizeEvent(QResizeEvent *event); | |
60 | void mousePressEvent(QMouseEvent *event); |
|
61 | void mousePressEvent(QMouseEvent *event); | |
61 | void mouseMoveEvent(QMouseEvent *event); |
|
62 | void mouseMoveEvent(QMouseEvent *event); | |
62 | void mouseReleaseEvent(QMouseEvent *event); |
|
63 | void mouseReleaseEvent(QMouseEvent *event); | |
63 |
|
64 | |||
64 | protected: |
|
65 | protected: | |
65 | QScopedPointer<QChartViewPrivate> d_ptr; |
|
66 | QScopedPointer<QChartViewPrivate> d_ptr; | |
66 | Q_DISABLE_COPY(QChartView) |
|
67 | Q_DISABLE_COPY(QChartView) | |
67 | }; |
|
68 | }; | |
68 |
|
69 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
71 | |||
71 | #endif // QCHARTWIDGET_H |
|
72 | #endif // QCHARTWIDGET_H |
@@ -1,56 +1,62 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QCHARTVIEW_P_H |
|
30 | #ifndef QCHARTVIEW_P_H | |
31 | #define QCHARTVIEW_P_H |
|
31 | #define QCHARTVIEW_P_H | |
32 |
|
32 | |||
33 | #include "qchartview.h" |
|
33 | #include "qchartview.h" | |
34 |
|
34 | |||
35 | class QGraphicsScene; |
|
35 | class QGraphicsScene; | |
36 | class ChartPresenter; |
|
36 | class ChartPresenter; | |
37 |
|
37 | |||
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 |
|
39 | |||
40 | class QChart; |
|
40 | class QChart; | |
|
41 | class QChartView; | |||
41 |
|
42 | |||
42 |
|
|
43 | class QChartViewPrivate { | |
43 |
|
44 | |||
44 | QChartViewPrivate(); |
|
45 | public: | |
|
46 | QChartViewPrivate(QChartView *q,QChart *chart = 0); | |||
45 | ~QChartViewPrivate(); |
|
47 | ~QChartViewPrivate(); | |
46 |
|
48 | |||
|
49 | protected: | |||
|
50 | QChartView *q_ptr; | |||
|
51 | ||||
|
52 | public: | |||
47 | QGraphicsScene *m_scene; |
|
53 | QGraphicsScene *m_scene; | |
48 | QChart *m_chart; |
|
54 | QChart *m_chart; | |
49 | ChartPresenter *m_presenter; |
|
55 | ChartPresenter *m_presenter; | |
50 | QPoint m_rubberBandOrigin; |
|
56 | QPoint m_rubberBandOrigin; | |
51 | QRubberBand *m_rubberBand; |
|
57 | QRubberBand *m_rubberBand; | |
52 | QChartView::RubberBands m_rubberBandFlags; |
|
58 | QChartView::RubberBands m_rubberBandFlags; | |
53 | }; |
|
59 | }; | |
54 |
|
60 | |||
55 | QTCOMMERCIALCHART_END_NAMESPACE |
|
61 | QTCOMMERCIALCHART_END_NAMESPACE | |
56 | #endif |
|
62 | #endif |
@@ -1,171 +1,177 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qlineseries.h> |
|
23 | #include <qlineseries.h> | |
24 | #include <cmath> |
|
24 | #include <cmath> | |
25 | #include <tst_definitions.h> |
|
25 | #include <tst_definitions.h> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
27 | QTCOMMERCIALCHART_USE_NAMESPACE | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QChart*) |
|
30 | Q_DECLARE_METATYPE(QChart*) | |
31 | Q_DECLARE_METATYPE(QChartView::RubberBands) |
|
31 | Q_DECLARE_METATYPE(QChartView::RubberBands) | |
32 | Q_DECLARE_METATYPE(Qt::Key) |
|
32 | Q_DECLARE_METATYPE(Qt::Key) | |
33 |
|
33 | |||
34 | class tst_QChartView : public QObject |
|
34 | class tst_QChartView : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public Q_SLOTS: |
|
38 | public Q_SLOTS: | |
39 | void initTestCase(); |
|
39 | void initTestCase(); | |
40 | void cleanupTestCase(); |
|
40 | void cleanupTestCase(); | |
41 | void init(); |
|
41 | void init(); | |
42 | void cleanup(); |
|
42 | void cleanup(); | |
43 |
|
43 | |||
44 | private Q_SLOTS: |
|
44 | private Q_SLOTS: | |
45 | void qchartview_data(); |
|
45 | void qchartview_data(); | |
46 | void qchartview(); |
|
46 | void qchartview(); | |
47 | void chart_data(); |
|
47 | void chart_data(); | |
48 | void chart(); |
|
48 | void chart(); | |
49 | void rubberBand_data(); |
|
49 | void rubberBand_data(); | |
50 | void rubberBand(); |
|
50 | void rubberBand(); | |
51 |
|
51 | |||
52 | private: |
|
52 | private: | |
53 | QChartView* m_view; |
|
53 | QChartView* m_view; | |
54 | }; |
|
54 | }; | |
55 |
|
55 | |||
56 | void tst_QChartView::initTestCase() |
|
56 | void tst_QChartView::initTestCase() | |
57 | { |
|
57 | { | |
58 | //test tracks mouse, give a while to user to relese it |
|
58 | //test tracks mouse, give a while to user to relese it | |
59 | QTest::qWait(1000); |
|
59 | QTest::qWait(1000); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void tst_QChartView::cleanupTestCase() |
|
62 | void tst_QChartView::cleanupTestCase() | |
63 | { |
|
63 | { | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void tst_QChartView::init() |
|
66 | void tst_QChartView::init() | |
67 | { |
|
67 | { | |
68 | m_view = new QChartView(new QChart()); |
|
68 | m_view = new QChartView(new QChart()); | |
69 | m_view->chart()->legend()->setVisible(false); |
|
69 | m_view->chart()->legend()->setVisible(false); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void tst_QChartView::cleanup() |
|
72 | void tst_QChartView::cleanup() | |
73 | { |
|
73 | { | |
74 | delete m_view; |
|
74 | delete m_view; | |
75 | m_view =0; |
|
75 | m_view =0; | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | void tst_QChartView::qchartview_data() |
|
78 | void tst_QChartView::qchartview_data() | |
79 | { |
|
79 | { | |
80 |
|
80 | |||
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | void tst_QChartView::qchartview() |
|
83 | void tst_QChartView::qchartview() | |
84 | { |
|
84 | { | |
85 | QVERIFY(m_view->chart()); |
|
85 | QVERIFY(m_view->chart()); | |
86 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); |
|
86 | QCOMPARE(m_view->rubberBand(), QChartView::NoRubberBand); | |
87 | m_view->show(); |
|
87 | m_view->show(); | |
88 | QTest::qWaitForWindowShown(m_view); |
|
88 | QTest::qWaitForWindowShown(m_view); | |
|
89 | ||||
|
90 | delete(new QChartView()); | |||
|
91 | ||||
|
92 | QChartView view; | |||
|
93 | QVERIFY(view.chart()); | |||
|
94 | ||||
89 | } |
|
95 | } | |
90 |
|
96 | |||
91 | void tst_QChartView::chart_data() |
|
97 | void tst_QChartView::chart_data() | |
92 | { |
|
98 | { | |
93 |
|
99 | |||
94 | QTest::addColumn<QChart*>("chart"); |
|
100 | QTest::addColumn<QChart*>("chart"); | |
95 | QTest::newRow("qchart") << new QChart(); |
|
101 | QTest::newRow("qchart") << new QChart(); | |
96 | } |
|
102 | } | |
97 |
|
103 | |||
98 | void tst_QChartView::chart() |
|
104 | void tst_QChartView::chart() | |
99 | { |
|
105 | { | |
100 | QFETCH(QChart*, chart); |
|
106 | QFETCH(QChart*, chart); | |
101 | QChartView* view = new QChartView(chart); |
|
107 | QChartView* view = new QChartView(chart); | |
102 | QCOMPARE(view->chart(), chart); |
|
108 | QCOMPARE(view->chart(), chart); | |
103 | delete view; |
|
109 | delete view; | |
104 | } |
|
110 | } | |
105 |
|
111 | |||
106 | void tst_QChartView::rubberBand_data() |
|
112 | void tst_QChartView::rubberBand_data() | |
107 | { |
|
113 | { | |
108 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); |
|
114 | QTest::addColumn<QChartView::RubberBands>("rubberBand"); | |
109 | QTest::addColumn<int>("Xcount"); |
|
115 | QTest::addColumn<int>("Xcount"); | |
110 | QTest::addColumn<int>("Ycount"); |
|
116 | QTest::addColumn<int>("Ycount"); | |
111 |
|
117 | |||
112 | QTest::addColumn<int>("minX"); |
|
118 | QTest::addColumn<int>("minX"); | |
113 | QTest::addColumn<int>("maxX"); |
|
119 | QTest::addColumn<int>("maxX"); | |
114 | QTest::addColumn<int>("minY"); |
|
120 | QTest::addColumn<int>("minY"); | |
115 | QTest::addColumn<int>("maxY"); |
|
121 | QTest::addColumn<int>("maxY"); | |
116 |
|
122 | |||
117 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; |
|
123 | QTest::newRow("HorizonalRubberBand") << QChartView::RubberBands(QChartView::HorizonalRubberBand) << 0 << 1 << 20 << 180 << 0<< 200; | |
118 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; |
|
124 | QTest::newRow("VerticalRubberBand") << QChartView::RubberBands(QChartView::VerticalRubberBand) << 1 << 0 << 0 << 200 << 20<< 180; | |
119 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; |
|
125 | QTest::newRow("RectangleRubberBand") << QChartView::RubberBands(QChartView::RectangleRubberBand) << 1 << 1 <<20 << 180 << 20<< 180; | |
120 | } |
|
126 | } | |
121 |
|
127 | |||
122 | void tst_QChartView::rubberBand() |
|
128 | void tst_QChartView::rubberBand() | |
123 | { |
|
129 | { | |
124 | QFETCH(QChartView::RubberBands, rubberBand); |
|
130 | QFETCH(QChartView::RubberBands, rubberBand); | |
125 | QFETCH(int, Xcount); |
|
131 | QFETCH(int, Xcount); | |
126 | QFETCH(int, Ycount); |
|
132 | QFETCH(int, Ycount); | |
127 | QFETCH(int, minX); |
|
133 | QFETCH(int, minX); | |
128 | QFETCH(int, maxX); |
|
134 | QFETCH(int, maxX); | |
129 | QFETCH(int, minY); |
|
135 | QFETCH(int, minY); | |
130 | QFETCH(int, maxY); |
|
136 | QFETCH(int, maxY); | |
131 |
|
137 | |||
132 | m_view->setRubberBand(rubberBand); |
|
138 | m_view->setRubberBand(rubberBand); | |
133 | QRectF padding = m_view->chart()->margins(); |
|
139 | QRectF padding = m_view->chart()->margins(); | |
134 | QCOMPARE(m_view->rubberBand(), rubberBand); |
|
140 | QCOMPARE(m_view->rubberBand(), rubberBand); | |
135 |
|
141 | |||
136 | QLineSeries* line = new QLineSeries(); |
|
142 | QLineSeries* line = new QLineSeries(); | |
137 | *line << QPointF(0, 0) << QPointF(200, 200); |
|
143 | *line << QPointF(0, 0) << QPointF(200, 200); | |
138 |
|
144 | |||
139 | m_view->chart()->addSeries(line); |
|
145 | m_view->chart()->addSeries(line); | |
140 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); |
|
146 | m_view->resize(200 + padding.left() + padding.right(), 200 + padding.top()+ padding.bottom()); | |
141 | m_view->show(); |
|
147 | m_view->show(); | |
142 |
|
148 | |||
143 | //this is hack since view does not get events otherwise |
|
149 | //this is hack since view does not get events otherwise | |
144 | m_view->setMouseTracking(true); |
|
150 | m_view->setMouseTracking(true); | |
145 |
|
151 | |||
146 | QAxis* axisY = m_view->chart()->axisY(); |
|
152 | QAxis* axisY = m_view->chart()->axisY(); | |
147 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); |
|
153 | QSignalSpy spy0(axisY, SIGNAL(rangeChanged(qreal,qreal))); | |
148 | QAxis* axisX = m_view->chart()->axisX(); |
|
154 | QAxis* axisX = m_view->chart()->axisX(); | |
149 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); |
|
155 | QSignalSpy spy1(axisX, SIGNAL(rangeChanged(qreal,qreal))); | |
150 |
|
156 | |||
151 | QTest::qWaitForWindowShown(m_view); |
|
157 | QTest::qWaitForWindowShown(m_view); | |
152 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
158 | QTest::mouseMove(m_view->viewport(), QPoint(minX, minY) + padding.topLeft().toPoint()); | |
153 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); |
|
159 | QTest::mousePress(m_view->viewport(), Qt::LeftButton, 0, QPoint(minX, minY) + padding.topLeft().toPoint()); | |
154 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); |
|
160 | QTest::mouseMove(m_view->viewport(), QPoint(maxX, maxY) + padding.topLeft().toPoint()); | |
155 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); |
|
161 | QTest::mouseRelease(m_view->viewport(), Qt::LeftButton, 0, QPoint(maxX, maxY)+ padding.topLeft().toPoint()); | |
156 |
|
162 | |||
157 | TRY_COMPARE(spy0.count(), Xcount); |
|
163 | TRY_COMPARE(spy0.count(), Xcount); | |
158 | TRY_COMPARE(spy1.count(), Ycount); |
|
164 | TRY_COMPARE(spy1.count(), Ycount); | |
159 |
|
165 | |||
160 | //this is hack since view does not get events otherwise |
|
166 | //this is hack since view does not get events otherwise | |
161 | m_view->setMouseTracking(false); |
|
167 | m_view->setMouseTracking(false); | |
162 |
|
168 | |||
163 | QVERIFY(axisX->min() - minX < 1); |
|
169 | QVERIFY(axisX->min() - minX < 1); | |
164 | QVERIFY(axisX->max() - maxX < 1); |
|
170 | QVERIFY(axisX->max() - maxX < 1); | |
165 | QVERIFY(axisY->min() - minY < 1); |
|
171 | QVERIFY(axisY->min() - minY < 1); | |
166 | QVERIFY(axisY->max() - maxY < 1); |
|
172 | QVERIFY(axisY->max() - maxY < 1); | |
167 | } |
|
173 | } | |
168 |
|
174 | |||
169 | QTEST_MAIN(tst_QChartView) |
|
175 | QTEST_MAIN(tst_QChartView) | |
170 | #include "tst_qchartview.moc" |
|
176 | #include "tst_qchartview.moc" | |
171 |
|
177 |
General Comments 0
You need to be logged in to leave comments.
Login now