QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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#include "qgssettingsentry.h"
19#include "qgslogger.h"
20
22 : mSettingsEntriesMap()
23 , mSettingsRegistryChildList()
24{
25}
26
30
32{
33 if ( !settingsEntry )
34 {
35 QgsDebugError( QStringLiteral( "Trying to register a nullptr settings entry." ) );
36 return false;
37 }
38
39 if ( mSettingsEntriesMap.contains( settingsEntry->definitionKey() ) )
40 {
41 QgsDebugError( QStringLiteral( "Settings with key '%1' is already registered." ).arg( settingsEntry->definitionKey() ) );
42 return false;
43 }
44
45 mSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry );
46 return true;
47}
48
50{
51 for ( const auto *setting : settingsGroup->settings() )
52 {
53 if ( addSettingsEntry( setting ) )
54 {
55 mSettingsEntriesGroupMap.insert( setting, settingsGroup );
56 }
57 }
58}
59
60QList<const QgsSettingsEntryBase *> QgsSettingsRegistry::settingEntries() const
61{
62 return mSettingsEntriesMap.values();
63}
64
65const QgsSettingsEntryBase *QgsSettingsRegistry::settingsEntry( const QString &key, bool searchChildRegistries ) const
66{
67 // Search in this registry
68 const QMap<QString, const QgsSettingsEntryBase *> settingsEntriesMap = mSettingsEntriesMap;
69 for ( const QgsSettingsEntryBase *settingsEntry : settingsEntriesMap )
70 {
71 if ( settingsEntry->keyIsValid( key ) )
72 return settingsEntry;
73 }
74
75 // Search in child registries
76 if ( searchChildRegistries )
77 {
78 for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) )
79 {
80 const QgsSettingsEntryBase *settingsEntry = settingsRegistry->settingsEntry( key, true );
81 if ( settingsEntry )
82 return settingsEntry;
83 }
84 }
85
86 return nullptr;
87}
88
90{
91 if ( !settingsRegistry )
92 {
93 QgsDebugError( QStringLiteral( "Trying to register a nullptr child settings registry." ) );
94 return;
95 }
96
97 if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
98 {
99 QgsDebugError( QStringLiteral( "Child register is already registered." ) );
100 return;
101 }
102
103 mSettingsRegistryChildList.append( settingsRegistry );
104}
105
107{
108 if ( !settingsRegistry )
109 {
110 QgsDebugError( QStringLiteral( "Trying to unregister a nullptr child settings registry." ) );
111 return;
112 }
113
114 if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
115 {
116 QgsDebugError( QStringLiteral( "Child register is not registered." ) );
117 return;
118 }
119
120 mSettingsRegistryChildList.removeAll( settingsRegistry );
121}
122
124QList<const QgsSettingsRegistry *> QgsSettingsRegistry::subRegistries() const
125{
126 return mSettingsRegistryChildList;
127}
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...
Q_DECL_DEPRECATED 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 QgsSettingsEntryBase * > settingEntries() const
Returns the list of registered QgsSettingsEntryBase.
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.
QList< const QgsSettingsRegistry * > subRegistries() const
Returns the list of registered child QgsSettingsRegistry.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:6643
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:6642
#define QgsDebugError(str)
Definition qgslogger.h:38