Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also make label property dialog understand coalesce type properties
  • Loading branch information
nyalldawson committed Sep 28, 2021
1 parent 5660e70 commit 41f0918
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/app/labeling/qgslabelpropertydialog.cpp
Expand Up @@ -322,6 +322,28 @@ int QgsLabelPropertyDialog::dataDefinedColumnIndex( QgsPalLayerSettings::Propert
const QgsExpressionNodeColumnRef *columnRef = qgis::down_cast<const QgsExpressionNodeColumnRef *>( node );
fieldName = columnRef->name();
}
// ok, it's not. But let's be super smart and helpful for users!
// maybe it's a COALESCE("some field", 'some' || 'fallback' || 'expression') type expression, where the user wants to override
// some labels with a value stored in a field but all others use some expression
else if ( node->nodeType() == QgsExpressionNode::ntFunction )
{
const QgsExpressionNodeFunction *functionNode = qgis::down_cast<const QgsExpressionNodeFunction *>( node );
if ( const QgsExpressionFunction *function = QgsExpression::QgsExpression::Functions()[functionNode->fnIndex()] )
{
if ( function->name() == QLatin1String( "coalesce" ) )
{
if ( const QgsExpressionNode *firstArg = functionNode->args()->list().value( 0 ) )
{
const QgsExpressionNode *firstArgNode = firstArg->effectiveNode();
if ( firstArgNode->nodeType() == QgsExpressionNode::ntColumnRef )
{
const QgsExpressionNodeColumnRef *columnRef = qgis::down_cast<const QgsExpressionNodeColumnRef *>( firstArgNode );
fieldName = columnRef->name();
}
}
}
}
}
}
break;
}
Expand Down

0 comments on commit 41f0918

Please sign in to comment.