Use PtrField as placeholder for current legend config

Set previous current legend to obsolete
When reading a file < 1.3.7.-dev, copy current legend config into legend
list
This commit is contained in:
Magne Sjaastad
2015-08-06 08:08:00 +02:00
parent cb6564e381
commit f8871e9808
2 changed files with 65 additions and 39 deletions

View File

@@ -34,12 +34,11 @@ RimEclipseCellColors::RimEclipseCellColors()
{ {
CAF_PDM_InitObject("Result Slot", "", "", ""); CAF_PDM_InitObject("Result Slot", "", "", "");
CAF_PDM_InitFieldNoDefault(&legendConfig, "LegendDefinition", "Legend Definition", "", "", ""); CAF_PDM_InitFieldNoDefault(&obsoleteField_legendConfig, "LegendDefinition", "Legend Definition", "", "", "");
this->legendConfig = new RimLegendConfig(); this->obsoleteField_legendConfig.uiCapability()->setUiHidden(true);
this->legendConfig.uiCapability()->setUiHidden(true); this->obsoleteField_legendConfig.uiCapability()->setUiChildrenHidden(true);
this->legendConfig.uiCapability()->setUiChildrenHidden(true); this->obsoleteField_legendConfig.xmlCapability()->setIOWritable(false);
// MODTODO
CAF_PDM_InitFieldNoDefault(&m_legendConfigData, "ResultVarLegendDefinitionList", "", "", "", ""); CAF_PDM_InitFieldNoDefault(&m_legendConfigData, "ResultVarLegendDefinitionList", "", "", "", "");
m_legendConfigData.uiCapability()->setUiHidden(true); m_legendConfigData.uiCapability()->setUiHidden(true);
m_legendConfigData.uiCapability()->setUiChildrenHidden(true); m_legendConfigData.uiCapability()->setUiChildrenHidden(true);
@@ -48,6 +47,10 @@ RimEclipseCellColors::RimEclipseCellColors()
this->ternaryLegendConfig = new RimTernaryLegendConfig(); this->ternaryLegendConfig = new RimTernaryLegendConfig();
this->ternaryLegendConfig.uiCapability()->setUiHidden(true); this->ternaryLegendConfig.uiCapability()->setUiHidden(true);
this->ternaryLegendConfig.uiCapability()->setUiChildrenHidden(true); this->ternaryLegendConfig.uiCapability()->setUiChildrenHidden(true);
CAF_PDM_InitFieldNoDefault(&m_legendConfigPtrField, "LegendDefinitionPtrField", "Legend Definition PtrField", "", "", "");
this->m_legendConfigPtrField.uiCapability()->setUiHidden(true);
this->m_legendConfigPtrField.uiCapability()->setUiChildrenHidden(true);
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -55,7 +58,7 @@ RimEclipseCellColors::RimEclipseCellColors()
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
RimEclipseCellColors::~RimEclipseCellColors() RimEclipseCellColors::~RimEclipseCellColors()
{ {
delete legendConfig(); delete obsoleteField_legendConfig();
delete ternaryLegendConfig(); delete ternaryLegendConfig();
} }
@@ -94,26 +97,35 @@ void RimEclipseCellColors::changeLegendConfig(QString resultVarNameOfNewLegend)
{ {
this->ternaryLegendConfig.uiCapability()->setUiHidden(false); this->ternaryLegendConfig.uiCapability()->setUiHidden(false);
this->ternaryLegendConfig.uiCapability()->setUiChildrenHidden(false); this->ternaryLegendConfig.uiCapability()->setUiChildrenHidden(false);
this->legendConfig.uiCapability()->setUiHidden(true); this->m_legendConfigPtrField.uiCapability()->setUiHidden(true);
this->legendConfig.uiCapability()->setUiChildrenHidden(true); this->m_legendConfigPtrField.uiCapability()->setUiChildrenHidden(true);
} }
else else
{ {
this->ternaryLegendConfig.uiCapability()->setUiHidden(true); this->ternaryLegendConfig.uiCapability()->setUiHidden(true);
this->ternaryLegendConfig.uiCapability()->setUiChildrenHidden(true); this->ternaryLegendConfig.uiCapability()->setUiChildrenHidden(true);
if (this->legendConfig()->resultVariableName() != resultVarNameOfNewLegend) bool found = false;
QString legendResultVariable;
if (this->m_legendConfigPtrField())
{
legendResultVariable = this->m_legendConfigPtrField()->resultVariableName();
}
else if (obsoleteField_legendConfig)
{
// Use resultVariableName from obsolete legend config if present
legendResultVariable = obsoleteField_legendConfig->resultVariableName();
}
if (!this->m_legendConfigPtrField() || legendResultVariable != resultVarNameOfNewLegend)
{ {
bool found = false;
for (size_t i = 0; i < m_legendConfigData.size(); i++) for (size_t i = 0; i < m_legendConfigData.size(); i++)
{ {
if (m_legendConfigData[i]->resultVariableName() == resultVarNameOfNewLegend) if (m_legendConfigData[i]->resultVariableName() == resultVarNameOfNewLegend)
{ {
RimLegendConfig* newLegend = m_legendConfigData[i]; this->m_legendConfigPtrField = m_legendConfigData[i];
m_legendConfigData.erase(i);
m_legendConfigData.push_back(this->legendConfig());
this->legendConfig = newLegend;
found = true; found = true;
break; break;
} }
@@ -122,18 +134,18 @@ void RimEclipseCellColors::changeLegendConfig(QString resultVarNameOfNewLegend)
// Not found ? // Not found ?
if (!found) if (!found)
{ {
RimLegendConfig* newLegend = new RimLegendConfig; RimLegendConfig* newLegend = new RimLegendConfig;
newLegend->setReservoirView(m_reservoirView); newLegend->setReservoirView(m_reservoirView);
newLegend->resultVariableName = resultVarNameOfNewLegend; newLegend->resultVariableName = resultVarNameOfNewLegend;
m_legendConfigData.push_back(this->legendConfig()); m_legendConfigData.push_back(newLegend);
this->legendConfig = newLegend;
this->m_legendConfigPtrField = newLegend;
} }
} }
this->legendConfig.uiCapability()->setUiHidden(false);
this->legendConfig.uiCapability()->setUiChildrenHidden(false);
}
this->m_legendConfigPtrField.uiCapability()->setUiHidden(false);
this->m_legendConfigPtrField.uiCapability()->setUiChildrenHidden(false);
}
} }
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@@ -143,9 +155,15 @@ void RimEclipseCellColors::initAfterRead()
{ {
RimEclipseResultDefinition::initAfterRead(); RimEclipseResultDefinition::initAfterRead();
if (this->legendConfig()->resultVariableName == "") if (this->m_legendConfigPtrField() && this->m_legendConfigPtrField()->resultVariableName == "")
{ {
this->legendConfig()->resultVariableName = this->resultVariable(); this->m_legendConfigPtrField()->resultVariableName = this->resultVariable();
}
if (obsoleteField_legendConfig)
{
// The current legend config is NOT stored in <ResultVarLegendDefinitionList> in ResInsight up to v 1.3.7-dev
m_legendConfigData.push_back(obsoleteField_legendConfig);
} }
changeLegendConfig(this->resultVariable()); changeLegendConfig(this->resultVariable());
@@ -159,14 +177,11 @@ void RimEclipseCellColors::setReservoirView(RimEclipseView* ownerReservoirView)
RimEclipseResultDefinition::setReservoirView(ownerReservoirView); RimEclipseResultDefinition::setReservoirView(ownerReservoirView);
m_reservoirView = ownerReservoirView; m_reservoirView = ownerReservoirView;
this->legendConfig()->setReservoirView(ownerReservoirView);
std::list<caf::PdmPointer<RimLegendConfig> >::iterator it;
// MODTODO for (size_t i = 0; i < m_legendConfigData.size(); i++)
// for (it = m_legendConfigData.v().begin(); it != m_legendConfigData.v().end(); ++it) {
// { m_legendConfigData[i]->setReservoirView(ownerReservoirView);
// (*it)->setReservoirView(ownerReservoirView); }
// }
this->ternaryLegendConfig()->setReservoirView(ownerReservoirView); this->ternaryLegendConfig()->setReservoirView(ownerReservoirView);
} }
@@ -181,3 +196,11 @@ void RimEclipseCellColors::setResultVariable(const QString& val)
this->changeLegendConfig(val); this->changeLegendConfig(val);
} }
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RimLegendConfig* RimEclipseCellColors::legendConfig()
{
return m_legendConfigPtrField;
}

View File

@@ -26,6 +26,7 @@
#include "cafPdmChildArrayField.h" #include "cafPdmChildArrayField.h"
#include "cafPdmChildField.h" #include "cafPdmChildField.h"
#include "cafPdmPtrField.h"
class RimTernaryLegendConfig; class RimTernaryLegendConfig;
@@ -33,7 +34,7 @@ class RimTernaryLegendConfig;
/// ///
/// ///
//================================================================================================== //==================================================================================================
class RimEclipseCellColors : public RimEclipseResultDefinition class RimEclipseCellColors : public RimEclipseResultDefinition
{ {
CAF_PDM_HEADER_INIT; CAF_PDM_HEADER_INIT;
public: public:
@@ -41,7 +42,9 @@ public:
virtual ~RimEclipseCellColors(); virtual ~RimEclipseCellColors();
virtual void setReservoirView(RimEclipseView* ownerReservoirView); virtual void setReservoirView(RimEclipseView* ownerReservoirView);
caf::PdmChildField<RimLegendConfig*> legendConfig;
RimLegendConfig* legendConfig();
caf::PdmChildField<RimTernaryLegendConfig*> ternaryLegendConfig; caf::PdmChildField<RimTernaryLegendConfig*> ternaryLegendConfig;
// Overridden methods // Overridden methods
@@ -55,9 +58,9 @@ protected:
private: private:
void changeLegendConfig(QString resultVarNameOfNewLegend); void changeLegendConfig(QString resultVarNameOfNewLegend);
// MODTODO caf::PdmChildArrayField<RimLegendConfig*> m_legendConfigData;
// Possibly replace with PdmChildArrayField caf::PdmPtrField<RimLegendConfig*> m_legendConfigPtrField;
//caf::PdmField<std::list<caf::PdmPointer<RimLegendConfig> > > m_legendConfigData;
caf::PdmChildArrayField<RimLegendConfig*> m_legendConfigData; caf::PdmChildField<RimLegendConfig*> obsoleteField_legendConfig;
}; };