Skip to content
Permalink
Browse files
Merge pull request #42860 from domi4484/settingsRegistryQep124PartTwo
Settings registry (QEP 124) part two settings introspection
  • Loading branch information
3nids committed Apr 26, 2021
2 parents 9989cff + 8a7bfa1 commit 96cee9f4964ac64f28d5611e5d3c133427c21161
@@ -1,7 +1,7 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgssettings.h *
* src/core/settings/qgssettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -279,7 +279,7 @@ Removes all entries in the user settings
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgssettings.h *
* src/core/settings/qgssettings.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -82,23 +82,41 @@ The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
Get settings entry key.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End

bool keyIsValid( const QString &key ) const;
%Docstring
Returns ``True`` if the provided key match the settings entry.

This is useful for settings with dynamic keys. For example this permits to check that
the settings key "NewsFeed/httpsfeedqgisorg/27/content" is valid for the settings entry
defined with the key "NewsFeed/%1/%2/content"

The ``key`` to check
%End

QString definitionKey() const;
%Docstring
Returns settings entry defining key.
For dynamic settings it return the key with the placeholder for dynamic part
included. For non-dynamic settings returns the same as :py:func:`~QgsSettingsEntryBase.key`.
%End

bool hasDynamicKey() const;
%Docstring
Returns true if a part of the settings key is built dynamically.
Returns ``True`` if a part of the settings key is built dynamically.
%End

bool exists( const QString &dynamicKeyPart = QString() ) const;
%Docstring
Returns true if the settings is contained in the underlying QSettings.
Returns ``True`` if the settings is contained in the underlying QSettings.

The ``dynamicKeyPart`` argument specifies the dynamic part of the settings key.
%End

bool exists( const QStringList &dynamicKeyPartList ) const;
%Docstring
Returns true if the settings is contained in the underlying QSettings.
Returns ``True`` if the settings is contained in the underlying QSettings.

The ``dynamicKeyParts`` argument specifies the list of dynamic parts of the settings key.
%End
@@ -0,0 +1,71 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/settings/qgssettingsregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsSettingsRegistry
{
%Docstring(signature="appended")
:py:class:`QgsSettingsRegistry` is used for settings introspection and collects a
list of child :py:class:`QgsSettingsRegistry` and a list of child :py:class:`QgsSettingsRegistry`

.. versionadded:: 3.20
%End

%TypeHeaderCode
#include "qgssettingsregistry.h"
%End
public:

QgsSettingsRegistry();
%Docstring
Constructor for QgsSettingsRegistry.
%End

virtual ~QgsSettingsRegistry();

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

const QgsSettingsEntryBase *getSettingsEntry( 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 );
%Docstring
Append a child ``settingsRegistry`` to the register.
%End

QList<const QgsSettingsRegistry *> getChildSettingsRegistries() const;
%Docstring
Returns the list of registered child QgsSettingsRegistry.
%End

protected:

void addSettingsEntry( const QgsSettingsEntryBase *settingsEntry );
%Docstring
Add ``settingsEntry`` to the register.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/settings/qgssettingsregistry.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -9,10 +9,7 @@






class QgsSettingsRegistryCore
class QgsSettingsRegistryCore : QgsSettingsRegistry
{
%Docstring(signature="appended")
:py:class:`QgsSettingsRegistryCore` is used for settings introspection and collects all
@@ -174,7 +174,6 @@
%Include auto_generated/qgsruntimeprofiler.sip
%Include auto_generated/qgsscalecalculator.sip
%Include auto_generated/qgsscaleutils.sip
%Include auto_generated/qgssettings.sip
%Include auto_generated/qgssimplifymethod.sip
%Include auto_generated/qgssnappingconfig.sip
%Include auto_generated/qgssnappingutils.sip
@@ -602,7 +601,9 @@
%Include auto_generated/textrenderer/qgstextrenderer.sip
%Include auto_generated/textrenderer/qgstextrendererutils.sip
%Include auto_generated/textrenderer/qgstextshadowsettings.sip
%Include auto_generated/settings/qgssettings.sip
%Include auto_generated/settings/qgssettingsentry.sip
%Include auto_generated/settings/qgssettingsregistry.sip
%Include auto_generated/settings/qgssettingsregistrycore.sip
%Include auto_generated/validity/qgsabstractvaliditycheck.sip
%Include auto_generated/validity/qgsvaliditycheckcontext.sip
@@ -45,6 +45,8 @@
#include "qgsvariantdelegate.h"
#include "qgslogger.h"
#include "qgssettings.h"
#include "qgssettingsentry.h"
#include "qgssettingsregistrycore.h"
#include "qgsapplication.h"

#include <QMenu>
@@ -58,11 +60,9 @@ QgsSettingsTree::QgsSettingsTree( QWidget *parent )
QStringList labels;
labels << tr( "Setting" ) << tr( "Type" ) << tr( "Value" ) << tr( "Description" );
setHeaderLabels( labels );
// header()->setResizeMode( 0, QHeaderView::Stretch );
// header()->setResizeMode( 2, QHeaderView::Stretch );
header()->resizeSection( 0, 250 );
header()->resizeSection( 1, 100 );
header()->resizeSection( 2, 250 );
header()->resizeSection( ColumnSettings, 250 );
header()->resizeSection( ColumnType, 100 );
header()->resizeSection( ColumnValue, 250 );

mRefreshTimer.setInterval( 2000 );

@@ -168,7 +168,7 @@ void QgsSettingsTree::updateSetting( QTreeWidgetItem *item )
if ( key.isNull() )
return;

mSettings->setValue( key, item->data( 2, Qt::UserRole ) );
mSettings->setValue( key, item->data( ColumnValue, Qt::UserRole ) );
if ( mAutoRefresh )
refresh();
}
@@ -179,9 +179,9 @@ void QgsSettingsTree::showContextMenu( QPoint pos )
if ( !item )
return;

Type itemType = item->data( 0, TypeRole ).value< Type >();
const QString itemText = item->data( 0, Qt::DisplayRole ).toString();
const QString itemPath = item->data( 0, PathRole ).toString();
Type itemType = item->data( ColumnSettings, TypeRole ).value< Type >();
const QString itemText = item->data( ColumnSettings, Qt::DisplayRole ).toString();
const QString itemPath = item->data( ColumnSettings, PathRole ).toString();
mContextMenu->clear();

switch ( itemType )
@@ -240,16 +240,16 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent )
if ( childIndex != -1 )
{
child = childAt( parent, childIndex );
child->setText( 1, QString() );
child->setText( 2, QString() );
child->setData( 2, Qt::UserRole, QVariant() );
child->setText( ColumnType, QString() );
child->setText( ColumnValue, QString() );
child->setData( ColumnValue, Qt::UserRole, QVariant() );
moveItemForward( parent, childIndex, dividerIndex );
}
else
{
child = createItem( group, parent, dividerIndex, true );
}
child->setIcon( 0, mGroupIcon );
child->setIcon( ColumnSettings, mGroupIcon );
++dividerIndex;

mSettings->beginGroup( group );
@@ -276,7 +276,7 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent )
{
child = createItem( key, parent, dividerIndex, false );
}
child->setIcon( 0, mKeyIcon );
child->setIcon( ColumnSettings, mKeyIcon );
++dividerIndex;
}
else
@@ -287,14 +287,14 @@ void QgsSettingsTree::updateChildItems( QTreeWidgetItem *parent )
QVariant value = mSettings->value( key );
if ( value.type() == QVariant::Invalid )
{
child->setText( 1, QStringLiteral( "Invalid" ) );
child->setText( ColumnType, QStringLiteral( "Invalid" ) );
}
else
{
child->setText( 1, QVariant::typeToName( QgsVariantDelegate::type( value ) ) );
child->setText( ColumnType, QVariant::typeToName( QgsVariantDelegate::type( value ) ) );
}
child->setText( 2, QgsVariantDelegate::displayText( value ) );
child->setData( 2, Qt::UserRole, value );
child->setText( ColumnValue, QgsVariantDelegate::displayText( value ) );
child->setData( ColumnValue, Qt::UserRole, value );
}

while ( dividerIndex < childCount( parent ) )
@@ -314,26 +314,38 @@ QTreeWidgetItem *QgsSettingsTree::createItem( const QString &text,
else
item = new QTreeWidgetItem( this, after );

item->setText( 0, text );
item->setText( ColumnSettings, text );
if ( !isGroup )
item->setFlags( item->flags() | Qt::ItemIsEditable );

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

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

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

QString key = itemKey( item );
QgsDebugMsgLevel( key, 4 );
if ( mSettingsMap.contains( key ) )
{
QgsDebugMsgLevel( QStringLiteral( "contains!!!!" ), 4 );
QStringList values = mSettingsMap[ key ];
item->setText( 3, values.at( 0 ) );
item->setToolTip( 0, values.at( 1 ) );
item->setToolTip( 2, values.at( 1 ) );
item->setText( ColumnDescription, values.at( 0 ) );
item->setToolTip( ColumnDescription, values.at( 0 ) );
item->setToolTip( ColumnSettings, values.at( 1 ) );
item->setToolTip( ColumnValue, values.at( 1 ) );
}

// if ( settingsMap.contains(

return item;
}

@@ -342,11 +354,11 @@ QString QgsSettingsTree::itemKey( QTreeWidgetItem *item )
if ( ! item )
return QString();

QString key = item->text( 0 );
QString key = item->text( ColumnSettings );
QTreeWidgetItem *ancestor = item->parent();
while ( ancestor )
{
key.prepend( ancestor->text( 0 ) + '/' );
key.prepend( ancestor->text( ColumnSettings ) + '/' );
ancestor = ancestor->parent();
}

@@ -374,7 +386,7 @@ int QgsSettingsTree::findChild( QTreeWidgetItem *parent, const QString &text,
{
for ( int i = startIndex; i < childCount( parent ); ++i )
{
if ( childAt( parent, i )->text( 0 ) == text )
if ( childAt( parent, i )->text( ColumnSettings ) == text )
return i;
}
return -1;
@@ -89,6 +89,15 @@ class QgsSettingsTree : public QTreeWidget
void showContextMenu( QPoint pos );

private:

enum Columns
{
ColumnSettings = 0,
ColumnType,
ColumnValue,
ColumnDescription
};

void updateChildItems( QTreeWidgetItem *parent );
QTreeWidgetItem *createItem( const QString &text, QTreeWidgetItem *parent,
int index, bool isGroup );
@@ -471,7 +471,6 @@ set(QGIS_CORE_SRCS
qgsvirtuallayerdefinitionutils.cpp
qgsmapthemecollection.cpp
qgsxmlutils.cpp
qgssettings.cpp
qgsarchive.cpp
qgstestutils.cpp
qgsziputils.cpp
@@ -717,7 +716,9 @@ set(QGIS_CORE_SRCS
geocms/geonode/qgsgeonodeconnection.cpp
geocms/geonode/qgsgeonoderequest.cpp

settings/qgssettings.cpp
settings/qgssettingsentry.cpp
settings/qgssettingsregistry.cpp
settings/qgssettingsregistrycore.cpp

validity/qgsabstractvaliditycheck.cpp
@@ -1035,7 +1036,6 @@ set(QGIS_CORE_HDRS
qgsruntimeprofiler.h
qgsscalecalculator.h
qgsscaleutils.h
qgssettings.h
qgsshapegenerator.h
qgssimplifymethod.h
qgssnappingconfig.h
@@ -1561,7 +1561,9 @@ set(QGIS_CORE_HDRS
textrenderer/qgstextrendererutils.h
textrenderer/qgstextshadowsettings.h

settings/qgssettings.h
settings/qgssettingsentry.h
settings/qgssettingsregistry.h
settings/qgssettingsregistrycore.h

validity/qgsabstractvaliditycheck.h
File renamed without changes.
File renamed without changes.

0 comments on commit 96cee9f

Please sign in to comment.