[search widgets] when selecting _Please select_ find all features

This commit is contained in:
Denis Rouzaud 2015-11-13 08:59:56 +01:00
parent b2034f2ea6
commit 31ac9be340
4 changed files with 26 additions and 4 deletions

View File

@ -33,3 +33,8 @@ void QgsSearchWidgetWrapper::setFeature( const QgsFeature& feature )
Q_UNUSED( feature )
}
void QgsSearchWidgetWrapper::clearExpression()
{
mExpression = QString( "TRUE" );
}

View File

@ -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;

View File

@ -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 );
}
}

View File

@ -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() ) );