• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Kross

  • Kross
  • Action
Public Slots | Signals | Public Member Functions | List of all members
Kross::Action Class Reference

#include <action.h>

Inheritance diagram for Kross::Action:
Inheritance graph
[legend]

Public Slots

void addQObject (QObject *obj, const QString &name=QString())
 
QVariant callFunction (const QString &name, const QVariantList &args=QVariantList())
 
QByteArray code () const
 
QString currentPath () const
 
QString description () const
 
QVariant evaluate (const QByteArray &code)
 
QString file () const
 
QStringList functionNames ()
 
QString iconName () const
 
QString interpreter () const
 
bool isEnabled () const
 
QString name () const
 
QVariant option (const QString &name, const QVariant &defaultvalue=QVariant())
 
QVariantMap options () const
 
QObject * qobject (const QString &name) const
 
QStringList qobjectNames () const
 
void setCode (const QByteArray &code)
 
void setDescription (const QString &description)
 
void setEnabled (bool enabled)
 
bool setFile (const QString &scriptfile)
 
void setIconName (const QString &iconname)
 
void setInterpreter (const QString &interpretername)
 
bool setOption (const QString &name, const QVariant &value)
 
int version () const
 

Signals

void dataChanged (Action *)
 
void finalized (Kross::Action *)
 
void finished (Kross::Action *)
 
void started (Kross::Action *)
 
void updated ()
 

Public Member Functions

 Action (QObject *parent, const QString &name, const QDir &packagepath=QDir())
 
 Action (QObject *parent, const QUrl &url)
 
virtual ~Action ()
 
void finalize ()
 
void fromDomElement (const QDomElement &element)
 
void fromDomElement (const QDomElement &element, const QStringList &searchPath)
 
bool initialize ()
 
bool isFinalized () const
 
Script * script () const
 
QDomElement toDomElement () const
 
QDomElement toDomElement (const QStringList &searchPath) const
 
- Public Member Functions inherited from QAction
 QAction (QObject *parent)
 
 QAction (const QString &text, QObject *parent)
 
 QAction (QObject *parent, const char *name)
 
 QAction (const QString &text, const QKeySequence &shortcut, QObject *parent, const char *name)
 
 QAction (const QIcon &icon, const QString &text, QObject *parent)
 
 QAction (const QIcon &icon, const QString &text, const QKeySequence &shortcut, QObject *parent, const char *name)
 
 ~QAction ()
 
QKeySequence accel () const
 
QActionGroup * actionGroup () const
 
void activate (ActionEvent event)
 
void activated (int i)
 
bool addTo (QWidget *w)
 
QList< QGraphicsWidget * > associatedGraphicsWidgets () const
 
QList< QWidget * > associatedWidgets () const
 
bool autoRepeat () const
 
void changed ()
 
QVariant data () const
 
QFont font () const
 
void hover ()
 
void hovered ()
 
QIcon icon () const
 
QIcon iconSet () const
 
QString iconText () const
 
bool isCheckable () const
 
bool isChecked () const
 
bool isEnabled () const
 
bool isIconVisibleInMenu () const
 
bool isOn () const
 
bool isSeparator () const
 
bool isToggleAction () const
 
bool isVisible () const
 
QMenu * menu () const
 
MenuRole menuRole () const
 
QString menuText () const
 
QWidget * parentWidget () const
 
Priority priority () const
 
bool removeFrom (QWidget *w)
 
void setAccel (const QKeySequence &shortcut)
 
void setActionGroup (QActionGroup *group)
 
void setAutoRepeat (bool)
 
void setCheckable (bool)
 
void setChecked (bool)
 
void setData (const QVariant &userData)
 
void setDisabled (bool b)
 
void setEnabled (bool)
 
void setFont (const QFont &font)
 
void setIcon (const QIcon &icon)
 
void setIconSet (const QIcon &i)
 
void setIconText (const QString &text)
 
void setIconVisibleInMenu (bool visible)
 
void setMenu (QMenu *menu)
 
void setMenuRole (MenuRole menuRole)
 
void setMenuText (const QString &text)
 
void setOn (bool b)
 
void setPriority (Priority priority)
 
void setSeparator (bool b)
 
void setShortcut (const QKeySequence &shortcut)
 
void setShortcutContext (Qt::ShortcutContext context)
 
void setShortcuts (QKeySequence::StandardKey key)
 
void setShortcuts (const QList< QKeySequence > &shortcuts)
 
void setSoftKeyRole (SoftKeyRole softKeyRole)
 
void setStatusTip (const QString &statusTip)
 
void setText (const QString &text)
 
void setToggleAction (bool b)
 
void setToolTip (const QString &tip)
 
void setVisible (bool)
 
void setWhatsThis (const QString &what)
 
QKeySequence shortcut () const
 
Qt::ShortcutContext shortcutContext () const
 
QList< QKeySequence > shortcuts () const
 
bool showStatusText (QWidget *widget)
 
SoftKeyRole softKeyRole () const
 
QString statusTip () const
 
QString text () const
 
void toggle ()
 
void toggled (bool checked)
 
QString toolTip () const
 
void trigger ()
 
void triggered (bool checked)
 
QString whatsThis () const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
 QObject (QObject *parent, const char *name)
 
virtual  ~QObject ()
 
bool blockSignals (bool block)
 
QObject * child (const char *objName, const char *inheritsClass, bool recursiveSearch) const
 
const QObjectList & children () const
 
const char * className () const
 
bool connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const QObject *receiver, const char *method)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method)
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QByteArray > dynamicPropertyNames () const
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
T findChild (const QString &name) const
 
QList< T > findChildren (const QRegExp &regExp) const
 
QList< T > findChildren (const QString &name) const
 
bool inherits (const char *className) const
 
void insertChild (QObject *object)
 
void installEventFilter (QObject *filterObj)
 
bool isA (const char *className) const
 
bool isWidgetType () const
 
void killTimer (int id)
 
virtual const QMetaObject * metaObject () const
 
void moveToThread (QThread *targetThread)
 
const char * name () const
 
const char * name (const char *defaultName) const
 
QString objectName () const
 
QObject * parent () const
 
QVariant property (const char *name) const
 
void removeChild (QObject *object)
 
void removeEventFilter (QObject *obj)
 
void setName (const char *name)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval)
 
QThread * thread () const
 
- Public Member Functions inherited from QScriptable
QScriptValue argument (int index) const
 
int argumentCount () const
 
QScriptContext * context () const
 
QScriptEngine * engine () const
 
QScriptValue thisObject () const
 
- Public Member Functions inherited from Kross::ChildrenInterface
void addObject (QObject *object, const QString &name=QString(), Options options=NoOption)
 
bool hasObject (const QString &name) const
 
QObject * object (const QString &name) const
 
Options objectOption (const QString &name) const
 
QHash< QString, Options > objectOptions () const
 
QHash< QString, QObject * > objects () const
 
- Public Member Functions inherited from Kross::ErrorInterface
 ErrorInterface ()
 
void clearError ()
 
long errorLineNo () const
 
const QString errorMessage () const
 
const QString errorTrace () const
 
bool hadError () const
 
void setError (const QString &errormessage, const QString &tracemessage=QString(), long lineno=-1)
 
void setError (ErrorInterface *error)
 

Additional Inherited Members

- Public Types inherited from Kross::ChildrenInterface
enum  Options { NoOption = 0x00, AutoConnectSignals = 0x01, LastOption = 0x1000000 }
 
- Static Public Member Functions inherited from QObject
bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Protected Member Functions inherited from QAction
virtual bool event (QEvent *e)
 
- Protected Member Functions inherited from QObject
bool checkConnectArgs (const char *signal, const QObject *object, const char *method)
 
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const char *signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const char *signal)
 
int receivers (const char *signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Static Protected Member Functions inherited from QObject
QByteArray normalizeSignalSlot (const char *signalSlot)
 
- Properties inherited from QAction
 autoRepeat
 
 checkable
 
 checked
 
 enabled
 
 font
 
 icon
 
 iconText
 
 iconVisibleInMenu
 
 menuRole
 
 priority
 
 shortcut
 
 shortcutContext
 
 softKeyRole
 
 statusTip
 
 text
 
 toolTip
 
 visible
 
 whatsThis
 
- Properties inherited from QObject
 objectName
 

Detailed Description

The Action class is an abstract container to deal with scripts like a single standalone script file.

Each action holds a reference to the matching Kross::Interpreter created Kross::Script instance.

The Manager takes care of handling the Action instances application by providing access to ActionCollection containers for those Action instances.

Once you've such a Action instance you're able to perform actions with it like executing scripting code.

Following sample shows "Hello World." executed with the python interpreter:

# Create a new Kross::Action instance.
Kross::Action* action = new Kross::Action(0,"MyFirstScript");
# Set the interpreter we like to use. This could be e.g. "python", "ruby" or "kjs".
action->setInterpreter("python");
# Set the scripting code.
action->setCode("print \"Hello World.\"");
# Execute the scripting code.
action->trigger();

Following sample demonstrates how to execute an external python script file. The script file itself is named "mytest.py" and contains:

# this function got called from within C++
def myfunction(args):
print "Arguments are: %s" % args
# Import the published QObject's
import MyFirstQObject, MySecondQObject
# Call a slot MyFirstQObject provides.
MyFirstQObject.someSlot("Some string")
# Set a property MySecondQObject provides.
MySecondQObject.someProperty = "Other string"

Then you are able to load the script file, publish QObject instances and let the script do whatever it likes to do:

# Publish a QObject instance for all Kross::Action instances.
Kross::Manager::self().addObject(myqobject1, "MyFirstQObject")
# Create a new Kross::Action instance.
Kross::Action* action = new Kross::Action(0,"MySecondScript");
# Publish a QObject instance only for the Kross::Action instance.
action->addObject(myqobject2, "MySecondQObject");
# Set the script file we like to execute.
action->setFile("/home/myuser/mytest.py");
# Execute the script file.
action->trigger();
# Call the "myfunction" defined in the "mytest.py" python script.
QVariant result = action->callFunction("myfunction", QVariantList()<<"Arg");

Definition at line 94 of file action.h.

Constructor & Destructor Documentation

Action::Action ( QObject *  parent,
const QString &  name,
const QDir &  packagepath = QDir() 
)

Constructor.

Parameters
parentThe parent QObject this Action is a child of.
nameThe unique name this Action has. It's used e.g. at the Manager to identify the Action. The name is accessible via QObject::objectName .
Deprecated:
since 4.3: pass search path to fromDomElement() and toDomElement()

Definition at line 115 of file action.cpp.

Action::Action ( QObject *  parent,
const QUrl &  url 
)

Constructor.

Parameters
parentThe parent QObject this Action is a child of.
urlThe URL should point to a valid scripting file. This Action will be filled with the content of the file (e.g. the file is read and code should return its content and it's also tried to determine the interpreter ). Remember to use QUrl c'tor explicitly. The name will be set to url.path()

Definition at line 126 of file action.cpp.

Action::~Action ( )
virtual

Destructor.

Definition at line 139 of file action.cpp.

Member Function Documentation

void Action::addQObject ( QObject *  obj,
const QString &  name = QString() 
)
slot

Add a QObject instance to the action.

This instance will be published to scripts.

Definition at line 386 of file action.cpp.

QVariant Action::callFunction ( const QString &  name,
const QVariantList &  args = QVariantList() 
)
slot

Call a function in the script.

Parameters
nameThe name of the function which should be called.
argsThe optional list of arguments.

Definition at line 430 of file action.cpp.

QByteArray Action::code ( ) const
slot
Returns
the scriptcode this Action holds.

Definition at line 318 of file action.cpp.

QString Action::currentPath ( ) const
slot
Returns
the current path the script is running in or an empty string if there is no current path defined.

Definition at line 376 of file action.cpp.

void Kross::Action::dataChanged ( Action *  )
signal

This signal is emitted when the data of the Action is changed.

QString Action::description ( ) const
slot
Returns
the optional description for this Action.

Definition at line 281 of file action.cpp.

QVariant Action::evaluate ( const QByteArray &  code)
slot

Evaluate some scripting code.

Example how this can be used:

Kross::Action* a = new Kross::Action(0, "MyScript");
a->setInterpreter("python");
a->setCode("def myFunc(x): return x");
a->trigger();
int three = a->evaluate("1+2").toInt(); // returns 3
int nine = a->evaluate("myFunc(9)").toInt(); // returns 9
Parameters
codeThe scripting code to evaluate.
Returns
The return value of the evaluation.

Definition at line 439 of file action.cpp.

QString Action::file ( ) const
slot
Returns
the script file that should be executed.

Definition at line 351 of file action.cpp.

void Action::finalize ( )

Finalize the Script instance and frees any cached or still running executions.

Normally there is no need to call this function directly because the Action will take care of calling it if needed.

Definition at line 496 of file action.cpp.

void Kross::Action::finalized ( Kross::Action *  )
signal

This signal is emitted once a script finalized.

void Kross::Action::finished ( Kross::Action *  )
signal

This signal is emitted after the script got executed.

void Action::fromDomElement ( const QDomElement &  element)

Method to read settings from the QDomElement element that contains details about e.g.

the displayed text, the file to execute or the used interpreter.

Todo:
BIC merge

Definition at line 153 of file action.cpp.

void Action::fromDomElement ( const QDomElement &  element,
const QStringList &  searchPath 
)

Method to read settings from the QDomElement element that contains details about e.g.

the displayed text, the file to execute or the used interpreter.

Parameters
searchPathList of directories where to search the script if its path is relative First item is given the highest priority.

Definition at line 158 of file action.cpp.

QStringList Action::functionNames ( )
slot
Returns
the list of functionnames.

Definition at line 421 of file action.cpp.

QString Action::iconName ( ) const
slot

Return the name of the icon.

Definition at line 293 of file action.cpp.

bool Action::initialize ( )

Initialize the Script instance.

Normally there is no need to call this function directly because if will be called internally if needed (e.g. on execute ).

Returns
true if the initialization was successful else false is returned.

Definition at line 448 of file action.cpp.

QString Action::interpreter ( ) const
slot
Returns
the name of the interpreter. Could be for example "python" or "ruby".

Definition at line 333 of file action.cpp.

bool Action::isEnabled ( ) const
slot

Return true if this Action is enabled else false is returned.

Definition at line 306 of file action.cpp.

bool Action::isFinalized ( ) const
Returns
true if the action is finalized, which means the action is currently not running.

Definition at line 504 of file action.cpp.

QString Action::name ( ) const
slot
Returns
the objectName for this Action.

Definition at line 271 of file action.cpp.

QVariant Action::option ( const QString &  name,
const QVariant &  defaultvalue = QVariant() 
)
slot
Returns
the value of the option defined with name . If there doesn't exist an option with such a name, the defaultvalue is returned.

Definition at line 401 of file action.cpp.

QVariantMap Action::options ( ) const
slot
Returns
a map of options this Action defines. The options are returned call-by-ref, so you are able to manipulate them.

Definition at line 381 of file action.cpp.

QObject * Action::qobject ( const QString &  name) const
slot
Returns
the QObject with the object name name .

Definition at line 391 of file action.cpp.

QStringList Action::qobjectNames ( ) const
slot
Returns
a list of QObject object names.

Definition at line 396 of file action.cpp.

Kross::Script * Action::script ( ) const
Returns
the Kross::Script implementation used by the scripting backend. This returns NULL until the action got triggered or if there was an error before that.

Normaly it shouldn't be necessary to deal with the scripting backend depending instance of a Kross::Script implementation since this Action class already decorates all the things needed. It may however be useful to provide additional interpreter dependent functionality.

Definition at line 266 of file action.cpp.

void Action::setCode ( const QByteArray &  code)
slot

Set the scriptcode code this Action should execute.

Definition at line 323 of file action.cpp.

void Action::setDescription ( const QString &  description)
slot

Set the optional description for this Action.

Definition at line 286 of file action.cpp.

void Action::setEnabled ( bool  enabled)
slot

Set the enable state of this Action to enabled .

Definition at line 311 of file action.cpp.

bool Action::setFile ( const QString &  scriptfile)
slot

Set the script file that should be executed.

Definition at line 356 of file action.cpp.

void Action::setIconName ( const QString &  iconname)
slot

Set the name of the icon to iconname .

Definition at line 298 of file action.cpp.

void Action::setInterpreter ( const QString &  interpretername)
slot

Set the name of the interpreter (javascript, python or ruby).

Definition at line 338 of file action.cpp.

bool Action::setOption ( const QString &  name,
const QVariant &  value 
)
slot

Set the Interpreter::Option value.

Definition at line 409 of file action.cpp.

void Kross::Action::started ( Kross::Action *  )
signal

This signal is emitted before the script got executed.

QDomElement Action::toDomElement ( ) const
Returns
a QDomElement that contains the settings like e.g. the displayed text, the file to execute or the used interpreter of this Action instance.

Definition at line 212 of file action.cpp.

QDomElement Action::toDomElement ( const QStringList &  searchPath) const
Returns
a QDomElement that contains the settings like e.g. the displayed text, the file to execute or the used interpreter of this Action instance.
Parameters
searchPathif given, find the closest directory containing the scriptfile and write relative filepath

Definition at line 217 of file action.cpp.

void Kross::Action::updated ( )
signal

This signal is emitted if the content of the Action was changed.

The ActionCollection instances this Action is a child of are connected with this signal to fire up their own updated signal if an Action of them was updated.

int Action::version ( ) const
slot
Returns
the version number this Action has. Per default 0 is returned.

Definition at line 276 of file action.cpp.


The documentation for this class was generated from the following files:
  • action.h
  • action.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:44 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Kross

Skip menu "Kross"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal