KTutorial
0.5.1
|
Main KTutorial interface for scripts. More...
#include <ScriptingModule.h>
Public Member Functions | |
virtual | ~ScriptingModule () |
Destroys this ScriptingModule. | |
bool | registerWaitForMetaObject (const QMetaObject &waitForMetaObject, const QString &typeName=QString()) |
Registers a WaitFor type to create instances of it using newWaitFor(const QString&). | |
Q_INVOKABLE QObject * | findObject (const QString &name) |
Returns the object with the specified name, if any. | |
Q_INVOKABLE QObject * | newOption (const QString &name) |
Returns a new Option with the given name. | |
Q_INVOKABLE QObject * | newStep (const QString &id) |
Returns a new ScriptedStep with the given id. | |
Q_INVOKABLE QObject * | newWaitFor (const QString &typeName) |
Returns a new WaitFor of the given type name. | |
Static Public Member Functions | |
static ScriptingModule * | self () |
Returns the only instance of this class. |
Main KTutorial interface for scripts.
It acts mainly as a factory for several KTutorial objects, as they can't be created on the scripts themselves. It also provides access to some KTutorial class methods needed to build tutorials, like findObject(const QString&). Note, however, that ScriptingModule isn't actually a Kross module, but an object exposed in Kross Actions.
The objects created through ScriptingModule can be from fixed classes, using newOption(const QString&) and newStep(const QString&), or from dynamically specified classes using a type name in newWaitFor(const QString&).
In any case, the objects created must be deleted. So if they are not deleted by their parent object (for example, a Step added to a Tutorial will be automatically deleted when the Tutorial is deleted), they must be deleted using QObject::deleteLater() method in the scripts.
New objects of the default KTutorial WaitFor classes can be created with newWaitFor(const QString&) using their name (without any namespace qualifier). Moreover, custom WaitFor classes can be registered with registerWaitForMetaObject(const QMetaObject&, const QString&) and new instances of those classes can be created since that moment, provided they have an invokable public default constructor.
ScriptingModule is a singleton, so all the scripts can use each registered WaitFor type.
Definition at line 66 of file ScriptingModule.h.
QObject * ktutorial::scripting::ScriptingModule::findObject | ( | const QString & | name | ) |
Returns the object with the specified name, if any.
This method can be invoked from a script.
name | The name of the object to find. |
Definition at line 109 of file ScriptingModule.cpp.
References findObject(), and self().
Referenced by findObject().
QObject * ktutorial::scripting::ScriptingModule::newOption | ( | const QString & | name | ) |
Returns a new Option with the given name.
This method can be invoked from a script.
name | The name of the Option. |
Definition at line 113 of file ScriptingModule.cpp.
QObject * ktutorial::scripting::ScriptingModule::newStep | ( | const QString & | id | ) |
Returns a new ScriptedStep with the given id.
This method can be invoked from a script.
id | The id of the ScriptedStep. |
Definition at line 117 of file ScriptingModule.cpp.
QObject * ktutorial::scripting::ScriptingModule::newWaitFor | ( | const QString & | typeName | ) |
Returns a new WaitFor of the given type name.
The type can be any of the default WaitFor included in KTutorial (WaitForSignal, WaitForAnd...) or the name of a custom WaitFor type registered with registerWaitForMetaObject(const QMetaObject&, const QString&). This method can be invoked from a script.
typeName | The type name of the WaitFor. |
Definition at line 121 of file ScriptingModule.cpp.
bool ktutorial::scripting::ScriptingModule::registerWaitForMetaObject | ( | const QMetaObject & | waitForMetaObject, |
const QString & | typeName = QString() |
||
) |
Registers a WaitFor type to create instances of it using newWaitFor(const QString&).
Only WaitFor subclasses that contain an invokable public default constructor can be registered.
When new instances are created with newWaitFor(const QString&), the types are identified by the name used to register them, not their true C++ name. The same type can be registered with several different names if needed (although once a name is used, no other types can be registered with that name). However, if no name is specified, the full name of the class is used (including namespaces and :: separators).
waitForMetaObject | The QMetaObject to create instances of. |
typeName | A specific name to be used for the QMetaObject. |
Definition at line 78 of file ScriptingModule.cpp.
Referenced by self().
ScriptingModule * ktutorial::scripting::ScriptingModule::self | ( | ) | [static] |
Returns the only instance of this class.
Definition at line 47 of file ScriptingModule.cpp.
References registerWaitForMetaObject().
Referenced by findObject(), and ktutorial::scripting::ScriptedTutorial::ScriptedTutorial().