Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43164 from domi4484/jsonEdit
[FEATURE] Json edit widget
- Loading branch information
Showing
20 changed files
with
1,187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# The following has been generated automatically from src/gui/editorwidgets/qgsjsoneditwidget.h | ||
# monkey patching scoped based enum | ||
QgsJsonEditWidget.View.Text.__doc__ = "JSON data displayed as text." | ||
QgsJsonEditWidget.View.Tree.__doc__ = "JSON data displayed as tree. Tree view is disabled for invalid JSON data." | ||
QgsJsonEditWidget.View.__doc__ = 'View mode, text or tree.\n\n' + '* ``Text``: ' + QgsJsonEditWidget.View.Text.__doc__ + '\n' + '* ``Tree``: ' + QgsJsonEditWidget.View.Tree.__doc__ | ||
# -- | ||
# monkey patching scoped based enum | ||
QgsJsonEditWidget.FormatJson.Indented.__doc__ = "JSON data formatted with regular indentation" | ||
QgsJsonEditWidget.FormatJson.Compact.__doc__ = "JSON data formatted as a compact one line string" | ||
QgsJsonEditWidget.FormatJson.Disabled.__doc__ = "JSON data is not formatted" | ||
QgsJsonEditWidget.FormatJson.__doc__ = 'Format mode in the text view\n\n' + '* ``Indented``: ' + QgsJsonEditWidget.FormatJson.Indented.__doc__ + '\n' + '* ``Compact``: ' + QgsJsonEditWidget.FormatJson.Compact.__doc__ + '\n' + '* ``Disabled``: ' + QgsJsonEditWidget.FormatJson.Disabled.__doc__ | ||
# -- |
44 changes: 44 additions & 0 deletions
44
python/gui/auto_generated/codeeditors/qgscodeeditorjson.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/codeeditors/qgscodeeditorjson.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
|
||
class QgsCodeEditorJson : QgsCodeEditor | ||
{ | ||
%Docstring(signature="appended") | ||
A JSON editor based on QScintilla2. Adds syntax highlighting and | ||
code autocompletion. | ||
|
||
.. versionadded:: 3.20 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgscodeeditorjson.h" | ||
%End | ||
public: | ||
|
||
QgsCodeEditorJson( QWidget *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Constructor for QgsCodeEditorJson | ||
%End | ||
|
||
protected: | ||
virtual void initializeLexer(); | ||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/codeeditors/qgscodeeditorjson.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
77 changes: 77 additions & 0 deletions
77
python/gui/auto_generated/editorwidgets/qgsjsoneditwidget.sip.in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/editorwidgets/qgsjsoneditwidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
|
||
class QgsJsonEditWidget : QWidget | ||
{ | ||
%Docstring(signature="appended") | ||
The :py:class:`QgsJsonEditWidget` is a widget to display JSON data in a code highlighted text or tree form. | ||
|
||
.. versionadded:: 3.20 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgsjsoneditwidget.h" | ||
%End | ||
public: | ||
|
||
enum class View | ||
{ | ||
Text, | ||
Tree | ||
}; | ||
|
||
enum class FormatJson | ||
{ | ||
Indented, | ||
Compact, | ||
Disabled | ||
}; | ||
|
||
explicit QgsJsonEditWidget( QWidget *parent /TransferThis/ = 0 ); | ||
%Docstring | ||
Constructor for QgsJsonEditWidget. | ||
|
||
:param parent: parent widget | ||
%End | ||
|
||
void setJsonText( const QString &jsonText ); | ||
%Docstring | ||
Set the JSON text in the widget to ``jsonText``. | ||
%End | ||
|
||
QString jsonText() const; | ||
%Docstring | ||
Returns the JSON text. | ||
%End | ||
|
||
void setView( View view ) const; | ||
%Docstring | ||
Set the ``view`` mode. | ||
|
||
.. seealso:: View | ||
%End | ||
|
||
void setFormatJsonMode( FormatJson formatJson ); | ||
%Docstring | ||
Set the ``formatJson`` mode. | ||
|
||
.. seealso:: FormatJson | ||
%End | ||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/editorwidgets/qgsjsoneditwidget.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/*************************************************************************** | ||
qgscodeeditorjson.cpp - A JSON editor based on QScintilla | ||
-------------------------------------- | ||
Date : 4.5.2021 | ||
Copyright : (C) 2021 Damiano Lombardi | ||
Email : damiano at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* 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 "qgscodeeditorjson.h" | ||
|
||
#include <QWidget> | ||
#include <QString> | ||
#include <QFont> | ||
#include <Qsci/qscilexerjson.h> | ||
|
||
|
||
QgsCodeEditorJson::QgsCodeEditorJson( QWidget *parent ) | ||
: QgsCodeEditor( parent ) | ||
{ | ||
if ( !parent ) | ||
{ | ||
setTitle( tr( "JSON Editor" ) ); | ||
} | ||
setFoldingVisible( true ); | ||
QgsCodeEditorJson::initializeLexer(); | ||
} | ||
|
||
void QgsCodeEditorJson::initializeLexer() | ||
{ | ||
QsciLexerJSON *lexer = new QsciLexerJSON( this ); | ||
|
||
QFont font = lexerFont(); | ||
lexer->setDefaultFont( font ); | ||
lexer->setFont( font, -1 ); | ||
|
||
font.setItalic( true ); | ||
lexer->setFont( font, QsciLexerJSON::CommentBlock ); | ||
lexer->setFont( font, QsciLexerJSON::CommentLine ); | ||
|
||
lexer->setDefaultColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Default ) ); | ||
lexer->setDefaultPaper( lexerColor( QgsCodeEditorColorScheme::ColorRole::Background ) ); | ||
lexer->setPaper( lexerColor( QgsCodeEditorColorScheme::ColorRole::Background ), -1 ); | ||
|
||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Class ), QsciLexerJSON::Property ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Keyword ), QsciLexerJSON::Keyword ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Operator ), QsciLexerJSON::Operator ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Number ), QsciLexerJSON::Number ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentBlock ), QsciLexerJSON::CommentBlock ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::CommentLine ), QsciLexerJSON::CommentLine ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerJSON::String ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::DoubleQuote ), QsciLexerJSON::IRI ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::SingleQuote ), QsciLexerJSON::UnclosedString ); | ||
lexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::Error ), QsciLexerJSON::Error ); | ||
|
||
setLexer( lexer ); | ||
setLineNumbersVisible( true ); | ||
runPostLexerConfigurationTasks(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*************************************************************************** | ||
qgscodeeditorjson.h - A JSON editor based on QScintilla | ||
-------------------------------------- | ||
Date : 4.5.2021 | ||
Copyright : (C) 2021 Damiano Lombardi | ||
Email : damiano at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* 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 QGSCODEEDITORJSON_H | ||
#define QGSCODEEDITORJSON_H | ||
|
||
#include "qgscodeeditor.h" | ||
#include "qgis_sip.h" | ||
#include "qgis_gui.h" | ||
|
||
SIP_IF_MODULE( HAVE_QSCI_SIP ) | ||
|
||
|
||
/** | ||
* \ingroup gui | ||
* \brief A JSON editor based on QScintilla2. Adds syntax highlighting and | ||
* code autocompletion. | ||
* \since QGIS 3.20 | ||
*/ | ||
class GUI_EXPORT QgsCodeEditorJson : public QgsCodeEditor | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
//! Constructor for QgsCodeEditorJson | ||
QgsCodeEditorJson( QWidget *parent SIP_TRANSFERTHIS = nullptr ); | ||
|
||
protected: | ||
void initializeLexer() override; | ||
|
||
}; | ||
|
||
#endif // QGSCODEEDITORJSON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/*************************************************************************** | ||
qgsjsoneditconfigdlg.cpp | ||
-------------------------------------- | ||
Date : 3.5.2021 | ||
Copyright : (C) 2021 Damiano Lombardi | ||
Email : damiano at opengis dot ch | ||
*************************************************************************** | ||
* * | ||
* 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 "qgsjsoneditconfigdlg.h" | ||
|
||
QgsJsonEditConfigDlg::QgsJsonEditConfigDlg( QgsVectorLayer *vl, int fieldIdx, QWidget *parent ) | ||
: QgsEditorConfigWidget( vl, fieldIdx, parent ) | ||
{ | ||
setupUi( this ); | ||
connect( mDefaultViewComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsEditorConfigWidget::changed ); | ||
connect( mFormatJsonComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, &QgsEditorConfigWidget::changed ); | ||
} | ||
|
||
|
||
QVariantMap QgsJsonEditConfigDlg::config() | ||
{ | ||
QVariantMap cfg; | ||
|
||
cfg.insert( QStringLiteral( "DefaultView" ), mDefaultViewComboBox->currentIndex() ); | ||
cfg.insert( QStringLiteral( "FormatJson" ), mFormatJsonComboBox->currentIndex() ); | ||
|
||
return cfg; | ||
} | ||
|
||
void QgsJsonEditConfigDlg::setConfig( const QVariantMap &config ) | ||
{ | ||
mDefaultViewComboBox->setCurrentIndex( config.value( QStringLiteral( "DefaultView" ) ).toInt() ); | ||
mFormatJsonComboBox->setCurrentIndex( config.value( QStringLiteral( "FormatJson" ) ).toInt() ); | ||
} |
Oops, something went wrong.