Skip to content
Permalink
Browse files
IdentiyResults dialog show JSON data as a tree view
  • Loading branch information
domi4484 committed May 14, 2021
1 parent a57a8dc commit a570a10bd9dec4f64f32a93dd803806e1192a83b
@@ -64,6 +64,11 @@ Set the ``view`` mode.
Set the ``formatJson`` mode.

.. seealso:: FormatJson
%End

void setControlsVisible( bool visible );
%Docstring
Set the visibility of controls to ``visible``.
%End

};
@@ -87,6 +87,7 @@
#include "qgsexpressioncontextutils.h"
#include "qgsidentifymenu.h"
#include "qgsjsonutils.h"
#include "qgsjsoneditwidget.h"
#include "qgspointcloudlayer.h"

#include <nlohmann/json.hpp>
@@ -697,7 +698,7 @@ QgsIdentifyResultsFeatureItem *QgsIdentifyResultsDialog::createFeatureItem( QgsV
break;

const QgsEditorWidgetSetup setup = QgsGui::editorWidgetRegistry()->findBest( vlayer, fields[i].name() );
if ( setup.type() == QLatin1String( "Hidden" ) )
if ( setup.type() == QStringLiteral( "Hidden" ) )
{
continue;
}
@@ -720,21 +721,36 @@ QgsIdentifyResultsFeatureItem *QgsIdentifyResultsDialog::createFeatureItem( QgsV
value = representValue( vlayer, setup, fields.at( i ).name(), attrs.at( i ) );
attrItem->setSortData( 1, value );
attrItem->setToolTip( 1, value );
bool foundLinks = false;
QString links = QgsStringUtils::insertLinks( value, &foundLinks );
if ( foundLinks )

if ( setup.type() == QStringLiteral( "JsonEdit" ) )
{
QLabel *valueLabel = new QLabel( links );
valueLabel->setOpenExternalLinks( true );
QgsJsonEditWidget *jsonEditWidget = new QgsJsonEditWidget();
jsonEditWidget->setJsonText( value );
jsonEditWidget->setView( QgsJsonEditWidget::View::Tree );
jsonEditWidget->setFormatJsonMode( QgsJsonEditWidget::FormatJson::Indented );
jsonEditWidget->setControlsVisible( false );
attrItem->setData( 1, Qt::DisplayRole, QString() );
QTreeWidget *tw = attrItem->treeWidget();
tw->setItemWidget( attrItem, 1, valueLabel );
QTreeWidget *treeWidget = attrItem->treeWidget();
treeWidget->setItemWidget( attrItem, 1, jsonEditWidget );
}
else
{
attrItem->setData( 1, Qt::DisplayRole, value );
QTreeWidget *tw = attrItem->treeWidget();
tw->setItemWidget( attrItem, 1, nullptr );
bool foundLinks = false;
QString links = QgsStringUtils::insertLinks( value, &foundLinks );
if ( foundLinks )
{
QLabel *valueLabel = new QLabel( links );
valueLabel->setOpenExternalLinks( true );
attrItem->setData( 1, Qt::DisplayRole, QString() );
QTreeWidget *tw = attrItem->treeWidget();
tw->setItemWidget( attrItem, 1, valueLabel );
}
else
{
attrItem->setData( 1, Qt::DisplayRole, value );
QTreeWidget *tw = attrItem->treeWidget();
tw->setItemWidget( attrItem, 1, nullptr );
}
}

if ( fields.at( i ).name() == vlayer->displayField() )
@@ -112,6 +112,11 @@ void QgsJsonEditWidget::setFormatJsonMode( QgsJsonEditWidget::FormatJson formatJ
mFormatJsonMode = formatJson;
}

void QgsJsonEditWidget::setControlsVisible( bool visible )
{
mControlsWidget->setVisible( visible );
}

void QgsJsonEditWidget::textToolButtonClicked( bool checked )
{
if ( checked )
@@ -77,6 +77,11 @@ class GUI_EXPORT QgsJsonEditWidget : public QWidget, private Ui::QgsJsonEditWidg
*/
void setFormatJsonMode( FormatJson formatJson );

/**
* \brief Set the visibility of controls to \a visible.
*/
void setControlsVisible( bool visible );

private slots:

void textToolButtonClicked( bool checked );
@@ -14,6 +14,71 @@
<string notr="true">Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QWidget" name="mControlsWidget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="mTextToolButton">
<property name="toolTip">
<string>Show text</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mIconFieldText.svg</normaloff>:/images/themes/default/mIconFieldText.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mTreeToolButton">
<property name="toolTip">
<string>Show tree</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mIconTreeView.svg</normaloff>:/images/themes/default/mIconTreeView.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QStackedWidget" name="mStackedWidget">
<property name="currentIndex">
@@ -49,57 +114,6 @@
</widget>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="mTextToolButton">
<property name="toolTip">
<string>Show text</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mIconFieldText.svg</normaloff>:/images/themes/default/mIconFieldText.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="mTreeToolButton">
<property name="toolTip">
<string>Show tree</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="../../../images/images.qrc">
<normaloff>:/images/themes/default/mIconTreeView.svg</normaloff>:/images/themes/default/mIconTreeView.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>

0 comments on commit a570a10

Please sign in to comment.