Skip to content

Commit

Permalink
Fix fragile method of setting font marker data defined style
Browse files Browse the repository at this point in the history
And fix test flakiness
  • Loading branch information
nyalldawson authored and github-actions[bot] committed Feb 11, 2021
1 parent dbd1c41 commit 5b2cfe3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/core/symbology/qgsmarkersymbollayer.cpp
Expand Up @@ -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 ) )
{
Expand Down
16 changes: 2 additions & 14 deletions tests/src/core/testqgsfontmarker.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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() );
Expand All @@ -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 );
Expand Down

0 comments on commit 5b2cfe3

Please sign in to comment.