QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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_sip.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 #include "qgis_sip.h"
30 
31 
47 class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
48 {
49  Q_OBJECT
50 
51  Q_PROPERTY( bool constraintResultVisible READ constraintResultVisible WRITE setConstraintResultVisible NOTIFY constraintResultVisibleChanged )
52  Q_PROPERTY( ConstraintResult constraintResult READ constraintResult NOTIFY constraintStatusChanged )
53 
54  public:
55 
61  {
62  ConstraintResultPass = 0,
65  };
66 
75  explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
76 
86  virtual QVariant value() const = 0;
87 
92  virtual QStringList additionalFields() const {return QStringList();}
93 
100  virtual QVariantList additionalFieldValues() const {return QVariantList();}
101 
109  int fieldIdx() const;
110 
118  QgsField field() const;
119 
127  QVariant defaultValue() const;
128 
134  static QgsEditorWidgetWrapper *fromWidget( QWidget *widget );
135 
141  static bool isInTable( const QWidget *parent );
142 
149  void setEnabled( bool enabled ) override;
150 
155  virtual void showIndeterminateState() {}
156 
164  void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
165 
176  void updateConstraint( const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
177 
186  bool isValidConstraint() const;
187 
194  bool isBlockingCommit() const;
195 
202  QString constraintFailureReason() const;
203 
209  virtual void setHint( const QString &hintText );
210 
217  ConstraintResult constraintResult() const;
218 
227  bool constraintResultVisible() const;
228 
238  void setConstraintResultVisible( bool constraintResultVisible );
239 
240  signals:
241 
248  Q_DECL_DEPRECATED void valueChanged( const QVariant &value );
249 
258  void valuesChanged( const QVariant &value, const QVariantList &additionalFieldValues = QVariantList() );
259 
268  void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status );
269 
273  void constraintResultVisibleChanged( bool visible );
274 
275  public slots:
276 
284  void setFeature( const QgsFeature &feature ) override;
285 
293  // TODO Q_DECL_DEPRECATED
294  virtual void setValue( const QVariant &value ) SIP_DEPRECATED;
295 
302  void setValues( const QVariant &value, const QVariantList &additionalValues );
303 
307  void emitValueChanged();
308 
320  virtual void parentFormValueChanged( const QString &attribute, const QVariant &value );
321 
322  protected:
323 
336  virtual void updateConstraintWidgetStatus();
337 
338 
345  QgsFeature formFeature() const { return mFormFeature; }
346 
352  void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
353 
361  bool setFormFeatureAttribute( const QString &attributeName, const QVariant &attributeValue );
362 
363  private:
364 
374  virtual void updateValues( const QVariant &value, const QVariantList &additionalValues = QVariantList() ); //TODO QGIS 4: make it pure virtual
375 
376  // TODO QGIS 4: remove
377  bool isRunningDeprecatedSetValue = false;
378 
382  int mFieldIdx = -1;
383 
384  QList<int> mAdditionalFieldIndexes;
385 
389  QgsFeature mFormFeature;
390 
394  bool mValidConstraint;
395 
397  bool mIsBlockingCommit;
398 
400  QString mConstraintFailureReason;
401 
403  ConstraintResult mConstraintResult = ConstraintResultPass;
404 
406  bool mConstraintResultVisible = false;
407 
408  mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
409 
410 };
411 
412 // We'll use this class inside a QVariant in the widgets properties
414 
415 #endif // QGSEDITORWIDGETWRAPPER_H
QgsWidgetWrapper
Definition: qgswidgetwrapper.h:52
QgsEditorWidgetWrapper::ConstraintResultFailHard
@ ConstraintResultFailHard
Widget failed at least one hard (enforced) constraint.
Definition: qgseditorwidgetwrapper.h:63
QgsEditorWidgetWrapper::additionalFieldValues
virtual QVariantList additionalFieldValues() const
Will be used to access the widget's values for potential additional fields handled by the widget.
Definition: qgseditorwidgetwrapper.h:100
QgsWidgetWrapper::fromWidget
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
Definition: qgswidgetwrapper.cpp:96
QgsEditorWidgetWrapper::ConstraintResult
ConstraintResult
Result of constraint checks.
Definition: qgseditorwidgetwrapper.h:60
QgsEditorWidgetWrapper::additionalFields
virtual QStringList additionalFields() const
Returns the list of additional fields which the editor handles.
Definition: qgseditorwidgetwrapper.h:92
QgsEditorWidgetWrapper
Definition: qgseditorwidgetwrapper.h:47
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsWidgetWrapper::setEnabled
virtual void setEnabled(bool enabled)
Is used to enable or disable the edit functionality of the managed widget.
Definition: qgswidgetwrapper.cpp:111
QgsFieldConstraints::ConstraintOrigin
ConstraintOrigin
Origin of constraints.
Definition: qgsfieldconstraints.h:54
qgis_sip.h
QgsEditorWidgetWrapper::setFormFeature
void setFormFeature(const QgsFeature &feature)
Set the feature currently being edited to feature.
Definition: qgseditorwidgetwrapper.h:352
QgsWidgetWrapper::setFeature
virtual void setFeature(const QgsFeature &feature)=0
Is called, when the value of the widget needs to be changed.
QgsFieldConstraints::ConstraintOriginNotSet
@ ConstraintOriginNotSet
Constraint is not set.
Definition: qgsfieldconstraints.h:56
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsEditorWidgetWrapper::ConstraintResultFailSoft
@ ConstraintResultFailSoft
Widget failed at least one soft (non-enforced) constraint.
Definition: qgseditorwidgetwrapper.h:64
qgswidgetwrapper.h
QgsFeature
Definition: qgsfeature.h:55
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsEditorWidgetWrapper::showIndeterminateState
virtual void showIndeterminateState()
Sets the widget to display in an indeterminate "mixed value" state.
Definition: qgseditorwidgetwrapper.h:155
QgsField
Definition: qgsfield.h:49
QgsEditorWidgetWrapper::formFeature
QgsFeature formFeature() const
The feature currently being edited, in its current state.
Definition: qgseditorwidgetwrapper.h:345