QGIS API Documentation  2.99.0-Master (19b062c)
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 
33 class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
34 {
35  Q_OBJECT
36  public:
37 
42  {
43  Zoom,
45  Clip,
47  FrameToImageSize
48  };
49 
53  enum Mode
54  {
55  SVG,
57  Unknown
58  };
59 
61  enum NorthMode
62  {
63  GridNorth = 0,
65  };
66 
68 
70  virtual int type() const override { return ComposerPicture; }
71 
73  void paint( QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget ) override;
74 
84  void setPicturePath( const QString &path );
85 
94  QString picturePath() const;
95 
100  void setSceneRect( const QRectF &rectangle ) override;
101 
107  bool writeXml( QDomElement &elem, QDomDocument &doc ) const override;
108 
114  bool readXml( const QDomElement &itemElem, const QDomDocument &doc ) override;
115 
123  double pictureRotation() const { return mPictureRotation; }
124 
134  void setRotationMap( int composerMapId );
135 
144  int rotationMap() const;
145 
152  bool useRotationMap() const { return mRotationMap; }
153 
160  NorthMode northMode() const { return mNorthMode; }
161 
168  void setNorthMode( NorthMode mode );
169 
176  double northOffset() const { return mNorthOffset; }
177 
184  void setNorthOffset( double offset );
185 
193  ResizeMode resizeMode() const { return mResizeMode; }
194 
202  void setPictureAnchor( QgsComposerItem::ItemPositionMode anchor );
203 
211  ItemPositionMode pictureAnchor() const { return mPictureAnchor; }
212 
219  QColor svgFillColor() const { return mSvgFillColor; }
220 
230  void setSvgFillColor( const QColor &color );
231 
238  QColor svgStrokeColor() const { return mSvgStrokeColor; }
239 
249  void setSvgStrokeColor( const QColor &color );
250 
257  double svgStrokeWidth() const { return mSvgStrokeWidth; }
258 
268  void setSvgStrokeWidth( double width );
269 
275  Mode mode() const { return mMode; }
276 
277  public slots:
278 
285  virtual void setPictureRotation( double rotation );
286 
293  virtual void setResizeMode( ResizeMode mode );
294 
301  void refreshPicture( const QgsExpressionContext *context = nullptr );
302 
307  void recalculateSize();
308 
309  virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext *context = nullptr ) override;
310 
311  signals:
313  void pictureRotationChanged( double newRotation );
314 
315  private:
316 
317  //default constructor is forbidden
320  QRectF boundedSVGRect( double deviceWidth, double deviceHeight );
322  QRectF boundedImageRect( double deviceWidth, double deviceHeight );
323 
325  QSizeF pictureSize();
326 
327  QImage mImage;
328  QSvgRenderer mSVG;
330  QString mSourcePath;
331  Mode mMode = Unknown;
332 
333  QSize mDefaultSvgSize;
334 
336  double mPictureRotation = 0;
338  const QgsComposerMap *mRotationMap = nullptr;
339 
341  NorthMode mNorthMode = GridNorth;
343  double mNorthOffset = 0.0;
344 
346  double mPictureWidth;
348  double mPictureHeight;
349 
350  ResizeMode mResizeMode = QgsComposerPicture::Zoom;
352 
353  QColor mSvgFillColor = QColor( 255, 255, 255 );
354  QColor mSvgStrokeColor = QColor( 0, 0, 0 );
355  double mSvgStrokeWidth = 0.2;
356 
357  bool mHasExpressionError = false;
358  bool mLoaded;
359  bool mLoadingSvg = false;
360 
362  void loadPicture( const QString &path );
363 
365  void init();
366 
371  QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
372 
376  void loadRemotePicture( const QString &url );
377 
381  void loadLocalPicture( const QString &path );
382 
383  private slots:
384 
385  void remotePictureLoaded();
386 
387  void updateMapRotation();
388 };
389 
390 #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:46
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.