Skip to content
Permalink
Browse files

Make matching to known page sizes less fussy

Since all gui widgets for page sizes limit to 2 decimal places,
we need to allow this much tolerance when checking the setting
against known page sizes.
  • Loading branch information
nyalldawson committed Jul 25, 2017
1 parent 9e2673a commit e8514be010a6dc91a19203081145452641d12a7c
Showing with 4 additions and 3 deletions.
  1. +2 −2 src/core/layout/qgspagesizeregistry.cpp
  2. +2 −1 tests/src/core/testqgspagesizeregistry.cpp
@@ -97,8 +97,8 @@ QString QgsPageSizeRegistry::find( const QgsLayoutSize &size ) const
QgsLayoutSize xSize = converter.convert( size, pageSize.size.units() );

//consider width and height values may be exchanged
if ( ( qgsDoubleNear( xSize.width(), pageSize.size.width() ) && qgsDoubleNear( xSize.height(), pageSize.size.height() ) )
|| ( qgsDoubleNear( xSize.height(), pageSize.size.width() ) && qgsDoubleNear( xSize.width(), pageSize.size.height() ) ) )
if ( ( qgsDoubleNear( xSize.width(), pageSize.size.width(), 0.01 ) && qgsDoubleNear( xSize.height(), pageSize.size.height(), 0.01 ) )
|| ( qgsDoubleNear( xSize.height(), pageSize.size.width(), 0.01 ) && qgsDoubleNear( xSize.width(), pageSize.size.height(), 0.01 ) ) )
{
return pageSize.name;
}
@@ -131,7 +131,8 @@ void TestQgsPageSizeRegistry::findBySize()
QCOMPARE( registry->find( QgsLayoutSize( 297, 210 ) ), QStringLiteral( "A4" ) );
QCOMPARE( registry->find( QgsLayoutSize( 125, 176 ) ), QStringLiteral( "B6" ) );
QCOMPARE( registry->find( QgsLayoutSize( 21, 29.7, QgsUnitTypes::LayoutCentimeters ) ), QStringLiteral( "A4" ) );

// must have allowance of 0.01 units - because we round to this precision in all page size widgets
QCOMPARE( registry->find( QgsLayoutSize( 125.009, 175.991 ) ), QStringLiteral( "B6" ) );
}

void TestQgsPageSizeRegistry::decodePageSize()

0 comments on commit e8514be

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