QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsrendererv2registry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrendererv2registry.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 "qgsrendererv2registry.h"
16 
17 // default renderers
21 #include "qgsrulebasedrendererv2.h"
24 #include "qgsheatmaprenderer.h"
25 #include "qgs25drenderer.h"
26 #include "qgsnullsymbolrenderer.h"
27 #include "qgsvectorlayer.h"
28 
30 {
31  // add default renderers
32  addRenderer( new QgsRendererV2Metadata( "nullSymbol",
33  QObject::tr( "No symbols" ),
35 
36  addRenderer( new QgsRendererV2Metadata( "singleSymbol",
37  QObject::tr( "Single symbol" ),
40 
41  addRenderer( new QgsRendererV2Metadata( "categorizedSymbol",
42  QObject::tr( "Categorized" ),
44 
45  addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
46  QObject::tr( "Graduated" ),
48 
49  addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
50  QObject::tr( "Rule-based" ),
53 
54  addRenderer( new QgsRendererV2Metadata( "pointDisplacement",
55  QObject::tr( "Point displacement" ),
57  QIcon(),
58  nullptr,
60 
61  addRenderer( new QgsRendererV2Metadata( "invertedPolygonRenderer",
62  QObject::tr( "Inverted polygons" ),
64  QIcon(),
65  nullptr,
67 
68  addRenderer( new QgsRendererV2Metadata( "heatmapRenderer",
69  QObject::tr( "Heatmap" ),
71  QIcon(),
72  nullptr,
74 
75 
76  addRenderer( new QgsRendererV2Metadata( "25dRenderer",
77  QObject::tr( "2.5 D" ),
79  QIcon(),
80  nullptr,
82 }
83 
85 {
86  qDeleteAll( mRenderers );
87 }
88 
90 {
91  static QgsRendererV2Registry mInstance;
92  return &mInstance;
93 }
94 
95 
97 {
98  if ( !metadata || mRenderers.contains( metadata->name() ) )
99  return false;
100 
101  mRenderers[metadata->name()] = metadata;
102  mRenderersOrder << metadata->name();
103  return true;
104 }
105 
107 {
108  if ( !mRenderers.contains( rendererName ) )
109  return false;
110 
111  delete mRenderers[rendererName];
112  mRenderers.remove( rendererName );
113  mRenderersOrder.removeAll( rendererName );
114  return true;
115 }
116 
118 {
119  return mRenderers.value( rendererName );
120 }
121 
123 
124 QStringList QgsRendererV2Registry::renderersList( QgsRendererV2AbstractMetadata::LayerTypes layerTypes ) const
125 {
126  QStringList renderers;
127  Q_FOREACH ( const QString& renderer, mRenderersOrder )
128  {
129  if ( mRenderers.value( renderer )->compatibleLayerTypes() & layerTypes )
130  renderers << renderer;
131  }
132  return renderers;
133 }
134 
136 {
138 
139  switch ( layer->geometryType() )
140  {
141  case QGis::Point:
143  break;
144 
145  case QGis::Line:
147  break;
148 
149  case QGis::Polygon:
151  break;
152 
154  case QGis::NoGeometry:
155  break;
156  }
157 
158  return renderersList( layerType );
159 }
static QgsRendererV2Registry * instance()
Returns a pointer to the QgsRendererV2Registry singleton.
bool contains(const Key &key) const
static QgsFeatureRendererV2 * create(QDomElement &element)
static QgsFeatureRendererV2 * create(QDomElement &element)
static QgsFeatureRendererV2 * create(QDomElement &symbologyElem)
create a renderer from XML element
QMap< QString, QgsRendererV2AbstractMetadata * > mRenderers
Map of name to renderer.
static QgsFeatureRendererV2 * create(QDomElement &element)
Create a new 2.5D renderer from XML.
static QgsFeatureRendererV2 * createFromSld(QDomElement &element, QGis::GeometryType geomType)
static QgsFeatureRendererV2 * createFromSld(QDomElement &element, QGis::GeometryType geomType)
Stores metadata about one renderer class.
bool removeRenderer(const QString &rendererName)
Removes a renderer from registry.
QString tr(const char *sourceText, const char *disambiguation, int n)
Registry of renderers.
QgsRendererV2AbstractMetadata * rendererMetadata(const QString &rendererName)
Returns the metadata for a specified renderer.
LayerType
Layer types the renderer is compatible with.
Compatible with all vector layers.
static QgsFeatureRendererV2 * create(QDomElement &element)
create renderer from XML element
static QgsFeatureRendererV2 * create(QDomElement &element)
Creates a null renderer from XML element.
int removeAll(const T &value)
bool addRenderer(QgsRendererV2AbstractMetadata *metadata)
Adds a renderer to the registry.
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QgsRendererV2Registry()
protected constructor
Convenience metadata class that uses static functions to create renderer and its widget.
static QgsFeatureRendererV2 * create(QDomElement &element)
create renderer from XML element
static QgsFeatureRendererV2 * create(QDomElement &element)
create renderer from XML element
QStringList renderersList(QgsRendererV2AbstractMetadata::LayerTypes layerTypes=QgsRendererV2AbstractMetadata::All) const
Returns a list of available renderers.
static QgsFeatureRendererV2 * create(QDomElement &element)
Creates a renderer out of an XML, for loading.
QStringList mRenderersOrder
List of renderers, maintained in the order that they have been added.
Represents a vector layer which manages a vector based data sets.
const T value(const Key &key) const
int remove(const Key &key)