QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
27 {
28  // add default renderers
29  addRenderer( new QgsRendererV2Metadata( "singleSymbol",
30  QObject::tr( "Single Symbol" ),
33 
34  addRenderer( new QgsRendererV2Metadata( "categorizedSymbol",
35  QObject::tr( "Categorized" ),
37 
38  addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
39  QObject::tr( "Graduated" ),
41 
42  addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
43  QObject::tr( "Rule-based" ),
46 
47  addRenderer( new QgsRendererV2Metadata( "pointDisplacement",
48  QObject::tr( "Point displacement" ),
50 
51  addRenderer( new QgsRendererV2Metadata( "invertedPolygonRenderer",
52  QObject::tr( "Inverted polygons" ),
54 
55  addRenderer( new QgsRendererV2Metadata( "heatmapRenderer",
56  QObject::tr( "Heatmap" ),
58 }
59 
61 {
62  foreach ( QString name, mRenderers.keys() )
63  {
64  delete mRenderers[name];
65  }
66  mRenderers.clear();
67 }
68 
70 {
71  static QgsRendererV2Registry mInstance;
72  return &mInstance;
73 }
74 
75 
77 {
78  if ( metadata == NULL || mRenderers.contains( metadata->name() ) )
79  return false;
80 
81  mRenderers[metadata->name()] = metadata;
82  mRenderersOrder << metadata->name();
83  return true;
84 }
85 
86 bool QgsRendererV2Registry::removeRenderer( QString rendererName )
87 {
88  if ( !mRenderers.contains( rendererName ) )
89  return false;
90 
91  delete mRenderers[rendererName];
92  mRenderers.remove( rendererName );
93  mRenderersOrder.removeAll( rendererName );
94  return true;
95 }
96 
98 {
99  return mRenderers.value( rendererName );
100 }
101 
103 
105 {
106  return mRenderersOrder;
107 }
static QgsRendererV2Registry * instance()
static QgsFeatureRendererV2 * create(QDomElement &element)
QgsRendererV2AbstractMetadata * rendererMetadata(QString rendererName)
get metadata for particular renderer. Returns NULL if not found in registry.
static QgsFeatureRendererV2 * create(QDomElement &element)
static QgsFeatureRendererV2 * create(QDomElement &symbologyElem)
create a renderer from XML element
QMap< QString, QgsRendererV2AbstractMetadata * > mRenderers
static QgsFeatureRendererV2 * createFromSld(QDomElement &element, QGis::GeometryType geomType)
static QgsFeatureRendererV2 * createFromSld(QDomElement &element, QGis::GeometryType geomType)
Stores metadata about one renderer class.
Registry of renderers.
QStringList renderersList()
return a list of available renderers
static QgsFeatureRendererV2 * create(QDomElement &element)
create renderer from XML element
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
#define tr(sourceText)
bool removeRenderer(QString rendererName)
remove renderer from registry