|
18 | 18 | #include "qgsprojectparser.h" |
19 | 19 | #include "qgsconfigcache.h" |
20 | 20 | #include "qgscrscache.h" |
| 21 | +#include "qgsdatasourceuri.h" |
21 | 22 | #include "qgsmslayercache.h" |
22 | 23 | #include "qgslogger.h" |
23 | 24 | #include "qgsmapserviceexception.h" |
@@ -773,18 +774,36 @@ QgsMapLayer* QgsProjectParser::createLayerFromElement( const QDomElement& elem, |
773 | 774 | return 0; |
774 | 775 | } |
775 | 776 |
|
776 | | - QString uri; |
777 | | - QString absoluteUri; |
778 | 777 | QDomElement dataSourceElem = elem.firstChildElement( "datasource" ); |
| 778 | + QString uri = dataSourceElem.text(); |
| 779 | + QString absoluteUri; |
779 | 780 | if ( !dataSourceElem.isNull() ) |
780 | 781 | { |
781 | 782 | //convert relative pathes to absolute ones if necessary |
782 | | - uri = dataSourceElem.text(); |
783 | | - absoluteUri = convertToAbsolutePath( uri ); |
784 | | - if ( uri != absoluteUri ) |
| 783 | + if ( uri.startsWith( "dbname" ) ) //database |
| 784 | + { |
| 785 | + QgsDataSourceURI dsUri( uri ); |
| 786 | + if ( dsUri.host().isEmpty() ) //only convert path for file based databases |
| 787 | + { |
| 788 | + QString dbnameUri = dsUri.database(); |
| 789 | + QString dbNameUriAbsolute = convertToAbsolutePath( dbnameUri ); |
| 790 | + if ( dbnameUri != dbNameUriAbsolute ) |
| 791 | + { |
| 792 | + dsUri.setDatabase( dbNameUriAbsolute ); |
| 793 | + absoluteUri = dsUri.uri(); |
| 794 | + QDomText absoluteTextNode = mXMLDoc->createTextNode( absoluteUri ); |
| 795 | + dataSourceElem.replaceChild( absoluteTextNode, dataSourceElem.firstChild() ); |
| 796 | + } |
| 797 | + } |
| 798 | + } |
| 799 | + else //file based data source |
785 | 800 | { |
786 | | - QDomText absoluteTextNode = mXMLDoc->createTextNode( absoluteUri ); |
787 | | - dataSourceElem.replaceChild( absoluteTextNode, dataSourceElem.firstChild() ); |
| 801 | + absoluteUri = convertToAbsolutePath( uri ); |
| 802 | + if ( uri != absoluteUri ) |
| 803 | + { |
| 804 | + QDomText absoluteTextNode = mXMLDoc->createTextNode( absoluteUri ); |
| 805 | + dataSourceElem.replaceChild( absoluteTextNode, dataSourceElem.firstChild() ); |
| 806 | + } |
788 | 807 | } |
789 | 808 | } |
790 | 809 |
|
|
0 commit comments