Created infrastructure used to resolve references for ptrFields

This commit is contained in:
Magne Sjaastad 2015-08-25 14:14:38 +02:00
parent 2b87c8c7d6
commit 90b6dd44ee
6 changed files with 56 additions and 4 deletions

View File

@ -34,6 +34,7 @@ public:
// Ptr referenced objects
bool hasPtrReferencedObjects();
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>*) { }
virtual void resolveReferences() { }
// Capabilities
void addCapability(PdmFieldCapability* capability, bool takeOwnership) { m_capabilities.push_back(std::make_pair(capability, takeOwnership)); }

View File

@ -37,7 +37,7 @@ class PdmPtrField <DataType*> : public PdmFieldHandle
public:
typedef PdmPointer<DataType> FieldDataType;
PdmPtrField() { }
PdmPtrField() { m_referenceString = ""; m_isResolved = false; }
explicit PdmPtrField(const DataTypePtr& fieldValue);
virtual ~PdmPtrField();
@ -68,6 +68,7 @@ public:
// Ptr referenced objects
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>* objectsToFill);
virtual void resolveReferences();
private:
PDM_DISABLE_COPY_AND_ASSIGN(PdmPtrField);
@ -76,6 +77,10 @@ private:
void setRawPtr(PdmObjectHandle* obj);
PdmPointer<DataType> m_fieldValue;
// Resolving
QString m_referenceString;
bool m_isResolved;
};
} // End of namespace caf

View File

@ -100,5 +100,19 @@ void PdmPtrField<DataType*>::ptrReferencedObjects(std::vector<PdmObjectHandle*>*
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
template<typename DataType >
void PdmPtrField<DataType*>::resolveReferences()
{
if (m_isResolved) return;
if (m_referenceString.isEmpty()) return;
PdmObjectHandle* objHandle = PdmReferenceHelper::objectFromFieldReference(this, m_referenceString);
this->setRawPtr(objHandle);
m_isResolved = true;
}
} // End of namespace caf

View File

@ -91,6 +91,7 @@ void PdmDocument::readFile(QIODevice* xmlFile)
// Ask all objects to initialize and set up internal datastructure and pointers
// after everything is read from file
PdmDocument::resolveReferencesTraversal(this);
PdmDocument::initAfterReadTraversal(this);
}
@ -215,6 +216,36 @@ void PdmDocument::updateUiIconStateRecursively(PdmObjectHandle* object)
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmDocument::resolveReferencesTraversal(PdmObjectHandle* object)
{
if (object == NULL) return;
std::vector<PdmFieldHandle*> fields;
object->fields(fields);
std::vector<PdmObjectHandle*> children;
size_t fIdx;
for (fIdx = 0; fIdx < fields.size(); ++fIdx)
{
PdmFieldHandle* field = fields[fIdx];
if (field)
{
field->childObjects(&children);
field->resolveReferences();
}
}
size_t cIdx;
for (cIdx = 0; cIdx < children.size(); ++cIdx)
{
PdmDocument::resolveReferencesTraversal(children[cIdx]);
}
}
} //End of namespace caf

View File

@ -63,6 +63,7 @@ class PdmDocument: public PdmObject
static void updateUiIconStateRecursively(PdmObjectHandle* root);
static void initAfterReadTraversal(PdmObjectHandle* root);
static void resolveReferencesTraversal(PdmObjectHandle* root);
private:
static void setupBeforeSaveTraversal(PdmObjectHandle * root);

View File

@ -67,9 +67,9 @@ template<typename FieldType >
//
// and then we need a traversal of the object hierarchy to resolve all references before initAfterRead.
PdmObjectHandle* objHandle = PdmReferenceHelper::objectFromFieldReference(m_field, dataString);
m_field->setRawPtr(objHandle);
}
m_field->m_isResolved = false;
m_field->m_referenceString = dataString;
}
//--------------------------------------------------------------------------------------------------
///