60   QList<QgsLayoutItemMap *> mapItems;
 
   66     if ( map->isSelected() )
 
   73   double largestZValue = std::numeric_limits< double >::lowest();
 
   76     if ( map->collidesWithItem( referenceItem ) && map->zValue() > largestZValue )
 
   79       largestZValue = map->zValue();
 
  118     return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ), mapCanvas );
 
  119   }, createRubberBand );
 
  120   mapItemMetadata->setItemAddedToLayoutFunction( [ = ]( 
QgsLayoutItem * item, 
const QVariantMap & )
 
  135     QList<QgsLayoutItemMap *> mapsList;
 
  139     int counter = mapsList.size() + 1;
 
  140     bool existing = 
false;
 
  146         if ( map == otherMap )
 
  149         if ( otherMap->id() == QObject::tr( 
"Map %1" ).arg( counter ) )
 
  160     map->
setId( QObject::tr( 
"Map %1" ).arg( counter ) );
 
  170   }, createRubberBand ) );
 
  179   }, createRubberBand );
 
  180   labelItemMetadata->setItemAddedToLayoutFunction( [ = ]( 
QgsLayoutItem * item, 
const QVariantMap & properties )
 
  185     label->
setText( properties.value( QStringLiteral( 
"expression" ) ).toString().isEmpty() ? QObject::tr( 
"Lorem ipsum" ) : QStringLiteral( 
"[% %1 %]" ).arg( properties.value( QStringLiteral( 
"expression" ) ).toString() ) );
 
  186     if ( QApplication::isRightToLeft() )
 
  191     QSizeF currentSize = label->rect().size();
 
  194     double labelWidth = std::max( minSize.width(), currentSize.width() );
 
  195     double labelHeight = std::max( minSize.height(), currentSize.height() );
 
  196     label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
 
  207     return new QgsLayoutLegendWidget( qobject_cast< QgsLayoutItemLegend * >( item ), mapCanvas );
 
  208   }, createRubberBand );
 
  209   legendItemMetadata->setItemAddedToLayoutFunction( [ = ]( 
QgsLayoutItem * item, 
const QVariantMap & )
 
  217     if ( QApplication::isRightToLeft() )
 
  229     const QString defaultFontString = settings.
value( QStringLiteral( 
"LayoutDesigner/defaultFont" ), QVariant(), 
QgsSettings::Gui ).toString();
 
  230     if ( !defaultFontString.isEmpty() )
 
  249   }, createRubberBand );
 
  250   scalebarItemMetadata->setItemAddedToLayoutFunction( [ = ]( 
QgsLayoutItem * item, 
const QVariantMap & )
 
  253     Q_ASSERT( scalebar );
 
  267   std::unique_ptr< QgsLayoutItemGuiMetadata > northArrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
 
  272   }, createRubberBand );
 
  273   northArrowMetadata->setItemCreationFunction( []( 
QgsLayout * layout )->QgsLayoutItem *
 
  277     QList< QgsLayoutItemPicture * > pictureItems;
 
  279     int northArrowCount = 0;
 
  282     const QString defaultPath = settings.
value( QStringLiteral( 
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral( 
":/images/north_arrows/layout_default_north_arrow.svg" ), 
QgsSettings::Gui ).toString();
 
  287       if ( p->picturePath() == defaultPath )
 
  291     std::unique_ptr< QgsLayoutItemPicture > picture = std::make_unique< QgsLayoutItemPicture >( layout );
 
  293     picture->setPicturePath( defaultPath );
 
  295     picture->setId( northArrowCount > 0 ? QObject::tr( 
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr( 
"North Arrow" ) );
 
  296     return picture.release();
 
  298   northArrowMetadata->setItemAddedToLayoutFunction( [ = ]( 
QgsLayoutItem * item, 
const QVariantMap & )
 
  303     QList<QgsLayoutItemMap *> mapItems;
 
  313   auto createShapeWidget =
 
  321     std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
 
  323     return shape.release();
 
  327     std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
 
  329     return shape.release();
 
  333     std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
 
  335     return shape.release();
 
  346   std::unique_ptr< QgsLayoutItemGuiMetadata > arrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
 
  351   }, createRubberBand, QString(), true );
 
  352   arrowMetadata->setItemCreationFunction( []( 
QgsLayout * layout )->QgsLayoutItem *
 
  354     std::unique_ptr< QgsLayoutItemPolyline > arrow = std::make_unique< QgsLayoutItemPolyline >( layout );
 
  356     return arrow.release();
 
  358   arrowMetadata->setNodeRubberBandCreationFunction( []( 
QgsLayoutView * )->QGraphicsPathItem*
 
  360     std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
 
  361     band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
 
  363     return band.release();
 
  369   std::unique_ptr< QgsLayoutItemGuiMetadata > polygonMetadata = std::make_unique< QgsLayoutItemGuiMetadata >(
 
  374   }, createRubberBand, QStringLiteral( 
"nodes" ), true );
 
  375   polygonMetadata->setNodeRubberBandCreationFunction( []( 
QgsLayoutView * )->QGraphicsPolygonItem*
 
  377     std::unique_ptr< QGraphicsPolygonItem > band = std::make_unique< QGraphicsPolygonItem >();
 
  378     band->setBrush( Qt::NoBrush );
 
  379     band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
 
  381     return band.release();
 
  385   std::unique_ptr< QgsLayoutItemGuiMetadata > polylineMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
 
  390   }, createRubberBand, QStringLiteral( 
"nodes" ), true );
 
  391   polylineMetadata->setNodeRubberBandCreationFunction( []( 
QgsLayoutView * )->QGraphicsPathItem*
 
  393     std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
 
  394     band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
 
  396     return band.release();
 
  407   }, createRubberBand );
 
  408   htmlItemMetadata->setItemCreationFunction( [ = ]( 
QgsLayout * layout )->QgsLayoutItem *
 
  410     std::unique_ptr< QgsLayoutItemHtml > htmlMultiFrame = std::make_unique< QgsLayoutItemHtml >( layout );
 
  413     std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, html );
 
  426   }, createRubberBand );
 
  427   attributeTableItemMetadata->setItemCreationFunction( [ = ]( 
QgsLayout * layout )->QgsLayoutItem *
 
  429     std::unique_ptr< QgsLayoutItemAttributeTable > tableMultiFrame = std::make_unique< QgsLayoutItemAttributeTable >( layout );
 
  434     for ( 
auto it = layerMap.constBegin() ; it != layerMap.constEnd(); ++it )
 
  436       if ( 
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
 
  445     const QString defaultFontString = settings.
value( QStringLiteral( 
"LayoutDesigner/defaultFont" ), QVariant(), 
QgsSettings::Gui ).toString();
 
  446     if ( !defaultFontString.isEmpty() )
 
  449       QFont f = format.
font();
 
  450       f.setFamily( defaultFontString );
 
  452       tableMultiFrame->setContentTextFormat( format );
 
  455       tableMultiFrame->setHeaderTextFormat( format );
 
  459     std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );
 
  472   }, createRubberBand );
 
  473   manualTableItemMetadata->setItemCreationFunction( [ = ]( 
QgsLayout * layout )->QgsLayoutItem *
 
  475     std::unique_ptr< QgsLayoutItemManualTable > tableMultiFrame = std::make_unique< QgsLayoutItemManualTable >( layout );
 
  486     const QString defaultFontString = settings.
value( QStringLiteral( 
"LayoutDesigner/defaultFont" ), QVariant(), 
QgsSettings::Gui ).toString();
 
  487     if ( !defaultFontString.isEmpty() )
 
  490       QFont f = format.
font();
 
  491       f.setFamily( defaultFontString );
 
  493       tableMultiFrame->setContentTextFormat( format );
 
  496       tableMultiFrame->setHeaderTextFormat( format );
 
  501     std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );