QGIS API Documentation  3.6.0-Noosa (5873452)
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | List of all members
QgsEditorWidgetWrapper Class Referenceabstract

Manages an editor widget Widget and wrapper share the same parent. More...

#include <qgseditorwidgetwrapper.h>

Inheritance diagram for QgsEditorWidgetWrapper:
Inheritance graph
[legend]

Public Types

enum  ConstraintResult { ConstraintResultPass = 0, ConstraintResultFailHard, ConstraintResultFailSoft }
 Result of constraint checks. More...
 
- Public Types inherited from QgsWidgetWrapper
enum  Property { RootPath = 0, DocumentViewerContent }
 Data defined properties for different editor widgets. More...
 

Public Slots

void emitValueChanged ()
 Will call the value() method to determine the emitted value. More...
 
void setFeature (const QgsFeature &feature) override
 Will be called when the feature changes. More...
 
virtual void setValue (const QVariant &value)=0
 Is called, when the value of the widget needs to be changed. More...
 
- Public Slots inherited from QgsWidgetWrapper
virtual void setFeature (const QgsFeature &feature)=0
 Is called, when the value of the widget needs to be changed. More...
 

Signals

void constraintResultVisibleChanged (bool visible)
 Emit this signal when the constraint result visibility changed. More...
 
void constraintStatusChanged (const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status)
 Emit this signal when the constraint status changed. More...
 
void valueChanged (const QVariant &value)
 Emit this signal, whenever the value changed. More...
 
- Signals inherited from QgsWidgetWrapper
void contextChanged ()
 Signal when QgsAttributeEditorContext mContext changed. More...
 

Public Member Functions

 QgsEditorWidgetWrapper (QgsVectorLayer *vl, int fieldIdx, QWidget *editor=nullptr, QWidget *parent=nullptr)
 Create a new widget wrapper. More...
 
QString constraintFailureReason () const
 Returns the reason why a constraint check has failed (or an empty string if constraint check was successful). More...
 
ConstraintResult constraintResult () const
 Returns the constraint result, which is the current result of the constraint on the widget influencing its visualization. More...
 
bool constraintResultVisible () const
 Returns whether the constraint result is visible. More...
 
QVariant defaultValue () const
 Access the default value of the field. More...
 
QgsField field () const
 Access the field. More...
 
int fieldIdx () const
 Access the field index. More...
 
bool isBlockingCommit () const
 Returns true if the widget is preventing the feature from being committed. More...
 
bool isValidConstraint () const
 Gets the current constraint status. More...
 
void setConstraintResultVisible (bool constraintResultVisible)
 Sets whether the constraint result is visible. More...
 
void setEnabled (bool enabled) override
 Is used to enable or disable the edit functionality of the managed widget. More...
 
virtual void setHint (const QString &hintText)
 Add a hint text on the widget. More...
 
virtual void showIndeterminateState ()
 Sets the widget to display in an indeterminate "mixed value" state. More...
 
void updateConstraint (const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin=QgsFieldConstraints::ConstraintOriginNotSet)
 Update constraint. More...
 
void updateConstraint (const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin=QgsFieldConstraints::ConstraintOriginNotSet)
 Update constraint on a feature coming from a specific layer. More...
 
virtual QVariant value () const =0
 Will be used to access the widget's value. More...
 
- Public Member Functions inherited from QgsWidgetWrapper
 QgsWidgetWrapper (QgsVectorLayer *vl, QWidget *editor=nullptr, QWidget *parent=nullptr)
 Create a new widget wrapper. More...
 
QVariant config (const QString &key, const QVariant &defaultVal=QVariant()) const
 Use this inside your overridden classes to access the configuration. More...
 
QVariantMap config () const
 Returns the whole config. More...
 
const QgsAttributeEditorContextcontext () const
 Returns information about the context in which this widget is shown. More...
 
QgsPropertyCollectiondataDefinedProperties ()
 Returns a reference to the editor widget's property collection, used for data defined overrides. More...
 
const QgsPropertyCollectiondataDefinedProperties () const
 Returns a reference to the editor widget's property collection, used for data defined overrides. More...
 
QgsVectorLayerlayer () const
 Returns the vector layer associated with the widget. More...
 
void notifyAboutToSave ()
 Notify this widget, that the containing form is about to save and that any pending changes should be pushed to the edit buffer or they might be lost. More...
 
void setConfig (const QVariantMap &config)
 Will set the config of this wrapper to the specified config. More...
 
void setContext (const QgsAttributeEditorContext &context)
 Set the context in which this widget is shown. More...
 
void setDataDefinedProperties (const QgsPropertyCollection &collection)
 Sets the editor widget's property collection, used for data defined overrides. More...
 
virtual bool valid () const =0
 Returns true if the widget has been properly initialized. More...
 
QWidget * widget ()
 Access the widget managed by this wrapper. More...
 
template<class T >
T * widget ()
 Access the widget managed by this wrapper and cast it to a given type Example: QPushButton* pb = wrapper->widget<QPushButton*>();. More...
 

Static Public Member Functions

static QgsEditorWidgetWrapperfromWidget (QWidget *widget)
 Will return a wrapper for a given widget. More...
 
static bool isInTable (const QWidget *parent)
 Check if the given widget or one of its parent is a QTableView. More...
 
- Static Public Member Functions inherited from QgsWidgetWrapper
static QgsWidgetWrapperfromWidget (QWidget *widget)
 Will return a wrapper for a given widget. More...
 
static const QgsPropertiesDefinitionpropertyDefinitions ()
 Returns the editor widget property definitions. More...
 

Protected Member Functions

QgsFeature formFeature () const
 The feature currently being edited, in its current state. More...
 
void setFormFeature (const QgsFeature &feature)
 Set the feature currently being edited to feature. More...
 
bool setFormFeatureAttribute (const QString &attributeName, const QVariant &attributeValue)
 Update the feature currently being edited by changing its attribute attributeName to attributeValue. More...
 
virtual void updateConstraintWidgetStatus ()
 This should update the widget with a visual cue if a constraint status changed. More...
 
- Protected Member Functions inherited from QgsWidgetWrapper
virtual QWidget * createWidget (QWidget *parent)=0
 This method should create a new widget with the provided parent. More...
 
virtual void initWidget (QWidget *editor)
 This method should initialize the editor widget with runtime data. More...
 

Properties

ConstraintResult constraintResult
 
bool constraintResultVisible
 

Additional Inherited Members

- Protected Attributes inherited from QgsWidgetWrapper
QgsPropertyCollection mPropertyCollection
 Data defined property collection. More...
 

Detailed Description

Manages an editor widget Widget and wrapper share the same parent.

A wrapper controls one attribute editor widget and is able to create a default widget or use a pre-existent widget. It is able to set the widget to the value implied by a field of a vector layer, or return the value it currently holds. Every time it is changed it has to emit a valueChanged signal. If it fails to do so, there is no guarantee that the changed status of the widget will be saved.

Definition at line 42 of file qgseditorwidgetwrapper.h.

Member Enumeration Documentation

◆ ConstraintResult

Result of constraint checks.

Since
QGIS 3.0
Enumerator
ConstraintResultPass 

Widget passed constraints successfully.

ConstraintResultFailHard 

Widget failed at least one hard (enforced) constraint.

ConstraintResultFailSoft 

Widget failed at least one soft (non-enforced) constraint.

Definition at line 55 of file qgseditorwidgetwrapper.h.

Constructor & Destructor Documentation

◆ QgsEditorWidgetWrapper()

QgsEditorWidgetWrapper::QgsEditorWidgetWrapper ( QgsVectorLayer vl,
int  fieldIdx,
QWidget *  editor = nullptr,
QWidget *  parent = nullptr 
)
explicit

Create a new widget wrapper.

Parameters
vlThe layer on which the field is
fieldIdxThe field which will be controlled
editorAn editor widget. Can be NULL if one should be autogenerated.
parentA parent widget for this widget wrapper and the created widget.

Definition at line 26 of file qgseditorwidgetwrapper.cpp.

Member Function Documentation

◆ constraintFailureReason()

QString QgsEditorWidgetWrapper::constraintFailureReason ( ) const

Returns the reason why a constraint check has failed (or an empty string if constraint check was successful).

See also
isValidConstraint()
Since
QGIS 3.0

Definition at line 240 of file qgseditorwidgetwrapper.cpp.

◆ constraintResult()

ConstraintResult QgsEditorWidgetWrapper::constraintResult ( ) const

Returns the constraint result, which is the current result of the constraint on the widget influencing its visualization.

Since
QGIS 3.0

◆ constraintResultVisible()

bool QgsEditorWidgetWrapper::constraintResultVisible ( ) const

Returns whether the constraint result is visible.

Returns true if the constraint result will be visualized on the widget (with color). This will be disabled when the form is not editable.

Since
QGIS 3.0

◆ constraintResultVisibleChanged

void QgsEditorWidgetWrapper::constraintResultVisibleChanged ( bool  visible)
signal

Emit this signal when the constraint result visibility changed.

◆ constraintStatusChanged

void QgsEditorWidgetWrapper::constraintStatusChanged ( const QString &  constraint,
const QString &  desc,
const QString &  err,
QgsEditorWidgetWrapper::ConstraintResult  status 
)
signal

Emit this signal when the constraint status changed.

constraintStatusChanged

Parameters
constraintrepresented as a string
descis the constraint description
errthe error represented as a string. Empty if none.
status

◆ defaultValue()

QVariant QgsEditorWidgetWrapper::defaultValue ( ) const

Access the default value of the field.

Returns
the default value of the field
See also
layer()

Definition at line 48 of file qgseditorwidgetwrapper.cpp.

◆ emitValueChanged

void QgsEditorWidgetWrapper::emitValueChanged ( )
slot

Will call the value() method to determine the emitted value.

Definition at line 75 of file qgseditorwidgetwrapper.cpp.

◆ field()

QgsField QgsEditorWidgetWrapper::field ( ) const

Access the field.

Returns
The field you are working on
See also
layer()

Definition at line 39 of file qgseditorwidgetwrapper.cpp.

◆ fieldIdx()

int QgsEditorWidgetWrapper::fieldIdx ( ) const

Access the field index.

Returns
The index of the field you are working on
See also
layer()

Definition at line 34 of file qgseditorwidgetwrapper.cpp.

◆ formFeature()

QgsFeature QgsEditorWidgetWrapper::formFeature ( ) const
inlineprotected

The feature currently being edited, in its current state.

Returns
the feature currently being edited, in its current state
Since
QGIS 3.2

Definition at line 292 of file qgseditorwidgetwrapper.h.

◆ fromWidget()

QgsEditorWidgetWrapper * QgsEditorWidgetWrapper::fromWidget ( QWidget *  widget)
static

Will return a wrapper for a given widget.

Parameters
widgetThe widget which was created by a wrapper
Returns
The wrapper for the widget or NULL

Definition at line 55 of file qgseditorwidgetwrapper.cpp.

◆ isBlockingCommit()

bool QgsEditorWidgetWrapper::isBlockingCommit ( ) const

Returns true if the widget is preventing the feature from being committed.

This may be true as a result of attribute values failing enforced field constraints.

See also
isValidConstraint()
Since
QGIS 3.0

Definition at line 235 of file qgseditorwidgetwrapper.cpp.

◆ isInTable()

bool QgsEditorWidgetWrapper::isInTable ( const QWidget *  parent)
static

Check if the given widget or one of its parent is a QTableView.

Parameters
parentthe widget to check
Returns
true if yes

Definition at line 245 of file qgseditorwidgetwrapper.cpp.

◆ isValidConstraint()

bool QgsEditorWidgetWrapper::isValidConstraint ( ) const

Gets the current constraint status.

Returns
true if the constraint is valid or if there's no constraint, false otherwise
See also
constraintFailureReason()
isBlockingCommit()
Since
QGIS 2.16

Definition at line 230 of file qgseditorwidgetwrapper.cpp.

◆ setConstraintResultVisible()

void QgsEditorWidgetWrapper::setConstraintResultVisible ( bool  constraintResultVisible)

Sets whether the constraint result is visible.

Controls if the constraint result should be visualized on the widget (with color). This will be disabled when the form is not editable.

Parameters
constraintResultVisibleif constraintResult should be displayed (mostly editable status)
Since
QGIS 3.0

Definition at line 120 of file qgseditorwidgetwrapper.cpp.

◆ setEnabled()

void QgsEditorWidgetWrapper::setEnabled ( bool  enabled)
overridevirtual

Is used to enable or disable the edit functionality of the managed widget.

By default this will enable or disable the whole widget

Parameters
enabledEnable or Disable?

Reimplemented from QgsWidgetWrapper.

Definition at line 60 of file qgseditorwidgetwrapper.cpp.

◆ setFeature

void QgsEditorWidgetWrapper::setFeature ( const QgsFeature feature)
overrideslot

Will be called when the feature changes.

Is forwarded to the slot setValue()

Parameters
featureThe new feature

Definition at line 69 of file qgseditorwidgetwrapper.cpp.

◆ setFormFeature()

void QgsEditorWidgetWrapper::setFormFeature ( const QgsFeature feature)
inlineprotected

Set the feature currently being edited to feature.

Since
QGIS 3.2

Definition at line 299 of file qgseditorwidgetwrapper.h.

◆ setFormFeatureAttribute()

bool QgsEditorWidgetWrapper::setFormFeatureAttribute ( const QString &  attributeName,
const QVariant &  attributeValue 
)
protected

Update the feature currently being edited by changing its attribute attributeName to attributeValue.

Returns
bool true on success
Since
QGIS 3.2

Definition at line 105 of file qgseditorwidgetwrapper.cpp.

◆ setHint()

void QgsEditorWidgetWrapper::setHint ( const QString &  hintText)
virtual

Add a hint text on the widget.

Parameters
hintTextThe hint text to display
Since
QGIS 3.0

Reimplemented in QgsTextEditWrapper.

Definition at line 252 of file qgseditorwidgetwrapper.cpp.

◆ setValue

virtual void QgsEditorWidgetWrapper::setValue ( const QVariant &  value)
pure virtualslot

Is called, when the value of the widget needs to be changed.

Update the widget representation to reflect the new value.

Parameters
valueThe new value of the attribute

◆ showIndeterminateState()

virtual void QgsEditorWidgetWrapper::showIndeterminateState ( )
inlinevirtual

◆ updateConstraint() [1/2]

void QgsEditorWidgetWrapper::updateConstraint ( const QgsFeature featureContext,
QgsFieldConstraints::ConstraintOrigin  constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet 
)

Update constraint.

Parameters
featureContextthe feature to use to evaluate the constraint
constraintOriginoptional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.
Since
QGIS 2.16

Definition at line 132 of file qgseditorwidgetwrapper.cpp.

◆ updateConstraint() [2/2]

void QgsEditorWidgetWrapper::updateConstraint ( const QgsVectorLayer layer,
int  index,
const QgsFeature feature,
QgsFieldConstraints::ConstraintOrigin  constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet 
)

Update constraint on a feature coming from a specific layer.

Parameters
layerThe vector layer where the feature is defined
indexThe index of the field to check
featureThe feature to use to evaluate the constraint
constraintOriginOptional origin for constraints to check. This can be used to limit the constraints tested to only provider or layer based constraints.
Since
QGIS 3.0

Definition at line 137 of file qgseditorwidgetwrapper.cpp.

◆ updateConstraintWidgetStatus()

void QgsEditorWidgetWrapper::updateConstraintWidgetStatus ( )
protectedvirtual

This should update the widget with a visual cue if a constraint status changed.

By default a stylesheet will be applied on the widget that changes the background color to red.

This can be overwritten in subclasses to allow individual widgets to change the visual cue.

Since
QGIS 2.16

Reimplemented in QgsRelationReferenceWidgetWrapper.

Definition at line 80 of file qgseditorwidgetwrapper.cpp.

◆ value()

virtual QVariant QgsEditorWidgetWrapper::value ( ) const
pure virtual

Will be used to access the widget's value.

Read the value from the widget and return it properly formatted to be saved in the attribute.

If an invalid variant is returned this will be interpreted as no change. Be sure to return a NULL QVariant if it should be set to NULL.

Returns
The current value the widget represents

Implemented in QgsValueRelationWidgetWrapper, QgsDateTimeEditWrapper, QgsRangeWidgetWrapper, QgsCheckboxWidgetWrapper, QgsExternalResourceWidgetWrapper, QgsTextEditWrapper, QgsValueMapWidgetWrapper, QgsRelationReferenceWidgetWrapper, QgsUniqueValuesWidgetWrapper, QgsBinaryWidgetWrapper, QgsUuidWidgetWrapper, QgsClassificationWidgetWrapper, QgsColorWidgetWrapper, QgsEnumerationWidgetWrapper, QgsKeyValueWidgetWrapper, QgsListWidgetWrapper, and QgsHiddenWidgetWrapper.

◆ valueChanged

void QgsEditorWidgetWrapper::valueChanged ( const QVariant &  value)
signal

Emit this signal, whenever the value changed.

Parameters
valueThe new value

Property Documentation

◆ constraintResult

QgsEditorWidgetWrapper::ConstraintResult QgsEditorWidgetWrapper::constraintResult
read

Definition at line 47 of file qgseditorwidgetwrapper.h.

◆ constraintResultVisible

bool QgsEditorWidgetWrapper::constraintResultVisible
readwrite

Definition at line 46 of file qgseditorwidgetwrapper.h.


The documentation for this class was generated from the following files: