Skip to content

Commit fee1c21

Browse files
committedJan 5, 2018
Restore HTML item atlas functionality
1 parent 8072d4d commit fee1c21

File tree

3 files changed

+25
-46
lines changed

3 files changed

+25
-46
lines changed
 

‎src/app/layout/qgslayouthtmlwidget.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,11 @@ void QgsLayoutHtmlWidget::mInsertExpressionButton_clicked()
352352
mHtmlEditor->getCursorPosition( &line, &index );
353353
}
354354

355-
#if 0 //TODO
356355
// use the atlas coverage layer, if any
357-
QgsVectorLayer *coverageLayer = atlasCoverageLayer();
358-
#endif
359-
QgsVectorLayer *coverageLayer = nullptr;
356+
QgsVectorLayer *layer = coverageLayer();
360357

361358
QgsExpressionContext context = mHtml->createExpressionContext();
362-
QgsExpressionBuilderDialog exprDlg( coverageLayer, selText, this, QStringLiteral( "generic" ), context );
359+
QgsExpressionBuilderDialog exprDlg( layer, selText, this, QStringLiteral( "generic" ), context );
363360
exprDlg.setWindowTitle( tr( "Insert Expression" ) );
364361
if ( exprDlg.exec() == QDialog::Accepted )
365362
{

‎src/core/layout/qgslayoutitemhtml.cpp

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsmapsettings.h"
2929
#include "qgswebpage.h"
3030
#include "qgswebframe.h"
31+
#include "qgslayoutitemmap.h"
3132

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

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

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

59-
if ( mComposition && mComposition->atlasMode() == QgsComposition::PreviewAtlas )
60-
{
61-
//a html item added while atlas preview is enabled needs to have the expression context set,
62-
//otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457)
63-
setExpressionContext( mComposition->atlasComposition().feature(), mComposition->atlasComposition().coverageLayer() );
64-
}
65-
66-
//connect to atlas feature changes
67-
//to update the expression context
68-
connect( &mComposition->atlasComposition(), &QgsAtlasComposition::featureChanged, this, &QgsLayoutItemHtml::refreshExpressionContext );
69-
#endif
58+
connect( &mLayout->context(), &QgsLayoutContext::changed, this, &QgsLayoutItemHtml::refreshExpressionContext );
7059

7160
mFetcher = new QgsNetworkContentFetcher();
7261
}
@@ -496,39 +485,39 @@ void QgsLayoutItemHtml::setExpressionContext( const QgsFeature &feature, QgsVect
496485
}
497486
else if ( mLayout )
498487
{
499-
#if 0 //TODO
500488
//set to composition's mapsettings' crs
501-
QgsComposerMap *referenceMap = mComposition->referenceMap();
489+
QgsLayoutItemMap *referenceMap = mLayout->referenceMap();
502490
if ( referenceMap )
503-
mDistanceArea->setSourceCrs( referenceMap->crs() );
504-
#endif
491+
mDistanceArea.setSourceCrs( referenceMap->crs(), mLayout->project()->transformContext() );
505492
}
506493
if ( mLayout )
507494
{
508495
mDistanceArea.setEllipsoid( mLayout->project()->ellipsoid() );
509496
}
510497

511-
// create JSON representation of feature
512-
QgsJsonExporter exporter( layer );
513-
exporter.setIncludeRelated( true );
514-
mAtlasFeatureJSON = exporter.exportFeature( feature );
498+
if ( feature.isValid() )
499+
{
500+
// create JSON representation of feature
501+
QgsJsonExporter exporter( layer );
502+
exporter.setIncludeRelated( true );
503+
mAtlasFeatureJSON = exporter.exportFeature( feature );
504+
}
505+
else
506+
{
507+
mAtlasFeatureJSON.clear();
508+
}
515509
}
516510

517511
void QgsLayoutItemHtml::refreshExpressionContext()
518512
{
519513
QgsVectorLayer *vl = nullptr;
520514
QgsFeature feature;
521515

522-
#if 0 //TODO
523-
if ( mComposition->atlasComposition().enabled() )
524-
{
525-
vl = mComposition->atlasComposition().coverageLayer();
526-
}
527-
if ( mComposition->atlasMode() != QgsComposition::AtlasOff )
516+
if ( mLayout )
528517
{
529-
feature = mComposition->atlasComposition().feature();
518+
vl = mLayout->context().layer();
519+
feature = mLayout->context().feature();
530520
}
531-
#endif
532521

533522
setExpressionContext( feature, vl );
534523
loadHtml( true );

‎src/core/layout/qgslayoutitemlabel.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ QgsLayoutItemLabel::QgsLayoutItemLabel( QgsLayout *layout )
6767
//otherwise fields in the label aren't correctly evaluated until atlas preview feature changes (#9457)
6868
refreshExpressionContext();
6969

70-
if ( mLayout )
71-
{
72-
//connect to context feature changes
73-
//to update the expression context
74-
connect( &mLayout->context(), &QgsLayoutContext::changed, this, &QgsLayoutItemLabel::refreshExpressionContext );
75-
}
76-
7770
mWebPage.reset( new QgsWebPage( this ) );
7871
mWebPage->setIdentifier( tr( "Layout label item" ) );
7972
mWebPage->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
@@ -253,7 +246,7 @@ void QgsLayoutItemLabel::refreshExpressionContext()
253246
//set to composition's reference map's crs
254247
QgsLayoutItemMap *referenceMap = mLayout->referenceMap();
255248
if ( referenceMap )
256-
mDistanceArea->setSourceCrs( referenceMap->crs() );
249+
mDistanceArea->setSourceCrs( referenceMap->crs(), mLayout->project()->transformContext() );
257250
}
258251
mDistanceArea->setEllipsoid( mLayout->project()->ellipsoid() );
259252
contentChanged();
@@ -493,7 +486,7 @@ void QgsLayoutItemLabel::setFrameStrokeWidth( const QgsLayoutMeasurement &stroke
493486
void QgsLayoutItemLabel::refresh()
494487
{
495488
QgsLayoutItem::refresh();
496-
contentChanged();
489+
refreshExpressionContext();
497490
}
498491

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

0 commit comments

Comments
 (0)
Please sign in to comment.