17#ifndef QGSCODEEDITOR_H
18#define QGSCODEEDITOR_H
27using namespace Qt::StringLiterals;
30#include <Qsci/qsciapis.h>
60 int exec(
const QString &command );
152 CodeFolding = 1 << 0,
153 ImmediatelyUpdateHistory
181 const QString &title = QString(),
182 bool folding = false,
192 void setTitle( const QString &title );
236 void setLineNumbersVisible(
bool visible );
244 bool lineNumbersVisible()
const;
250 void setFoldingVisible(
bool folding );
256 bool foldingVisible();
263 void insertText(
const QString &text );
307 static QFont getMonospaceFont();
316 void setCustomAppearance(
317 const QString &scheme = QString(),
318 const QMap<QgsCodeEditorColorScheme::ColorRole, QColor> &customColors = QMap<QgsCodeEditorColorScheme::ColorRole, QColor>(),
319 const QString &fontFamily = QString(),
329 void addWarning(
int lineNumber, const QString &warning );
337 void clearWarnings();
351 bool isCursorOnLastLine()
const;
361 void setHistoryFilePath(
const QString &path );
370 QStringList history()
const;
394 int linearPosition()
const;
401 void setLinearPosition(
int position );
410 int selectionStart()
const;
419 int selectionEnd()
const;
426 void setLinearSelection(
int start,
int end );
429 void callTip()
override;
438 int wrapPosition(
int line = -1 );
449 int editingTimeoutInterval()
const;
464 void runCommand(
const QString &command,
bool skipHistory =
false );
472 virtual void moveCursorToStart();
480 virtual void moveCursorToEnd();
489 void showPreviousCommand();
498 void showNextCommand();
514 void removeHistoryCommand(
int index );
523 void clearSessionHistory();
532 void clearPersistentHistory();
539 bool writeHistoryFile();
557 virtual bool checkSyntax();
566 virtual void toggleComment();
573 void adjustScrollWidth();
576 void setText(
const QString &text )
override;
587 void setEditingTimeoutInterval(
int timeout );
722 void onLastEditTimeout();
726 void updateFolding();
727 bool readHistoryFile();
728 void syncSoftHistory();
729 void updateHistory(
const QStringList &commands,
bool skipSoftHistory =
false );
730 char getCharacter(
int &pos )
const;
732 QString mWidgetTitle;
733 bool mMargin =
false;
737 bool mUseDefaultSettings =
true;
739 bool mOverrideColors =
false;
740 QString mColorScheme;
741 QMap<QgsCodeEditorColorScheme::ColorRole, QColor> mCustomColors;
745 QVector<int> mWarningLines;
748 QStringList mHistory;
749 QStringList mSoftHistory;
750 int mSoftHistoryIndex = 0;
751 QString mHistoryFilePath;
755 static QMap<QgsCodeEditorColorScheme::ColorRole, QString> sColorRoleToSettingsKey;
757 static constexpr int MARKER_NUMBER = 6;
759 QTimer *mLastEditTimer =
nullptr;
Provides global constants and enumerations for use throughout the application.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
bool eventFilter(QObject *watched, QEvent *event) override
void sessionHistoryCleared()
Emitted when the history of commands run in the current session is cleared.
static const QgsSettingsEntryBool * settingContextHelpHover
QgsCodeEditor::Mode mode() const
Returns the code editor mode.
@ ScriptEditor
Standard mode, allows for display and edit of entire scripts.
void contextMenuEvent(QContextMenuEvent *event) override
static const QgsSettingsEntryString * settingFontFamily
Settings entry for code editor font family override.
static constexpr int SEARCH_RESULT_INDICATOR
Indicator index for search results.
void keyPressEvent(QKeyEvent *event) override
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.
static QgsSettingsTreeNode * sTreeCodeEditor
virtual Qgis::ScriptLanguageCapabilities languageCapabilities() const
Returns the associated scripting language capabilities.
void runPostLexerConfigurationTasks()
Performs tasks which must be run after a lexer has been set for the widget.
bool event(QEvent *event) override
virtual void showMessage(const QString &title, const QString &message, Qgis::MessageLevel level)
Shows a user facing message (eg a warning message).
virtual void initializeLexer()
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
void setTitle(const QString &title)
Set the widget title.
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 focusOutEvent(QFocusEvent *event) override
Flag
Flags controlling behavior of code editor.
void helpRequested(const QString &word)
Emitted when documentation was requested for the specified word.
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.
static const QgsSettingsEntryInteger * settingFontSize
Settings entry for code editor font size override.
Q_DECL_DEPRECATED bool marginVisible()
Returns whether margins are in a visible state.
static QString languageToString(Qgis::ScriptLanguage language)
Returns a user-friendly, translated name of the specified script language.
virtual Qgis::ScriptLanguage language() const
Returns the associated scripting language.
QFont lexerFont() const
Returns the font to use in the lexer.
void toggleLineComments(const QString &commentPrefix)
Toggles comment for selected lines with the given comment prefix.
virtual QString reformatCodeString(const QString &string)
Applies code reformatting to a string and returns the result.
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.
Q_DECL_DEPRECATED void setMarginVisible(bool margin)
Set margin visible state.
void updatePrompt()
Triggers an update of the interactive prompt part of the editor.
void editingTimeout()
Emitted when either:
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()
QLineEdit subclass with built in support for clearing the widget's value and handling custom null val...
A boolean settings entry.
An integer settings entry.
A tree node for the settings tree to help organizing and introspecting the tree.
static QgsSettingsTreeNode * sTreeGui
#define SIP_IF_MODULE(condition)
#define SIP_ENUM_BASETYPE(type)
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)