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