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