settings edtior wrappers: add direct constructor + add combo box editor for strings

this improves the usage from Python plugins
This commit is contained in:
Denis Rouzaud 2024-10-07 07:25:47 +02:00
parent 789fd9c3b7
commit c75588d84a
6 changed files with 346 additions and 16 deletions

View File

@ -1,4 +1,14 @@
# The following has been generated automatically from src/gui/settings/qgssettingseditorwidgetwrapperimpl.h
# monkey patching scoped based enum
QgsSettingsStringComboBoxWrapper.Mode.Text.__doc__ = "Value is defined as the text entry"
QgsSettingsStringComboBoxWrapper.Mode.Data.__doc__ = "Value is defined as data entry with Qt.UserRole"
QgsSettingsStringComboBoxWrapper.Mode.__doc__ = """Mode to determine if the value is hold in the combo box text or data
* ``Text``: Value is defined as the text entry
* ``Data``: Value is defined as data entry with Qt.UserRole
"""
# --
try:
QgsSettingsEditorWidgetWrapperTemplate.__group__ = ['settings']
except NameError:
@ -7,6 +17,10 @@ try:
QgsSettingsStringLineEditWrapper.__group__ = ['settings']
except NameError:
pass
try:
QgsSettingsStringComboBoxWrapper.__group__ = ['settings']
except NameError:
pass
try:
QgsSettingsBoolCheckBoxWrapper.__group__ = ['settings']
except NameError:

View File

@ -93,7 +93,69 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString,QLineEdit,
public:
QgsSettingsStringLineEditWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsStringLineEditWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
virtual QString id() const;
virtual bool setSettingFromWidget() const;
virtual QString valueFromWidget() const;
virtual bool setWidgetValue( const QString &value ) const;
virtual void enableAutomaticUpdatePrivate();
};
typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString,QComboBox,QString> QgsSettingsEditorWidgetWrapperTemplateQgsSettingsEntryStringQComboBoxQStringBase;
class QgsSettingsStringComboBoxWrapper : QgsSettingsEditorWidgetWrapperTemplateQgsSettingsEntryStringQComboBoxQStringBase
{
%Docstring(signature="appended")
This class is a factory of editor for string settings with a combo box
.. versionadded:: 3.40
%End
%TypeHeaderCode
#include "qgssettingseditorwidgetwrapperimpl.h"
typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString,QComboBox,QString> QgsSettingsEditorWidgetWrapperTemplateQgsSettingsEntryStringQComboBoxQStringBase;
%End
public:
enum class Mode /BaseType=IntEnum/
{
Text,
Data
};
QgsSettingsStringComboBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor of the factory
%End
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -112,6 +174,7 @@ Constructor
virtual void enableAutomaticUpdatePrivate();
};
@ -133,7 +196,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool,QCheckBox,bo
public:
QgsSettingsBoolCheckBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsBoolCheckBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -172,7 +240,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger,QSpinBox,
public:
QgsSettingsIntegerSpinBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsIntegerSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -212,7 +285,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble,QDoubleSpi
public:
QgsSettingsDoubleSpinBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsDoubleSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -252,7 +330,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor,QgsColorBut
public:
QgsSettingsColorButtonWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsColorButtonWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;

View File

@ -1,4 +1,14 @@
# The following has been generated automatically from src/gui/settings/qgssettingseditorwidgetwrapperimpl.h
# monkey patching scoped based enum
QgsSettingsStringComboBoxWrapper.Mode.Text.__doc__ = "Value is defined as the text entry"
QgsSettingsStringComboBoxWrapper.Mode.Data.__doc__ = "Value is defined as data entry with Qt.UserRole"
QgsSettingsStringComboBoxWrapper.Mode.__doc__ = """Mode to determine if the value is hold in the combo box text or data
* ``Text``: Value is defined as the text entry
* ``Data``: Value is defined as data entry with Qt.UserRole
"""
# --
try:
QgsSettingsEditorWidgetWrapperTemplate.__group__ = ['settings']
except NameError:
@ -7,6 +17,10 @@ try:
QgsSettingsStringLineEditWrapper.__group__ = ['settings']
except NameError:
pass
try:
QgsSettingsStringComboBoxWrapper.__group__ = ['settings']
except NameError:
pass
try:
QgsSettingsBoolCheckBoxWrapper.__group__ = ['settings']
except NameError:

View File

@ -93,7 +93,69 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString,QLineEdit,
public:
QgsSettingsStringLineEditWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsStringLineEditWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
virtual QString id() const;
virtual bool setSettingFromWidget() const;
virtual QString valueFromWidget() const;
virtual bool setWidgetValue( const QString &value ) const;
virtual void enableAutomaticUpdatePrivate();
};
typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString,QComboBox,QString> QgsSettingsEditorWidgetWrapperTemplateQgsSettingsEntryStringQComboBoxQStringBase;
class QgsSettingsStringComboBoxWrapper : QgsSettingsEditorWidgetWrapperTemplateQgsSettingsEntryStringQComboBoxQStringBase
{
%Docstring(signature="appended")
This class is a factory of editor for string settings with a combo box
.. versionadded:: 3.40
%End
%TypeHeaderCode
#include "qgssettingseditorwidgetwrapperimpl.h"
typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString,QComboBox,QString> QgsSettingsEditorWidgetWrapperTemplateQgsSettingsEntryStringQComboBoxQStringBase;
%End
public:
enum class Mode
{
Text,
Data
};
QgsSettingsStringComboBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor of the factory
%End
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -112,6 +174,7 @@ Constructor
virtual void enableAutomaticUpdatePrivate();
};
@ -133,7 +196,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool,QCheckBox,bo
public:
QgsSettingsBoolCheckBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsBoolCheckBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -172,7 +240,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger,QSpinBox,
public:
QgsSettingsIntegerSpinBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsIntegerSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -212,7 +285,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble,QDoubleSpi
public:
QgsSettingsDoubleSpinBoxWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsDoubleSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;
@ -252,7 +330,12 @@ typedef QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor,QgsColorBut
public:
QgsSettingsColorButtonWrapper( QObject *parent = 0 );
%Docstring
Constructor
Constructor of the factory
%End
QgsSettingsColorButtonWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() );
%Docstring
Constructor of the wrapper for a given ``setting`` and its widget ``editor``
%End
virtual QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = 0 ) const;

View File

@ -24,7 +24,7 @@
// *******
// String
// String with line edit (= default)
// *******
QString QgsSettingsStringLineEditWrapper::id() const
@ -81,6 +81,75 @@ QString QgsSettingsStringLineEditWrapper::valueFromWidget() const
return QString();
}
// *******
// String with combo box
// *******
QString QgsSettingsStringComboBoxWrapper::id() const
{
return QString::fromUtf8( sSettingsTypeMetaEnum.valueToKey( static_cast<int>( Qgis::SettingsType::String ) ) );
}
bool QgsSettingsStringComboBoxWrapper::setWidgetValue( const QString &value ) const
{
if ( mEditor )
{
int idx = mMode == Mode::Data ? mEditor->findData( value ) : mEditor->findText( value );
if ( idx >= 0 )
{
mEditor->setCurrentIndex( idx );
return true;
}
else
{
return false;
}
}
else
{
QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
}
return false;
}
void QgsSettingsStringComboBoxWrapper::enableAutomaticUpdatePrivate()
{
QObject::connect( this->mEditor, &QComboBox::currentTextChanged, this, [ = ]( const QString & currentText )
{
QString textValue = currentText;
if ( mMode == Mode::Data )
textValue = mEditor->currentData().toString();
this->mSetting->setValue( textValue, this->mDynamicKeyPartList );
} );
}
bool QgsSettingsStringComboBoxWrapper::setSettingFromWidget() const
{
if ( mEditor )
{
mSetting->setValue( valueFromWidget(), mDynamicKeyPartList );
return true;
}
else
{
QgsDebugError( QStringLiteral( "Settings editor not set for %1" ).arg( mSetting->definitionKey() ) );
}
return false;
}
QString QgsSettingsStringComboBoxWrapper::valueFromWidget() const
{
if ( mEditor )
{
return mMode == Mode::Data ? mEditor->currentData().toString() : mEditor->currentText();
}
else
{
QgsDebugError( QString( "editor is not set, returning a non-existing value" ) );
}
return QString();
}
// *******
// Boolean
// *******

View File

@ -126,10 +126,15 @@ class GUI_EXPORT QgsSettingsStringLineEditWrapper : public QgsSettingsEditorWidg
{
Q_OBJECT
public:
//! Constructor
//! Constructor of the factory
QgsSettingsStringLineEditWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( parent ) {}
//! Constructor of the wrapper for a given \a setting and its widget \a editor
QgsSettingsStringLineEditWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QLineEdit, QString>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsStringLineEditWrapper( parent );}
QString id() const override;
@ -144,6 +149,52 @@ class GUI_EXPORT QgsSettingsStringLineEditWrapper : public QgsSettingsEditorWidg
};
/**
* \ingroup gui
* \brief This class is a factory of editor for string settings with a combo box
*
* \since QGIS 3.40
*/
class GUI_EXPORT QgsSettingsStringComboBoxWrapper : public QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>
{
Q_OBJECT
public:
//! Mode to determine if the value is hold in the combo box text or data
enum class Mode : int
{
Text, //!< Value is defined as the text entry
Data //!< Value is defined as data entry with Qt::UserRole
};
//! Constructor of the factory
QgsSettingsStringComboBoxWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( parent ) {}
//! Constructor of the wrapper for a given \a setting and its widget \a editor
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
//! Constructor of the wrapper for a given \a setting and its widget \a editor
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, const QStringList &dynamicKeyPartList = QStringList() )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( editor ), mMode( mode ) { configureEditor( editor, setting, dynamicKeyPartList ); }
QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsStringComboBoxWrapper( parent );}
QString id() const override;
bool setSettingFromWidget() const override;
QString valueFromWidget() const override;
bool setWidgetValue( const QString &value ) const override;
void enableAutomaticUpdatePrivate() override;
private:
Mode mMode = Mode::Text;
};
/**
* \ingroup gui
* \brief This class is a factory of editor for boolean settings with a checkbox
@ -154,10 +205,14 @@ class GUI_EXPORT QgsSettingsBoolCheckBoxWrapper : public QgsSettingsEditorWidget
{
Q_OBJECT
public:
//! Constructor
//! Constructor of the factory
QgsSettingsBoolCheckBoxWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( parent ) {}
//! Constructor of the wrapper for a given \a setting and its widget \a editor
QgsSettingsBoolCheckBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryBool, QCheckBox, bool>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsBoolCheckBoxWrapper( parent );}
QString id() const override;
@ -181,10 +236,14 @@ class GUI_EXPORT QgsSettingsIntegerSpinBoxWrapper : public QgsSettingsEditorWidg
{
Q_OBJECT
public:
//! Constructor
//! Constructor of the factory
QgsSettingsIntegerSpinBoxWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>( parent ) {}
//! Constructor of the wrapper for a given \a setting and its widget \a editor
QgsSettingsIntegerSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryInteger, QSpinBox, int>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsIntegerSpinBoxWrapper( parent );}
QString id() const override;
@ -209,10 +268,14 @@ class GUI_EXPORT QgsSettingsDoubleSpinBoxWrapper : public QgsSettingsEditorWidge
{
Q_OBJECT
public:
//! Constructor
//! Constructor of the factory
QgsSettingsDoubleSpinBoxWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( parent ) {}
//! Constructor of the wrapper for a given \a setting and its widget \a editor
QgsSettingsDoubleSpinBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryDouble, QDoubleSpinBox, double>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsDoubleSpinBoxWrapper( parent );}
QString id() const override;
@ -237,10 +300,14 @@ class GUI_EXPORT QgsSettingsColorButtonWrapper : public QgsSettingsEditorWidgetW
{
Q_OBJECT
public:
//! Constructor
//! Constructor of the factory
QgsSettingsColorButtonWrapper( QObject *parent = nullptr )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>( parent ) {}
//! Constructor of the wrapper for a given \a setting and its widget \a editor
QgsSettingsColorButtonWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, const QStringList &dynamicKeyPartList = QStringList() )
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryColor, QgsColorButton, QColor>( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); }
QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsColorButtonWrapper( parent );}
QString id() const override;