Files
ResInsight/Fwk/AppFwk/cafProjectDataModel/cafPdmCore/cafPdmFieldHandle.cpp
Magne Sjaastad 69cc36b3bc Add framework support for editor auto values
Add support for a field to be linked to a value updated by code outside the object itself. Mark the linked field by using a background color and icons for linked/unlinked state.
The auto value states is set as attributes in the project xml file. 
Add reference implementation in cafTestApplication, see Fwk/AppFwk/cafTests/cafTestApplication/MainWindow.cpp

* Tree View Editor: Avoid sending notification if selection is unchanged
* Use std++17 in test solution
* Move icons to icon factory
* add support for creating QIcon from SVG text string
2022-09-15 08:19:41 +02:00

162 lines
5.6 KiB
C++

#include "cafPdmFieldHandle.h"
#include "cafPdmFieldCapability.h"
namespace caf
{
#if 0
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::assertValid() const
{
if (m_keyword == "UNDEFINED")
{
std::cout << "PdmField: Detected use of non-initialized field. Did you forget to do CAF_PDM_InitField() on this field ?\n";
return false;
}
if (!PdmXmlSerializable::isValidXmlElementName(m_keyword))
{
std::cout << "PdmField: The supplied keyword: \"" << m_keyword.toStdString() << "\" is an invalid XML element name, and will break your file format!\n";
return false;
}
return true;
}
#endif
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmFieldHandle::setKeyword( const QString& keyword )
{
m_keyword = keyword;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::hasChildren()
{
std::vector<PdmObjectHandle*> children;
this->children( &children );
return ( children.size() > 0 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
PdmFieldHandle::~PdmFieldHandle()
{
for ( size_t i = 0; i < m_capabilities.size(); ++i )
{
if ( m_capabilities[i].second ) delete m_capabilities[i].first;
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::matchesKeyword( const QString& keyword ) const
{
if ( m_keyword == keyword ) return true;
return matchesKeywordAlias( keyword );
}
//--------------------------------------------------------------------------------------------------
/// The class of the ownerObject() can be different to ownerClass().
/// This is because the ownerClass() may be a super-class to the instantiated owner object.
//--------------------------------------------------------------------------------------------------
caf::PdmObjectHandle* PdmFieldHandle::ownerObject()
{
return m_ownerObject;
}
//--------------------------------------------------------------------------------------------------
/// Get the class in the class hierarchy the field actually belongs to.
/// This can be different to ownerObject's class, which may be a sub-class.
//--------------------------------------------------------------------------------------------------
QString PdmFieldHandle::ownerClass() const
{
return m_ownerClass;
}
//--------------------------------------------------------------------------------------------------
/// Set the class in the class hierarchy the field actually belongs to.
/// This can be different to ownerObject's class, which may be a sub-class.
//--------------------------------------------------------------------------------------------------
void PdmFieldHandle::setOwnerClass( const QString& ownerClass )
{
m_ownerClass = ownerClass;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::hasPtrReferencedObjects()
{
std::vector<PdmObjectHandle*> ptrReffedObjs;
this->ptrReferencedObjects( &ptrReffedObjs );
return ( ptrReffedObjs.size() > 0 );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<caf::PdmFieldCapability*> PdmFieldHandle::capabilities() const
{
std::vector<caf::PdmFieldCapability*> allCapabilities;
for ( const auto& cap : m_capabilities )
{
allCapabilities.push_back( cap.first );
}
return allCapabilities;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void PdmFieldHandle::registerKeywordAlias( const QString& alias )
{
m_keywordAliases.push_back( alias );
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool PdmFieldHandle::matchesKeywordAlias( const QString& keyword ) const
{
for ( const QString& alias : m_keywordAliases )
{
if ( alias == keyword ) return true;
}
return false;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<QString> PdmFieldHandle::keywordAliases() const
{
return m_keywordAliases;
}
// These two functions can be used when PdmCore is used standalone without PdmUi/PdmXml
/*
PdmUiFieldHandle* PdmFieldHandle::uiCapability()
{
return NULL;
}
PdmXmlFieldHandle* PdmFieldHandle::xmlCapability()
{
return NULL;
}
*/
} // End of namespace caf