16#ifndef QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
17#define QGSSETTINGSENUMFLAGEDITORWIDGETWRAPPER_H
28#include <QStandardItemModel>
31using namespace Qt::StringLiterals;
39template<
class ENUM,
class FLAGS>
50 QObject::connect( &
mModel, &QStandardItemModel::itemChanged,
this, [
this](
const QStandardItem *item ) {
58 QString
id()
const override
60 return u
"%1-%2"_s.arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<FLAGS>().name() );
78 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
88 for (
int r = 0; r <
mModel.rowCount(); r++ )
90 QStandardItem *item =
mModel.item( r );
91 if ( item->data( Qt::CheckStateRole ) == Qt::Checked )
92 value |= item->data().value<ENUM>();
98 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
107 for (
int r = 0; r <
mModel.rowCount(); r++ )
109 QStandardItem *item =
mModel.item( r );
110 bool isChecked = value.testFlag( item->data().value<ENUM>() );
111 item->setData( isChecked ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole );
117 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
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 );
158 QObject::connect( this->
mEditor, qOverload<int>( &QComboBox::currentIndexChanged ),
this, [
this](
int index ) {
160 ENUM value = this->
mEditor->currentData().template value<ENUM>();
165 QString
id()
const override
167 return u
"%1-%2"_s.arg( sSettingsTypeMetaEnum.valueToKey(
static_cast<int>(
Qgis::SettingsType::EnumFlag ) ), QMetaEnum::fromType<ENUM>().name() );
175 void setDisplayStrings(
const QMap<ENUM, QString> &displayStrings ) { mDisplayStrings = displayStrings; }
194 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
203 return this->
mEditor->currentData().template value<ENUM>();
207 QgsDebugMsgLevel( QString(
"editor is not set, returning a non-existing value" ), 2 );
216 int i = this->
mEditor->findData( QVariant::fromValue( value ) );
217 this->
mEditor->setCurrentIndex( i );
222 QgsDebugMsgLevel( u
"Settings editor not set for %1"_s.arg( this->mSetting->definitionKey() ), 2 );
231 for (
auto it = enumMap.constBegin(); it != enumMap.constEnd(); ++it )
233 const QString displayString = mDisplayStrings.value( it.key(), it.value() );
234 this->
mEditor->addItem( displayString, QVariant::fromValue( it.key() ) );
239 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)