Skip to content

Commit 1bfed13

Browse files
committed
Port picture item
1 parent 20b9d08 commit 1bfed13

File tree

41 files changed

+3836
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3836
-1
lines changed

python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@
414414
%Include layout/qgslayoutitemmapoverview.sip
415415
%Include layout/qgslayoutitemnodeitem.sip
416416
%Include layout/qgslayoutitempage.sip
417+
%Include layout/qgslayoutitempicture.sip
417418
%Include layout/qgslayoutitempolygon.sip
418419
%Include layout/qgslayoutitempolyline.sip
419420
%Include layout/qgslayoutitemregistry.sip

python/core/layout/qgslayoutitem.sip

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
7575
UndoMapGridAnnotationFontColor,
7676
UndoMapGridLineSymbol,
7777
UndoMapGridMarkerSymbol,
78+
UndoPictureRotation,
79+
UndoPictureFillColor,
80+
UndoPictureStrokeColor,
81+
UndoPictureNorthOffset,
82+
UndoCustomCommand,
7883
};
7984

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

704+
virtual QSizeF applyItemSizeConstraint( const QSizeF &targetSize );
705+
%Docstring
706+
Applies any item-specific size constraint handling to a given ``targetSize`` in layout units.
707+
Subclasses can override this method if they need to apply advanced logic regarding item
708+
sizes, which cannot be covered by setFixedSize() or setMinimumSize().
709+
Item size constraints are applied after fixed, minimum and data defined size constraints.
710+
.. seealso:: setFixedSize()
711+
.. seealso:: setMinimumSize()
712+
:rtype: QSizeF
713+
%End
714+
699715
void refreshItemSize();
700716
%Docstring
701717
Refreshes an item's size by rechecking it against any possible item fixed
@@ -798,6 +814,12 @@ class QgsLayoutItem : QgsLayoutObject, QGraphicsRectItem, QgsLayoutUndoObjectInt
798814
:rtype: bool
799815
%End
800816

817+
QgsLayoutSize applyDataDefinedSize( const QgsLayoutSize &size );
818+
%Docstring
819+
Applies any present data defined size overrides to the specified layout ``size``.
820+
:rtype: QgsLayoutSize
821+
%End
822+
801823
};
802824

803825

Lines changed: 293 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,293 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutitempicture.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLayoutItemPicture: QgsLayoutItem
13+
{
14+
%Docstring
15+
A layout item subclass that displays SVG files or raster format images (jpg, png, ...).
16+
.. versionadded:: 3.0
17+
%End
18+
19+
%TypeHeaderCode
20+
#include "qgslayoutitempicture.h"
21+
%End
22+
public:
23+
24+
enum ResizeMode
25+
{
26+
Zoom,
27+
Stretch,
28+
Clip,
29+
ZoomResizeFrame,
30+
FrameToImageSize
31+
};
32+
33+
enum Format
34+
{
35+
FormatSVG,
36+
FormatRaster,
37+
FormatUnknown,
38+
};
39+
40+
enum NorthMode
41+
{
42+
GridNorth,
43+
TrueNorth,
44+
};
45+
46+
QgsLayoutItemPicture( QgsLayout *layout );
47+
%Docstring
48+
Constructor for QgsLayoutItemPicture, with the specified parent ``layout``.
49+
%End
50+
51+
virtual int type() const;
52+
53+
virtual QString stringType() const;
54+
55+
56+
static QgsLayoutItemPicture *create( QgsLayout *layout ) /Factory/;
57+
%Docstring
58+
Returns a new picture item for the specified ``layout``.
59+
60+
The caller takes responsibility for deleting the returned object.
61+
:rtype: QgsLayoutItemPicture
62+
%End
63+
64+
65+
void setPicturePath( const QString &path );
66+
%Docstring
67+
Sets the source ``path`` of the image (may be svg or a raster format). Data defined
68+
picture source may override this value. The path can either be a local path
69+
or a remote (http) path.
70+
.. seealso:: picturePath()
71+
%End
72+
73+
QString picturePath() const;
74+
%Docstring
75+
Returns the path of the source image. Data defined picture source may override
76+
this value. The path can either be a local path or a remote (http) path.
77+
:return: path for the source image
78+
.. seealso:: usePictureExpression()
79+
.. seealso:: setPicturePath()
80+
:rtype: str
81+
%End
82+
83+
84+
85+
86+
double pictureRotation() const;
87+
%Docstring
88+
Returns the rotation used for drawing the picture within the item's frame,
89+
in degrees clockwise.
90+
.. seealso:: setPictureRotation()
91+
.. seealso:: rotationMap()
92+
:rtype: float
93+
%End
94+
95+
void setRotationMap( const QString &uuid );
96+
%Docstring
97+
Sets the map object for rotation (by ``uuid``). A empty string disables the map
98+
rotation. If this is set then the picture will be rotated by the same
99+
amount as the specified map object. This is useful especially for
100+
syncing north arrows with a map item.
101+
.. seealso:: setPictureRotation()
102+
.. seealso:: rotationMap()
103+
%End
104+
105+
QString rotationMap() const;
106+
%Docstring
107+
Returns the uuid of the rotation map. An empty string means map rotation is
108+
disabled. If this is set then the picture is rotated by the same amount
109+
as the specified map object.
110+
.. seealso:: setRotationMap()
111+
.. seealso:: useRotationMap()
112+
:rtype: str
113+
%End
114+
115+
bool useRotationMap() const;
116+
%Docstring
117+
True if the picture rotation is matched to a map item.
118+
.. seealso:: rotationMap()
119+
.. seealso:: setRotationMap()
120+
:rtype: bool
121+
%End
122+
123+
NorthMode northMode() const;
124+
%Docstring
125+
Returns the mode used to align the picture to a map's North.
126+
.. seealso:: setNorthMode()
127+
.. seealso:: northOffset()
128+
:rtype: NorthMode
129+
%End
130+
131+
void setNorthMode( NorthMode mode );
132+
%Docstring
133+
Sets the ``mode`` used to align the picture to a map's North.
134+
.. seealso:: northMode()
135+
.. seealso:: setNorthOffset()
136+
%End
137+
138+
double northOffset() const;
139+
%Docstring
140+
Returns the offset added to the picture's rotation from a map's North.
141+
.. seealso:: setNorthOffset()
142+
.. seealso:: northMode()
143+
:rtype: float
144+
%End
145+
146+
void setNorthOffset( double offset );
147+
%Docstring
148+
Sets the ``offset`` added to the picture's rotation from a map's North.
149+
.. seealso:: northOffset()
150+
.. seealso:: setNorthMode()
151+
%End
152+
153+
ResizeMode resizeMode() const;
154+
%Docstring
155+
Returns the resize mode used for drawing the picture within the composer
156+
item's frame.
157+
.. seealso:: setResizeMode()
158+
:rtype: ResizeMode
159+
%End
160+
161+
void setPictureAnchor( QgsLayoutItem::ReferencePoint anchor );
162+
%Docstring
163+
Sets the picture's ``anchor`` point, which controls how it is placed
164+
within the picture item's frame.
165+
.. seealso:: pictureAnchor()
166+
%End
167+
168+
QgsLayoutItem::ReferencePoint pictureAnchor() const;
169+
%Docstring
170+
Returns the picture's current anchor, which controls how it is placed
171+
within the picture item's frame.
172+
.. seealso:: setPictureAnchor()
173+
:rtype: QgsLayoutItem.ReferencePoint
174+
%End
175+
176+
QColor svgFillColor() const;
177+
%Docstring
178+
Returns the fill color used for parametrized SVG files.
179+
.. seealso:: setSvgFillColor()
180+
.. seealso:: svgStrokeColor()
181+
:rtype: QColor
182+
%End
183+
184+
void setSvgFillColor( const QColor &color );
185+
%Docstring
186+
Sets the fill ``color`` used for parametrized SVG files.
187+
.. note::
188+
189+
This setting only has an effect on parametrized SVG files, and is ignored for
190+
non-parametrized SVG files.
191+
.. seealso:: svgFillColor()
192+
.. seealso:: setSvgStrokeColor()
193+
%End
194+
195+
QColor svgStrokeColor() const;
196+
%Docstring
197+
Returns the stroke color used for parametrized SVG files.
198+
.. seealso:: setSvgStrokeColor()
199+
.. seealso:: svgFillColor()
200+
:rtype: QColor
201+
%End
202+
203+
void setSvgStrokeColor( const QColor &color );
204+
%Docstring
205+
Sets the stroke ``color`` used for parametrized SVG files.
206+
\param color stroke color.
207+
.. note::
208+
209+
This setting only has an effect on parametrized SVG files, and is ignored for
210+
non-parametrized SVG files.
211+
.. seealso:: svgStrokelColor()
212+
.. seealso:: setSvgFillColor()
213+
%End
214+
215+
double svgStrokeWidth() const;
216+
%Docstring
217+
Returns the stroke width (in layout units) used for parametrized SVG files.
218+
.. seealso:: setSvgStrokeWidth()
219+
.. seealso:: svgStrokeColor()
220+
:rtype: float
221+
%End
222+
223+
void setSvgStrokeWidth( double width );
224+
%Docstring
225+
Sets the stroke ``width`` (in layout units) used for parametrized SVG files.
226+
.. note::
227+
228+
This setting only has an effect on parametrized SVG files, and is ignored for
229+
non-parametrized SVG files.
230+
.. seealso:: svgStrokeWidth()
231+
.. seealso:: setSvgStrokeColor()
232+
%End
233+
234+
Format mode() const;
235+
%Docstring
236+
Returns the current picture mode (image format).
237+
:rtype: Format
238+
%End
239+
240+
public slots:
241+
242+
void setPictureRotation( double rotation );
243+
%Docstring
244+
Sets the picture ``rotation`` within the item bounds, in degrees clockwise. This does not affect
245+
the item's frame, only the way the picture is drawn within the item.
246+
.. seealso:: pictureRotation()
247+
%End
248+
249+
void setResizeMode( ResizeMode mode );
250+
%Docstring
251+
Sets the resize ``mode`` used for drawing the picture within the item bounds.
252+
\param mode ResizeMode to use for image file
253+
.. seealso:: resizeMode
254+
%End
255+
256+
void refreshPicture( const QgsExpressionContext *context = 0 );
257+
%Docstring
258+
Recalculates the source image (if using an expression for picture's source)
259+
and reloads and redraws the picture.
260+
\param context expression context for evaluating data defined picture sources
261+
%End
262+
263+
void recalculateSize();
264+
%Docstring
265+
Forces a recalculation of the picture's frame size
266+
%End
267+
268+
virtual void refreshDataDefinedProperty( const QgsLayoutObject::DataDefinedProperty property = QgsLayoutObject::AllProperties );
269+
270+
271+
signals:
272+
void pictureRotationChanged( double newRotation );
273+
%Docstring
274+
Is emitted on picture rotation change
275+
%End
276+
277+
protected:
278+
279+
virtual void draw( QgsRenderContext &context, const QStyleOptionGraphicsItem *itemStyle = 0 );
280+
281+
virtual QSizeF applyItemSizeConstraint( const QSizeF &targetSize );
282+
283+
284+
285+
};
286+
287+
/************************************************************************
288+
* This file has been generated automatically from *
289+
* *
290+
* src/core/layout/qgslayoutitempicture.h *
291+
* *
292+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
293+
************************************************************************/

python/core/layout/qgslayoutitemregistry.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class QgsLayoutItemRegistry : QObject
103103
// known
104104
LayoutPage,
105105
LayoutMap,
106+
LayoutPicture,
106107
LayoutShape,
107108
LayoutPolygon,
108109
LayoutPolyline,

python/core/layout/qgslayoututils.sip

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,18 @@ class QgsLayoutUtils
185185
The ``flags`` parameter allows for passing Qt.TextFlags to control appearance of rendered text.
186186
%End
187187

188+
static QRectF largestRotatedRectWithinBounds( const QRectF &originalRect, const QRectF &boundsRect, const double rotation );
189+
%Docstring
190+
Calculates the largest scaled version of ``originalRect`` which fits within ``boundsRect``, when it is rotated by
191+
the a specified ``rotation`` amount.
192+
\param originalRect QRectF to be rotated and scaled
193+
\param boundsRect QRectF specifying the bounds which the rotated and scaled rectangle must fit within
194+
\param rotation the rotation in degrees to be applied to the rectangle
195+
:return: largest scaled version of the rectangle possible
196+
:rtype: QRectF
197+
%End
198+
199+
188200
};
189201

190202
/************************************************************************

src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ SET(QGIS_APP_SRCS
182182
layout/qgslayoutmapwidget.cpp
183183
layout/qgslayoutmapgridwidget.cpp
184184
layout/qgslayoutpagepropertieswidget.cpp
185+
layout/qgslayoutpicturewidget.cpp
185186
layout/qgslayoutpolygonwidget.cpp
186187
layout/qgslayoutpolylinewidget.cpp
187188
layout/qgslayoutpropertieswidget.cpp
@@ -383,6 +384,7 @@ SET (QGIS_APP_MOC_HDRS
383384
layout/qgslayoutmapwidget.h
384385
layout/qgslayoutmapgridwidget.h
385386
layout/qgslayoutpagepropertieswidget.h
387+
layout/qgslayoutpicturewidget.h
386388
layout/qgslayoutpolygonwidget.h
387389
layout/qgslayoutpolylinewidget.h
388390
layout/qgslayoutpropertieswidget.h

0 commit comments

Comments
 (0)