From 95d299a3feb55d9db8225154aab8fe9c38925f60 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Thu, 2 Feb 2023 11:14:52 +1000 Subject: [PATCH] Fix crash when showing tooltips for invalid layers --- src/core/layertree/qgslayertreemodel.cpp | 4 ++-- src/core/layertree/qgslayertreemodellegendnode.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/layertree/qgslayertreemodel.cpp b/src/core/layertree/qgslayertreemodel.cpp index b7b4f6e188f7..14de4cd0cb76 100644 --- a/src/core/layertree/qgslayertreemodel.cpp +++ b/src/core/layertree/qgslayertreemodel.cpp @@ -180,7 +180,7 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const QgsVectorLayer *vlayer = qobject_cast( 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 @@ -323,7 +323,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( "Feature count is estimated : the feature count is determined by the database statistics" ); diff --git a/src/core/layertree/qgslayertreemodellegendnode.cpp b/src/core/layertree/qgslayertreemodellegendnode.cpp index 3a1f9a22878b..ea0d26b60a6a 100644 --- a/src/core/layertree/qgslayertreemodellegendnode.cpp +++ b/src/core/layertree/qgslayertreemodellegendnode.cpp @@ -875,7 +875,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)