From 194f693412bd35613162706e4887ea2017c418e6 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Fri, 11 Jan 2019 14:32:45 +0100 Subject: [PATCH] [partition] Use new NamedEnum approach --- .../partition/gui/PartitionViewStep.cpp | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/modules/partition/gui/PartitionViewStep.cpp b/src/modules/partition/gui/PartitionViewStep.cpp index 0152f8bec..7d1791342 100644 --- a/src/modules/partition/gui/PartitionViewStep.cpp +++ b/src/modules/partition/gui/PartitionViewStep.cpp @@ -35,6 +35,7 @@ #include "CalamaresVersion.h" #include "utils/CalamaresUtilsGui.h" #include "utils/Logger.h" +#include "utils/NamedEnum.h" #include "utils/Retranslator.h" #include "widgets/WaitingWidget.h" #include "GlobalStorage.h" @@ -474,25 +475,17 @@ PartitionViewStep::onLeave() static PartitionActions::Choices::SwapChoice nameToChoice( QString name, bool& ok ) { - ok = false; - name = name.toLower(); - using namespace PartitionActions::Choices; - // Each return here first sets ok to true, returns enum value - if ( name == QStringLiteral( "none" ) ) - return( ok=true, SwapChoice::NoSwap ); - else if ( name == QStringLiteral( "small" ) ) - return( ok=true, SwapChoice::SmallSwap); - else if ( name == QStringLiteral( "suspend" ) ) - return( ok=true, SwapChoice::FullSwap ); - else if ( name == QStringLiteral( "reuse" ) ) - return( ok=true, SwapChoice::ReuseSwap ); - else if ( name == QStringLiteral( "file" ) ) - return( ok=true, SwapChoice::SwapFile ); + static const NamedEnumTable names { + { QStringLiteral( "none" ), SwapChoice::NoSwap }, + { QStringLiteral( "small" ), SwapChoice::SmallSwap }, + { QStringLiteral( "suspend" ), SwapChoice::FullSwap }, + { QStringLiteral( "reuse" ), SwapChoice::ReuseSwap }, + { QStringLiteral( "file" ), SwapChoice::SwapFile } + }; - ok = false; - return SwapChoice::NoSwap; + return names.find( name, ok ); }