#6164 Color Legend : Update category colors when project file is loaded

This commit is contained in:
Magne Sjaastad 2020-06-30 17:10:51 +02:00
parent 7c8fced4fe
commit 18e0c8999e
3 changed files with 31 additions and 15 deletions

View File

@ -1983,7 +1983,7 @@ void RimEclipseResultDefinition::updateRangesForExplicitLegends( RimRegularLegen
int frmIdx2 = it->first.second;
int combIndex = it->second;
int fnVectorSize = fnVector.size();
int fnVectorSize = static_cast<int>( fnVector.size() );
if ( frmIdx1 >= fnVectorSize || frmIdx2 >= fnVectorSize ) continue;
QString frmName1 = fnVector[frmIdx1];

View File

@ -272,20 +272,7 @@ void RimRegularLegendConfig::fieldChangedByUi( const caf::PdmFieldHandle* change
if ( ( changedField == &m_colorLegend || changedField == &m_mappingMode ) &&
m_mappingMode() == MappingType::CATEGORY_INTEGER )
{
std::vector<std::tuple<QString, int, cvf::Color3ub>> categories;
if ( m_colorLegend() )
{
for ( auto item : m_colorLegend->colorLegendItems() )
{
cvf::Color3ub ubColor( item->color() );
QString categoryName = item->categoryName() + QString( " [%1]" ).arg( item->categoryValue() );
categories.push_back( std::make_tuple( categoryName, item->categoryValue(), ubColor ) );
}
}
std::reverse( categories.begin(), categories.end() );
setCategoryItems( categories );
updateCategoryItems();
}
updateLegend();
@ -587,6 +574,11 @@ void RimRegularLegendConfig::initAfterRead()
m_colorLegend = RimRegularLegendConfig::mapToColorLegend( m_colorRangeMode_OBSOLETE() );
}
if ( m_mappingMode() == MappingType::CATEGORY_INTEGER )
{
updateCategoryItems();
}
updateFieldVisibility();
this->updateUiIconFromToggleField();
@ -693,6 +685,28 @@ double RimRegularLegendConfig::roundToNumSignificantDigits( double domainValue,
return newDomainValue;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimRegularLegendConfig::updateCategoryItems()
{
std::vector<std::tuple<QString, int, cvf::Color3ub>> categories;
if ( m_colorLegend() )
{
for ( auto item : m_colorLegend->colorLegendItems() )
{
cvf::Color3ub ubColor( item->color() );
QString categoryName = item->categoryName() + QString( " [%1]" ).arg( item->categoryValue() );
categories.push_back( std::make_tuple( categoryName, item->categoryValue(), ubColor ) );
}
}
// Reverse the categories to make the ordering identical to items in project tree
std::reverse( categories.begin(), categories.end() );
setCategoryItems( categories );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------

View File

@ -166,6 +166,8 @@ private:
void updateFieldVisibility();
double roundToNumSignificantDigits( double value, double precision );
void updateCategoryItems();
friend class RimViewLinker;
private: