119 mapItemMetadata->setItemAddedToLayoutFunction( [mapCanvas](
QgsLayoutItem *item,
const QVariantMap & ) {
133 QList<QgsLayoutItemMap *> mapsList;
137 int counter = mapsList.size() + 1;
138 bool existing =
false;
144 if ( map == otherMap )
147 if ( otherMap->id() == QObject::tr(
"Map %1" ).arg( counter ) )
158 map->
setId( QObject::tr(
"Map %1" ).arg( counter ) );
169 labelItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap &properties ) {
173 label->
setText( properties.value( QStringLiteral(
"expression" ) ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : QStringLiteral(
"[% %1 %]" ).arg( properties.value( QStringLiteral(
"expression" ) ).toString() ) );
174 if ( QApplication::isRightToLeft() )
179 QSizeF currentSize = label->rect().size();
182 double labelWidth = std::max( minSize.width(), currentSize.width() );
183 double labelHeight = std::max( minSize.height(), currentSize.height() );
184 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
251 legendItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
258 if ( QApplication::isRightToLeft() )
270 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
271 if ( !defaultFontString.isEmpty() )
301 scalebarItemMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
303 Q_ASSERT( scalebar );
320 auto northArrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
329 QList<QgsLayoutItemPicture *> pictureItems;
331 int northArrowCount = 0;
334 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
339 if ( p->picturePath() == defaultPath )
343 auto picture = std::make_unique<QgsLayoutItemPicture>( layout );
345 picture->setPicturePath( defaultPath );
347 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
348 return picture.release();
350 northArrowMetadata->setItemAddedToLayoutFunction( [](
QgsLayoutItem *item,
const QVariantMap & ) {
354 QList<QgsLayoutItemMap *> mapItems;
364 auto createShapeWidget =
370 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
372 return shape.release();
375 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
377 return shape.release();
380 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
382 return shape.release();
389 auto arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
394 createRubberBand, QString(), true
397 auto arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
399 return arrow.release();
401 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
402 auto band = std::make_unique<QGraphicsItemGroup>();
403 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
404 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
406 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
407 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
410 return band.release();
416 auto polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
421 createRubberBand, QStringLiteral(
"nodes" ), true
423 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
424 auto band = std::make_unique<QGraphicsItemGroup>();
425 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
426 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
427 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
429 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
430 tempPoly->setBrush( Qt::NoBrush );
431 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
434 return band.release();
438 auto polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
443 createRubberBand, QStringLiteral(
"nodes" ), true
445 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
446 auto band = std::make_unique<QGraphicsItemGroup>();
447 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
448 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
450 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
451 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
454 return band.release();
463 auto htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
466 auto frame = std::make_unique<QgsLayoutFrame>( layout, html );
478 auto tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
483 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
485 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
494 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
495 if ( !defaultFontString.isEmpty() )
498 QFont f = format.
font();
501 tableMultiFrame->setContentTextFormat( format );
504 tableMultiFrame->setHeaderTextFormat( format );
508 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
520 auto tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
531 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
532 if ( !defaultFontString.isEmpty() )
535 QFont f = format.
font();
538 tableMultiFrame->setContentTextFormat( format );
541 tableMultiFrame->setHeaderTextFormat( format );
546 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
562 auto profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
566 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
567 if ( !defaultFontString.isEmpty() )
569 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
570 QFont f = format.
font();
573 profileItem->plot()->xAxis().setTextFormat( format );
575 format = profileItem->plot()->yAxis().textFormat();
579 profileItem->plot()->yAxis().setTextFormat( format );
581 return profileItem.release();