Skip to content

Commit 03a8b03

Browse files
nyalldawsonnirvn
authored andcommittedJun 14, 2019
Set north arrows ID by default, so that they are identifiable in layout item lists
1 parent ab92dee commit 03a8b03

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎src/app/layout/qgslayoutapputils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,23 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
232232
}, createRubberBand );
233233
northArrowMetadata->setItemCreationFunction( []( QgsLayout * layout )->QgsLayoutItem *
234234
{
235+
236+
// count how many existing north arrows are already in layout
237+
QList< QgsLayoutItemPicture * > pictureItems;
238+
layout->layoutItems( pictureItems );
239+
int northArrowCount = 0;
240+
for ( QgsLayoutItemPicture *p : qgis::as_const( pictureItems ) )
241+
{
242+
// look for pictures which use the default north arrow svg
243+
if ( p->picturePath() == QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ) )
244+
northArrowCount++;
245+
}
246+
235247
std::unique_ptr< QgsLayoutItemPicture > picture = qgis::make_unique< QgsLayoutItemPicture >( layout );
236248
picture->setNorthMode( QgsLayoutItemPicture::GridNorth );
237249
picture->setPicturePath( QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ) );
250+
// set an id by default, so that north arrows are discernable in layout item lists
251+
picture->setId( northArrowCount > 0 ? QObject::tr( "North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr( "North Arrow" ) );
238252
return picture.release();
239253
} );
240254
northArrowMetadata->setItemAddedToLayoutFunction( [ = ]( QgsLayoutItem * item )

0 commit comments

Comments
 (0)
Please sign in to comment.