##// END OF EJS Templates
Remove TODOs...
Miikka Heikkinen -
r2575:f9a133cb3e77
parent child
Show More
@@ -1,255 +1,252
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "qchart.h"
21 #include "qchart.h"
22 #include "qabstractaxis.h"
22 #include "qabstractaxis.h"
23 #include "qvalueaxis.h"
23 #include "qvalueaxis.h"
24 #include "qlogvalueaxis.h"
24 #include "qlogvalueaxis.h"
25 #include "declarativecategoryaxis.h"
25 #include "declarativecategoryaxis.h"
26 #include "qbarcategoryaxis.h"
26 #include "qbarcategoryaxis.h"
27 #include "declarativechart.h"
27 #include "declarativechart.h"
28 #include "declarativepolarchart.h"
28 #include "declarativepolarchart.h"
29 #include "declarativexypoint.h"
29 #include "declarativexypoint.h"
30 #include "declarativelineseries.h"
30 #include "declarativelineseries.h"
31 #include "declarativesplineseries.h"
31 #include "declarativesplineseries.h"
32 #include "declarativeareaseries.h"
32 #include "declarativeareaseries.h"
33 #include "declarativescatterseries.h"
33 #include "declarativescatterseries.h"
34 #include "declarativebarseries.h"
34 #include "declarativebarseries.h"
35 #include "declarativeboxplotseries.h"
35 #include "declarativeboxplotseries.h"
36 #include "declarativepieseries.h"
36 #include "declarativepieseries.h"
37 #include "declarativeaxes.h"
37 #include "declarativeaxes.h"
38 #include "qvxymodelmapper.h"
38 #include "qvxymodelmapper.h"
39 #include "qhxymodelmapper.h"
39 #include "qhxymodelmapper.h"
40 #include "qhpiemodelmapper.h"
40 #include "qhpiemodelmapper.h"
41 #include "qvpiemodelmapper.h"
41 #include "qvpiemodelmapper.h"
42 #include "qhbarmodelmapper.h"
42 #include "qhbarmodelmapper.h"
43 #include "qvbarmodelmapper.h"
43 #include "qvbarmodelmapper.h"
44 #include "declarativemargins.h"
44 #include "declarativemargins.h"
45 #include "qarealegendmarker.h"
45 #include "qarealegendmarker.h"
46 #include "qbarlegendmarker.h"
46 #include "qbarlegendmarker.h"
47 #include "qpielegendmarker.h"
47 #include "qpielegendmarker.h"
48 #include "qxylegendmarker.h"
48 #include "qxylegendmarker.h"
49 #ifndef QT_ON_ARM
49 #ifndef QT_ON_ARM
50 #include "qdatetimeaxis.h"
50 #include "qdatetimeaxis.h"
51 #endif
51 #endif
52 #include "shared_defines.h"
52 #include "shared_defines.h"
53 #include <QAbstractItemModel>
53 #include <QAbstractItemModel>
54 #ifdef CHARTS_FOR_QUICK2
54 #ifdef CHARTS_FOR_QUICK2
55 #include <QtQml/QQmlExtensionPlugin>
55 #include <QtQml/QQmlExtensionPlugin>
56 #else
56 #else
57 #include <QtDeclarative/qdeclarativeextensionplugin.h>
57 #include <QtDeclarative/qdeclarativeextensionplugin.h>
58 #include <QtDeclarative/qdeclarative.h>
58 #include <QtDeclarative/qdeclarative.h>
59 #endif
59 #endif
60
60
61 QTCOMMERCIALCHART_USE_NAMESPACE
61 QTCOMMERCIALCHART_USE_NAMESPACE
62
62
63 Q_DECLARE_METATYPE(QList<QPieSlice *>)
63 Q_DECLARE_METATYPE(QList<QPieSlice *>)
64 Q_DECLARE_METATYPE(QList<QBarSet *>)
64 Q_DECLARE_METATYPE(QList<QBarSet *>)
65 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
65 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
66
66
67 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
67 #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
68
68
69 // NOTE: Hackish fixes for Qt5 (beta2).
70 // These should not be needed or at least they are not needed in Qt4.
71
72 Q_DECLARE_METATYPE(DeclarativeChart *)
69 Q_DECLARE_METATYPE(DeclarativeChart *)
73 Q_DECLARE_METATYPE(DeclarativePolarChart *)
70 Q_DECLARE_METATYPE(DeclarativePolarChart *)
74 Q_DECLARE_METATYPE(DeclarativeMargins *)
71 Q_DECLARE_METATYPE(DeclarativeMargins *)
75 Q_DECLARE_METATYPE(DeclarativeAreaSeries *)
72 Q_DECLARE_METATYPE(DeclarativeAreaSeries *)
76 Q_DECLARE_METATYPE(DeclarativeBarSeries *)
73 Q_DECLARE_METATYPE(DeclarativeBarSeries *)
77 Q_DECLARE_METATYPE(DeclarativeBarSet *)
74 Q_DECLARE_METATYPE(DeclarativeBarSet *)
78 Q_DECLARE_METATYPE(DeclarativeBoxPlotSeries *)
75 Q_DECLARE_METATYPE(DeclarativeBoxPlotSeries *)
79 Q_DECLARE_METATYPE(DeclarativeBoxSet *)
76 Q_DECLARE_METATYPE(DeclarativeBoxSet *)
80 Q_DECLARE_METATYPE(DeclarativeLineSeries *)
77 Q_DECLARE_METATYPE(DeclarativeLineSeries *)
81 Q_DECLARE_METATYPE(DeclarativePieSeries *)
78 Q_DECLARE_METATYPE(DeclarativePieSeries *)
82 Q_DECLARE_METATYPE(DeclarativeScatterSeries *)
79 Q_DECLARE_METATYPE(DeclarativeScatterSeries *)
83 Q_DECLARE_METATYPE(DeclarativeSplineSeries *)
80 Q_DECLARE_METATYPE(DeclarativeSplineSeries *)
84
81
85 Q_DECLARE_METATYPE(QAbstractAxis *)
82 Q_DECLARE_METATYPE(QAbstractAxis *)
86 Q_DECLARE_METATYPE(QValueAxis *)
83 Q_DECLARE_METATYPE(QValueAxis *)
87 Q_DECLARE_METATYPE(QBarCategoryAxis *)
84 Q_DECLARE_METATYPE(QBarCategoryAxis *)
88 Q_DECLARE_METATYPE(QCategoryAxis *)
85 Q_DECLARE_METATYPE(QCategoryAxis *)
89 Q_DECLARE_METATYPE(QDateTimeAxis *)
86 Q_DECLARE_METATYPE(QDateTimeAxis *)
90 Q_DECLARE_METATYPE(QLogValueAxis *)
87 Q_DECLARE_METATYPE(QLogValueAxis *)
91
88
92 Q_DECLARE_METATYPE(QLegend *)
89 Q_DECLARE_METATYPE(QLegend *)
93 Q_DECLARE_METATYPE(QLegendMarker *)
90 Q_DECLARE_METATYPE(QLegendMarker *)
94 Q_DECLARE_METATYPE(QAreaLegendMarker *)
91 Q_DECLARE_METATYPE(QAreaLegendMarker *)
95 Q_DECLARE_METATYPE(QBarLegendMarker *)
92 Q_DECLARE_METATYPE(QBarLegendMarker *)
96 Q_DECLARE_METATYPE(QPieLegendMarker *)
93 Q_DECLARE_METATYPE(QPieLegendMarker *)
97
94
98 Q_DECLARE_METATYPE(QHPieModelMapper *)
95 Q_DECLARE_METATYPE(QHPieModelMapper *)
99 Q_DECLARE_METATYPE(QHXYModelMapper *)
96 Q_DECLARE_METATYPE(QHXYModelMapper *)
100 Q_DECLARE_METATYPE(QPieModelMapper *)
97 Q_DECLARE_METATYPE(QPieModelMapper *)
101 Q_DECLARE_METATYPE(QHBarModelMapper *)
98 Q_DECLARE_METATYPE(QHBarModelMapper *)
102 Q_DECLARE_METATYPE(QBarModelMapper *)
99 Q_DECLARE_METATYPE(QBarModelMapper *)
103 Q_DECLARE_METATYPE(QVBarModelMapper *)
100 Q_DECLARE_METATYPE(QVBarModelMapper *)
104 Q_DECLARE_METATYPE(QVPieModelMapper *)
101 Q_DECLARE_METATYPE(QVPieModelMapper *)
105 Q_DECLARE_METATYPE(QVXYModelMapper *)
102 Q_DECLARE_METATYPE(QVXYModelMapper *)
106 Q_DECLARE_METATYPE(QXYLegendMarker *)
103 Q_DECLARE_METATYPE(QXYLegendMarker *)
107 Q_DECLARE_METATYPE(QXYModelMapper *)
104 Q_DECLARE_METATYPE(QXYModelMapper *)
108
105
109 Q_DECLARE_METATYPE(QAbstractSeries *)
106 Q_DECLARE_METATYPE(QAbstractSeries *)
110 Q_DECLARE_METATYPE(QXYSeries *)
107 Q_DECLARE_METATYPE(QXYSeries *)
111 Q_DECLARE_METATYPE(QAbstractBarSeries *)
108 Q_DECLARE_METATYPE(QAbstractBarSeries *)
112 Q_DECLARE_METATYPE(QBarSeries *)
109 Q_DECLARE_METATYPE(QBarSeries *)
113 Q_DECLARE_METATYPE(QBarSet *)
110 Q_DECLARE_METATYPE(QBarSet *)
114 Q_DECLARE_METATYPE(QAreaSeries *)
111 Q_DECLARE_METATYPE(QAreaSeries *)
115 Q_DECLARE_METATYPE(QHorizontalBarSeries *)
112 Q_DECLARE_METATYPE(QHorizontalBarSeries *)
116 Q_DECLARE_METATYPE(QHorizontalPercentBarSeries *)
113 Q_DECLARE_METATYPE(QHorizontalPercentBarSeries *)
117 Q_DECLARE_METATYPE(QHorizontalStackedBarSeries *)
114 Q_DECLARE_METATYPE(QHorizontalStackedBarSeries *)
118 Q_DECLARE_METATYPE(QLineSeries *)
115 Q_DECLARE_METATYPE(QLineSeries *)
119 Q_DECLARE_METATYPE(QPercentBarSeries *)
116 Q_DECLARE_METATYPE(QPercentBarSeries *)
120 Q_DECLARE_METATYPE(QPieSeries *)
117 Q_DECLARE_METATYPE(QPieSeries *)
121 Q_DECLARE_METATYPE(QPieSlice *)
118 Q_DECLARE_METATYPE(QPieSlice *)
122 Q_DECLARE_METATYPE(QScatterSeries *)
119 Q_DECLARE_METATYPE(QScatterSeries *)
123 Q_DECLARE_METATYPE(QSplineSeries *)
120 Q_DECLARE_METATYPE(QSplineSeries *)
124 Q_DECLARE_METATYPE(QStackedBarSeries *)
121 Q_DECLARE_METATYPE(QStackedBarSeries *)
125
122
126 #endif
123 #endif
127
124
128 QTCOMMERCIALCHART_BEGIN_NAMESPACE
125 QTCOMMERCIALCHART_BEGIN_NAMESPACE
129
126
130 class ChartQmlPlugin : public QDECLARATIVE_EXTENSION_PLUGIN
127 class ChartQmlPlugin : public QDECLARATIVE_EXTENSION_PLUGIN
131 {
128 {
132 Q_OBJECT
129 Q_OBJECT
133
130
134 #ifdef CHARTS_FOR_QUICK2
131 #ifdef CHARTS_FOR_QUICK2
135 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
132 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
136 #else
133 #else
137 # if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
134 # if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
138 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface")
135 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDeclarativeExtensionInterface")
139 # endif
136 # endif
140 #endif
137 #endif
141
138
142 public:
139 public:
143 virtual void registerTypes(const char *uri)
140 virtual void registerTypes(const char *uri)
144 {
141 {
145 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
142 Q_ASSERT(QLatin1String(uri) == QLatin1String("QtCommercial.Chart"));
146
143
147 qRegisterMetaType<QList<QPieSlice *> >();
144 qRegisterMetaType<QList<QPieSlice *> >();
148 qRegisterMetaType<QList<QBarSet *> >();
145 qRegisterMetaType<QList<QBarSet *> >();
149 qRegisterMetaType<QList<QAbstractAxis *> >();
146 qRegisterMetaType<QList<QAbstractAxis *> >();
150
147
151 // QtCommercial.Chart 1.0
148 // QtCommercial.Chart 1.0
152 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
149 qmlRegisterType<DeclarativeChart>(uri, 1, 0, "ChartView");
153 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
150 qmlRegisterType<DeclarativeXYPoint>(uri, 1, 0, "XYPoint");
154 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
151 qmlRegisterType<DeclarativeScatterSeries>(uri, 1, 0, "ScatterSeries");
155 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
152 qmlRegisterType<DeclarativeLineSeries>(uri, 1, 0, "LineSeries");
156 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
153 qmlRegisterType<DeclarativeSplineSeries>(uri, 1, 0, "SplineSeries");
157 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
154 qmlRegisterType<DeclarativeAreaSeries>(uri, 1, 0, "AreaSeries");
158 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
155 qmlRegisterType<DeclarativeBarSeries>(uri, 1, 0, "BarSeries");
159 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
156 qmlRegisterType<DeclarativeStackedBarSeries>(uri, 1, 0, "StackedBarSeries");
160 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
157 qmlRegisterType<DeclarativePercentBarSeries>(uri, 1, 0, "PercentBarSeries");
161 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
158 qmlRegisterType<DeclarativePieSeries>(uri, 1, 0, "PieSeries");
162 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
159 qmlRegisterType<QPieSlice>(uri, 1, 0, "PieSlice");
163 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
160 qmlRegisterType<DeclarativeBarSet>(uri, 1, 0, "BarSet");
164 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
161 qmlRegisterType<QHXYModelMapper>(uri, 1, 0, "HXYModelMapper");
165 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
162 qmlRegisterType<QVXYModelMapper>(uri, 1, 0, "VXYModelMapper");
166 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
163 qmlRegisterType<QHPieModelMapper>(uri, 1, 0, "HPieModelMapper");
167 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
164 qmlRegisterType<QVPieModelMapper>(uri, 1, 0, "VPieModelMapper");
168 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
165 qmlRegisterType<QHBarModelMapper>(uri, 1, 0, "HBarModelMapper");
169 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
166 qmlRegisterType<QVBarModelMapper>(uri, 1, 0, "VBarModelMapper");
170 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
167 qmlRegisterType<QValueAxis>(uri, 1, 0, "ValuesAxis");
171 qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis");
168 qmlRegisterType<QBarCategoryAxis>(uri, 1, 0, "BarCategoriesAxis");
172 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
169 qmlRegisterUncreatableType<QLegend>(uri, 1, 0, "Legend",
173 QLatin1String("Trying to create uncreatable: Legend."));
170 QLatin1String("Trying to create uncreatable: Legend."));
174 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
171 qmlRegisterUncreatableType<QXYSeries>(uri, 1, 0, "XYSeries",
175 QLatin1String("Trying to create uncreatable: XYSeries."));
172 QLatin1String("Trying to create uncreatable: XYSeries."));
176 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
173 qmlRegisterUncreatableType<QAbstractItemModel>(uri, 1, 0, "AbstractItemModel",
177 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
174 QLatin1String("Trying to create uncreatable: AbstractItemModel."));
178 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
175 qmlRegisterUncreatableType<QXYModelMapper>(uri, 1, 0, "XYModelMapper",
179 QLatin1String("Trying to create uncreatable: XYModelMapper."));
176 QLatin1String("Trying to create uncreatable: XYModelMapper."));
180 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
177 qmlRegisterUncreatableType<QPieModelMapper>(uri, 1, 0, "PieModelMapper",
181 QLatin1String("Trying to create uncreatable: PieModelMapper."));
178 QLatin1String("Trying to create uncreatable: PieModelMapper."));
182 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
179 qmlRegisterUncreatableType<QBarModelMapper>(uri, 1, 0, "BarModelMapper",
183 QLatin1String("Trying to create uncreatable: BarModelMapper."));
180 QLatin1String("Trying to create uncreatable: BarModelMapper."));
184 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
181 qmlRegisterUncreatableType<QAbstractSeries>(uri, 1, 0, "AbstractSeries",
185 QLatin1String("Trying to create uncreatable: AbstractSeries."));
182 QLatin1String("Trying to create uncreatable: AbstractSeries."));
186 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
183 qmlRegisterUncreatableType<QAbstractBarSeries>(uri, 1, 0, "AbstractBarSeries",
187 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
184 QLatin1String("Trying to create uncreatable: AbstractBarSeries."));
188 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
185 qmlRegisterUncreatableType<QAbstractAxis>(uri, 1, 0, "AbstractAxis",
189 QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead."));
186 QLatin1String("Trying to create uncreatable: AbstractAxis. Use specific types of axis instead."));
190 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase",
187 qmlRegisterUncreatableType<QBarSet>(uri, 1, 0, "BarSetBase",
191 QLatin1String("Trying to create uncreatable: BarsetBase."));
188 QLatin1String("Trying to create uncreatable: BarsetBase."));
192 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
189 qmlRegisterUncreatableType<QPieSeries>(uri, 1, 0, "QPieSeries",
193 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
190 QLatin1String("Trying to create uncreatable: QPieSeries. Use PieSeries instead."));
194 qmlRegisterUncreatableType<DeclarativeAxes>(uri, 1, 0, "DeclarativeAxes",
191 qmlRegisterUncreatableType<DeclarativeAxes>(uri, 1, 0, "DeclarativeAxes",
195 QLatin1String("Trying to create uncreatable: DeclarativeAxes."));
192 QLatin1String("Trying to create uncreatable: DeclarativeAxes."));
196
193
197 // QtCommercial.Chart 1.1
194 // QtCommercial.Chart 1.1
198 qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView");
195 qmlRegisterType<DeclarativeChart, 1>(uri, 1, 1, "ChartView");
199 qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries");
196 qmlRegisterType<DeclarativeScatterSeries, 1>(uri, 1, 1, "ScatterSeries");
200 qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries");
197 qmlRegisterType<DeclarativeLineSeries, 1>(uri, 1, 1, "LineSeries");
201 qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries");
198 qmlRegisterType<DeclarativeSplineSeries, 1>(uri, 1, 1, "SplineSeries");
202 qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries");
199 qmlRegisterType<DeclarativeAreaSeries, 1>(uri, 1, 1, "AreaSeries");
203 qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries");
200 qmlRegisterType<DeclarativeBarSeries, 1>(uri, 1, 1, "BarSeries");
204 qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries");
201 qmlRegisterType<DeclarativeStackedBarSeries, 1>(uri, 1, 1, "StackedBarSeries");
205 qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries");
202 qmlRegisterType<DeclarativePercentBarSeries, 1>(uri, 1, 1, "PercentBarSeries");
206 qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries");
203 qmlRegisterType<DeclarativeHorizontalBarSeries, 1>(uri, 1, 1, "HorizontalBarSeries");
207 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries");
204 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 1>(uri, 1, 1, "HorizontalStackedBarSeries");
208 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries");
205 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 1>(uri, 1, 1, "HorizontalPercentBarSeries");
209 qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries");
206 qmlRegisterType<DeclarativePieSeries>(uri, 1, 1, "PieSeries");
210 qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet");
207 qmlRegisterType<DeclarativeBarSet>(uri, 1, 1, "BarSet");
211 qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis");
208 qmlRegisterType<QValueAxis>(uri, 1, 1, "ValueAxis");
212 #ifndef QT_ON_ARM
209 #ifndef QT_ON_ARM
213 qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis");
210 qmlRegisterType<QDateTimeAxis>(uri, 1, 1, "DateTimeAxis");
214 #endif
211 #endif
215 qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis");
212 qmlRegisterType<DeclarativeCategoryAxis>(uri, 1, 1, "CategoryAxis");
216 qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange");
213 qmlRegisterType<DeclarativeCategoryRange>(uri, 1, 1, "CategoryRange");
217 qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis");
214 qmlRegisterType<QBarCategoryAxis>(uri, 1, 1, "BarCategoryAxis");
218 qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins",
215 qmlRegisterUncreatableType<DeclarativeMargins>(uri, 1, 1, "Margins",
219 QLatin1String("Trying to create uncreatable: Margins."));
216 QLatin1String("Trying to create uncreatable: Margins."));
220
217
221 // QtCommercial.Chart 1.2
218 // QtCommercial.Chart 1.2
222 qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView");
219 qmlRegisterType<DeclarativeChart, 2>(uri, 1, 2, "ChartView");
223 qmlRegisterType<DeclarativeScatterSeries, 2>(uri, 1, 2, "ScatterSeries");
220 qmlRegisterType<DeclarativeScatterSeries, 2>(uri, 1, 2, "ScatterSeries");
224 qmlRegisterType<DeclarativeLineSeries, 2>(uri, 1, 2, "LineSeries");
221 qmlRegisterType<DeclarativeLineSeries, 2>(uri, 1, 2, "LineSeries");
225 qmlRegisterType<DeclarativeSplineSeries, 2>(uri, 1, 2, "SplineSeries");
222 qmlRegisterType<DeclarativeSplineSeries, 2>(uri, 1, 2, "SplineSeries");
226 qmlRegisterType<DeclarativeAreaSeries, 2>(uri, 1, 2, "AreaSeries");
223 qmlRegisterType<DeclarativeAreaSeries, 2>(uri, 1, 2, "AreaSeries");
227 qmlRegisterType<DeclarativeBarSeries, 2>(uri, 1, 2, "BarSeries");
224 qmlRegisterType<DeclarativeBarSeries, 2>(uri, 1, 2, "BarSeries");
228 qmlRegisterType<DeclarativeStackedBarSeries, 2>(uri, 1, 2, "StackedBarSeries");
225 qmlRegisterType<DeclarativeStackedBarSeries, 2>(uri, 1, 2, "StackedBarSeries");
229 qmlRegisterType<DeclarativePercentBarSeries, 2>(uri, 1, 2, "PercentBarSeries");
226 qmlRegisterType<DeclarativePercentBarSeries, 2>(uri, 1, 2, "PercentBarSeries");
230 qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries");
227 qmlRegisterType<DeclarativeHorizontalBarSeries, 2>(uri, 1, 2, "HorizontalBarSeries");
231 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries");
228 qmlRegisterType<DeclarativeHorizontalStackedBarSeries, 2>(uri, 1, 2, "HorizontalStackedBarSeries");
232 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
229 qmlRegisterType<DeclarativeHorizontalPercentBarSeries, 2>(uri, 1, 2, "HorizontalPercentBarSeries");
233
230
234 // QtCommercial.Chart 1.3
231 // QtCommercial.Chart 1.3
235 qmlRegisterType<DeclarativeChart, 3>(uri, 1, 3, "ChartView");
232 qmlRegisterType<DeclarativeChart, 3>(uri, 1, 3, "ChartView");
236 qmlRegisterType<DeclarativePolarChart, 1>(uri, 1, 3, "PolarChartView");
233 qmlRegisterType<DeclarativePolarChart, 1>(uri, 1, 3, "PolarChartView");
237 qmlRegisterType<DeclarativeSplineSeries, 3>(uri, 1, 3, "SplineSeries");
234 qmlRegisterType<DeclarativeSplineSeries, 3>(uri, 1, 3, "SplineSeries");
238 qmlRegisterType<DeclarativeScatterSeries, 3>(uri, 1, 3, "ScatterSeries");
235 qmlRegisterType<DeclarativeScatterSeries, 3>(uri, 1, 3, "ScatterSeries");
239 qmlRegisterType<DeclarativeLineSeries, 3>(uri, 1, 3, "LineSeries");
236 qmlRegisterType<DeclarativeLineSeries, 3>(uri, 1, 3, "LineSeries");
240 qmlRegisterType<DeclarativeAreaSeries, 3>(uri, 1, 3, "AreaSeries");
237 qmlRegisterType<DeclarativeAreaSeries, 3>(uri, 1, 3, "AreaSeries");
241 qmlRegisterType<QLogValueAxis>(uri, 1, 3, "LogValueAxis");
238 qmlRegisterType<QLogValueAxis>(uri, 1, 3, "LogValueAxis");
242 qmlRegisterType<DeclarativeBoxPlotSeries>(uri, 1, 3, "BoxPlotSeries");
239 qmlRegisterType<DeclarativeBoxPlotSeries>(uri, 1, 3, "BoxPlotSeries");
243 qmlRegisterType<DeclarativeBoxSet>(uri, 1, 3, "BoxSet");
240 qmlRegisterType<DeclarativeBoxSet>(uri, 1, 3, "BoxSet");
244 }
241 }
245 };
242 };
246
243
247 #include "plugin.moc"
244 #include "plugin.moc"
248
245
249 QTCOMMERCIALCHART_END_NAMESPACE
246 QTCOMMERCIALCHART_END_NAMESPACE
250
247
251 QTCOMMERCIALCHART_USE_NAMESPACE
248 QTCOMMERCIALCHART_USE_NAMESPACE
252
249
253 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
250 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
254 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
251 Q_EXPORT_PLUGIN2(qtcommercialchartqml, QT_PREPEND_NAMESPACE(ChartQmlPlugin))
255 #endif
252 #endif
@@ -1,141 +1,136
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "axisanimation_p.h"
21 #include "axisanimation_p.h"
22 #include "chartaxiselement_p.h"
22 #include "chartaxiselement_p.h"
23 #include "qabstractaxis_p.h"
23 #include "qabstractaxis_p.h"
24
24
25 Q_DECLARE_METATYPE(QVector<qreal>)
25 Q_DECLARE_METATYPE(QVector<qreal>)
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29
29
30 AxisAnimation::AxisAnimation(ChartAxisElement *axis)
30 AxisAnimation::AxisAnimation(ChartAxisElement *axis)
31 : ChartAnimation(axis),
31 : ChartAnimation(axis),
32 m_axis(axis),
32 m_axis(axis),
33 m_type(DefaultAnimation)
33 m_type(DefaultAnimation)
34 {
34 {
35 setDuration(ChartAnimationDuration);
35 setDuration(ChartAnimationDuration);
36 setEasingCurve(QEasingCurve::OutQuart);
36 setEasingCurve(QEasingCurve::OutQuart);
37 }
37 }
38
38
39 AxisAnimation::~AxisAnimation()
39 AxisAnimation::~AxisAnimation()
40 {
40 {
41 }
41 }
42
42
43 void AxisAnimation::setAnimationType(Animation type)
43 void AxisAnimation::setAnimationType(Animation type)
44 {
44 {
45 if (state() != QAbstractAnimation::Stopped)
45 if (state() != QAbstractAnimation::Stopped)
46 stop();
46 stop();
47 m_type = type;
47 m_type = type;
48 }
48 }
49
49
50 void AxisAnimation::setAnimationPoint(const QPointF &point)
50 void AxisAnimation::setAnimationPoint(const QPointF &point)
51 {
51 {
52 if (state() != QAbstractAnimation::Stopped)
52 if (state() != QAbstractAnimation::Stopped)
53 stop();
53 stop();
54 m_point = point;
54 m_point = point;
55 }
55 }
56
56
57 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout)
57 void AxisAnimation::setValues(QVector<qreal> &oldLayout, QVector<qreal> &newLayout)
58 {
58 {
59 if (state() != QAbstractAnimation::Stopped) stop();
59 if (state() != QAbstractAnimation::Stopped) stop();
60
60
61 // TODO: cannot return even if layout is empty
62 // New layout is not set properly without it (crash)
63 // if (newLayout.count() == 0)
64 // return;
65
66 switch (m_type) {
61 switch (m_type) {
67 case ZoomOutAnimation: {
62 case ZoomOutAnimation: {
68 QRectF rect = m_axis->gridGeometry();
63 QRectF rect = m_axis->gridGeometry();
69 oldLayout.resize(newLayout.count());
64 oldLayout.resize(newLayout.count());
70
65
71 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
66 for (int i = 0, j = oldLayout.count() - 1; i < (oldLayout.count() + 1) / 2; ++i, --j) {
72 oldLayout[i] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
67 oldLayout[i] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.left() : rect.bottom();
73 oldLayout[j] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.right() : rect.top();
68 oldLayout[j] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.right() : rect.top();
74 }
69 }
75 }
70 }
76 break;
71 break;
77 case ZoomInAnimation: {
72 case ZoomInAnimation: {
78 int index = qMin(oldLayout.count() * (m_axis->axis()->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
73 int index = qMin(oldLayout.count() * (m_axis->axis()->orientation() == Qt::Horizontal ? m_point.x() : (1 - m_point.y())), newLayout.count() - (qreal)1.0);
79 oldLayout.resize(newLayout.count());
74 oldLayout.resize(newLayout.count());
80
75
81 for (int i = 0; i < oldLayout.count(); i++)
76 for (int i = 0; i < oldLayout.count(); i++)
82 oldLayout[i] = oldLayout[index];
77 oldLayout[i] = oldLayout[index];
83 }
78 }
84 break;
79 break;
85 case MoveForwardAnimation: {
80 case MoveForwardAnimation: {
86 oldLayout.resize(newLayout.count());
81 oldLayout.resize(newLayout.count());
87
82
88 for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
83 for (int i = 0, j = i + 1; i < oldLayout.count() - 1; ++i, ++j)
89 oldLayout[i] = oldLayout[j];
84 oldLayout[i] = oldLayout[j];
90 }
85 }
91 break;
86 break;
92 case MoveBackwordAnimation: {
87 case MoveBackwordAnimation: {
93 oldLayout.resize(newLayout.count());
88 oldLayout.resize(newLayout.count());
94
89
95 for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
90 for (int i = oldLayout.count() - 1, j = i - 1; i > 0; --i, --j)
96 oldLayout[i] = oldLayout[j];
91 oldLayout[i] = oldLayout[j];
97 }
92 }
98 break;
93 break;
99 default: {
94 default: {
100 oldLayout.resize(newLayout.count());
95 oldLayout.resize(newLayout.count());
101 QRectF rect = m_axis->gridGeometry();
96 QRectF rect = m_axis->gridGeometry();
102 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
97 for (int i = 0, j = oldLayout.count() - 1; i < oldLayout.count(); ++i, --j)
103 oldLayout[i] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.left() : rect.top();
98 oldLayout[i] = m_axis->axis()->orientation() == Qt::Horizontal ? rect.left() : rect.top();
104 }
99 }
105 break;
100 break;
106 }
101 }
107
102
108 QVariantAnimation::KeyValues value;
103 QVariantAnimation::KeyValues value;
109 setKeyValues(value); //workaround for wrong interpolation call
104 setKeyValues(value); //workaround for wrong interpolation call
110 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
105 setKeyValueAt(0.0, qVariantFromValue(oldLayout));
111 setKeyValueAt(1.0, qVariantFromValue(newLayout));
106 setKeyValueAt(1.0, qVariantFromValue(newLayout));
112 }
107 }
113
108
114 QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
109 QVariant AxisAnimation::interpolated(const QVariant &start, const QVariant &end, qreal progress) const
115 {
110 {
116 QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start);
111 QVector<qreal> startVector = qvariant_cast<QVector<qreal> >(start);
117 QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end);
112 QVector<qreal> endVecotr = qvariant_cast<QVector<qreal> >(end);
118 QVector<qreal> result;
113 QVector<qreal> result;
119
114
120 Q_ASSERT(startVector.count() == endVecotr.count()) ;
115 Q_ASSERT(startVector.count() == endVecotr.count()) ;
121
116
122 for (int i = 0; i < startVector.count(); i++) {
117 for (int i = 0; i < startVector.count(); i++) {
123 qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0));
118 qreal value = startVector[i] + ((endVecotr[i] - startVector[i]) * progress); //qBound(0.0, progress, 1.0));
124 result << value;
119 result << value;
125 }
120 }
126 return qVariantFromValue(result);
121 return qVariantFromValue(result);
127 }
122 }
128
123
129
124
130 void AxisAnimation::updateCurrentValue(const QVariant &value)
125 void AxisAnimation::updateCurrentValue(const QVariant &value)
131 {
126 {
132 if (state() != QAbstractAnimation::Stopped) { //workaround
127 if (state() != QAbstractAnimation::Stopped) { //workaround
133 QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value);
128 QVector<qreal> vector = qvariant_cast<QVector<qreal> >(value);
134 // Q_ASSERT(vector.count() != 0);
129 // Q_ASSERT(vector.count() != 0);
135 m_axis->setLayout(vector);
130 m_axis->setLayout(vector);
136 m_axis->updateGeometry();
131 m_axis->updateGeometry();
137 }
132 }
138
133
139 }
134 }
140
135
141 QTCOMMERCIALCHART_END_NAMESPACE
136 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,191 +1,189
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "abstractdomain_p.h"
26 #include "abstractdomain_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
35
36 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
34 AreaChartItem::AreaChartItem(QAreaSeries *areaSeries, QGraphicsItem* item)
37 : ChartItem(areaSeries->d_func(),item),
35 : ChartItem(areaSeries->d_func(),item),
38 m_series(areaSeries),
36 m_series(areaSeries),
39 m_upper(0),
37 m_upper(0),
40 m_lower(0),
38 m_lower(0),
41 m_pointsVisible(false)
39 m_pointsVisible(false)
42 {
40 {
43 setAcceptHoverEvents(true);
41 setAcceptHoverEvents(true);
44 setZValue(ChartPresenter::LineChartZValue);
42 setZValue(ChartPresenter::LineChartZValue);
45 m_upper = new AreaBoundItem(this, m_series->upperSeries());
43 m_upper = new AreaBoundItem(this, m_series->upperSeries());
46 if (m_series->lowerSeries())
44 if (m_series->lowerSeries())
47 m_lower = new AreaBoundItem(this, m_series->lowerSeries());
45 m_lower = new AreaBoundItem(this, m_series->lowerSeries());
48
46
49 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
47 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
50 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
48 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
51 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
49 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
52 QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF)));
50 QObject::connect(this, SIGNAL(clicked(QPointF)), areaSeries, SIGNAL(clicked(QPointF)));
53 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool)));
51 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), areaSeries, SIGNAL(hovered(QPointF,bool)));
54
52
55 handleUpdated();
53 handleUpdated();
56 }
54 }
57
55
58 AreaChartItem::~AreaChartItem()
56 AreaChartItem::~AreaChartItem()
59 {
57 {
60 delete m_upper;
58 delete m_upper;
61 delete m_lower;
59 delete m_lower;
62 }
60 }
63
61
64 void AreaChartItem::setPresenter(ChartPresenter *presenter)
62 void AreaChartItem::setPresenter(ChartPresenter *presenter)
65 {
63 {
66 m_upper->setPresenter(presenter);
64 m_upper->setPresenter(presenter);
67 if (m_lower) {
65 if (m_lower) {
68 m_lower->setPresenter(presenter);
66 m_lower->setPresenter(presenter);
69 }
67 }
70 ChartItem::setPresenter(presenter);
68 ChartItem::setPresenter(presenter);
71 }
69 }
72
70
73 QRectF AreaChartItem::boundingRect() const
71 QRectF AreaChartItem::boundingRect() const
74 {
72 {
75 return m_rect;
73 return m_rect;
76 }
74 }
77
75
78 QPainterPath AreaChartItem::shape() const
76 QPainterPath AreaChartItem::shape() const
79 {
77 {
80 return m_path;
78 return m_path;
81 }
79 }
82
80
83 void AreaChartItem::updatePath()
81 void AreaChartItem::updatePath()
84 {
82 {
85 QPainterPath path;
83 QPainterPath path;
86 QRectF rect(QPointF(0,0),domain()->size());
84 QRectF rect(QPointF(0,0),domain()->size());
87
85
88 path = m_upper->path();
86 path = m_upper->path();
89
87
90 if (m_lower) {
88 if (m_lower) {
91 // Note: Polarcharts always draw area correctly only when both series have equal width or are
89 // Note: Polarcharts always draw area correctly only when both series have equal width or are
92 // fully displayed. If one series is partally off-chart, the connecting line between
90 // fully displayed. If one series is partally off-chart, the connecting line between
93 // the series does not attach to the end of the partially hidden series but to the point
91 // the series does not attach to the end of the partially hidden series but to the point
94 // where it intersects the axis line. The problem is especially noticeable when one of the series
92 // where it intersects the axis line. The problem is especially noticeable when one of the series
95 // is entirely off-chart, in which case the connecting line connects two ends of the
93 // is entirely off-chart, in which case the connecting line connects two ends of the
96 // visible series.
94 // visible series.
97 // This happens because we get the paths from linechart, which omits off-chart segments.
95 // This happens because we get the paths from linechart, which omits off-chart segments.
98 // To properly fix, linechart would need to provide true full path, in right, left, and the rest
96 // To properly fix, linechart would need to provide true full path, in right, left, and the rest
99 // portions to enable proper clipping. However, combining those to single visually unified area
97 // portions to enable proper clipping. However, combining those to single visually unified area
100 // would be a nightmare, since they would have to be painted separately.
98 // would be a nightmare, since they would have to be painted separately.
101 path.connectPath(m_lower->path().toReversed());
99 path.connectPath(m_lower->path().toReversed());
102 } else {
100 } else {
103 QPointF first = path.pointAtPercent(0);
101 QPointF first = path.pointAtPercent(0);
104 QPointF last = path.pointAtPercent(1);
102 QPointF last = path.pointAtPercent(1);
105 if (presenter()->chartType() == QChart::ChartTypeCartesian) {
103 if (presenter()->chartType() == QChart::ChartTypeCartesian) {
106 path.lineTo(last.x(), rect.bottom());
104 path.lineTo(last.x(), rect.bottom());
107 path.lineTo(first.x(), rect.bottom());
105 path.lineTo(first.x(), rect.bottom());
108 } else { // polar
106 } else { // polar
109 path.lineTo(rect.center());
107 path.lineTo(rect.center());
110 }
108 }
111 }
109 }
112 path.closeSubpath();
110 path.closeSubpath();
113 prepareGeometryChange();
111 prepareGeometryChange();
114 m_path = path;
112 m_path = path;
115 m_rect = path.boundingRect();
113 m_rect = path.boundingRect();
116 update();
114 update();
117 }
115 }
118
116
119 void AreaChartItem::handleUpdated()
117 void AreaChartItem::handleUpdated()
120 {
118 {
121 setVisible(m_series->isVisible());
119 setVisible(m_series->isVisible());
122 m_pointsVisible = m_series->pointsVisible();
120 m_pointsVisible = m_series->pointsVisible();
123 m_linePen = m_series->pen();
121 m_linePen = m_series->pen();
124 m_brush = m_series->brush();
122 m_brush = m_series->brush();
125 m_pointPen = m_series->pen();
123 m_pointPen = m_series->pen();
126 m_pointPen.setWidthF(2 * m_pointPen.width());
124 m_pointPen.setWidthF(2 * m_pointPen.width());
127 setOpacity(m_series->opacity());
125 setOpacity(m_series->opacity());
128 update();
126 update();
129 }
127 }
130
128
131 void AreaChartItem::handleDomainUpdated()
129 void AreaChartItem::handleDomainUpdated()
132 {
130 {
133 AbstractDomain* d = m_upper->domain();
131 AbstractDomain* d = m_upper->domain();
134
132
135 d->setSize(domain()->size());
133 d->setSize(domain()->size());
136 d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
134 d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
137 m_upper->handleDomainUpdated();
135 m_upper->handleDomainUpdated();
138
136
139 if (m_lower) {
137 if (m_lower) {
140 AbstractDomain* d = m_lower->domain();
138 AbstractDomain* d = m_lower->domain();
141 d->setSize(domain()->size());
139 d->setSize(domain()->size());
142 d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
140 d->setRange(domain()->minX(),domain()->maxX(),domain()->minY(),domain()->maxY());
143 m_lower->handleDomainUpdated();
141 m_lower->handleDomainUpdated();
144 }
142 }
145 }
143 }
146
144
147 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
145 void AreaChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
148 {
146 {
149 Q_UNUSED(widget)
147 Q_UNUSED(widget)
150 Q_UNUSED(option)
148 Q_UNUSED(option)
151 painter->save();
149 painter->save();
152 painter->setPen(m_linePen);
150 painter->setPen(m_linePen);
153 painter->setBrush(m_brush);
151 painter->setBrush(m_brush);
154 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
152 QRectF clipRect = QRectF(QPointF(0, 0), domain()->size());
155 if (presenter()->chartType() == QChart::ChartTypePolar)
153 if (presenter()->chartType() == QChart::ChartTypePolar)
156 painter->setClipRegion(QRegion(clipRect.toRect(), QRegion::Ellipse));
154 painter->setClipRegion(QRegion(clipRect.toRect(), QRegion::Ellipse));
157 else
155 else
158 painter->setClipRect(clipRect);
156 painter->setClipRect(clipRect);
159 painter->drawPath(m_path);
157 painter->drawPath(m_path);
160 if (m_pointsVisible) {
158 if (m_pointsVisible) {
161 painter->setPen(m_pointPen);
159 painter->setPen(m_pointPen);
162 painter->drawPoints(m_upper->geometryPoints());
160 painter->drawPoints(m_upper->geometryPoints());
163 if (m_lower)
161 if (m_lower)
164 painter->drawPoints(m_lower->geometryPoints());
162 painter->drawPoints(m_lower->geometryPoints());
165 }
163 }
166 painter->restore();
164 painter->restore();
167 }
165 }
168
166
169 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
167 void AreaChartItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
170 {
168 {
171 emit clicked(m_upper->domain()->calculateDomainPoint(event->pos()));
169 emit clicked(m_upper->domain()->calculateDomainPoint(event->pos()));
172 ChartItem::mousePressEvent(event);
170 ChartItem::mousePressEvent(event);
173 }
171 }
174
172
175 void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
173 void AreaChartItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
176 {
174 {
177 emit hovered(domain()->calculateDomainPoint(event->pos()), true);
175 emit hovered(domain()->calculateDomainPoint(event->pos()), true);
178 event->accept();
176 event->accept();
179 // QGraphicsItem::hoverEnterEvent(event);
177 // QGraphicsItem::hoverEnterEvent(event);
180 }
178 }
181
179
182 void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
180 void AreaChartItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
183 {
181 {
184 emit hovered(domain()->calculateDomainPoint(event->pos()), false);
182 emit hovered(domain()->calculateDomainPoint(event->pos()), false);
185 event->accept();
183 event->accept();
186 // QGraphicsItem::hoverEnterEvent(event);
184 // QGraphicsItem::hoverEnterEvent(event);
187 }
185 }
188
186
189 #include "moc_areachartitem_p.cpp"
187 #include "moc_areachartitem_p.cpp"
190
188
191 QTCOMMERCIALCHART_END_NAMESPACE
189 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,118 +1,117
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "chartcategoryaxisx_p.h"
21 #include "chartcategoryaxisx_p.h"
22 #include "qcategoryaxis.h"
22 #include "qcategoryaxis.h"
23 #include "qabstractaxis.h"
23 #include "qabstractaxis.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractchartlayout_p.h"
25 #include "abstractchartlayout_p.h"
26 #include <QGraphicsLayout>
26 #include <QGraphicsLayout>
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item)
31 ChartCategoryAxisX::ChartCategoryAxisX(QCategoryAxis *axis, QGraphicsItem* item)
32 : HorizontalAxis(axis, item, true),
32 : HorizontalAxis(axis, item, true),
33 m_axis(axis)
33 m_axis(axis)
34 {
34 {
35 QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged()));
35 QObject::connect(axis, SIGNAL(categoriesChanged()), this, SLOT(handleCategoriesChanged()));
36 }
36 }
37
37
38 ChartCategoryAxisX::~ChartCategoryAxisX()
38 ChartCategoryAxisX::~ChartCategoryAxisX()
39 {
39 {
40 }
40 }
41
41
42 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
42 QVector<qreal> ChartCategoryAxisX::calculateLayout() const
43 {
43 {
44 int tickCount = m_axis->categoriesLabels().count() + 1;
44 int tickCount = m_axis->categoriesLabels().count() + 1;
45 QVector<qreal> points;
45 QVector<qreal> points;
46
46
47 if (tickCount < 2)
47 if (tickCount < 2)
48 return points;
48 return points;
49
49
50 const QRectF &gridRect = gridGeometry();
50 const QRectF &gridRect = gridGeometry();
51 qreal range = max() - min();
51 qreal range = max() - min();
52 if (range > 0) {
52 if (range > 0) {
53 points.resize(tickCount);
53 points.resize(tickCount);
54 qreal scale = gridRect.width() / range;
54 qreal scale = gridRect.width() / range;
55 for (int i = 0; i < tickCount; ++i) {
55 for (int i = 0; i < tickCount; ++i) {
56 if (i < tickCount - 1) {
56 if (i < tickCount - 1) {
57 qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left();
57 qreal x = (m_axis->startValue(m_axis->categoriesLabels().at(i)) - min()) * scale + gridRect.left();
58 points[i] = x;
58 points[i] = x;
59 } else {
59 } else {
60 qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left();
60 qreal x = (m_axis->endValue(m_axis->categoriesLabels().at(i - 1)) - min()) * scale + gridRect.left();
61 points[i] = x;
61 points[i] = x;
62 }
62 }
63 }
63 }
64 }
64 }
65
65
66 return points;
66 return points;
67 }
67 }
68
68
69 void ChartCategoryAxisX::updateGeometry()
69 void ChartCategoryAxisX::updateGeometry()
70 {
70 {
71 //TODO: this is not optimal when many categories :( , create only visible lables
72 setLabels(m_axis->categoriesLabels() << "");
71 setLabels(m_axis->categoriesLabels() << "");
73 HorizontalAxis::updateGeometry();
72 HorizontalAxis::updateGeometry();
74 }
73 }
75
74
76 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
75 QSizeF ChartCategoryAxisX::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
77 {
76 {
78 Q_UNUSED(constraint)
77 Q_UNUSED(constraint)
79
78
80 QSizeF sh;
79 QSizeF sh;
81 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
80 QSizeF base = HorizontalAxis::sizeHint(which, constraint);
82 QStringList ticksList = m_axis->categoriesLabels();
81 QStringList ticksList = m_axis->categoriesLabels();
83 qreal width = 0; // Width is irrelevant for X axes with interval labels
82 qreal width = 0; // Width is irrelevant for X axes with interval labels
84 qreal height = 0;
83 qreal height = 0;
85
84
86 switch (which) {
85 switch (which) {
87 case Qt::MinimumSize: {
86 case Qt::MinimumSize: {
88 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
87 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), "...", axis()->labelsAngle());
89 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
88 height = boundingRect.height() + labelPadding() + base.height() + 1.0;
90 sh = QSizeF(width, height);
89 sh = QSizeF(width, height);
91 break;
90 break;
92 }
91 }
93 case Qt::PreferredSize: {
92 case Qt::PreferredSize: {
94 qreal labelHeight = 0.0;
93 qreal labelHeight = 0.0;
95 foreach (const QString& s, ticksList) {
94 foreach (const QString& s, ticksList) {
96 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
95 QRectF rect = ChartPresenter::textBoundingRect(axis()->labelsFont(), s, axis()->labelsAngle());
97 labelHeight = qMax(rect.height(), labelHeight);
96 labelHeight = qMax(rect.height(), labelHeight);
98 }
97 }
99 height = labelHeight + labelPadding() + base.height() + 1.0;
98 height = labelHeight + labelPadding() + base.height() + 1.0;
100 sh = QSizeF(width, height);
99 sh = QSizeF(width, height);
101 break;
100 break;
102 }
101 }
103 default:
102 default:
104 break;
103 break;
105 }
104 }
106
105
107 return sh;
106 return sh;
108 }
107 }
109
108
110 void ChartCategoryAxisX::handleCategoriesChanged()
109 void ChartCategoryAxisX::handleCategoriesChanged()
111 {
110 {
112 QGraphicsLayoutItem::updateGeometry();
111 QGraphicsLayoutItem::updateGeometry();
113 presenter()->layout()->invalidate();
112 presenter()->layout()->invalidate();
114 }
113 }
115
114
116 #include "moc_chartcategoryaxisx_p.cpp"
115 #include "moc_chartcategoryaxisx_p.cpp"
117
116
118 QTCOMMERCIALCHART_END_NAMESPACE
117 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,423 +1,420
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "polarchartaxisangular_p.h"
21 #include "polarchartaxisangular_p.h"
22 #include "chartpresenter_p.h"
22 #include "chartpresenter_p.h"
23 #include "abstractchartlayout_p.h"
23 #include "abstractchartlayout_p.h"
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25 #include "qabstractaxis_p.h"
25 #include "qabstractaxis_p.h"
26 #include <QDebug>
26 #include <QDebug>
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 PolarChartAxisAngular::PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
31 PolarChartAxisAngular::PolarChartAxisAngular(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis)
32 : PolarChartAxis(axis, item, intervalAxis)
32 : PolarChartAxis(axis, item, intervalAxis)
33 {
33 {
34 }
34 }
35
35
36 PolarChartAxisAngular::~PolarChartAxisAngular()
36 PolarChartAxisAngular::~PolarChartAxisAngular()
37 {
37 {
38 }
38 }
39
39
40 void PolarChartAxisAngular::updateGeometry()
40 void PolarChartAxisAngular::updateGeometry()
41 {
41 {
42 QGraphicsLayoutItem::updateGeometry();
42 QGraphicsLayoutItem::updateGeometry();
43
43
44 const QVector<qreal> &layout = this->layout();
44 const QVector<qreal> &layout = this->layout();
45 if (layout.isEmpty())
45 if (layout.isEmpty())
46 return;
46 return;
47
47
48 createAxisLabels(layout);
48 createAxisLabels(layout);
49 QStringList labelList = labels();
49 QStringList labelList = labels();
50 QPointF center = axisGeometry().center();
50 QPointF center = axisGeometry().center();
51 QList<QGraphicsItem *> arrowItemList = arrowItems();
51 QList<QGraphicsItem *> arrowItemList = arrowItems();
52 QList<QGraphicsItem *> gridItemList = gridItems();
52 QList<QGraphicsItem *> gridItemList = gridItems();
53 QList<QGraphicsItem *> labelItemList = labelItems();
53 QList<QGraphicsItem *> labelItemList = labelItems();
54 QList<QGraphicsItem *> shadeItemList = shadeItems();
54 QList<QGraphicsItem *> shadeItemList = shadeItems();
55 QGraphicsTextItem *title = titleItem();
55 QGraphicsTextItem *title = titleItem();
56
56
57 QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0));
57 QGraphicsEllipseItem *axisLine = static_cast<QGraphicsEllipseItem *>(arrowItemList.at(0));
58 axisLine->setRect(axisGeometry());
58 axisLine->setRect(axisGeometry());
59
59
60 qreal radius = axisGeometry().height() / 2.0;
60 qreal radius = axisGeometry().height() / 2.0;
61
61
62 QRectF previousLabelRect;
62 QRectF previousLabelRect;
63 QRectF firstLabelRect;
63 QRectF firstLabelRect;
64
64
65 qreal labelHeight = 0;
65 qreal labelHeight = 0;
66
66
67 bool firstShade = true;
67 bool firstShade = true;
68 bool nextTickVisible = false;
68 bool nextTickVisible = false;
69 if (layout.size())
69 if (layout.size())
70 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > 360.0);
70 nextTickVisible = !(layout.at(0) < 0.0 || layout.at(0) > 360.0);
71
71
72 for (int i = 0; i < layout.size(); ++i) {
72 for (int i = 0; i < layout.size(); ++i) {
73 qreal angularCoordinate = layout.at(i);
73 qreal angularCoordinate = layout.at(i);
74
74
75 QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i));
75 QGraphicsLineItem *gridLineItem = static_cast<QGraphicsLineItem *>(gridItemList.at(i));
76 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
76 QGraphicsLineItem *tickItem = static_cast<QGraphicsLineItem *>(arrowItemList.at(i + 1));
77 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
77 QGraphicsTextItem *labelItem = static_cast<QGraphicsTextItem *>(labelItemList.at(i));
78 QGraphicsPathItem *shadeItem = 0;
78 QGraphicsPathItem *shadeItem = 0;
79 if (i == 0)
79 if (i == 0)
80 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
80 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
81 else if (i % 2)
81 else if (i % 2)
82 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
82 shadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at((i / 2) + 1));
83
83
84 // Ignore ticks outside valid range
84 // Ignore ticks outside valid range
85 bool currentTickVisible = nextTickVisible;
85 bool currentTickVisible = nextTickVisible;
86 if ((i == layout.size() - 1)
86 if ((i == layout.size() - 1)
87 || layout.at(i + 1) < 0.0
87 || layout.at(i + 1) < 0.0
88 || layout.at(i + 1) > 360.0) {
88 || layout.at(i + 1) > 360.0) {
89 nextTickVisible = false;
89 nextTickVisible = false;
90 } else {
90 } else {
91 nextTickVisible = true;
91 nextTickVisible = true;
92 }
92 }
93
93
94 qreal labelCoordinate = angularCoordinate;
94 qreal labelCoordinate = angularCoordinate;
95 qreal labelVisible = currentTickVisible;
95 qreal labelVisible = currentTickVisible;
96 if (intervalAxis()) {
96 if (intervalAxis()) {
97 qreal farEdge;
97 qreal farEdge;
98 if (i == (layout.size() - 1))
98 if (i == (layout.size() - 1))
99 farEdge = 360.0;
99 farEdge = 360.0;
100 else
100 else
101 farEdge = qMin(qreal(360.0), layout.at(i + 1));
101 farEdge = qMin(qreal(360.0), layout.at(i + 1));
102
102
103 // Adjust the labelCoordinate to show it if next tick is visible
103 // Adjust the labelCoordinate to show it if next tick is visible
104 if (nextTickVisible)
104 if (nextTickVisible)
105 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
105 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
106
106
107 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
107 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
108 // Don't display label once the category gets too small near the axis
108 // Don't display label once the category gets too small near the axis
109 if (labelCoordinate < 5.0 || labelCoordinate > 355.0)
109 if (labelCoordinate < 5.0 || labelCoordinate > 355.0)
110 labelVisible = false;
110 labelVisible = false;
111 else
111 else
112 labelVisible = true;
112 labelVisible = true;
113 }
113 }
114
114
115 // Need this also in label calculations, so determine it first
115 // Need this also in label calculations, so determine it first
116 QLineF tickLine(QLineF::fromPolar(radius - tickWidth(), 90.0 - angularCoordinate).p2(),
116 QLineF tickLine(QLineF::fromPolar(radius - tickWidth(), 90.0 - angularCoordinate).p2(),
117 QLineF::fromPolar(radius + tickWidth(), 90.0 - angularCoordinate).p2());
117 QLineF::fromPolar(radius + tickWidth(), 90.0 - angularCoordinate).p2());
118 tickLine.translate(center);
118 tickLine.translate(center);
119
119
120 // Angular axis label
120 // Angular axis label
121 if (axis()->labelsVisible() && labelVisible) {
121 if (axis()->labelsVisible() && labelVisible) {
122 labelItem->setHtml(labelList.at(i));
122 labelItem->setHtml(labelList.at(i));
123 const QRectF &rect = labelItem->boundingRect();
123 const QRectF &rect = labelItem->boundingRect();
124 QPointF labelCenter = rect.center();
124 QPointF labelCenter = rect.center();
125 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
125 labelItem->setTransformOriginPoint(labelCenter.x(), labelCenter.y());
126 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
126 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
127 boundingRect.moveCenter(labelCenter);
127 boundingRect.moveCenter(labelCenter);
128 QPointF positionDiff(rect.topLeft() - boundingRect.topLeft());
128 QPointF positionDiff(rect.topLeft() - boundingRect.topLeft());
129
129
130 QPointF labelPoint;
130 QPointF labelPoint;
131 if (intervalAxis()) {
131 if (intervalAxis()) {
132 QLineF labelLine = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate);
132 QLineF labelLine = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate);
133 labelLine.translate(center);
133 labelLine.translate(center);
134 labelPoint = labelLine.p2();
134 labelPoint = labelLine.p2();
135 } else {
135 } else {
136 labelPoint = tickLine.p2();
136 labelPoint = tickLine.p2();
137 }
137 }
138
138
139 QRectF labelRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
139 QRectF labelRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
140 labelItem->setPos(labelRect.topLeft() + positionDiff);
140 labelItem->setPos(labelRect.topLeft() + positionDiff);
141
141
142 // Store height for title calculations
142 // Store height for title calculations
143 qreal labelClearance = axisGeometry().top() - labelRect.top();
143 qreal labelClearance = axisGeometry().top() - labelRect.top();
144 labelHeight = qMax(labelHeight, labelClearance);
144 labelHeight = qMax(labelHeight, labelClearance);
145
145
146 // Label overlap detection
146 // Label overlap detection
147 if (i && (previousLabelRect.intersects(labelRect) || firstLabelRect.intersects(labelRect))) {
147 if (i && (previousLabelRect.intersects(labelRect) || firstLabelRect.intersects(labelRect))) {
148 labelVisible = false;
148 labelVisible = false;
149 } else {
149 } else {
150 // Store labelRect for future comparison. Some area is deducted to make things look
150 // Store labelRect for future comparison. Some area is deducted to make things look
151 // little nicer, as usually intersection happens at label corner with angular labels.
151 // little nicer, as usually intersection happens at label corner with angular labels.
152 labelRect.adjust(-2.0, -4.0, -2.0, -4.0);
152 labelRect.adjust(-2.0, -4.0, -2.0, -4.0);
153 if (firstLabelRect.isEmpty())
153 if (firstLabelRect.isEmpty())
154 firstLabelRect = labelRect;
154 firstLabelRect = labelRect;
155
155
156 previousLabelRect = labelRect;
156 previousLabelRect = labelRect;
157 labelVisible = true;
157 labelVisible = true;
158 }
158 }
159 }
159 }
160
160
161 labelItem->setVisible(labelVisible);
161 labelItem->setVisible(labelVisible);
162 if (!currentTickVisible) {
162 if (!currentTickVisible) {
163 gridLineItem->setVisible(false);
163 gridLineItem->setVisible(false);
164 tickItem->setVisible(false);
164 tickItem->setVisible(false);
165 if (shadeItem)
165 if (shadeItem)
166 shadeItem->setVisible(false);
166 shadeItem->setVisible(false);
167 continue;
167 continue;
168 }
168 }
169
169
170 // Angular grid line
170 // Angular grid line
171 QLineF gridLine = QLineF::fromPolar(radius, 90.0 - angularCoordinate);
171 QLineF gridLine = QLineF::fromPolar(radius, 90.0 - angularCoordinate);
172 gridLine.translate(center);
172 gridLine.translate(center);
173 gridLineItem->setLine(gridLine);
173 gridLineItem->setLine(gridLine);
174 gridLineItem->setVisible(true);
174 gridLineItem->setVisible(true);
175
175
176 // Tick
176 // Tick
177 tickItem->setLine(tickLine);
177 tickItem->setLine(tickLine);
178 tickItem->setVisible(true);
178 tickItem->setVisible(true);
179
179
180 // Shades
180 // Shades
181 if (i % 2 || (i == 0 && !nextTickVisible)) {
181 if (i % 2 || (i == 0 && !nextTickVisible)) {
182 QPainterPath path;
182 QPainterPath path;
183 path.moveTo(center);
183 path.moveTo(center);
184 if (i == 0) {
184 if (i == 0) {
185 // If first tick is also the last, we need to custom fill the first partial arc
185 // If first tick is also the last, we need to custom fill the first partial arc
186 // or it won't get filled.
186 // or it won't get filled.
187 path.arcTo(axisGeometry(), 90.0 - layout.at(0), layout.at(0));
187 path.arcTo(axisGeometry(), 90.0 - layout.at(0), layout.at(0));
188 path.closeSubpath();
188 path.closeSubpath();
189 } else {
189 } else {
190 qreal nextCoordinate;
190 qreal nextCoordinate;
191 if (!nextTickVisible) // Last visible tick
191 if (!nextTickVisible) // Last visible tick
192 nextCoordinate = 360.0;
192 nextCoordinate = 360.0;
193 else
193 else
194 nextCoordinate = layout.at(i + 1);
194 nextCoordinate = layout.at(i + 1);
195 qreal arcSpan = angularCoordinate - nextCoordinate;
195 qreal arcSpan = angularCoordinate - nextCoordinate;
196 path.arcTo(axisGeometry(), 90.0 - angularCoordinate, arcSpan);
196 path.arcTo(axisGeometry(), 90.0 - angularCoordinate, arcSpan);
197 path.closeSubpath();
197 path.closeSubpath();
198
198
199 // Add additional arc for first shade item if there is a partial arc to be filled
199 // Add additional arc for first shade item if there is a partial arc to be filled
200 if (firstShade) {
200 if (firstShade) {
201 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
201 QGraphicsPathItem *specialShadeItem = static_cast<QGraphicsPathItem *>(shadeItemList.at(0));
202 if (layout.at(i - 1) > 0.0) {
202 if (layout.at(i - 1) > 0.0) {
203 QPainterPath specialPath;
203 QPainterPath specialPath;
204 specialPath.moveTo(center);
204 specialPath.moveTo(center);
205 specialPath.arcTo(axisGeometry(), 90.0 - layout.at(i - 1), layout.at(i - 1));
205 specialPath.arcTo(axisGeometry(), 90.0 - layout.at(i - 1), layout.at(i - 1));
206 specialPath.closeSubpath();
206 specialPath.closeSubpath();
207 specialShadeItem->setPath(specialPath);
207 specialShadeItem->setPath(specialPath);
208 specialShadeItem->setVisible(true);
208 specialShadeItem->setVisible(true);
209 } else {
209 } else {
210 specialShadeItem->setVisible(false);
210 specialShadeItem->setVisible(false);
211 }
211 }
212 }
212 }
213 }
213 }
214 shadeItem->setPath(path);
214 shadeItem->setPath(path);
215 shadeItem->setVisible(true);
215 shadeItem->setVisible(true);
216 firstShade = false;
216 firstShade = false;
217 }
217 }
218 }
218 }
219
219
220 // Title, centered above the chart
220 // Title, centered above the chart
221 QString titleText = axis()->titleText();
221 QString titleText = axis()->titleText();
222 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
222 if (!titleText.isEmpty() && axis()->isTitleVisible()) {
223 QRectF dummyRect;
223 QRectF dummyRect;
224 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), axisGeometry().width(), Qt::Horizontal, dummyRect));
224 title->setHtml(ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), axisGeometry().width(), Qt::Horizontal, dummyRect));
225
225
226 QRectF titleBoundingRect = title->boundingRect();
226 QRectF titleBoundingRect = title->boundingRect();
227 QPointF titleCenter = center - titleBoundingRect.center();
227 QPointF titleCenter = center - titleBoundingRect.center();
228 title->setPos(titleCenter.x(), axisGeometry().top() - titlePadding() * 2.0 - titleBoundingRect.height() - labelHeight);
228 title->setPos(titleCenter.x(), axisGeometry().top() - titlePadding() * 2.0 - titleBoundingRect.height() - labelHeight);
229 }
229 }
230 }
230 }
231
231
232 Qt::Orientation PolarChartAxisAngular::orientation() const
232 Qt::Orientation PolarChartAxisAngular::orientation() const
233 {
233 {
234 return Qt::Horizontal;
234 return Qt::Horizontal;
235 }
235 }
236
236
237 void PolarChartAxisAngular::createItems(int count)
237 void PolarChartAxisAngular::createItems(int count)
238 {
238 {
239 if (arrowItems().count() == 0) {
239 if (arrowItems().count() == 0) {
240 // angular axis line
240 // angular axis line
241 // TODO: need class similar to LineArrowItem for click handling?
242 QGraphicsEllipseItem *arrow = new QGraphicsEllipseItem(presenter()->rootItem());
241 QGraphicsEllipseItem *arrow = new QGraphicsEllipseItem(presenter()->rootItem());
243 arrow->setPen(axis()->linePen());
242 arrow->setPen(axis()->linePen());
244 arrowGroup()->addToGroup(arrow);
243 arrowGroup()->addToGroup(arrow);
245 }
244 }
246
245
247 for (int i = 0; i < count; ++i) {
246 for (int i = 0; i < count; ++i) {
248 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
247 QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem());
249 QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem());
248 QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem());
250 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
249 QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem());
251 QGraphicsTextItem *title = titleItem();
250 QGraphicsTextItem *title = titleItem();
252 arrow->setPen(axis()->linePen());
251 arrow->setPen(axis()->linePen());
253 grid->setPen(axis()->gridLinePen());
252 grid->setPen(axis()->gridLinePen());
254 label->setFont(axis()->labelsFont());
253 label->setFont(axis()->labelsFont());
255 label->setDefaultTextColor(axis()->labelsBrush().color());
254 label->setDefaultTextColor(axis()->labelsBrush().color());
256 label->setRotation(axis()->labelsAngle());
255 label->setRotation(axis()->labelsAngle());
257 title->setFont(axis()->titleFont());
256 title->setFont(axis()->titleFont());
258 title->setDefaultTextColor(axis()->titleBrush().color());
257 title->setDefaultTextColor(axis()->titleBrush().color());
259 title->setHtml(axis()->titleText());
258 title->setHtml(axis()->titleText());
260 arrowGroup()->addToGroup(arrow);
259 arrowGroup()->addToGroup(arrow);
261 gridGroup()->addToGroup(grid);
260 gridGroup()->addToGroup(grid);
262 labelGroup()->addToGroup(label);
261 labelGroup()->addToGroup(label);
263 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
262 if (gridItems().size() == 1 || (((gridItems().size() + 1) % 2) && gridItems().size() > 0)) {
264 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
263 QGraphicsPathItem *shade = new QGraphicsPathItem(presenter()->rootItem());
265 shade->setPen(axis()->shadesPen());
264 shade->setPen(axis()->shadesPen());
266 shade->setBrush(axis()->shadesBrush());
265 shade->setBrush(axis()->shadesBrush());
267 shadeGroup()->addToGroup(shade);
266 shadeGroup()->addToGroup(shade);
268 }
267 }
269 }
268 }
270 }
269 }
271
270
272 void PolarChartAxisAngular::handleArrowPenChanged(const QPen &pen)
271 void PolarChartAxisAngular::handleArrowPenChanged(const QPen &pen)
273 {
272 {
274 bool first = true;
273 bool first = true;
275 foreach (QGraphicsItem *item, arrowItems()) {
274 foreach (QGraphicsItem *item, arrowItems()) {
276 if (first) {
275 if (first) {
277 first = false;
276 first = false;
278 // First arrow item is the outer circle of axis
277 // First arrow item is the outer circle of axis
279 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
278 static_cast<QGraphicsEllipseItem *>(item)->setPen(pen);
280 } else {
279 } else {
281 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
280 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
282 }
281 }
283 }
282 }
284 }
283 }
285
284
286 void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen)
285 void PolarChartAxisAngular::handleGridPenChanged(const QPen &pen)
287 {
286 {
288 foreach (QGraphicsItem *item, gridItems())
287 foreach (QGraphicsItem *item, gridItems())
289 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
288 static_cast<QGraphicsLineItem *>(item)->setPen(pen);
290 }
289 }
291
290
292 QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
291 QSizeF PolarChartAxisAngular::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
293 {
292 {
294 Q_UNUSED(which);
293 Q_UNUSED(which);
295 Q_UNUSED(constraint);
294 Q_UNUSED(constraint);
296 return QSizeF(-1, -1);
295 return QSizeF(-1, -1);
297 }
296 }
298
297
299 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize)
298 qreal PolarChartAxisAngular::preferredAxisRadius(const QSizeF &maxSize)
300 {
299 {
301 qreal radius = maxSize.height() / 2.0;
300 qreal radius = maxSize.height() / 2.0;
302 if (maxSize.width() < maxSize.height())
301 if (maxSize.width() < maxSize.height())
303 radius = maxSize.width() / 2.0;
302 radius = maxSize.width() / 2.0;
304
303
305 if (axis()->labelsVisible()) {
304 if (axis()->labelsVisible()) {
306 QVector<qreal> layout = calculateLayout();
305 QVector<qreal> layout = calculateLayout();
307 if (layout.isEmpty())
306 if (layout.isEmpty())
308 return radius;
307 return radius;
309
308
310 createAxisLabels(layout);
309 createAxisLabels(layout);
311 QStringList labelList = labels();
310 QStringList labelList = labels();
312 QFont font = axis()->labelsFont();
311 QFont font = axis()->labelsFont();
313
312
314 QRectF maxRect;
313 QRectF maxRect;
315 maxRect.setSize(maxSize);
314 maxRect.setSize(maxSize);
316 maxRect.moveCenter(QPointF(0.0, 0.0));
315 maxRect.moveCenter(QPointF(0.0, 0.0));
317
316
318 // This is a horrible way to find out the maximum radius for angular axis and its labels.
317 // This is a horrible way to find out the maximum radius for angular axis and its labels.
319 // It just increments the radius down until everyhing fits the constraint size.
318 // It just increments the radius down until everyhing fits the constraint size.
320 // Proper way would be to actually calculate it but this seems to work reasonably fast as it is.
319 // Proper way would be to actually calculate it but this seems to work reasonably fast as it is.
321 bool nextTickVisible = false;
320 bool nextTickVisible = false;
322 for (int i = 0; i < layout.size(); ) {
321 for (int i = 0; i < layout.size(); ) {
323 if ((i == layout.size() - 1)
322 if ((i == layout.size() - 1)
324 || layout.at(i + 1) < 0.0
323 || layout.at(i + 1) < 0.0
325 || layout.at(i + 1) > 360.0) {
324 || layout.at(i + 1) > 360.0) {
326 nextTickVisible = false;
325 nextTickVisible = false;
327 } else {
326 } else {
328 nextTickVisible = true;
327 nextTickVisible = true;
329 }
328 }
330
329
331 qreal labelCoordinate = layout.at(i);
330 qreal labelCoordinate = layout.at(i);
332 qreal labelVisible;
331 qreal labelVisible;
333
332
334 if (intervalAxis()) {
333 if (intervalAxis()) {
335 qreal farEdge;
334 qreal farEdge;
336 if (i == (layout.size() - 1))
335 if (i == (layout.size() - 1))
337 farEdge = 360.0;
336 farEdge = 360.0;
338 else
337 else
339 farEdge = qMin(qreal(360.0), layout.at(i + 1));
338 farEdge = qMin(qreal(360.0), layout.at(i + 1));
340
339
341 // Adjust the labelCoordinate to show it if next tick is visible
340 // Adjust the labelCoordinate to show it if next tick is visible
342 if (nextTickVisible)
341 if (nextTickVisible)
343 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
342 labelCoordinate = qMax(qreal(0.0), labelCoordinate);
344
343
345 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
344 labelCoordinate = (labelCoordinate + farEdge) / 2.0;
346 }
345 }
347
346
348 if (labelCoordinate < 0.0 || labelCoordinate > 360.0)
347 if (labelCoordinate < 0.0 || labelCoordinate > 360.0)
349 labelVisible = false;
348 labelVisible = false;
350 else
349 else
351 labelVisible = true;
350 labelVisible = true;
352
351
353 if (!labelVisible) {
352 if (!labelVisible) {
354 i++;
353 i++;
355 continue;
354 continue;
356 }
355 }
357
356
358 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
357 QRectF boundingRect = ChartPresenter::textBoundingRect(axis()->labelsFont(), labelList.at(i), axis()->labelsAngle());
359 QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2();
358 QPointF labelPoint = QLineF::fromPolar(radius + tickWidth(), 90.0 - labelCoordinate).p2();
360
359
361 boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
360 boundingRect = moveLabelToPosition(labelCoordinate, labelPoint, boundingRect);
362 QRectF intersectRect = maxRect.intersected(boundingRect);
361 QRectF intersectRect = maxRect.intersected(boundingRect);
363 if (boundingRect.isEmpty() || intersectRect == boundingRect) {
362 if (boundingRect.isEmpty() || intersectRect == boundingRect) {
364 i++;
363 i++;
365 } else {
364 } else {
366 qreal reduction(0.0);
365 qreal reduction(0.0);
367 // If there is no intersection, reduce by smallest dimension of label rect to be on the safe side
366 // If there is no intersection, reduce by smallest dimension of label rect to be on the safe side
368 if (intersectRect.isEmpty()) {
367 if (intersectRect.isEmpty()) {
369 reduction = qMin(boundingRect.height(), boundingRect.width());
368 reduction = qMin(boundingRect.height(), boundingRect.width());
370 } else {
369 } else {
371 // Approximate needed radius reduction is the amount label rect exceeds max rect in either dimension.
370 // Approximate needed radius reduction is the amount label rect exceeds max rect in either dimension.
372 // Could be further optimized by figuring out the proper math how to calculate exact needed reduction.
371 // Could be further optimized by figuring out the proper math how to calculate exact needed reduction.
373 reduction = qMax(boundingRect.height() - intersectRect.height(),
372 reduction = qMax(boundingRect.height() - intersectRect.height(),
374 boundingRect.width() - intersectRect.width());
373 boundingRect.width() - intersectRect.width());
375 }
374 }
376 // Typically the approximated reduction is little low, so add one
375 // Typically the approximated reduction is little low, so add one
377 radius -= (reduction + 1.0);
376 radius -= (reduction + 1.0);
378
377
379 if (radius < 1.0) // safeguard
378 if (radius < 1.0) // safeguard
380 return 1.0;
379 return 1.0;
381 }
380 }
382 }
381 }
383 }
382 }
384
383
385 if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) {
384 if (!axis()->titleText().isEmpty() && axis()->isTitleVisible()) {
386 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText());
385 QRectF titleRect = ChartPresenter::textBoundingRect(axis()->titleFont(), axis()->titleText());
387
386
388 radius -= titlePadding() + (titleRect.height() / 2.0);
387 radius -= titlePadding() + (titleRect.height() / 2.0);
389 if (radius < 1.0) // safeguard
388 if (radius < 1.0) // safeguard
390 return 1.0;
389 return 1.0;
391 }
390 }
392
391
393 return radius;
392 return radius;
394 }
393 }
395
394
396 QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const
395 QRectF PolarChartAxisAngular::moveLabelToPosition(qreal angularCoordinate, QPointF labelPoint, QRectF labelRect) const
397 {
396 {
398 // TODO use fuzzy compare for "==" cases?
399 // TODO Adjust the rect position near 0, 90, 180, and 270 angles for smoother animation?
400 if (angularCoordinate == 0.0)
397 if (angularCoordinate == 0.0)
401 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
398 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
402 else if (angularCoordinate < 90.0)
399 else if (angularCoordinate < 90.0)
403 labelRect.moveBottomLeft(labelPoint);
400 labelRect.moveBottomLeft(labelPoint);
404 else if (angularCoordinate == 90.0)
401 else if (angularCoordinate == 90.0)
405 labelRect.moveCenter(labelPoint + QPointF(labelRect.width() / 2.0 + 2.0, 0)); // +2 so that it does not hit the radial axis
402 labelRect.moveCenter(labelPoint + QPointF(labelRect.width() / 2.0 + 2.0, 0)); // +2 so that it does not hit the radial axis
406 else if (angularCoordinate < 180.0)
403 else if (angularCoordinate < 180.0)
407 labelRect.moveTopLeft(labelPoint);
404 labelRect.moveTopLeft(labelPoint);
408 else if (angularCoordinate == 180.0)
405 else if (angularCoordinate == 180.0)
409 labelRect.moveCenter(labelPoint + QPointF(0, labelRect.height() / 2.0));
406 labelRect.moveCenter(labelPoint + QPointF(0, labelRect.height() / 2.0));
410 else if (angularCoordinate < 270.0)
407 else if (angularCoordinate < 270.0)
411 labelRect.moveTopRight(labelPoint);
408 labelRect.moveTopRight(labelPoint);
412 else if (angularCoordinate == 270.0)
409 else if (angularCoordinate == 270.0)
413 labelRect.moveCenter(labelPoint + QPointF(-labelRect.width() / 2.0 - 2.0, 0)); // -2 so that it does not hit the radial axis
410 labelRect.moveCenter(labelPoint + QPointF(-labelRect.width() / 2.0 - 2.0, 0)); // -2 so that it does not hit the radial axis
414 else if (angularCoordinate < 360.0)
411 else if (angularCoordinate < 360.0)
415 labelRect.moveBottomRight(labelPoint);
412 labelRect.moveBottomRight(labelPoint);
416 else
413 else
417 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
414 labelRect.moveCenter(labelPoint + QPointF(0, -labelRect.height() / 2.0));
418 return labelRect;
415 return labelRect;
419 }
416 }
420
417
421 #include "moc_polarchartaxisangular_p.cpp"
418 #include "moc_polarchartaxisangular_p.cpp"
422
419
423 QTCOMMERCIALCHART_END_NAMESPACE
420 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,1014 +1,1009
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "qabstractaxis.h"
21 #include "qabstractaxis.h"
22 #include "qabstractaxis_p.h"
22 #include "qabstractaxis_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24 #include "charttheme_p.h"
24 #include "charttheme_p.h"
25 #include "qchart_p.h"
25 #include "qchart_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QAbstractAxis
30 \class QAbstractAxis
31 \brief The QAbstractAxis class is used for manipulating chart's axis.
31 \brief The QAbstractAxis class is used for manipulating chart's axis.
32 \mainclass
32 \mainclass
33
33
34 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
34 Each series can be bound to one or more horizontal and vertical axes, but mixing axis types
35 that would result in different domains is not supported, such as specifying
35 that would result in different domains is not supported, such as specifying
36 QValueAxis and QLogValueAxis on the same orientation.
36 QValueAxis and QLogValueAxis on the same orientation.
37
37
38 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
38 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
39 and shades can be individually controlled.
39 and shades can be individually controlled.
40 */
40 */
41
41
42 /*!
42 /*!
43 \qmlclass AbstractAxis QAbstractAxis
43 \qmlclass AbstractAxis QAbstractAxis
44 \brief The AbstractAxis is a base element used for specialized axis elements.
44 \brief The AbstractAxis is a base element used for specialized axis elements.
45
45
46 Each series can be bound to only one horizontal and vertical axis.
46 Each series can be bound to only one horizontal and vertical axis.
47
47
48 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
48 Properties and visibility of various axis elements such as axis line, title, labels, grid lines,
49 and shades can be individually controlled.
49 and shades can be individually controlled.
50 */
50 */
51
51
52 /*!
52 /*!
53 \enum QAbstractAxis::AxisType
53 \enum QAbstractAxis::AxisType
54
54
55 The type of the series object.
55 The type of the series object.
56
56
57 \value AxisTypeNoAxis
57 \value AxisTypeNoAxis
58 \value AxisTypeValue
58 \value AxisTypeValue
59 \value AxisTypeBarCategory
59 \value AxisTypeBarCategory
60 \value AxisTypeCategory
60 \value AxisTypeCategory
61 \value AxisTypeDateTime
61 \value AxisTypeDateTime
62 \value AxisTypeLogValue
62 \value AxisTypeLogValue
63 */
63 */
64
64
65 /*!
65 /*!
66 *\fn void QAbstractAxis::type() const
66 *\fn void QAbstractAxis::type() const
67 Returns the type of the axis
67 Returns the type of the axis
68 */
68 */
69
69
70 /*!
70 /*!
71 \property QAbstractAxis::lineVisible
71 \property QAbstractAxis::lineVisible
72 The visibility of the axis line
72 The visibility of the axis line
73 */
73 */
74 /*!
74 /*!
75 \qmlproperty bool AbstractAxis::lineVisible
75 \qmlproperty bool AbstractAxis::lineVisible
76 The visibility of the axis line
76 The visibility of the axis line
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QAbstractAxis::linePen
80 \property QAbstractAxis::linePen
81 The pen of the line.
81 The pen of the line.
82 */
82 */
83
83
84 /*!
84 /*!
85 \property QAbstractAxis::labelsVisible
85 \property QAbstractAxis::labelsVisible
86 Defines if axis labels are visible.
86 Defines if axis labels are visible.
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty bool AbstractAxis::labelsVisible
89 \qmlproperty bool AbstractAxis::labelsVisible
90 Defines if axis labels are visible.
90 Defines if axis labels are visible.
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QAbstractAxis::labelsPen
94 \property QAbstractAxis::labelsPen
95 \deprecated
95 \deprecated
96 The pen of the labels.
96 The pen of the labels.
97 */
97 */
98
98
99 /*!
99 /*!
100 \property QAbstractAxis::labelsBrush
100 \property QAbstractAxis::labelsBrush
101 The brush of the labels. Only the color of the brush is relevant.
101 The brush of the labels. Only the color of the brush is relevant.
102 */
102 */
103
103
104 /*!
104 /*!
105 \property QAbstractAxis::visible
105 \property QAbstractAxis::visible
106 The visibility of the axis.
106 The visibility of the axis.
107 */
107 */
108 /*!
108 /*!
109 \qmlproperty bool AbstractAxis::visible
109 \qmlproperty bool AbstractAxis::visible
110 The visibility of the axis.
110 The visibility of the axis.
111 */
111 */
112
112
113 /*!
113 /*!
114 \property QAbstractAxis::gridVisible
114 \property QAbstractAxis::gridVisible
115 The visibility of the grid lines.
115 The visibility of the grid lines.
116 */
116 */
117 /*!
117 /*!
118 \qmlproperty bool AbstractAxis::gridVisible
118 \qmlproperty bool AbstractAxis::gridVisible
119 The visibility of the grid lines.
119 The visibility of the grid lines.
120 */
120 */
121
121
122 /*!
122 /*!
123 \property QAbstractAxis::color
123 \property QAbstractAxis::color
124 The color of the axis and ticks.
124 The color of the axis and ticks.
125 */
125 */
126 /*!
126 /*!
127 \qmlproperty color AbstractAxis::color
127 \qmlproperty color AbstractAxis::color
128 The color of the axis and ticks.
128 The color of the axis and ticks.
129 */
129 */
130
130
131 /*!
131 /*!
132 \property QAbstractAxis::gridLinePen
132 \property QAbstractAxis::gridLinePen
133 The pen of the grid line.
133 The pen of the grid line.
134 */
134 */
135
135
136 /*!
136 /*!
137 \property QAbstractAxis::labelsFont
137 \property QAbstractAxis::labelsFont
138 The font of the axis labels.
138 The font of the axis labels.
139 */
139 */
140
140
141 /*!
141 /*!
142 \qmlproperty Font AbstractAxis::labelsFont
142 \qmlproperty Font AbstractAxis::labelsFont
143 The font of the axis labels.
143 The font of the axis labels.
144
144
145 See the \l {Font} {QML Font Element} for detailed documentation.
145 See the \l {Font} {QML Font Element} for detailed documentation.
146 */
146 */
147
147
148 /*!
148 /*!
149 \property QAbstractAxis::labelsColor
149 \property QAbstractAxis::labelsColor
150 The color of the axis labels.
150 The color of the axis labels.
151 */
151 */
152 /*!
152 /*!
153 \qmlproperty color AbstractAxis::labelsColor
153 \qmlproperty color AbstractAxis::labelsColor
154 The color of the axis labels.
154 The color of the axis labels.
155 */
155 */
156
156
157 /*!
157 /*!
158 \property QAbstractAxis::labelsAngle
158 \property QAbstractAxis::labelsAngle
159 The angle of the axis labels in degrees.
159 The angle of the axis labels in degrees.
160 */
160 */
161 /*!
161 /*!
162 \qmlproperty int AbstractAxis::labelsAngle
162 \qmlproperty int AbstractAxis::labelsAngle
163 The angle of the axis labels in degrees.
163 The angle of the axis labels in degrees.
164 */
164 */
165
165
166 /*!
166 /*!
167 \property QAbstractAxis::shadesVisible
167 \property QAbstractAxis::shadesVisible
168 The visibility of the axis shades.
168 The visibility of the axis shades.
169 */
169 */
170 /*!
170 /*!
171 \qmlproperty bool AbstractAxis::shadesVisible
171 \qmlproperty bool AbstractAxis::shadesVisible
172 The visibility of the axis shades.
172 The visibility of the axis shades.
173 */
173 */
174
174
175 /*!
175 /*!
176 \property QAbstractAxis::shadesColor
176 \property QAbstractAxis::shadesColor
177 The fill (brush) color of the axis shades.
177 The fill (brush) color of the axis shades.
178 */
178 */
179 /*!
179 /*!
180 \qmlproperty color AbstractAxis::shadesColor
180 \qmlproperty color AbstractAxis::shadesColor
181 The fill (brush) color of the axis shades.
181 The fill (brush) color of the axis shades.
182 */
182 */
183
183
184 /*!
184 /*!
185 \property QAbstractAxis::shadesBorderColor
185 \property QAbstractAxis::shadesBorderColor
186 The border (pen) color of the axis shades.
186 The border (pen) color of the axis shades.
187 */
187 */
188 /*!
188 /*!
189 \qmlproperty color AbstractAxis::shadesBorderColor
189 \qmlproperty color AbstractAxis::shadesBorderColor
190 The border (pen) color of the axis shades.
190 The border (pen) color of the axis shades.
191 */
191 */
192
192
193 /*!
193 /*!
194 \property QAbstractAxis::shadesPen
194 \property QAbstractAxis::shadesPen
195 The pen of the axis shades (area between grid lines).
195 The pen of the axis shades (area between grid lines).
196 */
196 */
197
197
198 /*!
198 /*!
199 \property QAbstractAxis::shadesBrush
199 \property QAbstractAxis::shadesBrush
200 The brush of the axis shades (area between grid lines).
200 The brush of the axis shades (area between grid lines).
201 */
201 */
202
202
203 /*!
203 /*!
204 \property QAbstractAxis::titleVisible
204 \property QAbstractAxis::titleVisible
205 The visibility of the axis title. By default the value is true.
205 The visibility of the axis title. By default the value is true.
206 */
206 */
207 /*!
207 /*!
208 \qmlproperty bool AbstractAxis::titleVisible
208 \qmlproperty bool AbstractAxis::titleVisible
209 The visibility of the axis title. By default the value is true.
209 The visibility of the axis title. By default the value is true.
210 */
210 */
211
211
212 /*!
212 /*!
213 \property QAbstractAxis::titleText
213 \property QAbstractAxis::titleText
214 The title of the axis. Empty by default. Axis titles support html formatting.
214 The title of the axis. Empty by default. Axis titles support html formatting.
215 */
215 */
216 /*!
216 /*!
217 \qmlproperty String AbstractAxis::titleText
217 \qmlproperty String AbstractAxis::titleText
218 The title of the axis. Empty by default. Axis titles support html formatting.
218 The title of the axis. Empty by default. Axis titles support html formatting.
219 */
219 */
220
220
221 /*!
221 /*!
222 \property QAbstractAxis::titlePen
222 \property QAbstractAxis::titlePen
223 \deprecated
223 \deprecated
224 The pen of the title text.
224 The pen of the title text.
225 */
225 */
226
226
227 /*!
227 /*!
228 \property QAbstractAxis::titleBrush
228 \property QAbstractAxis::titleBrush
229 The brush of the title text. Only the color of the brush is relevant.
229 The brush of the title text. Only the color of the brush is relevant.
230 */
230 */
231
231
232 /*!
232 /*!
233 \property QAbstractAxis::titleFont
233 \property QAbstractAxis::titleFont
234 The font of the title of the axis.
234 The font of the title of the axis.
235 */
235 */
236 /*!
236 /*!
237 \qmlproperty Font AbstractAxis::titleFont
237 \qmlproperty Font AbstractAxis::titleFont
238 The font of the title of the axis.
238 The font of the title of the axis.
239 */
239 */
240
240
241 /*!
241 /*!
242 \property QAbstractAxis::orientation
242 \property QAbstractAxis::orientation
243 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
243 The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart.
244 */
244 */
245 /*!
245 /*!
246 \qmlproperty Qt.Orientation AbstractAxis::orientation
246 \qmlproperty Qt.Orientation AbstractAxis::orientation
247 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
247 The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series.
248 */
248 */
249
249
250 /*!
250 /*!
251 \property QAbstractAxis::alignment
251 \property QAbstractAxis::alignment
252 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
252 The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop.
253 */
253 */
254 /*!
254 /*!
255 \qmlproperty alignment AbstractAxis::alignment
255 \qmlproperty alignment AbstractAxis::alignment
256 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
256 The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop.
257 */
257 */
258
258
259 /*!
259 /*!
260 \fn void QAbstractAxis::visibleChanged(bool visible)
260 \fn void QAbstractAxis::visibleChanged(bool visible)
261 Visibility of the axis has changed to \a visible.
261 Visibility of the axis has changed to \a visible.
262 */
262 */
263 /*!
263 /*!
264 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
264 \qmlsignal AbstractAxis::onVisibleChanged(bool visible)
265 Visibility of the axis has changed to \a visible.
265 Visibility of the axis has changed to \a visible.
266 */
266 */
267
267
268 /*!
268 /*!
269 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
269 \fn void QAbstractAxis::linePenChanged(const QPen& pen)
270 The pen of the line of the axis has changed to \a pen.
270 The pen of the line of the axis has changed to \a pen.
271 */
271 */
272
272
273 /*!
273 /*!
274 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
274 \fn void QAbstractAxis::lineVisibleChanged(bool visible)
275 Visibility of the axis line has changed to \a visible.
275 Visibility of the axis line has changed to \a visible.
276 */
276 */
277 /*!
277 /*!
278 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
278 \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible)
279 Visibility of the axis line has changed to \a visible.
279 Visibility of the axis line has changed to \a visible.
280 */
280 */
281
281
282 /*!
282 /*!
283 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
283 \fn void QAbstractAxis::labelsVisibleChanged(bool visible)
284 Visibility of the labels of the axis has changed to \a visible.
284 Visibility of the labels of the axis has changed to \a visible.
285 */
285 */
286 /*!
286 /*!
287 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
287 \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible)
288 Visibility of the labels of the axis has changed to \a visible.
288 Visibility of the labels of the axis has changed to \a visible.
289 */
289 */
290
290
291 /*!
291 /*!
292 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
292 \fn void QAbstractAxis::labelsFontChanged(const QFont& font)
293 The font of the axis labels has changed to \a font.
293 The font of the axis labels has changed to \a font.
294 */
294 */
295 /*!
295 /*!
296 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
296 \qmlsignal AbstractAxis::onLabelsFontChanged(Font font)
297 The font of the axis labels has changed to \a font.
297 The font of the axis labels has changed to \a font.
298 */
298 */
299
299
300 /*!
300 /*!
301 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
301 \fn void QAbstractAxis::labelsPenChanged(const QPen& pen)
302 \deprecated
302 \deprecated
303 The pen of the axis labels has changed to \a pen.
303 The pen of the axis labels has changed to \a pen.
304 */
304 */
305
305
306 /*!
306 /*!
307 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
307 \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush)
308 The brush of the axis labels has changed to \a brush.
308 The brush of the axis labels has changed to \a brush.
309 */
309 */
310
310
311 /*!
311 /*!
312 \fn void QAbstractAxis::labelsAngleChanged(int angle)
312 \fn void QAbstractAxis::labelsAngleChanged(int angle)
313 The angle of the axis labels has changed to \a angle.
313 The angle of the axis labels has changed to \a angle.
314 */
314 */
315 /*!
315 /*!
316 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
316 \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle)
317 The angle of the axis labels has changed to \a angle.
317 The angle of the axis labels has changed to \a angle.
318 */
318 */
319
319
320 /*!
320 /*!
321 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
321 \fn void QAbstractAxis::gridVisibleChanged(bool visible)
322 Visibility of the grid lines of the axis has changed to \a visible.
322 Visibility of the grid lines of the axis has changed to \a visible.
323 */
323 */
324 /*!
324 /*!
325 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
325 \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible)
326 Visibility of the grid lines of the axis has changed to \a visible.
326 Visibility of the grid lines of the axis has changed to \a visible.
327 */
327 */
328
328
329 /*!
329 /*!
330 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
330 \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen)
331 The pen of the grid line has changed to \a pen.
331 The pen of the grid line has changed to \a pen.
332 */
332 */
333
333
334 /*!
334 /*!
335 \fn void QAbstractAxis::colorChanged(QColor color)
335 \fn void QAbstractAxis::colorChanged(QColor color)
336 Emitted if the \a color of the axis is changed.
336 Emitted if the \a color of the axis is changed.
337 */
337 */
338 /*!
338 /*!
339 \qmlsignal AbstractAxis::onColorChanged(QColor color)
339 \qmlsignal AbstractAxis::onColorChanged(QColor color)
340 Emitted if the \a color of the axis is changed.
340 Emitted if the \a color of the axis is changed.
341 */
341 */
342
342
343 /*!
343 /*!
344 \fn void QAbstractAxis::labelsColorChanged(QColor color)
344 \fn void QAbstractAxis::labelsColorChanged(QColor color)
345 Emitted if the \a color of the axis labels is changed.
345 Emitted if the \a color of the axis labels is changed.
346 */
346 */
347 /*!
347 /*!
348 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
348 \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color)
349 Emitted if the \a color of the axis labels is changed.
349 Emitted if the \a color of the axis labels is changed.
350 */
350 */
351
351
352 /*!
352 /*!
353 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
353 \fn void QAbstractAxis::titleVisibleChanged(bool visible)
354 Visibility of the title text of the axis has changed to \a visible.
354 Visibility of the title text of the axis has changed to \a visible.
355 */
355 */
356 /*!
356 /*!
357 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
357 \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible)
358 Visibility of the title text of the axis has changed to \a visible.
358 Visibility of the title text of the axis has changed to \a visible.
359 */
359 */
360
360
361 /*!
361 /*!
362 \fn void QAbstractAxis::titleTextChanged(const QString& text)
362 \fn void QAbstractAxis::titleTextChanged(const QString& text)
363 The text of the axis title has changed to \a text.
363 The text of the axis title has changed to \a text.
364 */
364 */
365 /*!
365 /*!
366 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
366 \qmlsignal AbstractAxis::onTitleTextChanged(String text)
367 The text of the axis title has changed to \a text.
367 The text of the axis title has changed to \a text.
368 */
368 */
369
369
370 /*!
370 /*!
371 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
371 \fn void QAbstractAxis::titlePenChanged(const QPen& pen)
372 \deprecated
372 \deprecated
373 The pen of the axis shades has changed to \a pen.
373 The pen of the axis shades has changed to \a pen.
374 */
374 */
375
375
376 /*!
376 /*!
377 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
377 \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush)
378 The brush of the axis title has changed to \a brush.
378 The brush of the axis title has changed to \a brush.
379 */
379 */
380
380
381 /*!
381 /*!
382 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
382 \fn void QAbstractAxis::titleFontChanged(const QFont& font)
383 The font of the axis title has changed to \a font.
383 The font of the axis title has changed to \a font.
384 */
384 */
385 /*!
385 /*!
386 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
386 \qmlsignal AbstractAxis::onTitleFontChanged(Font font)
387 The font of the axis title has changed to \a font.
387 The font of the axis title has changed to \a font.
388 */
388 */
389
389
390 /*!
390 /*!
391 \fn void QAbstractAxis::shadesVisibleChanged(bool)
391 \fn void QAbstractAxis::shadesVisibleChanged(bool)
392 Emitted if the visibility of the axis shades is changed to \a visible.
392 Emitted if the visibility of the axis shades is changed to \a visible.
393 */
393 */
394 /*!
394 /*!
395 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
395 \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible)
396 Emitted if the visibility of the axis shades is changed to \a visible.
396 Emitted if the visibility of the axis shades is changed to \a visible.
397 */
397 */
398
398
399 /*!
399 /*!
400 \fn void QAbstractAxis::shadesColorChanged(QColor color)
400 \fn void QAbstractAxis::shadesColorChanged(QColor color)
401 Emitted if the \a color of the axis shades is changed.
401 Emitted if the \a color of the axis shades is changed.
402 */
402 */
403 /*!
403 /*!
404 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
404 \qmlsignal AbstractAxis::onShadesColorChanged(QColor color)
405 Emitted if the \a color of the axis shades is changed.
405 Emitted if the \a color of the axis shades is changed.
406 */
406 */
407
407
408 /*!
408 /*!
409 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
409 \fn void QAbstractAxis::shadesBorderColorChanged(QColor)
410 Emitted if the border \a color of the axis shades is changed.
410 Emitted if the border \a color of the axis shades is changed.
411 */
411 */
412 /*!
412 /*!
413 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
413 \qmlsignal AbstractAxis::onBorderColorChanged(QColor color)
414 Emitted if the border \a color of the axis shades is changed.
414 Emitted if the border \a color of the axis shades is changed.
415 */
415 */
416
416
417 /*!
417 /*!
418 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
418 \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush)
419 The brush of the axis shades has changed to \a brush.
419 The brush of the axis shades has changed to \a brush.
420 */
420 */
421
421
422 /*!
422 /*!
423 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
423 \fn void QAbstractAxis::shadesPenChanged(const QPen& pen)
424 The pen of the axis shades has changed to \a pen.
424 The pen of the axis shades has changed to \a pen.
425 */
425 */
426
426
427 /*!
427 /*!
428 \internal
428 \internal
429 Constructs new axis object which is a child of \a parent. Ownership is taken by
429 Constructs new axis object which is a child of \a parent. Ownership is taken by
430 QChart when axis added.
430 QChart when axis added.
431 */
431 */
432
432
433 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
433 QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent)
434 : QObject(parent),
434 : QObject(parent),
435 d_ptr(&d)
435 d_ptr(&d)
436 {
436 {
437 }
437 }
438
438
439 /*!
439 /*!
440 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
440 Destructor of the axis object. When axis is added to chart, chart object takes ownership.
441 */
441 */
442
442
443 QAbstractAxis::~QAbstractAxis()
443 QAbstractAxis::~QAbstractAxis()
444 {
444 {
445 if (d_ptr->m_chart)
445 if (d_ptr->m_chart)
446 qFatal("Still binded axis detected !");
446 qFatal("Still binded axis detected !");
447 }
447 }
448
448
449 /*!
449 /*!
450 Sets \a pen used to draw axis line and ticks.
450 Sets \a pen used to draw axis line and ticks.
451 */
451 */
452 void QAbstractAxis::setLinePen(const QPen &pen)
452 void QAbstractAxis::setLinePen(const QPen &pen)
453 {
453 {
454 if (d_ptr->m_axisPen != pen) {
454 if (d_ptr->m_axisPen != pen) {
455 d_ptr->m_axisPen = pen;
455 d_ptr->m_axisPen = pen;
456 emit linePenChanged(pen);
456 emit linePenChanged(pen);
457 }
457 }
458 }
458 }
459
459
460 /*!
460 /*!
461 Returns pen used to draw axis and ticks.
461 Returns pen used to draw axis and ticks.
462 */
462 */
463 QPen QAbstractAxis::linePen() const
463 QPen QAbstractAxis::linePen() const
464 {
464 {
465 if (d_ptr->m_axisPen == QChartPrivate::defaultPen())
465 if (d_ptr->m_axisPen == QChartPrivate::defaultPen())
466 return QPen();
466 return QPen();
467 else
467 else
468 return d_ptr->m_axisPen;
468 return d_ptr->m_axisPen;
469 }
469 }
470
470
471 //TODO: remove me 2.0
472 void QAbstractAxis::setLinePenColor(QColor color)
471 void QAbstractAxis::setLinePenColor(QColor color)
473 {
472 {
474 QPen p = d_ptr->m_axisPen;
473 QPen p = d_ptr->m_axisPen;
475 if (p.color() != color) {
474 if (p.color() != color) {
476 p.setColor(color);
475 p.setColor(color);
477 setLinePen(p);
476 setLinePen(p);
478 emit colorChanged(color);
477 emit colorChanged(color);
479 }
478 }
480 }
479 }
481
480
482 QColor QAbstractAxis::linePenColor() const
481 QColor QAbstractAxis::linePenColor() const
483 {
482 {
484 return linePen().color();
483 return linePen().color();
485 }
484 }
486
485
487 /*!
486 /*!
488 Sets if axis and ticks are \a visible.
487 Sets if axis and ticks are \a visible.
489 */
488 */
490 void QAbstractAxis::setLineVisible(bool visible)
489 void QAbstractAxis::setLineVisible(bool visible)
491 {
490 {
492 if (d_ptr->m_arrowVisible != visible) {
491 if (d_ptr->m_arrowVisible != visible) {
493 d_ptr->m_arrowVisible = visible;
492 d_ptr->m_arrowVisible = visible;
494 emit lineVisibleChanged(visible);
493 emit lineVisibleChanged(visible);
495 }
494 }
496 }
495 }
497
496
498 bool QAbstractAxis::isLineVisible() const
497 bool QAbstractAxis::isLineVisible() const
499 {
498 {
500 return d_ptr->m_arrowVisible;
499 return d_ptr->m_arrowVisible;
501 }
500 }
502
501
503 void QAbstractAxis::setGridLineVisible(bool visible)
502 void QAbstractAxis::setGridLineVisible(bool visible)
504 {
503 {
505 if (d_ptr->m_gridLineVisible != visible) {
504 if (d_ptr->m_gridLineVisible != visible) {
506 d_ptr->m_gridLineVisible = visible;
505 d_ptr->m_gridLineVisible = visible;
507 emit gridVisibleChanged(visible);
506 emit gridVisibleChanged(visible);
508 }
507 }
509 }
508 }
510
509
511 bool QAbstractAxis::isGridLineVisible() const
510 bool QAbstractAxis::isGridLineVisible() const
512 {
511 {
513 return d_ptr->m_gridLineVisible;
512 return d_ptr->m_gridLineVisible;
514 }
513 }
515
514
516 /*!
515 /*!
517 Sets \a pen used to draw grid line.
516 Sets \a pen used to draw grid line.
518 */
517 */
519 void QAbstractAxis::setGridLinePen(const QPen &pen)
518 void QAbstractAxis::setGridLinePen(const QPen &pen)
520 {
519 {
521 if (d_ptr->m_gridLinePen != pen) {
520 if (d_ptr->m_gridLinePen != pen) {
522 d_ptr->m_gridLinePen = pen;
521 d_ptr->m_gridLinePen = pen;
523 emit gridLinePenChanged(pen);
522 emit gridLinePenChanged(pen);
524 }
523 }
525 }
524 }
526
525
527 /*!
526 /*!
528 Returns pen used to draw grid.
527 Returns pen used to draw grid.
529 */
528 */
530 QPen QAbstractAxis::gridLinePen() const
529 QPen QAbstractAxis::gridLinePen() const
531 {
530 {
532 if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen())
531 if (d_ptr->m_gridLinePen == QChartPrivate::defaultPen())
533 return QPen();
532 return QPen();
534 else
533 else
535 return d_ptr->m_gridLinePen;
534 return d_ptr->m_gridLinePen;
536 }
535 }
537
536
538 void QAbstractAxis::setLabelsVisible(bool visible)
537 void QAbstractAxis::setLabelsVisible(bool visible)
539 {
538 {
540 if (d_ptr->m_labelsVisible != visible) {
539 if (d_ptr->m_labelsVisible != visible) {
541 d_ptr->m_labelsVisible = visible;
540 d_ptr->m_labelsVisible = visible;
542 emit labelsVisibleChanged(visible);
541 emit labelsVisibleChanged(visible);
543 }
542 }
544 }
543 }
545
544
546 bool QAbstractAxis::labelsVisible() const
545 bool QAbstractAxis::labelsVisible() const
547 {
546 {
548 return d_ptr->m_labelsVisible;
547 return d_ptr->m_labelsVisible;
549 }
548 }
550
549
551 void QAbstractAxis::setLabelsPen(const QPen &pen)
550 void QAbstractAxis::setLabelsPen(const QPen &pen)
552 {
551 {
553 if (d_ptr->m_labelsPen != pen) {
552 if (d_ptr->m_labelsPen != pen) {
554 d_ptr->m_labelsPen = pen;
553 d_ptr->m_labelsPen = pen;
555 emit labelsPenChanged(pen);
554 emit labelsPenChanged(pen);
556 }
555 }
557 }
556 }
558
557
559 QPen QAbstractAxis::labelsPen() const
558 QPen QAbstractAxis::labelsPen() const
560 {
559 {
561 if (d_ptr->m_labelsPen == QChartPrivate::defaultPen())
560 if (d_ptr->m_labelsPen == QChartPrivate::defaultPen())
562 return QPen();
561 return QPen();
563 else
562 else
564 return d_ptr->m_labelsPen;
563 return d_ptr->m_labelsPen;
565 }
564 }
566
565
567 /*!
566 /*!
568 Sets \a brush used to draw labels.
567 Sets \a brush used to draw labels.
569 */
568 */
570 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
569 void QAbstractAxis::setLabelsBrush(const QBrush &brush)
571 {
570 {
572 if (d_ptr->m_labelsBrush != brush) {
571 if (d_ptr->m_labelsBrush != brush) {
573 d_ptr->m_labelsBrush = brush;
572 d_ptr->m_labelsBrush = brush;
574 emit labelsBrushChanged(brush);
573 emit labelsBrushChanged(brush);
575 }
574 }
576 }
575 }
577
576
578 /*!
577 /*!
579 Returns brush used to draw labels.
578 Returns brush used to draw labels.
580 */
579 */
581 QBrush QAbstractAxis::labelsBrush() const
580 QBrush QAbstractAxis::labelsBrush() const
582 {
581 {
583 if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush())
582 if (d_ptr->m_labelsBrush == QChartPrivate::defaultBrush())
584 return QBrush();
583 return QBrush();
585 else
584 else
586 return d_ptr->m_labelsBrush;
585 return d_ptr->m_labelsBrush;
587 }
586 }
588
587
589 /*!
588 /*!
590 Sets \a font used to draw labels.
589 Sets \a font used to draw labels.
591 */
590 */
592 void QAbstractAxis::setLabelsFont(const QFont &font)
591 void QAbstractAxis::setLabelsFont(const QFont &font)
593 {
592 {
594 if (d_ptr->m_labelsFont != font) {
593 if (d_ptr->m_labelsFont != font) {
595 d_ptr->m_labelsFont = font;
594 d_ptr->m_labelsFont = font;
596 emit labelsFontChanged(font);
595 emit labelsFontChanged(font);
597 }
596 }
598 }
597 }
599
598
600 /*!
599 /*!
601 Returns font used to draw labels.
600 Returns font used to draw labels.
602 */
601 */
603 QFont QAbstractAxis::labelsFont() const
602 QFont QAbstractAxis::labelsFont() const
604 {
603 {
605 if (d_ptr->m_labelsFont == QChartPrivate::defaultFont())
604 if (d_ptr->m_labelsFont == QChartPrivate::defaultFont())
606 return QFont();
605 return QFont();
607 else
606 else
608 return d_ptr->m_labelsFont;
607 return d_ptr->m_labelsFont;
609 }
608 }
610
609
611 void QAbstractAxis::setLabelsAngle(int angle)
610 void QAbstractAxis::setLabelsAngle(int angle)
612 {
611 {
613 if (d_ptr->m_labelsAngle != angle) {
612 if (d_ptr->m_labelsAngle != angle) {
614 d_ptr->m_labelsAngle = angle;
613 d_ptr->m_labelsAngle = angle;
615 emit labelsAngleChanged(angle);
614 emit labelsAngleChanged(angle);
616 }
615 }
617 }
616 }
618
617
619 int QAbstractAxis::labelsAngle() const
618 int QAbstractAxis::labelsAngle() const
620 {
619 {
621 return d_ptr->m_labelsAngle;
620 return d_ptr->m_labelsAngle;
622 }
621 }
623 //TODO: remove me 2.0
624 void QAbstractAxis::setLabelsColor(QColor color)
622 void QAbstractAxis::setLabelsColor(QColor color)
625 {
623 {
626 QBrush b = d_ptr->m_labelsBrush;
624 QBrush b = d_ptr->m_labelsBrush;
627 if (b.color() != color) {
625 if (b.color() != color) {
628 b.setColor(color);
626 b.setColor(color);
629 setLabelsBrush(b);
627 setLabelsBrush(b);
630 emit labelsColorChanged(color);
628 emit labelsColorChanged(color);
631 }
629 }
632 }
630 }
633
631
634 QColor QAbstractAxis::labelsColor() const
632 QColor QAbstractAxis::labelsColor() const
635 {
633 {
636 return labelsBrush().color();
634 return labelsBrush().color();
637 }
635 }
638
636
639 void QAbstractAxis::setTitleVisible(bool visible)
637 void QAbstractAxis::setTitleVisible(bool visible)
640 {
638 {
641 if (d_ptr->m_titleVisible != visible) {
639 if (d_ptr->m_titleVisible != visible) {
642 d_ptr->m_titleVisible = visible;
640 d_ptr->m_titleVisible = visible;
643 emit titleVisibleChanged(visible);
641 emit titleVisibleChanged(visible);
644 }
642 }
645 }
643 }
646
644
647 bool QAbstractAxis::isTitleVisible() const
645 bool QAbstractAxis::isTitleVisible() const
648 {
646 {
649 return d_ptr->m_titleVisible;
647 return d_ptr->m_titleVisible;
650 }
648 }
651
649
652 void QAbstractAxis::setTitlePen(const QPen &pen)
650 void QAbstractAxis::setTitlePen(const QPen &pen)
653 {
651 {
654 if (d_ptr->m_titlePen != pen) {
652 if (d_ptr->m_titlePen != pen) {
655 d_ptr->m_titlePen = pen;
653 d_ptr->m_titlePen = pen;
656 emit titlePenChanged(pen);
654 emit titlePenChanged(pen);
657 }
655 }
658 }
656 }
659
657
660 QPen QAbstractAxis::titlePen() const
658 QPen QAbstractAxis::titlePen() const
661 {
659 {
662 if (d_ptr->m_titlePen == QChartPrivate::defaultPen())
660 if (d_ptr->m_titlePen == QChartPrivate::defaultPen())
663 return QPen();
661 return QPen();
664 else
662 else
665 return d_ptr->m_titlePen;
663 return d_ptr->m_titlePen;
666 }
664 }
667
665
668 /*!
666 /*!
669 Sets \a brush used to draw title.
667 Sets \a brush used to draw title.
670 */
668 */
671 void QAbstractAxis::setTitleBrush(const QBrush &brush)
669 void QAbstractAxis::setTitleBrush(const QBrush &brush)
672 {
670 {
673 if (d_ptr->m_titleBrush != brush) {
671 if (d_ptr->m_titleBrush != brush) {
674 d_ptr->m_titleBrush = brush;
672 d_ptr->m_titleBrush = brush;
675 emit titleBrushChanged(brush);
673 emit titleBrushChanged(brush);
676 }
674 }
677 }
675 }
678
676
679 /*!
677 /*!
680 Returns brush used to draw title.
678 Returns brush used to draw title.
681 */
679 */
682 QBrush QAbstractAxis::titleBrush() const
680 QBrush QAbstractAxis::titleBrush() const
683 {
681 {
684 if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush())
682 if (d_ptr->m_titleBrush == QChartPrivate::defaultBrush())
685 return QBrush();
683 return QBrush();
686 else
684 else
687 return d_ptr->m_titleBrush;
685 return d_ptr->m_titleBrush;
688 }
686 }
689
687
690 /*!
688 /*!
691 Sets \a font used to draw title.
689 Sets \a font used to draw title.
692 */
690 */
693 void QAbstractAxis::setTitleFont(const QFont &font)
691 void QAbstractAxis::setTitleFont(const QFont &font)
694 {
692 {
695 if (d_ptr->m_titleFont != font) {
693 if (d_ptr->m_titleFont != font) {
696 d_ptr->m_titleFont = font;
694 d_ptr->m_titleFont = font;
697 emit titleFontChanged(font);
695 emit titleFontChanged(font);
698 }
696 }
699 }
697 }
700
698
701 /*!
699 /*!
702 Returns font used to draw title.
700 Returns font used to draw title.
703 */
701 */
704 QFont QAbstractAxis::titleFont() const
702 QFont QAbstractAxis::titleFont() const
705 {
703 {
706 if (d_ptr->m_titleFont == QChartPrivate::defaultFont())
704 if (d_ptr->m_titleFont == QChartPrivate::defaultFont())
707 return QFont();
705 return QFont();
708 else
706 else
709 return d_ptr->m_titleFont;
707 return d_ptr->m_titleFont;
710 }
708 }
711
709
712 void QAbstractAxis::setTitleText(const QString &title)
710 void QAbstractAxis::setTitleText(const QString &title)
713 {
711 {
714 if (d_ptr->m_title != title) {
712 if (d_ptr->m_title != title) {
715 d_ptr->m_title = title;
713 d_ptr->m_title = title;
716 emit titleTextChanged(title);
714 emit titleTextChanged(title);
717 }
715 }
718 }
716 }
719
717
720 QString QAbstractAxis::titleText() const
718 QString QAbstractAxis::titleText() const
721 {
719 {
722 return d_ptr->m_title;
720 return d_ptr->m_title;
723 }
721 }
724
722
725
723
726 void QAbstractAxis::setShadesVisible(bool visible)
724 void QAbstractAxis::setShadesVisible(bool visible)
727 {
725 {
728 if (d_ptr->m_shadesVisible != visible) {
726 if (d_ptr->m_shadesVisible != visible) {
729 d_ptr->m_shadesVisible = visible;
727 d_ptr->m_shadesVisible = visible;
730 emit shadesVisibleChanged(visible);
728 emit shadesVisibleChanged(visible);
731 }
729 }
732 }
730 }
733
731
734 bool QAbstractAxis::shadesVisible() const
732 bool QAbstractAxis::shadesVisible() const
735 {
733 {
736 return d_ptr->m_shadesVisible;
734 return d_ptr->m_shadesVisible;
737 }
735 }
738
736
739 /*!
737 /*!
740 Sets \a pen used to draw shades.
738 Sets \a pen used to draw shades.
741 */
739 */
742 void QAbstractAxis::setShadesPen(const QPen &pen)
740 void QAbstractAxis::setShadesPen(const QPen &pen)
743 {
741 {
744 if (d_ptr->m_shadesPen != pen) {
742 if (d_ptr->m_shadesPen != pen) {
745 d_ptr->m_shadesPen = pen;
743 d_ptr->m_shadesPen = pen;
746 emit shadesPenChanged(pen);
744 emit shadesPenChanged(pen);
747 }
745 }
748 }
746 }
749
747
750 /*!
748 /*!
751 Returns pen used to draw shades.
749 Returns pen used to draw shades.
752 */
750 */
753 QPen QAbstractAxis::shadesPen() const
751 QPen QAbstractAxis::shadesPen() const
754 {
752 {
755 if (d_ptr->m_shadesPen == QChartPrivate::defaultPen())
753 if (d_ptr->m_shadesPen == QChartPrivate::defaultPen())
756 return QPen();
754 return QPen();
757 else
755 else
758 return d_ptr->m_shadesPen;
756 return d_ptr->m_shadesPen;
759 }
757 }
760
758
761 /*!
759 /*!
762 Sets \a brush used to draw shades.
760 Sets \a brush used to draw shades.
763 */
761 */
764 void QAbstractAxis::setShadesBrush(const QBrush &brush)
762 void QAbstractAxis::setShadesBrush(const QBrush &brush)
765 {
763 {
766 if (d_ptr->m_shadesBrush != brush) {
764 if (d_ptr->m_shadesBrush != brush) {
767 d_ptr->m_shadesBrush = brush;
765 d_ptr->m_shadesBrush = brush;
768 emit shadesBrushChanged(brush);
766 emit shadesBrushChanged(brush);
769 }
767 }
770 }
768 }
771
769
772 /*!
770 /*!
773 Returns brush used to draw shades.
771 Returns brush used to draw shades.
774 */
772 */
775 QBrush QAbstractAxis::shadesBrush() const
773 QBrush QAbstractAxis::shadesBrush() const
776 {
774 {
777 if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush())
775 if (d_ptr->m_shadesBrush == QChartPrivate::defaultBrush())
778 return QBrush(Qt::SolidPattern);
776 return QBrush(Qt::SolidPattern);
779 else
777 else
780 return d_ptr->m_shadesBrush;
778 return d_ptr->m_shadesBrush;
781 }
779 }
782
780
783 void QAbstractAxis::setShadesColor(QColor color)
781 void QAbstractAxis::setShadesColor(QColor color)
784 {
782 {
785 QBrush b = d_ptr->m_shadesBrush;
783 QBrush b = d_ptr->m_shadesBrush;
786 if (b.color() != color) {
784 if (b.color() != color) {
787 b.setColor(color);
785 b.setColor(color);
788 setShadesBrush(b);
786 setShadesBrush(b);
789 emit shadesColorChanged(color);
787 emit shadesColorChanged(color);
790 }
788 }
791 }
789 }
792
790
793 QColor QAbstractAxis::shadesColor() const
791 QColor QAbstractAxis::shadesColor() const
794 {
792 {
795 return shadesBrush().color();
793 return shadesBrush().color();
796 }
794 }
797
795
798 void QAbstractAxis::setShadesBorderColor(QColor color)
796 void QAbstractAxis::setShadesBorderColor(QColor color)
799 {
797 {
800 QPen p = d_ptr->m_shadesPen;
798 QPen p = d_ptr->m_shadesPen;
801 if (p.color() != color) {
799 if (p.color() != color) {
802 p.setColor(color);
800 p.setColor(color);
803 setShadesPen(p);
801 setShadesPen(p);
804 emit shadesColorChanged(color);
802 emit shadesColorChanged(color);
805 }
803 }
806 }
804 }
807
805
808 QColor QAbstractAxis::shadesBorderColor() const
806 QColor QAbstractAxis::shadesBorderColor() const
809 {
807 {
810 return shadesPen().color();
808 return shadesPen().color();
811 }
809 }
812
810
813
811
814 bool QAbstractAxis::isVisible() const
812 bool QAbstractAxis::isVisible() const
815 {
813 {
816 return d_ptr->m_visible;
814 return d_ptr->m_visible;
817 }
815 }
818
816
819 /*!
817 /*!
820 Sets axis, shades, labels and grid lines to be visible.
818 Sets axis, shades, labels and grid lines to be visible.
821 */
819 */
822 void QAbstractAxis::setVisible(bool visible)
820 void QAbstractAxis::setVisible(bool visible)
823 {
821 {
824 if (d_ptr->m_visible != visible) {
822 if (d_ptr->m_visible != visible) {
825 d_ptr->m_visible = visible;
823 d_ptr->m_visible = visible;
826 emit visibleChanged(visible);
824 emit visibleChanged(visible);
827 }
825 }
828 }
826 }
829
827
830
828
831 /*!
829 /*!
832 Sets axis, shades, labels and grid lines to be visible.
830 Sets axis, shades, labels and grid lines to be visible.
833 */
831 */
834 void QAbstractAxis::show()
832 void QAbstractAxis::show()
835 {
833 {
836 setVisible(true);
834 setVisible(true);
837 }
835 }
838
836
839 /*!
837 /*!
840 Sets axis, shades, labels and grid lines to not be visible.
838 Sets axis, shades, labels and grid lines to not be visible.
841 */
839 */
842 void QAbstractAxis::hide()
840 void QAbstractAxis::hide()
843 {
841 {
844 setVisible(false);
842 setVisible(false);
845 }
843 }
846
844
847 /*!
845 /*!
848 Sets the minimum value shown on the axis.
846 Sets the minimum value shown on the axis.
849 Depending on the actual axis type the \a min parameter is converted to appropriate type.
847 Depending on the actual axis type the \a min parameter is converted to appropriate type.
850 If the conversion is impossible then the function call does nothing
848 If the conversion is impossible then the function call does nothing
851 */
849 */
852 void QAbstractAxis::setMin(const QVariant &min)
850 void QAbstractAxis::setMin(const QVariant &min)
853 {
851 {
854 d_ptr->setMin(min);
852 d_ptr->setMin(min);
855 }
853 }
856
854
857 /*!
855 /*!
858 Sets the maximum value shown on the axis.
856 Sets the maximum value shown on the axis.
859 Depending on the actual axis type the \a max parameter is converted to appropriate type.
857 Depending on the actual axis type the \a max parameter is converted to appropriate type.
860 If the conversion is impossible then the function call does nothing
858 If the conversion is impossible then the function call does nothing
861 */
859 */
862 void QAbstractAxis::setMax(const QVariant &max)
860 void QAbstractAxis::setMax(const QVariant &max)
863 {
861 {
864 d_ptr->setMax(max);
862 d_ptr->setMax(max);
865 }
863 }
866
864
867 /*!
865 /*!
868 Sets the range shown on the axis.
866 Sets the range shown on the axis.
869 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
867 Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types.
870 If the conversion is impossible then the function call does nothing.
868 If the conversion is impossible then the function call does nothing.
871 */
869 */
872 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
870 void QAbstractAxis::setRange(const QVariant &min, const QVariant &max)
873 {
871 {
874 d_ptr->setRange(min, max);
872 d_ptr->setRange(min, max);
875 }
873 }
876
874
877
875
878 /*!
876 /*!
879 Returns the orientation in which the axis is being used (Vertical or Horizontal)
877 Returns the orientation in which the axis is being used (Vertical or Horizontal)
880 */
878 */
881 // NOTE: should have const but it breaks BC:
882 // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function
883 Qt::Orientation QAbstractAxis::orientation()
879 Qt::Orientation QAbstractAxis::orientation()
884 {
880 {
885 return d_ptr->orientation();
881 return d_ptr->orientation();
886 }
882 }
887
883
888 Qt::Alignment QAbstractAxis::alignment() const
884 Qt::Alignment QAbstractAxis::alignment() const
889 {
885 {
890 return d_ptr->alignment();
886 return d_ptr->alignment();
891 }
887 }
892
888
893 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
889 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
894
890
895 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
891 QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q)
896 : q_ptr(q),
892 : q_ptr(q),
897 m_chart(0),
893 m_chart(0),
898 m_alignment(0),
894 m_alignment(0),
899 m_orientation(Qt::Orientation(0)),
895 m_orientation(Qt::Orientation(0)),
900 m_visible(true),
896 m_visible(true),
901 m_arrowVisible(true),
897 m_arrowVisible(true),
902 m_axisPen(QChartPrivate::defaultPen()),
898 m_axisPen(QChartPrivate::defaultPen()),
903 m_axisBrush(QChartPrivate::defaultBrush()),
899 m_axisBrush(QChartPrivate::defaultBrush()),
904 m_gridLineVisible(true),
900 m_gridLineVisible(true),
905 m_gridLinePen(QChartPrivate::defaultPen()),
901 m_gridLinePen(QChartPrivate::defaultPen()),
906 m_labelsVisible(true),
902 m_labelsVisible(true),
907 m_labelsPen(QChartPrivate::defaultPen()),
903 m_labelsPen(QChartPrivate::defaultPen()),
908 m_labelsBrush(QChartPrivate::defaultBrush()),
904 m_labelsBrush(QChartPrivate::defaultBrush()),
909 m_labelsFont(QChartPrivate::defaultFont()),
905 m_labelsFont(QChartPrivate::defaultFont()),
910 m_labelsAngle(0),
906 m_labelsAngle(0),
911 m_titleVisible(true),
907 m_titleVisible(true),
912 m_titlePen(QChartPrivate::defaultPen()),
908 m_titlePen(QChartPrivate::defaultPen()),
913 m_titleBrush(QChartPrivate::defaultBrush()),
909 m_titleBrush(QChartPrivate::defaultBrush()),
914 m_titleFont(QChartPrivate::defaultFont()),
910 m_titleFont(QChartPrivate::defaultFont()),
915 m_shadesVisible(false),
911 m_shadesVisible(false),
916 m_shadesPen(QChartPrivate::defaultPen()),
912 m_shadesPen(QChartPrivate::defaultPen()),
917 m_shadesBrush(QChartPrivate::defaultBrush()),
913 m_shadesBrush(QChartPrivate::defaultBrush()),
918 m_shadesOpacity(1.0),
914 m_shadesOpacity(1.0),
919 m_dirty(false)
915 m_dirty(false)
920 {
916 {
921 }
917 }
922
918
923 QAbstractAxisPrivate::~QAbstractAxisPrivate()
919 QAbstractAxisPrivate::~QAbstractAxisPrivate()
924 {
920 {
925 }
921 }
926
922
927 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
923 void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment)
928 {
924 {
929 switch(alignment) {
925 switch(alignment) {
930 case Qt::AlignTop:
926 case Qt::AlignTop:
931 case Qt::AlignBottom:
927 case Qt::AlignBottom:
932 m_orientation = Qt::Horizontal;
928 m_orientation = Qt::Horizontal;
933 break;
929 break;
934 case Qt::AlignLeft:
930 case Qt::AlignLeft:
935 case Qt::AlignRight:
931 case Qt::AlignRight:
936 m_orientation = Qt::Vertical;
932 m_orientation = Qt::Vertical;
937 break;
933 break;
938 default:
934 default:
939 qWarning()<<"No alignment specified !";
935 qWarning()<<"No alignment specified !";
940 break;
936 break;
941 };
937 };
942 m_alignment=alignment;
938 m_alignment=alignment;
943 }
939 }
944
940
945 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
941 void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced)
946 {
942 {
947 //TODO: introduce axis brush
948 if (forced || QChartPrivate::defaultPen() == m_axisPen)
943 if (forced || QChartPrivate::defaultPen() == m_axisPen)
949 q_ptr->setLinePen(theme->axisLinePen());
944 q_ptr->setLinePen(theme->axisLinePen());
950
945
951 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
946 if (forced || QChartPrivate::defaultPen() == m_gridLinePen)
952 q_ptr->setGridLinePen(theme->girdLinePen());
947 q_ptr->setGridLinePen(theme->girdLinePen());
953
948
954 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
949 if (forced || QChartPrivate::defaultBrush() == m_labelsBrush)
955 q_ptr->setLabelsBrush(theme->labelBrush());
950 q_ptr->setLabelsBrush(theme->labelBrush());
956 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
951 if (forced || QChartPrivate::defaultPen() == m_labelsPen)
957 q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
952 q_ptr->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
958 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
953 if (forced || QChartPrivate::defaultFont() == m_labelsFont)
959 q_ptr->setLabelsFont(theme->labelFont());
954 q_ptr->setLabelsFont(theme->labelFont());
960
955
961 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
956 if (forced || QChartPrivate::defaultBrush() == m_titleBrush)
962 q_ptr->setTitleBrush(theme->labelBrush());
957 q_ptr->setTitleBrush(theme->labelBrush());
963 if (forced || QChartPrivate::defaultPen() == m_titlePen)
958 if (forced || QChartPrivate::defaultPen() == m_titlePen)
964 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
959 q_ptr->setTitlePen(Qt::NoPen); // NoPen for performance reasons
965 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
960 if (forced || QChartPrivate::defaultFont() == m_titleFont) {
966 QFont font(m_labelsFont);
961 QFont font(m_labelsFont);
967 font.setBold(true);
962 font.setBold(true);
968 q_ptr->setTitleFont(font);
963 q_ptr->setTitleFont(font);
969 }
964 }
970
965
971 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
966 if (forced || QChartPrivate::defaultBrush() == m_shadesBrush)
972 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
967 q_ptr->setShadesBrush(theme->backgroundShadesBrush());
973 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
968 if (forced || QChartPrivate::defaultPen() == m_shadesPen)
974 q_ptr->setShadesPen(theme->backgroundShadesPen());
969 q_ptr->setShadesPen(theme->backgroundShadesPen());
975
970
976 bool axisX = m_orientation == Qt::Horizontal;
971 bool axisX = m_orientation == Qt::Horizontal;
977 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
972 if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth
978 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
973 || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX)
979 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
974 || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) {
980 q_ptr->setShadesVisible(true);
975 q_ptr->setShadesVisible(true);
981 } else if (forced) {
976 } else if (forced) {
982 q_ptr->setShadesVisible(false);
977 q_ptr->setShadesVisible(false);
983 }
978 }
984 }
979 }
985
980
986 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
981 void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max)
987 {
982 {
988 setRange(min,max);
983 setRange(min,max);
989 }
984 }
990
985
991 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
986 void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent)
992 {
987 {
993 Q_UNUSED(parent);
988 Q_UNUSED(parent);
994 }
989 }
995
990
996 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
991 void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options)
997 {
992 {
998 ChartAxisElement *axis = m_item.data();
993 ChartAxisElement *axis = m_item.data();
999 Q_ASSERT(axis);
994 Q_ASSERT(axis);
1000 if (axis->animation())
995 if (axis->animation())
1001 axis->animation()->stopAndDestroyLater();
996 axis->animation()->stopAndDestroyLater();
1002
997
1003 if (options.testFlag(QChart::GridAxisAnimations))
998 if (options.testFlag(QChart::GridAxisAnimations))
1004 axis->setAnimation(new AxisAnimation(axis));
999 axis->setAnimation(new AxisAnimation(axis));
1005 else
1000 else
1006 axis->setAnimation(0);
1001 axis->setAnimation(0);
1007 }
1002 }
1008
1003
1009
1004
1010
1005
1011 #include "moc_qabstractaxis.cpp"
1006 #include "moc_qabstractaxis.cpp"
1012 #include "moc_qabstractaxis_p.cpp"
1007 #include "moc_qabstractaxis_p.cpp"
1013
1008
1014 QTCOMMERCIALCHART_END_NAMESPACE
1009 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,193 +1,193
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 QABSTRACTAXIS_H
21 #ifndef QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
22 #define QABSTRACTAXIS_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QFont>
26 #include <QFont>
27 #include <QVariant>
27 #include <QVariant>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QAbstractAxisPrivate;
31 class QAbstractAxisPrivate;
32
32
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
33 class QTCOMMERCIALCHART_EXPORT QAbstractAxis : public QObject
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 //visibility
36 //visibility
37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
37 Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
38 //arrow
38 //arrow
39 Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged)
39 Q_PROPERTY(bool lineVisible READ isLineVisible WRITE setLineVisible NOTIFY lineVisibleChanged)
40 Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged)
40 Q_PROPERTY(QPen linePen READ linePen WRITE setLinePen NOTIFY linePenChanged)
41 Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged)
41 Q_PROPERTY(QColor color READ linePenColor WRITE setLinePenColor NOTIFY colorChanged)
42 //labels
42 //labels
43 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
43 Q_PROPERTY(bool labelsVisible READ labelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
44 Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged)
44 Q_PROPERTY(QPen labelsPen READ labelsPen WRITE setLabelsPen NOTIFY labelsPenChanged)
45 Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged)
45 Q_PROPERTY(QBrush labelsBrush READ labelsBrush WRITE setLabelsBrush NOTIFY labelsBrushChanged)
46 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged)
46 Q_PROPERTY(int labelsAngle READ labelsAngle WRITE setLabelsAngle NOTIFY labelsAngleChanged)
47 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged)
47 Q_PROPERTY(QFont labelsFont READ labelsFont WRITE setLabelsFont NOTIFY labelsFontChanged)
48 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
48 Q_PROPERTY(QColor labelsColor READ labelsColor WRITE setLabelsColor NOTIFY labelsColorChanged)
49 //grid
49 //grid
50 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
50 Q_PROPERTY(bool gridVisible READ isGridLineVisible WRITE setGridLineVisible NOTIFY gridVisibleChanged)
51 Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged)
51 Q_PROPERTY(QPen gridLinePen READ gridLinePen WRITE setGridLinePen NOTIFY gridLinePenChanged)
52 //shades
52 //shades
53 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
53 Q_PROPERTY(bool shadesVisible READ shadesVisible WRITE setShadesVisible NOTIFY shadesVisibleChanged)
54 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
54 Q_PROPERTY(QColor shadesColor READ shadesColor WRITE setShadesColor NOTIFY shadesColorChanged)
55 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
55 Q_PROPERTY(QColor shadesBorderColor READ shadesBorderColor WRITE setShadesBorderColor NOTIFY shadesBorderColorChanged)
56 Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged)
56 Q_PROPERTY(QPen shadesPen READ shadesPen WRITE setShadesPen NOTIFY shadesPenChanged)
57 Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged)
57 Q_PROPERTY(QBrush shadesBrush READ shadesBrush WRITE setShadesBrush NOTIFY shadesBrushChanged)
58 //title
58 //title
59 Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged)
59 Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged)
60 Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged)
60 Q_PROPERTY(QPen titlePen READ titlePen WRITE setTitlePen NOTIFY titlePenChanged)
61 Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged)
61 Q_PROPERTY(QBrush titleBrush READ titleBrush WRITE setTitleBrush NOTIFY titleBrushChanged)
62 Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged)
62 Q_PROPERTY(bool titleVisible READ isTitleVisible WRITE setTitleVisible NOTIFY titleVisibleChanged)
63 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged)
63 Q_PROPERTY(QFont titleFont READ titleFont WRITE setTitleFont NOTIFY titleFontChanged)
64 //orientation
64 //orientation
65 Q_PROPERTY(Qt::Orientation orientation READ orientation)
65 Q_PROPERTY(Qt::Orientation orientation READ orientation)
66 //aligment
66 //aligment
67 Q_PROPERTY(Qt::Alignment alignment READ alignment)
67 Q_PROPERTY(Qt::Alignment alignment READ alignment)
68
68
69 public:
69 public:
70
70
71 enum AxisType {
71 enum AxisType {
72 AxisTypeNoAxis = 0x0,
72 AxisTypeNoAxis = 0x0,
73 AxisTypeValue = 0x1,
73 AxisTypeValue = 0x1,
74 AxisTypeBarCategory = 0x2,
74 AxisTypeBarCategory = 0x2,
75 AxisTypeCategory = 0x3,
75 AxisTypeCategory = 0x3,
76 AxisTypeDateTime = 0x4,
76 AxisTypeDateTime = 0x4,
77 AxisTypeLogValue = 0x5
77 AxisTypeLogValue = 0x5
78 };
78 };
79
79
80 Q_DECLARE_FLAGS(AxisTypes, AxisType)
80 Q_DECLARE_FLAGS(AxisTypes, AxisType)
81
81
82 protected:
82 protected:
83 explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0);
83 explicit QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent = 0);
84
84
85 public:
85 public:
86 ~QAbstractAxis();
86 ~QAbstractAxis();
87
87
88 virtual AxisType type() const = 0;
88 virtual AxisType type() const = 0;
89
89
90 //visibility handling
90 //visibility handling
91 bool isVisible() const;
91 bool isVisible() const;
92 void setVisible(bool visible = true);
92 void setVisible(bool visible = true);
93 void show();
93 void show();
94 void hide();
94 void hide();
95
95
96 //arrow handling
96 //arrow handling
97 bool isLineVisible() const;
97 bool isLineVisible() const;
98 void setLineVisible(bool visible = true);
98 void setLineVisible(bool visible = true);
99 void setLinePen(const QPen &pen);
99 void setLinePen(const QPen &pen);
100 QPen linePen() const;
100 QPen linePen() const;
101 void setLinePenColor(QColor color);
101 void setLinePenColor(QColor color);
102 QColor linePenColor() const;
102 QColor linePenColor() const;
103
103
104 //grid handling
104 //grid handling
105 bool isGridLineVisible() const;
105 bool isGridLineVisible() const;
106 void setGridLineVisible(bool visible = true);
106 void setGridLineVisible(bool visible = true);
107 void setGridLinePen(const QPen &pen);
107 void setGridLinePen(const QPen &pen);
108 QPen gridLinePen() const;
108 QPen gridLinePen() const;
109
109
110 //labels handling
110 //labels handling
111 bool labelsVisible() const;
111 bool labelsVisible() const;
112 void setLabelsVisible(bool visible = true);
112 void setLabelsVisible(bool visible = true);
113 void setLabelsPen(const QPen &pen);
113 void setLabelsPen(const QPen &pen);
114 QPen labelsPen() const;
114 QPen labelsPen() const;
115 void setLabelsBrush(const QBrush &brush);
115 void setLabelsBrush(const QBrush &brush);
116 QBrush labelsBrush() const;
116 QBrush labelsBrush() const;
117 void setLabelsFont(const QFont &font);
117 void setLabelsFont(const QFont &font);
118 QFont labelsFont() const;
118 QFont labelsFont() const;
119 void setLabelsAngle(int angle);
119 void setLabelsAngle(int angle);
120 int labelsAngle() const;
120 int labelsAngle() const;
121 void setLabelsColor(QColor color);
121 void setLabelsColor(QColor color);
122 QColor labelsColor() const;
122 QColor labelsColor() const;
123
123
124 //title handling
124 //title handling
125 bool isTitleVisible() const;
125 bool isTitleVisible() const;
126 void setTitleVisible(bool visible = true);
126 void setTitleVisible(bool visible = true);
127 void setTitlePen(const QPen &pen);
127 void setTitlePen(const QPen &pen);
128 QPen titlePen() const;
128 QPen titlePen() const;
129 void setTitleBrush(const QBrush &brush);
129 void setTitleBrush(const QBrush &brush);
130 QBrush titleBrush() const;
130 QBrush titleBrush() const;
131 void setTitleFont(const QFont &font);
131 void setTitleFont(const QFont &font);
132 QFont titleFont() const;
132 QFont titleFont() const;
133 void setTitleText(const QString &title);
133 void setTitleText(const QString &title);
134 QString titleText() const;
134 QString titleText() const;
135
135
136 //shades handling
136 //shades handling
137 bool shadesVisible() const;
137 bool shadesVisible() const;
138 void setShadesVisible(bool visible = true);
138 void setShadesVisible(bool visible = true);
139 void setShadesPen(const QPen &pen);
139 void setShadesPen(const QPen &pen);
140 QPen shadesPen() const;
140 QPen shadesPen() const;
141 void setShadesBrush(const QBrush &brush);
141 void setShadesBrush(const QBrush &brush);
142 QBrush shadesBrush() const;
142 QBrush shadesBrush() const;
143 void setShadesColor(QColor color);
143 void setShadesColor(QColor color);
144 QColor shadesColor() const;
144 QColor shadesColor() const;
145 void setShadesBorderColor(QColor color);
145 void setShadesBorderColor(QColor color);
146 QColor shadesBorderColor() const;
146 QColor shadesBorderColor() const;
147
147
148 Qt::Orientation orientation(); //TODO: missing const <- BC (2.0)
148 Qt::Orientation orientation();
149 Qt::Alignment alignment() const;
149 Qt::Alignment alignment() const;
150
150
151 //range handling
151 //range handling
152 void setMin(const QVariant &min);
152 void setMin(const QVariant &min);
153 void setMax(const QVariant &max);
153 void setMax(const QVariant &max);
154 void setRange(const QVariant &min, const QVariant &max);
154 void setRange(const QVariant &min, const QVariant &max);
155
155
156 Q_SIGNALS:
156 Q_SIGNALS:
157 void visibleChanged(bool visible);
157 void visibleChanged(bool visible);
158 void linePenChanged(const QPen &pen);
158 void linePenChanged(const QPen &pen);
159 void lineVisibleChanged(bool visible);
159 void lineVisibleChanged(bool visible);
160 void labelsVisibleChanged(bool visible);
160 void labelsVisibleChanged(bool visible);
161 void labelsPenChanged(const QPen &pen);
161 void labelsPenChanged(const QPen &pen);
162 void labelsBrushChanged(const QBrush &brush);
162 void labelsBrushChanged(const QBrush &brush);
163 void labelsFontChanged(const QFont &pen);
163 void labelsFontChanged(const QFont &pen);
164 void labelsAngleChanged(int angle);
164 void labelsAngleChanged(int angle);
165 void gridLinePenChanged(const QPen &pen);
165 void gridLinePenChanged(const QPen &pen);
166 void gridVisibleChanged(bool visible);
166 void gridVisibleChanged(bool visible);
167 void colorChanged(QColor color);
167 void colorChanged(QColor color);
168 void labelsColorChanged(QColor color);
168 void labelsColorChanged(QColor color);
169 void titleTextChanged(const QString &title);
169 void titleTextChanged(const QString &title);
170 void titlePenChanged(const QPen &pen);
170 void titlePenChanged(const QPen &pen);
171 void titleBrushChanged(const QBrush &brush);
171 void titleBrushChanged(const QBrush &brush);
172 void titleVisibleChanged(bool visible);
172 void titleVisibleChanged(bool visible);
173 void titleFontChanged(const QFont &font);
173 void titleFontChanged(const QFont &font);
174 void shadesVisibleChanged(bool visible);
174 void shadesVisibleChanged(bool visible);
175 void shadesColorChanged(QColor color);
175 void shadesColorChanged(QColor color);
176 void shadesBorderColorChanged(QColor color);
176 void shadesBorderColorChanged(QColor color);
177 void shadesPenChanged(const QPen &pen);
177 void shadesPenChanged(const QPen &pen);
178 void shadesBrushChanged(const QBrush &brush);
178 void shadesBrushChanged(const QBrush &brush);
179
179
180 protected:
180 protected:
181 QScopedPointer<QAbstractAxisPrivate> d_ptr;
181 QScopedPointer<QAbstractAxisPrivate> d_ptr;
182 Q_DISABLE_COPY(QAbstractAxis)
182 Q_DISABLE_COPY(QAbstractAxis)
183 friend class ChartDataSet;
183 friend class ChartDataSet;
184 friend class ChartPresenter;
184 friend class ChartPresenter;
185 friend class ChartThemeManager;
185 friend class ChartThemeManager;
186 friend class AbstractDomain;
186 friend class AbstractDomain;
187 friend class ChartAxisElement;
187 friend class ChartAxisElement;
188 friend class XYChart;
188 friend class XYChart;
189 };
189 };
190
190
191 QTCOMMERCIALCHART_END_NAMESPACE
191 QTCOMMERCIALCHART_END_NAMESPACE
192
192
193 #endif // QABSTRACTAXIS_H
193 #endif // QABSTRACTAXIS_H
@@ -1,84 +1,83
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 QVALUEAXIS_H
21 #ifndef QVALUEAXIS_H
22 #define QVALUEAXIS_H
22 #define QVALUEAXIS_H
23
23
24 #include "qabstractaxis.h"
24 #include "qabstractaxis.h"
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QValueAxisPrivate;
28 class QValueAxisPrivate;
29
29
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
30 class QTCOMMERCIALCHART_EXPORT QValueAxis : public QAbstractAxis
31 {
31 {
32 Q_OBJECT
32 Q_OBJECT
33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged)
33 Q_PROPERTY(int tickCount READ tickCount WRITE setTickCount NOTIFY tickCountChanged)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
34 Q_PROPERTY(bool niceNumbersEnabled READ niceNumbersEnabled WRITE setNiceNumbersEnabled)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
35 Q_PROPERTY(qreal min READ min WRITE setMin NOTIFY minChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
36 Q_PROPERTY(qreal max READ max WRITE setMax NOTIFY maxChanged)
37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged)
37 Q_PROPERTY(QString labelFormat READ labelFormat WRITE setLabelFormat NOTIFY labelFormatChanged)
38
38
39 public:
39 public:
40 explicit QValueAxis(QObject *parent = 0);
40 explicit QValueAxis(QObject *parent = 0);
41 ~QValueAxis();
41 ~QValueAxis();
42
42
43 protected:
43 protected:
44 QValueAxis(QValueAxisPrivate &d, QObject *parent = 0);
44 QValueAxis(QValueAxisPrivate &d, QObject *parent = 0);
45
45
46 public:
46 public:
47 AxisType type() const;
47 AxisType type() const;
48
48
49 //range handling
49 //range handling
50 void setMin(qreal min);
50 void setMin(qreal min);
51 qreal min() const;
51 qreal min() const;
52 void setMax(qreal max);
52 void setMax(qreal max);
53 qreal max() const;
53 qreal max() const;
54 void setRange(qreal min, qreal max);
54 void setRange(qreal min, qreal max);
55
55
56 //ticks handling
56 //ticks handling
57 void setTickCount(int count);
57 void setTickCount(int count);
58 int tickCount() const;
58 int tickCount() const;
59
59
60 void setLabelFormat(const QString &format);
60 void setLabelFormat(const QString &format);
61 QString labelFormat() const;
61 QString labelFormat() const;
62
62
63 //TODO: deprecated! (2.0)
64 void setNiceNumbersEnabled(bool enable = true);
63 void setNiceNumbersEnabled(bool enable = true);
65 bool niceNumbersEnabled() const;
64 bool niceNumbersEnabled() const;
66
65
67 public Q_SLOTS:
66 public Q_SLOTS:
68 void applyNiceNumbers();
67 void applyNiceNumbers();
69
68
70 Q_SIGNALS:
69 Q_SIGNALS:
71 void minChanged(qreal min);
70 void minChanged(qreal min);
72 void maxChanged(qreal max);
71 void maxChanged(qreal max);
73 void rangeChanged(qreal min, qreal max);
72 void rangeChanged(qreal min, qreal max);
74 void tickCountChanged(int tickCount);
73 void tickCountChanged(int tickCount);
75 void labelFormatChanged(const QString &format);
74 void labelFormatChanged(const QString &format);
76
75
77 private:
76 private:
78 Q_DECLARE_PRIVATE(QValueAxis)
77 Q_DECLARE_PRIVATE(QValueAxis)
79 Q_DISABLE_COPY(QValueAxis)
78 Q_DISABLE_COPY(QValueAxis)
80 };
79 };
81
80
82 QTCOMMERCIALCHART_END_NAMESPACE
81 QTCOMMERCIALCHART_END_NAMESPACE
83
82
84 #endif // QVALUEAXIS_H
83 #endif // QVALUEAXIS_H
@@ -1,70 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 Qt Enterprise Chart API. It exists purely as an
24 // This file is not part of the Qt Enterprise 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 QVALUEAXIS_P_H
30 #ifndef QVALUEAXIS_P_H
31 #define QVALUEAXIS_P_H
31 #define QVALUEAXIS_P_H
32
32
33 #include "qvalueaxis.h"
33 #include "qvalueaxis.h"
34 #include "qabstractaxis_p.h"
34 #include "qabstractaxis_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38 class QValueAxisPrivate : public QAbstractAxisPrivate
38 class QValueAxisPrivate : public QAbstractAxisPrivate
39 {
39 {
40 Q_OBJECT
40 Q_OBJECT
41 public:
41 public:
42 QValueAxisPrivate(QValueAxis *q);
42 QValueAxisPrivate(QValueAxis *q);
43 ~QValueAxisPrivate();
43 ~QValueAxisPrivate();
44
44
45 public:
45 public:
46 void initializeGraphics(QGraphicsItem* parent);
46 void initializeGraphics(QGraphicsItem* parent);
47 void initializeDomain(AbstractDomain *domain);
47 void initializeDomain(AbstractDomain *domain);
48
48
49 qreal min() { return m_min; };
49 qreal min() { return m_min; };
50 qreal max() { return m_max; };
50 qreal max() { return m_max; };
51 void setRange(qreal min,qreal max);
51 void setRange(qreal min,qreal max);
52
52
53 protected:
53 protected:
54 void setMin(const QVariant &min);
54 void setMin(const QVariant &min);
55 void setMax(const QVariant &max);
55 void setMax(const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
56 void setRange(const QVariant &min, const QVariant &max);
57
57
58 private:
58 private:
59 qreal m_min;
59 qreal m_min;
60 qreal m_max;
60 qreal m_max;
61 int m_tickCount;
61 int m_tickCount;
62 QString m_format;
62 QString m_format;
63 bool m_applying;
63 bool m_applying;
64 bool m_niceNumbersEnabled; //TODO: this deprecated (2.0)
64 bool m_niceNumbersEnabled;
65 Q_DECLARE_PUBLIC(QValueAxis)
65 Q_DECLARE_PUBLIC(QValueAxis)
66 };
66 };
67
67
68 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
69
69
70 #endif // QVALUEAXIS_P_H
70 #endif // QVALUEAXIS_P_H
@@ -1,180 +1,179
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 Qt Enterprise Chart API. It exists purely as an
24 // This file is not part of the Qt Enterprise 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 CHARTPRESENTER_H
30 #ifndef CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
31 #define CHARTPRESENTER_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h" //because of QChart::ChartThemeId
34 #include "qchart.h" //because of QChart::ChartThemeId
35 #include <QRectF>
35 #include <QRectF>
36 #include <QMargins>
36 #include <QMargins>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class ChartItem;
40 class ChartItem;
41 class AxisItem;
41 class AxisItem;
42 class QAbstractSeries;
42 class QAbstractSeries;
43 class ChartDataSet;
43 class ChartDataSet;
44 class AbstractDomain;
44 class AbstractDomain;
45 class ChartAxisElement;
45 class ChartAxisElement;
46 class ChartAnimator;
46 class ChartAnimator;
47 class ChartBackground;
47 class ChartBackground;
48 class ChartTitle;
48 class ChartTitle;
49 class ChartAnimation;
49 class ChartAnimation;
50 class AbstractChartLayout;
50 class AbstractChartLayout;
51
51
52 class ChartPresenter: public QObject
52 class ChartPresenter: public QObject
53 {
53 {
54 Q_OBJECT
54 Q_OBJECT
55 public:
55 public:
56 enum ZValues {
56 enum ZValues {
57 BackgroundZValue = -1,
57 BackgroundZValue = -1,
58 PlotAreaZValue,
58 PlotAreaZValue,
59 ShadesZValue,
59 ShadesZValue,
60 GridZValue,
60 GridZValue,
61 AxisZValue,
61 AxisZValue,
62 SeriesZValue,
62 SeriesZValue,
63 LineChartZValue = SeriesZValue,
63 LineChartZValue = SeriesZValue,
64 SplineChartZValue = SeriesZValue,
64 SplineChartZValue = SeriesZValue,
65 BarSeriesZValue = SeriesZValue,
65 BarSeriesZValue = SeriesZValue,
66 ScatterSeriesZValue = SeriesZValue,
66 ScatterSeriesZValue = SeriesZValue,
67 PieSeriesZValue = SeriesZValue,
67 PieSeriesZValue = SeriesZValue,
68 BoxPlotSeriesZValue = SeriesZValue,
68 BoxPlotSeriesZValue = SeriesZValue,
69 LegendZValue,
69 LegendZValue,
70 TopMostZValue
70 TopMostZValue
71 };
71 };
72
72
73 enum State {
73 enum State {
74 ShowState,
74 ShowState,
75 ScrollUpState,
75 ScrollUpState,
76 ScrollDownState,
76 ScrollDownState,
77 ScrollLeftState,
77 ScrollLeftState,
78 ScrollRightState,
78 ScrollRightState,
79 ZoomInState,
79 ZoomInState,
80 ZoomOutState
80 ZoomOutState
81 };
81 };
82
82
83 ChartPresenter(QChart *chart, QChart::ChartType type);
83 ChartPresenter(QChart *chart, QChart::ChartType type);
84 virtual ~ChartPresenter();
84 virtual ~ChartPresenter();
85
85
86
86
87 void setGeometry(QRectF rect);
87 void setGeometry(QRectF rect);
88 QRectF geometry() const;
88 QRectF geometry() const;
89
89
90 QGraphicsItem *rootItem(){ return m_chart; }
90 QGraphicsItem *rootItem(){ return m_chart; }
91 ChartBackground *backgroundElement();
91 ChartBackground *backgroundElement();
92 QAbstractGraphicsShapeItem *plotAreaElement();
92 QAbstractGraphicsShapeItem *plotAreaElement();
93 ChartTitle *titleElement();
93 ChartTitle *titleElement();
94 QList<ChartAxisElement *> axisItems() const;
94 QList<ChartAxisElement *> axisItems() const;
95 QList<ChartItem *> chartItems() const;
95 QList<ChartItem *> chartItems() const;
96
96
97 QLegend *legend();
97 QLegend *legend();
98
98
99 void setBackgroundBrush(const QBrush &brush);
99 void setBackgroundBrush(const QBrush &brush);
100 QBrush backgroundBrush() const;
100 QBrush backgroundBrush() const;
101
101
102 void setBackgroundPen(const QPen &pen);
102 void setBackgroundPen(const QPen &pen);
103 QPen backgroundPen() const;
103 QPen backgroundPen() const;
104
104
105 void setBackgroundRoundness(qreal diameter);
105 void setBackgroundRoundness(qreal diameter);
106 qreal backgroundRoundness() const;
106 qreal backgroundRoundness() const;
107
107
108 void setPlotAreaBackgroundBrush(const QBrush &brush);
108 void setPlotAreaBackgroundBrush(const QBrush &brush);
109 QBrush plotAreaBackgroundBrush() const;
109 QBrush plotAreaBackgroundBrush() const;
110
110
111 void setPlotAreaBackgroundPen(const QPen &pen);
111 void setPlotAreaBackgroundPen(const QPen &pen);
112 QPen plotAreaBackgroundPen() const;
112 QPen plotAreaBackgroundPen() const;
113
113
114 void setTitle(const QString &title);
114 void setTitle(const QString &title);
115 QString title() const;
115 QString title() const;
116
116
117 void setTitleFont(const QFont &font);
117 void setTitleFont(const QFont &font);
118 QFont titleFont() const;
118 QFont titleFont() const;
119
119
120 void setTitleBrush(const QBrush &brush);
120 void setTitleBrush(const QBrush &brush);
121 QBrush titleBrush() const;
121 QBrush titleBrush() const;
122
122
123 void setBackgroundVisible(bool visible);
123 void setBackgroundVisible(bool visible);
124 bool isBackgroundVisible() const;
124 bool isBackgroundVisible() const;
125
125
126 void setPlotAreaBackgroundVisible(bool visible);
126 void setPlotAreaBackgroundVisible(bool visible);
127 bool isPlotAreaBackgroundVisible() const;
127 bool isPlotAreaBackgroundVisible() const;
128
128
129 void setBackgroundDropShadowEnabled(bool enabled);
129 void setBackgroundDropShadowEnabled(bool enabled);
130 bool isBackgroundDropShadowEnabled() const;
130 bool isBackgroundDropShadowEnabled() const;
131
131
132 void setVisible(bool visible);
132 void setVisible(bool visible);
133
133
134 void setAnimationOptions(QChart::AnimationOptions options);
134 void setAnimationOptions(QChart::AnimationOptions options);
135 QChart::AnimationOptions animationOptions() const;
135 QChart::AnimationOptions animationOptions() const;
136
136
137 void startAnimation(ChartAnimation *animation);
137 void startAnimation(ChartAnimation *animation);
138
138
139 //TODO refactor
140 void setState(State state,QPointF point);
139 void setState(State state,QPointF point);
141 State state() const { return m_state; }
140 State state() const { return m_state; }
142 QPointF statePoint() const { return m_statePoint; }
141 QPointF statePoint() const { return m_statePoint; }
143 AbstractChartLayout *layout();
142 AbstractChartLayout *layout();
144
143
145 QChart::ChartType chartType() const { return m_chart->chartType(); }
144 QChart::ChartType chartType() const { return m_chart->chartType(); }
146 QChart *chart() { return m_chart; }
145 QChart *chart() { return m_chart; }
147
146
148 static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0);
147 static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0);
149 static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize,
148 static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize,
150 Qt::Orientation constraintOrientation, QRectF &boundingRect);
149 Qt::Orientation constraintOrientation, QRectF &boundingRect);
151 private:
150 private:
152 void createBackgroundItem();
151 void createBackgroundItem();
153 void createPlotAreaBackgroundItem();
152 void createPlotAreaBackgroundItem();
154 void createTitleItem();
153 void createTitleItem();
155
154
156 public Q_SLOTS:
155 public Q_SLOTS:
157 void handleSeriesAdded(QAbstractSeries *series);
156 void handleSeriesAdded(QAbstractSeries *series);
158 void handleSeriesRemoved(QAbstractSeries *series);
157 void handleSeriesRemoved(QAbstractSeries *series);
159 void handleAxisAdded(QAbstractAxis *axis);
158 void handleAxisAdded(QAbstractAxis *axis);
160 void handleAxisRemoved(QAbstractAxis *axis);
159 void handleAxisRemoved(QAbstractAxis *axis);
161
160
162 private:
161 private:
163 QChart *m_chart;
162 QChart *m_chart;
164 QList<ChartItem *> m_chartItems;
163 QList<ChartItem *> m_chartItems;
165 QList<ChartAxisElement *> m_axisItems;
164 QList<ChartAxisElement *> m_axisItems;
166 QList<QAbstractSeries *> m_series;
165 QList<QAbstractSeries *> m_series;
167 QList<QAbstractAxis *> m_axes;
166 QList<QAbstractAxis *> m_axes;
168 QChart::AnimationOptions m_options;
167 QChart::AnimationOptions m_options;
169 State m_state;
168 State m_state;
170 QPointF m_statePoint;
169 QPointF m_statePoint;
171 AbstractChartLayout *m_layout;
170 AbstractChartLayout *m_layout;
172 ChartBackground *m_background;
171 ChartBackground *m_background;
173 QAbstractGraphicsShapeItem *m_plotAreaBackground;
172 QAbstractGraphicsShapeItem *m_plotAreaBackground;
174 ChartTitle *m_title;
173 ChartTitle *m_title;
175 QRectF m_rect;
174 QRectF m_rect;
176 };
175 };
177
176
178 QTCOMMERCIALCHART_END_NAMESPACE
177 QTCOMMERCIALCHART_END_NAMESPACE
179
178
180 #endif /* CHARTPRESENTER_H */
179 #endif /* CHARTPRESENTER_H */
@@ -1,248 +1,245
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 #include "qabstractseries_p.h"
20 #include "qabstractseries_p.h"
21 #include "qabstractaxis_p.h"
21 #include "qabstractaxis_p.h"
22 #include <QTime>
22 #include <QTime>
23 //themes
23 //themes
24 #include "chartthemesystem_p.h"
24 #include "chartthemesystem_p.h"
25 #include "chartthemelight_p.h"
25 #include "chartthemelight_p.h"
26 #include "chartthemebluecerulean_p.h"
26 #include "chartthemebluecerulean_p.h"
27 #include "chartthemedark_p.h"
27 #include "chartthemedark_p.h"
28 #include "chartthemebrownsand_p.h"
28 #include "chartthemebrownsand_p.h"
29 #include "chartthemebluencs_p.h"
29 #include "chartthemebluencs_p.h"
30 #include "chartthemehighcontrast_p.h"
30 #include "chartthemehighcontrast_p.h"
31 #include "chartthemeblueicy_p.h"
31 #include "chartthemeblueicy_p.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 ChartThemeManager::ChartThemeManager(QChart* chart) :
35 ChartThemeManager::ChartThemeManager(QChart* chart) :
36 m_chart(chart)
36 m_chart(chart)
37 {
37 {
38 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
38 qsrand(QTime(0, 0, 0).secsTo(QTime::currentTime()));
39 }
39 }
40
40
41
41
42 void ChartThemeManager::setTheme(QChart::ChartTheme theme)
42 void ChartThemeManager::setTheme(QChart::ChartTheme theme)
43 {
43 {
44 if (m_theme.isNull() || theme != m_theme->id()) {
44 if (m_theme.isNull() || theme != m_theme->id()) {
45 switch (theme) {
45 switch (theme) {
46 case QChart::ChartThemeLight:
46 case QChart::ChartThemeLight:
47 m_theme.reset(new ChartThemeLight());
47 m_theme.reset(new ChartThemeLight());
48 break;
48 break;
49 case QChart::ChartThemeBlueCerulean:
49 case QChart::ChartThemeBlueCerulean:
50 m_theme.reset(new ChartThemeBlueCerulean());
50 m_theme.reset(new ChartThemeBlueCerulean());
51 break;
51 break;
52 case QChart::ChartThemeDark:
52 case QChart::ChartThemeDark:
53 m_theme.reset(new ChartThemeDark());
53 m_theme.reset(new ChartThemeDark());
54 break;
54 break;
55 case QChart::ChartThemeBrownSand:
55 case QChart::ChartThemeBrownSand:
56 m_theme.reset(new ChartThemeBrownSand());
56 m_theme.reset(new ChartThemeBrownSand());
57 break;
57 break;
58 case QChart::ChartThemeBlueNcs:
58 case QChart::ChartThemeBlueNcs:
59 m_theme.reset(new ChartThemeBlueNcs());
59 m_theme.reset(new ChartThemeBlueNcs());
60 break;
60 break;
61 case QChart::ChartThemeHighContrast:
61 case QChart::ChartThemeHighContrast:
62 m_theme.reset(new ChartThemeHighContrast());
62 m_theme.reset(new ChartThemeHighContrast());
63 break;
63 break;
64 case QChart::ChartThemeBlueIcy:
64 case QChart::ChartThemeBlueIcy:
65 m_theme.reset(new ChartThemeBlueIcy());
65 m_theme.reset(new ChartThemeBlueIcy());
66 break;
66 break;
67 default:
67 default:
68 m_theme.reset(new ChartThemeSystem());
68 m_theme.reset(new ChartThemeSystem());
69 break;
69 break;
70 }
70 }
71
71
72 if (!m_theme.isNull()) {
72 if (!m_theme.isNull()) {
73 decorateChart(m_chart,m_theme.data());
73 decorateChart(m_chart,m_theme.data());
74 decorateLegend(m_chart->legend(),m_theme.data());
74 decorateLegend(m_chart->legend(),m_theme.data());
75 foreach (QAbstractAxis* axis, m_axisList)
75 foreach (QAbstractAxis* axis, m_axisList)
76 axis->d_ptr->initializeTheme(m_theme.data(), true);
76 axis->d_ptr->initializeTheme(m_theme.data(), true);
77 foreach (QAbstractSeries* series, m_seriesMap.keys())
77 foreach (QAbstractSeries* series, m_seriesMap.keys())
78 series->d_ptr->initializeTheme(m_seriesMap[series], m_theme.data(), true);
78 series->d_ptr->initializeTheme(m_seriesMap[series], m_theme.data(), true);
79 }
79 }
80 }
80 }
81 }
81 }
82
82
83 // decorateChart is only called when theme is forcibly initialized
83 // decorateChart is only called when theme is forcibly initialized
84 void ChartThemeManager::decorateChart(QChart *chart, ChartTheme *theme) const
84 void ChartThemeManager::decorateChart(QChart *chart, ChartTheme *theme) const
85 {
85 {
86 chart->setBackgroundBrush(theme->chartBackgroundGradient());
86 chart->setBackgroundBrush(theme->chartBackgroundGradient());
87
87
88 QPen pen(Qt::transparent);
88 QPen pen(Qt::transparent);
89 QBrush brush;
89 QBrush brush;
90 chart->setPlotAreaBackgroundBrush(brush);
90 chart->setPlotAreaBackgroundBrush(brush);
91 chart->setPlotAreaBackgroundPen(pen);
91 chart->setPlotAreaBackgroundPen(pen);
92 chart->setPlotAreaBackgroundVisible(false);
92 chart->setPlotAreaBackgroundVisible(false);
93
93
94 chart->setTitleFont(theme->masterFont());
94 chart->setTitleFont(theme->masterFont());
95 chart->setTitleBrush(theme->labelBrush());
95 chart->setTitleBrush(theme->labelBrush());
96 chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled());
96 chart->setDropShadowEnabled(theme->isBackgroundDropShadowEnabled());
97 }
97 }
98
98
99 // decorateLegend is only called when theme is forcibly initialized
99 // decorateLegend is only called when theme is forcibly initialized
100 void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme *theme) const
100 void ChartThemeManager::decorateLegend(QLegend *legend, ChartTheme *theme) const
101 {
101 {
102 legend->setPen(theme->axisLinePen());
102 legend->setPen(theme->axisLinePen());
103 legend->setBrush(theme->chartBackgroundGradient());
103 legend->setBrush(theme->chartBackgroundGradient());
104 legend->setFont(theme->labelFont());
104 legend->setFont(theme->labelFont());
105 legend->setLabelBrush(theme->labelBrush());
105 legend->setLabelBrush(theme->labelBrush());
106 }
106 }
107
107
108 int ChartThemeManager::createIndexKey(QList<int> keys) const
108 int ChartThemeManager::createIndexKey(QList<int> keys) const
109 {
109 {
110 qSort(keys);
110 qSort(keys);
111
111
112 int key = 0;
112 int key = 0;
113 QList<int>::iterator i;
113 QList<int>::iterator i;
114 i = keys.begin();
114 i = keys.begin();
115
115
116 while (i != keys.end()) {
116 while (i != keys.end()) {
117 if (*i != key)
117 if (*i != key)
118 break;
118 break;
119 key++;
119 key++;
120 i++;
120 i++;
121 }
121 }
122
122
123 return key;
123 return key;
124 }
124 }
125
125
126 int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const
126 int ChartThemeManager::seriesCount(QAbstractSeries::SeriesType type) const
127 {
127 {
128 int count = 0;
128 int count = 0;
129 QList<QAbstractSeries *> series = m_seriesMap.keys();
129 QList<QAbstractSeries *> series = m_seriesMap.keys();
130 foreach(QAbstractSeries *s, series) {
130 foreach(QAbstractSeries *s, series) {
131 if (s->type() == type)
131 if (s->type() == type)
132 count++;
132 count++;
133 }
133 }
134 return count;
134 return count;
135 }
135 }
136
136
137 void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series)
137 void ChartThemeManager::handleSeriesAdded(QAbstractSeries *series)
138 {
138 {
139 int key = createIndexKey(m_seriesMap.values());
139 int key = createIndexKey(m_seriesMap.values());
140 m_seriesMap.insert(series,key);
140 m_seriesMap.insert(series,key);
141 series->d_ptr->initializeTheme(key,m_theme.data(),false);
141 series->d_ptr->initializeTheme(key,m_theme.data(),false);
142 }
142 }
143
143
144 void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series)
144 void ChartThemeManager::handleSeriesRemoved(QAbstractSeries *series)
145 {
145 {
146 m_seriesMap.remove(series);
146 m_seriesMap.remove(series);
147 }
147 }
148
148
149 void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis)
149 void ChartThemeManager::handleAxisAdded(QAbstractAxis *axis)
150 {
150 {
151 m_axisList.append(axis);
151 m_axisList.append(axis);
152 axis->d_ptr->initializeTheme(m_theme.data(),false);
152 axis->d_ptr->initializeTheme(m_theme.data(),false);
153 }
153 }
154
154
155 void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis)
155 void ChartThemeManager::handleAxisRemoved(QAbstractAxis *axis)
156 {
156 {
157 m_axisList.removeAll(axis);
157 m_axisList.removeAll(axis);
158 }
158 }
159
159
160 void ChartThemeManager::updateSeries(QAbstractSeries *series)
160 void ChartThemeManager::updateSeries(QAbstractSeries *series)
161 {
161 {
162 if(m_seriesMap.contains(series)){
162 if(m_seriesMap.contains(series)){
163 series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false);
163 series->d_ptr->initializeTheme(m_seriesMap[series],m_theme.data(),false);
164 }
164 }
165 }
165 }
166 QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors)
166 QList<QGradient> ChartThemeManager::generateSeriesGradients(const QList<QColor>& colors)
167 {
167 {
168 QList<QGradient> result;
168 QList<QGradient> result;
169 // Generate gradients in HSV color space
169 // Generate gradients in HSV color space
170 foreach (const QColor &color, colors) {
170 foreach (const QColor &color, colors) {
171 QLinearGradient g;
171 QLinearGradient g;
172 qreal h = color.hsvHueF();
172 qreal h = color.hsvHueF();
173 qreal s = color.hsvSaturationF();
173 qreal s = color.hsvSaturationF();
174
174
175 // TODO: tune the algorithm to give nice results with most base colors defined in
176 // most themes. The rest of the gradients we can define manually in theme specific
177 // implementation.
178 QColor start = color;
175 QColor start = color;
179 start.setHsvF(h, 0.0, 1.0);
176 start.setHsvF(h, 0.0, 1.0);
180 g.setColorAt(0.0, start);
177 g.setColorAt(0.0, start);
181
178
182 g.setColorAt(0.5, color);
179 g.setColorAt(0.5, color);
183
180
184 QColor end = color;
181 QColor end = color;
185 end.setHsvF(h, s, 0.25);
182 end.setHsvF(h, s, 0.25);
186 g.setColorAt(1.0, end);
183 g.setColorAt(1.0, end);
187
184
188 result << g;
185 result << g;
189 }
186 }
190
187
191 return result;
188 return result;
192 }
189 }
193
190
194
191
195 QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos)
192 QColor ChartThemeManager::colorAt(const QColor &start, const QColor &end, qreal pos)
196 {
193 {
197 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
194 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
198 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
195 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
199 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
196 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
200 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
197 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
201 QColor c;
198 QColor c;
202 c.setRgbF(r, g, b);
199 c.setRgbF(r, g, b);
203 return c;
200 return c;
204 }
201 }
205
202
206 QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos)
203 QColor ChartThemeManager::colorAt(const QGradient &gradient, qreal pos)
207 {
204 {
208 Q_ASSERT(pos >= 0 && pos <= 1.0);
205 Q_ASSERT(pos >= 0 && pos <= 1.0);
209
206
210 QGradientStops stops = gradient.stops();
207 QGradientStops stops = gradient.stops();
211 int count = stops.count();
208 int count = stops.count();
212
209
213 // find previous stop relative to position
210 // find previous stop relative to position
214 QGradientStop prev = stops.first();
211 QGradientStop prev = stops.first();
215 for (int i = 0; i < count; i++) {
212 for (int i = 0; i < count; i++) {
216 QGradientStop stop = stops.at(i);
213 QGradientStop stop = stops.at(i);
217 if (pos > stop.first)
214 if (pos > stop.first)
218 prev = stop;
215 prev = stop;
219
216
220 // given position is actually a stop position?
217 // given position is actually a stop position?
221 if (pos == stop.first) {
218 if (pos == stop.first) {
222 //qDebug() << "stop color" << pos;
219 //qDebug() << "stop color" << pos;
223 return stop.second;
220 return stop.second;
224 }
221 }
225 }
222 }
226
223
227 // find next stop relative to position
224 // find next stop relative to position
228 QGradientStop next = stops.last();
225 QGradientStop next = stops.last();
229 for (int i = count - 1; i >= 0; i--) {
226 for (int i = count - 1; i >= 0; i--) {
230 QGradientStop stop = stops.at(i);
227 QGradientStop stop = stops.at(i);
231 if (pos < stop.first)
228 if (pos < stop.first)
232 next = stop;
229 next = stop;
233 }
230 }
234
231
235 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
232 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
236
233
237 qreal range = next.first - prev.first;
234 qreal range = next.first - prev.first;
238 qreal posDelta = pos - prev.first;
235 qreal posDelta = pos - prev.first;
239 qreal relativePos = posDelta / range;
236 qreal relativePos = posDelta / range;
240
237
241 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
238 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
242
239
243 return colorAt(prev.second, next.second, relativePos);
240 return colorAt(prev.second, next.second, relativePos);
244 }
241 }
245
242
246 #include "moc_chartthememanager_p.cpp"
243 #include "moc_chartthememanager_p.cpp"
247
244
248 QTCOMMERCIALCHART_END_NAMESPACE
245 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,82
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 Qt Enterprise Chart API. It exists purely as an
24 // This file is not part of the Qt Enterprise 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 QLEGENDMARKERPRIVATE_H
30 #ifndef QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
31 #define QLEGENDMARKERPRIVATE_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QBrush>
35 #include <QBrush>
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsLayoutItem>
37 #include <QGraphicsLayoutItem>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 // TODO: check these
42 class QAbstractSeries;
41 class QAbstractSeries;
43 class QAreaSeries;
44 class QXYSeries;
45 class QBarSet;
46 class QAbstractBarSeries;
47 class QPieSlice;
48 class QLegend;
42 class QLegend;
49 class QPieSeries;
50
43
51 class QLegendMarker;
44 class QLegendMarker;
52 class LegendMarkerItem;
45 class LegendMarkerItem;
53
46
54 class QLegendMarkerPrivate : public QObject
47 class QLegendMarkerPrivate : public QObject
55 {
48 {
56 Q_OBJECT
49 Q_OBJECT
57 public:
50 public:
58 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
51 explicit QLegendMarkerPrivate(QLegendMarker *q, QLegend *legend);
59 virtual ~QLegendMarkerPrivate();
52 virtual ~QLegendMarkerPrivate();
60
53
61 // Helper for now. (or declare LegendLayout as friend)
54 // Helper for now. (or declare LegendLayout as friend)
62 LegendMarkerItem* item() const { return m_item; }
55 LegendMarkerItem* item() const { return m_item; }
63
56
64 virtual QAbstractSeries* series() = 0;
57 virtual QAbstractSeries* series() = 0;
65 virtual QObject* relatedObject() = 0;
58 virtual QObject* relatedObject() = 0;
66
59
67 void invalidateLegend();
60 void invalidateLegend();
68
61
69 public Q_SLOTS:
62 public Q_SLOTS:
70 virtual void updated() = 0;
63 virtual void updated() = 0;
71
64
72 protected:
65 protected:
73 LegendMarkerItem *m_item;
66 LegendMarkerItem *m_item;
74 QLegend *m_legend;
67 QLegend *m_legend;
75 bool m_customLabel;
68 bool m_customLabel;
76 bool m_customBrush;
69 bool m_customBrush;
77 bool m_customPen;
70 bool m_customPen;
78
71
79 private:
72 private:
80 QLegendMarker *q_ptr;
73 QLegendMarker *q_ptr;
81
74
82 friend class QLegendPrivate;
75 friend class QLegendPrivate;
83 friend class LegendMarkerItem;
76 friend class LegendMarkerItem;
84 Q_DECLARE_PUBLIC(QLegendMarker)
77 Q_DECLARE_PUBLIC(QLegendMarker)
85 };
78 };
86
79
87 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
88
81
89 #endif // QLEGENDMARKERPRIVATE_H
82 #endif // QLEGENDMARKERPRIVATE_H
@@ -1,207 +1,206
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "qchart.h"
26 #include "qchart.h"
27 #include <QPainter>
27 #include <QPainter>
28 #include <QGraphicsScene>
28 #include <QGraphicsScene>
29 #include <QDebug>
29 #include <QDebug>
30 #include <QGraphicsSceneMouseEvent>
30 #include <QGraphicsSceneMouseEvent>
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
34 ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *item)
35 : XYChart(series,item),
35 : XYChart(series,item),
36 m_series(series),
36 m_series(series),
37 m_items(this),
37 m_items(this),
38 m_visible(true),
38 m_visible(true),
39 m_shape(QScatterSeries::MarkerShapeRectangle),
39 m_shape(QScatterSeries::MarkerShapeRectangle),
40 m_size(15)
40 m_size(15)
41 {
41 {
42 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
42 QObject::connect(m_series->d_func(), SIGNAL(updated()), this, SLOT(handleUpdated()));
43 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
43 QObject::connect(m_series, SIGNAL(visibleChanged()), this, SLOT(handleUpdated()));
44 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
44 QObject::connect(m_series, SIGNAL(opacityChanged()), this, SLOT(handleUpdated()));
45
45
46 setZValue(ChartPresenter::ScatterSeriesZValue);
46 setZValue(ChartPresenter::ScatterSeriesZValue);
47 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
47 setFlags(QGraphicsItem::ItemClipsChildrenToShape);
48
48
49 handleUpdated();
49 handleUpdated();
50
50
51 m_items.setHandlesChildEvents(false);
51 m_items.setHandlesChildEvents(false);
52 }
52 }
53
53
54 QRectF ScatterChartItem::boundingRect() const
54 QRectF ScatterChartItem::boundingRect() const
55 {
55 {
56 return m_rect;
56 return m_rect;
57 }
57 }
58
58
59 void ScatterChartItem::createPoints(int count)
59 void ScatterChartItem::createPoints(int count)
60 {
60 {
61 for (int i = 0; i < count; ++i) {
61 for (int i = 0; i < count; ++i) {
62
62
63 QGraphicsItem *item = 0;
63 QGraphicsItem *item = 0;
64
64
65 switch (m_shape) {
65 switch (m_shape) {
66 case QScatterSeries::MarkerShapeCircle: {
66 case QScatterSeries::MarkerShapeCircle: {
67 item = new CircleMarker(0, 0, m_size, m_size, this);
67 item = new CircleMarker(0, 0, m_size, m_size, this);
68 const QRectF &rect = item->boundingRect();
68 const QRectF &rect = item->boundingRect();
69 item->setPos(-rect.width() / 2, -rect.height() / 2);
69 item->setPos(-rect.width() / 2, -rect.height() / 2);
70 break;
70 break;
71 }
71 }
72 case QScatterSeries::MarkerShapeRectangle:
72 case QScatterSeries::MarkerShapeRectangle:
73 item = new RectangleMarker(0, 0, m_size, m_size, this);
73 item = new RectangleMarker(0, 0, m_size, m_size, this);
74 item->setPos(-m_size / 2, -m_size / 2);
74 item->setPos(-m_size / 2, -m_size / 2);
75 break;
75 break;
76 default:
76 default:
77 qWarning() << "Unsupported marker type";
77 qWarning() << "Unsupported marker type";
78 break;
78 break;
79 }
79 }
80 m_items.addToGroup(item);
80 m_items.addToGroup(item);
81 }
81 }
82 }
82 }
83
83
84 void ScatterChartItem::deletePoints(int count)
84 void ScatterChartItem::deletePoints(int count)
85 {
85 {
86 QList<QGraphicsItem *> items = m_items.childItems();
86 QList<QGraphicsItem *> items = m_items.childItems();
87
87
88 for (int i = 0; i < count; ++i) {
88 for (int i = 0; i < count; ++i) {
89 QGraphicsItem *item = items.takeLast();
89 QGraphicsItem *item = items.takeLast();
90 m_markerMap.remove(item);
90 m_markerMap.remove(item);
91 delete(item);
91 delete(item);
92 }
92 }
93 }
93 }
94
94
95 void ScatterChartItem::markerSelected(QGraphicsItem *marker)
95 void ScatterChartItem::markerSelected(QGraphicsItem *marker)
96 {
96 {
97 emit XYChart::clicked(m_markerMap[marker]);
97 emit XYChart::clicked(m_markerMap[marker]);
98 }
98 }
99
99
100 void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state)
100 void ScatterChartItem::markerHovered(QGraphicsItem *marker, bool state)
101 {
101 {
102 emit XYChart::hovered(m_markerMap[marker], state);
102 emit XYChart::hovered(m_markerMap[marker], state);
103 }
103 }
104
104
105 void ScatterChartItem::updateGeometry()
105 void ScatterChartItem::updateGeometry()
106 {
106 {
107
107
108 const QVector<QPointF>& points = geometryPoints();
108 const QVector<QPointF>& points = geometryPoints();
109
109
110 if (points.size() == 0) {
110 if (points.size() == 0) {
111 deletePoints(m_items.childItems().count());
111 deletePoints(m_items.childItems().count());
112 return;
112 return;
113 }
113 }
114
114
115 int diff = m_items.childItems().size() - points.size();
115 int diff = m_items.childItems().size() - points.size();
116
116
117 if (diff > 0)
117 if (diff > 0)
118 deletePoints(diff);
118 deletePoints(diff);
119 else if (diff < 0)
119 else if (diff < 0)
120 createPoints(-diff);
120 createPoints(-diff);
121
121
122 if (diff != 0)
122 if (diff != 0)
123 handleUpdated();
123 handleUpdated();
124
124
125 QList<QGraphicsItem *> items = m_items.childItems();
125 QList<QGraphicsItem *> items = m_items.childItems();
126
126
127 QRectF clipRect(QPointF(0,0),domain()->size());
127 QRectF clipRect(QPointF(0,0),domain()->size());
128
128
129 QVector<bool> offGridStatus = offGridStatusVector();
129 QVector<bool> offGridStatus = offGridStatusVector();
130 const int seriesLastIndex = m_series->count() - 1;
130 const int seriesLastIndex = m_series->count() - 1;
131
131
132 for (int i = 0; i < points.size(); i++) {
132 for (int i = 0; i < points.size(); i++) {
133 QGraphicsItem *item = items.at(i);
133 QGraphicsItem *item = items.at(i);
134 const QPointF &point = points.at(i);
134 const QPointF &point = points.at(i);
135 const QRectF &rect = item->boundingRect();
135 const QRectF &rect = item->boundingRect();
136 // During remove animation series may have different number of points,
136 // During remove animation series may have different number of points,
137 // so ensure we don't go over the index. Animation handling itself ensures that
137 // so ensure we don't go over the index. Animation handling itself ensures that
138 // if there is actually no points in the series, then it won't generate a fake point,
138 // if there is actually no points in the series, then it won't generate a fake point,
139 // so we can be assured there is always at least one point in m_series here.
139 // so we can be assured there is always at least one point in m_series here.
140 // Note that marker map values can be technically incorrect during the animation,
140 // Note that marker map values can be technically incorrect during the animation,
141 // if it was caused by an insert, but this shouldn't be a problem as the points are
141 // if it was caused by an insert, but this shouldn't be a problem as the points are
142 // fake anyway. After remove animation stops, geometry is updated to correct one.
142 // fake anyway. After remove animation stops, geometry is updated to correct one.
143 m_markerMap[item] = m_series->at(qMin(seriesLastIndex, i));
143 m_markerMap[item] = m_series->at(qMin(seriesLastIndex, i));
144 item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2);
144 item->setPos(point.x() - rect.width() / 2, point.y() - rect.height() / 2);
145
145
146 if (!m_visible || offGridStatus.at(i))
146 if (!m_visible || offGridStatus.at(i))
147 item->setVisible(false);
147 item->setVisible(false);
148 else
148 else
149 item->setVisible(true);
149 item->setVisible(true);
150 }
150 }
151
151
152 prepareGeometryChange();
152 prepareGeometryChange();
153 m_rect = clipRect;
153 m_rect = clipRect;
154 }
154 }
155
155
156 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
156 void ScatterChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
157 {
157 {
158 Q_UNUSED(painter)
158 Q_UNUSED(painter)
159 Q_UNUSED(option)
159 Q_UNUSED(option)
160 Q_UNUSED(widget)
160 Q_UNUSED(widget)
161 }
161 }
162
162
163 void ScatterChartItem::setPen(const QPen &pen)
163 void ScatterChartItem::setPen(const QPen &pen)
164 {
164 {
165 foreach (QGraphicsItem *item , m_items.childItems())
165 foreach (QGraphicsItem *item , m_items.childItems())
166 static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen);
166 static_cast<QAbstractGraphicsShapeItem*>(item)->setPen(pen);
167 }
167 }
168
168
169 void ScatterChartItem::setBrush(const QBrush &brush)
169 void ScatterChartItem::setBrush(const QBrush &brush)
170 {
170 {
171 foreach (QGraphicsItem *item , m_items.childItems())
171 foreach (QGraphicsItem *item , m_items.childItems())
172 static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush);
172 static_cast<QAbstractGraphicsShapeItem*>(item)->setBrush(brush);
173 }
173 }
174
174
175 void ScatterChartItem::handleUpdated()
175 void ScatterChartItem::handleUpdated()
176 {
176 {
177 int count = m_items.childItems().count();
177 int count = m_items.childItems().count();
178
178
179 if (count == 0)
179 if (count == 0)
180 return;
180 return;
181
181
182 bool recreate = m_visible != m_series->isVisible()
182 bool recreate = m_visible != m_series->isVisible()
183 || m_size != m_series->markerSize()
183 || m_size != m_series->markerSize()
184 || m_shape != m_series->markerShape();
184 || m_shape != m_series->markerShape();
185
185
186 m_visible = m_series->isVisible();
186 m_visible = m_series->isVisible();
187 m_size = m_series->markerSize();
187 m_size = m_series->markerSize();
188 m_shape = m_series->markerShape();
188 m_shape = m_series->markerShape();
189 setOpacity(m_series->opacity());
189 setOpacity(m_series->opacity());
190
190
191 if (recreate) {
191 if (recreate) {
192 // TODO: optimize handleUpdate to recreate points only in case shape changed
193 deletePoints(count);
192 deletePoints(count);
194 createPoints(count);
193 createPoints(count);
195
194
196 // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points
195 // Updating geometry is now safe, because it won't call handleUpdated unless it creates/deletes points
197 updateGeometry();
196 updateGeometry();
198 }
197 }
199
198
200 setPen(m_series->pen());
199 setPen(m_series->pen());
201 setBrush(m_series->brush());
200 setBrush(m_series->brush());
202 update();
201 update();
203 }
202 }
204
203
205 #include "moc_scatterchartitem_p.cpp"
204 #include "moc_scatterchartitem_p.cpp"
206
205
207 QTCOMMERCIALCHART_END_NAMESPACE
206 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,191 +1,189
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 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 Enterprise Charts Add-on.
7 ** This file is part of the Qt Enterprise Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
10 ** Licensees holding valid Qt Enterprise licenses may use this file in
11 ** accordance with the Qt Enterprise License Agreement provided with the
11 ** accordance with the Qt Enterprise 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 "xychart_p.h"
21 #include "xychart_p.h"
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "chartpresenter_p.h"
24 #include "chartpresenter_p.h"
25 #include "abstractdomain_p.h"
25 #include "abstractdomain_p.h"
26 #include "qxymodelmapper.h"
26 #include "qxymodelmapper.h"
27 #include "qabstractaxis_p.h"
27 #include "qabstractaxis_p.h"
28 #include <QPainter>
28 #include <QPainter>
29 #include <QAbstractItemModel>
29 #include <QAbstractItemModel>
30
30
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 //TODO: optimize : remove points which are not visible
35
36 XYChart::XYChart(QXYSeries *series, QGraphicsItem *item):
34 XYChart::XYChart(QXYSeries *series, QGraphicsItem *item):
37 ChartItem(series->d_func(),item),
35 ChartItem(series->d_func(),item),
38 m_series(series),
36 m_series(series),
39 m_animation(0),
37 m_animation(0),
40 m_dirty(true)
38 m_dirty(true)
41 {
39 {
42 QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
40 QObject::connect(series, SIGNAL(pointReplaced(int)), this, SLOT(handlePointReplaced(int)));
43 QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
41 QObject::connect(series, SIGNAL(pointsReplaced()), this, SLOT(handlePointsReplaced()));
44 QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
42 QObject::connect(series, SIGNAL(pointAdded(int)), this, SLOT(handlePointAdded(int)));
45 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
43 QObject::connect(series, SIGNAL(pointRemoved(int)), this, SLOT(handlePointRemoved(int)));
46 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
44 QObject::connect(this, SIGNAL(clicked(QPointF)), series, SIGNAL(clicked(QPointF)));
47 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool)));
45 QObject::connect(this, SIGNAL(hovered(QPointF,bool)), series, SIGNAL(hovered(QPointF,bool)));
48 }
46 }
49
47
50 void XYChart::setGeometryPoints(const QVector<QPointF> &points)
48 void XYChart::setGeometryPoints(const QVector<QPointF> &points)
51 {
49 {
52 m_points = points;
50 m_points = points;
53 }
51 }
54
52
55 void XYChart::setAnimation(XYAnimation *animation)
53 void XYChart::setAnimation(XYAnimation *animation)
56 {
54 {
57 m_animation = animation;
55 m_animation = animation;
58 }
56 }
59
57
60 void XYChart::setDirty(bool dirty)
58 void XYChart::setDirty(bool dirty)
61 {
59 {
62 m_dirty = dirty;
60 m_dirty = dirty;
63 }
61 }
64
62
65 // Returns a vector with same size as geometryPoints vector, indicating
63 // Returns a vector with same size as geometryPoints vector, indicating
66 // the off grid status of points.
64 // the off grid status of points.
67 QVector<bool> XYChart::offGridStatusVector()
65 QVector<bool> XYChart::offGridStatusVector()
68 {
66 {
69 qreal minX = domain()->minX();
67 qreal minX = domain()->minX();
70 qreal maxX = domain()->maxX();
68 qreal maxX = domain()->maxX();
71 qreal minY = domain()->minY();
69 qreal minY = domain()->minY();
72 qreal maxY = domain()->maxY();
70 qreal maxY = domain()->maxY();
73
71
74 QVector<bool> returnVector;
72 QVector<bool> returnVector;
75 returnVector.resize(m_points.size());
73 returnVector.resize(m_points.size());
76 // During remove animation series may have different number of points,
74 // During remove animation series may have different number of points,
77 // so ensure we don't go over the index. No need to check for zero points, this
75 // so ensure we don't go over the index. No need to check for zero points, this
78 // will not be called in such a situation.
76 // will not be called in such a situation.
79 const int seriesLastIndex = m_series->count() - 1;
77 const int seriesLastIndex = m_series->count() - 1;
80
78
81 for (int i = 0; i < m_points.size(); i++) {
79 for (int i = 0; i < m_points.size(); i++) {
82 const QPointF &seriesPoint = m_series->at(qMin(seriesLastIndex, i));
80 const QPointF &seriesPoint = m_series->at(qMin(seriesLastIndex, i));
83 if (seriesPoint.x() < minX
81 if (seriesPoint.x() < minX
84 || seriesPoint.x() > maxX
82 || seriesPoint.x() > maxX
85 || seriesPoint.y() < minY
83 || seriesPoint.y() < minY
86 || seriesPoint.y() > maxY) {
84 || seriesPoint.y() > maxY) {
87 returnVector[i] = true;
85 returnVector[i] = true;
88 } else {
86 } else {
89 returnVector[i] = false;
87 returnVector[i] = false;
90 }
88 }
91 }
89 }
92 return returnVector;
90 return returnVector;
93 }
91 }
94
92
95 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
93 void XYChart::updateChart(QVector<QPointF> &oldPoints, QVector<QPointF> &newPoints, int index)
96 {
94 {
97
95
98 if (m_animation) {
96 if (m_animation) {
99 m_animation->setup(oldPoints, newPoints, index);
97 m_animation->setup(oldPoints, newPoints, index);
100 m_points = newPoints;
98 m_points = newPoints;
101 setDirty(false);
99 setDirty(false);
102 presenter()->startAnimation(m_animation);
100 presenter()->startAnimation(m_animation);
103 } else {
101 } else {
104 m_points = newPoints;
102 m_points = newPoints;
105 updateGeometry();
103 updateGeometry();
106 }
104 }
107 }
105 }
108
106
109 //handlers
107 //handlers
110
108
111 void XYChart::handlePointAdded(int index)
109 void XYChart::handlePointAdded(int index)
112 {
110 {
113 Q_ASSERT(index < m_series->count());
111 Q_ASSERT(index < m_series->count());
114 Q_ASSERT(index >= 0);
112 Q_ASSERT(index >= 0);
115
113
116 QVector<QPointF> points;
114 QVector<QPointF> points;
117
115
118 if (m_dirty || m_points.isEmpty()) {
116 if (m_dirty || m_points.isEmpty()) {
119 points = domain()->calculateGeometryPoints(m_series->points());
117 points = domain()->calculateGeometryPoints(m_series->points());
120 } else {
118 } else {
121 points = m_points;
119 points = m_points;
122 QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData);
120 QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData);
123 if (!m_validData)
121 if (!m_validData)
124 m_points.clear();
122 m_points.clear();
125 else
123 else
126 points.insert(index, point);
124 points.insert(index, point);
127 }
125 }
128
126
129 updateChart(m_points, points, index);
127 updateChart(m_points, points, index);
130 }
128 }
131
129
132 void XYChart::handlePointRemoved(int index)
130 void XYChart::handlePointRemoved(int index)
133 {
131 {
134 Q_ASSERT(index <= m_series->count());
132 Q_ASSERT(index <= m_series->count());
135 Q_ASSERT(index >= 0);
133 Q_ASSERT(index >= 0);
136
134
137 QVector<QPointF> points;
135 QVector<QPointF> points;
138
136
139 if (m_dirty || m_points.isEmpty()) {
137 if (m_dirty || m_points.isEmpty()) {
140 points = domain()->calculateGeometryPoints(m_series->points());
138 points = domain()->calculateGeometryPoints(m_series->points());
141 } else {
139 } else {
142 points = m_points;
140 points = m_points;
143 points.remove(index);
141 points.remove(index);
144 }
142 }
145
143
146 updateChart(m_points, points, index);
144 updateChart(m_points, points, index);
147 }
145 }
148
146
149 void XYChart::handlePointReplaced(int index)
147 void XYChart::handlePointReplaced(int index)
150 {
148 {
151 Q_ASSERT(index < m_series->count());
149 Q_ASSERT(index < m_series->count());
152 Q_ASSERT(index >= 0);
150 Q_ASSERT(index >= 0);
153
151
154 QVector<QPointF> points;
152 QVector<QPointF> points;
155
153
156 if (m_dirty || m_points.isEmpty()) {
154 if (m_dirty || m_points.isEmpty()) {
157 points = domain()->calculateGeometryPoints(m_series->points());
155 points = domain()->calculateGeometryPoints(m_series->points());
158 } else {
156 } else {
159 QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData);
157 QPointF point = domain()->calculateGeometryPoint(m_series->points()[index], m_validData);
160 if (!m_validData)
158 if (!m_validData)
161 m_points.clear();
159 m_points.clear();
162 points = m_points;
160 points = m_points;
163 if (m_validData)
161 if (m_validData)
164 points.replace(index, point);
162 points.replace(index, point);
165 }
163 }
166
164
167 updateChart(m_points, points, index);
165 updateChart(m_points, points, index);
168 }
166 }
169
167
170 void XYChart::handlePointsReplaced()
168 void XYChart::handlePointsReplaced()
171 {
169 {
172 // All the points were replaced -> recalculate
170 // All the points were replaced -> recalculate
173 QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points());
171 QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points());
174 updateChart(m_points, points, -1);
172 updateChart(m_points, points, -1);
175 }
173 }
176
174
177 void XYChart::handleDomainUpdated()
175 void XYChart::handleDomainUpdated()
178 {
176 {
179 if (isEmpty()) return;
177 if (isEmpty()) return;
180 QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points());
178 QVector<QPointF> points = domain()->calculateGeometryPoints(m_series->points());
181 updateChart(m_points, points);
179 updateChart(m_points, points);
182 }
180 }
183
181
184 bool XYChart::isEmpty()
182 bool XYChart::isEmpty()
185 {
183 {
186 return domain()->isEmpty() || m_series->points().isEmpty();
184 return domain()->isEmpty() || m_series->points().isEmpty();
187 }
185 }
188
186
189 #include "moc_xychart_p.cpp"
187 #include "moc_xychart_p.cpp"
190
188
191 QTCOMMERCIALCHART_END_NAMESPACE
189 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now