QGIS API Documentation  2.99.0-Master (b698612)
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  void setEnabled( bool enabled ) override;
126 
130  virtual void showIndeterminateState() {}
131 
139  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
140 
149  bool isValidConstraint() const;
150 
157  bool isBlockingCommit() const;
158 
165  QString constraintFailureReason() const;
166 
167  signals:
168 
174  void valueChanged( const QVariant &value );
175 
184  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, ConstraintResult status );
185 
186  public slots:
187 
195  virtual void setFeature( const QgsFeature &feature ) override;
196 
203  virtual void setValue( const QVariant &value ) = 0;
204 
211  void valueChanged( const QString &value );
212 
220 #ifndef SIP_RUN
221  void valueChanged( int value );
222 #else
223  void valueChanged( int value ) SIP_PYNAME( valueChangedInt );
224 #endif
225 
233 #ifndef SIP_RUN
234  void valueChanged( double value );
235 #else
236  void valueChanged( double value ) SIP_PYNAME( valueChangedDouble );
237 #endif
238 
246 #ifndef SIP_RUN
247  void valueChanged( bool value );
248 #else
249  void valueChanged( bool value ) SIP_PYNAME( valueChangedBool );
250 #endif
251 
258  void valueChanged( qlonglong value );
259 
263  void valueChanged();
264 
265  protected:
266 
281  virtual void updateConstraintWidgetStatus( ConstraintResult status );
282 
283  private:
284 
288  bool mValidConstraint;
289 
291  bool mIsBlockingCommit;
292 
294  QString mConstraintFailureReason;
295 
296  int mFieldIdx;
297  QgsFeature mFeature;
298  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
299 
300 };
301 
302 // We'll use this class inside a QVariant in the widgets properties
304 
305 #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:34
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:62