Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 75c8678
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 0 deletions.
40 changes: 40 additions & 0 deletions python/gui/auto_generated/qgscodeeditorjs.sip.in
@@ -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 *
************************************************************************/
3 changes: 3 additions & 0 deletions python/gui/gui_auto.sip
Expand Up @@ -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 )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -361,6 +361,7 @@ SET(QGIS_GUI_SRCS
qgscodeeditor.cpp
qgscodeeditorcss.cpp
qgscodeeditorhtml.cpp
qgscodeeditorjs.cpp
qgscodeeditorpython.cpp
qgscodeeditorsql.cpp
qgscodeeditorexpression.cpp
Expand Down Expand Up @@ -591,6 +592,7 @@ SET(QGIS_GUI_HDRS
qgscodeeditorcss.h
qgscodeeditorexpression.h
qgscodeeditorhtml.h
qgscodeeditorjs.h
qgscodeeditorpython.h
qgscodeeditorsql.h
qgscollapsiblegroupbox.h
Expand Down
44 changes: 44 additions & 0 deletions src/gui/qgscodeeditorjs.cpp
@@ -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 );
}
45 changes: 45 additions & 0 deletions src/gui/qgscodeeditorjs.h
@@ -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.