QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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"
21#include "qgslayoutitemmap.h"
22#include "qgslayoutmodel.h"
23#include "qgslayertree.h"
24#include "qgslayertreemodel.h"
25#include "qgslegendrenderer.h"
26#include "qgslegendstyle.h"
27#include "qgslogger.h"
28#include "qgsmapsettings.h"
29#include "qgsproject.h"
30#include "qgscolorutils.h"
31#include "qgslayertreeutils.h"
32#include "qgslayoututils.h"
33#include "qgslayout.h"
36#include "qgsvectorlayer.h"
41
42#include <QDomDocument>
43#include <QDomElement>
44#include <QPainter>
46
48 : QgsLayoutItem( layout )
49 , mLegendModel( new QgsLegendModel( nullptr, this ) )
50{
51#if 0 //no longer required?
52 connect( &layout->atlasComposition(), &QgsAtlasComposition::renderEnded, this, &QgsLayoutItemLegend::onAtlasEnded );
53#endif
54
55 mTitle = mSettings.title();
56
57 connect( mLegendModel.get(), &QgsLayerTreeModel::hitTestStarted, this, [this] { emit backgroundTaskCountChanged( 1 ); } );
58 connect( mLegendModel.get(), &QgsLayerTreeModel::hitTestCompleted, this, [this]
59 {
60 adjustBoxSize();
61 emit backgroundTaskCountChanged( 0 );
62 } );
63
64 // Connect to the main layertreeroot.
65 // It serves in "auto update mode" as a medium between the main app legend and this one
66 connect( mLayout->project()->layerTreeRoot(), &QgsLayerTreeNode::customPropertyChanged, this, &QgsLayoutItemLegend::nodeCustomPropertyChanged );
67
68 // If project colors change, we need to redraw legend, as legend symbols may rely on project colors
69 connect( mLayout->project(), &QgsProject::projectColorsChanged, this, [this]
70 {
71 invalidateCache();
72 update();
73 } );
74 connect( mLegendModel.get(), &QgsLegendModel::refreshLegend, this, [this]
75 {
76 // NOTE -- we do NOT connect to ::refresh here, as we don't want to trigger the call to onAtlasFeature() which sets mFilterAskedForUpdate to true,
77 // causing an endless loop.
78 invalidateCache();
79 update();
80 } );
81}
82
84{
85 return new QgsLayoutItemLegend( layout );
86}
87
89{
91}
92
94{
95 return QgsApplication::getThemeIcon( QStringLiteral( "/mLayoutItemLegend.svg" ) );
96}
97
99{
101}
102
103void QgsLayoutItemLegend::paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget )
104{
105 if ( !painter )
106 return;
107
108 ensureModelIsInitialized();
109
110 if ( mFilterAskedForUpdate )
111 {
112 mFilterAskedForUpdate = false;
113 doUpdateFilterByMap();
114 }
115
116 if ( mLayout )
117 {
118 if ( !mLayout->renderContext().isPreviewRender() && mLegendModel->hitTestInProgress() )
119 {
120 mLegendModel->waitForHitTestBlocking();
121 }
122 }
123
124 const int dpi = painter->device()->logicalDpiX();
125 const double dotsPerMM = dpi / 25.4;
126
127 if ( mLayout )
128 {
130 // no longer required, but left set for api stability
132 mSettings.setDpi( dpi );
135 }
136 if ( mMap && mLayout )
137 {
139 // no longer required, but left set for api stability
140 mSettings.setMmPerMapUnit( mLayout->convertFromLayoutUnits( mMap->mapUnitsToLayoutUnits(), Qgis::LayoutUnit::Millimeters ).length() );
142
143 // use a temporary QgsMapSettings to find out real map scale
144 const QSizeF mapSizePixels = QSizeF( mMap->rect().width() * dotsPerMM, mMap->rect().height() * dotsPerMM );
145 const QgsRectangle mapExtent = mMap->extent();
146
147 const QgsMapSettings ms = mMap->mapSettings( mapExtent, mapSizePixels, dpi, false );
148
149 // no longer required, but left set for api stability
151 mSettings.setMapScale( ms.scale() );
153 }
154 mInitialMapScaleCalculated = true;
155
156 QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
157 legendRenderer.setLegendSize( mForceResize && mSizeToContents ? QSize() : rect().size() );
158
159 const QPointF oldPos = pos();
160
161 //adjust box if width or height is too small
162 if ( mSizeToContents )
163 {
164 QgsRenderContext context = mMap ? QgsLayoutUtils::createRenderContextForMap( mMap, painter )
166
167 const QSizeF size = legendRenderer.minimumSize( &context );
168 if ( mForceResize )
169 {
170 mForceResize = false;
171
172 //set new rect, respecting position mode and data defined size/position
173 const QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
174 attemptResize( newSize );
175 }
176 else if ( size.height() > rect().height() || size.width() > rect().width() )
177 {
178 //need to resize box
179 QSizeF targetSize = rect().size();
180 if ( size.height() > targetSize.height() )
181 targetSize.setHeight( size.height() );
182 if ( size.width() > targetSize.width() )
183 targetSize.setWidth( size.width() );
184
185 const QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( targetSize, sizeWithUnits().units() );
186 //set new rect, respecting position mode and data defined size/position
187 attemptResize( newSize );
188 }
189 }
190
191 // attemptResize may change the legend position and would call setPos
192 // BUT the position is actually changed for the next draw, so we need to translate of the difference
193 // between oldPos and newPos
194 // the issue doesn't appear in desktop rendering but only in export because in the first one,
195 // Qt triggers a redraw on position change
196 painter->save();
197 painter->translate( pos() - oldPos );
198 QgsLayoutItem::paint( painter, itemStyle, pWidget );
199 painter->restore();
200}
201
203{
204 if ( !mMapUuid.isEmpty() )
205 {
206 setLinkedMap( qobject_cast< QgsLayoutItemMap * >( mLayout->itemByUuid( mMapUuid, true ) ) );
207 }
208
209 if ( !mFilterByMapUuids.isEmpty() )
210 {
211 QList< QgsLayoutItemMap * > maps;
212 maps.reserve( mFilterByMapUuids.size() );
213 for ( const QString &uuid : std::as_const( mFilterByMapUuids ) )
214 {
215 if ( QgsLayoutItemMap *map = qobject_cast< QgsLayoutItemMap * >( mLayout->itemByUuid( uuid, true ) ) )
216 {
217 maps << map;
218 }
219 }
220 setFilterByMapItems( maps );
221 }
222}
223
225{
227 clearLegendCachedData();
228 onAtlasFeature();
229}
230
232{
233 clearLegendCachedData();
235}
236
238{
239 QPainter *painter = context.renderContext().painter();
240
241 QgsRenderContext rc = mMap ? QgsLayoutUtils::createRenderContextForMap( mMap, painter, context.renderContext().scaleFactor() * 25.4 )
243
245
246 const QgsScopedQPainterState painterState( painter );
247
248 // painter is scaled to dots, so scale back to layout units
249 painter->scale( rc.scaleFactor(), rc.scaleFactor() );
250
251 painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
252
253 if ( !mSizeToContents )
254 {
255 // set a clip region to crop out parts of legend which don't fit
256 const QRectF thisPaintRect = QRectF( 0, 0, rect().width(), rect().height() );
257 painter->setClipRect( thisPaintRect );
258 }
259
260 if ( mLayout )
261 {
262 // no longer required, but left for API compatibility
264 mSettings.setDpi( mLayout->renderContext().dpi() );
266 }
267
268 QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
269 legendRenderer.setLegendSize( rect().size() );
270
271 legendRenderer.drawLegend( rc );
272}
273
275{
276 if ( !mSizeToContents )
277 return;
278
279 if ( !mInitialMapScaleCalculated )
280 {
281 // this is messy - but until we have painted the item we have no knowledge of the current DPI
282 // and so cannot correctly calculate the map scale. This results in incorrect size calculations
283 // for marker symbols with size in map units, causing the legends to initially expand to huge
284 // sizes if we attempt to calculate the box size first.
285 return;
286 }
287
288 QgsRenderContext context = mMap ? QgsLayoutUtils::createRenderContextForMap( mMap, nullptr ) :
290
291 QgsLegendRenderer legendRenderer( mLegendModel.get(), mSettings );
292 const QSizeF size = legendRenderer.minimumSize( &context );
293 QgsDebugMsgLevel( QStringLiteral( "width = %1 height = %2" ).arg( size.width() ).arg( size.height() ), 2 );
294 if ( size.isValid() )
295 {
296 const QgsLayoutSize newSize = mLayout->convertFromLayoutUnits( size, sizeWithUnits().units() );
297 //set new rect, respecting position mode and data defined size/position
298 attemptResize( newSize );
299 }
300}
301
303{
304 mSizeToContents = enabled;
305}
306
308{
309 return mSizeToContents;
310}
311
312void QgsLayoutItemLegend::setCustomLayerTree( QgsLayerTree *rootGroup )
313{
314 if ( !mDeferLegendModelInitialization )
315 {
316 mLegendModel->setRootGroup( rootGroup ? rootGroup : ( mLayout ? mLayout->project()->layerTreeRoot() : nullptr ) );
317 }
318
319 mCustomLayerTree.reset( rootGroup );
320}
321
322void QgsLayoutItemLegend::ensureModelIsInitialized()
323{
324 if ( mDeferLegendModelInitialization )
325 {
326 mDeferLegendModelInitialization = false;
327 setCustomLayerTree( mCustomLayerTree.release() );
328 }
329}
330
332{
333 ensureModelIsInitialized();
334 return mLegendModel.get();
335}
336
338{
339 if ( autoUpdate == autoUpdateModel() )
340 return;
341
342 setCustomLayerTree( autoUpdate ? nullptr : mLayout->project()->layerTreeRoot()->clone() );
344 updateFilterByMap( false );
345}
346
347void QgsLayoutItemLegend::nodeCustomPropertyChanged( QgsLayerTreeNode *, const QString &key )
348{
349 if ( key == QLatin1String( "cached_name" ) )
350 return;
351
352 if ( autoUpdateModel() )
353 {
354 // in "auto update" mode, some parameters on the main app legend may have been changed (expression filtering)
355 // we must then call updateItem to reflect the changes
356 updateFilterByMap( false );
357 }
358}
359
361{
362 return !mCustomLayerTree;
363}
364
366{
367 if ( mLegendFilterByMap == enabled )
368 return;
369
370 mLegendFilterByMap = enabled;
371 updateFilterByMap( false );
372}
373
374void QgsLayoutItemLegend::setTitle( const QString &t )
375{
376 mTitle = t;
377 mSettings.setTitle( t );
378
379 if ( mLayout && id().isEmpty() )
380 {
381 //notify the model that the display name has changed
382 mLayout->itemsModel()->updateItemDisplayName( this );
383 }
384}
386{
387 return mTitle;
388}
389
390Qt::AlignmentFlag QgsLayoutItemLegend::titleAlignment() const
391{
392 return mSettings.titleAlignment();
393}
394
395void QgsLayoutItemLegend::setTitleAlignment( Qt::AlignmentFlag alignment )
396{
397 mSettings.setTitleAlignment( alignment );
398}
399
401{
402 return mSettings.rstyle( s );
403}
404
406{
407 return mSettings.style( s );
408}
409
411{
412 mSettings.setStyle( s, style );
413}
414
416{
418 return mSettings.style( s ).font();
420}
421
423{
425 rstyle( s ).setFont( f );
427}
428
430{
431 rstyle( s ).setMargin( margin );
432}
433
435{
436 rstyle( s ).setMargin( side, margin );
437}
438
440{
442 return mSettings.lineSpacing();
444}
445
447{
449 mSettings.setLineSpacing( spacing );
451}
452
454{
455 return mSettings.boxSpace();
456}
457
459{
460 mSettings.setBoxSpace( s );
461}
462
464{
465 return mSettings.columnSpace();
466}
467
469{
470 mSettings.setColumnSpace( s );
471}
472
474{
476 return mSettings.fontColor();
478}
479
481{
483 mSettings.setFontColor( c );
485}
486
488{
489 return mSettings.symbolSize().width();
490}
491
493{
494 mSettings.setSymbolSize( QSizeF( w, mSettings.symbolSize().height() ) );
495}
496
498{
499 return mSettings.maximumSymbolSize();
500}
501
503{
504 mSettings.setMaximumSymbolSize( size );
505}
506
508{
509 return mSettings.minimumSymbolSize();
510}
511
513{
514 mSettings.setMinimumSymbolSize( size );
515}
516
517void QgsLayoutItemLegend::setSymbolAlignment( Qt::AlignmentFlag alignment )
518{
519 mSettings.setSymbolAlignment( alignment );
520}
521
523{
524 return mSettings.symbolAlignment();
525}
526
528{
529 return mSettings.symbolSize().height();
530}
531
533{
534 mSettings.setSymbolSize( QSizeF( mSettings.symbolSize().width(), h ) );
535}
536
538{
539 return mSettings.wmsLegendSize().width();
540}
541
543{
544 mSettings.setWmsLegendSize( QSizeF( w, mSettings.wmsLegendSize().height() ) );
545}
546
548{
549 return mSettings.wmsLegendSize().height();
550}
552{
553 mSettings.setWmsLegendSize( QSizeF( mSettings.wmsLegendSize().width(), h ) );
554}
555
557{
558 mSettings.setWrapChar( t );
559}
560
562{
563 return mSettings.wrapChar();
564}
565
567{
568 return mColumnCount;
569}
570
572{
573 mColumnCount = c;
574 mSettings.setColumnCount( c );
575}
576
578{
579 return mSettings.splitLayer();
580}
581
583{
584 mSettings.setSplitLayer( s );
585}
586
588{
589 return mSettings.equalColumnWidth();
590}
591
593{
594 mSettings.setEqualColumnWidth( s );
595}
596
598{
599 return mSettings.drawRasterStroke();
600}
601
603{
604 mSettings.setDrawRasterStroke( enabled );
605}
606
608{
609 return mSettings.rasterStrokeColor();
610}
611
613{
614 mSettings.setRasterStrokeColor( color );
615}
616
618{
619 return mSettings.rasterStrokeWidth();
620}
621
623{
624 mSettings.setRasterStrokeWidth( width );
625}
626
628{
630 updateFilterByMap( false );
631}
632
633bool QgsLayoutItemLegend::writePropertiesToElement( QDomElement &legendElem, QDomDocument &doc, const QgsReadWriteContext &context ) const
634{
635
636 //write general properties
637 legendElem.setAttribute( QStringLiteral( "title" ), mTitle );
638 legendElem.setAttribute( QStringLiteral( "titleAlignment" ), QString::number( static_cast< int >( mSettings.titleAlignment() ) ) );
639 legendElem.setAttribute( QStringLiteral( "columnCount" ), QString::number( mColumnCount ) );
640 legendElem.setAttribute( QStringLiteral( "splitLayer" ), QString::number( mSettings.splitLayer() ) );
641 legendElem.setAttribute( QStringLiteral( "equalColumnWidth" ), QString::number( mSettings.equalColumnWidth() ) );
642
643 legendElem.setAttribute( QStringLiteral( "boxSpace" ), QString::number( mSettings.boxSpace() ) );
644 legendElem.setAttribute( QStringLiteral( "columnSpace" ), QString::number( mSettings.columnSpace() ) );
645
646 legendElem.setAttribute( QStringLiteral( "symbolWidth" ), QString::number( mSettings.symbolSize().width() ) );
647 legendElem.setAttribute( QStringLiteral( "symbolHeight" ), QString::number( mSettings.symbolSize().height() ) );
648 legendElem.setAttribute( QStringLiteral( "maxSymbolSize" ), QString::number( mSettings.maximumSymbolSize() ) );
649 legendElem.setAttribute( QStringLiteral( "minSymbolSize" ), QString::number( mSettings.minimumSymbolSize() ) );
650
651 legendElem.setAttribute( QStringLiteral( "symbolAlignment" ), mSettings.symbolAlignment() );
652
653 legendElem.setAttribute( QStringLiteral( "symbolAlignment" ), mSettings.symbolAlignment() );
654
655 legendElem.setAttribute( QStringLiteral( "rasterBorder" ), mSettings.drawRasterStroke() );
656 legendElem.setAttribute( QStringLiteral( "rasterBorderColor" ), QgsColorUtils::colorToString( mSettings.rasterStrokeColor() ) );
657 legendElem.setAttribute( QStringLiteral( "rasterBorderWidth" ), QString::number( mSettings.rasterStrokeWidth() ) );
658
659 legendElem.setAttribute( QStringLiteral( "wmsLegendWidth" ), QString::number( mSettings.wmsLegendSize().width() ) );
660 legendElem.setAttribute( QStringLiteral( "wmsLegendHeight" ), QString::number( mSettings.wmsLegendSize().height() ) );
661 legendElem.setAttribute( QStringLiteral( "wrapChar" ), mSettings.wrapChar() );
662
663 legendElem.setAttribute( QStringLiteral( "resizeToContents" ), mSizeToContents );
664
665 if ( mMap )
666 {
667 legendElem.setAttribute( QStringLiteral( "map_uuid" ), mMap->uuid() );
668 }
669
670 if ( !mFilterByMapItems.empty() )
671 {
672 QDomElement filterByMapsElem = doc.createElement( QStringLiteral( "filterByMaps" ) );
673 for ( QgsLayoutItemMap *map : mFilterByMapItems )
674 {
675 if ( map )
676 {
677 QDomElement mapElem = doc.createElement( QStringLiteral( "map" ) );
678 mapElem.setAttribute( QStringLiteral( "uuid" ), map->uuid() );
679 filterByMapsElem.appendChild( mapElem );
680 }
681 }
682 legendElem.appendChild( filterByMapsElem );
683 }
684
685 QDomElement legendStyles = doc.createElement( QStringLiteral( "styles" ) );
686 legendElem.appendChild( legendStyles );
687
688 style( QgsLegendStyle::Title ).writeXml( QStringLiteral( "title" ), legendStyles, doc, context );
689 style( QgsLegendStyle::Group ).writeXml( QStringLiteral( "group" ), legendStyles, doc, context );
690 style( QgsLegendStyle::Subgroup ).writeXml( QStringLiteral( "subgroup" ), legendStyles, doc, context );
691 style( QgsLegendStyle::Symbol ).writeXml( QStringLiteral( "symbol" ), legendStyles, doc, context );
692 style( QgsLegendStyle::SymbolLabel ).writeXml( QStringLiteral( "symbolLabel" ), legendStyles, doc, context );
693
694 if ( mCustomLayerTree )
695 {
696 // if not using auto-update - store the custom layer tree
697 mCustomLayerTree->writeXml( legendElem, context );
698 }
699
700 if ( mLegendFilterByMap )
701 {
702 legendElem.setAttribute( QStringLiteral( "legendFilterByMap" ), QStringLiteral( "1" ) );
703 }
704 legendElem.setAttribute( QStringLiteral( "legendFilterByAtlas" ), mFilterOutAtlas ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
705
706 return true;
707}
708
709bool QgsLayoutItemLegend::readPropertiesFromElement( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context )
710{
711 //read general properties
712 mTitle = itemElem.attribute( QStringLiteral( "title" ) );
713 mSettings.setTitle( mTitle );
714 if ( !itemElem.attribute( QStringLiteral( "titleAlignment" ) ).isEmpty() )
715 {
716 mSettings.setTitleAlignment( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral( "titleAlignment" ) ).toInt() ) );
717 }
718 int colCount = itemElem.attribute( QStringLiteral( "columnCount" ), QStringLiteral( "1" ) ).toInt();
719 if ( colCount < 1 ) colCount = 1;
720 mColumnCount = colCount;
721 mSettings.setColumnCount( mColumnCount );
722 mSettings.setSplitLayer( itemElem.attribute( QStringLiteral( "splitLayer" ), QStringLiteral( "0" ) ).toInt() == 1 );
723 mSettings.setEqualColumnWidth( itemElem.attribute( QStringLiteral( "equalColumnWidth" ), QStringLiteral( "0" ) ).toInt() == 1 );
724
725 const QDomNodeList stylesNodeList = itemElem.elementsByTagName( QStringLiteral( "styles" ) );
726 if ( !stylesNodeList.isEmpty() )
727 {
728 const QDomNode stylesNode = stylesNodeList.at( 0 );
729 for ( int i = 0; i < stylesNode.childNodes().size(); i++ )
730 {
731 const QDomElement styleElem = stylesNode.childNodes().at( i ).toElement();
733 style.readXml( styleElem, doc, context );
734 const QString name = styleElem.attribute( QStringLiteral( "name" ) );
736 if ( name == QLatin1String( "title" ) ) s = QgsLegendStyle::Title;
737 else if ( name == QLatin1String( "group" ) ) s = QgsLegendStyle::Group;
738 else if ( name == QLatin1String( "subgroup" ) ) s = QgsLegendStyle::Subgroup;
739 else if ( name == QLatin1String( "symbol" ) ) s = QgsLegendStyle::Symbol;
740 else if ( name == QLatin1String( "symbolLabel" ) ) s = QgsLegendStyle::SymbolLabel;
741 else continue;
742 setStyle( s, style );
743 }
744 }
745
746 //font color
747 if ( itemElem.hasAttribute( QStringLiteral( "fontColor" ) ) )
748 {
749 QColor fontClr;
750 fontClr.setNamedColor( itemElem.attribute( QStringLiteral( "fontColor" ), QStringLiteral( "#000000" ) ) );
755 }
756
757 //spaces
758 mSettings.setBoxSpace( itemElem.attribute( QStringLiteral( "boxSpace" ), QStringLiteral( "2.0" ) ).toDouble() );
759 mSettings.setColumnSpace( itemElem.attribute( QStringLiteral( "columnSpace" ), QStringLiteral( "2.0" ) ).toDouble() );
760
761 mSettings.setSymbolSize( QSizeF( itemElem.attribute( QStringLiteral( "symbolWidth" ), QStringLiteral( "7.0" ) ).toDouble(), itemElem.attribute( QStringLiteral( "symbolHeight" ), QStringLiteral( "14.0" ) ).toDouble() ) );
762 mSettings.setSymbolAlignment( static_cast< Qt::AlignmentFlag >( itemElem.attribute( QStringLiteral( "symbolAlignment" ), QString::number( Qt::AlignLeft ) ).toInt() ) );
763
764 mSettings.setMaximumSymbolSize( itemElem.attribute( QStringLiteral( "maxSymbolSize" ), QStringLiteral( "0.0" ) ).toDouble() );
765 mSettings.setMinimumSymbolSize( itemElem.attribute( QStringLiteral( "minSymbolSize" ), QStringLiteral( "0.0" ) ).toDouble() );
766
767 mSettings.setWmsLegendSize( QSizeF( itemElem.attribute( QStringLiteral( "wmsLegendWidth" ), QStringLiteral( "50" ) ).toDouble(), itemElem.attribute( QStringLiteral( "wmsLegendHeight" ), QStringLiteral( "25" ) ).toDouble() ) );
768
769 if ( itemElem.hasAttribute( QStringLiteral( "lineSpacing" ) ) )
770 {
771 const double spacing = itemElem.attribute( QStringLiteral( "lineSpacing" ), QStringLiteral( "1.0" ) ).toDouble();
772 // line spacing *was* a fixed amount (in mm) added between each line of text.
774 // assume font sizes in points, since that was what we always had from before this method was deprecated
775 f.setLineHeight( f.size() * 0.352778 + spacing );
778
780 f.setLineHeight( f.size() * 0.352778 + spacing );
783
785 f.setLineHeight( f.size() * 0.352778 + spacing );
788
790 f.setLineHeight( f.size() * 0.352778 + spacing );
793 }
794
795 mSettings.setDrawRasterStroke( itemElem.attribute( QStringLiteral( "rasterBorder" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) );
796 mSettings.setRasterStrokeColor( QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "rasterBorderColor" ), QStringLiteral( "0,0,0" ) ) ) );
797 mSettings.setRasterStrokeWidth( itemElem.attribute( QStringLiteral( "rasterBorderWidth" ), QStringLiteral( "0" ) ).toDouble() );
798
799 mSettings.setWrapChar( itemElem.attribute( QStringLiteral( "wrapChar" ) ) );
800
801 mSizeToContents = itemElem.attribute( QStringLiteral( "resizeToContents" ), QStringLiteral( "1" ) ) != QLatin1String( "0" );
802
803 // map
804 mLegendFilterByMap = itemElem.attribute( QStringLiteral( "legendFilterByMap" ), QStringLiteral( "0" ) ).toInt();
805
806 mMapUuid.clear();
807 if ( !itemElem.attribute( QStringLiteral( "map_uuid" ) ).isEmpty() )
808 {
809 mMapUuid = itemElem.attribute( QStringLiteral( "map_uuid" ) );
810 }
811
812 mFilterByMapUuids.clear();
813 {
814 const QDomElement filterByMapsElem = itemElem.firstChildElement( QStringLiteral( "filterByMaps" ) );
815 if ( !filterByMapsElem.isNull() )
816 {
817 QDomElement mapsElem = filterByMapsElem.firstChildElement( QStringLiteral( "map" ) );
818 while ( !mapsElem.isNull() )
819 {
820 mFilterByMapUuids << mapsElem.attribute( QStringLiteral( "uuid" ) );
821 mapsElem = mapsElem.nextSiblingElement( QStringLiteral( "map" ) );
822 }
823 }
824 else if ( !mMapUuid.isEmpty() )
825 {
826 // for compatibility with < QGIS 3.32 projects
827 mFilterByMapUuids << mMapUuid;
828 }
829 }
830
831 // disconnect current map
832 setupMapConnections( mMap, false );
833 mMap = nullptr;
834
835 mFilterOutAtlas = itemElem.attribute( QStringLiteral( "legendFilterByAtlas" ), QStringLiteral( "0" ) ).toInt();
836
837 // QGIS >= 2.6
838 QDomElement layerTreeElem = itemElem.firstChildElement( QStringLiteral( "layer-tree" ) );
839 if ( layerTreeElem.isNull() )
840 layerTreeElem = itemElem.firstChildElement( QStringLiteral( "layer-tree-group" ) );
841
842 if ( !layerTreeElem.isNull() )
843 {
844 std::unique_ptr< QgsLayerTree > tree( QgsLayerTree::readXml( layerTreeElem, context ) );
845 if ( mLayout )
846 tree->resolveReferences( mLayout->project(), true );
847 setCustomLayerTree( tree.release() );
848 }
849 else
850 setCustomLayerTree( nullptr );
851
852 return true;
853}
854
856{
857 if ( !id().isEmpty() )
858 {
859 return id();
860 }
861
862 //if no id, default to portion of title text
863 QString text = mSettings.title();
864 if ( text.isEmpty() )
865 {
866 return tr( "<Legend>" );
867 }
868 if ( text.length() > 25 )
869 {
870 return tr( "%1…" ).arg( text.left( 25 ) );
871 }
872 else
873 {
874 return text;
875 }
876}
877
879{
880 return blendMode() != QPainter::CompositionMode_SourceOver;
881}
882
884{
885 return mEvaluatedOpacity < 1.0;
886}
887
888void QgsLayoutItemLegend::setupMapConnections( QgsLayoutItemMap *map, bool connectSlots )
889{
890 if ( !map )
891 return;
892
893 if ( !connectSlots )
894 {
895 disconnect( map, &QObject::destroyed, this, &QgsLayoutItemLegend::invalidateCurrentMap );
896 disconnect( map, &QgsLayoutObject::changed, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
897 disconnect( map, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
898 disconnect( map, &QgsLayoutItemMap::mapRotationChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
899 disconnect( map, &QgsLayoutItemMap::layerStyleOverridesChanged, this, &QgsLayoutItemLegend::mapLayerStyleOverridesChanged );
900 disconnect( map, &QgsLayoutItemMap::themeChanged, this, &QgsLayoutItemLegend::mapThemeChanged );
901 }
902 else
903 {
904 connect( map, &QObject::destroyed, this, &QgsLayoutItemLegend::invalidateCurrentMap );
905 connect( map, &QgsLayoutObject::changed, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
906 connect( map, &QgsLayoutItemMap::extentChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
907 connect( map, &QgsLayoutItemMap::mapRotationChanged, this, &QgsLayoutItemLegend::updateFilterByMapAndRedraw );
908 connect( map, &QgsLayoutItemMap::layerStyleOverridesChanged, this, &QgsLayoutItemLegend::mapLayerStyleOverridesChanged );
909 connect( map, &QgsLayoutItemMap::themeChanged, this, &QgsLayoutItemLegend::mapThemeChanged );
910 }
911}
912
914{
915 if ( mMap == map )
916 return;
917
918 if ( mMap )
919 {
920 setupMapConnections( mMap, false );
921 }
922
923 mMap = map;
924
925 if ( mMap )
926 {
927 setupMapConnections( mMap, true );
928 mapThemeChanged( mMap->themeToRender( mMap->createExpressionContext() ) );
929 }
930
932}
933
934void QgsLayoutItemLegend::setFilterByMapItems( const QList<QgsLayoutItemMap *> &maps )
935{
936 if ( filterByMapItems() == maps )
937 return;
938
939 for ( QgsLayoutItemMap *map : std::as_const( mFilterByMapItems ) )
940 {
941 setupMapConnections( map, false );
942 }
943
944 mFilterByMapItems.clear();
945 mFilterByMapItems.reserve( maps.size() );
946 for ( QgsLayoutItemMap *map : maps )
947 {
948 if ( map )
949 {
950 mFilterByMapItems.append( map );
951 setupMapConnections( map, true );
952 }
953 }
954
956}
957
958QList<QgsLayoutItemMap *> QgsLayoutItemLegend::filterByMapItems() const
959{
960 QList<QgsLayoutItemMap *> res;
961 res.reserve( mFilterByMapItems.size() );
962 for ( QgsLayoutItemMap *map : mFilterByMapItems )
963 {
964 if ( map )
965 res.append( map );
966 }
967 return res;
968}
969
970void QgsLayoutItemLegend::invalidateCurrentMap()
971{
972 setLinkedMap( nullptr );
973}
974
976{
978
979 bool forceUpdate = false;
980 //updates data defined properties and redraws item to match
982 {
983 bool ok = false;
985 if ( ok )
986 {
987 mSettings.setTitle( t );
988 forceUpdate = true;
989 }
990 }
992 {
993 bool ok = false;
995 if ( ok && cols >= 0 )
996 {
997 mSettings.setColumnCount( cols );
998 forceUpdate = true;
999 }
1000 }
1001 if ( forceUpdate )
1002 {
1003 adjustBoxSize();
1004 update();
1005 }
1006
1008}
1009
1010
1011void QgsLayoutItemLegend::updateFilterByMapAndRedraw()
1012{
1013 updateFilterByMap( true );
1014}
1015
1016void QgsLayoutItemLegend::setModelStyleOverrides( const QMap<QString, QString> &overrides )
1017{
1018 mLegendModel->setLayerStyleOverrides( overrides );
1019 const QList< QgsLayerTreeLayer * > layers = mLegendModel->rootGroup()->findLayers();
1020 for ( QgsLayerTreeLayer *nodeLayer : layers )
1021 mLegendModel->refreshLayerLegend( nodeLayer );
1022
1023}
1024
1025void QgsLayoutItemLegend::clearLegendCachedData()
1026{
1027 std::function< void( QgsLayerTreeNode * ) > clearNodeCache;
1028 clearNodeCache = [&]( QgsLayerTreeNode * node )
1029 {
1030 mLegendModel->clearCachedData( node );
1031 if ( QgsLayerTree::isGroup( node ) )
1032 {
1034 const QList< QgsLayerTreeNode * > children = group->children();
1035 for ( QgsLayerTreeNode *child : children )
1036 {
1037 clearNodeCache( child );
1038 }
1039 }
1040 };
1041
1042 if ( QgsLayerTree *rootGroup = mLegendModel->rootGroup() )
1043 {
1044 clearNodeCache( rootGroup );
1045 }
1046}
1047
1048void QgsLayoutItemLegend::mapLayerStyleOverridesChanged()
1049{
1050 if ( !mMap )
1051 return;
1052
1053 // map's style has been changed, so make sure to update the legend here
1054 if ( mLegendFilterByMap )
1055 {
1056 // legend is being filtered by map, so we need to re run the hit test too
1057 // as the style overrides may also have affected the visible symbols
1058 updateFilterByMap( false );
1059 }
1060 else
1061 {
1062 setModelStyleOverrides( mMap->layerStyleOverrides() );
1063 }
1064
1065 adjustBoxSize();
1066
1067 updateFilterByMap( false );
1068}
1069
1070void QgsLayoutItemLegend::mapThemeChanged( const QString &theme )
1071{
1072 if ( mThemeName == theme )
1073 return;
1074
1075 mThemeName = theme;
1076
1077 // map's theme has been changed, so make sure to update the legend here
1078
1079 // legend is being filtered by map, so we need to re run the hit test too
1080 // as the style overrides may also have affected the visible symbols
1081 updateFilterByMap( false );
1082
1083 adjustBoxSize();
1084
1086}
1087
1089{
1090 // ask for update
1091 // the actual update will take place before the redraw.
1092 // This is to avoid multiple calls to the filter
1093 mFilterAskedForUpdate = true;
1094
1095 if ( redraw )
1096 update();
1097}
1098
1099void QgsLayoutItemLegend::doUpdateFilterByMap()
1100{
1101 // There's an incompatibility here between legend handling of linked map themes and layer style overrides vs
1102 // how expression evaluation is made in legend content text. The logic below is hacked together to get
1103 // all the existing unit tests passing, but these two features are incompatible with each other and fixing
1104 // this is extremely non-trivial. Let's just hope no-one tries to use those features together!
1105 // Ideally, all the branches below would be consistently using either "setModelStyleOverrides" (which forces
1106 // a rebuild of each layer's legend, and breaks legend text expression evaluation) OR
1107 // "mLegendModel->setLayerStyleOverrides" which just handles the expression updates but which doesn't correctly
1108 // generate the legend content from the associated theme settings.
1109 if ( mMap && !mThemeName.isEmpty() )
1110 {
1111 // get style overrides for theme
1112 const QMap<QString, QString> overrides = mLayout->project()->mapThemeCollection()->mapThemeStyleOverrides( mThemeName );
1113 setModelStyleOverrides( overrides );
1114 }
1115 else if ( mMap )
1116 {
1117 mLegendModel->setLayerStyleOverrides( mMap->layerStyleOverrides() );
1118 }
1119 else
1120 {
1121 mLegendModel->setLayerStyleOverrides( QMap<QString, QString>() );
1122 }
1123
1124 const bool filterByExpression = QgsLayerTreeUtils::hasLegendFilterExpression( *( mCustomLayerTree ? mCustomLayerTree.get() : mLayout->project()->layerTreeRoot() ) );
1125
1126 const bool hasValidFilter = filterByExpression
1127 || ( mLegendFilterByMap && ( mMap || !mFilterByMapItems.empty() ) )
1128 || mInAtlas;
1129
1130 if ( hasValidFilter )
1131 {
1132 const double dpi = mLayout->renderContext().dpi();
1133
1134 QSet< QgsLayoutItemMap * > linkedFilterMaps;
1135 if ( mLegendFilterByMap )
1136 {
1137 linkedFilterMaps = qgis::listToSet( filterByMapItems() );
1138 if ( mMap )
1139 linkedFilterMaps.insert( mMap );
1140 }
1141
1142 QgsMapSettings mapSettings;
1143 QgsGeometry filterGeometry;
1144 if ( mMap )
1145 {
1146 // if a specific linked map has been set, use it for the reference scale and extent
1147 const QgsRectangle requestRectangle = mMap->requestedExtent();
1148 QSizeF size( requestRectangle.width(), requestRectangle.height() );
1149 size *= mLayout->convertFromLayoutUnits( mMap->mapUnitsToLayoutUnits(), Qgis::LayoutUnit::Millimeters ).length() * dpi / 25.4;
1150 mapSettings = mMap->mapSettings( requestRectangle, size, dpi, true );
1151
1152 filterGeometry = QgsGeometry::fromQPolygonF( mMap->visibleExtentPolygon() );
1153 }
1154 else if ( !linkedFilterMaps.empty() )
1155 {
1156 // otherwise just take the first linked filter map
1157 const QgsRectangle requestRectangle = ( *linkedFilterMaps.constBegin() )->requestedExtent();
1158 QSizeF size( requestRectangle.width(), requestRectangle.height() );
1159 size *= mLayout->convertFromLayoutUnits( ( *linkedFilterMaps.constBegin() )->mapUnitsToLayoutUnits(), Qgis::LayoutUnit::Millimeters ).length() * dpi / 25.4;
1160 mapSettings = ( *linkedFilterMaps.constBegin() )->mapSettings( requestRectangle, size, dpi, true );
1161
1162 filterGeometry = QgsGeometry::fromQPolygonF( ( *linkedFilterMaps.constBegin() )->visibleExtentPolygon() );
1163 }
1164
1166
1167 const QgsGeometry atlasGeometry { mLayout->reportContext().currentGeometry( mapSettings.destinationCrs() ) };
1168
1169 QgsLayerTreeFilterSettings filterSettings( mapSettings );
1170
1171 QList<QgsMapLayer *> layersToClip;
1172 if ( !atlasGeometry.isNull() && mMap->atlasClippingSettings()->enabled() )
1173 {
1174 layersToClip = mMap->atlasClippingSettings()->layersToClip();
1175 for ( QgsMapLayer *layer : std::as_const( layersToClip ) )
1176 {
1177 QList<QgsMapLayer *> mapLayers { filterSettings.mapSettings().layers( true ) };
1178 mapLayers.removeAll( layer );
1179 filterSettings.mapSettings().setLayers( mapLayers );
1180 filterSettings.addVisibleExtentForLayer( layer, QgsReferencedGeometry( atlasGeometry, mapSettings.destinationCrs() ) );
1181 }
1182 }
1183
1184
1185 if ( !linkedFilterMaps.empty() )
1186 {
1187 for ( QgsLayoutItemMap *map : std::as_const( linkedFilterMaps ) )
1188 {
1189
1190 if ( map == mMap )
1191 continue;
1192
1194
1195 //transform back to destination CRS
1196 const QgsCoordinateTransform mapTransform( map->crs(), mapSettings.destinationCrs(), mLayout->project() );
1197 try
1198 {
1199 mapExtent.transform( mapTransform );
1200 }
1201 catch ( QgsCsException &cse )
1202 {
1203 continue;
1204 }
1205
1206 const QList< QgsMapLayer * > layersForMap = map->layersToRender();
1207 for ( QgsMapLayer *layer : layersForMap )
1208 {
1209 if ( mInAtlas && !atlasGeometry.isNull() )
1210 {
1211 mapExtent = mapExtent.intersection( atlasGeometry );
1212 }
1213
1214 filterSettings.addVisibleExtentForLayer( layer, QgsReferencedGeometry( mapExtent, mapSettings.destinationCrs() ) );
1215 }
1216 }
1217 }
1218
1219 if ( mInAtlas )
1220 {
1221 if ( !filterGeometry.isEmpty() )
1222 filterGeometry = mLayout->reportContext().currentGeometry( mapSettings.destinationCrs() );
1223 else
1224 filterGeometry = filterGeometry.intersection( mLayout->reportContext().currentGeometry( mapSettings.destinationCrs() ) );
1225 }
1226
1227 filterSettings.setLayerFilterExpressionsFromLayerTree( mLegendModel->rootGroup() );
1228 if ( !filterGeometry.isNull() )
1229 {
1230 filterSettings.setFilterPolygon( filterGeometry );
1231 }
1232 else
1233 {
1234 filterSettings.setFlags( Qgis::LayerTreeFilterFlag::SkipVisibilityCheck );
1235 }
1236
1237 mLegendModel->setFilterSettings( &filterSettings );
1238 }
1239 else
1240 {
1241 mLegendModel->setFilterSettings( nullptr );
1242 }
1243
1244 clearLegendCachedData();
1245 mForceResize = true;
1246}
1247
1249{
1250 return mThemeName;
1251}
1252
1254{
1255 mFilterOutAtlas = doFilter;
1256}
1257
1259{
1260 return mFilterOutAtlas;
1261}
1262
1263void QgsLayoutItemLegend::onAtlasFeature()
1264{
1265 if ( !mLayout || !mLayout->reportContext().feature().isValid() )
1266 return;
1267 mInAtlas = mFilterOutAtlas;
1269}
1270
1271void QgsLayoutItemLegend::onAtlasEnded()
1272{
1273 mInAtlas = false;
1275}
1276
1278{
1280
1281 // We only want the last scope from the map's expression context, as this contains
1282 // the map specific variables. We don't want the rest of the map's context, because that
1283 // will contain duplicate global, project, layout, etc scopes.
1284 if ( mMap )
1285 context.appendScope( mMap->createExpressionContext().popScope() );
1286
1287 QgsExpressionContextScope *scope = new QgsExpressionContextScope( tr( "Legend Settings" ) );
1288
1289 scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_title" ), title(), true ) );
1290 scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_column_count" ), columnCount(), true ) );
1291 scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_split_layers" ), splitLayer(), true ) );
1292 scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_wrap_string" ), wrapString(), true ) );
1293 scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_filter_by_map" ), legendFilterByMapEnabled(), true ) );
1294 scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "legend_filter_out_atlas" ), legendFilterOutAtlas(), true ) );
1295
1296 context.appendScope( scope );
1297 return context;
1298}
1299
1301{
1302 return MustPlaceInOwnLayer;
1303}
1304
1306{
1307 std::function<bool( QgsLayerTreeGroup *group ) >visit;
1308
1309 visit = [this, visitor, &visit]( QgsLayerTreeGroup * group ) -> bool
1310 {
1311 const QList<QgsLayerTreeNode *> childNodes = group->children();
1312 for ( QgsLayerTreeNode *node : childNodes )
1313 {
1314 if ( QgsLayerTree::isGroup( node ) )
1315 {
1316 QgsLayerTreeGroup *nodeGroup = QgsLayerTree::toGroup( node );
1317 if ( !visit( nodeGroup ) )
1318 return false;
1319 }
1320 else if ( QgsLayerTree::isLayer( node ) )
1321 {
1322 QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
1323 if ( !nodeLayer->patchShape().isNull() )
1324 {
1325 QgsStyleLegendPatchShapeEntity entity( nodeLayer->patchShape() );
1326 if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, uuid(), displayName() ) ) )
1327 return false;
1328 }
1329 const QList<QgsLayerTreeModelLegendNode *> legendNodes = mLegendModel->layerLegendNodes( nodeLayer );
1330 for ( QgsLayerTreeModelLegendNode *legendNode : legendNodes )
1331 {
1332 if ( QgsSymbolLegendNode *symbolNode = dynamic_cast< QgsSymbolLegendNode * >( legendNode ) )
1333 {
1334 if ( !symbolNode->patchShape().isNull() )
1335 {
1336 QgsStyleLegendPatchShapeEntity entity( symbolNode->patchShape() );
1337 if ( !visitor->visit( QgsStyleEntityVisitorInterface::StyleLeaf( &entity, uuid(), displayName() ) ) )
1338 return false;
1339 }
1340 }
1341 }
1342 }
1343 }
1344 return true;
1345 };
1346 return visit( mLegendModel->rootGroup( ) );
1347}
1348
1350{
1351 return mLegendModel->hitTestInProgress();
1352}
1353
1354
1355// -------------------------------------------------------------------------
1356
1358 : QgsLayerTreeModel( rootNode, parent )
1359 , mLayoutLegend( layout )
1360{
1364 connect( this, &QgsLegendModel::dataChanged, this, &QgsLegendModel::refreshLegend );
1365}
1366
1368 : QgsLayerTreeModel( rootNode )
1369 , mLayoutLegend( layout )
1370{
1374 connect( this, &QgsLegendModel::dataChanged, this, &QgsLegendModel::refreshLegend );
1375}
1376
1377QVariant QgsLegendModel::data( const QModelIndex &index, int role ) const
1378{
1379 // handle custom layer node labels
1380
1382 QgsLayerTreeLayer *nodeLayer = QgsLayerTree::isLayer( node ) ? QgsLayerTree::toLayer( node ) : nullptr;
1383 if ( nodeLayer && ( role == Qt::DisplayRole || role == Qt::EditRole ) )
1384 {
1385 QString name = node->customProperty( QStringLiteral( "cached_name" ) ).toString();
1386 if ( !name.isEmpty() )
1387 return name;
1388
1389 QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
1390
1391 //finding the first label that is stored
1392 name = nodeLayer->customProperty( QStringLiteral( "legend/title-label" ) ).toString();
1393 if ( name.isEmpty() )
1394 name = nodeLayer->name();
1395 if ( name.isEmpty() )
1396 name = node->customProperty( QStringLiteral( "legend/title-label" ) ).toString();
1397 if ( name.isEmpty() )
1398 name = node->name();
1399 if ( nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() )
1400 {
1401 if ( vlayer && vlayer->featureCount() >= 0 )
1402 {
1403 name += QStringLiteral( " [%1]" ).arg( vlayer->featureCount() );
1404 node->setCustomProperty( QStringLiteral( "cached_name" ), name );
1405 return name;
1406 }
1407 }
1408 node->setCustomProperty( QStringLiteral( "cached_name" ), name );
1409 return name;
1410 }
1411 return QgsLayerTreeModel::data( index, role );
1412}
1413
1414Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
1415{
1416 // make the legend nodes selectable even if they are not by default
1417 if ( index2legendNode( index ) )
1418 return QgsLayerTreeModel::flags( index ) | Qt::ItemIsSelectable;
1419
1421}
1422
1423QList<QgsLayerTreeModelLegendNode *> QgsLegendModel::layerLegendNodes( QgsLayerTreeLayer *nodeLayer, bool skipNodeEmbeddedInParent ) const
1424{
1425 if ( !mLegend.contains( nodeLayer ) )
1426 return QList<QgsLayerTreeModelLegendNode *>();
1427
1428 const LayerLegendData &data = mLegend[nodeLayer];
1429 QList<QgsLayerTreeModelLegendNode *> lst( data.activeNodes );
1430 if ( !skipNodeEmbeddedInParent && data.embeddedNodeInParent )
1431 lst.prepend( data.embeddedNodeInParent );
1432 return lst;
1433}
1434
1436{
1437 node->removeCustomProperty( QStringLiteral( "cached_name" ) );
1438}
1439
1440void QgsLegendModel::forceRefresh()
1441{
1442 emit refreshLegend();
1443}
@ Millimeters
Millimeters.
@ SkipVisibilityCheck
If set, the standard visibility check should be skipped.
@ Millimeters
Millimeters.
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.
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.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
Class for doing transforms between two map coordinate systems.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:67
Single scope for storing variables and functions for use within a QgsExpressionContext.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
QgsExpressionContextScope * popScope()
Removes the last scope from the expression context and return it.
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:162
static QgsGeometry fromQPolygonF(const QPolygonF &polygon)
Construct geometry from a QPolygonF.
Qgis::GeometryOperationResult transform(const QgsCoordinateTransform &ct, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward, bool transformZ=false)
Transforms this geometry as described by the coordinate transform ct.
Q_GADGET bool isNull
Definition: qgsgeometry.h:164
QgsGeometry intersection(const QgsGeometry &geometry, const QgsGeometryParameters &parameters=QgsGeometryParameters()) const
Returns a geometry representing the points shared by this geometry and other.
bool isEmpty() const
Returns true if the geometry is empty (eg a linestring with no vertices, or a collection with no geom...
Contains settings relating to filtering the contents of QgsLayerTreeModel and views.
Layer tree group node serves as a container for layers and further groups.
Layer tree node points to a map layer.
QgsLegendPatchShape patchShape() const
Returns the symbol patch shape to use when rendering the legend node symbol.
QString name() const override
Returns the layer's name.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
The QgsLegendRendererItem class is abstract interface for legend items returned from QgsMapLayerLegen...
The QgsLayerTreeModel class is model implementation for Qt item views framework.
Flags flags() const
Returns OR-ed combination of model flags.
void hitTestStarted()
Emitted when a hit test for visible legend items starts.
void hitTestCompleted()
Emitted when a hit test for visible legend items completes.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void setFlag(Flag f, bool on=true)
Enable or disable a model flag.
QHash< QgsLayerTreeLayer *, LayerLegendData > mLegend
Per layer data about layer's legend nodes.
QgsLayerTreeNode * index2node(const QModelIndex &index) const
Returns layer tree node for given index.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
static QgsLayerTreeModelLegendNode * index2legendNode(const QModelIndex &index)
Returns legend node for given index.
@ AllowNodeReorder
Allow reordering with drag'n'drop.
@ AllowLegendChangeState
Allow check boxes for legend nodes (if supported by layer's legend)
@ UseThreadedHitTest
Run legend hit tests in a background thread (since QGIS 3.30)
This class is a base class for nodes in a layer tree.
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.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file.
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.
virtual QString name() const =0
Returns name of the node.
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
static bool hasLegendFilterExpression(const QgsLayerTreeGroup &group)
Test if one of the layers in a group has an expression filter.
Namespace with helper functions for layer tree operations.
Definition: qgslayertree.h:32
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
Definition: qgslayertree.h:70
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
Definition: qgslayertree.h:50
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
Definition: qgslayertree.h:41
static QgsLayerTree * readXml(QDomElement &element, const QgsReadWriteContext &context)
Load the layer tree from an XML element.
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
Definition: qgslayertree.h:60
A layout item subclass for map legends.
bool autoUpdateModel() const
Returns whether the legend content should auto update to reflect changes in the project's layer tree.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void setStyleMargin(QgsLegendStyle::Style component, double margin)
Set the margin for a legend component.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
QString title() const
Returns the legend title.
void setSplitLayer(bool enabled)
Sets whether the legend items from a single layer can be split over multiple columns.
QgsLegendModel * model()
Returns the legend model.
void adjustBoxSize()
Sets the legend's item bounds to fit the whole legend content.
double wmsLegendWidth() const
Returns the WMS legend width.
void setColumnSpace(double spacing)
Sets the legend column spacing.
void setBoxSpace(double space)
Sets the legend box space.
bool splitLayer() const
Returns whether the legend items from a single layer can be split over multiple columns.
double symbolHeight() const
Returns the legend symbol height.
void updateFilterByMap(bool redraw=true)
Updates the legend content when filtered by map.
void setEqualColumnWidth(bool equalize)
Sets whether column widths should be equalized.
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties) override
Q_DECL_DEPRECATED QFont styleFont(QgsLegendStyle::Style component) const
Returns the font settings for a legend component.
static QgsLayoutItemLegend * create(QgsLayout *layout)
Returns a new legend item for the specified layout.
bool requiresRasterization() const override
Returns true if the item is drawn in such a way that forces the whole layout to be rasterized when ex...
void setLegendFilterOutAtlas(bool doFilter)
When set to true, during an atlas rendering, it will filter out legend elements where features are ou...
void setSymbolWidth(double width)
Sets the legend symbol width.
QString wrapString() const
Returns the legend text wrapping string.
bool resizeToContents() const
Returns whether the legend should automatically resize to fit its contents.
void setResizeToContents(bool enabled)
Sets whether the legend should automatically resize to fit its contents.
void updateLegend()
Updates the model and all legend entries.
QgsLayoutItemLegend(QgsLayout *layout)
Constructor for QgsLayoutItemLegend, with the specified parent layout.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to associate with the legend.
bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const override
Stores item state within an XML DOM element.
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable legend style.
Q_DECL_DEPRECATED QColor fontColor() const
Returns the legend font color.
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
double maximumSymbolSize() const
Returns the maximum symbol size (in mm).
void setWmsLegendWidth(double width)
Sets the WMS legend width.
void setTitle(const QString &title)
Sets the legend title.
Q_DECL_DEPRECATED void setFontColor(const QColor &color)
Sets the legend font color.
double boxSpace() const
Returns the legend box space.
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
QString displayName() const override
Gets item display name.
bool isRefreshing() const override
Returns true if the item is currently refreshing content in the background.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
double symbolWidth() const
Returns the legend symbol width.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
void draw(QgsLayoutItemRenderContext &context) override
Draws the item's contents using the specified item render context.
void finalizeRestoreFromXml() override
Called after all pending items have been restored from XML.
int type() const override
bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context) override
Sets item state from a DOM element.
bool legendFilterOutAtlas() const
Returns whether to filter out legend elements outside of the current atlas feature.
void setStyle(QgsLegendStyle::Style component, const QgsLegendStyle &style)
Sets the style of component to style for the legend.
ExportLayerBehavior exportLayerBehavior() const override
Returns the behavior of this item during exporting to layered exports (e.g.
Q_DECL_DEPRECATED void setLineSpacing(double spacing)
Sets the spacing in-between multiple lines.
double columnSpace() const
Returns the legend column spacing.
QgsLayoutItem::Flags itemFlags() const override
Returns the item's flags, which indicate how the item behaves.
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
void setFilterByMapItems(const QList< QgsLayoutItemMap * > &maps)
Sets the maps to use when filtering legend content by map extents.
void setLegendFilterByMapEnabled(bool enabled)
Set whether legend items should be filtered to show just the ones visible in the associated map.
QList< QgsLayoutItemMap * > filterByMapItems() const
Returns the maps to use when filtering legend content by map extents.
void setSymbolHeight(double height)
Sets the legend symbol height.
void setMinimumSymbolSize(double size)
Set the minimum symbol size for symbol (in millimeters).
void setAutoUpdateModel(bool autoUpdate)
Sets whether the legend content should auto update to reflect changes in the project's layer tree.
void setMaximumSymbolSize(double size)
Set the maximum symbol size for symbol (in millimeters).
QIcon icon() const override
Returns the item's icon.
double wmsLegendHeight() const
Returns the WMS legend height.
void setWmsLegendHeight(double height)
Sets the WMS legend height.
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
bool containsAdvancedEffects() const override
Returns true if the item contains contents with blend modes or transparency effects which can only be...
double minimumSymbolSize() const
Returns the minimum symbol size (in mm).
double rasterStrokeWidth() const
Returns the stroke width (in layout units) for the stroke drawn around raster symbol items.
Q_DECL_DEPRECATED double lineSpacing() const
Returns the spacing in-between lines in layout units.
void invalidateCache() override
Q_DECL_DEPRECATED void setStyleFont(QgsLegendStyle::Style component, const QFont &font)
Sets the style font for a legend component.
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns legend style.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
void setWrapString(const QString &string)
Sets the legend text wrapping string.
QString themeName() const
Returns the name of the theme currently linked to the legend.
void setColumnCount(int count)
Sets the legend column count.
bool equalColumnWidth() const
Returns whether column widths should be equalized.
int columnCount() const
Returns the legend column count.
bool legendFilterByMapEnabled() const
Find out whether legend items are filtered to show just the ones visible in the associated map.
QList< QgsMapLayer * > layersToClip() const
Returns the list of map layers to clip to the atlas feature.
bool enabled() const
Returns true if the map content should be clipped to the current atlas feature.
Layout graphical items for displaying a map.
void extentChanged()
Emitted when the map's extent changes.
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, double dpi, bool includeLayerSettings) const
Returns map settings that will be used for drawing of the map.
void layerStyleOverridesChanged()
Emitted when layer style overrides are changed... a means to let associated legend items know they sh...
void mapRotationChanged(double newRotation)
Emitted when the map's rotation changes.
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation.
QgsRectangle requestedExtent() const
Calculates the extent to request and the yShift of the top-left point in case of rotation.
QList< QgsMapLayer * > layersToRender(const QgsExpressionContext *context=nullptr) const
Returns a list of the layers which will be rendered within this map item, considering any locked laye...
QMap< QString, QString > layerStyleOverrides() const
Returns stored overrides of styles for layers.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
double mapUnitsToLayoutUnits() const
Returns the conversion factor from map units to layout units.
void themeChanged(const QString &theme)
Emitted when the map's associated theme is changed.
QgsRectangle extent() const
Returns the current map extent.
QgsLayoutItemMapAtlasClippingSettings * atlasClippingSettings()
Returns the map's atlas clipping settings.
QgsCoordinateReferenceSystem crs() const
Returns coordinate reference system used for rendering the map.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Definition: qgslayoutitem.h:43
QgsRenderContext & renderContext()
Returns a reference to the context's render context.
Definition: qgslayoutitem.h:70
Base class for graphical items within a QgsLayout.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
QgsLayoutSize sizeWithUnits() const
Returns the item's current size, including units.
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.
virtual void redraw()
Triggers a redraw (update) of the item.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
virtual void attemptResize(const QgsLayoutSize &size, bool includesFrame=false)
Attempts to resize the item to a specified target size.
@ FlagOverridesPaint
Item overrides the default layout item painting method.
virtual void invalidateCache()
Forces a deferred update of any cached image the item uses.
virtual QString uuid() const
Returns the item identification string.
QString id() const
Returns the item's ID name.
ExportLayerBehavior
Behavior of item when exporting to layered outputs.
@ MustPlaceInOwnLayer
Item must be placed in its own individual layer.
QFlags< Flag > Flags
void refresh() override
Refreshes the item, causing a recalculation of any property overrides and recalculation of its positi...
QPainter::CompositionMode blendMode() const
Returns the item's composition blending mode.
QgsPropertyCollection mDataDefinedProperties
const QgsLayout * layout() const
Returns the layout the object is attached to.
void changed()
Emitted when the object's properties change.
QPointer< QgsLayout > mLayout
DataDefinedProperty
Data defined properties for different item types.
@ LegendColumnCount
Legend column count.
@ AllProperties
All properties for item.
@ FlagUseAdvancedEffects
Enable advanced effects such as blend modes.
@ FlagSynchronousLegendGraphics
Query legend graphics synchronously.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
Definition: qgslayoutsize.h:40
static QgsRenderContext createRenderContextForLayout(QgsLayout *layout, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout and painter destination.
static QgsRenderContext createRenderContextForMap(QgsLayoutItemMap *map, QPainter *painter, double dpi=-1)
Creates a render context suitable for the specified layout map and painter destination.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
Item model implementation based on layer tree model for layout legend.
void clearCachedData(QgsLayerTreeNode *node) const
Clears any previously cached data for the specified node.
void refreshLegend()
Emitted to refresh the legend.
QgsLegendModel(QgsLayerTree *rootNode, QObject *parent=nullptr, QgsLayoutItemLegend *layout=nullptr)
Construct the model based on the given layer tree.
QVariant data(const QModelIndex &index, int role) const override
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...
bool isNull() const
Returns true if the patch shape is a null QgsLegendPatchShape, which indicates that the default legen...
The QgsLegendRenderer class handles automatic layout and rendering of legend.
QSizeF minimumSize(QgsRenderContext *renderContext=nullptr)
Runs the layout algorithm and returns the minimum size required for the legend.
void setLegendSize(QSizeF s)
Sets the preferred resulting legend size.
Q_DECL_DEPRECATED void drawLegend(QPainter *painter)
Draws the legend with given painter.
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
QString wrapChar() const
Returns the string used as a wrapping character.
Q_DECL_DEPRECATED void setFontColor(const QColor &c)
Sets the font color used for legend items.
void setWrapChar(const QString &t)
Sets a string to use as a wrapping character.
void setRasterStrokeColor(const QColor &color)
Sets the stroke color for the stroke drawn around raster symbol items.
void setStyle(QgsLegendStyle::Style s, const QgsLegendStyle &style)
Sets the style for a legend component.
void setColumnSpace(double s)
Sets the margin space between adjacent columns (in millimeters).
Q_DECL_DEPRECATED void setMapScale(double scale)
Sets the legend map scale.
QgsLegendStyle style(QgsLegendStyle::Style s) const
Returns the style for a legend component.
void setTitle(const QString &t)
Sets the title for the legend, which will be rendered above all legend items.
bool drawRasterStroke() const
Returns whether a stroke will be drawn around raster symbol items.
void setDrawRasterStroke(bool enabled)
Sets whether a stroke will be drawn around raster symbol items.
QSizeF wmsLegendSize() const
Returns the size (in millimeters) of WMS legend graphics shown in the legend.
double minimumSymbolSize() const
Returns the minimum symbol size (in mm).
double rasterStrokeWidth() const
Returns the stroke width (in millimeters) for the stroke drawn around raster symbol items.
Q_DECL_DEPRECATED void setLineSpacing(double s)
Sets the line spacing to use between lines of legend text.
void setColumnCount(int c)
Sets the desired minimum number of columns to show in the legend.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
Q_DECL_DEPRECATED void setMmPerMapUnit(double mmPerMapUnit)
Q_DECL_DEPRECATED void setDpi(int dpi)
Qt::AlignmentFlag titleAlignment() const
Returns the alignment of the legend title.
QSizeF symbolSize() const
Returns the default symbol size (in millimeters) used for legend items.
Q_DECL_DEPRECATED QColor fontColor() const
Returns the font color used for legend items.
double maximumSymbolSize() const
Returns the maximum symbol size (in mm).
QString title() const
Returns the title for the legend, which will be rendered above all legend items.
QColor rasterStrokeColor() const
Returns the stroke color for the stroke drawn around raster symbol items.
Q_DECL_DEPRECATED double lineSpacing() const
Returns the line spacing to use between lines of legend text.
Q_DECL_DEPRECATED void setUseAdvancedEffects(bool use)
void setSplitLayer(bool s)
Sets whether layer components can be split over multiple columns.
double columnSpace() const
Returns the margin space between adjacent columns (in millimeters).
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns modifiable reference to the style for a legend component.
void setEqualColumnWidth(bool s)
Sets whether all columns should have equal widths.
void setBoxSpace(double s)
Sets the legend box space (in millimeters), which is the empty margin around the inside of the legend...
void setSynchronousLegendRequests(bool b)
Sets whether to request legend graphics synchronously.
double boxSpace() const
Returns the legend box space (in millimeters), which is the empty margin around the inside of the leg...
void setMaximumSymbolSize(double size)
Set the maximum symbol size for symbol (in millimeters).
bool splitLayer() const
Returns true if layer components can be split over multiple columns.
void setMinimumSymbolSize(double size)
Set the minimum symbol size for symbol (in millimeters).
void setRasterStrokeWidth(double width)
Sets the stroke width for the stroke drawn around raster symbol items.
Qt::AlignmentFlag symbolAlignment() const
Returns the alignment for placement of legend symbols.
bool equalColumnWidth() const
Returns true if all columns should have equal widths.
void setSymbolSize(QSizeF s)
Sets the default symbol size (in millimeters) used for legend items.
void setWmsLegendSize(QSizeF s)
Sets the desired size (in millimeters) of WMS legend graphics shown in the legend.
Contains detailed styling information relating to how a layout legend should be rendered.
Q_DECL_DEPRECATED QFont font() const
Returns the font used for rendering this legend component.
QgsTextFormat & textFormat()
Returns the text format used for rendering this legend component.
void setMargin(Side side, double margin)
Sets the margin (in mm) for the specified side of the component.
Side
Margin sides.
void readXml(const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext())
Reads the component's style definition from an XML element.
Style
Component of legends which can be styled.
@ Group
Legend group title.
@ Symbol
Symbol icon (excluding label)
@ Subgroup
Legend subgroup title.
@ Title
Legend title.
@ SymbolLabel
Symbol label (excluding icon)
Q_DECL_DEPRECATED void setFont(const QFont &font)
Sets the font used for rendering this legend component.
void writeXml(const QString &name, QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context=QgsReadWriteContext()) const
Writes the component's style definition to an XML element.
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for rendering this legend component.
Base class for all map layer types.
Definition: qgsmaplayer.h:75
The QgsMapSettings class contains configuration for rendering of the map.
double scale() const
Returns the calculated map scale.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
void projectColorsChanged()
Emitted whenever the project's color scheme has been changed.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:236
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:243
A QgsGeometry with associated coordinate reference system.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QPainter * painter()
Returns the destination QPainter for the render operation.
QgsExpressionContext & expressionContext()
Gets the expression context.
Scoped object for saving and restoring a QPainter object's state.
An interface for classes which can visit style entity (e.g.
virtual bool visit(const QgsStyleEntityVisitorInterface::StyleLeaf &entity)
Called when the visitor will visit a style entity.
A legend patch shape entity for QgsStyle databases.
Definition: qgsstyle.h:1495
Implementation of legend node interface for displaying preview of vector symbols and their labels and...
Container for all settings relating to text rendering.
Definition: qgstextformat.h:41
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setLineHeightUnit(Qgis::RenderUnit unit)
Sets the unit for the line height for text.
double size() const
Returns the size for rendered text.
void setLineHeight(double height)
Sets the line height for text.
Represents a vector layer which manages a vector based data sets.
long long featureCount(const QString &legendKey) const
Number of features rendered with specified legend key.
QgsLayerTreeModelLegendNode * legendNode(const QString &rule, QgsLayerTreeModel &model)
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
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:5776
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:5775
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
Single variable definition for use within a QgsExpressionContextScope.
Structure that stores all data associated with one map layer.
Contains information relating to the style entity currently being visited.