28
28
#include " qgsmapsettings.h"
29
29
#include " qgswebpage.h"
30
30
#include " qgswebframe.h"
31
+ #include " qgslayoutitemmap.h"
31
32
32
33
#include < QCoreApplication>
33
34
#include < QPainter>
@@ -50,23 +51,11 @@ QgsLayoutItemHtml::QgsLayoutItemHtml( QgsLayout *layout )
50
51
51
52
mWebPage ->setNetworkAccessManager ( QgsNetworkAccessManager::instance () );
52
53
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 () );
58
57
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 );
70
59
71
60
mFetcher = new QgsNetworkContentFetcher ();
72
61
}
@@ -496,39 +485,39 @@ void QgsLayoutItemHtml::setExpressionContext( const QgsFeature &feature, QgsVect
496
485
}
497
486
else if ( mLayout )
498
487
{
499
- #if 0 //TODO
500
488
// set to composition's mapsettings' crs
501
- QgsComposerMap *referenceMap = mComposition ->referenceMap();
489
+ QgsLayoutItemMap *referenceMap = mLayout ->referenceMap ();
502
490
if ( referenceMap )
503
- mDistanceArea->setSourceCrs( referenceMap->crs() );
504
- #endif
491
+ mDistanceArea .setSourceCrs ( referenceMap->crs (), mLayout ->project ()->transformContext () );
505
492
}
506
493
if ( mLayout )
507
494
{
508
495
mDistanceArea .setEllipsoid ( mLayout ->project ()->ellipsoid () );
509
496
}
510
497
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
+ }
515
509
}
516
510
517
511
void QgsLayoutItemHtml::refreshExpressionContext ()
518
512
{
519
513
QgsVectorLayer *vl = nullptr ;
520
514
QgsFeature feature;
521
515
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 )
528
517
{
529
- feature = mComposition->atlasComposition().feature();
518
+ vl = mLayout ->context ().layer ();
519
+ feature = mLayout ->context ().feature ();
530
520
}
531
- #endif
532
521
533
522
setExpressionContext ( feature, vl );
534
523
loadHtml ( true );
0 commit comments