This commit is contained in:
Denis Rouzaud 2023-04-23 08:10:37 +02:00
parent de1363df05
commit 7498d0994c
14 changed files with 72 additions and 32 deletions

View File

@ -347,13 +347,11 @@ class QgsSettingsEntryBaseTemplate : QgsSettingsEntryBase
{ {
%Docstring(signature="appended") %Docstring(signature="appended")
Base abstract class for settings entry which are passed by reference Base abstract class for settings entries with typed get and set methods
.. seealso:: :py:class:`QgsSettingsEntryBase` .. seealso:: :py:class:`QgsSettingsEntryBase`
.. seealso:: :py:class:`QgsSettingsEntryByValue` .. versionadded:: 3.32
.. versionadded:: 3.26
%End %End
%TypeHeaderCode %TypeHeaderCode

View File

@ -85,8 +85,14 @@ The wrapper must be configured before calling this medthod
protected: protected:
virtual QWidget *createEditorPrivate( QWidget *parent = 0 ) const = 0; virtual QWidget *createEditorPrivate( QWidget *parent = 0 ) const = 0;
%Docstring
Creates the widgets
%End
virtual bool configureEditorPrivate( QWidget *editor, const QgsSettingsEntryBase *setting ) = 0; virtual bool configureEditorPrivate( QWidget *editor, const QgsSettingsEntryBase *setting ) = 0;
%Docstring
Configures an existing widget
%End
}; };

View File

@ -27,6 +27,9 @@ This class is a base factory of editor for settings
%End %End
public: public:
QgsSettingsEditorWidgetWrapperTemplate( QObject *parent = 0 ); QgsSettingsEditorWidgetWrapperTemplate( QObject *parent = 0 );
%Docstring
Constructor
%End
virtual QString id() const = 0; virtual QString id() const = 0;
virtual bool setWidgetFromSetting() const; virtual bool setWidgetFromSetting() const;
@ -36,10 +39,16 @@ This class is a base factory of editor for settings
virtual void setWidgetFromVariant( const QVariant &value ) const; virtual void setWidgetFromVariant( const QVariant &value ) const;
virtual bool setWidgetValue( const U &value ) const = 0; virtual bool setWidgetValue( const U &value ) const = 0;
%Docstring
Sets the widget value
%End
virtual QVariant variantValueFromWidget() const; virtual QVariant variantValueFromWidget() const;
virtual U valueFromWidget() const = 0; virtual U valueFromWidget() const = 0;
%Docstring
Returns the widget value
%End
V *editor() const; V *editor() const;
%Docstring %Docstring
@ -83,6 +92,9 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString,QLineEdit,
%End %End
public: public:
QgsSettingsStringEditorWidgetWrapper( QObject *parent = 0 ); QgsSettingsStringEditorWidgetWrapper( QObject *parent = 0 );
%Docstring
Constructor
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const; virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -116,6 +128,9 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool,QCheckBox,bo
%End %End
public: public:
QgsSettingsBoolEditorWidgetWrapper( QObject *parent = 0 ); QgsSettingsBoolEditorWidgetWrapper( QObject *parent = 0 );
%Docstring
Constructor
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const; virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -149,6 +164,9 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger,QSpinBox,
%End %End
public: public:
QgsSettingsIntegerEditorWidgetWrapper( QObject *parent = 0 ); QgsSettingsIntegerEditorWidgetWrapper( QObject *parent = 0 );
%Docstring
Constructor
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const; virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -183,6 +201,9 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble,QDoubleSpi
%End %End
public: public:
QgsSettingsDoubleEditorWidgetWrapper( QObject *parent = 0 ); QgsSettingsDoubleEditorWidgetWrapper( QObject *parent = 0 );
%Docstring
Constructor
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const; virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -217,6 +238,9 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor,QgsColorBut
%End %End
public: public:
QgsSettingsColorEditorWidgetWrapper( QObject *parent = 0 ); QgsSettingsColorEditorWidgetWrapper( QObject *parent = 0 );
%Docstring
Constructor
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const; virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;

View File

@ -41,6 +41,9 @@ Constructor
~QgsSettingsTreeModel(); ~QgsSettingsTreeModel();
void applyChanges(); void applyChanges();
%Docstring
Apply pending changes in the model to the corresponding settings
%End

View File

@ -30,6 +30,9 @@ Constructor
void applyChanges() const; void applyChanges() const;
%Docstring
Apply changes to settings value
%End
}; };

View File

@ -57,8 +57,8 @@ QgsAdvancedSettingsWidget::~QgsAdvancedSettingsWidget()
void QgsAdvancedSettingsWidget::apply() void QgsAdvancedSettingsWidget::apply()
{ {
// mAdvancedSettingsEditor applies changes immediately // the old settings editor applies changes immediately
// new settings tree is performing changes on appy // new settings tree is performing changes on apply
if ( mTreeWidget ) if ( mTreeWidget )
mTreeWidget->applyChanges(); mTreeWidget->applyChanges();

View File

@ -353,13 +353,12 @@ class CORE_EXPORT QgsSettingsEntryBase
/** /**
* \ingroup core * \ingroup core
* \class QgsSettingsEntryByReference * \class QgsSettingsEntryBaseTemplate
* *
* \brief Base abstract class for settings entry which are passed by reference * \brief Base abstract class for settings entries with typed get and set methods
* \see QgsSettingsEntryBase * \see QgsSettingsEntryBase
* \see QgsSettingsEntryByValue
* *
* \since QGIS 3.26 * \since QGIS 3.32
*/ */
template<class T> template<class T>
class QgsSettingsEntryBaseTemplate : public QgsSettingsEntryBase class QgsSettingsEntryBaseTemplate : public QgsSettingsEntryBase

View File

@ -1,5 +1,5 @@
/*************************************************************************** /***************************************************************************
qgssettingsfactoryfactoryregistry.cpp qgssettingseditorwidgetregistry.cpp
--------------------- ---------------------
begin : April 2023 begin : April 2023
copyright : (C) 2023 by Denis Rouzaud copyright : (C) 2023 by Denis Rouzaud
@ -66,7 +66,3 @@ QWidget *QgsSettingsEditorWidgetRegistry::createEditor( const QgsSettingsEntryBa
else else
return nullptr; return nullptr;
} }

View File

@ -28,7 +28,7 @@ class QgsSettingsEditorWidgetWrapper;
/** /**
* \ingroup gui * \ingroup gui
* \brief This class manages editors for settings * \brief This class manages editor widgets for settings
* *
* \since QGIS 3.32 * \since QGIS 3.32
*/ */
@ -40,15 +40,15 @@ class GUI_EXPORT QgsSettingsEditorWidgetRegistry
~QgsSettingsEditorWidgetRegistry(); ~QgsSettingsEditorWidgetRegistry();
/** /**
* Adds a editor to the registry * Adds an editor widget \a wrapper to the registry
* Returns FALSE if a editor with same id already exists. * Returns FALSE if an editor widget with same id already exists.
*/ */
bool addWrapper( QgsSettingsEditorWidgetWrapper *wrapper SIP_TRANSFER ); bool addWrapper( QgsSettingsEditorWidgetWrapper *wrapper SIP_TRANSFER );
//! Returns a new instance of the editor for the given id //! Returns a new instance of the editor widget for the given \a id
QgsSettingsEditorWidgetWrapper *createWrapper( const QString &id, QObject *parent ) const; QgsSettingsEditorWidgetWrapper *createWrapper( const QString &id, QObject *parent ) const;
//! Creates the editor for the given settings using the corresponding registered wrapper //! Creates an editor widget for the given \a setting using the corresponding registered wrapper
QWidget *createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent = nullptr ) const SIP_FACTORY; QWidget *createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList, QWidget *parent = nullptr ) const SIP_FACTORY;
//! Returns a map <name, id> of all registered editors. //! Returns a map <name, id> of all registered editors.

View File

@ -44,7 +44,7 @@ QWidget *QgsSettingsEditorWidgetWrapper::createEditor( const QgsSettingsEntryBas
if ( configureEditor( editor, setting, dynamicKeyPartList ) ) if ( configureEditor( editor, setting, dynamicKeyPartList ) )
return editor; return editor;
else else
QgsDebugMsg( QStringLiteral( "editor could not be confiugured" ) ); QgsDebugMsg( QStringLiteral( "editor could not be configured" ) );
return nullptr; return nullptr;
} }

View File

@ -33,7 +33,7 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapper : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
//! Creates a wrapper from the definition stored in a widget created by createEditor() //! Creates a wrapper from the definition stored in a \a widget created by createEditor()
static QgsSettingsEditorWidgetWrapper *fromWidget( const QWidget *widget ) SIP_FACTORY; static QgsSettingsEditorWidgetWrapper *fromWidget( const QWidget *widget ) SIP_FACTORY;
//! Constructor //! Constructor
@ -50,7 +50,7 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapper : public QObject
//! Creates a new instance of the editor wrapper so it can be configured for a widget and a setting //! Creates a new instance of the editor wrapper so it can be configured for a widget and a setting
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const = 0; virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const = 0;
//! Creates the editor for the given widget //! Creates the editor widget for the given \a setting
QWidget *createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList(), QWidget *parent = nullptr ); QWidget *createEditor( const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList(), QWidget *parent = nullptr );
//! Configures the \a editor according the setting //! Configures the \a editor according the setting
@ -63,7 +63,7 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapper : public QObject
virtual bool setWidgetFromSetting() const = 0; virtual bool setWidgetFromSetting() const = 0;
/** /**
* SDets the setting value from the widget value * Sets the setting value from the widget value
* The wrapper must be configured before calling this medthod * The wrapper must be configured before calling this medthod
*/ */
virtual bool setSettingFromWidget() const = 0; virtual bool setSettingFromWidget() const = 0;
@ -75,15 +75,17 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapper : public QObject
virtual QVariant variantValueFromWidget() const = 0; virtual QVariant variantValueFromWidget() const = 0;
/** /**
* Sets the value of the widget * Sets the \a value of the widget
* The wrapper must be configured before calling this medthod * The wrapper must be configured before calling this medthod
*/ */
virtual void setWidgetFromVariant( const QVariant &value ) const = 0; virtual void setWidgetFromVariant( const QVariant &value ) const = 0;
protected: protected:
//! Creates the widgets
virtual QWidget *createEditorPrivate( QWidget *parent = nullptr ) const = 0; virtual QWidget *createEditorPrivate( QWidget *parent = nullptr ) const = 0;
//! Configures an existing \a editor widget
virtual bool configureEditorPrivate( QWidget *editor, const QgsSettingsEntryBase *setting ) = 0; virtual bool configureEditorPrivate( QWidget *editor, const QgsSettingsEntryBase *setting ) = 0;
QStringList mDynamicKeyPartList; QStringList mDynamicKeyPartList;

View File

@ -45,6 +45,7 @@ template<class T, class V, class U>
class GUI_EXPORT QgsSettingsEditorWidgetWrapperTemplate : public QgsSettingsEditorWidgetWrapper class GUI_EXPORT QgsSettingsEditorWidgetWrapperTemplate : public QgsSettingsEditorWidgetWrapper
{ {
public: public:
//! Constructor
QgsSettingsEditorWidgetWrapperTemplate( QObject *parent = nullptr ) QgsSettingsEditorWidgetWrapperTemplate( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapper( parent ) {} : QgsSettingsEditorWidgetWrapper( parent ) {}
@ -66,6 +67,7 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapperTemplate : public QgsSettingsEdit
setWidgetValue( mSetting->convertFromVariant( value ) ); setWidgetValue( mSetting->convertFromVariant( value ) );
} }
//! Sets the widget value
virtual bool setWidgetValue( const U &value ) const = 0; virtual bool setWidgetValue( const U &value ) const = 0;
QVariant variantValueFromWidget() const override QVariant variantValueFromWidget() const override
@ -73,6 +75,7 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapperTemplate : public QgsSettingsEdit
return valueFromWidget(); return valueFromWidget();
}; };
//! Returns the widget value
virtual U valueFromWidget() const = 0; virtual U valueFromWidget() const = 0;
//! Returns the editor //! Returns the editor
@ -120,6 +123,7 @@ class GUI_EXPORT QgsSettingsEditorWidgetWrapperTemplate : public QgsSettingsEdit
class GUI_EXPORT QgsSettingsStringEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString> class GUI_EXPORT QgsSettingsStringEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>
{ {
public: public:
//! Constructor
QgsSettingsStringEditorWidgetWrapper( QObject *parent = nullptr ) QgsSettingsStringEditorWidgetWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( parent ) {} : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( parent ) {}
@ -143,6 +147,7 @@ class GUI_EXPORT QgsSettingsStringEditorWidgetWrapper : public QgsSettingsEditor
class GUI_EXPORT QgsSettingsBoolEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool> class GUI_EXPORT QgsSettingsBoolEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>
{ {
public: public:
//! Constructor
QgsSettingsBoolEditorWidgetWrapper( QObject *parent = nullptr ) QgsSettingsBoolEditorWidgetWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {} : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {}
@ -166,6 +171,7 @@ class GUI_EXPORT QgsSettingsBoolEditorWidgetWrapper : public QgsSettingsEditorWi
class GUI_EXPORT QgsSettingsIntegerEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int> class GUI_EXPORT QgsSettingsIntegerEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>
{ {
public: public:
//! Constructor
QgsSettingsIntegerEditorWidgetWrapper( QObject *parent = nullptr ) QgsSettingsIntegerEditorWidgetWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>( parent ) {} : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>( parent ) {}
@ -190,6 +196,7 @@ class GUI_EXPORT QgsSettingsIntegerEditorWidgetWrapper : public QgsSettingsEdito
class GUI_EXPORT QgsSettingsDoubleEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double> class GUI_EXPORT QgsSettingsDoubleEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>
{ {
public: public:
//! Constructor
QgsSettingsDoubleEditorWidgetWrapper( QObject *parent = nullptr ) QgsSettingsDoubleEditorWidgetWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {} : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {}
@ -214,6 +221,7 @@ class GUI_EXPORT QgsSettingsDoubleEditorWidgetWrapper : public QgsSettingsEditor
class GUI_EXPORT QgsSettingsColorEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor> class GUI_EXPORT QgsSettingsColorEditorWidgetWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>
{ {
public: public:
//! Constructor
QgsSettingsColorEditorWidgetWrapper( QObject *parent = nullptr ) QgsSettingsColorEditorWidgetWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>( parent ) {} : QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>( parent ) {}

View File

@ -63,10 +63,10 @@ class GUI_EXPORT QgsSettingsTreeModelNodeData : public QObject
void applyChanges(); void applyChanges();
//! Returns if the node is the root node //! Returns if the node is the root node
bool isRoot() const {return mParent == nullptr;} bool isRoot() const { return mParent == nullptr; }
//! Returns the dynamic key parts of the named list parent tree nodes //! Returns the dynamic key parts of the named list parent tree nodes
QStringList namedParentNodes() const {return mNamedParentNodes;} QStringList namedParentNodes() const { return mNamedParentNodes; }
//! Returns the children nodes of the node (setting or tree node) //! Returns the children nodes of the node (setting or tree node)
QList<QgsSettingsTreeModelNodeData *> children() const {return mChildren;} QList<QgsSettingsTreeModelNodeData *> children() const {return mChildren;}
@ -86,7 +86,7 @@ class GUI_EXPORT QgsSettingsTreeModelNodeData : public QObject
//! Returns the value of the node (setting or tree node) //! Returns the value of the node (setting or tree node)
QVariant originalValue() const {return mOriginalValue;} QVariant originalValue() const {return mOriginalValue;}
//! Sets the value of the setting node //! Sets the \a value of the setting node
bool setValue( const QVariant &value ); bool setValue( const QVariant &value );
//! Returns if the setting exists (value is set) //! Returns if the setting exists (value is set)
@ -96,8 +96,8 @@ class GUI_EXPORT QgsSettingsTreeModelNodeData : public QObject
bool isEdited() const {return mIsEdited;} bool isEdited() const {return mIsEdited;}
/** /**
* Returns the setting of the node * Returns a pointer to the setting of the node or NULLPTR if the
* It returns a nullptr if the setting does not exist * setting does not exist.
*/ */
const QgsSettingsEntryBase *setting() const {return mSetting;} const QgsSettingsEntryBase *setting() const {return mSetting;}
@ -179,10 +179,11 @@ class GUI_EXPORT QgsSettingsTreeModel : public QAbstractItemModel
~QgsSettingsTreeModel(); ~QgsSettingsTreeModel();
//! Apply pending changes in the model to the corresponding settings
void applyChanges(); void applyChanges();
/** /**
* Returns settings tree node for given index. Returns root node for invalid index. * Returns settings tree node for given \a index or the root node if the index is invalid.
*/ */
QgsSettingsTreeModelNodeData *index2node( const QModelIndex &index ) const SIP_SKIP; QgsSettingsTreeModelNodeData *index2node( const QModelIndex &index ) const SIP_SKIP;

View File

@ -39,7 +39,7 @@ class GUI_EXPORT QgsSettingsTreeWidget : public QWidget
explicit QgsSettingsTreeWidget( QWidget *parent = nullptr ); explicit QgsSettingsTreeWidget( QWidget *parent = nullptr );
// Apply changes to settings value //! Apply changes to settings value
void applyChanges() const; void applyChanges() const;
private: private: