117 auto mapItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
119 QObject::tr(
"Map" ),
124 mapItemMetadata->setItemAddedToLayoutFunction( [mapCanvas](
QgsLayoutItem *item,
const QVariantMap & ) {
138 QList<QgsLayoutItemMap *> mapsList;
142 int counter = mapsList.size() + 1;
143 bool existing =
false;
149 if ( map == otherMap )
152 if ( otherMap->id() == QObject::tr(
"Map %1" ).arg( counter ) )
163 map->
setId( QObject::tr(
"Map %1" ).arg( counter ) );
171 QObject::tr(
"Picture" ),
179 auto labelItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
181 QObject::tr(
"Label" ),
186 labelItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap &properties ) {
190 label->
setText( properties.value( u
"expression"_s ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : u
"[% %1 %]"_s.arg( properties.value( u
"expression"_s ).toString() ) );
191 if ( QApplication::isRightToLeft() )
196 QSizeF currentSize = label->rect().size();
199 double labelWidth = std::max( minSize.width(), currentSize.width() );
200 double labelHeight = std::max( minSize.height(), currentSize.height() );
201 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
267 auto legendItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
269 QObject::tr(
"Legend" ),
274 legendItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
284 if ( QApplication::isRightToLeft() )
296 if ( !defaultFontString.isEmpty() )
325 auto scalebarItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
327 QObject::tr(
"Scale Bar" ),
332 scalebarItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
334 Q_ASSERT( scalebar );
351 auto northArrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
353 QObject::tr(
"North Arrow" ),
360 QList<QgsLayoutItemPicture *> pictureItems;
362 int northArrowCount = 0;
369 if ( p->picturePath() == defaultPath )
373 auto picture = std::make_unique<QgsLayoutItemPicture>( layout );
375 picture->setPicturePath( defaultPath );
377 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
378 return picture.release();
380 northArrowMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
384 QList<QgsLayoutItemMap *> mapItems;
398 QObject::tr(
"Rectangle" ),
406 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
408 return shape.release();
413 QObject::tr(
"Ellipse" ),
421 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
423 return shape.release();
428 QObject::tr(
"Triangle" ),
436 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
438 return shape.release();
445 QObject::tr(
"Marker" ),
452 auto arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
454 QObject::tr(
"Arrow" ),
462 auto arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
464 return arrow.release();
466 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
467 auto band = std::make_unique<QGraphicsItemGroup>();
468 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
469 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
471 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
472 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
475 return band.release();
481 auto polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
483 QObject::tr(
"Polygon" ),
490 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
491 auto band = std::make_unique<QGraphicsItemGroup>();
492 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
493 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
494 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
496 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
497 tempPoly->setBrush( Qt::NoBrush );
498 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
501 return band.release();
505 auto polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
507 QObject::tr(
"Polyline" ),
514 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
515 auto band = std::make_unique<QGraphicsItemGroup>();
516 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
517 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
519 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
520 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
523 return band.release();
530 auto htmlItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
532 QObject::tr(
"HTML" ),
538 auto htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
541 auto frame = std::make_unique<QgsLayoutFrame>( layout, html );
551 auto attributeTableItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
553 QObject::tr(
"Attribute Table" ),
559 auto tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
564 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
566 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
575 if ( !defaultFontString.isEmpty() )
578 QFont f = format.
font();
581 tableMultiFrame->setContentTextFormat( format );
584 tableMultiFrame->setHeaderTextFormat( format );
588 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
598 auto manualTableItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
600 QObject::tr(
"Fixed Table" ),
606 auto tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
617 if ( !defaultFontString.isEmpty() )
620 QFont f = format.
font();
623 tableMultiFrame->setContentTextFormat( format );
626 tableMultiFrame->setHeaderTextFormat( format );
631 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
645 auto elevationProfileItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
647 QObject::tr(
"Elevation Profile" ),
653 auto profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
657 if ( !defaultFontString.isEmpty() )
659 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
660 QFont f = format.
font();
663 profileItem->plot()->xAxis().setTextFormat( format );
665 format = profileItem->plot()->yAxis().textFormat();
669 profileItem->plot()->yAxis().setTextFormat( format );
671 return profileItem.release();
679 QObject::tr(
"Chart" ),