Skip to content

Commit

Permalink
Fix crash when showing tooltips for invalid layers
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and jef-n committed Feb 3, 2023
1 parent ef17ad1 commit 7fd5f65
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core/layertree/qgslayertreemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
if ( vlayer && nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() && role == Qt::DisplayRole )
{
const bool estimatedCount = QgsDataSourceUri( vlayer->dataProvider()->dataSourceUri() ).useEstimatedMetadata();
const bool estimatedCount = vlayer->dataProvider() ? QgsDataSourceUri( vlayer->dataProvider()->dataSourceUri() ).useEstimatedMetadata() : false;
const qlonglong count = vlayer->featureCount();

// if you modify this line, please update QgsSymbolLegendNode::updateLabel
Expand Down Expand Up @@ -322,7 +322,7 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const

QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
const bool showFeatureCount = nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toBool();
const bool estimatedCount = QgsDataSourceUri( layer->dataProvider()->dataSourceUri() ).useEstimatedMetadata();
const bool estimatedCount = layer->dataProvider() ? QgsDataSourceUri( layer->dataProvider()->dataSourceUri() ).useEstimatedMetadata() : false;
if ( showFeatureCount && estimatedCount )
{
parts << tr( "<b>Feature count is estimated</b> : the feature count is determined by the database statistics" );
Expand Down
2 changes: 1 addition & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ void QgsSymbolLegendNode::updateLabel()

if ( showFeatureCount && vl )
{
const bool estimatedCount = QgsDataSourceUri( vl->dataProvider()->dataSourceUri() ).useEstimatedMetadata();
const bool estimatedCount = vl->dataProvider() ? QgsDataSourceUri( vl->dataProvider()->dataSourceUri() ).useEstimatedMetadata() : false;
const qlonglong count = mEmbeddedInParent ? vl->featureCount() : vl->featureCount( mItem.ruleKey() ) ;

// if you modify this line, please update QgsLayerTreeModel::data (DisplayRole)
Expand Down

0 comments on commit 7fd5f65

Please sign in to comment.