Skip to content
Permalink
Browse files
Renamed some methods of QgsSettingsRegistry
  • Loading branch information
domi4484 committed Apr 26, 2021
1 parent 70ab21f commit 952a77afe9ce60cd1e184e97ce8e61ed4b3e3e09
@@ -31,24 +31,24 @@ Constructor for QgsSettingsRegistry.

virtual ~QgsSettingsRegistry();

QList<const QgsSettingsEntryBase *> getChildSettingsEntries() const;
QList<const QgsSettingsEntryBase *> settingEntries() const;
%Docstring
Returns the list of registered :py:class:`QgsSettingsEntryBase`.
%End

const QgsSettingsEntryBase *getSettingsEntry( const QString &key, bool searchChildRegistries = true ) const;
const QgsSettingsEntryBase *settingsEntry( const QString &key, bool searchChildRegistries = true ) const;
%Docstring
Returns the :py:class:`QgsSettingsEntry` with the given ``key`` or None if not found.

The ``searchChildRegistries`` parameter specifies if child registries should be included in the search
%End

void appendRegistry( const QgsSettingsRegistry *settingsRegistry );
void addSubRegistry( const QgsSettingsRegistry *settingsRegistry );
%Docstring
Append a child ``settingsRegistry`` to the register.
%End

QList<const QgsSettingsRegistry *> getChildSettingsRegistries() const;
QList<const QgsSettingsRegistry *> subRegistries() const;
%Docstring
Returns the list of registered child QgsSettingsRegistry.
%End
@@ -331,7 +331,7 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text,
// If settings registered add description
if ( !isGroup )
{
const QgsSettingsEntryBase *settingsEntry = QgsApplication::settingsRegistryCore()->getSettingsEntry( completeSettingsPath, true );
const QgsSettingsEntryBase *settingsEntry = QgsApplication::settingsRegistryCore()->settingsEntry( completeSettingsPath, true );
if ( settingsEntry )
{
item->setText( ColumnDescription, settingsEntry->description() );
@@ -112,13 +112,13 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject
static QString keyForFeed( const QString &baseUrl );

//! Settings entry last fetch time
static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 );
static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%1/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 );
//! Settings entry feed language
static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) );
static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%1/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) );
//! Settings entry feed latitude
static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) );
static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%1/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) );
//! Settings entry feed longitude
static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) );
static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%1/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) );

public slots:

@@ -52,12 +52,12 @@ void QgsSettingsRegistry::addSettingsEntry( const QgsSettingsEntryBase *settings
mSettingsEntriesMap.insert( settingsEntry->definitionKey(), settingsEntry );
}

QList<const QgsSettingsEntryBase *> QgsSettingsRegistry::getChildSettingsEntries() const
QList<const QgsSettingsEntryBase *> QgsSettingsRegistry::settingEntries() const
{
return mSettingsEntriesMap.values();
}

const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString &key, bool searchChildRegistries ) const
const QgsSettingsEntryBase *QgsSettingsRegistry::settingsEntry( const QString &key, bool searchChildRegistries ) const
{
// Search in this registry
const QMap<QString, const QgsSettingsEntryBase *> settingsEntriesMap = mSettingsEntriesMap;
@@ -72,7 +72,7 @@ const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString
{
for ( const QgsSettingsRegistry *settingsRegistry : std::as_const( mSettingsRegistryChildList ) )
{
const QgsSettingsEntryBase *settingsEntry = settingsRegistry->getSettingsEntry( key, true );
const QgsSettingsEntryBase *settingsEntry = settingsRegistry->settingsEntry( key, true );
if ( settingsEntry )
return settingsEntry;
}
@@ -81,7 +81,7 @@ const QgsSettingsEntryBase *QgsSettingsRegistry::getSettingsEntry( const QString
return nullptr;
}

void QgsSettingsRegistry::appendRegistry( const QgsSettingsRegistry *settingsRegistry )
void QgsSettingsRegistry::addSubRegistry( const QgsSettingsRegistry *settingsRegistry )
{
if ( !settingsRegistry )
{
@@ -98,7 +98,7 @@ void QgsSettingsRegistry::appendRegistry( const QgsSettingsRegistry *settingsReg
mSettingsRegistryChildList.append( settingsRegistry );
}

QList<const QgsSettingsRegistry *> QgsSettingsRegistry::getChildSettingsRegistries() const
QList<const QgsSettingsRegistry *> QgsSettingsRegistry::subRegistries() const
{
return mSettingsRegistryChildList;
}
@@ -48,24 +48,24 @@ class CORE_EXPORT QgsSettingsRegistry
/**
* Returns the list of registered QgsSettingsEntryBase.
*/
QList<const QgsSettingsEntryBase *> getChildSettingsEntries() const;
QList<const QgsSettingsEntryBase *> settingEntries() const;

/**
* Returns the QgsSettingsEntry with the given \a key or nullptr if not found.
*
* The \a searchChildRegistries parameter specifies if child registries should be included in the search
*/
const QgsSettingsEntryBase *getSettingsEntry( const QString &key, bool searchChildRegistries = true ) const;
const QgsSettingsEntryBase *settingsEntry( const QString &key, bool searchChildRegistries = true ) const;

/**
* Append a child \a settingsRegistry to the register.
*/
void appendRegistry( const QgsSettingsRegistry *settingsRegistry );
void addSubRegistry( const QgsSettingsRegistry *settingsRegistry );

/**
* Returns the list of registered child QgsSettingsRegistry.
*/
QList<const QgsSettingsRegistry *> getChildSettingsRegistries() const;
QList<const QgsSettingsRegistry *> subRegistries() const;

protected:

@@ -61,9 +61,9 @@ void TestQgsSettingsRegistry::getSettingsEntries()
settingsRegistry.addSettingsEntry( &settingsEntryBool );
settingsRegistry.addSettingsEntry( &settingsEntryInteger );

QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryBoolKey ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryInexisting ), nullptr );
}

void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys()
@@ -82,13 +82,13 @@ void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys()
settingsRegistry.addSettingsEntry( &settingsEntryInteger );
settingsRegistry.addSettingsEntry( &settingsEntryDouble );

QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey ), &settingsEntryBool );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryBoolKey.replace( QStringLiteral( "%1" ), QStringLiteral( "1st" ) ) ), &settingsEntryBool );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey.replace( QStringLiteral( "%1" ), QStringLiteral( "Second" ) ) ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryDoubleKey ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryDoubleKey.replace( QStringLiteral( "%1" ), QStringLiteral( "1st" ) ).replace( QStringLiteral( "%2" ), QStringLiteral( "2nd" ) ) ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryInexisting ), nullptr );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryBoolKey ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryBoolKey.replace( QStringLiteral( "%1" ), QStringLiteral( "1st" ) ) ), &settingsEntryBool );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey.replace( QStringLiteral( "%1" ), QStringLiteral( "Second" ) ) ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryDoubleKey ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryDoubleKey.replace( QStringLiteral( "%1" ), QStringLiteral( "1st" ) ).replace( QStringLiteral( "%2" ), QStringLiteral( "2nd" ) ) ), &settingsEntryDouble );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryInexisting ), nullptr );
}

void TestQgsSettingsRegistry::childRegistry()
@@ -103,14 +103,14 @@ void TestQgsSettingsRegistry::childRegistry()

SettingsRegistryTest settingsRegistry;
settingsRegistry.addSettingsEntry( &settingsEntryBool );
settingsRegistry.appendRegistry( nullptr ); // should not crash
settingsRegistry.appendRegistry( &settingsRegistryChild );
settingsRegistry.addSubRegistry( nullptr ); // should not crash
settingsRegistry.addSubRegistry( &settingsRegistryChild );

// Search only in parent
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey, false ), nullptr );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey, false ), nullptr );

// Search including child registries
QCOMPARE( settingsRegistry.getSettingsEntry( settingsEntryIntegerKey, true ), &settingsEntryInteger );
QCOMPARE( settingsRegistry.settingsEntry( settingsEntryIntegerKey, true ), &settingsEntryInteger );
}

QGSTEST_MAIN( TestQgsSettingsRegistry )
@@ -35,12 +35,12 @@ def test_settings_registry(self):
settingsRegistry.addSettingsEntry(settingsEntry)

# check get settings entry
self.assertEqual(settingsRegistry.getSettingsEntry(settingsEntry.key(), False), settingsEntry)
self.assertEqual(settingsRegistry.settingsEntry(settingsEntry.key(), False), settingsEntry)

# add registry to core registry
QgsApplication.settingsRegistryCore().appendRegistry(settingsRegistry)
QgsApplication.settingsRegistryCore().addSubRegistry(settingsRegistry)

self.assertEqual(QgsApplication.settingsRegistryCore().getSettingsEntry(settingsEntry.key(), True), settingsEntry)
self.assertEqual(QgsApplication.settingsRegistryCore().settingsEntry(settingsEntry.key(), True), settingsEntry)


if __name__ == '__main__':

0 comments on commit 952a77a

Please sign in to comment.