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