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 
26 {
27  // add default renderers
28  addRenderer( new QgsRendererV2Metadata( "singleSymbol",
29  QObject::tr( "Single Symbol" ),
32 
33  addRenderer( new QgsRendererV2Metadata( "categorizedSymbol",
34  QObject::tr( "Categorized" ),
36 
37  addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
38  QObject::tr( "Graduated" ),
40 
41  addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
42  QObject::tr( "Rule-based" ),
45 
46  addRenderer( new QgsRendererV2Metadata( "pointDisplacement",
47  QObject::tr( "Point displacement" ),
49 
50  addRenderer( new QgsRendererV2Metadata( "invertedPolygonRenderer",
51  QObject::tr( "Inverted polygons" ),
53 }
54 
56 {
57  foreach ( QString name, mRenderers.keys() )
58  {
59  delete mRenderers[name];
60  }
61  mRenderers.clear();
62 }
63 
65 {
66  static QgsRendererV2Registry mInstance;
67  return &mInstance;
68 }
69 
70 
72 {
73  if ( metadata == NULL || mRenderers.contains( metadata->name() ) )
74  return false;
75 
76  mRenderers[metadata->name()] = metadata;
77  mRenderersOrder << metadata->name();
78  return true;
79 }
80 
81 bool QgsRendererV2Registry::removeRenderer( QString rendererName )
82 {
83  if ( !mRenderers.contains( rendererName ) )
84  return false;
85 
86  delete mRenderers[rendererName];
87  mRenderers.remove( rendererName );
88  mRenderersOrder.removeAll( rendererName );
89  return true;
90 }
91 
93 {
94  return mRenderers.value( rendererName );
95 }
96 
98 
100 {
101  return mRenderersOrder;
102 }
static QgsRendererV2Registry * instance()
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