Skip to content
Permalink
Browse files

Allow Constraint widget in attribute type form to be empty so express…

…ion could be removed (#9229)

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

* Change 'since' version to 3.4.6
  • Loading branch information
troopa81 authored and 3nids committed Mar 12, 2019
1 parent 83a0e00 commit 48068c26c0b7f3faeeba44b5e50492e216f23f83
@@ -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.4.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.4.6
%End

void setLeftHandButtonStyle( bool isLeft );
@@ -89,6 +89,7 @@ QgsAttributeTypeDialog::QgsAttributeTypeDialog( QgsVectorLayer *vl, int fieldIdx
QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/QgsAttributeTypeDialog/geometry" ) ).toByteArray() );

constraintExpressionWidget->setAllowEmptyFieldName( true );
constraintExpressionWidget->setLayer( vl );
}

@@ -82,6 +82,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() );
@@ -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.4.6
*/
void setAllowEmptyFieldName( bool allowEmpty );

/**
* Returns true if the combo box allows the empty field ("not set") choice.
* \see setAllowEmptyFieldName()
* \since QGIS 3.4.6
*/
bool allowEmptyFieldName() const;

void setLeftHandButtonStyle( bool isLeft );

//! currently used filter on list of fields
@@ -332,5 +332,3 @@ void TestQgsFieldExpressionWidget::setNull()

QGSTEST_MAIN( TestQgsFieldExpressionWidget )
#include "testqgsfieldexpressionwidget.moc"


0 comments on commit 48068c2

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