Show category text in legend

Create empty string for standard legends. Show category text if present.
This commit is contained in:
Magne Sjaastad 2023-05-08 14:47:59 +02:00
parent f70d2c4949
commit 3208abad19
2 changed files with 17 additions and 3 deletions

View File

@ -164,10 +164,9 @@ void RimColorLegendCollection::createStandardColorLegends()
for ( size_t i = 0; i < colorArray.size(); i++ )
{
cvf::Color3f color3f( colorArray[i] );
QColor colorQ( colorArray[i].r(), colorArray[i].g(), colorArray[i].b() );
RimColorLegendItem* colorLegendItem = new RimColorLegendItem;
colorLegendItem->setValues( colorQ.name(), static_cast<int>( i ), color3f );
colorLegendItem->setValues( "", static_cast<int>( i ), color3f );
colorLegend->appendColorLegendItem( colorLegendItem );
colorLegend->setReadOnly( true );

View File

@ -42,6 +42,7 @@
#include "Rim3dWellLogCurve.h"
#include "RimCellEdgeColors.h"
#include "RimColorLegend.h"
#include "RimColorLegendItem.h"
#include "RimContourMapProjection.h"
#include "RimEclipseCase.h"
#include "RimEclipseCellColors.h"
@ -2128,7 +2129,21 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen
}
}
else
valueTxt = QString( "%1" ).arg( value );
{
auto items = legendConfigToUpdate->colorLegend()->colorLegendItems();
auto it = std::find_if( items.begin(),
items.end(),
[value]( const RimColorLegendItem* const item )
{ return item->categoryValue() == value; } );
if ( it != items.end() && !( *it )->categoryName().isEmpty() )
{
valueTxt = QString( "%1 (%2)" ).arg( ( *it )->categoryName() ).arg( value );
}
else
{
valueTxt = QString( "%1" ).arg( value );
}
}
categoryVector.push_back( std::make_tuple( valueTxt, value, categoryColor ) );
}