Skip to content

Commit 6a54130

Browse files
committed
[layout] Add layout measurement and size classes
These classes are used for storing measurements for a layout (QgsLayoutMeasurement), sizes for a layout (QgsLayoutSize) and points in a layout (QgsLayoutPoint) They support storing a measurement unit alongside a measurement length/size. A new class QgsLayoutMeasurementConverter handles conversion between different units, including converting to and from pixels via a specified DPI property.
1 parent 81855a7 commit 6a54130

22 files changed

Lines changed: 2621 additions & 0 deletions

‎doc/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ IF(WITH_APIDOC)
6363
${CMAKE_SOURCE_DIR}/src/core/geometry
6464
${CMAKE_SOURCE_DIR}/src/core/gps
6565
${CMAKE_SOURCE_DIR}/src/core/layertree
66+
${CMAKE_SOURCE_DIR}/src/core/layout
6667
${CMAKE_SOURCE_DIR}/src/core/metadata
6768
${CMAKE_SOURCE_DIR}/src/core/pal
6869
${CMAKE_SOURCE_DIR}/src/core/processing

‎python/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ INCLUDE_DIRECTORIES(
106106
${CMAKE_SOURCE_DIR}/src/core/geometry
107107
${CMAKE_SOURCE_DIR}/src/core/gps
108108
${CMAKE_SOURCE_DIR}/src/core/layertree
109+
${CMAKE_SOURCE_DIR}/src/core/layout
109110
${CMAKE_SOURCE_DIR}/src/core/metadata
110111
${CMAKE_SOURCE_DIR}/src/core/processing
111112
${CMAKE_SOURCE_DIR}/src/core/providers

‎python/core/core.sip‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ done:
369369
%Include layertree/qgslayertreeregistrybridge.sip
370370
%Include layertree/qgslayertreeutils.sip
371371

372+
%Include layout/qgslayoutmeasurement.sip
373+
%Include layout/qgslayoutmeasurementconverter.sip
374+
%Include layout/qgslayoutpoint.sip
375+
%Include layout/qgslayoutsize.sip
376+
372377
%Include metadata/qgslayermetadata.sip
373378
%Include metadata/qgslayermetadatavalidator.sip
374379

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutmeasurement.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsLayoutMeasurement
14+
{
15+
%Docstring
16+
This class provides a method of storing measurements for use in QGIS layouts
17+
using a variety of different measurement units.
18+
.. seealso:: QgsLayoutMeasurementConverter
19+
.. versionadded:: 3.0
20+
%End
21+
22+
%TypeHeaderCode
23+
#include "qgslayoutmeasurement.h"
24+
%End
25+
public:
26+
27+
explicit QgsLayoutMeasurement( const double length, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
28+
%Docstring
29+
Constructor for QgsLayoutMeasurement.
30+
\param length measurement length
31+
\param units measurement units
32+
%End
33+
34+
~QgsLayoutMeasurement();
35+
36+
double length() const;
37+
%Docstring
38+
Returns the length of the measurement.
39+
.. seealso:: setLength()
40+
:rtype: float
41+
%End
42+
43+
void setLength( const double length );
44+
%Docstring
45+
Sets the ``length`` of the measurement.
46+
.. seealso:: length()
47+
%End
48+
49+
QgsUnitTypes::LayoutUnit units() const;
50+
%Docstring
51+
Returns the units for the measurement.
52+
.. seealso:: setUnits()
53+
:rtype: QgsUnitTypes.LayoutUnit
54+
%End
55+
56+
void setUnits( const QgsUnitTypes::LayoutUnit units );
57+
%Docstring
58+
Sets the ``units`` for the measurement. Does not alter the stored length,
59+
ie. no length conversion is done.
60+
.. seealso:: units()
61+
%End
62+
63+
QString encodeMeasurement() const;
64+
%Docstring
65+
Encodes the layout measurement to a string
66+
.. seealso:: decodeMeasurement()
67+
:rtype: str
68+
%End
69+
70+
static QgsLayoutMeasurement decodeMeasurement( const QString &string );
71+
%Docstring
72+
Decodes a measurement from a ``string``.
73+
.. seealso:: encodeMeasurement()
74+
:rtype: QgsLayoutMeasurement
75+
%End
76+
77+
bool operator==( const QgsLayoutMeasurement &other ) const;
78+
bool operator!=( const QgsLayoutMeasurement &other ) const;
79+
%Docstring
80+
:rtype: bool
81+
%End
82+
QgsLayoutMeasurement operator+( const double v ) const;
83+
%Docstring
84+
:rtype: QgsLayoutMeasurement
85+
%End
86+
QgsLayoutMeasurement operator+=( const double v );
87+
%Docstring
88+
:rtype: QgsLayoutMeasurement
89+
%End
90+
QgsLayoutMeasurement operator-( const double v ) const;
91+
%Docstring
92+
:rtype: QgsLayoutMeasurement
93+
%End
94+
QgsLayoutMeasurement operator-=( const double v );
95+
%Docstring
96+
:rtype: QgsLayoutMeasurement
97+
%End
98+
QgsLayoutMeasurement operator*( const double v ) const;
99+
%Docstring
100+
:rtype: QgsLayoutMeasurement
101+
%End
102+
QgsLayoutMeasurement operator*=( const double v );
103+
%Docstring
104+
:rtype: QgsLayoutMeasurement
105+
%End
106+
QgsLayoutMeasurement operator/( const double v ) const;
107+
%Docstring
108+
:rtype: QgsLayoutMeasurement
109+
%End
110+
QgsLayoutMeasurement operator/=( const double v );
111+
%Docstring
112+
:rtype: QgsLayoutMeasurement
113+
%End
114+
115+
};
116+
117+
/************************************************************************
118+
* This file has been generated automatically from *
119+
* *
120+
* src/core/layout/qgslayoutmeasurement.h *
121+
* *
122+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
123+
************************************************************************/
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutmeasurementconverter.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsLayoutMeasurementConverter
14+
{
15+
%Docstring
16+
This class provides a method of converting QgsLayoutMeasurements from
17+
one unit to another. Conversion to or from pixel units utilizes a specified
18+
dots per inch (DPI) property for the converter. Converters default to using
19+
300 DPI.
20+
.. seealso:: QgsLayoutMeasurement
21+
.. versionadded:: 3.0
22+
%End
23+
24+
%TypeHeaderCode
25+
#include "qgslayoutmeasurementconverter.h"
26+
%End
27+
public:
28+
29+
QgsLayoutMeasurementConverter();
30+
31+
~QgsLayoutMeasurementConverter();
32+
33+
void setDpi( const double dpi );
34+
%Docstring
35+
Sets the dots per inch (``dpi``) for the measurement converter. This is used
36+
when converting measurements to and from pixels.
37+
.. seealso:: dpi()
38+
%End
39+
40+
double dpi() const;
41+
%Docstring
42+
Returns the Dots per inch (DPI) of the measurement converter. This is used
43+
when converting measurements to and from pixels.
44+
.. seealso:: setDpi()
45+
:rtype: float
46+
%End
47+
48+
QgsLayoutMeasurement convert( const QgsLayoutMeasurement &measurement, const QgsUnitTypes::LayoutUnit targetUnits ) const;
49+
%Docstring
50+
Converts a measurement from one unit to another.
51+
\param measurement measurement to convert
52+
\param targetUnits units to convert measurement into
53+
:return: measurement converted to target units
54+
:rtype: QgsLayoutMeasurement
55+
%End
56+
57+
QgsLayoutSize convert( const QgsLayoutSize &size, const QgsUnitTypes::LayoutUnit targetUnits ) const;
58+
%Docstring
59+
Converts a layout size from one unit to another.
60+
\param size layout size to convert
61+
\param targetUnits units to convert size into
62+
:return: size converted to target units
63+
:rtype: QgsLayoutSize
64+
%End
65+
66+
QgsLayoutPoint convert( const QgsLayoutPoint &point, const QgsUnitTypes::LayoutUnit targetUnits ) const;
67+
%Docstring
68+
Converts a layout point from one unit to another.
69+
\param point layout point to convert
70+
\param targetUnits units to convert point into
71+
:return: point converted to target units
72+
:rtype: QgsLayoutPoint
73+
%End
74+
75+
};
76+
77+
/************************************************************************
78+
* This file has been generated automatically from *
79+
* *
80+
* src/core/layout/qgslayoutmeasurementconverter.h *
81+
* *
82+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
83+
************************************************************************/
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/layout/qgslayoutpoint.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsLayoutPoint
13+
{
14+
%Docstring
15+
This class provides a method of storing points, consisting of an x and y coordinate,
16+
for use in QGIS layouts. Measurement units are stored alongside the position.
17+
18+
.. seealso:: QgsLayoutMeasurementConverter
19+
.. versionadded:: 3.0
20+
.. note::
21+
22+
This class does not inherit from QPointF since QPointF includes methods which should not apply
23+
to positions with with units. For instance, the + and - operators would mislead users of this class
24+
to believe that addition of two QgsLayoutPoints with different unit types would automatically convert
25+
units. Instead, all unit conversion must be handled by a QgsLayoutMeasurementConverter so that
26+
conversion between paper and screen units can be correctly performed.
27+
%End
28+
29+
%TypeHeaderCode
30+
#include "qgslayoutpoint.h"
31+
%End
32+
public:
33+
34+
QgsLayoutPoint( const double x, const double y, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
35+
%Docstring
36+
Constructor for QgsLayoutPoint.
37+
\param x x coordinate
38+
\param x y coordinate
39+
\param units units for x and y
40+
%End
41+
42+
explicit QgsLayoutPoint( const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
43+
%Docstring
44+
Constructor for an empty point, where both x and y are set to 0.
45+
\param units units for measurement
46+
%End
47+
48+
~QgsLayoutPoint();
49+
50+
void setPoint( const double x, const double y );
51+
%Docstring
52+
Sets new x and y coordinates for the point.
53+
.. seealso:: setX()
54+
.. seealso:: setY()
55+
.. seealso:: setUnits()
56+
%End
57+
58+
double x() const;
59+
%Docstring
60+
Returns x coordinate of point.
61+
.. seealso:: setX()
62+
.. seealso:: y()
63+
:rtype: float
64+
%End
65+
66+
void setX( const double x );
67+
%Docstring
68+
Sets the x coordinate of point.
69+
.. seealso:: x()
70+
.. seealso:: setY()
71+
%End
72+
73+
double y() const;
74+
%Docstring
75+
Returns y coordinate of point.
76+
.. seealso:: setY()
77+
.. seealso:: x()
78+
:rtype: float
79+
%End
80+
81+
void setY( const double y );
82+
%Docstring
83+
Sets y coordinate of point.
84+
.. seealso:: y()
85+
.. seealso:: setX()
86+
%End
87+
88+
QgsUnitTypes::LayoutUnit units() const;
89+
%Docstring
90+
Returns the units for the point.
91+
.. seealso:: setUnits()
92+
:rtype: QgsUnitTypes.LayoutUnit
93+
%End
94+
95+
void setUnits( const QgsUnitTypes::LayoutUnit units );
96+
%Docstring
97+
Sets the ``units`` for the point. Does not alter the stored coordinates,
98+
ie. no conversion is done.
99+
.. seealso:: units()
100+
%End
101+
102+
bool isNull() const;
103+
%Docstring
104+
Tests whether the position is null, ie both its x and y coordinates
105+
are zero.
106+
:return: true if point is null
107+
:rtype: bool
108+
%End
109+
110+
QPointF toQPointF() const;
111+
%Docstring
112+
Converts the layout point to a QPointF. The unit information is discarded
113+
during this operation.
114+
:return: QPointF with same x and y coordinates as layout point
115+
:rtype: QPointF
116+
%End
117+
118+
QString encodePoint() const;
119+
%Docstring
120+
Encodes the layout point to a string
121+
.. seealso:: decodePoint()
122+
:rtype: str
123+
%End
124+
125+
static QgsLayoutPoint decodePoint( const QString &string );
126+
%Docstring
127+
Decodes a point from a ``string``.
128+
.. seealso:: encodePoint()
129+
:rtype: QgsLayoutPoint
130+
%End
131+
132+
bool operator==( const QgsLayoutPoint &other ) const;
133+
bool operator!=( const QgsLayoutPoint &other ) const;
134+
%Docstring
135+
:rtype: bool
136+
%End
137+
QgsLayoutPoint operator*( const double v ) const;
138+
%Docstring
139+
:rtype: QgsLayoutPoint
140+
%End
141+
QgsLayoutPoint operator*=( const double v );
142+
%Docstring
143+
:rtype: QgsLayoutPoint
144+
%End
145+
QgsLayoutPoint operator/( const double v ) const;
146+
%Docstring
147+
:rtype: QgsLayoutPoint
148+
%End
149+
QgsLayoutPoint operator/=( const double v );
150+
%Docstring
151+
:rtype: QgsLayoutPoint
152+
%End
153+
154+
};
155+
156+
/************************************************************************
157+
* This file has been generated automatically from *
158+
* *
159+
* src/core/layout/qgslayoutpoint.h *
160+
* *
161+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
162+
************************************************************************/

0 commit comments

Comments
 (0)