Skip to content

Commit e497a5c

Browse files
committed
labeling: consider configure representation for NULL values (fixes #9998)
1 parent 8e6c043 commit e497a5c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/core/qgspallabeling.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,17 @@ QgsPalLayerSettings::QgsPalLayerSettings()
449449

450450
// temp stuff for when drawing label components (don't copy)
451451
showingShadowRects = false;
452+
453+
QSettings settings;
454+
mNullValue = settings.value( "qgis/nullValue", "NULL" ).toString();
452455
}
453456

454457
QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
455458
{
456459
// copy only permanent stuff
457460

458461
enabled = s.enabled;
462+
mNullValue = s.mNullValue;
459463

460464
// text style
461465
fieldName = s.fieldName;
@@ -1702,11 +1706,12 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
17021706
QgsDebugMsgLevel( QString( "Expression parser eval error:%1" ).arg( exp->evalErrorString() ), 4 );
17031707
return;
17041708
}
1705-
labelText = result.toString();
1709+
labelText = result.isNull() ? mNullValue : result.toString();
17061710
}
17071711
else
17081712
{
1709-
labelText = f.attribute( fieldIndex ).toString();
1713+
const QVariant &v = f.attribute( fieldIndex );
1714+
labelText = v.isNull() ? mNullValue : v.toString();
17101715
}
17111716

17121717
// data defined format numbers?
@@ -1741,7 +1746,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
17411746
QgsDebugMsgLevel( QString( "exprVal NumPlusSign:%1" ).arg( signPlus ? "true" : "false" ), 4 );
17421747
}
17431748

1744-
QVariant textV = QVariant( labelText );
1749+
QVariant textV( labelText );
17451750
bool ok;
17461751
double d = textV.toDouble( &ok );
17471752
if ( ok )

src/core/qgspallabeling.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ class CORE_EXPORT QgsPalLayerSettings
550550
QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > mDataDefinedNames;
551551

552552
QFontDatabase mFontDB;
553+
QString mNullValue;
553554
};
554555

555556
class CORE_EXPORT QgsLabelCandidate

0 commit comments

Comments
 (0)