QGIS API Documentation  3.6.0-Noosa (5873452)
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 {}
25 
26 void QgsLayoutRenderContext::setFlags( const QgsLayoutRenderContext::Flags flags )
27 {
28  if ( flags == mFlags )
29  return;
30 
31  mFlags = flags;
32  emit flagsChanged( mFlags );
33 }
34 
36 {
37  Flags newFlags = mFlags;
38  if ( on )
39  newFlags |= flag;
40  else
41  newFlags &= ~flag;
42 
43  if ( newFlags == mFlags )
44  return;
45 
46  mFlags = newFlags;
47  emit flagsChanged( mFlags );
48 }
49 
50 QgsLayoutRenderContext::Flags QgsLayoutRenderContext::flags() const
51 {
52  return mFlags;
53 }
54 
56 {
57  return mFlags.testFlag( flag );
58 }
59 
60 QgsRenderContext::Flags QgsLayoutRenderContext::renderContextFlags() const
61 {
62  QgsRenderContext::Flags flags = nullptr;
63  if ( mFlags & FlagAntialiasing )
64  flags = flags | QgsRenderContext::Antialiasing;
65  if ( mFlags & FlagUseAdvancedEffects )
67 
68  // TODO - expose as layout context flag?
70  return flags;
71 }
72 
74 {
75  if ( qgsDoubleNear( dpi, mMeasurementConverter.dpi() ) )
76  return;
77 
78  mMeasurementConverter.setDpi( dpi );
79  emit dpiChanged();
80 }
81 
83 {
84  return mMeasurementConverter.dpi();
85 }
86 
88 {
89  return mGridVisible;
90 }
91 
93 {
94  mGridVisible = visible;
95 }
96 
98 {
99  return mBoundingBoxesVisible;
100 }
101 
103 {
104  mBoundingBoxesVisible = visible;
105 }
106 
108 {
109  mPagesVisible = visible;
110 }
void setDpi(double dpi)
Sets the dpi for outputting the layout.
Enable layer opacity and blending effects.
void setFlag(QgsLayoutRenderContext::Flag flag, bool on=true)
Enables or disables a particular rendering flag for the layout.
Use antialiasing while drawing.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:265
Flag
Flags for controlling how a layout is rendered.
void flagsChanged(QgsLayoutRenderContext::Flags flags)
Emitted whenever the context&#39;s flags change.
void setDpi(const double dpi)
Sets the dots per inch (dpi) for the measurement converter.
bool boundingBoxesVisible() const
Returns true if the item bounding boxes should be drawn.
void setGridVisible(bool visible)
Sets whether the page grid should be visible.
void setPagesVisible(bool visible)
Sets whether the page items should be visible in the layout.
void dpiChanged()
Emitted when the context&#39;s DPI is changed.
bool gridVisible() const
Returns true if the page grid should be drawn.
void setBoundingBoxesVisible(bool visible)
Sets whether the item bounding boxes should be visible.
QgsLayoutRenderContext::Flags flags() const
Returns the current combination of flags used for rendering the layout.
double dpi() const
Returns the dpi for outputting the layout.
QgsRenderContext::Flags renderContextFlags() const
Returns the combination of render context flags matched to the layout context&#39;s settings.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Definition: qgslayout.h:49
Vector graphics should not be cached and drawn as raster images.
Use antialiasing when drawing items.
double dpi() const
Returns the Dots per inch (DPI) of the measurement converter.
void setFlags(QgsLayoutRenderContext::Flags flags)
Sets the combination of flags that will be used for rendering the layout.
Enable advanced effects such as blend modes.
bool testFlag(Flag flag) const
Check whether a particular rendering flag is enabled for the layout.
QgsLayoutRenderContext(QgsLayout *layout)
Constructor for QgsLayoutRenderContext.