QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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
24class QgsVectorLayer;
25class QgsField;
26
27#include "qgswidgetwrapper.h"
28#include "qgis_gui.h"
29#include "qgis_sip.h"
30
31
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
286 // TODO Q_DECL_DEPRECATED
287
295 virtual void setValue( const QVariant &value ) SIP_DEPRECATED;
296
303 void setValues( const QVariant &value, const QVariantList &additionalValues );
304
308 void emitValueChanged();
309
321 virtual void parentFormValueChanged( const QString &attribute, const QVariant &value );
322
323 protected:
324
337 virtual void updateConstraintWidgetStatus();
338
339
346 QgsFeature formFeature() const { return mFormFeature; }
347
353 void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
354
362 bool setFormFeatureAttribute( const QString &attributeName, const QVariant &attributeValue );
363
364 private:
365
375 virtual void updateValues( const QVariant &value, const QVariantList &additionalValues = QVariantList() ); //TODO QGIS 4: make it pure virtual
376
377 // TODO QGIS 4: remove
378 bool isRunningDeprecatedSetValue = false;
379
383 int mFieldIdx = -1;
384
385 QList<int> mAdditionalFieldIndexes;
386
390 QgsFeature mFormFeature;
391
395 bool mValidConstraint;
396
398 bool mIsBlockingCommit;
399
401 QString mConstraintFailureReason;
402
404 ConstraintResult mConstraintResult = ConstraintResultPass;
405
407 bool mConstraintResultVisible = false;
408
409 mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
410
411};
412
413// We'll use this class inside a QVariant in the widgets properties
415
416#endif // QGSEDITORWIDGETWRAPPER_H
Manages an editor widget Widget and wrapper share the same parent.
QgsFeature formFeature() const
The feature currently being edited, in its current state.
Q_DECL_DEPRECATED void valueChanged(const QVariant &value)
Emit this signal, whenever the value changed.
void setFormFeature(const QgsFeature &feature)
Set the feature currently being edited to feature.
virtual QVariant value() const =0
Will be used to access the widget's value.
virtual QVariantList additionalFieldValues() const
Will be used to access the widget's values for potential additional fields handled by the widget.
virtual void showIndeterminateState()
Sets the widget to display in an indeterminate "mixed value" state.
virtual QStringList additionalFields() const
Returns the list of additional fields which the editor handles.
void constraintResultVisibleChanged(bool visible)
Emit this signal when the constraint result visibility changed.
void valuesChanged(const QVariant &value, const QVariantList &additionalFieldValues=QVariantList())
Emit this signal, whenever the value changed.
ConstraintResult
Result of constraint checks.
@ ConstraintResultFailSoft
Widget failed at least one soft (non-enforced) constraint.
@ ConstraintResultFailHard
Widget failed at least one hard (enforced) constraint.
void constraintStatusChanged(const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status)
Emit this signal when the constraint status changed.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
ConstraintOrigin
Origin of constraints.
@ ConstraintOriginNotSet
Constraint is not set.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:53
Represents a vector layer which manages a vector based data sets.
Manages an editor widget Widget and wrapper share the same parent.
virtual void setFeature(const QgsFeature &feature)=0
Is called when the value of the widget needs to be changed.
static QgsWidgetWrapper * fromWidget(QWidget *widget)
Will return a wrapper for a given widget.
virtual void setEnabled(bool enabled)
Is used to enable or disable the edit functionality of the managed widget.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Q_DECLARE_METATYPE(QgsDatabaseQueryLogEntry)
const QgsField & field
Definition: qgsfield.h:554