#14192 Python: Fix duplicate discrete property legend on repeated category-name calls

RimColorLegendCollection::deleteColorLegend erased the default-legend map
entry before looking the legend up, so findDefaultLegendForResult always
returned null and the old legend was never removed from m_customColorLegends.
Each set_discrete_property_category_names call for the same property left an
orphaned legend behind and appended a new one.

Look up the legend before erasing the map key, and guard against deleting a
standard legend that may have been registered as a default.
This commit is contained in:
Kristian Bendiksen authored and Magne Sjaastad committed 2026-06-10 18:02:07 +02:00
1 parent ef815a79f8
commit 5a083331b0
2 files changed
+32 -2

No files matched your search

@@ -119,10 +119,11 @@ RimColorLegend* RimColorLegendCollection::createColorLegend( const QString& colo
//--------------------------------------------------------------------------------------------------
void RimColorLegendCollection::deleteColorLegend( const RimCase* rimCase, const QString& resultName )
{
auto legend = findDefaultLegendForResult( rimCase, resultName );
m_defaultColorLegendNameForResult.erase( createLookupKey( rimCase, resultName ) );
auto legend = findDefaultLegendForResult( rimCase, resultName );
if ( !legend ) return;
if ( !legend || isStandardColorLegend( legend ) ) return;
m_customColorLegends.removeChild( legend );
delete legend;