From c23980c72a496472025eb6225f1ab96ce51b7b1f Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 24 Jul 2018 10:44:31 +0200 Subject: [PATCH] BaseTreeView: Robustify Check for selection and model before accessing them. Change-Id: If8e8e43f00c5812bce7a21639c3d3bee459117f3 Reviewed-by: Ulf Hermann --- src/libs/utils/basetreeview.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/libs/utils/basetreeview.cpp b/src/libs/utils/basetreeview.cpp index 6e5d2668554..bae4c16fef9 100644 --- a/src/libs/utils/basetreeview.cpp +++ b/src/libs/utils/basetreeview.cpp @@ -309,6 +309,7 @@ void BaseTreeView::setModel(QAbstractItemModel *m) void BaseTreeView::mousePressEvent(QMouseEvent *ev) { ItemViewEvent ive(ev, this); + QTC_ASSERT(model(), return); if (!model()->setData(ive.index(), QVariant::fromValue(ive), ItemViewEventRole)) TreeView::mousePressEvent(ev); // Resizing columns by clicking on the empty space seems to be controversial. @@ -321,6 +322,7 @@ void BaseTreeView::mousePressEvent(QMouseEvent *ev) void BaseTreeView::mouseReleaseEvent(QMouseEvent *ev) { ItemViewEvent ive(ev, this); + QTC_ASSERT(model(), return); if (!model()->setData(ive.index(), QVariant::fromValue(ive), ItemViewEventRole)) TreeView::mouseReleaseEvent(ev); } @@ -444,15 +446,17 @@ ItemViewEvent::ItemViewEvent(QEvent *ev, QAbstractItemView *view) m_index = view->indexAt(m_pos); break; default: - m_index = selection->currentIndex(); + m_index = selection ? selection->currentIndex() : QModelIndex(); break; } - m_selectedRows = selection->selectedRows(); - if (m_selectedRows.isEmpty()) { - QModelIndex current = selection->currentIndex(); - if (current.isValid()) - m_selectedRows.append(current); + if (selection) { + m_selectedRows = selection->selectedRows(); + if (m_selectedRows.isEmpty()) { + QModelIndex current = selection->currentIndex(); + if (current.isValid()) + m_selectedRows.append(current); + } } }