31#include <QStackedWidget>
34#include "moc_qgsattributeformeditorwidget.cpp"
36using namespace Qt::StringLiterals;
40 , mWidgetType( widgetType )
45 mRememberLastValueButton =
new QToolButton();
46 mRememberLastValueButton->setAutoRaise(
true );
47 mRememberLastValueButton->setCheckable(
true );
49 mRememberLastValueButton->setToolTip( tr(
"When enabled, the entered value will be remembered and reused for the next feature additions" ) );
50 updateRememberWidget();
52 connect( mRememberLastValueButton, &QAbstractButton::toggled,
this, [
this](
bool checked ) {
53 mRememberLastValueButton->setIcon(
QgsApplication::getThemeIcon( checked ? u
"/mIconRememberEnabled.svg"_s : u
"/mIconRememberDisabled.svg"_s ) );
58 mConstraintResultLabel =
new QLabel();
59 mConstraintResultLabel->setObjectName( u
"ConstraintStatus"_s );
60 mConstraintResultLabel->setSizePolicy( QSizePolicy::Fixed, mConstraintResultLabel->sizePolicy().verticalPolicy() );
61 mConstraintResultLabel->setAlignment( Qt::AlignCenter );
62 mConstraintResultLabel->setFixedWidth( 24 );
65 mAggregateButton->setType( mEditorWidget->field().type() );
68 if ( mEditorWidget->widget() )
70 mEditorWidget->widget()->setObjectName( mEditorWidget->field().name() );
75 mMultiEditButton->setField( mEditorWidget->field() );
85 delete mMultiEditButton;
86 delete mRememberLastValueButton;
87 delete mConstraintResultLabel;
92 Q_ASSERT( !mWidgetType.isEmpty() );
93 const QVariantMap config = mEditorWidget->config();
94 const int fieldIdx = mEditorWidget->fieldIdx();
112 mConstraintResultLabel->setText( u
"<font color=\"#FF9800\">%1</font>"_s.arg( QChar( 0x2718 ) ) );
113 mConstraintResultLabel->setToolTip( description.isEmpty() ? u
"<b>%1</b>: %2"_s.arg( constraint, err ) : description );
117 mConstraintResultLabel->setText( u
"<font color=\"#FFC107\">%1</font>"_s.arg( QChar( 0x2718 ) ) );
118 mConstraintResultLabel->setToolTip( description.isEmpty() ? u
"<b>%1</b>: %2"_s.arg( constraint, err ) : description );
122 mConstraintResultLabel->setText( u
"<font color=\"#259B24\">%1</font>"_s.arg( QChar( 0x2714 ) ) );
123 mConstraintResultLabel->setToolTip( description );
130 mIsConstraintResultVisible = editable;
144 const bool hasConstraintResultLabel = (
editPage()->layout()->indexOf( mConstraintResultLabel ) >= 0 );
145 if ( editable && !hasConstraintResultLabel )
147 editPage()->layout()->addWidget( mConstraintResultLabel );
149 else if ( !editable && hasConstraintResultLabel )
151 editPage()->layout()->removeWidget( mConstraintResultLabel );
152 mConstraintResultLabel->setParent(
nullptr );
159 return mEditorWidget;
164 if ( mEditorWidget && mixed )
166 mMultiEditButton->setIsMixed( mixed );
172 mRememberLastValueButton->setChecked( remember );
173 mRememberLastValueButton->setIcon(
QgsApplication::getThemeIcon( remember ? u
"/mIconRememberEnabled.svg"_s : u
"/mIconRememberDisabled.svg"_s ) );
180 mPreviousValue = mEditorWidget->value();
181 mPreviousAdditionalValues = mEditorWidget->additionalFieldValues();
185 mMultiEditButton->changesCommitted();
194 mBlockValueUpdate =
true;
195 mEditorWidget->setValues( initialValue, additionalFieldValues );
196 mBlockValueUpdate =
false;
198 mPreviousValue = initialValue;
199 mPreviousAdditionalValues = additionalFieldValues;
201 mMultiEditButton->setIsChanged(
false );
208 return mEditorWidget->value();
212void QgsAttributeFormEditorWidget::editorWidgetValuesChanged(
const QVariant &value,
const QVariantList &additionalFieldValues )
214 if ( mBlockValueUpdate )
235void QgsAttributeFormEditorWidget::resetValue()
238 mBlockValueUpdate =
true;
240 mEditorWidget->setValues( mPreviousValue, mPreviousAdditionalValues );
241 mBlockValueUpdate =
false;
251 mMultiEditButton->setIsChanged(
false );
252 if ( mEditorWidget && mIsMixed )
253 mEditorWidget->showIndeterminateState();
259void QgsAttributeFormEditorWidget::setFieldTriggered()
264void QgsAttributeFormEditorWidget::onAggregateChanged()
267 for ( QgsSearchWidgetWrapper *searchWidget : constWigets )
268 searchWidget->setAggregate( mAggregateButton->aggregate() );
271void QgsAttributeFormEditorWidget::updateRememberWidget()
273 const bool hasRememberButton = (
editPage()->layout()->indexOf( mRememberLastValueButton ) >= 0 );
274 const int idx = mEditorWidget->fieldIdx();
279 editPage()->layout()->addWidget( mRememberLastValueButton );
282 else if ( hasRememberButton )
284 editPage()->layout()->removeWidget( mRememberLastValueButton );
285 mRememberLastValueButton->setParent(
nullptr );
289void QgsAttributeFormEditorWidget::updateWidgets()
292 const bool hasMultiEditButton = (
editPage()->layout()->indexOf( mMultiEditButton ) >= 0 );
294 bool shouldShowMultiEditButton =
false;
301 shouldShowMultiEditButton =
false;
312 const int fieldIndex = mEditorWidget->fieldIdx();
314 if ( shouldShowMultiEditButton )
321 if ( fieldEditabilityDependsOnFeature )
331 shouldShowMultiEditButton =
false;
342 if ( hasMultiEditButton && !shouldShowMultiEditButton )
344 editPage()->layout()->removeWidget( mMultiEditButton );
345 mMultiEditButton->setParent(
nullptr );
347 else if ( !hasMultiEditButton && shouldShowMultiEditButton )
349 editPage()->layout()->addWidget( mMultiEditButton );
359 if ( mIsConstraintResultVisible &&
editPage()->layout()->indexOf( mConstraintResultLabel ) == -1 )
363 editPage()->layout()->addWidget( mConstraintResultLabel );
371 mAggregateButton->setVisible(
true );
377 mAggregateButton->setVisible(
false );
@ NotAllowed
Reuse of last values not allowed.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Contains context information for attribute editor widgets.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
static QgsEditorWidgetRegistry * editorWidgetRegistry()
Returns the global editor widget registry, used for managing all known edit widget factories.
static bool fieldIsEditable(const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature, QgsVectorLayerUtils::FieldIsEditableFlags flags=QgsVectorLayerUtils::FieldIsEditableFlags())
Tests whether a field is editable for a particular feature.
static bool fieldEditabilityDependsOnFeature(const QgsVectorLayer *layer, int fieldIndex)
Returns true if the editability of the field at index fieldIndex from layer may vary feature by featu...
static bool attributeHasConstraints(const QgsVectorLayer *layer, int attributeIndex)
Returns true if a feature attribute has active constraints.
static bool fieldIsReadOnly(const QgsVectorLayer *layer, int fieldIndex)
Returns true if the field at index fieldIndex from layer is editable, false if the field is read only...
QgsFeatureIterator getSelectedFeatures(QgsFeatureRequest request=QgsFeatureRequest()) const
Returns an iterator of the selected features.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH