49#include <QInputDialog>
66 int unfilteredNodeIndex = _unfilteredLegendNodeIndex( legendNode );
68 return ( unfilteredNodeIndex >= 0 && unfilteredNodeIndex < order.count() ? order[unfilteredNodeIndex] : -1 );
75 , mMapCanvas( mapCanvas )
80 connect( mWrapCharLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged );
81 connect( mTitleLineEdit, &QLineEdit::textChanged,
this, &QgsLayoutLegendWidget::mTitleLineEdit_textChanged );
86 connect( mColumnCountSpinBox,
static_cast < void ( QSpinBox::* )(
int )
> ( &QSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged );
87 connect( mSplitLayerCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled );
88 connect( mEqualColumnWidthCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled );
89 connect( mSymbolWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged );
90 connect( mSymbolHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged );
91 connect( mMaxSymbolSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged );
92 connect( mMinSymbolSizeSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged );
93 connect( mWmsLegendWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged );
94 connect( mWmsLegendHeightSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged );
95 connect( mTitleSpaceBottomSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged );
96 connect( mGroupSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged );
97 connect( mGroupIndentSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged );
98 connect( mSubgroupIndentSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged );
99 connect( mSpaceBelowGroupHeadingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged );
100 connect( mGroupSideSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceGroupSideChanged );
101 connect( mLayerSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged );
102 connect( mSpaceBelowSubgroupHeadingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged );
103 connect( mSubgroupSideSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceSubGroupSideChanged );
104 connect( mSymbolSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged );
105 connect( mSymbolSideSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::spaceSymbolSideChanged );
106 connect( mIconLabelSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged );
108 connect( mBoxSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged );
109 connect( mColumnSpaceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged );
110 connect( mLineSpacingSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mLineSpacingSpinBox_valueChanged );
111 connect( mCheckBoxAutoUpdate, &QCheckBox::stateChanged,
this, [ = ](
int state ) { mCheckBoxAutoUpdate_stateChanged( state ); } );
112 connect( mCheckboxResizeContents, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mCheckboxResizeContents_toggled );
113 connect( mRasterStrokeGroupBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled );
114 connect( mRasterStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged );
115 connect( mRasterStrokeColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged );
116 connect( mMoveDownToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mMoveDownToolButton_clicked );
117 connect( mMoveUpToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mMoveUpToolButton_clicked );
118 connect( mRemoveToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mRemoveToolButton_clicked );
119 connect( mAddToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mAddToolButton_clicked );
120 connect( mEditPushButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mEditPushButton_clicked );
121 connect( mCountToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mCountToolButton_clicked );
122 connect( mExpressionFilterButton, &QgsLegendFilterButton::toggled,
this, &QgsLayoutLegendWidget::mExpressionFilterButton_toggled );
123 connect( mLayerExpressionButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mLayerExpressionButton_clicked );
124 connect( mFilterByMapCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled );
125 connect( mUpdateAllPushButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mUpdateAllPushButton_clicked );
126 connect( mAddGroupToolButton, &QToolButton::clicked,
this, &QgsLayoutLegendWidget::mAddGroupToolButton_clicked );
127 connect( mFilterLegendByAtlasCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled );
128 connect( mItemTreeView, &QgsLayerTreeView::doubleClicked,
this, &QgsLayoutLegendWidget::mItemTreeView_doubleClicked );
129 setPanelTitle( tr(
"Legend Properties" ) );
136 mTitleAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
137 mGroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
138 mSubgroupAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
139 mItemAlignCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignHCenter | Qt::AlignRight );
141 mArrangementCombo->setAvailableAlignments( Qt::AlignLeft | Qt::AlignRight );
143 mArrangementCombo->customizeAlignmentDisplay( Qt::AlignLeft, tr(
"Symbols on Left" ),
QgsApplication::getThemeIcon( QStringLiteral(
"/mIconArrangeSymbolsLeft.svg" ) ) );
144 mArrangementCombo->customizeAlignmentDisplay( Qt::AlignRight, tr(
"Symbols on Right" ),
QgsApplication::getThemeIcon( QStringLiteral(
"/mIconArrangeSymbolsRight.svg" ) ) );
146 mSpaceBelowGroupHeadingSpinBox->setClearValue( 0 );
147 mGroupSideSpinBox->setClearValue( 0 );
148 mSpaceBelowSubgroupHeadingSpinBox->setClearValue( 0 );
149 mSubgroupSideSpinBox->setClearValue( 0 );
150 mSymbolSideSpaceSpinBox->setClearValue( 0 );
171 mFontColorButton->setColorDialogTitle( tr(
"Select Font Color" ) );
172 mFontColorButton->setContext( QStringLiteral(
"composer" ) );
174 mRasterStrokeColorButton->setColorDialogTitle( tr(
"Select Stroke Color" ) );
175 mRasterStrokeColorButton->setAllowOpacity(
true );
176 mRasterStrokeColorButton->setContext( QStringLiteral(
"composer " ) );
178 mMapComboBox->setCurrentLayout( legend->
layout() );
184 mainLayout->addWidget( mItemPropertiesWidget );
186 mItemTreeView->setHeaderHidden(
true );
188 mItemTreeView->setModel( legend->
model() );
189 mItemTreeView->setMenuProvider(
new QgsLayoutLegendMenuProvider( mItemTreeView,
this ) );
190 setLegendMapViewData();
196 connect( layoutAtlas(), &
QgsLayoutAtlas::toggled,
this, &QgsLayoutLegendWidget::updateFilterLegendByAtlasButton );
205 connect( mItemTreeView->selectionModel(), &QItemSelectionModel::currentChanged,
206 this, &QgsLayoutLegendWidget::selectedChanged );
215 if ( mItemPropertiesWidget )
216 mItemPropertiesWidget->setMasterLayout( masterLayout );
219void QgsLayoutLegendWidget::setGuiElements()
226 blockAllSignals(
true );
227 mTitleLineEdit->setText( mLegend->title() );
228 whileBlocking( mTitleAlignCombo )->setCurrentAlignment( mLegend->titleAlignment() );
232 whileBlocking( mArrangementCombo )->setCurrentAlignment( mLegend->symbolAlignment() );
233 mFilterByMapCheckBox->setChecked( mLegend->legendFilterByMapEnabled() );
234 mColumnCountSpinBox->setValue( mLegend->columnCount() );
235 mSplitLayerCheckBox->setChecked( mLegend->splitLayer() );
236 mEqualColumnWidthCheckBox->setChecked( mLegend->equalColumnWidth() );
237 mSymbolWidthSpinBox->setValue( mLegend->symbolWidth() );
238 mSymbolHeightSpinBox->setValue( mLegend->symbolHeight() );
239 mMaxSymbolSizeSpinBox->setValue( mLegend->maximumSymbolSize() );
240 mMinSymbolSizeSpinBox->setValue( mLegend->minimumSymbolSize() );
241 mWmsLegendWidthSpinBox->setValue( mLegend->wmsLegendWidth() );
242 mWmsLegendHeightSpinBox->setValue( mLegend->wmsLegendHeight() );
256 mBoxSpaceSpinBox->setValue( mLegend->boxSpace() );
257 mColumnSpaceSpinBox->setValue( mLegend->columnSpace() );
258 mLineSpacingSpinBox->setValue( mLegend->lineSpacing() );
260 mRasterStrokeGroupBox->setChecked( mLegend->drawRasterStroke() );
261 mRasterStrokeWidthSpinBox->setValue( mLegend->rasterStrokeWidth() );
262 mRasterStrokeColorButton->setColor( mLegend->rasterStrokeColor() );
264 mCheckBoxAutoUpdate->setChecked( mLegend->autoUpdateModel() );
266 mCheckboxResizeContents->setChecked( mLegend->resizeToContents() );
267 mFilterLegendByAtlasCheckBox->setChecked( mLegend->legendFilterOutAtlas() );
268 mWrapCharLineEdit->setText( mLegend->wrapString() );
271 mMapComboBox->setItem( map );
272 mFontColorButton->setColor( mLegend->fontColor() );
278 blockAllSignals(
false );
280 mCheckBoxAutoUpdate_stateChanged( mLegend->autoUpdateModel() ? Qt::Checked : Qt::Unchecked, false );
281 updateDataDefinedButton( mLegendTitleDDBtn );
282 updateDataDefinedButton( mColumnsDDBtn );
285void QgsLayoutLegendWidget::mWrapCharLineEdit_textChanged(
const QString &text )
289 mLegend->beginCommand( tr(
"Change Legend Wrap" ) );
290 mLegend->setWrapString( text );
291 mLegend->adjustBoxSize();
293 mLegend->endCommand();
297void QgsLayoutLegendWidget::mTitleLineEdit_textChanged(
const QString &text )
302 mLegend->setTitle( text );
303 mLegend->adjustBoxSize();
305 mLegend->endCommand();
309void QgsLayoutLegendWidget::titleAlignmentChanged()
313 Qt::AlignmentFlag alignment =
static_cast< Qt::AlignmentFlag
>(
static_cast< int >( mTitleAlignCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
314 mLegend->beginCommand( tr(
"Change Title Alignment" ) );
315 mLegend->setTitleAlignment( alignment );
317 mLegend->endCommand();
321void QgsLayoutLegendWidget::groupAlignmentChanged()
325 mLegend->beginCommand( tr(
"Change Group Alignment" ) );
328 mLegend->endCommand();
332void QgsLayoutLegendWidget::subgroupAlignmentChanged()
336 mLegend->beginCommand( tr(
"Change Subgroup Alignment" ) );
339 mLegend->endCommand();
343void QgsLayoutLegendWidget::itemAlignmentChanged()
347 mLegend->beginCommand( tr(
"Change Item Alignment" ) );
350 mLegend->endCommand();
354void QgsLayoutLegendWidget::arrangementChanged()
358 Qt::AlignmentFlag alignment =
static_cast< Qt::AlignmentFlag
>(
static_cast< int >( mArrangementCombo->currentAlignment() & Qt::AlignHorizontal_Mask ) );
359 mLegend->beginCommand( tr(
"Change Legend Arrangement" ) );
360 mLegend->setSymbolAlignment( alignment );
362 mLegend->endCommand();
366void QgsLayoutLegendWidget::mColumnCountSpinBox_valueChanged(
int c )
371 mLegend->setColumnCount(
c );
372 mLegend->adjustBoxSize();
374 mLegend->endCommand();
376 mSplitLayerCheckBox->setEnabled(
c > 1 );
377 mEqualColumnWidthCheckBox->setEnabled(
c > 1 );
380void QgsLayoutLegendWidget::mSplitLayerCheckBox_toggled(
bool checked )
384 mLegend->beginCommand( tr(
"Split Legend Layers" ) );
385 mLegend->setSplitLayer( checked );
386 mLegend->adjustBoxSize();
388 mLegend->endCommand();
392void QgsLayoutLegendWidget::mEqualColumnWidthCheckBox_toggled(
bool checked )
396 mLegend->beginCommand( tr(
"Legend Column Width" ) );
397 mLegend->setEqualColumnWidth( checked );
398 mLegend->adjustBoxSize();
400 mLegend->endCommand();
404void QgsLayoutLegendWidget::mSymbolWidthSpinBox_valueChanged(
double d )
409 mLegend->setSymbolWidth( d );
410 mLegend->adjustBoxSize();
412 mLegend->endCommand();
416void QgsLayoutLegendWidget::mMaxSymbolSizeSpinBox_valueChanged(
double d )
421 mLegend->setMaximumSymbolSize( d );
422 mLegend->adjustBoxSize();
424 mLegend->endCommand();
428void QgsLayoutLegendWidget::mMinSymbolSizeSpinBox_valueChanged(
double d )
433 mLegend->setMinimumSymbolSize( d );
434 mLegend->adjustBoxSize();
436 mLegend->endCommand();
440void QgsLayoutLegendWidget::mSymbolHeightSpinBox_valueChanged(
double d )
445 mLegend->setSymbolHeight( d );
446 mLegend->adjustBoxSize();
448 mLegend->endCommand();
452void QgsLayoutLegendWidget::mWmsLegendWidthSpinBox_valueChanged(
double d )
457 mLegend->setWmsLegendWidth( d );
458 mLegend->adjustBoxSize();
460 mLegend->endCommand();
464void QgsLayoutLegendWidget::mWmsLegendHeightSpinBox_valueChanged(
double d )
469 mLegend->setWmsLegendHeight( d );
470 mLegend->adjustBoxSize();
472 mLegend->endCommand();
476void QgsLayoutLegendWidget::mTitleSpaceBottomSpinBox_valueChanged(
double d )
482 mLegend->adjustBoxSize();
484 mLegend->endCommand();
488void QgsLayoutLegendWidget::mGroupSpaceSpinBox_valueChanged(
double d )
494 mLegend->adjustBoxSize();
496 mLegend->endCommand();
500void QgsLayoutLegendWidget::mGroupIndentSpinBox_valueChanged(
double d )
506 mLegend->adjustBoxSize();
508 mLegend->endCommand();
512void QgsLayoutLegendWidget::mSubgroupIndentSpinBox_valueChanged(
double d )
518 mLegend->adjustBoxSize();
520 mLegend->endCommand();
524void QgsLayoutLegendWidget::spaceBelowGroupHeadingChanged(
double space )
530 mLegend->adjustBoxSize();
532 mLegend->endCommand();
536void QgsLayoutLegendWidget::spaceGroupSideChanged(
double space )
542 mLegend->adjustBoxSize();
544 mLegend->endCommand();
548void QgsLayoutLegendWidget::spaceSubGroupSideChanged(
double space )
554 mLegend->adjustBoxSize();
556 mLegend->endCommand();
560void QgsLayoutLegendWidget::spaceSymbolSideChanged(
double space )
566 mLegend->adjustBoxSize();
568 mLegend->endCommand();
572void QgsLayoutLegendWidget::mLayerSpaceSpinBox_valueChanged(
double d )
578 mLegend->adjustBoxSize();
580 mLegend->endCommand();
584void QgsLayoutLegendWidget::mSymbolSpaceSpinBox_valueChanged(
double d )
592 mLegend->adjustBoxSize();
594 mLegend->endCommand();
598void QgsLayoutLegendWidget::mIconLabelSpaceSpinBox_valueChanged(
double d )
604 mLegend->adjustBoxSize();
606 mLegend->endCommand();
610void QgsLayoutLegendWidget::titleFontChanged()
616 mLegend->adjustBoxSize();
618 mLegend->endCommand();
622void QgsLayoutLegendWidget::groupFontChanged()
628 mLegend->adjustBoxSize();
630 mLegend->endCommand();
634void QgsLayoutLegendWidget::layerFontChanged()
640 mLegend->adjustBoxSize();
642 mLegend->endCommand();
646void QgsLayoutLegendWidget::itemFontChanged()
652 mLegend->adjustBoxSize();
654 mLegend->endCommand();
658void QgsLayoutLegendWidget::spaceBelowSubGroupHeadingChanged(
double space )
664 mLegend->adjustBoxSize();
666 mLegend->endCommand();
670void QgsLayoutLegendWidget::mFontColorButton_colorChanged(
const QColor &newFontColor )
678 mLegend->setFontColor( newFontColor );
680 mLegend->endCommand();
683void QgsLayoutLegendWidget::mBoxSpaceSpinBox_valueChanged(
double d )
688 mLegend->setBoxSpace( d );
689 mLegend->adjustBoxSize();
691 mLegend->endCommand();
695void QgsLayoutLegendWidget::mColumnSpaceSpinBox_valueChanged(
double d )
700 mLegend->setColumnSpace( d );
701 mLegend->adjustBoxSize();
703 mLegend->endCommand();
707void QgsLayoutLegendWidget::mLineSpacingSpinBox_valueChanged(
double d )
712 mLegend->setLineSpacing( d );
713 mLegend->adjustBoxSize();
715 mLegend->endCommand();
719static void _moveLegendNode(
QgsLayerTreeLayer *nodeLayer,
int legendNodeIndex,
int offset )
723 if ( legendNodeIndex < 0 || legendNodeIndex >= order.count() )
725 if ( legendNodeIndex + offset < 0 || legendNodeIndex + offset >= order.count() )
728 int id = order.takeAt( legendNodeIndex );
729 order.insert( legendNodeIndex + offset,
id );
735void QgsLayoutLegendWidget::mMoveDownToolButton_clicked()
742 const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
743 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
744 const QModelIndex parentIndex = sourceIndex.parent();
745 if ( !sourceIndex.isValid() || sourceIndex.row() == mItemTreeView->layerTreeModel()->rowCount( parentIndex ) - 1 )
750 if ( !node && !legendNode )
753 mLegend->beginCommand( tr(
"Moved Legend Item Down" ) );
767 mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() + 1, 0, parentIndex ) ) );
770 mLegend->endCommand();
773void QgsLayoutLegendWidget::mMoveUpToolButton_clicked()
780 const QModelIndex index = mItemTreeView->selectionModel()->currentIndex();
781 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( index );
782 const QModelIndex parentIndex = sourceIndex.parent();
783 if ( !sourceIndex.isValid() || sourceIndex.row() == 0 )
788 if ( !node && !legendNode )
791 mLegend->beginCommand( tr(
"Move Legend Item Up" ) );
805 mItemTreeView->setCurrentIndex( mItemTreeView->proxyModel()->mapFromSource( mItemTreeView->layerTreeModel()->index( sourceIndex.row() - 1, 0, parentIndex ) ) );
808 mLegend->endCommand();
811void QgsLayoutLegendWidget::mCheckBoxAutoUpdate_stateChanged(
int state,
bool userTriggered )
815 mLegend->beginCommand( tr(
"Change Auto Update" ) );
817 mLegend->setAutoUpdateModel( state == Qt::Checked );
819 mLegend->endCommand();
823 QList<QWidget *> widgets;
824 widgets << mMoveDownToolButton << mMoveUpToolButton << mRemoveToolButton << mAddToolButton
825 << mEditPushButton << mCountToolButton << mUpdateAllPushButton << mAddGroupToolButton
826 << mExpressionFilterButton;
827 for ( QWidget *w : std::as_const( widgets ) )
828 w->setEnabled( state != Qt::Checked );
830 if ( state == Qt::Unchecked )
833 selectedChanged( QModelIndex(), QModelIndex() );
837void QgsLayoutLegendWidget::composerMapChanged(
QgsLayoutItem *item )
853 mLegend->beginCommand( tr(
"Change Legend Map" ) );
854 mLegend->setLinkedMap( map );
856 mLegend->endCommand();
858 setLegendMapViewData();
862void QgsLayoutLegendWidget::mCheckboxResizeContents_toggled(
bool checked )
869 mLegend->beginCommand( tr(
"Resize Legend to Contents" ) );
870 mLegend->setResizeToContents( checked );
872 mLegend->adjustBoxSize();
874 mLegend->endCommand();
877void QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled(
bool state )
884 mLegend->beginCommand( tr(
"Change Legend Borders" ) );
885 mLegend->setDrawRasterStroke( state );
886 mLegend->adjustBoxSize();
888 mLegend->endCommand();
891void QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged(
double d )
899 mLegend->setRasterStrokeWidth( d );
900 mLegend->adjustBoxSize();
902 mLegend->endCommand();
905void QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged(
const QColor &newColor )
913 mLegend->setRasterStrokeColor( newColor );
915 mLegend->endCommand();
918void QgsLayoutLegendWidget::mAddToolButton_clicked()
925 QList< QgsMapLayer * > visibleLayers;
926 if ( mLegend->linkedMap() )
928 visibleLayers = mLegend->linkedMap()->layersToRender();
930 if ( visibleLayers.isEmpty() )
933 visibleLayers = mMapCanvas->layers(
true );
937 addDialog.setVisibleLayers( visibleLayers );
938 if ( addDialog.exec() == QDialog::Accepted )
940 const QList<QgsMapLayer *> layers = addDialog.selectedLayers();
941 if ( !layers.empty() )
943 mLegend->beginCommand( tr(
"Add Legend Item(s)" ) );
946 mLegend->model()->rootGroup()->addLayer( layer );
948 mLegend->updateLegend();
950 mLegend->endCommand();
955void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
962 QItemSelectionModel *selectionModel = mItemTreeView->selectionModel();
963 if ( !selectionModel )
968 mLegend->beginCommand( tr(
"Remove Legend Item" ) );
970 QList<QPersistentModelIndex> proxyIndexes;
971 const QModelIndexList viewSelection = selectionModel->selectedIndexes();
972 for (
const QModelIndex &index : viewSelection )
973 proxyIndexes << index;
976 QHash<QgsLayerTreeLayer *, QList<int> > nodesWithRemoval;
977 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
982 nodesWithRemoval[nodeLayer].append( _unfilteredLegendNodeIndex( legendNode ) );
985 for (
auto it = nodesWithRemoval.constBegin(); it != nodesWithRemoval.constEnd(); ++it )
987 QList<int> toDelete = it.value();
988 std::sort( toDelete.begin(), toDelete.end(), std::greater<int>() );
991 for (
int i : std::as_const( toDelete ) )
993 if ( i >= 0 && i < order.count() )
998 mItemTreeView->layerTreeModel()->refreshLayerLegend( it.key() );
1002 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
1004 if ( proxyIndex.isValid() && mItemTreeView->index2node( proxyIndex ) )
1006 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( proxyIndex );
1007 mLegend->model()->removeRow( sourceIndex.row(), sourceIndex.parent() );
1011 mLegend->updateLegend();
1013 mLegend->endCommand();
1016void QgsLayoutLegendWidget::mEditPushButton_clicked()
1023 QModelIndex idx = mItemTreeView->selectionModel()->currentIndex();
1024 mItemTreeView_doubleClicked( idx );
1027void QgsLayoutLegendWidget::resetLayerNodeToDefaults()
1035 QModelIndex currentIndex = mItemTreeView->currentIndex();
1036 if ( !currentIndex.isValid() )
1055 mLegend->beginCommand( tr(
"Update Legend" ) );
1058 for (
const QString &key : constCustomProperties )
1060 if ( key.startsWith( QLatin1String(
"legend/" ) ) )
1067 mItemTreeView->layerTreeModel()->refreshLayerLegend( nodeLayer );
1069 mLegend->updateLegend();
1071 mLegend->endCommand();
1074void QgsLayoutLegendWidget::mCountToolButton_clicked(
bool checked )
1081 const QList< QModelIndex > selectedIndexes = mItemTreeView->selectionModel()->selectedIndexes();
1082 if ( selectedIndexes.empty() )
1085 mLegend->beginCommand( tr(
"Update Legend" ) );
1086 for (
const QModelIndex &index : selectedIndexes )
1092 currentNode->
setCustomProperty( QStringLiteral(
"showFeatureCount" ), checked ? 1 : 0 );
1094 mLegend->updateFilterByMap();
1095 mLegend->adjustBoxSize();
1096 mLegend->endCommand();
1099void QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled(
bool checked )
1101 mLegend->beginCommand( tr(
"Update Legend" ) );
1102 mLegend->setLegendFilterByMapEnabled( checked );
1103 mLegend->adjustBoxSize();
1105 mLegend->endCommand();
1108void QgsLayoutLegendWidget::mExpressionFilterButton_toggled(
bool checked )
1116 QModelIndex currentIndex = mItemTreeView->currentIndex();
1117 if ( !currentIndex.isValid() )
1127 mExpressionFilterButton->expressionText(),
1130 mLegend->beginCommand( tr(
"Update Legend" ) );
1131 mLegend->updateFilterByMap();
1132 mLegend->adjustBoxSize();
1133 mLegend->endCommand();
1136void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
1143 QModelIndex currentIndex = mItemTreeView->currentIndex();
1144 if ( !currentIndex.isValid() )
1151 QgsLayerTreeLayer *layerNode = qobject_cast<QgsLayerTreeLayer *>( currentNode );
1157 QString currentExpression;
1159 currentExpression = QStringLiteral(
"@symbol_label" );
1169 QStringList highlighted;
1174 if ( !legendSymbols.empty() )
1180 highlighted << QStringLiteral(
"symbol_label" ) << QStringLiteral(
"symbol_id" );
1182 highlighted << QStringLiteral(
"symbol_count" );
1191 if ( expressiondialog.exec() )
1194 mLegend->beginCommand( tr(
"Update Legend" ) );
1196 mLegend->adjustBoxSize();
1197 mLegend->endCommand();
1200void QgsLayoutLegendWidget::mUpdateAllPushButton_clicked()
1205void QgsLayoutLegendWidget::mAddGroupToolButton_clicked()
1209 mLegend->beginCommand( tr(
"Add Legend Group" ) );
1210 mLegend->model()->rootGroup()->addGroup( tr(
"Group" ) );
1211 mLegend->updateLegend();
1213 mLegend->endCommand();
1217void QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled(
bool toggled )
1222 mLegend->setLegendFilterOutAtlas( toggled );
1228void QgsLayoutLegendWidget::updateLegend()
1232 mLegend->beginCommand( tr(
"Update Legend" ) );
1235 mLegend->setAutoUpdateModel(
true );
1236 mLegend->setAutoUpdateModel(
false );
1238 mLegend->endCommand();
1242void QgsLayoutLegendWidget::setReportTypeString(
const QString &
string )
1244 mFilterLegendByAtlasCheckBox->setText( tr(
"Only show items inside current %1 feature" ).arg(
string ) );
1245 mFilterLegendByAtlasCheckBox->setToolTip( tr(
"Filter out legend elements that lie outside the current %1 feature." ).arg(
string ) );
1248bool QgsLayoutLegendWidget::setNewItem(
QgsLayoutItem *item )
1258 mLegend = qobject_cast< QgsLayoutItemLegend * >( item );
1259 mItemPropertiesWidget->setItem( mLegend );
1263 mItemTreeView->setModel( mLegend->model() );
1272void QgsLayoutLegendWidget::blockAllSignals(
bool b )
1274 mTitleLineEdit->blockSignals( b );
1275 mTitleAlignCombo->blockSignals( b );
1276 mItemTreeView->blockSignals( b );
1277 mCheckBoxAutoUpdate->blockSignals( b );
1278 mMapComboBox->blockSignals( b );
1279 mFilterByMapCheckBox->blockSignals( b );
1280 mColumnCountSpinBox->blockSignals( b );
1281 mSplitLayerCheckBox->blockSignals( b );
1282 mEqualColumnWidthCheckBox->blockSignals( b );
1283 mSymbolWidthSpinBox->blockSignals( b );
1284 mSymbolHeightSpinBox->blockSignals( b );
1285 mMaxSymbolSizeSpinBox->blockSignals( b );
1286 mMinSymbolSizeSpinBox->blockSignals( b );
1287 mGroupSpaceSpinBox->blockSignals( b );
1288 mGroupIndentSpinBox->blockSignals( b );
1289 mSubgroupIndentSpinBox->blockSignals( b );
1290 mSpaceBelowGroupHeadingSpinBox->blockSignals( b );
1291 mGroupSideSpinBox->blockSignals( b );
1292 mSpaceBelowSubgroupHeadingSpinBox->blockSignals( b );
1293 mSubgroupSideSpinBox->blockSignals( b );
1294 mLayerSpaceSpinBox->blockSignals( b );
1295 mSymbolSpaceSpinBox->blockSignals( b );
1296 mSymbolSideSpaceSpinBox->blockSignals( b );
1297 mIconLabelSpaceSpinBox->blockSignals( b );
1298 mBoxSpaceSpinBox->blockSignals( b );
1299 mColumnSpaceSpinBox->blockSignals( b );
1300 mFontColorButton->blockSignals( b );
1301 mRasterStrokeGroupBox->blockSignals( b );
1302 mRasterStrokeColorButton->blockSignals( b );
1303 mRasterStrokeWidthSpinBox->blockSignals( b );
1304 mWmsLegendWidthSpinBox->blockSignals( b );
1305 mWmsLegendHeightSpinBox->blockSignals( b );
1306 mCheckboxResizeContents->blockSignals( b );
1307 mTitleSpaceBottomSpinBox->blockSignals( b );
1308 mFilterLegendByAtlasCheckBox->blockSignals( b );
1309 mTitleFontButton->blockSignals( b );
1310 mGroupFontButton->blockSignals( b );
1311 mLayerFontButton->blockSignals( b );
1312 mItemFontButton->blockSignals( b );
1313 mWrapCharLineEdit->blockSignals( b );
1314 mLineSpacingSpinBox->blockSignals( b );
1317void QgsLayoutLegendWidget::selectedChanged(
const QModelIndex ¤t,
const QModelIndex &previous )
1320 Q_UNUSED( previous )
1322 mLayerExpressionButton->setEnabled(
false );
1324 if ( mLegend && mLegend->autoUpdateModel() )
1335 mLayerExpressionButton->setEnabled(
true );
1339 mCountToolButton->setChecked(
false );
1340 mCountToolButton->setEnabled(
false );
1343 mExpressionFilterButton->blockSignals(
true );
1344 mExpressionFilterButton->setChecked(
false );
1345 mExpressionFilterButton->setEnabled(
false );
1346 mExpressionFilterButton->blockSignals(
false );
1357 mCountToolButton->setChecked( currentNode->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() );
1358 mCountToolButton->setEnabled(
true );
1359 mLayerExpressionButton->setEnabled(
true );
1363 mExpressionFilterButton->blockSignals(
true );
1364 mExpressionFilterButton->setExpressionText( expr );
1365 mExpressionFilterButton->setVectorLayer( vl );
1366 mExpressionFilterButton->setEnabled(
true );
1367 mExpressionFilterButton->setChecked( exprEnabled );
1368 mExpressionFilterButton->blockSignals(
false );
1371void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
1373 QAction *a = qobject_cast<QAction *>( sender() );
1374 if ( !a || !mItemTreeView->currentNode() )
1381void QgsLayoutLegendWidget::setLegendMapViewData()
1383 if ( mLegend->linkedMap() )
1387 measurementConverter.
setDpi( dpi );
1390 double mapUnitsPerPixelX = mLegend->linkedMap()->extent().width() / mapWidth;
1391 double mapUnitsPerPixelY = mLegend->linkedMap()->extent().height() / mapHeight;
1392 mLegend->model()->setLegendMapViewData( ( mapUnitsPerPixelX > mapUnitsPerPixelY ? mapUnitsPerPixelX : mapUnitsPerPixelY ), dpi, mLegend->linkedMap()->scale() );
1396void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
1400 mFilterLegendByAtlasCheckBox->setEnabled( atlas->enabled() && mLegend->layout()->reportContext().layer() && mLegend->layout()->reportContext().layer()->geometryType() ==
QgsWkbTypes::PolygonGeometry );
1404void QgsLayoutLegendWidget::mItemTreeView_doubleClicked(
const QModelIndex &idx )
1406 if ( !mLegend || !idx.isValid() )
1411 if ( mLegend->autoUpdateModel() )
1417 int originalIndex = -1;
1420 originalIndex = _originalLegendNodeIndex( legendNode );
1424 QgsLayoutLegendNodeWidget *widget =
new QgsLayoutLegendNodeWidget( mLegend, currentNode, legendNode, originalIndex );
1425 openPanel( widget );
1433QgsLayoutLegendMenuProvider::QgsLayoutLegendMenuProvider(
QgsLayerTreeView *view, QgsLayoutLegendWidget *w )
1438QMenu *QgsLayoutLegendMenuProvider::createContextMenu()
1440 if ( !mView->currentNode() )
1443 if ( mWidget->legend()->autoUpdateModel() )
1446 QMenu *menu =
new QMenu();
1450 menu->addAction( QObject::tr(
"Reset to Defaults" ), mWidget, &QgsLayoutLegendWidget::resetLayerNodeToDefaults );
1451 menu->addSeparator();
1456 QList<QgsLegendStyle::Style> lst;
1460 QAction *action = menu->addAction(
QgsLegendStyle::styleLabel( style ), mWidget, &QgsLayoutLegendWidget::setCurrentNodeStyleFromAction );
1461 action->setCheckable(
true );
1462 action->setChecked( currentStyle == style );
1463 action->setData(
static_cast< int >( style ) );
1478 , mOriginalLegendNodeIndex( originalLegendNodeIndex )
1481 setPanelTitle( tr(
"Legend Item Properties" ) );
1490 QString currentLabel;
1493 currentLabel = mLegendNode->data( Qt::EditRole ).toString();
1494 mColumnBreakBeforeCheckBox->setChecked( mLegendNode->columnBreak() );
1498 currentLabel = mLayer->name();
1499 QVariant v = mLayer->customProperty( QStringLiteral(
"legend/title-label" ) );
1501 currentLabel = v.toString();
1502 mColumnBreakBeforeCheckBox->setChecked( mLayer->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1504 mColumnSplitBehaviorComboBox->setCurrentIndex( mColumnSplitBehaviorComboBox->findData( mLayer->legendSplitBehavior() ) );
1509 mColumnBreakBeforeCheckBox->setChecked( mNode->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1512 mWidthSpinBox->setClearValue( 0, tr(
"Default" ) );
1513 mHeightSpinBox->setClearValue( 0, tr(
"Default" ) );
1514 mWidthSpinBox->setVisible( mLegendNode || mLayer );
1515 mHeightSpinBox->setVisible( mLegendNode || mLayer );
1516 mPatchGroup->setVisible( mLegendNode || mLayer );
1517 mPatchWidthLabel->setVisible( mLegendNode || mLayer );
1518 mPatchHeightLabel->setVisible( mLegendNode || mLayer );
1519 mCustomSymbolCheckBox->setVisible( mLegendNode || mLegend->model()->legendNodeEmbeddedInParent( mLayer ) );
1520 mColumnSplitLabel->setVisible( mLayer && !mLegendNode );
1521 mColumnSplitBehaviorComboBox->setVisible( mLayer && !mLegendNode );
1524 mWidthSpinBox->setValue( mLegendNode->userPatchSize().width() );
1525 mHeightSpinBox->setValue( mLegendNode->userPatchSize().height() );
1529 mWidthSpinBox->setValue( mLayer->patchSize().width() );
1530 mHeightSpinBox->setValue( mLayer->patchSize().height() );
1533 mCustomSymbolCheckBox->setChecked(
false );
1538 patchShape = symbolLegendNode->patchShape();
1540 std::unique_ptr< QgsSymbol > customSymbol( symbolLegendNode->customSymbol() ? symbolLegendNode->customSymbol()->clone() : nullptr );
1541 mCustomSymbolCheckBox->setChecked( customSymbol.get() );
1544 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1546 mCustomSymbolButton->setSymbol( customSymbol.release() );
1548 else if ( symbolLegendNode->symbol() )
1550 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1551 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1552 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1555 else if ( !mLegendNode && mLayer )
1557 patchShape = mLayer->patchShape();
1560 if (
QgsSymbol *customSymbol = symbolLegendNode->customSymbol() )
1562 mCustomSymbolCheckBox->setChecked(
true );
1563 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1565 mCustomSymbolButton->setSymbol( customSymbol->clone() );
1569 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1570 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1571 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1578 switch ( qobject_cast< QgsVectorLayer * >( mLayer->layer() )->geometryType() )
1593 mPatchShapeLabel->hide();
1594 mPatchShapeButton->hide();
1597 if ( !patchShape.
isNull() )
1598 mPatchShapeButton->setShape( patchShape );
1603 if ( symbolLegendNode->symbol() )
1605 mPatchShapeButton->setSymbolType( symbolLegendNode->symbol()->type() );
1609 mPatchShapeLabel->hide();
1610 mPatchShapeButton->hide();
1615 mPatchShapeLabel->hide();
1616 mPatchShapeButton->hide();
1621 mLabelGroup->hide();
1622 mColorRampLegendWidget->setSettings( colorRampNode->settings() );
1626 mColorRampLegendWidget->hide();
1639 mCustomSymbolCheckBox->hide();
1648 mLabelEdit->setPlainText( currentLabel );
1649 connect( mLabelEdit, &QPlainTextEdit::textChanged,
this, &QgsLayoutLegendNodeWidget::labelChanged );
1651 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutLegendNodeWidget::insertExpression );
1653 connect( mWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1654 connect( mHeightSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1656 connect( mCustomSymbolCheckBox, &QGroupBox::toggled,
this, &QgsLayoutLegendNodeWidget::customSymbolChanged );
1659 connect( mColumnBreakBeforeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendNodeWidget::columnBreakToggled );
1661 connect( mColumnSplitBehaviorComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutLegendNodeWidget::columnSplitChanged );
1665 connectChildPanel( mColorRampLegendWidget );
1668void QgsLayoutLegendNodeWidget::setDockMode(
bool dockMode )
1670 mColorRampLegendWidget->setDockMode( dockMode );
1674void QgsLayoutLegendNodeWidget::labelChanged()
1678 const QString label = mLabelEdit->toPlainText();
1683 else if ( mLegendNode )
1686 mLegend->model()->refreshLayerLegend( mLayer );
1690 mLayer->setCustomProperty( QStringLiteral(
"legend/title-label" ), label );
1694 embeddedNode->setUserLabel( QString() );
1697 mLegend->adjustBoxSize();
1698 mLegend->invalidateCache();
1700 mLegend->endCommand();
1703void QgsLayoutLegendNodeWidget::patchChanged()
1705 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1711 mLegend->model()->refreshLayerLegend( mLayer );
1715 mLayer->setPatchShape( shape );
1716 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1721 mLegend->model()->refreshLayerLegend( mLayer );
1724 mLegend->adjustBoxSize();
1726 mLegend->endCommand();
1729void QgsLayoutLegendNodeWidget::insertExpression()
1734 QString selText = mLabelEdit->textCursor().selectedText();
1737 selText = selText.replace( QChar( 0x2029 ), QChar(
'\n' ) );
1740 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
1741 selText = selText.mid( 2, selText.size() - 4 );
1744 QgsVectorLayer *layer = mLegend->layout() ? mLegend->layout()->reportContext().layer() :
nullptr;
1748 if ( mLayer && mLayer->layer() )
1754 << QStringLiteral(
"legend_column_count" )
1755 << QStringLiteral(
"legend_split_layers" )
1756 << QStringLiteral(
"legend_wrap_string" )
1757 << QStringLiteral(
"legend_filter_by_map" )
1758 << QStringLiteral(
"legend_filter_out_atlas" ) );
1762 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
1763 if ( exprDlg.exec() == QDialog::Accepted )
1765 QString expression = exprDlg.expressionText();
1766 if ( !expression.isEmpty() )
1768 mLegend->beginCommand( tr(
"Insert expression" ) );
1769 mLabelEdit->insertPlainText(
"[%" + expression +
"%]" );
1770 mLegend->endCommand();
1775void QgsLayoutLegendNodeWidget::sizeChanged(
double )
1777 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1778 const QSizeF size = QSizeF( mWidthSpinBox->value(), mHeightSpinBox->value() );
1783 mLegend->model()->refreshLayerLegend( mLayer );
1787 mLayer->setPatchSize( size );
1788 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1793 mLegend->model()->refreshLayerLegend( mLayer );
1796 mLegend->adjustBoxSize();
1798 mLegend->endCommand();
1801void QgsLayoutLegendNodeWidget::customSymbolChanged()
1803 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1805 if ( mCustomSymbolCheckBox->isChecked() )
1810 mLegend->model()->refreshLayerLegend( mLayer );
1814 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1819 mLegend->model()->refreshLayerLegend( mLayer );
1827 mLegend->model()->refreshLayerLegend( mLayer );
1831 const QList<QgsLayerTreeModelLegendNode *> layerLegendNodes = mLegend->model()->layerLegendNodes( mLayer,
false );
1836 mLegend->model()->refreshLayerLegend( mLayer );
1840 mLegend->adjustBoxSize();
1842 mLegend->endCommand();
1845void QgsLayoutLegendNodeWidget::colorRampLegendChanged()
1847 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1851 mLegend->model()->refreshLayerLegend( mLayer );
1853 mLegend->adjustBoxSize();
1855 mLegend->endCommand();
1858void QgsLayoutLegendNodeWidget::columnBreakToggled(
bool checked )
1860 mLegend->beginCommand( tr(
"Edit Legend Columns" ) );
1865 mLegend->model()->refreshLayerLegend( mLayer );
1869 mLayer->setCustomProperty( QStringLiteral(
"legend/column-break" ), QString( checked ?
'1' :
'0' ) );
1873 mNode->setCustomProperty( QStringLiteral(
"legend/column-break" ), QString( checked ?
'1' :
'0' ) );
1876 mLegend->adjustBoxSize();
1878 mLegend->endCommand();
1881void QgsLayoutLegendNodeWidget::columnSplitChanged()
1883 mLegend->beginCommand( tr(
"Edit Legend Columns" ) );
1885 if ( mLayer && !mLegendNode )
1890 mLegend->adjustBoxSize();
1892 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.
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.
@ UndoLegendLineSpacing
Legend line spacing.
@ UndoLegendBoxSpace
Legend box space.
@ UndoLegendRasterStrokeColor
Legend raster stroke color.
@ UndoLegendTitleFont
Legend title font.
@ UndoLegendFontColor
Legend font color.
@ 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.