116 auto mapItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
118 QObject::tr(
"Map" ),
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 ) );
170 QObject::tr(
"Picture" ),
178 auto labelItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
180 QObject::tr(
"Label" ),
185 labelItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap &properties ) {
189 label->
setText( properties.value( u
"expression"_s ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : u
"[% %1 %]"_s.arg( properties.value( u
"expression"_s ).toString() ) );
190 if ( QApplication::isRightToLeft() )
195 QSizeF currentSize = label->rect().size();
198 double labelWidth = std::max( minSize.width(), currentSize.width() );
199 double labelHeight = std::max( minSize.height(), currentSize.height() );
200 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
266 auto legendItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
268 QObject::tr(
"Legend" ),
273 legendItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
283 if ( QApplication::isRightToLeft() )
295 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
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;
365 const QString defaultPath = settings.
value( u
"LayoutDesigner/defaultNorthArrow"_s, u
":/images/north_arrows/layout_default_north_arrow.svg"_s,
QgsSettings::Gui ).toString();
370 if ( p->picturePath() == defaultPath )
374 auto picture = std::make_unique<QgsLayoutItemPicture>( layout );
376 picture->setPicturePath( defaultPath );
378 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
379 return picture.release();
381 northArrowMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
385 QList<QgsLayoutItemMap *> mapItems;
399 QObject::tr(
"Rectangle" ),
407 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
409 return shape.release();
414 QObject::tr(
"Ellipse" ),
422 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
424 return shape.release();
429 QObject::tr(
"Triangle" ),
437 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
439 return shape.release();
446 QObject::tr(
"Marker" ),
453 auto arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
455 QObject::tr(
"Arrow" ),
463 auto arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
465 return arrow.release();
467 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
468 auto band = std::make_unique<QGraphicsItemGroup>();
469 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
470 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
472 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
473 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
476 return band.release();
482 auto polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
484 QObject::tr(
"Polygon" ),
491 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
492 auto band = std::make_unique<QGraphicsItemGroup>();
493 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
494 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
495 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
497 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
498 tempPoly->setBrush( Qt::NoBrush );
499 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
502 return band.release();
506 auto polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
508 QObject::tr(
"Polyline" ),
515 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
516 auto band = std::make_unique<QGraphicsItemGroup>();
517 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
518 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
520 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
521 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
524 return band.release();
531 auto htmlItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
533 QObject::tr(
"HTML" ),
539 auto htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
542 auto frame = std::make_unique<QgsLayoutFrame>( layout, html );
552 auto attributeTableItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
554 QObject::tr(
"Attribute Table" ),
560 auto tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
565 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
567 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
576 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
577 if ( !defaultFontString.isEmpty() )
580 QFont f = format.
font();
583 tableMultiFrame->setContentTextFormat( format );
586 tableMultiFrame->setHeaderTextFormat( format );
590 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
600 auto manualTableItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
602 QObject::tr(
"Fixed Table" ),
608 auto tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
619 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
620 if ( !defaultFontString.isEmpty() )
623 QFont f = format.
font();
626 tableMultiFrame->setContentTextFormat( format );
629 tableMultiFrame->setHeaderTextFormat( format );
634 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
648 auto elevationProfileItemMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
650 QObject::tr(
"Elevation Profile" ),
656 auto profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
660 const QString defaultFontString = settings.
value( u
"LayoutDesigner/defaultFont"_s, QVariant(),
QgsSettings::Gui ).toString();
661 if ( !defaultFontString.isEmpty() )
663 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
664 QFont f = format.
font();
667 profileItem->plot()->xAxis().setTextFormat( format );
669 format = profileItem->plot()->yAxis().textFormat();
673 profileItem->plot()->yAxis().setTextFormat( format );
675 return profileItem.release();
683 QObject::tr(
"Chart" ),