QGIS API Documentation 4.1.0-Master (009143bf4b4)
Loading...
Searching...
No Matches
qgslayoutitempicture.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutitempicture.h
3 -------------------
4begin : October 2017
5copyright : (C) 2017 by Nyall Dawson
6email : nyall dot dawson at gmail dot com
7***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17#ifndef QGSLAYOUTITEMPICTURE_H
18#define QGSLAYOUTITEMPICTURE_H
19
20#include "qgis_core.h"
21#include "qgslayoutitem.h"
22
23#include <QFile>
24#include <QImage>
25#include <QSvgRenderer>
26
28class QgsExpression;
30
35class CORE_EXPORT QgsLayoutItemPicture : public QgsLayoutItem
36{
37 Q_OBJECT
38 public:
50
53 {
56 };
57
62
63 int type() const override;
64 QIcon icon() const override;
65
71 static QgsLayoutItemPicture *create( QgsLayout *layout ) SIP_FACTORY;
72
73
83 void setPicturePath( const QString &path, Qgis::PictureFormat format = Qgis::PictureFormat::Unknown );
84
92 QString picturePath() const;
93
100 double pictureRotation() const { return mPictureRotation; }
101
112 void setLinkedMap( QgsLayoutItemMap *map );
113
120 QgsLayoutItemMap *linkedMap() const;
121
127 NorthMode northMode() const;
128
134 void setNorthMode( NorthMode mode );
135
141 double northOffset() const;
142
148 void setNorthOffset( double offset );
149
155 ResizeMode resizeMode() const { return mResizeMode; }
156
162 void setPictureAnchor( QgsLayoutItem::ReferencePoint anchor );
163
169 QgsLayoutItem::ReferencePoint pictureAnchor() const { return mPictureAnchor; }
170
176 QColor svgFillColor() const { return mSvgFillColor; }
177
185 void setSvgFillColor( const QColor &color );
186
192 QColor svgStrokeColor() const { return mSvgStrokeColor; }
193
202 void setSvgStrokeColor( const QColor &color );
203
209 double svgStrokeWidth() const { return mSvgStrokeWidth; }
210
218 void setSvgStrokeWidth( double width );
219
226 Qgis::PictureFormat mode() const { return mMode; }
227
235 Qgis::PictureFormat originalMode() const { return mOriginalMode; }
236
242 void setMode( Qgis::PictureFormat mode );
243
244 void finalizeRestoreFromXml() override;
245
252 bool isMissingImage() const;
253
261 QString evaluatedPath() const;
262
267 QMap<QString, QgsProperty> svgDynamicParameters() const;
268
273 void setSvgDynamicParameters( const QMap<QString, QgsProperty> &parameters );
274
275 public slots:
276
282 void setPictureRotation( double rotation );
283
289 void setResizeMode( QgsLayoutItemPicture::ResizeMode mode );
290
298 bool clipToItem() const;
299
307 void setClipToItem( bool clipToItem );
308
317 QgsLayoutItem *clippingItem() const;
318
327 void setClippingItem( QgsLayoutItem *item );
328
334 void refreshPicture( const QgsExpressionContext *context = nullptr );
335
339 void recalculateSize();
340
342
343 signals:
345 void pictureRotationChanged( double newRotation );
346
347 protected:
348 void draw( QgsLayoutItemRenderContext &context ) override;
349 QPainterPath framePath() const override;
350 QSizeF applyItemSizeConstraint( QSizeF targetSize ) override;
351 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
352 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
353
354 private:
355 QgsLayoutItemPicture() = delete;
356
358 QSizeF pictureSize();
359
360 QImage mImage;
361 QSvgRenderer mSVG;
363 QString mSourcePath;
366
367 QSize mDefaultSvgSize;
368
370 double mPictureRotation = 0;
371
372 QString mRotationMapUuid;
373
375 double mPictureWidth = 0.0;
377 double mPictureHeight = 0.0;
378
381
382 QColor mSvgFillColor = QColor( 255, 255, 255 );
383 QColor mSvgStrokeColor = QColor( 0, 0, 0 );
384 double mSvgStrokeWidth = 0.2;
385
386 bool mHasExpressionError = false;
387 bool mLoaded = false;
388 bool mLoadingSvg = false;
389 bool mIsMissingImage = false;
390 QString mEvaluatedPath;
391
392 QgsLayoutNorthArrowHandler *mNorthArrowHandler = nullptr;
393
394 bool mClipToItem = false;
395 QPointer< QgsLayoutItem > mClippingItem;
396 QString mClippingItemUuid;
397
399 void loadPicture( const QVariant &data );
400
405 QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
406
410 void loadRemotePicture( const QString &url );
411
415 void loadLocalPicture( const QString &path );
416
417 void loadPictureUsingCache( const QString &path );
418
419 QPainterPath customFramePath() const;
420
421 QgsLayoutItemPicture( const QgsLayoutItemPicture & ) = delete;
422 QgsLayoutItemPicture &operator=( const QgsLayoutItemPicture & ) = delete;
423
424 private slots:
425
426 void updateNorthArrowRotation( double rotation );
427
428 void shapeChanged();
429
432};
433
434#endif // QGSLAYOUTITEMPICTURE_H
PictureFormat
Picture formats.
Definition qgis.h:5564
@ Unknown
Invalid or unknown image type.
Definition qgis.h:5567
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles parsing and evaluation of expressions (formerly called "search strings").
Layout graphical items for displaying a map.
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
double pictureRotation() const
Returns the rotation used for drawing the picture within the item's frame, in degrees clockwise.
QColor svgStrokeColor() const
Returns the stroke color used for parametrized SVG files.
QgsLayoutItemPicture(QgsLayout *layout)
Constructor for QgsLayoutItemPicture, with the specified parent layout.
QgsLayoutItem::ReferencePoint pictureAnchor() const
Returns the picture's current anchor, which controls how it is placed within the picture item's frame...
double svgStrokeWidth() const
Returns the stroke width (in layout units) used for parametrized SVG files.
Qgis::PictureFormat originalMode() const
Returns the original set picture mode (image format).
void pictureRotationChanged(double newRotation)
Emitted on picture rotation change.
ResizeMode resizeMode() const
Returns the resize mode used for drawing the picture within the layout item's frame.
Qgis::PictureFormat mode() const
Returns the current picture mode (image format), FormatUnknown if given picture format is unknown.
NorthMode
Method for syncing rotation to a map's North direction.
@ GridNorth
Align to grid north.
@ TrueNorth
Align to true north.
friend class TestQgsCompositionConverter
QColor svgFillColor() const
Returns the fill color used for parametrized SVG files.
ResizeMode
Controls how pictures are scaled within the item's frame.
@ FrameToImageSize
Sets size of frame to match original size of image without scaling.
@ ZoomResizeFrame
Enlarges image to fit frame, then resizes frame to fit resultant image.
@ Clip
Draws image at original size and clips any portion which falls outside frame.
@ Stretch
Stretches image to fit frame, ignores aspect ratio.
@ Zoom
Enlarges image to fit frame while maintaining aspect ratio of picture.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Base class for graphical items within a QgsLayout.
virtual QPainterPath framePath() const
Returns the path to use when drawing the item's frame or background.
virtual void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::DataDefinedProperty::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
QgsLayoutItem(QgsLayout *layout, bool manageZValue=true)
Constructor for QgsLayoutItem, with the specified parent layout.
virtual QIcon icon() const
Returns the item's icon.
ReferencePoint
Fixed position reference point.
@ UpperLeft
Upper left corner of item.
virtual bool writePropertiesToElement(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores item state within an XML DOM element.
virtual void finalizeRestoreFromXml()
Called after all pending items have been restored from XML.
int type() const override
Returns a unique graphics item type identifier.
virtual QSizeF applyItemSizeConstraint(QSizeF targetSize)
Applies any item-specific size constraint handling to a given targetSize in layout units.
virtual bool readPropertiesFromElement(const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context)
Sets item state from a DOM element.
virtual void draw(QgsLayoutItemRenderContext &context)=0
Draws the item's contents using the specified item render context.
An object which handles north-arrow type behavior for layout items.
DataDefinedProperty
Data defined properties for different item types.
@ AllProperties
All properties for item.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:51
A container for the context for various read/write operations on objects.
#define SIP_FACTORY
Definition qgis_sip.h:83