@@ -265,6 +265,7 @@ void QgsComposerLegend::setLegendFilterByMapEnabled( bool enabled )
265265
266266void QgsComposerLegend::setTitle ( const QString& t )
267267{
268+ mTitle = t;
268269 mSettings .setTitle ( t );
269270
270271 if ( mComposition && id ().isEmpty () )
@@ -273,7 +274,7 @@ void QgsComposerLegend::setTitle( const QString& t )
273274 mComposition ->itemsModel ()->updateItemDisplayName ( this );
274275 }
275276}
276- QString QgsComposerLegend::title () const { return mSettings . title () ; }
277+ QString QgsComposerLegend::title () const { return mTitle ; }
277278
278279Qt::AlignmentFlag QgsComposerLegend::titleAlignment () const { return mSettings .titleAlignment (); }
279280void QgsComposerLegend::setTitleAlignment ( Qt::AlignmentFlag alignment ) { mSettings .setTitleAlignment ( alignment ); }
@@ -315,8 +316,8 @@ void QgsComposerLegend::setWmsLegendHeight( double h ) { mSettings.setWmsLegendS
315316void QgsComposerLegend::setWrapChar ( const QString& t ) { mSettings .setWrapChar ( t ); }
316317QString QgsComposerLegend::wrapChar () const {return mSettings .wrapChar (); }
317318
318- int QgsComposerLegend::columnCount () const { return mSettings . columnCount () ; }
319- void QgsComposerLegend::setColumnCount ( int c ) { mSettings .setColumnCount ( c ); }
319+ int QgsComposerLegend::columnCount () const { return mColumnCount ; }
320+ void QgsComposerLegend::setColumnCount ( int c ) { mColumnCount = c; mSettings .setColumnCount ( c ); }
320321
321322bool QgsComposerLegend::splitLayer () const { return mSettings .splitLayer (); }
322323void QgsComposerLegend::setSplitLayer ( bool s ) { mSettings .setSplitLayer ( s ); }
@@ -362,9 +363,9 @@ bool QgsComposerLegend::writeXml( QDomElement& elem, QDomDocument & doc ) const
362363 elem.appendChild ( composerLegendElem );
363364
364365 // write general properties
365- composerLegendElem.setAttribute ( QStringLiteral ( " title" ), mSettings . title () );
366+ composerLegendElem.setAttribute ( QStringLiteral ( " title" ), mTitle );
366367 composerLegendElem.setAttribute ( QStringLiteral ( " titleAlignment" ), QString::number ( static_cast < int >( mSettings .titleAlignment () ) ) );
367- composerLegendElem.setAttribute ( QStringLiteral ( " columnCount" ), QString::number ( mSettings . columnCount () ) );
368+ composerLegendElem.setAttribute ( QStringLiteral ( " columnCount" ), QString::number ( mColumnCount ) );
368369 composerLegendElem.setAttribute ( QStringLiteral ( " splitLayer" ), QString::number ( mSettings .splitLayer () ) );
369370 composerLegendElem.setAttribute ( QStringLiteral ( " equalColumnWidth" ), QString::number ( mSettings .equalColumnWidth () ) );
370371
@@ -462,14 +463,16 @@ bool QgsComposerLegend::readXml( const QDomElement& itemElem, const QDomDocument
462463 }
463464
464465 // read general properties
465- mSettings .setTitle ( itemElem.attribute ( QStringLiteral ( " title" ) ) );
466+ mTitle = itemElem.attribute ( QStringLiteral ( " title" ) );
467+ mSettings .setTitle ( mTitle );
466468 if ( !itemElem.attribute ( QStringLiteral ( " titleAlignment" ) ).isEmpty () )
467469 {
468470 mSettings .setTitleAlignment ( static_cast < Qt::AlignmentFlag >( itemElem.attribute ( QStringLiteral ( " titleAlignment" ) ).toInt () ) );
469471 }
470472 int colCount = itemElem.attribute ( QStringLiteral ( " columnCount" ), QStringLiteral ( " 1" ) ).toInt ();
471473 if ( colCount < 1 ) colCount = 1 ;
472- mSettings .setColumnCount ( colCount );
474+ mColumnCount = colCount;
475+ mSettings .setColumnCount ( mColumnCount );
473476 mSettings .setSplitLayer ( itemElem.attribute ( QStringLiteral ( " splitLayer" ), QStringLiteral ( " 0" ) ).toInt () == 1 );
474477 mSettings .setEqualColumnWidth ( itemElem.attribute ( QStringLiteral ( " equalColumnWidth" ), QStringLiteral ( " 0" ) ).toInt () == 1 );
475478
@@ -642,6 +645,42 @@ void QgsComposerLegend::invalidateCurrentMap()
642645 setComposerMap ( nullptr );
643646}
644647
648+ void QgsComposerLegend::refreshDataDefinedProperty ( const QgsComposerObject::DataDefinedProperty property, const QgsExpressionContext* context )
649+ {
650+ QgsExpressionContext scopedContext = createExpressionContext ();
651+ const QgsExpressionContext* evalContext = context ? context : &scopedContext;
652+
653+ bool forceUpdate = false ;
654+ // updates data defined properties and redraws item to match
655+ if ( property == QgsComposerObject::LegendTitle || property == QgsComposerObject::AllProperties )
656+ {
657+ bool ok = false ;
658+ QString t = mProperties .valueAsString ( QgsComposerObject::LegendTitle, *evalContext, mTitle , &ok );
659+ if ( ok )
660+ {
661+ mSettings .setTitle ( t );
662+ forceUpdate = true ;
663+ }
664+ }
665+ if ( property == QgsComposerObject::LegendColumnCount || property == QgsComposerObject::AllProperties )
666+ {
667+ bool ok = false ;
668+ int cols = mProperties .valueAsInt ( QgsComposerObject::LegendColumnCount, *evalContext, mColumnCount , &ok );
669+ if ( ok && cols >= 0 )
670+ {
671+ mSettings .setColumnCount ( cols );
672+ forceUpdate = true ;
673+ }
674+ }
675+ if ( forceUpdate )
676+ {
677+ adjustBoxSize ();
678+ update ();
679+ }
680+
681+ QgsComposerObject::refreshDataDefinedProperty ( property, context );
682+ }
683+
645684void QgsComposerLegend::mapLayerStyleOverridesChanged ()
646685{
647686 if ( !mComposerMap )
0 commit comments