forked from qt-creator/qt-creator
BaseTreeView: Robustify
Check for selection and model before accessing them. Change-Id: If8e8e43f00c5812bce7a21639c3d3bee459117f3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
@@ -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,16 +446,18 @@ 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;
|
||||
}
|
||||
|
||||
if (selection) {
|
||||
m_selectedRows = selection->selectedRows();
|
||||
if (m_selectedRows.isEmpty()) {
|
||||
QModelIndex current = selection->currentIndex();
|
||||
if (current.isValid())
|
||||
m_selectedRows.append(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QModelIndexList ItemViewEvent::currentOrSelectedRows() const
|
||||
|
Reference in New Issue
Block a user