Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[snapping] Invalidate the filtered layer tree model when a parent group switches from empty/non-empty state #59668

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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