QGIS API Documentation  2.99.0-Master (25b0421)
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  public:
46 
52  {
53  ConstraintResultPass = 0,
56  };
57 
66  explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent SIP_TRANSFERTHIS = 0 );
67 
77  virtual QVariant value() const = 0;
78 
86  int fieldIdx() const;
87 
95  QgsField field() const;
96 
104  QVariant defaultValue() const;
105 
111  static QgsEditorWidgetWrapper *fromWidget( QWidget *widget );
112 
118  static bool isInTable( const QWidget *parent );
119 
126  virtual void setEnabled( bool enabled ) override;
127 
132  virtual void showIndeterminateState() {}
133 
141  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
142 
153  void updateConstraint( const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
154 
163  bool isValidConstraint() const;
164 
171  bool isBlockingCommit() const;
172 
179  QString constraintFailureReason() const;
180 
186  virtual void setHint( const QString &hintText );
187 
188  signals:
189 
195  void valueChanged( const QVariant &value );
196 
205  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, ConstraintResult status );
206 
207  public slots:
208 
216  virtual void setFeature( const QgsFeature &feature ) override;
217 
224  virtual void setValue( const QVariant &value ) = 0;
225 
232  void valueChanged( const QString &value );
233 
241 #ifndef SIP_RUN
242  void valueChanged( int value );
243 #else
244  void valueChanged( int value ) SIP_PYNAME( valueChangedInt );
245 #endif
246 
254 #ifndef SIP_RUN
255  void valueChanged( double value );
256 #else
257  void valueChanged( double value ) SIP_PYNAME( valueChangedDouble );
258 #endif
259 
267 #ifndef SIP_RUN
268  void valueChanged( bool value );
269 #else
270  void valueChanged( bool value ) SIP_PYNAME( valueChangedBool );
271 #endif
272 
279  void valueChanged( qlonglong value );
280 
284  void valueChanged();
285 
286  protected:
287 
302  virtual void updateConstraintWidgetStatus( ConstraintResult status );
303 
304  private:
305 
309  bool mValidConstraint;
310 
312  bool mIsBlockingCommit;
313 
315  QString mConstraintFailureReason;
316 
317  int mFieldIdx;
318  QgsFeature mFeature;
319  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
320 
321 };
322 
323 // We'll use this class inside a QVariant in the widgets properties
325 
326 #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.
#define SIP_PYNAME(name)
Definition: qgis_sip.h:74