Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Advanced settings editor show description for registered settings
  • Loading branch information
domi4484 committed Apr 19, 2021
1 parent fc55866 commit a693ebc
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
16 changes: 13 additions & 3 deletions src/app/qgssettingstree.cpp
Expand Up @@ -45,6 +45,8 @@
#include "qgsvariantdelegate.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgssettingsentry.h"
#include "qgssettingsregistrycore.h"
#include "qgsapplication.h"

#include <QMenu>
Expand Down Expand Up @@ -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 );
Expand All @@ -332,8 +344,6 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text,
item->setToolTip( 2, values.at( 1 ) );
}

// if ( settingsMap.contains(

return item;
}

Expand Down
38 changes: 29 additions & 9 deletions src/core/settings/qgssettingsentry.cpp
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testqgssettingsregistry.cpp
Expand Up @@ -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" );

Expand All @@ -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 );
Expand Down

0 comments on commit a693ebc

Please sign in to comment.