Skip to content
Permalink
Browse files
[statistics] In the stats panel, fix hard-coded expression return val…
…ue as numerical
  • Loading branch information
nirvn committed Aug 30, 2021
1 parent 5c35b1c commit a3db48a82428116d73c48bb3aafbed14aff97229
Showing with 40 additions and 0 deletions.
  1. +40 −0 src/app/qgsstatisticalsummarydockwidget.cpp
@@ -159,6 +159,46 @@ void QgsStatisticalSummaryDockWidget::refreshStatistics()
{
mFieldType = fieldType( mFieldExpressionWidget->currentField() );
}
else
{
QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
QgsExpression expression( mFieldExpressionWidget->expression() );
QgsFeatureRequest request = QgsFeatureRequest();
request.setFlags( ( expression.needsGeometry() ) ?
QgsFeatureRequest::NoFlags :
QgsFeatureRequest::NoGeometry );
request.setLimit( 10 );
request.setExpressionContext( context );


QgsFeature f;
QgsFeatureIterator it = mSelectedOnlyCheckBox->isChecked() ? mLayer->getSelectedFeatures( request ) : mLayer->getFeatures( request );
bool hasFeature = it.nextFeature( f );
while ( hasFeature )
{
context.setFeature( f );
const QVariant v = expression.evaluate( &context );
if ( !v.isNull() )
{
switch ( v.type() )
{
case QVariant::String:
mFieldType = DataType::String;
break;
case QVariant::Date:
case QVariant::DateTime:
mFieldType = DataType::DateTime;
break;
default:
mFieldType = DataType::Numeric;
break;
}
break;
}
hasFeature = it.nextFeature( f );
}
}

if ( mFieldType != mPreviousFieldType )
{

0 comments on commit a3db48a

Please sign in to comment.