@@ -1,177 +1,178 | |||||
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 | #ifdef QT5_QUICK_1 |
|
21 | #ifdef QT5_QUICK_1 | |
22 | #include <QtQuick1/qdeclarativeextensionplugin.h> |
|
22 | #include <QtQuick1/qdeclarativeextensionplugin.h> | |
23 | #include <QtQuick1/qdeclarative.h> |
|
23 | #include <QtQuick1/qdeclarative.h> | |
24 | #else |
|
24 | #else | |
25 | #include <QtDeclarative/qdeclarativeextensionplugin.h> |
|
25 | #include <QtDeclarative/qdeclarativeextensionplugin.h> | |
26 | #include <QtDeclarative/qdeclarative.h> |
|
26 | #include <QtDeclarative/qdeclarative.h> | |
27 | #endif |
|
27 | #endif | |
28 | #include "qchart.h" |
|
28 | #include "qchart.h" | |
29 | #include "qabstractaxis.h" |
|
29 | #include "qabstractaxis.h" | |
30 | #include "qvalueaxis.h" |
|
30 | #include "qvalueaxis.h" | |
31 | #include "declarativecategoryaxis.h" |
|
31 | #include "declarativecategoryaxis.h" | |
32 | #include "qbarcategoryaxis.h" |
|
32 | #include "qbarcategoryaxis.h" | |
33 | #include "declarativechart.h" |
|
33 | #include "declarativechart.h" | |
34 | #include "declarativexypoint.h" |
|
34 | #include "declarativexypoint.h" | |
35 | #include "declarativelineseries.h" |
|
35 | #include "declarativelineseries.h" | |
36 | #include "declarativesplineseries.h" |
|
36 | #include "declarativesplineseries.h" | |
37 | #include "declarativeareaseries.h" |
|
37 | #include "declarativeareaseries.h" | |
38 | #include "declarativescatterseries.h" |
|
38 | #include "declarativescatterseries.h" | |
39 | #include "declarativebarseries.h" |
|
39 | #include "declarativebarseries.h" | |
40 | #include "declarativepieseries.h" |
|
40 | #include "declarativepieseries.h" | |
41 | #include "qvxymodelmapper.h" |
|
41 | #include "qvxymodelmapper.h" | |
42 | #include "qhxymodelmapper.h" |
|
42 | #include "qhxymodelmapper.h" | |
43 | #include "qhpiemodelmapper.h" |
|
43 | #include "qhpiemodelmapper.h" | |
44 | #include "qvpiemodelmapper.h" |
|
44 | #include "qvpiemodelmapper.h" | |
45 | #include "qhbarmodelmapper.h" |
|
45 | #include "qhbarmodelmapper.h" | |
46 | #include "qvbarmodelmapper.h" |
|
46 | #include "qvbarmodelmapper.h" | |
47 | #include "declarativemargins.h" |
|
47 | #include "declarativemargins.h" | |
48 | #include <QAbstractItemModel> |
|
48 | #include <QAbstractItemModel> | |
49 |
|
49 | |||
50 | #ifndef QT_ON_ARM |
|
50 | #ifndef QT_ON_ARM | |
51 | #include "qdatetimeaxis.h" |
|
51 | #include "qdatetimeaxis.h" | |
52 | #endif |
|
52 | #endif | |
53 |
|
53 | |||
54 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
54 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
55 |
|
55 | |||
56 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin |
|
56 | class ChartQmlPlugin : public QDeclarativeExtensionPlugin | |
57 | { |
|
57 | { | |
58 | Q_OBJECT |
|
58 | Q_OBJECT | |
59 |
|
59 | |||
60 | #ifdef QT5_QUICK_1 |
|
60 | #ifdef QT5_QUICK_1 | |
|
61 | // TODO: fix the metadata | |||
61 | Q_PLUGIN_METADATA(IID "org.qt-project.foo") |
|
62 | Q_PLUGIN_METADATA(IID "org.qt-project.foo") | |
62 | #endif |
|
63 | #endif | |
63 |
|
64 | |||
64 | public: |
|
65 | public: | |
65 | virtual void registerTypes(const char *uri) |
|
66 | virtual void registerTypes(const char *uri) | |
66 | { |
|
67 | { | |
67 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); |
|
68 | Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart")); | |
68 |
|
69 | |||
69 | // QtCommercial.Chart 1.0 |
|
70 | // QtCommercial.Chart 1.0 | |
70 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); |
|
71 | qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView"); | |
71 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); |
|
72 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint"); | |
72 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); |
|
73 | qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries"); | |
73 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); |
|
74 | qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries"); | |
74 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); |
|
75 | qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries"); | |
75 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); |
|
76 | qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries"); | |
76 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); |
|
77 | qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries"); | |
77 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); |
|
78 | qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries"); | |
78 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); |
|
79 | qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries"); | |
79 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); |
|
80 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries"); | |
80 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); |
|
81 | qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice"); | |
81 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); |
|
82 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet"); | |
82 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); |
|
83 | qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper"); | |
83 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); |
|
84 | qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper"); | |
84 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); |
|
85 | qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper"); | |
85 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); |
|
86 | qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper"); | |
86 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); |
|
87 | qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper"); | |
87 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); |
|
88 | qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper"); | |
88 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); |
|
89 | qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis"); | |
89 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis"); |
|
90 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis"); | |
90 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", |
|
91 | qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend", | |
91 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
92 | QLatin1String("Trying to create uncreatable: Legend.")); | |
92 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", |
|
93 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries", | |
93 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
94 | QLatin1String("Trying to create uncreatable: XYSeries.")); | |
94 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", |
|
95 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel", | |
95 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
96 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); | |
96 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", |
|
97 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper", | |
97 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
98 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
98 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", |
|
99 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper", | |
99 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
100 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
100 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", |
|
101 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper", | |
101 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
102 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); | |
102 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", |
|
103 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries", | |
103 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
104 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); | |
104 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", |
|
105 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries", | |
105 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); |
|
106 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); | |
106 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", |
|
107 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis", | |
107 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); |
|
108 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); | |
108 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase", |
|
109 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase", | |
109 | QLatin1String("Trying to create uncreatable: BarsetBase.")); |
|
110 | QLatin1String("Trying to create uncreatable: BarsetBase.")); | |
110 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", |
|
111 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries", | |
111 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); |
|
112 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); | |
112 |
|
113 | |||
113 | // QtCommercial.Chart 1.1 |
|
114 | // QtCommercial.Chart 1.1 | |
114 | qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView"); |
|
115 | qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView"); | |
115 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 1, "XYPoint"); |
|
116 | qmlRegisterType<DeclarativeXYPoint>(uri, 1, 1, "XYPoint"); | |
116 | qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries"); |
|
117 | qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries"); | |
117 | qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries"); |
|
118 | qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries"); | |
118 | qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries"); |
|
119 | qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries"); | |
119 | qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries"); |
|
120 | qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries"); | |
120 | qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries"); |
|
121 | qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries"); | |
121 | qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries"); |
|
122 | qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries"); | |
122 | qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries"); |
|
123 | qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries"); | |
123 | qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries"); |
|
124 | qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries"); | |
124 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries"); |
|
125 | qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries"); | |
125 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries"); |
|
126 | qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries"); | |
126 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries"); |
|
127 | qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries"); | |
127 | qmlRegisterType<QPieSlice>(uri, 1, 1, "PieSlice"); |
|
128 | qmlRegisterType<QPieSlice>(uri, 1, 1, "PieSlice"); | |
128 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet"); |
|
129 | qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet"); | |
129 | qmlRegisterType<QHXYModelMapper>(uri, 1, 1, "HXYModelMapper"); |
|
130 | qmlRegisterType<QHXYModelMapper>(uri, 1, 1, "HXYModelMapper"); | |
130 | qmlRegisterType<QVXYModelMapper>(uri, 1, 1, "VXYModelMapper"); |
|
131 | qmlRegisterType<QVXYModelMapper>(uri, 1, 1, "VXYModelMapper"); | |
131 | qmlRegisterType<QHPieModelMapper>(uri, 1, 1, "HPieModelMapper"); |
|
132 | qmlRegisterType<QHPieModelMapper>(uri, 1, 1, "HPieModelMapper"); | |
132 | qmlRegisterType<QVPieModelMapper>(uri, 1, 1, "VPieModelMapper"); |
|
133 | qmlRegisterType<QVPieModelMapper>(uri, 1, 1, "VPieModelMapper"); | |
133 | qmlRegisterType<QHBarModelMapper>(uri, 1, 1, "HBarModelMapper"); |
|
134 | qmlRegisterType<QHBarModelMapper>(uri, 1, 1, "HBarModelMapper"); | |
134 | qmlRegisterType<QVBarModelMapper>(uri, 1, 1, "VBarModelMapper"); |
|
135 | qmlRegisterType<QVBarModelMapper>(uri, 1, 1, "VBarModelMapper"); | |
135 | qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis"); |
|
136 | qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis"); | |
136 | #ifndef QT_ON_ARM |
|
137 | #ifndef QT_ON_ARM | |
137 | qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis"); |
|
138 | qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis"); | |
138 | #endif |
|
139 | #endif | |
139 | qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis"); |
|
140 | qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis"); | |
140 | qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange"); |
|
141 | qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange"); | |
141 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis"); |
|
142 | qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis"); | |
142 | qmlRegisterUncreatableType<QLegend>(uri, 1, 1, "Legend", |
|
143 | qmlRegisterUncreatableType<QLegend>(uri, 1, 1, "Legend", | |
143 | QLatin1String("Trying to create uncreatable: Legend.")); |
|
144 | QLatin1String("Trying to create uncreatable: Legend.")); | |
144 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 1, "XYSeries", |
|
145 | qmlRegisterUncreatableType<QXYSeries>(uri, 1, 1, "XYSeries", | |
145 | QLatin1String("Trying to create uncreatable: XYSeries.")); |
|
146 | QLatin1String("Trying to create uncreatable: XYSeries.")); | |
146 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 1, "AbstractItemModel", |
|
147 | qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 1, "AbstractItemModel", | |
147 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); |
|
148 | QLatin1String("Trying to create uncreatable: AbstractItemModel.")); | |
148 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 1, "XYModelMapper", |
|
149 | qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 1, "XYModelMapper", | |
149 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); |
|
150 | QLatin1String("Trying to create uncreatable: XYModelMapper.")); | |
150 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 1, "PieModelMapper", |
|
151 | qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 1, "PieModelMapper", | |
151 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); |
|
152 | QLatin1String("Trying to create uncreatable: PieModelMapper.")); | |
152 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 1, "BarModelMapper", |
|
153 | qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 1, "BarModelMapper", | |
153 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); |
|
154 | QLatin1String("Trying to create uncreatable: BarModelMapper.")); | |
154 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 1, "AbstractSeries", |
|
155 | qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 1, "AbstractSeries", | |
155 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); |
|
156 | QLatin1String("Trying to create uncreatable: AbstractSeries.")); | |
156 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 1, "AbstractBarSeries", |
|
157 | qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 1, "AbstractBarSeries", | |
157 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); |
|
158 | QLatin1String("Trying to create uncreatable: AbstractBarSeries.")); | |
158 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 1, "AbstractAxis", |
|
159 | qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 1, "AbstractAxis", | |
159 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); |
|
160 | QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead.")); | |
160 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 1, "BarSetBase", |
|
161 | qmlRegisterUncreatableType<QBarSet>(uri, 1, 1, "BarSetBase", | |
161 | QLatin1String("Trying to create uncreatable: BarsetBase.")); |
|
162 | QLatin1String("Trying to create uncreatable: BarsetBase.")); | |
162 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 1, "QPieSeries", |
|
163 | qmlRegisterUncreatableType<QPieSeries>(uri, 1, 1, "QPieSeries", | |
163 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); |
|
164 | QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead.")); | |
164 | qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins", |
|
165 | qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins", | |
165 | QLatin1String("Trying to create uncreatable: Margins.")); |
|
166 | QLatin1String("Trying to create uncreatable: Margins.")); | |
166 | } |
|
167 | } | |
167 | }; |
|
168 | }; | |
168 |
|
169 | |||
169 | #include "plugin.moc" |
|
170 | #include "plugin.moc" | |
170 |
|
171 | |||
171 | QTCOMMERCIALCHART_END_NAMESPACE |
|
172 | QTCOMMERCIALCHART_END_NAMESPACE | |
172 |
|
173 | |||
173 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
174 | QTCOMMERCIALCHART_USE_NAMESPACE | |
174 |
|
175 | |||
175 | #ifndef QT5_QUICK_1 |
|
176 | #ifndef QT5_QUICK_1 | |
176 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) |
|
177 | Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin)) | |
177 | #endif |
|
178 | #endif |
@@ -1,151 +1,153 | |||||
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 "areachartitem_p.h" |
|
21 | #include "areachartitem_p.h" | |
22 | #include "qareaseries.h" |
|
22 | #include "qareaseries.h" | |
23 | #include "qareaseries_p.h" |
|
23 | #include "qareaseries_p.h" | |
24 | #include "qlineseries.h" |
|
24 | #include "qlineseries.h" | |
25 | #include "chartpresenter_p.h" |
|
25 | #include "chartpresenter_p.h" | |
26 | #include "domain_p.h" |
|
26 | #include "domain_p.h" | |
27 | #include <QPainter> |
|
27 | #include <QPainter> | |
28 | #include <QGraphicsSceneMouseEvent> |
|
28 | #include <QGraphicsSceneMouseEvent> | |
29 | #include <QDebug> |
|
29 | #include <QDebug> | |
30 |
|
30 | |||
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | //TODO: optimize : remove points which are not visible |
|
34 | //TODO: optimize : remove points which are not visible | |
35 |
|
35 | |||
36 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) |
|
36 | AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, ChartPresenter *presenter) | |
37 | : ChartItem(presenter), |
|
37 | : ChartItem(presenter), | |
38 | m_series(areaSeries), |
|
38 | m_series(areaSeries), | |
39 | m_upper(0), |
|
39 | m_upper(0), | |
40 | m_lower(0), |
|
40 | m_lower(0), | |
41 | m_pointsVisible(false) |
|
41 | m_pointsVisible(false) | |
42 | { |
|
42 | { | |
43 | setZValue(ChartPresenter::LineChartZValue); |
|
43 | setZValue(ChartPresenter::LineChartZValue); | |
44 | m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter); |
|
44 | m_upper = new AreaBoundItem(this,m_series->upperSeries(),presenter); | |
45 | if (m_series->lowerSeries()){ |
|
45 | if (m_series->lowerSeries()){ | |
46 | m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter); |
|
46 | m_lower = new AreaBoundItem(this,m_series->lowerSeries(),presenter); | |
47 | } |
|
47 | } | |
48 |
|
48 | |||
49 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
49 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
50 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
50 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
|
51 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); | |||
51 | QObject::connect(this,SIGNAL(clicked(QPointF)),areaSeries,SIGNAL(clicked(QPointF))); |
|
52 | QObject::connect(this,SIGNAL(clicked(QPointF)),areaSeries,SIGNAL(clicked(QPointF))); | |
52 |
|
53 | |||
53 | handleUpdated(); |
|
54 | handleUpdated(); | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | AreaChartItem::~AreaChartItem() |
|
57 | AreaChartItem::~AreaChartItem() | |
57 | { |
|
58 | { | |
58 | delete m_upper; |
|
59 | delete m_upper; | |
59 | delete m_lower; |
|
60 | delete m_lower; | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | QRectF AreaChartItem::boundingRect() const |
|
63 | QRectF AreaChartItem::boundingRect() const | |
63 | { |
|
64 | { | |
64 | return m_rect; |
|
65 | return m_rect; | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | QPainterPath AreaChartItem::shape() const |
|
68 | QPainterPath AreaChartItem::shape() const | |
68 | { |
|
69 | { | |
69 | return m_path; |
|
70 | return m_path; | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | void AreaChartItem::updatePath() |
|
73 | void AreaChartItem::updatePath() | |
73 | { |
|
74 | { | |
74 | QPainterPath path; |
|
75 | QPainterPath path; | |
75 |
|
76 | |||
76 | path = m_upper->path(); |
|
77 | path = m_upper->path(); | |
77 |
|
78 | |||
78 | if (m_lower) { |
|
79 | if (m_lower) { | |
79 | path.connectPath(m_lower->path().toReversed()); |
|
80 | path.connectPath(m_lower->path().toReversed()); | |
80 | } else { |
|
81 | } else { | |
81 | QPointF first = path.pointAtPercent(0); |
|
82 | QPointF first = path.pointAtPercent(0); | |
82 | QPointF last = path.pointAtPercent(1); |
|
83 | QPointF last = path.pointAtPercent(1); | |
83 | path.lineTo(last.x(),m_clipRect.bottom()); |
|
84 | path.lineTo(last.x(),m_clipRect.bottom()); | |
84 | path.lineTo(first.x(),m_clipRect.bottom()); |
|
85 | path.lineTo(first.x(),m_clipRect.bottom()); | |
85 | } |
|
86 | } | |
86 | path.closeSubpath(); |
|
87 | path.closeSubpath(); | |
87 | prepareGeometryChange(); |
|
88 | prepareGeometryChange(); | |
88 | m_path = path; |
|
89 | m_path = path; | |
89 | m_rect = path.boundingRect(); |
|
90 | m_rect = path.boundingRect(); | |
90 | update(); |
|
91 | update(); | |
91 | } |
|
92 | } | |
92 |
|
93 | |||
93 | void AreaChartItem::handleUpdated() |
|
94 | void AreaChartItem::handleUpdated() | |
94 | { |
|
95 | { | |
95 | setVisible(m_series->isVisible()); |
|
96 | setVisible(m_series->isVisible()); | |
96 | m_pointsVisible = m_series->pointsVisible(); |
|
97 | m_pointsVisible = m_series->pointsVisible(); | |
97 | m_linePen = m_series->pen(); |
|
98 | m_linePen = m_series->pen(); | |
98 | m_brush = m_series->brush(); |
|
99 | m_brush = m_series->brush(); | |
99 | m_pointPen = m_series->pen(); |
|
100 | m_pointPen = m_series->pen(); | |
100 | m_pointPen.setWidthF(2 * m_pointPen.width()); |
|
101 | m_pointPen.setWidthF(2 * m_pointPen.width()); | |
|
102 | setOpacity(m_series->opacity()); | |||
101 |
|
103 | |||
102 | update(); |
|
104 | update(); | |
103 | } |
|
105 | } | |
104 |
|
106 | |||
105 | void AreaChartItem::handleDomainUpdated() |
|
107 | void AreaChartItem::handleDomainUpdated() | |
106 | { |
|
108 | { | |
107 | m_upper->setDomain(domain()); |
|
109 | m_upper->setDomain(domain()); | |
108 | m_upper->handleDomainUpdated(); |
|
110 | m_upper->handleDomainUpdated(); | |
109 | if (m_lower){ |
|
111 | if (m_lower){ | |
110 | m_lower->setDomain(domain()); |
|
112 | m_lower->setDomain(domain()); | |
111 | m_lower->handleDomainUpdated(); |
|
113 | m_lower->handleDomainUpdated(); | |
112 | } |
|
114 | } | |
113 | } |
|
115 | } | |
114 |
|
116 | |||
115 | void AreaChartItem::handleGeometryChanged(const QRectF &rect) |
|
117 | void AreaChartItem::handleGeometryChanged(const QRectF &rect) | |
116 | { |
|
118 | { | |
117 | m_clipRect=rect.translated(-rect.topLeft()); |
|
119 | m_clipRect=rect.translated(-rect.topLeft()); | |
118 | setPos(rect.topLeft()); |
|
120 | setPos(rect.topLeft()); | |
119 | m_upper->handleGeometryChanged(rect); |
|
121 | m_upper->handleGeometryChanged(rect); | |
120 | if (m_lower) |
|
122 | if (m_lower) | |
121 | m_lower->handleGeometryChanged(rect); |
|
123 | m_lower->handleGeometryChanged(rect); | |
122 | } |
|
124 | } | |
123 |
|
125 | |||
124 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
126 | void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
125 | { |
|
127 | { | |
126 | Q_UNUSED(widget) |
|
128 | Q_UNUSED(widget) | |
127 | Q_UNUSED(option) |
|
129 | Q_UNUSED(option) | |
128 |
|
130 | |||
129 | painter->save(); |
|
131 | painter->save(); | |
130 | painter->setPen(m_linePen); |
|
132 | painter->setPen(m_linePen); | |
131 | painter->setBrush(m_brush); |
|
133 | painter->setBrush(m_brush); | |
132 | painter->setClipRect(m_clipRect); |
|
134 | painter->setClipRect(m_clipRect); | |
133 | painter->drawPath(m_path); |
|
135 | painter->drawPath(m_path); | |
134 | if (m_pointsVisible) { |
|
136 | if (m_pointsVisible) { | |
135 | painter->setPen(m_pointPen); |
|
137 | painter->setPen(m_pointPen); | |
136 | painter->drawPoints(m_upper->geometryPoints()); |
|
138 | painter->drawPoints(m_upper->geometryPoints()); | |
137 | if (m_lower) |
|
139 | if (m_lower) | |
138 | painter->drawPoints(m_lower->geometryPoints()); |
|
140 | painter->drawPoints(m_lower->geometryPoints()); | |
139 | } |
|
141 | } | |
140 | painter->restore(); |
|
142 | painter->restore(); | |
141 | } |
|
143 | } | |
142 |
|
144 | |||
143 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
145 | void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
144 | { |
|
146 | { | |
145 | emit clicked(m_upper->calculateDomainPoint(event->pos())); |
|
147 | emit clicked(m_upper->calculateDomainPoint(event->pos())); | |
146 | ChartItem::mousePressEvent(event); |
|
148 | ChartItem::mousePressEvent(event); | |
147 | } |
|
149 | } | |
148 |
|
150 | |||
149 | #include "moc_areachartitem_p.cpp" |
|
151 | #include "moc_areachartitem_p.cpp" | |
150 |
|
152 | |||
151 | QTCOMMERCIALCHART_END_NAMESPACE |
|
153 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,204 +1,210 | |||||
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 "abstractbarchartitem_p.h" |
|
21 | #include "abstractbarchartitem_p.h" | |
22 | #include "bar_p.h" |
|
22 | #include "bar_p.h" | |
23 | #include "qbarset.h" |
|
23 | #include "qbarset.h" | |
24 | #include "qbarset_p.h" |
|
24 | #include "qbarset_p.h" | |
25 | #include "qabstractbarseries.h" |
|
25 | #include "qabstractbarseries.h" | |
26 | #include "qabstractbarseries_p.h" |
|
26 | #include "qabstractbarseries_p.h" | |
27 | #include "qchart.h" |
|
27 | #include "qchart.h" | |
28 | #include "chartpresenter_p.h" |
|
28 | #include "chartpresenter_p.h" | |
29 | #include "charttheme_p.h" |
|
29 | #include "charttheme_p.h" | |
30 | #include "abstractbaranimation_p.h" |
|
30 | #include "abstractbaranimation_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : |
|
36 | AbstractBarChartItem::AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) : | |
37 | ChartItem(presenter), |
|
37 | ChartItem(presenter), | |
38 | m_animation(0), |
|
38 | m_animation(0), | |
39 | m_series(series) |
|
39 | m_series(series) | |
40 | { |
|
40 | { | |
41 |
|
41 | |||
42 | setFlag(ItemClipsChildrenToShape); |
|
42 | setFlag(ItemClipsChildrenToShape); | |
43 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); |
|
43 | connect(series->d_func(), SIGNAL(updatedLayout()), this, SLOT(handleLayoutChanged())); | |
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); |
|
44 | connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleUpdatedBars())); | |
45 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); |
|
45 | connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool))); | |
46 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); |
|
46 | connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged())); | |
47 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); |
|
47 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged())); | |
|
48 | connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); | |||
48 | setZValue(ChartPresenter::BarSeriesZValue); |
|
49 | setZValue(ChartPresenter::BarSeriesZValue); | |
49 | handleDataStructureChanged(); |
|
50 | handleDataStructureChanged(); | |
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | AbstractBarChartItem::~AbstractBarChartItem() |
|
53 | AbstractBarChartItem::~AbstractBarChartItem() | |
53 | { |
|
54 | { | |
54 | } |
|
55 | } | |
55 |
|
56 | |||
56 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
57 | void AbstractBarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
57 | { |
|
58 | { | |
58 | Q_UNUSED(painter); |
|
59 | Q_UNUSED(painter); | |
59 | Q_UNUSED(option); |
|
60 | Q_UNUSED(option); | |
60 | Q_UNUSED(widget); |
|
61 | Q_UNUSED(widget); | |
61 | } |
|
62 | } | |
62 |
|
63 | |||
63 | QRectF AbstractBarChartItem::boundingRect() const |
|
64 | QRectF AbstractBarChartItem::boundingRect() const | |
64 | { |
|
65 | { | |
65 | return m_rect; |
|
66 | return m_rect; | |
66 | } |
|
67 | } | |
67 |
|
68 | |||
68 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) |
|
69 | void AbstractBarChartItem::applyLayout(const QVector<QRectF> &layout) | |
69 | { |
|
70 | { | |
70 | if (m_animation) { |
|
71 | if (m_animation) { | |
71 | m_animation->setup(m_layout,layout); |
|
72 | m_animation->setup(m_layout,layout); | |
72 | presenter()->startAnimation(m_animation); |
|
73 | presenter()->startAnimation(m_animation); | |
73 |
|
74 | |||
74 | } else { |
|
75 | } else { | |
75 | setLayout(layout); |
|
76 | setLayout(layout); | |
76 | update(); |
|
77 | update(); | |
77 | } |
|
78 | } | |
78 | } |
|
79 | } | |
79 |
|
80 | |||
80 | void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation) |
|
81 | void AbstractBarChartItem::setAnimation(AbstractBarAnimation *animation) | |
81 | { |
|
82 | { | |
82 | m_animation = animation; |
|
83 | m_animation = animation; | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) |
|
86 | void AbstractBarChartItem::setLayout(const QVector<QRectF> &layout) | |
86 | { |
|
87 | { | |
87 | if (layout.count() != m_bars.count()) |
|
88 | if (layout.count() != m_bars.count()) | |
88 | return; |
|
89 | return; | |
89 |
|
90 | |||
90 | m_layout = layout; |
|
91 | m_layout = layout; | |
91 |
|
92 | |||
92 | for (int i=0; i < m_bars.count(); i++) { |
|
93 | for (int i=0; i < m_bars.count(); i++) { | |
93 | m_bars.at(i)->setRect(layout.at(i)); |
|
94 | m_bars.at(i)->setRect(layout.at(i)); | |
94 | } |
|
95 | } | |
95 | } |
|
96 | } | |
96 | //handlers |
|
97 | //handlers | |
97 |
|
98 | |||
98 | void AbstractBarChartItem::handleDomainUpdated() |
|
99 | void AbstractBarChartItem::handleDomainUpdated() | |
99 | { |
|
100 | { | |
100 | m_domainMinX = domain()->minX(); |
|
101 | m_domainMinX = domain()->minX(); | |
101 | m_domainMaxX = domain()->maxX(); |
|
102 | m_domainMaxX = domain()->maxX(); | |
102 | m_domainMinY = domain()->minY(); |
|
103 | m_domainMinY = domain()->minY(); | |
103 | m_domainMaxY = domain()->maxY(); |
|
104 | m_domainMaxY = domain()->maxY(); | |
104 | handleLayoutChanged(); |
|
105 | handleLayoutChanged(); | |
105 | } |
|
106 | } | |
106 |
|
107 | |||
107 | void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect) |
|
108 | void AbstractBarChartItem::handleGeometryChanged(const QRectF &rect) | |
108 | { |
|
109 | { | |
109 | prepareGeometryChange(); |
|
110 | prepareGeometryChange(); | |
110 | m_rect = rect; |
|
111 | m_rect = rect; | |
111 | handleLayoutChanged(); |
|
112 | handleLayoutChanged(); | |
112 | } |
|
113 | } | |
113 |
|
114 | |||
114 | void AbstractBarChartItem::handleLayoutChanged() |
|
115 | void AbstractBarChartItem::handleLayoutChanged() | |
115 | { |
|
116 | { | |
116 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { |
|
117 | if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) { | |
117 | // rect size zero. |
|
118 | // rect size zero. | |
118 | return; |
|
119 | return; | |
119 | } |
|
120 | } | |
120 | QVector<QRectF> layout = calculateLayout(); |
|
121 | QVector<QRectF> layout = calculateLayout(); | |
121 | applyLayout(layout); |
|
122 | applyLayout(layout); | |
122 | } |
|
123 | } | |
123 |
|
124 | |||
124 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) |
|
125 | void AbstractBarChartItem::handleLabelsVisibleChanged(bool visible) | |
125 | { |
|
126 | { | |
126 | foreach (QGraphicsSimpleTextItem* label, m_labels) { |
|
127 | foreach (QGraphicsSimpleTextItem* label, m_labels) { | |
127 | label->setVisible(visible); |
|
128 | label->setVisible(visible); | |
128 | } |
|
129 | } | |
129 | update(); |
|
130 | update(); | |
130 | } |
|
131 | } | |
131 |
|
132 | |||
132 | void AbstractBarChartItem::handleDataStructureChanged() |
|
133 | void AbstractBarChartItem::handleDataStructureChanged() | |
133 | { |
|
134 | { | |
134 | foreach(QGraphicsItem *item, childItems()) { |
|
135 | foreach(QGraphicsItem *item, childItems()) { | |
135 | delete item; |
|
136 | delete item; | |
136 | } |
|
137 | } | |
137 |
|
138 | |||
138 | m_bars.clear(); |
|
139 | m_bars.clear(); | |
139 | m_labels.clear(); |
|
140 | m_labels.clear(); | |
140 | m_layout.clear(); |
|
141 | m_layout.clear(); | |
141 |
|
142 | |||
142 | bool labelsVisible = m_series->isLabelsVisible(); |
|
143 | bool labelsVisible = m_series->isLabelsVisible(); | |
143 |
|
144 | |||
144 | // Create new graphic items for bars |
|
145 | // Create new graphic items for bars | |
145 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { |
|
146 | for (int c = 0; c < m_series->d_func()->categoryCount(); c++) { | |
146 | for (int s = 0; s < m_series->count(); s++) { |
|
147 | for (int s = 0; s < m_series->count(); s++) { | |
147 | QBarSet *set = m_series->d_func()->barsetAt(s); |
|
148 | QBarSet *set = m_series->d_func()->barsetAt(s); | |
148 |
|
149 | |||
149 | // Bars |
|
150 | // Bars | |
150 | Bar *bar = new Bar(set,c,this); |
|
151 | Bar *bar = new Bar(set,c,this); | |
151 | m_bars.append(bar); |
|
152 | m_bars.append(bar); | |
152 | connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*))); |
|
153 | connect(bar, SIGNAL(clicked(int,QBarSet*)), m_series, SIGNAL(clicked(int,QBarSet*))); | |
153 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*))); |
|
154 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), m_series, SIGNAL(hovered(bool,QBarSet*))); | |
154 | connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int))); |
|
155 | connect(bar, SIGNAL(clicked(int,QBarSet*)), set, SIGNAL(clicked(int))); | |
155 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool))); |
|
156 | connect(bar, SIGNAL(hovered(bool,QBarSet*)), set, SIGNAL(hovered(bool))); | |
156 | m_layout.append(QRectF(0, 0, 0, 0)); |
|
157 | m_layout.append(QRectF(0, 0, 0, 0)); | |
157 |
|
158 | |||
158 | // Labels |
|
159 | // Labels | |
159 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); |
|
160 | QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this); | |
160 | label->setVisible(labelsVisible); |
|
161 | label->setVisible(labelsVisible); | |
161 | m_labels.append(label); |
|
162 | m_labels.append(label); | |
162 | } |
|
163 | } | |
163 | } |
|
164 | } | |
164 |
|
165 | |||
165 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
166 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
166 | handleLayoutChanged(); |
|
167 | handleLayoutChanged(); | |
167 | } |
|
168 | } | |
168 |
|
169 | |||
169 | void AbstractBarChartItem::handleVisibleChanged() |
|
170 | void AbstractBarChartItem::handleVisibleChanged() | |
170 | { |
|
171 | { | |
171 | bool visible = m_series->isVisible(); |
|
172 | bool visible = m_series->isVisible(); | |
172 | handleLabelsVisibleChanged(visible); |
|
173 | handleLabelsVisibleChanged(visible); | |
173 |
foreach(QGraphicsItem *item, childItems()) |
|
174 | foreach(QGraphicsItem *item, childItems()) | |
174 | item->setVisible(visible); |
|
175 | item->setVisible(visible); | |
175 | } |
|
176 | } | |
|
177 | ||||
|
178 | void AbstractBarChartItem::handleOpacityChanged() | |||
|
179 | { | |||
|
180 | foreach(QGraphicsItem *item, childItems()) | |||
|
181 | item->setOpacity(m_series->opacity()); | |||
176 | } |
|
182 | } | |
177 |
|
183 | |||
178 | void AbstractBarChartItem::handleUpdatedBars() |
|
184 | void AbstractBarChartItem::handleUpdatedBars() | |
179 | { |
|
185 | { | |
180 | // Handle changes in pen, brush, labels etc. |
|
186 | // Handle changes in pen, brush, labels etc. | |
181 | int categoryCount = m_series->d_func()->categoryCount(); |
|
187 | int categoryCount = m_series->d_func()->categoryCount(); | |
182 | int setCount = m_series->count(); |
|
188 | int setCount = m_series->count(); | |
183 | int itemIndex(0); |
|
189 | int itemIndex(0); | |
184 |
|
190 | |||
185 | for (int category = 0; category < categoryCount; category++) { |
|
191 | for (int category = 0; category < categoryCount; category++) { | |
186 | for (int set = 0; set < setCount; set++) { |
|
192 | for (int set = 0; set < setCount; set++) { | |
187 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); |
|
193 | QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data(); | |
188 | Bar* bar = m_bars.at(itemIndex); |
|
194 | Bar* bar = m_bars.at(itemIndex); | |
189 | bar->setPen(barSet->m_pen); |
|
195 | bar->setPen(barSet->m_pen); | |
190 | bar->setBrush(barSet->m_brush); |
|
196 | bar->setBrush(barSet->m_brush); | |
191 | bar->update(); |
|
197 | bar->update(); | |
192 |
|
198 | |||
193 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); |
|
199 | QGraphicsSimpleTextItem* label = m_labels.at(itemIndex); | |
194 | label->setFont(barSet->m_labelFont); |
|
200 | label->setFont(barSet->m_labelFont); | |
195 | label->setBrush(barSet->m_labelBrush); |
|
201 | label->setBrush(barSet->m_labelBrush); | |
196 | label->update(); |
|
202 | label->update(); | |
197 | itemIndex++; |
|
203 | itemIndex++; | |
198 | } |
|
204 | } | |
199 | } |
|
205 | } | |
200 | } |
|
206 | } | |
201 |
|
207 | |||
202 | #include "moc_abstractbarchartitem_p.cpp" |
|
208 | #include "moc_abstractbarchartitem_p.cpp" | |
203 |
|
209 | |||
204 | QTCOMMERCIALCHART_END_NAMESPACE |
|
210 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,92 +1,93 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 |
|
30 | |||
31 | #ifndef ABSTRACTBARCHARTITEM_H |
|
31 | #ifndef ABSTRACTBARCHARTITEM_H | |
32 | #define ABSTRACTBARCHARTITEM_H |
|
32 | #define ABSTRACTBARCHARTITEM_H | |
33 |
|
33 | |||
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "qabstractbarseries.h" |
|
35 | #include "qabstractbarseries.h" | |
36 | #include <QPen> |
|
36 | #include <QPen> | |
37 | #include <QBrush> |
|
37 | #include <QBrush> | |
38 |
|
38 | |||
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
40 |
|
40 | |||
41 | class Bar; |
|
41 | class Bar; | |
42 | class QAxisCategories; |
|
42 | class QAxisCategories; | |
43 | class QChart; |
|
43 | class QChart; | |
44 | class AbstractBarAnimation; |
|
44 | class AbstractBarAnimation; | |
45 |
|
45 | |||
46 | class AbstractBarChartItem : public ChartItem |
|
46 | class AbstractBarChartItem : public ChartItem | |
47 | { |
|
47 | { | |
48 | Q_OBJECT |
|
48 | Q_OBJECT | |
49 | public: |
|
49 | public: | |
50 | AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); |
|
50 | AbstractBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter); | |
51 | virtual ~AbstractBarChartItem(); |
|
51 | virtual ~AbstractBarChartItem(); | |
52 |
|
52 | |||
53 | public: |
|
53 | public: | |
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); |
|
54 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); | |
55 | QRectF boundingRect() const; |
|
55 | QRectF boundingRect() const; | |
56 |
|
56 | |||
57 | virtual QVector<QRectF> calculateLayout() = 0; |
|
57 | virtual QVector<QRectF> calculateLayout() = 0; | |
58 | virtual void applyLayout(const QVector<QRectF> &layout); |
|
58 | virtual void applyLayout(const QVector<QRectF> &layout); | |
59 | virtual void setAnimation(AbstractBarAnimation* animation); |
|
59 | virtual void setAnimation(AbstractBarAnimation* animation); | |
60 | void setLayout(const QVector<QRectF> &layout); |
|
60 | void setLayout(const QVector<QRectF> &layout); | |
61 | void updateLayout(const QVector<QRectF> &layout); |
|
61 | void updateLayout(const QVector<QRectF> &layout); | |
62 | QRectF geometry() const { return m_rect;} |
|
62 | QRectF geometry() const { return m_rect;} | |
63 |
|
63 | |||
64 | public Q_SLOTS: |
|
64 | public Q_SLOTS: | |
65 | void handleDomainUpdated(); |
|
65 | void handleDomainUpdated(); | |
66 | void handleGeometryChanged(const QRectF &size); |
|
66 | void handleGeometryChanged(const QRectF &size); | |
67 | void handleLayoutChanged(); |
|
67 | void handleLayoutChanged(); | |
68 | void handleLabelsVisibleChanged(bool visible); |
|
68 | void handleLabelsVisibleChanged(bool visible); | |
69 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items |
|
69 | void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items | |
70 | void handleVisibleChanged(); |
|
70 | void handleVisibleChanged(); | |
|
71 | void handleOpacityChanged(); | |||
71 | void handleUpdatedBars(); |
|
72 | void handleUpdatedBars(); | |
72 |
|
73 | |||
73 | protected: |
|
74 | protected: | |
74 |
|
75 | |||
75 | qreal m_domainMinX; |
|
76 | qreal m_domainMinX; | |
76 | qreal m_domainMaxX; |
|
77 | qreal m_domainMaxX; | |
77 | qreal m_domainMinY; |
|
78 | qreal m_domainMinY; | |
78 | qreal m_domainMaxY; |
|
79 | qreal m_domainMaxY; | |
79 |
|
80 | |||
80 | QRectF m_rect; |
|
81 | QRectF m_rect; | |
81 | QVector<QRectF> m_layout; |
|
82 | QVector<QRectF> m_layout; | |
82 |
|
83 | |||
83 | AbstractBarAnimation *m_animation; |
|
84 | AbstractBarAnimation *m_animation; | |
84 |
|
85 | |||
85 | QAbstractBarSeries *m_series; // Not owned. |
|
86 | QAbstractBarSeries *m_series; // Not owned. | |
86 | QList<Bar *> m_bars; |
|
87 | QList<Bar *> m_bars; | |
87 | QList<QGraphicsSimpleTextItem *> m_labels; |
|
88 | QList<QGraphicsSimpleTextItem *> m_labels; | |
88 | }; |
|
89 | }; | |
89 |
|
90 | |||
90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
91 | QTCOMMERCIALCHART_END_NAMESPACE | |
91 |
|
92 | |||
92 | #endif // ABSTRACTBARCHARTITEM_H |
|
93 | #endif // ABSTRACTBARCHARTITEM_H |
@@ -1,139 +1,141 | |||||
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 "linechartitem_p.h" |
|
21 | #include "linechartitem_p.h" | |
22 | #include "qlineseries.h" |
|
22 | #include "qlineseries.h" | |
23 | #include "qlineseries_p.h" |
|
23 | #include "qlineseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsSceneMouseEvent> |
|
26 | #include <QGraphicsSceneMouseEvent> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | const qreal mouseEventMinWidth(12); |
|
30 | const qreal mouseEventMinWidth(12); | |
31 |
|
31 | |||
32 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter): |
|
32 | LineChartItem::LineChartItem(QLineSeries* series,ChartPresenter *presenter): | |
33 | XYChart(series, presenter), |
|
33 | XYChart(series, presenter), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_pointsVisible(false) |
|
36 | m_pointsVisible(false) | |
37 | { |
|
37 | { | |
38 | setZValue(ChartPresenter::LineChartZValue); |
|
38 | setZValue(ChartPresenter::LineChartZValue); | |
39 | QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
39 | QObject::connect(series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
40 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
40 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
|
41 | QObject::connect(series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); | |||
41 | handleUpdated(); |
|
42 | handleUpdated(); | |
42 | } |
|
43 | } | |
43 |
|
44 | |||
44 | QRectF LineChartItem::boundingRect() const |
|
45 | QRectF LineChartItem::boundingRect() const | |
45 | { |
|
46 | { | |
46 | return m_rect; |
|
47 | return m_rect; | |
47 | } |
|
48 | } | |
48 |
|
49 | |||
49 | QPainterPath LineChartItem::shape() const |
|
50 | QPainterPath LineChartItem::shape() const | |
50 | { |
|
51 | { | |
51 | return m_path; |
|
52 | return m_path; | |
52 | } |
|
53 | } | |
53 |
|
54 | |||
54 | void LineChartItem::updateGeometry() |
|
55 | void LineChartItem::updateGeometry() | |
55 | { |
|
56 | { | |
56 | m_points = geometryPoints(); |
|
57 | m_points = geometryPoints(); | |
57 |
|
58 | |||
58 | if(m_points.size()==0) |
|
59 | if(m_points.size()==0) | |
59 | { |
|
60 | { | |
60 | prepareGeometryChange(); |
|
61 | prepareGeometryChange(); | |
61 | m_path = QPainterPath(); |
|
62 | m_path = QPainterPath(); | |
62 | m_rect = QRect(); |
|
63 | m_rect = QRect(); | |
63 | return; |
|
64 | return; | |
64 | } |
|
65 | } | |
65 |
|
66 | |||
66 | QPainterPath linePath(m_points.at(0)); |
|
67 | QPainterPath linePath(m_points.at(0)); | |
67 |
|
68 | |||
68 | if(m_pointsVisible) { |
|
69 | if(m_pointsVisible) { | |
69 |
|
70 | |||
70 | int size = m_linePen.width(); |
|
71 | int size = m_linePen.width(); | |
71 | linePath.addEllipse(m_points.at(0),size,size); |
|
72 | linePath.addEllipse(m_points.at(0),size,size); | |
72 | for(int i=1; i< m_points.size();i++) { |
|
73 | for(int i=1; i< m_points.size();i++) { | |
73 | linePath.lineTo(m_points.at(i)); |
|
74 | linePath.lineTo(m_points.at(i)); | |
74 | linePath.addEllipse(m_points.at(i),size,size); |
|
75 | linePath.addEllipse(m_points.at(i),size,size); | |
75 | } |
|
76 | } | |
76 |
|
77 | |||
77 | } else { |
|
78 | } else { | |
78 |
|
79 | |||
79 | for(int i=1; i< m_points.size();i++) { |
|
80 | for(int i=1; i< m_points.size();i++) { | |
80 | linePath.lineTo(m_points.at(i)); |
|
81 | linePath.lineTo(m_points.at(i)); | |
81 | } |
|
82 | } | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | m_linePath = linePath; |
|
85 | m_linePath = linePath; | |
85 |
|
86 | |||
86 | QPainterPathStroker stroker; |
|
87 | QPainterPathStroker stroker; | |
87 | // QPainter::drawLine does not respect join styles, for example BevelJoin becomes MiterJoin. |
|
88 | // QPainter::drawLine does not respect join styles, for example BevelJoin becomes MiterJoin. | |
88 | // This is why we are prepared for the "worst case" scenario, i.e. use always MiterJoin and |
|
89 | // This is why we are prepared for the "worst case" scenario, i.e. use always MiterJoin and | |
89 | // multiply line width with square root of two when defining shape and bounding rectangle. |
|
90 | // multiply line width with square root of two when defining shape and bounding rectangle. | |
90 | stroker.setWidth(m_linePen.width() * 1.42); |
|
91 | stroker.setWidth(m_linePen.width() * 1.42); | |
91 | stroker.setJoinStyle(Qt::MiterJoin); |
|
92 | stroker.setJoinStyle(Qt::MiterJoin); | |
92 | stroker.setCapStyle(Qt::SquareCap); |
|
93 | stroker.setCapStyle(Qt::SquareCap); | |
93 | stroker.setMiterLimit(m_linePen.miterLimit()); |
|
94 | stroker.setMiterLimit(m_linePen.miterLimit()); | |
94 |
|
95 | |||
95 | prepareGeometryChange(); |
|
96 | prepareGeometryChange(); | |
96 |
|
97 | |||
97 | m_path = stroker.createStroke(linePath); |
|
98 | m_path = stroker.createStroke(linePath); | |
98 | m_rect = m_path.boundingRect(); |
|
99 | m_rect = m_path.boundingRect(); | |
99 |
|
100 | |||
100 | setPos(origin()); |
|
101 | setPos(origin()); | |
101 | } |
|
102 | } | |
102 |
|
103 | |||
103 | void LineChartItem::handleUpdated() |
|
104 | void LineChartItem::handleUpdated() | |
104 | { |
|
105 | { | |
105 | setVisible(m_series->isVisible()); |
|
106 | setVisible(m_series->isVisible()); | |
|
107 | setOpacity(m_series->opacity()); | |||
106 | m_pointsVisible = m_series->pointsVisible(); |
|
108 | m_pointsVisible = m_series->pointsVisible(); | |
107 | m_linePen = m_series->pen(); |
|
109 | m_linePen = m_series->pen(); | |
108 | update(); |
|
110 | update(); | |
109 | } |
|
111 | } | |
110 |
|
112 | |||
111 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
113 | void LineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
112 | { |
|
114 | { | |
113 | Q_UNUSED(widget) |
|
115 | Q_UNUSED(widget) | |
114 | Q_UNUSED(option) |
|
116 | Q_UNUSED(option) | |
115 |
|
117 | |||
116 | painter->save(); |
|
118 | painter->save(); | |
117 | painter->setPen(m_linePen); |
|
119 | painter->setPen(m_linePen); | |
118 | painter->setBrush(m_linePen.color()); |
|
120 | painter->setBrush(m_linePen.color()); | |
119 | painter->setClipRect(clipRect()); |
|
121 | painter->setClipRect(clipRect()); | |
120 |
|
122 | |||
121 | if (m_pointsVisible) { |
|
123 | if (m_pointsVisible) { | |
122 | painter->drawPath(m_linePath); |
|
124 | painter->drawPath(m_linePath); | |
123 | } |
|
125 | } | |
124 | else { |
|
126 | else { | |
125 | for (int i(1); i < m_points.size();i++) |
|
127 | for (int i(1); i < m_points.size();i++) | |
126 | painter->drawLine(m_points.at(i-1), m_points.at(i)); |
|
128 | painter->drawLine(m_points.at(i-1), m_points.at(i)); | |
127 | } |
|
129 | } | |
128 | painter->restore(); |
|
130 | painter->restore(); | |
129 | } |
|
131 | } | |
130 |
|
132 | |||
131 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
133 | void LineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
132 | { |
|
134 | { | |
133 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
135 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
134 | QGraphicsItem::mousePressEvent(event); |
|
136 | QGraphicsItem::mousePressEvent(event); | |
135 | } |
|
137 | } | |
136 |
|
138 | |||
137 | #include "moc_linechartitem_p.cpp" |
|
139 | #include "moc_linechartitem_p.cpp" | |
138 |
|
140 | |||
139 | QTCOMMERCIALCHART_END_NAMESPACE |
|
141 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,242 +1,248 | |||||
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 "piechartitem_p.h" |
|
21 | #include "piechartitem_p.h" | |
22 | #include "piesliceitem_p.h" |
|
22 | #include "piesliceitem_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "qpieseries.h" |
|
25 | #include "qpieseries.h" | |
26 | #include "qpieseries_p.h" |
|
26 | #include "qpieseries_p.h" | |
27 | #include "chartpresenter_p.h" |
|
27 | #include "chartpresenter_p.h" | |
28 | #include "chartdataset_p.h" |
|
28 | #include "chartdataset_p.h" | |
29 | #include "pieanimation_p.h" |
|
29 | #include "pieanimation_p.h" | |
30 | #include <QPainter> |
|
30 | #include <QPainter> | |
31 | #include <QTimer> |
|
31 | #include <QTimer> | |
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 |
|
34 | |||
35 | PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) |
|
35 | PieChartItem::PieChartItem(QPieSeries *series, ChartPresenter* presenter) | |
36 | :ChartItem(presenter), |
|
36 | :ChartItem(presenter), | |
37 | m_series(series), |
|
37 | m_series(series), | |
38 | m_animation(0) |
|
38 | m_animation(0) | |
39 | { |
|
39 | { | |
40 | Q_ASSERT(series); |
|
40 | Q_ASSERT(series); | |
41 |
|
41 | |||
42 | QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series); |
|
42 | QPieSeriesPrivate *p = QPieSeriesPrivate::fromSeries(series); | |
43 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
43 | connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
|
44 | connect(series, SIGNAL(opacityChanged()), this, SLOT(handleOpacityChanged())); | |||
44 | connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>))); |
|
45 | connect(series, SIGNAL(added(QList<QPieSlice*>)), this, SLOT(handleSlicesAdded(QList<QPieSlice*>))); | |
45 | connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>))); |
|
46 | connect(series, SIGNAL(removed(QList<QPieSlice*>)), this, SLOT(handleSlicesRemoved(QList<QPieSlice*>))); | |
46 | connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout())); |
|
47 | connect(p, SIGNAL(horizontalPositionChanged()), this, SLOT(updateLayout())); | |
47 | connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout())); |
|
48 | connect(p, SIGNAL(verticalPositionChanged()), this, SLOT(updateLayout())); | |
48 | connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); |
|
49 | connect(p, SIGNAL(pieSizeChanged()), this, SLOT(updateLayout())); | |
49 | connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout())); |
|
50 | connect(p, SIGNAL(calculatedDataChanged()), this, SLOT(updateLayout())); | |
50 |
|
51 | |||
51 | // Note: the following does not affect as long as the item does not have anything to paint |
|
52 | // Note: the following does not affect as long as the item does not have anything to paint | |
52 | setZValue(ChartPresenter::PieSeriesZValue); |
|
53 | setZValue(ChartPresenter::PieSeriesZValue); | |
53 |
|
54 | |||
54 | // Note: will not create slice items until we have a proper rectangle to draw on. |
|
55 | // Note: will not create slice items until we have a proper rectangle to draw on. | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | PieChartItem::~PieChartItem() |
|
58 | PieChartItem::~PieChartItem() | |
58 | { |
|
59 | { | |
59 | // slices deleted automatically through QGraphicsItem |
|
60 | // slices deleted automatically through QGraphicsItem | |
60 | } |
|
61 | } | |
61 |
|
62 | |||
62 | void PieChartItem::setAnimation(PieAnimation* animation) |
|
63 | void PieChartItem::setAnimation(PieAnimation* animation) | |
63 | { |
|
64 | { | |
64 | m_animation=animation; |
|
65 | m_animation=animation; | |
65 | } |
|
66 | } | |
66 |
|
67 | |||
67 | ChartAnimation* PieChartItem::animation() const |
|
68 | ChartAnimation* PieChartItem::animation() const | |
68 | { |
|
69 | { | |
69 | return m_animation; |
|
70 | return m_animation; | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | void PieChartItem::handleGeometryChanged(const QRectF& rect) |
|
73 | void PieChartItem::handleGeometryChanged(const QRectF& rect) | |
73 | { |
|
74 | { | |
74 | prepareGeometryChange(); |
|
75 | prepareGeometryChange(); | |
75 | m_rect = rect; |
|
76 | m_rect = rect; | |
76 | updateLayout(); |
|
77 | updateLayout(); | |
77 |
|
78 | |||
78 | // This is for delayed initialization of the slice items during startup. |
|
79 | // This is for delayed initialization of the slice items during startup. | |
79 | // It ensures that startup animation originates from the correct position. |
|
80 | // It ensures that startup animation originates from the correct position. | |
80 | if (m_sliceItems.isEmpty()) |
|
81 | if (m_sliceItems.isEmpty()) | |
81 | handleSlicesAdded(m_series->slices()); |
|
82 | handleSlicesAdded(m_series->slices()); | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) |
|
85 | void PieChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
85 | { |
|
86 | { | |
86 | Q_UNUSED(minX); |
|
87 | Q_UNUSED(minX); | |
87 | Q_UNUSED(maxX); |
|
88 | Q_UNUSED(maxX); | |
88 | Q_UNUSED(minY); |
|
89 | Q_UNUSED(minY); | |
89 | Q_UNUSED(maxY); |
|
90 | Q_UNUSED(maxY); | |
90 | // does not apply to pie |
|
91 | // does not apply to pie | |
91 | } |
|
92 | } | |
92 |
|
93 | |||
93 | void PieChartItem::handleDomainUpdated() |
|
94 | void PieChartItem::handleDomainUpdated() | |
94 | { |
|
95 | { | |
95 | // does not apply to pie |
|
96 | // does not apply to pie | |
96 | } |
|
97 | } | |
97 |
|
98 | |||
98 | void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount) |
|
99 | void PieChartItem::rangeXChanged(qreal min, qreal max, int tickXCount) | |
99 | { |
|
100 | { | |
100 | Q_UNUSED(min); |
|
101 | Q_UNUSED(min); | |
101 | Q_UNUSED(max); |
|
102 | Q_UNUSED(max); | |
102 | Q_UNUSED(tickXCount); |
|
103 | Q_UNUSED(tickXCount); | |
103 | // does not apply to pie |
|
104 | // does not apply to pie | |
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 | void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) |
|
107 | void PieChartItem::rangeYChanged(qreal min, qreal max, int tickYCount) | |
107 | { |
|
108 | { | |
108 | Q_UNUSED(min); |
|
109 | Q_UNUSED(min); | |
109 | Q_UNUSED(max); |
|
110 | Q_UNUSED(max); | |
110 | Q_UNUSED(tickYCount); |
|
111 | Q_UNUSED(tickYCount); | |
111 | // does not apply to pie |
|
112 | // does not apply to pie | |
112 | } |
|
113 | } | |
113 |
|
114 | |||
114 | void PieChartItem::updateLayout() |
|
115 | void PieChartItem::updateLayout() | |
115 | { |
|
116 | { | |
116 | // find pie center coordinates |
|
117 | // find pie center coordinates | |
117 | m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition())); |
|
118 | m_pieCenter.setX(m_rect.left() + (m_rect.width() * m_series->horizontalPosition())); | |
118 | m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition())); |
|
119 | m_pieCenter.setY(m_rect.top() + (m_rect.height() * m_series->verticalPosition())); | |
119 |
|
120 | |||
120 | // find maximum radius for pie |
|
121 | // find maximum radius for pie | |
121 | m_pieRadius = m_rect.height() / 2; |
|
122 | m_pieRadius = m_rect.height() / 2; | |
122 | if (m_rect.width() < m_rect.height()) |
|
123 | if (m_rect.width() < m_rect.height()) | |
123 | m_pieRadius = m_rect.width() / 2; |
|
124 | m_pieRadius = m_rect.width() / 2; | |
124 |
|
125 | |||
125 | m_holeSize = m_pieRadius; |
|
126 | m_holeSize = m_pieRadius; | |
126 | // apply size factor |
|
127 | // apply size factor | |
127 | m_pieRadius *= m_series->pieSize(); |
|
128 | m_pieRadius *= m_series->pieSize(); | |
128 | m_holeSize *= m_series->holeSize(); |
|
129 | m_holeSize *= m_series->holeSize(); | |
129 |
|
130 | |||
130 | // set layouts for existing slice items |
|
131 | // set layouts for existing slice items | |
131 | foreach (QPieSlice* slice, m_series->slices()) { |
|
132 | foreach (QPieSlice* slice, m_series->slices()) { | |
132 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
133 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
133 | if (sliceItem) { |
|
134 | if (sliceItem) { | |
134 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
135 | PieSliceData sliceData = updateSliceGeometry(slice); | |
135 | if (m_animation){ |
|
136 | if (m_animation){ | |
136 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); |
|
137 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); | |
137 | } |
|
138 | } | |
138 | else |
|
139 | else | |
139 | sliceItem->setLayout(sliceData); |
|
140 | sliceItem->setLayout(sliceData); | |
140 | } |
|
141 | } | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | update(); |
|
144 | update(); | |
144 | } |
|
145 | } | |
145 |
|
146 | |||
146 | void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) |
|
147 | void PieChartItem::handleSlicesAdded(QList<QPieSlice*> slices) | |
147 | { |
|
148 | { | |
148 | // delay creating slice items until there is a proper rectangle |
|
149 | // delay creating slice items until there is a proper rectangle | |
149 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) |
|
150 | if (!m_rect.isValid() && m_sliceItems.isEmpty()) | |
150 | return; |
|
151 | return; | |
151 |
|
152 | |||
152 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
153 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
153 |
|
154 | |||
154 | bool startupAnimation = m_sliceItems.isEmpty(); |
|
155 | bool startupAnimation = m_sliceItems.isEmpty(); | |
155 |
|
156 | |||
156 | foreach (QPieSlice *slice, slices) { |
|
157 | foreach (QPieSlice *slice, slices) { | |
157 | PieSliceItem* sliceItem = new PieSliceItem(this); |
|
158 | PieSliceItem* sliceItem = new PieSliceItem(this); | |
158 | m_sliceItems.insert(slice, sliceItem); |
|
159 | m_sliceItems.insert(slice, sliceItem); | |
159 |
|
160 | |||
160 | // Note: no need to connect to slice valueChanged() etc. |
|
161 | // Note: no need to connect to slice valueChanged() etc. | |
161 | // This is handled through calculatedDataChanged signal. |
|
162 | // This is handled through calculatedDataChanged signal. | |
162 | connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged())); |
|
163 | connect(slice, SIGNAL(labelChanged()), this, SLOT(handleSliceChanged())); | |
163 | connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged())); |
|
164 | connect(slice, SIGNAL(labelVisibleChanged()), this, SLOT(handleSliceChanged())); | |
164 | connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); |
|
165 | connect(slice, SIGNAL(penChanged()), this, SLOT(handleSliceChanged())); | |
165 | connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); |
|
166 | connect(slice, SIGNAL(brushChanged()), this, SLOT(handleSliceChanged())); | |
166 | connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged())); |
|
167 | connect(slice, SIGNAL(labelBrushChanged()), this, SLOT(handleSliceChanged())); | |
167 | connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); |
|
168 | connect(slice, SIGNAL(labelFontChanged()), this, SLOT(handleSliceChanged())); | |
168 |
|
169 | |||
169 | QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice); |
|
170 | QPieSlicePrivate *p = QPieSlicePrivate::fromSlice(slice); | |
170 | connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged())); |
|
171 | connect(p, SIGNAL(labelPositionChanged()), this, SLOT(handleSliceChanged())); | |
171 | connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); |
|
172 | connect(p, SIGNAL(explodedChanged()), this, SLOT(handleSliceChanged())); | |
172 | connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); |
|
173 | connect(p, SIGNAL(labelArmLengthFactorChanged()), this, SLOT(handleSliceChanged())); | |
173 | connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); |
|
174 | connect(p, SIGNAL(explodeDistanceFactorChanged()), this, SLOT(handleSliceChanged())); | |
174 |
|
175 | |||
175 | connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked())); |
|
176 | connect(sliceItem, SIGNAL(clicked(Qt::MouseButtons)), slice, SIGNAL(clicked())); | |
176 | connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); |
|
177 | connect(sliceItem, SIGNAL(hovered(bool)), slice, SIGNAL(hovered(bool))); | |
177 |
|
178 | |||
178 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
179 | PieSliceData sliceData = updateSliceGeometry(slice); | |
179 | if (m_animation) |
|
180 | if (m_animation) | |
180 | presenter()->startAnimation(m_animation->addSlice(sliceItem, sliceData, startupAnimation)); |
|
181 | presenter()->startAnimation(m_animation->addSlice(sliceItem, sliceData, startupAnimation)); | |
181 | else |
|
182 | else | |
182 | sliceItem->setLayout(sliceData); |
|
183 | sliceItem->setLayout(sliceData); | |
183 | } |
|
184 | } | |
184 | } |
|
185 | } | |
185 |
|
186 | |||
186 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) |
|
187 | void PieChartItem::handleSlicesRemoved(QList<QPieSlice*> slices) | |
187 | { |
|
188 | { | |
188 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); |
|
189 | presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series)); | |
189 |
|
190 | |||
190 | foreach (QPieSlice *slice, slices) { |
|
191 | foreach (QPieSlice *slice, slices) { | |
191 |
|
192 | |||
192 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
193 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
193 |
|
194 | |||
194 | // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created |
|
195 | // this can happen if you call append() & remove() in a row so that PieSliceItem is not even created | |
195 | if (!sliceItem) |
|
196 | if (!sliceItem) | |
196 | continue; |
|
197 | continue; | |
197 |
|
198 | |||
198 | m_sliceItems.remove(slice); |
|
199 | m_sliceItems.remove(slice); | |
199 |
|
200 | |||
200 | if (m_animation) |
|
201 | if (m_animation) | |
201 | presenter()->startAnimation(m_animation->removeSlice(sliceItem)); // animator deletes the PieSliceItem |
|
202 | presenter()->startAnimation(m_animation->removeSlice(sliceItem)); // animator deletes the PieSliceItem | |
202 | else |
|
203 | else | |
203 | delete sliceItem; |
|
204 | delete sliceItem; | |
204 | } |
|
205 | } | |
205 | } |
|
206 | } | |
206 |
|
207 | |||
207 | void PieChartItem::handleSliceChanged() |
|
208 | void PieChartItem::handleSliceChanged() | |
208 | { |
|
209 | { | |
209 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); |
|
210 | QPieSlice* slice = qobject_cast<QPieSlice *>(sender()); | |
210 | if (!slice) { |
|
211 | if (!slice) { | |
211 | QPieSlicePrivate* slicep = qobject_cast<QPieSlicePrivate *>(sender()); |
|
212 | QPieSlicePrivate* slicep = qobject_cast<QPieSlicePrivate *>(sender()); | |
212 | slice = slicep->q_ptr; |
|
213 | slice = slicep->q_ptr; | |
213 | } |
|
214 | } | |
214 | Q_ASSERT(m_sliceItems.contains(slice)); |
|
215 | Q_ASSERT(m_sliceItems.contains(slice)); | |
215 |
|
216 | |||
216 | PieSliceItem *sliceItem = m_sliceItems.value(slice); |
|
217 | PieSliceItem *sliceItem = m_sliceItems.value(slice); | |
217 | PieSliceData sliceData = updateSliceGeometry(slice); |
|
218 | PieSliceData sliceData = updateSliceGeometry(slice); | |
218 | if (m_animation) |
|
219 | if (m_animation) | |
219 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); |
|
220 | presenter()->startAnimation(m_animation->updateValue(sliceItem, sliceData)); | |
220 | else |
|
221 | else | |
221 | sliceItem->setLayout(sliceData); |
|
222 | sliceItem->setLayout(sliceData); | |
222 |
|
223 | |||
223 | update(); |
|
224 | update(); | |
224 | } |
|
225 | } | |
225 |
|
226 | |||
226 | void PieChartItem::handleSeriesVisibleChanged() |
|
227 | void PieChartItem::handleSeriesVisibleChanged() | |
227 | { |
|
228 | { | |
228 | setVisible(m_series->isVisible()); |
|
229 | setVisible(m_series->isVisible()); | |
229 | } |
|
230 | } | |
230 |
|
231 | |||
|
232 | void PieChartItem::handleOpacityChanged() | |||
|
233 | { | |||
|
234 | setOpacity(m_series->opacity()); | |||
|
235 | } | |||
|
236 | ||||
231 | PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) |
|
237 | PieSliceData PieChartItem::updateSliceGeometry(QPieSlice *slice) | |
232 | { |
|
238 | { | |
233 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; |
|
239 | PieSliceData &sliceData = QPieSlicePrivate::fromSlice(slice)->m_data; | |
234 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); |
|
240 | sliceData.m_center = PieSliceItem::sliceCenter(m_pieCenter, m_pieRadius, slice); | |
235 | sliceData.m_radius = m_pieRadius; |
|
241 | sliceData.m_radius = m_pieRadius; | |
236 | sliceData.m_holeRadius = m_holeSize; |
|
242 | sliceData.m_holeRadius = m_holeSize; | |
237 | return sliceData; |
|
243 | return sliceData; | |
238 | } |
|
244 | } | |
239 |
|
245 | |||
240 | #include "moc_piechartitem_p.cpp" |
|
246 | #include "moc_piechartitem_p.cpp" | |
241 |
|
247 | |||
242 | QTCOMMERCIALCHART_END_NAMESPACE |
|
248 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,88 +1,89 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef PIECHARTITEM_H |
|
30 | #ifndef PIECHARTITEM_H | |
31 | #define PIECHARTITEM_H |
|
31 | #define PIECHARTITEM_H | |
32 |
|
32 | |||
33 | #include "qpieseries.h" |
|
33 | #include "qpieseries.h" | |
34 | #include "chartitem_p.h" |
|
34 | #include "chartitem_p.h" | |
35 | #include "piesliceitem_p.h" |
|
35 | #include "piesliceitem_p.h" | |
36 |
|
36 | |||
37 | class QGraphicsItem; |
|
37 | class QGraphicsItem; | |
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
39 | class QPieSlice; |
|
39 | class QPieSlice; | |
40 | class ChartPresenter; |
|
40 | class ChartPresenter; | |
41 | class PieAnimation; |
|
41 | class PieAnimation; | |
42 |
|
42 | |||
43 | class PieChartItem : public ChartItem |
|
43 | class PieChartItem : public ChartItem | |
44 | { |
|
44 | { | |
45 | Q_OBJECT |
|
45 | Q_OBJECT | |
46 |
|
46 | |||
47 | public: |
|
47 | public: | |
48 | explicit PieChartItem(QPieSeries *series, ChartPresenter *presenter); |
|
48 | explicit PieChartItem(QPieSeries *series, ChartPresenter *presenter); | |
49 | ~PieChartItem(); |
|
49 | ~PieChartItem(); | |
50 |
|
50 | |||
51 | // from QGraphicsItem |
|
51 | // from QGraphicsItem | |
52 | QRectF boundingRect() const { return m_rect; } |
|
52 | QRectF boundingRect() const { return m_rect; } | |
53 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} |
|
53 | void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} | |
54 |
|
54 | |||
55 | public Q_SLOTS: |
|
55 | public Q_SLOTS: | |
56 | // from Chart |
|
56 | // from Chart | |
57 | virtual void handleGeometryChanged(const QRectF &rect); |
|
57 | virtual void handleGeometryChanged(const QRectF &rect); | |
58 | virtual void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); |
|
58 | virtual void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
59 | virtual void handleDomainUpdated(); |
|
59 | virtual void handleDomainUpdated(); | |
60 | virtual void rangeXChanged(qreal min, qreal max, int tickXCount); |
|
60 | virtual void rangeXChanged(qreal min, qreal max, int tickXCount); | |
61 | virtual void rangeYChanged(qreal min, qreal max, int tickYCount); |
|
61 | virtual void rangeYChanged(qreal min, qreal max, int tickYCount); | |
62 |
|
62 | |||
63 | void updateLayout(); |
|
63 | void updateLayout(); | |
64 | void handleSlicesAdded(QList<QPieSlice*> slices); |
|
64 | void handleSlicesAdded(QList<QPieSlice*> slices); | |
65 | void handleSlicesRemoved(QList<QPieSlice*> slices); |
|
65 | void handleSlicesRemoved(QList<QPieSlice*> slices); | |
66 | void handleSliceChanged(); |
|
66 | void handleSliceChanged(); | |
67 | void handleSeriesVisibleChanged(); |
|
67 | void handleSeriesVisibleChanged(); | |
|
68 | void handleOpacityChanged(); | |||
68 |
|
69 | |||
69 | void setAnimation(PieAnimation* animation); |
|
70 | void setAnimation(PieAnimation* animation); | |
70 | ChartAnimation* animation() const; |
|
71 | ChartAnimation* animation() const; | |
71 |
|
72 | |||
72 | private: |
|
73 | private: | |
73 | PieSliceData updateSliceGeometry(QPieSlice *slice); |
|
74 | PieSliceData updateSliceGeometry(QPieSlice *slice); | |
74 |
|
75 | |||
75 | private: |
|
76 | private: | |
76 | QHash<QPieSlice*, PieSliceItem*> m_sliceItems; |
|
77 | QHash<QPieSlice*, PieSliceItem*> m_sliceItems; | |
77 | QPieSeries *m_series; |
|
78 | QPieSeries *m_series; | |
78 | QRectF m_rect; |
|
79 | QRectF m_rect; | |
79 | QPointF m_pieCenter; |
|
80 | QPointF m_pieCenter; | |
80 | qreal m_pieRadius; |
|
81 | qreal m_pieRadius; | |
81 | qreal m_holeSize; |
|
82 | qreal m_holeSize; | |
82 | PieAnimation* m_animation; |
|
83 | PieAnimation* m_animation; | |
83 |
|
84 | |||
84 | }; |
|
85 | }; | |
85 |
|
86 | |||
86 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
87 |
|
88 | |||
88 | #endif // PIECHARTITEM_H |
|
89 | #endif // PIECHARTITEM_H |
@@ -1,209 +1,223 | |||||
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 "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QAbstractSeries |
|
28 | \class QAbstractSeries | |
29 | \brief Base class for all QtCommercial Chart series. |
|
29 | \brief Base class for all QtCommercial Chart series. | |
30 | \mainclass |
|
30 | \mainclass | |
31 |
|
31 | |||
32 | Usually you use the series type specific inherited classes instead of the base class. |
|
32 | Usually you use the series type specific inherited classes instead of the base class. | |
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
33 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, | |
34 | QPercentBarSeries, QPieSeries |
|
34 | QPercentBarSeries, QPieSeries | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass AbstractSeries |
|
37 | \qmlclass AbstractSeries | |
38 | AbstractSeries is the base class for all series. |
|
38 | AbstractSeries is the base class for all series. | |
39 | The class cannot be instantiated by the user. |
|
39 | The class cannot be instantiated by the user. | |
40 | */ |
|
40 | */ | |
41 |
|
41 | |||
42 | /*! |
|
42 | /*! | |
43 | \enum QAbstractSeries::SeriesType |
|
43 | \enum QAbstractSeries::SeriesType | |
44 |
|
44 | |||
45 | The type of the series object. |
|
45 | The type of the series object. | |
46 |
|
46 | |||
47 | \value SeriesTypeLine |
|
47 | \value SeriesTypeLine | |
48 | \value SeriesTypeArea |
|
48 | \value SeriesTypeArea | |
49 | \value SeriesTypeBar |
|
49 | \value SeriesTypeBar | |
50 | \value SeriesTypeStackedBar |
|
50 | \value SeriesTypeStackedBar | |
51 | \value SeriesTypePercentBar |
|
51 | \value SeriesTypePercentBar | |
52 | \value SeriesTypePie |
|
52 | \value SeriesTypePie | |
53 | \value SeriesTypeScatter |
|
53 | \value SeriesTypeScatter | |
54 | \value SeriesTypeSpline |
|
54 | \value SeriesTypeSpline | |
55 | \value SeriesTypeHorizontalBar |
|
55 | \value SeriesTypeHorizontalBar | |
56 | \value SeriesTypeHorizontalStackedBar |
|
56 | \value SeriesTypeHorizontalStackedBar | |
57 | \value SeriesTypeHorizontalPercentBar |
|
57 | \value SeriesTypeHorizontalPercentBar | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QAbstractSeries::type |
|
61 | \property QAbstractSeries::type | |
62 | The type of the series. |
|
62 | The type of the series. | |
63 | */ |
|
63 | */ | |
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
65 | \qmlproperty ChartView.SeriesType AbstractSeries::type | |
66 | The type of the series. |
|
66 | The type of the series. | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QAbstractSeries::name |
|
70 | \property QAbstractSeries::name | |
71 | \brief name of the series property. The name is shown in legend for QXYSeries. |
|
71 | \brief name of the series property. The name is shown in legend for QXYSeries. | |
72 | */ |
|
72 | */ | |
73 | /*! |
|
73 | /*! | |
74 | \qmlproperty string AbstractSeries::name |
|
74 | \qmlproperty string AbstractSeries::name | |
75 | Name of the series. The name is shown in legend for QXYSeries. |
|
75 | Name of the series. The name is shown in legend for QXYSeries. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \fn void QAbstractSeries::nameChanged() |
|
79 | \fn void QAbstractSeries::nameChanged() | |
80 | This signal is emitted when the series name changes. |
|
80 | This signal is emitted when the series name changes. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlsignal AbstractSeries::onNameChanged() |
|
83 | \qmlsignal AbstractSeries::onNameChanged() | |
84 | This signal is emitted when the series name changes. |
|
84 | This signal is emitted when the series name changes. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QAbstractSeries::visible |
|
88 | \property QAbstractSeries::visible | |
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 void AbstractSeries::visible | |
93 | Visibility of the series. True by default. |
|
93 | Visibility of the series. True by default. | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \fn void QAbstractSeries::visibleChanged() |
|
97 | \fn void QAbstractSeries::visibleChanged() | |
98 | Emitted when the series visibility changes. |
|
98 | Emitted when the series visibility changes. | |
99 | */ |
|
99 | */ | |
100 | /*! |
|
100 | /*! | |
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 | /*! |
|
104 | /*! | |
105 | \internal |
|
105 | \internal | |
106 | \brief Constructs ChartSeries object with \a parent. |
|
106 | \brief Constructs ChartSeries object with \a parent. | |
107 | */ |
|
107 | */ | |
108 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
108 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
109 | QObject(parent), |
|
109 | QObject(parent), | |
110 | d_ptr(&d) |
|
110 | d_ptr(&d) | |
111 | { |
|
111 | { | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \brief Virtual destructor for the chart series. |
|
115 | \brief Virtual destructor for the chart series. | |
116 | */ |
|
116 | */ | |
117 | QAbstractSeries::~QAbstractSeries() |
|
117 | QAbstractSeries::~QAbstractSeries() | |
118 | { |
|
118 | { | |
119 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); |
|
119 | if(d_ptr->m_dataset) qFatal("Still binded series detected !"); | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | void QAbstractSeries::setName(const QString& name) |
|
122 | void QAbstractSeries::setName(const QString& name) | |
123 | { |
|
123 | { | |
124 | if (name != d_ptr->m_name) { |
|
124 | if (name != d_ptr->m_name) { | |
125 | d_ptr->m_name = name; |
|
125 | d_ptr->m_name = name; | |
126 | emit nameChanged(); |
|
126 | emit nameChanged(); | |
127 | } |
|
127 | } | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | QString QAbstractSeries::name() const |
|
130 | QString QAbstractSeries::name() const | |
131 | { |
|
131 | { | |
132 | return d_ptr->m_name; |
|
132 | return d_ptr->m_name; | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | Sets the visibility of series to \a visible |
|
136 | Sets the visibility of series to \a visible | |
137 | */ |
|
137 | */ | |
138 | void QAbstractSeries::setVisible(bool visible) |
|
138 | void QAbstractSeries::setVisible(bool visible) | |
139 | { |
|
139 | { | |
140 | if (visible != d_ptr->m_visible) { |
|
140 | if (visible != d_ptr->m_visible) { | |
141 | d_ptr->m_visible = visible; |
|
141 | d_ptr->m_visible = visible; | |
142 | emit visibleChanged(); |
|
142 | emit visibleChanged(); | |
143 | } |
|
143 | } | |
144 | } |
|
144 | } | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | Returns the visibility of series |
|
147 | Returns the visibility of series | |
148 | */ |
|
148 | */ | |
149 | bool QAbstractSeries::isVisible() const |
|
149 | bool QAbstractSeries::isVisible() const | |
150 | { |
|
150 | { | |
151 | return d_ptr->m_visible; |
|
151 | return d_ptr->m_visible; | |
152 | } |
|
152 | } | |
153 |
|
153 | |||
|
154 | qreal QAbstractSeries::opacity() const | |||
|
155 | { | |||
|
156 | return d_ptr->m_opacity; | |||
|
157 | } | |||
|
158 | ||||
|
159 | void QAbstractSeries::setOpacity(qreal opacity) | |||
|
160 | { | |||
|
161 | if (opacity != d_ptr->m_opacity) { | |||
|
162 | d_ptr->m_opacity = opacity; | |||
|
163 | emit opacityChanged(); | |||
|
164 | } | |||
|
165 | } | |||
|
166 | ||||
154 | /*! |
|
167 | /*! | |
155 | \brief Returns the chart where series belongs to. |
|
168 | \brief Returns the chart where series belongs to. | |
156 |
|
169 | |||
157 | Set automatically when the series is added to the chart |
|
170 | Set automatically when the series is added to the chart | |
158 | and unset when the series is removed from the chart. |
|
171 | and unset when the series is removed from the chart. | |
159 | */ |
|
172 | */ | |
160 | QChart* QAbstractSeries::chart() const |
|
173 | QChart* QAbstractSeries::chart() const | |
161 | { |
|
174 | { | |
162 | return d_ptr->m_chart; |
|
175 | return d_ptr->m_chart; | |
163 | } |
|
176 | } | |
164 |
|
177 | |||
165 | //void QAbstractSeries::adjustView() |
|
178 | //void QAbstractSeries::adjustView() | |
166 | //{ |
|
179 | //{ | |
167 | // //TODO: |
|
180 | // //TODO: | |
168 | //} |
|
181 | //} | |
169 |
|
182 | |||
170 | /*! |
|
183 | /*! | |
171 | \brief Sets the visibility of the series to true |
|
184 | \brief Sets the visibility of the series to true | |
172 |
|
185 | |||
173 | \sa setVisible(), isVisible() |
|
186 | \sa setVisible(), isVisible() | |
174 | */ |
|
187 | */ | |
175 | void QAbstractSeries::show() |
|
188 | void QAbstractSeries::show() | |
176 | { |
|
189 | { | |
177 | setVisible(true); |
|
190 | setVisible(true); | |
178 | } |
|
191 | } | |
179 |
|
192 | |||
180 | /*! |
|
193 | /*! | |
181 | \brief Sets the visibility of the series to false |
|
194 | \brief Sets the visibility of the series to false | |
182 |
|
195 | |||
183 | \sa setVisible(), isVisible() |
|
196 | \sa setVisible(), isVisible() | |
184 | */ |
|
197 | */ | |
185 | void QAbstractSeries::hide() |
|
198 | void QAbstractSeries::hide() | |
186 | { |
|
199 | { | |
187 | setVisible(false); |
|
200 | setVisible(false); | |
188 | } |
|
201 | } | |
189 |
|
202 | |||
190 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
203 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
191 |
|
204 | |||
192 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): |
|
205 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q): | |
193 | q_ptr(q), |
|
206 | q_ptr(q), | |
194 | m_chart(0), |
|
207 | m_chart(0), | |
195 | m_dataset(0), |
|
208 | m_dataset(0), | |
196 | m_visible(true) |
|
209 | m_visible(true), | |
|
210 | m_opacity(1.0) | |||
197 | { |
|
211 | { | |
198 | } |
|
212 | } | |
199 |
|
213 | |||
200 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
214 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
201 | { |
|
215 | { | |
202 | } |
|
216 | } | |
203 |
|
217 | |||
204 | #include "moc_qabstractseries.cpp" |
|
218 | #include "moc_qabstractseries.cpp" | |
205 | #include "moc_qabstractseries_p.cpp" |
|
219 | #include "moc_qabstractseries_p.cpp" | |
206 |
|
220 | |||
207 | QTCOMMERCIALCHART_END_NAMESPACE |
|
221 | QTCOMMERCIALCHART_END_NAMESPACE | |
208 |
|
222 | |||
209 |
|
223 |
@@ -1,87 +1,92 | |||||
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 QABSTRACTSERIES_H |
|
21 | #ifndef QABSTRACTSERIES_H | |
22 | #define QABSTRACTSERIES_H |
|
22 | #define QABSTRACTSERIES_H | |
23 |
|
23 | |||
24 | #include <qchartglobal.h> |
|
24 | #include <qchartglobal.h> | |
25 | #include <qabstractaxis.h> |
|
25 | #include <qabstractaxis.h> | |
26 | #include <QObject> |
|
26 | #include <QObject> | |
27 | #include <QPen> |
|
27 | #include <QPen> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | class QAbstractSeriesPrivate; |
|
31 | class QAbstractSeriesPrivate; | |
32 | class QChart; |
|
32 | class QChart; | |
33 |
|
33 | |||
34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject |
|
34 | class QTCOMMERCIALCHART_EXPORT QAbstractSeries : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
|
37 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) | |
38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) |
|
38 | Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) | |
|
39 | Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) | |||
39 | Q_PROPERTY(SeriesType type READ type) |
|
40 | Q_PROPERTY(SeriesType type READ type) | |
40 | Q_ENUMS(SeriesType) |
|
41 | Q_ENUMS(SeriesType) | |
41 |
|
42 | |||
42 | public: |
|
43 | public: | |
43 | enum SeriesType { |
|
44 | enum SeriesType { | |
44 | SeriesTypeLine, |
|
45 | SeriesTypeLine, | |
45 | SeriesTypeArea, |
|
46 | SeriesTypeArea, | |
46 | SeriesTypeBar, |
|
47 | SeriesTypeBar, | |
47 | SeriesTypeStackedBar, |
|
48 | SeriesTypeStackedBar, | |
48 | SeriesTypePercentBar, |
|
49 | SeriesTypePercentBar, | |
49 | SeriesTypePie, |
|
50 | SeriesTypePie, | |
50 | SeriesTypeScatter, |
|
51 | SeriesTypeScatter, | |
51 | SeriesTypeSpline, |
|
52 | SeriesTypeSpline, | |
52 | SeriesTypeHorizontalBar, |
|
53 | SeriesTypeHorizontalBar, | |
53 | SeriesTypeHorizontalStackedBar, |
|
54 | SeriesTypeHorizontalStackedBar, | |
54 | SeriesTypeHorizontalPercentBar |
|
55 | SeriesTypeHorizontalPercentBar | |
55 | }; |
|
56 | }; | |
56 |
|
57 | |||
57 | protected: |
|
58 | protected: | |
58 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); |
|
59 | QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent = 0); | |
59 |
|
60 | |||
60 | public: |
|
61 | public: | |
61 | ~QAbstractSeries(); |
|
62 | ~QAbstractSeries(); | |
62 | virtual SeriesType type() const = 0; |
|
63 | virtual SeriesType type() const = 0; | |
63 |
|
64 | |||
64 | void setName(const QString& name); |
|
65 | void setName(const QString& name); | |
65 | QString name() const; |
|
66 | QString name() const; | |
66 | void setVisible(bool visible = true); |
|
67 | void setVisible(bool visible = true); | |
67 | bool isVisible() const; |
|
68 | bool isVisible() const; | |
|
69 | qreal opacity() const; | |||
|
70 | void setOpacity(qreal opacity); | |||
|
71 | ||||
68 | QChart* chart() const; |
|
72 | QChart* chart() const; | |
69 |
|
73 | |||
70 | void show(); |
|
74 | void show(); | |
71 | void hide(); |
|
75 | void hide(); | |
72 |
|
76 | |||
73 | Q_SIGNALS: |
|
77 | Q_SIGNALS: | |
74 | void nameChanged(); |
|
78 | void nameChanged(); | |
75 | void visibleChanged(); |
|
79 | void visibleChanged(); | |
|
80 | void opacityChanged(); | |||
76 |
|
81 | |||
77 | protected: |
|
82 | protected: | |
78 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; |
|
83 | QScopedPointer<QAbstractSeriesPrivate> d_ptr; | |
79 | friend class ChartDataSet; |
|
84 | friend class ChartDataSet; | |
80 | friend class ChartPresenter; |
|
85 | friend class ChartPresenter; | |
81 | friend class QLegendPrivate; |
|
86 | friend class QLegendPrivate; | |
82 | friend class DeclarativeChart; |
|
87 | friend class DeclarativeChart; | |
83 | }; |
|
88 | }; | |
84 |
|
89 | |||
85 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | QTCOMMERCIALCHART_END_NAMESPACE | |
86 |
|
91 | |||
87 | #endif // QABSTRACTSERIES_H |
|
92 | #endif // QABSTRACTSERIES_H |
@@ -1,71 +1,72 | |||||
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 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef QABSTRACTSERIES_P_H |
|
30 | #ifndef QABSTRACTSERIES_P_H | |
31 | #define QABSTRACTSERIES_P_H |
|
31 | #define QABSTRACTSERIES_P_H | |
32 |
|
32 | |||
33 | #include "qabstractseries.h" |
|
33 | #include "qabstractseries.h" | |
34 |
|
34 | |||
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
36 |
|
36 | |||
37 | class Domain; |
|
37 | class Domain; | |
38 | class ChartPresenter; |
|
38 | class ChartPresenter; | |
39 | class ChartElement; |
|
39 | class ChartElement; | |
40 | class LegendMarker; |
|
40 | class LegendMarker; | |
41 | class QLegend; |
|
41 | class QLegend; | |
42 | class ChartDataSet; |
|
42 | class ChartDataSet; | |
43 | class QAbstractAxis; |
|
43 | class QAbstractAxis; | |
44 |
|
44 | |||
45 | class QAbstractSeriesPrivate : public QObject |
|
45 | class QAbstractSeriesPrivate : public QObject | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | QAbstractSeriesPrivate(QAbstractSeries *q); |
|
49 | QAbstractSeriesPrivate(QAbstractSeries *q); | |
50 | ~QAbstractSeriesPrivate(); |
|
50 | ~QAbstractSeriesPrivate(); | |
51 |
|
51 | |||
52 | virtual void scaleDomain(Domain& domain) = 0; |
|
52 | virtual void scaleDomain(Domain& domain) = 0; | |
53 | virtual ChartElement* createGraphics(ChartPresenter* presenter) = 0; |
|
53 | virtual ChartElement* createGraphics(ChartPresenter* presenter) = 0; | |
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; |
|
54 | virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0; | |
55 | virtual void initializeAxis(QAbstractAxis* axis) = 0; |
|
55 | virtual void initializeAxis(QAbstractAxis* axis) = 0; | |
56 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; |
|
56 | virtual QAbstractAxis::AxisType defaultAxisType(Qt::Orientation) const = 0; | |
57 |
|
57 | |||
58 | protected: |
|
58 | protected: | |
59 | QAbstractSeries *q_ptr; |
|
59 | QAbstractSeries *q_ptr; | |
60 | QChart *m_chart; |
|
60 | QChart *m_chart; | |
61 | ChartDataSet *m_dataset; |
|
61 | ChartDataSet *m_dataset; | |
62 | QString m_name; |
|
62 | QString m_name; | |
63 | bool m_visible; |
|
63 | bool m_visible; | |
|
64 | qreal m_opacity; | |||
64 |
|
65 | |||
65 | friend class QAbstractSeries; |
|
66 | friend class QAbstractSeries; | |
66 | friend class ChartDataSet; |
|
67 | friend class ChartDataSet; | |
67 | }; |
|
68 | }; | |
68 |
|
69 | |||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
70 | QTCOMMERCIALCHART_END_NAMESPACE | |
70 |
|
71 | |||
71 | #endif |
|
72 | #endif |
@@ -1,194 +1,196 | |||||
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 "scatterchartitem_p.h" |
|
21 | #include "scatterchartitem_p.h" | |
22 | #include "qscatterseries.h" |
|
22 | #include "qscatterseries.h" | |
23 | #include "qscatterseries_p.h" |
|
23 | #include "qscatterseries_p.h" | |
24 | #include "chartpresenter_p.h" |
|
24 | #include "chartpresenter_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsScene> |
|
26 | #include <QGraphicsScene> | |
27 | #include <QDebug> |
|
27 | #include <QDebug> | |
28 | #include <QGraphicsSceneMouseEvent> |
|
28 | #include <QGraphicsSceneMouseEvent> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : |
|
32 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, ChartPresenter *presenter) : | |
33 | XYChart(series,presenter), |
|
33 | XYChart(series,presenter), | |
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
34 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
35 | m_series(series), |
|
35 | m_series(series), | |
36 | m_items(this), |
|
36 | m_items(this), | |
37 | m_visible(true), |
|
37 | m_visible(true), | |
38 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
38 | m_shape(QScatterSeries::MarkerShapeRectangle), | |
39 | m_size(15) |
|
39 | m_size(15) | |
40 | { |
|
40 | { | |
41 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); |
|
41 | QObject::connect(m_series->d_func(),SIGNAL(updated()), this, SLOT(handleUpdated())); | |
42 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
42 | QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
|
43 | QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); | |||
43 |
|
44 | |||
44 | setZValue(ChartPresenter::ScatterSeriesZValue); |
|
45 | setZValue(ChartPresenter::ScatterSeriesZValue); | |
45 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
46 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
46 |
|
47 | |||
47 | handleUpdated(); |
|
48 | handleUpdated(); | |
48 |
|
49 | |||
49 | m_items.setHandlesChildEvents(false); |
|
50 | m_items.setHandlesChildEvents(false); | |
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | QRectF ScatterChartItem::boundingRect() const |
|
53 | QRectF ScatterChartItem::boundingRect() const | |
53 | { |
|
54 | { | |
54 | return m_rect; |
|
55 | return m_rect; | |
55 | } |
|
56 | } | |
56 |
|
57 | |||
57 | void ScatterChartItem::createPoints(int count) |
|
58 | void ScatterChartItem::createPoints(int count) | |
58 | { |
|
59 | { | |
59 | for (int i = 0; i < count; ++i) { |
|
60 | for (int i = 0; i < count; ++i) { | |
60 |
|
61 | |||
61 | QGraphicsItem *item = 0; |
|
62 | QGraphicsItem *item = 0; | |
62 |
|
63 | |||
63 | switch (m_shape) { |
|
64 | switch (m_shape) { | |
64 | case QScatterSeries::MarkerShapeCircle: { |
|
65 | case QScatterSeries::MarkerShapeCircle: { | |
65 | item = new CircleMarker(0,0,m_size,m_size,this); |
|
66 | item = new CircleMarker(0,0,m_size,m_size,this); | |
66 | const QRectF& rect = item->boundingRect(); |
|
67 | const QRectF& rect = item->boundingRect(); | |
67 | item->setPos(-rect.width()/2,-rect.height()/2); |
|
68 | item->setPos(-rect.width()/2,-rect.height()/2); | |
68 | break; |
|
69 | break; | |
69 | } |
|
70 | } | |
70 | case QScatterSeries::MarkerShapeRectangle: { |
|
71 | case QScatterSeries::MarkerShapeRectangle: { | |
71 | item = new RectangleMarker(0,0,m_size,m_size,this); |
|
72 | item = new RectangleMarker(0,0,m_size,m_size,this); | |
72 | item->setPos(-m_size/2,-m_size/2); |
|
73 | item->setPos(-m_size/2,-m_size/2); | |
73 | break; |
|
74 | break; | |
74 | } |
|
75 | } | |
75 | default: |
|
76 | default: | |
76 | qWarning()<<"Unsupported marker type"; |
|
77 | qWarning()<<"Unsupported marker type"; | |
77 | break; |
|
78 | break; | |
78 |
|
79 | |||
79 | } |
|
80 | } | |
80 | m_items.addToGroup(item); |
|
81 | m_items.addToGroup(item); | |
81 | } |
|
82 | } | |
82 | } |
|
83 | } | |
83 |
|
84 | |||
84 | void ScatterChartItem::deletePoints(int count) |
|
85 | void ScatterChartItem::deletePoints(int count) | |
85 | { |
|
86 | { | |
86 | QList<QGraphicsItem *> items = m_items.childItems(); |
|
87 | QList<QGraphicsItem *> items = m_items.childItems(); | |
87 |
|
88 | |||
88 | for (int i = 0; i < count; ++i) { |
|
89 | for (int i = 0; i < count; ++i) { | |
89 | QGraphicsItem * item = items.takeLast(); |
|
90 | QGraphicsItem * item = items.takeLast(); | |
90 | m_markerMap.remove(item); |
|
91 | m_markerMap.remove(item); | |
91 | delete(item); |
|
92 | delete(item); | |
92 | } |
|
93 | } | |
93 | } |
|
94 | } | |
94 |
|
95 | |||
95 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) |
|
96 | void ScatterChartItem::markerSelected(QGraphicsItem *marker) | |
96 | { |
|
97 | { | |
97 | emit XYChart::clicked(calculateDomainPoint(m_markerMap[marker])); |
|
98 | emit XYChart::clicked(calculateDomainPoint(m_markerMap[marker])); | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | void ScatterChartItem::updateGeometry() |
|
101 | void ScatterChartItem::updateGeometry() | |
101 | { |
|
102 | { | |
102 |
|
103 | |||
103 | const QVector<QPointF>& points = geometryPoints(); |
|
104 | const QVector<QPointF>& points = geometryPoints(); | |
104 |
|
105 | |||
105 | if(points.size()==0) |
|
106 | if(points.size()==0) | |
106 | { |
|
107 | { | |
107 | deletePoints(m_items.childItems().count()); |
|
108 | deletePoints(m_items.childItems().count()); | |
108 | return; |
|
109 | return; | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | int diff = m_items.childItems().size() - points.size(); |
|
112 | int diff = m_items.childItems().size() - points.size(); | |
112 |
|
113 | |||
113 | if(diff>0) { |
|
114 | if(diff>0) { | |
114 | deletePoints(diff); |
|
115 | deletePoints(diff); | |
115 | } |
|
116 | } | |
116 | else if(diff<0) { |
|
117 | else if(diff<0) { | |
117 | createPoints(-diff); |
|
118 | createPoints(-diff); | |
118 | } |
|
119 | } | |
119 |
|
120 | |||
120 | if(diff!=0) handleUpdated(); |
|
121 | if(diff!=0) handleUpdated(); | |
121 |
|
122 | |||
122 | QList<QGraphicsItem*> items = m_items.childItems(); |
|
123 | QList<QGraphicsItem*> items = m_items.childItems(); | |
123 |
|
124 | |||
124 | for (int i = 0; i < points.size(); i++) { |
|
125 | for (int i = 0; i < points.size(); i++) { | |
125 | QGraphicsItem* item = items.at(i); |
|
126 | QGraphicsItem* item = items.at(i); | |
126 | const QPointF& point = points.at(i); |
|
127 | const QPointF& point = points.at(i); | |
127 | const QRectF& rect = item->boundingRect(); |
|
128 | const QRectF& rect = item->boundingRect(); | |
128 | m_markerMap[item]=point; |
|
129 | m_markerMap[item]=point; | |
129 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); |
|
130 | item->setPos(point.x()-rect.width()/2,point.y()-rect.height()/2); | |
130 | if(!m_visible || !clipRect().contains(point)) { |
|
131 | if(!m_visible || !clipRect().contains(point)) { | |
131 | item->setVisible(false); |
|
132 | item->setVisible(false); | |
132 | } |
|
133 | } | |
133 | else { |
|
134 | else { | |
134 | item->setVisible(true); |
|
135 | item->setVisible(true); | |
135 | } |
|
136 | } | |
136 | } |
|
137 | } | |
137 |
|
138 | |||
138 | prepareGeometryChange(); |
|
139 | prepareGeometryChange(); | |
139 | m_rect = clipRect(); |
|
140 | m_rect = clipRect(); | |
140 | setPos(origin()); |
|
141 | setPos(origin()); | |
141 | } |
|
142 | } | |
142 |
|
143 | |||
143 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
144 | void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
144 | { |
|
145 | { | |
145 | Q_UNUSED(painter) |
|
146 | Q_UNUSED(painter) | |
146 | Q_UNUSED(option) |
|
147 | Q_UNUSED(option) | |
147 | Q_UNUSED(widget) |
|
148 | Q_UNUSED(widget) | |
148 | } |
|
149 | } | |
149 |
|
150 | |||
150 | void ScatterChartItem::setPen(const QPen& pen) |
|
151 | void ScatterChartItem::setPen(const QPen& pen) | |
151 | { |
|
152 | { | |
152 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
153 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
153 | static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen); |
|
154 | static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen); | |
154 | } |
|
155 | } | |
155 | } |
|
156 | } | |
156 |
|
157 | |||
157 | void ScatterChartItem::setBrush(const QBrush& brush) |
|
158 | void ScatterChartItem::setBrush(const QBrush& brush) | |
158 | { |
|
159 | { | |
159 | foreach(QGraphicsItem* item , m_items.childItems()) { |
|
160 | foreach(QGraphicsItem* item , m_items.childItems()) { | |
160 | static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush); |
|
161 | static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush); | |
161 | } |
|
162 | } | |
162 | } |
|
163 | } | |
163 |
|
164 | |||
164 | void ScatterChartItem::handleUpdated() |
|
165 | void ScatterChartItem::handleUpdated() | |
165 | { |
|
166 | { | |
166 | int count = m_items.childItems().count(); |
|
167 | int count = m_items.childItems().count(); | |
167 |
|
168 | |||
168 | if(count==0) return; |
|
169 | if(count==0) return; | |
169 |
|
170 | |||
170 | bool recreate = m_visible != m_series->isVisible() |
|
171 | bool recreate = m_visible != m_series->isVisible() | |
171 | || m_size != m_series->markerSize() |
|
172 | || m_size != m_series->markerSize() | |
172 | || m_shape != m_series->markerShape(); |
|
173 | || m_shape != m_series->markerShape(); | |
173 |
|
174 | |||
174 | m_visible = m_series->isVisible(); |
|
175 | m_visible = m_series->isVisible(); | |
175 | m_size = m_series->markerSize(); |
|
176 | m_size = m_series->markerSize(); | |
176 | m_shape = m_series->markerShape(); |
|
177 | m_shape = m_series->markerShape(); | |
|
178 | setOpacity(m_series->opacity()); | |||
177 |
|
179 | |||
178 | if(recreate) { |
|
180 | if(recreate) { | |
179 | // TODO: optimize handleUpdate to recreate points only in case shape changed |
|
181 | // TODO: optimize handleUpdate to recreate points only in case shape changed | |
180 | deletePoints(count); |
|
182 | deletePoints(count); | |
181 | createPoints(count); |
|
183 | createPoints(count); | |
182 |
|
184 | |||
183 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points |
|
185 | // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points | |
184 | updateGeometry(); |
|
186 | updateGeometry(); | |
185 | } |
|
187 | } | |
186 |
|
188 | |||
187 | setPen(m_series->pen()); |
|
189 | setPen(m_series->pen()); | |
188 | setBrush(m_series->brush()); |
|
190 | setBrush(m_series->brush()); | |
189 | update(); |
|
191 | update(); | |
190 | } |
|
192 | } | |
191 |
|
193 | |||
192 | #include "moc_scatterchartitem_p.cpp" |
|
194 | #include "moc_scatterchartitem_p.cpp" | |
193 |
|
195 | |||
194 | QTCOMMERCIALCHART_END_NAMESPACE |
|
196 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,171 +1,173 | |||||
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 "splinechartitem_p.h" |
|
21 | #include "splinechartitem_p.h" | |
22 | #include "qsplineseries_p.h" |
|
22 | #include "qsplineseries_p.h" | |
23 | #include "chartpresenter_p.h" |
|
23 | #include "chartpresenter_p.h" | |
24 | #include "splineanimation_p.h" |
|
24 | #include "splineanimation_p.h" | |
25 | #include <QPainter> |
|
25 | #include <QPainter> | |
26 | #include <QGraphicsSceneMouseEvent> |
|
26 | #include <QGraphicsSceneMouseEvent> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
29 | |||
30 | SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) : |
|
30 | SplineChartItem::SplineChartItem(QSplineSeries *series, ChartPresenter *presenter) : | |
31 | XYChart(series, presenter), |
|
31 | XYChart(series, presenter), | |
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), |
|
32 | QGraphicsItem(presenter ? presenter->rootItem() : 0), | |
33 | m_series(series), |
|
33 | m_series(series), | |
34 | m_pointsVisible(false), |
|
34 | m_pointsVisible(false), | |
35 | m_animation(0) |
|
35 | m_animation(0) | |
36 | { |
|
36 | { | |
37 | setZValue(ChartPresenter::SplineChartZValue); |
|
37 | setZValue(ChartPresenter::SplineChartZValue); | |
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
38 | QObject::connect(m_series->d_func(),SIGNAL(updated()),this,SLOT(handleUpdated())); | |
39 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); |
|
39 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated())); | |
|
40 | QObject::connect(series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated())); | |||
40 | handleUpdated(); |
|
41 | handleUpdated(); | |
41 | } |
|
42 | } | |
42 |
|
43 | |||
43 | QRectF SplineChartItem::boundingRect() const |
|
44 | QRectF SplineChartItem::boundingRect() const | |
44 | { |
|
45 | { | |
45 | return m_rect; |
|
46 | return m_rect; | |
46 | } |
|
47 | } | |
47 |
|
48 | |||
48 | QPainterPath SplineChartItem::shape() const |
|
49 | QPainterPath SplineChartItem::shape() const | |
49 | { |
|
50 | { | |
50 | return m_path; |
|
51 | return m_path; | |
51 | } |
|
52 | } | |
52 |
|
53 | |||
53 | void SplineChartItem::setAnimation(SplineAnimation* animation) |
|
54 | void SplineChartItem::setAnimation(SplineAnimation* animation) | |
54 | { |
|
55 | { | |
55 | m_animation=animation; |
|
56 | m_animation=animation; | |
56 | XYChart::setAnimation(animation); |
|
57 | XYChart::setAnimation(animation); | |
57 | } |
|
58 | } | |
58 |
|
59 | |||
59 | ChartAnimation* SplineChartItem::animation() const |
|
60 | ChartAnimation* SplineChartItem::animation() const | |
60 | { |
|
61 | { | |
61 | return m_animation; |
|
62 | return m_animation; | |
62 | } |
|
63 | } | |
63 |
|
64 | |||
64 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) |
|
65 | void SplineChartItem::setControlGeometryPoints(QVector<QPointF>& points) | |
65 | { |
|
66 | { | |
66 | m_controlPoints=points; |
|
67 | m_controlPoints=points; | |
67 | } |
|
68 | } | |
68 |
|
69 | |||
69 | QVector<QPointF> SplineChartItem::controlGeometryPoints() const |
|
70 | QVector<QPointF> SplineChartItem::controlGeometryPoints() const | |
70 | { |
|
71 | { | |
71 | return m_controlPoints; |
|
72 | return m_controlPoints; | |
72 | } |
|
73 | } | |
73 |
|
74 | |||
74 | void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) |
|
75 | void SplineChartItem::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints,int index) | |
75 | { |
|
76 | { | |
76 | QVector<QPointF> controlPoints; |
|
77 | QVector<QPointF> controlPoints; | |
77 |
|
78 | |||
78 | if(newPoints.count()>=2) { |
|
79 | if(newPoints.count()>=2) { | |
79 | controlPoints.resize(newPoints.count()*2-2); |
|
80 | controlPoints.resize(newPoints.count()*2-2); | |
80 | } |
|
81 | } | |
81 |
|
82 | |||
82 | for (int i = 0; i < newPoints.size() - 1; i++) { |
|
83 | for (int i = 0; i < newPoints.size() - 1; i++) { | |
83 | controlPoints[2*i] = calculateGeometryControlPoint(2 * i); |
|
84 | controlPoints[2*i] = calculateGeometryControlPoint(2 * i); | |
84 | controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1); |
|
85 | controlPoints[2 * i + 1] = calculateGeometryControlPoint(2 * i + 1); | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | if (m_animation) |
|
88 | if (m_animation) | |
88 | m_animation->setup(oldPoints, newPoints, m_controlPoints, controlPoints, index); |
|
89 | m_animation->setup(oldPoints, newPoints, m_controlPoints, controlPoints, index); | |
89 |
|
90 | |||
90 | m_points = newPoints; |
|
91 | m_points = newPoints; | |
91 | m_controlPoints = controlPoints; |
|
92 | m_controlPoints = controlPoints; | |
92 | setDirty(false); |
|
93 | setDirty(false); | |
93 |
|
94 | |||
94 | if (m_animation) { |
|
95 | if (m_animation) { | |
95 | presenter()->startAnimation(m_animation); |
|
96 | presenter()->startAnimation(m_animation); | |
96 | } else { |
|
97 | } else { | |
97 | updateGeometry(); |
|
98 | updateGeometry(); | |
98 | } |
|
99 | } | |
99 | } |
|
100 | } | |
100 |
|
101 | |||
101 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const |
|
102 | QPointF SplineChartItem::calculateGeometryControlPoint(int index) const | |
102 | { |
|
103 | { | |
103 | return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index)); |
|
104 | return XYChart::calculateGeometryPoint(m_series->d_func()->controlPoint(index)); | |
104 | } |
|
105 | } | |
105 |
|
106 | |||
106 | void SplineChartItem::updateGeometry() |
|
107 | void SplineChartItem::updateGeometry() | |
107 | { |
|
108 | { | |
108 | const QVector<QPointF> &points = m_points; |
|
109 | const QVector<QPointF> &points = m_points; | |
109 | const QVector<QPointF> &controlPoints = m_controlPoints; |
|
110 | const QVector<QPointF> &controlPoints = m_controlPoints; | |
110 |
|
111 | |||
111 | if ((points.size()<2) || (controlPoints.size()<2)) { |
|
112 | if ((points.size()<2) || (controlPoints.size()<2)) { | |
112 | prepareGeometryChange(); |
|
113 | prepareGeometryChange(); | |
113 | m_path = QPainterPath(); |
|
114 | m_path = QPainterPath(); | |
114 | m_rect = QRect(); |
|
115 | m_rect = QRect(); | |
115 | return; |
|
116 | return; | |
116 | } |
|
117 | } | |
117 |
|
118 | |||
118 | Q_ASSERT(points.count()*2-2 == controlPoints.count()); |
|
119 | Q_ASSERT(points.count()*2-2 == controlPoints.count()); | |
119 |
|
120 | |||
120 | QPainterPath splinePath(points.at(0)); |
|
121 | QPainterPath splinePath(points.at(0)); | |
121 |
|
122 | |||
122 | for (int i = 0; i < points.size() - 1; i++) { |
|
123 | for (int i = 0; i < points.size() - 1; i++) { | |
123 | const QPointF& point = points.at(i + 1); |
|
124 | const QPointF& point = points.at(i + 1); | |
124 | splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point); |
|
125 | splinePath.cubicTo(controlPoints[2*i],controlPoints[2 * i + 1],point); | |
125 | } |
|
126 | } | |
126 |
|
127 | |||
127 | prepareGeometryChange(); |
|
128 | prepareGeometryChange(); | |
128 | m_path = splinePath; |
|
129 | m_path = splinePath; | |
129 | m_rect = splinePath.boundingRect(); |
|
130 | m_rect = splinePath.boundingRect(); | |
130 | setPos(origin()); |
|
131 | setPos(origin()); | |
131 | } |
|
132 | } | |
132 |
|
133 | |||
133 | //handlers |
|
134 | //handlers | |
134 |
|
135 | |||
135 | void SplineChartItem::handleUpdated() |
|
136 | void SplineChartItem::handleUpdated() | |
136 | { |
|
137 | { | |
137 | setVisible(m_series->isVisible()); |
|
138 | setVisible(m_series->isVisible()); | |
|
139 | setOpacity(m_series->opacity()); | |||
138 | m_pointsVisible = m_series->pointsVisible(); |
|
140 | m_pointsVisible = m_series->pointsVisible(); | |
139 | m_linePen = m_series->pen(); |
|
141 | m_linePen = m_series->pen(); | |
140 | m_pointPen = m_series->pen(); |
|
142 | m_pointPen = m_series->pen(); | |
141 | m_pointPen.setWidthF(2*m_pointPen.width()); |
|
143 | m_pointPen.setWidthF(2*m_pointPen.width()); | |
142 | update(); |
|
144 | update(); | |
143 | } |
|
145 | } | |
144 |
|
146 | |||
145 | //painter |
|
147 | //painter | |
146 |
|
148 | |||
147 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
149 | void SplineChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
148 | { |
|
150 | { | |
149 | Q_UNUSED(widget) |
|
151 | Q_UNUSED(widget) | |
150 | Q_UNUSED(option) |
|
152 | Q_UNUSED(option) | |
151 |
|
153 | |||
152 | painter->save(); |
|
154 | painter->save(); | |
153 | painter->setClipRect(clipRect()); |
|
155 | painter->setClipRect(clipRect()); | |
154 | painter->setPen(m_linePen); |
|
156 | painter->setPen(m_linePen); | |
155 | painter->drawPath(m_path); |
|
157 | painter->drawPath(m_path); | |
156 | if (m_pointsVisible) { |
|
158 | if (m_pointsVisible) { | |
157 | painter->setPen(m_pointPen); |
|
159 | painter->setPen(m_pointPen); | |
158 | painter->drawPoints(geometryPoints()); |
|
160 | painter->drawPoints(geometryPoints()); | |
159 | } |
|
161 | } | |
160 | painter->restore(); |
|
162 | painter->restore(); | |
161 | } |
|
163 | } | |
162 |
|
164 | |||
163 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
165 | void SplineChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event) | |
164 | { |
|
166 | { | |
165 | emit XYChart::clicked(calculateDomainPoint(event->pos())); |
|
167 | emit XYChart::clicked(calculateDomainPoint(event->pos())); | |
166 | QGraphicsItem::mousePressEvent(event); |
|
168 | QGraphicsItem::mousePressEvent(event); | |
167 | } |
|
169 | } | |
168 |
|
170 | |||
169 | #include "moc_splinechartitem_p.cpp" |
|
171 | #include "moc_splinechartitem_p.cpp" | |
170 |
|
172 | |||
171 | QTCOMMERCIALCHART_END_NAMESPACE |
|
173 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,623 +1,643 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qbarseries.h> |
|
22 | #include <qbarseries.h> | |
23 | #include <qbarset.h> |
|
23 | #include <qbarset.h> | |
24 | #include <qchartview.h> |
|
24 | #include <qchartview.h> | |
25 | #include <qchart.h> |
|
25 | #include <qchart.h> | |
26 | #include "tst_definitions.h" |
|
26 | #include "tst_definitions.h" | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QBarSet*) |
|
30 | Q_DECLARE_METATYPE(QBarSet*) | |
31 | Q_DECLARE_METATYPE(QList<QBarSet*>) |
|
31 | Q_DECLARE_METATYPE(QList<QBarSet*>) | |
32 |
|
32 | |||
33 | class tst_QBarSeries : public QObject |
|
33 | class tst_QBarSeries : public QObject | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 |
|
36 | |||
37 | public slots: |
|
37 | public slots: | |
38 | void initTestCase(); |
|
38 | void initTestCase(); | |
39 | void cleanupTestCase(); |
|
39 | void cleanupTestCase(); | |
40 | void init(); |
|
40 | void init(); | |
41 | void cleanup(); |
|
41 | void cleanup(); | |
42 |
|
42 | |||
43 | private slots: |
|
43 | private slots: | |
44 | void qbarseries_data(); |
|
44 | void qbarseries_data(); | |
45 | void qbarseries(); |
|
45 | void qbarseries(); | |
46 | void type_data(); |
|
46 | void type_data(); | |
47 | void type(); |
|
47 | void type(); | |
48 | void append_data(); |
|
48 | void append_data(); | |
49 | void append(); |
|
49 | void append(); | |
50 | void remove_data(); |
|
50 | void remove_data(); | |
51 | void remove(); |
|
51 | void remove(); | |
52 | void take_data(); |
|
52 | void take_data(); | |
53 | void take(); |
|
53 | void take(); | |
54 | void appendList_data(); |
|
54 | void appendList_data(); | |
55 | void appendList(); |
|
55 | void appendList(); | |
56 | void count_data(); |
|
56 | void count_data(); | |
57 | void count(); |
|
57 | void count(); | |
58 | void barSets_data(); |
|
58 | void barSets_data(); | |
59 | void barSets(); |
|
59 | void barSets(); | |
60 | void setLabelsVisible_data(); |
|
60 | void setLabelsVisible_data(); | |
61 | void setLabelsVisible(); |
|
61 | void setLabelsVisible(); | |
|
62 | void opacity(); | |||
62 | void mouseclicked_data(); |
|
63 | void mouseclicked_data(); | |
63 | void mouseclicked(); |
|
64 | void mouseclicked(); | |
64 | void mousehovered_data(); |
|
65 | void mousehovered_data(); | |
65 | void mousehovered(); |
|
66 | void mousehovered(); | |
66 | void clearWithAnimations(); |
|
67 | void clearWithAnimations(); | |
67 | void destruction(); |
|
68 | void destruction(); | |
68 |
|
69 | |||
69 | private: |
|
70 | private: | |
70 | QBarSeries* m_barseries; |
|
71 | QBarSeries* m_barseries; | |
71 | QBarSeries* m_barseries_with_sets; |
|
72 | QBarSeries* m_barseries_with_sets; | |
72 |
|
73 | |||
73 | QList<QBarSet*> m_testSets; |
|
74 | QList<QBarSet*> m_testSets; | |
74 |
|
75 | |||
75 | }; |
|
76 | }; | |
76 |
|
77 | |||
77 | void tst_QBarSeries::initTestCase() |
|
78 | void tst_QBarSeries::initTestCase() | |
78 | { |
|
79 | { | |
79 | qRegisterMetaType<QBarSet*>("QBarSet*"); |
|
80 | qRegisterMetaType<QBarSet*>("QBarSet*"); | |
80 | qRegisterMetaType<QList<QBarSet*> >("QList<QBarSet*>"); |
|
81 | qRegisterMetaType<QList<QBarSet*> >("QList<QBarSet*>"); | |
81 | } |
|
82 | } | |
82 |
|
83 | |||
83 | void tst_QBarSeries::cleanupTestCase() |
|
84 | void tst_QBarSeries::cleanupTestCase() | |
84 | { |
|
85 | { | |
85 | } |
|
86 | } | |
86 |
|
87 | |||
87 | void tst_QBarSeries::init() |
|
88 | void tst_QBarSeries::init() | |
88 | { |
|
89 | { | |
89 | m_barseries = new QBarSeries(); |
|
90 | m_barseries = new QBarSeries(); | |
90 | m_barseries_with_sets = new QBarSeries(); |
|
91 | m_barseries_with_sets = new QBarSeries(); | |
91 |
|
92 | |||
92 | for (int i=0; i<5; i++) { |
|
93 | for (int i=0; i<5; i++) { | |
93 | m_testSets.append(new QBarSet("testset")); |
|
94 | m_testSets.append(new QBarSet("testset")); | |
94 | m_barseries_with_sets->append(m_testSets.at(i)); |
|
95 | m_barseries_with_sets->append(m_testSets.at(i)); | |
95 | } |
|
96 | } | |
96 | } |
|
97 | } | |
97 |
|
98 | |||
98 | void tst_QBarSeries::cleanup() |
|
99 | void tst_QBarSeries::cleanup() | |
99 | { |
|
100 | { | |
100 | foreach(QBarSet* s, m_testSets) { |
|
101 | foreach(QBarSet* s, m_testSets) { | |
101 | m_barseries_with_sets->remove(s); |
|
102 | m_barseries_with_sets->remove(s); | |
102 | } |
|
103 | } | |
103 | m_testSets.clear(); |
|
104 | m_testSets.clear(); | |
104 |
|
105 | |||
105 | delete m_barseries; |
|
106 | delete m_barseries; | |
106 | m_barseries = 0; |
|
107 | m_barseries = 0; | |
107 | delete m_barseries_with_sets; |
|
108 | delete m_barseries_with_sets; | |
108 | m_barseries_with_sets = 0; |
|
109 | m_barseries_with_sets = 0; | |
109 | } |
|
110 | } | |
110 |
|
111 | |||
111 | void tst_QBarSeries::qbarseries_data() |
|
112 | void tst_QBarSeries::qbarseries_data() | |
112 | { |
|
113 | { | |
113 | } |
|
114 | } | |
114 |
|
115 | |||
115 | void tst_QBarSeries::qbarseries() |
|
116 | void tst_QBarSeries::qbarseries() | |
116 | { |
|
117 | { | |
117 | QBarSeries *barseries = new QBarSeries(); |
|
118 | QBarSeries *barseries = new QBarSeries(); | |
118 | QVERIFY(barseries != 0); |
|
119 | QVERIFY(barseries != 0); | |
119 | } |
|
120 | } | |
120 |
|
121 | |||
121 | void tst_QBarSeries::type_data() |
|
122 | void tst_QBarSeries::type_data() | |
122 | { |
|
123 | { | |
123 |
|
124 | |||
124 | } |
|
125 | } | |
125 |
|
126 | |||
126 | void tst_QBarSeries::type() |
|
127 | void tst_QBarSeries::type() | |
127 | { |
|
128 | { | |
128 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); |
|
129 | QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar); | |
129 | } |
|
130 | } | |
130 |
|
131 | |||
131 | void tst_QBarSeries::append_data() |
|
132 | void tst_QBarSeries::append_data() | |
132 | { |
|
133 | { | |
133 | } |
|
134 | } | |
134 |
|
135 | |||
135 | void tst_QBarSeries::append() |
|
136 | void tst_QBarSeries::append() | |
136 | { |
|
137 | { | |
137 | QVERIFY(m_barseries->count() == 0); |
|
138 | QVERIFY(m_barseries->count() == 0); | |
138 |
|
139 | |||
139 | bool ret = false; |
|
140 | bool ret = false; | |
140 |
|
141 | |||
141 | // Try adding barset |
|
142 | // Try adding barset | |
142 | QBarSet *barset = new QBarSet("testset"); |
|
143 | QBarSet *barset = new QBarSet("testset"); | |
143 | ret = m_barseries->append(barset); |
|
144 | ret = m_barseries->append(barset); | |
144 |
|
145 | |||
145 | QVERIFY(ret == true); |
|
146 | QVERIFY(ret == true); | |
146 | QVERIFY(m_barseries->count() == 1); |
|
147 | QVERIFY(m_barseries->count() == 1); | |
147 |
|
148 | |||
148 | // Try adding another set |
|
149 | // Try adding another set | |
149 | QBarSet *barset2 = new QBarSet("testset2"); |
|
150 | QBarSet *barset2 = new QBarSet("testset2"); | |
150 | ret = m_barseries->append(barset2); |
|
151 | ret = m_barseries->append(barset2); | |
151 |
|
152 | |||
152 | QVERIFY(ret == true); |
|
153 | QVERIFY(ret == true); | |
153 | QVERIFY(m_barseries->count() == 2); |
|
154 | QVERIFY(m_barseries->count() == 2); | |
154 |
|
155 | |||
155 | // Try adding same set again |
|
156 | // Try adding same set again | |
156 | ret = m_barseries->append(barset2); |
|
157 | ret = m_barseries->append(barset2); | |
157 | QVERIFY(ret == false); |
|
158 | QVERIFY(ret == false); | |
158 | QVERIFY(m_barseries->count() == 2); |
|
159 | QVERIFY(m_barseries->count() == 2); | |
159 |
|
160 | |||
160 | // Try adding null set |
|
161 | // Try adding null set | |
161 | ret = m_barseries->append(0); |
|
162 | ret = m_barseries->append(0); | |
162 | QVERIFY(ret == false); |
|
163 | QVERIFY(ret == false); | |
163 | QVERIFY(m_barseries->count() == 2); |
|
164 | QVERIFY(m_barseries->count() == 2); | |
164 |
|
165 | |||
165 | } |
|
166 | } | |
166 |
|
167 | |||
167 | void tst_QBarSeries::remove_data() |
|
168 | void tst_QBarSeries::remove_data() | |
168 | { |
|
169 | { | |
169 | } |
|
170 | } | |
170 |
|
171 | |||
171 | void tst_QBarSeries::remove() |
|
172 | void tst_QBarSeries::remove() | |
172 | { |
|
173 | { | |
173 | int count = m_testSets.count(); |
|
174 | int count = m_testSets.count(); | |
174 | QVERIFY(m_barseries_with_sets->count() == count); |
|
175 | QVERIFY(m_barseries_with_sets->count() == count); | |
175 |
|
176 | |||
176 | // Try to remove null pointer (should not remove, should not crash) |
|
177 | // Try to remove null pointer (should not remove, should not crash) | |
177 | bool ret = false; |
|
178 | bool ret = false; | |
178 | ret = m_barseries_with_sets->remove(0); |
|
179 | ret = m_barseries_with_sets->remove(0); | |
179 | QVERIFY(ret == false); |
|
180 | QVERIFY(ret == false); | |
180 | QVERIFY(m_barseries_with_sets->count() == count); |
|
181 | QVERIFY(m_barseries_with_sets->count() == count); | |
181 |
|
182 | |||
182 | // Try to remove invalid pointer (should not remove, should not crash) |
|
183 | // Try to remove invalid pointer (should not remove, should not crash) | |
183 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); |
|
184 | ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) ); | |
184 | QVERIFY(ret == false); |
|
185 | QVERIFY(ret == false); | |
185 | QVERIFY(m_barseries_with_sets->count() == count); |
|
186 | QVERIFY(m_barseries_with_sets->count() == count); | |
186 |
|
187 | |||
187 | // remove some sets |
|
188 | // remove some sets | |
188 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); |
|
189 | ret = m_barseries_with_sets->remove(m_testSets.at(2)); | |
189 | QVERIFY(ret == true); |
|
190 | QVERIFY(ret == true); | |
190 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); |
|
191 | ret = m_barseries_with_sets->remove(m_testSets.at(3)); | |
191 | QVERIFY(ret == true); |
|
192 | QVERIFY(ret == true); | |
192 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); |
|
193 | ret = m_barseries_with_sets->remove(m_testSets.at(4)); | |
193 | QVERIFY(ret == true); |
|
194 | QVERIFY(ret == true); | |
194 |
|
195 | |||
195 | QVERIFY(m_barseries_with_sets->count() == 2); |
|
196 | QVERIFY(m_barseries_with_sets->count() == 2); | |
196 |
|
197 | |||
197 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); |
|
198 | QList<QBarSet*> verifysets = m_barseries_with_sets->barSets(); | |
198 |
|
199 | |||
199 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); |
|
200 | QVERIFY(verifysets.at(0) == m_testSets.at(0)); | |
200 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); |
|
201 | QVERIFY(verifysets.at(1) == m_testSets.at(1)); | |
201 |
|
202 | |||
202 | // Try removing all sets again (should be ok, even if some sets have already been removed) |
|
203 | // Try removing all sets again (should be ok, even if some sets have already been removed) | |
203 | ret = false; |
|
204 | ret = false; | |
204 | for (int i=0; i<count; i++) { |
|
205 | for (int i=0; i<count; i++) { | |
205 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); |
|
206 | ret |= m_barseries_with_sets->remove(m_testSets.at(i)); | |
206 | } |
|
207 | } | |
207 |
|
208 | |||
208 | QVERIFY(ret == true); |
|
209 | QVERIFY(ret == true); | |
209 | QVERIFY(m_barseries_with_sets->count() == 0); |
|
210 | QVERIFY(m_barseries_with_sets->count() == 0); | |
210 | } |
|
211 | } | |
211 |
|
212 | |||
212 | void tst_QBarSeries::take_data() |
|
213 | void tst_QBarSeries::take_data() | |
213 | { |
|
214 | { | |
214 |
|
215 | |||
215 | } |
|
216 | } | |
216 |
|
217 | |||
217 | void tst_QBarSeries::take() |
|
218 | void tst_QBarSeries::take() | |
218 | { |
|
219 | { | |
219 | int count = m_testSets.count(); |
|
220 | int count = m_testSets.count(); | |
220 | QVERIFY(m_barseries_with_sets->count() == count); |
|
221 | QVERIFY(m_barseries_with_sets->count() == count); | |
221 |
|
222 | |||
222 | QSignalSpy countSpy(m_barseries_with_sets,SIGNAL(countChanged())); |
|
223 | QSignalSpy countSpy(m_barseries_with_sets,SIGNAL(countChanged())); | |
223 | QSignalSpy removedSpy(m_barseries_with_sets,SIGNAL(barsetsRemoved(QList<QBarSet *>))); |
|
224 | QSignalSpy removedSpy(m_barseries_with_sets,SIGNAL(barsetsRemoved(QList<QBarSet *>))); | |
224 |
|
225 | |||
225 | for (int i=0; i<m_testSets.count(); i++) { |
|
226 | for (int i=0; i<m_testSets.count(); i++) { | |
226 | QBarSet* set = m_testSets.at(i); |
|
227 | QBarSet* set = m_testSets.at(i); | |
227 | bool success = m_barseries_with_sets->take(set); |
|
228 | bool success = m_barseries_with_sets->take(set); | |
228 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
229 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
229 | QVERIFY(success); |
|
230 | QVERIFY(success); | |
230 | TRY_COMPARE(countSpy.count(),1); |
|
231 | TRY_COMPARE(countSpy.count(),1); | |
231 | TRY_COMPARE(removedSpy.count(),1); |
|
232 | TRY_COMPARE(removedSpy.count(),1); | |
232 |
|
233 | |||
233 | QList<QVariant> removedSpyArg = removedSpy.takeFirst(); |
|
234 | QList<QVariant> removedSpyArg = removedSpy.takeFirst(); | |
234 | QList<QBarSet*> removedSets = qvariant_cast<QList<QBarSet*> > (removedSpyArg.at(0)); |
|
235 | QList<QBarSet*> removedSets = qvariant_cast<QList<QBarSet*> > (removedSpyArg.at(0)); | |
235 | QCOMPARE(removedSets.at(0), m_testSets.at(i)); |
|
236 | QCOMPARE(removedSets.at(0), m_testSets.at(i)); | |
236 | countSpy.takeFirst(); |
|
237 | countSpy.takeFirst(); | |
237 | } |
|
238 | } | |
238 | } |
|
239 | } | |
239 |
|
240 | |||
240 |
|
241 | |||
241 | void tst_QBarSeries::appendList_data() |
|
242 | void tst_QBarSeries::appendList_data() | |
242 | { |
|
243 | { | |
243 |
|
244 | |||
244 | } |
|
245 | } | |
245 |
|
246 | |||
246 | void tst_QBarSeries::appendList() |
|
247 | void tst_QBarSeries::appendList() | |
247 | { |
|
248 | { | |
248 | int count = 5; |
|
249 | int count = 5; | |
249 | QVERIFY(m_barseries->count() == 0); |
|
250 | QVERIFY(m_barseries->count() == 0); | |
250 |
|
251 | |||
251 | QList<QBarSet*> sets; |
|
252 | QList<QBarSet*> sets; | |
252 | for (int i=0; i<count; i++) { |
|
253 | for (int i=0; i<count; i++) { | |
253 | sets.append(new QBarSet("testset")); |
|
254 | sets.append(new QBarSet("testset")); | |
254 | } |
|
255 | } | |
255 |
|
256 | |||
256 | // Append new sets (should succeed, count should match the count of sets) |
|
257 | // Append new sets (should succeed, count should match the count of sets) | |
257 | bool ret = false; |
|
258 | bool ret = false; | |
258 | ret = m_barseries->append(sets); |
|
259 | ret = m_barseries->append(sets); | |
259 | QVERIFY(ret == true); |
|
260 | QVERIFY(ret == true); | |
260 | QVERIFY(m_barseries->count() == count); |
|
261 | QVERIFY(m_barseries->count() == count); | |
261 |
|
262 | |||
262 | // Append same sets again (should fail, count should remain same) |
|
263 | // Append same sets again (should fail, count should remain same) | |
263 | ret = m_barseries->append(sets); |
|
264 | ret = m_barseries->append(sets); | |
264 | QVERIFY(ret == false); |
|
265 | QVERIFY(ret == false); | |
265 | QVERIFY(m_barseries->count() == count); |
|
266 | QVERIFY(m_barseries->count() == count); | |
266 |
|
267 | |||
267 | // Try append empty list (should succeed, but count should remain same) |
|
268 | // Try append empty list (should succeed, but count should remain same) | |
268 | QList<QBarSet*> invalidList; |
|
269 | QList<QBarSet*> invalidList; | |
269 | ret = m_barseries->append(invalidList); |
|
270 | ret = m_barseries->append(invalidList); | |
270 | QVERIFY(ret == true); |
|
271 | QVERIFY(ret == true); | |
271 | QVERIFY(m_barseries->count() == count); |
|
272 | QVERIFY(m_barseries->count() == count); | |
272 |
|
273 | |||
273 | // Try append list with one new and one existing set (should fail, count remains same) |
|
274 | // Try append list with one new and one existing set (should fail, count remains same) | |
274 | invalidList.append(new QBarSet("ok set")); |
|
275 | invalidList.append(new QBarSet("ok set")); | |
275 | invalidList.append(sets.at(0)); |
|
276 | invalidList.append(sets.at(0)); | |
276 | ret = m_barseries->append(invalidList); |
|
277 | ret = m_barseries->append(invalidList); | |
277 | QVERIFY(ret == false); |
|
278 | QVERIFY(ret == false); | |
278 | QVERIFY(m_barseries->count() == count); |
|
279 | QVERIFY(m_barseries->count() == count); | |
279 |
|
280 | |||
280 | // Try append list with null pointers (should fail, count remains same) |
|
281 | // Try append list with null pointers (should fail, count remains same) | |
281 | QList<QBarSet*> invalidList2; |
|
282 | QList<QBarSet*> invalidList2; | |
282 | invalidList2.append(0); |
|
283 | invalidList2.append(0); | |
283 | invalidList2.append(0); |
|
284 | invalidList2.append(0); | |
284 | invalidList2.append(0); |
|
285 | invalidList2.append(0); | |
285 | ret = m_barseries->append(invalidList2); |
|
286 | ret = m_barseries->append(invalidList2); | |
286 | QVERIFY(ret == false); |
|
287 | QVERIFY(ret == false); | |
287 | QVERIFY(m_barseries->count() == count); |
|
288 | QVERIFY(m_barseries->count() == count); | |
288 | } |
|
289 | } | |
289 |
|
290 | |||
290 | void tst_QBarSeries::count_data() |
|
291 | void tst_QBarSeries::count_data() | |
291 | { |
|
292 | { | |
292 |
|
293 | |||
293 | } |
|
294 | } | |
294 |
|
295 | |||
295 | void tst_QBarSeries::count() |
|
296 | void tst_QBarSeries::count() | |
296 | { |
|
297 | { | |
297 | QVERIFY(m_barseries->count() == 0); |
|
298 | QVERIFY(m_barseries->count() == 0); | |
298 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); |
|
299 | QVERIFY(m_barseries_with_sets->count() == m_testSets.count()); | |
299 | } |
|
300 | } | |
300 |
|
301 | |||
301 | void tst_QBarSeries::barSets_data() |
|
302 | void tst_QBarSeries::barSets_data() | |
302 | { |
|
303 | { | |
303 |
|
304 | |||
304 | } |
|
305 | } | |
305 |
|
306 | |||
306 | void tst_QBarSeries::barSets() |
|
307 | void tst_QBarSeries::barSets() | |
307 | { |
|
308 | { | |
308 | QVERIFY(m_barseries->barSets().count() == 0); |
|
309 | QVERIFY(m_barseries->barSets().count() == 0); | |
309 |
|
310 | |||
310 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); |
|
311 | QList<QBarSet*> sets = m_barseries_with_sets->barSets(); | |
311 | QVERIFY(sets.count() == m_testSets.count()); |
|
312 | QVERIFY(sets.count() == m_testSets.count()); | |
312 |
|
313 | |||
313 | for (int i=0; i<m_testSets.count(); i++) { |
|
314 | for (int i=0; i<m_testSets.count(); i++) { | |
314 | QVERIFY(sets.at(i) == m_testSets.at(i)); |
|
315 | QVERIFY(sets.at(i) == m_testSets.at(i)); | |
315 | } |
|
316 | } | |
316 | } |
|
317 | } | |
317 |
|
318 | |||
318 | void tst_QBarSeries::setLabelsVisible_data() |
|
319 | void tst_QBarSeries::setLabelsVisible_data() | |
319 | { |
|
320 | { | |
320 |
|
321 | |||
321 | } |
|
322 | } | |
322 |
|
323 | |||
323 | void tst_QBarSeries::setLabelsVisible() |
|
324 | void tst_QBarSeries::setLabelsVisible() | |
324 | { |
|
325 | { | |
325 | // labels should be invisible by default |
|
326 | // labels should be invisible by default | |
326 | QVERIFY(m_barseries->isLabelsVisible() == false); |
|
327 | QVERIFY(m_barseries->isLabelsVisible() == false); | |
327 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
328 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
328 |
|
329 | |||
329 | // turn labels to visible |
|
330 | // turn labels to visible | |
330 | m_barseries_with_sets->setLabelsVisible(true); |
|
331 | m_barseries_with_sets->setLabelsVisible(true); | |
331 | // TODO: test the signal |
|
332 | // TODO: test the signal | |
332 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
333 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
333 |
|
334 | |||
334 | // turn labels to invisible |
|
335 | // turn labels to invisible | |
335 | m_barseries_with_sets->setLabelsVisible(false); |
|
336 | m_barseries_with_sets->setLabelsVisible(false); | |
336 | // TODO: test the signal |
|
337 | // TODO: test the signal | |
337 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); |
|
338 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == false); | |
338 |
|
339 | |||
339 | // without parameter, should turn labels to visible |
|
340 | // without parameter, should turn labels to visible | |
340 | m_barseries_with_sets->setLabelsVisible(); |
|
341 | m_barseries_with_sets->setLabelsVisible(); | |
341 | // TODO: test the signal |
|
342 | // TODO: test the signal | |
342 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); |
|
343 | QVERIFY(m_barseries_with_sets->isLabelsVisible() == true); | |
343 | } |
|
344 | } | |
344 |
|
345 | |||
|
346 | void tst_QBarSeries::opacity() | |||
|
347 | { | |||
|
348 | QSignalSpy opacitySpy(m_barseries, SIGNAL(opacityChanged())); | |||
|
349 | ||||
|
350 | QCOMPARE(m_barseries->opacity(), 1.0); | |||
|
351 | ||||
|
352 | m_barseries->setOpacity(0.5); | |||
|
353 | QCOMPARE(m_barseries->opacity(), 0.5); | |||
|
354 | QCOMPARE(opacitySpy.count(), 1); | |||
|
355 | ||||
|
356 | m_barseries->setOpacity(0.0); | |||
|
357 | QCOMPARE(m_barseries->opacity(), 0.0); | |||
|
358 | QCOMPARE(opacitySpy.count(), 2); | |||
|
359 | ||||
|
360 | m_barseries->setOpacity(1.0); | |||
|
361 | QCOMPARE(m_barseries->opacity(), 1.0); | |||
|
362 | QCOMPARE(opacitySpy.count(), 3); | |||
|
363 | } | |||
|
364 | ||||
345 | void tst_QBarSeries::mouseclicked_data() |
|
365 | void tst_QBarSeries::mouseclicked_data() | |
346 | { |
|
366 | { | |
347 |
|
367 | |||
348 | } |
|
368 | } | |
349 |
|
369 | |||
350 | void tst_QBarSeries::mouseclicked() |
|
370 | void tst_QBarSeries::mouseclicked() | |
351 | { |
|
371 | { | |
352 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
372 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
353 |
|
373 | |||
354 | QBarSeries* series = new QBarSeries(); |
|
374 | QBarSeries* series = new QBarSeries(); | |
355 |
|
375 | |||
356 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
376 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
357 | *set1 << 10 << 10 << 10; |
|
377 | *set1 << 10 << 10 << 10; | |
358 | series->append(set1); |
|
378 | series->append(set1); | |
359 |
|
379 | |||
360 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
380 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
361 | *set2 << 10 << 10 << 10; |
|
381 | *set2 << 10 << 10 << 10; | |
362 | series->append(set2); |
|
382 | series->append(set2); | |
363 |
|
383 | |||
364 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); |
|
384 | QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*))); | |
365 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); |
|
385 | QSignalSpy setSpy1(set1, SIGNAL(clicked(int))); | |
366 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); |
|
386 | QSignalSpy setSpy2(set2, SIGNAL(clicked(int))); | |
367 |
|
387 | |||
368 | QChartView view(new QChart()); |
|
388 | QChartView view(new QChart()); | |
369 | view.resize(400,300); |
|
389 | view.resize(400,300); | |
370 | view.chart()->addSeries(series); |
|
390 | view.chart()->addSeries(series); | |
371 | view.show(); |
|
391 | view.show(); | |
372 | QTest::qWaitForWindowShown(&view); |
|
392 | QTest::qWaitForWindowShown(&view); | |
373 |
|
393 | |||
374 | //==================================================================================== |
|
394 | //==================================================================================== | |
375 | // barset 1, bar 0 |
|
395 | // barset 1, bar 0 | |
376 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(72,150)); |
|
396 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(72,150)); | |
377 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
397 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
378 |
|
398 | |||
379 | QCOMPARE(seriesSpy.count(), 1); |
|
399 | QCOMPARE(seriesSpy.count(), 1); | |
380 | QCOMPARE(setSpy1.count(), 1); |
|
400 | QCOMPARE(setSpy1.count(), 1); | |
381 | QCOMPARE(setSpy2.count(), 0); |
|
401 | QCOMPARE(setSpy2.count(), 0); | |
382 |
|
402 | |||
383 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
403 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
384 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
404 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
385 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
405 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
386 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
406 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
387 |
|
407 | |||
388 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
408 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
389 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
409 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
390 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
410 | QVERIFY(setSpyArg.at(0).toInt() == 0); | |
391 |
|
411 | |||
392 | //==================================================================================== |
|
412 | //==================================================================================== | |
393 | // barset 1, bar 1 |
|
413 | // barset 1, bar 1 | |
394 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,150)); |
|
414 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,150)); | |
395 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
415 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
396 |
|
416 | |||
397 | QCOMPARE(seriesSpy.count(), 1); |
|
417 | QCOMPARE(seriesSpy.count(), 1); | |
398 | QCOMPARE(setSpy1.count(), 1); |
|
418 | QCOMPARE(setSpy1.count(), 1); | |
399 | QCOMPARE(setSpy2.count(), 0); |
|
419 | QCOMPARE(setSpy2.count(), 0); | |
400 |
|
420 | |||
401 | seriesSpyArg = seriesSpy.takeFirst(); |
|
421 | seriesSpyArg = seriesSpy.takeFirst(); | |
402 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
422 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
403 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
423 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
404 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
424 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
405 |
|
425 | |||
406 | setSpyArg = setSpy1.takeFirst(); |
|
426 | setSpyArg = setSpy1.takeFirst(); | |
407 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
427 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
408 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
428 | QVERIFY(setSpyArg.at(0).toInt() == 1); | |
409 |
|
429 | |||
410 | //==================================================================================== |
|
430 | //==================================================================================== | |
411 | // barset 1, bar 2 |
|
431 | // barset 1, bar 2 | |
412 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(300,150)); |
|
432 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(300,150)); | |
413 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
433 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
414 |
|
434 | |||
415 | QCOMPARE(seriesSpy.count(), 1); |
|
435 | QCOMPARE(seriesSpy.count(), 1); | |
416 | QCOMPARE(setSpy1.count(), 1); |
|
436 | QCOMPARE(setSpy1.count(), 1); | |
417 | QCOMPARE(setSpy2.count(), 0); |
|
437 | QCOMPARE(setSpy2.count(), 0); | |
418 |
|
438 | |||
419 | seriesSpyArg = seriesSpy.takeFirst(); |
|
439 | seriesSpyArg = seriesSpy.takeFirst(); | |
420 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
440 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
421 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
441 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
422 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
442 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
423 |
|
443 | |||
424 | setSpyArg = setSpy1.takeFirst(); |
|
444 | setSpyArg = setSpy1.takeFirst(); | |
425 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
445 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
426 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
446 | QVERIFY(setSpyArg.at(0).toInt() == 2); | |
427 |
|
447 | |||
428 | //==================================================================================== |
|
448 | //==================================================================================== | |
429 | // barset 2, bar 0 |
|
449 | // barset 2, bar 0 | |
430 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(100,150)); |
|
450 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(100,150)); | |
431 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
451 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
432 |
|
452 | |||
433 | QCOMPARE(seriesSpy.count(), 1); |
|
453 | QCOMPARE(seriesSpy.count(), 1); | |
434 | QCOMPARE(setSpy1.count(), 0); |
|
454 | QCOMPARE(setSpy1.count(), 0); | |
435 | QCOMPARE(setSpy2.count(), 1); |
|
455 | QCOMPARE(setSpy2.count(), 1); | |
436 |
|
456 | |||
437 | seriesSpyArg = seriesSpy.takeFirst(); |
|
457 | seriesSpyArg = seriesSpy.takeFirst(); | |
438 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
458 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
439 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
459 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
440 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); |
|
460 | QVERIFY(seriesSpyArg.at(0).toInt() == 0); | |
441 |
|
461 | |||
442 | setSpyArg = setSpy2.takeFirst(); |
|
462 | setSpyArg = setSpy2.takeFirst(); | |
443 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
463 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
444 | QVERIFY(setSpyArg.at(0).toInt() == 0); |
|
464 | QVERIFY(setSpyArg.at(0).toInt() == 0); | |
445 |
|
465 | |||
446 | //==================================================================================== |
|
466 | //==================================================================================== | |
447 | // barset 2, bar 1 |
|
467 | // barset 2, bar 1 | |
448 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(214,150)); |
|
468 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(214,150)); | |
449 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
469 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
450 |
|
470 | |||
451 | QCOMPARE(seriesSpy.count(), 1); |
|
471 | QCOMPARE(seriesSpy.count(), 1); | |
452 | QCOMPARE(setSpy1.count(), 0); |
|
472 | QCOMPARE(setSpy1.count(), 0); | |
453 | QCOMPARE(setSpy2.count(), 1); |
|
473 | QCOMPARE(setSpy2.count(), 1); | |
454 |
|
474 | |||
455 | seriesSpyArg = seriesSpy.takeFirst(); |
|
475 | seriesSpyArg = seriesSpy.takeFirst(); | |
456 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
476 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
457 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
477 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
458 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); |
|
478 | QVERIFY(seriesSpyArg.at(0).toInt() == 1); | |
459 |
|
479 | |||
460 | setSpyArg = setSpy2.takeFirst(); |
|
480 | setSpyArg = setSpy2.takeFirst(); | |
461 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
481 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
462 | QVERIFY(setSpyArg.at(0).toInt() == 1); |
|
482 | QVERIFY(setSpyArg.at(0).toInt() == 1); | |
463 |
|
483 | |||
464 | //==================================================================================== |
|
484 | //==================================================================================== | |
465 | // barset 2, bar 2 |
|
485 | // barset 2, bar 2 | |
466 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(328,150)); |
|
486 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(328,150)); | |
467 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
487 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
468 |
|
488 | |||
469 | QCOMPARE(seriesSpy.count(), 1); |
|
489 | QCOMPARE(seriesSpy.count(), 1); | |
470 | QCOMPARE(setSpy1.count(), 0); |
|
490 | QCOMPARE(setSpy1.count(), 0); | |
471 | QCOMPARE(setSpy2.count(), 1); |
|
491 | QCOMPARE(setSpy2.count(), 1); | |
472 |
|
492 | |||
473 | seriesSpyArg = seriesSpy.takeFirst(); |
|
493 | seriesSpyArg = seriesSpy.takeFirst(); | |
474 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
494 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
475 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); |
|
495 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int); | |
476 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); |
|
496 | QVERIFY(seriesSpyArg.at(0).toInt() == 2); | |
477 |
|
497 | |||
478 | setSpyArg = setSpy2.takeFirst(); |
|
498 | setSpyArg = setSpy2.takeFirst(); | |
479 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); |
|
499 | QVERIFY(setSpyArg.at(0).type() == QVariant::Int); | |
480 | QVERIFY(setSpyArg.at(0).toInt() == 2); |
|
500 | QVERIFY(setSpyArg.at(0).toInt() == 2); | |
481 | } |
|
501 | } | |
482 |
|
502 | |||
483 | void tst_QBarSeries::mousehovered_data() |
|
503 | void tst_QBarSeries::mousehovered_data() | |
484 | { |
|
504 | { | |
485 |
|
505 | |||
486 | } |
|
506 | } | |
487 |
|
507 | |||
488 | void tst_QBarSeries::mousehovered() |
|
508 | void tst_QBarSeries::mousehovered() | |
489 | { |
|
509 | { | |
490 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
510 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
491 |
|
511 | |||
492 | QBarSeries* series = new QBarSeries(); |
|
512 | QBarSeries* series = new QBarSeries(); | |
493 |
|
513 | |||
494 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
514 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
495 | *set1 << 10 << 10 << 10; |
|
515 | *set1 << 10 << 10 << 10; | |
496 | series->append(set1); |
|
516 | series->append(set1); | |
497 |
|
517 | |||
498 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
518 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
499 | *set2 << 10 << 10 << 10; |
|
519 | *set2 << 10 << 10 << 10; | |
500 | series->append(set2); |
|
520 | series->append(set2); | |
501 |
|
521 | |||
502 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); |
|
522 | QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*))); | |
503 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); |
|
523 | QSignalSpy setSpy1(set1, SIGNAL(hovered(bool))); | |
504 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); |
|
524 | QSignalSpy setSpy2(set2, SIGNAL(hovered(bool))); | |
505 |
|
525 | |||
506 | QChartView view(new QChart()); |
|
526 | QChartView view(new QChart()); | |
507 | view.resize(400,300); |
|
527 | view.resize(400,300); | |
508 | view.chart()->addSeries(series); |
|
528 | view.chart()->addSeries(series); | |
509 | view.show(); |
|
529 | view.show(); | |
510 | QTest::qWaitForWindowShown(&view); |
|
530 | QTest::qWaitForWindowShown(&view); | |
511 |
|
531 | |||
512 | //this is hack since view does not get events otherwise |
|
532 | //this is hack since view does not get events otherwise | |
513 | view.setMouseTracking(true); |
|
533 | view.setMouseTracking(true); | |
514 |
|
534 | |||
515 | //======================================================================= |
|
535 | //======================================================================= | |
516 | // move mouse to left border |
|
536 | // move mouse to left border | |
517 | QTest::mouseMove(view.viewport(), QPoint(0, 150)); |
|
537 | QTest::mouseMove(view.viewport(), QPoint(0, 150)); | |
518 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); |
|
538 | QCoreApplication::processEvents(QEventLoop::AllEvents, 10000); | |
519 | TRY_COMPARE(seriesSpy.count(), 0); |
|
539 | TRY_COMPARE(seriesSpy.count(), 0); | |
520 | TRY_COMPARE(setSpy1.count(), 0); |
|
540 | TRY_COMPARE(setSpy1.count(), 0); | |
521 | TRY_COMPARE(setSpy2.count(), 0); |
|
541 | TRY_COMPARE(setSpy2.count(), 0); | |
522 |
|
542 | |||
523 | //======================================================================= |
|
543 | //======================================================================= | |
524 | // move mouse on top of set1 |
|
544 | // move mouse on top of set1 | |
525 | QTest::mouseMove(view.viewport(), QPoint(72,150)); |
|
545 | QTest::mouseMove(view.viewport(), QPoint(72,150)); | |
526 | TRY_COMPARE(seriesSpy.count(), 1); |
|
546 | TRY_COMPARE(seriesSpy.count(), 1); | |
527 | TRY_COMPARE(setSpy1.count(), 1); |
|
547 | TRY_COMPARE(setSpy1.count(), 1); | |
528 | TRY_COMPARE(setSpy2.count(), 0); |
|
548 | TRY_COMPARE(setSpy2.count(), 0); | |
529 |
|
549 | |||
530 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); |
|
550 | QList<QVariant> seriesSpyArg = seriesSpy.takeFirst(); | |
531 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
551 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
532 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
552 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
533 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
553 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
534 |
|
554 | |||
535 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); |
|
555 | QList<QVariant> setSpyArg = setSpy1.takeFirst(); | |
536 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
556 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
537 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
557 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
538 |
|
558 | |||
539 | //======================================================================= |
|
559 | //======================================================================= | |
540 | // move mouse from top of set1 to top of set2 |
|
560 | // move mouse from top of set1 to top of set2 | |
541 | QTest::mouseMove(view.viewport(), QPoint(100,150)); |
|
561 | QTest::mouseMove(view.viewport(), QPoint(100,150)); | |
542 | TRY_COMPARE(seriesSpy.count(), 2); |
|
562 | TRY_COMPARE(seriesSpy.count(), 2); | |
543 | TRY_COMPARE(setSpy1.count(), 1); |
|
563 | TRY_COMPARE(setSpy1.count(), 1); | |
544 | TRY_COMPARE(setSpy2.count(), 1); |
|
564 | TRY_COMPARE(setSpy2.count(), 1); | |
545 |
|
565 | |||
546 | // should leave set1 |
|
566 | // should leave set1 | |
547 | seriesSpyArg = seriesSpy.takeFirst(); |
|
567 | seriesSpyArg = seriesSpy.takeFirst(); | |
548 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); |
|
568 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1); | |
549 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
569 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
550 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
570 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
551 |
|
571 | |||
552 | setSpyArg = setSpy1.takeFirst(); |
|
572 | setSpyArg = setSpy1.takeFirst(); | |
553 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
573 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
554 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
574 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
555 |
|
575 | |||
556 | // should enter set2 |
|
576 | // should enter set2 | |
557 | seriesSpyArg = seriesSpy.takeFirst(); |
|
577 | seriesSpyArg = seriesSpy.takeFirst(); | |
558 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
578 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
559 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
579 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
560 | QVERIFY(seriesSpyArg.at(0).toBool() == true); |
|
580 | QVERIFY(seriesSpyArg.at(0).toBool() == true); | |
561 |
|
581 | |||
562 | setSpyArg = setSpy2.takeFirst(); |
|
582 | setSpyArg = setSpy2.takeFirst(); | |
563 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
583 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
564 | QVERIFY(setSpyArg.at(0).toBool() == true); |
|
584 | QVERIFY(setSpyArg.at(0).toBool() == true); | |
565 |
|
585 | |||
566 | //======================================================================= |
|
586 | //======================================================================= | |
567 | // move mouse from top of set2 to background |
|
587 | // move mouse from top of set2 to background | |
568 | QTest::mouseMove(view.viewport(), QPoint(100,0)); |
|
588 | QTest::mouseMove(view.viewport(), QPoint(100,0)); | |
569 | TRY_COMPARE(seriesSpy.count(), 1); |
|
589 | TRY_COMPARE(seriesSpy.count(), 1); | |
570 | TRY_COMPARE(setSpy1.count(), 0); |
|
590 | TRY_COMPARE(setSpy1.count(), 0); | |
571 | TRY_COMPARE(setSpy2.count(), 1); |
|
591 | TRY_COMPARE(setSpy2.count(), 1); | |
572 |
|
592 | |||
573 | // should leave set2 |
|
593 | // should leave set2 | |
574 | seriesSpyArg = seriesSpy.takeFirst(); |
|
594 | seriesSpyArg = seriesSpy.takeFirst(); | |
575 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); |
|
595 | QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2); | |
576 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); |
|
596 | QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool); | |
577 | QVERIFY(seriesSpyArg.at(0).toBool() == false); |
|
597 | QVERIFY(seriesSpyArg.at(0).toBool() == false); | |
578 |
|
598 | |||
579 | setSpyArg = setSpy2.takeFirst(); |
|
599 | setSpyArg = setSpy2.takeFirst(); | |
580 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); |
|
600 | QVERIFY(setSpyArg.at(0).type() == QVariant::Bool); | |
581 | QVERIFY(setSpyArg.at(0).toBool() == false); |
|
601 | QVERIFY(setSpyArg.at(0).toBool() == false); | |
582 | } |
|
602 | } | |
583 |
|
603 | |||
584 | void tst_QBarSeries::clearWithAnimations() |
|
604 | void tst_QBarSeries::clearWithAnimations() | |
585 | { |
|
605 | { | |
586 | QBarSeries* series = new QBarSeries(); |
|
606 | QBarSeries* series = new QBarSeries(); | |
587 |
|
607 | |||
588 | QBarSet* set1 = new QBarSet(QString("set 1")); |
|
608 | QBarSet* set1 = new QBarSet(QString("set 1")); | |
589 | *set1 << 10 << 10 << 10; |
|
609 | *set1 << 10 << 10 << 10; | |
590 | series->append(set1); |
|
610 | series->append(set1); | |
591 |
|
611 | |||
592 | QBarSet* set2 = new QBarSet(QString("set 2")); |
|
612 | QBarSet* set2 = new QBarSet(QString("set 2")); | |
593 | *set2 << 10 << 10 << 10; |
|
613 | *set2 << 10 << 10 << 10; | |
594 | series->append(set2); |
|
614 | series->append(set2); | |
595 |
|
615 | |||
596 | QChartView view(new QChart()); |
|
616 | QChartView view(new QChart()); | |
597 | view.resize(400,300); |
|
617 | view.resize(400,300); | |
598 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); |
|
618 | view.chart()->setAnimationOptions(QChart::SeriesAnimations); | |
599 | view.chart()->addSeries(series); |
|
619 | view.chart()->addSeries(series); | |
600 | view.show(); |
|
620 | view.show(); | |
601 |
|
621 | |||
602 | series->clear(); |
|
622 | series->clear(); | |
603 | } |
|
623 | } | |
604 |
|
624 | |||
605 | void tst_QBarSeries::destruction() |
|
625 | void tst_QBarSeries::destruction() | |
606 | { |
|
626 | { | |
607 | // add a barset |
|
627 | // add a barset | |
608 | QBarSeries *series = new QBarSeries(); |
|
628 | QBarSeries *series = new QBarSeries(); | |
609 | QBarSet *set = new QBarSet("testset"); |
|
629 | QBarSet *set = new QBarSet("testset"); | |
610 | QSignalSpy spy1(set, SIGNAL(destroyed())); |
|
630 | QSignalSpy spy1(set, SIGNAL(destroyed())); | |
611 | series->append(set); |
|
631 | series->append(set); | |
612 |
|
632 | |||
613 | // delete the series |
|
633 | // delete the series | |
614 | delete series; |
|
634 | delete series; | |
615 |
|
635 | |||
616 | // check that series deletes the set |
|
636 | // check that series deletes the set | |
617 | QCOMPARE(spy1.count(), 1); |
|
637 | QCOMPARE(spy1.count(), 1); | |
618 | } |
|
638 | } | |
619 |
|
639 | |||
620 | QTEST_MAIN(tst_QBarSeries) |
|
640 | QTEST_MAIN(tst_QBarSeries) | |
621 |
|
641 | |||
622 | #include "tst_qbarseries.moc" |
|
642 | #include "tst_qbarseries.moc" | |
623 |
|
643 |
@@ -1,636 +1,648 | |||||
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 <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qchart.h> |
|
23 | #include <qchart.h> | |
24 | #include <qpieseries.h> |
|
24 | #include <qpieseries.h> | |
25 | #include <qpieslice.h> |
|
25 | #include <qpieslice.h> | |
26 | #include <qpiemodelmapper.h> |
|
26 | #include <qpiemodelmapper.h> | |
27 | #include <QStandardItemModel> |
|
27 | #include <QStandardItemModel> | |
28 | #include <tst_definitions.h> |
|
28 | #include <tst_definitions.h> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | Q_DECLARE_METATYPE(QPieSlice*) |
|
32 | Q_DECLARE_METATYPE(QPieSlice*) | |
33 | Q_DECLARE_METATYPE(QList<QPieSlice*>) |
|
33 | Q_DECLARE_METATYPE(QList<QPieSlice*>) | |
34 |
|
34 | |||
35 | class tst_qpieseries : public QObject |
|
35 | class tst_qpieseries : public QObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 |
|
38 | |||
39 | public slots: |
|
39 | public slots: | |
40 | void initTestCase(); |
|
40 | void initTestCase(); | |
41 | void cleanupTestCase(); |
|
41 | void cleanupTestCase(); | |
42 | void init(); |
|
42 | void init(); | |
43 | void cleanup(); |
|
43 | void cleanup(); | |
44 |
|
44 | |||
45 | private slots: |
|
45 | private slots: | |
46 | void properties(); |
|
46 | void properties(); | |
47 | void append(); |
|
47 | void append(); | |
48 | void appendAnimated(); |
|
48 | void appendAnimated(); | |
49 | void insert(); |
|
49 | void insert(); | |
50 | void insertAnimated(); |
|
50 | void insertAnimated(); | |
51 | void remove(); |
|
51 | void remove(); | |
52 | void removeAnimated(); |
|
52 | void removeAnimated(); | |
53 | void take(); |
|
53 | void take(); | |
54 | void takeAnimated(); |
|
54 | void takeAnimated(); | |
55 | void calculatedValues(); |
|
55 | void calculatedValues(); | |
56 | void clickedSignal(); |
|
56 | void clickedSignal(); | |
57 | void hoverSignal(); |
|
57 | void hoverSignal(); | |
58 | void sliceSeries(); |
|
58 | void sliceSeries(); | |
59 | void destruction(); |
|
59 | void destruction(); | |
60 |
|
60 | |||
61 | private: |
|
61 | private: | |
62 | void verifyCalculatedData(const QPieSeries &series, bool *ok); |
|
62 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | |
63 | QList<QPoint> slicePoints(QRectF rect); |
|
63 | QList<QPoint> slicePoints(QRectF rect); | |
64 |
|
64 | |||
65 | private: |
|
65 | private: | |
66 | QChartView *m_view; |
|
66 | QChartView *m_view; | |
67 | QPieSeries *m_series; |
|
67 | QPieSeries *m_series; | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | void tst_qpieseries::initTestCase() |
|
70 | void tst_qpieseries::initTestCase() | |
71 | { |
|
71 | { | |
72 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); |
|
72 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | |
73 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); |
|
73 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void tst_qpieseries::cleanupTestCase() |
|
76 | void tst_qpieseries::cleanupTestCase() | |
77 | { |
|
77 | { | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_qpieseries::init() |
|
80 | void tst_qpieseries::init() | |
81 | { |
|
81 | { | |
82 | m_view = new QChartView(); |
|
82 | m_view = new QChartView(); | |
83 | m_series = new QPieSeries(m_view); |
|
83 | m_series = new QPieSeries(m_view); | |
84 | m_view->show(); |
|
84 | m_view->show(); | |
85 | QTest::qWaitForWindowShown(m_view); |
|
85 | QTest::qWaitForWindowShown(m_view); | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void tst_qpieseries::cleanup() |
|
89 | void tst_qpieseries::cleanup() | |
90 | { |
|
90 | { | |
91 | delete m_view; |
|
91 | delete m_view; | |
92 | m_view = 0; |
|
92 | m_view = 0; | |
93 | m_series = 0; |
|
93 | m_series = 0; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void tst_qpieseries::properties() |
|
96 | void tst_qpieseries::properties() | |
97 | { |
|
97 | { | |
98 | QSignalSpy countSpy(m_series, SIGNAL(countChanged())); |
|
98 | QSignalSpy countSpy(m_series, SIGNAL(countChanged())); | |
99 | QSignalSpy sumSpy(m_series, SIGNAL(sumChanged())); |
|
99 | QSignalSpy sumSpy(m_series, SIGNAL(sumChanged())); | |
|
100 | QSignalSpy opacitySpy(m_series, SIGNAL(opacityChanged())); | |||
100 |
|
101 | |||
101 | QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie); |
|
102 | QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie); | |
102 | QVERIFY(m_series->count() == 0); |
|
103 | QVERIFY(m_series->count() == 0); | |
103 | QVERIFY(m_series->isEmpty()); |
|
104 | QVERIFY(m_series->isEmpty()); | |
104 | QCOMPARE(m_series->sum(), 0.0); |
|
105 | QCOMPARE(m_series->sum(), 0.0); | |
105 | QCOMPARE(m_series->horizontalPosition(), 0.5); |
|
106 | QCOMPARE(m_series->horizontalPosition(), 0.5); | |
106 | QCOMPARE(m_series->verticalPosition(), 0.5); |
|
107 | QCOMPARE(m_series->verticalPosition(), 0.5); | |
107 | QCOMPARE(m_series->pieSize(), 0.7); |
|
108 | QCOMPARE(m_series->pieSize(), 0.7); | |
108 | QCOMPARE(m_series->pieStartAngle(), 0.0); |
|
109 | QCOMPARE(m_series->pieStartAngle(), 0.0); | |
109 | QCOMPARE(m_series->pieEndAngle(), 360.0); |
|
110 | QCOMPARE(m_series->pieEndAngle(), 360.0); | |
|
111 | QCOMPARE(m_series->opacity(), 1.0); | |||
110 |
|
112 | |||
111 | m_series->append("s1", 1); |
|
113 | m_series->append("s1", 1); | |
112 | m_series->append("s2", 1); |
|
114 | m_series->append("s2", 1); | |
113 | m_series->append("s3", 1); |
|
115 | m_series->append("s3", 1); | |
114 | m_series->insert(1, new QPieSlice("s4", 1)); |
|
116 | m_series->insert(1, new QPieSlice("s4", 1)); | |
115 | m_series->remove(m_series->slices().first()); |
|
117 | m_series->remove(m_series->slices().first()); | |
116 | QCOMPARE(m_series->count(), 3); |
|
118 | QCOMPARE(m_series->count(), 3); | |
117 | QCOMPARE(m_series->sum(), 3.0); |
|
119 | QCOMPARE(m_series->sum(), 3.0); | |
118 | m_series->clear(); |
|
120 | m_series->clear(); | |
119 | QCOMPARE(m_series->count(), 0); |
|
121 | QCOMPARE(m_series->count(), 0); | |
120 | QCOMPARE(m_series->sum(), 0.0); |
|
122 | QCOMPARE(m_series->sum(), 0.0); | |
121 | QCOMPARE(countSpy.count(), 6); |
|
123 | QCOMPARE(countSpy.count(), 6); | |
122 | QCOMPARE(sumSpy.count(), 6); |
|
124 | QCOMPARE(sumSpy.count(), 6); | |
123 |
|
125 | |||
124 | m_series->setPieSize(-1.0); |
|
126 | m_series->setPieSize(-1.0); | |
125 | QCOMPARE(m_series->pieSize(), 0.0); |
|
127 | QCOMPARE(m_series->pieSize(), 0.0); | |
126 | m_series->setPieSize(0.0); |
|
128 | m_series->setPieSize(0.0); | |
127 | m_series->setPieSize(0.9); |
|
129 | m_series->setPieSize(0.9); | |
128 | m_series->setPieSize(2.0); |
|
130 | m_series->setPieSize(2.0); | |
129 | QCOMPARE(m_series->pieSize(), 1.0); |
|
131 | QCOMPARE(m_series->pieSize(), 1.0); | |
130 |
|
132 | |||
131 | m_series->setPieSize(0.7); |
|
133 | m_series->setPieSize(0.7); | |
132 | QCOMPARE(m_series->pieSize(), 0.7); |
|
134 | QCOMPARE(m_series->pieSize(), 0.7); | |
133 |
|
135 | |||
134 | m_series->setHoleSize(-1.0); |
|
136 | m_series->setHoleSize(-1.0); | |
135 | QCOMPARE(m_series->holeSize(), 0.0); |
|
137 | QCOMPARE(m_series->holeSize(), 0.0); | |
136 | m_series->setHoleSize(0.5); |
|
138 | m_series->setHoleSize(0.5); | |
137 | QCOMPARE(m_series->holeSize(), 0.5); |
|
139 | QCOMPARE(m_series->holeSize(), 0.5); | |
138 |
|
140 | |||
139 | m_series->setHoleSize(0.8); |
|
141 | m_series->setHoleSize(0.8); | |
140 | QCOMPARE(m_series->holeSize(), 0.8); |
|
142 | QCOMPARE(m_series->holeSize(), 0.8); | |
141 | QCOMPARE(m_series->pieSize(), 0.8); |
|
143 | QCOMPARE(m_series->pieSize(), 0.8); | |
142 |
|
144 | |||
143 | m_series->setPieSize(0.4); |
|
145 | m_series->setPieSize(0.4); | |
144 | QCOMPARE(m_series->pieSize(), 0.4); |
|
146 | QCOMPARE(m_series->pieSize(), 0.4); | |
145 | QCOMPARE(m_series->holeSize(), 0.4); |
|
147 | QCOMPARE(m_series->holeSize(), 0.4); | |
146 |
|
148 | |||
147 | m_series->setPieStartAngle(0); |
|
149 | m_series->setPieStartAngle(0); | |
148 | m_series->setPieStartAngle(-180); |
|
150 | m_series->setPieStartAngle(-180); | |
149 | m_series->setPieStartAngle(180); |
|
151 | m_series->setPieStartAngle(180); | |
150 | QCOMPARE(m_series->pieStartAngle(), 180.0); |
|
152 | QCOMPARE(m_series->pieStartAngle(), 180.0); | |
151 |
|
153 | |||
152 | m_series->setPieEndAngle(360); |
|
154 | m_series->setPieEndAngle(360); | |
153 | m_series->setPieEndAngle(-180); |
|
155 | m_series->setPieEndAngle(-180); | |
154 | m_series->setPieEndAngle(180); |
|
156 | m_series->setPieEndAngle(180); | |
155 | QCOMPARE(m_series->pieEndAngle(), 180.0); |
|
157 | QCOMPARE(m_series->pieEndAngle(), 180.0); | |
156 |
|
158 | |||
157 | m_series->setHorizontalPosition(0.5); |
|
159 | m_series->setHorizontalPosition(0.5); | |
158 | m_series->setHorizontalPosition(-1.0); |
|
160 | m_series->setHorizontalPosition(-1.0); | |
159 | QCOMPARE(m_series->horizontalPosition(), 0.0); |
|
161 | QCOMPARE(m_series->horizontalPosition(), 0.0); | |
160 | m_series->setHorizontalPosition(1.0); |
|
162 | m_series->setHorizontalPosition(1.0); | |
161 | m_series->setHorizontalPosition(2.0); |
|
163 | m_series->setHorizontalPosition(2.0); | |
162 | QCOMPARE(m_series->horizontalPosition(), 1.0); |
|
164 | QCOMPARE(m_series->horizontalPosition(), 1.0); | |
163 |
|
165 | |||
164 | m_series->setVerticalPosition(0.5); |
|
166 | m_series->setVerticalPosition(0.5); | |
165 | m_series->setVerticalPosition(-1.0); |
|
167 | m_series->setVerticalPosition(-1.0); | |
166 | QCOMPARE(m_series->verticalPosition(), 0.0); |
|
168 | QCOMPARE(m_series->verticalPosition(), 0.0); | |
167 | m_series->setVerticalPosition(1.0); |
|
169 | m_series->setVerticalPosition(1.0); | |
168 | m_series->setVerticalPosition(2.0); |
|
170 | m_series->setVerticalPosition(2.0); | |
169 | QCOMPARE(m_series->verticalPosition(), 1.0); |
|
171 | QCOMPARE(m_series->verticalPosition(), 1.0); | |
|
172 | ||||
|
173 | m_series->setOpacity(0.5); | |||
|
174 | QCOMPARE(m_series->opacity(), 0.5); | |||
|
175 | QCOMPARE(opacitySpy.count(), 1); | |||
|
176 | m_series->setOpacity(0.0); | |||
|
177 | QCOMPARE(m_series->opacity(), 0.0); | |||
|
178 | QCOMPARE(opacitySpy.count(), 2); | |||
|
179 | m_series->setOpacity(1.0); | |||
|
180 | QCOMPARE(m_series->opacity(), 1.0); | |||
|
181 | QCOMPARE(opacitySpy.count(), 3); | |||
170 | } |
|
182 | } | |
171 |
|
183 | |||
172 | void tst_qpieseries::append() |
|
184 | void tst_qpieseries::append() | |
173 | { |
|
185 | { | |
174 | m_view->chart()->addSeries(m_series); |
|
186 | m_view->chart()->addSeries(m_series); | |
175 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); |
|
187 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | |
176 |
|
188 | |||
177 | // append pointer |
|
189 | // append pointer | |
178 | QPieSlice *slice1 = 0; |
|
190 | QPieSlice *slice1 = 0; | |
179 | QVERIFY(!m_series->append(slice1)); |
|
191 | QVERIFY(!m_series->append(slice1)); | |
180 | slice1 = new QPieSlice("slice 1", 1); |
|
192 | slice1 = new QPieSlice("slice 1", 1); | |
181 | QVERIFY(m_series->append(slice1)); |
|
193 | QVERIFY(m_series->append(slice1)); | |
182 | QVERIFY(!m_series->append(slice1)); |
|
194 | QVERIFY(!m_series->append(slice1)); | |
183 | QCOMPARE(m_series->count(), 1); |
|
195 | QCOMPARE(m_series->count(), 1); | |
184 | QCOMPARE(addedSpy.count(), 1); |
|
196 | QCOMPARE(addedSpy.count(), 1); | |
185 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); |
|
197 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
186 | QCOMPARE(added.count(), 1); |
|
198 | QCOMPARE(added.count(), 1); | |
187 | QCOMPARE(added.first(), slice1); |
|
199 | QCOMPARE(added.first(), slice1); | |
188 |
|
200 | |||
189 | // try to append same slice to another series |
|
201 | // try to append same slice to another series | |
190 | QPieSeries series2; |
|
202 | QPieSeries series2; | |
191 | QVERIFY(!series2.append(slice1)); |
|
203 | QVERIFY(!series2.append(slice1)); | |
192 |
|
204 | |||
193 | // append pointer list |
|
205 | // append pointer list | |
194 | QList<QPieSlice *> list; |
|
206 | QList<QPieSlice *> list; | |
195 | QVERIFY(!m_series->append(list)); |
|
207 | QVERIFY(!m_series->append(list)); | |
196 | list << (QPieSlice *) 0; |
|
208 | list << (QPieSlice *) 0; | |
197 | QVERIFY(!m_series->append(list)); |
|
209 | QVERIFY(!m_series->append(list)); | |
198 | list.clear(); |
|
210 | list.clear(); | |
199 | list << new QPieSlice("slice 2", 2); |
|
211 | list << new QPieSlice("slice 2", 2); | |
200 | list << new QPieSlice("slice 3", 3); |
|
212 | list << new QPieSlice("slice 3", 3); | |
201 | QVERIFY(m_series->append(list)); |
|
213 | QVERIFY(m_series->append(list)); | |
202 | QVERIFY(!m_series->append(list)); |
|
214 | QVERIFY(!m_series->append(list)); | |
203 | QCOMPARE(m_series->count(), 3); |
|
215 | QCOMPARE(m_series->count(), 3); | |
204 | QCOMPARE(addedSpy.count(), 2); |
|
216 | QCOMPARE(addedSpy.count(), 2); | |
205 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); |
|
217 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
206 | QCOMPARE(added.count(), 2); |
|
218 | QCOMPARE(added.count(), 2); | |
207 | QCOMPARE(added, list); |
|
219 | QCOMPARE(added, list); | |
208 |
|
220 | |||
209 | // append operator |
|
221 | // append operator | |
210 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); |
|
222 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); | |
211 | *m_series << slice4; |
|
223 | *m_series << slice4; | |
212 | *m_series << slice1; // fails because already added |
|
224 | *m_series << slice1; // fails because already added | |
213 | QCOMPARE(m_series->count(), 4); |
|
225 | QCOMPARE(m_series->count(), 4); | |
214 | QCOMPARE(addedSpy.count(), 3); |
|
226 | QCOMPARE(addedSpy.count(), 3); | |
215 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); |
|
227 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
216 | QCOMPARE(added.count(), 1); |
|
228 | QCOMPARE(added.count(), 1); | |
217 | QCOMPARE(added.first(), slice4); |
|
229 | QCOMPARE(added.first(), slice4); | |
218 |
|
230 | |||
219 | // append with params |
|
231 | // append with params | |
220 | QPieSlice *slice5 = m_series->append("slice 5", 5); |
|
232 | QPieSlice *slice5 = m_series->append("slice 5", 5); | |
221 | QVERIFY(slice5 != 0); |
|
233 | QVERIFY(slice5 != 0); | |
222 | QCOMPARE(slice5->value(), 5.0); |
|
234 | QCOMPARE(slice5->value(), 5.0); | |
223 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
235 | QCOMPARE(slice5->label(), QString("slice 5")); | |
224 | QCOMPARE(m_series->count(), 5); |
|
236 | QCOMPARE(m_series->count(), 5); | |
225 | QCOMPARE(addedSpy.count(), 4); |
|
237 | QCOMPARE(addedSpy.count(), 4); | |
226 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); |
|
238 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
227 | QCOMPARE(added.count(), 1); |
|
239 | QCOMPARE(added.count(), 1); | |
228 | QCOMPARE(added.first(), slice5); |
|
240 | QCOMPARE(added.first(), slice5); | |
229 |
|
241 | |||
230 | // check slices |
|
242 | // check slices | |
231 | QVERIFY(!m_series->isEmpty()); |
|
243 | QVERIFY(!m_series->isEmpty()); | |
232 | for (int i=0; i<m_series->count(); i++) { |
|
244 | for (int i=0; i<m_series->count(); i++) { | |
233 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); |
|
245 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | |
234 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
246 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
235 | } |
|
247 | } | |
236 | } |
|
248 | } | |
237 |
|
249 | |||
238 | void tst_qpieseries::appendAnimated() |
|
250 | void tst_qpieseries::appendAnimated() | |
239 | { |
|
251 | { | |
240 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
252 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
241 | append(); |
|
253 | append(); | |
242 | } |
|
254 | } | |
243 |
|
255 | |||
244 | void tst_qpieseries::insert() |
|
256 | void tst_qpieseries::insert() | |
245 | { |
|
257 | { | |
246 | m_view->chart()->addSeries(m_series); |
|
258 | m_view->chart()->addSeries(m_series); | |
247 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); |
|
259 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | |
248 |
|
260 | |||
249 | // insert one slice |
|
261 | // insert one slice | |
250 | QPieSlice *slice1 = 0; |
|
262 | QPieSlice *slice1 = 0; | |
251 | QVERIFY(!m_series->insert(0, slice1)); |
|
263 | QVERIFY(!m_series->insert(0, slice1)); | |
252 | slice1 = new QPieSlice("slice 1", 1); |
|
264 | slice1 = new QPieSlice("slice 1", 1); | |
253 | QVERIFY(!m_series->insert(-1, slice1)); |
|
265 | QVERIFY(!m_series->insert(-1, slice1)); | |
254 | QVERIFY(!m_series->insert(5, slice1)); |
|
266 | QVERIFY(!m_series->insert(5, slice1)); | |
255 | QVERIFY(m_series->insert(0, slice1)); |
|
267 | QVERIFY(m_series->insert(0, slice1)); | |
256 | QVERIFY(!m_series->insert(0, slice1)); |
|
268 | QVERIFY(!m_series->insert(0, slice1)); | |
257 | QCOMPARE(m_series->count(), 1); |
|
269 | QCOMPARE(m_series->count(), 1); | |
258 | QCOMPARE(addedSpy.count(), 1); |
|
270 | QCOMPARE(addedSpy.count(), 1); | |
259 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); |
|
271 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
260 | QCOMPARE(added.count(), 1); |
|
272 | QCOMPARE(added.count(), 1); | |
261 | QCOMPARE(added.first(), slice1); |
|
273 | QCOMPARE(added.first(), slice1); | |
262 |
|
274 | |||
263 | // try to insert same slice to another series |
|
275 | // try to insert same slice to another series | |
264 | QPieSeries series2; |
|
276 | QPieSeries series2; | |
265 | QVERIFY(!series2.insert(0, slice1)); |
|
277 | QVERIFY(!series2.insert(0, slice1)); | |
266 |
|
278 | |||
267 | // add some more slices |
|
279 | // add some more slices | |
268 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
280 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
269 | QPieSlice *slice4 = m_series->append("slice 4", 4); |
|
281 | QPieSlice *slice4 = m_series->append("slice 4", 4); | |
270 | QCOMPARE(m_series->count(), 3); |
|
282 | QCOMPARE(m_series->count(), 3); | |
271 | QCOMPARE(addedSpy.count(), 3); |
|
283 | QCOMPARE(addedSpy.count(), 3); | |
272 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); |
|
284 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
273 | QCOMPARE(added.count(), 1); |
|
285 | QCOMPARE(added.count(), 1); | |
274 | QCOMPARE(added.first(), slice2); |
|
286 | QCOMPARE(added.first(), slice2); | |
275 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); |
|
287 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
276 | QCOMPARE(added.count(), 1); |
|
288 | QCOMPARE(added.count(), 1); | |
277 | QCOMPARE(added.first(), slice4); |
|
289 | QCOMPARE(added.first(), slice4); | |
278 |
|
290 | |||
279 | // insert between slices |
|
291 | // insert between slices | |
280 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); |
|
292 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); | |
281 | m_series->insert(2, slice3); |
|
293 | m_series->insert(2, slice3); | |
282 | QCOMPARE(m_series->count(), 4); |
|
294 | QCOMPARE(m_series->count(), 4); | |
283 | QCOMPARE(addedSpy.count(), 4); |
|
295 | QCOMPARE(addedSpy.count(), 4); | |
284 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); |
|
296 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
285 | QCOMPARE(added.count(), 1); |
|
297 | QCOMPARE(added.count(), 1); | |
286 | QCOMPARE(added.first(), slice3); |
|
298 | QCOMPARE(added.first(), slice3); | |
287 |
|
299 | |||
288 | // check slices |
|
300 | // check slices | |
289 | for (int i=0; i<m_series->count(); i++) { |
|
301 | for (int i=0; i<m_series->count(); i++) { | |
290 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); |
|
302 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | |
291 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
303 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
292 | QVERIFY(m_series->slices().at(i)->parent() == m_series); |
|
304 | QVERIFY(m_series->slices().at(i)->parent() == m_series); | |
293 | } |
|
305 | } | |
294 | } |
|
306 | } | |
295 |
|
307 | |||
296 | void tst_qpieseries::insertAnimated() |
|
308 | void tst_qpieseries::insertAnimated() | |
297 | { |
|
309 | { | |
298 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
310 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
299 | insert(); |
|
311 | insert(); | |
300 | } |
|
312 | } | |
301 |
|
313 | |||
302 | void tst_qpieseries::remove() |
|
314 | void tst_qpieseries::remove() | |
303 | { |
|
315 | { | |
304 | m_view->chart()->addSeries(m_series); |
|
316 | m_view->chart()->addSeries(m_series); | |
305 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); |
|
317 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); | |
306 |
|
318 | |||
307 | // add some slices |
|
319 | // add some slices | |
308 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
320 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
309 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
321 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
310 | QPieSlice *slice3 = m_series->append("slice 3", 3); |
|
322 | QPieSlice *slice3 = m_series->append("slice 3", 3); | |
311 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
323 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
312 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
324 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
313 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
325 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
314 | QCOMPARE(m_series->count(), 3); |
|
326 | QCOMPARE(m_series->count(), 3); | |
315 |
|
327 | |||
316 | // null pointer remove |
|
328 | // null pointer remove | |
317 | QVERIFY(!m_series->remove(0)); |
|
329 | QVERIFY(!m_series->remove(0)); | |
318 |
|
330 | |||
319 | // remove first |
|
331 | // remove first | |
320 | QVERIFY(m_series->remove(slice1)); |
|
332 | QVERIFY(m_series->remove(slice1)); | |
321 | QVERIFY(!m_series->remove(slice1)); |
|
333 | QVERIFY(!m_series->remove(slice1)); | |
322 | QCOMPARE(m_series->count(), 2); |
|
334 | QCOMPARE(m_series->count(), 2); | |
323 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); |
|
335 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); | |
324 | QCOMPARE(removedSpy.count(), 1); |
|
336 | QCOMPARE(removedSpy.count(), 1); | |
325 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); |
|
337 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | |
326 | QCOMPARE(removed.count(), 1); |
|
338 | QCOMPARE(removed.count(), 1); | |
327 | QCOMPARE(removed.first(), slice1); |
|
339 | QCOMPARE(removed.first(), slice1); | |
328 |
|
340 | |||
329 | // remove all |
|
341 | // remove all | |
330 | m_series->clear(); |
|
342 | m_series->clear(); | |
331 | QVERIFY(m_series->isEmpty()); |
|
343 | QVERIFY(m_series->isEmpty()); | |
332 | QVERIFY(m_series->slices().isEmpty()); |
|
344 | QVERIFY(m_series->slices().isEmpty()); | |
333 | QCOMPARE(m_series->count(), 0); |
|
345 | QCOMPARE(m_series->count(), 0); | |
334 | QCOMPARE(removedSpy.count(), 2); |
|
346 | QCOMPARE(removedSpy.count(), 2); | |
335 | removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); |
|
347 | removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); | |
336 | QCOMPARE(removed.count(), 2); |
|
348 | QCOMPARE(removed.count(), 2); | |
337 | QCOMPARE(removed.first(), slice2); |
|
349 | QCOMPARE(removed.first(), slice2); | |
338 | QCOMPARE(removed.last(), slice3); |
|
350 | QCOMPARE(removed.last(), slice3); | |
339 |
|
351 | |||
340 | // check that slices were actually destroyed |
|
352 | // check that slices were actually destroyed | |
341 | TRY_COMPARE(spy1.count(), 1); |
|
353 | TRY_COMPARE(spy1.count(), 1); | |
342 | TRY_COMPARE(spy2.count(), 1); |
|
354 | TRY_COMPARE(spy2.count(), 1); | |
343 | TRY_COMPARE(spy3.count(), 1); |
|
355 | TRY_COMPARE(spy3.count(), 1); | |
344 | } |
|
356 | } | |
345 |
|
357 | |||
346 | void tst_qpieseries::removeAnimated() |
|
358 | void tst_qpieseries::removeAnimated() | |
347 | { |
|
359 | { | |
348 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
360 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
349 | remove(); |
|
361 | remove(); | |
350 | } |
|
362 | } | |
351 |
|
363 | |||
352 | void tst_qpieseries::take() |
|
364 | void tst_qpieseries::take() | |
353 | { |
|
365 | { | |
354 | m_view->chart()->addSeries(m_series); |
|
366 | m_view->chart()->addSeries(m_series); | |
355 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); |
|
367 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); | |
356 |
|
368 | |||
357 | // add some slices |
|
369 | // add some slices | |
358 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
370 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
359 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
371 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
360 | m_series->append("slice 3", 3); |
|
372 | m_series->append("slice 3", 3); | |
361 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
373 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
362 | QCOMPARE(m_series->count(), 3); |
|
374 | QCOMPARE(m_series->count(), 3); | |
363 |
|
375 | |||
364 | // null pointer remove |
|
376 | // null pointer remove | |
365 | QVERIFY(!m_series->take(0)); |
|
377 | QVERIFY(!m_series->take(0)); | |
366 |
|
378 | |||
367 | // take first |
|
379 | // take first | |
368 | QVERIFY(m_series->take(slice1)); |
|
380 | QVERIFY(m_series->take(slice1)); | |
369 | TRY_COMPARE(spy1.count(), 0); |
|
381 | TRY_COMPARE(spy1.count(), 0); | |
370 | QVERIFY(slice1->parent() == m_series); // series is still the parent object |
|
382 | QVERIFY(slice1->parent() == m_series); // series is still the parent object | |
371 | QVERIFY(!m_series->take(slice1)); |
|
383 | QVERIFY(!m_series->take(slice1)); | |
372 | QCOMPARE(m_series->count(), 2); |
|
384 | QCOMPARE(m_series->count(), 2); | |
373 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); |
|
385 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); | |
374 | QCOMPARE(removedSpy.count(), 1); |
|
386 | QCOMPARE(removedSpy.count(), 1); | |
375 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); |
|
387 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | |
376 | QCOMPARE(removed.count(), 1); |
|
388 | QCOMPARE(removed.count(), 1); | |
377 | QCOMPARE(removed.first(), slice1); |
|
389 | QCOMPARE(removed.first(), slice1); | |
378 | } |
|
390 | } | |
379 |
|
391 | |||
380 | void tst_qpieseries::takeAnimated() |
|
392 | void tst_qpieseries::takeAnimated() | |
381 | { |
|
393 | { | |
382 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
394 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
383 | take(); |
|
395 | take(); | |
384 | } |
|
396 | } | |
385 |
|
397 | |||
386 | void tst_qpieseries::calculatedValues() |
|
398 | void tst_qpieseries::calculatedValues() | |
387 | { |
|
399 | { | |
388 | m_view->chart()->addSeries(m_series); |
|
400 | m_view->chart()->addSeries(m_series); | |
389 |
|
401 | |||
390 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); |
|
402 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); | |
391 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); |
|
403 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); | |
392 | QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); |
|
404 | QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); | |
393 | QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); |
|
405 | QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); | |
394 |
|
406 | |||
395 | // add a slice |
|
407 | // add a slice | |
396 | m_series->append(slice1); |
|
408 | m_series->append(slice1); | |
397 | bool ok; |
|
409 | bool ok; | |
398 | verifyCalculatedData(*m_series, &ok); |
|
410 | verifyCalculatedData(*m_series, &ok); | |
399 | if (!ok) |
|
411 | if (!ok) | |
400 | return; |
|
412 | return; | |
401 | QCOMPARE(percentageSpy.count(), 1); |
|
413 | QCOMPARE(percentageSpy.count(), 1); | |
402 | QCOMPARE(startAngleSpy.count(), 0); |
|
414 | QCOMPARE(startAngleSpy.count(), 0); | |
403 | QCOMPARE(angleSpanSpy.count(), 1); |
|
415 | QCOMPARE(angleSpanSpy.count(), 1); | |
404 |
|
416 | |||
405 | // add some more slices |
|
417 | // add some more slices | |
406 | QList<QPieSlice *> list; |
|
418 | QList<QPieSlice *> list; | |
407 | list << new QPieSlice("slice 2", 2); |
|
419 | list << new QPieSlice("slice 2", 2); | |
408 | list << new QPieSlice("slice 3", 3); |
|
420 | list << new QPieSlice("slice 3", 3); | |
409 | m_series->append(list); |
|
421 | m_series->append(list); | |
410 | verifyCalculatedData(*m_series, &ok); |
|
422 | verifyCalculatedData(*m_series, &ok); | |
411 | if (!ok) |
|
423 | if (!ok) | |
412 | return; |
|
424 | return; | |
413 | QCOMPARE(percentageSpy.count(), 2); |
|
425 | QCOMPARE(percentageSpy.count(), 2); | |
414 | QCOMPARE(startAngleSpy.count(), 0); |
|
426 | QCOMPARE(startAngleSpy.count(), 0); | |
415 | QCOMPARE(angleSpanSpy.count(), 2); |
|
427 | QCOMPARE(angleSpanSpy.count(), 2); | |
416 |
|
428 | |||
417 | // remove a slice |
|
429 | // remove a slice | |
418 | m_series->remove(list.first()); // remove slice 2 |
|
430 | m_series->remove(list.first()); // remove slice 2 | |
419 | verifyCalculatedData(*m_series, &ok); |
|
431 | verifyCalculatedData(*m_series, &ok); | |
420 | if (!ok) |
|
432 | if (!ok) | |
421 | return; |
|
433 | return; | |
422 | QCOMPARE(percentageSpy.count(), 3); |
|
434 | QCOMPARE(percentageSpy.count(), 3); | |
423 | QCOMPARE(startAngleSpy.count(), 0); |
|
435 | QCOMPARE(startAngleSpy.count(), 0); | |
424 | QCOMPARE(angleSpanSpy.count(), 3); |
|
436 | QCOMPARE(angleSpanSpy.count(), 3); | |
425 |
|
437 | |||
426 | // insert a slice |
|
438 | // insert a slice | |
427 | m_series->insert(0, new QPieSlice("Slice 4", 4)); |
|
439 | m_series->insert(0, new QPieSlice("Slice 4", 4)); | |
428 | verifyCalculatedData(*m_series, &ok); |
|
440 | verifyCalculatedData(*m_series, &ok); | |
429 | if (!ok) |
|
441 | if (!ok) | |
430 | return; |
|
442 | return; | |
431 | QCOMPARE(percentageSpy.count(), 4); |
|
443 | QCOMPARE(percentageSpy.count(), 4); | |
432 | QCOMPARE(startAngleSpy.count(), 1); |
|
444 | QCOMPARE(startAngleSpy.count(), 1); | |
433 | QCOMPARE(angleSpanSpy.count(), 4); |
|
445 | QCOMPARE(angleSpanSpy.count(), 4); | |
434 |
|
446 | |||
435 | // modify pie angles |
|
447 | // modify pie angles | |
436 | m_series->setPieStartAngle(-90); |
|
448 | m_series->setPieStartAngle(-90); | |
437 | m_series->setPieEndAngle(90); |
|
449 | m_series->setPieEndAngle(90); | |
438 | verifyCalculatedData(*m_series, &ok); |
|
450 | verifyCalculatedData(*m_series, &ok); | |
439 | if (!ok) |
|
451 | if (!ok) | |
440 | return; |
|
452 | return; | |
441 | QCOMPARE(percentageSpy.count(), 4); |
|
453 | QCOMPARE(percentageSpy.count(), 4); | |
442 | QCOMPARE(startAngleSpy.count(), 3); |
|
454 | QCOMPARE(startAngleSpy.count(), 3); | |
443 | QCOMPARE(angleSpanSpy.count(), 6); |
|
455 | QCOMPARE(angleSpanSpy.count(), 6); | |
444 |
|
456 | |||
445 | // clear all |
|
457 | // clear all | |
446 | m_series->clear(); |
|
458 | m_series->clear(); | |
447 | verifyCalculatedData(*m_series, &ok); |
|
459 | verifyCalculatedData(*m_series, &ok); | |
448 | if (!ok) |
|
460 | if (!ok) | |
449 | return; |
|
461 | return; | |
450 | QCOMPARE(percentageSpy.count(), 4); |
|
462 | QCOMPARE(percentageSpy.count(), 4); | |
451 | QCOMPARE(startAngleSpy.count(), 3); |
|
463 | QCOMPARE(startAngleSpy.count(), 3); | |
452 | QCOMPARE(angleSpanSpy.count(), 6); |
|
464 | QCOMPARE(angleSpanSpy.count(), 6); | |
453 | } |
|
465 | } | |
454 |
|
466 | |||
455 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) |
|
467 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |
456 | { |
|
468 | { | |
457 | *ok = false; |
|
469 | *ok = false; | |
458 |
|
470 | |||
459 | qreal sum = 0; |
|
471 | qreal sum = 0; | |
460 | foreach (const QPieSlice *slice, series.slices()) |
|
472 | foreach (const QPieSlice *slice, series.slices()) | |
461 | sum += slice->value(); |
|
473 | sum += slice->value(); | |
462 | QCOMPARE(series.sum(), sum); |
|
474 | QCOMPARE(series.sum(), sum); | |
463 |
|
475 | |||
464 | qreal startAngle = series.pieStartAngle(); |
|
476 | qreal startAngle = series.pieStartAngle(); | |
465 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); |
|
477 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | |
466 | foreach (const QPieSlice *slice, series.slices()) { |
|
478 | foreach (const QPieSlice *slice, series.slices()) { | |
467 | qreal ratio = slice->value() / sum; |
|
479 | qreal ratio = slice->value() / sum; | |
468 | qreal sliceSpan = pieAngleSpan * ratio; |
|
480 | qreal sliceSpan = pieAngleSpan * ratio; | |
469 | QCOMPARE(slice->startAngle(), startAngle); |
|
481 | QCOMPARE(slice->startAngle(), startAngle); | |
470 | QCOMPARE(slice->angleSpan(), sliceSpan); |
|
482 | QCOMPARE(slice->angleSpan(), sliceSpan); | |
471 | QCOMPARE(slice->percentage(), ratio); |
|
483 | QCOMPARE(slice->percentage(), ratio); | |
472 | startAngle += sliceSpan; |
|
484 | startAngle += sliceSpan; | |
473 | } |
|
485 | } | |
474 |
|
486 | |||
475 | if (!series.isEmpty()) |
|
487 | if (!series.isEmpty()) | |
476 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); |
|
488 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); | |
477 |
|
489 | |||
478 | *ok = true; |
|
490 | *ok = true; | |
479 | } |
|
491 | } | |
480 |
|
492 | |||
481 | void tst_qpieseries::clickedSignal() |
|
493 | void tst_qpieseries::clickedSignal() | |
482 | { |
|
494 | { | |
483 | // NOTE: |
|
495 | // NOTE: | |
484 | // This test is the same as tst_qpieslice::clickedSignal() |
|
496 | // This test is the same as tst_qpieslice::clickedSignal() | |
485 | // Just for different signals. |
|
497 | // Just for different signals. | |
486 |
|
498 | |||
487 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
499 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
488 |
|
500 | |||
489 | // add some slices |
|
501 | // add some slices | |
490 | QPieSlice *s1 = m_series->append("slice 1", 1); |
|
502 | QPieSlice *s1 = m_series->append("slice 1", 1); | |
491 | QPieSlice *s2 = m_series->append("slice 2", 1); |
|
503 | QPieSlice *s2 = m_series->append("slice 2", 1); | |
492 | QPieSlice *s3 = m_series->append("slice 3", 1); |
|
504 | QPieSlice *s3 = m_series->append("slice 3", 1); | |
493 | QPieSlice *s4 = m_series->append("slice 4", 1); |
|
505 | QPieSlice *s4 = m_series->append("slice 4", 1); | |
494 | QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*))); |
|
506 | QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*))); | |
495 |
|
507 | |||
496 | // add series to the chart |
|
508 | // add series to the chart | |
497 | m_view->chart()->legend()->setVisible(false); |
|
509 | m_view->chart()->legend()->setVisible(false); | |
498 | m_view->chart()->addSeries(m_series); |
|
510 | m_view->chart()->addSeries(m_series); | |
499 | m_view->show(); |
|
511 | m_view->show(); | |
500 | QTest::qWaitForWindowShown(m_view); |
|
512 | QTest::qWaitForWindowShown(m_view); | |
501 |
|
513 | |||
502 | // test maximum size |
|
514 | // test maximum size | |
503 | m_series->setPieSize(1.0); |
|
515 | m_series->setPieSize(1.0); | |
504 | QRectF pieRect = m_view->chart()->plotArea(); |
|
516 | QRectF pieRect = m_view->chart()->plotArea(); | |
505 | QList<QPoint> points = slicePoints(pieRect); |
|
517 | QList<QPoint> points = slicePoints(pieRect); | |
506 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); |
|
518 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); | |
507 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); |
|
519 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); | |
508 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); |
|
520 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); | |
509 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); |
|
521 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); | |
510 | TRY_COMPARE(clickSpy.count(), 4); |
|
522 | TRY_COMPARE(clickSpy.count(), 4); | |
511 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); |
|
523 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); | |
512 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); |
|
524 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); | |
513 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); |
|
525 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); | |
514 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); |
|
526 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); | |
515 | clickSpy.clear(); |
|
527 | clickSpy.clear(); | |
516 |
|
528 | |||
517 | // test half size |
|
529 | // test half size | |
518 | m_series->setPieSize(0.5); |
|
530 | m_series->setPieSize(0.5); | |
519 | m_series->setVerticalPosition(0.25); |
|
531 | m_series->setVerticalPosition(0.25); | |
520 | m_series->setHorizontalPosition(0.25); |
|
532 | m_series->setHorizontalPosition(0.25); | |
521 | pieRect = QRectF(m_view->chart()->plotArea().topLeft(), m_view->chart()->plotArea().center()); |
|
533 | pieRect = QRectF(m_view->chart()->plotArea().topLeft(), m_view->chart()->plotArea().center()); | |
522 | points = slicePoints(pieRect); |
|
534 | points = slicePoints(pieRect); | |
523 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); |
|
535 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); | |
524 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); |
|
536 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); | |
525 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); |
|
537 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); | |
526 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); |
|
538 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); | |
527 | TRY_COMPARE(clickSpy.count(), 4); |
|
539 | TRY_COMPARE(clickSpy.count(), 4); | |
528 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); |
|
540 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); | |
529 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); |
|
541 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); | |
530 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); |
|
542 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); | |
531 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); |
|
543 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); | |
532 | } |
|
544 | } | |
533 |
|
545 | |||
534 | void tst_qpieseries::hoverSignal() |
|
546 | void tst_qpieseries::hoverSignal() | |
535 | { |
|
547 | { | |
536 | // NOTE: |
|
548 | // NOTE: | |
537 | // This test is the same as tst_qpieslice::hoverSignal() |
|
549 | // This test is the same as tst_qpieslice::hoverSignal() | |
538 | // Just for different signals. |
|
550 | // Just for different signals. | |
539 |
|
551 | |||
540 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
552 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
541 |
|
553 | |||
542 | // add some slices |
|
554 | // add some slices | |
543 | QPieSlice *s1 = m_series->append("slice 1", 1); |
|
555 | QPieSlice *s1 = m_series->append("slice 1", 1); | |
544 | QPieSlice *s2 = m_series->append("slice 2", 1); |
|
556 | QPieSlice *s2 = m_series->append("slice 2", 1); | |
545 | QPieSlice *s3 = m_series->append("slice 3", 1); |
|
557 | QPieSlice *s3 = m_series->append("slice 3", 1); | |
546 | QPieSlice *s4 = m_series->append("slice 4", 1); |
|
558 | QPieSlice *s4 = m_series->append("slice 4", 1); | |
547 |
|
559 | |||
548 | // add series to the chart |
|
560 | // add series to the chart | |
549 | m_view->chart()->legend()->setVisible(false); |
|
561 | m_view->chart()->legend()->setVisible(false); | |
550 | m_view->chart()->addSeries(m_series); |
|
562 | m_view->chart()->addSeries(m_series); | |
551 | m_view->show(); |
|
563 | m_view->show(); | |
552 | QTest::qWaitForWindowShown(m_view); |
|
564 | QTest::qWaitForWindowShown(m_view); | |
553 |
|
565 | |||
554 | // move inside the slices |
|
566 | // move inside the slices | |
555 | m_series->setPieSize(1.0); |
|
567 | m_series->setPieSize(1.0); | |
556 | QRectF pieRect = m_view->chart()->plotArea(); |
|
568 | QRectF pieRect = m_view->chart()->plotArea(); | |
557 | QList<QPoint> points = slicePoints(pieRect); |
|
569 | QList<QPoint> points = slicePoints(pieRect); | |
558 | QTest::mouseMove(m_view->viewport(), pieRect.topRight().toPoint()); |
|
570 | QTest::mouseMove(m_view->viewport(), pieRect.topRight().toPoint()); | |
559 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); |
|
571 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); | |
560 | QTest::mouseMove(m_view->viewport(), points.at(0)); |
|
572 | QTest::mouseMove(m_view->viewport(), points.at(0)); | |
561 | QTest::mouseMove(m_view->viewport(), points.at(1)); |
|
573 | QTest::mouseMove(m_view->viewport(), points.at(1)); | |
562 | QTest::mouseMove(m_view->viewport(), points.at(2)); |
|
574 | QTest::mouseMove(m_view->viewport(), points.at(2)); | |
563 | QTest::mouseMove(m_view->viewport(), points.at(3)); |
|
575 | QTest::mouseMove(m_view->viewport(), points.at(3)); | |
564 | QTest::mouseMove(m_view->viewport(), pieRect.topLeft().toPoint()); |
|
576 | QTest::mouseMove(m_view->viewport(), pieRect.topLeft().toPoint()); | |
565 |
|
577 | |||
566 | // check |
|
578 | // check | |
567 | QCOMPARE(hoverSpy.count(), 8); |
|
579 | QCOMPARE(hoverSpy.count(), 8); | |
568 | int i = 0; |
|
580 | int i = 0; | |
569 | foreach (QPieSlice *s, m_series->slices()) { |
|
581 | foreach (QPieSlice *s, m_series->slices()) { | |
570 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); |
|
582 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); | |
571 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), true); |
|
583 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), true); | |
572 | i++; |
|
584 | i++; | |
573 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); |
|
585 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); | |
574 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), false); |
|
586 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), false); | |
575 | i++; |
|
587 | i++; | |
576 | } |
|
588 | } | |
577 | } |
|
589 | } | |
578 |
|
590 | |||
579 | void tst_qpieseries::sliceSeries() |
|
591 | void tst_qpieseries::sliceSeries() | |
580 | { |
|
592 | { | |
581 | QPieSlice *slice = new QPieSlice(); |
|
593 | QPieSlice *slice = new QPieSlice(); | |
582 | QVERIFY(!slice->series()); |
|
594 | QVERIFY(!slice->series()); | |
583 | delete slice; |
|
595 | delete slice; | |
584 |
|
596 | |||
585 | slice = new QPieSlice(m_series); |
|
597 | slice = new QPieSlice(m_series); | |
586 | QVERIFY(!slice->series()); |
|
598 | QVERIFY(!slice->series()); | |
587 |
|
599 | |||
588 | m_series->append(slice); |
|
600 | m_series->append(slice); | |
589 | QCOMPARE(slice->series(), m_series); |
|
601 | QCOMPARE(slice->series(), m_series); | |
590 |
|
602 | |||
591 | slice = new QPieSlice(); |
|
603 | slice = new QPieSlice(); | |
592 | m_series->insert(0, slice); |
|
604 | m_series->insert(0, slice); | |
593 | QCOMPARE(slice->series(), m_series); |
|
605 | QCOMPARE(slice->series(), m_series); | |
594 |
|
606 | |||
595 | m_series->take(slice); |
|
607 | m_series->take(slice); | |
596 | QCOMPARE(slice->series(), (QPieSeries*) 0); |
|
608 | QCOMPARE(slice->series(), (QPieSeries*) 0); | |
597 | } |
|
609 | } | |
598 |
|
610 | |||
599 | void tst_qpieseries::destruction() |
|
611 | void tst_qpieseries::destruction() | |
600 | { |
|
612 | { | |
601 | // add some slices |
|
613 | // add some slices | |
602 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
614 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
603 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
615 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
604 | QPieSlice *slice3 = m_series->append("slice 3", 3); |
|
616 | QPieSlice *slice3 = m_series->append("slice 3", 3); | |
605 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
617 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
606 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
618 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
607 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
619 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
608 |
|
620 | |||
609 | // destroy series |
|
621 | // destroy series | |
610 | delete m_series; |
|
622 | delete m_series; | |
611 | m_series = 0; |
|
623 | m_series = 0; | |
612 |
|
624 | |||
613 | // check that series has destroyed its slices |
|
625 | // check that series has destroyed its slices | |
614 | QCOMPARE(spy1.count(), 1); |
|
626 | QCOMPARE(spy1.count(), 1); | |
615 | QCOMPARE(spy2.count(), 1); |
|
627 | QCOMPARE(spy2.count(), 1); | |
616 | QCOMPARE(spy3.count(), 1); |
|
628 | QCOMPARE(spy3.count(), 1); | |
617 | } |
|
629 | } | |
618 |
|
630 | |||
619 | QList<QPoint> tst_qpieseries::slicePoints(QRectF rect) |
|
631 | QList<QPoint> tst_qpieseries::slicePoints(QRectF rect) | |
620 | { |
|
632 | { | |
621 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); |
|
633 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); | |
622 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; |
|
634 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; | |
623 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); |
|
635 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); | |
624 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; |
|
636 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; | |
625 | QList<QPoint> points; |
|
637 | QList<QPoint> points; | |
626 | points << QPoint(x2, y1); |
|
638 | points << QPoint(x2, y1); | |
627 | points << QPoint(x2, y2); |
|
639 | points << QPoint(x2, y2); | |
628 | points << QPoint(x1, y2); |
|
640 | points << QPoint(x1, y2); | |
629 | points << QPoint(x1, y1); |
|
641 | points << QPoint(x1, y1); | |
630 | return points; |
|
642 | return points; | |
631 | } |
|
643 | } | |
632 |
|
644 | |||
633 | QTEST_MAIN(tst_qpieseries) |
|
645 | QTEST_MAIN(tst_qpieseries) | |
634 |
|
646 | |||
635 | #include "tst_qpieseries.moc" |
|
647 | #include "tst_qpieseries.moc" | |
636 |
|
648 |
@@ -1,439 +1,457 | |||||
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 "tst_qxyseries.h" |
|
21 | #include "tst_qxyseries.h" | |
22 |
|
22 | |||
23 | Q_DECLARE_METATYPE(QList<QPointF>) |
|
23 | Q_DECLARE_METATYPE(QList<QPointF>) | |
24 |
|
24 | |||
25 | void tst_QXYSeries::initTestCase() |
|
25 | void tst_QXYSeries::initTestCase() | |
26 | { |
|
26 | { | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | void tst_QXYSeries::cleanupTestCase() |
|
29 | void tst_QXYSeries::cleanupTestCase() | |
30 | { |
|
30 | { | |
31 | } |
|
31 | } | |
32 |
|
32 | |||
33 | void tst_QXYSeries::init() |
|
33 | void tst_QXYSeries::init() | |
34 | { |
|
34 | { | |
35 | m_view = new QChartView(new QChart()); |
|
35 | m_view = new QChartView(new QChart()); | |
36 | m_chart = m_view->chart(); |
|
36 | m_chart = m_view->chart(); | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | void tst_QXYSeries::cleanup() |
|
39 | void tst_QXYSeries::cleanup() | |
40 | { |
|
40 | { | |
41 | delete m_view; |
|
41 | delete m_view; | |
42 | m_view = 0; |
|
42 | m_view = 0; | |
43 | m_chart = 0; |
|
43 | m_chart = 0; | |
44 | m_series = 0; |
|
44 | m_series = 0; | |
45 | } |
|
45 | } | |
46 |
|
46 | |||
47 | void tst_QXYSeries::seriesName() |
|
47 | void tst_QXYSeries::seriesName() | |
48 | { |
|
48 | { | |
49 | QSignalSpy nameSpy(m_series, SIGNAL(nameChanged())); |
|
49 | QSignalSpy nameSpy(m_series, SIGNAL(nameChanged())); | |
50 | QCOMPARE(m_series->name(), QString()); |
|
50 | QCOMPARE(m_series->name(), QString()); | |
51 | m_series->setName("seriesname"); |
|
51 | m_series->setName("seriesname"); | |
52 | QCOMPARE(m_series->name(), QString("seriesname")); |
|
52 | QCOMPARE(m_series->name(), QString("seriesname")); | |
53 | TRY_COMPARE(nameSpy.count(), 1); |
|
53 | TRY_COMPARE(nameSpy.count(), 1); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | void tst_QXYSeries::seriesVisible() |
|
56 | void tst_QXYSeries::seriesVisible() | |
57 | { |
|
57 | { | |
58 | QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); |
|
58 | QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); | |
59 | QCOMPARE(m_series->isVisible(), true); |
|
59 | QCOMPARE(m_series->isVisible(), true); | |
60 | m_series->setVisible(false); |
|
60 | m_series->setVisible(false); | |
61 | QCOMPARE(m_series->isVisible(), false); |
|
61 | QCOMPARE(m_series->isVisible(), false); | |
62 | m_series->setVisible(true); |
|
62 | m_series->setVisible(true); | |
63 | TRY_COMPARE(visibleSpy.count(), 2); |
|
63 | TRY_COMPARE(visibleSpy.count(), 2); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
|
66 | void tst_QXYSeries::seriesOpacity() | |||
|
67 | { | |||
|
68 | QSignalSpy opacitySpy(m_series, SIGNAL(opacityChanged())); | |||
|
69 | QCOMPARE(m_series->opacity(), 1.0); | |||
|
70 | ||||
|
71 | m_series->setOpacity(0.5); | |||
|
72 | QCOMPARE(m_series->opacity(), 0.5); | |||
|
73 | QCOMPARE(opacitySpy.count(), 1); | |||
|
74 | ||||
|
75 | m_series->setOpacity(0.0); | |||
|
76 | QCOMPARE(m_series->opacity(), 0.0); | |||
|
77 | QCOMPARE(opacitySpy.count(), 2); | |||
|
78 | ||||
|
79 | m_series->setOpacity(1.0); | |||
|
80 | QCOMPARE(m_series->opacity(), 1.0); | |||
|
81 | QCOMPARE(opacitySpy.count(), 3); | |||
|
82 | } | |||
|
83 | ||||
66 | void tst_QXYSeries::append_data() |
|
84 | void tst_QXYSeries::append_data() | |
67 | { |
|
85 | { | |
68 | QTest::addColumn< QList<QPointF> >("points"); |
|
86 | QTest::addColumn< QList<QPointF> >("points"); | |
69 | QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); |
|
87 | QTest::newRow("0,0 1,1 2,2 3,3") << (QList<QPointF>() << QPointF(0,0) << QPointF(1,1) << QPointF(2,2) << QPointF(3,3)); | |
70 | QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); |
|
88 | QTest::newRow("0,0 -1,-1 -2,-2 -3,-3") << (QList<QPointF>() << QPointF(0,0) << QPointF(-1,-1) << QPointF(-2,-2) << QPointF(-3,-3)); | |
71 | } |
|
89 | } | |
72 |
|
90 | |||
73 |
|
91 | |||
74 | void tst_QXYSeries::append_raw_data() |
|
92 | void tst_QXYSeries::append_raw_data() | |
75 | { |
|
93 | { | |
76 | append_data(); |
|
94 | append_data(); | |
77 | } |
|
95 | } | |
78 |
|
96 | |||
79 | void tst_QXYSeries::append_raw() |
|
97 | void tst_QXYSeries::append_raw() | |
80 | { |
|
98 | { | |
81 | QFETCH(QList<QPointF>, points); |
|
99 | QFETCH(QList<QPointF>, points); | |
82 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
100 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
83 | QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int))); |
|
101 | QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int))); | |
84 | m_series->append(points); |
|
102 | m_series->append(points); | |
85 | TRY_COMPARE(spy0.count(), 0); |
|
103 | TRY_COMPARE(spy0.count(), 0); | |
86 | TRY_COMPARE(addedSpy.count(), points.count()); |
|
104 | TRY_COMPARE(addedSpy.count(), points.count()); | |
87 | QCOMPARE(m_series->points(), points); |
|
105 | QCOMPARE(m_series->points(), points); | |
88 | } |
|
106 | } | |
89 |
|
107 | |||
90 | void tst_QXYSeries::chart_append_data() |
|
108 | void tst_QXYSeries::chart_append_data() | |
91 | { |
|
109 | { | |
92 | append_data(); |
|
110 | append_data(); | |
93 | } |
|
111 | } | |
94 |
|
112 | |||
95 | void tst_QXYSeries::chart_append() |
|
113 | void tst_QXYSeries::chart_append() | |
96 | { |
|
114 | { | |
97 | append_raw(); |
|
115 | append_raw(); | |
98 | m_chart->addSeries(m_series); |
|
116 | m_chart->addSeries(m_series); | |
99 | m_view->show(); |
|
117 | m_view->show(); | |
100 | QTest::qWaitForWindowShown(m_view); |
|
118 | QTest::qWaitForWindowShown(m_view); | |
101 | } |
|
119 | } | |
102 |
|
120 | |||
103 | void tst_QXYSeries::append_chart_data() |
|
121 | void tst_QXYSeries::append_chart_data() | |
104 | { |
|
122 | { | |
105 | append_data(); |
|
123 | append_data(); | |
106 | } |
|
124 | } | |
107 |
|
125 | |||
108 | void tst_QXYSeries::append_chart() |
|
126 | void tst_QXYSeries::append_chart() | |
109 | { |
|
127 | { | |
110 | m_view->show(); |
|
128 | m_view->show(); | |
111 | m_chart->addSeries(m_series); |
|
129 | m_chart->addSeries(m_series); | |
112 | QTest::qWaitForWindowShown(m_view); |
|
130 | QTest::qWaitForWindowShown(m_view); | |
113 | append_raw(); |
|
131 | append_raw(); | |
114 |
|
132 | |||
115 | } |
|
133 | } | |
116 |
|
134 | |||
117 | void tst_QXYSeries::append_chart_animation_data() |
|
135 | void tst_QXYSeries::append_chart_animation_data() | |
118 | { |
|
136 | { | |
119 | append_data(); |
|
137 | append_data(); | |
120 | } |
|
138 | } | |
121 |
|
139 | |||
122 | void tst_QXYSeries::append_chart_animation() |
|
140 | void tst_QXYSeries::append_chart_animation() | |
123 | { |
|
141 | { | |
124 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
142 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
125 | append_chart(); |
|
143 | append_chart(); | |
126 | } |
|
144 | } | |
127 |
|
145 | |||
128 | void tst_QXYSeries::count_data() |
|
146 | void tst_QXYSeries::count_data() | |
129 | { |
|
147 | { | |
130 | QTest::addColumn<int>("count"); |
|
148 | QTest::addColumn<int>("count"); | |
131 | QTest::newRow("0") << 0; |
|
149 | QTest::newRow("0") << 0; | |
132 | QTest::newRow("5") << 5; |
|
150 | QTest::newRow("5") << 5; | |
133 | QTest::newRow("10") << 5; |
|
151 | QTest::newRow("10") << 5; | |
134 | } |
|
152 | } | |
135 |
|
153 | |||
136 | void tst_QXYSeries::count_raw_data() |
|
154 | void tst_QXYSeries::count_raw_data() | |
137 | { |
|
155 | { | |
138 | count_data(); |
|
156 | count_data(); | |
139 | } |
|
157 | } | |
140 |
|
158 | |||
141 | void tst_QXYSeries::count_raw() |
|
159 | void tst_QXYSeries::count_raw() | |
142 | { |
|
160 | { | |
143 | QFETCH(int, count); |
|
161 | QFETCH(int, count); | |
144 |
|
162 | |||
145 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
163 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
146 |
|
164 | |||
147 | for(int i=0 ; i< count; ++i) |
|
165 | for(int i=0 ; i< count; ++i) | |
148 | m_series->append(i,i); |
|
166 | m_series->append(i,i); | |
149 |
|
167 | |||
150 | TRY_COMPARE(spy0.count(), 0); |
|
168 | TRY_COMPARE(spy0.count(), 0); | |
151 | QCOMPARE(m_series->count(), count); |
|
169 | QCOMPARE(m_series->count(), count); | |
152 | } |
|
170 | } | |
153 |
|
171 | |||
154 | void tst_QXYSeries::remove_raw_data() |
|
172 | void tst_QXYSeries::remove_raw_data() | |
155 | { |
|
173 | { | |
156 | append_data(); |
|
174 | append_data(); | |
157 | } |
|
175 | } | |
158 |
|
176 | |||
159 | void tst_QXYSeries::remove_raw() |
|
177 | void tst_QXYSeries::remove_raw() | |
160 | { |
|
178 | { | |
161 | QFETCH(QList<QPointF>, points); |
|
179 | QFETCH(QList<QPointF>, points); | |
162 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
180 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
163 | m_series->append(points); |
|
181 | m_series->append(points); | |
164 | TRY_COMPARE(spy0.count(), 0); |
|
182 | TRY_COMPARE(spy0.count(), 0); | |
165 | QCOMPARE(m_series->points(), points); |
|
183 | QCOMPARE(m_series->points(), points); | |
166 |
|
184 | |||
167 | foreach(const QPointF& point,points) |
|
185 | foreach(const QPointF& point,points) | |
168 | m_series->remove(point); |
|
186 | m_series->remove(point); | |
169 |
|
187 | |||
170 | QCOMPARE(m_series->points().count(), 0); |
|
188 | QCOMPARE(m_series->points().count(), 0); | |
171 | TRY_COMPARE(spy0.count(), 0); |
|
189 | TRY_COMPARE(spy0.count(), 0); | |
172 |
|
190 | |||
173 | m_series->append(points); |
|
191 | m_series->append(points); | |
174 | QCOMPARE(m_series->points(), points); |
|
192 | QCOMPARE(m_series->points(), points); | |
175 |
|
193 | |||
176 | //reverse order |
|
194 | //reverse order | |
177 | for(int i = points.count()-1 ; i>=0; i--){ |
|
195 | for(int i = points.count()-1 ; i>=0; i--){ | |
178 | m_series->remove(points[i]); |
|
196 | m_series->remove(points[i]); | |
179 | } |
|
197 | } | |
180 | QCOMPARE(m_series->points().count(), 0); |
|
198 | QCOMPARE(m_series->points().count(), 0); | |
181 | } |
|
199 | } | |
182 |
|
200 | |||
183 | void tst_QXYSeries::remove_chart_data() |
|
201 | void tst_QXYSeries::remove_chart_data() | |
184 | { |
|
202 | { | |
185 | append_data(); |
|
203 | append_data(); | |
186 | } |
|
204 | } | |
187 |
|
205 | |||
188 | void tst_QXYSeries::remove_chart() |
|
206 | void tst_QXYSeries::remove_chart() | |
189 | { |
|
207 | { | |
190 | m_view->show(); |
|
208 | m_view->show(); | |
191 | m_chart->addSeries(m_series); |
|
209 | m_chart->addSeries(m_series); | |
192 | QTest::qWaitForWindowShown(m_view); |
|
210 | QTest::qWaitForWindowShown(m_view); | |
193 | remove_raw(); |
|
211 | remove_raw(); | |
194 | } |
|
212 | } | |
195 |
|
213 | |||
196 | void tst_QXYSeries::remove_chart_animation_data() |
|
214 | void tst_QXYSeries::remove_chart_animation_data() | |
197 | { |
|
215 | { | |
198 | append_data(); |
|
216 | append_data(); | |
199 | } |
|
217 | } | |
200 |
|
218 | |||
201 | void tst_QXYSeries::remove_chart_animation() |
|
219 | void tst_QXYSeries::remove_chart_animation() | |
202 | { |
|
220 | { | |
203 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
221 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
204 | remove_chart(); |
|
222 | remove_chart(); | |
205 | } |
|
223 | } | |
206 |
|
224 | |||
207 |
|
225 | |||
208 | void tst_QXYSeries::clear_raw_data() |
|
226 | void tst_QXYSeries::clear_raw_data() | |
209 | { |
|
227 | { | |
210 | append_data(); |
|
228 | append_data(); | |
211 | } |
|
229 | } | |
212 |
|
230 | |||
213 | void tst_QXYSeries::clear_raw() |
|
231 | void tst_QXYSeries::clear_raw() | |
214 | { |
|
232 | { | |
215 | QFETCH(QList<QPointF>, points); |
|
233 | QFETCH(QList<QPointF>, points); | |
216 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
234 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
217 | m_series->append(points); |
|
235 | m_series->append(points); | |
218 | TRY_COMPARE(spy0.count(), 0); |
|
236 | TRY_COMPARE(spy0.count(), 0); | |
219 | QCOMPARE(m_series->points(), points); |
|
237 | QCOMPARE(m_series->points(), points); | |
220 | m_series->clear(); |
|
238 | m_series->clear(); | |
221 | TRY_COMPARE(spy0.count(), 0); |
|
239 | TRY_COMPARE(spy0.count(), 0); | |
222 | QCOMPARE(m_series->points().count(), 0); |
|
240 | QCOMPARE(m_series->points().count(), 0); | |
223 | } |
|
241 | } | |
224 |
|
242 | |||
225 | void tst_QXYSeries::clear_chart_data() |
|
243 | void tst_QXYSeries::clear_chart_data() | |
226 | { |
|
244 | { | |
227 | append_data(); |
|
245 | append_data(); | |
228 | } |
|
246 | } | |
229 |
|
247 | |||
230 | void tst_QXYSeries::clear_chart() |
|
248 | void tst_QXYSeries::clear_chart() | |
231 | { |
|
249 | { | |
232 | m_view->show(); |
|
250 | m_view->show(); | |
233 | m_chart->addSeries(m_series); |
|
251 | m_chart->addSeries(m_series); | |
234 | QTest::qWaitForWindowShown(m_view); |
|
252 | QTest::qWaitForWindowShown(m_view); | |
235 | clear_raw(); |
|
253 | clear_raw(); | |
236 | } |
|
254 | } | |
237 |
|
255 | |||
238 | void tst_QXYSeries::clear_chart_animation_data() |
|
256 | void tst_QXYSeries::clear_chart_animation_data() | |
239 | { |
|
257 | { | |
240 | append_data(); |
|
258 | append_data(); | |
241 | } |
|
259 | } | |
242 |
|
260 | |||
243 | void tst_QXYSeries::clear_chart_animation() |
|
261 | void tst_QXYSeries::clear_chart_animation() | |
244 | { |
|
262 | { | |
245 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
263 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
246 | clear_chart(); |
|
264 | clear_chart(); | |
247 | } |
|
265 | } | |
248 |
|
266 | |||
249 | void tst_QXYSeries::replace_raw_data() |
|
267 | void tst_QXYSeries::replace_raw_data() | |
250 | { |
|
268 | { | |
251 | append_data(); |
|
269 | append_data(); | |
252 | } |
|
270 | } | |
253 |
|
271 | |||
254 | void tst_QXYSeries::replace_raw() |
|
272 | void tst_QXYSeries::replace_raw() | |
255 | { |
|
273 | { | |
256 | QFETCH(QList<QPointF>, points); |
|
274 | QFETCH(QList<QPointF>, points); | |
257 | QSignalSpy pointReplacedSpy(m_series, SIGNAL(pointReplaced(int))); |
|
275 | QSignalSpy pointReplacedSpy(m_series, SIGNAL(pointReplaced(int))); | |
258 | QSignalSpy pointsReplacedSpy(m_series, SIGNAL(pointsReplaced())); |
|
276 | QSignalSpy pointsReplacedSpy(m_series, SIGNAL(pointsReplaced())); | |
259 | m_series->append(points); |
|
277 | m_series->append(points); | |
260 | TRY_COMPARE(pointReplacedSpy.count(), 0); |
|
278 | TRY_COMPARE(pointReplacedSpy.count(), 0); | |
261 | TRY_COMPARE(pointsReplacedSpy.count(), 0); |
|
279 | TRY_COMPARE(pointsReplacedSpy.count(), 0); | |
262 | QCOMPARE(m_series->points(), points); |
|
280 | QCOMPARE(m_series->points(), points); | |
263 |
|
281 | |||
264 | foreach(const QPointF& point, points) |
|
282 | foreach(const QPointF& point, points) | |
265 | m_series->replace(point.x(),point.y(),point.x(),0); |
|
283 | m_series->replace(point.x(),point.y(),point.x(),0); | |
266 | TRY_COMPARE(pointReplacedSpy.count(), points.count()); |
|
284 | TRY_COMPARE(pointReplacedSpy.count(), points.count()); | |
267 | TRY_COMPARE(pointsReplacedSpy.count(), 0); |
|
285 | TRY_COMPARE(pointsReplacedSpy.count(), 0); | |
268 |
|
286 | |||
269 | // Replace a point that does not exist |
|
287 | // Replace a point that does not exist | |
270 | m_series->replace(-123, 999, 0, 0); |
|
288 | m_series->replace(-123, 999, 0, 0); | |
271 | TRY_COMPARE(pointReplacedSpy.count(), points.count()); |
|
289 | TRY_COMPARE(pointReplacedSpy.count(), points.count()); | |
272 | TRY_COMPARE(pointsReplacedSpy.count(), 0); |
|
290 | TRY_COMPARE(pointsReplacedSpy.count(), 0); | |
273 |
|
291 | |||
274 | QList<QPointF> newPoints = m_series->points(); |
|
292 | QList<QPointF> newPoints = m_series->points(); | |
275 | QCOMPARE(newPoints.count(), points.count()); |
|
293 | QCOMPARE(newPoints.count(), points.count()); | |
276 | for(int i =0 ; i<points.count() ; ++i) { |
|
294 | for(int i =0 ; i<points.count() ; ++i) { | |
277 | QCOMPARE(points[i].x(), newPoints[i].x()); |
|
295 | QCOMPARE(points[i].x(), newPoints[i].x()); | |
278 | QCOMPARE(newPoints[i].y(), 0.0); |
|
296 | QCOMPARE(newPoints[i].y(), 0.0); | |
279 | } |
|
297 | } | |
280 |
|
298 | |||
281 | // Replace all points |
|
299 | // Replace all points | |
282 | QList<QPointF> allPoints; |
|
300 | QList<QPointF> allPoints; | |
283 | for (int i = 0; i < 10; i++) |
|
301 | for (int i = 0; i < 10; i++) | |
284 | allPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX)); |
|
302 | allPoints.append(QPointF(i, (qreal) rand() / (qreal) RAND_MAX)); | |
285 | m_series->replace(allPoints); |
|
303 | m_series->replace(allPoints); | |
286 | TRY_COMPARE(pointReplacedSpy.count(), points.count()); |
|
304 | TRY_COMPARE(pointReplacedSpy.count(), points.count()); | |
287 | TRY_COMPARE(pointsReplacedSpy.count(), 1); |
|
305 | TRY_COMPARE(pointsReplacedSpy.count(), 1); | |
288 | } |
|
306 | } | |
289 |
|
307 | |||
290 |
|
308 | |||
291 | void tst_QXYSeries::replace_chart_data() |
|
309 | void tst_QXYSeries::replace_chart_data() | |
292 | { |
|
310 | { | |
293 | append_data(); |
|
311 | append_data(); | |
294 | } |
|
312 | } | |
295 |
|
313 | |||
296 | void tst_QXYSeries::replace_chart() |
|
314 | void tst_QXYSeries::replace_chart() | |
297 | { |
|
315 | { | |
298 | m_view->show(); |
|
316 | m_view->show(); | |
299 | m_chart->addSeries(m_series); |
|
317 | m_chart->addSeries(m_series); | |
300 | QTest::qWaitForWindowShown(m_view); |
|
318 | QTest::qWaitForWindowShown(m_view); | |
301 | replace_raw(); |
|
319 | replace_raw(); | |
302 | } |
|
320 | } | |
303 |
|
321 | |||
304 | void tst_QXYSeries::replace_chart_animation_data() |
|
322 | void tst_QXYSeries::replace_chart_animation_data() | |
305 | { |
|
323 | { | |
306 | append_data(); |
|
324 | append_data(); | |
307 | } |
|
325 | } | |
308 |
|
326 | |||
309 | void tst_QXYSeries::replace_chart_animation() |
|
327 | void tst_QXYSeries::replace_chart_animation() | |
310 | { |
|
328 | { | |
311 | m_chart->setAnimationOptions(QChart::AllAnimations); |
|
329 | m_chart->setAnimationOptions(QChart::AllAnimations); | |
312 | replace_chart(); |
|
330 | replace_chart(); | |
313 | } |
|
331 | } | |
314 |
|
332 | |||
315 | void tst_QXYSeries::insert_data() |
|
333 | void tst_QXYSeries::insert_data() | |
316 | { |
|
334 | { | |
317 | append_data(); |
|
335 | append_data(); | |
318 | } |
|
336 | } | |
319 |
|
337 | |||
320 | void tst_QXYSeries::insert() |
|
338 | void tst_QXYSeries::insert() | |
321 | { |
|
339 | { | |
322 | QFETCH(QList<QPointF>, points); |
|
340 | QFETCH(QList<QPointF>, points); | |
323 | m_series->append(points); |
|
341 | m_series->append(points); | |
324 |
|
342 | |||
325 | QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int))); |
|
343 | QSignalSpy addedSpy(m_series, SIGNAL(pointAdded(int))); | |
326 |
|
344 | |||
327 | m_series->insert(0, QPointF(5, 5)); |
|
345 | m_series->insert(0, QPointF(5, 5)); | |
328 | TRY_COMPARE(addedSpy.count(), 1); |
|
346 | TRY_COMPARE(addedSpy.count(), 1); | |
329 | QCOMPARE(m_series->points().count(), points.count() + 1); |
|
347 | QCOMPARE(m_series->points().count(), points.count() + 1); | |
330 |
|
348 | |||
331 | m_series->insert(m_series->count(), QPointF(6, 6)); |
|
349 | m_series->insert(m_series->count(), QPointF(6, 6)); | |
332 | TRY_COMPARE(addedSpy.count(), 2); |
|
350 | TRY_COMPARE(addedSpy.count(), 2); | |
333 | QCOMPARE(m_series->points().count(), points.count() + 2); |
|
351 | QCOMPARE(m_series->points().count(), points.count() + 2); | |
334 | } |
|
352 | } | |
335 |
|
353 | |||
336 | void tst_QXYSeries::oper_data() |
|
354 | void tst_QXYSeries::oper_data() | |
337 | { |
|
355 | { | |
338 | append_data(); |
|
356 | append_data(); | |
339 | } |
|
357 | } | |
340 |
|
358 | |||
341 | void tst_QXYSeries::oper() |
|
359 | void tst_QXYSeries::oper() | |
342 | { |
|
360 | { | |
343 | QFETCH(QList<QPointF>, points); |
|
361 | QFETCH(QList<QPointF>, points); | |
344 |
|
362 | |||
345 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
363 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
346 |
|
364 | |||
347 | foreach(const QPointF& point,points) |
|
365 | foreach(const QPointF& point,points) | |
348 | { |
|
366 | { | |
349 | *m_series<<point; |
|
367 | *m_series<<point; | |
350 | } |
|
368 | } | |
351 |
|
369 | |||
352 | QCOMPARE(m_series->points(), points); |
|
370 | QCOMPARE(m_series->points(), points); | |
353 | TRY_COMPARE(spy0.count(), 0); |
|
371 | TRY_COMPARE(spy0.count(), 0); | |
354 | } |
|
372 | } | |
355 |
|
373 | |||
356 |
|
374 | |||
357 | void tst_QXYSeries::pen_data() |
|
375 | void tst_QXYSeries::pen_data() | |
358 | { |
|
376 | { | |
359 | QTest::addColumn<QPen>("pen"); |
|
377 | QTest::addColumn<QPen>("pen"); | |
360 | QTest::newRow("null") << QPen(); |
|
378 | QTest::newRow("null") << QPen(); | |
361 | QTest::newRow("blue") << QPen(Qt::blue); |
|
379 | QTest::newRow("blue") << QPen(Qt::blue); | |
362 | QTest::newRow("black") << QPen(Qt::black); |
|
380 | QTest::newRow("black") << QPen(Qt::black); | |
363 | QTest::newRow("red") << QPen(Qt::red); |
|
381 | QTest::newRow("red") << QPen(Qt::red); | |
364 | } |
|
382 | } | |
365 |
|
383 | |||
366 | void tst_QXYSeries::pen() |
|
384 | void tst_QXYSeries::pen() | |
367 | { |
|
385 | { | |
368 | QFETCH(QPen, pen); |
|
386 | QFETCH(QPen, pen); | |
369 |
|
387 | |||
370 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
388 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
371 | m_series->setPen(pen); |
|
389 | m_series->setPen(pen); | |
372 |
|
390 | |||
373 | TRY_COMPARE(spy0.count(), 0); |
|
391 | TRY_COMPARE(spy0.count(), 0); | |
374 | QCOMPARE(m_series->pen(), pen); |
|
392 | QCOMPARE(m_series->pen(), pen); | |
375 |
|
393 | |||
376 | m_chart->addSeries(m_series); |
|
394 | m_chart->addSeries(m_series); | |
377 |
|
395 | |||
378 | if (pen != QPen()) |
|
396 | if (pen != QPen()) | |
379 | QCOMPARE(m_series->pen(), pen); |
|
397 | QCOMPARE(m_series->pen(), pen); | |
380 |
|
398 | |||
381 | m_chart->setTheme(QChart::ChartThemeDark); |
|
399 | m_chart->setTheme(QChart::ChartThemeDark); | |
382 |
|
400 | |||
383 | // setting a theme will overwrite all customizations |
|
401 | // setting a theme will overwrite all customizations | |
384 | if (pen != QPen()) |
|
402 | if (pen != QPen()) | |
385 | QVERIFY(m_series->pen() != pen); |
|
403 | QVERIFY(m_series->pen() != pen); | |
386 | } |
|
404 | } | |
387 |
|
405 | |||
388 | void tst_QXYSeries::pointsVisible_data() |
|
406 | void tst_QXYSeries::pointsVisible_data() | |
389 | { |
|
407 | { | |
390 | QTest::addColumn<bool>("pointsVisible"); |
|
408 | QTest::addColumn<bool>("pointsVisible"); | |
391 | QTest::newRow("true") << true; |
|
409 | QTest::newRow("true") << true; | |
392 | QTest::newRow("false") << false; |
|
410 | QTest::newRow("false") << false; | |
393 | } |
|
411 | } | |
394 |
|
412 | |||
395 | void tst_QXYSeries::pointsVisible_raw_data() |
|
413 | void tst_QXYSeries::pointsVisible_raw_data() | |
396 | { |
|
414 | { | |
397 | pointsVisible_data(); |
|
415 | pointsVisible_data(); | |
398 | } |
|
416 | } | |
399 |
|
417 | |||
400 | void tst_QXYSeries::pointsVisible_raw() |
|
418 | void tst_QXYSeries::pointsVisible_raw() | |
401 | { |
|
419 | { | |
402 | QFETCH(bool, pointsVisible); |
|
420 | QFETCH(bool, pointsVisible); | |
403 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); |
|
421 | QSignalSpy spy0(m_series, SIGNAL(clicked(QPointF const&))); | |
404 | m_series->setPointsVisible(pointsVisible); |
|
422 | m_series->setPointsVisible(pointsVisible); | |
405 | TRY_COMPARE(spy0.count(), 0); |
|
423 | TRY_COMPARE(spy0.count(), 0); | |
406 | QCOMPARE(m_series->pointsVisible(), pointsVisible); |
|
424 | QCOMPARE(m_series->pointsVisible(), pointsVisible); | |
407 | } |
|
425 | } | |
408 |
|
426 | |||
409 | void tst_QXYSeries::changedSignals() |
|
427 | void tst_QXYSeries::changedSignals() | |
410 | { |
|
428 | { | |
411 | QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); |
|
429 | QSignalSpy visibleSpy(m_series, SIGNAL(visibleChanged())); | |
412 | QSignalSpy nameSpy(m_series, SIGNAL(nameChanged())); |
|
430 | QSignalSpy nameSpy(m_series, SIGNAL(nameChanged())); | |
413 | QSignalSpy colorSpy(m_series, SIGNAL(colorChanged(QColor))); |
|
431 | QSignalSpy colorSpy(m_series, SIGNAL(colorChanged(QColor))); | |
414 |
|
432 | |||
415 | // Visibility |
|
433 | // Visibility | |
416 | m_series->setVisible(false); |
|
434 | m_series->setVisible(false); | |
417 | m_series->setVisible(false); |
|
435 | m_series->setVisible(false); | |
418 | TRY_COMPARE(visibleSpy.count(), 1); |
|
436 | TRY_COMPARE(visibleSpy.count(), 1); | |
419 | m_series->setVisible(true); |
|
437 | m_series->setVisible(true); | |
420 | TRY_COMPARE(visibleSpy.count(), 2); |
|
438 | TRY_COMPARE(visibleSpy.count(), 2); | |
421 |
|
439 | |||
422 | // Color |
|
440 | // Color | |
423 | m_series->setColor(QColor("aliceblue")); |
|
441 | m_series->setColor(QColor("aliceblue")); | |
424 | TRY_COMPARE(colorSpy.count(), 1); |
|
442 | TRY_COMPARE(colorSpy.count(), 1); | |
425 |
|
443 | |||
426 | // Pen and Brush |
|
444 | // Pen and Brush | |
427 | QPen p = m_series->pen(); |
|
445 | QPen p = m_series->pen(); | |
428 | p.setColor("aquamarine"); |
|
446 | p.setColor("aquamarine"); | |
429 | m_series->setPen(p); |
|
447 | m_series->setPen(p); | |
430 | QBrush b = m_series->brush(); |
|
448 | QBrush b = m_series->brush(); | |
431 | b.setColor("beige"); |
|
449 | b.setColor("beige"); | |
432 | m_series->setBrush(b); |
|
450 | m_series->setBrush(b); | |
433 | TRY_COMPARE(colorSpy.count(), 2); |
|
451 | TRY_COMPARE(colorSpy.count(), 2); | |
434 |
|
452 | |||
435 | // Verify all the signals again, to make sure no extra signals were emitted |
|
453 | // Verify all the signals again, to make sure no extra signals were emitted | |
436 | TRY_COMPARE(visibleSpy.count(), 2); |
|
454 | TRY_COMPARE(visibleSpy.count(), 2); | |
437 | TRY_COMPARE(nameSpy.count(), 0); |
|
455 | TRY_COMPARE(nameSpy.count(), 0); | |
438 | TRY_COMPARE(colorSpy.count(), 2); |
|
456 | TRY_COMPARE(colorSpy.count(), 2); | |
439 | } |
|
457 | } |
@@ -1,93 +1,94 | |||||
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 TST_QXYSERIES_H |
|
21 | #ifndef TST_QXYSERIES_H | |
22 | #define TST_QXYSERIES_H |
|
22 | #define TST_QXYSERIES_H | |
23 |
|
23 | |||
24 | #include <QtTest/QtTest> |
|
24 | #include <QtTest/QtTest> | |
25 | #include <qxyseries.h> |
|
25 | #include <qxyseries.h> | |
26 | #include <qchartview.h> |
|
26 | #include <qchartview.h> | |
27 | #include <QStandardItemModel> |
|
27 | #include <QStandardItemModel> | |
28 | #include <tst_definitions.h> |
|
28 | #include <tst_definitions.h> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | class tst_QXYSeries : public QObject |
|
32 | class tst_QXYSeries : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 |
|
35 | |||
36 | public slots: |
|
36 | public slots: | |
37 | virtual void initTestCase(); |
|
37 | virtual void initTestCase(); | |
38 | virtual void cleanupTestCase(); |
|
38 | virtual void cleanupTestCase(); | |
39 | virtual void init(); |
|
39 | virtual void init(); | |
40 | virtual void cleanup(); |
|
40 | virtual void cleanup(); | |
41 |
|
41 | |||
42 | private slots: |
|
42 | private slots: | |
43 | void seriesName(); |
|
43 | void seriesName(); | |
44 | void seriesVisible(); |
|
44 | void seriesVisible(); | |
|
45 | void seriesOpacity(); | |||
45 | void oper_data(); |
|
46 | void oper_data(); | |
46 | void oper(); |
|
47 | void oper(); | |
47 | void pen_data(); |
|
48 | void pen_data(); | |
48 | void pen(); |
|
49 | void pen(); | |
49 | void pointsVisible_raw_data(); |
|
50 | void pointsVisible_raw_data(); | |
50 | void pointsVisible_raw(); |
|
51 | void pointsVisible_raw(); | |
51 | void append_raw_data(); |
|
52 | void append_raw_data(); | |
52 | void append_raw(); |
|
53 | void append_raw(); | |
53 | void append_chart_data(); |
|
54 | void append_chart_data(); | |
54 | void append_chart(); |
|
55 | void append_chart(); | |
55 | void append_chart_animation_data(); |
|
56 | void append_chart_animation_data(); | |
56 | void append_chart_animation(); |
|
57 | void append_chart_animation(); | |
57 | void chart_append_data(); |
|
58 | void chart_append_data(); | |
58 | void chart_append(); |
|
59 | void chart_append(); | |
59 | void count_raw_data(); |
|
60 | void count_raw_data(); | |
60 | void count_raw(); |
|
61 | void count_raw(); | |
61 | void remove_raw_data(); |
|
62 | void remove_raw_data(); | |
62 | void remove_raw(); |
|
63 | void remove_raw(); | |
63 | void remove_chart_data(); |
|
64 | void remove_chart_data(); | |
64 | void remove_chart(); |
|
65 | void remove_chart(); | |
65 | void remove_chart_animation_data(); |
|
66 | void remove_chart_animation_data(); | |
66 | void remove_chart_animation(); |
|
67 | void remove_chart_animation(); | |
67 | void clear_raw_data(); |
|
68 | void clear_raw_data(); | |
68 | void clear_raw(); |
|
69 | void clear_raw(); | |
69 | void clear_chart_data(); |
|
70 | void clear_chart_data(); | |
70 | void clear_chart(); |
|
71 | void clear_chart(); | |
71 | void clear_chart_animation_data(); |
|
72 | void clear_chart_animation_data(); | |
72 | void clear_chart_animation(); |
|
73 | void clear_chart_animation(); | |
73 | void replace_raw_data(); |
|
74 | void replace_raw_data(); | |
74 | void replace_raw(); |
|
75 | void replace_raw(); | |
75 | void replace_chart_data(); |
|
76 | void replace_chart_data(); | |
76 | void replace_chart(); |
|
77 | void replace_chart(); | |
77 | void replace_chart_animation_data(); |
|
78 | void replace_chart_animation_data(); | |
78 | void replace_chart_animation(); |
|
79 | void replace_chart_animation(); | |
79 | void insert_data(); |
|
80 | void insert_data(); | |
80 | void insert(); |
|
81 | void insert(); | |
81 | void changedSignals(); |
|
82 | void changedSignals(); | |
82 | protected: |
|
83 | protected: | |
83 | void append_data(); |
|
84 | void append_data(); | |
84 | void count_data(); |
|
85 | void count_data(); | |
85 | void pointsVisible_data(); |
|
86 | void pointsVisible_data(); | |
86 |
|
87 | |||
87 | protected: |
|
88 | protected: | |
88 | QChartView* m_view; |
|
89 | QChartView* m_view; | |
89 | QChart* m_chart; |
|
90 | QChart* m_chart; | |
90 | QXYSeries* m_series; |
|
91 | QXYSeries* m_series; | |
91 | }; |
|
92 | }; | |
92 |
|
93 | |||
93 | #endif |
|
94 | #endif |
@@ -1,99 +1,100 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "area series" |
|
25 | title: "area series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | animationOptions: ChartView.SeriesAnimations |
|
27 | animationOptions: ChartView.SeriesAnimations | |
28 |
|
28 | |||
29 | property variant series: areaSeries |
|
29 | property variant series: areaSeries | |
30 |
|
30 | |||
31 | AreaSeries { |
|
31 | AreaSeries { | |
32 | id: areaSeries |
|
32 | id: areaSeries | |
33 | name: "area 1" |
|
33 | name: "area 1" | |
34 |
|
34 | |||
35 | upperSeries: LineSeries { |
|
35 | upperSeries: LineSeries { | |
36 | XYPoint { x: 0; y: 1 } |
|
36 | XYPoint { x: 0; y: 1 } | |
37 | XYPoint { x: 1; y: 1 } |
|
37 | XYPoint { x: 1; y: 1 } | |
38 | XYPoint { x: 2; y: 3 } |
|
38 | XYPoint { x: 2; y: 3 } | |
39 | XYPoint { x: 3; y: 3 } |
|
39 | XYPoint { x: 3; y: 3 } | |
40 | XYPoint { x: 4; y: 2 } |
|
40 | XYPoint { x: 4; y: 2 } | |
41 | XYPoint { x: 5; y: 0 } |
|
41 | XYPoint { x: 5; y: 0 } | |
42 | XYPoint { x: 6; y: 2 } |
|
42 | XYPoint { x: 6; y: 2 } | |
43 | XYPoint { x: 7; y: 1 } |
|
43 | XYPoint { x: 7; y: 1 } | |
44 | XYPoint { x: 8; y: 2 } |
|
44 | XYPoint { x: 8; y: 2 } | |
45 | XYPoint { x: 9; y: 1 } |
|
45 | XYPoint { x: 9; y: 1 } | |
46 | XYPoint { x: 10; y: 3 } |
|
46 | XYPoint { x: 10; y: 3 } | |
47 | XYPoint { x: 11; y: 3 } |
|
47 | XYPoint { x: 11; y: 3 } | |
48 | } |
|
48 | } | |
49 | lowerSeries: LineSeries { |
|
49 | lowerSeries: LineSeries { | |
50 | XYPoint { x: 0; y: 0 } |
|
50 | XYPoint { x: 0; y: 0 } | |
51 | XYPoint { x: 1; y: 0 } |
|
51 | XYPoint { x: 1; y: 0 } | |
52 | XYPoint { x: 2; y: 0 } |
|
52 | XYPoint { x: 2; y: 0 } | |
53 | XYPoint { x: 3; y: 0 } |
|
53 | XYPoint { x: 3; y: 0 } | |
54 | XYPoint { x: 4; y: 0 } |
|
54 | XYPoint { x: 4; y: 0 } | |
55 | XYPoint { x: 5; y: 0 } |
|
55 | XYPoint { x: 5; y: 0 } | |
56 | XYPoint { x: 6; y: 0 } |
|
56 | XYPoint { x: 6; y: 0 } | |
57 | XYPoint { x: 7; y: 0 } |
|
57 | XYPoint { x: 7; y: 0 } | |
58 | XYPoint { x: 8; y: 0 } |
|
58 | XYPoint { x: 8; y: 0 } | |
59 | XYPoint { x: 9; y: 0 } |
|
59 | XYPoint { x: 9; y: 0 } | |
60 | XYPoint { x: 10; y: 0 } |
|
60 | XYPoint { x: 10; y: 0 } | |
61 | XYPoint { x: 11; y: 0 } |
|
61 | XYPoint { x: 11; y: 0 } | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | onNameChanged: console.log(name + ".onNameChanged: " + name); |
|
64 | onNameChanged: console.log(name + ".onNameChanged: " + name); | |
65 | onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); |
|
65 | onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); | |
|
66 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); | |||
66 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
67 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
67 | onSelected: console.log(name + ".onSelected"); |
|
68 | onSelected: console.log(name + ".onSelected"); | |
68 | onColorChanged: console.log(name + ".onColorChanged: " + color); |
|
69 | onColorChanged: console.log(name + ".onColorChanged: " + color); | |
69 | onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor); |
|
70 | onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor); | |
70 | onBorderWidthChanged: console.log(name + ".onBorderChanged: " + borderWidth); |
|
71 | onBorderWidthChanged: console.log(name + ".onBorderChanged: " + borderWidth); | |
71 | // onCountChanged: console.log(name + ".onCountChanged: " + count); |
|
72 | // onCountChanged: console.log(name + ".onCountChanged: " + count); | |
72 | } |
|
73 | } | |
73 |
|
74 | |||
74 | AreaSeries { |
|
75 | AreaSeries { | |
75 | name: "area 2" |
|
76 | name: "area 2" | |
76 |
|
77 | |||
77 | upperSeries: LineSeries { |
|
78 | upperSeries: LineSeries { | |
78 | XYPoint { x: 0; y: 0.5 } |
|
79 | XYPoint { x: 0; y: 0.5 } | |
79 | XYPoint { x: 1; y: 1.5 } |
|
80 | XYPoint { x: 1; y: 1.5 } | |
80 | XYPoint { x: 2; y: 0.3 } |
|
81 | XYPoint { x: 2; y: 0.3 } | |
81 | XYPoint { x: 3; y: 1.5 } |
|
82 | XYPoint { x: 3; y: 1.5 } | |
82 | XYPoint { x: 4; y: 0.1 } |
|
83 | XYPoint { x: 4; y: 0.1 } | |
83 | XYPoint { x: 5; y: 0.3 } |
|
84 | XYPoint { x: 5; y: 0.3 } | |
84 | XYPoint { x: 6; y: 1.2 } |
|
85 | XYPoint { x: 6; y: 1.2 } | |
85 | XYPoint { x: 7; y: 1.3 } |
|
86 | XYPoint { x: 7; y: 1.3 } | |
86 | XYPoint { x: 8; y: 0.2 } |
|
87 | XYPoint { x: 8; y: 0.2 } | |
87 | XYPoint { x: 9; y: 0.1 } |
|
88 | XYPoint { x: 9; y: 0.1 } | |
88 | XYPoint { x: 10; y: 3.2 } |
|
89 | XYPoint { x: 10; y: 3.2 } | |
89 | XYPoint { x: 11; y: 4.6 } |
|
90 | XYPoint { x: 11; y: 4.6 } | |
90 | } |
|
91 | } | |
91 |
|
92 | |||
92 | onNameChanged: console.log(name + ".onNameChanged: " + name); |
|
93 | onNameChanged: console.log(name + ".onNameChanged: " + name); | |
93 | onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); |
|
94 | onVisibleChanged: console.log(name + ".onVisibleChanged: " + visible); | |
94 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
95 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
95 | onSelected: console.log(name + ".onSelected"); |
|
96 | onSelected: console.log(name + ".onSelected"); | |
96 | onColorChanged: console.log(name + ".onColorChanged: " + color); |
|
97 | onColorChanged: console.log(name + ".onColorChanged: " + color); | |
97 | onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor); |
|
98 | onBorderColorChanged: console.log(name + ".onBorderColorChanged: " + borderColor); | |
98 | } |
|
99 | } | |
99 | } |
|
100 | } |
@@ -1,77 +1,85 | |||||
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 |
|
22 | |||
23 | Flow { |
|
23 | Flow { | |
24 | id: flow |
|
24 | id: flow | |
25 | spacing: 5 |
|
25 | spacing: 5 | |
26 | flow: Flow.TopToBottom |
|
26 | flow: Flow.TopToBottom | |
27 | property variant series |
|
27 | property variant series | |
28 |
|
28 | |||
29 | Button { |
|
29 | Button { | |
30 | text: "visible" |
|
30 | text: "visible" | |
31 | onClicked: series.visible = !series.visible; |
|
31 | onClicked: series.visible = !series.visible; | |
32 | } |
|
32 | } | |
33 | Button { |
|
33 | Button { | |
|
34 | text: "opacity +" | |||
|
35 | onClicked: series.opacity += 0.1; | |||
|
36 | } | |||
|
37 | Button { | |||
|
38 | text: "opacity -" | |||
|
39 | onClicked: series.opacity -= 0.1; | |||
|
40 | } | |||
|
41 | Button { | |||
34 | text: "color" |
|
42 | text: "color" | |
35 | onClicked: series.color = main.nextColor(); |
|
43 | onClicked: series.color = main.nextColor(); | |
36 | } |
|
44 | } | |
37 | Button { |
|
45 | Button { | |
38 | text: "borderColor" |
|
46 | text: "borderColor" | |
39 | onClicked: series.borderColor = main.nextColor(); |
|
47 | onClicked: series.borderColor = main.nextColor(); | |
40 | } |
|
48 | } | |
41 | Button { |
|
49 | Button { | |
42 | text: series != undefined ? "borderWidth + (" + series.borderWidth + ")" : "" |
|
50 | text: series != undefined ? "borderWidth + (" + series.borderWidth + ")" : "" | |
43 | onClicked: series.borderWidth += 0.5; |
|
51 | onClicked: series.borderWidth += 0.5; | |
44 | } |
|
52 | } | |
45 | Button { |
|
53 | Button { | |
46 | text: series != undefined ? "borderWidth - (" + series.borderWidth + ")" : "" |
|
54 | text: series != undefined ? "borderWidth - (" + series.borderWidth + ")" : "" | |
47 | onClicked: series.borderWidth -= 0.5; |
|
55 | onClicked: series.borderWidth -= 0.5; | |
48 | } |
|
56 | } | |
49 | Button { |
|
57 | Button { | |
50 | id: upperButton |
|
58 | id: upperButton | |
51 | text: "upper series" |
|
59 | text: "upper series" | |
52 | unpressedColor: "#79bd8f" |
|
60 | unpressedColor: "#79bd8f" | |
53 | onClicked: { |
|
61 | onClicked: { | |
54 | lineEditor.visible = true; |
|
62 | lineEditor.visible = true; | |
55 | color = "#00a388"; |
|
63 | color = "#00a388"; | |
56 | lowerButton.color = "#79bd8f"; |
|
64 | lowerButton.color = "#79bd8f"; | |
57 | lineEditor.series = series.upperSeries; |
|
65 | lineEditor.series = series.upperSeries; | |
58 | } |
|
66 | } | |
59 | } |
|
67 | } | |
60 | Button { |
|
68 | Button { | |
61 | id: lowerButton |
|
69 | id: lowerButton | |
62 | text: "lower series" |
|
70 | text: "lower series" | |
63 | unpressedColor: "#79bd8f" |
|
71 | unpressedColor: "#79bd8f" | |
64 | onClicked: { |
|
72 | onClicked: { | |
65 | lineEditor.visible = true; |
|
73 | lineEditor.visible = true; | |
66 | color = "#00a388"; |
|
74 | color = "#00a388"; | |
67 | upperButton.color = "#79bd8f"; |
|
75 | upperButton.color = "#79bd8f"; | |
68 | lineEditor.series = series.lowerSeries; |
|
76 | lineEditor.series = series.lowerSeries; | |
69 | } |
|
77 | } | |
70 | } |
|
78 | } | |
71 | LineEditor { |
|
79 | LineEditor { | |
72 | id: lineEditor |
|
80 | id: lineEditor | |
73 | visible: false |
|
81 | visible: false | |
74 | } |
|
82 | } | |
75 |
|
83 | |||
76 | onSeriesChanged: lineEditor.series = series.upperSeries; |
|
84 | onSeriesChanged: lineEditor.series = series.upperSeries; | |
77 | } |
|
85 | } |
@@ -1,64 +1,65 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "Bar series" |
|
25 | title: "Bar series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | theme: ChartView.ChartThemeLight |
|
27 | theme: ChartView.ChartThemeLight | |
28 | legend.alignment: Qt.AlignBottom |
|
28 | legend.alignment: Qt.AlignBottom | |
29 | animationOptions: ChartView.SeriesAnimations |
|
29 | animationOptions: ChartView.SeriesAnimations | |
30 |
|
30 | |||
31 | property variant series: mySeries |
|
31 | property variant series: mySeries | |
32 |
|
32 | |||
33 |
|
33 | |||
34 | BarSeries { |
|
34 | BarSeries { | |
35 | id: mySeries |
|
35 | id: mySeries | |
36 | name: "bar" |
|
36 | name: "bar" | |
37 | axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } |
|
37 | axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } | |
38 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] |
|
38 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] | |
39 | onClicked: console.log("barset.onClicked: " + index); |
|
39 | onClicked: console.log("barset.onClicked: " + index); | |
40 | onHovered: console.log("barset.onHovered: " + status); |
|
40 | onHovered: console.log("barset.onHovered: " + status); | |
41 | onPenChanged: console.log("barset.onPenChanged: " + pen); |
|
41 | onPenChanged: console.log("barset.onPenChanged: " + pen); | |
42 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); |
|
42 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); | |
43 | onLabelChanged: console.log("barset.onLabelChanged: " + label); |
|
43 | onLabelChanged: console.log("barset.onLabelChanged: " + label); | |
44 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); |
|
44 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); | |
45 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); |
|
45 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); | |
46 | onColorChanged: console.log("barset.onColorChanged: " + color); |
|
46 | onColorChanged: console.log("barset.onColorChanged: " + color); | |
47 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); |
|
47 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); | |
48 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); |
|
48 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); | |
49 | onCountChanged: console.log("barset.onCountChanged: " + count); |
|
49 | onCountChanged: console.log("barset.onCountChanged: " + count); | |
50 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); |
|
50 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); | |
51 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); |
|
51 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); | |
52 | onValueChanged: console.log("barset.onValuesChanged: " + index); |
|
52 | onValueChanged: console.log("barset.onValuesChanged: " + index); | |
53 | } |
|
53 | } | |
54 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } |
|
54 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } | |
55 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } |
|
55 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } | |
56 |
|
56 | |||
57 |
onNameChanged: console.log(" |
|
57 | onNameChanged: console.log("barSeries.onNameChanged: " + series.name); | |
58 |
onVisibleChanged: console.log(" |
|
58 | onVisibleChanged: console.log("barSeries.onVisibleChanged: " + series.visible); | |
59 |
on |
|
59 | onOpacityChanged: console.log("barSeries.onOpacityChanged: " + opacity); | |
60 |
on |
|
60 | onClicked: console.log("barSeries.onClicked: " + barset + " " + index); | |
61 | onLabelsVisibleChanged: console.log("groupedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); |
|
61 | onHovered: console.log("barSeries.onHovered: " + barset + " " + status); | |
62 |
on |
|
62 | onLabelsVisibleChanged: console.log("barSeries.onLabelsVisibleChanged: " + series.labelsVisible); | |
|
63 | onCountChanged: console.log("barSeries.onCountChanged: " + count); | |||
63 | } |
|
64 | } | |
64 | } |
|
65 | } |
@@ -1,178 +1,186 | |||||
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 |
|
22 | |||
23 | Row { |
|
23 | Row { | |
24 | anchors.fill: parent |
|
24 | anchors.fill: parent | |
25 | spacing: 5 |
|
25 | spacing: 5 | |
26 | property variant series |
|
26 | property variant series | |
27 |
|
27 | |||
28 | // buttons for selecting the edited object: series, barset or label |
|
28 | // buttons for selecting the edited object: series, barset or label | |
29 | Flow { |
|
29 | Flow { | |
30 | spacing: 5 |
|
30 | spacing: 5 | |
31 | flow: Flow.TopToBottom |
|
31 | flow: Flow.TopToBottom | |
32 | Button { |
|
32 | Button { | |
33 | id: seriesButton |
|
33 | id: seriesButton | |
34 | text: "series" |
|
34 | text: "series" | |
35 | unpressedColor: "#79bd8f" |
|
35 | unpressedColor: "#79bd8f" | |
36 | onClicked: { |
|
36 | onClicked: { | |
37 | seriesFlow.visible = true; |
|
37 | seriesFlow.visible = true; | |
38 | setFlow.visible = false; |
|
38 | setFlow.visible = false; | |
39 | labelsFlow.visible = false; |
|
39 | labelsFlow.visible = false; | |
40 | color = "#00a388"; |
|
40 | color = "#00a388"; | |
41 | sliceButton.color = "#79bd8f"; |
|
41 | sliceButton.color = "#79bd8f"; | |
42 | labelButton.color = "#79bd8f"; |
|
42 | labelButton.color = "#79bd8f"; | |
43 | } |
|
43 | } | |
44 | } |
|
44 | } | |
45 | Button { |
|
45 | Button { | |
46 | id: setButton |
|
46 | id: setButton | |
47 | text: "BarSet" |
|
47 | text: "BarSet" | |
48 | unpressedColor: "#79bd8f" |
|
48 | unpressedColor: "#79bd8f" | |
49 | onClicked: { |
|
49 | onClicked: { | |
50 | seriesFlow.visible = false; |
|
50 | seriesFlow.visible = false; | |
51 | setFlow.visible = true; |
|
51 | setFlow.visible = true; | |
52 | labelsFlow.visible = false; |
|
52 | labelsFlow.visible = false; | |
53 | color = "#00a388"; |
|
53 | color = "#00a388"; | |
54 | seriesButton.color = "#79bd8f"; |
|
54 | seriesButton.color = "#79bd8f"; | |
55 | labelButton.color = "#79bd8f"; |
|
55 | labelButton.color = "#79bd8f"; | |
56 | } |
|
56 | } | |
57 | } |
|
57 | } | |
58 | Button { |
|
58 | Button { | |
59 | id: labelButton |
|
59 | id: labelButton | |
60 | text: "label" |
|
60 | text: "label" | |
61 | unpressedColor: "#79bd8f" |
|
61 | unpressedColor: "#79bd8f" | |
62 | onClicked: { |
|
62 | onClicked: { | |
63 | seriesFlow.visible = false; |
|
63 | seriesFlow.visible = false; | |
64 | setFlow.visible = false; |
|
64 | setFlow.visible = false; | |
65 | labelsFlow.visible = true; |
|
65 | labelsFlow.visible = true; | |
66 | color = "#00a388"; |
|
66 | color = "#00a388"; | |
67 | seriesButton.color = "#79bd8f"; |
|
67 | seriesButton.color = "#79bd8f"; | |
68 | sliceButton.color = "#79bd8f"; |
|
68 | sliceButton.color = "#79bd8f"; | |
69 | } |
|
69 | } | |
70 | } |
|
70 | } | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | // Buttons for editing series |
|
73 | // Buttons for editing series | |
74 | Flow { |
|
74 | Flow { | |
75 | id: seriesFlow |
|
75 | id: seriesFlow | |
76 | spacing: 5 |
|
76 | spacing: 5 | |
77 | flow: Flow.TopToBottom |
|
77 | flow: Flow.TopToBottom | |
78 | visible: false |
|
78 | visible: false | |
79 |
|
79 | |||
80 | Button { |
|
80 | Button { | |
81 | text: "visible" |
|
81 | text: "visible" | |
82 | onClicked: series.visible = !series.visible; |
|
82 | onClicked: series.visible = !series.visible; | |
83 | } |
|
83 | } | |
84 | Button { |
|
84 | Button { | |
|
85 | text: "opacity +" | |||
|
86 | onClicked: series.opacity += 0.1; | |||
|
87 | } | |||
|
88 | Button { | |||
|
89 | text: "opacity -" | |||
|
90 | onClicked: series.opacity -= 0.1; | |||
|
91 | } | |||
|
92 | Button { | |||
85 | text: "bar width +" |
|
93 | text: "bar width +" | |
86 | onClicked: series.barWidth += 0.1; |
|
94 | onClicked: series.barWidth += 0.1; | |
87 | } |
|
95 | } | |
88 | Button { |
|
96 | Button { | |
89 | text: "bar width -" |
|
97 | text: "bar width -" | |
90 | onClicked: series.barWidth -= 0.1; |
|
98 | onClicked: series.barWidth -= 0.1; | |
91 | } |
|
99 | } | |
92 | } |
|
100 | } | |
93 |
|
101 | |||
94 | // Buttons for editing sets |
|
102 | // Buttons for editing sets | |
95 | Flow { |
|
103 | Flow { | |
96 | id: setFlow |
|
104 | id: setFlow | |
97 | spacing: 5 |
|
105 | spacing: 5 | |
98 | flow: Flow.TopToBottom |
|
106 | flow: Flow.TopToBottom | |
99 | visible: false |
|
107 | visible: false | |
100 |
|
108 | |||
101 | Button { |
|
109 | Button { | |
102 | text: "append set" |
|
110 | text: "append set" | |
103 | onClicked: { |
|
111 | onClicked: { | |
104 | var count = series.count; |
|
112 | var count = series.count; | |
105 | series.append("set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); |
|
113 | series.append("set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); | |
106 | } |
|
114 | } | |
107 | } |
|
115 | } | |
108 | Button { |
|
116 | Button { | |
109 | text: "insert set" |
|
117 | text: "insert set" | |
110 | onClicked: { |
|
118 | onClicked: { | |
111 | var count = series.count; |
|
119 | var count = series.count; | |
112 | series.insert(count - 1, "set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); |
|
120 | series.insert(count - 1, "set" + count, [0, 0.1 * count, 0.2 * count, 0.3 * count, 0.4 * count, 0.5 * count, 0.6 * count]); | |
113 | } |
|
121 | } | |
114 | } |
|
122 | } | |
115 | Button { |
|
123 | Button { | |
116 | text: "remove set" |
|
124 | text: "remove set" | |
117 | onClicked: series.remove(series.at(series.count - 1)); |
|
125 | onClicked: series.remove(series.at(series.count - 1)); | |
118 | } |
|
126 | } | |
119 | Button { |
|
127 | Button { | |
120 | text: "clear sets" |
|
128 | text: "clear sets" | |
121 | onClicked: series.clear(); |
|
129 | onClicked: series.clear(); | |
122 | } |
|
130 | } | |
123 |
|
131 | |||
124 | Button { |
|
132 | Button { | |
125 | text: "set 1 append" |
|
133 | text: "set 1 append" | |
126 | onClicked: series.at(0).append(series.at(0).count + 1); |
|
134 | onClicked: series.at(0).append(series.at(0).count + 1); | |
127 | } |
|
135 | } | |
128 | Button { |
|
136 | Button { | |
129 | text: "set 1 replace" |
|
137 | text: "set 1 replace" | |
130 | onClicked: series.at(0).replace(series.at(0).count - 1, series.at(0).at(series.at(0).count - 1) + 1.5); |
|
138 | onClicked: series.at(0).replace(series.at(0).count - 1, series.at(0).at(series.at(0).count - 1) + 1.5); | |
131 | } |
|
139 | } | |
132 | Button { |
|
140 | Button { | |
133 | text: "set 1 remove" |
|
141 | text: "set 1 remove" | |
134 | onClicked: series.at(0).remove(series.at(0).count - 1); |
|
142 | onClicked: series.at(0).remove(series.at(0).count - 1); | |
135 | } |
|
143 | } | |
136 |
|
144 | |||
137 | Button { |
|
145 | Button { | |
138 | text: "set 1 color" |
|
146 | text: "set 1 color" | |
139 | onClicked: series.at(0).color = main.nextColor(); |
|
147 | onClicked: series.at(0).color = main.nextColor(); | |
140 | } |
|
148 | } | |
141 | Button { |
|
149 | Button { | |
142 | text: "set 1 border color" |
|
150 | text: "set 1 border color" | |
143 | onClicked: series.at(0).borderColor = main.nextColor(); |
|
151 | onClicked: series.at(0).borderColor = main.nextColor(); | |
144 | } |
|
152 | } | |
145 | Button { |
|
153 | Button { | |
146 | text: "set 1 borderWidth +" |
|
154 | text: "set 1 borderWidth +" | |
147 | onClicked: series.at(0).borderWidth += 0.5; |
|
155 | onClicked: series.at(0).borderWidth += 0.5; | |
148 | } |
|
156 | } | |
149 | Button { |
|
157 | Button { | |
150 | text: "set 1 borderWidth -" |
|
158 | text: "set 1 borderWidth -" | |
151 | onClicked: series.at(0).borderWidth -= 0.5; |
|
159 | onClicked: series.at(0).borderWidth -= 0.5; | |
152 | } |
|
160 | } | |
153 | } |
|
161 | } | |
154 |
|
162 | |||
155 |
|
163 | |||
156 | Flow { |
|
164 | Flow { | |
157 | id: labelsFlow |
|
165 | id: labelsFlow | |
158 | spacing: 5 |
|
166 | spacing: 5 | |
159 | flow: Flow.TopToBottom |
|
167 | flow: Flow.TopToBottom | |
160 | visible: false |
|
168 | visible: false | |
161 |
|
169 | |||
162 | Button { |
|
170 | Button { | |
163 | text: "labels visible" |
|
171 | text: "labels visible" | |
164 | onClicked: series.labelsVisible = !series.labelsVisible; |
|
172 | onClicked: series.labelsVisible = !series.labelsVisible; | |
165 | } |
|
173 | } | |
166 | Button { |
|
174 | Button { | |
167 | text: "set 1 label color" |
|
175 | text: "set 1 label color" | |
168 | onClicked: series.at(0).labelColor = main.nextColor(); |
|
176 | onClicked: series.at(0).labelColor = main.nextColor(); | |
169 | } |
|
177 | } | |
170 | FontEditor { |
|
178 | FontEditor { | |
171 | id: fontEditor |
|
179 | id: fontEditor | |
172 | fontDescription: "label" |
|
180 | fontDescription: "label" | |
173 | function editedFont() { |
|
181 | function editedFont() { | |
174 | return series.at(0).labelFont; |
|
182 | return series.at(0).labelFont; | |
175 | } |
|
183 | } | |
176 | } |
|
184 | } | |
177 | } |
|
185 | } | |
178 | } |
|
186 | } |
@@ -1,63 +1,64 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "Bar series" |
|
25 | title: "Bar series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | theme: ChartView.ChartThemeLight |
|
27 | theme: ChartView.ChartThemeLight | |
28 | legend.alignment: Qt.AlignBottom |
|
28 | legend.alignment: Qt.AlignBottom | |
29 | animationOptions: ChartView.SeriesAnimations |
|
29 | animationOptions: ChartView.SeriesAnimations | |
30 |
|
30 | |||
31 | property variant series: mySeries |
|
31 | property variant series: mySeries | |
32 |
|
32 | |||
33 | HorizontalBarSeries { |
|
33 | HorizontalBarSeries { | |
34 | id: mySeries |
|
34 | id: mySeries | |
35 | name: "bar" |
|
35 | name: "bar" | |
36 | axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } |
|
36 | axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } | |
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] |
|
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] | |
38 | onClicked: console.log("barset.onClicked: " + index); |
|
38 | onClicked: console.log("barset.onClicked: " + index); | |
39 | onHovered: console.log("barset.onHovered: " + status); |
|
39 | onHovered: console.log("barset.onHovered: " + status); | |
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); |
|
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); | |
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); |
|
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); | |
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); |
|
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); | |
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); |
|
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); | |
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); |
|
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); | |
45 | onColorChanged: console.log("barset.onColorChanged: " + color); |
|
45 | onColorChanged: console.log("barset.onColorChanged: " + color); | |
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); |
|
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); | |
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); |
|
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); | |
48 | onCountChanged: console.log("barset.onCountChanged: " + count); |
|
48 | onCountChanged: console.log("barset.onCountChanged: " + count); | |
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); |
|
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); | |
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); |
|
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); | |
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); |
|
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); | |
52 | } |
|
52 | } | |
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } |
|
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } | |
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } |
|
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } | |
55 |
|
55 | |||
56 |
onNameChanged: console.log(" |
|
56 | onNameChanged: console.log("horizontalBarSeries.onNameChanged: " + series.name); | |
57 |
onVisibleChanged: console.log(" |
|
57 | onVisibleChanged: console.log("horizontalBarSeries.onVisibleChanged: " + series.visible); | |
58 |
on |
|
58 | onOpacityChanged: console.log("horizontalBarSeries.onOpacityChanged: " + opacity); | |
59 |
on |
|
59 | onClicked: console.log("horizontalBarSeries.onClicked: " + barset + " " + index); | |
60 | onLabelsVisibleChanged: console.log("groupedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); |
|
60 | onHovered: console.log("horizontalBarSeries.onHovered: " + barset + " " + status); | |
61 |
on |
|
61 | onLabelsVisibleChanged: console.log("horizontalBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); | |
|
62 | onCountChanged: console.log("horizontalBarSeries.onCountChanged: " + count); | |||
62 | } |
|
63 | } | |
63 | } |
|
64 | } |
@@ -1,63 +1,64 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "Percent bar series" |
|
25 | title: "Percent bar series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | theme: ChartView.ChartThemeLight |
|
27 | theme: ChartView.ChartThemeLight | |
28 | legend.alignment: Qt.AlignBottom |
|
28 | legend.alignment: Qt.AlignBottom | |
29 | animationOptions: ChartView.SeriesAnimations |
|
29 | animationOptions: ChartView.SeriesAnimations | |
30 |
|
30 | |||
31 | property variant series: mySeries |
|
31 | property variant series: mySeries | |
32 |
|
32 | |||
33 | HorizontalPercentBarSeries { |
|
33 | HorizontalPercentBarSeries { | |
34 | id: mySeries |
|
34 | id: mySeries | |
35 | name: "bar" |
|
35 | name: "bar" | |
36 | axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } |
|
36 | axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } | |
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] |
|
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] | |
38 | onClicked: console.log("barset.onClicked: " + index); |
|
38 | onClicked: console.log("barset.onClicked: " + index); | |
39 | onHovered: console.log("barset.onHovered: " + status); |
|
39 | onHovered: console.log("barset.onHovered: " + status); | |
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); |
|
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); | |
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); |
|
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); | |
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); |
|
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); | |
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); |
|
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); | |
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); |
|
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); | |
45 | onColorChanged: console.log("barset.onColorChanged: " + color); |
|
45 | onColorChanged: console.log("barset.onColorChanged: " + color); | |
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); |
|
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); | |
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); |
|
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); | |
48 | onCountChanged: console.log("barset.onCountChanged: " + count); |
|
48 | onCountChanged: console.log("barset.onCountChanged: " + count); | |
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); |
|
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); | |
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); |
|
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); | |
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); |
|
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); | |
52 | } |
|
52 | } | |
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } |
|
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } | |
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } |
|
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } | |
55 |
|
55 | |||
56 |
onNameChanged: console.log(" |
|
56 | onNameChanged: console.log("horizontalPercentBarSeries.onNameChanged: " + series.name); | |
57 |
onVisibleChanged: console.log(" |
|
57 | onVisibleChanged: console.log("horizontalPercentBarSeries.onVisibleChanged: " + series.visible); | |
58 |
on |
|
58 | onOpacityChanged: console.log("horizontalPercentBarSeries.onOpacityChanged: " + opacity); | |
59 |
on |
|
59 | onClicked: console.log("horizontalPercentBarSeries.onClicked: " + barset + " " + index); | |
60 | onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); |
|
60 | onHovered: console.log("horizontalPercentBarSeries.onHovered: " + barset + " " + status); | |
61 |
on |
|
61 | onLabelsVisibleChanged: console.log("horizontalPercentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); | |
|
62 | onCountChanged: console.log("horizontalPercentBarSeries.onCountChanged: " + count); | |||
62 | } |
|
63 | } | |
63 | } |
|
64 | } |
@@ -1,63 +1,64 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "Stacked bar series" |
|
25 | title: "Stacked bar series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | theme: ChartView.ChartThemeLight |
|
27 | theme: ChartView.ChartThemeLight | |
28 | legend.alignment: Qt.AlignBottom |
|
28 | legend.alignment: Qt.AlignBottom | |
29 | animationOptions: ChartView.SeriesAnimations |
|
29 | animationOptions: ChartView.SeriesAnimations | |
30 |
|
30 | |||
31 | property variant series: mySeries |
|
31 | property variant series: mySeries | |
32 |
|
32 | |||
33 | HorizontalStackedBarSeries { |
|
33 | HorizontalStackedBarSeries { | |
34 | id: mySeries |
|
34 | id: mySeries | |
35 | name: "bar" |
|
35 | name: "bar" | |
36 | axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } |
|
36 | axisY: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } | |
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] |
|
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] | |
38 | onClicked: console.log("barset.onClicked: " + index); |
|
38 | onClicked: console.log("barset.onClicked: " + index); | |
39 | onHovered: console.log("barset.onHovered: " + status); |
|
39 | onHovered: console.log("barset.onHovered: " + status); | |
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); |
|
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); | |
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); |
|
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); | |
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); |
|
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); | |
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); |
|
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); | |
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); |
|
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); | |
45 | onColorChanged: console.log("barset.onColorChanged: " + color); |
|
45 | onColorChanged: console.log("barset.onColorChanged: " + color); | |
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); |
|
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); | |
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); |
|
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); | |
48 | onCountChanged: console.log("barset.onCountChanged: " + count); |
|
48 | onCountChanged: console.log("barset.onCountChanged: " + count); | |
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); |
|
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); | |
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); |
|
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); | |
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); |
|
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); | |
52 | } |
|
52 | } | |
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } |
|
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } | |
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } |
|
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } | |
55 |
|
55 | |||
56 |
onNameChanged: console.log(" |
|
56 | onNameChanged: console.log("horizontalStackedBarSeries.onNameChanged: " + series.name); | |
57 |
onVisibleChanged: console.log(" |
|
57 | onVisibleChanged: console.log("horizontalStackedBarSeries.onVisibleChanged: " + series.visible); | |
58 |
on |
|
58 | onOpacityChanged: console.log("horizontalStackedBarSeries.onOpacityChanged: " + opacity); | |
59 |
on |
|
59 | onClicked: console.log("horizontalStackedBarSeries.onClicked: " + barset + " " + index); | |
60 | onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); |
|
60 | onHovered: console.log("horizontalStackedBarSeries.onHovered: " + barset + " " + status); | |
61 |
on |
|
61 | onLabelsVisibleChanged: console.log("horizontalStackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); | |
|
62 | onCountChanged: console.log("horizontalStackedBarSeries.onCountChanged: " + count); | |||
62 | } |
|
63 | } | |
63 | } |
|
64 | } |
@@ -1,65 +1,66 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | property variant series: lineSeries |
|
25 | property variant series: lineSeries | |
26 |
|
26 | |||
27 | title: "line series" |
|
27 | title: "line series" | |
28 | anchors.fill: parent |
|
28 | anchors.fill: parent | |
29 | animationOptions: ChartView.SeriesAnimations |
|
29 | animationOptions: ChartView.SeriesAnimations | |
30 |
|
30 | |||
31 | LineSeries { |
|
31 | LineSeries { | |
32 | id: lineSeries |
|
32 | id: lineSeries | |
33 | name: "line 1" |
|
33 | name: "line 1" | |
34 | XYPoint { x: 0; y: 0 } |
|
34 | XYPoint { x: 0; y: 0 } | |
35 | XYPoint { x: 1.1; y: 2.1 } |
|
35 | XYPoint { x: 1.1; y: 2.1 } | |
36 | XYPoint { x: 1.9; y: 3.3 } |
|
36 | XYPoint { x: 1.9; y: 3.3 } | |
37 | XYPoint { x: 2.1; y: 2.1 } |
|
37 | XYPoint { x: 2.1; y: 2.1 } | |
38 | XYPoint { x: 2.9; y: 4.9 } |
|
38 | XYPoint { x: 2.9; y: 4.9 } | |
39 | XYPoint { x: 3.4; y: 3.0 } |
|
39 | XYPoint { x: 3.4; y: 3.0 } | |
40 | XYPoint { x: 4.1; y: 3.3 } |
|
40 | XYPoint { x: 4.1; y: 3.3 } | |
41 |
|
41 | |||
42 | onNameChanged: console.log("lineSeries.onNameChanged: " + name); |
|
42 | onNameChanged: console.log("lineSeries.onNameChanged: " + name); | |
43 | onVisibleChanged: console.log("lineSeries.onVisibleChanged: " + visible); |
|
43 | onVisibleChanged: console.log("lineSeries.onVisibleChanged: " + visible); | |
|
44 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); | |||
44 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
45 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
45 | onPointReplaced: console.log("lineSeries.onPointReplaced: " + index); |
|
46 | onPointReplaced: console.log("lineSeries.onPointReplaced: " + index); | |
46 | onPointRemoved: console.log("lineSeries.onPointRemoved: " + index); |
|
47 | onPointRemoved: console.log("lineSeries.onPointRemoved: " + index); | |
47 | onPointAdded: console.log("lineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); |
|
48 | onPointAdded: console.log("lineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); | |
48 | onColorChanged: console.log("lineSeries.onColorChanged: " + color); |
|
49 | onColorChanged: console.log("lineSeries.onColorChanged: " + color); | |
49 | onWidthChanged: console.log("lineSeries.onWidthChanged: " + width); |
|
50 | onWidthChanged: console.log("lineSeries.onWidthChanged: " + width); | |
50 | onStyleChanged: console.log("lineSeries.onStyleChanged: " + style); |
|
51 | onStyleChanged: console.log("lineSeries.onStyleChanged: " + style); | |
51 | onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle); |
|
52 | onCapStyleChanged: console.log("lineSeries.onCapStyleChanged: " + capStyle); | |
52 | onCountChanged: console.log("lineSeries.onCountChanged: " + count); |
|
53 | onCountChanged: console.log("lineSeries.onCountChanged: " + count); | |
53 | } |
|
54 | } | |
54 |
|
55 | |||
55 | LineSeries { |
|
56 | LineSeries { | |
56 | name: "line 2" |
|
57 | name: "line 2" | |
57 | XYPoint { x: 1.1; y: 1.1 } |
|
58 | XYPoint { x: 1.1; y: 1.1 } | |
58 | XYPoint { x: 1.9; y: 2.3 } |
|
59 | XYPoint { x: 1.9; y: 2.3 } | |
59 | XYPoint { x: 2.1; y: 1.1 } |
|
60 | XYPoint { x: 2.1; y: 1.1 } | |
60 | XYPoint { x: 2.9; y: 3.9 } |
|
61 | XYPoint { x: 2.9; y: 3.9 } | |
61 | XYPoint { x: 3.4; y: 2.0 } |
|
62 | XYPoint { x: 3.4; y: 2.0 } | |
62 | XYPoint { x: 4.1; y: 2.3 } |
|
63 | XYPoint { x: 4.1; y: 2.3 } | |
63 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
64 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
64 | } |
|
65 | } | |
65 | } |
|
66 | } |
@@ -1,89 +1,97 | |||||
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 |
|
22 | |||
23 |
|
23 | |||
24 | Flow { |
|
24 | Flow { | |
25 | id: flow |
|
25 | id: flow | |
26 | spacing: 5 |
|
26 | spacing: 5 | |
27 | flow: Flow.TopToBottom |
|
27 | flow: Flow.TopToBottom | |
28 | property variant series |
|
28 | property variant series | |
29 |
|
29 | |||
30 | Button { |
|
30 | Button { | |
31 | text: "visible" |
|
31 | text: "visible" | |
32 | onClicked: series.visible = !series.visible; |
|
32 | onClicked: series.visible = !series.visible; | |
33 | } |
|
33 | } | |
34 | Button { |
|
34 | Button { | |
|
35 | text: "opacity +" | |||
|
36 | onClicked: series.opacity += 0.1; | |||
|
37 | } | |||
|
38 | Button { | |||
|
39 | text: "opacity -" | |||
|
40 | onClicked: series.opacity -= 0.1; | |||
|
41 | } | |||
|
42 | Button { | |||
35 | text: "color" |
|
43 | text: "color" | |
36 | onClicked: series.color = main.nextColor(); |
|
44 | onClicked: series.color = main.nextColor(); | |
37 | } |
|
45 | } | |
38 | Button { |
|
46 | Button { | |
39 | text: series != undefined ? "width + (" + series.width + ")" : "" |
|
47 | text: series != undefined ? "width + (" + series.width + ")" : "" | |
40 | onClicked: series.width += 0.5; |
|
48 | onClicked: series.width += 0.5; | |
41 | } |
|
49 | } | |
42 | Button { |
|
50 | Button { | |
43 | text: series != undefined ? "width - (" + series.width + ")" : "" |
|
51 | text: series != undefined ? "width - (" + series.width + ")" : "" | |
44 | onClicked: series.width -= 0.5; |
|
52 | onClicked: series.width -= 0.5; | |
45 | } |
|
53 | } | |
46 | Button { |
|
54 | Button { | |
47 | text: series != undefined ? "style + (" + series.style + ")" : "" |
|
55 | text: series != undefined ? "style + (" + series.style + ")" : "" | |
48 | onClicked: series.style++; |
|
56 | onClicked: series.style++; | |
49 | } |
|
57 | } | |
50 | Button { |
|
58 | Button { | |
51 | text: series != undefined ? "style - (" + series.style + ")" : "" |
|
59 | text: series != undefined ? "style - (" + series.style + ")" : "" | |
52 | onClicked: series.style--; |
|
60 | onClicked: series.style--; | |
53 | } |
|
61 | } | |
54 | Button { |
|
62 | Button { | |
55 | text: series != undefined ? "cap style + (" + series.capStyle + ")" : "" |
|
63 | text: series != undefined ? "cap style + (" + series.capStyle + ")" : "" | |
56 | onClicked: series.capStyle++; |
|
64 | onClicked: series.capStyle++; | |
57 | } |
|
65 | } | |
58 | Button { |
|
66 | Button { | |
59 | text: series != undefined ? "cap style - (" +series.capStyle + ")" : "" |
|
67 | text: series != undefined ? "cap style - (" +series.capStyle + ")" : "" | |
60 | onClicked: series.capStyle--; |
|
68 | onClicked: series.capStyle--; | |
61 | } |
|
69 | } | |
62 | Button { |
|
70 | Button { | |
63 | text: "points visible" |
|
71 | text: "points visible" | |
64 | onClicked: series.pointsVisible = !series.pointsVisible; |
|
72 | onClicked: series.pointsVisible = !series.pointsVisible; | |
65 | } |
|
73 | } | |
66 | Button { |
|
74 | Button { | |
67 | text: "append point" |
|
75 | text: "append point" | |
68 | onClicked: series.append(series.count - 1, series.count - 1); |
|
76 | onClicked: series.append(series.count - 1, series.count - 1); | |
69 | } |
|
77 | } | |
70 | Button { |
|
78 | Button { | |
71 | text: "replace point" |
|
79 | text: "replace point" | |
72 | onClicked: { |
|
80 | onClicked: { | |
73 | var xyPoint = series.at(series.count - 1); |
|
81 | var xyPoint = series.at(series.count - 1); | |
74 | series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); |
|
82 | series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); | |
75 | } |
|
83 | } | |
76 | } |
|
84 | } | |
77 | Button { |
|
85 | Button { | |
78 | text: "remove point" |
|
86 | text: "remove point" | |
79 | onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); |
|
87 | onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); | |
80 | } |
|
88 | } | |
81 | Button { |
|
89 | Button { | |
82 | text: "insert point" |
|
90 | text: "insert point" | |
83 | onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); |
|
91 | onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); | |
84 | } |
|
92 | } | |
85 | Button { |
|
93 | Button { | |
86 | text: "clear" |
|
94 | text: "clear" | |
87 | onClicked: series.clear(); |
|
95 | onClicked: series.clear(); | |
88 | } |
|
96 | } | |
89 | } |
|
97 | } |
@@ -1,64 +1,65 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "Percent bar series" |
|
25 | title: "Percent bar series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | theme: ChartView.ChartThemeLight |
|
27 | theme: ChartView.ChartThemeLight | |
28 | legend.alignment: Qt.AlignBottom |
|
28 | legend.alignment: Qt.AlignBottom | |
29 | animationOptions: ChartView.SeriesAnimations |
|
29 | animationOptions: ChartView.SeriesAnimations | |
30 |
|
30 | |||
31 | property variant series: mySeries |
|
31 | property variant series: mySeries | |
32 |
|
32 | |||
33 | PercentBarSeries { |
|
33 | PercentBarSeries { | |
34 | id: mySeries |
|
34 | id: mySeries | |
35 | name: "bar" |
|
35 | name: "bar" | |
36 | axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } |
|
36 | axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } | |
37 |
|
37 | |||
38 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] |
|
38 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] | |
39 | onClicked: console.log("barset.onClicked: " + index); |
|
39 | onClicked: console.log("barset.onClicked: " + index); | |
40 | onHovered: console.log("barset.onHovered: " + status); |
|
40 | onHovered: console.log("barset.onHovered: " + status); | |
41 | onPenChanged: console.log("barset.onPenChanged: " + pen); |
|
41 | onPenChanged: console.log("barset.onPenChanged: " + pen); | |
42 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); |
|
42 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); | |
43 | onLabelChanged: console.log("barset.onLabelChanged: " + label); |
|
43 | onLabelChanged: console.log("barset.onLabelChanged: " + label); | |
44 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); |
|
44 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); | |
45 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); |
|
45 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); | |
46 | onColorChanged: console.log("barset.onColorChanged: " + color); |
|
46 | onColorChanged: console.log("barset.onColorChanged: " + color); | |
47 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); |
|
47 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); | |
48 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); |
|
48 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); | |
49 | onCountChanged: console.log("barset.onCountChanged: " + count); |
|
49 | onCountChanged: console.log("barset.onCountChanged: " + count); | |
50 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); |
|
50 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); | |
51 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); |
|
51 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); | |
52 | onValueChanged: console.log("barset.onValuesChanged: " + index); |
|
52 | onValueChanged: console.log("barset.onValuesChanged: " + index); | |
53 | } |
|
53 | } | |
54 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } |
|
54 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } | |
55 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } |
|
55 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } | |
56 |
|
56 | |||
57 | onNameChanged: console.log("percentBarSeries.onNameChanged: " + series.name); |
|
57 | onNameChanged: console.log("percentBarSeries.onNameChanged: " + series.name); | |
58 | onVisibleChanged: console.log("percentBarSeries.onVisibleChanged: " + series.visible); |
|
58 | onVisibleChanged: console.log("percentBarSeries.onVisibleChanged: " + series.visible); | |
|
59 | onOpacityChanged: console.log("percentBarSeries.onOpacityChanged: " + opacity); | |||
59 | onClicked: console.log("percentBarSeries.onClicked: " + barset + " " + index); |
|
60 | onClicked: console.log("percentBarSeries.onClicked: " + barset + " " + index); | |
60 | onHovered: console.log("percentBarSeries.onHovered: " + barset + " " + status); |
|
61 | onHovered: console.log("percentBarSeries.onHovered: " + barset + " " + status); | |
61 | onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); |
|
62 | onLabelsVisibleChanged: console.log("percentBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); | |
62 | onCountChanged: console.log("percentBarSeries.onCountChanged: " + count); |
|
63 | onCountChanged: console.log("percentBarSeries.onCountChanged: " + count); | |
63 | } |
|
64 | } | |
64 | } |
|
65 | } |
@@ -1,66 +1,67 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | id: chart |
|
25 | id: chart | |
26 | title: "pie series" |
|
26 | title: "pie series" | |
27 | animationOptions: ChartView.SeriesAnimations |
|
27 | animationOptions: ChartView.SeriesAnimations | |
28 |
|
28 | |||
29 | property variant series: pieSeries |
|
29 | property variant series: pieSeries | |
30 |
|
30 | |||
31 | PieSeries { |
|
31 | PieSeries { | |
32 | id: pieSeries |
|
32 | id: pieSeries | |
33 | name: "pie" |
|
33 | name: "pie" | |
34 | PieSlice { label: "slice1"; value: 11; |
|
34 | PieSlice { label: "slice1"; value: 11; | |
35 | onValueChanged: console.log("slice.onValueChanged: " + value); |
|
35 | onValueChanged: console.log("slice.onValueChanged: " + value); | |
36 | onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + labelVisible); |
|
36 | onLabelVisibleChanged: console.log("slice.onLabelVisibleChanged: " + labelVisible); | |
37 | onPenChanged: console.log("slice.onPenChanged: " + pen); |
|
37 | onPenChanged: console.log("slice.onPenChanged: " + pen); | |
38 | onBorderColorChanged: console.log("slice.onBorderColorChanged: " + borderColor); |
|
38 | onBorderColorChanged: console.log("slice.onBorderColorChanged: " + borderColor); | |
39 | onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + borderWidth); |
|
39 | onBorderWidthChanged: console.log("slice.onBorderWidthChanged: " + borderWidth); | |
40 | onBrushChanged: console.log("slice.onBrushChanged: " + brush); |
|
40 | onBrushChanged: console.log("slice.onBrushChanged: " + brush); | |
41 | onColorChanged: console.log("slice.onColorChanged: " + color); |
|
41 | onColorChanged: console.log("slice.onColorChanged: " + color); | |
42 | onLabelColorChanged: console.log("slice.onLabelColorChanged: " + labelColor); |
|
42 | onLabelColorChanged: console.log("slice.onLabelColorChanged: " + labelColor); | |
43 | onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + labelBrush); |
|
43 | onLabelBrushChanged: console.log("slice.onLabelBrushChanged: " + labelBrush); | |
44 | onLabelFontChanged: console.log("slice.onLabelFontChanged: " + labelFont); |
|
44 | onLabelFontChanged: console.log("slice.onLabelFontChanged: " + labelFont); | |
45 | onPercentageChanged: console.log("slice.onPercentageChanged: " + percentage); |
|
45 | onPercentageChanged: console.log("slice.onPercentageChanged: " + percentage); | |
46 | onStartAngleChanged: console.log("slice.onStartAngleChanged: " + startAngle); |
|
46 | onStartAngleChanged: console.log("slice.onStartAngleChanged: " + startAngle); | |
47 | onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + angleSpan); |
|
47 | onAngleSpanChanged: console.log("slice.onAngleSpanChanged: " + angleSpan); | |
48 | onClicked: console.log("slice.onClicked: " + label); |
|
48 | onClicked: console.log("slice.onClicked: " + label); | |
49 | onHovered: console.log("slice.onHovered: " + state); |
|
49 | onHovered: console.log("slice.onHovered: " + state); | |
50 | } |
|
50 | } | |
51 | PieSlice { label: "slice2"; value: 22 } |
|
51 | PieSlice { label: "slice2"; value: 22 } | |
52 | PieSlice { label: "slice3"; value: 33 } |
|
52 | PieSlice { label: "slice3"; value: 33 } | |
53 | PieSlice { label: "slice4"; value: 44 } |
|
53 | PieSlice { label: "slice4"; value: 44 } | |
54 |
|
54 | |||
55 |
onNameChanged: console.log("pieSeries.onNameChanged: " + |
|
55 | onNameChanged: console.log("pieSeries.onNameChanged: " + name); | |
56 | onVisibleChanged: console.log("pieSeries.onVisibleChanged: " + series.visible); |
|
56 | onVisibleChanged: console.log("pieSeries.onVisibleChanged: " + series.visible); | |
|
57 | onOpacityChanged: console.log("pieSeries.onOpacityChanged: " + opacity); | |||
57 | onClicked: console.log("pieSeries.onClicked: " + slice.label); |
|
58 | onClicked: console.log("pieSeries.onClicked: " + slice.label); | |
58 | onHovered: console.log("pieSeries.onHovered: " + slice.label); |
|
59 | onHovered: console.log("pieSeries.onHovered: " + slice.label); | |
59 | onAdded: console.log("pieSeries.onAdded: " + slices); |
|
60 | onAdded: console.log("pieSeries.onAdded: " + slices); | |
60 | onSliceAdded: console.log("pieSeries.onSliceAdded: " + slice.label); |
|
61 | onSliceAdded: console.log("pieSeries.onSliceAdded: " + slice.label); | |
61 | onRemoved: console.log("pieSeries.onRemoved: " + slices); |
|
62 | onRemoved: console.log("pieSeries.onRemoved: " + slices); | |
62 | onSliceRemoved: console.log("pieSeries.onSliceRemoved: " + slice.label); |
|
63 | onSliceRemoved: console.log("pieSeries.onSliceRemoved: " + slice.label); | |
63 |
onCountChanged: console.log("pieSeries.onCountChanged: " + |
|
64 | onCountChanged: console.log("pieSeries.onCountChanged: " + count); | |
64 |
onSumChanged: console.log("pieSeries.onSumChanged: " + |
|
65 | onSumChanged: console.log("pieSeries.onSumChanged: " + sum); | |
65 | } |
|
66 | } | |
66 | } |
|
67 | } |
@@ -1,220 +1,228 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | Row { |
|
24 | Row { | |
25 | anchors.fill: parent |
|
25 | anchors.fill: parent | |
26 | spacing: 5 |
|
26 | spacing: 5 | |
27 | property variant series |
|
27 | property variant series | |
28 | property int sliceIndex: 0 |
|
28 | property int sliceIndex: 0 | |
29 |
|
29 | |||
30 | // buttons for selecting the edited object: series, slice or label |
|
30 | // buttons for selecting the edited object: series, slice or label | |
31 | Flow { |
|
31 | Flow { | |
32 | spacing: 5 |
|
32 | spacing: 5 | |
33 | flow: Flow.TopToBottom |
|
33 | flow: Flow.TopToBottom | |
34 | Button { |
|
34 | Button { | |
35 | id: seriesButton |
|
35 | id: seriesButton | |
36 | text: "series" |
|
36 | text: "series" | |
37 | unpressedColor: "#79bd8f" |
|
37 | unpressedColor: "#79bd8f" | |
38 | onClicked: { |
|
38 | onClicked: { | |
39 | seriesFlow.visible = true; |
|
39 | seriesFlow.visible = true; | |
40 | slicesFlow.visible = false; |
|
40 | slicesFlow.visible = false; | |
41 | labelsFlow.visible = false; |
|
41 | labelsFlow.visible = false; | |
42 | color = "#00a388"; |
|
42 | color = "#00a388"; | |
43 | sliceButton.color = "#79bd8f"; |
|
43 | sliceButton.color = "#79bd8f"; | |
44 | labelButton.color = "#79bd8f"; |
|
44 | labelButton.color = "#79bd8f"; | |
45 | } |
|
45 | } | |
46 | } |
|
46 | } | |
47 | Button { |
|
47 | Button { | |
48 | id: sliceButton |
|
48 | id: sliceButton | |
49 | text: "slice" |
|
49 | text: "slice" | |
50 | unpressedColor: "#79bd8f" |
|
50 | unpressedColor: "#79bd8f" | |
51 | onClicked: { |
|
51 | onClicked: { | |
52 | seriesFlow.visible = false; |
|
52 | seriesFlow.visible = false; | |
53 | slicesFlow.visible = true; |
|
53 | slicesFlow.visible = true; | |
54 | labelsFlow.visible = false; |
|
54 | labelsFlow.visible = false; | |
55 | color = "#00a388"; |
|
55 | color = "#00a388"; | |
56 | seriesButton.color = "#79bd8f"; |
|
56 | seriesButton.color = "#79bd8f"; | |
57 | labelButton.color = "#79bd8f"; |
|
57 | labelButton.color = "#79bd8f"; | |
58 | } |
|
58 | } | |
59 | } |
|
59 | } | |
60 | Button { |
|
60 | Button { | |
61 | id: labelButton |
|
61 | id: labelButton | |
62 | text: "label" |
|
62 | text: "label" | |
63 | unpressedColor: "#79bd8f" |
|
63 | unpressedColor: "#79bd8f" | |
64 | onClicked: { |
|
64 | onClicked: { | |
65 | seriesFlow.visible = false; |
|
65 | seriesFlow.visible = false; | |
66 | slicesFlow.visible = false; |
|
66 | slicesFlow.visible = false; | |
67 | labelsFlow.visible = true; |
|
67 | labelsFlow.visible = true; | |
68 | color = "#00a388"; |
|
68 | color = "#00a388"; | |
69 | seriesButton.color = "#79bd8f"; |
|
69 | seriesButton.color = "#79bd8f"; | |
70 | sliceButton.color = "#79bd8f"; |
|
70 | sliceButton.color = "#79bd8f"; | |
71 | } |
|
71 | } | |
72 | } |
|
72 | } | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 | // Buttons for editing series |
|
75 | // Buttons for editing series | |
76 | Flow { |
|
76 | Flow { | |
77 | id: seriesFlow |
|
77 | id: seriesFlow | |
78 | spacing: 5 |
|
78 | spacing: 5 | |
79 | flow: Flow.TopToBottom |
|
79 | flow: Flow.TopToBottom | |
80 | visible: false |
|
80 | visible: false | |
81 | Button { |
|
81 | Button { | |
82 | text: "visible" |
|
82 | text: "visible" | |
83 | onClicked: series.visible = !series.visible; |
|
83 | onClicked: series.visible = !series.visible; | |
84 | } |
|
84 | } | |
85 | Button { |
|
85 | Button { | |
|
86 | text: "series opacity +" | |||
|
87 | onClicked: series.opacity += 0.1; | |||
|
88 | } | |||
|
89 | Button { | |||
|
90 | text: "series opacity -" | |||
|
91 | onClicked: series.opacity -= 0.1; | |||
|
92 | } | |||
|
93 | Button { | |||
86 | text: "series hpos +" |
|
94 | text: "series hpos +" | |
87 | onClicked: series.horizontalPosition += 0.1; |
|
95 | onClicked: series.horizontalPosition += 0.1; | |
88 | } |
|
96 | } | |
89 | Button { |
|
97 | Button { | |
90 | text: "series hpos -" |
|
98 | text: "series hpos -" | |
91 | onClicked: series.horizontalPosition -= 0.1; |
|
99 | onClicked: series.horizontalPosition -= 0.1; | |
92 | } |
|
100 | } | |
93 | Button { |
|
101 | Button { | |
94 | text: "series vpos +" |
|
102 | text: "series vpos +" | |
95 | onClicked: series.verticalPosition += 0.1; |
|
103 | onClicked: series.verticalPosition += 0.1; | |
96 | } |
|
104 | } | |
97 | Button { |
|
105 | Button { | |
98 | text: "series vpos -" |
|
106 | text: "series vpos -" | |
99 | onClicked: series.verticalPosition -= 0.1; |
|
107 | onClicked: series.verticalPosition -= 0.1; | |
100 | } |
|
108 | } | |
101 | Button { |
|
109 | Button { | |
102 | text: "series size +" |
|
110 | text: "series size +" | |
103 | onClicked: series.size += 0.1; |
|
111 | onClicked: series.size += 0.1; | |
104 | } |
|
112 | } | |
105 | Button { |
|
113 | Button { | |
106 | text: "series size -" |
|
114 | text: "series size -" | |
107 | onClicked: series.size -= 0.1; |
|
115 | onClicked: series.size -= 0.1; | |
108 | } |
|
116 | } | |
109 | Button { |
|
117 | Button { | |
110 | text: "series start angle +" |
|
118 | text: "series start angle +" | |
111 | onClicked: series.startAngle += 1.1; |
|
119 | onClicked: series.startAngle += 1.1; | |
112 | } |
|
120 | } | |
113 | Button { |
|
121 | Button { | |
114 | text: "series start angle -" |
|
122 | text: "series start angle -" | |
115 | onClicked: series.startAngle -= 1.1; |
|
123 | onClicked: series.startAngle -= 1.1; | |
116 | } |
|
124 | } | |
117 | Button { |
|
125 | Button { | |
118 | text: "series end angle +" |
|
126 | text: "series end angle +" | |
119 | onClicked: series.endAngle += 1.1; |
|
127 | onClicked: series.endAngle += 1.1; | |
120 | } |
|
128 | } | |
121 | Button { |
|
129 | Button { | |
122 | text: "series end angle -" |
|
130 | text: "series end angle -" | |
123 | onClicked: series.endAngle -= 1.1; |
|
131 | onClicked: series.endAngle -= 1.1; | |
124 | } |
|
132 | } | |
125 | } |
|
133 | } | |
126 |
|
134 | |||
127 | // Buttons for editing slices |
|
135 | // Buttons for editing slices | |
128 | Flow { |
|
136 | Flow { | |
129 | id: slicesFlow |
|
137 | id: slicesFlow | |
130 | spacing: 5 |
|
138 | spacing: 5 | |
131 | flow: Flow.TopToBottom |
|
139 | flow: Flow.TopToBottom | |
132 | visible: false |
|
140 | visible: false | |
133 |
|
141 | |||
134 | Button { |
|
142 | Button { | |
135 | text: "append slice" |
|
143 | text: "append slice" | |
136 | onClicked: series.append("slice" + (series.count + 1), 3.0); |
|
144 | onClicked: series.append("slice" + (series.count + 1), 3.0); | |
137 | } |
|
145 | } | |
138 | Button { |
|
146 | Button { | |
139 | text: "remove slice" |
|
147 | text: "remove slice" | |
140 | onClicked: series.remove(series.at(series.count - 1)); |
|
148 | onClicked: series.remove(series.at(series.count - 1)); | |
141 | } |
|
149 | } | |
142 | Button { |
|
150 | Button { | |
143 | text: "slice color" |
|
151 | text: "slice color" | |
144 | onClicked: series.at(sliceIndex).color = main.nextColor(); |
|
152 | onClicked: series.at(sliceIndex).color = main.nextColor(); | |
145 | } |
|
153 | } | |
146 | Button { |
|
154 | Button { | |
147 | text: "slice border color" |
|
155 | text: "slice border color" | |
148 | onClicked: series.at(sliceIndex).borderColor = main.nextColor(); |
|
156 | onClicked: series.at(sliceIndex).borderColor = main.nextColor(); | |
149 | } |
|
157 | } | |
150 | Button { |
|
158 | Button { | |
151 | text: "slice border width +" |
|
159 | text: "slice border width +" | |
152 | onClicked: series.at(sliceIndex).borderWidth++; |
|
160 | onClicked: series.at(sliceIndex).borderWidth++; | |
153 | } |
|
161 | } | |
154 | Button { |
|
162 | Button { | |
155 | text: "slice border width -" |
|
163 | text: "slice border width -" | |
156 | onClicked: series.at(sliceIndex).borderWidth--; |
|
164 | onClicked: series.at(sliceIndex).borderWidth--; | |
157 | } |
|
165 | } | |
158 | Button { |
|
166 | Button { | |
159 | text: "slice exploded" |
|
167 | text: "slice exploded" | |
160 | onClicked: series.at(sliceIndex).exploded = !series.at(sliceIndex).exploded; |
|
168 | onClicked: series.at(sliceIndex).exploded = !series.at(sliceIndex).exploded; | |
161 | } |
|
169 | } | |
162 | Button { |
|
170 | Button { | |
163 | text: "slice explode dist +" |
|
171 | text: "slice explode dist +" | |
164 | onClicked: series.at(sliceIndex).explodeDistanceFactor += 0.1; |
|
172 | onClicked: series.at(sliceIndex).explodeDistanceFactor += 0.1; | |
165 | } |
|
173 | } | |
166 | Button { |
|
174 | Button { | |
167 | text: "slice explode dist -" |
|
175 | text: "slice explode dist -" | |
168 | onClicked: series.at(sliceIndex).explodeDistanceFactor -= 0.1; |
|
176 | onClicked: series.at(sliceIndex).explodeDistanceFactor -= 0.1; | |
169 | } |
|
177 | } | |
170 | } |
|
178 | } | |
171 |
|
179 | |||
172 | // Buttons for editing labels |
|
180 | // Buttons for editing labels | |
173 | Flow { |
|
181 | Flow { | |
174 | id: labelsFlow |
|
182 | id: labelsFlow | |
175 | spacing: 5 |
|
183 | spacing: 5 | |
176 | flow: Flow.TopToBottom |
|
184 | flow: Flow.TopToBottom | |
177 | visible: false |
|
185 | visible: false | |
178 |
|
186 | |||
179 | Button { |
|
187 | Button { | |
180 | text: "label visible" |
|
188 | text: "label visible" | |
181 | onClicked: series.at(sliceIndex).labelVisible = !series.at(sliceIndex).labelVisible; |
|
189 | onClicked: series.at(sliceIndex).labelVisible = !series.at(sliceIndex).labelVisible; | |
182 | } |
|
190 | } | |
183 | Button { |
|
191 | Button { | |
184 | text: "LabelInsideNormal" |
|
192 | text: "LabelInsideNormal" | |
185 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideNormal; |
|
193 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideNormal; | |
186 | } |
|
194 | } | |
187 | Button { |
|
195 | Button { | |
188 | text: "LabelInsideHorizontal" |
|
196 | text: "LabelInsideHorizontal" | |
189 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideHorizontal; |
|
197 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideHorizontal; | |
190 | } |
|
198 | } | |
191 | Button { |
|
199 | Button { | |
192 | text: "LabelInsideTangential" |
|
200 | text: "LabelInsideTangential" | |
193 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideTangential; |
|
201 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelInsideTangential; | |
194 | } |
|
202 | } | |
195 | Button { |
|
203 | Button { | |
196 | text: "LabelOutside" |
|
204 | text: "LabelOutside" | |
197 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelOutside; |
|
205 | onClicked: series.at(sliceIndex).labelPosition = PieSlice.LabelOutside; | |
198 | } |
|
206 | } | |
199 | Button { |
|
207 | Button { | |
200 | text: "label arm len +" |
|
208 | text: "label arm len +" | |
201 | onClicked: series.at(sliceIndex).labelArmLengthFactor += 0.1; |
|
209 | onClicked: series.at(sliceIndex).labelArmLengthFactor += 0.1; | |
202 | } |
|
210 | } | |
203 | Button { |
|
211 | Button { | |
204 | text: "label arm len -" |
|
212 | text: "label arm len -" | |
205 | onClicked: series.at(sliceIndex).labelArmLengthFactor -= 0.1; |
|
213 | onClicked: series.at(sliceIndex).labelArmLengthFactor -= 0.1; | |
206 | } |
|
214 | } | |
207 | Button { |
|
215 | Button { | |
208 | text: "slice label color" |
|
216 | text: "slice label color" | |
209 | onClicked: series.at(sliceIndex).labelColor = main.nextColor(); |
|
217 | onClicked: series.at(sliceIndex).labelColor = main.nextColor(); | |
210 | } |
|
218 | } | |
211 |
|
219 | |||
212 | FontEditor { |
|
220 | FontEditor { | |
213 | id: fontEditor |
|
221 | id: fontEditor | |
214 | fontDescription: "label" |
|
222 | fontDescription: "label" | |
215 | function editedFont() { |
|
223 | function editedFont() { | |
216 | return series.at(sliceIndex).labelFont; |
|
224 | return series.at(sliceIndex).labelFont; | |
217 | } |
|
225 | } | |
218 | } |
|
226 | } | |
219 | } |
|
227 | } | |
220 | } |
|
228 | } |
@@ -1,62 +1,63 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "scatter series" |
|
25 | title: "scatter series" | |
26 | property variant series: scatterSeries |
|
26 | property variant series: scatterSeries | |
27 | animationOptions: ChartView.SeriesAnimations |
|
27 | animationOptions: ChartView.SeriesAnimations | |
28 |
|
28 | |||
29 | ScatterSeries { |
|
29 | ScatterSeries { | |
30 | id: scatterSeries |
|
30 | id: scatterSeries | |
31 | name: "scatter 1" |
|
31 | name: "scatter 1" | |
32 | XYPoint { x: 1.5; y: 1.5 } |
|
32 | XYPoint { x: 1.5; y: 1.5 } | |
33 | XYPoint { x: 1.5; y: 1.6 } |
|
33 | XYPoint { x: 1.5; y: 1.6 } | |
34 | XYPoint { x: 1.57; y: 1.55 } |
|
34 | XYPoint { x: 1.57; y: 1.55 } | |
35 | XYPoint { x: 1.8; y: 1.8 } |
|
35 | XYPoint { x: 1.8; y: 1.8 } | |
36 | XYPoint { x: 1.9; y: 1.6 } |
|
36 | XYPoint { x: 1.9; y: 1.6 } | |
37 | XYPoint { x: 2.1; y: 1.3 } |
|
37 | XYPoint { x: 2.1; y: 1.3 } | |
38 | XYPoint { x: 2.5; y: 2.1 } |
|
38 | XYPoint { x: 2.5; y: 2.1 } | |
39 |
|
39 | |||
40 | onNameChanged: console.log("scatterSeries.onNameChanged: " + name); |
|
40 | onNameChanged: console.log("scatterSeries.onNameChanged: " + name); | |
41 | onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); |
|
41 | onVisibleChanged: console.log("scatterSeries.onVisibleChanged: " + visible); | |
|
42 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); | |||
42 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
43 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
43 | onPointReplaced: console.log("scatterSeries.onPointReplaced: " + index); |
|
44 | onPointReplaced: console.log("scatterSeries.onPointReplaced: " + index); | |
44 | onPointRemoved: console.log("scatterSeries.onPointRemoved: " + index); |
|
45 | onPointRemoved: console.log("scatterSeries.onPointRemoved: " + index); | |
45 | onPointAdded: console.log("scatterSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); |
|
46 | onPointAdded: console.log("scatterSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); | |
46 | onColorChanged: console.log("scatterSeries.onColorChanged: " + color); |
|
47 | onColorChanged: console.log("scatterSeries.onColorChanged: " + color); | |
47 | onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor); |
|
48 | onBorderColorChanged: console.log("scatterSeries.onBorderColorChanged: " + borderColor); | |
48 | onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth); |
|
49 | onBorderWidthChanged: console.log("scatterSeries.onBorderChanged: " + borderWidth); | |
49 | onCountChanged: console.log("scatterSeries.onCountChanged: " + count); |
|
50 | onCountChanged: console.log("scatterSeries.onCountChanged: " + count); | |
50 | } |
|
51 | } | |
51 |
|
52 | |||
52 | ScatterSeries { |
|
53 | ScatterSeries { | |
53 | name: "scatter2" |
|
54 | name: "scatter2" | |
54 | XYPoint { x: 2.0; y: 2.0 } |
|
55 | XYPoint { x: 2.0; y: 2.0 } | |
55 | XYPoint { x: 2.0; y: 2.1 } |
|
56 | XYPoint { x: 2.0; y: 2.1 } | |
56 | XYPoint { x: 2.07; y: 2.05 } |
|
57 | XYPoint { x: 2.07; y: 2.05 } | |
57 | XYPoint { x: 2.2; y: 2.9 } |
|
58 | XYPoint { x: 2.2; y: 2.9 } | |
58 | XYPoint { x: 2.4; y: 2.7 } |
|
59 | XYPoint { x: 2.4; y: 2.7 } | |
59 | XYPoint { x: 2.67; y: 2.65 } |
|
60 | XYPoint { x: 2.67; y: 2.65 } | |
60 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
61 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
61 | } |
|
62 | } | |
62 | } |
|
63 | } |
@@ -1,84 +1,92 | |||||
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 |
|
22 | |||
23 | Flow { |
|
23 | Flow { | |
24 | id: flow |
|
24 | id: flow | |
25 | spacing: 5 |
|
25 | spacing: 5 | |
26 | flow: Flow.TopToBottom |
|
26 | flow: Flow.TopToBottom | |
27 | property variant series |
|
27 | property variant series | |
28 |
|
28 | |||
29 | Button { |
|
29 | Button { | |
30 | text: "visible" |
|
30 | text: "visible" | |
31 | onClicked: series.visible = !series.visible; |
|
31 | onClicked: series.visible = !series.visible; | |
32 | } |
|
32 | } | |
33 | Button { |
|
33 | Button { | |
|
34 | text: "opacity +" | |||
|
35 | onClicked: series.opacity += 0.1; | |||
|
36 | } | |||
|
37 | Button { | |||
|
38 | text: "opacity -" | |||
|
39 | onClicked: series.opacity -= 0.1; | |||
|
40 | } | |||
|
41 | Button { | |||
34 | text: "color" |
|
42 | text: "color" | |
35 | onClicked: series.color = main.nextColor(); |
|
43 | onClicked: series.color = main.nextColor(); | |
36 | } |
|
44 | } | |
37 | Button { |
|
45 | Button { | |
38 | text: "borderColor" |
|
46 | text: "borderColor" | |
39 | onClicked: series.borderColor = main.nextColor(); |
|
47 | onClicked: series.borderColor = main.nextColor(); | |
40 | } |
|
48 | } | |
41 | Button { |
|
49 | Button { | |
42 | text: series != undefined ? "borderWidth + (" + series.borderWidth + ")" : "" |
|
50 | text: series != undefined ? "borderWidth + (" + series.borderWidth + ")" : "" | |
43 | onClicked: series.borderWidth += 0.5; |
|
51 | onClicked: series.borderWidth += 0.5; | |
44 | } |
|
52 | } | |
45 | Button { |
|
53 | Button { | |
46 | text: series != undefined ? "borderWidth - (" + series.borderWidth + ")" : "" |
|
54 | text: series != undefined ? "borderWidth - (" + series.borderWidth + ")" : "" | |
47 | onClicked: series.borderWidth -= 0.5; |
|
55 | onClicked: series.borderWidth -= 0.5; | |
48 | } |
|
56 | } | |
49 | Button { |
|
57 | Button { | |
50 | text: "markerSize +" |
|
58 | text: "markerSize +" | |
51 | onClicked: series.markerSize += 1.0; |
|
59 | onClicked: series.markerSize += 1.0; | |
52 | } |
|
60 | } | |
53 | Button { |
|
61 | Button { | |
54 | text: "markerSize -" |
|
62 | text: "markerSize -" | |
55 | onClicked: series.markerSize -= 1.0; |
|
63 | onClicked: series.markerSize -= 1.0; | |
56 | } |
|
64 | } | |
57 | Button { |
|
65 | Button { | |
58 | text: "markerShape" |
|
66 | text: "markerShape" | |
59 | onClicked: series.markerShape = ((series.markerShape + 1) % 2); |
|
67 | onClicked: series.markerShape = ((series.markerShape + 1) % 2); | |
60 | } |
|
68 | } | |
61 | Button { |
|
69 | Button { | |
62 | text: "append point" |
|
70 | text: "append point" | |
63 | onClicked: series.append(series.count - 1, series.count - 1); |
|
71 | onClicked: series.append(series.count - 1, series.count - 1); | |
64 | } |
|
72 | } | |
65 | Button { |
|
73 | Button { | |
66 | text: "replace point" |
|
74 | text: "replace point" | |
67 | onClicked: { |
|
75 | onClicked: { | |
68 | var xyPoint = series.at(series.count - 1); |
|
76 | var xyPoint = series.at(series.count - 1); | |
69 | series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); |
|
77 | series.replace(xyPoint.x, xyPoint.y, xyPoint.x, xyPoint.y + 0.1); | |
70 | } |
|
78 | } | |
71 | } |
|
79 | } | |
72 | Button { |
|
80 | Button { | |
73 | text: "remove point" |
|
81 | text: "remove point" | |
74 | onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); |
|
82 | onClicked: series.remove(series.at(series.count - 1).x, series.at(series.count - 1).y); | |
75 | } |
|
83 | } | |
76 | Button { |
|
84 | Button { | |
77 | text: "insert point" |
|
85 | text: "insert point" | |
78 | onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); |
|
86 | onClicked: series.insert(series.count - 2, series.count - 2, series.count - 2); | |
79 | } |
|
87 | } | |
80 | Button { |
|
88 | Button { | |
81 | text: "clear" |
|
89 | text: "clear" | |
82 | onClicked: series.clear(); |
|
90 | onClicked: series.clear(); | |
83 | } |
|
91 | } | |
84 | } |
|
92 | } |
@@ -1,64 +1,65 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "spline series" |
|
25 | title: "spline series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | property variant series: splineSeries |
|
27 | property variant series: splineSeries | |
28 | animationOptions: ChartView.SeriesAnimations |
|
28 | animationOptions: ChartView.SeriesAnimations | |
29 |
|
29 | |||
30 | SplineSeries { |
|
30 | SplineSeries { | |
31 | id: splineSeries |
|
31 | id: splineSeries | |
32 | name: "spline 1" |
|
32 | name: "spline 1" | |
33 | XYPoint { x: 0; y: 0 } |
|
33 | XYPoint { x: 0; y: 0 } | |
34 | XYPoint { x: 1.1; y: 2.1 } |
|
34 | XYPoint { x: 1.1; y: 2.1 } | |
35 | XYPoint { x: 1.9; y: 3.3 } |
|
35 | XYPoint { x: 1.9; y: 3.3 } | |
36 | XYPoint { x: 2.1; y: 2.1 } |
|
36 | XYPoint { x: 2.1; y: 2.1 } | |
37 | XYPoint { x: 2.9; y: 4.9 } |
|
37 | XYPoint { x: 2.9; y: 4.9 } | |
38 | XYPoint { x: 3.4; y: 3.0 } |
|
38 | XYPoint { x: 3.4; y: 3.0 } | |
39 | XYPoint { x: 4.1; y: 3.3 } |
|
39 | XYPoint { x: 4.1; y: 3.3 } | |
40 |
|
40 | |||
41 | onNameChanged: console.log("splineSeries.onNameChanged: " + name); |
|
41 | onNameChanged: console.log("splineSeries.onNameChanged: " + name); | |
42 | onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible); |
|
42 | onVisibleChanged: console.log("splineSeries.onVisibleChanged: " + visible); | |
|
43 | onOpacityChanged: console.log(name + ".onOpacityChanged: " + opacity); | |||
43 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
44 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
44 | onPointReplaced: console.log("splineSeries.onPointReplaced: " + index); |
|
45 | onPointReplaced: console.log("splineSeries.onPointReplaced: " + index); | |
45 | onPointRemoved: console.log("splineSeries.onPointRemoved: " + index); |
|
46 | onPointRemoved: console.log("splineSeries.onPointRemoved: " + index); | |
46 | onPointAdded: console.log("splineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); |
|
47 | onPointAdded: console.log("splineSeries.onPointAdded: " + series.at(index).x + ", " + series.at(index).y); | |
47 | onColorChanged: console.log("splineSeries.onColorChanged: " + color); |
|
48 | onColorChanged: console.log("splineSeries.onColorChanged: " + color); | |
48 | onWidthChanged: console.log("splineSeries.onWidthChanged: " + width); |
|
49 | onWidthChanged: console.log("splineSeries.onWidthChanged: " + width); | |
49 | onStyleChanged: console.log("splineSeries.onStyleChanged: " + style); |
|
50 | onStyleChanged: console.log("splineSeries.onStyleChanged: " + style); | |
50 | onCapStyleChanged: console.log("splineSeries.onCapStyleChanged: " + capStyle); |
|
51 | onCapStyleChanged: console.log("splineSeries.onCapStyleChanged: " + capStyle); | |
51 | onCountChanged: console.log("splineSeries.onCountChanged: " + count); |
|
52 | onCountChanged: console.log("splineSeries.onCountChanged: " + count); | |
52 | } |
|
53 | } | |
53 |
|
54 | |||
54 | SplineSeries { |
|
55 | SplineSeries { | |
55 | name: "spline 2" |
|
56 | name: "spline 2" | |
56 | XYPoint { x: 1.1; y: 1.1 } |
|
57 | XYPoint { x: 1.1; y: 1.1 } | |
57 | XYPoint { x: 1.9; y: 2.3 } |
|
58 | XYPoint { x: 1.9; y: 2.3 } | |
58 | XYPoint { x: 2.1; y: 1.1 } |
|
59 | XYPoint { x: 2.1; y: 1.1 } | |
59 | XYPoint { x: 2.9; y: 3.9 } |
|
60 | XYPoint { x: 2.9; y: 3.9 } | |
60 | XYPoint { x: 3.4; y: 2.0 } |
|
61 | XYPoint { x: 3.4; y: 2.0 } | |
61 | XYPoint { x: 4.1; y: 2.3 } |
|
62 | XYPoint { x: 4.1; y: 2.3 } | |
62 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); |
|
63 | onClicked: console.log(name + ".onClicked: " + point.x + ", " + point.y); | |
63 | } |
|
64 | } | |
64 | } |
|
65 | } |
@@ -1,63 +1,64 | |||||
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.1 |
|
22 | import QtCommercial.Chart 1.1 | |
23 |
|
23 | |||
24 | ChartView { |
|
24 | ChartView { | |
25 | title: "Stacked bar series" |
|
25 | title: "Stacked bar series" | |
26 | anchors.fill: parent |
|
26 | anchors.fill: parent | |
27 | theme: ChartView.ChartThemeLight |
|
27 | theme: ChartView.ChartThemeLight | |
28 | legend.alignment: Qt.AlignBottom |
|
28 | legend.alignment: Qt.AlignBottom | |
29 | animationOptions: ChartView.SeriesAnimations |
|
29 | animationOptions: ChartView.SeriesAnimations | |
30 |
|
30 | |||
31 | property variant series: mySeries |
|
31 | property variant series: mySeries | |
32 |
|
32 | |||
33 | StackedBarSeries { |
|
33 | StackedBarSeries { | |
34 | id: mySeries |
|
34 | id: mySeries | |
35 | name: "bar" |
|
35 | name: "bar" | |
36 | axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } |
|
36 | axisX: BarCategoryAxis { categories: ["2007", "2008", "2009", "2010", "2011", "2012" ] } | |
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] |
|
37 | BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] | |
38 | onClicked: console.log("barset.onClicked: " + index); |
|
38 | onClicked: console.log("barset.onClicked: " + index); | |
39 | onHovered: console.log("barset.onHovered: " + status); |
|
39 | onHovered: console.log("barset.onHovered: " + status); | |
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); |
|
40 | onPenChanged: console.log("barset.onPenChanged: " + pen); | |
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); |
|
41 | onBrushChanged: console.log("barset.onBrushChanged: " + brush); | |
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); |
|
42 | onLabelChanged: console.log("barset.onLabelChanged: " + label); | |
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); |
|
43 | onLabelBrushChanged: console.log("barset.onLabelBrushChanged: " + labelBrush); | |
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); |
|
44 | onLabelFontChanged: console.log("barset.onLabelFontChanged: " + labelFont); | |
45 | onColorChanged: console.log("barset.onColorChanged: " + color); |
|
45 | onColorChanged: console.log("barset.onColorChanged: " + color); | |
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); |
|
46 | onBorderColorChanged: console.log("barset.onBorderColorChanged: " + color); | |
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); |
|
47 | onLabelColorChanged: console.log("barset.onLabelColorChanged: " + color); | |
48 | onCountChanged: console.log("barset.onCountChanged: " + count); |
|
48 | onCountChanged: console.log("barset.onCountChanged: " + count); | |
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); |
|
49 | onValuesAdded: console.log("barset.onValuesAdded: " + index + ", " + count); | |
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); |
|
50 | onValuesRemoved: console.log("barset.onValuesRemoved: " + index + ", " + count); | |
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); |
|
51 | onValueChanged: console.log("barset.onValuesChanged: " + index); | |
52 | } |
|
52 | } | |
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } |
|
53 | BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] } | |
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } |
|
54 | BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] } | |
55 |
|
55 | |||
56 | onNameChanged: console.log("stackedBarSeries.onNameChanged: " + series.name); |
|
56 | onNameChanged: console.log("stackedBarSeries.onNameChanged: " + series.name); | |
57 | onVisibleChanged: console.log("stackedBarSeries.onVisibleChanged: " + series.visible); |
|
57 | onVisibleChanged: console.log("stackedBarSeries.onVisibleChanged: " + series.visible); | |
|
58 | onOpacityChanged: console.log("stackedBarSeries.onOpacityChanged: " + opacity); | |||
58 | onClicked: console.log("stackedBarSeries.onClicked: " + barset + " " + index); |
|
59 | onClicked: console.log("stackedBarSeries.onClicked: " + barset + " " + index); | |
59 | onHovered: console.log("stackedBarSeries.onHovered: " + barset + " " + status); |
|
60 | onHovered: console.log("stackedBarSeries.onHovered: " + barset + " " + status); | |
60 | onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); |
|
61 | onLabelsVisibleChanged: console.log("stackedBarSeries.onLabelsVisibleChanged: " + series.labelsVisible); | |
61 | onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count); |
|
62 | onCountChanged: console.log("stackedBarSeries.onCountChanged: " + count); | |
62 | } |
|
63 | } | |
63 | } |
|
64 | } |
General Comments 0
You need to be logged in to leave comments.
Login now