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 );
309 std::unique_ptr<QgsLayoutItemGuiMetadata> northArrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
318 QList<QgsLayoutItemPicture *> pictureItems;
320 int northArrowCount = 0;
323 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
328 if ( p->picturePath() == defaultPath )
332 std::unique_ptr<QgsLayoutItemPicture> picture = std::make_unique<QgsLayoutItemPicture>( layout );
334 picture->setPicturePath( defaultPath );
336 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
337 return picture.release();
339 northArrowMetadata->setItemAddedToLayoutFunction( [=](
QgsLayoutItem *item,
const QVariantMap & ) {
343 QList<QgsLayoutItemMap *> mapItems;
353 auto createShapeWidget =
359 std::unique_ptr<QgsLayoutItemShape> shape = std::make_unique<QgsLayoutItemShape>( layout );
361 return shape.release();
364 std::unique_ptr<QgsLayoutItemShape> shape = std::make_unique<QgsLayoutItemShape>( layout );
366 return shape.release();
369 std::unique_ptr<QgsLayoutItemShape> shape = std::make_unique<QgsLayoutItemShape>( layout );
371 return shape.release();
378 std::unique_ptr<QgsLayoutItemGuiMetadata> arrowMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
383 createRubberBand, QString(), true
386 std::unique_ptr<QgsLayoutItemPolyline> arrow = std::make_unique<QgsLayoutItemPolyline>( layout );
388 return arrow.release();
390 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
391 std::unique_ptr<QGraphicsItemGroup> band = std::make_unique<QGraphicsItemGroup>();
392 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
393 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
395 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
396 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
399 return band.release();
405 std::unique_ptr<QgsLayoutItemGuiMetadata> polygonMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
410 createRubberBand, QStringLiteral(
"nodes" ), true
412 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
413 std::unique_ptr<QGraphicsItemGroup> band = std::make_unique<QGraphicsItemGroup>();
414 QGraphicsPolygonItem *poly =
new QGraphicsPolygonItem( band.get() );
415 poly->setBrush( QBrush( QColor( 227, 22, 22, 20 ) ) );
416 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
418 QGraphicsPolygonItem *tempPoly =
new QGraphicsPolygonItem( band.get() );
419 tempPoly->setBrush( Qt::NoBrush );
420 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
423 return band.release();
427 std::unique_ptr<QgsLayoutItemGuiMetadata> polylineMetadata = std::make_unique<QgsLayoutItemGuiMetadata>(
432 createRubberBand, QStringLiteral(
"nodes" ), true
434 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * ) -> QGraphicsItemGroup * {
435 std::unique_ptr<QGraphicsItemGroup> band = std::make_unique<QGraphicsItemGroup>();
436 QGraphicsPathItem *poly =
new QGraphicsPathItem( band.get() );
437 poly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
439 QGraphicsPathItem *tempPoly =
new QGraphicsPathItem( band.get() );
440 tempPoly->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0, Qt::DotLine ) );
443 return band.release();
452 std::unique_ptr<QgsLayoutItemHtml> htmlMultiFrame = std::make_unique<QgsLayoutItemHtml>( layout );
455 std::unique_ptr<QgsLayoutFrame> frame = std::make_unique<QgsLayoutFrame>( layout, html );
467 std::unique_ptr<QgsLayoutItemAttributeTable> tableMultiFrame = std::make_unique<QgsLayoutItemAttributeTable>( layout );
472 for (
auto it = layerMap.constBegin(); it != layerMap.constEnd(); ++it )
474 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
483 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
484 if ( !defaultFontString.isEmpty() )
487 QFont f = format.
font();
490 tableMultiFrame->setContentTextFormat( format );
493 tableMultiFrame->setHeaderTextFormat( format );
497 std::unique_ptr<QgsLayoutFrame> frame = std::make_unique<QgsLayoutFrame>( layout, table );
509 std::unique_ptr<QgsLayoutItemManualTable> tableMultiFrame = std::make_unique<QgsLayoutItemManualTable>( layout );
520 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
521 if ( !defaultFontString.isEmpty() )
524 QFont f = format.
font();
527 tableMultiFrame->setContentTextFormat( format );
530 tableMultiFrame->setHeaderTextFormat( format );
535 std::unique_ptr<QgsLayoutFrame> frame = std::make_unique<QgsLayoutFrame>( layout, table );
551 std::unique_ptr<QgsLayoutItemElevationProfile> profileItem = std::make_unique<QgsLayoutItemElevationProfile>( layout );
555 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
556 if ( !defaultFontString.isEmpty() )
558 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
559 QFont f = format.
font();
562 profileItem->plot()->xAxis().setTextFormat( format );
564 format = profileItem->plot()->yAxis().textFormat();
568 profileItem->plot()->yAxis().setTextFormat( format );
570 return profileItem.release();