Skip to content

Commit

Permalink
Tag current_value and current_parent_value functions as not static
Browse files Browse the repository at this point in the history
... and use the new approach for dynamic labels
  • Loading branch information
elpaso committed Apr 15, 2020
1 parent 83e42f5 commit 6f3cac2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/core/expression/qgsexpressioncontextutils.cpp
Expand Up @@ -132,6 +132,11 @@ class GetCurrentFormFieldValue : public QgsScopedExpressionFunction
return new GetCurrentFormFieldValue( );
}

bool isStatic( const QgsExpressionNodeFunction *, QgsExpression *, const QgsExpressionContext * ) const override
{
return false;
};

};

class GetCurrentParentFormFieldValue : public QgsScopedExpressionFunction
Expand All @@ -157,6 +162,11 @@ class GetCurrentParentFormFieldValue : public QgsScopedExpressionFunction
return new GetCurrentParentFormFieldValue( );
}

bool isStatic( const QgsExpressionNodeFunction *, QgsExpression *, const QgsExpressionContext * ) const override
{
return false;
};

};


Expand Down
21 changes: 10 additions & 11 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -1009,20 +1009,21 @@ void QgsAttributeForm::updateConstraint( const QgsFeature &ft, QgsEditorWidgetWr

void QgsAttributeForm::updateLabels()
{
if ( ! mExpressionLabels.isEmpty() )
if ( ! mLabelDataDefinedProperties.isEmpty() )
{
QgsFeature currentFeature;
if ( currentFormFeature( currentFeature ) )
{
mExpressionContext << QgsExpressionContextUtils::formScope( currentFeature, mContext.attributeFormModeString() );
mExpressionContext.setFields( mLayer->fields() );
for ( auto it = mExpressionLabels.constBegin() ; it != mExpressionLabels.constEnd(); ++it )
for ( auto it = mLabelDataDefinedProperties.constBegin() ; it != mLabelDataDefinedProperties.constEnd(); ++it )
{
QLabel *label { it.key() };
QgsExpression exp { it.value() };
if ( exp.prepare( &mExpressionContext ) && ! exp.hasParserError() )
bool ok;
const QString value { it->valueAsString( mExpressionContext, QString(), &ok ) };
if ( ok && ! value.isEmpty() )
{
label->setText( exp.evaluate( &mExpressionContext ).toString() );
label->setText( value );
}
}
}
Expand Down Expand Up @@ -1482,10 +1483,9 @@ void QgsAttributeForm::init()
if ( mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).hasProperty( QgsEditFormConfig::DataDefinedProperty::Alias ) )
{
const QgsProperty property { mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).property( QgsEditFormConfig::DataDefinedProperty::Alias ) };
const QString labelExpression { property.asExpression() };
if ( ! labelExpression.isEmpty() && property.isActive() )
if ( property.isActive() && ! property.expressionString().isEmpty() )
{
mExpressionLabels[ label ] = QgsExpression( labelExpression );
mLabelDataDefinedProperties[ label ] = property;
}
}
}
Expand Down Expand Up @@ -1557,10 +1557,9 @@ void QgsAttributeForm::init()
if ( mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).hasProperty( QgsEditFormConfig::DataDefinedProperty::Alias ) )
{
const QgsProperty property { mLayer->editFormConfig().dataDefinedFieldProperties( fieldName ).property( QgsEditFormConfig::DataDefinedProperty::Alias ) };
const QString labelExpression { property.asExpression() };
if ( ! labelExpression.isEmpty() && property.isActive() )
if ( property.isActive() && ! property.expressionString().isEmpty() )
{
mExpressionLabels[ label ] = QgsExpression( labelExpression );
mLabelDataDefinedProperties[ label ] = property;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsattributeform.h
Expand Up @@ -414,7 +414,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
QList< QgsAttributeFormWidget *> mFormWidgets;
QgsExpressionContext mExpressionContext;
QMap<const QgsVectorLayerJoinInfo *, QgsFeature> mJoinedFeatures;
QMap<QLabel *, QgsExpression> mExpressionLabels;
QMap<QLabel *, QgsProperty> mLabelDataDefinedProperties;
bool mValuesInitialized = false;
bool mDirty = false;
bool mIsSettingFeature = false;
Expand Down

0 comments on commit 6f3cac2

Please sign in to comment.