35 , mEmbeddedInParent( false )
50 return Qt::ItemIsEnabled;
69 double itemHeight = qMax( static_cast< double >( settings.
symbolSize().
height() ), textHeight );
102 double labelX = 0.0, labelY = 0.0;
112 labelY += symbolSize.
height() / 2 - labelSize.
height() / 2;
114 labelY += textHeight;
123 settings.
drawText( ctx->
painter, labelX, labelY, *itemPart, symbolLabelFont );
124 if ( itemPart != lines.
end() )
138 , mSymbolUsesMapUnits( false )
139 , mIconSize( 16, 16 )
154 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
156 return Qt::ItemIsEnabled;
162 QSize minSz( 16, 16 );
168 context.
data() ).toImage(),
177 context.
data() ).toImage(),
222 QgsRenderContext * QgsSymbolV2LegendNode::createTemporaryRenderContext()
const 233 context->setScaleFactor( dpi / 25.4 );
234 context->setRendererScale( scale );
236 return validData ? context.
take() :
nullptr;
239 void QgsSymbolV2LegendNode::checkAll(
bool state )
257 if ( role == Qt::DisplayRole )
261 else if ( role == Qt::EditRole )
265 else if ( role == Qt::DecorationRole )
267 if ( mPixmap.
isNull() || mPixmap.
size() != mIconSize )
278 pix.
fill( Qt::transparent );
287 pix2.
fill( Qt::transparent );
296 else if ( role == Qt::CheckStateRole )
325 if ( role != Qt::CheckStateRole )
367 double widthOffset = 0;
368 double heightOffset = 0;
388 double currentXPosition = ctx->
point.
x();
397 opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 );
401 p->
translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
402 p->
scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
407 QSize tempImageSize( width * dotsPerMM, height * dotsPerMM );
408 QImage tempImage =
QImage( tempImageSize, QImage::Format_ARGB32 );
409 tempImage.
fill( Qt::transparent );
410 QPainter imagePainter( &tempImage );
428 return QSizeF( qMax( width + 2 * widthOffset, static_cast< double >( settings.
symbolSize().
width() ) ),
429 qMax( height + 2 * heightOffset, static_cast< double >( settings.
symbolSize().
height() ) ) );
442 if ( mSymbolUsesMapUnits )
450 void QgsSymbolV2LegendNode::updateLabel()
462 if ( showFeatureCount && vl && vl->
featureCount() >= 0 )
488 if ( role == Qt::DisplayRole || role == Qt::EditRole )
490 else if ( role == Qt::DecorationRole )
509 if ( role == Qt::DecorationRole )
513 else if ( role == Qt::SizeHintRole )
515 return mImage.
size();
522 Q_UNUSED( itemHeight );
543 if ( role == Qt::DecorationRole )
545 QSize iconSize( 16, 16 );
550 else if ( role == Qt::DisplayRole || role == Qt::EditRole )
561 QColor itemColor = mColor;
565 itemColor.
setAlpha( rasterRenderer->opacity() * 255.0 );
596 const QImage& QgsWMSLegendNode::getLegendGraphic()
const 598 if ( ! mValid && ! mFetcher )
605 if ( ! mod )
return mImage;
610 Q_ASSERT( ! mFetcher );
614 connect( mFetcher.
data(), SIGNAL( finish(
const QImage& ) ),
this, SLOT( getLegendGraphicFinished(
const QImage& ) ) );
616 connect( mFetcher.
data(), SIGNAL( progress( qint64, qint64 ) ),
this, SLOT( getLegendGraphicProgress( qint64, qint64 ) ) );
629 if ( role == Qt::DecorationRole )
633 else if ( role == Qt::SizeHintRole )
635 return getLegendGraphic().
size();
642 Q_UNUSED( itemHeight );
654 QImage QgsWMSLegendNode::renderMessage(
const QString& msg )
const 656 const int fontHeight = 10;
657 const int margin = fontHeight / 2;
658 const int nlines = 1;
660 const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
661 QImage theImage( w, h, QImage::Format_ARGB32_Premultiplied );
663 painter.
begin( &theImage );
667 painter.
drawText( 0, margin + fontHeight, msg );
674 void QgsWMSLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
678 mImage = renderMessage( msg );
682 void QgsWMSLegendNode::getLegendGraphicErrored(
const QString& msg )
684 if ( ! mFetcher )
return;
686 mImage = renderMessage( msg );
698 void QgsWMSLegendNode::getLegendGraphicFinished(
const QImage& theImage )
700 if ( ! mFetcher )
return;
703 if ( ! theImage.
isNull() )
705 if ( theImage != mImage )
void setForceVectorOutput(bool force)
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
void checkAllItems()
Checks all items belonging to the same layer as this node.
QgsWMSLegendNode(QgsLayerTreeLayer *nodeLayer, QObject *parent=nullptr)
virtual Qt::ItemFlags flags() const
Return item flags associated with the item.
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setCompositionMode(CompositionMode mode)
~QgsLayerTreeModelLegendNode()
bool useAdvancedEffects() const
void setRenderHint(RenderHint hint, bool on)
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
void fill(const QColor &color)
QgsImageLegendNode(QgsLayerTreeLayer *nodeLayer, const QImage &img, QObject *parent=nullptr)
virtual bool setData(const QVariant &value, int role)
Set some data associated with the item.
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
virtual QVariant data(int role) const override
Return data associated with the item.
bool testFlag(Flag f) const
Check whether a flag is enabled.
void scale(qreal sx, qreal sy)
QStringList splitStringForWrapping(const QString &stringToSplt) const
Splits a string using the wrap char taking into account handling empty wrap char which means no wrapp...
QString ruleKey() const
Return unique identifier of the rule for identification of the item within renderer.
void setRendererScale(double scale)
double rasterBorderWidth() const
Returns the border width (in millimeters) for the border drawn around raster symbol items...
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Get an image downloader for the raster legend.
virtual void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
QgsLayerTreeLayer * layerNode() const
Return pointer to the parent layer node.
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
void setJoinStyle(Qt::PenJoinStyle style)
virtual QVariant data(int role) const override
Return data associated with the item.
virtual QgsLegendSymbolListV2 legendSymbolItemsV2() const
Return a list of symbology items for the legend.
virtual QVariant data(int role) const override
Return data associated with the item.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
virtual Qt::ItemFlags flags() const override
Return item flags associated with the item.
QgsLayerTreeModelLegendNode(QgsLayerTreeLayer *nodeL, QObject *parent=nullptr)
Construct the node with pointer to its parent layer node.
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=nullptr)
Draw icon of the symbol that occupyies area given by size using the painter.
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
QPainter * painter
Painter.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
The QgsMapSettings class contains configuration for rendering of the map.
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
void drawRect(const QRectF &rectangle)
Perform transforms between map coordinates and device coordinates.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
QSizeF wmsLegendSize() const
rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2...
void setFont(const QFont &font)
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
The output shall be in millimeters.
QString parentRuleKey() const
Key of the parent legend node.
int count(const T &value) const
void setScaleFactor(double factor)
void fill(uint pixelValue)
static double convertToPainterUnits(const QgsRenderContext &c, double size, QgsSymbolV2::OutputUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale())
Converts a size from the specied units to painter units.
rule key of the node (QString)
void setPen(const QColor &color)
QgsRasterSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QColor &color, const QString &label, QObject *parent=nullptr)
virtual QVariant data(int role) const override
Return data associated with the item.
void drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source)
virtual void setEmbeddedInParent(bool embedded) override
QgsLayerTreeLayer * mLayerNode
QgsLayerTreeModel * model() const
Return pointer to model owning this legend node.
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
void legendMapViewData(double *mapUnitsPerPixel, int *dpi, double *scale)
Get hints about map view - to be used in legend nodes.
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const
Returns style.
void triggerRepaint()
Will advice the map canvas (and any other interested party) that this layer requires to be repainted...
bool isCheckable() const
Return whether the item is user-checkable - whether renderer supports enabling/disabling it...
void setWidthF(qreal width)
void setBrush(const QBrush &brush)
void setPainter(QPainter *p)
void drawText(const QPointF &position, const QString &text)
void setColor(const QColor &color)
QString label() const
Return text label.
void paint(QPainter *painter, const QRect &rect, QFlags< Qt::AlignmentFlag > alignment, Mode mode, State state) const
virtual void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
const QgsSymbolV2 * symbol() const
Returns the symbol used by the legend node.
void dataChanged()
Emitted on internal data change so the layer tree model can forward the signal to views...
QSizeF symbolSize() const
double fontHeightCharacterMM(const QFont &font, QChar c) const
Returns the font height of a character in millimeters.
virtual ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx)
Entry point called from QgsLegendRenderer to do the rendering.
QgsSymbolV2 * symbol() const
Return associated symbol. May be null.
QgsMapLayer * layer() const
virtual bool setData(const QVariant &value, int role) override
Set some data associated with the item.
QgsSymbolV2::OutputUnit outputUnit() const
QgsSimpleLegendNode(QgsLayerTreeLayer *nodeLayer, const QString &label, const QIcon &icon=QIcon(), QObject *parent=nullptr, const QString &key=QString())
virtual void setEmbeddedInParent(bool embedded)
Contains information about the context of a rendering operation.
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
QSize minimumIconSize() const
Get 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.
QPointF point
Top-left corner of the legend item.
static QPixmap symbolPreviewPixmap(QgsSymbolV2 *symbol, QSize size, QgsRenderContext *customContext=nullptr)
void setMapToPixel(const QgsMapToPixel &mtp)
virtual QVariant data(int role) const =0
Return data associated with the item.
static QRect nonTransparentImageRect(const QImage &image, QSize minSize=QSize(), bool center=false)
Calculates the non-transparent region of an image.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
void translate(const QPointF &offset)
QgsSymbolV2 * legacyRuleKey() const
Used for older code that identifies legend entries from symbol pointer within renderer.
for QgsSymbolV2LegendNode only - legacy rule key (void ptr, to be cast to QgsSymbolV2 ptr) ...
QString layerName() const
void setSymbol(QgsSymbolV2 *symbol)
Sets the symbol to be used by the legend node.
QgsRasterDataProvider * dataProvider()
Returns the data provider.
void uncheckAllItems()
Unchecks all items belonging to the same layer as this node.
virtual QSizeF drawSymbolText(const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize) const
Draws label on the right side of the item.
int level() const
Identation level that tells how deep the item is in a hierarchy of items. For flat lists level is 0...
QColor rasterBorderColor() const
Returns the border color for the border drawn around raster symbol items.
virtual QVariant data(int role) const override
Return data associated with the item.
double lineSpacing() const
For legends that support it, will show them in a tree instead of a list (needs also ShowLegend)...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setSymbol(QgsSymbolV2 *s)
Set symbol of the item. Takes ownership of symbol.
double scaleFactor() const
Represents a vector layer which manages a vector based data sets.
double labelXOffset
offset from the left side where label should start
bool begin(QPaintDevice *device)
bool drawRasterBorder() const
Returns whether a border will be drawn around raster symbol items.
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
double mmPerMapUnit() const
Raster renderer pipe that applies colors to a raster.
virtual void setLegendSymbolItem(const QString &key, QgsSymbolV2 *symbol)
Sets the symbol to be used for a legend symbol item.
QgsSymbolV2LegendNode(QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItemV2 &item, QObject *parent=nullptr)
Layer tree node points to a map layer.
Base class for raster data providers.