Strip file:// from local files path before resolving

Fixes #21150 - Delimitedtext layer saves absolute path
when project in relative path mode
This commit is contained in:
Alessandro Pasotti 2019-02-05 08:29:38 +01:00
parent 109fcc0abc
commit 22c22e8e5c
2 changed files with 22 additions and 1 deletions

View File

@ -163,7 +163,8 @@ QString QgsPathResolver::writePath( const QString &src ) const
return src;
}
QFileInfo srcFileInfo( src );
// Strip "file://"
QFileInfo srcFileInfo( src.startsWith( QStringLiteral( "file://" ) ) ? src.mid( 7 ) : src );
QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src;
// if this is a VSIFILE, remove the VSI prefix and append to final result

View File

@ -41,6 +41,7 @@ class TestQgsProject : public QObject
void testProjectUnits();
void variablesChanged();
void testLayerFlags();
void testLocalFiles();
};
void TestQgsProject::init()
@ -386,6 +387,25 @@ void TestQgsProject::testLayerFlags()
QVERIFY( !layer->flags().testFlag( QgsMapLayer::Removable ) );
}
void TestQgsProject::testLocalFiles()
{
QTemporaryFile f;
QVERIFY( f.open() );
f.close();
QgsProject prj;
QFileInfo info( f.fileName() );
prj.setFileName( f.fileName() );
prj.write();
QString shpPath = info.dir().path() + '/' + info.baseName() + ".shp";
QString layerPath = "file://" + shpPath;
QFile f2( shpPath );
QVERIFY( f2.open( QFile::ReadWrite ) );
f2.close();
QgsPathResolver resolver( f.fileName( ) );
QCOMPARE( resolver.writePath( layerPath ), QString( "./" + info.baseName() + ".shp" ) ) ;
}
QGSTEST_MAIN( TestQgsProject )
#include "testqgsproject.moc"