ScriptEdit Class Reference

Editor widget with support for evaluating expressions and executing code. More...

`#include <ScriptEdit.h>`

Inheritance diagram for ScriptEdit:

## Public Slots

void | evaluate ()
void | execute ()
void | executeAll ()
QString | exportASCII (const QString &file=QString::null)
void | exportPDF (const QString &fileName)
QString | importASCII (const QString &file=QString::null)
void | insertFunction (const QString &)
void | insertFunction (QAction *action)
void | print ()
void | print (QPrinter *)
void | replace ()
QString | save ()
void | scriptPrint (const QString &)
void | setContext (QObject *context)
void | setDirPath (const QString &path)
void | showFindDialog (bool replace=false)
void | updateIndentation ()

## Signals

void | activated (ScriptEdit *)
void | dirPathChanged (const QString &path)
void | error (const QString &, const QString &, int)

## Public Member Functions

void | commentSelection ()
void | customEvent (QEvent *)
| Handle changing of scripting environment. More...
void | enableShortcuts ()
bool | error ()
bool | find (const QString &searchString, QTextDocument::FindFlags flags, bool previous=false)
void | findNext ()
void | findPrevious ()
int | lineNumber (int pos) const
| Map cursor positions to line numbers. More...
void | redirectOutputTo (QTextEdit *)
void | rehighlight ()
| ScriptEdit (ScriptingEnv *env, QWidget *parent=0, const char *name=0)
void | setCompleter (QCompleter *c)
void | setFileName (const QString &fn)
void | uncommentSelection ()
| ~ScriptEdit ()
Public Member Functions inherited from scripted
| scripted (ScriptingEnv *env)
void | scriptingChangeEvent (ScriptingChangeEvent *)
ScriptingEnv * | scriptingEnv ()
| ~scripted ()

## Protected Member Functions

virtual void | contextMenuEvent (QContextMenuEvent *e)
void | focusInEvent (QFocusEvent *e)
virtual void | keyPressEvent (QKeyEvent *e)

## Private Slots

void | insertCompletion (const QString &completion)
void | insertErrorMsg (const QString &message)
| Insert an error message from the scripting system at printCursor. More...
void | matchParentheses ()

## Private Member Functions

void | clearErrorHighlighting ()
void | createParenthesisSelection (int pos)
void | highlightErrorLine (int offset)
bool | matchLeftParenthesis (QTextBlock currentBlock, int index, int numRightParentheses)
bool | matchRightParenthesis (QTextBlock currentBlock, int index, int numLeftParentheses)
QString | textUnderCursor () const

## Private Attributes

QAction * | actionEval
QAction * | actionExecute
QAction * | actionExecuteAll
QAction * | actionExport
QAction * | actionFind
QAction * | actionFindNext
QAction * | actionFindPrevious
QAction * | actionImport
QAction * | actionPrint
QAction * | actionReplace
QAction * | actionSave
QCompleter * | d_completer
QString | d_err_message
bool | d_error
| True if we are inside evaluate(), execute() or executeAll() there were errors. More...
QString | d_file_name
QTextBlockFormat | d_fmt_default
| Format used for resetting success/failure markers. More...
SyntaxHighlighter * | d_highlighter
QTextEdit * | d_output_widget
QTextDocument::FindFlags | d_search_flags
QString | d_search_string
QMenu * | functionsMenu
| Submenu of context menu with mathematical functions. More...
Script * | myScript
QTextCursor | printCursor
| Cursor used for output of evaluation results and error messages. More...
QString | scriptsDirPath

## Additional Inherited Members

Protected Attributes inherited from scripted
ScriptingEnv * | scriptEnv

## Detailed Description

Editor widget with support for evaluating expressions and executing code.

# Future Plans

- Display line numbers.
- syntax highlighting, indentation, auto-completion etc. (maybe using QScintilla)

## Constructor & Destructor Documentation

## ScriptEdit()

ScriptEdit::ScriptEdit | ( | ScriptingEnv * | env,
|  | QWidget * | parent = `0`,
|  | const char * | name = `0`
| ) |  |

References actionEval, actionExecute, actionExecuteAll, actionExport, actionFind, actionFindNext, actionFindPrevious, actionImport, actionPrint, actionReplace, actionSave, activated(), d_fmt_default, error(), evaluate(), execute(), executeAll(), exportASCII(), findNext(), findPrevious(), MyParser::functionNamesList(), functionsMenu, importASCII(), insertErrorMsg(), insertFunction(), matchParentheses(), myScript, ScriptingEnv::newScript(), print(), printCursor, rehighlight(), replace(), save(), scripted::scriptEnv, scriptPrint(), scriptsDirPath, setCompleter(), and showFindDialog().

## ~ScriptEdit()

ScriptEdit::~ScriptEdit | ( |  | ) |

References d_completer, and d_highlighter.

## Member Function Documentation

## activated

void ScriptEdit::activated | ( | ScriptEdit * |  | ) |

signal

Referenced by contextMenuEvent(), enableShortcuts(), focusInEvent(), replace(), ScriptEdit(), and setCompleter().

## clearErrorHighlighting()

void ScriptEdit::clearErrorHighlighting | ( |  | ) |

private

References d_fmt_default, and d_output_widget.

Referenced by evaluate(), execute(), executeAll(), and replace().

## commentSelection()

void ScriptEdit::commentSelection | ( |  | ) |

Referenced by ApplicationWindow::commentSelection(), and replace().

## contextMenuEvent()

void ScriptEdit::contextMenuEvent | ( | QContextMenuEvent * | e | ) |

protected virtual

References actionEval, actionExecute, actionExecuteAll, actionExport, actionFind, actionFindNext, actionFindPrevious, actionImport, actionPrint, actionReplace, actionSave, activated(), Note::autoexec(), Script::context(), functionsMenu, ScriptingEnv::mathFunctionDoc(), ScriptingEnv::mathFunctions(), myScript, scripted::scriptEnv, Script::scriptingEnv(), and Note::tabs().

Referenced by replace().

## createParenthesisSelection()

void ScriptEdit::createParenthesisSelection | ( | int | pos | ) |

private

Referenced by matchLeftParenthesis(), matchParentheses(), and matchRightParenthesis().

## customEvent()

void ScriptEdit::customEvent | ( | QEvent * | e | ) |

Handle changing of scripting environment.

References error(), insertErrorMsg(), myScript, ScriptingEnv::newScript(), print(), rehighlight(), scripted::scriptEnv, SCRIPTING_CHANGE_EVENT, scripted::scriptingChangeEvent(), and scriptPrint().

## dirPathChanged

void ScriptEdit::dirPathChanged | ( | const QString & | path | ) |

signal

Referenced by importASCII(), and replace().

## enableShortcuts()

void ScriptEdit::enableShortcuts | ( |  | ) |

References actionEval, actionFind, actionFindNext, actionFindPrevious, actionImport, actionReplace, actionSave, activated(), evaluate(), findNext(), findPrevious(), importASCII(), replace(), save(), and showFindDialog().

Referenced by error(), FunctionDialog::FunctionDialog(), FitDialog::initEditPage(), SurfaceDialog::initFunctionPage(), SurfaceDialog::initParametricSurfacePage(), and IntDialog::IntDialog().

## error() [1/2]

bool ScriptEdit::error | ( |  | ) |

inline

References d_error, enableShortcuts(), evaluate(), execute(), executeAll(), exportASCII(), exportPDF(), importASCII(), insertFunction(), print(), redirectOutputTo(), rehighlight(), save(), setCompleter(), and setFileName().

Referenced by customEvent(), ApplicationWindow::loadScript(), replace(), and ScriptEdit().

## error [2/2]

void ScriptEdit::error | ( | const QString & | ,
|  | const QString & | ,
|  | int |
| ) |  |

signal

## evaluate

void ScriptEdit::evaluate | ( |  | ) |

slot

References clearErrorHighlighting(), Script::code(), d_error, d_fmt_default, Script::eval(), highlightErrorLine(), lineNumber(), myScript, printCursor, Script::scriptingEnv(), Script::setCode(), and Script::setName().

Referenced by enableShortcuts(), error(), Note::evaluate(), and ScriptEdit().

## execute

void ScriptEdit::execute | ( |  | ) |

slot

References clearErrorHighlighting(), d_error, Script::exec(), highlightErrorLine(), lineNumber(), myScript, printCursor, Script::setCode(), and Script::setName().

Referenced by error(), Note::execute(), and ScriptEdit().

## executeAll

void ScriptEdit::executeAll | ( |  | ) |

slot

References clearErrorHighlighting(), d_error, Script::exec(), highlightErrorLine(), myScript, Script::setCode(), and Script::setName().

Referenced by ApplicationWindow::addColumnNameToCompleter(), error(), ScriptWindow::executeAll(), Note::executeAll(), ApplicationWindow::loadScript(), ApplicationWindow::performCustomAction(), and ScriptEdit().

## exportASCII

QString ScriptEdit::exportASCII | ( | const QString & | file = `QString::null` | ) |

slot

References ScriptingEnv::application(), ApplicationWindow::d_confirm_overwrite, ScriptingEnv::fileFilter(), ApplicationWindow::getFileName(), scripted::scriptEnv, scriptsDirPath, and setFileName().

Referenced by error(), Note::exportASCII(), save(), ScriptWindow::saveAs(), and ScriptEdit().

## exportPDF

void ScriptEdit::exportPDF | ( | const QString & | fileName | ) |

slot

Referenced by error(), and Note::exportPDF().

## find()

bool ScriptEdit::find | ( | const QString & | searchString,
|  | QTextDocument::FindFlags | flags,
|  | bool | previous = `false`
| ) |  |

References d_search_flags, and d_search_string.

Referenced by FindReplaceDialog::find(), findNext(), findPrevious(), and replace().

## findNext()

void ScriptEdit::findNext | ( |  | ) |

References d_search_flags, d_search_string, find(), and showFindDialog().

Referenced by enableShortcuts(), ScriptWindow::findNext(), ApplicationWindow::noteFindNext(), replace(), and ScriptEdit().

## findPrevious()

void ScriptEdit::findPrevious | ( |  | ) |

References d_search_flags, d_search_string, find(), and showFindDialog().

Referenced by enableShortcuts(), ScriptWindow::findPrevious(), ApplicationWindow::noteFindPrev(), replace(), and ScriptEdit().

## focusInEvent()

void ScriptEdit::focusInEvent | ( | QFocusEvent * | e | ) |

protected

References activated(), and d_completer.

Referenced by replace().

## highlightErrorLine()

void ScriptEdit::highlightErrorLine | ( | int | offset | ) |

private

References d_err_message, d_error, lineNumber(), and scripted::scriptEnv.

Referenced by evaluate(), execute(), executeAll(), and replace().

## importASCII

QString ScriptEdit::importASCII | ( | const QString & | file = `QString::null` | ) |

slot

References dirPathChanged(), ScriptingEnv::fileFilter(), ApplicationWindow::getFileName(), scripted::scriptEnv, scriptsDirPath, and setFileName().

Referenced by ApplicationWindow::addColumnNameToCompleter(), enableShortcuts(), error(), Note::importASCII(), ApplicationWindow::loadScript(), ScriptWindow::open(), ApplicationWindow::performCustomAction(), and ScriptEdit().

## insertCompletion

void ScriptEdit::insertCompletion | ( | const QString & | completion | ) |

private slot

References ScriptingEnv::application(), d_completer, PythonSyntaxHighlighter::keywordsList(), scripted::scriptEnv, ApplicationWindow::table(), and ApplicationWindow::windowsNameList().

Referenced by setCompleter().

## insertErrorMsg

void ScriptEdit::insertErrorMsg | ( | const QString & | message | ) |

private slot

Insert an error message from the scripting system at printCursor.

After insertion, the text cursor will have the error message selected, allowing the user to delete it and fix the error.

References ScriptingEnv::application(), d_err_message, d_error, printCursor, and scripted::scriptEnv.

Referenced by customEvent(), and ScriptEdit().

## insertFunction [1/2]

void ScriptEdit::insertFunction | ( | const QString & | fname | ) |

slot

Referenced by error(), IntDialog::insertFunction(), ExtractDataDialog::insertFunction(), MatrixValuesDialog::insertFunction(), SetColValuesDialog::insertFunction(), FunctionDialog::insertFunction(), insertFunction(), and ScriptEdit().

## insertFunction [2/2]

void ScriptEdit::insertFunction | ( | QAction * | action | ) |

slot

References insertFunction(), ScriptingEnv::mathFunctions(), and scripted::scriptEnv.

## keyPressEvent()

void ScriptEdit::keyPressEvent | ( | QKeyEvent * | e | ) |

protected virtual

References d_completer, textUnderCursor(), and updateIndentation().

Referenced by replace().

## lineNumber()

int ScriptEdit::lineNumber | ( | int | pos | ) | const

Map cursor positions to line numbers.

Referenced by evaluate(), execute(), highlightErrorLine(), and scriptPrint().

## matchLeftParenthesis()

bool ScriptEdit::matchLeftParenthesis | ( | QTextBlock | currentBlock,
|  | int | index,
|  | int | numRightParentheses
| ) |  |

private

References ParenthesisInfo::character, createParenthesisSelection(), TextBlockData::parentheses(), and ParenthesisInfo::position.

Referenced by matchParentheses().

## matchParentheses

void ScriptEdit::matchParentheses | ( |  | ) |

private slot

References ParenthesisInfo::character, createParenthesisSelection(), matchLeftParenthesis(), matchRightParenthesis(), TextBlockData::parentheses(), and ParenthesisInfo::position.

Referenced by ScriptEdit().

## matchRightParenthesis()

bool ScriptEdit::matchRightParenthesis | ( | QTextBlock | currentBlock,
|  | int | index,
|  | int | numLeftParentheses
| ) |  |

private

References ParenthesisInfo::character, createParenthesisSelection(), TextBlockData::parentheses(), and ParenthesisInfo::position.

Referenced by matchParentheses().

## print [1/2]

void ScriptEdit::print | ( |  | ) |

slot

Referenced by customEvent(), error(), Note::print(), and ScriptEdit().

## print [2/2]

void ScriptEdit::print | ( | QPrinter * | printer | ) |

slot

## redirectOutputTo()

void ScriptEdit::redirectOutputTo | ( | QTextEdit * | te | ) |

References d_output_widget, and printCursor.

Referenced by error(), and ScriptWindow::redirectOutput().

## rehighlight()

void ScriptEdit::rehighlight | ( |  | ) |

References d_highlighter, and scripted::scriptEnv.

Referenced by customEvent(), error(), ConfigDialog::rehighlight(), and ScriptEdit().

## replace

void ScriptEdit::replace | ( |  | ) |

inline slot

References activated(), clearErrorHighlighting(), commentSelection(), contextMenuEvent(), dirPathChanged(), error(), find(), findNext(), findPrevious(), focusInEvent(), highlightErrorLine(), keyPressEvent(), showFindDialog(), and uncommentSelection().

Referenced by enableShortcuts(), ScriptEdit(), and setContext().

## save

QString ScriptEdit::save | ( |  | ) |

slot

References d_file_name, and exportASCII().

Referenced by enableShortcuts(), error(), and ScriptEdit().

## scriptPrint

void ScriptEdit::scriptPrint | ( | const QString & | text | ) |

slot

References lineNumber(), and printCursor.

Referenced by customEvent(), ScriptEdit(), and setContext().

## setCompleter()

void ScriptEdit::setCompleter | ( | QCompleter * | c | ) |

References activated(), d_completer, and insertCompletion().

Referenced by Note::addTab(), ApplicationWindow::enableCompletion(), error(), ScriptEdit(), ExtractDataDialog::setCompleter(), MatrixValuesDialog::setCompleter(), SetColValuesDialog::setCompleter(), and ApplicationWindow::showScriptWindow().

## setContext

void ScriptEdit::setContext | ( | QObject * | context | ) |

inline slot

References myScript, replace(), scriptPrint(), Script::setContext(), setDirPath(), showFindDialog(), and updateIndentation().

Referenced by Note::addTab(), ScriptWindow::ScriptWindow(), MatrixValuesDialog::setMatrix(), ExtractDataDialog::setTable(), and SetColValuesDialog::setTable().

## setDirPath

void ScriptEdit::setDirPath | ( | const QString & | path | ) |

slot

References scriptsDirPath.

Referenced by Note::addTab(), ScriptWindow::ScriptWindow(), setContext(), and Note::setDirPath().

## setFileName()

void ScriptEdit::setFileName | ( | const QString & | fn | ) |

References Script::context(), d_file_name, Note::indexOf(), myScript, and Note::renameTab().

Referenced by error(), exportASCII(), and importASCII().

## showFindDialog

void ScriptEdit::showFindDialog | ( | bool | replace = `false` | ) |

slot

References scripted::scriptingEnv().

Referenced by enableShortcuts(), ScriptWindow::find(), findNext(), findPrevious(), ApplicationWindow::noteFindDialogue(), ApplicationWindow::noteReplaceDialogue(), ScriptWindow::replace(), replace(), ScriptEdit(), and setContext().

## textUnderCursor()

QString ScriptEdit::textUnderCursor | ( |  | ) | const

private

Referenced by keyPressEvent().

## uncommentSelection()

void ScriptEdit::uncommentSelection | ( |  | ) |

Referenced by replace(), and ApplicationWindow::uncommentSelection().

## updateIndentation

void ScriptEdit::updateIndentation | ( |  | ) |

slot

Referenced by keyPressEvent(), and setContext().

## Member Data Documentation

## actionEval

QAction * ScriptEdit::actionEval

private

Referenced by contextMenuEvent(), enableShortcuts(), and ScriptEdit().

## actionExecute

QAction* ScriptEdit::actionExecute

private

Referenced by contextMenuEvent(), and ScriptEdit().

## actionExecuteAll

QAction * ScriptEdit::actionExecuteAll

private

Referenced by contextMenuEvent(), and ScriptEdit().

## actionExport

QAction * ScriptEdit::actionExport

private

Referenced by contextMenuEvent(), and ScriptEdit().

## actionFind

QAction* ScriptEdit::actionFind

private

Referenced by contextMenuEvent(), enableShortcuts(), and ScriptEdit().

## actionFindNext

QAction * ScriptEdit::actionFindNext

private

Referenced by contextMenuEvent(), enableShortcuts(), and ScriptEdit().

## actionFindPrevious

QAction * ScriptEdit::actionFindPrevious

private

Referenced by contextMenuEvent(), enableShortcuts(), and ScriptEdit().

## actionImport

QAction * ScriptEdit::actionImport

private

Referenced by contextMenuEvent(), enableShortcuts(), and ScriptEdit().

## actionPrint

QAction * ScriptEdit::actionPrint

private

Referenced by contextMenuEvent(), and ScriptEdit().

## actionReplace

QAction * ScriptEdit::actionReplace

private

Referenced by contextMenuEvent(), enableShortcuts(), and ScriptEdit().

## actionSave

QAction * ScriptEdit::actionSave

private

Referenced by contextMenuEvent(), enableShortcuts(), and ScriptEdit().

## d_completer

QCompleter* ScriptEdit::d_completer

private

Referenced by focusInEvent(), insertCompletion(), keyPressEvent(), setCompleter(), and ~ScriptEdit().

## d_err_message

QString ScriptEdit::d_err_message

private

Referenced by highlightErrorLine(), and insertErrorMsg().

## d_error

bool ScriptEdit::d_error

private

True if we are inside evaluate(), execute() or executeAll() there were errors.

Referenced by error(), evaluate(), execute(), executeAll(), highlightErrorLine(), and insertErrorMsg().

## d_file_name

QString ScriptEdit::d_file_name

private

Referenced by save(), and setFileName().

## d_fmt_default

QTextBlockFormat ScriptEdit::d_fmt_default

private

Format used for resetting success/failure markers.

Referenced by clearErrorHighlighting(), evaluate(), and ScriptEdit().

## d_highlighter

SyntaxHighlighter* ScriptEdit::d_highlighter

private

Referenced by rehighlight(), and ~ScriptEdit().

## d_output_widget

QTextEdit* ScriptEdit::d_output_widget

private

Referenced by clearErrorHighlighting(), and redirectOutputTo().

## d_search_flags

QTextDocument::FindFlags ScriptEdit::d_search_flags

private

Referenced by find(), findNext(), and findPrevious().

## d_search_string

QString ScriptEdit::d_search_string

private

Referenced by find(), findNext(), and findPrevious().

## functionsMenu

QMenu* ScriptEdit::functionsMenu

private

Submenu of context menu with mathematical functions.

Referenced by contextMenuEvent(), and ScriptEdit().

## myScript

Script* ScriptEdit::myScript

private

Referenced by contextMenuEvent(), customEvent(), evaluate(), execute(), executeAll(), ScriptEdit(), setContext(), and setFileName().

## printCursor

QTextCursor ScriptEdit::printCursor

private

Cursor used for output of evaluation results and error messages.

Referenced by evaluate(), execute(), insertErrorMsg(), redirectOutputTo(), ScriptEdit(), and scriptPrint().

## scriptsDirPath

QString ScriptEdit::scriptsDirPath

private

Referenced by exportASCII(), importASCII(), ScriptEdit(), and setDirPath().

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

- qtiplot/src/scripting/ScriptEdit.h
- qtiplot/src/scripting/ScriptEdit.cpp