116 mapItemMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
130 QList<QgsLayoutItemMap *> mapsList;
134 int counter = mapsList.size() + 1;
135 bool existing =
false;
141 if ( map == otherMap )
144 if ( otherMap->id() == QObject::tr(
"Map %1" ).arg( counter ) )
155 map->
setId( QObject::tr(
"Map %1" ).arg( counter ) );
167 labelItemMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap &properties ) {
171 label->
setText( properties.value( QStringLiteral(
"expression" ) ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : QStringLiteral(
"[% %1 %]" ).arg( properties.value( QStringLiteral(
"expression" ) ).toString() ) );
172 if ( QApplication::isRightToLeft() )
177 QSizeF currentSize = label->rect().size();
180 double labelWidth = std::max( minSize.width(), currentSize.width() );
181 double labelHeight = std::max( minSize.height(), currentSize.height() );
182 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
245 legendItemMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
252 if ( QApplication::isRightToLeft() )
264 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
265 if ( !defaultFontString.isEmpty() )
295 scalebarItemMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
297 Q_ASSERT( scalebar );
314 auto northArrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
323 QList<QgsLayoutItemPicture *> pictureItems;
325 int northArrowCount = 0;
328 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
333 if ( p->picturePath() == defaultPath )
337 auto picture = std::make_unique<QgsLayoutItemPicture>( layout );
339 picture->setPicturePath( defaultPath );
341 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
342 return picture.release();
344 northArrowMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
348 QList<QgsLayoutItemMap *> mapItems;
358 auto createShapeWidget =
364 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
366 return shape.release();
369 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
371 return shape.release();
374 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
376 return shape.release();
383 auto arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
388 createRubberBand, QString(), true
391 auto arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
393 return arrow.release();
395 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
396 auto band = std::make_unique<QGraphicsItemGroup>();
397 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
398 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
400 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
401 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
404 return band.release();
410 auto polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
415 createRubberBand, QStringLiteral(
"nodes" ), true
417 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
418 auto band = std::make_unique<QGraphicsItemGroup>();
419 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
420 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
421 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
423 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
424 tempPoly->setBrush( Qt::NoBrush );
425 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
428 return band.release();
432 auto polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
437 createRubberBand, QStringLiteral(
"nodes" ), true
439 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
440 auto band = std::make_unique<QGraphicsItemGroup>();
441 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
442 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
444 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
445 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
448 return band.release();
457 auto htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
460 auto frame = std::make_unique<QgsLayoutFrame>( layout, html );
472 auto tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
477 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
479 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
488 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
489 if ( !defaultFontString.isEmpty() )
492 QFont f = format.
font();
495 tableMultiFrame->setContentTextFormat( format );
498 tableMultiFrame->setHeaderTextFormat( format );
502 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
514 auto tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
525 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
526 if ( !defaultFontString.isEmpty() )
529 QFont f = format.
font();
532 tableMultiFrame->setContentTextFormat( format );
535 tableMultiFrame->setHeaderTextFormat( format );
540 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
556 auto profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
560 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
561 if ( !defaultFontString.isEmpty() )
563 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
564 QFont f = format.
font();
567 profileItem->plot()->xAxis().setTextFormat( format );
569 format = profileItem->plot()->yAxis().textFormat();
573 profileItem->plot()->yAxis().setTextFormat( format );
575 return profileItem.release();