Skip to content
Permalink
Browse files

Seriously, I thought I told ya ta shuddup already, right?

(cherry-picked from 8f9a378)
  • Loading branch information
nyalldawson committed May 3, 2018
1 parent 1b26316 commit ca553eaee3c9861bf05038fd7167fb37dcd730c8
@@ -614,16 +614,20 @@ Return a list of all available svg files
Return a list of svg files at the specified directory
%End

static QString svgSymbolNameToPath( QString name, const QgsPathResolver &pathResolver );
static QString svgSymbolNameToPath( const QString &name, const QgsPathResolver &pathResolver );
%Docstring
Get SVG symbol's path from its name.
If the name is not absolute path the file is searched in SVG paths specified
Determines an SVG symbol's path from its ``name``.
If ``name`` is not an absolute path the file is scanned for in the SVG paths specified
in settings svg/searchPathsForSVG.

.. seealso:: :py:func:`svgSymbolPathToName`
%End

static QString svgSymbolPathToName( QString path, const QgsPathResolver &pathResolver );
static QString svgSymbolPathToName( const QString &path, const QgsPathResolver &pathResolver );
%Docstring
Get SVG symbols's name from its path
Determines an SVG symbol's name from its ``path``.

.. seealso:: :py:func:`svgSymbolNameToPath`
%End

static QPointF polygonCentroid( const QPolygonF &points );
@@ -3653,15 +3653,16 @@ QStringList QgsSymbolLayerUtils::listSvgFilesAt( const QString &directory )

}

QString QgsSymbolLayerUtils::svgSymbolNameToPath( QString name, const QgsPathResolver &pathResolver )
QString QgsSymbolLayerUtils::svgSymbolNameToPath( const QString &n, const QgsPathResolver &pathResolver )
{
if ( name.isEmpty() )
if ( n.isEmpty() )
return QString();

// we might have a full path...
if ( QFileInfo::exists( name ) )
return QFileInfo( name ).canonicalFilePath();
if ( QFileInfo::exists( n ) )
return QFileInfo( n ).canonicalFilePath();

QString name = n;
// or it might be an url...
if ( name.contains( QLatin1String( "://" ) ) )
{
@@ -3715,12 +3716,15 @@ QString QgsSymbolLayerUtils::svgSymbolNameToPath( QString name, const QgsPathRes
return pathResolver.readPath( name );
}

QString QgsSymbolLayerUtils::svgSymbolPathToName( QString path, const QgsPathResolver &pathResolver )
QString QgsSymbolLayerUtils::svgSymbolPathToName( const QString &p, const QgsPathResolver &pathResolver )
{
if ( !QFileInfo::exists( path ) )
return path;
if ( p.isEmpty() )
return QString();

if ( !QFileInfo::exists( p ) )
return p;

path = QFileInfo( path ).canonicalFilePath();
QString path = QFileInfo( p ).canonicalFilePath();

QStringList svgPaths = QgsApplication::svgPaths();

@@ -563,14 +563,18 @@ class CORE_EXPORT QgsSymbolLayerUtils
static QStringList listSvgFilesAt( const QString &directory );

/**
* Get SVG symbol's path from its name.
* If the name is not absolute path the file is searched in SVG paths specified
* in settings svg/searchPathsForSVG.
* Determines an SVG symbol's path from its \a name.
* If \a name is not an absolute path the file is scanned for in the SVG paths specified
* in settings svg/searchPathsForSVG.
* \see svgSymbolPathToName()
*/
static QString svgSymbolNameToPath( QString name, const QgsPathResolver &pathResolver );
static QString svgSymbolNameToPath( const QString &name, const QgsPathResolver &pathResolver );

//! Get SVG symbols's name from its path
static QString svgSymbolPathToName( QString path, const QgsPathResolver &pathResolver );
/**
* Determines an SVG symbol's name from its \a path.
* \see svgSymbolNameToPath()
*/
static QString svgSymbolPathToName( const QString &path, const QgsPathResolver &pathResolver );

//! Calculate the centroid point of a QPolygonF
static QPointF polygonCentroid( const QPolygonF &points );
@@ -212,6 +212,7 @@ void TestQgsProject::testPathResolverSvg()
QString layerPath = dataDir + "/points.shp";

QVERIFY( QgsSymbolLayerUtils::svgSymbolNameToPath( QString(), QgsPathResolver() ).isEmpty() );
QVERIFY( QgsSymbolLayerUtils::svgSymbolPathToName( QString(), QgsPathResolver() ).isEmpty() );

// build a project with 3 layers, each having a simple renderer with SVG marker
// - existing SVG file in project dir
@@ -235,6 +236,7 @@ void TestQgsProject::testPathResolverSvg()
QVERIFY( QFileInfo::exists( ourSvgPath ) ); // should exist now

QString librarySvgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( QStringLiteral( "transport/transport_airport.svg" ), QgsPathResolver() );
QCOMPARE( QgsSymbolLayerUtils::svgSymbolPathToName( librarySvgPath, QgsPathResolver() ), QStringLiteral( "transport/transport_airport.svg" ) );

QgsVectorLayer *layer1 = new QgsVectorLayer( layerPath, QStringLiteral( "points 1" ), QStringLiteral( "ogr" ) );
_useRendererWithSvgSymbol( layer1, ourSvgPath );

0 comments on commit ca553ea

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