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.
This commit is contained in:
Nyall Dawson 2017-07-25 13:57:57 +10:00
parent 9e2673a178
commit e8514be010
2 changed files with 4 additions and 3 deletions

View File

@ -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;
}

View File

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