Skip to content
Permalink
Browse files

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.
  • Loading branch information
nyalldawson committed Oct 12, 2016
1 parent a5ffc6a commit 53c3ed2dc02baf43c3a5cc7323f37869f434f25a
Showing with 31 additions and 29 deletions.
  1. +31 −29 src/gui/qgshtmlannotationitem.cpp
@@ -193,42 +193,44 @@ void QgsHtmlAnnotationItem::readXml( const QDomDocument& doc, const QDomElement&

void QgsHtmlAnnotationItem::setFeatureForMapPosition()
{
if ( !mVectorLayer || !mMapCanvas )
QString newText;
if ( mVectorLayer && mMapCanvas )
{
return;
}
double halfIdentifyWidth = QgsMapTool::searchRadiusMU( mMapCanvas );
QgsRectangle searchRect( mMapPosition.x() - halfIdentifyWidth, mMapPosition.y() - halfIdentifyWidth,
mMapPosition.x() + halfIdentifyWidth, mMapPosition.y() + halfIdentifyWidth );

QSettings settings;
double halfIdentifyWidth = QgsMapTool::searchRadiusMU( mMapCanvas );
QgsRectangle searchRect( mMapPosition.x() - halfIdentifyWidth, mMapPosition.y() - halfIdentifyWidth,
mMapPosition.x() + halfIdentifyWidth, mMapPosition.y() + halfIdentifyWidth );
QgsFeatureIterator fit = mVectorLayer->getFeatures( QgsFeatureRequest().setFilterRect( searchRect ).setFlags( QgsFeatureRequest::NoGeometry | QgsFeatureRequest::ExactIntersect ) );

QgsFeatureIterator fit = mVectorLayer->getFeatures( QgsFeatureRequest().setFilterRect( searchRect ).setFlags( QgsFeatureRequest::NoGeometry | QgsFeatureRequest::ExactIntersect ) );
QgsFeature currentFeature;
QgsFeatureId currentFeatureId = 0;
bool featureFound = false;

while ( fit.nextFeature( currentFeature ) )
{
currentFeatureId = currentFeature.id();
featureFound = true;
break;
}

QgsFeature currentFeature;
QgsFeatureId currentFeatureId = 0;
bool featureFound = false;
mHasAssociatedFeature = featureFound;
mFeatureId = currentFeatureId;
mFeature = currentFeature;

while ( fit.nextFeature( currentFeature ) )
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( mVectorLayer );
if ( mMapCanvas )
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() ) );
context.setFeature( mFeature );
newText = QgsExpression::replaceExpressionText( mHtmlSource, &context );
}
else
{
currentFeatureId = currentFeature.id();
featureFound = true;
break;
newText = mHtmlSource;
}

mHasAssociatedFeature = featureFound;
mFeatureId = currentFeatureId;
mFeature = currentFeature;

QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::layerScope( mVectorLayer );
if ( mMapCanvas )
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mMapCanvas->mapSettings() ) );
context.setFeature( mFeature );
QString newtext = QgsExpression::replaceExpressionText( mHtmlSource, &context );
mWebView->setHtml( newtext );
mWebView->setHtml( newText );
}

void QgsHtmlAnnotationItem::updateVisibility()

1 comment on commit 53c3ed2

@NathanW2

This comment has been minimized.

Copy link
Member

@NathanW2 NathanW2 commented on 53c3ed2 Oct 12, 2016

Nice!

Please sign in to comment.
You can’t perform that action at this time.