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