Skip to content
Permalink
Browse files

Add QgsCodeEditorJavascript subclass of QgsCodeEditor

Allows plugins to create a nice editor for JSON content -- not easy
to do if we don't expose this through the QGIS api!
  • Loading branch information
nyalldawson committed Jun 16, 2020
1 parent 52692f9 commit 75c86786c160605c8b9937f3c35680db326eca5a
@@ -0,0 +1,40 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgscodeeditorjs.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsCodeEditorJavascript : QgsCodeEditor
{
%Docstring
A Javascript editor based on QScintilla2. Adds syntax highlighting and
code autocompletion.

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgscodeeditorjs.h"
%End
public:

QgsCodeEditorJavascript( QWidget *parent /TransferThis/ = 0 );
%Docstring
Constructor for QgsCodeEditorJavascript
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/gui/qgscodeeditorjs.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -34,6 +34,9 @@
%Include auto_generated/qgscodeeditorhtml.sip
%End
%If ( HAVE_QSCI_SIP )
%Include auto_generated/qgscodeeditorjs.sip
%End
%If ( HAVE_QSCI_SIP )
%Include auto_generated/qgscodeeditorpython.sip
%End
%If ( HAVE_QSCI_SIP )
@@ -361,6 +361,7 @@ SET(QGIS_GUI_SRCS
qgscodeeditor.cpp
qgscodeeditorcss.cpp
qgscodeeditorhtml.cpp
qgscodeeditorjs.cpp
qgscodeeditorpython.cpp
qgscodeeditorsql.cpp
qgscodeeditorexpression.cpp
@@ -591,6 +592,7 @@ SET(QGIS_GUI_HDRS
qgscodeeditorcss.h
qgscodeeditorexpression.h
qgscodeeditorhtml.h
qgscodeeditorjs.h
qgscodeeditorpython.h
qgscodeeditorsql.h
qgscollapsiblegroupbox.h
@@ -0,0 +1,44 @@
/***************************************************************************
qgscodeeditorjs.cpp - A Javascript editor based on QScintilla
--------------------------------------
Date : June 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsapplication.h"
#include "qgscodeeditorjs.h"

#include <QWidget>
#include <QString>
#include <QFont>
#include <Qsci/qscilexerjavascript.h>


QgsCodeEditorJavascript::QgsCodeEditorJavascript( QWidget *parent )
: QgsCodeEditor( parent )
{
if ( !parent )
{
setTitle( tr( "JavaScript Editor" ) );
}
setMarginVisible( false );
setFoldingVisible( true );
setSciLexerJs();
}

void QgsCodeEditorJavascript::setSciLexerJs()
{
QsciLexerJavaScript *lexer = new QsciLexerJavaScript( this );
QFont f = getMonospaceFont();
lexer->setDefaultFont( f );
lexer->setFont( f, -1 );
setLexer( lexer );
}
@@ -0,0 +1,45 @@
/***************************************************************************
qgscodeeditorjs.h - A Javascript editor based on QScintilla
--------------------------------------
Date : June 2020
Copyright : (C) 2020 by Nyall Dawson
Email : nyall dot dawson at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSCODEEDITORJS_H
#define QGSCODEEDITORJS_H

#include "qgscodeeditor.h"
#include "qgis_sip.h"
#include "qgis_gui.h"

SIP_IF_MODULE( HAVE_QSCI_SIP )


/**
* \ingroup gui
* A Javascript editor based on QScintilla2. Adds syntax highlighting and
* code autocompletion.
* \since QGIS 3.14
*/
class GUI_EXPORT QgsCodeEditorJavascript : public QgsCodeEditor
{
Q_OBJECT

public:

//! Constructor for QgsCodeEditorJavascript
QgsCodeEditorJavascript( QWidget *parent SIP_TRANSFERTHIS = nullptr );

private:
void setSciLexerJs();
};

#endif // QGSCODEEDITORJS_H

0 comments on commit 75c8678

Please sign in to comment.
You can’t perform that action at this time.