mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Added deepCopy()
p4#: 22334
This commit is contained in:
parent
46f02f9384
commit
6c7c11ab6b
@ -24,6 +24,8 @@
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include "cafPdmObjectFactory.h"
|
||||
#include "cafPdmDocument.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@ -309,6 +311,58 @@ bool PdmObject::isValidXmlElementName(const QString& name)
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmObject* PdmObject::deepCopy()
|
||||
{
|
||||
QString encodedXml;
|
||||
|
||||
{
|
||||
PdmObjectGroup typedObjectGroup;
|
||||
typedObjectGroup.addObject(this);
|
||||
|
||||
QXmlStreamWriter xmlStream(&encodedXml);
|
||||
xmlStream.setAutoFormatting(true);
|
||||
|
||||
typedObjectGroup.writeFields(xmlStream);
|
||||
}
|
||||
|
||||
PdmObject* pdmCopy = NULL;
|
||||
{
|
||||
// Read back XML into object group, factory methods will be called that will create new objects
|
||||
PdmObjectGroup destinationObjectGroup;
|
||||
QXmlStreamReader xmlStream(encodedXml);
|
||||
destinationObjectGroup.readFields(xmlStream);
|
||||
|
||||
if (destinationObjectGroup.objects.size() == 1)
|
||||
{
|
||||
pdmCopy = destinationObjectGroup.objects[0];
|
||||
}
|
||||
}
|
||||
|
||||
return pdmCopy;
|
||||
|
||||
/*
|
||||
PdmObject* cloneRoot = PdmObjectFactory::instance()->create(this->classKeyword());
|
||||
|
||||
|
||||
|
||||
QString encodedXml;
|
||||
{
|
||||
QXmlStreamWriter xmlStream(&encodedXml);
|
||||
xmlStream.setAutoFormatting(true);
|
||||
|
||||
this->writeFields(xmlStream);
|
||||
}
|
||||
|
||||
QXmlStreamReader xmlStream(encodedXml);
|
||||
cloneRoot->readFields(xmlStream);
|
||||
|
||||
return cloneRoot;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
} //End of namespace caf
|
||||
|
@ -122,6 +122,8 @@ public:
|
||||
void readFields (QXmlStreamReader& inputStream );
|
||||
void writeFields(QXmlStreamWriter& outputStream);
|
||||
|
||||
PdmObject* deepCopy();
|
||||
|
||||
/// The registered fields contained in this PdmObject. Registered by subclasses.
|
||||
void fields(std::vector<PdmFieldHandle*>& fields) const;
|
||||
/// The fields containing pointers to this PdmObject. Use ownerObject() on the fieldHandle to get the PdmObject parent.
|
||||
|
Loading…
Reference in New Issue
Block a user