QGIS API Documentation  2.14.0-Essen
qgsattributeeditor.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsattributeeditor.cpp - description
3  -------------------
4  begin : July 2009
5  copyright : (C) 2009 by Jürgen E. Fischer
6  email : [email protected]
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 
19 #include "qgseditorwidgetfactory.h"
21 #include "qgseditorwidgetwrapper.h"
22 
23 #include "qgsattributeeditor.h"
25 #include "qgsvectorlayer.h"
26 
27 
29 {
31 
32  return createAttributeEditor( parent, editor, vl, idx, value, context );
33 }
34 
36 {
37  Q_UNUSED( proxyWidgets )
38 
40 
41  return createAttributeEditor( parent, editor, vl, idx, value, context );
42 }
43 
45 {
46  QString widgetType = vl->editFormConfig()->widgetType( idx );
48 
49  QgsEditorWidgetWrapper* eww = QgsEditorWidgetRegistry::instance()->create( widgetType, vl, idx, cfg, editor, parent, context );
50 
51  if ( eww )
52  {
53  eww->setValue( value );
54  return eww->widget();
55  }
56  else
57  {
58  return nullptr;
59  }
60 }
61 
63 {
64  Q_UNUSED( vl )
65  Q_UNUSED( idx )
66 
67  if ( !editor )
68  return false;
69 
71 
72  if ( wrapper )
73  {
74  value = wrapper->value();
75  return true;
76  }
77  return false;
78 }
79 
80 bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value )
81 {
82  Q_UNUSED( vl )
83  Q_UNUSED( idx )
84 
85  if ( !editor )
86  return false;
87 
89 
90  if ( wrapper )
91  {
92  wrapper->setValue( value );
93  return true;
94  }
95  return false;
96 }
static bool retrieveValue(QWidget *widget, QgsVectorLayer *vl, int idx, QVariant &value)
This class contains context information for attribute editor widgets.
Manages an editor widget Widget and wrapper share the same parent.
QString widgetType(int fieldIdx) const
Get the id for the editor widget used to represent the field at the given index.
QgsEditFormConfig * editFormConfig() const
Get the configuration of the form used to represent this vector layer.
static QgsEditorWidgetRegistry * instance()
This class is a singleton and has therefore to be accessed with this method instead of a constructor...
QgsEditorWidgetWrapper * create(const QString &widgetId, QgsVectorLayer *vl, int fieldIdx, const QgsEditorWidgetConfig &config, QWidget *editor, QWidget *parent, const QgsAttributeEditorContext &context=QgsAttributeEditorContext())
Create an attribute editor widget wrapper of a given type for a given field.
static QgsEditorWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
static bool setValue(QWidget *widget, QgsVectorLayer *vl, int idx, const QVariant &value)
QgsEditorWidgetConfig widgetConfig(int fieldIdx) const
Get the configuration for the editor widget used to represent the field at the given index...
virtual void setValue(const QVariant &value)=0
Is called, when the value of the widget needs to be changed.
static Q_DECL_DEPRECATED QWidget * createAttributeEditor(QWidget *parent, QWidget *editor, QgsVectorLayer *vl, int idx, const QVariant &value, QMap< int, QWidget * > &proxyWidgets)
Creates or prepares a attribute editor widget.
virtual QVariant value() const =0
Will be used to access the widget&#39;s value.
QWidget * widget()
Access the widget managed by this wrapper.
QObject * parent() const
Represents a vector layer which manages a vector based data sets.