28#include "moc_qgseditorwidgetwrapper.cpp"
30using namespace Qt::StringLiterals;
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() );
127 u
"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); }"_s
133 u
"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); }"_s
138#if QT_VERSION >= QT_VERSION_CHECK( 6, 9, 0 ) && QT_VERSION < QT_VERSION_CHECK( 6, 10, 0 )
146 return mFormFeature.setAttribute( attributeName, attributeValue );
149void QgsEditorWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList &additionalValues )
152 Q_UNUSED( additionalValues );
155 if ( !isRunningDeprecatedSetValue )
162 return mConstraintResult;
167 return mConstraintResultVisible;
190 QStringList softErrors;
191 QStringList expressions;
192 QStringList descriptions;
193 bool toEmit(
false );
194 bool hardConstraintsOk(
true );
195 bool softConstraintsOk(
true );
198 const QString expression =
field.constraints().constraintExpression();
202 if ( !expression.isEmpty() )
204 expressions << expression;
205 descriptions <<
field.constraints().constraintDescription();
211 descriptions << tr(
"Not NULL" );
212 if ( !expression.isEmpty() )
214 expressions <<
field.name() + u
" IS NOT NULL"_s;
218 expressions << u
"IS NOT NULL"_s;
225 descriptions << tr(
"Unique" );
226 if ( !expression.isEmpty() )
228 expressions <<
field.name() + u
" IS UNIQUE"_s;
232 expressions << u
"IS UNIQUE"_s;
240 errors << softErrors;
244 if ( !expression.isEmpty() )
246 hardConstraintsOk =
true;
247 softConstraintsOk =
false;
249 errors << u
"Invalid feature"_s;
255 mValidConstraint = hardConstraintsOk && softConstraintsOk;
256 mIsBlockingCommit = !hardConstraintsOk;
258 mConstraintFailureReason = errors.join(
", "_L1 );
262 const QString errStr = errors.isEmpty() ? tr(
"Constraint checks passed" ) : mConstraintFailureReason;
264 const QString description = descriptions.join(
", "_L1 );
265 QString expressionDesc;
266 if ( expressions.size() > 1 )
267 expressionDesc =
"( " + expressions.join(
" ) AND ( "_L1 ) +
" )";
268 else if ( !expressions.isEmpty() )
269 expressionDesc = expressions.at( 0 );
273 mConstraintResult = result;
290 return mValidConstraint;
295 return mIsBlockingCommit;
301 return mConstraintFailureReason;
308 if ( qobject_cast<const QTableView *>( parent ) )
310 return isInTable( parent->parentWidget() );
315 if ( QWidget *w =
widget() )
316 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