QGIS API Documentation  2.99.0-Master (6a61179)
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 "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 
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 svgBorderColor() const { return mSvgBorderColor; }
221 
230  void setSvgBorderColor( const QColor& color );
231 
237  double svgBorderWidth() const { return mSvgBorderWidth; }
238 
247  void setSvgBorderWidth( 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;
304  QString mSourcePath;
305  Mode mMode;
306 
307  QSize mDefaultSvgSize;
308 
310  double mPictureRotation;
312  const QgsComposerMap* mRotationMap;
313 
315  NorthMode mNorthMode;
317  double mNorthOffset;
318 
320  double mPictureWidth;
322  double mPictureHeight;
323 
324  ResizeMode mResizeMode;
325  QgsComposerItem::ItemPositionMode mPictureAnchor;
326 
327  QColor mSvgFillColor;
328  QColor mSvgBorderColor;
329  double mSvgBorderWidth;
330 
331  bool mHasExpressionError;
332  bool mLoaded;
333  bool mLoadingSvg;
334 
336  void loadPicture( const QString &path );
337 
339  void init();
340 
344  QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
345 
348  void loadRemotePicture( const QString &url );
349 
352  void loadLocalPicture( const QString &path );
353 
354  private slots:
355 
356  void remotePictureLoaded();
357 
358  void updateMapRotation();
359 };
360 
361 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Enlarges image to fit frame while maintaining aspect ratio of picture.
Mode
Format of source image.
Stretches image to fit frame, ignores aspect ratio.
QColor svgFillColor() const
Returns the fill color used for parameterized SVG files.
double svgBorderWidth() const
Returns the border width (in mm) used for parameterized 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.
QColor svgBorderColor() const
Returns the border color used for parameterized SVG files.
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...
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.