@@ -180,55 +180,62 @@ void QgsActiveLayerFeaturesLocatorFilter::fetchResults( const QString &string, c
180
180
if ( !layer )
181
181
return ;
182
182
183
- int i = 0 ;
184
183
int found = 0 ;
185
184
QgsExpression dispExpression ( layer->displayExpression () );
186
185
QgsExpressionContext context;
187
186
context.appendScopes ( QgsExpressionContextUtils::globalProjectLayerScopes ( layer ) );
188
187
dispExpression.prepare ( &context );
189
188
189
+ // build up request expression
190
+ QStringList expressionParts;
190
191
Q_FOREACH ( const QgsField &field, layer->fields () )
191
192
{
192
- if ( feedback->isCanceled () )
193
- return ;
194
-
195
193
QString exp = QStringLiteral ( " %1 ILIKE '%%2%'" ).arg ( QgsExpression::quotedColumnRef ( field.name () ),
196
194
string );
197
- QgsFeatureRequest req;
198
- req.setFlags ( QgsFeatureRequest::NoGeometry );
199
- QStringList attrs;
200
- attrs << field.name ();
201
- attrs.append ( dispExpression.referencedColumns ().toList () );
202
- req.setSubsetOfAttributes ( attrs, layer->fields () );
203
- req.setFilterExpression ( exp );
204
- req.setLimit ( 30 );
205
- QgsFeature f;
206
- QgsFeatureIterator it = layer->getFeatures ( req );
207
- while ( it.nextFeature ( f ) )
208
- {
209
- if ( feedback->isCanceled () )
210
- return ;
195
+ expressionParts << exp;
196
+ }
211
197
212
- QgsLocatorResult result;
213
- result.filter = this ;
198
+ QString expression = QStringLiteral ( " (%1)" ).arg ( expressionParts.join ( QStringLiteral ( " ) OR ( " ) ) );
214
199
215
- context.setFeature ( f );
216
- result.displayString = dispExpression.evaluate ( &context ).toString ();
217
- if ( result.displayString .isEmpty () )
218
- result.displayString = f.attribute ( i ).toString ();
219
- else
220
- result.description = f.attribute ( i ).toString ();
200
+ QgsFeatureRequest req;
201
+ req.setFlags ( QgsFeatureRequest::NoGeometry );
202
+ req.setFilterExpression ( expression );
203
+ req.setLimit ( 30 );
204
+ QgsFeature f;
205
+ QgsFeatureIterator it = layer->getFeatures ( req );
206
+ while ( it.nextFeature ( f ) )
207
+ {
208
+ if ( feedback->isCanceled () )
209
+ return ;
221
210
222
- result.userData = f.id ();
223
- result.icon = QgsMapLayerModel::iconForLayer ( layer );
224
- result.score = static_cast < double >( string.length () ) / f.attribute ( i ).toString ().size ();
225
- emit resultFetched ( result );
211
+ QgsLocatorResult result;
212
+ result.filter = this ;
226
213
227
- found++;
228
- if ( found >= 30 )
229
- return ;
214
+ context.setFeature ( f );
215
+
216
+ // find matching field content
217
+ Q_FOREACH ( const QVariant &var, f.attributes () )
218
+ {
219
+ QString attrString = var.toString ();
220
+ if ( attrString.contains ( string, Qt::CaseInsensitive ) )
221
+ {
222
+ result.displayString = attrString;
223
+ break ;
224
+ }
230
225
}
231
- i++;
226
+ if ( result.displayString .isEmpty () )
227
+ continue ; // not sure how this result slipped through...
228
+
229
+ result.description = dispExpression.evaluate ( &context ).toString ();
230
+
231
+ result.userData = f.id ();
232
+ result.icon = QgsMapLayerModel::iconForLayer ( layer );
233
+ result.score = static_cast < double >( string.length () ) / result.displayString .size ();
234
+ emit resultFetched ( result );
235
+
236
+ found++;
237
+ if ( found >= 30 )
238
+ return ;
232
239
}
233
240
}
234
241
0 commit comments