QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
25SIP_IF_MODULE( HAVE_QSCI_SIP )
26
27
33class GUI_EXPORT QgsJsonEditWidget : public QWidget, private Ui::QgsJsonEditWidget
34{
35 Q_OBJECT
36
37 public:
39 enum class View : int
40 {
41 Text = 0,
42 Tree = 1
43 };
44
46 enum class FormatJson : int
47 {
48 Indented = 0,
49 Compact = 1,
50 Disabled = 2
51 };
52
57 explicit QgsJsonEditWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
58
64 QgsCodeEditorJson *jsonEditor();
65
69 void setJsonText( const QString &jsonText );
70
74 QString jsonText() const;
75
80 void setView( View view ) const;
81
86 void setFormatJsonMode( FormatJson formatJson );
87
91 void setControlsVisible( bool visible );
92
93 private slots:
94
95 void textToolButtonClicked( bool checked );
96 void treeToolButtonClicked( bool checked );
97
98 void copyValueActionTriggered();
99 void copyKeyActionTriggered();
100
101 void codeEditorJsonTextChanged();
102 void codeEditorJsonIndicatorClicked( int line, int index, Qt::KeyboardModifiers state );
103 void codeEditorJsonDwellStart( int position, int x, int y );
104 void codeEditorJsonDwellEnd( int position, int x, int y );
105
106 private:
107 enum class TreeWidgetColumn : int
108 {
109 Key = 0,
110 Value = 1
111 };
112
113 const int SCINTILLA_UNDERLINE_INDICATOR_INDEX = 15;
114
115 void refreshTreeView( const QJsonDocument &jsonDocument );
116 void refreshTreeViewItem( QTreeWidgetItem *treeWidgetItemParent, const QJsonValue &jsonValue );
117 void refreshTreeViewItemValue( QTreeWidgetItem *treeWidgetItem, const QString &jsonValueString, const QColor &textColor );
118
119 QFont monospaceFont() const;
120
121 QString mJsonText;
122
123 FormatJson mFormatJsonMode = FormatJson::Indented;
124
125 QStringList mClickableLinkList;
126
127 QAction *mCopyValueAction;
128 QAction *mCopyKeyAction;
129
130 bool mEnableUrlHighlighting = true;
131};
132
133#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_IF_MODULE(condition)
Definition qgis_sip.h:28
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53