31#include <QStackedWidget>
33#include "moc_qgsattributeformeditorwidget.cpp"
37 , mWidgetType( widgetType )
42 mRememberLastValueButton =
new QToolButton();
43 mRememberLastValueButton->setAutoRaise(
true );
44 mRememberLastValueButton->setCheckable(
true );
46 mRememberLastValueButton->setToolTip( tr(
"When enabled, the entered value will be remembered and reused for the next feature additions" ) );
47 updateRememberWidget();
49 connect( mRememberLastValueButton, &QAbstractButton::toggled,
this, [
this](
bool checked ) {
50 mRememberLastValueButton->setIcon(
QgsApplication::getThemeIcon( checked ? QStringLiteral(
"/mIconRememberEnabled.svg" ) : QStringLiteral(
"/mIconRememberDisabled.svg" ) ) );
54 updateRememberWidget();
57 mConstraintResultLabel =
new QLabel();
58 mConstraintResultLabel->setObjectName( QStringLiteral(
"ConstraintStatus" ) );
59 mConstraintResultLabel->setSizePolicy( QSizePolicy::Fixed, mConstraintResultLabel->sizePolicy().verticalPolicy() );
60 mConstraintResultLabel->setAlignment( Qt::AlignCenter );
61 mConstraintResultLabel->setFixedWidth( 24 );
64 mAggregateButton->setType( mEditorWidget->field().type() );
67 if ( mEditorWidget->widget() )
69 mEditorWidget->widget()->setObjectName( mEditorWidget->field().name() );
74 mMultiEditButton->setField( mEditorWidget->field() );
84 delete mMultiEditButton;
85 delete mRememberLastValueButton;
86 delete mConstraintResultLabel;
91 Q_ASSERT( !mWidgetType.isEmpty() );
92 const QVariantMap config = mEditorWidget->config();
93 const int fieldIdx = mEditorWidget->fieldIdx();
111 mConstraintResultLabel->setText( QStringLiteral(
"<font color=\"#FF9800\">%1</font>" ).arg( QChar( 0x2718 ) ) );
112 mConstraintResultLabel->setToolTip( description.isEmpty() ? QStringLiteral(
"<b>%1</b>: %2" ).arg( constraint, err ) : description );
116 mConstraintResultLabel->setText( QStringLiteral(
"<font color=\"#FFC107\">%1</font>" ).arg( QChar( 0x2718 ) ) );
117 mConstraintResultLabel->setToolTip( description.isEmpty() ? QStringLiteral(
"<b>%1</b>: %2" ).arg( constraint, err ) : description );
121 mConstraintResultLabel->setText( QStringLiteral(
"<font color=\"#259B24\">%1</font>" ).arg( QChar( 0x2714 ) ) );
122 mConstraintResultLabel->setToolTip( description );
129 mIsConstraintResultVisible = editable;
143 const bool hasConstraintResultLabel = (
editPage()->layout()->indexOf( mConstraintResultLabel ) >= 0 );
144 if ( editable && !hasConstraintResultLabel )
146 editPage()->layout()->addWidget( mConstraintResultLabel );
148 else if ( !editable && hasConstraintResultLabel )
150 editPage()->layout()->removeWidget( mConstraintResultLabel );
151 mConstraintResultLabel->setParent(
nullptr );
158 return mEditorWidget;
163 if ( mEditorWidget && mixed )
165 mMultiEditButton->setIsMixed( mixed );
171 mRememberLastValueButton->setChecked( remember );
172 mRememberLastValueButton->setIcon(
QgsApplication::getThemeIcon( remember ? QStringLiteral(
"/mIconRememberEnabled.svg" ) : QStringLiteral(
"/mIconRememberDisabled.svg" ) ) );
179 mPreviousValue = mEditorWidget->value();
180 mPreviousAdditionalValues = mEditorWidget->additionalFieldValues();
184 mMultiEditButton->changesCommitted();
193 mBlockValueUpdate =
true;
194 mEditorWidget->setValues( initialValue, additionalFieldValues );
195 mBlockValueUpdate =
false;
197 mPreviousValue = initialValue;
198 mPreviousAdditionalValues = additionalFieldValues;
200 mMultiEditButton->setIsChanged(
false );
207 return mEditorWidget->value();
211void QgsAttributeFormEditorWidget::editorWidgetValuesChanged(
const QVariant &value,
const QVariantList &additionalFieldValues )
213 if ( mBlockValueUpdate )
234void QgsAttributeFormEditorWidget::resetValue()
237 mBlockValueUpdate =
true;
239 mEditorWidget->setValues( mPreviousValue, mPreviousAdditionalValues );
240 mBlockValueUpdate =
false;
250 mMultiEditButton->setIsChanged(
false );
251 if ( mEditorWidget && mIsMixed )
252 mEditorWidget->showIndeterminateState();
258void QgsAttributeFormEditorWidget::setFieldTriggered()
263void QgsAttributeFormEditorWidget::onAggregateChanged()
266 for ( QgsSearchWidgetWrapper *searchWidget : constWigets )
267 searchWidget->setAggregate( mAggregateButton->aggregate() );
270void QgsAttributeFormEditorWidget::updateRememberWidget()
272 const bool hasRememberButton = (
editPage()->layout()->indexOf( mRememberLastValueButton ) >= 0 );
273 const int idx = mEditorWidget->fieldIdx();
278 editPage()->layout()->addWidget( mRememberLastValueButton );
281 else if ( hasRememberButton )
283 editPage()->layout()->removeWidget( mRememberLastValueButton );
284 mRememberLastValueButton->setParent(
nullptr );
288void QgsAttributeFormEditorWidget::updateWidgets()
291 const bool hasMultiEditButton = (
editPage()->layout()->indexOf( mMultiEditButton ) >= 0 );
293 bool shouldShowMultiEditButton =
false;
300 shouldShowMultiEditButton =
false;
311 const int fieldIndex = mEditorWidget->fieldIdx();
313 if ( shouldShowMultiEditButton )
320 if ( fieldEditabilityDependsOnFeature )
330 shouldShowMultiEditButton =
false;
341 if ( hasMultiEditButton && !shouldShowMultiEditButton )
343 editPage()->layout()->removeWidget( mMultiEditButton );
344 mMultiEditButton->setParent(
nullptr );
346 else if ( !hasMultiEditButton && shouldShowMultiEditButton )
348 editPage()->layout()->addWidget( mMultiEditButton );
358 if ( mIsConstraintResultVisible &&
editPage()->layout()->indexOf( mConstraintResultLabel ) == -1 )
362 editPage()->layout()->addWidget( mConstraintResultLabel );
370 mAggregateButton->setVisible(
true );
376 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 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 fieldIsEditable(const QgsVectorLayer *layer, int fieldIndex, const QgsFeature &feature)
Tests whether a field is editable for a particular feature.
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