QGIS API Documentation  2.14.0-Essen
qgseditorwidgetwrapper.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgseditorwidgetwrapper.cpp
3  --------------------------------------
4  Date : 20.4.2013
5  Copyright : (C) 2013 Matthias Kuhn
6  Email : matthias 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 "qgseditorwidgetwrapper.h"
17 #include "qgsvectorlayer.h"
18 #include "qgsvectordataprovider.h"
19 #include "qgsfield.h"
20 
21 #include <QWidget>
22 
24  : QgsWidgetWrapper( vl, editor, parent )
25  , mFieldIdx( fieldIdx )
26 {
27 }
28 
30 {
31  return mFieldIdx;
32 }
33 
35 {
36  if ( mFieldIdx < layer()->fields().count() )
37  return layer()->fields().at( mFieldIdx );
38  else
39  return QgsField();
40 }
41 
43 {
44  return layer()->dataProvider()->defaultValue( mFieldIdx );
45 }
46 
48 {
49  return qobject_cast<QgsEditorWidgetWrapper*>( widget->property( "EWV2Wrapper" ).value<QgsWidgetWrapper*>() );
50 }
51 
53 {
54  QWidget* wdg = widget();
55  if ( wdg )
56  {
57  wdg->setEnabled( enabled );
58  }
59 }
60 
62 {
63  setValue( feature.attribute( mFieldIdx ) );
64 }
65 
67 {
68  emit valueChanged( QVariant( value ) );
69 }
70 
72 {
73  emit valueChanged( QVariant( value ) );
74 }
75 
77 {
78  emit valueChanged( QVariant( value ) );
79 }
80 
82 {
83  emit valueChanged( QVariant( value ) );
84 }
85 
87 {
88  emit valueChanged( QVariant( value ) );
89 }
90 
92 {
93  emit valueChanged( value() );
94 }
int fieldIdx() const
Access the field index.
void valueChanged()
Will call the value() method to determine the emitted value.
QgsFields fields() const
Returns the list of fields of this layer.
Manages an editor widget Widget and wrapper share the same parent.
QgsField field() const
Access the field.
T value() const
void setEnabled(bool enabled) override
Is used to enable or disable the edit functionality of the managed widget.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
void setEnabled(bool)
QVariant property(const char *name) const
void setFeature(const QgsFeature &feature) override
Will be called when the feature changes.
static QgsEditorWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
virtual void setValue(const QVariant &value)=0
Is called, when the value of the widget needs to be changed.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
Definition: qgsfield.cpp:385
QVariant defaultValue() const
Access the default value of the field.
QgsEditorWidgetWrapper(QgsVectorLayer *vl, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
Create a new widget wrapper.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Definition: qgsfeature.cpp:271
virtual QVariant defaultValue(int fieldId)
Returns the default value for field specified by fieldId.
QgsVectorLayer * layer() const
Access the QgsVectorLayer, you are working on.
virtual QVariant value() const =0
Will be used to access the widget&#39;s value.
QWidget * widget()
Access the widget managed by this wrapper.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.