QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
42 , mEmbeddedInParent( false )
48 return qobject_cast<QgsLayerTreeModel *>( parent() );
53 return Qt::ItemIsEnabled;
88 double itemHeight = std::max(
static_cast< double >( ctx && ctx->
patchSize.height() > 0 ? ctx->
patchSize.height() : settings.
symbolSize().height() ), textHeight );
99 const QString text =
data( Qt::DisplayRole ).toString();
100 json[ QStringLiteral(
"title" ) ] = text;
106 QIcon symbolIcon =
data( Qt::DecorationRole ).value<QIcon>();
107 if ( symbolIcon.isNull() )
114 size.setWidth( ctx->
patchSize.width( ) );
116 size.setHeight( ctx->
patchSize.height( ) );
125 symbolIcon.paint( ctx->
painter,
127 static_cast< int >( ctx->
top + ( itemHeight - size.height() ) / 2 ),
128 static_cast< int >( size.width() ),
129 static_cast< int >( size.height() ) );
133 symbolIcon.paint( ctx->
painter,
134 static_cast< int >( ctx->
columnRight - size.width() ),
135 static_cast< int >( ctx->
top + ( itemHeight - size.height() ) / 2 ),
136 static_cast< int >( size.width() ),
137 static_cast< int >( size.height() ) );
146 const QIcon icon =
data( Qt::DecorationRole ).value<QIcon>();
148 return QJsonObject();
150 const QImage image( icon.pixmap( settings.
symbolSize().width(), settings.
symbolSize().height() ).toImage() );
151 QByteArray byteArray;
152 QBuffer buffer( &byteArray );
153 image.save( &buffer,
"PNG" );
154 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
157 json[ QStringLiteral(
"icon" ) ] = base64;
163 QSizeF labelSize( 0, 0 );
173 labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * ( settings.
lineSpacing() + textDescent );
175 double labelXMin = 0.0;
176 double labelXMax = 0.0;
205 if ( labelSize.height() < symbolSize.height() )
206 labelY += symbolSize.height() / 2 - labelSize.height() / 2;
208 labelY += textHeight;
211 for ( QStringList::ConstIterator itemPart = lines.constBegin(); itemPart != lines.constEnd(); ++itemPart )
214 labelSize.rwidth() = std::max( lineWidth,
double( labelSize.width() ) );
222 settings.
drawText( ctx->
painter, labelXMin, labelY, *itemPart, symbolLabelFont );
226 settings.
drawText( ctx->
painter, labelXMax - lineWidth, labelY, *itemPart, symbolLabelFont );
229 case Qt::AlignHCenter:
230 settings.
drawText( ctx->
painter, labelXMin + ( labelXMax - labelXMin - lineWidth ) / 2.0, labelY, *itemPart, symbolLabelFont );
234 if ( itemPart != ( lines.end() - 1 ) )
235 labelY += textDescent + settings.
lineSpacing() + textHeight;
247 , mSymbolUsesMapUnits( false )
254 connect( nodeLayer, &QObject::destroyed,
this, [ = ]() {
mLayerNode =
nullptr; } );
256 if (
auto *lSymbol = mItem.
symbol() )
263 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
265 return Qt::ItemIsEnabled;
297 if ( !mTextOnSymbolLabel.isEmpty() && context )
301 int wInt = ceil( w ), hInt = ceil( h );
302 if ( wInt > minSz.width() ) minSz.setWidth( wInt );
303 if ( hInt > minSz.height() ) minSz.setHeight( hInt );
320 QString layerName = legendlabel.isNull() ?
mLayerNode->
name() : legendlabel.toString();
347 return mCustomSymbol.get();
352 mCustomSymbol.reset(
symbol );
360 std::unique_ptr< QgsSymbol > s(
symbol );
362 if ( !vlayer || !vlayer->
renderer() )
387 if ( !vlayer || !vlayer->
renderer() )
391 for (
const auto &item : symbolList )
405 if (
auto *lModel =
model() )
406 lModel->legendMapViewData( &mupp, &dpi, &scale );
412 std::unique_ptr<QgsRenderContext> context = qgis::make_unique<QgsRenderContext>( );
413 context->setScaleFactor( dpi / 25.4 );
414 context->setRendererScale( scale );
418 return context.release();
421 void QgsSymbolLegendNode::checkAll(
bool state )
424 if ( !vlayer || !vlayer->
renderer() )
428 for (
const auto &item : symbolList )
439 if ( role == Qt::DisplayRole )
443 else if ( role == Qt::EditRole )
447 else if ( role == Qt::DecorationRole )
449 if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
457 if ( !mTextOnSymbolLabel.isEmpty() && context )
459 QPainter painter( &pix );
460 painter.setRenderHint( QPainter::Antialiasing );
461 context->setPainter( &painter );
462 QFontMetricsF fm( mTextOnSymbolTextFormat.
scaledFont( *context ) );
463 qreal yBaselineVCenter = ( mIconSize.height() + fm.ascent() - fm.descent() ) / 2;
465 QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
470 pix = QPixmap( mIconSize );
471 pix.fill( Qt::transparent );
478 else if ( role == Qt::CheckStateRole )
484 if ( !vlayer || !vlayer->
renderer() )
503 if ( role != Qt::CheckStateRole )
510 if ( !vlayer || !vlayer->
renderer() )
535 std::unique_ptr< QgsRenderContext > tempRenderContext;
541 tempRenderContext = qgis::make_unique< QgsRenderContext >();
544 tempRenderContext->setScaleFactor( settings.
dpi() / 25.4 );
545 tempRenderContext->setRendererScale( settings.
mapScale() );
549 tempRenderContext->setForceVectorOutput(
true );
550 tempRenderContext->setPainter( ctx ? ctx->
painter :
nullptr );
555 tempRenderContext->setExpressionContext( expContext );
556 context = tempRenderContext.get();
562 double height = desiredHeight;
563 double width = desiredWidth;
566 double widthOffset = 0;
567 double heightOffset = 0;
574 double size = markerSymbol->size( *context ) / context->
scaleFactor();
580 if ( minMaxSizeSymbol )
582 s = minMaxSizeSymbol.get();
587 if ( width < desiredWidth )
589 widthOffset = ( desiredWidth - width ) / 2.0;
591 if ( height < desiredHeight )
593 heightOffset = ( desiredHeight - height ) / 2.0;
598 double currentYCoord = ctx->
top + ( itemHeight - desiredHeight ) / 2;
606 opacity =
static_cast<int >( std::round( 255 * vectorLayer->opacity() ) );
615 p->translate( ctx->
columnLeft + widthOffset, currentYCoord + heightOffset );
618 p->translate( ctx->
columnRight - widthOffset - width, currentYCoord + heightOffset );
622 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
627 if ( opacity != 255 && useAdvancedEffects )
633 const QSize symbolSize(
static_cast< int >( std::round( width * dotsPerMM ) ),
static_cast<int >( std::round( height * dotsPerMM ) ) );
634 const QSize tempImageSize( symbolSize.width() + maxBleed * 2, symbolSize.height() + maxBleed * 2 );
635 QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
636 tempImage.fill( Qt::transparent );
637 QPainter imagePainter( &tempImage );
641 imagePainter.translate( maxBleed, maxBleed );
643 imagePainter.translate( -maxBleed, -maxBleed );
646 imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
647 imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
650 p->drawImage( -maxBleed, -maxBleed, tempImage );
654 s->
drawPreviewIcon( p, QSize(
static_cast< int >( std::round( width * dotsPerMM ) ),
static_cast< int >( std::round( height * dotsPerMM ) ) ), context,
false,
nullptr, &
patchShape );
657 if ( !mTextOnSymbolLabel.isEmpty() )
659 QFontMetricsF fm( mTextOnSymbolTextFormat.
scaledFont( *context ) );
660 qreal yBaselineVCenter = ( height * dotsPerMM + fm.ascent() - fm.descent() ) / 2;
662 QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
666 return QSizeF( std::max( width + 2 * widthOffset,
static_cast< double >( desiredWidth ) ),
667 std::max( height + 2 * heightOffset,
static_cast< double >( desiredHeight ) ) );
672 const QgsSymbol *s = mCustomSymbol ? mCustomSymbol.get() : mItem.
symbol();
675 return QJsonObject();
697 QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );
701 opacity = ( 255 * vectorLayer->opacity() );
703 if ( opacity != 255 )
706 painter.begin( &img );
707 painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
708 painter.fillRect( pix.rect(), QColor( 0, 0, 0, opacity ) );
712 QByteArray byteArray;
713 QBuffer buffer( &byteArray );
714 img.save( &buffer,
"PNG" );
715 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
718 json[ QStringLiteral(
"icon" ) ] = base64;
731 if ( mSymbolUsesMapUnits )
739 void QgsSymbolLegendNode::updateLabel()
748 if ( showFeatureCount && vl )
751 mLabel += QStringLiteral(
" [%1]" ).arg( count != -1 ? QLocale().toString( count ) : tr(
"N/A" ) );
771 if ( label.isEmpty() )
775 else if ( mLabel.contains(
"[%" ) )
787 else if ( label.contains(
"[%" ) )
822 if ( role == Qt::DisplayRole || role == Qt::EditRole )
824 else if ( role == Qt::DecorationRole )
843 if ( role == Qt::DecorationRole )
845 return QPixmap::fromImage( mImage );
847 else if ( role == Qt::SizeHintRole )
849 return mImage.size();
856 Q_UNUSED( itemHeight )
865 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
870 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
879 QByteArray byteArray;
880 QBuffer buffer( &byteArray );
881 mImage.save( &buffer,
"PNG" );
882 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
885 json[ QStringLiteral(
"icon" ) ] = base64;
900 if ( role == Qt::DecorationRole )
907 else if ( role == Qt::DisplayRole || role == Qt::EditRole )
922 if ( ctx->
patchSize.width() < size.width() )
923 offsetX = ( size.width() - ctx->
patchSize.width() ) / 2.0;
928 size.setHeight( ctx->
patchSize.height() );
934 QColor itemColor = mColor;
938 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
940 ctx->
painter->setBrush( itemColor );
947 pen.setJoinStyle( Qt::MiterJoin );
952 ctx->
painter->setPen( Qt::NoPen );
959 ctx->
painter->drawRect( QRectF( ctx->
columnLeft + offsetX, ctx->
top + ( itemHeight - size.height() ) / 2,
960 size.width(), size.height() ) );
964 ctx->
painter->drawRect( QRectF( ctx->
columnRight - size.width() - offsetX, ctx->
top + ( itemHeight - size.height() ) / 2,
965 size.width(), size.height() ) );
974 QImage img = QImage( settings.
symbolSize().toSize(), QImage::Format_ARGB32 );
975 img.fill( Qt::transparent );
977 QPainter painter( &img );
978 painter.setRenderHint( QPainter::Antialiasing );
980 QColor itemColor = mColor;
984 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
986 painter.setBrush( itemColor );
993 pen.setJoinStyle( Qt::MiterJoin );
994 painter.setPen( pen );
998 painter.setPen( Qt::NoPen );
1001 painter.drawRect( QRectF( 0, 0, settings.
symbolSize().width(), settings.
symbolSize().height() ) );
1003 QByteArray byteArray;
1004 QBuffer buffer( &byteArray );
1005 img.save( &buffer,
"PNG" );
1006 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
1009 json[ QStringLiteral(
"icon" ) ] = base64;
1021 QImage QgsWmsLegendNode::getLegendGraphic()
const
1023 if ( ! mValid && ! mFetcher )
1038 Q_ASSERT( ! mFetcher );
1054 if ( role == Qt::DecorationRole )
1056 return QPixmap::fromImage( getLegendGraphic() );
1058 else if ( role == Qt::SizeHintRole )
1060 return getLegendGraphic().size();
1067 Q_UNUSED( itemHeight )
1080 QRectF( QPointF( 0, 0 ), mImage.size() ) );
1083 case Qt::AlignRight:
1089 QRectF( QPointF( 0, 0 ), mImage.size() ) );
1098 QByteArray byteArray;
1099 QBuffer buffer( &byteArray );
1100 mImage.save( &buffer,
"PNG" );
1101 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
1104 json[ QStringLiteral(
"icon" ) ] = base64;
1108 QImage QgsWmsLegendNode::renderMessage(
const QString &msg )
const
1110 const int fontHeight = 10;
1111 const int margin = fontHeight / 2;
1112 const int nlines = 1;
1114 const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
1115 QImage image( w, h, QImage::Format_ARGB32_Premultiplied );
1117 painter.begin( &image );
1118 painter.setPen( QColor( 255, 0, 0 ) );
1119 painter.setFont( QFont( QStringLiteral(
"Chicago" ), fontHeight ) );
1120 painter.fillRect( 0, 0, w, h, QColor( 255, 255, 255 ) );
1121 painter.drawText( 0, margin + fontHeight, msg );
1128 void QgsWmsLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
1130 QString msg = QStringLiteral(
"Downloading... %1/%2" ).arg( cur ).arg( tot );
1131 mImage = renderMessage( msg );
1135 void QgsWmsLegendNode::getLegendGraphicErrored(
const QString & )
1148 void QgsWmsLegendNode::getLegendGraphicFinished(
const QImage &image )
1153 if ( ! image.isNull() )
1155 if ( image != mImage )
1188 if ( role == Qt::DecorationRole )
1191 return QPixmap::fromImage( mImage );
1193 else if ( role == Qt::SizeHintRole )
1196 return mImage.size();
1205 std::unique_ptr< QgsRenderContext > tempRenderContext;
1210 tempRenderContext = qgis::make_unique< QgsRenderContext >();
1213 tempRenderContext->setScaleFactor( settings.
dpi() / 25.4 );
1214 tempRenderContext->setRendererScale( settings.
mapScale() );
1216 tempRenderContext->setMapToPixel(
QgsMapToPixel( 1 / ( settings.
mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
1217 tempRenderContext->setForceVectorOutput(
true );
1218 tempRenderContext->setPainter( ctx ? ctx->
painter :
nullptr );
1225 tempRenderContext->setExpressionContext( expContext );
1226 context = tempRenderContext.get();
1243 double labelXOffset;
1247 context->
painter()->restore();
1256 void QgsDataDefinedSizeLegendNode::cacheImage()
const
1258 if ( mImage.isNull() )
1264 Q_ASSERT( context );
1265 context->setScaleFactor( 96 / 25.4 );
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
QgsSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItem &item, QObject *parent=nullptr)
Constructor for QgsSymbolLegendNode.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
@ Symbol
Symbol icon (excluding label)
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
QgsExpressionContextScope * createExpressionContextScope() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
QString symbolLabel() const
Label of the symbol, user defined label will be used, otherwise will default to the label made by QGI...
QgsWmsLegendNode(QgsLayerTreeLayer *nodeLayer, QObject *parent=nullptr)
Constructor for QgsWmsLegendNode.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
void setCustomSymbol(QgsSymbol *symbol)
Sets the node's custom symbol.
Q_DECL_DEPRECATED bool useAdvancedEffects() const
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
QFont scaledFont(const QgsRenderContext &context, double scaleFactor=1.0) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
void setSymbol(QgsSymbol *s)
Sets the symbol of the item.
QgsExpressionContext & expressionContext()
Gets the expression context.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
double maximumSymbolSize() const
Returns the maximum symbol size (in mm).
Q_DECL_DEPRECATED double mmPerMapUnit() const
double columnRight
Right side of current legend column.
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true, VAlignment vAlignment=AlignTop)
Draws text within a rectangle using the specified settings.
void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx) override
Entry point called from QgsLegendRenderer to do the rendering.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
QImage collapsedLegendImage(QgsRenderContext &context, const QColor &backgroundColor=Qt::transparent, double paddingMM=1) const
Returns output image that would be shown in the legend. Returns invalid image if legend is not config...
QSizeF patchSize
Symbol patch size to render for the node.
virtual QSizeF drawSymbolText(const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize) const
Draws label on the right side of the item.
void checkAllItems()
Checks all items belonging to the same layer as this node.
@ AlignCenter
Center align.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
virtual void setUserPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
Q_DECL_DEPRECATED double mapScale() const
Returns the legend map scale.
Contains information about the context of a rendering operation.
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
@ RenderMillimeters
Millimeters.
QJsonObject exportToJson(const QgsLegendSettings &settings, const QgsRenderContext &context)
Entry point called from QgsLegendRenderer to do the rendering in a JSON object.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
QgsLegendPatchShape patchShape
The patch shape to render for the node.
QString name() const override
Returns the layer's name.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Abstract base class for all rendered symbols.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
QgsDataDefinedSizeLegendNode(QgsLayerTreeLayer *nodeLayer, const QgsDataDefinedSizeLegend &settings, QObject *parent=nullptr)
Construct the node using QgsDataDefinedSizeLegend as definition of the node's appearance.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
@ SymbolLabel
Symbol label (excluding icon)
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
~QgsDataDefinedSizeLegendNode() override
QString ruleKey() const
Returns unique identifier of the rule for identification of the item within renderer.
QgsLayerTreeModel * model() const
Returns pointer to model owning this legend node.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
Represents a patch shape for use in map legends.
Q_DECL_DEPRECATED int dpi() const
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
virtual QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const
Adds a symbol in base64 string within a JSON object with the key "icon".
static double textWidth(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, QFontMetricsF *fontMetrics=nullptr)
Returns the width of a text based on a given format.
void sizeChanged()
Emitted when the size of this node changes.
virtual Qt::ItemFlags flags() const
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
static int scaleIconSize(int standardSize)
Scales an layer tree model icon size to compensate for display pixel density, making the icon size hi...
virtual ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx)
Entry point called from QgsLegendRenderer to do the rendering.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
#define Q_NOWARN_DEPRECATED_POP
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
@ Point
Text at point of origin draw mode.
static QPixmap symbolPreviewPixmap(const QgsSymbol *symbol, QSize size, int padding=0, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *shape=nullptr)
Returns a pixmap preview for a color ramp.
void progress(qint64 received, qint64 total)
Emitted to report progress.
QgsRasterSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QColor &color, const QString &label, QObject *parent=nullptr)
Constructor for QgsRasterSymbolLegendNode.
void setPatchShape(const QgsLegendPatchShape &shape)
Sets the symbol patch shape to use when rendering the legend node symbol.
bool setData(const QVariant &value, int role) override
Sets some data associated with the item. Default implementation does nothing and returns false.
QgsLayerTreeModelLegendNode(QgsLayerTreeLayer *nodeL, QObject *parent=nullptr)
Construct the node with pointer to its parent layer node.
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
Raster renderer pipe that applies colors to a raster.
A marker symbol type, for rendering Point and MultiPoint geometries.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
double minimumSymbolSize() const
Returns the minimum symbol size (in mm).
virtual QSizeF userPatchSize() const
Returns the user (overridden) size for the legend node.
Qt::Alignment alignment() const
Returns the alignment for the legend component.
QgsImageLegendNode(QgsLayerTreeLayer *nodeLayer, const QImage &img, QObject *parent=nullptr)
Constructor for QgsImageLegendNode.
Layer tree node points to a map layer.
const QgsMapSettings * legendFilterMapSettings() const
Returns the current map settings used for the current legend filter (or nullptr if none is enabled)
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Returns a new image downloader for the raster legend.
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
void setTextColor(const QColor &color)
Sets text color for rendering of labels - only valid for collapsed legend.
Qt::ItemFlags flags() const override
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
@ ParentRuleKeyRole
Rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2....
static double textHeight(const QgsRenderContext &context, const QgsTextFormat &format, const QStringList &textLines, DrawMode mode=Point, QFontMetricsF *fontMetrics=nullptr)
Returns the height of a text based on a given format.
Represents a raster layer.
Scoped object for saving and restoring a QPainter object's state.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
virtual void setEmbeddedInParent(bool embedded)
QString label() const
Returns text label.
Single scope for storing variables and functions for use within a QgsExpressionContext.
void setRendererScale(double scale)
Sets the renderer map scale.
double maxSiblingSymbolWidth
Largest symbol width, considering all other sibling legend components associated with the current com...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
virtual bool setData(const QVariant &value, int role)
Sets some data associated with the item. Default implementation does nothing and returns false.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
void toggleAllItems()
Toggle all items belonging to the same layer as this node.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
QgsSymbol * symbol() const
Returns associated symbol. May be nullptr.
QgsRenderContext * createTemporaryRenderContext() const
Returns a temporary context or nullptr if legendMapViewData are not valid.
Perform transforms between map coordinates and device coordinates.
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr, bool selected=false, const QgsExpressionContext *expressionContext=nullptr, const QgsLegendPatchShape *patchShape=nullptr)
Draws an icon of the symbol that occupies an area given by size using the specified painter.
Represents a vector layer which manages a vector based data sets.
QFont font() const
Returns the font used for rendering this legend component.
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.
QgsLegendPatchShape mPatchShape
bool isCheckable() const
Returns whether the item is user-checkable - whether renderer supports enabling/disabling it.
static QgsSymbol * restrictedSizeSymbol(const QgsSymbol *s, double minSize, double maxSize, QgsRenderContext *context, double &width, double &height)
Creates a new symbol with size restricted to min/max size if original size is out of min/max range.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
double top
Top y-position of legend item.
void setEmbeddedInParent(bool embedded) override
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
void finish(const QImage &legend)
Emitted when the download completes.
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
double fontHeightCharacterMM(const QFont &font, QChar c) const
Returns the font height of a character in millimeters.
SymbolType type() const
Returns the symbol's type.
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
QString evaluateLabel(const QgsExpressionContext &context=QgsExpressionContext(), const QString &label=QString())
Evaluates and returns the text label of the current node.
@ Antialiasing
Use antialiasing while drawing.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QPainter * painter
Painter.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
QColor fontColor() const
Returns the font color used for legend items.
double lineSpacing() const
Returns the line spacing to use between lines of legend text.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
static QRect nonTransparentImageRect(const QImage &image, QSize minSize=QSize(), bool center=false)
Calculates the non-transparent region of an image.
QSize minimumIconSize() const
Calculates the minimum icon size to prevent cropping.
double fontDescentMillimeters(const QFont &font) const
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCA...
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
QPainter * painter()
Returns the destination QPainter for the render operation.
QSizeF patchSize() const
Returns the user (overridden) size for the legend node.
Single variable definition for use within a QgsExpressionContextScope.
QgsSymbol * customSymbol() const
Returns the node's custom symbol.
void drawCollapsedLegend(QgsRenderContext &context, QSizeF *outputSize SIP_OUT=nullptr, double *labelXOffset SIP_OUT=nullptr) const
Draw the legend if using LegendOneNodeForAll and optionally output size of the legend and x offset of...
The QgsMapSettings class contains configuration for rendering of the map.
QList< QgsLegendSymbolItem > QgsLegendSymbolList
@ RuleKeyRole
Rule key of the node (QString)
#define Q_NOWARN_DEPRECATED_PUSH
static QString replaceExpressionText(const QString &action, const QgsExpressionContext *context, const QgsDistanceArea *distanceArea=nullptr)
This function replaces each expression between [% and %] in the string with the result of its evaluat...
void dataChanged()
Emitted on internal data change so the layer tree model can forward the signal to views.
Base class for raster data providers.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QString parentRuleKey() const
Key of the parent legend node.
double columnLeft
Left side of current legend column.
QgsLayerTreeLayer * mLayerNode
void uncheckAllItems()
Unchecks all items belonging to the same layer as this node.
void error(const QString &msg)
Emitted when an error occurs.
Flags flags() const
Returns combination of flags used for rendering.
QgsSimpleLegendNode(QgsLayerTreeLayer *nodeLayer, const QString &label, const QIcon &icon=QIcon(), QObject *parent=nullptr, const QString &key=QString())
Constructor for QgsSimpleLegendNode.
const QgsSymbol * symbol() const
Returns the symbol used by the legend node.
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.
QgsFeatureRenderer * renderer()
Returns renderer.
double margin(Side side)
Returns the margin (in mm) for the specified side of the component.
void setSymbol(QgsSymbol *symbol)
Sets the symbol to be used by the legend node.
void setFont(const QFont &font)
Sets font used for rendering of labels - only valid for collapsed legend.
QStringList evaluateItemText(const QString &text, const QgsExpressionContext &context) const
Splits a string using the wrap char taking into account handling empty wrap char which means no wrapp...
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...