47 , mEmbeddedInParent( false )
53 return qobject_cast<QgsLayerTreeModel *>( parent() );
58 return Qt::ItemIsEnabled;
93 double itemHeight = std::max(
static_cast< double >( ctx && ctx->
patchSize.height() > 0 ? ctx->
patchSize.height() : settings.
symbolSize().height() ), textHeight );
104 const QString text =
data( Qt::DisplayRole ).toString();
105 json[ QStringLiteral(
"title" ) ] = text;
111 QIcon symbolIcon =
data( Qt::DecorationRole ).value<QIcon>();
112 if ( symbolIcon.isNull() )
119 size.setWidth( ctx->
patchSize.width( ) );
121 size.setHeight( ctx->
patchSize.height( ) );
130 symbolIcon.paint( ctx->
painter,
132 static_cast< int >( ctx->
top + ( itemHeight - size.height() ) / 2 ),
133 static_cast< int >( size.width() ),
134 static_cast< int >( size.height() ) );
138 symbolIcon.paint( ctx->
painter,
139 static_cast< int >( ctx->
columnRight - size.width() ),
140 static_cast< int >( ctx->
top + ( itemHeight - size.height() ) / 2 ),
141 static_cast< int >( size.width() ),
142 static_cast< int >( size.height() ) );
151 const QIcon icon =
data( Qt::DecorationRole ).value<QIcon>();
153 return QJsonObject();
155 const QImage image( icon.pixmap( settings.
symbolSize().width(), settings.
symbolSize().height() ).toImage() );
156 QByteArray byteArray;
157 QBuffer buffer( &byteArray );
158 image.save( &buffer,
"PNG" );
159 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
162 json[ QStringLiteral(
"icon" ) ] = base64;
168 QSizeF labelSize( 0, 0 );
178 labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * ( settings.
lineSpacing() + textDescent );
180 double labelXMin = 0.0;
181 double labelXMax = 0.0;
210 if ( labelSize.height() < symbolSize.height() )
211 labelY += symbolSize.height() / 2 - labelSize.height() / 2;
213 labelY += textHeight;
216 for ( QStringList::ConstIterator itemPart = lines.constBegin(); itemPart != lines.constEnd(); ++itemPart )
219 labelSize.rwidth() = std::max( lineWidth,
double( labelSize.width() ) );
227 settings.
drawText( ctx->
painter, labelXMin, labelY, *itemPart, symbolLabelFont );
231 settings.
drawText( ctx->
painter, labelXMax - lineWidth, labelY, *itemPart, symbolLabelFont );
234 case Qt::AlignHCenter:
235 settings.
drawText( ctx->
painter, labelXMin + ( labelXMax - labelXMin - lineWidth ) / 2.0, labelY, *itemPart, symbolLabelFont );
239 if ( itemPart != ( lines.end() - 1 ) )
240 labelY += textDescent + settings.
lineSpacing() + textHeight;
261 if ( !vlayer->renderer() )
265 for (
const auto &item : symbolList )
267 vlayer->renderer()->checkLegendSymbolItem( item.ruleKey(), ! vlayer->renderer()->legendSymbolItemChecked( item.ruleKey() ) );
271 vlayer->emitStyleChanged();
272 vlayer->triggerRepaint();
276 if ( !pclayer->renderer() )
279 const QStringList ruleKeys = pclayer->renderer()->legendRuleKeys();
280 for (
const QString &rule : ruleKeys )
282 pclayer->renderer()->checkLegendItem( rule, !pclayer->renderer()->legendItemChecked( rule ) );
286 pclayer->emitStyleChanged();
287 pclayer->triggerRepaint();
299 , mSymbolUsesMapUnits( false )
309 MINIMUM_SIZE = settings.
value(
"/qgis/legendsymbolMinimumSize", 0.5 ).toDouble();
310 MAXIMUM_SIZE = settings.
value(
"/qgis/legendsymbolMaximumSize", 20.0 ).toDouble();
317 connect( nodeLayer, &QObject::destroyed,
this, [ = ]() {
mLayerNode =
nullptr; } );
328 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
330 return Qt::ItemIsEnabled;
369 if ( !mTextOnSymbolLabel.isEmpty() && context )
373 int wInt = ceil( w ), hInt = ceil( h );
374 if ( wInt > minSz.width() ) minSz.setWidth( wInt );
375 if ( hInt > minSz.height() ) minSz.setHeight( hInt );
392 QString layerName = legendlabel.isNull() ?
mLayerNode->
name() : legendlabel.toString();
419 return mCustomSymbol.get();
424 mCustomSymbol.reset(
symbol );
432 std::unique_ptr< QgsSymbol > s(
symbol );
434 if ( !vlayer || !vlayer->
renderer() )
451 if (
auto *lModel =
model() )
452 lModel->legendMapViewData( &mupp, &dpi, &scale );
458 std::unique_ptr<QgsRenderContext> context = qgis::make_unique<QgsRenderContext>( );
459 context->setScaleFactor( dpi / 25.4 );
460 context->setRendererScale( scale );
464 return context.release();
467 void QgsLayerTreeModelLegendNode::checkAll(
bool state )
471 if ( !vlayer->renderer() )
475 for (
const auto &item : symbolList )
477 vlayer->renderer()->checkLegendSymbolItem( item.ruleKey(), state );
481 vlayer->emitStyleChanged();
482 vlayer->triggerRepaint();
486 if ( !pclayer->renderer() )
489 const QStringList ruleKeys = pclayer->renderer()->legendRuleKeys();
490 for (
const QString &rule : ruleKeys )
492 pclayer->renderer()->checkLegendItem( rule, state );
496 pclayer->emitStyleChanged();
497 pclayer->triggerRepaint();
503 if ( role == Qt::DisplayRole )
507 else if ( role == Qt::EditRole )
511 else if ( role == Qt::DecorationRole )
513 if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
526 if ( !mTextOnSymbolLabel.isEmpty() && context )
528 QPainter painter( &pix );
529 painter.setRenderHint( QPainter::Antialiasing );
530 context->setPainter( &painter );
531 QFontMetricsF fm( mTextOnSymbolTextFormat.
scaledFont( *context ) );
532 qreal yBaselineVCenter = ( mIconSize.height() + fm.ascent() - fm.descent() ) / 2;
534 QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
539 pix = QPixmap( mIconSize );
540 pix.fill( Qt::transparent );
547 else if ( role == Qt::CheckStateRole )
554 if ( !vlayer->renderer() )
557 return vlayer->renderer()->legendSymbolItemChecked( mItem.
ruleKey() ) ? Qt::Checked : Qt::Unchecked;
578 if ( role != Qt::CheckStateRole )
585 if ( !vlayer || !vlayer->
renderer() )
610 std::unique_ptr< QgsRenderContext > tempRenderContext;
616 tempRenderContext = qgis::make_unique< QgsRenderContext >();
619 tempRenderContext->setScaleFactor( settings.
dpi() / 25.4 );
620 tempRenderContext->setRendererScale( settings.
mapScale() );
624 tempRenderContext->setForceVectorOutput(
true );
625 tempRenderContext->setPainter( ctx ? ctx->
painter :
nullptr );
630 tempRenderContext->setExpressionContext( expContext );
631 context = tempRenderContext.get();
637 double height = desiredHeight;
638 double width = desiredWidth;
641 double widthOffset = 0;
642 double heightOffset = 0;
649 double size = markerSymbol->size( *context ) / context->
scaleFactor();
655 if ( minMaxSizeSymbol )
657 s = minMaxSizeSymbol.get();
662 if ( width < desiredWidth )
664 widthOffset = ( desiredWidth - width ) / 2.0;
666 if ( height < desiredHeight )
668 heightOffset = ( desiredHeight - height ) / 2.0;
673 double currentYCoord = ctx->
top + ( itemHeight - desiredHeight ) / 2;
681 opacity =
static_cast<int >( std::round( 255 * layer->opacity() ) );
690 p->translate( ctx->
columnLeft + widthOffset, currentYCoord + heightOffset );
693 p->translate( ctx->
columnRight - widthOffset - width, currentYCoord + heightOffset );
697 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
702 if ( opacity != 255 && useAdvancedEffects )
708 const QSize symbolSize(
static_cast< int >( std::round( width * dotsPerMM ) ),
static_cast<int >( std::round( height * dotsPerMM ) ) );
709 const QSize tempImageSize( symbolSize.width() + maxBleed * 2, symbolSize.height() + maxBleed * 2 );
710 QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
711 tempImage.fill( Qt::transparent );
712 QPainter imagePainter( &tempImage );
716 imagePainter.translate( maxBleed, maxBleed );
718 imagePainter.translate( -maxBleed, -maxBleed );
721 imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
722 imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
725 p->drawImage( -maxBleed, -maxBleed, tempImage );
729 s->
drawPreviewIcon( p, QSize(
static_cast< int >( std::round( width * dotsPerMM ) ),
static_cast< int >( std::round( height * dotsPerMM ) ) ), context,
false,
nullptr, &
patchShape );
732 if ( !mTextOnSymbolLabel.isEmpty() )
734 QFontMetricsF fm( mTextOnSymbolTextFormat.
scaledFont( *context ) );
735 qreal yBaselineVCenter = ( height * dotsPerMM + fm.ascent() - fm.descent() ) / 2;
737 QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
741 return QSizeF( std::max( width + 2 * widthOffset,
static_cast< double >( desiredWidth ) ),
742 std::max( height + 2 * heightOffset,
static_cast< double >( desiredHeight ) ) );
747 const QgsSymbol *s = mCustomSymbol ? mCustomSymbol.get() : mItem.
symbol();
750 return QJsonObject();
772 QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );
776 opacity = ( 255 * layer->opacity() );
778 if ( opacity != 255 )
781 painter.begin( &img );
782 painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
783 painter.fillRect( pix.rect(), QColor( 0, 0, 0, opacity ) );
787 QByteArray byteArray;
788 QBuffer buffer( &byteArray );
789 img.save( &buffer,
"PNG" );
790 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
793 json[ QStringLiteral(
"icon" ) ] = base64;
796 json[ QStringLiteral(
"scaleMaxDenom" ) ] = mItem.
scaleMaxDenom();
800 json[ QStringLiteral(
"scaleMinDenom" ) ] = mItem.
scaleMinDenom();
815 if ( mSymbolUsesMapUnits )
823 void QgsSymbolLegendNode::updateLabel()
832 if ( showFeatureCount && vl )
835 mLabel += QStringLiteral(
" [%1]" ).arg( count != -1 ? QLocale().toString( count ) : tr(
"N/A" ) );
855 if ( label.isEmpty() )
859 else if ( mLabel.contains(
"[%" ) )
871 else if ( label.contains(
"[%" ) )
906 if ( role == Qt::DisplayRole || role == Qt::EditRole )
908 else if ( role == Qt::DecorationRole )
929 if ( role == Qt::DecorationRole )
931 return QPixmap::fromImage( mImage );
933 else if ( role == Qt::SizeHintRole )
935 return mImage.size();
946 Q_UNUSED( itemHeight )
955 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
960 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
969 QByteArray byteArray;
970 QBuffer buffer( &byteArray );
971 mImage.save( &buffer,
"PNG" );
972 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
975 json[ QStringLiteral(
"icon" ) ] = base64;
985 , mCheckable( isCheckable )
986 , mRuleKey( ruleKey )
993 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
995 return Qt::ItemIsEnabled;
1002 case Qt::DecorationRole:
1007 return QIcon( pix );
1010 case Qt::DisplayRole:
1020 case Qt::CheckStateRole:
1027 if ( !pclayer->renderer() )
1030 return pclayer->renderer()->legendItemChecked( mRuleKey ) ? Qt::Checked : Qt::Unchecked;
1043 if ( role != Qt::CheckStateRole )
1051 if ( !pclayer->renderer() )
1054 pclayer->renderer()->checkLegendItem( mRuleKey, value == Qt::Checked );
1057 pclayer->emitStyleChanged();
1059 pclayer->triggerRepaint();
1077 if ( ctx->
patchSize.width() < size.width() )
1078 offsetX = ( size.width() - ctx->
patchSize.width() ) / 2.0;
1079 size.setWidth( ctx->
patchSize.width() );
1083 size.setHeight( ctx->
patchSize.height() );
1089 QColor itemColor = mColor;
1093 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
1095 ctx->
painter->setBrush( itemColor );
1102 pen.setJoinStyle( Qt::MiterJoin );
1107 ctx->
painter->setPen( Qt::NoPen );
1114 ctx->
painter->drawRect( QRectF( ctx->
columnLeft + offsetX, ctx->
top + ( itemHeight - size.height() ) / 2,
1115 size.width(), size.height() ) );
1118 case Qt::AlignRight:
1119 ctx->
painter->drawRect( QRectF( ctx->
columnRight - size.width() - offsetX, ctx->
top + ( itemHeight - size.height() ) / 2,
1120 size.width(), size.height() ) );
1129 QImage img = QImage( settings.
symbolSize().toSize(), QImage::Format_ARGB32 );
1130 img.fill( Qt::transparent );
1132 QPainter painter( &img );
1133 painter.setRenderHint( QPainter::Antialiasing );
1135 QColor itemColor = mColor;
1139 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
1141 painter.setBrush( itemColor );
1148 pen.setJoinStyle( Qt::MiterJoin );
1149 painter.setPen( pen );
1153 painter.setPen( Qt::NoPen );
1156 painter.drawRect( QRectF( 0, 0, settings.
symbolSize().width(), settings.
symbolSize().height() ) );
1158 QByteArray byteArray;
1159 QBuffer buffer( &byteArray );
1160 img.save( &buffer,
"PNG" );
1161 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
1164 json[ QStringLiteral(
"icon" ) ] = base64;
1178 QImage QgsWmsLegendNode::getLegendGraphic()
const
1180 if ( ! mValid && ! mFetcher )
1195 Q_ASSERT( ! mFetcher );
1211 if ( role == Qt::DecorationRole )
1213 return QPixmap::fromImage( getLegendGraphic() );
1215 else if ( role == Qt::SizeHintRole )
1217 return getLegendGraphic().size();
1228 Q_UNUSED( itemHeight )
1241 QRectF( QPointF( 0, 0 ), mImage.size() ) );
1244 case Qt::AlignRight:
1250 QRectF( QPointF( 0, 0 ), mImage.size() ) );
1259 QByteArray byteArray;
1260 QBuffer buffer( &byteArray );
1261 mImage.save( &buffer,
"PNG" );
1262 const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
1265 json[ QStringLiteral(
"icon" ) ] = base64;
1269 QImage QgsWmsLegendNode::renderMessage(
const QString &msg )
const
1271 const int fontHeight = 10;
1272 const int margin = fontHeight / 2;
1273 const int nlines = 1;
1275 const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
1276 QImage image( w, h, QImage::Format_ARGB32_Premultiplied );
1278 painter.begin( &image );
1279 painter.setPen( QColor( 255, 0, 0 ) );
1280 painter.setFont( QFont( QStringLiteral(
"Chicago" ), fontHeight ) );
1281 painter.fillRect( 0, 0, w, h, QColor( 255, 255, 255 ) );
1282 painter.drawText( 0, margin + fontHeight, msg );
1289 void QgsWmsLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
1291 const QString msg = tot > 0 ? tr(
"Downloading: %1% (%2)" ).arg(
static_cast< int >( std::round( 100 * cur / tot ) ) ).arg(
QgsFileUtils::representFileSize( tot ) )
1293 mImage = renderMessage( msg );
1297 void QgsWmsLegendNode::getLegendGraphicErrored(
const QString & )
1310 void QgsWmsLegendNode::getLegendGraphicFinished(
const QImage &image )
1315 if ( ! image.isNull() )
1317 if ( image != mImage )
1350 if ( role == Qt::DecorationRole )
1353 return QPixmap::fromImage( mImage );
1355 else if ( role == Qt::SizeHintRole )
1358 return mImage.size();
1371 std::unique_ptr< QgsRenderContext > tempRenderContext;
1376 tempRenderContext = qgis::make_unique< QgsRenderContext >();
1379 tempRenderContext->setScaleFactor( settings.
dpi() / 25.4 );
1380 tempRenderContext->setRendererScale( settings.
mapScale() );
1382 tempRenderContext->setMapToPixel(
QgsMapToPixel( 1 / ( settings.
mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
1383 tempRenderContext->setForceVectorOutput(
true );
1384 tempRenderContext->setPainter( ctx ? ctx->
painter :
nullptr );
1391 tempRenderContext->setExpressionContext( expContext );
1392 context = tempRenderContext.get();
1409 double labelXOffset;
1413 context->
painter()->restore();
1422 void QgsDataDefinedSizeLegendNode::cacheImage()
const
1424 if ( mImage.isNull() )
1430 Q_ASSERT( context );
1431 context->setScaleFactor( 96 / 25.4 );
QgsDataDefinedSizeLegendNode(QgsLayerTreeLayer *nodeLayer, const QgsDataDefinedSizeLegend &settings, QObject *parent=nullptr)
Construct the node using QgsDataDefinedSizeLegend as definition of the node's appearance.
ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx) override
Entry point called from QgsLegendRenderer to do the rendering.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
~QgsDataDefinedSizeLegendNode() override
Object that keeps configuration of appearance of marker symbol's data-defined size in legend.
void setFont(const QFont &font)
Sets font used for rendering of labels - only valid for collapsed legend.
void setTextColor(const QColor &color)
Sets text color for rendering of labels - only valid for collapsed legend.
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...
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...
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
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...
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
static QString representFileSize(qint64 bytes)
Returns the human size from bytes.
void progress(qint64 received, qint64 total)
Emitted to report progress.
void error(const QString &msg)
Emitted when an error occurs.
void finish(const QImage &legend)
Emitted when the download completes.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
QgsImageLegendNode(QgsLayerTreeLayer *nodeLayer, const QImage &img, QObject *parent=nullptr)
Constructor for QgsImageLegendNode.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
static QRect nonTransparentImageRect(const QImage &image, QSize minSize=QSize(), bool center=false)
Calculates the non-transparent region of an image.
Layer tree node points to a map layer.
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
QString name() const override
Returns the layer's name.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
QSizeF patchSize() const
Returns the user (overridden) size for the legend node.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
QJsonObject exportToJson(const QgsLegendSettings &settings, const QgsRenderContext &context)
Entry point called from QgsLegendRenderer to do the rendering in a JSON object.
@ SimpleLegend
Simple label with icon legend node type.
@ RasterSymbolLegend
Raster symbol legend node type.
@ ImageLegend
Raster image legend node type.
@ DataDefinedSizeLegend
Marker symbol legend node type.
@ WmsLegend
WMS legend node type.
@ SymbolLegend
Vector symbol legend node type.
void checkAllItems()
Checks all checkable items belonging to the same layer as this node.
void uncheckAllItems()
Unchecks all checkable items belonging to the same layer as this node.
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
QgsLayerTreeLayer * mLayerNode
QgsLayerTreeModelLegendNode(QgsLayerTreeLayer *nodeL, QObject *parent=nullptr)
Construct the node with pointer to its parent layer node.
virtual void setUserPatchSize(QSizeF size)
Sets the user (overridden) size for the legend node.
@ ParentRuleKeyRole
Rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2....
@ RuleKeyRole
Rule key of the node (QString)
@ NodeTypeRole
Type of node. Added in 3.16.
void sizeChanged()
Emitted when the size of this node changes.
void dataChanged()
Emitted on internal data change so the layer tree model can forward the signal to views.
QgsRenderContext * createTemporaryRenderContext() const
Returns a temporary context or nullptr if legendMapViewData are not valid.
virtual QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const
Adds a symbol in base64 string within a JSON object with the key "icon".
QgsLayerTreeModel * model() const
Returns pointer to model owning this legend node.
void toggleAllItems()
Toggle all checkable items belonging to the same layer as this node.
QgsLegendPatchShape mPatchShape
virtual QSizeF userPatchSize() const
Returns the user (overridden) size for the legend node.
virtual ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx)
Entry point called from QgsLegendRenderer to do the rendering.
virtual Qt::ItemFlags flags() const
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
virtual void setEmbeddedInParent(bool embedded)
virtual bool setData(const QVariant &value, int role)
Sets some data associated with the item. Default implementation does nothing and returns false.
virtual QSizeF drawSymbolText(const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize) const
Draws label on the right side of the item.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
const QgsMapSettings * legendFilterMapSettings() const
Returns the current map settings used for the current legend filter (or nullptr if none is enabled)
static int scaleIconSize(int standardSize)
Scales an layer tree model icon size to compensate for display pixel density, making the icon size hi...
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.
Represents a patch shape for use in map legends.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
double minimumSymbolSize() const
Returns the minimum symbol size (in mm).
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
double fontDescentMillimeters(const QFont &font) const
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCA...
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
QColor fontColor() const
Returns the font color used for legend items.
double maximumSymbolSize() const
Returns the maximum symbol size (in mm).
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
Q_DECL_DEPRECATED bool useAdvancedEffects() const
double fontHeightCharacterMM(const QFont &font, QChar c) const
Returns the font height of a character in millimeters.
Q_DECL_DEPRECATED int dpi() const
double lineSpacing() const
Returns the line spacing to use between lines of legend text.
Q_DECL_DEPRECATED double mmPerMapUnit() const
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...
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
Q_DECL_DEPRECATED double mapScale() const
Returns the legend map scale.
double margin(Side side)
Returns the margin (in mm) for the specified side of the component.
Qt::Alignment alignment() const
Returns the alignment for the legend component.
QFont font() const
Returns the font used for rendering this legend component.
@ Symbol
Symbol icon (excluding label)
@ SymbolLabel
Symbol label (excluding icon)
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QString parentRuleKey() const
Key of the parent legend node.
int scaleMaxDenom() const
Max scale denominator of the scale range.
void setSymbol(QgsSymbol *s)
Sets the symbol of the item.
QgsSymbol * symbol() const
Returns associated symbol. May be nullptr.
int scaleMinDenom() const
Min scale denominator of the scale range.
QString ruleKey() const
Returns unique identifier of the rule for identification of the item within renderer.
bool isCheckable() const
Returns whether the item is user-checkable - whether renderer supports enabling/disabling it.
QString label() const
Returns text label.
Base class for all map layer types.
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
The QgsMapSettings class contains configuration for rendering of the map.
Perform transforms between map coordinates and device coordinates.
A marker symbol type, for rendering Point and MultiPoint geometries.
Represents a map layer supporting display of point clouds.
Base class for raster data providers.
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Returns a new image downloader for the raster legend.
Represents a raster layer.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Raster renderer pipe that applies colors to a raster.
Qt::ItemFlags flags() const override
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
bool setData(const QVariant &value, int role) override
Sets some data associated with the item. Default implementation does nothing and returns false.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
QgsRasterSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QColor &color, const QString &label, QObject *parent=nullptr, bool isCheckable=false, const QString &ruleKey=QString())
Constructor for QgsRasterSymbolLegendNode.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
Contains information about the context of a rendering operation.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
@ Antialiasing
Use antialiasing while drawing.
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
Flags flags() const
Returns combination of flags used for rendering.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void setRendererScale(double scale)
Sets the renderer map scale.
Scoped object for saving and restoring a QPainter object's state.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
QgsSimpleLegendNode(QgsLayerTreeLayer *nodeLayer, const QString &label, const QIcon &icon=QIcon(), QObject *parent=nullptr, const QString &key=QString())
Constructor for QgsSimpleLegendNode.
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.
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.
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
static double MAXIMUM_SIZE
QString evaluateLabel(const QgsExpressionContext &context=QgsExpressionContext(), const QString &label=QString())
Evaluates and returns the text label of the current node.
const QgsSymbol * symbol() const
Returns the symbol used by the legend node.
void setPatchShape(const QgsLegendPatchShape &shape)
Sets the symbol patch shape to use when rendering the legend node symbol.
QgsSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItem &item, QObject *parent=nullptr)
Constructor for QgsSymbolLegendNode.
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
QSize minimumIconSize() const
Calculates the minimum icon size to prevent cropping.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
bool setData(const QVariant &value, int role) override
Sets some data associated with the item. Default implementation does nothing and returns false.
Qt::ItemFlags flags() const override
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
void setCustomSymbol(QgsSymbol *symbol)
Sets the node's custom symbol.
void setEmbeddedInParent(bool embedded) override
QgsSymbol * customSymbol() const
Returns the node's custom symbol.
QString symbolLabel() const
Label of the symbol, user defined label will be used, otherwise will default to the label made by QGI...
void setSymbol(QgsSymbol *symbol)
Sets the symbol to be used by the legend node.
static double MINIMUM_SIZE
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
Abstract base class for all rendered symbols.
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.
bool usesMapUnits() const
Returns true if the symbol has any components which use map unit based sizes.
SymbolType type() const
Returns the symbol's type.
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...
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.
@ AlignCenter
Center align.
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.
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.
@ Point
Text at point of origin draw mode.
Represents a vector layer which manages a vector based data sets.
QgsExpressionContextScope * createExpressionContextScope() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QgsFeatureRenderer * renderer()
Returns the feature renderer used for rendering the features in the layer in 2D map views.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
~QgsWmsLegendNode() override
QgsWmsLegendNode(QgsLayerTreeLayer *nodeLayer, QObject *parent=nullptr)
Constructor for QgsWmsLegendNode.
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Single variable definition for use within a QgsExpressionContextScope.
QPainter * painter
Painter.
double top
Top y-position of legend item.
QgsLegendPatchShape patchShape
The patch shape to render for the node.
double maxSiblingSymbolWidth
Largest symbol width, considering all other sibling legend components associated with the current com...
QSizeF patchSize
Symbol patch size to render for the node.
double columnLeft
Left side of current legend column.
double columnRight
Right side of current legend column.
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.