30#include <QFontDatabase>
33#include <Qsci/qscistyle.h>
38#include "Qsci/qscilexer.h"
40QMap< QgsCodeEditorColorScheme::ColorRole, QString > QgsCodeEditor::sColorRoleToSettingsKey
81 : QsciScintilla( parent )
82 , mWidgetTitle( title )
87 if ( !parent && mWidgetTitle.isEmpty() )
89 setWindowTitle( QStringLiteral(
"Text Editor" ) );
93 setWindowTitle( mWidgetTitle );
99 mSoftHistory.append( QString() );
102 setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
104 SendScintilla( SCI_SETADDITIONALSELECTIONTYPING, 1 );
105 SendScintilla( SCI_SETMULTIPASTE, 1 );
106 SendScintilla( SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION );
111 setAnnotationDisplay( QsciScintilla::AnnotationBoxed );
127 SendScintilla( QsciScintilla::SCI_SETHSCROLLBAR, 0 );
129 setWrapMode( QsciScintilla::WrapCharacter );
136 SendScintilla( QsciScintilla::SCI_SETHSCROLLBAR, 0 );
138 setWrapMode( QsciScintilla::WrapCharacter );
139 SendScintilla( QsciScintilla::SCI_EMPTYUNDOBUFFER );
144#if QSCINTILLA_VERSION < 0x020d03
145 installEventFilter(
this );
152#if QSCINTILLA_VERSION >= 0x020800 && QSCINTILLA_VERSION < 0x020900
153 if ( event->reason() != Qt::ActiveWindowFocusReason )
167 QFocusEvent newFocusEvent( QEvent::FocusOut, Qt::ActiveWindowFocusReason );
168 QsciScintilla::focusOutEvent( &newFocusEvent );
173 QsciScintilla::focusOutEvent( event );
182 if ( isListActive() )
184 QsciScintilla::keyPressEvent( event );
188 if ( event->key() == Qt::Key_Escape )
191 QWidget::keyPressEvent( event );
197 switch ( event->key() )
220 const bool ctrlModifier =
event->modifiers() & Qt::ControlModifier;
221 const bool altModifier =
event->modifiers() & Qt::AltModifier;
225 if ( !isReadOnly() && canReformat && ctrlModifier && altModifier && event->key() == Qt::Key_F )
234 if ( !isReadOnly() && canToggle && ctrlModifier && event->key() == Qt::Key_Colon )
241 QsciScintilla::keyPressEvent( event );
244 if ( !event->isAutoRepeat() )
257 QMenu *menu = createStandardContextMenu();
258 menu->setAttribute( Qt::WA_DeleteOnClose );
263 menu->addSeparator();
268 QAction *reformatAction =
new QAction( tr(
"Reformat Code" ), menu );
269 reformatAction->setShortcut( QStringLiteral(
"Ctrl+Alt+F" ) );
271 reformatAction->setEnabled( !isReadOnly() );
273 menu->addAction( reformatAction );
278 QAction *syntaxCheckAction =
new QAction( tr(
"Check Syntax" ), menu );
281 menu->addAction( syntaxCheckAction );
286 QAction *toggleCommentAction =
new QAction( tr(
"Toggle Comment" ), menu );
287 toggleCommentAction->setShortcut( QStringLiteral(
"Ctrl+:" ) );
289 toggleCommentAction->setEnabled( !isReadOnly() );
291 menu->addAction( toggleCommentAction );
296 menu->exec( mapToGlobal( event->pos() ) );
302 QMenu *menu =
new QMenu(
this );
303 QMenu *historySubMenu =
new QMenu( tr(
"Command History" ), menu );
309 menu->addMenu( historySubMenu );
310 menu->addSeparator();
312 QAction *copyAction = menu->addAction(
QgsApplication::getThemeIcon(
"mActionEditCopy.svg" ), tr(
"Copy" ),
this, &QgsCodeEditor::copy, QKeySequence::Copy );
313 QAction *pasteAction = menu->addAction(
QgsApplication::getThemeIcon(
"mActionEditPaste.svg" ), tr(
"Paste" ),
this, &QgsCodeEditor::paste, QKeySequence::Paste );
314 copyAction->setEnabled( hasSelectedText() );
315 pasteAction->setEnabled( !QApplication::clipboard()->text().isEmpty() );
319 menu->exec( mapToGlobal( event->pos() ) );
324 QsciScintilla::contextMenuEvent( event );
331#if QSCINTILLA_VERSION < 0x020d03
332 if ( watched ==
this && event->type() == QEvent::InputMethod )
341 return QsciScintilla::eventFilter( watched, event );
351 if ( mUseDefaultSettings )
352 return color( role );
354 if ( !mOverrideColors )
360 const QColor
color = mCustomColors.value( role );
367 if ( mUseDefaultSettings )
370 QFont font = QFontDatabase::systemFont( QFontDatabase::FixedFont );
373 if ( !mFontFamily.isEmpty() )
378 font.setPointSize( mFontSize );
382 font.setPointSize( QLabel().font().pointSize() );
386 font.setPointSize( mFontSize );
389 const int fontSize = settings.
value( QStringLiteral(
"qgis/stylesheet/fontPointSize" ), 10 ).toInt();
390 font.setPointSize( fontSize );
393 font.setBold(
false );
420 setCaretLineVisible(
false );
423 setMarginLineNumbers( 1,
true );
424 setMarginWidth( 1,
"00000" );
425 setMarginType( 1, QsciScintilla::MarginType::TextMarginRightJustified );
427 setEdgeMode( QsciScintilla::EdgeNone );
431void QgsCodeEditor::setSciWidget()
437 setCaretLineVisible(
true );
443 setBraceMatching( QsciScintilla::SloppyBraceMatch );
450 setFolding( QsciScintilla::NoFoldStyle );
462 setFoldMarginColors( foldColor, foldColor );
464 setAutoIndent(
true );
465 setIndentationWidth( 4 );
466 setTabIndents(
true );
467 setBackspaceUnindents(
true );
470 setAutoCompletionThreshold( 2 );
471 setAutoCompletionSource( QsciScintilla::AcsAPIs );
479 setWindowTitle( title );
499 return tr(
"Expression" );
503 return tr(
"JavaScript" );
507 return tr(
"Python" );
513 return tr(
"Batch" );
528 marginFont.setPointSize( 10 );
529 setMarginLineNumbers( 0,
true );
530 setMarginsFont( marginFont );
548 marginFont.setPointSize( 10 );
550 setMarginsFont( marginFont );
585void QgsCodeEditor::updateFolding()
592 setFolding( QsciScintilla::PlainFoldStyle );
596 setFolding( QsciScintilla::NoFoldStyle );
601bool QgsCodeEditor::readHistoryFile()
603 if ( mHistoryFilePath.isEmpty() || !QFile::exists( mHistoryFilePath ) )
606 QFile file( mHistoryFilePath );
607 if ( file.open( QIODevice::ReadOnly ) )
609 QTextStream stream( &file );
610#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
612 stream.setCodec(
"UTF-8" );
615 while ( !stream.atEnd() )
617 line = stream.readLine();
618 mHistory.append( line );
627void QgsCodeEditor::syncSoftHistory()
629 mSoftHistory = mHistory;
630 mSoftHistory.append( QString() );
631 mSoftHistoryIndex = mSoftHistory.length() - 1;
636 mSoftHistory[mSoftHistoryIndex] = text();
639void QgsCodeEditor::updateHistory(
const QStringList &commands,
bool skipSoftHistory )
641 if ( commands.size() > 1 )
643 mHistory.append( commands );
645 else if ( !commands.value( 0 ).isEmpty() )
647 const QString command = commands.value( 0 );
648 if ( mHistory.empty() || command != mHistory.constLast() )
649 mHistory.append( command );
652 if ( !skipSoftHistory )
673 QMessageBox::information(
this, title, message );
677 QMessageBox::warning(
this, title, message );
681 QMessageBox::critical(
this, title, message );
691 SendScintilla( QsciScintilla::SCI_MARGINSETTEXT,
static_cast< uintptr_t
>( 0 ), prompt.toUtf8().constData() );
702 mInterpreter = newInterpreter;
709 const int index = std::min( source.length(), target.length() );
715 int refDistanceMore = d0;
716 int refIndexMore = index;
717 if ( index < source.length() - 1 )
722 if ( newDistance <= refDistanceMore )
724 refDistanceMore = newDistance;
726 if ( refIndexMore == source.length() - 1 )
736 int refDistanceLess = d0;
737 int refIndexLess = index;
743 if ( newDistance <= refDistanceLess )
745 refDistanceLess = newDistance;
747 if ( refIndexLess == 0 )
757 if ( refDistanceMore < refDistanceLess )
769 const QString originalText = text();
772 if ( originalText == newText )
776 const int oldScrollValue = verticalScrollBar()->value();
781 removeSelectedText();
784 verticalScrollBar()->setValue( oldScrollValue );
807 updateHistory( { command } );
813 mInterpreter->
exec( command );
832 if ( !mHistoryFilePath.isEmpty() && QFile::exists( mHistoryFilePath ) )
834 QFile file( mHistoryFilePath );
835 file.open( QFile::WriteOnly | QFile::Truncate );
843 if ( mHistoryFilePath.isEmpty() )
846 QFile f( mHistoryFilePath );
847 if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
852 QTextStream ts( &f );
853#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
854 ts.setCodec(
"UTF-8" );
856 for (
const QString &command : std::as_const( mHistory ) )
858 ts << command +
'\n';
865 if ( mSoftHistoryIndex < mSoftHistory.length() - 1 && !mSoftHistory.isEmpty() )
867 mSoftHistoryIndex += 1;
868 setText( mSoftHistory[mSoftHistoryIndex] );
875 if ( mSoftHistoryIndex > 0 && !mSoftHistory.empty() )
877 mSoftHistoryIndex -= 1;
878 setText( mSoftHistory[mSoftHistoryIndex] );
886 dialog->setAttribute( Qt::WA_DeleteOnClose );
889 dialog->activateWindow();
895 mHistory.removeAt( index );
896 mSoftHistory.removeAt( index );
897 if ( index < mSoftHistoryIndex )
899 mSoftHistoryIndex -= 1;
900 if ( mSoftHistoryIndex < 0 )
901 mSoftHistoryIndex = mSoftHistory.length() - 1;
908 if ( hasSelectedText() )
910 replaceSelectedText( text );
915 getCursorPosition( &line, &index );
916 insertAt( text, line, index );
917 setCursorPosition( line, index + text.length() );
926 const QPalette
pal = qApp->palette();
931 return pal.color( QPalette::Highlight );
933 return pal.color( QPalette::HighlightedText );
938 else if ( theme.isEmpty() )
943 static const QMap< QgsCodeEditorColorScheme::ColorRole, QString > sColorRoleToIniKey
988 return scheme.
color( role );
994 if ( !settings.
value( QStringLiteral(
"codeEditor/overrideColors" ),
false,
QgsSettings::Gui ).toBool() )
996 const QString theme = settings.
value( QStringLiteral(
"codeEditor/colorScheme" ), QString(),
QgsSettings::Gui ).toString();
1001 const QString
color = settings.
value( QStringLiteral(
"codeEditor/%1" ).arg( sColorRoleToSettingsKey.value( role ) ), QString(),
QgsSettings::Gui ).toString();
1009 if (
color.isValid() )
1015 settings.
remove( QStringLiteral(
"codeEditor/%1" ).arg( sColorRoleToSettingsKey.value( role ) ),
QgsSettings::Gui );
1022 return font.fixedPitch();
1027 QFont font = QFontDatabase::systemFont( QFontDatabase::FixedFont );
1030 if ( !settings.
value( QStringLiteral(
"codeEditor/fontfamily" ), QString(),
QgsSettings::Gui ).toString().isEmpty() )
1033 const int fontSize = settings.
value( QStringLiteral(
"codeEditor/fontsize" ), 0,
QgsSettings::Gui ).toInt();
1037 font.setPointSize( fontSize );
1041 font.setPointSize( QLabel().font().pointSize() );
1045 font.setPointSize( fontSize );
1048 const int fontSize = settings.
value( QStringLiteral(
"qgis/stylesheet/fontPointSize" ), 10 ).toInt();
1049 font.setPointSize( fontSize );
1052 font.setBold(
false );
1059 mUseDefaultSettings =
false;
1060 mOverrideColors = !customColors.isEmpty();
1061 mColorScheme = scheme;
1062 mCustomColors = customColors;
1063 mFontFamily = fontFamily;
1064 mFontSize = fontSize;
1073 markerAdd( lineNumber, MARKER_NUMBER );
1075 font.setItalic(
true );
1076 const QsciStyle styleAnn = QsciStyle( -1, QStringLiteral(
"Annotation" ),
1081 annotate( lineNumber, warning, styleAnn );
1082 mWarningLines.push_back( lineNumber );
1087 for (
const int line : mWarningLines )
1089 markerDelete( line );
1090 clearAnnotations( line );
1093 mWarningLines.clear();
1100 getCursorPosition( &line, &index );
1101 return line == lines() - 1;
1106 mHistoryFilePath = path;
1112 setCursorPosition( 0, 0 );
1113 ensureCursorVisible();
1114 ensureLineVisible( 0 );
1122 const int endLine = lines() - 1;
1123 const int endLineLength = lineLength( endLine );
1124 setCursorPosition( endLine, endLineLength );
1125 ensureCursorVisible();
1126 ensureLineVisible( endLine );
1134 return static_cast<int>( SendScintilla( SCI_GETCURRENTPOS ) );
1140 lineIndexFromPosition( linearIndex, &line, &index );
1141 setCursorPosition( line, index );
1146 int startLine, startIndex, _;
1147 getSelection( &startLine, &startIndex, &_, &_ );
1148 if ( startLine == -1 )
1152 return positionFromLineIndex( startLine, startIndex );
1157 int endLine, endIndex, _;
1158 getSelection( &_, &_, &endLine, &endIndex );
1159 if ( endLine == -1 )
1163 return positionFromLineIndex( endLine, endIndex );
1168 int startLine, startIndex, endLine, endIndex;
1169 lineIndexFromPosition( start, &startLine, &startIndex );
1170 lineIndexFromPosition( end, &endLine, &endIndex );
1171 setSelection( startLine, startIndex, endLine, endIndex );
1186 if ( wrapMode() == WrapNone )
1198 if ( SendScintilla( SCI_WRAPCOUNT, line ) <= 1 )
1204 const long endLine = SendScintilla( SCI_GETLINEENDPOSITION, line );
1206 const long y = SendScintilla( SCI_POINTYFROMPOSITION, 0, endLine );
1208 return static_cast<int>( SendScintilla( SCI_POSITIONFROMPOINT, 0, y ) );
1215 if ( callTipsStyle() == CallTipsNone || lexer() ==
nullptr )
1220 QsciAbstractAPIs *apis = lexer()->apis();
1225 int pos, commas = 0;
1233 while ( ( ch = getCharacter( pos ) ) !=
'\0' )
1237 else if ( ch ==
')' )
1243 while ( ( ch = getCharacter( pos ) ) !=
'\0' )
1247 else if ( ch ==
'(' && --depth == 0 )
1251 else if ( ch ==
'(' )
1259 SendScintilla( SCI_CALLTIPCANCEL );
1265 int contextStart, lastWordStart;
1266 QStringList context = apiContext( pos, contextStart, lastWordStart );
1268 if ( context.isEmpty() )
1272 context << QString();
1274 QList<int> ctShifts;
1275 QStringList ctEntries = apis->callTips( context, commas, callTipsStyle(), ctShifts );
1277 int nbEntries = ctEntries.count();
1279 if ( nbEntries == 0 )
1282 const int maxNumberOfCallTips = callTipsVisible();
1285 if ( maxNumberOfCallTips > 0 && maxNumberOfCallTips < nbEntries )
1287 ctEntries = ctEntries.mid( 0, maxNumberOfCallTips );
1288 nbEntries = maxNumberOfCallTips;
1294 int nbShifts = ctShifts.count();
1296 if ( maxNumberOfCallTips < 0 && nbEntries > 1 )
1298 shift = ( nbShifts > 0 ? ctShifts.first() : 0 );
1300 ct.prepend(
'\002' );
1304 if ( nbShifts > nbEntries )
1305 nbShifts = nbEntries;
1310 for (
int i = 0; i < nbShifts; ++i )
1312 int sh = ctShifts[i];
1318 ct = ctEntries.join(
"\n" );
1321 QByteArray ctBa = ct.toLatin1();
1322 const char *cts = ctBa.data();
1326 if ( currentWrapPosition != -1 )
1328 SendScintilla( SCI_CALLTIPSHOW, currentWrapPosition, cts );
1336 int ctmin =
static_cast<int>( SendScintilla( SCI_POSITIONFROMLINE, SendScintilla( SCI_LINEFROMPOSITION, ct ) ) );
1337 if ( lastWordStart - shift < ctmin )
1338 lastWordStart = ctmin;
1342 lineIndexFromPosition( lastWordStart, &line, &index );
1343 SendScintilla( SCI_CALLTIPSHOW, positionFromLineIndex( line, index ), cts );
1347 if ( nbEntries > 1 )
1354 astart = strchr( cts,
'(' );
1356 for ( astart = strchr( cts,
',' ); astart && --commas > 0; astart = strchr( astart + 1,
',' ) )
1370 for ( aend = astart; *aend; ++aend )
1374 if ( ch ==
',' && depth == 0 )
1376 else if ( ch ==
'(' )
1378 else if ( ch ==
')' )
1387 if ( astart != aend )
1388 SendScintilla( SCI_CALLTIPSETHLT, astart - cts, aend - cts );
1395char QgsCodeEditor::getCharacter(
int &pos )
const
1400 char ch =
static_cast<char>( SendScintilla( SCI_GETCHARAT, --pos ) );
1403 if ( ch ==
'\n' || ch ==
'\r' )
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Warning
Warning message.
@ Critical
Critical/error message.
@ Info
Information message.
@ Success
Used for reporting a successful operation.
@ CheckSyntax
Language supports syntax checking.
@ Reformat
Language supports automatic code reformatting.
@ ToggleComment
Language supports comment toggling.
ScriptLanguage
Scripting languages.
@ QgisExpression
QGIS expressions.
@ Batch
Windows batch files.
@ Unknown
Unknown/other language.
QFlags< ScriptLanguageCapability > ScriptLanguageCapabilities
Script language capabilities.
static QPixmap getThemePixmap(const QString &name, const QColor &foreColor=QColor(), const QColor &backColor=QColor(), int size=16)
Helper to get a theme icon as a pixmap.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QHash< QString, QString > uiThemes()
All themes found in ~/.qgis3/themes folder.
static QString themeName()
Set the active theme to the specified theme.
QgsCodeEditorColorScheme scheme(const QString &id) const
Returns the color scheme with matching id.
Defines a color scheme for use in QgsCodeEditor widgets.
@ TripleSingleQuote
Triple single quote color.
@ CommentBlock
Comment block color.
@ QuotedOperator
Quoted operator color.
@ Decoration
Decoration color.
@ Identifier
Identifier color.
@ DoubleQuote
Double quote color.
@ QuotedIdentifier
Quoted identifier color.
@ SelectionForeground
Selection foreground color.
@ CommentLine
Line comment color.
@ FoldIconForeground
Fold icon foreground color.
@ MarginForeground
Margin foreground color.
@ ErrorBackground
Error background color.
@ MatchedBraceBackground
Matched brace background color.
@ Default
Default text color.
@ SearchMatchBackground
Background color for search matches.
@ CaretLine
Caret line color.
@ IndentationGuide
Indentation guide line.
@ Background
Background color.
@ SingleQuote
Single quote color.
@ MarginBackground
Margin background color.
@ SelectionBackground
Selection background color.
@ MatchedBraceForeground
Matched brace foreground color.
@ Operator
Operator color.
@ TripleDoubleQuote
Triple double quote color.
@ FoldIconHalo
Fold icon halo color.
QColor color(ColorRole role) const
Returns the color to use in the editor for the specified role.
A dialog for displaying and managing command history for a QgsCodeEditor widget.
bool eventFilter(QObject *watched, QEvent *event) override
void sessionHistoryCleared()
Emitted when the history of commands run in the current session is cleared.
void showHistory()
Shows the command history dialog.
int wrapPosition(int line=-1)
Returns the linear position of the start of the last wrapped part for the specified line,...
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 fr...
@ OutputDisplay
Read only mode for display of command outputs.
@ ScriptEditor
Standard mode, allows for display and edit of entire scripts.
@ CommandInput
Command input mode.
void reformatCode()
Applies code reformatting to the editor.
virtual void toggleComment()
Toggle comment for the selected text.
void contextMenuEvent(QContextMenuEvent *event) override
void clearPersistentHistory()
Clears the entire persistent history of commands run in the editor.
void removeHistoryCommand(int index)
Removes the command at the specified index from the history of the code editor.
static void setColor(QgsCodeEditorColorScheme::ColorRole role, const QColor &color)
Sets the color to use in the editor for the specified role.
void setHistoryFilePath(const QString &path)
Sets the file path to use for recording and retrieving previously executed commands.
void setLinearSelection(int start, int end)
Convenience function to set the selection using linear indexes.
QStringList history() const
Returns the list of commands previously executed in the editor.
static constexpr int SEARCH_RESULT_INDICATOR
Indicator index for search results.
void keyPressEvent(QKeyEvent *event) override
virtual void moveCursorToStart()
Moves the cursor to the start of the document and scrolls to ensure it is visible.
virtual void populateContextMenu(QMenu *menu)
Called when the context menu for the widget is about to be shown, after it has been fully populated w...
QFlags< Flag > Flags
Flags controlling behavior of code editor.
void persistentHistoryCleared()
Emitted when the persistent history of commands run in the editor is cleared.
virtual void callTip() override
void runCommand(const QString &command, bool skipHistory=false)
Runs a command in the editor.
void setFoldingVisible(bool folding)
Set whether the folding controls are visible in the editor.
virtual Qgis::ScriptLanguageCapabilities languageCapabilities() const
Returns the associated scripting language capabilities.
void setInterpreter(QgsCodeInterpreter *newInterpreter)
Sets an attached code interpreter for executing commands when the editor is in the QgsCodeEditor::Mod...
@ FoldingControls
Folding controls.
@ ErrorIndicators
Error indicators.
@ LineNumbers
Line numbers.
void runPostLexerConfigurationTasks()
Performs tasks which must be run after a lexer has been set for the widget.
virtual void showMessage(const QString &title, const QString &message, Qgis::MessageLevel level)
Shows a user facing message (eg a warning message).
int selectionEnd() const
Convenience function to return the end of the selection as a linear index Contrary to the getSelectio...
virtual void initializeLexer()
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
int linearPosition() const
Convenience function to return the cursor position as a linear index.
void setTitle(const QString &title)
Set the widget title.
void setLinearPosition(int position)
Convenience function to set the cursor position as a linear index.
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.
void clearWarnings()
Clears all warning messages from the editor.
static QFont getMonospaceFont()
Returns the monospaced font to use for code editors.
void showNextCommand()
Shows the next command from the session in the editor.
void focusOutEvent(QFocusEvent *event) override
@ CodeFolding
Indicates that code folding should be enabled for the editor.
@ ImmediatelyUpdateHistory
Indicates that the history file should be immediately updated whenever a command is executed,...
bool isCursorOnLastLine() const
Returns true if the cursor is on the last line of the document.
static bool isFixedPitch(const QFont &font)
Returns true if a font is a fixed pitch font.
void updateSoftHistory()
Updates the soft history by storing the current editor text in the history.
void clearSessionHistory()
Clears the history of commands run in the current session.
void insertText(const QString &text)
Insert text at cursor position, or replace any selected text if user has made a selection.
bool writeHistoryFile()
Stores the commands executed in the editor to the persistent history file.
virtual void moveCursorToEnd()
Moves the cursor to the end of the document and scrolls to ensure it is visible.
static QString languageToString(Qgis::ScriptLanguage language)
Returns a user-friendly, translated name of the specified script language.
void setLineNumbersVisible(bool visible)
Sets whether line numbers should be visible in the editor.
virtual Qgis::ScriptLanguage language() const
Returns the associated scripting language.
QFont lexerFont() const
Returns the font to use in the lexer.
virtual QString reformatCodeString(const QString &string)
Applies code reformatting to a string and returns the result.
QgsCodeInterpreter * interpreter() const
Returns the attached code interpreter, or nullptr if not set.
bool lineNumbersVisible() const
Returns whether line numbers are visible in the editor.
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.
bool foldingVisible()
Returns true if the folding controls are visible in the editor.
void showPreviousCommand()
Shows the previous command from the session in the editor.
Q_DECL_DEPRECATED void setMarginVisible(bool margin)
Set margin visible state.
void updatePrompt()
Triggers an update of the interactive prompt part of the editor.
static QColor defaultColor(QgsCodeEditorColorScheme::ColorRole role, const QString &theme=QString())
Returns the default color for the specified role.
int selectionStart() const
Convenience function to return the start of the selection as a linear index Contrary to the getSelect...
void addWarning(int lineNumber, const QString &warning)
Adds a warning message and indicator to the specified a lineNumber.
virtual bool checkSyntax()
Applies syntax checking to the editor.
static QColor color(QgsCodeEditorColorScheme::ColorRole role)
Returns the color to use in the editor for the specified role.
An interface for code interpreters.
virtual int execCommandImpl(const QString &command)=0
Pure virtual method for executing commands in the interpreter.
virtual int currentState() const
Returns the current interpreter state.
virtual QString promptForState(int state) const =0
Returns the interactive prompt string to use for the interpreter, given a state.
int exec(const QString &command)
Executes a command in the interpreter.
virtual ~QgsCodeInterpreter()
static void setFontFamily(QFont &font, const QString &family)
Sets the family for a font object.
void optionsChanged()
This signal is emitted whenever the application options have been changed.
static QgsGui * instance()
Returns a pointer to the singleton instance.
static QgsCodeEditorColorSchemeRegistry * codeEditorColorSchemeRegistry()
Returns the global code editor color scheme registry, used for registering the color schemes for QgsC...
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static int levenshteinDistance(const QString &string1, const QString &string2, bool caseSensitive=false)
Returns the Levenshtein edit distance between two strings.
static QColor decodeColor(const QString &str)
#define BUILTIN_UNREACHABLE
int findMinimalDistanceIndex(const QString &source, const QString &target)