QGIS API Documentation 3.28.14-Firenze (exported)
Loading...
Searching...
No Matches
qgscodeeditor.h
Go to the documentation of this file.
1/***************************************************************************
2 qgscodeeditor.h - A base code editor for QGIS and plugins. Provides
3 a base editor using QScintilla for editors
4 --------------------------------------
5 Date : 06-Oct-2013
6 Copyright : (C) 2013 by Salvatore Larosa
7 Email : lrssvtml (at) gmail (dot) com
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGSCODEEDITOR_H
18#define QGSCODEEDITOR_H
19
20#include <QString>
22// qscintilla includes
23#include <Qsci/qsciapis.h>
24#include "qgis_sip.h"
25#include "qgis_gui.h"
26
27#include <QMap>
28
29
30SIP_IF_MODULE( HAVE_QSCI_SIP )
31
32
33class QWidget;
34
41class GUI_EXPORT QgsCodeEditor : public QsciScintilla
42{
43 Q_OBJECT
44
45 public:
46
55 {
56 LineNumbers = 0,
57 ErrorIndicators = 1,
58 FoldingControls = 2,
59 };
60 Q_ENUM( MarginRole )
61
62
67 enum class Flag : int
68 {
69 CodeFolding = 1 << 0,
70 };
71 Q_ENUM( Flag )
72
73
78 Q_DECLARE_FLAGS( Flags, Flag )
79 Q_FLAG( Flags )
80
81
91 QgsCodeEditor( QWidget * parent SIP_TRANSFERTHIS = nullptr, const QString & title = QString(), bool folding = false, bool margin = false, QgsCodeEditor::Flags flags = QgsCodeEditor::Flags() );
92
97 void setTitle( const QString & title );
98
104 Q_DECL_DEPRECATED void setMarginVisible( bool margin ) SIP_DEPRECATED;
105
110 Q_DECL_DEPRECATED bool marginVisible() SIP_DEPRECATED { return mMargin; }
111
120 void setLineNumbersVisible( bool visible );
121
128 bool lineNumbersVisible() const;
129
134 void setFoldingVisible( bool folding );
135
140 bool foldingVisible();
141
147 void insertText( const QString & text );
148
160 static QColor defaultColor( QgsCodeEditorColorScheme::ColorRole role, const QString & theme = QString() );
161
171 static QColor color( QgsCodeEditorColorScheme::ColorRole role );
172
184 static void setColor( QgsCodeEditorColorScheme::ColorRole role, const QColor & color );
185
191 static QFont getMonospaceFont();
192
200 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;
201
208 void addWarning( int lineNumber, const QString & warning );
209
216 void clearWarnings();
217
223 bool isCursorOnLastLine() const;
224
225 public slots:
226
233 virtual void moveCursorToStart();
234
241 virtual void moveCursorToEnd();
242
243 protected:
244
245 bool isFixedPitch( const QFont & font );
246
247 void focusOutEvent( QFocusEvent * event ) override;
248 void keyPressEvent( QKeyEvent * event ) override;
249 bool eventFilter( QObject * watched, QEvent * event ) override;
250
258 virtual void initializeLexer();
259
265 QColor lexerColor( QgsCodeEditorColorScheme::ColorRole role ) const;
266
272 QFont lexerFont() const;
273
279 void runPostLexerConfigurationTasks();
280
281 private:
282
283 void setSciWidget();
284 void updateFolding();
285
286 QString mWidgetTitle;
287 bool mMargin = false;
288 QgsCodeEditor::Flags mFlags;
289
290 bool mUseDefaultSettings = true;
291 // used if above is false, inplace of values taken from QSettings:
292 bool mOverrideColors = false;
293 QString mColorScheme;
294 QMap< QgsCodeEditorColorScheme::ColorRole, QColor > mCustomColors;
295 QString mFontFamily;
296 int mFontSize = 0;
297
298 QVector< int > mWarningLines;
299
300 static QMap< QgsCodeEditorColorScheme::ColorRole, QString > sColorRoleToSettingsKey;
301
302 static constexpr int MARKER_NUMBER = 6;
303};
304
306
307// clazy:excludeall=qstring-allocations
308
309#endif
Defines a color scheme for use in QgsCodeEditor widgets.
A text editor based on QScintilla2.
MarginRole
Margin roles.
Flag
Flags controlling behavior of code editor.
Q_DECL_DEPRECATED bool marginVisible()
Returns whether margins are in a visible state.
#define SIP_IF_MODULE(condition)
Definition qgis_sip.h:28
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:266
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.