Skip to content

Commit

Permalink
Add fixed size mode for picture annotations
Browse files Browse the repository at this point in the history
When selected, the picture annotation will always be rendered
at the same size, regardless of the map scale
  • Loading branch information
nyalldawson committed Jul 18, 2024
1 parent c391bc0 commit cd99d2c
Show file tree
Hide file tree
Showing 17 changed files with 1,058 additions and 169 deletions.
6 changes: 6 additions & 0 deletions python/PyQt6/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2073,6 +2073,12 @@
Qgis.AnnotationItemFlags.baseClass = Qgis
AnnotationItemFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.AnnotationPictureSizeMode.SpatialBounds.__doc__ = "Picture is rendered inside spatial bounds, and size will depend on map scale"
Qgis.AnnotationPictureSizeMode.FixedSize.__doc__ = "Picture is rendered at a fixed size, regardless of map scale"
Qgis.AnnotationPictureSizeMode.__doc__ = "Picture annotation item size modes.\n\n.. versionadded:: 3.40\n\n" + '* ``SpatialBounds``: ' + Qgis.AnnotationPictureSizeMode.SpatialBounds.__doc__ + '\n' + '* ``FixedSize``: ' + Qgis.AnnotationPictureSizeMode.FixedSize.__doc__
# --
Qgis.AnnotationPictureSizeMode.baseClass = Qgis
# monkey patching scoped based enum
Qgis.AnnotationItemGuiFlag.FlagNoCreationTools.__doc__ = "Do not show item creation tools for the item type"
Qgis.AnnotationItemGuiFlag.__doc__ = "Flags for controlling how an annotation item behaves in the GUI.\n\n.. versionadded:: 3.22\n\n" + '* ``FlagNoCreationTools``: ' + Qgis.AnnotationItemGuiFlag.FlagNoCreationTools.__doc__
# --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ within the specified ``bounds`` geometry.

virtual QString type() const;

virtual Qgis::AnnotationItemFlags flags() const;

virtual void render( QgsRenderContext &context, QgsFeedback *feedback );

virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
Expand All @@ -53,13 +55,18 @@ Creates a new polygon annotation item.

virtual QgsRectangle boundingBox() const;

virtual QgsRectangle boundingBox( QgsRenderContext &context ) const;


QgsRectangle bounds() const;
%Docstring
Returns the bounds of the picture.

The coordinate reference system for the bounds will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

When the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize then the picture will be placed
at the center of the bounds.

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

Expand All @@ -69,6 +76,9 @@ Sets the ``bounds`` of the picture.

The coordinate reference system for the bounds will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

When the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize then the picture will be placed
at the center of the bounds.

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

Expand All @@ -91,6 +101,60 @@ Sets the ``format`` and ``path`` of the image used to render the item.
.. seealso:: :py:func:`path`

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

Qgis::AnnotationPictureSizeMode sizeMode() const;
%Docstring
Returns the size mode for the picture.

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

void setSizeMode( Qgis::AnnotationPictureSizeMode mode );
%Docstring
Sets the size ``mode`` for the picture.

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

QSizeF fixedSize() const;
%Docstring
Returns the fixed size to use for the picture, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

Units are retrieved via :py:func:`~QgsAnnotationPictureItem.fixedSizeUnit`

.. seealso:: :py:func:`setFixedSize`

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

void setFixedSize( const QSizeF &size );
%Docstring
Sets the fixed ``size`` to use for the picture, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

Units are set via :py:func:`~QgsAnnotationPictureItem.setFixedSizeUnit`

.. seealso:: :py:func:`fixedSize`

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

Qgis::RenderUnit fixedSizeUnit() const;
%Docstring
Returns the units to use for fixed picture sizes, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

.. seealso:: :py:func:`setFixedSizeUnit`

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

void setFixedSizeUnit( Qgis::RenderUnit unit );
%Docstring
Sets the ``unit`` to use for fixed picture sizes, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

.. seealso:: :py:func:`fixedSizeUnit`

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

bool lockAspectRatio() const;
Expand Down
7 changes: 7 additions & 0 deletions python/PyQt6/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,12 @@ The development version
typedef QFlags<Qgis::AnnotationItemFlag> AnnotationItemFlags;


enum class AnnotationPictureSizeMode /BaseType=IntEnum/
{
SpatialBounds,
FixedSize,
};

enum class AnnotationItemGuiFlag /BaseType=IntFlag/
{
FlagNoCreationTools,
Expand Down Expand Up @@ -2559,6 +2565,7 @@ The development version
Unknown,
};


enum class ScaleBarAlignment /BaseType=IntEnum/
{
Left,
Expand Down
6 changes: 6 additions & 0 deletions python/core/auto_additions/qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,12 @@
Qgis.AnnotationItemFlags.baseClass = Qgis
AnnotationItemFlags = Qgis # dirty hack since SIP seems to introduce the flags in module
# monkey patching scoped based enum
Qgis.AnnotationPictureSizeMode.SpatialBounds.__doc__ = "Picture is rendered inside spatial bounds, and size will depend on map scale"
Qgis.AnnotationPictureSizeMode.FixedSize.__doc__ = "Picture is rendered at a fixed size, regardless of map scale"
Qgis.AnnotationPictureSizeMode.__doc__ = "Picture annotation item size modes.\n\n.. versionadded:: 3.40\n\n" + '* ``SpatialBounds``: ' + Qgis.AnnotationPictureSizeMode.SpatialBounds.__doc__ + '\n' + '* ``FixedSize``: ' + Qgis.AnnotationPictureSizeMode.FixedSize.__doc__
# --
Qgis.AnnotationPictureSizeMode.baseClass = Qgis
# monkey patching scoped based enum
Qgis.AnnotationItemGuiFlag.FlagNoCreationTools.__doc__ = "Do not show item creation tools for the item type"
Qgis.AnnotationItemGuiFlag.__doc__ = "Flags for controlling how an annotation item behaves in the GUI.\n\n.. versionadded:: 3.22\n\n" + '* ``FlagNoCreationTools``: ' + Qgis.AnnotationItemGuiFlag.FlagNoCreationTools.__doc__
# --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ within the specified ``bounds`` geometry.

virtual QString type() const;

virtual Qgis::AnnotationItemFlags flags() const;

virtual void render( QgsRenderContext &context, QgsFeedback *feedback );

virtual bool writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const;
Expand All @@ -53,13 +55,18 @@ Creates a new polygon annotation item.

virtual QgsRectangle boundingBox() const;

virtual QgsRectangle boundingBox( QgsRenderContext &context ) const;


QgsRectangle bounds() const;
%Docstring
Returns the bounds of the picture.

The coordinate reference system for the bounds will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

When the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize then the picture will be placed
at the center of the bounds.

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

Expand All @@ -69,6 +76,9 @@ Sets the ``bounds`` of the picture.

The coordinate reference system for the bounds will be the parent layer's :py:func:`QgsAnnotationLayer.crs()`.

When the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize then the picture will be placed
at the center of the bounds.

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

Expand All @@ -91,6 +101,60 @@ Sets the ``format`` and ``path`` of the image used to render the item.
.. seealso:: :py:func:`path`

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

Qgis::AnnotationPictureSizeMode sizeMode() const;
%Docstring
Returns the size mode for the picture.

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

void setSizeMode( Qgis::AnnotationPictureSizeMode mode );
%Docstring
Sets the size ``mode`` for the picture.

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

QSizeF fixedSize() const;
%Docstring
Returns the fixed size to use for the picture, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

Units are retrieved via :py:func:`~QgsAnnotationPictureItem.fixedSizeUnit`

.. seealso:: :py:func:`setFixedSize`

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

void setFixedSize( const QSizeF &size );
%Docstring
Sets the fixed ``size`` to use for the picture, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

Units are set via :py:func:`~QgsAnnotationPictureItem.setFixedSizeUnit`

.. seealso:: :py:func:`fixedSize`

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

Qgis::RenderUnit fixedSizeUnit() const;
%Docstring
Returns the units to use for fixed picture sizes, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

.. seealso:: :py:func:`setFixedSizeUnit`

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

void setFixedSizeUnit( Qgis::RenderUnit unit );
%Docstring
Sets the ``unit`` to use for fixed picture sizes, when the :py:func:`~QgsAnnotationPictureItem.sizeMode` is :py:class:`Qgis`.AnnotationPictureSizeMode.FixedSize.

.. seealso:: :py:func:`fixedSizeUnit`

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

bool lockAspectRatio() const;
Expand Down
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgis.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,12 @@ The development version
typedef QFlags<Qgis::AnnotationItemFlag> AnnotationItemFlags;


enum class AnnotationPictureSizeMode
{
SpatialBounds,
FixedSize,
};

enum class AnnotationItemGuiFlag
{
FlagNoCreationTools,
Expand Down Expand Up @@ -2559,6 +2565,7 @@ The development version
Unknown,
};


enum class ScaleBarAlignment
{
Left,
Expand Down
Loading

0 comments on commit cd99d2c

Please sign in to comment.