QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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"
25 #include "qgsheatmaprenderer.h"
26 #include "qgs25drenderer.h"
27 #include "qgsnullsymbolrenderer.h"
28 #include "qgsvectorlayer.h"
29 
31 {
32  // add default renderers
33  addRenderer( new QgsRendererMetadata( QStringLiteral( "nullSymbol" ),
34  QObject::tr( "No symbols" ),
36 
37  addRenderer( new QgsRendererMetadata( QStringLiteral( "singleSymbol" ),
38  QObject::tr( "Single symbol" ),
41 
42  addRenderer( new QgsRendererMetadata( QStringLiteral( "categorizedSymbol" ),
43  QObject::tr( "Categorized" ),
45 
46  addRenderer( new QgsRendererMetadata( QStringLiteral( "graduatedSymbol" ),
47  QObject::tr( "Graduated" ),
49 
50  addRenderer( new QgsRendererMetadata( QStringLiteral( "RuleRenderer" ),
51  QObject::tr( "Rule-based" ),
54 
55  addRenderer( new QgsRendererMetadata( QStringLiteral( "pointDisplacement" ),
56  QObject::tr( "Point displacement" ),
58  QIcon(),
59  nullptr,
61 
62  addRenderer( new QgsRendererMetadata( QStringLiteral( "pointCluster" ),
63  QObject::tr( "Point cluster" ),
65  QIcon(),
66  nullptr,
68 
69  addRenderer( new QgsRendererMetadata( QStringLiteral( "invertedPolygonRenderer" ),
70  QObject::tr( "Inverted polygons" ),
72  QIcon(),
73  nullptr,
75 
76  addRenderer( new QgsRendererMetadata( QStringLiteral( "heatmapRenderer" ),
77  QObject::tr( "Heatmap" ),
79  QIcon(),
80  nullptr,
82 
83 
84  addRenderer( new QgsRendererMetadata( QStringLiteral( "25dRenderer" ),
85  QObject::tr( "2.5 D" ),
87  QIcon(),
88  nullptr,
90 }
91 
93 {
94  qDeleteAll( mRenderers );
95 }
96 
98 {
99  if ( !metadata || mRenderers.contains( metadata->name() ) )
100  return false;
101 
102  mRenderers[metadata->name()] = metadata;
103  mRenderersOrder << metadata->name();
104  return true;
105 }
106 
107 bool QgsRendererRegistry::removeRenderer( const QString &rendererName )
108 {
109  if ( !mRenderers.contains( rendererName ) )
110  return false;
111 
112  delete mRenderers[rendererName];
113  mRenderers.remove( rendererName );
114  mRenderersOrder.removeAll( rendererName );
115  return true;
116 }
117 
119 {
120  return mRenderers.value( rendererName );
121 }
122 
123 QStringList QgsRendererRegistry::renderersList( QgsRendererAbstractMetadata::LayerTypes layerTypes ) const
124 {
125  QStringList renderers;
126  const auto constMRenderersOrder = mRenderersOrder;
127  for ( const QString &renderer : constMRenderersOrder )
128  {
129  QgsRendererAbstractMetadata *r = mRenderers.value( renderer );
130  if ( r && r->compatibleLayerTypes() & layerTypes )
131  renderers << renderer;
132  }
133  return renderers;
134 }
135 
136 QStringList QgsRendererRegistry::renderersList( const QgsVectorLayer *layer ) const
137 {
139 
140  switch ( layer->geometryType() )
141  {
144  break;
145 
148  break;
149 
152  break;
153 
156  break;
157  }
158 
159  return renderersList( layerType );
160 }
qgsnullsymbolrenderer.h
qgscategorizedsymbolrenderer.h
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:145
qgssinglesymbolrenderer.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:97
QgsRuleBasedRenderer::createFromSld
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Definition: qgsrulebasedrenderer.cpp:1152
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:143
QgsSingleSymbolRenderer::createFromSld
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Creates a new single symbol renderer from an SLD element.
Definition: qgssinglesymbolrenderer.cpp:186
QgsRendererRegistry::removeRenderer
bool removeRenderer(const QString &rendererName)
Removes a renderer from registry.
Definition: qgsrendererregistry.cpp:107
qgsrendererregistry.h
Qgs25DRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Create a new 2.5D renderer from XML.
Definition: qgs25drenderer.cpp:129
QgsCategorizedSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a categorized renderer from an XML element.
Definition: qgscategorizedsymbolrenderer.cpp:654
QgsGraduatedSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
Definition: qgsgraduatedsymbolrenderer.cpp:462
QgsNullSymbolRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a null renderer from XML element.
Definition: qgsnullsymbolrenderer.cpp:100
qgsheatmaprenderer.h
qgs25drenderer.h
QgsRendererRegistry::renderersList
QStringList renderersList(QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All) const
Returns a list of available renderers.
Definition: qgsrendererregistry.cpp:123
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:151
QgsRendererRegistry::addRenderer
bool addRenderer(QgsRendererAbstractMetadata *metadata)
Adds a renderer to the registry.
Definition: qgsrendererregistry.cpp:97
qgsvectorlayer.h
QgsRendererAbstractMetadata::All
@ All
Compatible with all vector layers.
Definition: qgsrendererregistry.h:54
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:142
QgsRendererRegistry::QgsRendererRegistry
QgsRendererRegistry()
Definition: qgsrendererregistry.cpp:30
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:141
QgsRendererRegistry::~QgsRendererRegistry
~QgsRendererRegistry()
Definition: qgsrendererregistry.cpp:92
QgsRendererMetadata
Definition: qgsrendererregistry.h:141
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsRendererAbstractMetadata::compatibleLayerTypes
virtual QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const
Returns flags indicating the types of layer the renderer is compatible with.
Definition: qgsrendererregistry.h:100
qgspointdisplacementrenderer.h
QgsInvertedPolygonRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
Definition: qgsinvertedpolygonrenderer.cpp:393
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:144
qgspointclusterrenderer.h
qgsinvertedpolygonrenderer.h
qgsgraduatedsymbolrenderer.h
QgsVectorLayer::geometryType
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
Definition: qgsvectorlayer.cpp:659
QgsRendererRegistry::rendererMetadata
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
Definition: qgsrendererregistry.cpp:118
QgsRendererAbstractMetadata
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:146
QgsRuleBasedRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new rule-based renderer instance from XML.
Definition: qgsrulebasedrenderer.cpp:1129
QgsHeatmapRenderer::create
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new heatmap renderer instance from XML.
Definition: qgsheatmaprenderer.cpp:308