KTutorial  0.5.1
Public Member Functions | Static Public Member Functions
ktutorial::scripting::ScriptingModule Class Reference

Main KTutorial interface for scripts. More...

#include <ScriptingModule.h>

List of all members.

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 ScriptingModuleself ()
 Returns the only instance of this class.

Detailed Description

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.


Member Function Documentation

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.

Parameters:
nameThe name of the object to find.
Returns:
The object with the specified name, or null if there is none.
See also:
KTutorial::findObject(const QString&)

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.

Parameters:
nameThe name of the Option.
Returns:
The new Option.
Todo:
Change return type to Option* once all major Kross scripting backends support classes wrapped through WrapperInterface

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.

Parameters:
idThe id of the ScriptedStep.
Returns:
The new ScriptedStep.
Todo:
Change return type to ScriptedStep* once all major Kross scripting backends support classes wrapped through WrapperInterface

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.

Parameters:
typeNameThe type name of the WaitFor.
Returns:
The new WaitFor, or a null pointer if the type name isn't registered.
Todo:
Change return type to WaitFor* once all major Kross scripting backends support classes wrapped through WrapperInterface

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).

Parameters:
waitForMetaObjectThe QMetaObject to create instances of.
typeNameA specific name to be used for the QMetaObject.
Returns:
True if the type was successfully registered, false otherwise.

Definition at line 78 of file ScriptingModule.cpp.

Referenced by self().

Returns the only instance of this class.

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().


The documentation for this class was generated from the following files: