##// END OF EJS Templates
Fix...
Mika Salmela -
r2518:04911b229610
parent child
Show More
@@ -1,493 +1,493
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2013 Digia Plc
3 ** Copyright (C) 2013 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qboxset.h"
21 #include "qboxset.h"
22 #include "qboxset_p.h"
22 #include "qboxset_p.h"
23 #include "charthelpers_p.h"
23 #include "charthelpers_p.h"
24
24
25 #include <QDebug> //TODO: remove on release
25 #include <QDebug> //TODO: remove on release
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
29 /*!
30 \class QBoxSet
30 \class QBoxSet
31 \brief Building block for box-and-whiskers chart
31 \brief Building block for box-and-whiskers chart
32
32
33 QBoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
33 QBoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
34 of range and three medians. There's two type of methods to give the values. The first one is with constructor
34 of range and three medians. There's two type of methods to give the values. The first one is with constructor
35 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
35 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
36 lower quartile, median, upper quartile and upper extre. Second method is to create an empty QBoxSet instance and
36 lower quartile, median, upper quartile and upper extre. Second method is to create an empty QBoxSet instance and
37 give the values using own methods.
37 give the values using own methods.
38
38
39 \mainclass
39 \mainclass
40
40
41 \sa QBoxPlotSeries
41 \sa QBoxPlotSeries
42 */
42 */
43 /*!
43 /*!
44 \qmlclass BoxSet QBoxSet
44 \qmlclass BoxSet QBoxSet
45
45
46 BoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
46 BoxSet represents one box-and-whiskers item. It takes fives values to create a graphical representation
47 of range and three medians. There's two type of methods to give the values. The first one is with constructor
47 of range and three medians. There's two type of methods to give the values. The first one is with constructor
48 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
48 or append type of methods (append and operator <<). In these the values have to be given in order lower extreme,
49 lower quartile, median, upper quartile and upper extre. Second method is to create an empty BoxSet instance and
49 lower quartile, median, upper quartile and upper extre. Second method is to create an empty BoxSet instance and
50 give the values using own methods.
50 give the values using own methods.
51 \sa BoxPlotSeries
51 \sa BoxPlotSeries
52 */
52 */
53
53
54 /*!
54 /*!
55 \property QBoxSet::pen
55 \property QBoxSet::pen
56 \brief Defines the pen used by the box-and-whiskers set.
56 \brief Defines the pen used by the box-and-whiskers set.
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QBoxSet::brush
60 \property QBoxSet::brush
61 \brief Defines the brush used by the box-and-whiskers set.
61 \brief Defines the brush used by the box-and-whiskers set.
62 */
62 */
63
63
64 /*!
64 /*!
65 \property QBoxSet::color
65 \property QBoxSet::color
66 The fill (brush) color of the box-and-whiskers set.
66 The fill (brush) color of the box-and-whiskers set.
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QBoxSet::borderColor
70 \property QBoxSet::borderColor
71 The line (pen) color of the box-and-whiskers set.
71 The line (pen) color of the box-and-whiskers set.
72 */
72 */
73
73
74 /*!
74 /*!
75 \fn void QBoxSet::clicked()
75 \fn void QBoxSet::clicked()
76 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
76 The signal is emitted if the user clicks with a mouse on top of box-and-whisker item.
77 */
77 */
78
78
79 /*!
79 /*!
80 \fn void QBoxSet::hovered(bool status)
80 \fn void QBoxSet::hovered(bool status)
81
81
82 The signal is emitted if mouse is hovered on top of box-and-whisker item.
82 The signal is emitted if mouse is hovered on top of box-and-whisker item.
83 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
83 Parameter \a status is true, if mouse entered on top of item, false if mouse left from top of item.
84 */
84 */
85
85
86 /*!
86 /*!
87 \fn void QBoxSet::penChanged()
87 \fn void QBoxSet::penChanged()
88 This signal is emitted when the pen of the box-and-whisker item has changed.
88 This signal is emitted when the pen of the box-and-whisker item has changed.
89 \sa pen
89 \sa pen
90 */
90 */
91
91
92 /*!
92 /*!
93 \fn void QBoxSet::brushChanged()
93 \fn void QBoxSet::brushChanged()
94 This signal is emitted when the brush of the box-and-whisker item has changed.
94 This signal is emitted when the brush of the box-and-whisker item has changed.
95 \sa brush
95 \sa brush
96 */
96 */
97
97
98 /*!
98 /*!
99 \fn void QBoxSet::colorChanged(QColor)
99 \fn void QBoxSet::colorChanged(QColor)
100 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
100 This signal is emitted when the fill (brush) color of the box-and-whisker item has changed to \a color.
101 */
101 */
102
102
103 /*!
103 /*!
104 \fn void QBoxSet::valuesAdded(int index, int count)
104 \fn void QBoxSet::valuesAdded(int index, int count)
105 This signal is emitted when new values have been added to the box-and-whisker item.
105 This signal is emitted when new values have been added to the box-and-whisker item.
106 Parameter \a index indicates the position of the first inserted value.
106 Parameter \a index indicates the position of the first inserted value.
107 Parameter \a count is the number of inserted values.
107 Parameter \a count is the number of inserted values.
108 \sa append(), insert()
108 \sa append(), insert()
109 */
109 */
110
110
111 /*!
111 /*!
112 \fn void QBoxSet::valueChanged(int index)
112 \fn void QBoxSet::valueChanged(int index)
113 This signal is emitted values the value in the box-and-whisker item has been modified.
113 This signal is emitted values the value in the box-and-whisker item has been modified.
114 Parameter \a index indicates the position of the modified value.
114 Parameter \a index indicates the position of the modified value.
115 \sa at()
115 \sa at()
116 */
116 */
117
117
118 /*!
118 /*!
119 \fn void QBoxSet::borderColorChanged(QColor)
119 \fn void QBoxSet::borderColorChanged(QColor)
120 This signal is emitted when the line (pen) color of the box-and-whisker item has changed to \a color.
120 This signal is emitted when the line (pen) color of the box-and-whisker item has changed to \a color.
121 */
121 */
122
122
123 /*!
123 /*!
124 Constructs QBoxSet with optional \a label and parent of \a parent
124 Constructs QBoxSet with optional \a label and parent of \a parent
125 */
125 */
126 QBoxSet::QBoxSet(const QString label, QObject *parent)
126 QBoxSet::QBoxSet(const QString label, QObject *parent)
127 : QObject(parent),
127 : QObject(parent),
128 d_ptr(new QBoxSetPrivate(label, this))
128 d_ptr(new QBoxSetPrivate(label, this))
129 {
129 {
130 }
130 }
131
131
132 /*!
132 /*!
133 Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median,
133 Constructs QBoxSet with given ordered values. \a le for lower extreme, \a lq for lower quartile, \a m for median,
134 \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional.
134 \a uq for upper quartile and \a ue for upper quartile. \a label and \a parent are optional.
135 */
135 */
136 QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label = "", QObject *parent)
136 QBoxSet::QBoxSet(const qreal le, const qreal lq, const qreal m, const qreal uq, const qreal ue, const QString label, QObject *parent)
137 : QObject(parent),
137 : QObject(parent),
138 d_ptr(new QBoxSetPrivate(label, this))
138 d_ptr(new QBoxSetPrivate(label, this))
139 {
139 {
140 d_ptr->append(le);
140 d_ptr->append(le);
141 d_ptr->append(lq);
141 d_ptr->append(lq);
142 d_ptr->append(m);
142 d_ptr->append(m);
143 d_ptr->append(uq);
143 d_ptr->append(uq);
144 d_ptr->append(ue);
144 d_ptr->append(ue);
145 }
145 }
146
146
147 /*!
147 /*!
148 Destroys the boxset
148 Destroys the boxset
149 */
149 */
150 QBoxSet::~QBoxSet()
150 QBoxSet::~QBoxSet()
151 {
151 {
152 // NOTE: d_ptr destroyed by QObject
152 // NOTE: d_ptr destroyed by QObject
153 }
153 }
154
154
155 /*!
155 /*!
156 Appends new value \a value to the end of set.
156 Appends new value \a value to the end of set.
157 */
157 */
158 void QBoxSet::append(const qreal value)
158 void QBoxSet::append(const qreal value)
159 {
159 {
160 //int index = d_ptr->m_values.count();
160 //int index = d_ptr->m_values.count();
161 d_ptr->append(value);
161 d_ptr->append(value);
162
162
163 emit valuesAdded(d_ptr->m_valuesCount, 1);
163 emit valuesAdded(d_ptr->m_valuesCount, 1);
164 }
164 }
165
165
166 /*!
166 /*!
167 Appends a list of reals to set. Works like append with single real value. The \a values in list
167 Appends a list of reals to set. Works like append with single real value. The \a values in list
168 are appended to end of boxset
168 are appended to end of boxset
169 \sa append()
169 \sa append()
170 */
170 */
171 void QBoxSet::append(const QList<qreal> &values)
171 void QBoxSet::append(const QList<qreal> &values)
172 {
172 {
173 //int index = d_ptr->m_values.count();
173 //int index = d_ptr->m_values.count();
174 d_ptr->append(values);
174 d_ptr->append(values);
175 emit valuesAdded(d_ptr->m_valuesCount, values.count());
175 emit valuesAdded(d_ptr->m_valuesCount, values.count());
176 }
176 }
177
177
178 /*!
178 /*!
179 Sets new value \a value as the lower extreme for the set.
179 Sets new value \a value as the lower extreme for the set.
180 */
180 */
181 void QBoxSet::setLowerExtreme(const qreal value)
181 void QBoxSet::setLowerExtreme(const qreal value)
182 {
182 {
183 d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value);
183 d_ptr->replace(QBoxSetPrivate::PosLowerExtreme, value);
184 emit d_ptr->restructuredBox();
184 emit d_ptr->restructuredBox();
185 emit valueChanged(QBoxSetPrivate::PosLowerExtreme);
185 emit valueChanged(QBoxSetPrivate::PosLowerExtreme);
186 }
186 }
187
187
188 /*!
188 /*!
189 Returns the lower extreme value of the set.
189 Returns the lower extreme value of the set.
190 */
190 */
191 qreal QBoxSet::lowerExtreme()
191 qreal QBoxSet::lowerExtreme()
192 {
192 {
193 return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme];
193 return d_ptr->m_values[QBoxSetPrivate::PosLowerExtreme];
194 }
194 }
195
195
196 /*!
196 /*!
197 Sets new value \a value as the lower quartile for the set.
197 Sets new value \a value as the lower quartile for the set.
198 */
198 */
199 void QBoxSet::setLowerQuartile(const qreal value)
199 void QBoxSet::setLowerQuartile(const qreal value)
200 {
200 {
201 d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value);
201 d_ptr->replace(QBoxSetPrivate::PosLowerQuartile, value);
202 emit d_ptr->restructuredBox();
202 emit d_ptr->restructuredBox();
203 emit valueChanged(QBoxSetPrivate::PosLowerQuartile);
203 emit valueChanged(QBoxSetPrivate::PosLowerQuartile);
204 }
204 }
205
205
206 /*!
206 /*!
207 Returns the lower quartile value of the set.
207 Returns the lower quartile value of the set.
208 */
208 */
209 qreal QBoxSet::lowerQuartile()
209 qreal QBoxSet::lowerQuartile()
210 {
210 {
211 return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile];
211 return d_ptr->m_values[QBoxSetPrivate::PosLowerQuartile];
212 }
212 }
213
213
214 /*!
214 /*!
215 Sets new value \a value as the median for the set.
215 Sets new value \a value as the median for the set.
216 */
216 */
217 void QBoxSet::setMedian(const qreal value)
217 void QBoxSet::setMedian(const qreal value)
218 {
218 {
219 d_ptr->replace(QBoxSetPrivate::PosMedian, value);
219 d_ptr->replace(QBoxSetPrivate::PosMedian, value);
220 emit d_ptr->restructuredBox();
220 emit d_ptr->restructuredBox();
221 emit valueChanged(QBoxSetPrivate::PosMedian);
221 emit valueChanged(QBoxSetPrivate::PosMedian);
222 }
222 }
223
223
224 /*!
224 /*!
225 Returns the median value of the set.
225 Returns the median value of the set.
226 */
226 */
227 qreal QBoxSet::median()
227 qreal QBoxSet::median()
228 {
228 {
229 return d_ptr->m_values[QBoxSetPrivate::PosMedian];
229 return d_ptr->m_values[QBoxSetPrivate::PosMedian];
230 }
230 }
231
231
232 /*!
232 /*!
233 Sets new value \a value as the upper quartile for the set.
233 Sets new value \a value as the upper quartile for the set.
234 */
234 */
235 void QBoxSet::setUpperQuartile(const qreal value)
235 void QBoxSet::setUpperQuartile(const qreal value)
236 {
236 {
237 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
237 d_ptr->replace(QBoxSetPrivate::PosUpperQuartile, value);
238 emit d_ptr->restructuredBox();
238 emit d_ptr->restructuredBox();
239 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
239 emit valueChanged(QBoxSetPrivate::PosUpperQuartile);
240 }
240 }
241
241
242 /*!
242 /*!
243 Returns the upper quartile value of the set.
243 Returns the upper quartile value of the set.
244 */
244 */
245 qreal QBoxSet::upperQuartile()
245 qreal QBoxSet::upperQuartile()
246 {
246 {
247 return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile];
247 return d_ptr->m_values[QBoxSetPrivate::PosUpperQuartile];
248 }
248 }
249
249
250 /*!
250 /*!
251 Sets new value \a value as the upper extreme for the set.
251 Sets new value \a value as the upper extreme for the set.
252 */
252 */
253 void QBoxSet::setUpperExtreme(const qreal value)
253 void QBoxSet::setUpperExtreme(const qreal value)
254 {
254 {
255 d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value);
255 d_ptr->replace(QBoxSetPrivate::PosUpperExtreme, value);
256 emit d_ptr->restructuredBox();
256 emit d_ptr->restructuredBox();
257 emit valueChanged(QBoxSetPrivate::PosUpperExtreme);
257 emit valueChanged(QBoxSetPrivate::PosUpperExtreme);
258 }
258 }
259
259
260 /*!
260 /*!
261 Returns the upper extreme value of the set.
261 Returns the upper extreme value of the set.
262 */
262 */
263 qreal QBoxSet::upperExtreme()
263 qreal QBoxSet::upperExtreme()
264 {
264 {
265 return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme];
265 return d_ptr->m_values[QBoxSetPrivate::PosUpperExtreme];
266 }
266 }
267
267
268 /*!
268 /*!
269 Sets new \a label for set.
269 Sets new \a label for set.
270 */
270 */
271 void QBoxSet::setLabel(const QString label)
271 void QBoxSet::setLabel(const QString label)
272 {
272 {
273 d_ptr->m_label = label;
273 d_ptr->m_label = label;
274 }
274 }
275
275
276 /*!
276 /*!
277 Returns label of the set.
277 Returns label of the set.
278 */
278 */
279 QString QBoxSet::label() const
279 QString QBoxSet::label() const
280 {
280 {
281 return d_ptr->m_label;
281 return d_ptr->m_label;
282 }
282 }
283
283
284 /*!
284 /*!
285 Convenience operator. Same as append, with real \a value.
285 Convenience operator. Same as append, with real \a value.
286 \sa append()
286 \sa append()
287 */
287 */
288 QBoxSet &QBoxSet::operator << (const qreal &value)
288 QBoxSet &QBoxSet::operator << (const qreal &value)
289 {
289 {
290 append(value);
290 append(value);
291 return *this;
291 return *this;
292 }
292 }
293
293
294 /*!
294 /*!
295 Inserts new \a value on the \a index position.
295 Inserts new \a value on the \a index position.
296 The value that is currently at this postion is moved to postion index + 1
296 The value that is currently at this postion is moved to postion index + 1
297 */
297 */
298 void QBoxSet::insert(const int index, const qreal value)
298 void QBoxSet::insert(const int index, const qreal value)
299 {
299 {
300 d_ptr->insert(index, value);
300 d_ptr->insert(index, value);
301 emit valuesAdded(index, 1);
301 emit valuesAdded(index, 1);
302 }
302 }
303
303
304 /*!
304 /*!
305 Sets a new value \a value to set, indexed by \a index
305 Sets a new value \a value to set, indexed by \a index
306 */
306 */
307 void QBoxSet::replace(const int index, const qreal value)
307 void QBoxSet::replace(const int index, const qreal value)
308 {
308 {
309 if (index >= 0 && index < 5) {
309 if (index >= 0 && index < 5) {
310 d_ptr->replace(index, value);
310 d_ptr->replace(index, value);
311 emit valueChanged(index);
311 emit valueChanged(index);
312 }
312 }
313 }
313 }
314
314
315
315
316 /*!
316 /*!
317 Returns value of set indexed by \a index.
317 Returns value of set indexed by \a index.
318 If the index is out of bounds 0.0 is returned.
318 If the index is out of bounds 0.0 is returned.
319 */
319 */
320 qreal QBoxSet::at(const int index) const
320 qreal QBoxSet::at(const int index) const
321 {
321 {
322 if (index < 0 || index >= 5)
322 if (index < 0 || index >= 5)
323 return 0;
323 return 0;
324 return d_ptr->m_values[index];
324 return d_ptr->m_values[index];
325 }
325 }
326
326
327 /*!
327 /*!
328 Returns value of set indexed by \a index.
328 Returns value of set indexed by \a index.
329 If the index is out of bounds 0.0 is returned.
329 If the index is out of bounds 0.0 is returned.
330 */
330 */
331 qreal QBoxSet::operator [](const int index) const
331 qreal QBoxSet::operator [](const int index) const
332 {
332 {
333 return at(index);
333 return at(index);
334 }
334 }
335
335
336 /*!
336 /*!
337 Returns count of values in set.
337 Returns count of values in set.
338 */
338 */
339 int QBoxSet::count() const
339 int QBoxSet::count() const
340 {
340 {
341 return d_ptr->m_valuesCount;
341 return d_ptr->m_valuesCount;
342 }
342 }
343
343
344 /*!
344 /*!
345 Sets pen for set. Boxes of this set are drawn using \a pen
345 Sets pen for set. Boxes of this set are drawn using \a pen
346 */
346 */
347 void QBoxSet::setPen(const QPen &pen)
347 void QBoxSet::setPen(const QPen &pen)
348 {
348 {
349 if (d_ptr->m_pen != pen) {
349 if (d_ptr->m_pen != pen) {
350 d_ptr->m_pen = pen;
350 d_ptr->m_pen = pen;
351 emit d_ptr->updatedBox();
351 emit d_ptr->updatedBox();
352 emit penChanged();
352 emit penChanged();
353 }
353 }
354 }
354 }
355
355
356 /*!
356 /*!
357 Returns pen of the set.
357 Returns pen of the set.
358 */
358 */
359 QPen QBoxSet::pen() const
359 QPen QBoxSet::pen() const
360 {
360 {
361 return d_ptr->m_pen;
361 return d_ptr->m_pen;
362 }
362 }
363
363
364 /*!
364 /*!
365 Sets brush for the set. Boxes of this set are drawn using \a brush
365 Sets brush for the set. Boxes of this set are drawn using \a brush
366 */
366 */
367 void QBoxSet::setBrush(const QBrush &brush)
367 void QBoxSet::setBrush(const QBrush &brush)
368 {
368 {
369 if (d_ptr->m_brush != brush) {
369 if (d_ptr->m_brush != brush) {
370 d_ptr->m_brush = brush;
370 d_ptr->m_brush = brush;
371 emit d_ptr->updatedBox();
371 emit d_ptr->updatedBox();
372 emit brushChanged();
372 emit brushChanged();
373 }
373 }
374 }
374 }
375
375
376 /*!
376 /*!
377 Returns brush of the set.
377 Returns brush of the set.
378 */
378 */
379 QBrush QBoxSet::brush() const
379 QBrush QBoxSet::brush() const
380 {
380 {
381 return d_ptr->m_brush;
381 return d_ptr->m_brush;
382 }
382 }
383
383
384 /*!
384 /*!
385 Returns the color of the brush of boxset.
385 Returns the color of the brush of boxset.
386 */
386 */
387 QColor QBoxSet::color()
387 QColor QBoxSet::color()
388 {
388 {
389 return brush().color();
389 return brush().color();
390 }
390 }
391
391
392 /*!
392 /*!
393 Sets the \a color of brush for this boxset
393 Sets the \a color of brush for this boxset
394 */
394 */
395 void QBoxSet::setColor(QColor color)
395 void QBoxSet::setColor(QColor color)
396 {
396 {
397 QBrush b = brush();
397 QBrush b = brush();
398 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
398 if ((b.color() != color) || (b.style() == Qt::NoBrush)) {
399 b.setColor(color);
399 b.setColor(color);
400 if (b.style() == Qt::NoBrush) {
400 if (b.style() == Qt::NoBrush) {
401 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
401 // Set tyle to Qt::SolidPattern. (Default is Qt::NoBrush)
402 // This prevents theme to override color defined in QML side:
402 // This prevents theme to override color defined in QML side:
403 // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] }
403 // BoxSet { label: "Bob"; color:"red"; values: [1,2,3] }
404 // The color must be obeyed, since user wanted it.
404 // The color must be obeyed, since user wanted it.
405 b.setStyle(Qt::SolidPattern);
405 b.setStyle(Qt::SolidPattern);
406 }
406 }
407 setBrush(b);
407 setBrush(b);
408 emit colorChanged(color);
408 emit colorChanged(color);
409 }
409 }
410 }
410 }
411
411
412 /*!
412 /*!
413 Returns the color of pen of this boxset
413 Returns the color of pen of this boxset
414 */
414 */
415 QColor QBoxSet::borderColor()
415 QColor QBoxSet::borderColor()
416 {
416 {
417 return pen().color();
417 return pen().color();
418 }
418 }
419
419
420 /*!
420 /*!
421 Sets the color of pen for this boxset
421 Sets the color of pen for this boxset
422 */
422 */
423 void QBoxSet::setBorderColor(QColor color)
423 void QBoxSet::setBorderColor(QColor color)
424 {
424 {
425 QPen p = pen();
425 QPen p = pen();
426 if (p.color() != color) {
426 if (p.color() != color) {
427 p.setColor(color);
427 p.setColor(color);
428 setPen(p);
428 setPen(p);
429 emit borderColorChanged(color);
429 emit borderColorChanged(color);
430 }
430 }
431 }
431 }
432
432
433 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
433 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
434
434
435 QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent),
435 QBoxSetPrivate::QBoxSetPrivate(const QString label, QBoxSet *parent) : QObject(parent),
436 q_ptr(parent),
436 q_ptr(parent),
437 m_label(label),
437 m_label(label),
438 m_valuesCount(5),
438 m_valuesCount(5),
439 m_appendCount(0),
439 m_appendCount(0),
440 m_pen(QPen(Qt::NoPen)),
440 m_pen(QPen(Qt::NoPen)),
441 m_brush(QBrush(Qt::NoBrush))
441 m_brush(QBrush(Qt::NoBrush))
442 {
442 {
443 m_values = new qreal[m_valuesCount];
443 m_values = new qreal[m_valuesCount];
444 }
444 }
445
445
446 QBoxSetPrivate::~QBoxSetPrivate()
446 QBoxSetPrivate::~QBoxSetPrivate()
447 {
447 {
448 }
448 }
449
449
450 void QBoxSetPrivate::append(qreal value)
450 void QBoxSetPrivate::append(qreal value)
451 {
451 {
452 if (isValidValue(value) && m_appendCount < m_valuesCount) {
452 if (isValidValue(value) && m_appendCount < m_valuesCount) {
453 m_values[m_appendCount++] = value;
453 m_values[m_appendCount++] = value;
454 emit restructuredBox();
454 emit restructuredBox();
455 }
455 }
456 }
456 }
457
457
458 void QBoxSetPrivate::append(QList<qreal> values)
458 void QBoxSetPrivate::append(QList<qreal> values)
459 {
459 {
460 for (int i = 0; i < values.count(); i++) {
460 for (int i = 0; i < values.count(); i++) {
461 if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount)
461 if (isValidValue(values.at(i)) && m_appendCount < m_valuesCount)
462 m_values[m_appendCount++] = values.at(i);
462 m_values[m_appendCount++] = values.at(i);
463 }
463 }
464 emit restructuredBox();
464 emit restructuredBox();
465 }
465 }
466
466
467 void QBoxSetPrivate::insert(const int index, const qreal value)
467 void QBoxSetPrivate::insert(const int index, const qreal value)
468 {
468 {
469 if (isValidValue(value)) {
469 if (isValidValue(value)) {
470 for (int i = 4; i > index; i--)
470 for (int i = 4; i > index; i--)
471 m_values[i] = m_values[i - 1];
471 m_values[i] = m_values[i - 1];
472 m_values[index] = value;
472 m_values[index] = value;
473 emit restructuredBox();
473 emit restructuredBox();
474 }
474 }
475 }
475 }
476
476
477 void QBoxSetPrivate::replace(const int index, const qreal value)
477 void QBoxSetPrivate::replace(const int index, const qreal value)
478 {
478 {
479 m_values[index] = value;
479 m_values[index] = value;
480 emit updatedLayout();
480 emit updatedLayout();
481 }
481 }
482
482
483 qreal QBoxSetPrivate::value(const int index)
483 qreal QBoxSetPrivate::value(const int index)
484 {
484 {
485 if (index < 0 || index >= m_valuesCount)
485 if (index < 0 || index >= m_valuesCount)
486 return 0;
486 return 0;
487 return m_values[index];
487 return m_values[index];
488 }
488 }
489
489
490 #include "moc_qboxset.cpp"
490 #include "moc_qboxset.cpp"
491 #include "moc_qboxset_p.cpp"
491 #include "moc_qboxset_p.cpp"
492
492
493 QTCOMMERCIALCHART_END_NAMESPACE
493 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now