34 , mEmbeddedInParent( false )
49 return Qt::ItemIsEnabled;
68 double itemHeight = qMax((
double ) settings.
symbolSize().height(), textHeight );
79 QIcon symbolIcon =
data( Qt::DecorationRole ).value<QIcon>();
80 if ( symbolIcon.isNull() )
92 QSizeF labelSize( 0, 0 );
99 labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * settings.
lineSpacing();
101 double labelX, labelY;
106 labelX = ctx->
point.x() + qMax((
double ) symbolSize.width(), ctx->
labelXOffset );
107 labelY = ctx->
point.y();
110 if ( labelSize.height() < symbolSize.height() )
111 labelY += symbolSize.height() / 2 + textHeight / 2;
113 labelY += textHeight;
116 for ( QStringList::Iterator itemPart = lines.begin(); itemPart != lines.end(); ++itemPart )
118 labelSize.rwidth() = qMax( settings.
textWidthMillimeters( symbolLabelFont, *itemPart ), double( labelSize.width() ) );
122 settings.
drawText( ctx->
painter, labelX, labelY, *itemPart, symbolLabelFont );
123 if ( itemPart != lines.end() )
137 , mSymbolUsesMapUnits( false )
152 return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
154 return Qt::ItemIsEnabled;
160 if ( role == Qt::DisplayRole )
164 else if ( role == Qt::EditRole )
168 else if ( role == Qt::DecorationRole )
170 QSize iconSize( 16, 16 );
171 const int indentSize = 20;
172 if ( mPixmap.isNull() )
182 bool validData = mupp != 0 && dpi != 0 && scale != 0;
194 pix = QPixmap( iconSize );
195 pix.fill( Qt::transparent );
203 QPixmap pix2( pix.width() + mItem.
level() * indentSize, pix.height() );
204 pix2.fill( Qt::transparent );
206 p.drawPixmap( mItem.
level() * indentSize, 0, pix );
213 else if ( role == Qt::CheckStateRole )
242 if ( role != Qt::CheckStateRole )
280 double height = settings.
symbolSize().height();
284 double widthOffset = 0;
285 double heightOffset = 0;
295 widthOffset = ( settings.
symbolSize().width() - width ) / 2.0;
297 if ( height < settings.
symbolSize().height() )
299 heightOffset = ( settings.
symbolSize().height() - height ) / 2.0;
305 double currentXPosition = ctx->
point.x();
306 double currentYCoord = ctx->
point.y() + ( itemHeight - settings.
symbolSize().height() ) / 2;
314 opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 );
317 p->setRenderHint( QPainter::Antialiasing );
318 p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
319 p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
324 QSize tempImageSize( width * dotsPerMM, height * dotsPerMM );
325 QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
326 tempImage.fill( Qt::transparent );
327 QPainter imagePainter( &tempImage );
332 imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
333 imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
336 p->drawImage( 0, 0, tempImage );
340 s->
drawPreviewIcon( p, QSize( width * dotsPerMM, height * dotsPerMM ), &context );
345 return QSizeF( qMax( width + 2 * widthOffset, (
double ) settings.
symbolSize().width() ),
346 qMax( height + 2 * heightOffset, (
double ) settings.
symbolSize().height() ) );
359 if ( mSymbolUsesMapUnits )
367 void QgsSymbolV2LegendNode::updateLabel()
405 if ( role == Qt::DisplayRole || role == Qt::EditRole )
407 else if ( role == Qt::DecorationRole )
426 if ( role == Qt::DecorationRole )
428 return QPixmap::fromImage( mImage );
430 else if ( role == Qt::SizeHintRole )
432 return mImage.size();
439 Q_UNUSED( itemHeight );
444 mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
460 if ( role == Qt::DecorationRole )
462 QSize iconSize( 16, 16 );
463 QPixmap pix( iconSize );
467 else if ( role == Qt::DisplayRole || role == Qt::EditRole )
478 QColor itemColor = mColor;
482 itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
485 ctx->
painter->setBrush( itemColor );
500 const QImage& QgsWMSLegendNode::getLegendGraphic()
const 502 if ( ! mValid && ! mFetcher )
509 if ( ! mod )
return mImage;
514 Q_ASSERT( ! mFetcher );
518 connect( mFetcher.data(), SIGNAL( finish(
const QImage& ) ),
this, SLOT( getLegendGraphicFinished(
const QImage& ) ) );
519 connect( mFetcher.data(), SIGNAL( error(
const QString& ) ),
this, SLOT( getLegendGraphicErrored(
const QString& ) ) );
520 connect( mFetcher.data(), SIGNAL( progress( qint64, qint64 ) ),
this, SLOT( getLegendGraphicProgress( qint64, qint64 ) ) );
533 if ( role == Qt::DecorationRole )
535 return QPixmap::fromImage( getLegendGraphic() );
537 else if ( role == Qt::SizeHintRole )
539 return getLegendGraphic().size();
546 Q_UNUSED( itemHeight );
552 QRectF( QPointF( 0, 0 ), mImage.size() ) );
558 QImage QgsWMSLegendNode::renderMessage(
const QString& msg )
const 560 const int fontHeight = 10;
561 const int margin = fontHeight / 2;
562 const int nlines = 1;
564 const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
565 QImage theImage( w, h, QImage::Format_ARGB32_Premultiplied );
567 painter.begin( &theImage );
568 painter.setPen( QColor( 255, 0, 0 ) );
569 painter.setFont( QFont(
"Chicago", fontHeight ) );
570 painter.fillRect( 0, 0, w, h, QColor( 255, 255, 255 ) );
571 painter.drawText( 0, margin + fontHeight, msg );
578 void QgsWMSLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
580 QString msg = QString(
"Downloading... %1/%2" ).arg( cur ).arg( tot );
582 mImage = renderMessage( msg );
586 void QgsWMSLegendNode::getLegendGraphicErrored(
const QString& msg )
588 if ( ! mFetcher )
return;
590 mImage = renderMessage( msg );
602 void QgsWMSLegendNode::getLegendGraphicFinished(
const QImage& theImage )
604 if ( ! mFetcher )
return;
607 if ( ! theImage.isNull() )
609 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
~QgsLayerTreeModelLegendNode()
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 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
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.
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.
The QgsMapSettings class contains configuration for rendering of the map.
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 setScaleFactor(double factor)
rule key of the node (QString)
virtual bool legendSymbolItemChecked(QString key)
items of symbology items in legend is checked
virtual QVariant data(int role) const override
Return data associated with the item.
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 setPainter(QPainter *p)
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
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...
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.
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
The class stores information about one class/rule of a vector layer renderer in a unified way that ca...
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...