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