#7667 Refactor: extract number format settings for reuse.

This commit is contained in:
Kristian Bendiksen
2021-05-28 15:56:54 +02:00
committed by Magne Sjaastad
parent 5d703b2a08
commit b2025fbeef
8 changed files with 119 additions and 61 deletions

View File

@@ -23,6 +23,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaStringListSerializer.h
${CMAKE_CURRENT_LIST_DIR}/RiaNncDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaStimPlanModelDefines.h
${CMAKE_CURRENT_LIST_DIR}/RiaResultNames.h
${CMAKE_CURRENT_LIST_DIR}/RiaNumberFormat.h
)
set (SOURCE_GROUP_SOURCE_FILES
@@ -49,6 +50,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaStringListSerializer.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaNncDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaStimPlanModelDefines.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaResultNames.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaNumberFormat.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaNumberFormat.h"
#include "cafAppEnum.h"
template <>
void caf::AppEnum<RiaNumberFormat::NumberFormatType>::setUp()
{
addItem( RiaNumberFormat::NumberFormatType::AUTO, "AUTO", "Automatic" );
addItem( RiaNumberFormat::NumberFormatType::FIXED, "FIXED", "Fixed, decimal" );
addItem( RiaNumberFormat::NumberFormatType::SCIENTIFIC, "SCIENTIFIC", "Scientific notation" );
setDefault( RiaNumberFormat::NumberFormatType::FIXED );
};
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaNumberFormat::valueToText( double value, RiaNumberFormat::NumberFormatType numberFormat, int precision )
{
QString valueString;
switch ( numberFormat )
{
case RiaNumberFormat::NumberFormatType::FIXED:
valueString = QString::number( value, 'f', precision );
break;
case RiaNumberFormat::NumberFormatType::SCIENTIFIC:
valueString = QString::number( value, 'e', precision );
break;
default:
valueString = QString::number( value );
break;
}
return valueString;
}

View File

@@ -0,0 +1,37 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2021 Equinor ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QString>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
class RiaNumberFormat
{
public:
enum class NumberFormatType
{
AUTO,
SCIENTIFIC,
FIXED
};
static QString valueToText( double value, RiaNumberFormat::NumberFormatType numberFormat, int precision );
};