From b1757d3965820b93d4ccb566ee449966bc104617 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Thu, 3 Sep 2020 13:00:20 +0200 Subject: [PATCH] Update DD labels on drag&drop forms Also make sure label expressions are evaluated after form init. Fixes #38531 --- src/gui/qgsattributeform.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index 0ef55dc36df0..b1d4348dc4da 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -86,6 +86,7 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer *vl, const QgsFeature &featur connect( this, &QgsAttributeForm::modeChanged, this, &QgsAttributeForm::updateContainersVisibility ); updateContainersVisibility(); + updateLabels(); } @@ -2047,6 +2048,27 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt else { QLabel *mypLabel = new QLabel( widgetInfo.labelText ); + + // Alias DD overrides + if ( childDef->type() == QgsAttributeEditorElement::AeTypeField ) + { + const QgsAttributeEditorField *fieldDef { static_cast( childDef ) }; + const QgsFields fields = vl->fields(); + const int fldIdx = fieldDef->idx(); + if ( fldIdx < fields.count() && fldIdx >= 0 ) + { + const QString fieldName { fields.at( fldIdx ).name() }; + if ( mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).hasProperty( QgsEditFormConfig::DataDefinedProperty::Alias ) ) + { + const QgsProperty property { mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).property( QgsEditFormConfig::DataDefinedProperty::Alias ) }; + if ( property.isActive() && ! property.expressionString().isEmpty() ) + { + mLabelDataDefinedProperties[ mypLabel ] = property; + } + } + } + } + mypLabel->setToolTip( widgetInfo.toolTip ); if ( columnCount > 1 && !widgetInfo.labelOnTop ) {