QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
42 , mEmbeddedInParent( false )
48 return qobject_cast<QgsLayerTreeModel *>( parent() );
53 return Qt::ItemIsEnabled;
79 double itemHeight = std::max(
static_cast< double >( ctx && ctx->
patchSize.height() > 0 ? ctx->
patchSize.height() : settings.
symbolSize().height() ), textHeight );
90 const QString text =
data( Qt::DisplayRole ).toString();
91 json[ QStringLiteral(
"title" ) ] = text;
97 QIcon symbolIcon =
data( Qt::DecorationRole ).value<QIcon>();
98 if ( symbolIcon.isNull() )
105 size.setWidth( ctx->
patchSize.width( ) );
107 size.setHeight( ctx->
patchSize.height( ) );
116 symbolIcon.paint( ctx->
painter,
118 static_cast< int >( ctx->
top + ( itemHeight - size.height() ) / 2 ),
119 static_cast< int >( size.width() ),
120 static_cast< int >( size.height() ) );
124 symbolIcon.paint( ctx->
painter,
125 static_cast< int >( ctx->
columnRight - size.width() ),
126 static_cast< int >( ctx->
top + ( itemHeight - size.height() ) / 2 ),
127 static_cast< int >( size.width() ),
128 static_cast< int >( size.height() ) );
137 const QIcon icon =
data( Qt::DecorationRole ).value<QIcon>();
139 return QJsonObject();
141 const QImage image( icon.pixmap( settings.
symbolSize().width(), settings.
symbolSize().height() ).toImage() );
142 QByteArray byteArray;
143 QBuffer buffer( &byteArray );
144 image.save( &buffer,
"PNG" );
145 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
148 json[ QStringLiteral(
"icon" ) ] = base64;
154 QSizeF labelSize( 0, 0 );
164 labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * ( settings.
lineSpacing() + textDescent );
166 double labelXMin = 0.0;
167 double labelXMax = 0.0;
196 if ( labelSize.height() < symbolSize.height() )
197 labelY += symbolSize.height() / 2 - labelSize.height() / 2;
199 labelY += textHeight;
202 for ( QStringList::ConstIterator itemPart = lines.constBegin(); itemPart != lines.constEnd(); ++itemPart )
205 labelSize.rwidth() = std::max( lineWidth,
double( labelSize.width() ) );
213 settings.
drawText( ctx->
painter, labelXMin, labelY, *itemPart, symbolLabelFont );
217 settings.
drawText( ctx->
painter, labelXMax - lineWidth, labelY, *itemPart, symbolLabelFont );
220 case Qt::AlignHCenter:
221 settings.
drawText( ctx->
painter, labelXMin + ( labelXMax - labelXMin - lineWidth ) / 2.0, labelY, *itemPart, symbolLabelFont );
225 if ( itemPart != ( lines.end() - 1 ) )
226 labelY += textDescent + settings.
lineSpacing() + textHeight;
238 , mSymbolUsesMapUnits( false )
245 connect( nodeLayer, &QObject::destroyed,
this, [ = ]() {
mLayerNode =
nullptr; } );
254 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
256 return Qt::ItemIsEnabled;
288 if ( !mTextOnSymbolLabel.isEmpty() && context )
292 int wInt = ceil( w ), hInt = ceil( h );
293 if ( wInt > minSz.width() ) minSz.setWidth( wInt );
294 if ( hInt > minSz.height() ) minSz.setHeight( hInt );
311 QString layerName = legendlabel.isNull() ?
mLayerNode->
name() : legendlabel.toString();
338 return mCustomSymbol.get();
343 mCustomSymbol.reset(
symbol );
351 std::unique_ptr< QgsSymbol > s(
symbol );
353 if ( !vlayer || !vlayer->
renderer() )
378 if ( !vlayer || !vlayer->
renderer() )
382 for (
const auto &item : symbolList )
403 std::unique_ptr<QgsRenderContext> context = qgis::make_unique<QgsRenderContext>( );
404 context->setScaleFactor( dpi / 25.4 );
405 context->setRendererScale( scale );
409 return context.release();
412 void QgsSymbolLegendNode::checkAll(
bool state )
415 if ( !vlayer || !vlayer->
renderer() )
419 for (
const auto &item : symbolList )
430 if ( role == Qt::DisplayRole )
434 else if ( role == Qt::EditRole )
438 else if ( role == Qt::DecorationRole )
440 if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
448 if ( !mTextOnSymbolLabel.isEmpty() && context )
450 QPainter painter( &pix );
451 painter.setRenderHint( QPainter::Antialiasing );
452 context->setPainter( &painter );
453 QFontMetricsF fm( mTextOnSymbolTextFormat.
scaledFont( *context ) );
454 qreal yBaselineVCenter = ( mIconSize.height() + fm.ascent() - fm.descent() ) / 2;
456 QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
461 pix = QPixmap( mIconSize );
462 pix.fill( Qt::transparent );
469 else if ( role == Qt::CheckStateRole )
475 if ( !vlayer || !vlayer->
renderer() )
494 if ( role != Qt::CheckStateRole )
501 if ( !vlayer || !vlayer->
renderer() )
526 std::unique_ptr< QgsRenderContext > tempRenderContext;
532 tempRenderContext = qgis::make_unique< QgsRenderContext >();
535 tempRenderContext->setScaleFactor( settings.
dpi() / 25.4 );
536 tempRenderContext->setRendererScale( settings.
mapScale() );
540 tempRenderContext->setForceVectorOutput(
true );
541 tempRenderContext->setPainter( ctx ? ctx->
painter :
nullptr );
546 tempRenderContext->setExpressionContext( expContext );
547 context = tempRenderContext.get();
553 double height = desiredHeight;
554 double width = desiredWidth;
557 double widthOffset = 0;
558 double heightOffset = 0;
563 double size = markerSymbol->size( *context ) / context->
scaleFactor();
566 if ( width < desiredWidth )
568 widthOffset = ( desiredWidth - width ) / 2.0;
570 if ( height < desiredHeight )
572 heightOffset = ( desiredHeight - height ) / 2.0;
578 double currentYCoord = ctx->
top + ( itemHeight - desiredHeight ) / 2;
586 opacity =
static_cast<int >( std::round( 255 * vectorLayer->opacity() ) );
590 p->setRenderHint( QPainter::Antialiasing );
596 p->translate( ctx->
columnLeft + widthOffset, currentYCoord + heightOffset );
599 p->translate( ctx->
columnRight - widthOffset - width, currentYCoord + heightOffset );
603 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
608 if ( opacity != 255 && useAdvancedEffects )
614 const QSize symbolSize(
static_cast< int >( std::round( width * dotsPerMM ) ),
static_cast<int >( std::round( height * dotsPerMM ) ) );
615 const QSize tempImageSize( symbolSize.width() + maxBleed * 2, symbolSize.height() + maxBleed * 2 );
616 QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
617 tempImage.fill( Qt::transparent );
618 QPainter imagePainter( &tempImage );
620 imagePainter.setRenderHint( QPainter::Antialiasing );
622 imagePainter.translate( maxBleed, maxBleed );
624 imagePainter.translate( -maxBleed, -maxBleed );
627 imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
628 imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
631 p->drawImage( -maxBleed, -maxBleed, tempImage );
635 s->
drawPreviewIcon( p, QSize(
static_cast< int >( std::round( width * dotsPerMM ) ),
static_cast< int >( std::round( height * dotsPerMM ) ) ), context,
false,
nullptr, &
patchShape );
638 if ( !mTextOnSymbolLabel.isEmpty() )
640 QFontMetricsF fm( mTextOnSymbolTextFormat.
scaledFont( *context ) );
641 qreal yBaselineVCenter = ( height * dotsPerMM + fm.ascent() - fm.descent() ) / 2;
643 QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
649 return QSizeF( std::max( width + 2 * widthOffset,
static_cast< double >( desiredWidth ) ),
650 std::max( height + 2 * heightOffset,
static_cast< double >( desiredHeight ) ) );
655 const QgsSymbol *s = mCustomSymbol ? mCustomSymbol.get() : mItem.
symbol();
658 return QJsonObject();
678 QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );
682 opacity = ( 255 * vectorLayer->opacity() );
684 if ( opacity != 255 )
687 painter.begin( &img );
688 painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
689 painter.fillRect( pix.rect(), QColor( 0, 0, 0, opacity ) );
693 QByteArray byteArray;
694 QBuffer buffer( &byteArray );
695 img.save( &buffer,
"PNG" );
696 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
699 json[ QStringLiteral(
"icon" ) ] = base64;
712 if ( mSymbolUsesMapUnits )
720 void QgsSymbolLegendNode::updateLabel()
729 if ( showFeatureCount && vl )
732 mLabel += QStringLiteral(
" [%1]" ).arg( count != -1 ? QLocale().toString( count ) : tr(
"N/A" ) );
752 if ( label.isEmpty() )
756 else if ( mLabel.contains(
"[%" ) )
768 else if ( label.contains(
"[%" ) )
803 if ( role == Qt::DisplayRole || role == Qt::EditRole )
805 else if ( role == Qt::DecorationRole )
824 if ( role == Qt::DecorationRole )
826 return QPixmap::fromImage( mImage );
828 else if ( role == Qt::SizeHintRole )
830 return mImage.size();
837 Q_UNUSED( itemHeight )
846 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
851 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
860 QByteArray byteArray;
861 QBuffer buffer( &byteArray );
862 mImage.save( &buffer,
"PNG" );
863 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
866 json[ QStringLiteral(
"icon" ) ] = base64;
881 if ( role == Qt::DecorationRole )
888 else if ( role == Qt::DisplayRole || role == Qt::EditRole )
903 if ( ctx->
patchSize.width() < size.width() )
904 offsetX = ( size.width() - ctx->
patchSize.width() ) / 2.0;
909 size.setHeight( ctx->
patchSize.height() );
915 QColor itemColor = mColor;
919 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
921 ctx->
painter->setBrush( itemColor );
928 pen.setJoinStyle( Qt::MiterJoin );
933 ctx->
painter->setPen( Qt::NoPen );
940 ctx->
painter->drawRect( QRectF( ctx->
columnLeft + offsetX, ctx->
top + ( itemHeight - size.height() ) / 2,
941 size.width(), size.height() ) );
945 ctx->
painter->drawRect( QRectF( ctx->
columnRight - size.width() - offsetX, ctx->
top + ( itemHeight - size.height() ) / 2,
946 size.width(), size.height() ) );
955 QImage img = QImage( settings.
symbolSize().toSize(), QImage::Format_ARGB32 );
956 img.fill( Qt::transparent );
958 QPainter painter( &img );
959 painter.setRenderHint( QPainter::Antialiasing );
961 QColor itemColor = mColor;
965 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
967 painter.setBrush( itemColor );
974 pen.setJoinStyle( Qt::MiterJoin );
975 painter.setPen( pen );
979 painter.setPen( Qt::NoPen );
982 painter.drawRect( QRectF( 0, 0, settings.
symbolSize().width(), settings.
symbolSize().height() ) );
984 QByteArray byteArray;
985 QBuffer buffer( &byteArray );
986 img.save( &buffer,
"PNG" );
987 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
990 json[ QStringLiteral(
"icon" ) ] = base64;
1002 QImage QgsWmsLegendNode::getLegendGraphic()
const
1004 if ( ! mValid && ! mFetcher )
1019 Q_ASSERT( ! mFetcher );
1038 if ( role == Qt::DecorationRole )
1040 return QPixmap::fromImage( getLegendGraphic() );
1042 else if ( role == Qt::SizeHintRole )
1044 return getLegendGraphic().size();
1051 Q_UNUSED( itemHeight )
1064 QRectF( QPointF( 0, 0 ), mImage.size() ) );
1067 case Qt::AlignRight:
1073 QRectF( QPointF( 0, 0 ), mImage.size() ) );
1082 QByteArray byteArray;
1083 QBuffer buffer( &byteArray );
1084 mImage.save( &buffer,
"PNG" );
1085 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
1088 json[ QStringLiteral(
"icon" ) ] = base64;
1093 QImage QgsWmsLegendNode::renderMessage(
const QString &msg )
const
1095 const int fontHeight = 10;
1096 const int margin = fontHeight / 2;
1097 const int nlines = 1;
1099 const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
1100 QImage image( w, h, QImage::Format_ARGB32_Premultiplied );
1102 painter.begin( &image );
1103 painter.setPen( QColor( 255, 0, 0 ) );
1104 painter.setFont( QFont( QStringLiteral(
"Chicago" ), fontHeight ) );
1105 painter.fillRect( 0, 0, w, h, QColor( 255, 255, 255 ) );
1106 painter.drawText( 0, margin + fontHeight, msg );
1113 void QgsWmsLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
1115 QString msg = QStringLiteral(
"Downloading... %1/%2" ).arg( cur ).arg( tot );
1117 mImage = renderMessage( msg );
1121 void QgsWmsLegendNode::getLegendGraphicErrored(
const QString &msg )
1123 if ( ! mFetcher )
return;
1125 mImage = renderMessage( msg );
1137 void QgsWmsLegendNode::getLegendGraphicFinished(
const QImage &image )
1139 if ( ! mFetcher )
return;
1142 if ( ! image.isNull() )
1144 if ( image != mImage )
1178 if ( role == Qt::DecorationRole )
1181 return QPixmap::fromImage( mImage );
1183 else if ( role == Qt::SizeHintRole )
1186 return mImage.size();
1195 std::unique_ptr< QgsRenderContext > tempRenderContext;
1200 tempRenderContext = qgis::make_unique< QgsRenderContext >();
1203 tempRenderContext->setScaleFactor( settings.
dpi() / 25.4 );
1204 tempRenderContext->setRendererScale( settings.
mapScale() );
1206 tempRenderContext->setMapToPixel(
QgsMapToPixel( 1 / ( settings.
mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
1207 tempRenderContext->setForceVectorOutput(
true );
1208 tempRenderContext->setPainter( ctx ? ctx->
painter :
nullptr );
1215 tempRenderContext->setExpressionContext( expContext );
1216 context = tempRenderContext.get();
1233 double labelXOffset;
1237 context->
painter()->restore();
1246 void QgsDataDefinedSizeLegendNode::cacheImage()
const
1248 if ( mImage.isNull() )
1254 Q_ASSERT( context );
1255 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 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.
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.
Q_DECL_DEPRECATED double mmPerMapUnit() const
double columnRight
Right side of current legend column.
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.
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.
Q_DECL_DEPRECATED double mapScale() const
Returns the legend map scale.
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.
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.
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
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.
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.
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.
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true)
Draws text within a rectangle using the specified settings.
#define Q_NOWARN_DEPRECATED_POP
@ 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.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
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.
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...
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.
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 legendMapViewData(double *mapUnitsPerPixel, int *dpi, double *scale) const
Gets hints about map view - to be used in legend nodes.
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.
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.
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.
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.
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...
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.
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.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
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.
QFont scaledFont(const QgsRenderContext &context) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
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...