Fixed copyOfTypedObjects

This commit is contained in:
Magne Sjaastad
2015-08-14 08:36:41 +02:00
parent a1ecc50605
commit 9cae0e09ff

View File

@@ -51,39 +51,16 @@ void PdmObjectGroup::createCopyByType(std::vector<PdmPointer<T> >* copyOfTypedOb
std::vector<PdmPointer<T> > sourceTypedObjects; std::vector<PdmPointer<T> > sourceTypedObjects;
objectsByType(&sourceTypedObjects); objectsByType(&sourceTypedObjects);
QString encodedXml; for (size_t i = 0; i < sourceTypedObjects.size(); i++)
{ {
// Write original objects to XML file QString xml = xmlObj(sourceTypedObjects[i])->writeObjectToXmlString();
QXmlStreamWriter xmlStream(&encodedXml);
xmlStream.setAutoFormatting(true);
xmlStream.writeStartElement("", "PdmObjects"); PdmObjectHandle* objectCopy = PdmXmlObjectHandle::readUnknownObjectFromXmlString(xml, PdmDefaultObjectFactory::instance());
for (size_t i = 0; i < sourceTypedObjects.size(); i++)
{
PdmXmlObjectHandle* xmlObjHandle = sourceTypedObjects[i]->capability<PdmXmlObjectHandle>();
assert(xmlObjHandle);
QString className = xmlObjHandle->classKeyword(); T* typedObject = dynamic_cast<T*>(objectCopy);
assert(typedObject);
xmlStream.writeStartElement("", className); copyOfTypedObjects->push_back(typedObject);
xmlObjHandle->writeFields(xmlStream);
xmlStream.writeEndElement();
}
xmlStream.writeEndElement();
}
// Read back XML into object group, factory methods will be called that will create new objects
PdmObjectGroup destinationObjectGroup;
QXmlStreamReader xmlStream(encodedXml);
PdmXmlObjectHandle* xmlObjHandle = destinationObjectGroup.capability<PdmXmlObjectHandle>();
assert(xmlObjHandle);
xmlObjHandle->readFields(xmlStream, objectFactory);
for (size_t it = 0; it < destinationObjectGroup.objects.size(); it++)
{
T* obj = dynamic_cast<T*>(destinationObjectGroup.objects[it]);
if (obj) copyOfTypedObjects->push_back(obj);
} }
} }