Skip to content

Commit

Permalink
Address review: add vector layer tools context class, implement addFe…
Browse files Browse the repository at this point in the history
…atureV2
  • Loading branch information
nirvn committed May 22, 2024
1 parent 18c80b6 commit 14987cd
Show file tree
Hide file tree
Showing 25 changed files with 459 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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, QgsExpressionContextScope *scope = 0 ) const;
virtual bool addFeatureV2( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false, QgsVectorLayerToolsContext *context = 0 ) const;

%Docstring
This method calls the addFeature method of the backend :py:class:`QgsVectorLayerTools`
Expand All @@ -32,7 +32,7 @@ This method calls the addFeature method of the backend :py:class:`QgsVectorLayer
: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 scope: A context scope to be used to calculate feature expression-based values
: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
%End
Expand Down
8 changes: 4 additions & 4 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, QgsExpressionContext *context = 0 );
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,7 +1796,7 @@ 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.
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.

Expand All @@ -1817,7 +1817,7 @@ If ``context`` is provided, it will be used when updating default values.
.. seealso:: :py:func:`updateFeature`
%End

bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false, QgsExpressionContext *context = 0 );
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 @@ -1837,7 +1837,7 @@ 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.
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.

Expand Down
29 changes: 27 additions & 2 deletions python/PyQt6/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, QgsExpressionContextScope *scope = 0 ) 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 @@ -38,10 +38,35 @@ This method should/will be called, whenever a new feature will be added to the l
: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 scope: A context scope to be used to calculate feature expression-based values

: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, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false, QgsVectorLayerToolsContext *context = 0 ) 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 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
- 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,83 @@
/************************************************************************
* 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( 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( QgsExpressionContextScope *scope );
%Docstring
Sets an additional expression context scope to be made available when calculating expressions.

:param scope: additional scope

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

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

.. seealso:: :py:func:`setAdditionalExpressionContextScope`
%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 @@ -769,6 +769,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
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgstrackedvectorlayertools.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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, QgsExpressionContextScope *scope = 0 ) const;
virtual bool addFeatureV2( QgsVectorLayer *layer, const QgsAttributeMap &defaultValues, const QgsGeometry &defaultGeometry, QgsFeature *feature, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false, QgsVectorLayerToolsContext *context = 0 ) const;

%Docstring
This method calls the addFeature method of the backend :py:class:`QgsVectorLayerTools`
Expand All @@ -32,7 +32,7 @@ This method calls the addFeature method of the backend :py:class:`QgsVectorLayer
: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 scope: A context scope to be used to calculate feature expression-based values
: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
%End
Expand Down
8 changes: 4 additions & 4 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, QgsExpressionContext *context = 0 );
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,7 +1796,7 @@ 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.
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.

Expand All @@ -1817,7 +1817,7 @@ If ``context`` is provided, it will be used when updating default values.
.. seealso:: :py:func:`updateFeature`
%End

bool changeAttributeValues( QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues = QgsAttributeMap(), bool skipDefaultValues = false, QgsExpressionContext *context = 0 );
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 @@ -1837,7 +1837,7 @@ 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.
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.

Expand Down
29 changes: 27 additions & 2 deletions 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, QgsExpressionContextScope *scope = 0 ) 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 @@ -38,10 +38,35 @@ This method should/will be called, whenever a new feature will be added to the l
: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 scope: A context scope to be used to calculate feature expression-based values

: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, QWidget *parentWidget = 0, bool showModal = true, bool hideParent = false, QgsVectorLayerToolsContext *context = 0 ) 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 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
- 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,83 @@
/************************************************************************
* 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( 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( QgsExpressionContextScope *scope );
%Docstring
Sets an additional expression context scope to be made available when calculating expressions.

:param scope: additional scope

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

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

.. seealso:: :py:func:`setAdditionalExpressionContextScope`
%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/core/core_auto.sip
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,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
Loading

0 comments on commit 14987cd

Please sign in to comment.