34 #include <QDomDocument> 35 #include <QDomElement> 41 , mLegendModel( new
QgsLegendModel( layout->project()->layerTreeRoot(), this ) )
43 #if 0 //no longer required? 44 connect( &layout->atlasComposition(), &QgsAtlasComposition::renderEnded,
this, &QgsLayoutItemLegend::onAtlasEnded );
47 mTitle = mSettings.
title();
87 if ( mFilterAskedForUpdate )
89 mFilterAskedForUpdate =
false;
90 doUpdateFilterByMap();
93 int dpi = painter->device()->logicalDpiX();
94 double dotsPerMM = dpi / 25.4;
106 QSizeF mapSizePixels = QSizeF( mMap->rect().width() * dotsPerMM, mMap->rect().height() * dotsPerMM );
112 mInitialMapScaleCalculated =
true;
115 legendRenderer.
setLegendSize( mForceResize && mSizeToContents ? QSize() : rect().size() );
118 if ( mSizeToContents )
121 QSizeF size = legendRenderer.minimumSize( &context );
124 mForceResize =
false;
130 else if ( size.height() > rect().height() || size.width() > rect().width() )
133 QSizeF targetSize = rect().size();
134 if ( size.height() > targetSize.height() )
135 targetSize.setHeight( size.height() );
136 if ( size.width() > targetSize.width() )
137 targetSize.setWidth( size.width() );
150 if ( !mMapUuid.isEmpty() )
152 setLinkedMap( qobject_cast< QgsLayoutItemMap * >(
mLayout->itemByUuid( mMapUuid,
true ) ) );
170 painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
172 if ( !mSizeToContents )
175 QRectF thisPaintRect = QRectF( 0, 0, rect().width(), rect().height() );
176 painter->setClipRect( thisPaintRect );
192 if ( !mSizeToContents )
195 if ( !mInitialMapScaleCalculated )
206 QSizeF size = legendRenderer.
minimumSize( &context );
207 QgsDebugMsg( QStringLiteral(
"width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
208 if ( size.isValid() )
218 mSizeToContents = enabled;
223 return mSizeToContents;
226 void QgsLayoutItemLegend::setCustomLayerTree(
QgsLayerTree *rootGroup )
228 mLegendModel->setRootGroup( rootGroup ? rootGroup : (
mLayout ?
mLayout->project()->layerTreeRoot() : nullptr ) );
230 mCustomLayerTree.reset( rootGroup );
239 setCustomLayerTree( autoUpdate ?
nullptr :
mLayout->project()->layerTreeRoot()->clone() );
244 void QgsLayoutItemLegend::nodeCustomPropertyChanged(
QgsLayerTreeNode *,
const QString & )
256 return !mCustomLayerTree;
261 mLegendFilterByMap = enabled;
270 if (
mLayout &&
id().isEmpty() )
273 mLayout->itemsModel()->updateItemDisplayName(
this );
293 return mSettings.
rstyle( s );
298 return mSettings.
style( s );
497 legendElem.setAttribute( QStringLiteral(
"title" ), mTitle );
498 legendElem.setAttribute( QStringLiteral(
"titleAlignment" ), QString::number( static_cast< int >( mSettings.
titleAlignment() ) ) );
499 legendElem.setAttribute( QStringLiteral(
"columnCount" ), QString::number( mColumnCount ) );
500 legendElem.setAttribute( QStringLiteral(
"splitLayer" ), QString::number( mSettings.
splitLayer() ) );
501 legendElem.setAttribute( QStringLiteral(
"equalColumnWidth" ), QString::number( mSettings.
equalColumnWidth() ) );
503 legendElem.setAttribute( QStringLiteral(
"boxSpace" ), QString::number( mSettings.
boxSpace() ) );
504 legendElem.setAttribute( QStringLiteral(
"columnSpace" ), QString::number( mSettings.
columnSpace() ) );
506 legendElem.setAttribute( QStringLiteral(
"symbolWidth" ), QString::number( mSettings.
symbolSize().width() ) );
507 legendElem.setAttribute( QStringLiteral(
"symbolHeight" ), QString::number( mSettings.
symbolSize().height() ) );
509 legendElem.setAttribute( QStringLiteral(
"symbolAlignment" ), mSettings.
symbolAlignment() );
511 legendElem.setAttribute( QStringLiteral(
"symbolAlignment" ), mSettings.
symbolAlignment() );
512 legendElem.setAttribute( QStringLiteral(
"lineSpacing" ), QString::number( mSettings.
lineSpacing() ) );
514 legendElem.setAttribute( QStringLiteral(
"rasterBorder" ), mSettings.
drawRasterStroke() );
516 legendElem.setAttribute( QStringLiteral(
"rasterBorderWidth" ), QString::number( mSettings.
rasterStrokeWidth() ) );
518 legendElem.setAttribute( QStringLiteral(
"wmsLegendWidth" ), QString::number( mSettings.
wmsLegendSize().width() ) );
519 legendElem.setAttribute( QStringLiteral(
"wmsLegendHeight" ), QString::number( mSettings.
wmsLegendSize().height() ) );
520 legendElem.setAttribute( QStringLiteral(
"wrapChar" ), mSettings.
wrapChar() );
521 legendElem.setAttribute( QStringLiteral(
"fontColor" ), mSettings.
fontColor().name() );
523 legendElem.setAttribute( QStringLiteral(
"resizeToContents" ), mSizeToContents );
527 legendElem.setAttribute( QStringLiteral(
"map_uuid" ), mMap->
uuid() );
530 QDomElement legendStyles = doc.createElement( QStringLiteral(
"styles" ) );
531 legendElem.appendChild( legendStyles );
539 if ( mCustomLayerTree )
542 mCustomLayerTree->writeXml( legendElem, context );
545 if ( mLegendFilterByMap )
547 legendElem.setAttribute( QStringLiteral(
"legendFilterByMap" ), QStringLiteral(
"1" ) );
549 legendElem.setAttribute( QStringLiteral(
"legendFilterByAtlas" ), mFilterOutAtlas ? QStringLiteral(
"1" ) : QStringLiteral(
"0" ) );
557 mTitle = itemElem.attribute( QStringLiteral(
"title" ) );
559 if ( !itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).isEmpty() )
561 mSettings.
setTitleAlignment( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral(
"titleAlignment" ) ).toInt() ) );
563 int colCount = itemElem.attribute( QStringLiteral(
"columnCount" ), QStringLiteral(
"1" ) ).toInt();
564 if ( colCount < 1 ) colCount = 1;
565 mColumnCount = colCount;
567 mSettings.
setSplitLayer( itemElem.attribute( QStringLiteral(
"splitLayer" ), QStringLiteral(
"0" ) ).toInt() == 1 );
568 mSettings.
setEqualColumnWidth( itemElem.attribute( QStringLiteral(
"equalColumnWidth" ), QStringLiteral(
"0" ) ).toInt() == 1 );
570 QDomNodeList stylesNodeList = itemElem.elementsByTagName( QStringLiteral(
"styles" ) );
571 if ( !stylesNodeList.isEmpty() )
573 QDomNode stylesNode = stylesNodeList.at( 0 );
574 for (
int i = 0; i < stylesNode.childNodes().size(); i++ )
576 QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
578 style.
readXml( styleElem, doc );
579 QString name = styleElem.attribute( QStringLiteral(
"name" ) );
593 fontClr.setNamedColor( itemElem.attribute( QStringLiteral(
"fontColor" ), QStringLiteral(
"#000000" ) ) );
597 mSettings.
setBoxSpace( itemElem.attribute( QStringLiteral(
"boxSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
598 mSettings.
setColumnSpace( itemElem.attribute( QStringLiteral(
"columnSpace" ), QStringLiteral(
"2.0" ) ).toDouble() );
600 mSettings.
setSymbolSize( QSizeF( itemElem.attribute( QStringLiteral(
"symbolWidth" ), QStringLiteral(
"7.0" ) ).toDouble(), itemElem.attribute( QStringLiteral(
"symbolHeight" ), QStringLiteral(
"14.0" ) ).toDouble() ) );
601 mSettings.
setSymbolAlignment( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral(
"symbolAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() ) );
603 mSettings.
setWmsLegendSize( QSizeF( itemElem.attribute( QStringLiteral(
"wmsLegendWidth" ), QStringLiteral(
"50" ) ).toDouble(), itemElem.attribute( QStringLiteral(
"wmsLegendHeight" ), QStringLiteral(
"25" ) ).toDouble() ) );
604 mSettings.
setLineSpacing( itemElem.attribute( QStringLiteral(
"lineSpacing" ), QStringLiteral(
"1.0" ) ).toDouble() );
606 mSettings.
setDrawRasterStroke( itemElem.attribute( QStringLiteral(
"rasterBorder" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" ) );
608 mSettings.
setRasterStrokeWidth( itemElem.attribute( QStringLiteral(
"rasterBorderWidth" ), QStringLiteral(
"0" ) ).toDouble() );
610 mSettings.
setWrapChar( itemElem.attribute( QStringLiteral(
"wrapChar" ) ) );
612 mSizeToContents = itemElem.attribute( QStringLiteral(
"resizeToContents" ), QStringLiteral(
"1" ) ) != QLatin1String(
"0" );
615 mLegendFilterByMap = itemElem.attribute( QStringLiteral(
"legendFilterByMap" ), QStringLiteral(
"0" ) ).toInt();
618 if ( !itemElem.attribute( QStringLiteral(
"map_uuid" ) ).isEmpty() )
620 mMapUuid = itemElem.attribute( QStringLiteral(
"map_uuid" ) );
623 setupMapConnections( mMap,
false );
626 mFilterOutAtlas = itemElem.attribute( QStringLiteral(
"legendFilterByAtlas" ), QStringLiteral(
"0" ) ).toInt();
629 QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree" ) );
630 if ( layerTreeElem.isNull() )
631 layerTreeElem = itemElem.firstChildElement( QStringLiteral(
"layer-tree-group" ) );
633 if ( !layerTreeElem.isNull() )
637 tree->resolveReferences(
mLayout->project(), true );
638 setCustomLayerTree( tree.release() );
641 setCustomLayerTree(
nullptr );
648 if ( !
id().isEmpty() )
654 QString text = mSettings.
title();
655 if ( text.isEmpty() )
657 return tr(
"<Legend>" );
659 if ( text.length() > 25 )
661 return tr(
"%1…" ).arg( text.left( 25 ) );
670 void QgsLayoutItemLegend::setupMapConnections(
QgsLayoutItemMap *map,
bool connectSlots )
677 disconnect( map, &QObject::destroyed,
this, &QgsLayoutItemLegend::invalidateCurrentMap );
684 connect( map, &QObject::destroyed,
this, &QgsLayoutItemLegend::invalidateCurrentMap );
695 setupMapConnections( mMap,
false );
702 setupMapConnections( mMap,
true );
709 void QgsLayoutItemLegend::invalidateCurrentMap()
718 bool forceUpdate =
false;
734 if ( ok && cols >= 0 )
750 void QgsLayoutItemLegend::updateFilterByMapAndRedraw()
755 void QgsLayoutItemLegend::mapLayerStyleOverridesChanged()
761 if ( mLegendFilterByMap )
770 const QList< QgsLayerTreeLayer * > layers = mLegendModel->rootGroup()->findLayers();
772 mLegendModel->refreshLayerLegend( nodeLayer );
784 mFilterAskedForUpdate =
true;
790 void QgsLayoutItemLegend::doUpdateFilterByMap()
795 mLegendModel->setLayerStyleOverrides( QMap<QString, QString>() );
800 if ( mMap && ( mLegendFilterByMap || filterByExpression || mInAtlas ) )
802 double dpi =
mLayout->renderContext().dpi();
806 QSizeF size( requestRectangle.
width(), requestRectangle.
height() );
814 filterPolygon =
mLayout->reportContext().currentGeometry( mMap->
crs() );
816 mLegendModel->setLegendFilter( &ms, mInAtlas || mLegendFilterByMap, filterPolygon,
true );
819 mLegendModel->setLegendFilterByMap(
nullptr );
826 mFilterOutAtlas = doFilter;
831 return mFilterOutAtlas;
834 void QgsLayoutItemLegend::onAtlasFeature()
836 if ( !
mLayout->reportContext().feature().isValid() )
838 mInAtlas = mFilterOutAtlas;
842 void QgsLayoutItemLegend::onAtlasEnded()
884 , mLayoutLegend( layout )
892 , mLayoutLegend( layout )
904 if ( nodeLayer && ( role == Qt::DisplayRole || role == Qt::EditRole ) )
910 name = nodeLayer->
customProperty( QStringLiteral(
"legend/title-label" ) ).toString();
911 if ( name.isEmpty() )
912 name = nodeLayer->
name();
913 if ( name.isEmpty() )
914 name = node->
customProperty( QStringLiteral(
"legend/title-label" ) ).toString();
915 if ( name.isEmpty() )
917 if ( nodeLayer->
customProperty( QStringLiteral(
"showFeatureCount" ), 0 ).toInt() )
921 name += QStringLiteral(
" [%1]" ).arg( vlayer->
featureCount() );
926 bool evaluate = vlayer ? !nodeLayer->
labelExpression().isEmpty() :
false;
928 if ( evaluate || name.contains(
"[%" ) )
943 const QList<QgsLayerTreeModelLegendNode *> legendnodes = layerLegendNodes( nodeLayer,
false );
944 if ( legendnodes.count() > 1 )
949 symnode->evaluateLabel( expressionContext );
952 else if (
QgsSymbolLegendNode *symnode = qobject_cast<QgsSymbolLegendNode *>( legendnodes.first() ) )
953 name = symnode->evaluateLabel( expressionContext );
969 QList<QgsLayerTreeModelLegendNode *> QgsLegendModel::layerLegendNodes(
QgsLayerTreeLayer *nodeLayer,
bool skipNodeEmbeddedInParent )
const 971 if ( !
mLegend.contains( nodeLayer ) )
972 return QList<QgsLayerTreeModelLegendNode *>();
975 QList<QgsLayerTreeModelLegendNode *> lst( data.
activeNodes );
981 void QgsLegendModel::forceRefresh()
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
void setColumnSpace(double spacing)
Sets the legend column spacing.
bool splitLayer() const
Returns whether the legend items from a single layer can be split over multiple columns.
void setWrapChar(const QString &t)
The class is used as a container of context for various read/write operations on other objects...
void setEqualColumnWidth(bool equalize)
Sets whether column widths should be equalized.
void setLegendSize(QSizeF s)
Sets the preferred resulting legend size.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QMap< QgsLayerTreeLayer *, LayerLegendData > mLegend
Per layer data about layer's legend nodes.
Single variable definition for use within a QgsExpressionContextScope.
void setFontColor(const QColor &color)
Sets the legend font color.
void setLegendFilterOutAtlas(bool doFilter)
When set to true, during an atlas rendering, it will filter out legend elements where features are ou...
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
A rectangle specified with double values.
void setTitle(const QString &title)
Sets the legend title.
void setEqualColumnWidth(bool s)
double lineSpacing() const
Returns the spacing in-between lines in layout units.
double boxSpace() const
Returns the legend box space.
QgsVectorLayerFeatureCounter * countSymbolFeatures()
Count features for symbols.
Item model implementation based on layer tree model for layout legend.
virtual QString name() const =0
Returns name of the node.
double columnSpace() const
Returns the legend column spacing.
void setBoxSpace(double s)
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
void setMmPerMapUnit(double mmPerMapUnit)
void setSplitLayer(bool enabled)
Sets whether the legend items from a single layer can be split over multiple columns.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
Base class for graphical items within a QgsLayout.
void setSymbolWidth(double width)
Sets the legend symbol width.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
Item must be placed in its own individual layer.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
int type() const override
void setSymbolSize(QSizeF s)
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, double dpi, bool includeLayerSettings) const
Returns map settings that will be used for drawing of the map.
void extentChanged()
Emitted when the map's extent changes.
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
QFont font() const
Returns the font used for rendering this legend component.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
bool legendFilterByMapEnabled() const
Find out whether legend items are filtered to show just the ones visible in the associated map...
QgsLayerTreeModelLegendNode * embeddedNodeInParent
A legend node that is not displayed separately, its icon is instead shown within the layer node's ite...
Contains detailed styling information relating to how a layout legend should be rendered.
void updateFilterByMap(bool redraw=true)
Updates the legend content when filtered by map.
A geometry is the spatial representation of a feature.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QString title() const
Returns the legend title.
void setStyle(QgsLegendStyle::Style component, const QgsLegendStyle &style)
Sets the style of component to style for the legend.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
void setLegendFilterByMapEnabled(bool enabled)
Set whether legend items should be filtered to show just the ones visible in the associated map...
bool resizeToContents() const
Returns whether the legend should automatically resize to fit its contents.
double rasterStrokeWidth() const
Returns the stroke width (in layout units) for the stroke drawn around raster symbol items...
int columnCount() const
Returns the legend column count.
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
bool equalColumnWidth() const
Returns whether column widths should be equalized.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
QgsLegendModel(QgsLayerTree *rootNode, QObject *parent=nullptr, QgsLayoutItemLegend *layout=nullptr)
Construct the model based on the given layer tree.
Allow check boxes for legend nodes (if supported by layer's legend)
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
The QgsMapSettings class contains configuration for rendering of the map.
static QString encodeColor(const QColor &color)
QString displayName() const override
Gets item display name.
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
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QSizeF wmsLegendSize() const
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns style.
void adjustBoxSize()
Sets the legend's item bounds to fit the whole legend content.
virtual void invalidateCache()
Forces a deferred update of any cached image the item uses.
QgsRectangle extent() const
Returns the current map extent.
Layout graphical items for displaying a map.
void setFont(const QFont &font)
Sets the font used for rendering this legend component.
QString name() const override
Returns the layer's name.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
double symbolWidth() const
Returns the legend symbol width.
Namespace with helper functions for layer tree operations.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
QColor fontColor() const
Returns the legend font color.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Handles preparing a paint surface for the layout item and painting the item's content.
double scale() const
Returns the calculated map scale.
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
double width() const
Returns the width of the rectangle.
static QgsLayerTreeModelLegendNode * index2legendNode(const QModelIndex &index)
Returns legend node for given index.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setMapScale(double scale)
Sets the legend map scale.
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
double symbolHeight() const
Returns the legend symbol height.
QVariant data(const QModelIndex &index, int role) const override
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable legend style.
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items...
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
double mapUnitsToLayoutUnits() const
Returns the conversion factor from map units to layout units.
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
QPointer< QgsLayout > mLayout
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...
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
Symbol icon (excluding label)
void setTitle(const QString &t)
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
This class is a base class for nodes in a layer tree.
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
void setMargin(Side side, double margin)
Sets the margin (in mm) for the specified side of the component.
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns legend style.
QString id() const
Returns the item's ID name.
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
QgsLayoutItemLegend(QgsLayout *layout)
Constructor for QgsLayoutItemLegend, with the specified parent layout.
void setLineSpacing(double spacing)
Sets the spacing in-between multiple lines.
QgsRectangle requestedExtent() const
Calculates the extent to request and the yShift of the top-left point in case of rotation.
void setFontColor(const QColor &c)
Single scope for storing variables and functions for use within a QgsExpressionContext.
static bool hasLegendFilterExpression(const QgsLayerTreeGroup &group)
Test if one of the layers in a group has an expression filter.
void refreshLegend()
Emitted to refresh the legend.
void setColumnSpace(double s)
void setFlag(Flag f, bool on=true)
Enable or disable a model flag.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void updateLegend()
Updates the model and all legend entries.
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
void setWrapString(const QString &string)
Sets the legend text wrapping string.
Style
Component of legends which can be styled.
void setStyleFont(QgsLegendStyle::Style component, const QFont &font)
Sets the style font for a legend component.
void setResizeToContents(bool enabled)
Sets whether the legend should automatically resize to fit its contents.
virtual void redraw()
Triggers a redraw (update) of the item.
void setAutoUpdateModel(bool autoUpdate)
Sets whether the legend content should auto update to reflect changes in the project's layer tree...
void setColumnCount(int count)
Sets the legend column count.
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
QSizeF symbolSize() const
Contains settings and helpers relating to a render of a QgsLayoutItem.
void setLineSpacing(double s)
QgsMapLayer * layer() const
Returns the map layer associated with this node.
void readXml(const QDomElement &elem, const QDomDocument &doc)
Reads the component's style definition from an XML element.
static QgsLayoutItemLegend * create(QgsLayout *layout)
Returns a new legend item for the specified layout.
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string...
void setWmsLegendSize(QSizeF s)
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable style.
Contains information about the context of a rendering operation.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
void setUseAdvancedEffects(bool use)
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to associate with the legend.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Returns layer tree node for given index.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
void setStyle(QgsLegendStyle::Style s, const QgsLegendStyle &style)
Enable advanced effects such as blend modes.
QString wrapString() const
Returns the legend text wrapping string.
static QgsLayerTree * readXml(QDomElement &element, const QgsReadWriteContext &context)
Load the layer tree from an XML element.
double wmsLegendHeight() const
Returns the WMS legend height.
bool equalColumnWidth() const
void setStyleMargin(QgsLegendStyle::Style component, double margin)
Set the margin for a legend component.
void setColumnCount(int c)
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
double columnSpace() const
virtual QString uuid() const
Returns the item identification string.
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
bool autoUpdateModel() const
Returns whether the legend content should auto update to reflect changes in the project's layer tree...
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties) override
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
void writeXml(const QString &name, QDomElement &elem, QDomDocument &doc) const
Writes the component's style definition to an XML element.
void setWmsLegendHeight(double height)
Sets the WMS legend height.
QSizeF minimumSize(QgsRenderContext *renderContext=nullptr)
Runs the layout algorithm and returns the minimum size required for the legend.
QList< QgsLayerTreeModelLegendNode * > activeNodes
Active legend nodes.
void layerStyleOverridesChanged()
Emitted when layer style overrides are changed...
void setWmsLegendWidth(double width)
Sets the WMS legend width.
Item overrides the default layout item painting method.
Flags flags() const
Returns OR-ed combination of model flags.
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
A layout item subclass for map legends.
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
void setSymbolHeight(double height)
Sets the legend symbol height.
Symbol label (excluding icon)
double lineSpacing() const
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
void setBoxSpace(double space)
Sets the legend box space.
void changed()
Emitted when the object's properties change.
QgsLayoutItem::Flags itemFlags() const override
Returns the item's flags, which indicate how the item behaves.
bool legendFilterOutAtlas() const
Returns whether to filter out legend elements outside of the current atlas feature.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Represents a vector layer which manages a vector based data sets.
DataDefinedProperty
Data defined properties for different item types.
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer...
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
QIcon icon() const override
Returns the item's icon.
double wmsLegendWidth() const
Returns the WMS legend width.
Allow reordering with drag'n'drop.
void setSplitLayer(bool s)
static QColor decodeColor(const QString &str)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
double height() const
Returns the height of the rectangle.
Layer tree node points to a map layer.
The QgsLegendRenderer class handles automatic layout and rendering of legend.
QMap< QString, QString > layerStyleOverrides() const
Returns stored overrides of styles for layers.
Structure that stores all data associated with one map layer.
QFont styleFont(QgsLegendStyle::Style component) const
Returns the font settings for a legend component.