17#ifndef QGSCODEEDITOR_H
18#define QGSCODEEDITOR_H
27using namespace Qt::StringLiterals;
30#include <Qsci/qsciapis.h>
58 int exec(
const QString &command );
146 CodeFolding = 1 << 0,
147 ImmediatelyUpdateHistory
175 const QString &title = QString(),
176 bool folding = false,
186 void setTitle( const QString &title );
230 void setLineNumbersVisible(
bool visible );
238 bool lineNumbersVisible()
const;
244 void setFoldingVisible(
bool folding );
250 bool foldingVisible();
257 void insertText(
const QString &text );
301 static QFont getMonospaceFont();
310 void setCustomAppearance(
311 const QString &scheme = QString(),
312 const QMap<QgsCodeEditorColorScheme::ColorRole, QColor> &customColors = QMap<QgsCodeEditorColorScheme::ColorRole, QColor>(),
313 const QString &fontFamily = QString(),
323 void addWarning(
int lineNumber, const QString &warning );
331 void clearWarnings();
345 bool isCursorOnLastLine()
const;
355 void setHistoryFilePath(
const QString &path );
364 QStringList history()
const;
388 int linearPosition()
const;
395 void setLinearPosition(
int position );
404 int selectionStart()
const;
413 int selectionEnd()
const;
420 void setLinearSelection(
int start,
int end );
423 void callTip()
override;
432 int wrapPosition(
int line = -1 );
443 int editingTimeoutInterval()
const;
458 void runCommand(
const QString &command,
bool skipHistory =
false );
466 virtual void moveCursorToStart();
474 virtual void moveCursorToEnd();
483 void showPreviousCommand();
492 void showNextCommand();
508 void removeHistoryCommand(
int index );
517 void clearSessionHistory();
526 void clearPersistentHistory();
533 bool writeHistoryFile();
551 virtual bool checkSyntax();
560 virtual void toggleComment();
567 void adjustScrollWidth();
570 void setText(
const QString &text )
override;
581 void setEditingTimeoutInterval(
int timeout );
716 void onLastEditTimeout();
720 void updateFolding();
721 bool readHistoryFile();
722 void syncSoftHistory();
723 void updateHistory(
const QStringList &commands,
bool skipSoftHistory =
false );
724 char getCharacter(
int &pos )
const;
726 QString mWidgetTitle;
727 bool mMargin =
false;
731 bool mUseDefaultSettings =
true;
733 bool mOverrideColors =
false;
734 QString mColorScheme;
735 QMap<QgsCodeEditorColorScheme::ColorRole, QColor> mCustomColors;
739 QVector<int> mWarningLines;
742 QStringList mHistory;
743 QStringList mSoftHistory;
744 int mSoftHistoryIndex = 0;
745 QString mHistoryFilePath;
749 static QMap<QgsCodeEditorColorScheme::ColorRole, QString> sColorRoleToSettingsKey;
751 static constexpr int MARKER_NUMBER = 6;
753 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 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.
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.
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)