QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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
19#include "qgslayout.h"
20
21#include "moc_qgslayoutrendercontext.cpp"
22
24 : QObject( layout )
25 , mFlags( Qgis::LayoutRenderFlag::Antialiasing | Qgis::LayoutRenderFlag::UseAdvancedEffects )
26 , mLayout( layout )
27{
28 mSimplifyMethod.setSimplifyHints( Qgis::VectorRenderingSimplificationFlag::NoSimplification );
29}
30
32{
33 if ( flags == mFlags )
34 return;
35
36 mFlags = flags;
37 matchRasterizedRenderingPolicyToFlags();
38 emit flagsChanged( mFlags );
39}
40
42{
43 Qgis::LayoutRenderFlags newFlags = mFlags;
44 if ( on )
45 newFlags |= flag;
46 else
47 newFlags &= ~static_cast< int >( flag );
48
49 if ( newFlags == mFlags )
50 return;
51
52 mFlags = newFlags;
53 matchRasterizedRenderingPolicyToFlags();
54 emit flagsChanged( mFlags );
55}
56
61
63{
64 return mFlags.testFlag( flag );
65}
66
84
86{
87 return mRasterizedRenderingPolicy;
88}
89
91{
92 mRasterizedRenderingPolicy = policy;
93 switch ( mRasterizedRenderingPolicy )
94 {
97 mFlags.setFlag( Qgis::LayoutRenderFlag::ForceVectorOutput, false );
98 mFlags.setFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects, true );
99 break;
101 mFlags.setFlag( Qgis::LayoutRenderFlag::ForceVectorOutput, true );
102 mFlags.setFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects, false );
103 break;
104 }
105}
106
108{
109 if ( qgsDoubleNear( dpi, mMeasurementConverter.dpi() ) )
110 return;
111
112 mMeasurementConverter.setDpi( dpi );
113 emit dpiChanged();
114}
115
117{
118 return mMeasurementConverter.dpi();
119}
120
122{
123 return mGridVisible;
124}
125
127{
128 mGridVisible = visible;
129}
130
132{
133 return mBoundingBoxesVisible;
134}
135
137{
138 mBoundingBoxesVisible = visible;
139}
140
142{
143 mPagesVisible = visible;
144}
145
147{
148 mMaskRenderSettings = settings;
149}
150
152{
153 return mExportThemes;
154}
155
157{
158 mExportThemes = exportThemes;
159}
160
161void QgsLayoutRenderContext::setPredefinedScales( const QVector<qreal> &scales )
162{
163 if ( scales == mPredefinedScales )
164 return;
165
166 mPredefinedScales = scales;
167 // make sure the list is sorted
168 std::sort( mPredefinedScales.begin(), mPredefinedScales.end() ); // clazy:exclude=detaching-member
170}
171
173{
174 return mFeatureFilterProvider;
175}
176
181
182void QgsLayoutRenderContext::matchRasterizedRenderingPolicyToFlags()
183{
184 if ( !mFlags.testFlag( Qgis::LayoutRenderFlag::ForceVectorOutput )
185 && mFlags.testFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects ) )
186 mRasterizedRenderingPolicy = Qgis::RasterizedRenderingPolicy::PreferVector;
187 else if ( mFlags.testFlag( Qgis::LayoutRenderFlag::ForceVectorOutput )
188 || !mFlags.testFlag( Qgis::LayoutRenderFlag::UseAdvancedEffects ) )
189 mRasterizedRenderingPolicy = Qgis::RasterizedRenderingPolicy::ForceVector;
190}
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
RasterizedRenderingPolicy
Policies controlling when rasterisation of content during renders is permitted.
Definition qgis.h:2703
@ Default
Allow raster-based rendering in situations where it is required for correct rendering or where it wil...
Definition qgis.h:2704
@ PreferVector
Prefer vector-based rendering, when the result will still be visually near-identical to a raster-base...
Definition qgis.h:2705
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
Definition qgis.h:2706
@ NoSimplification
No simplification can be applied.
Definition qgis.h:3030
QFlags< RenderContextFlag > RenderContextFlags
Render context flags.
Definition qgis.h:2774
QFlags< LayoutRenderFlag > LayoutRenderFlags
Flags for controlling how a layout is rendered.
Definition qgis.h:5261
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
Definition qgis.h:2750
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
Definition qgis.h:2761
@ Antialiasing
Use antialiasing while drawing.
Definition qgis.h:2756
@ UseAdvancedEffects
Enable layer opacity and blending effects.
Definition qgis.h:2751
@ HighQualityImageTransforms
Enable high quality image transformations, which results in better appearance of scaled or rotated ra...
Definition qgis.h:2766
LayoutRenderFlag
Flags for controlling how a layout is rendered.
Definition qgis.h:5237
@ ForceVectorOutput
Force output in vector format where possible, even if items require rasterization to keep their corre...
Definition qgis.h:5242
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
Definition qgis.h:5247
@ Antialiasing
Use antialiasing when drawing items.
Definition qgis.h:5240
@ UseAdvancedEffects
Enable advanced effects such as blend modes.
Definition qgis.h:5241
Abstract interface for use by classes that filter the features or attributes of a layer.
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:50
Contains settings regarding how masks are calculated and handled during a map render.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:6607