mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Move to use a static registry of scriptable classes
This commit is contained in:
@@ -19,16 +19,23 @@
|
||||
#include "RicfObjectCapability.h"
|
||||
#include "RicfFieldHandle.h"
|
||||
#include "RicfMessages.h"
|
||||
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include "cafPdmXmlFieldHandle.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
std::map<QString, QString> RicfObjectCapability::s_classKeywordToScriptClassName;
|
||||
std::map<QString, QString> RicfObjectCapability::s_scriptClassNameToClassKeyword;
|
||||
std::map<QString, QString> RicfObjectCapability::s_scriptClassComments;
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfObjectCapability::RicfObjectCapability( caf::PdmObjectHandle* owner, bool giveOwnership )
|
||||
: m_owner( owner )
|
||||
{
|
||||
m_owner = owner;
|
||||
m_owner->addCapability( this, giveOwnership );
|
||||
}
|
||||
|
||||
@@ -216,3 +223,76 @@ void RicfObjectCapability::writeFields( QTextStream& outputStream ) const
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfObjectCapability::registerScriptClassNameAndComment( const QString& classKeyword,
|
||||
const QString& scriptClassName,
|
||||
const QString& scriptClassComment )
|
||||
{
|
||||
s_classKeywordToScriptClassName[classKeyword] = scriptClassName;
|
||||
s_scriptClassNameToClassKeyword[scriptClassName] = classKeyword;
|
||||
s_scriptClassComments[classKeyword] = scriptClassComment;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfObjectCapability::scriptClassNameFromClassKeyword( const QString& classKeyword )
|
||||
{
|
||||
auto it = s_classKeywordToScriptClassName.find( classKeyword );
|
||||
if ( it != s_classKeywordToScriptClassName.end() )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return classKeyword;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfObjectCapability::classKeywordFromScriptClassName( const QString& scriptClassName )
|
||||
{
|
||||
auto it = s_scriptClassNameToClassKeyword.find( scriptClassName );
|
||||
if ( it != s_scriptClassNameToClassKeyword.end() )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return scriptClassName;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfObjectCapability::scriptClassComment( const QString& classKeyword )
|
||||
{
|
||||
auto it = s_scriptClassComments.find( classKeyword );
|
||||
if ( it != s_scriptClassComments.end() )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool RicfObjectCapability::isScriptable( const caf::PdmObject* object )
|
||||
{
|
||||
return s_classKeywordToScriptClassName.find( object->classKeyword() ) != s_classKeywordToScriptClassName.end();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfObjectCapability::addCapabilityToObject( caf::PdmObject* object,
|
||||
const QString& scriptClassName,
|
||||
const QString& scriptClassComment )
|
||||
{
|
||||
if ( !object->capability<RicfObjectCapability>() )
|
||||
{
|
||||
new RicfObjectCapability( object, true );
|
||||
}
|
||||
RicfObjectCapability::registerScriptClassNameAndComment( object->classKeyword(), scriptClassName, scriptClassComment );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user