Skip to content

Commit

Permalink
handle null
Browse files Browse the repository at this point in the history
  • Loading branch information
roya0045 authored and nyalldawson committed Feb 21, 2022
1 parent 3372009 commit 5850003
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/core/symbology/qgsrulebasedrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,15 +1202,17 @@ void QgsRuleBasedRenderer::refineRuleCategories( QgsRuleBasedRenderer::Rule *ini
{
QString value;
// not quoting numbers saves a type cast
if ( cat.value().type() == QVariant::Int )
if ( cat.value().isNull() )
value = "NULL";
else if ( cat.value().type() == QVariant::Int )
value = cat.value().toString();
else if ( cat.value().type() == QVariant::Double )
// we loose precision here - so we may miss some categories :-(
// TODO: have a possibility to construct expressions directly as a parse tree to avoid loss of precision
value = QString::number( cat.value().toDouble(), 'f', 4 );
else
value = QgsExpression::quotedString( cat.value().toString() );
const QString filter = QStringLiteral( "%1 = %2" ).arg( attr, value );
const QString filter = QStringLiteral( "%1 %2 %3" ).arg( attr, value == "NULL" ? "IS" : "=" , value );
const QString label = !cat.label().isEmpty() ? cat.label() :
cat.value().isValid() ? value : QString();
initialRule->appendChild( new Rule( cat.symbol()->clone(), 0, 0, filter, label ) );
Expand Down

0 comments on commit 5850003

Please sign in to comment.