116 mapItemMetadata->setItemAddedToLayoutFunction( [mapCanvas](
QgsLayoutItem *item,
const QVariantMap & ) {
130 QList<QgsLayoutItemMap *> mapsList;
134 int counter = mapsList.size() + 1;
135 bool existing =
false;
141 if ( map == otherMap )
144 if ( otherMap->id() == QObject::tr(
"Map %1" ).arg( counter ) )
155 map->
setId( QObject::tr(
"Map %1" ).arg( counter ) );
167 labelItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap &properties ) {
171 label->
setText( properties.value( QStringLiteral(
"expression" ) ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : QStringLiteral(
"[% %1 %]" ).arg( properties.value( QStringLiteral(
"expression" ) ).toString() ) );
172 if ( QApplication::isRightToLeft() )
177 QSizeF currentSize = label->rect().size();
180 double labelWidth = std::max( minSize.width(), currentSize.width() );
181 double labelHeight = std::max( minSize.height(), currentSize.height() );
182 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
249 legendItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
256 if ( QApplication::isRightToLeft() )
268 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
269 if ( !defaultFontString.isEmpty() )
299 scalebarItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
301 Q_ASSERT( scalebar );
318 auto northArrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
327 QList<QgsLayoutItemPicture *> pictureItems;
329 int northArrowCount = 0;
332 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
337 if ( p->picturePath() == defaultPath )
341 auto picture = std::make_unique<QgsLayoutItemPicture>( layout );
343 picture->setPicturePath( defaultPath );
345 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
346 return picture.release();
348 northArrowMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
352 QList<QgsLayoutItemMap *> mapItems;
362 auto createShapeWidget =
368 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
370 return shape.release();
373 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
375 return shape.release();
378 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
380 return shape.release();
387 auto arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
392 createRubberBand, QString(), true
395 auto arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
397 return arrow.release();
399 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
400 auto band = std::make_unique<QGraphicsItemGroup>();
401 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
402 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
404 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
405 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
408 return band.release();
414 auto polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
419 createRubberBand, QStringLiteral(
"nodes" ), true
421 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
422 auto band = std::make_unique<QGraphicsItemGroup>();
423 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
424 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
425 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
427 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
428 tempPoly->setBrush( Qt::NoBrush );
429 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
432 return band.release();
436 auto polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
441 createRubberBand, QStringLiteral(
"nodes" ), true
443 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
444 auto band = std::make_unique<QGraphicsItemGroup>();
445 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
446 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
448 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
449 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
452 return band.release();
461 auto htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
464 auto frame = std::make_unique<QgsLayoutFrame>( layout, html );
476 auto tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
481 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
483 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
492 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
493 if ( !defaultFontString.isEmpty() )
496 QFont f = format.
font();
499 tableMultiFrame->setContentTextFormat( format );
502 tableMultiFrame->setHeaderTextFormat( format );
506 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
518 auto tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
529 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
530 if ( !defaultFontString.isEmpty() )
533 QFont f = format.
font();
536 tableMultiFrame->setContentTextFormat( format );
539 tableMultiFrame->setHeaderTextFormat( format );
544 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
560 auto profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
564 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
565 if ( !defaultFontString.isEmpty() )
567 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
568 QFont f = format.
font();
571 profileItem->plot()->xAxis().setTextFormat( format );
573 format = profileItem->plot()->yAxis().textFormat();
577 profileItem->plot()->yAxis().setTextFormat( format );
579 return profileItem.release();