Skip to content

Commit

Permalink
Add methods to construct layout size/point from QSizeF/QPointF
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 18, 2017
1 parent d14f3b9 commit 19a7863
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python/core/layout/qgslayoutpoint.sip
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions python/core/layout/qgslayoutsize.sip
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/core/layout/qgslayoutpoint.cpp
Expand Up @@ -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 )
{
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutpoint.h
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/core/layout/qgslayoutsize.cpp
Expand Up @@ -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 )
{
Expand Down
5 changes: 5 additions & 0 deletions src/core/layout/qgslayoutsize.h
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions tests/src/core/testqgslayoutunits.cpp
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 19a7863

Please sign in to comment.