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 ) {
56 virtual QString
id()
const override
58 return QStringLiteral(
"%1-%2" ).arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<FLAGS>().name() );
71 this->mSetting->setValue( this->
valueFromWidget(), this->mDynamicKeyPartList );
76 QgsDebugMsgLevel( QStringLiteral(
"Settings editor not set for %1" ).arg( this->mSetting->definitionKey() ), 2 );
86 for (
int r = 0; r < mModel.rowCount(); r++ )
88 QStandardItem *item = mModel.item( r );
89 if ( item->data( Qt::CheckStateRole ) == Qt::Checked )
90 value |= item->data().value<ENUM>();
96 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
105 for (
int r = 0; r < mModel.rowCount(); r++ )
107 QStandardItem *item = mModel.item( r );
108 bool isChecked = value.testFlag( item->data().value<ENUM>() );
109 item->setData( isChecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
115 QgsDebugMsgLevel( QStringLiteral(
"Settings editor not set for %1" ).arg( this->mSetting->definitionKey() ), 2 );
124 const QMap<ENUM, QString> enumMap = qgsEnumMap<ENUM>();
125 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
127 QStandardItem *item =
new QStandardItem( it.value() );
128 item->setData( QVariant::fromValue( it.key() ) );
129 item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
130 item->setData( Qt::Unchecked, Qt::CheckStateRole );
131 mModel.appendRow( item );
133 this->mEditor->setModel( &mModel );
156 QObject::connect( this->
mEditor, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [=](
int index ) {
158 ENUM value = this->
mEditor->currentData().template value<ENUM>();
163 virtual QString
id()
const override
165 return QStringLiteral(
"%1-%2" ).arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<ENUM>().name() );
173 void setDisplayStrings(
const QMap<ENUM, QString> &displayStrings ) { mDisplayStrings = displayStrings; }
201 return this->
mEditor->currentData().template value<ENUM>();
205 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
214 int i = this->
mEditor->findData( QVariant::fromValue( value ) );
215 this->
mEditor->setCurrentIndex( i );
228 const QMap<ENUM, QString> enumMap = qgsEnumMap<ENUM>();
229 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
231 const QString displayString = mDisplayStrings.value( it.key(), it.value() );
232 this->
mEditor->addItem( displayString, QVariant::fromValue( it.key() ) );
237 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)