Skip to content
Permalink
Browse files

Restore HTML item atlas functionality

  • Loading branch information
nyalldawson committed Dec 23, 2017
1 parent 8072d4d commit fee1c211a6bea43bccf87c685d803ef99b173aa4
@@ -352,14 +352,11 @@ void QgsLayoutHtmlWidget::mInsertExpressionButton_clicked()
mHtmlEditor->getCursorPosition( &line, &index );
}

#if 0 //TODO
// use the atlas coverage layer, if any
QgsVectorLayer *coverageLayer = atlasCoverageLayer();
#endif
QgsVectorLayer *coverageLayer = nullptr;
QgsVectorLayer *layer = coverageLayer();

QgsExpressionContext context = mHtml->createExpressionContext();
QgsExpressionBuilderDialog exprDlg( coverageLayer, selText, this, QStringLiteral( "generic" ), context );
QgsExpressionBuilderDialog exprDlg( layer, selText, this, QStringLiteral( "generic" ), context );
exprDlg.setWindowTitle( tr( "Insert Expression" ) );
if ( exprDlg.exec() == QDialog::Accepted )
{
@@ -28,6 +28,7 @@
#include "qgsmapsettings.h"
#include "qgswebpage.h"
#include "qgswebframe.h"
#include "qgslayoutitemmap.h"

#include <QCoreApplication>
#include <QPainter>
@@ -50,23 +51,11 @@ QgsLayoutItemHtml::QgsLayoutItemHtml( QgsLayout *layout )

mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );

#if 0 //TODO
if ( mLayout )
{
connect( mLayout, &QgsComposition::itemRemoved, this, &QgsComposerMultiFrame::handleFrameRemoval );
}
//a html item added to a layout needs to have the initial expression context set,
//otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457)
setExpressionContext( mLayout->context().feature(), mLayout->context().layer() );

if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas )
{
//a html item added while atlas preview is enabled needs to have the expression context set,
//otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457)
setExpressionContext( mComposition->atlasComposition().feature(), mComposition->atlasComposition().coverageLayer() );
}

//connect to atlas feature changes
//to update the expression context
connect( &mComposition->atlasComposition(), &QgsAtlasComposition::featureChanged, this, &QgsLayoutItemHtml::refreshExpressionContext );
#endif
connect( &mLayout->context(), &QgsLayoutContext::changed, this, &QgsLayoutItemHtml::refreshExpressionContext );

mFetcher = new QgsNetworkContentFetcher();
}
@@ -496,39 +485,39 @@ void QgsLayoutItemHtml::setExpressionContext( const QgsFeature &feature, QgsVect
}
else if ( mLayout )
{
#if 0 //TODO
//set to composition's mapsettings' crs
QgsComposerMap *referenceMap = mComposition->referenceMap();
QgsLayoutItemMap *referenceMap = mLayout->referenceMap();
if ( referenceMap )
mDistanceArea->setSourceCrs( referenceMap->crs() );
#endif
mDistanceArea.setSourceCrs( referenceMap->crs(), mLayout->project()->transformContext() );
}
if ( mLayout )
{
mDistanceArea.setEllipsoid( mLayout->project()->ellipsoid() );
}

// create JSON representation of feature
QgsJsonExporter exporter( layer );
exporter.setIncludeRelated( true );
mAtlasFeatureJSON = exporter.exportFeature( feature );
if ( feature.isValid() )
{
// create JSON representation of feature
QgsJsonExporter exporter( layer );
exporter.setIncludeRelated( true );
mAtlasFeatureJSON = exporter.exportFeature( feature );
}
else
{
mAtlasFeatureJSON.clear();
}
}

void QgsLayoutItemHtml::refreshExpressionContext()
{
QgsVectorLayer *vl = nullptr;
QgsFeature feature;

#if 0 //TODO
if ( mComposition->atlasComposition().enabled() )
{
vl = mComposition->atlasComposition().coverageLayer();
}
if ( mComposition->atlasMode() != QgsComposition::AtlasOff )
if ( mLayout )
{
feature = mComposition->atlasComposition().feature();
vl = mLayout->context().layer();
feature = mLayout->context().feature();
}
#endif

setExpressionContext( feature, vl );
loadHtml( true );
@@ -67,13 +67,6 @@ QgsLayoutItemLabel::QgsLayoutItemLabel( QgsLayout *layout )
//otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
refreshExpressionContext();

if ( mLayout )
{
//connect to context feature changes
//to update the expression context
connect( &mLayout->context(), &QgsLayoutContext::changed, this, &QgsLayoutItemLabel::refreshExpressionContext );
}

mWebPage.reset( new QgsWebPage( this ) );
mWebPage->setIdentifier( tr( "Layout label item" ) );
mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
@@ -253,7 +246,7 @@ void QgsLayoutItemLabel::refreshExpressionContext()
//set to composition's reference map's crs
QgsLayoutItemMap *referenceMap = mLayout->referenceMap();
if ( referenceMap )
mDistanceArea->setSourceCrs( referenceMap->crs() );
mDistanceArea->setSourceCrs( referenceMap->crs(), mLayout->project()->transformContext() );
}
mDistanceArea->setEllipsoid( mLayout->project()->ellipsoid() );
contentChanged();
@@ -493,7 +486,7 @@ void QgsLayoutItemLabel::setFrameStrokeWidth( const QgsLayoutMeasurement &stroke
void QgsLayoutItemLabel::refresh()
{
QgsLayoutItem::refresh();
contentChanged();
refreshExpressionContext();
}

void QgsLayoutItemLabel::itemShiftAdjustSize( double newWidth, double newHeight, double &xShift, double &yShift ) const

0 comments on commit fee1c21

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