Skip to content

Commit

Permalink
Restore HTML item atlas functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 5, 2018
1 parent 8072d4d commit fee1c21
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 46 deletions.
7 changes: 2 additions & 5 deletions src/app/layout/qgslayouthtmlwidget.cpp
Expand Up @@ -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 )
{
Expand Down
53 changes: 21 additions & 32 deletions src/core/layout/qgslayoutitemhtml.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsmapsettings.h"
#include "qgswebpage.h"
#include "qgswebframe.h"
#include "qgslayoutitemmap.h"

#include <QCoreApplication>
#include <QPainter>
Expand All @@ -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();
}
Expand Down Expand Up @@ -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 );
Expand Down
11 changes: 2 additions & 9 deletions src/core/layout/qgslayoutitemlabel.cpp
Expand Up @@ -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() );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fee1c21

Please sign in to comment.