mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-07 00:15:48 -04:00
Replace paths pointing to inbuilt data folder with "inbuilt:" prefix
during project write, and redirect paths beginning with "inbuilt:" prefix to actual local install folder during project read Allows projects using data like the built-in world map layer to work correctly across different installs
This commit is contained in:
parent
f578216919
commit
10c5b2f9db
@ -16,7 +16,7 @@
|
||||
#include "qgspathresolver.h"
|
||||
|
||||
#include "qgis.h"
|
||||
|
||||
#include "qgsapplication.h"
|
||||
#include <QFileInfo>
|
||||
#include <QUrl>
|
||||
#include <QUuid>
|
||||
@ -40,6 +40,11 @@ QString QgsPathResolver::readPath( const QString &f ) const
|
||||
return QString();
|
||||
|
||||
QString src = filename;
|
||||
if ( src.startsWith( QLatin1String( "inbuilt:" ) ) )
|
||||
{
|
||||
// strip away "inbuilt:" prefix, replace with actual inbuilt data folder path
|
||||
return QgsApplication::pkgDataPath() + QStringLiteral( "/resources" ) + src.mid( 8 );
|
||||
}
|
||||
|
||||
if ( mBaseFileName.isNull() )
|
||||
{
|
||||
@ -168,7 +173,18 @@ bool QgsPathResolver::removePathPreprocessor( const QString &id )
|
||||
|
||||
QString QgsPathResolver::writePath( const QString &src ) const
|
||||
{
|
||||
if ( mBaseFileName.isEmpty() || src.isEmpty() )
|
||||
if ( src.isEmpty() )
|
||||
{
|
||||
return src;
|
||||
}
|
||||
|
||||
if ( src.startsWith( QgsApplication::pkgDataPath() + QStringLiteral( "/resources" ) ) )
|
||||
{
|
||||
// replace inbuilt data folder path with "inbuilt:" prefix
|
||||
return QStringLiteral( "inbuilt:" ) + src.mid( QgsApplication::pkgDataPath().length() + 10 );
|
||||
}
|
||||
|
||||
if ( mBaseFileName.isEmpty() )
|
||||
{
|
||||
return src;
|
||||
}
|
||||
|
@ -15,7 +15,12 @@ import qgis # NOQA
|
||||
import tempfile
|
||||
import os
|
||||
import gc
|
||||
from qgis.core import QgsPathResolver, QgsVectorLayer, QgsProject
|
||||
from qgis.core import (
|
||||
QgsPathResolver,
|
||||
QgsVectorLayer,
|
||||
QgsProject,
|
||||
QgsApplication
|
||||
)
|
||||
from qgis.testing import start_app, unittest
|
||||
from utilities import unitTestDataPath
|
||||
|
||||
@ -130,6 +135,15 @@ class TestQgsPathResolver(unittest.TestCase):
|
||||
# layer should have correct path now
|
||||
self.assertTrue(l.isValid())
|
||||
|
||||
def testInbuiltPath(self):
|
||||
"""
|
||||
Test resolving and saving inbuilt data paths
|
||||
"""
|
||||
path = "inbuilt:/data/world_map.shp"
|
||||
self.assertEqual(QgsPathResolver().readPath(path), QgsApplication.pkgDataPath() + '/resources/data/world_map.shp')
|
||||
|
||||
self.assertEqual(QgsPathResolver().writePath(QgsApplication.pkgDataPath() + '/resources/data/world_map.shp'), 'inbuilt:/data/world_map.shp')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user