QGIS API Documentation  3.0.2-Girona (307d082)
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.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 
197  ConstraintResult constraintResult() const;
198 
205  bool constraintResultVisible() const;
206 
214  void setConstraintResultVisible( bool constraintResultVisible );
215 
216  signals:
217 
223  void valueChanged( const QVariant &value );
224 
233  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status );
234 
238  void constraintResultVisibleChanged( bool visible );
239 
240  public slots:
241 
249  void setFeature( const QgsFeature &feature ) override;
250 
257  virtual void setValue( const QVariant &value ) = 0;
258 
262  void emitValueChanged();
263 
264  protected:
265 
278  virtual void updateConstraintWidgetStatus();
279 
280  private:
281 
285  bool mValidConstraint;
286 
288  bool mIsBlockingCommit;
289 
291  QString mConstraintFailureReason;
292 
294  ConstraintResult mConstraintResult = ConstraintResultPass;
295 
297  bool mConstraintResultVisible = false;
298 
299  int mFieldIdx;
300  QgsFeature mFeature;
301  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
302 
303 };
304 
305 // We'll use this class inside a QVariant in the widgets properties
307 
308 #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.
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:62
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.
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.