Skip to content

Commit

Permalink
Fixes #46790 : make it clear when feature count is estimated
Browse files Browse the repository at this point in the history
  • Loading branch information
troopa81 authored and nyalldawson committed Nov 19, 2022
1 parent a46b015 commit 858e8a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -179,8 +179,12 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
if ( nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
const bool estimatedCount = QgsDataSourceUri( vlayer->dataProvider()->dataSourceUri() ).useEstimatedMetadata();

if ( vlayer && vlayer->featureCount() >= 0 )
name += QStringLiteral( " [%1]" ).arg( vlayer->featureCount() );
name += QStringLiteral( " [%1%2]" ).arg(
estimatedCount ? QStringLiteral( "~" ) : QString(),
QLocale().toString( vlayer->featureCount() ) );
}
return name;
}
Expand Down Expand Up @@ -315,6 +319,14 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const

parts << "<i>" + source.toHtmlEscaped() + "</i>";

QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
const bool showFeatureCount = nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toBool();
const bool estimatedCount = QgsDataSourceUri( layer->dataProvider()->dataSourceUri() ).useEstimatedMetadata();
if ( showFeatureCount && estimatedCount )
{
parts << "<b>Feature Count is estimated</b> : Please consider keeping database statistics up to date";
}

return parts.join( QLatin1String( "<br/>" ) );
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -840,8 +840,12 @@ void QgsSymbolLegendNode::updateLabel()

if ( showFeatureCount && vl )
{
const bool estimatedCount = QgsDataSourceUri( vl->dataProvider()->dataSourceUri() ).useEstimatedMetadata();

const qlonglong count = mEmbeddedInParent ? vl->featureCount() : vl->featureCount( mItem.ruleKey() ) ;
mLabel += QStringLiteral( " [%1]" ).arg( count != -1 ? QLocale().toString( count ) : tr( "N/A" ) );
mLabel += QStringLiteral( " [%1%2]" ).arg(
estimatedCount ? QStringLiteral( "~" ) : QString(),
count != -1 ? QLocale().toString( count ) : tr( "N/A" ) );
}

emit dataChanged();
Expand Down

0 comments on commit 858e8a1

Please sign in to comment.