QGIS API Documentation  2.18.3-Las Palmas (77b8c3d)
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 : radim.blazek@gmail.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 QGSCOMPOSERPICTURE_H
18 #define QGSCOMPOSERPICTURE_H
19 
20 #include "qgscomposeritem.h"
21 #include <QFile>
22 #include <QImage>
23 #include <QSvgRenderer>
24 
25 class QgsComposerMap;
26 class QgsExpression;
27 
31 class CORE_EXPORT QgsComposerPicture: public QgsComposerItem
32 {
33  Q_OBJECT
34  public:
35 
39  {
40  Zoom,
42  Clip,
44  FrameToImageSize
45  };
46 
49  enum Mode
50  {
51  SVG,
54  };
55 
57  enum NorthMode
58  {
59  GridNorth = 0,
61  };
62 
63  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 
79  Q_DECL_DEPRECATED void setPictureFile( const QString& path );
80 
88  Q_DECL_DEPRECATED QString pictureFile() const;
89 
98  void setPicturePath( const QString& path );
99 
107  QString picturePath() const;
108 
112  void setSceneRect( const QRectF& rectangle ) override;
113 
118  bool writeXML( QDomElement& elem, QDomDocument & doc ) const override;
119 
124  bool readXML( const QDomElement& itemElem, const QDomDocument& doc ) override;
125 
129  Q_DECL_DEPRECATED double rotation() const { return mPictureRotation; }
130 
137  double pictureRotation() const { return mPictureRotation; }
138 
147  void setRotationMap( int composerMapId );
148 
156  int rotationMap() const;
157 
163  bool useRotationMap() const { return mRotationMap; }
164 
171  NorthMode northMode() const { return mNorthMode; }
172 
179  void setNorthMode( NorthMode mode );
180 
187  double northOffset() const { return mNorthOffset; }
188 
195  void setNorthOffset( double offset );
196 
203  ResizeMode resizeMode() const { return mResizeMode; }
204 
211  void setPictureAnchor( QgsComposerItem::ItemPositionMode anchor );
212 
219  ItemPositionMode pictureAnchor() const { return mPictureAnchor; }
220 
226  QColor svgFillColor() const { return mSvgFillColor; }
227 
236  void setSvgFillColor( const QColor& color );
237 
243  QColor svgBorderColor() const { return mSvgBorderColor; }
244 
253  void setSvgBorderColor( const QColor& color );
254 
260  double svgBorderWidth() const { return mSvgBorderWidth; }
261 
270  void setSvgBorderWidth( double width );
271 
281  Q_DECL_DEPRECATED bool usePictureExpression() const;
282 
291  Q_DECL_DEPRECATED QString pictureExpression() const;
292 
297  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
298 
303  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
304 
309  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
310 
315  Mode mode() const { return mMode; }
316 
317  public slots:
322  virtual void setRotation( double r ) override;
323 
330  virtual void setPictureRotation( double r );
331 
337  virtual void setResizeMode( ResizeMode mode );
338 
348  virtual void setUsePictureExpression( bool useExpression );
349 
358  virtual void setPictureExpression( const QString& expression );
359 
365  void refreshPicture( const QgsExpressionContext* context = nullptr );
366 
372  Q_DECL_DEPRECATED void updatePictureExpression() {}
373 
377  void recalculateSize();
378 
379  virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext *context = nullptr ) override;
380 
381  signals:
383  void pictureRotationChanged( double newRotation );
384 
385  private:
386 
387  //default constructor is forbidden
390  QRectF boundedSVGRect( double deviceWidth, double deviceHeight );
392  QRectF boundedImageRect( double deviceWidth, double deviceHeight );
393 
395  QSizeF pictureSize();
396 
397  QImage mImage;
398  QSvgRenderer mSVG;
399  QString mSourcePath;
400  Mode mMode;
401 
402  QSize mDefaultSvgSize;
403 
405  double mPictureRotation;
407  const QgsComposerMap* mRotationMap;
408 
410  NorthMode mNorthMode;
412  double mNorthOffset;
413 
415  double mPictureWidth;
417  double mPictureHeight;
418 
419  ResizeMode mResizeMode;
420  QgsComposerItem::ItemPositionMode mPictureAnchor;
421 
422  QColor mSvgFillColor;
423  QColor mSvgBorderColor;
424  double mSvgBorderWidth;
425 
426  bool mHasExpressionError;
427  bool mLoaded;
428  bool mLoadingSvg;
429 
431  void loadPicture( const QString &path );
432 
434  void init();
435 
439  QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
440 
443  void loadRemotePicture( const QString &url );
444 
447  void loadLocalPicture( const QString &path );
448 
449  private slots:
450 
451  void remotePictureLoaded();
452 
453  void updateMapRotation();
454 };
455 
456 #endif
NorthMode northMode() const
Returns the mode used to align the picture to a map&#39;s North.
Class for parsing and evaluation of expressions (formerly called "search strings").
Q_DECL_DEPRECATED bool imageSizeConsideringRotation(double &width, double &height, double rotation) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
Mode
Format of source image.
virtual void setRotation(double r)
Sets the item rotation.
QColor svgFillColor() const
Returns the fill color used for parameterized SVG files.
Q_DECL_DEPRECATED double rotation() const
Returns the rotation used for drawing the picture within the composer item.
double svgBorderWidth() const
Returns the border width (in mm) used for parameterized SVG files.
Mode mode() const
Returns the current picture mode (image format).
A item that forms part of a map composition.
QColor svgBorderColor() const
Returns the border color used for parameterized SVG files.
Q_DECL_DEPRECATED void updatePictureExpression()
Prepares the picture&#39;s source expression after it is altered or the compositions atlas coverage layer...
DataDefinedProperty
Data defined properties for different item types.
A composer class that displays svg files or raster format (jpg, png, ...)
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
ResizeMode resizeMode() const
Returns the resize mode used for drawing the picture within the composer item&#39;s frame.
ItemPositionMode pictureAnchor() const
Returns the picture&#39;s current anchor, which controls how it is placed within the picture item&#39;s frame...
ResizeMode
Controls how pictures are scaled within the item&#39;s frame.
NorthMode
Method for syncing rotation to a map&#39;s North direction.
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...
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...
bool useRotationMap() const
True if the picture rotation is matched to a map item.
Graphics scene for map printing.
Object representing map window.
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
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 pictureRotation() const
Returns the rotation used for drawing the picture within the item&#39;s frame.
double northOffset() const
Returns the offset added to the picture&#39;s rotation from a map&#39;s North.
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.