QGIS API Documentation  3.6.0-Noosa (5873452)
qgseditorwidgetwrapper.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgseditorwidgetwrapper.h
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 #ifndef QGSEDITORWIDGETWRAPPER_H
17 #define QGSEDITORWIDGETWRAPPER_H
18 
19 #include <QObject>
20 #include "qgis_sip.h"
21 #include <QMap>
22 #include <QVariant>
23 
24 class QgsVectorLayer;
25 class QgsField;
26 
27 #include "qgswidgetwrapper.h"
28 #include "qgis_gui.h"
29 
42 class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
43 {
44  Q_OBJECT
45 
46  Q_PROPERTY( bool constraintResultVisible READ constraintResultVisible WRITE setConstraintResultVisible NOTIFY constraintResultVisibleChanged )
47  Q_PROPERTY( ConstraintResult constraintResult READ constraintResult NOTIFY constraintStatusChanged )
48 
49  public:
50 
56  {
57  ConstraintResultPass = 0,
60  };
61 
70  explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
71 
81  virtual QVariant value() const = 0;
82 
90  int fieldIdx() const;
91 
99  QgsField field() const;
100 
108  QVariant defaultValue() const;
109 
115  static QgsEditorWidgetWrapper *fromWidget( QWidget *widget );
116 
122  static bool isInTable( const QWidget *parent );
123 
130  void setEnabled( bool enabled ) override;
131 
136  virtual void showIndeterminateState() {}
137 
145  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
146 
157  void updateConstraint( const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
158 
167  bool isValidConstraint() const;
168 
175  bool isBlockingCommit() const;
176 
183  QString constraintFailureReason() const;
184 
190  virtual void setHint( const QString &hintText );
191 
198  ConstraintResult constraintResult() const;
199 
208  bool constraintResultVisible() const;
209 
219  void setConstraintResultVisible( bool constraintResultVisible );
220 
221  signals:
222 
228  void valueChanged( const QVariant &value );
229 
238  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status );
239 
243  void constraintResultVisibleChanged( bool visible );
244 
245  public slots:
246 
254  void setFeature( const QgsFeature &feature ) override;
255 
262  virtual void setValue( const QVariant &value ) = 0;
263 
267  void emitValueChanged();
268 
269  protected:
270 
283  virtual void updateConstraintWidgetStatus();
284 
285 
292  QgsFeature formFeature() const { return mFormFeature; }
293 
299  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
300 
308  bool setFormFeatureAttribute( const QString &attributeName, const QVariant &attributeValue );
309 
310 
311  private:
312 
316  int mFieldIdx = -1;
317 
321  QgsFeature mFormFeature;
322 
326  bool mValidConstraint;
327 
329  bool mIsBlockingCommit;
330 
332  QString mConstraintFailureReason;
333 
335  ConstraintResult mConstraintResult = ConstraintResultPass;
336 
338  bool mConstraintResultVisible = false;
339 
340  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
341 
342 };
343 
344 // We'll use this class inside a QVariant in the widgets properties
346 
347 #endif // QGSEDITORWIDGETWRAPPER_H
virtual void setEnabled(bool enabled)
Is used to enable or disable the edit functionality of the managed widget.
Widget failed at least one soft (non-enforced) constraint.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:46
Manages an editor widget Widget and wrapper share the same parent.
ConstraintOrigin
Origin of constraints.
void setFormFeature(const QgsFeature &feature)
Set the feature currently being edited to feature.
Widget failed at least one hard (enforced) constraint.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Q_DECLARE_METATYPE(QModelIndex)
virtual void setFeature(const QgsFeature &feature)=0
Is called, when the value of the widget needs to be changed.
virtual void showIndeterminateState()
Sets the widget to display in an indeterminate "mixed value" state.
QgsFeature formFeature() const
The feature currently being edited, in its current state.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:48
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
ConstraintResult
Result of constraint checks.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.