QGIS API Documentation  2.99.0-Master (6a61179)
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 <QMap>
21 #include <QVariant>
22 
23 class QgsVectorLayer;
24 class QgsField;
25 
26 #include "qgswidgetwrapper.h"
27 
39 class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
40 {
41  Q_OBJECT
42  public:
43 
49  {
50  ConstraintResultPass = 0,
53  };
54 
63  explicit QgsEditorWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor = nullptr, QWidget* parent = nullptr );
64 
74  virtual QVariant value() const = 0;
75 
83  int fieldIdx() const;
84 
92  QgsField field() const;
93 
101  QVariant defaultValue() const;
102 
108  static QgsEditorWidgetWrapper* fromWidget( QWidget* widget );
109 
115  static bool isInTable( const QWidget* parent );
116 
123  void setEnabled( bool enabled ) override;
124 
128  virtual void showIndeterminateState() {}
129 
137  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
138 
147  bool isValidConstraint() const;
148 
155  bool isBlockingCommit() const;
156 
163  QString constraintFailureReason() const;
164 
165  signals:
166 
172  void valueChanged( const QVariant& value );
173 
182  void constraintStatusChanged( const QString& constraint, const QString &desc, const QString& err, ConstraintResult status );
183 
184  public slots:
185 
193  void setFeature( const QgsFeature& feature ) override;
194 
201  virtual void setValue( const QVariant& value ) = 0;
202 
203  protected slots:
204 
211  void valueChanged( const QString& value );
212 
220  void valueChanged( int value );
221 
229  void valueChanged( double value );
230 
238  void valueChanged( bool value );
239 
246  void valueChanged( qlonglong value );
247 
251  void valueChanged();
252 
253  protected:
254 
269  virtual void updateConstraintWidgetStatus( ConstraintResult status );
270 
271  private:
272 
276  bool mValidConstraint;
277 
279  bool mIsBlockingCommit;
280 
282  QString mConstraintFailureReason;
283 
284  int mFieldIdx;
285  QgsFeature mFeature;
286  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
287 };
288 
289 // We'll use this class inside a QVariant in the widgets properties
291 
292 #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.
Manages an editor widget Widget and wrapper share the same parent.
ConstraintOrigin
Origin of constraints.
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
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:135
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:47
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.