Skip to content

Commit

Permalink
Fix HTML annotation does not display HTML (fix #8609)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
nyalldawson committed Oct 13, 2016
1 parent 9486166 commit 3efbc0b
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions src/gui/qgshtmlannotationitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,42 +191,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()
Expand Down

0 comments on commit 3efbc0b

Please sign in to comment.