diff --git a/python/gui/auto_generated/qgsfieldexpressionwidget.sip.in b/python/gui/auto_generated/qgsfieldexpressionwidget.sip.in index b16a7009a6a..ed7d2e761f5 100644 --- a/python/gui/auto_generated/qgsfieldexpressionwidget.sip.in +++ b/python/gui/auto_generated/qgsfieldexpressionwidget.sip.in @@ -55,6 +55,24 @@ Returns the title used for the expression dialog void setFilters( QgsFieldProxyModel::Filters filters ); %Docstring setFilters allows fitering according to the type of field +%End + + void setAllowEmptyFieldName( bool allowEmpty ); +%Docstring +Sets whether an optional empty field ("not set") option is shown in the combo box. + +.. seealso:: :py:func:`allowEmptyFieldName` + +.. versionadded:: 3.6 +%End + + bool allowEmptyFieldName() const; +%Docstring +Returns true if the combo box allows the empty field ("not set") choice. + +.. seealso:: :py:func:`setAllowEmptyFieldName` + +.. versionadded:: 3.6 %End void setLeftHandButtonStyle( bool isLeft ); diff --git a/src/app/qgsattributetypedialog.cpp b/src/app/qgsattributetypedialog.cpp index fa06e64f484..e9910d91304 100644 --- a/src/app/qgsattributetypedialog.cpp +++ b/src/app/qgsattributetypedialog.cpp @@ -91,6 +91,7 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx QgsSettings settings; restoreGeometry( settings.value( QStringLiteral( "Windows/QgsAttributeTypeDialog/geometry" ) ).toByteArray() ); + constraintExpressionWidget->setAllowEmptyFieldName( true ); constraintExpressionWidget->setLayer( vl ); } diff --git a/src/gui/qgsfieldexpressionwidget.cpp b/src/gui/qgsfieldexpressionwidget.cpp index 6ca1ee0f14f..8e2a4ff6004 100644 --- a/src/gui/qgsfieldexpressionwidget.cpp +++ b/src/gui/qgsfieldexpressionwidget.cpp @@ -83,6 +83,17 @@ void QgsFieldExpressionWidget::setFilters( QgsFieldProxyModel::Filters filters ) mFieldProxyModel->setFilters( filters ); } +void QgsFieldExpressionWidget::setAllowEmptyFieldName( bool allowEmpty ) +{ + mCombo->lineEdit()->setClearButtonEnabled( allowEmpty ); + mFieldProxyModel->sourceFieldModel()->setAllowEmptyFieldName( allowEmpty ); +} + +bool QgsFieldExpressionWidget::allowEmptyFieldName() const +{ + return mFieldProxyModel->sourceFieldModel()->allowEmptyFieldName(); +} + void QgsFieldExpressionWidget::setLeftHandButtonStyle( bool isLeft ) { QHBoxLayout *layout = dynamic_cast( this->layout() ); diff --git a/src/gui/qgsfieldexpressionwidget.h b/src/gui/qgsfieldexpressionwidget.h index 40cb7b66600..aaaa8aefef8 100644 --- a/src/gui/qgsfieldexpressionwidget.h +++ b/src/gui/qgsfieldexpressionwidget.h @@ -48,6 +48,7 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget Q_OBJECT Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle ) Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters ) + Q_PROPERTY( bool allowEmptyFieldName READ allowEmptyFieldName WRITE setAllowEmptyFieldName ) Q_PROPERTY( bool allowEvalErrors READ allowEvalErrors WRITE setAllowEvalErrors NOTIFY allowEvalErrorsChanged ) public: @@ -75,6 +76,20 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget //! setFilters allows fitering according to the type of field void setFilters( QgsFieldProxyModel::Filters filters ); + /** + * Sets whether an optional empty field ("not set") option is shown in the combo box. + * \see allowEmptyFieldName() + * \since QGIS 3.6 + */ + void setAllowEmptyFieldName( bool allowEmpty ); + + /** + * Returns true if the combo box allows the empty field ("not set") choice. + * \see setAllowEmptyFieldName() + * \since QGIS 3.6 + */ + bool allowEmptyFieldName() const; + void setLeftHandButtonStyle( bool isLeft ); //! currently used filter on list of fields diff --git a/tests/src/gui/testqgsfieldexpressionwidget.cpp b/tests/src/gui/testqgsfieldexpressionwidget.cpp index e27b920bf9e..ec8c6dec3f8 100644 --- a/tests/src/gui/testqgsfieldexpressionwidget.cpp +++ b/tests/src/gui/testqgsfieldexpressionwidget.cpp @@ -332,5 +332,3 @@ void TestQgsFieldExpressionWidget::setNull() QGSTEST_MAIN( TestQgsFieldExpressionWidget ) #include "testqgsfieldexpressionwidget.moc" - -