QGIS API Documentation
2.18.21-Las Palmas (9fba24a)
|
This class tracks map layers that are currently loaded and provides various methods to retrieve matching layers from the registry. More...
#include <qgsmaplayerregistry.h>
Signals | |
void | layerRemoved (const QString &theLayerId) |
Emitted after a layer was removed from the registry. More... | |
void | layersAdded (const QList< QgsMapLayer *> &theMapLayers) |
Emitted when one or more layers were added to the registry. More... | |
void | layersRemoved (const QStringList &theLayerIds) |
Emitted after one or more layers were removed from the registry. More... | |
void | layersWillBeRemoved (const QStringList &theLayerIds) |
Emitted when one or more layers are about to be removed from the registry. More... | |
void | layersWillBeRemoved (const QList< QgsMapLayer *> &layers) |
Emitted when one or more layers are about to be removed from the registry. More... | |
void | layerWasAdded (QgsMapLayer *theMapLayer) |
Emitted when a layer was added to the registry. More... | |
void | layerWillBeRemoved (const QString &theLayerId) |
Emitted when a layer is about to be removed from the registry. More... | |
void | layerWillBeRemoved (QgsMapLayer *layer) |
Emitted when a layer is about to be removed from the registry. More... | |
void | legendLayersAdded (const QList< QgsMapLayer *> &theMapLayers) |
Emitted, when a layer was added to the registry and the legend. More... | |
void | removeAll () |
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted. More... | |
Public Member Functions | |
~QgsMapLayerRegistry () | |
QgsMapLayer * | addMapLayer (QgsMapLayer *theMapLayer, bool addToLegend=true, bool takeOwnership=true) |
Add a layer to the map of loaded layers. More... | |
QList< QgsMapLayer * > | addMapLayers (const QList< QgsMapLayer *> &theMapLayers, bool addToLegend=true, bool takeOwnership=true) |
Add a list of layers to the map of loaded layers. More... | |
Q_DECL_DEPRECATED void | clearAllLayerCaches () |
Clears all layer caches, resetting them to zero and freeing up any memory they may have been using. More... | |
int | count () const |
Returns the number of registered layers. More... | |
template<typename T > | |
QVector< T > | layers () const |
Returns a list of registered map layers with a specified layer type. More... | |
QgsMapLayer * | mapLayer (const QString &theLayerId) const |
Retrieve a pointer to a registered layer by layer ID. More... | |
QMap< QString, QgsMapLayer * > | mapLayers () const |
Returns a map of all registered layers by layer ID. More... | |
QList< QgsMapLayer * > | mapLayersByName (const QString &layerName) const |
Retrieve a list of matching registered layers by layer name. More... | |
void | reloadAllLayers () |
Reload all registered layer's provider data caches, synchronising the layer with any changes in the datasource. More... | |
void | removeAllMapLayers () |
Removes all registered layers. More... | |
void | removeMapLayer (const QString &theLayerId) |
Remove a layer from the registry by layer ID. More... | |
void | removeMapLayer (QgsMapLayer *layer) |
Remove a layer from the registry. More... | |
void | removeMapLayers (const QStringList &theLayerIds) |
Remove a set of layers from the registry by layer ID. More... | |
void | removeMapLayers (const QList< QgsMapLayer *> &layers) |
Remove a set of layers from the registry. More... | |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
QObject (QObject *parent, const char *name) | |
virtual | ~QObject () |
bool | blockSignals (bool block) |
QObject * | child (const char *objName, const char *inheritsClass, bool recursiveSearch) const |
const QObjectList & | children () const |
const char * | className () const |
bool | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const |
void | deleteLater () |
void | destroyed (QObject *obj) |
bool | disconnect (const QObject *receiver, const char *method) |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QByteArray > | dynamicPropertyNames () const |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
T | findChild (const QString &name) const |
QList< T > | findChildren (const QRegExp ®Exp) const |
QList< T > | findChildren (const QString &name) const |
bool | inherits (const char *className) const |
void | insertChild (QObject *object) |
void | installEventFilter (QObject *filterObj) |
bool | isA (const char *className) const |
bool | isWidgetType () const |
void | killTimer (int id) |
virtual const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
const char * | name () const |
const char * | name (const char *defaultName) const |
QString | objectName () const |
QObject * | parent () const |
QVariant | property (const char *name) const |
void | removeChild (QObject *object) |
void | removeEventFilter (QObject *obj) |
void | setName (const char *name) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const char *name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval) |
QThread * | thread () const |
Static Public Member Functions | |
static QgsMapLayerRegistry * | instance () |
Returns the instance pointer, creating the object on the first call. More... | |
Static Public Member Functions inherited from QObject | |
bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
Additional Inherited Members | |
Protected Member Functions inherited from QObject | |
bool | checkConnectArgs (const char *signal, const QObject *object, const char *method) |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const char *signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const char *signal) |
int | receivers (const char *signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Static Protected Member Functions inherited from QObject | |
QByteArray | normalizeSignalSlot (const char *signalSlot) |
Properties inherited from QObject | |
objectName | |
This class tracks map layers that are currently loaded and provides various methods to retrieve matching layers from the registry.
Definition at line 34 of file qgsmaplayerregistry.h.
QgsMapLayerRegistry::~QgsMapLayerRegistry | ( | ) |
Definition at line 35 of file qgsmaplayerregistry.cpp.
QgsMapLayer * QgsMapLayerRegistry::addMapLayer | ( | QgsMapLayer * | theMapLayer, |
bool | addToLegend = true , |
||
bool | takeOwnership = true |
||
) |
Add a layer to the map of loaded layers.
The layersAdded() and layerWasAdded() signals will always be emitted. The legendLayersAdded() signal is emitted only if addToLegend is true. If you are adding multiple layers at once, you should use addMapLayers() instead.
theMapLayer | A layer to add to the registry |
addToLegend | If true (by default), the layer will be added to the legend and to the main canvas. If you have a private layer you can set this parameter to false to hide it. |
takeOwnership | Ownership will be transferred to the layer registry. If you specify false here you have take care of deleting the layer yourself. Not available in python. |
Definition at line 100 of file qgsmaplayerregistry.cpp.
QList< QgsMapLayer * > QgsMapLayerRegistry::addMapLayers | ( | const QList< QgsMapLayer *> & | theMapLayers, |
bool | addToLegend = true , |
||
bool | takeOwnership = true |
||
) |
Add a list of layers to the map of loaded layers.
The layersAdded() and layerWasAdded() signals will always be emitted. The legendLayersAdded() signal is emitted only if addToLegend is true.
theMapLayers | A list of layer which should be added to the registry |
addToLegend | If true (by default), the layers will be added to the legend and to the main canvas. If you have a private layer you can set this parameter to false to hide it. |
takeOwnership | Ownership will be transferred to the layer registry. If you specify false here you have take care of deleting the layers yourself. Not available in python. |
Definition at line 63 of file qgsmaplayerregistry.cpp.
|
inline |
Clears all layer caches, resetting them to zero and freeing up any memory they may have been using.
Layer caches are used to speed up rendering in certain situations see ticket #1974 for more details.
Definition at line 239 of file qgsmaplayerregistry.h.
int QgsMapLayerRegistry::count | ( | ) | const |
Returns the number of registered layers.
Definition at line 40 of file qgsmaplayerregistry.cpp.
|
static |
Returns the instance pointer, creating the object on the first call.
Definition at line 25 of file qgsmaplayerregistry.cpp.
|
signal |
Emitted after a layer was removed from the registry.
theLayerId | The ID of the layer removed. |
|
inline |
Returns a list of registered map layers with a specified layer type.
Example:
QVector<QgsVectorLayer*> vectorLayers = QgsMapLayerRegistry::instance()->layers<QgsVectorLayer*>();
Definition at line 83 of file qgsmaplayerregistry.h.
|
signal |
Emitted when one or more layers were added to the registry.
This signal is also emitted for layers added to the registry, but not to the legend.
theMapLayers | List of layers which have been added. |
|
signal |
Emitted after one or more layers were removed from the registry.
theLayerIds | A list of IDs of the layers which were removed. |
|
signal |
Emitted when one or more layers are about to be removed from the registry.
theLayerIds | A list of IDs for the layers which are to be removed. |
|
signal |
Emitted when one or more layers are about to be removed from the registry.
layers | A list of layers which are to be removed. |
|
signal |
Emitted when a layer was added to the registry.
theMapLayer | The ID of the layer which has been added. |
|
signal |
Emitted when a layer is about to be removed from the registry.
theLayerId | The ID of the layer to be removed. |
|
signal |
Emitted when a layer is about to be removed from the registry.
layer | The layer to be removed. |
|
signal |
Emitted, when a layer was added to the registry and the legend.
Layers can also be private layers, which are signalled by layersAdded() and layerWasAdded() but will not be advertised by this signal.
theMapLayers | List of QgsMapLayers which were added to the legend. |
QgsMapLayer * QgsMapLayerRegistry::mapLayer | ( | const QString & | theLayerId | ) | const |
Retrieve a pointer to a registered layer by layer ID.
theLayerId | ID of layer to retrieve |
Definition at line 45 of file qgsmaplayerregistry.cpp.
QMap< QString, QgsMapLayer * > QgsMapLayerRegistry::mapLayers | ( | ) | const |
Returns a map of all registered layers by layer ID.
Definition at line 199 of file qgsmaplayerregistry.cpp.
QList< QgsMapLayer * > QgsMapLayerRegistry::mapLayersByName | ( | const QString & | layerName | ) | const |
Retrieve a list of matching registered layers by layer name.
layerName | name of layers to match |
Definition at line 50 of file qgsmaplayerregistry.cpp.
void QgsMapLayerRegistry::reloadAllLayers | ( | ) |
Reload all registered layer's provider data caches, synchronising the layer with any changes in the datasource.
Definition at line 180 of file qgsmaplayerregistry.cpp.
|
signal |
Emitted when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted.
The layersWillBeRemoved() and layerWillBeRemoved() signals will still be emitted following this signal. You can use this signal to do easy (and fast) cleanup.
void QgsMapLayerRegistry::removeAllMapLayers | ( | ) |
Removes all registered layers.
If the registry has ownership of any layers these layers will also be deleted.
Definition at line 171 of file qgsmaplayerregistry.cpp.
void QgsMapLayerRegistry::removeMapLayer | ( | const QString & | theLayerId | ) |
Remove a layer from the registry by layer ID.
The specified layer will be removed from the registry. If the registry has ownership of the layer then it will also be deleted.
theLayerId | ID of the layer to remove |
Definition at line 160 of file qgsmaplayerregistry.cpp.
void QgsMapLayerRegistry::removeMapLayer | ( | QgsMapLayer * | layer | ) |
Remove a layer from the registry.
The specified layer will be removed from the registry. If the registry has ownership of the layer then it will also be deleted.
layer | The layer to remove. Null pointers are ignored. |
Definition at line 165 of file qgsmaplayerregistry.cpp.
void QgsMapLayerRegistry::removeMapLayers | ( | const QStringList & | theLayerIds | ) |
Remove a set of layers from the registry by layer ID.
The specified layers will be removed from the registry. If the registry has ownership of any layers these layers will also be deleted.
theLayerIds | list of IDs of the layers to remove |
Definition at line 109 of file qgsmaplayerregistry.cpp.
void QgsMapLayerRegistry::removeMapLayers | ( | const QList< QgsMapLayer *> & | layers | ) |
Remove a set of layers from the registry.
The specified layers will be removed from the registry. If the registry has ownership of any layers these layers will also be deleted.
layers | A list of layers to remove. Null pointers are ignored. |
Definition at line 120 of file qgsmaplayerregistry.cpp.