QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QgsCodeEditor Class Reference

A text editor based on QScintilla2. More...

#include <qgscodeeditor.h>

Inheritance diagram for QgsCodeEditor:
Inheritance graph
[legend]

Public Types

enum  MarginRole { LineNumbers = 0, ErrorIndicators = 1, FoldingControls = 2 }
 Margin roles. More...
 

Public Member Functions

 QgsCodeEditor (QWidget *parent=nullptr, const QString &title=QString(), bool folding=false, bool margin=false)
 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...
 
void insertText (const QString &text)
 Insert text at cursor position, or replace any selected text if user has made a selection. 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...
 
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 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 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 focusOutEvent (QFocusEvent *event) override
 
virtual void initializeLexer ()
 Called when the dialect specific code lexer needs to be initialized (or reinitialized). More...
 
bool isFixedPitch (const QFont &font)
 
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...
 
void runPostLexerConfigurationTasks ()
 Performs tasks which must be run after a lexer has been set for the widget. More...
 

Detailed Description

A text editor based on QScintilla2.

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

Definition at line 41 of file qgscodeeditor.h.

Member Enumeration Documentation

◆ MarginRole

Margin roles.

This enum contains the roles which the different numbered margins are used for.

Since
QGIS 3.16
Enumerator
LineNumbers 

Line numbers.

ErrorIndicators 

Error indicators.

FoldingControls 

Folding controls.

Definition at line 54 of file qgscodeeditor.h.

Constructor & Destructor Documentation

◆ QgsCodeEditor()

QgsCodeEditor::QgsCodeEditor ( QWidget *  parent = nullptr,
const QString &  title = QString(),
bool  folding = false,
bool  margin = false 
)

Construct a new code editor.

Parameters
parentThe parent QWidget
titleThe title to show in the code editor dialog
foldingfalse: Enable folding for code editor
marginfalse: Enable margin for code editor (deprecated)
Since
QGIS 2.6

Definition at line 72 of file qgscodeeditor.cpp.

Member Function Documentation

◆ addWarning()

void QgsCodeEditor::addWarning ( int  lineNumber,
const QString &  warning 
)

Adds a warning message and indicator to the specified a lineNumber.

See also
clearWarnings()
Since
QGIS 3.16

Definition at line 490 of file qgscodeeditor.cpp.

◆ clearWarnings()

void QgsCodeEditor::clearWarnings ( )

Clears all warning messages from the editor.

See also
addWarning()
Since
QGIS 3.16

Definition at line 505 of file qgscodeeditor.cpp.

◆ color()

QColor QgsCodeEditor::color ( QgsCodeEditorColorScheme::ColorRole  role)
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.

See also
setColor()
Since
QGIS 3.16

Definition at line 411 of file qgscodeeditor.cpp.

◆ defaultColor()

QColor QgsCodeEditor::defaultColor ( QgsCodeEditorColorScheme::ColorRole  role,
const QString &  theme = QString() 
)
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().

Since
QGIS 3.16

Definition at line 342 of file qgscodeeditor.cpp.

◆ focusOutEvent()

void QgsCodeEditor::focusOutEvent ( QFocusEvent *  event)
overrideprotected

Definition at line 106 of file qgscodeeditor.cpp.

◆ foldingVisible()

bool QgsCodeEditor::foldingVisible ( )
inline

Returns true if the folding controls are visible in the editor.

See also
setFoldingVisible()

Definition at line 119 of file qgscodeeditor.h.

◆ getMonospaceFont()

QFont QgsCodeEditor::getMonospaceFont ( )
static

Returns the monospaced font to use for code editors.

Since
QGIS 3.16

Definition at line 445 of file qgscodeeditor.cpp.

◆ initializeLexer()

void QgsCodeEditor::initializeLexer ( )
protectedvirtual

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

The default implementation does nothing.

Since
QGIS 3.16

Reimplemented in QgsCodeEditorSQL, QgsCodeEditorPython, QgsCodeEditorJavascript, QgsCodeEditorHTML, QgsCodeEditorExpression, and QgsCodeEditorCSS.

Definition at line 149 of file qgscodeeditor.cpp.

◆ insertText()

void QgsCodeEditor::insertText ( const QString &  text)

Insert text at cursor position, or replace any selected text if user has made a selection.

Parameters
textThe text to be inserted

Definition at line 326 of file qgscodeeditor.cpp.

◆ isFixedPitch()

bool QgsCodeEditor::isFixedPitch ( const QFont &  font)
protected

Definition at line 440 of file qgscodeeditor.cpp.

◆ keyPressEvent()

void QgsCodeEditor::keyPressEvent ( QKeyEvent *  event)
overrideprotected

Definition at line 136 of file qgscodeeditor.cpp.

◆ lexerColor()

QColor QgsCodeEditor::lexerColor ( QgsCodeEditorColorScheme::ColorRole  role) const
protected

Returns the color to use in the lexer for the specified role.

Since
QGIS 3.16

Definition at line 154 of file qgscodeeditor.cpp.

◆ lexerFont()

QFont QgsCodeEditor::lexerFont ( ) const
protected

Returns the font to use in the lexer.

Since
QGIS 3.16

Definition at line 170 of file qgscodeeditor.cpp.

◆ lineNumbersVisible()

bool QgsCodeEditor::lineNumbersVisible ( ) const

Returns whether line numbers are visible in the editor.

See also
setLineNumbersVisible()
Since
QGIS 3.16

Definition at line 304 of file qgscodeeditor.cpp.

◆ marginVisible()

Q_DECL_DEPRECATED bool QgsCodeEditor::marginVisible ( )
inline

Returns whether margins are in a visible state.

Deprecated:
Use base class methods for individual margins instead, or lineNumbersVisible()

Definition at line 89 of file qgscodeeditor.h.

◆ runPostLexerConfigurationTasks()

void QgsCodeEditor::runPostLexerConfigurationTasks ( )
protected

Performs tasks which must be run after a lexer has been set for the widget.

Since
QGIS 3.16

Definition at line 203 of file qgscodeeditor.cpp.

◆ setColor()

void QgsCodeEditor::setColor ( QgsCodeEditorColorScheme::ColorRole  role,
const QColor &  color 
)
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.

See also
color()
Since
QGIS 3.16

Definition at line 426 of file qgscodeeditor.cpp.

◆ setCustomAppearance()

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.

Note
Not available in Python bindings
Since
QGIS 3.16

Definition at line 477 of file qgscodeeditor.cpp.

◆ setFoldingVisible()

void QgsCodeEditor::setFoldingVisible ( bool  folding)

Set whether the folding controls are visible in the editor.

See also
foldingVisible()

Definition at line 309 of file qgscodeeditor.cpp.

◆ setLineNumbersVisible()

void QgsCodeEditor::setLineNumbersVisible ( bool  visible)

Sets whether line numbers should be visible in the editor.

Defaults to false.

See also
lineNumbersVisible()
Since
QGIS 3.16

Definition at line 285 of file qgscodeeditor.cpp.

◆ setMarginVisible()

void QgsCodeEditor::setMarginVisible ( bool  margin)

Set margin visible state.

Parameters
marginSet margin in the editor
Deprecated:
Use base class methods for individual margins instead, or setLineNumbersVisible()

Definition at line 264 of file qgscodeeditor.cpp.

◆ setTitle()

void QgsCodeEditor::setTitle ( const QString &  title)

Set the widget title.

Parameters
titlewidget title

Definition at line 259 of file qgscodeeditor.cpp.


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