Skip to content

Commit

Permalink
Use white bg color for test images to avoid black background
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 22, 2017
1 parent 60c3dcf commit 59ca985
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/core/qgsdatadefinedsizelegend.sip
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Generates legend symbol items according to the configuration
Does nothing if legend is not configured as collapsed.
%End

QImage collapsedLegendImage( QgsRenderContext &context, double paddingMM = 1 ) const;
QImage collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor = Qt::transparent, double paddingMM = 1 ) const;
%Docstring
Returns output image that would be shown in the legend. Returns invalid image if legend is not configured as collapsed.
:rtype: QImage
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsdatadefinedsizelegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void QgsDataDefinedSizeLegend::drawCollapsedLegend( QgsRenderContext &context, Q
}


QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context, double paddingMM ) const
QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor, double paddingMM ) const
{
if ( mType != LegendCollapsed || mSizeClasses.isEmpty() || !mSymbol )
return QImage();
Expand All @@ -276,7 +276,7 @@ QImage QgsDataDefinedSizeLegend::collapsedLegendImage( QgsRenderContext &context
QImage img( contentSize.width() + padding * 2, contentSize.height() + padding * 2, QImage::Format_ARGB32_Premultiplied );
img.setDotsPerMeterX( dpm );
img.setDotsPerMeterY( dpm );
img.fill( Qt::transparent );
img.fill( backgroundColor );

QPainter painter( &img );
painter.setRenderHint( QPainter::Antialiasing, true );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdatadefinedsizelegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class CORE_EXPORT QgsDataDefinedSizeLegend
void drawCollapsedLegend( QgsRenderContext &context, QSize *outputSize SIP_OUT = nullptr, int *labelXOffset SIP_OUT = nullptr ) const;

//! Returns output image that would be shown in the legend. Returns invalid image if legend is not configured as collapsed.
QImage collapsedLegendImage( QgsRenderContext &context, double paddingMM = 1 ) const;
QImage collapsedLegendImage( QgsRenderContext &context, const QColor &backgroundColor = Qt::transparent, double paddingMM = 1 ) const;

//! Creates instance from given element and returns it (caller takes ownership). Returns null on error.
static QgsDataDefinedSizeLegend *readXml( const QDomElement &elem, const QgsReadWriteContext &context ) SIP_FACTORY;
Expand Down
6 changes: 3 additions & 3 deletions tests/src/core/testqgsdatadefinedsizelegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ void TestQgsDataDefinedSizeLegend::testBasic()

QgsRenderContext context( _createRenderContext( 100, 96, 100 ) );

QImage imgBottom = settings.collapsedLegendImage( context, 1 );
QImage imgBottom = settings.collapsedLegendImage( context, Qt::white, 1 );
imgBottom.save( _fileNameForTest( "basic_bottom" ) );
QVERIFY( _verifyImage( "basic_bottom", mReport ) );

settings.setVerticalAlignment( QgsDataDefinedSizeLegend::AlignCenter );

QImage imgCenter = settings.collapsedLegendImage( context, 1 );
QImage imgCenter = settings.collapsedLegendImage( context, Qt::white, 1 );
imgCenter.save( _fileNameForTest( "basic_center" ) );
QVERIFY( _verifyImage( "basic_center", mReport ) );
}
Expand Down Expand Up @@ -149,7 +149,7 @@ void TestQgsDataDefinedSizeLegend::testCrowded()

QgsRenderContext context( _createRenderContext( 100, 96, 100 ) );

QImage img = settings.collapsedLegendImage( context, 1 );
QImage img = settings.collapsedLegendImage( context, Qt::white, 1 );
img.save( _fileNameForTest( "crowded" ) );

QVERIFY( _verifyImage( "crowded", mReport ) );
Expand Down

0 comments on commit 59ca985

Please sign in to comment.