QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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:
64
73 explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
74
84 virtual QVariant value() const = 0;
85
90 virtual QStringList additionalFields() const { return QStringList(); }
91
98 virtual QVariantList additionalFieldValues() const { return QVariantList(); }
99
107 int fieldIdx() const;
108
116 QgsField field() const;
117
125 QVariant defaultValue() const;
126
132 static QgsEditorWidgetWrapper *fromWidget( QWidget *widget ); // cppcheck-suppress duplInheritedMember
133
139 static bool isInTable( const QWidget *parent );
140
147 void setEnabled( bool enabled ) override;
148
152 virtual void showIndeterminateState() {}
153
160 void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
161
171 void updateConstraint( const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
172
179 void updateConstraint( QgsEditorWidgetWrapper::ConstraintResult constraintResult, const QString &constraintFailureReason );
180
188 bool isValidConstraint() const;
189
195 bool isBlockingCommit() const;
196
202 QString constraintFailureReason() const;
203
208 virtual void setHint( const QString &hintText );
209
215 ConstraintResult constraintResult() const;
216
224 bool constraintResultVisible() const;
225
234 void setConstraintResultVisible( bool constraintResultVisible );
235
236 signals:
237
244 Q_DECL_DEPRECATED void valueChanged( const QVariant &value );
245
254 void valuesChanged( const QVariant &value, const QVariantList &additionalFieldValues = QVariantList() );
255
264 void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status );
265
269 void constraintResultVisibleChanged( bool visible );
270
271 public slots:
272
280 void setFeature( const QgsFeature &feature ) override;
281
282 // TODO Q_DECL_DEPRECATED
283
291 virtual void setValue( const QVariant &value ) SIP_DEPRECATED;
292
299 void setValues( const QVariant &value, const QVariantList &additionalValues );
300
304 void emitValueChanged();
305
317 virtual void parentFormValueChanged( const QString &attribute, const QVariant &value );
318
319 protected:
331 virtual void updateConstraintWidgetStatus();
332
333
340 QgsFeature formFeature() const { return mFormFeature; }
341
347 void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
348
356 bool setFormFeatureAttribute( const QString &attributeName, const QVariant &attributeValue );
357
358 private:
368 virtual void updateValues( const QVariant &value, const QVariantList &additionalValues = QVariantList() ); //TODO QGIS 4: make it pure virtual
369
370 // TODO QGIS 4: remove
371 bool isRunningDeprecatedSetValue = false;
372
376 int mFieldIdx = -1;
377
378 QList<int> mAdditionalFieldIndexes;
379
383 QgsFeature mFormFeature;
384
388 bool mValidConstraint;
389
391 bool mIsBlockingCommit;
392
394 QString mConstraintFailureReason;
395
397 ConstraintResult mConstraintResult = ConstraintResultPass;
398
400 bool mConstraintResultVisible = false;
401
402 mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
403};
404
405// We'll use this class inside a QVariant in the widgets properties
407
408#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:58
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)