mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-02 09:00:14 -06:00
Add copyObject to PdmObjectHandle
New syntax to copy an object
auto curveCopy = curve->copyObject<RimSummaryCurve>();
Previous deprecated syntax
RimColorLegend* customLegend = dynamic_cast<RimColorLegend*>(
standardLegend->xmlCapability()->copyByXmlSerialization( caf::PdmDefaultObjectFactory::instance() ) );
This commit is contained in:
1 parent
7efefbb93a
commit
a0ebb6e496
46 files changed
+126
-131
No files matched your search
@@ -167,6 +167,14 @@ void PdmObjectHandle::prepareForDelete()
|
||||
m_pointersReferencingMe.clear();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmObjectHandle::addCapability( PdmObjectCapability* capability, bool takeOwnership )
|
||||
{
|
||||
m_capabilities.push_back( std::make_pair( capability, takeOwnership ) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -181,6 +189,14 @@ void PdmObjectHandle::addField( PdmFieldHandle* field, const QString& keyword )
|
||||
m_fields.push_back( field );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
caf::PdmObjectHandle* PdmObjectHandle::doCopyObject() const
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -31,6 +31,10 @@ public:
|
||||
static QString classKeywordStatic(); // For PdmXmlFieldCap to be able to handle fields of PdmObjectHandle directly
|
||||
static std::vector<QString> classKeywordAliases();
|
||||
|
||||
// Function template to call the virtual copy function
|
||||
template <typename T>
|
||||
[[nodiscard]] T* copyObject() const;
|
||||
|
||||
/// The registered fields contained in this PdmObject.
|
||||
[[nodiscard]] std::vector<PdmFieldHandle*> fields() const;
|
||||
[[nodiscard]] PdmFieldHandle* findField( const QString& keyword ) const;
|
||||
@@ -84,21 +88,10 @@ public:
|
||||
void prepareForDelete();
|
||||
|
||||
// Object capabilities
|
||||
void addCapability( PdmObjectCapability* capability, bool takeOwnership )
|
||||
{
|
||||
m_capabilities.push_back( std::make_pair( capability, takeOwnership ) );
|
||||
}
|
||||
void addCapability( PdmObjectCapability* capability, bool takeOwnership );
|
||||
|
||||
template <typename CapabilityType>
|
||||
CapabilityType* capability() const
|
||||
{
|
||||
for ( size_t i = 0; i < m_capabilities.size(); ++i )
|
||||
{
|
||||
CapabilityType* capability = dynamic_cast<CapabilityType*>( m_capabilities[i].first );
|
||||
if ( capability ) return capability;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
CapabilityType* capability() const;
|
||||
|
||||
PdmUiObjectHandle* uiCapability() const; // Implementation is in cafPdmUiObjectHandle.cpp
|
||||
PdmXmlObjectHandle* xmlCapability() const; // Implementation is in cafPdmXmlObjectHandle.cpp
|
||||
@@ -118,6 +111,9 @@ public:
|
||||
protected:
|
||||
void addField( PdmFieldHandle* field, const QString& keyword );
|
||||
|
||||
// Virtual method used to copy objects. The implementation is in PdmObject
|
||||
[[nodiscard]] virtual PdmObjectHandle* doCopyObject() const;
|
||||
|
||||
private:
|
||||
PDM_DISABLE_COPY_AND_ASSIGN( PdmObjectHandle );
|
||||
|
||||
@@ -173,6 +169,16 @@ private:
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
[[nodiscard]] T* PdmObjectHandle::copyObject() const
|
||||
{
|
||||
return dynamic_cast<T*>( doCopyObject() );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -338,4 +344,17 @@ template <typename T>
|
||||
return objectsOfType;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename CapabilityType>
|
||||
CapabilityType* PdmObjectHandle::capability() const
|
||||
{
|
||||
for ( auto capability : m_capabilities )
|
||||
{
|
||||
if ( auto capabilityType = dynamic_cast<CapabilityType*>( capability.first ) ) return capabilityType;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // End of namespace caf
|
||||
Reference in new issue
Block a user