QSEditor Class

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

# QSEditor Class Reference

The QSEditor class provides an enhanced editor for editing Qt Script source code. More...

`#include <qseditor.h>`

List of all member functions.

## Public Members

- QSEditor ( QWidget * parent, const char * name = 0 )
- ~QSEditor ()
- bool setScript ( QSScript * script )
- QSScript * script () const
- bool setInterpreter ( QSInterpreter * interpreter, QObject * context = 0 )
- QSInterpreter * interpreter () const
- void setText ( const QString & text )
- QString text () const
- bool isModified () const
- void commit ()
- void revert ()
- bool isActive () const
- bool isUndoAvailable () const
- bool isRedoAvailable () const
- void undo ()
- void redo ()
- void cut ()
- void copy ()
- void paste ()
- void selectAll ()
- bool find ( const QString & expr, bool cs, bool wo, bool forward, bool startAtCursor )
- bool replace ( const QString & find, const QString & replace, bool cs, bool wo, bool forward, bool startAtCursor, bool replaceAll )
- void gotoLine ( int line )
- void indent ()
- void readSettings ()
- void setErrorMark ( int line )
- void removeErrorMark ()
- QTextEdit * textEdit () const
- QSProject * project () const

## Signals

- void textChanged ()

## Detailed Description

The QSEditor class provides an enhanced editor for editing Qt Script source code.

For some applications QSA Workbench is too complex and it might be more appropriate to embed a simple editor into the application's user interface. QSEditor provides a type of widget component which offers normal editor functionality as well as Qt Script syntax highlighting, completion, function argument hints, and auto-indentation.

The text in the QSEditor can be set using setText() and retrieved using text().

A QSEditor can be associated with a QSScript object using setScript() and the QSScript can then be retrieved by using script().

When text is edited in the QSEditor, it is not directly reflected in the underlying script. To write the changes from the editor to the script, use commit(). To revert the changes from the editor to the text in the script, use revert().

The QSEditor will automatically become the active editor when it gets the focus. The active editor can be retrieved from QSProject.

Look at the examples/scriptbutton and examples/console examples to see an example of the QSEditor class.

## Member Function Documentation

### QSEditor::QSEditor ( QWidget * parent, const char * name = 0 )

Constructs an editor not linked to any project.

The parent and name arguments are passed to the QWidget constructor.

### QSEditor::~QSEditor ()

Destructs the editor.

### void QSEditor::commit ()

Updates the script with the text in the editor.

When the text in the editor is changed, the changes must be committed before they are reflected in the script.

### void QSEditor::copy ()

Copies the selected text to the clipboard.

### void QSEditor::cut ()

Cuts the selected text to the clipboard.

### bool QSEditor::find ( const QString & expr, bool cs, bool wo, bool forward, bool startAtCursor )

Finds the string expr in the editor and selects the result. If cs is TRUE, the search is case sensitive. If wo is TRUE, only whole words are searched. If forward is TRUE, the search is executed forward, otherwise backwards. If startAtCursor is TRUE, the search starts at the current cursor position, otherwise it starts at the beginning of the document.

Returns TRUE if expr was found, otherwise returns FALSE.

### void QSEditor::gotoLine ( int line )

Moves the cursor to the line line in the editor.

### void QSEditor::indent ()

Indents the current line or selection.

### QSInterpreter * QSEditor::interpreter () const

Returns the interpreter that this editor uses for completion if it has been set; otherwise returns 0.

The interpreter can be set using functions QSProject::createEditor(), setScript() or setInterpreter().

### bool QSEditor::isActive () const

Returns TRUE if the editor is active; otherwise returns FALSE.

See the class description for information on active editors.

### bool QSEditor::isModified () const

Returns TRUE if the text in the editor is different from the text in the underlying script. This is the case whenever the user edited the script and the changes have not been committed or reverted.

### bool QSEditor::isRedoAvailable () const

Returns TRUE if redo is available; otherwise returns FALSE.

### bool QSEditor::isUndoAvailable () const

Returns TRUE if undo is available; otherwise returns FALSE.

### void QSEditor::paste ()

Pastes text from the clipboard into the editor.

### QSProject * QSEditor::project () const

Returns the project the editor is associated with; otherwise returns 0.

### void QSEditor::readSettings ()

Re-reads settings for syntax highlighting, indentation, etc. The settings are read from the QSettings path `/Trolltech/QSAScriptEditor/`.

The following settings are read for syntax highlighting:

- `/Comment`
- `/Number`
- `/String`
- `/Type`
- `/Label`
- `/Standard`

For each of those, the following settings are read:

- `/family` (string)
- `/size` (number)
- `/bold` (bool)
- `/italic` (bool)
- `/underline` (bool)
- `/red` (number)
- `/green` (number)
- `/blue` (number)

The font family for strings is e.g. saved in `/Trolltech/QuickScriptEditor/String/family`.

The following settings for indentation are read:

- `/indentAutoIndent` (bool) - whether auto indentation should be done
- `/indentTabSize` (number) - the tab size for indentation
- `/indentIndentSize` (number) - the indentation width
- `/indentKeepTabs` (bool) - whether to keep tabs or to replace them with spaces

Code completion can be switched on or off via `/completion`. Wordwrapping can be switched on or off via `/wordWrap`. Parentheses matching can be switched on or off via `/parenMatching`.

### void QSEditor::redo ()

Redo the last editor operation.

### void QSEditor::removeErrorMark ()

Removes all the error marks for the editor.

### bool QSEditor::replace ( const QString & find, const QString & replace, bool cs, bool wo, bool forward, bool startAtCursor, bool replaceAll )

Replaces the string find in the editor with replace. If cs is TRUE, the search is case sensitive. If wo is TRUE, only whole words are searched. If forward is TRUE, the search is executed forward, otherwise backwards. If startAtCursor is TRUE, the search starts at the current cursor position, otherwise it starts at the beginning of the document. If replaceAll is TRUE, all found occurrences of find are replaced by replace. Otherwise only the first occurrence is replaced.

### void QSEditor::revert ()

Reverts the contents in the editor back to the contents of the underlying script.

### QSScript * QSEditor::script () const

Returns the script that the editor is editing if any; otherwise returns 0.

### void QSEditor::selectAll ()

Selects all the text in the editor.

### void QSEditor::setErrorMark ( int line )

Highlights the line line. This can be used e.g., to show an error or warning.

### bool QSEditor::setInterpreter ( QSInterpreter * interpreter, QObject * context = 0 )

Sets the interpreter that this editor will do completion for to interpreter with the contetext ( `this` object ) as context

This function is only for use when the editor is used outside a project. If the editor has been associated with a project with the functions QSProject::createEditor() or QSEditor::setScript() this function will not have any effect.

See also QSProject::createEditor() and setScript().

### bool QSEditor::setScript ( QSScript * script )

Sets the current script of the editor to be script.

### void QSEditor::setText ( const QString & text )

Sets the editor contents to text.

### QString QSEditor::text () const

Returns the text of the editor.

### void QSEditor::textChanged ()`[signal]`

This signal is emitted if the text of the editor has been changed

### QTextEdit * QSEditor::textEdit () const

Returns the pointer to the real editor widget which is a QTextEdit. This might be 0 if an error occurred while initializing the editor.

### void QSEditor::undo ()

Undo the last editor operation.

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