Skip to content

Commit

Permalink
[layouts] Improve north arrow export time validity check to also test
Browse files Browse the repository at this point in the history
for north arrows by checking their default id string
  • Loading branch information
nyalldawson authored and nirvn committed Jun 14, 2019
1 parent 1423ae3 commit ad4a38d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app/layout/qgslayoutvaliditychecks.cpp
Expand Up @@ -105,8 +105,10 @@ bool QgsLayoutNorthArrowValidityCheck::prepareCheck( const QgsValidityCheckConte
layoutContext->layout->layoutItems( pictureItems );
for ( QgsLayoutItemPicture *picture : qgis::as_const( pictureItems ) )
{
// look for pictures which use the default north arrow svg, but aren't actually linked to maps
if ( !picture->linkedMap() && picture->picturePath() == QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ) )
// look for pictures which use the default north arrow svg, but aren't actually linked to maps.
// alternatively identify them by looking for the default "North Arrow" string in their id
if ( !picture->linkedMap() && ( picture->picturePath() == QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" )
|| picture->id().contains( QObject::tr( "North Arrow" ), Qt::CaseInsensitive ) ) )
{
QgsValidityCheckResult res;
res.type = QgsValidityCheckResult::Warning;
Expand Down
18 changes: 18 additions & 0 deletions tests/src/app/testqgsapplayoutvaliditychecks.cpp
Expand Up @@ -134,6 +134,24 @@ void TestQgsLayoutValidityChecks::testNorthArrowValidity()
QVERIFY( check2.prepareCheck( &context, &f ) );
res = check2.runCheck( &context, &f );
QCOMPARE( res.size(), 0 );

// test with ID check
picture->setPicturePath( QStringLiteral( "a" ) );
picture->setId( QStringLiteral( "north arrow 2" ) );
picture->setLinkedMap( nullptr );

QgsLayoutNorthArrowValidityCheck check3;
QVERIFY( check3.prepareCheck( &context, &f ) );
res = check3.runCheck( &context, &f );
QCOMPARE( res.size(), 1 );
QCOMPARE( res.at( 0 ).type, QgsValidityCheckResult::Warning );

// no longer looks like a north arrow
picture->setId( QStringLiteral( "a" ) );
QgsLayoutNorthArrowValidityCheck check4;
QVERIFY( check4.prepareCheck( &context, &f ) );
res = check4.runCheck( &context, &f );
QCOMPARE( res.size(), 0 );
}

void TestQgsLayoutValidityChecks::testOverviewValidity()
Expand Down

0 comments on commit ad4a38d

Please sign in to comment.