Skip to content

Commit

Permalink
QgsSettings Q_GLOBAL_STATIC
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 2, 2019
1 parent 4ea4b67 commit f8f9de8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/core/qgssettings.cpp
Expand Up @@ -23,23 +23,23 @@
#include "qgssettings.h"
#include "qgslogger.h"

QString QgsSettings::sGlobalSettingsPath = QString();
Q_GLOBAL_STATIC( QString, sGlobalSettingsPath )

bool QgsSettings::setGlobalSettingsPath( const QString &path )
{
if ( QFileInfo::exists( path ) )
{
sGlobalSettingsPath = path;
*sGlobalSettingsPath() = path;
return true;
}
return false;
}

void QgsSettings::init()
{
if ( ! sGlobalSettingsPath.isEmpty() )
if ( ! sGlobalSettingsPath()->isEmpty() )
{
mGlobalSettings = new QSettings( sGlobalSettingsPath, QSettings::IniFormat );
mGlobalSettings = new QSettings( *sGlobalSettingsPath(), QSettings::IniFormat );
mGlobalSettings->setIniCodec( "UTF-8" );
}
}
Expand Down Expand Up @@ -166,6 +166,11 @@ QStringList QgsSettings::globalChildGroups() const
return keys;
}

QString QgsSettings::globalSettingsPath()
{
return *sGlobalSettingsPath();
}

QVariant QgsSettings::value( const QString &key, const QVariant &defaultValue, const QgsSettings::Section section ) const
{
QString pKey = prefixedKey( key, section );
Expand Down
4 changes: 1 addition & 3 deletions src/core/qgssettings.h
Expand Up @@ -172,7 +172,7 @@ class CORE_EXPORT QgsSettings : public QObject
//! Returns a list of all key top-level groups (same as childGroups) but only for groups defined in global settings.
QStringList globalChildGroups() const;
//! Returns the path to the Global Settings QSettings storage file
static QString globalSettingsPath() { return sGlobalSettingsPath; }
static QString globalSettingsPath();
//! Sets the Global Settings QSettings storage file
static bool setGlobalSettingsPath( const QString &path );
//! Adds prefix to the current group and starts reading from an array. Returns the size of the array.
Expand Down Expand Up @@ -410,8 +410,6 @@ class CORE_EXPORT QgsSettings : public QObject
void clear();

private:

static QString sGlobalSettingsPath;
void init();
QString sanitizeKey( const QString &key ) const;
QSettings *mUserSettings = nullptr;
Expand Down

0 comments on commit f8f9de8

Please sign in to comment.