mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
add qgsEnumMap to list all entries (int, string) of enums
This commit is contained in:
parent
827cfbc4df
commit
3b1b41f391
@ -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
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <QString>
|
||||
#include <QRegExp>
|
||||
#include <QMetaType>
|
||||
#include <QMap>
|
||||
#include <QMetaEnum>
|
||||
#include <QVariant>
|
||||
#include <QDateTime>
|
||||
#include <QDate>
|
||||
@ -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<class T> CORE_EXPORT const QMap<T, QString> qgsEnumMap() SIP_SKIP
|
||||
{
|
||||
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
|
||||
Q_ASSERT( metaEnum.isValid() );
|
||||
QMap<T, QString> enumMap;
|
||||
for ( int idx = 0; idx < metaEnum.keyCount(); ++idx )
|
||||
{
|
||||
const char *enumKey = metaEnum.key( idx );
|
||||
enumMap.insert( static_cast<T>( 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user