27#include "moc_qgseditorwidgetwrapper.cpp"
32 , mValidConstraint( true )
33 , mIsBlockingCommit( false )
45 if ( vl && mFieldIdx < vl->fields().count() )
63 return qobject_cast<QgsEditorWidgetWrapper *>(
widget->property(
"EWV2Wrapper" ).value<
QgsWidgetWrapper *>() );
71 wdg->setEnabled( enabled );
78 QVariantList newAdditionalFieldValues;
80 for (
const QString &fieldName : constAdditionalFields )
81 newAdditionalFieldValues << feature.
attribute( fieldName );
87 isRunningDeprecatedSetValue =
true;
88 updateValues(
value, QVariantList() );
89 isRunningDeprecatedSetValue =
false;
94 updateValues(
value, additionalValues );
107 Q_UNUSED( attribute )
113 if ( !mConstraintResultVisible )
115 widget()->setStyleSheet( QString() );
119 switch ( mConstraintResult )
122 widget()->setStyleSheet( QString() );
126 widget()->setStyleSheet( QStringLiteral(
"QWidget { background-color: rgba(255, 150, 0, 0.3); } QCalendarWidget QWidget#qt_calendar_calendarview, QCalendarWidget QWidget#qt_calendar_navigationbar QWidget { color: rgb(0, 0, 0); background-color: rgba(255, 150, 0, 1); }" ) );
130 widget()->setStyleSheet( QStringLiteral(
"QWidget { background-color: rgba(255, 200, 45, 0.3); } QCalendarWidget QWidget#qt_calendar_calendarview, QCalendarWidget QWidget#qt_calendar_navigationbar QWidget { color: rgb(0, 0, 0); background-color: rgba(255, 200, 45, 1); }" ) );
138 return mFormFeature.setAttribute( attributeName, attributeValue );
141void QgsEditorWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList &additionalValues )
144 Q_UNUSED( additionalValues );
147 if ( !isRunningDeprecatedSetValue )
154 return mConstraintResult;
159 return mConstraintResultVisible;
182 QStringList softErrors;
183 QStringList expressions;
184 QStringList descriptions;
185 bool toEmit(
false );
186 bool hardConstraintsOk(
true );
187 bool softConstraintsOk(
true );
190 const QString expression =
field.constraints().constraintExpression();
194 if ( !expression.isEmpty() )
196 expressions << expression;
197 descriptions <<
field.constraints().constraintDescription();
203 descriptions << tr(
"Not NULL" );
204 if ( !expression.isEmpty() )
206 expressions <<
field.name() + QStringLiteral(
" IS NOT NULL" );
210 expressions << QStringLiteral(
"IS NOT NULL" );
217 descriptions << tr(
"Unique" );
218 if ( !expression.isEmpty() )
220 expressions <<
field.name() + QStringLiteral(
" IS UNIQUE" );
224 expressions << QStringLiteral(
"IS UNIQUE" );
232 errors << softErrors;
236 if ( !expression.isEmpty() )
238 hardConstraintsOk =
true;
239 softConstraintsOk =
false;
241 errors << QStringLiteral(
"Invalid feature" );
247 mValidConstraint = hardConstraintsOk && softConstraintsOk;
248 mIsBlockingCommit = !hardConstraintsOk;
250 mConstraintFailureReason = errors.join( QLatin1String(
", " ) );
254 const QString errStr = errors.isEmpty() ? tr(
"Constraint checks passed" ) : mConstraintFailureReason;
256 const QString description = descriptions.join( QLatin1String(
", " ) );
257 QString expressionDesc;
258 if ( expressions.size() > 1 )
259 expressionDesc =
"( " + expressions.join( QLatin1String(
" ) AND ( " ) ) +
" )";
260 else if ( !expressions.isEmpty() )
261 expressionDesc = expressions.at( 0 );
266 mConstraintResult = result;
283 return mValidConstraint;
288 return mIsBlockingCommit;
294 return mConstraintFailureReason;
301 if ( qobject_cast<const QTableView *>( parent ) )
303 return isInTable( parent->parentWidget() );
308 if ( QWidget *w =
widget() )
309 w->setToolTip( hintText );
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
bool isValid() const
Returns the validity of this feature.
Q_INVOKABLE 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.
@ ConstraintNotNull
Field may not be null.
@ ConstraintUnique
Field must have a unique value.
Encapsulate a field in an attribute table or data source.
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 dataset.
QgsVectorDataProvider * dataProvider() final
Returns the layer's data provider, it may be nullptr.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH