QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsjsoneditwidget.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsjsoneditwidget.h
3 --------------------------------------
4 Date : 3.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#ifndef QGSJSONEDITWIDGET_H
17#define QGSJSONEDITWIDGET_H
18
19#include "ui_qgsjsoneditwidget.h"
20
22#include "qgis_sip.h"
23#include "qgis_gui.h"
24
31class GUI_EXPORT QgsJsonEditWidget : public QWidget, private Ui::QgsJsonEditWidget
32{
33 Q_OBJECT
34
35 public:
37 enum class View : int
38 {
39 Text = 0,
40 Tree = 1
41 };
42
44 enum class FormatJson : int
45 {
46 Indented = 0,
47 Compact = 1,
48 Disabled = 2
49 };
50
55 explicit QgsJsonEditWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
56
62 QgsCodeEditorJson *jsonEditor();
63
67 void setJsonText( const QString &jsonText );
68
72 QString jsonText() const;
73
78 void setView( View view ) const;
79
84 void setFormatJsonMode( FormatJson formatJson );
85
89 void setControlsVisible( bool visible );
90
91 private slots:
92
93 void textToolButtonClicked( bool checked );
94 void treeToolButtonClicked( bool checked );
95
96 void copyValueActionTriggered();
97 void copyKeyActionTriggered();
98
99 void codeEditorJsonTextChanged();
100 void codeEditorJsonIndicatorClicked( int line, int index, Qt::KeyboardModifiers state );
101 void codeEditorJsonDwellStart( int position, int x, int y );
102 void codeEditorJsonDwellEnd( int position, int x, int y );
103
104 private:
105 enum class TreeWidgetColumn : int
106 {
107 Key = 0,
108 Value = 1
109 };
110
111 const int SCINTILLA_UNDERLINE_INDICATOR_INDEX = 15;
112
113 void refreshTreeView( const QJsonDocument &jsonDocument );
114 void refreshTreeViewItem( QTreeWidgetItem *treeWidgetItemParent, const QJsonValue &jsonValue );
115 void refreshTreeViewItemValue( QTreeWidgetItem *treeWidgetItem, const QString &jsonValueString, const QColor &textColor );
116
117 QFont monospaceFont() const;
118
119 QString mJsonText;
120
121 FormatJson mFormatJsonMode = FormatJson::Indented;
122
123 QStringList mClickableLinkList;
124
125 QAction *mCopyValueAction;
126 QAction *mCopyKeyAction;
127
128 bool mEnableUrlHighlighting = true;
129};
130
131#endif // QGSJSONEDITWIDGET_H
A JSON editor based on QScintilla2.
The QgsJsonEditWidget is a widget to display JSON data in a code highlighted text or tree form.
View
View mode, text or tree.
FormatJson
Format mode in the text view.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53