##// 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 80 void AxisItem::handleAxisUpdate(QChartAxis* axis)
81 81 {
82 if(m_layoutVector.count()==0) return;
83
82 84 if(axis->isAxisVisible()) {
83 85 setAxisOpacity(100);
84 86 }
@@ -130,7 +132,7 void AxisItem::handleLabelsChanged(QChartAxis* axis,const QStringList& labels)
130 132 m_thicksList=labels;
131 133 m_layoutVector.resize(m_thicksList.size());
132 134 updateItems(m_layoutVector);
133 handleAxisUpdate(axis);
135 if(diff!=0) handleAxisUpdate(axis);
134 136 }
135 137
136 138 void AxisItem::handleGeometryChanged(const QRectF& rect)
@@ -25,6 +25,7 public:
25 25 void clearDomains(int toIndex =0);
26 26 const Domain domain(QChartAxis *axisY) const;
27 27 int domainIndex() const {return m_domainIndex;}
28 void setDomain(int index);
28 29
29 30 QChartAxis* axisX() const { return m_axisX;};
30 31 QChartAxis* axisY(QChartSeries* series = 0) const;
@@ -43,7 +44,6 private slots:
43 44 void handleTickChanged(QChartAxis*);
44 45
45 46 private:
46 void setDomain(int index);
47 47 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
48 48
49 49 private:
@@ -12,6 +12,7
12 12 #include "qscatterseries.h"
13 13 //items
14 14 #include "axisitem_p.h"
15 #include "axisanimationitem_p.h"
15 16 #include "barpresenter.h"
16 17 #include "stackedbarpresenter.h"
17 18 #include "linechartitem_p.h"
@@ -27,7 +28,8 m_chart(chart),
27 28 m_dataset(dataset),
28 29 m_chartTheme(0),
29 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 34 createConnections();
33 35 setChartTheme(QChart::ChartThemeDefault);
@@ -75,13 +77,18 void ChartPresenter::setMargin(int margin)
75 77
76 78 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
77 79 {
80
78 81 AxisItem* item ;
79 82
80 if(axis==m_dataset->axisX()){
81 item = new AxisItem(AxisItem::X_AXIS,m_chart);
83 if(!m_options.testFlag(QChart::GridAxisAnimations))
84 {
85 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
86 qDebug()<<"kuku1";
82 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 92 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
86 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 113 case QChartSeries::SeriesTypeLine: {
107 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 121 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
110 122 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
111 123 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
@@ -235,6 +247,37 QChart::ChartTheme ChartPresenter::chartTheme()
235 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 282 #include "moc_chartpresenter_p.cpp"
240 283
@@ -33,6 +33,9 public:
33 33 void setChartTheme(QChart::ChartTheme theme);
34 34 QChart::ChartTheme chartTheme();
35 35
36 void setAnimationOptions(QChart::AnimationOptions options);
37 QChart::AnimationOptions animationOptions() const;
38
36 39 private:
37 40 void createConnections();
38 41
@@ -55,6 +58,7 private:
55 58 ChartTheme *m_chartTheme;
56 59 int m_marginSize;
57 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 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 272 #include "moc_qchart.cpp"
257 273
258 274 QTCOMMERCIALCHART_END_NAMESPACE
@@ -25,7 +25,7 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
25 25 {
26 26 Q_OBJECT
27 27 public:
28 enum ChartTheme {
28 enum ChartTheme {
29 29 ChartThemeDefault,
30 30 ChartThemeVanilla,
31 31 ChartThemeIcy,
@@ -35,6 +35,14 public:
35 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 46 public:
39 47 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
40 48 ~QChart();
@@ -53,6 +61,9 public:
53 61 void setChartBackgroundBrush(const QBrush& brush);
54 62 void setChartBackgroundPen(const QPen& pen);
55 63
64 void setAnimationOptions(AnimationOptions options);
65 AnimationOptions animationOptions() const;
66
56 67 void zoomIn();
57 68 void zoomIn(const QRectF& rect);
58 69 void zoomOut();
@@ -79,4 +90,6 private:
79 90
80 91 QTCOMMERCIALCHART_END_NAMESPACE
81 92
93 Q_DECLARE_OPERATORS_FOR_FLAGS(QTCOMMERCIALCHART_NAMESPACE::QChart::AnimationOptions)
94
82 95 #endif
@@ -331,4 +331,20 QChartAxis* QChartView::axisY() const
331 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 350 QTCOMMERCIALCHART_END_NAMESPACE
@@ -44,6 +44,9 public:
44 44 void setChartTheme(QChart::ChartTheme theme);
45 45 QChart::ChartTheme chartTheme() const;
46 46
47 void setAnimationOptions(QChart::AnimationOptions options);
48 QChart::AnimationOptions animationOptions() const;
49
47 50 QChartAxis* axisX() const;
48 51 QChartAxis* axisY() const;
49 52
General Comments 0
You need to be logged in to leave comments. Login now