QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgssymbollayerv2registry.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgssymbollayerv2registry.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 
17 
19 #include "qgsmarkersymbollayerv2.h"
20 #include "qgslinesymbollayerv2.h"
21 #include "qgsfillsymbollayerv2.h"
23 
25 {
26  // init registry with known symbol layers
27  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleLine", QObject::tr( "Simple line" ), QgsSymbolV2::Line,
29  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "MarkerLine", QObject::tr( "Marker line" ), QgsSymbolV2::Line,
31 
32  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleMarker", QObject::tr( "Simple marker" ), QgsSymbolV2::Marker,
36  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "FontMarker", QObject::tr( "Font marker" ), QgsSymbolV2::Marker,
38  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "EllipseMarker", QObject::tr( "Ellipse marker" ), QgsSymbolV2::Marker,
40  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "VectorField", QObject::tr( "Vector Field marker" ), QgsSymbolV2::Marker,
42 
43  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "SimpleFill", QObject::tr( "Simple fill" ), QgsSymbolV2::Fill,
45  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "GradientFill", QObject::tr( "Gradient fill" ), QgsSymbolV2::Fill,
47  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "ShapeburstFill", QObject::tr( "Shapeburst fill" ), QgsSymbolV2::Fill,
51  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "CentroidFill", QObject::tr( "Centroid fill" ), QgsSymbolV2::Fill,
53  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "LinePatternFill", QObject::tr( "Line pattern fill" ), QgsSymbolV2::Fill,
55  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "PointPatternFill", QObject::tr( "Point pattern fill" ), QgsSymbolV2::Fill,
57 }
58 
60 {
61  foreach ( QString name, mMetadata.keys() )
62  {
63  delete mMetadata[name];
64  }
65  mMetadata.clear();
66 }
67 
69 {
70  if ( metadata == NULL || mMetadata.contains( metadata->name() ) )
71  return false;
72 
73  mMetadata[metadata->name()] = metadata;
74  return true;
75 }
76 
77 
79 {
80  if ( mMetadata.contains( name ) )
81  return mMetadata.value( name );
82  else
83  return NULL;
84 }
85 
87 {
88  static QgsSymbolLayerV2Registry mInstance;
89  return &mInstance;
90 }
91 
93 {
94  switch ( type )
95  {
98 
99  case QgsSymbolV2::Line:
101 
102  case QgsSymbolV2::Fill:
104  }
105  return NULL;
106 }
107 
108 
110 {
111  if ( !mMetadata.contains( name ) )
112  return NULL;
113 
114  return mMetadata[name]->createSymbolLayer( properties );
115 }
116 
117 QgsSymbolLayerV2* QgsSymbolLayerV2Registry::createSymbolLayerFromSld( QString name, QDomElement& element ) const
118 {
119  if ( !mMetadata.contains( name ) )
120  return NULL;
121 
122  return mMetadata[name]->createSymbolLayerFromSld( element );
123 }
124 
126 {
127  QStringList lst;
128  QMap<QString, QgsSymbolLayerV2AbstractMetadata*>::ConstIterator it = mMetadata.begin();
129  for ( ; it != mMetadata.end(); ++it )
130  {
131  if (( *it )->type() == type )
132  lst.append( it.key() );
133  }
134  return lst;
135 }
static QgsSymbolLayerV2 * defaultSymbolLayer(QgsSymbolV2::SymbolType type)
create a new instance of symbol layer for specified symbol type with default settings ...
QgsSymbolLayerV2 * createSymbolLayer(QString name, const QgsStringMap &properties=QgsStringMap()) const
create a new instance of symbol layer given symbol layer name and properties
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
QgsSymbolLayerV2AbstractMetadata * symbolLayerMetadata(QString name) const
return metadata for specified symbol layer. Returns NULL if not found
Stores metadata about one symbol layer class.
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2Registry * instance()
return the single instance of this class (instantiate it if not exists)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
QgsSymbolLayerV2 * createSymbolLayerFromSld(QString name, QDomElement &element) const
create a new instance of symbol layer given symbol layer name and SLD
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
QMap< QString, QgsSymbolLayerV2AbstractMetadata * > mMetadata
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
QStringList symbolLayersForType(QgsSymbolV2::SymbolType type)
return a list of available symbol layers for a specified symbol type
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
bool addSymbolLayerType(QgsSymbolLayerV2AbstractMetadata *metadata)
register a new symbol layer type. Takes ownership of the metadata instance.
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
static QgsSymbolLayerV2 * createFromSld(QDomElement &element)
Registry of available symbol layer classes.
static QgsSymbolLayerV2 * create(const QgsStringMap &properties=QgsStringMap())
Convenience metadata class that uses static functions to create symbol layer and its widget...
#define tr(sourceText)