summaryrefslogtreecommitdiffstats
path: root/src/widgets/itemviews/qtreewidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/itemviews/qtreewidget.cpp')
-rw-r--r--src/widgets/itemviews/qtreewidget.cpp40
1 files changed, 30 insertions, 10 deletions
diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp
index 762a19126e..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);
}
@@ -2909,7 +2912,7 @@ void QTreeWidget::editItem(QTreeWidgetItem *item, int column)
/*!
Opens a persistent editor for the \a item in the given \a column.
- \sa closePersistentEditor()
+ \sa closePersistentEditor(), isPersistentEditorOpen()
*/
void QTreeWidget::openPersistentEditor(QTreeWidgetItem *item, int column)
@@ -2924,7 +2927,7 @@ void QTreeWidget::openPersistentEditor(QTreeWidgetItem *item, int column)
This function has no effect if no persistent editor is open for this
combination of item and column.
- \sa openPersistentEditor()
+ \sa openPersistentEditor(), isPersistentEditorOpen()
*/
void QTreeWidget::closePersistentEditor(QTreeWidgetItem *item, int column)
@@ -2934,6 +2937,21 @@ void QTreeWidget::closePersistentEditor(QTreeWidgetItem *item, int column)
}
/*!
+ \since 5.10
+
+ Returns whether a persistent editor is open for item \a item in
+ column \a column.
+
+ \sa openPersistentEditor(), closePersistentEditor()
+*/
+
+bool QTreeWidget::isPersistentEditorOpen(QTreeWidgetItem *item, int column) const
+{
+ Q_D(const QTreeWidget);
+ return QAbstractItemView::isPersistentEditorOpen(d->index(item, column));
+}
+
+/*!
\since 4.1
Returns the widget displayed in the cell specified by \a item and the given \a column.
@@ -3354,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
@@ -3362,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.