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 )
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 )
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->updateFilterByMap();
820 mLegend->endCommand();
824 QList<QWidget *> widgets;
825 widgets << mMoveDownToolButton << mMoveUpToolButton << mRemoveToolButton << mAddToolButton
826 << mEditPushButton << mCountToolButton << mUpdateAllPushButton << mAddGroupToolButton
827 << mExpressionFilterButton;
828 for ( QWidget *w : std::as_const( widgets ) )
829 w->setEnabled( state != Qt::Checked );
831 if ( state == Qt::Unchecked )
834 selectedChanged( QModelIndex(), QModelIndex() );
838void QgsLayoutLegendWidget::composerMapChanged(
QgsLayoutItem *item )
854 mLegend->beginCommand( tr(
"Change Legend Map" ) );
855 mLegend->setLinkedMap( map );
856 mLegend->updateFilterByMap();
857 mLegend->endCommand();
859 setLegendMapViewData();
863void QgsLayoutLegendWidget::mCheckboxResizeContents_toggled(
bool checked )
870 mLegend->beginCommand( tr(
"Resize Legend to Contents" ) );
871 mLegend->setResizeToContents( checked );
873 mLegend->adjustBoxSize();
874 mLegend->updateFilterByMap();
875 mLegend->endCommand();
878void QgsLayoutLegendWidget::mRasterStrokeGroupBox_toggled(
bool state )
885 mLegend->beginCommand( tr(
"Change Legend Borders" ) );
886 mLegend->setDrawRasterStroke( state );
887 mLegend->adjustBoxSize();
889 mLegend->endCommand();
892void QgsLayoutLegendWidget::mRasterStrokeWidthSpinBox_valueChanged(
double d )
900 mLegend->setRasterStrokeWidth( d );
901 mLegend->adjustBoxSize();
903 mLegend->endCommand();
906void QgsLayoutLegendWidget::mRasterStrokeColorButton_colorChanged(
const QColor &newColor )
914 mLegend->setRasterStrokeColor( newColor );
916 mLegend->endCommand();
919void QgsLayoutLegendWidget::mAddToolButton_clicked()
926 QList< QgsMapLayer * > visibleLayers;
927 if ( mLegend->linkedMap() )
929 visibleLayers = mLegend->linkedMap()->layersToRender();
931 if ( visibleLayers.isEmpty() )
934 visibleLayers = mMapCanvas->layers(
true );
938 addDialog.setVisibleLayers( visibleLayers );
939 if ( addDialog.exec() == QDialog::Accepted )
941 const QList<QgsMapLayer *> layers = addDialog.selectedLayers();
942 if ( !layers.empty() )
944 mLegend->beginCommand( tr(
"Add Legend Item(s)" ) );
947 mLegend->model()->rootGroup()->addLayer( layer );
949 mLegend->updateLegend();
951 mLegend->endCommand();
956void QgsLayoutLegendWidget::mRemoveToolButton_clicked()
963 QItemSelectionModel *selectionModel = mItemTreeView->selectionModel();
964 if ( !selectionModel )
969 mLegend->beginCommand( tr(
"Remove Legend Item" ) );
971 QList<QPersistentModelIndex> proxyIndexes;
972 const QModelIndexList viewSelection = selectionModel->selectedIndexes();
973 for (
const QModelIndex &index : viewSelection )
974 proxyIndexes << index;
977 QHash<QgsLayerTreeLayer *, QList<int> > nodesWithRemoval;
978 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
983 nodesWithRemoval[nodeLayer].append( _unfilteredLegendNodeIndex(
legendNode ) );
986 for (
auto it = nodesWithRemoval.constBegin(); it != nodesWithRemoval.constEnd(); ++it )
988 QList<int> toDelete = it.value();
989 std::sort( toDelete.begin(), toDelete.end(), std::greater<int>() );
992 for (
int i : std::as_const( toDelete ) )
994 if ( i >= 0 && i < order.count() )
999 mItemTreeView->layerTreeModel()->refreshLayerLegend( it.key() );
1003 for (
const QPersistentModelIndex &proxyIndex : std::as_const( proxyIndexes ) )
1005 if ( proxyIndex.isValid() && mItemTreeView->index2node( proxyIndex ) )
1007 const QModelIndex sourceIndex = mItemTreeView->proxyModel()->mapToSource( proxyIndex );
1008 mLegend->model()->removeRow( sourceIndex.row(), sourceIndex.parent() );
1012 mLegend->updateLegend();
1014 mLegend->endCommand();
1017void QgsLayoutLegendWidget::mEditPushButton_clicked()
1024 QModelIndex idx = mItemTreeView->selectionModel()->currentIndex();
1025 mItemTreeView_doubleClicked( idx );
1028void QgsLayoutLegendWidget::resetLayerNodeToDefaults()
1036 QModelIndex currentIndex = mItemTreeView->currentIndex();
1037 if ( !currentIndex.isValid() )
1056 mLegend->beginCommand( tr(
"Update Legend" ) );
1059 for (
const QString &key : constCustomProperties )
1061 if ( key.startsWith( QLatin1String(
"legend/" ) ) )
1068 mItemTreeView->layerTreeModel()->refreshLayerLegend( nodeLayer );
1070 mLegend->updateLegend();
1072 mLegend->endCommand();
1075void QgsLayoutLegendWidget::mCountToolButton_clicked(
bool checked )
1082 const QList< QModelIndex > selectedIndexes = mItemTreeView->selectionModel()->selectedIndexes();
1083 if ( selectedIndexes.empty() )
1086 mLegend->beginCommand( tr(
"Update Legend" ) );
1087 for (
const QModelIndex &index : selectedIndexes )
1093 currentNode->
setCustomProperty( QStringLiteral(
"showFeatureCount" ), checked ? 1 : 0 );
1095 mLegend->updateFilterByMap();
1096 mLegend->adjustBoxSize();
1097 mLegend->endCommand();
1100void QgsLayoutLegendWidget::mFilterByMapCheckBox_toggled(
bool checked )
1102 mLegend->beginCommand( tr(
"Update Legend" ) );
1103 mLegend->setLegendFilterByMapEnabled( checked );
1104 mLegend->adjustBoxSize();
1106 mLegend->endCommand();
1109void QgsLayoutLegendWidget::mExpressionFilterButton_toggled(
bool checked )
1117 QModelIndex currentIndex = mItemTreeView->currentIndex();
1118 if ( !currentIndex.isValid() )
1128 mExpressionFilterButton->expressionText(),
1131 mLegend->beginCommand( tr(
"Update Legend" ) );
1132 mLegend->updateFilterByMap();
1133 mLegend->adjustBoxSize();
1134 mLegend->endCommand();
1137void QgsLayoutLegendWidget::mLayerExpressionButton_clicked()
1144 QModelIndex currentIndex = mItemTreeView->currentIndex();
1145 if ( !currentIndex.isValid() )
1152 QgsLayerTreeLayer *layerNode = qobject_cast<QgsLayerTreeLayer *>( currentNode );
1158 QString currentExpression;
1160 currentExpression = QStringLiteral(
"@symbol_label" );
1170 QStringList highlighted;
1175 if ( !legendSymbols.empty() )
1181 highlighted << QStringLiteral(
"symbol_label" ) << QStringLiteral(
"symbol_id" );
1183 highlighted << QStringLiteral(
"symbol_count" );
1192 if ( expressiondialog.exec() )
1195 mLegend->beginCommand( tr(
"Update Legend" ) );
1197 mLegend->adjustBoxSize();
1198 mLegend->endCommand();
1201void QgsLayoutLegendWidget::mUpdateAllPushButton_clicked()
1206void QgsLayoutLegendWidget::mAddGroupToolButton_clicked()
1210 mLegend->beginCommand( tr(
"Add Legend Group" ) );
1211 mLegend->model()->rootGroup()->addGroup( tr(
"Group" ) );
1212 mLegend->updateLegend();
1214 mLegend->endCommand();
1218void QgsLayoutLegendWidget::mFilterLegendByAtlasCheckBox_toggled(
bool toggled )
1223 mLegend->setLegendFilterOutAtlas( toggled );
1229void QgsLayoutLegendWidget::updateLegend()
1233 mLegend->beginCommand( tr(
"Update Legend" ) );
1236 mLegend->setAutoUpdateModel(
true );
1237 mLegend->setAutoUpdateModel(
false );
1238 mLegend->updateFilterByMap();
1239 mLegend->endCommand();
1243void QgsLayoutLegendWidget::setReportTypeString(
const QString &
string )
1245 mFilterLegendByAtlasCheckBox->setText( tr(
"Only show items inside current %1 feature" ).arg(
string ) );
1246 mFilterLegendByAtlasCheckBox->setToolTip( tr(
"Filter out legend elements that lie outside the current %1 feature." ).arg(
string ) );
1249bool QgsLayoutLegendWidget::setNewItem(
QgsLayoutItem *item )
1259 mLegend = qobject_cast< QgsLayoutItemLegend * >( item );
1260 mItemPropertiesWidget->setItem( mLegend );
1264 mItemTreeView->setModel( mLegend->model() );
1273void QgsLayoutLegendWidget::blockAllSignals(
bool b )
1275 mTitleLineEdit->blockSignals( b );
1276 mTitleAlignCombo->blockSignals( b );
1277 mItemTreeView->blockSignals( b );
1278 mCheckBoxAutoUpdate->blockSignals( b );
1279 mMapComboBox->blockSignals( b );
1280 mFilterByMapCheckBox->blockSignals( b );
1281 mColumnCountSpinBox->blockSignals( b );
1282 mSplitLayerCheckBox->blockSignals( b );
1283 mEqualColumnWidthCheckBox->blockSignals( b );
1284 mSymbolWidthSpinBox->blockSignals( b );
1285 mSymbolHeightSpinBox->blockSignals( b );
1286 mMaxSymbolSizeSpinBox->blockSignals( b );
1287 mMinSymbolSizeSpinBox->blockSignals( b );
1288 mGroupSpaceSpinBox->blockSignals( b );
1289 mGroupIndentSpinBox->blockSignals( b );
1290 mSubgroupIndentSpinBox->blockSignals( b );
1291 mSpaceBelowGroupHeadingSpinBox->blockSignals( b );
1292 mGroupSideSpinBox->blockSignals( b );
1293 mSpaceBelowSubgroupHeadingSpinBox->blockSignals( b );
1294 mSubgroupSideSpinBox->blockSignals( b );
1295 mLayerSpaceSpinBox->blockSignals( b );
1296 mSymbolSpaceSpinBox->blockSignals( b );
1297 mSymbolSideSpaceSpinBox->blockSignals( b );
1298 mIconLabelSpaceSpinBox->blockSignals( b );
1299 mBoxSpaceSpinBox->blockSignals( b );
1300 mColumnSpaceSpinBox->blockSignals( b );
1301 mFontColorButton->blockSignals( b );
1302 mRasterStrokeGroupBox->blockSignals( b );
1303 mRasterStrokeColorButton->blockSignals( b );
1304 mRasterStrokeWidthSpinBox->blockSignals( b );
1305 mWmsLegendWidthSpinBox->blockSignals( b );
1306 mWmsLegendHeightSpinBox->blockSignals( b );
1307 mCheckboxResizeContents->blockSignals( b );
1308 mTitleSpaceBottomSpinBox->blockSignals( b );
1309 mFilterLegendByAtlasCheckBox->blockSignals( b );
1310 mTitleFontButton->blockSignals( b );
1311 mGroupFontButton->blockSignals( b );
1312 mLayerFontButton->blockSignals( b );
1313 mItemFontButton->blockSignals( b );
1314 mWrapCharLineEdit->blockSignals( b );
1315 mLineSpacingSpinBox->blockSignals( b );
1318void QgsLayoutLegendWidget::selectedChanged(
const QModelIndex ¤t,
const QModelIndex &previous )
1321 Q_UNUSED( previous )
1323 mLayerExpressionButton->setEnabled(
false );
1325 if ( mLegend && mLegend->autoUpdateModel() )
1336 mLayerExpressionButton->setEnabled(
true );
1340 mCountToolButton->setChecked(
false );
1341 mCountToolButton->setEnabled(
false );
1344 mExpressionFilterButton->blockSignals(
true );
1345 mExpressionFilterButton->setChecked(
false );
1346 mExpressionFilterButton->setEnabled(
false );
1347 mExpressionFilterButton->blockSignals(
false );
1358 mCountToolButton->setChecked( currentNode->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() );
1359 mCountToolButton->setEnabled(
true );
1360 mLayerExpressionButton->setEnabled(
true );
1364 mExpressionFilterButton->blockSignals(
true );
1365 mExpressionFilterButton->setExpressionText( expr );
1366 mExpressionFilterButton->setVectorLayer( vl );
1367 mExpressionFilterButton->setEnabled(
true );
1368 mExpressionFilterButton->setChecked( exprEnabled );
1369 mExpressionFilterButton->blockSignals(
false );
1372void QgsLayoutLegendWidget::setCurrentNodeStyleFromAction()
1374 QAction *a = qobject_cast<QAction *>( sender() );
1375 if ( !a || !mItemTreeView->currentNode() )
1379 mLegend->updateFilterByMap();
1382void QgsLayoutLegendWidget::setLegendMapViewData()
1384 if ( mLegend->linkedMap() )
1388 measurementConverter.
setDpi( dpi );
1391 double mapUnitsPerPixelX = mLegend->linkedMap()->extent().width() / mapWidth;
1392 double mapUnitsPerPixelY = mLegend->linkedMap()->extent().height() / mapHeight;
1393 mLegend->model()->setLegendMapViewData( ( mapUnitsPerPixelX > mapUnitsPerPixelY ? mapUnitsPerPixelX : mapUnitsPerPixelY ), dpi, mLegend->linkedMap()->scale() );
1397void QgsLayoutLegendWidget::updateFilterLegendByAtlasButton()
1401 mFilterLegendByAtlasCheckBox->setEnabled( atlas->enabled() && mLegend->layout()->reportContext().layer() && mLegend->layout()->reportContext().layer()->geometryType() ==
QgsWkbTypes::PolygonGeometry );
1405void QgsLayoutLegendWidget::mItemTreeView_doubleClicked(
const QModelIndex &idx )
1407 if ( !mLegend || !idx.isValid() )
1412 if ( mLegend->autoUpdateModel() )
1418 int originalIndex = -1;
1421 originalIndex = _originalLegendNodeIndex(
legendNode );
1425 QgsLayoutLegendNodeWidget *widget =
new QgsLayoutLegendNodeWidget( mLegend, currentNode,
legendNode, originalIndex );
1426 openPanel( widget );
1434QgsLayoutLegendMenuProvider::QgsLayoutLegendMenuProvider(
QgsLayerTreeView *view, QgsLayoutLegendWidget *w )
1439QMenu *QgsLayoutLegendMenuProvider::createContextMenu()
1441 if ( !mView->currentNode() )
1444 if ( mWidget->legend()->autoUpdateModel() )
1447 QMenu *menu =
new QMenu();
1451 menu->addAction( QObject::tr(
"Reset to Defaults" ), mWidget, &QgsLayoutLegendWidget::resetLayerNodeToDefaults );
1452 menu->addSeparator();
1457 QList<QgsLegendStyle::Style> lst;
1461 QAction *action = menu->addAction(
QgsLegendStyle::styleLabel( style ), mWidget, &QgsLayoutLegendWidget::setCurrentNodeStyleFromAction );
1462 action->setCheckable(
true );
1463 action->setChecked( currentStyle == style );
1464 action->setData(
static_cast< int >( style ) );
1479 , mOriginalLegendNodeIndex( originalLegendNodeIndex )
1482 setPanelTitle( tr(
"Legend Item Properties" ) );
1491 QString currentLabel;
1494 currentLabel = mLegendNode->data( Qt::EditRole ).toString();
1495 mColumnBreakBeforeCheckBox->setChecked( mLegendNode->columnBreak() );
1499 currentLabel = mLayer->name();
1500 QVariant v = mLayer->customProperty( QStringLiteral(
"legend/title-label" ) );
1502 currentLabel = v.toString();
1503 mColumnBreakBeforeCheckBox->setChecked( mLayer->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1505 mColumnSplitBehaviorComboBox->setCurrentIndex( mColumnSplitBehaviorComboBox->findData( mLayer->legendSplitBehavior() ) );
1510 mColumnBreakBeforeCheckBox->setChecked( mNode->customProperty( QStringLiteral(
"legend/column-break" ) ).toInt() );
1513 mWidthSpinBox->setClearValue( 0, tr(
"Default" ) );
1514 mHeightSpinBox->setClearValue( 0, tr(
"Default" ) );
1515 mWidthSpinBox->setVisible( mLegendNode || mLayer );
1516 mHeightSpinBox->setVisible( mLegendNode || mLayer );
1517 mPatchGroup->setVisible( mLegendNode || mLayer );
1518 mPatchWidthLabel->setVisible( mLegendNode || mLayer );
1519 mPatchHeightLabel->setVisible( mLegendNode || mLayer );
1520 mCustomSymbolCheckBox->setVisible( mLegendNode || mLegend->model()->legendNodeEmbeddedInParent( mLayer ) );
1521 mColumnSplitLabel->setVisible( mLayer && !mLegendNode );
1522 mColumnSplitBehaviorComboBox->setVisible( mLayer && !mLegendNode );
1525 mWidthSpinBox->setValue( mLegendNode->userPatchSize().width() );
1526 mHeightSpinBox->setValue( mLegendNode->userPatchSize().height() );
1530 mWidthSpinBox->setValue( mLayer->patchSize().width() );
1531 mHeightSpinBox->setValue( mLayer->patchSize().height() );
1534 mCustomSymbolCheckBox->setChecked(
false );
1539 patchShape = symbolLegendNode->patchShape();
1541 std::unique_ptr< QgsSymbol > customSymbol( symbolLegendNode->customSymbol() ? symbolLegendNode->customSymbol()->clone() :
nullptr );
1542 mCustomSymbolCheckBox->setChecked( customSymbol.get() );
1545 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1546 mCustomSymbolButton->setSymbolType( customSymbol->type() );
1547 mCustomSymbolButton->setSymbol( customSymbol.release() );
1549 else if ( symbolLegendNode->symbol() )
1551 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1552 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1553 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1556 else if ( !mLegendNode && mLayer )
1558 patchShape = mLayer->patchShape();
1561 if (
QgsSymbol *customSymbol = symbolLegendNode->customSymbol() )
1563 mCustomSymbolCheckBox->setChecked(
true );
1564 mPatchShapeButton->setPreviewSymbol( customSymbol->clone() );
1566 mCustomSymbolButton->setSymbol( customSymbol->clone() );
1570 mPatchShapeButton->setPreviewSymbol( symbolLegendNode->symbol()->clone() );
1571 mCustomSymbolButton->setSymbolType( symbolLegendNode->symbol()->type() );
1572 mCustomSymbolButton->setSymbol( symbolLegendNode->symbol()->clone() );
1579 switch ( qobject_cast< QgsVectorLayer * >( mLayer->layer() )->geometryType() )
1594 mPatchShapeLabel->hide();
1595 mPatchShapeButton->hide();
1598 if ( !patchShape.
isNull() )
1599 mPatchShapeButton->setShape( patchShape );
1604 if ( symbolLegendNode->symbol() )
1606 mPatchShapeButton->setSymbolType( symbolLegendNode->symbol()->type() );
1610 mPatchShapeLabel->hide();
1611 mPatchShapeButton->hide();
1616 mPatchShapeLabel->hide();
1617 mPatchShapeButton->hide();
1622 mLabelGroup->hide();
1623 mColorRampLegendWidget->setSettings( colorRampNode->settings() );
1627 mColorRampLegendWidget->hide();
1640 mCustomSymbolCheckBox->hide();
1649 mLabelEdit->setPlainText( currentLabel );
1650 connect( mLabelEdit, &QPlainTextEdit::textChanged,
this, &QgsLayoutLegendNodeWidget::labelChanged );
1652 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutLegendNodeWidget::insertExpression );
1654 connect( mWidthSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1655 connect( mHeightSpinBox, qOverload<double>( &QgsDoubleSpinBox::valueChanged ),
this, &QgsLayoutLegendNodeWidget::sizeChanged );
1657 connect( mCustomSymbolCheckBox, &QGroupBox::toggled,
this, &QgsLayoutLegendNodeWidget::customSymbolChanged );
1660 connect( mColumnBreakBeforeCheckBox, &QCheckBox::toggled,
this, &QgsLayoutLegendNodeWidget::columnBreakToggled );
1662 connect( mColumnSplitBehaviorComboBox, qOverload<int>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutLegendNodeWidget::columnSplitChanged );
1666 connectChildPanel( mColorRampLegendWidget );
1669void QgsLayoutLegendNodeWidget::setDockMode(
bool dockMode )
1671 mColorRampLegendWidget->setDockMode( dockMode );
1675void QgsLayoutLegendNodeWidget::labelChanged()
1679 const QString label = mLabelEdit->toPlainText();
1684 else if ( mLegendNode )
1687 mLegend->model()->refreshLayerLegend( mLayer );
1691 mLayer->setCustomProperty( QStringLiteral(
"legend/title-label" ), label );
1695 embeddedNode->setUserLabel( QString() );
1698 mLegend->adjustBoxSize();
1699 mLegend->updateFilterByMap();
1700 mLegend->endCommand();
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();
1725 mLegend->updateFilterByMap();
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();
1797 mLegend->updateFilterByMap();
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();
1841 mLegend->updateFilterByMap();
1842 mLegend->endCommand();
1845void QgsLayoutLegendNodeWidget::colorRampLegendChanged()
1847 mLegend->beginCommand( tr(
"Edit Legend Item" ) );
1851 mLegend->model()->refreshLayerLegend( mLayer );
1853 mLegend->adjustBoxSize();
1854 mLegend->updateFilterByMap();
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();
1877 mLegend->updateFilterByMap();
1878 mLegend->endCommand();
1881void QgsLayoutLegendNodeWidget::columnSplitChanged()
1883 mLegend->beginCommand( tr(
"Edit Legend Columns" ) );
1885 if ( mLayer && !mLegendNode )
1890 mLegend->adjustBoxSize();
1891 mLegend->updateFilterByMap();
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.