Skip to content

Commit 19a7863

Browse files
committed
Add methods to construct layout size/point from QSizeF/QPointF
1 parent d14f3b9 commit 19a7863

File tree

7 files changed

+47
-0
lines changed

7 files changed

+47
-0
lines changed

python/core/layout/qgslayoutpoint.sip

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class QgsLayoutPoint
3636
Constructor for QgsLayoutPoint.
3737
%End
3838

39+
explicit QgsLayoutPoint( const QPointF point, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
40+
%Docstring
41+
Constructor for QgsLayoutPoint.
42+
%End
43+
3944
explicit QgsLayoutPoint( const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
4045
%Docstring
4146
Constructor for an empty point, where both x and y are set to 0.

python/core/layout/qgslayoutsize.sip

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ class QgsLayoutSize
4040
\param units units for width and height
4141
%End
4242

43+
explicit QgsLayoutSize( const QSizeF size, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
44+
%Docstring
45+
Constructor for QgsLayoutSize.
46+
%End
47+
4348
explicit QgsLayoutSize( const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
4449
%Docstring
4550
Constructor for an empty layout size

src/core/layout/qgslayoutpoint.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ QgsLayoutPoint::QgsLayoutPoint( const double x, const double y, const QgsUnitTyp
2828

2929
}
3030

31+
QgsLayoutPoint::QgsLayoutPoint( const QPointF point, const QgsUnitTypes::LayoutUnit units )
32+
: mX( point.x() )
33+
, mY( point.y() )
34+
, mUnits( units )
35+
{
36+
37+
}
38+
3139
QgsLayoutPoint::QgsLayoutPoint( const QgsUnitTypes::LayoutUnit units )
3240
: mUnits( units )
3341
{

src/core/layout/qgslayoutpoint.h

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ class CORE_EXPORT QgsLayoutPoint
4545
*/
4646
QgsLayoutPoint( const double x, const double y, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
4747

48+
/**
49+
* Constructor for QgsLayoutPoint.
50+
*/
51+
explicit QgsLayoutPoint( const QPointF point, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
52+
4853
/**
4954
* Constructor for an empty point, where both x and y are set to 0.
5055
* \param units units for measurement

src/core/layout/qgslayoutsize.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ QgsLayoutSize::QgsLayoutSize( const double width, const double height, const Qgs
2626
{
2727
}
2828

29+
QgsLayoutSize::QgsLayoutSize( const QSizeF size, const QgsUnitTypes::LayoutUnit units )
30+
: mWidth( size.width() )
31+
, mHeight( size.height() )
32+
, mUnits( units )
33+
{
34+
}
35+
2936
QgsLayoutSize::QgsLayoutSize( const QgsUnitTypes::LayoutUnit units )
3037
: mUnits( units )
3138
{

src/core/layout/qgslayoutsize.h

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ class CORE_EXPORT QgsLayoutSize
4949
*/
5050
QgsLayoutSize( const double width, const double height, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
5151

52+
/**
53+
* Constructor for QgsLayoutSize.
54+
*/
55+
explicit QgsLayoutSize( const QSizeF size, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
56+
5257
/**
5358
* Constructor for an empty layout size
5459
* \param units units for measurement

tests/src/core/testqgslayoutunits.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,12 @@ void TestQgsLayoutUnits::createSize()
259259
QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels );
260260
QCOMPARE( empty.width(), 0.0 );
261261
QCOMPARE( empty.height(), 0.0 );
262+
263+
//test constructing from QSizeF
264+
QgsLayoutSize fromQSizeF( QSizeF( 17.0, 18.0 ), QgsUnitTypes::LayoutInches );
265+
QCOMPARE( fromQSizeF.units(), QgsUnitTypes::LayoutInches );
266+
QCOMPARE( fromQSizeF.width(), 17.0 );
267+
QCOMPARE( fromQSizeF.height(), 18.0 );
262268
}
263269

264270
void TestQgsLayoutUnits::sizeGettersSetters()
@@ -393,6 +399,12 @@ void TestQgsLayoutUnits::createPoint()
393399
QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels );
394400
QCOMPARE( empty.x(), 0.0 );
395401
QCOMPARE( empty.y(), 0.0 );
402+
403+
//test constructing from QPointF
404+
QgsLayoutPoint fromQPointF( QPointF( 17.0, 18.0 ), QgsUnitTypes::LayoutInches );
405+
QCOMPARE( fromQPointF.units(), QgsUnitTypes::LayoutInches );
406+
QCOMPARE( fromQPointF.x(), 17.0 );
407+
QCOMPARE( fromQPointF.y(), 18.0 );
396408
}
397409

398410
void TestQgsLayoutUnits::pointGettersSetters()

0 commit comments

Comments
 (0)