QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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
28
29QgsEditorWidgetWrapper *QgsJsonEditWidgetFactory::create( QgsVectorLayer *vl, int fieldIdx, QWidget *editor, QWidget *parent ) const
30{
31 return new QgsJsonEditWrapper( vl, fieldIdx, editor, parent );
32}
33
35{
36 return new QgsJsonEditConfigDlg( vl, fieldIdx, parent );
37}
38
39unsigned int QgsJsonEditWidgetFactory::fieldScore( const QgsVectorLayer *vl, int fieldIdx ) const
40{
41 const QMetaType::Type type = vl->fields().field( fieldIdx ).type();
42
43 switch ( type )
44 {
45 case QMetaType::Type::QVariantMap:
46 {
47 const QString typeName = vl->fields().field( fieldIdx ).typeName();
48 if ( typeName == "json"_L1 || typeName == "jsonb"_L1 )
49 return 21;
50 return 15;
51 }
52 break;
53 case QMetaType::Type::QVariantList:
54 return 10;
55 break;
56 default:
57 return 5;
58 break;
59 }
60}
61
63{
64 return true;
65}
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:158
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.