Skip to content
Permalink
Browse files

Merge pull request #9273 from elpaso/bugfix-fix-path-resolver-urls

fix path resolver urls
  • Loading branch information
elpaso committed Feb 25, 2019
2 parents 29b952d + 84e903c commit a3e37420c8af827855ecba896e27e66453cf1d19
@@ -17,7 +17,7 @@ The QgsDefaultValue class provides a container for managing client
side default values for fields.

A QgsDefaultValue consists of an expression string that will be evaluated
on the client when a defeault field value needs to be generated.
on the client when a default field value needs to be generated.

Usual values for such an expression are

@@ -30,7 +30,7 @@
* side default values for fields.
*
* A QgsDefaultValue consists of an expression string that will be evaluated
* on the client when a defeault field value needs to be generated.
* on the client when a default field value needs to be generated.
*
* Usual values for such an expression are
*
@@ -18,6 +18,7 @@
#include "qgis.h"

#include <QFileInfo>
#include <QUrl>


QgsPathResolver::QgsPathResolver( const QString &baseFileName )
@@ -163,9 +164,20 @@ QString QgsPathResolver::writePath( const QString &src ) const
return src;
}

// Strip "file://"
QFileInfo srcFileInfo( src.startsWith( QStringLiteral( "file://" ) ) ? src.mid( 7 ) : src );
QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src;
// Check if it is a publicSource uri and clean it
QUrl url { src };
QString srcPath { src };
QString urlQuery;

if ( url.isLocalFile( ) )
{
srcPath = url.path();
urlQuery = url.query();
}

QFileInfo srcFileInfo( srcPath );
if ( srcFileInfo.exists() )
srcPath = srcFileInfo.canonicalFilePath();

// if this is a VSIFILE, remove the VSI prefix and append to final result
QString vsiPrefix = qgsVsiPrefix( src );
@@ -233,5 +245,12 @@ QString QgsPathResolver::writePath( const QString &src ) const
srcElems.insert( 0, QStringLiteral( "." ) );
}

return vsiPrefix + srcElems.join( QStringLiteral( "/" ) );
// Append url query if any
QString returnPath { vsiPrefix + srcElems.join( QStringLiteral( "/" ) ) };
if ( ! urlQuery.isEmpty() )
{
returnPath.append( '?' );
returnPath.append( urlQuery );
}
return returnPath;
}
@@ -42,6 +42,7 @@ class TestQgsProject : public QObject
void variablesChanged();
void testLayerFlags();
void testLocalFiles();
void testLocalUrlFiles();
};

void TestQgsProject::init()
@@ -406,6 +407,26 @@ void TestQgsProject::testLocalFiles()

}

void TestQgsProject::testLocalUrlFiles()
{
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 extraStuff {"?someVar=someValue&someOtherVar=someOtherValue" };
QString layerPath = "file://" + shpPath + extraStuff;
QFile f2( shpPath );
QVERIFY( f2.open( QFile::ReadWrite ) );
f2.close();
QgsPathResolver resolver( f.fileName( ) );
QCOMPARE( resolver.writePath( layerPath ), QString( "./" + info.baseName() + ".shp" + extraStuff ) ) ;

}


QGSTEST_MAIN( TestQgsProject )
#include "testqgsproject.moc"

0 comments on commit a3e3742

Please sign in to comment.
You can’t perform that action at this time.