28#include "moc_qgseditorwidgetwrapper.cpp"
30using namespace Qt::StringLiterals;
45 if ( vl && mFieldIdx < vl->fields().count() )
54 mDefaultValue = defaultValueClause.isEmpty() ? QVariant() : defaultValueClause;
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() );
128 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
134 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
139#if QT_VERSION >= QT_VERSION_CHECK( 6, 9, 0 ) && QT_VERSION < QT_VERSION_CHECK( 6, 10, 0 )
147 return mFormFeature.setAttribute( attributeName, attributeValue );
150void QgsEditorWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList &additionalValues )
153 Q_UNUSED( additionalValues );
156 if ( !isRunningDeprecatedSetValue )
163 return mConstraintResult;
168 return mConstraintResultVisible;
191 QStringList softErrors;
192 QStringList expressions;
193 QStringList descriptions;
194 bool toEmit(
false );
195 bool hardConstraintsOk(
true );
196 bool softConstraintsOk(
true );
199 const QString expression =
field.constraints().constraintExpression();
203 if ( !expression.isEmpty() )
205 expressions << expression;
206 descriptions <<
field.constraints().constraintDescription();
212 descriptions << tr(
"Not NULL" );
213 if ( !expression.isEmpty() )
215 expressions <<
field.name() + u
" IS NOT NULL"_s;
219 expressions << u
"IS NOT NULL"_s;
226 descriptions << tr(
"Unique" );
227 if ( !expression.isEmpty() )
229 expressions <<
field.name() + u
" IS UNIQUE"_s;
233 expressions << u
"IS UNIQUE"_s;
241 errors << softErrors;
245 if ( !expression.isEmpty() )
247 hardConstraintsOk =
true;
248 softConstraintsOk =
false;
250 errors << u
"Invalid feature"_s;
256 mValidConstraint = hardConstraintsOk && softConstraintsOk;
257 mIsBlockingCommit = !hardConstraintsOk;
259 mConstraintFailureReason = errors.join(
", "_L1 );
263 const QString errStr = errors.isEmpty() ? tr(
"Constraint checks passed" ) : mConstraintFailureReason;
265 const QString description = descriptions.join(
", "_L1 );
266 QString expressionDesc;
267 if ( expressions.size() > 1 )
268 expressionDesc =
"( " + expressions.join(
" ) AND ( "_L1 ) +
" )";
269 else if ( !expressions.isEmpty() )
270 expressionDesc = expressions.at( 0 );
274 mConstraintResult = result;
291 return mValidConstraint;
296 return mIsBlockingCommit;
302 return mConstraintFailureReason;
309 if ( qobject_cast<const QTableView *>( parent ) )
311 return isInTable( parent->parentWidget() );
316 if ( QWidget *w =
widget() )
317 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