Skip to content
Permalink
Browse files

Fix #8758 (graduated classes on expression broken)

  • Loading branch information
wonder-sk committed Feb 12, 2014
1 parent 18b1bdb commit a64610186173c0b274cebcc9a858efcd0680057c
Showing with 23 additions and 7 deletions.
  1. +23 −7 src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
@@ -641,6 +641,9 @@ static QList<double> _calcJenksBreaks( QList<double> values, int classes,
// Returns class breaks such that classes are internally homogeneous while
// assuring heterogeneity among classes.

if ( !values.count() )
return QList<double>();

if ( classes <= 1 )
{
return QList<double>() << maximum;
@@ -772,15 +775,22 @@ QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::createRenderer(
int attrNum = vlayer->fieldNameIndex( attrName );
double minimum;
double maximum;

QScopedPointer<QgsExpression> expression;

if ( attrNum == -1 )
{
// try to use expression
expression.reset( new QgsExpression( attrName ) );
if ( expression->hasParserError() || !expression->prepare( vlayer->pendingFields() ) )
return 0; // should have a means to report errors

QList<double> values;
QgsFeatureIterator fit = vlayer->getFeatures();
QgsFeature feature;
QgsExpression expression( attrName );
while ( fit.nextFeature( feature ) )
{
values << expression.evaluate( feature ).toDouble();
values << expression->evaluate( feature ).toDouble();
}
qSort( values );
minimum = values.first();
@@ -808,15 +818,21 @@ QgsGraduatedSymbolRendererV2* QgsGraduatedSymbolRendererV2::createRenderer(
// get values from layer
QList<double> values;
QgsFeature f;
QgsAttributeList lst;
lst.append( attrNum );
QStringList lst;
if ( expression.isNull() )
lst.append( attrName );
else
lst = expression->referencedColumns();

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( lst ) );
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ).setSubsetOfAttributes( lst, vlayer->pendingFields() ) );

// create list of non-null attribute values
while ( fit.nextFeature( f ) )
if ( !f.attribute( attrNum ).isNull() )
values.append( f.attribute( attrNum ).toDouble() );
{
QVariant v = expression.isNull() ? f.attribute( attrNum ) : expression->evaluate( f );
if ( !v.isNull() )
values.append( v.toDouble() );
}

// calculate the breaks
if ( mode == Quantile )

0 comments on commit a646101

Please sign in to comment.
You can’t perform that action at this time.