QGIS API Documentation 3.99.0-Master (e69e8341d6a)
qgslayoutrendercontext.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutrendercontext.cpp
3 --------------------
4 begin : July 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
18#include "moc_qgslayoutrendercontext.cpp"
19#include "qgslayout.h"
20
22 : QObject( layout )
23 , mFlags( Qgis::LayoutRenderFlag::Antialiasing | Qgis::LayoutRenderFlag::UseAdvancedEffects )
24 , mLayout( layout )
25{
27}
28
30{
31 if ( flags == mFlags )
32 return;
33
34 mFlags = flags;
35 matchRasterizedRenderingPolicyToFlags();
36 emit flagsChanged( mFlags );
37}
38
40{
41 Qgis::LayoutRenderFlags newFlags = mFlags;
42 if ( on )
43 newFlags |= flag;
44 else
45 newFlags &= ~static_cast< int >( flag );
46
47 if ( newFlags == mFlags )
48 return;
49
50 mFlags = newFlags;
51 matchRasterizedRenderingPolicyToFlags();
52 emit flagsChanged( mFlags );
53}
54
59
61{
62 return mFlags.testFlag( flag );
63}
64
82
84{
85 return mRasterizedRenderingPolicy;
86}
87
89{
90 mRasterizedRenderingPolicy = policy;
91 switch ( mRasterizedRenderingPolicy )
92 {
95 mFlags.setFlag( Qgis::LayoutRenderFlag::ForceVectorOutput, false );
96 mFlags.setFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects, true );
97 break;
99 mFlags.setFlag( Qgis::LayoutRenderFlag::ForceVectorOutput, true );
100 mFlags.setFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects, false );
101 break;
102 }
103}
104
106{
107 if ( qgsDoubleNear( dpi, mMeasurementConverter.dpi() ) )
108 return;
109
110 mMeasurementConverter.setDpi( dpi );
111 emit dpiChanged();
112}
113
115{
116 return mMeasurementConverter.dpi();
117}
118
120{
121 return mGridVisible;
122}
123
125{
126 mGridVisible = visible;
127}
128
130{
131 return mBoundingBoxesVisible;
132}
133
135{
136 mBoundingBoxesVisible = visible;
137}
138
140{
141 mPagesVisible = visible;
142}
143
145{
146 mMaskRenderSettings = settings;
147}
148
150{
151 return mExportThemes;
152}
153
154void QgsLayoutRenderContext::setExportThemes( const QStringList &exportThemes )
155{
156 mExportThemes = exportThemes;
157}
158
159void QgsLayoutRenderContext::setPredefinedScales( const QVector<qreal> &scales )
160{
161 if ( scales == mPredefinedScales )
162 return;
163
164 mPredefinedScales = scales;
165 // make sure the list is sorted
166 std::sort( mPredefinedScales.begin(), mPredefinedScales.end() ); // clazy:exclude=detaching-member
168}
169
171{
172 return mFeatureFilterProvider;
173}
174
176{
177 mFeatureFilterProvider = featureFilterProvider;
178}
179
180void QgsLayoutRenderContext::matchRasterizedRenderingPolicyToFlags()
181{
182 if ( !mFlags.testFlag( Qgis::LayoutRenderFlag::ForceVectorOutput )
183 && mFlags.testFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects ) )
184 mRasterizedRenderingPolicy = Qgis::RasterizedRenderingPolicy::PreferVector;
185 else if ( mFlags.testFlag( Qgis::LayoutRenderFlag::ForceVectorOutput )
186 || !mFlags.testFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects ) )
187 mRasterizedRenderingPolicy = Qgis::RasterizedRenderingPolicy::ForceVector;
188}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:54
RasterizedRenderingPolicy
Policies controlling when rasterisation of content during renders is permitted.
Definition qgis.h:2653
@ Default
Allow raster-based rendering in situations where it is required for correct rendering or where it wil...
@ PreferVector
Prefer vector-based rendering, when the result will still be visually near-identical to a raster-base...
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
@ NoSimplification
No simplification can be applied.
QFlags< RenderContextFlag > RenderContextFlags
Render context flags.
Definition qgis.h:2724
QFlags< LayoutRenderFlag > LayoutRenderFlags
Flags for controlling how a layout is rendered.
Definition qgis.h:5141
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ Antialiasing
Use antialiasing while drawing.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ HighQualityImageTransforms
Enable high quality image transformations, which results in better appearance of scaled or rotated ra...
LayoutRenderFlag
Flags for controlling how a layout is rendered.
Definition qgis.h:5118
@ ForceVectorOutput
Force output in vector format where possible, even if items require rasterization to keep their corre...
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ Antialiasing
Use antialiasing when drawing items.
@ UseAdvancedEffects
Enable advanced effects such as blend modes.
Abstract interface for use by classes that filter the features or attributes of a layer.
double dpi() const
Returns the Dots per inch (DPI) of the measurement converter.
void setDpi(const double dpi)
Sets the dots per inch (dpi) for the measurement converter.
void setDpi(double dpi)
Sets the dpi for outputting the layout.
void dpiChanged()
Emitted when the context's DPI is changed.
void setGridVisible(bool visible)
Sets whether the page grid should be visible.
void predefinedScalesChanged()
Emitted when the list of predefined scales changes.
void setFeatureFilterProvider(QgsFeatureFilterProvider *featureFilterProvider)
Sets feature filter provider to featureFilterProvider.
Qgis::LayoutRenderFlags flags() const
Returns the current combination of flags used for rendering the layout.
bool boundingBoxesVisible() const
Returns true if the item bounding boxes should be drawn.
bool gridVisible() const
Returns true if the page grid should be drawn.
QStringList exportThemes() const
Returns a list of map themes to use during the export.
QgsFeatureFilterProvider * featureFilterProvider() const
Returns the (possibly nullptr) feature filter provider.
void flagsChanged(Qgis::LayoutRenderFlags flags)
Emitted whenever the context's flags change.
void setRasterizedRenderingPolicy(Qgis::RasterizedRenderingPolicy policy)
Sets the policy controlling when rasterization of content during renders is permitted.
QgsLayoutRenderContext(QgsLayout *layout)
Constructor for QgsLayoutRenderContext.
double dpi() const
Returns the dpi for outputting the layout.
Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const
Returns the policy controlling when rasterization of content during renders is permitted.
void setPredefinedScales(const QVector< qreal > &scales)
Sets the list of predefined scales to use with the layout.
Qgis::RenderContextFlags renderContextFlags() const
Returns the combination of render context flags matched to the layout context's settings.
void setMaskSettings(const QgsMaskRenderSettings &settings)
Sets the mask render settings, which control how masks are drawn and behave during map renders.
void setExportThemes(const QStringList &themes)
Sets a list of map themes to use during the export.
void setFlags(Qgis::LayoutRenderFlags flags)
Sets the combination of flags that will be used for rendering the layout.
void setPagesVisible(bool visible)
Sets whether the page items should be visible in the layout.
void setBoundingBoxesVisible(bool visible)
Sets whether the item bounding boxes should be visible.
bool testFlag(Qgis::LayoutRenderFlag flag) const
Check whether a particular rendering flag is enabled for the layout.
void setFlag(Qgis::LayoutRenderFlag flag, bool on=true)
Enables or disables a particular rendering flag for the layout.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition qgslayout.h:49
Contains settings regarding how masks are calculated and handled during a map render.
void setSimplifyHints(Qgis::VectorRenderingSimplificationFlags simplifyHints)
Sets the simplification hints of the vector layer managed.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:6387