#14192 Update color legend in place on roff property re-import

Reuse RimColorLegendCollection::updateColorLegend in the two roff import
sites that previously deleted and recreated the legend bound to a result,
so views referencing the legend keep their binding on re-import.

Extract the rock color matching from createColorLegendMatchDefaultRockColors
into matchDefaultRockColors so the facies branch can pass matched colors to
updateColorLegend. Remove the now-unused
RimColorLegendCollection::createColorLegend.
This commit is contained in:
Kristian Bendiksen authored and Magne Sjaastad committed 2026-06-10 18:02:07 +02:00
1 parent a4fe22508a
commit d78d7cf430
5 files changed
+61 -45

No files matched your search

@@ -88,32 +88,6 @@ void RimColorLegendCollection::deleteCustomColorLegends()
m_customColorLegends.deleteChildren();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimColorLegend* RimColorLegendCollection::createColorLegend( const QString& colorLegendName, const std::map<int, QString>& valuesAndNames )
{
auto colors = RiaColorTables::categoryPaletteColors().color3ubArray();
auto colorLegend = new RimColorLegend();
colorLegend->setColorLegendName( colorLegendName );
int colorIndex = 0;
for ( const auto& [value, name] : valuesAndNames )
{
auto item = new RimColorLegendItem();
auto color = colors[colorIndex++ % colors.size()];
cvf::Color3f color3f( color );
item->setValues( name, value, color3f );
colorLegend->appendColorLegendItem( item );
}
appendCustomColorLegend( colorLegend );
return colorLegend;
}
//--------------------------------------------------------------------------------------------------
/// Update the custom color legend registered as default for the given result in place, so that
/// objects referring to the legend keep their binding. Creates and registers a new custom legend
@@ -158,6 +132,26 @@ RimColorLegend* RimColorLegendCollection::updateColorLegend( const RimCase*
return legend;
}
//--------------------------------------------------------------------------------------------------
/// Overload taking values and names as a map, with optional colors ordered by ascending value.
//--------------------------------------------------------------------------------------------------
RimColorLegend* RimColorLegendCollection::updateColorLegend( const RimCase* rimCase,
const QString& resultName,
const QString& colorLegendName,
const std::map<int, QString>& valuesAndNames,
const std::vector<cvf::Color3f>& colors )
{
std::vector<int> categoryValues;
std::vector<QString> categoryNames;
for ( const auto& [value, name] : valuesAndNames )
{
categoryValues.push_back( value );
categoryNames.push_back( name );
}
return updateColorLegend( rimCase, resultName, colorLegendName, categoryValues, categoryNames, colors );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
@@ -51,13 +51,17 @@ public:
bool isStandardColorLegend( RimColorLegend* colorLegend );
void deleteCustomColorLegends();
RimColorLegend* createColorLegend( const QString& colorLegendName, const std::map<int, QString>& valuesAndNames );
RimColorLegend* updateColorLegend( const RimCase* rimCase,
const QString& resultName,
const QString& colorLegendName,
const std::vector<int>& categoryValues,
const std::vector<QString>& categoryNames,
const std::vector<cvf::Color3f>& colors );
RimColorLegend* updateColorLegend( const RimCase* rimCase,
const QString& resultName,
const QString& colorLegendName,
const std::map<int, QString>& valuesAndNames,
const std::vector<cvf::Color3f>& colors = {} );
void createColorLegendFromFormationNames( RimFormationNames* rimFormationNames );
void deleteColorLegend( const RimCase* rimCase, const QString& resultName );
void setDefaultColorLegendForResult( const RimCase* rimCase, const QString& resultName, RimColorLegend* colorLegend );