Skip to content

Commit dd75937

Browse files
committedSep 25, 2015
[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
1 parent 2f34300 commit dd75937

File tree

11 files changed

+1250
-104
lines changed

11 files changed

+1250
-104
lines changed
 

‎python/core/composer/qgscomposition.sip

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,18 +601,59 @@ class QgsComposition : QGraphicsScene
601601
*/
602602
bool exportAsPDF( const QString& file );
603603

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

608-
/** Render a page to a paint device
612+
/** Renders a portion of the composition to an image. This method can be used to render
613+
* sections of pages rather than full pages.
614+
* @param rect region of composition to render
615+
* @returns rendered image, or null image if image does not fit into available memory
616+
* @note added in QGIS 2.12
617+
* @see printPageAsRaster()
618+
* @see renderRect()
619+
*/
620+
QImage renderRectAsRaster( const QRectF& rect );
621+
622+
/** Renders a full page to a paint device.
609623
* @param p destination painter
610-
* @param page page number, 0 based such that the first page is page 0 */
624+
* @param page page number, 0 based such that the first page is page 0
625+
* @see renderRect()
626+
* @see printPageAsRaster()
627+
*/
611628
void renderPage( QPainter* p, int page );
612629

613-
/** Compute world file parameters */
630+
/** Renders a portion of the composition to a paint device. This method can be used
631+
* to render sections of pages rather than full pages.
632+
* @param p destination painter
633+
* @param rect region of composition to render
634+
* @note added in QGIS 2.12
635+
* @see renderPage()
636+
* @see renderRectAsRaster()
637+
*/
638+
void renderRect( QPainter* p, const QRectF& rect );
639+
640+
/** Compute world file parameters. Assumes the whole page containing the associated map item
641+
* will be exported.
642+
*/
614643
void computeWorldFileParameters( double& a, double& b, double& c, double& d, double& e, double& f ) const;
615644

645+
/** Computes the world file parameters for a specified region of the composition.
646+
* @param exportRegion region of the composition which will be associated with world file
647+
* @param a
648+
* @param b
649+
* @param c
650+
* @param d
651+
* @param e
652+
* @param f
653+
* @note added in QGIS 2.12
654+
*/
655+
void computeWorldFileParameters( const QRectF& exportRegion, double& a, double& b, double& c, double& d, double& e, double& f ) const;
656+
616657
QgsAtlasComposition& atlasComposition();
617658

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

747+
/** Returns the bounding box of the items contained on a specified page.
748+
* @param pageNumber page number, where 0 is the first page
749+
* @param visibleOnly set to true to only include visible items
750+
* @note added in QGIS 2.12
751+
*/
752+
QRectF pageItemBounds( int pageNumber, bool visibleOnly = false ) const;
753+
754+
/** Calculates the bounds of all non-gui items in the composition. Ignores snap lines and mouse handles.
755+
* @param ignorePages set to true to ignore page items
756+
* @param margin optional marginal (in percent, eg 0.05 = 5% ) to add around items
757+
*/
758+
QRectF compositionBounds( bool ignorePages = false, double margin = 0.0 ) const;
759+
760+
706761
public slots:
707762
/** Casts object to the proper subclass type and calls corresponding itemAdded signal*/
708763
void sendItemAddedSignal( QgsComposerItem* item );

‎src/app/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ SET(QGIS_APP_SRCS
124124
composer/qgscomposerarrowwidget.cpp
125125
composer/qgscomposerattributetablewidget.cpp
126126
composer/qgscomposerhtmlwidget.cpp
127+
composer/qgscomposerimageexportoptionsdialog.cpp
127128
composer/qgscomposeritemwidget.cpp
128129
composer/qgscomposerlabelwidget.cpp
129130
composer/qgscomposerpicturewidget.cpp
@@ -278,6 +279,7 @@ SET (QGIS_APP_MOC_HDRS
278279
composer/qgscomposerarrowwidget.h
279280
composer/qgscomposerattributetablewidget.h
280281
composer/qgscomposerhtmlwidget.h
282+
composer/qgscomposerimageexportoptionsdialog.h
281283
composer/qgscomposeritemwidget.h
282284
composer/qgscomposerlabelwidget.h
283285
composer/qgscomposerlegendwidget.h

0 commit comments

Comments
 (0)
Please sign in to comment.