QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgscodeeditorpython.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscodeeditorpython.h - A Python editor based on QScintilla
3 --------------------------------------
4 Date : 06-Oct-2013
5 Copyright : (C) 2013 by Salvatore Larosa
6 Email : lrssvtml (at) gmail (dot) com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSCODEEDITORPYTHON_H
17#define QGSCODEEDITORPYTHON_H
18
19#include "qgis_gui.h"
20#include "qgis_sip.h"
21#include "qgscodeeditor.h"
22
23#include <QString>
24#include <Qsci/qscilexerpython.h>
25
26using namespace Qt::StringLiterals;
27
30template<class T> class QgsSettingsEntryEnumFlag;
31
32SIP_IF_MODULE( HAVE_QSCI_SIP )
33
34#ifndef SIP_RUN
36class QgsQsciLexerPython : public QsciLexerPython
37{
38 Q_OBJECT
39 public:
40 QgsQsciLexerPython( QObject *parent = nullptr );
41
42 const char *keywords( int set ) const override;
43};
45#endif
46
54class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
55{
56 Q_OBJECT
57
58 public:
59#ifndef SIP_RUN
61 static inline QgsSettingsTreeNode *sTreePythonCodeEditor = QgsCodeEditor::sTreeCodeEditor->createChildNode( u"python"_s );
62 static const QgsSettingsEntryString *settingCodeFormatter;
63 static const QgsSettingsEntryInteger *settingMaxLineLength;
64 static const QgsSettingsEntryBool *settingSortImports;
65 static const QgsSettingsEntryInteger *settingAutopep8Level;
66 static const QgsSettingsEntryBool *settingBlackNormalizeQuotes;
67 static const QgsSettingsEntryString *settingExternalPythonEditorCommand;
68 static const QgsSettingsEntryEnumFlag<Qgis::DocumentationBrowser> *settingContextHelpBrowser;
70#endif
71
80 QgsCodeEditorPython( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QList<QString> &filenames = QList<QString>(), QgsCodeEditor::Mode mode = QgsCodeEditor::Mode::ScriptEditor, QgsCodeEditor::Flags flags = QgsCodeEditor::Flag::CodeFolding );
81
82 Qgis::ScriptLanguage language() const override;
84
89 void loadAPIs( const QList<QString> &filenames );
90
94 bool loadScript( const QString &script );
95
102
108 QString characterBeforeCursor() const;
109
115 QString characterAfterCursor() const;
116
122 void updateCapabilities();
123
124 bool checkSyntax() override;
125
126 public slots:
127
134
140 virtual void showApiDocumentation( const QString &item );
141
147 void toggleComment() override;
148
149 protected:
150 void initializeLexer() override;
151 void keyPressEvent( QKeyEvent *event ) override;
152 QString reformatCodeString( const QString &string ) override;
153 void populateContextMenu( QMenu *menu ) override;
154
155 protected slots:
156
162 void autoComplete();
163
164 private:
165 QList<QString> mAPISFilesList;
166 QString mPapFile;
167
169
170 static const QMap<QString, QString> sCompletionPairs;
171
172 // Only used for selected text
173 static const QStringList sCompletionSingleCharacters;
174};
175
176#endif
ScriptLanguage
Scripting languages.
Definition qgis.h:4537
QFlags< ScriptLanguageCapability > ScriptLanguageCapabilities
Script language capabilities.
Definition qgis.h:4572
void autoComplete()
Triggers the autocompletion popup.
QString characterAfterCursor() const
Returns the character after the cursor, or an empty string if the cursor is set at end.
bool isCursorInsideStringLiteralOrComment() const
Check whether the current cursor position is inside a string literal or a comment.
void searchSelectedTextInPyQGISDocs()
Searches the selected text in the official PyQGIS online documentation.
void loadAPIs(const QList< QString > &filenames)
Load APIs from one or more files.
virtual void showApiDocumentation(const QString &item)
Displays the given text in the official APIs (PyQGIS, C++ QGIS or Qt) documentation.
PRIVATE QgsCodeEditorPython(QWidget *parent=nullptr, const QList< QString > &filenames=QList< QString >(), QgsCodeEditor::Mode mode=QgsCodeEditor::Mode::ScriptEditor, QgsCodeEditor::Flags flags=QgsCodeEditor::Flag::CodeFolding)
Construct a new Python editor.
void updateCapabilities()
Updates the editor capabilities.
bool loadScript(const QString &script)
Loads a script file.
QString characterBeforeCursor() const
Returns the character before the cursor, or an empty string if cursor is set at start.
QgsCodeEditor::Mode mode() const
Returns the code editor mode.
Mode
Code editor modes.
@ ScriptEditor
Standard mode, allows for display and edit of entire scripts.
virtual void toggleComment()
Toggle comment for the selected text.
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.
static QgsSettingsTreeNode * sTreeCodeEditor
virtual Qgis::ScriptLanguageCapabilities languageCapabilities() const
Returns the associated scripting language capabilities.
bool event(QEvent *event) override
virtual void initializeLexer()
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
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.
@ CodeFolding
Indicates that code folding should be enabled for the editor.
virtual Qgis::ScriptLanguage language() const
Returns the associated scripting language.
virtual QString reformatCodeString(const QString &string)
Applies code reformatting to a string and returns the result.
virtual bool checkSyntax()
Applies syntax checking to the editor.
A boolean settings entry.
A template class for enum and flag settings entry.
An integer settings entry.
A string settings entry.
A tree node for the settings tree to help organizing and introspecting the tree.
#define SIP_IF_MODULE(condition)
Definition qgis_sip.h:28
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53