@@ -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 | 32 | #include "qcategoryaxis.h" |
|
33 | 33 | #include "qabstractseries_p.h" |
|
34 | 34 | #include "declarativemargins.h" |
|
35 | #include "qchart_p.h" | |
|
35 | 36 | |
|
36 | 37 | #ifndef QT_ON_ARM |
|
37 | 38 | #include "qdatetimeaxis.h" |
@@ -186,12 +187,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
186 | 187 | */ |
|
187 | 188 | |
|
188 | 189 | /*! |
|
189 |
\qmlmethod Axis ChartView::axisX( |
|
|
190 | \qmlmethod Axis ChartView::axisX(AbstractSeries series) | |
|
190 | 191 | The x-axis of the series. |
|
191 | 192 | */ |
|
192 | 193 | |
|
193 | 194 | /*! |
|
194 |
\qmlmethod Axis ChartView::axisY( |
|
|
195 | \qmlmethod Axis ChartView::axisY(AbstractSeries series) | |
|
195 | 196 | The y-axis of the series. |
|
196 | 197 | */ |
|
197 | 198 | |
@@ -231,6 +232,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
231 | 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 | 246 | DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) |
|
235 | 247 | : QDeclarativeItem(parent), |
|
236 | 248 | m_chart(new QChart(this)) |
@@ -241,6 +253,14 DeclarativeChart::DeclarativeChart(QDeclarativeItem *parent) | |||
|
241 | 253 | connect(m_minMargins, SIGNAL(bottomChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); |
|
242 | 254 | connect(m_minMargins, SIGNAL(leftChanged(int, int, int, int)), this, SLOT(changeMinimumMargins(int, int, int, int))); |
|
243 | 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 | 266 | void DeclarativeChart::changeMinimumMargins(int top, int bottom, int left, int right) |
@@ -620,6 +640,14 QAbstractSeries *DeclarativeChart::createSeries(DeclarativeChart::SeriesType typ | |||
|
620 | 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 | 651 | void DeclarativeChart::setAxisX(QAbstractAxis *axis, QAbstractSeries *series) |
|
624 | 652 | { |
|
625 | 653 | if (axis) |
@@ -32,6 +32,7 | |||
|
32 | 32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | 33 | |
|
34 | 34 | class DeclarativeMargins; |
|
35 | class Domain; | |
|
35 | 36 | |
|
36 | 37 | class DeclarativeChart : public QDeclarativeItem |
|
37 | 38 | { |
@@ -127,7 +128,7 public: | |||
|
127 | 128 | Q_INVOKABLE QAbstractSeries *series(QString seriesName); |
|
128 | 129 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name = ""); |
|
129 | 130 | Q_INVOKABLE QAbstractSeries *createSeries(DeclarativeChart::SeriesType type, QString name, QAbstractAxis *axisX, QAbstractAxis *axisY); |
|
130 |
Q_INVOKABLE void removeSeries(QAbstractSeries *series) |
|
|
131 | Q_INVOKABLE void removeSeries(QAbstractSeries *series); | |
|
131 | 132 | Q_INVOKABLE void removeAllSeries() { m_chart->removeAllSeries(); } |
|
132 | 133 | Q_INVOKABLE void setAxisX(QAbstractAxis *axis, QAbstractSeries *series = 0); |
|
133 | 134 | Q_INVOKABLE void setAxisY(QAbstractAxis *axis, QAbstractSeries *series = 0); |
@@ -147,11 +148,14 Q_SIGNALS: | |||
|
147 | 148 | void dropShadowEnabledChanged(bool enabled); |
|
148 | 149 | void minimumMarginsChanged(); |
|
149 | 150 | void plotAreaChanged(QRectF plotArea); |
|
151 | void seriesAdded(QAbstractSeries* series); | |
|
152 | void seriesRemoved(QAbstractSeries* series); | |
|
150 | 153 | |
|
151 | 154 | public Q_SLOTS: |
|
152 | 155 | void changeMinimumMargins(int top, int bottom, int left, int right); |
|
153 | 156 | void handleAxisXSet(QAbstractAxis *axis); |
|
154 | 157 | void handleAxisYSet(QAbstractAxis *axis); |
|
158 | void handleSeriesAdded(QAbstractSeries *series, Domain *domain); | |
|
155 | 159 | |
|
156 | 160 | private: |
|
157 | 161 | // Extending QChart with DeclarativeChart is not possible because QObject does not support |
@@ -89,7 +89,7 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
89 | 89 | \brief whether the series is visible or not; true by default. |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 |
\qmlproperty |
|
|
92 | \qmlproperty bool AbstractSeries::visible | |
|
93 | 93 | Visibility of the series. True by default. |
|
94 | 94 | */ |
|
95 | 95 | |
@@ -101,6 +101,27 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||
|
101 | 101 | \qmlsignal AbstractSeries::onVisibleChanged() |
|
102 | 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 | 126 | \internal |
|
106 | 127 | \brief Constructs ChartSeries object with \a parent. |
@@ -122,7 +122,7 public: | |||
|
122 | 122 | protected: |
|
123 | 123 | QScopedPointer<QChartPrivate> d_ptr; |
|
124 | 124 | friend class QLegend; |
|
125 |
friend class |
|
|
125 | friend class DeclarativeChart; | |
|
126 | 126 | Q_DISABLE_COPY(QChart) |
|
127 | 127 | }; |
|
128 | 128 |
@@ -25,7 +25,7 ChartView { | |||
|
25 | 25 | id: chartView |
|
26 | 26 | title: "Chart Title" |
|
27 | 27 | anchors.fill: parent |
|
28 |
property variant |
|
|
28 | property variant chart: chartView | |
|
29 | 29 | |
|
30 | 30 | LineSeries { |
|
31 | 31 | name: "line" |
@@ -40,10 +40,12 ChartView { | |||
|
40 | 40 | |
|
41 | 41 | onVisibleChanged: console.log("chart.onVisibleChanged: " + visible); |
|
42 | 42 | onTitleColorChanged: console.log("chart.onTitleColorChanged: " + color); |
|
43 |
onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + |
|
|
43 | onBackgroundColorChanged: console.log("chart.onBackgroundColorChanged: " + chart.backgroundColor); | |
|
44 | 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: " + |
|
|
48 | legend.onVisibleChanged: console.log("legend.onVisibleChanged: " + chart.legend.visible); | |
|
47 | 49 | legend.onBackgroundVisibleChanged: console.log("legend.onBackgroundVisibleChanged: " + visible); |
|
48 | 50 | legend.onColorChanged: console.log("legend.onColorChanged: " + color); |
|
49 | 51 | legend.onBorderColorChanged: console.log("legend.onBorderColorChanged: " + color); |
@@ -22,10 +22,10 import QtQuick 1.0 | |||
|
22 | 22 | |
|
23 | 23 | Item { |
|
24 | 24 | id: chartEditor |
|
25 |
property variant |
|
|
26 |
|
|
|
25 | property variant chart | |
|
26 | onChartChanged: { | |
|
27 | 27 | if (loader.item != undefined) |
|
28 |
loader.item.chart = |
|
|
28 | loader.item.chart = chart; | |
|
29 | 29 | } |
|
30 | 30 | |
|
31 | 31 | function selectButton(button) { |
@@ -34,6 +34,7 Item { | |||
|
34 | 34 | legendButton.color = "#79bd8f"; |
|
35 | 35 | axisXButton.color = "#79bd8f"; |
|
36 | 36 | axisYButton.color = "#79bd8f"; |
|
37 | seriesButton.color = "#79bd8f"; | |
|
37 | 38 | button.color = "#00a388"; |
|
38 | 39 | } |
|
39 | 40 | |
@@ -53,7 +54,7 Item { | |||
|
53 | 54 | onClicked: { |
|
54 | 55 | selectButton(chartButton); |
|
55 | 56 | loader.source = "ChartEditorProperties.qml"; |
|
56 |
loader.item.chart = |
|
|
57 | loader.item.chart = chart; | |
|
57 | 58 | } |
|
58 | 59 | } |
|
59 | 60 | Button { |
@@ -63,7 +64,7 Item { | |||
|
63 | 64 | onClicked: { |
|
64 | 65 | selectButton(titleButton); |
|
65 | 66 | loader.source = "ChartEditorTitle.qml"; |
|
66 |
loader.item.chart = |
|
|
67 | loader.item.chart = chart; | |
|
67 | 68 | } |
|
68 | 69 | } |
|
69 | 70 | Button { |
@@ -73,7 +74,7 Item { | |||
|
73 | 74 | onClicked: { |
|
74 | 75 | selectButton(legendButton); |
|
75 | 76 | loader.source = "ChartEditorLegend.qml"; |
|
76 |
loader.item.chartLegend = |
|
|
77 | loader.item.chartLegend = chart.legend; | |
|
77 | 78 | } |
|
78 | 79 | } |
|
79 | 80 | Button { |
@@ -83,7 +84,7 Item { | |||
|
83 | 84 | onClicked: { |
|
84 | 85 | selectButton(axisXButton); |
|
85 | 86 | loader.source = "ChartEditorAxis.qml"; |
|
86 |
loader.item.axis = |
|
|
87 | loader.item.axis = chart.axisX; | |
|
87 | 88 | } |
|
88 | 89 | } |
|
89 | 90 | Button { |
@@ -93,7 +94,17 Item { | |||
|
93 | 94 | onClicked: { |
|
94 | 95 | selectButton(axisYButton); |
|
95 | 96 | loader.source = "ChartEditorAxis.qml"; |
|
96 |
loader.item.axis = |
|
|
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 | 82 | onClicked: chart.titleColor = main.nextColor(); |
|
83 | 83 | } |
|
84 | 84 | Button { |
|
85 | text: "zoom -" | |
|
86 | onClicked: chart.zoom(0.5); | |
|
87 | } | |
|
88 | Button { | |
|
89 | 85 | text: "top min margin +" |
|
90 | 86 | onClicked: chart.minimumMargins.top += 5; |
|
91 | 87 | } |
@@ -47,8 +47,12 Rectangle { | |||
|
47 | 47 | height: parent.height |
|
48 | 48 | source: "Chart.qml" |
|
49 | 49 | onStatusChanged: { |
|
50 | if (status == Loader.Ready && editorLoader.status == Loader.Ready && chartLoader.item) | |
|
51 | editorLoader.item.series = chartLoader.item.series; | |
|
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 | |
|
54 | editorLoader.item.series = chartLoader.item.series; | |
|
55 | } | |
|
52 | 56 | } |
|
53 | 57 | } |
|
54 | 58 | |
@@ -58,8 +62,12 Rectangle { | |||
|
58 | 62 | height: parent.height |
|
59 | 63 | source: "ChartEditor.qml" |
|
60 | 64 | onStatusChanged: { |
|
61 | if (status == Loader.Ready && chartLoader.status == Loader.Ready && chartLoader.item) | |
|
62 | editorLoader.item.series = chartLoader.item.series; | |
|
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 | |
|
69 | editorLoader.item.series = chartLoader.item.series; | |
|
70 | } | |
|
63 | 71 | } |
|
64 | 72 | } |
|
65 | 73 | } |
@@ -26,5 +26,6 | |||
|
26 | 26 | <file>qml/qmlchartproperties/ChartEditorLegend.qml</file> |
|
27 | 27 | <file>qml/qmlchartproperties/ChartEditorProperties.qml</file> |
|
28 | 28 | <file>qml/qmlchartproperties/ChartEditorTitle.qml</file> |
|
29 | <file>qml/qmlchartproperties/ChartEditorSeries.qml</file> | |
|
29 | 30 | </qresource> |
|
30 | 31 | </RCC> |
General Comments 0
You need to be logged in to leave comments.
Login now