Skip to content

Commit e8514be

Browse files
committedJul 25, 2017
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.
1 parent 9e2673a commit e8514be

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed
 

‎src/core/layout/qgspagesizeregistry.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ QString QgsPageSizeRegistry::find( const QgsLayoutSize &size ) const
9797
QgsLayoutSize xSize = converter.convert( size, pageSize.size.units() );
9898

9999
//consider width and height values may be exchanged
100-
if ( ( qgsDoubleNear( xSize.width(), pageSize.size.width() ) && qgsDoubleNear( xSize.height(), pageSize.size.height() ) )
101-
|| ( qgsDoubleNear( xSize.height(), pageSize.size.width() ) && qgsDoubleNear( xSize.width(), pageSize.size.height() ) ) )
100+
if ( ( qgsDoubleNear( xSize.width(), pageSize.size.width(), 0.01 ) && qgsDoubleNear( xSize.height(), pageSize.size.height(), 0.01 ) )
101+
|| ( qgsDoubleNear( xSize.height(), pageSize.size.width(), 0.01 ) && qgsDoubleNear( xSize.width(), pageSize.size.height(), 0.01 ) ) )
102102
{
103103
return pageSize.name;
104104
}

‎tests/src/core/testqgspagesizeregistry.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ void TestQgsPageSizeRegistry::findBySize()
131131
QCOMPARE( registry->find( QgsLayoutSize( 297, 210 ) ), QStringLiteral( "A4" ) );
132132
QCOMPARE( registry->find( QgsLayoutSize( 125, 176 ) ), QStringLiteral( "B6" ) );
133133
QCOMPARE( registry->find( QgsLayoutSize( 21, 29.7, QgsUnitTypes::LayoutCentimeters ) ), QStringLiteral( "A4" ) );
134-
134+
// must have allowance of 0.01 units - because we round to this precision in all page size widgets
135+
QCOMPARE( registry->find( QgsLayoutSize( 125.009, 175.991 ) ), QStringLiteral( "B6" ) );
135136
}
136137

137138
void TestQgsPageSizeRegistry::decodePageSize()

0 commit comments

Comments
 (0)
Please sign in to comment.