QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgscodeeditorjson.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgscodeeditorjson.cpp - A JSON editor based on QScintilla
3 --------------------------------------
4 Date : 4.5.2021
5 Copyright : (C) 2021 Damiano Lombardi
6 Email : damiano at opengis dot ch
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#include "qgscodeeditorjson.h"
17
18#include <QFont>
19#include <QString>
20#include <QWidget>
21#include <Qsci/qscilexerjson.h>
22
23#include "moc_qgscodeeditorjson.cpp"
24
26 : QgsCodeEditor( parent, QString(), false, false, QgsCodeEditor::Flag::CodeFolding )
27{
28 if ( !parent )
29 {
30 setTitle( tr( "JSON Editor" ) );
31 }
33}
34
39
41{
42 QsciLexerJSON *lexer = new QsciLexerJSON( this );
43
44 QFont font = lexerFont();
45 lexer->setDefaultFont( font );
46 lexer->setFont( font, -1 );
47
48 font.setItalic( true );
49 lexer->setFont( font, QsciLexerJSON::CommentBlock );
50 lexer->setFont( font, QsciLexerJSON::CommentLine );
51
55
56 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QsciLexerJSON::Property );
57 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QsciLexerJSON::Keyword );
58 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Operator ), QsciLexerJSON::Operator );
59 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerJSON::Number );
60 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentBlock ), QsciLexerJSON::CommentBlock );
61 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentLine ), QsciLexerJSON::CommentLine );
62 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerJSON::String );
63 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerJSON::IRI );
64 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerJSON::UnclosedString );
65 lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Error ), QsciLexerJSON::Error );
66
67 setLexer( lexer );
70}
ScriptLanguage
Scripting languages.
Definition qgis.h:4478
Qgis::ScriptLanguage language() const override
Returns the associated scripting language.
void initializeLexer() override
Called when the dialect specific code lexer needs to be initialized (or reinitialized).
QgsCodeEditorJson(QWidget *parent=nullptr)
Constructor for QgsCodeEditorJson.
void runPostLexerConfigurationTasks()
Performs tasks which must be run after a lexer has been set for the widget.
void setTitle(const QString &title)
Set the widget title.
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.
Flag
Flags controlling behavior of code editor.
void setLineNumbersVisible(bool visible)
Sets whether line numbers should be visible in the editor.
QFont lexerFont() const
Returns the font to use in the lexer.
QColor lexerColor(QgsCodeEditorColorScheme::ColorRole role) const
Returns the color to use in the lexer for the specified role.