QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
qgsjsoneditwrapper.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsjsoneditwrapper.cpp
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#include "qgsjsoneditwrapper.h"
17#include "moc_qgsjsoneditwrapper.cpp"
18
19#include "qgsjsoneditwidget.h"
20
21QgsJsonEditWrapper::QgsJsonEditWrapper( QgsVectorLayer *layer, int fieldIdx, QWidget *editor, QWidget *parent )
22 : QgsEditorWidgetWrapper( layer, fieldIdx, editor, parent )
23{
24}
25
27{
28 if ( !mJsonEditWidget )
29 return QVariant();
30
31 return mJsonEditWidget->property( RAW_VALUE_PROPERTY.toUtf8().data() );
32}
33
34QWidget *QgsJsonEditWrapper::createWidget( QWidget *parent )
35{
36 QgsJsonEditWidget *jsonEditWidget = new QgsJsonEditWidget( parent );
37 jsonEditWidget->setView( static_cast<QgsJsonEditWidget::View>( config( QStringLiteral( "DefaultView" ) ).toInt() ) );
38 jsonEditWidget->setFormatJsonMode( static_cast<QgsJsonEditWidget::FormatJson>( config( QStringLiteral( "FormatJson" ) ).toInt() ) );
39 return jsonEditWidget;
40}
41
42void QgsJsonEditWrapper::initWidget( QWidget *editor )
43{
44 mJsonEditWidget = qobject_cast<QgsJsonEditWidget *>( editor );
45 if ( !mJsonEditWidget )
46 {
47 mJsonEditWidget = new QgsJsonEditWidget( editor );
48 }
49}
50
52{
53 return ( mJsonEditWidget );
54}
55
57{
58 if ( !mJsonEditWidget )
59 return;
60
61 mJsonEditWidget->blockSignals( true );
62 mJsonEditWidget->setJsonText( QStringLiteral( "<mixed values>" ) );
63 mJsonEditWidget->blockSignals( false );
64}
65
67{
68 setFormFeature( feature );
69 setValue( feature.attribute( fieldIdx() ) );
70}
71
72void QgsJsonEditWrapper::updateValues( const QVariant &value, const QVariantList & )
73{
74 if ( !mJsonEditWidget )
75 return;
76
77 mJsonEditWidget->setProperty( RAW_VALUE_PROPERTY.toUtf8().data(), value );
78 mJsonEditWidget->setJsonText( field().displayString( value ) );
79}
80
82{
83 // No need to disable JsonEditWidget as it is already read only
84 Q_UNUSED( enabled )
85}
86
Manages an editor widget Widget and wrapper share the same parent.
void setFormFeature(const QgsFeature &feature)
Set the feature currently being edited to feature.
int fieldIdx() const
Access the field index.
QgsField field() const
Access the field.
virtual void setValue(const QVariant &value)
Is called when the value of the widget needs to be changed.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
The QgsJsonEditWidget is a widget to display JSON data in a code highlighted text or tree form.
void setJsonText(const QString &jsonText)
Set the JSON text in the widget to jsonText.
View
View mode, text or tree.
void setFormatJsonMode(FormatJson formatJson)
Set the formatJson mode.
void setView(View view) const
Set the view mode.
FormatJson
Format mode in the text view.
QWidget * createWidget(QWidget *parent) override
This method should create a new widget with the provided parent.
QVariant value() const override
Will be used to access the widget's value.
bool valid() const override
Returns true if the widget has been properly initialized.
QgsJsonEditWrapper(QgsVectorLayer *layer, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Constructor for QgsJsonEditWrapper.
void setEnabled(bool enabled) override
void initWidget(QWidget *editor) override
This method should initialize the editor widget with runtime data.
void showIndeterminateState() override
Sets the widget to display in an indeterminate "mixed value" state.
void setFeature(const QgsFeature &feature) override
Represents a vector layer which manages a vector based data sets.
QVariantMap config() const
Returns the whole config.