#7055 Contour Map: Label format it should match the legend format

This commit is contained in:
Magne Sjaastad
2020-11-30 16:06:44 +01:00
parent 404d77662e
commit 27946d2d69
4 changed files with 38 additions and 18 deletions

View File

@@ -417,9 +417,8 @@ std::vector<cvf::ref<cvf::Drawable>>
{
if ( m_contourLinePolygons[i][j].vertices.empty() ) continue;
// cvf::String::number does not allow precision on 'g' formats, so use Qt.
QString qLabelText = QString::number( m_contourLinePolygons[i][j].value, 'g', 2 );
cvf::String labelText = cvfqt::Utils::toString( qLabelText );
QString qLabelText = m_contourMapProjection->legendConfig()->valueToText( m_contourLinePolygons[i][j].value );
cvf::String labelText = cvfqt::Utils::toString( qLabelText );
size_t nVertices = m_contourLinePolygons[i][j].vertices.size();
size_t nLabels = nVertices;

View File

@@ -1150,6 +1150,37 @@ 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_precision() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@@ -165,6 +165,9 @@ public:
void updateFonts() override;
QString valueToText( double value ) const;
static QString valueToText( double value, NumberFormatType numberFormat, int precision );
private:
void fieldChangedByUi( const caf::PdmFieldHandle* changedField, const QVariant& oldValue, const QVariant& newValue ) override;
void initAfterRead() override;

View File

@@ -123,21 +123,8 @@ void RiuScalarMapperLegendFrame::layoutInfo( LayoutInfo* layout ) const
//--------------------------------------------------------------------------------------------------
QString RiuScalarMapperLegendFrame::label( int index ) const
{
double tickValue = m_tickValues[index];
QString valueString;
switch ( m_numberFormat )
{
case RimRegularLegendConfig::NumberFormatType::FIXED:
valueString = QString::number( tickValue, 'f', m_tickNumberPrecision );
break;
case RimRegularLegendConfig::NumberFormatType::SCIENTIFIC:
valueString = QString::number( tickValue, 'e', m_tickNumberPrecision );
break;
default:
valueString = QString::number( tickValue );
break;
}
return valueString;
double tickValue = m_tickValues[index];
return RimRegularLegendConfig::valueToText( tickValue, m_numberFormat, m_tickNumberPrecision );
}
//--------------------------------------------------------------------------------------------------