##// END OF EJS Templates
Legend to QML API
Tero Ahola -
r1095:746114f1a345
parent child
Show More
@@ -28,6 +28,7 Rectangle {
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
@@ -28,6 +28,7 Rectangle {
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"
@@ -25,7 +25,8 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);
@@ -73,6 +74,42 QChart::AnimationOption DeclarativeChart::animationOptions()
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
@@ -36,6 +36,17 class DeclarativeChart : public QDeclarativeItem
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);
@@ -52,11 +63,14 public:
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
General Comments 0
You need to be logged in to leave comments. Login now