Skip to content
Permalink
Browse files

Fix fragile method of setting font marker data defined style

And fix test flakiness
  • Loading branch information
nyalldawson authored and github-actions committed Feb 11, 2021
1 parent dbd1c41 commit 5b2cfe3aa4200b8edfa7e3ab75290ad8e89e095b
Showing with 3 additions and 15 deletions.
  1. +1 −1 src/core/symbology/qgsmarkersymbollayer.cpp
  2. +2 −14 tests/src/core/testqgsfontmarker.cpp
@@ -3286,7 +3286,7 @@ void QgsFontMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContex
{
context.setOriginalValueVariable( mFontStyle );
QString fontStyle = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFontStyle, context.renderContext().expressionContext(), mFontStyle, &ok );
mFont.setStyleName( QgsFontUtils::translateNamedStyle( ok ? fontStyle : mFontStyle ) );
QgsFontUtils::updateFontViaStyle( mFont, QgsFontUtils::translateNamedStyle( ok ? fontStyle : mFontStyle ) );
}
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFontFamily ) || mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFontStyle ) )
{
@@ -82,7 +82,7 @@ void TestQgsFontMarkerSymbol::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();
QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Bold" ) );
QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Bold" ) << QStringLiteral( "Oblique" ) );

//create some objects that will be used in all tests...
QString myDataDir( TEST_DATA_DIR ); //defined in CmakeLists.txt
@@ -143,26 +143,18 @@ void TestQgsFontMarkerSymbol::fontMarkerSymbolStyle()
{
mReport += QLatin1String( "<h2>Font marker symbol style layer test</h2>\n" );

QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Bold" ) << QStringLiteral( "Oblique" ) );
mFontMarkerLayer->setColor( Qt::blue );
QFont font = QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) );
mFontMarkerLayer->setFontFamily( font.family() );
mFontMarkerLayer->setFontStyle( QStringLiteral( "Oblique" ) );
mFontMarkerLayer->setCharacter( QChar( 'A' ) );
mFontMarkerLayer->setSize( 12 );
QVERIFY( imageCheck( "fontmarker_style" ) );

// Loading both Bold and Oblique in the initTestCase() function creates inconsistent results on windows and linux, this is a workaround
QFontDatabase fontDb;
fontDb.removeAllApplicationFonts();
QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Bold" ) );
}

void TestQgsFontMarkerSymbol::fontMarkerSymbolDataDefinedProperties()
{
mReport += QLatin1String( "<h2>Font marker symbol data defined properties layer test</h2>\n" );

QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Bold" ) << QStringLiteral( "Oblique" ) );
mFontMarkerLayer->setColor( Qt::blue );
QFont font = QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) );
mFontMarkerLayer->setFontFamily( font.family() );
@@ -175,17 +167,13 @@ void TestQgsFontMarkerSymbol::fontMarkerSymbolDataDefinedProperties()
QVERIFY( imageCheck( "fontmarker_datadefinedproperties" ) );

mFontMarkerLayer->setDataDefinedProperties( QgsPropertyCollection() );

// Loading both Bold and Oblique in the initTestCase() function creates inconsistent results on windows and linux, this is a workaround
QFontDatabase fontDb;
fontDb.removeAllApplicationFonts();
QgsFontUtils::loadStandardTestFonts( QStringList() << QStringLiteral( "Bold" ) );
}

void TestQgsFontMarkerSymbol::fontMarkerSymbolStroke()
{
mFontMarkerLayer->setColor( Qt::blue );
QFont font = QgsFontUtils::getStandardTestFont( QStringLiteral( "Bold" ) );
mFontMarkerLayer->setFontStyle( QStringLiteral( "Bold" ) );
mFontMarkerLayer->setFontFamily( font.family() );
mFontMarkerLayer->setCharacter( QChar( 'A' ) );
mFontMarkerLayer->setSize( 30 );

0 comments on commit 5b2cfe3

Please sign in to comment.