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>
This commit is contained in:
Christian Ehrlicher 2019-12-11 19:48:53 +01:00
parent 4689e198e7
commit 0edd2e39ad
2 changed files with 13 additions and 8 deletions

View File

@ -1627,8 +1627,7 @@ 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;
int top = range.top();
@ -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();

View File

@ -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()