diff --git a/src/libcalamares/utils/CalamaresUtils.cpp b/src/libcalamares/utils/CalamaresUtils.cpp index 9e678737b..c0175f771 100644 --- a/src/libcalamares/utils/CalamaresUtils.cpp +++ b/src/libcalamares/utils/CalamaresUtils.cpp @@ -366,6 +366,22 @@ getInteger( const QVariantMap& map, const QString& key, int d ) 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 getSubMap( const QVariantMap& map, const QString& key, bool& success ) { diff --git a/src/libcalamares/utils/CalamaresUtils.h b/src/libcalamares/utils/CalamaresUtils.h index 9b279ef43..13caf1cad 100644 --- a/src/libcalamares/utils/CalamaresUtils.h +++ b/src/libcalamares/utils/CalamaresUtils.h @@ -110,10 +110,15 @@ namespace CalamaresUtils 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 ); + /** + * 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 * given key. @p success is set to true if the @p key exists