@@ -1,638 +1,645 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarset.h" |
|
21 | #include "qbarset.h" | |
22 | #include "qbarset_p.h" |
|
22 | #include "qbarset_p.h" | |
23 |
|
23 | |||
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
25 |
|
25 | |||
26 | /*! |
|
26 | /*! | |
27 | \class QBarSet |
|
27 | \class QBarSet | |
28 | \brief Building block for different bar charts |
|
28 | \brief Building block for different bar charts | |
29 |
|
29 | |||
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. | |
31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
31 | First value of set is assumed to belong to first category, second to second category and so on. | |
32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
32 | If set has fewer values than there are categories, then the missing values are assumed to be | |
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
34 |
|
34 | |||
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries | |
38 | */ |
|
38 | */ | |
39 | /*! |
|
39 | /*! | |
40 | \qmlclass BarSet QBarSet |
|
40 | \qmlclass BarSet QBarSet | |
41 |
|
41 | |||
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
42 | BarSet represents one set of bars. Set of bars contains one data value for each category. | |
43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
43 | First value of set is assumed to belong to first category, second to second category and so on. | |
44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
44 | If set has fewer values than there are categories, then the missing values are assumed to be | |
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. | |
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries |
|
46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries | |
47 | */ |
|
47 | */ | |
48 |
|
48 | |||
49 | /*! |
|
49 | /*! | |
50 | \property QBarSet::label |
|
50 | \property QBarSet::label | |
51 | Defines the label of the barSet. |
|
51 | Defines the label of the barSet. | |
52 | */ |
|
52 | */ | |
53 | /*! |
|
53 | /*! | |
54 | \qmlproperty string BarSet::label |
|
54 | \qmlproperty string BarSet::label | |
55 | Defines the label of the barSet. |
|
55 | Defines the label of the barSet. | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | \property QBarSet::pen |
|
59 | \property QBarSet::pen | |
60 | \brief Defines the pen used by the barSet. |
|
60 | \brief Defines the pen used by the barSet. | |
61 | */ |
|
61 | */ | |
62 |
|
62 | |||
63 | /*! |
|
63 | /*! | |
64 | \property QBarSet::brush |
|
64 | \property QBarSet::brush | |
65 | \brief Defines the brush used by the barSet. |
|
65 | \brief Defines the brush used by the barSet. | |
66 | */ |
|
66 | */ | |
67 |
|
67 | |||
68 | /*! |
|
68 | /*! | |
69 | \property QBarSet::labelBrush |
|
69 | \property QBarSet::labelBrush | |
70 | \brief Defines the brush used by the barSet's label. |
|
70 | \brief Defines the brush used by the barSet's label. | |
71 | */ |
|
71 | */ | |
72 |
|
72 | |||
73 | /*! |
|
73 | /*! | |
74 | \property QBarSet::labelFont |
|
74 | \property QBarSet::labelFont | |
75 | \brief Defines the font used by the barSet's label. |
|
75 | \brief Defines the font used by the barSet's label. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty Font BarSet::labelFont |
|
79 | \qmlproperty Font BarSet::labelFont | |
80 | Defines the font used by the barSet's label. |
|
80 | Defines the font used by the barSet's label. | |
81 |
|
81 | |||
82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
82 | See the \l {Font} {QML Font Element} for detailed documentation. | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \property QBarSet::color |
|
86 | \property QBarSet::color | |
87 | The fill (brush) color of the bar set. |
|
87 | The fill (brush) color of the bar set. | |
88 | */ |
|
88 | */ | |
89 | /*! |
|
89 | /*! | |
90 | \qmlproperty color BarSet::color |
|
90 | \qmlproperty color BarSet::color | |
91 | The fill (brush) color of the bar set. |
|
91 | The fill (brush) color of the bar set. | |
92 | */ |
|
92 | */ | |
93 |
|
93 | |||
94 | /*! |
|
94 | /*! | |
95 | \property QBarSet::borderColor |
|
95 | \property QBarSet::borderColor | |
96 | The line (pen) color of the bar set. |
|
96 | The line (pen) color of the bar set. | |
97 | */ |
|
97 | */ | |
98 | /*! |
|
98 | /*! | |
99 | \qmlproperty color BarSet::borderColor |
|
99 | \qmlproperty color BarSet::borderColor | |
100 | The line (pen) color of the bar set. |
|
100 | The line (pen) color of the bar set. | |
101 | */ |
|
101 | */ | |
102 |
|
102 | |||
103 | /*! |
|
103 | /*! | |
104 | \property QBarSet::labelColor |
|
104 | \property QBarSet::labelColor | |
105 | The text (label) color of the bar set. |
|
105 | The text (label) color of the bar set. | |
106 | */ |
|
106 | */ | |
107 | /*! |
|
107 | /*! | |
108 | \qmlproperty color BarSet::labelColor |
|
108 | \qmlproperty color BarSet::labelColor | |
109 | The text (label) color of the bar set. |
|
109 | The text (label) color of the bar set. | |
110 | */ |
|
110 | */ | |
111 |
|
111 | |||
112 | /*! |
|
112 | /*! | |
113 | \fn void QBarSet::clicked(int index) |
|
113 | \fn void QBarSet::clicked(int index) | |
114 |
|
114 | |||
115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
115 | The signal is emitted if the user clicks with a mouse on top of barset. | |
116 | Clicked bar inside set is indexed by \a index |
|
116 | Clicked bar inside set is indexed by \a index | |
117 | */ |
|
117 | */ | |
118 |
|
118 | |||
119 | /*! |
|
119 | /*! | |
120 | \fn void QBarSet::hovered(bool status) |
|
120 | \fn void QBarSet::hovered(bool status) | |
121 |
|
121 | |||
122 | The signal is emitted if mouse is hovered on top of barset. |
|
122 | The signal is emitted if mouse is hovered on top of barset. | |
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 |
|
126 | |||
127 | /*! |
|
127 | /*! | |
128 | \fn void QBarSet::labelChanged() |
|
128 | \fn void QBarSet::labelChanged() | |
129 | This signal is emitted when the label of the barSet has changed. |
|
129 | This signal is emitted when the label of the barSet has changed. | |
130 | \sa label |
|
130 | \sa label | |
131 | */ |
|
131 | */ | |
132 | /*! |
|
132 | /*! | |
133 | \qmlsignal BarSet::onLabelChanged() |
|
133 | \qmlsignal BarSet::onLabelChanged() | |
134 | This signal is emitted when the label of the barSet has changed. |
|
134 | This signal is emitted when the label of the barSet has changed. | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QBarSet::penChanged() |
|
138 | \fn void QBarSet::penChanged() | |
139 | This signal is emitted when the pen of the barSet has changed. |
|
139 | This signal is emitted when the pen of the barSet has changed. | |
140 | \sa pen |
|
140 | \sa pen | |
141 | */ |
|
141 | */ | |
142 |
|
142 | |||
143 | /*! |
|
143 | /*! | |
144 | \fn void QBarSet::brushChanged() |
|
144 | \fn void QBarSet::brushChanged() | |
145 | This signal is emitted when the brush of the barSet has changed. |
|
145 | This signal is emitted when the brush of the barSet has changed. | |
146 | \sa brush |
|
146 | \sa brush | |
147 | */ |
|
147 | */ | |
148 |
|
148 | |||
149 | /*! |
|
149 | /*! | |
150 | \fn void QBarSet::labelBrushChanged() |
|
150 | \fn void QBarSet::labelBrushChanged() | |
151 | This signal is emitted when the brush of the barSet's label has changed. |
|
151 | This signal is emitted when the brush of the barSet's label has changed. | |
152 | \sa labelBrush |
|
152 | \sa labelBrush | |
153 | */ |
|
153 | */ | |
154 |
|
154 | |||
155 | /*! |
|
155 | /*! | |
156 | \fn void QBarSet::labelFontChanged() |
|
156 | \fn void QBarSet::labelFontChanged() | |
157 | This signal is emitted when the font of the barSet's label has changed. |
|
157 | This signal is emitted when the font of the barSet's label has changed. | |
158 | \sa labelBrush |
|
158 | \sa labelBrush | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QBarSet::colorChanged(QColor) |
|
162 | \fn void QBarSet::colorChanged(QColor) | |
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
164 | */ |
|
164 | */ | |
165 | /*! |
|
165 | /*! | |
166 | \qmlsignal BarSet::onColorChanged(color color) |
|
166 | \qmlsignal BarSet::onColorChanged(color color) | |
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. | |
168 | */ |
|
168 | */ | |
169 |
|
169 | |||
170 | /*! |
|
170 | /*! | |
171 | \fn void QBarSet::borderColorChanged(QColor) |
|
171 | \fn void QBarSet::borderColorChanged(QColor) | |
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
172 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
173 | */ |
|
173 | */ | |
174 | /*! |
|
174 | /*! | |
175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
175 | \qmlsignal BarSet::onBorderColorChanged(color color) | |
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
176 | This signal is emitted when the line (pen) color of the set has changed to \a color. | |
177 | */ |
|
177 | */ | |
178 |
|
178 | |||
179 | /*! |
|
179 | /*! | |
180 | \fn void QBarSet::labelColorChanged(QColor) |
|
180 | \fn void QBarSet::labelColorChanged(QColor) | |
181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
181 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
182 | */ |
|
182 | */ | |
183 | /*! |
|
183 | /*! | |
184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
184 | \qmlsignal BarSet::onLabelColorChanged(color color) | |
185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
185 | This signal is emitted when the text (label) color of the set has changed to \a color. | |
186 | */ |
|
186 | */ | |
187 |
|
187 | |||
188 | /*! |
|
188 | /*! | |
189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
189 | \fn void QBarSet::valuesAdded(int index, int count) | |
190 | This signal is emitted when new values have been added to the set. |
|
190 | This signal is emitted when new values have been added to the set. | |
191 | Parameter \a index indicates the position of the first inserted value. |
|
191 | Parameter \a index indicates the position of the first inserted value. | |
192 | Parameter \a count is the number of iserted values. |
|
192 | Parameter \a count is the number of iserted values. | |
193 | \sa append(), insert() |
|
193 | \sa append(), insert() | |
194 | */ |
|
194 | */ | |
195 | /*! |
|
195 | /*! | |
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
196 | \qmlsignal BarSet::onValuesAdded(int index, int count) | |
197 | This signal is emitted when new values have been added to the set. |
|
197 | This signal is emitted when new values have been added to the set. | |
198 | Parameter \a index indicates the position of the first inserted value. |
|
198 | Parameter \a index indicates the position of the first inserted value. | |
199 | Parameter \a count is the number of iserted values. |
|
199 | Parameter \a count is the number of iserted values. | |
200 | */ |
|
200 | */ | |
201 |
|
201 | |||
202 | /*! |
|
202 | /*! | |
203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
203 | \fn void QBarSet::valuesRemoved(int index, int count) | |
204 | This signal is emitted values have been removed from the set. |
|
204 | This signal is emitted values have been removed from the set. | |
205 | Parameter \a index indicates the position of the first removed value. |
|
205 | Parameter \a index indicates the position of the first removed value. | |
206 | Parameter \a count is the number of removed values. |
|
206 | Parameter \a count is the number of removed values. | |
207 | \sa remove() |
|
207 | \sa remove() | |
208 | */ |
|
208 | */ | |
209 | /*! |
|
209 | /*! | |
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) | |
211 | This signal is emitted values have been removed from the set. |
|
211 | This signal is emitted values have been removed from the set. | |
212 | Parameter \a index indicates the position of the first removed value. |
|
212 | Parameter \a index indicates the position of the first removed value. | |
213 | Parameter \a count is the number of removed values. |
|
213 | Parameter \a count is the number of removed values. | |
214 | */ |
|
214 | */ | |
215 |
|
215 | |||
216 | /*! |
|
216 | /*! | |
217 | \fn void QBarSet::valueChanged(int index) |
|
217 | \fn void QBarSet::valueChanged(int index) | |
218 | This signal is emitted values the value in the set has been modified. |
|
218 | This signal is emitted values the value in the set has been modified. | |
219 | Parameter \a index indicates the position of the modified value. |
|
219 | Parameter \a index indicates the position of the modified value. | |
220 | \sa at() |
|
220 | \sa at() | |
221 | */ |
|
221 | */ | |
222 | /*! |
|
222 | /*! | |
223 | \qmlsignal BarSet::onValueChanged(int index) |
|
223 | \qmlsignal BarSet::onValueChanged(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 | */ |
|
226 | */ | |
227 |
|
227 | |||
228 | /*! |
|
228 | /*! | |
229 | \qmlproperty int BarSet::count |
|
229 | \qmlproperty int BarSet::count | |
230 | The count of values on the barset |
|
230 | The count of values on the barset | |
231 | */ |
|
231 | */ | |
232 |
|
232 | |||
233 | /*! |
|
233 | /*! | |
234 | \qmlproperty QVariantList BarSet::values |
|
234 | \qmlproperty QVariantList BarSet::values | |
235 | 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 |
|
235 | 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 | |
236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
236 | reals as values, the values are automatically completed to points by using the index of a value as it's | |
237 | x-coordinate. For example: |
|
237 | x-coordinate. For example: | |
238 | \code |
|
238 | \code | |
239 | myBarSet1.values = [0, 5, 1, 5]; |
|
239 | myBarSet1.values = [0, 5, 1, 5]; | |
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; | |
241 | \endcode |
|
241 | \endcode | |
242 | */ |
|
242 | */ | |
243 |
|
243 | |||
244 | /*! |
|
244 | /*! | |
245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
245 | Constructs QBarSet with a label of \a label and with parent of \a parent | |
246 | */ |
|
246 | */ | |
247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
247 | QBarSet::QBarSet(const QString label, QObject *parent) | |
248 | : QObject(parent) |
|
248 | : QObject(parent) | |
249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
249 | ,d_ptr(new QBarSetPrivate(label,this)) | |
250 | { |
|
250 | { | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | /*! |
|
253 | /*! | |
254 | Destroys the barset |
|
254 | Destroys the barset | |
255 | */ |
|
255 | */ | |
256 | QBarSet::~QBarSet() |
|
256 | QBarSet::~QBarSet() | |
257 | { |
|
257 | { | |
258 | // NOTE: d_ptr destroyed by QObject |
|
258 | // NOTE: d_ptr destroyed by QObject | |
259 | } |
|
259 | } | |
260 |
|
260 | |||
261 | /*! |
|
261 | /*! | |
262 | Sets new \a label for set. |
|
262 | Sets new \a label for set. | |
263 | */ |
|
263 | */ | |
264 | void QBarSet::setLabel(const QString label) |
|
264 | void QBarSet::setLabel(const QString label) | |
265 | { |
|
265 | { | |
266 | d_ptr->m_label = label; |
|
266 | d_ptr->m_label = label; | |
267 | emit labelChanged(); |
|
267 | emit labelChanged(); | |
268 | } |
|
268 | } | |
269 |
|
269 | |||
270 | /*! |
|
270 | /*! | |
271 | Returns label of the set. |
|
271 | Returns label of the set. | |
272 | */ |
|
272 | */ | |
273 | QString QBarSet::label() const |
|
273 | QString QBarSet::label() const | |
274 | { |
|
274 | { | |
275 | return d_ptr->m_label; |
|
275 | return d_ptr->m_label; | |
276 | } |
|
276 | } | |
277 |
|
277 | |||
278 | /*! |
|
278 | /*! | |
279 | Appends new value \a value to the end of set. |
|
279 | Appends new value \a value to the end of set. | |
280 | */ |
|
280 | */ | |
281 | void QBarSet::append(const qreal value) |
|
281 | void QBarSet::append(const qreal value) | |
282 | { |
|
282 | { | |
283 | // Convert to QPointF |
|
283 | // Convert to QPointF | |
284 | int index = d_ptr->m_values.count(); |
|
284 | int index = d_ptr->m_values.count(); | |
285 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
285 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); | |
286 | emit valuesAdded(index, 1); |
|
286 | emit valuesAdded(index, 1); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | /*! |
|
289 | /*! | |
290 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
290 | Appends a list of reals to set. Works like append with single real value. The \a values in list | |
291 | are appended to end of barset |
|
291 | are appended to end of barset | |
292 | \sa append() |
|
292 | \sa append() | |
293 | */ |
|
293 | */ | |
294 | void QBarSet::append(const QList<qreal> &values) |
|
294 | void QBarSet::append(const QList<qreal> &values) | |
295 | { |
|
295 | { | |
296 | int index = d_ptr->m_values.count(); |
|
296 | int index = d_ptr->m_values.count(); | |
297 | d_ptr->append(values); |
|
297 | d_ptr->append(values); | |
298 | emit valuesAdded(index, values.count()); |
|
298 | emit valuesAdded(index, values.count()); | |
299 | } |
|
299 | } | |
300 |
|
300 | |||
301 | /*! |
|
301 | /*! | |
302 | Convinience operator. Same as append, with real \a value. |
|
302 | Convinience operator. Same as append, with real \a value. | |
303 | \sa append() |
|
303 | \sa append() | |
304 | */ |
|
304 | */ | |
305 | QBarSet& QBarSet::operator << (const qreal &value) |
|
305 | QBarSet& QBarSet::operator << (const qreal &value) | |
306 | { |
|
306 | { | |
307 | append(value); |
|
307 | append(value); | |
308 | return *this; |
|
308 | return *this; | |
309 | } |
|
309 | } | |
310 |
|
310 | |||
311 | /*! |
|
311 | /*! | |
312 | Inserts new \a value on the \a index position. |
|
312 | Inserts new \a value on the \a index position. | |
313 | The value that is currently at this postion is moved to postion index + 1 |
|
313 | The value that is currently at this postion is moved to postion index + 1 | |
314 | \sa remove() |
|
314 | \sa remove() | |
315 | */ |
|
315 | */ | |
316 | void QBarSet::insert(const int index, const qreal value) |
|
316 | void QBarSet::insert(const int index, const qreal value) | |
317 | { |
|
317 | { | |
318 | d_ptr->insert(index, value); |
|
318 | d_ptr->insert(index, value); | |
319 | emit valuesAdded(index,1); |
|
319 | emit valuesAdded(index,1); | |
320 | } |
|
320 | } | |
321 |
|
321 | |||
322 | /*! |
|
322 | /*! | |
323 | Removes \a count number of values from the set starting at \a index. |
|
323 | Removes \a count number of values from the set starting at \a index. | |
324 | \sa insert() |
|
324 | \sa insert() | |
325 | */ |
|
325 | */ | |
326 | void QBarSet::remove(const int index, const int count) |
|
326 | void QBarSet::remove(const int index, const int count) | |
327 | { |
|
327 | { | |
328 | int removedCount = d_ptr->remove(index,count); |
|
328 | int removedCount = d_ptr->remove(index,count); | |
329 | if (removedCount > 0) { |
|
329 | if (removedCount > 0) { | |
330 | emit valuesRemoved(index,removedCount); |
|
330 | emit valuesRemoved(index,removedCount); | |
331 | } |
|
331 | } | |
332 | return; |
|
332 | return; | |
333 | } |
|
333 | } | |
334 |
|
334 | |||
335 | /*! |
|
335 | /*! | |
336 | Sets a new value \a value to set, indexed by \a index |
|
336 | Sets a new value \a value to set, indexed by \a index | |
337 | */ |
|
337 | */ | |
338 | void QBarSet::replace(const int index, const qreal value) |
|
338 | void QBarSet::replace(const int index, const qreal value) | |
339 | { |
|
339 | { | |
340 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
340 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
341 | d_ptr->replace(index,value); |
|
341 | d_ptr->replace(index,value); | |
342 | emit valueChanged(index); |
|
342 | emit valueChanged(index); | |
343 | } |
|
343 | } | |
344 | } |
|
344 | } | |
345 |
|
345 | |||
346 |
|
346 | |||
347 | /*! |
|
347 | /*! | |
348 | Returns value of set indexed by \a index. |
|
348 | Returns value of set indexed by \a index. | |
349 | If the index is out of bounds 0.0 is returned. |
|
349 | If the index is out of bounds 0.0 is returned. | |
350 | */ |
|
350 | */ | |
351 | qreal QBarSet::at(const int index) const |
|
351 | qreal QBarSet::at(const int index) const | |
352 | { |
|
352 | { | |
353 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
353 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
354 | return 0; |
|
354 | return 0; | |
355 | } |
|
355 | } | |
356 |
|
356 | |||
357 | return d_ptr->m_values.at(index).y(); |
|
357 | return d_ptr->m_values.at(index).y(); | |
358 | } |
|
358 | } | |
359 |
|
359 | |||
360 | /*! |
|
360 | /*! | |
361 | Returns value of set indexed by \a index. |
|
361 | Returns value of set indexed by \a index. | |
362 | If the index is out of bounds 0.0 is returned. |
|
362 | If the index is out of bounds 0.0 is returned. | |
363 | */ |
|
363 | */ | |
364 | qreal QBarSet::operator [](const int index) const |
|
364 | qreal QBarSet::operator [](const int index) const | |
365 | { |
|
365 | { | |
366 | return at(index); |
|
366 | return at(index); | |
367 | } |
|
367 | } | |
368 |
|
368 | |||
369 | /*! |
|
369 | /*! | |
370 | Returns count of values in set. |
|
370 | Returns count of values in set. | |
371 | */ |
|
371 | */ | |
372 | int QBarSet::count() const |
|
372 | int QBarSet::count() const | |
373 | { |
|
373 | { | |
374 | return d_ptr->m_values.count(); |
|
374 | return d_ptr->m_values.count(); | |
375 | } |
|
375 | } | |
376 |
|
376 | |||
377 | /*! |
|
377 | /*! | |
378 | Returns sum of all values in barset. |
|
378 | Returns sum of all values in barset. | |
379 | */ |
|
379 | */ | |
380 | qreal QBarSet::sum() const |
|
380 | qreal QBarSet::sum() const | |
381 | { |
|
381 | { | |
382 | qreal total(0); |
|
382 | qreal total(0); | |
383 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
383 | for (int i=0; i < d_ptr->m_values.count(); i++) { | |
384 | total += d_ptr->m_values.at(i).y(); |
|
384 | total += d_ptr->m_values.at(i).y(); | |
385 | } |
|
385 | } | |
386 | return total; |
|
386 | return total; | |
387 | } |
|
387 | } | |
388 |
|
388 | |||
389 | /*! |
|
389 | /*! | |
390 | Sets pen for set. Bars of this set are drawn using \a pen |
|
390 | Sets pen for set. Bars of this set are drawn using \a pen | |
391 | */ |
|
391 | */ | |
392 | void QBarSet::setPen(const QPen &pen) |
|
392 | void QBarSet::setPen(const QPen &pen) | |
393 | { |
|
393 | { | |
394 | if(d_ptr->m_pen!=pen){ |
|
394 | if(d_ptr->m_pen!=pen){ | |
395 | d_ptr->m_pen = pen; |
|
395 | d_ptr->m_pen = pen; | |
396 | emit d_ptr->updatedBars(); |
|
396 | emit d_ptr->updatedBars(); | |
397 | emit penChanged(); |
|
397 | emit penChanged(); | |
398 | } |
|
398 | } | |
399 | } |
|
399 | } | |
400 |
|
400 | |||
401 | /*! |
|
401 | /*! | |
402 | Returns pen of the set. |
|
402 | Returns pen of the set. | |
403 | */ |
|
403 | */ | |
404 | QPen QBarSet::pen() const |
|
404 | QPen QBarSet::pen() const | |
405 | { |
|
405 | { | |
406 | return d_ptr->m_pen; |
|
406 | return d_ptr->m_pen; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | /*! |
|
409 | /*! | |
410 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
410 | Sets brush for the set. Bars of this set are drawn using \a brush | |
411 | */ |
|
411 | */ | |
412 | void QBarSet::setBrush(const QBrush &brush) |
|
412 | void QBarSet::setBrush(const QBrush &brush) | |
413 | { |
|
413 | { | |
414 | if(d_ptr->m_brush!=brush){ |
|
414 | if(d_ptr->m_brush!=brush){ | |
415 | d_ptr->m_brush = brush; |
|
415 | d_ptr->m_brush = brush; | |
416 | emit d_ptr->updatedBars(); |
|
416 | emit d_ptr->updatedBars(); | |
417 | emit brushChanged(); |
|
417 | emit brushChanged(); | |
418 | } |
|
418 | } | |
419 | } |
|
419 | } | |
420 |
|
420 | |||
421 | /*! |
|
421 | /*! | |
422 | Returns brush of the set. |
|
422 | Returns brush of the set. | |
423 | */ |
|
423 | */ | |
424 | QBrush QBarSet::brush() const |
|
424 | QBrush QBarSet::brush() const | |
425 | { |
|
425 | { | |
426 | return d_ptr->m_brush; |
|
426 | return d_ptr->m_brush; | |
427 | } |
|
427 | } | |
428 |
|
428 | |||
429 | /*! |
|
429 | /*! | |
430 | Sets \a brush of the values that are drawn on top of this barset |
|
430 | Sets \a brush of the values that are drawn on top of this barset | |
431 | */ |
|
431 | */ | |
432 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
432 | void QBarSet::setLabelBrush(const QBrush &brush) | |
433 | { |
|
433 | { | |
434 | if(d_ptr->m_labelBrush!=brush){ |
|
434 | if(d_ptr->m_labelBrush!=brush){ | |
435 | d_ptr->m_labelBrush = brush; |
|
435 | d_ptr->m_labelBrush = brush; | |
436 | emit d_ptr->updatedBars(); |
|
436 | emit d_ptr->updatedBars(); | |
437 | emit labelBrushChanged(); |
|
437 | emit labelBrushChanged(); | |
438 | } |
|
438 | } | |
439 | } |
|
439 | } | |
440 |
|
440 | |||
441 | /*! |
|
441 | /*! | |
442 | Returns brush of the values that are drawn on top of this barset |
|
442 | Returns brush of the values that are drawn on top of this barset | |
443 | */ |
|
443 | */ | |
444 | QBrush QBarSet::labelBrush() const |
|
444 | QBrush QBarSet::labelBrush() const | |
445 | { |
|
445 | { | |
446 | return d_ptr->m_labelBrush; |
|
446 | return d_ptr->m_labelBrush; | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | /*! |
|
449 | /*! | |
450 | Sets the \a font for values that are drawn on top of this barset |
|
450 | Sets the \a font for values that are drawn on top of this barset | |
451 | */ |
|
451 | */ | |
452 | void QBarSet::setLabelFont(const QFont &font) |
|
452 | void QBarSet::setLabelFont(const QFont &font) | |
453 | { |
|
453 | { | |
454 | if(d_ptr->m_labelFont!=font) { |
|
454 | if(d_ptr->m_labelFont!=font) { | |
455 | d_ptr->m_labelFont = font; |
|
455 | d_ptr->m_labelFont = font; | |
456 | emit d_ptr->updatedBars(); |
|
456 | emit d_ptr->updatedBars(); | |
457 | emit labelFontChanged(); |
|
457 | emit labelFontChanged(); | |
458 | } |
|
458 | } | |
459 |
|
459 | |||
460 | } |
|
460 | } | |
461 |
|
461 | |||
462 | /*! |
|
462 | /*! | |
463 | Returns the pen for values that are drawn on top of this barset |
|
463 | Returns the pen for values that are drawn on top of this barset | |
464 | */ |
|
464 | */ | |
465 | QFont QBarSet::labelFont() const |
|
465 | QFont QBarSet::labelFont() const | |
466 | { |
|
466 | { | |
467 | return d_ptr->m_labelFont; |
|
467 | return d_ptr->m_labelFont; | |
468 | } |
|
468 | } | |
469 |
|
469 | |||
470 | /*! |
|
470 | /*! | |
471 | Returns the color of the brush of barset. |
|
471 | Returns the color of the brush of barset. | |
472 | */ |
|
472 | */ | |
473 | QColor QBarSet::color() |
|
473 | QColor QBarSet::color() | |
474 | { |
|
474 | { | |
475 | return brush().color(); |
|
475 | return brush().color(); | |
476 | } |
|
476 | } | |
477 |
|
477 | |||
478 | /*! |
|
478 | /*! | |
479 | Sets the \a color of brush for this barset |
|
479 | Sets the \a color of brush for this barset | |
480 | */ |
|
480 | */ | |
481 | void QBarSet::setColor(QColor color) |
|
481 | void QBarSet::setColor(QColor color) | |
482 | { |
|
482 | { | |
483 | QBrush b = brush(); |
|
483 | QBrush b = brush(); | |
484 | if (b.color() != color) { |
|
484 | if ((b.color() != color) || (b.style() == Qt::NoBrush)) { | |
485 | b.setColor(color); |
|
485 | b.setColor(color); | |
|
486 | if (b.style() == Qt::NoBrush) { | |||
|
487 | // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush) | |||
|
488 | // This prevents theme to override color defined in QML side: | |||
|
489 | // BarSet { label: "Bob"; color:"red"; values: [1,2,3] } | |||
|
490 | // The color must be obeyed, since user wanted it. | |||
|
491 | b.setStyle(Qt::SolidPattern); | |||
|
492 | } | |||
486 | setBrush(b); |
|
493 | setBrush(b); | |
487 | emit colorChanged(color); |
|
494 | emit colorChanged(color); | |
488 | } |
|
495 | } | |
489 | } |
|
496 | } | |
490 |
|
497 | |||
491 | /*! |
|
498 | /*! | |
492 | Returns the color of pen of this barset |
|
499 | Returns the color of pen of this barset | |
493 | */ |
|
500 | */ | |
494 | QColor QBarSet::borderColor() |
|
501 | QColor QBarSet::borderColor() | |
495 | { |
|
502 | { | |
496 | return pen().color(); |
|
503 | return pen().color(); | |
497 | } |
|
504 | } | |
498 |
|
505 | |||
499 | /*! |
|
506 | /*! | |
500 | Sets the color of pen for this barset |
|
507 | Sets the color of pen for this barset | |
501 | */ |
|
508 | */ | |
502 | void QBarSet::setBorderColor(QColor color) |
|
509 | void QBarSet::setBorderColor(QColor color) | |
503 | { |
|
510 | { | |
504 | QPen p = pen(); |
|
511 | QPen p = pen(); | |
505 | if (p.color() != color) { |
|
512 | if (p.color() != color) { | |
506 | p.setColor(color); |
|
513 | p.setColor(color); | |
507 | setPen(p); |
|
514 | setPen(p); | |
508 | emit borderColorChanged(color); |
|
515 | emit borderColorChanged(color); | |
509 | } |
|
516 | } | |
510 | } |
|
517 | } | |
511 |
|
518 | |||
512 | /*! |
|
519 | /*! | |
513 | Returns the color of labels of this barset |
|
520 | Returns the color of labels of this barset | |
514 | */ |
|
521 | */ | |
515 | QColor QBarSet::labelColor() |
|
522 | QColor QBarSet::labelColor() | |
516 | { |
|
523 | { | |
517 | return labelBrush().color(); |
|
524 | return labelBrush().color(); | |
518 | } |
|
525 | } | |
519 |
|
526 | |||
520 | /*! |
|
527 | /*! | |
521 | Sets the color of labels for this barset |
|
528 | Sets the color of labels for this barset | |
522 | */ |
|
529 | */ | |
523 | void QBarSet::setLabelColor(QColor color) |
|
530 | void QBarSet::setLabelColor(QColor color) | |
524 | { |
|
531 | { | |
525 | QBrush b = labelBrush(); |
|
532 | QBrush b = labelBrush(); | |
526 | if (b == QBrush()) |
|
533 | if (b == QBrush()) | |
527 | b.setStyle(Qt::SolidPattern); |
|
534 | b.setStyle(Qt::SolidPattern); | |
528 |
|
535 | |||
529 | if (b.color() != color) { |
|
536 | if (b.color() != color) { | |
530 | b.setColor(color); |
|
537 | b.setColor(color); | |
531 | setLabelBrush(b); |
|
538 | setLabelBrush(b); | |
532 | emit labelColorChanged(color); |
|
539 | emit labelColorChanged(color); | |
533 | } |
|
540 | } | |
534 | } |
|
541 | } | |
535 |
|
542 | |||
536 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
543 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
537 |
|
544 | |||
538 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
545 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
539 | q_ptr(parent), |
|
546 | q_ptr(parent), | |
540 | m_label(label) |
|
547 | m_label(label) | |
541 | { |
|
548 | { | |
542 | } |
|
549 | } | |
543 |
|
550 | |||
544 | QBarSetPrivate::~QBarSetPrivate() |
|
551 | QBarSetPrivate::~QBarSetPrivate() | |
545 | { |
|
552 | { | |
546 | } |
|
553 | } | |
547 |
|
554 | |||
548 | void QBarSetPrivate::append(QPointF value) |
|
555 | void QBarSetPrivate::append(QPointF value) | |
549 | { |
|
556 | { | |
550 | m_values.append(value); |
|
557 | m_values.append(value); | |
551 | emit restructuredBars(); |
|
558 | emit restructuredBars(); | |
552 | } |
|
559 | } | |
553 |
|
560 | |||
554 | void QBarSetPrivate::append(QList<QPointF> values) |
|
561 | void QBarSetPrivate::append(QList<QPointF> values) | |
555 | { |
|
562 | { | |
556 | for (int i=0; i<values.count(); i++) { |
|
563 | for (int i=0; i<values.count(); i++) { | |
557 | m_values.append(values.at(i)); |
|
564 | m_values.append(values.at(i)); | |
558 | } |
|
565 | } | |
559 | emit restructuredBars(); |
|
566 | emit restructuredBars(); | |
560 | } |
|
567 | } | |
561 |
|
568 | |||
562 | void QBarSetPrivate::append(QList<qreal> values) |
|
569 | void QBarSetPrivate::append(QList<qreal> values) | |
563 | { |
|
570 | { | |
564 | int index = m_values.count(); |
|
571 | int index = m_values.count(); | |
565 | for (int i=0; i<values.count(); i++) { |
|
572 | for (int i=0; i<values.count(); i++) { | |
566 | m_values.append(QPointF(index,values.at(i))); |
|
573 | m_values.append(QPointF(index,values.at(i))); | |
567 | index++; |
|
574 | index++; | |
568 | } |
|
575 | } | |
569 | emit restructuredBars(); |
|
576 | emit restructuredBars(); | |
570 | } |
|
577 | } | |
571 |
|
578 | |||
572 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
579 | void QBarSetPrivate::insert(const int index, const qreal value) | |
573 | { |
|
580 | { | |
574 | m_values.insert(index, QPointF(index, value)); |
|
581 | m_values.insert(index, QPointF(index, value)); | |
575 | emit restructuredBars(); |
|
582 | emit restructuredBars(); | |
576 | } |
|
583 | } | |
577 |
|
584 | |||
578 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
585 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
579 | { |
|
586 | { | |
580 | m_values.insert(index, value); |
|
587 | m_values.insert(index, value); | |
581 | emit restructuredBars(); |
|
588 | emit restructuredBars(); | |
582 | } |
|
589 | } | |
583 |
|
590 | |||
584 | int QBarSetPrivate::remove(const int index, const int count) |
|
591 | int QBarSetPrivate::remove(const int index, const int count) | |
585 | { |
|
592 | { | |
586 | int removeCount = count; |
|
593 | int removeCount = count; | |
587 |
|
594 | |||
588 | if ((index <0) || (m_values.count() == 0)) { |
|
595 | if ((index <0) || (m_values.count() == 0)) { | |
589 | // Invalid index or not values in list, remove nothing. |
|
596 | // Invalid index or not values in list, remove nothing. | |
590 | return 0; |
|
597 | return 0; | |
591 | } else if ((index + count) > m_values.count()) { |
|
598 | } else if ((index + count) > m_values.count()) { | |
592 | // Trying to remove more items than list has. Limit amount to be removed. |
|
599 | // Trying to remove more items than list has. Limit amount to be removed. | |
593 | removeCount = m_values.count() - index; |
|
600 | removeCount = m_values.count() - index; | |
594 | } |
|
601 | } | |
595 |
|
602 | |||
596 | int c = 0; |
|
603 | int c = 0; | |
597 | while (c < removeCount) { |
|
604 | while (c < removeCount) { | |
598 | m_values.removeAt(index); |
|
605 | m_values.removeAt(index); | |
599 | c++; |
|
606 | c++; | |
600 | } |
|
607 | } | |
601 | emit restructuredBars(); |
|
608 | emit restructuredBars(); | |
602 | return removeCount; |
|
609 | return removeCount; | |
603 | } |
|
610 | } | |
604 |
|
611 | |||
605 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
612 | void QBarSetPrivate::replace(const int index, const qreal value) | |
606 | { |
|
613 | { | |
607 | m_values.replace(index,QPointF(index,value)); |
|
614 | m_values.replace(index,QPointF(index,value)); | |
608 | emit updatedBars(); |
|
615 | emit updatedBars(); | |
609 | } |
|
616 | } | |
610 |
|
617 | |||
611 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
618 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
612 | { |
|
619 | { | |
613 | m_values.replace(index,value); |
|
620 | m_values.replace(index,value); | |
614 | emit updatedBars(); |
|
621 | emit updatedBars(); | |
615 | } |
|
622 | } | |
616 |
|
623 | |||
617 | qreal QBarSetPrivate::pos(const int index) |
|
624 | qreal QBarSetPrivate::pos(const int index) | |
618 | { |
|
625 | { | |
619 | if (index < 0 || index >= m_values.count()) { |
|
626 | if (index < 0 || index >= m_values.count()) { | |
620 | return 0; |
|
627 | return 0; | |
621 | } |
|
628 | } | |
622 |
|
629 | |||
623 | return m_values.at(index).x(); |
|
630 | return m_values.at(index).x(); | |
624 | } |
|
631 | } | |
625 |
|
632 | |||
626 | qreal QBarSetPrivate::value(const int index) |
|
633 | qreal QBarSetPrivate::value(const int index) | |
627 | { |
|
634 | { | |
628 | if (index < 0 || index >= m_values.count()) { |
|
635 | if (index < 0 || index >= m_values.count()) { | |
629 | return 0; |
|
636 | return 0; | |
630 | } |
|
637 | } | |
631 |
|
638 | |||
632 | return m_values.at(index).y(); |
|
639 | return m_values.at(index).y(); | |
633 | } |
|
640 | } | |
634 |
|
641 | |||
635 | #include "moc_qbarset.cpp" |
|
642 | #include "moc_qbarset.cpp" | |
636 | #include "moc_qbarset_p.cpp" |
|
643 | #include "moc_qbarset_p.cpp" | |
637 |
|
644 | |||
638 | QTCOMMERCIALCHART_END_NAMESPACE |
|
645 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now