QGIS API Documentation  3.23.0-Master (c716e02dd3)
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 
21 #include "qgseditorconfigwidget.h"
22 #include "qgis_sip.h"
23 #include "qgis_gui.h"
24 
31 class GUI_EXPORT QgsJsonEditWidget : public QWidget, private Ui::QgsJsonEditWidget
32 {
33  Q_OBJECT
34 
35  public:
36 
38  enum class View : int
39  {
40  Text = 0,
41  Tree = 1
42  };
43 
45  enum class FormatJson : int
46  {
47  Indented = 0,
48  Compact = 1,
49  Disabled = 2
50  };
51 
56  explicit QgsJsonEditWidget( QWidget *parent SIP_TRANSFERTHIS = nullptr );
57 
61  void setJsonText( const QString &jsonText );
62 
66  QString jsonText() const;
67 
72  void setView( View view ) const;
73 
78  void setFormatJsonMode( FormatJson formatJson );
79 
83  void setControlsVisible( bool visible );
84 
85  private slots:
86 
87  void textToolButtonClicked( bool checked );
88  void treeToolButtonClicked( bool checked );
89 
90  void copyValueActionTriggered();
91  void copyKeyActionTriggered();
92 
93  void codeEditorJsonTextChanged();
94  void codeEditorJsonIndicatorClicked( int line, int index, Qt::KeyboardModifiers state );
95  void codeEditorJsonDwellStart( int position, int x, int y );
96  void codeEditorJsonDwellEnd( int position, int x, int y );
97 
98  private:
99 
100  enum class TreeWidgetColumn : int
101  {
102  Key = 0,
103  Value = 1
104  };
105 
106  const int SCINTILLA_UNDERLINE_INDICATOR_INDEX = 15;
107 
108  void refreshTreeView( const QJsonDocument &jsonDocument );
109  void refreshTreeViewItem( QTreeWidgetItem *treeWidgetItemParent, const QJsonValue &jsonValue );
110  void refreshTreeViewItemValue( QTreeWidgetItem *treeWidgetItem, const QString &jsonValueString, const QColor &textColor );
111 
112  QString mJsonText;
113 
114  FormatJson mFormatJsonMode = FormatJson::Indented;
115 
116  QStringList mClickableLinkList;
117 
118  QAction *mCopyValueAction;
119  QAction *mCopyKeyAction;
120 };
121 
122 #endif // QGSJSONEDITWIDGET_H
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