@@ -175,14 +175,7 @@ void QgsValueRelationWidgetWrapper::setValue( const QVariant& value )
175
175
for ( int i = 0 ; i < mListWidget ->count (); ++i )
176
176
{
177
177
QListWidgetItem* item = mListWidget ->item ( i );
178
- if ( config ( " OrderByValue" ).toBool () )
179
- {
180
- item->setCheckState ( checkList.contains ( item->data ( Qt::UserRole ).toString () ) ? Qt::Checked : Qt::Unchecked );
181
- }
182
- else
183
- {
184
- item->setCheckState ( checkList.contains ( item->data ( Qt::UserRole ).toString () ) ? Qt::Checked : Qt::Unchecked );
185
- }
178
+ item->setCheckState ( checkList.contains ( item->data ( Qt::UserRole ).toString () ) ? Qt::Checked : Qt::Unchecked );
186
179
}
187
180
}
188
181
else if ( mComboBox )
@@ -209,70 +202,27 @@ QgsValueRelationWidgetWrapper::ValueRelationCache QgsValueRelationWidgetWrapper:
209
202
210
203
QgsVectorLayer* layer = qobject_cast<QgsVectorLayer*>( QgsMapLayerRegistry::instance ()->mapLayer ( config.value ( " Layer" ).toString () ) );
211
204
212
- if ( layer )
213
- {
214
- int ki = layer->fieldNameIndex ( config.value ( " Key" ).toString () );
215
- int vi = layer->fieldNameIndex ( config.value ( " Value" ).toString () );
216
-
217
- QgsExpressionContext context;
218
- context << QgsExpressionContextUtils::globalScope ()
219
- << QgsExpressionContextUtils::projectScope ()
220
- << QgsExpressionContextUtils::layerScope ( layer );
221
-
222
- QgsExpression *e = nullptr ;
223
- if ( !config.value ( " FilterExpression" ).toString ().isEmpty () )
224
- {
225
- e = new QgsExpression ( config.value ( " FilterExpression" ).toString () );
226
- if ( e->hasParserError () || !e->prepare ( &context ) )
227
- ki = -1 ;
228
- }
229
-
230
- if ( ki >= 0 && vi >= 0 )
231
- {
232
- QSet<int > attributes;
233
- attributes << ki << vi;
234
-
235
- QgsFeatureRequest::Flags flags = QgsFeatureRequest::NoGeometry;
205
+ if ( !layer )
206
+ return cache;
236
207
237
- bool requiresAllAttributes = false ;
238
- if ( e )
239
- {
240
- if ( e->needsGeometry () )
241
- flags = QgsFeatureRequest::NoFlags;
242
-
243
- Q_FOREACH ( const QString& field, e->referencedColumns () )
244
- {
245
- if ( field == QgsFeatureRequest::AllAttributes )
246
- {
247
- requiresAllAttributes = true ;
248
- break ;
249
- }
250
- int idx = layer->fieldNameIndex ( field );
251
- if ( idx < 0 )
252
- continue ;
253
- attributes << idx;
254
- }
255
- }
208
+ int ki = layer->fieldNameIndex ( config.value ( " Key" ).toString () );
209
+ int vi = layer->fieldNameIndex ( config.value ( " Value" ).toString () );
256
210
257
- QgsFeatureRequest fr = QgsFeatureRequest ().setFlags ( flags );
258
- if ( !requiresAllAttributes )
259
- {
260
- fr.setSubsetOfAttributes ( attributes.toList () );
261
- }
211
+ QgsFeatureRequest request;
262
212
263
- QgsFeatureIterator fit = layer->getFeatures ( fr );
213
+ request.setFlags ( QgsFeatureRequest::NoGeometry );
214
+ request.setSubsetOfAttributes ( QgsAttributeList () << ki << vi );
215
+ if ( !config.value ( " FilterExpression" ).toString ().isEmpty () )
216
+ {
217
+ request.setFilterExpression ( config.value ( " FilterExpression" ).toString () );
218
+ }
264
219
265
- QgsFeature f;
266
- while ( fit.nextFeature ( f ) )
267
- {
268
- context.setFeature ( f );
269
- if ( e && !e->evaluate ( &context ).toBool () )
270
- continue ;
220
+ QgsFeatureIterator fit = layer->getFeatures ( request );
271
221
272
- cache. append ( ValueRelationItem ( f. attribute ( ki ), f. attribute ( vi ). toString () ) ) ;
273
- }
274
- }
275
- delete e ;
222
+ QgsFeature f ;
223
+ while ( fit. nextFeature ( f ) )
224
+ {
225
+ cache. append ( ValueRelationItem ( f. attribute ( ki ), f. attribute ( vi ). toString () ) ) ;
276
226
}
277
227
278
228
if ( config.value ( " OrderByValue" ).toBool () )
0 commit comments