QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Signals | Public Member Functions | Static Public Member Functions | List of all members
QgsMapLayerRegistry Class Reference

This class tracks map layers that are currently loaded and provides various methods to retrieve matching layers from the registry. More...

#include <qgsmaplayerregistry.h>

Inheritance diagram for QgsMapLayerRegistry:
Inheritance graph
[legend]

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 ()
 
QgsMapLayeraddMapLayer (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...
 
QgsMapLayermapLayer (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)
 
QObjectchild (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< QByteArraydynamicPropertyNames () const
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) 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 QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObjectparent () 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)
 
QThreadthread () const
 

Static Public Member Functions

static QgsMapLayerRegistryinstance ()
 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
 
QObjectsender () 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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ~QgsMapLayerRegistry()

QgsMapLayerRegistry::~QgsMapLayerRegistry ( )

Definition at line 35 of file qgsmaplayerregistry.cpp.

Member Function Documentation

◆ addMapLayer()

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.

Parameters
theMapLayerA layer to add to the registry
addToLegendIf 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.
takeOwnershipOwnership 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.
Returns
nullptr if unable to add layer, otherwise pointer to newly added layer
See also
addMapLayers
Note
As a side-effect QgsProject is made dirty.
Use addMapLayers if adding more than one layer at a time
takeOwnership is not available in the Python bindings - the registry will always take ownership
See also
addMapLayers()

Definition at line 100 of file qgsmaplayerregistry.cpp.

◆ addMapLayers()

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.

Parameters
theMapLayersA list of layer which should be added to the registry
addToLegendIf 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.
takeOwnershipOwnership 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.
Returns
a list of the map layers that were added successfully. If a layer is invalid, or already exists in the registry, it will not be part of the returned QList.
Note
As a side-effect QgsProject is made dirty.
takeOwnership is not available in the Python bindings - the registry will always take ownership
added in QGIS 1.8
See also
addMapLayer()

Definition at line 63 of file qgsmaplayerregistry.cpp.

◆ clearAllLayerCaches()

Q_DECL_DEPRECATED void QgsMapLayerRegistry::clearAllLayerCaches ( )
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.

Deprecated:
since 2.4 - does nothing

Definition at line 239 of file qgsmaplayerregistry.h.

◆ count()

int QgsMapLayerRegistry::count ( ) const

Returns the number of registered layers.

Definition at line 40 of file qgsmaplayerregistry.cpp.

◆ instance()

QgsMapLayerRegistry * QgsMapLayerRegistry::instance ( )
static

Returns the instance pointer, creating the object on the first call.

Definition at line 25 of file qgsmaplayerregistry.cpp.

◆ layerRemoved

void QgsMapLayerRegistry::layerRemoved ( const QString theLayerId)
signal

Emitted after a layer was removed from the registry.

Parameters
theLayerIdThe ID of the layer removed.
Note
Consider using layersRemoved() instead
See also
layerWillBeRemoved()

◆ layers()

template<typename T >
QVector<T> QgsMapLayerRegistry::layers ( ) const
inline

Returns a list of registered map layers with a specified layer type.

Example:

QVector<QgsVectorLayer*> vectorLayers = QgsMapLayerRegistry::instance()->layers<QgsVectorLayer*>();
Note
not available in Python bindings
added in QGIS 2.16
See also
mapLayers()

Definition at line 83 of file qgsmaplayerregistry.h.

◆ layersAdded

void QgsMapLayerRegistry::layersAdded ( const QList< QgsMapLayer *> &  theMapLayers)
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.

Parameters
theMapLayersList of layers which have been added.
See also
legendLayersAdded()
layerWasAdded()

◆ layersRemoved

void QgsMapLayerRegistry::layersRemoved ( const QStringList theLayerIds)
signal

Emitted after one or more layers were removed from the registry.

Parameters
theLayerIdsA list of IDs of the layers which were removed.
See also
layersWillBeRemoved()

◆ layersWillBeRemoved [1/2]

void QgsMapLayerRegistry::layersWillBeRemoved ( const QStringList theLayerIds)
signal

Emitted when one or more layers are about to be removed from the registry.

Parameters
theLayerIdsA list of IDs for the layers which are to be removed.
See also
layerWillBeRemoved()
layersRemoved()

◆ layersWillBeRemoved [2/2]

void QgsMapLayerRegistry::layersWillBeRemoved ( const QList< QgsMapLayer *> &  layers)
signal

Emitted when one or more layers are about to be removed from the registry.

Parameters
layersA list of layers which are to be removed.
See also
layerWillBeRemoved()
layersRemoved()

◆ layerWasAdded

void QgsMapLayerRegistry::layerWasAdded ( QgsMapLayer theMapLayer)
signal

Emitted when a layer was added to the registry.

Parameters
theMapLayerThe ID of the layer which has been added.
Note
Consider using layersAdded() instead
See also
layersAdded()

◆ layerWillBeRemoved [1/2]

void QgsMapLayerRegistry::layerWillBeRemoved ( const QString theLayerId)
signal

Emitted when a layer is about to be removed from the registry.

Parameters
theLayerIdThe ID of the layer to be removed.
Note
Consider using layersWillBeRemoved() instead
See also
layersWillBeRemoved()
layerRemoved()

◆ layerWillBeRemoved [2/2]

void QgsMapLayerRegistry::layerWillBeRemoved ( QgsMapLayer layer)
signal

Emitted when a layer is about to be removed from the registry.

Parameters
layerThe layer to be removed.
Note
Consider using layersWillBeRemoved() instead
See also
layersWillBeRemoved()
layerRemoved()

◆ legendLayersAdded

void QgsMapLayerRegistry::legendLayersAdded ( const QList< QgsMapLayer *> &  theMapLayers)
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.

Parameters
theMapLayersList of QgsMapLayers which were added to the legend.

◆ mapLayer()

QgsMapLayer * QgsMapLayerRegistry::mapLayer ( const QString theLayerId) const

Retrieve a pointer to a registered layer by layer ID.

Parameters
theLayerIdID of layer to retrieve
Returns
matching layer, or nullptr if no matching layer found
See also
mapLayersByName()
mapLayers()

Definition at line 45 of file qgsmaplayerregistry.cpp.

◆ mapLayers()

QMap< QString, QgsMapLayer * > QgsMapLayerRegistry::mapLayers ( ) const

Returns a map of all registered layers by layer ID.

See also
mapLayer()
mapLayersByName()
layers()

Definition at line 199 of file qgsmaplayerregistry.cpp.

◆ mapLayersByName()

QList< QgsMapLayer * > QgsMapLayerRegistry::mapLayersByName ( const QString layerName) const

Retrieve a list of matching registered layers by layer name.

Parameters
layerNamename of layers to match
Returns
list of matching layers
See also
mapLayer()
mapLayers()

Definition at line 50 of file qgsmaplayerregistry.cpp.

◆ reloadAllLayers()

void QgsMapLayerRegistry::reloadAllLayers ( )

Reload all registered layer's provider data caches, synchronising the layer with any changes in the datasource.

See also
QgsMapLayer::reload()

Definition at line 180 of file qgsmaplayerregistry.cpp.

◆ removeAll

void QgsMapLayerRegistry::removeAll ( )
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.

◆ removeAllMapLayers()

void QgsMapLayerRegistry::removeAllMapLayers ( )

Removes all registered layers.

If the registry has ownership of any layers these layers will also be deleted.

Note
As a side-effect the QgsProject instance is marked dirty.
Calling this method will cause the removeAll() signal to be emitted.
See also
removeMapLayer()
removeMapLayers()

Definition at line 171 of file qgsmaplayerregistry.cpp.

◆ removeMapLayer() [1/2]

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.

Parameters
theLayerIdID of the layer to remove
Note
As a side-effect the QgsProject instance is marked dirty.
See also
removeMapLayers()
removeAllMapLayers()

Definition at line 160 of file qgsmaplayerregistry.cpp.

◆ removeMapLayer() [2/2]

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.

Parameters
layerThe layer to remove. Null pointers are ignored.
Note
As a side-effect the QgsProject instance is marked dirty.
See also
removeMapLayers()
removeAllMapLayers()

Definition at line 165 of file qgsmaplayerregistry.cpp.

◆ removeMapLayers() [1/2]

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.

Parameters
theLayerIdslist of IDs of the layers to remove
Note
As a side-effect the QgsProject instance is marked dirty.
added in QGIS 1.8
See also
removeMapLayer()
removeAllMapLayers()

Definition at line 109 of file qgsmaplayerregistry.cpp.

◆ removeMapLayers() [2/2]

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.

Parameters
layersA list of layers to remove. Null pointers are ignored.
Note
As a side-effect the QgsProject instance is marked dirty.
See also
removeMapLayer()
removeAllMapLayers()

Definition at line 120 of file qgsmaplayerregistry.cpp.


The documentation for this class was generated from the following files: