Skip to content

Commit

Permalink
[snapping] Invalidate the filtered layer tree model when a parent gro…
Browse files Browse the repository at this point in the history
…up switches from empty/non-empty state
  • Loading branch information
nirvn committed Nov 30, 2024
1 parent dd49296 commit 10b8875
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/app/qgssnappinglayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,33 @@ QgsLayerTreeModel *QgsSnappingLayerTreeModel::layerTreeModel() const

void QgsSnappingLayerTreeModel::setLayerTreeModel( QgsLayerTreeModel *layerTreeModel )
{
if ( mLayerTreeModel )
{
disconnect( mLayerTreeModel, &QAbstractItemModel::rowsInserted, this, &QgsSnappingLayerTreeModel::onNodesInserted );
disconnect( mLayerTreeModel, &QAbstractItemModel::rowsRemoved, this, &QgsSnappingLayerTreeModel::onNodesRemoved );
}

mLayerTreeModel = layerTreeModel;
QSortFilterProxyModel::setSourceModel( layerTreeModel );

connect( mLayerTreeModel, &QAbstractItemModel::rowsInserted, this, &QgsSnappingLayerTreeModel::onNodesInserted );
connect( mLayerTreeModel, &QAbstractItemModel::rowsRemoved, this, &QgsSnappingLayerTreeModel::onNodesRemoved );
}

void QgsSnappingLayerTreeModel::onNodesInserted( const QModelIndex &parent, int first, int last )
{
if ( mLayerTreeModel->rowCount( parent ) - ( last - first + 1 ) <= 0 )
{
invalidateFilter();
}
}

void QgsSnappingLayerTreeModel::onNodesRemoved( const QModelIndex &parent, int, int )
{
if ( mLayerTreeModel->rowCount( parent ) == 0 )
{
invalidateFilter();
}
}

bool QgsSnappingLayerTreeModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const
Expand Down
2 changes: 2 additions & 0 deletions src/app/qgssnappinglayertreemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class APP_EXPORT QgsSnappingLayerTreeModel : public QSortFilterProxyModel
void onSnappingSettingsChanged();

private:
void onNodesInserted( const QModelIndex &parent, int first, int last );
void onNodesRemoved( const QModelIndex &parent, int first, int last );
bool nodeShown( QgsLayerTreeNode *node ) const;

QgsProject *mProject = nullptr;
Expand Down

0 comments on commit 10b8875

Please sign in to comment.