Skip to content

Commit 48e6bfc

Browse files
committedOct 12, 2016
Fix HTML annotation does not display HTML (fix #8609)
Annotation was only rendering html when it was associated with a map layer. Now if it isn't associated with a map layer it will always render the html. (cherry-picked from 53c3ed2)
1 parent 8f42bb8 commit 48e6bfc

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed
 

‎src/gui/qgshtmlannotationitem.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -191,42 +191,44 @@ void QgsHtmlAnnotationItem::readXML( const QDomDocument& doc, const QDomElement&
191191

192192
void 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

232234
void QgsHtmlAnnotationItem::updateVisibility()

0 commit comments

Comments
 (0)
Please sign in to comment.