16#ifndef QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
17#define QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
29#include <QStandardItemModel>
37template <
class ENUM,
class FLAGS>
48 QObject::connect( &mModel, &QStandardItemModel::itemChanged,
this, [ = ](
const QStandardItem * item )
57 virtual QString
id()
const override
59 return QStringLiteral(
"%1-%2" ).arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<FLAGS>().name() );
72 this->mSetting->setValue( this->
valueFromWidget(), this->mDynamicKeyPartList );
77 QgsDebugMsgLevel( QStringLiteral(
"Settings editor not set for %1" ).arg( this->mSetting->definitionKey() ), 2 );
87 for (
int r = 0; r < mModel.rowCount(); r++ )
89 QStandardItem *item = mModel.item( r );
90 if ( item->data( Qt::CheckStateRole ) == Qt::Checked )
91 value |= item->data().value<ENUM>();
97 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
106 for (
int r = 0; r < mModel.rowCount(); r++ )
108 QStandardItem *item = mModel.item( r );
109 bool isChecked = value.testFlag( item->data().value<ENUM>() );
110 item->setData( isChecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
116 QgsDebugMsgLevel( QStringLiteral(
"Settings editor not set for %1" ).arg( this->mSetting->definitionKey() ), 2 );
126 const QMap<ENUM, QString> enumMap = qgsEnumMap<ENUM>();
127 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
129 QStandardItem *item =
new QStandardItem( it.value() );
130 item->setData( QVariant::fromValue( it.key() ) );
131 item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
132 item->setData( Qt::Unchecked, Qt::CheckStateRole );
133 mModel.appendRow( item );
135 this->mEditor->setModel( &mModel );
158 QObject::connect( this->
mEditor, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [ = ](
int index )
161 ENUM value = this->
mEditor->currentData().template value<ENUM>();
166 virtual QString
id()
const override
168 return QStringLiteral(
"%1-%2" ).arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<ENUM>().name() );
176 void setDisplayStrings(
const QMap<ENUM, QString> &displayStrings ) { mDisplayStrings = displayStrings; }
204 return this->
mEditor->currentData().template value<ENUM>();
208 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
217 int i = this->
mEditor->findData( QVariant::fromValue( value ) );
218 this->
mEditor->setCurrentIndex( i );
232 const QMap<ENUM, QString> enumMap = qgsEnumMap<ENUM>();
233 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
235 const QString displayString = mDisplayStrings.value( it.key(), it.value() );
236 this->
mEditor->addItem( displayString, QVariant::fromValue( it.key() ) );
241 QMap<ENUM, QString> mDisplayStrings;
bool setValue(const T &value, const QString &dynamicKeyPart=QString()) const
Set settings value.
QString definitionKey() const
Returns settings entry defining key.
A template class for enum and flag settings entry.
QVariant convertToVariant(const T &value) const override
Converts the value to a variant.
#define QgsDebugMsgLevel(str, level)