Skip to content

Commit 31ac9be

Browse files
committed
[search widgets] when selecting _Please select_ find all features
1 parent b2034f2 commit 31ac9be

4 files changed

+26
-4
lines changed

src/gui/editorwidgets/core/qgssearchwidgetwrapper.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ void QgsSearchWidgetWrapper::setFeature( const QgsFeature& feature )
3333
Q_UNUSED( feature )
3434
}
3535

36+
void QgsSearchWidgetWrapper::clearExpression()
37+
{
38+
mExpression = QString( "TRUE" );
39+
}
40+

src/gui/editorwidgets/core/qgssearchwidgetwrapper.h

+3
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ class GUI_EXPORT QgsSearchWidgetWrapper : public QgsWidgetWrapper
8181
void setFeature( const QgsFeature& feature ) override;
8282

8383
protected:
84+
//! clears the expression to search for all features
85+
void clearExpression();
86+
8487
QString mExpression;
8588
int mFieldIdx;
8689

src/gui/editorwidgets/qgsvaluemapsearchwidgetwrapper.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ void QgsValueMapSearchWidgetWrapper::comboBoxIndexChanged( int idx )
3737
{
3838
if ( mComboBox )
3939
{
40-
setExpression( mComboBox->itemData( idx ).toString() );
40+
if ( idx == 0 )
41+
{
42+
clearExpression();
43+
}
44+
else
45+
{
46+
setExpression( mComboBox->itemData( idx ).toString() );
47+
}
4148
emit expressionChanged( mExpression );
4249
}
4350
}

src/gui/editorwidgets/qgsvaluerelationsearchwidgetwrapper.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,15 @@ bool QgsValueRelationSearchWidgetWrapper::valid()
9797
void QgsValueRelationSearchWidgetWrapper::valueChanged()
9898
{
9999
QVariant vl = value();
100-
QSettings settings;
101-
setExpression( vl.isNull() ? settings.value( "qgis/nullValue", "NULL" ).toString() : vl.toString() );
100+
if ( !vl.isValid() )
101+
{
102+
clearExpression();
103+
}
104+
else
105+
{
106+
QSettings settings;
107+
setExpression( vl.isNull() ? settings.value( "qgis/nullValue", "NULL" ).toString() : vl.toString() );
108+
}
102109
emit expressionChanged( mExpression );
103110
}
104111

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

150157
if ( mComboBox )
151158
{
152-
mComboBox->addItem( tr( "Please select" ), QVariant( layer()->fields().at( mFieldIdx ).type() ) );
159+
mComboBox->addItem( tr( "Please select" ), QVariant() ); // creates an invalid to allow selecting all features
153160
if ( config( "AllowNull" ).toBool() )
154161
{
155162
mComboBox->addItem( tr( "(no selection)" ), QVariant( layer()->fields().at( mFieldIdx ).type() ) );

0 commit comments

Comments
 (0)