mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-08 23:23:01 -06:00
Caf Field: Comments etc. regarding optionvalues
Fields with option values implicitly have an index based seUiValue/uiValue interface. This is commented better. Fields of AppEnum specialization was not quite in line with the rest of the optionValue system. That is commented and some ifdeffed code has been added to highlight what could be done when we dare.
This commit is contained in:
parent
86fe500690
commit
c537d7179b
@ -81,6 +81,8 @@ public:
|
||||
PdmObject* ownerObject() { return m_ownerObject; }
|
||||
|
||||
// Generalized access methods for User interface
|
||||
// The QVariant encapsulates the real value, or an index into the valueOptions
|
||||
//
|
||||
|
||||
virtual QVariant uiValue() const { return QVariant(); }
|
||||
virtual void setValueFromUi(const QVariant& ) { }
|
||||
|
@ -48,6 +48,13 @@ namespace caf
|
||||
//==================================================================================================
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// This method is supposed to be the interface for the implementation of UI editors to set values into
|
||||
/// the field. The data to set must be encapsulated in a QVariant.
|
||||
/// This method triggers PdmObject::fieldChangedByUi() and PdmObject::updateConnectedEditors(), an thus
|
||||
/// makes the application and the UI aware of the change.
|
||||
///
|
||||
/// Note : If the field has optionValues the interface is _index-based_. The QVariant must contain
|
||||
/// an UInt representing the index to the option selected by the user interface.
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType >
|
||||
@ -131,6 +138,9 @@ void caf::PdmField<DataType>::setValueFromUi(const QVariant& uiValue)
|
||||
/// This method calls the virtual PdmObject::calculateValueOptions to get the list provided from the
|
||||
/// application, then possibly adds the current field value(s) to the list, to
|
||||
/// make sure the actual values are shown
|
||||
///
|
||||
/// Note: This method is missing the uiConfigName concept. This is a Todo. The m_optionEntryCache
|
||||
/// then needs to be stored pr. uiConfigName.
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType >
|
||||
QList<PdmOptionItemInfo> caf::PdmField<DataType>::valueOptions(bool* useOptionsOnly)
|
||||
@ -190,16 +200,24 @@ QList<PdmOptionItemInfo> caf::PdmField<DataType>::valueOptions(bool* useOptionsO
|
||||
|
||||
// If we have no options, use the options defined by the type. Normally only caf::AppEnum type
|
||||
|
||||
#if 0
|
||||
m_optionEntryCache = PdmFieldTypeSpecialization<DataType>::valueOptions(useOptionsOnly, m_fieldValue);
|
||||
return m_optionEntryCache;
|
||||
#else
|
||||
return PdmFieldTypeSpecialization<DataType>::valueOptions(useOptionsOnly, m_fieldValue);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Extracts a QVariant representation of the data in the field to be used in the UI.
|
||||
/// Note that for fields with a none empty valueOptions list the returned QVariant contains the
|
||||
/// indexes to the selected options rather than the actual values, if they can be found.
|
||||
/// If this is a multivalue field, and we cant find all of the field values among the options,
|
||||
/// the method asserts (For now), forcing the valueOptions to always contain the field values.
|
||||
/// Single value fields will return -1 if the option is not found, allowing the concept of "nothing selected"
|
||||
///
|
||||
/// Note : For fields with a none-empty valueOptions list, the returned QVariant contains the
|
||||
/// _indexes_ to the selected options rather than the actual values, if they can be found.
|
||||
///
|
||||
/// If this is a multivalue field, and we cant find all of the field values among the options,
|
||||
/// the method asserts (For now), forcing the valueOptions to always contain the field values.
|
||||
/// Single value fields will return -1 if the option is not found, allowing the concept of "nothing selected"
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template<typename DataType >
|
||||
QVariant caf::PdmField<DataType>::uiValue() const
|
||||
|
@ -252,8 +252,15 @@ public:
|
||||
|
||||
//==================================================================================================
|
||||
/// Partial specialization for PdmField< caf::AppEnum<T> >
|
||||
///
|
||||
/// Note : Makes the setUiValue() and uiValue() interface index based, and NOT based on real enum values.
|
||||
/// The valueOptions() interface is thus also index based (the value in the PdmOptionItemInfo is index NOT enum)
|
||||
/// This is probably going to change, ans it is strange.
|
||||
/// This conversion should really be done in the editors we think (now)
|
||||
//==================================================================================================
|
||||
|
||||
#define PDMFIELDAPPENUM_USE_INDEX_BASED_INTERFACE 1
|
||||
|
||||
template <typename T>
|
||||
class PdmFieldTypeSpecialization < caf::AppEnum<T> >
|
||||
{
|
||||
@ -261,13 +268,22 @@ public:
|
||||
/// Convert the field value into a QVariant
|
||||
static QVariant convert(const caf::AppEnum<T>& value)
|
||||
{
|
||||
#if PDMFIELDAPPENUM_USE_INDEX_BASED_INTERFACE
|
||||
return QVariant(static_cast<unsigned int>(caf::AppEnum<T>::index(value)));
|
||||
#else
|
||||
unsigned int enumVal = value;
|
||||
return QVariant(enumVal);
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Set the field value from a QVariant
|
||||
static void setFromVariant(const QVariant& variantValue, caf::AppEnum<T>& value)
|
||||
{
|
||||
#if PDMFIELDAPPENUM_USE_INDEX_BASED_INTERFACE
|
||||
value.setFromIndex(variantValue.toInt());
|
||||
#else
|
||||
value = static_cast<T> (variantValue.toInt());
|
||||
#endif
|
||||
}
|
||||
|
||||
/// Methods to get a list of options for a field, specialized for AppEnum
|
||||
@ -280,7 +296,11 @@ public:
|
||||
int i;
|
||||
for (i = 0; i < optionTexts.size(); ++i)
|
||||
{
|
||||
#if PDMFIELDAPPENUM_USE_INDEX_BASED_INTERFACE
|
||||
optionList.push_back(PdmOptionItemInfo(optionTexts[i], static_cast<unsigned int>(i)));
|
||||
#else
|
||||
optionList.push_back(PdmOptionItemInfo(optionTexts[i], caf::AppEnum<T>::fromIndex(i)));
|
||||
#endif
|
||||
}
|
||||
|
||||
return optionList;
|
||||
|
Loading…
Reference in New Issue
Block a user