QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
17 #include "qgslayoutrendercontext.h"
18 #include "qgslayout.h"
19 
21  : QObject( layout )
22  , mFlags( FlagAntialiasing | FlagUseAdvancedEffects )
23  , mLayout( layout )
24 {
26 }
27 
28 void QgsLayoutRenderContext::setFlags( const QgsLayoutRenderContext::Flags flags )
29 {
30  if ( flags == mFlags )
31  return;
32 
33  mFlags = flags;
34  emit flagsChanged( mFlags );
35 }
36 
38 {
39  Flags newFlags = mFlags;
40  if ( on )
41  newFlags |= flag;
42  else
43  newFlags &= ~flag;
44 
45  if ( newFlags == mFlags )
46  return;
47 
48  mFlags = newFlags;
49  emit flagsChanged( mFlags );
50 }
51 
52 QgsLayoutRenderContext::Flags QgsLayoutRenderContext::flags() const
53 {
54  return mFlags;
55 }
56 
58 {
59  return mFlags.testFlag( flag );
60 }
61 
62 QgsRenderContext::Flags QgsLayoutRenderContext::renderContextFlags() const
63 {
64  QgsRenderContext::Flags flags = QgsRenderContext::Flags();
65  if ( mFlags & FlagAntialiasing )
67  if ( mFlags & FlagUseAdvancedEffects )
69  if ( mFlags & FlagLosslessImageRendering )
71 
72  // TODO - expose as layout context flag?
74  return flags;
75 }
76 
78 {
79  if ( qgsDoubleNear( dpi, mMeasurementConverter.dpi() ) )
80  return;
81 
82  mMeasurementConverter.setDpi( dpi );
83  emit dpiChanged();
84 }
85 
87 {
88  return mMeasurementConverter.dpi();
89 }
90 
92 {
93  return mGridVisible;
94 }
95 
97 {
98  mGridVisible = visible;
99 }
100 
102 {
103  return mBoundingBoxesVisible;
104 }
105 
107 {
108  mBoundingBoxesVisible = visible;
109 }
110 
112 {
113  mPagesVisible = visible;
114 }
115 
117 {
118  return mExportThemes;
119 }
120 
121 void QgsLayoutRenderContext::setExportThemes( const QStringList &exportThemes )
122 {
123  mExportThemes = exportThemes;
124 }
125 
126 void QgsLayoutRenderContext::setPredefinedScales( const QVector<qreal> &scales )
127 {
128  if ( scales == mPredefinedScales )
129  return;
130 
131  mPredefinedScales = scales;
132  // make sure the list is sorted
133  std::sort( mPredefinedScales.begin(), mPredefinedScales.end() ); // clazy:exclude=detaching-member
135 }
QgsLayoutRenderContext::FlagUseAdvancedEffects
@ FlagUseAdvancedEffects
Enable advanced effects such as blend modes.
Definition: qgslayoutrendercontext.h:45
QgsLayoutRenderContext::flags
QgsLayoutRenderContext::Flags flags() const
Returns the current combination of flags used for rendering the layout.
Definition: qgslayoutrendercontext.cpp:52
QgsVectorSimplifyMethod::NoSimplification
@ NoSimplification
No simplification can be applied.
Definition: qgsvectorsimplifymethod.h:39
QgsLayoutRenderContext::predefinedScalesChanged
void predefinedScalesChanged()
Emitted when the list of predefined scales changes.
QgsRenderContext::UseAdvancedEffects
@ UseAdvancedEffects
Enable layer opacity and blending effects.
Definition: qgsrendercontext.h:74
QgsVectorSimplifyMethod::setSimplifyHints
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
Definition: qgsvectorsimplifymethod.h:49
QgsLayoutRenderContext::setFlags
void setFlags(QgsLayoutRenderContext::Flags flags)
Sets the combination of flags that will be used for rendering the layout.
Definition: qgslayoutrendercontext.cpp:28
QgsLayoutMeasurementConverter::setDpi
void setDpi(const double dpi)
Sets the dots per inch (dpi) for the measurement converter.
Definition: qgslayoutmeasurementconverter.h:54
QgsLayoutRenderContext::QgsLayoutRenderContext
QgsLayoutRenderContext(QgsLayout *layout)
Constructor for QgsLayoutRenderContext.
Definition: qgslayoutrendercontext.cpp:20
QgsRenderContext::ForceVectorOutput
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
Definition: qgsrendercontext.h:73
QgsLayoutRenderContext::testFlag
bool testFlag(Flag flag) const
Check whether a particular rendering flag is enabled for the layout.
Definition: qgslayoutrendercontext.cpp:57
QgsLayoutRenderContext::setDpi
void setDpi(double dpi)
Sets the dpi for outputting the layout.
Definition: qgslayoutrendercontext.cpp:77
QgsLayoutRenderContext::setPredefinedScales
void setPredefinedScales(const QVector< qreal > &scales)
Sets the list of predefined scales to use with the layout.
Definition: qgslayoutrendercontext.cpp:126
qgsDoubleNear
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:315
QgsLayoutRenderContext::exportThemes
QStringList exportThemes() const
Returns a list of map themes to use during the export.
Definition: qgslayoutrendercontext.cpp:116
QgsLayoutRenderContext::flagsChanged
void flagsChanged(QgsLayoutRenderContext::Flags flags)
Emitted whenever the context's flags change.
qgslayout.h
QgsRenderContext::LosslessImageRendering
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
Definition: qgsrendercontext.h:84
QgsLayoutRenderContext::FlagLosslessImageRendering
@ FlagLosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
Definition: qgslayoutrendercontext.h:51
QgsLayoutRenderContext::setFlag
void setFlag(QgsLayoutRenderContext::Flag flag, bool on=true)
Enables or disables a particular rendering flag for the layout.
Definition: qgslayoutrendercontext.cpp:37
qgslayoutrendercontext.h
QgsLayoutRenderContext::Flag
Flag
Flags for controlling how a layout is rendered.
Definition: qgslayoutrendercontext.h:41
QgsLayout
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:50
QgsLayoutMeasurementConverter::dpi
double dpi() const
Returns the Dots per inch (DPI) of the measurement converter.
Definition: qgslayoutmeasurementconverter.h:61
QgsLayoutRenderContext::setExportThemes
void setExportThemes(const QStringList &themes)
Sets a list of map themes to use during the export.
Definition: qgslayoutrendercontext.cpp:121
QgsLayoutRenderContext::setGridVisible
void setGridVisible(bool visible)
Sets whether the page grid should be visible.
Definition: qgslayoutrendercontext.cpp:96
QgsLayoutRenderContext::boundingBoxesVisible
bool boundingBoxesVisible() const
Returns true if the item bounding boxes should be drawn.
Definition: qgslayoutrendercontext.cpp:101
QgsLayoutRenderContext::setPagesVisible
void setPagesVisible(bool visible)
Sets whether the page items should be visible in the layout.
Definition: qgslayoutrendercontext.cpp:111
QgsRenderContext::Antialiasing
@ Antialiasing
Use antialiasing while drawing.
Definition: qgsrendercontext.h:79
QgsLayoutRenderContext::renderContextFlags
QgsRenderContext::Flags renderContextFlags() const
Returns the combination of render context flags matched to the layout context's settings.
Definition: qgslayoutrendercontext.cpp:62
QgsLayoutRenderContext::dpi
double dpi() const
Returns the dpi for outputting the layout.
Definition: qgslayoutrendercontext.cpp:86
QgsLayoutRenderContext::gridVisible
bool gridVisible() const
Returns true if the page grid should be drawn.
Definition: qgslayoutrendercontext.cpp:91
QgsLayoutRenderContext::FlagAntialiasing
@ FlagAntialiasing
Use antialiasing when drawing items.
Definition: qgslayoutrendercontext.h:44
QgsLayoutRenderContext::setBoundingBoxesVisible
void setBoundingBoxesVisible(bool visible)
Sets whether the item bounding boxes should be visible.
Definition: qgslayoutrendercontext.cpp:106
QgsLayoutRenderContext::dpiChanged
void dpiChanged()
Emitted when the context's DPI is changed.