QGIS API Documentation  2.99.0-Master (314842d)
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 #include "qgis_gui.h"
28 
40 class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
41 {
42  Q_OBJECT
43  public:
44 
50  {
51  ConstraintResultPass = 0,
54  };
55 
64  explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent = nullptr );
65 
75  virtual QVariant value() const = 0;
76 
84  int fieldIdx() const;
85 
93  QgsField field() const;
94 
102  QVariant defaultValue() const;
103 
109  static QgsEditorWidgetWrapper *fromWidget( QWidget *widget );
110 
116  static bool isInTable( const QWidget *parent );
117 
124  void setEnabled( bool enabled ) override;
125 
129  virtual void showIndeterminateState() {}
130 
138  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
139 
148  bool isValidConstraint() const;
149 
156  bool isBlockingCommit() const;
157 
164  QString constraintFailureReason() const;
165 
166  signals:
167 
173  void valueChanged( const QVariant &value );
174 
183  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, ConstraintResult status );
184 
185  public slots:
186 
194  virtual void setFeature( const QgsFeature &feature ) override;
195 
202  virtual void setValue( const QVariant &value ) = 0;
203 
204  protected slots:
205 
212  void valueChanged( const QString &value );
213 
221  void valueChanged( int value );
222 
230  void valueChanged( double value );
231 
239  void valueChanged( bool value );
240 
247  void valueChanged( qlonglong value );
248 
252  void valueChanged();
253 
254  protected:
255 
270  virtual void updateConstraintWidgetStatus( ConstraintResult status );
271 
272  private:
273 
277  bool mValidConstraint;
278 
280  bool mIsBlockingCommit;
281 
283  QString mConstraintFailureReason;
284 
285  int mFieldIdx;
286  QgsFeature mFeature;
287  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
288 
289 };
290 
291 // We'll use this class inside a QVariant in the widgets properties
293 
294 #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:136
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:45
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.