From b3e4755e2eb93f846ff3f6f6170548d9c53a4a00 Mon Sep 17 00:00:00 2001 From: signedav Date: Tue, 11 Sep 2018 12:14:20 +0200 Subject: [PATCH] Enum Mode in QgsAttributeEditorContext instead of QgsAttributeForm - because it's used on places not including QgsAttributeForm now it's able to use @form_mode in expressions of containers and QML widgets --- .../qgsattributeeditorcontext.py | 2 + .../attributetable/qgsdualview.sip.in | 2 +- .../core/qgswidgetwrapper.sip.in | 2 +- .../editorwidgets/qgsqmlwidgetwrapper.sip.in | 3 - .../gui/auto_generated/qgsactionmenu.sip.in | 2 +- .../auto_generated/qgsattributedialog.sip.in | 4 +- .../qgsattributeeditorcontext.sip.in | 14 +- .../auto_generated/qgsattributeform.sip.in | 23 +-- src/app/qgisapp.cpp | 2 +- src/app/qgisappinterface.cpp | 2 +- src/app/qgsattributetabledialog.cpp | 4 +- src/app/qgsattributetabledialog.h | 2 +- src/app/qgsfeatureaction.cpp | 6 +- src/app/qgsmaptoolfillring.cpp | 2 +- src/app/qgsselectbyformdialog.cpp | 2 +- src/gui/CMakeLists.txt | 2 +- src/gui/attributetable/qgsdualview.cpp | 6 +- src/gui/attributetable/qgsdualview.h | 2 +- src/gui/editorwidgets/core/qgswidgetwrapper.h | 2 +- src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp | 3 +- src/gui/editorwidgets/qgsqmlwidgetwrapper.h | 7 +- ...gsrelationaggregatesearchwidgetwrapper.cpp | 2 +- src/gui/qgsactionmenu.cpp | 6 +- src/gui/qgsactionmenu.h | 4 +- src/gui/qgsattributedialog.cpp | 4 +- src/gui/qgsattributedialog.h | 4 +- src/gui/qgsattributeeditorcontext.h | 22 ++- src/gui/qgsattributeform.cpp | 155 ++++++++---------- src/gui/qgsattributeform.h | 26 +-- src/gui/qgsidentifymenu.cpp | 4 +- tests/src/gui/testqgsattributeform.cpp | 16 +- 31 files changed, 154 insertions(+), 183 deletions(-) create mode 100644 python/gui/auto_additions/qgsattributeeditorcontext.py diff --git a/python/gui/auto_additions/qgsattributeeditorcontext.py b/python/gui/auto_additions/qgsattributeeditorcontext.py new file mode 100644 index 00000000000..c15adf0eb9a --- /dev/null +++ b/python/gui/auto_additions/qgsattributeeditorcontext.py @@ -0,0 +1,2 @@ +# The following has been generated automatically from src/gui/qgsattributeeditorcontext.h +QgsAttributeEditorContext.Mode.baseClass = QgsAttributeEditorContext diff --git a/python/gui/auto_generated/attributetable/qgsdualview.sip.in b/python/gui/auto_generated/attributetable/qgsdualview.sip.in index ca68a815380..9815f982943 100644 --- a/python/gui/auto_generated/attributetable/qgsdualview.sip.in +++ b/python/gui/auto_generated/attributetable/qgsdualview.sip.in @@ -240,7 +240,7 @@ Is emitted when a filter expression is set using the view. .. versionadded:: 2.16 %End - void formModeChanged( QgsAttributeForm::Mode mode ); + void formModeChanged( QgsAttributeEditorContext::Mode mode ); %Docstring Emitted when the form changes mode. diff --git a/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in b/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in index b8770398fc5..7eaa7cc3701 100644 --- a/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in +++ b/python/gui/auto_generated/editorwidgets/core/qgswidgetwrapper.sip.in @@ -171,7 +171,7 @@ might be lost. void contextChanged(); %Docstring -Signal when QgsAttributeEditorContext mContext changed after the widget wrapper has already been intialized +Signal when QgsAttributeEditorContext mContext changed .. versionadded:: 3.4 %End diff --git a/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in b/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in index 171e484a02a..2add09b09c4 100644 --- a/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in +++ b/python/gui/auto_generated/editorwidgets/qgsqmlwidgetwrapper.sip.in @@ -49,9 +49,6 @@ writes the ``qmlCode`` into a temporary file %End public slots: - - void setQmlContext(); - virtual void setFeature( const QgsFeature &feature ); diff --git a/python/gui/auto_generated/qgsactionmenu.sip.in b/python/gui/auto_generated/qgsactionmenu.sip.in index 77426124415..6765e107a54 100644 --- a/python/gui/auto_generated/qgsactionmenu.sip.in +++ b/python/gui/auto_generated/qgsactionmenu.sip.in @@ -73,7 +73,7 @@ Change the feature on which actions are performed as long as the menu is displayed and the action is running. %End - void setMode( QgsAttributeForm::Mode mode ); + void setMode( QgsAttributeEditorContext::Mode mode ); %Docstring Change the mode of the actions diff --git a/python/gui/auto_generated/qgsattributedialog.sip.in b/python/gui/auto_generated/qgsattributedialog.sip.in index 618a2687134..2cc30e2c000 100644 --- a/python/gui/auto_generated/qgsattributedialog.sip.in +++ b/python/gui/auto_generated/qgsattributedialog.sip.in @@ -50,11 +50,11 @@ Is this dialog editable? :return: returns true, if this dialog was created in an editable manner. %End - void setMode( QgsAttributeForm::Mode mode ); + void setMode( QgsAttributeEditorContext::Mode mode ); %Docstring Toggles the form mode. -:param mode: form mode. For example, if set to QgsAttributeForm.AddFeatureMode, the dialog will be editable even with an invalid feature and +:param mode: form mode. For example, if set to QgsAttributeEditorContext.AddFeatureMode, the dialog will be editable even with an invalid feature and will add a new feature when the form is accepted. %End diff --git a/python/gui/auto_generated/qgsattributeeditorcontext.sip.in b/python/gui/auto_generated/qgsattributeeditorcontext.sip.in index bbba38e3c9e..e1d9b757e7e 100644 --- a/python/gui/auto_generated/qgsattributeeditorcontext.sip.in +++ b/python/gui/auto_generated/qgsattributeeditorcontext.sip.in @@ -22,6 +22,9 @@ showing an embedded form due to relations) %TypeHeaderCode #include "qgsattributeeditorcontext.h" %End + public: + static const QMetaObject staticMetaObject; + public: enum Mode @@ -208,17 +211,24 @@ Set current ``feature`` for the currently edited form or table row .. versionadded:: 3.2 %End - QString attributeFormMode() const; + Mode attributeFormMode() const; %Docstring Returns current attributeFormMode .. versionadded:: 3.4 %End - void setAttributeFormMode( const QString &attributeFormMode ); + void setAttributeFormMode( const Mode &attributeFormMode ); %Docstring Set ``attributeFormMode`` for the edited form +.. versionadded:: 3.4 +%End + + QString attributeFormModeString( const Mode &attributeFormMode ); +%Docstring +Returns given ``attributeFormMode`` as string + .. versionadded:: 3.4 %End diff --git a/python/gui/auto_generated/qgsattributeform.sip.in b/python/gui/auto_generated/qgsattributeform.sip.in index e664c9151b9..b934d8df54c 100644 --- a/python/gui/auto_generated/qgsattributeform.sip.in +++ b/python/gui/auto_generated/qgsattributeform.sip.in @@ -19,16 +19,6 @@ class QgsAttributeForm : QWidget %End public: - enum Mode - { - SingleEditMode, - AddFeatureMode, - MultiEditMode, - SearchMode, - AggregateSearchMode, - IdentifyMode - }; - enum FilterType { ReplaceFilter, @@ -71,7 +61,7 @@ Returns if the form is currently in editable mode. :return: Editable mode of this form %End - Mode mode() const; + QgsAttributeEditorContext::Mode mode() const; %Docstring Returns the current mode of the form. @@ -80,7 +70,7 @@ Returns the current mode of the form. .. versionadded:: 2.16 %End - void setMode( Mode mode ); + void setMode( QgsAttributeEditorContext::Mode mode ); %Docstring Sets the current mode of the form. @@ -89,13 +79,6 @@ Sets the current mode of the form. .. seealso:: :py:func:`mode` .. versionadded:: 2.16 -%End - - QString modeString( Mode mode ) const; -%Docstring -Returns the context as string of ``mode`` - -.. versionadded:: 3.4 %End void setEditCommandMessage( const QString &message ); @@ -184,7 +167,7 @@ Is emitted when a filter expression is set using the form. .. versionadded:: 2.16 %End - void modeChanged( QgsAttributeForm::Mode mode ); + void modeChanged( QgsAttributeEditorContext::Mode mode ); %Docstring Emitted when the form changes mode. diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 4245e25261e..fb5a73b0dff 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -8196,7 +8196,7 @@ void QgisApp::modifyAttributesOfSelectedFeatures() context.setAllowCustomUi( false ); QgsAttributeDialog *dialog = new QgsAttributeDialog( vl, &f, false, this, true, context ); - dialog->setMode( QgsAttributeForm::MultiEditMode ); + dialog->setMode( QgsAttributeEditorContext::MultiEditMode ); dialog->exec(); } diff --git a/src/app/qgisappinterface.cpp b/src/app/qgisappinterface.cpp index 5e133520b0b..a69d771657f 100644 --- a/src/app/qgisappinterface.cpp +++ b/src/app/qgisappinterface.cpp @@ -745,7 +745,7 @@ QgsAttributeDialog *QgisAppInterface::getFeatureForm( QgsVectorLayer *l, QgsFeat QgsAttributeDialog *dialog = new QgsAttributeDialog( l, &feature, false, qgis, true, context ); if ( !feature.isValid() ) { - dialog->setMode( QgsAttributeForm::AddFeatureMode ); + dialog->setMode( QgsAttributeEditorContext::AddFeatureMode ); } return dialog; } diff --git a/src/app/qgsattributetabledialog.cpp b/src/app/qgsattributetabledialog.cpp index a1954744cf5..62835d45cd6 100644 --- a/src/app/qgsattributetabledialog.cpp +++ b/src/app/qgsattributetabledialog.cpp @@ -475,9 +475,9 @@ void QgsAttributeTableDialog::updateFieldFromExpressionSelected() runFieldCalculation( mLayer, mFieldCombo->currentField(), mUpdateExpressionText->asExpression(), filteredIds ); } -void QgsAttributeTableDialog::viewModeChanged( QgsAttributeForm::Mode mode ) +void QgsAttributeTableDialog::viewModeChanged( QgsAttributeEditorContext::Mode mode ) { - if ( mode != QgsAttributeForm::SearchMode ) + if ( mode != QgsAttributeEditorContext::SearchMode ) mActionSearchForm->setChecked( false ); } diff --git a/src/app/qgsattributetabledialog.h b/src/app/qgsattributetabledialog.h index 3bbd522d7ff..9f9ff9656b8 100644 --- a/src/app/qgsattributetabledialog.h +++ b/src/app/qgsattributetabledialog.h @@ -218,7 +218,7 @@ class APP_EXPORT QgsAttributeTableDialog : public QDialog, private Ui::QgsAttrib void runFieldCalculation( QgsVectorLayer *layer, const QString &fieldName, const QString &expression, const QgsFeatureIds &filteredIds = QgsFeatureIds() ); void updateFieldFromExpression(); void updateFieldFromExpressionSelected(); - void viewModeChanged( QgsAttributeForm::Mode mode ); + void viewModeChanged( QgsAttributeEditorContext::Mode mode ); void formFilterSet( const QString &filter, QgsAttributeForm::FilterType type ); void showContextMenu( QgsActionMenu *menu, QgsFeatureId fid ); void toggleDockMode( bool docked ); diff --git a/src/app/qgsfeatureaction.cpp b/src/app/qgsfeatureaction.cpp index 8e846675384..f869e800512 100644 --- a/src/app/qgsfeatureaction.cpp +++ b/src/app/qgsfeatureaction.cpp @@ -135,7 +135,7 @@ bool QgsFeatureAction::editFeature( bool showModal ) std::unique_ptr dialog( newDialog( false ) ); if ( !mFeature->isValid() ) - dialog->setMode( QgsAttributeForm::AddFeatureMode ); + dialog->setMode( QgsAttributeEditorContext::AddFeatureMode ); int rv = dialog->exec(); mFeature->setAttributes( dialog->feature()->attributes() ); @@ -155,7 +155,7 @@ bool QgsFeatureAction::editFeature( bool showModal ) dialog = newDialog( false ); if ( !mFeature->isValid() ) - dialog->setMode( QgsAttributeForm::AddFeatureMode ); + dialog->setMode( QgsAttributeEditorContext::AddFeatureMode ); // delete the dialog when it is closed dialog->setAttribute( Qt::WA_DeleteOnClose ); @@ -235,7 +235,7 @@ bool QgsFeatureAction::addFeature( const QgsAttributeMap &defaultAttributes, boo QgsAttributeDialog *dialog = newDialog( false ); // delete the dialog when it is closed dialog->setAttribute( Qt::WA_DeleteOnClose ); - dialog->setMode( QgsAttributeForm::AddFeatureMode ); + dialog->setMode( QgsAttributeEditorContext::AddFeatureMode ); dialog->setEditCommandMessage( text() ); connect( dialog->attributeForm(), &QgsAttributeForm::featureSaved, this, &QgsFeatureAction::onFeatureSaved ); diff --git a/src/app/qgsmaptoolfillring.cpp b/src/app/qgsmaptoolfillring.cpp index 308d11bfd23..8626b071270 100644 --- a/src/app/qgsmaptoolfillring.cpp +++ b/src/app/qgsmaptoolfillring.cpp @@ -161,7 +161,7 @@ void QgsMapToolFillRing::cadCanvasReleaseEvent( QgsMapMouseEvent *e ) else { QgsAttributeDialog *dialog = new QgsAttributeDialog( vlayer, &ft, false, nullptr, true ); - dialog->setMode( QgsAttributeForm::AddFeatureMode ); + dialog->setMode( QgsAttributeEditorContext::AddFeatureMode ); res = dialog->exec(); // will also add the feature } diff --git a/src/app/qgsselectbyformdialog.cpp b/src/app/qgsselectbyformdialog.cpp index 6dc1044739b..26fc1fafdfe 100644 --- a/src/app/qgsselectbyformdialog.cpp +++ b/src/app/qgsselectbyformdialog.cpp @@ -30,7 +30,7 @@ QgsSelectByFormDialog::QgsSelectByFormDialog( QgsVectorLayer *layer, const QgsAt dlgContext.setAllowCustomUi( false ); mForm = new QgsAttributeForm( layer, QgsFeature(), dlgContext, this ); - mForm->setMode( QgsAttributeForm::SearchMode ); + mForm->setMode( QgsAttributeEditorContext::SearchMode ); QVBoxLayout *vLayout = new QVBoxLayout(); vLayout->setMargin( 0 ); diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index 76dc27e1918..6dcd2d8536d 100755 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -547,6 +547,7 @@ SET(QGIS_GUI_MOC_HDRS qgsdatasourcemanagerdialog.h qgsabstractdatasourcewidget.h qgswidgetstatehelper_p.h + qgsattributeeditorcontext.h ogr/qgsnewogrconnection.h ogr/qgsvectorlayersaveasdialog.h @@ -757,7 +758,6 @@ ENDIF(MSVC) # for installing headers SET(QGIS_GUI_HDRS - qgsattributeeditorcontext.h qgsattributeforminterface.h qgsattributeformlegacyinterface.h qgsdetaileditemdata.h diff --git a/src/gui/attributetable/qgsdualview.cpp b/src/gui/attributetable/qgsdualview.cpp index 52b0ac8ebf6..57e9c88e013 100644 --- a/src/gui/attributetable/qgsdualview.cpp +++ b/src/gui/attributetable/qgsdualview.cpp @@ -446,7 +446,7 @@ void QgsDualView::setMultiEditEnabled( bool enabled ) if ( enabled ) setView( AttributeEditor ); - mAttributeForm->setMode( enabled ? QgsAttributeForm::MultiEditMode : QgsAttributeForm::SingleEditMode ); + mAttributeForm->setMode( enabled ? QgsAttributeEditorContext::MultiEditMode : QgsAttributeEditorContext::SingleEditMode ); } void QgsDualView::toggleSearchMode( bool enabled ) @@ -454,11 +454,11 @@ void QgsDualView::toggleSearchMode( bool enabled ) if ( enabled ) { setView( AttributeEditor ); - mAttributeForm->setMode( QgsAttributeForm::SearchMode ); + mAttributeForm->setMode( QgsAttributeEditorContext::SearchMode ); } else { - mAttributeForm->setMode( QgsAttributeForm::SingleEditMode ); + mAttributeForm->setMode( QgsAttributeEditorContext::SingleEditMode ); } } diff --git a/src/gui/attributetable/qgsdualview.h b/src/gui/attributetable/qgsdualview.h index a178f1a2272..9826a978e46 100644 --- a/src/gui/attributetable/qgsdualview.h +++ b/src/gui/attributetable/qgsdualview.h @@ -267,7 +267,7 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas * Emitted when the form changes mode. * \param mode new mode */ - void formModeChanged( QgsAttributeForm::Mode mode ); + void formModeChanged( QgsAttributeEditorContext::Mode mode ); /** * Emitted when selecting context menu on the feature list to create the context menu individually diff --git a/src/gui/editorwidgets/core/qgswidgetwrapper.h b/src/gui/editorwidgets/core/qgswidgetwrapper.h index ec024c96f99..03704c1eec1 100644 --- a/src/gui/editorwidgets/core/qgswidgetwrapper.h +++ b/src/gui/editorwidgets/core/qgswidgetwrapper.h @@ -205,7 +205,7 @@ class GUI_EXPORT QgsWidgetWrapper : public QObject signals: /** - * Signal when QgsAttributeEditorContext mContext changed after the widget wrapper has already been intialized + * Signal when QgsAttributeEditorContext mContext changed * * \since QGIS 3.4 */ diff --git a/src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp b/src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp index 7fc38111486..c143956264b 100644 --- a/src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsqmlwidgetwrapper.cpp @@ -85,8 +85,9 @@ void QgsQmlWidgetWrapper::setQmlContext( ) if ( !mWidget ) return; + QgsAttributeEditorContext attributecontext = context(); QgsExpressionContext expressionContext = layer()->createExpressionContext(); - expressionContext << QgsExpressionContextUtils::formScope( mFeature, context().attributeFormMode() ); + expressionContext << QgsExpressionContextUtils::formScope( mFeature, attributecontext.attributeFormModeString( attributecontext.attributeFormMode() ) ); expressionContext.setFeature( mFeature ); QmlExpression *qmlExpression = new QmlExpression(); diff --git a/src/gui/editorwidgets/qgsqmlwidgetwrapper.h b/src/gui/editorwidgets/qgsqmlwidgetwrapper.h index bc73fe21abd..fbfcfa8a42c 100644 --- a/src/gui/editorwidgets/qgsqmlwidgetwrapper.h +++ b/src/gui/editorwidgets/qgsqmlwidgetwrapper.h @@ -54,11 +54,12 @@ class GUI_EXPORT QgsQmlWidgetWrapper : public QgsWidgetWrapper void setQmlCode( const QString &qmlCode ); public slots: - - void setQmlContext(); - void setFeature( const QgsFeature &feature ) override; + private slots: + //! sets the qml context with the current values + void setQmlContext(); + private: QTemporaryFile mQmlFile; QQuickWidget *mWidget = nullptr; diff --git a/src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp b/src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp index 931e2dca236..993ec6000ed 100644 --- a/src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp +++ b/src/gui/editorwidgets/qgsrelationaggregatesearchwidgetwrapper.cpp @@ -90,7 +90,7 @@ bool QgsRelationAggregateSearchWidgetWrapper::eventFilter( QObject *watched, QEv { QgsAttributeEditorContext subContext = QgsAttributeEditorContext( context(), mWrapper->relation(), QgsAttributeEditorContext::Multiple, QgsAttributeEditorContext::Embed ); mAttributeForm = new QgsAttributeForm( mWrapper->relation().referencingLayer(), QgsFeature(), subContext, mContainerWidget ); - mAttributeForm->setMode( QgsAttributeForm::AggregateSearchMode ); + mAttributeForm->setMode( QgsAttributeEditorContext::AggregateSearchMode ); QGridLayout *glayout = new QGridLayout(); mContainerWidget->setLayout( glayout ); glayout->setMargin( 0 ); diff --git a/src/gui/qgsactionmenu.cpp b/src/gui/qgsactionmenu.cpp index 9e9b4d0b083..d15b69eb282 100644 --- a/src/gui/qgsactionmenu.cpp +++ b/src/gui/qgsactionmenu.cpp @@ -67,7 +67,7 @@ void QgsActionMenu::setFeature( const QgsFeature &feature ) mFeature = feature; } -void QgsActionMenu::setMode( const QgsAttributeForm::Mode mode ) +void QgsActionMenu::setMode( const QgsAttributeEditorContext::Mode mode ) { mMode = mode; reloadActions(); @@ -120,7 +120,7 @@ void QgsActionMenu::reloadActions() if ( !mLayer->isEditable() && action.isEnabledOnlyWhenEditable() ) continue; - if ( action.isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeForm::AddFeatureMode || mMode == QgsAttributeForm::IdentifyMode ) ) + if ( action.isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeEditorContext::AddFeatureMode || mMode == QgsAttributeEditorContext::IdentifyMode ) ) continue; QgsAction act( action ); @@ -155,7 +155,7 @@ void QgsActionMenu::reloadActions() { QgsMapLayerAction *qaction = mapLayerActions.at( i ); - if ( qaction->isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeForm::AddFeatureMode || mMode == QgsAttributeForm::IdentifyMode ) ) + if ( qaction->isEnabledOnlyWhenEditable() && ( mMode == QgsAttributeEditorContext::AddFeatureMode || mMode == QgsAttributeEditorContext::IdentifyMode ) ) continue; QAction *qAction = new QAction( qaction->icon(), qaction->text(), this ); diff --git a/src/gui/qgsactionmenu.h b/src/gui/qgsactionmenu.h index 8ed0f445a84..3ddd366c204 100644 --- a/src/gui/qgsactionmenu.h +++ b/src/gui/qgsactionmenu.h @@ -97,7 +97,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu * * \param mode The mode of the attribute form */ - void setMode( QgsAttributeForm::Mode mode ); + void setMode( QgsAttributeEditorContext::Mode mode ); /** * Sets an expression context scope used to resolve underlying actions. @@ -131,7 +131,7 @@ class GUI_EXPORT QgsActionMenu : public QMenu QgsFeatureId mFeatureId; QString mActionScope; QgsExpressionContextScope mExpressionContextScope; - QgsAttributeForm::Mode mMode; + QgsAttributeEditorContext::Mode mMode; }; diff --git a/src/gui/qgsattributedialog.cpp b/src/gui/qgsattributedialog.cpp index 82c20df7853..139cf539368 100644 --- a/src/gui/qgsattributedialog.cpp +++ b/src/gui/qgsattributedialog.cpp @@ -79,7 +79,7 @@ void QgsAttributeDialog::show() void QgsAttributeDialog::reject() { // Delete any actions on other layers that may have been triggered from this dialog - if ( mAttributeForm->mode() == QgsAttributeForm::AddFeatureMode ) + if ( mAttributeForm->mode() == QgsAttributeEditorContext::AddFeatureMode ) mTrackedVectorLayerTools.rollback(); QDialog::reject(); @@ -116,7 +116,7 @@ void QgsAttributeDialog::init( QgsVectorLayer *layer, QgsFeature *feature, const focusNextChild(); } -void QgsAttributeDialog::setMode( QgsAttributeForm::Mode mode ) +void QgsAttributeDialog::setMode( QgsAttributeEditorContext::Mode mode ) { mAttributeForm->setMode( mode ); mMenu->setMode( mode ); diff --git a/src/gui/qgsattributedialog.h b/src/gui/qgsattributedialog.h index d2a725bb542..5a42cad4637 100644 --- a/src/gui/qgsattributedialog.h +++ b/src/gui/qgsattributedialog.h @@ -75,10 +75,10 @@ class GUI_EXPORT QgsAttributeDialog : public QDialog /** * Toggles the form mode. - * \param mode form mode. For example, if set to QgsAttributeForm::AddFeatureMode, the dialog will be editable even with an invalid feature and + * \param mode form mode. For example, if set to QgsAttributeEditorContext::AddFeatureMode, the dialog will be editable even with an invalid feature and * will add a new feature when the form is accepted. */ - void setMode( QgsAttributeForm::Mode mode ); + void setMode( QgsAttributeEditorContext::Mode mode ); /** * Sets the edit command message (Undo) that will be used when the dialog is accepted diff --git a/src/gui/qgsattributeeditorcontext.h b/src/gui/qgsattributeeditorcontext.h index 1b73f0d1ec5..37e6dfe63ba 100644 --- a/src/gui/qgsattributeeditorcontext.h +++ b/src/gui/qgsattributeeditorcontext.h @@ -18,6 +18,7 @@ #include #include +#include #include "qgsdistancearea.h" #include "qgsvectorlayer.h" @@ -36,9 +37,11 @@ class QgsMapCanvas; class GUI_EXPORT QgsAttributeEditorContext { + Q_GADGET + public: - //! Form modes + //! modes enum Mode { SingleEditMode, //!< Single edit mode, for editing a single feature @@ -49,6 +52,7 @@ class GUI_EXPORT QgsAttributeEditorContext AggregateSearchMode, //!< Form is in aggregate search mode, show each widget in this mode \since QGIS 3.0 IdentifyMode //!< Identify the feature \since QGIS 3.0 }; + Q_ENUM( Mode ) /** * Determines in which direction a relation was resolved. @@ -220,13 +224,23 @@ class GUI_EXPORT QgsAttributeEditorContext * Returns current attributeFormMode * \since QGIS 3.4 */ - QString attributeFormMode() const { return mAttributeFormMode; } + Mode attributeFormMode() const { return mAttributeFormMode; } /** * Set \a attributeFormMode for the edited form * \since QGIS 3.4 */ - void setAttributeFormMode( const QString &attributeFormMode ) { mAttributeFormMode = attributeFormMode; } + void setAttributeFormMode( const Mode &attributeFormMode ) { mAttributeFormMode = attributeFormMode; } + + /** + * Returns given \a attributeFormMode as string + * \since QGIS 3.4 + */ + QString attributeFormModeString( const Mode &attributeFormMode ) + { + const QMetaEnum metaEnum( QMetaEnum::fromType() ); + return metaEnum.valueToKey( static_cast( attributeFormMode ) ); + } private: const QgsAttributeEditorContext *mParentContext = nullptr; @@ -240,7 +254,7 @@ class GUI_EXPORT QgsAttributeEditorContext QgsFeature mFormFeature; FormMode mFormMode = Embed; bool mAllowCustomUi = true; - QString mAttributeFormMode = QStringLiteral( "SingleEditMode" ); + Mode mAttributeFormMode = SingleEditMode; }; #endif // QGSATTRIBUTEEDITORCONTEXT_H diff --git a/src/gui/qgsattributeform.cpp b/src/gui/qgsattributeform.cpp index 8ef94a5b65e..89cd6bcf9cf 100644 --- a/src/gui/qgsattributeform.cpp +++ b/src/gui/qgsattributeform.cpp @@ -67,7 +67,7 @@ QgsAttributeForm::QgsAttributeForm( QgsVectorLayer *vl, const QgsFeature &featur , mIsSettingMultiEditFeatures( false ) , mUnsavedMultiEditChanges( false ) , mEditCommandMessage( tr( "Attributes changed" ) ) - , mMode( SingleEditMode ) + , mMode( QgsAttributeEditorContext::SingleEditMode ) { init(); initPython(); @@ -93,7 +93,7 @@ void QgsAttributeForm::hideButtonBox() mButtonBox->hide(); // Make sure that changes are taken into account if somebody tries to figure out if there have been some - if ( mMode == SingleEditMode ) + if ( mMode == QgsAttributeEditorContext::SingleEditMode ) connect( mLayer, &QgsVectorLayer::beforeModifiedCheck, this, &QgsAttributeForm::save ); } @@ -120,12 +120,12 @@ bool QgsAttributeForm::editable() return mFeature.isValid() && mLayer->isEditable(); } -void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode ) +void QgsAttributeForm::setMode( QgsAttributeEditorContext::Mode mode ) { if ( mode == mMode ) return; - if ( mMode == MultiEditMode ) + if ( mMode == QgsAttributeEditorContext::MultiEditMode ) { //switching out of multi edit mode triggers a save if ( mUnsavedMultiEditChanges ) @@ -144,7 +144,7 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode ) mMode = mode; - if ( mButtonBox->isVisible() && mMode == SingleEditMode ) + if ( mButtonBox->isVisible() && mMode == QgsAttributeEditorContext::SingleEditMode ) { connect( mLayer, &QgsVectorLayer::beforeModifiedCheck, this, &QgsAttributeForm::save ); } @@ -158,27 +158,27 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode ) { switch ( mode ) { - case QgsAttributeForm::SingleEditMode: + case QgsAttributeEditorContext::SingleEditMode: w->setMode( QgsAttributeFormWidget::DefaultMode ); break; - case QgsAttributeForm::AddFeatureMode: + case QgsAttributeEditorContext::AddFeatureMode: w->setMode( QgsAttributeFormWidget::DefaultMode ); break; - case QgsAttributeForm::MultiEditMode: + case QgsAttributeEditorContext::MultiEditMode: w->setMode( QgsAttributeFormWidget::MultiEditMode ); break; - case QgsAttributeForm::SearchMode: + case QgsAttributeEditorContext::SearchMode: w->setMode( QgsAttributeFormWidget::SearchMode ); break; - case QgsAttributeForm::AggregateSearchMode: + case QgsAttributeEditorContext::AggregateSearchMode: w->setMode( QgsAttributeFormWidget::AggregateSearchMode ); break; - case QgsAttributeForm::IdentifyMode: + case QgsAttributeEditorContext::IdentifyMode: w->setMode( QgsAttributeFormWidget::DefaultMode ); break; } @@ -187,11 +187,11 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode ) for ( QgsWidgetWrapper *w : qgis::as_const( mWidgets ) ) { QgsAttributeEditorContext newContext = w->context(); - newContext.setAttributeFormMode( modeString( mMode ) ); + newContext.setAttributeFormMode( mMode ); w->setContext( newContext ); } - bool relationWidgetsVisible = ( mMode != QgsAttributeForm::MultiEditMode && mMode != QgsAttributeForm::AggregateSearchMode ); + bool relationWidgetsVisible = ( mMode != QgsAttributeEditorContext::MultiEditMode && mMode != QgsAttributeEditorContext::AggregateSearchMode ); for ( QgsAttributeFormRelationEditorWidget *w : findChildren< QgsAttributeFormRelationEditorWidget * >() ) { w->setVisible( relationWidgetsVisible ); @@ -199,33 +199,33 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode ) switch ( mode ) { - case QgsAttributeForm::SingleEditMode: + case QgsAttributeEditorContext::SingleEditMode: setFeature( mFeature ); mSearchButtonBox->setVisible( false ); break; - case QgsAttributeForm::AddFeatureMode: + case QgsAttributeEditorContext::AddFeatureMode: synchronizeEnabledState(); mSearchButtonBox->setVisible( false ); break; - case QgsAttributeForm::MultiEditMode: + case QgsAttributeEditorContext::MultiEditMode: resetMultiEdit( false ); synchronizeEnabledState(); mSearchButtonBox->setVisible( false ); break; - case QgsAttributeForm::SearchMode: + case QgsAttributeEditorContext::SearchMode: mSearchButtonBox->setVisible( true ); hideButtonBox(); break; - case QgsAttributeForm::AggregateSearchMode: + case QgsAttributeEditorContext::AggregateSearchMode: mSearchButtonBox->setVisible( false ); hideButtonBox(); break; - case QgsAttributeForm::IdentifyMode: + case QgsAttributeEditorContext::IdentifyMode: setFeature( mFeature ); mSearchButtonBox->setVisible( false ); break; @@ -234,25 +234,6 @@ void QgsAttributeForm::setMode( QgsAttributeForm::Mode mode ) emit modeChanged( mMode ); } -QString QgsAttributeForm::modeString( Mode mode ) const -{ - switch ( mode ) - { - case SingleEditMode: - return QStringLiteral( "SingleEditMode" ); - case AddFeatureMode: - return QStringLiteral( "AddFeatureMode" ); - case MultiEditMode: - return QStringLiteral( "MultiEditMode" ); - case SearchMode: - return QStringLiteral( "SearchMode" ); - case AggregateSearchMode: - return QStringLiteral( "AggregateSearchMode" ); - case IdentifyMode: - return QStringLiteral( "IdentifyMode" ); - } -} - void QgsAttributeForm::changeAttribute( const QString &field, const QVariant &value, const QString &hintText ) { Q_FOREACH ( QgsWidgetWrapper *ww, mWidgets ) @@ -273,9 +254,9 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature ) switch ( mMode ) { - case SingleEditMode: - case IdentifyMode: - case AddFeatureMode: + case QgsAttributeEditorContext::SingleEditMode: + case QgsAttributeEditorContext::IdentifyMode: + case QgsAttributeEditorContext::AddFeatureMode: { resetValues(); @@ -287,9 +268,9 @@ void QgsAttributeForm::setFeature( const QgsFeature &feature ) } break; } - case MultiEditMode: - case SearchMode: - case AggregateSearchMode: + case QgsAttributeEditorContext::MultiEditMode: + case QgsAttributeEditorContext::SearchMode: + case QgsAttributeEditorContext::AggregateSearchMode: { //ignore setFeature break; @@ -305,13 +286,13 @@ bool QgsAttributeForm::saveEdits() QgsFeature updatedFeature = QgsFeature( mFeature ); - if ( mFeature.isValid() || mMode == AddFeatureMode ) + if ( mFeature.isValid() || mMode == QgsAttributeEditorContext::AddFeatureMode ) { bool doUpdate = false; // An add dialog should perform an action by default // and not only if attributes have "changed" - if ( mMode == AddFeatureMode ) + if ( mMode == QgsAttributeEditorContext::AddFeatureMode ) doUpdate = true; QgsAttributes src = mFeature.attributes(); @@ -351,7 +332,7 @@ bool QgsAttributeForm::saveEdits() if ( doUpdate ) { - if ( mMode == AddFeatureMode ) + if ( mMode == QgsAttributeEditorContext::AddFeatureMode ) { mFeature.setValid( true ); mLayer->beginEditCommand( mEditCommandMessage ); @@ -360,7 +341,7 @@ bool QgsAttributeForm::saveEdits() { mFeature.setAttributes( updatedFeature.attributes() ); mLayer->endEditCommand(); - setMode( SingleEditMode ); + setMode( QgsAttributeEditorContext::SingleEditMode ); changedLayer = true; } else @@ -444,7 +425,7 @@ void QgsAttributeForm::filterTriggered() QString filter = createFilterExpression(); emit filterExpressionSet( filter, ReplaceFilter ); if ( mContext.formMode() == QgsAttributeEditorContext::Embed ) - setMode( SingleEditMode ); + setMode( QgsAttributeEditorContext::SingleEditMode ); } void QgsAttributeForm::searchZoomTo() @@ -472,7 +453,7 @@ void QgsAttributeForm::filterAndTriggered() return; if ( mContext.formMode() == QgsAttributeEditorContext::Embed ) - setMode( SingleEditMode ); + setMode( QgsAttributeEditorContext::SingleEditMode ); emit filterExpressionSet( filter, FilterAnd ); } @@ -483,7 +464,7 @@ void QgsAttributeForm::filterOrTriggered() return; if ( mContext.formMode() == QgsAttributeEditorContext::Embed ) - setMode( SingleEditMode ); + setMode( QgsAttributeEditorContext::SingleEditMode ); emit filterExpressionSet( filter, FilterOr ); } @@ -516,7 +497,7 @@ void QgsAttributeForm::runSearchSelect( QgsVectorLayer::SelectBehavior behavior mLayer->selectByExpression( filter, behavior ); pushSelectedFeaturesMessage(); if ( mContext.formMode() == QgsAttributeEditorContext::Embed ) - setMode( SingleEditMode ); + setMode( QgsAttributeEditorContext::SingleEditMode ); } void QgsAttributeForm::searchSetSelection() @@ -625,16 +606,16 @@ bool QgsAttributeForm::save() // default values switch ( mMode ) { - case SingleEditMode: - case IdentifyMode: - case MultiEditMode: + case QgsAttributeEditorContext::SingleEditMode: + case QgsAttributeEditorContext::IdentifyMode: + case QgsAttributeEditorContext::MultiEditMode: if ( !mDirty ) return true; break; - case AddFeatureMode: - case SearchMode: - case AggregateSearchMode: + case QgsAttributeEditorContext::AddFeatureMode: + case QgsAttributeEditorContext::SearchMode: + case QgsAttributeEditorContext::AggregateSearchMode: break; } @@ -650,15 +631,15 @@ bool QgsAttributeForm::save() switch ( mMode ) { - case SingleEditMode: - case IdentifyMode: - case AddFeatureMode: - case SearchMode: - case AggregateSearchMode: + case QgsAttributeEditorContext::SingleEditMode: + case QgsAttributeEditorContext::IdentifyMode: + case QgsAttributeEditorContext::AddFeatureMode: + case QgsAttributeEditorContext::SearchMode: + case QgsAttributeEditorContext::AggregateSearchMode: success = saveEdits(); break; - case MultiEditMode: + case QgsAttributeEditorContext::MultiEditMode: success = saveMultiEdits(); break; } @@ -735,9 +716,9 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value ) switch ( mMode ) { - case SingleEditMode: - case IdentifyMode: - case AddFeatureMode: + case QgsAttributeEditorContext::SingleEditMode: + case QgsAttributeEditorContext::IdentifyMode: + case QgsAttributeEditorContext::AddFeatureMode: { Q_NOWARN_DEPRECATED_PUSH emit attributeChanged( eww->field().name(), value ); @@ -750,7 +731,7 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value ) break; } - case MultiEditMode: + case QgsAttributeEditorContext::MultiEditMode: { if ( !mIsSettingMultiEditFeatures ) { @@ -768,8 +749,8 @@ void QgsAttributeForm::onAttributeChanged( const QVariant &value ) } break; } - case SearchMode: - case AggregateSearchMode: + case QgsAttributeEditorContext::SearchMode: + case QgsAttributeEditorContext::AggregateSearchMode: //nothing to do break; } @@ -824,7 +805,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww ) mExpressionContext.setFeature( ft ); - mExpressionContext << QgsExpressionContextUtils::formScope( ft, modeString( mMode ) ); + mExpressionContext << QgsExpressionContextUtils::formScope( ft, mContext.attributeFormModeString( mMode ) ); // Recheck visibility for all containers which are controlled by this value const QVector infos = mContainerInformationDependency.value( eww->field().name() ); @@ -838,7 +819,7 @@ void QgsAttributeForm::updateConstraints( QgsEditorWidgetWrapper *eww ) void QgsAttributeForm::updateContainersVisibility() { - mExpressionContext << QgsExpressionContextUtils::formScope( QgsFeature( mFeature ), modeString( mMode ) ); + mExpressionContext << QgsExpressionContextUtils::formScope( QgsFeature( mFeature ), mContext.attributeFormModeString( mMode ) ); const QVector infos = mContainerVisibilityInformation; @@ -1077,8 +1058,8 @@ void QgsAttributeForm::refreshFeature() void QgsAttributeForm::synchronizeEnabledState() { bool isEditable = ( mFeature.isValid() - || mMode == AddFeatureMode - || mMode == MultiEditMode ) && mLayer->isEditable(); + || mMode == QgsAttributeEditorContext::AddFeatureMode + || mMode == QgsAttributeEditorContext::MultiEditMode ) && mLayer->isEditable(); for ( QgsWidgetWrapper *ww : qgis::as_const( mWidgets ) ) { @@ -1099,7 +1080,7 @@ void QgsAttributeForm::synchronizeEnabledState() } } - if ( mMode != SearchMode ) + if ( mMode != QgsAttributeEditorContext::SearchMode ) { QStringList invalidFields, descriptions; bool validConstraint = currentFormValidConstraints( invalidFields, descriptions ); @@ -1498,7 +1479,7 @@ void QgsAttributeForm::init() layout->addWidget( mSearchButtonBox ); } - mSearchButtonBox->setVisible( mMode == SearchMode ); + mSearchButtonBox->setVisible( mMode == QgsAttributeEditorContext::SearchMode ); afterWidgetInit(); @@ -1519,7 +1500,7 @@ void QgsAttributeForm::init() iface->initForm(); } - if ( mContext.formMode() == QgsAttributeEditorContext::Embed || mMode == SearchMode ) + if ( mContext.formMode() == QgsAttributeEditorContext::Embed || mMode == QgsAttributeEditorContext::SearchMode ) { hideButtonBox(); } @@ -1821,7 +1802,7 @@ QgsAttributeForm::WidgetInfo QgsAttributeForm::createWidgetFromDef( const QgsAtt QgsQmlWidgetWrapper *qmlWrapper = new QgsQmlWidgetWrapper( mLayer, nullptr, this ); qmlWrapper->setQmlCode( elementDef->qmlCode() ); qmlWrapper->setConfig( mLayer->editFormConfig().widgetConfig( elementDef->name() ) ); - context.setAttributeFormMode( modeString( mMode ) ); + context.setAttributeFormMode( mMode ); qmlWrapper->setContext( context ); mWidgets.append( qmlWrapper ); @@ -1983,14 +1964,14 @@ void QgsAttributeForm::layerSelectionChanged() { switch ( mMode ) { - case SingleEditMode: - case IdentifyMode: - case AddFeatureMode: - case SearchMode: - case AggregateSearchMode: + case QgsAttributeEditorContext::SingleEditMode: + case QgsAttributeEditorContext::IdentifyMode: + case QgsAttributeEditorContext::AddFeatureMode: + case QgsAttributeEditorContext::SearchMode: + case QgsAttributeEditorContext::AggregateSearchMode: break; - case MultiEditMode: + case QgsAttributeEditorContext::MultiEditMode: resetMultiEdit( true ); break; } @@ -2053,7 +2034,7 @@ void QgsAttributeForm::setMessageBar( QgsMessageBar *messageBar ) QString QgsAttributeForm::aggregateFilter() const { - if ( mMode != AggregateSearchMode ) + if ( mMode != QgsAttributeEditorContext::AggregateSearchMode ) { Q_ASSERT( false ); } @@ -2165,7 +2146,7 @@ bool QgsAttributeForm::fieldIsEditable( int fieldIndex ) const int srcFieldIndex; const QgsVectorLayerJoinInfo *info = mLayer->joinBuffer()->joinForFieldIndex( fieldIndex, mLayer->fields(), srcFieldIndex ); - if ( info && !info->hasUpsertOnEdit() && mMode == QgsAttributeForm::AddFeatureMode ) + if ( info && !info->hasUpsertOnEdit() && mMode == QgsAttributeEditorContext::AddFeatureMode ) editable = false; else if ( info && info->isEditable() && info->joinLayer()->isEditable() ) editable = fieldIsEditable( *( info->joinLayer() ), srcFieldIndex, mFeature.id() ); @@ -2206,7 +2187,7 @@ void QgsAttributeForm::updateIcon( QgsEditorWidgetWrapper *eww ) const QString tooltip = tr( "Join settings do not allow editing" ); reloadIcon( file, tooltip, mIconMap[eww->widget()] ); } - else if ( mMode == QgsAttributeForm::AddFeatureMode && !info->hasUpsertOnEdit() ) + else if ( mMode == QgsAttributeEditorContext::AddFeatureMode && !info->hasUpsertOnEdit() ) { const QString file = QStringLiteral( "mIconJoinHasNotUpsertOnEdit.svg" ); const QString tooltip = tr( "Join settings do not allow upsert on edit" ); diff --git a/src/gui/qgsattributeform.h b/src/gui/qgsattributeform.h index 0b7ea82ab76..c5298456c06 100644 --- a/src/gui/qgsattributeform.h +++ b/src/gui/qgsattributeform.h @@ -46,18 +46,6 @@ class GUI_EXPORT QgsAttributeForm : public QWidget public: - //! Form modes - enum Mode - { - SingleEditMode, //!< Single edit mode, for editing a single feature - AddFeatureMode, /*!< Add feature mode, for setting attributes for a new feature. In this mode the dialog will be editable even with an invalid feature and - will add a new feature when the form is accepted. */ - MultiEditMode, //!< Multi edit mode, for editing fields of multiple features at once - SearchMode, //!< Form values are used for searching/filtering the layer - AggregateSearchMode, //!< Form is in aggregate search mode, show each widget in this mode \since QGIS 3.0 - IdentifyMode //!< Identify the feature \since QGIS 3.0 - }; - //! Filter types enum FilterType { @@ -120,7 +108,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget * \see setMode() * \since QGIS 2.16 */ - Mode mode() const { return mMode; } + QgsAttributeEditorContext::Mode mode() const { return mMode; } /** * Sets the current mode of the form. @@ -128,13 +116,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget * \see mode() * \since QGIS 2.16 */ - void setMode( Mode mode ); - - /** - * Returns the context as string of \a mode - * \since QGIS 3.4 - */ - QString modeString( Mode mode ) const; + void setMode( QgsAttributeEditorContext::Mode mode ); /** * Sets the edit command message (Undo) that will be used when the dialog is accepted @@ -226,7 +208,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget * Emitted when the form changes mode. * \param mode new mode */ - void modeChanged( QgsAttributeForm::Mode mode ); + void modeChanged( QgsAttributeEditorContext::Mode mode ); /** * Emitted when the user selects the close option from the form's button bar. @@ -440,7 +422,7 @@ class GUI_EXPORT QgsAttributeForm : public QWidget QString mEditCommandMessage; - Mode mMode; + QgsAttributeEditorContext::Mode mMode; QMap mIconMap; diff --git a/src/gui/qgsidentifymenu.cpp b/src/gui/qgsidentifymenu.cpp index 45ecae22ebc..c8aa4242de2 100644 --- a/src/gui/qgsidentifymenu.cpp +++ b/src/gui/qgsidentifymenu.cpp @@ -260,7 +260,7 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QListsetMode( QgsAttributeForm::IdentifyMode ); + featureActionMenu->setMode( QgsAttributeEditorContext::IdentifyMode ); createMenu = !featureActionMenu->actions().isEmpty(); delete featureActionMenu; } @@ -346,7 +346,7 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QListsetMode( QgsAttributeForm::IdentifyMode ); + featureActionMenu->setMode( QgsAttributeEditorContext::IdentifyMode ); featureActionMenu->setExpressionContextScope( mExpressionContextScope ); } diff --git a/tests/src/gui/testqgsattributeform.cpp b/tests/src/gui/testqgsattributeform.cpp index 9b6d5c46444..1e2b9921d4a 100644 --- a/tests/src/gui/testqgsattributeform.cpp +++ b/tests/src/gui/testqgsattributeform.cpp @@ -373,7 +373,7 @@ void TestQgsAttributeForm::testDynamicForm() // build a form with feature A QgsAttributeForm form( layerA ); - form.setMode( QgsAttributeForm::AddFeatureMode ); + form.setMode( QgsAttributeEditorContext::AddFeatureMode ); form.setFeature( ftA ); // test that there's no joined feature by default @@ -487,7 +487,7 @@ void TestQgsAttributeForm::testConstraintsOnJoinedFields() // build a form for this feature QgsAttributeForm form( layerA ); - form.setMode( QgsAttributeForm::AddFeatureMode ); + form.setMode( QgsAttributeEditorContext::AddFeatureMode ); form.setFeature( ftA ); // change layerA join id field @@ -568,7 +568,7 @@ void TestQgsAttributeForm::testEditableJoin() ftA = layerA->getFeature( 1 ); QgsAttributeForm form( layerA ); - form.setMode( QgsAttributeForm::SingleEditMode ); + form.setMode( QgsAttributeEditorContext::SingleEditMode ); form.setFeature( ftA ); // change layerA join id field to join with layerB and layerC @@ -692,7 +692,7 @@ void TestQgsAttributeForm::testUpsertOnEdit() // build a form with feature A QgsAttributeForm form( layerA ); - form.setMode( QgsAttributeForm::AddFeatureMode ); + form.setMode( QgsAttributeEditorContext::AddFeatureMode ); form.setFeature( ft0A ); // count features @@ -725,7 +725,7 @@ void TestQgsAttributeForm::testUpsertOnEdit() // add a new feature with not null joined fields. Joined feature should be // added QgsAttributeForm form1( layerA ); - form1.setMode( QgsAttributeForm::AddFeatureMode ); + form1.setMode( QgsAttributeEditorContext::AddFeatureMode ); form1.setFeature( ft0A ); form1.changeAttribute( QStringLiteral( "id_a" ), QVariant( 34 ) ); @@ -760,7 +760,7 @@ void TestQgsAttributeForm::testUpsertOnEdit() // create a target feature but update a joined feature. A new feature should // be added in layerA and values in layerB should be updated QgsAttributeForm form2( layerA ); - form2.setMode( QgsAttributeForm::AddFeatureMode ); + form2.setMode( QgsAttributeEditorContext::AddFeatureMode ); form2.setFeature( ft0A ); form2.changeAttribute( QStringLiteral( "id_a" ), QVariant( 33 ) ); form2.changeAttribute( QStringLiteral( "layerB_col0" ), QVariant( 3333 ) ); @@ -794,7 +794,7 @@ void TestQgsAttributeForm::testUpsertOnEdit() // update feature which does not exist in joined layer but with null joined // fields. A new feature should NOT be added in joined layer QgsAttributeForm form3( layerA ); - form3.setMode( QgsAttributeForm::SingleEditMode ); + form3.setMode( QgsAttributeEditorContext::SingleEditMode ); form3.setFeature( ft0A ); form3.changeAttribute( QStringLiteral( "id_a" ), QVariant( 31 ) ); form3.changeAttribute( QStringLiteral( "layerB_col0" ), QVariant() ); @@ -819,7 +819,7 @@ void TestQgsAttributeForm::testUpsertOnEdit() // update feature which does not exist in joined layer with NOT null joined // fields. A new feature should be added in joined layer QgsAttributeForm form4( layerA ); - form4.setMode( QgsAttributeForm::SingleEditMode ); + form4.setMode( QgsAttributeEditorContext::SingleEditMode ); form4.setFeature( ft0A ); form4.changeAttribute( QStringLiteral( "id_a" ), QVariant( 31 ) ); form4.changeAttribute( QStringLiteral( "layerB_col0" ), QVariant( 1111 ) );