Skip to content

Commit faa4a09

Browse files
authored
Merge pull request #4877 from nyalldawson/layout_next
Layouts, chapter II
2 parents d570b43 + 54bf013 commit faa4a09

70 files changed

Lines changed: 6034 additions & 58 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

python/core/core_auto.sip

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@
153153
%Include composer/qgscomposermultiframecommand.sip
154154
%Include composer/qgscomposertexttable.sip
155155
%Include composer/qgspaperitem.sip
156-
%Include layout/qgslayout.sip
156+
%Include layout/qgslayoutcontext.sip
157157
%Include layout/qgslayoutmeasurement.sip
158158
%Include layout/qgslayoutmeasurementconverter.sip
159159
%Include layout/qgspagesizeregistry.sip
160160
%Include layout/qgslayoutpoint.sip
161161
%Include layout/qgslayoutsize.sip
162+
%Include layout/qgslayoututils.sip
162163
%Include metadata/qgslayermetadata.sip
163164
%Include metadata/qgslayermetadatavalidator.sip
164165
%Include processing/qgsprocessing.sip
@@ -378,8 +379,11 @@
378379
%Include gps/qgsgpsdetector.sip
379380
%Include gps/qgsnmeaconnection.sip
380381
%Include gps/qgsgpsdconnection.sip
382+
%Include layout/qgslayout.sip
381383
%Include layout/qgslayoutitem.sip
384+
%Include layout/qgslayoutitemmap.sip
382385
%Include layout/qgslayoutitemregistry.sip
386+
%Include layout/qgslayoutitemshape.sip
383387
%Include layout/qgslayoutobject.sip
384388
%Include symbology-ng/qgscptcityarchive.sip
385389
%Include symbology-ng/qgssvgcache.sip

python/core/layout/qgslayout.sip

Lines changed: 166 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
************************************************************************/
88

99

10-
class QgsLayout : QGraphicsScene
10+
11+
class QgsLayout : QGraphicsScene, QgsExpressionContextGenerator
1112
{
1213
%Docstring
1314
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
@@ -24,7 +25,170 @@ class QgsLayout : QGraphicsScene
2425
ZMapTool,
2526
};
2627

27-
QgsLayout();
28+
QgsLayout( QgsProject *project );
29+
%Docstring
30+
Construct a new layout linked to the specified ``project``.
31+
%End
32+
33+
QgsProject *project() const;
34+
%Docstring
35+
The project associated with the layout. Used to get access to layers, map themes,
36+
relations and various other bits. It is never null.
37+
:rtype: QgsProject
38+
%End
39+
40+
QString name() const;
41+
%Docstring
42+
Returns the layout's name.
43+
.. seealso:: setName()
44+
:rtype: str
45+
%End
46+
47+
void setName( const QString &name );
48+
%Docstring
49+
Sets the layout's name.
50+
.. seealso:: name()
51+
%End
52+
53+
void setUnits( QgsUnitTypes::LayoutUnit units );
54+
%Docstring
55+
Sets the native measurement ``units`` for the layout. These also form the default unit
56+
for measurements for the layout.
57+
.. seealso:: units()
58+
.. seealso:: convertToLayoutUnits()
59+
%End
60+
61+
QgsUnitTypes::LayoutUnit units() const;
62+
%Docstring
63+
Returns the native units for the layout.
64+
.. seealso:: setUnits()
65+
.. seealso:: convertToLayoutUnits()
66+
:rtype: QgsUnitTypes.LayoutUnit
67+
%End
68+
69+
double convertToLayoutUnits( const QgsLayoutMeasurement &measurement ) const;
70+
%Docstring
71+
Converts a measurement into the layout's native units.
72+
:return: length of measurement in layout units
73+
.. seealso:: convertFromLayoutUnits()
74+
.. seealso:: units()
75+
:rtype: float
76+
%End
77+
78+
QSizeF convertToLayoutUnits( const QgsLayoutSize &size ) const;
79+
%Docstring
80+
Converts a size into the layout's native units.
81+
:return: size of measurement in layout units
82+
.. seealso:: convertFromLayoutUnits()
83+
.. seealso:: units()
84+
:rtype: QSizeF
85+
%End
86+
87+
QPointF convertToLayoutUnits( const QgsLayoutPoint &point ) const;
88+
%Docstring
89+
Converts a ``point`` into the layout's native units.
90+
:return: point in layout units
91+
.. seealso:: convertFromLayoutUnits()
92+
.. seealso:: units()
93+
:rtype: QPointF
94+
%End
95+
96+
QgsLayoutMeasurement convertFromLayoutUnits( const double length, const QgsUnitTypes::LayoutUnit unit ) const;
97+
%Docstring
98+
Converts a ``length`` measurement from the layout's native units to a specified target ``unit``.
99+
:return: length of measurement in specified units
100+
.. seealso:: convertToLayoutUnits()
101+
.. seealso:: units()
102+
:rtype: QgsLayoutMeasurement
103+
%End
104+
105+
QgsLayoutSize convertFromLayoutUnits( const QSizeF &size, const QgsUnitTypes::LayoutUnit unit ) const;
106+
%Docstring
107+
Converts a ``size`` from the layout's native units to a specified target ``unit``.
108+
:return: size of measurement in specified units
109+
.. seealso:: convertToLayoutUnits()
110+
.. seealso:: units()
111+
:rtype: QgsLayoutSize
112+
%End
113+
114+
QgsLayoutPoint convertFromLayoutUnits( const QPointF &point, const QgsUnitTypes::LayoutUnit unit ) const;
115+
%Docstring
116+
Converts a ``point`` from the layout's native units to a specified target ``unit``.
117+
:return: point in specified units
118+
.. seealso:: convertToLayoutUnits()
119+
.. seealso:: units()
120+
:rtype: QgsLayoutPoint
121+
%End
122+
123+
QgsLayoutContext &context();
124+
%Docstring
125+
Returns a reference to the layout's context, which stores information relating to the
126+
current context and rendering settings for the layout.
127+
:rtype: QgsLayoutContext
128+
%End
129+
130+
131+
virtual QgsExpressionContext createExpressionContext() const;
132+
133+
%Docstring
134+
Creates an expression context relating to the layout's current state. The context includes
135+
scopes for global, project, layout and layout context properties.
136+
:rtype: QgsExpressionContext
137+
%End
138+
139+
void setCustomProperty( const QString &key, const QVariant &value );
140+
%Docstring
141+
Set a custom property for the layout.
142+
\param key property key. If a property with the same key already exists it will be overwritten.
143+
\param value property value
144+
.. seealso:: customProperty()
145+
.. seealso:: removeCustomProperty()
146+
.. seealso:: customProperties()
147+
%End
148+
149+
QVariant customProperty( const QString &key, const QVariant &defaultValue = QVariant() ) const;
150+
%Docstring
151+
Read a custom property from the layout.
152+
\param key property key
153+
\param defaultValue default value to return if property with matching key does not exist
154+
:return: value of matching property
155+
.. seealso:: setCustomProperty()
156+
.. seealso:: removeCustomProperty()
157+
.. seealso:: customProperties()
158+
:rtype: QVariant
159+
%End
160+
161+
void removeCustomProperty( const QString &key );
162+
%Docstring
163+
Remove a custom property from the layout.
164+
\param key property key
165+
.. seealso:: setCustomProperty()
166+
.. seealso:: customProperty()
167+
.. seealso:: customProperties()
168+
%End
169+
170+
QStringList customProperties() const;
171+
%Docstring
172+
Return list of keys stored in custom properties for the layout.
173+
.. seealso:: setCustomProperty()
174+
.. seealso:: customProperty()
175+
.. seealso:: removeCustomProperty()
176+
:rtype: list of str
177+
%End
178+
179+
QgsLayoutItemMap *referenceMap() const;
180+
%Docstring
181+
:rtype: QgsLayoutItemMap
182+
%End
183+
184+
void setReferenceMap( QgsLayoutItemMap *map );
185+
186+
signals:
187+
188+
void variablesChanged();
189+
%Docstring
190+
Emitted whenever the expression variables stored in the layout have been changed.
191+
%End
28192

29193
};
30194

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
void setDpi( double dpi );
101+
%Docstring
102+
Sets the ``dpi`` for outputting the layout. This also sets the
103+
corresponding DPI for the context's measurementConverter().
104+
.. seealso:: dpi()
105+
%End
106+
107+
double dpi() const;
108+
%Docstring
109+
Returns the ``dpi`` for outputting the layout.
110+
.. seealso:: setDpi()
111+
:rtype: float
112+
%End
113+
114+
115+
QgsLayoutMeasurementConverter &measurementConverter();
116+
%Docstring
117+
Returns the layout measurement converter to be used in the layout. This converter is used
118+
for translating between other measurement units and the layout's native unit.
119+
:rtype: QgsLayoutMeasurementConverter
120+
%End
121+
122+
};
123+
124+
125+
126+
127+
/************************************************************************
128+
* This file has been generated automatically from *
129+
* *
130+
* src/core/layout/qgslayoutcontext.h *
131+
* *
132+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
133+
************************************************************************/

0 commit comments

Comments
 (0)