28 , mFieldIdx( fieldIdx )
29 , mValidConstraint( true )
30 , mIsBlockingCommit( false )
42 if ( vl && mFieldIdx < vl->fields().count() )
57 return qobject_cast<QgsEditorWidgetWrapper *>(
widget->property(
"EWV2Wrapper" ).value<
QgsWidgetWrapper *>() );
65 wdg->setEnabled( enabled );
72 QVariantList newAdditionalFieldValues;
74 for (
const QString &fieldName : constAdditionalFields )
75 newAdditionalFieldValues << feature.
attribute( fieldName );
81 isRunningDeprecatedSetValue =
true;
82 updateValues(
value, QVariantList() );
83 isRunningDeprecatedSetValue =
false;
88 updateValues(
value, additionalValues );
101 Q_UNUSED( attribute )
107 if ( !mConstraintResultVisible )
109 widget()->setStyleSheet( QString() );
113 switch ( mConstraintResult )
116 widget()->setStyleSheet( QString() );
120 widget()->setStyleSheet( QStringLiteral(
"background-color: #FFE0B2;" ) );
124 widget()->setStyleSheet( QStringLiteral(
"background-color: #FFECB3;" ) );
132 return mFormFeature.
setAttribute( attributeName, attributeValue );
135 void QgsEditorWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList &additionalValues )
138 Q_UNUSED( additionalValues );
141 if ( !isRunningDeprecatedSetValue )
148 return mConstraintResult;
153 return mConstraintResultVisible;
176 QStringList softErrors;
177 QStringList expressions;
178 QStringList descriptions;
179 bool toEmit(
false );
180 bool hardConstraintsOk(
true );
181 bool softConstraintsOk(
true );
188 if ( ! expression.isEmpty() )
190 expressions << expression;
197 descriptions << tr(
"Not NULL" );
198 if ( !expression.isEmpty() )
200 expressions <<
field.
name() + QStringLiteral(
" IS NOT NULL" );
204 expressions << QStringLiteral(
"IS NOT NULL" );
211 descriptions << tr(
"Unique" );
212 if ( !expression.isEmpty() )
214 expressions <<
field.
name() + QStringLiteral(
" IS UNIQUE" );
218 expressions << QStringLiteral(
"IS UNIQUE" );
226 errors << softErrors;
230 if ( ! expression.isEmpty() )
232 hardConstraintsOk =
true;
233 softConstraintsOk =
false;
235 errors << QStringLiteral(
"Invalid feature" );
241 mValidConstraint = hardConstraintsOk && softConstraintsOk;
242 mIsBlockingCommit = !hardConstraintsOk;
244 mConstraintFailureReason = errors.join( QLatin1String(
", " ) );
248 QString errStr = errors.isEmpty() ? tr(
"Constraint checks passed" ) : mConstraintFailureReason;
250 QString description = descriptions.join( QLatin1String(
", " ) );
251 QString expressionDesc;
252 if ( expressions.size() > 1 )
253 expressionDesc =
"( " + expressions.join( QLatin1String(
" ) AND ( " ) ) +
" )";
254 else if ( !expressions.isEmpty() )
255 expressionDesc = expressions.at( 0 );
260 mConstraintResult = result;
268 return mValidConstraint;
273 return mIsBlockingCommit;
279 return mConstraintFailureReason;
284 if ( !parent )
return false;
285 if ( qobject_cast<const QTableView *>( parent ) )
return true;
286 return isInTable( parent->parentWidget() );
291 widget()->setToolTip( hintText );
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
bool isValid() const
Returns the validity of this feature.
QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
@ ConstraintStrengthSoft
User is warned if constraint is violated but feature can still be accepted.
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
ConstraintOrigin
Origin of constraints.
QString constraintExpression() const
Returns the constraint expression for the field, if set.
@ ConstraintNotNull
Field may not be null.
@ ConstraintUnique
Field must have a unique value.
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
Q_GADGET Constraints constraints
Encapsulate a field in an attribute table or data source.
QgsFieldConstraints constraints
QgsField at(int i) const
Returns the field at particular index (must be in range 0..N-1).
virtual QString defaultValueClause(int fieldIndex) const
Returns any default value clauses which are present at the provider for a specified field index.
static bool validateAttribute(const QgsVectorLayer *layer, const QgsFeature &feature, int attributeIndex, QStringList &errors, QgsFieldConstraints::ConstraintStrength strength=QgsFieldConstraints::ConstraintStrengthNotSet, QgsFieldConstraints::ConstraintOrigin origin=QgsFieldConstraints::ConstraintOriginNotSet)
Tests an attribute value to check whether it passes all constraints which are present on the correspo...
Represents a vector layer which manages a vector based data sets.
QgsFields fields() const FINAL
Returns the list of fields of this layer.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH