From 31ac9be340e724ab777b2dc487a1a3817ed5b67c Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Fri, 13 Nov 2015 08:59:56 +0100 Subject: [PATCH] [search widgets] when selecting _Please select_ find all features --- .../editorwidgets/core/qgssearchwidgetwrapper.cpp | 5 +++++ src/gui/editorwidgets/core/qgssearchwidgetwrapper.h | 3 +++ .../qgsvaluemapsearchwidgetwrapper.cpp | 9 ++++++++- .../qgsvaluerelationsearchwidgetwrapper.cpp | 13 ++++++++++--- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp b/src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp index b666956c9df..74965e515ad 100644 --- a/src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp @@ -33,3 +33,8 @@ void QgsSearchWidgetWrapper::setFeature( const QgsFeature& feature ) Q_UNUSED( feature ) } +void QgsSearchWidgetWrapper::clearExpression() +{ + mExpression = QString( "TRUE" ); +} + diff --git a/src/gui/editorwidgets/core/qgssearchwidgetwrapper.h b/src/gui/editorwidgets/core/qgssearchwidgetwrapper.h index 6fefca63fcc..83d8ca72ef7 100644 --- a/src/gui/editorwidgets/core/qgssearchwidgetwrapper.h +++ b/src/gui/editorwidgets/core/qgssearchwidgetwrapper.h @@ -81,6 +81,9 @@ class GUI_EXPORT QgsSearchWidgetWrapper : public QgsWidgetWrapper void setFeature( const QgsFeature& feature ) override; protected: + //! clears the expression to search for all features + void clearExpression(); + QString mExpression; int mFieldIdx; diff --git a/src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp index a23b75f2709..368de908787 100644 --- a/src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp @@ -37,7 +37,14 @@ void QgsValueMapSearchWidgetWrapper::comboBoxIndexChanged( int idx ) { if ( mComboBox ) { - setExpression( mComboBox->itemData( idx ).toString() ); + if ( idx == 0 ) + { + clearExpression(); + } + else + { + setExpression( mComboBox->itemData( idx ).toString() ); + } emit expressionChanged( mExpression ); } } diff --git a/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp index 35221bf7dd9..2c0fb325c62 100644 --- a/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp @@ -97,8 +97,15 @@ bool QgsValueRelationSearchWidgetWrapper::valid() void QgsValueRelationSearchWidgetWrapper::valueChanged() { QVariant vl = value(); - QSettings settings; - setExpression( vl.isNull() ? settings.value( "qgis/nullValue", "NULL" ).toString() : vl.toString() ); + if ( !vl.isValid() ) + { + clearExpression(); + } + else + { + QSettings settings; + setExpression( vl.isNull() ? settings.value( "qgis/nullValue", "NULL" ).toString() : vl.toString() ); + } emit expressionChanged( mExpression ); } @@ -149,7 +156,7 @@ void QgsValueRelationSearchWidgetWrapper::initWidget( QWidget* editor ) if ( mComboBox ) { - mComboBox->addItem( tr( "Please select" ), QVariant( layer()->fields().at( mFieldIdx ).type() ) ); + mComboBox->addItem( tr( "Please select" ), QVariant() ); // creates an invalid to allow selecting all features if ( config( "AllowNull" ).toBool() ) { mComboBox->addItem( tr( "(no selection)" ), QVariant( layer()->fields().at( mFieldIdx ).type() ) );