QGIS API Documentation  2.15.0-Master (94d88e6)
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 
29 {
30  // add default renderers
31  addRenderer( new QgsRendererV2Metadata( "nullSymbol",
32  QObject::tr( "No symbols" ),
34 
35  addRenderer( new QgsRendererV2Metadata( "singleSymbol",
36  QObject::tr( "Single symbol" ),
39 
40  addRenderer( new QgsRendererV2Metadata( "categorizedSymbol",
41  QObject::tr( "Categorized" ),
43 
44  addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
45  QObject::tr( "Graduated" ),
47 
48  addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
49  QObject::tr( "Rule-based" ),
52 
53  addRenderer( new QgsRendererV2Metadata( "pointDisplacement",
54  QObject::tr( "Point displacement" ),
56 
57  addRenderer( new QgsRendererV2Metadata( "invertedPolygonRenderer",
58  QObject::tr( "Inverted polygons" ),
60 
61  addRenderer( new QgsRendererV2Metadata( "heatmapRenderer",
62  QObject::tr( "Heatmap" ),
64 
65 
66  addRenderer( new QgsRendererV2Metadata( "25dRenderer",
67  QObject::tr( "2.5 D" ),
69 }
70 
72 {
73  qDeleteAll( mRenderers );
74 }
75 
77 {
78  static QgsRendererV2Registry mInstance;
79  return &mInstance;
80 }
81 
82 
84 {
85  if ( !metadata || mRenderers.contains( metadata->name() ) )
86  return false;
87 
88  mRenderers[metadata->name()] = metadata;
89  mRenderersOrder << metadata->name();
90  return true;
91 }
92 
94 {
95  if ( !mRenderers.contains( rendererName ) )
96  return false;
97 
98  delete mRenderers[rendererName];
99  mRenderers.remove( rendererName );
100  mRenderersOrder.removeAll( rendererName );
101  return true;
102 }
103 
105 {
106  return mRenderers.value( rendererName );
107 }
108 
110 
112 {
113  return mRenderersOrder;
114 }
static QgsRendererV2Registry * instance()
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
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)
remove renderer from registry
QString tr(const char *sourceText, const char *disambiguation, int n)
Registry of renderers.
QgsRendererV2AbstractMetadata * rendererMetadata(const QString &rendererName)
get metadata for particular renderer. Returns NULL if not found in registry.
QStringList renderersList()
return a list of available renderers
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)
add a renderer to registry. Takes ownership of the metadata object.
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
static QgsFeatureRendererV2 * create(QDomElement &element)
Creates a renderer out of an XML, for loading.
QStringList mRenderersOrder
list to keep order in which renderers have been added
const T value(const Key &key) const
int remove(const Key &key)