121 return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ), mapCanvas );
122 }, createRubberBand );
123 mapItemMetadata->setItemAddedToLayoutFunction( [ = ](
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 ) );
173 }, createRubberBand ) );
182 }, createRubberBand );
183 labelItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & properties )
188 label->
setText( properties.value( QStringLiteral(
"expression" ) ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : QStringLiteral(
"[% %1 %]" ).arg( properties.value( QStringLiteral(
"expression" ) ).toString() ) );
189 if ( QApplication::isRightToLeft() )
194 QSizeF currentSize = label->rect().size();
197 double labelWidth = std::max( minSize.width(), currentSize.width() );
198 double labelHeight = std::max( minSize.height(), currentSize.height() );
199 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
210 return new QgsLayoutLegendWidget( qobject_cast< QgsLayoutItemLegend * >( item ), mapCanvas );
211 }, createRubberBand );
212 legendItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
220 if ( QApplication::isRightToLeft() )
232 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
233 if ( !defaultFontString.isEmpty() )
266 }, createRubberBand );
267 scalebarItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
270 Q_ASSERT( scalebar );
284 std::unique_ptr< QgsLayoutItemGuiMetadata > northArrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
289 }, createRubberBand );
290 northArrowMetadata->setItemCreationFunction( [](
QgsLayout * layout )->QgsLayoutItem *
294 QList< QgsLayoutItemPicture * > pictureItems;
296 int northArrowCount = 0;
299 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
304 if ( p->picturePath() == defaultPath )
308 std::unique_ptr< QgsLayoutItemPicture > picture = std::make_unique< QgsLayoutItemPicture >( layout );
310 picture->setPicturePath( defaultPath );
312 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
313 return picture.release();
315 northArrowMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
320 QList<QgsLayoutItemMap *> mapItems;
330 auto createShapeWidget =
338 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
340 return shape.release();
344 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
346 return shape.release();
350 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
352 return shape.release();
363 std::unique_ptr< QgsLayoutItemGuiMetadata > arrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
368 }, createRubberBand, QString(), true );
369 arrowMetadata->setItemCreationFunction( [](
QgsLayout * layout )->QgsLayoutItem *
371 std::unique_ptr< QgsLayoutItemPolyline > arrow = std::make_unique< QgsLayoutItemPolyline >( layout );
373 return arrow.release();
375 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPathItem*
377 std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
378 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
380 return band.release();
386 std::unique_ptr< QgsLayoutItemGuiMetadata > polygonMetadata = std::make_unique< QgsLayoutItemGuiMetadata >(
391 }, createRubberBand, QStringLiteral(
"nodes" ), true );
392 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPolygonItem*
394 std::unique_ptr< QGraphicsPolygonItem > band = std::make_unique< QGraphicsPolygonItem >();
395 band->setBrush( Qt::NoBrush );
396 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
398 return band.release();
402 std::unique_ptr< QgsLayoutItemGuiMetadata > polylineMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
407 }, createRubberBand, QStringLiteral(
"nodes" ), true );
408 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPathItem*
410 std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
411 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
413 return band.release();
424 }, createRubberBand );
425 htmlItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
427 std::unique_ptr< QgsLayoutItemHtml > htmlMultiFrame = std::make_unique< QgsLayoutItemHtml >( layout );
430 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, html );
444 }, createRubberBand );
445 attributeTableItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
447 std::unique_ptr< QgsLayoutItemAttributeTable > tableMultiFrame = std::make_unique< QgsLayoutItemAttributeTable >( layout );
452 for (
auto it = layerMap.constBegin() ; it != layerMap.constEnd(); ++it )
454 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
463 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
464 if ( !defaultFontString.isEmpty() )
467 QFont f = format.
font();
470 tableMultiFrame->setContentTextFormat( format );
473 tableMultiFrame->setHeaderTextFormat( format );
477 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );
491 }, createRubberBand );
492 manualTableItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
494 std::unique_ptr< QgsLayoutItemManualTable > tableMultiFrame = std::make_unique< QgsLayoutItemManualTable >( layout );
505 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
506 if ( !defaultFontString.isEmpty() )
509 QFont f = format.
font();
512 tableMultiFrame->setContentTextFormat( format );
515 tableMultiFrame->setHeaderTextFormat( format );
520 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );
535 }, createRubberBand );
536 elevationProfileItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
538 std::unique_ptr< QgsLayoutItemElevationProfile > profileItem = std::make_unique< QgsLayoutItemElevationProfile >( layout );
542 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
543 if ( !defaultFontString.isEmpty() )
545 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
546 QFont f = format.
font();
549 profileItem->plot()->xAxis().setTextFormat( format );
551 format = profileItem->plot()->yAxis().textFormat();
555 profileItem->plot()->yAxis().setTextFormat( format );
557 return profileItem.release();