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 = 1 << 1,
178 void setTitle( const QString &title );
222 void setLineNumbersVisible(
bool visible );
230 bool lineNumbersVisible()
const;
236 void setFoldingVisible(
bool folding );
242 bool foldingVisible();
249 void insertText(
const QString &text );
293 static QFont getMonospaceFont();
302 void setCustomAppearance(
const QString &scheme = QString(),
const QMap<QgsCodeEditorColorScheme::ColorRole, QColor> &customColors = QMap<QgsCodeEditorColorScheme::ColorRole, QColor>(),
const QString &fontFamily = QString(),
int fontSize = 0 )
SIP_SKIP;
310 void addWarning(
int lineNumber, const QString &warning );
318 void clearWarnings();
332 bool isCursorOnLastLine()
const;
342 void setHistoryFilePath(
const QString &path );
351 QStringList history()
const;
375 int linearPosition()
const;
382 void setLinearPosition(
int position );
391 int selectionStart()
const;
400 int selectionEnd()
const;
407 void setLinearSelection(
int start,
int end );
410 void callTip()
override;
419 int wrapPosition(
int line = -1 );
430 int editingTimeoutInterval()
const;
445 void runCommand(
const QString &command,
bool skipHistory =
false );
453 virtual void moveCursorToStart();
461 virtual void moveCursorToEnd();
470 void showPreviousCommand();
479 void showNextCommand();
495 void removeHistoryCommand(
int index );
504 void clearSessionHistory();
513 void clearPersistentHistory();
520 bool writeHistoryFile();
538 virtual bool checkSyntax();
547 virtual void toggleComment();
554 void adjustScrollWidth();
557 void setText(
const QString &text )
override;
568 void setEditingTimeoutInterval(
int timeout );
703 void onLastEditTimeout();
707 void updateFolding();
708 bool readHistoryFile();
709 void syncSoftHistory();
710 void updateHistory(
const QStringList &commands,
bool skipSoftHistory =
false );
711 char getCharacter(
int &pos )
const;
713 QString mWidgetTitle;
714 bool mMargin =
false;
718 bool mUseDefaultSettings =
true;
720 bool mOverrideColors =
false;
721 QString mColorScheme;
722 QMap<QgsCodeEditorColorScheme::ColorRole, QColor> mCustomColors;
726 QVector<int> mWarningLines;
729 QStringList mHistory;
730 QStringList mSoftHistory;
731 int mSoftHistoryIndex = 0;
732 QString mHistoryFilePath;
736 static QMap<QgsCodeEditorColorScheme::ColorRole, QString> sColorRoleToSettingsKey;
738 static constexpr int MARKER_NUMBER = 6;
740 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)