diff options
Diffstat (limited to 'src/widgets/itemviews/qtreewidget.cpp')
-rw-r--r-- | src/widgets/itemviews/qtreewidget.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index b253abac73..de7f7c0b77 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -145,7 +145,7 @@ QTreeModel::QTreeModel(QTreeModelPrivate &dd, QTreeWidget *parent) QTreeModel::~QTreeModel() { clear(); - headerItem->view = Q_NULLPTR; + headerItem->view = nullptr; delete headerItem; rootItem->view = 0; delete rootItem; @@ -2012,6 +2012,9 @@ void QTreeWidgetItem::addChildren(const QList<QTreeWidgetItem*> &children) */ void QTreeWidgetItem::insertChildren(int index, const QList<QTreeWidgetItem*> &children) { + if (index < 0 || index > this->children.count() || children.isEmpty()) + return; + if (view && view->isSortingEnabled()) { for (int n = 0; n < children.count(); ++n) insertChild(index, children.at(n)); @@ -2729,14 +2732,14 @@ void QTreeWidget::setHeaderItem(QTreeWidgetItem *item) int oldCount = columnCount(); if (oldCount < item->columnCount()) - d->treeModel()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount()); - else - d->treeModel()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount); + d->treeModel()->beginInsertColumns(QModelIndex(), oldCount, item->columnCount() - 1); + else if (oldCount > item->columnCount()) + d->treeModel()->beginRemoveColumns(QModelIndex(), item->columnCount(), oldCount - 1); delete d->treeModel()->headerItem; d->treeModel()->headerItem = item; if (oldCount < item->columnCount()) d->treeModel()->endInsertColumns(); - else + else if (oldCount > item->columnCount()) d->treeModel()->endRemoveColumns(); d->treeModel()->headerDataChanged(Qt::Horizontal, 0, oldCount); } @@ -2859,11 +2862,11 @@ QRect QTreeWidget::visualItemRect(const QTreeWidgetItem *item) const Q_D(const QTreeWidget); //the visual rect for an item is across all columns. So we need to determine //what is the first and last column and get their visual index rects - QModelIndex base = d->index(item); + const QModelIndex base = d->index(item); const int firstVisiblesection = header()->logicalIndexAt(- header()->offset()); const int lastVisibleSection = header()->logicalIndexAt(header()->length() - header()->offset() - 1); - QModelIndex first = base.sibling(base.row(), header()->logicalIndex(firstVisiblesection)); - QModelIndex last = base.sibling(base.row(), header()->logicalIndex(lastVisibleSection)); + const QModelIndex first = base.sibling(base.row(), firstVisiblesection); + const QModelIndex last = base.sibling(base.row(), lastVisibleSection); return visualRect(first) | visualRect(last); } @@ -3369,6 +3372,7 @@ QModelIndex QTreeWidget::indexFromItem(const QTreeWidgetItem *item, int column) return d->index(item, column); } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) /*! \overload \internal @@ -3377,6 +3381,7 @@ QModelIndex QTreeWidget::indexFromItem(QTreeWidgetItem *item, int column) const { return indexFromItem(const_cast<const QTreeWidgetItem *>(item), column); } +#endif /*! Returns a pointer to the QTreeWidgetItem associated with the given \a index. |