QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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"
28 #include "qgsnullsymbolrenderer.h"
29 #include "qgsvectorlayer.h"
30 
32 {
33  // add default renderers
34  addRenderer( new QgsRendererMetadata( QStringLiteral( "nullSymbol" ),
35  QObject::tr( "No Symbols" ),
37 
38  addRenderer( new QgsRendererMetadata( QStringLiteral( "singleSymbol" ),
39  QObject::tr( "Single Symbol" ),
42 
43  addRenderer( new QgsRendererMetadata( QStringLiteral( "categorizedSymbol" ),
44  QObject::tr( "Categorized" ),
46 
47  addRenderer( new QgsRendererMetadata( QStringLiteral( "graduatedSymbol" ),
48  QObject::tr( "Graduated" ),
50 
51  addRenderer( new QgsRendererMetadata( QStringLiteral( "RuleRenderer" ),
52  QObject::tr( "Rule-based" ),
55 
56  addRenderer( new QgsRendererMetadata( QStringLiteral( "pointDisplacement" ),
57  QObject::tr( "Point Displacement" ),
59  QIcon(),
60  nullptr,
62 
63  addRenderer( new QgsRendererMetadata( QStringLiteral( "pointCluster" ),
64  QObject::tr( "Point Cluster" ),
66  QIcon(),
67  nullptr,
69 
70  addRenderer( new QgsRendererMetadata( QStringLiteral( "mergedFeatureRenderer" ),
71  QObject::tr( "Merged Features" ),
73  QIcon(),
74  nullptr,
76 
77  addRenderer( new QgsRendererMetadata( QStringLiteral( "invertedPolygonRenderer" ),
78  QObject::tr( "Inverted Polygons" ),
80  QIcon(),
81  nullptr,
83 
84  addRenderer( new QgsRendererMetadata( QStringLiteral( "heatmapRenderer" ),
85  QObject::tr( "Heatmap" ),
87  QIcon(),
88  nullptr,
90 
91 
92  addRenderer( new QgsRendererMetadata( QStringLiteral( "25dRenderer" ),
93  QObject::tr( "2.5 D" ),
95  QIcon(),
96  nullptr,
98 }
99 
101 {
102  qDeleteAll( mRenderers );
103 }
104 
106 {
107  if ( !metadata || mRenderers.contains( metadata->name() ) )
108  return false;
109 
110  mRenderers[metadata->name()] = metadata;
111  mRenderersOrder << metadata->name();
112  return true;
113 }
114 
115 bool QgsRendererRegistry::removeRenderer( const QString &rendererName )
116 {
117  if ( !mRenderers.contains( rendererName ) )
118  return false;
119 
120  delete mRenderers[rendererName];
121  mRenderers.remove( rendererName );
122  mRenderersOrder.removeAll( rendererName );
123  return true;
124 }
125 
127 {
128  return mRenderers.value( rendererName );
129 }
130 
131 QStringList QgsRendererRegistry::renderersList( QgsRendererAbstractMetadata::LayerTypes layerTypes ) const
132 {
133  QStringList renderers;
134  const auto constMRenderersOrder = mRenderersOrder;
135  for ( const QString &renderer : constMRenderersOrder )
136  {
137  QgsRendererAbstractMetadata *r = mRenderers.value( renderer );
138  if ( r && r->compatibleLayerTypes() & layerTypes )
139  renderers << renderer;
140  }
141  return renderers;
142 }
143 
144 QStringList QgsRendererRegistry::renderersList( const QgsVectorLayer *layer ) const
145 {
147 
148  switch ( layer->geometryType() )
149  {
152  break;
153 
156  break;
157 
160  break;
161 
164  break;
165  }
166 
167  return renderersList( layerType );
168 }
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Create a new 2.5D renderer from XML.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a categorized renderer from an XML element.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new heatmap renderer instance from XML.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a renderer out of an XML, for loading.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a null renderer from XML element.
static QgsFeatureRenderer * create(QDomElement &symbologyElem, const QgsReadWriteContext &context)
Creates a renderer from XML element.
static QgsFeatureRenderer * create(QDomElement &symbologyElem, const QgsReadWriteContext &context)
Create a renderer from XML element.
Stores metadata about one renderer class.
LayerType
Layer types the renderer is compatible with.
@ All
Compatible with all vector layers.
@ LineLayer
Compatible with line layers.
@ PolygonLayer
Compatible with polygon layers.
@ PointLayer
Compatible with point layers.
virtual QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const
Returns flags indicating the types of layer the renderer is compatible with.
QString name() const
Returns the unique name of the renderer.
Convenience metadata class that uses static functions to create renderer and its widget.
bool addRenderer(QgsRendererAbstractMetadata *metadata)
Adds a renderer to the registry.
QStringList renderersList(QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All) const
Returns a list of available renderers.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
bool removeRenderer(const QString &rendererName)
Removes a renderer from registry.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new rule-based renderer instance from XML.
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new single symbol renderer from an XML element, using the supplied read/write context.
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Creates a new single symbol renderer from an SLD element.
Represents a vector layer which manages a vector based data sets.
Q_INVOKABLE QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.