123 mapItemMetadata->setItemAddedToLayoutFunction( [mapCanvas](
QgsLayoutItem *item,
const QVariantMap & ) {
137 QList<QgsLayoutItemMap *> mapsList;
141 int counter = mapsList.size() + 1;
142 bool existing =
false;
148 if ( map == otherMap )
151 if ( otherMap->id() == QObject::tr(
"Map %1" ).arg( counter ) )
162 map->
setId( QObject::tr(
"Map %1" ).arg( counter ) );
173 labelItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap &properties ) {
177 label->
setText( properties.value( u
"expression"_s ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : u
"[% %1 %]"_s.arg( properties.value( u
"expression"_s ).toString() ) );
178 if ( QApplication::isRightToLeft() )
183 QSizeF currentSize = label->rect().size();
186 double labelWidth = std::max( minSize.width(), currentSize.width() );
187 double labelHeight = std::max( minSize.height(), currentSize.height() );
188 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
255 legendItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
265 if ( QApplication::isRightToLeft() )
277 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
278 if ( !defaultFontString.isEmpty() )
308 scalebarItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
310 Q_ASSERT( scalebar );
327 auto northArrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
336 QList<QgsLayoutItemPicture *> pictureItems;
338 int northArrowCount = 0;
341 const QString defaultPath = settings.
value( u
"LayoutDesigner/defaultNorthArrow"_s, u
":/images/north_arrows/layout_default_north_arrow.svg"_s,
QgsSettings::Gui ).toString();
346 if ( p->picturePath() == defaultPath )
350 auto picture = std::make_unique<QgsLayoutItemPicture>( layout );
352 picture->setPicturePath( defaultPath );
354 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
355 return picture.release();
357 northArrowMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
361 QList<QgsLayoutItemMap *> mapItems;
371 auto createShapeWidget =
377 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
379 return shape.release();
382 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
384 return shape.release();
387 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
389 return shape.release();
396 auto arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
401 createRubberBand, QString(), true
404 auto arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
406 return arrow.release();
408 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
409 auto band = std::make_unique<QGraphicsItemGroup>();
410 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
411 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
413 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
414 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
417 return band.release();
423 auto polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
428 createRubberBand, u
"nodes"_s, true
430 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
431 auto band = std::make_unique<QGraphicsItemGroup>();
432 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
433 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
434 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
436 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
437 tempPoly->setBrush( Qt::NoBrush );
438 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
441 return band.release();
445 auto polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
450 createRubberBand, u
"nodes"_s, true
452 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
453 auto band = std::make_unique<QGraphicsItemGroup>();
454 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
455 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
457 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
458 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
461 return band.release();
470 auto htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
473 auto frame = std::make_unique<QgsLayoutFrame>( layout, html );
485 auto tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
490 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
492 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
501 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
502 if ( !defaultFontString.isEmpty() )
505 QFont f = format.
font();
508 tableMultiFrame->setContentTextFormat( format );
511 tableMultiFrame->setHeaderTextFormat( format );
515 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
527 auto tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
538 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
539 if ( !defaultFontString.isEmpty() )
542 QFont f = format.
font();
545 tableMultiFrame->setContentTextFormat( format );
548 tableMultiFrame->setHeaderTextFormat( format );
553 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
569 auto profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
573 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
574 if ( !defaultFontString.isEmpty() )
576 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
577 QFont f = format.
font();
580 profileItem->plot()->xAxis().setTextFormat( format );
582 format = profileItem->plot()->yAxis().textFormat();
586 profileItem->plot()->yAxis().setTextFormat( format );
588 return profileItem.release();