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 ) );
243 legendItemMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
250 if ( QApplication::isRightToLeft() )
262 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
263 if ( !defaultFontString.isEmpty() )
293 scalebarItemMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
295 Q_ASSERT( scalebar );
312 auto northArrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
321 QList<QgsLayoutItemPicture *> pictureItems;
323 int northArrowCount = 0;
326 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
331 if ( p->picturePath() == defaultPath )
335 auto picture = std::make_unique<QgsLayoutItemPicture>( layout );
337 picture->setPicturePath( defaultPath );
339 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
340 return picture.release();
342 northArrowMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
346 QList<QgsLayoutItemMap *> mapItems;
356 auto createShapeWidget =
362 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
364 return shape.release();
367 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
369 return shape.release();
372 auto shape = std::make_unique<QgsLayoutItemShape>( layout );
374 return shape.release();
381 auto arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
386 createRubberBand, QString(), true
389 auto arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
391 return arrow.release();
393 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
394 auto band = std::make_unique<QGraphicsItemGroup>();
395 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
396 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
398 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
399 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
402 return band.release();
408 auto polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
413 createRubberBand, QStringLiteral(
"nodes" ), true
415 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
416 auto band = std::make_unique<QGraphicsItemGroup>();
417 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
418 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
419 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
421 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
422 tempPoly->setBrush( Qt::NoBrush );
423 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
426 return band.release();
430 auto polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
435 createRubberBand, QStringLiteral(
"nodes" ), true
437 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
438 auto band = std::make_unique<QGraphicsItemGroup>();
439 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
440 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
442 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
443 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
446 return band.release();
455 auto htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
458 auto frame = std::make_unique<QgsLayoutFrame>( layout, html );
470 auto tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
475 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
477 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
486 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
487 if ( !defaultFontString.isEmpty() )
490 QFont f = format.
font();
493 tableMultiFrame->setContentTextFormat( format );
496 tableMultiFrame->setHeaderTextFormat( format );
500 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
512 auto tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
523 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
524 if ( !defaultFontString.isEmpty() )
527 QFont f = format.
font();
530 tableMultiFrame->setContentTextFormat( format );
533 tableMultiFrame->setHeaderTextFormat( format );
538 auto frame = std::make_unique<QgsLayoutFrame>( layout, table );
554 auto profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
558 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
559 if ( !defaultFontString.isEmpty() )
561 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
562 QFont f = format.
font();
565 profileItem->plot()->xAxis().setTextFormat( format );
567 format = profileItem->plot()->yAxis().textFormat();
571 profileItem->plot()->yAxis().setTextFormat( format );
573 return profileItem.release();