From 0edd2e39ad7f959c3d0c56e79abd3c60d9950538 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Wed, 11 Dec 2019 19:48:53 +0100 Subject: Let QItemSelectionModel::columnIntersectsSelection honor the parent QItemSelectionModel::columnIntersectsSelection() should honor the parent according to the docs. For rowIntersectsSelection() this was fixed a long time ago but columnIntersectsSelection() was forgotten. Sync the both functions and use range-based for loops as a drive-by. Fixes: QTBUG-80644 Change-Id: Iaf08f85e2225204d1e6564fa4bb0bc826352ed53 Reviewed-by: Friedemann Kleint Reviewed-by: Richard Moe Gustavsen --- src/corelib/itemmodels/qitemselectionmodel.cpp | 17 +++++++++-------- .../qitemselectionmodel/tst_qitemselectionmodel.cpp | 4 ++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index c93a4d15b9..ebcc3b10ca 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -1627,10 +1627,9 @@ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &par QItemSelection sel = d->ranges; sel.merge(d->currentSelection, d->currentCommand); - for (int i = 0; i < sel.count(); ++i) { - QItemSelectionRange range = sel.at(i); + for (const QItemSelectionRange &range : qAsConst(sel)) { if (range.parent() != parent) - return false; + return false; int top = range.top(); int bottom = range.bottom(); int left = range.left(); @@ -1661,11 +1660,13 @@ bool QItemSelectionModel::columnIntersectsSelection(int column, const QModelInde QItemSelection sel = d->ranges; sel.merge(d->currentSelection, d->currentCommand); - for (int i = 0; i < sel.count(); ++i) { - int left = sel.at(i).left(); - int right = sel.at(i).right(); - int top = sel.at(i).top(); - int bottom = sel.at(i).bottom(); + for (const QItemSelectionRange &range : qAsConst(sel)) { + if (range.parent() != parent) + return false; + int top = range.top(); + int bottom = range.bottom(); + int left = range.left(); + int right = range.right(); if (left <= column && right >= column) { for (int j = top; j <= bottom; j++) { const Qt::ItemFlags flags = d->model->index(j, column, parent).flags(); diff --git a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp index c74101928a..80e5456306 100644 --- a/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp +++ b/tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp @@ -2037,12 +2037,16 @@ void tst_QItemSelectionModel::rowIntersectsSelection3() QModelIndex parent; QVERIFY(!selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(!selectionModel.columnIntersectsSelection(0, parent)); parent = model.index(0, 0, parent); QVERIFY(selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(selectionModel.columnIntersectsSelection(0, parent)); parent = model.index(0, 0, parent); QVERIFY(!selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(!selectionModel.columnIntersectsSelection(0, parent)); parent = model.index(0, 0, parent); QVERIFY(!selectionModel.rowIntersectsSelection(0, parent)); + QVERIFY(!selectionModel.columnIntersectsSelection(0, parent)); } void tst_QItemSelectionModel::unselectable() -- cgit v1.2.3