diff --git a/python/PyQt6/gui/auto_additions/qgssettingseditorwidgetwrapperimpl.py b/python/PyQt6/gui/auto_additions/qgssettingseditorwidgetwrapperimpl.py index 09e5cbb4525..b05c219e8d3 100644 --- a/python/PyQt6/gui/auto_additions/qgssettingseditorwidgetwrapperimpl.py +++ b/python/PyQt6/gui/auto_additions/qgssettingseditorwidgetwrapperimpl.py @@ -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: diff --git a/python/PyQt6/gui/auto_generated/settings/qgssettingseditorwidgetwrapperimpl.sip.in b/python/PyQt6/gui/auto_generated/settings/qgssettingseditorwidgetwrapperimpl.sip.in index e4c9ffada89..9f0fb0b0965 100644 --- a/python/PyQt6/gui/auto_generated/settings/qgssettingseditorwidgetwrapperimpl.sip.in +++ b/python/PyQt6/gui/auto_generated/settings/qgssettingseditorwidgetwrapperimpl.sip.in @@ -93,7 +93,69 @@ typedef QgsSettingsEditorWidgetWrapperTemplate 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 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 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 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( 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 // ******* diff --git a/src/gui/settings/qgssettingseditorwidgetwrapperimpl.h b/src/gui/settings/qgssettingseditorwidgetwrapperimpl.h index a45989648cd..d5d93de353a 100644 --- a/src/gui/settings/qgssettingseditorwidgetwrapperimpl.h +++ b/src/gui/settings/qgssettingseditorwidgetwrapperimpl.h @@ -126,10 +126,15 @@ class GUI_EXPORT QgsSettingsStringLineEditWrapper : public QgsSettingsEditorWidg { Q_OBJECT public: - //! Constructor + //! Constructor of the factory QgsSettingsStringLineEditWrapper( QObject *parent = nullptr ) : QgsSettingsEditorWidgetWrapperTemplate( 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( 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 +{ + 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( 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( 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( 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( 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( 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( 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( 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( 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( 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( 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( editor ) { configureEditor( editor, setting, dynamicKeyPartList ); } + QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override {return new QgsSettingsColorButtonWrapper( parent );} QString id() const override;