QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
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:
55
65
74 explicit QgsEditorWidgetWrapper( QgsVectorLayer *vl, int fieldIdx, QWidget *editor = nullptr, QWidget *parent SIP_TRANSFERTHIS = nullptr );
75
85 virtual QVariant value() const = 0;
86
91 virtual QStringList additionalFields() const {return QStringList();}
92
99 virtual QVariantList additionalFieldValues() const {return QVariantList();}
100
108 int fieldIdx() const;
109
117 QgsField field() const;
118
126 QVariant defaultValue() const;
127
133 static QgsEditorWidgetWrapper *fromWidget( QWidget *widget );
134
140 static bool isInTable( const QWidget *parent );
141
148 void setEnabled( bool enabled ) override;
149
153 virtual void showIndeterminateState() {}
154
161 void updateConstraint( const QgsFeature &featureContext, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
162
172 void updateConstraint( const QgsVectorLayer *layer, int index, const QgsFeature &feature, QgsFieldConstraints::ConstraintOrigin constraintOrigin = QgsFieldConstraints::ConstraintOriginNotSet );
173
180 void updateConstraint( QgsEditorWidgetWrapper::ConstraintResult constraintResult, const QString &constraintFailureReason );
181
189 bool isValidConstraint() const;
190
196 bool isBlockingCommit() const;
197
203 QString constraintFailureReason() const;
204
209 virtual void setHint( const QString &hintText );
210
216 ConstraintResult constraintResult() const;
217
225 bool constraintResultVisible() const;
226
235 void setConstraintResultVisible( bool constraintResultVisible );
236
237 signals:
238
245 Q_DECL_DEPRECATED void valueChanged( const QVariant &value );
246
255 void valuesChanged( const QVariant &value, const QVariantList &additionalFieldValues = QVariantList() );
256
265 void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, QgsEditorWidgetWrapper::ConstraintResult status );
266
270 void constraintResultVisibleChanged( bool visible );
271
272 public slots:
273
281 void setFeature( const QgsFeature &feature ) override;
282
283 // TODO Q_DECL_DEPRECATED
284
292 virtual void setValue( const QVariant &value ) SIP_DEPRECATED;
293
300 void setValues( const QVariant &value, const QVariantList &additionalValues );
301
305 void emitValueChanged();
306
318 virtual void parentFormValueChanged( const QString &attribute, const QVariant &value );
319
320 protected:
321
333 virtual void updateConstraintWidgetStatus();
334
335
342 QgsFeature formFeature() const { return mFormFeature; }
343
349 void setFormFeature( const QgsFeature &feature ) { mFormFeature = feature; }
350
358 bool setFormFeatureAttribute( const QString &attributeName, const QVariant &attributeValue );
359
360 private:
361
371 virtual void updateValues( const QVariant &value, const QVariantList &additionalValues = QVariantList() ); //TODO QGIS 4: make it pure virtual
372
373 // TODO QGIS 4: remove
374 bool isRunningDeprecatedSetValue = false;
375
379 int mFieldIdx = -1;
380
381 QList<int> mAdditionalFieldIndexes;
382
386 QgsFeature mFormFeature;
387
391 bool mValidConstraint;
392
394 bool mIsBlockingCommit;
395
397 QString mConstraintFailureReason;
398
400 ConstraintResult mConstraintResult = ConstraintResultPass;
401
403 bool mConstraintResultVisible = false;
404
405 mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
406
407};
408
409// We'll use this class inside a QVariant in the widgets properties
411
412#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)