Skip to content

Commit 6ef22ee

Browse files
committedMay 23, 2016
Only show 'case sensitive' checkbox for string fields
1 parent 1c4811f commit 6ef22ee

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed
 

‎src/gui/editorwidgets/qgsdefaultsearchwidgetwrapper.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ QString QgsDefaultSearchWidgetWrapper::createExpression( QgsSearchWidgetWrapper:
207207
// case insensitive!
208208
if ( flags & EqualTo || flags & NotEqualTo )
209209
{
210-
if ( mCheckbox->isChecked() )
210+
if ( mCheckbox && mCheckbox->isChecked() )
211211
return fieldName + ( flags & EqualTo ? "=" : "<>" )
212212
+ QgsExpression::quotedString( mLineEdit->text() );
213213
else
@@ -217,7 +217,7 @@ QString QgsDefaultSearchWidgetWrapper::createExpression( QgsSearchWidgetWrapper:
217217
}
218218
else if ( flags & Contains || flags & DoesNotContain )
219219
{
220-
QString exp = fieldName + ( mCheckbox->isChecked() ? " LIKE " : " ILIKE " );
220+
QString exp = fieldName + ( mCheckbox && mCheckbox->isChecked() ? " LIKE " : " ILIKE " );
221221
QString value = QgsExpression::quotedString( mLineEdit->text() );
222222
value.chop( 1 );
223223
value = value.remove( 0, 1 );
@@ -245,7 +245,8 @@ void QgsDefaultSearchWidgetWrapper::clearWidget()
245245
void QgsDefaultSearchWidgetWrapper::setEnabled( bool enabled )
246246
{
247247
mLineEdit->setEnabled( enabled );
248-
mCheckbox->setEnabled( enabled );
248+
if ( mCheckbox )
249+
mCheckbox->setEnabled( enabled );
249250
}
250251

251252
void QgsDefaultSearchWidgetWrapper::initWidget( QWidget* widget )
@@ -255,14 +256,21 @@ void QgsDefaultSearchWidgetWrapper::initWidget( QWidget* widget )
255256
mContainer->layout()->setMargin( 0 );
256257
mContainer->layout()->setContentsMargins( 0, 0, 0, 0 );
257258
mLineEdit = new QgsFilterLineEdit();
258-
mCheckbox = new QCheckBox( "Case sensitive" );
259259
mContainer->layout()->addWidget( mLineEdit );
260-
mContainer->layout()->addWidget( mCheckbox );
260+
261+
QVariant::Type fldType = layer()->fields().at( mFieldIdx ).type();
262+
if ( fldType == QVariant::String )
263+
{
264+
mCheckbox = new QCheckBox( "Case sensitive" );
265+
mContainer->layout()->addWidget( mCheckbox );
266+
connect( mCheckbox, SIGNAL( stateChanged( int ) ), this, SLOT( setCaseString( int ) ) );
267+
mCheckbox->setChecked( Qt::Unchecked );
268+
}
269+
261270
connect( mLineEdit, SIGNAL( textChanged( QString ) ), this, SLOT( textChanged( QString ) ) );
262271
connect( mLineEdit, SIGNAL( returnPressed() ), this, SLOT( filterChanged() ) );
263-
connect( mCheckbox, SIGNAL( stateChanged( int ) ), this, SLOT( setCaseString( int ) ) );
264272
connect( mLineEdit, SIGNAL( textEdited( QString ) ), this, SIGNAL( valueChanged() ) );
265-
mCheckbox->setChecked( Qt::Unchecked );
273+
266274
mCaseString = "ILIKE";
267275
}
268276

0 commit comments

Comments
 (0)
Please sign in to comment.