Skip to content

Commit

Permalink
[search widgets] when selecting _Please select_ find all features
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Nov 13, 2015
1 parent b2034f2 commit 31ac9be
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp
Expand Up @@ -33,3 +33,8 @@ void QgsSearchWidgetWrapper::setFeature( const QgsFeature& feature )
Q_UNUSED( feature ) Q_UNUSED( feature )
} }


void QgsSearchWidgetWrapper::clearExpression()
{
mExpression = QString( "TRUE" );
}

3 changes: 3 additions & 0 deletions src/gui/editorwidgets/core/qgssearchwidgetwrapper.h
Expand Up @@ -81,6 +81,9 @@ class GUI_EXPORT QgsSearchWidgetWrapper : public QgsWidgetWrapper
void setFeature( const QgsFeature& feature ) override; void setFeature( const QgsFeature& feature ) override;


protected: protected:
//! clears the expression to search for all features
void clearExpression();

QString mExpression; QString mExpression;
int mFieldIdx; int mFieldIdx;


Expand Down
9 changes: 8 additions & 1 deletion src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp
Expand Up @@ -37,7 +37,14 @@ void QgsValueMapSearchWidgetWrapper::comboBoxIndexChanged( int idx )
{ {
if ( mComboBox ) if ( mComboBox )
{ {
setExpression( mComboBox->itemData( idx ).toString() ); if ( idx == 0 )
{
clearExpression();
}
else
{
setExpression( mComboBox->itemData( idx ).toString() );
}
emit expressionChanged( mExpression ); emit expressionChanged( mExpression );
} }
} }
Expand Down
13 changes: 10 additions & 3 deletions src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp
Expand Up @@ -97,8 +97,15 @@ bool QgsValueRelationSearchWidgetWrapper::valid()
void QgsValueRelationSearchWidgetWrapper::valueChanged() void QgsValueRelationSearchWidgetWrapper::valueChanged()
{ {
QVariant vl = value(); QVariant vl = value();
QSettings settings; if ( !vl.isValid() )
setExpression( vl.isNull() ? settings.value( "qgis/nullValue", "NULL" ).toString() : vl.toString() ); {
clearExpression();
}
else
{
QSettings settings;
setExpression( vl.isNull() ? settings.value( "qgis/nullValue", "NULL" ).toString() : vl.toString() );
}
emit expressionChanged( mExpression ); emit expressionChanged( mExpression );
} }


Expand Down Expand Up @@ -149,7 +156,7 @@ void QgsValueRelationSearchWidgetWrapper::initWidget( QWidget* editor )


if ( mComboBox ) 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() ) if ( config( "AllowNull" ).toBool() )
{ {
mComboBox->addItem( tr( "(no selection)" ), QVariant( layer()->fields().at( mFieldIdx ).type() ) ); mComboBox->addItem( tr( "(no selection)" ), QVariant( layer()->fields().at( mFieldIdx ).type() ) );
Expand Down

0 comments on commit 31ac9be

Please sign in to comment.