16#ifndef QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
17#define QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
27#include <QStandardItemModel>
32using namespace Qt::StringLiterals;
40template<
class ENUM,
class FLAGS>
51 QObject::connect( &
mModel, &QStandardItemModel::itemChanged,
this, [
this](
const QStandardItem *item ) {
59 QString
id()
const override
61 return u
"%1-%2"_s.arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<FLAGS>().name() );
79 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
89 for (
int r = 0; r <
mModel.rowCount(); r++ )
91 QStandardItem *item =
mModel.item( r );
92 if ( item->data( Qt::CheckStateRole ) == Qt::Checked )
93 value |= item->data().value<ENUM>();
99 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
108 for (
int r = 0; r <
mModel.rowCount(); r++ )
110 QStandardItem *item =
mModel.item( r );
111 bool isChecked = value.testFlag( item->data().value<ENUM>() );
112 item->setData( isChecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
118 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
128 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
130 QStandardItem *item =
new QStandardItem( it.value() );
131 item->setData( QVariant::fromValue( it.key() ) );
132 item->setFlags( Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
133 item->setData( Qt::Unchecked, Qt::CheckStateRole );
159 QObject::connect( this->
mEditor, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) {
161 ENUM value = this->
mEditor->currentData().template value<ENUM>();
166 QString
id()
const override
168 return u
"%1-%2"_s.arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<ENUM>().name() );
176 void setDisplayStrings(
const QMap<ENUM, QString> &displayStrings ) { mDisplayStrings = displayStrings; }
195 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
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 );
223 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
232 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
234 const QString displayString = mDisplayStrings.value( it.key(), it.value() );
235 this->
mEditor->addItem( displayString, QVariant::fromValue( it.key() ) );
240 QMap<ENUM, QString> mDisplayStrings;
A template class for enum and flag settings entry.
const QMap< T, QString > qgsEnumMap()
Returns a map of all enum entries.
#define QgsDebugMsgLevel(str, level)