QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsjsoneditwidgetfactory.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsjsoneditwidgetfactory.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
17
19#include "qgsjsoneditwrapper.h"
20
21#include <QString>
22
23using namespace Qt::StringLiterals;
24
29
30QgsEditorWidgetWrapper *QgsJsonEditWidgetFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
31{
32 return new QgsJsonEditWrapper( vl, fieldIdx, editor, parent );
33}
34
36{
37 return new QgsJsonEditConfigDlg( vl, fieldIdx, parent );
38}
39
40unsigned int QgsJsonEditWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
41{
42 const QMetaType::Type type = vl->fields().field( fieldIdx ).type();
43
44 switch ( type )
45 {
46 case QMetaType::Type::QVariantMap:
47 {
48 const QString typeName = vl->fields().field( fieldIdx ).typeName();
49 if ( typeName == "json"_L1 || typeName == "jsonb"_L1 )
50 return 21;
51 return 15;
52 }
53 break;
54 case QMetaType::Type::QVariantList:
55 return 10;
56 break;
57 default:
58 return 5;
59 break;
60 }
61}
62
64{
65 return true;
66}
Base class for widgets which configure editor widget types.
QgsEditorWidgetFactory(const QString &name, const QIcon &icon=QIcon())
Constructor.
QIcon icon() const
Returns the icon of this widget type.
QString name() const
Returns the human readable identifier name of this widget type.
Manages an editor widget.
QMetaType::Type type
Definition qgsfield.h:63
QString typeName() const
Gets the field type.
Definition qgsfield.cpp:167
QgsField field(int fieldIdx) const
Returns the field at particular index (must be in range 0..N-1).
A configuration widget for JSON edit widget.
QgsJsonEditWidgetFactory(const QString &name, const QIcon &icon=QIcon())
Constructor for QgsJsonEditWidgetFactory, where name is a human-readable name for the factory and ico...
QgsEditorConfigWidget * configWidget(QgsVectorLayer *vl, int fieldIdx, QWidget *parent) const override
Override this in your implementation.
unsigned int fieldScore(const QgsVectorLayer *vl, int fieldIdx) const override
This method allows disabling this editor widget type for a certain field.
QgsEditorWidgetWrapper * create(QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent) const override
Override this in your implementation.
bool isReadOnly() const override
Returns true if this widget is a read-only widget.
Wraps a JSON edit widget.
Represents a vector layer which manages a vector based dataset.