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