mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-24 15:26:48 -06:00
Created infrastructure used to resolve references for ptrFields
This commit is contained in:
parent
2b87c8c7d6
commit
90b6dd44ee
@ -34,6 +34,7 @@ public:
|
|||||||
// Ptr referenced objects
|
// Ptr referenced objects
|
||||||
bool hasPtrReferencedObjects();
|
bool hasPtrReferencedObjects();
|
||||||
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>*) { }
|
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>*) { }
|
||||||
|
virtual void resolveReferences() { }
|
||||||
|
|
||||||
// Capabilities
|
// Capabilities
|
||||||
void addCapability(PdmFieldCapability* capability, bool takeOwnership) { m_capabilities.push_back(std::make_pair(capability, takeOwnership)); }
|
void addCapability(PdmFieldCapability* capability, bool takeOwnership) { m_capabilities.push_back(std::make_pair(capability, takeOwnership)); }
|
||||||
|
@ -37,7 +37,7 @@ class PdmPtrField <DataType*> : public PdmFieldHandle
|
|||||||
public:
|
public:
|
||||||
typedef PdmPointer<DataType> FieldDataType;
|
typedef PdmPointer<DataType> FieldDataType;
|
||||||
|
|
||||||
PdmPtrField() { }
|
PdmPtrField() { m_referenceString = ""; m_isResolved = false; }
|
||||||
explicit PdmPtrField(const DataTypePtr& fieldValue);
|
explicit PdmPtrField(const DataTypePtr& fieldValue);
|
||||||
virtual ~PdmPtrField();
|
virtual ~PdmPtrField();
|
||||||
|
|
||||||
@ -68,6 +68,7 @@ public:
|
|||||||
// Ptr referenced objects
|
// Ptr referenced objects
|
||||||
|
|
||||||
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>* objectsToFill);
|
virtual void ptrReferencedObjects(std::vector<PdmObjectHandle*>* objectsToFill);
|
||||||
|
virtual void resolveReferences();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PDM_DISABLE_COPY_AND_ASSIGN(PdmPtrField);
|
PDM_DISABLE_COPY_AND_ASSIGN(PdmPtrField);
|
||||||
@ -76,6 +77,10 @@ private:
|
|||||||
void setRawPtr(PdmObjectHandle* obj);
|
void setRawPtr(PdmObjectHandle* obj);
|
||||||
|
|
||||||
PdmPointer<DataType> m_fieldValue;
|
PdmPointer<DataType> m_fieldValue;
|
||||||
|
|
||||||
|
// Resolving
|
||||||
|
QString m_referenceString;
|
||||||
|
bool m_isResolved;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End of namespace caf
|
} // End of namespace caf
|
||||||
|
@ -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
|
} // End of namespace caf
|
||||||
|
|
||||||
|
@ -91,6 +91,7 @@ void PdmDocument::readFile(QIODevice* xmlFile)
|
|||||||
// Ask all objects to initialize and set up internal datastructure and pointers
|
// Ask all objects to initialize and set up internal datastructure and pointers
|
||||||
// after everything is read from file
|
// after everything is read from file
|
||||||
|
|
||||||
|
PdmDocument::resolveReferencesTraversal(this);
|
||||||
PdmDocument::initAfterReadTraversal(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
|
} //End of namespace caf
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ class PdmDocument: public PdmObject
|
|||||||
|
|
||||||
static void updateUiIconStateRecursively(PdmObjectHandle* root);
|
static void updateUiIconStateRecursively(PdmObjectHandle* root);
|
||||||
static void initAfterReadTraversal(PdmObjectHandle* root);
|
static void initAfterReadTraversal(PdmObjectHandle* root);
|
||||||
|
static void resolveReferencesTraversal(PdmObjectHandle* root);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void setupBeforeSaveTraversal(PdmObjectHandle * root);
|
static void setupBeforeSaveTraversal(PdmObjectHandle * root);
|
||||||
|
@ -67,9 +67,9 @@ template<typename FieldType >
|
|||||||
//
|
//
|
||||||
// and then we need a traversal of the object hierarchy to resolve all references before initAfterRead.
|
// 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->m_isResolved = false;
|
||||||
m_field->setRawPtr(objHandle);
|
m_field->m_referenceString = dataString;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user