Skip to content
Permalink
Browse files

Ensure correct expression context is shown in expression builder

for form container visibility

(cherry picked from commit f56327a)
  • Loading branch information
nyalldawson committed Apr 20, 2020
1 parent 79b82c3 commit baee39ff464394f4211bf99751941c7471d021d7
@@ -48,6 +48,11 @@ QgsAttributeFormContainerEdit::QgsAttributeFormContainerEdit( QTreeWidgetItem *i
connect( mShowAsGroupBoxCheckBox, &QCheckBox::stateChanged, mShowLabelCheckBox, &QCheckBox::setEnabled );
}

void QgsAttributeFormContainerEdit::registerExpressionContextGenerator( QgsExpressionContextGenerator *generator )
{
mVisibilityExpressionWidget->registerExpressionContextGenerator( generator );
}

void QgsAttributeFormContainerEdit::updateItemData()
{
QgsAttributesFormProperties::DnDTreeItemData itemData = mTreeItem->data( 0, QgsAttributesFormProperties::DnDTreeRole ).value<QgsAttributesFormProperties::DnDTreeItemData>();
@@ -34,12 +34,17 @@ class APP_EXPORT QgsAttributeFormContainerEdit: public QWidget, private Ui_QgsAt
public:
explicit QgsAttributeFormContainerEdit( QTreeWidgetItem *item, QWidget *parent = nullptr );

/**
* Register an expression context generator class that will be used to retrieve
* an expression context for the widget when required.
* \since QGIS 3.14
*/
void registerExpressionContextGenerator( QgsExpressionContextGenerator *generator );

void updateItemData();


private:
QTreeWidgetItem *mTreeItem;
QTreeWidgetItem *mTreeItem = nullptr;
};

#endif // QGSATTRIBUTEFORMCONTAINEREDIT_H
@@ -26,6 +26,7 @@
#include "qgsapplication.h"
#include "qgscolorbutton.h"
#include "qgscodeeditorhtml.h"
#include "qgsexpressioncontextutils.h"


QgsAttributesFormProperties::QgsAttributesFormProperties( QgsVectorLayer *layer, QWidget *parent )
@@ -183,9 +184,15 @@ void QgsAttributesFormProperties::initSuppressCombo()
mFormSuppressCmbBx->addItem( tr( "Show form on add feature" ) );

mFormSuppressCmbBx->setCurrentIndex( mLayer->editFormConfig().suppress() );
}


QgsExpressionContext QgsAttributesFormProperties::createExpressionContext() const
{
QgsExpressionContext context;
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
return context;
}

void QgsAttributesFormProperties::initLayoutConfig()
{
mEditorLayoutComboBox->setCurrentIndex( mEditorLayoutComboBox->findData( mLayer->editFormConfig().layout() ) );
@@ -428,6 +435,7 @@ void QgsAttributesFormProperties::loadAttributeContainerEdit()

QTreeWidgetItem *currentItem = mFormLayoutTree->selectedItems().at( 0 );
mAttributeContainerEdit = new QgsAttributeFormContainerEdit( currentItem, this );
mAttributeContainerEdit->registerExpressionContextGenerator( this );
mAttributeContainerEdit->layout()->setContentsMargins( 0, 0, 0, 0 );
mAttributeTypeFrame->layout()->setContentsMargins( 0, 0, 0, 0 );
mAttributeTypeFrame->layout()->addWidget( mAttributeContainerEdit );
@@ -52,7 +52,7 @@ class QgsAttributeRelationEdit;
class QgsAttributeWidgetEdit;
class DnDTree;

class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAttributesFormProperties
class APP_EXPORT QgsAttributesFormProperties : public QWidget, public QgsExpressionContextGenerator, private Ui_QgsAttributesFormProperties
{
Q_OBJECT

@@ -208,6 +208,8 @@ class APP_EXPORT QgsAttributesFormProperties : public QWidget, private Ui_QgsAtt
void initInitPython();
void initSuppressCombo();

QgsExpressionContext createExpressionContext() const override;

protected:
void updateButtons();

0 comments on commit baee39f

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