QGIS API Documentation  3.2.0-Bonn (bc43194)
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  Q_FOREACH ( const QString &renderer, mRenderersOrder )
127  {
128  QgsRendererAbstractMetadata *r = mRenderers.value( renderer );
129  if ( r && r->compatibleLayerTypes() & layerTypes )
130  renderers << renderer;
131  }
132  return renderers;
133 }
134 
135 QStringList QgsRendererRegistry::renderersList( const QgsVectorLayer *layer ) const
136 {
138 
139  switch ( layer->geometryType() )
140  {
143  break;
144 
147  break;
148 
151  break;
152 
155  break;
156  }
157 
158  return renderersList( layerType );
159 }
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 * create(QDomElement &symbologyElem, const QgsReadWriteContext &context)
Create a renderer from 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 renderer out of an XML, for loading.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
create renderer from XML element
QgsWkbTypes::GeometryType geometryType() const
Returns point, line or polygon.
QStringList renderersList(QgsRendererAbstractMetadata::LayerTypes layerTypes=QgsRendererAbstractMetadata::All) const
Returns a list of available renderers.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new heatmap renderer instance from XML.
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
Creates a new single symbol renderer from an SLD element.
static QgsFeatureRenderer * createFromSld(QDomElement &element, QgsWkbTypes::GeometryType geomType)
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new rule-based renderer instance from XML.
Compatible with point layers.
static QgsFeatureRenderer * create(QDomElement &symbologyElem, const QgsReadWriteContext &context)
Creates a renderer from XML element.
QgsRendererAbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a null renderer from XML element.
bool addRenderer(QgsRendererAbstractMetadata *metadata)
Adds a renderer to the registry.
Convenience metadata class that uses static functions to create renderer and its widget.
Compatible with polygon layers.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Create a new 2.5D renderer from XML.
Stores metadata about one renderer class.
Compatible with all vector layers.
Represents a vector layer which manages a vector based data sets.
LayerType
Layer types the renderer is compatible with.
virtual QgsRendererAbstractMetadata::LayerTypes compatibleLayerTypes() const
Returns flags indicating the types of layer the renderer is compatible with.
bool removeRenderer(const QString &rendererName)
Removes a renderer from registry.