mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-28 00:06:23 -05:00
Cache snapping results in feature dialog for subsequent recalculation of
References #37359
This commit is contained in:
parent
2e2acf9170
commit
15182ae418
@ -73,6 +73,14 @@ Intercept window activate/deactivate events to show/hide the highlighted feature
|
|||||||
:param e: The event
|
:param e: The event
|
||||||
|
|
||||||
:return: The same as the parent QDialog
|
: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
|
%End
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
@ -167,6 +167,14 @@ In this case it will return a combined expression according to the chosen filter
|
|||||||
on all attribute widgets.
|
on all attribute widgets.
|
||||||
|
|
||||||
.. versionadded:: 3.0
|
.. 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
|
%End
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|||||||
@ -65,6 +65,9 @@ QgsAttributeDialog *QgsFeatureAction::newDialog( bool cloneFeature )
|
|||||||
|
|
||||||
QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, f, cloneFeature, parentWidget(), true, context );
|
QgsAttributeDialog *dialog = new QgsAttributeDialog( mLayer, f, cloneFeature, parentWidget(), true, context );
|
||||||
dialog->setWindowFlags( dialog->windowFlags() | Qt::Tool );
|
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() ) );
|
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->setAttribute( Qt::WA_DeleteOnClose );
|
||||||
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
|
dialog->setMode( QgsAttributeEditorContext::AddFeatureMode );
|
||||||
dialog->setEditCommandMessage( text() );
|
dialog->setEditCommandMessage( text() );
|
||||||
|
if ( scope )
|
||||||
|
dialog->setExtraContextScope( new QgsExpressionContextScope( *scope ) );
|
||||||
|
|
||||||
connect( dialog->attributeForm(), &QgsAttributeForm::featureSaved, this, &QgsFeatureAction::onFeatureSaved );
|
connect( dialog->attributeForm(), &QgsAttributeForm::featureSaved, this, &QgsFeatureAction::onFeatureSaved );
|
||||||
|
|
||||||
|
|||||||
@ -148,3 +148,8 @@ bool QgsAttributeDialog::event( QEvent *e )
|
|||||||
|
|
||||||
return QDialog::event( 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;
|
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:
|
public slots:
|
||||||
void accept() override;
|
void accept() override;
|
||||||
void reject() override;
|
void reject() override;
|
||||||
|
|||||||
@ -516,7 +516,8 @@ bool QgsAttributeForm::updateDefaultValues( const int originIdx )
|
|||||||
if ( mAlreadyUpdatedFields.contains( eww->fieldIdx() ) )
|
if ( mAlreadyUpdatedFields.contains( eww->fieldIdx() ) )
|
||||||
continue;
|
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 );
|
eww->setValue( value );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -832,6 +833,17 @@ QString QgsAttributeForm::createFilterExpression() const
|
|||||||
return filter;
|
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 )
|
void QgsAttributeForm::onAttributeChanged( const QVariant &value, const QVariantList &additionalFieldValues )
|
||||||
{
|
{
|
||||||
@ -950,10 +962,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
|
|||||||
// sync OK button status
|
// sync OK button status
|
||||||
synchronizeEnabledState();
|
synchronizeEnabledState();
|
||||||
|
|
||||||
QgsExpressionContext context;
|
QgsExpressionContext context = createExpressionContext( ft );
|
||||||
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
|
|
||||||
context.appendScope( QgsExpressionContextUtils::formScope( ft, mContext.attributeFormModeString() ) );
|
|
||||||
context.setFeature( ft );
|
|
||||||
|
|
||||||
// Recheck visibility for all containers which are controlled by this value
|
// Recheck visibility for all containers which are controlled by this value
|
||||||
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
|
const QVector<ContainerInformation *> infos = mContainerInformationDependency.value( eww->field().name() );
|
||||||
@ -966,10 +975,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww )
|
|||||||
|
|
||||||
void QgsAttributeForm::updateContainersVisibility()
|
void QgsAttributeForm::updateContainersVisibility()
|
||||||
{
|
{
|
||||||
QgsExpressionContext context;
|
QgsExpressionContext context = createExpressionContext( mFeature );
|
||||||
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
|
|
||||||
context.appendScope( QgsExpressionContextUtils::formScope( mFeature, mContext.attributeFormModeString() ) );
|
|
||||||
context.setFeature( mFeature );
|
|
||||||
|
|
||||||
const QVector<ContainerInformation *> infos = mContainerVisibilityInformation;
|
const QVector<ContainerInformation *> infos = mContainerVisibilityInformation;
|
||||||
|
|
||||||
@ -1017,10 +1023,7 @@ void QgsAttributeForm::updateLabels()
|
|||||||
QgsFeature currentFeature;
|
QgsFeature currentFeature;
|
||||||
if ( currentFormFeature( currentFeature ) )
|
if ( currentFormFeature( currentFeature ) )
|
||||||
{
|
{
|
||||||
QgsExpressionContext context;
|
QgsExpressionContext context = createExpressionContext( currentFeature );
|
||||||
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
|
|
||||||
context.appendScope( QgsExpressionContextUtils::formScope( currentFeature, mContext.attributeFormModeString() ) );
|
|
||||||
context.setFeature( currentFeature );
|
|
||||||
|
|
||||||
for ( auto it = mLabelDataDefinedProperties.constBegin() ; it != mLabelDataDefinedProperties.constEnd(); ++it )
|
for ( auto it = mLabelDataDefinedProperties.constBegin() ; it != mLabelDataDefinedProperties.constEnd(); ++it )
|
||||||
{
|
{
|
||||||
@ -2380,6 +2383,11 @@ QString QgsAttributeForm::aggregateFilter() const
|
|||||||
return filters.join( QStringLiteral( " AND " ) );
|
return filters.join( QStringLiteral( " AND " ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgsAttributeForm::setExtraContextScope( QgsExpressionContextScope *extraScope )
|
||||||
|
{
|
||||||
|
mExtraContextScope.reset( extraScope );
|
||||||
|
}
|
||||||
|
|
||||||
int QgsAttributeForm::messageTimeout()
|
int QgsAttributeForm::messageTimeout()
|
||||||
{
|
{
|
||||||
QgsSettings settings;
|
QgsSettings settings;
|
||||||
|
|||||||
@ -183,6 +183,14 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
*/
|
*/
|
||||||
QString aggregateFilter() const;
|
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:
|
signals:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,6 +395,8 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
|
|
||||||
QString createFilterExpression() const;
|
QString createFilterExpression() const;
|
||||||
|
|
||||||
|
QgsExpressionContext createExpressionContext( const QgsFeature &feature ) const;
|
||||||
|
|
||||||
//! constraints management
|
//! constraints management
|
||||||
void updateAllConstraints();
|
void updateAllConstraints();
|
||||||
void updateConstraints( QgsEditorWidgetWrapper *w );
|
void updateConstraints( QgsEditorWidgetWrapper *w );
|
||||||
@ -407,6 +417,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget
|
|||||||
QgsMessageBarItem *mMultiEditMessageBarItem = nullptr;
|
QgsMessageBarItem *mMultiEditMessageBarItem = nullptr;
|
||||||
QList<QgsWidgetWrapper *> mWidgets;
|
QList<QgsWidgetWrapper *> mWidgets;
|
||||||
QgsAttributeEditorContext mContext;
|
QgsAttributeEditorContext mContext;
|
||||||
|
std::unique_ptr<QgsExpressionContextScope> mExtraContextScope;
|
||||||
QDialogButtonBox *mButtonBox = nullptr;
|
QDialogButtonBox *mButtonBox = nullptr;
|
||||||
QWidget *mSearchButtonBox = nullptr;
|
QWidget *mSearchButtonBox = nullptr;
|
||||||
QList<QgsAttributeFormInterface *> mInterfaces;
|
QList<QgsAttributeFormInterface *> mInterfaces;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user