Skip to content

Commit

Permalink
add helpers in QgsSettings to retrieve or create tree elements, creat…
Browse files Browse the repository at this point in the history
…e some first tree elements
  • Loading branch information
3nids committed Jan 16, 2023
1 parent 82d4e0e commit 95c84b5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/core/settings/qgssettings.cpp
Expand Up @@ -48,6 +48,30 @@ void QgsSettings::init()
}


QgsSettingsTreeElement *QgsSettings::treeRoot()
{
// this must be defined in cpp code so we are sure only one instance is around
static QgsSettingsTreeElement *sTreeRoot = QgsSettingsTreeElement::createRootElement();
return sTreeRoot;
}

QgsSettingsTreeElement *QgsSettings::createPluginTreeElement( const QString &pluginName )
{
QgsSettingsTreeElement *te = sTreePlugins->childElement( pluginName );
if ( te )
return te;
else
return sTreePlugins->createChildElement( pluginName );
}

void QgsSettings::unregisterPluginTreeElement( const QString &pluginName )
{
//QgsDebugMsg( "unregister plugin tree element" );
QgsSettingsTreeElement *pluginTreeElement = sTreePlugins->childElement( pluginName );
if ( pluginTreeElement )
delete pluginTreeElement;
}

QgsSettings::QgsSettings( const QString &organization, const QString &application, QObject *parent )
{
mUserSettings = new QSettings( organization, application, parent );
Expand Down
25 changes: 25 additions & 0 deletions src/core/settings/qgssettings.h
Expand Up @@ -23,6 +23,7 @@
#include "qgis_core.h"
#include "qgis_sip.h"
#include "qgslogger.h"
#include "qgssettingstreeelement.h"

/**
* \ingroup core
Expand Down Expand Up @@ -79,6 +80,30 @@ class CORE_EXPORT QgsSettings : public QObject
Gps, //!< GPS section, since QGIS 3.22
};

#ifndef SIP_RUN
static QgsSettingsTreeElement *treeRoot();
static inline QgsSettingsTreeElement *sTtreeConnections = treeRoot()->createChildElement( QStringLiteral( "connections" ) );
static inline QgsSettingsTreeElement *sTreeLocale = treeRoot()->createChildElement( QStringLiteral( "locale" ) );
static inline QgsSettingsTreeElement *sTreeGps = treeRoot()->createChildElement( QStringLiteral( "gps" ) );
static inline QgsSettingsTreeElement *sTreeQgis = treeRoot()->createChildElement( QStringLiteral( "qgis" ) );
static inline QgsSettingsTreeElement *sTreePlugins = treeRoot()->createChildElement( QStringLiteral( "plugins" ) );
static inline QgsSettingsTreeElement *sTreeSvg = treeRoot()->createChildElement( QStringLiteral( "svg" ) );
#endif

/**
* Creates a settings tree element for the given \a pluginName
* \since QGIS 3.30
*/
static QgsSettingsTreeElement *createPluginTreeElement( const QString &pluginName ) SIP_THROW( QgsSettingsException );


/**
* Unregisters the tree element for the given plugin
* \since QGIS 3.30
*/
static void unregisterPluginTreeElement( const QString &pluginName );


/**
* \ingroup core
* \brief Prefixes for the settings keys
Expand Down

0 comments on commit 95c84b5

Please sign in to comment.