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