QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgssettingsregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgssettingsregistry.cpp
3 --------------------------------------
4 Date : February 2021
5 Copyright : (C) 2021 by Damiano Lombardi
6 Email : damiano at opengis dot ch
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgssettingsregistry.h"
17
18#include "qgslayout.h"
19#include "qgslocator.h"
21#include "qgsnewsfeedparser.h"
22#include "qgsprocessing.h"
23#include "qgsapplication.h"
24#include "qgsgeometryoptions.h"
26#include "qgsmaprendererjob.h"
27
29 : mSettingsEntriesMap()
30 , mSettingsRegistryChildList()
31{
32}
33
35{
36}
37
39{
40 if ( !settingsEntry )
41 {
42 QgsDebugMsg( QStringLiteral( "Trying to register a nullptr settings entry." ) );
43 return false;
44 }
45
46 if ( mSettingsEntriesMap.contains( settingsEntry->definitionKey() ) )
47 {
48 QgsDebugMsg( QStringLiteral( "Settings with key '%1' is already registered." ).arg( settingsEntry->definitionKey() ) );
49 return false;
50 }
51
52 mSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry );
53 return true;
54}
55
57{
58 for ( const auto *setting : settingsGroup->settings() )
59 {
60 if ( addSettingsEntry( setting ) )
61 {
62 mSettingsEntriesGroupMap.insert( setting, settingsGroup );
63 }
64 }
65}
66
67QList<const QgsSettingsEntryBase *> QgsSettingsRegistry::settingEntries() const
68{
69 return mSettingsEntriesMap.values();
70}
71
72const QgsSettingsEntryBase *QgsSettingsRegistry::settingsEntry( const QString &key, bool searchChildRegistries ) const
73{
74 // Search in this registry
75 const QMap<QString, const QgsSettingsEntryBase *> settingsEntriesMap = mSettingsEntriesMap;
76 for ( const QgsSettingsEntryBase *settingsEntry : settingsEntriesMap )
77 {
78 if ( settingsEntry->keyIsValid( key ) )
79 return settingsEntry;
80 }
81
82 // Search in child registries
83 if ( searchChildRegistries )
84 {
85 for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) )
86 {
87 const QgsSettingsEntryBase *settingsEntry = settingsRegistry->settingsEntry( key, true );
88 if ( settingsEntry )
89 return settingsEntry;
90 }
91 }
92
93 return nullptr;
94}
95
97{
98 if ( !settingsRegistry )
99 {
100 QgsDebugMsg( QStringLiteral( "Trying to register a nullptr child settings registry." ) );
101 return;
102 }
103
104 if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
105 {
106 QgsDebugMsg( QStringLiteral( "Child register is already registered." ) );
107 return;
108 }
109
110 mSettingsRegistryChildList.append( settingsRegistry );
111}
112
114{
115 if ( !settingsRegistry )
116 {
117 QgsDebugMsg( QStringLiteral( "Trying to unregister a nullptr child settings registry." ) );
118 return;
119 }
120
121 if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
122 {
123 QgsDebugMsg( QStringLiteral( "Child register is not registered." ) );
124 return;
125 }
126
127 mSettingsRegistryChildList.removeAll( settingsRegistry );
128}
129
130QList<const QgsSettingsRegistry *> QgsSettingsRegistry::subRegistries() const
131{
132 return mSettingsRegistryChildList;
133}
Represent settings entry and provides methods for reading and writing settings values.
bool keyIsValid(const QString &key) const
Returns true if the provided key match the settings entry.
QString definitionKey() const
Returns settings entry defining key.
Creates a group of setting which have a common definition of base key.
const QList< const QgsSettingsEntryBase * > settings() const
Returns all the settings.
QgsSettingsRegistry is used for settings introspection and collects a list of child QgsSettingsRegist...
QgsSettingsRegistry()
Constructor for QgsSettingsRegistry.
void addSettingsEntryGroup(const QgsSettingsEntryGroup *settingsGroup)
Adds a group of setting to the registry.
bool addSettingsEntry(const QgsSettingsEntryBase *settingsEntry)
Adds settingsEntry to the registry.
QList< const QgsSettingsRegistry * > subRegistries() const
Returns the list of registered child QgsSettingsRegistry.
QList< const QgsSettingsEntryBase * > settingEntries() const
Returns the list of registered QgsSettingsEntryBase.
virtual ~QgsSettingsRegistry()
Destructor for QgsSettingsRegistry.
void removeSubRegistry(const QgsSettingsRegistry *settingsRegistry)
Remove a child settingsRegistry from the register.
const QgsSettingsEntryBase * settingsEntry(const QString &key, bool searchChildRegistries=true) const
Returns the QgsSettingsEntry with the given key or nullptr if not found.
void addSubRegistry(const QgsSettingsRegistry *settingsRegistry)
Append a child settingsRegistry to the register.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38