ScriptEdit Class Reference

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

`#include <ScriptEdit.h>`

Inheritance diagram for ScriptEdit:

## Public Slots

void | commentSelection ()
void | evaluate ()
void | execute ()
void | executeAll ()
QString | exportASCII (const QString &file=QString::null)
void | exportPDF (const QString &fileName)
bool | find (const QString &searchString, QTextDocument::FindFlags flags, bool previous=false)
void | findNext ()
void | findPrevious ()
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 | uncommentSelection ()
void | updateIndentation ()

## Signals

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

## Public Member Functions

void | customEvent (QEvent *)
| Handle changing of scripting environment. More...
void | enableShortcuts ()
bool | error ()
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)
| ~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 | ( | 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 | ( |  | ) |

References d_completer, and d_highlighter.

## Member Function Documentation

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

signal

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

void ScriptEdit::clearErrorHighlighting | ( |  | ) |

private

References d_fmt_default, and d_output_widget.

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

void ScriptEdit::commentSelection | ( |  | ) |

slot

Referenced by ApplicationWindow::commentSelection().

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

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

private

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

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

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

signal

Referenced by importASCII().

void ScriptEdit::enableShortcuts | ( |  | ) |

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

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

bool ScriptEdit::error | ( |  | ) |

inline

References d_error.

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

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

signal

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(), Note::evaluate(), and ScriptEdit().

void ScriptEdit::execute | ( |  | ) |

slot

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

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

void ScriptEdit::executeAll | ( |  | ) |

slot

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

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

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 Note::exportASCII(), save(), ScriptWindow::saveAs(), and ScriptEdit().

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

slot

Referenced by Note::exportPDF().

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

slot

References d_search_flags, and d_search_string.

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

void ScriptEdit::findNext | ( |  | ) |

slot

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

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

void ScriptEdit::findPrevious | ( |  | ) |

slot

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

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

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

protected

References activated(), and d_completer.

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

private

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

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

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

slot

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

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

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

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

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

slot

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

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

slot

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

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

protected virtual

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

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

Map cursor positions to line numbers.

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

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

private

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

Referenced by matchParentheses().

void ScriptEdit::matchParentheses | ( |  | ) |

private slot

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

Referenced by ScriptEdit().

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

private

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

Referenced by matchParentheses().

void ScriptEdit::print | ( |  | ) |

slot

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

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

slot

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

References d_output_widget, and printCursor.

Referenced by ScriptWindow::redirectOutput().

void ScriptEdit::rehighlight | ( |  | ) |

References d_highlighter, and scripted::scriptEnv.

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

void ScriptEdit::replace | ( |  | ) |

inline slot

References showFindDialog().

Referenced by enableShortcuts(), and ScriptEdit().

QString ScriptEdit::save | ( |  | ) |

slot

References d_file_name, and exportASCII().

Referenced by enableShortcuts(), and ScriptEdit().

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

slot

References lineNumber(), and printCursor.

Referenced by customEvent(), and ScriptEdit().

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

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

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

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

inline slot

References myScript, and Script::setContext().

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

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

slot

References scriptsDirPath.

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

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

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

Referenced by exportASCII(), and importASCII().

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

slot

References scripted::scriptingEnv().

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

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

private

Referenced by keyPressEvent().

void ScriptEdit::uncommentSelection | ( |  | ) |

slot

Referenced by ApplicationWindow::uncommentSelection().

void ScriptEdit::updateIndentation | ( |  | ) |

slot

Referenced by keyPressEvent().

## Member Data Documentation

QAction * ScriptEdit::actionEval

private

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

QAction* ScriptEdit::actionExecute

private

Referenced by contextMenuEvent(), and ScriptEdit().

QAction * ScriptEdit::actionExecuteAll

private

Referenced by contextMenuEvent(), and ScriptEdit().

QAction * ScriptEdit::actionExport

private

Referenced by contextMenuEvent(), and ScriptEdit().

QAction* ScriptEdit::actionFind

private

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

QAction * ScriptEdit::actionFindNext

private

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

QAction * ScriptEdit::actionFindPrevious

private

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

QAction * ScriptEdit::actionImport

private

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

QAction * ScriptEdit::actionPrint

private

Referenced by contextMenuEvent(), and ScriptEdit().

QAction * ScriptEdit::actionReplace

private

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

QAction * ScriptEdit::actionSave

private

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

QCompleter* ScriptEdit::d_completer

private

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

QString ScriptEdit::d_err_message

private

Referenced by highlightErrorLine(), and insertErrorMsg().

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

QString ScriptEdit::d_file_name

private

Referenced by save(), and setFileName().

QTextBlockFormat ScriptEdit::d_fmt_default

private

Format used for resetting success/failure markers.

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

SyntaxHighlighter* ScriptEdit::d_highlighter

private

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

QTextEdit* ScriptEdit::d_output_widget

private

Referenced by clearErrorHighlighting(), and redirectOutputTo().

QTextDocument::FindFlags ScriptEdit::d_search_flags

private

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

QString ScriptEdit::d_search_string

private

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

QMenu* ScriptEdit::functionsMenu

private

Submenu of context menu with mathematical functions.

Referenced by contextMenuEvent(), and ScriptEdit().

Script* ScriptEdit::myScript

private

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

QTextCursor ScriptEdit::printCursor

private

Cursor used for output of evaluation results and error messages.

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

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