Skip to content
Permalink
Browse files

Cache snapping results in feature dialog for subsequent recalculation of

References #37359
  • Loading branch information
m-kuhn committed Jul 11, 2020
1 parent 2e2acf9 commit 15182ae4183354dbe56ecf375a62b7242a1c8a6c
@@ -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 an additional expression context scope to be used
for calculations in this form.

.. versionadded:: 3.16
%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.16
%End

signals:
@@ -65,6 +65,9 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )

QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, f, cloneFeature, parentWidget(), true, context );
dialog->setWindowFlags( dialog->windowFlags() | Qt::Tool );
if ( scope )
dialog->setExtraContextScope( new QgsExpressionContextScope( *scope ) );


dialog->setObjectName( QStringLiteral( "featureactiondlg:%1:%2" ).arg( mLayer->id() ).arg( f->id() ) );

@@ -255,6 +258,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 an additional expression context scope to be used
* for calculations in this form.
*
* \since QGIS 3.16
*/
void setExtraContextScope( QgsExpressionContextScope *extraScope SIP_TRANSFER );

public slots:
void accept() override;
void reject() override;
@@ -516,7 +516,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 );
}
}
@@ -832,6 +833,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 )
{
@@ -950,10 +962,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() );
@@ -966,10 +975,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;

@@ -1017,10 +1023,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 )
{
@@ -2380,6 +2383,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.16
*/
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;

0 comments on commit 15182ae

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