Skip to content
Permalink
Browse files

Fix QPainter warnings when broken image paths are passed to QgsImageC…

…ache
  • Loading branch information
nyalldawson committed Dec 5, 2018
1 parent bafda24 commit 313688515712aeb85fb600f4cb3d16c12dc01a28
Showing with 29 additions and 1 deletion.
  1. +11 −0 src/core/qgsimagecache.cpp
  2. +18 −1 tests/src/core/testqgsimagecache.cpp
@@ -194,6 +194,11 @@ QImage QgsImageCache::renderImage( const QString &path, QSize size, const bool k

if ( ba == "broken" )
{
// if image size is set to respect aspect ratio, correct for broken image aspect ratio
if ( size.width() == 0 )
size.setWidth( size.height() );
if ( size.height() == 0 )
size.setHeight( size.width() );
// render "broken" svg
im = QImage( size, QImage::Format_ARGB32_Premultiplied );
im.fill( 0 ); // transparent background
@@ -208,6 +213,12 @@ QImage QgsImageCache::renderImage( const QString &path, QSize size, const bool k
}
else if ( ba == "fetching" )
{
// if image size is set to respect aspect ratio, correct for broken image aspect ratio
if ( size.width() == 0 )
size.setWidth( size.height() );
if ( size.height() == 0 )
size.setHeight( size.width() );

// render "fetching" svg
im = QImage( size, QImage::Format_ARGB32_Premultiplied );
im.fill( 0 ); // transparent background
@@ -217,6 +217,23 @@ void TestQgsImageCache::size()
img = cache.pathAsImage( originalImage, QSize( 0, 100 ), true, 1.0, inCache );
QCOMPARE( img.width(), 64 );
QCOMPARE( img.height(), 100 );

// broken images should fallback to square aspect ratios, not the originally specified 0 px width or height
img = cache.pathAsImage( QStringLiteral( "broken" ), QSize( 0, 100 ), true, 1.0, inCache );
QCOMPARE( img.width(), 100 );
QCOMPARE( img.height(), 100 );

img = cache.pathAsImage( QStringLiteral( "broken" ), QSize( 100, 0 ), true, 1.0, inCache );
QCOMPARE( img.width(), 100 );
QCOMPARE( img.height(), 100 );

img = cache.pathAsImage( QStringLiteral( "broken" ), QSize( 0, 100 ), false, 1.0, inCache );
QCOMPARE( img.width(), 100 );
QCOMPARE( img.height(), 100 );

img = cache.pathAsImage( QStringLiteral( "broken" ), QSize( 100, 0 ), false, 1.0, inCache );
QCOMPARE( img.width(), 100 );
QCOMPARE( img.height(), 100 );
}

void TestQgsImageCache::opacity()
@@ -228,7 +245,7 @@ void TestQgsImageCache::opacity()

// null size should return image using original size
img = cache.pathAsImage( originalImage, QSize( 200, 200 ), true, 0.5, inCache );
QVERIFY( imageCheck( "opaque_image", img, 30 ) );
QVERIFY( imageCheck( QStringLiteral( "opaque_image" ), img, 30 ) );
}

void TestQgsImageCache::base64()

0 comments on commit 3136885

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