Quantum GIS API Documentation
1.7.5-Wroclaw
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
src
core
qgspluginlayerregistry.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgspluginlayerregistry.cpp - class for
3
registering plugin layer creators
4
-------------------
5
begin : Mon Nov 30 2009
6
copyright : (C) 2009 by Mathias Walker, Sourcepole
7
email : mwa at sourcepole.ch
8
***************************************************************************/
9
10
/***************************************************************************
11
* *
12
* This program is free software; you can redistribute it and/or modify *
13
* it under the terms of the GNU General Public License as published by *
14
* the Free Software Foundation; either version 2 of the License, or *
15
* (at your option) any later version. *
16
* *
17
***************************************************************************/
18
/* $Id$ */
19
20
#include "
qgspluginlayerregistry.h
"
21
#include "
qgslogger.h
"
22
#include "
qgspluginlayer.h
"
23
#include "
qgsmaplayerregistry.h
"
24
25
QgsPluginLayerType::QgsPluginLayerType
( QString name )
26
: mName( name )
27
{
28
}
29
30
QgsPluginLayerType::~QgsPluginLayerType
()
31
{
32
}
33
34
QString
QgsPluginLayerType::name
()
35
{
36
return
mName
;
37
}
38
39
QgsPluginLayer
*
QgsPluginLayerType::createLayer
()
40
{
41
return
NULL;
42
}
43
44
bool
QgsPluginLayerType::showLayerProperties
(
QgsPluginLayer
* layer )
45
{
46
return
false
;
47
}
48
49
//=============================================================================
50
52
QgsPluginLayerRegistry
*
QgsPluginLayerRegistry::_instance
= NULL;
53
QgsPluginLayerRegistry
*
QgsPluginLayerRegistry::instance
()
54
{
55
if
(
_instance
== NULL )
56
{
57
_instance
=
new
QgsPluginLayerRegistry
();
58
}
59
return
_instance
;
60
}
61
62
63
QgsPluginLayerRegistry::QgsPluginLayerRegistry
()
64
{
65
}
66
67
QgsPluginLayerRegistry::~QgsPluginLayerRegistry
()
68
{
69
if
( !
mPluginLayerTypes
.isEmpty() )
70
{
71
QgsDebugMsg
(
"QgsPluginLayerRegistry::~QgsPluginLayerRegistry(): creator list not empty"
);
72
foreach
( QString typeName,
mPluginLayerTypes
.keys() )
73
removePluginLayerType
( typeName );
74
}
75
}
76
77
bool
QgsPluginLayerRegistry::addPluginLayerType
(
QgsPluginLayerType
* type )
78
{
79
if
( type == NULL )
80
return
false
;
81
if
(
mPluginLayerTypes
.contains( type->
name
() ) )
82
return
false
;
83
84
mPluginLayerTypes
[type->
name
()] = type;
85
return
true
;
86
}
87
88
89
bool
QgsPluginLayerRegistry::removePluginLayerType
( QString typeName )
90
{
91
if
( !
mPluginLayerTypes
.contains( typeName ) )
92
return
false
;
93
94
// remove all remaining layers of this type - to avoid invalid behaviour
95
QList<QgsMapLayer*> layers =
QgsMapLayerRegistry::instance
()->mapLayers().values();
96
foreach
(
QgsMapLayer
* layer, layers )
97
{
98
if
( layer->
type
() ==
QgsMapLayer::PluginLayer
)
99
{
100
QgsPluginLayer
* pl = qobject_cast<
QgsPluginLayer
*>( layer );
101
if
( pl->
pluginLayerType
() == typeName )
102
{
103
QgsMapLayerRegistry::instance
()->removeMapLayer( layer->
id
() );
104
}
105
}
106
}
107
108
delete
mPluginLayerTypes
.take( typeName );
109
return
true
;
110
}
111
112
QgsPluginLayerType
*
QgsPluginLayerRegistry::pluginLayerType
( QString typeName )
113
{
114
return
mPluginLayerTypes
.value( typeName, NULL );
115
}
116
117
118
QgsPluginLayer
*
QgsPluginLayerRegistry::createLayer
( QString typeName )
119
{
120
QgsPluginLayerType
* type =
pluginLayerType
( typeName );
121
if
( !type )
122
{
123
QgsDebugMsg
(
"Unknown plugin layer type: "
+ typeName );
124
return
NULL;
125
}
126
127
return
type->
createLayer
();
128
}
Generated on Wed Jun 13 2012 13:54:10 for Quantum GIS API Documentation by
1.8.1