QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 }
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)
Creates a new embedded symbol renderer from an XML element, using the supplied read/write context.
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.