[libcalamares] Additional convenience for doubles

This commit is contained in:
Adriaan de Groot 2018-01-29 14:45:42 +01:00
parent 26dfd56f6d
commit 778feb50e8
2 changed files with 22 additions and 1 deletions

View File

@ -366,6 +366,22 @@ getInteger( const QVariantMap& map, const QString& key, int d )
return result; return result;
} }
double
getDouble( const QVariantMap& map, const QString& key, double d )
{
double result = d;
if ( map.contains( key ) )
{
auto v = map.value( key );
if ( v.type() == QVariant::Int )
result = v.toInt();
else if ( v.type() == QVariant::Double )
result = v.toDouble();
}
return result;
}
QVariantMap QVariantMap
getSubMap( const QVariantMap& map, const QString& key, bool& success ) getSubMap( const QVariantMap& map, const QString& key, bool& success )
{ {

View File

@ -110,10 +110,15 @@ namespace CalamaresUtils
DLLEXPORT QString getString( const QVariantMap& map, const QString& key ); DLLEXPORT QString getString( const QVariantMap& map, const QString& key );
/** /**
* Get an integer value from a mapping; returns @p default if no value. * Get an integer value from a mapping; returns @p d if no value.
*/ */
DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int d ); DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int d );
/**
* Get a double value from a mapping (integers are converted); returns @p d if no value.
*/
DLLEXPORT double getDouble( const QVariantMap& map, const QString& key, double d );
/** /**
* Returns a sub-map (i.e. a nested map) from the given mapping with the * Returns a sub-map (i.e. a nested map) from the given mapping with the
* given key. @p success is set to true if the @p key exists * given key. @p success is set to true if the @p key exists