48 #include <QMessageBox> 
   49 #include <QInputDialog> 
   66   int unfilteredNodeIndex = _unfilteredLegendNodeIndex( 
legendNode );
 
   68   return ( unfilteredNodeIndex >= 0 && unfilteredNodeIndex < order.count() ? order[unfilteredNodeIndex] : -1 );
 
   75   , mMapCanvas( mapCanvas )
 
   80   connect( mWrapCharLineEdit, &QLineEdit::textChanged, 
this, &QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged );
 
   81   connect( mTitleLineEdit, &QLineEdit::textChanged, 
this, &QgsLayoutLegendWidget::mTitleLineEdit_textChanged );
 
   86   connect( mColumnCountSpinBox, 
static_cast < void ( QSpinBox::* )( 
int ) 
> ( &QSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged );
 
   87   connect( mSplitLayerCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled );
 
   88   connect( mEqualColumnWidthCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled );
 
   89   connect( mSymbolWidthSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged );
 
   90   connect( mSymbolHeightSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged );
 
   91   connect( mMaxSymbolSizeSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged );
 
   92   connect( mMinSymbolSizeSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged );
 
   93   connect( mWmsLegendWidthSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged );
 
   94   connect( mWmsLegendHeightSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged );
 
   95   connect( mTitleSpaceBottomSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged );
 
   96   connect( mGroupSpaceSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged );
 
   97   connect( mGroupIndentSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged );
 
   98   connect( mSubgroupIndentSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged );
 
   99   connect( mSpaceBelowGroupHeadingSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged );
 
  100   connect( mGroupSideSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::spaceGroupSideChanged );
 
  101   connect( mLayerSpaceSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged );
 
  102   connect( mSpaceBelowSubgroupHeadingSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged );
 
  103   connect( mSubgroupSideSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::spaceSubGroupSideChanged );
 
  104   connect( mSymbolSpaceSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged );
 
  105   connect( mSymbolSideSpaceSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::spaceSymbolSideChanged );
 
  106   connect( mIconLabelSpaceSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged );
 
  108   connect( mBoxSpaceSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged );
 
  109   connect( mColumnSpaceSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged );
 
  110   connect( mLineSpacingSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mLineSpacingSpinBox_valueChanged );
 
  111   connect( mCheckBoxAutoUpdate, &QCheckBox::stateChanged, 
this, [ = ]( 
int state ) { mCheckBoxAutoUpdate_stateChanged( state ); } );
 
  112   connect( mCheckboxResizeContents, &QCheckBox::toggled, 
this, &QgsLayoutLegendWidget::mCheckboxResizeContents_toggled );
 
  113   connect( mRasterStrokeGroupBox, &QgsCollapsibleGroupBoxBasic::toggled, 
this, &QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled );
 
  114   connect( mRasterStrokeWidthSpinBox, 
static_cast < void ( QDoubleSpinBox::* )( 
double ) 
> ( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged );
 
  115   connect( mRasterStrokeColorButton, &
QgsColorButton::colorChanged, 
this, &QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged );
 
  116   connect( mMoveDownToolButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mMoveDownToolButton_clicked );
 
  117   connect( mMoveUpToolButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mMoveUpToolButton_clicked );
 
  118   connect( mRemoveToolButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mRemoveToolButton_clicked );
 
  119   connect( mAddToolButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mAddToolButton_clicked );
 
  120   connect( mEditPushButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mEditPushButton_clicked );
 
  121   connect( mCountToolButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mCountToolButton_clicked );
 
  122   connect( mExpressionFilterButton, &QgsLegendFilterButton::toggled, 
this, &QgsLayoutLegendWidget::mExpressionFilterButton_toggled );
 
  123   connect( mLayerExpressionButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mLayerExpressionButton_clicked );
 
  124   connect( mFilterByMapCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled );
 
  125   connect( mUpdateAllPushButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mUpdateAllPushButton_clicked );
 
  126   connect( mAddGroupToolButton, &QToolButton::clicked, 
this, &QgsLayoutLegendWidget::mAddGroupToolButton_clicked );
 
  127   connect( mFilterLegendByAtlasCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled );
 
  128   connect( mItemTreeView, &QgsLayerTreeView::doubleClicked, 
this, &QgsLayoutLegendWidget::mItemTreeView_doubleClicked );
 
  129   setPanelTitle( tr( 
"Legend Properties" ) );
 
  136   mTitleAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
 
  137   mGroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
 
  138   mSubgroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
 
  139   mItemAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
 
  141   mArrangementCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignRight );
 
  143   mArrangementCombo->customizeAlignmentDisplay( Qt::AlignLeft, tr( 
"Symbols on Left" ), 
QgsApplication::getThemeIcon( QStringLiteral( 
"/mIconArrangeSymbolsLeft.svg" ) ) );
 
  144   mArrangementCombo->customizeAlignmentDisplay( Qt::AlignRight, tr( 
"Symbols on Right" ), 
QgsApplication::getThemeIcon( QStringLiteral( 
"/mIconArrangeSymbolsRight.svg" ) ) );
 
  146   mSpaceBelowGroupHeadingSpinBox->setClearValue( 0 );
 
  147   mGroupSideSpinBox->setClearValue( 0 );
 
  148   mSpaceBelowSubgroupHeadingSpinBox->setClearValue( 0 );
 
  149   mSubgroupSideSpinBox->setClearValue( 0 );
 
  150   mSymbolSideSpaceSpinBox->setClearValue( 0 );
 
  171   mFontColorButton->setColorDialogTitle( tr( 
"Select Font Color" ) );
 
  172   mFontColorButton->setContext( QStringLiteral( 
"composer" ) );
 
  174   mRasterStrokeColorButton->setColorDialogTitle( tr( 
"Select Stroke Color" ) );
 
  175   mRasterStrokeColorButton->setAllowOpacity( 
true );
 
  176   mRasterStrokeColorButton->setContext( QStringLiteral( 
"composer " ) );
 
  178   mMapComboBox->setCurrentLayout( legend->
layout() );
 
  184   mainLayout->addWidget( mItemPropertiesWidget );
 
  186   mItemTreeView->setHeaderHidden( 
true );
 
  188   mItemTreeView->setModel( legend->
model() );
 
  189   mItemTreeView->setMenuProvider( 
new QgsLayoutLegendMenuProvider( mItemTreeView, 
this ) );
 
  190   setLegendMapViewData();
 
  196     connect( layoutAtlas(), &
QgsLayoutAtlas::toggled, 
this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
 
  205   connect( mItemTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
 
  206            this, &QgsLayoutLegendWidget::selectedChanged );
 
  215   if ( mItemPropertiesWidget )
 
  216     mItemPropertiesWidget->setMasterLayout( masterLayout );
 
  219 void QgsLayoutLegendWidget::setGuiElements()
 
  226   blockAllSignals( 
true );
 
  227   mTitleLineEdit->setText( mLegend->title() );
 
  228   whileBlocking( mTitleAlignCombo )->setCurrentAlignment( mLegend->titleAlignment() );
 
  232   whileBlocking( mArrangementCombo )->setCurrentAlignment( mLegend->symbolAlignment() );
 
  233   mFilterByMapCheckBox->setChecked( mLegend->legendFilterByMapEnabled() );
 
  234   mColumnCountSpinBox->setValue( mLegend->columnCount() );
 
  235   mSplitLayerCheckBox->setChecked( mLegend->splitLayer() );
 
  236   mEqualColumnWidthCheckBox->setChecked( mLegend->equalColumnWidth() );
 
  237   mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
 
  238   mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
 
  239   mMaxSymbolSizeSpinBox->setValue( mLegend->maximumSymbolSize() );
 
  240   mMinSymbolSizeSpinBox->setValue( mLegend->minimumSymbolSize() );
 
  241   mWmsLegendWidthSpinBox->setValue( mLegend->wmsLegendWidth() );
 
  242   mWmsLegendHeightSpinBox->setValue( mLegend->wmsLegendHeight() );
 
  256   mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
 
  257   mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
 
  258   mLineSpacingSpinBox->setValue( mLegend->lineSpacing() );
 
  260   mRasterStrokeGroupBox->setChecked( mLegend->drawRasterStroke() );
 
  261   mRasterStrokeWidthSpinBox->setValue( mLegend->rasterStrokeWidth() );
 
  262   mRasterStrokeColorButton->setColor( mLegend->rasterStrokeColor() );
 
  264   mCheckBoxAutoUpdate->setChecked( mLegend->autoUpdateModel() );
 
  266   mCheckboxResizeContents->setChecked( mLegend->resizeToContents() );
 
  267   mFilterLegendByAtlasCheckBox->setChecked( mLegend->legendFilterOutAtlas() );
 
  268   mWrapCharLineEdit->setText( mLegend->wrapString() );
 
  271   mMapComboBox->setItem( map );
 
  272   mFontColorButton->setColor( mLegend->fontColor() );
 
  278   blockAllSignals( 
false );
 
  280   mCheckBoxAutoUpdate_stateChanged( mLegend->autoUpdateModel() ? Qt::Checked : Qt::Unchecked, 
false );
 
  281   updateDataDefinedButton( mLegendTitleDDBtn );
 
  282   updateDataDefinedButton( mColumnsDDBtn );
 
  285 void QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged( 
const QString &text )
 
  289     mLegend->beginCommand( tr( 
"Change Legend Wrap" ) );
 
  290     mLegend->setWrapString( text );
 
  291     mLegend->adjustBoxSize();
 
  293     mLegend->endCommand();
 
  297 void QgsLayoutLegendWidget::mTitleLineEdit_textChanged( 
const QString &text )
 
  302     mLegend->setTitle( text );
 
  303     mLegend->adjustBoxSize();
 
  305     mLegend->endCommand();
 
  309 void QgsLayoutLegendWidget::titleAlignmentChanged()
 
  313     Qt::AlignmentFlag alignment = 
static_cast< Qt::AlignmentFlag 
>( 
static_cast< int  >( mTitleAlignCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
 
  314     mLegend->beginCommand( tr( 
"Change Title Alignment" ) );
 
  315     mLegend->setTitleAlignment( alignment );
 
  317     mLegend->endCommand();
 
  321 void QgsLayoutLegendWidget::groupAlignmentChanged()
 
  325     mLegend->beginCommand( tr( 
"Change Group Alignment" ) );
 
  328     mLegend->endCommand();
 
  332 void QgsLayoutLegendWidget::subgroupAlignmentChanged()
 
  336     mLegend->beginCommand( tr( 
"Change Subgroup Alignment" ) );
 
  339     mLegend->endCommand();
 
  343 void QgsLayoutLegendWidget::itemAlignmentChanged()
 
  347     mLegend->beginCommand( tr( 
"Change Item Alignment" ) );
 
  350     mLegend->endCommand();
 
  354 void QgsLayoutLegendWidget::arrangementChanged()
 
  358     Qt::AlignmentFlag alignment = 
static_cast< Qt::AlignmentFlag 
>( 
static_cast< int  >( mArrangementCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
 
  359     mLegend->beginCommand( tr( 
"Change Legend Arrangement" ) );
 
  360     mLegend->setSymbolAlignment( alignment );
 
  362     mLegend->endCommand();
 
  366 void QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged( 
int c )
 
  371     mLegend->setColumnCount( 
c );
 
  372     mLegend->adjustBoxSize();
 
  374     mLegend->endCommand();
 
  376   mSplitLayerCheckBox->setEnabled( 
c > 1 );
 
  377   mEqualColumnWidthCheckBox->setEnabled( 
c > 1 );
 
  380 void QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled( 
bool checked )
 
  384     mLegend->beginCommand( tr( 
"Split Legend Layers" ) );
 
  385     mLegend->setSplitLayer( checked );
 
  386     mLegend->adjustBoxSize();
 
  388     mLegend->endCommand();
 
  392 void QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled( 
bool checked )
 
  396     mLegend->beginCommand( tr( 
"Legend Column Width" ) );
 
  397     mLegend->setEqualColumnWidth( checked );
 
  398     mLegend->adjustBoxSize();
 
  400     mLegend->endCommand();
 
  404 void QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged( 
double d )
 
  409     mLegend->setSymbolWidth( d );
 
  410     mLegend->adjustBoxSize();
 
  412     mLegend->endCommand();
 
  416 void QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged( 
double d )
 
  421     mLegend->setMaximumSymbolSize( d );
 
  422     mLegend->adjustBoxSize();
 
  424     mLegend->endCommand();
 
  428 void QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged( 
double d )
 
  433     mLegend->setMinimumSymbolSize( d );
 
  434     mLegend->adjustBoxSize();
 
  436     mLegend->endCommand();
 
  440 void QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged( 
double d )
 
  445     mLegend->setSymbolHeight( d );
 
  446     mLegend->adjustBoxSize();
 
  448     mLegend->endCommand();
 
  452 void QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged( 
double d )
 
  457     mLegend->setWmsLegendWidth( d );
 
  458     mLegend->adjustBoxSize();
 
  460     mLegend->endCommand();
 
  464 void QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged( 
double d )
 
  469     mLegend->setWmsLegendHeight( d );
 
  470     mLegend->adjustBoxSize();
 
  472     mLegend->endCommand();
 
  476 void QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged( 
double d )
 
  482     mLegend->adjustBoxSize();
 
  484     mLegend->endCommand();
 
  488 void QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged( 
double d )
 
  494     mLegend->adjustBoxSize();
 
  496     mLegend->endCommand();
 
  500 void QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged( 
double d )
 
  506     mLegend->adjustBoxSize();
 
  508     mLegend->endCommand();
 
  512 void QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged( 
double d )
 
  518     mLegend->adjustBoxSize();
 
  520     mLegend->endCommand();
 
  524 void QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged( 
double space )
 
  530     mLegend->adjustBoxSize();
 
  532     mLegend->endCommand();
 
  536 void QgsLayoutLegendWidget::spaceGroupSideChanged( 
double space )
 
  542     mLegend->adjustBoxSize();
 
  544     mLegend->endCommand();
 
  548 void QgsLayoutLegendWidget::spaceSubGroupSideChanged( 
double space )
 
  554     mLegend->adjustBoxSize();
 
  556     mLegend->endCommand();
 
  560 void QgsLayoutLegendWidget::spaceSymbolSideChanged( 
double space )
 
  566     mLegend->adjustBoxSize();
 
  568     mLegend->endCommand();
 
  572 void QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged( 
double d )
 
  578     mLegend->adjustBoxSize();
 
  580     mLegend->endCommand();
 
  584 void QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged( 
double d )
 
  592     mLegend->adjustBoxSize();
 
  594     mLegend->endCommand();
 
  598 void QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged( 
double d )
 
  604     mLegend->adjustBoxSize();
 
  606     mLegend->endCommand();
 
  610 void QgsLayoutLegendWidget::titleFontChanged()
 
  616     mLegend->adjustBoxSize();
 
  618     mLegend->endCommand();
 
  622 void QgsLayoutLegendWidget::groupFontChanged()
 
  628     mLegend->adjustBoxSize();
 
  630     mLegend->endCommand();
 
  634 void QgsLayoutLegendWidget::layerFontChanged()
 
  640     mLegend->adjustBoxSize();
 
  642     mLegend->endCommand();
 
  646 void QgsLayoutLegendWidget::itemFontChanged()
 
  652     mLegend->adjustBoxSize();
 
  654     mLegend->endCommand();
 
  658 void QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged( 
double space )
 
  664     mLegend->adjustBoxSize();
 
  666     mLegend->endCommand();
 
  670 void QgsLayoutLegendWidget::mFontColorButton_colorChanged( 
const QColor &newFontColor )
 
  678   mLegend->setFontColor( newFontColor );
 
  680   mLegend->endCommand();
 
  683 void QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged( 
double d )
 
  688     mLegend->setBoxSpace( d );
 
  689     mLegend->adjustBoxSize();
 
  691     mLegend->endCommand();
 
  695 void QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged( 
double d )
 
  700     mLegend->setColumnSpace( d );
 
  701     mLegend->adjustBoxSize();
 
  703     mLegend->endCommand();
 
  707 void QgsLayoutLegendWidget::mLineSpacingSpinBox_valueChanged( 
double d )
 
  712     mLegend->setLineSpacing( d );
 
  713     mLegend->adjustBoxSize();
 
  715     mLegend->endCommand();
 
  719 static void _moveLegendNode( 
QgsLayerTreeLayer *nodeLayer, 
int legendNodeIndex, 
int offset )
 
  723   if ( legendNodeIndex < 0 || legendNodeIndex >= order.count() )
 
  725   if ( legendNodeIndex + offset < 0 || legendNodeIndex + offset >= order.count() )
 
  728   int id = order.takeAt( legendNodeIndex );
 
  729   order.insert( legendNodeIndex + offset, 
id );
 
  735 void QgsLayoutLegendWidget::mMoveDownToolButton_clicked()
 
  742   const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
 
  743   const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
 
  744   const QModelIndex parentIndex = sourceIndex.parent();
 
  745   if ( !sourceIndex.isValid() || sourceIndex.row() == mItemTreeView->layerTreeModel()->rowCount( parentIndex ) - 1 )
 
  753   mLegend->beginCommand( tr( 
"Moved Legend Item Down" ) );
 
  767   mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() + 1, 0, parentIndex ) ) );
 
  770   mLegend->endCommand();
 
  773 void QgsLayoutLegendWidget::mMoveUpToolButton_clicked()
 
  780   const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
 
  781   const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
 
  782   const QModelIndex parentIndex = sourceIndex.parent();
 
  783   if ( !sourceIndex.isValid() || sourceIndex.row() == 0 )
 
  791   mLegend->beginCommand( tr( 
"Move Legend Item Up" ) );
 
  805   mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() - 1, 0, parentIndex ) ) );
 
  808   mLegend->endCommand();
 
  811 void QgsLayoutLegendWidget::mCheckBoxAutoUpdate_stateChanged( 
int state, 
bool userTriggered )
 
  815     mLegend->beginCommand( tr( 
"Change Auto Update" ) );
 
  817     mLegend->setAutoUpdateModel( state == Qt::Checked );
 
  819     mLegend->updateFilterByMap();
 
  820     mLegend->endCommand();
 
  824   QList<QWidget *> widgets;
 
  825   widgets << mMoveDownToolButton << mMoveUpToolButton << mRemoveToolButton << mAddToolButton
 
  826           << mEditPushButton << mCountToolButton << mUpdateAllPushButton << mAddGroupToolButton
 
  827           << mExpressionFilterButton;
 
  828   for ( QWidget *w : std::as_const( widgets ) )
 
  829     w->setEnabled( state != Qt::Checked );
 
  831   if ( state == Qt::Unchecked )
 
  834     selectedChanged( QModelIndex(), QModelIndex() );
 
  838 void QgsLayoutLegendWidget::composerMapChanged( 
QgsLayoutItem *item )
 
  854     mLegend->beginCommand( tr( 
"Change Legend Map" ) );
 
  855     mLegend->setLinkedMap( map );
 
  856     mLegend->updateFilterByMap();
 
  857     mLegend->endCommand();
 
  859     setLegendMapViewData();
 
  863 void QgsLayoutLegendWidget::mCheckboxResizeContents_toggled( 
bool checked )
 
  870   mLegend->beginCommand( tr( 
"Resize Legend to Contents" ) );
 
  871   mLegend->setResizeToContents( checked );
 
  873     mLegend->adjustBoxSize();
 
  874   mLegend->updateFilterByMap();
 
  875   mLegend->endCommand();
 
  878 void QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled( 
bool state )
 
  885   mLegend->beginCommand( tr( 
"Change Legend Borders" ) );
 
  886   mLegend->setDrawRasterStroke( state );
 
  887   mLegend->adjustBoxSize();
 
  889   mLegend->endCommand();
 
  892 void QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged( 
double d )
 
  900   mLegend->setRasterStrokeWidth( d );
 
  901   mLegend->adjustBoxSize();
 
  903   mLegend->endCommand();
 
  906 void QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged( 
const QColor &newColor )
 
  914   mLegend->setRasterStrokeColor( newColor );
 
  916   mLegend->endCommand();
 
  919 void QgsLayoutLegendWidget::mAddToolButton_clicked()
 
  926   QList< QgsMapLayer * > visibleLayers;
 
  927   if ( mLegend->linkedMap() )
 
  929     visibleLayers = mLegend->linkedMap()->layersToRender();
 
  931   if ( visibleLayers.isEmpty() )
 
  934     visibleLayers = mMapCanvas->layers( 
true );
 
  938   addDialog.setVisibleLayers( visibleLayers );
 
  939   if ( addDialog.exec() == QDialog::Accepted )
 
  941     const QList<QgsMapLayer *> layers = addDialog.selectedLayers();
 
  942     if ( !layers.empty() )
 
  944       mLegend->beginCommand( tr( 
"Add Legend Item(s)" ) );
 
  947         mLegend->model()->rootGroup()->addLayer( layer );
 
  949       mLegend->updateLegend();
 
  951       mLegend->endCommand();
 
  956 void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
 
  963   QItemSelectionModel *selectionModel = mItemTreeView->selectionModel();
 
  964   if ( !selectionModel )
 
  969   mLegend->beginCommand( tr( 
"Remove Legend Item" ) );
 
  971   QList<QPersistentModelIndex> proxyIndexes;
 
  972   const QModelIndexList viewSelection = selectionModel->selectedIndexes();
 
  973   for ( 
const QModelIndex &index : viewSelection )
 
  974     proxyIndexes << index;
 
  977   QHash<QgsLayerTreeLayer *, QList<int> > nodesWithRemoval;
 
  978   for ( 
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
 
  983       nodesWithRemoval[nodeLayer].append( _unfilteredLegendNodeIndex( 
legendNode ) );
 
  986   for ( 
auto it = nodesWithRemoval.constBegin(); it != nodesWithRemoval.constEnd(); ++it )
 
  988     QList<int> toDelete = it.value();
 
  989     std::sort( toDelete.begin(), toDelete.end(), std::greater<int>() );
 
  992     for ( 
int i : std::as_const( toDelete ) )
 
  994       if ( i >= 0 && i < order.count() )
 
  999     mItemTreeView->layerTreeModel()->refreshLayerLegend( it.key() );
 
 1003   for ( 
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
 
 1005     if ( proxyIndex.isValid() && mItemTreeView->index2node( proxyIndex ) )
 
 1007       const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( proxyIndex );
 
 1008       mLegend->model()->removeRow( sourceIndex.row(), sourceIndex.parent() );
 
 1012   mLegend->updateLegend();
 
 1014   mLegend->endCommand();
 
 1017 void QgsLayoutLegendWidget::mEditPushButton_clicked()
 
 1024   QModelIndex idx = mItemTreeView->selectionModel()->currentIndex();
 
 1025   mItemTreeView_doubleClicked( idx );
 
 1028 void QgsLayoutLegendWidget::resetLayerNodeToDefaults()
 
 1036   QModelIndex currentIndex = mItemTreeView->currentIndex();
 
 1037   if ( !currentIndex.isValid() )
 
 1056   mLegend->beginCommand( tr( 
"Update Legend" ) );
 
 1059   for ( 
const QString &key : constCustomProperties )
 
 1061     if ( key.startsWith( QLatin1String( 
"legend/" ) ) )
 
 1068   mItemTreeView->layerTreeModel()->refreshLayerLegend( nodeLayer );
 
 1070   mLegend->updateLegend();
 
 1072   mLegend->endCommand();
 
 1075 void QgsLayoutLegendWidget::mCountToolButton_clicked( 
bool checked )
 
 1082   const QList< QModelIndex > selectedIndexes = mItemTreeView->selectionModel()->selectedIndexes();
 
 1083   if ( selectedIndexes.empty() )
 
 1086   mLegend->beginCommand( tr( 
"Update Legend" ) );
 
 1087   for ( 
const QModelIndex &index : selectedIndexes )
 
 1093     currentNode->
setCustomProperty( QStringLiteral( 
"showFeatureCount" ), checked ? 1 : 0 );
 
 1095   mLegend->updateFilterByMap();
 
 1096   mLegend->adjustBoxSize();
 
 1097   mLegend->endCommand();
 
 1100 void QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled( 
bool checked )
 
 1102   mLegend->beginCommand( tr( 
"Update Legend" ) );
 
 1103   mLegend->setLegendFilterByMapEnabled( checked );
 
 1104   mLegend->adjustBoxSize();
 
 1106   mLegend->endCommand();
 
 1109 void QgsLayoutLegendWidget::mExpressionFilterButton_toggled( 
bool checked )
 
 1117   QModelIndex currentIndex = mItemTreeView->currentIndex();
 
 1118   if ( !currentIndex.isValid() )
 
 1128       mExpressionFilterButton->expressionText(),
 
 1131   mLegend->beginCommand( tr( 
"Update Legend" ) );
 
 1132   mLegend->updateFilterByMap();
 
 1133   mLegend->adjustBoxSize();
 
 1134   mLegend->endCommand();
 
 1137 void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
 
 1144   QModelIndex currentIndex = mItemTreeView->currentIndex();
 
 1145   if ( !currentIndex.isValid() )
 
 1152   QgsLayerTreeLayer *layerNode = qobject_cast<QgsLayerTreeLayer *>( currentNode );
 
 1158   QString currentExpression;
 
 1160     currentExpression = QStringLiteral( 
"@symbol_label" );
 
 1170   QStringList highlighted;
 
 1175     if ( !legendSymbols.empty() )
 
 1181       highlighted << QStringLiteral( 
"symbol_label" ) << QStringLiteral( 
"symbol_id" );
 
 1183       highlighted << QStringLiteral( 
"symbol_count" );
 
 1192   if ( expressiondialog.exec() )
 
 1195   mLegend->beginCommand( tr( 
"Update Legend" ) );
 
 1197   mLegend->adjustBoxSize();
 
 1198   mLegend->endCommand();
 
 1201 void QgsLayoutLegendWidget::mUpdateAllPushButton_clicked()
 
 1206 void QgsLayoutLegendWidget::mAddGroupToolButton_clicked()
 
 1210     mLegend->beginCommand( tr( 
"Add Legend Group" ) );
 
 1211     mLegend->model()->rootGroup()->addGroup( tr( 
"Group" ) );
 
 1212     mLegend->updateLegend();
 
 1214     mLegend->endCommand();
 
 1218 void QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled( 
bool toggled )
 
 1223     mLegend->setLegendFilterOutAtlas( toggled );
 
 1229 void QgsLayoutLegendWidget::updateLegend()
 
 1233     mLegend->beginCommand( tr( 
"Update Legend" ) );
 
 1236     mLegend->setAutoUpdateModel( 
true );
 
 1237     mLegend->setAutoUpdateModel( 
false );
 
 1238     mLegend->updateFilterByMap();
 
 1239     mLegend->endCommand();
 
 1243 void QgsLayoutLegendWidget::setReportTypeString( 
const QString &
string )
 
 1245   mFilterLegendByAtlasCheckBox->setText( tr( 
"Only show items inside current %1 feature" ).arg( 
string ) );
 
 1246   mFilterLegendByAtlasCheckBox->setToolTip( tr( 
"Filter out legend elements that lie outside the current %1 feature." ).arg( 
string ) );
 
 1249 bool QgsLayoutLegendWidget::setNewItem( 
QgsLayoutItem *item )
 
 1259   mLegend = qobject_cast< QgsLayoutItemLegend * >( item );
 
 1260   mItemPropertiesWidget->setItem( mLegend );
 
 1264     mItemTreeView->setModel( mLegend->model() );
 
 1273 void QgsLayoutLegendWidget::blockAllSignals( 
bool b )
 
 1275   mTitleLineEdit->blockSignals( b );
 
 1276   mTitleAlignCombo->blockSignals( b );
 
 1277   mItemTreeView->blockSignals( b );
 
 1278   mCheckBoxAutoUpdate->blockSignals( b );
 
 1279   mMapComboBox->blockSignals( b );
 
 1280   mFilterByMapCheckBox->blockSignals( b );
 
 1281   mColumnCountSpinBox->blockSignals( b );
 
 1282   mSplitLayerCheckBox->blockSignals( b );
 
 1283   mEqualColumnWidthCheckBox->blockSignals( b );
 
 1284   mSymbolWidthSpinBox->blockSignals( b );
 
 1285   mSymbolHeightSpinBox->blockSignals( b );
 
 1286   mMaxSymbolSizeSpinBox->blockSignals( b );
 
 1287   mMinSymbolSizeSpinBox->blockSignals( b );
 
 1288   mGroupSpaceSpinBox->blockSignals( b );
 
 1289   mGroupIndentSpinBox->blockSignals( b );
 
 1290   mSubgroupIndentSpinBox->blockSignals( b );
 
 1291   mSpaceBelowGroupHeadingSpinBox->blockSignals( b );
 
 1292   mGroupSideSpinBox->blockSignals( b );
 
 1293   mSpaceBelowSubgroupHeadingSpinBox->blockSignals( b );
 
 1294   mSubgroupSideSpinBox->blockSignals( b );
 
 1295   mLayerSpaceSpinBox->blockSignals( b );
 
 1296   mSymbolSpaceSpinBox->blockSignals( b );
 
 1297   mSymbolSideSpaceSpinBox->blockSignals( b );
 
 1298   mIconLabelSpaceSpinBox->blockSignals( b );
 
 1299   mBoxSpaceSpinBox->blockSignals( b );
 
 1300   mColumnSpaceSpinBox->blockSignals( b );
 
 1301   mFontColorButton->blockSignals( b );
 
 1302   mRasterStrokeGroupBox->blockSignals( b );
 
 1303   mRasterStrokeColorButton->blockSignals( b );
 
 1304   mRasterStrokeWidthSpinBox->blockSignals( b );
 
 1305   mWmsLegendWidthSpinBox->blockSignals( b );
 
 1306   mWmsLegendHeightSpinBox->blockSignals( b );
 
 1307   mCheckboxResizeContents->blockSignals( b );
 
 1308   mTitleSpaceBottomSpinBox->blockSignals( b );
 
 1309   mFilterLegendByAtlasCheckBox->blockSignals( b );
 
 1310   mTitleFontButton->blockSignals( b );
 
 1311   mGroupFontButton->blockSignals( b );
 
 1312   mLayerFontButton->blockSignals( b );
 
 1313   mItemFontButton->blockSignals( b );
 
 1314   mWrapCharLineEdit->blockSignals( b );
 
 1315   mLineSpacingSpinBox->blockSignals( b );
 
 1318 void QgsLayoutLegendWidget::selectedChanged( 
const QModelIndex ¤t, 
const QModelIndex &previous )
 
 1321   Q_UNUSED( previous )
 
 1323   mLayerExpressionButton->setEnabled( 
false );
 
 1325   if ( mLegend && mLegend->autoUpdateModel() )
 
 1336     mLayerExpressionButton->setEnabled( 
true );
 
 1340   mCountToolButton->setChecked( 
false );
 
 1341   mCountToolButton->setEnabled( 
false );
 
 1344   mExpressionFilterButton->blockSignals( 
true );
 
 1345   mExpressionFilterButton->setChecked( 
false );
 
 1346   mExpressionFilterButton->setEnabled( 
false );
 
 1347   mExpressionFilterButton->blockSignals( 
false );
 
 1358   mCountToolButton->setChecked( currentNode->
customProperty( QStringLiteral( 
"showFeatureCount" ), 0 ).toInt() );
 
 1359   mCountToolButton->setEnabled( 
true );
 
 1360   mLayerExpressionButton->setEnabled( 
true );
 
 1364   mExpressionFilterButton->blockSignals( 
true );
 
 1365   mExpressionFilterButton->setExpressionText( expr );
 
 1366   mExpressionFilterButton->setVectorLayer( vl );
 
 1367   mExpressionFilterButton->setEnabled( 
true );
 
 1368   mExpressionFilterButton->setChecked( exprEnabled );
 
 1369   mExpressionFilterButton->blockSignals( 
false );
 
 1372 void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
 
 1374   QAction *a = qobject_cast<QAction *>( sender() );
 
 1375   if ( !a || !mItemTreeView->currentNode() )
 
 1379   mLegend->updateFilterByMap();
 
 1382 void QgsLayoutLegendWidget::setLegendMapViewData()
 
 1384   if ( mLegend->linkedMap() )
 
 1388     measurementConverter.
setDpi( dpi );
 
 1391     double mapUnitsPerPixelX = mLegend->linkedMap()->extent().width() / mapWidth;
 
 1392     double mapUnitsPerPixelY = mLegend->linkedMap()->extent().height() / mapHeight;
 
 1393     mLegend->model()->setLegendMapViewData( ( mapUnitsPerPixelX > mapUnitsPerPixelY ? mapUnitsPerPixelX : mapUnitsPerPixelY ), dpi, mLegend->linkedMap()->scale() );
 
 1397 void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
 
 1401     mFilterLegendByAtlasCheckBox->setEnabled( atlas->enabled() && mLegend->layout()->reportContext().layer() && mLegend->layout()->reportContext().layer()->geometryType() == 
QgsWkbTypes::PolygonGeometry );
 
 1405 void QgsLayoutLegendWidget::mItemTreeView_doubleClicked( 
const QModelIndex &idx )
 
 1407   if ( !mLegend || !idx.isValid() )
 
 1412   if ( mLegend->autoUpdateModel() )
 
 1418   int originalIndex = -1;
 
 1421     originalIndex = _originalLegendNodeIndex( 
legendNode );
 
 1425   QgsLayoutLegendNodeWidget *widget = 
new QgsLayoutLegendNodeWidget( mLegend, currentNode, 
legendNode, originalIndex );
 
 1426   openPanel( widget );
 
 1434 QgsLayoutLegendMenuProvider::QgsLayoutLegendMenuProvider( 
QgsLayerTreeView *view, QgsLayoutLegendWidget *w )
 
 1439 QMenu *QgsLayoutLegendMenuProvider::createContextMenu()
 
 1441   if ( !mView->currentNode() )
 
 1444   if ( mWidget->legend()->autoUpdateModel() )
 
 1447   QMenu *menu = 
new QMenu();
 
 1451     menu->addAction( QObject::tr( 
"Reset to Defaults" ), mWidget, &QgsLayoutLegendWidget::resetLayerNodeToDefaults );
 
 1452     menu->addSeparator();
 
 1457   QList<QgsLegendStyle::Style> lst;
 
 1461     QAction *action = menu->addAction( 
QgsLegendStyle::styleLabel( style ), mWidget, &QgsLayoutLegendWidget::setCurrentNodeStyleFromAction );
 
 1462     action->setCheckable( 
true );
 
 1463     action->setChecked( currentStyle == style );
 
 1464     action->setData( 
static_cast< int >( style ) );
 
 1479   , mOriginalLegendNodeIndex( originalLegendNodeIndex )
 
 1482   setPanelTitle( tr( 
"Legend Item Properties" ) );
 
 1491   QString currentLabel;
 
 1494     currentLabel = mLegendNode->data( Qt::EditRole ).toString();
 
 1495     mColumnBreakBeforeCheckBox->setChecked( mLegendNode->columnBreak() );
 
 1499     currentLabel = mLayer->name();
 
 1500     QVariant v = mLayer->customProperty( QStringLiteral( 
"legend/title-label" ) );
 
 1502       currentLabel = v.toString();
 
 1503     mColumnBreakBeforeCheckBox->setChecked( mLayer->customProperty( QStringLiteral( 
"legend/column-break" ) ).toInt() );
 
 1505     mColumnSplitBehaviorComboBox->setCurrentIndex( mColumnSplitBehaviorComboBox->findData( mLayer->legendSplitBehavior() ) );
 
 1510     mColumnBreakBeforeCheckBox->setChecked( mNode->customProperty( QStringLiteral( 
"legend/column-break" ) ).toInt() );
 
 1513   mWidthSpinBox->setClearValue( 0, tr( 
"Default" ) );
 
 1514   mHeightSpinBox->setClearValue( 0, tr( 
"Default" ) );
 
 1515   mWidthSpinBox->setVisible( mLegendNode || mLayer );
 
 1516   mHeightSpinBox->setVisible( mLegendNode || mLayer );
 
 1517   mPatchGroup->setVisible( mLegendNode || mLayer );
 
 1518   mPatchWidthLabel->setVisible( mLegendNode || mLayer );
 
 1519   mPatchHeightLabel->setVisible( mLegendNode || mLayer );
 
 1520   mCustomSymbolCheckBox->setVisible( mLegendNode || mLegend->model()->legendNodeEmbeddedInParent( mLayer ) );
 
 1521   mColumnSplitLabel->setVisible( mLayer && !mLegendNode );
 
 1522   mColumnSplitBehaviorComboBox->setVisible( mLayer && !mLegendNode );
 
 1525     mWidthSpinBox->setValue( mLegendNode->userPatchSize().width() );
 
 1526     mHeightSpinBox->setValue( mLegendNode->userPatchSize().height() );
 
 1530     mWidthSpinBox->setValue( mLayer->patchSize().width() );
 
 1531     mHeightSpinBox->setValue( mLayer->patchSize().height() );
 
 1534   mCustomSymbolCheckBox->setChecked( 
false );
 
 1539     patchShape = symbolLegendNode->patchShape();
 
 1541     std::unique_ptr< QgsSymbol > customSymbol( symbolLegendNode->customSymbol() ? symbolLegendNode->customSymbol()->clone() : 
nullptr );
 
 1542     mCustomSymbolCheckBox->setChecked( customSymbol.get() );
 
 1545       mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
 
 1546       mCustomSymbolButton->setSymbolType( customSymbol->type() );
 
 1547       mCustomSymbolButton->setSymbol( customSymbol.release() );
 
 1549     else if ( symbolLegendNode->symbol() )
 
 1551       mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
 
 1552       mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
 
 1553       mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
 
 1556   else if ( !mLegendNode && mLayer )
 
 1558     patchShape = mLayer->patchShape();
 
 1561       if ( 
QgsSymbol *customSymbol = symbolLegendNode->customSymbol() )
 
 1563         mCustomSymbolCheckBox->setChecked( 
true );
 
 1564         mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
 
 1566         mCustomSymbolButton->setSymbol( customSymbol->clone() );
 
 1570         mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
 
 1571         mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
 
 1572         mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
 
 1579     switch ( qobject_cast< QgsVectorLayer * >( mLayer->layer() )->geometryType() )
 
 1594         mPatchShapeLabel->hide();
 
 1595         mPatchShapeButton->hide();
 
 1598     if ( !patchShape.
isNull() )
 
 1599       mPatchShapeButton->setShape( patchShape );
 
 1604     if ( symbolLegendNode->symbol() )
 
 1606       mPatchShapeButton->setSymbolType( symbolLegendNode->symbol()->type() );
 
 1610       mPatchShapeLabel->hide();
 
 1611       mPatchShapeButton->hide();
 
 1616     mPatchShapeLabel->hide();
 
 1617     mPatchShapeButton->hide();
 
 1622     mLabelGroup->hide();
 
 1623     mColorRampLegendWidget->setSettings( colorRampNode->settings() );
 
 1627     mColorRampLegendWidget->hide();
 
 1640         mCustomSymbolCheckBox->hide();
 
 1649   mLabelEdit->setPlainText( currentLabel );
 
 1650   connect( mLabelEdit, &QPlainTextEdit::textChanged, 
this, &QgsLayoutLegendNodeWidget::labelChanged );
 
 1652   connect( mInsertExpressionButton, &QPushButton::clicked, 
this, &QgsLayoutLegendNodeWidget::insertExpression );
 
 1654   connect( mWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendNodeWidget::sizeChanged );
 
 1655   connect( mHeightSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ), 
this, &QgsLayoutLegendNodeWidget::sizeChanged );
 
 1657   connect( mCustomSymbolCheckBox, &QGroupBox::toggled, 
this, &QgsLayoutLegendNodeWidget::customSymbolChanged );
 
 1660   connect( mColumnBreakBeforeCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutLegendNodeWidget::columnBreakToggled );
 
 1662   connect( mColumnSplitBehaviorComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutLegendNodeWidget::columnSplitChanged );
 
 1666   connectChildPanel( mColorRampLegendWidget );
 
 1669 void QgsLayoutLegendNodeWidget::setDockMode( 
bool dockMode )
 
 1671   mColorRampLegendWidget->setDockMode( dockMode );
 
 1675 void QgsLayoutLegendNodeWidget::labelChanged()
 
 1679   const QString label = mLabelEdit->toPlainText();
 
 1684   else if ( mLegendNode )
 
 1687     mLegend->model()->refreshLayerLegend( mLayer );
 
 1691     mLayer->setCustomProperty( QStringLiteral( 
"legend/title-label" ), label );
 
 1695       embeddedNode->setUserLabel( QString() );
 
 1698   mLegend->adjustBoxSize();
 
 1699   mLegend->updateFilterByMap();
 
 1700   mLegend->endCommand();
 
 1703 void QgsLayoutLegendNodeWidget::patchChanged()
 
 1705   mLegend->beginCommand( tr( 
"Edit Legend Item" ) );
 
 1711     mLegend->model()->refreshLayerLegend( mLayer );
 
 1715     mLayer->setPatchShape( shape );
 
 1716     const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer, 
false );
 
 1721     mLegend->model()->refreshLayerLegend( mLayer );
 
 1724   mLegend->adjustBoxSize();
 
 1725   mLegend->updateFilterByMap();
 
 1726   mLegend->endCommand();
 
 1729 void QgsLayoutLegendNodeWidget::insertExpression()
 
 1734   QString selText = mLabelEdit->textCursor().selectedText();
 
 1737   selText = selText.replace( QChar( 0x2029 ), QChar( 
'\n' ) );
 
 1740   if ( selText.startsWith( QLatin1String( 
"[%" ) ) && selText.endsWith( QLatin1String( 
"%]" ) ) )
 
 1741     selText = selText.mid( 2, selText.size() - 4 );
 
 1744   QgsVectorLayer *layer = mLegend->layout() ? mLegend->layout()->reportContext().layer() : 
nullptr;
 
 1748   if ( mLayer && mLayer->layer() )
 
 1754                                    << QStringLiteral( 
"legend_column_count" )
 
 1755                                    << QStringLiteral( 
"legend_split_layers" )
 
 1756                                    << QStringLiteral( 
"legend_wrap_string" )
 
 1757                                    << QStringLiteral( 
"legend_filter_by_map" )
 
 1758                                    << QStringLiteral( 
"legend_filter_out_atlas" ) );
 
 1762   exprDlg.setWindowTitle( tr( 
"Insert Expression" ) );
 
 1763   if ( exprDlg.exec() == QDialog::Accepted )
 
 1765     QString expression = exprDlg.expressionText();
 
 1766     if ( !expression.isEmpty() )
 
 1768       mLegend->beginCommand( tr( 
"Insert expression" ) );
 
 1769       mLabelEdit->insertPlainText( 
"[%" + expression + 
"%]" );
 
 1770       mLegend->endCommand();
 
 1775 void QgsLayoutLegendNodeWidget::sizeChanged( 
double )
 
 1777   mLegend->beginCommand( tr( 
"Edit Legend Item" ) );
 
 1778   const QSizeF size = QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() );
 
 1783     mLegend->model()->refreshLayerLegend( mLayer );
 
 1787     mLayer->setPatchSize( size );
 
 1788     const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer, 
false );
 
 1793     mLegend->model()->refreshLayerLegend( mLayer );
 
 1796   mLegend->adjustBoxSize();
 
 1797   mLegend->updateFilterByMap();
 
 1798   mLegend->endCommand();
 
 1801 void QgsLayoutLegendNodeWidget::customSymbolChanged()
 
 1803   mLegend->beginCommand( tr( 
"Edit Legend Item" ) );
 
 1805   if ( mCustomSymbolCheckBox->isChecked() )
 
 1810       mLegend->model()->refreshLayerLegend( mLayer );
 
 1814       const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer, 
false );
 
 1819       mLegend->model()->refreshLayerLegend( mLayer );
 
 1827       mLegend->model()->refreshLayerLegend( mLayer );
 
 1831       const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer, 
false );
 
 1836       mLegend->model()->refreshLayerLegend( mLayer );
 
 1840   mLegend->adjustBoxSize();
 
 1841   mLegend->updateFilterByMap();
 
 1842   mLegend->endCommand();
 
 1845 void QgsLayoutLegendNodeWidget::colorRampLegendChanged()
 
 1847   mLegend->beginCommand( tr( 
"Edit Legend Item" ) );
 
 1851   mLegend->model()->refreshLayerLegend( mLayer );
 
 1853   mLegend->adjustBoxSize();
 
 1854   mLegend->updateFilterByMap();
 
 1855   mLegend->endCommand();
 
 1858 void QgsLayoutLegendNodeWidget::columnBreakToggled( 
bool checked )
 
 1860   mLegend->beginCommand( tr( 
"Edit Legend Columns" ) );
 
 1865     mLegend->model()->refreshLayerLegend( mLayer );
 
 1869     mLayer->setCustomProperty( QStringLiteral( 
"legend/column-break" ), QString( checked ? 
'1' : 
'0' ) );
 
 1873     mNode->setCustomProperty( QStringLiteral( 
"legend/column-break" ), QString( checked ? 
'1' : 
'0' ) );
 
 1876   mLegend->adjustBoxSize();
 
 1877   mLegend->updateFilterByMap();
 
 1878   mLegend->endCommand();
 
 1881 void QgsLayoutLegendNodeWidget::columnSplitChanged()
 
 1883   mLegend->beginCommand( tr( 
"Edit Legend Columns" ) );
 
 1885   if ( mLayer && !mLegendNode )
 
 1890   mLegend->adjustBoxSize();
 
 1891   mLegend->updateFilterByMap();
 
 1892   mLegend->endCommand();