diff --git a/python/core/auto_generated/qgis.sip.in b/python/core/auto_generated/qgis.sip.in index 3ba9544570b..69c0de773d0 100644 --- a/python/core/auto_generated/qgis.sip.in +++ b/python/core/auto_generated/qgis.sip.in @@ -132,6 +132,7 @@ Returns a double ``number``, rounded (as close as possible) to the specified num + double qgsPermissiveToDouble( QString string, bool &ok ); %Docstring Converts a string to a double in a permissive way, e.g., allowing for incorrect diff --git a/src/core/qgis.h b/src/core/qgis.h index 97f2acb5a8e..7bca5c8b259 100644 --- a/src/core/qgis.h +++ b/src/core/qgis.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -387,6 +389,24 @@ namespace qgis ///@endcond #endif +/** + * Returns a map of all enum entries. + * The map has the enum values (int) as keys and the enum keys (QString) as values. + * The enum must have been declared using Q_ENUM or Q_FLAG. + */ +template CORE_EXPORT const QMap qgsEnumMap() SIP_SKIP +{ + QMetaEnum metaEnum = QMetaEnum::fromType(); + Q_ASSERT( metaEnum.isValid() ); + QMap enumMap; + for ( int idx = 0; idx < metaEnum.keyCount(); ++idx ) + { + const char *enumKey = metaEnum.key( idx ); + enumMap.insert( static_cast( metaEnum.keyToValue( enumKey ) ), QString( enumKey ) ); + } + return enumMap; +}; + /** * Converts a string to a double in a permissive way, e.g., allowing for incorrect * numbers of digits between thousand separators