QGIS API Documentation 3.99.0-Master (e9821da5c6b)
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
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27 : mSettingsEntriesMap()
28 , mSettingsRegistryChildList()
29{
30}
31
35
37{
38 if ( !settingsEntry )
39 {
40 QgsDebugError( u"Trying to register a nullptr settings entry."_s );
41 return false;
42 }
43
44 if ( mSettingsEntriesMap.contains( settingsEntry->definitionKey() ) )
45 {
46 QgsDebugError( u"Settings with key '%1' is already registered."_s.arg( settingsEntry->definitionKey() ) );
47 return false;
48 }
49
50 mSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry );
51 return true;
52}
53
55{
56 for ( const auto *setting : settingsGroup->settings() )
57 {
58 if ( addSettingsEntry( setting ) )
59 {
60 mSettingsEntriesGroupMap.insert( setting, settingsGroup );
61 }
62 }
63}
64
65QList<const QgsSettingsEntryBase *> QgsSettingsRegistry::settingEntries() const
66{
67 return mSettingsEntriesMap.values();
68}
69
70const QgsSettingsEntryBase *QgsSettingsRegistry::settingsEntry( const QString &key, bool searchChildRegistries ) const
71{
72 // Search in this registry
73 const QMap<QString, const QgsSettingsEntryBase *> settingsEntriesMap = mSettingsEntriesMap;
74 for ( const QgsSettingsEntryBase *settingsEntry : settingsEntriesMap )
75 {
76 if ( settingsEntry->keyIsValid( key ) )
77 return settingsEntry;
78 }
79
80 // Search in child registries
81 if ( searchChildRegistries )
82 {
83 for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) )
84 {
85 const QgsSettingsEntryBase *settingsEntry = settingsRegistry->settingsEntry( key, true );
86 if ( settingsEntry )
87 return settingsEntry;
88 }
89 }
90
91 return nullptr;
92}
93
95{
96 if ( !settingsRegistry )
97 {
98 QgsDebugError( u"Trying to register a nullptr child settings registry."_s );
99 return;
100 }
101
102 if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
103 {
104 QgsDebugError( u"Child register is already registered."_s );
105 return;
106 }
107
108 mSettingsRegistryChildList.append( settingsRegistry );
109}
110
112{
113 if ( !settingsRegistry )
114 {
115 QgsDebugError( u"Trying to unregister a nullptr child settings registry."_s );
116 return;
117 }
118
119 if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
120 {
121 QgsDebugError( u"Child register is not registered."_s );
122 return;
123 }
124
125 mSettingsRegistryChildList.removeAll( settingsRegistry );
126}
127
129QList<const QgsSettingsRegistry *> QgsSettingsRegistry::subRegistries() const
130{
131 return mSettingsRegistryChildList;
132}
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:7475
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7474
#define QgsDebugError(str)
Definition qgslogger.h:59