Skip to content
Permalink
Browse files
Advanced settings editor show description for registered settings
  • Loading branch information
domi4484 committed Apr 19, 2021
1 parent fc55866 commit a693ebc8d5be3f1aeacc9bdf7e399304d2fef407
Showing with 45 additions and 15 deletions.
  1. +13 −3 src/app/qgssettingstree.cpp
  2. +29 −9 src/core/settings/qgssettingsentry.cpp
  3. +3 −3 tests/src/core/testqgssettingsregistry.cpp
@@ -45,6 +45,8 @@
#include "qgsvariantdelegate.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgssettingsentry.h"
#include "qgssettingsregistrycore.h"
#include "qgsapplication.h"

#include <QMenu>
@@ -319,7 +321,17 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text,
item->setFlags( item->flags() | Qt::ItemIsEditable );

item->setData( 0, TypeRole, isGroup ? Group : Setting );
item->setData( 0, PathRole, mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text );

QString completeSettingsPath = mSettings->group().isEmpty() ? text : mSettings->group() + '/' + text;
item->setData( 0, PathRole, completeSettingsPath );

// If settings registered add description
if ( !isGroup )
{
const QgsSettingsEntryBase *settingsEntry = QgsApplication::settingsRegistryCore()->getSettingsEntry( completeSettingsPath, true );
if ( settingsEntry != nullptr )
item->setText( 3, settingsEntry->description() );
}

QString key = itemKey( item );
QgsDebugMsgLevel( key, 4 );
@@ -332,8 +344,6 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text,
item->setToolTip( 2, values.at( 1 ) );
}

// if ( settingsMap.contains(

return item;
}

@@ -85,20 +85,40 @@ QString QgsSettingsEntryBase::key( const QStringList &dynamicKeyPartList ) const

bool QgsSettingsEntryBase::checkKey( const QString &key ) const
{
QString completeKey = key;
if ( !mPluginName.isEmpty()
&& !completeKey.startsWith( mPluginName ) )
// Key to check
QString completeKeyToCheck = key;

QString settingsPrefix = QgsSettings().prefixedKey( "", section() );
settingsPrefix.chop( 1 );
if ( !completeKeyToCheck.startsWith( settingsPrefix ) )
{
if ( !completeKey.startsWith( "/" ) )
completeKey.prepend( "/" );
completeKey.prepend( mPluginName );
if ( !mPluginName.isEmpty()
&& !completeKeyToCheck.startsWith( mPluginName ) )
{
if ( !completeKeyToCheck.startsWith( "/" ) )
completeKeyToCheck.prepend( "/" );
completeKeyToCheck.prepend( mPluginName );
}

if ( !completeKeyToCheck.startsWith( "/" ) )
completeKeyToCheck.prepend( "/" );
completeKeyToCheck.prepend( settingsPrefix );
}

// Prefixed settings key
QString prefixedSettingsKey = definitionKey();
if ( !prefixedSettingsKey.startsWith( settingsPrefix ) )
{
if ( !prefixedSettingsKey.startsWith( "/" ) )
prefixedSettingsKey.prepend( "/" );
prefixedSettingsKey.prepend( settingsPrefix );
}

if ( !hasDynamicKey() )
return completeKey == QgsSettingsEntryBase::key();
return completeKeyToCheck == prefixedSettingsKey;

QRegularExpression regularExpression( definitionKey().replace( QRegularExpression( "%\\d+" ), ".*" ) );
QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKey );
QRegularExpression regularExpression( prefixedSettingsKey.replace( QRegularExpression( "%\\d+" ), ".*" ) );
QRegularExpressionMatch regularExpresisonMatch = regularExpression.match( completeKeyToCheck );
return regularExpresisonMatch.hasMatch();
}

@@ -59,9 +59,9 @@ void TestQgsSettingsRegistry::getSettingsEntriesWithDynamicKeys()
QString settingsEntryBoolKey( "/qgis/testing/%1_settingsEntryBool" );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false );
QString settingsEntryIntegerKey( "/qgis/testing/%1/settingsEntryInteger" );
QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 );
QString settingsEntryDoubleKey( "/qgis/testing/%1/settingsEntryDouble_%2" );
QgsSettingsEntryBool settingsEntryDouble( settingsEntryDoubleKey, QgsSettings::NoSection, 1.23 );
QgsSettingsEntryDouble settingsEntryDouble( settingsEntryDoubleKey, QgsSettings::NoSection, 1.23 );

QString settingsEntryInexisting( "/qgis/testing/settingsEntryInexisting%1" );

@@ -84,7 +84,7 @@ void TestQgsSettingsRegistry::childRegistry()
QString settingsEntryBoolKey( "/qgis/testing/settingsEntryBool" );
QgsSettingsEntryBool settingsEntryBool( settingsEntryBoolKey, QgsSettings::NoSection, false );
QString settingsEntryIntegerKey( "/qgis/testing/settingsEntryInteger" );
QgsSettingsEntryBool settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 );
QgsSettingsEntryInteger settingsEntryInteger( settingsEntryIntegerKey, QgsSettings::NoSection, 123 );

QgsSettingsRegistry settingsRegistryChild;
settingsRegistryChild.addSettingsEntry( &settingsEntryInteger );

0 comments on commit a693ebc

Please sign in to comment.