Skip to content
Permalink
Browse files

Fix fragile method of setting font marker data defined style

And fix test flakiness
  • Loading branch information
nyalldawson committed Feb 11, 2021
1 parent 2f7d6de commit 1ed964d34c55a7d63a80f2a3eaf7bbb9e521a913
Showing with 3 additions and 15 deletions.
  1. +1 −1 src/core/symbology/qgsmarkersymbollayer.cpp
  2. +2 −14 tests/src/core/testqgsfontmarker.cpp
@@ -3325,7 +3325,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 ) )
{
@@ -83,7 +83,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
@@ -144,26 +144,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() );
@@ -176,17 +168,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 1ed964d

Please sign in to comment.