QGIS API Documentation  2.8.6-Wien
qgslayertreemodellegendnode.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayertreemodellegendnode.cpp
3  --------------------------------------
4  Date : August 2014
5  Copyright : (C) 2014 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7 
8  QgsWMSLegendNode : Sandro Santilli < strk at keybit dot net >
9 
10  ***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
20 
21 #include "qgslayertree.h"
22 #include "qgslayertreemodel.h"
23 #include "qgslegendsettings.h"
24 #include "qgsrasterlayer.h"
25 #include "qgsrendererv2.h"
26 #include "qgssymbollayerv2utils.h"
27 #include "qgsvectorlayer.h"
28 
29 
30 
32  : QObject( parent )
33  , mLayerNode( nodeL )
34  , mEmbeddedInParent( false )
35 {
36 }
37 
39 {
40 }
41 
43 {
44  return qobject_cast<QgsLayerTreeModel*>( parent() );
45 }
46 
48 {
49  return Qt::ItemIsEnabled;
50 }
51 
52 bool QgsLayerTreeModelLegendNode::setData( const QVariant& value, int role )
53 {
54  Q_UNUSED( value );
55  Q_UNUSED( role );
56  return false;
57 }
58 
59 
61 {
62  QFont symbolLabelFont = settings.style( QgsComposerLegendStyle::SymbolLabel ).font();
63 
64  double textHeight = settings.fontHeightCharacterMM( symbolLabelFont, QChar( '0' ) );
65  // itemHeight here is not realy item height, it is only for symbol
66  // vertical alignment purpose, i.e. ok take single line height
67  // if there are more lines, thos run under the symbol
68  double itemHeight = qMax(( double ) settings.symbolSize().height(), textHeight );
69 
70  ItemMetrics im;
71  im.symbolSize = drawSymbol( settings, ctx, itemHeight );
72  im.labelSize = drawSymbolText( settings, ctx, im.symbolSize );
73  return im;
74 }
75 
76 
77 QSizeF QgsLayerTreeModelLegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const
78 {
79  QIcon symbolIcon = data( Qt::DecorationRole ).value<QIcon>();
80  if ( symbolIcon.isNull() )
81  return QSizeF();
82 
83  if ( ctx )
84  symbolIcon.paint( ctx->painter, ctx->point.x(), ctx->point.y() + ( itemHeight - settings.symbolSize().height() ) / 2,
85  settings.symbolSize().width(), settings.symbolSize().height() );
86  return settings.symbolSize();
87 }
88 
89 
90 QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings& settings, ItemContext* ctx, const QSizeF& symbolSize ) const
91 {
92  QSizeF labelSize( 0, 0 );
93 
94  QFont symbolLabelFont = settings.style( QgsComposerLegendStyle::SymbolLabel ).font();
95  double textHeight = settings.fontHeightCharacterMM( symbolLabelFont, QChar( '0' ) );
96 
97  QStringList lines = settings.splitStringForWrapping( data( Qt::DisplayRole ).toString() );
98 
99  labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * settings.lineSpacing();
100 
101  double labelX, labelY;
102  if ( ctx )
103  {
104  ctx->painter->setPen( settings.fontColor() );
105 
106  labelX = ctx->point.x() + qMax(( double ) symbolSize.width(), ctx->labelXOffset );
107  labelY = ctx->point.y();
108 
109  // Vertical alignment of label with symbol
110  if ( labelSize.height() < symbolSize.height() )
111  labelY += symbolSize.height() / 2 + textHeight / 2; // label centered with symbol
112  else
113  labelY += textHeight; // label starts at top and runs under symbol
114  }
115 
116  for ( QStringList::Iterator itemPart = lines.begin(); itemPart != lines.end(); ++itemPart )
117  {
118  labelSize.rwidth() = qMax( settings.textWidthMillimeters( symbolLabelFont, *itemPart ), double( labelSize.width() ) );
119 
120  if ( ctx )
121  {
122  settings.drawText( ctx->painter, labelX, labelY, *itemPart, symbolLabelFont );
123  if ( itemPart != lines.end() )
124  labelY += settings.lineSpacing() + textHeight;
125  }
126  }
127 
128  return labelSize;
129 }
130 
131 // -------------------------------------------------------------------------
132 
133 
135  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
136  , mItem( item )
137  , mSymbolUsesMapUnits( false )
138 {
139  updateLabel();
140 
141  if ( mItem.symbol() )
142  mSymbolUsesMapUnits = ( mItem.symbol()->outputUnit() != QgsSymbolV2::MM );
143 }
144 
146 {
147 }
148 
149 Qt::ItemFlags QgsSymbolV2LegendNode::flags() const
150 {
151  if ( mItem.isCheckable() )
152  return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
153  else
154  return Qt::ItemIsEnabled;
155 }
156 
157 
158 QVariant QgsSymbolV2LegendNode::data( int role ) const
159 {
160  if ( role == Qt::DisplayRole )
161  {
162  return mLabel;
163  }
164  else if ( role == Qt::EditRole )
165  {
166  return mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
167  }
168  else if ( role == Qt::DecorationRole )
169  {
170  QSize iconSize( 16, 16 ); // TODO: configurable
171  const int indentSize = 20;
172  if ( mPixmap.isNull() )
173  {
174  QPixmap pix;
175  if ( mItem.symbol() )
176  {
177  double scale = 0.0;
178  double mupp = 0.0;
179  int dpi = 0;
180  if ( model() )
181  model()->legendMapViewData( &mupp, &dpi, &scale );
182  bool validData = mupp != 0 && dpi != 0 && scale != 0;
183 
184  // setup temporary render context
185  QgsRenderContext context;
186  context.setScaleFactor( dpi / 25.4 );
187  context.setRendererScale( scale );
188  context.setMapToPixel( QgsMapToPixel( mupp ) ); // hope it's ok to leave out other params
189 
190  pix = QgsSymbolLayerV2Utils::symbolPreviewPixmap( mItem.symbol(), iconSize, validData ? &context : 0 );
191  }
192  else
193  {
194  pix = QPixmap( iconSize );
195  pix.fill( Qt::transparent );
196  }
197 
198  if ( mItem.level() == 0 || ( model() && model()->testFlag( QgsLayerTreeModel::ShowLegendAsTree ) ) )
199  mPixmap = pix;
200  else
201  {
202  // ident the symbol icon to make it look like a tree structure
203  QPixmap pix2( pix.width() + mItem.level() * indentSize, pix.height() );
204  pix2.fill( Qt::transparent );
205  QPainter p( &pix2 );
206  p.drawPixmap( mItem.level() * indentSize, 0, pix );
207  p.end();
208  mPixmap = pix2;
209  }
210  }
211  return mPixmap;
212  }
213  else if ( role == Qt::CheckStateRole )
214  {
215  if ( !mItem.isCheckable() )
216  return QVariant();
217 
218  QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
219  if ( !vlayer || !vlayer->rendererV2() )
220  return QVariant();
221 
222  return vlayer->rendererV2()->legendSymbolItemChecked( mItem.ruleKey() ) ? Qt::Checked : Qt::Unchecked;
223  }
224  else if ( role == RuleKeyRole )
225  {
226  return mItem.ruleKey();
227  }
228  else if ( role == SymbolV2LegacyRuleKeyRole )
229  {
230  return QVariant::fromValue<void*>( mItem.legacyRuleKey() );
231  }
232  else if ( role == ParentRuleKeyRole )
233  {
234  return mItem.parentRuleKey();
235  }
236 
237  return QVariant();
238 }
239 
240 bool QgsSymbolV2LegendNode::setData( const QVariant& value, int role )
241 {
242  if ( role != Qt::CheckStateRole )
243  return false;
244 
245  if ( !mItem.isCheckable() )
246  return false;
247 
248  QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
249  if ( !vlayer || !vlayer->rendererV2() )
250  return false;
251 
252  vlayer->rendererV2()->checkLegendSymbolItem( mItem.ruleKey(), value == Qt::Checked );
253 
254  emit dataChanged();
255 
256  vlayer->triggerRepaint();
257 
258  return true;
259 }
260 
261 
262 
263 QSizeF QgsSymbolV2LegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const
264 {
265  QgsSymbolV2* s = mItem.symbol();
266  if ( !s )
267  {
268  return QSizeF();
269  }
270 
271  // setup temporary render context
272  QgsRenderContext context;
273  context.setScaleFactor( settings.dpi() / 25.4 );
274  context.setRendererScale( settings.mapScale() );
275  context.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * context.scaleFactor() ) ) ); // hope it's ok to leave out other params
276  context.setForceVectorOutput( true );
277  context.setPainter( ctx ? ctx->painter : 0 );
278 
279  //Consider symbol size for point markers
280  double height = settings.symbolSize().height();
281  double width = settings.symbolSize().width();
282  double size = 0;
283  //Center small marker symbols
284  double widthOffset = 0;
285  double heightOffset = 0;
286 
287  if ( QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( s ) )
288  {
289  // allow marker symbol to occupy bigger area if necessary
290  size = markerSymbol->size() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context, s->outputUnit(), s->mapUnitScale() ) / context.scaleFactor();
291  height = size;
292  width = size;
293  if ( width < settings.symbolSize().width() )
294  {
295  widthOffset = ( settings.symbolSize().width() - width ) / 2.0;
296  }
297  if ( height < settings.symbolSize().height() )
298  {
299  heightOffset = ( settings.symbolSize().height() - height ) / 2.0;
300  }
301  }
302 
303  if ( ctx )
304  {
305  double currentXPosition = ctx->point.x();
306  double currentYCoord = ctx->point.y() + ( itemHeight - settings.symbolSize().height() ) / 2;
307  QPainter* p = ctx->painter;
308 
309  //setup painter scaling to dots so that raster symbology is drawn to scale
310  double dotsPerMM = context.scaleFactor();
311 
312  int opacity = 255;
313  if ( QgsVectorLayer* vectorLayer = dynamic_cast<QgsVectorLayer*>( layerNode()->layer() ) )
314  opacity = 255 - ( 255 * vectorLayer->layerTransparency() / 100 );
315 
316  p->save();
317  p->setRenderHint( QPainter::Antialiasing );
318  p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
319  p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
320  if ( opacity != 255 && settings.useAdvancedEffects() )
321  {
322  //semi transparent layer, so need to draw symbol to an image (to flatten it first)
323  //create image which is same size as legend rect, in case symbol bleeds outside its alloted space
324  QSize tempImageSize( width * dotsPerMM, height * dotsPerMM );
325  QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
326  tempImage.fill( Qt::transparent );
327  QPainter imagePainter( &tempImage );
328  context.setPainter( &imagePainter );
329  s->drawPreviewIcon( &imagePainter, tempImageSize, &context );
330  context.setPainter( ctx->painter );
331  //reduce opacity of image
332  imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
333  imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
334  imagePainter.end();
335  //draw rendered symbol image
336  p->drawImage( 0, 0, tempImage );
337  }
338  else
339  {
340  s->drawPreviewIcon( p, QSize( width * dotsPerMM, height * dotsPerMM ), &context );
341  }
342  p->restore();
343  }
344 
345  return QSizeF( qMax( width + 2 * widthOffset, ( double ) settings.symbolSize().width() ),
346  qMax( height + 2 * heightOffset, ( double ) settings.symbolSize().height() ) );
347 }
348 
349 
351 {
353  updateLabel();
354 }
355 
356 
358 {
359  if ( mSymbolUsesMapUnits )
360  {
361  mPixmap = QPixmap();
362  emit dataChanged();
363  }
364 }
365 
366 
367 void QgsSymbolV2LegendNode::updateLabel()
368 {
369  bool showFeatureCount = mLayerNode->customProperty( "showFeatureCount", 0 ).toBool();
370  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
371 
372  if ( mEmbeddedInParent )
373  {
374  QString layerName = mLayerNode->layerName();
375  if ( !mLayerNode->customProperty( "legend/title-label" ).isNull() )
376  layerName = mLayerNode->customProperty( "legend/title-label" ).toString();
377 
378  mLabel = mUserLabel.isEmpty() ? layerName : mUserLabel;
379  if ( showFeatureCount && vl && vl->pendingFeatureCount() >= 0 )
380  mLabel += QString( " [%1]" ).arg( vl->pendingFeatureCount() );
381  }
382  else
383  {
384  mLabel = mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
385  if ( showFeatureCount && vl && mItem.legacyRuleKey() )
386  mLabel += QString( " [%1]" ).arg( vl->featureCount( mItem.legacyRuleKey() ) );
387  }
388 }
389 
390 
391 
392 // -------------------------------------------------------------------------
393 
394 
395 QgsSimpleLegendNode::QgsSimpleLegendNode( QgsLayerTreeLayer* nodeLayer, const QString& label, const QIcon& icon, QObject* parent, const QString& key )
396  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
397  , mLabel( label )
398  , mIcon( icon )
399  , mKey( key )
400 {
401 }
402 
403 QVariant QgsSimpleLegendNode::data( int role ) const
404 {
405  if ( role == Qt::DisplayRole || role == Qt::EditRole )
406  return mUserLabel.isEmpty() ? mLabel : mUserLabel;
407  else if ( role == Qt::DecorationRole )
408  return mIcon;
409  else if ( role == RuleKeyRole && !mKey.isEmpty() )
410  return mKey;
411  else
412  return QVariant();
413 }
414 
415 
416 // -------------------------------------------------------------------------
417 
418 QgsImageLegendNode::QgsImageLegendNode( QgsLayerTreeLayer* nodeLayer, const QImage& img, QObject* parent )
419  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
420  , mImage( img )
421 {
422 }
423 
424 QVariant QgsImageLegendNode::data( int role ) const
425 {
426  if ( role == Qt::DecorationRole )
427  {
428  return QPixmap::fromImage( mImage );
429  }
430  else if ( role == Qt::SizeHintRole )
431  {
432  return mImage.size();
433  }
434  return QVariant();
435 }
436 
437 QSizeF QgsImageLegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const
438 {
439  Q_UNUSED( itemHeight );
440 
441  if ( ctx )
442  {
443  ctx->painter->drawImage( QRectF( ctx->point.x(), ctx->point.y(), settings.wmsLegendSize().width(), settings.wmsLegendSize().height() ),
444  mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
445  }
446  return settings.wmsLegendSize();
447 }
448 
449 // -------------------------------------------------------------------------
450 
451 QgsRasterSymbolLegendNode::QgsRasterSymbolLegendNode( QgsLayerTreeLayer* nodeLayer, const QColor& color, const QString& label, QObject* parent )
452  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
453  , mColor( color )
454  , mLabel( label )
455 {
456 }
457 
458 QVariant QgsRasterSymbolLegendNode::data( int role ) const
459 {
460  if ( role == Qt::DecorationRole )
461  {
462  QSize iconSize( 16, 16 ); // TODO: configurable?
463  QPixmap pix( iconSize );
464  pix.fill( mColor );
465  return QIcon( pix );
466  }
467  else if ( role == Qt::DisplayRole || role == Qt::EditRole )
468  return mUserLabel.isEmpty() ? mLabel : mUserLabel;
469  else
470  return QVariant();
471 }
472 
473 
474 QSizeF QgsRasterSymbolLegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const
475 {
476  if ( ctx )
477  {
478  QColor itemColor = mColor;
479  if ( QgsRasterLayer* rasterLayer = dynamic_cast<QgsRasterLayer*>( layerNode()->layer() ) )
480  {
481  if ( QgsRasterRenderer* rasterRenderer = rasterLayer->renderer() )
482  itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
483  }
484 
485  ctx->painter->setBrush( itemColor );
486  ctx->painter->drawRect( QRectF( ctx->point.x(), ctx->point.y() + ( itemHeight - settings.symbolSize().height() ) / 2,
487  settings.symbolSize().width(), settings.symbolSize().height() ) );
488  }
489  return settings.symbolSize();
490 }
491 
492 // -------------------------------------------------------------------------
493 
495  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
496  , mValid( false )
497 {
498 }
499 
500 const QImage& QgsWMSLegendNode::getLegendGraphic() const
501 {
502  if ( ! mValid && ! mFetcher )
503  {
504  // or maybe in presence of a downloader we should just delete it
505  // and start a new one ?
506 
507  QgsRasterLayer* layer = qobject_cast<QgsRasterLayer*>( mLayerNode->layer() );
508  const QgsLayerTreeModel* mod = model();
509  if ( ! mod ) return mImage;
510  const QgsMapSettings* ms = mod->legendFilterByMap();
511 
512  QgsRasterDataProvider* prov = layer->dataProvider();
513 
514  Q_ASSERT( ! mFetcher );
515  mFetcher.reset( prov->getLegendGraphicFetcher( ms ) );
516  if ( mFetcher )
517  {
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 ) ) );
521  mFetcher->start();
522  } // else QgsDebugMsg("XXX No legend supported ?");
523 
524  }
525 
526  return mImage;
527 }
528 
529 QVariant QgsWMSLegendNode::data( int role ) const
530 {
531  //QgsDebugMsg( QString("XXX data called with role %1 -- mImage size is %2x%3").arg(role).arg(mImage.width()).arg(mImage.height()) );
532 
533  if ( role == Qt::DecorationRole )
534  {
535  return QPixmap::fromImage( getLegendGraphic() );
536  }
537  else if ( role == Qt::SizeHintRole )
538  {
539  return getLegendGraphic().size();
540  }
541  return QVariant();
542 }
543 
544 QSizeF QgsWMSLegendNode::drawSymbol( const QgsLegendSettings& settings, ItemContext* ctx, double itemHeight ) const
545 {
546  Q_UNUSED( itemHeight );
547 
548  if ( ctx )
549  {
550  ctx->painter->drawImage( QRectF( ctx->point, settings.wmsLegendSize() ),
551  mImage,
552  QRectF( QPointF( 0, 0 ), mImage.size() ) );
553  }
554  return settings.wmsLegendSize();
555 }
556 
557 /* private */
558 QImage QgsWMSLegendNode::renderMessage( const QString& msg ) const
559 {
560  const int fontHeight = 10;
561  const int margin = fontHeight / 2;
562  const int nlines = 1;
563 
564  const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
565  QImage theImage( w, h, QImage::Format_ARGB32_Premultiplied );
566  QPainter painter;
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 );
572  //painter.drawText(0,2*(margin+fontHeight),QString("retrying in 5 seconds..."));
573  painter.end();
574 
575  return theImage;
576 }
577 
578 void QgsWMSLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
579 {
580  QString msg = QString( "Downloading... %1/%2" ).arg( cur ).arg( tot );
581  //QgsDebugMsg ( QString("XXX %1").arg(msg) );
582  mImage = renderMessage( msg );
583  emit dataChanged();
584 }
585 
586 void QgsWMSLegendNode::getLegendGraphicErrored( const QString& msg )
587 {
588  if ( ! mFetcher ) return; // must be coming after finish
589 
590  mImage = renderMessage( msg );
591  //QgsDebugMsg( QString("XXX emitting dataChanged after writing an image of %1x%2").arg(mImage.width()).arg(mImage.height()) );
592 
593  emit dataChanged();
594 
595  mFetcher.reset();
596 
597  mValid = true; // we consider it valid anyway
598  // ... but remove validity after 5 seconds
599  //QTimer::singleShot(5000, this, SLOT(invalidateMapBasedData()));
600 }
601 
602 void QgsWMSLegendNode::getLegendGraphicFinished( const QImage& theImage )
603 {
604  if ( ! mFetcher ) return; // must be coming after error
605 
606  //QgsDebugMsg( QString("XXX legend graphic finished, image is %1x%2").arg(theImage.width()).arg(theImage.height()) );
607  if ( ! theImage.isNull() )
608  {
609  if ( theImage != mImage )
610  {
611  mImage = theImage;
612  //QgsDebugMsg( QString("XXX emitting dataChanged") );
613  emit dataChanged();
614  }
615  mValid = true; // only if not null I guess
616  }
617  mFetcher.reset();
618 }
619 
621 {
622  //QgsDebugMsg( QString("XXX invalidateMapBasedData called") );
623  // TODO: do this only if this extent != prev extent ?
624  mValid = false;
625  emit dataChanged();
626 }
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
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
Definition: qgssymbolv2.cpp:84
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.
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.
QColor fontColor() const
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
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)
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.
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.
double mapScale() const
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
Definition: qgssymbolv2.cpp:63
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...