@@ -28,6 +28,7 Rectangle { | |||
|
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 |
@@ -28,6 +28,7 Rectangle { | |||
|
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" |
@@ -25,7 +25,8 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); |
@@ -73,6 +74,42 QChart::AnimationOption DeclarativeChart::animationOptions() | |||
|
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 |
@@ -36,6 +36,17 class DeclarativeChart : public QDeclarativeItem | |||
|
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); |
@@ -52,11 +63,14 public: | |||
|
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 |
General Comments 0
You need to be logged in to leave comments.
Login now