QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes | List of all members
QgsMapLayerRegistry Class Reference

This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a map layer and delete it. More...

#include <qgsmaplayerregistry.h>

Inheritance diagram for QgsMapLayerRegistry:
Inheritance graph
[legend]
Collaboration diagram for QgsMapLayerRegistry:
Collaboration graph
[legend]

Signals

void layersWillBeRemoved (QStringList theLayerIds)
 Emitted when one or more layers are removed from the registry. More...
 
void layerWillBeRemoved (QString theLayerId)
 Emitted when a layer is removed from the registry. More...
 
void layersRemoved (QStringList theLayerIds)
 Emitted after one or more layers were removed from the registry. More...
 
void layerRemoved (QString theLayerId)
 Emitted after a layer was removed from the registry. More...
 
void removeAll ()
 Emitted, when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted. More...
 
void layersAdded (QList< QgsMapLayer * > theMapLayers)
 Emitted when one or more layers are added to the registry. More...
 
void layerWasAdded (QgsMapLayer *theMapLayer)
 Emitted when a layer is added to the registry. More...
 
void legendLayersAdded (QList< QgsMapLayer * > theMapLayers)
 Emitted, when a layer is added to the registry and the legend. More...
 

Public Member Functions

int count ()
 Return the number of registered layers. More...
 
 ~QgsMapLayerRegistry ()
 
QgsMapLayermapLayer (QString theLayerId)
 Retrieve a pointer to a loaded layer by id. More...
 
QList< QgsMapLayer * > mapLayersByName (QString layerName)
 Retrieve a pointer to a loaded layer by name. More...
 
const QMap< QString,
QgsMapLayer * > & 
mapLayers ()
 Retrieve the mapLayers collection (mainly intended for use by projection) More...
 
QList< QgsMapLayer * > addMapLayers (QList< QgsMapLayer * > theMapLayers, bool addToLegend=true, bool takeOwnership=true)
 Add a list of layers to the map of loaded layers. More...
 
QgsMapLayeraddMapLayer (QgsMapLayer *theMapLayer, bool addToLegend=true, bool takeOwnership=true)
 Add a layer to the map of loaded layers. More...
 
void removeMapLayers (QStringList theLayerIds)
 Remove a set of layers from the registry. More...
 
void removeMapLayer (const QString &theLayerId)
 Remove a layer from qgis. More...
 
void removeAllMapLayers ()
 Remove all registered 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...
 
void reloadAllLayers ()
 Reload all provider data caches (currently used for WFS and WMS providers) More...
 

Static Public Member Functions

static QgsMapLayerRegistryinstance ()
 Returns the instance pointer, creating the object on the first call. More...
 

Protected Member Functions

 QgsMapLayerRegistry (QObject *parent=0)
 protected constructor More...
 
void connectNotify (const char *signal)
 debugging member invoked when a connect() is made to this object More...
 

Private Attributes

QMap< QString, QgsMapLayer * > mMapLayers
 
QSet< QgsMapLayer * > mOwnedLayers
 

Static Private Attributes

static QgsMapLayerRegistrymInstance = 0
 

Detailed Description

This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a map layer and delete it.

Definition at line 33 of file qgsmaplayerregistry.h.

Constructor & Destructor Documentation

QgsMapLayerRegistry::~QgsMapLayerRegistry ( )

Definition at line 44 of file qgsmaplayerregistry.cpp.

References removeAllMapLayers().

QgsMapLayerRegistry::QgsMapLayerRegistry ( QObject *  parent = 0)
protected

protected constructor

Definition at line 39 of file qgsmaplayerregistry.cpp.

Referenced by instance().

Member Function Documentation

QgsMapLayer * QgsMapLayerRegistry::addMapLayer ( QgsMapLayer theMapLayer,
bool  addToLegend = true,
bool  takeOwnership = true 
)

Add a layer to the map of loaded layers.

The layersAdded() and layersWasAdded() signals will be emitted in any case. The legendLayersAdded() signal 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 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
NULL 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
takeOwner not available in python binding - always takes ownership

Definition at line 110 of file qgsmaplayerregistry.cpp.

References addMapLayers().

QList< QgsMapLayer * > QgsMapLayerRegistry::addMapLayers ( QList< QgsMapLayer * >  theMapLayers,
bool  addToLegend = true,
bool  takeOwnership = true 
)

Add a list of layers to the map of loaded layers.

The layersAdded() and layersWasAdded() signals will be emitted in any case. The legendLayersAdded() signal 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
QList<QgsMapLayer *> - 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.
Added in QGIS 1.8
takeOwner not available in python binding - always takes ownership

Definition at line 74 of file qgsmaplayerregistry.cpp.

References QgsMapLayer::id(), QgsMapLayer::isValid(), layersAdded(), layerWasAdded(), legendLayersAdded(), mMapLayers, mOwnedLayers, and QgsDebugMsg.

Referenced by QgsProject::addLayer(), addMapLayer(), QgsOfflineEditing::copyVectorLayer(), and QgsOfflineEditing::synchronize().

void QgsMapLayerRegistry::clearAllLayerCaches ( )

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.

Note
Added in QGIS 1.4
Deprecated:
since 2.4 - does nothing

Definition at line 154 of file qgsmaplayerregistry.cpp.

void QgsMapLayerRegistry::connectNotify ( const char *  signal)
protected

debugging member invoked when a connect() is made to this object

Definition at line 178 of file qgsmaplayerregistry.cpp.

int QgsMapLayerRegistry::count ( )

Return the number of registered layers.

Definition at line 50 of file qgsmaplayerregistry.cpp.

References mMapLayers.

QgsMapLayerRegistry * QgsMapLayerRegistry::instance ( )
static

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

Definition at line 26 of file qgsmaplayerregistry.cpp.

References mInstance, and QgsMapLayerRegistry().

Referenced by QgsProject::addLayer(), QgsLayerTreeLayer::attachToLayer(), QgsGeometry::avoidIntersections(), QgsVectorLayerJoinBuffer::cacheJoinLayer(), QgsMapRendererCache::clearCacheImage(), QgsMapRendererCache::clearInternal(), QgsOfflineEditing::committedFeaturesAdded(), QgsComposerMap::connectUpdateSlot(), QgsComposerMap::containsAdvancedEffects(), QgsComposerMap::containsWMSLayer(), QgsOfflineEditing::convertToOfflineProject(), QgsOfflineEditing::copyVectorLayer(), QgsValueRelationWidget::createCache(), QgsRelation::createFromXML(), QgsAttributeTypeLoadDialog::createPreview(), CustomLayerOrderModel::data(), QgsDxfPalLabeling::drawLabel(), QgsMapRendererJob::drawOldLabeling(), QgsLegendRenderer::drawSymbolItem(), QgsApplication::exitQgis(), QgsAttributeTypeLoadDialog::fillComboBoxes(), QgsAttributeTypeLoadDialog::fillLayerList(), QgsMapSettings::fullExtent(), QgsMapToolIdentify::handleMenuHover(), QgsMapToolIdentify::identify(), QgsApplication::initQgis(), QgsMapCanvas::layer(), QgsMapCanvas::layers(), QgsAttributeTypeLoadDialog::loadDataToValueMap(), QgsVectorLayer::maximumValue(), QgsVectorLayer::minimumValue(), QgsMapRendererJob::prepareJobs(), QgsVectorLayerFeatureIterator::prepareJoins(), QgsComposerAttributeTable::QgsComposerAttributeTable(), QgsLayerTreeLayer::QgsLayerTreeLayer(), QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge(), QgsLegendModel::QgsLegendModel(), QgsMapLayerModel::QgsMapLayerModel(), QgsOfflineEditing::QgsOfflineEditing(), QgsRelationManager::QgsRelationManager(), QgsVectorLayer::QgsVectorLayer(), QgsFormAnnotationItem::readXML(), QgsHtmlAnnotationItem::readXML(), QgsLayerTreeLayer::readXML(), QgsComposerAttributeTable::readXML(), QgsAtlasComposition::readXML(), QgsVectorLayer::readXml(), QgsMapCanvas::refreshMap(), QgsLayerTreeLayer::registryLayersAdded(), QgsLegendModel::removeLayer(), QgsLayerTreeRegistryBridge::removeLayersFromRegistry(), QgsPluginLayerRegistry::removePluginLayerType(), QgsMapRenderer::render(), QgsLegendModel::setAutoUpdate(), QgsMapRendererCache::setCacheImage(), QgsValueRelationConfigDlg::setConfig(), QgsVectorLayer::setDataProvider(), QgsComposerLayerItem::setDefaultStyle(), QgsLegendModel::setLayerSet(), QgsMapCanvasSnapper::snapToBackgroundLayers(), QgsPalLabeling::staticWillUseLayer(), QgsOfflineEditing::synchronize(), QgsComposerMap::syncLayerSet(), QgsVectorLayer::uniqueValues(), QgsMapCanvas::updateDatumTransformEntries(), QgsVectorLayerJoinBuffer::updateFields(), QgsMapRenderer::updateFullExtent(), QgsLegendModel::updateLayer(), QgsMapRendererJob::updateLayerGeometryCaches(), QgsLegendModel::updateLayerItemText(), QgsLegendModel::updateRasterSymbolItemText(), QgsRelation::updateRelationStatus(), QgsLegendModel::updateSymbolV2ItemText(), QgsProject::write(), and QgsLayerTreeViewDefaultActions::zoomToGroup().

void QgsMapLayerRegistry::layerRemoved ( QString  theLayerId)
signal

Emitted after a layer was removed from the registry.

Parameters
theLayerIdThe id of the layer removed
Note
Consider using layersRemoved() instead

Referenced by removeMapLayers().

void QgsMapLayerRegistry::layersAdded ( QList< QgsMapLayer * >  theMapLayers)
signal

Emitted when one or more layers are added to the registry.

This signal is also emitted for layers added to the registry, but not to the legend and canvas.

Parameters
theMapLayersThe layers which have been added
See also
legendLayersAdded()

Referenced by addMapLayers().

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

Referenced by removeMapLayers().

void QgsMapLayerRegistry::layersWillBeRemoved ( QStringList  theLayerIds)
signal

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

Parameters
theLayerIdsA list of ids of the layers which are removed.

Referenced by removeMapLayers().

void QgsMapLayerRegistry::layerWasAdded ( QgsMapLayer theMapLayer)
signal

Emitted when a layer is added to the registry.

Parameters
theMapLayerThe id of the layer which has been added
Note
Consider using layersAdded() instead

Referenced by addMapLayers().

void QgsMapLayerRegistry::layerWillBeRemoved ( QString  theLayerId)
signal

Emitted when a layer is removed from the registry.

Parameters
theLayerIdThe id of the layer being removed
Note
Consider using layersWillBeRemoved() instead

Referenced by removeMapLayers().

void QgsMapLayerRegistry::legendLayersAdded ( QList< QgsMapLayer * >  theMapLayers)
signal

Emitted, when a layer is added to the registry and the legend.

Plugins are allowed to have private layers, which are signalled by layersAdded() and layerWasAdded() but will not be advertised by this signal.

Parameters
theMapLayersThe QgsMapLayers which are added to the legend.
Note
Added in 2.0

Referenced by addMapLayers().

QgsMapLayer * QgsMapLayerRegistry::mapLayer ( QString  theLayerId)

Retrieve a pointer to a loaded layer by id.

Definition at line 55 of file qgsmaplayerregistry.cpp.

References mMapLayers.

Referenced by QgsLayerTreeLayer::attachToLayer(), QgsGeometry::avoidIntersections(), QgsVectorLayerJoinBuffer::cacheJoinLayer(), QgsMapRendererCache::clearCacheImage(), QgsMapRendererCache::clearInternal(), QgsOfflineEditing::committedFeaturesAdded(), QgsComposerMap::containsAdvancedEffects(), QgsComposerMap::containsWMSLayer(), QgsOfflineEditing::convertToOfflineProject(), QgsValueRelationWidget::createCache(), QgsAttributeTypeLoadDialog::createPreview(), CustomLayerOrderModel::data(), QgsDxfPalLabeling::drawLabel(), QgsMapRendererJob::drawOldLabeling(), QgsLegendRenderer::drawSymbolItem(), QgsAttributeTypeLoadDialog::fillComboBoxes(), QgsMapSettings::fullExtent(), QgsMapToolIdentify::handleMenuHover(), QgsMapToolIdentify::identify(), QgsMapCanvas::layer(), QgsMapCanvas::layers(), QgsAttributeTypeLoadDialog::loadDataToValueMap(), QgsVectorLayer::maximumValue(), QgsVectorLayer::minimumValue(), QgsMapRendererJob::prepareJobs(), QgsVectorLayerFeatureIterator::prepareJoins(), QgsFormAnnotationItem::readXML(), QgsHtmlAnnotationItem::readXML(), QgsLayerTreeLayer::readXML(), QgsComposerAttributeTable::readXML(), QgsLegendModel::removeLayer(), QgsMapRenderer::render(), QgsLegendModel::setAutoUpdate(), QgsMapRendererCache::setCacheImage(), QgsValueRelationConfigDlg::setConfig(), QgsComposerLayerItem::setDefaultStyle(), QgsLegendModel::setLayerSet(), QgsMapCanvasSnapper::snapToBackgroundLayers(), QgsPalLabeling::staticWillUseLayer(), QgsVectorLayer::uniqueValues(), QgsMapCanvas::updateDatumTransformEntries(), QgsVectorLayerJoinBuffer::updateFields(), QgsMapRenderer::updateFullExtent(), QgsLegendModel::updateLayer(), QgsLegendModel::updateLayerItemText(), QgsLegendModel::updateRasterSymbolItemText(), QgsLegendModel::updateSymbolV2ItemText(), and QgsLayerTreeViewDefaultActions::zoomToGroup().

const QMap< QString, QgsMapLayer * > & QgsMapLayerRegistry::mapLayers ( )
QList< QgsMapLayer * > QgsMapLayerRegistry::mapLayersByName ( QString  layerName)

Retrieve a pointer to a loaded layer by name.

Definition at line 60 of file qgsmaplayerregistry.cpp.

References mMapLayers, and QgsMapLayer::name().

void QgsMapLayerRegistry::reloadAllLayers ( )

Reload all provider data caches (currently used for WFS and WMS providers)

Note
Added in QGIS 1.6

Definition at line 158 of file qgsmaplayerregistry.cpp.

References mMapLayers, and QgsMapLayer::reload().

void QgsMapLayerRegistry::removeAll ( )
signal

Emitted, when all layers are removed, before layersWillBeRemoved() and layerWillBeRemoved() signals are emitted.

You will still get these signals in any case. You can use this signal to do easy (and fast) cleanup.

Note
Added in 2.0

Referenced by removeAllMapLayers().

void QgsMapLayerRegistry::removeAllMapLayers ( )

Remove all registered layers.

Note
As a side-effect QgsProject is made dirty.
The layers are deleted as the registry is cleared!

Definition at line 145 of file qgsmaplayerregistry.cpp.

References mMapLayers, removeAll(), and removeMapLayers().

Referenced by ~QgsMapLayerRegistry().

void QgsMapLayerRegistry::removeMapLayer ( const QString &  theLayerId)

Remove a layer from qgis.

Any canvases using the affected layers will need to remove them

The layer being removed is deleted as well as the registry table entry.

Parameters
theLayerIdThe id of the layer to remove
Note
As a side-effect QgsProject is made dirty.

Definition at line 140 of file qgsmaplayerregistry.cpp.

References removeMapLayers().

void QgsMapLayerRegistry::removeMapLayers ( QStringList  theLayerIds)

Remove a set of layers from the registry.

Any canvases using the affected layers will need to remove them

The layers being removed are deleted as well as the registry table entries.

Parameters
theLayerIdsThe ids of the layers to remove
Note
As a side-effect QgsProject is made dirty.

Definition at line 121 of file qgsmaplayerregistry.cpp.

References layerRemoved(), layersRemoved(), layersWillBeRemoved(), layerWillBeRemoved(), mMapLayers, and mOwnedLayers.

Referenced by QgsOfflineEditing::copyVectorLayer(), removeAllMapLayers(), QgsLayerTreeRegistryBridge::removeLayersFromRegistry(), removeMapLayer(), QgsPluginLayerRegistry::removePluginLayerType(), and QgsOfflineEditing::synchronize().

Member Data Documentation

QgsMapLayerRegistry * QgsMapLayerRegistry::mInstance = 0
staticprivate

Definition at line 251 of file qgsmaplayerregistry.h.

Referenced by instance().

QMap<QString, QgsMapLayer*> QgsMapLayerRegistry::mMapLayers
private
QSet<QgsMapLayer*> QgsMapLayerRegistry::mOwnedLayers
private

Definition at line 253 of file qgsmaplayerregistry.h.

Referenced by addMapLayers(), and removeMapLayers().


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