Skip to content
Permalink
Browse files

[FEATURE][composer] Option to restrict image/SVG outputs to content

If selected, then the images output by composer will include only
the area of the composition with content. There's also an option
for margins to add around the item bounds if required.

If the composition includes a single page, then the output will
be sized to include EVERYTHING on the composition. If it's a
multi-page composition, then each page will be cropped to only
include the area of that page with items.

A new image export options dialog has been added to facilitate
this, which also includes handy shortcuts for overriding the
print resolution or exported image dimensions.

Sponsored by NIWA
  • Loading branch information
nyalldawson committed Sep 25, 2015
1 parent 2f34300 commit dd759370bd90784de0332fd1568a5945f99df5d9
@@ -601,18 +601,59 @@ class QgsComposition : QGraphicsScene
*/
bool exportAsPDF( const QString& file );

//! print composer page to image
//! If the image does not fit into memory, a null image is returned
/** Renders a composer page to an image.
* @param page page number, 0 based such that the first page is page 0
* @returns rendered image, or null image if image does not fit into available memory
* @see renderRectAsRaster()
* @see renderPage()
*/
QImage printPageAsRaster( int page );

/** Render a page to a paint device
/** Renders a portion of the composition to an image. This method can be used to render
* sections of pages rather than full pages.
* @param rect region of composition to render
* @returns rendered image, or null image if image does not fit into available memory
* @note added in QGIS 2.12
* @see printPageAsRaster()
* @see renderRect()
*/
QImage renderRectAsRaster( const QRectF& rect );

/** Renders a full page to a paint device.
* @param p destination painter
* @param page page number, 0 based such that the first page is page 0 */
* @param page page number, 0 based such that the first page is page 0
* @see renderRect()
* @see printPageAsRaster()
*/
void renderPage( QPainter* p, int page );

/** Compute world file parameters */
/** Renders a portion of the composition to a paint device. This method can be used
* to render sections of pages rather than full pages.
* @param p destination painter
* @param rect region of composition to render
* @note added in QGIS 2.12
* @see renderPage()
* @see renderRectAsRaster()
*/
void renderRect( QPainter* p, const QRectF& rect );

/** Compute world file parameters. Assumes the whole page containing the associated map item
* will be exported.
*/
void computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const;

/** Computes the world file parameters for a specified region of the composition.
* @param exportRegion region of the composition which will be associated with world file
* @param a
* @param b
* @param c
* @param d
* @param e
* @param f
* @note added in QGIS 2.12
*/
void computeWorldFileParameters( const QRectF& exportRegion, double& a, double& b, double& c, double& d, double& e, double& f ) const;

QgsAtlasComposition& atlasComposition();

/** Resizes a QRectF relative to the change from boundsBefore to boundsAfter
@@ -703,6 +744,20 @@ class QgsComposition : QGraphicsScene
*/
QStringList customProperties() const;

/** Returns the bounding box of the items contained on a specified page.
* @param pageNumber page number, where 0 is the first page
* @param visibleOnly set to true to only include visible items
* @note added in QGIS 2.12
*/
QRectF pageItemBounds( int pageNumber, bool visibleOnly = false ) const;

/** Calculates the bounds of all non-gui items in the composition. Ignores snap lines and mouse handles.
* @param ignorePages set to true to ignore page items
* @param margin optional marginal (in percent, eg 0.05 = 5% ) to add around items
*/
QRectF compositionBounds( bool ignorePages = false, double margin = 0.0 ) const;


public slots:
/** Casts object to the proper subclass type and calls corresponding itemAdded signal*/
void sendItemAddedSignal( QgsComposerItem* item );
@@ -124,6 +124,7 @@ SET(QGIS_APP_SRCS
composer/qgscomposerarrowwidget.cpp
composer/qgscomposerattributetablewidget.cpp
composer/qgscomposerhtmlwidget.cpp
composer/qgscomposerimageexportoptionsdialog.cpp
composer/qgscomposeritemwidget.cpp
composer/qgscomposerlabelwidget.cpp
composer/qgscomposerpicturewidget.cpp
@@ -278,6 +279,7 @@ SET (QGIS_APP_MOC_HDRS
composer/qgscomposerarrowwidget.h
composer/qgscomposerattributetablewidget.h
composer/qgscomposerhtmlwidget.h
composer/qgscomposerimageexportoptionsdialog.h
composer/qgscomposeritemwidget.h
composer/qgscomposerlabelwidget.h
composer/qgscomposerlegendwidget.h

0 comments on commit dd75937

Please sign in to comment.
You can’t perform that action at this time.