##// 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 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 64 \sa percentage(), QPieSeries::sum()
63 65 */
64 66
@@ -303,8 +305,8 QPieSlice::QPieSlice(QString label, qreal value, QObject *parent)
303 305 :QObject(parent),
304 306 d_ptr(new QPieSlicePrivate(this))
305 307 {
306 d_ptr->m_data.m_value = value;
307 d_ptr->m_data.m_labelText = label;
308 setValue(value);
309 setLabel(label);
308 310 }
309 311
310 312 /*!
@@ -331,6 +333,7 QString QPieSlice::label() const
331 333
332 334 void QPieSlice::setValue(qreal value)
333 335 {
336 value = qAbs(value); // negative values not allowed
334 337 if (!qFuzzyIsNull(d_ptr->m_data.m_value - value)) {
335 338 d_ptr->m_data.m_value = value;
336 339 emit valueChanged();
@@ -121,8 +121,9 void tst_qpieslice::changedSignals()
121 121 // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues()
122 122
123 123 // set everything twice to see we do not get unnecessary signals
124 slice.setValue(1);
125 slice.setValue(1);
124 slice.setValue(1.0);
125 slice.setValue(-1.0);
126 QCOMPARE(slice.value(), 1.0);
126 127 slice.setLabel("foobar");
127 128 slice.setLabel("foobar");
128 129 slice.setLabelVisible();
General Comments 0
You need to be logged in to leave comments. Login now