63 QList<QgsLayoutItemMap *> mapItems;
69 if ( map->isSelected() )
76 double largestZValue = std::numeric_limits< double >::lowest();
79 if ( map->collidesWithItem( referenceItem ) && map->zValue() > largestZValue )
82 largestZValue = map->zValue();
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();
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static void setFontFamily(QFont &font, const QString &family)
Sets the family for a font object.
static QgsLayoutItemGuiRegistry * layoutItemGuiRegistry()
Returns the global layout item GUI registry, used for registering the GUI behavior of layout items.
Base class for frame items, which form a layout multiframe item.
static void registerGuiForKnownItemTypes(QgsMapCanvas *mapCanvas)
Registers the GUI handlers for known layout item types.
A layout table subclass that displays attributes from a vector layer.
void setVectorLayer(QgsVectorLayer *layer)
Sets the vector layer from which to display feature attributes.
Stores GUI metadata about a group of layout item classes.
Registry of available layout item GUI behavior.
bool addItemGroup(const QgsLayoutItemGuiGroup &group)
Registers a new item group with the registry.
bool addLayoutItemGuiMetadata(QgsLayoutItemAbstractGuiMetadata *metadata)
Registers the gui metadata for a new layout item type.
A layout multiframe subclass for HTML content.
A layout item subclass for text labels.
void setHAlign(Qt::AlignmentFlag alignment)
Sets the horizontal alignment of the label.
QSizeF sizeForText() const
Returns the required item size (in layout units) for the label's text to fill the item.
void setText(const QString &text)
Sets the label's preset text.
A layout item subclass for map legends.
void updateLegend()
Updates the model and all legend entries.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map to associate with the legend.
void setSymbolAlignment(Qt::AlignmentFlag alignment)
Sets the alignment for placement of legend symbols.
QgsLegendStyle & rstyle(QgsLegendStyle::Style s)
Returns reference to modifiable legend style.
void setTitleAlignment(Qt::AlignmentFlag alignment)
Sets the alignment of the legend title.
A layout table subclass that displays manually entered (and formatted) content.
void setTableContents(const QgsTableContents &contents)
Sets the contents of the table.
Layout graphical items for displaying a map.
void zoomToExtent(const QgsRectangle &extent)
Zooms the map so that the specified extent is fully visible within the map item.
void setMapRotation(double rotation)
Sets the rotation for the map - this does not affect the layout item shape, only the way the map is d...
A layout item subclass that displays SVG files or raster format images (jpg, png, ....
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map object for rotation.
@ GridNorth
Align to grid north.
@ ArrowHead
Show arrow marker.
@ LayoutManualTable
Manual (fixed) table.
@ LayoutElevationProfile
Elevation profile item (since QGIS 3.30)
@ LayoutPicture
Picture item.
@ LayoutAttributeTable
Attribute table.
@ LayoutPolyline
Polyline shape item.
@ LayoutScaleBar
Scale bar item.
@ LayoutItem
Base class for items.
@ LayoutLegend
Legend item.
@ LayoutMarker
Marker item.
@ LayoutHtml
Html multiframe item.
@ LayoutPolygon
Polygon shape item.
A layout item subclass for scale bars.
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
Qgis::DistanceUnit guessUnits() const
Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map's sc...
void applyDefaultSize(Qgis::DistanceUnit units=Qgis::DistanceUnit::Meters)
Applies the default size to the scale bar (scale bar 1/5 of map item width)
@ Rectangle
Rectangle shape.
@ Triangle
Triangle shape.
Base class for graphical items within a QgsLayout.
void setBackgroundColor(const QColor &color)
Sets the background color for this item.
virtual void setId(const QString &id)
Set the item's id name.
void attemptSetSceneRect(const QRectF &rect, bool includesFrame=false)
Attempts to update the item's position and size to match the passed rect in layout coordinates.
virtual void addFrame(QgsLayoutFrame *frame, bool recalcFrameSizes=true)
Adds a frame to the multiframe.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QgsLayoutViewEllipseRubberBand is elliptical rubber band for use within QgsLayoutView widgets.
QgsLayoutViewRectangularRubberBand is rectangular rubber band for use within QgsLayoutView widgets.
QgsLayoutViewRubberBand is an abstract base class for temporary rubber band items in various shapes,...
QgsLayoutViewTriangleRubberBand is triangular rubber band for use within QgsLayoutView widgets.
A graphical widget to display and interact with QgsLayouts.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
void addMultiFrame(QgsLayoutMultiFrame *multiFrame)
Adds a multiFrame to the layout.
QgsLayoutItemMap * referenceMap() const
Returns the map item which will be used to generate corresponding world files when the layout is expo...
@ ZViewTool
Z-value for temporary view tool items.
QgsProject * project() const
The project associated with the layout.
void setAlignment(Qt::Alignment alignment)
Sets the alignment for the legend component.
QgsTextFormat & textFormat()
Returns the text format used for rendering this legend component.
@ Group
Legend group title.
@ Subgroup
Legend subgroup title.
@ SymbolLabel
Symbol label (excluding icon)
void setTextFormat(const QgsTextFormat &format)
Sets the text format used for rendering this legend component.
Map canvas is a class for displaying all GIS data types on a canvas.
double rotation() const
Gets the current map canvas rotation in clockwise degrees.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
static QgsProject * instance()
Returns the QgsProject singleton instance.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Encapsulates the contents and formatting of a single table cell.
Container for all settings relating to text rendering.
void setFont(const QFont &font)
Sets the font used for rendering text.
QFont font() const
Returns the font used for rendering text.
Represents a vector layer which manages a vector based data sets.
QgsLayoutItemMap * findSensibleDefaultLinkedMapItem(QgsLayoutItem *referenceItem)
Attempts to find the best guess at a map item to link referenceItem to, by:
QVector< QgsTableRow > QgsTableContents
A set of table rows.
QVector< QgsTableCell > QgsTableRow
A row of table cells.