mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
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:
parent
109fcc0abc
commit
22c22e8e5c
@ -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
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user