Skip to content

Commit ad4a38d

Browse files
nyalldawsonnirvn
authored andcommittedJun 14, 2019
[layouts] Improve north arrow export time validity check to also test
for north arrows by checking their default id string
1 parent 1423ae3 commit ad4a38d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎src/app/layout/qgslayoutvaliditychecks.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ bool QgsLayoutNorthArrowValidityCheck::prepareCheck( const QgsValidityCheckConte
105105
layoutContext->layout->layoutItems( pictureItems );
106106
for ( QgsLayoutItemPicture *picture : qgis::as_const( pictureItems ) )
107107
{
108-
// look for pictures which use the default north arrow svg, but aren't actually linked to maps
109-
if ( !picture->linkedMap() && picture->picturePath() == QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ) )
108+
// look for pictures which use the default north arrow svg, but aren't actually linked to maps.
109+
// alternatively identify them by looking for the default "North Arrow" string in their id
110+
if ( !picture->linkedMap() && ( picture->picturePath() == QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" )
111+
|| picture->id().contains( QObject::tr( "North Arrow" ), Qt::CaseInsensitive ) ) )
110112
{
111113
QgsValidityCheckResult res;
112114
res.type = QgsValidityCheckResult::Warning;

‎tests/src/app/testqgsapplayoutvaliditychecks.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ void TestQgsLayoutValidityChecks::testNorthArrowValidity()
134134
QVERIFY( check2.prepareCheck( &context, &f ) );
135135
res = check2.runCheck( &context, &f );
136136
QCOMPARE( res.size(), 0 );
137+
138+
// test with ID check
139+
picture->setPicturePath( QStringLiteral( "a" ) );
140+
picture->setId( QStringLiteral( "north arrow 2" ) );
141+
picture->setLinkedMap( nullptr );
142+
143+
QgsLayoutNorthArrowValidityCheck check3;
144+
QVERIFY( check3.prepareCheck( &context, &f ) );
145+
res = check3.runCheck( &context, &f );
146+
QCOMPARE( res.size(), 1 );
147+
QCOMPARE( res.at( 0 ).type, QgsValidityCheckResult::Warning );
148+
149+
// no longer looks like a north arrow
150+
picture->setId( QStringLiteral( "a" ) );
151+
QgsLayoutNorthArrowValidityCheck check4;
152+
QVERIFY( check4.prepareCheck( &context, &f ) );
153+
res = check4.runCheck( &context, &f );
154+
QCOMPARE( res.size(), 0 );
137155
}
138156

139157
void TestQgsLayoutValidityChecks::testOverviewValidity()

0 commit comments

Comments
 (0)
Please sign in to comment.