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