Skip to content

Commit b2b35dd

Browse files
committed
Add a context class for layouts
Stores information relating to the current context (such as associated feature and layer) and rendering settings for a layout.
1 parent d70f53c commit b2b35dd

File tree

7 files changed

+424
-0
lines changed

7 files changed

+424
-0
lines changed

python/core/core_auto.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@
378378
%Include gps/qgsgpsdetector.sip
379379
%Include gps/qgsnmeaconnection.sip
380380
%Include gps/qgsgpsdconnection.sip
381+
%Include layout/qgslayoutcontext.sip
381382
%Include layout/qgslayoutitem.sip
382383
%Include layout/qgslayoutitemregistry.sip
383384
%Include layout/qgslayoutobject.sip
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutcontext.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
class QgsLayoutContext
12+
{
13+
%Docstring
14+
Stores information relating to the current context and rendering settings for a layout.
15+
.. versionadded:: 3.0
16+
%End
17+
18+
%TypeHeaderCode
19+
#include "qgslayoutcontext.h"
20+
%End
21+
public:
22+
23+
enum Flag
24+
{
25+
FlagDebug,
26+
FlagOutlineOnly,
27+
FlagAntialiasing,
28+
FlagUseAdvancedEffects,
29+
};
30+
typedef QFlags<QgsLayoutContext::Flag> Flags;
31+
32+
33+
QgsLayoutContext();
34+
35+
void setFlags( const QgsLayoutContext::Flags flags );
36+
%Docstring
37+
Sets the combination of ``flags`` that will be used for rendering the layout.
38+
.. seealso:: setFlag()
39+
.. seealso:: flags()
40+
.. seealso:: testFlag()
41+
%End
42+
43+
void setFlag( const QgsLayoutContext::Flag flag, const bool on = true );
44+
%Docstring
45+
Enables or disables a particular rendering ``flag`` for the layout. Other existing
46+
flags are not affected.
47+
.. seealso:: setFlags()
48+
.. seealso:: flags()
49+
.. seealso:: testFlag()
50+
%End
51+
52+
QgsLayoutContext::Flags flags() const;
53+
%Docstring
54+
Returns the current combination of flags used for rendering the layout.
55+
.. seealso:: setFlags()
56+
.. seealso:: setFlag()
57+
.. seealso:: testFlag()
58+
:rtype: QgsLayoutContext.Flags
59+
%End
60+
61+
bool testFlag( const Flag flag ) const;
62+
%Docstring
63+
Check whether a particular rendering ``flag`` is enabled for the layout.
64+
.. seealso:: setFlags()
65+
.. seealso:: setFlag()
66+
.. seealso:: flags()
67+
:rtype: bool
68+
%End
69+
70+
void setFeature( const QgsFeature &feature );
71+
%Docstring
72+
Sets the current ``feature`` for evaluating the layout. This feature may
73+
be used for altering an item's content and appearance for a report
74+
or atlas layout.
75+
.. seealso:: feature()
76+
%End
77+
78+
QgsFeature feature() const;
79+
%Docstring
80+
Returns the current feature for evaluating the layout. This feature may
81+
be used for altering an item's content and appearance for a report
82+
or atlas layout.
83+
.. seealso:: setFeature()
84+
:rtype: QgsFeature
85+
%End
86+
87+
QgsVectorLayer *layer() const;
88+
%Docstring
89+
Returns the vector layer associated with the layout's context.
90+
.. seealso:: setLayer()
91+
:rtype: QgsVectorLayer
92+
%End
93+
94+
void setLayer( QgsVectorLayer *layer );
95+
%Docstring
96+
Sets the vector ``layer`` associated with the layout's context.
97+
.. seealso:: layer()
98+
%End
99+
100+
};
101+
102+
103+
104+
105+
/************************************************************************
106+
* This file has been generated automatically from *
107+
* *
108+
* src/core/layout/qgslayoutcontext.h *
109+
* *
110+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
111+
************************************************************************/

src/core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ SET(QGIS_CORE_SRCS
350350
dxf/qgsdxfpallabeling.cpp
351351

352352
layout/qgslayout.cpp
353+
layout/qgslayoutcontext.cpp
353354
layout/qgslayoutitem.cpp
354355
layout/qgslayoutitemregistry.cpp
355356
layout/qgslayoutmeasurement.cpp
@@ -671,6 +672,7 @@ SET(QGIS_CORE_MOC_HDRS
671672
gps/qgsgpsdconnection.h
672673

673674
layout/qgslayout.h
675+
layout/qgslayoutcontext.h
674676
layout/qgslayoutitem.h
675677
layout/qgslayoutitemregistry.h
676678
layout/qgslayoutobject.h

src/core/layout/qgslayoutcontext.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/***************************************************************************
2+
qgslayoutcontext.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 "qgslayoutcontext.h"
18+
#include "qgsfeature.h"
19+
20+
21+
QgsLayoutContext::QgsLayoutContext()
22+
: mFlags( FlagAntialiasing | FlagUseAdvancedEffects )
23+
{}
24+
25+
void QgsLayoutContext::setFlags( const QgsLayoutContext::Flags flags )
26+
{
27+
mFlags = flags;
28+
}
29+
30+
void QgsLayoutContext::setFlag( const QgsLayoutContext::Flag flag, const bool on )
31+
{
32+
if ( on )
33+
mFlags |= flag;
34+
else
35+
mFlags &= ~flag;
36+
}
37+
38+
QgsLayoutContext::Flags QgsLayoutContext::flags() const
39+
{
40+
return mFlags;
41+
}
42+
43+
bool QgsLayoutContext::testFlag( const QgsLayoutContext::Flag flag ) const
44+
{
45+
return mFlags.testFlag( flag );
46+
}
47+
48+
QgsVectorLayer *QgsLayoutContext::layer() const
49+
{
50+
return mLayer;
51+
}
52+
53+
void QgsLayoutContext::setLayer( QgsVectorLayer *layer )
54+
{
55+
mLayer = layer;
56+
}

src/core/layout/qgslayoutcontext.h

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/***************************************************************************
2+
qgslayoutcontext.h
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+
#ifndef QGSLAYOUTCONTEXT_H
17+
#define QGSLAYOUTCONTEXT_H
18+
19+
#include "qgis_core.h"
20+
#include "qgsfeature.h"
21+
#include "qgsvectorlayer.h"
22+
#include <QtGlobal>
23+
24+
class QgsFeature;
25+
class QgsVectorLayer;
26+
27+
/**
28+
* \ingroup Layout
29+
* \class QgsLayoutContext
30+
* \brief Stores information relating to the current context and rendering settings for a layout.
31+
* \since QGIS 3.0
32+
*/
33+
class CORE_EXPORT QgsLayoutContext
34+
{
35+
36+
public:
37+
38+
//! Flags for controlling how a layout is rendered
39+
enum Flag
40+
{
41+
FlagDebug = 1 << 1, //!< Debug/testing mode, items are drawn as solid rectangles.
42+
FlagOutlineOnly = 1 << 2, //!< Render items as outlines only.
43+
FlagAntialiasing = 1 << 3, //!< Use antialiasing when drawing items.
44+
FlagUseAdvancedEffects = 1 << 4, //!< Enable advanced effects such as blend modes.
45+
};
46+
Q_DECLARE_FLAGS( Flags, Flag )
47+
48+
QgsLayoutContext();
49+
50+
/**
51+
* Sets the combination of \a flags that will be used for rendering the layout.
52+
* \see setFlag()
53+
* \see flags()
54+
* \see testFlag()
55+
*/
56+
void setFlags( const QgsLayoutContext::Flags flags );
57+
58+
/**
59+
* Enables or disables a particular rendering \a flag for the layout. Other existing
60+
* flags are not affected.
61+
* \see setFlags()
62+
* \see flags()
63+
* \see testFlag()
64+
*/
65+
void setFlag( const QgsLayoutContext::Flag flag, const bool on = true );
66+
67+
/**
68+
* Returns the current combination of flags used for rendering the layout.
69+
* \see setFlags()
70+
* \see setFlag()
71+
* \see testFlag()
72+
*/
73+
QgsLayoutContext::Flags flags() const;
74+
75+
/**
76+
* Check whether a particular rendering \a flag is enabled for the layout.
77+
* \see setFlags()
78+
* \see setFlag()
79+
* \see flags()
80+
*/
81+
bool testFlag( const Flag flag ) const;
82+
83+
/**
84+
* Sets the current \a feature for evaluating the layout. This feature may
85+
* be used for altering an item's content and appearance for a report
86+
* or atlas layout.
87+
* \see feature()
88+
*/
89+
void setFeature( const QgsFeature &feature ) { mFeature = feature; }
90+
91+
/**
92+
* Returns the current feature for evaluating the layout. This feature may
93+
* be used for altering an item's content and appearance for a report
94+
* or atlas layout.
95+
* \see setFeature()
96+
*/
97+
QgsFeature feature() const { return mFeature; }
98+
99+
/**
100+
* Returns the vector layer associated with the layout's context.
101+
* \see setLayer()
102+
*/
103+
QgsVectorLayer *layer() const;
104+
105+
/**
106+
* Sets the vector \a layer associated with the layout's context.
107+
* \see layer()
108+
*/
109+
void setLayer( QgsVectorLayer *layer );
110+
111+
private:
112+
113+
Flags mFlags = 0;
114+
115+
QgsFeature mFeature;
116+
QPointer< QgsVectorLayer > mLayer;
117+
118+
};
119+
120+
#endif //QGSLAYOUTCONTEXT_H
121+
122+
123+

tests/src/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ SET(TESTS
127127
testqgslabelingengine.cpp
128128
testqgslayertree.cpp
129129
testqgslayout.cpp
130+
testqgslayoutcontext.cpp
130131
testqgslayoutitem.cpp
131132
testqgslayoutobject.cpp
132133
testqgslayoutunits.cpp

0 commit comments

Comments
 (0)