QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
56  QgsComposerPicture( QgsComposition *composition );
58 
60  virtual int type() const { return ComposerPicture; }
61 
63  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
64 
72  Q_DECL_DEPRECATED void setPictureFile( const QString& path );
73 
81  Q_DECL_DEPRECATED QString pictureFile() const;
82 
91  void setPicturePath( const QString& path );
92 
100  QString picturePath() const;
101 
105  void setSceneRect( const QRectF& rectangle );
106 
111  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
112 
117  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
118 
122  Q_DECL_DEPRECATED double rotation() const { return mPictureRotation; }
123 
130  double pictureRotation() const { return mPictureRotation; }
131 
140  void setRotationMap( int composerMapId );
141 
149  int rotationMap() const;
150 
156  bool useRotationMap() const { return mRotationMap; }
157 
164  ResizeMode resizeMode() const { return mResizeMode; }
165 
172  void setPictureAnchor( QgsComposerItem::ItemPositionMode anchor );
173 
180  ItemPositionMode pictureAnchor() const { return mPictureAnchor; }
181 
191  Q_DECL_DEPRECATED bool usePictureExpression() const;
192 
201  Q_DECL_DEPRECATED QString pictureExpression() const;
202 
207  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
208 
213  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
214 
219  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
220 
225  Mode mode() const { return mMode; }
226 
227  public slots:
232  virtual void setRotation( double r );
233 
240  virtual void setPictureRotation( double r );
241 
247  virtual void setResizeMode( ResizeMode mode );
248 
258  virtual void setUsePictureExpression( bool useExpression );
259 
268  virtual void setPictureExpression( QString expression );
269 
274  void refreshPicture();
275 
281  Q_DECL_DEPRECATED void updatePictureExpression() {};
282 
286  void recalculateSize();
287 
289 
290  signals:
292  void pictureRotationChanged( double newRotation );
293 
294  private:
295 
296  //default constructor is forbidden
299  QRectF boundedSVGRect( double deviceWidth, double deviceHeight );
301  QRectF boundedImageRect( double deviceWidth, double deviceHeight );
302 
304  QSizeF pictureSize();
305 
306  QImage mImage;
307  QSvgRenderer mSVG;
308  QString mSourcePath;
309  Mode mMode;
310 
311  QSize mDefaultSvgSize;
312 
314  double mPictureRotation;
316  const QgsComposerMap* mRotationMap;
318  double mPictureWidth;
320  double mPictureHeight;
321 
322  ResizeMode mResizeMode;
323  QgsComposerItem::ItemPositionMode mPictureAnchor;
324 
325  bool mHasExpressionError;
326  bool mLoaded;
327 
329  void loadPicture( const QString &path );
330 
332  void init();
333 
337  QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
338 
341  void loadRemotePicture( const QString &url );
342 
345  void loadLocalPicture( const QString &path );
346 
347  private slots:
348 
349  void remotePictureLoaded();
350 };
351 
352 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
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...
Definition: qgscomposeritem.cpp:1065
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
Definition: qgscomposerobject.cpp:61
virtual void setRotation(double r)
Sets the item rotation.
Definition: qgscomposeritem.cpp:990
Definition: qgscomposeritem.h:55
Q_DECL_DEPRECATED double rotation() const
Returns the rotation used for drawing the picture within the composer item.
Definition: qgscomposerpicture.h:122
Mode mode() const
Returns the current picture mode (image format).
Definition: qgscomposerpicture.h:225
ItemPositionMode
Definition: qgscomposeritem.h:79
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
Definition: qgscomposerpicture.h:40
Q_DECL_DEPRECATED void updatePictureExpression()
Prepares the picture's source expression after it is altered or the compositions atlas coverage layer...
Definition: qgscomposerpicture.h:281
DataDefinedProperty
Data defined properties for different item types.
Definition: qgscomposerobject.h:40
ResizeMode
Definition: qgscomposerpicture.h:38
Definition: qgscomposerobject.h:43
Definition: qgsexpression.cpp:123
A composer class that displays svg files or raster format (jpg, png, ...)
Definition: qgscomposerpicture.h:31
ResizeMode resizeMode() const
Returns the resize mode used for drawing the picture within the composer item's frame.
Definition: qgscomposerpicture.h:164
Mode
Definition: qgscomposerpicture.h:49
ItemPositionMode pictureAnchor() const
Returns the picture's current anchor, which controls how it is placed within the picture item's frame...
Definition: qgscomposerpicture.h:180
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Definition: qgscomposeritem.cpp:1286
bool useRotationMap() const
True if the picture rotation is matched to a map item.
Definition: qgscomposerpicture.h:156
Definition: qgscomposerpicture.h:43
Graphics scene for map printing.
Definition: qgscomposition.h:70
Definition: qgscomposerpicture.h:42
Object representing map window.
Definition: qgscomposermap.h:45
Definition: qgscomposerpicture.h:51
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
Definition: qgscomposeritem.cpp:1144
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Definition: qgscomposerobject.cpp:74
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...
Definition: qgscomposeritem.cpp:676
double pictureRotation() const
Returns the rotation used for drawing the picture within the item's frame.
Definition: qgscomposerpicture.h:130
Definition: qgscomposerpicture.h:41
Definition: qgscomposerpicture.h:52
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
Definition: qgscomposeritem.cpp:1189
virtual int type() const
return correct graphics item type.
Definition: qgscomposerpicture.h:60