28#include "moc_qgseditorwidgetwrapper.cpp"
30using namespace Qt::StringLiterals;
46 if ( vl && mFieldIdx < vl->fields().count() )
64 return qobject_cast<QgsEditorWidgetWrapper *>(
widget->property(
"EWV2Wrapper" ).value<
QgsWidgetWrapper *>() );
72 wdg->setEnabled( enabled );
79 QVariantList newAdditionalFieldValues;
81 for (
const QString &fieldName : constAdditionalFields )
82 newAdditionalFieldValues << feature.
attribute( fieldName );
88 isRunningDeprecatedSetValue =
true;
89 updateValues(
value, QVariantList() );
90 isRunningDeprecatedSetValue =
false;
95 updateValues(
value, additionalValues );
108 Q_UNUSED( attribute )
114 if ( !mConstraintResultVisible )
116 widget()->setStyleSheet( QString() );
120 switch ( mConstraintResult )
123 widget()->setStyleSheet( QString() );
127 widget()->setStyleSheet( 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 );
131 widget()->setStyleSheet( 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 );
135#if QT_VERSION >= QT_VERSION_CHECK( 6, 9, 0 ) && QT_VERSION < QT_VERSION_CHECK( 6, 10, 0 )
143 return mFormFeature.setAttribute( attributeName, attributeValue );
146void QgsEditorWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList &additionalValues )
149 Q_UNUSED( additionalValues );
152 if ( !isRunningDeprecatedSetValue )
159 return mConstraintResult;
164 return mConstraintResultVisible;
187 QStringList softErrors;
188 QStringList expressions;
189 QStringList descriptions;
190 bool toEmit(
false );
191 bool hardConstraintsOk(
true );
192 bool softConstraintsOk(
true );
195 const QString expression =
field.constraints().constraintExpression();
199 if ( !expression.isEmpty() )
201 expressions << expression;
202 descriptions <<
field.constraints().constraintDescription();
208 descriptions << tr(
"Not NULL" );
209 if ( !expression.isEmpty() )
211 expressions <<
field.name() + u
" IS NOT NULL"_s;
215 expressions << u
"IS NOT NULL"_s;
222 descriptions << tr(
"Unique" );
223 if ( !expression.isEmpty() )
225 expressions <<
field.name() + u
" IS UNIQUE"_s;
229 expressions << u
"IS UNIQUE"_s;
237 errors << softErrors;
241 if ( !expression.isEmpty() )
243 hardConstraintsOk =
true;
244 softConstraintsOk =
false;
246 errors << u
"Invalid feature"_s;
252 mValidConstraint = hardConstraintsOk && softConstraintsOk;
253 mIsBlockingCommit = !hardConstraintsOk;
255 mConstraintFailureReason = errors.join(
", "_L1 );
259 const QString errStr = errors.isEmpty() ? tr(
"Constraint checks passed" ) : mConstraintFailureReason;
261 const QString description = descriptions.join(
", "_L1 );
262 QString expressionDesc;
263 if ( expressions.size() > 1 )
264 expressionDesc =
"( " + expressions.join(
" ) AND ( "_L1 ) +
" )";
265 else if ( !expressions.isEmpty() )
266 expressionDesc = expressions.at( 0 );
271 mConstraintResult = result;
288 return mValidConstraint;
293 return mIsBlockingCommit;
299 return mConstraintFailureReason;
306 if ( qobject_cast<const QTableView *>( parent ) )
308 return isInTable( parent->parentWidget() );
313 if ( QWidget *w =
widget() )
314 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