QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
Public Slots | Public Member Functions | Protected Slots | Protected Member Functions | List of all members
QgsCodeEditorPython Class Reference

A Python editor based on QScintilla2. More...

#include <qgscodeeditorpython.h>

Inheritance diagram for QgsCodeEditorPython:
Inheritance graph
[legend]

Public Slots

void searchSelectedTextInPyQGISDocs ()
 Searches the selected text in the official PyQGIS online documentation. More...
 
void toggleComment () override
 Toggle comment for the selected text. More...
 
- Public Slots inherited from QgsCodeEditor
virtual bool checkSyntax ()
 Applies syntax checking to the editor. More...
 
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 reformatCode ()
 Applies code reformatting to the editor. 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, bool skipHistory=false)
 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...
 
virtual void toggleComment ()
 Toggle comment for the selected text. More...
 
bool writeHistoryFile ()
 Stores the commands executed in the editor to the persistent history file. More...
 

Public Member Functions

PRIVATE QgsCodeEditorPython (QWidget *parent=nullptr, const QList< QString > &filenames=QList< QString >(), QgsCodeEditor::Mode mode=QgsCodeEditor::Mode::ScriptEditor, QgsCodeEditor::Flags flags=QgsCodeEditor::Flag::CodeFolding)
 Construct a new Python editor. More...
 
QString characterAfterCursor () const
 Returns the character after the cursor, or an empty string if the cursor is set at end. More...
 
QString characterBeforeCursor () const
 Returns the character before the cursor, or an empty string if cursor is set at start. More...
 
bool checkSyntax () override
 Applies syntax checking to the editor. More...
 
bool isCursorInsideStringLiteralOrComment () const
 Check whether the current cursor position is inside a string literal or a comment. More...
 
Qgis::ScriptLanguage language () const override
 Returns the associated scripting language. More...
 
Qgis::ScriptLanguageCapabilities languageCapabilities () const override
 Returns the associated scripting language capabilities. More...
 
void loadAPIs (const QList< QString > &filenames)
 Load APIs from one or more files. More...
 
bool loadScript (const QString &script)
 Loads a script file. More...
 
void updateCapabilities ()
 Updates the editor capabilities. More...
 
- Public Member Functions inherited from 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)
 Construct a new 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...
 
QgsCodeInterpreterinterpreter () 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...
 
virtual Qgis::ScriptLanguageCapabilities languageCapabilities () const
 Returns the associated scripting language capabilities. More...
 
int linearPosition () const
 Convenience function to return the cursor position as a linear index. 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...
 
int selectionEnd () const
 Convenience function to return the end of the selection as a linear index Contrary to the getSelection method, this method returns the cursor position if no selection is made. More...
 
int selectionStart () const
 Convenience function to return the start of the selection as a linear index Contrary to the getSelection method, this method returns the cursor position if no selection is made. 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 setLinearPosition (int position)
 Convenience function to set the cursor position as a linear index. More...
 
void setLinearSelection (int start, int end)
 Convenience function to set the selection using linear indexes. 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...
 

Protected Slots

void autoComplete ()
 Triggers the autocompletion popup. More...
 

Protected Member Functions

void initializeLexer () override
 Called when the dialect specific code lexer needs to be initialized (or reinitialized). More...
 
virtual void keyPressEvent (QKeyEvent *event) override
 
void populateContextMenu (QMenu *menu) override
 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...
 
QString reformatCodeString (const QString &string) override
 Applies code reformatting to a string and returns the result. More...
 
- Protected Member Functions inherited from QgsCodeEditor
void contextMenuEvent (QContextMenuEvent *event) override
 
bool eventFilter (QObject *watched, QEvent *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...
 
virtual QString reformatCodeString (const QString &string)
 Applies code reformatting to a string and returns the result. More...
 
void runPostLexerConfigurationTasks ()
 Performs tasks which must be run after a lexer has been set for the widget. More...
 
virtual void showMessage (const QString &title, const QString &message, Qgis::MessageLevel level)
 Shows a user facing message (eg a warning message). 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...
 

Additional Inherited Members

- Public Types inherited from QgsCodeEditor
enum class  Flag : int { CodeFolding = 1 << 0 , ImmediatelyUpdateHistory = 1 << 1 }
 Flags controlling behavior of code editor. More...
 
typedef QFlags< FlagFlags
 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...
 
- Signals inherited from QgsCodeEditor
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...
 
- Static Public Member Functions inherited from QgsCodeEditor
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...
 
- Static Public Attributes inherited from QgsCodeEditor
static QgsSettingsTreeNodesTreeCodeEditor = QgsSettingsTree::sTreeGui->createChildNode( QStringLiteral( "code-editor" ) )
 
- Static Protected Member Functions inherited from QgsCodeEditor
static bool isFixedPitch (const QFont &font)
 Returns true if a font is a fixed pitch font. More...
 

Detailed Description

A Python editor based on QScintilla2.

Adds syntax highlighting and code autocompletion.

Note
may not be available in Python bindings, depending on platform support

Definition at line 50 of file qgscodeeditorpython.h.

Constructor & Destructor Documentation

◆ QgsCodeEditorPython()

PRIVATE QgsCodeEditorPython::QgsCodeEditorPython ( QWidget *  parent = nullptr,
const QList< QString > &  filenames = QList<QString>(),
QgsCodeEditor::Mode  mode = QgsCodeEditor::Mode::ScriptEditor,
QgsCodeEditor::Flags  flags = QgsCodeEditor::Flag::CodeFolding 
)

Construct a new Python editor.

Parameters
parentThe parent QWidget
filenamesThe list of apis files to load for the Python lexer
modecode editor mode (since QGIS 3.30)
flagscode editor flags (since QGIS 3.32)

Definition at line 56 of file qgscodeeditorpython.cpp.

Member Function Documentation

◆ autoComplete

void QgsCodeEditorPython::autoComplete ( )
protectedslot

Triggers the autocompletion popup.

Since
QGIS 3.16

Definition at line 536 of file qgscodeeditorpython.cpp.

◆ characterAfterCursor()

QString QgsCodeEditorPython::characterAfterCursor ( ) const

Returns the character after the cursor, or an empty string if the cursor is set at end.

Since
QGIS 3.30

Definition at line 630 of file qgscodeeditorpython.cpp.

◆ characterBeforeCursor()

QString QgsCodeEditorPython::characterBeforeCursor ( ) const

Returns the character before the cursor, or an empty string if cursor is set at start.

Since
QGIS 3.30

Definition at line 620 of file qgscodeeditorpython.cpp.

◆ checkSyntax()

bool QgsCodeEditorPython::checkSyntax ( )
overridevirtual

Applies syntax checking to the editor.

This is only supported for editors which return the Qgis::ScriptLanguageCapability::CheckSyntax capability from languageCapabilities().

Since
QGIS 3.32

Reimplemented from QgsCodeEditor.

Definition at line 655 of file qgscodeeditorpython.cpp.

◆ initializeLexer()

void QgsCodeEditorPython::initializeLexer ( )
overrideprotectedvirtual

Called when the dialect specific code lexer needs to be initialized (or reinitialized).

The default implementation does nothing.

Since
QGIS 3.16

Reimplemented from QgsCodeEditor.

Definition at line 87 of file qgscodeeditorpython.cpp.

◆ isCursorInsideStringLiteralOrComment()

bool QgsCodeEditorPython::isCursorInsideStringLiteralOrComment ( ) const

Check whether the current cursor position is inside a string literal or a comment.

Since
QGIS 3.30

Definition at line 585 of file qgscodeeditorpython.cpp.

◆ keyPressEvent()

void QgsCodeEditorPython::keyPressEvent ( QKeyEvent *  event)
overrideprotectedvirtual

Definition at line 219 of file qgscodeeditorpython.cpp.

◆ language()

Qgis::ScriptLanguage QgsCodeEditorPython::language ( ) const
overridevirtual

Returns the associated scripting language.

Since
QGIS 3.30

Reimplemented from QgsCodeEditor.

Definition at line 77 of file qgscodeeditorpython.cpp.

◆ languageCapabilities()

Qgis::ScriptLanguageCapabilities QgsCodeEditorPython::languageCapabilities ( ) const
overridevirtual

Returns the associated scripting language capabilities.

Since
QGIS 3.32

Reimplemented from QgsCodeEditor.

Definition at line 82 of file qgscodeeditorpython.cpp.

◆ loadAPIs()

void QgsCodeEditorPython::loadAPIs ( const QList< QString > &  filenames)

Load APIs from one or more files.

Parameters
filenamesThe list of apis files to load for the Python lexer

Definition at line 557 of file qgscodeeditorpython.cpp.

◆ loadScript()

bool QgsCodeEditorPython::loadScript ( const QString &  script)

Loads a script file.

Definition at line 564 of file qgscodeeditorpython.cpp.

◆ populateContextMenu()

void QgsCodeEditorPython::populateContextMenu ( QMenu *  menu)
overrideprotectedvirtual

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.

Since
QGIS 3.30

Reimplemented from QgsCodeEditor.

Definition at line 521 of file qgscodeeditorpython.cpp.

◆ reformatCodeString()

QString QgsCodeEditorPython::reformatCodeString ( const QString &  string)
overrideprotectedvirtual

Applies code reformatting to a string and returns the result.

This is only supported for editors which return the Qgis::ScriptLanguageCapability::Reformat capability from languageCapabilities().

Since
QGIS 3.32

Reimplemented from QgsCodeEditor.

Definition at line 365 of file qgscodeeditorpython.cpp.

◆ searchSelectedTextInPyQGISDocs

void QgsCodeEditorPython::searchSelectedTextInPyQGISDocs ( )
slot

Searches the selected text in the official PyQGIS online documentation.

Since
QGIS 3.16

Definition at line 713 of file qgscodeeditorpython.cpp.

◆ toggleComment

void QgsCodeEditorPython::toggleComment ( )
overrideslot

Toggle comment for the selected text.

Since
QGIS 3.30

Definition at line 724 of file qgscodeeditorpython.cpp.

◆ updateCapabilities()

void QgsCodeEditorPython::updateCapabilities ( )

Updates the editor capabilities.

Since
QGIS 3.32

Definition at line 640 of file qgscodeeditorpython.cpp.


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