|
44 | 44 | #include <QObject>
|
45 | 45 | #include <QTextStream>
|
46 | 46 | #include <QDir>
|
| 47 | +#include <QUrl> |
47 | 48 |
|
48 | 49 | // canonical project instance
|
49 | 50 | QgsProject *QgsProject::theProject_ = 0;
|
@@ -1665,34 +1666,72 @@ bool QgsProject::createEmbeddedLayer( const QString &layerId, const QString &pro
|
1665 | 1666 | mEmbeddedLayers.insert( layerId, qMakePair( projectFilePath, saveFlag ) );
|
1666 | 1667 |
|
1667 | 1668 | // change datasource path from relative to absolute if necessary
|
| 1669 | + // see also QgsMapLayer::readLayerXML |
1668 | 1670 | if ( !useAbsolutePathes )
|
1669 | 1671 | {
|
1670 |
| - QDomElement provider = mapLayerElem.firstChildElement( "provider" ); |
1671 |
| - if ( provider.text() == "spatialite" ) |
| 1672 | + QString provider( mapLayerElem.firstChildElement( "provider" ).text() ); |
| 1673 | + QDomElement dsElem( mapLayerElem.firstChildElement( "datasource" ) ); |
| 1674 | + QString datasource( dsElem.text() ); |
| 1675 | + if ( provider == "spatialite" ) |
1672 | 1676 | {
|
1673 |
| - QDomElement dsElem = mapLayerElem.firstChildElement( "datasource" ); |
1674 |
| - |
1675 |
| - QgsDataSourceURI uri( dsElem.text() ); |
1676 |
| - |
| 1677 | + QgsDataSourceURI uri( datasource ); |
1677 | 1678 | QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + uri.database() );
|
1678 | 1679 | if ( absoluteDs.exists() )
|
1679 | 1680 | {
|
1680 | 1681 | uri.setDatabase( absoluteDs.absoluteFilePath() );
|
1681 |
| - dsElem.removeChild( dsElem.childNodes().at( 0 ) ); |
1682 |
| - dsElem.appendChild( projectDocument.createTextNode( uri.uri() ) ); |
| 1682 | + datasource = uri.uri(); |
| 1683 | + } |
| 1684 | + } |
| 1685 | + else if ( provider == "ogr" ) |
| 1686 | + { |
| 1687 | + QStringList theURIParts( datasource.split( "|" ) ); |
| 1688 | + QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + theURIParts[0] ); |
| 1689 | + if ( absoluteDs.exists() ) |
| 1690 | + { |
| 1691 | + theURIParts[0] = absoluteDs.absoluteFilePath(); |
| 1692 | + datasource = theURIParts.join( "|" ); |
| 1693 | + } |
| 1694 | + } |
| 1695 | + else if ( provider == "gpx" ) |
| 1696 | + { |
| 1697 | + QStringList theURIParts( datasource.split( "?" ) ); |
| 1698 | + QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + theURIParts[0] ); |
| 1699 | + if ( absoluteDs.exists() ) |
| 1700 | + { |
| 1701 | + theURIParts[0] = absoluteDs.absoluteFilePath(); |
| 1702 | + datasource = theURIParts.join( "?" ); |
| 1703 | + } |
| 1704 | + } |
| 1705 | + else if ( provider == "delimitedtext" ) |
| 1706 | + { |
| 1707 | + QUrl urlSource( QUrl::fromEncoded( datasource.toAscii() ) ); |
| 1708 | + |
| 1709 | + if ( !datasource.startsWith( "file:" ) ) |
| 1710 | + { |
| 1711 | + QUrl file( QUrl::fromLocalFile( datasource.left( datasource.indexOf( "?" ) ) ) ); |
| 1712 | + urlSource.setScheme( "file" ); |
| 1713 | + urlSource.setPath( file.path() ); |
| 1714 | + } |
| 1715 | + |
| 1716 | + QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + urlSource.toLocalFile() ); |
| 1717 | + if ( absoluteDs.exists() ) |
| 1718 | + { |
| 1719 | + QUrl urlDest = QUrl::fromLocalFile( absoluteDs.absoluteFilePath() ); |
| 1720 | + urlDest.setQueryItems( urlSource.queryItems() ); |
| 1721 | + datasource = QString::fromAscii( urlDest.toEncoded() ); |
1683 | 1722 | }
|
1684 | 1723 | }
|
1685 | 1724 | else
|
1686 | 1725 | {
|
1687 |
| - QDomElement dsElem = mapLayerElem.firstChildElement( "datasource" ); |
1688 |
| - QString debug( QFileInfo( projectFilePath ).absolutePath() + "/" + dsElem.text() ); |
1689 |
| - QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + dsElem.text() ); |
| 1726 | + QFileInfo absoluteDs( QFileInfo( projectFilePath ).absolutePath() + "/" + datasource ); |
1690 | 1727 | if ( absoluteDs.exists() )
|
1691 | 1728 | {
|
1692 |
| - dsElem.removeChild( dsElem.childNodes().at( 0 ) ); |
1693 |
| - dsElem.appendChild( projectDocument.createTextNode( absoluteDs.absoluteFilePath() ) ); |
| 1729 | + datasource = absoluteDs.absoluteFilePath(); |
1694 | 1730 | }
|
1695 | 1731 | }
|
| 1732 | + |
| 1733 | + dsElem.removeChild( dsElem.childNodes().at( 0 ) ); |
| 1734 | + dsElem.appendChild( projectDocument.createTextNode( datasource ) ); |
1696 | 1735 | }
|
1697 | 1736 |
|
1698 | 1737 | if ( addLayer( mapLayerElem, brokenNodes, vectorLayerList ) )
|
|
0 commit comments