Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[attribute form] Add parent feature scope when adding/editing a child feature through the relation editor widget #57271

Merged
merged 4 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ class QgsTrackedVectorLayerTools : QgsVectorLayerTools
Constructor for QgsTrackedVectorLayerTools.
%End

virtual bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false ) const;
virtual bool addFeatureV2( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature /Out/, const QgsVectorLayerToolsContext &context ) const;

%Docstring
This method calls the addFeature method of the backend :py:class:`QgsVectorLayerTools`

:param layer: The layer to which the feature should be added
:param defaultValues: Default values for the feature to add
:param defaultGeometry: A default geometry to add to the feature
:param feature: A pointer to the feature
:param parentWidget: The widget calling this function to be passed to the used dialog
:param showModal: If the used dialog should be modal or not
:param hideParent: If the parent widget should be hidden, when the used dialog is opened
:param context: A context object to be used for e.g. to calculate feature expression-based values (since QGIS 3.38)

:return: ``True`` in case of success, ``False`` if the operation failed/was aborted
:return: - ``True`` in case of success, ``False`` if the operation failed/was aborted
- feature: A pointer to the feature
%End
virtual bool startEditing( QgsVectorLayer *layer ) const;

Expand Down
8 changes: 6 additions & 2 deletions python/PyQt6/core/auto_generated/vector/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ be updated. This can be used to override default field value expressions.
.. seealso:: :py:func:`updateFeature`
%End

bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false );
bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false, QgsVectorLayerToolsContext *context = 0 );
%Docstring
Changes an attribute value for a feature (but does not immediately commit the changes).
The ``fid`` argument specifies the ID of the feature to be changed.
Expand All @@ -1796,6 +1796,8 @@ so it is more efficient to explicitly pass an ``oldValue`` if it is already avai
If ``skipDefaultValues`` is set to ``True``, default field values will not
be updated. This can be used to override default field value expressions.

If ``context`` is provided, it will be used when updating default values (since QGIS 3.38).

:return: ``True`` if the feature's attribute was successfully changed.

.. note::
Expand All @@ -1815,7 +1817,7 @@ be updated. This can be used to override default field value expressions.
.. seealso:: :py:func:`updateFeature`
%End

bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false );
bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false, QgsVectorLayerToolsContext *context = 0 );
%Docstring
Changes attributes' values for a feature (but does not immediately
commit the changes).
Expand All @@ -1835,6 +1837,8 @@ If ``skipDefaultValues`` is set to ``True``, default field values will not
be updated. This can be used to override default field value
expressions.

If ``context`` is provided, it will be used when updating default values (since QGIS 3.38).

:return: ``True`` if feature's attributes was successfully changed.

.. note::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ in your application.
QgsVectorLayerTools();


virtual bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues = QgsAttributeMap(), const QgsGeometry &defaultGeometry = QgsGeometry(), QgsFeature *feature /Out/ = 0, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false ) const = 0;
virtual bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues = QgsAttributeMap(), const QgsGeometry &defaultGeometry = QgsGeometry(), QgsFeature *feature /Out/ = 0, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false ) const;
%Docstring
This method should/will be called, whenever a new feature will be added to the layer

Expand All @@ -41,6 +41,29 @@ This method should/will be called, whenever a new feature will be added to the l

:return: - ``True`` in case of success, ``False`` if the operation failed/was aborted
- feature: Updated feature after adding will be written back to this

.. note::

addFeature or addFeatureV2 must be overwritten when implementing a class inheriting from QgsVectorLayerTools
%End

virtual bool addFeatureV2( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues = QgsAttributeMap(), const QgsGeometry &defaultGeometry = QgsGeometry(), QgsFeature *feature /Out/ = 0, const QgsVectorLayerToolsContext &context = QgsVectorLayerToolsContext() ) const;
%Docstring
This method should/will be called, whenever a new feature will be added to the layer

:param layer: The layer to which the feature should be added
:param defaultValues: Default values for the feature to add
:param defaultGeometry: A default geometry to add to the feature
:param context: A context object to be used for e.g. to calculate feature expression-based values (since QGIS 3.38)

:return: - ``True`` in case of success, ``False`` if the operation failed/was aborted
- feature: Updated feature after adding will be written back to this

.. note::

addFeature or addFeatureV2 must be overwritten when implementing a class inheriting from QgsVectorLayerTools

.. versionadded:: 3.38
%End


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/vector/qgsvectorlayertoolscontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsVectorLayerToolsContext
{
%Docstring(signature="appended")
Contains settings which reflect the context in which vector layer tool operations should
consider.

.. versionadded:: 3.38
%End

%TypeHeaderCode
#include "qgsvectorlayertoolscontext.h"
%End
public:

QgsVectorLayerToolsContext();
%Docstring
Constructor for QgsVectorLayerToolsContext.
%End

QgsVectorLayerToolsContext( const QgsVectorLayerToolsContext &other );
%Docstring
Copy constructor.

:param other: source QgsVectorLayerToolsContext
%End


void setExpressionContext( const QgsExpressionContext *context );
%Docstring
Sets the optional expression context used by the vector layer tools.

:param context: expression context pointer. Ownership is not transferred.

.. seealso:: :py:func:`expressionContext`

.. seealso:: :py:func:`setAdditionalExpressionContextScope`
%End

QgsExpressionContext *expressionContext() const;
%Docstring
Returns the optional expression context used by the vector layer tools.

.. seealso:: :py:func:`setExpressionContext`

.. seealso:: :py:func:`additionalExpressionContextScope`
%End

void setAdditionalExpressionContextScope( const QgsExpressionContextScope *scope );
%Docstring
Sets an additional expression context scope to be made available when calculating expressions.

:param scope: additional scope. Ownership is not transferred and a copy will be made.

.. seealso:: :py:func:`additionalExpressionContextScope`
%End

const QgsExpressionContextScope *additionalExpressionContextScope() const;
%Docstring
Returns an additional expression context scope to be made available when calculating expressions.

.. seealso:: :py:func:`setAdditionalExpressionContextScope`
%End

QWidget *parentWidget() const;
%Docstring
Returns the widget which should be parented to tools dialogues.
%End

void setParentWidget( QWidget *parent );
%Docstring
Sets the widget which should be parented to tools' dialogues.

:param parent: the widget actign as parent
%End

bool showModal() const;
%Docstring
Returns whether tools' dialogues should be modal.
%End

void setShowModal( bool modal );
%Docstring
Sets whether tools' dialogues should be modal.
%End

bool hideParent() const;
%Docstring
Returns whether the parent widget should be hidden when showing tools' dialogues.
%End

void setHideParent( bool hide );
%Docstring
Sets whether the parent widget should be hidden when showing tools' dialogues.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/vector/qgsvectorlayertoolscontext.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
1 change: 1 addition & 0 deletions python/PyQt6/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@
%Include auto_generated/vector/qgsvectorlayerselectionproperties.sip
%Include auto_generated/vector/qgsvectorlayertemporalproperties.sip
%Include auto_generated/vector/qgsvectorlayertools.sip
%Include auto_generated/vector/qgsvectorlayertoolscontext.sip
%Include auto_generated/vector/qgsvectorlayerundocommand.sip
%Include auto_generated/vector/qgsvectorlayerundopassthroughcommand.sip
%Include auto_generated/vector/qgsvectorlayerutils.sip
Expand Down
10 changes: 4 additions & 6 deletions python/core/auto_generated/qgstrackedvectorlayertools.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@ class QgsTrackedVectorLayerTools : QgsVectorLayerTools
Constructor for QgsTrackedVectorLayerTools.
%End

virtual bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false ) const;
virtual bool addFeatureV2( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature /Out/, const QgsVectorLayerToolsContext &context ) const;

%Docstring
This method calls the addFeature method of the backend :py:class:`QgsVectorLayerTools`

:param layer: The layer to which the feature should be added
:param defaultValues: Default values for the feature to add
:param defaultGeometry: A default geometry to add to the feature
:param feature: A pointer to the feature
:param parentWidget: The widget calling this function to be passed to the used dialog
:param showModal: If the used dialog should be modal or not
:param hideParent: If the parent widget should be hidden, when the used dialog is opened
:param context: A context object to be used for e.g. to calculate feature expression-based values (since QGIS 3.38)

:return: ``True`` in case of success, ``False`` if the operation failed/was aborted
:return: - ``True`` in case of success, ``False`` if the operation failed/was aborted
- feature: A pointer to the feature
%End
virtual bool startEditing( QgsVectorLayer *layer ) const;

Expand Down
8 changes: 6 additions & 2 deletions python/core/auto_generated/vector/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ be updated. This can be used to override default field value expressions.
.. seealso:: :py:func:`updateFeature`
%End

bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false );
bool changeAttributeValue( QgsFeatureId fid, int field, const QVariant &newValue, const QVariant &oldValue = QVariant(), bool skipDefaultValues = false, QgsVectorLayerToolsContext *context = 0 );
%Docstring
Changes an attribute value for a feature (but does not immediately commit the changes).
The ``fid`` argument specifies the ID of the feature to be changed.
Expand All @@ -1796,6 +1796,8 @@ so it is more efficient to explicitly pass an ``oldValue`` if it is already avai
If ``skipDefaultValues`` is set to ``True``, default field values will not
be updated. This can be used to override default field value expressions.

If ``context`` is provided, it will be used when updating default values (since QGIS 3.38).

:return: ``True`` if the feature's attribute was successfully changed.

.. note::
Expand All @@ -1815,7 +1817,7 @@ be updated. This can be used to override default field value expressions.
.. seealso:: :py:func:`updateFeature`
%End

bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false );
bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false, QgsVectorLayerToolsContext *context = 0 );
%Docstring
Changes attributes' values for a feature (but does not immediately
commit the changes).
Expand All @@ -1835,6 +1837,8 @@ If ``skipDefaultValues`` is set to ``True``, default field values will not
be updated. This can be used to override default field value
expressions.

If ``context`` is provided, it will be used when updating default values (since QGIS 3.38).

:return: ``True`` if feature's attributes was successfully changed.

.. note::
Expand Down
25 changes: 24 additions & 1 deletion python/core/auto_generated/vector/qgsvectorlayertools.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ in your application.
QgsVectorLayerTools();


virtual bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues = QgsAttributeMap(), const QgsGeometry &defaultGeometry = QgsGeometry(), QgsFeature *feature /Out/ = 0, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false ) const = 0;
virtual bool addFeature( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues = QgsAttributeMap(), const QgsGeometry &defaultGeometry = QgsGeometry(), QgsFeature *feature /Out/ = 0, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false ) const;
%Docstring
This method should/will be called, whenever a new feature will be added to the layer

Expand All @@ -41,6 +41,29 @@ This method should/will be called, whenever a new feature will be added to the l

:return: - ``True`` in case of success, ``False`` if the operation failed/was aborted
- feature: Updated feature after adding will be written back to this

.. note::

addFeature or addFeatureV2 must be overwritten when implementing a class inheriting from QgsVectorLayerTools
%End

virtual bool addFeatureV2( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues = QgsAttributeMap(), const QgsGeometry &defaultGeometry = QgsGeometry(), QgsFeature *feature /Out/ = 0, const QgsVectorLayerToolsContext &context = QgsVectorLayerToolsContext() ) const;
%Docstring
This method should/will be called, whenever a new feature will be added to the layer

:param layer: The layer to which the feature should be added
:param defaultValues: Default values for the feature to add
:param defaultGeometry: A default geometry to add to the feature
:param context: A context object to be used for e.g. to calculate feature expression-based values (since QGIS 3.38)

:return: - ``True`` in case of success, ``False`` if the operation failed/was aborted
- feature: Updated feature after adding will be written back to this

.. note::

addFeature or addFeatureV2 must be overwritten when implementing a class inheriting from QgsVectorLayerTools

.. versionadded:: 3.38
%End


Expand Down