Skip to content

Commit

Permalink
Allow expression widget to be empty so expression could be removed (#…
Browse files Browse the repository at this point in the history
…9032)

* fixes #20516 : Allow Constraint widget in attribute type form to be empty so expression could be removed

per widget modification

* correct tests

* Add the clear button on field expression widget when widget is allowed to be empty

* Change API since version to 3.6
  • Loading branch information
troopa81 authored and 3nids committed Feb 20, 2019
1 parent eceaea8 commit 1c34329
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
18 changes: 18 additions & 0 deletions python/gui/auto_generated/qgsfieldexpressionwidget.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsattributetypedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsfieldexpressionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QHBoxLayout *>( this->layout() );
Expand Down
15 changes: 15 additions & 0 deletions src/gui/qgsfieldexpressionwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/src/gui/testqgsfieldexpressionwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,5 +332,3 @@ void TestQgsFieldExpressionWidget::setNull()

QGSTEST_MAIN( TestQgsFieldExpressionWidget )
#include "testqgsfieldexpressionwidget.moc"


0 comments on commit 1c34329

Please sign in to comment.