46#include <QInputDialog>
63 int unfilteredNodeIndex = _unfilteredLegendNodeIndex(
legendNode );
65 return ( unfilteredNodeIndex >= 0 && unfilteredNodeIndex < order.count() ? order[unfilteredNodeIndex] : -1 );
72 , mMapCanvas( mapCanvas )
77 connect( mWrapCharLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged );
78 connect( mTitleLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutLegendWidget::mTitleLineEdit_textChanged );
83 connect( mColumnCountSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged );
84 connect( mSplitLayerCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled );
85 connect( mEqualColumnWidthCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled );
86 connect( mSymbolWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged );
87 connect( mSymbolHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged );
88 connect( mMaxSymbolSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged );
89 connect( mMinSymbolSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged );
90 connect( mWmsLegendWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged );
91 connect( mWmsLegendHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged );
92 connect( mTitleSpaceBottomSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged );
93 connect( mGroupSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged );
94 connect( mGroupIndentSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged );
95 connect( mSubgroupIndentSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged );
96 connect( mSpaceBelowGroupHeadingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged );
97 connect( mGroupSideSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceGroupSideChanged );
98 connect( mLayerSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged );
99 connect( mSpaceBelowSubgroupHeadingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged );
100 connect( mSubgroupSideSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceSubGroupSideChanged );
101 connect( mSymbolSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged );
102 connect( mSymbolSideSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceSymbolSideChanged );
103 connect( mIconLabelSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged );
104 connect( mBoxSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged );
105 connect( mColumnSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged );
106 connect( mCheckBoxAutoUpdate, &QCheckBox::stateChanged,
this, [ = ](
int state ) { mCheckBoxAutoUpdate_stateChanged( state ); } );
107 connect( mCheckboxResizeContents, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mCheckboxResizeContents_toggled );
108 connect( mRasterStrokeGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled );
109 connect( mRasterStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged );
110 connect( mRasterStrokeColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged );
111 connect( mMoveDownToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mMoveDownToolButton_clicked );
112 connect( mMoveUpToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mMoveUpToolButton_clicked );
113 connect( mRemoveToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mRemoveToolButton_clicked );
114 connect( mAddToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mAddToolButton_clicked );
115 connect( mEditPushButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mEditPushButton_clicked );
116 connect( mCountToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mCountToolButton_clicked );
117 connect( mExpressionFilterButton, &QgsLegendFilterButton::toggled,
this, &QgsLayoutLegendWidget::mExpressionFilterButton_toggled );
118 connect( mLayerExpressionButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mLayerExpressionButton_clicked );
119 connect( mFilterByMapCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled );
120 connect( mUpdateAllPushButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mUpdateAllPushButton_clicked );
121 connect( mAddGroupToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mAddGroupToolButton_clicked );
122 connect( mFilterLegendByAtlasCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled );
123 connect( mItemTreeView, &QgsLayerTreeView::doubleClicked,
this, &QgsLayoutLegendWidget::mItemTreeView_doubleClicked );
124 setPanelTitle( tr(
"Legend Properties" ) );
131 mTitleAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
132 mGroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
133 mSubgroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
134 mItemAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
136 mArrangementCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignRight );
138 mArrangementCombo->customizeAlignmentDisplay( Qt::AlignLeft, tr(
"Symbols on Left" ),
QgsApplication::getThemeIcon( QStringLiteral(
"/mIconArrangeSymbolsLeft.svg" ) ) );
139 mArrangementCombo->customizeAlignmentDisplay( Qt::AlignRight, tr(
"Symbols on Right" ),
QgsApplication::getThemeIcon( QStringLiteral(
"/mIconArrangeSymbolsRight.svg" ) ) );
141 mSpaceBelowGroupHeadingSpinBox->setClearValue( 0 );
142 mGroupSideSpinBox->setClearValue( 0 );
143 mSpaceBelowSubgroupHeadingSpinBox->setClearValue( 0 );
144 mSubgroupSideSpinBox->setClearValue( 0 );
145 mSymbolSideSpaceSpinBox->setClearValue( 0 );
166 mRasterStrokeColorButton->setColorDialogTitle( tr(
"Select Stroke Color" ) );
167 mRasterStrokeColorButton->setAllowOpacity(
true );
168 mRasterStrokeColorButton->setContext( QStringLiteral(
"composer " ) );
170 mMapComboBox->setCurrentLayout( legend->
layout() );
176 mainLayout->addWidget( mItemPropertiesWidget );
178 mItemTreeView->setHeaderHidden(
true );
180 mItemTreeView->setModel( legend->
model() );
181 mItemTreeView->setMenuProvider(
new QgsLayoutLegendMenuProvider( mItemTreeView,
this ) );
182 setLegendMapViewData();
188 connect( layoutAtlas(), &
QgsLayoutAtlas::toggled,
this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
192 mTitleFontButton->registerExpressionContextGenerator(
this );
193 mGroupFontButton->registerExpressionContextGenerator(
this );
194 mLayerFontButton->registerExpressionContextGenerator(
this );
195 mItemFontButton->registerExpressionContextGenerator(
this );
197 mTitleFontButton->setLayer( coverageLayer() );
198 mGroupFontButton->setLayer( coverageLayer() );
199 mLayerFontButton->setLayer( coverageLayer() );
200 mItemFontButton->setLayer( coverageLayer() );
201 if ( mLegend->layout() )
214 connect( mItemTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
215 this, &QgsLayoutLegendWidget::selectedChanged );
224 if ( mItemPropertiesWidget )
225 mItemPropertiesWidget->setMasterLayout( masterLayout );
231 mTitleFontButton->setMessageBar( iface->
messageBar() );
232 mGroupFontButton->setMessageBar( iface->
messageBar() );
233 mLayerFontButton->setMessageBar( iface->
messageBar() );
234 mItemFontButton->setMessageBar( iface->
messageBar() );
237void QgsLayoutLegendWidget::setGuiElements()
244 blockAllSignals(
true );
245 mTitleLineEdit->setText( mLegend->title() );
246 whileBlocking( mTitleAlignCombo )->setCurrentAlignment( mLegend->titleAlignment() );
250 whileBlocking( mArrangementCombo )->setCurrentAlignment( mLegend->symbolAlignment() );
251 mFilterByMapCheckBox->setChecked( mLegend->legendFilterByMapEnabled() );
252 mColumnCountSpinBox->setValue( mLegend->columnCount() );
253 mSplitLayerCheckBox->setChecked( mLegend->splitLayer() );
254 mEqualColumnWidthCheckBox->setChecked( mLegend->equalColumnWidth() );
255 mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
256 mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
257 mMaxSymbolSizeSpinBox->setValue( mLegend->maximumSymbolSize() );
258 mMinSymbolSizeSpinBox->setValue( mLegend->minimumSymbolSize() );
259 mWmsLegendWidthSpinBox->setValue( mLegend->wmsLegendWidth() );
260 mWmsLegendHeightSpinBox->setValue( mLegend->wmsLegendHeight() );
274 mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
275 mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
277 mRasterStrokeGroupBox->setChecked( mLegend->drawRasterStroke() );
278 mRasterStrokeWidthSpinBox->setValue( mLegend->rasterStrokeWidth() );
279 mRasterStrokeColorButton->setColor( mLegend->rasterStrokeColor() );
281 mCheckBoxAutoUpdate->setChecked( mLegend->autoUpdateModel() );
283 mCheckboxResizeContents->setChecked( mLegend->resizeToContents() );
284 mFilterLegendByAtlasCheckBox->setChecked( mLegend->legendFilterOutAtlas() );
285 mWrapCharLineEdit->setText( mLegend->wrapString() );
288 mMapComboBox->setItem( map );
294 blockAllSignals(
false );
296 mCheckBoxAutoUpdate_stateChanged( mLegend->autoUpdateModel() ? Qt::Checked : Qt::Unchecked,
false );
297 updateDataDefinedButton( mLegendTitleDDBtn );
298 updateDataDefinedButton( mColumnsDDBtn );
301void QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged(
const QString &text )
305 mLegend->beginCommand( tr(
"Change Legend Wrap" ) );
306 mLegend->setWrapString( text );
307 mLegend->adjustBoxSize();
309 mLegend->endCommand();
313void QgsLayoutLegendWidget::mTitleLineEdit_textChanged(
const QString &text )
318 mLegend->setTitle( text );
319 mLegend->adjustBoxSize();
321 mLegend->endCommand();
325void QgsLayoutLegendWidget::titleAlignmentChanged()
329 Qt::AlignmentFlag alignment =
static_cast< Qt::AlignmentFlag
>(
static_cast< int >( mTitleAlignCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
330 mLegend->beginCommand( tr(
"Change Title Alignment" ) );
331 mLegend->setTitleAlignment( alignment );
333 mLegend->endCommand();
337void QgsLayoutLegendWidget::groupAlignmentChanged()
341 mLegend->beginCommand( tr(
"Change Group Alignment" ) );
344 mLegend->endCommand();
348void QgsLayoutLegendWidget::subgroupAlignmentChanged()
352 mLegend->beginCommand( tr(
"Change Subgroup Alignment" ) );
355 mLegend->endCommand();
359void QgsLayoutLegendWidget::itemAlignmentChanged()
363 mLegend->beginCommand( tr(
"Change Item Alignment" ) );
366 mLegend->endCommand();
370void QgsLayoutLegendWidget::arrangementChanged()
374 Qt::AlignmentFlag alignment =
static_cast< Qt::AlignmentFlag
>(
static_cast< int >( mArrangementCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
375 mLegend->beginCommand( tr(
"Change Legend Arrangement" ) );
376 mLegend->setSymbolAlignment( alignment );
378 mLegend->endCommand();
382void QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged(
int c )
387 mLegend->setColumnCount(
c );
388 mLegend->adjustBoxSize();
390 mLegend->endCommand();
392 mSplitLayerCheckBox->setEnabled(
c > 1 );
393 mEqualColumnWidthCheckBox->setEnabled(
c > 1 );
396void QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled(
bool checked )
400 mLegend->beginCommand( tr(
"Split Legend Layers" ) );
401 mLegend->setSplitLayer( checked );
402 mLegend->adjustBoxSize();
404 mLegend->endCommand();
408void QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled(
bool checked )
412 mLegend->beginCommand( tr(
"Legend Column Width" ) );
413 mLegend->setEqualColumnWidth( checked );
414 mLegend->adjustBoxSize();
416 mLegend->endCommand();
420void QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged(
double d )
425 mLegend->setSymbolWidth( d );
426 mLegend->adjustBoxSize();
428 mLegend->endCommand();
432void QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged(
double d )
437 mLegend->setMaximumSymbolSize( d );
438 mLegend->adjustBoxSize();
440 mLegend->endCommand();
444void QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged(
double d )
449 mLegend->setMinimumSymbolSize( d );
450 mLegend->adjustBoxSize();
452 mLegend->endCommand();
456void QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged(
double d )
461 mLegend->setSymbolHeight( d );
462 mLegend->adjustBoxSize();
464 mLegend->endCommand();
468void QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged(
double d )
473 mLegend->setWmsLegendWidth( d );
474 mLegend->adjustBoxSize();
476 mLegend->endCommand();
480void QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged(
double d )
485 mLegend->setWmsLegendHeight( d );
486 mLegend->adjustBoxSize();
488 mLegend->endCommand();
492void QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged(
double d )
498 mLegend->adjustBoxSize();
500 mLegend->endCommand();
504void QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged(
double d )
510 mLegend->adjustBoxSize();
512 mLegend->endCommand();
516void QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged(
double d )
522 mLegend->adjustBoxSize();
524 mLegend->endCommand();
528void QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged(
double d )
534 mLegend->adjustBoxSize();
536 mLegend->endCommand();
540void QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged(
double space )
546 mLegend->adjustBoxSize();
548 mLegend->endCommand();
552void QgsLayoutLegendWidget::spaceGroupSideChanged(
double space )
558 mLegend->adjustBoxSize();
560 mLegend->endCommand();
564void QgsLayoutLegendWidget::spaceSubGroupSideChanged(
double space )
570 mLegend->adjustBoxSize();
572 mLegend->endCommand();
576void QgsLayoutLegendWidget::spaceSymbolSideChanged(
double space )
582 mLegend->adjustBoxSize();
584 mLegend->endCommand();
588void QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged(
double d )
594 mLegend->adjustBoxSize();
596 mLegend->endCommand();
600void QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged(
double d )
608 mLegend->adjustBoxSize();
610 mLegend->endCommand();
614void QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged(
double d )
620 mLegend->adjustBoxSize();
622 mLegend->endCommand();
626void QgsLayoutLegendWidget::titleFontChanged()
632 mLegend->adjustBoxSize();
634 mLegend->endCommand();
638void QgsLayoutLegendWidget::groupFontChanged()
644 mLegend->adjustBoxSize();
646 mLegend->endCommand();
650void QgsLayoutLegendWidget::layerFontChanged()
656 mLegend->adjustBoxSize();
658 mLegend->endCommand();
662void QgsLayoutLegendWidget::itemFontChanged()
668 mLegend->adjustBoxSize();
670 mLegend->endCommand();
674void QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged(
double space )
680 mLegend->adjustBoxSize();
682 mLegend->endCommand();
686void QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged(
double d )
691 mLegend->setBoxSpace( d );
692 mLegend->adjustBoxSize();
694 mLegend->endCommand();
698void QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged(
double d )
703 mLegend->setColumnSpace( d );
704 mLegend->adjustBoxSize();
706 mLegend->endCommand();
710static void _moveLegendNode(
QgsLayerTreeLayer *nodeLayer,
int legendNodeIndex,
int offset )
714 if ( legendNodeIndex < 0 || legendNodeIndex >= order.count() )
716 if ( legendNodeIndex + offset < 0 || legendNodeIndex + offset >= order.count() )
719 int id = order.takeAt( legendNodeIndex );
720 order.insert( legendNodeIndex + offset,
id );
726void QgsLayoutLegendWidget::mMoveDownToolButton_clicked()
733 const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
734 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
735 const QModelIndex parentIndex = sourceIndex.parent();
736 if ( !sourceIndex.isValid() || sourceIndex.row() == mItemTreeView->layerTreeModel()->rowCount( parentIndex ) - 1 )
744 mLegend->beginCommand( tr(
"Moved Legend Item Down" ) );
758 mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() + 1, 0, parentIndex ) ) );
761 mLegend->endCommand();
764void QgsLayoutLegendWidget::mMoveUpToolButton_clicked()
771 const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
772 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
773 const QModelIndex parentIndex = sourceIndex.parent();
774 if ( !sourceIndex.isValid() || sourceIndex.row() == 0 )
782 mLegend->beginCommand( tr(
"Move Legend Item Up" ) );
796 mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() - 1, 0, parentIndex ) ) );
799 mLegend->endCommand();
802void QgsLayoutLegendWidget::mCheckBoxAutoUpdate_stateChanged(
int state,
bool userTriggered )
806 mLegend->beginCommand( tr(
"Change Auto Update" ) );
808 mLegend->setAutoUpdateModel( state == Qt::Checked );
810 mLegend->endCommand();
814 QList<QWidget *> widgets;
815 widgets << mMoveDownToolButton << mMoveUpToolButton << mRemoveToolButton << mAddToolButton
816 << mEditPushButton << mCountToolButton << mUpdateAllPushButton << mAddGroupToolButton
817 << mExpressionFilterButton;
818 for ( QWidget *w : std::as_const( widgets ) )
819 w->setEnabled( state != Qt::Checked );
821 if ( state == Qt::Unchecked )
824 selectedChanged( QModelIndex(), QModelIndex() );
828void QgsLayoutLegendWidget::composerMapChanged(
QgsLayoutItem *item )
844 mLegend->beginCommand( tr(
"Change Legend Map" ) );
845 mLegend->setLinkedMap( map );
847 mLegend->endCommand();
849 setLegendMapViewData();
853void QgsLayoutLegendWidget::mCheckboxResizeContents_toggled(
bool checked )
860 mLegend->beginCommand( tr(
"Resize Legend to Contents" ) );
861 mLegend->setResizeToContents( checked );
863 mLegend->adjustBoxSize();
865 mLegend->endCommand();
868void QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled(
bool state )
875 mLegend->beginCommand( tr(
"Change Legend Borders" ) );
876 mLegend->setDrawRasterStroke( state );
877 mLegend->adjustBoxSize();
879 mLegend->endCommand();
882void QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged(
double d )
890 mLegend->setRasterStrokeWidth( d );
891 mLegend->adjustBoxSize();
893 mLegend->endCommand();
896void QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged(
const QColor &newColor )
904 mLegend->setRasterStrokeColor( newColor );
906 mLegend->endCommand();
909void QgsLayoutLegendWidget::mAddToolButton_clicked()
916 QList< QgsMapLayer * > visibleLayers;
917 if ( mLegend->linkedMap() )
919 visibleLayers = mLegend->linkedMap()->layersToRender();
921 if ( visibleLayers.isEmpty() )
924 visibleLayers = mMapCanvas->layers(
true );
928 addDialog.setVisibleLayers( visibleLayers );
929 if ( addDialog.exec() == QDialog::Accepted )
931 const QList<QgsMapLayer *> layers = addDialog.selectedLayers();
932 if ( !layers.empty() )
934 mLegend->beginCommand( tr(
"Add Legend Item(s)" ) );
937 mLegend->model()->rootGroup()->addLayer( layer );
939 mLegend->updateLegend();
941 mLegend->endCommand();
946void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
953 QItemSelectionModel *selectionModel = mItemTreeView->selectionModel();
954 if ( !selectionModel )
959 mLegend->beginCommand( tr(
"Remove Legend Item" ) );
961 QList<QPersistentModelIndex> proxyIndexes;
962 const QModelIndexList viewSelection = selectionModel->selectedIndexes();
963 for (
const QModelIndex &index : viewSelection )
964 proxyIndexes << index;
967 QHash<QgsLayerTreeLayer *, QList<int> > nodesWithRemoval;
968 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
973 nodesWithRemoval[nodeLayer].append( _unfilteredLegendNodeIndex(
legendNode ) );
976 for (
auto it = nodesWithRemoval.constBegin(); it != nodesWithRemoval.constEnd(); ++it )
978 QList<int> toDelete = it.value();
979 std::sort( toDelete.begin(), toDelete.end(), std::greater<int>() );
982 for (
int i : std::as_const( toDelete ) )
984 if ( i >= 0 && i < order.count() )
989 mItemTreeView->layerTreeModel()->refreshLayerLegend( it.key() );
993 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
995 if ( proxyIndex.isValid() && mItemTreeView->index2node( proxyIndex ) )
997 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( proxyIndex );
998 mLegend->model()->removeRow( sourceIndex.row(), sourceIndex.parent() );
1002 mLegend->updateLegend();
1004 mLegend->endCommand();
1007void QgsLayoutLegendWidget::mEditPushButton_clicked()
1014 QModelIndex idx = mItemTreeView->selectionModel()->currentIndex();
1015 mItemTreeView_doubleClicked( idx );
1018void QgsLayoutLegendWidget::resetLayerNodeToDefaults()
1026 QModelIndex currentIndex = mItemTreeView->currentIndex();
1027 if ( !currentIndex.isValid() )
1046 mLegend->beginCommand( tr(
"Update Legend" ) );
1049 for (
const QString &key : constCustomProperties )
1051 if ( key.startsWith( QLatin1String(
"legend/" ) ) )
1058 mItemTreeView->layerTreeModel()->refreshLayerLegend( nodeLayer );
1060 mLegend->updateLegend();
1062 mLegend->endCommand();
1065void QgsLayoutLegendWidget::mCountToolButton_clicked(
bool checked )
1072 const QList< QModelIndex > selectedIndexes = mItemTreeView->selectionModel()->selectedIndexes();
1073 if ( selectedIndexes.empty() )
1076 mLegend->beginCommand( tr(
"Update Legend" ) );
1077 for (
const QModelIndex &index : selectedIndexes )
1083 currentNode->
setCustomProperty( QStringLiteral(
"showFeatureCount" ), checked ? 1 : 0 );
1085 mLegend->updateFilterByMap();
1086 mLegend->adjustBoxSize();
1087 mLegend->endCommand();
1090void QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled(
bool checked )
1092 mLegend->beginCommand( tr(
"Update Legend" ) );
1093 mLegend->setLegendFilterByMapEnabled( checked );
1094 mLegend->adjustBoxSize();
1096 mLegend->endCommand();
1099void QgsLayoutLegendWidget::mExpressionFilterButton_toggled(
bool checked )
1107 QModelIndex currentIndex = mItemTreeView->currentIndex();
1108 if ( !currentIndex.isValid() )
1118 mExpressionFilterButton->expressionText(),
1121 mLegend->beginCommand( tr(
"Update Legend" ) );
1122 mLegend->updateFilterByMap();
1123 mLegend->adjustBoxSize();
1124 mLegend->endCommand();
1127void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
1134 QModelIndex currentIndex = mItemTreeView->currentIndex();
1135 if ( !currentIndex.isValid() )
1142 QgsLayerTreeLayer *layerNode = qobject_cast<QgsLayerTreeLayer *>( currentNode );
1148 QString currentExpression;
1150 currentExpression = QStringLiteral(
"@symbol_label" );
1160 QStringList highlighted;
1165 if ( !legendSymbols.empty() )
1171 highlighted << QStringLiteral(
"symbol_label" ) << QStringLiteral(
"symbol_id" );
1173 highlighted << QStringLiteral(
"symbol_count" );
1182 if ( expressiondialog.exec() )
1185 mLegend->beginCommand( tr(
"Update Legend" ) );
1187 mLegend->adjustBoxSize();
1188 mLegend->endCommand();
1191void QgsLayoutLegendWidget::mUpdateAllPushButton_clicked()
1196void QgsLayoutLegendWidget::mAddGroupToolButton_clicked()
1200 mLegend->beginCommand( tr(
"Add Legend Group" ) );
1201 mLegend->model()->rootGroup()->addGroup( tr(
"Group" ) );
1202 mLegend->updateLegend();
1204 mLegend->endCommand();
1208void QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled(
bool toggled )
1213 mLegend->setLegendFilterOutAtlas( toggled );
1219void QgsLayoutLegendWidget::updateLegend()
1223 mLegend->beginCommand( tr(
"Update Legend" ) );
1226 mLegend->setAutoUpdateModel(
true );
1227 mLegend->setAutoUpdateModel(
false );
1229 mLegend->endCommand();
1233void QgsLayoutLegendWidget::setReportTypeString(
const QString &
string )
1235 mFilterLegendByAtlasCheckBox->setText( tr(
"Only show items inside current %1 feature" ).arg(
string ) );
1236 mFilterLegendByAtlasCheckBox->setToolTip( tr(
"Filter out legend elements that lie outside the current %1 feature." ).arg(
string ) );
1245bool QgsLayoutLegendWidget::setNewItem(
QgsLayoutItem *item )
1255 mLegend = qobject_cast< QgsLayoutItemLegend * >( item );
1256 mItemPropertiesWidget->setItem( mLegend );
1260 mItemTreeView->setModel( mLegend->model() );
1269void QgsLayoutLegendWidget::blockAllSignals(
bool b )
1271 mTitleLineEdit->blockSignals( b );
1272 mTitleAlignCombo->blockSignals( b );
1273 mItemTreeView->blockSignals( b );
1274 mCheckBoxAutoUpdate->blockSignals( b );
1275 mMapComboBox->blockSignals( b );
1276 mFilterByMapCheckBox->blockSignals( b );
1277 mColumnCountSpinBox->blockSignals( b );
1278 mSplitLayerCheckBox->blockSignals( b );
1279 mEqualColumnWidthCheckBox->blockSignals( b );
1280 mSymbolWidthSpinBox->blockSignals( b );
1281 mSymbolHeightSpinBox->blockSignals( b );
1282 mMaxSymbolSizeSpinBox->blockSignals( b );
1283 mMinSymbolSizeSpinBox->blockSignals( b );
1284 mGroupSpaceSpinBox->blockSignals( b );
1285 mGroupIndentSpinBox->blockSignals( b );
1286 mSubgroupIndentSpinBox->blockSignals( b );
1287 mSpaceBelowGroupHeadingSpinBox->blockSignals( b );
1288 mGroupSideSpinBox->blockSignals( b );
1289 mSpaceBelowSubgroupHeadingSpinBox->blockSignals( b );
1290 mSubgroupSideSpinBox->blockSignals( b );
1291 mLayerSpaceSpinBox->blockSignals( b );
1292 mSymbolSpaceSpinBox->blockSignals( b );
1293 mSymbolSideSpaceSpinBox->blockSignals( b );
1294 mIconLabelSpaceSpinBox->blockSignals( b );
1295 mBoxSpaceSpinBox->blockSignals( b );
1296 mColumnSpaceSpinBox->blockSignals( b );
1297 mRasterStrokeGroupBox->blockSignals( b );
1298 mRasterStrokeColorButton->blockSignals( b );
1299 mRasterStrokeWidthSpinBox->blockSignals( b );
1300 mWmsLegendWidthSpinBox->blockSignals( b );
1301 mWmsLegendHeightSpinBox->blockSignals( b );
1302 mCheckboxResizeContents->blockSignals( b );
1303 mTitleSpaceBottomSpinBox->blockSignals( b );
1304 mFilterLegendByAtlasCheckBox->blockSignals( b );
1305 mTitleFontButton->blockSignals( b );
1306 mGroupFontButton->blockSignals( b );
1307 mLayerFontButton->blockSignals( b );
1308 mItemFontButton->blockSignals( b );
1309 mWrapCharLineEdit->blockSignals( b );
1312void QgsLayoutLegendWidget::selectedChanged(
const QModelIndex ¤t,
const QModelIndex &previous )
1315 Q_UNUSED( previous )
1317 mLayerExpressionButton->setEnabled(
false );
1319 if ( mLegend && mLegend->autoUpdateModel() )
1330 mLayerExpressionButton->setEnabled(
true );
1334 mCountToolButton->setChecked(
false );
1335 mCountToolButton->setEnabled(
false );
1338 mExpressionFilterButton->blockSignals(
true );
1339 mExpressionFilterButton->setChecked(
false );
1340 mExpressionFilterButton->setEnabled(
false );
1341 mExpressionFilterButton->blockSignals(
false );
1352 mCountToolButton->setChecked( currentNode->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() );
1353 mCountToolButton->setEnabled(
true );
1354 mLayerExpressionButton->setEnabled(
true );
1358 mExpressionFilterButton->blockSignals(
true );
1359 mExpressionFilterButton->setExpressionText( expr );
1360 mExpressionFilterButton->setVectorLayer( vl );
1361 mExpressionFilterButton->setEnabled(
true );
1362 mExpressionFilterButton->setChecked( exprEnabled );
1363 mExpressionFilterButton->blockSignals(
false );
1366void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
1368 QAction *a = qobject_cast<QAction *>( sender() );
1369 if ( !a || !mItemTreeView->currentNode() )
1376void QgsLayoutLegendWidget::setLegendMapViewData()
1378 if ( mLegend->linkedMap() )
1382 measurementConverter.
setDpi( dpi );
1383 double mapWidth = measurementConverter.
convert( mLegend->linkedMap()->sizeWithUnits(), Qgis::LayoutUnit::Pixels ).width();
1384 double mapHeight = measurementConverter.
convert( mLegend->linkedMap()->sizeWithUnits(), Qgis::LayoutUnit::Pixels ).height();
1385 double mapUnitsPerPixelX = mLegend->linkedMap()->extent().width() / mapWidth;
1386 double mapUnitsPerPixelY = mLegend->linkedMap()->extent().height() / mapHeight;
1387 mLegend->model()->setLegendMapViewData( ( mapUnitsPerPixelX > mapUnitsPerPixelY ? mapUnitsPerPixelX : mapUnitsPerPixelY ), dpi, mLegend->linkedMap()->scale() );
1391void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
1395 mFilterLegendByAtlasCheckBox->setEnabled( atlas->enabled() && mLegend->layout()->reportContext().layer() && mLegend->layout()->reportContext().layer()->geometryType() == Qgis::GeometryType::Polygon );
1399void QgsLayoutLegendWidget::mItemTreeView_doubleClicked(
const QModelIndex &idx )
1401 if ( !mLegend || !idx.isValid() )
1406 if ( mLegend->autoUpdateModel() )
1412 int originalIndex = -1;
1415 originalIndex = _originalLegendNodeIndex(
legendNode );
1419 QgsLayoutLegendNodeWidget *widget =
new QgsLayoutLegendNodeWidget( mLegend, currentNode,
legendNode, originalIndex );
1420 openPanel( widget );
1428QgsLayoutLegendMenuProvider::QgsLayoutLegendMenuProvider(
QgsLayerTreeView *view, QgsLayoutLegendWidget *w )
1433QMenu *QgsLayoutLegendMenuProvider::createContextMenu()
1435 if ( !mView->currentNode() )
1438 if ( mWidget->legend()->autoUpdateModel() )
1441 QMenu *menu =
new QMenu();
1445 menu->addAction( QObject::tr(
"Reset to Defaults" ), mWidget, &QgsLayoutLegendWidget::resetLayerNodeToDefaults );
1446 menu->addSeparator();
1451 QList<QgsLegendStyle::Style> lst;
1455 QAction *action = menu->addAction(
QgsLegendStyle::styleLabel( style ), mWidget, &QgsLayoutLegendWidget::setCurrentNodeStyleFromAction );
1456 action->setCheckable(
true );
1457 action->setChecked( currentStyle == style );
1458 action->setData(
static_cast< int >( style ) );
1473 , mOriginalLegendNodeIndex( originalLegendNodeIndex )
1476 setPanelTitle( tr(
"Legend Item Properties" ) );
1485 QString currentLabel;
1488 currentLabel = mLegendNode->data( Qt::EditRole ).toString();
1489 mColumnBreakBeforeCheckBox->setChecked( mLegendNode->columnBreak() );
1493 currentLabel = mLayer->name();
1494 QVariant v = mLayer->customProperty( QStringLiteral(
"legend/title-label" ) );
1496 currentLabel = v.toString();
1497 mColumnBreakBeforeCheckBox->setChecked( mLayer->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1499 mColumnSplitBehaviorComboBox->setCurrentIndex( mColumnSplitBehaviorComboBox->findData( mLayer->legendSplitBehavior() ) );
1504 mColumnBreakBeforeCheckBox->setChecked( mNode->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1507 mWidthSpinBox->setClearValue( 0, tr(
"Default" ) );
1508 mHeightSpinBox->setClearValue( 0, tr(
"Default" ) );
1509 mWidthSpinBox->setVisible( mLegendNode || mLayer );
1510 mHeightSpinBox->setVisible( mLegendNode || mLayer );
1511 mPatchGroup->setVisible( mLegendNode || mLayer );
1512 mPatchWidthLabel->setVisible( mLegendNode || mLayer );
1513 mPatchHeightLabel->setVisible( mLegendNode || mLayer );
1514 mCustomSymbolCheckBox->setVisible( mLegendNode || mLegend->model()->legendNodeEmbeddedInParent( mLayer ) );
1515 mColumnSplitLabel->setVisible( mLayer && !mLegendNode );
1516 mColumnSplitBehaviorComboBox->setVisible( mLayer && !mLegendNode );
1519 mWidthSpinBox->setValue( mLegendNode->userPatchSize().width() );
1520 mHeightSpinBox->setValue( mLegendNode->userPatchSize().height() );
1524 mWidthSpinBox->setValue( mLayer->patchSize().width() );
1525 mHeightSpinBox->setValue( mLayer->patchSize().height() );
1528 mCustomSymbolCheckBox->setChecked(
false );
1533 patchShape = symbolLegendNode->patchShape();
1535 std::unique_ptr< QgsSymbol > customSymbol( symbolLegendNode->customSymbol() ? symbolLegendNode->customSymbol()->clone() :
nullptr );
1536 mCustomSymbolCheckBox->setChecked( customSymbol.get() );
1539 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1540 mCustomSymbolButton->setSymbolType( customSymbol->type() );
1541 mCustomSymbolButton->setSymbol( customSymbol.release() );
1543 else if ( symbolLegendNode->symbol() )
1545 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1546 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1547 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1550 else if ( !mLegendNode && mLayer )
1552 patchShape = mLayer->patchShape();
1555 if (
QgsSymbol *customSymbol = symbolLegendNode->customSymbol() )
1557 mCustomSymbolCheckBox->setChecked(
true );
1558 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1560 mCustomSymbolButton->setSymbol( customSymbol->clone() );
1564 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1565 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1566 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1571 if ( mLayer && mLayer->layer() && mLayer->layer()->type() == Qgis::LayerType::Vector )
1573 switch ( qobject_cast< QgsVectorLayer * >( mLayer->layer() )->geometryType() )
1575 case Qgis::GeometryType::Polygon:
1579 case Qgis::GeometryType::Line:
1583 case Qgis::GeometryType::Point:
1588 mPatchShapeLabel->hide();
1589 mPatchShapeButton->hide();
1592 if ( !patchShape.
isNull() )
1593 mPatchShapeButton->setShape( patchShape );
1598 if ( symbolLegendNode->symbol() )
1600 mPatchShapeButton->setSymbolType( symbolLegendNode->symbol()->type() );
1604 mPatchShapeLabel->hide();
1605 mPatchShapeButton->hide();
1610 mPatchShapeLabel->hide();
1611 mPatchShapeButton->hide();
1616 mLabelGroup->hide();
1617 mColorRampLegendWidget->setSettings( colorRampNode->settings() );
1621 mColorRampLegendWidget->hide();
1634 mCustomSymbolCheckBox->hide();
1643 mLabelEdit->setPlainText( currentLabel );
1644 connect( mLabelEdit, &QPlainTextEdit::textChanged,
this, &QgsLayoutLegendNodeWidget::labelChanged );
1646 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutLegendNodeWidget::insertExpression );
1648 connect( mWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1649 connect( mHeightSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1651 connect( mCustomSymbolCheckBox, &QGroupBox::toggled,
this, &QgsLayoutLegendNodeWidget::customSymbolChanged );
1654 connect( mColumnBreakBeforeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendNodeWidget::columnBreakToggled );
1656 connect( mColumnSplitBehaviorComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutLegendNodeWidget::columnSplitChanged );
1660 connectChildPanel( mColorRampLegendWidget );
1663void QgsLayoutLegendNodeWidget::setDockMode(
bool dockMode )
1665 mColorRampLegendWidget->setDockMode( dockMode );
1669void QgsLayoutLegendNodeWidget::labelChanged()
1673 const QString label = mLabelEdit->toPlainText();
1678 else if ( mLegendNode )
1681 mLegend->model()->refreshLayerLegend( mLayer );
1685 mLayer->setCustomProperty( QStringLiteral(
"legend/title-label" ), label );
1689 embeddedNode->setUserLabel( QString() );
1692 mLegend->adjustBoxSize();
1694 mLegend->endCommand();
1697void QgsLayoutLegendNodeWidget::patchChanged()
1699 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1705 mLegend->model()->refreshLayerLegend( mLayer );
1709 mLayer->setPatchShape( shape );
1710 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1715 mLegend->model()->refreshLayerLegend( mLayer );
1718 mLegend->adjustBoxSize();
1720 mLegend->endCommand();
1723void QgsLayoutLegendNodeWidget::insertExpression()
1728 QString selText = mLabelEdit->textCursor().selectedText();
1731 selText = selText.replace( QChar( 0x2029 ), QChar(
'\n' ) );
1734 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
1735 selText = selText.mid( 2, selText.size() - 4 );
1738 QgsVectorLayer *layer = mLegend->layout() ? mLegend->layout()->reportContext().layer() :
nullptr;
1742 if ( mLayer && mLayer->layer() )
1748 << QStringLiteral(
"legend_column_count" )
1749 << QStringLiteral(
"legend_split_layers" )
1750 << QStringLiteral(
"legend_wrap_string" )
1751 << QStringLiteral(
"legend_filter_by_map" )
1752 << QStringLiteral(
"legend_filter_out_atlas" ) );
1756 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1757 if ( exprDlg.exec() == QDialog::Accepted )
1759 QString expression = exprDlg.expressionText();
1760 if ( !expression.isEmpty() )
1762 mLegend->beginCommand( tr(
"Insert expression" ) );
1763 mLabelEdit->insertPlainText(
"[%" + expression +
"%]" );
1764 mLegend->endCommand();
1769void QgsLayoutLegendNodeWidget::sizeChanged(
double )
1771 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1772 const QSizeF size = QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() );
1777 mLegend->model()->refreshLayerLegend( mLayer );
1781 mLayer->setPatchSize( size );
1782 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1787 mLegend->model()->refreshLayerLegend( mLayer );
1790 mLegend->adjustBoxSize();
1792 mLegend->endCommand();
1795void QgsLayoutLegendNodeWidget::customSymbolChanged()
1797 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1799 if ( mCustomSymbolCheckBox->isChecked() )
1804 mLegend->model()->refreshLayerLegend( mLayer );
1808 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1813 mLegend->model()->refreshLayerLegend( mLayer );
1821 mLegend->model()->refreshLayerLegend( mLayer );
1825 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1830 mLegend->model()->refreshLayerLegend( mLayer );
1834 mLegend->adjustBoxSize();
1836 mLegend->endCommand();
1839void QgsLayoutLegendNodeWidget::colorRampLegendChanged()
1841 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1845 mLegend->model()->refreshLayerLegend( mLayer );
1847 mLegend->adjustBoxSize();
1849 mLegend->endCommand();
1852void QgsLayoutLegendNodeWidget::columnBreakToggled(
bool checked )
1854 mLegend->beginCommand( tr(
"Edit Legend Columns" ) );
1859 mLegend->model()->refreshLayerLegend( mLayer );
1863 mLayer->setCustomProperty( QStringLiteral(
"legend/column-break" ), QString( checked ?
'1' :
'0' ) );
1867 mNode->setCustomProperty( QStringLiteral(
"legend/column-break" ), QString( checked ?
'1' :
'0' ) );
1870 mLegend->adjustBoxSize();
1872 mLegend->endCommand();
1875void QgsLayoutLegendNodeWidget::columnSplitChanged()
1877 mLegend->beginCommand( tr(
"Edit Legend Columns" ) );
1879 if ( mLayer && !mLegendNode )
1884 mLegend->adjustBoxSize();
1886 mLegend->endCommand();
void changed()
Emitted when the alignment is changed.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QString iconPath(const QString &iconFile)
Returns path to the desired icon file.
Settings for a color ramp legend node.
A legend node which renders a color ramp.
A generic dialog for building expression strings.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
Layer tree group node serves as a container for layers and further groups.
void insertChildNode(int index, QgsLayerTreeNode *node)
Insert existing node at specified position.
void setName(const QString &n) override
Sets the group's name.
void removeChildNode(QgsLayerTreeNode *node)
Remove a child node from this group.
QString name() const override
Returns the group's name.
Layer tree node points to a map layer.
void setPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
LegendNodesSplitBehavior
Legend node column split behavior.
@ AllowSplittingLegendNodesOverMultipleColumns
Allow splitting node's legend nodes across multiple columns.
@ PreventSplittingLegendNodesOverMultipleColumns
Prevent splitting node's legend nodes across multiple columns.
@ UseDefaultLegendSetting
Inherit default legend column splitting setting.
void setLabelExpression(const QString &expression)
set the expression to evaluate
void setPatchShape(const QgsLegendPatchShape &shape)
Sets the symbol patch shape to use when rendering the legend node symbol.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
NodeTypes
Types of legend nodes.
@ SimpleLegend
Simple label with icon legend node type.
@ RasterSymbolLegend
Raster symbol legend node type.
@ ImageLegend
Raster image legend node type.
@ DataDefinedSizeLegend
Marker symbol legend node type.
@ WmsLegend
WMS legend node type.
@ EmbeddedWidget
Embedded widget placeholder node type.
@ ColorRampLegend
Color ramp legend (since QGIS 3.18)
@ SymbolLegend
Vector symbol legend node type.
@ NodeTypeRole
Type of node. Added in 3.16.
QgsLayerTreeModel * model() const
Returns pointer to model owning this legend node.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
QgsLayerTreeModelLegendNode * legendNodeEmbeddedInParent(QgsLayerTreeLayer *nodeLayer) const
Returns legend node that may be embedded in parent (i.e.
QList< QgsLayerTreeModelLegendNode * > layerOriginalLegendNodes(QgsLayerTreeLayer *nodeLayer)
Returns original (unfiltered) list of legend nodes attached to a particular layer node.
This class is a base class for nodes in a layer tree.
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file.
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer. Properties are stored in a map and saved in project file.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
QStringList customProperties() const
Returns list of keys stored in custom properties.
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
static void setLegendFilterByExpression(QgsLayerTreeLayer &layer, const QString &expr, bool enabled=true)
Sets the expression filter of a legend layer.
static QString legendFilterByExpression(const QgsLayerTreeLayer &layer, bool *enabled=nullptr)
Returns the expression filter of a legend layer.
The QgsLayerTreeView class extends QTreeView and provides some additional functionality when working ...
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Class used to render QgsLayout as an atlas, by iterating over the features from an associated vector ...
void toggled(bool)
Emitted when atlas is enabled or disabled.
A common interface for layout designer dialogs and widgets.
virtual QgsMessageBar * messageBar()=0
Returns the designer's message bar.
void itemChanged(QgsLayoutItem *item)
Emitted whenever the currently selected item changes.
A layout item subclass for map legends.
QgsLegendModel * model()
Returns the legend model.
Layout graphical items for displaying a map.
@ LayoutLegend
Legend item.
Base class for graphical items within a QgsLayout.
@ UndoLegendMinSymbolSize
Legend minimum symbol size.
@ UndoLegendTitleSpaceBottom
Legend title space.
@ UndoLegendIconSymbolSpace
Legend icon symbol space.
@ UndoLegendLayerFont
Legend layer font.
@ UndoLegendBoxSpace
Legend box space.
@ UndoLegendRasterStrokeColor
Legend raster stroke color.
@ UndoLegendTitleFont
Legend title font.
@ UndoLegendItemFont
Legend item font.
@ UndoLegendWmsLegendWidth
Legend WMS width.
@ UndoLegendLayerSpace
Legend layer spacing.
@ UndoLegendColumnSpace
Legend column space.
@ UndoLegendMaxSymbolSize
Legend maximum symbol size.
@ UndoLegendSymbolSpace
Legend symbol spacing.
@ UndoLegendSymbolWidth
Legend symbol width.
@ UndoLegendColumnCount
Legend column count.
@ UndoLegendSymbolHeight
Legend symbol height.
@ UndoLegendGroupSpace
Legend group spacing.
@ UndoLegendSubgroupIndent
Legend subgroup indent.
@ UndoLegendRasterStrokeWidth
Legend raster stroke width.
@ UndoLegendGroupIndent
Legend group indent.
@ UndoLegendText
Legend text.
@ UndoLegendWmsLegendHeight
Legend WMS height.
@ UndoLegendGroupFont
Legend group font.
int type() const override
Returns a unique graphics item type identifier.
A dialog to add new layers to the legend.
This class provides a method of converting QgsLayoutMeasurements from one unit to another.
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, Qgis::LayoutUnit targetUnits) const
Converts a measurement from one unit to another.
void setDpi(const double dpi)
Sets the dots per inch (dpi) for the measurement converter.
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
@ LegendTitle
Legend title.
@ LegendColumnCount
Legend column count.
void layerChanged(QgsVectorLayer *layer)
Emitted when the context's layer is changed.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutReportContext & reportContext()
Returns a reference to the layout's report context, which stores information relating to the current ...
Represents a patch shape for use in map legends.
void setSymbolType(Qgis::SymbolType type)
Sets the symbol type associated with this patch.
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
static void setNodeLegendStyle(QgsLayerTreeNode *node, QgsLegendStyle::Style style)
Sets the style of a node.
static QgsLegendStyle::Style nodeLegendStyle(QgsLayerTreeNode *node, QgsLayerTreeModel *model)
Returns the style for the given node, within the specified model.
static QString styleLabel(Style s)
Returns a translated string representing a style component, for use in UI.
Style
Component of legends which can be styled.
@ Group
Legend group title.
@ Symbol
Symbol icon (excluding label)
@ Subgroup
Legend subgroup title.
@ Hidden
Special style, item is hidden including margins around.
@ SymbolLabel
Symbol label (excluding icon)
Map canvas is a class for displaying all GIS data types on a canvas.
static void setLegendNodeOrder(QgsLayerTreeLayer *nodeLayer, const QList< int > &order)
static void setLegendNodeColorRampSettings(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsColorRampLegendNodeSettings *settings)
Sets a custom legend color ramp settings for the legend node belonging to nodeLayer at the specified ...
static void setLegendNodeCustomSymbol(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsSymbol *symbol)
Sets a custom legend symbol for the legend node belonging to nodeLayer at the specified originalIndex...
static void setLegendNodeUserLabel(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QString &newLabel)
static void setLegendNodeSymbolSize(QgsLayerTreeLayer *nodeLayer, int originalIndex, QSizeF size)
Sets the legend symbol size for the legend node belonging to nodeLayer at the specified originalIndex...
static void setLegendNodeColumnBreak(QgsLayerTreeLayer *nodeLayer, int originalIndex, bool columnBreakBeforeNode)
Sets whether a forced column break should occur before the node.
static void setLegendNodePatchShape(QgsLayerTreeLayer *nodeLayer, int originalIndex, const QgsLegendPatchShape &shape)
Sets the legend patch shape for the legend node belonging to nodeLayer at the specified originalIndex...
static QList< int > legendNodeOrder(QgsLayerTreeLayer *nodeLayer)
Base class for all map layer types.
Interface for master layout type objects, such as print layouts and reports.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
Abstract base class for all rendered symbols.
static bool isNull(const QVariant &variant)
Returns true if the specified variant should be considered a NULL value.
Represents a vector layer which manages a vector based data sets.
QgsExpressionContextScope * createExpressionContextScope() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Q_GUI_EXPORT int qt_defaultDpiX()
Single variable definition for use within a QgsExpressionContextScope.