@@ -191,42 +191,44 @@ void QgsHtmlAnnotationItem::readXML( const QDomDocument& doc, const QDomElement&
191191
192192void QgsHtmlAnnotationItem::setFeatureForMapPosition ()
193193{
194- if ( !mVectorLayer || !mMapCanvas )
194+ QString newText;
195+ if ( mVectorLayer && mMapCanvas )
195196 {
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 );
198200
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 ) );
203202
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+ }
205213
206- QgsFeature currentFeature ;
207- QgsFeatureId currentFeatureId = 0 ;
208- bool featureFound = false ;
214+ mHasAssociatedFeature = featureFound ;
215+ mFeatureId = currentFeatureId ;
216+ mFeature = currentFeature ;
209217
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
211228 {
212- currentFeatureId = currentFeature.id ();
213- featureFound = true ;
214- break ;
229+ newText = mHtmlSource ;
215230 }
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 );
230232}
231233
232234void QgsHtmlAnnotationItem::updateVisibility ()
0 commit comments