diff options
-rw-r--r-- | src/widgets/kernel/qformlayout.cpp | 13 | ||||
-rw-r--r-- | tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp | 15 |
2 files changed, 13 insertions, 15 deletions
diff --git a/src/widgets/kernel/qformlayout.cpp b/src/widgets/kernel/qformlayout.cpp index f3f7280030..6b134379c6 100644 --- a/src/widgets/kernel/qformlayout.cpp +++ b/src/widgets/kernel/qformlayout.cpp @@ -1551,24 +1551,19 @@ QFormLayout::TakeRowResult QFormLayout::takeRow(int row) { Q_D(QFormLayout); - const int storageIndex = storageIndexFromLayoutItem(d->m_matrix, d->m_things.value(row)); - if (Q_UNLIKELY(storageIndex == -1)) { + if (Q_UNLIKELY(!(uint(row) < uint(d->m_matrix.rowCount())))) { qWarning("QFormLayout::takeRow: Invalid row %d", row); return TakeRowResult(); } - int storageRow, dummy; - QFormLayoutPrivate::ItemMatrix::storageIndexToPosition(storageIndex, &storageRow, &dummy); - Q_ASSERT(d->m_matrix(storageRow, dummy)); - - QFormLayoutItem *label = d->m_matrix(storageRow, 0); - QFormLayoutItem *field = d->m_matrix(storageRow, 1); + QFormLayoutItem *label = d->m_matrix(row, 0); + QFormLayoutItem *field = d->m_matrix(row, 1); Q_ASSERT(field); d->m_things.removeOne(label); d->m_things.removeOne(field); - d->m_matrix.removeRow(storageRow); + d->m_matrix.removeRow(row); invalidate(); diff --git a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp index d8239b5a28..c324a4bd56 100644 --- a/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp +++ b/tests/auto/widgets/kernel/qformlayout/tst_qformlayout.cpp @@ -757,13 +757,14 @@ void tst_QFormLayout::removeRow() layout->removeRow(1); - QVERIFY(!w1); - QCOMPARE(layout->count(), 1); + QVERIFY(w1); + QVERIFY(!w2); + QCOMPARE(layout->count(), 2); QCOMPARE(layout->rowCount(), 1); layout->removeRow(0); - QVERIFY(!w2); + QVERIFY(!w1); QCOMPARE(layout->count(), 0); QCOMPARE(layout->rowCount(), 0); } @@ -863,17 +864,19 @@ void tst_QFormLayout::takeRow() QVERIFY(w2); QVERIFY(result.fieldItem); - QVERIFY(result.labelItem); - QCOMPARE(layout->count(), 1); + QVERIFY(!result.labelItem); + QCOMPARE(layout->count(), 2); QCOMPARE(layout->rowCount(), 1); + QCOMPARE(result.fieldItem->widget(), w2.data()); result = layout->takeRow(0); QVERIFY(w1); QVERIFY(result.fieldItem); - QVERIFY(!result.labelItem); + QVERIFY(result.labelItem); QCOMPARE(layout->count(), 0); QCOMPARE(layout->rowCount(), 0); + QCOMPARE(result.fieldItem->widget(), w1.data()); result = layout->takeRow(0); |