Skip to content

Commit

Permalink
Merge pull request #50425 from qgis/backport-50256-to-queued_ltr_back…
Browse files Browse the repository at this point in the history
…ports

[Backport queued_ltr_backports] Make it clear when feature count is estimated
  • Loading branch information
troopa81 committed Nov 7, 2022
2 parents b9601b0 + a7e0dc6 commit ef1fbd6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -176,11 +176,16 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
QString name = nodeLayer->name();
if ( nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() && role == Qt::DisplayRole )
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
if ( vlayer && nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
if ( vlayer && vlayer->featureCount() >= 0 )
name += QStringLiteral( " [%1]" ).arg( vlayer->featureCount() );
const bool estimatedCount = QgsDataSourceUri( vlayer->dataProvider()->dataSourceUri() ).useEstimatedMetadata();
const qlonglong count = vlayer->featureCount();

// if you modify this line, please update QgsSymbolLegendNode::updateLabel
name += QStringLiteral( " [%1%2]" ).arg(
estimatedCount ? QStringLiteral( "" ) : QString(),
count != -1 ? QLocale().toString( count ) : tr( "N/A" ) );
}
return name;
}
Expand Down Expand Up @@ -315,6 +320,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 << tr( "<b>Feature count is estimated</b> : the feature count is determined by the database statistics" );
}

return parts.join( QLatin1String( "<br/>" ) );
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -840,8 +840,13 @@ 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" ) );

// if you modify this line, please update QgsLayerTreeModel::data (DisplayRole)
mLabel += QStringLiteral( " [%1%2]" ).arg(
estimatedCount ? QStringLiteral( "" ) : QString(),
count != -1 ? QLocale().toString( count ) : tr( "N/A" ) );
}

emit dataChanged();
Expand Down

0 comments on commit ef1fbd6

Please sign in to comment.