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