QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgslayoutitemlegend.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgslayoutitemlegend.cpp
3  -----------------------
4  begin : October 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include <limits>
18 
19 #include "qgslayoutitemlegend.h"
20 #include "qgslayoutitemregistry.h"
21 #include "qgslayoutitemmap.h"
22 #include "qgslayout.h"
23 #include "qgslayoutmodel.h"
24 #include "qgslayertree.h"
25 #include "qgslayertreemodel.h"
26 #include "qgslegendrenderer.h"
27 #include "qgslegendstyle.h"
28 #include "qgslogger.h"
29 #include "qgsmapsettings.h"
30 #include "qgsproject.h"
31 #include "qgssymbollayerutils.h"
32 #include "qgslayertreeutils.h"
33 #include "qgslayoututils.h"
34 #include "qgsmapthemecollection.h"
35 #include "qgsstyleentityvisitor.h"
36 #include <QDomDocument>
37 #include <QDomElement>
38 #include <QPainter>
39 #include "qgsexpressioncontext.h"
40 
42  : QgsLayoutItem( layout )
43  , mLegendModel( new QgsLegendModel( layout->project()->layerTreeRoot(), this ) )
44 {
45 #if 0 //no longer required?
46  connect( &layout->atlasComposition(), &QgsAtlasComposition::renderEnded, this, &QgsLayoutItemLegend::onAtlasEnded );
47 #endif
48 
49  mTitle = mSettings.title();
50 
51  // Connect to the main layertreeroot.
52  // It serves in "auto update mode" as a medium between the main app legend and this one
53  connect( mLayout->project()->layerTreeRoot(), &QgsLayerTreeNode::customPropertyChanged, this, &QgsLayoutItemLegend::nodeCustomPropertyChanged );
54 
55  // If project colors change, we need to redraw legend, as legend symbols may rely on project colors
56  connect( mLayout->project(), &QgsProject::projectColorsChanged, this, [ = ]
57  {
58  invalidateCache();
59  update();
60  } );
61  connect( mLegendModel.get(), &QgsLegendModel::refreshLegend, this, &QgsLayoutItemLegend::refresh );
62 }
63 
65 {
66  return new QgsLayoutItemLegend( layout );
67 }
68 
70 {
72 }
73 
75 {
76  return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItemLegend.svg" ) );
77 }
78 
79 QgsLayoutItem::Flags QgsLayoutItemLegend::itemFlags() const
80 {
82 }
83 
84 void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
85 {
86  if ( !painter )
87  return;
88 
89  if ( mFilterAskedForUpdate )
90  {
91  mFilterAskedForUpdate = false;
92  doUpdateFilterByMap();
93  }
94 
95  int dpi = painter->device()->logicalDpiX();
96  double dotsPerMM = dpi / 25.4;
97 
98  if ( mLayout )
99  {
101  // no longer required, but left set for api stability
102  mSettings.setUseAdvancedEffects( mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagUseAdvancedEffects );
103  mSettings.setDpi( dpi );
105  }
106  if ( mMap && mLayout )
107  {
109  // no longer required, but left set for api stability
110  mSettings.setMmPerMapUnit( mLayout->convertFromLayoutUnits( mMap->mapUnitsToLayoutUnits(), QgsUnitTypes::LayoutMillimeters ).length() );
112 
113  // use a temporary QgsMapSettings to find out real map scale
114  QSizeF mapSizePixels = QSizeF( mMap->rect().width() * dotsPerMM, mMap->rect().height() * dotsPerMM );
115  QgsRectangle mapExtent = mMap->extent();
116 
117  QgsMapSettings ms = mMap->mapSettings( mapExtent, mapSizePixels, dpi, false );
118 
119  // no longer required, but left set for api stability
121  mSettings.setMapScale( ms.scale() );
123  }
124  mInitialMapScaleCalculated = true;
125 
126  QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
127  legendRenderer.setLegendSize( mForceResize && mSizeToContents ? QSize() : rect().size() );
128 
129  //adjust box if width or height is too small
130  if ( mSizeToContents )
131  {
133  QSizeF size = legendRenderer.minimumSize( &context );
134  if ( mForceResize )
135  {
136  mForceResize = false;
137 
138  //set new rect, respecting position mode and data defined size/position
139  QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
140  attemptResize( newSize );
141  }
142  else if ( size.height() > rect().height() || size.width() > rect().width() )
143  {
144  //need to resize box
145  QSizeF targetSize = rect().size();
146  if ( size.height() > targetSize.height() )
147  targetSize.setHeight( size.height() );
148  if ( size.width() > targetSize.width() )
149  targetSize.setWidth( size.width() );
150 
151  QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( targetSize, sizeWithUnits().units() );
152  //set new rect, respecting position mode and data defined size/position
153  attemptResize( newSize );
154  }
155  }
156 
157  QgsLayoutItem::paint( painter, itemStyle, pWidget );
158 }
159 
161 {
162  if ( !mMapUuid.isEmpty() )
163  {
164  setLinkedMap( qobject_cast< QgsLayoutItemMap * >( mLayout->itemByUuid( mMapUuid, true ) ) );
165  }
166 }
167 
169 {
171  clearLegendCachedData();
172  onAtlasFeature();
173 }
174 
176 {
177  QPainter *painter = context.renderContext().painter();
178  painter->save();
179 
180  // painter is scaled to dots, so scale back to layout units
181  painter->scale( context.renderContext().scaleFactor(), context.renderContext().scaleFactor() );
182 
183  painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
184 
185  if ( !mSizeToContents )
186  {
187  // set a clip region to crop out parts of legend which don't fit
188  QRectF thisPaintRect = QRectF( 0, 0, rect().width(), rect().height() );
189  painter->setClipRect( thisPaintRect );
190  }
191 
192  if ( mLayout )
193  {
194  // no longer required, but left for API compatibility
196  mSettings.setDpi( mLayout->renderContext().dpi() );
198  }
199 
200  QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
201  legendRenderer.setLegendSize( rect().size() );
202 
203  legendRenderer.drawLegend( context.renderContext() );
204 
205  painter->restore();
206 }
207 
209 {
210  if ( !mSizeToContents )
211  return;
212 
213  if ( !mInitialMapScaleCalculated )
214  {
215  // this is messy - but until we have painted the item we have no knowledge of the current DPI
216  // and so cannot correctly calculate the map scale. This results in incorrect size calculations
217  // for marker symbols with size in map units, causing the legends to initially expand to huge
218  // sizes if we attempt to calculate the box size first.
219  return;
220  }
221 
223  QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
224  QSizeF size = legendRenderer.minimumSize( &context );
225  QgsDebugMsg( QStringLiteral( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ) );
226  if ( size.isValid() )
227  {
228  QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
229  //set new rect, respecting position mode and data defined size/position
230  attemptResize( newSize );
231  }
232 }
233 
235 {
236  mSizeToContents = enabled;
237 }
238 
240 {
241  return mSizeToContents;
242 }
243 
244 void QgsLayoutItemLegend::setCustomLayerTree( QgsLayerTree *rootGroup )
245 {
246  mLegendModel->setRootGroup( rootGroup ? rootGroup : ( mLayout ? mLayout->project()->layerTreeRoot() : nullptr ) );
247 
248  mCustomLayerTree.reset( rootGroup );
249 }
250 
251 
253 {
254  if ( autoUpdate == autoUpdateModel() )
255  return;
256 
257  setCustomLayerTree( autoUpdate ? nullptr : mLayout->project()->layerTreeRoot()->clone() );
258  adjustBoxSize();
259  updateFilterByMap( false );
260 }
261 
262 void QgsLayoutItemLegend::nodeCustomPropertyChanged( QgsLayerTreeNode *, const QString &key )
263 {
264  if ( key == QLatin1String( "cached_name" ) )
265  return;
266 
267  if ( autoUpdateModel() )
268  {
269  // in "auto update" mode, some parameters on the main app legend may have been changed (expression filtering)
270  // we must then call updateItem to reflect the changes
271  updateFilterByMap( false );
272  }
273 }
274 
276 {
277  return !mCustomLayerTree;
278 }
279 
281 {
282  mLegendFilterByMap = enabled;
283  updateFilterByMap( false );
284 }
285 
286 void QgsLayoutItemLegend::setTitle( const QString &t )
287 {
288  mTitle = t;
289  mSettings.setTitle( t );
290 
291  if ( mLayout && id().isEmpty() )
292  {
293  //notify the model that the display name has changed
294  mLayout->itemsModel()->updateItemDisplayName( this );
295  }
296 }
298 {
299  return mTitle;
300 }
301 
302 Qt::AlignmentFlag QgsLayoutItemLegend::titleAlignment() const
303 {
304  return mSettings.titleAlignment();
305 }
306 
307 void QgsLayoutItemLegend::setTitleAlignment( Qt::AlignmentFlag alignment )
308 {
309  mSettings.setTitleAlignment( alignment );
310 }
311 
313 {
314  return mSettings.rstyle( s );
315 }
316 
318 {
319  return mSettings.style( s );
320 }
321 
323 {
324  mSettings.setStyle( s, style );
325 }
326 
328 {
329  return mSettings.style( s ).font();
330 }
331 
333 {
334  rstyle( s ).setFont( f );
335 }
336 
338 {
339  rstyle( s ).setMargin( margin );
340 }
341 
343 {
344  rstyle( s ).setMargin( side, margin );
345 }
346 
348 {
349  return mSettings.lineSpacing();
350 }
351 
353 {
354  mSettings.setLineSpacing( spacing );
355 }
356 
358 {
359  return mSettings.boxSpace();
360 }
361 
363 {
364  mSettings.setBoxSpace( s );
365 }
366 
368 {
369  return mSettings.columnSpace();
370 }
371 
373 {
374  mSettings.setColumnSpace( s );
375 }
376 
378 {
379  return mSettings.fontColor();
380 }
381 
383 {
384  mSettings.setFontColor( c );
385 }
386 
388 {
389  return mSettings.symbolSize().width();
390 }
391 
393 {
394  mSettings.setSymbolSize( QSizeF( w, mSettings.symbolSize().height() ) );
395 }
396 
397 void QgsLayoutItemLegend::setSymbolAlignment( Qt::AlignmentFlag alignment )
398 {
399  mSettings.setSymbolAlignment( alignment );
400 }
401 
402 Qt::AlignmentFlag QgsLayoutItemLegend::symbolAlignment() const
403 {
404  return mSettings.symbolAlignment();
405 }
406 
408 {
409  return mSettings.symbolSize().height();
410 }
411 
413 {
414  mSettings.setSymbolSize( QSizeF( mSettings.symbolSize().width(), h ) );
415 }
416 
418 {
419  return mSettings.wmsLegendSize().width();
420 }
421 
423 {
424  mSettings.setWmsLegendSize( QSizeF( w, mSettings.wmsLegendSize().height() ) );
425 }
426 
428 {
429  return mSettings.wmsLegendSize().height();
430 }
432 {
433  mSettings.setWmsLegendSize( QSizeF( mSettings.wmsLegendSize().width(), h ) );
434 }
435 
436 void QgsLayoutItemLegend::setWrapString( const QString &t )
437 {
438  mSettings.setWrapChar( t );
439 }
440 
442 {
443  return mSettings.wrapChar();
444 }
445 
447 {
448  return mColumnCount;
449 }
450 
452 {
453  mColumnCount = c;
454  mSettings.setColumnCount( c );
455 }
456 
458 {
459  return mSettings.splitLayer();
460 }
461 
463 {
464  mSettings.setSplitLayer( s );
465 }
466 
468 {
469  return mSettings.equalColumnWidth();
470 }
471 
473 {
474  mSettings.setEqualColumnWidth( s );
475 }
476 
478 {
479  return mSettings.drawRasterStroke();
480 }
481 
483 {
484  mSettings.setDrawRasterStroke( enabled );
485 }
486 
488 {
489  return mSettings.rasterStrokeColor();
490 }
491 
492 void QgsLayoutItemLegend::setRasterStrokeColor( const QColor &color )
493 {
494  mSettings.setRasterStrokeColor( color );
495 }
496 
498 {
499  return mSettings.rasterStrokeWidth();
500 }
501 
503 {
504  mSettings.setRasterStrokeWidth( width );
505 }
506 
507 
509 {
510  adjustBoxSize();
511  updateFilterByMap( false );
512 }
513 
514 bool QgsLayoutItemLegend::writePropertiesToElement( QDomElement &legendElem, QDomDocument &doc, const QgsReadWriteContext &context ) const
515 {
516 
517  //write general properties
518  legendElem.setAttribute( QStringLiteral( "title" ), mTitle );
519  legendElem.setAttribute( QStringLiteral( "titleAlignment" ), QString::number( static_cast< int >( mSettings.titleAlignment() ) ) );
520  legendElem.setAttribute( QStringLiteral( "columnCount" ), QString::number( mColumnCount ) );
521  legendElem.setAttribute( QStringLiteral( "splitLayer" ), QString::number( mSettings.splitLayer() ) );
522  legendElem.setAttribute( QStringLiteral( "equalColumnWidth" ), QString::number( mSettings.equalColumnWidth() ) );
523 
524  legendElem.setAttribute( QStringLiteral( "boxSpace" ), QString::number( mSettings.boxSpace() ) );
525  legendElem.setAttribute( QStringLiteral( "columnSpace" ), QString::number( mSettings.columnSpace() ) );
526 
527  legendElem.setAttribute( QStringLiteral( "symbolWidth" ), QString::number( mSettings.symbolSize().width() ) );
528  legendElem.setAttribute( QStringLiteral( "symbolHeight" ), QString::number( mSettings.symbolSize().height() ) );
529 
530  legendElem.setAttribute( QStringLiteral( "symbolAlignment" ), mSettings.symbolAlignment() );
531 
532  legendElem.setAttribute( QStringLiteral( "symbolAlignment" ), mSettings.symbolAlignment() );
533  legendElem.setAttribute( QStringLiteral( "lineSpacing" ), QString::number( mSettings.lineSpacing() ) );
534 
535  legendElem.setAttribute( QStringLiteral( "rasterBorder" ), mSettings.drawRasterStroke() );
536  legendElem.setAttribute( QStringLiteral( "rasterBorderColor" ), QgsSymbolLayerUtils::encodeColor( mSettings.rasterStrokeColor() ) );
537  legendElem.setAttribute( QStringLiteral( "rasterBorderWidth" ), QString::number( mSettings.rasterStrokeWidth() ) );
538 
539  legendElem.setAttribute( QStringLiteral( "wmsLegendWidth" ), QString::number( mSettings.wmsLegendSize().width() ) );
540  legendElem.setAttribute( QStringLiteral( "wmsLegendHeight" ), QString::number( mSettings.wmsLegendSize().height() ) );
541  legendElem.setAttribute( QStringLiteral( "wrapChar" ), mSettings.wrapChar() );
542  legendElem.setAttribute( QStringLiteral( "fontColor" ), mSettings.fontColor().name() );
543 
544  legendElem.setAttribute( QStringLiteral( "resizeToContents" ), mSizeToContents );
545 
546  if ( mMap )
547  {
548  legendElem.setAttribute( QStringLiteral( "map_uuid" ), mMap->uuid() );
549  }
550 
551  QDomElement legendStyles = doc.createElement( QStringLiteral( "styles" ) );
552  legendElem.appendChild( legendStyles );
553 
554  style( QgsLegendStyle::Title ).writeXml( QStringLiteral( "title" ), legendStyles, doc );
555  style( QgsLegendStyle::Group ).writeXml( QStringLiteral( "group" ), legendStyles, doc );
556  style( QgsLegendStyle::Subgroup ).writeXml( QStringLiteral( "subgroup" ), legendStyles, doc );
557  style( QgsLegendStyle::Symbol ).writeXml( QStringLiteral( "symbol" ), legendStyles, doc );
558  style( QgsLegendStyle::SymbolLabel ).writeXml( QStringLiteral( "symbolLabel" ), legendStyles, doc );
559 
560  if ( mCustomLayerTree )
561  {
562  // if not using auto-update - store the custom layer tree
563  mCustomLayerTree->writeXml( legendElem, context );
564  }
565 
566  if ( mLegendFilterByMap )
567  {
568  legendElem.setAttribute( QStringLiteral( "legendFilterByMap" ), QStringLiteral( "1" ) );
569  }
570  legendElem.setAttribute( QStringLiteral( "legendFilterByAtlas" ), mFilterOutAtlas ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
571 
572  return true;
573 }
574 
575 bool QgsLayoutItemLegend::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context )
576 {
577  //read general properties
578  mTitle = itemElem.attribute( QStringLiteral( "title" ) );
579  mSettings.setTitle( mTitle );
580  if ( !itemElem.attribute( QStringLiteral( "titleAlignment" ) ).isEmpty() )
581  {
582  mSettings.setTitleAlignment( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral( "titleAlignment" ) ).toInt() ) );
583  }
584  int colCount = itemElem.attribute( QStringLiteral( "columnCount" ), QStringLiteral( "1" ) ).toInt();
585  if ( colCount < 1 ) colCount = 1;
586  mColumnCount = colCount;
587  mSettings.setColumnCount( mColumnCount );
588  mSettings.setSplitLayer( itemElem.attribute( QStringLiteral( "splitLayer" ), QStringLiteral( "0" ) ).toInt() == 1 );
589  mSettings.setEqualColumnWidth( itemElem.attribute( QStringLiteral( "equalColumnWidth" ), QStringLiteral( "0" ) ).toInt() == 1 );
590 
591  QDomNodeList stylesNodeList = itemElem.elementsByTagName( QStringLiteral( "styles" ) );
592  if ( !stylesNodeList.isEmpty() )
593  {
594  QDomNode stylesNode = stylesNodeList.at( 0 );
595  for ( int i = 0; i < stylesNode.childNodes().size(); i++ )
596  {
597  QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
599  style.readXml( styleElem, doc, context );
600  QString name = styleElem.attribute( QStringLiteral( "name" ) );
602  if ( name == QLatin1String( "title" ) ) s = QgsLegendStyle::Title;
603  else if ( name == QLatin1String( "group" ) ) s = QgsLegendStyle::Group;
604  else if ( name == QLatin1String( "subgroup" ) ) s = QgsLegendStyle::Subgroup;
605  else if ( name == QLatin1String( "symbol" ) ) s = QgsLegendStyle::Symbol;
606  else if ( name == QLatin1String( "symbolLabel" ) ) s = QgsLegendStyle::SymbolLabel;
607  else continue;
608  setStyle( s, style );
609  }
610  }
611 
612  //font color
613  QColor fontClr;
614  fontClr.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) );
615  mSettings.setFontColor( fontClr );
616 
617  //spaces
618  mSettings.setBoxSpace( itemElem.attribute( QStringLiteral( "boxSpace" ), QStringLiteral( "2.0" ) ).toDouble() );
619  mSettings.setColumnSpace( itemElem.attribute( QStringLiteral( "columnSpace" ), QStringLiteral( "2.0" ) ).toDouble() );
620 
621  mSettings.setSymbolSize( QSizeF( itemElem.attribute( QStringLiteral( "symbolWidth" ), QStringLiteral( "7.0" ) ).toDouble(), itemElem.attribute( QStringLiteral( "symbolHeight" ), QStringLiteral( "14.0" ) ).toDouble() ) );
622  mSettings.setSymbolAlignment( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral( "symbolAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() ) );
623 
624  mSettings.setWmsLegendSize( QSizeF( itemElem.attribute( QStringLiteral( "wmsLegendWidth" ), QStringLiteral( "50" ) ).toDouble(), itemElem.attribute( QStringLiteral( "wmsLegendHeight" ), QStringLiteral( "25" ) ).toDouble() ) );
625  mSettings.setLineSpacing( itemElem.attribute( QStringLiteral( "lineSpacing" ), QStringLiteral( "1.0" ) ).toDouble() );
626 
627  mSettings.setDrawRasterStroke( itemElem.attribute( QStringLiteral( "rasterBorder" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
628  mSettings.setRasterStrokeColor( QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "rasterBorderColor" ), QStringLiteral( "0,0,0" ) ) ) );
629  mSettings.setRasterStrokeWidth( itemElem.attribute( QStringLiteral( "rasterBorderWidth" ), QStringLiteral( "0" ) ).toDouble() );
630 
631  mSettings.setWrapChar( itemElem.attribute( QStringLiteral( "wrapChar" ) ) );
632 
633  mSizeToContents = itemElem.attribute( QStringLiteral( "resizeToContents" ), QStringLiteral( "1" ) ) != QLatin1String( "0" );
634 
635  // map
636  mLegendFilterByMap = itemElem.attribute( QStringLiteral( "legendFilterByMap" ), QStringLiteral( "0" ) ).toInt();
637 
638  mMapUuid.clear();
639  if ( !itemElem.attribute( QStringLiteral( "map_uuid" ) ).isEmpty() )
640  {
641  mMapUuid = itemElem.attribute( QStringLiteral( "map_uuid" ) );
642  }
643  // disconnect current map
644  setupMapConnections( mMap, false );
645  mMap = nullptr;
646 
647  mFilterOutAtlas = itemElem.attribute( QStringLiteral( "legendFilterByAtlas" ), QStringLiteral( "0" ) ).toInt();
648 
649  // QGIS >= 2.6
650  QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral( "layer-tree" ) );
651  if ( layerTreeElem.isNull() )
652  layerTreeElem = itemElem.firstChildElement( QStringLiteral( "layer-tree-group" ) );
653 
654  if ( !layerTreeElem.isNull() )
655  {
656  std::unique_ptr< QgsLayerTree > tree( QgsLayerTree::readXml( layerTreeElem, context ) );
657  if ( mLayout )
658  tree->resolveReferences( mLayout->project(), true );
659  setCustomLayerTree( tree.release() );
660  }
661  else
662  setCustomLayerTree( nullptr );
663 
664  return true;
665 }
666 
668 {
669  if ( !id().isEmpty() )
670  {
671  return id();
672  }
673 
674  //if no id, default to portion of title text
675  QString text = mSettings.title();
676  if ( text.isEmpty() )
677  {
678  return tr( "<Legend>" );
679  }
680  if ( text.length() > 25 )
681  {
682  return tr( "%1…" ).arg( text.left( 25 ) );
683  }
684  else
685  {
686  return text;
687  }
688 }
689 
690 
691 void QgsLayoutItemLegend::setupMapConnections( QgsLayoutItemMap *map, bool connectSlots )
692 {
693  if ( !map )
694  return;
695 
696  if ( !connectSlots )
697  {
698  disconnect( map, &QObject::destroyed, this, &QgsLayoutItemLegend::invalidateCurrentMap );
699  disconnect( map, &QgsLayoutObject::changed, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
700  disconnect( map, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
701  disconnect( map, &QgsLayoutItemMap::mapRotationChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
702  disconnect( map, &QgsLayoutItemMap::layerStyleOverridesChanged, this, &QgsLayoutItemLegend::mapLayerStyleOverridesChanged );
703  disconnect( map, &QgsLayoutItemMap::themeChanged, this, &QgsLayoutItemLegend::mapThemeChanged );
704  }
705  else
706  {
707  connect( map, &QObject::destroyed, this, &QgsLayoutItemLegend::invalidateCurrentMap );
708  connect( map, &QgsLayoutObject::changed, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
709  connect( map, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
710  connect( map, &QgsLayoutItemMap::mapRotationChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
711  connect( map, &QgsLayoutItemMap::layerStyleOverridesChanged, this, &QgsLayoutItemLegend::mapLayerStyleOverridesChanged );
712  connect( map, &QgsLayoutItemMap::themeChanged, this, &QgsLayoutItemLegend::mapThemeChanged );
713  }
714 }
715 
717 {
718  if ( mMap )
719  {
720  setupMapConnections( mMap, false );
721  }
722 
723  mMap = map;
724 
725  if ( mMap )
726  {
727  setupMapConnections( mMap, true );
728  mapThemeChanged( mMap->themeToRender( mMap->createExpressionContext() ) );
729  }
730 
732 }
733 
734 void QgsLayoutItemLegend::invalidateCurrentMap()
735 {
736  setLinkedMap( nullptr );
737 }
738 
740 {
742 
743  bool forceUpdate = false;
744  //updates data defined properties and redraws item to match
745  if ( property == QgsLayoutObject::LegendTitle || property == QgsLayoutObject::AllProperties )
746  {
747  bool ok = false;
748  QString t = mDataDefinedProperties.valueAsString( QgsLayoutObject::LegendTitle, context, mTitle, &ok );
749  if ( ok )
750  {
751  mSettings.setTitle( t );
752  forceUpdate = true;
753  }
754  }
756  {
757  bool ok = false;
758  int cols = mDataDefinedProperties.valueAsInt( QgsLayoutObject::LegendColumnCount, context, mColumnCount, &ok );
759  if ( ok && cols >= 0 )
760  {
761  mSettings.setColumnCount( cols );
762  forceUpdate = true;
763  }
764  }
765  if ( forceUpdate )
766  {
767  adjustBoxSize();
768  update();
769  }
770 
772 }
773 
774 
775 void QgsLayoutItemLegend::updateFilterByMapAndRedraw()
776 {
777  updateFilterByMap( true );
778 }
779 
780 void QgsLayoutItemLegend::setModelStyleOverrides( const QMap<QString, QString> &overrides )
781 {
782  mLegendModel->setLayerStyleOverrides( overrides );
783  const QList< QgsLayerTreeLayer * > layers = mLegendModel->rootGroup()->findLayers();
784  for ( QgsLayerTreeLayer *nodeLayer : layers )
785  mLegendModel->refreshLayerLegend( nodeLayer );
786 
787 }
788 
789 void QgsLayoutItemLegend::clearLegendCachedData()
790 {
791  std::function< void( QgsLayerTreeNode * ) > clearNodeCache;
792  clearNodeCache = [&]( QgsLayerTreeNode * node )
793  {
794  mLegendModel->clearCachedData( node );
795  if ( QgsLayerTree::isGroup( node ) )
796  {
797  QgsLayerTreeGroup *group = QgsLayerTree::toGroup( node );
798  const QList< QgsLayerTreeNode * > children = group->children();
799  for ( QgsLayerTreeNode *child : children )
800  {
801  clearNodeCache( child );
802  }
803  }
804  };
805 
806  clearNodeCache( mLegendModel->rootGroup() );
807 }
808 
809 void QgsLayoutItemLegend::mapLayerStyleOverridesChanged()
810 {
811  if ( !mMap )
812  return;
813 
814  // map's style has been changed, so make sure to update the legend here
815  if ( mLegendFilterByMap )
816  {
817  // legend is being filtered by map, so we need to re run the hit test too
818  // as the style overrides may also have affected the visible symbols
819  updateFilterByMap( false );
820  }
821  else
822  {
823  setModelStyleOverrides( mMap->layerStyleOverrides() );
824  }
825 
826  adjustBoxSize();
827 
828  updateFilterByMap( false );
829 }
830 
831 void QgsLayoutItemLegend::mapThemeChanged( const QString &theme )
832 {
833  if ( mThemeName == theme )
834  return;
835 
836  mThemeName = theme;
837 
838  // map's theme has been changed, so make sure to update the legend here
839  if ( mLegendFilterByMap )
840  {
841  // legend is being filtered by map, so we need to re run the hit test too
842  // as the style overrides may also have affected the visible symbols
843  updateFilterByMap( false );
844  }
845  else
846  {
847  if ( mThemeName.isEmpty() )
848  {
849  setModelStyleOverrides( QMap<QString, QString>() );
850  }
851  else
852  {
853  // get style overrides for theme
854  const QMap<QString, QString> overrides = mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( mThemeName );
855  setModelStyleOverrides( overrides );
856  }
857  }
858 
859  adjustBoxSize();
860 
862 }
863 
865 {
866  // ask for update
867  // the actual update will take place before the redraw.
868  // This is to avoid multiple calls to the filter
869  mFilterAskedForUpdate = true;
870 
871  if ( redraw )
872  update();
873 }
874 
875 void QgsLayoutItemLegend::doUpdateFilterByMap()
876 {
877  if ( mMap )
878  {
879  if ( !mThemeName.isEmpty() )
880  {
881  // get style overrides for theme
882  const QMap<QString, QString> overrides = mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( mThemeName );
883  mLegendModel->setLayerStyleOverrides( overrides );
884  }
885  else
886  {
887  mLegendModel->setLayerStyleOverrides( mMap->layerStyleOverrides() );
888  }
889  }
890  else
891  mLegendModel->setLayerStyleOverrides( QMap<QString, QString>() );
892 
893 
894  bool filterByExpression = QgsLayerTreeUtils::hasLegendFilterExpression( *( mCustomLayerTree ? mCustomLayerTree.get() : mLayout->project()->layerTreeRoot() ) );
895 
896  if ( mMap && ( mLegendFilterByMap || filterByExpression || mInAtlas ) )
897  {
898  double dpi = mLayout->renderContext().dpi();
899 
900  QgsRectangle requestRectangle = mMap->requestedExtent();
901 
902  QSizeF size( requestRectangle.width(), requestRectangle.height() );
903  size *= mLayout->convertFromLayoutUnits( mMap->mapUnitsToLayoutUnits(), QgsUnitTypes::LayoutMillimeters ).length() * dpi / 25.4;
904 
905  QgsMapSettings ms = mMap->mapSettings( requestRectangle, size, dpi, true );
906 
907  QgsGeometry filterPolygon;
908  if ( mInAtlas )
909  {
910  filterPolygon = mLayout->reportContext().currentGeometry( mMap->crs() );
911  }
912  mLegendModel->setLegendFilter( &ms, /* useExtent */ mInAtlas || mLegendFilterByMap, filterPolygon, /* useExpressions */ true );
913  }
914  else
915  mLegendModel->setLegendFilterByMap( nullptr );
916 
917  clearLegendCachedData();
918  mForceResize = true;
919 }
920 
922 {
923  return mThemeName;
924 }
925 
927 {
928  mFilterOutAtlas = doFilter;
929 }
930 
932 {
933  return mFilterOutAtlas;
934 }
935 
936 void QgsLayoutItemLegend::onAtlasFeature()
937 {
938  if ( !mLayout->reportContext().feature().isValid() )
939  return;
940  mInAtlas = mFilterOutAtlas;
942 }
943 
944 void QgsLayoutItemLegend::onAtlasEnded()
945 {
946  mInAtlas = false;
948 }
949 
951 {
953 
954  // We only want the last scope from the map's expression context, as this contains
955  // the map specific variables. We don't want the rest of the map's context, because that
956  // will contain duplicate global, project, layout, etc scopes.
957  if ( mMap )
958  context.appendScope( mMap->createExpressionContext().popScope() );
959 
960  QgsExpressionContextScope *scope = new QgsExpressionContextScope( tr( "Legend Settings" ) );
961 
962  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_title" ), title(), true ) );
963  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_column_count" ), columnCount(), true ) );
964  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_split_layers" ), splitLayer(), true ) );
965  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_wrap_string" ), wrapString(), true ) );
966  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_filter_by_map" ), legendFilterByMapEnabled(), true ) );
967  scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_filter_out_atlas" ), legendFilterOutAtlas(), true ) );
968 
969  context.appendScope( scope );
970  return context;
971 }
972 
974 {
975  return MustPlaceInOwnLayer;
976 }
977 
979 {
980  std::function<bool( QgsLayerTreeGroup *group ) >visit;
981 
982  visit = [ =, &visit]( QgsLayerTreeGroup * group ) -> bool
983  {
984  const QList<QgsLayerTreeNode *> childNodes = group->children();
985  for ( QgsLayerTreeNode *node : childNodes )
986  {
987  if ( QgsLayerTree::isGroup( node ) )
988  {
989  QgsLayerTreeGroup *nodeGroup = QgsLayerTree::toGroup( node );
990  if ( !visit( nodeGroup ) )
991  return false;
992  }
993  else if ( QgsLayerTree::isLayer( node ) )
994  {
995  QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
996  if ( !nodeLayer->patchShape().isNull() )
997  {
998  QgsStyleLegendPatchShapeEntity entity( nodeLayer->patchShape() );
999  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, uuid(), displayName() ) ) )
1000  return false;
1001  }
1002  const QList<QgsLayerTreeModelLegendNode *> legendNodes = mLegendModel->layerLegendNodes( nodeLayer );
1003  for ( QgsLayerTreeModelLegendNode *legendNode : legendNodes )
1004  {
1005  if ( QgsSymbolLegendNode *symbolNode = dynamic_cast< QgsSymbolLegendNode * >( legendNode ) )
1006  {
1007  if ( !symbolNode->patchShape().isNull() )
1008  {
1009  QgsStyleLegendPatchShapeEntity entity( symbolNode->patchShape() );
1010  if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, uuid(), displayName() ) ) )
1011  return false;
1012  }
1013  }
1014  }
1015  }
1016  }
1017  return true;
1018  };
1019  return visit( mLegendModel->rootGroup( ) );
1020 }
1021 
1022 
1023 // -------------------------------------------------------------------------
1025 #include "qgsvectorlayer.h"
1026 #include "qgsmaplayerlegend.h"
1027 
1029  : QgsLayerTreeModel( rootNode, parent )
1030  , mLayoutLegend( layout )
1031 {
1034 }
1035 
1037  : QgsLayerTreeModel( rootNode )
1038  , mLayoutLegend( layout )
1039 {
1042 }
1043 
1044 QVariant QgsLegendModel::data( const QModelIndex &index, int role ) const
1045 {
1046  // handle custom layer node labels
1047 
1048  QgsLayerTreeNode *node = index2node( index );
1049  QgsLayerTreeLayer *nodeLayer = QgsLayerTree::isLayer( node ) ? QgsLayerTree::toLayer( node ) : nullptr;
1050  if ( nodeLayer && ( role == Qt::DisplayRole || role == Qt::EditRole ) )
1051  {
1052  QString name = node->customProperty( QStringLiteral( "cached_name" ) ).toString();
1053  if ( !name.isEmpty() )
1054  return name;
1055 
1056  QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
1057 
1058  //finding the first label that is stored
1059  name = nodeLayer->customProperty( QStringLiteral( "legend/title-label" ) ).toString();
1060  if ( name.isEmpty() )
1061  name = nodeLayer->name();
1062  if ( name.isEmpty() )
1063  name = node->customProperty( QStringLiteral( "legend/title-label" ) ).toString();
1064  if ( name.isEmpty() )
1065  name = node->name();
1066  if ( nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() )
1067  {
1068  if ( vlayer && vlayer->featureCount() >= 0 )
1069  {
1070  name += QStringLiteral( " [%1]" ).arg( vlayer->featureCount() );
1071  node->setCustomProperty( QStringLiteral( "cached_name" ), name );
1072  return name;
1073  }
1074  }
1075 
1076  const bool evaluate = ( vlayer && !nodeLayer->labelExpression().isEmpty() ) || name.contains( "[%" );
1077  if ( evaluate )
1078  {
1079  QgsExpressionContext expressionContext;
1080  if ( vlayer )
1081  {
1082  connect( vlayer, &QgsVectorLayer::symbolFeatureCountMapChanged, this, &QgsLegendModel::forceRefresh, Qt::UniqueConnection );
1083  // counting is done here to ensure that a valid vector layer needs to be evaluated, count is used to validate previous count or update the count if invalidated
1084  vlayer->countSymbolFeatures();
1085  }
1086 
1087  if ( mLayoutLegend )
1088  expressionContext = mLayoutLegend->createExpressionContext();
1089 
1090  const QList<QgsLayerTreeModelLegendNode *> legendnodes = layerLegendNodes( nodeLayer, false );
1091  if ( legendnodes.count() > 1 ) // evaluate all existing legend nodes but leave the name for the legend evaluator
1092  {
1093  for ( QgsLayerTreeModelLegendNode *treenode : legendnodes )
1094  {
1095  if ( QgsSymbolLegendNode *symnode = qobject_cast<QgsSymbolLegendNode *>( treenode ) )
1096  symnode->evaluateLabel( expressionContext );
1097  }
1098  }
1099  else if ( QgsSymbolLegendNode *symnode = qobject_cast<QgsSymbolLegendNode *>( legendnodes.first() ) )
1100  name = symnode->evaluateLabel( expressionContext );
1101  }
1102  node->setCustomProperty( QStringLiteral( "cached_name" ), name );
1103  return name;
1104  }
1105  return QgsLayerTreeModel::data( index, role );
1106 }
1107 
1108 Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
1109 {
1110  // make the legend nodes selectable even if they are not by default
1111  if ( index2legendNode( index ) )
1112  return QgsLayerTreeModel::flags( index ) | Qt::ItemIsSelectable;
1113 
1114  return QgsLayerTreeModel::flags( index );
1115 }
1116 
1117 QList<QgsLayerTreeModelLegendNode *> QgsLegendModel::layerLegendNodes( QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent ) const
1118 {
1119  if ( !mLegend.contains( nodeLayer ) )
1120  return QList<QgsLayerTreeModelLegendNode *>();
1121 
1122  const LayerLegendData &data = mLegend[nodeLayer];
1123  QList<QgsLayerTreeModelLegendNode *> lst( data.activeNodes );
1124  if ( !skipNodeEmbeddedInParent && data.embeddedNodeInParent )
1125  lst.prepend( data.embeddedNodeInParent );
1126  return lst;
1127 }
1128 
1130 {
1131  node->removeCustomProperty( QStringLiteral( "cached_name" ) );
1132 }
1133 
1134 void QgsLegendModel::forceRefresh()
1135 {
1136  emit refreshLegend();
1137 }
1138 
1139 
QgsLayoutRenderContext::FlagUseAdvancedEffects
@ FlagUseAdvancedEffects
Enable advanced effects such as blend modes.
Definition: qgslayoutrendercontext.h:45
QgsLegendSettings::setSymbolAlignment
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
Definition: qgslegendsettings.h:245
QgsLegendSettings::setEqualColumnWidth
void setEqualColumnWidth(bool s)
Sets whether all columns should have equal widths.
Definition: qgslegendsettings.h:190
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
QgsLayoutItem::id
QString id() const
Returns the item's ID name.
Definition: qgslayoutitem.h:354
QgsLayoutObject::layout
const QgsLayout * layout() const
Returns the layout the object is attached to.
Definition: qgslayoutobject.cpp:118
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
QgsLegendSettings::title
QString title() const
Returns the title for the legend, which will be rendered above all legend items.
Definition: qgslegendsettings.h:55
QgsLegendStyle::Style
Style
Component of legends which can be styled.
Definition: qgslegendstyle.h:53
QgsSymbolLayerUtils::encodeColor
static QString encodeColor(const QColor &color)
Definition: qgssymbollayerutils.cpp:52
QgsLegendSettings::setTitleAlignment
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
Definition: qgslegendsettings.h:67
QgsLayerTreeNode
Definition: qgslayertreenode.h:74
QgsLayerTreeLayer::patchShape
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
Definition: qgslayertreelayer.cpp:227
QgsLegendRenderer::setLegendSize
void setLegendSize(QSizeF s)
Sets the preferred resulting legend size.
Definition: qgslegendrenderer.h:71
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
Definition: qgsapplication.cpp:605
qgslayertreemodellegendnode.h
QgsLayoutItemLegend::rasterStrokeColor
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
Definition: qgslayoutitemlegend.cpp:487
QgsAbstractPropertyCollection::valueAsInt
int valueAsInt(int key, const QgsExpressionContext &context, int defaultValue=0, bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as an integer.
Definition: qgspropertycollection.cpp:77
QgsLayerTreeModel::index
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
Definition: qgslayertreemodel.cpp:99
QgsExpressionContext::popScope
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
Definition: qgsexpressioncontext.cpp:500
QgsLayoutItemLegend::rasterStrokeWidth
double rasterStrokeWidth() const
Returns the stroke width (in layout units) for the stroke drawn around raster symbol items.
Definition: qgslayoutitemlegend.cpp:497
QgsReadWriteContext
Definition: qgsreadwritecontext.h:34
QgsLayoutItemMap::layerStyleOverrides
QMap< QString, QString > layerStyleOverrides() const
Returns stored overrides of styles for layers.
Definition: qgslayoutitemmap.h:261
QgsLayoutItemLegend::icon
QIcon icon() const override
Returns the item's icon.
Definition: qgslayoutitemlegend.cpp:74
qgsmapthemecollection.h
QgsExpressionContextScope::addVariable
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Definition: qgsexpressioncontext.cpp:93
QgsLegendSettings::setSymbolSize
void setSymbolSize(QSizeF s)
Sets the default symbol size (in millimeters) used for legend items.
Definition: qgslegendsettings.h:235
QgsLayoutItemLegend::titleAlignment
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
Definition: qgslayoutitemlegend.cpp:302
QgsLegendRenderer::drawLegend
Q_DECL_DEPRECATED void drawLegend(QPainter *painter)
Draws the legend with given painter.
Definition: qgslegendrenderer.cpp:58
QgsLayoutItemLegend::setStyleMargin
void setStyleMargin(QgsLegendStyle::Style component, double margin)
Set the margin for a legend component.
Definition: qgslayoutitemlegend.cpp:337
QgsLegendModel::data
QVariant data(const QModelIndex &index, int role) const override
Definition: qgslayoutitemlegend.cpp:1044
QgsLayoutItemLegend::setTitle
void setTitle(const QString &title)
Sets the legend title.
Definition: qgslayoutitemlegend.cpp:286
QgsLegendSettings::setSplitLayer
void setSplitLayer(bool s)
Sets whether layer components can be split over multiple columns.
Definition: qgslegendsettings.h:172
QgsLegendStyle::setFont
void setFont(const QFont &font)
Sets the font used for rendering this legend component.
Definition: qgslegendstyle.h:87
QgsLayoutItemMap::extentChanged
void extentChanged()
Emitted when the map's extent changes.
QgsLayerTreeModel::AllowLegendChangeState
@ AllowLegendChangeState
Allow check boxes for legend nodes (if supported by layer's legend)
Definition: qgslayertreemodel.h:106
QgsLayerTreeModel::mLegend
QHash< QgsLayerTreeLayer *, LayerLegendData > mLegend
Per layer data about layer's legend nodes.
Definition: qgslayertreemodel.h:436
QgsLayoutItemMap::layerStyleOverridesChanged
void layerStyleOverridesChanged()
Emitted when layer style overrides are changed...
QgsLayoutItemLegend::type
int type() const override
Definition: qgslayoutitemlegend.cpp:69
qgssymbollayerutils.h
QgsLayoutItemRenderContext
Definition: qgslayoutitem.h:44
QgsLayoutObject::LegendColumnCount
@ LegendColumnCount
Legend column count.
Definition: qgslayoutobject.h:186
QgsLegendStyle::setMargin
void setMargin(Side side, double margin)
Sets the margin (in mm) for the specified side of the component.
Definition: qgslegendstyle.h:113
QgsLayoutItemMap::mapSettings
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, double dpi, bool includeLayerSettings) const
Returns map settings that will be used for drawing of the map.
Definition: qgslayoutitemmap.cpp:1398
QgsLayoutObject::mDataDefinedProperties
QgsPropertyCollection mDataDefinedProperties
Definition: qgslayoutobject.h:337
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsLegendSettings::setMmPerMapUnit
Q_DECL_DEPRECATED void setMmPerMapUnit(double mmPerMapUnit)
Definition: qgslegendsettings.cpp:45
QgsLegendSettings::style
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
Definition: qgslegendsettings.h:81
QgsStyleEntityVisitorInterface
Definition: qgsstyleentityvisitor.h:33
QgsLayoutItemMap::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutitemmap.cpp:1512
QgsLegendSettings::setBoxSpace
void setBoxSpace(double s)
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend...
Definition: qgslegendsettings.h:104
QgsLayoutItem::refreshDataDefinedProperty
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Definition: qgslayoutitem.cpp:1082
QgsLegendStyle::writeXml
void writeXml(const QString &name, QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes the component's style definition to an XML element.
Definition: qgslegendstyle.cpp:43
QgsLayoutItemLegend::setFontColor
void setFontColor(const QColor &color)
Sets the legend font color.
Definition: qgslayoutitemlegend.cpp:382
QgsLayerTreeNode::customPropertyChanged
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
QgsLayerTree::toLayer
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:88
QgsLayerTreeLayer::name
QString name() const override
Returns the layer's name.
Definition: qgslayertreelayer.cpp:81
QgsLayerTreeModel
Definition: qgslayertreemodel.h:53
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
qgsmapsettings.h
QgsRenderContext::scaleFactor
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Definition: qgsrendercontext.h:317
QgsLegendSettings::rasterStrokeColor
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:284
QgsLayoutItemLegend::rstyle
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable legend style.
Definition: qgslayoutitemlegend.cpp:312
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
QgsLayoutObject::changed
void changed()
Emitted when the object's properties change.
QgsSymbolLayerUtils::decodeColor
static QColor decodeColor(const QString &str)
Definition: qgssymbollayerutils.cpp:57
QgsLayoutItemLegend::legendFilterOutAtlas
bool legendFilterOutAtlas() const
Returns whether to filter out legend elements outside of the current atlas feature.
Definition: qgslayoutitemlegend.cpp:931
QgsLayoutItemLegend::wmsLegendWidth
double wmsLegendWidth() const
Returns the WMS legend width.
Definition: qgslayoutitemlegend.cpp:417
QgsLayoutItem::sizeWithUnits
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
Definition: qgslayoutitem.h:668
QgsRectangle
Definition: qgsrectangle.h:41
QgsLayoutItemLegend::readPropertiesFromElement
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
Definition: qgslayoutitemlegend.cpp:575
QgsStyleEntityVisitorInterface::StyleLeaf
Contains information relating to the style entity currently being visited.
Definition: qgsstyleentityvisitor.h:60
QgsLegendSettings::drawRasterStroke
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
Definition: qgslegendsettings.h:264
QgsLayerTree::toGroup
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:77
QgsLegendModel::refreshLegend
void refreshLegend()
Emitted to refresh the legend.
QgsLayoutItem::redraw
virtual void redraw()
Triggers a redraw (update) of the item.
Definition: qgslayoutitem.cpp:1190
QgsLayoutItemLegend
Definition: qgslayoutitemlegend.h:113
QgsLegendStyle::Title
@ Title
Legend title.
Definition: qgslegendstyle.h:70
qgslayoututils.h
QgsLayoutItemLegend::finalizeRestoreFromXml
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
Definition: qgslayoutitemlegend.cpp:160
QgsLayoutItemLegend::displayName
QString displayName() const override
Gets item display name.
Definition: qgslayoutitemlegend.cpp:667
QgsLayoutUtils::createRenderContextForLayout
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
Definition: qgslayoututils.cpp:138
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:752
QgsLayoutItemLegend::refresh
void refresh() override
Definition: qgslayoutitemlegend.cpp:168
QgsLayerTreeModel::index2legendNode
static QgsLayerTreeModelLegendNode * index2legendNode(const QModelIndex &index)
Returns legend node for given index.
Definition: qgslayertreemodel.cpp:1396
QgsLayoutObject::AllProperties
@ AllProperties
All properties for item.
Definition: qgslayoutobject.h:135
QgsLayoutItemLegend::wmsLegendHeight
double wmsLegendHeight() const
Returns the WMS legend height.
Definition: qgslayoutitemlegend.cpp:427
qgsexpressioncontext.h
QgsLayoutItemLegend::setResizeToContents
void setResizeToContents(bool enabled)
Sets whether the legend should automatically resize to fit its contents.
Definition: qgslayoutitemlegend.cpp:234
QgsLayoutItemLegend::legendFilterByMapEnabled
bool legendFilterByMapEnabled() const
Find out whether legend items are filtered to show just the ones visible in the associated map.
Definition: qgslayoutitemlegend.h:185
QgsLayerTreeUtils::hasLegendFilterExpression
static bool hasLegendFilterExpression(const QgsLayerTreeGroup &group)
Test if one of the layers in a group has an expression filter.
Definition: qgslayertreeutils.cpp:442
QgsLayerTree
Definition: qgslayertree.h:32
QgsLayoutItemLegend::create
static QgsLayoutItemLegend * create(QgsLayout *layout)
Returns a new legend item for the specified layout.
Definition: qgslayoutitemlegend.cpp:64
QgsLegendModel::clearCachedData
void clearCachedData(QgsLayerTreeNode *node) const
Clears any previously cached data for the specified node.
Definition: qgslayoutitemlegend.cpp:1129
QgsLayoutItemLegend::setAutoUpdateModel
void setAutoUpdateModel(bool autoUpdate)
Sets whether the legend content should auto update to reflect changes in the project's layer tree.
Definition: qgslayoutitemlegend.cpp:252
QgsLayoutItemLegend::setLegendFilterOutAtlas
void setLegendFilterOutAtlas(bool doFilter)
When set to true, during an atlas rendering, it will filter out legend elements where features are ou...
Definition: qgslayoutitemlegend.cpp:926
QgsLayoutItemLegend::writePropertiesToElement
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
Definition: qgslayoutitemlegend.cpp:514
QgsLegendStyle::Side
Side
Margin sides.
Definition: qgslegendstyle.h:67
QgsLayoutItem::ExportLayerBehavior
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
Definition: qgslayoutitem.h:424
QgsLegendSettings::rasterStrokeWidth
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:305
QgsLayoutItemLegend::setLineSpacing
void setLineSpacing(double spacing)
Sets the spacing in-between multiple lines.
Definition: qgslayoutitemlegend.cpp:352
QgsLayoutItemLegend::setStyle
void setStyle(QgsLegendStyle::Style component, const QgsLegendStyle &style)
Sets the style of component to style for the legend.
Definition: qgslayoutitemlegend.cpp:322
QgsLayoutItemLegend::itemFlags
QgsLayoutItem::Flags itemFlags() const override
Returns the item's flags, which indicate how the item behaves.
Definition: qgslayoutitemlegend.cpp:79
QgsLayoutItemLegend::setSplitLayer
void setSplitLayer(bool enabled)
Sets whether the legend items from a single layer can be split over multiple columns.
Definition: qgslayoutitemlegend.cpp:462
QgsLayoutItemLegend::styleFont
QFont styleFont(QgsLegendStyle::Style component) const
Returns the font settings for a legend component.
Definition: qgslayoutitemlegend.cpp:327
QgsLegendSettings::setTitle
void setTitle(const QString &t)
Sets the title for the legend, which will be rendered above all legend items.
Definition: qgslegendsettings.h:48
QgsLegendSettings::setRasterStrokeWidth
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:316
QgsLayoutItemLegend::setEqualColumnWidth
void setEqualColumnWidth(bool equalize)
Sets whether column widths should be equalized.
Definition: qgslayoutitemlegend.cpp:472
QgsLayerTreeLayer
Definition: qgslayertreelayer.h:43
QgsLayoutItemLegend::setRasterStrokeColor
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
Definition: qgslayoutitemlegend.cpp:492
QgsLegendSettings::boxSpace
double boxSpace() const
Returns the legend box space (in millimeters), which is the empty margin around the inside of the leg...
Definition: qgslegendsettings.h:96
QgsLayoutItem::FlagOverridesPaint
@ FlagOverridesPaint
Item overrides the default layout item painting method.
Definition: qgslayoutitem.h:301
QgsProject::projectColorsChanged
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
QgsLayerTreeModel::LayerLegendData
Structure that stores all data associated with one map layer.
Definition: qgslayertreemodel.h:399
QgsLegendSettings::setColumnSpace
void setColumnSpace(double s)
Sets the margin space between adjacent columns (in millimeters).
Definition: qgslegendsettings.h:138
QgsLayoutItemLegend::symbolAlignment
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
Definition: qgslayoutitemlegend.cpp:402
QgsLegendSettings::wmsLegendSize
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
Definition: qgslegendsettings.h:323
QgsLayerTreeGroup
Definition: qgslayertreegroup.h:34
QgsLayoutItemMap::extent
QgsRectangle extent() const
Returns the current map extent.
Definition: qgslayoutitemmap.cpp:252
QgsLayoutItemLegend::accept
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitemlegend.cpp:978
QgsLayoutItemLegend::setBoxSpace
void setBoxSpace(double space)
Sets the legend box space.
Definition: qgslayoutitemlegend.cpp:362
QgsLayoutItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Handles preparing a paint surface for the layout item and painting the item's content.
Definition: qgslayoutitem.cpp:285
QgsLayoutItem::MustPlaceInOwnLayer
@ MustPlaceInOwnLayer
Item must be placed in its own individual layer.
Definition: qgslayoutitem.h:428
QgsMapSettings::scale
double scale() const
Returns the calculated map scale.
Definition: qgsmapsettings.cpp:395
QgsLayoutItemLegend::drawRasterStroke
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
Definition: qgslayoutitemlegend.cpp:477
QgsLayoutItem
Base class for graphical items within a QgsLayout.
Definition: qgslayoutitem.h:112
QgsLegendSettings::titleAlignment
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
Definition: qgslegendsettings.h:61
QgsLayoutItemLegend::updateFilterByMap
void updateFilterByMap(bool redraw=true)
Updates the legend content when filtered by map.
Definition: qgslayoutitemlegend.cpp:864
QgsLayoutItemLegend::exportLayerBehavior
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
Definition: qgslayoutitemlegend.cpp:973
QgsLegendSettings::setLineSpacing
void setLineSpacing(double s)
Sets the line spacing to use between lines of legend text.
Definition: qgslegendsettings.h:344
QgsLayerTreeLayer::layer
QgsMapLayer * layer() const
Returns the map layer associated with this node.
Definition: qgslayertreelayer.h:74
qgslayertree.h
QgsLayoutItemMap::requestedExtent
QgsRectangle requestedExtent() const
Calculates the extent to request and the yShift of the top-left point in case of rotation.
Definition: qgslayoutitemmap.cpp:1674
QgsLegendSettings::setDpi
Q_DECL_DEPRECATED void setDpi(int dpi)
Definition: qgslegendsettings.cpp:85
QgsLayoutItemLegend::symbolWidth
double symbolWidth() const
Returns the legend symbol width.
Definition: qgslayoutitemlegend.cpp:387
qgslayout.h
QgsLayoutItemLegend::QgsLayoutItemLegend
QgsLayoutItemLegend(QgsLayout *layout)
Constructor for QgsLayoutItemLegend, with the specified parent layout.
Definition: qgslayoutitemlegend.cpp:41
QgsLayoutItemMap::crs
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
Definition: qgslayoutitemmap.cpp:264
QgsLayoutItemMap::mapUnitsToLayoutUnits
double mapUnitsToLayoutUnits() const
Returns the conversion factor from map units to layout units.
Definition: qgslayoutitemmap.cpp:1573
QgsLayoutItemLegend::setLinkedMap
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to associate with the legend.
Definition: qgslayoutitemlegend.cpp:716
QgsLegendSettings::setDrawRasterStroke
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
Definition: qgslegendsettings.h:274
QgsExpressionContextScope
Single scope for storing variables and functions for use within a QgsExpressionContext....
Definition: qgsexpressioncontext.h:111
QgsLegendModel::layerLegendNodes
QList< QgsLayerTreeModelLegendNode * > layerLegendNodes(QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent=false) const
Returns filtered list of active legend nodes attached to a particular layer node (by default it retur...
Definition: qgslayoutitemlegend.cpp:1117
QgsLegendSettings::setMapScale
Q_DECL_DEPRECATED void setMapScale(double scale)
Sets the legend map scale.
Definition: qgslegendsettings.cpp:65
QgsAbstractPropertyCollection::valueAsString
QString valueAsString(int key, const QgsExpressionContext &context, const QString &defaultString=QString(), bool *ok=nullptr) const
Calculates the current value of the property with the specified key and interprets it as a string.
Definition: qgspropertycollection.cpp:42
QgsWms::legendNode
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
Definition: qgswmsgetlegendgraphics.cpp:358
QgsLayoutItemLegend::fontColor
QColor fontColor() const
Returns the legend font color.
Definition: qgslayoutitemlegend.cpp:377
QgsLayoutItemLegend::symbolHeight
double symbolHeight() const
Returns the legend symbol height.
Definition: qgslayoutitemlegend.cpp:407
QgsLayoutItemLegend::setSymbolWidth
void setSymbolWidth(double width)
Sets the legend symbol width.
Definition: qgslayoutitemlegend.cpp:392
QgsExpressionContext::appendScope
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Definition: qgsexpressioncontext.cpp:490
QgsLayoutItem::refresh
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
Definition: qgslayoutitem.cpp:1172
QgsLayoutItemLegend::themeName
QString themeName() const
Returns the name of the theme currently linked to the legend.
Definition: qgslayoutitemlegend.cpp:921
qgsvectorlayer.h
QgsLayerTreeModel::index2node
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Returns layer tree node for given index.
Definition: qgslayertreemodel.cpp:63
qgslayoutitemlegend.h
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:39
QgsLayoutObject::LegendTitle
@ LegendTitle
Legend title.
Definition: qgslayoutobject.h:185
QgsLayoutItemLegend::columnCount
int columnCount() const
Returns the legend column count.
Definition: qgslayoutitemlegend.cpp:446
QgsLayoutItemLegend::boxSpace
double boxSpace() const
Returns the legend box space.
Definition: qgslayoutitemlegend.cpp:357
QgsLayerTree::isLayer
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:66
QgsLegendSettings::setStyle
void setStyle(QgsLegendStyle::Style s, const QgsLegendStyle &style)
Sets the style for a legend component.
Definition: qgslegendsettings.h:88
QgsLayoutItemLegend::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Definition: qgslayoutitemlegend.cpp:84
QgsLayoutItemLegend::draw
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
Definition: qgslayoutitemlegend.cpp:175
QgsLayoutItemRenderContext::renderContext
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Definition: qgslayoutitem.h:72
QgsLayoutItem::uuid
virtual QString uuid() const
Returns the item identification string.
Definition: qgslayoutitem.h:340
qgslegendstyle.h
QgsLayoutItemLegend::style
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns legend style.
Definition: qgslayoutitemlegend.cpp:317
QgsLayoutItemMap::themeChanged
void themeChanged(const QString &theme)
Emitted when the map's associated theme is changed.
QgsLayoutItemLegend::setColumnCount
void setColumnCount(int count)
Sets the legend column count.
Definition: qgslayoutitemlegend.cpp:451
QgsLegendSettings::setFontColor
void setFontColor(const QColor &c)
Sets the font color used for legend items.
Definition: qgslegendsettings.h:204
QgsLayoutItemLegend::setDrawRasterStroke
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
Definition: qgslayoutitemlegend.cpp:482
QgsLegendSettings::setColumnCount
void setColumnCount(int c)
Sets the desired minimum number of columns to show in the legend.
Definition: qgslegendsettings.h:158
QgsLayoutItemLegend::setWmsLegendHeight
void setWmsLegendHeight(double height)
Sets the WMS legend height.
Definition: qgslayoutitemlegend.cpp:431
QgsLayoutObject::mLayout
QPointer< QgsLayout > mLayout
Definition: qgslayoutobject.h:335
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsGeometry
Definition: qgsgeometry.h:122
QgsLayerTreeModel::setFlag
void setFlag(Flag f, bool on=true)
Enable or disable a model flag.
Definition: qgslayertreemodel.cpp:1162
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
QgsLayoutItemLegend::adjustBoxSize
void adjustBoxSize()
Sets the legend's item bounds to fit the whole legend content.
Definition: qgslayoutitemlegend.cpp:208
QgsLayerTreeNode::setCustomProperty
void setCustomProperty(const QString &key, const QVariant &value)
Sets a custom property for the node. Properties are stored in a map and saved in project file.
Definition: qgslayertreenode.cpp:180
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsLayoutItemMap::mapRotationChanged
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
QgsLegendStyle::font
QFont font() const
Returns the font used for rendering this legend component.
Definition: qgslegendstyle.h:81
QgsLayoutItemLegend::setTitleAlignment
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
Definition: qgslayoutitemlegend.cpp:307
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
QgsLayerTreeModel::flags
Flags flags() const
Returns OR-ed combination of model flags.
Definition: qgslayertreemodel.cpp:1170
QgsLegendSettings::splitLayer
bool splitLayer() const
Returns true if layer components can be split over multiple columns.
Definition: qgslegendsettings.h:165
QgsLayoutItemLegend::setStyleFont
void setStyleFont(QgsLegendStyle::Style component, const QFont &font)
Sets the style font for a legend component.
Definition: qgslayoutitemlegend.cpp:332
QgsRectangle::height
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsLayerTreeNode::children
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
Definition: qgslayertreenode.h:112
QgsLayoutItem::attemptResize
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
Definition: qgslayoutitem.cpp:432
qgsmaplayerlegend.h
QgsLegendSettings::symbolSize
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
Definition: qgslegendsettings.h:228
QgsVectorLayer::symbolFeatureCountMapChanged
void symbolFeatureCountMapChanged()
Emitted when the feature count for symbols on this layer has been recalculated.
QgsLayerTreeNode::name
virtual QString name() const =0
Returns name of the node.
QgsLayoutItemLegend::setColumnSpace
void setColumnSpace(double spacing)
Sets the legend column spacing.
Definition: qgslayoutitemlegend.cpp:372
QgsVectorLayer::countSymbolFeatures
QgsVectorLayerFeatureCounter * countSymbolFeatures(bool storeSymbolFids=false)
Count features for symbols.
Definition: qgsvectorlayer.cpp:766
QgsLayoutItemLegend::splitLayer
bool splitLayer() const
Returns whether the legend items from a single layer can be split over multiple columns.
Definition: qgslayoutitemlegend.cpp:457
QgsStyleEntityVisitorInterface::visit
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
Definition: qgsstyleentityvisitor.h:153
qgslayertreeutils.h
QgsLegendSettings::equalColumnWidth
bool equalColumnWidth() const
Returns true if all columns should have equal widths.
Definition: qgslegendsettings.h:181
QgsLayoutSize
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
QgsLayoutItemLegend::setRasterStrokeWidth
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
Definition: qgslayoutitemlegend.cpp:502
qgslayertreemodel.h
QgsLayoutItemLegend::setWmsLegendWidth
void setWmsLegendWidth(double width)
Sets the WMS legend width.
Definition: qgslayoutitemlegend.cpp:422
QgsLegendSettings::setWmsLegendSize
void setWmsLegendSize(QSizeF s)
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Definition: qgslegendsettings.h:330
QgsLegendRenderer
The QgsLegendRenderer class handles automatic layout and rendering of legend. The content is given by...
Definition: qgslegendrenderer.h:46
QgsLegendSettings::fontColor
QColor fontColor() const
Returns the font color used for legend items.
Definition: qgslegendsettings.h:197
QgsLegendSettings::lineSpacing
double lineSpacing() const
Returns the line spacing to use between lines of legend text.
Definition: qgslegendsettings.h:337
QgsLegendSettings::setUseAdvancedEffects
Q_DECL_DEPRECATED void setUseAdvancedEffects(bool use)
Definition: qgslegendsettings.cpp:55
QgsUnitTypes::LayoutMillimeters
@ LayoutMillimeters
Millimeters.
Definition: qgsunittypes.h:182
QgsLayerTreeModel::AllowNodeReorder
@ AllowNodeReorder
Allow reordering with drag'n'drop.
Definition: qgslayertreemodel.h:103
QgsLegendSettings::rstyle
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns modifiable reference to the style for a legend component.
Definition: qgslegendsettings.h:74
QgsStyleLegendPatchShapeEntity
Definition: qgsstyle.h:1257
QgsLayoutItemLegend::title
QString title() const
Returns the legend title.
Definition: qgslayoutitemlegend.cpp:297
QgsLegendSettings::setRasterStrokeColor
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
Definition: qgslegendsettings.h:295
QgsLegendRenderer::minimumSize
QSizeF minimumSize(QgsRenderContext *renderContext=nullptr)
Runs the layout algorithm and returns the minimum size required for the legend.
Definition: qgslegendrenderer.cpp:39
QgsLayoutItemLegend::refreshDataDefinedProperty
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties) override
Definition: qgslayoutitemlegend.cpp:739
qgslogger.h
QgsLayoutItemLegend::resizeToContents
bool resizeToContents() const
Returns whether the legend should automatically resize to fit its contents.
Definition: qgslayoutitemlegend.cpp:239
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:174
QgsLayerTreeModel::data
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Definition: qgslayertreemodel.cpp:158
QgsLayoutItemLegend::setSymbolHeight
void setSymbolHeight(double height)
Sets the legend symbol height.
Definition: qgslayoutitemlegend.cpp:412
QgsExpressionContextScope::StaticVariable
Single variable definition for use within a QgsExpressionContextScope.
Definition: qgsexpressioncontext.h:118
QgsLayoutItemLegend::lineSpacing
double lineSpacing() const
Returns the spacing in-between lines in layout units.
Definition: qgslayoutitemlegend.cpp:347
QgsLegendModel
Definition: qgslayoutitemlegend.h:43
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsLayerTree::readXml
static QgsLayerTree * readXml(QDomElement &element, const QgsReadWriteContext &context)
Load the layer tree from an XML element.
Definition: qgslayertree.cpp:114
QgsSymbolLegendNode
Definition: qgslayertreemodellegendnode.h:283
qgslayoutitemregistry.h
QgsLayerTreeNode::removeCustomProperty
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file.
Definition: qgslayertreenode.cpp:194
QgsLegendModel::QgsLegendModel
QgsLegendModel(QgsLayerTree *rootNode, QObject *parent=nullptr, QgsLayoutItemLegend *layout=nullptr)
Construct the model based on the given layer tree.
Definition: qgslayoutitemlegend.cpp:1028
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:751
QgsLegendStyle::readXml
void readXml(const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads the component's style definition from an XML element.
Definition: qgslegendstyle.cpp:67
QgsLayerTree::isGroup
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:56
QgsLayoutItemRegistry::LayoutLegend
@ LayoutLegend
Legend item.
Definition: qgslayoutitemregistry.h:320
qgslegendrenderer.h
QgsLegendSettings::columnSpace
double columnSpace() const
Returns the margin space between adjacent columns (in millimeters).
Definition: qgslegendsettings.h:131
QgsLayoutItem::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutitem.cpp:1159
QgsLayoutItemLegend::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutitemlegend.cpp:950
QgsLegendStyle::Group
@ Group
Legend group title.
Definition: qgslegendstyle.h:71
QgsLayoutItemLegend::wrapString
QString wrapString() const
Returns the legend text wrapping string.
Definition: qgslayoutitemlegend.cpp:441
QgsLegendStyle::Subgroup
@ Subgroup
Legend subgroup title.
Definition: qgslegendstyle.h:72
qgslayoutmodel.h
QgsLayoutItemLegend::setSymbolAlignment
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
Definition: qgslayoutitemlegend.cpp:397
qgsproject.h
QgsRectangle::width
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsLayoutItemLegend::columnSpace
double columnSpace() const
Returns the legend column spacing.
Definition: qgslayoutitemlegend.cpp:367
QgsLegendSettings::setWrapChar
void setWrapChar(const QString &t)
Sets a string to use as a wrapping character.
Definition: qgslegendsettings.h:114
QgsLayoutItemLegend::updateLegend
void updateLegend()
Updates the model and all legend entries.
Definition: qgslayoutitemlegend.cpp:508
QgsLayoutItemLegend::equalColumnWidth
bool equalColumnWidth() const
Returns whether column widths should be equalized.
Definition: qgslayoutitemlegend.cpp:467
QgsLayoutItemLegend::setWrapString
void setWrapString(const QString &string)
Sets the legend text wrapping string.
Definition: qgslayoutitemlegend.cpp:436
QgsLayoutObject::DataDefinedProperty
DataDefinedProperty
Data defined properties for different item types.
Definition: qgslayoutobject.h:132
qgsstyleentityvisitor.h
QgsLegendSettings::wrapChar
QString wrapChar() const
Returns the string used as a wrapping character.
Definition: qgslegendsettings.h:124
QgsLayoutItemLegend::autoUpdateModel
bool autoUpdateModel() const
Returns whether the legend content should auto update to reflect changes in the project's layer tree.
Definition: qgslayoutitemlegend.cpp:275
QgsLegendStyle
Definition: qgslegendstyle.h:35
qgslayoutitemmap.h
QgsLayoutItemLegend::setLegendFilterByMapEnabled
void setLegendFilterByMapEnabled(bool enabled)
Set whether legend items should be filtered to show just the ones visible in the associated map.
Definition: qgslayoutitemlegend.cpp:280
QgsLegendPatchShape::isNull
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
Definition: qgslegendpatchshape.cpp:32
QgsLayerTreeModelLegendNode
Definition: qgslayertreemodellegendnode.h:50