From ba6e0e4aac4d06782325c7032c8ea475f2d3eab0 Mon Sep 17 00:00:00 2001 From: David Faure Date: Sat, 13 Apr 2019 19:37:37 +0200 Subject: QHeaderView: fix assert when restoring section sizes over less columns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If columns are removed and we get notified via layoutChanged, the code tries to restore old section sizes, and went out of bounds, leading to an assert in QVector. Simply add an if() to skip restoring out-of-bounds columns. This comes from https://bugs.kde.org/show_bug.cgi?id=395181, which translates into the unittest that is part of this commit. Change-Id: Ide42176a758f87b21957c40508127d67f1d5a2d9 Reviewed-by: Christian Ehrlicher Reviewed-by: Thorbjørn Lund Martsum --- src/widgets/itemviews/qheaderview.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index 62abf56751..99309633a7 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2283,13 +2283,15 @@ void QHeaderViewPrivate::_q_sectionsChanged(const QList & : index.row()); // the new visualIndices are already adjusted / reset by initializeSections() const int newVisualIndex = visualIndex(newLogicalIndex); - auto &newSection = sectionItems[newVisualIndex]; - newSection = item.section; - - if (newSection.isHidden) { - // otherwise setSectionHidden will return without doing anything - newSection.isHidden = false; - q->setSectionHidden(newLogicalIndex, true); + if (newVisualIndex < sectionItems.count()) { + auto &newSection = sectionItems[newVisualIndex]; + newSection = item.section; + + if (newSection.isHidden) { + // otherwise setSectionHidden will return without doing anything + newSection.isHidden = false; + q->setSectionHidden(newLogicalIndex, true); + } } } -- cgit v1.2.3 From ed66c932b1460ce5dcb3f7f1cb4c37f726683175 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 15 Apr 2019 21:07:40 +0200 Subject: QListWidgetItem constructors: don't emit dataChanged(invalid, invalid) This is a regression introduced by 63967313f57add which blocked signals on the view, but not on the model. Change-Id: Ib2f93fe6ef842264aaba200c98ee4a19065ca220 Reviewed-by: Shawn Rutledge Reviewed-by: Konstantin Shegunov Reviewed-by: Laurent Montel Reviewed-by: Christian Ehrlicher --- src/widgets/itemviews/qlistwidget.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qlistwidget.cpp b/src/widgets/itemviews/qlistwidget.cpp index a9899983c2..e46d25bef1 100644 --- a/src/widgets/itemviews/qlistwidget.cpp +++ b/src/widgets/itemviews/qlistwidget.cpp @@ -650,11 +650,13 @@ QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *listview, int |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled) { + QListModel *model = listModel(); { QSignalBlocker b(view); + QSignalBlocker bm(model); setData(Qt::DisplayRole, text); } - if (QListModel *model = listModel()) + if (model) model->insert(model->rowCount(), this); } @@ -683,12 +685,14 @@ QListWidgetItem::QListWidgetItem(const QIcon &icon,const QString &text, |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled) { + QListModel *model = listModel(); { QSignalBlocker b(view); + QSignalBlocker bm(model); setData(Qt::DisplayRole, text); setData(Qt::DecorationRole, icon); } - if (QListModel *model = listModel()) + if (model) model->insert(model->rowCount(), this); } -- cgit v1.2.3