QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
22 #include "qgslayertree.h"
23 #include "qgslayertreemodel.h"
24 #include "qgslegendsettings.h"
25 #include "qgsrasterlayer.h"
26 #include "qgsrenderer.h"
27 #include "qgssymbollayerutils.h"
28 #include "qgsimageoperation.h"
29 #include "qgsvectorlayer.h"
30 #include "qgsrasterrenderer.h"
32 #include "qgsfeatureid.h"
33 #include "qgslayoutitem.h"
35 #include "qgsexpression.h"
36 #include "qgstextrenderer.h"
37 
38 
40  : QObject( parent )
41  , mLayerNode( nodeL )
42  , mEmbeddedInParent( false )
43 {
44 }
45 
47 {
48  return qobject_cast<QgsLayerTreeModel *>( parent() );
49 }
50 
52 {
53  return Qt::ItemIsEnabled;
54 }
55 
56 bool QgsLayerTreeModelLegendNode::setData( const QVariant &value, int role )
57 {
58  Q_UNUSED( value )
59  Q_UNUSED( role )
60  return false;
61 }
62 
64 {
65  if ( mEmbeddedInParent )
66  return mLayerNode->patchSize();
67 
68  return mUserSize;
69 }
70 
72 {
73  QFont symbolLabelFont = settings.style( QgsLegendStyle::SymbolLabel ).font();
74 
75  double textHeight = settings.fontHeightCharacterMM( symbolLabelFont, QChar( '0' ) );
76  // itemHeight here is not really item height, it is only for symbol
77  // vertical alignment purpose, i.e. OK take single line height
78  // if there are more lines, those run under the symbol
79  double itemHeight = std::max( static_cast< double >( ctx && ctx->patchSize.height() > 0 ? ctx->patchSize.height() : settings.symbolSize().height() ), textHeight );
80 
81  ItemMetrics im;
82  im.symbolSize = drawSymbol( settings, ctx, itemHeight );
83  im.labelSize = drawSymbolText( settings, ctx, im.symbolSize );
84  return im;
85 }
86 
88 {
89  QJsonObject json = exportSymbolToJson( settings, context );
90  const QString text = data( Qt::DisplayRole ).toString();
91  json[ QStringLiteral( "title" ) ] = text;
92  return json;
93 }
94 
95 QSizeF QgsLayerTreeModelLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight ) const
96 {
97  QIcon symbolIcon = data( Qt::DecorationRole ).value<QIcon>();
98  if ( symbolIcon.isNull() )
99  return QSizeF();
100 
101  QSizeF size = settings.symbolSize();
102  if ( ctx )
103  {
104  if ( ctx->patchSize.width() > 0 )
105  size.setWidth( ctx->patchSize.width( ) );
106  if ( ctx->patchSize.height() > 0 )
107  size.setHeight( ctx->patchSize.height( ) );
108  }
109 
110  if ( ctx && ctx->painter )
111  {
112  switch ( settings.symbolAlignment() )
113  {
114  case Qt::AlignLeft:
115  default:
116  symbolIcon.paint( ctx->painter,
117  static_cast< int >( ctx->columnLeft ),
118  static_cast< int >( ctx->top + ( itemHeight - size.height() ) / 2 ),
119  static_cast< int >( size.width() ),
120  static_cast< int >( size.height() ) );
121  break;
122 
123  case Qt::AlignRight:
124  symbolIcon.paint( ctx->painter,
125  static_cast< int >( ctx->columnRight - size.width() ),
126  static_cast< int >( ctx->top + ( itemHeight - size.height() ) / 2 ),
127  static_cast< int >( size.width() ),
128  static_cast< int >( size.height() ) );
129  break;
130  }
131  }
132  return size;
133 }
134 
136 {
137  const QIcon icon = data( Qt::DecorationRole ).value<QIcon>();
138  if ( icon.isNull() )
139  return QJsonObject();
140 
141  const QImage image( icon.pixmap( settings.symbolSize().width(), settings.symbolSize().height() ).toImage() );
142  QByteArray byteArray;
143  QBuffer buffer( &byteArray );
144  image.save( &buffer, "PNG" );
145  const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
146 
147  QJsonObject json;
148  json[ QStringLiteral( "icon" ) ] = base64;
149  return json;
150 }
151 
152 QSizeF QgsLayerTreeModelLegendNode::drawSymbolText( const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize ) const
153 {
154  QSizeF labelSize( 0, 0 );
155 
156  QFont symbolLabelFont = settings.style( QgsLegendStyle::SymbolLabel ).font();
157  double textHeight = settings.fontHeightCharacterMM( symbolLabelFont, QChar( '0' ) );
158  double textDescent = settings.fontDescentMillimeters( symbolLabelFont );
159 
160  QgsExpressionContext tempContext;
161 
162  const QStringList lines = settings.evaluateItemText( data( Qt::DisplayRole ).toString(), ctx && ctx->context ? ctx->context->expressionContext() : tempContext );
163 
164  labelSize.rheight() = lines.count() * textHeight + ( lines.count() - 1 ) * ( settings.lineSpacing() + textDescent );
165 
166  double labelXMin = 0.0;
167  double labelXMax = 0.0;
168  double labelY = 0.0;
169  if ( ctx && ctx->painter )
170  {
171  ctx->painter->setPen( settings.fontColor() );
172  switch ( settings.symbolAlignment() )
173  {
174  case Qt::AlignLeft:
175  default:
176  labelXMin = ctx->columnLeft + std::max( static_cast< double >( symbolSize.width() ), ctx->maxSiblingSymbolWidth )
179  labelXMax = ctx->columnRight;
180  break;
181 
182  case Qt::AlignRight:
183  labelXMin = ctx->columnLeft;
184  // NOTE -- while the below calculations use the flipped margins from the style, that's only done because
185  // those are the only margins we expose and use for now! (and we expose them as generic margins, not side-specific
186  // ones) TODO when/if we expose other margin settings, these should be reversed...
187  labelXMax = ctx->columnRight - std::max( static_cast< double >( symbolSize.width() ), ctx->maxSiblingSymbolWidth )
190  break;
191  }
192 
193  labelY = ctx->top;
194 
195  // Vertical alignment of label with symbol
196  if ( labelSize.height() < symbolSize.height() )
197  labelY += symbolSize.height() / 2 - labelSize.height() / 2; // label centered with symbol
198 
199  labelY += textHeight;
200  }
201 
202  for ( QStringList::ConstIterator itemPart = lines.constBegin(); itemPart != lines.constEnd(); ++itemPart )
203  {
204  const double lineWidth = settings.textWidthMillimeters( symbolLabelFont, *itemPart );
205  labelSize.rwidth() = std::max( lineWidth, double( labelSize.width() ) );
206 
207  if ( ctx && ctx->painter )
208  {
209  switch ( settings.style( QgsLegendStyle::SymbolLabel ).alignment() )
210  {
211  case Qt::AlignLeft:
212  default:
213  settings.drawText( ctx->painter, labelXMin, labelY, *itemPart, symbolLabelFont );
214  break;
215 
216  case Qt::AlignRight:
217  settings.drawText( ctx->painter, labelXMax - lineWidth, labelY, *itemPart, symbolLabelFont );
218  break;
219 
220  case Qt::AlignHCenter:
221  settings.drawText( ctx->painter, labelXMin + ( labelXMax - labelXMin - lineWidth ) / 2.0, labelY, *itemPart, symbolLabelFont );
222  break;
223  }
224 
225  if ( itemPart != ( lines.end() - 1 ) )
226  labelY += textDescent + settings.lineSpacing() + textHeight;
227  }
228  }
229 
230  return labelSize;
231 }
232 
233 // -------------------------------------------------------------------------
234 
236  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
237  , mItem( item )
238  , mSymbolUsesMapUnits( false )
239 {
240  const int iconSize = QgsLayerTreeModel::scaleIconSize( 16 );
241  mIconSize = QSize( iconSize, iconSize );
242 
243  updateLabel();
244  connect( qobject_cast<QgsVectorLayer *>( nodeLayer->layer() ), &QgsVectorLayer::symbolFeatureCountMapChanged, this, &QgsSymbolLegendNode::updateLabel );
245  connect( nodeLayer, &QObject::destroyed, this, [ = ]() { mLayerNode = nullptr; } );
246 
247  if ( mItem.symbol() )
248  mSymbolUsesMapUnits = ( mItem.symbol()->outputUnit() != QgsUnitTypes::RenderMillimeters );
249 }
250 
251 Qt::ItemFlags QgsSymbolLegendNode::flags() const
252 {
253  if ( mItem.isCheckable() )
254  return Qt::ItemIsEnabled | Qt::ItemIsUserCheckable;
255  else
256  return Qt::ItemIsEnabled;
257 }
258 
259 
261 {
262  std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
263  return minimumIconSize( context.get() );
264 }
265 
267 {
268  const int iconSize = QgsLayerTreeModel::scaleIconSize( 16 );
269  const int largeIconSize = QgsLayerTreeModel::scaleIconSize( 512 );
270  QSize minSz( iconSize, iconSize );
271  if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbol::Marker )
272  {
274  QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( largeIconSize, largeIconSize ), 0,
275  context ).toImage(),
276  minSz,
277  true ).size();
278  }
279  else if ( mItem.symbol() && mItem.symbol()->type() == QgsSymbol::Line )
280  {
282  QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), QSize( minSz.width(), largeIconSize ), 0,
283  context ).toImage(),
284  minSz,
285  true ).size();
286  }
287 
288  if ( !mTextOnSymbolLabel.isEmpty() && context )
289  {
290  double w = QgsTextRenderer::textWidth( *context, mTextOnSymbolTextFormat, QStringList() << mTextOnSymbolLabel );
291  double h = QgsTextRenderer::textHeight( *context, mTextOnSymbolTextFormat, QStringList() << mTextOnSymbolLabel, QgsTextRenderer::Point );
292  int wInt = ceil( w ), hInt = ceil( h );
293  if ( wInt > minSz.width() ) minSz.setWidth( wInt );
294  if ( hInt > minSz.height() ) minSz.setHeight( hInt );
295  }
296 
297  return minSz;
298 }
299 
301 {
302  return mItem.symbol();
303 }
304 
306 {
307  QString label;
308  if ( mEmbeddedInParent )
309  {
310  QVariant legendlabel = mLayerNode->customProperty( QStringLiteral( "legend/title-label" ) );
311  QString layerName = legendlabel.isNull() ? mLayerNode->name() : legendlabel.toString();
312  label = mUserLabel.isEmpty() ? layerName : mUserLabel;
313  }
314  else
315  label = mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
316  return label;
317 }
318 
320 {
321  if ( mEmbeddedInParent )
322  {
323  return mLayerNode->patchShape();
324  }
325  else
326  {
327  return mPatchShape;
328  }
329 }
330 
332 {
333  mPatchShape = shape;
334 }
335 
337 {
338  return mCustomSymbol.get();
339 }
340 
342 {
343  mCustomSymbol.reset( symbol );
344 }
345 
347 {
348  if ( !symbol )
349  return;
350 
351  std::unique_ptr< QgsSymbol > s( symbol ); // this method takes ownership of symbol
352  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
353  if ( !vlayer || !vlayer->renderer() )
354  return;
355 
356  mItem.setSymbol( s.get() ); // doesn't transfer ownership
357  vlayer->renderer()->setLegendSymbolItem( mItem.ruleKey(), s.release() ); // DOES transfer ownership!
358 
359  mPixmap = QPixmap();
360 
361  emit dataChanged();
362  vlayer->triggerRepaint();
363 }
364 
366 {
367  checkAll( true );
368 }
369 
371 {
372  checkAll( false );
373 }
374 
376 {
377  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
378  if ( !vlayer || !vlayer->renderer() )
379  return;
380 
381  const QgsLegendSymbolList symbolList = vlayer->renderer()->legendSymbolItems();
382  for ( const auto &item : symbolList )
383  {
384  vlayer->renderer()->checkLegendSymbolItem( item.ruleKey(), ! vlayer->renderer()->legendSymbolItemChecked( item.ruleKey() ) );
385  }
386 
387  emit dataChanged();
388  vlayer->triggerRepaint();
389 }
390 
392 {
393  double scale = 0.0;
394  double mupp = 0.0;
395  int dpi = 0;
396  if ( model() )
397  model()->legendMapViewData( &mupp, &dpi, &scale );
398 
399  if ( qgsDoubleNear( mupp, 0.0 ) || dpi == 0 || qgsDoubleNear( scale, 0.0 ) )
400  return nullptr;
401 
402  // setup temporary render context
403  std::unique_ptr<QgsRenderContext> context = qgis::make_unique<QgsRenderContext>( );
404  context->setScaleFactor( dpi / 25.4 );
405  context->setRendererScale( scale );
406  context->setMapToPixel( QgsMapToPixel( mupp ) );
407  context->setFlag( QgsRenderContext::Antialiasing, true );
408  context->setFlag( QgsRenderContext::RenderSymbolPreview, true );
409  return context.release();
410 }
411 
412 void QgsSymbolLegendNode::checkAll( bool state )
413 {
414  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
415  if ( !vlayer || !vlayer->renderer() )
416  return;
417 
418  const QgsLegendSymbolList symbolList = vlayer->renderer()->legendSymbolItems();
419  for ( const auto &item : symbolList )
420  {
421  vlayer->renderer()->checkLegendSymbolItem( item.ruleKey(), state );
422  }
423 
424  emit dataChanged();
425  vlayer->triggerRepaint();
426 }
427 
428 QVariant QgsSymbolLegendNode::data( int role ) const
429 {
430  if ( role == Qt::DisplayRole )
431  {
432  return mLabel;
433  }
434  else if ( role == Qt::EditRole )
435  {
436  return mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
437  }
438  else if ( role == Qt::DecorationRole )
439  {
440  if ( mPixmap.isNull() || mPixmap.size() != mIconSize )
441  {
442  QPixmap pix;
443  if ( mItem.symbol() )
444  {
445  std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
446  pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), mIconSize, 0, context.get() );
447 
448  if ( !mTextOnSymbolLabel.isEmpty() && context )
449  {
450  QPainter painter( &pix );
451  painter.setRenderHint( QPainter::Antialiasing );
452  context->setPainter( &painter );
453  QFontMetricsF fm( mTextOnSymbolTextFormat.scaledFont( *context ) );
454  qreal yBaselineVCenter = ( mIconSize.height() + fm.ascent() - fm.descent() ) / 2;
455  QgsTextRenderer::drawText( QPointF( mIconSize.width() / 2, yBaselineVCenter ), 0, QgsTextRenderer::AlignCenter,
456  QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
457  }
458  }
459  else
460  {
461  pix = QPixmap( mIconSize );
462  pix.fill( Qt::transparent );
463  }
464 
465  mPixmap = pix;
466  }
467  return mPixmap;
468  }
469  else if ( role == Qt::CheckStateRole )
470  {
471  if ( !mItem.isCheckable() )
472  return QVariant();
473 
474  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
475  if ( !vlayer || !vlayer->renderer() )
476  return QVariant();
477 
478  return vlayer->renderer()->legendSymbolItemChecked( mItem.ruleKey() ) ? Qt::Checked : Qt::Unchecked;
479  }
480  else if ( role == RuleKeyRole )
481  {
482  return mItem.ruleKey();
483  }
484  else if ( role == ParentRuleKeyRole )
485  {
486  return mItem.parentRuleKey();
487  }
488 
489  return QVariant();
490 }
491 
492 bool QgsSymbolLegendNode::setData( const QVariant &value, int role )
493 {
494  if ( role != Qt::CheckStateRole )
495  return false;
496 
497  if ( !mItem.isCheckable() )
498  return false;
499 
500  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
501  if ( !vlayer || !vlayer->renderer() )
502  return false;
503 
504  vlayer->renderer()->checkLegendSymbolItem( mItem.ruleKey(), value == Qt::Checked );
505 
506  emit dataChanged();
507  vlayer->emitStyleChanged();
508 
509  vlayer->triggerRepaint();
510 
511  return true;
512 }
513 
514 
515 
516 QSizeF QgsSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight ) const
517 {
518  QgsSymbol *s = mCustomSymbol ? mCustomSymbol.get() : mItem.symbol();
519  if ( !s )
520  {
521  return QSizeF();
522  }
523 
524  // setup temporary render context
525  QgsRenderContext *context = nullptr;
526  std::unique_ptr< QgsRenderContext > tempRenderContext;
528  if ( ctx && ctx->context )
529  context = ctx->context;
530  else
531  {
532  tempRenderContext = qgis::make_unique< QgsRenderContext >();
533  // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
535  tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
536  tempRenderContext->setRendererScale( settings.mapScale() );
537  tempRenderContext->setFlag( QgsRenderContext::Antialiasing, true );
538  tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
540  tempRenderContext->setForceVectorOutput( true );
541  tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
542 
543  // setup a minimal expression context
544  QgsExpressionContext expContext;
546  tempRenderContext->setExpressionContext( expContext );
547  context = tempRenderContext.get();
548  }
549 
550  //Consider symbol size for point markers
551  const double desiredHeight = ctx && ctx->patchSize.height() > 0 ? ctx->patchSize.height() : settings.symbolSize().height();
552  const double desiredWidth = ctx && ctx->patchSize.width() > 0 ? ctx->patchSize.width() : settings.symbolSize().width();
553  double height = desiredHeight;
554  double width = desiredWidth;
555 
556  //Center small marker symbols
557  double widthOffset = 0;
558  double heightOffset = 0;
559 
560  if ( QgsMarkerSymbol *markerSymbol = dynamic_cast<QgsMarkerSymbol *>( s ) )
561  {
562  // allow marker symbol to occupy bigger area if necessary
563  double size = markerSymbol->size( *context ) / context->scaleFactor();
564  height = size;
565  width = size;
566  if ( width < desiredWidth )
567  {
568  widthOffset = ( desiredWidth - width ) / 2.0;
569  }
570  if ( height < desiredHeight )
571  {
572  heightOffset = ( desiredHeight - height ) / 2.0;
573  }
574  }
575 
576  if ( ctx && ctx->painter )
577  {
578  double currentYCoord = ctx->top + ( itemHeight - desiredHeight ) / 2;
579  QPainter *p = ctx->painter;
580 
581  //setup painter scaling to dots so that raster symbology is drawn to scale
582  double dotsPerMM = context->scaleFactor();
583 
584  int opacity = 255;
585  if ( QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layerNode()->layer() ) )
586  opacity = static_cast<int >( std::round( 255 * vectorLayer->opacity() ) );
587 
588  p->save();
589  if ( context->flags() & QgsRenderContext::Antialiasing )
590  p->setRenderHint( QPainter::Antialiasing );
591 
592  switch ( settings.symbolAlignment() )
593  {
594  case Qt::AlignLeft:
595  default:
596  p->translate( ctx->columnLeft + widthOffset, currentYCoord + heightOffset );
597  break;
598  case Qt::AlignRight:
599  p->translate( ctx->columnRight - widthOffset - width, currentYCoord + heightOffset );
600  break;
601  }
602 
603  p->scale( 1.0 / dotsPerMM, 1.0 / dotsPerMM );
605  // QGIS 4.0 -- ctx->context will be mandatory
606  const bool useAdvancedEffects = ctx->context ? ctx->context->flags() & QgsRenderContext::UseAdvancedEffects : settings.useAdvancedEffects();
608  if ( opacity != 255 && useAdvancedEffects )
609  {
610  const int maxBleed = static_cast< int >( std::ceil( QgsSymbolLayerUtils::estimateMaxSymbolBleed( s, *context ) ) );
611 
612  //semi transparent layer, so need to draw symbol to an image (to flatten it first)
613  //create image which is same size as legend rect, in case symbol bleeds outside its allotted space
614  const QSize symbolSize( static_cast< int >( std::round( width * dotsPerMM ) ), static_cast<int >( std::round( height * dotsPerMM ) ) );
615  const QSize tempImageSize( symbolSize.width() + maxBleed * 2, symbolSize.height() + maxBleed * 2 );
616  QImage tempImage = QImage( tempImageSize, QImage::Format_ARGB32 );
617  tempImage.fill( Qt::transparent );
618  QPainter imagePainter( &tempImage );
619  if ( context->flags() & QgsRenderContext::Antialiasing )
620  imagePainter.setRenderHint( QPainter::Antialiasing );
621  context->setPainter( &imagePainter );
622  imagePainter.translate( maxBleed, maxBleed );
623  s->drawPreviewIcon( &imagePainter, symbolSize, context, false, nullptr, &patchShape );
624  imagePainter.translate( -maxBleed, -maxBleed );
625  context->setPainter( ctx->painter );
626  //reduce opacity of image
627  imagePainter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
628  imagePainter.fillRect( tempImage.rect(), QColor( 0, 0, 0, opacity ) );
629  imagePainter.end();
630  //draw rendered symbol image
631  p->drawImage( -maxBleed, -maxBleed, tempImage );
632  }
633  else
634  {
635  s->drawPreviewIcon( p, QSize( static_cast< int >( std::round( width * dotsPerMM ) ), static_cast< int >( std::round( height * dotsPerMM ) ) ), context, false, nullptr, &patchShape );
636  }
637 
638  if ( !mTextOnSymbolLabel.isEmpty() )
639  {
640  QFontMetricsF fm( mTextOnSymbolTextFormat.scaledFont( *context ) );
641  qreal yBaselineVCenter = ( height * dotsPerMM + fm.ascent() - fm.descent() ) / 2;
642  QgsTextRenderer::drawText( QPointF( width * dotsPerMM / 2, yBaselineVCenter ), 0, QgsTextRenderer::AlignCenter,
643  QStringList() << mTextOnSymbolLabel, *context, mTextOnSymbolTextFormat );
644  }
645 
646  p->restore();
647  }
648 
649  return QSizeF( std::max( width + 2 * widthOffset, static_cast< double >( desiredWidth ) ),
650  std::max( height + 2 * heightOffset, static_cast< double >( desiredHeight ) ) );
651 }
652 
653 QJsonObject QgsSymbolLegendNode::exportSymbolToJson( const QgsLegendSettings &settings, const QgsRenderContext &context ) const
654 {
655  const QgsSymbol *s = mCustomSymbol ? mCustomSymbol.get() : mItem.symbol();
656  if ( !s )
657  {
658  return QJsonObject();
659  }
660 
661 
662  QgsRenderContext ctx;
663  // QGIS 4.0 - use render context directly here, and note in the dox that the context must be correctly setup
665  ctx.setScaleFactor( settings.dpi() / 25.4 );
666  ctx.setRendererScale( settings.mapScale() );
667  ctx.setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * ctx.scaleFactor() ) ) );
668  ctx.setForceVectorOutput( true );
671 
672  // ensure that a minimal expression context is available
673  QgsExpressionContext expContext = context.expressionContext();
675  ctx.setExpressionContext( expContext );
676 
677  const QPixmap pix = QgsSymbolLayerUtils::symbolPreviewPixmap( mItem.symbol(), minimumIconSize(), 0, &ctx );
678  QImage img( pix.toImage().convertToFormat( QImage::Format_ARGB32_Premultiplied ) );
679 
680  int opacity = 255;
681  if ( QgsVectorLayer *vectorLayer = qobject_cast<QgsVectorLayer *>( layerNode()->layer() ) )
682  opacity = ( 255 * vectorLayer->opacity() );
683 
684  if ( opacity != 255 )
685  {
686  QPainter painter;
687  painter.begin( &img );
688  painter.setCompositionMode( QPainter::CompositionMode_DestinationIn );
689  painter.fillRect( pix.rect(), QColor( 0, 0, 0, opacity ) );
690  painter.end();
691  }
692 
693  QByteArray byteArray;
694  QBuffer buffer( &byteArray );
695  img.save( &buffer, "PNG" );
696  const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
697 
698  QJsonObject json;
699  json[ QStringLiteral( "icon" ) ] = base64;
700  return json;
701 }
702 
704 {
706  updateLabel();
707 }
708 
709 
711 {
712  if ( mSymbolUsesMapUnits )
713  {
714  mPixmap = QPixmap();
715  emit dataChanged();
716  }
717 }
718 
719 
720 void QgsSymbolLegendNode::updateLabel()
721 {
722  if ( !mLayerNode )
723  return;
724 
725  bool showFeatureCount = mLayerNode->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toBool();
726  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
727  mLabel = symbolLabel();
728 
729  if ( showFeatureCount && vl )
730  {
731  qlonglong count = mEmbeddedInParent ? vl->featureCount() : vl->featureCount( mItem.ruleKey() ) ;
732  mLabel += QStringLiteral( " [%1]" ).arg( count != -1 ? QLocale().toString( count ) : tr( "N/A" ) );
733  }
734 
735  emit dataChanged();
736 }
737 
738 QString QgsSymbolLegendNode::evaluateLabel( const QgsExpressionContext &context, const QString &label )
739 {
740  if ( !mLayerNode )
741  return QString();
742 
743  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
744 
745  if ( vl )
746  {
747  QgsExpressionContext contextCopy = QgsExpressionContext( context );
748  QgsExpressionContextScope *symbolScope = createSymbolScope();
749  contextCopy.appendScope( symbolScope );
750  contextCopy.appendScope( vl->createExpressionContextScope() );
751 
752  if ( label.isEmpty() )
753  {
754  if ( ! mLayerNode->labelExpression().isEmpty() )
755  mLabel = QgsExpression::replaceExpressionText( "[%" + mLayerNode->labelExpression() + "%]", &contextCopy );
756  else if ( mLabel.contains( "[%" ) )
757  {
758  const QString symLabel = symbolLabel();
759  mLabel = QgsExpression::replaceExpressionText( symLabel, &contextCopy );
760  }
761  return mLabel;
762  }
763  else
764  {
765  QString eLabel;
766  if ( ! mLayerNode->labelExpression().isEmpty() )
767  eLabel = QgsExpression::replaceExpressionText( label + "[%" + mLayerNode->labelExpression() + "%]", &contextCopy );
768  else if ( label.contains( "[%" ) )
769  eLabel = QgsExpression::replaceExpressionText( label, &contextCopy );
770  return eLabel;
771  }
772  }
773  return mLabel;
774 }
775 
776 QgsExpressionContextScope *QgsSymbolLegendNode::createSymbolScope() const
777 {
778  QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
779 
780  QgsExpressionContextScope *scope = new QgsExpressionContextScope( tr( "Symbol scope" ) );
781  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "symbol_label" ), symbolLabel().remove( "[%" ).remove( "%]" ), true ) );
782  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "symbol_id" ), mItem.ruleKey(), true ) );
783  if ( vl )
784  {
785  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "symbol_count" ), QVariant::fromValue( vl->featureCount( mItem.ruleKey() ) ), true ) );
786  }
787  return scope;
788 }
789 
790 // -------------------------------------------------------------------------
791 
792 
793 QgsSimpleLegendNode::QgsSimpleLegendNode( QgsLayerTreeLayer *nodeLayer, const QString &label, const QIcon &icon, QObject *parent, const QString &key )
794  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
795  , mLabel( label )
796  , mIcon( icon )
797  , mKey( key )
798 {
799 }
800 
801 QVariant QgsSimpleLegendNode::data( int role ) const
802 {
803  if ( role == Qt::DisplayRole || role == Qt::EditRole )
804  return mUserLabel.isEmpty() ? mLabel : mUserLabel;
805  else if ( role == Qt::DecorationRole )
806  return mIcon;
807  else if ( role == RuleKeyRole && !mKey.isEmpty() )
808  return mKey;
809  else
810  return QVariant();
811 }
812 
813 
814 // -------------------------------------------------------------------------
815 
816 QgsImageLegendNode::QgsImageLegendNode( QgsLayerTreeLayer *nodeLayer, const QImage &img, QObject *parent )
817  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
818  , mImage( img )
819 {
820 }
821 
822 QVariant QgsImageLegendNode::data( int role ) const
823 {
824  if ( role == Qt::DecorationRole )
825  {
826  return QPixmap::fromImage( mImage );
827  }
828  else if ( role == Qt::SizeHintRole )
829  {
830  return mImage.size();
831  }
832  return QVariant();
833 }
834 
835 QSizeF QgsImageLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight ) const
836 {
837  Q_UNUSED( itemHeight )
838 
839  if ( ctx && ctx->painter )
840  {
841  switch ( settings.symbolAlignment() )
842  {
843  case Qt::AlignLeft:
844  default:
845  ctx->painter->drawImage( QRectF( ctx->columnLeft, ctx->top, settings.wmsLegendSize().width(), settings.wmsLegendSize().height() ),
846  mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
847  break;
848 
849  case Qt::AlignRight:
850  ctx->painter->drawImage( QRectF( ctx->columnRight - settings.wmsLegendSize().width(), ctx->top, settings.wmsLegendSize().width(), settings.wmsLegendSize().height() ),
851  mImage, QRectF( 0, 0, mImage.width(), mImage.height() ) );
852  break;
853  }
854  }
855  return settings.wmsLegendSize();
856 }
857 
859 {
860  QByteArray byteArray;
861  QBuffer buffer( &byteArray );
862  mImage.save( &buffer, "PNG" );
863  const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
864 
865  QJsonObject json;
866  json[ QStringLiteral( "icon" ) ] = base64;
867  return json;
868 }
869 
870 // -------------------------------------------------------------------------
871 
872 QgsRasterSymbolLegendNode::QgsRasterSymbolLegendNode( QgsLayerTreeLayer *nodeLayer, const QColor &color, const QString &label, QObject *parent )
873  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
874  , mColor( color )
875  , mLabel( label )
876 {
877 }
878 
879 QVariant QgsRasterSymbolLegendNode::data( int role ) const
880 {
881  if ( role == Qt::DecorationRole )
882  {
883  const int iconSize = QgsLayerTreeModel::scaleIconSize( 16 ); // TODO: configurable?
884  QPixmap pix( iconSize, iconSize );
885  pix.fill( mColor );
886  return QIcon( pix );
887  }
888  else if ( role == Qt::DisplayRole || role == Qt::EditRole )
889  return mUserLabel.isEmpty() ? mLabel : mUserLabel;
890  else
891  return QVariant();
892 }
893 
894 
895 QSizeF QgsRasterSymbolLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight ) const
896 {
897  QSizeF size = settings.symbolSize();
898  double offsetX = 0;
899  if ( ctx )
900  {
901  if ( ctx->patchSize.width() > 0 )
902  {
903  if ( ctx->patchSize.width() < size.width() )
904  offsetX = ( size.width() - ctx->patchSize.width() ) / 2.0;
905  size.setWidth( ctx->patchSize.width() );
906  }
907  if ( ctx->patchSize.height() > 0 )
908  {
909  size.setHeight( ctx->patchSize.height() );
910  }
911  }
912 
913  if ( ctx && ctx->painter )
914  {
915  QColor itemColor = mColor;
916  if ( QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layerNode()->layer() ) )
917  {
918  if ( QgsRasterRenderer *rasterRenderer = rasterLayer->renderer() )
919  itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
920  }
921  ctx->painter->setBrush( itemColor );
922 
923  if ( settings.drawRasterStroke() )
924  {
925  QPen pen;
926  pen.setColor( settings.rasterStrokeColor() );
927  pen.setWidthF( settings.rasterStrokeWidth() );
928  pen.setJoinStyle( Qt::MiterJoin );
929  ctx->painter->setPen( pen );
930  }
931  else
932  {
933  ctx->painter->setPen( Qt::NoPen );
934  }
935 
936  switch ( settings.symbolAlignment() )
937  {
938  case Qt::AlignLeft:
939  default:
940  ctx->painter->drawRect( QRectF( ctx->columnLeft + offsetX, ctx->top + ( itemHeight - size.height() ) / 2,
941  size.width(), size.height() ) );
942  break;
943 
944  case Qt::AlignRight:
945  ctx->painter->drawRect( QRectF( ctx->columnRight - size.width() - offsetX, ctx->top + ( itemHeight - size.height() ) / 2,
946  size.width(), size.height() ) );
947  break;
948  }
949  }
950  return size;
951 }
952 
954 {
955  QImage img = QImage( settings.symbolSize().toSize(), QImage::Format_ARGB32 );
956  img.fill( Qt::transparent );
957 
958  QPainter painter( &img );
959  painter.setRenderHint( QPainter::Antialiasing );
960 
961  QColor itemColor = mColor;
962  if ( QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( layerNode()->layer() ) )
963  {
964  if ( QgsRasterRenderer *rasterRenderer = rasterLayer->renderer() )
965  itemColor.setAlpha( rasterRenderer->opacity() * 255.0 );
966  }
967  painter.setBrush( itemColor );
968 
969  if ( settings.drawRasterStroke() )
970  {
971  QPen pen;
972  pen.setColor( settings.rasterStrokeColor() );
973  pen.setWidthF( settings.rasterStrokeWidth() );
974  pen.setJoinStyle( Qt::MiterJoin );
975  painter.setPen( pen );
976  }
977  else
978  {
979  painter.setPen( Qt::NoPen );
980  }
981 
982  painter.drawRect( QRectF( 0, 0, settings.symbolSize().width(), settings.symbolSize().height() ) );
983 
984  QByteArray byteArray;
985  QBuffer buffer( &byteArray );
986  img.save( &buffer, "PNG" );
987  const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
988 
989  QJsonObject json;
990  json[ QStringLiteral( "icon" ) ] = base64;
991  return json;
992 }
993 
994 // -------------------------------------------------------------------------
995 
997  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
998  , mValid( false )
999 {
1000 }
1001 
1002 QImage QgsWmsLegendNode::getLegendGraphic() const
1003 {
1004  if ( ! mValid && ! mFetcher )
1005  {
1006  // or maybe in presence of a downloader we should just delete it
1007  // and start a new one ?
1008 
1009  QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( mLayerNode->layer() );
1010  const QgsLayerTreeModel *mod = model();
1011  if ( ! mod )
1012  return mImage;
1013  const QgsMapSettings *ms = mod->legendFilterMapSettings();
1014 
1015  QgsRasterDataProvider *prov = layer->dataProvider();
1016  if ( ! prov )
1017  return mImage;
1018 
1019  Q_ASSERT( ! mFetcher );
1020  mFetcher.reset( prov->getLegendGraphicFetcher( ms ) );
1021  if ( mFetcher )
1022  {
1023  connect( mFetcher.get(), &QgsImageFetcher::finish, this, &QgsWmsLegendNode::getLegendGraphicFinished );
1024  connect( mFetcher.get(), &QgsImageFetcher::error, this, &QgsWmsLegendNode::getLegendGraphicErrored );
1025  connect( mFetcher.get(), &QgsImageFetcher::progress, this, &QgsWmsLegendNode::getLegendGraphicProgress );
1026  mFetcher->start();
1027  } // else QgsDebugMsg("XXX No legend supported?");
1028 
1029  }
1030 
1031  return mImage;
1032 }
1033 
1034 QVariant QgsWmsLegendNode::data( int role ) const
1035 {
1036  //QgsDebugMsg( QStringLiteral("XXX data called with role %1 -- mImage size is %2x%3").arg(role).arg(mImage.width()).arg(mImage.height()) );
1037 
1038  if ( role == Qt::DecorationRole )
1039  {
1040  return QPixmap::fromImage( getLegendGraphic() );
1041  }
1042  else if ( role == Qt::SizeHintRole )
1043  {
1044  return getLegendGraphic().size();
1045  }
1046  return QVariant();
1047 }
1048 
1049 QSizeF QgsWmsLegendNode::drawSymbol( const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight ) const
1050 {
1051  Q_UNUSED( itemHeight )
1052 
1053  if ( ctx && ctx->painter )
1054  {
1055  switch ( settings.symbolAlignment() )
1056  {
1057  case Qt::AlignLeft:
1058  default:
1059  ctx->painter->drawImage( QRectF( ctx->columnLeft,
1060  ctx->top,
1061  settings.wmsLegendSize().width(),
1062  settings.wmsLegendSize().height() ),
1063  mImage,
1064  QRectF( QPointF( 0, 0 ), mImage.size() ) );
1065  break;
1066 
1067  case Qt::AlignRight:
1068  ctx->painter->drawImage( QRectF( ctx->columnRight - settings.wmsLegendSize().width(),
1069  ctx->top,
1070  settings.wmsLegendSize().width(),
1071  settings.wmsLegendSize().height() ),
1072  mImage,
1073  QRectF( QPointF( 0, 0 ), mImage.size() ) );
1074  break;
1075  }
1076  }
1077  return settings.wmsLegendSize();
1078 }
1079 
1081 {
1082  QByteArray byteArray;
1083  QBuffer buffer( &byteArray );
1084  mImage.save( &buffer, "PNG" );
1085  const QString base64 = QString::fromLatin1( byteArray.toBase64().data() );
1086 
1087  QJsonObject json;
1088  json[ QStringLiteral( "icon" ) ] = base64;
1089  return json;
1090 }
1091 
1092 /* private */
1093 QImage QgsWmsLegendNode::renderMessage( const QString &msg ) const
1094 {
1095  const int fontHeight = 10;
1096  const int margin = fontHeight / 2;
1097  const int nlines = 1;
1098 
1099  const int w = 512, h = fontHeight * nlines + margin * ( nlines + 1 );
1100  QImage image( w, h, QImage::Format_ARGB32_Premultiplied );
1101  QPainter painter;
1102  painter.begin( &image );
1103  painter.setPen( QColor( 255, 0, 0 ) );
1104  painter.setFont( QFont( QStringLiteral( "Chicago" ), fontHeight ) );
1105  painter.fillRect( 0, 0, w, h, QColor( 255, 255, 255 ) );
1106  painter.drawText( 0, margin + fontHeight, msg );
1107  //painter.drawText(0,2*(margin+fontHeight),tr("retrying in 5 seconds…"));
1108  painter.end();
1109 
1110  return image;
1111 }
1112 
1113 void QgsWmsLegendNode::getLegendGraphicProgress( qint64 cur, qint64 tot )
1114 {
1115  QString msg = QStringLiteral( "Downloading... %1/%2" ).arg( cur ).arg( tot );
1116  //QgsDebugMsg ( QString("XXX %1").arg(msg) );
1117  mImage = renderMessage( msg );
1118  emit dataChanged();
1119 }
1120 
1121 void QgsWmsLegendNode::getLegendGraphicErrored( const QString &msg )
1122 {
1123  if ( ! mFetcher ) return; // must be coming after finish
1124 
1125  mImage = renderMessage( msg );
1126  //QgsDebugMsg( QStringLiteral("XXX emitting dataChanged after writing an image of %1x%2").arg(mImage.width()).arg(mImage.height()) );
1127 
1128  emit dataChanged();
1129 
1130  mFetcher.reset();
1131 
1132  mValid = true; // we consider it valid anyway
1133  // ... but remove validity after 5 seconds
1134  //QTimer::singleShot(5000, this, SLOT(invalidateMapBasedData()));
1135 }
1136 
1137 void QgsWmsLegendNode::getLegendGraphicFinished( const QImage &image )
1138 {
1139  if ( ! mFetcher ) return; // must be coming after error
1140 
1141  //QgsDebugMsg( QStringLiteral("XXX legend graphic finished, image is %1x%2").arg(theImage.width()).arg(theImage.height()) );
1142  if ( ! image.isNull() )
1143  {
1144  if ( image != mImage )
1145  {
1146  mImage = image;
1147  //QgsDebugMsg( QStringLiteral("XXX emitting dataChanged") );
1148  emit dataChanged();
1149  }
1150  mValid = true; // only if not null I guess
1151  }
1152  mFetcher.reset();
1153 }
1154 
1156 {
1157  //QgsDebugMsg( QStringLiteral("XXX invalidateMapBasedData called") );
1158  // TODO: do this only if this extent != prev extent ?
1159  mValid = false;
1160  emit dataChanged();
1161 }
1162 
1163 // -------------------------------------------------------------------------
1164 
1166  : QgsLayerTreeModelLegendNode( nodeLayer, parent )
1167  , mSettings( new QgsDataDefinedSizeLegend( settings ) )
1168 {
1169 }
1170 
1172 {
1173  delete mSettings;
1174 }
1175 
1176 QVariant QgsDataDefinedSizeLegendNode::data( int role ) const
1177 {
1178  if ( role == Qt::DecorationRole )
1179  {
1180  cacheImage();
1181  return QPixmap::fromImage( mImage );
1182  }
1183  else if ( role == Qt::SizeHintRole )
1184  {
1185  cacheImage();
1186  return mImage.size();
1187  }
1188  return QVariant();
1189 }
1190 
1192 {
1193  // setup temporary render context if none specified
1194  QgsRenderContext *context = nullptr;
1195  std::unique_ptr< QgsRenderContext > tempRenderContext;
1196  if ( ctx && ctx->context )
1197  context = ctx->context;
1198  else
1199  {
1200  tempRenderContext = qgis::make_unique< QgsRenderContext >();
1201  // QGIS 4.0 - make ItemContext compulsory, so we don't have to construct temporary render contexts here
1203  tempRenderContext->setScaleFactor( settings.dpi() / 25.4 );
1204  tempRenderContext->setRendererScale( settings.mapScale() );
1205  tempRenderContext->setFlag( QgsRenderContext::Antialiasing, true );
1206  tempRenderContext->setMapToPixel( QgsMapToPixel( 1 / ( settings.mmPerMapUnit() * tempRenderContext->scaleFactor() ) ) );
1207  tempRenderContext->setForceVectorOutput( true );
1208  tempRenderContext->setPainter( ctx ? ctx->painter : nullptr );
1209  tempRenderContext->setFlag( QgsRenderContext::Antialiasing, true );
1211 
1212  // setup a minimal expression context
1213  QgsExpressionContext expContext;
1215  tempRenderContext->setExpressionContext( expContext );
1216  context = tempRenderContext.get();
1217  }
1218 
1219  if ( context->painter() )
1220  {
1221  context->painter()->save();
1222  context->painter()->translate( ctx->columnLeft, ctx->top );
1223 
1224  // scale to pixels
1225  context->painter()->scale( 1 / context->scaleFactor(), 1 / context->scaleFactor() );
1226  }
1227 
1228  QgsDataDefinedSizeLegend ddsLegend( *mSettings );
1229  ddsLegend.setFont( settings.style( QgsLegendStyle::SymbolLabel ).font() );
1230  ddsLegend.setTextColor( settings.fontColor() );
1231 
1232  QSizeF contentSize;
1233  double labelXOffset;
1234  ddsLegend.drawCollapsedLegend( *context, &contentSize, &labelXOffset );
1235 
1236  if ( context->painter() )
1237  context->painter()->restore();
1238 
1239  ItemMetrics im;
1240  im.symbolSize = QSizeF( ( contentSize.width() - labelXOffset ) / context->scaleFactor(), contentSize.height() / context->scaleFactor() );
1241  im.labelSize = QSizeF( labelXOffset / context->scaleFactor(), contentSize.height() / context->scaleFactor() );
1242  return im;
1243 }
1244 
1245 
1246 void QgsDataDefinedSizeLegendNode::cacheImage() const
1247 {
1248  if ( mImage.isNull() )
1249  {
1250  std::unique_ptr<QgsRenderContext> context( createTemporaryRenderContext() );
1251  if ( !context )
1252  {
1253  context.reset( new QgsRenderContext );
1254  Q_ASSERT( context ); // to make cppcheck happy
1255  context->setScaleFactor( 96 / 25.4 );
1256  }
1257  mImage = mSettings->collapsedLegendImage( *context );
1258  }
1259 }
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:369
QgsLayerTreeLayer::labelExpression
QString labelExpression() const
Returns the expression member of the LayerTreeNode.
Definition: qgslayertreelayer.h:144
QgsMapLayer::emitStyleChanged
void emitStyleChanged()
Triggers an emission of the styleChanged() signal.
Definition: qgsmaplayer.cpp:1844
QgsFeatureRenderer::setLegendSymbolItem
virtual void setLegendSymbolItem(const QString &key, QgsSymbol *symbol)
Sets the symbol to be used for a legend symbol item.
Definition: qgsrenderer.cpp:347
QgsSymbolLegendNode::QgsSymbolLegendNode
QgsSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QgsLegendSymbolItem &item, QObject *parent=nullptr)
Constructor for QgsSymbolLegendNode.
Definition: qgslayertreemodellegendnode.cpp:235
qgsexpressioncontextutils.h
QgsExpressionContext::appendScopes
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
Definition: qgsexpressioncontext.cpp:495
QgsLegendStyle::Symbol
@ Symbol
Symbol icon (excluding label)
Definition: qgslegendstyle.h:73
QgsLegendSettings::symbolAlignment
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
Definition: qgslegendsettings.h:255
QgsSymbolLegendNode::exportSymbolToJson
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
Definition: qgslayertreemodellegendnode.cpp:653
QgsVectorLayer::createExpressionContextScope
QgsExpressionContextScope * createExpressionContextScope() const FINAL
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgsvectorlayer.cpp:4938
QgsSymbolLegendNode::symbolLabel
QString symbolLabel() const
Label of the symbol, user defined label will be used, otherwise will default to the label made by QGI...
Definition: qgslayertreemodellegendnode.cpp:305
QgsWmsLegendNode::QgsWmsLegendNode
QgsWmsLegendNode(QgsLayerTreeLayer *nodeLayer, QObject *parent=nullptr)
Constructor for QgsWmsLegendNode.
Definition: qgslayertreemodellegendnode.cpp:996
QgsSymbolLegendNode::setCustomSymbol
void setCustomSymbol(QgsSymbol *symbol)
Sets the node's custom symbol.
Definition: qgslayertreemodellegendnode.cpp:341
QgsLegendSettings::useAdvancedEffects
Q_DECL_DEPRECATED bool useAdvancedEffects() const
Definition: qgslegendsettings.cpp:50
QgsLayerTreeLayer::patchShape
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
Definition: qgslayertreelayer.cpp:227
qgsrasterlayer.h
QgsLegendSymbolItem::setSymbol
void setSymbol(QgsSymbol *s)
Sets the symbol of the item.
Definition: qgslegendsymbolitem.cpp:79
qgslayertreemodellegendnode.h
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:580
QgsImageLegendNode::drawSymbol
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
Definition: qgslayertreemodellegendnode.cpp:835
QgsLegendSettings::mmPerMapUnit
Q_DECL_DEPRECATED double mmPerMapUnit() const
Definition: qgslegendsettings.cpp:40
QgsLayerTreeModelLegendNode::ItemContext::columnRight
double columnRight
Right side of current legend column.
Definition: qgslayertreemodellegendnode.h:178
QgsSymbolLegendNode::invalidateMapBasedData
void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
Definition: qgslayertreemodellegendnode.cpp:710
QgsLayerTreeModelLegendNode::data
virtual QVariant data(int role) const =0
Returns data associated with the item. Must be implemented in derived class.
QgsDataDefinedSizeLegendNode::draw
ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx) override
Entry point called from QgsLegendRenderer to do the rendering.
Definition: qgslayertreemodellegendnode.cpp:1191
QgsExpressionContextScope::addVariable
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Definition: qgsexpressioncontext.cpp:93
qgstextrenderer.h
QgsLegendSettings::textWidthMillimeters
double textWidthMillimeters(const QFont &font, const QString &text) const
Returns the font width in millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCALE...
Definition: qgslegendsettings.cpp:157
QgsDataDefinedSizeLegend::collapsedLegendImage
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...
Definition: qgsdatadefinedsizelegend.cpp:336
QgsLayerTreeModelLegendNode::ItemContext::patchSize
QSizeF patchSize
Symbol patch size to render for the node.
Definition: qgslayertreemodellegendnode.h:201
QgsLayerTreeModelLegendNode::drawSymbolText
virtual QSizeF drawSymbolText(const QgsLegendSettings &settings, ItemContext *ctx, QSizeF symbolSize) const
Draws label on the right side of the item.
Definition: qgslayertreemodellegendnode.cpp:152
qgsexpression.h
QgsSymbolLegendNode::checkAllItems
void checkAllItems()
Checks all items belonging to the same layer as this node.
Definition: qgslayertreemodellegendnode.cpp:365
QgsTextRenderer::AlignCenter
@ AlignCenter
Center align.
Definition: qgstextrenderer.h:61
QgsRasterSymbolLegendNode::drawSymbol
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
Definition: qgslayertreemodellegendnode.cpp:895
QgsRenderContext::UseAdvancedEffects
@ UseAdvancedEffects
Enable layer opacity and blending effects.
Definition: qgsrendercontext.h:73
QgsRenderContext::setFlag
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Definition: qgsrendercontext.cpp:152
QgsRenderContext::setPainter
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Definition: qgsrendercontext.h:475
qgssymbollayerutils.h
QgsLegendSettings::drawText
void drawText(QPainter *p, double x, double y, const QString &text, const QFont &font) const
Draws Text.
Definition: qgslegendsettings.cpp:115
QgsRasterSymbolLegendNode::exportSymbolToJson
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
Definition: qgslayertreemodellegendnode.cpp:953
QgsSymbolLegendNode::patchShape
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
Definition: qgslayertreemodellegendnode.cpp:319
QgsSimpleLegendNode::data
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Definition: qgslayertreemodellegendnode.cpp:801
QgsDataDefinedSizeLegend
Definition: qgsdatadefinedsizelegend.h:41
QgsLegendSettings::mapScale
Q_DECL_DEPRECATED double mapScale() const
Returns the legend map scale.
Definition: qgslegendsettings.cpp:60
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsLegendSettings::style
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
Definition: qgslegendsettings.h:81
qgsrasterrenderer.h
QgsUnitTypes::RenderMillimeters
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
QgsLayerTreeModelLegendNode::exportToJson
QJsonObject exportToJson(const QgsLegendSettings &settings, const QgsRenderContext &context)
Entry point called from QgsLegendRenderer to do the rendering in a JSON object.
Definition: qgslayertreemodellegendnode.cpp:87
QgsExpressionContextUtils::globalProjectLayerScopes
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Definition: qgsexpressioncontextutils.cpp:306
QgsFeatureRenderer::legendSymbolItems
virtual QgsLegendSymbolList legendSymbolItems() const
Returns a list of symbology items for the legend.
Definition: qgsrenderer.cpp:353
qgsfeatureid.h
QgsLayerTreeModelLegendNode::ItemContext::patchShape
QgsLegendPatchShape patchShape
The patch shape to render for the node.
Definition: qgslayertreemodellegendnode.h:192
QgsLayerTreeLayer::name
QString name() const override
Returns the layer's name.
Definition: qgslayertreelayer.cpp:81
QgsLayerTreeModel
Definition: qgslayertreemodel.h:53
QgsSymbol
Definition: qgssymbol.h:63
qgsimageoperation.h
QgsRenderContext::scaleFactor
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Definition: qgsrendercontext.h:317
qgsvectorlayerfeaturecounter.h
QgsLegendSettings::rasterStrokeColor
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:284
QgsImageLegendNode::data
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Definition: qgslayertreemodellegendnode.cpp:822
QgsDataDefinedSizeLegendNode::QgsDataDefinedSizeLegendNode
QgsDataDefinedSizeLegendNode(QgsLayerTreeLayer *nodeLayer, const QgsDataDefinedSizeLegend &settings, QObject *parent=nullptr)
Construct the node using QgsDataDefinedSizeLegend as definition of the node's appearance.
Definition: qgslayertreemodellegendnode.cpp:1165
QgsSymbol::outputUnit
QgsUnitTypes::RenderUnit outputUnit() const
Returns the units to use for sizes and widths within the symbol.
Definition: qgssymbol.cpp:238
QgsImageLegendNode::exportSymbolToJson
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
Definition: qgslayertreemodellegendnode.cpp:858
QgsLegendStyle::SymbolLabel
@ SymbolLabel
Symbol label (excluding icon)
Definition: qgslegendstyle.h:74
QgsVectorLayer::featureCount
long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
Definition: qgsvectorlayer.cpp:751
QgsDataDefinedSizeLegendNode::~QgsDataDefinedSizeLegendNode
~QgsDataDefinedSizeLegendNode() override
Definition: qgslayertreemodellegendnode.cpp:1171
QgsLegendSymbolItem::ruleKey
QString ruleKey() const
Returns unique identifier of the rule for identification of the item within renderer.
Definition: qgslegendsymbolitem.h:60
QgsLayerTreeModelLegendNode::model
QgsLayerTreeModel * model() const
Returns pointer to model owning this legend node.
Definition: qgslayertreemodellegendnode.cpp:46
QgsLegendSettings::drawRasterStroke
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
Definition: qgslegendsettings.h:264
QgsLegendPatchShape
Definition: qgslegendpatchshape.h:30
QgsLegendSettings::dpi
Q_DECL_DEPRECATED int dpi() const
Definition: qgslegendsettings.cpp:80
QgsGuiUtils::iconSize
QSize iconSize(bool dockableToolbar)
Returns the user-preferred size of a window's toolbar icons.
Definition: qgsguiutils.cpp:264
QgsFeatureRenderer::legendSymbolItemChecked
virtual bool legendSymbolItemChecked(const QString &key)
items of symbology items in legend is checked
Definition: qgsrenderer.cpp:335
QgsLayerTreeModelLegendNode::exportSymbolToJson
virtual QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const
Adds a symbol in base64 string within a JSON object with the key "icon".
Definition: qgslayertreemodellegendnode.cpp:135
QgsTextRenderer::textWidth
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.
Definition: qgstextrenderer.cpp:448
QgsLayerTreeModelLegendNode::flags
virtual Qt::ItemFlags flags() const
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
Definition: qgslayertreemodellegendnode.cpp:51
QgsLayerTreeModel::scaleIconSize
static int scaleIconSize(int standardSize)
Scales an layer tree model icon size to compensate for display pixel density, making the icon size hi...
Definition: qgslayertreemodel.cpp:719
QgsLayerTreeModelLegendNode::draw
virtual ItemMetrics draw(const QgsLegendSettings &settings, ItemContext *ctx)
Entry point called from QgsLegendRenderer to do the rendering.
Definition: qgslayertreemodellegendnode.cpp:71
QgsMapLayer::triggerRepaint
void triggerRepaint(bool deferredUpdate=false)
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
Definition: qgsmaplayer.cpp:1817
QgsWmsLegendNode::invalidateMapBasedData
void invalidateMapBasedData() override
Notification from model that information from associated map view has changed.
Definition: qgslayertreemodellegendnode.cpp:1155
QgsTextRenderer::drawText
static void drawText(const QRectF &rect, double rotation, HAlignment alignment, const QStringList &textLines, QgsRenderContext &context, const QgsTextFormat &format, bool drawAsOutlines=true)
Draws text within a rectangle using the specified settings.
Definition: qgstextrenderer.cpp:45
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:752
QgsLayerTreeModelLegendNode::ItemMetrics::labelSize
QSizeF labelSize
Definition: qgslayertreemodellegendnode.h:207
QgsLegendSymbolItem
Definition: qgslegendsymbolitem.h:36
QgsTextRenderer::Point
@ Point
Text at point of origin draw mode.
Definition: qgstextrenderer.h:44
QgsSymbolLayerUtils::symbolPreviewPixmap
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.
Definition: qgssymbollayerutils.cpp:767
QgsImageFetcher::progress
void progress(qint64 received, qint64 total)
Emitted to report progress.
QgsRasterSymbolLegendNode::QgsRasterSymbolLegendNode
QgsRasterSymbolLegendNode(QgsLayerTreeLayer *nodeLayer, const QColor &color, const QString &label, QObject *parent=nullptr)
Constructor for QgsRasterSymbolLegendNode.
Definition: qgslayertreemodellegendnode.cpp:872
QgsSymbolLegendNode::setPatchShape
void setPatchShape(const QgsLegendPatchShape &shape)
Sets the symbol patch shape to use when rendering the legend node symbol.
Definition: qgslayertreemodellegendnode.cpp:331
QgsSymbolLegendNode::setData
bool setData(const QVariant &value, int role) override
Sets some data associated with the item. Default implementation does nothing and returns false.
Definition: qgslayertreemodellegendnode.cpp:492
QgsLayerTreeModelLegendNode::QgsLayerTreeModelLegendNode
QgsLayerTreeModelLegendNode(QgsLayerTreeLayer *nodeL, QObject *parent=nullptr)
Construct the node with pointer to its parent layer node.
Definition: qgslayertreemodellegendnode.cpp:39
QgsLegendSettings::rasterStrokeWidth
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:305
QgsFeatureRenderer::checkLegendSymbolItem
virtual void checkLegendSymbolItem(const QString &key, bool state=true)
item in symbology was checked
Definition: qgsrenderer.cpp:341
QgsLayerTreeModelLegendNode::mEmbeddedInParent
bool mEmbeddedInParent
Definition: qgslayertreemodellegendnode.h:266
qgslayoutitem.h
QgsWmsLegendNode::drawSymbol
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
Definition: qgslayertreemodellegendnode.cpp:1049
QgsRasterRenderer
Definition: qgsrasterrenderer.h:38
QgsMarkerSymbol
Definition: qgssymbol.h:917
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:315
QgsLayerTreeModelLegendNode::userPatchSize
virtual QSizeF userPatchSize() const
Returns the user (overridden) size for the legend node.
Definition: qgslayertreemodellegendnode.cpp:63
QgsLegendStyle::alignment
Qt::Alignment alignment() const
Returns the alignment for the legend component.
Definition: qgslegendstyle.h:127
QgsImageLegendNode::QgsImageLegendNode
QgsImageLegendNode(QgsLayerTreeLayer *nodeLayer, const QImage &img, QObject *parent=nullptr)
Constructor for QgsImageLegendNode.
Definition: qgslayertreemodellegendnode.cpp:816
qgslegendsettings.h
QgsLayerTreeLayer
Definition: qgslayertreelayer.h:43
QgsLayerTreeModel::legendFilterMapSettings
const QgsMapSettings * legendFilterMapSettings() const
Returns the current map settings used for the current legend filter (or nullptr if none is enabled)
Definition: qgslayertreemodel.h:250
QgsRasterDataProvider::getLegendGraphicFetcher
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Returns a new image downloader for the raster legend.
Definition: qgsrasterdataprovider.h:309
QgsLegendSettings::wmsLegendSize
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
Definition: qgslegendsettings.h:323
QgsRenderContext::setMapToPixel
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
Definition: qgsrendercontext.h:404
QgsLegendSettings
The QgsLegendSettings class stores the appearance and layout settings for legend drawing with QgsLege...
Definition: qgslegendsettings.h:38
QgsLegendStyle::Right
@ Right
Right side.
Definition: qgslegendstyle.h:72
QgsDataDefinedSizeLegend::setTextColor
void setTextColor(const QColor &color)
Sets text color for rendering of labels - only valid for collapsed legend.
Definition: qgsdatadefinedsizelegend.h:132
QgsSymbolLegendNode::flags
Qt::ItemFlags flags() const override
Returns item flags associated with the item. Default implementation returns Qt::ItemIsEnabled.
Definition: qgslayertreemodellegendnode.cpp:251
QgsLayerTreeModelLegendNode::ParentRuleKeyRole
@ ParentRuleKeyRole
Rule key of the parent legend node - for legends with tree hierarchy (QString). Added in 2....
Definition: qgslayertreemodellegendnode.h:66
QgsTextRenderer::textHeight
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.
Definition: qgstextrenderer.cpp:515
QgsLayerTreeModelLegendNode::ItemContext
Definition: qgslayertreemodellegendnode.h:135
qgsrenderer.h
QgsRasterLayer
Definition: qgsrasterlayer.h:72
QgsLayerTreeLayer::layer
QgsMapLayer * layer() const
Returns the map layer associated with this node.
Definition: qgslayertreelayer.h:74
qgslayertree.h
QgsLayerTreeModelLegendNode::setEmbeddedInParent
virtual void setEmbeddedInParent(bool embedded)
Definition: qgslayertreemodellegendnode.h:85
QgsLayerTreeModelLegendNode::ItemMetrics::symbolSize
QSizeF symbolSize
Definition: qgslayertreemodellegendnode.h:206
QgsLegendSymbolItem::label
QString label() const
Returns text label.
Definition: qgslegendsymbolitem.h:58
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:111
QgsRenderContext::setRendererScale
void setRendererScale(double scale)
Sets the renderer map scale.
Definition: qgsrendercontext.h:467
QgsLayerTreeModelLegendNode::ItemContext::maxSiblingSymbolWidth
double maxSiblingSymbolWidth
Largest symbol width, considering all other sibling legend components associated with the current com...
Definition: qgslayertreemodellegendnode.h:185
QgsExpressionContext::appendScope
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Definition: qgsexpressioncontext.cpp:490
qgsvectorlayer.h
QgsLayerTreeModel::legendMapViewData
void legendMapViewData(double *mapUnitsPerPixel, int *dpi, double *scale) const
Gets hints about map view - to be used in legend nodes.
Definition: qgslayertreemodel.cpp:702
QgsRenderContext::setForceVectorOutput
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
Definition: qgsrendercontext.cpp:250
QgsLayerTreeModelLegendNode::setData
virtual bool setData(const QVariant &value, int role)
Sets some data associated with the item. Default implementation does nothing and returns false.
Definition: qgslayertreemodellegendnode.cpp:56
QgsLegendStyle::Left
@ Left
Left side.
Definition: qgslegendstyle.h:71
QgsSymbolLegendNode::toggleAllItems
void toggleAllItems()
Toggle all items belonging to the same layer as this node.
Definition: qgslayertreemodellegendnode.cpp:375
QgsLayerTreeModelLegendNode::ItemMetrics
Definition: qgslayertreemodellegendnode.h:204
QgsDataDefinedSizeLegendNode::data
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Definition: qgslayertreemodellegendnode.cpp:1176
QgsLayerTreeModelLegendNode::layerNode
QgsLayerTreeLayer * layerNode() const
Returns pointer to the parent layer node.
Definition: qgslayertreemodellegendnode.h:70
QgsWmsLegendNode::exportSymbolToJson
QJsonObject exportSymbolToJson(const QgsLegendSettings &settings, const QgsRenderContext &context) const override
Adds a symbol in base64 string within a JSON object with the key "icon".
Definition: qgslayertreemodellegendnode.cpp:1080
QgsLegendSymbolItem::symbol
QgsSymbol * symbol() const
Returns associated symbol. May be nullptr.
Definition: qgslegendsymbolitem.h:56
QgsLayerTreeModelLegendNode::createTemporaryRenderContext
QgsRenderContext * createTemporaryRenderContext() const
Returns a temporary context or nullptr if legendMapViewData are not valid.
Definition: qgslayertreemodellegendnode.cpp:391
QgsMapToPixel
Definition: qgsmaptopixel.h:37
QgsSymbol::drawPreviewIcon
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.
Definition: qgssymbol.cpp:506
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsLegendStyle::font
QFont font() const
Returns the font used for rendering this legend component.
Definition: qgslegendstyle.h:81
QgsLayerTreeNode::customProperty
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.
Definition: qgslayertreenode.cpp:189
QgsLayerTreeModelLegendNode::mPatchShape
QgsLegendPatchShape mPatchShape
Definition: qgslayertreemodellegendnode.h:268
QgsLegendSymbolItem::isCheckable
bool isCheckable() const
Returns whether the item is user-checkable - whether renderer supports enabling/disabling it.
Definition: qgslegendsymbolitem.h:62
QgsSymbolLegendNode::drawSymbol
QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const override
Draws symbol on the left side of the item.
Definition: qgslayertreemodellegendnode.cpp:516
QgsLayerTreeModelLegendNode::ItemContext::top
double top
Top y-position of legend item.
Definition: qgslayertreemodellegendnode.h:162
QgsSymbolLegendNode::setEmbeddedInParent
void setEmbeddedInParent(bool embedded) override
Definition: qgslayertreemodellegendnode.cpp:703
QgsSymbol::Line
@ Line
Line symbol.
Definition: qgssymbol.h:88
QgsSymbolLegendNode::data
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Definition: qgslayertreemodellegendnode.cpp:428
QgsImageFetcher::finish
void finish(const QImage &legend)
Emitted when the download completes.
QgsLegendSettings::symbolSize
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
Definition: qgslegendsettings.h:228
QgsLegendSettings::fontHeightCharacterMM
double fontHeightCharacterMM(const QFont &font, QChar c) const
Returns the font height of a character in millimeters.
Definition: qgslegendsettings.cpp:164
QgsSymbol::type
SymbolType type() const
Returns the symbol's type.
Definition: qgssymbol.h:122
QgsVectorLayer::symbolFeatureCountMapChanged
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
QgsSymbol::Marker
@ Marker
Marker symbol.
Definition: qgssymbol.h:87
QgsSymbolLegendNode::evaluateLabel
QString evaluateLabel(const QgsExpressionContext &context=QgsExpressionContext(), const QString &label=QString())
Evaluates and returns the text label of the current node.
Definition: qgslayertreemodellegendnode.cpp:738
QgsRenderContext::Antialiasing
@ Antialiasing
Use antialiasing while drawing.
Definition: qgsrendercontext.h:78
QgsRenderContext::setExpressionContext
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
Definition: qgsrendercontext.h:572
qgslayertreemodel.h
QgsLayerTreeModelLegendNode::ItemContext::painter
QPainter * painter
Painter.
Definition: qgslayertreemodellegendnode.h:144
QgsWmsLegendNode::data
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Definition: qgslayertreemodellegendnode.cpp:1034
QgsRenderContext::RenderSymbolPreview
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
Definition: qgsrendercontext.h:82
QgsLegendSettings::fontColor
QColor fontColor() const
Returns the font color used for legend items.
Definition: qgslegendsettings.h:197
qgsdatadefinedsizelegend.h
QgsLegendSettings::lineSpacing
double lineSpacing() const
Returns the line spacing to use between lines of legend text.
Definition: qgslegendsettings.h:337
QgsRasterSymbolLegendNode::data
QVariant data(int role) const override
Returns data associated with the item. Must be implemented in derived class.
Definition: qgslayertreemodellegendnode.cpp:879
QgsSymbolLayerUtils::estimateMaxSymbolBleed
static double estimateMaxSymbolBleed(QgsSymbol *symbol, const QgsRenderContext &context)
Returns the maximum estimated bleed for the symbol.
Definition: qgssymbollayerutils.cpp:820
QgsImageOperation::nonTransparentImageRect
static QRect nonTransparentImageRect(const QImage &image, QSize minSize=QSize(), bool center=false)
Calculates the non-transparent region of an image.
Definition: qgsimageoperation.cpp:773
QgsSymbolLegendNode::minimumIconSize
QSize minimumIconSize() const
Calculates the minimum icon size to prevent cropping.
Definition: qgslayertreemodellegendnode.cpp:260
QgsLegendSettings::fontDescentMillimeters
double fontDescentMillimeters(const QFont &font) const
Returns the font descent in Millimeters (considers upscaling and downscaling with FONT_WORKAROUND_SCA...
Definition: qgslegendsettings.cpp:178
QgsLayerTreeModelLegendNode::drawSymbol
virtual QSizeF drawSymbol(const QgsLegendSettings &settings, ItemContext *ctx, double itemHeight) const
Draws symbol on the left side of the item.
Definition: qgslayertreemodellegendnode.cpp:95
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:174
QgsLayerTreeLayer::patchSize
QSizeF patchSize() const
Returns the user (overridden) size for the legend node.
Definition: qgslayertreelayer.h:171
QgsExpressionContextScope::StaticVariable
Single variable definition for use within a QgsExpressionContextScope.
Definition: qgsexpressioncontext.h:118
QgsSymbolLegendNode::customSymbol
QgsSymbol * customSymbol() const
Returns the node's custom symbol.
Definition: qgslayertreemodellegendnode.cpp:336
QgsDataDefinedSizeLegend::drawCollapsedLegend
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...
Definition: qgsdatadefinedsizelegend.cpp:162
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsLegendSymbolList
QList< QgsLegendSymbolItem > QgsLegendSymbolList
Definition: qgslegendsymbolitem.h:144
QgsLayerTreeModelLegendNode::RuleKeyRole
@ RuleKeyRole
Rule key of the node (QString)
Definition: qgslayertreemodellegendnode.h:65
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:751
QgsExpression::replaceExpressionText
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...
Definition: qgsexpression.cpp:430
QgsSymbolLegendNode::iconSize
QSize iconSize() const
Definition: qgslayertreemodellegendnode.h:320
QgsLayerTreeModelLegendNode::mUserSize
QSizeF mUserSize
Definition: qgslayertreemodellegendnode.h:269
QgsLayerTreeModelLegendNode::dataChanged
void dataChanged()
Emitted on internal data change so the layer tree model can forward the signal to views.
QgsRasterDataProvider
Definition: qgsrasterdataprovider.h:88
QgsRenderContext::setScaleFactor
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
Definition: qgsrendercontext.h:460
QgsLegendSymbolItem::parentRuleKey
QString parentRuleKey() const
Key of the parent legend node.
Definition: qgslegendsymbolitem.h:89
QgsLayerTreeModelLegendNode::ItemContext::columnLeft
double columnLeft
Left side of current legend column.
Definition: qgslayertreemodellegendnode.h:170
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:233
QgsLayerTreeModelLegendNode::mLayerNode
QgsLayerTreeLayer * mLayerNode
Definition: qgslayertreemodellegendnode.h:265
QgsSymbolLegendNode::uncheckAllItems
void uncheckAllItems()
Unchecks all items belonging to the same layer as this node.
Definition: qgslayertreemodellegendnode.cpp:370
QgsImageFetcher::error
void error(const QString &msg)
Emitted when an error occurs.
QgsRenderContext::flags
Flags flags() const
Returns combination of flags used for rendering.
Definition: qgsrendercontext.cpp:160
QgsSimpleLegendNode::QgsSimpleLegendNode
QgsSimpleLegendNode(QgsLayerTreeLayer *nodeLayer, const QString &label, const QIcon &icon=QIcon(), QObject *parent=nullptr, const QString &key=QString())
Constructor for QgsSimpleLegendNode.
Definition: qgslayertreemodellegendnode.cpp:793
QgsSymbolLegendNode::symbol
const QgsSymbol * symbol() const
Returns the symbol used by the legend node.
Definition: qgslayertreemodellegendnode.cpp:300
QgsLayerTreeModelLegendNode::ItemContext::context
Q_NOWARN_DEPRECATED_POP QgsRenderContext * context
Render context, if available.
Definition: qgslayertreemodellegendnode.h:142
QgsTextFormat::scaledFont
QFont scaledFont(const QgsRenderContext &context) const
Returns a font with the size scaled to match the format's size settings (including units and map unit...
Definition: qgstextformat.cpp:67
QgsLayerTreeModelLegendNode::mUserLabel
QString mUserLabel
Definition: qgslayertreemodellegendnode.h:267
QgsVectorLayer::renderer
QgsFeatureRenderer * renderer()
Returns renderer.
Definition: qgsvectorlayer.h:881
QgsLegendStyle::margin
double margin(Side side)
Returns the margin (in mm) for the specified side of the component.
Definition: qgslegendstyle.h:104
QgsSymbolLegendNode::setSymbol
void setSymbol(QgsSymbol *symbol)
Sets the symbol to be used by the legend node.
Definition: qgslayertreemodellegendnode.cpp:346
QgsDataDefinedSizeLegend::setFont
void setFont(const QFont &font)
Sets font used for rendering of labels - only valid for collapsed legend.
Definition: qgsdatadefinedsizelegend.h:127
QgsLegendSettings::evaluateItemText
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...
Definition: qgslegendsettings.cpp:90
QgsLayerTreeModelLegendNode
Definition: qgslayertreemodellegendnode.h:50