@@ -1,51 +1,52 | |||
|
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 | anchors.fill: parent |
|
26 | 26 | |
|
27 | 27 | Chart { |
|
28 | 28 | title: "Car brand shares in Finland" |
|
29 | 29 | anchors.fill: parent |
|
30 | 30 | theme: Chart.ChartThemeLight |
|
31 | legend: Chart.LegendBottom | |
|
31 | 32 | |
|
32 | 33 | PieSeries { |
|
33 | 34 | horizontalPosition: 0.2 |
|
34 | 35 | verticalPosition: 0.3 |
|
35 | 36 | size: 0.4 |
|
36 | 37 | slices: [ |
|
37 | 38 | PieSlice { label: "Volkswagen"; value: 13.5 }, |
|
38 | 39 | PieSlice { label: "Toyota"; value: 10.9 }, |
|
39 | 40 | PieSlice { label: "Ford"; value: 8.6 }, |
|
40 | 41 | PieSlice { label: "Skoda"; value: 8.2 }, |
|
41 | 42 | PieSlice { label: "Volvo"; value: 6.8 }, |
|
42 | 43 | PieSlice { label: "Others"; value: 52.0 } |
|
43 | 44 | ] |
|
44 | 45 | } |
|
45 | 46 | |
|
46 | 47 | BarSeries { |
|
47 | 48 | barCategories: [ "2008", "2009", "2010", "2011", "2012" ] |
|
48 | 49 | // data implementation missing |
|
49 | 50 | } |
|
50 | 51 | } |
|
51 | 52 | } |
@@ -1,128 +1,129 | |||
|
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 | anchors.fill: parent |
|
26 | 26 | |
|
27 | 27 | Chart { |
|
28 | 28 | title: "NHL All-Star Team Players" |
|
29 | 29 | anchors.fill: parent |
|
30 | 30 | theme: Chart.ChartThemeHighContrast |
|
31 | legend: Chart.LegendTop | |
|
31 | 32 | |
|
32 | 33 | AreaSeries { |
|
33 | 34 | name: "Finnish" |
|
34 | 35 | points: [ |
|
35 | 36 | XyPoint { x: 0; y: 0 }, |
|
36 | 37 | XyPoint { x: 1; y: 0 }, |
|
37 | 38 | XyPoint { x: 2; y: 0 }, |
|
38 | 39 | XyPoint { x: 3; y: 0 }, |
|
39 | 40 | XyPoint { x: 4; y: 0 }, |
|
40 | 41 | XyPoint { x: 5; y: 0 }, |
|
41 | 42 | XyPoint { x: 6; y: 1 }, |
|
42 | 43 | XyPoint { x: 7; y: 0 }, |
|
43 | 44 | XyPoint { x: 8; y: 0 }, |
|
44 | 45 | XyPoint { x: 9; y: 0 }, |
|
45 | 46 | XyPoint { x: 10; y: 0 }, |
|
46 | 47 | XyPoint { x: 11; y: 1 } |
|
47 | 48 | ] |
|
48 | 49 | lowerPoints: [ |
|
49 | 50 | XyPoint { x: 0; y: 0 }, |
|
50 | 51 | XyPoint { x: 1; y: 0 }, |
|
51 | 52 | XyPoint { x: 2; y: 0 }, |
|
52 | 53 | XyPoint { x: 3; y: 0 }, |
|
53 | 54 | XyPoint { x: 4; y: 0 }, |
|
54 | 55 | XyPoint { x: 5; y: 0 }, |
|
55 | 56 | XyPoint { x: 6; y: 0 }, |
|
56 | 57 | XyPoint { x: 7; y: 0 }, |
|
57 | 58 | XyPoint { x: 8; y: 0 }, |
|
58 | 59 | XyPoint { x: 9; y: 0 }, |
|
59 | 60 | XyPoint { x: 10; y: 0 }, |
|
60 | 61 | XyPoint { x: 11; y: 0 } |
|
61 | 62 | ] |
|
62 | 63 | } |
|
63 | 64 | |
|
64 | 65 | AreaSeries { |
|
65 | 66 | name: "Russian" |
|
66 | 67 | points: [ |
|
67 | 68 | XyPoint { x: 0; y: 1 }, |
|
68 | 69 | XyPoint { x: 1; y: 1 }, |
|
69 | 70 | XyPoint { x: 2; y: 1 }, |
|
70 | 71 | XyPoint { x: 3; y: 1 }, |
|
71 | 72 | XyPoint { x: 4; y: 1 }, |
|
72 | 73 | XyPoint { x: 5; y: 0 }, |
|
73 | 74 | XyPoint { x: 6; y: 1 }, |
|
74 | 75 | XyPoint { x: 7; y: 1 }, |
|
75 | 76 | XyPoint { x: 8; y: 4 }, |
|
76 | 77 | XyPoint { x: 9; y: 3 }, |
|
77 | 78 | XyPoint { x: 10; y: 2 }, |
|
78 | 79 | XyPoint { x: 11; y: 1 } |
|
79 | 80 | ] |
|
80 | 81 | lowerPoints: [ |
|
81 | 82 | XyPoint { x: 0; y: 0 }, |
|
82 | 83 | XyPoint { x: 1; y: 0 }, |
|
83 | 84 | XyPoint { x: 2; y: 0 }, |
|
84 | 85 | XyPoint { x: 3; y: 0 }, |
|
85 | 86 | XyPoint { x: 4; y: 0 }, |
|
86 | 87 | XyPoint { x: 5; y: 0 }, |
|
87 | 88 | XyPoint { x: 6; y: 0 }, |
|
88 | 89 | XyPoint { x: 7; y: 0 }, |
|
89 | 90 | XyPoint { x: 8; y: 0 }, |
|
90 | 91 | XyPoint { x: 9; y: 0 }, |
|
91 | 92 | XyPoint { x: 10; y: 0 }, |
|
92 | 93 | XyPoint { x: 11; y: 0 } |
|
93 | 94 | ] |
|
94 | 95 | } |
|
95 | 96 | |
|
96 | 97 | AreaSeries { |
|
97 | 98 | name: "Swedish" |
|
98 | 99 | points: [ |
|
99 | 100 | XyPoint { x: 0; y: 1 }, |
|
100 | 101 | XyPoint { x: 1; y: 1 }, |
|
101 | 102 | XyPoint { x: 2; y: 3 }, |
|
102 | 103 | XyPoint { x: 3; y: 3 }, |
|
103 | 104 | XyPoint { x: 4; y: 2 }, |
|
104 | 105 | XyPoint { x: 5; y: 0 }, |
|
105 | 106 | XyPoint { x: 6; y: 2 }, |
|
106 | 107 | XyPoint { x: 7; y: 1 }, |
|
107 | 108 | XyPoint { x: 8; y: 2 }, |
|
108 | 109 | XyPoint { x: 9; y: 1 }, |
|
109 | 110 | XyPoint { x: 10; y: 3 }, |
|
110 | 111 | XyPoint { x: 11; y: 3 } |
|
111 | 112 | ] |
|
112 | 113 | lowerPoints: [ |
|
113 | 114 | XyPoint { x: 0; y: 0 }, |
|
114 | 115 | XyPoint { x: 1; y: 0 }, |
|
115 | 116 | XyPoint { x: 2; y: 0 }, |
|
116 | 117 | XyPoint { x: 3; y: 0 }, |
|
117 | 118 | XyPoint { x: 4; y: 0 }, |
|
118 | 119 | XyPoint { x: 5; y: 0 }, |
|
119 | 120 | XyPoint { x: 6; y: 0 }, |
|
120 | 121 | XyPoint { x: 7; y: 0 }, |
|
121 | 122 | XyPoint { x: 8; y: 0 }, |
|
122 | 123 | XyPoint { x: 9; y: 0 }, |
|
123 | 124 | XyPoint { x: 10; y: 0 }, |
|
124 | 125 | XyPoint { x: 11; y: 0 } |
|
125 | 126 | ] |
|
126 | 127 | } |
|
127 | 128 | } |
|
128 | 129 | } |
@@ -1,78 +1,115 | |||
|
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 | m_chart(new QChart(this)) | |
|
28 | m_chart(new QChart(this)), | |
|
29 | m_legend(LegendDisabled) | |
|
29 | 30 | { |
|
30 | 31 | m_chart->setAnimationOptions(QChart::SeriesAnimations); |
|
31 | 32 | setFlag(QGraphicsItem::ItemHasNoContents, false); |
|
32 | 33 | } |
|
33 | 34 | |
|
34 | 35 | DeclarativeChart::~DeclarativeChart() |
|
35 | 36 | { |
|
36 | 37 | delete m_chart; |
|
37 | 38 | } |
|
38 | 39 | |
|
39 | 40 | void DeclarativeChart::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) |
|
40 | 41 | { |
|
41 | 42 | Q_UNUSED(oldGeometry) |
|
42 | 43 | |
|
43 | 44 | if (newGeometry.isValid()) { |
|
44 | 45 | if (newGeometry.width() > 0 && newGeometry.height() > 0) { |
|
45 | 46 | m_chart->resize(newGeometry.width(), newGeometry.height()); |
|
46 | 47 | } |
|
47 | 48 | } |
|
48 | 49 | } |
|
49 | 50 | |
|
50 | 51 | void DeclarativeChart::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
51 | 52 | { |
|
52 | 53 | Q_UNUSED(option) |
|
53 | 54 | Q_UNUSED(widget) |
|
54 | 55 | |
|
55 | 56 | // TODO: optimized? |
|
56 | 57 | painter->setRenderHint(QPainter::Antialiasing, true); |
|
57 | 58 | } |
|
58 | 59 | |
|
59 | 60 | void DeclarativeChart::setAnimationOptions(QChart::AnimationOption animations) |
|
60 | 61 | { |
|
61 | 62 | m_chart->setAnimationOptions(animations); |
|
62 | 63 | } |
|
63 | 64 | |
|
64 | 65 | QChart::AnimationOption DeclarativeChart::animationOptions() |
|
65 | 66 | { |
|
66 | 67 | if (m_chart->animationOptions().testFlag(QChart::AllAnimations)) |
|
67 | 68 | return QChart::AllAnimations; |
|
68 | 69 | else if (m_chart->animationOptions().testFlag(QChart::GridAxisAnimations)) |
|
69 | 70 | return QChart::GridAxisAnimations; |
|
70 | 71 | else if (m_chart->animationOptions().testFlag(QChart::SeriesAnimations)) |
|
71 | 72 | return QChart::SeriesAnimations; |
|
72 | 73 | else |
|
73 | 74 | return QChart::NoAnimation; |
|
74 | 75 | } |
|
75 | 76 | |
|
77 | void DeclarativeChart::setLegend(ChartLegend legend) | |
|
78 | { | |
|
79 | if (legend != m_legend) { | |
|
80 | m_legend = legend; | |
|
81 | switch (m_legend) { | |
|
82 | case LegendDisabled: | |
|
83 | m_chart->legend()->setVisible(false); | |
|
84 | break; | |
|
85 | case LegendTop: | |
|
86 | m_chart->legend()->setVisible(true); | |
|
87 | m_chart->legend()->setAlignment(QLegend::AlignmentTop); | |
|
88 | break; | |
|
89 | case LegendBottom: | |
|
90 | m_chart->legend()->setVisible(true); | |
|
91 | m_chart->legend()->setAlignment(QLegend::AlignmentBottom); | |
|
92 | break; | |
|
93 | case LegendLeft: | |
|
94 | m_chart->legend()->setVisible(true); | |
|
95 | m_chart->legend()->setAlignment(QLegend::AlignmentLeft); | |
|
96 | break; | |
|
97 | case LegendRight: | |
|
98 | m_chart->legend()->setVisible(true); | |
|
99 | m_chart->legend()->setAlignment(QLegend::AlignmentRight); | |
|
100 | break; | |
|
101 | default: | |
|
102 | m_chart->legend()->setVisible(false); | |
|
103 | break; | |
|
104 | } | |
|
105 | } | |
|
106 | } | |
|
107 | ||
|
108 | DeclarativeChart::ChartLegend DeclarativeChart::legend() | |
|
109 | { | |
|
110 | return m_legend; | |
|
111 | } | |
|
112 | ||
|
76 | 113 | #include "moc_declarativechart.cpp" |
|
77 | 114 | |
|
78 | 115 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,64 +1,78 | |||
|
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 | 30 | // TODO: Derive from QChart for easier definition of properties? |
|
31 | 31 | class DeclarativeChart : public QDeclarativeItem |
|
32 | 32 | // TODO: for QTQUICK2: extend QQuickPainterItem instead |
|
33 | 33 | //class DeclarativeChart : public QQuickPaintedItem, public Chart |
|
34 | 34 | { |
|
35 | 35 | Q_OBJECT |
|
36 | 36 | Q_PROPERTY(QChart::ChartTheme theme READ theme WRITE setTheme) |
|
37 | 37 | Q_PROPERTY(QChart::AnimationOption animationOptions READ animationOptions WRITE setAnimationOptions) |
|
38 | 38 | Q_PROPERTY(QString title READ title WRITE setTitle) |
|
39 | Q_PROPERTY(ChartLegend legend READ legend WRITE setLegend) | |
|
40 | Q_ENUMS(ChartLegend) | |
|
41 | ||
|
42 | public: | |
|
43 | enum ChartLegend { | |
|
44 | LegendDisabled = 0, | |
|
45 | LegendTop, | |
|
46 | LegendBottom, | |
|
47 | LegendLeft, | |
|
48 | LegendRight | |
|
49 | }; | |
|
39 | 50 | |
|
40 | 51 | public: |
|
41 | 52 | DeclarativeChart(QDeclarativeItem *parent = 0); |
|
42 | 53 | ~DeclarativeChart(); |
|
43 | 54 | |
|
44 | 55 | public: // From QDeclarativeItem/QGraphicsItem |
|
45 | 56 | void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
|
46 | 57 | void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
47 | 58 | |
|
48 | 59 | public: |
|
49 | 60 | void setTheme(QChart::ChartTheme theme) {m_chart->setTheme(theme);} |
|
50 | 61 | QChart::ChartTheme theme() {return m_chart->theme();} |
|
51 | 62 | void setAnimationOptions(QChart::AnimationOption animations); |
|
52 | 63 | QChart::AnimationOption animationOptions(); |
|
53 | 64 | void setTitle(QString title) {m_chart->setTitle(title);} |
|
54 | 65 | QString title() { return m_chart->title();} |
|
66 | void setLegend(ChartLegend legend); | |
|
67 | ChartLegend legend(); | |
|
55 | 68 | |
|
56 | 69 | public: |
|
57 | 70 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
|
58 | 71 | // multi inheritance, so we now have a QChart as a member instead |
|
59 | 72 | QChart *m_chart; |
|
73 | ChartLegend m_legend; | |
|
60 | 74 | }; |
|
61 | 75 | |
|
62 | 76 | QTCOMMERCIALCHART_END_NAMESPACE |
|
63 | 77 | |
|
64 | 78 | #endif // DECLARATIVECHART_H |
General Comments 0
You need to be logged in to leave comments.
Login now