26 QgsMapLayerRegistry::QgsMapLayerRegistry( QObject *parent ) : QObject( parent )
39 return mMapLayers.size();
44 return mMapLayers.value( theLayerId );
49 QList<QgsMapLayer *> myResultList;
52 if ( layer->
name() == layerName )
54 myResultList << layer;
62 QList<QgsMapLayer *> theMapLayers,
66 QList<QgsMapLayer *> myResultList;
67 for (
int i = 0; i < theMapLayers.size(); ++i )
70 if ( !myLayer || !myLayer->
isValid() )
76 if ( !mMapLayers.contains( myLayer->
id() ) )
78 mMapLayers[myLayer->
id()] = myLayer;
79 myResultList << mMapLayers[myLayer->
id()];
81 mOwnedLayers << myLayer;
82 emit layerWasAdded( myLayer );
85 if ( myResultList.count() > 0 )
87 emit layersAdded( myResultList );
90 emit legendLayersAdded( myResultList );
101 QList<QgsMapLayer *> addedLayers;
102 addedLayers = addMapLayers( QList<QgsMapLayer*>() << theMapLayer, addToLegend, takeOwnership );
103 return addedLayers.isEmpty() ? 0 : addedLayers[0];
110 emit layersWillBeRemoved( theLayerIds );
112 foreach (
const QString &myId, theLayerIds )
115 if ( mOwnedLayers.contains( lyr ) )
117 emit layerWillBeRemoved( myId );
119 mOwnedLayers.remove( lyr );
121 mMapLayers.remove( myId );
122 emit layerRemoved( myId );
124 emit layersRemoved( theLayerIds );
129 removeMapLayers( QStringList( theLayerId ) );
137 removeMapLayers( mMapLayers.keys() );
147 QMap<QString, QgsMapLayer *>::iterator it;
148 for ( it = mMapLayers.begin(); it != mMapLayers.end() ; ++it )
165 void QgsMapLayerRegistry::connectNotify(
const char * signal )
Base class for all map layer types.
void removeMapLayer(const QString &theLayerId)
Remove a layer from qgis.
virtual void reload()
Synchronises with changes in the datasource.
void removeAllMapLayers()
Remove all registered layers.
const QString & name() const
Get the display name of the layer.
QList< QgsMapLayer * > addMapLayers(QList< QgsMapLayer * > theMapLayers, bool addToLegend=true, bool takeOwnership=true)
Add a list of layers to the map of loaded layers.
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
QList< QgsMapLayer * > mapLayersByName(QString layerName)
Retrieve a pointer to a loaded layer by name.
int count()
Return the number of registered layers.
void removeMapLayers(QStringList theLayerIds)
Remove a set of layers from the registry.
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
Q_DECL_DEPRECATED void clearAllLayerCaches()
Clears all layer caches, resetting them to zero and freeing up any memory they may have been using...
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
QgsMapLayer * addMapLayer(QgsMapLayer *theMapLayer, bool addToLegend=true, bool takeOwnership=true)
Add a layer to the map of loaded layers.
void reloadAllLayers()
Reload all provider data caches (currently used for WFS and WMS providers)