QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 "qgseditorwidgetconfig.h"
28 #include "qgswidgetwrapper.h"
29 
41 class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
42 {
43  Q_OBJECT
44  public:
53  explicit QgsEditorWidgetWrapper( QgsVectorLayer* vl, int fieldIdx, QWidget* editor = nullptr, QWidget* parent = nullptr );
54 
64  virtual QVariant value() const = 0;
65 
73  int fieldIdx() const;
74 
82  QgsField field() const;
83 
91  QVariant defaultValue() const;
92 
98  static QgsEditorWidgetWrapper* fromWidget( QWidget* widget );
99 
106  virtual void setEnabled( bool enabled ) override;
107 
111  virtual void showIndeterminateState() {}
112 
118  void updateConstraint( const QgsFeature &featureContext );
119 
126  bool isValidConstraint() const;
127 
128  signals:
134  void valueChanged( const QVariant& value );
135 
144  void constraintStatusChanged( const QString& constraint, const QString &desc, const QString& err, bool status );
145 
146  public slots:
154  void setFeature( const QgsFeature& feature ) override;
155 
162  virtual void setValue( const QVariant& value ) = 0;
163 
164  protected slots:
171  void valueChanged( const QString& value );
172 
180  void valueChanged( int value );
181 
189  void valueChanged( double value );
190 
198  void valueChanged( bool value );
199 
206  void valueChanged( qlonglong value );
207 
211  void valueChanged();
212 
213  protected:
228  virtual void updateConstraintWidgetStatus( bool constraintValid );
229 
230  private:
231 
235  bool mValidConstraint;
236 
237  int mFieldIdx;
238  QgsFeature mFeature;
239  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
240 };
241 
242 // We'll use this class inside a QVariant in the widgets properties
244 
245 #endif // QGSEDITORWIDGETWRAPPER_H
virtual void setEnabled(bool enabled)
Is used to enable or disable the edit functionality of the managed widget.
Manages an editor widget Widget and wrapper share the same parent.
Q_DECLARE_METATYPE(QgsMimeDataUtils::UriList)
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
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:44
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.