Skip to content
Permalink
Browse files

Merge pull request #37848 from qgis-bot/backport-37769-to-release-3_14

[Backport release-3_14] Cache snapping results in feature dialog for subsequent recalculation
  • Loading branch information
m-kuhn committed Jul 17, 2020
2 parents 8d0b564 + df8e2e0 commit 371153735236dce5e560d2f174b2e8259d023c2d
@@ -73,6 +73,14 @@ Intercept window activate/deactivate events to show/hide the highlighted feature
:param e: The event

:return: The same as the parent QDialog
%End

void setExtraContextScope( QgsExpressionContextScope *extraScope /Transfer/ );
%Docstring
Sets ``extraScope`` as an additional expression context scope to be used
for calculations in this form.

.. versionadded:: 3.14.1
%End

public slots:
@@ -167,6 +167,14 @@ In this case it will return a combined expression according to the chosen filter
on all attribute widgets.

.. versionadded:: 3.0
%End

void setExtraContextScope( QgsExpressionContextScope *extraScope /Transfer/ );
%Docstring
Sets an additional expression context scope to be used
for calculations in this form.

.. versionadded:: 3.14.1
%End

signals:
@@ -294,7 +302,6 @@ have filter expressions that depend on the parent form scope.

};


/************************************************************************
* This file has been generated automatically from *
* *
@@ -254,6 +254,8 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo
dialog->setAttribute( Qt::WA_DeleteOnClose );
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
dialog->setEditCommandMessage( text() );
if ( scope )
dialog->setExtraContextScope( new QgsExpressionContextScope( *scope ) );

connect( dialog->attributeForm(), &QgsAttributeForm::featureSaved, this, &QgsFeatureAction::onFeatureSaved );

@@ -148,3 +148,8 @@ bool QgsAttributeDialog::event( QEvent *e )

return QDialog::event( e );
}

void QgsAttributeDialog::setExtraContextScope( QgsExpressionContextScope *extraScope )
{
mAttributeForm->setExtraContextScope( extraScope );
}
@@ -95,6 +95,14 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog
*/
bool event( QEvent *e ) override;

/**
* Sets \a extraScope as an additional expression context scope to be used
* for calculations in this form.
*
* \since QGIS 3.14.1
*/
void setExtraContextScope( QgsExpressionContextScope *extraScope SIP_TRANSFER );

public slots:
void accept() override;
void reject() override;
@@ -530,7 +530,8 @@ bool QgsAttributeForm::updateDefaultValues( const int originIdx )
if ( mAlreadyUpdatedFields.contains( eww->fieldIdx() ) )
continue;

QString value = mLayer->defaultValue( eww->fieldIdx(), updatedFeature ).toString();
QgsExpressionContext context = createExpressionContext( updatedFeature );
QString value = mLayer->defaultValue( eww->fieldIdx(), updatedFeature, &context ).toString();
eww->setValue( value );
}
}
@@ -848,6 +849,17 @@ QString QgsAttributeForm::createFilterExpression() const
return filter;
}

QgsExpressionContext QgsAttributeForm::createExpressionContext( const QgsFeature &feature ) const
{
QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.appendScope( QgsExpressionContextUtils::formScope( feature, mContext.attributeFormModeString() ) );
if ( mExtraContextScope )
context.appendScope( new QgsExpressionContextScope( *mExtraContextScope.get() ) );
context.setFeature( feature );
return context;
}


void QgsAttributeForm::onAttributeChanged( const QVariant &value, const QVariantList &additionalFieldValues )
{
@@ -967,10 +979,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
// sync OK button status
synchronizeEnabledState();

QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.appendScope( QgsExpressionContextUtils::formScope( ft, mContext.attributeFormModeString() ) );
context.setFeature( ft );
QgsExpressionContext context = createExpressionContext( ft );

// Recheck visibility for all containers which are controlled by this value
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
@@ -983,10 +992,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )

void QgsAttributeForm::updateContainersVisibility()
{
QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.appendScope( QgsExpressionContextUtils::formScope( mFeature, mContext.attributeFormModeString() ) );
context.setFeature( mFeature );
QgsExpressionContext context = createExpressionContext( mFeature );

const QVector<ContainerInformation *> infos = mContainerVisibilityInformation;

@@ -1034,10 +1040,7 @@ void QgsAttributeForm::updateLabels()
QgsFeature currentFeature;
if ( currentFormFeature( currentFeature ) )
{
QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
context.appendScope( QgsExpressionContextUtils::formScope( currentFeature, mContext.attributeFormModeString() ) );
context.setFeature( currentFeature );
QgsExpressionContext context = createExpressionContext( currentFeature );

for ( auto it = mLabelDataDefinedProperties.constBegin() ; it != mLabelDataDefinedProperties.constEnd(); ++it )
{
@@ -2398,6 +2401,11 @@ QString QgsAttributeForm::aggregateFilter() const
return filters.join( QStringLiteral( " AND " ) );
}

void QgsAttributeForm::setExtraContextScope( QgsExpressionContextScope *extraScope )
{
mExtraContextScope.reset( extraScope );
}

int QgsAttributeForm::messageTimeout()
{
QgsSettings settings;
@@ -183,6 +183,14 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
*/
QString aggregateFilter() const;

/**
* Sets an additional expression context scope to be used
* for calculations in this form.
*
* \since QGIS 3.14.1
*/
void setExtraContextScope( QgsExpressionContextScope *extraScope SIP_TRANSFER );

signals:

/**
@@ -387,6 +395,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget

QString createFilterExpression() const;

QgsExpressionContext createExpressionContext( const QgsFeature &feature ) const;

//! constraints management
void updateAllConstraints();
void updateConstraints( QgsEditorWidgetWrapper *w );
@@ -407,6 +417,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
QgsMessageBarItem *mMultiEditMessageBarItem = nullptr;
QList<QgsWidgetWrapper *> mWidgets;
QgsAttributeEditorContext mContext;
std::unique_ptr<QgsExpressionContextScope> mExtraContextScope;
QDialogButtonBox *mButtonBox = nullptr;
QWidget *mSearchButtonBox = nullptr;
QList<QgsAttributeFormInterface *> mInterfaces;
@@ -487,4 +498,3 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
};

#endif // QGSATTRIBUTEFORM_H

0 comments on commit 3711537

Please sign in to comment.
You can’t perform that action at this time.