summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-12-11 19:48:53 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2019-12-14 08:46:37 +0100
commit0edd2e39ad7f959c3d0c56e79abd3c60d9950538 (patch)
treefa0d9829d645f2aeb36cfacea3ff5e1b97767100
parent4689e198e76e054ef51254c0724064ba61408625 (diff)
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 <Friedemann.Kleint@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/corelib/itemmodels/qitemselectionmodel.cpp17
-rw-r--r--tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp4
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()