16#ifndef QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
17#define QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
29#include <QStandardItemModel>
37template <
class ENUM,
class FLAGS>
48 virtual QString
id()
const override
50 return QStringLiteral(
"%1-%2" ).arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<FLAGS>().name() );
63 this->mSetting->setValue( this->
valueFromWidget(), this->mDynamicKeyPartList );
68 QgsDebugMsgLevel( QStringLiteral(
"Settings editor not set for %1" ).arg( this->mSetting->definitionKey() ), 2 );
78 for (
int r = 0; r < mModel.rowCount(); r++ )
80 QStandardItem *item = mModel.item( r );
81 if ( item->data( Qt::CheckStateRole ) == Qt::Checked )
82 value |= item->data().value<ENUM>();
88 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
97 for (
int r = 0; r < mModel.rowCount(); r++ )
99 QStandardItem *item = mModel.item( r );
100 bool isChecked = value.testFlag( item->data().value<ENUM>() );
101 item->setData( isChecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
107 QgsDebugMsgLevel( QStringLiteral(
"Settings editor not set for %1" ).arg( this->mSetting->definitionKey() ), 2 );
117 const QMap<ENUM, QString> enumMap = qgsEnumMap<ENUM>();
118 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
120 QStandardItem *item =
new QStandardItem( it.value() );
121 item->setData( QVariant::fromValue( it.key() ) );
122 item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
123 item->setData( Qt::Unchecked, Qt::CheckStateRole );
124 mModel.appendRow( item );
126 this->mEditor->setModel( &mModel );
147 virtual QString
id()
const override
149 return QStringLiteral(
"%1-%2" ).arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<ENUM>().name() );
178 return this->
mEditor->currentData().template value<ENUM>();
182 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
191 int i = this->
mEditor->findData( QVariant::fromValue( value ) );
192 this->
mEditor->setCurrentIndex( i );
206 const QMap<ENUM, QString> enumMap = qgsEnumMap<ENUM>();
207 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
209 this->
mEditor->addItem( it.value(), QVariant::fromValue( it.key() ) );
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)