diff options
author | Liang Qi <liang.qi@qt.io> | 2017-11-30 12:57:22 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-11-30 12:57:22 +0000 |
commit | c35342ffeba10deecb2d8c0ce30a3a1a4ec1ee8d (patch) | |
tree | 0b7782b3d8973d20ee4db36f768367b94e3d3394 /src/widgets/itemviews | |
parent | 7200572b393534a2f503b810180276d2ae809c7a (diff) | |
parent | 87204c856ae3d8495c41af998ac196a12fe1c779 (diff) |
Merge "Merge remote-tracking branch 'origin/5.10' into dev" into refs/staging/dev
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qheaderview.cpp | 34 | ||||
-rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 3 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreeview.cpp | 24 |
3 files changed, 32 insertions, 29 deletions
diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 463ed7e58c..c7966f624f 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2086,40 +2086,26 @@ void QHeaderViewPrivate::_q_layoutChanged() { Q_Q(QHeaderView); viewport->update(); - if (persistentHiddenSections.isEmpty() || modelIsEmpty()) { - if (modelSectionCount() != sectionCount()) - q->initializeSections(); - persistentHiddenSections.clear(); + + const auto hiddenSections = persistentHiddenSections; + persistentHiddenSections.clear(); + + clear(); + q->initializeSections(); + invalidateCachedSizeHint(); + + if (modelIsEmpty()) { return; } - QBitArray oldSectionHidden = sectionsHiddenToBitVector(); - oldSectionHidden.resize(sectionItems.size()); - bool sectionCountChanged = false; - - for (int i = 0; i < persistentHiddenSections.count(); ++i) { - QModelIndex index = persistentHiddenSections.at(i); + for (const auto &index : hiddenSections) { if (index.isValid()) { const int logical = (orientation == Qt::Horizontal ? index.column() : index.row()); q->setSectionHidden(logical, true); - oldSectionHidden.setBit(logical, false); - } else if (!sectionCountChanged && (modelSectionCount() != sectionCount())) { - sectionCountChanged = true; - break; } } - persistentHiddenSections.clear(); - - for (int i = 0; i < oldSectionHidden.count(); ++i) { - if (oldSectionHidden.testBit(i)) - q->setSectionHidden(i, false); - } - - // the number of sections changed; we need to reread the state of the model - if (sectionCountChanged) - q->initializeSections(); } /*! diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index d42ed0ad19..fd3bdfd065 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -1397,6 +1397,9 @@ void QTableView::paintEvent(QPaintEvent *event) } else { dirtyArea.setRight(qMin(dirtyArea.right(), int(x))); } + // dirtyArea may be invalid when the horizontal header is not stretched + if (!dirtyArea.isValid()) + continue; // get the horizontal start and end visual sections int left = horizontalHeader->visualIndexAt(dirtyArea.left()); diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index d504263bd1..6ea180dcf2 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -736,7 +736,10 @@ void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &botto void QTreeView::hideColumn(int column) { Q_D(QTreeView); + if (d->header->isSectionHidden(column)) + return; d->header->hideSection(column); + doItemsLayout(); } /*! @@ -747,7 +750,10 @@ void QTreeView::hideColumn(int column) void QTreeView::showColumn(int column) { Q_D(QTreeView); + if (!d->header->isSectionHidden(column)) + return; d->header->showSection(column); + doItemsLayout(); } /*! @@ -1008,11 +1014,16 @@ void QTreeView::keyboardSearch(const QString &search) if (!d->model->rowCount(d->root) || !d->model->columnCount(d->root)) return; + // Do a relayout nows, so that we can utilize viewItems + d->executePostedLayout(); + if (d->viewItems.isEmpty()) + return; + QModelIndex start; if (currentIndex().isValid()) start = currentIndex(); else - start = d->model->index(0, 0, d->root); + start = d->viewItems.at(0).index; bool skipRow = false; bool keyboardTimeWasValid = d->keyboardInputTime.isValid(); @@ -1040,13 +1051,16 @@ void QTreeView::keyboardSearch(const QString &search) // skip if we are searching for the same key or a new search started if (skipRow) { - if (indexBelow(start).isValid()) + if (indexBelow(start).isValid()) { start = indexBelow(start); - else - start = d->model->index(0, start.column(), d->root); + } else { + const int origCol = start.column(); + start = d->viewItems.at(0).index; + if (origCol != start.column()) + start = start.sibling(start.row(), origCol); + } } - d->executePostedLayout(); int startIndex = d->viewIndex(start); if (startIndex <= -1) return; |