@@ -191,42 +191,44 @@ void QgsHtmlAnnotationItem::readXML( const QDomDocument& doc, const QDomElement&
191
191
192
192
void QgsHtmlAnnotationItem::setFeatureForMapPosition ()
193
193
{
194
- if ( !mVectorLayer || !mMapCanvas )
194
+ QString newText;
195
+ if ( mVectorLayer && mMapCanvas )
195
196
{
196
- return ;
197
- }
197
+ double halfIdentifyWidth = QgsMapTool::searchRadiusMU ( mMapCanvas );
198
+ QgsRectangle searchRect ( mMapPosition .x () - halfIdentifyWidth, mMapPosition .y () - halfIdentifyWidth,
199
+ mMapPosition .x () + halfIdentifyWidth, mMapPosition .y () + halfIdentifyWidth );
198
200
199
- QSettings settings;
200
- double halfIdentifyWidth = QgsMapTool::searchRadiusMU ( mMapCanvas );
201
- QgsRectangle searchRect ( mMapPosition .x () - halfIdentifyWidth, mMapPosition .y () - halfIdentifyWidth,
202
- mMapPosition .x () + halfIdentifyWidth, mMapPosition .y () + halfIdentifyWidth );
201
+ QgsFeatureIterator fit = mVectorLayer ->getFeatures ( QgsFeatureRequest ().setFilterRect ( searchRect ).setFlags ( QgsFeatureRequest::NoGeometry | QgsFeatureRequest::ExactIntersect ) );
203
202
204
- QgsFeatureIterator fit = mVectorLayer ->getFeatures ( QgsFeatureRequest ().setFilterRect ( searchRect ).setFlags ( QgsFeatureRequest::NoGeometry | QgsFeatureRequest::ExactIntersect ) );
203
+ QgsFeature currentFeature;
204
+ QgsFeatureId currentFeatureId = 0 ;
205
+ bool featureFound = false ;
206
+
207
+ while ( fit.nextFeature ( currentFeature ) )
208
+ {
209
+ currentFeatureId = currentFeature.id ();
210
+ featureFound = true ;
211
+ break ;
212
+ }
205
213
206
- QgsFeature currentFeature ;
207
- QgsFeatureId currentFeatureId = 0 ;
208
- bool featureFound = false ;
214
+ mHasAssociatedFeature = featureFound ;
215
+ mFeatureId = currentFeatureId ;
216
+ mFeature = currentFeature ;
209
217
210
- while ( fit.nextFeature ( currentFeature ) )
218
+ QgsExpressionContext context;
219
+ context << QgsExpressionContextUtils::globalScope ()
220
+ << QgsExpressionContextUtils::projectScope ()
221
+ << QgsExpressionContextUtils::layerScope ( mVectorLayer );
222
+ if ( mMapCanvas )
223
+ context.appendScope ( QgsExpressionContextUtils::mapSettingsScope ( mMapCanvas ->mapSettings () ) );
224
+ context.setFeature ( mFeature );
225
+ newText = QgsExpression::replaceExpressionText ( mHtmlSource , &context );
226
+ }
227
+ else
211
228
{
212
- currentFeatureId = currentFeature.id ();
213
- featureFound = true ;
214
- break ;
229
+ newText = mHtmlSource ;
215
230
}
216
-
217
- mHasAssociatedFeature = featureFound;
218
- mFeatureId = currentFeatureId;
219
- mFeature = currentFeature;
220
-
221
- QgsExpressionContext context;
222
- context << QgsExpressionContextUtils::globalScope ()
223
- << QgsExpressionContextUtils::projectScope ()
224
- << QgsExpressionContextUtils::layerScope ( mVectorLayer );
225
- if ( mMapCanvas )
226
- context.appendScope ( QgsExpressionContextUtils::mapSettingsScope ( mMapCanvas ->mapSettings () ) );
227
- context.setFeature ( mFeature );
228
- QString newtext = QgsExpression::replaceExpressionText ( mHtmlSource , &context );
229
- mWebView ->setHtml ( newtext );
231
+ mWebView ->setHtml ( newText );
230
232
}
231
233
232
234
void QgsHtmlAnnotationItem::updateVisibility ()
0 commit comments