Skip to content

Commit

Permalink
Only search text and numeric fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 1, 2017
1 parent f9aa749 commit 787769a
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/app/locator/qgsinbuiltlocatorfilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ( " ) ) );
Expand Down

0 comments on commit 787769a

Please sign in to comment.