Skip to content

Commit

Permalink
Allow data defined format properties for layout labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 1, 2021
1 parent edab6ff commit 5976e85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/gui/layout/qgslayoutlabelwidget.cpp
Expand Up @@ -51,6 +51,8 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
setPanelTitle( tr( "Label Properties" ) );

mFontButton->setMode( QgsFontButton::ModeTextRenderer );
mFontButton->setDialogTitle( tr( "Label Font" ) );
mFontButton->registerExpressionContextGenerator( this );

//add widget for general composer item properties
mItemPropertiesWidget = new QgsLayoutItemPropertiesWidget( this, label );
Expand Down Expand Up @@ -88,6 +90,12 @@ QgsLayoutLabelWidget::QgsLayoutLabelWidget( QgsLayoutItemLabel *label )
expressionMenu->addAction( convertToStaticAction );
connect( convertToStaticAction, &QAction::triggered, mLabel, &QgsLayoutItemLabel::convertToStaticText );
mInsertExpressionButton->setMenu( expressionMenu );

mFontButton->setLayer( coverageLayer() );
if ( mLabel->layout() )
{
connect( &mLabel->layout()->reportContext(), &QgsLayoutReportContext::layerChanged, mFontButton, &QgsFontButton::setLayer );
}
}

void QgsLayoutLabelWidget::setMasterLayout( QgsMasterLayoutInterface *masterLayout )
Expand All @@ -96,6 +104,11 @@ void QgsLayoutLabelWidget::setMasterLayout( QgsMasterLayoutInterface *masterLayo
mItemPropertiesWidget->setMasterLayout( masterLayout );
}

QgsExpressionContext QgsLayoutLabelWidget::createExpressionContext() const
{
return mLabel->createExpressionContext();
}

void QgsLayoutLabelWidget::buildInsertDynamicTextMenu( QgsLayout *layout, QMenu *menu, const std::function<void ( const QString & )> &callback )
{
Q_ASSERT( layout );
Expand Down
3 changes: 2 additions & 1 deletion src/gui/layout/qgslayoutlabelwidget.h
Expand Up @@ -34,13 +34,14 @@
* \note This class is not a part of public API
* \since QGIS 3.12
*/
class GUI_EXPORT QgsLayoutLabelWidget: public QgsLayoutItemBaseWidget, private Ui::QgsLayoutLabelWidgetBase
class GUI_EXPORT QgsLayoutLabelWidget: public QgsLayoutItemBaseWidget, public QgsExpressionContextGenerator, private Ui::QgsLayoutLabelWidgetBase
{
Q_OBJECT
public:
//! constructor
explicit QgsLayoutLabelWidget( QgsLayoutItemLabel *label );
void setMasterLayout( QgsMasterLayoutInterface *masterLayout ) override;
QgsExpressionContext createExpressionContext() const override;

/**
* Populates the specified \a menu with actions reflecting dynamic text expressions applicable for a \a layout.
Expand Down

0 comments on commit 5976e85

Please sign in to comment.