|Home | Tutorial | Classes | Functions | QSA Developer | Language | Library | Qt API | QSA Articles Qt Script for Applications

QSProject Class Reference

The QSProject class provides control over a script project for the Qt Application Script interpreter. More...

#include <qsproject.h>

List of all member functions.

Public Members

Public Slots


Detailed Description

The QSProject class provides control over a script project for the Qt Application Script interpreter.

Qt Script for Applications (QSA) collects sets of functions and classes together in projects. Use open() to access a project, either from a file or from a byte array. If a file is used, QSA will automatically take care of saving user changes. The project's data can be retrieved into a byte array using projectData(). One project is current at any one time; close the current project with clear().

The contents of the current project are available using forms() and classes() which return a list of all the forms and classes respectively.

A new global function can be added with addFunction(); this function can also invoke Qt Scripter if required. Qt Scripter is invoked with openIDE() and closed with closeIDE().

If Qt Scripter is too complex for your application (even with the GUI builder functionality and/or the debugger switched off), you can use QSEditor to create a source code editor for Qt Script (with syntax highlighting, completion, auto indentation, etc), which can be embedded into your application user interface.

See the Manual for more explanation and examples.


Member Type Documentation

QSProject::IDEFlags

The IDEFlags describe in which mode Qt Scripter is opened.


Member Function Documentation

QSEditor * QSProject::activeEditor () const

Returns the editor which is currently editing the project, or 0 if no editor if active for that project.

void QSProject::addForm ( const QString & fileName ) [slot]

Loads the form fileName and adds it to the project.

See also removeForm().

bool QSProject::addFunction ( const QString & functionName, const QString & functionBody = QString::null, bool open = TRUE ) [slot]

A function called functionName is added to the current project. The name must match the regular expression /^[A-Za-z_][A-Za-z_0-9]*$/.

The code for the function can be passed in the functionBody parameter. If open is TRUE (the default), then QSA Developer will be invoked so that the user can edit this function. If functionBody was specified its text will appear in the editor; if the functionBody is empty a new empty function will be created. If the function functionName already exists in the project and open is TRUE, Qt Scripter will be invoked showing the already existing function in the editor (and any functionBody will be discarded).

This function returns TRUE on success (i.e. the functionName was valid); otherwise returns FALSE.

If there is no project currently open this function does nothing.

void QSProject::addSource ( const QString & code, const QString & fileName, bool append = FALSE ) [slot]

Adds the code code under the name fileName to the project as global code

If there has been added code already under the name fileName, code is appended to this code if append is TRUE, otherwise the currently set code is replaced with code.

See also removeSource().

void QSProject::closeIDE () [slot]

Closes Qt Scripter, if it is currently open.

If there is no project currently open this function does nothing.

This function clears the interpreter, so code which has been passed into previous evaluate() calls will be lost.

QPtrList<QSEditor> * QSProject::editors () const

Returns all editors which work on this project.

QString QSProject::formSource ( const QString & formName ) const

Returns the code for the form called formName

See also forms() and formUi().

QString QSProject::formUi ( const QString & formName ) const

Returns the XML GUI description of the form called formName

See also forms() and formSource().

QStringList QSProject::forms () const

Returns all names of the forms of the project.

See also formSource() and formUi().

QSInterpreter * QSProject::interpreter () const

Returns the interpreter which is used to evaluate code of this project.

bool QSProject::isOpened () const

Returns whether this project is opened.

QDateTime QSProject::lastModified () const

Returns when this project was last modified.

QString QSProject::objectSource ( QObject * object ) const [slot]

Returns the code of the object object

void QSProject::open ( const QString & scriptProject ) [slot]

Opens and parses the Qt Script for Applications script contained in the file, scriptProject. This overload of open() takes care of saving the project to the specified filename automatically. If an error occurs while running or parsing the script, actions according to the errorMode() are taken and the signal error() is emitted.

After open() is called, functions, classes and forms defined in this project can be called and used using evaluate() and call().

If the project has signal/slot connections (for example, a form that connects widget signals to Qt Script slots), then these connections are established as part of the open() process.

The project always stops when Qt Scripter is opened, and continues when Qt Scripter is closed.

void QSProject::open ( const QByteArray & projectData, const QString & projectName ) [slot]

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Reads and parses the Qt Script for Applications script from the projectData QByteArray. projectName must be specified.

If an error occurs while running or parsing the script, the error() signal is emitted, and further action may occur depending on the errorMode().

After open() is called, functions, classes and forms defined in this project can be called and used inside call() and evaluate() calls.

If the project has signal/slot connections (for example, a form that connects widget signals to Qt Script slots), then these connections are established as part of the open() process.

The project always stops when the Qt Scripter is invoked, and continues when the Qt Scripter is closed.

void QSProject::openIDE ( int flags = FullIDE ) [slot]

Opens Qt Scripter with the current scripting project (if there is one open), so that the project can be edited and debugged.

flags is a value which can contains values of DeveloperFlags or'd together.

If there is no project currently open this function does nothing.

This function clears the interpreter, so code which has been passed into previous evaluate() calls will be lost.

If you created QSEditors, the Qt Scripter is always opened with read only editors, even if EditableEditor is part of flags, so that the Qt Scripter can be used for debugging, but not editing.

QByteArray QSProject::projectData () const

Returns the whole project as a data block (QByteArray).

This is useful for keeping the project data with a document. For example, you could take the data returned by this function and store it in a document's file. Later, when the document was opened, you could extract this data from the document and pass it to the overload of open() that takes a QByteArray to reconstruct the project.

QString QSProject::projectName () const

Returns the name of the project.

void QSProject::removeForm ( const QString & fileName ) [slot]

Removes the form which was added under the filename fileName.

See also addForm().

void QSProject::removeSource ( const QString & fileName ) [slot]

Removes the code which was added under the filename fileName.

See also addSource().

void QSProject::reset () [slot]

Normally this function doesn't need to be called, since it is called automatically by the relevant functions (e.g. open(), call(), execute(), etc.). This function is useful in the case where an error has occurred and the script must be run again to reestablish the signal/slot connections between Qt and the script.

QStringList QSProject::scriptFiles () const

Returns a list for all files in this project

void QSProject::setInterpreter ( QSInterpreter * inter )

Sets inter to be the interpreter of this project.

void QSProject::setObjectSource ( QObject * object, const QString & code, bool append = FALSE ) [slot]

Adds the script code code in the context of object. object must have been available to the scripting language via addObject() before.

If there has been set code already for that object object, code is appended to this code if append is TRUE, otherwise the currently set code is replaced with code.

QString QSProject::source ( const QString & fileName ) const

Returns the source of the file fileName in this project

This file is part of Qt Script for Applications, copyright © 2001-2003 Trolltech. All Rights Reserved.


Copyright © 2001-2003 TrolltechTrademarks
QSA version 1.0.0-beta2