2009-02-27 13:57:26 +00:00
|
|
|
/** \ingroup MapComposer
|
|
|
|
* A composer class that displays svg files or raster format (jpg, png, ...)
|
|
|
|
* */
|
2009-11-19 09:04:33 +00:00
|
|
|
class QgsComposerPicture: QgsComposerItem
|
2009-02-27 13:57:26 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include "qgscomposerpicture.h"
|
|
|
|
%End
|
|
|
|
|
|
|
|
public:
|
2014-05-27 23:22:50 +02:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/*! Controls how pictures are scaled within the item's frame
|
|
|
|
*/
|
|
|
|
enum ResizeMode
|
|
|
|
{
|
|
|
|
Zoom, /*!< enlarges image to fit frame while maintaining aspect ratio of picture */
|
|
|
|
Stretch, /*!< stretches image to fit frame, ignores aspect ratio */
|
|
|
|
Clip, /*!< draws image at original size and clips any portion which falls outside frame */
|
|
|
|
ZoomResizeFrame, /*!< enlarges image to fit frame, then resizes frame to fit resultant image */
|
|
|
|
FrameToImageSize /*!< sets size of frame to match original size of image without scaling */
|
|
|
|
};
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/*! Format of source image
|
|
|
|
*/
|
|
|
|
enum Mode
|
|
|
|
{
|
|
|
|
SVG,
|
|
|
|
RASTER,
|
|
|
|
Unknown
|
2014-05-18 15:22:26 +02:00
|
|
|
};
|
|
|
|
|
2009-02-28 14:35:45 +00:00
|
|
|
QgsComposerPicture( QgsComposition *composition /TransferThis/);
|
2009-02-27 13:57:26 +00:00
|
|
|
~QgsComposerPicture();
|
|
|
|
|
2010-11-25 21:45:52 +00:00
|
|
|
/** return correct graphics item type. Added in v1.7 */
|
|
|
|
virtual int type() const;
|
|
|
|
|
2009-02-27 13:57:26 +00:00
|
|
|
/**Reimplementation of QCanvasItem::paint*/
|
|
|
|
void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
|
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**Sets the source file of the image (may be svg or a raster format). This is only used if
|
|
|
|
* usePictureExpression() is false.
|
|
|
|
* @param path full path to the source image
|
|
|
|
* @see usePictureExpression
|
|
|
|
* @see pictureFile
|
|
|
|
*/
|
2009-02-27 13:57:26 +00:00
|
|
|
void setPictureFile( const QString& path );
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**Returns the path of the source image file. This is only used if
|
|
|
|
* usePictureExpression() is false.
|
|
|
|
* @returns path to the source image
|
|
|
|
* @see usePictureExpression
|
|
|
|
* @see setPictureFile
|
|
|
|
*/
|
2009-02-27 13:57:26 +00:00
|
|
|
QString pictureFile() const;
|
|
|
|
|
|
|
|
/**Sets this items bound in scene coordinates such that 1 item size units
|
2012-09-24 02:28:15 +02:00
|
|
|
corresponds to 1 scene size unit and resizes the svg symbol / image*/
|
2009-02-27 13:57:26 +00:00
|
|
|
void setSceneRect( const QRectF& rectangle );
|
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
/** stores state in Dom element
|
|
|
|
* @param elem is Dom element corresponding to 'Composer' tag
|
|
|
|
* @param doc is Dom document
|
2009-02-27 13:57:26 +00:00
|
|
|
*/
|
|
|
|
bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
|
|
|
|
|
|
|
|
/** sets state from Dom document
|
|
|
|
* @param itemElem is Dom node corresponding to item tag
|
2012-09-24 02:28:15 +02:00
|
|
|
* @param doc is Dom document
|
2009-02-27 13:57:26 +00:00
|
|
|
*/
|
|
|
|
bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
|
|
|
|
|
2014-01-27 09:22:24 +01:00
|
|
|
/**Returns the rotation used for drawing the picture within the composer item
|
2013-12-30 19:50:00 +11:00
|
|
|
* @deprecated Use pictureRotation() instead
|
|
|
|
*/
|
2014-04-28 19:11:11 +10:00
|
|
|
double rotation() const /Deprecated/;
|
2013-12-30 19:50:00 +11:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**Returns the rotation used for drawing the picture within the item's frame
|
|
|
|
* @returns picture rotation in degrees
|
|
|
|
* @note added in 2.2
|
|
|
|
* @see setPictureRotation
|
|
|
|
* @see rotationMap
|
|
|
|
*/
|
2013-12-30 19:50:00 +11:00
|
|
|
double pictureRotation() const;
|
|
|
|
|
2014-05-18 15:22:26 +02:00
|
|
|
/**Sets the map object for rotation (by id). A value of -1 disables the map
|
|
|
|
* rotation. If this is set then the picture will be rotated by the same
|
|
|
|
* amount as the specified map object. This is useful especially for
|
|
|
|
* syncing north arrows with a map item.
|
|
|
|
* @param composerMapId composer map id to sync rotation with
|
2014-04-28 19:53:32 +10:00
|
|
|
* @see setPictureRotation
|
|
|
|
* @see rotationMap
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2009-11-02 17:27:13 +00:00
|
|
|
void setRotationMap( int composerMapId );
|
2014-05-18 15:22:26 +02:00
|
|
|
|
|
|
|
/**Returns the id of the rotation map. A value of -1 means map rotation is
|
|
|
|
* disabled. If this is set then the picture is rotated by the same amount
|
|
|
|
* as the specified map object.
|
2014-04-28 19:53:32 +10:00
|
|
|
* @returns id of map object
|
|
|
|
* @see setRotationMap
|
|
|
|
* @see useRotationMap
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2009-11-02 17:27:13 +00:00
|
|
|
int rotationMap() const;
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**True if the picture rotation is matched to a map item.
|
|
|
|
* @returns true if rotation map is in use
|
|
|
|
* @see rotationMap
|
|
|
|
* @see setRotationMap
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2009-11-02 17:27:13 +00:00
|
|
|
bool useRotationMap() const;
|
2014-05-18 15:22:26 +02:00
|
|
|
|
|
|
|
/**Returns the resize mode used for drawing the picture within the composer
|
|
|
|
* item's frame.
|
2014-04-28 19:53:32 +10:00
|
|
|
* @returns resize mode of picture
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setResizeMode
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
ResizeMode resizeMode() const;
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-05-15 11:58:13 +10:00
|
|
|
/**Sets the picture's anchor point, which controls how it is placed
|
|
|
|
* within the picture item's frame.
|
|
|
|
* @param anchor anchor point for picture
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see pictureAnchor
|
|
|
|
*/
|
|
|
|
void setPictureAnchor( QgsComposerItem::ItemPositionMode anchor );
|
|
|
|
|
|
|
|
/**Returns the picture's current anchor, which controls how it is placed
|
|
|
|
* within the picture item's frame.
|
|
|
|
* @returns anchor point for picture
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setPictureAnchor
|
|
|
|
*/
|
2014-05-18 15:22:26 +02:00
|
|
|
ItemPositionMode pictureAnchor() const;
|
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**Returns whether the picture item is using an expression for the image source.
|
|
|
|
* @returns true if the picture is using an expression for the source, false if
|
|
|
|
* it is using a single static file path for the source.
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setUsePictureExpression
|
|
|
|
* @see pictureFile
|
|
|
|
* @see pictureExpression
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
bool usePictureExpression() const;
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**Returns the expression the item is using for the picture source. This is only
|
|
|
|
* used if usePictureExpression() is true.
|
|
|
|
* @returns expression for the picture item's image path
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setPictureExpression
|
|
|
|
* @see usePictureExpression
|
2014-05-27 23:22:50 +02:00
|
|
|
*/
|
2014-05-18 15:22:26 +02:00
|
|
|
QString pictureExpression() const;
|
2009-11-02 17:27:13 +00:00
|
|
|
|
2013-12-30 19:50:00 +11:00
|
|
|
/**Calculates width and hight of the picture (in mm) such that it fits into the item frame with the given rotation
|
|
|
|
* @deprecated Use bool QgsComposerItem::imageSizeConsideringRotation( double& width, double& height, double rotation )
|
|
|
|
* instead
|
|
|
|
*/
|
2014-04-28 19:11:11 +10:00
|
|
|
bool imageSizeConsideringRotation( double& width, double& height ) const /Deprecated/;
|
2013-12-30 19:50:00 +11:00
|
|
|
/**Calculates corner point after rotation and scaling
|
|
|
|
* @deprecated Use QgsComposerItem::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height, double rotation )
|
|
|
|
* instead
|
|
|
|
*/
|
2014-04-28 19:11:11 +10:00
|
|
|
bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const /Deprecated/;
|
2013-12-30 19:50:00 +11:00
|
|
|
/**Calculates width / height of the bounding box of a rotated rectangle
|
2014-05-18 15:22:26 +02:00
|
|
|
* @deprecated Use QgsComposerItem::sizeChangedByRotation( double& width, double& height, double rotation )
|
|
|
|
* instead
|
|
|
|
*/
|
2014-04-28 19:11:11 +10:00
|
|
|
void sizeChangedByRotation( double& width, double& height ) /Deprecated/;
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**Returns the current picture mode (image format).
|
|
|
|
* @returns picture mode
|
|
|
|
* @note added in 2.3
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
|
|
|
Mode mode() const;
|
2014-01-27 09:22:24 +01:00
|
|
|
|
2012-09-24 02:28:15 +02:00
|
|
|
public slots:
|
2014-05-18 15:22:26 +02:00
|
|
|
/**Sets the picture rotation within the item bounds. This does not affect
|
|
|
|
* the item rectangle, only the way the picture is drawn within the item.
|
2013-12-30 19:50:00 +11:00
|
|
|
* @deprecated Use setPictureRotation( double rotation ) instead
|
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
virtual void setRotation( double r ) /Deprecated/;
|
2013-12-30 19:50:00 +11:00
|
|
|
|
2014-05-18 15:22:26 +02:00
|
|
|
/**Sets the picture rotation within the item bounds. This does not affect
|
|
|
|
* the item's frame, only the way the picture is drawn within the item.
|
2014-04-28 19:53:32 +10:00
|
|
|
* @param r rotation in degrees clockwise
|
|
|
|
* @see pictureRotation
|
|
|
|
* @note added in 2.2
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2013-12-30 19:50:00 +11:00
|
|
|
virtual void setPictureRotation( double r );
|
2014-05-18 15:22:26 +02:00
|
|
|
|
2014-04-28 19:53:32 +10:00
|
|
|
/**Sets the resize mode used for drawing the picture within the item bounds.
|
|
|
|
* @param mode ResizeMode to use for image file
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see resizeMode
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
virtual void setResizeMode( ResizeMode mode );
|
|
|
|
|
|
|
|
/**Sets whether the picture should use an expression based image source path
|
|
|
|
* @param useExpression set to true to use an expression based image source,
|
|
|
|
* set to false to use a single image source path
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see usePictureExpression
|
|
|
|
* @see setPictureFile
|
|
|
|
* @see setPictureExpression
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
virtual void setUsePictureExpression( bool useExpression );
|
|
|
|
|
|
|
|
/**Sets an expression to use for the picture source. This expression is only
|
|
|
|
* used if usePictureExpression() is true.
|
|
|
|
* @param expression to use for picture path
|
|
|
|
* @note added in 2.3
|
|
|
|
* @see setUsePictureExpression
|
|
|
|
* @see pictureExpression
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
virtual void setPictureExpression( QString expression );
|
|
|
|
|
|
|
|
/**Recalculates the source image (if using an expression for picture's source)
|
|
|
|
* and reloads and redraws the picture.
|
|
|
|
* @note added in 2.3
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
void refreshPicture();
|
|
|
|
|
|
|
|
/**Prepares the picture's source expression after it is altered or the compositions
|
|
|
|
* atlas coverage layer changes.
|
|
|
|
* @note added in 2.3
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
2014-04-28 19:53:32 +10:00
|
|
|
void updatePictureExpression();
|
|
|
|
|
|
|
|
/**Forces a recalculation of the picture's frame size
|
|
|
|
* @note added in 2.3
|
2014-05-18 15:22:26 +02:00
|
|
|
*/
|
|
|
|
void recalculateSize();
|
2014-01-27 09:22:24 +01:00
|
|
|
|
2013-12-30 19:50:00 +11:00
|
|
|
signals:
|
|
|
|
/**Is emitted on picture rotation change*/
|
2014-01-27 09:22:24 +01:00
|
|
|
void pictureRotationChanged( double newRotation );
|
2009-02-28 14:35:45 +00:00
|
|
|
};
|