##// END OF EJS Templates
Enabled animations on QML
Tero Ahola -
r885:7d3819363bdf
parent child
Show More
@@ -1,66 +1,66
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "declarativechart.h"
21 #include "declarativechart.h"
22 #include <QPainter>
22 #include <QPainter>
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
26 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
27 : QDeclarativeItem(parent),
27 : QDeclarativeItem(parent),
28 m_chart(new QChart(this))
28 m_chart(new QChart(this))
29 {
29 {
30 // m_chart->setAnimationOptions(QChart::SeriesAnimations);
30 m_chart->setAnimationOptions(QChart::SeriesAnimations);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
32 }
32 }
33
33
34 DeclarativeChart::~DeclarativeChart()
34 DeclarativeChart::~DeclarativeChart()
35 {
35 {
36 delete m_chart;
36 delete m_chart;
37 }
37 }
38
38
39 QChart::ChartTheme DeclarativeChart::theme()
39 QChart::ChartTheme DeclarativeChart::theme()
40 {
40 {
41 return m_chart->theme();
41 return m_chart->theme();
42 }
42 }
43
43
44 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
44 void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
45 {
45 {
46 Q_UNUSED(oldGeometry)
46 Q_UNUSED(oldGeometry)
47
47
48 if (newGeometry.isValid()) {
48 if (newGeometry.isValid()) {
49 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
49 if (newGeometry.width() > 0 && newGeometry.height() > 0) {
50 m_chart->resize(newGeometry.width(), newGeometry.height());
50 m_chart->resize(newGeometry.width(), newGeometry.height());
51 }
51 }
52 }
52 }
53 }
53 }
54
54
55 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
55 void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
56 {
56 {
57 Q_UNUSED(option)
57 Q_UNUSED(option)
58 Q_UNUSED(widget)
58 Q_UNUSED(widget)
59
59
60 // TODO: optimized?
60 // TODO: optimized?
61 painter->setRenderHint(QPainter::Antialiasing, true);
61 painter->setRenderHint(QPainter::Antialiasing, true);
62 }
62 }
63
63
64 #include "moc_declarativechart.cpp"
64 #include "moc_declarativechart.cpp"
65
65
66 QTCOMMERCIALCHART_END_NAMESPACE
66 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,57 +1,58
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVECHART_H
21 #ifndef DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
22 #define DECLARATIVECHART_H
23
23
24 #include <QtCore/QtGlobal>
24 #include <QtCore/QtGlobal>
25 #include <QDeclarativeItem>
25 #include <QDeclarativeItem>
26 #include <qchart.h>
26 #include <qchart.h>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 // TODO: Derive from QChart for easier definition of properties?
30 class DeclarativeChart : public QDeclarativeItem
31 class DeclarativeChart : public QDeclarativeItem
31 // TODO: for QTQUICK2: extend QQuickPainterItem instead
32 // TODO: for QTQUICK2: extend QQuickPainterItem instead
32 //class DeclarativeChart : public QQuickPaintedItem, public Chart
33 //class DeclarativeChart : public QQuickPaintedItem, public Chart
33 {
34 {
34 Q_OBJECT
35 Q_OBJECT
35 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
36 Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme)
36
37
37 public:
38 public:
38 DeclarativeChart(QDeclarativeItem *parent = 0);
39 DeclarativeChart(QDeclarativeItem *parent = 0);
39 ~DeclarativeChart();
40 ~DeclarativeChart();
40
41
41 public: // From QDeclarativeItem/QGraphicsItem
42 public: // From QDeclarativeItem/QGraphicsItem
42 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
43 void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
43 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
44 void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
44
45
45 public:
46 public:
46 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
47 void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);}
47 QChart::ChartTheme theme();
48 QChart::ChartTheme theme();
48
49
49 public:
50 public:
50 // Extending QChart with DeclarativeChart is not possible because QObject does not support
51 // Extending QChart with DeclarativeChart is not possible because QObject does not support
51 // multi inheritance, so we now have a QChart as a member instead
52 // multi inheritance, so we now have a QChart as a member instead
52 QChart *m_chart;
53 QChart *m_chart;
53 };
54 };
54
55
55 QTCOMMERCIALCHART_END_NAMESPACE
56 QTCOMMERCIALCHART_END_NAMESPACE
56
57
57 #endif // DECLARATIVECHART_H
58 #endif // DECLARATIVECHART_H
@@ -1,146 +1,147
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 Rectangle {
24 Rectangle {
25 width: parent.width
25 width: parent.width
26 height: parent.height
26 height: parent.height
27
27
28 // Another option for QML data api:
28 // Another option for QML data api:
29 // ListModel {
29 // ListModel {
30 // id: listModelForPie
30 // id: listModelForPie
31 // // PieDataElement
31 // // PieDataElement
32 // ListElement {
32 // ListElement {
33 // label: "Apple"
33 // label: "Apple"
34 // value: 4.3
34 // value: 4.3
35 // }
35 // }
36 // ListElement {
36 // ListElement {
37 // label: "Blackberry"
37 // label: "Blackberry"
38 // value: 15.1
38 // value: 15.1
39 // }
39 // }
40 // }
40 // }
41
41
42 Component.onCompleted: {
42 Component.onCompleted: {
43 // console.log("model:" + myModel.item(0));
43 // console.log("model:" + myModel.item(0));
44 // myModel.insert(1, {"time":1.4; "speed":41.1 });
44 // myModel.insert(1, {"time":1.4; "speed":41.1 });
45 // scatter.appendData();
45 // scatter.appendData();
46 // chart1.theme = Chart.ThemeHighContrast;
46 // chart1.theme = Chart.ThemeHighContrast;
47 // chart2.theme = Chart.ThemeHighContrast;
47 // chart2.theme = Chart.ThemeHighContrast;
48 }
48 }
49
49
50
50
51 Chart {
51 Chart {
52 id: chart1
52 id: chart1
53 anchors.top: parent.top
53 anchors.top: parent.top
54 anchors.left: parent.left
54 anchors.left: parent.left
55 anchors.right: parent.right
55 anchors.right: parent.right
56 height: parent.height / 2
56 height: parent.height / 2
57 theme: Chart.ChartThemeDark
57 theme: Chart.ChartThemeDark
58
58
59 BarSeries {
59 BarSeries {
60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
60 barCategories: [ "2008", "2009", "2010", "2011", "2012" ]
61 // TBD: data
61 // TBD: data
62 }
62 }
63
63
64 PieSeries {
64 PieSeries {
65 horizontalPosition: 0.2
65 horizontalPosition: 0.2
66 verticalPosition: 0.3
66 verticalPosition: 0.3
67 size: 0.4
67 size: 0.4
68 endAngle: 0.52 * 360 // The share of "others" is 52%
68 endAngle: 0.52 * 360 // The share of "others" is 52%
69 slices: [
69 slices: [
70 PieSlice { label: "Volkswagen"; value: 13.5 },
70 PieSlice { label: "Volkswagen"; value: 13.5 },
71 PieSlice { label: "Toyota"; value: 10.9 },
71 PieSlice { label: "Toyota"; value: 10.9 },
72 PieSlice { label: "Ford"; value: 8.6 },
72 PieSlice { label: "Ford"; value: 8.6 },
73 PieSlice { label: "Skoda"; value: 8.2 },
73 PieSlice { label: "Skoda"; value: 8.2 },
74 PieSlice { label: "Volvo"; value: 6.8 }
74 PieSlice { label: "Volvo"; value: 6.8 }
75 ]
75 ]
76 }
76 }
77 }
77 }
78
78
79
79
80 Chart {
80 Chart {
81 id: chart2
81 id: chart2
82 anchors.top: chart1.bottom
82 anchors.top: chart1.bottom
83 anchors.bottom: parent.bottom
83 anchors.bottom: parent.bottom
84 anchors.left: parent.left
84 anchors.left: parent.left
85 anchors.right: parent.right
85 anchors.right: parent.right
86 theme: Chart.ChartThemeBrownSand
86 theme: Chart.ChartThemeBrownSand
87
87
88 LineSeries {
88 LineSeries {
89 name: "Line"
89 name: "Line"
90 points: [
90 points: [
91 XyPoint { x: 0.0; y: 0.0 },
91 XyPoint { x: 0.0; y: 0.0 },
92 XyPoint { x: 1.1; y: 2.1 },
92 XyPoint { x: 1.1; y: 2.1 },
93 XyPoint { x: 2.9; y: 4.9 },
93 XyPoint { x: 2.9; y: 4.9 },
94 XyPoint { x: 3.2; y: 3.0 }
94 XyPoint { x: 3.2; y: 3.0 }
95 ]
95 ]
96 }
96 }
97
97
98 SplineSeries {
98 SplineSeries {
99 name: "Spline"
99 name: "Spline"
100 points: [
100 points: [
101 XyPoint { x: 0.0; y: 0.3 },
101 XyPoint { x: 0.0; y: 0.3 },
102 XyPoint { x: 1.1; y: 3.2 },
102 XyPoint { x: 1.1; y: 3.2 },
103 XyPoint { x: 2.17; y: 2.15 },
103 XyPoint { x: 4.17; y: 3.15 }
104 XyPoint { x: 4.17; y: 3.15 }
104 ]
105 ]
105 }
106 }
106
107
107 AreaSeries {
108 AreaSeries {
108 name: "Area"
109 name: "Area"
109 points: [
110 points: [
110 XyPoint { x: 0.0; y: 1.1 },
111 XyPoint { x: 0.0; y: 1.1 },
111 XyPoint { x: 2.5; y: 3.6 },
112 XyPoint { x: 2.5; y: 3.6 },
112 XyPoint { x: 3.57; y: 2.55 }
113 XyPoint { x: 3.57; y: 2.55 }
113 ]
114 ]
114 lowerPoints: [
115 lowerPoints: [
115 XyPoint { x: 0.0; y: 0.0 },
116 XyPoint { x: 0.0; y: 0.0 },
116 XyPoint { x: 2.5; y: 0.0 },
117 XyPoint { x: 2.5; y: 0.0 },
117 XyPoint { x: 3.57; y: 0.0 }
118 XyPoint { x: 3.57; y: 0.0 }
118 ]
119 ]
119 }
120 }
120
121
121 ScatterSeries {
122 ScatterSeries {
122 name: "Scatter1"
123 name: "Scatter1"
123 points: [
124 points: [
124 XyPoint { x: 1.5; y: 1.5 },
125 XyPoint { x: 1.5; y: 1.5 },
125 XyPoint { x: 1.5; y: 1.6 },
126 XyPoint { x: 1.5; y: 1.6 },
126 XyPoint { x: 1.57; y: 1.55 }
127 XyPoint { x: 1.57; y: 1.55 }
127 ]
128 ]
128 }
129 }
129 ScatterSeries {
130 ScatterSeries {
130 name: "Scatter2"
131 name: "Scatter2"
131 points: [
132 points: [
132 XyPoint { x: 2.0; y: 2.0 },
133 XyPoint { x: 2.0; y: 2.0 },
133 XyPoint { x: 2.0; y: 2.1 },
134 XyPoint { x: 2.0; y: 2.1 },
134 XyPoint { x: 2.07; y: 2.05 }
135 XyPoint { x: 2.07; y: 2.05 }
135 ]
136 ]
136 }
137 }
137 ScatterSeries {
138 ScatterSeries {
138 name: "Scatter3"
139 name: "Scatter3"
139 points: [
140 points: [
140 XyPoint { x: 2.6; y: 2.6 },
141 XyPoint { x: 2.6; y: 2.6 },
141 XyPoint { x: 2.6; y: 2.7 },
142 XyPoint { x: 2.6; y: 2.7 },
142 XyPoint { x: 2.67; y: 2.65 }
143 XyPoint { x: 2.67; y: 2.65 }
143 ]
144 ]
144 }
145 }
145 }
146 }
146 }
147 }
General Comments 0
You need to be logged in to leave comments. Login now