QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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;
44  }
45 
46  if ( mSettingsEntriesMap.contains( settingsEntry->definitionKey() ) )
47  {
48  QgsDebugMsg( QStringLiteral( "Settings with key '%1' is already registered." ).arg( settingsEntry->definitionKey() ) );
49  return;
50  }
51 
52  mSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry );
53 }
54 
55 QList<const QgsSettingsEntryBase *> QgsSettingsRegistry::settingEntries() const
56 {
57  return mSettingsEntriesMap.values();
58 }
59 
60 const QgsSettingsEntryBase *QgsSettingsRegistry::settingsEntry( const QString &key, bool searchChildRegistries ) const
61 {
62  // Search in this registry
63  const QMap<QString, const QgsSettingsEntryBase *> settingsEntriesMap = mSettingsEntriesMap;
64  for ( const QgsSettingsEntryBase *settingsEntry : settingsEntriesMap )
65  {
66  if ( settingsEntry->keyIsValid( key ) )
67  return settingsEntry;
68  }
69 
70  // Search in child registries
71  if ( searchChildRegistries )
72  {
73  for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) )
74  {
75  const QgsSettingsEntryBase *settingsEntry = settingsRegistry->settingsEntry( key, true );
76  if ( settingsEntry )
77  return settingsEntry;
78  }
79  }
80 
81  return nullptr;
82 }
83 
85 {
86  if ( !settingsRegistry )
87  {
88  QgsDebugMsg( QStringLiteral( "Trying to register a nullptr child settings registry." ) );
89  return;
90  }
91 
92  if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
93  {
94  QgsDebugMsg( QStringLiteral( "Child register is already registered." ) );
95  return;
96  }
97 
98  mSettingsRegistryChildList.append( settingsRegistry );
99 }
100 
102 {
103  if ( !settingsRegistry )
104  {
105  QgsDebugMsg( QStringLiteral( "Trying to unregister a nullptr child settings registry." ) );
106  return;
107  }
108 
109  if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
110  {
111  QgsDebugMsg( QStringLiteral( "Child register is not registered." ) );
112  return;
113  }
114 
115  mSettingsRegistryChildList.removeAll( settingsRegistry );
116 }
117 
118 QList<const QgsSettingsRegistry *> QgsSettingsRegistry::subRegistries() const
119 {
120  return mSettingsRegistryChildList;
121 }
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.
QgsSettingsRegistry is used for settings introspection and collects a list of child QgsSettingsRegist...
QgsSettingsRegistry()
Constructor for QgsSettingsRegistry.
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.
void addSettingsEntry(const QgsSettingsEntryBase *settingsEntry)
Add settingsEntry to the register.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38