diff --git a/python/core/layout/qgslayout.sip b/python/core/layout/qgslayout.sip index eb3e5cd1203..0f1d4f46180 100644 --- a/python/core/layout/qgslayout.sip +++ b/python/core/layout/qgslayout.sip @@ -13,6 +13,12 @@ class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator, QgsLayoutUndoOb %Docstring Base class for layouts, which can contain items such as maps, labels, scalebars, etc. +While the raw QGraphicsScene API can be used to render the contents of a QgsLayout +to a QPainter, it is recommended to instead use a QgsLayoutExporter to handle rendering +layouts instead. QgsLayoutExporter automatically takes care of the intracacies of +preparing the layout and paint devices for correct exports, respecting various +user settings such as the layout context DPI. + .. versionadded:: 3.0 %End @@ -72,12 +78,6 @@ relations and various other bits. It is never null. QgsLayoutModel *itemsModel(); %Docstring Returns the items model attached to the layout. -%End - - QgsLayoutExporter &exporter(); -%Docstring -Returns the layout's exporter, which is used for rendering the layout and exporting -to various formats. %End QString name() const; @@ -182,7 +182,7 @@ z order list. This should be called after any stacking changes which deferred z-order updates. %End - QgsLayoutItem *itemByUuid( const QString &uuid, bool includeTemplateUuids = false ); + QgsLayoutItem *itemByUuid( const QString &uuid, bool includeTemplateUuids = false ) const; %Docstring Returns the layout item with matching ``uuid`` unique identifier, or a None if a matching item could not be found. @@ -387,8 +387,25 @@ Return list of keys stored in custom properties for the layout. %End QgsLayoutItemMap *referenceMap() const; +%Docstring +Returns the map item which will be used to generate corresponding world files when the +layout is exported. If no map was explicitly set via setReferenceMap(), the largest +map in the layout will be returned (or None if there are no maps in the layout). + +.. seealso:: :py:func:`setReferenceMap()` + +.. seealso:: :py:func:`generateWorldFile()` +%End void setReferenceMap( QgsLayoutItemMap *map ); +%Docstring +Sets the ``map`` item which will be used to generate corresponding world files when the +layout is exported. + +.. seealso:: :py:func:`referenceMap()` + +.. seealso:: :py:func:`setGenerateWorldFile()` +%End QgsLayoutPageCollection *pageCollection(); %Docstring @@ -406,6 +423,20 @@ and other cosmetic items. :param margin: optional marginal (in percent, e.g., 0.05 = 5% ) to add around items :return: layout bounds, in layout units. + +.. seealso:: :py:func:`pageItemBounds()` +%End + + QRectF pageItemBounds( int page, bool visibleOnly = false ) const; +%Docstring +Returns the bounding box of the items contained on a specified ``page``. +A page number of 0 represents the first page in the layout. + +Set ``visibleOnly`` to true to only include visible items. + +The returned bounds are in layout units. + +.. seealso:: :py:func:`layoutBounds()` %End void addLayoutItem( QgsLayoutItem *item /Transfer/ ); @@ -549,9 +580,9 @@ Updates the scene bounds of the layout. void changed(); %Docstring - Is emitted when properties of the layout change. This signal is only - emitted for settings directly managed by the layout, and is not emitted - when child items change. +Is emitted when properties of the layout change. This signal is only +emitted for settings directly managed by the layout, and is not emitted +when child items change. %End void variablesChanged(); diff --git a/python/core/layout/qgslayoutexporter.sip b/python/core/layout/qgslayoutexporter.sip index c4bad687691..0e9b9e86bb2 100644 --- a/python/core/layout/qgslayoutexporter.sip +++ b/python/core/layout/qgslayoutexporter.sip @@ -53,8 +53,7 @@ Constructor for QgsLayoutExporter, for the specified ``layout``. QgsLayout *layout() const; %Docstring - Returns the layout linked to this exporter. - :rtype: QgsLayout +Returns the layout linked to this exporter. %End void renderPage( QPainter *painter, int page ) const; @@ -69,23 +68,23 @@ are 0 based, such that the first page in a layout is page 0. QImage renderPageToImage( int page, QSize imageSize = QSize(), double dpi = 0 ) const; %Docstring - Renders a full page to an image. +Renders a full page to an image. - The ``page`` argument specifies the page number to render. Page numbers - are 0 based, such that the first page in a layout is page 0. +The ``page`` argument specifies the page number to render. Page numbers +are 0 based, such that the first page in a layout is page 0. - The optional ``imageSize`` parameter can specify the target image size, in pixels. - It is the caller's responsibility to ensure that the ratio of the target image size - matches the ratio of the corresponding layout page size. +The optional ``imageSize`` parameter can specify the target image size, in pixels. +It is the caller's responsibility to ensure that the ratio of the target image size +matches the ratio of the corresponding layout page size. - The ``dpi`` parameter is an optional dpi override. Set to 0 to use the default layout print - resolution. This parameter has no effect if ``imageSize`` is specified. +The ``dpi`` parameter is an optional dpi override. Set to 0 to use the default layout print +resolution. This parameter has no effect if ``imageSize`` is specified. - Returns the rendered image, or a null QImage if the image does not fit into available memory. +Returns the rendered image, or a null QImage if the image does not fit into available memory. .. seealso:: :py:func:`renderPage()` + .. seealso:: :py:func:`renderRegionToImage()` - :rtype: QImage %End void renderRegion( QPainter *painter, const QRectF ®ion ) const; @@ -94,26 +93,27 @@ Renders a ``region`` from the layout to a ``painter``. This method can be used to render sections of pages rather than full pages. .. seealso:: :py:func:`renderPage()` + .. seealso:: :py:func:`renderRegionToImage()` %End QImage renderRegionToImage( const QRectF ®ion, QSize imageSize = QSize(), double dpi = 0 ) const; %Docstring - Renders a ``region`` of the layout to an image. This method can be used to render - sections of pages rather than full pages. +Renders a ``region`` of the layout to an image. This method can be used to render +sections of pages rather than full pages. - The optional ``imageSize`` parameter can specify the target image size, in pixels. - It is the caller's responsibility to ensure that the ratio of the target image size - matches the ratio of the specified region of the layout. +The optional ``imageSize`` parameter can specify the target image size, in pixels. +It is the caller's responsibility to ensure that the ratio of the target image size +matches the ratio of the specified region of the layout. - The ``dpi`` parameter is an optional dpi override. Set to 0 to use the default layout print - resolution. This parameter has no effect if ``imageSize`` is specified. +The ``dpi`` parameter is an optional dpi override. Set to 0 to use the default layout print +resolution. This parameter has no effect if ``imageSize`` is specified. - Returns the rendered image, or a null QImage if the image does not fit into available memory. +Returns the rendered image, or a null QImage if the image does not fit into available memory. .. seealso:: :py:func:`renderRegion()` + .. seealso:: :py:func:`renderPageToImage()` - :rtype: QImage %End @@ -139,63 +139,62 @@ Resolution to export layout at. If dpi <= 0 the default layout dpi will be used. QSize imageSize; %Docstring - Manual size in pixels for output image. If imageSize is not - set then it will be automatically calculated based on the - output dpi and layout size. +Manual size in pixels for output image. If imageSize is not +set then it will be automatically calculated based on the +output dpi and layout size. - If cropToContents is true then imageSize has no effect. +If cropToContents is true then imageSize has no effect. - Be careful when specifying manual sizes if pages in the layout - have differing sizes! It's likely not going to give a reasonable - output in this case, and the automatic dpi-based image size should be - used instead. +Be careful when specifying manual sizes if pages in the layout +have differing sizes! It's likely not going to give a reasonable +output in this case, and the automatic dpi-based image size should be +used instead. %End bool cropToContents; %Docstring - Set to true if image should be cropped so only parts of the layout - containing items are exported. +Set to true if image should be cropped so only parts of the layout +containing items are exported. %End QgsMargins cropMargins; %Docstring - Crop to content margins, in pixels. These margins will be added - to the bounds of the exported layout if cropToContents is true. +Crop to content margins, in pixels. These margins will be added +to the bounds of the exported layout if cropToContents is true. %End QList< int > pages; %Docstring - List of specific pages to export, or an empty list to - export all pages. +List of specific pages to export, or an empty list to +export all pages. - Page numbers are 0 index based, so the first page in the - layout corresponds to page 0. +Page numbers are 0 index based, so the first page in the +layout corresponds to page 0. %End bool generateWorldFile; %Docstring - Set to true to generate an external world file alongside - exported images. +Set to true to generate an external world file alongside +exported images. %End QgsLayoutContext::Flags flags; %Docstring - Layout context flags, which control how the export will be created. +Layout context flags, which control how the export will be created. %End }; ExportResult exportToImage( const QString &filePath, const QgsLayoutExporter::ImageExportSettings &settings ); %Docstring - Exports the layout to the a ``filePath``, using the specified export ``settings``. +Exports the layout to the a ``filePath``, using the specified export ``settings``. - If the layout is a multi-page layout, then filenames for each page will automatically - be generated by appending "_1", "_2", etc to the image file's base name. +If the layout is a multi-page layout, then filenames for each page will automatically +be generated by appending "_1", "_2", etc to the image file's base name. - Returns a result code indicating whether the export was successful or an - error was encountered. If an error code is returned, errorFile() can be called - to determine the filename for the export which encountered the error. - :rtype: ExportResult +Returns a result code indicating whether the export was successful or an +error was encountered. If an error code is returned, errorFile() can be called +to determine the filename for the export which encountered the error. %End struct PdfExportSettings @@ -212,85 +211,81 @@ Resolution to export layout at. If dpi <= 0 the default layout dpi will be used. bool rasterizeWholeImage; %Docstring - Set to true to force whole layout to be rasterized while exporting. +Set to true to force whole layout to be rasterized while exporting. - This option is mutually exclusive with forceVectorOutput. +This option is mutually exclusive with forceVectorOutput. %End bool forceVectorOutput; %Docstring - Set to true to force vector object exports, even when the resultant appearance will differ - from the layout. If false, some items may be rasterized in order to maintain their - correct appearance in the output. +Set to true to force vector object exports, even when the resultant appearance will differ +from the layout. If false, some items may be rasterized in order to maintain their +correct appearance in the output. - This option is mutually exclusive with rasterizeWholeImage. +This option is mutually exclusive with rasterizeWholeImage. %End QgsLayoutContext::Flags flags; %Docstring - Layout context flags, which control how the export will be created. +Layout context flags, which control how the export will be created. %End }; ExportResult exportToPdf( const QString &filePath, const QgsLayoutExporter::PdfExportSettings &settings ); %Docstring - Exports the layout as a PDF to the a ``filePath``, using the specified export ``settings``. +Exports the layout as a PDF to the a ``filePath``, using the specified export ``settings``. - Returns a result code indicating whether the export was successful or an - error was encountered. - :rtype: ExportResult +Returns a result code indicating whether the export was successful or an +error was encountered. %End QString errorFile() const; %Docstring - Returns the file name corresponding to the last error encountered during - an export. - :rtype: str +Returns the file name corresponding to the last error encountered during +an export. %End bool georeferenceOutput( const QString &file, QgsLayoutItemMap *referenceMap = 0, const QRectF &exportRegion = QRectF(), double dpi = -1 ) const; %Docstring - Georeferences a ``file`` (image of PDF) exported from the layout. +Georeferences a ``file`` (image of PDF) exported from the layout. - The ``referenceMap`` argument specifies a map item to use for georeferencing. If left as None, the - default layout QgsLayout.referenceMap() will be used. +The ``referenceMap`` argument specifies a map item to use for georeferencing. If left as None, the +default layout QgsLayout.referenceMap() will be used. - The ``exportRegion`` argument can be set to a valid rectangle to indicate that only part of the layout was - exported. +The ``exportRegion`` argument can be set to a valid rectangle to indicate that only part of the layout was +exported. - Similarly, the ``dpi`` can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. +Similarly, the ``dpi`` can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. - The function will return true if the output was successfully georeferenced. +The function will return true if the output was successfully georeferenced. .. seealso:: :py:func:`computeGeoTransform()` - :rtype: bool %End void computeWorldFileParameters( double &a, double &b, double &c, double &d, double &e, double &f, double dpi = -1 ) const; %Docstring - Compute world file parameters. Assumes the whole page containing the reference map item - will be exported. +Compute world file parameters. Assumes the whole page containing the reference map item +will be exported. - The ``dpi`` argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. +The ``dpi`` argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. %End void computeWorldFileParameters( const QRectF ®ion, double &a, double &b, double &c, double &d, double &e, double &f, double dpi = -1 ) const; %Docstring - Computes the world file parameters for a specified ``region`` of the layout. +Computes the world file parameters for a specified ``region`` of the layout. - The ``dpi`` argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. +The ``dpi`` argument can be set to the actual DPI of exported file, or left as -1 to use the layout's default DPI. %End protected: virtual QString generateFileName( const PageExportDetails &details ) const; %Docstring - Generates the file name for a page during export. +Generates the file name for a page during export. - Subclasses can override this method to customise page file naming. - :rtype: str +Subclasses can override this method to customise page file naming. %End }; diff --git a/python/core/layout/qgslayoutitem.sip b/python/core/layout/qgslayoutitem.sip index 41048d0595a..9079bdfb88f 100644 --- a/python/core/layout/qgslayoutitem.sip +++ b/python/core/layout/qgslayoutitem.sip @@ -822,22 +822,21 @@ Sets whether the item should be excluded from composer exports and prints. virtual bool containsAdvancedEffects() const; %Docstring - Returns true if the item contains contents with blend modes or transparency - effects which can only be reproduced by rastering the item. +Returns true if the item contains contents with blend modes or transparency +effects which can only be reproduced by rastering the item. - Subclasses should ensure that implemented overrides of this method - also check the base class result. +Subclasses should ensure that implemented overrides of this method +also check the base class result. .. seealso:: :py:func:`requiresRasterization()` - :rtype: bool %End virtual bool requiresRasterization() const; %Docstring - Returns true if the item is drawn in such a way that forces the whole layout - to be rasterised when exporting to vector formats. +Returns true if the item is drawn in such a way that forces the whole layout +to be rasterized when exporting to vector formats. + .. seealso:: :py:func:`containsAdvancedEffects()` - :rtype: bool %End virtual double estimatedFrameBleed() const; @@ -920,6 +919,11 @@ Cancels the current item command and discards it. .. seealso:: :py:func:`beginCommand()` .. seealso:: :py:func:`endCommand()` +%End + + bool shouldDrawItem() const; +%Docstring +Returns whether the item should be drawn in the current context. %End public slots: @@ -1161,11 +1165,6 @@ in finalizeRestoreFromXml(), not readPropertiesFromElement(). .. seealso:: :py:func:`writePropertiesToElement()` .. seealso:: :py:func:`readXml()` -%End - - bool shouldDrawItem() const; -%Docstring -Returns whether the item should be drawn in the current context. %End QgsLayoutSize applyDataDefinedSize( const QgsLayoutSize &size ); diff --git a/python/core/layout/qgslayoutitemmap.sip b/python/core/layout/qgslayoutitemmap.sip index fb8c4c4f3cb..b47b1475f52 100644 --- a/python/core/layout/qgslayoutitemmap.sip +++ b/python/core/layout/qgslayoutitemmap.sip @@ -62,7 +62,6 @@ The caller takes responsibility for deleting the returned object. virtual void setFrameStrokeWidth( const QgsLayoutMeasurement &width ); - double scale() const; %Docstring Returns the map scale. @@ -280,10 +279,10 @@ Sets preset name for map rendering. See followVisibilityPresetName() for more de Returns true if the map contains a WMS layer. %End - bool containsAdvancedEffects() const; -%Docstring -Returns true if the map contains layers with blend modes or flattened layers for vectors -%End + virtual bool requiresRasterization() const; + + virtual bool containsAdvancedEffects() const; + void setMapRotation( double rotation ); %Docstring diff --git a/python/core/layout/qgslayoutpagecollection.sip b/python/core/layout/qgslayoutpagecollection.sip index ce2510b792b..44dbfe2d7c2 100644 --- a/python/core/layout/qgslayoutpagecollection.sip +++ b/python/core/layout/qgslayoutpagecollection.sip @@ -85,6 +85,8 @@ Returns a list of the page numbers which are visible within the specified %Docstring Returns whether a given ``page`` index is empty, ie, it contains no items except for the background paper item. + +.. seealso:: :py:func:`shouldExportPage()` %End QList< QgsLayoutItem *> itemsOnPage( int page ) const; @@ -92,6 +94,14 @@ paper item. Returns a list of layout items on the specified ``page`` index. %End + + bool shouldExportPage( int page ) const; +%Docstring +Returns whether the specified ``page`` number should be included in exports of the layouts. + +.. seealso:: :py:func:`pageIsEmpty()` +%End + void addPage( QgsLayoutItemPage *page /Transfer/ ); %Docstring Adds a ``page`` to the collection. Ownership of the ``page`` is transferred @@ -188,17 +198,19 @@ Returns the symbol to use for drawing pages in the collection. void beginPageSizeChange(); %Docstring - Should be called before changing any page item sizes, and followed by a call to - endPageSizeChange(). If page size changes are wrapped in these calls, then items - will maintain their same relative position on pages after the page sizes are updated. +Should be called before changing any page item sizes, and followed by a call to +endPageSizeChange(). If page size changes are wrapped in these calls, then items +will maintain their same relative position on pages after the page sizes are updated. + .. seealso:: :py:func:`endPageSizeChange()` %End void endPageSizeChange(); %Docstring - Should be called after changing any page item sizes, and preceded by a call to - beginPageSizeChange(). If page size changes are wrapped in these calls, then items - will maintain their same relative position on pages after the page sizes are updated. +Should be called after changing any page item sizes, and preceded by a call to +beginPageSizeChange(). If page size changes are wrapped in these calls, then items +will maintain their same relative position on pages after the page sizes are updated. + .. seealso:: :py:func:`beginPageSizeChange()` %End @@ -212,15 +224,24 @@ for page size/orientation change. %Docstring Returns the maximum width of pages in the collection. The returned value is in layout units. + +.. seealso:: :py:func:`maximumPageSize()` +%End + + QSizeF maximumPageSize() const; +%Docstring +Returns the maximum size of any page in the collection, by area. The returned value +is in layout units. + +.. seealso:: :py:func:`maximumPageWidth()` %End bool hasUniformPageSizes() const; %Docstring - Returns true if the layout has uniform page sizes, e.g. all pages are the same size. +Returns true if the layout has uniform page sizes, e.g. all pages are the same size. - This method does not consider differing units as non-uniform sizes, only the actual - physical size of the pages. - :rtype: bool +This method does not consider differing units as non-uniform sizes, only the actual +physical size of the pages. %End int pageNumberForPoint( QPointF point ) const; @@ -309,12 +330,12 @@ Returns the size of the page shadow, in layout units. void resizeToContents( const QgsMargins &margins, QgsUnitTypes::LayoutUnit marginUnits ); %Docstring - Resizes the layout to a single page which fits the current contents of the layout. +Resizes the layout to a single page which fits the current contents of the layout. - Calling this method resets the number of pages to 1, with the size set to the - minimum size required to fit all existing layout items. Items will also be - repositioned so that the new top-left bounds of the layout is at the point - (marginLeft, marginTop). An optional margin can be specified. +Calling this method resets the number of pages to 1, with the size set to the +minimum size required to fit all existing layout items. Items will also be +repositioned so that the new top-left bounds of the layout is at the point +(marginLeft, marginTop). An optional margin can be specified. %End virtual bool writeXml( QDomElement &parentElement, QDomDocument &document, const QgsReadWriteContext &context ) const; diff --git a/python/core/layout/qgslayoututils.sip b/python/core/layout/qgslayoututils.sip index 8777962853a..b0e6c82a0b5 100644 --- a/python/core/layout/qgslayoututils.sip +++ b/python/core/layout/qgslayoututils.sip @@ -216,10 +216,9 @@ the a specified ``rotation`` amount. static QgsLayoutItemPage::Orientation decodePaperOrientation( const QString &string, bool &ok ); %Docstring - Decodes a ``string`` representing a paper orientation and returns the - decoded orientation. - If the string was correctly decoded, ``ok`` will be set to true. - :rtype: QgsLayoutItemPage.Orientation +Decodes a ``string`` representing a paper orientation and returns the +decoded orientation. +If the string was correctly decoded, ``ok`` will be set to true. %End }; diff --git a/python/gui/layout/qgslayoutdesignerinterface.sip b/python/gui/layout/qgslayoutdesignerinterface.sip index 1e4db3a83c3..bd3dfdda479 100644 --- a/python/gui/layout/qgslayoutdesignerinterface.sip +++ b/python/gui/layout/qgslayoutdesignerinterface.sip @@ -48,8 +48,7 @@ Returns the layout view utilized by the designer. virtual QgsMessageBar *messageBar() = 0; %Docstring - Returns the designer's message bar. - :rtype: QgsMessageBar +Returns the designer's message bar. %End virtual void selectItems( const QList< QgsLayoutItem * > items ) = 0; diff --git a/src/app/layout/qgslayoutdesignerdialog.cpp b/src/app/layout/qgslayoutdesignerdialog.cpp index ee458d4bb26..7ab0df3d46a 100644 --- a/src/app/layout/qgslayoutdesignerdialog.cpp +++ b/src/app/layout/qgslayoutdesignerdialog.cpp @@ -1624,7 +1624,7 @@ void QgsLayoutDesignerDialog::exportToPdf() QApplication::setOverrideCursor( Qt::BusyCursor ); QgsLayoutExporter::PdfExportSettings pdfSettings; - pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterise" ), false ).toBool(); + pdfSettings.rasterizeWholeImage = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool(); pdfSettings.forceVectorOutput = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool(); // force a refresh, to e.g. update data defined properties, tables, etc @@ -1843,7 +1843,7 @@ bool QgsLayoutDesignerDialog::containsAdvancedEffects() const void QgsLayoutDesignerDialog::showRasterizationWarning() { - if ( mLayout->customProperty( QStringLiteral( "rasterise" ), false ).toBool() || + if ( mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool() || mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool() ) return; @@ -1855,7 +1855,7 @@ void QgsLayoutDesignerDialog::showRasterizationWarning() m.setCheckBoxVisible( true ); m.showMessage( true ); - mLayout->setCustomProperty( QStringLiteral( "rasterise" ), m.checkBoxState() == Qt::Checked ); + mLayout->setCustomProperty( QStringLiteral( "rasterize" ), m.checkBoxState() == Qt::Checked ); //make sure print as raster checkbox is updated mLayoutPropertiesWidget->updateGui(); } diff --git a/src/app/layout/qgslayoutpropertieswidget.cpp b/src/app/layout/qgslayoutpropertieswidget.cpp index 54d14a9ca18..8ebd70fd108 100644 --- a/src/app/layout/qgslayoutpropertieswidget.cpp +++ b/src/app/layout/qgslayoutpropertieswidget.cpp @@ -58,7 +58,7 @@ QgsLayoutPropertiesWidget::QgsLayoutPropertiesWidget( QWidget *parent, QgsLayout mGenerateWorldFileCheckBox->setChecked( exportWorldFile ); connect( mGenerateWorldFileCheckBox, &QCheckBox::toggled, this, &QgsLayoutPropertiesWidget::worldFileToggled ); - connect( mRasterizeCheckBox, &QCheckBox::toggled, this, &QgsLayoutPropertiesWidget::rasteriseToggled ); + connect( mRasterizeCheckBox, &QCheckBox::toggled, this, &QgsLayoutPropertiesWidget::rasterizeToggled ); connect( mForceVectorCheckBox, &QCheckBox::toggled, this, &QgsLayoutPropertiesWidget::forceVectorToggled ); mTopMarginSpinBox->setValue( topMargin ); @@ -92,13 +92,13 @@ void QgsLayoutPropertiesWidget::updateGui() whileBlocking( mReferenceMapComboBox )->setItem( mLayout->referenceMap() ); whileBlocking( mResolutionSpinBox )->setValue( mLayout->context().dpi() ); - bool rasterise = mLayout->customProperty( QStringLiteral( "rasterise" ), false ).toBool(); - whileBlocking( mRasterizeCheckBox )->setChecked( rasterise ); + bool rasterize = mLayout->customProperty( QStringLiteral( "rasterize" ), false ).toBool(); + whileBlocking( mRasterizeCheckBox )->setChecked( rasterize ); bool forceVectors = mLayout->customProperty( QStringLiteral( "forceVector" ), false ).toBool(); whileBlocking( mForceVectorCheckBox )->setChecked( forceVectors ); - if ( rasterise ) + if ( rasterize ) { mForceVectorCheckBox->setChecked( false ); mForceVectorCheckBox->setEnabled( false ); @@ -208,9 +208,9 @@ void QgsLayoutPropertiesWidget::worldFileToggled() mLayout->setCustomProperty( QStringLiteral( "exportWorldFile" ), mGenerateWorldFileCheckBox->isChecked() ); } -void QgsLayoutPropertiesWidget::rasteriseToggled() +void QgsLayoutPropertiesWidget::rasterizeToggled() { - mLayout->setCustomProperty( QStringLiteral( "rasterise" ), mRasterizeCheckBox->isChecked() ); + mLayout->setCustomProperty( QStringLiteral( "rasterize" ), mRasterizeCheckBox->isChecked() ); if ( mRasterizeCheckBox->isChecked() ) { diff --git a/src/app/layout/qgslayoutpropertieswidget.h b/src/app/layout/qgslayoutpropertieswidget.h index e65bdabed0b..642bb243a85 100644 --- a/src/app/layout/qgslayoutpropertieswidget.h +++ b/src/app/layout/qgslayoutpropertieswidget.h @@ -46,7 +46,7 @@ class QgsLayoutPropertiesWidget: public QgsPanelWidget, private Ui::QgsLayoutWid void referenceMapChanged( QgsLayoutItem *item ); void dpiChanged( int value ); void worldFileToggled(); - void rasteriseToggled(); + void rasterizeToggled(); void forceVectorToggled(); private: diff --git a/src/core/layout/qgslayoutexporter.cpp b/src/core/layout/qgslayoutexporter.cpp index c9e193d4935..7e198c458e9 100644 --- a/src/core/layout/qgslayoutexporter.cpp +++ b/src/core/layout/qgslayoutexporter.cpp @@ -427,14 +427,14 @@ QgsLayoutExporter::ExportResult QgsLayoutExporter::print( QPrinter &printer ) return Success; } -QgsLayoutExporter::ExportResult QgsLayoutExporter::printPrivate( QPrinter &printer, QPainter &painter, bool startNewPage, double dpi, bool rasterise ) +QgsLayoutExporter::ExportResult QgsLayoutExporter::printPrivate( QPrinter &printer, QPainter &painter, bool startNewPage, double dpi, bool rasterize ) { //layout starts page numbering at 0 int fromPage = ( printer.fromPage() < 1 ) ? 0 : printer.fromPage() - 1; int toPage = ( printer.toPage() < 1 ) ? mLayout->pageCollection()->pageCount() - 1 : printer.toPage() - 1; bool pageExported = false; - if ( rasterise ) + if ( rasterize ) { for ( int i = fromPage; i <= toPage; ++i ) { diff --git a/src/core/layout/qgslayoutexporter.h b/src/core/layout/qgslayoutexporter.h index 96cc62aba2a..bd3f49b1500 100644 --- a/src/core/layout/qgslayoutexporter.h +++ b/src/core/layout/qgslayoutexporter.h @@ -343,6 +343,8 @@ class CORE_EXPORT QgsLayoutExporter * \param printer QPrinter destination * \param painter QPainter source * \param startNewPage set to true to begin the print on a new page + * \param dpi set to a value > 0 to manually override the layout's default dpi + * \param rasterize set to true to force print as a raster image */ ExportResult printPrivate( QPrinter &printer, QPainter &painter, bool startNewPage = false, double dpi = -1, bool rasterize = false ); diff --git a/src/core/layout/qgslayoutitem.h b/src/core/layout/qgslayoutitem.h index c4e70cd3927..2067c31e9f1 100644 --- a/src/core/layout/qgslayoutitem.h +++ b/src/core/layout/qgslayoutitem.h @@ -755,7 +755,7 @@ class CORE_EXPORT QgsLayoutItem : public QgsLayoutObject, public QGraphicsRectIt /** * Returns true if the item is drawn in such a way that forces the whole layout - * to be rasterised when exporting to vector formats. + * to be rasterized when exporting to vector formats. * \see containsAdvancedEffects() */ virtual bool requiresRasterization() const; diff --git a/src/core/layout/qgslayoutitemmap.cpp b/src/core/layout/qgslayoutitemmap.cpp index 3818744fd67..6a2d1a0d439 100644 --- a/src/core/layout/qgslayoutitemmap.cpp +++ b/src/core/layout/qgslayoutitemmap.cpp @@ -834,7 +834,7 @@ void QgsLayoutItemMap::paint( QPainter *painter, const QStyleOptionGraphicsItem if ( containsAdvancedEffects() && ( !mLayout || !( mLayout->context().flags() & QgsLayoutContext::FlagForceVectorOutput ) ) ) { - // rasterise + // rasterize double destinationDpi = style->matrix.m11() * 25.4; double layoutUnitsInInches = mLayout ? mLayout->convertFromLayoutUnits( 1, QgsUnitTypes::LayoutInches ).length() : 1; int widthInPixels = std::round( boundingRect().width() * layoutUnitsInInches * destinationDpi ); diff --git a/src/ui/layout/qgslayoutwidgetbase.ui b/src/ui/layout/qgslayoutwidgetbase.ui index 0bb37df5afc..58f9b5502f5 100644 --- a/src/ui/layout/qgslayoutwidgetbase.ui +++ b/src/ui/layout/qgslayoutwidgetbase.ui @@ -262,7 +262,7 @@ - If checked, the layout will always be kept as vector objects when exported to a compatible format, even if the appearance of the resultant file does not match the layouts settings. If unchecked, some elements in the layout may be rasterised in order to keep their appearance intact. + If checked, the layout will always be kept as vector objects when exported to a compatible format, even if the appearance of the resultant file does not match the layouts settings. If unchecked, some elements in the layout may be rasterized in order to keep their appearance intact. Always export as vectors diff --git a/tests/src/core/testqgslayoutmap.cpp b/tests/src/core/testqgslayoutmap.cpp index dbdf563d376..4fce7944437 100644 --- a/tests/src/core/testqgslayoutmap.cpp +++ b/tests/src/core/testqgslayoutmap.cpp @@ -444,7 +444,7 @@ void TestQgsLayoutMap::dataDefinedStyles() void TestQgsLayoutMap::rasterized() { - // test a map which must be rasterised + // test a map which must be rasterized QgsLayout l( QgsProject::instance() ); l.initializeDefaults(); @@ -496,7 +496,7 @@ void TestQgsLayoutMap::rasterized() QVERIFY( checker.testLayout( mReport, 0, 0 ) ); // try rendering again, without requiring rasterization, for comparison - // (we can use the same test image, because CompositionMode_Darken doesn't actually have any noticable + // (we can use the same test image, because CompositionMode_Darken doesn't actually have any noticeable // rendering differences for the black grid!) grid->setBlendMode( QPainter::CompositionMode_SourceOver ); QVERIFY( !map->containsAdvancedEffects() );