Mantid
Loading...
Searching...
No Matches
Classes | Public Slots | Signals | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
ScriptEditor Class Reference

This class provides an area to write scripts. More...

#include <ScriptEditor.h>

Inheritance diagram for ScriptEditor:

Classes

class  SaveCancelledException
 Exception type to indicate that saving was cancelled. More...
 

Public Slots

void markExecutingLineAsError ()
 Mark the progress arrow as an error. More...
 
void padMargin ()
 Ensure the margin width is big enough to hold everything + padding. More...
 
void print ()
 Print the text within the widget. More...
 
void saveAs ()
 Save the script, opening a dialog. More...
 
void saveScript (const QString &filename)
 Save a the text to the given filename. More...
 
void saveToCurrentFile ()
 Save to the current filename, opening a dialog if blank. More...
 
void setMarkerState (bool enabled)
 Set the marker state. More...
 
virtual void showFindReplaceDialog ()
 Raise find replace dialog. More...
 
void updateCompletionAPI (const QStringList &keywords)
 Refresh the autocomplete information base on a new set of keywords. More...
 
void updateProgressMarker (int lineno, bool error=false)
 Update the progress marker. More...
 
void updateProgressMarkerFromThread (int lineno, bool error=false)
 Update the progress marker potentially from a separate thread. More...
 
void zoomTo (int level) override
 Override zoomTo slot. More...
 

Signals

void fileNameChanged (const QString &fileName)
 Notify that the filename has been modified. More...
 
void progressMade (const int progress)
 Progress has been made in script execution. More...
 
void redoAvailable (bool)
 Inform observers that redo information is available. More...
 
void textZoomedIn ()
 Emitted when a zoom in is requested. More...
 
void textZoomedOut ()
 Emitted when a zoom out is requested. More...
 
void undoAvailable (bool)
 Inform observers that undo information is available. More...
 

Public Member Functions

void clearKeyBinding (const QString &keyCombination)
 Clear keyboard shortcut binding. More...
 
void disableAutoCompletion ()
 Disable the auto complete. More...
 
void enableAutoCompletion (AutoCompletionSource source=QsciScintilla::AcsAPIs)
 Enable the auto complete. More...
 
QString fileName () const
 The current filename. More...
 
int getZoom () const
 Get the current zoom factor. More...
 
void keyPressEvent (QKeyEvent *event) override
 Capture key presses. More...
 
void readSettings ()
 Read settings from persistent store. More...
 
void replaceAll (const QString &search, const QString &replace, bool regex, bool caseSensitive, bool matchWords, bool wrap, bool forward=true)
 Replace all occurences of a string. More...
 
QsciAPIs * scintillaAPI () const
 Return a pointer to the object responsible for code completion. More...
 
 ScriptEditor (const QString &lexerName, const QFont &font=QFont(), QWidget *parent=nullptr)
 Construction based on a string defining the langauge used for syntax highlighting. More...
 
 ScriptEditor (QWidget *parent=nullptr, QsciLexer *lexer=nullptr, QString settingsGroup="")
 Constructor. More...
 
void setAutoMarginResize ()
 Make the object resize to margin to fit the contents with padding. More...
 
void setFileName (const QString &filename)
 Set a new file name. More...
 
void setLexer (QsciLexer *) override
 Set a new code lexer for this object. More...
 
void setSettingsGroup (const QString &name)
 Set the name of the group to save the settings for. More...
 
void setText (int lineno, const QString &text, int index=0)
 Set the text on a given line number. More...
 
QString settingsGroup () const
 Settings group. More...
 
QSize sizeHint () const override
 Default size hint. More...
 
void wheelEvent (QWheelEvent *e) override
 Override so that ctrl + mouse wheel will zoom in and out. More...
 
void writeSettings ()
 Write settings from persistent store. More...
 
 ~ScriptEditor () override
 Destructor. More...
 

Protected Member Functions

void dragEnterEvent (QDragEnterEvent *de) override
 Accept a drag enter event and selects whether to accept the action. More...
 
void dragMoveEvent (QDragMoveEvent *de) override
 Accept a drag move event and selects whether to accept the action. More...
 
void dropEvent (QDropEvent *de) override
 Accept a drag drop event and process the data appropriately. More...
 
QByteArray fromMimeData (const QMimeData *source, bool &rectangular) const override
 If the QMimeData object holds workspaces names then extract text from a QMimeData object and add the necessary wrapping text to import mantid. More...
 
virtual void writeToDevice (QIODevice &device) const
 Write to the given device. More...
 

Private Member Functions

void forwardKeyPressToBase (QKeyEvent *event)
 Forward a KeyPress event to QsciScintilla base class. More...
 

Private Attributes

QsciAPIs * m_completer
 A pointer to a QsciAPI object that handles the code completion. More...
 
int m_currentExecLine
 Hold the line number of the currently executing line. More...
 
QString m_filename
 The file name associated with this editor. More...
 
FindReplaceDialogm_findDialog
 A pointer to the find replace dialog. More...
 
int m_previousKey
 previous key More...
 
int m_progressArrowKey
 The margin marker. More...
 
QString m_settingsGroup
 Name of group that the settings are stored under. More...
 

Static Private Attributes

static QColor g_error_colour = QColor("red")
 The colour of the marker for an error state. More...
 
static QColor g_success_colour = QColor("lightgreen")
 The colour of the marker for a success state. More...
 

Detailed Description

This class provides an area to write scripts.

It inherits from QScintilla to use functionality such as auto-indent and if supported, syntax highlighting.

Author
Martyn Gigg, Tessella Support Services plc
Date
19/08/2009

Definition at line 37 of file ScriptEditor.h.

Constructor & Destructor Documentation

◆ ScriptEditor() [1/2]

ScriptEditor::ScriptEditor ( const QString &  lexerName,
const QFont &  font = QFont(),
QWidget *  parent = nullptr 
)

Construction based on a string defining the langauge used for syntax highlighting.

Parameters
lexerNameA string choosing the name of a lexer
fontA reference to the initial font to be used in the editor
parentParent widget

Definition at line 79 of file ScriptEditor.cpp.

◆ ScriptEditor() [2/2]

ScriptEditor::ScriptEditor ( QWidget *  parent = nullptr,
QsciLexer *  codelexer = nullptr,
QString  settingsGroup = "" 
)

Constructor.

Parameters
parentThe parent widget (can be NULL)
codelexerdefine the syntax highlighting and code completion.
settingsGroupUsed when saving settings to persistent store

Definition at line 88 of file ScriptEditor.cpp.

References clearKeyBinding(), readSettings(), redoAvailable(), setLexer(), and undoAvailable().

◆ ~ScriptEditor()

ScriptEditor::~ScriptEditor ( )
override

Destructor.

Definition at line 121 of file ScriptEditor.cpp.

References m_completer.

Member Function Documentation

◆ clearKeyBinding()

void ScriptEditor::clearKeyBinding ( const QString &  keyCombination)

Clear keyboard shortcut binding.

if key identifier bound to a command

Definition at line 329 of file ScriptEditor.cpp.

Referenced by ScriptEditor().

◆ disableAutoCompletion()

void ScriptEditor::disableAutoCompletion ( )

Disable the auto complete.

Definition at line 197 of file ScriptEditor.cpp.

◆ dragEnterEvent()

void ScriptEditor::dragEnterEvent ( QDragEnterEvent *  de)
overrideprotected

Accept a drag enter event and selects whether to accept the action.

Parameters
de:: The drag enter event

Definition at line 466 of file ScriptEditor.cpp.

◆ dragMoveEvent()

void ScriptEditor::dragMoveEvent ( QDragMoveEvent *  de)
overrideprotected

Accept a drag move event and selects whether to accept the action.

Parameters
de:: The drag move event

Definition at line 456 of file ScriptEditor.cpp.

◆ dropEvent()

void ScriptEditor::dropEvent ( QDropEvent *  de)
overrideprotected

Accept a drag drop event and process the data appropriately.

Parameters
de:: The drag drop event

Definition at line 488 of file ScriptEditor.cpp.

◆ enableAutoCompletion()

void ScriptEditor::enableAutoCompletion ( AutoCompletionSource  source = QsciScintilla::AcsAPIs)

Enable the auto complete.

Default is for backwards compatability with existing code

Definition at line 187 of file ScriptEditor.cpp.

◆ fileName()

QString ScriptEditor::fileName ( ) const
inline

The current filename.

Definition at line 88 of file ScriptEditor.h.

Referenced by saveToCurrentFile().

◆ fileNameChanged

void ScriptEditor::fileNameChanged ( const QString &  fileName)
signal

Notify that the filename has been modified.

Referenced by setFileName().

◆ forwardKeyPressToBase()

void ScriptEditor::forwardKeyPressToBase ( QKeyEvent *  event)
private

Forward a KeyPress event to QsciScintilla base class.

Forward the QKeyEvent to the QsciScintilla base class.

Necessary due to bug in QsciScintilla

Under Gnome on Linux with Qscintilla versions < 2.4.2 there is a bug with the autocomplete box that means the editor loses focus as soon as it the box appears. This functions forwards the call and sets the correct flags on the resulting window so that this does not occur

Definition at line 544 of file ScriptEditor.cpp.

Referenced by keyPressEvent().

◆ fromMimeData()

QByteArray ScriptEditor::fromMimeData ( const QMimeData *  source,
bool &  rectangular 
) const
overrideprotected

If the QMimeData object holds workspaces names then extract text from a QMimeData object and add the necessary wrapping text to import mantid.

Parameters
sourceAn existing QMimeData object
rectangularOn return rectangular is set if the text corresponds to a rectangular selection.
Returns
The text

Definition at line 480 of file ScriptEditor.cpp.

◆ getZoom()

int ScriptEditor::getZoom ( ) const

Get the current zoom factor.

Definition at line 614 of file ScriptEditor.cpp.

◆ keyPressEvent()

void ScriptEditor::keyPressEvent ( QKeyEvent *  event)
override

Capture key presses.

Enter/Return executes the code or asks for more input if necessary. Up/Down search the command history

Parameters
eventA pointer to the QKeyPressEvent object

Definition at line 280 of file ScriptEditor.cpp.

References forwardKeyPressToBase(), textZoomedIn(), and textZoomedOut().

◆ markExecutingLineAsError

void ScriptEditor::markExecutingLineAsError ( )
slot

Mark the progress arrow as an error.

Definition at line 412 of file ScriptEditor.cpp.

References m_currentExecLine, and updateProgressMarker().

◆ padMargin

void ScriptEditor::padMargin ( )
slot

Ensure the margin width is big enough to hold everything + padding.

Ensure the margin width is big enough to hold everything.

Definition at line 347 of file ScriptEditor.cpp.

Referenced by setAutoMarginResize().

◆ print

void ScriptEditor::print ( )
slot

Print the text within the widget.

Print the current text.

Definition at line 499 of file ScriptEditor.cpp.

◆ progressMade

void ScriptEditor::progressMade ( const int  progress)
signal

Progress has been made in script execution.

Referenced by updateProgressMarker().

◆ readSettings()

void ScriptEditor::readSettings ( )

Read settings from persistent store.

Read settings saved to persistent store.

Definition at line 145 of file ScriptEditor.cpp.

Referenced by ScriptEditor().

◆ redoAvailable

void ScriptEditor::redoAvailable ( bool  )
signal

Inform observers that redo information is available.

Referenced by ScriptEditor().

◆ replaceAll()

void ScriptEditor::replaceAll ( const QString &  search,
const QString &  replace,
bool  regex,
bool  caseSensitive,
bool  matchWords,
bool  wrap,
bool  forward = true 
)

Replace all occurences of a string.

Definition at line 587 of file ScriptEditor.cpp.

References index.

Referenced by FindReplaceDialog::replaceAll().

◆ saveAs

void ScriptEditor::saveAs ( )
slot

Save the script, opening a dialog.

Save the script, opening a dialog to ask for the filename.

Definition at line 211 of file ScriptEditor.cpp.

References saveScript().

Referenced by saveToCurrentFile().

◆ saveScript

void ScriptEditor::saveScript ( const QString &  filename)
slot

Save a the text to the given filename.

Save the text to the given filename.

Parameters
filename:: The filename to use
Exceptions
std::runtime_errorif the file could not be opened

Definition at line 244 of file ScriptEditor.cpp.

References m_filename, and writeToDevice().

Referenced by saveAs(), and saveToCurrentFile().

◆ saveToCurrentFile

void ScriptEditor::saveToCurrentFile ( )
slot

Save to the current filename, opening a dialog if blank.

Definition at line 229 of file ScriptEditor.cpp.

References fileName(), saveAs(), and saveScript().

◆ scintillaAPI()

QsciAPIs * ScriptEditor::scintillaAPI ( ) const
inline

Return a pointer to the object responsible for code completion.

Definition at line 99 of file ScriptEditor.h.

◆ setAutoMarginResize()

void ScriptEditor::setAutoMarginResize ( )

Make the object resize to margin to fit the contents with padding.

Definition at line 182 of file ScriptEditor.cpp.

References padMargin().

◆ setFileName()

void ScriptEditor::setFileName ( const QString &  filename)

Set a new file name.

Definition at line 304 of file ScriptEditor.cpp.

References fileNameChanged(), and m_filename.

◆ setLexer()

void ScriptEditor::setLexer ( QsciLexer *  codelexer)
override

Set a new code lexer for this object.

Note that this clears all auto complete information

Definition at line 156 of file ScriptEditor.cpp.

References m_completer.

Referenced by ScriptEditor().

◆ setMarkerState

void ScriptEditor::setMarkerState ( bool  enabled)
slot

Set the marker state.

Parameters
enabled:: If true then the progress arrow is enabled

Definition at line 361 of file ScriptEditor.cpp.

References m_progressArrowKey.

◆ setSettingsGroup()

void ScriptEditor::setSettingsGroup ( const QString &  name)

Set the name of the group to save the settings for.

Parameters
nameThe name of the group

Definition at line 133 of file ScriptEditor.cpp.

References m_settingsGroup.

◆ setText()

void ScriptEditor::setText ( int  lineno,
const QString &  txt,
int  index = 0 
)

Set the text on a given line number.

Set the text on the given line, something I feel is missing from the QScintilla API.

Note that like QScintilla line numbers start from 0

Parameters
lineno:: A zero-based index representing the linenumber,
txt:: The text to insert at the given line
index:: The position of text in a line number,default value is zero

Definition at line 265 of file ScriptEditor.cpp.

References index.

◆ settingsGroup()

QString ScriptEditor::settingsGroup ( ) const

Settings group.

Returns a string containing the settings group to use

Returns
A QString containing the group to use within the QSettings class

Definition at line 140 of file ScriptEditor.cpp.

References m_settingsGroup.

◆ showFindReplaceDialog

void ScriptEditor::showFindReplaceDialog ( )
virtualslot

Raise find replace dialog.

Raises the find replace dialog.

Definition at line 513 of file ScriptEditor.cpp.

References m_findDialog.

◆ sizeHint()

QSize ScriptEditor::sizeHint ( ) const
override

Default size hint.

Definition at line 206 of file ScriptEditor.cpp.

◆ textZoomedIn

void ScriptEditor::textZoomedIn ( )
signal

Emitted when a zoom in is requested.

Referenced by keyPressEvent(), and wheelEvent().

◆ textZoomedOut

void ScriptEditor::textZoomedOut ( )
signal

Emitted when a zoom out is requested.

Referenced by keyPressEvent(), and wheelEvent().

◆ undoAvailable

void ScriptEditor::undoAvailable ( bool  )
signal

Inform observers that undo information is available.

Referenced by ScriptEditor().

◆ updateCompletionAPI

void ScriptEditor::updateCompletionAPI ( const QStringList &  keywords)
slot

Refresh the autocomplete information base on a new set of keywords.

Update the completion API with a new list of keywords.

Note that the old is cleared

2012-08-14 M. Gigg: QScintilla v2.6.1 contains a bug surrounding the calltips. If the entire list of completions is exhausted then the underlying API keeps on trying to iterate further due to a bug in the stopping condition. It sorts the keyword list so that it can quickly jump to a starting point when trying to match what the user has typed with the completions it has. A short cut out is when it first checks that the current completion starts with the users' text and if not the loop is halted correctly.

This line adds a single character that is guaranteed to be after all of the other completions (due to ascii ordering) but is not alpha-numeric so a user would not want to complete on it. Even better it won't show up in the auto complete list because a user has to type at least 2 characters for that to appear.

Definition at line 418 of file ScriptEditor.cpp.

References m_completer.

◆ updateProgressMarker

void ScriptEditor::updateProgressMarker ( int  lineno,
bool  error = false 
)
slot

Update the progress marker.

Update the arrow marker to point to the correct line and colour it depending on the error state.

Parameters
lineno:: The line to place the marker at. A negative number will clear all markers
error:: If true, the marker will turn red

Definition at line 393 of file ScriptEditor.cpp.

References error, g_error_colour, g_success_colour, m_currentExecLine, m_progressArrowKey, and progressMade().

Referenced by markExecutingLineAsError(), and updateProgressMarkerFromThread().

◆ updateProgressMarkerFromThread

void ScriptEditor::updateProgressMarkerFromThread ( int  lineno,
bool  error = false 
)
slot

Update the progress marker potentially from a separate thread.

Update the arrow marker to point to the correct line and colour it depending on the error state.

If the call is from a thread other than the application thread then the call is reperformed on that thread

Parameters
lineno:: The line to place the marker at. A negative number will clear all markers
error:: If true, the marker will turn red

Definition at line 378 of file ScriptEditor.cpp.

References error, and updateProgressMarker().

◆ wheelEvent()

void ScriptEditor::wheelEvent ( QWheelEvent *  e)
override

Override so that ctrl + mouse wheel will zoom in and out.

Ctrl + Rotating the mouse wheel will increase/decrease the font size.

Definition at line 312 of file ScriptEditor.cpp.

References textZoomedIn(), and textZoomedOut().

◆ writeSettings()

void ScriptEditor::writeSettings ( )

Write settings from persistent store.

Read settings saved to persistent store.

Definition at line 150 of file ScriptEditor.cpp.

◆ writeToDevice()

void ScriptEditor::writeToDevice ( QIODevice &  device) const
protectedvirtual

Write to the given device.

Definition at line 531 of file ScriptEditor.cpp.

Referenced by saveScript().

◆ zoomTo

void ScriptEditor::zoomTo ( int  level)
overrideslot

Override zoomTo slot.

Override the zoomTo slot to make the font size larger on Mac as the defaults are tiny.

Parameters
levelSet the font size to this level of zoom

Definition at line 520 of file ScriptEditor.cpp.

Member Data Documentation

◆ g_error_colour

QColor ScriptEditor::g_error_colour = QColor("red")
staticprivate

The colour of the marker for an error state.

Definition at line 178 of file ScriptEditor.h.

Referenced by updateProgressMarker().

◆ g_success_colour

QColor ScriptEditor::g_success_colour = QColor("lightgreen")
staticprivate

The colour of the marker for a success state.

Definition at line 176 of file ScriptEditor.h.

Referenced by updateProgressMarker().

◆ m_completer

QsciAPIs* ScriptEditor::m_completer
private

A pointer to a QsciAPI object that handles the code completion.

Definition at line 174 of file ScriptEditor.h.

Referenced by setLexer(), updateCompletionAPI(), and ~ScriptEditor().

◆ m_currentExecLine

int ScriptEditor::m_currentExecLine
private

Hold the line number of the currently executing line.

Definition at line 172 of file ScriptEditor.h.

Referenced by markExecutingLineAsError(), and updateProgressMarker().

◆ m_filename

QString ScriptEditor::m_filename
private

The file name associated with this editor.

Definition at line 167 of file ScriptEditor.h.

Referenced by saveScript(), and setFileName().

◆ m_findDialog

FindReplaceDialog* ScriptEditor::m_findDialog
private

A pointer to the find replace dialog.

Definition at line 182 of file ScriptEditor.h.

Referenced by showFindReplaceDialog().

◆ m_previousKey

int ScriptEditor::m_previousKey
private

previous key

Definition at line 180 of file ScriptEditor.h.

◆ m_progressArrowKey

int ScriptEditor::m_progressArrowKey
private

The margin marker.

Definition at line 170 of file ScriptEditor.h.

Referenced by setMarkerState(), and updateProgressMarker().

◆ m_settingsGroup

QString ScriptEditor::m_settingsGroup
private

Name of group that the settings are stored under.

Definition at line 184 of file ScriptEditor.h.

Referenced by setSettingsGroup(), and settingsGroup().


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