@@ -1,635 +1,639 | |||||
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) { | |
485 | b.setColor(color); |
|
485 | b.setColor(color); | |
486 | setBrush(b); |
|
486 | setBrush(b); | |
487 | emit colorChanged(color); |
|
487 | emit colorChanged(color); | |
488 | } |
|
488 | } | |
489 | } |
|
489 | } | |
490 |
|
490 | |||
491 | /*! |
|
491 | /*! | |
492 | Returns the color of pen of this barset |
|
492 | Returns the color of pen of this barset | |
493 | */ |
|
493 | */ | |
494 | QColor QBarSet::borderColor() |
|
494 | QColor QBarSet::borderColor() | |
495 | { |
|
495 | { | |
496 | return pen().color(); |
|
496 | return pen().color(); | |
497 | } |
|
497 | } | |
498 |
|
498 | |||
499 | /*! |
|
499 | /*! | |
500 | Sets the color of pen for this barset |
|
500 | Sets the color of pen for this barset | |
501 | */ |
|
501 | */ | |
502 | void QBarSet::setBorderColor(QColor color) |
|
502 | void QBarSet::setBorderColor(QColor color) | |
503 | { |
|
503 | { | |
504 | QPen p = pen(); |
|
504 | QPen p = pen(); | |
505 | if (p.color() != color) { |
|
505 | if (p.color() != color) { | |
506 | p.setColor(color); |
|
506 | p.setColor(color); | |
507 | setPen(p); |
|
507 | setPen(p); | |
508 | emit borderColorChanged(color); |
|
508 | emit borderColorChanged(color); | |
509 | } |
|
509 | } | |
510 | } |
|
510 | } | |
511 |
|
511 | |||
512 | /*! |
|
512 | /*! | |
513 | Returns the color of labels of this barset |
|
513 | Returns the color of labels of this barset | |
514 | */ |
|
514 | */ | |
515 | QColor QBarSet::labelColor() |
|
515 | QColor QBarSet::labelColor() | |
516 | { |
|
516 | { | |
517 | return labelBrush().color(); |
|
517 | return labelBrush().color(); | |
518 | } |
|
518 | } | |
519 |
|
519 | |||
520 | /*! |
|
520 | /*! | |
521 | Sets the color of labels for this barset |
|
521 | Sets the color of labels for this barset | |
522 | */ |
|
522 | */ | |
523 | void QBarSet::setLabelColor(QColor color) |
|
523 | void QBarSet::setLabelColor(QColor color) | |
524 | { |
|
524 | { | |
|
525 | QBrush defaultBrush; | |||
525 | QBrush b = labelBrush(); |
|
526 | QBrush b = labelBrush(); | |
|
527 | if (b == defaultBrush) | |||
|
528 | b.setStyle(Qt::SolidPattern); | |||
|
529 | ||||
526 | if (b.color() != color) { |
|
530 | if (b.color() != color) { | |
527 | b.setColor(color); |
|
531 | b.setColor(color); | |
528 | setLabelBrush(b); |
|
532 | setLabelBrush(b); | |
529 | emit labelColorChanged(color); |
|
533 | emit labelColorChanged(color); | |
530 | } |
|
534 | } | |
531 | } |
|
535 | } | |
532 |
|
536 | |||
533 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
537 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
534 |
|
538 | |||
535 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
539 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), | |
536 | q_ptr(parent), |
|
540 | q_ptr(parent), | |
537 | m_label(label) |
|
541 | m_label(label) | |
538 | { |
|
542 | { | |
539 | } |
|
543 | } | |
540 |
|
544 | |||
541 | QBarSetPrivate::~QBarSetPrivate() |
|
545 | QBarSetPrivate::~QBarSetPrivate() | |
542 | { |
|
546 | { | |
543 | } |
|
547 | } | |
544 |
|
548 | |||
545 | void QBarSetPrivate::append(QPointF value) |
|
549 | void QBarSetPrivate::append(QPointF value) | |
546 | { |
|
550 | { | |
547 | m_values.append(value); |
|
551 | m_values.append(value); | |
548 | emit restructuredBars(); |
|
552 | emit restructuredBars(); | |
549 | } |
|
553 | } | |
550 |
|
554 | |||
551 | void QBarSetPrivate::append(QList<QPointF> values) |
|
555 | void QBarSetPrivate::append(QList<QPointF> values) | |
552 | { |
|
556 | { | |
553 | for (int i=0; i<values.count(); i++) { |
|
557 | for (int i=0; i<values.count(); i++) { | |
554 | m_values.append(values.at(i)); |
|
558 | m_values.append(values.at(i)); | |
555 | } |
|
559 | } | |
556 | emit restructuredBars(); |
|
560 | emit restructuredBars(); | |
557 | } |
|
561 | } | |
558 |
|
562 | |||
559 | void QBarSetPrivate::append(QList<qreal> values) |
|
563 | void QBarSetPrivate::append(QList<qreal> values) | |
560 | { |
|
564 | { | |
561 | int index = m_values.count(); |
|
565 | int index = m_values.count(); | |
562 | for (int i=0; i<values.count(); i++) { |
|
566 | for (int i=0; i<values.count(); i++) { | |
563 | m_values.append(QPointF(index,values.at(i))); |
|
567 | m_values.append(QPointF(index,values.at(i))); | |
564 | index++; |
|
568 | index++; | |
565 | } |
|
569 | } | |
566 | emit restructuredBars(); |
|
570 | emit restructuredBars(); | |
567 | } |
|
571 | } | |
568 |
|
572 | |||
569 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
573 | void QBarSetPrivate::insert(const int index, const qreal value) | |
570 | { |
|
574 | { | |
571 | m_values.insert(index, QPointF(index, value)); |
|
575 | m_values.insert(index, QPointF(index, value)); | |
572 | emit restructuredBars(); |
|
576 | emit restructuredBars(); | |
573 | } |
|
577 | } | |
574 |
|
578 | |||
575 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
579 | void QBarSetPrivate::insert(const int index, const QPointF value) | |
576 | { |
|
580 | { | |
577 | m_values.insert(index, value); |
|
581 | m_values.insert(index, value); | |
578 | emit restructuredBars(); |
|
582 | emit restructuredBars(); | |
579 | } |
|
583 | } | |
580 |
|
584 | |||
581 | int QBarSetPrivate::remove(const int index, const int count) |
|
585 | int QBarSetPrivate::remove(const int index, const int count) | |
582 | { |
|
586 | { | |
583 | int removeCount = count; |
|
587 | int removeCount = count; | |
584 |
|
588 | |||
585 | if ((index <0) || (m_values.count() == 0)) { |
|
589 | if ((index <0) || (m_values.count() == 0)) { | |
586 | // Invalid index or not values in list, remove nothing. |
|
590 | // Invalid index or not values in list, remove nothing. | |
587 | return 0; |
|
591 | return 0; | |
588 | } else if ((index + count) > m_values.count()) { |
|
592 | } else if ((index + count) > m_values.count()) { | |
589 | // Trying to remove more items than list has. Limit amount to be removed. |
|
593 | // Trying to remove more items than list has. Limit amount to be removed. | |
590 | removeCount = m_values.count() - index; |
|
594 | removeCount = m_values.count() - index; | |
591 | } |
|
595 | } | |
592 |
|
596 | |||
593 | int c = 0; |
|
597 | int c = 0; | |
594 | while (c < removeCount) { |
|
598 | while (c < removeCount) { | |
595 | m_values.removeAt(index); |
|
599 | m_values.removeAt(index); | |
596 | c++; |
|
600 | c++; | |
597 | } |
|
601 | } | |
598 | emit restructuredBars(); |
|
602 | emit restructuredBars(); | |
599 | return removeCount; |
|
603 | return removeCount; | |
600 | } |
|
604 | } | |
601 |
|
605 | |||
602 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
606 | void QBarSetPrivate::replace(const int index, const qreal value) | |
603 | { |
|
607 | { | |
604 | m_values.replace(index,QPointF(index,value)); |
|
608 | m_values.replace(index,QPointF(index,value)); | |
605 | emit updatedBars(); |
|
609 | emit updatedBars(); | |
606 | } |
|
610 | } | |
607 |
|
611 | |||
608 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
612 | void QBarSetPrivate::replace(const int index, const QPointF value) | |
609 | { |
|
613 | { | |
610 | m_values.replace(index,value); |
|
614 | m_values.replace(index,value); | |
611 | emit updatedBars(); |
|
615 | emit updatedBars(); | |
612 | } |
|
616 | } | |
613 |
|
617 | |||
614 | qreal QBarSetPrivate::pos(const int index) |
|
618 | qreal QBarSetPrivate::pos(const int index) | |
615 | { |
|
619 | { | |
616 | if (index < 0 || index >= m_values.count()) { |
|
620 | if (index < 0 || index >= m_values.count()) { | |
617 | return 0; |
|
621 | return 0; | |
618 | } |
|
622 | } | |
619 |
|
623 | |||
620 | return m_values.at(index).x(); |
|
624 | return m_values.at(index).x(); | |
621 | } |
|
625 | } | |
622 |
|
626 | |||
623 | qreal QBarSetPrivate::value(const int index) |
|
627 | qreal QBarSetPrivate::value(const int index) | |
624 | { |
|
628 | { | |
625 | if (index < 0 || index >= m_values.count()) { |
|
629 | if (index < 0 || index >= m_values.count()) { | |
626 | return 0; |
|
630 | return 0; | |
627 | } |
|
631 | } | |
628 |
|
632 | |||
629 | return m_values.at(index).y(); |
|
633 | return m_values.at(index).y(); | |
630 | } |
|
634 | } | |
631 |
|
635 | |||
632 | #include "moc_qbarset.cpp" |
|
636 | #include "moc_qbarset.cpp" | |
633 | #include "moc_qbarset_p.cpp" |
|
637 | #include "moc_qbarset_p.cpp" | |
634 |
|
638 | |||
635 | QTCOMMERCIALCHART_END_NAMESPACE |
|
639 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,391 +1,393 | |||||
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 "charttheme_p.h" |
|
21 | #include "charttheme_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qchart_p.h" |
|
23 | #include "qchart_p.h" | |
24 | #include "qchartview.h" |
|
24 | #include "qchartview.h" | |
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 | #include "qabstractaxis.h" |
|
26 | #include "qabstractaxis.h" | |
27 | #include <QTime> |
|
27 | #include <QTime> | |
28 |
|
28 | |||
29 | //series |
|
29 | //series | |
30 | #include "qbarset.h" |
|
30 | #include "qbarset.h" | |
31 | #include "qabstractbarseries.h" |
|
31 | #include "qabstractbarseries.h" | |
32 | #include "qstackedbarseries.h" |
|
32 | #include "qstackedbarseries.h" | |
33 | #include "qpercentbarseries.h" |
|
33 | #include "qpercentbarseries.h" | |
34 | #include "qlineseries.h" |
|
34 | #include "qlineseries.h" | |
35 | #include "qareaseries.h" |
|
35 | #include "qareaseries.h" | |
36 | #include "qscatterseries.h" |
|
36 | #include "qscatterseries.h" | |
37 | #include "qpieseries.h" |
|
37 | #include "qpieseries.h" | |
38 | #include "qpieslice.h" |
|
38 | #include "qpieslice.h" | |
39 | #include "qpieslice_p.h" |
|
39 | #include "qpieslice_p.h" | |
40 | #include "qsplineseries.h" |
|
40 | #include "qsplineseries.h" | |
41 |
|
41 | |||
42 | //items |
|
42 | //items | |
43 | #include "chartaxis_p.h" |
|
43 | #include "chartaxis_p.h" | |
44 | #include "abstractbarchartitem_p.h" |
|
44 | #include "abstractbarchartitem_p.h" | |
45 | #include "stackedbarchartitem_p.h" |
|
45 | #include "stackedbarchartitem_p.h" | |
46 | #include "percentbarchartitem_p.h" |
|
46 | #include "percentbarchartitem_p.h" | |
47 | #include "linechartitem_p.h" |
|
47 | #include "linechartitem_p.h" | |
48 | #include "areachartitem_p.h" |
|
48 | #include "areachartitem_p.h" | |
49 | #include "scatterchartitem_p.h" |
|
49 | #include "scatterchartitem_p.h" | |
50 | #include "piechartitem_p.h" |
|
50 | #include "piechartitem_p.h" | |
51 | #include "splinechartitem_p.h" |
|
51 | #include "splinechartitem_p.h" | |
52 |
|
52 | |||
53 | //themes |
|
53 | //themes | |
54 | #include "chartthemesystem_p.h" |
|
54 | #include "chartthemesystem_p.h" | |
55 | #include "chartthemelight_p.h" |
|
55 | #include "chartthemelight_p.h" | |
56 | #include "chartthemebluecerulean_p.h" |
|
56 | #include "chartthemebluecerulean_p.h" | |
57 | #include "chartthemedark_p.h" |
|
57 | #include "chartthemedark_p.h" | |
58 | #include "chartthemebrownsand_p.h" |
|
58 | #include "chartthemebrownsand_p.h" | |
59 | #include "chartthemebluencs_p.h" |
|
59 | #include "chartthemebluencs_p.h" | |
60 | #include "chartthemehighcontrast_p.h" |
|
60 | #include "chartthemehighcontrast_p.h" | |
61 | #include "chartthemeblueicy_p.h" |
|
61 | #include "chartthemeblueicy_p.h" | |
62 |
|
62 | |||
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
64 |
|
64 | |||
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : | |
66 | m_masterFont(QFont("arial", 14)), |
|
66 | m_masterFont(QFont("arial", 14)), | |
67 | m_labelFont(QFont("arial", 10)), |
|
67 | m_labelFont(QFont("arial", 10)), | |
68 | m_labelBrush(QColor(QRgb(0x000000))), |
|
68 | m_labelBrush(QColor(QRgb(0x000000))), | |
69 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
69 | m_axisLinePen(QPen(QRgb(0x000000))), | |
70 | m_backgroundShadesPen(Qt::NoPen), |
|
70 | m_backgroundShadesPen(Qt::NoPen), | |
71 | m_backgroundShadesBrush(Qt::NoBrush), |
|
71 | m_backgroundShadesBrush(Qt::NoBrush), | |
72 | m_backgroundShades(BackgroundShadesNone), |
|
72 | m_backgroundShades(BackgroundShadesNone), | |
73 | m_backgroundDropShadowEnabled(false), |
|
73 | m_backgroundDropShadowEnabled(false), | |
74 | m_gridLinePen(QPen(QRgb(0x000000))), |
|
74 | m_gridLinePen(QPen(QRgb(0x000000))), | |
75 | m_force(false) |
|
75 | m_force(false) | |
76 | { |
|
76 | { | |
77 | m_id = id; |
|
77 | m_id = id; | |
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); | |
79 | } |
|
79 | } | |
80 |
|
80 | |||
81 |
|
81 | |||
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) | |
83 | { |
|
83 | { | |
84 | switch(theme) { |
|
84 | switch(theme) { | |
85 |
|
|
85 | case QChart::ChartThemeLight: | |
86 |
|
|
86 | return new ChartThemeLight(); | |
87 |
|
|
87 | case QChart::ChartThemeBlueCerulean: | |
88 |
|
|
88 | return new ChartThemeBlueCerulean(); | |
89 |
|
|
89 | case QChart::ChartThemeDark: | |
90 |
|
|
90 | return new ChartThemeDark(); | |
91 |
|
|
91 | case QChart::ChartThemeBrownSand: | |
92 |
|
|
92 | return new ChartThemeBrownSand(); | |
93 |
|
|
93 | case QChart::ChartThemeBlueNcs: | |
94 |
|
|
94 | return new ChartThemeBlueNcs(); | |
95 |
|
|
95 | case QChart::ChartThemeHighContrast: | |
96 |
|
|
96 | return new ChartThemeHighContrast(); | |
97 |
|
|
97 | case QChart::ChartThemeBlueIcy: | |
98 |
|
|
98 | return new ChartThemeBlueIcy(); | |
99 |
|
|
99 | default: | |
100 |
|
|
100 | return new ChartThemeSystem(); | |
101 | } |
|
101 | } | |
102 | } |
|
102 | } | |
103 |
|
103 | |||
104 | void ChartTheme::decorate(QChart *chart) |
|
104 | void ChartTheme::decorate(QChart *chart) | |
105 | { |
|
105 | { | |
106 | QBrush brush; |
|
106 | QBrush brush; | |
107 |
|
107 | |||
108 | if(brush == chart->backgroundBrush() || m_force) |
|
108 | if(brush == chart->backgroundBrush() || m_force) | |
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
109 | chart->setBackgroundBrush(m_chartBackgroundGradient); | |
110 | chart->setTitleFont(m_masterFont); |
|
110 | chart->setTitleFont(m_masterFont); | |
111 | chart->setTitleBrush(m_labelBrush); |
|
111 | chart->setTitleBrush(m_labelBrush); | |
112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); |
|
112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); | |
113 | } |
|
113 | } | |
114 |
|
114 | |||
115 | void ChartTheme::decorate(QLegend *legend) |
|
115 | void ChartTheme::decorate(QLegend *legend) | |
116 | { |
|
116 | { | |
117 | QPen pen; |
|
117 | QPen pen; | |
118 | QBrush brush; |
|
118 | QBrush brush; | |
119 | QFont font; |
|
119 | QFont font; | |
120 |
|
120 | |||
121 | if (pen == legend->pen() || m_force) |
|
121 | if (pen == legend->pen() || m_force) | |
122 | legend->setPen(m_axisLinePen); |
|
122 | legend->setPen(m_axisLinePen); | |
123 |
|
123 | |||
124 | if (brush == legend->brush() || m_force) |
|
124 | if (brush == legend->brush() || m_force) | |
125 | legend->setBrush(m_chartBackgroundGradient); |
|
125 | legend->setBrush(m_chartBackgroundGradient); | |
126 |
|
126 | |||
127 | if (font == legend->font() || m_force) |
|
127 | if (font == legend->font() || m_force) | |
128 | legend->setFont(m_labelFont); |
|
128 | legend->setFont(m_labelFont); | |
129 |
|
129 | |||
130 | if (brush == legend->labelBrush() || m_force) |
|
130 | if (brush == legend->labelBrush() || m_force) | |
131 | legend->setLabelBrush(m_labelBrush); |
|
131 | legend->setLabelBrush(m_labelBrush); | |
132 | } |
|
132 | } | |
133 |
|
133 | |||
134 | void ChartTheme::decorate(QAreaSeries *series, int index) |
|
134 | void ChartTheme::decorate(QAreaSeries *series, int index) | |
135 | { |
|
135 | { | |
136 | QPen pen; |
|
136 | QPen pen; | |
137 | QBrush brush; |
|
137 | QBrush brush; | |
138 |
|
138 | |||
139 | if (pen == series->pen() || m_force){ |
|
139 | if (pen == series->pen() || m_force){ | |
140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
141 | pen.setWidthF(2); |
|
141 | pen.setWidthF(2); | |
142 | series->setPen(pen); |
|
142 | series->setPen(pen); | |
143 | } |
|
143 | } | |
144 |
|
144 | |||
145 | if (brush == series->brush() || m_force) { |
|
145 | if (brush == series->brush() || m_force) { | |
146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
147 | series->setBrush(brush); |
|
147 | series->setBrush(brush); | |
148 | } |
|
148 | } | |
149 | } |
|
149 | } | |
150 |
|
150 | |||
151 |
|
151 | |||
152 | void ChartTheme::decorate(QLineSeries *series,int index) |
|
152 | void ChartTheme::decorate(QLineSeries *series,int index) | |
153 | { |
|
153 | { | |
154 | QPen pen; |
|
154 | QPen pen; | |
155 | if(pen == series->pen() || m_force ){ |
|
155 | if(pen == series->pen() || m_force ){ | |
156 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
156 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
157 | pen.setWidthF(2); |
|
157 | pen.setWidthF(2); | |
158 | series->setPen(pen); |
|
158 | series->setPen(pen); | |
159 | } |
|
159 | } | |
160 | } |
|
160 | } | |
161 |
|
161 | |||
162 | void ChartTheme::decorate(QAbstractBarSeries *series, int index) |
|
162 | void ChartTheme::decorate(QAbstractBarSeries *series, int index) | |
163 | { |
|
163 | { | |
164 | QBrush brush; |
|
164 | QBrush brush; | |
165 | QPen pen; |
|
165 | QPen pen; | |
166 | QList<QBarSet *> sets = series->barSets(); |
|
166 | QList<QBarSet *> sets = series->barSets(); | |
167 |
|
167 | |||
168 | qreal takeAtPos = 0.5; |
|
168 | qreal takeAtPos = 0.5; | |
169 | qreal step = 0.2; |
|
169 | qreal step = 0.2; | |
170 | if (sets.count() > 1 ) { |
|
170 | if (sets.count() > 1 ) { | |
171 | step = 1.0 / (qreal) sets.count(); |
|
171 | step = 1.0 / (qreal) sets.count(); | |
172 | if (sets.count() % m_seriesGradients.count()) |
|
172 | if (sets.count() % m_seriesGradients.count()) | |
173 | step *= m_seriesGradients.count(); |
|
173 | step *= m_seriesGradients.count(); | |
174 | else |
|
174 | else | |
175 | step *= (m_seriesGradients.count() - 1); |
|
175 | step *= (m_seriesGradients.count() - 1); | |
176 | } |
|
176 | } | |
177 |
|
177 | |||
178 | for (int i(0); i < sets.count(); i++) { |
|
178 | for (int i(0); i < sets.count(); i++) { | |
179 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
179 | int colorIndex = (index + i) % m_seriesGradients.count(); | |
180 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
180 | if (i > 0 && i % m_seriesGradients.count() == 0) { | |
181 | // There is no dedicated base color for each sets, generate more colors |
|
181 | // There is no dedicated base color for each sets, generate more colors | |
182 | takeAtPos += step; |
|
182 | takeAtPos += step; | |
183 | if (takeAtPos == 1.0) |
|
183 | if (takeAtPos == 1.0) | |
184 | takeAtPos += step; |
|
184 | takeAtPos += step; | |
185 | takeAtPos -= (int) takeAtPos; |
|
185 | takeAtPos -= (int) takeAtPos; | |
186 | } |
|
186 | } | |
187 | if (brush == sets.at(i)->brush() || m_force ) |
|
187 | if (brush == sets.at(i)->brush() || m_force ) | |
188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); | |
189 |
|
189 | |||
190 | // Pick label color from the opposite end of the gradient. |
|
190 | // Pick label color from the opposite end of the gradient. | |
191 | // 0.3 as a boundary seems to work well. |
|
191 | // 0.3 as a boundary seems to work well. | |
192 | if (takeAtPos < 0.3) |
|
192 | if (brush == sets.at(i)->labelBrush() || m_force) { | |
193 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
193 | if (takeAtPos < 0.3) | |
194 | else |
|
194 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
195 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
195 | else | |
|
196 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |||
|
197 | } | |||
196 |
|
198 | |||
197 | if (pen == sets.at(i)->pen() || m_force) { |
|
199 | if (pen == sets.at(i)->pen() || m_force) { | |
198 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
200 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
199 | sets.at(i)->setPen(c); |
|
201 | sets.at(i)->setPen(c); | |
200 | } |
|
202 | } | |
201 | } |
|
203 | } | |
202 | } |
|
204 | } | |
203 |
|
205 | |||
204 | void ChartTheme::decorate(QScatterSeries *series, int index) |
|
206 | void ChartTheme::decorate(QScatterSeries *series, int index) | |
205 | { |
|
207 | { | |
206 | QPen pen; |
|
208 | QPen pen; | |
207 | QBrush brush; |
|
209 | QBrush brush; | |
208 |
|
210 | |||
209 | if (pen == series->pen() || m_force) { |
|
211 | if (pen == series->pen() || m_force) { | |
210 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
212 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
211 | pen.setWidthF(2); |
|
213 | pen.setWidthF(2); | |
212 | series->setPen(pen); |
|
214 | series->setPen(pen); | |
213 | } |
|
215 | } | |
214 |
|
216 | |||
215 | if (brush == series->brush() || m_force) { |
|
217 | if (brush == series->brush() || m_force) { | |
216 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
218 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); | |
217 | series->setBrush(brush); |
|
219 | series->setBrush(brush); | |
218 | } |
|
220 | } | |
219 | } |
|
221 | } | |
220 |
|
222 | |||
221 | void ChartTheme::decorate(QPieSeries *series, int index) |
|
223 | void ChartTheme::decorate(QPieSeries *series, int index) | |
222 | { |
|
224 | { | |
223 |
|
225 | |||
224 | for (int i(0); i < series->slices().count(); i++) { |
|
226 | for (int i(0); i < series->slices().count(); i++) { | |
225 |
|
227 | |||
226 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
228 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
227 |
|
229 | |||
228 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
230 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
229 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
231 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); | |
230 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
232 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
231 |
|
233 | |||
232 | QPieSlice *s = series->slices().at(i); |
|
234 | QPieSlice *s = series->slices().at(i); | |
233 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
235 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); | |
234 |
|
236 | |||
235 | if (d->m_data.m_slicePen.isThemed() || m_force) |
|
237 | if (d->m_data.m_slicePen.isThemed() || m_force) | |
236 | d->setPen(penColor, true); |
|
238 | d->setPen(penColor, true); | |
237 |
|
239 | |||
238 | if (d->m_data.m_sliceBrush.isThemed() || m_force) |
|
240 | if (d->m_data.m_sliceBrush.isThemed() || m_force) | |
239 | d->setBrush(brushColor, true); |
|
241 | d->setBrush(brushColor, true); | |
240 |
|
242 | |||
241 | if (d->m_data.m_labelBrush.isThemed() || m_force) |
|
243 | if (d->m_data.m_labelBrush.isThemed() || m_force) | |
242 | d->setLabelBrush(m_labelBrush.color(), true); |
|
244 | d->setLabelBrush(m_labelBrush.color(), true); | |
243 |
|
245 | |||
244 | if (d->m_data.m_labelFont.isThemed() || m_force) |
|
246 | if (d->m_data.m_labelFont.isThemed() || m_force) | |
245 | d->setLabelFont(m_labelFont, true); |
|
247 | d->setLabelFont(m_labelFont, true); | |
246 | } |
|
248 | } | |
247 | } |
|
249 | } | |
248 |
|
250 | |||
249 | void ChartTheme::decorate(QSplineSeries *series, int index) |
|
251 | void ChartTheme::decorate(QSplineSeries *series, int index) | |
250 | { |
|
252 | { | |
251 | QPen pen; |
|
253 | QPen pen; | |
252 | if(pen == series->pen() || m_force){ |
|
254 | if(pen == series->pen() || m_force){ | |
253 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
255 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); | |
254 | pen.setWidthF(2); |
|
256 | pen.setWidthF(2); | |
255 | series->setPen(pen); |
|
257 | series->setPen(pen); | |
256 | } |
|
258 | } | |
257 | } |
|
259 | } | |
258 |
|
260 | |||
259 | void ChartTheme::decorate(QAbstractAxis *axis) |
|
261 | void ChartTheme::decorate(QAbstractAxis *axis) | |
260 | { |
|
262 | { | |
261 | QPen pen; |
|
263 | QPen pen; | |
262 | QBrush brush; |
|
264 | QBrush brush; | |
263 | QFont font; |
|
265 | QFont font; | |
264 |
|
266 | |||
265 | bool axisX = axis->orientation()== Qt::Horizontal; |
|
267 | bool axisX = axis->orientation()== Qt::Horizontal; | |
266 |
|
268 | |||
267 | if (axis->isArrowVisible()) { |
|
269 | if (axis->isArrowVisible()) { | |
268 |
|
270 | |||
269 | if(brush == axis->labelsBrush() || m_force){ |
|
271 | if(brush == axis->labelsBrush() || m_force){ | |
270 | axis->setLabelsBrush(m_labelBrush); |
|
272 | axis->setLabelsBrush(m_labelBrush); | |
271 | } |
|
273 | } | |
272 | if(pen == axis->labelsPen() || m_force){ |
|
274 | if(pen == axis->labelsPen() || m_force){ | |
273 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
275 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons | |
274 | } |
|
276 | } | |
275 |
|
277 | |||
276 |
|
278 | |||
277 | if (axis->shadesVisible() || m_force) { |
|
279 | if (axis->shadesVisible() || m_force) { | |
278 |
|
280 | |||
279 | if(brush == axis->shadesBrush() || m_force){ |
|
281 | if(brush == axis->shadesBrush() || m_force){ | |
280 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
282 | axis->setShadesBrush(m_backgroundShadesBrush); | |
281 | } |
|
283 | } | |
282 |
|
284 | |||
283 | if(pen == axis->shadesPen() || m_force){ |
|
285 | if(pen == axis->shadesPen() || m_force){ | |
284 | axis->setShadesPen(m_backgroundShadesPen); |
|
286 | axis->setShadesPen(m_backgroundShadesPen); | |
285 | } |
|
287 | } | |
286 |
|
288 | |||
287 | if( m_force && (m_backgroundShades == BackgroundShadesBoth |
|
289 | if( m_force && (m_backgroundShades == BackgroundShadesBoth | |
288 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
290 | || (m_backgroundShades == BackgroundShadesVertical && axisX) | |
289 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
291 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ | |
290 | axis->setShadesVisible(true); |
|
292 | axis->setShadesVisible(true); | |
291 |
|
293 | |||
292 | } |
|
294 | } | |
293 | } |
|
295 | } | |
294 |
|
296 | |||
295 | if(pen == axis->axisPen() || m_force){ |
|
297 | if(pen == axis->axisPen() || m_force){ | |
296 | axis->setAxisPen(m_axisLinePen); |
|
298 | axis->setAxisPen(m_axisLinePen); | |
297 | } |
|
299 | } | |
298 |
|
300 | |||
299 | if(pen == axis->gridLinePen() || m_force){ |
|
301 | if(pen == axis->gridLinePen() || m_force){ | |
300 | axis->setGridLinePen(m_gridLinePen); |
|
302 | axis->setGridLinePen(m_gridLinePen); | |
301 | } |
|
303 | } | |
302 |
|
304 | |||
303 | if(font == axis->labelsFont() || m_force){ |
|
305 | if(font == axis->labelsFont() || m_force){ | |
304 | axis->setLabelsFont(m_labelFont); |
|
306 | axis->setLabelsFont(m_labelFont); | |
305 | } |
|
307 | } | |
306 | } |
|
308 | } | |
307 | } |
|
309 | } | |
308 |
|
310 | |||
309 | void ChartTheme::generateSeriesGradients() |
|
311 | void ChartTheme::generateSeriesGradients() | |
310 | { |
|
312 | { | |
311 | // Generate gradients in HSV color space |
|
313 | // Generate gradients in HSV color space | |
312 | foreach (const QColor& color, m_seriesColors) { |
|
314 | foreach (const QColor& color, m_seriesColors) { | |
313 | QLinearGradient g; |
|
315 | QLinearGradient g; | |
314 | qreal h = color.hsvHueF(); |
|
316 | qreal h = color.hsvHueF(); | |
315 | qreal s = color.hsvSaturationF(); |
|
317 | qreal s = color.hsvSaturationF(); | |
316 |
|
318 | |||
317 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
319 | // TODO: tune the algorithm to give nice results with most base colors defined in | |
318 | // most themes. The rest of the gradients we can define manually in theme specific |
|
320 | // most themes. The rest of the gradients we can define manually in theme specific | |
319 | // implementation. |
|
321 | // implementation. | |
320 | QColor start = color; |
|
322 | QColor start = color; | |
321 | start.setHsvF(h, 0.0, 1.0); |
|
323 | start.setHsvF(h, 0.0, 1.0); | |
322 | g.setColorAt(0.0, start); |
|
324 | g.setColorAt(0.0, start); | |
323 |
|
325 | |||
324 | g.setColorAt(0.5, color); |
|
326 | g.setColorAt(0.5, color); | |
325 |
|
327 | |||
326 | QColor end = color; |
|
328 | QColor end = color; | |
327 | end.setHsvF(h, s, 0.25); |
|
329 | end.setHsvF(h, s, 0.25); | |
328 | g.setColorAt(1.0, end); |
|
330 | g.setColorAt(1.0, end); | |
329 |
|
331 | |||
330 | m_seriesGradients << g; |
|
332 | m_seriesGradients << g; | |
331 | } |
|
333 | } | |
332 | } |
|
334 | } | |
333 |
|
335 | |||
334 |
|
336 | |||
335 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
337 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) | |
336 | { |
|
338 | { | |
337 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
339 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); | |
338 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
340 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); | |
339 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
341 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); | |
340 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
342 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); | |
341 | QColor c; |
|
343 | QColor c; | |
342 | c.setRgbF(r, g, b); |
|
344 | c.setRgbF(r, g, b); | |
343 | return c; |
|
345 | return c; | |
344 | } |
|
346 | } | |
345 |
|
347 | |||
346 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
348 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) | |
347 | { |
|
349 | { | |
348 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
350 | Q_ASSERT(pos >= 0 && pos <= 1.0); | |
349 |
|
351 | |||
350 | QGradientStops stops = gradient.stops(); |
|
352 | QGradientStops stops = gradient.stops(); | |
351 | int count = stops.count(); |
|
353 | int count = stops.count(); | |
352 |
|
354 | |||
353 | // find previous stop relative to position |
|
355 | // find previous stop relative to position | |
354 | QGradientStop prev = stops.first(); |
|
356 | QGradientStop prev = stops.first(); | |
355 | for (int i = 0; i < count; i++) { |
|
357 | for (int i = 0; i < count; i++) { | |
356 | QGradientStop stop = stops.at(i); |
|
358 | QGradientStop stop = stops.at(i); | |
357 | if (pos > stop.first) |
|
359 | if (pos > stop.first) | |
358 | prev = stop; |
|
360 | prev = stop; | |
359 |
|
361 | |||
360 | // given position is actually a stop position? |
|
362 | // given position is actually a stop position? | |
361 | if (pos == stop.first) { |
|
363 | if (pos == stop.first) { | |
362 | //qDebug() << "stop color" << pos; |
|
364 | //qDebug() << "stop color" << pos; | |
363 | return stop.second; |
|
365 | return stop.second; | |
364 | } |
|
366 | } | |
365 | } |
|
367 | } | |
366 |
|
368 | |||
367 | // find next stop relative to position |
|
369 | // find next stop relative to position | |
368 | QGradientStop next = stops.last(); |
|
370 | QGradientStop next = stops.last(); | |
369 | for (int i = count - 1; i >= 0; i--) { |
|
371 | for (int i = count - 1; i >= 0; i--) { | |
370 | QGradientStop stop = stops.at(i); |
|
372 | QGradientStop stop = stops.at(i); | |
371 | if (pos < stop.first) |
|
373 | if (pos < stop.first) | |
372 | next = stop; |
|
374 | next = stop; | |
373 | } |
|
375 | } | |
374 |
|
376 | |||
375 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
377 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; | |
376 |
|
378 | |||
377 | qreal range = next.first - prev.first; |
|
379 | qreal range = next.first - prev.first; | |
378 | qreal posDelta = pos - prev.first; |
|
380 | qreal posDelta = pos - prev.first; | |
379 | qreal relativePos = posDelta / range; |
|
381 | qreal relativePos = posDelta / range; | |
380 |
|
382 | |||
381 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
383 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; | |
382 |
|
384 | |||
383 | return colorAt(prev.second, next.second, relativePos); |
|
385 | return colorAt(prev.second, next.second, relativePos); | |
384 | } |
|
386 | } | |
385 |
|
387 | |||
386 | void ChartTheme::setForced(bool enabled) |
|
388 | void ChartTheme::setForced(bool enabled) | |
387 | { |
|
389 | { | |
388 | m_force=enabled; |
|
390 | m_force=enabled; | |
389 | } |
|
391 | } | |
390 |
|
392 | |||
391 | QTCOMMERCIALCHART_END_NAMESPACE |
|
393 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now