@@ -1,452 +1,452 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qareaseries.h" |
|
21 | #include "qareaseries.h" | |
22 | #include "qareaseries_p.h" |
|
22 | #include "qareaseries_p.h" | |
23 | #include "qlineseries.h" |
|
23 | #include "qlineseries.h" | |
24 | #include "areachartitem_p.h" |
|
24 | #include "areachartitem_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
29 | #include "qarealegendmarker.h" |
|
29 | #include "qarealegendmarker.h" | |
30 | #include "qchart_p.h" |
|
30 | #include "qchart_p.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAreaSeries |
|
35 | \class QAreaSeries | |
36 | \brief The QAreaSeries class is used for making area charts. |
|
36 | \brief The QAreaSeries class is used for making area charts. | |
37 |
|
37 | |||
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line |
|
40 | An area chart is used to show quantitative data. It is based on line chart, in the way that area between axis and the line | |
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, |
|
41 | is emphasized with color. Since the area chart is based on line chart, QAreaSeries constructor needs QLineSeries instance, | |
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. |
|
42 | which defines "upper" boundary of the area. "Lower" boundary is defined by default by axis X. Instead of axis X "lower" boundary can be specified by other line. | |
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases |
|
43 | In that case QAreaSeries should be initiated with two QLineSeries instances. Please note terms "upper" and "lower" boundary can be misleading in cases | |
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. |
|
44 | where "lower" boundary had bigger values than the "upper" one, however the main point that area between these two boundary lines will be filled. | |
45 |
|
45 | |||
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. |
|
46 | See the \l {AreaChart Example} {area chart example} to learn how to create a simple area chart. | |
47 | \image examples_areachart.png |
|
47 | \image examples_areachart.png | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AreaSeries QAreaSeries |
|
50 | \qmlclass AreaSeries QAreaSeries | |
51 |
|
51 | |||
52 | The following QML shows how to create a simple area chart: |
|
52 | The following QML shows how to create a simple area chart: | |
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 |
|
53 | \snippet ../demos/qmlchart/qml/qmlchart/View4.qml 1 | |
54 | \beginfloatleft |
|
54 | \beginfloatleft | |
55 | \image demos_qmlchart4.png |
|
55 | \image demos_qmlchart4.png | |
56 | \endfloat |
|
56 | \endfloat | |
57 | \clearfloat |
|
57 | \clearfloat | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QAreaSeries::upperSeries |
|
61 | \property QAreaSeries::upperSeries | |
62 | \brief The upper one of the two line series used to define area series boundaries. |
|
62 | \brief The upper one of the two line series used to define area series boundaries. | |
63 | */ |
|
63 | */ | |
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty LineSeries AreaSeries::upperSeries |
|
65 | \qmlproperty LineSeries AreaSeries::upperSeries | |
66 | The upper one of the two line series used to define area series boundaries. |
|
66 | The upper one of the two line series used to define area series boundaries. | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QAreaSeries::lowerSeries |
|
70 | \property QAreaSeries::lowerSeries | |
71 | The lower one of the two line series used to define are series boundaries. Note if |
|
71 | The lower one of the two line series used to define are series boundaries. Note if | |
72 |
QAreaSeries was co |
|
72 | QAreaSeries was constructed without a\ lowerSeries this is null. | |
73 | */ |
|
73 | */ | |
74 | /*! |
|
74 | /*! | |
75 | \qmlproperty LineSeries AreaSeries::lowerSeries |
|
75 | \qmlproperty LineSeries AreaSeries::lowerSeries | |
76 | The lower one of the two line series used to define are series boundaries. Note if |
|
76 | The lower one of the two line series used to define are series boundaries. Note if | |
77 |
AreaSeries was co |
|
77 | AreaSeries was constructed without a\ lowerSeries this is null. | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QAreaSeries::color |
|
81 | \property QAreaSeries::color | |
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. |
|
82 | Fill (brush) color of the series. This is a convenience property for modifying the color of brush. | |
83 | \sa QAreaSeries::brush() |
|
83 | \sa QAreaSeries::brush() | |
84 | */ |
|
84 | */ | |
85 | /*! |
|
85 | /*! | |
86 | \qmlproperty color AreaSeries::color |
|
86 | \qmlproperty color AreaSeries::color | |
87 | Fill (brush) color of the series. |
|
87 | Fill (brush) color of the series. | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \property QAreaSeries::borderColor |
|
91 | \property QAreaSeries::borderColor | |
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. |
|
92 | Line (pen) color of the series. This is a convenience property for modifying the color of pen. | |
93 | \sa QAreaSeries::pen() |
|
93 | \sa QAreaSeries::pen() | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlproperty color AreaSeries::borderColor |
|
96 | \qmlproperty color AreaSeries::borderColor | |
97 | Line (pen) color of the series. |
|
97 | Line (pen) color of the series. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \qmlproperty real AreaSeries::borderWidth |
|
101 | \qmlproperty real AreaSeries::borderWidth | |
102 | The width of the border line. By default the width is 2.0. |
|
102 | The width of the border line. By default the width is 2.0. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \fn QPen QAreaSeries::pen() const |
|
106 | \fn QPen QAreaSeries::pen() const | |
107 | \brief Returns the pen used to draw line for this series. |
|
107 | \brief Returns the pen used to draw line for this series. | |
108 | \sa setPen() |
|
108 | \sa setPen() | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | \fn QPen QAreaSeries::brush() const |
|
112 | \fn QPen QAreaSeries::brush() const | |
113 | \brief Returns the brush used to draw line for this series. |
|
113 | \brief Returns the brush used to draw line for this series. | |
114 | \sa setBrush() |
|
114 | \sa setBrush() | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QAreaSeries::colorChanged(QColor color) |
|
118 | \fn void QAreaSeries::colorChanged(QColor color) | |
119 | \brief Signal is emitted when the fill (brush) color has changed to \a color. |
|
119 | \brief Signal is emitted when the fill (brush) color has changed to \a color. | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlsignal AreaSeries::onColorChanged(color color) |
|
122 | \qmlsignal AreaSeries::onColorChanged(color color) | |
123 | Signal is emitted when the fill (brush) color has changed to \a color. |
|
123 | Signal is emitted when the fill (brush) color has changed to \a color. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QAreaSeries::borderColorChanged(QColor color) |
|
127 | \fn void QAreaSeries::borderColorChanged(QColor color) | |
128 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
128 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
129 | */ |
|
129 | */ | |
130 | /*! |
|
130 | /*! | |
131 | \qmlsignal AreaSeries::onBorderColorChanged(color color) |
|
131 | \qmlsignal AreaSeries::onBorderColorChanged(color color) | |
132 | Signal is emitted when the line (pen) color has changed to \a color. |
|
132 | Signal is emitted when the line (pen) color has changed to \a color. | |
133 | */ |
|
133 | */ | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | \fn void QAreaSeries::clicked(const QPointF& point) |
|
136 | \fn void QAreaSeries::clicked(const QPointF& point) | |
137 | \brief Signal is emitted when user clicks the \a point on area chart. |
|
137 | \brief Signal is emitted when user clicks the \a point on area chart. | |
138 | */ |
|
138 | */ | |
139 | /*! |
|
139 | /*! | |
140 | \qmlsignal AreaSeries::onClicked(QPointF point) |
|
140 | \qmlsignal AreaSeries::onClicked(QPointF point) | |
141 | Signal is emitted when user clicks the \a point on area chart. |
|
141 | Signal is emitted when user clicks the \a point on area chart. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QAreaSeries::hovered(const QPointF &point, bool state) |
|
145 | \fn void QAreaSeries::hovered(const QPointF &point, bool state) | |
146 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
146 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
147 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
147 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
148 | the series. |
|
148 | the series. | |
149 | */ |
|
149 | */ | |
150 | /*! |
|
150 | /*! | |
151 | \qmlsignal AreaSeries::onHovered(point point, bool state) |
|
151 | \qmlsignal AreaSeries::onHovered(point point, bool state) | |
152 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
152 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
153 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
153 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
154 | the series. |
|
154 | the series. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \fn void QAreaSeries::selected() |
|
158 | \fn void QAreaSeries::selected() | |
159 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
159 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
160 | implemented by the user of QAreaSeries API. |
|
160 | implemented by the user of QAreaSeries API. | |
161 | */ |
|
161 | */ | |
162 | /*! |
|
162 | /*! | |
163 | \qmlsignal AreaSeries::onSelected() |
|
163 | \qmlsignal AreaSeries::onSelected() | |
164 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be |
|
164 | The signal is emitted if the user selects/deselects the XY series. The logic for maintaining selections should be | |
165 | implemented by the user of AreaSeries API. |
|
165 | implemented by the user of AreaSeries API. | |
166 | */ |
|
166 | */ | |
167 |
|
167 | |||
168 | /*! |
|
168 | /*! | |
169 | \fn void QAreaSeriesPrivate::updated() |
|
169 | \fn void QAreaSeriesPrivate::updated() | |
170 | \brief \internal |
|
170 | \brief \internal | |
171 | */ |
|
171 | */ | |
172 |
|
172 | |||
173 | /*! |
|
173 | /*! | |
174 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a |
|
174 | Constructs area series object which is a child of \a upperSeries. Area will be spanned between \a | |
175 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. |
|
175 | upperSeries line and \a lowerSeries line. If no \a lowerSeries is passed to constructor, area is specified by axis x (y=0) instead. | |
176 | When series object is added to QChartView or QChart instance ownerships is transferred. |
|
176 | When series object is added to QChartView or QChart instance ownerships is transferred. | |
177 | */ |
|
177 | */ | |
178 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) |
|
178 | QAreaSeries::QAreaSeries(QLineSeries *upperSeries, QLineSeries *lowerSeries) | |
179 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) |
|
179 | : QAbstractSeries(*new QAreaSeriesPrivate(upperSeries, lowerSeries, this), upperSeries) | |
180 | { |
|
180 | { | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 | /*! |
|
183 | /*! | |
184 | Constructs area series object without upper or lower series with \a parent object. |
|
184 | Constructs area series object without upper or lower series with \a parent object. | |
185 | */ |
|
185 | */ | |
186 | QAreaSeries::QAreaSeries(QObject *parent) |
|
186 | QAreaSeries::QAreaSeries(QObject *parent) | |
187 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) |
|
187 | : QAbstractSeries(*new QAreaSeriesPrivate(0, 0, this), parent) | |
188 | { |
|
188 | { | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | /*! |
|
191 | /*! | |
192 | Destroys the object. |
|
192 | Destroys the object. | |
193 | */ |
|
193 | */ | |
194 | QAreaSeries::~QAreaSeries() |
|
194 | QAreaSeries::~QAreaSeries() | |
195 | { |
|
195 | { | |
196 | Q_D(QAreaSeries); |
|
196 | Q_D(QAreaSeries); | |
197 | if (d->m_chart) |
|
197 | if (d->m_chart) | |
198 | d->m_chart->removeSeries(this); |
|
198 | d->m_chart->removeSeries(this); | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | Returns QChartSeries::SeriesTypeArea. |
|
202 | Returns QChartSeries::SeriesTypeArea. | |
203 | */ |
|
203 | */ | |
204 | QAbstractSeries::SeriesType QAreaSeries::type() const |
|
204 | QAbstractSeries::SeriesType QAreaSeries::type() const | |
205 | { |
|
205 | { | |
206 | return QAbstractSeries::SeriesTypeArea; |
|
206 | return QAbstractSeries::SeriesTypeArea; | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Sets the \a series that is to be used as the area chart upper series. |
|
210 | Sets the \a series that is to be used as the area chart upper series. | |
211 | */ |
|
211 | */ | |
212 | void QAreaSeries::setUpperSeries(QLineSeries *series) |
|
212 | void QAreaSeries::setUpperSeries(QLineSeries *series) | |
213 | { |
|
213 | { | |
214 | Q_D(QAreaSeries); |
|
214 | Q_D(QAreaSeries); | |
215 | if (d->m_upperSeries != series) |
|
215 | if (d->m_upperSeries != series) | |
216 | d->m_upperSeries = series; |
|
216 | d->m_upperSeries = series; | |
217 | } |
|
217 | } | |
218 |
|
218 | |||
219 | QLineSeries *QAreaSeries::upperSeries() const |
|
219 | QLineSeries *QAreaSeries::upperSeries() const | |
220 | { |
|
220 | { | |
221 | Q_D(const QAreaSeries); |
|
221 | Q_D(const QAreaSeries); | |
222 | return d->m_upperSeries; |
|
222 | return d->m_upperSeries; | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | Sets the \a series that is to be used as the area chart lower series. |
|
226 | Sets the \a series that is to be used as the area chart lower series. | |
227 | */ |
|
227 | */ | |
228 | void QAreaSeries::setLowerSeries(QLineSeries *series) |
|
228 | void QAreaSeries::setLowerSeries(QLineSeries *series) | |
229 | { |
|
229 | { | |
230 | Q_D(QAreaSeries); |
|
230 | Q_D(QAreaSeries); | |
231 | d->m_lowerSeries = series; |
|
231 | d->m_lowerSeries = series; | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | QLineSeries *QAreaSeries::lowerSeries() const |
|
234 | QLineSeries *QAreaSeries::lowerSeries() const | |
235 | { |
|
235 | { | |
236 | Q_D(const QAreaSeries); |
|
236 | Q_D(const QAreaSeries); | |
237 | return d->m_lowerSeries; |
|
237 | return d->m_lowerSeries; | |
238 | } |
|
238 | } | |
239 |
|
239 | |||
240 | /*! |
|
240 | /*! | |
241 | Sets \a pen used for drawing area outline. |
|
241 | Sets \a pen used for drawing area outline. | |
242 | */ |
|
242 | */ | |
243 | void QAreaSeries::setPen(const QPen &pen) |
|
243 | void QAreaSeries::setPen(const QPen &pen) | |
244 | { |
|
244 | { | |
245 | Q_D(QAreaSeries); |
|
245 | Q_D(QAreaSeries); | |
246 | if (d->m_pen != pen) { |
|
246 | if (d->m_pen != pen) { | |
247 | d->m_pen = pen; |
|
247 | d->m_pen = pen; | |
248 | emit d->updated(); |
|
248 | emit d->updated(); | |
249 | } |
|
249 | } | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | QPen QAreaSeries::pen() const |
|
252 | QPen QAreaSeries::pen() const | |
253 | { |
|
253 | { | |
254 | Q_D(const QAreaSeries); |
|
254 | Q_D(const QAreaSeries); | |
255 | return d->m_pen; |
|
255 | return d->m_pen; | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | /*! |
|
258 | /*! | |
259 | Sets \a brush used for filling the area. |
|
259 | Sets \a brush used for filling the area. | |
260 | */ |
|
260 | */ | |
261 | void QAreaSeries::setBrush(const QBrush &brush) |
|
261 | void QAreaSeries::setBrush(const QBrush &brush) | |
262 | { |
|
262 | { | |
263 | Q_D(QAreaSeries); |
|
263 | Q_D(QAreaSeries); | |
264 | if (d->m_brush != brush) { |
|
264 | if (d->m_brush != brush) { | |
265 | bool emitColorChanged = brush.color() != d->m_brush.color(); |
|
265 | bool emitColorChanged = brush.color() != d->m_brush.color(); | |
266 | d->m_brush = brush; |
|
266 | d->m_brush = brush; | |
267 | emit d->updated(); |
|
267 | emit d->updated(); | |
268 | if (emitColorChanged) |
|
268 | if (emitColorChanged) | |
269 | emit colorChanged(brush.color()); |
|
269 | emit colorChanged(brush.color()); | |
270 | } |
|
270 | } | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | QBrush QAreaSeries::brush() const |
|
273 | QBrush QAreaSeries::brush() const | |
274 | { |
|
274 | { | |
275 | Q_D(const QAreaSeries); |
|
275 | Q_D(const QAreaSeries); | |
276 | return d->m_brush; |
|
276 | return d->m_brush; | |
277 | } |
|
277 | } | |
278 |
|
278 | |||
279 | void QAreaSeries::setColor(const QColor &color) |
|
279 | void QAreaSeries::setColor(const QColor &color) | |
280 | { |
|
280 | { | |
281 | QBrush b = brush(); |
|
281 | QBrush b = brush(); | |
282 | if (b == QBrush()) |
|
282 | if (b == QBrush()) | |
283 | b.setStyle(Qt::SolidPattern); |
|
283 | b.setStyle(Qt::SolidPattern); | |
284 | b.setColor(color); |
|
284 | b.setColor(color); | |
285 | setBrush(b); |
|
285 | setBrush(b); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | QColor QAreaSeries::color() const |
|
288 | QColor QAreaSeries::color() const | |
289 | { |
|
289 | { | |
290 | return brush().color(); |
|
290 | return brush().color(); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void QAreaSeries::setBorderColor(const QColor &color) |
|
293 | void QAreaSeries::setBorderColor(const QColor &color) | |
294 | { |
|
294 | { | |
295 | QPen p = pen(); |
|
295 | QPen p = pen(); | |
296 | if (p.color() != color) { |
|
296 | if (p.color() != color) { | |
297 | p.setColor(color); |
|
297 | p.setColor(color); | |
298 | setPen(p); |
|
298 | setPen(p); | |
299 | emit borderColorChanged(color); |
|
299 | emit borderColorChanged(color); | |
300 | } |
|
300 | } | |
301 | } |
|
301 | } | |
302 |
|
302 | |||
303 | QColor QAreaSeries::borderColor() const |
|
303 | QColor QAreaSeries::borderColor() const | |
304 | { |
|
304 | { | |
305 | return pen().color(); |
|
305 | return pen().color(); | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | /*! |
|
308 | /*! | |
309 | Sets if data points are \a visible and should be drawn on line. |
|
309 | Sets if data points are \a visible and should be drawn on line. | |
310 | */ |
|
310 | */ | |
311 | void QAreaSeries::setPointsVisible(bool visible) |
|
311 | void QAreaSeries::setPointsVisible(bool visible) | |
312 | { |
|
312 | { | |
313 | Q_D(QAreaSeries); |
|
313 | Q_D(QAreaSeries); | |
314 | if (d->m_pointsVisible != visible) { |
|
314 | if (d->m_pointsVisible != visible) { | |
315 | d->m_pointsVisible = visible; |
|
315 | d->m_pointsVisible = visible; | |
316 | emit d->updated(); |
|
316 | emit d->updated(); | |
317 | } |
|
317 | } | |
318 | } |
|
318 | } | |
319 |
|
319 | |||
320 | /*! |
|
320 | /*! | |
321 | Returns if the points are drawn for this series. |
|
321 | Returns if the points are drawn for this series. | |
322 | \sa setPointsVisible() |
|
322 | \sa setPointsVisible() | |
323 | */ |
|
323 | */ | |
324 | bool QAreaSeries::pointsVisible() const |
|
324 | bool QAreaSeries::pointsVisible() const | |
325 | { |
|
325 | { | |
326 | Q_D(const QAreaSeries); |
|
326 | Q_D(const QAreaSeries); | |
327 | return d->m_pointsVisible; |
|
327 | return d->m_pointsVisible; | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
330 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
331 |
|
331 | |||
332 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) |
|
332 | QAreaSeriesPrivate::QAreaSeriesPrivate(QLineSeries *upperSeries, QLineSeries *lowerSeries, QAreaSeries *q) | |
333 | : QAbstractSeriesPrivate(q), |
|
333 | : QAbstractSeriesPrivate(q), | |
334 | m_upperSeries(upperSeries), |
|
334 | m_upperSeries(upperSeries), | |
335 | m_lowerSeries(lowerSeries), |
|
335 | m_lowerSeries(lowerSeries), | |
336 | m_pointsVisible(false) |
|
336 | m_pointsVisible(false) | |
337 | { |
|
337 | { | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | void QAreaSeriesPrivate::initializeDomain() |
|
340 | void QAreaSeriesPrivate::initializeDomain() | |
341 | { |
|
341 | { | |
342 | Q_Q(QAreaSeries); |
|
342 | Q_Q(QAreaSeries); | |
343 |
|
343 | |||
344 | qreal minX(domain()->minX()); |
|
344 | qreal minX(domain()->minX()); | |
345 | qreal minY(domain()->minY()); |
|
345 | qreal minY(domain()->minY()); | |
346 | qreal maxX(domain()->maxX()); |
|
346 | qreal maxX(domain()->maxX()); | |
347 | qreal maxY(domain()->maxY()); |
|
347 | qreal maxY(domain()->maxY()); | |
348 |
|
348 | |||
349 | QLineSeries *upperSeries = q->upperSeries(); |
|
349 | QLineSeries *upperSeries = q->upperSeries(); | |
350 | QLineSeries *lowerSeries = q->lowerSeries(); |
|
350 | QLineSeries *lowerSeries = q->lowerSeries(); | |
351 |
|
351 | |||
352 | const QList<QPointF>& points = upperSeries->points(); |
|
352 | const QList<QPointF>& points = upperSeries->points(); | |
353 |
|
353 | |||
354 | for (int i = 0; i < points.count(); i++) { |
|
354 | for (int i = 0; i < points.count(); i++) { | |
355 | qreal x = points[i].x(); |
|
355 | qreal x = points[i].x(); | |
356 | qreal y = points[i].y(); |
|
356 | qreal y = points[i].y(); | |
357 | minX = qMin(minX, x); |
|
357 | minX = qMin(minX, x); | |
358 | minY = qMin(minY, y); |
|
358 | minY = qMin(minY, y); | |
359 | maxX = qMax(maxX, x); |
|
359 | maxX = qMax(maxX, x); | |
360 | maxY = qMax(maxY, y); |
|
360 | maxY = qMax(maxY, y); | |
361 | } |
|
361 | } | |
362 | if (lowerSeries) { |
|
362 | if (lowerSeries) { | |
363 |
|
363 | |||
364 | const QList<QPointF>& points = lowerSeries->points(); |
|
364 | const QList<QPointF>& points = lowerSeries->points(); | |
365 |
|
365 | |||
366 | for (int i = 0; i < points.count(); i++) { |
|
366 | for (int i = 0; i < points.count(); i++) { | |
367 | qreal x = points[i].x(); |
|
367 | qreal x = points[i].x(); | |
368 | qreal y = points[i].y(); |
|
368 | qreal y = points[i].y(); | |
369 | minX = qMin(minX, x); |
|
369 | minX = qMin(minX, x); | |
370 | minY = qMin(minY, y); |
|
370 | minY = qMin(minY, y); | |
371 | maxX = qMax(maxX, x); |
|
371 | maxX = qMax(maxX, x); | |
372 | maxY = qMax(maxY, y); |
|
372 | maxY = qMax(maxY, y); | |
373 | } |
|
373 | } | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | domain()->setRange(minX, maxX, minY, maxY); |
|
376 | domain()->setRange(minX, maxX, minY, maxY); | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
379 | void QAreaSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
380 | { |
|
380 | { | |
381 | Q_Q(QAreaSeries); |
|
381 | Q_Q(QAreaSeries); | |
382 | AreaChartItem *area = new AreaChartItem(q,parent); |
|
382 | AreaChartItem *area = new AreaChartItem(q,parent); | |
383 | m_item.reset(area); |
|
383 | m_item.reset(area); | |
384 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
384 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
385 | } |
|
385 | } | |
386 | void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
386 | void QAreaSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |
387 | { |
|
387 | { | |
388 | Q_Q(QAreaSeries); |
|
388 | Q_Q(QAreaSeries); | |
389 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); |
|
389 | AreaChartItem *area = static_cast<AreaChartItem *>(m_item.data()); | |
390 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
390 | if (options.testFlag(QChart::SeriesAnimations)) { | |
391 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); |
|
391 | area->upperLineItem()->setAnimation(new XYAnimation(area->upperLineItem())); | |
392 | if (q->lowerSeries()) |
|
392 | if (q->lowerSeries()) | |
393 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); |
|
393 | area->lowerLineItem()->setAnimation(new XYAnimation(area->lowerLineItem())); | |
394 | }else{ |
|
394 | }else{ | |
395 | area->upperLineItem()->setAnimation(0); |
|
395 | area->upperLineItem()->setAnimation(0); | |
396 | if (q->lowerSeries()) |
|
396 | if (q->lowerSeries()) | |
397 | area->lowerLineItem()->setAnimation(0); |
|
397 | area->lowerLineItem()->setAnimation(0); | |
398 | } |
|
398 | } | |
399 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
399 | QAbstractSeriesPrivate::initializeAnimations(options); | |
400 | } |
|
400 | } | |
401 |
|
401 | |||
402 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
402 | QList<QLegendMarker*> QAreaSeriesPrivate::createLegendMarkers(QLegend* legend) | |
403 | { |
|
403 | { | |
404 | Q_Q(QAreaSeries); |
|
404 | Q_Q(QAreaSeries); | |
405 | QList<QLegendMarker*> list; |
|
405 | QList<QLegendMarker*> list; | |
406 | return list << new QAreaLegendMarker(q,legend); |
|
406 | return list << new QAreaLegendMarker(q,legend); | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 |
|
409 | |||
410 | void QAreaSeriesPrivate::initializeAxes() |
|
410 | void QAreaSeriesPrivate::initializeAxes() | |
411 | { |
|
411 | { | |
412 |
|
412 | |||
413 | } |
|
413 | } | |
414 |
|
414 | |||
415 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
415 | QAbstractAxis::AxisType QAreaSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
416 | { |
|
416 | { | |
417 | Q_UNUSED(orientation); |
|
417 | Q_UNUSED(orientation); | |
418 | return QAbstractAxis::AxisTypeValue; |
|
418 | return QAbstractAxis::AxisTypeValue; | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
421 | QAbstractAxis* QAreaSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
422 | { |
|
422 | { | |
423 | Q_UNUSED(orientation); |
|
423 | Q_UNUSED(orientation); | |
424 | return 0; |
|
424 | return 0; | |
425 | } |
|
425 | } | |
426 |
|
426 | |||
427 | void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
427 | void QAreaSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
428 | { |
|
428 | { | |
429 | Q_Q(QAreaSeries); |
|
429 | Q_Q(QAreaSeries); | |
430 | QPen pen; |
|
430 | QPen pen; | |
431 | QBrush brush; |
|
431 | QBrush brush; | |
432 |
|
432 | |||
433 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
433 | const QList<QGradient> gradients = theme->seriesGradients(); | |
434 | const QList<QColor> colors = theme->seriesColors(); |
|
434 | const QList<QColor> colors = theme->seriesColors(); | |
435 |
|
435 | |||
436 | if (forced || pen == m_pen) { |
|
436 | if (forced || pen == m_pen) { | |
437 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); |
|
437 | pen.setColor(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0)); | |
438 | pen.setWidthF(2); |
|
438 | pen.setWidthF(2); | |
439 | q->setPen(pen); |
|
439 | q->setPen(pen); | |
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | if (forced || brush == m_brush) { |
|
442 | if (forced || brush == m_brush) { | |
443 | QBrush brush(colors.at(index % colors.size())); |
|
443 | QBrush brush(colors.at(index % colors.size())); | |
444 | q->setBrush(brush); |
|
444 | q->setBrush(brush); | |
445 | } |
|
445 | } | |
446 | } |
|
446 | } | |
447 |
|
447 | |||
448 |
|
448 | |||
449 | #include "moc_qareaseries.cpp" |
|
449 | #include "moc_qareaseries.cpp" | |
450 | #include "moc_qareaseries_p.cpp" |
|
450 | #include "moc_qareaseries_p.cpp" | |
451 |
|
451 | |||
452 | QTCOMMERCIALCHART_END_NAMESPACE |
|
452 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,598 +1,598 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarcategoryaxis.h" |
|
21 | #include "qbarcategoryaxis.h" | |
22 | #include "qbarcategoryaxis_p.h" |
|
22 | #include "qbarcategoryaxis_p.h" | |
23 | #include "chartbarcategoryaxisx_p.h" |
|
23 | #include "chartbarcategoryaxisx_p.h" | |
24 | #include "chartbarcategoryaxisy_p.h" |
|
24 | #include "chartbarcategoryaxisy_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "qchart.h" |
|
26 | #include "qchart.h" | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 | /*! |
|
30 | /*! | |
31 | \class QBarCategoryAxis |
|
31 | \class QBarCategoryAxis | |
32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. |
|
32 | \brief The QBarCategoryAxis class is used for manipulating chart's axis. | |
33 | \mainclass |
|
33 | \mainclass | |
34 |
|
34 | |||
35 | BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | BarCategoryAxis can be setup to show axis line with tick marks, grid lines and shades. | |
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
36 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. |
|
37 | See the \l {Line and BarChart Example} {Line and BarChart Example} to learn how to do that. | |
38 |
|
38 | |||
39 | Example code on how to use QBarCategoryAxis. |
|
39 | Example code on how to use QBarCategoryAxis. | |
40 | \code |
|
40 | \code | |
41 | QChartView *chartView = new QChartView; |
|
41 | QChartView *chartView = new QChartView; | |
42 | QBarSeries *series = new QBarSeries; |
|
42 | QBarSeries *series = new QBarSeries; | |
43 | // ... |
|
43 | // ... | |
44 | chartView->chart()->addSeries(series); |
|
44 | chartView->chart()->addSeries(series); | |
45 | chartView->chart()->createDefaultAxes(); |
|
45 | chartView->chart()->createDefaultAxes(); | |
46 |
|
46 | |||
47 | QBarCategoryAxis *axisX = new QBarCategoryAxis; |
|
47 | QBarCategoryAxis *axisX = new QBarCategoryAxis; | |
48 | QStringList categories; |
|
48 | QStringList categories; | |
49 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; |
|
49 | categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun"; | |
50 | axisX->append(categories); |
|
50 | axisX->append(categories); | |
51 | axisX->setRange("Feb", "May"); |
|
51 | axisX->setRange("Feb", "May"); | |
52 | chartView->chart()->setAxisX(axisX, series); |
|
52 | chartView->chart()->setAxisX(axisX, series); | |
53 | \endcode |
|
53 | \endcode | |
54 | */ |
|
54 | */ | |
55 |
|
55 | |||
56 | /*! |
|
56 | /*! | |
57 | \qmlclass BarCategoryAxis QBarCategoryAxis |
|
57 | \qmlclass BarCategoryAxis QBarCategoryAxis | |
58 | \inherits AbstractAxis |
|
58 | \inherits AbstractAxis | |
59 | \brief The Axis element is used for manipulating chart's axes. |
|
59 | \brief The Axis element is used for manipulating chart's axes. | |
60 |
|
60 | |||
61 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
61 | Axis can be setup to show axis line with tick marks, grid lines and shades. | |
62 | Categories are drawn between ticks. Note that you can use this also with lineseries too. |
|
62 | Categories are drawn between ticks. Note that you can use this also with lineseries too. | |
63 |
|
63 | |||
64 | To access BarCategoryAxis you can use ChartView API. For example: |
|
64 | To access BarCategoryAxis you can use ChartView API. For example: | |
65 | \code |
|
65 | \code | |
66 | ChartView { |
|
66 | ChartView { | |
67 | BarCategoryAxis { |
|
67 | BarCategoryAxis { | |
68 | id: categoryAxis |
|
68 | id: categoryAxis | |
69 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] |
|
69 | categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ] | |
70 | } |
|
70 | } | |
71 | // Add a few series... |
|
71 | // Add a few series... | |
72 | } |
|
72 | } | |
73 | \endcode |
|
73 | \endcode | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QBarCategoryAxis::categories |
|
77 | \property QBarCategoryAxis::categories | |
78 | Defines the categories of axis |
|
78 | Defines the categories of axis | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty QStringList BarCategoryAxis::categories |
|
81 | \qmlproperty QStringList BarCategoryAxis::categories | |
82 | Defines the categories of axis |
|
82 | Defines the categories of axis | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarCategoryAxis::min |
|
86 | \property QBarCategoryAxis::min | |
87 | Defines the minimum value on the axis. |
|
87 | Defines the minimum value on the axis. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty string BarCategoryAxis::min |
|
90 | \qmlproperty string BarCategoryAxis::min | |
91 | Defines the minimum value on the axis. |
|
91 | Defines the minimum value on the axis. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarCategoryAxis::max |
|
95 | \property QBarCategoryAxis::max | |
96 | Defines the maximum value on the axis. |
|
96 | Defines the maximum value on the axis. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty string BarCategoryAxis::max |
|
99 | \qmlproperty string BarCategoryAxis::max | |
100 | Defines the maximum value on the axis. |
|
100 | Defines the maximum value on the axis. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QBarCategoryAxis::count |
|
104 | \property QBarCategoryAxis::count | |
105 | The count of categories. |
|
105 | The count of categories. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty int BarCategoryAxis::count |
|
108 | \qmlproperty int BarCategoryAxis::count | |
109 | The count of categories. |
|
109 | The count of categories. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QBarCategoryAxis::categoriesChanged() |
|
113 | \fn void QBarCategoryAxis::categoriesChanged() | |
114 | Axis emits signal when the categories of the axis have changed. |
|
114 | Axis emits signal when the categories of the axis have changed. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QBarCategoryAxis::minChanged(const QString &min) |
|
118 | \fn void QBarCategoryAxis::minChanged(const QString &min) | |
119 | Axis emits signal when \a min of axis has changed. |
|
119 | Axis emits signal when \a min of axis has changed. | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) |
|
122 | \qmlsignal BarCategoryAxis::onMinChanged(const QString &min) | |
123 | Axis emits signal when \a min of axis has changed. |
|
123 | Axis emits signal when \a min of axis has changed. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QBarCategoryAxis::maxChanged(const QString &max) |
|
127 | \fn void QBarCategoryAxis::maxChanged(const QString &max) | |
128 | Axis emits signal when \a max of axis has changed. |
|
128 | Axis emits signal when \a max of axis has changed. | |
129 | */ |
|
129 | */ | |
130 | /*! |
|
130 | /*! | |
131 | \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) |
|
131 | \qmlsignal BarCategoryAxis::onMaxChanged(const QString &max) | |
132 | Axis emits signal when \a max of axis has changed. |
|
132 | Axis emits signal when \a max of axis has changed. | |
133 | */ |
|
133 | */ | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | \fn void QBarCategoryAxis::countChanged() |
|
136 | \fn void QBarCategoryAxis::countChanged() | |
137 | Axis emits signal when the count of categories has changed. |
|
137 | Axis emits signal when the count of categories has changed. | |
138 | */ |
|
138 | */ | |
139 | /*! |
|
139 | /*! | |
140 | \qmlsignal BarCategoryAxis::onCountChanged() |
|
140 | \qmlsignal BarCategoryAxis::onCountChanged() | |
141 | Axis emits signal when the count of categories has changed. |
|
141 | Axis emits signal when the count of categories has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) |
|
145 | \fn void QBarCategoryAxis::rangeChanged(const QString &min, const QString &max) | |
146 | Axis emits signal when \a min or \a max of axis has changed. |
|
146 | Axis emits signal when \a min or \a max of axis has changed. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | Constructs an axis object which is a child of \a parent. |
|
150 | Constructs an axis object which is a child of \a parent. | |
151 | */ |
|
151 | */ | |
152 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): |
|
152 | QBarCategoryAxis::QBarCategoryAxis(QObject *parent): | |
153 | QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent) |
|
153 | QAbstractAxis(*new QBarCategoryAxisPrivate(this), parent) | |
154 | { |
|
154 | { | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | Destroys the object |
|
158 | Destroys the object | |
159 | */ |
|
159 | */ | |
160 | QBarCategoryAxis::~QBarCategoryAxis() |
|
160 | QBarCategoryAxis::~QBarCategoryAxis() | |
161 | { |
|
161 | { | |
162 | Q_D(QBarCategoryAxis); |
|
162 | Q_D(QBarCategoryAxis); | |
163 | if (d->m_chart) |
|
163 | if (d->m_chart) | |
164 | d->m_chart->removeAxis(this); |
|
164 | d->m_chart->removeAxis(this); | |
165 | } |
|
165 | } | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | \internal |
|
168 | \internal | |
169 | */ |
|
169 | */ | |
170 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) |
|
170 | QBarCategoryAxis::QBarCategoryAxis(QBarCategoryAxisPrivate &d, QObject *parent) | |
171 | : QAbstractAxis(d, parent) |
|
171 | : QAbstractAxis(d, parent) | |
172 | { |
|
172 | { | |
173 |
|
173 | |||
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories. |
|
177 | Appends \a categories to axis. A maximum of the axis will be changed to last category in \a categories. | |
178 | If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories. |
|
178 | If there were no categories previously defined, minimum of axis will be also changed to first category in \a categories. | |
179 | A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
179 | A category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. | |
180 | */ |
|
180 | */ | |
181 | void QBarCategoryAxis::append(const QStringList &categories) |
|
181 | void QBarCategoryAxis::append(const QStringList &categories) | |
182 | { |
|
182 | { | |
183 | if (categories.isEmpty()) |
|
183 | if (categories.isEmpty()) | |
184 | return; |
|
184 | return; | |
185 |
|
185 | |||
186 | Q_D(QBarCategoryAxis); |
|
186 | Q_D(QBarCategoryAxis); | |
187 |
|
187 | |||
188 | int count = d->m_categories.count(); |
|
188 | int count = d->m_categories.count(); | |
189 |
|
189 | |||
190 | foreach(QString category, categories) { |
|
190 | foreach(QString category, categories) { | |
191 | if (!d->m_categories.contains(category) && !category.isNull()) { |
|
191 | if (!d->m_categories.contains(category) && !category.isNull()) { | |
192 | d->m_categories.append(category); |
|
192 | d->m_categories.append(category); | |
193 | } |
|
193 | } | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | if (d->m_categories.count() == count) |
|
196 | if (d->m_categories.count() == count) | |
197 | return; |
|
197 | return; | |
198 |
|
198 | |||
199 | if (count == 0) |
|
199 | if (count == 0) | |
200 | setRange(d->m_categories.first(), d->m_categories.last()); |
|
200 | setRange(d->m_categories.first(), d->m_categories.last()); | |
201 | else |
|
201 | else | |
202 | setRange(d->m_minCategory, d->m_categories.last()); |
|
202 | setRange(d->m_minCategory, d->m_categories.last()); | |
203 |
|
203 | |||
204 | emit categoriesChanged(); |
|
204 | emit categoriesChanged(); | |
205 | emit countChanged(); |
|
205 | emit countChanged(); | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | /*! |
|
208 | /*! | |
209 | Appends \a category to axis. A maximum of the axis will be changed to last \a category. |
|
209 | Appends \a category to axis. A maximum of the axis will be changed to last \a category. | |
210 | If there were no categories previously defined, minimum of axis will be also changed to \a category. |
|
210 | If there were no categories previously defined, minimum of axis will be also changed to \a category. | |
211 | A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. |
|
211 | A \a category has to be valid QStrings and can not be duplicated. Duplicated categories will not be appended. | |
212 | */ |
|
212 | */ | |
213 | void QBarCategoryAxis::append(const QString &category) |
|
213 | void QBarCategoryAxis::append(const QString &category) | |
214 | { |
|
214 | { | |
215 | Q_D(QBarCategoryAxis); |
|
215 | Q_D(QBarCategoryAxis); | |
216 |
|
216 | |||
217 | int count = d->m_categories.count(); |
|
217 | int count = d->m_categories.count(); | |
218 |
|
218 | |||
219 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
219 | if (!d->m_categories.contains(category) && !category.isNull()) | |
220 | d->m_categories.append(category); |
|
220 | d->m_categories.append(category); | |
221 |
|
221 | |||
222 | if (d->m_categories.count() == count) |
|
222 | if (d->m_categories.count() == count) | |
223 | return; |
|
223 | return; | |
224 |
|
224 | |||
225 | if (count == 0) |
|
225 | if (count == 0) | |
226 | setRange(d->m_categories.last(), d->m_categories.last()); |
|
226 | setRange(d->m_categories.last(), d->m_categories.last()); | |
227 | else |
|
227 | else | |
228 | setRange(d->m_minCategory, d->m_categories.last()); |
|
228 | setRange(d->m_minCategory, d->m_categories.last()); | |
229 |
|
229 | |||
230 | emit categoriesChanged(); |
|
230 | emit categoriesChanged(); | |
231 | emit countChanged(); |
|
231 | emit countChanged(); | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | Removes \a category from axis. Removing category which is currently maximum or minimum |
|
235 | Removes \a category from axis. Removing category which is currently maximum or minimum | |
236 | will affect the axis range. |
|
236 | will affect the axis range. | |
237 | */ |
|
237 | */ | |
238 | void QBarCategoryAxis::remove(const QString &category) |
|
238 | void QBarCategoryAxis::remove(const QString &category) | |
239 | { |
|
239 | { | |
240 | Q_D(QBarCategoryAxis); |
|
240 | Q_D(QBarCategoryAxis); | |
241 |
|
241 | |||
242 | if (d->m_categories.contains(category)) { |
|
242 | if (d->m_categories.contains(category)) { | |
243 | d->m_categories.removeAt(d->m_categories.indexOf(category)); |
|
243 | d->m_categories.removeAt(d->m_categories.indexOf(category)); | |
244 | if (!d->m_categories.isEmpty()) { |
|
244 | if (!d->m_categories.isEmpty()) { | |
245 | if (d->m_minCategory == category) { |
|
245 | if (d->m_minCategory == category) { | |
246 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
246 | setRange(d->m_categories.first(), d->m_maxCategory); | |
247 | } else if (d->m_maxCategory == category) { |
|
247 | } else if (d->m_maxCategory == category) { | |
248 | setRange(d->m_minCategory, d->m_categories.last()); |
|
248 | setRange(d->m_minCategory, d->m_categories.last()); | |
249 | } else { |
|
249 | } else { | |
250 | d->updateCategoryDomain(); |
|
250 | d->updateCategoryDomain(); | |
251 | //TODO:: d->emitUpdated(); |
|
251 | //TODO:: d->emitUpdated(); | |
252 | } |
|
252 | } | |
253 | } else { |
|
253 | } else { | |
254 | setRange(QString::null, QString::null); |
|
254 | setRange(QString::null, QString::null); | |
255 | } |
|
255 | } | |
256 | emit categoriesChanged(); |
|
256 | emit categoriesChanged(); | |
257 | emit countChanged(); |
|
257 | emit countChanged(); | |
258 | } |
|
258 | } | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated. |
|
262 | Inserts \a category to axis at \a index. A \a category has to be valid QStrings and can not be duplicated. | |
263 | If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly. |
|
263 | If \a category is prepended or appended to categories, minimum and maximum of axis is updated accordingly. | |
264 | */ |
|
264 | */ | |
265 | void QBarCategoryAxis::insert(int index, const QString &category) |
|
265 | void QBarCategoryAxis::insert(int index, const QString &category) | |
266 | { |
|
266 | { | |
267 | Q_D(QBarCategoryAxis); |
|
267 | Q_D(QBarCategoryAxis); | |
268 |
|
268 | |||
269 | int count = d->m_categories.count(); |
|
269 | int count = d->m_categories.count(); | |
270 |
|
270 | |||
271 | if (!d->m_categories.contains(category) && !category.isNull()) |
|
271 | if (!d->m_categories.contains(category) && !category.isNull()) | |
272 | d->m_categories.insert(index, category); |
|
272 | d->m_categories.insert(index, category); | |
273 |
|
273 | |||
274 | if (d->m_categories.count() == count) |
|
274 | if (d->m_categories.count() == count) | |
275 | return; |
|
275 | return; | |
276 |
|
276 | |||
277 | if (count == 0) { |
|
277 | if (count == 0) { | |
278 | setRange(d->m_categories.first(), d->m_categories.first()); |
|
278 | setRange(d->m_categories.first(), d->m_categories.first()); | |
279 | } else if (index == 0) { |
|
279 | } else if (index == 0) { | |
280 | setRange(d->m_categories.first(), d->m_maxCategory); |
|
280 | setRange(d->m_categories.first(), d->m_maxCategory); | |
281 | } else if (index == count) { |
|
281 | } else if (index == count) { | |
282 | setRange(d->m_minCategory, d->m_categories.last()); |
|
282 | setRange(d->m_minCategory, d->m_categories.last()); | |
283 | } else { |
|
283 | } else { | |
284 | d->updateCategoryDomain(); |
|
284 | d->updateCategoryDomain(); | |
285 | //TODO:: d->emitUpdated(); |
|
285 | //TODO:: d->emitUpdated(); | |
286 | } |
|
286 | } | |
287 |
|
287 | |||
288 | emit categoriesChanged(); |
|
288 | emit categoriesChanged(); | |
289 | emit countChanged(); |
|
289 | emit countChanged(); | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 |
Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exi |
|
293 | Replaces \a oldCategory with \a newCategory. If \a oldCategory does not exist on the axis nothing is done. | |
294 | A \a newCategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category, |
|
294 | A \a newCategory has to be valid QStrings and can not be duplicated. In case of replacing minimum or maximum category, | |
295 | minimum and maximum of axis is updated accordingly. |
|
295 | minimum and maximum of axis is updated accordingly. | |
296 | */ |
|
296 | */ | |
297 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) |
|
297 | void QBarCategoryAxis::replace(const QString &oldCategory, const QString &newCategory) | |
298 | { |
|
298 | { | |
299 | Q_D(QBarCategoryAxis); |
|
299 | Q_D(QBarCategoryAxis); | |
300 |
|
300 | |||
301 | int pos = d->m_categories.indexOf(oldCategory); |
|
301 | int pos = d->m_categories.indexOf(oldCategory); | |
302 |
|
302 | |||
303 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { |
|
303 | if (pos != -1 && !d->m_categories.contains(newCategory) && !newCategory.isNull()) { | |
304 | d->m_categories.replace(pos, newCategory); |
|
304 | d->m_categories.replace(pos, newCategory); | |
305 | if (d->m_minCategory == oldCategory) { |
|
305 | if (d->m_minCategory == oldCategory) { | |
306 | setRange(newCategory, d->m_maxCategory); |
|
306 | setRange(newCategory, d->m_maxCategory); | |
307 | } else if (d->m_maxCategory == oldCategory) { |
|
307 | } else if (d->m_maxCategory == oldCategory) { | |
308 | setRange(d->m_minCategory, newCategory); |
|
308 | setRange(d->m_minCategory, newCategory); | |
309 | } else { |
|
309 | } else { | |
310 | //TODO:: d->emitUpdated(); |
|
310 | //TODO:: d->emitUpdated(); | |
311 | } |
|
311 | } | |
312 | emit categoriesChanged(); |
|
312 | emit categoriesChanged(); | |
313 | emit countChanged(); |
|
313 | emit countChanged(); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | /*! |
|
317 | /*! | |
318 | Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. |
|
318 | Removes all categories. Sets the maximum and minimum of the axis's range to QString::null. | |
319 | */ |
|
319 | */ | |
320 | void QBarCategoryAxis::clear() |
|
320 | void QBarCategoryAxis::clear() | |
321 | { |
|
321 | { | |
322 | Q_D(QBarCategoryAxis); |
|
322 | Q_D(QBarCategoryAxis); | |
323 | d->m_categories.clear(); |
|
323 | d->m_categories.clear(); | |
324 | setRange(QString::null, QString::null); |
|
324 | setRange(QString::null, QString::null); | |
325 | emit categoriesChanged(); |
|
325 | emit categoriesChanged(); | |
326 | emit countChanged(); |
|
326 | emit countChanged(); | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | /*! |
|
329 | /*! | |
330 | Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories. |
|
330 | Set \a categories and discards the old ones, range of axis is adjusted to match first and last category in \a categories. | |
331 | A category has to be valid QStrings and can not be duplicated. |
|
331 | A category has to be valid QStrings and can not be duplicated. | |
332 | */ |
|
332 | */ | |
333 | void QBarCategoryAxis::setCategories(const QStringList &categories) |
|
333 | void QBarCategoryAxis::setCategories(const QStringList &categories) | |
334 | { |
|
334 | { | |
335 | Q_D(QBarCategoryAxis); |
|
335 | Q_D(QBarCategoryAxis); | |
336 | d->m_categories.clear(); |
|
336 | d->m_categories.clear(); | |
337 | d->m_minCategory = QString::null; |
|
337 | d->m_minCategory = QString::null; | |
338 | d->m_maxCategory = QString::null; |
|
338 | d->m_maxCategory = QString::null; | |
339 | d->m_min = 0; |
|
339 | d->m_min = 0; | |
340 | d->m_max = 0; |
|
340 | d->m_max = 0; | |
341 | d->m_count = 0; |
|
341 | d->m_count = 0; | |
342 | append(categories); |
|
342 | append(categories); | |
343 | } |
|
343 | } | |
344 |
|
344 | |||
345 | /*! |
|
345 | /*! | |
346 | Returns categories |
|
346 | Returns categories | |
347 | */ |
|
347 | */ | |
348 | QStringList QBarCategoryAxis::categories() |
|
348 | QStringList QBarCategoryAxis::categories() | |
349 | { |
|
349 | { | |
350 | Q_D(QBarCategoryAxis); |
|
350 | Q_D(QBarCategoryAxis); | |
351 | return d->m_categories; |
|
351 | return d->m_categories; | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Returns number of categories. |
|
355 | Returns number of categories. | |
356 | */ |
|
356 | */ | |
357 | int QBarCategoryAxis::count() const |
|
357 | int QBarCategoryAxis::count() const | |
358 | { |
|
358 | { | |
359 | Q_D(const QBarCategoryAxis); |
|
359 | Q_D(const QBarCategoryAxis); | |
360 | return d->m_categories.count(); |
|
360 | return d->m_categories.count(); | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | /*! |
|
363 | /*! | |
364 | Returns category at \a index. Index must be valid. |
|
364 | Returns category at \a index. Index must be valid. | |
365 | */ |
|
365 | */ | |
366 | QString QBarCategoryAxis::at(int index) const |
|
366 | QString QBarCategoryAxis::at(int index) const | |
367 | { |
|
367 | { | |
368 | Q_D(const QBarCategoryAxis); |
|
368 | Q_D(const QBarCategoryAxis); | |
369 | return d->m_categories.at(index); |
|
369 | return d->m_categories.at(index); | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | /*! |
|
372 | /*! | |
373 | Sets minimum category to \a min. |
|
373 | Sets minimum category to \a min. | |
374 | */ |
|
374 | */ | |
375 | void QBarCategoryAxis::setMin(const QString &min) |
|
375 | void QBarCategoryAxis::setMin(const QString &min) | |
376 | { |
|
376 | { | |
377 | Q_D(QBarCategoryAxis); |
|
377 | Q_D(QBarCategoryAxis); | |
378 | d->setRange(min, d->m_maxCategory); |
|
378 | d->setRange(min, d->m_maxCategory); | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | /*! |
|
381 | /*! | |
382 | Returns minimum category. |
|
382 | Returns minimum category. | |
383 | */ |
|
383 | */ | |
384 | QString QBarCategoryAxis::min() const |
|
384 | QString QBarCategoryAxis::min() const | |
385 | { |
|
385 | { | |
386 | Q_D(const QBarCategoryAxis); |
|
386 | Q_D(const QBarCategoryAxis); | |
387 | return d->m_minCategory; |
|
387 | return d->m_minCategory; | |
388 | } |
|
388 | } | |
389 |
|
389 | |||
390 | /*! |
|
390 | /*! | |
391 | Sets maximum category to \a max. |
|
391 | Sets maximum category to \a max. | |
392 | */ |
|
392 | */ | |
393 | void QBarCategoryAxis::setMax(const QString &max) |
|
393 | void QBarCategoryAxis::setMax(const QString &max) | |
394 | { |
|
394 | { | |
395 | Q_D(QBarCategoryAxis); |
|
395 | Q_D(QBarCategoryAxis); | |
396 | d->setRange(d->m_minCategory, max); |
|
396 | d->setRange(d->m_minCategory, max); | |
397 | } |
|
397 | } | |
398 |
|
398 | |||
399 | /*! |
|
399 | /*! | |
400 | Returns maximum category |
|
400 | Returns maximum category | |
401 | */ |
|
401 | */ | |
402 | QString QBarCategoryAxis::max() const |
|
402 | QString QBarCategoryAxis::max() const | |
403 | { |
|
403 | { | |
404 | Q_D(const QBarCategoryAxis); |
|
404 | Q_D(const QBarCategoryAxis); | |
405 | return d->m_maxCategory; |
|
405 | return d->m_maxCategory; | |
406 | } |
|
406 | } | |
407 |
|
407 | |||
408 | /*! |
|
408 | /*! | |
409 | Sets range from \a minCategory to \a maxCategory |
|
409 | Sets range from \a minCategory to \a maxCategory | |
410 | */ |
|
410 | */ | |
411 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) |
|
411 | void QBarCategoryAxis::setRange(const QString &minCategory, const QString &maxCategory) | |
412 | { |
|
412 | { | |
413 | Q_D(QBarCategoryAxis); |
|
413 | Q_D(QBarCategoryAxis); | |
414 | d->setRange(minCategory,maxCategory); |
|
414 | d->setRange(minCategory,maxCategory); | |
415 | } |
|
415 | } | |
416 |
|
416 | |||
417 | /*! |
|
417 | /*! | |
418 | Returns the type of the axis |
|
418 | Returns the type of the axis | |
419 | */ |
|
419 | */ | |
420 | QAbstractAxis::AxisType QBarCategoryAxis::type() const |
|
420 | QAbstractAxis::AxisType QBarCategoryAxis::type() const | |
421 | { |
|
421 | { | |
422 | return AxisTypeBarCategory; |
|
422 | return AxisTypeBarCategory; | |
423 | } |
|
423 | } | |
424 |
|
424 | |||
425 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
425 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
426 |
|
426 | |||
427 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q) |
|
427 | QBarCategoryAxisPrivate::QBarCategoryAxisPrivate(QBarCategoryAxis *q) | |
428 | : QAbstractAxisPrivate(q), |
|
428 | : QAbstractAxisPrivate(q), | |
429 | m_min(0.0), |
|
429 | m_min(0.0), | |
430 | m_max(0.0), |
|
430 | m_max(0.0), | |
431 | m_count(0) |
|
431 | m_count(0) | |
432 | { |
|
432 | { | |
433 |
|
433 | |||
434 | } |
|
434 | } | |
435 |
|
435 | |||
436 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() |
|
436 | QBarCategoryAxisPrivate::~QBarCategoryAxisPrivate() | |
437 | { |
|
437 | { | |
438 |
|
438 | |||
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) |
|
441 | void QBarCategoryAxisPrivate::setMin(const QVariant &min) | |
442 | { |
|
442 | { | |
443 | setRange(min, m_maxCategory); |
|
443 | setRange(min, m_maxCategory); | |
444 | } |
|
444 | } | |
445 |
|
445 | |||
446 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) |
|
446 | void QBarCategoryAxisPrivate::setMax(const QVariant &max) | |
447 | { |
|
447 | { | |
448 | setRange(m_minCategory, max); |
|
448 | setRange(m_minCategory, max); | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
451 | void QBarCategoryAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
452 | { |
|
452 | { | |
453 | QString value1 = min.toString(); |
|
453 | QString value1 = min.toString(); | |
454 | QString value2 = max.toString(); |
|
454 | QString value2 = max.toString(); | |
455 | setRange(value1, value2); |
|
455 | setRange(value1, value2); | |
456 | } |
|
456 | } | |
457 |
|
457 | |||
458 | void QBarCategoryAxisPrivate::setRange(qreal min, qreal max) |
|
458 | void QBarCategoryAxisPrivate::setRange(qreal min, qreal max) | |
459 | { |
|
459 | { | |
460 | Q_Q(QBarCategoryAxis); |
|
460 | Q_Q(QBarCategoryAxis); | |
461 |
|
461 | |||
462 | bool categoryChanged = false; |
|
462 | bool categoryChanged = false; | |
463 | bool changed = false; |
|
463 | bool changed = false; | |
464 |
|
464 | |||
465 | if (min > max) |
|
465 | if (min > max) | |
466 | return; |
|
466 | return; | |
467 |
|
467 | |||
468 | if (!qFuzzyIsNull(m_min - min)) { |
|
468 | if (!qFuzzyIsNull(m_min - min)) { | |
469 | m_min = min; |
|
469 | m_min = min; | |
470 | changed = true; |
|
470 | changed = true; | |
471 |
|
471 | |||
472 | int imin = m_min + 0.5; |
|
472 | int imin = m_min + 0.5; | |
473 | if (imin >= 0 && imin < m_categories.count()) { |
|
473 | if (imin >= 0 && imin < m_categories.count()) { | |
474 | QString minCategory = m_categories.at(imin); |
|
474 | QString minCategory = m_categories.at(imin); | |
475 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { |
|
475 | if (m_minCategory != minCategory && !minCategory.isEmpty()) { | |
476 | m_minCategory = minCategory; |
|
476 | m_minCategory = minCategory; | |
477 | categoryChanged = true; |
|
477 | categoryChanged = true; | |
478 | emit q->minChanged(minCategory); |
|
478 | emit q->minChanged(minCategory); | |
479 | } |
|
479 | } | |
480 | } |
|
480 | } | |
481 |
|
481 | |||
482 | } |
|
482 | } | |
483 |
|
483 | |||
484 | if (!qFuzzyIsNull(m_max - max)) { |
|
484 | if (!qFuzzyIsNull(m_max - max)) { | |
485 | m_max = max; |
|
485 | m_max = max; | |
486 | changed = true; |
|
486 | changed = true; | |
487 |
|
487 | |||
488 | int imax = m_max - 0.5; |
|
488 | int imax = m_max - 0.5; | |
489 | if (imax >= 0 && imax < m_categories.count()) { |
|
489 | if (imax >= 0 && imax < m_categories.count()) { | |
490 | QString maxCategory = m_categories.at(imax); |
|
490 | QString maxCategory = m_categories.at(imax); | |
491 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { |
|
491 | if (m_maxCategory != maxCategory && !maxCategory.isEmpty()) { | |
492 | m_maxCategory = maxCategory; |
|
492 | m_maxCategory = maxCategory; | |
493 | categoryChanged = true; |
|
493 | categoryChanged = true; | |
494 | emit q->maxChanged(maxCategory); |
|
494 | emit q->maxChanged(maxCategory); | |
495 | } |
|
495 | } | |
496 | } |
|
496 | } | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | if (categoryChanged){ |
|
499 | if (categoryChanged){ | |
500 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
500 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
501 | } |
|
501 | } | |
502 |
|
502 | |||
503 | if (changed) { |
|
503 | if (changed) { | |
504 | emit rangeChanged(m_min,m_max); |
|
504 | emit rangeChanged(m_min,m_max); | |
505 | } |
|
505 | } | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QString &maxCategory) |
|
508 | void QBarCategoryAxisPrivate::setRange(const QString &minCategory, const QString &maxCategory) | |
509 | { |
|
509 | { | |
510 | Q_Q(QBarCategoryAxis); |
|
510 | Q_Q(QBarCategoryAxis); | |
511 | bool changed = false; |
|
511 | bool changed = false; | |
512 |
|
512 | |||
513 | //special case in case or clearing all categories |
|
513 | //special case in case or clearing all categories | |
514 | if (minCategory.isNull() && maxCategory.isNull()) { |
|
514 | if (minCategory.isNull() && maxCategory.isNull()) { | |
515 | m_minCategory = minCategory; |
|
515 | m_minCategory = minCategory; | |
516 | m_maxCategory = maxCategory; |
|
516 | m_maxCategory = maxCategory; | |
517 | m_min = 0; |
|
517 | m_min = 0; | |
518 | m_max = 0; |
|
518 | m_max = 0; | |
519 | m_count = 0; |
|
519 | m_count = 0; | |
520 | emit q->minChanged(minCategory); |
|
520 | emit q->minChanged(minCategory); | |
521 | emit q->maxChanged(maxCategory); |
|
521 | emit q->maxChanged(maxCategory); | |
522 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
522 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
523 | emit rangeChanged(m_min,m_max); |
|
523 | emit rangeChanged(m_min,m_max); | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 | if (m_categories.indexOf(maxCategory) < m_categories.indexOf(minCategory)) |
|
526 | if (m_categories.indexOf(maxCategory) < m_categories.indexOf(minCategory)) | |
527 | return; |
|
527 | return; | |
528 |
|
528 | |||
529 | if (!minCategory.isEmpty() && m_minCategory != minCategory && m_categories.contains(minCategory)) { |
|
529 | if (!minCategory.isEmpty() && m_minCategory != minCategory && m_categories.contains(minCategory)) { | |
530 | m_minCategory = minCategory; |
|
530 | m_minCategory = minCategory; | |
531 | m_min = m_categories.indexOf(m_minCategory) - 0.5; |
|
531 | m_min = m_categories.indexOf(m_minCategory) - 0.5; | |
532 | changed = true; |
|
532 | changed = true; | |
533 | emit q->minChanged(minCategory); |
|
533 | emit q->minChanged(minCategory); | |
534 | } |
|
534 | } | |
535 |
|
535 | |||
536 | if (!maxCategory.isEmpty() && m_maxCategory != maxCategory && m_categories.contains(maxCategory)) { |
|
536 | if (!maxCategory.isEmpty() && m_maxCategory != maxCategory && m_categories.contains(maxCategory)) { | |
537 | m_maxCategory = maxCategory; |
|
537 | m_maxCategory = maxCategory; | |
538 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; |
|
538 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; | |
539 | changed = true; |
|
539 | changed = true; | |
540 | emit q->maxChanged(maxCategory); |
|
540 | emit q->maxChanged(maxCategory); | |
541 | } |
|
541 | } | |
542 |
|
542 | |||
543 | if (changed) { |
|
543 | if (changed) { | |
544 | m_count = m_max - m_min; |
|
544 | m_count = m_max - m_min; | |
545 | emit q->rangeChanged(m_minCategory, m_maxCategory); |
|
545 | emit q->rangeChanged(m_minCategory, m_maxCategory); | |
546 | emit rangeChanged(m_min,m_max); |
|
546 | emit rangeChanged(m_min,m_max); | |
547 | } |
|
547 | } | |
548 | } |
|
548 | } | |
549 |
|
549 | |||
550 | void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
550 | void QBarCategoryAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
551 | { |
|
551 | { | |
552 | Q_Q(QBarCategoryAxis); |
|
552 | Q_Q(QBarCategoryAxis); | |
553 | ChartAxisElement* axis(0); |
|
553 | ChartAxisElement* axis(0); | |
554 | if (orientation() == Qt::Vertical) |
|
554 | if (orientation() == Qt::Vertical) | |
555 | axis = new ChartBarCategoryAxisY(q,parent); |
|
555 | axis = new ChartBarCategoryAxisY(q,parent); | |
556 | if (orientation() == Qt::Horizontal) |
|
556 | if (orientation() == Qt::Horizontal) | |
557 | axis = new ChartBarCategoryAxisX(q,parent); |
|
557 | axis = new ChartBarCategoryAxisX(q,parent); | |
558 |
|
558 | |||
559 | m_item.reset(axis); |
|
559 | m_item.reset(axis); | |
560 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
560 | QAbstractAxisPrivate::initializeGraphics(parent); | |
561 | } |
|
561 | } | |
562 |
|
562 | |||
563 | void QBarCategoryAxisPrivate::updateCategoryDomain() |
|
563 | void QBarCategoryAxisPrivate::updateCategoryDomain() | |
564 | { |
|
564 | { | |
565 | m_min = m_categories.indexOf(m_minCategory) - 0.5; |
|
565 | m_min = m_categories.indexOf(m_minCategory) - 0.5; | |
566 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; |
|
566 | m_max = m_categories.indexOf(m_maxCategory) + 0.5; | |
567 | m_count = m_max - m_min; |
|
567 | m_count = m_max - m_min; | |
568 | } |
|
568 | } | |
569 |
|
569 | |||
570 |
|
570 | |||
571 | void QBarCategoryAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
571 | void QBarCategoryAxisPrivate::initializeDomain(AbstractDomain *domain) | |
572 | { |
|
572 | { | |
573 | Q_Q(QBarCategoryAxis); |
|
573 | Q_Q(QBarCategoryAxis); | |
574 | if (m_max == m_min) { |
|
574 | if (m_max == m_min) { | |
575 | int min; |
|
575 | int min; | |
576 | int max; |
|
576 | int max; | |
577 | if (orientation() == Qt::Vertical) { |
|
577 | if (orientation() == Qt::Vertical) { | |
578 | min = domain->minY() + 0.5; |
|
578 | min = domain->minY() + 0.5; | |
579 | max = domain->maxY() - 0.5; |
|
579 | max = domain->maxY() - 0.5; | |
580 | } else { |
|
580 | } else { | |
581 | min = domain->minX() + 0.5; |
|
581 | min = domain->minX() + 0.5; | |
582 | max = domain->maxX() - 0.5; |
|
582 | max = domain->maxX() - 0.5; | |
583 | } |
|
583 | } | |
584 |
|
584 | |||
585 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) |
|
585 | if (min > 0 && min < m_categories.count() && max > 0 && max < m_categories.count()) | |
586 | q->setRange(m_categories.at(min), m_categories.at(max)); |
|
586 | q->setRange(m_categories.at(min), m_categories.at(max)); | |
587 | } else { |
|
587 | } else { | |
588 | if (orientation() == Qt::Vertical) |
|
588 | if (orientation() == Qt::Vertical) | |
589 | domain->setRangeY(m_min, m_max); |
|
589 | domain->setRangeY(m_min, m_max); | |
590 | else |
|
590 | else | |
591 | domain->setRangeX(m_min, m_max); |
|
591 | domain->setRangeX(m_min, m_max); | |
592 | } |
|
592 | } | |
593 | } |
|
593 | } | |
594 |
|
594 | |||
595 | #include "moc_qbarcategoryaxis.cpp" |
|
595 | #include "moc_qbarcategoryaxis.cpp" | |
596 | #include "moc_qbarcategoryaxis_p.cpp" |
|
596 | #include "moc_qbarcategoryaxis_p.cpp" | |
597 |
|
597 | |||
598 | QTCOMMERCIALCHART_END_NAMESPACE |
|
598 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,384 +1,384 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qdatetimeaxis.h" |
|
21 | #include "qdatetimeaxis.h" | |
22 | #include "qdatetimeaxis_p.h" |
|
22 | #include "qdatetimeaxis_p.h" | |
23 | #include "chartdatetimeaxisx_p.h" |
|
23 | #include "chartdatetimeaxisx_p.h" | |
24 | #include "chartdatetimeaxisy_p.h" |
|
24 | #include "chartdatetimeaxisy_p.h" | |
25 | #include "polarchartdatetimeaxisangular_p.h" |
|
25 | #include "polarchartdatetimeaxisangular_p.h" | |
26 | #include "polarchartdatetimeaxisradial_p.h" |
|
26 | #include "polarchartdatetimeaxisradial_p.h" | |
27 | #include "abstractdomain_p.h" |
|
27 | #include "abstractdomain_p.h" | |
28 | #include "qchart.h" |
|
28 | #include "qchart.h" | |
29 | #include <float.h> |
|
29 | #include <float.h> | |
30 | #include <cmath> |
|
30 | #include <cmath> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 | /*! |
|
33 | /*! | |
34 | \class QDateTimeAxis |
|
34 | \class QDateTimeAxis | |
35 | \brief The QDateTimeAxis class is used for manipulating chart's axis. |
|
35 | \brief The QDateTimeAxis class is used for manipulating chart's axis. | |
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | The labels can be configured by setting an appropriate DateTime format. |
|
38 | The labels can be configured by setting an appropriate DateTime format. | |
39 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE |
|
39 | QDateTimeAxis works correctly with dates from 4714 BCE to 287396 CE. | |
40 |
There are also other limitiation related to QDateTime |
|
40 | There are also other limitiation related to QDateTime. Please refer to QDateTime documentation. | |
41 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
41 | QDateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. | |
42 |
|
42 | |||
43 | Note: QDateTimeAxis is disabled on ARM architecture. |
|
43 | Note: QDateTimeAxis is disabled on ARM architecture. | |
44 |
|
44 | |||
45 | \image api_datatime_axis.png |
|
45 | \image api_datatime_axis.png | |
46 |
|
46 | |||
47 |
QDateTimeAxis can be used with |
|
47 | QDateTimeAxis can be used with any QXYSeries. | |
48 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. |
|
48 | To add a data point to the series QDateTime::toMSecsSinceEpoch() is used. | |
49 | \code |
|
49 | \code | |
50 | QLineSeries *series = new QLineSeries; |
|
50 | QLineSeries *series = new QLineSeries; | |
51 |
|
51 | |||
52 | QDateTime xValue; |
|
52 | QDateTime xValue; | |
53 | xValue.setDate(QDate(2012, 1 , 18)); |
|
53 | xValue.setDate(QDate(2012, 1 , 18)); | |
54 | xValue.setTime(QTime(9, 34)); |
|
54 | xValue.setTime(QTime(9, 34)); | |
55 | qreal yValue = 12; |
|
55 | qreal yValue = 12; | |
56 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
56 | series->append(xValue.toMSecsSinceEpoch(), yValue); | |
57 |
|
57 | |||
58 | xValue.setDate(QDate(2013, 5 , 11)); |
|
58 | xValue.setDate(QDate(2013, 5 , 11)); | |
59 | xValue.setTime(QTime(11, 14)); |
|
59 | xValue.setTime(QTime(11, 14)); | |
60 | qreal yValue = 22; |
|
60 | qreal yValue = 22; | |
61 | series->append(xValue.toMSecsSinceEpoch(), yValue); |
|
61 | series->append(xValue.toMSecsSinceEpoch(), yValue); | |
62 | \endcode |
|
62 | \endcode | |
63 |
|
63 | |||
64 | Adding the series to the chart and setting up the QDateTimeAxis. |
|
64 | Adding the series to the chart and setting up the QDateTimeAxis. | |
65 | \code |
|
65 | \code | |
66 | QChartView *chartView = new QChartView; |
|
66 | QChartView *chartView = new QChartView; | |
67 | chartView->chart()->addSeries(series); |
|
67 | chartView->chart()->addSeries(series); | |
68 |
|
68 | |||
69 | // ... |
|
69 | // ... | |
70 | QDateTimeAxis *axisX = new QDateTimeAxis; |
|
70 | QDateTimeAxis *axisX = new QDateTimeAxis; | |
71 | axisX->setFormat("dd-MM-yyyy h:mm"); |
|
71 | axisX->setFormat("dd-MM-yyyy h:mm"); | |
72 | chartView->chart()->setAxisX(axisX, series); |
|
72 | chartView->chart()->setAxisX(axisX, series); | |
73 | \endcode |
|
73 | \endcode | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \qmlclass DateTimeAxis QDateTimeAxis |
|
77 | \qmlclass DateTimeAxis QDateTimeAxis | |
78 | \brief The DateTimeAxis element is used for manipulating chart's axes |
|
78 | \brief The DateTimeAxis element is used for manipulating chart's axes | |
79 | \inherits AbstractAxis |
|
79 | \inherits AbstractAxis | |
80 |
|
80 | |||
81 | The labels can be configured by setting an appropriate DateTime format. |
|
81 | The labels can be configured by setting an appropriate DateTime format. | |
82 | Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored. |
|
82 | Note that any date before 4714 BCE or after about 1.4 million CE may not be accurately stored. | |
83 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
83 | DateTimeAxis can be setup to show axis line with tick marks, grid lines and shades. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \property QDateTimeAxis::min |
|
87 | \property QDateTimeAxis::min | |
88 | Defines the minimum value on the axis. |
|
88 | Defines the minimum value on the axis. | |
89 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
89 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty real ValuesAxis::min |
|
92 | \qmlproperty real ValuesAxis::min | |
93 | Defines the minimum value on the axis. |
|
93 | Defines the minimum value on the axis. | |
94 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
94 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
95 | */ |
|
95 | */ | |
96 |
|
96 | |||
97 | /*! |
|
97 | /*! | |
98 | \property QDateTimeAxis::max |
|
98 | \property QDateTimeAxis::max | |
99 | Defines the maximum value on the axis. |
|
99 | Defines the maximum value on the axis. | |
100 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
100 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
101 | */ |
|
101 | */ | |
102 | /*! |
|
102 | /*! | |
103 | \qmlproperty real ValuesAxis::max |
|
103 | \qmlproperty real ValuesAxis::max | |
104 | Defines the maximum value on the axis. |
|
104 | Defines the maximum value on the axis. | |
105 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
105 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \fn void QDateTimeAxis::minChanged(QDateTime min) |
|
109 | \fn void QDateTimeAxis::minChanged(QDateTime min) | |
110 | Axis emits signal when \a min of axis has changed. |
|
110 | Axis emits signal when \a min of axis has changed. | |
111 | */ |
|
111 | */ | |
112 | /*! |
|
112 | /*! | |
113 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) |
|
113 | \qmlsignal ValuesAxis::onMinChanged(QDateTime min) | |
114 | Axis emits signal when \a min of axis has changed. |
|
114 | Axis emits signal when \a min of axis has changed. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \fn void QDateTimeAxis::maxChanged(QDateTime max) |
|
118 | \fn void QDateTimeAxis::maxChanged(QDateTime max) | |
119 | Axis emits signal when \a max of axis has changed. |
|
119 | Axis emits signal when \a max of axis has changed. | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) |
|
122 | \qmlsignal ValuesAxis::onMaxChanged(QDateTime max) | |
123 | Axis emits signal when \a max of axis has changed. |
|
123 | Axis emits signal when \a max of axis has changed. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) |
|
127 | \fn void QDateTimeAxis::rangeChanged(QDateTime min, QDateTime max) | |
128 | Axis emits signal when \a min or \a max of axis has changed. |
|
128 | Axis emits signal when \a min or \a max of axis has changed. | |
129 | */ |
|
129 | */ | |
130 |
|
130 | |||
131 | /*! |
|
131 | /*! | |
132 | \property QDateTimeAxis::tickCount |
|
132 | \property QDateTimeAxis::tickCount | |
133 | The number of tick marks for the axis. |
|
133 | The number of tick marks for the axis. | |
134 | */ |
|
134 | */ | |
135 |
|
135 | |||
136 | /*! |
|
136 | /*! | |
137 | \qmlproperty int DateTimeAxis::tickCount |
|
137 | \qmlproperty int DateTimeAxis::tickCount | |
138 | The number of tick marks for the axis. |
|
138 | The number of tick marks for the axis. | |
139 | */ |
|
139 | */ | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | \property QDateTimeAxis::format |
|
142 | \property QDateTimeAxis::format | |
143 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
143 | The format string that is used when creating label for the axis out of a QDateTime object. | |
144 | Check QDateTime documentation for information on how the string should be defined. |
|
144 | Check QDateTime documentation for information on how the string should be defined. | |
145 | */ |
|
145 | */ | |
146 | /*! |
|
146 | /*! | |
147 | \qmlproperty string DateTimeAxis::format |
|
147 | \qmlproperty string DateTimeAxis::format | |
148 | The format string that is used when creating label for the axis out of a QDateTime object. |
|
148 | The format string that is used when creating label for the axis out of a QDateTime object. | |
149 | Check QDateTime documentation for information on how the string should be defined. |
|
149 | Check QDateTime documentation for information on how the string should be defined. | |
150 | */ |
|
150 | */ | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | \fn void QDateTimeAxis::tickCountChanged(int tickCount) |
|
153 | \fn void QDateTimeAxis::tickCountChanged(int tickCount) | |
154 | Axis emits signal when \a tickCount number on axis have changed. |
|
154 | Axis emits signal when \a tickCount number on axis have changed. | |
155 | */ |
|
155 | */ | |
156 | /*! |
|
156 | /*! | |
157 | \qmlsignal DateTimeAxis::tickCountChanged(int tickCount) |
|
157 | \qmlsignal DateTimeAxis::tickCountChanged(int tickCount) | |
158 | Axis emits signal when \a tickCount number on axis have changed. |
|
158 | Axis emits signal when \a tickCount number on axis have changed. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QDateTimeAxis::formatChanged(QString format) |
|
162 | \fn void QDateTimeAxis::formatChanged(QString format) | |
163 | Axis emits signal when \a format of the axis has changed. |
|
163 | Axis emits signal when \a format of the axis has changed. | |
164 | */ |
|
164 | */ | |
165 | /*! |
|
165 | /*! | |
166 | \qmlsignal DateTimeAxis::onFormatChanged(string format) |
|
166 | \qmlsignal DateTimeAxis::onFormatChanged(string format) | |
167 | Axis emits signal when \a format of the axis has changed. |
|
167 | Axis emits signal when \a format of the axis has changed. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Constructs an axis object which is a child of \a parent. |
|
171 | Constructs an axis object which is a child of \a parent. | |
172 | */ |
|
172 | */ | |
173 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : |
|
173 | QDateTimeAxis::QDateTimeAxis(QObject *parent) : | |
174 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) |
|
174 | QAbstractAxis(*new QDateTimeAxisPrivate(this), parent) | |
175 | { |
|
175 | { | |
176 |
|
176 | |||
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \internal |
|
180 | \internal | |
181 | */ |
|
181 | */ | |
182 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
182 | QDateTimeAxis::QDateTimeAxis(QDateTimeAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) | |
183 | { |
|
183 | { | |
184 |
|
184 | |||
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | Destroys the object |
|
188 | Destroys the object | |
189 | */ |
|
189 | */ | |
190 | QDateTimeAxis::~QDateTimeAxis() |
|
190 | QDateTimeAxis::~QDateTimeAxis() | |
191 | { |
|
191 | { | |
192 | Q_D(QDateTimeAxis); |
|
192 | Q_D(QDateTimeAxis); | |
193 | if (d->m_chart) |
|
193 | if (d->m_chart) | |
194 | d->m_chart->removeAxis(this); |
|
194 | d->m_chart->removeAxis(this); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | void QDateTimeAxis::setMin(QDateTime min) |
|
197 | void QDateTimeAxis::setMin(QDateTime min) | |
198 | { |
|
198 | { | |
199 | Q_D(QDateTimeAxis); |
|
199 | Q_D(QDateTimeAxis); | |
200 | if (min.isValid()) |
|
200 | if (min.isValid()) | |
201 | d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch()))); |
|
201 | d->setRange(min.toMSecsSinceEpoch(), qMax(d->m_max, qreal(min.toMSecsSinceEpoch()))); | |
202 | } |
|
202 | } | |
203 |
|
203 | |||
204 | QDateTime QDateTimeAxis::min() const |
|
204 | QDateTime QDateTimeAxis::min() const | |
205 | { |
|
205 | { | |
206 | Q_D(const QDateTimeAxis); |
|
206 | Q_D(const QDateTimeAxis); | |
207 | return QDateTime::fromMSecsSinceEpoch(d->m_min); |
|
207 | return QDateTime::fromMSecsSinceEpoch(d->m_min); | |
208 | } |
|
208 | } | |
209 |
|
209 | |||
210 | void QDateTimeAxis::setMax(QDateTime max) |
|
210 | void QDateTimeAxis::setMax(QDateTime max) | |
211 | { |
|
211 | { | |
212 | Q_D(QDateTimeAxis); |
|
212 | Q_D(QDateTimeAxis); | |
213 | if (max.isValid()) |
|
213 | if (max.isValid()) | |
214 | d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch()); |
|
214 | d->setRange(qMin(d->m_min, qreal(max.toMSecsSinceEpoch())), max.toMSecsSinceEpoch()); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | QDateTime QDateTimeAxis::max() const |
|
217 | QDateTime QDateTimeAxis::max() const | |
218 | { |
|
218 | { | |
219 | Q_D(const QDateTimeAxis); |
|
219 | Q_D(const QDateTimeAxis); | |
220 | return QDateTime::fromMSecsSinceEpoch(d->m_max); |
|
220 | return QDateTime::fromMSecsSinceEpoch(d->m_max); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | /*! |
|
223 | /*! | |
224 | Sets range from \a min to \a max on the axis. |
|
224 | Sets range from \a min to \a max on the axis. | |
225 | If min is greater than max then this function returns without making any changes. |
|
225 | If min is greater than max then this function returns without making any changes. | |
226 | */ |
|
226 | */ | |
227 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) |
|
227 | void QDateTimeAxis::setRange(QDateTime min, QDateTime max) | |
228 | { |
|
228 | { | |
229 | Q_D(QDateTimeAxis); |
|
229 | Q_D(QDateTimeAxis); | |
230 | if (!min.isValid() || !max.isValid() || min > max) |
|
230 | if (!min.isValid() || !max.isValid() || min > max) | |
231 | return; |
|
231 | return; | |
232 |
|
232 | |||
233 | d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch()); |
|
233 | d->setRange(min.toMSecsSinceEpoch(),max.toMSecsSinceEpoch()); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | void QDateTimeAxis::setFormat(QString format) |
|
236 | void QDateTimeAxis::setFormat(QString format) | |
237 | { |
|
237 | { | |
238 | Q_D(QDateTimeAxis); |
|
238 | Q_D(QDateTimeAxis); | |
239 | if (d->m_format != format) { |
|
239 | if (d->m_format != format) { | |
240 | d->m_format = format; |
|
240 | d->m_format = format; | |
241 | emit formatChanged(format); |
|
241 | emit formatChanged(format); | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | QString QDateTimeAxis::format() const |
|
245 | QString QDateTimeAxis::format() const | |
246 | { |
|
246 | { | |
247 | Q_D(const QDateTimeAxis); |
|
247 | Q_D(const QDateTimeAxis); | |
248 | return d->m_format; |
|
248 | return d->m_format; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | /*! |
|
251 | /*! | |
252 | Sets \a count for ticks on the axis. |
|
252 | Sets \a count for ticks on the axis. | |
253 | */ |
|
253 | */ | |
254 | void QDateTimeAxis::setTickCount(int count) |
|
254 | void QDateTimeAxis::setTickCount(int count) | |
255 | { |
|
255 | { | |
256 | Q_D(QDateTimeAxis); |
|
256 | Q_D(QDateTimeAxis); | |
257 | if (d->m_tickCount != count && count >= 2) { |
|
257 | if (d->m_tickCount != count && count >= 2) { | |
258 | d->m_tickCount = count; |
|
258 | d->m_tickCount = count; | |
259 | emit tickCountChanged(count); |
|
259 | emit tickCountChanged(count); | |
260 | } |
|
260 | } | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | /*! |
|
263 | /*! | |
264 | \fn int QDateTimeAxis::tickCount() const |
|
264 | \fn int QDateTimeAxis::tickCount() const | |
265 | Return number of ticks on the axis |
|
265 | Return number of ticks on the axis | |
266 | */ |
|
266 | */ | |
267 | int QDateTimeAxis::tickCount() const |
|
267 | int QDateTimeAxis::tickCount() const | |
268 | { |
|
268 | { | |
269 | Q_D(const QDateTimeAxis); |
|
269 | Q_D(const QDateTimeAxis); | |
270 | return d->m_tickCount; |
|
270 | return d->m_tickCount; | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | /*! |
|
273 | /*! | |
274 | Returns the type of the axis |
|
274 | Returns the type of the axis | |
275 | */ |
|
275 | */ | |
276 | QAbstractAxis::AxisType QDateTimeAxis::type() const |
|
276 | QAbstractAxis::AxisType QDateTimeAxis::type() const | |
277 | { |
|
277 | { | |
278 | return AxisTypeDateTime; |
|
278 | return AxisTypeDateTime; | |
279 | } |
|
279 | } | |
280 |
|
280 | |||
281 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
281 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
282 |
|
282 | |||
283 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) |
|
283 | QDateTimeAxisPrivate::QDateTimeAxisPrivate(QDateTimeAxis *q) | |
284 | : QAbstractAxisPrivate(q), |
|
284 | : QAbstractAxisPrivate(q), | |
285 | m_min(0), |
|
285 | m_min(0), | |
286 | m_max(0), |
|
286 | m_max(0), | |
287 | m_tickCount(5) |
|
287 | m_tickCount(5) | |
288 | { |
|
288 | { | |
289 | m_format = "dd-MM-yyyy\nh:mm"; |
|
289 | m_format = "dd-MM-yyyy\nh:mm"; | |
290 | } |
|
290 | } | |
291 |
|
291 | |||
292 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() |
|
292 | QDateTimeAxisPrivate::~QDateTimeAxisPrivate() | |
293 | { |
|
293 | { | |
294 |
|
294 | |||
295 | } |
|
295 | } | |
296 |
|
296 | |||
297 | void QDateTimeAxisPrivate::setRange(qreal min,qreal max) |
|
297 | void QDateTimeAxisPrivate::setRange(qreal min,qreal max) | |
298 | { |
|
298 | { | |
299 | Q_Q(QDateTimeAxis); |
|
299 | Q_Q(QDateTimeAxis); | |
300 |
|
300 | |||
301 | bool changed = false; |
|
301 | bool changed = false; | |
302 |
|
302 | |||
303 | if (m_min != min) { |
|
303 | if (m_min != min) { | |
304 | m_min = min; |
|
304 | m_min = min; | |
305 | changed = true; |
|
305 | changed = true; | |
306 | emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min)); |
|
306 | emit q->minChanged(QDateTime::fromMSecsSinceEpoch(min)); | |
307 | } |
|
307 | } | |
308 |
|
308 | |||
309 | if (m_max != max) { |
|
309 | if (m_max != max) { | |
310 | m_max = max; |
|
310 | m_max = max; | |
311 | changed = true; |
|
311 | changed = true; | |
312 | emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max)); |
|
312 | emit q->maxChanged(QDateTime::fromMSecsSinceEpoch(max)); | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | if (changed) { |
|
315 | if (changed) { | |
316 | emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); |
|
316 | emit q->rangeChanged(QDateTime::fromMSecsSinceEpoch(min), QDateTime::fromMSecsSinceEpoch(max)); | |
317 | emit rangeChanged(m_min,m_max); |
|
317 | emit rangeChanged(m_min,m_max); | |
318 | } |
|
318 | } | |
319 | } |
|
319 | } | |
320 |
|
320 | |||
321 |
|
321 | |||
322 | void QDateTimeAxisPrivate::setMin(const QVariant &min) |
|
322 | void QDateTimeAxisPrivate::setMin(const QVariant &min) | |
323 | { |
|
323 | { | |
324 | Q_Q(QDateTimeAxis); |
|
324 | Q_Q(QDateTimeAxis); | |
325 | if (min.canConvert(QVariant::DateTime)) |
|
325 | if (min.canConvert(QVariant::DateTime)) | |
326 | q->setMin(min.toDateTime()); |
|
326 | q->setMin(min.toDateTime()); | |
327 | } |
|
327 | } | |
328 |
|
328 | |||
329 | void QDateTimeAxisPrivate::setMax(const QVariant &max) |
|
329 | void QDateTimeAxisPrivate::setMax(const QVariant &max) | |
330 | { |
|
330 | { | |
331 |
|
331 | |||
332 | Q_Q(QDateTimeAxis); |
|
332 | Q_Q(QDateTimeAxis); | |
333 | if (max.canConvert(QVariant::DateTime)) |
|
333 | if (max.canConvert(QVariant::DateTime)) | |
334 | q->setMax(max.toDateTime()); |
|
334 | q->setMax(max.toDateTime()); | |
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
337 | void QDateTimeAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
338 | { |
|
338 | { | |
339 | Q_Q(QDateTimeAxis); |
|
339 | Q_Q(QDateTimeAxis); | |
340 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) |
|
340 | if (min.canConvert(QVariant::DateTime) && max.canConvert(QVariant::DateTime)) | |
341 | q->setRange(min.toDateTime(), max.toDateTime()); |
|
341 | q->setRange(min.toDateTime(), max.toDateTime()); | |
342 | } |
|
342 | } | |
343 |
|
343 | |||
344 | void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
344 | void QDateTimeAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
345 | { |
|
345 | { | |
346 | Q_Q(QDateTimeAxis); |
|
346 | Q_Q(QDateTimeAxis); | |
347 | ChartAxisElement *axis(0); |
|
347 | ChartAxisElement *axis(0); | |
348 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
348 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { | |
349 | if (orientation() == Qt::Vertical) |
|
349 | if (orientation() == Qt::Vertical) | |
350 | axis = new ChartDateTimeAxisY(q,parent); |
|
350 | axis = new ChartDateTimeAxisY(q,parent); | |
351 | if (orientation() == Qt::Horizontal) |
|
351 | if (orientation() == Qt::Horizontal) | |
352 | axis = new ChartDateTimeAxisX(q,parent); |
|
352 | axis = new ChartDateTimeAxisX(q,parent); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
355 | if (m_chart->chartType() == QChart::ChartTypePolar) { | |
356 | if (orientation() == Qt::Vertical) |
|
356 | if (orientation() == Qt::Vertical) | |
357 | axis = new PolarChartDateTimeAxisRadial(q, parent); |
|
357 | axis = new PolarChartDateTimeAxisRadial(q, parent); | |
358 | if (orientation() == Qt::Horizontal) |
|
358 | if (orientation() == Qt::Horizontal) | |
359 | axis = new PolarChartDateTimeAxisAngular(q, parent); |
|
359 | axis = new PolarChartDateTimeAxisAngular(q, parent); | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | m_item.reset(axis); |
|
362 | m_item.reset(axis); | |
363 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
363 | QAbstractAxisPrivate::initializeGraphics(parent); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
366 | void QDateTimeAxisPrivate::initializeDomain(AbstractDomain *domain) | |
367 | { |
|
367 | { | |
368 | if (m_max == m_min) { |
|
368 | if (m_max == m_min) { | |
369 | if (orientation() == Qt::Vertical) |
|
369 | if (orientation() == Qt::Vertical) | |
370 | setRange(domain->minY(), domain->maxY()); |
|
370 | setRange(domain->minY(), domain->maxY()); | |
371 | else |
|
371 | else | |
372 | setRange(domain->minX(), domain->maxX()); |
|
372 | setRange(domain->minX(), domain->maxX()); | |
373 | } else { |
|
373 | } else { | |
374 | if (orientation() == Qt::Vertical) |
|
374 | if (orientation() == Qt::Vertical) | |
375 | domain->setRangeY(m_min, m_max); |
|
375 | domain->setRangeY(m_min, m_max); | |
376 | else |
|
376 | else | |
377 | domain->setRangeX(m_min, m_max); |
|
377 | domain->setRangeX(m_min, m_max); | |
378 | } |
|
378 | } | |
379 | } |
|
379 | } | |
380 |
|
380 | |||
381 | #include "moc_qdatetimeaxis.cpp" |
|
381 | #include "moc_qdatetimeaxis.cpp" | |
382 | #include "moc_qdatetimeaxis_p.cpp" |
|
382 | #include "moc_qdatetimeaxis_p.cpp" | |
383 |
|
383 | |||
384 | QTCOMMERCIALCHART_END_NAMESPACE |
|
384 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,396 +1,396 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlogvalueaxis.h" |
|
21 | #include "qlogvalueaxis.h" | |
22 | #include "qlogvalueaxis_p.h" |
|
22 | #include "qlogvalueaxis_p.h" | |
23 | #include "chartlogvalueaxisx_p.h" |
|
23 | #include "chartlogvalueaxisx_p.h" | |
24 | #include "chartlogvalueaxisy_p.h" |
|
24 | #include "chartlogvalueaxisy_p.h" | |
25 | #include "polarchartlogvalueaxisangular_p.h" |
|
25 | #include "polarchartlogvalueaxisangular_p.h" | |
26 | #include "polarchartlogvalueaxisradial_p.h" |
|
26 | #include "polarchartlogvalueaxisradial_p.h" | |
27 | #include "abstractdomain_p.h" |
|
27 | #include "abstractdomain_p.h" | |
28 | #include <float.h> |
|
28 | #include <float.h> | |
29 | #include <cmath> |
|
29 | #include <cmath> | |
30 |
|
30 | |||
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
31 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
32 | /*! |
|
32 | /*! | |
33 | \class QLogValueAxis |
|
33 | \class QLogValueAxis | |
34 | \brief The QLogValueAxis class is used for manipulating chart's axis. |
|
34 | \brief The QLogValueAxis class is used for manipulating chart's axis. | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \note If a QLogValueAxis is attached to a series with one or more points with |
|
37 | \note If a QLogValueAxis is attached to a series with one or more points with | |
38 | negative or zero values on the associated dimension, the series will not be |
|
38 | negative or zero values on the associated dimension, the series will not be | |
39 | plotted at all. This is particularly relevant when XYModelMappers are used, |
|
39 | plotted at all. This is particularly relevant when XYModelMappers are used, | |
40 | since empty cells in models typically contain zero values. |
|
40 | since empty cells in models typically contain zero values. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 |
\qmlclass LogValue |
|
44 | \qmlclass LogValueAxis QLogValueAxis | |
45 | \brief The LogValueAxis element is used for manipulating chart's axes |
|
45 | \brief The LogValueAxis element is used for manipulating chart's axes | |
46 | \inherits AbstractAxis |
|
46 | \inherits AbstractAxis | |
47 |
|
47 | |||
48 | \note If a LogValueAxis is attached to a series with one or more points with |
|
48 | \note If a LogValueAxis is attached to a series with one or more points with | |
49 | negative or zero values on the associated dimension, the series will not be |
|
49 | negative or zero values on the associated dimension, the series will not be | |
50 | plotted at all. This is particularly relevant when XYModelMappers are used, |
|
50 | plotted at all. This is particularly relevant when XYModelMappers are used, | |
51 | since empty cells in models typically contain zero values. |
|
51 | since empty cells in models typically contain zero values. | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | \property QLogValueAxis::min |
|
55 | \property QLogValueAxis::min | |
56 | Defines the minimum value on the axis. |
|
56 | Defines the minimum value on the axis. | |
57 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
57 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
58 | Value has to be greater than 0. |
|
58 | Value has to be greater than 0. | |
59 | */ |
|
59 | */ | |
60 | /*! |
|
60 | /*! | |
61 |
\qmlproperty real LogValue |
|
61 | \qmlproperty real LogValueAxis::min | |
62 | Defines the minimum value on the axis. |
|
62 | Defines the minimum value on the axis. | |
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
63 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
64 | Value has to be greater than 0. |
|
64 | Value has to be greater than 0. | |
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | \property QLogValueAxis::max |
|
68 | \property QLogValueAxis::max | |
69 | Defines the maximum value on the axis. |
|
69 | Defines the maximum value on the axis. | |
70 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
70 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
71 | Value has to be greater than 0. |
|
71 | Value has to be greater than 0. | |
72 | */ |
|
72 | */ | |
73 | /*! |
|
73 | /*! | |
74 |
\qmlproperty real LogValue |
|
74 | \qmlproperty real LogValueAxis::max | |
75 | Defines the maximum value on the axis. |
|
75 | Defines the maximum value on the axis. | |
76 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
76 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
77 | Value has to be greater than 0. |
|
77 | Value has to be greater than 0. | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QLogValueAxis::base |
|
81 | \property QLogValueAxis::base | |
82 | Defines the base of the logarithm. |
|
82 | Defines the base of the logarithm. | |
83 | Value has to be greater than 0 and not equal 1 |
|
83 | Value has to be greater than 0 and not equal 1 | |
84 | */ |
|
84 | */ | |
85 | /*! |
|
85 | /*! | |
86 |
\qmlproperty real LogValue |
|
86 | \qmlproperty real LogValueAxis::base | |
87 | Defines the maximum value on the axis. |
|
87 | Defines the maximum value on the axis. | |
88 | Defines the base of the logarithm. |
|
88 | Defines the base of the logarithm. | |
89 | Value has to be greater than 0 and not equal 1 |
|
89 | Value has to be greater than 0 and not equal 1 | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \property QLogValueAxis::labelFormat |
|
93 | \property QLogValueAxis::labelFormat | |
94 | Defines the label format of the axis. |
|
94 | Defines the label format of the axis. | |
95 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
95 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c | |
96 | See QString::sprintf() for additional details. |
|
96 | See QString::sprintf() for additional details. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 |
\qmlproperty real LogValue |
|
99 | \qmlproperty real LogValueAxis::labelFormat | |
100 | Defines the label format of the axis. |
|
100 | Defines the label format of the axis. | |
101 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
101 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c | |
102 | See QString::sprintf() for additional details. |
|
102 | See QString::sprintf() for additional details. | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \fn void QLogValueAxis::minChanged(qreal min) |
|
106 | \fn void QLogValueAxis::minChanged(qreal min) | |
107 | Axis emits signal when \a min of axis has changed. |
|
107 | Axis emits signal when \a min of axis has changed. | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 |
\qmlsignal LogValue |
|
110 | \qmlsignal LogValueAxis::onMinChanged(qreal min) | |
111 | Axis emits signal when \a min of axis has changed. |
|
111 | Axis emits signal when \a min of axis has changed. | |
112 | */ |
|
112 | */ | |
113 |
|
113 | |||
114 | /*! |
|
114 | /*! | |
115 | \fn void QLogValueAxis::maxChanged(qreal max) |
|
115 | \fn void QLogValueAxis::maxChanged(qreal max) | |
116 | Axis emits signal when \a max of axis has changed. |
|
116 | Axis emits signal when \a max of axis has changed. | |
117 | */ |
|
117 | */ | |
118 | /*! |
|
118 | /*! | |
119 |
\qmlsignal LogValue |
|
119 | \qmlsignal LogValueAxis::onMaxChanged(qreal max) | |
120 | Axis emits signal when \a max of axis has changed. |
|
120 | Axis emits signal when \a max of axis has changed. | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) |
|
124 | \fn void QLogValueAxis::rangeChanged(qreal min, qreal max) | |
125 | Axis emits signal when \a min or \a max of axis has changed. |
|
125 | Axis emits signal when \a min or \a max of axis has changed. | |
126 | */ |
|
126 | */ | |
127 |
|
127 | |||
128 | /*! |
|
128 | /*! | |
129 | \fn void QLogValueAxis::labelFormatChanged(const QString &format) |
|
129 | \fn void QLogValueAxis::labelFormatChanged(const QString &format) | |
130 | Axis emits signal when \a format of axis labels has changed. |
|
130 | Axis emits signal when \a format of axis labels has changed. | |
131 | */ |
|
131 | */ | |
132 | /*! |
|
132 | /*! | |
133 | \qmlsignal LogValueAxis::labelFormatChanged(const QString &format) |
|
133 | \qmlsignal LogValueAxis::labelFormatChanged(const QString &format) | |
134 | Axis emits signal when \a format of axis labels has changed. |
|
134 | Axis emits signal when \a format of axis labels has changed. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QLogValueAxis::baseChanged(qreal base) |
|
138 | \fn void QLogValueAxis::baseChanged(qreal base) | |
139 | Axis emits signal when \a base of logarithm of the axis has changed. |
|
139 | Axis emits signal when \a base of logarithm of the axis has changed. | |
140 | */ |
|
140 | */ | |
141 | /*! |
|
141 | /*! | |
142 |
\qmlsignal LogValue |
|
142 | \qmlsignal LogValueAxis::baseChanged(qreal base) | |
143 | Axis emits signal when \a base of logarithm of the axis has changed. |
|
143 | Axis emits signal when \a base of logarithm of the axis has changed. | |
144 | */ |
|
144 | */ | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | Constructs an axis object which is a child of \a parent. |
|
147 | Constructs an axis object which is a child of \a parent. | |
148 | */ |
|
148 | */ | |
149 | QLogValueAxis::QLogValueAxis(QObject *parent) : |
|
149 | QLogValueAxis::QLogValueAxis(QObject *parent) : | |
150 | QAbstractAxis(*new QLogValueAxisPrivate(this), parent) |
|
150 | QAbstractAxis(*new QLogValueAxisPrivate(this), parent) | |
151 | { |
|
151 | { | |
152 |
|
152 | |||
153 | } |
|
153 | } | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \internal |
|
156 | \internal | |
157 | */ |
|
157 | */ | |
158 | QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) |
|
158 | QLogValueAxis::QLogValueAxis(QLogValueAxisPrivate &d, QObject *parent) : QAbstractAxis(d, parent) | |
159 | { |
|
159 | { | |
160 |
|
160 | |||
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | /*! |
|
163 | /*! | |
164 | Destroys the object |
|
164 | Destroys the object | |
165 | */ |
|
165 | */ | |
166 | QLogValueAxis::~QLogValueAxis() |
|
166 | QLogValueAxis::~QLogValueAxis() | |
167 | { |
|
167 | { | |
168 | Q_D(QLogValueAxis); |
|
168 | Q_D(QLogValueAxis); | |
169 | if (d->m_chart) |
|
169 | if (d->m_chart) | |
170 | d->m_chart->removeAxis(this); |
|
170 | d->m_chart->removeAxis(this); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void QLogValueAxis::setMin(qreal min) |
|
173 | void QLogValueAxis::setMin(qreal min) | |
174 | { |
|
174 | { | |
175 | Q_D(QLogValueAxis); |
|
175 | Q_D(QLogValueAxis); | |
176 | setRange(min, qMax(d->m_max, min)); |
|
176 | setRange(min, qMax(d->m_max, min)); | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | qreal QLogValueAxis::min() const |
|
179 | qreal QLogValueAxis::min() const | |
180 | { |
|
180 | { | |
181 | Q_D(const QLogValueAxis); |
|
181 | Q_D(const QLogValueAxis); | |
182 | return d->m_min; |
|
182 | return d->m_min; | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void QLogValueAxis::setMax(qreal max) |
|
185 | void QLogValueAxis::setMax(qreal max) | |
186 | { |
|
186 | { | |
187 | Q_D(QLogValueAxis); |
|
187 | Q_D(QLogValueAxis); | |
188 | setRange(qMin(d->m_min, max), max); |
|
188 | setRange(qMin(d->m_min, max), max); | |
189 | } |
|
189 | } | |
190 |
|
190 | |||
191 | qreal QLogValueAxis::max() const |
|
191 | qreal QLogValueAxis::max() const | |
192 | { |
|
192 | { | |
193 | Q_D(const QLogValueAxis); |
|
193 | Q_D(const QLogValueAxis); | |
194 | return d->m_max; |
|
194 | return d->m_max; | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | Sets range from \a min to \a max on the axis. |
|
198 | Sets range from \a min to \a max on the axis. | |
199 | If min is greater than max then this function returns without making any changes. |
|
199 | If min is greater than max then this function returns without making any changes. | |
200 | */ |
|
200 | */ | |
201 | void QLogValueAxis::setRange(qreal min, qreal max) |
|
201 | void QLogValueAxis::setRange(qreal min, qreal max) | |
202 | { |
|
202 | { | |
203 | Q_D(QLogValueAxis); |
|
203 | Q_D(QLogValueAxis); | |
204 | bool changed = false; |
|
204 | bool changed = false; | |
205 |
|
205 | |||
206 | if (min > max) |
|
206 | if (min > max) | |
207 | return; |
|
207 | return; | |
208 |
|
208 | |||
209 | if (min > 0) { |
|
209 | if (min > 0) { | |
210 | if (!qFuzzyCompare(d->m_min, min)) { |
|
210 | if (!qFuzzyCompare(d->m_min, min)) { | |
211 | d->m_min = min; |
|
211 | d->m_min = min; | |
212 | changed = true; |
|
212 | changed = true; | |
213 | emit minChanged(min); |
|
213 | emit minChanged(min); | |
214 | } |
|
214 | } | |
215 |
|
215 | |||
216 | if (!qFuzzyCompare(d->m_max, max)) { |
|
216 | if (!qFuzzyCompare(d->m_max, max)) { | |
217 | d->m_max = max; |
|
217 | d->m_max = max; | |
218 | changed = true; |
|
218 | changed = true; | |
219 | emit maxChanged(max); |
|
219 | emit maxChanged(max); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | if (changed) { |
|
222 | if (changed) { | |
223 | emit rangeChanged(min, max); |
|
223 | emit rangeChanged(min, max); | |
224 | emit d->rangeChanged(min,max); |
|
224 | emit d->rangeChanged(min,max); | |
225 | } |
|
225 | } | |
226 | } |
|
226 | } | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | void QLogValueAxis::setLabelFormat(const QString &format) |
|
229 | void QLogValueAxis::setLabelFormat(const QString &format) | |
230 | { |
|
230 | { | |
231 | Q_D(QLogValueAxis); |
|
231 | Q_D(QLogValueAxis); | |
232 | d->m_format = format; |
|
232 | d->m_format = format; | |
233 | emit labelFormatChanged(format); |
|
233 | emit labelFormatChanged(format); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | QString QLogValueAxis::labelFormat() const |
|
236 | QString QLogValueAxis::labelFormat() const | |
237 | { |
|
237 | { | |
238 | Q_D(const QLogValueAxis); |
|
238 | Q_D(const QLogValueAxis); | |
239 | return d->m_format; |
|
239 | return d->m_format; | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | void QLogValueAxis::setBase(qreal base) |
|
242 | void QLogValueAxis::setBase(qreal base) | |
243 | { |
|
243 | { | |
244 | // check if base is correct |
|
244 | // check if base is correct | |
245 | if (qFuzzyCompare(base, 1)) |
|
245 | if (qFuzzyCompare(base, 1)) | |
246 | return; |
|
246 | return; | |
247 |
|
247 | |||
248 | if (base > 0) { |
|
248 | if (base > 0) { | |
249 | Q_D(QLogValueAxis); |
|
249 | Q_D(QLogValueAxis); | |
250 | d->m_base = base; |
|
250 | d->m_base = base; | |
251 | emit baseChanged(base); |
|
251 | emit baseChanged(base); | |
252 | } |
|
252 | } | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 | qreal QLogValueAxis::base() const |
|
255 | qreal QLogValueAxis::base() const | |
256 | { |
|
256 | { | |
257 | Q_D(const QLogValueAxis); |
|
257 | Q_D(const QLogValueAxis); | |
258 | return d->m_base; |
|
258 | return d->m_base; | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Returns the type of the axis |
|
262 | Returns the type of the axis | |
263 | */ |
|
263 | */ | |
264 | QAbstractAxis::AxisType QLogValueAxis::type() const |
|
264 | QAbstractAxis::AxisType QLogValueAxis::type() const | |
265 | { |
|
265 | { | |
266 | return AxisTypeLogValue; |
|
266 | return AxisTypeLogValue; | |
267 | } |
|
267 | } | |
268 |
|
268 | |||
269 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
269 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
270 |
|
270 | |||
271 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) |
|
271 | QLogValueAxisPrivate::QLogValueAxisPrivate(QLogValueAxis *q) | |
272 | : QAbstractAxisPrivate(q), |
|
272 | : QAbstractAxisPrivate(q), | |
273 | m_min(1), |
|
273 | m_min(1), | |
274 | m_max(1), |
|
274 | m_max(1), | |
275 | m_base(10), |
|
275 | m_base(10), | |
276 | m_format(QString::null) |
|
276 | m_format(QString::null) | |
277 | { |
|
277 | { | |
278 | } |
|
278 | } | |
279 |
|
279 | |||
280 | QLogValueAxisPrivate::~QLogValueAxisPrivate() |
|
280 | QLogValueAxisPrivate::~QLogValueAxisPrivate() | |
281 | { |
|
281 | { | |
282 |
|
282 | |||
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | void QLogValueAxisPrivate::setMin(const QVariant &min) |
|
285 | void QLogValueAxisPrivate::setMin(const QVariant &min) | |
286 | { |
|
286 | { | |
287 | Q_Q(QLogValueAxis); |
|
287 | Q_Q(QLogValueAxis); | |
288 | bool ok; |
|
288 | bool ok; | |
289 | qreal value = min.toReal(&ok); |
|
289 | qreal value = min.toReal(&ok); | |
290 | if (ok) |
|
290 | if (ok) | |
291 | q->setMin(value); |
|
291 | q->setMin(value); | |
292 | } |
|
292 | } | |
293 |
|
293 | |||
294 | void QLogValueAxisPrivate::setMax(const QVariant &max) |
|
294 | void QLogValueAxisPrivate::setMax(const QVariant &max) | |
295 | { |
|
295 | { | |
296 |
|
296 | |||
297 | Q_Q(QLogValueAxis); |
|
297 | Q_Q(QLogValueAxis); | |
298 | bool ok; |
|
298 | bool ok; | |
299 | qreal value = max.toReal(&ok); |
|
299 | qreal value = max.toReal(&ok); | |
300 | if (ok) |
|
300 | if (ok) | |
301 | q->setMax(value); |
|
301 | q->setMax(value); | |
302 | } |
|
302 | } | |
303 |
|
303 | |||
304 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
304 | void QLogValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
305 | { |
|
305 | { | |
306 | Q_Q(QLogValueAxis); |
|
306 | Q_Q(QLogValueAxis); | |
307 | bool ok1; |
|
307 | bool ok1; | |
308 | bool ok2; |
|
308 | bool ok2; | |
309 | qreal value1 = min.toReal(&ok1); |
|
309 | qreal value1 = min.toReal(&ok1); | |
310 | qreal value2 = max.toReal(&ok2); |
|
310 | qreal value2 = max.toReal(&ok2); | |
311 | if (ok1 && ok2) |
|
311 | if (ok1 && ok2) | |
312 | q->setRange(value1, value2); |
|
312 | q->setRange(value1, value2); | |
313 | } |
|
313 | } | |
314 |
|
314 | |||
315 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) |
|
315 | void QLogValueAxisPrivate::setRange(qreal min, qreal max) | |
316 | { |
|
316 | { | |
317 | Q_Q(QLogValueAxis); |
|
317 | Q_Q(QLogValueAxis); | |
318 | bool changed = false; |
|
318 | bool changed = false; | |
319 |
|
319 | |||
320 | if (min > max) |
|
320 | if (min > max) | |
321 | return; |
|
321 | return; | |
322 |
|
322 | |||
323 | if (min > 0) { |
|
323 | if (min > 0) { | |
324 | if (!qFuzzyCompare(m_min, min)) { |
|
324 | if (!qFuzzyCompare(m_min, min)) { | |
325 | m_min = min; |
|
325 | m_min = min; | |
326 | changed = true; |
|
326 | changed = true; | |
327 | emit q->minChanged(min); |
|
327 | emit q->minChanged(min); | |
328 | } |
|
328 | } | |
329 |
|
329 | |||
330 | if (!qFuzzyCompare(m_max, max)) { |
|
330 | if (!qFuzzyCompare(m_max, max)) { | |
331 | m_max = max; |
|
331 | m_max = max; | |
332 | changed = true; |
|
332 | changed = true; | |
333 | emit q->maxChanged(max); |
|
333 | emit q->maxChanged(max); | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | if (changed) { |
|
336 | if (changed) { | |
337 | emit rangeChanged(min,max); |
|
337 | emit rangeChanged(min,max); | |
338 | emit q->rangeChanged(min, max); |
|
338 | emit q->rangeChanged(min, max); | |
339 | } |
|
339 | } | |
340 | } |
|
340 | } | |
341 | } |
|
341 | } | |
342 |
|
342 | |||
343 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem *parent) |
|
343 | void QLogValueAxisPrivate::initializeGraphics(QGraphicsItem *parent) | |
344 | { |
|
344 | { | |
345 | Q_Q(QLogValueAxis); |
|
345 | Q_Q(QLogValueAxis); | |
346 | ChartAxisElement *axis(0); |
|
346 | ChartAxisElement *axis(0); | |
347 |
|
347 | |||
348 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
348 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { | |
349 | if (orientation() == Qt::Vertical) |
|
349 | if (orientation() == Qt::Vertical) | |
350 | axis = new ChartLogValueAxisY(q,parent); |
|
350 | axis = new ChartLogValueAxisY(q,parent); | |
351 | if (orientation() == Qt::Horizontal) |
|
351 | if (orientation() == Qt::Horizontal) | |
352 | axis = new ChartLogValueAxisX(q,parent); |
|
352 | axis = new ChartLogValueAxisX(q,parent); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
355 | if (m_chart->chartType() == QChart::ChartTypePolar) { | |
356 | if (orientation() == Qt::Vertical) |
|
356 | if (orientation() == Qt::Vertical) | |
357 | axis = new PolarChartLogValueAxisRadial(q, parent); |
|
357 | axis = new PolarChartLogValueAxisRadial(q, parent); | |
358 | if (orientation() == Qt::Horizontal) |
|
358 | if (orientation() == Qt::Horizontal) | |
359 | axis = new PolarChartLogValueAxisAngular(q, parent); |
|
359 | axis = new PolarChartLogValueAxisAngular(q, parent); | |
360 | } |
|
360 | } | |
361 |
|
361 | |||
362 | m_item.reset(axis); |
|
362 | m_item.reset(axis); | |
363 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
363 | QAbstractAxisPrivate::initializeGraphics(parent); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 |
|
366 | |||
367 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
367 | void QLogValueAxisPrivate::initializeDomain(AbstractDomain *domain) | |
368 | { |
|
368 | { | |
369 | if (orientation() == Qt::Vertical) { |
|
369 | if (orientation() == Qt::Vertical) { | |
370 | if (!qFuzzyCompare(m_max, m_min)) { |
|
370 | if (!qFuzzyCompare(m_max, m_min)) { | |
371 | domain->setRangeY(m_min, m_max); |
|
371 | domain->setRangeY(m_min, m_max); | |
372 | } else if ( domain->minY() > 0) { |
|
372 | } else if ( domain->minY() > 0) { | |
373 | setRange(domain->minY(), domain->maxY()); |
|
373 | setRange(domain->minY(), domain->maxY()); | |
374 | } else if (domain->maxY() > 0) { |
|
374 | } else if (domain->maxY() > 0) { | |
375 | domain->setRangeY(m_min, domain->maxY()); |
|
375 | domain->setRangeY(m_min, domain->maxY()); | |
376 | } else { |
|
376 | } else { | |
377 | domain->setRangeY(1, 10); |
|
377 | domain->setRangeY(1, 10); | |
378 | } |
|
378 | } | |
379 | } |
|
379 | } | |
380 | if (orientation() == Qt::Horizontal) { |
|
380 | if (orientation() == Qt::Horizontal) { | |
381 | if (!qFuzzyCompare(m_max, m_min)) { |
|
381 | if (!qFuzzyCompare(m_max, m_min)) { | |
382 | domain->setRangeX(m_min, m_max); |
|
382 | domain->setRangeX(m_min, m_max); | |
383 | } else if (domain->minX() > 0){ |
|
383 | } else if (domain->minX() > 0){ | |
384 | setRange(domain->minX(), domain->maxX()); |
|
384 | setRange(domain->minX(), domain->maxX()); | |
385 | } else if (domain->maxX() > 0) { |
|
385 | } else if (domain->maxX() > 0) { | |
386 | domain->setRangeX(m_min, domain->maxX()); |
|
386 | domain->setRangeX(m_min, domain->maxX()); | |
387 | } else { |
|
387 | } else { | |
388 | domain->setRangeX(1, 10); |
|
388 | domain->setRangeX(1, 10); | |
389 | } |
|
389 | } | |
390 | } |
|
390 | } | |
391 | } |
|
391 | } | |
392 |
|
392 | |||
393 | #include "moc_qlogvalueaxis.cpp" |
|
393 | #include "moc_qlogvalueaxis.cpp" | |
394 | #include "moc_qlogvalueaxis_p.cpp" |
|
394 | #include "moc_qlogvalueaxis_p.cpp" | |
395 |
|
395 | |||
396 | QTCOMMERCIALCHART_END_NAMESPACE |
|
396 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,1007 +1,999 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "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 |
|
25 | |||
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
26 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QAbstractAxis |
|
29 | \class QAbstractAxis | |
30 | \brief The QAbstractAxis class is used for manipulating chart's axis. |
|
30 | \brief The QAbstractAxis class is used for manipulating chart's axis. | |
31 | \mainclass |
|
31 | \mainclass | |
32 |
|
32 | |||
33 | There is only one x Axis visible at the time, however there can be multiple y axes. |
|
33 | Each series can be bound to one or more horizontal and vertical axes, but mixing axis types | |
34 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
34 | that would result in different domains is not supported, such as specifying | |
35 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
35 | QValueAxis and QLogValueAxis on the same orientation. | |
|
36 | ||||
|
37 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, | |||
|
38 | and shades can be individually controlled. | |||
36 | */ |
|
39 | */ | |
37 |
|
40 | |||
38 | /*! |
|
41 | /*! | |
39 | \qmlclass AbstractAxis QAbstractAxis |
|
42 | \qmlclass AbstractAxis QAbstractAxis | |
40 | \brief The Axis element is used for manipulating chart's axes |
|
43 | \brief The AbstractAxis is a base element used for specialized axis elements | |
41 |
|
44 | |||
42 | There is only one x Axis visible at the time, however there can be multiple y axes on a ChartView. |
|
45 | Each series can be bound to only one horizontal and vertical axis. | |
43 | Each chart series can be bound to exactly one Y axis and the shared common X axis. |
|
46 | ||
44 | Axis can be setup to show axis line with tick marks, grid lines and shades. |
|
47 | Properties and visibility of various axis elements such as axis line, title, labels, grid lines, | |
45 |
|
48 | and shades can be individually controlled. | ||
46 | To access Axes you can use ChartView API. For example: |
|
|||
47 | \code |
|
|||
48 | ChartView { |
|
|||
49 | axisX.min: 0 |
|
|||
50 | axisX.max: 3 |
|
|||
51 | axisX.ticksCount: 4 |
|
|||
52 | axisY.min: 0 |
|
|||
53 | axisY.max: 4 |
|
|||
54 | // Add a few series... |
|
|||
55 | } |
|
|||
56 | \endcode |
|
|||
57 | */ |
|
49 | */ | |
58 |
|
50 | |||
59 | /*! |
|
51 | /*! | |
60 | \enum QAbstractAxis::AxisType |
|
52 | \enum QAbstractAxis::AxisType | |
61 |
|
53 | |||
62 | The type of the series object. |
|
54 | The type of the series object. | |
63 |
|
55 | |||
64 | \value AxisTypeNoAxis |
|
56 | \value AxisTypeNoAxis | |
65 | \value AxisTypeValue |
|
57 | \value AxisTypeValue | |
66 | \value AxisTypeBarCategory |
|
58 | \value AxisTypeBarCategory | |
67 | \value AxisTypeCategory |
|
59 | \value AxisTypeCategory | |
68 | \value AxisTypeDateTime |
|
60 | \value AxisTypeDateTime | |
69 | \value AxisTypeLogValue |
|
61 | \value AxisTypeLogValue | |
70 | */ |
|
62 | */ | |
71 |
|
63 | |||
72 | /*! |
|
64 | /*! | |
73 | *\fn void QAbstractAxis::type() const |
|
65 | *\fn void QAbstractAxis::type() const | |
74 | Returns the type of the axis |
|
66 | Returns the type of the axis | |
75 | */ |
|
67 | */ | |
76 |
|
68 | |||
77 | /*! |
|
69 | /*! | |
78 | \property QAbstractAxis::lineVisible |
|
70 | \property QAbstractAxis::lineVisible | |
79 | The visibility of the axis line |
|
71 | The visibility of the axis line | |
80 | */ |
|
72 | */ | |
81 | /*! |
|
73 | /*! | |
82 | \qmlproperty bool AbstractAxis::lineVisible |
|
74 | \qmlproperty bool AbstractAxis::lineVisible | |
83 | The visibility of the axis line |
|
75 | The visibility of the axis line | |
84 | */ |
|
76 | */ | |
85 |
|
77 | |||
86 | /*! |
|
78 | /*! | |
87 | \property QAbstractAxis::linePen |
|
79 | \property QAbstractAxis::linePen | |
88 | The pen of the line. |
|
80 | The pen of the line. | |
89 | */ |
|
81 | */ | |
90 |
|
82 | |||
91 | /*! |
|
83 | /*! | |
92 | \property QAbstractAxis::labelsVisible |
|
84 | \property QAbstractAxis::labelsVisible | |
93 | Defines if axis labels are visible. |
|
85 | Defines if axis labels are visible. | |
94 | */ |
|
86 | */ | |
95 | /*! |
|
87 | /*! | |
96 | \qmlproperty bool AbstractAxis::labelsVisible |
|
88 | \qmlproperty bool AbstractAxis::labelsVisible | |
97 | Defines if axis labels are visible. |
|
89 | Defines if axis labels are visible. | |
98 | */ |
|
90 | */ | |
99 |
|
91 | |||
100 | /*! |
|
92 | /*! | |
101 | \property QAbstractAxis::labelsPen |
|
93 | \property QAbstractAxis::labelsPen | |
102 | The pen of the labels. |
|
94 | The pen of the labels. | |
103 | */ |
|
95 | */ | |
104 |
|
96 | |||
105 | /*! |
|
97 | /*! | |
106 | \property QAbstractAxis::labelsBrush |
|
98 | \property QAbstractAxis::labelsBrush | |
107 | The brush of the labels. |
|
99 | The brush of the labels. | |
108 | */ |
|
100 | */ | |
109 |
|
101 | |||
110 | /*! |
|
102 | /*! | |
111 | \property QAbstractAxis::visible |
|
103 | \property QAbstractAxis::visible | |
112 | The visibility of the axis. |
|
104 | The visibility of the axis. | |
113 | */ |
|
105 | */ | |
114 | /*! |
|
106 | /*! | |
115 | \qmlproperty bool AbstractAxis::visible |
|
107 | \qmlproperty bool AbstractAxis::visible | |
116 | The visibility of the axis. |
|
108 | The visibility of the axis. | |
117 | */ |
|
109 | */ | |
118 |
|
110 | |||
119 | /*! |
|
111 | /*! | |
120 | \property QAbstractAxis::gridVisible |
|
112 | \property QAbstractAxis::gridVisible | |
121 | The visibility of the grid lines. |
|
113 | The visibility of the grid lines. | |
122 | */ |
|
114 | */ | |
123 | /*! |
|
115 | /*! | |
124 | \qmlproperty bool AbstractAxis::gridVisible |
|
116 | \qmlproperty bool AbstractAxis::gridVisible | |
125 | The visibility of the grid lines. |
|
117 | The visibility of the grid lines. | |
126 | */ |
|
118 | */ | |
127 |
|
119 | |||
128 | /*! |
|
120 | /*! | |
129 | \property QAbstractAxis::color |
|
121 | \property QAbstractAxis::color | |
130 | The color of the axis and ticks. |
|
122 | The color of the axis and ticks. | |
131 | */ |
|
123 | */ | |
132 | /*! |
|
124 | /*! | |
133 | \qmlproperty color AbstractAxis::color |
|
125 | \qmlproperty color AbstractAxis::color | |
134 | The color of the axis and ticks. |
|
126 | The color of the axis and ticks. | |
135 | */ |
|
127 | */ | |
136 |
|
128 | |||
137 | /*! |
|
129 | /*! | |
138 | \property QAbstractAxis::gridLinePen |
|
130 | \property QAbstractAxis::gridLinePen | |
139 | The pen of the grid line. |
|
131 | The pen of the grid line. | |
140 | */ |
|
132 | */ | |
141 |
|
133 | |||
142 | /*! |
|
134 | /*! | |
143 | \property QAbstractAxis::labelsFont |
|
135 | \property QAbstractAxis::labelsFont | |
144 | The font of the axis labels. |
|
136 | The font of the axis labels. | |
145 | */ |
|
137 | */ | |
146 |
|
138 | |||
147 | /*! |
|
139 | /*! | |
148 | \qmlproperty Font AbstractAxis::labelsFont |
|
140 | \qmlproperty Font AbstractAxis::labelsFont | |
149 | The font of the axis labels. |
|
141 | The font of the axis labels. | |
150 |
|
142 | |||
151 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
143 | See the \l {Font} {QML Font Element} for detailed documentation. | |
152 | */ |
|
144 | */ | |
153 |
|
145 | |||
154 | /*! |
|
146 | /*! | |
155 | \property QAbstractAxis::labelsColor |
|
147 | \property QAbstractAxis::labelsColor | |
156 | The color of the axis labels. |
|
148 | The color of the axis labels. | |
157 | */ |
|
149 | */ | |
158 | /*! |
|
150 | /*! | |
159 | \qmlproperty color AbstractAxis::labelsColor |
|
151 | \qmlproperty color AbstractAxis::labelsColor | |
160 | The color of the axis labels. |
|
152 | The color of the axis labels. | |
161 | */ |
|
153 | */ | |
162 |
|
154 | |||
163 | /*! |
|
155 | /*! | |
164 | \property QAbstractAxis::labelsAngle |
|
156 | \property QAbstractAxis::labelsAngle | |
165 | The angle of the axis labels in degrees. |
|
157 | The angle of the axis labels in degrees. | |
166 | */ |
|
158 | */ | |
167 | /*! |
|
159 | /*! | |
168 | \qmlproperty int AbstractAxis::labelsAngle |
|
160 | \qmlproperty int AbstractAxis::labelsAngle | |
169 | The angle of the axis labels in degrees. |
|
161 | The angle of the axis labels in degrees. | |
170 | */ |
|
162 | */ | |
171 |
|
163 | |||
172 | /*! |
|
164 | /*! | |
173 | \property QAbstractAxis::shadesVisible |
|
165 | \property QAbstractAxis::shadesVisible | |
174 | The visibility of the axis shades. |
|
166 | The visibility of the axis shades. | |
175 | */ |
|
167 | */ | |
176 | /*! |
|
168 | /*! | |
177 | \qmlproperty bool AbstractAxis::shadesVisible |
|
169 | \qmlproperty bool AbstractAxis::shadesVisible | |
178 | The visibility of the axis shades. |
|
170 | The visibility of the axis shades. | |
179 | */ |
|
171 | */ | |
180 |
|
172 | |||
181 | /*! |
|
173 | /*! | |
182 | \property QAbstractAxis::shadesColor |
|
174 | \property QAbstractAxis::shadesColor | |
183 | The fill (brush) color of the axis shades. |
|
175 | The fill (brush) color of the axis shades. | |
184 | */ |
|
176 | */ | |
185 | /*! |
|
177 | /*! | |
186 | \qmlproperty color AbstractAxis::shadesColor |
|
178 | \qmlproperty color AbstractAxis::shadesColor | |
187 | The fill (brush) color of the axis shades. |
|
179 | The fill (brush) color of the axis shades. | |
188 | */ |
|
180 | */ | |
189 |
|
181 | |||
190 | /*! |
|
182 | /*! | |
191 | \property QAbstractAxis::shadesBorderColor |
|
183 | \property QAbstractAxis::shadesBorderColor | |
192 | The border (pen) color of the axis shades. |
|
184 | The border (pen) color of the axis shades. | |
193 | */ |
|
185 | */ | |
194 | /*! |
|
186 | /*! | |
195 | \qmlproperty color AbstractAxis::shadesBorderColor |
|
187 | \qmlproperty color AbstractAxis::shadesBorderColor | |
196 | The border (pen) color of the axis shades. |
|
188 | The border (pen) color of the axis shades. | |
197 | */ |
|
189 | */ | |
198 |
|
190 | |||
199 | /*! |
|
191 | /*! | |
200 | \property QAbstractAxis::shadesPen |
|
192 | \property QAbstractAxis::shadesPen | |
201 | The pen of the axis shades (area between grid lines). |
|
193 | The pen of the axis shades (area between grid lines). | |
202 | */ |
|
194 | */ | |
203 |
|
195 | |||
204 | /*! |
|
196 | /*! | |
205 | \property QAbstractAxis::shadesBrush |
|
197 | \property QAbstractAxis::shadesBrush | |
206 | The brush of the axis shades (area between grid lines). |
|
198 | The brush of the axis shades (area between grid lines). | |
207 | */ |
|
199 | */ | |
208 |
|
200 | |||
209 | /*! |
|
201 | /*! | |
210 | \property QAbstractAxis::titleVisible |
|
202 | \property QAbstractAxis::titleVisible | |
211 | The visibility of the axis title. By default the value is true. |
|
203 | The visibility of the axis title. By default the value is true. | |
212 | */ |
|
204 | */ | |
213 | /*! |
|
205 | /*! | |
214 | \qmlproperty bool AbstractAxis::titleVisible |
|
206 | \qmlproperty bool AbstractAxis::titleVisible | |
215 | The visibility of the axis title. By default the value is true. |
|
207 | The visibility of the axis title. By default the value is true. | |
216 | */ |
|
208 | */ | |
217 |
|
209 | |||
218 | /*! |
|
210 | /*! | |
219 | \property QAbstractAxis::titleText |
|
211 | \property QAbstractAxis::titleText | |
220 | The title of the axis. Empty by default. |
|
212 | The title of the axis. Empty by default. | |
221 | */ |
|
213 | */ | |
222 | /*! |
|
214 | /*! | |
223 | \qmlproperty String AbstractAxis::titleText |
|
215 | \qmlproperty String AbstractAxis::titleText | |
224 | The title of the axis. Empty by default. |
|
216 | The title of the axis. Empty by default. | |
225 | */ |
|
217 | */ | |
226 |
|
218 | |||
227 | /*! |
|
219 | /*! | |
228 | \property QAbstractAxis::titlePen |
|
220 | \property QAbstractAxis::titlePen | |
229 | The pen of the title text. |
|
221 | The pen of the title text. | |
230 | */ |
|
222 | */ | |
231 |
|
223 | |||
232 | /*! |
|
224 | /*! | |
233 | \property QAbstractAxis::titleBrush |
|
225 | \property QAbstractAxis::titleBrush | |
234 | The brush of the title text. |
|
226 | The brush of the title text. | |
235 | */ |
|
227 | */ | |
236 |
|
228 | |||
237 | /*! |
|
229 | /*! | |
238 | \property QAbstractAxis::titleFont |
|
230 | \property QAbstractAxis::titleFont | |
239 | The font of the title of the axis. |
|
231 | The font of the title of the axis. | |
240 | */ |
|
232 | */ | |
241 | /*! |
|
233 | /*! | |
242 | \qmlproperty Font AbstractAxis::titleFont |
|
234 | \qmlproperty Font AbstractAxis::titleFont | |
243 | The font of the title of the axis. |
|
235 | The font of the title of the axis. | |
244 | */ |
|
236 | */ | |
245 |
|
237 | |||
246 | /*! |
|
238 | /*! | |
247 | \property QAbstractAxis::orientation |
|
239 | \property QAbstractAxis::orientation | |
248 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. |
|
240 | The orientation of the axis. Fixed to either Qt::Horizontal or Qt::Vertical when you add the axis to a chart. | |
249 | */ |
|
241 | */ | |
250 | /*! |
|
242 | /*! | |
251 | \qmlproperty Qt.Orientation AbstractAxis::orientation |
|
243 | \qmlproperty Qt.Orientation AbstractAxis::orientation | |
252 |
The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a |
|
244 | The orientation of the axis. Fixed to either Qt.Horizontal or Qt.Vertical when the axis is set to a series. | |
253 | */ |
|
245 | */ | |
254 |
|
246 | |||
255 | /*! |
|
247 | /*! | |
256 | \property QAbstractAxis::alignment |
|
248 | \property QAbstractAxis::alignment | |
257 | The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop. |
|
249 | The alignment of the axis. Can be Qt::AlignLeft, Qt::AlignRight, Qt::AlignBottom, or Qt::AlignTop. | |
258 | */ |
|
250 | */ | |
259 | /*! |
|
251 | /*! | |
260 | \qmlproperty alignment AbstractAxis::alignment |
|
252 | \qmlproperty alignment AbstractAxis::alignment | |
261 | The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop. |
|
253 | The alignment of the axis. Can be Qt.AlignLeft, Qt.AlignRight, Qt.AlignBottom, or Qt.AlignTop. | |
262 | */ |
|
254 | */ | |
263 |
|
255 | |||
264 | /*! |
|
256 | /*! | |
265 | \fn void QAbstractAxis::visibleChanged(bool visible) |
|
257 | \fn void QAbstractAxis::visibleChanged(bool visible) | |
266 | Visibility of the axis has changed to \a visible. |
|
258 | Visibility of the axis has changed to \a visible. | |
267 | */ |
|
259 | */ | |
268 | /*! |
|
260 | /*! | |
269 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) |
|
261 | \qmlsignal AbstractAxis::onVisibleChanged(bool visible) | |
270 | Visibility of the axis has changed to \a visible. |
|
262 | Visibility of the axis has changed to \a visible. | |
271 | */ |
|
263 | */ | |
272 |
|
264 | |||
273 | /*! |
|
265 | /*! | |
274 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) |
|
266 | \fn void QAbstractAxis::linePenChanged(const QPen& pen) | |
275 | The pen of the line of the axis has changed to \a pen. |
|
267 | The pen of the line of the axis has changed to \a pen. | |
276 | */ |
|
268 | */ | |
277 |
|
269 | |||
278 | /*! |
|
270 | /*! | |
279 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) |
|
271 | \fn void QAbstractAxis::lineVisibleChanged(bool visible) | |
280 | Visibility of the axis line has changed to \a visible. |
|
272 | Visibility of the axis line has changed to \a visible. | |
281 | */ |
|
273 | */ | |
282 | /*! |
|
274 | /*! | |
283 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) |
|
275 | \qmlsignal AbstractAxis::onLineVisibleChanged(bool visible) | |
284 | Visibility of the axis line has changed to \a visible. |
|
276 | Visibility of the axis line has changed to \a visible. | |
285 | */ |
|
277 | */ | |
286 |
|
278 | |||
287 | /*! |
|
279 | /*! | |
288 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) |
|
280 | \fn void QAbstractAxis::labelsVisibleChanged(bool visible) | |
289 | Visibility of the labels of the axis has changed to \a visible. |
|
281 | Visibility of the labels of the axis has changed to \a visible. | |
290 | */ |
|
282 | */ | |
291 | /*! |
|
283 | /*! | |
292 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) |
|
284 | \qmlsignal AbstractAxis::onLabelsVisibleChanged(bool visible) | |
293 | Visibility of the labels of the axis has changed to \a visible. |
|
285 | Visibility of the labels of the axis has changed to \a visible. | |
294 | */ |
|
286 | */ | |
295 |
|
287 | |||
296 | /*! |
|
288 | /*! | |
297 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) |
|
289 | \fn void QAbstractAxis::labelsFontChanged(const QFont& font) | |
298 | The font of the axis labels has changed to \a font. |
|
290 | The font of the axis labels has changed to \a font. | |
299 | */ |
|
291 | */ | |
300 | /*! |
|
292 | /*! | |
301 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) |
|
293 | \qmlsignal AbstractAxis::onLabelsFontChanged(Font font) | |
302 | The font of the axis labels has changed to \a font. |
|
294 | The font of the axis labels has changed to \a font. | |
303 | */ |
|
295 | */ | |
304 |
|
296 | |||
305 | /*! |
|
297 | /*! | |
306 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) |
|
298 | \fn void QAbstractAxis::labelsPenChanged(const QPen& pen) | |
307 | The pen of the axis labels has changed to \a pen. |
|
299 | The pen of the axis labels has changed to \a pen. | |
308 | */ |
|
300 | */ | |
309 |
|
301 | |||
310 | /*! |
|
302 | /*! | |
311 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) |
|
303 | \fn void QAbstractAxis::labelsBrushChanged(const QBrush& brush) | |
312 | The brush of the axis labels has changed to \a brush. |
|
304 | The brush of the axis labels has changed to \a brush. | |
313 | */ |
|
305 | */ | |
314 |
|
306 | |||
315 | /*! |
|
307 | /*! | |
316 | \fn void QAbstractAxis::labelsAngleChanged(int angle) |
|
308 | \fn void QAbstractAxis::labelsAngleChanged(int angle) | |
317 | The angle of the axis labels has changed to \a angle. |
|
309 | The angle of the axis labels has changed to \a angle. | |
318 | */ |
|
310 | */ | |
319 | /*! |
|
311 | /*! | |
320 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) |
|
312 | \qmlsignal AbstractAxis::onLabelsAngleChanged(int angle) | |
321 | The angle of the axis labels has changed to \a angle. |
|
313 | The angle of the axis labels has changed to \a angle. | |
322 | */ |
|
314 | */ | |
323 |
|
315 | |||
324 | /*! |
|
316 | /*! | |
325 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) |
|
317 | \fn void QAbstractAxis::gridVisibleChanged(bool visible) | |
326 | Visibility of the grid lines of the axis has changed to \a visible. |
|
318 | Visibility of the grid lines of the axis has changed to \a visible. | |
327 | */ |
|
319 | */ | |
328 | /*! |
|
320 | /*! | |
329 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) |
|
321 | \qmlsignal AbstractAxis::onGridVisibleChanged(bool visible) | |
330 | 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. | |
331 | */ |
|
323 | */ | |
332 |
|
324 | |||
333 | /*! |
|
325 | /*! | |
334 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) |
|
326 | \fn void QAbstractAxis::gridLinePenChanged(const QPen& pen) | |
335 | The pen of the grid line has changed to \a pen. |
|
327 | The pen of the grid line has changed to \a pen. | |
336 | */ |
|
328 | */ | |
337 |
|
329 | |||
338 | /*! |
|
330 | /*! | |
339 | \fn void QAbstractAxis::colorChanged(QColor color) |
|
331 | \fn void QAbstractAxis::colorChanged(QColor color) | |
340 | Emitted if the \a color of the axis is changed. |
|
332 | Emitted if the \a color of the axis is changed. | |
341 | */ |
|
333 | */ | |
342 | /*! |
|
334 | /*! | |
343 | \qmlsignal AbstractAxis::onColorChanged(QColor color) |
|
335 | \qmlsignal AbstractAxis::onColorChanged(QColor color) | |
344 | Emitted if the \a color of the axis is changed. |
|
336 | Emitted if the \a color of the axis is changed. | |
345 | */ |
|
337 | */ | |
346 |
|
338 | |||
347 | /*! |
|
339 | /*! | |
348 | \fn void QAbstractAxis::labelsColorChanged(QColor color) |
|
340 | \fn void QAbstractAxis::labelsColorChanged(QColor color) | |
349 | Emitted if the \a color of the axis labels is changed. |
|
341 | Emitted if the \a color of the axis labels is changed. | |
350 | */ |
|
342 | */ | |
351 | /*! |
|
343 | /*! | |
352 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) |
|
344 | \qmlsignal AbstractAxis::onLabelsColorChanged(QColor color) | |
353 | Emitted if the \a color of the axis labels is changed. |
|
345 | Emitted if the \a color of the axis labels is changed. | |
354 | */ |
|
346 | */ | |
355 |
|
347 | |||
356 | /*! |
|
348 | /*! | |
357 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) |
|
349 | \fn void QAbstractAxis::titleVisibleChanged(bool visible) | |
358 | Visibility of the title text of the axis has changed to \a visible. |
|
350 | Visibility of the title text of the axis has changed to \a visible. | |
359 | */ |
|
351 | */ | |
360 | /*! |
|
352 | /*! | |
361 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) |
|
353 | \qmlsignal AbstractAxis::onTitleVisibleChanged(bool visible) | |
362 | 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. | |
363 | */ |
|
355 | */ | |
364 |
|
356 | |||
365 | /*! |
|
357 | /*! | |
366 | \fn void QAbstractAxis::titleTextChanged(const QString& text) |
|
358 | \fn void QAbstractAxis::titleTextChanged(const QString& text) | |
367 | The text of the axis title has changed to \a text. |
|
359 | The text of the axis title has changed to \a text. | |
368 | */ |
|
360 | */ | |
369 | /*! |
|
361 | /*! | |
370 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) |
|
362 | \qmlsignal AbstractAxis::onTitleTextChanged(String text) | |
371 | The text of the axis title has changed to \a text. |
|
363 | The text of the axis title has changed to \a text. | |
372 | */ |
|
364 | */ | |
373 |
|
365 | |||
374 | /*! |
|
366 | /*! | |
375 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) |
|
367 | \fn void QAbstractAxis::titlePenChanged(const QPen& pen) | |
376 | The pen of the axis shades has changed to \a pen. |
|
368 | The pen of the axis shades has changed to \a pen. | |
377 | */ |
|
369 | */ | |
378 |
|
370 | |||
379 | /*! |
|
371 | /*! | |
380 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) |
|
372 | \fn void QAbstractAxis::titleBrushChanged(const QBrush& brush) | |
381 | The brush of the axis title has changed to \a brush. |
|
373 | The brush of the axis title has changed to \a brush. | |
382 | */ |
|
374 | */ | |
383 |
|
375 | |||
384 | /*! |
|
376 | /*! | |
385 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) |
|
377 | \fn void QAbstractAxis::titleFontChanged(const QFont& font) | |
386 | The font of the axis title has changed to \a font. |
|
378 | The font of the axis title has changed to \a font. | |
387 | */ |
|
379 | */ | |
388 | /*! |
|
380 | /*! | |
389 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) |
|
381 | \qmlsignal AbstractAxis::onTitleFontChanged(Font font) | |
390 | The font of the axis title has changed to \a font. |
|
382 | The font of the axis title has changed to \a font. | |
391 | */ |
|
383 | */ | |
392 |
|
384 | |||
393 | /*! |
|
385 | /*! | |
394 | \fn void QAbstractAxis::shadesVisibleChanged(bool) |
|
386 | \fn void QAbstractAxis::shadesVisibleChanged(bool) | |
395 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
387 | Emitted if the visibility of the axis shades is changed to \a visible. | |
396 | */ |
|
388 | */ | |
397 | /*! |
|
389 | /*! | |
398 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) |
|
390 | \qmlsignal AbstractAxis::onShadesVisibleChanged(bool visible) | |
399 | Emitted if the visibility of the axis shades is changed to \a visible. |
|
391 | Emitted if the visibility of the axis shades is changed to \a visible. | |
400 | */ |
|
392 | */ | |
401 |
|
393 | |||
402 | /*! |
|
394 | /*! | |
403 | \fn void QAbstractAxis::shadesColorChanged(QColor color) |
|
395 | \fn void QAbstractAxis::shadesColorChanged(QColor color) | |
404 | Emitted if the \a color of the axis shades is changed. |
|
396 | Emitted if the \a color of the axis shades is changed. | |
405 | */ |
|
397 | */ | |
406 | /*! |
|
398 | /*! | |
407 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) |
|
399 | \qmlsignal AbstractAxis::onShadesColorChanged(QColor color) | |
408 | Emitted if the \a color of the axis shades is changed. |
|
400 | Emitted if the \a color of the axis shades is changed. | |
409 | */ |
|
401 | */ | |
410 |
|
402 | |||
411 | /*! |
|
403 | /*! | |
412 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) |
|
404 | \fn void QAbstractAxis::shadesBorderColorChanged(QColor) | |
413 | Emitted if the border \a color of the axis shades is changed. |
|
405 | Emitted if the border \a color of the axis shades is changed. | |
414 | */ |
|
406 | */ | |
415 | /*! |
|
407 | /*! | |
416 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) |
|
408 | \qmlsignal AbstractAxis::onBorderColorChanged(QColor color) | |
417 | Emitted if the border \a color of the axis shades is changed. |
|
409 | Emitted if the border \a color of the axis shades is changed. | |
418 | */ |
|
410 | */ | |
419 |
|
411 | |||
420 | /*! |
|
412 | /*! | |
421 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) |
|
413 | \fn void QAbstractAxis::shadesBrushChanged(const QBrush& brush) | |
422 | The brush of the axis shades has changed to \a brush. |
|
414 | The brush of the axis shades has changed to \a brush. | |
423 | */ |
|
415 | */ | |
424 |
|
416 | |||
425 | /*! |
|
417 | /*! | |
426 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) |
|
418 | \fn void QAbstractAxis::shadesPenChanged(const QPen& pen) | |
427 | The pen of the axis shades has changed to \a pen. |
|
419 | The pen of the axis shades has changed to \a pen. | |
428 | */ |
|
420 | */ | |
429 |
|
421 | |||
430 | /*! |
|
422 | /*! | |
431 | \internal |
|
423 | \internal | |
432 | Constructs new axis object which is a child of \a parent. Ownership is taken by |
|
424 | Constructs new axis object which is a child of \a parent. Ownership is taken by | |
433 | QChart when axis added. |
|
425 | QChart when axis added. | |
434 | */ |
|
426 | */ | |
435 |
|
427 | |||
436 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) |
|
428 | QAbstractAxis::QAbstractAxis(QAbstractAxisPrivate &d, QObject *parent) | |
437 | : QObject(parent), |
|
429 | : QObject(parent), | |
438 | d_ptr(&d) |
|
430 | d_ptr(&d) | |
439 | { |
|
431 | { | |
440 | } |
|
432 | } | |
441 |
|
433 | |||
442 | /*! |
|
434 | /*! | |
443 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. |
|
435 | Destructor of the axis object. When axis is added to chart, chart object takes ownership. | |
444 | */ |
|
436 | */ | |
445 |
|
437 | |||
446 | QAbstractAxis::~QAbstractAxis() |
|
438 | QAbstractAxis::~QAbstractAxis() | |
447 | { |
|
439 | { | |
448 | if (d_ptr->m_chart) |
|
440 | if (d_ptr->m_chart) | |
449 | qFatal("Still binded axis detected !"); |
|
441 | qFatal("Still binded axis detected !"); | |
450 | } |
|
442 | } | |
451 |
|
443 | |||
452 | /*! |
|
444 | /*! | |
453 | Sets \a pen used to draw axis line and ticks. |
|
445 | Sets \a pen used to draw axis line and ticks. | |
454 | */ |
|
446 | */ | |
455 | void QAbstractAxis::setLinePen(const QPen &pen) |
|
447 | void QAbstractAxis::setLinePen(const QPen &pen) | |
456 | { |
|
448 | { | |
457 | if (d_ptr->m_axisPen != pen) { |
|
449 | if (d_ptr->m_axisPen != pen) { | |
458 | d_ptr->m_axisPen = pen; |
|
450 | d_ptr->m_axisPen = pen; | |
459 | emit linePenChanged(pen); |
|
451 | emit linePenChanged(pen); | |
460 | } |
|
452 | } | |
461 | } |
|
453 | } | |
462 |
|
454 | |||
463 | /*! |
|
455 | /*! | |
464 | Returns pen used to draw axis and ticks. |
|
456 | Returns pen used to draw axis and ticks. | |
465 | */ |
|
457 | */ | |
466 | QPen QAbstractAxis::linePen() const |
|
458 | QPen QAbstractAxis::linePen() const | |
467 | { |
|
459 | { | |
468 | return d_ptr->m_axisPen; |
|
460 | return d_ptr->m_axisPen; | |
469 | } |
|
461 | } | |
470 |
|
462 | |||
471 | //TODO: remove me 2.0 |
|
463 | //TODO: remove me 2.0 | |
472 | void QAbstractAxis::setLinePenColor(QColor color) |
|
464 | void QAbstractAxis::setLinePenColor(QColor color) | |
473 | { |
|
465 | { | |
474 | QPen p = d_ptr->m_axisPen; |
|
466 | QPen p = d_ptr->m_axisPen; | |
475 | if (p.color() != color) { |
|
467 | if (p.color() != color) { | |
476 | p.setColor(color); |
|
468 | p.setColor(color); | |
477 | setLinePen(p); |
|
469 | setLinePen(p); | |
478 | emit colorChanged(color); |
|
470 | emit colorChanged(color); | |
479 | } |
|
471 | } | |
480 | } |
|
472 | } | |
481 |
|
473 | |||
482 | QColor QAbstractAxis::linePenColor() const |
|
474 | QColor QAbstractAxis::linePenColor() const | |
483 | { |
|
475 | { | |
484 | return d_ptr->m_axisPen.color(); |
|
476 | return d_ptr->m_axisPen.color(); | |
485 | } |
|
477 | } | |
486 |
|
478 | |||
487 | /*! |
|
479 | /*! | |
488 | Sets if axis and ticks are \a visible. |
|
480 | Sets if axis and ticks are \a visible. | |
489 | */ |
|
481 | */ | |
490 | void QAbstractAxis::setLineVisible(bool visible) |
|
482 | void QAbstractAxis::setLineVisible(bool visible) | |
491 | { |
|
483 | { | |
492 | if (d_ptr->m_arrowVisible != visible) { |
|
484 | if (d_ptr->m_arrowVisible != visible) { | |
493 | d_ptr->m_arrowVisible = visible; |
|
485 | d_ptr->m_arrowVisible = visible; | |
494 | emit lineVisibleChanged(visible); |
|
486 | emit lineVisibleChanged(visible); | |
495 | } |
|
487 | } | |
496 | } |
|
488 | } | |
497 |
|
489 | |||
498 | bool QAbstractAxis::isLineVisible() const |
|
490 | bool QAbstractAxis::isLineVisible() const | |
499 | { |
|
491 | { | |
500 | return d_ptr->m_arrowVisible; |
|
492 | return d_ptr->m_arrowVisible; | |
501 | } |
|
493 | } | |
502 |
|
494 | |||
503 | void QAbstractAxis::setGridLineVisible(bool visible) |
|
495 | void QAbstractAxis::setGridLineVisible(bool visible) | |
504 | { |
|
496 | { | |
505 | if (d_ptr->m_gridLineVisible != visible) { |
|
497 | if (d_ptr->m_gridLineVisible != visible) { | |
506 | d_ptr->m_gridLineVisible = visible; |
|
498 | d_ptr->m_gridLineVisible = visible; | |
507 | emit gridVisibleChanged(visible); |
|
499 | emit gridVisibleChanged(visible); | |
508 | } |
|
500 | } | |
509 | } |
|
501 | } | |
510 |
|
502 | |||
511 | bool QAbstractAxis::isGridLineVisible() const |
|
503 | bool QAbstractAxis::isGridLineVisible() const | |
512 | { |
|
504 | { | |
513 | return d_ptr->m_gridLineVisible; |
|
505 | return d_ptr->m_gridLineVisible; | |
514 | } |
|
506 | } | |
515 |
|
507 | |||
516 | /*! |
|
508 | /*! | |
517 | Sets \a pen used to draw grid line. |
|
509 | Sets \a pen used to draw grid line. | |
518 | */ |
|
510 | */ | |
519 | void QAbstractAxis::setGridLinePen(const QPen &pen) |
|
511 | void QAbstractAxis::setGridLinePen(const QPen &pen) | |
520 | { |
|
512 | { | |
521 | if (d_ptr->m_gridLinePen != pen) { |
|
513 | if (d_ptr->m_gridLinePen != pen) { | |
522 | d_ptr->m_gridLinePen = pen; |
|
514 | d_ptr->m_gridLinePen = pen; | |
523 | emit gridLinePenChanged(pen); |
|
515 | emit gridLinePenChanged(pen); | |
524 | } |
|
516 | } | |
525 | } |
|
517 | } | |
526 |
|
518 | |||
527 | /*! |
|
519 | /*! | |
528 | Returns pen used to draw grid. |
|
520 | Returns pen used to draw grid. | |
529 | */ |
|
521 | */ | |
530 | QPen QAbstractAxis::gridLinePen() const |
|
522 | QPen QAbstractAxis::gridLinePen() const | |
531 | { |
|
523 | { | |
532 | return d_ptr->m_gridLinePen; |
|
524 | return d_ptr->m_gridLinePen; | |
533 | } |
|
525 | } | |
534 |
|
526 | |||
535 | void QAbstractAxis::setLabelsVisible(bool visible) |
|
527 | void QAbstractAxis::setLabelsVisible(bool visible) | |
536 | { |
|
528 | { | |
537 | if (d_ptr->m_labelsVisible != visible) { |
|
529 | if (d_ptr->m_labelsVisible != visible) { | |
538 | d_ptr->m_labelsVisible = visible; |
|
530 | d_ptr->m_labelsVisible = visible; | |
539 | emit labelsVisibleChanged(visible); |
|
531 | emit labelsVisibleChanged(visible); | |
540 | } |
|
532 | } | |
541 | } |
|
533 | } | |
542 |
|
534 | |||
543 | bool QAbstractAxis::labelsVisible() const |
|
535 | bool QAbstractAxis::labelsVisible() const | |
544 | { |
|
536 | { | |
545 | return d_ptr->m_labelsVisible; |
|
537 | return d_ptr->m_labelsVisible; | |
546 | } |
|
538 | } | |
547 |
|
539 | |||
548 | /*! |
|
540 | /*! | |
549 | Sets \a pen used to draw labels. |
|
541 | Sets \a pen used to draw labels. | |
550 | */ |
|
542 | */ | |
551 | void QAbstractAxis::setLabelsPen(const QPen &pen) |
|
543 | void QAbstractAxis::setLabelsPen(const QPen &pen) | |
552 | { |
|
544 | { | |
553 | if (d_ptr->m_labelsPen != pen) { |
|
545 | if (d_ptr->m_labelsPen != pen) { | |
554 | d_ptr->m_labelsPen = pen; |
|
546 | d_ptr->m_labelsPen = pen; | |
555 | emit labelsPenChanged(pen); |
|
547 | emit labelsPenChanged(pen); | |
556 | } |
|
548 | } | |
557 | } |
|
549 | } | |
558 |
|
550 | |||
559 | /*! |
|
551 | /*! | |
560 | Returns the pen used to labels. |
|
552 | Returns the pen used to labels. | |
561 | */ |
|
553 | */ | |
562 | QPen QAbstractAxis::labelsPen() const |
|
554 | QPen QAbstractAxis::labelsPen() const | |
563 | { |
|
555 | { | |
564 | return d_ptr->m_labelsPen; |
|
556 | return d_ptr->m_labelsPen; | |
565 | } |
|
557 | } | |
566 |
|
558 | |||
567 | /*! |
|
559 | /*! | |
568 | Sets \a brush used to draw labels. |
|
560 | Sets \a brush used to draw labels. | |
569 | */ |
|
561 | */ | |
570 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) |
|
562 | void QAbstractAxis::setLabelsBrush(const QBrush &brush) | |
571 | { |
|
563 | { | |
572 | if (d_ptr->m_labelsBrush != brush) { |
|
564 | if (d_ptr->m_labelsBrush != brush) { | |
573 | d_ptr->m_labelsBrush = brush; |
|
565 | d_ptr->m_labelsBrush = brush; | |
574 | emit labelsBrushChanged(brush); |
|
566 | emit labelsBrushChanged(brush); | |
575 | } |
|
567 | } | |
576 | } |
|
568 | } | |
577 |
|
569 | |||
578 | /*! |
|
570 | /*! | |
579 | Returns brush used to draw labels. |
|
571 | Returns brush used to draw labels. | |
580 | */ |
|
572 | */ | |
581 | QBrush QAbstractAxis::labelsBrush() const |
|
573 | QBrush QAbstractAxis::labelsBrush() const | |
582 | { |
|
574 | { | |
583 | return d_ptr->m_labelsBrush; |
|
575 | return d_ptr->m_labelsBrush; | |
584 | } |
|
576 | } | |
585 |
|
577 | |||
586 | /*! |
|
578 | /*! | |
587 | Sets \a font used to draw labels. |
|
579 | Sets \a font used to draw labels. | |
588 | */ |
|
580 | */ | |
589 | void QAbstractAxis::setLabelsFont(const QFont &font) |
|
581 | void QAbstractAxis::setLabelsFont(const QFont &font) | |
590 | { |
|
582 | { | |
591 | if (d_ptr->m_labelsFont != font) { |
|
583 | if (d_ptr->m_labelsFont != font) { | |
592 | d_ptr->m_labelsFont = font; |
|
584 | d_ptr->m_labelsFont = font; | |
593 | emit labelsFontChanged(font); |
|
585 | emit labelsFontChanged(font); | |
594 | } |
|
586 | } | |
595 | } |
|
587 | } | |
596 |
|
588 | |||
597 | /*! |
|
589 | /*! | |
598 | Returns font used to draw labels. |
|
590 | Returns font used to draw labels. | |
599 | */ |
|
591 | */ | |
600 | QFont QAbstractAxis::labelsFont() const |
|
592 | QFont QAbstractAxis::labelsFont() const | |
601 | { |
|
593 | { | |
602 | return d_ptr->m_labelsFont; |
|
594 | return d_ptr->m_labelsFont; | |
603 | } |
|
595 | } | |
604 |
|
596 | |||
605 | void QAbstractAxis::setLabelsAngle(int angle) |
|
597 | void QAbstractAxis::setLabelsAngle(int angle) | |
606 | { |
|
598 | { | |
607 | if (d_ptr->m_labelsAngle != angle) { |
|
599 | if (d_ptr->m_labelsAngle != angle) { | |
608 | d_ptr->m_labelsAngle = angle; |
|
600 | d_ptr->m_labelsAngle = angle; | |
609 | emit labelsAngleChanged(angle); |
|
601 | emit labelsAngleChanged(angle); | |
610 | } |
|
602 | } | |
611 | } |
|
603 | } | |
612 |
|
604 | |||
613 | int QAbstractAxis::labelsAngle() const |
|
605 | int QAbstractAxis::labelsAngle() const | |
614 | { |
|
606 | { | |
615 | return d_ptr->m_labelsAngle; |
|
607 | return d_ptr->m_labelsAngle; | |
616 | } |
|
608 | } | |
617 | //TODO: remove me 2.0 |
|
609 | //TODO: remove me 2.0 | |
618 | void QAbstractAxis::setLabelsColor(QColor color) |
|
610 | void QAbstractAxis::setLabelsColor(QColor color) | |
619 | { |
|
611 | { | |
620 | QBrush b = d_ptr->m_labelsBrush; |
|
612 | QBrush b = d_ptr->m_labelsBrush; | |
621 | if (b.color() != color) { |
|
613 | if (b.color() != color) { | |
622 | b.setColor(color); |
|
614 | b.setColor(color); | |
623 | setLabelsBrush(b); |
|
615 | setLabelsBrush(b); | |
624 | emit labelsColorChanged(color); |
|
616 | emit labelsColorChanged(color); | |
625 | } |
|
617 | } | |
626 | } |
|
618 | } | |
627 |
|
619 | |||
628 | QColor QAbstractAxis::labelsColor() const |
|
620 | QColor QAbstractAxis::labelsColor() const | |
629 | { |
|
621 | { | |
630 | return d_ptr->m_labelsBrush.color(); |
|
622 | return d_ptr->m_labelsBrush.color(); | |
631 | } |
|
623 | } | |
632 |
|
624 | |||
633 | void QAbstractAxis::setTitleVisible(bool visible) |
|
625 | void QAbstractAxis::setTitleVisible(bool visible) | |
634 | { |
|
626 | { | |
635 | if (d_ptr->m_titleVisible != visible) { |
|
627 | if (d_ptr->m_titleVisible != visible) { | |
636 | d_ptr->m_titleVisible = visible; |
|
628 | d_ptr->m_titleVisible = visible; | |
637 | emit titleVisibleChanged(visible); |
|
629 | emit titleVisibleChanged(visible); | |
638 | } |
|
630 | } | |
639 | } |
|
631 | } | |
640 |
|
632 | |||
641 | bool QAbstractAxis::isTitleVisible() const |
|
633 | bool QAbstractAxis::isTitleVisible() const | |
642 | { |
|
634 | { | |
643 | return d_ptr->m_titleVisible; |
|
635 | return d_ptr->m_titleVisible; | |
644 | } |
|
636 | } | |
645 |
|
637 | |||
646 | /*! |
|
638 | /*! | |
647 | Sets \a pen used to draw title. |
|
639 | Sets \a pen used to draw title. | |
648 | */ |
|
640 | */ | |
649 | void QAbstractAxis::setTitlePen(const QPen &pen) |
|
641 | void QAbstractAxis::setTitlePen(const QPen &pen) | |
650 | { |
|
642 | { | |
651 | if (d_ptr->m_titlePen != pen) { |
|
643 | if (d_ptr->m_titlePen != pen) { | |
652 | d_ptr->m_titlePen = pen; |
|
644 | d_ptr->m_titlePen = pen; | |
653 | emit titlePenChanged(pen); |
|
645 | emit titlePenChanged(pen); | |
654 | } |
|
646 | } | |
655 | } |
|
647 | } | |
656 |
|
648 | |||
657 | /*! |
|
649 | /*! | |
658 | Returns the pen used to title. |
|
650 | Returns the pen used to title. | |
659 | */ |
|
651 | */ | |
660 | QPen QAbstractAxis::titlePen() const |
|
652 | QPen QAbstractAxis::titlePen() const | |
661 | { |
|
653 | { | |
662 | return d_ptr->m_titlePen; |
|
654 | return d_ptr->m_titlePen; | |
663 | } |
|
655 | } | |
664 |
|
656 | |||
665 | /*! |
|
657 | /*! | |
666 | Sets \a brush used to draw title. |
|
658 | Sets \a brush used to draw title. | |
667 | */ |
|
659 | */ | |
668 | void QAbstractAxis::setTitleBrush(const QBrush &brush) |
|
660 | void QAbstractAxis::setTitleBrush(const QBrush &brush) | |
669 | { |
|
661 | { | |
670 | if (d_ptr->m_titleBrush != brush) { |
|
662 | if (d_ptr->m_titleBrush != brush) { | |
671 | d_ptr->m_titleBrush = brush; |
|
663 | d_ptr->m_titleBrush = brush; | |
672 | emit titleBrushChanged(brush); |
|
664 | emit titleBrushChanged(brush); | |
673 | } |
|
665 | } | |
674 | } |
|
666 | } | |
675 |
|
667 | |||
676 | /*! |
|
668 | /*! | |
677 | Returns brush used to draw title. |
|
669 | Returns brush used to draw title. | |
678 | */ |
|
670 | */ | |
679 | QBrush QAbstractAxis::titleBrush() const |
|
671 | QBrush QAbstractAxis::titleBrush() const | |
680 | { |
|
672 | { | |
681 | return d_ptr->m_titleBrush; |
|
673 | return d_ptr->m_titleBrush; | |
682 | } |
|
674 | } | |
683 |
|
675 | |||
684 | /*! |
|
676 | /*! | |
685 | Sets \a font used to draw title. |
|
677 | Sets \a font used to draw title. | |
686 | */ |
|
678 | */ | |
687 | void QAbstractAxis::setTitleFont(const QFont &font) |
|
679 | void QAbstractAxis::setTitleFont(const QFont &font) | |
688 | { |
|
680 | { | |
689 | if (d_ptr->m_titleFont != font) { |
|
681 | if (d_ptr->m_titleFont != font) { | |
690 | d_ptr->m_titleFont = font; |
|
682 | d_ptr->m_titleFont = font; | |
691 | emit titleFontChanged(font); |
|
683 | emit titleFontChanged(font); | |
692 | } |
|
684 | } | |
693 | } |
|
685 | } | |
694 |
|
686 | |||
695 | /*! |
|
687 | /*! | |
696 | Returns font used to draw title. |
|
688 | Returns font used to draw title. | |
697 | */ |
|
689 | */ | |
698 | QFont QAbstractAxis::titleFont() const |
|
690 | QFont QAbstractAxis::titleFont() const | |
699 | { |
|
691 | { | |
700 | return d_ptr->m_titleFont; |
|
692 | return d_ptr->m_titleFont; | |
701 | } |
|
693 | } | |
702 |
|
694 | |||
703 | void QAbstractAxis::setTitleText(const QString &title) |
|
695 | void QAbstractAxis::setTitleText(const QString &title) | |
704 | { |
|
696 | { | |
705 | if (d_ptr->m_title != title) { |
|
697 | if (d_ptr->m_title != title) { | |
706 | d_ptr->m_title = title; |
|
698 | d_ptr->m_title = title; | |
707 | emit titleTextChanged(title); |
|
699 | emit titleTextChanged(title); | |
708 | } |
|
700 | } | |
709 | } |
|
701 | } | |
710 |
|
702 | |||
711 | QString QAbstractAxis::titleText() const |
|
703 | QString QAbstractAxis::titleText() const | |
712 | { |
|
704 | { | |
713 | return d_ptr->m_title; |
|
705 | return d_ptr->m_title; | |
714 | } |
|
706 | } | |
715 |
|
707 | |||
716 |
|
708 | |||
717 | void QAbstractAxis::setShadesVisible(bool visible) |
|
709 | void QAbstractAxis::setShadesVisible(bool visible) | |
718 | { |
|
710 | { | |
719 | if (d_ptr->m_shadesVisible != visible) { |
|
711 | if (d_ptr->m_shadesVisible != visible) { | |
720 | d_ptr->m_shadesVisible = visible; |
|
712 | d_ptr->m_shadesVisible = visible; | |
721 | emit shadesVisibleChanged(visible); |
|
713 | emit shadesVisibleChanged(visible); | |
722 | } |
|
714 | } | |
723 | } |
|
715 | } | |
724 |
|
716 | |||
725 | bool QAbstractAxis::shadesVisible() const |
|
717 | bool QAbstractAxis::shadesVisible() const | |
726 | { |
|
718 | { | |
727 | return d_ptr->m_shadesVisible; |
|
719 | return d_ptr->m_shadesVisible; | |
728 | } |
|
720 | } | |
729 |
|
721 | |||
730 | /*! |
|
722 | /*! | |
731 | Sets \a pen used to draw shades. |
|
723 | Sets \a pen used to draw shades. | |
732 | */ |
|
724 | */ | |
733 | void QAbstractAxis::setShadesPen(const QPen &pen) |
|
725 | void QAbstractAxis::setShadesPen(const QPen &pen) | |
734 | { |
|
726 | { | |
735 | if (d_ptr->m_shadesPen != pen) { |
|
727 | if (d_ptr->m_shadesPen != pen) { | |
736 | d_ptr->m_shadesPen = pen; |
|
728 | d_ptr->m_shadesPen = pen; | |
737 | emit shadesPenChanged(pen); |
|
729 | emit shadesPenChanged(pen); | |
738 | } |
|
730 | } | |
739 | } |
|
731 | } | |
740 |
|
732 | |||
741 | /*! |
|
733 | /*! | |
742 | Returns pen used to draw shades. |
|
734 | Returns pen used to draw shades. | |
743 | */ |
|
735 | */ | |
744 | QPen QAbstractAxis::shadesPen() const |
|
736 | QPen QAbstractAxis::shadesPen() const | |
745 | { |
|
737 | { | |
746 | return d_ptr->m_shadesPen; |
|
738 | return d_ptr->m_shadesPen; | |
747 | } |
|
739 | } | |
748 |
|
740 | |||
749 | /*! |
|
741 | /*! | |
750 | Sets \a brush used to draw shades. |
|
742 | Sets \a brush used to draw shades. | |
751 | */ |
|
743 | */ | |
752 | void QAbstractAxis::setShadesBrush(const QBrush &brush) |
|
744 | void QAbstractAxis::setShadesBrush(const QBrush &brush) | |
753 | { |
|
745 | { | |
754 | if (d_ptr->m_shadesBrush != brush) { |
|
746 | if (d_ptr->m_shadesBrush != brush) { | |
755 | d_ptr->m_shadesBrush = brush; |
|
747 | d_ptr->m_shadesBrush = brush; | |
756 | emit shadesBrushChanged(brush); |
|
748 | emit shadesBrushChanged(brush); | |
757 | } |
|
749 | } | |
758 | } |
|
750 | } | |
759 |
|
751 | |||
760 | /*! |
|
752 | /*! | |
761 | Returns brush used to draw shades. |
|
753 | Returns brush used to draw shades. | |
762 | */ |
|
754 | */ | |
763 | QBrush QAbstractAxis::shadesBrush() const |
|
755 | QBrush QAbstractAxis::shadesBrush() const | |
764 | { |
|
756 | { | |
765 | return d_ptr->m_shadesBrush; |
|
757 | return d_ptr->m_shadesBrush; | |
766 | } |
|
758 | } | |
767 |
|
759 | |||
768 | void QAbstractAxis::setShadesColor(QColor color) |
|
760 | void QAbstractAxis::setShadesColor(QColor color) | |
769 | { |
|
761 | { | |
770 | QBrush b = d_ptr->m_shadesBrush; |
|
762 | QBrush b = d_ptr->m_shadesBrush; | |
771 | if (b.color() != color) { |
|
763 | if (b.color() != color) { | |
772 | b.setColor(color); |
|
764 | b.setColor(color); | |
773 | setShadesBrush(b); |
|
765 | setShadesBrush(b); | |
774 | emit shadesColorChanged(color); |
|
766 | emit shadesColorChanged(color); | |
775 | } |
|
767 | } | |
776 | } |
|
768 | } | |
777 |
|
769 | |||
778 | QColor QAbstractAxis::shadesColor() const |
|
770 | QColor QAbstractAxis::shadesColor() const | |
779 | { |
|
771 | { | |
780 | return d_ptr->m_shadesBrush.color(); |
|
772 | return d_ptr->m_shadesBrush.color(); | |
781 | } |
|
773 | } | |
782 |
|
774 | |||
783 | void QAbstractAxis::setShadesBorderColor(QColor color) |
|
775 | void QAbstractAxis::setShadesBorderColor(QColor color) | |
784 | { |
|
776 | { | |
785 | QPen p = d_ptr->m_shadesPen; |
|
777 | QPen p = d_ptr->m_shadesPen; | |
786 | if (p.color() != color) { |
|
778 | if (p.color() != color) { | |
787 | p.setColor(color); |
|
779 | p.setColor(color); | |
788 | setShadesPen(p); |
|
780 | setShadesPen(p); | |
789 | emit shadesColorChanged(color); |
|
781 | emit shadesColorChanged(color); | |
790 | } |
|
782 | } | |
791 | } |
|
783 | } | |
792 |
|
784 | |||
793 | QColor QAbstractAxis::shadesBorderColor() const |
|
785 | QColor QAbstractAxis::shadesBorderColor() const | |
794 | { |
|
786 | { | |
795 | return d_ptr->m_shadesPen.color(); |
|
787 | return d_ptr->m_shadesPen.color(); | |
796 | } |
|
788 | } | |
797 |
|
789 | |||
798 |
|
790 | |||
799 | bool QAbstractAxis::isVisible() const |
|
791 | bool QAbstractAxis::isVisible() const | |
800 | { |
|
792 | { | |
801 | return d_ptr->m_visible; |
|
793 | return d_ptr->m_visible; | |
802 | } |
|
794 | } | |
803 |
|
795 | |||
804 | /*! |
|
796 | /*! | |
805 | Sets axis, shades, labels and grid lines to be visible. |
|
797 | Sets axis, shades, labels and grid lines to be visible. | |
806 | */ |
|
798 | */ | |
807 | void QAbstractAxis::setVisible(bool visible) |
|
799 | void QAbstractAxis::setVisible(bool visible) | |
808 | { |
|
800 | { | |
809 | if (d_ptr->m_visible != visible) { |
|
801 | if (d_ptr->m_visible != visible) { | |
810 | d_ptr->m_visible = visible; |
|
802 | d_ptr->m_visible = visible; | |
811 | emit visibleChanged(visible); |
|
803 | emit visibleChanged(visible); | |
812 | } |
|
804 | } | |
813 | } |
|
805 | } | |
814 |
|
806 | |||
815 |
|
807 | |||
816 | /*! |
|
808 | /*! | |
817 | Sets axis, shades, labels and grid lines to be visible. |
|
809 | Sets axis, shades, labels and grid lines to be visible. | |
818 | */ |
|
810 | */ | |
819 | void QAbstractAxis::show() |
|
811 | void QAbstractAxis::show() | |
820 | { |
|
812 | { | |
821 | setVisible(true); |
|
813 | setVisible(true); | |
822 | } |
|
814 | } | |
823 |
|
815 | |||
824 | /*! |
|
816 | /*! | |
825 | Sets axis, shades, labels and grid lines to not be visible. |
|
817 | Sets axis, shades, labels and grid lines to not be visible. | |
826 | */ |
|
818 | */ | |
827 | void QAbstractAxis::hide() |
|
819 | void QAbstractAxis::hide() | |
828 | { |
|
820 | { | |
829 | setVisible(false); |
|
821 | setVisible(false); | |
830 | } |
|
822 | } | |
831 |
|
823 | |||
832 | /*! |
|
824 | /*! | |
833 | Sets the minimum value shown on the axis. |
|
825 | Sets the minimum value shown on the axis. | |
834 | Depending on the actual axis type the \a min parameter is converted to appropriate type. |
|
826 | Depending on the actual axis type the \a min parameter is converted to appropriate type. | |
835 | If the conversion is impossible then the function call does nothing |
|
827 | If the conversion is impossible then the function call does nothing | |
836 | */ |
|
828 | */ | |
837 | void QAbstractAxis::setMin(const QVariant &min) |
|
829 | void QAbstractAxis::setMin(const QVariant &min) | |
838 | { |
|
830 | { | |
839 | d_ptr->setMin(min); |
|
831 | d_ptr->setMin(min); | |
840 | } |
|
832 | } | |
841 |
|
833 | |||
842 | /*! |
|
834 | /*! | |
843 | Sets the maximum value shown on the axis. |
|
835 | Sets the maximum value shown on the axis. | |
844 | Depending on the actual axis type the \a max parameter is converted to appropriate type. |
|
836 | Depending on the actual axis type the \a max parameter is converted to appropriate type. | |
845 | If the conversion is impossible then the function call does nothing |
|
837 | If the conversion is impossible then the function call does nothing | |
846 | */ |
|
838 | */ | |
847 | void QAbstractAxis::setMax(const QVariant &max) |
|
839 | void QAbstractAxis::setMax(const QVariant &max) | |
848 | { |
|
840 | { | |
849 | d_ptr->setMax(max); |
|
841 | d_ptr->setMax(max); | |
850 | } |
|
842 | } | |
851 |
|
843 | |||
852 | /*! |
|
844 | /*! | |
853 | Sets the range shown on the axis. |
|
845 | Sets the range shown on the axis. | |
854 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. |
|
846 | Depending on the actual axis type the \a min and \a max parameters are converted to appropriate types. | |
855 | If the conversion is impossible then the function call does nothing. |
|
847 | If the conversion is impossible then the function call does nothing. | |
856 | */ |
|
848 | */ | |
857 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) |
|
849 | void QAbstractAxis::setRange(const QVariant &min, const QVariant &max) | |
858 | { |
|
850 | { | |
859 | d_ptr->setRange(min, max); |
|
851 | d_ptr->setRange(min, max); | |
860 | } |
|
852 | } | |
861 |
|
853 | |||
862 |
|
854 | |||
863 | /*! |
|
855 | /*! | |
864 | Returns the orientation in which the axis is being used (Vertical or Horizontal) |
|
856 | Returns the orientation in which the axis is being used (Vertical or Horizontal) | |
865 | */ |
|
857 | */ | |
866 | // NOTE: should have const but it breaks BC: |
|
858 | // NOTE: should have const but it breaks BC: | |
867 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function |
|
859 | // http://techbase.kde.org/Policies/Binary_Compatibility_Examples#Change_the_CV-qualifiers_of_a_member_function | |
868 | Qt::Orientation QAbstractAxis::orientation() |
|
860 | Qt::Orientation QAbstractAxis::orientation() | |
869 | { |
|
861 | { | |
870 | return d_ptr->orientation(); |
|
862 | return d_ptr->orientation(); | |
871 | } |
|
863 | } | |
872 |
|
864 | |||
873 | Qt::Alignment QAbstractAxis::alignment() const |
|
865 | Qt::Alignment QAbstractAxis::alignment() const | |
874 | { |
|
866 | { | |
875 | return d_ptr->alignment(); |
|
867 | return d_ptr->alignment(); | |
876 | } |
|
868 | } | |
877 |
|
869 | |||
878 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
870 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
879 |
|
871 | |||
880 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) |
|
872 | QAbstractAxisPrivate::QAbstractAxisPrivate(QAbstractAxis *q) | |
881 | : q_ptr(q), |
|
873 | : q_ptr(q), | |
882 | m_chart(0), |
|
874 | m_chart(0), | |
883 | m_alignment(0), |
|
875 | m_alignment(0), | |
884 | m_orientation(Qt::Orientation(0)), |
|
876 | m_orientation(Qt::Orientation(0)), | |
885 | m_visible(true), |
|
877 | m_visible(true), | |
886 | m_arrowVisible(true), |
|
878 | m_arrowVisible(true), | |
887 | m_gridLineVisible(true), |
|
879 | m_gridLineVisible(true), | |
888 | m_labelsVisible(true), |
|
880 | m_labelsVisible(true), | |
889 | m_labelsAngle(0), |
|
881 | m_labelsAngle(0), | |
890 | m_titleVisible(true), |
|
882 | m_titleVisible(true), | |
891 | m_shadesVisible(false), |
|
883 | m_shadesVisible(false), | |
892 | m_shadesBrush(Qt::SolidPattern), |
|
884 | m_shadesBrush(Qt::SolidPattern), | |
893 | m_shadesOpacity(1.0), |
|
885 | m_shadesOpacity(1.0), | |
894 | m_dirty(false) |
|
886 | m_dirty(false) | |
895 | { |
|
887 | { | |
896 |
|
888 | |||
897 | } |
|
889 | } | |
898 |
|
890 | |||
899 | QAbstractAxisPrivate::~QAbstractAxisPrivate() |
|
891 | QAbstractAxisPrivate::~QAbstractAxisPrivate() | |
900 | { |
|
892 | { | |
901 | } |
|
893 | } | |
902 |
|
894 | |||
903 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) |
|
895 | void QAbstractAxisPrivate::setAlignment( Qt::Alignment alignment) | |
904 | { |
|
896 | { | |
905 | switch(alignment) { |
|
897 | switch(alignment) { | |
906 | case Qt::AlignTop: |
|
898 | case Qt::AlignTop: | |
907 | case Qt::AlignBottom: |
|
899 | case Qt::AlignBottom: | |
908 | m_orientation = Qt::Horizontal; |
|
900 | m_orientation = Qt::Horizontal; | |
909 | break; |
|
901 | break; | |
910 | case Qt::AlignLeft: |
|
902 | case Qt::AlignLeft: | |
911 | case Qt::AlignRight: |
|
903 | case Qt::AlignRight: | |
912 | m_orientation = Qt::Vertical; |
|
904 | m_orientation = Qt::Vertical; | |
913 | break; |
|
905 | break; | |
914 | default: |
|
906 | default: | |
915 | qWarning()<<"No alignment specified !"; |
|
907 | qWarning()<<"No alignment specified !"; | |
916 | break; |
|
908 | break; | |
917 | }; |
|
909 | }; | |
918 | m_alignment=alignment; |
|
910 | m_alignment=alignment; | |
919 | } |
|
911 | } | |
920 |
|
912 | |||
921 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) |
|
913 | void QAbstractAxisPrivate::initializeTheme(ChartTheme* theme, bool forced) | |
922 | { |
|
914 | { | |
923 | QPen pen; |
|
915 | QPen pen; | |
924 | QBrush brush; |
|
916 | QBrush brush; | |
925 | QFont font; |
|
917 | QFont font; | |
926 |
|
918 | |||
927 | bool axisX = m_orientation == Qt::Horizontal; |
|
919 | bool axisX = m_orientation == Qt::Horizontal; | |
928 |
|
920 | |||
929 | //TODO: introduce axis brush |
|
921 | //TODO: introduce axis brush | |
930 | if (m_visible) { |
|
922 | if (m_visible) { | |
931 | if (m_arrowVisible) { |
|
923 | if (m_arrowVisible) { | |
932 | if (forced || pen == m_axisPen) { |
|
924 | if (forced || pen == m_axisPen) { | |
933 | q_ptr->setLinePen(theme->axisLinePen()); |
|
925 | q_ptr->setLinePen(theme->axisLinePen()); | |
934 | } |
|
926 | } | |
935 | } |
|
927 | } | |
936 | if (m_gridLineVisible) { |
|
928 | if (m_gridLineVisible) { | |
937 | if (forced || pen == m_gridLinePen) { |
|
929 | if (forced || pen == m_gridLinePen) { | |
938 | q_ptr->setGridLinePen(theme->girdLinePen()); |
|
930 | q_ptr->setGridLinePen(theme->girdLinePen()); | |
939 | } |
|
931 | } | |
940 | } |
|
932 | } | |
941 | if (m_labelsVisible) { |
|
933 | if (m_labelsVisible) { | |
942 | if (forced || brush == m_labelsBrush){ |
|
934 | if (forced || brush == m_labelsBrush){ | |
943 | q_ptr->setLabelsBrush(theme->labelBrush()); |
|
935 | q_ptr->setLabelsBrush(theme->labelBrush()); | |
944 | } |
|
936 | } | |
945 | if (forced || pen == m_labelsPen){ |
|
937 | if (forced || pen == m_labelsPen){ | |
946 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons |
|
938 | q_ptr->setLabelsPen(Qt::NoPen);// NoPen for performance reasons | |
947 | } |
|
939 | } | |
948 | if (forced || font == m_labelsFont){ |
|
940 | if (forced || font == m_labelsFont){ | |
949 | q_ptr->setLabelsFont(theme->labelFont()); |
|
941 | q_ptr->setLabelsFont(theme->labelFont()); | |
950 | } |
|
942 | } | |
951 | } |
|
943 | } | |
952 | if (m_titleVisible) { |
|
944 | if (m_titleVisible) { | |
953 | if (forced || brush == m_titleBrush){ |
|
945 | if (forced || brush == m_titleBrush){ | |
954 | q_ptr->setTitleBrush(theme->labelBrush()); |
|
946 | q_ptr->setTitleBrush(theme->labelBrush()); | |
955 | } |
|
947 | } | |
956 | if (forced || pen == m_titlePen){ |
|
948 | if (forced || pen == m_titlePen){ | |
957 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons |
|
949 | q_ptr->setTitlePen(Qt::NoPen);// Noen for performance reasons | |
958 | } |
|
950 | } | |
959 | if (forced || font == m_titleFont){ |
|
951 | if (forced || font == m_titleFont){ | |
960 | QFont font(m_labelsFont); |
|
952 | QFont font(m_labelsFont); | |
961 | font.setBold(true); |
|
953 | font.setBold(true); | |
962 | q_ptr->setTitleFont(font); |
|
954 | q_ptr->setTitleFont(font); | |
963 | } |
|
955 | } | |
964 | } |
|
956 | } | |
965 | if (forced || m_shadesVisible) { |
|
957 | if (forced || m_shadesVisible) { | |
966 | if (forced || brush == m_shadesBrush){ |
|
958 | if (forced || brush == m_shadesBrush){ | |
967 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); |
|
959 | q_ptr->setShadesBrush(theme->backgroundShadesBrush()); | |
968 | } |
|
960 | } | |
969 | if (forced || pen == m_shadesPen){ |
|
961 | if (forced || pen == m_shadesPen){ | |
970 | q_ptr->setShadesPen(theme->backgroundShadesPen()); |
|
962 | q_ptr->setShadesPen(theme->backgroundShadesPen()); | |
971 | } |
|
963 | } | |
972 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth |
|
964 | if (forced && (theme->backgroundShades() == ChartTheme::BackgroundShadesBoth | |
973 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) |
|
965 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesVertical && axisX) | |
974 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { |
|
966 | || (theme->backgroundShades() == ChartTheme::BackgroundShadesHorizontal && !axisX))) { | |
975 | q_ptr->setShadesVisible(true); |
|
967 | q_ptr->setShadesVisible(true); | |
976 | } |
|
968 | } | |
977 | } |
|
969 | } | |
978 | } |
|
970 | } | |
979 | } |
|
971 | } | |
980 |
|
972 | |||
981 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) |
|
973 | void QAbstractAxisPrivate::handleRangeChanged(qreal min, qreal max) | |
982 | { |
|
974 | { | |
983 | setRange(min,max); |
|
975 | setRange(min,max); | |
984 | } |
|
976 | } | |
985 |
|
977 | |||
986 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) |
|
978 | void QAbstractAxisPrivate::initializeGraphics(QGraphicsItem* parent) | |
987 | { |
|
979 | { | |
988 | Q_UNUSED(parent); |
|
980 | Q_UNUSED(parent); | |
989 | } |
|
981 | } | |
990 |
|
982 | |||
991 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
983 | void QAbstractAxisPrivate::initializeAnimations(QChart::AnimationOptions options) | |
992 | { |
|
984 | { | |
993 | ChartAxisElement *axis = m_item.data(); |
|
985 | ChartAxisElement *axis = m_item.data(); | |
994 | Q_ASSERT(axis); |
|
986 | Q_ASSERT(axis); | |
995 | if (options.testFlag(QChart::GridAxisAnimations)) { |
|
987 | if (options.testFlag(QChart::GridAxisAnimations)) { | |
996 | axis->setAnimation(new AxisAnimation(axis)); |
|
988 | axis->setAnimation(new AxisAnimation(axis)); | |
997 | } else { |
|
989 | } else { | |
998 | axis->setAnimation(0); |
|
990 | axis->setAnimation(0); | |
999 | } |
|
991 | } | |
1000 | } |
|
992 | } | |
1001 |
|
993 | |||
1002 |
|
994 | |||
1003 |
|
995 | |||
1004 | #include "moc_qabstractaxis.cpp" |
|
996 | #include "moc_qabstractaxis.cpp" | |
1005 | #include "moc_qabstractaxis_p.cpp" |
|
997 | #include "moc_qabstractaxis_p.cpp" | |
1006 |
|
998 | |||
1007 | QTCOMMERCIALCHART_END_NAMESPACE |
|
999 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,435 +1,435 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qvalueaxis.h" |
|
21 | #include "qvalueaxis.h" | |
22 | #include "qvalueaxis_p.h" |
|
22 | #include "qvalueaxis_p.h" | |
23 | #include "chartvalueaxisx_p.h" |
|
23 | #include "chartvalueaxisx_p.h" | |
24 | #include "chartvalueaxisy_p.h" |
|
24 | #include "chartvalueaxisy_p.h" | |
25 | #include "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "polarchartvalueaxisangular_p.h" |
|
26 | #include "polarchartvalueaxisangular_p.h" | |
27 | #include "polarchartvalueaxisradial_p.h" |
|
27 | #include "polarchartvalueaxisradial_p.h" | |
28 | #include "chartdataset_p.h" |
|
28 | #include "chartdataset_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "charttheme_p.h" |
|
30 | #include "charttheme_p.h" | |
31 |
|
31 | |||
32 |
|
32 | |||
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
34 | /*! |
|
34 | /*! | |
35 | \class QValueAxis |
|
35 | \class QValueAxis | |
36 | \brief The QValueAxis class is used for manipulating chart's axis. |
|
36 | \brief The QValueAxis class is used for manipulating chart's axis. | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
39 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
40 | Values of axis are drawn to position of ticks. |
|
40 | Values of axis are drawn to position of ticks. | |
41 |
|
41 | |||
42 | Example code on how to use QValueAxis. |
|
42 | Example code on how to use QValueAxis. | |
43 | \code |
|
43 | \code | |
44 | QChartView *chartView = new QChartView; |
|
44 | QChartView *chartView = new QChartView; | |
45 | QLineSeries *series = new QLineSeries; |
|
45 | QLineSeries *series = new QLineSeries; | |
46 | // ... |
|
46 | // ... | |
47 | chartView->chart()->addSeries(series); |
|
47 | chartView->chart()->addSeries(series); | |
48 |
|
48 | |||
49 | QValueAxis *axisX = new QValueAxis; |
|
49 | QValueAxis *axisX = new QValueAxis; | |
50 | axisX->setRange(10, 20.5); |
|
50 | axisX->setRange(10, 20.5); | |
51 | axisX->setTickCount(10); |
|
51 | axisX->setTickCount(10); | |
52 | axisX->setLabelFormat("%.2f"); |
|
52 | axisX->setLabelFormat("%.2f"); | |
53 | chartView->chart()->setAxisX(axisX, series); |
|
53 | chartView->chart()->setAxisX(axisX, series); | |
54 | \endcode |
|
54 | \endcode | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \qmlclass ValueAxis QValueAxis |
|
58 | \qmlclass ValueAxis QValueAxis | |
59 | \inherits AbstractAxis |
|
59 | \inherits AbstractAxis | |
60 | \brief The ValueAxis element is used for manipulating chart's axes |
|
60 | \brief The ValueAxis element is used for manipulating chart's axes | |
61 |
|
61 | |||
62 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. |
|
62 | ValueAxis can be setup to show axis line with tick marks, grid lines and shades. | |
63 | Values of axis are drawn to position of ticks |
|
63 | Values of axis are drawn to position of ticks | |
64 |
|
64 | |||
65 | To access Axes you can use ChartView API. For example: |
|
65 | Example about using ValueAxis: | |
66 | \code |
|
66 | \code | |
67 | ChartView { |
|
67 | ChartView { | |
68 | ValueAxis { |
|
68 | ValueAxis { | |
69 | id: xAxis |
|
69 | id: xAxis | |
70 | min: 0 |
|
70 | min: 0 | |
71 | max: 10 |
|
71 | max: 10 | |
72 | } |
|
72 | } | |
73 | // Add a few series... |
|
73 | // Add a few series... | |
74 | } |
|
74 | } | |
75 | \endcode |
|
75 | \endcode | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QValueAxis::min |
|
79 | \property QValueAxis::min | |
80 | Defines the minimum value on the axis. |
|
80 | Defines the minimum value on the axis. | |
81 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
81 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
82 | */ |
|
82 | */ | |
83 | /*! |
|
83 | /*! | |
84 | \qmlproperty real ValueAxis::min |
|
84 | \qmlproperty real ValueAxis::min | |
85 | Defines the minimum value on the axis. |
|
85 | Defines the minimum value on the axis. | |
86 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. |
|
86 | When setting this property the max is adjusted if necessary, to ensure that the range remains valid. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QValueAxis::max |
|
90 | \property QValueAxis::max | |
91 | Defines the maximum value on the axis. |
|
91 | Defines the maximum value on the axis. | |
92 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
92 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
93 | */ |
|
93 | */ | |
94 | /*! |
|
94 | /*! | |
95 | \qmlproperty real ValueAxis::max |
|
95 | \qmlproperty real ValueAxis::max | |
96 | Defines the maximum value on the axis. |
|
96 | Defines the maximum value on the axis. | |
97 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. |
|
97 | When setting this property the min is adjusted if necessary, to ensure that the range remains valid. | |
98 | */ |
|
98 | */ | |
99 |
|
99 | |||
100 | /*! |
|
100 | /*! | |
101 | \property QValueAxis::tickCount |
|
101 | \property QValueAxis::tickCount | |
102 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. |
|
102 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. | |
103 | The default value is 5, and it can not be below 2. |
|
103 | The default value is 5, and it can not be below 2. | |
104 | */ |
|
104 | */ | |
105 | /*! |
|
105 | /*! | |
106 | \qmlproperty real ValueAxis::tickCount |
|
106 | \qmlproperty real ValueAxis::tickCount | |
107 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. |
|
107 | Defines the number of ticks on the axis. This indicates how many grid lines are draw on the chart. | |
108 | The default value is 5, and it can not be below 2. |
|
108 | The default value is 5, and it can not be below 2. | |
109 | */ |
|
109 | */ | |
110 |
|
110 | |||
111 | /*! |
|
111 | /*! | |
112 | \property QValueAxis::labelFormat |
|
112 | \property QValueAxis::labelFormat | |
113 | Defines the label format of the axis. |
|
113 | Defines the label format of the axis. | |
114 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
114 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c | |
115 | See QString::sprintf() for additional details. |
|
115 | See QString::sprintf() for additional details. | |
116 | */ |
|
116 | */ | |
117 | /*! |
|
117 | /*! | |
118 | \qmlproperty real ValueAxis::labelFormat |
|
118 | \qmlproperty real ValueAxis::labelFormat | |
119 | Defines the label format of the axis. |
|
119 | Defines the label format of the axis. | |
120 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c |
|
120 | Supported specifiers are: d, i, o, x, X, f, F, e, E, g, G, c | |
121 | See QString::sprintf() for additional details. |
|
121 | See QString::sprintf() for additional details. | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \fn void QValueAxis::minChanged(qreal min) |
|
125 | \fn void QValueAxis::minChanged(qreal min) | |
126 | Axis emits signal when \a min of axis has changed. |
|
126 | Axis emits signal when \a min of axis has changed. | |
127 | */ |
|
127 | */ | |
128 | /*! |
|
128 | /*! | |
129 | \qmlsignal ValueAxis::onMinChanged(real min) |
|
129 | \qmlsignal ValueAxis::onMinChanged(real min) | |
130 | Axis emits signal when \a min of axis has changed. |
|
130 | Axis emits signal when \a min of axis has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QValueAxis::maxChanged(qreal max) |
|
134 | \fn void QValueAxis::maxChanged(qreal max) | |
135 | Axis emits signal when \a max of axis has changed. |
|
135 | Axis emits signal when \a max of axis has changed. | |
136 | */ |
|
136 | */ | |
137 | /*! |
|
137 | /*! | |
138 | \qmlsignal ValueAxis::onMaxChanged(real max) |
|
138 | \qmlsignal ValueAxis::onMaxChanged(real max) | |
139 | Axis emits signal when \a max of axis has changed. |
|
139 | Axis emits signal when \a max of axis has changed. | |
140 | */ |
|
140 | */ | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \fn void QValueAxis::tickCountChanged(int tickCount) |
|
143 | \fn void QValueAxis::tickCountChanged(int tickCount) | |
144 |
Axis emits signal when \a tickCount |
|
144 | Axis emits signal when \a tickCount of axis has changed. | |
145 | */ |
|
145 | */ | |
146 | /*! |
|
146 | /*! | |
147 | \qmlsignal ValueAxis::tickCountChanged(int tickCount) |
|
147 | \qmlsignal ValueAxis::tickCountChanged(int tickCount) | |
148 |
Axis emits signal when \a tickCount |
|
148 | Axis emits signal when \a tickCount of axis has changed. | |
149 | */ |
|
149 | */ | |
150 |
|
150 | |||
151 | /*! |
|
151 | /*! | |
152 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) |
|
152 | \fn void QValueAxis::rangeChanged(qreal min, qreal max) | |
153 | Axis emits signal when \a min or \a max of axis has changed. |
|
153 | Axis emits signal when \a min or \a max of axis has changed. | |
154 | */ |
|
154 | */ | |
155 |
|
155 | |||
156 | /*! |
|
156 | /*! | |
157 | \fn void QValueAxis::labelFormatChanged(const QString &format) |
|
157 | \fn void QValueAxis::labelFormatChanged(const QString &format) | |
158 | Axis emits signal when \a format of axis labels has changed. |
|
158 | Axis emits signal when \a format of axis labels has changed. | |
159 | */ |
|
159 | */ | |
160 | /*! |
|
160 | /*! | |
161 | \qmlsignal ValueAxis::labelFormatChanged(const QString &format) |
|
161 | \qmlsignal ValueAxis::labelFormatChanged(const QString &format) | |
162 |
|
|
162 | Axis emits signal when \a format of axis labels has changed. | |
163 | */ |
|
163 | */ | |
164 |
|
164 | |||
165 | /*! |
|
165 | /*! | |
166 | \property QValueAxis::niceNumbersEnabled |
|
166 | \property QValueAxis::niceNumbersEnabled | |
167 | \obsolete |
|
167 | \obsolete | |
168 | Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. |
|
168 | Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. | |
169 | */ |
|
169 | */ | |
170 |
|
170 | |||
171 | /*! |
|
171 | /*! | |
172 | \qmlproperty bool ValueAxis::niceNumbersEnabled |
|
172 | \qmlproperty bool ValueAxis::niceNumbersEnabled | |
173 | \obsolete |
|
173 | \obsolete | |
174 | Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. |
|
174 | Using this function can lead to unexpected behavior. Use applyNiceNumbers() instead. | |
175 | */ |
|
175 | */ | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | Constructs an axis object which is a child of \a parent. |
|
178 | Constructs an axis object which is a child of \a parent. | |
179 | */ |
|
179 | */ | |
180 | QValueAxis::QValueAxis(QObject *parent) : |
|
180 | QValueAxis::QValueAxis(QObject *parent) : | |
181 | QAbstractAxis(*new QValueAxisPrivate(this), parent) |
|
181 | QAbstractAxis(*new QValueAxisPrivate(this), parent) | |
182 | { |
|
182 | { | |
183 |
|
183 | |||
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | /*! |
|
186 | /*! | |
187 | \internal |
|
187 | \internal | |
188 | */ |
|
188 | */ | |
189 | QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) |
|
189 | QValueAxis::QValueAxis(QValueAxisPrivate &d, QObject *parent) | |
190 | : QAbstractAxis(d, parent) |
|
190 | : QAbstractAxis(d, parent) | |
191 | { |
|
191 | { | |
192 |
|
192 | |||
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Destroys the object |
|
196 | Destroys the object | |
197 | */ |
|
197 | */ | |
198 | QValueAxis::~QValueAxis() |
|
198 | QValueAxis::~QValueAxis() | |
199 | { |
|
199 | { | |
200 | Q_D(QValueAxis); |
|
200 | Q_D(QValueAxis); | |
201 | if (d->m_chart) |
|
201 | if (d->m_chart) | |
202 | d->m_chart->removeAxis(this); |
|
202 | d->m_chart->removeAxis(this); | |
203 | } |
|
203 | } | |
204 |
|
204 | |||
205 | void QValueAxis::setMin(qreal min) |
|
205 | void QValueAxis::setMin(qreal min) | |
206 | { |
|
206 | { | |
207 | Q_D(QValueAxis); |
|
207 | Q_D(QValueAxis); | |
208 | setRange(min, qMax(d->m_max, min)); |
|
208 | setRange(min, qMax(d->m_max, min)); | |
209 | } |
|
209 | } | |
210 |
|
210 | |||
211 | qreal QValueAxis::min() const |
|
211 | qreal QValueAxis::min() const | |
212 | { |
|
212 | { | |
213 | Q_D(const QValueAxis); |
|
213 | Q_D(const QValueAxis); | |
214 | return d->m_min; |
|
214 | return d->m_min; | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | void QValueAxis::setMax(qreal max) |
|
217 | void QValueAxis::setMax(qreal max) | |
218 | { |
|
218 | { | |
219 | Q_D(QValueAxis); |
|
219 | Q_D(QValueAxis); | |
220 | setRange(qMin(d->m_min, max), max); |
|
220 | setRange(qMin(d->m_min, max), max); | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | qreal QValueAxis::max() const |
|
223 | qreal QValueAxis::max() const | |
224 | { |
|
224 | { | |
225 | Q_D(const QValueAxis); |
|
225 | Q_D(const QValueAxis); | |
226 | return d->m_max; |
|
226 | return d->m_max; | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | /*! |
|
229 | /*! | |
230 | Sets range from \a min to \a max on the axis. |
|
230 | Sets range from \a min to \a max on the axis. | |
231 | If min is greater than max then this function returns without making any changes. |
|
231 | If min is greater than max then this function returns without making any changes. | |
232 | */ |
|
232 | */ | |
233 | void QValueAxis::setRange(qreal min, qreal max) |
|
233 | void QValueAxis::setRange(qreal min, qreal max) | |
234 | { |
|
234 | { | |
235 | Q_D(QValueAxis); |
|
235 | Q_D(QValueAxis); | |
236 | d->setRange(min,max); |
|
236 | d->setRange(min,max); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | void QValueAxis::setTickCount(int count) |
|
239 | void QValueAxis::setTickCount(int count) | |
240 | { |
|
240 | { | |
241 | Q_D(QValueAxis); |
|
241 | Q_D(QValueAxis); | |
242 | if (d->m_tickCount != count && count >= 2) { |
|
242 | if (d->m_tickCount != count && count >= 2) { | |
243 | d->m_tickCount = count; |
|
243 | d->m_tickCount = count; | |
244 | emit tickCountChanged(count); |
|
244 | emit tickCountChanged(count); | |
245 | } |
|
245 | } | |
246 | } |
|
246 | } | |
247 |
|
247 | |||
248 | int QValueAxis::tickCount() const |
|
248 | int QValueAxis::tickCount() const | |
249 | { |
|
249 | { | |
250 | Q_D(const QValueAxis); |
|
250 | Q_D(const QValueAxis); | |
251 | return d->m_tickCount; |
|
251 | return d->m_tickCount; | |
252 | } |
|
252 | } | |
253 |
|
253 | |||
254 | void QValueAxis::setNiceNumbersEnabled(bool enable) |
|
254 | void QValueAxis::setNiceNumbersEnabled(bool enable) | |
255 | { |
|
255 | { | |
256 | Q_D(QValueAxis); |
|
256 | Q_D(QValueAxis); | |
257 | qWarning()<<"This function is depreciated, it can lead to unexpected behavior.Use applyNiceNumbers(). "; |
|
257 | qWarning()<<"This function is depreciated, it can lead to unexpected behavior.Use applyNiceNumbers(). "; | |
258 | if(enable) { |
|
258 | if(enable) { | |
259 | QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
259 | QObject::connect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); | |
260 | QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
260 | QObject::connect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); | |
261 | applyNiceNumbers(); |
|
261 | applyNiceNumbers(); | |
262 | } |
|
262 | } | |
263 | else { |
|
263 | else { | |
264 | QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); |
|
264 | QObject::disconnect(this,SIGNAL(rangeChanged(qreal,qreal)),this,SLOT(applyNiceNumbers())); | |
265 | QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); |
|
265 | QObject::disconnect(this,SIGNAL(tickCountChanged(int)),this,SLOT(applyNiceNumbers())); | |
266 | } |
|
266 | } | |
267 | d->m_niceNumbersEnabled=enable; |
|
267 | d->m_niceNumbersEnabled=enable; | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | bool QValueAxis::niceNumbersEnabled() const |
|
270 | bool QValueAxis::niceNumbersEnabled() const | |
271 | { |
|
271 | { | |
272 | Q_D(const QValueAxis); |
|
272 | Q_D(const QValueAxis); | |
273 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; |
|
273 | qWarning()<<"This function is depreciated.Use applyNiceNumbers()."; | |
274 | return d->m_niceNumbersEnabled; |
|
274 | return d->m_niceNumbersEnabled; | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void QValueAxis::setLabelFormat(const QString &format) |
|
277 | void QValueAxis::setLabelFormat(const QString &format) | |
278 | { |
|
278 | { | |
279 | Q_D(QValueAxis); |
|
279 | Q_D(QValueAxis); | |
280 | d->m_format = format; |
|
280 | d->m_format = format; | |
281 | emit labelFormatChanged(format); |
|
281 | emit labelFormatChanged(format); | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | QString QValueAxis::labelFormat() const |
|
284 | QString QValueAxis::labelFormat() const | |
285 | { |
|
285 | { | |
286 | Q_D(const QValueAxis); |
|
286 | Q_D(const QValueAxis); | |
287 | return d->m_format; |
|
287 | return d->m_format; | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | /*! |
|
290 | /*! | |
291 | Returns the type of the axis |
|
291 | Returns the type of the axis | |
292 | */ |
|
292 | */ | |
293 | QAbstractAxis::AxisType QValueAxis::type() const |
|
293 | QAbstractAxis::AxisType QValueAxis::type() const | |
294 | { |
|
294 | { | |
295 | return AxisTypeValue; |
|
295 | return AxisTypeValue; | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | /*! |
|
298 | /*! | |
299 | This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that |
|
299 | This method modifies range and number of ticks on the axis to look "nice". Algorithm considers numbers that | |
300 | can be expressed as form of 1*10^n, 2* 10^n or 5*10^n as a nice numbers. These numbers are used for spacing the ticks. |
|
300 | can be expressed as form of 1*10^n, 2* 10^n or 5*10^n as a nice numbers. These numbers are used for spacing the ticks. | |
301 | This method will modify the current range and number of ticks. |
|
301 | This method will modify the current range and number of ticks. | |
302 | \sa setRange(), setTickCount() |
|
302 | \sa setRange(), setTickCount() | |
303 | */ |
|
303 | */ | |
304 | void QValueAxis::applyNiceNumbers() |
|
304 | void QValueAxis::applyNiceNumbers() | |
305 | { |
|
305 | { | |
306 | Q_D(QValueAxis); |
|
306 | Q_D(QValueAxis); | |
307 | if(d->m_applying) return; |
|
307 | if(d->m_applying) return; | |
308 | qreal min = d->m_min; |
|
308 | qreal min = d->m_min; | |
309 | qreal max = d->m_max; |
|
309 | qreal max = d->m_max; | |
310 | int ticks = d->m_tickCount; |
|
310 | int ticks = d->m_tickCount; | |
311 | AbstractDomain::looseNiceNumbers(min,max,ticks); |
|
311 | AbstractDomain::looseNiceNumbers(min,max,ticks); | |
312 | d->m_applying=true; |
|
312 | d->m_applying=true; | |
313 | d->setRange(min,max); |
|
313 | d->setRange(min,max); | |
314 | setTickCount(ticks); |
|
314 | setTickCount(ticks); | |
315 | d->m_applying=false; |
|
315 | d->m_applying=false; | |
316 | } |
|
316 | } | |
317 |
|
317 | |||
318 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
318 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
319 |
|
319 | |||
320 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) |
|
320 | QValueAxisPrivate::QValueAxisPrivate(QValueAxis *q) | |
321 | : QAbstractAxisPrivate(q), |
|
321 | : QAbstractAxisPrivate(q), | |
322 | m_min(0), |
|
322 | m_min(0), | |
323 | m_max(0), |
|
323 | m_max(0), | |
324 | m_tickCount(5), |
|
324 | m_tickCount(5), | |
325 | m_format(QString::null), |
|
325 | m_format(QString::null), | |
326 | m_applying(false), |
|
326 | m_applying(false), | |
327 | m_niceNumbersEnabled(false) |
|
327 | m_niceNumbersEnabled(false) | |
328 | { |
|
328 | { | |
329 |
|
329 | |||
330 | } |
|
330 | } | |
331 |
|
331 | |||
332 | QValueAxisPrivate::~QValueAxisPrivate() |
|
332 | QValueAxisPrivate::~QValueAxisPrivate() | |
333 | { |
|
333 | { | |
334 |
|
334 | |||
335 | } |
|
335 | } | |
336 |
|
336 | |||
337 | void QValueAxisPrivate::setMin(const QVariant &min) |
|
337 | void QValueAxisPrivate::setMin(const QVariant &min) | |
338 | { |
|
338 | { | |
339 | Q_Q(QValueAxis); |
|
339 | Q_Q(QValueAxis); | |
340 | bool ok; |
|
340 | bool ok; | |
341 | qreal value = min.toReal(&ok); |
|
341 | qreal value = min.toReal(&ok); | |
342 | if (ok) |
|
342 | if (ok) | |
343 | q->setMin(value); |
|
343 | q->setMin(value); | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 | void QValueAxisPrivate::setMax(const QVariant &max) |
|
346 | void QValueAxisPrivate::setMax(const QVariant &max) | |
347 | { |
|
347 | { | |
348 | Q_Q(QValueAxis); |
|
348 | Q_Q(QValueAxis); | |
349 | bool ok; |
|
349 | bool ok; | |
350 | qreal value = max.toReal(&ok); |
|
350 | qreal value = max.toReal(&ok); | |
351 | if (ok) |
|
351 | if (ok) | |
352 | q->setMax(value); |
|
352 | q->setMax(value); | |
353 | } |
|
353 | } | |
354 |
|
354 | |||
355 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) |
|
355 | void QValueAxisPrivate::setRange(const QVariant &min, const QVariant &max) | |
356 | { |
|
356 | { | |
357 | Q_Q(QValueAxis); |
|
357 | Q_Q(QValueAxis); | |
358 | bool ok1; |
|
358 | bool ok1; | |
359 | bool ok2; |
|
359 | bool ok2; | |
360 | qreal value1 = min.toReal(&ok1); |
|
360 | qreal value1 = min.toReal(&ok1); | |
361 | qreal value2 = max.toReal(&ok2); |
|
361 | qreal value2 = max.toReal(&ok2); | |
362 | if (ok1 && ok2) |
|
362 | if (ok1 && ok2) | |
363 | q->setRange(value1, value2); |
|
363 | q->setRange(value1, value2); | |
364 | } |
|
364 | } | |
365 |
|
365 | |||
366 | void QValueAxisPrivate::setRange(qreal min, qreal max) |
|
366 | void QValueAxisPrivate::setRange(qreal min, qreal max) | |
367 | { |
|
367 | { | |
368 | Q_Q(QValueAxis); |
|
368 | Q_Q(QValueAxis); | |
369 | bool changed = false; |
|
369 | bool changed = false; | |
370 |
|
370 | |||
371 | if (min > max) |
|
371 | if (min > max) | |
372 | return; |
|
372 | return; | |
373 |
|
373 | |||
374 | if (!qFuzzyCompare(m_min,min)) { |
|
374 | if (!qFuzzyCompare(m_min,min)) { | |
375 | m_min = min; |
|
375 | m_min = min; | |
376 | changed = true; |
|
376 | changed = true; | |
377 | emit q->minChanged(min); |
|
377 | emit q->minChanged(min); | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | if (!qFuzzyCompare(m_max,max)) { |
|
380 | if (!qFuzzyCompare(m_max,max)) { | |
381 | m_max = max; |
|
381 | m_max = max; | |
382 | changed = true; |
|
382 | changed = true; | |
383 | emit q->maxChanged(max); |
|
383 | emit q->maxChanged(max); | |
384 | } |
|
384 | } | |
385 |
|
385 | |||
386 | if (changed) { |
|
386 | if (changed) { | |
387 | emit rangeChanged(min,max); |
|
387 | emit rangeChanged(min,max); | |
388 | emit q->rangeChanged(min, max); |
|
388 | emit q->rangeChanged(min, max); | |
389 | } |
|
389 | } | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent) |
|
392 | void QValueAxisPrivate::initializeGraphics(QGraphicsItem *parent) | |
393 | { |
|
393 | { | |
394 | Q_Q(QValueAxis); |
|
394 | Q_Q(QValueAxis); | |
395 | ChartAxisElement *axis(0); |
|
395 | ChartAxisElement *axis(0); | |
396 |
|
396 | |||
397 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { |
|
397 | if (m_chart->chartType() == QChart::ChartTypeCartesian) { | |
398 | if (orientation() == Qt::Vertical) |
|
398 | if (orientation() == Qt::Vertical) | |
399 | axis = new ChartValueAxisY(q,parent); |
|
399 | axis = new ChartValueAxisY(q,parent); | |
400 | if (orientation() == Qt::Horizontal) |
|
400 | if (orientation() == Qt::Horizontal) | |
401 | axis = new ChartValueAxisX(q,parent); |
|
401 | axis = new ChartValueAxisX(q,parent); | |
402 | } |
|
402 | } | |
403 |
|
403 | |||
404 | if (m_chart->chartType() == QChart::ChartTypePolar) { |
|
404 | if (m_chart->chartType() == QChart::ChartTypePolar) { | |
405 | if (orientation() == Qt::Vertical) |
|
405 | if (orientation() == Qt::Vertical) | |
406 | axis = new PolarChartValueAxisRadial(q, parent); |
|
406 | axis = new PolarChartValueAxisRadial(q, parent); | |
407 | if (orientation() == Qt::Horizontal) |
|
407 | if (orientation() == Qt::Horizontal) | |
408 | axis = new PolarChartValueAxisAngular(q, parent); |
|
408 | axis = new PolarChartValueAxisAngular(q, parent); | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | m_item.reset(axis); |
|
411 | m_item.reset(axis); | |
412 | QAbstractAxisPrivate::initializeGraphics(parent); |
|
412 | QAbstractAxisPrivate::initializeGraphics(parent); | |
413 | } |
|
413 | } | |
414 |
|
414 | |||
415 |
|
415 | |||
416 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) |
|
416 | void QValueAxisPrivate::initializeDomain(AbstractDomain *domain) | |
417 | { |
|
417 | { | |
418 | if (orientation() == Qt::Vertical) { |
|
418 | if (orientation() == Qt::Vertical) { | |
419 | if (!qFuzzyIsNull(m_max - m_min)) |
|
419 | if (!qFuzzyIsNull(m_max - m_min)) | |
420 | domain->setRangeY(m_min, m_max); |
|
420 | domain->setRangeY(m_min, m_max); | |
421 | else |
|
421 | else | |
422 | setRange(domain->minY(), domain->maxY()); |
|
422 | setRange(domain->minY(), domain->maxY()); | |
423 | } |
|
423 | } | |
424 | if (orientation() == Qt::Horizontal) { |
|
424 | if (orientation() == Qt::Horizontal) { | |
425 | if (!qFuzzyIsNull(m_max - m_min)) |
|
425 | if (!qFuzzyIsNull(m_max - m_min)) | |
426 | domain->setRangeX(m_min, m_max); |
|
426 | domain->setRangeX(m_min, m_max); | |
427 | else |
|
427 | else | |
428 | setRange(domain->minX(), domain->maxX()); |
|
428 | setRange(domain->minX(), domain->maxX()); | |
429 | } |
|
429 | } | |
430 | } |
|
430 | } | |
431 |
|
431 | |||
432 | #include "moc_qvalueaxis.cpp" |
|
432 | #include "moc_qvalueaxis.cpp" | |
433 | #include "moc_qvalueaxis_p.cpp" |
|
433 | #include "moc_qvalueaxis_p.cpp" | |
434 |
|
434 | |||
435 | QTCOMMERCIALCHART_END_NAMESPACE |
|
435 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,120 +1,120 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qhorizontalbarseries.h" |
|
21 | #include "qhorizontalbarseries.h" | |
22 | #include "qhorizontalbarseries_p.h" |
|
22 | #include "qhorizontalbarseries_p.h" | |
23 | #include "horizontalbarchartitem_p.h" |
|
23 | #include "horizontalbarchartitem_p.h" | |
24 | #include "qbarcategoryaxis.h" |
|
24 | #include "qbarcategoryaxis.h" | |
25 |
|
25 | |||
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QHorizontalBarSeries |
|
33 | \class QHorizontalBarSeries | |
34 | \brief Series for creating horizontal bar chart |
|
34 | \brief Series for creating horizontal bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QHorizontalBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data |
|
38 | as groups, where bars in same category are grouped next to each other. QHorizontalBarSeries groups the data | |
39 | from sets to categories, which are defined by a QStringList. |
|
39 | from sets to categories, which are defined by a QStringList. | |
40 |
|
40 | |||
41 | See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart. |
|
41 | See the \l {HorizontalBarChart Example} {horizontal bar chart example} to learn how to create a horizontal bar chart. | |
42 | \image examples_horizontalbarchart.png |
|
42 | \image examples_horizontalbarchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries |
|
44 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalPercentBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass HorizontalBarSeries QHorizontalBarSeries |
|
47 | \qmlclass HorizontalBarSeries QHorizontalBarSeries | |
48 | \inherits AbstractBarSeries |
|
48 | \inherits AbstractBarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple horizontal bar chart: |
|
50 | The following QML shows how to create a simple horizontal bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart9.png |
|
53 | \image demos_qmlchart9.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QHorizontalBarSeries. |
|
59 | Constructs empty QHorizontalBarSeries. | |
60 | QHorizontalBarSeries is QObject which is a child of a \a parent. |
|
60 | QHorizontalBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) |
|
62 | QHorizontalBarSeries::QHorizontalBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QHorizontalBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Destructor |
|
68 | Destructor. | |
69 | Removes series from chart. |
|
69 | Removes series from chart. | |
70 | */ |
|
70 | */ | |
71 | QHorizontalBarSeries::~QHorizontalBarSeries() |
|
71 | QHorizontalBarSeries::~QHorizontalBarSeries() | |
72 | { |
|
72 | { | |
73 | Q_D(QHorizontalBarSeries); |
|
73 | Q_D(QHorizontalBarSeries); | |
74 | if (d->m_chart) |
|
74 | if (d->m_chart) | |
75 | d->m_chart->removeSeries(this); |
|
75 | d->m_chart->removeSeries(this); | |
76 | } |
|
76 | } | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | Returns QChartSeries::SeriesTypeHorizontalBar. |
|
79 | Returns QChartSeries::SeriesTypeHorizontalBar. | |
80 | */ |
|
80 | */ | |
81 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const |
|
81 | QAbstractSeries::SeriesType QHorizontalBarSeries::type() const | |
82 | { |
|
82 | { | |
83 | return QAbstractSeries::SeriesTypeHorizontalBar; |
|
83 | return QAbstractSeries::SeriesTypeHorizontalBar; | |
84 | } |
|
84 | } | |
85 |
|
85 | |||
86 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
87 |
|
87 | |||
88 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) |
|
88 | QHorizontalBarSeriesPrivate::QHorizontalBarSeriesPrivate(QHorizontalBarSeries *q) | |
89 | : QAbstractBarSeriesPrivate(q) |
|
89 | : QAbstractBarSeriesPrivate(q) | |
90 | { |
|
90 | { | |
91 |
|
91 | |||
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | void QHorizontalBarSeriesPrivate::initializeDomain() |
|
94 | void QHorizontalBarSeriesPrivate::initializeDomain() | |
95 | { |
|
95 | { | |
96 | qreal minX(domain()->minX()); |
|
96 | qreal minX(domain()->minX()); | |
97 | qreal minY(domain()->minY()); |
|
97 | qreal minY(domain()->minY()); | |
98 | qreal maxX(domain()->maxX()); |
|
98 | qreal maxX(domain()->maxX()); | |
99 | qreal maxY(domain()->maxY()); |
|
99 | qreal maxY(domain()->maxY()); | |
100 |
|
100 | |||
101 | qreal y = categoryCount(); |
|
101 | qreal y = categoryCount(); | |
102 | minX = qMin(minX, min()); |
|
102 | minX = qMin(minX, min()); | |
103 | minY = qMin(minY, - (qreal)0.5); |
|
103 | minY = qMin(minY, - (qreal)0.5); | |
104 | maxX = qMax(maxX, max()); |
|
104 | maxX = qMax(maxX, max()); | |
105 | maxY = qMax(maxY, y - (qreal)0.5); |
|
105 | maxY = qMax(maxY, y - (qreal)0.5); | |
106 |
|
106 | |||
107 | domain()->setRange(minX, maxX, minY, maxY); |
|
107 | domain()->setRange(minX, maxX, minY, maxY); | |
108 | } |
|
108 | } | |
109 |
|
109 | |||
110 | void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
110 | void QHorizontalBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
111 | { |
|
111 | { | |
112 | Q_Q(QHorizontalBarSeries); |
|
112 | Q_Q(QHorizontalBarSeries); | |
113 | HorizontalBarChartItem *bar = new HorizontalBarChartItem(q,parent); |
|
113 | HorizontalBarChartItem *bar = new HorizontalBarChartItem(q,parent); | |
114 | m_item.reset(bar); |
|
114 | m_item.reset(bar); | |
115 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
115 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
116 | } |
|
116 | } | |
117 |
|
117 | |||
118 | #include "moc_qhorizontalbarseries.cpp" |
|
118 | #include "moc_qhorizontalbarseries.cpp" | |
119 |
|
119 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
120 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,116 +1,116 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 | #include "qhorizontalpercentbarseries.h" |
|
20 | #include "qhorizontalpercentbarseries.h" | |
21 | #include "qhorizontalpercentbarseries_p.h" |
|
21 | #include "qhorizontalpercentbarseries_p.h" | |
22 | #include "horizontalpercentbarchartitem_p.h" |
|
22 | #include "horizontalpercentbarchartitem_p.h" | |
23 |
|
23 | |||
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | /*! |
|
29 | /*! | |
30 | \class QHorizontalPercentBarSeries |
|
30 | \class QHorizontalPercentBarSeries | |
31 | \brief Series for creating horizontal percent bar chart |
|
31 | \brief Series for creating horizontal percent bar chart | |
32 | \mainclass |
|
32 | \mainclass | |
33 |
|
33 | |||
34 | QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
34 | QHorizontalPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
35 | as groups, where bars in same category are grouped next to each other. QHorizontalPercentBarSeries groups the data |
|
35 | as groups, where bars in same category are grouped next to each other. QHorizontalPercentBarSeries groups the data | |
36 | from sets to categories, which are defined by a QStringList. |
|
36 | from sets to categories, which are defined by a QStringList. | |
37 |
|
37 | |||
38 | See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn how to create a horizontal percent bar chart. |
|
38 | See the \l {HorizontalPercentBarChart Example} {horizontal percent bar chart example} to learn how to create a horizontal percent bar chart. | |
39 | \image examples_horizontalpercentbarchart.png |
|
39 | \image examples_horizontalpercentbarchart.png | |
40 |
|
40 | |||
41 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalBarSeries |
|
41 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalStackedBarSeries, QHorizontalBarSeries | |
42 | */ |
|
42 | */ | |
43 | /*! |
|
43 | /*! | |
44 | \qmlclass HorizontalPercentBarSeries QHorizontalPercentBarSeries |
|
44 | \qmlclass HorizontalPercentBarSeries QHorizontalPercentBarSeries | |
45 | \inherits QAbstractBarSeries |
|
45 | \inherits QAbstractBarSeries | |
46 |
|
46 | |||
47 | The following QML shows how to create a simple horizontal percent bar chart: |
|
47 | The following QML shows how to create a simple horizontal percent bar chart: | |
48 | \snippet ../demos/qmlchart/qml/qmlchart/View11.qml 1 |
|
48 | \snippet ../demos/qmlchart/qml/qmlchart/View11.qml 1 | |
49 | \beginfloatleft |
|
49 | \beginfloatleft | |
50 | \image demos_qmlchart11.png |
|
50 | \image demos_qmlchart11.png | |
51 | \endfloat |
|
51 | \endfloat | |
52 | \clearfloat |
|
52 | \clearfloat | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | Constructs empty QHorizontalPercentBarSeries. |
|
56 | Constructs empty QHorizontalPercentBarSeries. | |
57 | QHorizontalPercentBarSeries is QObject which is a child of a \a parent. |
|
57 | QHorizontalPercentBarSeries is QObject which is a child of a \a parent. | |
58 | */ |
|
58 | */ | |
59 | QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) : |
|
59 | QHorizontalPercentBarSeries::QHorizontalPercentBarSeries(QObject *parent) : | |
60 | QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent) |
|
60 | QAbstractBarSeries(*new QHorizontalPercentBarSeriesPrivate(this), parent) | |
61 | { |
|
61 | { | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | Returns QChartSeries::SeriesTypeHorizontalPercentBar. |
|
65 | Returns QChartSeries::SeriesTypeHorizontalPercentBar. | |
66 | */ |
|
66 | */ | |
67 | QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const |
|
67 | QAbstractSeries::SeriesType QHorizontalPercentBarSeries::type() const | |
68 | { |
|
68 | { | |
69 | return QAbstractSeries::SeriesTypeHorizontalPercentBar; |
|
69 | return QAbstractSeries::SeriesTypeHorizontalPercentBar; | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | Destructor |
|
73 | Destructor. | |
74 | Removes series from chart. |
|
74 | Removes series from chart. | |
75 | */ |
|
75 | */ | |
76 | QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries() |
|
76 | QHorizontalPercentBarSeries::~QHorizontalPercentBarSeries() | |
77 | { |
|
77 | { | |
78 | Q_D(QHorizontalPercentBarSeries); |
|
78 | Q_D(QHorizontalPercentBarSeries); | |
79 | if (d->m_chart) |
|
79 | if (d->m_chart) | |
80 | d->m_chart->removeSeries(this); |
|
80 | d->m_chart->removeSeries(this); | |
81 | } |
|
81 | } | |
82 |
|
82 | |||
83 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
83 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
84 |
|
84 | |||
85 | QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
85 | QHorizontalPercentBarSeriesPrivate::QHorizontalPercentBarSeriesPrivate(QHorizontalPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
86 | { |
|
86 | { | |
87 |
|
87 | |||
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void QHorizontalPercentBarSeriesPrivate::initializeDomain() |
|
90 | void QHorizontalPercentBarSeriesPrivate::initializeDomain() | |
91 | { |
|
91 | { | |
92 | qreal minX(domain()->minX()); |
|
92 | qreal minX(domain()->minX()); | |
93 | qreal minY(domain()->minY()); |
|
93 | qreal minY(domain()->minY()); | |
94 | qreal maxX(domain()->maxX()); |
|
94 | qreal maxX(domain()->maxX()); | |
95 | qreal maxY(domain()->maxY()); |
|
95 | qreal maxY(domain()->maxY()); | |
96 |
|
96 | |||
97 | qreal y = categoryCount(); |
|
97 | qreal y = categoryCount(); | |
98 | minX = 0; |
|
98 | minX = 0; | |
99 | maxX = 100; |
|
99 | maxX = 100; | |
100 | minY = qMin(minY, - (qreal)0.5); |
|
100 | minY = qMin(minY, - (qreal)0.5); | |
101 | maxY = qMax(maxY, y - (qreal)0.5); |
|
101 | maxY = qMax(maxY, y - (qreal)0.5); | |
102 |
|
102 | |||
103 | domain()->setRange(minX, maxX, minY, maxY); |
|
103 | domain()->setRange(minX, maxX, minY, maxY); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
106 | void QHorizontalPercentBarSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
107 | { |
|
107 | { | |
108 | Q_Q(QHorizontalPercentBarSeries); |
|
108 | Q_Q(QHorizontalPercentBarSeries); | |
109 | HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q,parent); |
|
109 | HorizontalPercentBarChartItem *bar = new HorizontalPercentBarChartItem(q,parent); | |
110 | m_item.reset(bar); |
|
110 | m_item.reset(bar); | |
111 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
111 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
112 | } |
|
112 | } | |
113 |
|
113 | |||
114 | #include "moc_qhorizontalpercentbarseries.cpp" |
|
114 | #include "moc_qhorizontalpercentbarseries.cpp" | |
115 |
|
115 | |||
116 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,115 +1,115 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 | #include "qhorizontalstackedbarseries.h" |
|
20 | #include "qhorizontalstackedbarseries.h" | |
21 | #include "qhorizontalstackedbarseries_p.h" |
|
21 | #include "qhorizontalstackedbarseries_p.h" | |
22 | #include "horizontalstackedbarchartitem_p.h" |
|
22 | #include "horizontalstackedbarchartitem_p.h" | |
23 |
|
23 | |||
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 | /*! |
|
28 | /*! | |
29 | \class QHorizontalStackedBarSeries |
|
29 | \class QHorizontalStackedBarSeries | |
30 | \brief Series for creating horizontal stacked bar chart |
|
30 | \brief Series for creating horizontal stacked bar chart | |
31 | \mainclass |
|
31 | \mainclass | |
32 |
|
32 | |||
33 | QHorizontalStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
33 | QHorizontalStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
34 | as groups, where bars in same category are grouped next to each other. QHorizontalStackedBarSeries groups the data |
|
34 | as groups, where bars in same category are grouped next to each other. QHorizontalStackedBarSeries groups the data | |
35 | from sets to categories, which are defined by a QStringList. |
|
35 | from sets to categories, which are defined by a QStringList. | |
36 |
|
36 | |||
37 | See the \l {HorizontalStackedBarChart Example} {horizontal stacked bar chart example} to learn how to create a horizontal stacked bar chart. |
|
37 | See the \l {HorizontalStackedBarChart Example} {horizontal stacked bar chart example} to learn how to create a horizontal stacked bar chart. | |
38 | \image examples_horizontalstackedbarchart.png |
|
38 | \image examples_horizontalstackedbarchart.png | |
39 |
|
39 | |||
40 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries |
|
40 | \sa QBarSet, QBarSeries, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries, QHorizontalPercentBarSeries, QHorizontalBarSeries | |
41 | */ |
|
41 | */ | |
42 | /*! |
|
42 | /*! | |
43 | \qmlclass HorizontalStackedBarSeries QHorizontalStackedBarSeries |
|
43 | \qmlclass HorizontalStackedBarSeries QHorizontalStackedBarSeries | |
44 | \inherits QAbstractBarSeries |
|
44 | \inherits QAbstractBarSeries | |
45 |
|
45 | |||
46 | The following QML shows how to create a simple horizontal stacked bar chart: |
|
46 | The following QML shows how to create a simple horizontal stacked bar chart: | |
47 | \snippet ../demos/qmlchart/qml/qmlchart/View10.qml 1 |
|
47 | \snippet ../demos/qmlchart/qml/qmlchart/View10.qml 1 | |
48 | \beginfloatleft |
|
48 | \beginfloatleft | |
49 | \image demos_qmlchart10.png |
|
49 | \image demos_qmlchart10.png | |
50 | \endfloat |
|
50 | \endfloat | |
51 | \clearfloat |
|
51 | \clearfloat | |
52 | */ |
|
52 | */ | |
53 |
|
53 | |||
54 | /*! |
|
54 | /*! | |
55 | Constructs empty QHorizontalStackedBarSeries. |
|
55 | Constructs empty QHorizontalStackedBarSeries. | |
56 | QHorizontalStackedBarSeries is QObject which is a child of a \a parent. |
|
56 | QHorizontalStackedBarSeries is QObject which is a child of a \a parent. | |
57 | */ |
|
57 | */ | |
58 | QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent) |
|
58 | QHorizontalStackedBarSeries::QHorizontalStackedBarSeries(QObject *parent) | |
59 | : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent) |
|
59 | : QAbstractBarSeries(*new QHorizontalStackedBarSeriesPrivate(this), parent) | |
60 | { |
|
60 | { | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | Destructor |
|
64 | Destructor. | |
65 | Removes series from chart. |
|
65 | Removes series from chart. | |
66 | */ |
|
66 | */ | |
67 | QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries() |
|
67 | QHorizontalStackedBarSeries::~QHorizontalStackedBarSeries() | |
68 | { |
|
68 | { | |
69 | Q_D(QHorizontalStackedBarSeries); |
|
69 | Q_D(QHorizontalStackedBarSeries); | |
70 | if (d->m_chart) |
|
70 | if (d->m_chart) | |
71 | d->m_chart->removeSeries(this); |
|
71 | d->m_chart->removeSeries(this); | |
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | Returns QChartSeries::SeriesTypeHorizontalStackedBar. |
|
75 | Returns QChartSeries::SeriesTypeHorizontalStackedBar. | |
76 | */ |
|
76 | */ | |
77 | QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const |
|
77 | QAbstractSeries::SeriesType QHorizontalStackedBarSeries::type() const | |
78 | { |
|
78 | { | |
79 | return QAbstractSeries::SeriesTypeHorizontalStackedBar; |
|
79 | return QAbstractSeries::SeriesTypeHorizontalStackedBar; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
83 | |||
84 | QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
84 | QHorizontalStackedBarSeriesPrivate::QHorizontalStackedBarSeriesPrivate(QHorizontalStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
85 | { | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void QHorizontalStackedBarSeriesPrivate::initializeDomain() |
|
89 | void QHorizontalStackedBarSeriesPrivate::initializeDomain() | |
90 | { |
|
90 | { | |
91 | qreal minX(domain()->minX()); |
|
91 | qreal minX(domain()->minX()); | |
92 | qreal minY(domain()->minY()); |
|
92 | qreal minY(domain()->minY()); | |
93 | qreal maxX(domain()->maxX()); |
|
93 | qreal maxX(domain()->maxX()); | |
94 | qreal maxY(domain()->maxY()); |
|
94 | qreal maxY(domain()->maxY()); | |
95 |
|
95 | |||
96 | qreal y = categoryCount(); |
|
96 | qreal y = categoryCount(); | |
97 | minX = qMin(minX, bottom()); |
|
97 | minX = qMin(minX, bottom()); | |
98 | minY = qMin(minY, - (qreal)0.5); |
|
98 | minY = qMin(minY, - (qreal)0.5); | |
99 | maxX = qMax(maxX, top()); |
|
99 | maxX = qMax(maxX, top()); | |
100 | maxY = qMax(maxY, y - (qreal)0.5); |
|
100 | maxY = qMax(maxY, y - (qreal)0.5); | |
101 |
|
101 | |||
102 | domain()->setRange(minX, maxX, minY, maxY); |
|
102 | domain()->setRange(minX, maxX, minY, maxY); | |
103 | } |
|
103 | } | |
104 |
|
104 | |||
105 | void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent) |
|
105 | void QHorizontalStackedBarSeriesPrivate::initializeGraphics(QGraphicsItem *parent) | |
106 | { |
|
106 | { | |
107 | Q_Q(QHorizontalStackedBarSeries); |
|
107 | Q_Q(QHorizontalStackedBarSeries); | |
108 | HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent); |
|
108 | HorizontalStackedBarChartItem *bar = new HorizontalStackedBarChartItem(q,parent); | |
109 | m_item.reset(bar); |
|
109 | m_item.reset(bar); | |
110 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
110 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | #include "moc_qhorizontalstackedbarseries.cpp" |
|
113 | #include "moc_qhorizontalstackedbarseries.cpp" | |
114 |
|
114 | |||
115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
115 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,645 +1,645 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 | #include "charthelpers_p.h" |
|
23 | #include "charthelpers_p.h" | |
24 |
|
24 | |||
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \class QBarSet |
|
28 | \class QBarSet | |
29 | \brief Building block for different bar charts |
|
29 | \brief Building block for different bar charts | |
30 |
|
30 | |||
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
32 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | First value of set is assumed to belong to first category, second to second category and so on. | |
33 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | If set has fewer values than there are categories, then the missing values are assumed to be | |
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
35 |
|
35 | |||
36 | \mainclass |
|
36 | \mainclass | |
37 |
|
37 | |||
38 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | |
39 | */ |
|
39 | */ | |
40 | /*! |
|
40 | /*! | |
41 | \qmlclass BarSet QBarSet |
|
41 | \qmlclass BarSet QBarSet | |
42 |
|
42 | |||
43 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
43 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
44 | First value of set is assumed to belong to first category, second to second category and so on. |
|
44 | First value of set is assumed to belong to first category, second to second category and so on. | |
45 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
45 | If set has fewer values than there are categories, then the missing values are assumed to be | |
46 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
46 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
47 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries |
|
47 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \property QBarSet::label |
|
51 | \property QBarSet::label | |
52 | Defines the label of the barSet. |
|
52 | Defines the label of the barSet. | |
53 | */ |
|
53 | */ | |
54 | /*! |
|
54 | /*! | |
55 | \qmlproperty string BarSet::label |
|
55 | \qmlproperty string BarSet::label | |
56 | Defines the label of the barSet. |
|
56 | Defines the label of the barSet. | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QBarSet::pen |
|
60 | \property QBarSet::pen | |
61 | \brief Defines the pen used by the barSet. |
|
61 | \brief Defines the pen used by the barSet. | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \property QBarSet::brush |
|
65 | \property QBarSet::brush | |
66 | \brief Defines the brush used by the barSet. |
|
66 | \brief Defines the brush used by the barSet. | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QBarSet::labelBrush |
|
70 | \property QBarSet::labelBrush | |
71 | \brief Defines the brush used by the barSet's label. |
|
71 | \brief Defines the brush used by the barSet's label. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \property QBarSet::labelFont |
|
75 | \property QBarSet::labelFont | |
76 | \brief Defines the font used by the barSet's label. |
|
76 | \brief Defines the font used by the barSet's label. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \qmlproperty Font BarSet::labelFont |
|
80 | \qmlproperty Font BarSet::labelFont | |
81 | Defines the font used by the barSet's label. |
|
81 | Defines the font used by the barSet's label. | |
82 |
|
82 | |||
83 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
83 | See the \l {Font} {QML Font Element} for detailed documentation. | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \property QBarSet::color |
|
87 | \property QBarSet::color | |
88 | The fill (brush) color of the bar set. |
|
88 | The fill (brush) color of the bar set. | |
89 | */ |
|
89 | */ | |
90 | /*! |
|
90 | /*! | |
91 | \qmlproperty color BarSet::color |
|
91 | \qmlproperty color BarSet::color | |
92 | The fill (brush) color of the bar set. |
|
92 | The fill (brush) color of the bar set. | |
93 | */ |
|
93 | */ | |
94 |
|
94 | |||
95 | /*! |
|
95 | /*! | |
96 | \property QBarSet::borderColor |
|
96 | \property QBarSet::borderColor | |
97 | The line (pen) color of the bar set. |
|
97 | The line (pen) color of the bar set. | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty color BarSet::borderColor |
|
100 | \qmlproperty color BarSet::borderColor | |
101 | The line (pen) color of the bar set. |
|
101 | The line (pen) color of the bar set. | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \qmlproperty real BarSet::borderWidth |
|
105 | \qmlproperty real BarSet::borderWidth | |
106 | The width of the border line. By default the width is 2.0. |
|
106 | The width of the border line. By default the width is 2.0. | |
107 | */ |
|
107 | */ | |
108 |
|
108 | |||
109 | /*! |
|
109 | /*! | |
110 | \property QBarSet::labelColor |
|
110 | \property QBarSet::labelColor | |
111 | The text (label) color of the bar set. |
|
111 | The text (label) color of the bar set. | |
112 | */ |
|
112 | */ | |
113 | /*! |
|
113 | /*! | |
114 | \qmlproperty color BarSet::labelColor |
|
114 | \qmlproperty color BarSet::labelColor | |
115 | The text (label) color of the bar set. |
|
115 | The text (label) color of the bar set. | |
116 | */ |
|
116 | */ | |
117 |
|
117 | |||
118 | /*! |
|
118 | /*! | |
119 | \fn void QBarSet::clicked(int index) |
|
119 | \fn void QBarSet::clicked(int index) | |
120 |
|
120 | |||
121 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
121 | The signal is emitted if the user clicks with a mouse on top of barset. | |
122 | Clicked bar inside set is indexed by \a index |
|
122 | Clicked bar inside set is indexed by \a index | |
123 | */ |
|
123 | */ | |
124 |
|
124 | |||
125 | /*! |
|
125 | /*! | |
126 | \fn void QBarSet::hovered(bool status) |
|
126 | \fn void QBarSet::hovered(bool status) | |
127 |
|
127 | |||
128 | The signal is emitted if mouse is hovered on top of barset. |
|
128 | The signal is emitted if mouse is hovered on top of barset. | |
129 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
129 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QBarSet::labelChanged() |
|
134 | \fn void QBarSet::labelChanged() | |
135 | This signal is emitted when the label of the barSet has changed. |
|
135 | This signal is emitted when the label of the barSet has changed. | |
136 | \sa label |
|
136 | \sa label | |
137 | */ |
|
137 | */ | |
138 | /*! |
|
138 | /*! | |
139 | \qmlsignal BarSet::onLabelChanged() |
|
139 | \qmlsignal BarSet::onLabelChanged() | |
140 | This signal is emitted when the label of the barSet has changed. |
|
140 | This signal is emitted when the label of the barSet has changed. | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn void QBarSet::penChanged() |
|
144 | \fn void QBarSet::penChanged() | |
145 | This signal is emitted when the pen of the barSet has changed. |
|
145 | This signal is emitted when the pen of the barSet has changed. | |
146 | \sa pen |
|
146 | \sa pen | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QBarSet::brushChanged() |
|
150 | \fn void QBarSet::brushChanged() | |
151 | This signal is emitted when the brush of the barSet has changed. |
|
151 | This signal is emitted when the brush of the barSet has changed. | |
152 | \sa brush |
|
152 | \sa brush | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QBarSet::labelBrushChanged() |
|
156 | \fn void QBarSet::labelBrushChanged() | |
157 | This signal is emitted when the brush of the barSet's label has changed. |
|
157 | This signal is emitted when the brush of the barSet's label has changed. | |
158 | \sa labelBrush |
|
158 | \sa labelBrush | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QBarSet::labelFontChanged() |
|
162 | \fn void QBarSet::labelFontChanged() | |
163 | This signal is emitted when the font of the barSet's label has changed. |
|
163 | This signal is emitted when the font of the barSet's label has changed. | |
164 | \sa labelBrush |
|
164 | \sa labelBrush | |
165 | */ |
|
165 | */ | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | \fn void QBarSet::colorChanged(QColor) |
|
168 | \fn void QBarSet::colorChanged(QColor) | |
169 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
169 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
170 | */ |
|
170 | */ | |
171 | /*! |
|
171 | /*! | |
172 | \qmlsignal BarSet::onColorChanged(color color) |
|
172 | \qmlsignal BarSet::onColorChanged(color color) | |
173 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
173 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | \fn void QBarSet::borderColorChanged(QColor) |
|
177 | \fn void QBarSet::borderColorChanged(QColor) | |
178 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
178 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
179 | */ |
|
179 | */ | |
180 | /*! |
|
180 | /*! | |
181 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
181 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
182 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
182 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \fn void QBarSet::labelColorChanged(QColor) |
|
186 | \fn void QBarSet::labelColorChanged(QColor) | |
187 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
187 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
188 | */ |
|
188 | */ | |
189 | /*! |
|
189 | /*! | |
190 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
190 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
191 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
191 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
192 | */ |
|
192 | */ | |
193 |
|
193 | |||
194 | /*! |
|
194 | /*! | |
195 | \fn void QBarSet::valuesAdded(int index, int count) |
|
195 | \fn void QBarSet::valuesAdded(int index, int count) | |
196 | This signal is emitted when new values have been added to the set. |
|
196 | This signal is emitted when new values have been added to the set. | |
197 | Parameter \a index indicates the position of the first inserted value. |
|
197 | Parameter \a index indicates the position of the first inserted value. | |
198 | Parameter \a count is the number of iserted values. |
|
198 | Parameter \a count is the number of inserted values. | |
199 | \sa append(), insert() |
|
199 | \sa append(), insert() | |
200 | */ |
|
200 | */ | |
201 | /*! |
|
201 | /*! | |
202 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
202 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
203 | This signal is emitted when new values have been added to the set. |
|
203 | This signal is emitted when new values have been added to the set. | |
204 | Parameter \a index indicates the position of the first inserted value. |
|
204 | Parameter \a index indicates the position of the first inserted value. | |
205 | Parameter \a count is the number of iserted values. |
|
205 | Parameter \a count is the number of inserted values. | |
206 | */ |
|
206 | */ | |
207 |
|
207 | |||
208 | /*! |
|
208 | /*! | |
209 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
209 | \fn void QBarSet::valuesRemoved(int index, int count) | |
210 | This signal is emitted values have been removed from the set. |
|
210 | This signal is emitted values have been removed from the set. | |
211 | Parameter \a index indicates the position of the first removed value. |
|
211 | Parameter \a index indicates the position of the first removed value. | |
212 | Parameter \a count is the number of removed values. |
|
212 | Parameter \a count is the number of removed values. | |
213 | \sa remove() |
|
213 | \sa remove() | |
214 | */ |
|
214 | */ | |
215 | /*! |
|
215 | /*! | |
216 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
216 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
217 | This signal is emitted values have been removed from the set. |
|
217 | This signal is emitted values have been removed from the set. | |
218 | Parameter \a index indicates the position of the first removed value. |
|
218 | Parameter \a index indicates the position of the first removed value. | |
219 | Parameter \a count is the number of removed values. |
|
219 | Parameter \a count is the number of removed values. | |
220 | */ |
|
220 | */ | |
221 |
|
221 | |||
222 | /*! |
|
222 | /*! | |
223 | \fn void QBarSet::valueChanged(int index) |
|
223 | \fn void QBarSet::valueChanged(int index) | |
224 | This signal is emitted values the value in the set has been modified. |
|
224 | This signal is emitted values the value in the set has been modified. | |
225 | Parameter \a index indicates the position of the modified value. |
|
225 | Parameter \a index indicates the position of the modified value. | |
226 | \sa at() |
|
226 | \sa at() | |
227 | */ |
|
227 | */ | |
228 | /*! |
|
228 | /*! | |
229 | \qmlsignal BarSet::onValueChanged(int index) |
|
229 | \qmlsignal BarSet::onValueChanged(int index) | |
230 | This signal is emitted values the value in the set has been modified. |
|
230 | This signal is emitted values the value in the set has been modified. | |
231 | Parameter \a index indicates the position of the modified value. |
|
231 | Parameter \a index indicates the position of the modified value. | |
232 | */ |
|
232 | */ | |
233 |
|
233 | |||
234 | /*! |
|
234 | /*! | |
235 | \qmlproperty int BarSet::count |
|
235 | \qmlproperty int BarSet::count | |
236 | The count of values on the barset |
|
236 | The count of values on the barset | |
237 | */ |
|
237 | */ | |
238 |
|
238 | |||
239 | /*! |
|
239 | /*! | |
240 | \qmlproperty QVariantList BarSet::values |
|
240 | \qmlproperty QVariantList BarSet::values | |
241 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
241 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of | |
242 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
242 | reals as values, the values are automatically completed to points by using the index of a value as it's | |
243 | x-coordinate. For example: |
|
243 | x-coordinate. For example: | |
244 | \code |
|
244 | \code | |
245 | myBarSet1.values = [0, 5, 1, 5]; |
|
245 | myBarSet1.values = [0, 5, 1, 5]; | |
246 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
246 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; | |
247 | \endcode |
|
247 | \endcode | |
248 | */ |
|
248 | */ | |
249 |
|
249 | |||
250 | /*! |
|
250 | /*! | |
251 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
251 | Constructs QBarSet with a label of \a label and with parent of \a parent. | |
252 | */ |
|
252 | */ | |
253 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
253 | QBarSet::QBarSet(const QString label, QObject *parent) | |
254 | : QObject(parent), |
|
254 | : QObject(parent), | |
255 | d_ptr(new QBarSetPrivate(label, this)) |
|
255 | d_ptr(new QBarSetPrivate(label, this)) | |
256 | { |
|
256 | { | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | Destroys the barset |
|
260 | Destroys the barset. | |
261 | */ |
|
261 | */ | |
262 | QBarSet::~QBarSet() |
|
262 | QBarSet::~QBarSet() | |
263 | { |
|
263 | { | |
264 | // NOTE: d_ptr destroyed by QObject |
|
264 | // NOTE: d_ptr destroyed by QObject | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | /*! |
|
267 | /*! | |
268 | Sets new \a label for set. |
|
268 | Sets new \a label for set. | |
269 | */ |
|
269 | */ | |
270 | void QBarSet::setLabel(const QString label) |
|
270 | void QBarSet::setLabel(const QString label) | |
271 | { |
|
271 | { | |
272 | d_ptr->m_label = label; |
|
272 | d_ptr->m_label = label; | |
273 | emit labelChanged(); |
|
273 | emit labelChanged(); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | /*! |
|
276 | /*! | |
277 | Returns label of the set. |
|
277 | Returns label of the set. | |
278 | */ |
|
278 | */ | |
279 | QString QBarSet::label() const |
|
279 | QString QBarSet::label() const | |
280 | { |
|
280 | { | |
281 | return d_ptr->m_label; |
|
281 | return d_ptr->m_label; | |
282 | } |
|
282 | } | |
283 |
|
283 | |||
284 | /*! |
|
284 | /*! | |
285 | Appends new value \a value to the end of set. |
|
285 | Appends new value \a value to the end of set. | |
286 | */ |
|
286 | */ | |
287 | void QBarSet::append(const qreal value) |
|
287 | void QBarSet::append(const qreal value) | |
288 | { |
|
288 | { | |
289 | // Convert to QPointF |
|
289 | // Convert to QPointF | |
290 | int index = d_ptr->m_values.count(); |
|
290 | int index = d_ptr->m_values.count(); | |
291 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
291 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
292 | emit valuesAdded(index, 1); |
|
292 | emit valuesAdded(index, 1); | |
293 | } |
|
293 | } | |
294 |
|
294 | |||
295 | /*! |
|
295 | /*! | |
296 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
296 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
297 | are appended to end of barset |
|
297 | are appended to end of barset | |
298 | \sa append() |
|
298 | \sa append() | |
299 | */ |
|
299 | */ | |
300 | void QBarSet::append(const QList<qreal> &values) |
|
300 | void QBarSet::append(const QList<qreal> &values) | |
301 | { |
|
301 | { | |
302 | int index = d_ptr->m_values.count(); |
|
302 | int index = d_ptr->m_values.count(); | |
303 | d_ptr->append(values); |
|
303 | d_ptr->append(values); | |
304 | emit valuesAdded(index, values.count()); |
|
304 | emit valuesAdded(index, values.count()); | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | /*! |
|
307 | /*! | |
308 | Convenience operator. Same as append, with real \a value. |
|
308 | Convenience operator. Same as append, with real \a value. | |
309 | \sa append() |
|
309 | \sa append() | |
310 | */ |
|
310 | */ | |
311 | QBarSet &QBarSet::operator << (const qreal &value) |
|
311 | QBarSet &QBarSet::operator << (const qreal &value) | |
312 | { |
|
312 | { | |
313 | append(value); |
|
313 | append(value); | |
314 | return *this; |
|
314 | return *this; | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | /*! |
|
317 | /*! | |
318 | Inserts new \a value on the \a index position. |
|
318 | Inserts new \a value on the \a index position. | |
319 | The value that is currently at this postion is moved to postion index + 1 |
|
319 | The value that is currently at this postion is moved to position index + 1 | |
320 | \sa remove() |
|
320 | \sa remove() | |
321 | */ |
|
321 | */ | |
322 | void QBarSet::insert(const int index, const qreal value) |
|
322 | void QBarSet::insert(const int index, const qreal value) | |
323 | { |
|
323 | { | |
324 | d_ptr->insert(index, value); |
|
324 | d_ptr->insert(index, value); | |
325 | emit valuesAdded(index, 1); |
|
325 | emit valuesAdded(index, 1); | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | /*! |
|
328 | /*! | |
329 | Removes \a count number of values from the set starting at \a index. |
|
329 | Removes \a count number of values from the set starting at \a index. | |
330 | \sa insert() |
|
330 | \sa insert() | |
331 | */ |
|
331 | */ | |
332 | void QBarSet::remove(const int index, const int count) |
|
332 | void QBarSet::remove(const int index, const int count) | |
333 | { |
|
333 | { | |
334 | int removedCount = d_ptr->remove(index, count); |
|
334 | int removedCount = d_ptr->remove(index, count); | |
335 | if (removedCount > 0) |
|
335 | if (removedCount > 0) | |
336 | emit valuesRemoved(index, removedCount); |
|
336 | emit valuesRemoved(index, removedCount); | |
337 | return; |
|
337 | return; | |
338 | } |
|
338 | } | |
339 |
|
339 | |||
340 | /*! |
|
340 | /*! | |
341 | Sets a new value \a value to set, indexed by \a index |
|
341 | Sets a new value \a value to set, indexed by \a index. | |
342 | */ |
|
342 | */ | |
343 | void QBarSet::replace(const int index, const qreal value) |
|
343 | void QBarSet::replace(const int index, const qreal value) | |
344 | { |
|
344 | { | |
345 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
345 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
346 | d_ptr->replace(index, value); |
|
346 | d_ptr->replace(index, value); | |
347 | emit valueChanged(index); |
|
347 | emit valueChanged(index); | |
348 | } |
|
348 | } | |
349 | } |
|
349 | } | |
350 |
|
350 | |||
351 |
|
351 | |||
352 | /*! |
|
352 | /*! | |
353 | Returns value of set indexed by \a index. |
|
353 | Returns value of set indexed by \a index. | |
354 | If the index is out of bounds 0.0 is returned. |
|
354 | If the index is out of bounds 0.0 is returned. | |
355 | */ |
|
355 | */ | |
356 | qreal QBarSet::at(const int index) const |
|
356 | qreal QBarSet::at(const int index) const | |
357 | { |
|
357 | { | |
358 | if (index < 0 || index >= d_ptr->m_values.count()) |
|
358 | if (index < 0 || index >= d_ptr->m_values.count()) | |
359 | return 0; |
|
359 | return 0; | |
360 | return d_ptr->m_values.at(index).y(); |
|
360 | return d_ptr->m_values.at(index).y(); | |
361 | } |
|
361 | } | |
362 |
|
362 | |||
363 | /*! |
|
363 | /*! | |
364 | Returns value of set indexed by \a index. |
|
364 | Returns value of set indexed by \a index. | |
365 | If the index is out of bounds 0.0 is returned. |
|
365 | If the index is out of bounds 0.0 is returned. | |
366 | */ |
|
366 | */ | |
367 | qreal QBarSet::operator [](const int index) const |
|
367 | qreal QBarSet::operator [](const int index) const | |
368 | { |
|
368 | { | |
369 | return at(index); |
|
369 | return at(index); | |
370 | } |
|
370 | } | |
371 |
|
371 | |||
372 | /*! |
|
372 | /*! | |
373 | Returns count of values in set. |
|
373 | Returns count of values in set. | |
374 | */ |
|
374 | */ | |
375 | int QBarSet::count() const |
|
375 | int QBarSet::count() const | |
376 | { |
|
376 | { | |
377 | return d_ptr->m_values.count(); |
|
377 | return d_ptr->m_values.count(); | |
378 | } |
|
378 | } | |
379 |
|
379 | |||
380 | /*! |
|
380 | /*! | |
381 | Returns sum of all values in barset. |
|
381 | Returns sum of all values in barset. | |
382 | */ |
|
382 | */ | |
383 | qreal QBarSet::sum() const |
|
383 | qreal QBarSet::sum() const | |
384 | { |
|
384 | { | |
385 | qreal total(0); |
|
385 | qreal total(0); | |
386 | for (int i = 0; i < d_ptr->m_values.count(); i++) |
|
386 | for (int i = 0; i < d_ptr->m_values.count(); i++) | |
387 | total += d_ptr->m_values.at(i).y(); |
|
387 | total += d_ptr->m_values.at(i).y(); | |
388 | return total; |
|
388 | return total; | |
389 | } |
|
389 | } | |
390 |
|
390 | |||
391 | /*! |
|
391 | /*! | |
392 | Sets pen for set. Bars of this set are drawn using \a pen |
|
392 | Sets pen for set. Bars of this set are drawn using \a pen | |
393 | */ |
|
393 | */ | |
394 | void QBarSet::setPen(const QPen &pen) |
|
394 | void QBarSet::setPen(const QPen &pen) | |
395 | { |
|
395 | { | |
396 | if (d_ptr->m_pen != pen) { |
|
396 | if (d_ptr->m_pen != pen) { | |
397 | d_ptr->m_pen = pen; |
|
397 | d_ptr->m_pen = pen; | |
398 | emit d_ptr->updatedBars(); |
|
398 | emit d_ptr->updatedBars(); | |
399 | emit penChanged(); |
|
399 | emit penChanged(); | |
400 | } |
|
400 | } | |
401 | } |
|
401 | } | |
402 |
|
402 | |||
403 | /*! |
|
403 | /*! | |
404 | Returns pen of the set. |
|
404 | Returns pen of the set. | |
405 | */ |
|
405 | */ | |
406 | QPen QBarSet::pen() const |
|
406 | QPen QBarSet::pen() const | |
407 | { |
|
407 | { | |
408 | return d_ptr->m_pen; |
|
408 | return d_ptr->m_pen; | |
409 | } |
|
409 | } | |
410 |
|
410 | |||
411 | /*! |
|
411 | /*! | |
412 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
412 | Sets brush for the set. Bars of this set are drawn using \a brush | |
413 | */ |
|
413 | */ | |
414 | void QBarSet::setBrush(const QBrush &brush) |
|
414 | void QBarSet::setBrush(const QBrush &brush) | |
415 | { |
|
415 | { | |
416 | if (d_ptr->m_brush != brush) { |
|
416 | if (d_ptr->m_brush != brush) { | |
417 | d_ptr->m_brush = brush; |
|
417 | d_ptr->m_brush = brush; | |
418 | emit d_ptr->updatedBars(); |
|
418 | emit d_ptr->updatedBars(); | |
419 | emit brushChanged(); |
|
419 | emit brushChanged(); | |
420 | } |
|
420 | } | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | /*! |
|
423 | /*! | |
424 | Returns brush of the set. |
|
424 | Returns brush of the set. | |
425 | */ |
|
425 | */ | |
426 | QBrush QBarSet::brush() const |
|
426 | QBrush QBarSet::brush() const | |
427 | { |
|
427 | { | |
428 | return d_ptr->m_brush; |
|
428 | return d_ptr->m_brush; | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | /*! |
|
431 | /*! | |
432 | Sets \a brush of the values that are drawn on top of this barset |
|
432 | Sets \a brush of the values that are drawn on top of this barset | |
433 | */ |
|
433 | */ | |
434 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
434 | void QBarSet::setLabelBrush(const QBrush &brush) | |
435 | { |
|
435 | { | |
436 | if (d_ptr->m_labelBrush != brush) { |
|
436 | if (d_ptr->m_labelBrush != brush) { | |
437 | d_ptr->m_labelBrush = brush; |
|
437 | d_ptr->m_labelBrush = brush; | |
438 | emit d_ptr->updatedBars(); |
|
438 | emit d_ptr->updatedBars(); | |
439 | emit labelBrushChanged(); |
|
439 | emit labelBrushChanged(); | |
440 | } |
|
440 | } | |
441 | } |
|
441 | } | |
442 |
|
442 | |||
443 | /*! |
|
443 | /*! | |
444 | Returns brush of the values that are drawn on top of this barset |
|
444 | Returns brush of the values that are drawn on top of this barset | |
445 | */ |
|
445 | */ | |
446 | QBrush QBarSet::labelBrush() const |
|
446 | QBrush QBarSet::labelBrush() const | |
447 | { |
|
447 | { | |
448 | return d_ptr->m_labelBrush; |
|
448 | return d_ptr->m_labelBrush; | |
449 | } |
|
449 | } | |
450 |
|
450 | |||
451 | /*! |
|
451 | /*! | |
452 | Sets the \a font for values that are drawn on top of this barset |
|
452 | Sets the \a font for values that are drawn on top of this barset | |
453 | */ |
|
453 | */ | |
454 | void QBarSet::setLabelFont(const QFont &font) |
|
454 | void QBarSet::setLabelFont(const QFont &font) | |
455 | { |
|
455 | { | |
456 | if (d_ptr->m_labelFont != font) { |
|
456 | if (d_ptr->m_labelFont != font) { | |
457 | d_ptr->m_labelFont = font; |
|
457 | d_ptr->m_labelFont = font; | |
458 | emit d_ptr->updatedBars(); |
|
458 | emit d_ptr->updatedBars(); | |
459 | emit labelFontChanged(); |
|
459 | emit labelFontChanged(); | |
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | /*! |
|
464 | /*! | |
465 | Returns the pen for values that are drawn on top of this barset |
|
465 | Returns the pen for values that are drawn on top of this barset | |
466 | */ |
|
466 | */ | |
467 | QFont QBarSet::labelFont() const |
|
467 | QFont QBarSet::labelFont() const | |
468 | { |
|
468 | { | |
469 | return d_ptr->m_labelFont; |
|
469 | return d_ptr->m_labelFont; | |
470 | } |
|
470 | } | |
471 |
|
471 | |||
472 | /*! |
|
472 | /*! | |
473 | Returns the color of the brush of barset. |
|
473 | Returns the color of the brush of barset. | |
474 | */ |
|
474 | */ | |
475 | QColor QBarSet::color() |
|
475 | QColor QBarSet::color() | |
476 | { |
|
476 | { | |
477 | return brush().color(); |
|
477 | return brush().color(); | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | /*! |
|
480 | /*! | |
481 | Sets the \a color of brush for this barset |
|
481 | Sets the \a color of brush for this barset | |
482 | */ |
|
482 | */ | |
483 | void QBarSet::setColor(QColor color) |
|
483 | void QBarSet::setColor(QColor color) | |
484 | { |
|
484 | { | |
485 | QBrush b = brush(); |
|
485 | QBrush b = brush(); | |
486 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { |
|
486 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { | |
487 | b.setColor(color); |
|
487 | b.setColor(color); | |
488 | if (b.style() == Qt::NoBrush) { |
|
488 | if (b.style() == Qt::NoBrush) { | |
489 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) |
|
489 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) | |
490 | // This prevents theme to override color defined in QML side: |
|
490 | // This prevents theme to override color defined in QML side: | |
491 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } |
|
491 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } | |
492 | // The color must be obeyed, since user wanted it. |
|
492 | // The color must be obeyed, since user wanted it. | |
493 | b.setStyle(Qt::SolidPattern); |
|
493 | b.setStyle(Qt::SolidPattern); | |
494 | } |
|
494 | } | |
495 | setBrush(b); |
|
495 | setBrush(b); | |
496 | emit colorChanged(color); |
|
496 | emit colorChanged(color); | |
497 | } |
|
497 | } | |
498 | } |
|
498 | } | |
499 |
|
499 | |||
500 | /*! |
|
500 | /*! | |
501 | Returns the color of pen of this barset |
|
501 | Returns the color of pen of this barset | |
502 | */ |
|
502 | */ | |
503 | QColor QBarSet::borderColor() |
|
503 | QColor QBarSet::borderColor() | |
504 | { |
|
504 | { | |
505 | return pen().color(); |
|
505 | return pen().color(); | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | /*! |
|
508 | /*! | |
509 | Sets the color of pen for this barset |
|
509 | Sets the color of pen for this barset | |
510 | */ |
|
510 | */ | |
511 | void QBarSet::setBorderColor(QColor color) |
|
511 | void QBarSet::setBorderColor(QColor color) | |
512 | { |
|
512 | { | |
513 | QPen p = pen(); |
|
513 | QPen p = pen(); | |
514 | if (p.color() != color) { |
|
514 | if (p.color() != color) { | |
515 | p.setColor(color); |
|
515 | p.setColor(color); | |
516 | setPen(p); |
|
516 | setPen(p); | |
517 | emit borderColorChanged(color); |
|
517 | emit borderColorChanged(color); | |
518 | } |
|
518 | } | |
519 | } |
|
519 | } | |
520 |
|
520 | |||
521 | /*! |
|
521 | /*! | |
522 | Returns the color of labels of this barset |
|
522 | Returns the color of labels of this barset | |
523 | */ |
|
523 | */ | |
524 | QColor QBarSet::labelColor() |
|
524 | QColor QBarSet::labelColor() | |
525 | { |
|
525 | { | |
526 | return labelBrush().color(); |
|
526 | return labelBrush().color(); | |
527 | } |
|
527 | } | |
528 |
|
528 | |||
529 | /*! |
|
529 | /*! | |
530 | Sets the color of labels for this barset |
|
530 | Sets the color of labels for this barset | |
531 | */ |
|
531 | */ | |
532 | void QBarSet::setLabelColor(QColor color) |
|
532 | void QBarSet::setLabelColor(QColor color) | |
533 | { |
|
533 | { | |
534 | QBrush b = labelBrush(); |
|
534 | QBrush b = labelBrush(); | |
535 | if (b == QBrush()) |
|
535 | if (b == QBrush()) | |
536 | b.setStyle(Qt::SolidPattern); |
|
536 | b.setStyle(Qt::SolidPattern); | |
537 |
|
537 | |||
538 | if (b.color() != color) { |
|
538 | if (b.color() != color) { | |
539 | b.setColor(color); |
|
539 | b.setColor(color); | |
540 | setLabelBrush(b); |
|
540 | setLabelBrush(b); | |
541 | emit labelColorChanged(color); |
|
541 | emit labelColorChanged(color); | |
542 | } |
|
542 | } | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
545 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
546 |
|
546 | |||
547 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
547 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
548 | q_ptr(parent), |
|
548 | q_ptr(parent), | |
549 | m_label(label) |
|
549 | m_label(label) | |
550 | { |
|
550 | { | |
551 | } |
|
551 | } | |
552 |
|
552 | |||
553 | QBarSetPrivate::~QBarSetPrivate() |
|
553 | QBarSetPrivate::~QBarSetPrivate() | |
554 | { |
|
554 | { | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | void QBarSetPrivate::append(QPointF value) |
|
557 | void QBarSetPrivate::append(QPointF value) | |
558 | { |
|
558 | { | |
559 | if (isValidValue(value)) { |
|
559 | if (isValidValue(value)) { | |
560 | m_values.append(value); |
|
560 | m_values.append(value); | |
561 | emit restructuredBars(); |
|
561 | emit restructuredBars(); | |
562 | } |
|
562 | } | |
563 | } |
|
563 | } | |
564 |
|
564 | |||
565 | void QBarSetPrivate::append(QList<QPointF> values) |
|
565 | void QBarSetPrivate::append(QList<QPointF> values) | |
566 | { |
|
566 | { | |
567 | for (int i = 0; i < values.count(); i++) { |
|
567 | for (int i = 0; i < values.count(); i++) { | |
568 | if (isValidValue(values.at(i))) |
|
568 | if (isValidValue(values.at(i))) | |
569 | m_values.append(values.at(i)); |
|
569 | m_values.append(values.at(i)); | |
570 | } |
|
570 | } | |
571 | emit restructuredBars(); |
|
571 | emit restructuredBars(); | |
572 | } |
|
572 | } | |
573 |
|
573 | |||
574 | void QBarSetPrivate::append(QList<qreal> values) |
|
574 | void QBarSetPrivate::append(QList<qreal> values) | |
575 | { |
|
575 | { | |
576 | int index = m_values.count(); |
|
576 | int index = m_values.count(); | |
577 | for (int i = 0; i < values.count(); i++) { |
|
577 | for (int i = 0; i < values.count(); i++) { | |
578 | if (isValidValue(values.at(i))) { |
|
578 | if (isValidValue(values.at(i))) { | |
579 | m_values.append(QPointF(index, values.at(i))); |
|
579 | m_values.append(QPointF(index, values.at(i))); | |
580 | index++; |
|
580 | index++; | |
581 | } |
|
581 | } | |
582 | } |
|
582 | } | |
583 | emit restructuredBars(); |
|
583 | emit restructuredBars(); | |
584 | } |
|
584 | } | |
585 |
|
585 | |||
586 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
586 | void QBarSetPrivate::insert(const int index, const qreal value) | |
587 | { |
|
587 | { | |
588 | m_values.insert(index, QPointF(index, value)); |
|
588 | m_values.insert(index, QPointF(index, value)); | |
589 | emit restructuredBars(); |
|
589 | emit restructuredBars(); | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
592 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
593 | { |
|
593 | { | |
594 | m_values.insert(index, value); |
|
594 | m_values.insert(index, value); | |
595 | emit restructuredBars(); |
|
595 | emit restructuredBars(); | |
596 | } |
|
596 | } | |
597 |
|
597 | |||
598 | int QBarSetPrivate::remove(const int index, const int count) |
|
598 | int QBarSetPrivate::remove(const int index, const int count) | |
599 | { |
|
599 | { | |
600 | int removeCount = count; |
|
600 | int removeCount = count; | |
601 |
|
601 | |||
602 | if ((index < 0) || (m_values.count() == 0)) |
|
602 | if ((index < 0) || (m_values.count() == 0)) | |
603 | return 0; // Invalid index or not values in list, remove nothing. |
|
603 | return 0; // Invalid index or not values in list, remove nothing. | |
604 | else if ((index + count) > m_values.count()) |
|
604 | else if ((index + count) > m_values.count()) | |
605 | removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed. |
|
605 | removeCount = m_values.count() - index; // Trying to remove more items than list has. Limit amount to be removed. | |
606 |
|
606 | |||
607 | int c = 0; |
|
607 | int c = 0; | |
608 | while (c < removeCount) { |
|
608 | while (c < removeCount) { | |
609 | m_values.removeAt(index); |
|
609 | m_values.removeAt(index); | |
610 | c++; |
|
610 | c++; | |
611 | } |
|
611 | } | |
612 | emit restructuredBars(); |
|
612 | emit restructuredBars(); | |
613 | return removeCount; |
|
613 | return removeCount; | |
614 | } |
|
614 | } | |
615 |
|
615 | |||
616 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
616 | void QBarSetPrivate::replace(const int index, const qreal value) | |
617 | { |
|
617 | { | |
618 | m_values.replace(index, QPointF(index, value)); |
|
618 | m_values.replace(index, QPointF(index, value)); | |
619 | emit updatedLayout(); |
|
619 | emit updatedLayout(); | |
620 | } |
|
620 | } | |
621 |
|
621 | |||
622 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
622 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
623 | { |
|
623 | { | |
624 | m_values.replace(index, value); |
|
624 | m_values.replace(index, value); | |
625 | emit updatedLayout(); |
|
625 | emit updatedLayout(); | |
626 | } |
|
626 | } | |
627 |
|
627 | |||
628 | qreal QBarSetPrivate::pos(const int index) |
|
628 | qreal QBarSetPrivate::pos(const int index) | |
629 | { |
|
629 | { | |
630 | if (index < 0 || index >= m_values.count()) |
|
630 | if (index < 0 || index >= m_values.count()) | |
631 | return 0; |
|
631 | return 0; | |
632 | return m_values.at(index).x(); |
|
632 | return m_values.at(index).x(); | |
633 | } |
|
633 | } | |
634 |
|
634 | |||
635 | qreal QBarSetPrivate::value(const int index) |
|
635 | qreal QBarSetPrivate::value(const int index) | |
636 | { |
|
636 | { | |
637 | if (index < 0 || index >= m_values.count()) |
|
637 | if (index < 0 || index >= m_values.count()) | |
638 | return 0; |
|
638 | return 0; | |
639 | return m_values.at(index).y(); |
|
639 | return m_values.at(index).y(); | |
640 | } |
|
640 | } | |
641 |
|
641 | |||
642 | #include "moc_qbarset.cpp" |
|
642 | #include "moc_qbarset.cpp" | |
643 | #include "moc_qbarset_p.cpp" |
|
643 | #include "moc_qbarset_p.cpp" | |
644 |
|
644 | |||
645 | QTCOMMERCIALCHART_END_NAMESPACE |
|
645 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,249 +1,249 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qhbarmodelmapper.h" |
|
21 | #include "qhbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHBarModelMapper |
|
26 | \class QHBarModelMapper | |
27 | \brief Horizontal model mapper for bar series |
|
27 | \brief Horizontal model mapper for bar series | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
31 | Horizontal model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 |
|
|
34 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass HBarModelMapper QHBarModelMapper |
|
37 | \qmlclass HBarModelMapper QHBarModelMapper | |
38 |
|
38 | |||
39 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
39 | HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
40 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
40 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |
41 | HBarModelMapper keeps the series and the model in sync. |
|
41 | HBarModelMapper keeps the series and the model in sync. | |
42 |
|
42 | |||
43 | The following QML example would create a bar series with three bar sets (assuming the model has |
|
43 | The following QML example would create a bar series with three bar sets (assuming the model has | |
44 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by |
|
44 | at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by | |
45 | the vertical header (of the row). |
|
45 | the vertical header (of the row). | |
46 | \code |
|
46 | \code | |
47 | BarSeries { |
|
47 | BarSeries { | |
48 | HBarModelMapper { |
|
48 | HBarModelMapper { | |
49 | model: myCustomModel // QAbstractItemModel derived implementation |
|
49 | model: myCustomModel // QAbstractItemModel derived implementation | |
50 | firstBarSetRow: 1 |
|
50 | firstBarSetRow: 1 | |
51 | lastBarSetRow: 3 |
|
51 | lastBarSetRow: 3 | |
52 | firstColumn: 1 |
|
52 | firstColumn: 1 | |
53 | } |
|
53 | } | |
54 | } |
|
54 | } | |
55 | \endcode |
|
55 | \endcode | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QHBarModelMapper::series |
|
59 | \property QHBarModelMapper::series | |
60 | \brief Defines the QPieSeries object that is used by the mapper. |
|
60 | \brief Defines the QPieSeries object that is used by the mapper. | |
61 |
|
61 | |||
62 | All the data in the series is discarded when it is set to the mapper. |
|
62 | All the data in the series is discarded when it is set to the mapper. | |
63 | When new series is specified the old series is disconnected (it preserves its data) |
|
63 | When new series is specified the old series is disconnected (it preserves its data) | |
64 | */ |
|
64 | */ | |
65 | /*! |
|
65 | /*! | |
66 | \qmlproperty AbstractBarSeries HBarModelMapper::series |
|
66 | \qmlproperty AbstractBarSeries HBarModelMapper::series | |
67 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
67 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
68 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
68 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \property QHBarModelMapper::model |
|
72 | \property QHBarModelMapper::model | |
73 | \brief Defines the model that is used by the mapper. |
|
73 | \brief Defines the model that is used by the mapper. | |
74 | */ |
|
74 | */ | |
75 | /*! |
|
75 | /*! | |
76 | \qmlproperty SomeModel HBarModelMapper::model |
|
76 | \qmlproperty SomeModel HBarModelMapper::model | |
77 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
77 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
78 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns |
|
78 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns | |
79 | and modifying the data of the cells. |
|
79 | and modifying the data of the cells. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \property QHBarModelMapper::firstBarSetRow |
|
83 | \property QHBarModelMapper::firstBarSetRow | |
84 | \brief Defines which column of the model is used as the data source for the first bar set |
|
84 | \brief Defines which column of the model is used as the data source for the first bar set | |
85 | Default value is: -1 (invalid mapping) |
|
85 | Default value is: -1 (invalid mapping) | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty int HBarModelMapper::firstBarSetRow |
|
88 | \qmlproperty int HBarModelMapper::firstBarSetRow | |
89 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 |
|
89 | Defines which column of the model is used as the data source for the first bar set. The default value is -1 | |
90 | (invalid mapping). |
|
90 | (invalid mapping). | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QHBarModelMapper::lastBarSetRow |
|
94 | \property QHBarModelMapper::lastBarSetRow | |
95 | \brief Defines which column of the model is used as the data source for the last bar set |
|
95 | \brief Defines which column of the model is used as the data source for the last bar set | |
96 | Default value is: -1 (invalid mapping) |
|
96 | Default value is: -1 (invalid mapping) | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty int HBarModelMapper::lastBarSetRow |
|
99 | \qmlproperty int HBarModelMapper::lastBarSetRow | |
100 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 |
|
100 | Defines which column of the model is used as the data source for the last bar set. The default value is -1 | |
101 | (invalid mapping). |
|
101 | (invalid mapping). | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QHBarModelMapper::firstColumn |
|
105 | \property QHBarModelMapper::firstColumn | |
106 | \brief Defines which column of the model contains the first values of the QBarSets in the series. |
|
106 | \brief Defines which column of the model contains the first values of the QBarSets in the series. | |
107 | Minimal and default value is: 0 |
|
107 | Minimal and default value is: 0 | |
108 | */ |
|
108 | */ | |
109 | /*! |
|
109 | /*! | |
110 | \qmlproperty int HBarModelMapper::firstColumn |
|
110 | \qmlproperty int HBarModelMapper::firstColumn | |
111 | Defines which column of the model contains the first values of the QBarSets in the series. |
|
111 | Defines which column of the model contains the first values of the QBarSets in the series. | |
112 | The default value is 0. |
|
112 | The default value is 0. | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \property QHBarModelMapper::columnCount |
|
116 | \property QHBarModelMapper::columnCount | |
117 | \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries |
|
117 | \brief Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries | |
118 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
118 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
119 | */ |
|
119 | */ | |
120 | /*! |
|
120 | /*! | |
121 | \qmlproperty int HBarModelMapper::columnCount |
|
121 | \qmlproperty int HBarModelMapper::columnCount | |
122 | Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
122 | Defines the number of columns of the model that are mapped as the data for QAbstractBarSeries. The default value is | |
123 | -1 (count limited by the number of columns in the model) |
|
123 | -1 (count limited by the number of columns in the model) | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QHBarModelMapper::seriesReplaced() |
|
127 | \fn void QHBarModelMapper::seriesReplaced() | |
128 |
|
128 | |||
129 | Emitted when the series to which mapper is connected to has changed. |
|
129 | Emitted when the series to which mapper is connected to has changed. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QHBarModelMapper::modelReplaced() |
|
133 | \fn void QHBarModelMapper::modelReplaced() | |
134 |
|
134 | |||
135 | Emitted when the model to which mapper is connected to has changed. |
|
135 | Emitted when the model to which mapper is connected to has changed. | |
136 | */ |
|
136 | */ | |
137 |
|
137 | |||
138 | /*! |
|
138 | /*! | |
139 | \fn void QHBarModelMapper::firstBarSetRowChanged() |
|
139 | \fn void QHBarModelMapper::firstBarSetRowChanged() | |
140 |
|
140 | |||
141 | Emitted when the firstBarSetRow has changed. |
|
141 | Emitted when the firstBarSetRow has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QHBarModelMapper::lastBarSetRowChanged() |
|
145 | \fn void QHBarModelMapper::lastBarSetRowChanged() | |
146 |
|
146 | |||
147 | Emitted when the lastBarSetRow has changed. |
|
147 | Emitted when the lastBarSetRow has changed. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QHBarModelMapper::firstColumnChanged() |
|
151 | \fn void QHBarModelMapper::firstColumnChanged() | |
152 | Emitted when the firstColumn has changed. |
|
152 | Emitted when the firstColumn has changed. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QHBarModelMapper::columnCountChanged() |
|
156 | \fn void QHBarModelMapper::columnCountChanged() | |
157 | Emitted when the columnCount has changed. |
|
157 | Emitted when the columnCount has changed. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | /*! |
|
160 | /*! | |
161 | Constructs a mapper object which is a child of \a parent. |
|
161 | Constructs a mapper object which is a child of \a parent. | |
162 | */ |
|
162 | */ | |
163 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : |
|
163 | QHBarModelMapper::QHBarModelMapper(QObject *parent) : | |
164 | QBarModelMapper(parent) |
|
164 | QBarModelMapper(parent) | |
165 | { |
|
165 | { | |
166 | QBarModelMapper::setOrientation(Qt::Horizontal); |
|
166 | QBarModelMapper::setOrientation(Qt::Horizontal); | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | QAbstractItemModel *QHBarModelMapper::model() const |
|
169 | QAbstractItemModel *QHBarModelMapper::model() const | |
170 | { |
|
170 | { | |
171 | return QBarModelMapper::model(); |
|
171 | return QBarModelMapper::model(); | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | void QHBarModelMapper::setModel(QAbstractItemModel *model) |
|
174 | void QHBarModelMapper::setModel(QAbstractItemModel *model) | |
175 | { |
|
175 | { | |
176 | if (model != QBarModelMapper::model()) { |
|
176 | if (model != QBarModelMapper::model()) { | |
177 | QBarModelMapper::setModel(model); |
|
177 | QBarModelMapper::setModel(model); | |
178 | emit modelReplaced(); |
|
178 | emit modelReplaced(); | |
179 | } |
|
179 | } | |
180 | } |
|
180 | } | |
181 |
|
181 | |||
182 | QAbstractBarSeries *QHBarModelMapper::series() const |
|
182 | QAbstractBarSeries *QHBarModelMapper::series() const | |
183 | { |
|
183 | { | |
184 | return QBarModelMapper::series(); |
|
184 | return QBarModelMapper::series(); | |
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
187 | void QHBarModelMapper::setSeries(QAbstractBarSeries *series) | |
188 | { |
|
188 | { | |
189 | if (series != QBarModelMapper::series()) { |
|
189 | if (series != QBarModelMapper::series()) { | |
190 | QBarModelMapper::setSeries(series); |
|
190 | QBarModelMapper::setSeries(series); | |
191 | emit seriesReplaced(); |
|
191 | emit seriesReplaced(); | |
192 | } |
|
192 | } | |
193 | } |
|
193 | } | |
194 |
|
194 | |||
195 | int QHBarModelMapper::firstBarSetRow() const |
|
195 | int QHBarModelMapper::firstBarSetRow() const | |
196 | { |
|
196 | { | |
197 | return QBarModelMapper::firstBarSetSection(); |
|
197 | return QBarModelMapper::firstBarSetSection(); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) |
|
200 | void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow) | |
201 | { |
|
201 | { | |
202 | if (firstBarSetRow != firstBarSetSection()) { |
|
202 | if (firstBarSetRow != firstBarSetSection()) { | |
203 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); |
|
203 | QBarModelMapper::setFirstBarSetSection(firstBarSetRow); | |
204 | emit firstBarSetRowChanged(); |
|
204 | emit firstBarSetRowChanged(); | |
205 | } |
|
205 | } | |
206 | } |
|
206 | } | |
207 |
|
207 | |||
208 | int QHBarModelMapper::lastBarSetRow() const |
|
208 | int QHBarModelMapper::lastBarSetRow() const | |
209 | { |
|
209 | { | |
210 | return QBarModelMapper::lastBarSetSection(); |
|
210 | return QBarModelMapper::lastBarSetSection(); | |
211 | } |
|
211 | } | |
212 |
|
212 | |||
213 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) |
|
213 | void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow) | |
214 | { |
|
214 | { | |
215 | if (lastBarSetRow != lastBarSetSection()) { |
|
215 | if (lastBarSetRow != lastBarSetSection()) { | |
216 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); |
|
216 | QBarModelMapper::setLastBarSetSection(lastBarSetRow); | |
217 | emit lastBarSetRowChanged(); |
|
217 | emit lastBarSetRowChanged(); | |
218 | } |
|
218 | } | |
219 | } |
|
219 | } | |
220 |
|
220 | |||
221 | int QHBarModelMapper::firstColumn() const |
|
221 | int QHBarModelMapper::firstColumn() const | |
222 | { |
|
222 | { | |
223 | return QBarModelMapper::first(); |
|
223 | return QBarModelMapper::first(); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | void QHBarModelMapper::setFirstColumn(int firstColumn) |
|
226 | void QHBarModelMapper::setFirstColumn(int firstColumn) | |
227 | { |
|
227 | { | |
228 | if (firstColumn != first()) { |
|
228 | if (firstColumn != first()) { | |
229 | QBarModelMapper::setFirst(firstColumn); |
|
229 | QBarModelMapper::setFirst(firstColumn); | |
230 | emit firstColumnChanged(); |
|
230 | emit firstColumnChanged(); | |
231 | } |
|
231 | } | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | int QHBarModelMapper::columnCount() const |
|
234 | int QHBarModelMapper::columnCount() const | |
235 | { |
|
235 | { | |
236 | return QBarModelMapper::count(); |
|
236 | return QBarModelMapper::count(); | |
237 | } |
|
237 | } | |
238 |
|
238 | |||
239 | void QHBarModelMapper::setColumnCount(int columnCount) |
|
239 | void QHBarModelMapper::setColumnCount(int columnCount) | |
240 | { |
|
240 | { | |
241 | if (columnCount != count()) { |
|
241 | if (columnCount != count()) { | |
242 | QBarModelMapper::setCount(columnCount); |
|
242 | QBarModelMapper::setCount(columnCount); | |
243 | emit columnCountChanged(); |
|
243 | emit columnCountChanged(); | |
244 | } |
|
244 | } | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | #include "moc_qhbarmodelmapper.cpp" |
|
247 | #include "moc_qhbarmodelmapper.cpp" | |
248 |
|
248 | |||
249 | QTCOMMERCIALCHART_END_NAMESPACE |
|
249 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,248 +1,248 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qvbarmodelmapper.h" |
|
21 | #include "qvbarmodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVBarModelMapper |
|
26 | \class QVBarModelMapper | |
27 | \brief Vertical model mapper for bar series |
|
27 | \brief Vertical model mapper for bar series | |
28 | \mainclass |
|
28 | \mainclass | |
29 |
|
29 | |||
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
30 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. |
|
31 | Vertical model mapper is used to create a connection between QAbstractBarSeries and QAbstractItemModel derived model object. | |
32 | Model mapper maintains equal size of all the BarSets. |
|
32 | Model mapper maintains equal size of all the BarSets. | |
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. |
|
33 | Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series. | |
34 |
|
|
34 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. | |
35 | */ |
|
35 | */ | |
36 | /*! |
|
36 | /*! | |
37 | \qmlclass VBarModelMapper |
|
37 | \qmlclass VBarModelMapper | |
38 | \mainclass |
|
38 | \mainclass | |
39 |
|
39 | |||
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
40 | VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. |
|
41 | for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data. | |
42 | VBarModelMapper keeps the series and the model in sync. |
|
42 | VBarModelMapper keeps the series and the model in sync. | |
43 |
|
43 | |||
44 | The following QML example would create a bar series with three bar sets (assuming the |
|
44 | The following QML example would create a bar series with three bar sets (assuming the | |
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be |
|
45 | model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be | |
46 | defined by the horizontal header (of the column). |
|
46 | defined by the horizontal header (of the column). | |
47 | \code |
|
47 | \code | |
48 | BarSeries { |
|
48 | BarSeries { | |
49 | VBarModelMapper { |
|
49 | VBarModelMapper { | |
50 | model: myCustomModel // QAbstractItemModel derived implementation |
|
50 | model: myCustomModel // QAbstractItemModel derived implementation | |
51 | firstBarSetColumn: 1 |
|
51 | firstBarSetColumn: 1 | |
52 | lastBarSetColumn: 3 |
|
52 | lastBarSetColumn: 3 | |
53 | firstRow: 1 |
|
53 | firstRow: 1 | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 | \endcode |
|
56 | \endcode | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \property QVBarModelMapper::series |
|
60 | \property QVBarModelMapper::series | |
61 | \brief Defines the QPieSeries object that is used by the mapper. |
|
61 | \brief Defines the QPieSeries object that is used by the mapper. | |
62 |
|
62 | |||
63 | All the data in the series is discarded when it is set to the mapper. |
|
63 | All the data in the series is discarded when it is set to the mapper. | |
64 | When new series is specified the old series is disconnected (it preserves its data) |
|
64 | When new series is specified the old series is disconnected (it preserves its data) | |
65 | */ |
|
65 | */ | |
66 | /*! |
|
66 | /*! | |
67 | \qmlproperty AbstractBarSeries VBarModelMapper::series |
|
67 | \qmlproperty AbstractBarSeries VBarModelMapper::series | |
68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is |
|
68 | Defines the AbstractBarSeries based object that is used by the mapper. All the data in the series is discarded when it is | |
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). |
|
69 | set to the mapper. When new series is specified the old series is disconnected (it preserves its data). | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QVBarModelMapper::model |
|
73 | \property QVBarModelMapper::model | |
74 | \brief Defines the model that is used by the mapper. |
|
74 | \brief Defines the model that is used by the mapper. | |
75 | */ |
|
75 | */ | |
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty SomeModel VBarModelMapper::model |
|
77 | \qmlproperty SomeModel VBarModelMapper::model | |
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
78 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
79 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns |
|
79 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns | |
80 | and modifying the data of the cells. |
|
80 | and modifying the data of the cells. | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QVBarModelMapper::firstBarSetColumn |
|
84 | \property QVBarModelMapper::firstBarSetColumn | |
85 | \brief Defines which column of the model is used as the data source for the first bar set |
|
85 | \brief Defines which column of the model is used as the data source for the first bar set | |
86 | Default value is: -1 (invalid mapping) |
|
86 | Default value is: -1 (invalid mapping) | |
87 | */ |
|
87 | */ | |
88 | /*! |
|
88 | /*! | |
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn |
|
89 | \qmlproperty int VBarModelMapper::firstBarSetColumn | |
90 | Defines which column of the model is used as the data source for the first bar set. Default value |
|
90 | Defines which column of the model is used as the data source for the first bar set. Default value | |
91 | is: -1 (invalid mapping). |
|
91 | is: -1 (invalid mapping). | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QVBarModelMapper::lastBarSetColumn |
|
95 | \property QVBarModelMapper::lastBarSetColumn | |
96 | \brief Defines which column of the model is used as the data source for the last bar set |
|
96 | \brief Defines which column of the model is used as the data source for the last bar set | |
97 | Default value is: -1 (invalid mapping) |
|
97 | Default value is: -1 (invalid mapping) | |
98 | */ |
|
98 | */ | |
99 | /*! |
|
99 | /*! | |
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn |
|
100 | \qmlproperty int VBarModelMapper::lastBarSetColumn | |
101 | Defines which column of the model is used as the data source for the last bar set. Default |
|
101 | Defines which column of the model is used as the data source for the last bar set. Default | |
102 | value is: -1 (invalid mapping). |
|
102 | value is: -1 (invalid mapping). | |
103 | */ |
|
103 | */ | |
104 |
|
104 | |||
105 | /*! |
|
105 | /*! | |
106 | \property QVBarModelMapper::firstRow |
|
106 | \property QVBarModelMapper::firstRow | |
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. |
|
107 | \brief Defines which row of the model contains the first values of the QBarSets in the series. | |
108 | Minimal and default value is: 0 |
|
108 | Minimal and default value is: 0 | |
109 | */ |
|
109 | */ | |
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty int VBarModelMapper::firstRow |
|
111 | \qmlproperty int VBarModelMapper::firstRow | |
112 | Defines which row of the model contains the first values of the QBarSets in the series. |
|
112 | Defines which row of the model contains the first values of the QBarSets in the series. | |
113 | The default value is 0. |
|
113 | The default value is 0. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \property QVBarModelMapper::rowCount |
|
117 | \property QVBarModelMapper::rowCount | |
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries |
|
118 | \brief Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries | |
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
119 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty int VBarModelMapper::rowCount |
|
122 | \qmlproperty int VBarModelMapper::rowCount | |
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is |
|
123 | Defines the number of rows of the model that are mapped as the data for QAbstractBarSeries. The default value is | |
124 | -1 (count limited by the number of rows in the model) |
|
124 | -1 (count limited by the number of rows in the model) | |
125 | */ |
|
125 | */ | |
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QVBarModelMapper::seriesReplaced() |
|
128 | \fn void QVBarModelMapper::seriesReplaced() | |
129 |
|
129 | |||
130 | Emitted when the series to which mapper is connected to has changed. |
|
130 | Emitted when the series to which mapper is connected to has changed. | |
131 | */ |
|
131 | */ | |
132 |
|
132 | |||
133 | /*! |
|
133 | /*! | |
134 | \fn void QVBarModelMapper::modelReplaced() |
|
134 | \fn void QVBarModelMapper::modelReplaced() | |
135 |
|
135 | |||
136 | Emitted when the model to which mapper is connected to has changed. |
|
136 | Emitted when the model to which mapper is connected to has changed. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() |
|
140 | \fn void QVBarModelMapper::firstBarSetColumnChanged() | |
141 | Emitted when the firstBarSetColumn has changed. |
|
141 | Emitted when the firstBarSetColumn has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() |
|
145 | \fn void QVBarModelMapper::lastBarSetColumnChanged() | |
146 | Emitted when the lastBarSetColumn has changed. |
|
146 | Emitted when the lastBarSetColumn has changed. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QVBarModelMapper::firstRowChanged() |
|
150 | \fn void QVBarModelMapper::firstRowChanged() | |
151 | Emitted when the firstRow has changed. |
|
151 | Emitted when the firstRow has changed. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | \fn void QVBarModelMapper::rowCountChanged() |
|
155 | \fn void QVBarModelMapper::rowCountChanged() | |
156 | Emitted when the rowCount has changed. |
|
156 | Emitted when the rowCount has changed. | |
157 | */ |
|
157 | */ | |
158 |
|
158 | |||
159 | /*! |
|
159 | /*! | |
160 | Constructs a mapper object which is a child of \a parent. |
|
160 | Constructs a mapper object which is a child of \a parent. | |
161 | */ |
|
161 | */ | |
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : |
|
162 | QVBarModelMapper::QVBarModelMapper(QObject *parent) : | |
163 | QBarModelMapper(parent) |
|
163 | QBarModelMapper(parent) | |
164 | { |
|
164 | { | |
165 | QBarModelMapper::setOrientation(Qt::Vertical); |
|
165 | QBarModelMapper::setOrientation(Qt::Vertical); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | QAbstractItemModel *QVBarModelMapper::model() const |
|
168 | QAbstractItemModel *QVBarModelMapper::model() const | |
169 | { |
|
169 | { | |
170 | return QBarModelMapper::model(); |
|
170 | return QBarModelMapper::model(); | |
171 | } |
|
171 | } | |
172 |
|
172 | |||
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) |
|
173 | void QVBarModelMapper::setModel(QAbstractItemModel *model) | |
174 | { |
|
174 | { | |
175 | if (model != QBarModelMapper::model()) { |
|
175 | if (model != QBarModelMapper::model()) { | |
176 | QBarModelMapper::setModel(model); |
|
176 | QBarModelMapper::setModel(model); | |
177 | emit modelReplaced(); |
|
177 | emit modelReplaced(); | |
178 | } |
|
178 | } | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | QAbstractBarSeries *QVBarModelMapper::series() const |
|
181 | QAbstractBarSeries *QVBarModelMapper::series() const | |
182 | { |
|
182 | { | |
183 | return QBarModelMapper::series(); |
|
183 | return QBarModelMapper::series(); | |
184 | } |
|
184 | } | |
185 |
|
185 | |||
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) |
|
186 | void QVBarModelMapper::setSeries(QAbstractBarSeries *series) | |
187 | { |
|
187 | { | |
188 | if (series != QBarModelMapper::series()) { |
|
188 | if (series != QBarModelMapper::series()) { | |
189 | QBarModelMapper::setSeries(series); |
|
189 | QBarModelMapper::setSeries(series); | |
190 | emit seriesReplaced(); |
|
190 | emit seriesReplaced(); | |
191 | } |
|
191 | } | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 | int QVBarModelMapper::firstBarSetColumn() const |
|
194 | int QVBarModelMapper::firstBarSetColumn() const | |
195 | { |
|
195 | { | |
196 | return QBarModelMapper::firstBarSetSection(); |
|
196 | return QBarModelMapper::firstBarSetSection(); | |
197 | } |
|
197 | } | |
198 |
|
198 | |||
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) |
|
199 | void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn) | |
200 | { |
|
200 | { | |
201 | if (firstBarSetColumn != firstBarSetSection()) { |
|
201 | if (firstBarSetColumn != firstBarSetSection()) { | |
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); |
|
202 | QBarModelMapper::setFirstBarSetSection(firstBarSetColumn); | |
203 | emit firstBarSetColumnChanged(); |
|
203 | emit firstBarSetColumnChanged(); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | int QVBarModelMapper::lastBarSetColumn() const |
|
207 | int QVBarModelMapper::lastBarSetColumn() const | |
208 | { |
|
208 | { | |
209 | return QBarModelMapper::lastBarSetSection(); |
|
209 | return QBarModelMapper::lastBarSetSection(); | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) |
|
212 | void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn) | |
213 | { |
|
213 | { | |
214 | if (lastBarSetColumn != lastBarSetSection()) { |
|
214 | if (lastBarSetColumn != lastBarSetSection()) { | |
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); |
|
215 | QBarModelMapper::setLastBarSetSection(lastBarSetColumn); | |
216 | emit lastBarSetColumnChanged(); |
|
216 | emit lastBarSetColumnChanged(); | |
217 | } |
|
217 | } | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | int QVBarModelMapper::firstRow() const |
|
220 | int QVBarModelMapper::firstRow() const | |
221 | { |
|
221 | { | |
222 | return QBarModelMapper::first(); |
|
222 | return QBarModelMapper::first(); | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | void QVBarModelMapper::setFirstRow(int firstRow) |
|
225 | void QVBarModelMapper::setFirstRow(int firstRow) | |
226 | { |
|
226 | { | |
227 | if (firstRow != first()) { |
|
227 | if (firstRow != first()) { | |
228 | QBarModelMapper::setFirst(firstRow); |
|
228 | QBarModelMapper::setFirst(firstRow); | |
229 | emit firstRowChanged(); |
|
229 | emit firstRowChanged(); | |
230 | } |
|
230 | } | |
231 | } |
|
231 | } | |
232 |
|
232 | |||
233 | int QVBarModelMapper::rowCount() const |
|
233 | int QVBarModelMapper::rowCount() const | |
234 | { |
|
234 | { | |
235 | return QBarModelMapper::count(); |
|
235 | return QBarModelMapper::count(); | |
236 | } |
|
236 | } | |
237 |
|
237 | |||
238 | void QVBarModelMapper::setRowCount(int rowCount) |
|
238 | void QVBarModelMapper::setRowCount(int rowCount) | |
239 | { |
|
239 | { | |
240 | if (rowCount != count()) { |
|
240 | if (rowCount != count()) { | |
241 | QBarModelMapper::setCount(rowCount); |
|
241 | QBarModelMapper::setCount(rowCount); | |
242 | emit rowCountChanged(); |
|
242 | emit rowCountChanged(); | |
243 | } |
|
243 | } | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | #include "moc_qvbarmodelmapper.cpp" |
|
246 | #include "moc_qvbarmodelmapper.cpp" | |
247 |
|
247 | |||
248 | QTCOMMERCIALCHART_END_NAMESPACE |
|
248 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,596 +1,596 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qlegend.h" |
|
21 | #include "qlegend.h" | |
22 | #include "qlegend_p.h" |
|
22 | #include "qlegend_p.h" | |
23 | #include "qabstractseries.h" |
|
23 | #include "qabstractseries.h" | |
24 | #include "qabstractseries_p.h" |
|
24 | #include "qabstractseries_p.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "legendlayout_p.h" |
|
26 | #include "legendlayout_p.h" | |
27 | #include "chartpresenter_p.h" |
|
27 | #include "chartpresenter_p.h" | |
28 | #include "abstractchartlayout_p.h" |
|
28 | #include "abstractchartlayout_p.h" | |
29 | #include "qlegendmarker.h" |
|
29 | #include "qlegendmarker.h" | |
30 | #include "qlegendmarker_p.h" |
|
30 | #include "qlegendmarker_p.h" | |
31 | #include "legendmarkeritem_p.h" |
|
31 | #include "legendmarkeritem_p.h" | |
32 | #include "chartdataset_p.h" |
|
32 | #include "chartdataset_p.h" | |
33 | #include <QPainter> |
|
33 | #include <QPainter> | |
34 | #include <QPen> |
|
34 | #include <QPen> | |
35 | #include <QGraphicsItemGroup> |
|
35 | #include <QGraphicsItemGroup> | |
36 |
|
36 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
38 | |||
39 | /*! |
|
39 | /*! | |
40 | \class QLegend |
|
40 | \class QLegend | |
41 | \brief Legend object |
|
41 | \brief Legend object | |
42 | \mainclass |
|
42 | \mainclass | |
43 |
|
43 | |||
44 |
QLegend is a graphical object |
|
44 | QLegend is a graphical object for displaying the legend of the chart. Legend state is updated by QChart, when | |
45 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and |
|
45 | series have been changed. By default, legend is drawn by QChart, but user can set a new parent to legend and | |
46 | handle the drawing manually. |
|
46 | handle the drawing manually. | |
47 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. |
|
47 | User isn't supposed to create or delete legend objects, but can reference it via QChart class. | |
48 |
|
48 | |||
49 | \image examples_percentbarchart_legend.png |
|
49 | \image examples_percentbarchart_legend.png | |
50 |
|
50 | |||
51 | \sa QChart |
|
51 | \sa QChart | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlclass Legend QLegend |
|
54 | \qmlclass Legend QLegend | |
55 | \brief Legend is part of QtCommercial Chart QML API. |
|
55 | \brief Legend is part of QtCommercial Chart QML API. | |
56 |
|
56 | |||
57 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when |
|
57 | Legend is a graphical object, whics displays legend of the chart. Legend state is updated by ChartView, when | |
58 | series have been changed. Legend is used via ChartView class. For example: |
|
58 | series have been changed. Legend is used via ChartView class. For example: | |
59 | \code |
|
59 | \code | |
60 | ChartView { |
|
60 | ChartView { | |
61 | legend.visible: true |
|
61 | legend.visible: true | |
62 | legend.alignment: Qt.AlignBottom |
|
62 | legend.alignment: Qt.AlignBottom | |
63 | // Add a few series... |
|
63 | // Add a few series... | |
64 | } |
|
64 | } | |
65 | \endcode |
|
65 | \endcode | |
66 |
|
66 | |||
67 | \image examples_percentbarchart_legend.png |
|
67 | \image examples_percentbarchart_legend.png | |
68 |
|
68 | |||
69 | Please note that there is no QML API available for modifying legend markers, unlike in the Qt API of Charts. |
|
69 | Please note that there is no QML API available for modifying legend markers, unlike in the Qt API of Charts. | |
70 | The use case of modifying markers can be implemented for example by creating your own custom legend. For an example |
|
70 | The use case of modifying markers can be implemented for example by creating your own custom legend. For an example | |
71 | on how to do this, see \l {demos/qmlcustomlegend}{Qml Custom Demo} application. |
|
71 | on how to do this, see \l {demos/qmlcustomlegend}{Qml Custom Demo} application. | |
72 | */ |
|
72 | */ | |
73 |
|
73 | |||
74 | /*! |
|
74 | /*! | |
75 | \property QLegend::alignment |
|
75 | \property QLegend::alignment | |
76 | \brief The alignment of the legend. |
|
76 | \brief The alignment of the legend. | |
77 |
|
77 | |||
78 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
78 | Legend paints on the defined position in the chart. The following alignments are supported: | |
79 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. |
|
79 | Qt::AlignTop, Qt::AlignBottom, Qt::AlignLeft, Qt::AlignRight. If you set more than one flag the result is undefined. | |
80 | */ |
|
80 | */ | |
81 | /*! |
|
81 | /*! | |
82 | \qmlproperty Qt.Alignment Legend::alignment |
|
82 | \qmlproperty Qt.Alignment Legend::alignment | |
83 | \brief The alignment of the legend. |
|
83 | \brief The alignment of the legend. | |
84 |
|
84 | |||
85 | Legend paints on the defined position in the chart. The following alignments are supported: |
|
85 | Legend paints on the defined position in the chart. The following alignments are supported: | |
86 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. |
|
86 | Qt.AlignTop, Qt.AlignBottom, Qt.AlignLeft, Qt.AlignRight. If you set more than one flag the result is undefined. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | /*! |
|
89 | /*! | |
90 | \property QLegend::backgroundVisible |
|
90 | \property QLegend::backgroundVisible | |
91 | Whether the legend background is visible or not. |
|
91 | Whether the legend background is visible or not. | |
92 | */ |
|
92 | */ | |
93 | /*! |
|
93 | /*! | |
94 | \qmlproperty bool Legend::backgroundVisible |
|
94 | \qmlproperty bool Legend::backgroundVisible | |
95 | Whether the legend background is visible or not. |
|
95 | Whether the legend background is visible or not. | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \property QLegend::color |
|
99 | \property QLegend::color | |
100 | The color of the legend, i.e. the background (brush) color. Note that if you change the color |
|
100 | The color of the legend, i.e. the background (brush) color. Note that if you change the color | |
101 | of the legend, the style of the legend brush is set to Qt::SolidPattern. |
|
101 | of the legend, the style of the legend brush is set to Qt::SolidPattern. | |
102 | */ |
|
102 | */ | |
103 | /*! |
|
103 | /*! | |
104 | \qmlproperty color Legend::color |
|
104 | \qmlproperty color Legend::color | |
105 | The color of the legend, i.e. the background (brush) color. |
|
105 | The color of the legend, i.e. the background (brush) color. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \property QLegend::borderColor |
|
109 | \property QLegend::borderColor | |
110 | The border color of the legend, i.e. the line color. |
|
110 | The border color of the legend, i.e. the line color. | |
111 | */ |
|
111 | */ | |
112 | /*! |
|
112 | /*! | |
113 | \qmlproperty color Legend::borderColor |
|
113 | \qmlproperty color Legend::borderColor | |
114 | The border color of the legend, i.e. the line color. |
|
114 | The border color of the legend, i.e. the line color. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \property QLegend::font |
|
118 | \property QLegend::font | |
119 | The font of markers used by legend |
|
119 | The font of markers used by legend | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty Font Legend::font |
|
122 | \qmlproperty Font Legend::font | |
123 | The font of markers used by legend |
|
123 | The font of markers used by legend | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \property QLegend::labelColor |
|
127 | \property QLegend::labelColor | |
128 | The color of brush used to draw labels. |
|
128 | The color of brush used to draw labels. | |
129 | */ |
|
129 | */ | |
130 | /*! |
|
130 | /*! | |
131 | \qmlproperty color QLegend::labelColor |
|
131 | \qmlproperty color QLegend::labelColor | |
132 | The color of brush used to draw labels. |
|
132 | The color of brush used to draw labels. | |
133 | */ |
|
133 | */ | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | \fn void QLegend::backgroundVisibleChanged(bool) |
|
136 | \fn void QLegend::backgroundVisibleChanged(bool) | |
137 | The visibility of the legend background changed to \a visible. |
|
137 | The visibility of the legend background changed to \a visible. | |
138 | */ |
|
138 | */ | |
139 |
|
139 | |||
140 | /*! |
|
140 | /*! | |
141 | \fn void QLegend::colorChanged(QColor) |
|
141 | \fn void QLegend::colorChanged(QColor) | |
142 | The color of the legend background changed to \a color. |
|
142 | The color of the legend background changed to \a color. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \fn void QLegend::borderColorChanged(QColor) |
|
146 | \fn void QLegend::borderColorChanged(QColor) | |
147 | The border color of the legend background changed to \a color. |
|
147 | The border color of the legend background changed to \a color. | |
148 | */ |
|
148 | */ | |
149 |
|
149 | |||
150 | /*! |
|
150 | /*! | |
151 | \fn void QLegend::fontChanged(QFont) |
|
151 | \fn void QLegend::fontChanged(QFont) | |
152 | The font of markers of the legend changed to \a font. |
|
152 | The font of markers of the legend changed to \a font. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QLegend::labelColorChanged(QColor color) |
|
156 | \fn void QLegend::labelColorChanged(QColor color) | |
157 | This signal is emitted when the color of brush used to draw labels has changed to \a color. |
|
157 | This signal is emitted when the color of brush used to draw labels has changed to \a color. | |
158 | */ |
|
158 | */ | |
159 |
|
159 | |||
160 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), |
|
160 | QLegend::QLegend(QChart *chart): QGraphicsWidget(chart), | |
161 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) |
|
161 | d_ptr(new QLegendPrivate(chart->d_ptr->m_presenter, chart, this)) | |
162 | { |
|
162 | { | |
163 | setZValue(ChartPresenter::LegendZValue); |
|
163 | setZValue(ChartPresenter::LegendZValue); | |
164 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
|
164 | setFlags(QGraphicsItem::ItemClipsChildrenToShape); | |
165 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
165 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesAdded(QAbstractSeries*))); | |
166 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
166 | QObject::connect(chart->d_ptr->m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), d_ptr.data(), SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
167 | setLayout(d_ptr->m_layout); |
|
167 | setLayout(d_ptr->m_layout); | |
168 | } |
|
168 | } | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. |
|
171 | Destroys the legend object. Legend is always owned by a QChart, so an application should never call this. | |
172 | */ |
|
172 | */ | |
173 | QLegend::~QLegend() |
|
173 | QLegend::~QLegend() | |
174 | { |
|
174 | { | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | \internal |
|
178 | \internal | |
179 | */ |
|
179 | */ | |
180 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
180 | void QLegend::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
181 | { |
|
181 | { | |
182 | Q_UNUSED(option) |
|
182 | Q_UNUSED(option) | |
183 | Q_UNUSED(widget) |
|
183 | Q_UNUSED(widget) | |
184 |
|
184 | |||
185 | if (!d_ptr->m_backgroundVisible) |
|
185 | if (!d_ptr->m_backgroundVisible) | |
186 | return; |
|
186 | return; | |
187 |
|
187 | |||
188 | painter->setOpacity(opacity()); |
|
188 | painter->setOpacity(opacity()); | |
189 | painter->setPen(d_ptr->m_pen); |
|
189 | painter->setPen(d_ptr->m_pen); | |
190 | painter->setBrush(d_ptr->m_brush); |
|
190 | painter->setBrush(d_ptr->m_brush); | |
191 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); |
|
191 | painter->drawRoundRect(rect(), d_ptr->roundness(rect().width()), d_ptr->roundness(rect().height())); | |
192 | } |
|
192 | } | |
193 |
|
193 | |||
194 |
|
194 | |||
195 | /*! |
|
195 | /*! | |
196 | Sets the \a brush of legend. Brush affects the background of legend. |
|
196 | Sets the \a brush of legend. Brush affects the background of legend. | |
197 | */ |
|
197 | */ | |
198 | void QLegend::setBrush(const QBrush &brush) |
|
198 | void QLegend::setBrush(const QBrush &brush) | |
199 | { |
|
199 | { | |
200 | if (d_ptr->m_brush != brush) { |
|
200 | if (d_ptr->m_brush != brush) { | |
201 | d_ptr->m_brush = brush; |
|
201 | d_ptr->m_brush = brush; | |
202 | update(); |
|
202 | update(); | |
203 | emit colorChanged(brush.color()); |
|
203 | emit colorChanged(brush.color()); | |
204 | } |
|
204 | } | |
205 | } |
|
205 | } | |
206 |
|
206 | |||
207 | /*! |
|
207 | /*! | |
208 | Returns the brush used by legend. |
|
208 | Returns the brush used by legend. | |
209 | */ |
|
209 | */ | |
210 | QBrush QLegend::brush() const |
|
210 | QBrush QLegend::brush() const | |
211 | { |
|
211 | { | |
212 | return d_ptr->m_brush; |
|
212 | return d_ptr->m_brush; | |
213 | } |
|
213 | } | |
214 |
|
214 | |||
215 | void QLegend::setColor(QColor color) |
|
215 | void QLegend::setColor(QColor color) | |
216 | { |
|
216 | { | |
217 | QBrush b = d_ptr->m_brush; |
|
217 | QBrush b = d_ptr->m_brush; | |
218 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
218 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
219 | b.setStyle(Qt::SolidPattern); |
|
219 | b.setStyle(Qt::SolidPattern); | |
220 | b.setColor(color); |
|
220 | b.setColor(color); | |
221 | setBrush(b); |
|
221 | setBrush(b); | |
222 | } |
|
222 | } | |
223 | } |
|
223 | } | |
224 |
|
224 | |||
225 | QColor QLegend::color() |
|
225 | QColor QLegend::color() | |
226 | { |
|
226 | { | |
227 | return d_ptr->m_brush.color(); |
|
227 | return d_ptr->m_brush.color(); | |
228 | } |
|
228 | } | |
229 |
|
229 | |||
230 | /*! |
|
230 | /*! | |
231 | Sets the \a pen of legend. Pen affects the legend borders. |
|
231 | Sets the \a pen of legend. Pen affects the legend borders. | |
232 | */ |
|
232 | */ | |
233 | void QLegend::setPen(const QPen &pen) |
|
233 | void QLegend::setPen(const QPen &pen) | |
234 | { |
|
234 | { | |
235 | if (d_ptr->m_pen != pen) { |
|
235 | if (d_ptr->m_pen != pen) { | |
236 | d_ptr->m_pen = pen; |
|
236 | d_ptr->m_pen = pen; | |
237 | update(); |
|
237 | update(); | |
238 | emit borderColorChanged(pen.color()); |
|
238 | emit borderColorChanged(pen.color()); | |
239 | } |
|
239 | } | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | /*! |
|
242 | /*! | |
243 | Returns the pen used by legend |
|
243 | Returns the pen used by legend | |
244 | */ |
|
244 | */ | |
245 |
|
245 | |||
246 | QPen QLegend::pen() const |
|
246 | QPen QLegend::pen() const | |
247 | { |
|
247 | { | |
248 | return d_ptr->m_pen; |
|
248 | return d_ptr->m_pen; | |
249 | } |
|
249 | } | |
250 |
|
250 | |||
251 | void QLegend::setFont(const QFont &font) |
|
251 | void QLegend::setFont(const QFont &font) | |
252 | { |
|
252 | { | |
253 | if (d_ptr->m_font != font) { |
|
253 | if (d_ptr->m_font != font) { | |
254 | d_ptr->m_font = font; |
|
254 | d_ptr->m_font = font; | |
255 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
255 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
256 | marker->setFont(d_ptr->m_font); |
|
256 | marker->setFont(d_ptr->m_font); | |
257 | } |
|
257 | } | |
258 | layout()->invalidate(); |
|
258 | layout()->invalidate(); | |
259 | emit fontChanged(font); |
|
259 | emit fontChanged(font); | |
260 | } |
|
260 | } | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 | QFont QLegend::font() const |
|
263 | QFont QLegend::font() const | |
264 | { |
|
264 | { | |
265 | return d_ptr->m_font; |
|
265 | return d_ptr->m_font; | |
266 | } |
|
266 | } | |
267 |
|
267 | |||
268 | void QLegend::setBorderColor(QColor color) |
|
268 | void QLegend::setBorderColor(QColor color) | |
269 | { |
|
269 | { | |
270 | QPen p = d_ptr->m_pen; |
|
270 | QPen p = d_ptr->m_pen; | |
271 | if (p.color() != color) { |
|
271 | if (p.color() != color) { | |
272 | p.setColor(color); |
|
272 | p.setColor(color); | |
273 | setPen(p); |
|
273 | setPen(p); | |
274 | } |
|
274 | } | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | QColor QLegend::borderColor() |
|
277 | QColor QLegend::borderColor() | |
278 | { |
|
278 | { | |
279 | return d_ptr->m_pen.color(); |
|
279 | return d_ptr->m_pen.color(); | |
280 | } |
|
280 | } | |
281 |
|
281 | |||
282 | /*! |
|
282 | /*! | |
283 | Set brush used to draw labels to \a brush. |
|
283 | Set brush used to draw labels to \a brush. | |
284 | */ |
|
284 | */ | |
285 | void QLegend::setLabelBrush(const QBrush &brush) |
|
285 | void QLegend::setLabelBrush(const QBrush &brush) | |
286 | { |
|
286 | { | |
287 | if (d_ptr->m_labelBrush != brush) { |
|
287 | if (d_ptr->m_labelBrush != brush) { | |
288 | d_ptr->m_labelBrush = brush; |
|
288 | d_ptr->m_labelBrush = brush; | |
289 | foreach (QLegendMarker *marker, d_ptr->markers()) { |
|
289 | foreach (QLegendMarker *marker, d_ptr->markers()) { | |
290 | marker->setLabelBrush(d_ptr->m_labelBrush); |
|
290 | marker->setLabelBrush(d_ptr->m_labelBrush); | |
291 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API |
|
291 | // Note: The pen of the marker rectangle could be exposed in the public QLegend API | |
292 | // instead of mapping it from label brush color |
|
292 | // instead of mapping it from label brush color | |
293 | marker->setPen(brush.color()); |
|
293 | marker->setPen(brush.color()); | |
294 | } |
|
294 | } | |
295 | emit labelColorChanged(brush.color()); |
|
295 | emit labelColorChanged(brush.color()); | |
296 | } |
|
296 | } | |
297 | } |
|
297 | } | |
298 |
|
298 | |||
299 | /*! |
|
299 | /*! | |
300 | Brush used to draw labels. |
|
300 | Brush used to draw labels. | |
301 | */ |
|
301 | */ | |
302 | QBrush QLegend::labelBrush() const |
|
302 | QBrush QLegend::labelBrush() const | |
303 | { |
|
303 | { | |
304 | return d_ptr->m_labelBrush; |
|
304 | return d_ptr->m_labelBrush; | |
305 | } |
|
305 | } | |
306 |
|
306 | |||
307 | void QLegend::setLabelColor(QColor color) |
|
307 | void QLegend::setLabelColor(QColor color) | |
308 | { |
|
308 | { | |
309 | QBrush b = d_ptr->m_labelBrush; |
|
309 | QBrush b = d_ptr->m_labelBrush; | |
310 | if (b.style() != Qt::SolidPattern || b.color() != color) { |
|
310 | if (b.style() != Qt::SolidPattern || b.color() != color) { | |
311 | b.setStyle(Qt::SolidPattern); |
|
311 | b.setStyle(Qt::SolidPattern); | |
312 | b.setColor(color); |
|
312 | b.setColor(color); | |
313 | setLabelBrush(b); |
|
313 | setLabelBrush(b); | |
314 | } |
|
314 | } | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | QColor QLegend::labelColor() const |
|
317 | QColor QLegend::labelColor() const | |
318 | { |
|
318 | { | |
319 | return d_ptr->m_labelBrush.color(); |
|
319 | return d_ptr->m_labelBrush.color(); | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 |
|
322 | |||
323 | void QLegend::setAlignment(Qt::Alignment alignment) |
|
323 | void QLegend::setAlignment(Qt::Alignment alignment) | |
324 | { |
|
324 | { | |
325 | if (d_ptr->m_alignment != alignment) { |
|
325 | if (d_ptr->m_alignment != alignment) { | |
326 | d_ptr->m_alignment = alignment; |
|
326 | d_ptr->m_alignment = alignment; | |
327 | layout()->invalidate(); |
|
327 | layout()->invalidate(); | |
328 | } |
|
328 | } | |
329 | } |
|
329 | } | |
330 |
|
330 | |||
331 | Qt::Alignment QLegend::alignment() const |
|
331 | Qt::Alignment QLegend::alignment() const | |
332 | { |
|
332 | { | |
333 | return d_ptr->m_alignment; |
|
333 | return d_ptr->m_alignment; | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | /*! |
|
336 | /*! | |
337 | Detaches the legend from chart. Chart won't change layout of the legend. |
|
337 | Detaches the legend from chart. Chart won't change layout of the legend. | |
338 | */ |
|
338 | */ | |
339 | void QLegend::detachFromChart() |
|
339 | void QLegend::detachFromChart() | |
340 | { |
|
340 | { | |
341 | d_ptr->m_attachedToChart = false; |
|
341 | d_ptr->m_attachedToChart = false; | |
342 | // layout()->invalidate(); |
|
342 | // layout()->invalidate(); | |
343 | d_ptr->m_chart->layout()->invalidate(); |
|
343 | d_ptr->m_chart->layout()->invalidate(); | |
344 | setParent(0); |
|
344 | setParent(0); | |
345 |
|
345 | |||
346 | } |
|
346 | } | |
347 |
|
347 | |||
348 | /*! |
|
348 | /*! | |
349 | Attaches the legend to chart. Chart may change layout of the legend. |
|
349 | Attaches the legend to chart. Chart may change layout of the legend. | |
350 | */ |
|
350 | */ | |
351 | void QLegend::attachToChart() |
|
351 | void QLegend::attachToChart() | |
352 | { |
|
352 | { | |
353 | d_ptr->m_attachedToChart = true; |
|
353 | d_ptr->m_attachedToChart = true; | |
354 | // layout()->invalidate(); |
|
354 | // layout()->invalidate(); | |
355 | d_ptr->m_chart->layout()->invalidate(); |
|
355 | d_ptr->m_chart->layout()->invalidate(); | |
356 | setParent(d_ptr->m_chart); |
|
356 | setParent(d_ptr->m_chart); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Returns true, if legend is attached to chart. |
|
360 | Returns true, if legend is attached to chart. | |
361 | */ |
|
361 | */ | |
362 | bool QLegend::isAttachedToChart() |
|
362 | bool QLegend::isAttachedToChart() | |
363 | { |
|
363 | { | |
364 | return d_ptr->m_attachedToChart; |
|
364 | return d_ptr->m_attachedToChart; | |
365 | } |
|
365 | } | |
366 |
|
366 | |||
367 | /*! |
|
367 | /*! | |
368 | Sets the visibility of legend background to \a visible |
|
368 | Sets the visibility of legend background to \a visible | |
369 | */ |
|
369 | */ | |
370 | void QLegend::setBackgroundVisible(bool visible) |
|
370 | void QLegend::setBackgroundVisible(bool visible) | |
371 | { |
|
371 | { | |
372 | if (d_ptr->m_backgroundVisible != visible) { |
|
372 | if (d_ptr->m_backgroundVisible != visible) { | |
373 | d_ptr->m_backgroundVisible = visible; |
|
373 | d_ptr->m_backgroundVisible = visible; | |
374 | update(); |
|
374 | update(); | |
375 | emit backgroundVisibleChanged(visible); |
|
375 | emit backgroundVisibleChanged(visible); | |
376 | } |
|
376 | } | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | /*! |
|
379 | /*! | |
380 | Returns the visibility of legend background |
|
380 | Returns the visibility of legend background | |
381 | */ |
|
381 | */ | |
382 | bool QLegend::isBackgroundVisible() const |
|
382 | bool QLegend::isBackgroundVisible() const | |
383 | { |
|
383 | { | |
384 | return d_ptr->m_backgroundVisible; |
|
384 | return d_ptr->m_backgroundVisible; | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | /*! |
|
387 | /*! | |
388 | Returns the list of markers in legend. The list can be filtered with \a series parameter. |
|
388 | Returns the list of markers in legend. The list can be filtered with \a series parameter. | |
389 | If \a series is given, only markers related to that series are returned. |
|
389 | If \a series is given, only markers related to that series are returned. | |
390 | */ |
|
390 | */ | |
391 | QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const |
|
391 | QList<QLegendMarker*> QLegend::markers(QAbstractSeries *series) const | |
392 | { |
|
392 | { | |
393 | return d_ptr->markers(series); |
|
393 | return d_ptr->markers(series); | |
394 | } |
|
394 | } | |
395 |
|
395 | |||
396 | /*! |
|
396 | /*! | |
397 | \internal \a event see QGraphicsWidget for details |
|
397 | \internal \a event see QGraphicsWidget for details | |
398 | */ |
|
398 | */ | |
399 | void QLegend::hideEvent(QHideEvent *event) |
|
399 | void QLegend::hideEvent(QHideEvent *event) | |
400 | { |
|
400 | { | |
401 | if (isAttachedToChart()) |
|
401 | if (isAttachedToChart()) | |
402 | d_ptr->m_presenter->layout()->invalidate(); |
|
402 | d_ptr->m_presenter->layout()->invalidate(); | |
403 | QGraphicsWidget::hideEvent(event); |
|
403 | QGraphicsWidget::hideEvent(event); | |
404 | } |
|
404 | } | |
405 | /*! |
|
405 | /*! | |
406 | \internal \a event see QGraphicsWidget for details |
|
406 | \internal \a event see QGraphicsWidget for details | |
407 | */ |
|
407 | */ | |
408 | void QLegend::showEvent(QShowEvent *event) |
|
408 | void QLegend::showEvent(QShowEvent *event) | |
409 | { |
|
409 | { | |
410 | if (isAttachedToChart()) { |
|
410 | if (isAttachedToChart()) { | |
411 | d_ptr->items()->setVisible(false); |
|
411 | d_ptr->items()->setVisible(false); | |
412 | layout()->invalidate(); |
|
412 | layout()->invalidate(); | |
413 | } |
|
413 | } | |
414 | QGraphicsWidget::showEvent(event); |
|
414 | QGraphicsWidget::showEvent(event); | |
415 | //layout activation will show the items |
|
415 | //layout activation will show the items | |
416 | } |
|
416 | } | |
417 |
|
417 | |||
418 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
418 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
419 |
|
419 | |||
420 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) |
|
420 | QLegendPrivate::QLegendPrivate(ChartPresenter *presenter, QChart *chart, QLegend *q) | |
421 | : q_ptr(q), |
|
421 | : q_ptr(q), | |
422 | m_presenter(presenter), |
|
422 | m_presenter(presenter), | |
423 | m_layout(new LegendLayout(q)), |
|
423 | m_layout(new LegendLayout(q)), | |
424 | m_chart(chart), |
|
424 | m_chart(chart), | |
425 | m_items(new QGraphicsItemGroup(q)), |
|
425 | m_items(new QGraphicsItemGroup(q)), | |
426 | m_alignment(Qt::AlignTop), |
|
426 | m_alignment(Qt::AlignTop), | |
427 | m_brush(QBrush()), |
|
427 | m_brush(QBrush()), | |
428 | m_pen(QPen()), |
|
428 | m_pen(QPen()), | |
429 | m_labelBrush(QBrush()), |
|
429 | m_labelBrush(QBrush()), | |
430 | m_diameter(5), |
|
430 | m_diameter(5), | |
431 | m_attachedToChart(true), |
|
431 | m_attachedToChart(true), | |
432 | m_backgroundVisible(false) |
|
432 | m_backgroundVisible(false) | |
433 | { |
|
433 | { | |
434 | m_items->setHandlesChildEvents(false); |
|
434 | m_items->setHandlesChildEvents(false); | |
435 | } |
|
435 | } | |
436 |
|
436 | |||
437 | QLegendPrivate::~QLegendPrivate() |
|
437 | QLegendPrivate::~QLegendPrivate() | |
438 | { |
|
438 | { | |
439 |
|
439 | |||
440 | } |
|
440 | } | |
441 |
|
441 | |||
442 | void QLegendPrivate::setOffset(const QPointF &offset) |
|
442 | void QLegendPrivate::setOffset(const QPointF &offset) | |
443 | { |
|
443 | { | |
444 | m_layout->setOffset(offset.x(), offset.y()); |
|
444 | m_layout->setOffset(offset.x(), offset.y()); | |
445 | } |
|
445 | } | |
446 |
|
446 | |||
447 | QPointF QLegendPrivate::offset() const |
|
447 | QPointF QLegendPrivate::offset() const | |
448 | { |
|
448 | { | |
449 | return m_layout->offset(); |
|
449 | return m_layout->offset(); | |
450 | } |
|
450 | } | |
451 |
|
451 | |||
452 | int QLegendPrivate::roundness(qreal size) |
|
452 | int QLegendPrivate::roundness(qreal size) | |
453 | { |
|
453 | { | |
454 | return 100 * m_diameter / int(size); |
|
454 | return 100 * m_diameter / int(size); | |
455 | } |
|
455 | } | |
456 |
|
456 | |||
457 | QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series) |
|
457 | QList<QLegendMarker*> QLegendPrivate::markers(QAbstractSeries *series) | |
458 | { |
|
458 | { | |
459 | // Return all markers |
|
459 | // Return all markers | |
460 | if (!series) { |
|
460 | if (!series) { | |
461 | return m_markers; |
|
461 | return m_markers; | |
462 | } |
|
462 | } | |
463 |
|
463 | |||
464 | // Create filtered list |
|
464 | // Create filtered list | |
465 | QList<QLegendMarker *> markers; |
|
465 | QList<QLegendMarker *> markers; | |
466 | foreach (QLegendMarker *marker, m_markers) { |
|
466 | foreach (QLegendMarker *marker, m_markers) { | |
467 | if (marker->series() == series) { |
|
467 | if (marker->series() == series) { | |
468 | markers.append(marker); |
|
468 | markers.append(marker); | |
469 | } |
|
469 | } | |
470 | } |
|
470 | } | |
471 | return markers; |
|
471 | return markers; | |
472 | } |
|
472 | } | |
473 |
|
473 | |||
474 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) |
|
474 | void QLegendPrivate::handleSeriesAdded(QAbstractSeries *series) | |
475 | { |
|
475 | { | |
476 | if (m_series.contains(series)) { |
|
476 | if (m_series.contains(series)) { | |
477 | return; |
|
477 | return; | |
478 | } |
|
478 | } | |
479 |
|
479 | |||
480 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); |
|
480 | QList<QLegendMarker*> newMarkers = series->d_ptr->createLegendMarkers(q_ptr); | |
481 | decorateMarkers(newMarkers); |
|
481 | decorateMarkers(newMarkers); | |
482 | addMarkers(newMarkers); |
|
482 | addMarkers(newMarkers); | |
483 |
|
483 | |||
484 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
484 | QObject::connect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
485 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
485 | QObject::connect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
486 |
|
486 | |||
487 | m_series.append(series); |
|
487 | m_series.append(series); | |
488 | m_items->setVisible(false); |
|
488 | m_items->setVisible(false); | |
489 | m_layout->invalidate(); |
|
489 | m_layout->invalidate(); | |
490 | } |
|
490 | } | |
491 |
|
491 | |||
492 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) |
|
492 | void QLegendPrivate::handleSeriesRemoved(QAbstractSeries *series) | |
493 | { |
|
493 | { | |
494 | if (m_series.contains(series)) { |
|
494 | if (m_series.contains(series)) { | |
495 | m_series.removeOne(series); |
|
495 | m_series.removeOne(series); | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | // Find out, which markers to remove |
|
498 | // Find out, which markers to remove | |
499 | QList<QLegendMarker *> removed; |
|
499 | QList<QLegendMarker *> removed; | |
500 | foreach (QLegendMarker *m, m_markers) { |
|
500 | foreach (QLegendMarker *m, m_markers) { | |
501 | if (m->series() == series) { |
|
501 | if (m->series() == series) { | |
502 | removed << m; |
|
502 | removed << m; | |
503 | } |
|
503 | } | |
504 | } |
|
504 | } | |
505 | removeMarkers(removed); |
|
505 | removeMarkers(removed); | |
506 |
|
506 | |||
507 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); |
|
507 | QObject::disconnect(series->d_ptr.data(), SIGNAL(countChanged()), this, SLOT(handleCountChanged())); | |
508 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); |
|
508 | QObject::disconnect(series, SIGNAL(visibleChanged()), this, SLOT(handleSeriesVisibleChanged())); | |
509 |
|
509 | |||
510 | m_layout->invalidate(); |
|
510 | m_layout->invalidate(); | |
511 | } |
|
511 | } | |
512 |
|
512 | |||
513 | void QLegendPrivate::handleSeriesVisibleChanged() |
|
513 | void QLegendPrivate::handleSeriesVisibleChanged() | |
514 | { |
|
514 | { | |
515 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); |
|
515 | QAbstractSeries *series = qobject_cast<QAbstractSeries *> (sender()); | |
516 | Q_ASSERT(series); |
|
516 | Q_ASSERT(series); | |
517 |
|
517 | |||
518 | foreach (QLegendMarker *marker, m_markers) { |
|
518 | foreach (QLegendMarker *marker, m_markers) { | |
519 | if (marker->series() == series) { |
|
519 | if (marker->series() == series) { | |
520 | marker->setVisible(series->isVisible()); |
|
520 | marker->setVisible(series->isVisible()); | |
521 | } |
|
521 | } | |
522 | } |
|
522 | } | |
523 | m_layout->invalidate(); |
|
523 | m_layout->invalidate(); | |
524 | } |
|
524 | } | |
525 |
|
525 | |||
526 | void QLegendPrivate::handleCountChanged() |
|
526 | void QLegendPrivate::handleCountChanged() | |
527 | { |
|
527 | { | |
528 | // Here we handle the changes in marker count. |
|
528 | // Here we handle the changes in marker count. | |
529 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. |
|
529 | // Can happen for example when pieslice(s) have been added to or removed from pieseries. | |
530 |
|
530 | |||
531 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); |
|
531 | QAbstractSeriesPrivate *series = qobject_cast<QAbstractSeriesPrivate *> (sender()); | |
532 | QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr); |
|
532 | QList<QLegendMarker *> createdMarkers = series->createLegendMarkers(q_ptr); | |
533 |
|
533 | |||
534 | // Find out removed markers and created markers |
|
534 | // Find out removed markers and created markers | |
535 | QList<QLegendMarker *> removedMarkers; |
|
535 | QList<QLegendMarker *> removedMarkers; | |
536 | foreach (QLegendMarker *oldMarker, m_markers) { |
|
536 | foreach (QLegendMarker *oldMarker, m_markers) { | |
537 | // we have marker, which is related to sender. |
|
537 | // we have marker, which is related to sender. | |
538 | if (oldMarker->series() == series->q_ptr) { |
|
538 | if (oldMarker->series() == series->q_ptr) { | |
539 | bool found = false; |
|
539 | bool found = false; | |
540 | foreach(QLegendMarker *newMarker, createdMarkers) { |
|
540 | foreach(QLegendMarker *newMarker, createdMarkers) { | |
541 | // New marker considered existing if: |
|
541 | // New marker considered existing if: | |
542 | // - d_ptr->relatedObject() is same for both markers. |
|
542 | // - d_ptr->relatedObject() is same for both markers. | |
543 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { |
|
543 | if (newMarker->d_ptr->relatedObject() == oldMarker->d_ptr->relatedObject()) { | |
544 | // Delete the new marker, since we already have existing marker, that might be connected on user side. |
|
544 | // Delete the new marker, since we already have existing marker, that might be connected on user side. | |
545 | found = true; |
|
545 | found = true; | |
546 | createdMarkers.removeOne(newMarker); |
|
546 | createdMarkers.removeOne(newMarker); | |
547 | delete newMarker; |
|
547 | delete newMarker; | |
548 | } |
|
548 | } | |
549 | } |
|
549 | } | |
550 | if (!found) { |
|
550 | if (!found) { | |
551 | // No related object found for marker, add to removedMarkers list |
|
551 | // No related object found for marker, add to removedMarkers list | |
552 | removedMarkers << oldMarker; |
|
552 | removedMarkers << oldMarker; | |
553 | } |
|
553 | } | |
554 | } |
|
554 | } | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | removeMarkers(removedMarkers); |
|
557 | removeMarkers(removedMarkers); | |
558 | decorateMarkers(createdMarkers); |
|
558 | decorateMarkers(createdMarkers); | |
559 | addMarkers(createdMarkers); |
|
559 | addMarkers(createdMarkers); | |
560 |
|
560 | |||
561 | q_ptr->layout()->invalidate(); |
|
561 | q_ptr->layout()->invalidate(); | |
562 | } |
|
562 | } | |
563 |
|
563 | |||
564 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) |
|
564 | void QLegendPrivate::addMarkers(QList<QLegendMarker *> markers) | |
565 | { |
|
565 | { | |
566 | foreach (QLegendMarker *marker, markers) { |
|
566 | foreach (QLegendMarker *marker, markers) { | |
567 | m_items->addToGroup(marker->d_ptr.data()->item()); |
|
567 | m_items->addToGroup(marker->d_ptr.data()->item()); | |
568 | m_markers << marker; |
|
568 | m_markers << marker; | |
569 | m_markerHash.insert(marker->d_ptr->item(), marker); |
|
569 | m_markerHash.insert(marker->d_ptr->item(), marker); | |
570 | } |
|
570 | } | |
571 | } |
|
571 | } | |
572 |
|
572 | |||
573 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) |
|
573 | void QLegendPrivate::removeMarkers(QList<QLegendMarker *> markers) | |
574 | { |
|
574 | { | |
575 | foreach (QLegendMarker *marker, markers) { |
|
575 | foreach (QLegendMarker *marker, markers) { | |
576 | marker->d_ptr->item()->setVisible(false); |
|
576 | marker->d_ptr->item()->setVisible(false); | |
577 | m_items->removeFromGroup(marker->d_ptr->item()); |
|
577 | m_items->removeFromGroup(marker->d_ptr->item()); | |
578 | m_markers.removeOne(marker); |
|
578 | m_markers.removeOne(marker); | |
579 | m_markerHash.remove(marker->d_ptr->item()); |
|
579 | m_markerHash.remove(marker->d_ptr->item()); | |
580 | delete marker; |
|
580 | delete marker; | |
581 | } |
|
581 | } | |
582 | } |
|
582 | } | |
583 |
|
583 | |||
584 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) |
|
584 | void QLegendPrivate::decorateMarkers(QList<QLegendMarker *> markers) | |
585 | { |
|
585 | { | |
586 | foreach (QLegendMarker *marker, markers) { |
|
586 | foreach (QLegendMarker *marker, markers) { | |
587 | marker->setFont(m_font); |
|
587 | marker->setFont(m_font); | |
588 | marker->setLabelBrush(m_labelBrush); |
|
588 | marker->setLabelBrush(m_labelBrush); | |
589 | } |
|
589 | } | |
590 | } |
|
590 | } | |
591 |
|
591 | |||
592 |
|
592 | |||
593 | #include "moc_qlegend.cpp" |
|
593 | #include "moc_qlegend.cpp" | |
594 | #include "moc_qlegend_p.cpp" |
|
594 | #include "moc_qlegend_p.cpp" | |
595 |
|
595 | |||
596 | QTCOMMERCIALCHART_END_NAMESPACE |
|
596 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,257 +1,257 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qhpiemodelmapper.h" |
|
21 | #include "qhpiemodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QHPieModelMapper |
|
26 | \class QHPieModelMapper | |
27 | \mainclass |
|
27 | \mainclass | |
28 |
|
28 | |||
29 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
29 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
30 | Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows. |
|
30 | Horizontal model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in rows. | |
31 | It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync. |
|
31 | It is possible to use both QAbstractItemModel and QPieSeries model API. QHPieModelMapper makes sure that Pie and the model are kept in sync. | |
32 |
|
|
32 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. | |
33 | */ |
|
33 | */ | |
34 | /*! |
|
34 | /*! | |
35 | \qmlclass HPieModelMapper QHPieModelMapper |
|
35 | \qmlclass HPieModelMapper QHPieModelMapper | |
36 |
|
36 | |||
37 | HPieModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source |
|
37 | HPieModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source | |
38 | for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data. |
|
38 | for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data. | |
39 | HPieModelMapper keeps the Pie and the model in sync. |
|
39 | HPieModelMapper keeps the Pie and the model in sync. | |
40 |
|
40 | |||
41 | The following QML example would create a pie series with four slices (assuming the model has |
|
41 | The following QML example would create a pie series with four slices (assuming the model has | |
42 | at least five columns). Each slice would contain a label from row 1 and a value from row 2. |
|
42 | at least five columns). Each slice would contain a label from row 1 and a value from row 2. | |
43 | \code |
|
43 | \code | |
44 | HPieModelMapper { |
|
44 | HPieModelMapper { | |
45 | series: pieSeries |
|
45 | series: pieSeries | |
46 | model: customModel |
|
46 | model: customModel | |
47 | labelsRow: 1 |
|
47 | labelsRow: 1 | |
48 | valuesRow: 2 |
|
48 | valuesRow: 2 | |
49 | firstColumn: 1 |
|
49 | firstColumn: 1 | |
50 | columnCount: 4 |
|
50 | columnCount: 4 | |
51 | } |
|
51 | } | |
52 | \endcode |
|
52 | \endcode | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \property QHPieModelMapper::series |
|
56 | \property QHPieModelMapper::series | |
57 | \brief Defines the QPieSeries object that is used by the mapper. |
|
57 | \brief Defines the QPieSeries object that is used by the mapper. | |
58 |
|
58 | |||
59 | All the data in the series is discarded when it is set to the mapper. |
|
59 | All the data in the series is discarded when it is set to the mapper. | |
60 | When new series is specified the old series is disconnected (it preserves its data) |
|
60 | When new series is specified the old series is disconnected (it preserves its data) | |
61 | */ |
|
61 | */ | |
62 | /*! |
|
62 | /*! | |
63 | \qmlproperty PieSeries HPieModelMapper::series |
|
63 | \qmlproperty PieSeries HPieModelMapper::series | |
64 | Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a |
|
64 | Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a | |
65 | PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper. |
|
65 | PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper. | |
66 | When new series is specified the old series is disconnected (it preserves its data). |
|
66 | When new series is specified the old series is disconnected (it preserves its data). | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \property QHPieModelMapper::model |
|
70 | \property QHPieModelMapper::model | |
71 | \brief Defines the model that is used by the mapper. |
|
71 | \brief Defines the model that is used by the mapper. | |
72 | */ |
|
72 | */ | |
73 | /*! |
|
73 | /*! | |
74 | \qmlproperty SomeModel HPieModelMapper::model |
|
74 | \qmlproperty SomeModel HPieModelMapper::model | |
75 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
75 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
76 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns |
|
76 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns | |
77 | and modifying the data of the cells. |
|
77 | and modifying the data of the cells. | |
78 | */ |
|
78 | */ | |
79 |
|
79 | |||
80 | /*! |
|
80 | /*! | |
81 | \property QHPieModelMapper::valuesRow |
|
81 | \property QHPieModelMapper::valuesRow | |
82 | \brief Defines which row of the model is kept in sync with the values of the pie's slices |
|
82 | \brief Defines which row of the model is kept in sync with the values of the pie's slices | |
83 | Default value is: -1 (invalid mapping) |
|
83 | Default value is: -1 (invalid mapping) | |
84 | */ |
|
84 | */ | |
85 | /*! |
|
85 | /*! | |
86 | \qmlproperty int HPieModelMapper::valuesRow |
|
86 | \qmlproperty int HPieModelMapper::valuesRow | |
87 | Defines which row of the model is kept in sync with the values of the pie's slices. Default value is: -1 (invalid |
|
87 | Defines which row of the model is kept in sync with the values of the pie's slices. Default value is: -1 (invalid | |
88 | mapping). |
|
88 | mapping). | |
89 | */ |
|
89 | */ | |
90 |
|
90 | |||
91 | /*! |
|
91 | /*! | |
92 | \property QHPieModelMapper::labelsRow |
|
92 | \property QHPieModelMapper::labelsRow | |
93 | \brief Defines which row of the model is kept in sync with the labels of the pie's slices |
|
93 | \brief Defines which row of the model is kept in sync with the labels of the pie's slices | |
94 | Default value is: -1 (invalid mapping) |
|
94 | Default value is: -1 (invalid mapping) | |
95 | */ |
|
95 | */ | |
96 | /*! |
|
96 | /*! | |
97 | \qmlproperty int HPieModelMapper::labelsRow |
|
97 | \qmlproperty int HPieModelMapper::labelsRow | |
98 | Defines which row of the model is kept in sync with the labels of the pie's slices |
|
98 | Defines which row of the model is kept in sync with the labels of the pie's slices | |
99 | Default value is: -1 (invalid mapping) |
|
99 | Default value is: -1 (invalid mapping) | |
100 | */ |
|
100 | */ | |
101 |
|
101 | |||
102 | /*! |
|
102 | /*! | |
103 | \property QHPieModelMapper::firstColumn |
|
103 | \property QHPieModelMapper::firstColumn | |
104 | \brief Defines which column of the model contains the first slice value. |
|
104 | \brief Defines which column of the model contains the first slice value. | |
105 | Minimal and default value is: 0 |
|
105 | Minimal and default value is: 0 | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty int HPieModelMapper::firstColumn |
|
108 | \qmlproperty int HPieModelMapper::firstColumn | |
109 | Defines which column of the model contains the first slice value. |
|
109 | Defines which column of the model contains the first slice value. | |
110 | The default value is 0. |
|
110 | The default value is 0. | |
111 | */ |
|
111 | */ | |
112 |
|
112 | |||
113 | /*! |
|
113 | /*! | |
114 | \property QHPieModelMapper::columnCount |
|
114 | \property QHPieModelMapper::columnCount | |
115 | \brief Defines the number of columns of the model that are mapped as the data for QPieSeries |
|
115 | \brief Defines the number of columns of the model that are mapped as the data for QPieSeries | |
116 | Minimal and default value is: -1 (count limited by the number of columns in the model) |
|
116 | Minimal and default value is: -1 (count limited by the number of columns in the model) | |
117 | */ |
|
117 | */ | |
118 | /*! |
|
118 | /*! | |
119 | \qmlproperty int HPieModelMapper::columnCount |
|
119 | \qmlproperty int HPieModelMapper::columnCount | |
120 | Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is |
|
120 | Defines the number of columns of the model that are mapped as the data for QPieSeries. The default value is | |
121 | -1 (count limited by the number of columns in the model) |
|
121 | -1 (count limited by the number of columns in the model) | |
122 | */ |
|
122 | */ | |
123 |
|
123 | |||
124 | /*! |
|
124 | /*! | |
125 | \fn void QHPieModelMapper::seriesReplaced() |
|
125 | \fn void QHPieModelMapper::seriesReplaced() | |
126 | Emitted when the series to which mapper is connected to has changed. |
|
126 | Emitted when the series to which mapper is connected to has changed. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QHPieModelMapper::modelReplaced() |
|
130 | \fn void QHPieModelMapper::modelReplaced() | |
131 | Emitted when the model to which mapper is connected to has changed. |
|
131 | Emitted when the model to which mapper is connected to has changed. | |
132 | */ |
|
132 | */ | |
133 |
|
133 | |||
134 | /*! |
|
134 | /*! | |
135 | \fn void QHPieModelMapper::valuesRowChanged() |
|
135 | \fn void QHPieModelMapper::valuesRowChanged() | |
136 | Emitted when the valuesRow has changed. |
|
136 | Emitted when the valuesRow has changed. | |
137 | */ |
|
137 | */ | |
138 |
|
138 | |||
139 | /*! |
|
139 | /*! | |
140 | \fn void QHPieModelMapper::labelsRowChanged() |
|
140 | \fn void QHPieModelMapper::labelsRowChanged() | |
141 | Emitted when the labelsRow has changed. |
|
141 | Emitted when the labelsRow has changed. | |
142 | */ |
|
142 | */ | |
143 |
|
143 | |||
144 | /*! |
|
144 | /*! | |
145 | \fn void QHPieModelMapper::firstColumnChanged() |
|
145 | \fn void QHPieModelMapper::firstColumnChanged() | |
146 | Emitted when the firstColumn has changed. |
|
146 | Emitted when the firstColumn has changed. | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QHPieModelMapper::columnCountChanged() |
|
150 | \fn void QHPieModelMapper::columnCountChanged() | |
151 | Emitted when the columnCount has changed. |
|
151 | Emitted when the columnCount has changed. | |
152 | */ |
|
152 | */ | |
153 |
|
153 | |||
154 | /*! |
|
154 | /*! | |
155 | Constructs a mapper object which is a child of \a parent. |
|
155 | Constructs a mapper object which is a child of \a parent. | |
156 | */ |
|
156 | */ | |
157 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : |
|
157 | QHPieModelMapper::QHPieModelMapper(QObject *parent) : | |
158 | QPieModelMapper(parent) |
|
158 | QPieModelMapper(parent) | |
159 | { |
|
159 | { | |
160 | setOrientation(Qt::Horizontal); |
|
160 | setOrientation(Qt::Horizontal); | |
161 | } |
|
161 | } | |
162 |
|
162 | |||
163 | QAbstractItemModel *QHPieModelMapper::model() const |
|
163 | QAbstractItemModel *QHPieModelMapper::model() const | |
164 | { |
|
164 | { | |
165 | return QPieModelMapper::model(); |
|
165 | return QPieModelMapper::model(); | |
166 | } |
|
166 | } | |
167 |
|
167 | |||
168 | void QHPieModelMapper::setModel(QAbstractItemModel *model) |
|
168 | void QHPieModelMapper::setModel(QAbstractItemModel *model) | |
169 | { |
|
169 | { | |
170 | if (model != QPieModelMapper::model()) { |
|
170 | if (model != QPieModelMapper::model()) { | |
171 | QPieModelMapper::setModel(model); |
|
171 | QPieModelMapper::setModel(model); | |
172 | emit modelReplaced(); |
|
172 | emit modelReplaced(); | |
173 | } |
|
173 | } | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | QPieSeries *QHPieModelMapper::series() const |
|
176 | QPieSeries *QHPieModelMapper::series() const | |
177 | { |
|
177 | { | |
178 | return QPieModelMapper::series(); |
|
178 | return QPieModelMapper::series(); | |
179 | } |
|
179 | } | |
180 |
|
180 | |||
181 | void QHPieModelMapper::setSeries(QPieSeries *series) |
|
181 | void QHPieModelMapper::setSeries(QPieSeries *series) | |
182 | { |
|
182 | { | |
183 | if (series != QPieModelMapper::series()) { |
|
183 | if (series != QPieModelMapper::series()) { | |
184 | QPieModelMapper::setSeries(series); |
|
184 | QPieModelMapper::setSeries(series); | |
185 | emit seriesReplaced(); |
|
185 | emit seriesReplaced(); | |
186 | } |
|
186 | } | |
187 | } |
|
187 | } | |
188 |
|
188 | |||
189 | /*! |
|
189 | /*! | |
190 | Returns which row of the model is kept in sync with the values of the pie's slices |
|
190 | Returns which row of the model is kept in sync with the values of the pie's slices | |
191 | */ |
|
191 | */ | |
192 | int QHPieModelMapper::valuesRow() const |
|
192 | int QHPieModelMapper::valuesRow() const | |
193 | { |
|
193 | { | |
194 | return valuesSection(); |
|
194 | return valuesSection(); | |
195 | } |
|
195 | } | |
196 |
|
196 | |||
197 | /*! |
|
197 | /*! | |
198 | Sets the model row that is kept in sync with the pie slices values. |
|
198 | Sets the model row that is kept in sync with the pie slices values. | |
199 | Parameter \a valuesRow specifies the row of the model. |
|
199 | Parameter \a valuesRow specifies the row of the model. | |
200 | */ |
|
200 | */ | |
201 | void QHPieModelMapper::setValuesRow(int valuesRow) |
|
201 | void QHPieModelMapper::setValuesRow(int valuesRow) | |
202 | { |
|
202 | { | |
203 | if (valuesRow != valuesSection()) { |
|
203 | if (valuesRow != valuesSection()) { | |
204 | setValuesSection(valuesRow); |
|
204 | setValuesSection(valuesRow); | |
205 | emit valuesRowChanged(); |
|
205 | emit valuesRowChanged(); | |
206 | } |
|
206 | } | |
207 | } |
|
207 | } | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | Returns which row of the model is kept in sync with the labels of the pie's slices |
|
210 | Returns which row of the model is kept in sync with the labels of the pie's slices | |
211 | */ |
|
211 | */ | |
212 | int QHPieModelMapper::labelsRow() const |
|
212 | int QHPieModelMapper::labelsRow() const | |
213 | { |
|
213 | { | |
214 | return labelsSection(); |
|
214 | return labelsSection(); | |
215 | } |
|
215 | } | |
216 |
|
216 | |||
217 | /*! |
|
217 | /*! | |
218 | Sets the model row that is kept in sync with the pie's slices labels. |
|
218 | Sets the model row that is kept in sync with the pie's slices labels. | |
219 | Parameter \a labelsRow specifies the row of the model. |
|
219 | Parameter \a labelsRow specifies the row of the model. | |
220 | */ |
|
220 | */ | |
221 | void QHPieModelMapper::setLabelsRow(int labelsRow) |
|
221 | void QHPieModelMapper::setLabelsRow(int labelsRow) | |
222 | { |
|
222 | { | |
223 | if (labelsRow != labelsSection()) { |
|
223 | if (labelsRow != labelsSection()) { | |
224 | setLabelsSection(labelsRow); |
|
224 | setLabelsSection(labelsRow); | |
225 | emit labelsRowChanged(); |
|
225 | emit labelsRowChanged(); | |
226 | } |
|
226 | } | |
227 | } |
|
227 | } | |
228 |
|
228 | |||
229 | int QHPieModelMapper::firstColumn() const |
|
229 | int QHPieModelMapper::firstColumn() const | |
230 | { |
|
230 | { | |
231 | return first(); |
|
231 | return first(); | |
232 | } |
|
232 | } | |
233 |
|
233 | |||
234 | void QHPieModelMapper::setFirstColumn(int firstColumn) |
|
234 | void QHPieModelMapper::setFirstColumn(int firstColumn) | |
235 | { |
|
235 | { | |
236 | if (firstColumn != first()) { |
|
236 | if (firstColumn != first()) { | |
237 | setFirst(firstColumn); |
|
237 | setFirst(firstColumn); | |
238 | emit firstColumnChanged(); |
|
238 | emit firstColumnChanged(); | |
239 | } |
|
239 | } | |
240 | } |
|
240 | } | |
241 |
|
241 | |||
242 | int QHPieModelMapper::columnCount() const |
|
242 | int QHPieModelMapper::columnCount() const | |
243 | { |
|
243 | { | |
244 | return count(); |
|
244 | return count(); | |
245 | } |
|
245 | } | |
246 |
|
246 | |||
247 | void QHPieModelMapper::setColumnCount(int columnCount) |
|
247 | void QHPieModelMapper::setColumnCount(int columnCount) | |
248 | { |
|
248 | { | |
249 | if (columnCount != count()) { |
|
249 | if (columnCount != count()) { | |
250 | setCount(columnCount); |
|
250 | setCount(columnCount); | |
251 | emit columnCountChanged(); |
|
251 | emit columnCountChanged(); | |
252 | } |
|
252 | } | |
253 | } |
|
253 | } | |
254 |
|
254 | |||
255 | #include "moc_qhpiemodelmapper.cpp" |
|
255 | #include "moc_qhpiemodelmapper.cpp" | |
256 |
|
256 | |||
257 | QTCOMMERCIALCHART_END_NAMESPACE |
|
257 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,937 +1,937 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpieseries.h" |
|
21 | #include "qpieseries.h" | |
22 | #include "qpieseries_p.h" |
|
22 | #include "qpieseries_p.h" | |
23 | #include "qpieslice.h" |
|
23 | #include "qpieslice.h" | |
24 | #include "qpieslice_p.h" |
|
24 | #include "qpieslice_p.h" | |
25 | #include "pieslicedata_p.h" |
|
25 | #include "pieslicedata_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qabstractaxis.h" |
|
28 | #include "qabstractaxis.h" | |
29 | #include "pieanimation_p.h" |
|
29 | #include "pieanimation_p.h" | |
30 | #include "charthelpers_p.h" |
|
30 | #include "charthelpers_p.h" | |
31 |
|
31 | |||
32 | #include "qpielegendmarker.h" |
|
32 | #include "qpielegendmarker.h" | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QPieSeries |
|
37 | \class QPieSeries | |
38 | \brief Pie series API for QtCommercial Charts |
|
38 | \brief Pie series API for QtCommercial Charts | |
39 |
|
39 | |||
40 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. |
|
40 | The pie series defines a pie chart which consists of pie slices which are defined as QPieSlice objects. | |
41 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. |
|
41 | The slices can have any values as the QPieSeries will calculate its relative value to the sum of all slices. | |
42 | The actual slice size is determined by that relative value. |
|
42 | The actual slice size is determined by that relative value. | |
43 |
|
43 | |||
44 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0 |
|
44 | Pie size and position on the chart is controlled by using relative values which range from 0.0 to 1.0. | |
45 | These relate to the actual chart rectangle. |
|
45 | These relate to the actual chart rectangle. | |
46 |
|
46 | |||
47 | By default the pie is defined as a full pie but it can also be a partial pie. |
|
47 | By default the pie is defined as a full pie but it can also be a partial pie. | |
48 | This can be done by setting a starting angle and angle span to the series. |
|
48 | This can be done by setting a starting angle and angle span to the series. | |
49 | Full pie is 360 degrees where 0 is at 12 a'clock. |
|
49 | Full pie is 360 degrees where 0 is at 12 a'clock. | |
50 |
|
50 | |||
51 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. |
|
51 | See the \l {PieChart Example} {pie chart example} or \l {DonutChart Example} {donut chart example} to learn how to use QPieSeries. | |
52 | \table 100% |
|
52 | \table 100% | |
53 | \row |
|
53 | \row | |
54 | \o \image examples_piechart.png |
|
54 | \o \image examples_piechart.png | |
55 | \o \image examples_donutchart.png |
|
55 | \o \image examples_donutchart.png | |
56 | \endtable |
|
56 | \endtable | |
57 | */ |
|
57 | */ | |
58 | /*! |
|
58 | /*! | |
59 | \qmlclass PieSeries QPieSeries |
|
59 | \qmlclass PieSeries QPieSeries | |
60 | \inherits AbstractSeries |
|
60 | \inherits AbstractSeries | |
61 |
|
61 | |||
62 | The following QML shows how to create a simple pie chart. |
|
62 | The following QML shows how to create a simple pie chart. | |
63 |
|
63 | |||
64 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 |
|
64 | \snippet ../demos/qmlchart/qml/qmlchart/View1.qml 1 | |
65 |
|
65 | |||
66 | \beginfloatleft |
|
66 | \beginfloatleft | |
67 | \image demos_qmlchart1.png |
|
67 | \image demos_qmlchart1.png | |
68 | \endfloat |
|
68 | \endfloat | |
69 | \clearfloat |
|
69 | \clearfloat | |
70 | */ |
|
70 | */ | |
71 |
|
71 | |||
72 | /*! |
|
72 | /*! | |
73 | \property QPieSeries::horizontalPosition |
|
73 | \property QPieSeries::horizontalPosition | |
74 | \brief Defines the horizontal position of the pie. |
|
74 | \brief Defines the horizontal position of the pie. | |
75 |
|
75 | |||
76 | The value is a relative value to the chart rectangle where: |
|
76 | The value is a relative value to the chart rectangle where: | |
77 |
|
77 | |||
78 | \list |
|
78 | \list | |
79 | \o 0.0 is the absolute left. |
|
79 | \o 0.0 is the absolute left. | |
80 | \o 1.0 is the absolute right. |
|
80 | \o 1.0 is the absolute right. | |
81 | \endlist |
|
81 | \endlist | |
82 | Default value is 0.5 (center). |
|
82 | Default value is 0.5 (center). | |
83 | \sa verticalPosition |
|
83 | \sa verticalPosition | |
84 | */ |
|
84 | */ | |
85 |
|
85 | |||
86 | /*! |
|
86 | /*! | |
87 | \qmlproperty real PieSeries::horizontalPosition |
|
87 | \qmlproperty real PieSeries::horizontalPosition | |
88 |
|
88 | |||
89 | Defines the horizontal position of the pie. |
|
89 | Defines the horizontal position of the pie. | |
90 |
|
90 | |||
91 | The value is a relative value to the chart rectangle where: |
|
91 | The value is a relative value to the chart rectangle where: | |
92 |
|
92 | |||
93 | \list |
|
93 | \list | |
94 | \o 0.0 is the absolute left. |
|
94 | \o 0.0 is the absolute left. | |
95 | \o 1.0 is the absolute right. |
|
95 | \o 1.0 is the absolute right. | |
96 | \endlist |
|
96 | \endlist | |
97 | Default value is 0.5 (center). |
|
97 | Default value is 0.5 (center). | |
98 | \sa verticalPosition |
|
98 | \sa verticalPosition | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \property QPieSeries::verticalPosition |
|
102 | \property QPieSeries::verticalPosition | |
103 | \brief Defines the vertical position of the pie. |
|
103 | \brief Defines the vertical position of the pie. | |
104 |
|
104 | |||
105 | The value is a relative value to the chart rectangle where: |
|
105 | The value is a relative value to the chart rectangle where: | |
106 |
|
106 | |||
107 | \list |
|
107 | \list | |
108 | \o 0.0 is the absolute top. |
|
108 | \o 0.0 is the absolute top. | |
109 | \o 1.0 is the absolute bottom. |
|
109 | \o 1.0 is the absolute bottom. | |
110 | \endlist |
|
110 | \endlist | |
111 | Default value is 0.5 (center). |
|
111 | Default value is 0.5 (center). | |
112 | \sa horizontalPosition |
|
112 | \sa horizontalPosition | |
113 | */ |
|
113 | */ | |
114 |
|
114 | |||
115 | /*! |
|
115 | /*! | |
116 | \qmlproperty real PieSeries::verticalPosition |
|
116 | \qmlproperty real PieSeries::verticalPosition | |
117 |
|
117 | |||
118 | Defines the vertical position of the pie. |
|
118 | Defines the vertical position of the pie. | |
119 |
|
119 | |||
120 | The value is a relative value to the chart rectangle where: |
|
120 | The value is a relative value to the chart rectangle where: | |
121 |
|
121 | |||
122 | \list |
|
122 | \list | |
123 | \o 0.0 is the absolute top. |
|
123 | \o 0.0 is the absolute top. | |
124 | \o 1.0 is the absolute bottom. |
|
124 | \o 1.0 is the absolute bottom. | |
125 | \endlist |
|
125 | \endlist | |
126 | Default value is 0.5 (center). |
|
126 | Default value is 0.5 (center). | |
127 | \sa horizontalPosition |
|
127 | \sa horizontalPosition | |
128 | */ |
|
128 | */ | |
129 |
|
129 | |||
130 | /*! |
|
130 | /*! | |
131 | \property QPieSeries::size |
|
131 | \property QPieSeries::size | |
132 | \brief Defines the pie size. |
|
132 | \brief Defines the pie size. | |
133 |
|
133 | |||
134 | The value is a relative value to the chart rectangle where: |
|
134 | The value is a relative value to the chart rectangle where: | |
135 |
|
135 | |||
136 | \list |
|
136 | \list | |
137 | \o 0.0 is the minimum size (pie not drawn). |
|
137 | \o 0.0 is the minimum size (pie not drawn). | |
138 | \o 1.0 is the maximum size that can fit the chart. |
|
138 | \o 1.0 is the maximum size that can fit the chart. | |
139 | \endlist |
|
139 | \endlist | |
140 |
|
140 | |||
141 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. |
|
141 | When setting this property the holeSize property is adjusted if necessary, to ensure that the hole size is not greater than the outer size. | |
142 |
|
142 | |||
143 | Default value is 0.7. |
|
143 | Default value is 0.7. | |
144 | */ |
|
144 | */ | |
145 |
|
145 | |||
146 | /*! |
|
146 | /*! | |
147 | \qmlproperty real PieSeries::size |
|
147 | \qmlproperty real PieSeries::size | |
148 |
|
148 | |||
149 | Defines the pie size. |
|
149 | Defines the pie size. | |
150 |
|
150 | |||
151 | The value is a relative value to the chart rectangle where: |
|
151 | The value is a relative value to the chart rectangle where: | |
152 |
|
152 | |||
153 | \list |
|
153 | \list | |
154 | \o 0.0 is the minimum size (pie not drawn). |
|
154 | \o 0.0 is the minimum size (pie not drawn). | |
155 | \o 1.0 is the maximum size that can fit the chart. |
|
155 | \o 1.0 is the maximum size that can fit the chart. | |
156 | \endlist |
|
156 | \endlist | |
157 |
|
157 | |||
158 | Default value is 0.7. |
|
158 | Default value is 0.7. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \property QPieSeries::holeSize |
|
162 | \property QPieSeries::holeSize | |
163 | \brief Defines the donut hole size. |
|
163 | \brief Defines the donut hole size. | |
164 |
|
164 | |||
165 | The value is a relative value to the chart rectangle where: |
|
165 | The value is a relative value to the chart rectangle where: | |
166 |
|
166 | |||
167 | \list |
|
167 | \list | |
168 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
168 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
169 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
169 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
170 | \endlist |
|
170 | \endlist | |
171 |
|
171 | |||
172 | The value is never greater then size property. |
|
172 | The value is never greater then size property. | |
173 | Default value is 0.0. |
|
173 | Default value is 0.0. | |
174 | */ |
|
174 | */ | |
175 |
|
175 | |||
176 | /*! |
|
176 | /*! | |
177 | \qmlproperty real PieSeries::holeSize |
|
177 | \qmlproperty real PieSeries::holeSize | |
178 |
|
178 | |||
179 | Defines the donut hole size. |
|
179 | Defines the donut hole size. | |
180 |
|
180 | |||
181 | The value is a relative value to the chart rectangle where: |
|
181 | The value is a relative value to the chart rectangle where: | |
182 |
|
182 | |||
183 | \list |
|
183 | \list | |
184 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). |
|
184 | \o 0.0 is the minimum size (full pie drawn, without any hole inside). | |
185 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) |
|
185 | \o 1.0 is the maximum size that can fit the chart. (donut has no width) | |
186 | \endlist |
|
186 | \endlist | |
187 |
|
187 | |||
188 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. |
|
188 | When setting this property the size property is adjusted if necessary, to ensure that the inner size is not greater than the outer size. | |
189 |
|
189 | |||
190 | Default value is 0.0. |
|
190 | Default value is 0.0. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | \property QPieSeries::startAngle |
|
194 | \property QPieSeries::startAngle | |
195 | \brief Defines the starting angle of the pie. |
|
195 | \brief Defines the starting angle of the pie. | |
196 |
|
196 | |||
197 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
197 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
198 |
|
198 | |||
199 | Default is value is 0. |
|
199 | Default is value is 0. | |
200 | */ |
|
200 | */ | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | \qmlproperty real PieSeries::startAngle |
|
203 | \qmlproperty real PieSeries::startAngle | |
204 |
|
204 | |||
205 | Defines the starting angle of the pie. |
|
205 | Defines the starting angle of the pie. | |
206 |
|
206 | |||
207 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
207 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
208 |
|
208 | |||
209 | Default is value is 0. |
|
209 | Default is value is 0. | |
210 | */ |
|
210 | */ | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | \property QPieSeries::endAngle |
|
213 | \property QPieSeries::endAngle | |
214 | \brief Defines the ending angle of the pie. |
|
214 | \brief Defines the ending angle of the pie. | |
215 |
|
215 | |||
216 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
216 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
217 |
|
217 | |||
218 | Default is value is 360. |
|
218 | Default is value is 360. | |
219 | */ |
|
219 | */ | |
220 |
|
220 | |||
221 | /*! |
|
221 | /*! | |
222 | \qmlproperty real PieSeries::endAngle |
|
222 | \qmlproperty real PieSeries::endAngle | |
223 |
|
223 | |||
224 | Defines the ending angle of the pie. |
|
224 | Defines the ending angle of the pie. | |
225 |
|
225 | |||
226 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
226 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
227 |
|
227 | |||
228 | Default is value is 360. |
|
228 | Default is value is 360. | |
229 | */ |
|
229 | */ | |
230 |
|
230 | |||
231 | /*! |
|
231 | /*! | |
232 | \property QPieSeries::count |
|
232 | \property QPieSeries::count | |
233 |
|
233 | |||
234 | Number of slices in the series. |
|
234 | Number of slices in the series. | |
235 | */ |
|
235 | */ | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | \qmlproperty int PieSeries::count |
|
238 | \qmlproperty int PieSeries::count | |
239 |
|
239 | |||
240 | Number of slices in the series. |
|
240 | Number of slices in the series. | |
241 | */ |
|
241 | */ | |
242 |
|
242 | |||
243 | /*! |
|
243 | /*! | |
244 | \fn void QPieSeries::countChanged() |
|
244 | \fn void QPieSeries::countChanged() | |
245 | Emitted when the slice count has changed. |
|
245 | Emitted when the slice count has changed. | |
246 | \sa count |
|
246 | \sa count | |
247 | */ |
|
247 | */ | |
248 | /*! |
|
248 | /*! | |
249 | \qmlsignal PieSeries::onCountChanged() |
|
249 | \qmlsignal PieSeries::onCountChanged() | |
250 | Emitted when the slice count has changed. |
|
250 | Emitted when the slice count has changed. | |
251 | */ |
|
251 | */ | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | \property QPieSeries::sum |
|
254 | \property QPieSeries::sum | |
255 |
|
255 | |||
256 | Sum of all slices. |
|
256 | Sum of all slices. | |
257 |
|
257 | |||
258 | The series keeps track of the sum of all slices it holds. |
|
258 | The series keeps track of the sum of all slices it holds. | |
259 | */ |
|
259 | */ | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | \qmlproperty real PieSeries::sum |
|
262 | \qmlproperty real PieSeries::sum | |
263 |
|
263 | |||
264 | Sum of all slices. |
|
264 | Sum of all slices. | |
265 |
|
265 | |||
266 | The series keeps track of the sum of all slices it holds. |
|
266 | The series keeps track of the sum of all slices it holds. | |
267 | */ |
|
267 | */ | |
268 |
|
268 | |||
269 | /*! |
|
269 | /*! | |
270 | \fn void QPieSeries::sumChanged() |
|
270 | \fn void QPieSeries::sumChanged() | |
271 | Emitted when the sum of all slices has changed. |
|
271 | Emitted when the sum of all slices has changed. | |
272 | \sa sum |
|
272 | \sa sum | |
273 | */ |
|
273 | */ | |
274 | /*! |
|
274 | /*! | |
275 | \qmlsignal PieSeries::onSumChanged() |
|
275 | \qmlsignal PieSeries::onSumChanged() | |
276 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you |
|
276 | Emitted when the sum of all slices has changed. This may happen for example if you add or remove slices, or if you | |
277 | change value of a slice. |
|
277 | change value of a slice. | |
278 | */ |
|
278 | */ | |
279 |
|
279 | |||
280 | /*! |
|
280 | /*! | |
281 | \fn void QPieSeries::added(QList<QPieSlice*> slices) |
|
281 | \fn void QPieSeries::added(QList<QPieSlice*> slices) | |
282 |
|
282 | |||
283 | This signal is emitted when \a slices have been added to the series. |
|
283 | This signal is emitted when \a slices have been added to the series. | |
284 |
|
284 | |||
285 | \sa append(), insert() |
|
285 | \sa append(), insert() | |
286 | */ |
|
286 | */ | |
287 | /*! |
|
287 | /*! | |
288 | \qmlsignal PieSeries::onAdded(PieSlice slice) |
|
288 | \qmlsignal PieSeries::onAdded(PieSlice slice) | |
289 | Emitted when \a slice has been added to the series. |
|
289 | Emitted when \a slice has been added to the series. | |
290 | */ |
|
290 | */ | |
291 |
|
291 | |||
292 | /*! |
|
292 | /*! | |
293 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) |
|
293 | \fn void QPieSeries::removed(QList<QPieSlice*> slices) | |
294 | This signal is emitted when \a slices have been removed from the series. |
|
294 | This signal is emitted when \a slices have been removed from the series. | |
295 | \sa remove() |
|
295 | \sa remove() | |
296 | */ |
|
296 | */ | |
297 | /*! |
|
297 | /*! | |
298 | \qmlsignal PieSeries::onRemoved(PieSlice slice) |
|
298 | \qmlsignal PieSeries::onRemoved(PieSlice slice) | |
299 | Emitted when \a slice has been removed from the series. |
|
299 | Emitted when \a slice has been removed from the series. | |
300 | */ |
|
300 | */ | |
301 |
|
301 | |||
302 | /*! |
|
302 | /*! | |
303 | \fn void QPieSeries::clicked(QPieSlice* slice) |
|
303 | \fn void QPieSeries::clicked(QPieSlice* slice) | |
304 | This signal is emitted when a \a slice has been clicked. |
|
304 | This signal is emitted when a \a slice has been clicked. | |
305 | \sa QPieSlice::clicked() |
|
305 | \sa QPieSlice::clicked() | |
306 | */ |
|
306 | */ | |
307 | /*! |
|
307 | /*! | |
308 | \qmlsignal PieSeries::onClicked(PieSlice slice) |
|
308 | \qmlsignal PieSeries::onClicked(PieSlice slice) | |
309 | This signal is emitted when a \a slice has been clicked. |
|
309 | This signal is emitted when a \a slice has been clicked. | |
310 | */ |
|
310 | */ | |
311 |
|
311 | |||
312 | /*! |
|
312 | /*! | |
313 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) |
|
313 | \fn void QPieSeries::hovered(QPieSlice* slice, bool state) | |
314 | This signal is emitted when user has hovered over or away from the \a slice. |
|
314 | This signal is emitted when user has hovered over or away from the \a slice. | |
315 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. |
|
315 | \a state is true when user has hovered over the slice and false when hover has moved away from the slice. | |
316 | \sa QPieSlice::hovered() |
|
316 | \sa QPieSlice::hovered() | |
317 | */ |
|
317 | */ | |
318 | /*! |
|
318 | /*! | |
319 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) |
|
319 | \qmlsignal PieSeries::onHovered(PieSlice slice, bool state) | |
320 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered |
|
320 | This signal is emitted when user has hovered over or away from the \a slice. \a state is true when user has hovered | |
321 | over the slice and false when hover has moved away from the slice. |
|
321 | over the slice and false when hover has moved away from the slice. | |
322 | */ |
|
322 | */ | |
323 |
|
323 | |||
324 | /*! |
|
324 | /*! | |
325 | \qmlmethod PieSlice PieSeries::at(int index) |
|
325 | \qmlmethod PieSlice PieSeries::at(int index) | |
326 | Returns slice at \a index. Returns null if the index is not valid. |
|
326 | Returns slice at \a index. Returns null if the index is not valid. | |
327 | */ |
|
327 | */ | |
328 |
|
328 | |||
329 | /*! |
|
329 | /*! | |
330 | \qmlmethod PieSlice PieSeries::find(string label) |
|
330 | \qmlmethod PieSlice PieSeries::find(string label) | |
331 | Returns the first slice with \a label. Returns null if the index is not valid. |
|
331 | Returns the first slice with \a label. Returns null if the index is not valid. | |
332 | */ |
|
332 | */ | |
333 |
|
333 | |||
334 | /*! |
|
334 | /*! | |
335 | \qmlmethod PieSlice PieSeries::append(string label, real value) |
|
335 | \qmlmethod PieSlice PieSeries::append(string label, real value) | |
336 | Adds a new slice with \a label and \a value to the pie. |
|
336 | Adds a new slice with \a label and \a value to the pie. | |
337 | */ |
|
337 | */ | |
338 |
|
338 | |||
339 | /*! |
|
339 | /*! | |
340 | \qmlmethod bool PieSeries::remove(PieSlice slice) |
|
340 | \qmlmethod bool PieSeries::remove(PieSlice slice) | |
341 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. |
|
341 | Removes the \a slice from the pie. Returns true if the removal was successful, false otherwise. | |
342 | */ |
|
342 | */ | |
343 |
|
343 | |||
344 | /*! |
|
344 | /*! | |
345 | \qmlmethod PieSeries::clear() |
|
345 | \qmlmethod PieSeries::clear() | |
346 | Removes all slices from the pie. |
|
346 | Removes all slices from the pie. | |
347 | */ |
|
347 | */ | |
348 |
|
348 | |||
349 | /*! |
|
349 | /*! | |
350 | Constructs a series object which is a child of \a parent. |
|
350 | Constructs a series object which is a child of \a parent. | |
351 | */ |
|
351 | */ | |
352 | QPieSeries::QPieSeries(QObject *parent) |
|
352 | QPieSeries::QPieSeries(QObject *parent) | |
353 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) |
|
353 | : QAbstractSeries(*new QPieSeriesPrivate(this), parent) | |
354 | { |
|
354 | { | |
355 | Q_D(QPieSeries); |
|
355 | Q_D(QPieSeries); | |
356 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
356 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); | |
357 | } |
|
357 | } | |
358 |
|
358 | |||
359 | /*! |
|
359 | /*! | |
360 | Destroys the series and its slices. |
|
360 | Destroys the series and its slices. | |
361 | */ |
|
361 | */ | |
362 | QPieSeries::~QPieSeries() |
|
362 | QPieSeries::~QPieSeries() | |
363 | { |
|
363 | { | |
364 | // NOTE: d_prt destroyed by QObject |
|
364 | // NOTE: d_prt destroyed by QObject | |
365 | clear(); |
|
365 | clear(); | |
366 | } |
|
366 | } | |
367 |
|
367 | |||
368 | /*! |
|
368 | /*! | |
369 | Returns QChartSeries::SeriesTypePie. |
|
369 | Returns QChartSeries::SeriesTypePie. | |
370 | */ |
|
370 | */ | |
371 | QAbstractSeries::SeriesType QPieSeries::type() const |
|
371 | QAbstractSeries::SeriesType QPieSeries::type() const | |
372 | { |
|
372 | { | |
373 | return QAbstractSeries::SeriesTypePie; |
|
373 | return QAbstractSeries::SeriesTypePie; | |
374 | } |
|
374 | } | |
375 |
|
375 | |||
376 | /*! |
|
376 | /*! | |
377 | Appends a single \a slice to the series. |
|
377 | Appends a single \a slice to the series. | |
378 | Slice ownership is passed to the series. |
|
378 | Slice ownership is passed to the series. | |
379 |
|
379 | |||
380 | Returns true if append was succesfull. |
|
380 | Returns true if append was succesfull. | |
381 | */ |
|
381 | */ | |
382 | bool QPieSeries::append(QPieSlice *slice) |
|
382 | bool QPieSeries::append(QPieSlice *slice) | |
383 | { |
|
383 | { | |
384 | return append(QList<QPieSlice *>() << slice); |
|
384 | return append(QList<QPieSlice *>() << slice); | |
385 | } |
|
385 | } | |
386 |
|
386 | |||
387 | /*! |
|
387 | /*! | |
388 | Appends an array of \a slices to the series. |
|
388 | Appends an array of \a slices to the series. | |
389 | Slice ownership is passed to the series. |
|
389 | Slice ownership is passed to the series. | |
390 |
|
390 | |||
391 | Returns true if append was successful. |
|
391 | Returns true if append was successful. | |
392 | */ |
|
392 | */ | |
393 | bool QPieSeries::append(QList<QPieSlice *> slices) |
|
393 | bool QPieSeries::append(QList<QPieSlice *> slices) | |
394 | { |
|
394 | { | |
395 | Q_D(QPieSeries); |
|
395 | Q_D(QPieSeries); | |
396 |
|
396 | |||
397 | if (slices.count() == 0) |
|
397 | if (slices.count() == 0) | |
398 | return false; |
|
398 | return false; | |
399 |
|
399 | |||
400 | foreach (QPieSlice *s, slices) { |
|
400 | foreach (QPieSlice *s, slices) { | |
401 | if (!s || d->m_slices.contains(s)) |
|
401 | if (!s || d->m_slices.contains(s)) | |
402 | return false; |
|
402 | return false; | |
403 | if (s->series()) // already added to some series |
|
403 | if (s->series()) // already added to some series | |
404 | return false; |
|
404 | return false; | |
405 | if (!isValidValue(s->value())) |
|
405 | if (!isValidValue(s->value())) | |
406 | return false; |
|
406 | return false; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | foreach (QPieSlice *s, slices) { |
|
409 | foreach (QPieSlice *s, slices) { | |
410 | s->setParent(this); |
|
410 | s->setParent(this); | |
411 | QPieSlicePrivate::fromSlice(s)->m_series = this; |
|
411 | QPieSlicePrivate::fromSlice(s)->m_series = this; | |
412 | d->m_slices << s; |
|
412 | d->m_slices << s; | |
413 | } |
|
413 | } | |
414 |
|
414 | |||
415 | d->updateDerivativeData(); |
|
415 | d->updateDerivativeData(); | |
416 |
|
416 | |||
417 | foreach(QPieSlice * s, slices) { |
|
417 | foreach(QPieSlice * s, slices) { | |
418 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
418 | connect(s, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
419 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
419 | connect(s, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
420 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
420 | connect(s, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
421 | } |
|
421 | } | |
422 |
|
422 | |||
423 | emit added(slices); |
|
423 | emit added(slices); | |
424 | emit countChanged(); |
|
424 | emit countChanged(); | |
425 |
|
425 | |||
426 | return true; |
|
426 | return true; | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | /*! |
|
429 | /*! | |
430 | Appends a single \a slice to the series and returns a reference to the series. |
|
430 | Appends a single \a slice to the series and returns a reference to the series. | |
431 | Slice ownership is passed to the series. |
|
431 | Slice ownership is passed to the series. | |
432 | */ |
|
432 | */ | |
433 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) |
|
433 | QPieSeries &QPieSeries::operator << (QPieSlice *slice) | |
434 | { |
|
434 | { | |
435 | append(slice); |
|
435 | append(slice); | |
436 | return *this; |
|
436 | return *this; | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 |
|
439 | |||
440 | /*! |
|
440 | /*! | |
441 | Appends a single slice to the series with give \a value and \a label. |
|
441 | Appends a single slice to the series with give \a value and \a label. | |
442 | Slice ownership is passed to the series. |
|
442 | Slice ownership is passed to the series. | |
443 | Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series. |
|
443 | Returns NULL if value is NaN, Inf or -Inf and no slice is added to the series. | |
444 | */ |
|
444 | */ | |
445 | QPieSlice *QPieSeries::append(QString label, qreal value) |
|
445 | QPieSlice *QPieSeries::append(QString label, qreal value) | |
446 | { |
|
446 | { | |
447 | if (isValidValue(value)) { |
|
447 | if (isValidValue(value)) { | |
448 | QPieSlice *slice = new QPieSlice(label, value); |
|
448 | QPieSlice *slice = new QPieSlice(label, value); | |
449 | append(slice); |
|
449 | append(slice); | |
450 | return slice; |
|
450 | return slice; | |
451 | } else { |
|
451 | } else { | |
452 | return 0; |
|
452 | return 0; | |
453 | } |
|
453 | } | |
454 | } |
|
454 | } | |
455 |
|
455 | |||
456 | /*! |
|
456 | /*! | |
457 | Inserts a single \a slice to the series before the slice at \a index position. |
|
457 | Inserts a single \a slice to the series before the slice at \a index position. | |
458 | Slice ownership is passed to the series. |
|
458 | Slice ownership is passed to the series. | |
459 |
|
459 | |||
460 | Returns true if insert was successful. |
|
460 | Returns true if insert was successful. | |
461 | */ |
|
461 | */ | |
462 | bool QPieSeries::insert(int index, QPieSlice *slice) |
|
462 | bool QPieSeries::insert(int index, QPieSlice *slice) | |
463 | { |
|
463 | { | |
464 | Q_D(QPieSeries); |
|
464 | Q_D(QPieSeries); | |
465 |
|
465 | |||
466 | if (index < 0 || index > d->m_slices.count()) |
|
466 | if (index < 0 || index > d->m_slices.count()) | |
467 | return false; |
|
467 | return false; | |
468 |
|
468 | |||
469 | if (!slice || d->m_slices.contains(slice)) |
|
469 | if (!slice || d->m_slices.contains(slice)) | |
470 | return false; |
|
470 | return false; | |
471 |
|
471 | |||
472 | if (slice->series()) // already added to some series |
|
472 | if (slice->series()) // already added to some series | |
473 | return false; |
|
473 | return false; | |
474 |
|
474 | |||
475 | if (!isValidValue(slice->value())) |
|
475 | if (!isValidValue(slice->value())) | |
476 | return false; |
|
476 | return false; | |
477 |
|
477 | |||
478 | slice->setParent(this); |
|
478 | slice->setParent(this); | |
479 | QPieSlicePrivate::fromSlice(slice)->m_series = this; |
|
479 | QPieSlicePrivate::fromSlice(slice)->m_series = this; | |
480 | d->m_slices.insert(index, slice); |
|
480 | d->m_slices.insert(index, slice); | |
481 |
|
481 | |||
482 | d->updateDerivativeData(); |
|
482 | d->updateDerivativeData(); | |
483 |
|
483 | |||
484 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); |
|
484 | connect(slice, SIGNAL(valueChanged()), d, SLOT(sliceValueChanged())); | |
485 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); |
|
485 | connect(slice, SIGNAL(clicked()), d, SLOT(sliceClicked())); | |
486 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); |
|
486 | connect(slice, SIGNAL(hovered(bool)), d, SLOT(sliceHovered(bool))); | |
487 |
|
487 | |||
488 | emit added(QList<QPieSlice *>() << slice); |
|
488 | emit added(QList<QPieSlice *>() << slice); | |
489 | emit countChanged(); |
|
489 | emit countChanged(); | |
490 |
|
490 | |||
491 | return true; |
|
491 | return true; | |
492 | } |
|
492 | } | |
493 |
|
493 | |||
494 | /*! |
|
494 | /*! | |
495 | Removes a single \a slice from the series and deletes the slice. |
|
495 | Removes a single \a slice from the series and deletes the slice. | |
496 |
|
496 | |||
497 | Do not reference the pointer after this call. |
|
497 | Do not reference the pointer after this call. | |
498 |
|
498 | |||
499 | Returns true if remove was successful. |
|
499 | Returns true if remove was successful. | |
500 | */ |
|
500 | */ | |
501 | bool QPieSeries::remove(QPieSlice *slice) |
|
501 | bool QPieSeries::remove(QPieSlice *slice) | |
502 | { |
|
502 | { | |
503 | Q_D(QPieSeries); |
|
503 | Q_D(QPieSeries); | |
504 |
|
504 | |||
505 | if (!d->m_slices.removeOne(slice)) |
|
505 | if (!d->m_slices.removeOne(slice)) | |
506 | return false; |
|
506 | return false; | |
507 |
|
507 | |||
508 | d->updateDerivativeData(); |
|
508 | d->updateDerivativeData(); | |
509 |
|
509 | |||
510 | emit removed(QList<QPieSlice *>() << slice); |
|
510 | emit removed(QList<QPieSlice *>() << slice); | |
511 | emit countChanged(); |
|
511 | emit countChanged(); | |
512 |
|
512 | |||
513 | delete slice; |
|
513 | delete slice; | |
514 | slice = 0; |
|
514 | slice = 0; | |
515 |
|
515 | |||
516 | return true; |
|
516 | return true; | |
517 | } |
|
517 | } | |
518 |
|
518 | |||
519 | /*! |
|
519 | /*! | |
520 | Takes a single \a slice from the series. Does not destroy the slice object. |
|
520 | Takes a single \a slice from the series. Does not destroy the slice object. | |
521 |
|
521 | |||
522 |
|
|
522 | \note The series remains as the slice's parent object. You must set the | |
523 | parent object to take full ownership. |
|
523 | parent object to take full ownership. | |
524 |
|
524 | |||
525 | Returns true if take was successful. |
|
525 | Returns true if take was successful. | |
526 | */ |
|
526 | */ | |
527 | bool QPieSeries::take(QPieSlice *slice) |
|
527 | bool QPieSeries::take(QPieSlice *slice) | |
528 | { |
|
528 | { | |
529 | Q_D(QPieSeries); |
|
529 | Q_D(QPieSeries); | |
530 |
|
530 | |||
531 | if (!d->m_slices.removeOne(slice)) |
|
531 | if (!d->m_slices.removeOne(slice)) | |
532 | return false; |
|
532 | return false; | |
533 |
|
533 | |||
534 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; |
|
534 | QPieSlicePrivate::fromSlice(slice)->m_series = 0; | |
535 | slice->disconnect(d); |
|
535 | slice->disconnect(d); | |
536 |
|
536 | |||
537 | d->updateDerivativeData(); |
|
537 | d->updateDerivativeData(); | |
538 |
|
538 | |||
539 | emit removed(QList<QPieSlice *>() << slice); |
|
539 | emit removed(QList<QPieSlice *>() << slice); | |
540 | emit countChanged(); |
|
540 | emit countChanged(); | |
541 |
|
541 | |||
542 | return true; |
|
542 | return true; | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | /*! |
|
545 | /*! | |
546 | Clears all slices from the series. |
|
546 | Clears all slices from the series. | |
547 | */ |
|
547 | */ | |
548 | void QPieSeries::clear() |
|
548 | void QPieSeries::clear() | |
549 | { |
|
549 | { | |
550 | Q_D(QPieSeries); |
|
550 | Q_D(QPieSeries); | |
551 | if (d->m_slices.count() == 0) |
|
551 | if (d->m_slices.count() == 0) | |
552 | return; |
|
552 | return; | |
553 |
|
553 | |||
554 | QList<QPieSlice *> slices = d->m_slices; |
|
554 | QList<QPieSlice *> slices = d->m_slices; | |
555 | foreach (QPieSlice *s, d->m_slices) |
|
555 | foreach (QPieSlice *s, d->m_slices) | |
556 | d->m_slices.removeOne(s); |
|
556 | d->m_slices.removeOne(s); | |
557 |
|
557 | |||
558 | d->updateDerivativeData(); |
|
558 | d->updateDerivativeData(); | |
559 |
|
559 | |||
560 | emit removed(slices); |
|
560 | emit removed(slices); | |
561 | emit countChanged(); |
|
561 | emit countChanged(); | |
562 |
|
562 | |||
563 | foreach (QPieSlice *s, slices) |
|
563 | foreach (QPieSlice *s, slices) | |
564 | delete s; |
|
564 | delete s; | |
565 | } |
|
565 | } | |
566 |
|
566 | |||
567 | /*! |
|
567 | /*! | |
568 | Returns a list of slices that belong to this series. |
|
568 | Returns a list of slices that belong to this series. | |
569 | */ |
|
569 | */ | |
570 | QList<QPieSlice *> QPieSeries::slices() const |
|
570 | QList<QPieSlice *> QPieSeries::slices() const | |
571 | { |
|
571 | { | |
572 | Q_D(const QPieSeries); |
|
572 | Q_D(const QPieSeries); | |
573 | return d->m_slices; |
|
573 | return d->m_slices; | |
574 | } |
|
574 | } | |
575 |
|
575 | |||
576 | /*! |
|
576 | /*! | |
577 | returns the number of the slices in this series. |
|
577 | returns the number of the slices in this series. | |
578 | */ |
|
578 | */ | |
579 | int QPieSeries::count() const |
|
579 | int QPieSeries::count() const | |
580 | { |
|
580 | { | |
581 | Q_D(const QPieSeries); |
|
581 | Q_D(const QPieSeries); | |
582 | return d->m_slices.count(); |
|
582 | return d->m_slices.count(); | |
583 | } |
|
583 | } | |
584 |
|
584 | |||
585 | /*! |
|
585 | /*! | |
586 | Returns true is the series is empty. |
|
586 | Returns true is the series is empty. | |
587 | */ |
|
587 | */ | |
588 | bool QPieSeries::isEmpty() const |
|
588 | bool QPieSeries::isEmpty() const | |
589 | { |
|
589 | { | |
590 | Q_D(const QPieSeries); |
|
590 | Q_D(const QPieSeries); | |
591 | return d->m_slices.isEmpty(); |
|
591 | return d->m_slices.isEmpty(); | |
592 | } |
|
592 | } | |
593 |
|
593 | |||
594 | /*! |
|
594 | /*! | |
595 | Returns the sum of all slice values in this series. |
|
595 | Returns the sum of all slice values in this series. | |
596 |
|
596 | |||
597 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() |
|
597 | \sa QPieSlice::value(), QPieSlice::setValue(), QPieSlice::percentage() | |
598 | */ |
|
598 | */ | |
599 | qreal QPieSeries::sum() const |
|
599 | qreal QPieSeries::sum() const | |
600 | { |
|
600 | { | |
601 | Q_D(const QPieSeries); |
|
601 | Q_D(const QPieSeries); | |
602 | return d->m_sum; |
|
602 | return d->m_sum; | |
603 | } |
|
603 | } | |
604 |
|
604 | |||
605 | void QPieSeries::setHoleSize(qreal holeSize) |
|
605 | void QPieSeries::setHoleSize(qreal holeSize) | |
606 | { |
|
606 | { | |
607 | Q_D(QPieSeries); |
|
607 | Q_D(QPieSeries); | |
608 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); |
|
608 | holeSize = qBound((qreal)0.0, holeSize, (qreal)1.0); | |
609 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); |
|
609 | d->setSizes(holeSize, qMax(d->m_pieRelativeSize, holeSize)); | |
610 | } |
|
610 | } | |
611 |
|
611 | |||
612 | qreal QPieSeries::holeSize() const |
|
612 | qreal QPieSeries::holeSize() const | |
613 | { |
|
613 | { | |
614 | Q_D(const QPieSeries); |
|
614 | Q_D(const QPieSeries); | |
615 | return d->m_holeRelativeSize; |
|
615 | return d->m_holeRelativeSize; | |
616 | } |
|
616 | } | |
617 |
|
617 | |||
618 | void QPieSeries::setHorizontalPosition(qreal relativePosition) |
|
618 | void QPieSeries::setHorizontalPosition(qreal relativePosition) | |
619 | { |
|
619 | { | |
620 | Q_D(QPieSeries); |
|
620 | Q_D(QPieSeries); | |
621 |
|
621 | |||
622 | if (relativePosition < 0.0) |
|
622 | if (relativePosition < 0.0) | |
623 | relativePosition = 0.0; |
|
623 | relativePosition = 0.0; | |
624 | if (relativePosition > 1.0) |
|
624 | if (relativePosition > 1.0) | |
625 | relativePosition = 1.0; |
|
625 | relativePosition = 1.0; | |
626 |
|
626 | |||
627 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { |
|
627 | if (!qFuzzyCompare(d->m_pieRelativeHorPos, relativePosition)) { | |
628 | d->m_pieRelativeHorPos = relativePosition; |
|
628 | d->m_pieRelativeHorPos = relativePosition; | |
629 | emit d->horizontalPositionChanged(); |
|
629 | emit d->horizontalPositionChanged(); | |
630 | } |
|
630 | } | |
631 | } |
|
631 | } | |
632 |
|
632 | |||
633 | qreal QPieSeries::horizontalPosition() const |
|
633 | qreal QPieSeries::horizontalPosition() const | |
634 | { |
|
634 | { | |
635 | Q_D(const QPieSeries); |
|
635 | Q_D(const QPieSeries); | |
636 | return d->m_pieRelativeHorPos; |
|
636 | return d->m_pieRelativeHorPos; | |
637 | } |
|
637 | } | |
638 |
|
638 | |||
639 | void QPieSeries::setVerticalPosition(qreal relativePosition) |
|
639 | void QPieSeries::setVerticalPosition(qreal relativePosition) | |
640 | { |
|
640 | { | |
641 | Q_D(QPieSeries); |
|
641 | Q_D(QPieSeries); | |
642 |
|
642 | |||
643 | if (relativePosition < 0.0) |
|
643 | if (relativePosition < 0.0) | |
644 | relativePosition = 0.0; |
|
644 | relativePosition = 0.0; | |
645 | if (relativePosition > 1.0) |
|
645 | if (relativePosition > 1.0) | |
646 | relativePosition = 1.0; |
|
646 | relativePosition = 1.0; | |
647 |
|
647 | |||
648 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { |
|
648 | if (!qFuzzyCompare(d->m_pieRelativeVerPos, relativePosition)) { | |
649 | d->m_pieRelativeVerPos = relativePosition; |
|
649 | d->m_pieRelativeVerPos = relativePosition; | |
650 | emit d->verticalPositionChanged(); |
|
650 | emit d->verticalPositionChanged(); | |
651 | } |
|
651 | } | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 | qreal QPieSeries::verticalPosition() const |
|
654 | qreal QPieSeries::verticalPosition() const | |
655 | { |
|
655 | { | |
656 | Q_D(const QPieSeries); |
|
656 | Q_D(const QPieSeries); | |
657 | return d->m_pieRelativeVerPos; |
|
657 | return d->m_pieRelativeVerPos; | |
658 | } |
|
658 | } | |
659 |
|
659 | |||
660 | void QPieSeries::setPieSize(qreal relativeSize) |
|
660 | void QPieSeries::setPieSize(qreal relativeSize) | |
661 | { |
|
661 | { | |
662 | Q_D(QPieSeries); |
|
662 | Q_D(QPieSeries); | |
663 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); |
|
663 | relativeSize = qBound((qreal)0.0, relativeSize, (qreal)1.0); | |
664 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); |
|
664 | d->setSizes(qMin(d->m_holeRelativeSize, relativeSize), relativeSize); | |
665 |
|
665 | |||
666 | } |
|
666 | } | |
667 |
|
667 | |||
668 | qreal QPieSeries::pieSize() const |
|
668 | qreal QPieSeries::pieSize() const | |
669 | { |
|
669 | { | |
670 | Q_D(const QPieSeries); |
|
670 | Q_D(const QPieSeries); | |
671 | return d->m_pieRelativeSize; |
|
671 | return d->m_pieRelativeSize; | |
672 | } |
|
672 | } | |
673 |
|
673 | |||
674 |
|
674 | |||
675 | void QPieSeries::setPieStartAngle(qreal angle) |
|
675 | void QPieSeries::setPieStartAngle(qreal angle) | |
676 | { |
|
676 | { | |
677 | Q_D(QPieSeries); |
|
677 | Q_D(QPieSeries); | |
678 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) |
|
678 | if (qFuzzyCompare(d->m_pieStartAngle, angle)) | |
679 | return; |
|
679 | return; | |
680 | d->m_pieStartAngle = angle; |
|
680 | d->m_pieStartAngle = angle; | |
681 | d->updateDerivativeData(); |
|
681 | d->updateDerivativeData(); | |
682 | emit d->pieStartAngleChanged(); |
|
682 | emit d->pieStartAngleChanged(); | |
683 | } |
|
683 | } | |
684 |
|
684 | |||
685 | qreal QPieSeries::pieStartAngle() const |
|
685 | qreal QPieSeries::pieStartAngle() const | |
686 | { |
|
686 | { | |
687 | Q_D(const QPieSeries); |
|
687 | Q_D(const QPieSeries); | |
688 | return d->m_pieStartAngle; |
|
688 | return d->m_pieStartAngle; | |
689 | } |
|
689 | } | |
690 |
|
690 | |||
691 | /*! |
|
691 | /*! | |
692 | Sets the end angle of the pie. |
|
692 | Sets the end angle of the pie. | |
693 |
|
693 | |||
694 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
694 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
695 |
|
695 | |||
696 | \a angle must be greater than start angle. |
|
696 | \a angle must be greater than start angle. | |
697 |
|
697 | |||
698 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
698 | \sa pieEndAngle(), pieStartAngle(), setPieStartAngle() | |
699 | */ |
|
699 | */ | |
700 | void QPieSeries::setPieEndAngle(qreal angle) |
|
700 | void QPieSeries::setPieEndAngle(qreal angle) | |
701 | { |
|
701 | { | |
702 | Q_D(QPieSeries); |
|
702 | Q_D(QPieSeries); | |
703 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) |
|
703 | if (qFuzzyCompare(d->m_pieEndAngle, angle)) | |
704 | return; |
|
704 | return; | |
705 | d->m_pieEndAngle = angle; |
|
705 | d->m_pieEndAngle = angle; | |
706 | d->updateDerivativeData(); |
|
706 | d->updateDerivativeData(); | |
707 | emit d->pieEndAngleChanged(); |
|
707 | emit d->pieEndAngleChanged(); | |
708 | } |
|
708 | } | |
709 |
|
709 | |||
710 | /*! |
|
710 | /*! | |
711 | Returns the end angle of the pie. |
|
711 | Returns the end angle of the pie. | |
712 |
|
712 | |||
713 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. |
|
713 | Full pie is 360 degrees where 0 degrees is at 12 a'clock. | |
714 |
|
714 | |||
715 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() |
|
715 | \sa setPieEndAngle(), pieStartAngle(), setPieStartAngle() | |
716 | */ |
|
716 | */ | |
717 | qreal QPieSeries::pieEndAngle() const |
|
717 | qreal QPieSeries::pieEndAngle() const | |
718 | { |
|
718 | { | |
719 | Q_D(const QPieSeries); |
|
719 | Q_D(const QPieSeries); | |
720 | return d->m_pieEndAngle; |
|
720 | return d->m_pieEndAngle; | |
721 | } |
|
721 | } | |
722 |
|
722 | |||
723 | /*! |
|
723 | /*! | |
724 | Sets the all the slice labels \a visible or invisible. |
|
724 | Sets the all the slice labels \a visible or invisible. | |
725 |
|
725 | |||
726 | Note that this affects only the current slices in the series. |
|
726 | Note that this affects only the current slices in the series. | |
727 | If user adds a new slice the default label visibility is false. |
|
727 | If user adds a new slice the default label visibility is false. | |
728 |
|
728 | |||
729 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() |
|
729 | \sa QPieSlice::isLabelVisible(), QPieSlice::setLabelVisible() | |
730 | */ |
|
730 | */ | |
731 | void QPieSeries::setLabelsVisible(bool visible) |
|
731 | void QPieSeries::setLabelsVisible(bool visible) | |
732 | { |
|
732 | { | |
733 | Q_D(QPieSeries); |
|
733 | Q_D(QPieSeries); | |
734 | foreach (QPieSlice *s, d->m_slices) |
|
734 | foreach (QPieSlice *s, d->m_slices) | |
735 | s->setLabelVisible(visible); |
|
735 | s->setLabelVisible(visible); | |
736 | } |
|
736 | } | |
737 |
|
737 | |||
738 | /*! |
|
738 | /*! | |
739 | Sets the all the slice labels \a position |
|
739 | Sets the all the slice labels \a position | |
740 |
|
740 | |||
741 | Note that this affects only the current slices in the series. |
|
741 | Note that this affects only the current slices in the series. | |
742 | If user adds a new slice the default label position is LabelOutside |
|
742 | If user adds a new slice the default label position is LabelOutside | |
743 |
|
743 | |||
744 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() |
|
744 | \sa QPieSlice::labelPosition(), QPieSlice::setLabelPosition() | |
745 | */ |
|
745 | */ | |
746 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) |
|
746 | void QPieSeries::setLabelsPosition(QPieSlice::LabelPosition position) | |
747 | { |
|
747 | { | |
748 | Q_D(QPieSeries); |
|
748 | Q_D(QPieSeries); | |
749 | foreach (QPieSlice *s, d->m_slices) |
|
749 | foreach (QPieSlice *s, d->m_slices) | |
750 | s->setLabelPosition(position); |
|
750 | s->setLabelPosition(position); | |
751 | } |
|
751 | } | |
752 |
|
752 | |||
753 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
753 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
754 |
|
754 | |||
755 |
|
755 | |||
756 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : |
|
756 | QPieSeriesPrivate::QPieSeriesPrivate(QPieSeries *parent) : | |
757 | QAbstractSeriesPrivate(parent), |
|
757 | QAbstractSeriesPrivate(parent), | |
758 | m_pieRelativeHorPos(0.5), |
|
758 | m_pieRelativeHorPos(0.5), | |
759 | m_pieRelativeVerPos(0.5), |
|
759 | m_pieRelativeVerPos(0.5), | |
760 | m_pieRelativeSize(0.7), |
|
760 | m_pieRelativeSize(0.7), | |
761 | m_pieStartAngle(0), |
|
761 | m_pieStartAngle(0), | |
762 | m_pieEndAngle(360), |
|
762 | m_pieEndAngle(360), | |
763 | m_sum(0), |
|
763 | m_sum(0), | |
764 | m_holeRelativeSize(0.0) |
|
764 | m_holeRelativeSize(0.0) | |
765 | { |
|
765 | { | |
766 | } |
|
766 | } | |
767 |
|
767 | |||
768 | QPieSeriesPrivate::~QPieSeriesPrivate() |
|
768 | QPieSeriesPrivate::~QPieSeriesPrivate() | |
769 | { |
|
769 | { | |
770 | } |
|
770 | } | |
771 |
|
771 | |||
772 | void QPieSeriesPrivate::updateDerivativeData() |
|
772 | void QPieSeriesPrivate::updateDerivativeData() | |
773 | { |
|
773 | { | |
774 | // calculate sum of all slices |
|
774 | // calculate sum of all slices | |
775 | qreal sum = 0; |
|
775 | qreal sum = 0; | |
776 | foreach (QPieSlice *s, m_slices) |
|
776 | foreach (QPieSlice *s, m_slices) | |
777 | sum += s->value(); |
|
777 | sum += s->value(); | |
778 |
|
778 | |||
779 | if (!qFuzzyCompare(m_sum, sum)) { |
|
779 | if (!qFuzzyCompare(m_sum, sum)) { | |
780 | m_sum = sum; |
|
780 | m_sum = sum; | |
781 | emit q_func()->sumChanged(); |
|
781 | emit q_func()->sumChanged(); | |
782 | } |
|
782 | } | |
783 |
|
783 | |||
784 | // nothing to show.. |
|
784 | // nothing to show.. | |
785 | if (qFuzzyCompare(m_sum, 0)) |
|
785 | if (qFuzzyCompare(m_sum, 0)) | |
786 | return; |
|
786 | return; | |
787 |
|
787 | |||
788 | // update slice attributes |
|
788 | // update slice attributes | |
789 | qreal sliceAngle = m_pieStartAngle; |
|
789 | qreal sliceAngle = m_pieStartAngle; | |
790 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; |
|
790 | qreal pieSpan = m_pieEndAngle - m_pieStartAngle; | |
791 | QVector<QPieSlice *> changed; |
|
791 | QVector<QPieSlice *> changed; | |
792 | foreach (QPieSlice *s, m_slices) { |
|
792 | foreach (QPieSlice *s, m_slices) { | |
793 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
793 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
794 | d->setPercentage(s->value() / m_sum); |
|
794 | d->setPercentage(s->value() / m_sum); | |
795 | d->setStartAngle(sliceAngle); |
|
795 | d->setStartAngle(sliceAngle); | |
796 | d->setAngleSpan(pieSpan * s->percentage()); |
|
796 | d->setAngleSpan(pieSpan * s->percentage()); | |
797 | sliceAngle += s->angleSpan(); |
|
797 | sliceAngle += s->angleSpan(); | |
798 | } |
|
798 | } | |
799 |
|
799 | |||
800 |
|
800 | |||
801 | emit calculatedDataChanged(); |
|
801 | emit calculatedDataChanged(); | |
802 | } |
|
802 | } | |
803 |
|
803 | |||
804 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) |
|
804 | void QPieSeriesPrivate::setSizes(qreal innerSize, qreal outerSize) | |
805 | { |
|
805 | { | |
806 | bool changed = false; |
|
806 | bool changed = false; | |
807 |
|
807 | |||
808 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { |
|
808 | if (!qFuzzyCompare(m_holeRelativeSize, innerSize)) { | |
809 | m_holeRelativeSize = innerSize; |
|
809 | m_holeRelativeSize = innerSize; | |
810 | changed = true; |
|
810 | changed = true; | |
811 | } |
|
811 | } | |
812 |
|
812 | |||
813 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { |
|
813 | if (!qFuzzyCompare(m_pieRelativeSize, outerSize)) { | |
814 | m_pieRelativeSize = outerSize; |
|
814 | m_pieRelativeSize = outerSize; | |
815 | changed = true; |
|
815 | changed = true; | |
816 | } |
|
816 | } | |
817 |
|
817 | |||
818 | if (changed) |
|
818 | if (changed) | |
819 | emit pieSizeChanged(); |
|
819 | emit pieSizeChanged(); | |
820 | } |
|
820 | } | |
821 |
|
821 | |||
822 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) |
|
822 | QPieSeriesPrivate *QPieSeriesPrivate::fromSeries(QPieSeries *series) | |
823 | { |
|
823 | { | |
824 | return series->d_func(); |
|
824 | return series->d_func(); | |
825 | } |
|
825 | } | |
826 |
|
826 | |||
827 | void QPieSeriesPrivate::sliceValueChanged() |
|
827 | void QPieSeriesPrivate::sliceValueChanged() | |
828 | { |
|
828 | { | |
829 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); |
|
829 | Q_ASSERT(m_slices.contains(qobject_cast<QPieSlice *>(sender()))); | |
830 | updateDerivativeData(); |
|
830 | updateDerivativeData(); | |
831 | } |
|
831 | } | |
832 |
|
832 | |||
833 | void QPieSeriesPrivate::sliceClicked() |
|
833 | void QPieSeriesPrivate::sliceClicked() | |
834 | { |
|
834 | { | |
835 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
835 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
836 | Q_ASSERT(m_slices.contains(slice)); |
|
836 | Q_ASSERT(m_slices.contains(slice)); | |
837 | Q_Q(QPieSeries); |
|
837 | Q_Q(QPieSeries); | |
838 | emit q->clicked(slice); |
|
838 | emit q->clicked(slice); | |
839 | } |
|
839 | } | |
840 |
|
840 | |||
841 | void QPieSeriesPrivate::sliceHovered(bool state) |
|
841 | void QPieSeriesPrivate::sliceHovered(bool state) | |
842 | { |
|
842 | { | |
843 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); |
|
843 | QPieSlice *slice = qobject_cast<QPieSlice *>(sender()); | |
844 | Q_ASSERT(m_slices.contains(slice)); |
|
844 | Q_ASSERT(m_slices.contains(slice)); | |
845 | Q_Q(QPieSeries); |
|
845 | Q_Q(QPieSeries); | |
846 | emit q->hovered(slice, state); |
|
846 | emit q->hovered(slice, state); | |
847 | } |
|
847 | } | |
848 |
|
848 | |||
849 | void QPieSeriesPrivate::initializeDomain() |
|
849 | void QPieSeriesPrivate::initializeDomain() | |
850 | { |
|
850 | { | |
851 | // does not apply to pie |
|
851 | // does not apply to pie | |
852 | } |
|
852 | } | |
853 |
|
853 | |||
854 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
854 | void QPieSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
855 | { |
|
855 | { | |
856 | Q_Q(QPieSeries); |
|
856 | Q_Q(QPieSeries); | |
857 | PieChartItem *pie = new PieChartItem(q,parent); |
|
857 | PieChartItem *pie = new PieChartItem(q,parent); | |
858 | m_item.reset(pie); |
|
858 | m_item.reset(pie); | |
859 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
859 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
860 | } |
|
860 | } | |
861 |
|
861 | |||
862 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
862 | void QPieSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
863 | { |
|
863 | { | |
864 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); |
|
864 | PieChartItem *item = static_cast<PieChartItem *>(m_item.data()); | |
865 | Q_ASSERT(item); |
|
865 | Q_ASSERT(item); | |
866 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
866 | if (options.testFlag(QChart::SeriesAnimations)) { | |
867 | item->setAnimation(new PieAnimation(item)); |
|
867 | item->setAnimation(new PieAnimation(item)); | |
868 | }else{ |
|
868 | }else{ | |
869 | item->setAnimation(0); |
|
869 | item->setAnimation(0); | |
870 | } |
|
870 | } | |
871 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
871 | QAbstractSeriesPrivate::initializeAnimations(options); | |
872 | } |
|
872 | } | |
873 |
|
873 | |||
874 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
874 | QList<QLegendMarker*> QPieSeriesPrivate::createLegendMarkers(QLegend* legend) | |
875 | { |
|
875 | { | |
876 | Q_Q(QPieSeries); |
|
876 | Q_Q(QPieSeries); | |
877 | QList<QLegendMarker*> markers; |
|
877 | QList<QLegendMarker*> markers; | |
878 | foreach(QPieSlice* slice, q->slices()) { |
|
878 | foreach(QPieSlice* slice, q->slices()) { | |
879 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); |
|
879 | QPieLegendMarker* marker = new QPieLegendMarker(q,slice,legend); | |
880 | markers << marker; |
|
880 | markers << marker; | |
881 | } |
|
881 | } | |
882 | return markers; |
|
882 | return markers; | |
883 | } |
|
883 | } | |
884 |
|
884 | |||
885 | void QPieSeriesPrivate::initializeAxes() |
|
885 | void QPieSeriesPrivate::initializeAxes() | |
886 | { |
|
886 | { | |
887 |
|
887 | |||
888 | } |
|
888 | } | |
889 |
|
889 | |||
890 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
890 | QAbstractAxis::AxisType QPieSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
891 | { |
|
891 | { | |
892 | Q_UNUSED(orientation); |
|
892 | Q_UNUSED(orientation); | |
893 | return QAbstractAxis::AxisTypeNoAxis; |
|
893 | return QAbstractAxis::AxisTypeNoAxis; | |
894 | } |
|
894 | } | |
895 |
|
895 | |||
896 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
896 | QAbstractAxis* QPieSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
897 | { |
|
897 | { | |
898 | Q_UNUSED(orientation); |
|
898 | Q_UNUSED(orientation); | |
899 | return 0; |
|
899 | return 0; | |
900 | } |
|
900 | } | |
901 |
|
901 | |||
902 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
902 | void QPieSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
903 | { |
|
903 | { | |
904 | //Q_Q(QPieSeries); |
|
904 | //Q_Q(QPieSeries); | |
905 | //const QList<QColor>& colors = theme->seriesColors(); |
|
905 | //const QList<QColor>& colors = theme->seriesColors(); | |
906 | const QList<QGradient>& gradients = theme->seriesGradients(); |
|
906 | const QList<QGradient>& gradients = theme->seriesGradients(); | |
907 |
|
907 | |||
908 | for (int i(0); i < m_slices.count(); i++) { |
|
908 | for (int i(0); i < m_slices.count(); i++) { | |
909 |
|
909 | |||
910 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
910 | QColor penColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); | |
911 |
|
911 | |||
912 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
912 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
913 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); |
|
913 | qreal pos = (qreal)(i + 1) / (qreal) m_slices.count(); | |
914 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); |
|
914 | QColor brushColor = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), pos); | |
915 |
|
915 | |||
916 | QPieSlice *s = m_slices.at(i); |
|
916 | QPieSlice *s = m_slices.at(i); | |
917 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
917 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
918 |
|
918 | |||
919 | if (forced || d->m_data.m_slicePen.isThemed()) |
|
919 | if (forced || d->m_data.m_slicePen.isThemed()) | |
920 | d->setPen(penColor, true); |
|
920 | d->setPen(penColor, true); | |
921 |
|
921 | |||
922 | if (forced || d->m_data.m_sliceBrush.isThemed()) |
|
922 | if (forced || d->m_data.m_sliceBrush.isThemed()) | |
923 | d->setBrush(brushColor, true); |
|
923 | d->setBrush(brushColor, true); | |
924 |
|
924 | |||
925 | if (forced || d->m_data.m_labelBrush.isThemed()) |
|
925 | if (forced || d->m_data.m_labelBrush.isThemed()) | |
926 | d->setLabelBrush(theme->labelBrush().color(), true); |
|
926 | d->setLabelBrush(theme->labelBrush().color(), true); | |
927 |
|
927 | |||
928 | if (forced || d->m_data.m_labelFont.isThemed()) |
|
928 | if (forced || d->m_data.m_labelFont.isThemed()) | |
929 | d->setLabelFont(theme->labelFont(), true); |
|
929 | d->setLabelFont(theme->labelFont(), true); | |
930 | } |
|
930 | } | |
931 | } |
|
931 | } | |
932 |
|
932 | |||
933 |
|
933 | |||
934 | #include "moc_qpieseries.cpp" |
|
934 | #include "moc_qpieseries.cpp" | |
935 | #include "moc_qpieseries_p.cpp" |
|
935 | #include "moc_qpieseries_p.cpp" | |
936 |
|
936 | |||
937 | QTCOMMERCIALCHART_END_NAMESPACE |
|
937 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,260 +1,260 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qvpiemodelmapper.h" |
|
21 | #include "qvpiemodelmapper.h" | |
22 |
|
22 | |||
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
23 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
24 |
|
24 | |||
25 | /*! |
|
25 | /*! | |
26 | \class QVPieModelMapper |
|
26 | \class QVPieModelMapper | |
27 | \mainclass |
|
27 | \mainclass | |
28 |
|
28 | |||
29 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. |
|
29 | Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series. | |
30 | Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns. |
|
30 | Vertical model mapper is used to create a connection between QPieSeries and QAbstractItemModel derived model object that keeps the consecutive pie slices data in columns. | |
31 | It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync. |
|
31 | It is possible to use both QAbstractItemModel and QPieSeries model API. QVPieModelMapper makes sure that Pie and the model are kept in sync. | |
32 |
|
|
32 | \note Used model has to support adding/removing rows/columns and modifying the data of the cells. | |
33 | */ |
|
33 | */ | |
34 | /*! |
|
34 | /*! | |
35 | \qmlclass VPieModelMapper QVPieModelMapper |
|
35 | \qmlclass VPieModelMapper QVPieModelMapper | |
36 |
|
36 | |||
37 | VPieModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source |
|
37 | VPieModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source | |
38 | for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data. |
|
38 | for a pie series. It is possible to use both QAbstractItemModel and PieSeries data API to manipulate data. | |
39 | VPieModelMapper keeps the Pie and the model in sync. |
|
39 | VPieModelMapper keeps the Pie and the model in sync. | |
40 |
|
40 | |||
41 | The following QML example would create a pie series with four slices (assuming the model has at least five rows). |
|
41 | The following QML example would create a pie series with four slices (assuming the model has at least five rows). | |
42 | Each slice would contain a label from column 1 and a value from column 2. |
|
42 | Each slice would contain a label from column 1 and a value from column 2. | |
43 | \code |
|
43 | \code | |
44 | VPieModelMapper { |
|
44 | VPieModelMapper { | |
45 | series: pieSeries |
|
45 | series: pieSeries | |
46 | model: customModel |
|
46 | model: customModel | |
47 | labelsColumn: 1 |
|
47 | labelsColumn: 1 | |
48 | valuesColumn: 2 |
|
48 | valuesColumn: 2 | |
49 | firstRow: 1 |
|
49 | firstRow: 1 | |
50 | rowCount: 4 |
|
50 | rowCount: 4 | |
51 | } |
|
51 | } | |
52 | \endcode |
|
52 | \endcode | |
53 | */ |
|
53 | */ | |
54 |
|
54 | |||
55 | /*! |
|
55 | /*! | |
56 | \property QVPieModelMapper::series |
|
56 | \property QVPieModelMapper::series | |
57 | \brief Defines the QPieSeries object that is used by the mapper. |
|
57 | \brief Defines the QPieSeries object that is used by the mapper. | |
58 | All the data in the series is discarded when it is set to the mapper. |
|
58 | All the data in the series is discarded when it is set to the mapper. | |
59 | When new series is specified the old series is disconnected (it preserves its data) |
|
59 | When new series is specified the old series is disconnected (it preserves its data) | |
60 | */ |
|
60 | */ | |
61 | /*! |
|
61 | /*! | |
62 | \qmlproperty PieSeries VPieModelMapper::series |
|
62 | \qmlproperty PieSeries VPieModelMapper::series | |
63 | Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a |
|
63 | Defines the PieSeries object that is used by the mapper. If you define the mapper element as a child for a | |
64 | PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper. |
|
64 | PieSeries, leave this property undefined. All the data in the series is discarded when it is set to the mapper. | |
65 | When new series is specified the old series is disconnected (it preserves its data). |
|
65 | When new series is specified the old series is disconnected (it preserves its data). | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QVPieModelMapper::model |
|
69 | \property QVPieModelMapper::model | |
70 | \brief Defines the model that is used by the mapper. |
|
70 | \brief Defines the model that is used by the mapper. | |
71 | */ |
|
71 | */ | |
72 | /*! |
|
72 | /*! | |
73 | \qmlproperty SomeModel VPieModelMapper::model |
|
73 | \qmlproperty SomeModel VPieModelMapper::model | |
74 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to |
|
74 | The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to | |
75 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns |
|
75 | QML as shown in \l {QML Custom Model} demo application. Note: the model has to support adding/removing rows/columns | |
76 | and modifying the data of the cells. |
|
76 | and modifying the data of the cells. | |
77 | */ |
|
77 | */ | |
78 |
|
78 | |||
79 | /*! |
|
79 | /*! | |
80 | \property QVPieModelMapper::valuesColumn |
|
80 | \property QVPieModelMapper::valuesColumn | |
81 | \brief Defines which column of the model is kept in sync with the values of the pie's slices |
|
81 | \brief Defines which column of the model is kept in sync with the values of the pie's slices | |
82 | Default value is: -1 (invalid mapping) |
|
82 | Default value is: -1 (invalid mapping) | |
83 | */ |
|
83 | */ | |
84 | /*! |
|
84 | /*! | |
85 | \qmlproperty int VPieModelMapper::valuesColumn |
|
85 | \qmlproperty int VPieModelMapper::valuesColumn | |
86 | Defines which column of the model is kept in sync with the values of the pie's slices. Default value is -1 (invalid |
|
86 | Defines which column of the model is kept in sync with the values of the pie's slices. Default value is -1 (invalid | |
87 | mapping). |
|
87 | mapping). | |
88 | */ |
|
88 | */ | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | \property QVPieModelMapper::labelsColumn |
|
91 | \property QVPieModelMapper::labelsColumn | |
92 | \brief Defines which column of the model is kept in sync with the labels of the pie's slices |
|
92 | \brief Defines which column of the model is kept in sync with the labels of the pie's slices | |
93 | Default value is: -1 (invalid mapping) |
|
93 | Default value is: -1 (invalid mapping) | |
94 | */ |
|
94 | */ | |
95 | /*! |
|
95 | /*! | |
96 | \qmlproperty int VPieModelMapper::labelsColumn |
|
96 | \qmlproperty int VPieModelMapper::labelsColumn | |
97 | Defines which column of the model is kept in sync with the labels of the pie's slices. Default value is -1 (invalid |
|
97 | Defines which column of the model is kept in sync with the labels of the pie's slices. Default value is -1 (invalid | |
98 | mapping). |
|
98 | mapping). | |
99 | */ |
|
99 | */ | |
100 |
|
100 | |||
101 | /*! |
|
101 | /*! | |
102 | \property QVPieModelMapper::firstRow |
|
102 | \property QVPieModelMapper::firstRow | |
103 | \brief Defines which row of the model contains the first slice value. |
|
103 | \brief Defines which row of the model contains the first slice value. | |
104 | Minimal and default value is: 0 |
|
104 | Minimal and default value is: 0 | |
105 | */ |
|
105 | */ | |
106 | /*! |
|
106 | /*! | |
107 | \qmlproperty int VPieModelMapper::firstRow |
|
107 | \qmlproperty int VPieModelMapper::firstRow | |
108 | Defines which row of the model contains the first slice value. |
|
108 | Defines which row of the model contains the first slice value. | |
109 | The default value is 0. |
|
109 | The default value is 0. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \property QVPieModelMapper::rowCount |
|
113 | \property QVPieModelMapper::rowCount | |
114 | \brief Defines the number of rows of the model that are mapped as the data for QPieSeries |
|
114 | \brief Defines the number of rows of the model that are mapped as the data for QPieSeries | |
115 | Minimal and default value is: -1 (count limited by the number of rows in the model) |
|
115 | Minimal and default value is: -1 (count limited by the number of rows in the model) | |
116 | */ |
|
116 | */ | |
117 | /*! |
|
117 | /*! | |
118 | \qmlproperty int VPieModelMapper::columnCount |
|
118 | \qmlproperty int VPieModelMapper::columnCount | |
119 | Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is |
|
119 | Defines the number of rows of the model that are mapped as the data for QPieSeries. The default value is | |
120 | -1 (count limited by the number of rows in the model) |
|
120 | -1 (count limited by the number of rows in the model) | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QVPieModelMapper::seriesReplaced() |
|
124 | \fn void QVPieModelMapper::seriesReplaced() | |
125 |
|
125 | |||
126 | Emitted when the series to which mapper is connected to has changed. |
|
126 | Emitted when the series to which mapper is connected to has changed. | |
127 | */ |
|
127 | */ | |
128 |
|
128 | |||
129 | /*! |
|
129 | /*! | |
130 | \fn void QVPieModelMapper::modelReplaced() |
|
130 | \fn void QVPieModelMapper::modelReplaced() | |
131 |
|
131 | |||
132 | Emitted when the model to which mapper is connected to has changed. |
|
132 | Emitted when the model to which mapper is connected to has changed. | |
133 | */ |
|
133 | */ | |
134 |
|
134 | |||
135 | /*! |
|
135 | /*! | |
136 | \fn void QVPieModelMapper::valuesColumnChanged() |
|
136 | \fn void QVPieModelMapper::valuesColumnChanged() | |
137 |
|
137 | |||
138 | Emitted when the valuesColumn has changed. |
|
138 | Emitted when the valuesColumn has changed. | |
139 | */ |
|
139 | */ | |
140 |
|
140 | |||
141 | /*! |
|
141 | /*! | |
142 | \fn void QVPieModelMapper::labelsColumnChanged() |
|
142 | \fn void QVPieModelMapper::labelsColumnChanged() | |
143 |
|
143 | |||
144 | Emitted when the labelsColumn has changed. |
|
144 | Emitted when the labelsColumn has changed. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn void QVPieModelMapper::firstRowChanged() |
|
148 | \fn void QVPieModelMapper::firstRowChanged() | |
149 | Emitted when the firstRow has changed. |
|
149 | Emitted when the firstRow has changed. | |
150 | */ |
|
150 | */ | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | \fn void QVPieModelMapper::rowCountChanged() |
|
153 | \fn void QVPieModelMapper::rowCountChanged() | |
154 | Emitted when the rowCount has changed. |
|
154 | Emitted when the rowCount has changed. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | Constructs a mapper object which is a child of \a parent. |
|
158 | Constructs a mapper object which is a child of \a parent. | |
159 | */ |
|
159 | */ | |
160 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : |
|
160 | QVPieModelMapper::QVPieModelMapper(QObject *parent) : | |
161 | QPieModelMapper(parent) |
|
161 | QPieModelMapper(parent) | |
162 | { |
|
162 | { | |
163 | QPieModelMapper::setOrientation(Qt::Vertical); |
|
163 | QPieModelMapper::setOrientation(Qt::Vertical); | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | QAbstractItemModel *QVPieModelMapper::model() const |
|
166 | QAbstractItemModel *QVPieModelMapper::model() const | |
167 | { |
|
167 | { | |
168 | return QPieModelMapper::model(); |
|
168 | return QPieModelMapper::model(); | |
169 | } |
|
169 | } | |
170 |
|
170 | |||
171 | void QVPieModelMapper::setModel(QAbstractItemModel *model) |
|
171 | void QVPieModelMapper::setModel(QAbstractItemModel *model) | |
172 | { |
|
172 | { | |
173 | if (model != QPieModelMapper::model()) { |
|
173 | if (model != QPieModelMapper::model()) { | |
174 | QPieModelMapper::setModel(model); |
|
174 | QPieModelMapper::setModel(model); | |
175 | emit modelReplaced(); |
|
175 | emit modelReplaced(); | |
176 | } |
|
176 | } | |
177 | } |
|
177 | } | |
178 |
|
178 | |||
179 | QPieSeries *QVPieModelMapper::series() const |
|
179 | QPieSeries *QVPieModelMapper::series() const | |
180 | { |
|
180 | { | |
181 | return QPieModelMapper::series(); |
|
181 | return QPieModelMapper::series(); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void QVPieModelMapper::setSeries(QPieSeries *series) |
|
184 | void QVPieModelMapper::setSeries(QPieSeries *series) | |
185 | { |
|
185 | { | |
186 | if (series != QPieModelMapper::series()) { |
|
186 | if (series != QPieModelMapper::series()) { | |
187 | QPieModelMapper::setSeries(series); |
|
187 | QPieModelMapper::setSeries(series); | |
188 | emit seriesReplaced(); |
|
188 | emit seriesReplaced(); | |
189 | } |
|
189 | } | |
190 | } |
|
190 | } | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | Returns which column of the model is kept in sync with the values of the pie's slices |
|
193 | Returns which column of the model is kept in sync with the values of the pie's slices | |
194 | */ |
|
194 | */ | |
195 | int QVPieModelMapper::valuesColumn() const |
|
195 | int QVPieModelMapper::valuesColumn() const | |
196 | { |
|
196 | { | |
197 | return QPieModelMapper::valuesSection(); |
|
197 | return QPieModelMapper::valuesSection(); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | /*! |
|
200 | /*! | |
201 | Sets the model column that is kept in sync with the pie slices values. |
|
201 | Sets the model column that is kept in sync with the pie slices values. | |
202 | Parameter \a valuesColumn specifies the row of the model. |
|
202 | Parameter \a valuesColumn specifies the row of the model. | |
203 | */ |
|
203 | */ | |
204 | void QVPieModelMapper::setValuesColumn(int valuesColumn) |
|
204 | void QVPieModelMapper::setValuesColumn(int valuesColumn) | |
205 | { |
|
205 | { | |
206 | if (valuesColumn != valuesSection()) { |
|
206 | if (valuesColumn != valuesSection()) { | |
207 | QPieModelMapper::setValuesSection(valuesColumn); |
|
207 | QPieModelMapper::setValuesSection(valuesColumn); | |
208 | emit valuesColumnChanged(); |
|
208 | emit valuesColumnChanged(); | |
209 | } |
|
209 | } | |
210 | } |
|
210 | } | |
211 |
|
211 | |||
212 | /*! |
|
212 | /*! | |
213 | Returns which column of the model is kept in sync with the labels of the pie's slices |
|
213 | Returns which column of the model is kept in sync with the labels of the pie's slices | |
214 | */ |
|
214 | */ | |
215 | int QVPieModelMapper::labelsColumn() const |
|
215 | int QVPieModelMapper::labelsColumn() const | |
216 | { |
|
216 | { | |
217 | return QPieModelMapper::labelsSection(); |
|
217 | return QPieModelMapper::labelsSection(); | |
218 | } |
|
218 | } | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 | Sets the model column that is kept in sync with the pie's slices labels. |
|
221 | Sets the model column that is kept in sync with the pie's slices labels. | |
222 | Parameter \a labelsColumn specifies the row of the model. |
|
222 | Parameter \a labelsColumn specifies the row of the model. | |
223 | */ |
|
223 | */ | |
224 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) |
|
224 | void QVPieModelMapper::setLabelsColumn(int labelsColumn) | |
225 | { |
|
225 | { | |
226 | if (labelsColumn != labelsSection()) { |
|
226 | if (labelsColumn != labelsSection()) { | |
227 | QPieModelMapper::setLabelsSection(labelsColumn); |
|
227 | QPieModelMapper::setLabelsSection(labelsColumn); | |
228 | emit labelsColumnChanged(); |
|
228 | emit labelsColumnChanged(); | |
229 | } |
|
229 | } | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | int QVPieModelMapper::firstRow() const |
|
232 | int QVPieModelMapper::firstRow() const | |
233 | { |
|
233 | { | |
234 | return first(); |
|
234 | return first(); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | void QVPieModelMapper::setFirstRow(int firstRow) |
|
237 | void QVPieModelMapper::setFirstRow(int firstRow) | |
238 | { |
|
238 | { | |
239 | if (firstRow != first()) { |
|
239 | if (firstRow != first()) { | |
240 | setFirst(firstRow); |
|
240 | setFirst(firstRow); | |
241 | emit firstRowChanged(); |
|
241 | emit firstRowChanged(); | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 |
|
244 | |||
245 | int QVPieModelMapper::rowCount() const |
|
245 | int QVPieModelMapper::rowCount() const | |
246 | { |
|
246 | { | |
247 | return count(); |
|
247 | return count(); | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | void QVPieModelMapper::setRowCount(int rowCount) |
|
250 | void QVPieModelMapper::setRowCount(int rowCount) | |
251 | { |
|
251 | { | |
252 | if (rowCount != count()) { |
|
252 | if (rowCount != count()) { | |
253 | setCount(rowCount); |
|
253 | setCount(rowCount); | |
254 | emit rowCountChanged(); |
|
254 | emit rowCountChanged(); | |
255 | } |
|
255 | } | |
256 | } |
|
256 | } | |
257 |
|
257 | |||
258 | #include "moc_qvpiemodelmapper.cpp" |
|
258 | #include "moc_qvpiemodelmapper.cpp" | |
259 |
|
259 | |||
260 | QTCOMMERCIALCHART_END_NAMESPACE |
|
260 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,314 +1,308 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qabstractseries.h" |
|
21 | #include "qabstractseries.h" | |
22 | #include "qabstractseries_p.h" |
|
22 | #include "qabstractseries_p.h" | |
23 | #include "chartdataset_p.h" |
|
23 | #include "chartdataset_p.h" | |
24 | #include "qchart.h" |
|
24 | #include "qchart.h" | |
25 | #include "qchart_p.h" |
|
25 | #include "qchart_p.h" | |
26 | #include "chartitem_p.h" |
|
26 | #include "chartitem_p.h" | |
27 | #include "xydomain_p.h" |
|
27 | #include "xydomain_p.h" | |
28 | #include "xlogydomain_p.h" |
|
28 | #include "xlogydomain_p.h" | |
29 | #include "logxydomain_p.h" |
|
29 | #include "logxydomain_p.h" | |
30 | #include "logxlogydomain_p.h" |
|
30 | #include "logxlogydomain_p.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractSeries |
|
35 | \class QAbstractSeries | |
36 | \brief Base class for all QtCommercial Chart series. |
|
36 | \brief Base class for all QtCommercial Chart series. | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | Usually you use the series type specific inherited classes instead of the base class. |
|
39 | Usually you use the series type specific inherited classes instead of the base class. | |
40 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, |
|
40 | \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QAbstractBarSeries, QStackedBarSeries, | |
41 | QPercentBarSeries, QPieSeries |
|
41 | QPercentBarSeries, QPieSeries | |
42 | */ |
|
42 | */ | |
43 | /*! |
|
43 | /*! | |
44 | \qmlclass AbstractSeries |
|
44 | \qmlclass AbstractSeries | |
45 | AbstractSeries is the base class for all series. |
|
45 | AbstractSeries is the base class for all series. | |
46 | The class cannot be instantiated by the user. |
|
46 | The class cannot be instantiated by the user. | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \enum QAbstractSeries::SeriesType |
|
50 | \enum QAbstractSeries::SeriesType | |
51 |
|
51 | |||
52 | The type of the series object. |
|
52 | The type of the series object. | |
53 |
|
53 | |||
54 | \value SeriesTypeLine |
|
54 | \value SeriesTypeLine | |
55 | \value SeriesTypeArea |
|
55 | \value SeriesTypeArea | |
56 | \value SeriesTypeBar |
|
56 | \value SeriesTypeBar | |
57 | \value SeriesTypeStackedBar |
|
57 | \value SeriesTypeStackedBar | |
58 | \value SeriesTypePercentBar |
|
58 | \value SeriesTypePercentBar | |
59 | \value SeriesTypePie |
|
59 | \value SeriesTypePie | |
60 | \value SeriesTypeScatter |
|
60 | \value SeriesTypeScatter | |
61 | \value SeriesTypeSpline |
|
61 | \value SeriesTypeSpline | |
62 | \value SeriesTypeHorizontalBar |
|
62 | \value SeriesTypeHorizontalBar | |
63 | \value SeriesTypeHorizontalStackedBar |
|
63 | \value SeriesTypeHorizontalStackedBar | |
64 | \value SeriesTypeHorizontalPercentBar |
|
64 | \value SeriesTypeHorizontalPercentBar | |
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | \property QAbstractSeries::type |
|
68 | \property QAbstractSeries::type | |
69 | The type of the series. |
|
69 | The type of the series. | |
70 | */ |
|
70 | */ | |
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty ChartView.SeriesType AbstractSeries::type |
|
72 | \qmlproperty ChartView.SeriesType AbstractSeries::type | |
73 | The type of the series. |
|
73 | The type of the series. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \property QAbstractSeries::name |
|
77 | \property QAbstractSeries::name | |
78 | \brief name of the series property. The name is shown in legend for QXYSeries. |
|
78 | \brief name of the series property. The name is shown in legend for QXYSeries. | |
79 | */ |
|
79 | */ | |
80 | /*! |
|
80 | /*! | |
81 | \qmlproperty string AbstractSeries::name |
|
81 | \qmlproperty string AbstractSeries::name | |
82 | Name of the series. The name is shown in legend for QXYSeries. |
|
82 | Name of the series. The name is shown in legend for QXYSeries. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \fn void QAbstractSeries::nameChanged() |
|
86 | \fn void QAbstractSeries::nameChanged() | |
87 | This signal is emitted when the series name changes. |
|
87 | This signal is emitted when the series name changes. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlsignal AbstractSeries::onNameChanged() |
|
90 | \qmlsignal AbstractSeries::onNameChanged() | |
91 | This signal is emitted when the series name changes. |
|
91 | This signal is emitted when the series name changes. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QAbstractSeries::visible |
|
95 | \property QAbstractSeries::visible | |
96 | \brief whether the series is visible or not; true by default. |
|
96 | \brief whether the series is visible or not; true by default. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty bool AbstractSeries::visible |
|
99 | \qmlproperty bool AbstractSeries::visible | |
100 | Visibility of the series. True by default. |
|
100 | Visibility of the series. True by default. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \fn void QAbstractSeries::visibleChanged() |
|
104 | \fn void QAbstractSeries::visibleChanged() | |
105 | Emitted when the series visibility changes. |
|
105 | Emitted when the series visibility changes. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlsignal AbstractSeries::onVisibleChanged() |
|
108 | \qmlsignal AbstractSeries::onVisibleChanged() | |
109 | Emitted when the series visibility changes. |
|
109 | Emitted when the series visibility changes. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \property QAbstractSeries::opacity |
|
113 | \property QAbstractSeries::opacity | |
114 | \brief The opacity of the series. |
|
114 | \brief The opacity of the series. | |
115 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
115 | By default the opacity is 1.0. The valid values range from 0.0 (transparent) to 1.0 (opaque). | |
116 | */ |
|
116 | */ | |
117 | /*! |
|
117 | /*! | |
118 | \qmlproperty real AbstractSeries::opacity |
|
118 | \qmlproperty real AbstractSeries::opacity | |
119 | The opacity of the series. By default the opacity is 1.0. |
|
119 | The opacity of the series. By default the opacity is 1.0. | |
120 | The valid values range from 0.0 (transparent) to 1.0 (opaque). |
|
120 | The valid values range from 0.0 (transparent) to 1.0 (opaque). | |
121 | */ |
|
121 | */ | |
122 |
|
122 | |||
123 | /*! |
|
123 | /*! | |
124 | \fn void QAbstractSeries::opacityChanged() |
|
124 | \fn void QAbstractSeries::opacityChanged() | |
125 | Emitted when the opacity of the series changes. |
|
125 | Emitted when the opacity of the series changes. | |
126 | */ |
|
126 | */ | |
127 | /*! |
|
127 | /*! | |
128 | \qmlsignal AbstractSeries::onOpacityChanged() |
|
128 | \qmlsignal AbstractSeries::onOpacityChanged() | |
129 | Emitted when the opacity of the series changes. |
|
129 | Emitted when the opacity of the series changes. | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \internal |
|
133 | \internal | |
134 |
\brief Constructs |
|
134 | \brief Constructs QAbstractSeries object with \a parent. | |
135 | */ |
|
135 | */ | |
136 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : |
|
136 | QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) : | |
137 | QObject(parent), |
|
137 | QObject(parent), | |
138 | d_ptr(&d) |
|
138 | d_ptr(&d) | |
139 | { |
|
139 | { | |
140 | } |
|
140 | } | |
141 |
|
141 | |||
142 | /*! |
|
142 | /*! | |
143 | \brief Virtual destructor for the chart series. |
|
143 | \brief Virtual destructor for the chart series. | |
144 | */ |
|
144 | */ | |
145 | QAbstractSeries::~QAbstractSeries() |
|
145 | QAbstractSeries::~QAbstractSeries() | |
146 | { |
|
146 | { | |
147 | if (d_ptr->m_chart) |
|
147 | if (d_ptr->m_chart) | |
148 |
qFatal("Still b |
|
148 | qFatal("Series still bound to a chart when destroyed!"); | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 | void QAbstractSeries::setName(const QString &name) |
|
151 | void QAbstractSeries::setName(const QString &name) | |
152 | { |
|
152 | { | |
153 | if (name != d_ptr->m_name) { |
|
153 | if (name != d_ptr->m_name) { | |
154 | d_ptr->m_name = name; |
|
154 | d_ptr->m_name = name; | |
155 | emit nameChanged(); |
|
155 | emit nameChanged(); | |
156 | } |
|
156 | } | |
157 | } |
|
157 | } | |
158 |
|
158 | |||
159 | QString QAbstractSeries::name() const |
|
159 | QString QAbstractSeries::name() const | |
160 | { |
|
160 | { | |
161 | return d_ptr->m_name; |
|
161 | return d_ptr->m_name; | |
162 | } |
|
162 | } | |
163 |
|
163 | |||
164 | /*! |
|
|||
165 | Sets the visibility of series to \a visible |
|
|||
166 | */ |
|
|||
167 | void QAbstractSeries::setVisible(bool visible) |
|
164 | void QAbstractSeries::setVisible(bool visible) | |
168 | { |
|
165 | { | |
169 | if (visible != d_ptr->m_visible) { |
|
166 | if (visible != d_ptr->m_visible) { | |
170 | d_ptr->m_visible = visible; |
|
167 | d_ptr->m_visible = visible; | |
171 | emit visibleChanged(); |
|
168 | emit visibleChanged(); | |
172 | } |
|
169 | } | |
173 | } |
|
170 | } | |
174 |
|
171 | |||
175 | /*! |
|
|||
176 | Returns the visibility of series |
|
|||
177 | */ |
|
|||
178 | bool QAbstractSeries::isVisible() const |
|
172 | bool QAbstractSeries::isVisible() const | |
179 | { |
|
173 | { | |
180 | return d_ptr->m_visible; |
|
174 | return d_ptr->m_visible; | |
181 | } |
|
175 | } | |
182 |
|
176 | |||
183 | qreal QAbstractSeries::opacity() const |
|
177 | qreal QAbstractSeries::opacity() const | |
184 | { |
|
178 | { | |
185 | return d_ptr->m_opacity; |
|
179 | return d_ptr->m_opacity; | |
186 | } |
|
180 | } | |
187 |
|
181 | |||
188 | void QAbstractSeries::setOpacity(qreal opacity) |
|
182 | void QAbstractSeries::setOpacity(qreal opacity) | |
189 | { |
|
183 | { | |
190 | if (opacity != d_ptr->m_opacity) { |
|
184 | if (opacity != d_ptr->m_opacity) { | |
191 | d_ptr->m_opacity = opacity; |
|
185 | d_ptr->m_opacity = opacity; | |
192 | emit opacityChanged(); |
|
186 | emit opacityChanged(); | |
193 | } |
|
187 | } | |
194 | } |
|
188 | } | |
195 |
|
189 | |||
196 | /*! |
|
190 | /*! | |
197 | \brief Returns the chart where series belongs to. |
|
191 | \brief Returns the chart where series belongs to. | |
198 |
|
192 | |||
199 | Set automatically when the series is added to the chart |
|
193 | Set automatically when the series is added to the chart | |
200 | and unset when the series is removed from the chart. |
|
194 | and unset when the series is removed from the chart. | |
201 | */ |
|
195 | */ | |
202 | QChart *QAbstractSeries::chart() const |
|
196 | QChart *QAbstractSeries::chart() const | |
203 | { |
|
197 | { | |
204 | return d_ptr->m_chart; |
|
198 | return d_ptr->m_chart; | |
205 | } |
|
199 | } | |
206 |
|
200 | |||
207 | /*! |
|
201 | /*! | |
208 | \brief Sets the visibility of the series to true |
|
202 | \brief Sets the visibility of the series to true | |
209 |
|
203 | |||
210 | \sa setVisible(), isVisible() |
|
204 | \sa setVisible(), isVisible() | |
211 | */ |
|
205 | */ | |
212 | void QAbstractSeries::show() |
|
206 | void QAbstractSeries::show() | |
213 | { |
|
207 | { | |
214 | setVisible(true); |
|
208 | setVisible(true); | |
215 | } |
|
209 | } | |
216 |
|
210 | |||
217 | /*! |
|
211 | /*! | |
218 | \brief Sets the visibility of the series to false |
|
212 | \brief Sets the visibility of the series to false | |
219 |
|
213 | |||
220 | \sa setVisible(), isVisible() |
|
214 | \sa setVisible(), isVisible() | |
221 | */ |
|
215 | */ | |
222 | void QAbstractSeries::hide() |
|
216 | void QAbstractSeries::hide() | |
223 | { |
|
217 | { | |
224 | setVisible(false); |
|
218 | setVisible(false); | |
225 | } |
|
219 | } | |
226 |
|
220 | |||
227 | /*! |
|
221 | /*! | |
228 | Attach \a axis to the series. |
|
222 | Attach \a axis to the series. | |
229 | \return true if the axis was attached successfully, false otherwise. |
|
223 | \return true if the axis was attached successfully, false otherwise. | |
230 | \sa QChart::addAxis(), QChart::createDefaultAxes() |
|
224 | \sa QChart::addAxis(), QChart::createDefaultAxes() | |
231 | */ |
|
225 | */ | |
232 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) |
|
226 | bool QAbstractSeries::attachAxis(QAbstractAxis* axis) | |
233 | { |
|
227 | { | |
234 | if(d_ptr->m_chart) { |
|
228 | if(d_ptr->m_chart) { | |
235 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); |
|
229 | return d_ptr->m_chart->d_ptr->m_dataset->attachAxis(this, axis); | |
236 | } else { |
|
230 | } else { | |
237 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
231 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |
238 | return false; |
|
232 | return false; | |
239 | } |
|
233 | } | |
240 | } |
|
234 | } | |
241 |
|
235 | |||
242 | /*! |
|
236 | /*! | |
243 | Detach \a axis from the series. |
|
237 | Detach \a axis from the series. | |
244 | \return true if the axis was detached successfully, false otherwise. |
|
238 | \return true if the axis was detached successfully, false otherwise. | |
245 | \sa QChart::removeAxis() |
|
239 | \sa QChart::removeAxis() | |
246 | */ |
|
240 | */ | |
247 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) |
|
241 | bool QAbstractSeries::detachAxis(QAbstractAxis* axis) | |
248 | { |
|
242 | { | |
249 | if(d_ptr->m_chart) { |
|
243 | if(d_ptr->m_chart) { | |
250 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); |
|
244 | return d_ptr->m_chart->d_ptr->m_dataset->detachAxis(this, axis); | |
251 | } |
|
245 | } | |
252 | else { |
|
246 | else { | |
253 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; |
|
247 | qWarning()<<"Series not in the chart. Please addSeries to chart first."; | |
254 | return false; |
|
248 | return false; | |
255 | } |
|
249 | } | |
256 | } |
|
250 | } | |
257 |
|
251 | |||
258 | /*! |
|
252 | /*! | |
259 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except |
|
253 | Returns the list of axes attached to the series. Usually there is an x-axis and a y-axis attached to a series, except | |
260 | in case of a QPieSeries, which does not have any axes attached. |
|
254 | in case of a QPieSeries, which does not have any axes attached. | |
261 | \sa attachAxis(), detachAxis() |
|
255 | \sa attachAxis(), detachAxis() | |
262 | */ |
|
256 | */ | |
263 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() |
|
257 | QList<QAbstractAxis*> QAbstractSeries::attachedAxes() | |
264 | { |
|
258 | { | |
265 | return d_ptr->m_axes; |
|
259 | return d_ptr->m_axes; | |
266 | } |
|
260 | } | |
267 |
|
261 | |||
268 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
262 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
269 |
|
263 | |||
270 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) |
|
264 | QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries *q) | |
271 | : q_ptr(q), |
|
265 | : q_ptr(q), | |
272 | m_chart(0), |
|
266 | m_chart(0), | |
273 | m_item(0), |
|
267 | m_item(0), | |
274 | m_domain(new XYDomain()), |
|
268 | m_domain(new XYDomain()), | |
275 | m_visible(true), |
|
269 | m_visible(true), | |
276 | m_opacity(1.0) |
|
270 | m_opacity(1.0) | |
277 | { |
|
271 | { | |
278 | } |
|
272 | } | |
279 |
|
273 | |||
280 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() |
|
274 | QAbstractSeriesPrivate::~QAbstractSeriesPrivate() | |
281 | { |
|
275 | { | |
282 | } |
|
276 | } | |
283 |
|
277 | |||
284 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) |
|
278 | void QAbstractSeriesPrivate::setDomain(AbstractDomain* domain) | |
285 | { |
|
279 | { | |
286 | Q_ASSERT(domain); |
|
280 | Q_ASSERT(domain); | |
287 | if(m_domain.data()!=domain) { |
|
281 | if(m_domain.data()!=domain) { | |
288 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); |
|
282 | if(!m_item.isNull()) QObject::disconnect(m_domain.data(), SIGNAL(updated()), m_item.data(), SLOT(handleDomainUpdated())); | |
289 | m_domain.reset(domain); |
|
283 | m_domain.reset(domain); | |
290 | if(!m_item.isNull()) { |
|
284 | if(!m_item.isNull()) { | |
291 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
285 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |
292 | m_item->handleDomainUpdated(); |
|
286 | m_item->handleDomainUpdated(); | |
293 | } |
|
287 | } | |
294 | } |
|
288 | } | |
295 | } |
|
289 | } | |
296 |
|
290 | |||
297 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
291 | void QAbstractSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
298 | { |
|
292 | { | |
299 | Q_ASSERT(!m_item.isNull()); |
|
293 | Q_ASSERT(!m_item.isNull()); | |
300 | Q_UNUSED(parent); |
|
294 | Q_UNUSED(parent); | |
301 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); |
|
295 | QObject::connect(m_domain.data(), SIGNAL(updated()),m_item.data(), SLOT(handleDomainUpdated())); | |
302 | } |
|
296 | } | |
303 |
|
297 | |||
304 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
298 | void QAbstractSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |
305 | { |
|
299 | { | |
306 | Q_UNUSED(options); |
|
300 | Q_UNUSED(options); | |
307 | } |
|
301 | } | |
308 |
|
302 | |||
309 | #include "moc_qabstractseries.cpp" |
|
303 | #include "moc_qabstractseries.cpp" | |
310 | #include "moc_qabstractseries_p.cpp" |
|
304 | #include "moc_qabstractseries_p.cpp" | |
311 |
|
305 | |||
312 | QTCOMMERCIALCHART_END_NAMESPACE |
|
306 | QTCOMMERCIALCHART_END_NAMESPACE | |
313 |
|
307 | |||
314 |
|
308 |
@@ -1,710 +1,696 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchart.h" |
|
21 | #include "qchart.h" | |
22 | #include "qchart_p.h" |
|
22 | #include "qchart_p.h" | |
23 | #include "legendscroller_p.h" |
|
23 | #include "legendscroller_p.h" | |
24 | #include "qlegend_p.h" |
|
24 | #include "qlegend_p.h" | |
25 | #include "chartbackground_p.h" |
|
25 | #include "chartbackground_p.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include "abstractchartlayout_p.h" |
|
27 | #include "abstractchartlayout_p.h" | |
28 | #include "charttheme_p.h" |
|
28 | #include "charttheme_p.h" | |
29 | #include "chartpresenter_p.h" |
|
29 | #include "chartpresenter_p.h" | |
30 | #include "chartdataset_p.h" |
|
30 | #include "chartdataset_p.h" | |
31 | #include <QGraphicsScene> |
|
31 | #include <QGraphicsScene> | |
32 | #include <QGraphicsSceneResizeEvent> |
|
32 | #include <QGraphicsSceneResizeEvent> | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \enum QChart::ChartTheme |
|
37 | \enum QChart::ChartTheme | |
38 |
|
38 | |||
39 | This enum describes the theme used by the chart. |
|
39 | This enum describes the theme used by the chart. | |
40 |
|
40 | |||
41 | \value ChartThemeLight The default theme |
|
41 | \value ChartThemeLight The default theme | |
42 | \value ChartThemeBlueCerulean |
|
42 | \value ChartThemeBlueCerulean | |
43 | \value ChartThemeDark |
|
43 | \value ChartThemeDark | |
44 | \value ChartThemeBrownSand |
|
44 | \value ChartThemeBrownSand | |
45 | \value ChartThemeBlueNcs |
|
45 | \value ChartThemeBlueNcs | |
46 | \value ChartThemeHighContrast |
|
46 | \value ChartThemeHighContrast | |
47 | \value ChartThemeBlueIcy |
|
47 | \value ChartThemeBlueIcy | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \enum QChart::AnimationOption |
|
51 | \enum QChart::AnimationOption | |
52 |
|
52 | |||
53 | For enabling/disabling animations. Defaults to NoAnimation. |
|
53 | For enabling/disabling animations. Defaults to NoAnimation. | |
54 |
|
54 | |||
55 | \value NoAnimation |
|
55 | \value NoAnimation | |
56 | \value GridAxisAnimations |
|
56 | \value GridAxisAnimations | |
57 | \value SeriesAnimations |
|
57 | \value SeriesAnimations | |
58 | \value AllAnimations |
|
58 | \value AllAnimations | |
59 | */ |
|
59 | */ | |
60 |
|
60 | |||
61 | /*! |
|
61 | /*! | |
62 | \enum QChart::ChartType |
|
62 | \enum QChart::ChartType | |
63 |
|
63 | |||
64 | This enum describes the chart type. |
|
64 | This enum describes the chart type. | |
65 |
|
65 | |||
66 | \value ChartTypeUndefined |
|
66 | \value ChartTypeUndefined | |
67 | \value ChartTypeCartesian |
|
67 | \value ChartTypeCartesian | |
68 | \value ChartTypePolar |
|
68 | \value ChartTypePolar | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \class QChart |
|
72 | \class QChart | |
73 | \brief QtCommercial chart API. |
|
73 | \brief QtCommercial chart API. | |
74 |
|
74 | |||
75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical |
|
75 | QChart is a QGraphicsWidget that you can show in a QGraphicsScene. It manages the graphical | |
76 | representation of different types of series and other chart related objects like |
|
76 | representation of different types of series and other chart related objects like legend and | |
77 |
|
|
77 | axes. If you simply want to show a chart in a layout, you can use the | |
78 | convenience class QChartView instead of QChart. |
|
78 | convenience class QChartView instead of QChart. | |
79 | \sa QChartView |
|
79 | \sa QChartView, QPolarChart | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | \property QChart::animationOptions |
|
83 | \property QChart::animationOptions | |
84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. |
|
84 | The animation \a options for the chart. Animations are enabled/disabled based on this setting. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QChart::backgroundVisible |
|
88 | \property QChart::backgroundVisible | |
89 |
|
|
89 | Specifies whether the chart background is visible or not. | |
90 | \sa setBackgroundBrush(), setBackgroundPen() |
|
90 | \sa setBackgroundBrush(), setBackgroundPen() | |
91 | */ |
|
91 | */ | |
92 |
|
92 | |||
93 | /*! |
|
93 | /*! | |
94 | \property QChart::dropShadowEnabled |
|
94 | \property QChart::dropShadowEnabled | |
95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop |
|
95 | If set to true, the background drop shadow effect is enabled. If set to false, it is disabled. Note that the drop | |
96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. |
|
96 | shadow effect depends on theme, which means the setting may be changed if you switch to another theme. | |
97 | */ |
|
97 | */ | |
98 |
|
98 | |||
99 | /*! |
|
99 | /*! | |
100 | \property QChart::minimumMargins |
|
100 | \property QChart::minimumMargins | |
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. |
|
101 | Minimum margins between the plot area (axes) and the edge of the chart widget. | |
|
102 | This property is deprecated; use margins property instead. | |||
|
103 | ||||
|
104 | \sa margins | |||
102 | */ |
|
105 | */ | |
103 |
|
106 | |||
104 | /*! |
|
107 | /*! | |
105 | \property QChart::margins |
|
108 | \property QChart::margins | |
106 |
M |
|
109 | Margins between the plot area (axes) and the edge of the chart widget. | |
107 | */ |
|
110 | */ | |
108 |
|
111 | |||
109 | /*! |
|
112 | /*! | |
110 | \property QChart::theme |
|
113 | \property QChart::theme | |
111 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, |
|
114 | Theme is a built-in collection of UI style related settings applied for all visual elements of a chart, like colors, | |
112 | pens, brushes and fonts of series, axes, title and legend. \l {Chart themes demo} shows an example with a few |
|
115 | pens, brushes, and fonts of series, axes, title, and legend. \l {Chart themes demo} shows an example with a few | |
113 | different themes. |
|
116 | different themes. | |
114 |
|
|
117 | \note Changing the theme will overwrite all customizations previously applied to the series. | |
115 | */ |
|
118 | */ | |
116 |
|
119 | |||
117 | /*! |
|
120 | /*! | |
118 | \property QChart::title |
|
121 | \property QChart::title | |
119 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. |
|
122 | Title is the name (label) of a chart. It is shown as a headline on top of the chart. | |
120 | */ |
|
123 | */ | |
121 |
|
124 | |||
122 | /*! |
|
125 | /*! | |
123 | \property QChart::chartType |
|
126 | \property QChart::chartType | |
124 | Chart type indicates if the chart is a cartesian chart or a polar chart. |
|
127 | Chart type indicates if the chart is a cartesian chart or a polar chart. | |
125 | This property is set internally and is read only. |
|
128 | This property is set internally and it is read only. | |
126 | \sa QPolarChart |
|
129 | \sa QPolarChart | |
127 | */ |
|
130 | */ | |
128 |
|
131 | |||
129 | /*! |
|
132 | /*! | |
130 | \internal |
|
133 | \internal | |
131 | Constructs a chart object of \a type which is a child of a \a parent. |
|
134 | Constructs a chart object of \a type which is a child of a \a parent. | |
132 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
135 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
133 | This constructor is called only by subclasses. |
|
136 | This constructor is called only by subclasses. | |
134 | */ |
|
137 | */ | |
135 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
138 | QChart::QChart(QChart::ChartType type, QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
136 | : QGraphicsWidget(parent, wFlags), |
|
139 | : QGraphicsWidget(parent, wFlags), | |
137 | d_ptr(new QChartPrivate(this, type)) |
|
140 | d_ptr(new QChartPrivate(this, type)) | |
138 | { |
|
141 | { | |
139 | d_ptr->init(); |
|
142 | d_ptr->init(); | |
140 | } |
|
143 | } | |
141 |
|
144 | |||
142 | /*! |
|
145 | /*! | |
143 | Constructs a chart object which is a child of a \a parent. |
|
146 | Constructs a chart object which is a child of a \a parent. | |
144 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. |
|
147 | Parameter \a wFlags is passed to the QGraphicsWidget constructor. | |
145 | */ |
|
148 | */ | |
146 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
149 | QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
147 | : QGraphicsWidget(parent, wFlags), |
|
150 | : QGraphicsWidget(parent, wFlags), | |
148 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) |
|
151 | d_ptr(new QChartPrivate(this, ChartTypeCartesian)) | |
149 | { |
|
152 | { | |
150 | d_ptr->init(); |
|
153 | d_ptr->init(); | |
151 | } |
|
154 | } | |
152 |
|
155 | |||
153 | /*! |
|
156 | /*! | |
154 |
Destroys the object and it |
|
157 | Destroys the chart object and its children, like series and axis objects added to it. | |
155 | */ |
|
158 | */ | |
156 | QChart::~QChart() |
|
159 | QChart::~QChart() | |
157 | { |
|
160 | { | |
158 | //start by deleting dataset, it will remove all series and axes |
|
161 | //start by deleting dataset, it will remove all series and axes | |
159 | delete d_ptr->m_dataset; |
|
162 | delete d_ptr->m_dataset; | |
160 | d_ptr->m_dataset = 0; |
|
163 | d_ptr->m_dataset = 0; | |
161 | } |
|
164 | } | |
162 |
|
165 | |||
163 | /*! |
|
166 | /*! | |
164 |
Adds the \a series onto the chart and takes the ownership of |
|
167 | Adds the \a series onto the chart and takes the ownership of it. | |
165 | If auto scaling is enabled, re-scales the axes the series is bound to (both the x axis and |
|
168 | ||
166 | the y axis). |
|
169 | \note A newly added series is attached to no axes by default, including any axes that were created for the chart | |
|
170 | using createDefaultAxes() before the series was added to the chart. If no axes are attached to | |||
|
171 | the newly added series before the chart is shown, the series will get drawn as if it had axes with ranges | |||
|
172 | that exactly fit the series to the plot area of the chart. This can be confusing if the same chart also displays other | |||
|
173 | series that have properly attached axes, so always make sure you either call createDefaultAxes() after | |||
|
174 | a series has been added or explicitly attach axes for the series. | |||
167 |
|
175 | |||
168 | \sa removeSeries(), removeAllSeries() |
|
176 | \sa removeSeries(), removeAllSeries(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
169 | */ |
|
177 | */ | |
170 | void QChart::addSeries(QAbstractSeries *series) |
|
178 | void QChart::addSeries(QAbstractSeries *series) | |
171 | { |
|
179 | { | |
172 | Q_ASSERT(series); |
|
180 | Q_ASSERT(series); | |
173 | d_ptr->m_dataset->addSeries(series); |
|
181 | d_ptr->m_dataset->addSeries(series); | |
174 | } |
|
182 | } | |
175 |
|
183 | |||
176 | /*! |
|
184 | /*! | |
177 |
Removes the \a series |
|
185 | Removes the \a series from the chart. | |
178 |
|
|
186 | The chart releases its ownership of the specified \a series object. | |
179 | It does not delete the pointed QChartSeries data object |
|
187 | ||
180 | \sa addSeries(), removeAllSeries() |
|
188 | \sa addSeries(), removeAllSeries() | |
181 | */ |
|
189 | */ | |
182 | void QChart::removeSeries(QAbstractSeries *series) |
|
190 | void QChart::removeSeries(QAbstractSeries *series) | |
183 | { |
|
191 | { | |
184 | Q_ASSERT(series); |
|
192 | Q_ASSERT(series); | |
185 | d_ptr->m_dataset->removeSeries(series); |
|
193 | d_ptr->m_dataset->removeSeries(series); | |
186 | } |
|
194 | } | |
187 |
|
195 | |||
188 | /*! |
|
196 | /*! | |
189 |
Removes a |
|
197 | Removes and deletes all series objects that have been added to the chart. | |
190 | It also deletes the pointed QChartSeries data objects |
|
198 | ||
191 | \sa addSeries(), removeSeries() |
|
199 | \sa addSeries(), removeSeries() | |
192 | */ |
|
200 | */ | |
193 | void QChart::removeAllSeries() |
|
201 | void QChart::removeAllSeries() | |
194 | { |
|
202 | { | |
195 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ |
|
203 | foreach (QAbstractSeries *s , d_ptr->m_dataset->series()){ | |
196 | removeSeries(s); |
|
204 | removeSeries(s); | |
197 | delete s; |
|
205 | delete s; | |
198 | } |
|
206 | } | |
199 | } |
|
207 | } | |
200 |
|
208 | |||
201 | /*! |
|
209 | /*! | |
202 | Sets the \a brush that is used for painting the background of the chart area. |
|
210 | Sets the \a brush that is used for painting the background of the chart area. | |
203 | */ |
|
211 | */ | |
204 | void QChart::setBackgroundBrush(const QBrush &brush) |
|
212 | void QChart::setBackgroundBrush(const QBrush &brush) | |
205 | { |
|
213 | { | |
206 | d_ptr->m_presenter->setBackgroundBrush(brush); |
|
214 | d_ptr->m_presenter->setBackgroundBrush(brush); | |
207 | } |
|
215 | } | |
208 |
|
216 | |||
209 | /*! |
|
217 | /*! | |
210 |
|
|
218 | Gets the brush that is used for painting the background of the chart area. | |
211 | */ |
|
219 | */ | |
212 | QBrush QChart::backgroundBrush() const |
|
220 | QBrush QChart::backgroundBrush() const | |
213 | { |
|
221 | { | |
214 | return d_ptr->m_presenter->backgroundBrush(); |
|
222 | return d_ptr->m_presenter->backgroundBrush(); | |
215 | } |
|
223 | } | |
216 |
|
224 | |||
217 | /*! |
|
225 | /*! | |
218 | Sets the \a pen that is used for painting the background of the chart area. |
|
226 | Sets the \a pen that is used for painting the background of the chart area. | |
219 | */ |
|
227 | */ | |
220 | void QChart::setBackgroundPen(const QPen &pen) |
|
228 | void QChart::setBackgroundPen(const QPen &pen) | |
221 | { |
|
229 | { | |
222 | d_ptr->m_presenter->setBackgroundPen(pen); |
|
230 | d_ptr->m_presenter->setBackgroundPen(pen); | |
223 | } |
|
231 | } | |
224 |
|
232 | |||
225 | /*! |
|
233 | /*! | |
226 |
|
|
234 | Gets the pen that is used for painting the background of the chart area. | |
227 | */ |
|
235 | */ | |
228 | QPen QChart::backgroundPen() const |
|
236 | QPen QChart::backgroundPen() const | |
229 | { |
|
237 | { | |
230 | return d_ptr->m_presenter->backgroundPen(); |
|
238 | return d_ptr->m_presenter->backgroundPen(); | |
231 | } |
|
239 | } | |
232 |
|
240 | |||
233 | /*! |
|
|||
234 | Sets the chart \a title. The description text that is drawn above the chart. |
|
|||
235 | */ |
|
|||
236 | void QChart::setTitle(const QString &title) |
|
241 | void QChart::setTitle(const QString &title) | |
237 | { |
|
242 | { | |
238 | d_ptr->m_presenter->setTitle(title); |
|
243 | d_ptr->m_presenter->setTitle(title); | |
239 | } |
|
244 | } | |
240 |
|
245 | |||
241 | /*! |
|
|||
242 | Returns the chart title. The description text that is drawn above the chart. |
|
|||
243 | */ |
|
|||
244 | QString QChart::title() const |
|
246 | QString QChart::title() const | |
245 | { |
|
247 | { | |
246 | return d_ptr->m_presenter->title(); |
|
248 | return d_ptr->m_presenter->title(); | |
247 | } |
|
249 | } | |
248 |
|
250 | |||
249 | /*! |
|
251 | /*! | |
250 |
Sets the \a font that is used for drawing the chart |
|
252 | Sets the \a font that is used for drawing the chart title. | |
251 | */ |
|
253 | */ | |
252 | void QChart::setTitleFont(const QFont &font) |
|
254 | void QChart::setTitleFont(const QFont &font) | |
253 | { |
|
255 | { | |
254 | d_ptr->m_presenter->setTitleFont(font); |
|
256 | d_ptr->m_presenter->setTitleFont(font); | |
255 | } |
|
257 | } | |
256 |
|
258 | |||
257 | /*! |
|
259 | /*! | |
258 |
|
|
260 | Gets the font that is used for drawing the chart title. | |
259 | */ |
|
261 | */ | |
260 | QFont QChart::titleFont() const |
|
262 | QFont QChart::titleFont() const | |
261 | { |
|
263 | { | |
262 | return d_ptr->m_presenter->titleFont(); |
|
264 | return d_ptr->m_presenter->titleFont(); | |
263 | } |
|
265 | } | |
264 |
|
266 | |||
265 | /*! |
|
267 | /*! | |
266 |
Sets the \a brush used for |
|
268 | Sets the \a brush used for drawing the title text. | |
267 | */ |
|
269 | */ | |
268 | void QChart::setTitleBrush(const QBrush &brush) |
|
270 | void QChart::setTitleBrush(const QBrush &brush) | |
269 | { |
|
271 | { | |
270 | d_ptr->m_presenter->setTitleBrush(brush); |
|
272 | d_ptr->m_presenter->setTitleBrush(brush); | |
271 | } |
|
273 | } | |
272 |
|
274 | |||
273 | /*! |
|
275 | /*! | |
274 |
Returns the brush used for |
|
276 | Returns the brush used for drawing the title text. | |
275 | */ |
|
277 | */ | |
276 | QBrush QChart::titleBrush() const |
|
278 | QBrush QChart::titleBrush() const | |
277 | { |
|
279 | { | |
278 | return d_ptr->m_presenter->titleBrush(); |
|
280 | return d_ptr->m_presenter->titleBrush(); | |
279 | } |
|
281 | } | |
280 |
|
282 | |||
281 | void QChart::setTheme(QChart::ChartTheme theme) |
|
283 | void QChart::setTheme(QChart::ChartTheme theme) | |
282 | { |
|
284 | { | |
283 | d_ptr->m_themeManager->setTheme(theme); |
|
285 | d_ptr->m_themeManager->setTheme(theme); | |
284 | } |
|
286 | } | |
285 |
|
287 | |||
286 | QChart::ChartTheme QChart::theme() const |
|
288 | QChart::ChartTheme QChart::theme() const | |
287 | { |
|
289 | { | |
288 | return d_ptr->m_themeManager->theme()->id(); |
|
290 | return d_ptr->m_themeManager->theme()->id(); | |
289 | } |
|
291 | } | |
290 |
|
292 | |||
291 | /*! |
|
293 | /*! | |
292 |
Zooms in the view by a factor of |
|
294 | Zooms in the view by a factor of two. | |
293 | */ |
|
295 | */ | |
294 | void QChart::zoomIn() |
|
296 | void QChart::zoomIn() | |
295 | { |
|
297 | { | |
296 | d_ptr->zoomIn(2.0); |
|
298 | d_ptr->zoomIn(2.0); | |
297 | } |
|
299 | } | |
298 |
|
300 | |||
299 | /*! |
|
301 | /*! | |
300 | Zooms in the view to a maximum level at which \a rect is still fully visible. |
|
302 | Zooms in the view to a maximum level at which \a rect is still fully visible. | |
301 | \note This is not supported for polar charts. |
|
303 | \note This is not supported for polar charts. | |
302 | */ |
|
304 | */ | |
303 | void QChart::zoomIn(const QRectF &rect) |
|
305 | void QChart::zoomIn(const QRectF &rect) | |
304 | { |
|
306 | { | |
305 | if (d_ptr->m_type == QChart::ChartTypePolar) |
|
307 | if (d_ptr->m_type == QChart::ChartTypePolar) | |
306 | return; |
|
308 | return; | |
307 | d_ptr->zoomIn(rect); |
|
309 | d_ptr->zoomIn(rect); | |
308 | } |
|
310 | } | |
309 |
|
311 | |||
310 | /*! |
|
312 | /*! | |
311 | Restores the view zoom level to the previous one. |
|
313 | Zooms out the view by a factor of two. | |
312 | */ |
|
314 | */ | |
313 | void QChart::zoomOut() |
|
315 | void QChart::zoomOut() | |
314 | { |
|
316 | { | |
315 | d_ptr->zoomOut(2.0); |
|
317 | d_ptr->zoomOut(2.0); | |
316 | } |
|
318 | } | |
317 |
|
319 | |||
318 | /*! |
|
320 | /*! | |
319 | Zooms in the view by a \a factor. |
|
321 | Zooms in the view by a custom \a factor. | |
320 |
|
322 | |||
321 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. |
|
323 | A factor over 1.0 zooms the view in and factor between 0.0 and 1.0 zooms out. | |
322 | */ |
|
324 | */ | |
323 | void QChart::zoom(qreal factor) |
|
325 | void QChart::zoom(qreal factor) | |
324 | { |
|
326 | { | |
325 | if (qFuzzyCompare(factor, 0)) |
|
327 | if (qFuzzyCompare(factor, 0)) | |
326 | return; |
|
328 | return; | |
327 |
|
329 | |||
328 | if (qFuzzyCompare(factor, (qreal)1.0)) |
|
330 | if (qFuzzyCompare(factor, (qreal)1.0)) | |
329 | return; |
|
331 | return; | |
330 |
|
332 | |||
331 | if (factor < 0) |
|
333 | if (factor < 0) | |
332 | return; |
|
334 | return; | |
333 |
|
335 | |||
334 | if (factor > 1.0) |
|
336 | if (factor > 1.0) | |
335 | d_ptr->zoomIn(factor); |
|
337 | d_ptr->zoomIn(factor); | |
336 | else |
|
338 | else | |
337 | d_ptr->zoomOut(1.0 / factor); |
|
339 | d_ptr->zoomOut(1.0 / factor); | |
338 | } |
|
340 | } | |
339 |
|
341 | |||
340 | /*! |
|
342 | /*! | |
341 |
Returns |
|
343 | Returns a pointer to the horizontal axis attached to the specified \a series. | |
342 | If no series is provided then pointer to currently visible axis is provided. |
|
344 | If no \a series is specified, the first horizontal axis added to the chart is returned. | |
|
345 | ||||
|
346 | \sa addAxis(), QAbstractSeries::attachAxis() | |||
343 | */ |
|
347 | */ | |
344 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const |
|
348 | QAbstractAxis *QChart::axisX(QAbstractSeries *series) const | |
345 | { |
|
349 | { | |
346 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); |
|
350 | QList<QAbstractAxis *> axisList = axes(Qt::Horizontal, series); | |
347 | if (axisList.count()) |
|
351 | if (axisList.count()) | |
348 | return axisList[0]; |
|
352 | return axisList[0]; | |
349 | return 0; |
|
353 | return 0; | |
350 | } |
|
354 | } | |
351 |
|
355 | |||
352 | /*! |
|
356 | /*! | |
353 |
Returns |
|
357 | Returns a pointer to the vertical axis attached to the specified \a series. | |
354 | If no series is provided then pointer to currently visible axis is provided. |
|
358 | If no \a series is specified, the first vertical axis added to the chart is returned. | |
|
359 | ||||
|
360 | \sa addAxis(), QAbstractSeries::attachAxis() | |||
355 | */ |
|
361 | */ | |
356 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const |
|
362 | QAbstractAxis *QChart::axisY(QAbstractSeries *series) const | |
357 | { |
|
363 | { | |
358 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); |
|
364 | QList<QAbstractAxis *> axisList = axes(Qt::Vertical, series); | |
359 | if (axisList.count()) |
|
365 | if (axisList.count()) | |
360 | return axisList[0]; |
|
366 | return axisList[0]; | |
361 | return 0; |
|
367 | return 0; | |
362 | } |
|
368 | } | |
363 |
|
369 | |||
364 | /*! |
|
370 | /*! | |
365 |
Returns the axes a |
|
371 | Returns the axes attached to the \a series with \a orientation. If no \a series is provided, | |
366 | specified orientation are returned. |
|
372 | then all axes added to the chart with the specified orientation are returned. | |
367 | \sa addAxis(), createDefaultAxes() |
|
373 | \sa addAxis(), createDefaultAxes() | |
368 | */ |
|
374 | */ | |
369 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const |
|
375 | QList<QAbstractAxis *> QChart::axes(Qt::Orientations orientation, QAbstractSeries *series) const | |
370 | { |
|
376 | { | |
371 | QList<QAbstractAxis *> result ; |
|
377 | QList<QAbstractAxis *> result ; | |
372 |
|
378 | |||
373 | if (series) { |
|
379 | if (series) { | |
374 | foreach (QAbstractAxis *axis, series->attachedAxes()){ |
|
380 | foreach (QAbstractAxis *axis, series->attachedAxes()){ | |
375 | if (orientation.testFlag(axis->orientation())) |
|
381 | if (orientation.testFlag(axis->orientation())) | |
376 | result << axis; |
|
382 | result << axis; | |
377 | } |
|
383 | } | |
378 | } else { |
|
384 | } else { | |
379 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ |
|
385 | foreach (QAbstractAxis *axis, d_ptr->m_dataset->axes()){ | |
380 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) |
|
386 | if (orientation.testFlag(axis->orientation()) && !result.contains(axis)) | |
381 | result << axis; |
|
387 | result << axis; | |
382 | } |
|
388 | } | |
383 | } |
|
389 | } | |
384 |
|
390 | |||
385 | return result; |
|
391 | return result; | |
386 | } |
|
392 | } | |
387 |
|
393 | |||
388 | /*! |
|
394 | /*! | |
389 | NOTICE: This function has to be called after series has been added to the chart if no customized axes are set to the chart. Otherwise axisX(), axisY() calls return NULL. |
|
395 | Creates axes for the chart based on the series that have already been added to the chart. Any axes previously added to | |
|
396 | the chart will be deleted. | |||
390 |
|
397 | |||
391 | Creates the axes for the chart based on the series that has already been added to the chart. |
|
398 | \note This function has to be called after all series have been added to the chart. The axes created by this function | |
|
399 | will NOT get automatically attached to any series added to the chart after this function has been called. | |||
|
400 | A series with no axes attached will by default scale to utilize the entire plot area of the chart, which can be confusing | |||
|
401 | if there are other series with properly attached axes also present. | |||
392 |
|
402 | |||
393 | \table |
|
403 | \table | |
394 | \header |
|
404 | \header | |
395 | \o Series type |
|
405 | \o Series type | |
396 | \o X-axis |
|
406 | \o X-axis | |
397 | \o Y-axis |
|
407 | \o Y-axis | |
398 | \row |
|
408 | \row | |
399 | \o QXYSeries |
|
409 | \o QXYSeries | |
400 | \o QValueAxis |
|
410 | \o QValueAxis | |
401 | \o QValueAxis |
|
411 | \o QValueAxis | |
402 | \row |
|
412 | \row | |
403 | \o QBarSeries |
|
413 | \o QBarSeries | |
404 | \o QBarCategoryAxis |
|
414 | \o QBarCategoryAxis | |
405 | \o QValueAxis |
|
415 | \o QValueAxis | |
406 | \row |
|
416 | \row | |
407 | \o QPieSeries |
|
417 | \o QPieSeries | |
408 | \o None |
|
418 | \o None | |
409 | \o None |
|
419 | \o None | |
410 |
|
|
420 | \endtable | |
411 |
|
421 | |||
412 |
If there are several QXYSeries derived series added to the chart and no |
|
422 | If there are several QXYSeries derived series added to the chart and no series of other types have been added, then only one pair of axes is created. | |
413 |
If there are sev |
|
423 | If there are several series of different types added to the chart, then each series gets its own axes pair. | |
414 |
|
424 | |||
415 | NOTICE: if there is more than one x and y axes created then no axis is drawn by default and one needs to choose explicitly which axis should be shown. |
|
425 | The axes specific to the series can be later obtained from the chart by providing the series as the parameter for axes() function call. | |
416 |
|
||||
417 | Axis specifix to the series can be later obtained from the chart by providing the series as the parameter of axisX(), axisY() function calls. |
|
|||
418 | QPieSeries does not create any axes. |
|
426 | QPieSeries does not create any axes. | |
419 |
|
427 | |||
420 | \sa axisX(), axisY(), setAxisX(), setAxisY() |
|
428 | \sa axisX(), axisY(), axes(), setAxisX(), setAxisY(), QAbstractSeries::attachAxis() | |
421 | */ |
|
429 | */ | |
422 | void QChart::createDefaultAxes() |
|
430 | void QChart::createDefaultAxes() | |
423 | { |
|
431 | { | |
424 | d_ptr->m_dataset->createDefaultAxes(); |
|
432 | d_ptr->m_dataset->createDefaultAxes(); | |
425 | } |
|
433 | } | |
426 |
|
434 | |||
427 | /*! |
|
435 | /*! | |
428 |
Returns the legend object of the chart. Ownership stays |
|
436 | Returns the legend object of the chart. Ownership stays with the chart. | |
429 | */ |
|
437 | */ | |
430 | QLegend *QChart::legend() const |
|
438 | QLegend *QChart::legend() const | |
431 | { |
|
439 | { | |
432 | return d_ptr->m_legend; |
|
440 | return d_ptr->m_legend; | |
433 | } |
|
441 | } | |
434 |
|
442 | |||
435 | /*! |
|
|||
436 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
|||
437 | Deprecated. Use setMargins(). |
|
|||
438 | */ |
|
|||
439 | void QChart::setMinimumMargins(const QMargins &margins) |
|
443 | void QChart::setMinimumMargins(const QMargins &margins) | |
440 | { |
|
444 | { | |
441 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; |
|
445 | qWarning() << "QChart::setMinimumMargins is deprecated. Use QChart::setMargins instead."; | |
442 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
446 | d_ptr->m_presenter->layout()->setMargins(margins); | |
443 | } |
|
447 | } | |
444 |
|
448 | |||
445 | /*! |
|
|||
446 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
|||
447 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
|||
448 | Deprecated. Use margins(). |
|
|||
449 | */ |
|
|||
450 | QMargins QChart::minimumMargins() const |
|
449 | QMargins QChart::minimumMargins() const | |
451 | { |
|
450 | { | |
452 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; |
|
451 | qWarning() << "QChart::minimumMargins is deprecated. Use QChart::margins instead."; | |
453 | return d_ptr->m_presenter->layout()->margins(); |
|
452 | return d_ptr->m_presenter->layout()->margins(); | |
454 | } |
|
453 | } | |
455 |
|
454 | |||
456 | /*! |
|
|||
457 | Sets the minimum \a margins between the plot area (axes) and the edge of the chart widget. |
|
|||
458 | */ |
|
|||
459 | void QChart::setMargins(const QMargins &margins) |
|
455 | void QChart::setMargins(const QMargins &margins) | |
460 | { |
|
456 | { | |
461 | d_ptr->m_presenter->layout()->setMargins(margins); |
|
457 | d_ptr->m_presenter->layout()->setMargins(margins); | |
462 | } |
|
458 | } | |
463 |
|
459 | |||
464 | /*! |
|
|||
465 | Returns the rect that contains information about margins (distance between chart widget edge and axes). |
|
|||
466 | Individual margins can be obtained by calling left, top, right, bottom on the returned rect. |
|
|||
467 | */ |
|
|||
468 | QMargins QChart::margins() const |
|
460 | QMargins QChart::margins() const | |
469 | { |
|
461 | { | |
470 | return d_ptr->m_presenter->layout()->margins(); |
|
462 | return d_ptr->m_presenter->layout()->margins(); | |
471 | } |
|
463 | } | |
472 |
|
464 | |||
473 | QChart::ChartType QChart::chartType() const |
|
465 | QChart::ChartType QChart::chartType() const | |
474 | { |
|
466 | { | |
475 | return d_ptr->m_type; |
|
467 | return d_ptr->m_type; | |
476 | } |
|
468 | } | |
477 |
|
469 | |||
478 | /*! |
|
470 | /*! | |
479 | Returns the the rect within which the drawing of the chart is done. |
|
471 | Returns the the rectangle within which the drawing of the chart is done. | |
480 |
It does not include the area define |
|
472 | It does not include the area defined by margins. | |
481 | */ |
|
473 | */ | |
482 | QRectF QChart::plotArea() const |
|
474 | QRectF QChart::plotArea() const | |
483 | { |
|
475 | { | |
484 | return d_ptr->m_presenter->geometry(); |
|
476 | return d_ptr->m_presenter->geometry(); | |
485 | } |
|
477 | } | |
486 |
|
478 | |||
487 | ///*! |
|
|||
488 | // TODO: Dummy. |
|
|||
489 | // Adjust the ranges of the axes so that all the data of the specified \a series is visible |
|
|||
490 | // */ |
|
|||
491 | //void QChart::adjustViewToSeries(QAbstractSeries* series) |
|
|||
492 | //{ |
|
|||
493 | // // |
|
|||
494 | //} |
|
|||
495 |
|
||||
496 | /*! |
|
|||
497 | Sets animation \a options for the chart |
|
|||
498 | */ |
|
|||
499 | void QChart::setAnimationOptions(AnimationOptions options) |
|
479 | void QChart::setAnimationOptions(AnimationOptions options) | |
500 | { |
|
480 | { | |
501 | d_ptr->m_presenter->setAnimationOptions(options); |
|
481 | d_ptr->m_presenter->setAnimationOptions(options); | |
502 | } |
|
482 | } | |
503 |
|
483 | |||
504 | QChart::AnimationOptions QChart::animationOptions() const |
|
484 | QChart::AnimationOptions QChart::animationOptions() const | |
505 | { |
|
485 | { | |
506 | return d_ptr->m_presenter->animationOptions(); |
|
486 | return d_ptr->m_presenter->animationOptions(); | |
507 | } |
|
487 | } | |
508 |
|
488 | |||
509 | /*! |
|
489 | /*! | |
510 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. |
|
490 | Scrolls the visible area of the chart by the distance defined in the \a dx and \a dy. | |
511 |
|
491 | |||
512 | For polar charts, \a dx indicates the angle along angular axis instead of distance. |
|
492 | For polar charts, \a dx indicates the angle along angular axis instead of distance. | |
513 | */ |
|
493 | */ | |
514 | void QChart::scroll(qreal dx, qreal dy) |
|
494 | void QChart::scroll(qreal dx, qreal dy) | |
515 | { |
|
495 | { | |
516 | d_ptr->scroll(dx,dy); |
|
496 | d_ptr->scroll(dx,dy); | |
517 | } |
|
497 | } | |
518 |
|
498 | |||
519 | void QChart::setBackgroundVisible(bool visible) |
|
499 | void QChart::setBackgroundVisible(bool visible) | |
520 | { |
|
500 | { | |
521 | d_ptr->m_presenter->setBackgroundVisible(visible); |
|
501 | d_ptr->m_presenter->setBackgroundVisible(visible); | |
522 | } |
|
502 | } | |
523 |
|
503 | |||
524 | bool QChart::isBackgroundVisible() const |
|
504 | bool QChart::isBackgroundVisible() const | |
525 | { |
|
505 | { | |
526 | return d_ptr->m_presenter->isBackgroundVisible(); |
|
506 | return d_ptr->m_presenter->isBackgroundVisible(); | |
527 | } |
|
507 | } | |
528 |
|
508 | |||
529 | void QChart::setDropShadowEnabled(bool enabled) |
|
509 | void QChart::setDropShadowEnabled(bool enabled) | |
530 | { |
|
510 | { | |
531 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); |
|
511 | d_ptr->m_presenter->setBackgroundDropShadowEnabled(enabled); | |
532 | } |
|
512 | } | |
533 |
|
513 | |||
534 | bool QChart::isDropShadowEnabled() const |
|
514 | bool QChart::isDropShadowEnabled() const | |
535 | { |
|
515 | { | |
536 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); |
|
516 | return d_ptr->m_presenter->isBackgroundDropShadowEnabled(); | |
537 | } |
|
517 | } | |
538 |
|
518 | |||
539 | /*! |
|
519 | /*! | |
540 |
Returns all |
|
520 | Returns all series that are added to the chart. | |
541 |
|
521 | |||
542 | \sa addSeries(), removeSeries(), removeAllSeries() |
|
522 | \sa addSeries(), removeSeries(), removeAllSeries() | |
543 | */ |
|
523 | */ | |
544 | QList<QAbstractSeries *> QChart::series() const |
|
524 | QList<QAbstractSeries *> QChart::series() const | |
545 | { |
|
525 | { | |
546 | return d_ptr->m_dataset->series(); |
|
526 | return d_ptr->m_dataset->series(); | |
547 | } |
|
527 | } | |
548 |
|
528 | |||
549 | /*! |
|
529 | /*! | |
550 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
530 | Adds the \a axis to the chart and attaches it to the \a series as a bottom-aligned horizontal axis. | |
|
531 | The chart takes ownership of both the \a axis and the \a series. | |||
|
532 | Any horizontal axes previously attached to the \a series are deleted. | |||
551 |
|
533 | |||
552 |
|
|
534 | \sa axisX(), axisY(), setAxisY(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
553 | */ |
|
535 | */ | |
554 |
void QChart::setAxisX(QAbstractAxis *axis , |
|
536 | void QChart::setAxisX(QAbstractAxis *axis ,QAbstractSeries *series) | |
555 | { |
|
537 | { | |
556 | QList<QAbstractAxis*> list = axes(Qt::Horizontal,series); |
|
538 | QList<QAbstractAxis*> list = axes(Qt::Horizontal, series); | |
557 |
|
539 | |||
558 | foreach(QAbstractAxis* a, list){ |
|
540 | foreach (QAbstractAxis* a, list) { | |
559 | d_ptr->m_dataset->removeAxis(a); |
|
541 | d_ptr->m_dataset->removeAxis(a); | |
560 | delete a; |
|
542 | delete a; | |
561 | } |
|
543 | } | |
562 |
|
544 | |||
563 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
545 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
564 | d_ptr->m_dataset->addAxis(axis,Qt::AlignBottom); |
|
546 | d_ptr->m_dataset->addAxis(axis, Qt::AlignBottom); | |
565 | d_ptr->m_dataset->attachAxis(series,axis); |
|
547 | d_ptr->m_dataset->attachAxis(series, axis); | |
566 | } |
|
548 | } | |
567 |
|
549 | |||
568 | /*! |
|
550 | /*! | |
569 | Sets \a axis to the chart, which will control the presentation of the \a series |
|
551 | Adds the \a axis to the chart and attaches it to the \a series as a left-aligned vertical axis. | |
|
552 | The chart takes ownership of both the \a axis and the \a series. | |||
|
553 | Any vertical axes previously attached to the \a series are deleted. | |||
570 |
|
554 | |||
571 |
|
|
555 | \sa axisX(), axisY(), setAxisX(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
572 | */ |
|
556 | */ | |
573 |
void QChart::setAxisY(QAbstractAxis *axis , |
|
557 | void QChart::setAxisY(QAbstractAxis *axis ,QAbstractSeries *series) | |
574 | { |
|
558 | { | |
575 | QList<QAbstractAxis*> list = axes(Qt::Vertical,series); |
|
559 | QList<QAbstractAxis*> list = axes(Qt::Vertical, series); | |
576 |
|
560 | |||
577 | foreach(QAbstractAxis* a, list) { |
|
561 | foreach (QAbstractAxis* a, list) { | |
578 | d_ptr->m_dataset->removeAxis(a); |
|
562 | d_ptr->m_dataset->removeAxis(a); | |
579 | delete a; |
|
563 | delete a; | |
580 | } |
|
564 | } | |
581 |
|
565 | |||
582 | if(!d_ptr->m_dataset->axes().contains(axis)) |
|
566 | if (!d_ptr->m_dataset->axes().contains(axis)) | |
583 | d_ptr->m_dataset->addAxis(axis,Qt::AlignLeft); |
|
567 | d_ptr->m_dataset->addAxis(axis, Qt::AlignLeft); | |
584 | d_ptr->m_dataset->attachAxis(series,axis); |
|
568 | d_ptr->m_dataset->attachAxis(series, axis); | |
585 | } |
|
569 | } | |
586 |
|
570 | |||
587 | /*! |
|
571 | /*! | |
588 | Adds \a axis to the chart with \a alignment. The chart takes the ownership of the axis. |
|
572 | Adds the \a axis to the chart with \a alignment. The chart takes the ownership of the axis. | |
|
573 | ||||
589 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() |
|
574 | \sa removeAxis(), createDefaultAxes(), QAbstractSeries::attachAxis() | |
590 | */ |
|
575 | */ | |
591 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) |
|
576 | void QChart::addAxis(QAbstractAxis *axis, Qt::Alignment alignment) | |
592 | { |
|
577 | { | |
593 | d_ptr->m_dataset->addAxis(axis, alignment); |
|
578 | d_ptr->m_dataset->addAxis(axis, alignment); | |
594 | } |
|
579 | } | |
595 |
|
580 | |||
596 | /*! |
|
581 | /*! | |
597 | Removes \a axis from the chart. The ownership is returned to the caller. |
|
582 | Removes the \a axis from the chart. | |
|
583 | The chart releases its ownership of the specified \a axis object. | |||
|
584 | ||||
598 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() |
|
585 | \sa addAxis(), createDefaultAxes(), QAbstractSeries::detachAxis() | |
599 | */ |
|
586 | */ | |
600 | void QChart::removeAxis(QAbstractAxis *axis) |
|
587 | void QChart::removeAxis(QAbstractAxis *axis) | |
601 | { |
|
588 | { | |
602 | d_ptr->m_dataset->removeAxis(axis); |
|
589 | d_ptr->m_dataset->removeAxis(axis); | |
603 | } |
|
590 | } | |
604 |
|
591 | |||
605 | /*! |
|
592 | /*! | |
606 |
Returns the value in the \a series domain that corresponds to the |
|
593 | Returns the value in the \a series domain that corresponds to the \a position relative to chart widget. | |
607 | */ |
|
594 | */ | |
608 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
595 | QPointF QChart::mapToValue(const QPointF &position, QAbstractSeries *series) | |
609 | { |
|
596 | { | |
610 | return d_ptr->m_dataset->mapToValue(position, series); |
|
597 | return d_ptr->m_dataset->mapToValue(position, series); | |
611 | } |
|
598 | } | |
612 |
|
599 | |||
613 | /*! |
|
600 | /*! | |
614 |
Returns the position on the chart |
|
601 | Returns the position on the chart widget that corresponds to the \a value in the \a series domain. | |
615 | */ |
|
602 | */ | |
616 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
603 | QPointF QChart::mapToPosition(const QPointF &value, QAbstractSeries *series) | |
617 | { |
|
604 | { | |
618 | return d_ptr->m_dataset->mapToPosition(value, series); |
|
605 | return d_ptr->m_dataset->mapToPosition(value, series); | |
619 | } |
|
606 | } | |
620 |
|
607 | |||
621 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
608 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
622 |
|
609 | |||
623 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): |
|
610 | QChartPrivate::QChartPrivate(QChart *q, QChart::ChartType type): | |
624 | q_ptr(q), |
|
611 | q_ptr(q), | |
625 | m_type(type), |
|
612 | m_type(type), | |
626 | m_legend(0), |
|
613 | m_legend(0), | |
627 | m_dataset(new ChartDataSet(q)), |
|
614 | m_dataset(new ChartDataSet(q)), | |
628 | m_presenter(new ChartPresenter(q, type)), |
|
615 | m_presenter(new ChartPresenter(q, type)), | |
629 | m_themeManager(new ChartThemeManager(q)) |
|
616 | m_themeManager(new ChartThemeManager(q)) | |
630 | { |
|
617 | { | |
631 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
618 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_presenter, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
632 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
619 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_presenter, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
633 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
620 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_presenter, SLOT(handleAxisAdded(QAbstractAxis*))); | |
634 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
621 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_presenter, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
635 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); |
|
622 | QObject::connect(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesAdded(QAbstractSeries*))); | |
636 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); |
|
623 | QObject::connect(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)), m_themeManager, SLOT(handleSeriesRemoved(QAbstractSeries*))); | |
637 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); |
|
624 | QObject::connect(m_dataset, SIGNAL(axisAdded(QAbstractAxis*)), m_themeManager, SLOT(handleAxisAdded(QAbstractAxis*))); | |
638 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); |
|
625 | QObject::connect(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)), m_themeManager, SLOT(handleAxisRemoved(QAbstractAxis*))); | |
639 | } |
|
626 | } | |
640 |
|
627 | |||
641 | QChartPrivate::~QChartPrivate() |
|
628 | QChartPrivate::~QChartPrivate() | |
642 | { |
|
629 | { | |
643 |
|
||||
644 | } |
|
630 | } | |
645 |
|
631 | |||
646 | void QChartPrivate::init() |
|
632 | void QChartPrivate::init() | |
647 | { |
|
633 | { | |
648 | m_legend = new LegendScroller(q_ptr); |
|
634 | m_legend = new LegendScroller(q_ptr); | |
649 | q_ptr->setTheme(QChart::ChartThemeLight); |
|
635 | q_ptr->setTheme(QChart::ChartThemeLight); | |
650 | q_ptr->setLayout(m_presenter->layout()); |
|
636 | q_ptr->setLayout(m_presenter->layout()); | |
651 | } |
|
637 | } | |
652 |
|
638 | |||
653 | void QChartPrivate::zoomIn(qreal factor) |
|
639 | void QChartPrivate::zoomIn(qreal factor) | |
654 | { |
|
640 | { | |
655 | QRectF rect = m_presenter->geometry(); |
|
641 | QRectF rect = m_presenter->geometry(); | |
656 | rect.setWidth(rect.width() / factor); |
|
642 | rect.setWidth(rect.width() / factor); | |
657 | rect.setHeight(rect.height() / factor); |
|
643 | rect.setHeight(rect.height() / factor); | |
658 | rect.moveCenter(m_presenter->geometry().center()); |
|
644 | rect.moveCenter(m_presenter->geometry().center()); | |
659 | zoomIn(rect); |
|
645 | zoomIn(rect); | |
660 | } |
|
646 | } | |
661 |
|
647 | |||
662 | void QChartPrivate::zoomIn(const QRectF &rect) |
|
648 | void QChartPrivate::zoomIn(const QRectF &rect) | |
663 | { |
|
649 | { | |
664 | if (!rect.isValid()) |
|
650 | if (!rect.isValid()) | |
665 | return; |
|
651 | return; | |
666 |
|
652 | |||
667 | QRectF r = rect.normalized(); |
|
653 | QRectF r = rect.normalized(); | |
668 | const QRectF geometry = m_presenter->geometry(); |
|
654 | const QRectF geometry = m_presenter->geometry(); | |
669 | r.translate(-geometry.topLeft()); |
|
655 | r.translate(-geometry.topLeft()); | |
670 |
|
656 | |||
671 | if (!r.isValid()) |
|
657 | if (!r.isValid()) | |
672 | return; |
|
658 | return; | |
673 |
|
659 | |||
674 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
660 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
675 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); |
|
661 | m_presenter->setState(ChartPresenter::ZoomInState,zoomPoint); | |
676 | m_dataset->zoomInDomain(r); |
|
662 | m_dataset->zoomInDomain(r); | |
677 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
663 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
678 |
|
664 | |||
679 | } |
|
665 | } | |
680 |
|
666 | |||
681 | void QChartPrivate::zoomOut(qreal factor) |
|
667 | void QChartPrivate::zoomOut(qreal factor) | |
682 | { |
|
668 | { | |
683 | const QRectF geometry = m_presenter->geometry(); |
|
669 | const QRectF geometry = m_presenter->geometry(); | |
684 |
|
670 | |||
685 | QRectF r; |
|
671 | QRectF r; | |
686 | r.setSize(geometry.size() / factor); |
|
672 | r.setSize(geometry.size() / factor); | |
687 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); |
|
673 | r.moveCenter(QPointF(geometry.size().width()/2 ,geometry.size().height()/2)); | |
688 | if (!r.isValid()) |
|
674 | if (!r.isValid()) | |
689 | return; |
|
675 | return; | |
690 |
|
676 | |||
691 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); |
|
677 | QPointF zoomPoint(r.center().x() / geometry.width(), r.center().y() / geometry.height()); | |
692 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); |
|
678 | m_presenter->setState(ChartPresenter::ZoomOutState,zoomPoint); | |
693 | m_dataset->zoomOutDomain(r); |
|
679 | m_dataset->zoomOutDomain(r); | |
694 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
680 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
695 | } |
|
681 | } | |
696 |
|
682 | |||
697 | void QChartPrivate::scroll(qreal dx, qreal dy) |
|
683 | void QChartPrivate::scroll(qreal dx, qreal dy) | |
698 | { |
|
684 | { | |
699 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); |
|
685 | if (dx < 0) m_presenter->setState(ChartPresenter::ScrollLeftState,QPointF()); | |
700 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); |
|
686 | if (dx > 0) m_presenter->setState(ChartPresenter::ScrollRightState,QPointF()); | |
701 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); |
|
687 | if (dy < 0) m_presenter->setState(ChartPresenter::ScrollUpState,QPointF()); | |
702 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); |
|
688 | if (dy > 0) m_presenter->setState(ChartPresenter::ScrollDownState,QPointF()); | |
703 |
|
689 | |||
704 | m_dataset->scrollDomain(dx, dy); |
|
690 | m_dataset->scrollDomain(dx, dy); | |
705 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); |
|
691 | m_presenter->setState(ChartPresenter::ShowState,QPointF()); | |
706 | } |
|
692 | } | |
707 |
|
693 | |||
708 | #include "moc_qchart.cpp" |
|
694 | #include "moc_qchart.cpp" | |
709 |
|
695 | |||
710 | QTCOMMERCIALCHART_END_NAMESPACE |
|
696 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,266 +1,269 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qchartview.h" |
|
21 | #include "qchartview.h" | |
22 | #include "qchartview_p.h" |
|
22 | #include "qchartview_p.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include <QGraphicsScene> |
|
24 | #include <QGraphicsScene> | |
25 | #include <QRubberBand> |
|
25 | #include <QRubberBand> | |
26 |
|
26 | |||
27 | /*! |
|
27 | /*! | |
28 | \enum QChartView::RubberBand |
|
28 | \enum QChartView::RubberBand | |
29 |
|
29 | |||
30 | This enum describes the different types of rubber bands that can be used for zoom rect selection |
|
30 | This enum describes the different types of rubber bands that can be used for zoom rect selection | |
31 |
|
31 | |||
32 | \value NoRubberBand |
|
32 | \value NoRubberBand | |
33 | \value VerticalRubberBand |
|
33 | \value VerticalRubberBand | |
34 | \value HorizonalRubberBand |
|
34 | \value HorizonalRubberBand | |
35 | \value RectangleRubberBand |
|
35 | \value RectangleRubberBand | |
36 | */ |
|
36 | */ | |
37 |
|
37 | |||
38 | /*! |
|
38 | /*! | |
39 | \class QChartView |
|
39 | \class QChartView | |
40 | \brief Standalone charting widget. |
|
40 | \brief Standalone charting widget. | |
41 |
|
41 | |||
42 | QChartView is a standalone widget that can display charts. It does not require separate |
|
42 | QChartView is a standalone widget that can display charts. It does not require separate | |
43 | QGraphicsScene to work. It manages the graphical representation of different types of |
|
43 | QGraphicsScene to work. If you want to display a chart in your existing QGraphicsScene, | |
44 | series and other chart related objects like QAxis and QLegend. If you want to |
|
44 | you need to use the QChart (or QPolarChart) class instead. | |
45 | display a chart in your existing QGraphicsScene, you can use the QChart class instead. |
|
|||
46 |
|
45 | |||
47 | \sa QChart |
|
46 | \sa QChart, QPolarChart | |
48 | */ |
|
47 | */ | |
49 |
|
48 | |||
50 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
49 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
51 |
|
50 | |||
52 | /*! |
|
51 | /*! | |
53 | Constructs a chartView object with parent \a parent. |
|
52 | Constructs a chartView object with parent \a parent. | |
54 | */ |
|
53 | */ | |
55 |
|
54 | |||
56 | QChartView::QChartView(QWidget *parent) |
|
55 | QChartView::QChartView(QWidget *parent) | |
57 | : QGraphicsView(parent), |
|
56 | : QGraphicsView(parent), | |
58 | d_ptr(new QChartViewPrivate(this)) |
|
57 | d_ptr(new QChartViewPrivate(this)) | |
59 | { |
|
58 | { | |
60 |
|
59 | |||
61 | } |
|
60 | } | |
62 |
|
61 | |||
63 | /*! |
|
62 | /*! | |
64 |
Constructs a chart |
|
63 | Constructs a chartview object with parent \a parent to display a \a chart. | |
|
64 | Ownership of the \a chart is passed to chartview. | |||
65 | */ |
|
65 | */ | |
66 |
|
66 | |||
67 | QChartView::QChartView(QChart *chart, QWidget *parent) |
|
67 | QChartView::QChartView(QChart *chart, QWidget *parent) | |
68 | : QGraphicsView(parent), |
|
68 | : QGraphicsView(parent), | |
69 | d_ptr(new QChartViewPrivate(this, chart)) |
|
69 | d_ptr(new QChartViewPrivate(this, chart)) | |
70 | { |
|
70 | { | |
71 |
|
71 | |||
72 | } |
|
72 | } | |
73 |
|
73 | |||
74 |
|
74 | |||
75 | /*! |
|
75 | /*! | |
76 | Destroys the object and it's children, like series and axis objects added to it. |
|
76 | Destroys the chartview object and the associated chart. | |
77 | */ |
|
77 | */ | |
78 | QChartView::~QChartView() |
|
78 | QChartView::~QChartView() | |
79 | { |
|
79 | { | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | /*! |
|
82 | /*! | |
83 | Returns the pointer to the associated chart |
|
83 | Returns the pointer to the associated chart. | |
84 | */ |
|
84 | */ | |
85 | QChart *QChartView::chart() const |
|
85 | QChart *QChartView::chart() const | |
86 | { |
|
86 | { | |
87 | return d_ptr->m_chart; |
|
87 | return d_ptr->m_chart; | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | /*! |
|
90 | /*! | |
91 | Sets the current chart to \a chart. Ownership of the new chart is passed to chartview |
|
91 | Sets the current chart to \a chart. Ownership of the new chart is passed to chartview | |
92 | and ownership of the previous chart is released. |
|
92 | and ownership of the previous chart is released. | |
93 |
|
93 | |||
94 |
To avoid memory leaks users need |
|
94 | To avoid memory leaks users need to make sure the previous chart is deleted. | |
95 | */ |
|
95 | */ | |
96 |
|
96 | |||
97 | void QChartView::setChart(QChart *chart) |
|
97 | void QChartView::setChart(QChart *chart) | |
98 | { |
|
98 | { | |
99 | d_ptr->setChart(chart); |
|
99 | d_ptr->setChart(chart); | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | /*! |
|
102 | /*! | |
103 | Sets the RubberBandPlicy to \a rubberBand. Selected policy determines the way zooming is performed. |
|
103 | Sets the rubber band flags to \a rubberBand. | |
|
104 | Selected flags determine the way zooming is performed. | |||
|
105 | ||||
|
106 | \note Rubber band zooming is not supported for polar charts. | |||
104 | */ |
|
107 | */ | |
105 | void QChartView::setRubberBand(const RubberBands &rubberBand) |
|
108 | void QChartView::setRubberBand(const RubberBands &rubberBand) | |
106 | { |
|
109 | { | |
107 | d_ptr->m_rubberBandFlags = rubberBand; |
|
110 | d_ptr->m_rubberBandFlags = rubberBand; | |
108 |
|
111 | |||
109 | if (!d_ptr->m_rubberBandFlags) { |
|
112 | if (!d_ptr->m_rubberBandFlags) { | |
110 | delete d_ptr->m_rubberBand; |
|
113 | delete d_ptr->m_rubberBand; | |
111 | d_ptr->m_rubberBand = 0; |
|
114 | d_ptr->m_rubberBand = 0; | |
112 | return; |
|
115 | return; | |
113 | } |
|
116 | } | |
114 |
|
117 | |||
115 | if (!d_ptr->m_rubberBand) { |
|
118 | if (!d_ptr->m_rubberBand) { | |
116 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); |
|
119 | d_ptr->m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this); | |
117 | d_ptr->m_rubberBand->setEnabled(true); |
|
120 | d_ptr->m_rubberBand->setEnabled(true); | |
118 | } |
|
121 | } | |
119 | } |
|
122 | } | |
120 |
|
123 | |||
121 | /*! |
|
124 | /*! | |
122 |
Returns the |
|
125 | Returns the rubber band flags that are currently being used by the widget. | |
123 | */ |
|
126 | */ | |
124 | QChartView::RubberBands QChartView::rubberBand() const |
|
127 | QChartView::RubberBands QChartView::rubberBand() const | |
125 | { |
|
128 | { | |
126 | return d_ptr->m_rubberBandFlags; |
|
129 | return d_ptr->m_rubberBandFlags; | |
127 | } |
|
130 | } | |
128 |
|
131 | |||
129 | /*! |
|
132 | /*! | |
130 |
If Left mouse button is pressed and the |
|
133 | If Left mouse button is pressed and the rubber band is enabled the \a event is accepted and the rubber band is displayed on the screen allowing the user to select the zoom area. | |
131 |
If different mouse button is pressed and/or the |
|
134 | If different mouse button is pressed and/or the rubber band is disabled then the \a event is passed to QGraphicsView::mousePressEvent() implementation. | |
132 | */ |
|
135 | */ | |
133 | void QChartView::mousePressEvent(QMouseEvent *event) |
|
136 | void QChartView::mousePressEvent(QMouseEvent *event) | |
134 | { |
|
137 | { | |
135 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { |
|
138 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) { | |
136 |
|
139 | |||
137 | QRectF plotArea = d_ptr->m_chart->plotArea(); |
|
140 | QRectF plotArea = d_ptr->m_chart->plotArea(); | |
138 |
|
141 | |||
139 | if (plotArea.contains(event->pos())) { |
|
142 | if (plotArea.contains(event->pos())) { | |
140 | d_ptr->m_rubberBandOrigin = event->pos(); |
|
143 | d_ptr->m_rubberBandOrigin = event->pos(); | |
141 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); |
|
144 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin, QSize())); | |
142 | d_ptr->m_rubberBand->show(); |
|
145 | d_ptr->m_rubberBand->show(); | |
143 | event->accept(); |
|
146 | event->accept(); | |
144 | } |
|
147 | } | |
145 | } else { |
|
148 | } else { | |
146 | QGraphicsView::mousePressEvent(event); |
|
149 | QGraphicsView::mousePressEvent(event); | |
147 | } |
|
150 | } | |
148 | } |
|
151 | } | |
149 |
|
152 | |||
150 | /*! |
|
153 | /*! | |
151 |
If |
|
154 | If the rubber band rectange has been displayed in pressEvent then \a event data is used to update the rubber band geometry. | |
152 |
|
|
155 | Otherwise the default QGraphicsView::mouseMoveEvent implementation is called. | |
153 | */ |
|
156 | */ | |
154 | void QChartView::mouseMoveEvent(QMouseEvent *event) |
|
157 | void QChartView::mouseMoveEvent(QMouseEvent *event) | |
155 | { |
|
158 | { | |
156 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { |
|
159 | if (d_ptr->m_rubberBand && d_ptr->m_rubberBand->isVisible()) { | |
157 | QRect rect = d_ptr->m_chart->plotArea().toRect(); |
|
160 | QRect rect = d_ptr->m_chart->plotArea().toRect(); | |
158 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); |
|
161 | int width = event->pos().x() - d_ptr->m_rubberBandOrigin.x(); | |
159 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); |
|
162 | int height = event->pos().y() - d_ptr->m_rubberBandOrigin.y(); | |
160 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { |
|
163 | if (!d_ptr->m_rubberBandFlags.testFlag(VerticalRubberBand)) { | |
161 | d_ptr->m_rubberBandOrigin.setY(rect.top()); |
|
164 | d_ptr->m_rubberBandOrigin.setY(rect.top()); | |
162 | height = rect.height(); |
|
165 | height = rect.height(); | |
163 | } |
|
166 | } | |
164 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { |
|
167 | if (!d_ptr->m_rubberBandFlags.testFlag(HorizonalRubberBand)) { | |
165 | d_ptr->m_rubberBandOrigin.setX(rect.left()); |
|
168 | d_ptr->m_rubberBandOrigin.setX(rect.left()); | |
166 | width = rect.width(); |
|
169 | width = rect.width(); | |
167 | } |
|
170 | } | |
168 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(), d_ptr->m_rubberBandOrigin.y(), width, height).normalized()); |
|
171 | d_ptr->m_rubberBand->setGeometry(QRect(d_ptr->m_rubberBandOrigin.x(), d_ptr->m_rubberBandOrigin.y(), width, height).normalized()); | |
169 | } else { |
|
172 | } else { | |
170 | QGraphicsView::mouseMoveEvent(event); |
|
173 | QGraphicsView::mouseMoveEvent(event); | |
171 | } |
|
174 | } | |
172 | } |
|
175 | } | |
173 |
|
176 | |||
174 | /*! |
|
177 | /*! | |
175 |
If left mouse button is release |
|
178 | If left mouse button is released and the rubber band is enabled then \a event is accepted and | |
176 | If it is the right mouse button \a event then RubberBand is dissmissed and zoom is canceled. |
|
179 | the view is zoomed into the rect specified by the rubber band. | |
|
180 | If it is a right mouse button \a event then the rubber band is dismissed and the zoom is canceled. | |||
177 | */ |
|
181 | */ | |
178 | void QChartView::mouseReleaseEvent(QMouseEvent *event) |
|
182 | void QChartView::mouseReleaseEvent(QMouseEvent *event) | |
179 | { |
|
183 | { | |
180 | if (d_ptr->m_rubberBand) { |
|
184 | if (d_ptr->m_rubberBand) { | |
181 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { |
|
185 | if (event->button() == Qt::LeftButton && d_ptr->m_rubberBand->isVisible()) { | |
182 | d_ptr->m_rubberBand->hide(); |
|
186 | d_ptr->m_rubberBand->hide(); | |
183 | QRectF rect = d_ptr->m_rubberBand->geometry(); |
|
187 | QRectF rect = d_ptr->m_rubberBand->geometry(); | |
184 | // Since plotArea uses QRectF and rubberband uses QRect, we can't just blindly use |
|
188 | // Since plotArea uses QRectF and rubberband uses QRect, we can't just blindly use | |
185 | // rubberband's dimensions for vertical and horizontal rubberbands, where one |
|
189 | // rubberband's dimensions for vertical and horizontal rubberbands, where one | |
186 | // dimension must match the corresponding plotArea dimension exactly. |
|
190 | // dimension must match the corresponding plotArea dimension exactly. | |
187 | if (d_ptr->m_rubberBandFlags == VerticalRubberBand) { |
|
191 | if (d_ptr->m_rubberBandFlags == VerticalRubberBand) { | |
188 | rect.setX(d_ptr->m_chart->plotArea().x()); |
|
192 | rect.setX(d_ptr->m_chart->plotArea().x()); | |
189 | rect.setWidth(d_ptr->m_chart->plotArea().width()); |
|
193 | rect.setWidth(d_ptr->m_chart->plotArea().width()); | |
190 | } else if (d_ptr->m_rubberBandFlags == HorizonalRubberBand) { |
|
194 | } else if (d_ptr->m_rubberBandFlags == HorizonalRubberBand) { | |
191 | rect.setY(d_ptr->m_chart->plotArea().y()); |
|
195 | rect.setY(d_ptr->m_chart->plotArea().y()); | |
192 | rect.setHeight(d_ptr->m_chart->plotArea().height()); |
|
196 | rect.setHeight(d_ptr->m_chart->plotArea().height()); | |
193 | } |
|
197 | } | |
194 | d_ptr->m_chart->zoomIn(rect); |
|
198 | d_ptr->m_chart->zoomIn(rect); | |
195 | event->accept(); |
|
199 | event->accept(); | |
196 | } |
|
200 | } | |
197 |
|
201 | |||
198 | if (event->button() == Qt::RightButton) { |
|
202 | if (event->button() == Qt::RightButton) { | |
199 | d_ptr->m_chart->zoomOut(); |
|
203 | d_ptr->m_chart->zoomOut(); | |
200 | event->accept(); |
|
204 | event->accept(); | |
201 | } |
|
205 | } | |
202 | } else { |
|
206 | } else { | |
203 | QGraphicsView::mouseReleaseEvent(event); |
|
207 | QGraphicsView::mouseReleaseEvent(event); | |
204 | } |
|
208 | } | |
205 | } |
|
209 | } | |
206 |
|
210 | |||
207 | /*! |
|
211 | /*! | |
208 | Resizes and updates the chart area using the \a event data |
|
212 | Resizes and updates the chart area using the \a event data | |
209 | */ |
|
213 | */ | |
210 | void QChartView::resizeEvent(QResizeEvent *event) |
|
214 | void QChartView::resizeEvent(QResizeEvent *event) | |
211 | { |
|
215 | { | |
212 | QGraphicsView::resizeEvent(event); |
|
216 | QGraphicsView::resizeEvent(event); | |
213 | d_ptr->resize(); |
|
217 | d_ptr->resize(); | |
214 | } |
|
218 | } | |
215 |
|
219 | |||
216 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
220 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
217 |
|
221 | |||
218 | QChartViewPrivate::QChartViewPrivate(QChartView *q, QChart *chart) |
|
222 | QChartViewPrivate::QChartViewPrivate(QChartView *q, QChart *chart) | |
219 | : q_ptr(q), |
|
223 | : q_ptr(q), | |
220 | m_scene(new QGraphicsScene(q)), |
|
224 | m_scene(new QGraphicsScene(q)), | |
221 | m_chart(chart), |
|
225 | m_chart(chart), | |
222 | m_rubberBand(0), |
|
226 | m_rubberBand(0), | |
223 | m_rubberBandFlags(QChartView::NoRubberBand) |
|
227 | m_rubberBandFlags(QChartView::NoRubberBand) | |
224 | { |
|
228 | { | |
225 | q_ptr->setFrameShape(QFrame::NoFrame); |
|
229 | q_ptr->setFrameShape(QFrame::NoFrame); | |
226 | q_ptr->setBackgroundRole(QPalette::Window); |
|
230 | q_ptr->setBackgroundRole(QPalette::Window); | |
227 | q_ptr->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
231 | q_ptr->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
228 | q_ptr->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
232 | q_ptr->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); | |
229 | q_ptr->setScene(m_scene); |
|
233 | q_ptr->setScene(m_scene); | |
230 | q_ptr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
234 | q_ptr->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); | |
231 | if (!m_chart) |
|
235 | if (!m_chart) | |
232 | m_chart = new QChart(); |
|
236 | m_chart = new QChart(); | |
233 | m_scene->addItem(m_chart); |
|
237 | m_scene->addItem(m_chart); | |
234 | } |
|
238 | } | |
235 |
|
239 | |||
236 | QChartViewPrivate::~QChartViewPrivate() |
|
240 | QChartViewPrivate::~QChartViewPrivate() | |
237 | { |
|
241 | { | |
238 |
|
||||
239 | } |
|
242 | } | |
240 |
|
243 | |||
241 | void QChartViewPrivate::setChart(QChart *chart) |
|
244 | void QChartViewPrivate::setChart(QChart *chart) | |
242 | { |
|
245 | { | |
243 | Q_ASSERT(chart); |
|
246 | Q_ASSERT(chart); | |
244 |
|
247 | |||
245 | if (m_chart == chart) |
|
248 | if (m_chart == chart) | |
246 | return; |
|
249 | return; | |
247 |
|
250 | |||
248 | if (m_chart) |
|
251 | if (m_chart) | |
249 | m_scene->removeItem(m_chart); |
|
252 | m_scene->removeItem(m_chart); | |
250 |
|
253 | |||
251 | m_chart = chart; |
|
254 | m_chart = chart; | |
252 | m_scene->addItem(m_chart); |
|
255 | m_scene->addItem(m_chart); | |
253 |
|
256 | |||
254 | resize(); |
|
257 | resize(); | |
255 | } |
|
258 | } | |
256 |
|
259 | |||
257 | void QChartViewPrivate::resize() |
|
260 | void QChartViewPrivate::resize() | |
258 | { |
|
261 | { | |
259 | m_chart->resize(q_ptr->size()); |
|
262 | m_chart->resize(q_ptr->size()); | |
260 | q_ptr->setMinimumSize(m_chart->minimumSize().toSize()); |
|
263 | q_ptr->setMinimumSize(m_chart->minimumSize().toSize()); | |
261 | q_ptr->setSceneRect(m_chart->geometry()); |
|
264 | q_ptr->setSceneRect(m_chart->geometry()); | |
262 | } |
|
265 | } | |
263 |
|
266 | |||
264 | #include "moc_qchartview.cpp" |
|
267 | #include "moc_qchartview.cpp" | |
265 |
|
268 | |||
266 | QTCOMMERCIALCHART_END_NAMESPACE |
|
269 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,126 +1,129 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qpolarchart.h" |
|
21 | #include "qpolarchart.h" | |
22 | #include "qabstractaxis.h" |
|
22 | #include "qabstractaxis.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \enum QPolarChart::PolarOrientation |
|
27 | \enum QPolarChart::PolarOrientation | |
28 |
|
28 | |||
29 |
This type is used to s |
|
29 | This type is used to specify the polar orientation of an axis. | |
30 |
|
30 | |||
31 | \value PolarOrientationRadial |
|
31 | \value PolarOrientationRadial | |
32 | \value PolarOrientationAngular |
|
32 | \value PolarOrientationAngular | |
33 | */ |
|
33 | */ | |
34 |
|
34 | |||
35 | /*! |
|
35 | /*! | |
36 | \class QPolarChart |
|
36 | \class QPolarChart | |
37 | \brief QtCommercial chart API. |
|
37 | \brief QtCommercial chart API. | |
38 |
|
38 | |||
39 | QPolarChart is a specialization of QChart to show a polar chart. |
|
39 | QPolarChart is a specialization of QChart to show a polar chart. | |
40 |
|
40 | |||
41 | Polar charts support line, spline, area, and scatter series, and all axis types |
|
41 | Polar charts support line, spline, area, and scatter series, and all axis types | |
42 | supported by those series. |
|
42 | supported by those series. | |
43 |
|
43 | |||
44 | \note When setting ticks to an angular QValueAxis, keep in mind that the first and last tick |
|
44 | \note When setting ticks to an angular QValueAxis, keep in mind that the first and last tick | |
45 | are co-located at 0/360 degree angle. |
|
45 | are co-located at 0/360 degree angle. | |
46 |
|
46 | |||
47 | \note If the angular distance between two consecutive points in a series is more than 180 degrees, |
|
47 | \note If the angular distance between two consecutive points in a series is more than 180 degrees, | |
48 | any line connecting the two points becomes meaningless, so choose the axis ranges accordingly |
|
48 | any line connecting the two points becomes meaningless, so choose the axis ranges accordingly | |
49 | when displaying line, spline, or area series. |
|
49 | when displaying line, spline, or area series. In such case series don't draw a direct line between | |
|
50 | the two points, but instead draw a line to and from the center of the chart. | |||
50 |
|
51 | |||
51 | \note Polar charts do not support multiple axes of same orientation. |
|
52 | \note Polar charts do not support multiple axes of same orientation. | |
52 |
|
53 | |||
53 | \sa QChart |
|
54 | \sa QChart | |
54 | */ |
|
55 | */ | |
55 |
|
56 | |||
56 | /*! |
|
57 | /*! | |
57 |
Constructs a polar chart as a child of |
|
58 | Constructs a polar chart as a child of the \a parent. | |
58 | Parameter \a wFlags is passed to the QChart constructor. |
|
59 | Parameter \a wFlags is passed to the QChart constructor. | |
59 | */ |
|
60 | */ | |
60 | QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
61 | QPolarChart::QPolarChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
61 | : QChart(QChart::ChartTypePolar, parent, wFlags) |
|
62 | : QChart(QChart::ChartTypePolar, parent, wFlags) | |
62 | { |
|
63 | { | |
63 | } |
|
64 | } | |
64 |
|
65 | |||
65 | /*! |
|
66 | /*! | |
66 |
Destroys the object and it |
|
67 | Destroys the polar chart object and its children, like series and axis objects added to it. | |
67 | */ |
|
68 | */ | |
68 | QPolarChart::~QPolarChart() |
|
69 | QPolarChart::~QPolarChart() | |
69 | { |
|
70 | { | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | /*! |
|
73 | /*! | |
73 | Returns the axes added for the \a series with \a polarOrientation. If no series is provided, then any axis with the |
|
74 | Returns the axes added for the \a series with \a polarOrientation. If no series is provided, then any axis with the | |
74 | specified polar orientation is returned. |
|
75 | specified polar orientation is returned. | |
|
76 | ||||
75 | \sa addAxis() |
|
77 | \sa addAxis() | |
76 | */ |
|
78 | */ | |
77 | QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const |
|
79 | QList<QAbstractAxis *> QPolarChart::axes(PolarOrientations polarOrientation, QAbstractSeries *series) const | |
78 | { |
|
80 | { | |
79 | Qt::Orientations orientation(0); |
|
81 | Qt::Orientations orientation(0); | |
80 | if (polarOrientation.testFlag(PolarOrientationAngular)) |
|
82 | if (polarOrientation.testFlag(PolarOrientationAngular)) | |
81 | orientation |= Qt::Horizontal; |
|
83 | orientation |= Qt::Horizontal; | |
82 | if (polarOrientation.testFlag(PolarOrientationRadial)) |
|
84 | if (polarOrientation.testFlag(PolarOrientationRadial)) | |
83 | orientation |= Qt::Vertical; |
|
85 | orientation |= Qt::Vertical; | |
84 |
|
86 | |||
85 | return QChart::axes(orientation, series); |
|
87 | return QChart::axes(orientation, series); | |
86 | } |
|
88 | } | |
87 |
|
89 | |||
88 | /*! |
|
90 | /*! | |
89 | This convenience method adds \a axis to the polar chart with \a polarOrientation. |
|
91 | This convenience method adds \a axis to the polar chart with \a polarOrientation. | |
90 | The chart takes the ownership of the axis. |
|
92 | The chart takes the ownership of the axis. | |
91 |
|
93 | |||
92 | \note Axes can be added to a polar chart also with QChart::addAxis() instead of this method. |
|
94 | \note Axes can be added to a polar chart also with QChart::addAxis() instead of this method. | |
93 | The specified alignment determines the polar orientation: horizontal alignments indicate angular |
|
95 | The specified alignment determines the polar orientation: horizontal alignments indicate angular | |
94 | axis and vertical alignments indicate radial axis. |
|
96 | axis and vertical alignments indicate radial axis. | |
|
97 | ||||
95 | \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis() |
|
98 | \sa QChart::removeAxis(), QChart::createDefaultAxes(), QAbstractSeries::attachAxis(), QChart::addAxis() | |
96 | */ |
|
99 | */ | |
97 | void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation) |
|
100 | void QPolarChart::addAxis(QAbstractAxis *axis, PolarOrientation polarOrientation) | |
98 | { |
|
101 | { | |
99 | if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
102 | if (!axis || axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
100 | qWarning("QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts."); |
|
103 | qWarning("QAbstractAxis::AxisTypeBarCategory is not a supported axis type for polar charts."); | |
101 | } else { |
|
104 | } else { | |
102 | Qt::Alignment alignment = Qt::AlignLeft; |
|
105 | Qt::Alignment alignment = Qt::AlignLeft; | |
103 | if (polarOrientation == PolarOrientationAngular) |
|
106 | if (polarOrientation == PolarOrientationAngular) | |
104 | alignment = Qt::AlignBottom; |
|
107 | alignment = Qt::AlignBottom; | |
105 | QChart::addAxis(axis, alignment); |
|
108 | QChart::addAxis(axis, alignment); | |
106 | } |
|
109 | } | |
107 | } |
|
110 | } | |
108 |
|
111 | |||
109 | /*! |
|
112 | /*! | |
110 | Angular axes of a polar chart report horizontal orientation and radial axes report |
|
113 | Angular axes of a polar chart report horizontal orientation and radial axes report | |
111 | vertical orientation. |
|
114 | vertical orientation. | |
112 | This function is a convenience function for converting the orientation of an \a axis to |
|
115 | This function is a convenience function for converting the orientation of an \a axis to | |
113 | corresponding polar orientation. If the \a axis is NULL or not added to a polar chart, |
|
116 | corresponding polar orientation. If the \a axis is NULL or not added to a polar chart, | |
114 | the return value is meaningless. |
|
117 | the return value is meaningless. | |
115 | */ |
|
118 | */ | |
116 | QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis) |
|
119 | QPolarChart::PolarOrientation QPolarChart::axisPolarOrientation(QAbstractAxis *axis) | |
117 | { |
|
120 | { | |
118 | if (axis && axis->orientation() == Qt::Horizontal) |
|
121 | if (axis && axis->orientation() == Qt::Horizontal) | |
119 | return PolarOrientationAngular; |
|
122 | return PolarOrientationAngular; | |
120 | else |
|
123 | else | |
121 | return PolarOrientationRadial; |
|
124 | return PolarOrientationRadial; | |
122 | } |
|
125 | } | |
123 |
|
126 | |||
124 | #include "moc_qpolarchart.cpp" |
|
127 | #include "moc_qpolarchart.cpp" | |
125 |
|
128 | |||
126 | QTCOMMERCIALCHART_END_NAMESPACE |
|
129 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,152 +1,152 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qsplineseries.h" |
|
21 | #include "qsplineseries.h" | |
22 | #include "qsplineseries_p.h" |
|
22 | #include "qsplineseries_p.h" | |
23 | #include "splinechartitem_p.h" |
|
23 | #include "splinechartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "splineanimation_p.h" |
|
26 | #include "splineanimation_p.h" | |
27 |
|
27 | |||
28 | /*! |
|
28 | /*! | |
29 | \class QSplineSeries |
|
29 | \class QSplineSeries | |
30 | \brief Series type used to store data needed to draw a spline. |
|
30 | \brief Series type used to store data needed to draw a spline. | |
31 |
|
31 | |||
32 | QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline |
|
32 | QSplineSeries stores the data points along with the segment control points needed by QPainterPath to draw spline | |
33 | Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn. |
|
33 | Control points are automatically calculated when data changes. The algorithm computes the points so that the normal spline can be drawn. | |
34 |
|
34 | |||
35 | \image examples_splinechart.png |
|
35 | \image examples_splinechart.png | |
36 |
|
36 | |||
37 | Creating basic spline chart is simple: |
|
37 | Creating basic spline chart is simple: | |
38 | \code |
|
38 | \code | |
39 | QSplineSeries* series = new QSplineSeries(); |
|
39 | QSplineSeries* series = new QSplineSeries(); | |
40 | series->append(0, 6); |
|
40 | series->append(0, 6); | |
41 | series->append(2, 4); |
|
41 | series->append(2, 4); | |
42 | ... |
|
42 | ... | |
43 | chart->addSeries(series); |
|
43 | chart->addSeries(series); | |
44 | \endcode |
|
44 | \endcode | |
45 | */ |
|
45 | */ | |
46 |
|
46 | |||
47 | /*! |
|
47 | /*! | |
48 | \qmlclass SplineSeries QSplineSeries |
|
48 | \qmlclass SplineSeries QSplineSeries | |
49 | \inherits XYSeries |
|
49 | \inherits XYSeries | |
50 |
|
50 | |||
51 | The following QML shows how to create a simple spline chart: |
|
51 | The following QML shows how to create a simple spline chart: | |
52 | \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1 |
|
52 | \snippet ../demos/qmlchart/qml/qmlchart/View3.qml 1 | |
53 | \beginfloatleft |
|
53 | \beginfloatleft | |
54 | \image demos_qmlchart3.png |
|
54 | \image demos_qmlchart3.png | |
55 | \endfloat |
|
55 | \endfloat | |
56 | \clearfloat |
|
56 | \clearfloat | |
57 | */ |
|
57 | */ | |
58 |
|
58 | |||
59 | /*! |
|
59 | /*! | |
60 | \fn QSeriesType QSplineSeries::type() const |
|
60 | \fn QSeriesType QSplineSeries::type() const | |
61 | Returns the type of the series |
|
61 | Returns the type of the series | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty real SplineSeries::width |
|
65 | \qmlproperty real SplineSeries::width | |
66 | The width of the line. By default the width is 2.0. |
|
66 | The width of the line. By default the width is 2.0. | |
67 | */ |
|
67 | */ | |
68 |
|
68 | |||
69 | /*! |
|
69 | /*! | |
70 | \qmlproperty Qt::PenStyle SplineSeries::style |
|
70 | \qmlproperty Qt::PenStyle SplineSeries::style | |
71 | Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine, |
|
71 | Controls the style of the line. Set to one of Qt.NoPen, Qt.SolidLine, Qt.DashLine, Qt.DotLine, | |
72 | Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API. |
|
72 | Qt.DashDotLine or Qt.DashDotDotLine. Using Qt.CustomDashLine is not supported in the QML API. | |
73 | By default the style is Qt.SolidLine. |
|
73 | By default the style is Qt.SolidLine. | |
74 | */ |
|
74 | */ | |
75 |
|
75 | |||
76 | /*! |
|
76 | /*! | |
77 | \qmlproperty Qt::PenCapStyle SplineSeries::capStyle |
|
77 | \qmlproperty Qt::PenCapStyle SplineSeries::capStyle | |
78 | Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By |
|
78 | Controls the cap style of the line. Set to one of Qt.FlatCap, Qt.SquareCap or Qt.RoundCap. By | |
79 | default the cap style is Qt.SquareCap. |
|
79 | default the cap style is Qt.SquareCap. | |
80 | */ |
|
80 | */ | |
81 |
|
81 | |||
82 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
82 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
83 |
|
83 | |||
84 | /*! |
|
84 | /*! | |
85 | Constructs empty series object which is a child of \a parent. |
|
85 | Constructs empty series object which is a child of \a parent. | |
86 |
When series object is added to |
|
86 | When series object is added to a QChart instance then the ownerships is transferred. | |
87 | */ |
|
87 | */ | |
88 |
|
88 | |||
89 | QSplineSeries::QSplineSeries(QObject *parent) |
|
89 | QSplineSeries::QSplineSeries(QObject *parent) | |
90 | : QLineSeries(*new QSplineSeriesPrivate(this), parent) |
|
90 | : QLineSeries(*new QSplineSeriesPrivate(this), parent) | |
91 | { |
|
91 | { | |
92 | } |
|
92 | } | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | Destroys the object. |
|
95 | Destroys the object. | |
96 | */ |
|
96 | */ | |
97 | QSplineSeries::~QSplineSeries() |
|
97 | QSplineSeries::~QSplineSeries() | |
98 | { |
|
98 | { | |
99 | Q_D(QSplineSeries); |
|
99 | Q_D(QSplineSeries); | |
100 | if (d->m_chart) |
|
100 | if (d->m_chart) | |
101 | d->m_chart->removeSeries(this); |
|
101 | d->m_chart->removeSeries(this); | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | QAbstractSeries::SeriesType QSplineSeries::type() const |
|
104 | QAbstractSeries::SeriesType QSplineSeries::type() const | |
105 | { |
|
105 | { | |
106 | return QAbstractSeries::SeriesTypeSpline; |
|
106 | return QAbstractSeries::SeriesTypeSpline; | |
107 | } |
|
107 | } | |
108 |
|
108 | |||
109 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
110 |
|
110 | |||
111 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q) |
|
111 | QSplineSeriesPrivate::QSplineSeriesPrivate(QSplineSeries *q) | |
112 | : QLineSeriesPrivate(q) |
|
112 | : QLineSeriesPrivate(q) | |
113 | { |
|
113 | { | |
114 | } |
|
114 | } | |
115 |
|
115 | |||
116 | void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent) |
|
116 | void QSplineSeriesPrivate::initializeGraphics(QGraphicsItem* parent) | |
117 | { |
|
117 | { | |
118 | Q_Q(QSplineSeries); |
|
118 | Q_Q(QSplineSeries); | |
119 | SplineChartItem *spline = new SplineChartItem(q,parent); |
|
119 | SplineChartItem *spline = new SplineChartItem(q,parent); | |
120 | m_item.reset(spline); |
|
120 | m_item.reset(spline); | |
121 | QAbstractSeriesPrivate::initializeGraphics(parent); |
|
121 | QAbstractSeriesPrivate::initializeGraphics(parent); | |
122 | } |
|
122 | } | |
123 |
|
123 | |||
124 | void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
124 | void QSplineSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
125 | { |
|
125 | { | |
126 | Q_Q(QSplineSeries); |
|
126 | Q_Q(QSplineSeries); | |
127 | const QList<QColor> colors = theme->seriesColors(); |
|
127 | const QList<QColor> colors = theme->seriesColors(); | |
128 |
|
128 | |||
129 | QPen pen; |
|
129 | QPen pen; | |
130 | if (forced || pen == m_pen) { |
|
130 | if (forced || pen == m_pen) { | |
131 | pen.setColor(colors.at(index % colors.size())); |
|
131 | pen.setColor(colors.at(index % colors.size())); | |
132 | pen.setWidthF(2); |
|
132 | pen.setWidthF(2); | |
133 | q->setPen(pen); |
|
133 | q->setPen(pen); | |
134 | } |
|
134 | } | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
137 | void QSplineSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
138 | { |
|
138 | { | |
139 | SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); |
|
139 | SplineChartItem *item = static_cast<SplineChartItem *>(m_item.data()); | |
140 | Q_ASSERT(item); |
|
140 | Q_ASSERT(item); | |
141 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
141 | if (options.testFlag(QChart::SeriesAnimations)) { | |
142 | item->setAnimation(new SplineAnimation(item)); |
|
142 | item->setAnimation(new SplineAnimation(item)); | |
143 | }else{ |
|
143 | }else{ | |
144 | item->setAnimation(0); |
|
144 | item->setAnimation(0); | |
145 | } |
|
145 | } | |
146 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
146 | QAbstractSeriesPrivate::initializeAnimations(options); | |
147 | } |
|
147 | } | |
148 |
|
148 | |||
149 | #include "moc_qsplineseries.cpp" |
|
149 | #include "moc_qsplineseries.cpp" | |
150 | #include "moc_qsplineseries_p.cpp" |
|
150 | #include "moc_qsplineseries_p.cpp" | |
151 |
|
151 | |||
152 | QTCOMMERCIALCHART_END_NAMESPACE |
|
152 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,560 +1,559 | |||||
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 Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qxyseries.h" |
|
21 | #include "qxyseries.h" | |
22 | #include "qxyseries_p.h" |
|
22 | #include "qxyseries_p.h" | |
23 | #include "abstractdomain_p.h" |
|
23 | #include "abstractdomain_p.h" | |
24 | #include "qvalueaxis.h" |
|
24 | #include "qvalueaxis.h" | |
25 | #include "xychart_p.h" |
|
25 | #include "xychart_p.h" | |
26 | #include "qxylegendmarker.h" |
|
26 | #include "qxylegendmarker.h" | |
27 | #include "charthelpers_p.h" |
|
27 | #include "charthelpers_p.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QXYSeries |
|
32 | \class QXYSeries | |
33 | \brief The QXYSeries class is a base class for line, spline and scatter series. |
|
33 | \brief The QXYSeries class is a base class for line, spline and scatter series. | |
34 | */ |
|
34 | */ | |
35 | /*! |
|
35 | /*! | |
36 | \qmlclass XYSeries |
|
36 | \qmlclass XYSeries | |
37 | \inherits AbstractSeries |
|
37 | \inherits AbstractSeries | |
38 | The XYSeries class is a base class for line, spline and scatter series. |
|
38 | The XYSeries class is a base class for line, spline and scatter series. | |
39 |
|
39 | |||
40 | The class cannot be instantiated directly. |
|
40 | The class cannot be instantiated directly. | |
41 | */ |
|
41 | */ | |
42 |
|
42 | |||
43 | /*! |
|
43 | /*! | |
44 | \qmlproperty AbstractAxis XYSeries::axisX |
|
44 | \qmlproperty AbstractAxis XYSeries::axisX | |
45 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for |
|
45 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a ValueAxis is created for | |
46 | the series. |
|
46 | the series. | |
47 | \sa axisXTop |
|
47 | \sa axisXTop | |
48 | */ |
|
48 | */ | |
49 |
|
49 | |||
50 | /*! |
|
50 | /*! | |
51 | \qmlproperty AbstractAxis XYSeries::axisY |
|
51 | \qmlproperty AbstractAxis XYSeries::axisY | |
52 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
52 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for | |
53 | the series. |
|
53 | the series. | |
54 | \sa axisYRight |
|
54 | \sa axisYRight | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | \qmlproperty AbstractAxis XYSeries::axisXTop |
|
58 | \qmlproperty AbstractAxis XYSeries::axisXTop | |
59 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
59 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or | |
60 | axisXTop, but not both. |
|
60 | axisXTop, but not both. | |
61 | \sa axisX |
|
61 | \sa axisX | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty AbstractAxis XYSeries::axisYRight |
|
65 | \qmlproperty AbstractAxis XYSeries::axisYRight | |
66 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
66 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY | |
67 | or axisYRight, but not both. |
|
67 | or axisYRight, but not both. | |
68 | \sa axisY |
|
68 | \sa axisY | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty AbstractAxis XYSeries::axisAngular |
|
72 | \qmlproperty AbstractAxis XYSeries::axisAngular | |
73 | The angular axis used for the series, drawn around the polar chart view. |
|
73 | The angular axis used for the series, drawn around the polar chart view. | |
74 | \sa axisX |
|
74 | \sa axisX | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \qmlproperty AbstractAxis XYSeries::axisRadial |
|
78 | \qmlproperty AbstractAxis XYSeries::axisRadial | |
79 | The radial axis used for the series, drawn inside the polar chart view. |
|
79 | The radial axis used for the series, drawn inside the polar chart view. | |
80 | \sa axisY |
|
80 | \sa axisY | |
81 | */ |
|
81 | */ | |
82 |
|
82 | |||
83 | /*! |
|
83 | /*! | |
84 | \property QXYSeries::pointsVisible |
|
84 | \property QXYSeries::pointsVisible | |
85 | Controls if the data points are visible and should be drawn. |
|
85 | Controls if the data points are visible and should be drawn. | |
86 | */ |
|
86 | */ | |
87 | /*! |
|
87 | /*! | |
88 | \qmlproperty bool XYSeries::pointsVisible |
|
88 | \qmlproperty bool XYSeries::pointsVisible | |
89 | Controls if the data points are visible and should be drawn. |
|
89 | Controls if the data points are visible and should be drawn. | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \fn QPen QXYSeries::pen() const |
|
93 | \fn QPen QXYSeries::pen() const | |
94 | \brief Returns pen used to draw points for series. |
|
94 | \brief Returns pen used to draw points for series. | |
95 | \sa setPen() |
|
95 | \sa setPen() | |
96 | */ |
|
96 | */ | |
97 |
|
97 | |||
98 | /*! |
|
98 | /*! | |
99 | \fn QBrush QXYSeries::brush() const |
|
99 | \fn QBrush QXYSeries::brush() const | |
100 | \brief Returns brush used to draw points for series. |
|
100 | \brief Returns brush used to draw points for series. | |
101 | \sa setBrush() |
|
101 | \sa setBrush() | |
102 | */ |
|
102 | */ | |
103 |
|
103 | |||
104 | /*! |
|
104 | /*! | |
105 | \property QXYSeries::color |
|
105 | \property QXYSeries::color | |
106 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and |
|
106 | The color of the series. This is line (pen) color in case of QLineSeries or QSplineSeries and | |
107 | fill (brush) color in case of QScatterSeries or QAreaSeries. |
|
107 | fill (brush) color in case of QScatterSeries or QAreaSeries. | |
108 | \sa QXYSeries::pen(), QXYSeries::brush() |
|
108 | \sa QXYSeries::pen(), QXYSeries::brush() | |
109 | */ |
|
109 | */ | |
110 | /*! |
|
110 | /*! | |
111 | \qmlproperty color XYSeries::color |
|
111 | \qmlproperty color XYSeries::color | |
112 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and |
|
112 | The color of the series. This is line (pen) color in case of LineSeries or SplineSeries and | |
113 | fill (brush) color in case of ScatterSeries or AreaSeries. |
|
113 | fill (brush) color in case of ScatterSeries or AreaSeries. | |
114 | */ |
|
114 | */ | |
115 |
|
115 | |||
116 | /*! |
|
116 | /*! | |
117 | \fn void QXYSeries::clicked(const QPointF& point) |
|
117 | \fn void QXYSeries::clicked(const QPointF& point) | |
118 | \brief Signal is emitted when user clicks the \a point on chart. |
|
118 | \brief Signal is emitted when user clicks the \a point on chart. | |
119 | */ |
|
119 | */ | |
120 | /*! |
|
120 | /*! | |
121 | \qmlsignal XYSeries::onClicked(QPointF point) |
|
121 | \qmlsignal XYSeries::onClicked(QPointF point) | |
122 | Signal is emitted when user clicks the \a point on chart. For example: |
|
122 | Signal is emitted when user clicks the \a point on chart. For example: | |
123 | \code |
|
123 | \code | |
124 | LineSeries { |
|
124 | LineSeries { | |
125 | XYPoint { x: 0; y: 0 } |
|
125 | XYPoint { x: 0; y: 0 } | |
126 | XYPoint { x: 1.1; y: 2.1 } |
|
126 | XYPoint { x: 1.1; y: 2.1 } | |
127 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); |
|
127 | onClicked: console.log("onClicked: " + point.x + ", " + point.y); | |
128 | } |
|
128 | } | |
129 | \endcode |
|
129 | \endcode | |
130 | */ |
|
130 | */ | |
131 |
|
131 | |||
132 | /*! |
|
132 | /*! | |
133 | \fn void QXYSeries::hovered(const QPointF &point, bool state) |
|
133 | \fn void QXYSeries::hovered(const QPointF &point, bool state) | |
134 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
134 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
135 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
135 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
136 | the series. |
|
136 | the series. | |
137 | */ |
|
137 | */ | |
138 | /*! |
|
138 | /*! | |
139 | \qmlsignal XYSeries::onHovered(point point, bool state) |
|
139 | \qmlsignal XYSeries::onHovered(point point, bool state) | |
140 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) |
|
140 | This signal is emitted when user has hovered over or away from the series. \a point shows the origin (coordinate) | |
141 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from |
|
141 | of the hover event. \a state is true when user has hovered over the series and false when hover has moved away from | |
142 | the series. |
|
142 | the series. | |
143 | */ |
|
143 | */ | |
144 |
|
144 | |||
145 | /*! |
|
145 | /*! | |
146 | \fn void QXYSeries::pointReplaced(int index) |
|
146 | \fn void QXYSeries::pointReplaced(int index) | |
147 | Signal is emitted when a point has been replaced at \a index. |
|
147 | Signal is emitted when a point has been replaced at \a index. | |
148 | \sa replace() |
|
148 | \sa replace() | |
149 | */ |
|
149 | */ | |
150 | /*! |
|
150 | /*! | |
151 | \qmlsignal XYSeries::onPointReplaced(int index) |
|
151 | \qmlsignal XYSeries::onPointReplaced(int index) | |
152 | Signal is emitted when a point has been replaced at \a index. |
|
152 | Signal is emitted when a point has been replaced at \a index. | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QXYSeries::pointsReplaced() |
|
156 | \fn void QXYSeries::pointsReplaced() | |
157 |
Signal is emitted when all points have been replaced with |
|
157 | Signal is emitted when all points have been replaced with other points. | |
158 | \sa replace() |
|
158 | \sa replace() | |
159 | */ |
|
159 | */ | |
160 | /*! |
|
160 | /*! | |
161 | \qmlsignal XYSeries::onPointsReplaced() |
|
161 | \qmlsignal XYSeries::onPointsReplaced() | |
162 | */ |
|
162 | */ | |
163 |
|
163 | |||
164 | /*! |
|
164 | /*! | |
165 | \fn void QXYSeries::pointAdded(int index) |
|
165 | \fn void QXYSeries::pointAdded(int index) | |
166 | Signal is emitted when a point has been added at \a index. |
|
166 | Signal is emitted when a point has been added at \a index. | |
167 | \sa append(), insert() |
|
167 | \sa append(), insert() | |
168 | */ |
|
168 | */ | |
169 | /*! |
|
169 | /*! | |
170 | \qmlsignal XYSeries::onPointAdded(int index) |
|
170 | \qmlsignal XYSeries::onPointAdded(int index) | |
171 | Signal is emitted when a point has been added at \a index. |
|
171 | Signal is emitted when a point has been added at \a index. | |
172 | */ |
|
172 | */ | |
173 |
|
173 | |||
174 | /*! |
|
174 | /*! | |
175 | \fn void QXYSeries::pointRemoved(int index) |
|
175 | \fn void QXYSeries::pointRemoved(int index) | |
176 | Signal is emitted when a point has been removed from \a index. |
|
176 | Signal is emitted when a point has been removed from \a index. | |
177 | \sa remove() |
|
177 | \sa remove() | |
178 | */ |
|
178 | */ | |
179 | /*! |
|
179 | /*! | |
180 | \qmlsignal XYSeries::onPointRemoved(int index) |
|
180 | \qmlsignal XYSeries::onPointRemoved(int index) | |
181 | Signal is emitted when a point has been removed from \a index. |
|
181 | Signal is emitted when a point has been removed from \a index. | |
182 | */ |
|
182 | */ | |
183 |
|
183 | |||
184 | /*! |
|
184 | /*! | |
185 | \fn void QXYSeries::colorChanged(QColor color) |
|
185 | \fn void QXYSeries::colorChanged(QColor color) | |
186 | \brief Signal is emitted when the line (pen) color has changed to \a color. |
|
186 | \brief Signal is emitted when the line (pen) color has changed to \a color. | |
187 | */ |
|
187 | */ | |
188 | /*! |
|
188 | /*! | |
189 | \qmlsignal XYSeries::onColorChanged(color color) |
|
189 | \qmlsignal XYSeries::onColorChanged(color color) | |
190 | Signal is emitted when the line (pen) color has changed to \a color. |
|
190 | Signal is emitted when the line (pen) color has changed to \a color. | |
191 | */ |
|
191 | */ | |
192 |
|
192 | |||
193 | /*! |
|
193 | /*! | |
194 | \fn void QXYSeriesPrivate::updated() |
|
194 | \fn void QXYSeriesPrivate::updated() | |
195 | \brief \internal |
|
195 | \brief \internal | |
196 | */ |
|
196 | */ | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | \qmlmethod XYSeries::append(real x, real y) |
|
199 | \qmlmethod XYSeries::append(real x, real y) | |
200 | Append point (\a x, \a y) to the series |
|
200 | Append point (\a x, \a y) to the series | |
201 | */ |
|
201 | */ | |
202 |
|
202 | |||
203 | /*! |
|
203 | /*! | |
204 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) |
|
204 | \qmlmethod XYSeries::replace(real oldX, real oldY, real newX, real newY) | |
205 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not |
|
205 | Replaces point (\a oldX, \a oldY) with point (\a newX, \a newY). Does nothing, if point (oldX, oldY) does not | |
206 | exist. |
|
206 | exist. | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \qmlmethod XYSeries::remove(real x, real y) |
|
210 | \qmlmethod XYSeries::remove(real x, real y) | |
211 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. |
|
211 | Removes point (\a x, \a y) from the series. Does nothing, if point (x, y) does not exist. | |
212 | */ |
|
212 | */ | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | \qmlmethod XYSeries::insert(int index, real x, real y) |
|
215 | \qmlmethod XYSeries::insert(int index, real x, real y) | |
216 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of |
|
216 | Inserts point (\a x, \a y) to the \a index. If index is 0 or smaller than 0 the point is prepended to the list of | |
217 | points. If index is the same as or bigger than count, the point is appended to the list of points. |
|
217 | points. If index is the same as or bigger than count, the point is appended to the list of points. | |
218 | */ |
|
218 | */ | |
219 |
|
219 | |||
220 | /*! |
|
220 | /*! | |
221 | \qmlmethod QPointF XYSeries::at(int index) |
|
221 | \qmlmethod QPointF XYSeries::at(int index) | |
222 | Returns point at \a index. Returns (0, 0) if the index is not valid. |
|
222 | Returns point at \a index. Returns (0, 0) if the index is not valid. | |
223 | */ |
|
223 | */ | |
224 |
|
224 | |||
225 | /*! |
|
225 | /*! | |
226 | \internal |
|
226 | \internal | |
227 |
|
227 | |||
228 | Constructs empty series object which is a child of \a parent. |
|
228 | Constructs empty series object which is a child of \a parent. | |
229 |
When series object is added to QChart |
|
229 | When series object is added to QChart instance ownerships is transferred. | |
230 | */ |
|
230 | */ | |
231 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) |
|
231 | QXYSeries::QXYSeries(QXYSeriesPrivate &d, QObject *parent) | |
232 | : QAbstractSeries(d, parent) |
|
232 | : QAbstractSeries(d, parent) | |
233 | { |
|
233 | { | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 |
Destroys the object. Series added to QChart |
|
237 | Destroys the object. Series added to QChart instances are owned by those, | |
238 |
and are de |
|
238 | and are destroyed when QChart instances are destroyed. | |
239 | */ |
|
239 | */ | |
240 | QXYSeries::~QXYSeries() |
|
240 | QXYSeries::~QXYSeries() | |
241 | { |
|
241 | { | |
242 | } |
|
242 | } | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 |
Adds data point \a x \a y to the series. |
|
245 | Adds data point (\a x, \a y) to the series. | |
246 | */ |
|
246 | */ | |
247 | void QXYSeries::append(qreal x, qreal y) |
|
247 | void QXYSeries::append(qreal x, qreal y) | |
248 | { |
|
248 | { | |
249 | append(QPointF(x, y)); |
|
249 | append(QPointF(x, y)); | |
250 | } |
|
250 | } | |
251 |
|
251 | |||
252 | /*! |
|
252 | /*! | |
253 | This is an overloaded function. |
|
253 | This is an overloaded function. | |
254 |
Adds data \a point to the series. |
|
254 | Adds data \a point to the series. | |
255 | */ |
|
255 | */ | |
256 | void QXYSeries::append(const QPointF &point) |
|
256 | void QXYSeries::append(const QPointF &point) | |
257 | { |
|
257 | { | |
258 | Q_D(QXYSeries); |
|
258 | Q_D(QXYSeries); | |
259 |
|
259 | |||
260 | if (isValidValue(point)) { |
|
260 | if (isValidValue(point)) { | |
261 | d->m_points << point; |
|
261 | d->m_points << point; | |
262 | emit pointAdded(d->m_points.count() - 1); |
|
262 | emit pointAdded(d->m_points.count() - 1); | |
263 | } |
|
263 | } | |
264 | } |
|
264 | } | |
265 |
|
265 | |||
266 | /*! |
|
266 | /*! | |
267 | This is an overloaded function. |
|
267 | This is an overloaded function. | |
268 |
Adds list of data \a points to the series. |
|
268 | Adds list of data \a points to the series. | |
269 | */ |
|
269 | */ | |
270 | void QXYSeries::append(const QList<QPointF> &points) |
|
270 | void QXYSeries::append(const QList<QPointF> &points) | |
271 | { |
|
271 | { | |
272 | foreach (const QPointF &point , points) |
|
272 | foreach (const QPointF &point , points) | |
273 | append(point); |
|
273 | append(point); | |
274 | } |
|
274 | } | |
275 |
|
275 | |||
276 | /*! |
|
276 | /*! | |
277 | Replaces data point \a oldX \a oldY with data point \a newX \a newY. |
|
277 | Replaces data point (\a oldX, \a oldY) with data point (\a newX, \a newY). | |
278 | \sa QXYSeries::pointReplaced() |
|
278 | \sa QXYSeries::pointReplaced() | |
279 | */ |
|
279 | */ | |
280 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) |
|
280 | void QXYSeries::replace(qreal oldX, qreal oldY, qreal newX, qreal newY) | |
281 | { |
|
281 | { | |
282 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); |
|
282 | replace(QPointF(oldX, oldY), QPointF(newX, newY)); | |
283 | } |
|
283 | } | |
284 |
|
284 | |||
285 | /*! |
|
285 | /*! | |
286 | Replaces \a oldPoint with \a newPoint. |
|
286 | Replaces \a oldPoint with \a newPoint. | |
287 | \sa QXYSeries::pointReplaced() |
|
287 | \sa QXYSeries::pointReplaced() | |
288 | */ |
|
288 | */ | |
289 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) |
|
289 | void QXYSeries::replace(const QPointF &oldPoint, const QPointF &newPoint) | |
290 | { |
|
290 | { | |
291 | Q_D(QXYSeries); |
|
291 | Q_D(QXYSeries); | |
292 | int index = d->m_points.indexOf(oldPoint); |
|
292 | int index = d->m_points.indexOf(oldPoint); | |
293 | if (index == -1) |
|
293 | if (index == -1) | |
294 | return; |
|
294 | return; | |
295 | if (isValidValue(newPoint)) { |
|
295 | if (isValidValue(newPoint)) { | |
296 | d->m_points[index] = newPoint; |
|
296 | d->m_points[index] = newPoint; | |
297 | emit pointReplaced(index); |
|
297 | emit pointReplaced(index); | |
298 | } |
|
298 | } | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | /*! |
|
301 | /*! | |
302 |
Replaces the current points with \a points. |
|
302 | Replaces the current points with \a points. | |
|
303 | \note This is much faster than replacing data points one by one, | |||
303 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() |
|
304 | or first clearing all data, and then appending the new data. Emits QXYSeries::pointsReplaced() | |
304 | when the points have been replaced. |
|
305 | when the points have been replaced. | |
305 | \sa QXYSeries::pointsReplaced() |
|
306 | \sa QXYSeries::pointsReplaced() | |
306 | */ |
|
307 | */ | |
307 | void QXYSeries::replace(QList<QPointF> points) |
|
308 | void QXYSeries::replace(QList<QPointF> points) | |
308 | { |
|
309 | { | |
309 | Q_D(QXYSeries); |
|
310 | Q_D(QXYSeries); | |
310 | d->m_points = points.toVector(); |
|
311 | d->m_points = points.toVector(); | |
311 | emit pointsReplaced(); |
|
312 | emit pointsReplaced(); | |
312 | } |
|
313 | } | |
313 |
|
314 | |||
314 | /*! |
|
315 | /*! | |
315 | Removes current \a x and \a y value. |
|
316 | Removes the point (\a x, \a y) from the series. | |
316 | */ |
|
317 | */ | |
317 | void QXYSeries::remove(qreal x, qreal y) |
|
318 | void QXYSeries::remove(qreal x, qreal y) | |
318 | { |
|
319 | { | |
319 | remove(QPointF(x, y)); |
|
320 | remove(QPointF(x, y)); | |
320 | } |
|
321 | } | |
321 |
|
322 | |||
322 | /*! |
|
323 | /*! | |
323 |
Removes |
|
324 | Removes the \a point from the series. | |
324 |
|
||||
325 | Note: point y value is ignored. |
|
|||
326 | */ |
|
325 | */ | |
327 | void QXYSeries::remove(const QPointF &point) |
|
326 | void QXYSeries::remove(const QPointF &point) | |
328 | { |
|
327 | { | |
329 | Q_D(QXYSeries); |
|
328 | Q_D(QXYSeries); | |
330 | int index = d->m_points.indexOf(point); |
|
329 | int index = d->m_points.indexOf(point); | |
331 | if (index == -1) |
|
330 | if (index == -1) | |
332 | return; |
|
331 | return; | |
333 | d->m_points.remove(index); |
|
332 | d->m_points.remove(index); | |
334 | emit pointRemoved(index); |
|
333 | emit pointRemoved(index); | |
335 | } |
|
334 | } | |
336 |
|
335 | |||
337 | /*! |
|
336 | /*! | |
338 | Inserts a \a point in the series at \a index position. |
|
337 | Inserts a \a point in the series at \a index position. | |
339 | */ |
|
338 | */ | |
340 | void QXYSeries::insert(int index, const QPointF &point) |
|
339 | void QXYSeries::insert(int index, const QPointF &point) | |
341 | { |
|
340 | { | |
342 | Q_D(QXYSeries); |
|
341 | Q_D(QXYSeries); | |
343 | if (isValidValue(point)) { |
|
342 | if (isValidValue(point)) { | |
344 | d->m_points.insert(index, point); |
|
343 | d->m_points.insert(index, point); | |
345 | emit pointAdded(index); |
|
344 | emit pointAdded(index); | |
346 | } |
|
345 | } | |
347 | } |
|
346 | } | |
348 |
|
347 | |||
349 | /*! |
|
348 | /*! | |
350 | Removes all points from the series. |
|
349 | Removes all points from the series. | |
351 | */ |
|
350 | */ | |
352 | void QXYSeries::clear() |
|
351 | void QXYSeries::clear() | |
353 | { |
|
352 | { | |
354 | Q_D(QXYSeries); |
|
353 | Q_D(QXYSeries); | |
355 | for (int i = d->m_points.size() - 1; i >= 0; i--) |
|
354 | for (int i = d->m_points.size() - 1; i >= 0; i--) | |
356 | remove(d->m_points.at(i)); |
|
355 | remove(d->m_points.at(i)); | |
357 | } |
|
356 | } | |
358 |
|
357 | |||
359 | /*! |
|
358 | /*! | |
360 | Returns list of points in the series. |
|
359 | Returns list of points in the series. | |
361 | */ |
|
360 | */ | |
362 | QList<QPointF> QXYSeries::points() const |
|
361 | QList<QPointF> QXYSeries::points() const | |
363 | { |
|
362 | { | |
364 | Q_D(const QXYSeries); |
|
363 | Q_D(const QXYSeries); | |
365 | return d->m_points.toList(); |
|
364 | return d->m_points.toList(); | |
366 | } |
|
365 | } | |
367 |
|
366 | |||
368 | /*! |
|
367 | /*! | |
369 | Returns point at \a index in internal points vector. |
|
368 | Returns point at \a index in internal points vector. | |
370 | */ |
|
369 | */ | |
371 | const QPointF &QXYSeries::at(int index) const |
|
370 | const QPointF &QXYSeries::at(int index) const | |
372 | { |
|
371 | { | |
373 | Q_D(const QXYSeries); |
|
372 | Q_D(const QXYSeries); | |
374 | return d->m_points.at(index); |
|
373 | return d->m_points.at(index); | |
375 | } |
|
374 | } | |
376 |
|
375 | |||
377 | /*! |
|
376 | /*! | |
378 | Returns number of data points within series. |
|
377 | Returns number of data points within series. | |
379 | */ |
|
378 | */ | |
380 | int QXYSeries::count() const |
|
379 | int QXYSeries::count() const | |
381 | { |
|
380 | { | |
382 | Q_D(const QXYSeries); |
|
381 | Q_D(const QXYSeries); | |
383 | return d->m_points.count(); |
|
382 | return d->m_points.count(); | |
384 | } |
|
383 | } | |
385 |
|
384 | |||
386 |
|
385 | |||
387 | /*! |
|
386 | /*! | |
388 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the |
|
387 | Sets \a pen used for drawing points on the chart. If the pen is not defined, the | |
389 | pen from chart theme is used. |
|
388 | pen from chart theme is used. | |
390 | \sa QChart::setTheme() |
|
389 | \sa QChart::setTheme() | |
391 | */ |
|
390 | */ | |
392 | void QXYSeries::setPen(const QPen &pen) |
|
391 | void QXYSeries::setPen(const QPen &pen) | |
393 | { |
|
392 | { | |
394 | Q_D(QXYSeries); |
|
393 | Q_D(QXYSeries); | |
395 | if (d->m_pen != pen) { |
|
394 | if (d->m_pen != pen) { | |
396 | bool emitColorChanged = d->m_pen.color() != pen.color(); |
|
395 | bool emitColorChanged = d->m_pen.color() != pen.color(); | |
397 | d->m_pen = pen; |
|
396 | d->m_pen = pen; | |
398 | emit d->updated(); |
|
397 | emit d->updated(); | |
399 | if (emitColorChanged) |
|
398 | if (emitColorChanged) | |
400 | emit colorChanged(pen.color()); |
|
399 | emit colorChanged(pen.color()); | |
401 | } |
|
400 | } | |
402 | } |
|
401 | } | |
403 |
|
402 | |||
404 | QPen QXYSeries::pen() const |
|
403 | QPen QXYSeries::pen() const | |
405 | { |
|
404 | { | |
406 | Q_D(const QXYSeries); |
|
405 | Q_D(const QXYSeries); | |
407 | return d->m_pen; |
|
406 | return d->m_pen; | |
408 | } |
|
407 | } | |
409 |
|
408 | |||
410 | /*! |
|
409 | /*! | |
411 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush |
|
410 | Sets \a brush used for drawing points on the chart. If the brush is not defined, brush | |
412 | from chart theme setting is used. |
|
411 | from chart theme setting is used. | |
413 | \sa QChart::setTheme() |
|
412 | \sa QChart::setTheme() | |
414 | */ |
|
413 | */ | |
415 | void QXYSeries::setBrush(const QBrush &brush) |
|
414 | void QXYSeries::setBrush(const QBrush &brush) | |
416 | { |
|
415 | { | |
417 | Q_D(QXYSeries); |
|
416 | Q_D(QXYSeries); | |
418 | if (d->m_brush != brush) { |
|
417 | if (d->m_brush != brush) { | |
419 | d->m_brush = brush; |
|
418 | d->m_brush = brush; | |
420 | emit d->updated(); |
|
419 | emit d->updated(); | |
421 | } |
|
420 | } | |
422 | } |
|
421 | } | |
423 |
|
422 | |||
424 | QBrush QXYSeries::brush() const |
|
423 | QBrush QXYSeries::brush() const | |
425 | { |
|
424 | { | |
426 | Q_D(const QXYSeries); |
|
425 | Q_D(const QXYSeries); | |
427 | return d->m_brush; |
|
426 | return d->m_brush; | |
428 | } |
|
427 | } | |
429 |
|
428 | |||
430 | void QXYSeries::setColor(const QColor &color) |
|
429 | void QXYSeries::setColor(const QColor &color) | |
431 | { |
|
430 | { | |
432 | QPen p = pen(); |
|
431 | QPen p = pen(); | |
433 | if (p.color() != color) { |
|
432 | if (p.color() != color) { | |
434 | p.setColor(color); |
|
433 | p.setColor(color); | |
435 | setPen(p); |
|
434 | setPen(p); | |
436 | } |
|
435 | } | |
437 | } |
|
436 | } | |
438 |
|
437 | |||
439 | QColor QXYSeries::color() const |
|
438 | QColor QXYSeries::color() const | |
440 | { |
|
439 | { | |
441 | return pen().color(); |
|
440 | return pen().color(); | |
442 | } |
|
441 | } | |
443 |
|
442 | |||
444 | void QXYSeries::setPointsVisible(bool visible) |
|
443 | void QXYSeries::setPointsVisible(bool visible) | |
445 | { |
|
444 | { | |
446 | Q_D(QXYSeries); |
|
445 | Q_D(QXYSeries); | |
447 | if (d->m_pointsVisible != visible) { |
|
446 | if (d->m_pointsVisible != visible) { | |
448 | d->m_pointsVisible = visible; |
|
447 | d->m_pointsVisible = visible; | |
449 | emit d->updated(); |
|
448 | emit d->updated(); | |
450 | } |
|
449 | } | |
451 | } |
|
450 | } | |
452 |
|
451 | |||
453 | bool QXYSeries::pointsVisible() const |
|
452 | bool QXYSeries::pointsVisible() const | |
454 | { |
|
453 | { | |
455 | Q_D(const QXYSeries); |
|
454 | Q_D(const QXYSeries); | |
456 | return d->m_pointsVisible; |
|
455 | return d->m_pointsVisible; | |
457 | } |
|
456 | } | |
458 |
|
457 | |||
459 |
|
458 | |||
460 | /*! |
|
459 | /*! | |
461 | Stream operator for adding a data \a point to the series. |
|
460 | Stream operator for adding a data \a point to the series. | |
462 | \sa append() |
|
461 | \sa append() | |
463 | */ |
|
462 | */ | |
464 | QXYSeries &QXYSeries::operator<< (const QPointF &point) |
|
463 | QXYSeries &QXYSeries::operator<< (const QPointF &point) | |
465 | { |
|
464 | { | |
466 | append(point); |
|
465 | append(point); | |
467 | return *this; |
|
466 | return *this; | |
468 | } |
|
467 | } | |
469 |
|
468 | |||
470 |
|
469 | |||
471 | /*! |
|
470 | /*! | |
472 | Stream operator for adding a list of \a points to the series. |
|
471 | Stream operator for adding a list of \a points to the series. | |
473 | \sa append() |
|
472 | \sa append() | |
474 | */ |
|
473 | */ | |
475 |
|
474 | |||
476 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) |
|
475 | QXYSeries &QXYSeries::operator<< (const QList<QPointF>& points) | |
477 | { |
|
476 | { | |
478 | append(points); |
|
477 | append(points); | |
479 | return *this; |
|
478 | return *this; | |
480 | } |
|
479 | } | |
481 |
|
480 | |||
482 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
481 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
483 |
|
482 | |||
484 |
|
483 | |||
485 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) |
|
484 | QXYSeriesPrivate::QXYSeriesPrivate(QXYSeries *q) | |
486 | : QAbstractSeriesPrivate(q), |
|
485 | : QAbstractSeriesPrivate(q), | |
487 | m_pointsVisible(false) |
|
486 | m_pointsVisible(false) | |
488 | { |
|
487 | { | |
489 | } |
|
488 | } | |
490 |
|
489 | |||
491 | void QXYSeriesPrivate::initializeDomain() |
|
490 | void QXYSeriesPrivate::initializeDomain() | |
492 | { |
|
491 | { | |
493 | qreal minX(0); |
|
492 | qreal minX(0); | |
494 | qreal minY(0); |
|
493 | qreal minY(0); | |
495 | qreal maxX(1); |
|
494 | qreal maxX(1); | |
496 | qreal maxY(1); |
|
495 | qreal maxY(1); | |
497 |
|
496 | |||
498 | Q_Q(QXYSeries); |
|
497 | Q_Q(QXYSeries); | |
499 |
|
498 | |||
500 | const QList<QPointF>& points = q->points(); |
|
499 | const QList<QPointF>& points = q->points(); | |
501 |
|
500 | |||
502 | if (!points.isEmpty()) { |
|
501 | if (!points.isEmpty()) { | |
503 | minX = points[0].x(); |
|
502 | minX = points[0].x(); | |
504 | minY = points[0].y(); |
|
503 | minY = points[0].y(); | |
505 | maxX = minX; |
|
504 | maxX = minX; | |
506 | maxY = minY; |
|
505 | maxY = minY; | |
507 |
|
506 | |||
508 | for (int i = 0; i < points.count(); i++) { |
|
507 | for (int i = 0; i < points.count(); i++) { | |
509 | qreal x = points[i].x(); |
|
508 | qreal x = points[i].x(); | |
510 | qreal y = points[i].y(); |
|
509 | qreal y = points[i].y(); | |
511 | minX = qMin(minX, x); |
|
510 | minX = qMin(minX, x); | |
512 | minY = qMin(minY, y); |
|
511 | minY = qMin(minY, y); | |
513 | maxX = qMax(maxX, x); |
|
512 | maxX = qMax(maxX, x); | |
514 | maxY = qMax(maxY, y); |
|
513 | maxY = qMax(maxY, y); | |
515 | } |
|
514 | } | |
516 | } |
|
515 | } | |
517 |
|
516 | |||
518 | domain()->setRange(minX, maxX, minY, maxY); |
|
517 | domain()->setRange(minX, maxX, minY, maxY); | |
519 | } |
|
518 | } | |
520 |
|
519 | |||
521 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
520 | QList<QLegendMarker*> QXYSeriesPrivate::createLegendMarkers(QLegend* legend) | |
522 | { |
|
521 | { | |
523 | Q_Q(QXYSeries); |
|
522 | Q_Q(QXYSeries); | |
524 | QList<QLegendMarker*> list; |
|
523 | QList<QLegendMarker*> list; | |
525 | return list << new QXYLegendMarker(q,legend); |
|
524 | return list << new QXYLegendMarker(q,legend); | |
526 | } |
|
525 | } | |
527 |
|
526 | |||
528 | void QXYSeriesPrivate::initializeAxes() |
|
527 | void QXYSeriesPrivate::initializeAxes() | |
529 | { |
|
528 | { | |
530 |
|
529 | |||
531 | } |
|
530 | } | |
532 |
|
531 | |||
533 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
532 | QAbstractAxis::AxisType QXYSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
534 | { |
|
533 | { | |
535 | Q_UNUSED(orientation); |
|
534 | Q_UNUSED(orientation); | |
536 | return QAbstractAxis::AxisTypeValue; |
|
535 | return QAbstractAxis::AxisTypeValue; | |
537 | } |
|
536 | } | |
538 |
|
537 | |||
539 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
538 | QAbstractAxis* QXYSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
540 | { |
|
539 | { | |
541 | Q_UNUSED(orientation); |
|
540 | Q_UNUSED(orientation); | |
542 | return 0; |
|
541 | return 0; | |
543 | } |
|
542 | } | |
544 |
|
543 | |||
545 | void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) |
|
544 | void QXYSeriesPrivate::initializeAnimations(QtCommercialChart::QChart::AnimationOptions options) | |
546 | { |
|
545 | { | |
547 | XYChart *item = static_cast<XYChart *>(m_item.data()); |
|
546 | XYChart *item = static_cast<XYChart *>(m_item.data()); | |
548 | Q_ASSERT(item); |
|
547 | Q_ASSERT(item); | |
549 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
548 | if (options.testFlag(QChart::SeriesAnimations)) { | |
550 | item->setAnimation(new XYAnimation(item)); |
|
549 | item->setAnimation(new XYAnimation(item)); | |
551 | }else{ |
|
550 | }else{ | |
552 | item->setAnimation(0); |
|
551 | item->setAnimation(0); | |
553 | } |
|
552 | } | |
554 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
553 | QAbstractSeriesPrivate::initializeAnimations(options); | |
555 | } |
|
554 | } | |
556 |
|
555 | |||
557 | #include "moc_qxyseries.cpp" |
|
556 | #include "moc_qxyseries.cpp" | |
558 | #include "moc_qxyseries_p.cpp" |
|
557 | #include "moc_qxyseries_p.cpp" | |
559 |
|
558 | |||
560 | QTCOMMERCIALCHART_END_NAMESPACE |
|
559 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now