34 return mMapLayers.size();
40 const QList<QgsMapLayer *> cLayers = mMapLayers.values();
41 for (
const auto l : cLayers )
51 return mMapLayers.value( layerId );
56 QList<QgsMapLayer *> myResultList;
57 const auto constMMapLayers = mMapLayers;
60 if ( layer->name() == layerName )
62 myResultList << layer;
70 QList<QgsMapLayer *> myResultList;
71 const auto constLayers =
layers;
76 QgsDebugMsg( QStringLiteral(
"Cannot add null layers" ) );
80 if ( mMapLayers.contains( myLayer->id() ) && ! mMapLayers[myLayer->id()]->isValid() && myLayer->isValid() && myLayer->dataProvider() )
82 mMapLayers[myLayer->id()]->setDataSource( myLayer->dataProvider()->dataSourceUri(), myLayer->name(), myLayer->providerType(),
QgsDataProvider::ProviderOptions() );
85 if ( !mMapLayers.contains( myLayer->id() ) )
87 mMapLayers[myLayer->id()] = myLayer;
88 myResultList << mMapLayers[myLayer->id()];
91 myLayer->setParent(
this );
93 connect( myLayer, &QObject::destroyed,
this, &QgsMapLayerStore::onMapLayerDeleted );
97 if ( !myResultList.isEmpty() )
107 QList<QgsMapLayer *> addedLayers;
108 addedLayers =
addMapLayers( QList<QgsMapLayer *>() << layer, takeOwnership );
109 return addedLayers.isEmpty() ? nullptr : addedLayers[0];
114 QList<QgsMapLayer *>
layers;
115 const auto constLayerIds = layerIds;
116 for (
const QString &myId : constLayerIds )
118 layers << mMapLayers.value( myId );
129 QStringList layerIds;
130 QList<QgsMapLayer *> layerList;
132 const auto constLayers =
layers;
136 if ( layer && mMapLayers.contains( layer->id() ) )
138 layerIds << layer->id();
143 if ( layerIds.isEmpty() )
149 const auto constLayerList = layerList;
152 QString myId( lyr->id() );
155 mMapLayers.remove( myId );
156 if ( lyr->parent() ==
this )
168 removeMapLayers( QList<QgsMapLayer *>() << mMapLayers.value( layerId ) );
182 if ( mMapLayers.contains( layer->
id() ) )
189 mMapLayers.remove( layer->
id() );
190 layer->setParent(
nullptr );
209 if ( !other || other ==
this )
212 Q_ASSERT_X( other->thread() == thread(),
"QgsMapLayerStore::transferLayersFromStore",
"Cannot transfer layers from store with different thread affinity" );
214 QMap<QString, QgsMapLayer *> otherLayers = other->
mapLayers();
215 QMap<QString, QgsMapLayer *>::const_iterator it = otherLayers.constBegin();
216 for ( ; it != otherLayers.constEnd(); ++it )
224 void QgsMapLayerStore::onMapLayerDeleted( QObject *obj )
226 QString
id = mMapLayers.key(
static_cast<QgsMapLayer *
>( obj ) );
230 QgsDebugMsg( QStringLiteral(
"Map layer deleted without unregistering! %1" ).arg(
id ) );
231 mMapLayers.remove(
id );
242 QMap<QString, QgsMapLayer *> validLayers;
243 for (
const auto &
id : mMapLayers.keys() )
245 if ( mMapLayers[
id]->isValid() )
246 validLayers[id] = mMapLayers[id];