Commit ffdc36ed authored by Dirk Wilden's avatar Dirk Wilden

added slotDescriptions for scripting slots

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@3418 383ad7c9-94d9-4d36-a494-682f7c89f535
parent e0840170
......@@ -81,6 +81,19 @@ class BaseInterface {
*/
virtual void activeObjectChanged() {};
/** \brief Set a description for a public slot
*
* public slots of each plugin are automaticly available for scripting. \n
* Use this Signal to add a description for your slot so that everyone knows what it is used for. \n
*
* @param _slotName the name of the slot
* @param _slotDescription a description for the slot
* @param _parameters list of parameters
* @param _descriptions list of descriptions for the parameters (_descriptions[i] corresponds to _parameters[i])
*/
virtual void setSlotDescription(QString /*_slotName*/, QString /*_slotDescription*/,
QStringList /*_parameters*/, QStringList /*_descriptions*/) {};
private slots :
/** \brief An object has been updated by an other plugin
......
......@@ -77,6 +77,16 @@ class ScriptInterface {
* @param _functions All available functions
*/
virtual void getAvailableFunctions( QStringList& /*_functions*/ ) {};
/** With this signal you can get descriptions about a given function if available
*
* @param _function name of the function (e.g. plugin.function)
* @param _description a description for the function
* @param _parameters list of names for the parameters
* @param _descriptions list of descriptions for the parameters (_descriptions[i] corresponds to _parameters[i])
*/
virtual void getDescription(QString /*_function*/, QString& /*_description*/,
QStringList& /*_parameters*/, QStringList& /*_descriptions*/ ) {};
private slots:
......
......@@ -124,6 +124,8 @@ Core() :
// Get all relevant Paths and Options from option files
setupOptions();
// set discriptions for scriptable slots
setDescriptions();
}
/** \brief Second initialization stage
......@@ -798,6 +800,124 @@ void Core::slotLogToFile(Logtype _type, QString _message){
}
/// set descriptions for a scriptable slot
void Core::slotSetSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions)
{
//handle core slots
if (sender() == this){
SlotInfo info;
info.slotName = _slotName;
info.slotDescription = _slotDescription;
info.parameters = _parameters;
info.descriptions = _descriptions;
coreSlots_.push_back( info );
return;
}
//handle plugin slots
//find plugin
PluginInfo* pluginInfo = 0;
for (uint i=0; i < plugins.size(); i++)
if (plugins[i].plugin == sender())
pluginInfo = &plugins[i];
if (pluginInfo == 0){
emit log(LOGERR, "Unable to set slot-description. Plugin not found!");
return;
}
SlotInfo info;
info.slotName = _slotName;
info.slotDescription = _slotDescription;
info.parameters = _parameters;
info.descriptions = _descriptions;
pluginInfo->slotInfos.append( info );
}
/// get available Descriptions for a scriptable slot
void Core::slotGetDescription(QString _function, QString& _fnDescription,
QStringList& _parameters, QStringList& _descriptions )
{
QString pluginName = _function.section(".", 0, 0);
QString slotName = _function.section(".", 1, 1);
//handle core slots
if (pluginName == "core"){
_fnDescription = "";
_parameters.clear();
_descriptions.clear();
for (int i=0; i < coreSlots_.count(); i++)
if (coreSlots_[i].slotName == slotName){
_fnDescription = coreSlots_[i].slotDescription;
_parameters = coreSlots_[i].parameters;
_descriptions = coreSlots_[i].descriptions;
return;
}
return;
}
//handle plugin slots
//find plugin
PluginInfo* pluginInfo = 0;
for (uint i=0; i < plugins.size(); i++)
if (plugins[i].rpcName == pluginName)
pluginInfo = &plugins[i];
if (pluginInfo == 0){
emit log(LOGERR, "Unable to get slot-description. Plugin not found!");
return;
}
_fnDescription = "";
_parameters.clear();
_descriptions.clear();
//find slot
for (int i=0; i < pluginInfo->slotInfos.count(); i++)
if (pluginInfo->slotInfos[i].slotName == slotName){
_fnDescription = pluginInfo->slotInfos[i].slotDescription;
_parameters = pluginInfo->slotInfos[i].parameters;
_descriptions = pluginInfo->slotInfos[i].descriptions;
return;
}
}
/// set the descriptions for scriptable slots of the core
void Core::setDescriptions(){
connect(this, SIGNAL(setSlotDescription(QString,QString,QStringList,QStringList)),
this, SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
emit setSlotDescription("updateView()", "Redraw the contents of the viewer.", QStringList(), QStringList());
emit setSlotDescription("clearAll()", "Clear all data objects.", QStringList(), QStringList());
emit setSlotDescription("exitApplication()", "Quit OpenFlipper", QStringList(), QStringList());
emit setSlotDescription("translate(Vector)", "translate Scene",
QStringList("TranslationVector"), QStringList("vector for the translation."));
emit setSlotDescription("rotate(Vector,double,Vector)", "Rotate Scene",
QString("Axis,Angle,Center").split(","),
QString("Rotation axis., Rotation Angle., Rotation Center.").split(","));
emit setSlotDescription("setViewingDirection(Vector,Vector)", "Set the viewing direction",
QString("direction,upVector").split(","),
QString("Viewing direction., Up-Vector.").split(","));
emit setSlotDescription("fullscreen()", "Toggle fullscreen mode", QStringList(), QStringList());
emit setSlotDescription("logger()", "Toggle logging window visibility", QStringList(), QStringList());
emit setSlotDescription("toolbox()", "Toggle toolbox visibility", QStringList(), QStringList());
emit setSlotDescription("setDrawMode(QString)", "Set the drawMode",
QStringList("DrawMode"), QStringList("the drawMode ( ; separated list )"));
emit setSlotDescription("restrictFrameRate(bool)", "Restrict FrameRate to MaxFrameRate",
QStringList("enabled"), QStringList("restriction switch"));
emit setSlotDescription("setMaxFrameRate(int)", "set the maximal framerate (automatically enables framerate restriction)",
QStringList("frameRate"), QStringList("Maximum frameRate"));
}
// //-----------------------------------------------------------------------------
//
// void Core::slotGetPlugin(QString _name, QObject* & _plugin ){
......
......@@ -557,6 +557,8 @@ private:
void executeFileScript( QString _filename );
void setSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
private :
/// Core scripting engine
QScriptEngine scriptEngine_;
......@@ -583,6 +585,19 @@ private:
void slotGetAllAvailableFunctions( QStringList& _functions );
/// set a description for one of the plugin's public slots
void slotSetSlotDescription(QString _slotName, QString _slotDescription,
QStringList _parameters, QStringList _descriptions);
/// get available descriptions for a given public slot
void slotGetDescription(QString _function, QString& _fnDescription,
QStringList& _parameters, QStringList& _descriptions );
private:
QList< SlotInfo > coreSlots_;
void setDescriptions();
/** @} */
//===========================================================================
......
......@@ -15,6 +15,13 @@ struct KeyBinding{
bool multiUse;
};
struct SlotInfo{
QString slotName;
QString slotDescription;
QStringList parameters;
QStringList descriptions;
};
/** Type defining a currently loaded Plugin */
struct PluginInfo{
......@@ -39,6 +46,9 @@ struct PluginInfo{
/// List of exported rpc slots
QStringList rpcFunctions;
/// This list contains Descriptions about public slots if available
QList< SlotInfo > slotInfos;
/// List of registered keys with description
QList< KeyBinding > keys;
......
......@@ -471,6 +471,10 @@ void Core::loadPlugin(QString filename, bool silent){
if ( checkSlot( plugin , "pluginsInitialized()" ) )
connect(this,SIGNAL(pluginsInitialized()),plugin,SLOT(pluginsInitialized()), Qt::DirectConnection);
if ( checkSignal(plugin,"setSlotDescription(QString,QString,QStringList,QStringList)") )
connect(plugin, SIGNAL(setSlotDescription(QString,QString,QStringList,QStringList)),
this, SLOT(slotSetSlotDescription(QString,QString,QStringList,QStringList)) );
}
//Check if its a filePlugin
......@@ -918,6 +922,11 @@ void Core::loadPlugin(QString filename, bool silent){
plugin , SLOT(slotScriptInfo(QString,QString)));
}
// Function descriptions
if ( checkSignal(plugin,"getDescription(QString,QString&,QStringList&,QStringList&)") )
connect(plugin , SIGNAL( getDescription(QString,QString&,QStringList&,QStringList&) ),
this , SLOT( slotGetDescription(QString,QString&,QStringList&,QStringList&) ));
//========= Script Execution ==========
// Plugins to Core
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment