[libcalamares] Additional convenience function extracting int

This commit is contained in:
Adriaan de Groot 2018-01-24 15:24:19 +01:00
parent b828580464
commit 26dfd56f6d
2 changed files with 19 additions and 0 deletions

View File

@ -352,6 +352,20 @@ getString(const QVariantMap& map, const QString& key)
return QString(); return QString();
} }
int
getInteger( const QVariantMap& map, const QString& key, int d )
{
int result = d;
if ( map.contains( key ) )
{
auto v = map.value( key );
if ( v.type() == QVariant::Int )
result = v.toInt();
}
return result;
}
QVariantMap QVariantMap
getSubMap( const QVariantMap& map, const QString& key, bool& success ) getSubMap( const QVariantMap& map, const QString& key, bool& success )
{ {

View File

@ -109,6 +109,11 @@ 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.
*/
DLLEXPORT int getInteger( const QVariantMap& map, const QString& key, int 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