47#include <QInputDialog>
64 int unfilteredNodeIndex = _unfilteredLegendNodeIndex(
legendNode );
66 return ( unfilteredNodeIndex >= 0 && unfilteredNodeIndex < order.count() ? order[unfilteredNodeIndex] : -1 );
73 , mMapCanvas( mapCanvas )
78 connect( mWrapCharLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged );
79 connect( mTitleLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutLegendWidget::mTitleLineEdit_textChanged );
84 connect( mColumnCountSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged );
85 connect( mSplitLayerCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled );
86 connect( mEqualColumnWidthCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled );
87 connect( mSymbolWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged );
88 connect( mSymbolHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged );
89 connect( mMaxSymbolSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged );
90 connect( mMinSymbolSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged );
91 connect( mWmsLegendWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged );
92 connect( mWmsLegendHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged );
93 connect( mTitleSpaceBottomSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged );
94 connect( mGroupSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged );
95 connect( mGroupIndentSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged );
96 connect( mSubgroupIndentSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged );
97 connect( mSpaceBelowGroupHeadingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged );
98 connect( mGroupSideSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceGroupSideChanged );
99 connect( mLayerSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged );
100 connect( mSpaceBelowSubgroupHeadingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged );
101 connect( mSubgroupSideSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceSubGroupSideChanged );
102 connect( mSymbolSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged );
103 connect( mSymbolSideSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceSymbolSideChanged );
104 connect( mIconLabelSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged );
105 connect( mBoxSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged );
106 connect( mColumnSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged );
107 connect( mCheckBoxAutoUpdate, &QCheckBox::stateChanged,
this, [ = ](
int state ) { mCheckBoxAutoUpdate_stateChanged( state ); } );
108 connect( mCheckboxResizeContents, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mCheckboxResizeContents_toggled );
109 connect( mRasterStrokeGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled );
110 connect( mRasterStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged );
111 connect( mRasterStrokeColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged );
112 connect( mMoveDownToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mMoveDownToolButton_clicked );
113 connect( mMoveUpToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mMoveUpToolButton_clicked );
114 connect( mRemoveToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mRemoveToolButton_clicked );
115 connect( mAddToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mAddToolButton_clicked );
116 connect( mEditPushButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mEditPushButton_clicked );
117 connect( mCountToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mCountToolButton_clicked );
118 connect( mExpressionFilterButton, &QgsLegendFilterButton::toggled,
this, &QgsLayoutLegendWidget::mExpressionFilterButton_toggled );
119 connect( mLayerExpressionButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mLayerExpressionButton_clicked );
120 connect( mFilterByMapCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled );
121 connect( mUpdateAllPushButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mUpdateAllPushButton_clicked );
122 connect( mAddGroupToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mAddGroupToolButton_clicked );
123 connect( mFilterLegendByAtlasCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled );
124 connect( mItemTreeView, &QgsLayerTreeView::doubleClicked,
this, &QgsLayoutLegendWidget::mItemTreeView_doubleClicked );
125 setPanelTitle( tr(
"Legend Properties" ) );
132 mTitleAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
133 mGroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
134 mSubgroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
135 mItemAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
137 mArrangementCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignRight );
139 mArrangementCombo->customizeAlignmentDisplay( Qt::AlignLeft, tr(
"Symbols on Left" ),
QgsApplication::getThemeIcon( QStringLiteral(
"/mIconArrangeSymbolsLeft.svg" ) ) );
140 mArrangementCombo->customizeAlignmentDisplay( Qt::AlignRight, tr(
"Symbols on Right" ),
QgsApplication::getThemeIcon( QStringLiteral(
"/mIconArrangeSymbolsRight.svg" ) ) );
142 mSpaceBelowGroupHeadingSpinBox->setClearValue( 0 );
143 mGroupSideSpinBox->setClearValue( 0 );
144 mSpaceBelowSubgroupHeadingSpinBox->setClearValue( 0 );
145 mSubgroupSideSpinBox->setClearValue( 0 );
146 mSymbolSideSpaceSpinBox->setClearValue( 0 );
167 mRasterStrokeColorButton->setColorDialogTitle( tr(
"Select Stroke Color" ) );
168 mRasterStrokeColorButton->setAllowOpacity(
true );
169 mRasterStrokeColorButton->setContext( QStringLiteral(
"composer " ) );
171 mMapComboBox->setCurrentLayout( legend->
layout() );
177 mainLayout->addWidget( mItemPropertiesWidget );
179 mItemTreeView->setHeaderHidden(
true );
181 mItemTreeView->setModel( legend->
model() );
182 mItemTreeView->setMenuProvider(
new QgsLayoutLegendMenuProvider( mItemTreeView,
this ) );
183 setLegendMapViewData();
189 connect( layoutAtlas(), &
QgsLayoutAtlas::toggled,
this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
193 mTitleFontButton->registerExpressionContextGenerator(
this );
194 mGroupFontButton->registerExpressionContextGenerator(
this );
195 mLayerFontButton->registerExpressionContextGenerator(
this );
196 mItemFontButton->registerExpressionContextGenerator(
this );
198 mTitleFontButton->setLayer( coverageLayer() );
199 mGroupFontButton->setLayer( coverageLayer() );
200 mLayerFontButton->setLayer( coverageLayer() );
201 mItemFontButton->setLayer( coverageLayer() );
202 if ( mLegend->layout() )
215 connect( mItemTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
216 this, &QgsLayoutLegendWidget::selectedChanged );
225 if ( mItemPropertiesWidget )
226 mItemPropertiesWidget->setMasterLayout( masterLayout );
232 mTitleFontButton->setMessageBar( iface->
messageBar() );
233 mGroupFontButton->setMessageBar( iface->
messageBar() );
234 mLayerFontButton->setMessageBar( iface->
messageBar() );
235 mItemFontButton->setMessageBar( iface->
messageBar() );
238void QgsLayoutLegendWidget::setGuiElements()
245 blockAllSignals(
true );
246 mTitleLineEdit->setText( mLegend->title() );
247 whileBlocking( mTitleAlignCombo )->setCurrentAlignment( mLegend->titleAlignment() );
251 whileBlocking( mArrangementCombo )->setCurrentAlignment( mLegend->symbolAlignment() );
252 mFilterByMapCheckBox->setChecked( mLegend->legendFilterByMapEnabled() );
253 mColumnCountSpinBox->setValue( mLegend->columnCount() );
254 mSplitLayerCheckBox->setChecked( mLegend->splitLayer() );
255 mEqualColumnWidthCheckBox->setChecked( mLegend->equalColumnWidth() );
256 mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
257 mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
258 mMaxSymbolSizeSpinBox->setValue( mLegend->maximumSymbolSize() );
259 mMinSymbolSizeSpinBox->setValue( mLegend->minimumSymbolSize() );
260 mWmsLegendWidthSpinBox->setValue( mLegend->wmsLegendWidth() );
261 mWmsLegendHeightSpinBox->setValue( mLegend->wmsLegendHeight() );
275 mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
276 mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
278 mRasterStrokeGroupBox->setChecked( mLegend->drawRasterStroke() );
279 mRasterStrokeWidthSpinBox->setValue( mLegend->rasterStrokeWidth() );
280 mRasterStrokeColorButton->setColor( mLegend->rasterStrokeColor() );
282 mCheckBoxAutoUpdate->setChecked( mLegend->autoUpdateModel() );
284 mCheckboxResizeContents->setChecked( mLegend->resizeToContents() );
285 mFilterLegendByAtlasCheckBox->setChecked( mLegend->legendFilterOutAtlas() );
286 mWrapCharLineEdit->setText( mLegend->wrapString() );
289 mMapComboBox->setItem( map );
295 blockAllSignals(
false );
297 mCheckBoxAutoUpdate_stateChanged( mLegend->autoUpdateModel() ? Qt::Checked : Qt::Unchecked,
false );
298 updateDataDefinedButton( mLegendTitleDDBtn );
299 updateDataDefinedButton( mColumnsDDBtn );
302void QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged(
const QString &text )
306 mLegend->beginCommand( tr(
"Change Legend Wrap" ) );
307 mLegend->setWrapString( text );
308 mLegend->adjustBoxSize();
310 mLegend->endCommand();
314void QgsLayoutLegendWidget::mTitleLineEdit_textChanged(
const QString &text )
319 mLegend->setTitle( text );
320 mLegend->adjustBoxSize();
322 mLegend->endCommand();
326void QgsLayoutLegendWidget::titleAlignmentChanged()
330 Qt::AlignmentFlag alignment =
static_cast< Qt::AlignmentFlag
>(
static_cast< int >( mTitleAlignCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
331 mLegend->beginCommand( tr(
"Change Title Alignment" ) );
332 mLegend->setTitleAlignment( alignment );
334 mLegend->endCommand();
338void QgsLayoutLegendWidget::groupAlignmentChanged()
342 mLegend->beginCommand( tr(
"Change Group Alignment" ) );
345 mLegend->endCommand();
349void QgsLayoutLegendWidget::subgroupAlignmentChanged()
353 mLegend->beginCommand( tr(
"Change Subgroup Alignment" ) );
356 mLegend->endCommand();
360void QgsLayoutLegendWidget::itemAlignmentChanged()
364 mLegend->beginCommand( tr(
"Change Item Alignment" ) );
367 mLegend->endCommand();
371void QgsLayoutLegendWidget::arrangementChanged()
375 Qt::AlignmentFlag alignment =
static_cast< Qt::AlignmentFlag
>(
static_cast< int >( mArrangementCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
376 mLegend->beginCommand( tr(
"Change Legend Arrangement" ) );
377 mLegend->setSymbolAlignment( alignment );
379 mLegend->endCommand();
383void QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged(
int c )
388 mLegend->setColumnCount(
c );
389 mLegend->adjustBoxSize();
391 mLegend->endCommand();
393 mSplitLayerCheckBox->setEnabled(
c > 1 );
394 mEqualColumnWidthCheckBox->setEnabled(
c > 1 );
397void QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled(
bool checked )
401 mLegend->beginCommand( tr(
"Split Legend Layers" ) );
402 mLegend->setSplitLayer( checked );
403 mLegend->adjustBoxSize();
405 mLegend->endCommand();
409void QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled(
bool checked )
413 mLegend->beginCommand( tr(
"Legend Column Width" ) );
414 mLegend->setEqualColumnWidth( checked );
415 mLegend->adjustBoxSize();
417 mLegend->endCommand();
421void QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged(
double d )
426 mLegend->setSymbolWidth( d );
427 mLegend->adjustBoxSize();
429 mLegend->endCommand();
433void QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged(
double d )
438 mLegend->setMaximumSymbolSize( d );
439 mLegend->adjustBoxSize();
441 mLegend->endCommand();
445void QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged(
double d )
450 mLegend->setMinimumSymbolSize( d );
451 mLegend->adjustBoxSize();
453 mLegend->endCommand();
457void QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged(
double d )
462 mLegend->setSymbolHeight( d );
463 mLegend->adjustBoxSize();
465 mLegend->endCommand();
469void QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged(
double d )
474 mLegend->setWmsLegendWidth( d );
475 mLegend->adjustBoxSize();
477 mLegend->endCommand();
481void QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged(
double d )
486 mLegend->setWmsLegendHeight( d );
487 mLegend->adjustBoxSize();
489 mLegend->endCommand();
493void QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged(
double d )
499 mLegend->adjustBoxSize();
501 mLegend->endCommand();
505void QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged(
double d )
511 mLegend->adjustBoxSize();
513 mLegend->endCommand();
517void QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged(
double d )
523 mLegend->adjustBoxSize();
525 mLegend->endCommand();
529void QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged(
double d )
535 mLegend->adjustBoxSize();
537 mLegend->endCommand();
541void QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged(
double space )
547 mLegend->adjustBoxSize();
549 mLegend->endCommand();
553void QgsLayoutLegendWidget::spaceGroupSideChanged(
double space )
559 mLegend->adjustBoxSize();
561 mLegend->endCommand();
565void QgsLayoutLegendWidget::spaceSubGroupSideChanged(
double space )
571 mLegend->adjustBoxSize();
573 mLegend->endCommand();
577void QgsLayoutLegendWidget::spaceSymbolSideChanged(
double space )
583 mLegend->adjustBoxSize();
585 mLegend->endCommand();
589void QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged(
double d )
595 mLegend->adjustBoxSize();
597 mLegend->endCommand();
601void QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged(
double d )
609 mLegend->adjustBoxSize();
611 mLegend->endCommand();
615void QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged(
double d )
621 mLegend->adjustBoxSize();
623 mLegend->endCommand();
627void QgsLayoutLegendWidget::titleFontChanged()
633 mLegend->adjustBoxSize();
635 mLegend->endCommand();
639void QgsLayoutLegendWidget::groupFontChanged()
645 mLegend->adjustBoxSize();
647 mLegend->endCommand();
651void QgsLayoutLegendWidget::layerFontChanged()
657 mLegend->adjustBoxSize();
659 mLegend->endCommand();
663void QgsLayoutLegendWidget::itemFontChanged()
669 mLegend->adjustBoxSize();
671 mLegend->endCommand();
675void QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged(
double space )
681 mLegend->adjustBoxSize();
683 mLegend->endCommand();
687void QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged(
double d )
692 mLegend->setBoxSpace( d );
693 mLegend->adjustBoxSize();
695 mLegend->endCommand();
699void QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged(
double d )
704 mLegend->setColumnSpace( d );
705 mLegend->adjustBoxSize();
707 mLegend->endCommand();
711static void _moveLegendNode(
QgsLayerTreeLayer *nodeLayer,
int legendNodeIndex,
int offset )
715 if ( legendNodeIndex < 0 || legendNodeIndex >= order.count() )
717 if ( legendNodeIndex + offset < 0 || legendNodeIndex + offset >= order.count() )
720 int id = order.takeAt( legendNodeIndex );
721 order.insert( legendNodeIndex + offset,
id );
727void QgsLayoutLegendWidget::mMoveDownToolButton_clicked()
734 const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
735 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
736 const QModelIndex parentIndex = sourceIndex.parent();
737 if ( !sourceIndex.isValid() || sourceIndex.row() == mItemTreeView->layerTreeModel()->rowCount( parentIndex ) - 1 )
745 mLegend->beginCommand( tr(
"Moved Legend Item Down" ) );
759 mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() + 1, 0, parentIndex ) ) );
762 mLegend->endCommand();
765void QgsLayoutLegendWidget::mMoveUpToolButton_clicked()
772 const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
773 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
774 const QModelIndex parentIndex = sourceIndex.parent();
775 if ( !sourceIndex.isValid() || sourceIndex.row() == 0 )
783 mLegend->beginCommand( tr(
"Move Legend Item Up" ) );
797 mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() - 1, 0, parentIndex ) ) );
800 mLegend->endCommand();
803void QgsLayoutLegendWidget::mCheckBoxAutoUpdate_stateChanged(
int state,
bool userTriggered )
807 mLegend->beginCommand( tr(
"Change Auto Update" ) );
809 mLegend->setAutoUpdateModel( state == Qt::Checked );
811 mLegend->endCommand();
815 QList<QWidget *> widgets;
816 widgets << mMoveDownToolButton << mMoveUpToolButton << mRemoveToolButton << mAddToolButton
817 << mEditPushButton << mCountToolButton << mUpdateAllPushButton << mAddGroupToolButton
818 << mExpressionFilterButton;
819 for ( QWidget *w : std::as_const( widgets ) )
820 w->setEnabled( state != Qt::Checked );
822 if ( state == Qt::Unchecked )
825 selectedChanged( QModelIndex(), QModelIndex() );
829void QgsLayoutLegendWidget::composerMapChanged(
QgsLayoutItem *item )
845 mLegend->beginCommand( tr(
"Change Legend Map" ) );
846 mLegend->setLinkedMap( map );
848 mLegend->endCommand();
850 setLegendMapViewData();
854void QgsLayoutLegendWidget::mCheckboxResizeContents_toggled(
bool checked )
861 mLegend->beginCommand( tr(
"Resize Legend to Contents" ) );
862 mLegend->setResizeToContents( checked );
864 mLegend->adjustBoxSize();
866 mLegend->endCommand();
869void QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled(
bool state )
876 mLegend->beginCommand( tr(
"Change Legend Borders" ) );
877 mLegend->setDrawRasterStroke( state );
878 mLegend->adjustBoxSize();
880 mLegend->endCommand();
883void QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged(
double d )
891 mLegend->setRasterStrokeWidth( d );
892 mLegend->adjustBoxSize();
894 mLegend->endCommand();
897void QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged(
const QColor &newColor )
905 mLegend->setRasterStrokeColor( newColor );
907 mLegend->endCommand();
910void QgsLayoutLegendWidget::mAddToolButton_clicked()
917 QList< QgsMapLayer * > visibleLayers;
918 if ( mLegend->linkedMap() )
920 visibleLayers = mLegend->linkedMap()->layersToRender();
922 if ( visibleLayers.isEmpty() )
925 visibleLayers = mMapCanvas->layers(
true );
929 addDialog.setVisibleLayers( visibleLayers );
930 if ( addDialog.exec() == QDialog::Accepted )
932 const QList<QgsMapLayer *> layers = addDialog.selectedLayers();
933 if ( !layers.empty() )
935 mLegend->beginCommand( tr(
"Add Legend Item(s)" ) );
938 mLegend->model()->rootGroup()->addLayer( layer );
940 mLegend->updateLegend();
942 mLegend->endCommand();
947void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
954 QItemSelectionModel *selectionModel = mItemTreeView->selectionModel();
955 if ( !selectionModel )
960 mLegend->beginCommand( tr(
"Remove Legend Item" ) );
962 QList<QPersistentModelIndex> proxyIndexes;
963 const QModelIndexList viewSelection = selectionModel->selectedIndexes();
964 for (
const QModelIndex &index : viewSelection )
965 proxyIndexes << index;
968 QHash<QgsLayerTreeLayer *, QList<int> > nodesWithRemoval;
969 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
974 nodesWithRemoval[nodeLayer].append( _unfilteredLegendNodeIndex(
legendNode ) );
977 for (
auto it = nodesWithRemoval.constBegin(); it != nodesWithRemoval.constEnd(); ++it )
979 QList<int> toDelete = it.value();
980 std::sort( toDelete.begin(), toDelete.end(), std::greater<int>() );
983 for (
int i : std::as_const( toDelete ) )
985 if ( i >= 0 && i < order.count() )
990 mItemTreeView->layerTreeModel()->refreshLayerLegend( it.key() );
994 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
996 if ( proxyIndex.isValid() && mItemTreeView->index2node( proxyIndex ) )
998 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( proxyIndex );
999 mLegend->model()->removeRow( sourceIndex.row(), sourceIndex.parent() );
1003 mLegend->updateLegend();
1005 mLegend->endCommand();
1008void QgsLayoutLegendWidget::mEditPushButton_clicked()
1015 QModelIndex idx = mItemTreeView->selectionModel()->currentIndex();
1016 mItemTreeView_doubleClicked( idx );
1019void QgsLayoutLegendWidget::resetLayerNodeToDefaults()
1027 QModelIndex currentIndex = mItemTreeView->currentIndex();
1028 if ( !currentIndex.isValid() )
1047 mLegend->beginCommand( tr(
"Update Legend" ) );
1050 for (
const QString &key : constCustomProperties )
1052 if ( key.startsWith( QLatin1String(
"legend/" ) ) )
1059 mItemTreeView->layerTreeModel()->refreshLayerLegend( nodeLayer );
1061 mLegend->updateLegend();
1063 mLegend->endCommand();
1066void QgsLayoutLegendWidget::mCountToolButton_clicked(
bool checked )
1073 const QList< QModelIndex > selectedIndexes = mItemTreeView->selectionModel()->selectedIndexes();
1074 if ( selectedIndexes.empty() )
1077 mLegend->beginCommand( tr(
"Update Legend" ) );
1078 for (
const QModelIndex &index : selectedIndexes )
1084 currentNode->
setCustomProperty( QStringLiteral(
"showFeatureCount" ), checked ? 1 : 0 );
1086 mLegend->updateFilterByMap();
1087 mLegend->adjustBoxSize();
1088 mLegend->endCommand();
1091void QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled(
bool checked )
1093 mLegend->beginCommand( tr(
"Update Legend" ) );
1094 mLegend->setLegendFilterByMapEnabled( checked );
1095 mLegend->adjustBoxSize();
1097 mLegend->endCommand();
1100void QgsLayoutLegendWidget::mExpressionFilterButton_toggled(
bool checked )
1108 QModelIndex currentIndex = mItemTreeView->currentIndex();
1109 if ( !currentIndex.isValid() )
1119 mExpressionFilterButton->expressionText(),
1122 mLegend->beginCommand( tr(
"Update Legend" ) );
1123 mLegend->updateFilterByMap();
1124 mLegend->adjustBoxSize();
1125 mLegend->endCommand();
1128void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
1135 QModelIndex currentIndex = mItemTreeView->currentIndex();
1136 if ( !currentIndex.isValid() )
1143 QgsLayerTreeLayer *layerNode = qobject_cast<QgsLayerTreeLayer *>( currentNode );
1149 QString currentExpression;
1151 currentExpression = QStringLiteral(
"@symbol_label" );
1161 QStringList highlighted;
1166 if ( !legendSymbols.empty() )
1172 highlighted << QStringLiteral(
"symbol_label" ) << QStringLiteral(
"symbol_id" );
1174 highlighted << QStringLiteral(
"symbol_count" );
1183 if ( expressiondialog.exec() )
1186 mLegend->beginCommand( tr(
"Update Legend" ) );
1188 mLegend->adjustBoxSize();
1189 mLegend->endCommand();
1192void QgsLayoutLegendWidget::mUpdateAllPushButton_clicked()
1197void QgsLayoutLegendWidget::mAddGroupToolButton_clicked()
1201 mLegend->beginCommand( tr(
"Add Legend Group" ) );
1202 mLegend->model()->rootGroup()->addGroup( tr(
"Group" ) );
1203 mLegend->updateLegend();
1205 mLegend->endCommand();
1209void QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled(
bool toggled )
1214 mLegend->setLegendFilterOutAtlas( toggled );
1220void QgsLayoutLegendWidget::updateLegend()
1224 mLegend->beginCommand( tr(
"Update Legend" ) );
1227 mLegend->setAutoUpdateModel(
true );
1228 mLegend->setAutoUpdateModel(
false );
1230 mLegend->endCommand();
1234void QgsLayoutLegendWidget::setReportTypeString(
const QString &
string )
1236 mFilterLegendByAtlasCheckBox->setText( tr(
"Only show items inside current %1 feature" ).arg(
string ) );
1237 mFilterLegendByAtlasCheckBox->setToolTip( tr(
"Filter out legend elements that lie outside the current %1 feature." ).arg(
string ) );
1246bool QgsLayoutLegendWidget::setNewItem(
QgsLayoutItem *item )
1256 mLegend = qobject_cast< QgsLayoutItemLegend * >( item );
1257 mItemPropertiesWidget->setItem( mLegend );
1261 mItemTreeView->setModel( mLegend->model() );
1270void QgsLayoutLegendWidget::blockAllSignals(
bool b )
1272 mTitleLineEdit->blockSignals( b );
1273 mTitleAlignCombo->blockSignals( b );
1274 mItemTreeView->blockSignals( b );
1275 mCheckBoxAutoUpdate->blockSignals( b );
1276 mMapComboBox->blockSignals( b );
1277 mFilterByMapCheckBox->blockSignals( b );
1278 mColumnCountSpinBox->blockSignals( b );
1279 mSplitLayerCheckBox->blockSignals( b );
1280 mEqualColumnWidthCheckBox->blockSignals( b );
1281 mSymbolWidthSpinBox->blockSignals( b );
1282 mSymbolHeightSpinBox->blockSignals( b );
1283 mMaxSymbolSizeSpinBox->blockSignals( b );
1284 mMinSymbolSizeSpinBox->blockSignals( b );
1285 mGroupSpaceSpinBox->blockSignals( b );
1286 mGroupIndentSpinBox->blockSignals( b );
1287 mSubgroupIndentSpinBox->blockSignals( b );
1288 mSpaceBelowGroupHeadingSpinBox->blockSignals( b );
1289 mGroupSideSpinBox->blockSignals( b );
1290 mSpaceBelowSubgroupHeadingSpinBox->blockSignals( b );
1291 mSubgroupSideSpinBox->blockSignals( b );
1292 mLayerSpaceSpinBox->blockSignals( b );
1293 mSymbolSpaceSpinBox->blockSignals( b );
1294 mSymbolSideSpaceSpinBox->blockSignals( b );
1295 mIconLabelSpaceSpinBox->blockSignals( b );
1296 mBoxSpaceSpinBox->blockSignals( b );
1297 mColumnSpaceSpinBox->blockSignals( b );
1298 mRasterStrokeGroupBox->blockSignals( b );
1299 mRasterStrokeColorButton->blockSignals( b );
1300 mRasterStrokeWidthSpinBox->blockSignals( b );
1301 mWmsLegendWidthSpinBox->blockSignals( b );
1302 mWmsLegendHeightSpinBox->blockSignals( b );
1303 mCheckboxResizeContents->blockSignals( b );
1304 mTitleSpaceBottomSpinBox->blockSignals( b );
1305 mFilterLegendByAtlasCheckBox->blockSignals( b );
1306 mTitleFontButton->blockSignals( b );
1307 mGroupFontButton->blockSignals( b );
1308 mLayerFontButton->blockSignals( b );
1309 mItemFontButton->blockSignals( b );
1310 mWrapCharLineEdit->blockSignals( b );
1313void QgsLayoutLegendWidget::selectedChanged(
const QModelIndex ¤t,
const QModelIndex &previous )
1316 Q_UNUSED( previous )
1318 mLayerExpressionButton->setEnabled(
false );
1320 if ( mLegend && mLegend->autoUpdateModel() )
1331 mLayerExpressionButton->setEnabled(
true );
1335 mCountToolButton->setChecked(
false );
1336 mCountToolButton->setEnabled(
false );
1339 mExpressionFilterButton->blockSignals(
true );
1340 mExpressionFilterButton->setChecked(
false );
1341 mExpressionFilterButton->setEnabled(
false );
1342 mExpressionFilterButton->blockSignals(
false );
1353 mCountToolButton->setChecked( currentNode->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() );
1354 mCountToolButton->setEnabled(
true );
1355 mLayerExpressionButton->setEnabled(
true );
1359 mExpressionFilterButton->blockSignals(
true );
1360 mExpressionFilterButton->setExpressionText( expr );
1361 mExpressionFilterButton->setVectorLayer( vl );
1362 mExpressionFilterButton->setEnabled(
true );
1363 mExpressionFilterButton->setChecked( exprEnabled );
1364 mExpressionFilterButton->blockSignals(
false );
1367void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
1369 QAction *a = qobject_cast<QAction *>( sender() );
1370 if ( !a || !mItemTreeView->currentNode() )
1377void QgsLayoutLegendWidget::setLegendMapViewData()
1379 if ( mLegend->linkedMap() )
1383 measurementConverter.
setDpi( dpi );
1386 double mapUnitsPerPixelX = mLegend->linkedMap()->extent().width() / mapWidth;
1387 double mapUnitsPerPixelY = mLegend->linkedMap()->extent().height() / mapHeight;
1388 mLegend->model()->setLegendMapViewData( ( mapUnitsPerPixelX > mapUnitsPerPixelY ? mapUnitsPerPixelX : mapUnitsPerPixelY ), dpi, mLegend->linkedMap()->scale() );
1392void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
1396 mFilterLegendByAtlasCheckBox->setEnabled( atlas->enabled() && mLegend->layout()->reportContext().layer() && mLegend->layout()->reportContext().layer()->geometryType() ==
QgsWkbTypes::PolygonGeometry );
1400void QgsLayoutLegendWidget::mItemTreeView_doubleClicked(
const QModelIndex &idx )
1402 if ( !mLegend || !idx.isValid() )
1407 if ( mLegend->autoUpdateModel() )
1413 int originalIndex = -1;
1416 originalIndex = _originalLegendNodeIndex(
legendNode );
1420 QgsLayoutLegendNodeWidget *widget =
new QgsLayoutLegendNodeWidget( mLegend, currentNode,
legendNode, originalIndex );
1421 openPanel( widget );
1429QgsLayoutLegendMenuProvider::QgsLayoutLegendMenuProvider(
QgsLayerTreeView *view, QgsLayoutLegendWidget *w )
1434QMenu *QgsLayoutLegendMenuProvider::createContextMenu()
1436 if ( !mView->currentNode() )
1439 if ( mWidget->legend()->autoUpdateModel() )
1442 QMenu *menu =
new QMenu();
1446 menu->addAction( QObject::tr(
"Reset to Defaults" ), mWidget, &QgsLayoutLegendWidget::resetLayerNodeToDefaults );
1447 menu->addSeparator();
1452 QList<QgsLegendStyle::Style> lst;
1456 QAction *action = menu->addAction(
QgsLegendStyle::styleLabel( style ), mWidget, &QgsLayoutLegendWidget::setCurrentNodeStyleFromAction );
1457 action->setCheckable(
true );
1458 action->setChecked( currentStyle == style );
1459 action->setData(
static_cast< int >( style ) );
1474 , mOriginalLegendNodeIndex( originalLegendNodeIndex )
1477 setPanelTitle( tr(
"Legend Item Properties" ) );
1486 QString currentLabel;
1489 currentLabel = mLegendNode->data( Qt::EditRole ).toString();
1490 mColumnBreakBeforeCheckBox->setChecked( mLegendNode->columnBreak() );
1494 currentLabel = mLayer->name();
1495 QVariant v = mLayer->customProperty( QStringLiteral(
"legend/title-label" ) );
1497 currentLabel = v.toString();
1498 mColumnBreakBeforeCheckBox->setChecked( mLayer->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1500 mColumnSplitBehaviorComboBox->setCurrentIndex( mColumnSplitBehaviorComboBox->findData( mLayer->legendSplitBehavior() ) );
1505 mColumnBreakBeforeCheckBox->setChecked( mNode->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1508 mWidthSpinBox->setClearValue( 0, tr(
"Default" ) );
1509 mHeightSpinBox->setClearValue( 0, tr(
"Default" ) );
1510 mWidthSpinBox->setVisible( mLegendNode || mLayer );
1511 mHeightSpinBox->setVisible( mLegendNode || mLayer );
1512 mPatchGroup->setVisible( mLegendNode || mLayer );
1513 mPatchWidthLabel->setVisible( mLegendNode || mLayer );
1514 mPatchHeightLabel->setVisible( mLegendNode || mLayer );
1515 mCustomSymbolCheckBox->setVisible( mLegendNode || mLegend->model()->legendNodeEmbeddedInParent( mLayer ) );
1516 mColumnSplitLabel->setVisible( mLayer && !mLegendNode );
1517 mColumnSplitBehaviorComboBox->setVisible( mLayer && !mLegendNode );
1520 mWidthSpinBox->setValue( mLegendNode->userPatchSize().width() );
1521 mHeightSpinBox->setValue( mLegendNode->userPatchSize().height() );
1525 mWidthSpinBox->setValue( mLayer->patchSize().width() );
1526 mHeightSpinBox->setValue( mLayer->patchSize().height() );
1529 mCustomSymbolCheckBox->setChecked(
false );
1534 patchShape = symbolLegendNode->patchShape();
1536 std::unique_ptr< QgsSymbol > customSymbol( symbolLegendNode->customSymbol() ? symbolLegendNode->customSymbol()->clone() :
nullptr );
1537 mCustomSymbolCheckBox->setChecked( customSymbol.get() );
1540 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1541 mCustomSymbolButton->setSymbolType( customSymbol->type() );
1542 mCustomSymbolButton->setSymbol( customSymbol.release() );
1544 else if ( symbolLegendNode->symbol() )
1546 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1547 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1548 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1551 else if ( !mLegendNode && mLayer )
1553 patchShape = mLayer->patchShape();
1556 if (
QgsSymbol *customSymbol = symbolLegendNode->customSymbol() )
1558 mCustomSymbolCheckBox->setChecked(
true );
1559 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1561 mCustomSymbolButton->setSymbol( customSymbol->clone() );
1565 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1566 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1567 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1574 switch ( qobject_cast< QgsVectorLayer * >( mLayer->layer() )->geometryType() )
1589 mPatchShapeLabel->hide();
1590 mPatchShapeButton->hide();
1593 if ( !patchShape.
isNull() )
1594 mPatchShapeButton->setShape( patchShape );
1599 if ( symbolLegendNode->symbol() )
1601 mPatchShapeButton->setSymbolType( symbolLegendNode->symbol()->type() );
1605 mPatchShapeLabel->hide();
1606 mPatchShapeButton->hide();
1611 mPatchShapeLabel->hide();
1612 mPatchShapeButton->hide();
1617 mLabelGroup->hide();
1618 mColorRampLegendWidget->setSettings( colorRampNode->settings() );
1622 mColorRampLegendWidget->hide();
1635 mCustomSymbolCheckBox->hide();
1644 mLabelEdit->setPlainText( currentLabel );
1645 connect( mLabelEdit, &QPlainTextEdit::textChanged,
this, &QgsLayoutLegendNodeWidget::labelChanged );
1647 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutLegendNodeWidget::insertExpression );
1649 connect( mWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1650 connect( mHeightSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1652 connect( mCustomSymbolCheckBox, &QGroupBox::toggled,
this, &QgsLayoutLegendNodeWidget::customSymbolChanged );
1655 connect( mColumnBreakBeforeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendNodeWidget::columnBreakToggled );
1657 connect( mColumnSplitBehaviorComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutLegendNodeWidget::columnSplitChanged );
1661 connectChildPanel( mColorRampLegendWidget );
1664void QgsLayoutLegendNodeWidget::setDockMode(
bool dockMode )
1666 mColorRampLegendWidget->setDockMode( dockMode );
1670void QgsLayoutLegendNodeWidget::labelChanged()
1674 const QString label = mLabelEdit->toPlainText();
1679 else if ( mLegendNode )
1682 mLegend->model()->refreshLayerLegend( mLayer );
1686 mLayer->setCustomProperty( QStringLiteral(
"legend/title-label" ), label );
1690 embeddedNode->setUserLabel( QString() );
1693 mLegend->adjustBoxSize();
1695 mLegend->endCommand();
1698void QgsLayoutLegendNodeWidget::patchChanged()
1700 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1706 mLegend->model()->refreshLayerLegend( mLayer );
1710 mLayer->setPatchShape( shape );
1711 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1716 mLegend->model()->refreshLayerLegend( mLayer );
1719 mLegend->adjustBoxSize();
1721 mLegend->endCommand();
1724void QgsLayoutLegendNodeWidget::insertExpression()
1729 QString selText = mLabelEdit->textCursor().selectedText();
1732 selText = selText.replace( QChar( 0x2029 ), QChar(
'\n' ) );
1735 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
1736 selText = selText.mid( 2, selText.size() - 4 );
1739 QgsVectorLayer *layer = mLegend->layout() ? mLegend->layout()->reportContext().layer() :
nullptr;
1743 if ( mLayer && mLayer->layer() )
1749 << QStringLiteral(
"legend_column_count" )
1750 << QStringLiteral(
"legend_split_layers" )
1751 << QStringLiteral(
"legend_wrap_string" )
1752 << QStringLiteral(
"legend_filter_by_map" )
1753 << QStringLiteral(
"legend_filter_out_atlas" ) );
1757 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1758 if ( exprDlg.exec() == QDialog::Accepted )
1760 QString expression = exprDlg.expressionText();
1761 if ( !expression.isEmpty() )
1763 mLegend->beginCommand( tr(
"Insert expression" ) );
1764 mLabelEdit->insertPlainText(
"[%" + expression +
"%]" );
1765 mLegend->endCommand();
1770void QgsLayoutLegendNodeWidget::sizeChanged(
double )
1772 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1773 const QSizeF size = QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() );
1778 mLegend->model()->refreshLayerLegend( mLayer );
1782 mLayer->setPatchSize( size );
1783 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1788 mLegend->model()->refreshLayerLegend( mLayer );
1791 mLegend->adjustBoxSize();
1793 mLegend->endCommand();
1796void QgsLayoutLegendNodeWidget::customSymbolChanged()
1798 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1800 if ( mCustomSymbolCheckBox->isChecked() )
1805 mLegend->model()->refreshLayerLegend( mLayer );
1809 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1814 mLegend->model()->refreshLayerLegend( mLayer );
1822 mLegend->model()->refreshLayerLegend( mLayer );
1826 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1831 mLegend->model()->refreshLayerLegend( mLayer );
1835 mLegend->adjustBoxSize();
1837 mLegend->endCommand();
1840void QgsLayoutLegendNodeWidget::colorRampLegendChanged()
1842 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1846 mLegend->model()->refreshLayerLegend( mLayer );
1848 mLegend->adjustBoxSize();
1850 mLegend->endCommand();
1853void QgsLayoutLegendNodeWidget::columnBreakToggled(
bool checked )
1855 mLegend->beginCommand( tr(
"Edit Legend Columns" ) );
1860 mLegend->model()->refreshLayerLegend( mLayer );
1864 mLayer->setCustomProperty( QStringLiteral(
"legend/column-break" ), QString( checked ?
'1' :
'0' ) );
1868 mNode->setCustomProperty( QStringLiteral(
"legend/column-break" ), QString( checked ?
'1' :
'0' ) );
1871 mLegend->adjustBoxSize();
1873 mLegend->endCommand();
1876void QgsLayoutLegendNodeWidget::columnSplitChanged()
1878 mLegend->beginCommand( tr(
"Edit Legend Columns" ) );
1880 if ( mLayer && !mLegendNode )
1885 mLegend->adjustBoxSize();
1887 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, QgsUnitTypes::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.
@ VectorLayer
Vector layer.
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.