Skip to content
Permalink
Browse files

remove more redundancy in qgsproject

  • Loading branch information
mhugent committed Jun 8, 2011
1 parent 39fcdb7 commit d9c853fb19d6b6702550208f31a829ccc919f635
Showing with 23 additions and 13 deletions.
  1. +4 −1 src/app/qgisapp.cpp
  2. +17 −11 src/core/qgsproject.cpp
  3. +2 −1 src/core/qgsproject.h
@@ -5056,7 +5056,10 @@ void QgisApp::embedLayers()
//hardcoded for debugging
QString filepath="/home/marco/geodaten/projekte/composertest.qgs";
QString id="komb113320110516093016594";
QgsProject::instance()->createEmbeddedLayer( id, filepath );

QList<QDomNode> brokenNodes;
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;
QgsProject::instance()->createEmbeddedLayer( id, filepath, brokenNodes, vectorLayerList );
}

void QgisApp::setExtent( QgsRectangle theRect )
@@ -684,7 +684,10 @@ QPair< bool, QList<QDomNode> > QgsProject::_getMapLayers( QDomDocument const &do

if( element.attribute("embedded") == "1" )
{
createEmbeddedLayer( element.attribute( "id" ), readPath( element.attribute( "project" ) ) );
if( !createEmbeddedLayer( element.attribute( "id" ), readPath( element.attribute( "project" ) ), brokenNodes, vLayerList ) )
{
returnStatus = false;
}
continue;
}
else
@@ -960,6 +963,10 @@ bool QgsProject::read()

bool QgsProject::read( QDomNode & layerNode )
{
QList<QDomNode> brokenNodes;
QList< QPair< QgsVectorLayer*, QDomElement > > vectorLayerList;
return addLayer( layerNode.toElement(), brokenNodes, vectorLayerList );
#if 0
QString type = layerNode.toElement().attribute( "type" );

QgsMapLayer *mapLayer = NULL;
@@ -1004,6 +1011,7 @@ bool QgsProject::read( QDomNode & layerNode )
}

return true;
#endif //0
} // QgsProject::read( QDomNode & layerNode )


@@ -1617,24 +1625,24 @@ QString QgsProject::layerIsEmbedded( const QString& id ) const
return it.value();
};

QgsMapLayer* QgsProject::createEmbeddedLayer( const QString& layerId, const QString& projectFilePath )
bool QgsProject::createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList )
{
QFile projectFile( projectFilePath );
if( !projectFile.open( QIODevice::ReadOnly ) )
{
return 0;
return false;
}

QDomDocument projectDocument;
if( !projectDocument.setContent( &projectFile ) )
{
return 0;
return false;
}

QDomElement projectLayersElem = projectDocument.documentElement().firstChildElement("projectlayers");
if( projectLayersElem.isNull() )
{
return 0;
return false;
}

QDomNodeList mapLayerNodes = projectLayersElem.elementsByTagName("maplayer");
@@ -1645,12 +1653,8 @@ QgsMapLayer* QgsProject::createEmbeddedLayer( const QString& layerId, const QStr
QString id = mapLayerElem.firstChildElement("id").text();
if( id == layerId )
{
return addLayer( mapLayerElem, brokenNodes, vectorLayerList );
#if 0
if( !addLayer( element, brokenNodes, vLayerList ) )
{
returnStatus = false;
}
#endif //0
QString type = mapLayerElem.attribute("type");
QgsMapLayer* layer = 0;
if( type == "vector" )
@@ -1684,10 +1688,12 @@ QgsMapLayer* QgsProject::createEmbeddedLayer( const QString& layerId, const QStr
return 0;
}
return layer;
#endif //0
}
}

return 0;
//brokenNodes.push_back( );
return false;
}

void QgsProjectBadLayerDefaultHandler::handleBadLayers( QList<QDomNode> /*layers*/, QDomDocument /*projectDom*/ )
@@ -286,7 +286,8 @@ class CORE_EXPORT QgsProject : public QObject
/**Creates a maplayer instance defined in an arbitrary project file. Caller takes ownership
@return the layer or 0 in case of error
@note: added in version 1.8*/
static QgsMapLayer* createEmbeddedLayer( const QString& layerId, const QString& projectFilePath );
//static QgsMapLayer* createEmbeddedLayer( const QString& layerId, const QString& projectFilePath );
bool createEmbeddedLayer( const QString& layerId, const QString& projectFilePath, QList<QDomNode>& brokenNodes, QList< QPair< QgsVectorLayer*, QDomElement > >& vectorLayerList );

protected:

0 comments on commit d9c853f

Please sign in to comment.
You can’t perform that action at this time.