Added deepCopy()

p4#: 22334
This commit is contained in:
Magne Sjaastad 2013-09-06 15:30:32 +02:00
parent 46f02f9384
commit 6c7c11ab6b
2 changed files with 56 additions and 0 deletions

View File

@ -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

View File

@ -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.