QGIS API Documentation  2.13.0-Master
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 
28 {
29  // add default renderers
30  addRenderer( new QgsRendererV2Metadata( "singleSymbol",
31  QObject::tr( "Single Symbol" ),
34 
35  addRenderer( new QgsRendererV2Metadata( "categorizedSymbol",
36  QObject::tr( "Categorized" ),
38 
39  addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
40  QObject::tr( "Graduated" ),
42 
43  addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
44  QObject::tr( "Rule-based" ),
47 
48  addRenderer( new QgsRendererV2Metadata( "pointDisplacement",
49  QObject::tr( "Point Displacement" ),
51 
52  addRenderer( new QgsRendererV2Metadata( "invertedPolygonRenderer",
53  QObject::tr( "Inverted Polygons" ),
55 
56  addRenderer( new QgsRendererV2Metadata( "heatmapRenderer",
57  QObject::tr( "Heatmap" ),
59 
60 
61  addRenderer( new QgsRendererV2Metadata( "25dRenderer",
62  QObject::tr( "2.5 D" ),
64 }
65 
67 {
68  Q_FOREACH ( const QString& name, mRenderers.keys() )
69  {
70  delete mRenderers[name];
71  }
72  mRenderers.clear();
73 }
74 
76 {
77  static QgsRendererV2Registry mInstance;
78  return &mInstance;
79 }
80 
81 
83 {
84  if ( !metadata || mRenderers.contains( metadata->name() ) )
85  return false;
86 
87  mRenderers[metadata->name()] = metadata;
88  mRenderersOrder << metadata->name();
89  return true;
90 }
91 
93 {
94  if ( !mRenderers.contains( rendererName ) )
95  return false;
96 
97  delete mRenderers[rendererName];
98  mRenderers.remove( rendererName );
99  mRenderersOrder.removeAll( rendererName );
100  return true;
101 }
102 
104 {
105  return mRenderers.value( rendererName );
106 }
107 
109 
111 {
112  return mRenderersOrder;
113 }
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
void clear()
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.
QList< Key > keys() const
const char * name() const
QStringList renderersList()
return a list of available renderers
static QgsFeatureRendererV2 * create(QDomElement &element)
create 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)