QGIS API Documentation  2.99.0-Master (7d4f81d)
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 
41 class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
42 {
43  Q_OBJECT
44  public:
45 
51  {
52  ConstraintResultPass = 0,
55  };
56 
65  explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent SIP_TRANSFERTHIS = 0 );
66 
76  virtual QVariant value() const = 0;
77 
85  int fieldIdx() const;
86 
94  QgsField field() const;
95 
103  QVariant defaultValue() const;
104 
110  static QgsEditorWidgetWrapper *fromWidget( QWidget *widget );
111 
117  static bool isInTable( const QWidget *parent );
118 
125  virtual void setEnabled( bool enabled ) override;
126 
130  virtual void showIndeterminateState() {}
131 
139  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
140 
151  void updateConstraint( const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
152 
161  bool isValidConstraint() const;
162 
169  bool isBlockingCommit() const;
170 
177  QString constraintFailureReason() const;
178 
184  virtual void setHint( const QString &hintText );
185 
186  signals:
187 
193  void valueChanged( const QVariant &value );
194 
203  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, ConstraintResult status );
204 
205  public slots:
206 
214  virtual void setFeature( const QgsFeature &feature ) override;
215 
222  virtual void setValue( const QVariant &value ) = 0;
223 
230  void valueChanged( const QString &value );
231 
239 #ifndef SIP_RUN
240  void valueChanged( int value );
241 #else
242  void valueChanged( int value ) SIP_PYNAME( valueChangedInt );
243 #endif
244 
252 #ifndef SIP_RUN
253  void valueChanged( double value );
254 #else
255  void valueChanged( double value ) SIP_PYNAME( valueChangedDouble );
256 #endif
257 
265 #ifndef SIP_RUN
266  void valueChanged( bool value );
267 #else
268  void valueChanged( bool value ) SIP_PYNAME( valueChangedBool );
269 #endif
270 
277  void valueChanged( qlonglong value );
278 
282  void valueChanged();
283 
284  protected:
285 
300  virtual void updateConstraintWidgetStatus( ConstraintResult status );
301 
302  private:
303 
307  bool mValidConstraint;
308 
310  bool mIsBlockingCommit;
311 
313  QString mConstraintFailureReason;
314 
315  int mFieldIdx;
316  QgsFeature mFeature;
317  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
318 
319 };
320 
321 // We'll use this class inside a QVariant in the widgets properties
323 
324 #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:61
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:46
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.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74