ResInsight/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmPtrField.inl
Magne Sjaastad 1d57b9032b
Custom vfp plot (#11450)
* AppFwk: When clearing a tree selection, make sure all values are cleared
* Fix deprecated implicit lambda
* Add support for using the closest value in addition to exact match
* Add table data source object and add plot with multiple data sources
Delete the temporary RimVfpDeck class
Add RimVfpTable to represent a table in a data source
Add plot able to show data from multiple tables

* AppFwk: Make it possible to call resolveReferences multiple times
Use case: Vfp tables are stored in files. Multiple tables can be present in one file. Pdm table objects are created after resolve references is done as part of parsing file. When the Pdm object are created, resolveReferences can be called once more.

* Call resolveReferencesRecursively() after RimVfpTable objects are created
2024-05-29 12:55:45 +02:00

117 lines
4.5 KiB
C++

#include <QVariant>
namespace caf
{
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
QVariant caf::PdmPtrField<DataType*>::toQVariant() const
{
caf::PdmObjectHandle* objectHandle = m_fieldValue.rawPtr();
caf::PdmPointer<caf::PdmObjectHandle> ptrHandle( objectHandle );
return QVariant::fromValue( ptrHandle );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void caf::PdmPtrField<DataType*>::setFromQVariant( const QVariant& variant )
{
caf::PdmPointer<caf::PdmObjectHandle> variantHandle = variant.value<caf::PdmPointer<caf::PdmObjectHandle>>();
m_fieldValue.setRawPtr( variantHandle.rawPtr() );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
caf::PdmPtrField<DataType*>::PdmPtrField( const DataTypePtr& fieldValue )
{
m_fieldValue = fieldValue;
if ( m_fieldValue != NULL ) m_fieldValue->addReferencingPtrField( this );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
caf::PdmPtrField<DataType*>::~PdmPtrField()
{
if ( !m_fieldValue.isNull() ) m_fieldValue.rawPtr()->removeReferencingPtrField( this );
m_fieldValue.setRawPtr( NULL );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void PdmPtrField<DataType*>::setValue( const DataTypePtr& fieldValue )
{
CAF_ASSERT( isInitializedByInitFieldMacro() );
if ( m_fieldValue ) m_fieldValue->removeReferencingPtrField( this );
m_fieldValue = fieldValue;
if ( m_fieldValue != NULL ) m_fieldValue->addReferencingPtrField( this );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
void PdmPtrField<DataType*>::setRawPtr( PdmObjectHandle* obj )
{
CAF_ASSERT( isInitializedByInitFieldMacro() );
if ( m_fieldValue.notNull() ) m_fieldValue.rawPtr()->removeReferencingPtrField( this );
m_fieldValue.setRawPtr( obj );
if ( m_fieldValue.notNull() ) m_fieldValue.rawPtr()->addReferencingPtrField( this );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
caf::PdmPtrField<DataType*>& PdmPtrField<DataType*>::operator=( const DataTypePtr& fieldValue )
{
CAF_ASSERT( isInitializedByInitFieldMacro() );
if ( m_fieldValue ) m_fieldValue->removeReferencingPtrField( this );
m_fieldValue = fieldValue;
if ( m_fieldValue != NULL ) m_fieldValue->addReferencingPtrField( this );
return *this;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
caf::PdmPtrField<DataType*>& PdmPtrField<DataType*>::operator=( const FieldDataType& fieldValue )
{
CAF_ASSERT( isInitializedByInitFieldMacro() );
if ( m_fieldValue ) m_fieldValue->removeReferencingPtrField( this );
m_fieldValue = fieldValue;
if ( m_fieldValue != NULL ) m_fieldValue->addReferencingPtrField( this );
return *this;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template <typename DataType>
std::vector<PdmObjectHandle*> PdmPtrField<DataType*>::ptrReferencedObjects() const
{
if ( m_fieldValue.rawPtr() )
{
return { m_fieldValue.rawPtr() };
}
return {};
}
} // End of namespace caf