##// END OF EJS Templates
Adds animation settings handling
Michal Klocek -
r298:cf230c2f88fb
parent child
Show More
@@ -79,6 +79,8 void AxisItem::updateItems(QVector<qreal>& vector)
79
79
80 void AxisItem::handleAxisUpdate(QChartAxis* axis)
80 void AxisItem::handleAxisUpdate(QChartAxis* axis)
81 {
81 {
82 if(m_layoutVector.count()==0) return;
83
82 if(axis->isAxisVisible()) {
84 if(axis->isAxisVisible()) {
83 setAxisOpacity(100);
85 setAxisOpacity(100);
84 }
86 }
@@ -130,7 +132,7 void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels)
130 m_thicksList=labels;
132 m_thicksList=labels;
131 m_layoutVector.resize(m_thicksList.size());
133 m_layoutVector.resize(m_thicksList.size());
132 updateItems(m_layoutVector);
134 updateItems(m_layoutVector);
133 handleAxisUpdate(axis);
135 if(diff!=0) handleAxisUpdate(axis);
134 }
136 }
135
137
136 void AxisItem::handleGeometryChanged(const QRectF& rect)
138 void AxisItem::handleGeometryChanged(const QRectF& rect)
@@ -25,6 +25,7 public:
25 void clearDomains(int toIndex =0);
25 void clearDomains(int toIndex =0);
26 const Domain domain(QChartAxis *axisY) const;
26 const Domain domain(QChartAxis *axisY) const;
27 int domainIndex() const {return m_domainIndex;}
27 int domainIndex() const {return m_domainIndex;}
28 void setDomain(int index);
28
29
29 QChartAxis* axisX() const { return m_axisX;};
30 QChartAxis* axisX() const { return m_axisX;};
30 QChartAxis* axisY(QChartSeries* series = 0) const;
31 QChartAxis* axisY(QChartSeries* series = 0) const;
@@ -43,7 +44,6 private slots:
43 void handleTickChanged(QChartAxis*);
44 void handleTickChanged(QChartAxis*);
44
45
45 private:
46 private:
46 void setDomain(int index);
47 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
47 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
48
48
49 private:
49 private:
@@ -12,6 +12,7
12 #include "qscatterseries.h"
12 #include "qscatterseries.h"
13 //items
13 //items
14 #include "axisitem_p.h"
14 #include "axisitem_p.h"
15 #include "axisanimationitem_p.h"
15 #include "barpresenter.h"
16 #include "barpresenter.h"
16 #include "stackedbarpresenter.h"
17 #include "stackedbarpresenter.h"
17 #include "linechartitem_p.h"
18 #include "linechartitem_p.h"
@@ -27,7 +28,8 m_chart(chart),
27 m_dataset(dataset),
28 m_dataset(dataset),
28 m_chartTheme(0),
29 m_chartTheme(0),
29 m_marginSize(0),
30 m_marginSize(0),
30 m_rect(QRectF(QPoint(0,0),m_chart->size()))
31 m_rect(QRectF(QPoint(0,0),m_chart->size())),
32 m_options(0)
31 {
33 {
32 createConnections();
34 createConnections();
33 setChartTheme(QChart::ChartThemeDefault);
35 setChartTheme(QChart::ChartThemeDefault);
@@ -75,13 +77,18 void ChartPresenter::setMargin(int margin)
75
77
76 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
78 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
77 {
79 {
80
78 AxisItem* item ;
81 AxisItem* item ;
79
82
80 if(axis==m_dataset->axisX()){
83 if(!m_options.testFlag(QChart::GridAxisAnimations))
81 item = new AxisItem(AxisItem::X_AXIS,m_chart);
84 {
85 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
86 qDebug()<<"kuku1";
82 }else{
87 }else{
83 item = new AxisItem(AxisItem::Y_AXIS,m_chart);
88 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
89 qDebug()<<"kuku2";
84 }
90 }
91
85 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
92 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
86 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
93 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
87
94
@@ -105,7 +112,12 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
105 {
112 {
106 case QChartSeries::SeriesTypeLine: {
113 case QChartSeries::SeriesTypeLine: {
107 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
114 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
108 LineChartItem* item = new LineChartAnimationItem(this,lineSeries,m_chart);
115 LineChartItem* item;
116 if(m_options.testFlag(QChart::SeriesAnimations)){
117 item = new LineChartAnimationItem(this,lineSeries,m_chart);
118 }else{
119 item = new LineChartItem(this,lineSeries,m_chart);
120 }
109 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
121 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
110 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
122 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
111 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
123 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
@@ -235,6 +247,37 QChart::ChartTheme ChartPresenter::chartTheme()
235 return m_chartTheme->id();
247 return m_chartTheme->id();
236 }
248 }
237
249
250 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
251 {
252 if(m_options!=options) {
253
254 m_options=options;
255
256 //recreate elements
257
258 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
259 QList<QChartSeries*> seriesList = m_chartItems.uniqueKeys();
260
261 foreach(QChartAxis* axis, axisList) {
262 handleAxisRemoved(axis);
263 handleAxisAdded(axis);
264 }
265 foreach(QChartSeries* series, seriesList) {
266 handleSeriesRemoved(series);
267 handleSeriesAdded(series);
268 }
269
270 //now reintialize view data
271 //TODO: make it more nice
272 m_dataset->setDomain(m_dataset->domainIndex());
273 }
274 }
275
276 QChart::AnimationOptions ChartPresenter::animationOptions() const
277 {
278 return m_options;
279 }
280
238
281
239 #include "moc_chartpresenter_p.cpp"
282 #include "moc_chartpresenter_p.cpp"
240
283
@@ -33,6 +33,9 public:
33 void setChartTheme(QChart::ChartTheme theme);
33 void setChartTheme(QChart::ChartTheme theme);
34 QChart::ChartTheme chartTheme();
34 QChart::ChartTheme chartTheme();
35
35
36 void setAnimationOptions(QChart::AnimationOptions options);
37 QChart::AnimationOptions animationOptions() const;
38
36 private:
39 private:
37 void createConnections();
40 void createConnections();
38
41
@@ -55,6 +58,7 private:
55 ChartTheme *m_chartTheme;
58 ChartTheme *m_chartTheme;
56 int m_marginSize;
59 int m_marginSize;
57 QRectF m_rect;
60 QRectF m_rect;
61 QChart::AnimationOptions m_options;
58
62
59 };
63 };
60
64
@@ -253,6 +253,22 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
253 update();
253 update();
254 }
254 }
255
255
256 /*!
257 Sets animation options for the chart
258 */
259 void QChart::setAnimationOptions(AnimationOptions options)
260 {
261 m_presenter->setAnimationOptions(options);
262 }
263
264 /*!
265 Returns animation options for the chart
266 */
267 QChart::AnimationOptions QChart::animationOptions() const
268 {
269 return m_presenter->animationOptions();
270 }
271
256 #include "moc_qchart.cpp"
272 #include "moc_qchart.cpp"
257
273
258 QTCOMMERCIALCHART_END_NAMESPACE
274 QTCOMMERCIALCHART_END_NAMESPACE
@@ -35,6 +35,14 public:
35 /*! The default theme follows the GUI style of the Operating System */
35 /*! The default theme follows the GUI style of the Operating System */
36 };
36 };
37
37
38 enum AnimationOption {
39 NoAnimation = 0x0,
40 GridAxisAnimations = 0x1,
41 SeriesAnimations =0x2,
42 AllAnimations = 0x3
43 };
44 Q_DECLARE_FLAGS(AnimationOptions, AnimationOption)
45
38 public:
46 public:
39 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
47 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
40 ~QChart();
48 ~QChart();
@@ -53,6 +61,9 public:
53 void setChartBackgroundBrush(const QBrush& brush);
61 void setChartBackgroundBrush(const QBrush& brush);
54 void setChartBackgroundPen(const QPen& pen);
62 void setChartBackgroundPen(const QPen& pen);
55
63
64 void setAnimationOptions(AnimationOptions options);
65 AnimationOptions animationOptions() const;
66
56 void zoomIn();
67 void zoomIn();
57 void zoomIn(const QRectF& rect);
68 void zoomIn(const QRectF& rect);
58 void zoomOut();
69 void zoomOut();
@@ -79,4 +90,6 private:
79
90
80 QTCOMMERCIALCHART_END_NAMESPACE
91 QTCOMMERCIALCHART_END_NAMESPACE
81
92
93 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
94
82 #endif
95 #endif
@@ -331,4 +331,20 QChartAxis* QChartView::axisY() const
331 return m_chart->axisY();
331 return m_chart->axisY();
332 }
332 }
333
333
334 /*!
335 Sets animation options for the chart
336 */
337 void QChartView::setAnimationOptions(QChart::AnimationOptions options)
338 {
339 m_chart->setAnimationOptions(options);
340 }
341
342 /*!
343 Returns animation options for the chart
344 */
345 QChart::AnimationOptions QChartView::animationOptions() const
346 {
347 return m_chart->animationOptions();
348 }
349
334 QTCOMMERCIALCHART_END_NAMESPACE
350 QTCOMMERCIALCHART_END_NAMESPACE
@@ -44,6 +44,9 public:
44 void setChartTheme(QChart::ChartTheme theme);
44 void setChartTheme(QChart::ChartTheme theme);
45 QChart::ChartTheme chartTheme() const;
45 QChart::ChartTheme chartTheme() const;
46
46
47 void setAnimationOptions(QChart::AnimationOptions options);
48 QChart::AnimationOptions animationOptions() const;
49
47 QChartAxis* axisX() const;
50 QChartAxis* axisX() const;
48 QChartAxis* axisY() const;
51 QChartAxis* axisY() const;
49
52
General Comments 0
You need to be logged in to leave comments. Login now