@@ -355,8 +355,10 bool QBarSet::remove(const int index, const int count) | |||||
355 | */ |
|
355 | */ | |
356 | void QBarSet::replace(const int index, const qreal value) |
|
356 | void QBarSet::replace(const int index, const qreal value) | |
357 | { |
|
357 | { | |
358 | d_ptr->replace(index,value); |
|
358 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
359 | emit valueChanged(index); |
|
359 | d_ptr->replace(index,value); | |
|
360 | emit valueChanged(index); | |||
|
361 | } | |||
360 | } |
|
362 | } | |
361 |
|
363 | |||
362 | /*! |
|
364 | /*! | |
@@ -364,8 +366,10 void QBarSet::replace(const int index, const qreal value) | |||||
364 | */ |
|
366 | */ | |
365 | void QBarSet::replace(const int index, const QPointF value) |
|
367 | void QBarSet::replace(const int index, const QPointF value) | |
366 | { |
|
368 | { | |
367 | d_ptr->replace(index,value); |
|
369 | if (index >= 0 && index < d_ptr->m_values.count()) { | |
368 | emit valueChanged(index); |
|
370 | d_ptr->replace(index,value); | |
|
371 | emit valueChanged(index); | |||
|
372 | } | |||
369 | } |
|
373 | } | |
370 |
|
374 | |||
371 | /*! |
|
375 | /*! | |
@@ -608,7 +612,7 void QBarSetPrivate::insert(const int index, const QPointF value) | |||||
608 |
|
612 | |||
609 | bool QBarSetPrivate::remove(const int index, const int count) |
|
613 | bool QBarSetPrivate::remove(const int index, const int count) | |
610 | { |
|
614 | { | |
611 | if ((index + count) > m_values.count()) { |
|
615 | if (index < 0 || (index + count) > m_values.count()) { | |
612 | // cant remove more values than there are |
|
616 | // cant remove more values than there are | |
613 | return false; |
|
617 | return false; | |
614 | } |
|
618 | } |
@@ -226,6 +226,7 void tst_QBarSet::remove() | |||||
226 | QCOMPARE(m_barset->count(), 4); |
|
226 | QCOMPARE(m_barset->count(), 4); | |
227 | QCOMPARE(m_barset->sum(), 10.0); |
|
227 | QCOMPARE(m_barset->sum(), 10.0); | |
228 |
|
228 | |||
|
229 | // Remove middle | |||
229 | m_barset->remove(2); // 1.0 2.0 4.0 |
|
230 | m_barset->remove(2); // 1.0 2.0 4.0 | |
230 | QCOMPARE(m_barset->at(0).y(), 1.0); |
|
231 | QCOMPARE(m_barset->at(0).y(), 1.0); | |
231 | QCOMPARE(m_barset->at(1).y(), 2.0); |
|
232 | QCOMPARE(m_barset->at(1).y(), 2.0); | |
@@ -233,12 +234,21 void tst_QBarSet::remove() | |||||
233 | QCOMPARE(m_barset->count(), 3); |
|
234 | QCOMPARE(m_barset->count(), 3); | |
234 | QCOMPARE(m_barset->sum(), 7.0); |
|
235 | QCOMPARE(m_barset->sum(), 7.0); | |
235 |
|
236 | |||
|
237 | // Remove first | |||
236 | m_barset->remove(0); // 2.0 4.0 |
|
238 | m_barset->remove(0); // 2.0 4.0 | |
237 | QCOMPARE(m_barset->at(0).y(), 2.0); |
|
239 | QCOMPARE(m_barset->at(0).y(), 2.0); | |
238 | QCOMPARE(m_barset->at(1).y(), 4.0); |
|
240 | QCOMPARE(m_barset->at(1).y(), 4.0); | |
239 | QCOMPARE(m_barset->count(), 2); |
|
241 | QCOMPARE(m_barset->count(), 2); | |
240 | QCOMPARE(m_barset->sum(), 6.0); |
|
242 | QCOMPARE(m_barset->sum(), 6.0); | |
241 |
|
243 | |||
|
244 | // Illegal indexes | |||
|
245 | m_barset->remove(4); | |||
|
246 | QCOMPARE(m_barset->count(), 2); | |||
|
247 | QCOMPARE(m_barset->sum(), 6.0); | |||
|
248 | m_barset->remove(-1); | |||
|
249 | QCOMPARE(m_barset->count(), 2); | |||
|
250 | QCOMPARE(m_barset->sum(), 6.0); | |||
|
251 | ||||
242 | QCOMPARE(valueSpy.count(), 2); |
|
252 | QCOMPARE(valueSpy.count(), 2); | |
243 | } |
|
253 | } | |
244 |
|
254 | |||
@@ -261,11 +271,13 void tst_QBarSet::replace() | |||||
261 | QCOMPARE(m_barset->count(), 4); |
|
271 | QCOMPARE(m_barset->count(), 4); | |
262 | QCOMPARE(m_barset->sum(), 10.0); |
|
272 | QCOMPARE(m_barset->sum(), 10.0); | |
263 |
|
273 | |||
|
274 | // Replace first | |||
264 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 |
|
275 | m_barset->replace(0, 5.0); // 5.0 2.0 3.0 4.0 | |
265 | QCOMPARE(m_barset->count(), 4); |
|
276 | QCOMPARE(m_barset->count(), 4); | |
266 | QCOMPARE(m_barset->sum(), 14.0); |
|
277 | QCOMPARE(m_barset->sum(), 14.0); | |
267 | QCOMPARE(m_barset->at(0).y(), 5.0); |
|
278 | QCOMPARE(m_barset->at(0).y(), 5.0); | |
268 |
|
279 | |||
|
280 | // Replace last | |||
269 | m_barset->replace(3, 6.0); |
|
281 | m_barset->replace(3, 6.0); | |
270 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 |
|
282 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |
271 | QCOMPARE(m_barset->sum(), 16.0); |
|
283 | QCOMPARE(m_barset->sum(), 16.0); | |
@@ -274,6 +286,20 void tst_QBarSet::replace() | |||||
274 | QCOMPARE(m_barset->at(2).y(), 3.0); |
|
286 | QCOMPARE(m_barset->at(2).y(), 3.0); | |
275 | QCOMPARE(m_barset->at(3).y(), 6.0); |
|
287 | QCOMPARE(m_barset->at(3).y(), 6.0); | |
276 |
|
288 | |||
|
289 | // Illegal indexes | |||
|
290 | m_barset->replace(4, 6.0); | |||
|
291 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |||
|
292 | QCOMPARE(m_barset->sum(), 16.0); | |||
|
293 | m_barset->replace(-1, 6.0); | |||
|
294 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |||
|
295 | QCOMPARE(m_barset->sum(), 16.0); | |||
|
296 | m_barset->replace(4, QPointF(1.0, 1.0)); | |||
|
297 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |||
|
298 | QCOMPARE(m_barset->sum(), 16.0); | |||
|
299 | m_barset->replace(-1, QPointF(1.0, 1.0)); | |||
|
300 | QCOMPARE(m_barset->count(), 4); // 5.0 2.0 3.0 6.0 | |||
|
301 | QCOMPARE(m_barset->sum(), 16.0); | |||
|
302 | ||||
277 | QVERIFY(valueSpy.count() == 2); |
|
303 | QVERIFY(valueSpy.count() == 2); | |
278 | } |
|
304 | } | |
279 |
|
305 |
General Comments 0
You need to be logged in to leave comments.
Login now