QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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#include <QFile>
23#include <QImage>
24#include <QSvgRenderer>
25
27class QgsExpression;
29
35class CORE_EXPORT QgsLayoutItemPicture: public QgsLayoutItem
36{
37 Q_OBJECT
38 public:
39
44 {
49 FrameToImageSize
50 };
51
61
64 {
65 GridNorth = 0,
67 };
68
73
74 int type() const override;
75 QIcon icon() const override;
76
82 static QgsLayoutItemPicture *create( QgsLayout *layout ) SIP_FACTORY;
83
84
94 void setPicturePath( const QString &path, Format format = FormatUnknown );
95
103 QString picturePath() const;
104
111 double pictureRotation() const { return mPictureRotation; }
112
123 void setLinkedMap( QgsLayoutItemMap *map );
124
131 QgsLayoutItemMap *linkedMap() const;
132
138 NorthMode northMode() const;
139
145 void setNorthMode( NorthMode mode );
146
152 double northOffset() const;
153
159 void setNorthOffset( double offset );
160
166 ResizeMode resizeMode() const { return mResizeMode; }
167
173 void setPictureAnchor( QgsLayoutItem::ReferencePoint anchor );
174
180 QgsLayoutItem::ReferencePoint pictureAnchor() const { return mPictureAnchor; }
181
187 QColor svgFillColor() const { return mSvgFillColor; }
188
196 void setSvgFillColor( const QColor &color );
197
203 QColor svgStrokeColor() const { return mSvgStrokeColor; }
204
213 void setSvgStrokeColor( const QColor &color );
214
220 double svgStrokeWidth() const { return mSvgStrokeWidth; }
221
229 void setSvgStrokeWidth( double width );
230
236 Format mode() const { return mMode; }
237
244 Format originalMode() const { return mOriginalMode; }
245
251 void setMode( Format mode );
252
253 void finalizeRestoreFromXml() override;
254
261 bool isMissingImage() const;
262
270 QString evaluatedPath() const;
271
276 QMap<QString, QgsProperty> svgDynamicParameters() const;
277
282 void setSvgDynamicParameters( const QMap<QString, QgsProperty> &parameters );
283
284 public slots:
285
291 void setPictureRotation( double rotation );
292
298 void setResizeMode( QgsLayoutItemPicture::ResizeMode mode );
299
305 void refreshPicture( const QgsExpressionContext *context = nullptr );
306
310 void recalculateSize();
311
313
314 signals:
316 void pictureRotationChanged( double newRotation );
317
318 protected:
319
320 void draw( QgsLayoutItemRenderContext &context ) override;
321 QSizeF applyItemSizeConstraint( QSizeF targetSize ) override;
322 bool writePropertiesToElement( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context ) const override;
323 bool readPropertiesFromElement( const QDomElement &element, const QDomDocument &document, const QgsReadWriteContext &context ) override;
324
325 private:
326
327 QgsLayoutItemPicture() = delete;
328
330 QRectF boundedSVGRect( double deviceWidth, double deviceHeight );
332 QRectF boundedImageRect( double deviceWidth, double deviceHeight );
333
335 QSizeF pictureSize();
336
337 QImage mImage;
338 QSvgRenderer mSVG;
340 QString mSourcePath;
341 Format mMode = FormatUnknown;
342 Format mOriginalMode = FormatUnknown;
343
344 QSize mDefaultSvgSize;
345
347 double mPictureRotation = 0;
348
349 QString mRotationMapUuid;
350
352 double mPictureWidth = 0.0;
354 double mPictureHeight = 0.0;
355
358
359 QColor mSvgFillColor = QColor( 255, 255, 255 );
360 QColor mSvgStrokeColor = QColor( 0, 0, 0 );
361 double mSvgStrokeWidth = 0.2;
362
363 bool mHasExpressionError = false;
364 bool mLoaded = false;
365 bool mLoadingSvg = false;
366 bool mIsMissingImage = false;
367 QString mEvaluatedPath;
368
369 QgsLayoutNorthArrowHandler *mNorthArrowHandler = nullptr;
370
372 void loadPicture( const QVariant &data );
373
378 QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
379
383 void loadRemotePicture( const QString &url );
384
388 void loadLocalPicture( const QString &path );
389
390 void loadPictureUsingCache( const QString &path );
391
392 QgsLayoutItemPicture( const QgsLayoutItemPicture & ) = delete;
393 QgsLayoutItemPicture &operator=( const QgsLayoutItemPicture & ) = delete;
394
395 private slots:
396
397 void updateNorthArrowRotation( double rotation );
398
399 void shapeChanged();
400
402 friend class TestQgsCompositionConverter;
403
404};
405
406#endif // QGSLAYOUTITEMPICTURE_H
QgsCompositionConverter class converts a QGIS 2.x composition to a QGIS 3.x layout.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for 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.
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.
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.
Format originalMode() const
Returns the original set picture mode (image format).
NorthMode
Method for syncing rotation to a map's North direction.
@ TrueNorth
Align to true north.
Format mode() const
Returns the current picture mode (image format), FormatUnknown if given picture format is unknown.
QColor svgFillColor() const
Returns the fill color used for parametrized SVG files.
ResizeMode
Controls how pictures are scaled within the item's frame.
@ 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.
Format
Format of source image.
@ FormatUnknown
Invalid or unknown image type.
Contains settings and helpers relating to a render of a QgsLayoutItem.
Base class for graphical items within a QgsLayout.
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 void refreshDataDefinedProperty(QgsLayoutObject::DataDefinedProperty property=QgsLayoutObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
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:50
The class is used as a container of context for various read/write operations on other objects.
#define SIP_FACTORY
Definition qgis_sip.h:76