@@ -46,14 +46,14 @@ QgsComposerLegend::QgsComposerLegend( QgsComposition* composition )
46
46
, mForceResize( false )
47
47
, mSizeToContents( true )
48
48
{
49
- mLegendModel = new QgsLegendModel ( QgsProject::instance ()->layerTreeRoot () );
49
+ mLegendModel = new QgsLegendModel ( mComposition -> project ()->layerTreeRoot () );
50
50
51
51
connect ( &composition->atlasComposition (), SIGNAL ( renderEnded () ), this , SLOT ( onAtlasEnded () ) );
52
52
connect ( &composition->atlasComposition (), SIGNAL ( featureChanged ( QgsFeature* ) ), this , SLOT ( onAtlasFeature ( QgsFeature* ) ) );
53
53
54
54
// Connect to the main layertreeroot.
55
55
// It serves in "auto update mode" as a medium between the main app legend and this one
56
- connect ( QgsProject::instance ()->layerTreeRoot (), SIGNAL ( customPropertyChanged ( QgsLayerTreeNode*, QString ) ), this , SLOT ( nodeCustomPropertyChanged ( QgsLayerTreeNode*, QString ) ) );
56
+ connect ( mComposition -> project ()->layerTreeRoot (), SIGNAL ( customPropertyChanged ( QgsLayerTreeNode*, QString ) ), this , SLOT ( nodeCustomPropertyChanged ( QgsLayerTreeNode*, QString ) ) );
57
57
}
58
58
59
59
QgsComposerLegend::QgsComposerLegend ()
@@ -225,7 +225,7 @@ bool QgsComposerLegend::resizeToContents() const
225
225
226
226
void QgsComposerLegend::setCustomLayerTree ( QgsLayerTreeGroup* rootGroup )
227
227
{
228
- mLegendModel ->setRootGroup ( rootGroup ? rootGroup : QgsProject::instance ()->layerTreeRoot () );
228
+ mLegendModel ->setRootGroup ( rootGroup ? rootGroup : mComposition -> project ()->layerTreeRoot () );
229
229
230
230
delete mCustomLayerTree ;
231
231
mCustomLayerTree = rootGroup;
@@ -237,7 +237,7 @@ void QgsComposerLegend::setAutoUpdateModel( bool autoUpdate )
237
237
if ( autoUpdate == autoUpdateModel () )
238
238
return ;
239
239
240
- setCustomLayerTree ( autoUpdate ? nullptr : QgsLayerTree::toGroup ( QgsProject::instance ()->layerTreeRoot ()->clone () ) );
240
+ setCustomLayerTree ( autoUpdate ? nullptr : QgsLayerTree::toGroup ( mComposition -> project ()->layerTreeRoot ()->clone () ) );
241
241
adjustBoxSize ();
242
242
updateItem ();
243
243
}
@@ -414,7 +414,7 @@ bool QgsComposerLegend::writeXml( QDomElement& elem, QDomDocument & doc ) const
414
414
return _writeXml ( composerLegendElem, doc );
415
415
}
416
416
417
- static void _readOldLegendGroup ( QDomElement& elem, QgsLayerTreeGroup* parentGroup )
417
+ static void _readOldLegendGroup ( QDomElement& elem, QgsLayerTreeGroup* parentGroup, QgsProject* project )
418
418
{
419
419
QDomElement itemElem = elem.firstChildElement ();
420
420
@@ -424,7 +424,7 @@ static void _readOldLegendGroup( QDomElement& elem, QgsLayerTreeGroup* parentGro
424
424
if ( itemElem.tagName () == QLatin1String ( " LayerItem" ) )
425
425
{
426
426
QString layerId = itemElem.attribute ( QStringLiteral ( " layerId" ) );
427
- if ( QgsMapLayer* layer = QgsProject::instance () ->mapLayer ( layerId ) )
427
+ if ( QgsMapLayer* layer = project ->mapLayer ( layerId ) )
428
428
{
429
429
QgsLayerTreeLayer* nodeLayer = parentGroup->addLayer ( layer );
430
430
QString userText = itemElem.attribute ( QStringLiteral ( " userText" ) );
@@ -447,7 +447,7 @@ static void _readOldLegendGroup( QDomElement& elem, QgsLayerTreeGroup* parentGro
447
447
if ( !style.isEmpty () )
448
448
nodeGroup->setCustomProperty ( QStringLiteral ( " legend/title-style" ), style );
449
449
450
- _readOldLegendGroup ( itemElem, nodeGroup );
450
+ _readOldLegendGroup ( itemElem, nodeGroup, project );
451
451
}
452
452
453
453
itemElem = itemElem.nextSiblingElement ();
@@ -527,7 +527,7 @@ bool QgsComposerLegend::readXml( const QDomElement& itemElem, const QDomDocument
527
527
{
528
528
// QGIS <= 2.4
529
529
QgsLayerTreeGroup* nodeRoot = new QgsLayerTreeGroup ();
530
- _readOldLegendGroup ( oldLegendModelElem, nodeRoot );
530
+ _readOldLegendGroup ( oldLegendModelElem, nodeRoot, mComposition -> project () );
531
531
setCustomLayerTree ( nodeRoot );
532
532
}
533
533
else
@@ -687,7 +687,7 @@ void QgsComposerLegend::doUpdateFilterByMap()
687
687
mLegendModel ->setLayerStyleOverrides ( QMap<QString, QString>() );
688
688
689
689
690
- bool filterByExpression = QgsLayerTreeUtils::hasLegendFilterExpression ( *( mCustomLayerTree ? mCustomLayerTree : QgsProject::instance ()->layerTreeRoot () ) );
690
+ bool filterByExpression = QgsLayerTreeUtils::hasLegendFilterExpression ( *( mCustomLayerTree ? mCustomLayerTree : mComposition -> project ()->layerTreeRoot () ) );
691
691
692
692
if ( mComposerMap && ( mLegendFilterByMap || filterByExpression || mInAtlas ) )
693
693
{
0 commit comments