mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-05 21:53:27 -06:00
#7667 Refactor: extract number format settings for reuse.
This commit is contained in:
parent
5d703b2a08
commit
b2025fbeef
@ -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
|
||||
|
53
ApplicationLibCode/Application/RiaNumberFormat.cpp
Normal file
53
ApplicationLibCode/Application/RiaNumberFormat.cpp
Normal 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;
|
||||
}
|
37
ApplicationLibCode/Application/RiaNumberFormat.h
Normal file
37
ApplicationLibCode/Application/RiaNumberFormat.h
Normal 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 );
|
||||
};
|
@ -218,7 +218,7 @@ RimRegularLegendConfig* RimEclipseCellColors::createLegendForResult( const QStri
|
||||
else
|
||||
newLegend->setMappingMode( RimRegularLegendConfig::MappingType::LOG10_CONTINUOUS );
|
||||
|
||||
newLegend->setTickNumberFormat( RimRegularLegendConfig::NumberFormatType::AUTO );
|
||||
newLegend->setTickNumberFormat( RiaNumberFormat::NumberFormatType::AUTO );
|
||||
newLegend->setRangeMode( RimLegendConfig::RangeModeType::USER_DEFINED );
|
||||
newLegend->resetUserDefinedValues();
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "RiaApplication.h"
|
||||
#include "RiaColorTables.h"
|
||||
#include "RiaNumberFormat.h"
|
||||
#include "RiaPreferences.h"
|
||||
|
||||
#include "RimCellEdgeColors.h"
|
||||
@ -116,15 +117,6 @@ void RimRegularLegendConfig::MappingEnum::setUp()
|
||||
setDefault( RimRegularLegendConfig::MappingType::LINEAR_CONTINUOUS );
|
||||
}
|
||||
|
||||
template <>
|
||||
void AppEnum<RimRegularLegendConfig::NumberFormatType>::setUp()
|
||||
{
|
||||
addItem( RimRegularLegendConfig::NumberFormatType::AUTO, "AUTO", "Automatic" );
|
||||
addItem( RimRegularLegendConfig::NumberFormatType::FIXED, "FIXED", "Fixed, decimal" );
|
||||
addItem( RimRegularLegendConfig::NumberFormatType::SCIENTIFIC, "SCIENTIFIC", "Scientific notation" );
|
||||
setDefault( RimRegularLegendConfig::NumberFormatType::FIXED );
|
||||
}
|
||||
|
||||
template <>
|
||||
void AppEnum<RimRegularLegendConfig::CategoryColorModeType>::setUp()
|
||||
{
|
||||
@ -167,7 +159,7 @@ RimRegularLegendConfig::RimRegularLegendConfig()
|
||||
m_significantDigitsInData = m_precision;
|
||||
CAF_PDM_InitField( &m_tickNumberFormat,
|
||||
"TickNumberFormat",
|
||||
caf::AppEnum<RimRegularLegendConfig::NumberFormatType>( NumberFormatType::FIXED ),
|
||||
caf::AppEnum<RiaNumberFormat::NumberFormatType>( RiaNumberFormat::NumberFormatType::FIXED ),
|
||||
"Number format",
|
||||
"",
|
||||
"",
|
||||
@ -576,12 +568,12 @@ void RimRegularLegendConfig::updateLegend()
|
||||
decadesInRange = cvf::Math::ceil( decadesInRange );
|
||||
|
||||
// Using Fixed format
|
||||
NumberFormatType nft = m_tickNumberFormat();
|
||||
RiaNumberFormat::NumberFormatType nft = m_tickNumberFormat();
|
||||
m_scalarMapperLegend->setTickFormat( (caf::OverlayScalarMapperLegend::NumberFormat)nft );
|
||||
|
||||
// Set the fixed number of digits after the decimal point to the number needed to show all the significant digits.
|
||||
int numDecimalDigits = m_precision();
|
||||
if ( nft != NumberFormatType::SCIENTIFIC )
|
||||
if ( nft != RiaNumberFormat::NumberFormatType::SCIENTIFIC )
|
||||
{
|
||||
numDecimalDigits -= static_cast<int>( decadesInRange );
|
||||
}
|
||||
@ -617,7 +609,7 @@ void RimRegularLegendConfig::updateLegend()
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimRegularLegendConfig::setTickNumberFormat( NumberFormatType numberFormat )
|
||||
void RimRegularLegendConfig::setTickNumberFormat( RiaNumberFormat::NumberFormatType numberFormat )
|
||||
{
|
||||
m_tickNumberFormat = numberFormat;
|
||||
}
|
||||
@ -1198,35 +1190,12 @@ void RimRegularLegendConfig::updateFonts()
|
||||
updateLegend();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimRegularLegendConfig::valueToText( double value, NumberFormatType numberFormat, int precision )
|
||||
{
|
||||
QString valueString;
|
||||
|
||||
switch ( numberFormat )
|
||||
{
|
||||
case RimRegularLegendConfig::NumberFormatType::FIXED:
|
||||
valueString = QString::number( value, 'f', precision );
|
||||
break;
|
||||
case RimRegularLegendConfig::NumberFormatType::SCIENTIFIC:
|
||||
valueString = QString::number( value, 'e', precision );
|
||||
break;
|
||||
default:
|
||||
valueString = QString::number( value );
|
||||
break;
|
||||
}
|
||||
|
||||
return valueString;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimRegularLegendConfig::valueToText( double value ) const
|
||||
{
|
||||
return RimRegularLegendConfig::valueToText( value, m_tickNumberFormat(), m_significantDigitsInData );
|
||||
return RiaNumberFormat::valueToText( value, m_tickNumberFormat(), m_significantDigitsInData );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RiaNumberFormat.h"
|
||||
|
||||
#include "RimLegendConfig.h"
|
||||
#include "RimLegendConfigChangeType.h"
|
||||
|
||||
@ -108,12 +110,6 @@ public:
|
||||
LOG10_DISCRETE,
|
||||
CATEGORY_INTEGER
|
||||
};
|
||||
enum class NumberFormatType
|
||||
{
|
||||
AUTO,
|
||||
SCIENTIFIC,
|
||||
FIXED
|
||||
};
|
||||
typedef caf::AppEnum<MappingType> MappingEnum;
|
||||
|
||||
enum class CategoryColorModeType
|
||||
@ -129,7 +125,7 @@ public:
|
||||
RimColorLegend* colorLegend() const;
|
||||
void setMappingMode( MappingType mappingType );
|
||||
MappingType mappingMode() { return m_mappingMode(); }
|
||||
void setTickNumberFormat( NumberFormatType numberFormat );
|
||||
void setTickNumberFormat( RiaNumberFormat::NumberFormatType numberFormat );
|
||||
void resetUserDefinedValues();
|
||||
|
||||
void disableAllTimeStepsRange( bool doDisable );
|
||||
@ -171,8 +167,7 @@ public:
|
||||
|
||||
void updateFonts() override;
|
||||
|
||||
QString valueToText( double value ) const;
|
||||
static QString valueToText( double value, NumberFormatType numberFormat, int precision );
|
||||
QString valueToText( double value ) const;
|
||||
|
||||
private:
|
||||
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
|
||||
@ -225,17 +220,17 @@ private:
|
||||
cvf::Color3ubArray m_categoryColors;
|
||||
|
||||
// Fields
|
||||
caf::PdmField<bool> m_showLegend;
|
||||
caf::PdmField<int> m_numLevels;
|
||||
caf::PdmField<int> m_precision;
|
||||
caf::PdmField<caf::AppEnum<NumberFormatType>> m_tickNumberFormat;
|
||||
caf::PdmField<RangeModeEnum> m_rangeMode;
|
||||
caf::PdmField<double> m_userDefinedMaxValue;
|
||||
caf::PdmField<double> m_userDefinedMinValue;
|
||||
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
|
||||
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
|
||||
caf::PdmField<caf::AppEnum<CategoryColorModeType>> m_categoryColorMode;
|
||||
caf::PdmField<bool> m_resetUserDefinedValuesButton;
|
||||
caf::PdmField<bool> m_showLegend;
|
||||
caf::PdmField<int> m_numLevels;
|
||||
caf::PdmField<int> m_precision;
|
||||
caf::PdmField<caf::AppEnum<RiaNumberFormat::NumberFormatType>> m_tickNumberFormat;
|
||||
caf::PdmField<RangeModeEnum> m_rangeMode;
|
||||
caf::PdmField<double> m_userDefinedMaxValue;
|
||||
caf::PdmField<double> m_userDefinedMinValue;
|
||||
caf::PdmField<caf::AppEnum<ColorRangesType>> m_colorRangeMode_OBSOLETE;
|
||||
caf::PdmField<caf::AppEnum<MappingType>> m_mappingMode;
|
||||
caf::PdmField<caf::AppEnum<CategoryColorModeType>> m_categoryColorMode;
|
||||
caf::PdmField<bool> m_resetUserDefinedValuesButton;
|
||||
|
||||
caf::PdmPtrField<RimColorLegend*> m_colorLegend;
|
||||
caf::PdmField<bool> m_selectColorLegendButton;
|
||||
|
@ -35,7 +35,7 @@ RiuScalarMapperLegendFrame::RiuScalarMapperLegendFrame( QWidget* parent, const Q
|
||||
: RiuAbstractLegendFrame( parent, title )
|
||||
, m_scalarMapper( scalarMapper )
|
||||
, m_tickNumberPrecision( 4 )
|
||||
, m_numberFormat( RimRegularLegendConfig::NumberFormatType::AUTO )
|
||||
, m_numberFormat( RiaNumberFormat::NumberFormatType::AUTO )
|
||||
{
|
||||
if ( m_scalarMapper.notNull() )
|
||||
{
|
||||
@ -126,7 +126,7 @@ void RiuScalarMapperLegendFrame::layoutInfo( LayoutInfo* layout ) const
|
||||
QString RiuScalarMapperLegendFrame::label( int index ) const
|
||||
{
|
||||
double tickValue = m_tickValues[index];
|
||||
return RimRegularLegendConfig::valueToText( tickValue, m_numberFormat, m_tickNumberPrecision );
|
||||
return RiaNumberFormat::valueToText( tickValue, m_numberFormat, m_tickNumberPrecision );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -17,6 +17,8 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
#pragma once
|
||||
|
||||
#include "RiaNumberFormat.h"
|
||||
|
||||
#include "RimRegularLegendConfig.h"
|
||||
#include "RiuAbstractLegendFrame.h"
|
||||
|
||||
@ -37,7 +39,7 @@ class RiuScalarMapperLegendFrame : public RiuAbstractLegendFrame
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using NumberFormat = RimRegularLegendConfig::NumberFormatType;
|
||||
using NumberFormat = RiaNumberFormat::NumberFormatType;
|
||||
|
||||
public:
|
||||
RiuScalarMapperLegendFrame( QWidget* parent, const QString& title, cvf::ScalarMapper* scalarMapper );
|
||||
|
Loading…
Reference in New Issue
Block a user