Skip to content
Permalink
Browse files

Add methods to construct layout size/point from QSizeF/QPointF

  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent d14f3b9 commit 19a7863ea49c8076d2df94d88f138898e7ad25a2
@@ -36,6 +36,11 @@ class QgsLayoutPoint
Constructor for QgsLayoutPoint.
%End

explicit QgsLayoutPoint( const QPointF point, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
%Docstring
Constructor for QgsLayoutPoint.
%End

explicit QgsLayoutPoint( const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
%Docstring
Constructor for an empty point, where both x and y are set to 0.
@@ -40,6 +40,11 @@ class QgsLayoutSize
\param units units for width and height
%End

explicit QgsLayoutSize( const QSizeF size, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
%Docstring
Constructor for QgsLayoutSize.
%End

explicit QgsLayoutSize( const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
%Docstring
Constructor for an empty layout size
@@ -28,6 +28,14 @@ QgsLayoutPoint::QgsLayoutPoint( const double x, const double y, const QgsUnitTyp

}

QgsLayoutPoint::QgsLayoutPoint( const QPointF point, const QgsUnitTypes::LayoutUnit units )
: mX( point.x() )
, mY( point.y() )
, mUnits( units )
{

}

QgsLayoutPoint::QgsLayoutPoint( const QgsUnitTypes::LayoutUnit units )
: mUnits( units )
{
@@ -45,6 +45,11 @@ class CORE_EXPORT QgsLayoutPoint
*/
QgsLayoutPoint( const double x, const double y, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );

/**
* Constructor for QgsLayoutPoint.
*/
explicit QgsLayoutPoint( const QPointF point, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );

/**
* Constructor for an empty point, where both x and y are set to 0.
* \param units units for measurement
@@ -26,6 +26,13 @@ QgsLayoutSize::QgsLayoutSize( const double width, const double height, const Qgs
{
}

QgsLayoutSize::QgsLayoutSize( const QSizeF size, const QgsUnitTypes::LayoutUnit units )
: mWidth( size.width() )
, mHeight( size.height() )
, mUnits( units )
{
}

QgsLayoutSize::QgsLayoutSize( const QgsUnitTypes::LayoutUnit units )
: mUnits( units )
{
@@ -49,6 +49,11 @@ class CORE_EXPORT QgsLayoutSize
*/
QgsLayoutSize( const double width, const double height, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );

/**
* Constructor for QgsLayoutSize.
*/
explicit QgsLayoutSize( const QSizeF size, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );

/**
* Constructor for an empty layout size
* \param units units for measurement
@@ -259,6 +259,12 @@ void TestQgsLayoutUnits::createSize()
QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels );
QCOMPARE( empty.width(), 0.0 );
QCOMPARE( empty.height(), 0.0 );

//test constructing from QSizeF
QgsLayoutSize fromQSizeF( QSizeF( 17.0, 18.0 ), QgsUnitTypes::LayoutInches );
QCOMPARE( fromQSizeF.units(), QgsUnitTypes::LayoutInches );
QCOMPARE( fromQSizeF.width(), 17.0 );
QCOMPARE( fromQSizeF.height(), 18.0 );
}

void TestQgsLayoutUnits::sizeGettersSetters()
@@ -393,6 +399,12 @@ void TestQgsLayoutUnits::createPoint()
QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels );
QCOMPARE( empty.x(), 0.0 );
QCOMPARE( empty.y(), 0.0 );

//test constructing from QPointF
QgsLayoutPoint fromQPointF( QPointF( 17.0, 18.0 ), QgsUnitTypes::LayoutInches );
QCOMPARE( fromQPointF.units(), QgsUnitTypes::LayoutInches );
QCOMPARE( fromQPointF.x(), 17.0 );
QCOMPARE( fromQPointF.y(), 18.0 );
}

void TestQgsLayoutUnits::pointGettersSetters()

0 comments on commit 19a7863

Please sign in to comment.
You can’t perform that action at this time.