##// END OF EJS Templates
QML ChartView signals seriesAdded and seriesRemoved
Tero Ahola -
r2068:1370cf739b4f
parent child
Show More
@@ -0,0 +1,64
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.1
23
24 Flow {
25 anchors.fill: parent
26 property variant chart
27 flow: Flow.TopToBottom
28 spacing: 5
29
30 Button {
31 text: "add line"
32 onClicked: addXYSeries(ChartView.SeriesTypeLine, "line");
33 }
34 Button {
35 text: "add spline"
36 onClicked: addXYSeries(ChartView.SeriesTypeSpline, "spline");
37 }
38 Button {
39 text: "add scatter"
40 onClicked: addXYSeries(ChartView.SeriesTypeScatter, "scatter");
41 }
42 Button {
43 text: "remove last"
44 onClicked: {
45 if (chart.count > 0)
46 chart.removeSeries(chart.series(chart.count - 1));
47 else
48 chart.removeSeries(0);
49 }
50 }
51 Button {
52 text: "remove all"
53 onClicked: chart.removeAllSeries();
54 }
55
56 function addXYSeries(type, name) {
57 var series = chart.createSeries(type, name + " " + chart.count);
58 for (var i = chart.axisX().min; i < chart.axisX().max; i++) {
59 var y = Math.random() * (chart.axisY().max - chart.axisY().min) + chart.axisY().min;
60 var x = Math.random() + i;
61 series.append(x, y);
62 }
63 }
64 }
@@ -32,6 +32,7
32 #include "qcategoryaxis.h"
32 #include "qcategoryaxis.h"
33 #include "qabstractseries_p.h"
33 #include "qabstractseries_p.h"
34 #include "declarativemargins.h"
34 #include "declarativemargins.h"
35 #include "qchart_p.h"
35
36
36 #ifndef QT_ON_ARM
37 #ifndef QT_ON_ARM
37 #include "qdatetimeaxis.h"
38 #include "qdatetimeaxis.h"
@@ -186,12 +187,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
186 */
187 */
187
188
188 /*!
189 /*!
189 \qmlmethod Axis ChartView::axisX(QAbstractSeries *series)
190 \qmlmethod Axis ChartView::axisX(AbstractSeries series)
190 The x-axis of the series.
191 The x-axis of the series.
191 */
192 */
192
193
193 /*!
194 /*!
194 \qmlmethod Axis ChartView::axisY(QAbstractSeries *series)
195 \qmlmethod Axis ChartView::axisY(AbstractSeries series)
195 The y-axis of the series.
196 The y-axis of the series.
196 */
197 */
197
198
@@ -231,6 +232,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
231 title.
232 title.
232 */
233 */
233
234
235 /*!
236 \qmlsignal ChartView::seriesAdded(AbstractSeries series)
237 The \a series has been added to the chart.
238 */
239
240 /*!
241 \qmlsignal ChartView::seriesRemoved(AbstractSeries series)
242 The \a series has been removed from the chart. Please note that \a series is no longer a valid
243 object after the signal handler has completed.
244 */
245
234 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
246 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
235 : QDeclarativeItem(parent),
247 : QDeclarativeItem(parent),
236 m_chart(new QChart(this))
248 m_chart(new QChart(this))
@@ -241,6 +253,14 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent)
241 connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
253 connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
242 connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
254 connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
243 connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
255 connect(m_minMargins, SIGNAL(rightChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int)));
256 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)), this, SLOT(handleSeriesAdded(QAbstractSeries *, Domain *)));
257 connect(m_chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)), this, SIGNAL(seriesRemoved(QAbstractSeries *)));
258 }
259
260 void DeclarativeChart::handleSeriesAdded(QAbstractSeries *series, Domain *domain)
261 {
262 Q_UNUSED(domain)
263 emit seriesAdded(series);
244 }
264 }
245
265
246 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
266 void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right)
@@ -620,6 +640,14 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType typ
620 return series;
640 return series;
621 }
641 }
622
642
643 void DeclarativeChart::removeSeries(QAbstractSeries *series)
644 {
645 if (series)
646 m_chart->removeSeries(series);
647 else
648 qWarning("removeSeries: cannot remove null");
649 }
650
623 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
651 void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series)
624 {
652 {
625 if (axis)
653 if (axis)
@@ -32,6 +32,7
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 class DeclarativeMargins;
34 class DeclarativeMargins;
35 class Domain;
35
36
36 class DeclarativeChart : public QDeclarativeItem
37 class DeclarativeChart : public QDeclarativeItem
37 {
38 {
@@ -127,7 +128,7 public:
127 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
128 Q_INVOKABLE QAbstractSeries *series(QString seriesName);
128 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
129 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = "");
129 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY);
130 Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY);
130 Q_INVOKABLE void removeSeries(QAbstractSeries *series) { m_chart->removeSeries(series); }
131 Q_INVOKABLE void removeSeries(QAbstractSeries *series);
131 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
132 Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); }
132 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
133 Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0);
133 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
134 Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0);
@@ -147,11 +148,14 Q_SIGNALS:
147 void dropShadowEnabledChanged(bool enabled);
148 void dropShadowEnabledChanged(bool enabled);
148 void minimumMarginsChanged();
149 void minimumMarginsChanged();
149 void plotAreaChanged(QRectF plotArea);
150 void plotAreaChanged(QRectF plotArea);
151 void seriesAdded(QAbstractSeries* series);
152 void seriesRemoved(QAbstractSeries* series);
150
153
151 public Q_SLOTS:
154 public Q_SLOTS:
152 void changeMinimumMargins(int top, int bottom, int left, int right);
155 void changeMinimumMargins(int top, int bottom, int left, int right);
153 void handleAxisXSet(QAbstractAxis *axis);
156 void handleAxisXSet(QAbstractAxis *axis);
154 void handleAxisYSet(QAbstractAxis *axis);
157 void handleAxisYSet(QAbstractAxis *axis);
158 void handleSeriesAdded(QAbstractSeries *series, Domain *domain);
155
159
156 private:
160 private:
157 // Extending QChart with DeclarativeChart is not possible because QObject does not support
161 // Extending QChart with DeclarativeChart is not possible because QObject does not support
@@ -89,7 +89,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE
89 \brief whether the series is visible or not; true by default.
89 \brief whether the series is visible or not; true by default.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty void AbstractSeries::visible
92 \qmlproperty bool AbstractSeries::visible
93 Visibility of the series. True by default.
93 Visibility of the series. True by default.
94 */
94 */
95
95
@@ -101,6 +101,27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
101 \qmlsignal AbstractSeries::onVisibleChanged()
101 \qmlsignal AbstractSeries::onVisibleChanged()
102 Emitted when the series visibility changes.
102 Emitted when the series visibility changes.
103 */
103 */
104
105 /*!
106 \property QAbstractSeries::opacity
107 \brief The opacity of the series.
108 By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque).
109 */
110 /*!
111 \qmlproperty real AbstractSeries::opacity
112 The opacity of the series. By default the opacity is 1.0.
113 The valid values range from 0.0 (transparent) to 1.0 (opaque).
114 */
115
116 /*!
117 \fn void QAbstractSeries::opacityChanged()
118 Emitted when the opacity of the series changes.
119 */
120 /*!
121 \qmlsignal AbstractSeries::onOpacityChanged()
122 Emitted when the opacity of the series changes.
123 */
124
104 /*!
125 /*!
105 \internal
126 \internal
106 \brief Constructs ChartSeries object with \a parent.
127 \brief Constructs ChartSeries object with \a parent.
@@ -122,7 +122,7 public:
122 protected:
122 protected:
123 QScopedPointer<QChartPrivate> d_ptr;
123 QScopedPointer<QChartPrivate> d_ptr;
124 friend class QLegend;
124 friend class QLegend;
125 friend class ChartPresenter;
125 friend class DeclarativeChart;
126 Q_DISABLE_COPY(QChart)
126 Q_DISABLE_COPY(QChart)
127 };
127 };
128
128
@@ -25,7 +25,7 ChartView {
25 id: chartView
25 id: chartView
26 title: "Chart Title"
26 title: "Chart Title"
27 anchors.fill: parent
27 anchors.fill: parent
28 property variant series: chartView
28 property variant chart: chartView
29
29
30 LineSeries {
30 LineSeries {
31 name: "line"
31 name: "line"
@@ -40,10 +40,12 ChartView {
40
40
41 onVisibleChanged: console.log("chart.onVisibleChanged: " + visible);
41 onVisibleChanged: console.log("chart.onVisibleChanged: " + visible);
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
42 onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + series.backgroundColor);
43 onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
44 onDropShadowEnabledChanged: console.log("chart.onDropShadowEnabledChanged: " + enabled);
45 onSeriesAdded: console.log("chart.onSeriesAdded: " + series.name);
46 onSeriesRemoved: console.log("chart.onSeriesRemoved: " + series.name);
45
47
46 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + series.legend.visible);
48 legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible);
47 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
49 legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible);
48 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
50 legend.onColorChanged: console.log("legend.onColorChanged: " + color);
49 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
51 legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color);
@@ -22,10 +22,10 import QtQuick 1.0
22
22
23 Item {
23 Item {
24 id: chartEditor
24 id: chartEditor
25 property variant series // TODO: rename to chart
25 property variant chart
26 onSeriesChanged: {
26 onChartChanged: {
27 if (loader.item != undefined)
27 if (loader.item != undefined)
28 loader.item.chart = series;
28 loader.item.chart = chart;
29 }
29 }
30
30
31 function selectButton(button) {
31 function selectButton(button) {
@@ -34,6 +34,7 Item {
34 legendButton.color = "#79bd8f";
34 legendButton.color = "#79bd8f";
35 axisXButton.color = "#79bd8f";
35 axisXButton.color = "#79bd8f";
36 axisYButton.color = "#79bd8f";
36 axisYButton.color = "#79bd8f";
37 seriesButton.color = "#79bd8f";
37 button.color = "#00a388";
38 button.color = "#00a388";
38 }
39 }
39
40
@@ -53,7 +54,7 Item {
53 onClicked: {
54 onClicked: {
54 selectButton(chartButton);
55 selectButton(chartButton);
55 loader.source = "ChartEditorProperties.qml";
56 loader.source = "ChartEditorProperties.qml";
56 loader.item.chart = series;
57 loader.item.chart = chart;
57 }
58 }
58 }
59 }
59 Button {
60 Button {
@@ -63,7 +64,7 Item {
63 onClicked: {
64 onClicked: {
64 selectButton(titleButton);
65 selectButton(titleButton);
65 loader.source = "ChartEditorTitle.qml";
66 loader.source = "ChartEditorTitle.qml";
66 loader.item.chart = series;
67 loader.item.chart = chart;
67 }
68 }
68 }
69 }
69 Button {
70 Button {
@@ -73,7 +74,7 Item {
73 onClicked: {
74 onClicked: {
74 selectButton(legendButton);
75 selectButton(legendButton);
75 loader.source = "ChartEditorLegend.qml";
76 loader.source = "ChartEditorLegend.qml";
76 loader.item.chartLegend = series.legend;
77 loader.item.chartLegend = chart.legend;
77 }
78 }
78 }
79 }
79 Button {
80 Button {
@@ -83,7 +84,7 Item {
83 onClicked: {
84 onClicked: {
84 selectButton(axisXButton);
85 selectButton(axisXButton);
85 loader.source = "ChartEditorAxis.qml";
86 loader.source = "ChartEditorAxis.qml";
86 loader.item.axis = series.axisX;
87 loader.item.axis = chart.axisX;
87 }
88 }
88 }
89 }
89 Button {
90 Button {
@@ -93,7 +94,17 Item {
93 onClicked: {
94 onClicked: {
94 selectButton(axisYButton);
95 selectButton(axisYButton);
95 loader.source = "ChartEditorAxis.qml";
96 loader.source = "ChartEditorAxis.qml";
96 loader.item.axis = series.axisY;
97 loader.item.axis = chart.axisY;
98 }
99 }
100 Button {
101 id: seriesButton
102 text: "Series"
103 unpressedColor: "#79bd8f"
104 onClicked: {
105 selectButton(seriesButton);
106 loader.source = "ChartEditorSeries.qml";
107 loader.item.chart = chart;
97 }
108 }
98 }
109 }
99 }
110 }
@@ -82,10 +82,6 Flow {
82 onClicked: chart.titleColor = main.nextColor();
82 onClicked: chart.titleColor = main.nextColor();
83 }
83 }
84 Button {
84 Button {
85 text: "zoom -"
86 onClicked: chart.zoom(0.5);
87 }
88 Button {
89 text: "top min margin +"
85 text: "top min margin +"
90 onClicked: chart.minimumMargins.top += 5;
86 onClicked: chart.minimumMargins.top += 5;
91 }
87 }
@@ -47,10 +47,14 Rectangle {
47 height: parent.height
47 height: parent.height
48 source: "Chart.qml"
48 source: "Chart.qml"
49 onStatusChanged: {
49 onStatusChanged: {
50 if (status == Loader.Ready && editorLoader.status == Loader.Ready && chartLoader.item)
50 if (status == Loader.Ready && editorLoader.status == Loader.Ready && chartLoader.item) {
51 if (source.toString().search("Chart.qml") > 0)
52 editorLoader.item.chart = chartLoader.item.chart;
53 else
51 editorLoader.item.series = chartLoader.item.series;
54 editorLoader.item.series = chartLoader.item.series;
52 }
55 }
53 }
56 }
57 }
54
58
55 Loader {
59 Loader {
56 id: editorLoader
60 id: editorLoader
@@ -58,11 +62,15 Rectangle {
58 height: parent.height
62 height: parent.height
59 source: "ChartEditor.qml"
63 source: "ChartEditor.qml"
60 onStatusChanged: {
64 onStatusChanged: {
61 if (status == Loader.Ready && chartLoader.status == Loader.Ready && chartLoader.item)
65 if (status == Loader.Ready && chartLoader.status == Loader.Ready && chartLoader.item) {
66 if (source.toString().search("ChartEditor.qml") > 0)
67 editorLoader.item.chart = chartLoader.item.chart;
68 else
62 editorLoader.item.series = chartLoader.item.series;
69 editorLoader.item.series = chartLoader.item.series;
63 }
70 }
64 }
71 }
65 }
72 }
73 }
66
74
67 Row {
75 Row {
68 id: buttonRow
76 id: buttonRow
@@ -26,5 +26,6
26 <file>qml/qmlchartproperties/ChartEditorLegend.qml</file>
26 <file>qml/qmlchartproperties/ChartEditorLegend.qml</file>
27 <file>qml/qmlchartproperties/ChartEditorProperties.qml</file>
27 <file>qml/qmlchartproperties/ChartEditorProperties.qml</file>
28 <file>qml/qmlchartproperties/ChartEditorTitle.qml</file>
28 <file>qml/qmlchartproperties/ChartEditorTitle.qml</file>
29 <file>qml/qmlchartproperties/ChartEditorSeries.qml</file>
29 </qresource>
30 </qresource>
30 </RCC>
31 </RCC>
General Comments 0
You need to be logged in to leave comments. Login now