QGIS API Documentation 3.27.0-Master (f261cc1f8b)
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
70 QgsCodeEditor( QWidget *parent SIP_TRANSFERTHIS = nullptr, const QString &title = QString(), bool folding = false, bool margin = false );
71
76 void setTitle( const QString &title );
77
83 Q_DECL_DEPRECATED void setMarginVisible( bool margin ) SIP_DEPRECATED;
84
89 Q_DECL_DEPRECATED bool marginVisible() SIP_DEPRECATED { return mMargin; }
90
99 void setLineNumbersVisible( bool visible );
100
107 bool lineNumbersVisible() const;
108
113 void setFoldingVisible( bool folding );
114
119 bool foldingVisible() { return mFolding; }
120
126 void insertText( const QString &text );
127
139 static QColor defaultColor( QgsCodeEditorColorScheme::ColorRole role, const QString &theme = QString() );
140
150 static QColor color( QgsCodeEditorColorScheme::ColorRole role );
151
163 static void setColor( QgsCodeEditorColorScheme::ColorRole role, const QColor &color );
164
170 static QFont getMonospaceFont();
171
179 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;
180
187 void addWarning( int lineNumber, const QString &warning );
188
195 void clearWarnings();
196
197 protected:
198
199 bool isFixedPitch( const QFont &font );
200
201 void focusOutEvent( QFocusEvent *event ) override;
202 void keyPressEvent( QKeyEvent *event ) override;
203
211 virtual void initializeLexer();
212
218 QColor lexerColor( QgsCodeEditorColorScheme::ColorRole role ) const;
219
225 QFont lexerFont() const;
226
232 void runPostLexerConfigurationTasks();
233
234 private:
235
236 void setSciWidget();
237
238 QString mWidgetTitle;
239 bool mFolding;
240 bool mMargin;
241
242 bool mUseDefaultSettings = true;
243 // used if above is false, inplace of values taken from QSettings:
244 bool mOverrideColors = false;
245 QString mColorScheme;
246 QMap< QgsCodeEditorColorScheme::ColorRole, QColor > mCustomColors;
247 QString mFontFamily;
248 int mFontSize = 0;
249
250 QVector< int > mWarningLines;
251
252 static QMap< QgsCodeEditorColorScheme::ColorRole, QString > sColorRoleToSettingsKey;
253
254 static constexpr int MARKER_NUMBER = 6;
255};
256
257// clazy:excludeall=qstring-allocations
258
259#endif
Defines a color scheme for use in QgsCodeEditor widgets.
A text editor based on QScintilla2.
Definition: qgscodeeditor.h:42
Q_DECL_DEPRECATED bool marginVisible()
Returns whether margins are in a visible state.
Definition: qgscodeeditor.h:89
bool foldingVisible()
Returns true if the folding controls are visible in the editor.
MarginRole
Margin roles.
Definition: qgscodeeditor.h:55
#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