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

This commit is contained in:
Nyall Dawson 2017-07-18 11:43:41 +10:00
parent d14f3b9c13
commit 19a7863ea4
7 changed files with 47 additions and 0 deletions

View File

@ -36,6 +36,11 @@ class QgsLayoutPoint
Constructor for QgsLayoutPoint. Constructor for QgsLayoutPoint.
%End %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 ); explicit QgsLayoutPoint( const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
%Docstring %Docstring
Constructor for an empty point, where both x and y are set to 0. Constructor for an empty point, where both x and y are set to 0.

View File

@ -40,6 +40,11 @@ class QgsLayoutSize
\param units units for width and height \param units units for width and height
%End %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 ); explicit QgsLayoutSize( const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters );
%Docstring %Docstring
Constructor for an empty layout size Constructor for an empty layout size

View File

@ -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 ) QgsLayoutPoint::QgsLayoutPoint( const QgsUnitTypes::LayoutUnit units )
: mUnits( units ) : mUnits( units )
{ {

View File

@ -45,6 +45,11 @@ class CORE_EXPORT QgsLayoutPoint
*/ */
QgsLayoutPoint( const double x, const double y, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters ); 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. * Constructor for an empty point, where both x and y are set to 0.
* \param units units for measurement * \param units units for measurement

View File

@ -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 ) QgsLayoutSize::QgsLayoutSize( const QgsUnitTypes::LayoutUnit units )
: mUnits( units ) : mUnits( units )
{ {

View File

@ -49,6 +49,11 @@ class CORE_EXPORT QgsLayoutSize
*/ */
QgsLayoutSize( const double width, const double height, const QgsUnitTypes::LayoutUnit units = QgsUnitTypes::LayoutMillimeters ); 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 * Constructor for an empty layout size
* \param units units for measurement * \param units units for measurement

View File

@ -259,6 +259,12 @@ void TestQgsLayoutUnits::createSize()
QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels ); QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels );
QCOMPARE( empty.width(), 0.0 ); QCOMPARE( empty.width(), 0.0 );
QCOMPARE( empty.height(), 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() void TestQgsLayoutUnits::sizeGettersSetters()
@ -393,6 +399,12 @@ void TestQgsLayoutUnits::createPoint()
QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels ); QCOMPARE( empty.units(), QgsUnitTypes::LayoutPixels );
QCOMPARE( empty.x(), 0.0 ); QCOMPARE( empty.x(), 0.0 );
QCOMPARE( empty.y(), 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() void TestQgsLayoutUnits::pointGettersSetters()