mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-05 00:09:32 -04:00
allow to specify data role in QgsSettingsStringComboBoxWrapper
This commit is contained in:
parent
90528a1937
commit
ef23a603cf
@ -160,6 +160,12 @@ Constructor of the wrapper for a given ``setting`` and its widget
|
||||
%Docstring
|
||||
Constructor of the wrapper for a given ``setting`` and its widget
|
||||
``editor``
|
||||
%End
|
||||
|
||||
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, int role, 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;
|
||||
|
@ -160,6 +160,12 @@ Constructor of the wrapper for a given ``setting`` and its widget
|
||||
%Docstring
|
||||
Constructor of the wrapper for a given ``setting`` and its widget
|
||||
``editor``
|
||||
%End
|
||||
|
||||
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, int role, 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;
|
||||
|
@ -94,7 +94,7 @@ bool QgsSettingsStringComboBoxWrapper::setWidgetValue( const QString &value ) co
|
||||
{
|
||||
if ( mEditor )
|
||||
{
|
||||
int idx = mMode == Mode::Data ? mEditor->findData( value ) : mEditor->findText( value );
|
||||
int idx = mMode == Mode::Data ? mEditor->findData( value, mDataRole ) : mEditor->findText( value );
|
||||
if ( idx >= 0 )
|
||||
{
|
||||
mEditor->setCurrentIndex( idx );
|
||||
@ -140,7 +140,7 @@ QString QgsSettingsStringComboBoxWrapper::valueFromWidget() const
|
||||
{
|
||||
if ( mEditor )
|
||||
{
|
||||
return mMode == Mode::Data ? mEditor->currentData().toString() : mEditor->currentText();
|
||||
return mMode == Mode::Data ? mEditor->currentData( mDataRole ).toString() : mEditor->currentText();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -178,6 +178,10 @@ class GUI_EXPORT QgsSettingsStringComboBoxWrapper : public QgsSettingsEditorWidg
|
||||
QgsSettingsStringComboBoxWrapper( QWidget *editor, const QgsSettingsEntryBase *setting, Mode mode, const QStringList &dynamicKeyPartList = QStringList() )
|
||||
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( editor ), mMode( mode ) { 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, int role, const QStringList &dynamicKeyPartList = QStringList() )
|
||||
: QgsSettingsEditorWidgetWrapperTemplate<QgsSettingsEntryString, QComboBox, QString>( editor ), mMode( mode ), mDataRole( role ) { configureEditor( editor, setting, dynamicKeyPartList ); }
|
||||
|
||||
QgsSettingsEditorWidgetWrapper *createWrapper( QObject *parent = nullptr ) const override { return new QgsSettingsStringComboBoxWrapper( parent ); }
|
||||
|
||||
QString id() const override;
|
||||
@ -192,6 +196,7 @@ class GUI_EXPORT QgsSettingsStringComboBoxWrapper : public QgsSettingsEditorWidg
|
||||
|
||||
private:
|
||||
Mode mMode = Mode::Text;
|
||||
int mDataRole = Qt::UserRole; // Default to UserRole, can be changed in the constructor
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user