QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
257 virtual void initializeLexer();
258
264 QColor lexerColor( QgsCodeEditorColorScheme::ColorRole role ) const;
265
271 QFont lexerFont() const;
272
278 void runPostLexerConfigurationTasks();
279
280 private:
281
282 void setSciWidget();
283 void updateFolding();
284
285 QString mWidgetTitle;
286 bool mMargin = false;
287 QgsCodeEditor::Flags mFlags;
288
289 bool mUseDefaultSettings = true;
290 // used if above is false, inplace of values taken from QSettings:
291 bool mOverrideColors = false;
292 QString mColorScheme;
293 QMap< QgsCodeEditorColorScheme::ColorRole, QColor > mCustomColors;
294 QString mFontFamily;
295 int mFontSize = 0;
296
297 QVector< int > mWarningLines;
298
299 static QMap< QgsCodeEditorColorScheme::ColorRole, QString > sColorRoleToSettingsKey;
300
301 static constexpr int MARKER_NUMBER = 6;
302};
303
305
306// clazy:excludeall=qstring-allocations
307
308#endif
Defines a color scheme for use in QgsCodeEditor widgets.
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:42
MarginRole
Margin roles.
Definition: qgscodeeditor.h:55
Flag
Flags controlling behavior of code editor.
Definition: qgscodeeditor.h:68
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.