Skip to content

Commit

Permalink
Update tooltip message and homogenize categorized item and layer
Browse files Browse the repository at this point in the history
legend feature count
  • Loading branch information
troopa81 authored and nyalldawson committed Nov 19, 2022
1 parent 858e8a1 commit 8c11d3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/core/layertree/qgslayertreemodel.cpp
Expand Up @@ -180,11 +180,12 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
const bool estimatedCount = QgsDataSourceUri( vlayer->dataProvider()->dataSourceUri() ).useEstimatedMetadata();
const qlonglong count = vlayer ? vlayer->featureCount() : -1;

if ( vlayer && vlayer->featureCount() >= 0 )
name += QStringLiteral( " [%1%2]" ).arg(
estimatedCount ? QStringLiteral( "~" ) : QString(),
QLocale().toString( 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 @@ -324,7 +325,8 @@ QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
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";
parts << QStringLiteral( "<b>%1</b> %2" ).arg(
tr( "Feature Count is estimated" ), tr( ": the feature count is determined by the database statistics" ) );
}

return parts.join( QLatin1String( "<br/>" ) );
Expand Down
5 changes: 3 additions & 2 deletions src/core/layertree/qgslayertreemodellegendnode.cpp
Expand Up @@ -841,10 +841,11 @@ void QgsSymbolLegendNode::updateLabel()
if ( showFeatureCount && vl )
{
const bool estimatedCount = QgsDataSourceUri( vl->dataProvider()->dataSourceUri() ).useEstimatedMetadata();

const qlonglong count = mEmbeddedInParent ? vl->featureCount() : vl->featureCount( mItem.ruleKey() ) ;

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

Expand Down

0 comments on commit 8c11d3c

Please sign in to comment.