QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 false;
44  }
45 
46  if ( mSettingsEntriesMap.contains( settingsEntry->definitionKey() ) )
47  {
48  QgsDebugMsg( QStringLiteral( "Settings with key '%1' is already registered." ).arg( settingsEntry->definitionKey() ) );
49  return false;
50  }
51 
52  mSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry );
53  return true;
54 }
55 
57 {
58  for ( const auto *setting : settingsGroup->settings() )
59  {
60  if ( addSettingsEntry( setting ) )
61  {
62  mSettingsEntriesGroupMap.insert( setting, settingsGroup );
63  }
64  }
65 }
66 
67 QList<const QgsSettingsEntryBase *> QgsSettingsRegistry::settingEntries() const
68 {
69  return mSettingsEntriesMap.values();
70 }
71 
72 const QgsSettingsEntryBase *QgsSettingsRegistry::settingsEntry( const QString &key, bool searchChildRegistries ) const
73 {
74  // Search in this registry
75  const QMap<QString, const QgsSettingsEntryBase *> settingsEntriesMap = mSettingsEntriesMap;
76  for ( const QgsSettingsEntryBase *settingsEntry : settingsEntriesMap )
77  {
78  if ( settingsEntry->keyIsValid( key ) )
79  return settingsEntry;
80  }
81 
82  // Search in child registries
83  if ( searchChildRegistries )
84  {
85  for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) )
86  {
87  const QgsSettingsEntryBase *settingsEntry = settingsRegistry->settingsEntry( key, true );
88  if ( settingsEntry )
89  return settingsEntry;
90  }
91  }
92 
93  return nullptr;
94 }
95 
97 {
98  if ( !settingsRegistry )
99  {
100  QgsDebugMsg( QStringLiteral( "Trying to register a nullptr child settings registry." ) );
101  return;
102  }
103 
104  if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
105  {
106  QgsDebugMsg( QStringLiteral( "Child register is already registered." ) );
107  return;
108  }
109 
110  mSettingsRegistryChildList.append( settingsRegistry );
111 }
112 
114 {
115  if ( !settingsRegistry )
116  {
117  QgsDebugMsg( QStringLiteral( "Trying to unregister a nullptr child settings registry." ) );
118  return;
119  }
120 
121  if ( mSettingsRegistryChildList.contains( settingsRegistry ) )
122  {
123  QgsDebugMsg( QStringLiteral( "Child register is not registered." ) );
124  return;
125  }
126 
127  mSettingsRegistryChildList.removeAll( settingsRegistry );
128 }
129 
130 QList<const QgsSettingsRegistry *> QgsSettingsRegistry::subRegistries() const
131 {
132  return mSettingsRegistryChildList;
133 }
QgsSettingsRegistry::settingsEntry
const QgsSettingsEntryBase * settingsEntry(const QString &key, bool searchChildRegistries=true) const
Returns the QgsSettingsEntry with the given key or nullptr if not found.
Definition: qgssettingsregistry.cpp:72
QgsSettingsRegistry::subRegistries
QList< const QgsSettingsRegistry * > subRegistries() const
Returns the list of registered child QgsSettingsRegistry.
Definition: qgssettingsregistry.cpp:130
QgsSettingsRegistry::~QgsSettingsRegistry
virtual ~QgsSettingsRegistry()
Destructor for QgsSettingsRegistry.
Definition: qgssettingsregistry.cpp:34
qgslocalizeddatapathregistry.h
qgslocator.h
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
qgsnewsfeedparser.h
QgsSettingsRegistry::addSubRegistry
void addSubRegistry(const QgsSettingsRegistry *settingsRegistry)
Append a child settingsRegistry to the register.
Definition: qgssettingsregistry.cpp:96
QgsSettingsEntryGroup
Creates a group of setting which have a common definition of base key.
Definition: qgssettingsentry.h:38
qgsapplication.h
QgsSettingsRegistry::addSettingsEntryGroup
void addSettingsEntryGroup(const QgsSettingsEntryGroup *settingsGroup)
Adds a group of setting to the registry.
Definition: qgssettingsregistry.cpp:56
QgsSettingsRegistry::removeSubRegistry
void removeSubRegistry(const QgsSettingsRegistry *settingsRegistry)
Remove a child settingsRegistry from the register.
Definition: qgssettingsregistry.cpp:113
QgsSettingsRegistry::QgsSettingsRegistry
QgsSettingsRegistry()
Constructor for QgsSettingsRegistry.
Definition: qgssettingsregistry.cpp:28
QgsSettingsRegistry
QgsSettingsRegistry is used for settings introspection and collects a list of child QgsSettingsRegist...
Definition: qgssettingsregistry.h:34
QgsSettingsRegistry::addSettingsEntry
bool addSettingsEntry(const QgsSettingsEntryBase *settingsEntry)
Adds settingsEntry to the registry.
Definition: qgssettingsregistry.cpp:38
qgsnetworkaccessmanager.h
qgsmaprendererjob.h
QgsSettingsEntryGroup::settings
const QList< const QgsSettingsEntryBase * > settings() const
Returns all the settings.
Definition: qgssettingsentry.h:64
qgslayout.h
QgsSettingsEntryBase::keyIsValid
bool keyIsValid(const QString &key) const
Returns true if the provided key match the settings entry.
Definition: qgssettingsentry.cpp:147
qgsprocessing.h
QgsSettingsEntryBase
Represent settings entry and provides methods for reading and writing settings values....
Definition: qgssettingsentry.h:102
qgssettingsregistry.h
QgsSettingsRegistry::settingEntries
QList< const QgsSettingsEntryBase * > settingEntries() const
Returns the list of registered QgsSettingsEntryBase.
Definition: qgssettingsregistry.cpp:67
qgsgeometryoptions.h
QgsSettingsEntryBase::definitionKey
QString definitionKey() const
Returns settings entry defining key.
Definition: qgssettingsentry.cpp:162