Skip to content

Commit 1c34329

Browse files
troopa813nids
authored andcommitted
Allow expression widget to be empty so expression could be removed (#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
1 parent eceaea8 commit 1c34329

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

python/gui/auto_generated/qgsfieldexpressionwidget.sip.in

+18
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ Returns the title used for the expression dialog
5555
void setFilters( QgsFieldProxyModel::Filters filters );
5656
%Docstring
5757
setFilters allows fitering according to the type of field
58+
%End
59+
60+
void setAllowEmptyFieldName( bool allowEmpty );
61+
%Docstring
62+
Sets whether an optional empty field ("not set") option is shown in the combo box.
63+
64+
.. seealso:: :py:func:`allowEmptyFieldName`
65+
66+
.. versionadded:: 3.6
67+
%End
68+
69+
bool allowEmptyFieldName() const;
70+
%Docstring
71+
Returns true if the combo box allows the empty field ("not set") choice.
72+
73+
.. seealso:: :py:func:`setAllowEmptyFieldName`
74+
75+
.. versionadded:: 3.6
5876
%End
5977

6078
void setLeftHandButtonStyle( bool isLeft );

src/app/qgsattributetypedialog.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
9191
QgsSettings settings;
9292
restoreGeometry( settings.value( QStringLiteral( "Windows/QgsAttributeTypeDialog/geometry" ) ).toByteArray() );
9393

94+
constraintExpressionWidget->setAllowEmptyFieldName( true );
9495
constraintExpressionWidget->setLayer( vl );
9596
}
9697

src/gui/qgsfieldexpressionwidget.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ void QgsFieldExpressionWidget::setFilters( QgsFieldProxyModel::Filters filters )
8383
mFieldProxyModel->setFilters( filters );
8484
}
8585

86+
void QgsFieldExpressionWidget::setAllowEmptyFieldName( bool allowEmpty )
87+
{
88+
mCombo->lineEdit()->setClearButtonEnabled( allowEmpty );
89+
mFieldProxyModel->sourceFieldModel()->setAllowEmptyFieldName( allowEmpty );
90+
}
91+
92+
bool QgsFieldExpressionWidget::allowEmptyFieldName() const
93+
{
94+
return mFieldProxyModel->sourceFieldModel()->allowEmptyFieldName();
95+
}
96+
8697
void QgsFieldExpressionWidget::setLeftHandButtonStyle( bool isLeft )
8798
{
8899
QHBoxLayout *layout = dynamic_cast<QHBoxLayout *>( this->layout() );

src/gui/qgsfieldexpressionwidget.h

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
4848
Q_OBJECT
4949
Q_PROPERTY( QString expressionDialogTitle READ expressionDialogTitle WRITE setExpressionDialogTitle )
5050
Q_PROPERTY( QgsFieldProxyModel::Filters filters READ filters WRITE setFilters )
51+
Q_PROPERTY( bool allowEmptyFieldName READ allowEmptyFieldName WRITE setAllowEmptyFieldName )
5152
Q_PROPERTY( bool allowEvalErrors READ allowEvalErrors WRITE setAllowEvalErrors NOTIFY allowEvalErrorsChanged )
5253

5354
public:
@@ -75,6 +76,20 @@ class GUI_EXPORT QgsFieldExpressionWidget : public QWidget
7576
//! setFilters allows fitering according to the type of field
7677
void setFilters( QgsFieldProxyModel::Filters filters );
7778

79+
/**
80+
* Sets whether an optional empty field ("not set") option is shown in the combo box.
81+
* \see allowEmptyFieldName()
82+
* \since QGIS 3.6
83+
*/
84+
void setAllowEmptyFieldName( bool allowEmpty );
85+
86+
/**
87+
* Returns true if the combo box allows the empty field ("not set") choice.
88+
* \see setAllowEmptyFieldName()
89+
* \since QGIS 3.6
90+
*/
91+
bool allowEmptyFieldName() const;
92+
7893
void setLeftHandButtonStyle( bool isLeft );
7994

8095
//! currently used filter on list of fields

tests/src/gui/testqgsfieldexpressionwidget.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -332,5 +332,3 @@ void TestQgsFieldExpressionWidget::setNull()
332332

333333
QGSTEST_MAIN( TestQgsFieldExpressionWidget )
334334
#include "testqgsfieldexpressionwidget.moc"
335-
336-

0 commit comments

Comments
 (0)