@@ -207,7 +207,7 @@ QString QgsDefaultSearchWidgetWrapper::createExpression( QgsSearchWidgetWrapper:
207
207
// case insensitive!
208
208
if ( flags & EqualTo || flags & NotEqualTo )
209
209
{
210
- if ( mCheckbox ->isChecked () )
210
+ if ( mCheckbox && mCheckbox ->isChecked () )
211
211
return fieldName + ( flags & EqualTo ? " =" : " <>" )
212
212
+ QgsExpression::quotedString ( mLineEdit ->text () );
213
213
else
@@ -217,7 +217,7 @@ QString QgsDefaultSearchWidgetWrapper::createExpression( QgsSearchWidgetWrapper:
217
217
}
218
218
else if ( flags & Contains || flags & DoesNotContain )
219
219
{
220
- QString exp = fieldName + ( mCheckbox ->isChecked () ? " LIKE " : " ILIKE " );
220
+ QString exp = fieldName + ( mCheckbox && mCheckbox ->isChecked () ? " LIKE " : " ILIKE " );
221
221
QString value = QgsExpression::quotedString ( mLineEdit ->text () );
222
222
value.chop ( 1 );
223
223
value = value.remove ( 0 , 1 );
@@ -245,7 +245,8 @@ void QgsDefaultSearchWidgetWrapper::clearWidget()
245
245
void QgsDefaultSearchWidgetWrapper::setEnabled ( bool enabled )
246
246
{
247
247
mLineEdit ->setEnabled ( enabled );
248
- mCheckbox ->setEnabled ( enabled );
248
+ if ( mCheckbox )
249
+ mCheckbox ->setEnabled ( enabled );
249
250
}
250
251
251
252
void QgsDefaultSearchWidgetWrapper::initWidget ( QWidget* widget )
@@ -255,14 +256,21 @@ void QgsDefaultSearchWidgetWrapper::initWidget( QWidget* widget )
255
256
mContainer ->layout ()->setMargin ( 0 );
256
257
mContainer ->layout ()->setContentsMargins ( 0 , 0 , 0 , 0 );
257
258
mLineEdit = new QgsFilterLineEdit ();
258
- mCheckbox = new QCheckBox ( " Case sensitive" );
259
259
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
+
261
270
connect ( mLineEdit , SIGNAL ( textChanged ( QString ) ), this , SLOT ( textChanged ( QString ) ) );
262
271
connect ( mLineEdit , SIGNAL ( returnPressed () ), this , SLOT ( filterChanged () ) );
263
- connect ( mCheckbox , SIGNAL ( stateChanged ( int ) ), this , SLOT ( setCaseString ( int ) ) );
264
272
connect ( mLineEdit , SIGNAL ( textEdited ( QString ) ), this , SIGNAL ( valueChanged () ) );
265
- mCheckbox -> setChecked ( Qt::Unchecked );
273
+
266
274
mCaseString = " ILIKE" ;
267
275
}
268
276
0 commit comments