35 , mEmbeddedInParent( false )
50 return Qt::ItemIsEnabled;
69 double itemHeight = qMax((
double ) settings.
symbolSize().
height(), textHeight );
102 double labelX = 0.0, labelY = 0.0;
112 labelY += symbolSize.
height() / 2 + textHeight / 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;
176 context.
data() ).toImage(),
192 QgsRenderContext * QgsSymbolV2LegendNode::createTemporaryRenderContext()
const
199 bool validData = mupp != 0 && dpi != 0 && scale != 0;
203 context->setScaleFactor( dpi / 25.4 );
204 context->setRendererScale( scale );
206 return validData ? context.take() : 0;
211 if ( role == Qt::DisplayRole )
215 else if ( role == Qt::EditRole )
219 else if ( role == Qt::DecorationRole )
221 if ( mPixmap.
isNull() || mPixmap.
size() != mIconSize )
232 pix.
fill( Qt::transparent );
241 pix2.
fill( Qt::transparent );
250 else if ( role == Qt::CheckStateRole )
279 if ( role != Qt::CheckStateRole )
321 double widthOffset = 0;
322 double heightOffset = 0;
342 double currentXPosition = ctx->
point.
x();
351 opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 );
355 p->
translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
356 p->
scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
361 QSize tempImageSize( width * dotsPerMM, height * dotsPerMM );
362 QImage tempImage =
QImage( tempImageSize, QImage::Format_ARGB32 );
363 tempImage.
fill( Qt::transparent );
364 QPainter imagePainter( &tempImage );
383 qMax( height + 2 * heightOffset, (
double ) settings.
symbolSize().
height() ) );
396 if ( mSymbolUsesMapUnits )
404 void QgsSymbolV2LegendNode::updateLabel()
442 if ( role == Qt::DisplayRole || role == Qt::EditRole )
444 else if ( role == Qt::DecorationRole )
463 if ( role == Qt::DecorationRole )
467 else if ( role == Qt::SizeHintRole )
469 return mImage.
size();
476 Q_UNUSED( itemHeight );
497 if ( role == Qt::DecorationRole )
499 QSize iconSize( 16, 16 );
504 else if ( role == Qt::DisplayRole || role == Qt::EditRole )
515 QColor itemColor = mColor;
519 itemColor.
setAlpha( rasterRenderer->opacity() * 255.0 );
537 const QImage& QgsWMSLegendNode::getLegendGraphic()
const
539 if ( ! mValid && ! mFetcher )
546 if ( ! mod )
return mImage;
551 Q_ASSERT( ! mFetcher );
555 connect( mFetcher.
data(), SIGNAL( finish(
const QImage& ) ),
this, SLOT( getLegendGraphicFinished(
const QImage& ) ) );
557 connect( mFetcher.
data(), SIGNAL( progress( qint64, qint64 ) ),
this, SLOT( getLegendGraphicProgress( qint64, qint64 ) ) );
570 if ( role == Qt::DecorationRole )
574 else if ( role == Qt::SizeHintRole )
576 return getLegendGraphic().
size();
583 Q_UNUSED( itemHeight );
595 QImage QgsWMSLegendNode::renderMessage(
const QString& msg )
const
597 const int fontHeight = 10;
598 const int margin = fontHeight / 2;
599 const int nlines = 1;
601 const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
602 QImage theImage( w, h, QImage::Format_ARGB32_Premultiplied );
604 painter.
begin( &theImage );
608 painter.
drawText( 0, margin + fontHeight, msg );
615 void QgsWMSLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
619 mImage = renderMessage( msg );
623 void QgsWMSLegendNode::getLegendGraphicErrored(
const QString& msg )
625 if ( ! mFetcher )
return;
627 mImage = renderMessage( msg );
639 void QgsWMSLegendNode::getLegendGraphicFinished(
const QImage& theImage )
641 if ( ! mFetcher )
return;
644 if ( ! theImage.
isNull() )
646 if ( theImage != mImage )
void setForceVectorOutput(bool force)
QStringList splitStringForWrapping(QString stringToSplt) const
Splits a string using the wrap char taking into account handling empty wrap char which means no wrapp...
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
QgsSymbolV2LegendNode(QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItemV2 &item, QObject *parent=0)
virtual void checkLegendSymbolItem(QString key, bool state=true)
item in symbology was checked
double lineSpacing() const
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setCompositionMode(CompositionMode mode)
~QgsLayerTreeModelLegendNode()
void setRenderHint(RenderHint hint, bool on)
void fill(const QColor &color)
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QgsMapLayer * layer() const
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.
void scale(qreal sx, qreal sy)
void setRendererScale(double scale)
QString label() const
Return text label.
QgsSymbolV2 * legacyRuleKey() const
Used for older code that identifies legend entries from symbol pointer within renderer.
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.
QgsWMSLegendNode(QgsLayerTreeLayer *nodeLayer, QObject *parent=0)
QgsMapUnitScale mapUnitScale() const
QSize minimumIconSize() const
Get the minimum icon size to prevent cropping.
QgsSimpleLegendNode(QgsLayerTreeLayer *nodeLayer, const QString &label, const QIcon &icon=QIcon(), QObject *parent=0, const QString &key=QString())
QString parentRuleKey() const
Key of the parent legend node.
QPixmap fromImage(const QImage &image, QFlags< Qt::ImageConversionFlag > flags)
int level() const
Identation level that tells how deep the item is in a hierarchy of items. For flat lists level is 0...
virtual QVariant data(int role) const override
Return data associated with the item.
virtual Qt::ItemFlags flags() const
Return item flags associated with the item.
virtual QVariant data(int role) const override
Return data associated with the item.
double mmPerMapUnit() const
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
QgsComposerLegendStyle style(QgsComposerLegendStyle::Style s) const
Returns style.
double scaleFactor() const
QString ruleKey() const
Return unique identifier of the rule for identification of the item within renderer.
virtual Qt::ItemFlags flags() const override
Return item flags associated with the item.
QPainter * painter
Painter.
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
QgsSymbolV2 * symbol() const
Return associated symbol. May be null.
static QRect nonTransparentImageRect(const QImage &image, const QSize &minSize=QSize(), bool center=false)
Calculates the non-transparent region of an image.
The QgsMapSettings class contains configuration for rendering of the map.
void drawRect(const QRectF &rectangle)
Perform transforms between map coordinates and device coordinates.
The QgsLayerTreeModel class is model implementation for Qt item views framework.
rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2...
void setFont(const QFont &font)
int count(const T &value) const
void setScaleFactor(double factor)
void fill(uint pixelValue)
rule key of the node (QString)
virtual bool legendSymbolItemChecked(QString key)
items of symbology items in legend is checked
void setPen(const QColor &color)
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
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
QgsLayerTreeLayer * mLayerNode
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
void legendMapViewData(double *mapUnitsPerPixel, int *dpi, double *scale)
Get hints about map view - to be used in legend nodes.
void triggerRepaint()
Will advice the map canvas (and any other interested party) that this layer requires to be repainted...
QgsLayerTreeLayer * layerNode() const
Return pointer to the parent layer node.
int pendingFeatureCount()
returns feature count after commit
void setBrush(const QBrush &brush)
void setPainter(QPainter *p)
void drawText(const QPointF &position, const QString &text)
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.
void dataChanged()
Emitted on internal data change so the layer tree model can forward the signal to views...
bool testFlag(Flag f) const
Check whether a flag is enabled.
virtual ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx)
Entry point called from QgsLegendRenderer to do the rendering.
double fontHeightCharacterMM(const QFont &font, const QChar &c) const
Returns the font height of a character in millimeters.
virtual QSizeF drawSymbolText(const QgsLegendSettings &settings, ItemContext *ctx, const QSizeF &symbolSize) const
Draws label on the right side of the item.
virtual bool setData(const QVariant &value, int role) override
Set some data associated with the item.
virtual long featureCount() const
Number of features in the layer.
virtual void setEmbeddedInParent(bool embedded)
Contains information about the context of a rendering operation.
bool useAdvancedEffects() const
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
QgsRasterSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QColor &color, const QString &label, QObject *parent=0)
static double lineWidthScaleFactor(const QgsRenderContext &c, QgsSymbolV2::OutputUnit u, const QgsMapUnitScale &scale=QgsMapUnitScale())
Returns the line width scale factor depending on the unit and the paint device.
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.
QgsLayerTreeModel * model() const
Return pointer to model owning this legend node.
void setMapToPixel(const QgsMapToPixel &mtp)
QgsSymbolV2::OutputUnit outputUnit() const
virtual QVariant data(int role) const =0
Return data associated with the item.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
void translate(const QPointF &offset)
for QgsSymbolV2LegendNode only - legacy rule key (void ptr, to be cast to QgsSymbolV2 ptr) ...
bool isCheckable() const
Return whether the item is user-checkable - whether renderer supports enabling/disabling it...
QgsRasterDataProvider * dataProvider()
Returns the data provider.
virtual QVariant data(int role) const override
Return data associated with the item.
QSizeF symbolSize() const
QSizeF wmsLegendSize() const
For legends that support it, will show them in a tree instead of a list (needs also ShowLegend)...
static QPixmap symbolPreviewPixmap(QgsSymbolV2 *symbol, QSize size, QgsRenderContext *customContext=0)
void drawPreviewIcon(QPainter *painter, QSize size, QgsRenderContext *customContext=0)
Draw icon of the symbol that occupyies area given by size using the painter.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString layerName() const
QgsImageLegendNode(QgsLayerTreeLayer *nodeLayer, const QImage &img, QObject *parent=0)
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)
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
Raster renderer pipe that applies colors to a raster.
QgsLayerTreeModelLegendNode(QgsLayerTreeLayer *nodeL, QObject *parent=0)
Construct the node with pointer to its parent layer node.
Layer tree node points to a map layer.
Base class for raster data providers.
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...