QGIS API Documentation  2.99.0-Master (d55fa22)
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 
64  QgsComposerPicture( QgsComposition *composition );
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 
114  double pictureRotation() const { return mPictureRotation; }
115 
124  void setRotationMap( int composerMapId );
125 
133  int rotationMap() const;
134 
140  bool useRotationMap() const { return mRotationMap; }
141 
148  NorthMode northMode() const { return mNorthMode; }
149 
156  void setNorthMode( NorthMode mode );
157 
164  double northOffset() const { return mNorthOffset; }
165 
172  void setNorthOffset( double offset );
173 
180  ResizeMode resizeMode() const { return mResizeMode; }
181 
188  void setPictureAnchor( QgsComposerItem::ItemPositionMode anchor );
189 
196  ItemPositionMode pictureAnchor() const { return mPictureAnchor; }
197 
203  QColor svgFillColor() const { return mSvgFillColor; }
204 
213  void setSvgFillColor( const QColor &color );
214 
220  QColor svgStrokeColor() const { return mSvgStrokeColor; }
221 
230  void setSvgStrokeColor( const QColor &color );
231 
237  double svgStrokeWidth() const { return mSvgStrokeWidth; }
238 
247  void setSvgStrokeWidth( double width );
248 
253  Mode mode() const { return mMode; }
254 
255  public slots:
256 
263  virtual void setPictureRotation( double r );
264 
270  virtual void setResizeMode( ResizeMode mode );
271 
277  void refreshPicture( const QgsExpressionContext *context = nullptr );
278 
282  void recalculateSize();
283 
284  virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext *context = nullptr ) override;
285 
286  signals:
288  void pictureRotationChanged( double newRotation );
289 
290  private:
291 
292  //default constructor is forbidden
295  QRectF boundedSVGRect( double deviceWidth, double deviceHeight );
297  QRectF boundedImageRect( double deviceWidth, double deviceHeight );
298 
300  QSizeF pictureSize();
301 
302  QImage mImage;
303  QSvgRenderer mSVG;
305  QString mSourcePath;
306  Mode mMode;
307 
308  QSize mDefaultSvgSize;
309 
311  double mPictureRotation;
313  const QgsComposerMap *mRotationMap = nullptr;
314 
316  NorthMode mNorthMode;
318  double mNorthOffset;
319 
321  double mPictureWidth;
323  double mPictureHeight;
324 
325  ResizeMode mResizeMode;
326  QgsComposerItem::ItemPositionMode mPictureAnchor;
327 
328  QColor mSvgFillColor = QColor( 255, 255, 255 );
329  QColor mSvgStrokeColor = QColor( 0, 0, 0 );
330  double mSvgStrokeWidth = 0.2;
331 
332  bool mHasExpressionError;
333  bool mLoaded;
334  bool mLoadingSvg;
335 
337  void loadPicture( const QString &path );
338 
340  void init();
341 
345  QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
346 
349  void loadRemotePicture( const QString &url );
350 
353  void loadLocalPicture( const QString &path );
354 
355  private slots:
356 
357  void remotePictureLoaded();
358 
359  void updateMapRotation();
360 };
361 
362 #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.
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.
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.