From 03c587f510f2a5f9126b53a0c3913ac06bb86c79 Mon Sep 17 00:00:00 2001 From: Stian Sandvik Thomassen Date: Thu, 15 Oct 2009 13:31:39 +1000 Subject: Removed assertion from QComboBox::removeItem() Made QComboBox::removeItem() do nothing instead of asserting if index is out of range. Reviewed-by: Andy Shaw --- src/gui/widgets/qcombobox.cpp | 5 ++++- tests/auto/qcombobox/tst_qcombobox.cpp | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index b606538..0e888d6 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -2174,11 +2174,14 @@ void QComboBox::insertSeparator(int index) /*! Removes the item at the given \a index from the combobox. This will update the current index if the index is removed. + + This function does nothing if \a index is out of range. */ void QComboBox::removeItem(int index) { - Q_ASSERT(index >= 0 && index < count()); Q_D(QComboBox); + if (index < 0 || index >= count()) + return; d->model->removeRows(index, 1, d->root); } diff --git a/tests/auto/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index e76f0f7..0d3469d 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -151,6 +151,7 @@ private slots: void subControlRectsWithOffset_data(); void subControlRectsWithOffset(); void task260974_menuItemRectangleForComboBoxPopup(); + void removeItem(); protected slots: void onEditTextChanged( const QString &newString ); @@ -2398,5 +2399,22 @@ void tst_QComboBox::task260974_menuItemRectangleForComboBoxPopup() #endif } +void tst_QComboBox::removeItem() +{ + QComboBox cb; + cb.removeItem(-1); + cb.removeItem(1); + cb.removeItem(0); + QCOMPARE(cb.count(), 0); + + cb.addItem("foo"); + cb.removeItem(-1); + QCOMPARE(cb.count(), 1); + cb.removeItem(1); + QCOMPARE(cb.count(), 1); + cb.removeItem(0); + QCOMPARE(cb.count(), 0); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" -- cgit v0.12