mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
WIA: Add better support for list parameters (#8266)
* Add better support for list parameters
This commit is contained in:
@@ -6,6 +6,7 @@ set(SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimListParameter.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterGroup.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterGroups.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterList.h
|
||||
)
|
||||
|
||||
set(SOURCE_GROUP_SOURCE_FILES
|
||||
@@ -16,6 +17,7 @@ set(SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimListParameter.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterGroup.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterGroups.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RimParameterList.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES ${SOURCE_GROUP_HEADER_FILES})
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "RimDoubleParameter.h"
|
||||
#include "RimGenericParameter.h"
|
||||
#include "RimIntegerParameter.h"
|
||||
#include "RimListParameter.h"
|
||||
#include "RimParameterList.h"
|
||||
#include "RimStringParameter.h"
|
||||
|
||||
#include <cmath>
|
||||
@@ -67,6 +69,11 @@ RimParameterGroup::RimParameterGroup()
|
||||
m_labelProxy.uiCapability()->setUiReadOnly( true );
|
||||
m_labelProxy.uiCapability()->setUiHidden( true );
|
||||
m_labelProxy.xmlCapability()->disableIO();
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_lists, "ParameterLists", "Parameter Lists", "", "", "" );
|
||||
m_lists.uiCapability()->setUiHidden( true );
|
||||
m_lists.uiCapability()->setUiTreeHidden( true );
|
||||
m_lists.uiCapability()->setUiTreeChildrenHidden( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -140,6 +147,14 @@ void RimParameterGroup::addParameter( QString name, double value )
|
||||
addParameter( p );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimParameterGroup::addList( RimParameterList* paramList )
|
||||
{
|
||||
m_lists.push_back( paramList );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -246,12 +261,37 @@ QString RimParameterGroup::label() const
|
||||
return labelOrName();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimParameterGroup::isListParameter( QString paramName ) const
|
||||
{
|
||||
for ( auto& list : m_lists )
|
||||
{
|
||||
if ( list->containsParameter( paramName ) ) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RimGenericParameter*> RimParameterGroup::parameters() const
|
||||
{
|
||||
return m_parameters.childObjects();
|
||||
std::vector<RimGenericParameter*> retParams;
|
||||
|
||||
for ( const auto& p : m_parameters.childObjects() )
|
||||
{
|
||||
if ( isListParameter( p->name() ) ) continue;
|
||||
retParams.push_back( p );
|
||||
}
|
||||
|
||||
for ( const auto& list : m_lists )
|
||||
{
|
||||
retParams.push_back( list->getAsListParameter( m_parameters.childObjects() ) );
|
||||
}
|
||||
|
||||
return retParams;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <vector>
|
||||
|
||||
class RimGenericParameter;
|
||||
class RimParameterList;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
@@ -46,6 +47,8 @@ public:
|
||||
void addParameter( QString name, QString value );
|
||||
void addParameter( QString name, double value );
|
||||
|
||||
void addList( RimParameterList* paramList );
|
||||
|
||||
void appendParametersToList( std::list<RimGenericParameter*>& parameterList );
|
||||
|
||||
void setName( QString name );
|
||||
@@ -76,6 +79,8 @@ private:
|
||||
caf::PdmFieldHandle* userDescriptionField() override;
|
||||
QString labelOrName() const;
|
||||
|
||||
bool isListParameter( QString paramName ) const;
|
||||
|
||||
private:
|
||||
caf::PdmChildArrayField<RimGenericParameter*> m_parameters;
|
||||
caf::PdmField<bool> m_showExpanded;
|
||||
@@ -83,4 +88,5 @@ private:
|
||||
caf::PdmField<QString> m_label;
|
||||
caf::PdmField<QString> m_comment;
|
||||
caf::PdmProxyValueField<QString> m_labelProxy;
|
||||
caf::PdmChildArrayField<RimParameterList*> m_lists;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2021 - Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RimParameterList.h"
|
||||
|
||||
#include "RimListParameter.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
CAF_PDM_SOURCE_INIT( RimParameterList, "ParameterList" );
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimParameterList::RimParameterList()
|
||||
{
|
||||
CAF_PDM_InitObject( "Parameter List", ":/Bullet.png", "", "" );
|
||||
uiCapability()->setUiTreeChildrenHidden( true );
|
||||
|
||||
CAF_PDM_InitFieldNoDefault( &m_parameterNames, "ParameterNames", "Parameters", "", "", "" );
|
||||
m_parameterNames.uiCapability()->setUiHidden( true );
|
||||
m_parameterNames.uiCapability()->setUiTreeHidden( true );
|
||||
m_parameterNames.uiCapability()->setUiTreeChildrenHidden( true );
|
||||
|
||||
CAF_PDM_InitField( &m_name, "Name", QString(), "Name", "", "", "" );
|
||||
m_name.uiCapability()->setUiHidden( true );
|
||||
|
||||
CAF_PDM_InitField( &m_label, "Label", QString(), "Name", "", "", "" );
|
||||
m_label.uiCapability()->setUiHidden( true );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimParameterList::~RimParameterList()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimParameterList::addParameter( QString paramName )
|
||||
{
|
||||
m_parameterNames.v().push_back( paramName );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RimParameterList::containsParameter( QString paramName )
|
||||
{
|
||||
for ( auto& param : m_parameterNames.v() )
|
||||
{
|
||||
if ( param == paramName ) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimParameterList::setName( QString name )
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RimParameterList::setLabel( QString labelText )
|
||||
{
|
||||
m_label = labelText;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimParameterList::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimParameterList::label() const
|
||||
{
|
||||
return m_label;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RimParameterList::parameterValue( QString paramName, std::vector<RimGenericParameter*>& parameters )
|
||||
{
|
||||
for ( auto& param : parameters )
|
||||
{
|
||||
if ( paramName == param->name() ) return param->stringValue();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RimListParameter* RimParameterList::getAsListParameter( std::vector<RimGenericParameter*> parameters )
|
||||
{
|
||||
QString stringValue = "[";
|
||||
|
||||
bool skipComma = true;
|
||||
|
||||
for ( auto& paramName : m_parameterNames.v() )
|
||||
{
|
||||
if ( skipComma )
|
||||
{
|
||||
stringValue += " ";
|
||||
skipComma = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
stringValue += ", ";
|
||||
}
|
||||
stringValue += parameterValue( paramName, parameters );
|
||||
}
|
||||
|
||||
stringValue += " ]";
|
||||
|
||||
RimListParameter* param = new RimListParameter();
|
||||
param->setName( name() );
|
||||
param->setLabel( label() );
|
||||
param->setValue( stringValue );
|
||||
|
||||
return param;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2021 - Equinor ASA
|
||||
//
|
||||
// ResInsight is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cafPdmChildArrayField.h"
|
||||
#include "cafPdmField.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
class RimListParameter;
|
||||
class RimGenericParameter;
|
||||
|
||||
//==================================================================================================
|
||||
///
|
||||
///
|
||||
//==================================================================================================
|
||||
class RimParameterList : public caf::PdmObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
|
||||
public:
|
||||
RimParameterList();
|
||||
~RimParameterList() override;
|
||||
|
||||
void addParameter( QString paramName );
|
||||
bool containsParameter( QString paramName );
|
||||
|
||||
RimListParameter* getAsListParameter( std::vector<RimGenericParameter*> parameters );
|
||||
|
||||
void setName( QString name );
|
||||
void setLabel( QString labelText );
|
||||
|
||||
QString name() const;
|
||||
QString label() const;
|
||||
|
||||
private:
|
||||
QString parameterValue( QString paramName, std::vector<RimGenericParameter*>& parameters );
|
||||
|
||||
private:
|
||||
caf::PdmField<QString> m_name;
|
||||
caf::PdmField<QString> m_label;
|
||||
caf::PdmField<std::vector<QString>> m_parameterNames;
|
||||
};
|
||||
Reference in New Issue
Block a user