QGIS API Documentation  2.2.0-Valmiera
 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,
49  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "CentroidFill", QObject::tr( "Centroid fill" ), QgsSymbolV2::Fill,
51  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "LinePatternFill", QObject::tr( "Line pattern fill" ), QgsSymbolV2::Fill,
53  addSymbolLayerType( new QgsSymbolLayerV2Metadata( "PointPatternFill", QObject::tr( "Point pattern fill" ), QgsSymbolV2::Fill,
55 }
56 
58 {
59  foreach ( QString name, mMetadata.keys() )
60  {
61  delete mMetadata[name];
62  }
63  mMetadata.clear();
64 }
65 
67 {
68  if ( metadata == NULL || mMetadata.contains( metadata->name() ) )
69  return false;
70 
71  mMetadata[metadata->name()] = metadata;
72  return true;
73 }
74 
75 
77 {
78  if ( mMetadata.contains( name ) )
79  return mMetadata.value( name );
80  else
81  return NULL;
82 }
83 
85 {
86  static QgsSymbolLayerV2Registry mInstance;
87  return &mInstance;
88 }
89 
91 {
92  switch ( type )
93  {
96 
97  case QgsSymbolV2::Line:
99 
100  case QgsSymbolV2::Fill:
102  }
103  return NULL;
104 }
105 
106 
108 {
109  if ( !mMetadata.contains( name ) )
110  return NULL;
111 
112  return mMetadata[name]->createSymbolLayer( properties );
113 }
114 
115 QgsSymbolLayerV2* QgsSymbolLayerV2Registry::createSymbolLayerFromSld( QString name, QDomElement& element ) const
116 {
117  if ( !mMetadata.contains( name ) )
118  return NULL;
119 
120  return mMetadata[name]->createSymbolLayerFromSld( element );
121 }
122 
124 {
125  QStringList lst;
126  QMap<QString, QgsSymbolLayerV2AbstractMetadata*>::ConstIterator it = mMetadata.begin();
127  for ( ; it != mMetadata.end(); ++it )
128  {
129  if (( *it )->type() == type )
130  lst.append( it.key() );
131  }
132  return lst;
133 }