[layouts] Allow default north arrow path to be specified through settings

This commit is contained in:
Nyall Dawson 2019-06-13 06:14:21 +10:00 committed by Mathieu Pellerin
parent ad4a38d1c0
commit 5db0965a26
2 changed files with 12 additions and 2 deletions

View File

@ -99,6 +99,12 @@ PostgreSQL\default_timeout=30
# cause performance issues, as the records must all be loaded from the related table on display.
maxEntriesRelationWidget=100
# Path to default image to use for layout north arrows
LayoutDesigner\defaultNorthArrow=:/images/north_arrows/layout_default_north_arrow.svg
# Default font to use in layout designer
LayoutDesigner\defaultFont=
[geometry_validation]
# A comma separated list of geometry validations to enable by default for newly added layers
# Available checks: QgsIsValidCheck,QgsGeometryGapCheck,QgsGeometryOverlapCheck,QgsGeometryMissingVertexCheck

View File

@ -237,16 +237,20 @@ void QgsLayoutAppUtils::registerGuiForKnownItemTypes()
QList< QgsLayoutItemPicture * > pictureItems;
layout->layoutItems( pictureItems );
int northArrowCount = 0;
QgsSettings settings;
const QString defaultPath = settings.value( QStringLiteral( "LayoutDesigner/defaultNorthArrow" ), QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ), QgsSettings::Gui ).toString();
for ( QgsLayoutItemPicture *p : qgis::as_const( pictureItems ) )
{
// look for pictures which use the default north arrow svg
if ( p->picturePath() == QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ) )
if ( p->picturePath() == defaultPath )
northArrowCount++;
}
std::unique_ptr< QgsLayoutItemPicture > picture = qgis::make_unique< QgsLayoutItemPicture >( layout );
picture->setNorthMode( QgsLayoutItemPicture::GridNorth );
picture->setPicturePath( QStringLiteral( ":/images/north_arrows/layout_default_north_arrow.svg" ) );
picture->setPicturePath( defaultPath );
// set an id by default, so that north arrows are discernible in layout item lists
picture->setId( northArrowCount > 0 ? QObject::tr( "North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr( "North Arrow" ) );
return picture.release();