Fix stale index hanging around in RDTreeView after change

This commit is contained in:
baldurk
2020-03-18 12:01:37 +00:00
parent f8143c6dc5
commit 15a2753d63
2 changed files with 23 additions and 2 deletions
+18 -1
View File
@@ -226,7 +226,24 @@ QAbstractItemDelegate *RDTreeView::itemDelegate() const
return m_userDelegate;
}
void RDTreeView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
void RDTreeView::setModel(QAbstractItemModel *model)
{
QAbstractItemModel *old = this->model();
if(old)
QObject::disconnect(old, &QAbstractItemModel::modelAboutToBeReset, this,
&RDTreeView::modelAboutToBeReset);
QTreeView::setModel(model);
if(model)
{
QObject::connect(model, &QAbstractItemModel::modelAboutToBeReset, this,
&RDTreeView::modelAboutToBeReset);
}
}
void RDTreeView::modelAboutToBeReset()
{
m_currentHoverIndex = QModelIndex();
}
+5 -1
View File
@@ -91,6 +91,8 @@ public:
void setItemDelegate(QAbstractItemDelegate *delegate);
QAbstractItemDelegate *itemDelegate() const;
void setModel(QAbstractItemModel *model) override;
// state is the storage to save the expansion state into
// keygen is a function that will take the index of a row and a previous hash, and return the hash
// for that row.
@@ -124,7 +126,6 @@ signals:
void keyPress(QKeyEvent *e);
protected:
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) override;
void mouseMoveEvent(QMouseEvent *e) override;
void wheelEvent(QWheelEvent *e) override;
void leaveEvent(QEvent *e) override;
@@ -139,6 +140,9 @@ protected:
void enableBranchRectFill(bool fill) { m_fillBranchRect = fill; }
QModelIndex m_currentHoverIndex;
private slots:
void modelAboutToBeReset();
private:
bool m_VisibleBranches = true;
bool m_VisibleGridLines = true;