diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-05-02 13:15:15 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2018-05-02 13:15:15 +0200 |
commit | 7de400052f7df52095103f56f1cb753854be1af1 (patch) | |
tree | 823c01302efd5d2181a3b3a55eb2937e52c849b1 /src/corelib/itemmodels | |
parent | 8b098e6544221a96bc6a41a6bfcc0dfa7cf805e6 (diff) | |
parent | 364bd6ca74b059ffe8ae367e1562645a3ed0855e (diff) |
Merge remote-tracking branch 'origin/5.11' into dev
Change-Id: Ia082e20e2eb4b76afd4c1a1584ff4e5514655d7a
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 69 |
1 files changed, 46 insertions, 23 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 9af4fd9133..edb9bb9098 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -1502,30 +1502,40 @@ bool QItemSelectionModel::isRowSelected(int row, const QModelIndex &parent) cons && d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid()) return false; } + + auto isSelectable = [&](int row, int column) { + Qt::ItemFlags flags = d->model->index(row, column, parent).flags(); + return (flags & Qt::ItemIsSelectable); + }; + + const int colCount = d->model->columnCount(parent); + int unselectable = 0; // add ranges and currentSelection and check through them all QList<QItemSelectionRange>::const_iterator it; QList<QItemSelectionRange> joined = d->ranges; if (d->currentSelection.count()) joined += d->currentSelection; - int colCount = d->model->columnCount(parent); for (int column = 0; column < colCount; ++column) { + if (!isSelectable(row, column)) { + ++unselectable; + continue; + } + for (it = joined.constBegin(); it != joined.constEnd(); ++it) { if ((*it).contains(row, column, parent)) { - bool selectable = false; - for (int i = column; !selectable && i <= (*it).right(); ++i) { - Qt::ItemFlags flags = d->model->index(row, i, parent).flags(); - selectable = flags & Qt::ItemIsSelectable; - } - if (selectable){ - column = qMax(column, (*it).right()); - break; + for (int i = column; i <= (*it).right(); ++i) { + if (!isSelectable(row, i)) + ++unselectable; } + + column = qMax(column, (*it).right()); + break; } } if (it == joined.constEnd()) return false; } - return colCount > 0; // no columns means no selected items + return unselectable < colCount; } /*! @@ -1568,26 +1578,39 @@ bool QItemSelectionModel::isColumnSelected(int column, const QModelIndex &parent } } } + + auto isSelectable = [&](int row, int column) { + Qt::ItemFlags flags = d->model->index(row, column, parent).flags(); + return (flags & Qt::ItemIsSelectable); + }; + const int rowCount = d->model->rowCount(parent); + int unselectable = 0; + // add ranges and currentSelection and check through them all QList<QItemSelectionRange>::const_iterator it; QList<QItemSelectionRange> joined = d->ranges; if (d->currentSelection.count()) joined += d->currentSelection; - int rowCount = d->model->rowCount(parent); for (int row = 0; row < rowCount; ++row) { - for (it = joined.constBegin(); it != joined.constEnd(); ++it) { - if ((*it).contains(row, column, parent)) { - Qt::ItemFlags flags = d->model->index(row, column, parent).flags(); - if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) { - row = qMax(row, (*it).bottom()); - break; - } - } - } - if (it == joined.constEnd()) - return false; + if (!isSelectable(row, column)) { + ++unselectable; + continue; + } + for (it = joined.constBegin(); it != joined.constEnd(); ++it) { + if ((*it).contains(row, column, parent)) { + for (int i = row; i <= (*it).bottom(); ++i) { + if (!isSelectable(i, column)) { + ++unselectable; + } + } + row = qMax(row, (*it).bottom()); + break; + } + } + if (it == joined.constEnd()) + return false; } - return rowCount > 0; // no rows means no selected items + return unselectable < rowCount; } /*! |