@@ -144,7 +144,7 @@ void QgsLayoutItemLegend::draw( QgsRenderContext &context, const QStyleOptionGra
144
144
}
145
145
146
146
QgsLegendRenderer legendRenderer ( mLegendModel .get (), mSettings );
147
- legendRenderer.setLegendSize ( mForceResize && mSizeToContents ? QSize () : rect ().size () );
147
+ legendRenderer.setLegendSize ( mSizeToContents ? QSize () : rect ().size () );
148
148
149
149
legendRenderer.drawLegend ( painter );
150
150
@@ -448,17 +448,8 @@ void QgsLayoutItemLegend::updateLegend()
448
448
updateFilterByMap ( false );
449
449
}
450
450
451
- #if 0 //TODO
452
- bool QgsLayoutItemLegend::writeXml( QDomElement &elem, QDomDocument &doc ) const
451
+ bool QgsLayoutItemLegend::writePropertiesToElement ( QDomElement &composerLegendElem, QDomDocument &doc, const QgsReadWriteContext & ) const
453
452
{
454
- if ( elem.isNull() )
455
- {
456
- return false;
457
- }
458
-
459
- QDomElement composerLegendElem = doc.createElement( QStringLiteral( "ComposerLegend" ) );
460
- elem.appendChild( composerLegendElem );
461
-
462
453
// write general properties
463
454
composerLegendElem.setAttribute ( QStringLiteral ( " title" ), mTitle );
464
455
composerLegendElem.setAttribute ( QStringLiteral ( " titleAlignment" ), QString::number ( static_cast < int >( mSettings .titleAlignment () ) ) );
@@ -486,7 +477,7 @@ bool QgsLayoutItemLegend::writeXml( QDomElement &elem, QDomDocument &doc ) const
486
477
487
478
if ( mMap )
488
479
{
489
- composerLegendElem.setAttribute( QStringLiteral( "map " ), mMap->id () );
480
+ composerLegendElem.setAttribute ( QStringLiteral ( " map_uuid " ), mMap ->uuid () );
490
481
}
491
482
492
483
QDomElement composerLegendStyles = doc.createElement ( QStringLiteral ( " styles" ) );
@@ -510,16 +501,11 @@ bool QgsLayoutItemLegend::writeXml( QDomElement &elem, QDomDocument &doc ) const
510
501
}
511
502
composerLegendElem.setAttribute ( QStringLiteral ( " legendFilterByAtlas" ), mFilterOutAtlas ? QStringLiteral ( " 1" ) : QStringLiteral ( " 0" ) );
512
503
513
- return _writeXml( composerLegendElem, doc ) ;
504
+ return true ;
514
505
}
515
506
516
- bool QgsLayoutItemLegend::readXml ( const QDomElement &itemElem, const QDomDocument &doc )
507
+ bool QgsLayoutItemLegend::readPropertiesFromElement ( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext & )
517
508
{
518
- if ( itemElem.isNull() )
519
- {
520
- return false;
521
- }
522
-
523
509
// read general properties
524
510
mTitle = itemElem.attribute ( QStringLiteral ( " title" ) );
525
511
mSettings .setTitle ( mTitle );
@@ -578,10 +564,19 @@ bool QgsLayoutItemLegend::readXml( const QDomElement &itemElem, const QDomDocume
578
564
579
565
// composer map
580
566
mLegendFilterByMap = itemElem.attribute ( QStringLiteral ( " legendFilterByMap" ), QStringLiteral ( " 0" ) ).toInt ();
567
+
568
+ #if 0 //TODO
581
569
if ( !itemElem.attribute( QStringLiteral( "map" ) ).isEmpty() )
582
570
{
583
571
setMap( mComposition->getComposerMapById( itemElem.attribute( QStringLiteral( "map" ) ).toInt() ) );
584
572
}
573
+ #endif
574
+ if ( !itemElem.attribute ( QStringLiteral ( " map_uuid" ) ).isEmpty () )
575
+ {
576
+ setMap ( qobject_cast< QgsLayoutItemMap * >( mLayout ->itemByUuid ( itemElem.attribute ( QStringLiteral ( " map_uuid" ) ) ) ) );
577
+ }
578
+
579
+
585
580
mFilterOutAtlas = itemElem.attribute ( QStringLiteral ( " legendFilterByAtlas" ), QStringLiteral ( " 0" ) ).toInt ();
586
581
587
582
// QGIS >= 2.6
@@ -592,67 +587,15 @@ bool QgsLayoutItemLegend::readXml( const QDomElement &itemElem, const QDomDocume
592
587
if ( !layerTreeElem.isNull () )
593
588
{
594
589
std::unique_ptr< QgsLayerTree > tree ( QgsLayerTree::readXml ( layerTreeElem ) );
595
- if ( mComposition )
596
- tree->resolveReferences( mComposition ->project(), true );
590
+ if ( mLayout )
591
+ tree->resolveReferences ( mLayout ->project (), true );
597
592
setCustomLayerTree ( tree.release () );
598
593
}
599
594
else
600
595
setCustomLayerTree ( nullptr );
601
596
602
- //restore general composer item properties
603
- QDomNodeList composerItemList = itemElem.elementsByTagName( QStringLiteral( "ComposerItem" ) );
604
- if ( !composerItemList.isEmpty() )
605
- {
606
- QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
607
- _readXml( composerItemElem, doc );
608
- }
609
-
610
- // < 2.0 projects backward compatibility >>>>>
611
- //title font
612
- QString titleFontString = itemElem.attribute( QStringLiteral( "titleFont" ) );
613
- if ( !titleFontString.isEmpty() )
614
- {
615
- rstyle( QgsLegendStyle::Title ).rfont().fromString( titleFontString );
616
- }
617
- //group font
618
- QString groupFontString = itemElem.attribute( QStringLiteral( "groupFont" ) );
619
- if ( !groupFontString.isEmpty() )
620
- {
621
- rstyle( QgsLegendStyle::Group ).rfont().fromString( groupFontString );
622
- }
623
-
624
- //layer font
625
- QString layerFontString = itemElem.attribute( QStringLiteral( "layerFont" ) );
626
- if ( !layerFontString.isEmpty() )
627
- {
628
- rstyle( QgsLegendStyle::Subgroup ).rfont().fromString( layerFontString );
629
- }
630
- //item font
631
- QString itemFontString = itemElem.attribute( QStringLiteral( "itemFont" ) );
632
- if ( !itemFontString.isEmpty() )
633
- {
634
- rstyle( QgsLegendStyle::SymbolLabel ).rfont().fromString( itemFontString );
635
- }
636
-
637
- if ( !itemElem.attribute( QStringLiteral( "groupSpace" ) ).isEmpty() )
638
- {
639
- rstyle( QgsLegendStyle::Group ).setMargin( QgsLegendStyle::Top, itemElem.attribute( QStringLiteral( "groupSpace" ), QStringLiteral( "3.0" ) ).toDouble() );
640
- }
641
- if ( !itemElem.attribute( QStringLiteral( "layerSpace" ) ).isEmpty() )
642
- {
643
- rstyle( QgsLegendStyle::Subgroup ).setMargin( QgsLegendStyle::Top, itemElem.attribute( QStringLiteral( "layerSpace" ), QStringLiteral( "3.0" ) ).toDouble() );
644
- }
645
- if ( !itemElem.attribute( QStringLiteral( "symbolSpace" ) ).isEmpty() )
646
- {
647
- rstyle( QgsLegendStyle::Symbol ).setMargin( QgsLegendStyle::Top, itemElem.attribute( QStringLiteral( "symbolSpace" ), QStringLiteral( "2.0" ) ).toDouble() );
648
- rstyle( QgsLegendStyle::SymbolLabel ).setMargin( QgsLegendStyle::Top, itemElem.attribute( QStringLiteral( "symbolSpace" ), QStringLiteral( "2.0" ) ).toDouble() );
649
- }
650
- // <<<<<<< < 2.0 projects backward compatibility
651
-
652
- emit itemChanged();
653
597
return true ;
654
598
}
655
- #endif
656
599
657
600
QString QgsLayoutItemLegend::displayName () const
658
601
{
0 commit comments