28 , mFieldIdx( fieldIdx )
29 , mValidConstraint( true )
30 , mIsBlockingCommit( false )
42 if ( vl && mFieldIdx < vl->fields().count() )
60 return qobject_cast<QgsEditorWidgetWrapper *>(
widget->property(
"EWV2Wrapper" ).value<
QgsWidgetWrapper *>() );
68 wdg->setEnabled( enabled );
75 QVariantList newAdditionalFieldValues;
77 for (
const QString &fieldName : constAdditionalFields )
78 newAdditionalFieldValues << feature.
attribute( fieldName );
84 isRunningDeprecatedSetValue =
true;
85 updateValues(
value, QVariantList() );
86 isRunningDeprecatedSetValue =
false;
91 updateValues(
value, additionalValues );
104 Q_UNUSED( attribute )
110 if ( !mConstraintResultVisible )
112 widget()->setStyleSheet( QString() );
116 switch ( mConstraintResult )
119 widget()->setStyleSheet( QString() );
123 widget()->setStyleSheet( QStringLiteral(
"background-color: #FFE0B2;" ) );
127 widget()->setStyleSheet( QStringLiteral(
"background-color: #FFECB3;" ) );
135 return mFormFeature.
setAttribute( attributeName, attributeValue );
138void QgsEditorWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList &additionalValues )
141 Q_UNUSED( additionalValues );
144 if ( !isRunningDeprecatedSetValue )
151 return mConstraintResult;
156 return mConstraintResultVisible;
179 QStringList softErrors;
180 QStringList expressions;
181 QStringList descriptions;
182 bool toEmit(
false );
183 bool hardConstraintsOk(
true );
184 bool softConstraintsOk(
true );
191 if ( ! expression.isEmpty() )
193 expressions << expression;
200 descriptions << tr(
"Not NULL" );
201 if ( !expression.isEmpty() )
203 expressions <<
field.
name() + QStringLiteral(
" IS NOT NULL" );
207 expressions << QStringLiteral(
"IS NOT NULL" );
214 descriptions << tr(
"Unique" );
215 if ( !expression.isEmpty() )
217 expressions <<
field.
name() + QStringLiteral(
" IS UNIQUE" );
221 expressions << QStringLiteral(
"IS UNIQUE" );
229 errors << softErrors;
233 if ( ! expression.isEmpty() )
235 hardConstraintsOk =
true;
236 softConstraintsOk =
false;
238 errors << QStringLiteral(
"Invalid feature" );
244 mValidConstraint = hardConstraintsOk && softConstraintsOk;
245 mIsBlockingCommit = !hardConstraintsOk;
247 mConstraintFailureReason = errors.join( QLatin1String(
", " ) );
251 const QString errStr = errors.isEmpty() ? tr(
"Constraint checks passed" ) : mConstraintFailureReason;
253 const QString description = descriptions.join( QLatin1String(
", " ) );
254 QString expressionDesc;
255 if ( expressions.size() > 1 )
256 expressionDesc =
"( " + expressions.join( QLatin1String(
" ) AND ( " ) ) +
" )";
257 else if ( !expressions.isEmpty() )
258 expressionDesc = expressions.at( 0 );
263 mConstraintResult = result;
271 return mValidConstraint;
276 return mIsBlockingCommit;
282 return mConstraintFailureReason;
287 if ( !parent )
return false;
288 if ( qobject_cast<const QTableView *>( parent ) )
return true;
289 return isInTable( parent->parentWidget() );
294 if ( QWidget *w =
widget() )
295 w->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.
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 a feature attribute value to check whether it passes all constraints which are present on the c...
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