mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-07 00:03:52 -05:00
Cache svg paths
Rebuilding them for each access from the settings is costly
This commit is contained in:
parent
54667e310d
commit
af709503d5
@ -281,6 +281,13 @@ Returns the path to the icons image directory.
|
||||
static QString srsDatabaseFilePath();
|
||||
%Docstring
|
||||
Returns the path to the srs.db file.
|
||||
%End
|
||||
|
||||
static void setSvgPaths( const QStringList &svgPaths );
|
||||
%Docstring
|
||||
Sets the paths to svg directories and invalidates the svg path list cache.
|
||||
|
||||
.. versionadded:: 3.18
|
||||
%End
|
||||
|
||||
static QStringList svgPaths();
|
||||
|
||||
@ -1464,7 +1464,7 @@ void QgsOptions::saveOptions()
|
||||
{
|
||||
pathsList << mListSVGPaths->item( i )->text();
|
||||
}
|
||||
mSettings->setValue( QStringLiteral( "svg/searchPathsForSVG" ), pathsList );
|
||||
QgsApplication::setSvgPaths( pathsList );
|
||||
|
||||
pathsList.clear();
|
||||
for ( int i = 0; i < mListComposerTemplatePaths->count(); ++i )
|
||||
|
||||
@ -70,6 +70,7 @@
|
||||
#include "qgsmeshlayer.h"
|
||||
#include "qgsfeaturestore.h"
|
||||
#include "qgslocator.h"
|
||||
#include "qgsreadwritelocker.h"
|
||||
|
||||
#include "gps/qgsgpsconnectionregistry.h"
|
||||
#include "processing/qgsprocessingregistry.h"
|
||||
@ -1050,27 +1051,46 @@ QString QgsApplication::srsDatabaseFilePath()
|
||||
}
|
||||
}
|
||||
|
||||
void QgsApplication::setSvgPaths( const QStringList &svgPaths )
|
||||
{
|
||||
QgsSettings().setValue( QStringLiteral( "svg/searchPathsForSVG" ), svgPaths );
|
||||
members()->mSvgPathCacheValid = false;
|
||||
}
|
||||
|
||||
QStringList QgsApplication::svgPaths()
|
||||
{
|
||||
//local directories to search when looking for an SVG with a given basename
|
||||
//defined by user in options dialog
|
||||
QgsSettings settings;
|
||||
const QStringList pathList = settings.value( QStringLiteral( "svg/searchPathsForSVG" ) ).toStringList();
|
||||
static QReadWriteLock lock;
|
||||
|
||||
// maintain user set order while stripping duplicates
|
||||
QStringList paths;
|
||||
for ( const QString &path : pathList )
|
||||
{
|
||||
if ( !paths.contains( path ) )
|
||||
paths.append( path );
|
||||
}
|
||||
for ( const QString &path : qgis::as_const( *sDefaultSvgPaths() ) )
|
||||
{
|
||||
if ( !paths.contains( path ) )
|
||||
paths.append( path );
|
||||
}
|
||||
QgsReadWriteLocker locker( lock, QgsReadWriteLocker::Read );
|
||||
|
||||
return paths;
|
||||
if ( members()->mSvgPathCacheValid )
|
||||
{
|
||||
return members()->mSvgPathCache;
|
||||
}
|
||||
else
|
||||
{
|
||||
locker.changeMode( QgsReadWriteLocker::Write );
|
||||
//local directories to search when looking for an SVG with a given basename
|
||||
//defined by user in options dialog
|
||||
QgsSettings settings;
|
||||
const QStringList pathList = settings.value( QStringLiteral( "svg/searchPathsForSVG" ) ).toStringList();
|
||||
|
||||
// maintain user set order while stripping duplicates
|
||||
QStringList paths;
|
||||
for ( const QString &path : pathList )
|
||||
{
|
||||
if ( !paths.contains( path ) )
|
||||
paths.append( path );
|
||||
}
|
||||
for ( const QString &path : qgis::as_const( *sDefaultSvgPaths() ) )
|
||||
{
|
||||
if ( !paths.contains( path ) )
|
||||
paths.append( path );
|
||||
}
|
||||
members()->mSvgPathCache = paths;
|
||||
|
||||
return paths;
|
||||
}
|
||||
}
|
||||
|
||||
QStringList QgsApplication::layoutTemplatePaths()
|
||||
|
||||
@ -316,6 +316,13 @@ class CORE_EXPORT QgsApplication : public QApplication
|
||||
//! Returns the path to the srs.db file.
|
||||
static QString srsDatabaseFilePath();
|
||||
|
||||
/**
|
||||
* Sets the paths to svg directories and invalidates the svg path list cache.
|
||||
*
|
||||
* \since QGIS 3.18
|
||||
*/
|
||||
static void setSvgPaths( const QStringList &svgPaths );
|
||||
|
||||
//! Returns the paths to svg directories.
|
||||
static QStringList svgPaths();
|
||||
|
||||
@ -1005,6 +1012,8 @@ class CORE_EXPORT QgsApplication : public QApplication
|
||||
QgsBookmarkManager *mBookmarkManager = nullptr;
|
||||
QgsStyleModel *mStyleModel = nullptr;
|
||||
QString mNullRepresentation;
|
||||
QStringList mSvgPathCache;
|
||||
bool mSvgPathCacheValid = false;
|
||||
|
||||
ApplicationMembers();
|
||||
~ApplicationMembers();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user