Skip to content
Permalink
Browse files

Only search text and numeric fields

  • Loading branch information
nyalldawson committed Jun 1, 2017
1 parent f9aa749 commit 787769a7bfdfc8c48071ca833e1f56dae17f6110
Showing with 12 additions and 3 deletions.
  1. +12 −3 src/app/locator/qgsinbuiltlocatorfilters.cpp
@@ -176,6 +176,9 @@ void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, c
if ( string.length() < 3 )
return;

bool allowNumeric = false;
double numericValue = string.toDouble( &allowNumeric );

QgsVectorLayer *layer = qobject_cast< QgsVectorLayer *>( QgisApp::instance()->activeLayer() );
if ( !layer )
return;
@@ -190,9 +193,15 @@ void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, c
QStringList expressionParts;
Q_FOREACH ( const QgsField &field, layer->fields() )
{
QString exp = QStringLiteral( "%1 ILIKE '%%2%'" ).arg( QgsExpression::quotedColumnRef( field.name() ),
string );
expressionParts << exp;
if ( field.type() == QVariant::String )
{
expressionParts << QStringLiteral( "%1 ILIKE '%%2%'" ).arg( QgsExpression::quotedColumnRef( field.name() ),
string );
}
else if ( allowNumeric && field.isNumeric() )
{
expressionParts << QStringLiteral( "%1 = %2" ).arg( QgsExpression::quotedColumnRef( field.name() ) ).arg( numericValue );
}
}

QString expression = QStringLiteral( "(%1)" ).arg( expressionParts.join( QStringLiteral( " ) OR ( " ) ) );

0 comments on commit 787769a

Please sign in to comment.
You can’t perform that action at this time.