mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Add separate scriptKeyword to RICF capability and a Python help tooltip system
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
#include "RiaTextStringTools.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -32,3 +34,16 @@ RicfCommandObject::RicfCommandObject()
|
||||
RicfCommandObject::~RicfCommandObject()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString RicfCommandObject::pythonHelpString( const QString& existingTooltip, const QString& keyword )
|
||||
{
|
||||
QString snake_case = RiaTextStringTools::camelToSnakeCase( keyword );
|
||||
|
||||
QString helpString = QString( "Available through python/rips as the attribute '%1'" ).arg( snake_case );
|
||||
|
||||
if ( !existingTooltip.isEmpty() ) return existingTooltip + "\n\n" + helpString;
|
||||
return helpString;
|
||||
}
|
||||
|
||||
@@ -23,13 +23,59 @@
|
||||
#include "cafCmdFeature.h"
|
||||
#include "cafPdmObject.h"
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfCommandObject : public caf::PdmObject, public RicfObjectCapability
|
||||
{
|
||||
public:
|
||||
RicfCommandObject();
|
||||
~RicfCommandObject() override;
|
||||
|
||||
virtual RicfCommandResponse execute() = 0;
|
||||
|
||||
static QString pythonHelpString( const QString& existingTooltip, const QString& keyword );
|
||||
};
|
||||
|
||||
#define RICF_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitField( field, keyword, default, uiName, iconResourceName, toolTip, whatsThis ); \
|
||||
AddRicfCapabilityToField( field )
|
||||
CAF_PDM_InitField( field, \
|
||||
keyword, \
|
||||
default, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, keyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, keyword )
|
||||
|
||||
#define RICF_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitFieldNoDefault( field, keyword, uiName, iconResourceName, toolTip, whatsThis ); \
|
||||
AddRicfCapabilityToField( field )
|
||||
CAF_PDM_InitFieldNoDefault( field, \
|
||||
keyword, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, keyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, keyword )
|
||||
|
||||
#define RICF_InitFieldTranslated( field, keyword, scriptKeyword, default, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitField( field, \
|
||||
keyword, \
|
||||
default, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, scriptKeyword )
|
||||
|
||||
#define RICF_InitFieldNoDefaultTranslated( field, keyword, scriptKeyword, uiName, iconResourceName, toolTip, whatsThis ) \
|
||||
CAF_PDM_InitFieldNoDefault( field, \
|
||||
keyword, \
|
||||
uiName, \
|
||||
iconResourceName, \
|
||||
RicfCommandObject::pythonHelpString( toolTip, scriptKeyword ), \
|
||||
whatsThis ); \
|
||||
AddRicfCapabilityToField( field, scriptKeyword )
|
||||
|
||||
#define RICF_HEADER_INIT \
|
||||
CAF_CMD_HEADER_INIT; \
|
||||
@@ -44,17 +90,3 @@
|
||||
} \
|
||||
CAF_FACTORY_REGISTER2( caf::CmdFeature, ClassName, std::string, ClassName::idNameStatic() ); \
|
||||
CAF_PDM_SOURCE_INIT( ClassName, CommandKeyword )
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfCommandObject : public caf::PdmObject, public RicfObjectCapability
|
||||
{
|
||||
public:
|
||||
RicfCommandObject();
|
||||
~RicfCommandObject() override;
|
||||
|
||||
virtual RicfCommandResponse execute() = 0;
|
||||
};
|
||||
|
||||
@@ -215,8 +215,8 @@ template <typename FieldType>
|
||||
class RicfFieldCapability : public RicfFieldHandle
|
||||
{
|
||||
public:
|
||||
RicfFieldCapability( FieldType* field, bool giveOwnership )
|
||||
: RicfFieldHandle( field, giveOwnership )
|
||||
RicfFieldCapability( FieldType* field, const QString& fieldName, bool giveOwnership )
|
||||
: RicfFieldHandle( field, fieldName, giveOwnership )
|
||||
{
|
||||
m_field = field;
|
||||
}
|
||||
@@ -250,10 +250,10 @@ private:
|
||||
};
|
||||
|
||||
template <typename FieldType>
|
||||
void AddRicfCapabilityToField( FieldType* field )
|
||||
void AddRicfCapabilityToField( FieldType* field, const QString& fieldName )
|
||||
{
|
||||
if ( field->template capability<RicfFieldCapability<FieldType>>() == nullptr )
|
||||
{
|
||||
new RicfFieldCapability<FieldType>( field, true );
|
||||
new RicfFieldCapability<FieldType>( field, fieldName, true );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,11 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership )
|
||||
RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& fieldName, bool giveOwnership )
|
||||
{
|
||||
m_IOWriteable = true;
|
||||
m_owner = owner;
|
||||
m_fieldName = fieldName;
|
||||
owner->addCapability( this, giveOwnership );
|
||||
}
|
||||
|
||||
@@ -35,3 +36,11 @@ RicfFieldHandle::RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership
|
||||
RicfFieldHandle::~RicfFieldHandle()
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const QString& RicfFieldHandle::fieldName() const
|
||||
{
|
||||
return m_fieldName;
|
||||
}
|
||||
|
||||
@@ -39,9 +39,11 @@ class QTextStream;
|
||||
class RicfFieldHandle : public caf::PdmFieldCapability
|
||||
{
|
||||
public:
|
||||
RicfFieldHandle( caf::PdmFieldHandle* owner, bool giveOwnership );
|
||||
RicfFieldHandle( caf::PdmFieldHandle* owner, const QString& fieldName, bool giveOwnership );
|
||||
~RicfFieldHandle() override;
|
||||
|
||||
const QString& fieldName() const;
|
||||
|
||||
bool isIOWriteable() const { return m_IOWriteable; }
|
||||
|
||||
void setIOWriteable( bool writeable ) { m_IOWriteable = writeable; }
|
||||
@@ -54,5 +56,6 @@ public:
|
||||
|
||||
private:
|
||||
caf::PdmFieldHandle* m_owner;
|
||||
QString m_fieldName;
|
||||
bool m_IOWriteable;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user