From 626a4d89c2aec6354db9602ad1816e7f7e13d9b1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 7 Feb 2017 21:21:59 +0100 Subject: QFormLayout: take the correct row in takeRow() I didn't even try to understand what the old code was trying to do; once you're told by a user that the code is wrong, you see that it is. Fixed by just using the row as passed to takeRow() instead of trying to do some storage-index calculations. The m_matrix indexing operator does it all for us. Added a test that checks that the expected field widget gets returned. Fixed expected test data that was wrong, and just checking that the implementation behaves as implemented, instead of as documented. Amends change 8fbae648db3bc51bafacfe1f88e40561d357e60a. [ChangeLog][QtWidget][QFormLayout] The functions takeRow() and removeRow(), new in 5.8.0, now take and remove the correct row. Task-number: QTBUG-58693 Task-number: QTBUG-15990 Change-Id: I7185ccbc6c03e2579741cad5c0c821d3ed165474 Reviewed-by: Friedemann Kleint --- src/widgets/kernel/qformlayout.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/widgets/kernel/qformlayout.cpp') 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(); -- cgit v1.2.3