17#include "moc_qgseditorwidgetwrapper.cpp"
29 , mFieldIdx( fieldIdx )
30 , mValidConstraint( true )
31 , mIsBlockingCommit( false )
43 if ( vl && mFieldIdx < vl->fields().count() )
61 return qobject_cast<QgsEditorWidgetWrapper *>(
widget->property(
"EWV2Wrapper" ).value<
QgsWidgetWrapper *>() );
69 wdg->setEnabled( enabled );
76 QVariantList newAdditionalFieldValues;
78 for (
const QString &fieldName : constAdditionalFields )
79 newAdditionalFieldValues << feature.
attribute( fieldName );
85 isRunningDeprecatedSetValue =
true;
86 updateValues(
value, QVariantList() );
87 isRunningDeprecatedSetValue =
false;
92 updateValues(
value, additionalValues );
105 Q_UNUSED( attribute )
111 if ( !mConstraintResultVisible )
113 widget()->setStyleSheet( QString() );
117 switch ( mConstraintResult )
120 widget()->setStyleSheet( QString() );
124 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); }" ) );
128 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); }" ) );
136 return mFormFeature.
setAttribute( attributeName, attributeValue );
139void QgsEditorWidgetWrapper::updateValues(
const QVariant &value,
const QVariantList &additionalValues )
142 Q_UNUSED( additionalValues );
145 if ( !isRunningDeprecatedSetValue )
152 return mConstraintResult;
157 return mConstraintResultVisible;
180 QStringList softErrors;
181 QStringList expressions;
182 QStringList descriptions;
183 bool toEmit(
false );
184 bool hardConstraintsOk(
true );
185 bool softConstraintsOk(
true );
192 if ( !expression.isEmpty() )
194 expressions << expression;
201 descriptions << tr(
"Not NULL" );
202 if ( !expression.isEmpty() )
204 expressions <<
field.
name() + QStringLiteral(
" IS NOT NULL" );
208 expressions << QStringLiteral(
"IS NOT NULL" );
215 descriptions << tr(
"Unique" );
216 if ( !expression.isEmpty() )
218 expressions <<
field.
name() + QStringLiteral(
" IS UNIQUE" );
222 expressions << QStringLiteral(
"IS UNIQUE" );
230 errors << softErrors;
234 if ( !expression.isEmpty() )
236 hardConstraintsOk =
true;
237 softConstraintsOk =
false;
239 errors << QStringLiteral(
"Invalid feature" );
245 mValidConstraint = hardConstraintsOk && softConstraintsOk;
246 mIsBlockingCommit = !hardConstraintsOk;
248 mConstraintFailureReason = errors.join( QLatin1String(
", " ) );
252 const QString errStr = errors.isEmpty() ? tr(
"Constraint checks passed" ) : mConstraintFailureReason;
254 const QString description = descriptions.join( QLatin1String(
", " ) );
255 QString expressionDesc;
256 if ( expressions.size() > 1 )
257 expressionDesc =
"( " + expressions.join( QLatin1String(
" ) AND ( " ) ) +
" )";
258 else if ( !expressions.isEmpty() )
259 expressionDesc = expressions.at( 0 );
264 mConstraintResult = result;
281 return mValidConstraint;
286 return mIsBlockingCommit;
292 return mConstraintFailureReason;
299 if ( qobject_cast<const QTableView *>( parent ) )
301 return isInTable( parent->parentWidget() );
306 if ( QWidget *w =
widget() )
307 w->setToolTip( hintText );
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Q_INVOKABLE bool setAttribute(int field, const QVariant &attr)
Sets an attribute's value by field index.
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.
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.
QgsVectorDataProvider * dataProvider() FINAL
Returns the layer's data provider, it may be nullptr.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH