QGIS API Documentation
2.2.0-Valmiera
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
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
19
#include "
qgspluginlayerregistry.h
"
20
#include "
qgslogger.h
"
21
#include "
qgspluginlayer.h
"
22
#include "
qgsmaplayerregistry.h
"
23
24
QgsPluginLayerType::QgsPluginLayerType
( QString name )
25
: mName( name )
26
{
27
}
28
29
QgsPluginLayerType::~QgsPluginLayerType
()
30
{
31
}
32
33
QString
QgsPluginLayerType::name
()
34
{
35
return
mName
;
36
}
37
38
QgsPluginLayer
*
QgsPluginLayerType::createLayer
()
39
{
40
return
NULL;
41
}
42
43
bool
QgsPluginLayerType::showLayerProperties
(
QgsPluginLayer
*layer )
44
{
45
Q_UNUSED( layer );
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
QStringList
QgsPluginLayerRegistry::pluginLayerTypes
()
78
{
79
return
mPluginLayerTypes
.keys();
80
}
81
82
bool
QgsPluginLayerRegistry::addPluginLayerType
(
QgsPluginLayerType
* type )
83
{
84
if
( type == NULL )
85
return
false
;
86
if
(
mPluginLayerTypes
.contains( type->
name
() ) )
87
return
false
;
88
89
mPluginLayerTypes
[type->
name
()] = type;
90
return
true
;
91
}
92
93
94
bool
QgsPluginLayerRegistry::removePluginLayerType
( QString typeName )
95
{
96
if
( !
mPluginLayerTypes
.contains( typeName ) )
97
return
false
;
98
99
// remove all remaining layers of this type - to avoid invalid behaviour
100
QList<QgsMapLayer*> layers =
QgsMapLayerRegistry::instance
()->mapLayers().values();
101
foreach
(
QgsMapLayer
* layer, layers )
102
{
103
if
( layer->
type
() ==
QgsMapLayer::PluginLayer
)
104
{
105
QgsPluginLayer
* pl = qobject_cast<
QgsPluginLayer
*>( layer );
106
if
( pl->
pluginLayerType
() == typeName )
107
{
108
QgsMapLayerRegistry::instance
()->removeMapLayers(
109
QStringList() << layer->
id
() );
110
}
111
}
112
}
113
114
delete
mPluginLayerTypes
.take( typeName );
115
return
true
;
116
}
117
118
QgsPluginLayerType
*
QgsPluginLayerRegistry::pluginLayerType
( QString typeName )
119
{
120
return
mPluginLayerTypes
.value( typeName, NULL );
121
}
122
123
124
QgsPluginLayer
*
QgsPluginLayerRegistry::createLayer
( QString typeName )
125
{
126
QgsPluginLayerType
* type =
pluginLayerType
( typeName );
127
if
( !type )
128
{
129
QgsDebugMsg
(
"Unknown plugin layer type: "
+ typeName );
130
return
NULL;
131
}
132
133
return
type->
createLayer
();
134
}
Generated on Sun Feb 23 2014 14:27:19 for QGIS API Documentation by
1.8.1.2