foreach ( QgsMapLayer* l, layers ) { if ( l->id() == mLayerId ) { mLayer = l; disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) ); emit layerLoaded(); break; } }
Q_FOREACH ( QgsMapLayer* l, layers ) { if ( l->id() == mLayerId ) { disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layersAdded( QList<QgsMapLayer*> ) ), this, SLOT( registryLayersAdded( QList<QgsMapLayer*> ) ) ); attachToLayer(); emit layerLoaded(); break; } }
/** Read map layers from project file @returns \code QPair< bool, QList<QDomNode> > \endcode bool is true if function worked; else is false. list contains nodes corresponding to layers that couldn't be loaded @note XML of form: \verbatim <maplayer type="vector"> <layername>Hydrop</layername> <datasource>/data/usgs/city_shp/hydrop.shp</datasource> <zorder>0</zorder> <provider>ogr</provider> <singlesymbol> <renderitem> <value>blabla</value> <symbol> <outlinecolor red="85" green="0" blue="255" /> <outlinestyle>SolidLine</outlinestyle> <outlinewidth>1</outlinewidth> <fillcolor red="0" green="170" blue="255" /> <fillpattern>SolidPattern</fillpattern> </symbol> <label>blabla</label> </renderitem> </singlesymbol> <label>0</label> <labelattributes> <label text="Label" field="" /> <family name="Sans Serif" field="" /> <size value="12" units="pt" field="" /> <bold on="0" field="" /> <italic on="0" field="" /> <underline on="0" field="" /> <color red="0" green="0" blue="0" field="" /> <x field="" /> <y field="" /> <offset units="pt" x="0" xfield="" y="0" yfield="" /> <angle value="0" field="" /> <alignment value="center" field="" /> </labelattributes> </maplayer> \endverbatim */ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &doc ) { // Layer order is set by the restoring the legend settings from project file. // This is done on the 'readProject( ... )' signal QDomNodeList nl = doc.elementsByTagName( "maplayer" ); // XXX what is this used for? QString layerCount( QString::number(nl.count()) ); QString wk; QList<QDomNode> brokenNodes; // a list of Dom nodes corresponding to layers // that we were unable to load; this could be // because the layers were removed or // re-located after the project was last saved // process the map layer nodes if ( 0 == nl.count() ) // if we have no layers to process, bail { return qMakePair( true, brokenNodes ); // Decided to return "true" since it's // possible for there to be a project with no // layers; but also, more imporantly, this // would cause the tests/qgsproject to fail // since the test suite doesn't currently // support test layers } bool returnStatus = true; emit layerLoaded( 0, nl.count() ); //Collect vector layers with joins. //They need to refresh join caches and symbology infos after all layers are loaded QList< QPair< QgsVectorLayer*, QDomElement > > vLayerList; for ( int i = 0; i < nl.count(); i++ ) { QDomNode node = nl.item( i ); QDomElement element = node.toElement(); if ( element.attribute( "embedded" ) == "1" ) { createEmbeddedLayer( element.attribute( "id" ), readPath( element.attribute( "project" ) ), brokenNodes, vLayerList ); continue; } else { if ( !addLayer( element, brokenNodes, vLayerList ) ) { returnStatus = false; } } emit layerLoaded( i + 1, nl.count() ); } //Update field map of layers with joins and create join caches if necessary //Needs to be done here once all dependent layers are loaded QList< QPair< QgsVectorLayer*, QDomElement > >::iterator vIt = vLayerList.begin(); for ( ; vIt != vLayerList.end(); ++vIt ) { vIt->first->createJoinCaches(); vIt->first->updateFields(); } return qMakePair( returnStatus, brokenNodes ); } // _getMapLayers