QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 "qgscodeeditor.h"
20#include "qgis_sip.h"
21#include "qgis_gui.h"
22#include <Qsci/qscilexerpython.h>
23
26template<class T> class QgsSettingsEntryEnumFlag;
27
28SIP_IF_MODULE( HAVE_QSCI_SIP )
29
30#ifndef SIP_RUN
32class QgsQsciLexerPython : public QsciLexerPython
33{
34 Q_OBJECT
35 public:
36 QgsQsciLexerPython( QObject *parent = nullptr );
37
38 const char *keywords( int set ) const override;
39};
41#endif
42
49class GUI_EXPORT QgsCodeEditorPython : public QgsCodeEditor
50{
51 Q_OBJECT
52
53 public:
54#ifndef SIP_RUN
56 static inline QgsSettingsTreeNode *sTreePythonCodeEditor = QgsCodeEditor::sTreeCodeEditor->createChildNode( QStringLiteral( "python" ) );
57 static const QgsSettingsEntryString *settingCodeFormatter;
58 static const QgsSettingsEntryInteger *settingMaxLineLength;
59 static const QgsSettingsEntryBool *settingSortImports;
60 static const QgsSettingsEntryInteger *settingAutopep8Level;
61 static const QgsSettingsEntryBool *settingBlackNormalizeQuotes;
62 static const QgsSettingsEntryString *settingExternalPythonEditorCommand;
63 static const QgsSettingsEntryEnumFlag<Qgis::DocumentationBrowser> *settingContextHelpBrowser;
65#endif
66
75 QgsCodeEditorPython( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QList<QString> &filenames = QList<QString>(), QgsCodeEditor::Mode mode = QgsCodeEditor::Mode::ScriptEditor, QgsCodeEditor::Flags flags = QgsCodeEditor::Flag::CodeFolding );
76
77 Qgis::ScriptLanguage language() const override;
79
84 void loadAPIs( const QList<QString> &filenames );
85
89 bool loadScript( const QString &script );
90
96 bool isCursorInsideStringLiteralOrComment() const;
97
103 QString characterBeforeCursor() const;
104
110 QString characterAfterCursor() const;
111
117 void updateCapabilities();
118
119 bool checkSyntax() override;
120
121 public slots:
122
128 void searchSelectedTextInPyQGISDocs();
129
135 virtual void showApiDocumentation( const QString &item );
136
142 void toggleComment() override;
143
144 protected:
145 void initializeLexer() override;
146 virtual void keyPressEvent( QKeyEvent *event ) override;
147 QString reformatCodeString( const QString &string ) override;
148 void populateContextMenu( QMenu *menu ) override;
149
150 protected slots:
151
157 void autoComplete();
158
159 private:
160 QList<QString> mAPISFilesList;
161 QString mPapFile;
162
164
165 static const QMap<QString, QString> sCompletionPairs;
166
167 // Only used for selected text
168 static const QStringList sCompletionSingleCharacters;
169};
170
171#endif
ScriptLanguage
Scripting languages.
Definition qgis.h:4244
QFlags< ScriptLanguageCapability > ScriptLanguageCapabilities
Script language capabilities.
Definition qgis.h:4279
A Python editor based on QScintilla2.
A text editor based on QScintilla2.
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.
virtual void initializeLexer()
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
@ 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.
QgsSettingsTreeNode is a tree node for the settings tree to help organizing and introspecting the tre...
QgsSettingsTreeNode * createChildNode(const QString &key)
Creates a normal tree node It will return the existing child node if it exists at the given key.
#define SIP_IF_MODULE(condition)
Definition qgis_sip.h:28
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53