Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added QgsSettingsRegistry base class
- Loading branch information
Showing
13 changed files
with
256 additions
and
248 deletions.
There are no files selected for viewing
217 changes: 25 additions & 192 deletions
217
python/core/auto_generated/settings/qgssettingsentry.sip.in
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*************************************************************************** | ||
qgssettingsregistry.cpp | ||
-------------------------------------- | ||
Date : February 2021 | ||
Copyright : (C) 2021 by Damiano Lombardi | ||
Email : damiano at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgssettingsregistry.h" | ||
|
||
#include "qgslayout.h" | ||
#include "qgslocator.h" | ||
#include "qgsnetworkaccessmanager.h" | ||
#include "qgsnewsfeedparser.h" | ||
#include "qgsprocessing.h" | ||
#include "qgsapplication.h" | ||
#include "qgsgeometryoptions.h" | ||
#include "qgslocalizeddatapathregistry.h" | ||
#include "qgsmaprendererjob.h" | ||
|
||
QgsSettingsRegistry::QgsSettingsRegistry() | ||
: mSettingsEntriesMap() | ||
, mDynamicSettingsEntriesMap() | ||
{ | ||
} | ||
|
||
QgsSettingsRegistry::~QgsSettingsRegistry() | ||
{ | ||
} | ||
|
||
const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString &key ) | ||
{ | ||
if ( mSettingsEntriesMap.contains( key ) ) | ||
return mSettingsEntriesMap.value( key ); | ||
|
||
const QMap<QString, const QgsSettingsEntryBase *> dynamicSettingsEntriesMap = mDynamicSettingsEntriesMap; | ||
for ( const QgsSettingsEntryBase *settingsEntry : dynamicSettingsEntriesMap ) | ||
{ | ||
QRegularExpression regularExpression( settingsEntry->key( ".*" ) ); | ||
QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( key ); | ||
if ( regularExpresisonMatch.hasMatch() ) | ||
return settingsEntry; | ||
} | ||
|
||
return nullptr; | ||
} | ||
|
||
void QgsSettingsRegistry::addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ) | ||
{ | ||
if ( settingsEntry->hasDynamicKey() ) | ||
mDynamicSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry ); | ||
else | ||
mSettingsEntriesMap.insert( settingsEntry->key(), settingsEntry ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/*************************************************************************** | ||
qgssettingsregistry.h | ||
-------------------------------------- | ||
Date : February 2021 | ||
Copyright : (C) 2021 by Damiano Lombardi | ||
Email : damiano at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#ifndef QGSSETTINGSREGISTRY_H | ||
#define QGSSETTINGSREGISTRY_H | ||
|
||
#include "qgis_core.h" | ||
#include "qgis_sip.h" | ||
#include "qgssettingsentry.h" | ||
|
||
#include <QMap> | ||
|
||
/** | ||
* \ingroup core | ||
* \class QgsSettingsRegistry | ||
* QgsSettingsRegistry is used for settings introspection and collects a | ||
* list of child QgsSettingsRegistry and a list of child QgsSettingsRegistry | ||
* | ||
* \since QGIS 3.20 | ||
*/ | ||
class CORE_EXPORT QgsSettingsRegistry | ||
{ | ||
public: | ||
|
||
/** | ||
* Constructor for QgsSettingsRegistry. | ||
*/ | ||
QgsSettingsRegistry(); | ||
|
||
/** | ||
* Destructor for QgsSettingsRegistry. | ||
*/ | ||
virtual ~QgsSettingsRegistry(); | ||
|
||
/** | ||
* Returns the QgsSettingsEntry with the given \a key or nullptr if not found. | ||
*/ | ||
const QgsSettingsEntryBase *getSettingsEntry( const QString &key ); | ||
|
||
/** | ||
* Add \a settingsEntry to the register. | ||
*/ | ||
void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry ); | ||
|
||
private: | ||
|
||
QMap<QString, const QgsSettingsEntryBase *> mSettingsEntriesMap; | ||
QMap<QString, const QgsSettingsEntryBase *> mDynamicSettingsEntriesMap; | ||
|
||
}; | ||
|
||
#endif // QGSSETTINGSREGISTRY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/*************************************************************************** | ||
testqgssettingregistry.cpp | ||
-------------------------------------- | ||
Date : 08.04.2021 | ||
Copyright : (C) 2021 by Damiano Lombardi | ||
Email : damiano@opengis.ch | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
#include <QObject> | ||
|
||
#include "qgssettingsentry.h" | ||
#include "qgssettingsregistry.h" | ||
#include "qgsunittypes.h" | ||
#include "qgsmaplayerproxymodel.h" | ||
#include "qgstest.h" | ||
|
||
|
||
/** | ||
* \ingroup UnitTests | ||
* This is a unit test for the QgsSettingsRegistry classes | ||
*/ | ||
class TestQgsSettingsRegistry : public QObject | ||
{ | ||
Q_OBJECT | ||
|
||
private slots: | ||
void getSettingsEntries(); | ||
void getSettingsEntriesWithDynamicKeys(); | ||
}; | ||
|
||
void TestQgsSettingsRegistry::getSettingsEntries() | ||
{ | ||
QString settingsEntryBoolKey( "/qgis/testing/settingsEntryBool" ); | ||
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); | ||
QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" ); | ||
QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); | ||
|
||
QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting" ); | ||
|
||
QgsSettingsRegistry settingsRegistry; | ||
settingsRegistry.addSettingsEntry( &settingsEntryBool ); | ||
settingsRegistry.addSettingsEntry( &settingsEntryInteger ); | ||
|
||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool ); | ||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger ); | ||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr ); | ||
} | ||
|
||
void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys() | ||
{ | ||
QString settingsEntryBoolKey( "/qgis/testing/%_settingsEntryBool" ); | ||
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false ); | ||
QString settingsEntryIntegerKey( "/qgis/testing/%/settingsEntryInteger" ); | ||
QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 ); | ||
|
||
QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%" ); | ||
|
||
QgsSettingsRegistry settingsRegistry; | ||
settingsRegistry.addSettingsEntry( &settingsEntryBool ); | ||
settingsRegistry.addSettingsEntry( &settingsEntryInteger ); | ||
|
||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool ); | ||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey.replace( "%", "1st" ) ), &settingsEntryBool ); | ||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey.replace( "%", "Second" ) ), &settingsEntryInteger ); | ||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger ); | ||
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr ); | ||
} | ||
|
||
QGSTEST_MAIN( TestQgsSettingsRegistry ) | ||
#include "testqgssettingsregistry.moc" |