1
0
mirror of https://github.com/qgis/QGIS.git synced 2025-04-18 00:03:05 -04:00

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

@ -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()