QGIS API Documentation  2.99.0-Master (9f5e33a)
qgscomposerpicture.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerpicture.h
3  -------------------
4  begin : September 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : [email protected]
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 QGSCOMPOSERPICTURE_H
18 #define QGSCOMPOSERPICTURE_H
19 
20 #include "qgis_core.h"
21 #include "qgscomposeritem.h"
22 #include <QFile>
23 #include <QImage>
24 #include <QSvgRenderer>
25 
26 class QgsComposerMap;
27 class QgsExpression;
28 
32 class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
33 {
34  Q_OBJECT
35  public:
36 
40  {
41  Zoom,
43  Clip,
45  FrameToImageSize
46  };
47 
50  enum Mode
51  {
52  SVG,
54  Unknown
55  };
56 
58  enum NorthMode
59  {
60  GridNorth = 0,
62  };
63 
65 
67  virtual int type() const override { return ComposerPicture; }
68 
70  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
71 
80  void setPicturePath( const QString &path );
81 
89  QString picturePath() const;
90 
94  void setSceneRect( const QRectF &rectangle ) override;
95 
100  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
101 
106  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
107 
115  double pictureRotation() const { return mPictureRotation; }
116 
125  void setRotationMap( int composerMapId );
126 
134  int rotationMap() const;
135 
141  bool useRotationMap() const { return mRotationMap; }
142 
149  NorthMode northMode() const { return mNorthMode; }
150 
157  void setNorthMode( NorthMode mode );
158 
165  double northOffset() const { return mNorthOffset; }
166 
173  void setNorthOffset( double offset );
174 
181  ResizeMode resizeMode() const { return mResizeMode; }
182 
189  void setPictureAnchor( QgsComposerItem::ItemPositionMode anchor );
190 
197  ItemPositionMode pictureAnchor() const { return mPictureAnchor; }
198 
204  QColor svgFillColor() const { return mSvgFillColor; }
205 
214  void setSvgFillColor( const QColor &color );
215 
221  QColor svgStrokeColor() const { return mSvgStrokeColor; }
222 
231  void setSvgStrokeColor( const QColor &color );
232 
238  double svgStrokeWidth() const { return mSvgStrokeWidth; }
239 
248  void setSvgStrokeWidth( double width );
249 
254  Mode mode() const { return mMode; }
255 
256  public slots:
257 
264  virtual void setPictureRotation( double rotation );
265 
271  virtual void setResizeMode( ResizeMode mode );
272 
278  void refreshPicture( const QgsExpressionContext *context = nullptr );
279 
283  void recalculateSize();
284 
285  virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext *context = nullptr ) override;
286 
287  signals:
289  void pictureRotationChanged( double newRotation );
290 
291  private:
292 
293  //default constructor is forbidden
296  QRectF boundedSVGRect( double deviceWidth, double deviceHeight );
298  QRectF boundedImageRect( double deviceWidth, double deviceHeight );
299 
301  QSizeF pictureSize();
302 
303  QImage mImage;
304  QSvgRenderer mSVG;
306  QString mSourcePath;
307  Mode mMode;
308 
309  QSize mDefaultSvgSize;
310 
312  double mPictureRotation;
314  const QgsComposerMap *mRotationMap = nullptr;
315 
317  NorthMode mNorthMode;
319  double mNorthOffset;
320 
322  double mPictureWidth;
324  double mPictureHeight;
325 
326  ResizeMode mResizeMode;
327  QgsComposerItem::ItemPositionMode mPictureAnchor;
328 
329  QColor mSvgFillColor = QColor( 255, 255, 255 );
330  QColor mSvgStrokeColor = QColor( 0, 0, 0 );
331  double mSvgStrokeWidth = 0.2;
332 
333  bool mHasExpressionError;
334  bool mLoaded;
335  bool mLoadingSvg;
336 
338  void loadPicture( const QString &path );
339 
341  void init();
342 
346  QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
347 
350  void loadRemotePicture( const QString &url );
351 
354  void loadLocalPicture( const QString &path );
355 
356  private slots:
357 
358  void remotePictureLoaded();
359 
360  void updateMapRotation();
361 };
362 
363 #endif
Enlarges image to fit frame while maintaining aspect ratio of picture.
QColor svgStrokeColor() const
Returns the stroke color used for parametrized SVG files.
Mode
Format of source image.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:34
Stretches image to fit frame, ignores aspect ratio.
QColor svgFillColor() const
Returns the fill color used for parametrized SVG files.
bool useRotationMap() const
True if the picture rotation is matched to a map item.
A item that forms part of a map composition.
double pictureRotation() const
Returns the rotation used for drawing the picture within the item&#39;s frame, in degrees clockwise...
NorthMode northMode() const
Returns the mode used to align the picture to a map&#39;s North.
DataDefinedProperty
Data defined properties for different item types.
A composer class that displays svg files or raster format (jpg, png, ...)
ResizeMode
Controls how pictures are scaled within the item&#39;s frame.
NorthMode
Method for syncing rotation to a map&#39;s North direction.
ItemPositionMode pictureAnchor() const
Returns the picture&#39;s current anchor, which controls how it is placed within the picture item&#39;s frame...
virtual bool readXml(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
virtual int type() const override
Return correct graphics item type.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
double northOffset() const
Returns the offset added to the picture&#39;s rotation from a map&#39;s North.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties, const QgsExpressionContext *context=nullptr) override
Refreshes a data defined property for the item by reevaluating the property&#39;s value and redrawing the...
Graphics scene for map printing.
Object representing map window.
Enlarges image to fit frame, then resizes frame to fit resultant image.
Draws image at original size and clips any portion which falls outside frame.
Mode mode() const
Returns the current picture mode (image format).
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
double svgStrokeWidth() const
Returns the stroke width (in mm) used for parametrized SVG files.
ResizeMode resizeMode() const
Returns the resize mode used for drawing the picture within the composer item&#39;s frame.
virtual bool writeXml(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
All properties for item.