Skip to content
Permalink
Browse files

add methods to retrieve from/to value to keys for flags (#37752)

* add methods to retrieve from/to value to keys for flags

* sipify
  • Loading branch information
3nids committed Jul 11, 2020
1 parent 06fea4f commit a61a83d6486bb368a1f0527b03494b532737ae07
Showing with 30 additions and 0 deletions.
  1. +2 −0 python/core/auto_generated/qgis.sip.in
  2. +28 −0 src/core/qgis.h
@@ -181,6 +181,8 @@ 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
@@ -527,6 +527,34 @@ template<class T> T qgsEnumKeyToValue( const QString &key, const T &defaultValue
return defaultValue;
}

/**
* Returns the value for the given keys of a flag.
* \since QGIS 3.16
*/
template<class T> QString qgsFlagValueToKeys( const T &value ) SIP_SKIP
{
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
Q_ASSERT( metaEnum.isValid() );
return QString::fromUtf8( metaEnum.valueToKeys( static_cast<int>( value ) ) );
}

/**
* Returns the value corresponding to the given \a keys of a flag.
* If the keys are invalid, it will return the \a defaultValue.
* \since QGIS 3.16
*/
template<class T> T qgsFlagKeysToValue( const QString &keys, const T &defaultValue ) SIP_SKIP
{
QMetaEnum metaEnum = QMetaEnum::fromType<T>();
Q_ASSERT( metaEnum.isValid() );
bool ok = false;
T v = static_cast<T>( metaEnum.keysToValue( keys.toUtf8().constData(), &ok ) );
if ( ok )
return v;
else
return defaultValue;
}


/**
* Converts a string to a double in a permissive way, e.g., allowing for incorrect

0 comments on commit a61a83d

Please sign in to comment.
You can’t perform that action at this time.