|  | Home · Tutorial · Classes · Functions · Language · QSA Workbench · Qt Documentation · www.trolltech.com |

# QSEditor Class Reference

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

        #include <QSEditor>

- List of all members, including inherited members

### Public Functions

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

### 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 argument is passed to the QWidget constructor. The name argument is used as the widget's object name.

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

See also 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:

c /Comment c /Number c /String c /Type c /Label c /Standard

For each of those, the following settings are read:

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

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

The following settings for indentation are read:

c /indentAutoIndent (bool) - whether auto indentation should be done c /indentTabSize (number) - the tab size for indentation c /indentIndentSize (number) - the indentation width c /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.

See also setScript().

### 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 context ( `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 interpreter(), QSProject::createEditor(), and setScript().

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

Sets the current script of the editor to be script.

See also script().

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

Sets the editor contents to text.

See also text().

### QString QSEditor::text () const

Returns the text of the editor.

See also setText().

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

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

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

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

### void QSEditor::undo ()

Undo the last editor operation.