@@ -43,38 +43,42 @@ QgsVirtualLayerFeatureIterator::QgsVirtualLayerFeatureIterator( QgsVirtualLayerF
43
43
wheres << subset;
44
44
}
45
45
46
- if ( mDefinition .hasDefinedGeometry () && !request. filterRect ().isNull () )
46
+ if ( ! mDefinition .uid ().isNull () )
47
47
{
48
- bool do_exact = request.flags () & QgsFeatureRequest::ExactIntersect;
49
- QgsRectangle rect ( request.filterRect () );
50
- QString mbr = QStringLiteral ( " %1,%2,%3,%4" ).arg ( rect.xMinimum () ).arg ( rect.yMinimum () ).arg ( rect.xMaximum () ).arg ( rect.yMaximum () );
51
- wheres << quotedColumn ( mDefinition .geometryField () ) + " is not null" ;
52
- wheres << QStringLiteral ( " %1Intersects(%2,BuildMbr(%3))" )
53
- .arg ( do_exact ? " " : " Mbr" ,
54
- quotedColumn ( mDefinition .geometryField () ),
55
- mbr );
56
- }
57
- else if ( !mDefinition .uid ().isNull () && request.filterType () == QgsFeatureRequest::FilterFid )
58
- {
59
- wheres << QStringLiteral ( " %1=%2" )
60
- .arg ( quotedColumn ( mDefinition .uid () ) )
61
- .arg ( request.filterFid () );
62
- }
63
- else if ( !mDefinition .uid ().isNull () && request.filterType () == QgsFeatureRequest::FilterFids )
64
- {
65
- QString values = quotedColumn ( mDefinition .uid () ) + " IN (" ;
66
- bool first = true ;
67
- Q_FOREACH ( QgsFeatureId v, request.filterFids () )
48
+ // filters are only available when a column with unique id exists
49
+ if ( mDefinition .hasDefinedGeometry () && !request.filterRect ().isNull () )
50
+ {
51
+ bool do_exact = request.flags () & QgsFeatureRequest::ExactIntersect;
52
+ QgsRectangle rect ( request.filterRect () );
53
+ QString mbr = QStringLiteral ( " %1,%2,%3,%4" ).arg ( rect.xMinimum () ).arg ( rect.yMinimum () ).arg ( rect.xMaximum () ).arg ( rect.yMaximum () );
54
+ wheres << quotedColumn ( mDefinition .geometryField () ) + " is not null" ;
55
+ wheres << QStringLiteral ( " %1Intersects(%2,BuildMbr(%3))" )
56
+ .arg ( do_exact ? " " : " Mbr" ,
57
+ quotedColumn ( mDefinition .geometryField () ),
58
+ mbr );
59
+ }
60
+ else if ( request.filterType () == QgsFeatureRequest::FilterFid )
61
+ {
62
+ wheres << QStringLiteral ( " %1=%2" )
63
+ .arg ( quotedColumn ( mDefinition .uid () ) )
64
+ .arg ( request.filterFid () );
65
+ }
66
+ else if ( request.filterType () == QgsFeatureRequest::FilterFids )
68
67
{
69
- if ( !first )
68
+ QString values = quotedColumn ( mDefinition .uid () ) + " IN (" ;
69
+ bool first = true ;
70
+ Q_FOREACH ( QgsFeatureId v, request.filterFids () )
70
71
{
71
- values += QLatin1String ( " ," );
72
+ if ( !first )
73
+ {
74
+ values += QLatin1String ( " ," );
75
+ }
76
+ first = false ;
77
+ values += QString::number ( v );
72
78
}
73
- first = false ;
74
- values += QString::number ( v ) ;
79
+ values += QLatin1String ( " ) " ) ;
80
+ wheres << values ;
75
81
}
76
- values += QLatin1String ( " )" );
77
- wheres << values;
78
82
}
79
83
80
84
mFields = mSource ->provider ()->fields ();
0 commit comments