Skip to content
Permalink
Browse files

Port picture item

  • Loading branch information
nyalldawson committed Oct 23, 2017
1 parent 20b9d08 commit 1bfed134841bd3ad77901897bfae4c6a284bbee3
Showing with 3,836 additions and 1 deletion.
  1. +1 −0 python/core/core_auto.sip
  2. +22 −0 python/core/layout/qgslayoutitem.sip
  3. +293 −0 python/core/layout/qgslayoutitempicture.sip
  4. +1 −0 python/core/layout/qgslayoutitemregistry.sip
  5. +12 −0 python/core/layout/qgslayoututils.sip
  6. +2 −0 src/app/CMakeLists.txt
  7. +19 −0 src/app/layout/qgslayoutapputils.cpp
  8. +747 −0 src/app/layout/qgslayoutpicturewidget.cpp
  9. +102 −0 src/app/layout/qgslayoutpicturewidget.h
  10. +2 −0 src/core/CMakeLists.txt
  11. +12 −0 src/core/layout/qgslayoutitem.cpp
  12. +21 −1 src/core/layout/qgslayoutitem.h
  13. +863 −0 src/core/layout/qgslayoutitempicture.cpp
  14. +378 −0 src/core/layout/qgslayoutitempicture.h
  15. +2 −0 src/core/layout/qgslayoutitemregistry.cpp
  16. +1 −0 src/core/layout/qgslayoutitemregistry.h
  17. +85 −0 src/core/layout/qgslayoututils.cpp
  18. +11 −0 src/core/layout/qgslayoututils.h
  19. +619 −0 src/ui/layout/qgslayoutpicturewidgetbase.ui
  20. +1 −0 tests/src/core/CMakeLists.txt
  21. +426 −0 tests/src/core/testqgslayoutpicture.cpp
  22. +66 −0 tests/src/core/testqgslayoututils.cpp
  23. +1 −0 tests/src/python/CMakeLists.txt
  24. +149 −0 tests/src/python/test_qgslayoutpicture.py
  25. BIN ...er_picture/expected_composerpicture_badexpression/expected_composerpicture_badexpression_mask.png
  26. BIN ...mposer_picture/expected_composerpicture_clip_anchor/expected_composerpicture_clip_anchor_mask.png
  27. BIN ...xpected_composerpicture_clip_anchoroversize/expected_composerpicture_clip_anchoroversize_mask.png
  28. BIN ...composer_picture/expected_composerpicture_expression/expected_composerpicture_expression_mask.png
  29. BIN ...oser_picture/expected_composerpicture_itemrotation/expected_composerpicture_itemrotation_mask.png
  30. BIN ...ntrol_images/composer_picture/expected_composerpicture_render/expected_composerpicture_render.png
  31. BIN ...mposer_picture/expected_composerpicture_resize_clip/expected_composerpicture_resize_clip_mask.png
  32. BIN ...xpected_composerpicture_resize_frametoimage/expected_composerpicture_resize_frametoimage_mask.png
  33. BIN ..._picture/expected_composerpicture_resize_stretch/expected_composerpicture_resize_stretch_mask.png
  34. BIN ...mposer_picture/expected_composerpicture_resize_zoom/expected_composerpicture_resize_zoom_mask.png
  35. BIN ...re/expected_composerpicture_resize_zoomresize/expected_composerpicture_resize_zoomresize_mask.png
  36. BIN ...ges/composer_picture/expected_composerpicture_rotation/expected_composerpicture_rotation_mask.png
  37. BIN ...ture/expected_composerpicture_svg_frametoimage/expected_composerpicture_svg_frametoimage_mask.png
  38. BIN ...composer_picture/expected_composerpicture_svg_params/expected_composerpicture_svg_params_mask.png
  39. BIN ...mposer_picture/expected_composerpicture_svg_stretch/expected_composerpicture_svg_stretch_mask.png
  40. BIN ...ges/composer_picture/expected_composerpicture_svg_zoom/expected_composerpicture_svg_zoom_mask.png
  41. BIN ...mposer_picture/expected_composerpicture_zoom_anchor/expected_composerpicture_zoom_anchor_mask.png
@@ -414,6 +414,7 @@
%Include layout/qgslayoutitemmapoverview.sip
%Include layout/qgslayoutitemnodeitem.sip
%Include layout/qgslayoutitempage.sip
%Include layout/qgslayoutitempicture.sip
%Include layout/qgslayoutitempolygon.sip
%Include layout/qgslayoutitempolyline.sip
%Include layout/qgslayoutitemregistry.sip
@@ -75,6 +75,11 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
UndoMapGridAnnotationFontColor,
UndoMapGridLineSymbol,
UndoMapGridMarkerSymbol,
UndoPictureRotation,
UndoPictureFillColor,
UndoPictureStrokeColor,
UndoPictureNorthOffset,
UndoCustomCommand,
};

explicit QgsLayoutItem( QgsLayout *layout, bool manageZValue = true );
@@ -696,6 +701,17 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
.. seealso:: setFixedSize()
%End

virtual QSizeF applyItemSizeConstraint( const QSizeF &targetSize );
%Docstring
Applies any item-specific size constraint handling to a given ``targetSize`` in layout units.
Subclasses can override this method if they need to apply advanced logic regarding item
sizes, which cannot be covered by setFixedSize() or setMinimumSize().
Item size constraints are applied after fixed, minimum and data defined size constraints.
.. seealso:: setFixedSize()
.. seealso:: setMinimumSize()
:rtype: QSizeF
%End

void refreshItemSize();
%Docstring
Refreshes an item's size by rechecking it against any possible item fixed
@@ -798,6 +814,12 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
:rtype: bool
%End

QgsLayoutSize applyDataDefinedSize( const QgsLayoutSize &size );
%Docstring
Applies any present data defined size overrides to the specified layout ``size``.
:rtype: QgsLayoutSize
%End

};


@@ -0,0 +1,293 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitempicture.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




class QgsLayoutItemPicture: QgsLayoutItem
{
%Docstring
A layout item subclass that displays SVG files or raster format images (jpg, png, ...).
.. versionadded:: 3.0
%End

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

enum ResizeMode
{
Zoom,
Stretch,
Clip,
ZoomResizeFrame,
FrameToImageSize
};

enum Format
{
FormatSVG,
FormatRaster,
FormatUnknown,
};

enum NorthMode
{
GridNorth,
TrueNorth,
};

QgsLayoutItemPicture( QgsLayout *layout );
%Docstring
Constructor for QgsLayoutItemPicture, with the specified parent ``layout``.
%End

virtual int type() const;

virtual QString stringType() const;


static QgsLayoutItemPicture *create( QgsLayout *layout ) /Factory/;
%Docstring
Returns a new picture item for the specified ``layout``.

The caller takes responsibility for deleting the returned object.
:rtype: QgsLayoutItemPicture
%End


void setPicturePath( const QString &path );
%Docstring
Sets the source ``path`` of the image (may be svg or a raster format). Data defined
picture source may override this value. The path can either be a local path
or a remote (http) path.
.. seealso:: picturePath()
%End

QString picturePath() const;
%Docstring
Returns the path of the source image. Data defined picture source may override
this value. The path can either be a local path or a remote (http) path.
:return: path for the source image
.. seealso:: usePictureExpression()
.. seealso:: setPicturePath()
:rtype: str
%End




double pictureRotation() const;
%Docstring
Returns the rotation used for drawing the picture within the item's frame,
in degrees clockwise.
.. seealso:: setPictureRotation()
.. seealso:: rotationMap()
:rtype: float
%End

void setRotationMap( const QString &uuid );
%Docstring
Sets the map object for rotation (by ``uuid``). A empty string disables the map
rotation. If this is set then the picture will be rotated by the same
amount as the specified map object. This is useful especially for
syncing north arrows with a map item.
.. seealso:: setPictureRotation()
.. seealso:: rotationMap()
%End

QString rotationMap() const;
%Docstring
Returns the uuid of the rotation map. An empty string means map rotation is
disabled. If this is set then the picture is rotated by the same amount
as the specified map object.
.. seealso:: setRotationMap()
.. seealso:: useRotationMap()
:rtype: str
%End

bool useRotationMap() const;
%Docstring
True if the picture rotation is matched to a map item.
.. seealso:: rotationMap()
.. seealso:: setRotationMap()
:rtype: bool
%End

NorthMode northMode() const;
%Docstring
Returns the mode used to align the picture to a map's North.
.. seealso:: setNorthMode()
.. seealso:: northOffset()
:rtype: NorthMode
%End

void setNorthMode( NorthMode mode );
%Docstring
Sets the ``mode`` used to align the picture to a map's North.
.. seealso:: northMode()
.. seealso:: setNorthOffset()
%End

double northOffset() const;
%Docstring
Returns the offset added to the picture's rotation from a map's North.
.. seealso:: setNorthOffset()
.. seealso:: northMode()
:rtype: float
%End

void setNorthOffset( double offset );
%Docstring
Sets the ``offset`` added to the picture's rotation from a map's North.
.. seealso:: northOffset()
.. seealso:: setNorthMode()
%End

ResizeMode resizeMode() const;
%Docstring
Returns the resize mode used for drawing the picture within the composer
item's frame.
.. seealso:: setResizeMode()
:rtype: ResizeMode
%End

void setPictureAnchor( QgsLayoutItem::ReferencePoint anchor );
%Docstring
Sets the picture's ``anchor`` point, which controls how it is placed
within the picture item's frame.
.. seealso:: pictureAnchor()
%End

QgsLayoutItem::ReferencePoint pictureAnchor() const;
%Docstring
Returns the picture's current anchor, which controls how it is placed
within the picture item's frame.
.. seealso:: setPictureAnchor()
:rtype: QgsLayoutItem.ReferencePoint
%End

QColor svgFillColor() const;
%Docstring
Returns the fill color used for parametrized SVG files.
.. seealso:: setSvgFillColor()
.. seealso:: svgStrokeColor()
:rtype: QColor
%End

void setSvgFillColor( const QColor &color );
%Docstring
Sets the fill ``color`` used for parametrized SVG files.
.. note::

This setting only has an effect on parametrized SVG files, and is ignored for
non-parametrized SVG files.
.. seealso:: svgFillColor()
.. seealso:: setSvgStrokeColor()
%End

QColor svgStrokeColor() const;
%Docstring
Returns the stroke color used for parametrized SVG files.
.. seealso:: setSvgStrokeColor()
.. seealso:: svgFillColor()
:rtype: QColor
%End

void setSvgStrokeColor( const QColor &color );
%Docstring
Sets the stroke ``color`` used for parametrized SVG files.
\param color stroke color.
.. note::

This setting only has an effect on parametrized SVG files, and is ignored for
non-parametrized SVG files.
.. seealso:: svgStrokelColor()
.. seealso:: setSvgFillColor()
%End

double svgStrokeWidth() const;
%Docstring
Returns the stroke width (in layout units) used for parametrized SVG files.
.. seealso:: setSvgStrokeWidth()
.. seealso:: svgStrokeColor()
:rtype: float
%End

void setSvgStrokeWidth( double width );
%Docstring
Sets the stroke ``width`` (in layout units) used for parametrized SVG files.
.. note::

This setting only has an effect on parametrized SVG files, and is ignored for
non-parametrized SVG files.
.. seealso:: svgStrokeWidth()
.. seealso:: setSvgStrokeColor()
%End

Format mode() const;
%Docstring
Returns the current picture mode (image format).
:rtype: Format
%End

public slots:

void setPictureRotation( double rotation );
%Docstring
Sets the picture ``rotation`` within the item bounds, in degrees clockwise. This does not affect
the item's frame, only the way the picture is drawn within the item.
.. seealso:: pictureRotation()
%End

void setResizeMode( ResizeMode mode );
%Docstring
Sets the resize ``mode`` used for drawing the picture within the item bounds.
\param mode ResizeMode to use for image file
.. seealso:: resizeMode
%End

void refreshPicture( const QgsExpressionContext *context = 0 );
%Docstring
Recalculates the source image (if using an expression for picture's source)
and reloads and redraws the picture.
\param context expression context for evaluating data defined picture sources
%End

void recalculateSize();
%Docstring
Forces a recalculation of the picture's frame size
%End

virtual void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );


signals:
void pictureRotationChanged( double newRotation );
%Docstring
Is emitted on picture rotation change
%End

protected:

virtual void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );

virtual QSizeF applyItemSizeConstraint( const QSizeF &targetSize );



};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/layout/qgslayoutitempicture.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -103,6 +103,7 @@ class QgsLayoutItemRegistry : QObject
// known
LayoutPage,
LayoutMap,
LayoutPicture,
LayoutShape,
LayoutPolygon,
LayoutPolyline,
@@ -185,6 +185,18 @@ class QgsLayoutUtils
The ``flags`` parameter allows for passing Qt.TextFlags to control appearance of rendered text.
%End

static QRectF largestRotatedRectWithinBounds( const QRectF &originalRect, const QRectF &boundsRect, const double rotation );
%Docstring
Calculates the largest scaled version of ``originalRect`` which fits within ``boundsRect``, when it is rotated by
the a specified ``rotation`` amount.
\param originalRect QRectF to be rotated and scaled
\param boundsRect QRectF specifying the bounds which the rotated and scaled rectangle must fit within
\param rotation the rotation in degrees to be applied to the rectangle
:return: largest scaled version of the rectangle possible
:rtype: QRectF
%End


};

/************************************************************************
@@ -182,6 +182,7 @@ SET(QGIS_APP_SRCS
layout/qgslayoutmapwidget.cpp
layout/qgslayoutmapgridwidget.cpp
layout/qgslayoutpagepropertieswidget.cpp
layout/qgslayoutpicturewidget.cpp
layout/qgslayoutpolygonwidget.cpp
layout/qgslayoutpolylinewidget.cpp
layout/qgslayoutpropertieswidget.cpp
@@ -383,6 +384,7 @@ SET (QGIS_APP_MOC_HDRS
layout/qgslayoutmapwidget.h
layout/qgslayoutmapgridwidget.h
layout/qgslayoutpagepropertieswidget.h
layout/qgslayoutpicturewidget.h
layout/qgslayoutpolygonwidget.h
layout/qgslayoutpolylinewidget.h
layout/qgslayoutpropertieswidget.h

0 comments on commit 1bfed13

Please sign in to comment.
You can’t perform that action at this time.