QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 : [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 
56  QgsComposerPicture( QgsComposition *composition );
58 
60  virtual int type() const { return ComposerPicture; }
61 
63  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
64 
71  void setPictureFile( const QString& path );
72 
79  QString pictureFile() const;
80 
83  void setSceneRect( const QRectF& rectangle );
84 
89  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
90 
95  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
96 
100  Q_DECL_DEPRECATED double rotation() const { return mPictureRotation; }
101 
108  double pictureRotation() const { return mPictureRotation; }
109 
118  void setRotationMap( int composerMapId );
119 
127  int rotationMap() const;
128 
134  bool useRotationMap() const { return mRotationMap; }
135 
142  ResizeMode resizeMode() const { return mResizeMode; }
143 
150  void setPictureAnchor( QgsComposerItem::ItemPositionMode anchor );
151 
158  ItemPositionMode pictureAnchor() const { return mPictureAnchor; }
159 
168  bool usePictureExpression() const { return mUseSourceExpression; }
169 
177  QString pictureExpression() const { return mSourceExpression; }
178 
183  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
188  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
193  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
194 
199  Mode mode() const { return mMode; }
200 
201  public slots:
206  virtual void setRotation( double r );
207 
214  virtual void setPictureRotation( double r );
215 
221  virtual void setResizeMode( ResizeMode mode );
222 
231  virtual void setUsePictureExpression( bool useExpression );
232 
240  virtual void setPictureExpression( QString expression );
241 
246  void refreshPicture();
247 
252  void updatePictureExpression();
253 
257  void recalculateSize();
258 
259  signals:
261  void pictureRotationChanged( double newRotation );
262 
263  private:
264 
265  //default constructor is forbidden
268  QRectF boundedSVGRect( double deviceWidth, double deviceHeight );
270  QRectF boundedImageRect( double deviceWidth, double deviceHeight );
271 
273  QSizeF pictureSize();
274 
275  QImage mImage;
276  QSvgRenderer mSVG;
277  QFile mSourceFile;
281 
283 
292 
295 
297 
299  void loadPicture( const QFile &file );
300 
302  QString evalPictureExpression();
303 
305  void init();
306 
310  QRect clippedImageRect( double &boundRectWidthMM, double &boundRectHeightMM, QSize imageRectPixels );
311 };
312 
313 #endif
Class for parsing and evaluation of expressions (formerly called "search strings").
Definition: qgsexpression.h:89
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 readXML(const QDomElement &itemElem, const QDomDocument &doc)=0
sets state from Dom document
virtual void setRotation(double r)
Sets the item rotation.
Q_DECL_DEPRECATED double rotation() const
Returns the rotation used for drawing the picture within the composer item.
Mode mode() const
Returns the current picture mode (image format).
A item that forms part of a map composition.
QgsComposerItem::ItemPositionMode mPictureAnchor
A composer class that displays svg files or raster format (jpg, png, ...)
ResizeMode resizeMode() const
Returns the resize mode used for drawing the picture within the composer item's frame.
ItemPositionMode pictureAnchor() const
Returns the picture's current anchor, which controls how it is placed within the picture item's frame...
const QgsComposerMap * mRotationMap
Map that sets the rotation (or 0 if this picture uses map independent rotation)
double mPictureHeight
Height of the picture (in mm)
bool useRotationMap() const
True if the picture rotation is matched to a map item.
Graphics scene for map printing.
Object representing map window.
QString file
Definition: qgssvgcache.cpp:76
bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
QString pictureExpression() const
Returns the expression the item is using for the picture source.
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 mPictureWidth
Width of the picture (in mm)
double pictureRotation() const
Returns the rotation used for drawing the picture within the item's frame.
void init(bool manageZValue)
double mPictureRotation
Image rotation.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const =0
stores state in Dom element
void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
bool usePictureExpression() const
Returns whether the picture item is using an expression for the image source.
virtual int type() const
return correct graphics item type.
QgsExpression * mPictureExpr