QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
|
A text editor based on QScintilla2. More...
#include <qgscodeeditor.h>
Public Types | |
enum class | Flag : int { CodeFolding = 1 << 0 } |
Flags controlling behavior of code editor. More... | |
enum class | MarginRole : int { LineNumbers = 0 , ErrorIndicators = 1 , FoldingControls = 2 } |
Margin roles. More... | |
enum class | Mode { ScriptEditor , OutputDisplay , CommandInput } |
Code editor modes. More... | |
Public Slots | |
void | clearPersistentHistory () |
Clears the entire persistent history of commands run in the editor. More... | |
void | clearSessionHistory () |
Clears the history of commands run in the current session. More... | |
virtual void | moveCursorToEnd () |
Moves the cursor to the end of the document and scrolls to ensure it is visible. More... | |
virtual void | moveCursorToStart () |
Moves the cursor to the start of the document and scrolls to ensure it is visible. More... | |
void | removeHistoryCommand (int index) |
Removes the command at the specified index from the history of the code editor. More... | |
void | runCommand (const QString &command) |
Runs a command in the editor. More... | |
void | showHistory () |
Shows the command history dialog. More... | |
void | showNextCommand () |
Shows the next command from the session in the editor. More... | |
void | showPreviousCommand () |
Shows the previous command from the session in the editor. More... | |
bool | writeHistoryFile () |
Stores the commands executed in the editor to the persistent history file. More... | |
Signals | |
void | persistentHistoryCleared () |
Emitted when the persistent history of commands run in the editor is cleared. More... | |
void | sessionHistoryCleared () |
Emitted when the history of commands run in the current session is cleared. More... | |
Public Member Functions | |
QgsCodeEditor (QWidget *parent=nullptr, const QString &title=QString(), bool folding=false, bool margin=false, QgsCodeEditor::Flags flags=QgsCodeEditor::Flags(), QgsCodeEditor::Mode mode=QgsCodeEditor::Mode::ScriptEditor) | |
Flags controlling behavior of code editor. More... | |
void | addWarning (int lineNumber, const QString &warning) |
Adds a warning message and indicator to the specified a lineNumber. More... | |
void | clearWarnings () |
Clears all warning messages from the editor. More... | |
bool | foldingVisible () |
Returns true if the folding controls are visible in the editor. More... | |
QStringList | history () const |
Returns the list of commands previously executed in the editor. More... | |
void | insertText (const QString &text) |
Insert text at cursor position, or replace any selected text if user has made a selection. More... | |
QgsCodeInterpreter * | interpreter () const |
Returns the attached code interpreter, or nullptr if not set. More... | |
bool | isCursorOnLastLine () const |
Returns true if the cursor is on the last line of the document. More... | |
virtual Qgis::ScriptLanguage | language () const |
Returns the associated scripting language. More... | |
bool | lineNumbersVisible () const |
Returns whether line numbers are visible in the editor. More... | |
Q_DECL_DEPRECATED bool | marginVisible () |
Returns whether margins are in a visible state. More... | |
QgsCodeEditor::Mode | mode () const |
Returns the code editor mode. More... | |
void | setCustomAppearance (const QString &scheme=QString(), const QMap< QgsCodeEditorColorScheme::ColorRole, QColor > &customColors=QMap< QgsCodeEditorColorScheme::ColorRole, QColor >(), const QString &fontFamily=QString(), int fontSize=0) |
Sets a custom appearance for the widget, disconnecting it from using the standard appearance taken from QSettings. More... | |
void | setFoldingVisible (bool folding) |
Set whether the folding controls are visible in the editor. More... | |
void | setHistoryFilePath (const QString &path) |
Sets the file path to use for recording and retrieving previously executed commands. More... | |
void | setInterpreter (QgsCodeInterpreter *newInterpreter) |
Sets an attached code interpreter for executing commands when the editor is in the QgsCodeEditor::Mode::CommandInput mode. More... | |
void | setLineNumbersVisible (bool visible) |
Sets whether line numbers should be visible in the editor. More... | |
Q_DECL_DEPRECATED void | setMarginVisible (bool margin) |
Set margin visible state. More... | |
void | setTitle (const QString &title) |
Set the widget title. More... | |
Static Public Member Functions | |
static QColor | color (QgsCodeEditorColorScheme::ColorRole role) |
Returns the color to use in the editor for the specified role. More... | |
static QColor | defaultColor (QgsCodeEditorColorScheme::ColorRole role, const QString &theme=QString()) |
Returns the default color for the specified role. More... | |
static QFont | getMonospaceFont () |
Returns the monospaced font to use for code editors. More... | |
static QString | languageToString (Qgis::ScriptLanguage language) |
Returns a user-friendly, translated name of the specified script language. More... | |
static void | setColor (QgsCodeEditorColorScheme::ColorRole role, const QColor &color) |
Sets the color to use in the editor for the specified role. More... | |
Protected Member Functions | |
void | contextMenuEvent (QContextMenuEvent *event) override |
void | focusOutEvent (QFocusEvent *event) override |
virtual void | initializeLexer () |
Called when the dialect specific code lexer needs to be initialized (or reinitialized). More... | |
void | keyPressEvent (QKeyEvent *event) override |
QColor | lexerColor (QgsCodeEditorColorScheme::ColorRole role) const |
Returns the color to use in the lexer for the specified role. More... | |
QFont | lexerFont () const |
Returns the font to use in the lexer. More... | |
virtual void | populateContextMenu (QMenu *menu) |
Called when the context menu for the widget is about to be shown, after it has been fully populated with the standard actions created by the base class. More... | |
void | runPostLexerConfigurationTasks () |
Performs tasks which must be run after a lexer has been set for the widget. More... | |
void | updatePrompt () |
Triggers an update of the interactive prompt part of the editor. More... | |
void | updateSoftHistory () |
Updates the soft history by storing the current editor text in the history. More... | |
Static Protected Member Functions | |
static bool | isFixedPitch (const QFont &font) |
Returns true if a font is a fixed pitch font. More... | |
A text editor based on QScintilla2.
Definition at line 92 of file qgscodeeditor.h.
|
strong |
Flags controlling behavior of code editor.
Enumerator | |
---|---|
CodeFolding | Indicates that code folding should be enabled for the editor. |
Definition at line 131 of file qgscodeeditor.h.
|
strong |
Margin roles.
This enum contains the roles which the different numbered margins are used for.
Enumerator | |
---|---|
LineNumbers | Line numbers. |
ErrorIndicators | Error indicators. |
FoldingControls | Folding controls. |
Definition at line 118 of file qgscodeeditor.h.
|
strong |
Code editor modes.
Enumerator | |
---|---|
ScriptEditor | Standard mode, allows for display and edit of entire scripts. |
OutputDisplay | Read only mode for display of command outputs. |
CommandInput | Command input mode. |
Definition at line 103 of file qgscodeeditor.h.
QgsCodeEditor::QgsCodeEditor | ( | QWidget * | parent = nullptr , |
const QString & | title = QString() , |
||
bool | folding = false , |
||
bool | margin = false , |
||
QgsCodeEditor::Flags | flags = QgsCodeEditor::Flags() , |
||
QgsCodeEditor::Mode | mode = QgsCodeEditor::Mode::ScriptEditor |
||
) |
Flags controlling behavior of code editor.
parent | The parent QWidget |
title | The title to show in the code editor dialog |
folding | false: Enable folding for code editor (deprecated, use flags instead) |
margin | false: Enable margin for code editor (deprecated) |
flags | flags controlling behavior of code editor (since QGIS 3.28) |
mode | code editor mode (since QGIS 3.30) |
Definition at line 75 of file qgscodeeditor.cpp.
void QgsCodeEditor::addWarning | ( | int | lineNumber, |
const QString & | warning | ||
) |
Adds a warning message and indicator to the specified a lineNumber.
Definition at line 831 of file qgscodeeditor.cpp.
|
slot |
Clears the entire persistent history of commands run in the editor.
Definition at line 590 of file qgscodeeditor.cpp.
|
slot |
Clears the history of commands run in the current session.
Definition at line 581 of file qgscodeeditor.cpp.
void QgsCodeEditor::clearWarnings | ( | ) |
Clears all warning messages from the editor.
Definition at line 846 of file qgscodeeditor.cpp.
|
static |
Returns the color to use in the editor for the specified role.
This color will be the default theme color for the role, unless the user has manually selected a custom color scheme for the editor.
Definition at line 752 of file qgscodeeditor.cpp.
|
overrideprotected |
Definition at line 215 of file qgscodeeditor.cpp.
|
static |
Returns the default color for the specified role.
The optional theme argument can be used to specify a color theme. A blank theme indicates the default color scheme.
Available themes are stored in QgsCodeEditorColorSchemeRegistry, and can be retrieved via QgsGui::codeEditorColorSchemeRegistry().
Definition at line 683 of file qgscodeeditor.cpp.
|
overrideprotected |
Definition at line 141 of file qgscodeeditor.cpp.
bool QgsCodeEditor::foldingVisible | ( | ) |
Returns true
if the folding controls are visible in the editor.
Definition at line 464 of file qgscodeeditor.cpp.
|
static |
Returns the monospaced font to use for code editors.
Definition at line 786 of file qgscodeeditor.cpp.
QStringList QgsCodeEditor::history | ( | ) | const |
Returns the list of commands previously executed in the editor.
Definition at line 565 of file qgscodeeditor.cpp.
|
protectedvirtual |
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
The default implementation does nothing.
Reimplemented in QgsCodeEditorCSS, QgsCodeEditorExpression, QgsCodeEditorHTML, QgsCodeEditorJavascript, QgsCodeEditorJson, QgsCodeEditorPython, QgsCodeEditorR, and QgsCodeEditorSQL.
Definition at line 243 of file qgscodeeditor.cpp.
void QgsCodeEditor::insertText | ( | const QString & | text | ) |
Insert text at cursor position, or replace any selected text if user has made a selection.
text | The text to be inserted |
Definition at line 667 of file qgscodeeditor.cpp.
QgsCodeInterpreter * QgsCodeEditor::interpreter | ( | ) | const |
Returns the attached code interpreter, or nullptr
if not set.
Definition at line 554 of file qgscodeeditor.cpp.
bool QgsCodeEditor::isCursorOnLastLine | ( | ) | const |
Returns true
if the cursor is on the last line of the document.
Definition at line 857 of file qgscodeeditor.cpp.
|
staticprotected |
Returns true
if a font is a fixed pitch font.
Definition at line 781 of file qgscodeeditor.cpp.
|
overrideprotected |
Definition at line 171 of file qgscodeeditor.cpp.
|
virtual |
Returns the associated scripting language.
Reimplemented in QgsCodeEditorCSS, QgsCodeEditorExpression, QgsCodeEditorHTML, QgsCodeEditorJavascript, QgsCodeEditorJson, QgsCodeEditorPython, QgsCodeEditorR, and QgsCodeEditorSQL.
Definition at line 375 of file qgscodeeditor.cpp.
|
static |
Returns a user-friendly, translated name of the specified script language.
Definition at line 380 of file qgscodeeditor.cpp.
|
protected |
Returns the color to use in the lexer for the specified role.
Definition at line 248 of file qgscodeeditor.cpp.
|
protected |
Returns the font to use in the lexer.
Definition at line 264 of file qgscodeeditor.cpp.
bool QgsCodeEditor::lineNumbersVisible | ( | ) | const |
Returns whether line numbers are visible in the editor.
Definition at line 446 of file qgscodeeditor.cpp.
|
inline |
Returns whether margins are in a visible state.
Definition at line 189 of file qgscodeeditor.h.
|
inline |
|
virtualslot |
Moves the cursor to the end of the document and scrolls to ensure it is visible.
Definition at line 881 of file qgscodeeditor.cpp.
|
virtualslot |
Moves the cursor to the start of the document and scrolls to ensure it is visible.
Definition at line 871 of file qgscodeeditor.cpp.
|
signal |
Emitted when the persistent history of commands run in the editor is cleared.
|
protectedvirtual |
Called when the context menu for the widget is about to be shown, after it has been fully populated with the standard actions created by the base class.
This method provides an opportunity for subclasses to add additional non-standard actions to the context menu.
Definition at line 540 of file qgscodeeditor.cpp.
|
slot |
Removes the command at the specified index from the history of the code editor.
Definition at line 654 of file qgscodeeditor.cpp.
|
slot |
Runs a command in the editor.
An interpreter() must be set.
Definition at line 570 of file qgscodeeditor.cpp.
|
protected |
Performs tasks which must be run after a lexer has been set for the widget.
Definition at line 297 of file qgscodeeditor.cpp.
|
signal |
Emitted when the history of commands run in the current session is cleared.
|
static |
Sets the color to use in the editor for the specified role.
This color will be stored as the new default color for the role, to be used for all code editors.
Set color to an invalid QColor in order to clear the stored color value and reset it to the default color.
Definition at line 767 of file qgscodeeditor.cpp.
void QgsCodeEditor::setCustomAppearance | ( | const QString & | scheme = QString() , |
const QMap< QgsCodeEditorColorScheme::ColorRole, QColor > & | customColors = QMap< QgsCodeEditorColorScheme::ColorRole, QColor >() , |
||
const QString & | fontFamily = QString() , |
||
int | fontSize = 0 |
||
) |
Sets a custom appearance for the widget, disconnecting it from using the standard appearance taken from QSettings.
Definition at line 818 of file qgscodeeditor.cpp.
void QgsCodeEditor::setFoldingVisible | ( | bool | folding | ) |
Set whether the folding controls are visible in the editor.
Definition at line 451 of file qgscodeeditor.cpp.
void QgsCodeEditor::setHistoryFilePath | ( | const QString & | path | ) |
Sets the file path to use for recording and retrieving previously executed commands.
Definition at line 865 of file qgscodeeditor.cpp.
void QgsCodeEditor::setInterpreter | ( | QgsCodeInterpreter * | newInterpreter | ) |
Sets an attached code interpreter for executing commands when the editor is in the QgsCodeEditor::Mode::CommandInput mode.
Definition at line 559 of file qgscodeeditor.cpp.
void QgsCodeEditor::setLineNumbersVisible | ( | bool | visible | ) |
Sets whether line numbers should be visible in the editor.
Defaults to false
.
Definition at line 427 of file qgscodeeditor.cpp.
void QgsCodeEditor::setMarginVisible | ( | bool | margin | ) |
Set margin visible state.
margin | Set margin in the editor |
Definition at line 406 of file qgscodeeditor.cpp.
void QgsCodeEditor::setTitle | ( | const QString & | title | ) |
Set the widget title.
title | widget title |
Definition at line 370 of file qgscodeeditor.cpp.
|
slot |
Shows the command history dialog.
Definition at line 645 of file qgscodeeditor.cpp.
|
slot |
Shows the next command from the session in the editor.
Definition at line 635 of file qgscodeeditor.cpp.
|
slot |
Shows the previous command from the session in the editor.
Definition at line 625 of file qgscodeeditor.cpp.
|
protected |
Triggers an update of the interactive prompt part of the editor.
Definition at line 545 of file qgscodeeditor.cpp.
|
protected |
Updates the soft history by storing the current editor text in the history.
Definition at line 518 of file qgscodeeditor.cpp.
|
slot |
Stores the commands executed in the editor to the persistent history file.
Definition at line 603 of file qgscodeeditor.cpp.