QGIS API Documentation  3.0.2-Girona (307d082)
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 "qgsfeature.h"
19 #include "qgslayout.h"
20 
22  : QObject( layout )
23  , mFlags( FlagAntialiasing | FlagUseAdvancedEffects )
24  , mLayout( layout )
25 {}
26 
27 void QgsLayoutRenderContext::setFlags( const QgsLayoutRenderContext::Flags flags )
28 {
29  if ( flags == mFlags )
30  return;
31 
32  mFlags = flags;
33  emit flagsChanged( mFlags );
34 }
35 
37 {
38  Flags newFlags = mFlags;
39  if ( on )
40  newFlags |= flag;
41  else
42  newFlags &= ~flag;
43 
44  if ( newFlags == mFlags )
45  return;
46 
47  mFlags = newFlags;
48  emit flagsChanged( mFlags );
49 }
50 
51 QgsLayoutRenderContext::Flags QgsLayoutRenderContext::flags() const
52 {
53  return mFlags;
54 }
55 
57 {
58  return mFlags.testFlag( flag );
59 }
60 
61 QgsRenderContext::Flags QgsLayoutRenderContext::renderContextFlags() const
62 {
63  QgsRenderContext::Flags flags = nullptr;
64  if ( mFlags & FlagAntialiasing )
65  flags = flags | QgsRenderContext::Antialiasing;
66  if ( mFlags & FlagUseAdvancedEffects )
68 
69  // TODO - expose as layout context flag?
71  return flags;
72 }
73 
75 {
76  if ( dpi == mMeasurementConverter.dpi() )
77  return;
78 
79  mMeasurementConverter.setDpi( dpi );
80  emit dpiChanged();
81 }
82 
84 {
85  return mMeasurementConverter.dpi();
86 }
87 
89 {
90  return mGridVisible;
91 }
92 
94 {
95  mGridVisible = visible;
96 }
97 
99 {
100  return mBoundingBoxesVisible;
101 }
102 
104 {
105  mBoundingBoxesVisible = visible;
106 }
107 
109 {
110  mPagesVisible = visible;
111 }
void setDpi(double dpi)
Sets the dpi for outputting the layout.
Enable layer opacity and blending effects.
Use antialiasing while drawing.
Flag
Flags for controlling how a layout is rendered.
void flagsChanged(QgsLayoutRenderContext::Flags flags)
Emitted whenever the context'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'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's settings.
void setFlags(const QgsLayoutRenderContext::Flags flags)
Sets the combination of flags that will be used for rendering the layout.
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.
bool testFlag(const Flag flag) const
Check whether a particular rendering flag is enabled for the layout.
double dpi() const
Returns the Dots per inch (DPI) of the measurement converter.
Enable advanced effects such as blend modes.
void setFlag(const QgsLayoutRenderContext::Flag flag, const bool on=true)
Enables or disables a particular rendering flag for the layout.
QgsLayoutRenderContext(QgsLayout *layout)
Constructor for QgsLayoutRenderContext.