Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
remove more redundancy in qgsproject
  • Loading branch information
mhugent committed May 31, 2011
1 parent 017db9c commit e3197a6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -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 )
Expand Down
28 changes: 17 additions & 11 deletions src/core/qgsproject.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1004,6 +1011,7 @@ bool QgsProject::read( QDomNode & layerNode )
}

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


Expand Down Expand Up @@ -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");
Expand All @@ -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" )
Expand Down Expand Up @@ -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*/ )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsproject.h
Expand Up @@ -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:

Expand Down

0 comments on commit e3197a6

Please sign in to comment.