QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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  addRenderer( new QgsRendererV2Metadata( "graduatedSymbol",
37  QObject::tr( "Graduated" ),
39 
40  addRenderer( new QgsRendererV2Metadata( "RuleRenderer",
41  QObject::tr( "Rule-based" ),
44 
45  addRenderer( new QgsRendererV2Metadata( "pointDisplacement",
46  QObject::tr( "Point displacement" ),
48 
49  addRenderer( new QgsRendererV2Metadata( "invertedPolygonRenderer",
50  QObject::tr( "Inverted polygons" ),
52 }
53 
55 {
56  foreach ( QString name, mRenderers.keys() )
57  {
58  delete mRenderers[name];
59  }
60  mRenderers.clear();
61 }
62 
64 {
65  static QgsRendererV2Registry mInstance;
66  return &mInstance;
67 }
68 
69 
71 {
72  if ( metadata == NULL || mRenderers.contains( metadata->name() ) )
73  return false;
74 
75  mRenderers[metadata->name()] = metadata;
76  mRenderersOrder << metadata->name();
77  return true;
78 }
79 
80 bool QgsRendererV2Registry::removeRenderer( QString rendererName )
81 {
82  if ( !mRenderers.contains( rendererName ) )
83  return false;
84 
85  delete mRenderers[rendererName];
86  mRenderers.remove( rendererName );
87  mRenderersOrder.removeAll( rendererName );
88  return true;
89 }
90 
92 {
93  return mRenderers.value( rendererName );
94 }
95 
97 
99 {
100  return mRenderersOrder;
101 }
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