QGIS API Documentation  3.9.0-Master (224899f119)
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 #include "qgis_sip.h"
30 
46 class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
47 {
48  Q_OBJECT
49 
50  Q_PROPERTY( bool constraintResultVisible READ constraintResultVisible WRITE setConstraintResultVisible NOTIFY constraintResultVisibleChanged )
51  Q_PROPERTY( ConstraintResult constraintResult READ constraintResult NOTIFY constraintStatusChanged )
52 
53  public:
54 
60  {
61  ConstraintResultPass = 0,
64  };
65 
74  explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
75 
85  virtual QVariant value() const = 0;
86 
91  virtual QStringList additionalFields() const {return QStringList();}
92 
99  virtual QVariantList additionalFieldValues() const {return QVariantList();}
100 
108  int fieldIdx() const;
109 
117  QgsField field() const;
118 
126  QVariant defaultValue() const;
127 
133  static QgsEditorWidgetWrapper *fromWidget( QWidget *widget );
134 
140  static bool isInTable( const QWidget *parent );
141 
148  void setEnabled( bool enabled ) override;
149 
154  virtual void showIndeterminateState() {}
155 
163  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
164 
175  void updateConstraint( const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
176 
185  bool isValidConstraint() const;
186 
193  bool isBlockingCommit() const;
194 
201  QString constraintFailureReason() const;
202 
208  virtual void setHint( const QString &hintText );
209 
216  ConstraintResult constraintResult() const;
217 
226  bool constraintResultVisible() const;
227 
237  void setConstraintResultVisible( bool constraintResultVisible );
238 
239  signals:
240 
247  Q_DECL_DEPRECATED void valueChanged( const QVariant &value );
248 
257  void valuesChanged( const QVariant &value, const QVariantList &additionalFieldValues = QVariantList() );
258 
267  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status );
268 
272  void constraintResultVisibleChanged( bool visible );
273 
274  public slots:
275 
283  void setFeature( const QgsFeature &feature ) override;
284 
292  // TODO Q_DECL_DEPRECATED
293  virtual void setValue( const QVariant &value ) SIP_DEPRECATED;
294 
301  void setValues( const QVariant &value, const QVariantList &additionalValues );
302 
306  void emitValueChanged();
307 
308  protected:
309 
322  virtual void updateConstraintWidgetStatus();
323 
324 
331  QgsFeature formFeature() const { return mFormFeature; }
332 
338  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
339 
347  bool setFormFeatureAttribute( const QString &attributeName, const QVariant &attributeValue );
348 
349 
350  private:
351 
361  virtual void updateValues( const QVariant &value, const QVariantList &additionalValues = QVariantList() ); //TODO QGIS 4: make it pure virtual
362 
363  // TODO QGIS 4: remove
364  bool isRunningDeprecatedSetValue = false;
365 
369  int mFieldIdx = -1;
370 
371  QList<int> mAdditionalFieldIndexes;
372 
376  QgsFeature mFormFeature;
377 
381  bool mValidConstraint;
382 
384  bool mIsBlockingCommit;
385 
387  QString mConstraintFailureReason;
388 
390  ConstraintResult mConstraintResult = ConstraintResultPass;
391 
393  bool mConstraintResultVisible = false;
394 
395  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
396 
397 };
398 
399 // We'll use this class inside a QVariant in the widgets properties
401 
402 #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:53
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
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.
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
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
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
ConstraintResult
Result of constraint checks.
virtual QVariantList additionalFieldValues() const
Will be used to access the widget&#39;s values for potential additional fields handled by the widget...
virtual QStringList additionalFields() const
Returns the list of additional fields which the editor handles.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.