QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
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
21
#include "
qgslogger.h
"
22
#include "
qgspluginlayer.h
"
23
#include "
qgsproject.h
"
24
25
#include <QString>
26
27
using namespace
Qt::StringLiterals;
28
29
QgsPluginLayerType::QgsPluginLayerType
(
const
QString &
name
)
30
:
mName
(
name
)
31
{}
32
33
QString
QgsPluginLayerType::name
()
const
34
{
35
return
mName
;
36
}
37
38
QgsPluginLayer
*
QgsPluginLayerType::createLayer
()
39
{
40
return
nullptr
;
41
}
42
43
QgsPluginLayer
*
QgsPluginLayerType::createLayer
(
const
QString &uri )
44
{
45
Q_UNUSED( uri )
46
return
nullptr
;
47
}
48
49
bool
QgsPluginLayerType::showLayerProperties
(
QgsPluginLayer
*layer )
50
{
51
Q_UNUSED( layer )
52
return
false
;
53
}
54
55
//
56
// QgsPluginLayerRegistry
57
//
58
59
QgsPluginLayerRegistry::~QgsPluginLayerRegistry
()
60
{
61
if
( !mPluginLayerTypes.isEmpty() )
62
{
63
QgsDebugMsgLevel
( u
"QgsPluginLayerRegistry::~QgsPluginLayerRegistry(): creator list not empty"
_s, 2 );
64
const
QStringList keys = mPluginLayerTypes.keys();
65
for
(
const
QString &key : keys )
66
{
67
removePluginLayerType
( key );
68
}
69
}
70
}
71
72
QStringList
QgsPluginLayerRegistry::pluginLayerTypes
()
73
{
74
return
mPluginLayerTypes.keys();
75
}
76
77
bool
QgsPluginLayerRegistry::addPluginLayerType
(
QgsPluginLayerType
*type )
78
{
79
if
( !type )
80
return
false
;
81
82
if
( mPluginLayerTypes.contains( type->
name
() ) )
83
return
false
;
84
85
mPluginLayerTypes[type->
name
()] = type;
86
return
true
;
87
}
88
89
90
bool
QgsPluginLayerRegistry::removePluginLayerType
(
const
QString &typeName )
91
{
92
if
( !mPluginLayerTypes.contains( typeName ) )
93
return
false
;
94
95
// remove all remaining layers of this type - to avoid invalid behavior
96
const
QList<QgsMapLayer *> layers =
QgsProject::instance
()->
mapLayers
().values();
// skip-keyword-check
97
const
auto
constLayers = layers;
98
for
(
QgsMapLayer
*layer : constLayers )
99
{
100
if
( layer->type() ==
Qgis::LayerType::Plugin
)
101
{
102
QgsPluginLayer
*pl = qobject_cast<QgsPluginLayer *>( layer );
103
if
( pl->
pluginLayerType
() == typeName )
104
{
105
QgsProject::instance
()->
removeMapLayers
(
// skip-keyword-check
106
QStringList() << layer->id() );
107
}
108
}
109
}
110
111
delete
mPluginLayerTypes.take( typeName );
112
return
true
;
113
}
114
115
QgsPluginLayerType
*
QgsPluginLayerRegistry::pluginLayerType
(
const
QString &typeName )
116
{
117
return
mPluginLayerTypes.value( typeName,
nullptr
);
118
}
119
120
121
QgsPluginLayer
*
QgsPluginLayerRegistry::createLayer
(
const
QString &typeName,
const
QString &uri )
122
{
123
QgsPluginLayerType
*type =
pluginLayerType
( typeName );
124
if
( !type )
125
{
126
QgsDebugError
(
"Unknown plugin layer type: "
+ typeName );
127
return
nullptr
;
128
}
129
130
if
( !uri.isEmpty() )
131
return
type->
createLayer
( uri );
132
else
133
return
type->
createLayer
();
134
}
Qgis::LayerType::Plugin
@ Plugin
Plugin based layer.
Definition
qgis.h:209
QgsMapLayer
Base class for all map layer types.
Definition
qgsmaplayer.h:83
QgsPluginLayerRegistry::addPluginLayerType
bool addPluginLayerType(QgsPluginLayerType *pluginLayerType)
Add plugin layer type (take ownership) and return true on success.
Definition
qgspluginlayerregistry.cpp:77
QgsPluginLayerRegistry::~QgsPluginLayerRegistry
~QgsPluginLayerRegistry()
Definition
qgspluginlayerregistry.cpp:59
QgsPluginLayerRegistry::removePluginLayerType
bool removePluginLayerType(const QString &typeName)
Remove plugin layer type and return true on success.
Definition
qgspluginlayerregistry.cpp:90
QgsPluginLayerRegistry::pluginLayerTypes
QStringList pluginLayerTypes()
List all known layer types.
Definition
qgspluginlayerregistry.cpp:72
QgsPluginLayerRegistry::pluginLayerType
QgsPluginLayerType * pluginLayerType(const QString &typeName)
Returns plugin layer type metadata or nullptr if doesn't exist.
Definition
qgspluginlayerregistry.cpp:115
QgsPluginLayerRegistry::createLayer
QgsPluginLayer * createLayer(const QString &typeName, const QString &uri=QString())
Returns new layer if corresponding plugin has been found else returns nullptr.
Definition
qgspluginlayerregistry.cpp:121
QgsPluginLayerType
Responsible for creating plugin specific map layers.
Definition
qgspluginlayerregistry.h:35
QgsPluginLayerType::name
QString name() const
Definition
qgspluginlayerregistry.cpp:33
QgsPluginLayerType::showLayerProperties
virtual bool showLayerProperties(QgsPluginLayer *layer)
Show plugin layer properties dialog. Return false if the dialog cannot be shown.
Definition
qgspluginlayerregistry.cpp:49
QgsPluginLayerType::mName
QString mName
Definition
qgspluginlayerregistry.h:54
QgsPluginLayerType::QgsPluginLayerType
QgsPluginLayerType(const QString &name)
Definition
qgspluginlayerregistry.cpp:29
QgsPluginLayerType::createLayer
virtual QgsPluginLayer * createLayer()
Returns new layer of this type. Return nullptr on error.
Definition
qgspluginlayerregistry.cpp:38
QgsPluginLayer
Base class for plugin layers.
Definition
qgspluginlayer.h:38
QgsPluginLayer::pluginLayerType
QString pluginLayerType() const
Returns plugin layer type (the same as used in QgsPluginLayerRegistry).
Definition
qgspluginlayer.cpp:36
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition
qgsproject.cpp:490
QgsProject::removeMapLayers
void removeMapLayers(const QStringList &layerIds)
Remove a set of layers from the registry by layer ID.
Definition
qgsproject.cpp:4989
QgsProject::mapLayers
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Definition
qgsproject.cpp:5073
qgslogger.h
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition
qgslogger.h:80
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
qgspluginlayer.h
qgspluginlayerregistry.h
qgsproject.h
Generated on
for QGIS API Documentation by
1.17.0