##// END OF EJS Templates
pie: make it impossible to add negative slice values
Jani Honkonen -
r1280:dde538c774a3
parent child
Show More
@@ -59,6 +59,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
59
59
60 Value of the slice.
60 Value of the slice.
61
61
62 Note that if users sets a negative value it is converted to a positive value.
63
62 \sa percentage(), QPieSeries::sum()
64 \sa percentage(), QPieSeries::sum()
63 */
65 */
64
66
@@ -303,8 +305,8 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
303 :QObject(parent),
305 :QObject(parent),
304 d_ptr(new QPieSlicePrivate(this))
306 d_ptr(new QPieSlicePrivate(this))
305 {
307 {
306 d_ptr->m_data.m_value = value;
308 setValue(value);
307 d_ptr->m_data.m_labelText = label;
309 setLabel(label);
308 }
310 }
309
311
310 /*!
312 /*!
@@ -331,6 +333,7 QString QPieSlice::label() const
331
333
332 void QPieSlice::setValue(qreal value)
334 void QPieSlice::setValue(qreal value)
333 {
335 {
336 value = qAbs(value); // negative values not allowed
334 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
337 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
335 d_ptr->m_data.m_value = value;
338 d_ptr->m_data.m_value = value;
336 emit valueChanged();
339 emit valueChanged();
@@ -121,8 +121,9 void tst_qpieslice::changedSignals()
121 // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
121 // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
122
122
123 // set everything twice to see we do not get unnecessary signals
123 // set everything twice to see we do not get unnecessary signals
124 slice.setValue(1);
124 slice.setValue(1.0);
125 slice.setValue(1);
125 slice.setValue(-1.0);
126 QCOMPARE(slice.value(), 1.0);
126 slice.setLabel("foobar");
127 slice.setLabel("foobar");
127 slice.setLabel("foobar");
128 slice.setLabel("foobar");
128 slice.setLabelVisible();
129 slice.setLabelVisible();
General Comments 0
You need to be logged in to leave comments. Login now