QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsrendererregistry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererregistry.cpp
3  ---------------------
4  begin : November 2009
5  copyright : (C) 2009 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "qgsrendererregistry.h"
16 
17 // default renderers
21 #include "qgsrulebasedrenderer.h"
26 #include "qgsheatmaprenderer.h"
27 #include "qgs25drenderer.h"
29 #include "qgsnullsymbolrenderer.h"
30 #include "qgsvectorlayer.h"
31 #include "qgsmarkersymbol.h"
32 
34 {
35  // add default renderers
36  addRenderer( new QgsRendererMetadata( QStringLiteral( "nullSymbol" ),
37  QObject::tr( "No Symbols" ),
39 
40  addRenderer( new QgsRendererMetadata( QStringLiteral( "singleSymbol" ),
41  QObject::tr( "Single Symbol" ),
44 
45  addRenderer( new QgsRendererMetadata( QStringLiteral( "categorizedSymbol" ),
46  QObject::tr( "Categorized" ),
48 
49  addRenderer( new QgsRendererMetadata( QStringLiteral( "graduatedSymbol" ),
50  QObject::tr( "Graduated" ),
52 
53  addRenderer( new QgsRendererMetadata( QStringLiteral( "RuleRenderer" ),
54  QObject::tr( "Rule-based" ),
57 
58  addRenderer( new QgsRendererMetadata( QStringLiteral( "pointDisplacement" ),
59  QObject::tr( "Point Displacement" ),
61  QIcon(),
62  nullptr,
64 
65  addRenderer( new QgsRendererMetadata( QStringLiteral( "pointCluster" ),
66  QObject::tr( "Point Cluster" ),
68  QIcon(),
69  nullptr,
71 
72  addRenderer( new QgsRendererMetadata( QStringLiteral( "mergedFeatureRenderer" ),
73  QObject::tr( "Merged Features" ),
75  QIcon(),
76  nullptr,
78 
79  addRenderer( new QgsRendererMetadata( QStringLiteral( "invertedPolygonRenderer" ),
80  QObject::tr( "Inverted Polygons" ),
82  QIcon(),
83  nullptr,
85 
86  addRenderer( new QgsRendererMetadata( QStringLiteral( "heatmapRenderer" ),
87  QObject::tr( "Heatmap" ),
89  QIcon(),
90  nullptr,
92 
93 
94  addRenderer( new QgsRendererMetadata( QStringLiteral( "25dRenderer" ),
95  QObject::tr( "2.5 D" ),
97  QIcon(),
98  nullptr,
100 
101  addRenderer( new QgsRendererMetadata( QStringLiteral( "embeddedSymbol" ),
102  QObject::tr( "Embedded Symbols" ),
104 }
105 
107 {
108  qDeleteAll( mRenderers );
109 }
110 
112 {
113  if ( !metadata || mRenderers.contains( metadata->name() ) )
114  return false;
115 
116  mRenderers[metadata->name()] = metadata;
117  mRenderersOrder << metadata->name();
118  return true;
119 }
120 
121 bool QgsRendererRegistry::removeRenderer( const QString &rendererName )
122 {
123  if ( !mRenderers.contains( rendererName ) )
124  return false;
125 
126  delete mRenderers[rendererName];
127  mRenderers.remove( rendererName );
128  mRenderersOrder.removeAll( rendererName );
129  return true;
130 }
131 
133 {
134  return mRenderers.value( rendererName );
135 }
136 
137 QStringList QgsRendererRegistry::renderersList( QgsRendererAbstractMetadata::LayerTypes layerTypes ) const
138 {
139  QStringList renderers;
140  const auto constMRenderersOrder = mRenderersOrder;
141  for ( const QString &renderer : constMRenderersOrder )
142  {
143  QgsRendererAbstractMetadata *r = mRenderers.value( renderer );
144  if ( r && r->compatibleLayerTypes() & layerTypes )
145  renderers << renderer;
146  }
147  return renderers;
148 }
149 
150 QStringList QgsRendererRegistry::renderersList( const QgsVectorLayer *layer ) const
151 {
153 
154  switch ( layer->geometryType() )
155  {
158  break;
159 
162  break;
163 
166  break;
167 
170  break;
171  }
172 
173  return renderersList( layerType );
174 }
qgsnullsymbolrenderer.h
qgscategorizedsymbolrenderer.h
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:146
qgssinglesymbolrenderer.h
qgsmergedfeaturerenderer.h
QgsRendererAbstractMetadata::PointLayer
@ PointLayer
Compatible with point layers.
Definition: qgsrendererregistry.h:51
QgsRendererAbstractMetadata::name
QString name() const
Returns the unique name of the renderer.
Definition: qgsrendererregistry.h:76
QgsRendererAbstractMetadata::LineLayer
@ LineLayer
Compatible with line layers.
Definition: qgsrendererregistry.h:52
QgsPointClusterRenderer::create
static QgsFeatureRenderer * create(QDomElement &symbologyElem, const QgsReadWriteContext &context)
Creates a renderer from XML element.
Definition: qgspointclusterrenderer.cpp:99
QgsRuleBasedRenderer::createFromSld
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Definition: qgsrulebasedrenderer.cpp:1237
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:144
QgsEmbeddedSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new embedded symbol renderer from an XML element, using the supplied read/write context.
Definition: qgsembeddedsymbolrenderer.cpp:104
QgsSingleSymbolRenderer::createFromSld
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Creates a new single symbol renderer from an SLD element.
Definition: qgssinglesymbolrenderer.cpp:188
QgsRendererRegistry::removeRenderer
bool removeRenderer(const QString &rendererName)
Removes a renderer from registry.
Definition: qgsrendererregistry.cpp:121
qgsrendererregistry.h
Qgs25DRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Create a new 2.5D renderer from XML.
Definition: qgs25drenderer.cpp:132
QgsCategorizedSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a categorized renderer from an XML element.
Definition: qgscategorizedsymbolrenderer.cpp:659
QgsGraduatedSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
Definition: qgsgraduatedsymbolrenderer.cpp:463
QgsNullSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a null renderer from XML element.
Definition: qgsnullsymbolrenderer.cpp:103
qgsheatmaprenderer.h
qgs25drenderer.h
QgsRendererRegistry::renderersList
QStringList renderersList(QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All) const
Returns a list of available renderers.
Definition: qgsrendererregistry.cpp:137
QgsRendererAbstractMetadata::LayerType
LayerType
Layer types the renderer is compatible with.
Definition: qgsrendererregistry.h:49
qgsrulebasedrenderer.h
QgsPointDisplacementRenderer::create
static QgsFeatureRenderer * create(QDomElement &symbologyElem, const QgsReadWriteContext &context)
Create a renderer from XML element.
Definition: qgspointdisplacementrenderer.cpp:152
QgsRendererRegistry::addRenderer
bool addRenderer(QgsRendererAbstractMetadata *metadata)
Adds a renderer to the registry.
Definition: qgsrendererregistry.cpp:111
qgsvectorlayer.h
QgsRendererAbstractMetadata::All
@ All
Compatible with all vector layers.
Definition: qgsrendererregistry.h:54
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:143
QgsRendererRegistry::QgsRendererRegistry
QgsRendererRegistry()
Definition: qgsrendererregistry.cpp:33
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:142
QgsRendererRegistry::~QgsRendererRegistry
~QgsRendererRegistry()
Definition: qgsrendererregistry.cpp:106
QgsRendererMetadata
Convenience metadata class that uses static functions to create renderer and its widget.
Definition: qgsrendererregistry.h:142
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsRendererAbstractMetadata::compatibleLayerTypes
virtual QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const
Returns flags indicating the types of layer the renderer is compatible with.
Definition: qgsrendererregistry.h:100
qgsmarkersymbol.h
qgspointdisplacementrenderer.h
QgsInvertedPolygonRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
Definition: qgsinvertedpolygonrenderer.cpp:68
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:145
qgsembeddedsymbolrenderer.h
qgspointclusterrenderer.h
qgsinvertedpolygonrenderer.h
QgsMergedFeatureRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
Definition: qgsmergedfeaturerenderer.cpp:426
qgsgraduatedsymbolrenderer.h
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:720
QgsRendererRegistry::rendererMetadata
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
Definition: qgsrendererregistry.cpp:132
QgsRendererAbstractMetadata
Stores metadata about one renderer class.
Definition: qgsrendererregistry.h:41
QgsRendererAbstractMetadata::PolygonLayer
@ PolygonLayer
Compatible with polygon layers.
Definition: qgsrendererregistry.h:53
QgsSingleSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new single symbol renderer from an XML element, using the supplied read/write context.
Definition: qgssinglesymbolrenderer.cpp:148
QgsRuleBasedRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new rule-based renderer instance from XML.
Definition: qgsrulebasedrenderer.cpp:1214
QgsHeatmapRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new heatmap renderer instance from XML.
Definition: qgsheatmaprenderer.cpp:309