Skip to content

Commit

Permalink
fix QgsLayerTreeModel::refreshLayerLegend (#9785)
Browse files Browse the repository at this point in the history
* fix QgsLayerTreeModel::refreshLayerLegend

Guard if the QModelIndex (idx) has no children.

* Update qgslayertreemodel.cpp

* Update qgslayertreemodel.cpp

* Update qgslayertreemodel.cpp

* Apply suggestions from code review

Co-Authored-By: vcloarec <vcloarec@gmail.com>
  • Loading branch information
vcloarec authored and m-kuhn committed Apr 16, 2019
1 parent 891ea18 commit bed3da4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/core/layertree/qgslayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,12 @@ void QgsLayerTreeModel::refreshLayerLegend( QgsLayerTreeLayer *nodeLayer )

// update children
int oldNodeCount = rowCount( idx );
beginRemoveRows( idx, 0, std::max( oldNodeCount - 1, 0 ) );
removeLegendFromLayer( nodeLayer );
endRemoveRows();
if ( oldNodeCount > 0 )
{
beginRemoveRows( idx, 0, oldNodeCount - 1 );
removeLegendFromLayer( nodeLayer );
endRemoveRows();
}

addLegendToLayer( nodeLayer );
int newNodeCount = rowCount( idx );
Expand Down

0 comments on commit bed3da4

Please sign in to comment.