mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
CAF: support aliases for keywords in case of renaming
This commit is contained in:
parent
610e7d6391
commit
82cf721ae8
@ -57,6 +57,16 @@ PdmFieldHandle::~PdmFieldHandle()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmFieldHandle::matchesKeyword(const QString& keyword) const
|
||||
{
|
||||
if (m_keyword == keyword) return true;
|
||||
|
||||
return matchesKeywordAlias(keyword);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
virtual ~PdmFieldHandle();
|
||||
|
||||
QString keyword() const { return m_keyword; }
|
||||
|
||||
bool matchesKeyword(const QString& keyword) const;
|
||||
PdmObjectHandle* ownerObject() { return m_ownerObject; }
|
||||
|
||||
// Child objects
|
||||
@ -39,7 +39,10 @@ public:
|
||||
void addCapability(PdmFieldCapability* capability, bool takeOwnership) { m_capabilities.push_back(std::make_pair(capability, takeOwnership)); }
|
||||
|
||||
template <typename CapabilityType>
|
||||
CapabilityType* capability();
|
||||
CapabilityType* capability();
|
||||
template <typename CapabilityType>
|
||||
const CapabilityType* capability() const;
|
||||
|
||||
|
||||
PdmUiFieldHandle* uiCapability();
|
||||
PdmXmlFieldHandle* xmlCapability();
|
||||
@ -50,6 +53,8 @@ protected:
|
||||
private:
|
||||
PDM_DISABLE_COPY_AND_ASSIGN(PdmFieldHandle);
|
||||
|
||||
bool matchesKeywordAlias(const QString& keyword) const;
|
||||
|
||||
friend class PdmObjectHandle; // Give access to m_ownerObject and set Keyword
|
||||
void setKeyword(const QString& keyword);
|
||||
PdmObjectHandle* m_ownerObject;
|
||||
@ -74,4 +79,18 @@ CapabilityType* PdmFieldHandle::capability()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
template <typename CapabilityType>
|
||||
const CapabilityType* PdmFieldHandle::capability() const
|
||||
{
|
||||
for (size_t i = 0; i < m_capabilities.size(); ++i)
|
||||
{
|
||||
const CapabilityType* capability = dynamic_cast<CapabilityType*>(m_capabilities[i].first);
|
||||
if (capability) return capability;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
} // End of namespace caf
|
||||
|
@ -141,7 +141,7 @@ PdmFieldHandle* PdmObjectHandle::findField(const QString& keyword) const
|
||||
for (size_t it = 0; it < fields.size(); it++)
|
||||
{
|
||||
PdmFieldHandle* field = fields[it];
|
||||
if (field->keyword() == keyword)
|
||||
if (field->matchesKeyword(keyword))
|
||||
{
|
||||
return field;
|
||||
}
|
||||
|
@ -61,6 +61,26 @@ QString PdmXmlFieldHandle::childClassKeyword()
|
||||
return m_childClassKeyword;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmXmlFieldHandle::registerKeywordAlias(const QString& alias)
|
||||
{
|
||||
m_keywordAliases.push_back(alias);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmXmlFieldHandle::matchesKeywordAlias(const QString& keyword) const
|
||||
{
|
||||
for (const QString& alias : m_keywordAliases)
|
||||
{
|
||||
if (alias == keyword) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
/// Implementation of uiCapability() defined in cafPdmFieldHandle.h
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@ -72,4 +92,14 @@ PdmXmlFieldHandle* PdmFieldHandle::xmlCapability()
|
||||
return xmlField;
|
||||
}
|
||||
|
||||
bool PdmFieldHandle::matchesKeywordAlias(const QString& keyword) const
|
||||
{
|
||||
const PdmXmlFieldHandle* xmlField = capability<PdmXmlFieldHandle>();
|
||||
if (xmlField)
|
||||
{
|
||||
return xmlField->matchesKeywordAlias(keyword);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // End of namespace caf
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "cafPdmFieldCapability.h"
|
||||
#include <QString>
|
||||
#include <vector>
|
||||
|
||||
class QXmlStreamReader;
|
||||
class QXmlStreamWriter;
|
||||
@ -39,6 +40,9 @@ public:
|
||||
|
||||
QString childClassKeyword();
|
||||
|
||||
void registerKeywordAlias(const QString& alias);
|
||||
bool matchesKeywordAlias(const QString& keyword) const;
|
||||
|
||||
virtual void readFieldData(QXmlStreamReader& xmlStream, PdmObjectFactory* objectFactory) = 0;
|
||||
virtual void writeFieldData(QXmlStreamWriter& xmlStream) const = 0;
|
||||
|
||||
@ -51,9 +55,10 @@ protected:
|
||||
QString m_childClassKeyword; ///< Must be set in constructor of derived XmlFieldHandle
|
||||
|
||||
private:
|
||||
bool m_isIOReadable;
|
||||
bool m_isIOWritable;
|
||||
bool m_isCopyable;
|
||||
bool m_isIOReadable;
|
||||
bool m_isIOWritable;
|
||||
bool m_isCopyable;
|
||||
std::vector<QString> m_keywordAliases;
|
||||
|
||||
PdmFieldHandle* m_owner;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user