31#include <QStackedWidget>
33#include "moc_qgsattributeformeditorwidget.cpp"
37 , mWidgetType( widgetType )
41 , mBlockValueUpdate( false )
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 ? QStringLiteral(
"/mIconRememberEnabled.svg" ) : QStringLiteral(
"/mIconRememberDisabled.svg" ) ) );
57 updateRememberWidget();
60 mConstraintResultLabel =
new QLabel();
61 mConstraintResultLabel->setObjectName( QStringLiteral(
"ConstraintStatus" ) );
62 mConstraintResultLabel->setSizePolicy( QSizePolicy::Fixed, mConstraintResultLabel->sizePolicy().verticalPolicy() );
63 mConstraintResultLabel->setAlignment( Qt::AlignCenter );
64 mConstraintResultLabel->setFixedWidth( 24 );
67 mAggregateButton->setType( mEditorWidget->field().type() );
70 if ( mEditorWidget->widget() )
72 mEditorWidget->widget()->setObjectName( mEditorWidget->field().name() );
77 mMultiEditButton->setField( mEditorWidget->field() );
87 delete mMultiEditButton;
88 delete mRememberLastValueButton;
89 delete mConstraintResultLabel;
94 Q_ASSERT( !mWidgetType.isEmpty() );
95 const QVariantMap config = mEditorWidget->config();
96 const int fieldIdx = mEditorWidget->fieldIdx();
114 mConstraintResultLabel->setText( QStringLiteral(
"<font color=\"#FF9800\">%1</font>" ).arg( QChar( 0x2718 ) ) );
115 mConstraintResultLabel->setToolTip( description.isEmpty() ? QStringLiteral(
"<b>%1</b>: %2" ).arg( constraint, err ) : description );
119 mConstraintResultLabel->setText( QStringLiteral(
"<font color=\"#FFC107\">%1</font>" ).arg( QChar( 0x2718 ) ) );
120 mConstraintResultLabel->setToolTip( description.isEmpty() ? QStringLiteral(
"<b>%1</b>: %2" ).arg( constraint, err ) : description );
124 mConstraintResultLabel->setText( QStringLiteral(
"<font color=\"#259B24\">%1</font>" ).arg( QChar( 0x2714 ) ) );
125 mConstraintResultLabel->setToolTip( description );
132 mIsConstraintResultVisible = editable;
146 const bool hasConstraintResultLabel = (
editPage()->layout()->indexOf( mConstraintResultLabel ) >= 0 );
147 if ( editable && !hasConstraintResultLabel )
149 editPage()->layout()->addWidget( mConstraintResultLabel );
151 else if ( !editable && hasConstraintResultLabel )
153 editPage()->layout()->removeWidget( mConstraintResultLabel );
154 mConstraintResultLabel->setParent(
nullptr );
161 return mEditorWidget;
166 if ( mEditorWidget && mixed )
168 mMultiEditButton->setIsMixed( mixed );
174 mRememberLastValueButton->setChecked( remember );
175 mRememberLastValueButton->setIcon(
QgsApplication::getThemeIcon( remember ? QStringLiteral(
"/mIconRememberEnabled.svg" ) : QStringLiteral(
"/mIconRememberDisabled.svg" ) ) );
182 mPreviousValue = mEditorWidget->value();
183 mPreviousAdditionalValues = mEditorWidget->additionalFieldValues();
187 mMultiEditButton->changesCommitted();
196 mBlockValueUpdate =
true;
197 mEditorWidget->setValues( initialValue, additionalFieldValues );
198 mBlockValueUpdate =
false;
200 mPreviousValue = initialValue;
201 mPreviousAdditionalValues = additionalFieldValues;
203 mMultiEditButton->setIsChanged(
false );
210 return mEditorWidget->value();
214void QgsAttributeFormEditorWidget::editorWidgetValuesChanged(
const QVariant &value,
const QVariantList &additionalFieldValues )
216 if ( mBlockValueUpdate )
237void QgsAttributeFormEditorWidget::resetValue()
240 mBlockValueUpdate =
true;
242 mEditorWidget->setValues( mPreviousValue, mPreviousAdditionalValues );
243 mBlockValueUpdate =
false;
253 mMultiEditButton->setIsChanged(
false );
254 if ( mEditorWidget && mIsMixed )
255 mEditorWidget->showIndeterminateState();
261void QgsAttributeFormEditorWidget::setFieldTriggered()
266void QgsAttributeFormEditorWidget::onAggregateChanged()
269 for ( QgsSearchWidgetWrapper *searchWidget : constWigets )
270 searchWidget->setAggregate( mAggregateButton->aggregate() );
273void QgsAttributeFormEditorWidget::updateRememberWidget()
275 const bool hasRememberButton = (
editPage()->layout()->indexOf( mRememberLastValueButton ) >= 0 );
276 const int idx = mEditorWidget->fieldIdx();
281 editPage()->layout()->addWidget( mRememberLastValueButton );
284 else if ( hasRememberButton )
286 editPage()->layout()->removeWidget( mRememberLastValueButton );
287 mRememberLastValueButton->setParent(
nullptr );
291void QgsAttributeFormEditorWidget::updateWidgets()
294 const bool hasMultiEditButton = (
editPage()->layout()->indexOf( mMultiEditButton ) >= 0 );
296 bool shouldShowMultiEditButton =
false;
303 shouldShowMultiEditButton =
false;
314 const int fieldIndex = mEditorWidget->fieldIdx();
316 if ( shouldShowMultiEditButton )
323 if ( fieldEditabilityDependsOnFeature )
333 shouldShowMultiEditButton =
false;
344 if ( hasMultiEditButton && !shouldShowMultiEditButton )
346 editPage()->layout()->removeWidget( mMultiEditButton );
347 mMultiEditButton->setParent(
nullptr );
349 else if ( !hasMultiEditButton && shouldShowMultiEditButton )
351 editPage()->layout()->addWidget( mMultiEditButton );
361 if ( mIsConstraintResultVisible &&
editPage()->layout()->indexOf( mConstraintResultLabel ) == -1 )
365 editPage()->layout()->addWidget( mConstraintResultLabel );
373 mAggregateButton->setVisible(
true );
379 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