62 QList<QgsLayoutItemMap *> mapItems;
68 if ( map->isSelected() )
75 double largestZValue = std::numeric_limits< double >::lowest();
78 if ( map->collidesWithItem( referenceItem ) && map->zValue() > largestZValue )
81 largestZValue = map->zValue();
120 return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ), mapCanvas );
121 }, createRubberBand );
122 mapItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
137 QList<QgsLayoutItemMap *> mapsList;
141 int counter = mapsList.size() + 1;
142 bool existing =
false;
148 if ( map == otherMap )
151 if ( otherMap->id() == QObject::tr(
"Map %1" ).arg( counter ) )
162 map->
setId( QObject::tr(
"Map %1" ).arg( counter ) );
172 }, createRubberBand ) );
181 }, createRubberBand );
182 labelItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & properties )
187 label->
setText( properties.value( QStringLiteral(
"expression" ) ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : QStringLiteral(
"[% %1 %]" ).arg( properties.value( QStringLiteral(
"expression" ) ).toString() ) );
188 if ( QApplication::isRightToLeft() )
193 QSizeF currentSize = label->rect().size();
196 double labelWidth = std::max( minSize.width(), currentSize.width() );
197 double labelHeight = std::max( minSize.height(), currentSize.height() );
198 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
209 return new QgsLayoutLegendWidget( qobject_cast< QgsLayoutItemLegend * >( item ), mapCanvas );
210 }, createRubberBand );
211 legendItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
219 if ( QApplication::isRightToLeft() )
231 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
232 if ( !defaultFontString.isEmpty() )
235 font.setFamily( defaultFontString );
265 }, createRubberBand );
266 scalebarItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
269 Q_ASSERT( scalebar );
283 std::unique_ptr< QgsLayoutItemGuiMetadata > northArrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
288 }, createRubberBand );
289 northArrowMetadata->setItemCreationFunction( [](
QgsLayout * layout )->QgsLayoutItem *
293 QList< QgsLayoutItemPicture * > pictureItems;
295 int northArrowCount = 0;
298 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
303 if ( p->picturePath() == defaultPath )
307 std::unique_ptr< QgsLayoutItemPicture > picture = std::make_unique< QgsLayoutItemPicture >( layout );
309 picture->setPicturePath( defaultPath );
311 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
312 return picture.release();
314 northArrowMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
319 QList<QgsLayoutItemMap *> mapItems;
329 auto createShapeWidget =
337 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
339 return shape.release();
343 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
345 return shape.release();
349 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
351 return shape.release();
362 std::unique_ptr< QgsLayoutItemGuiMetadata > arrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
367 }, createRubberBand, QString(), true );
368 arrowMetadata->setItemCreationFunction( [](
QgsLayout * layout )->QgsLayoutItem *
370 std::unique_ptr< QgsLayoutItemPolyline > arrow = std::make_unique< QgsLayoutItemPolyline >( layout );
372 return arrow.release();
374 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPathItem*
376 std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
377 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
379 return band.release();
385 std::unique_ptr< QgsLayoutItemGuiMetadata > polygonMetadata = std::make_unique< QgsLayoutItemGuiMetadata >(
390 }, createRubberBand, QStringLiteral(
"nodes" ), true );
391 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPolygonItem*
393 std::unique_ptr< QGraphicsPolygonItem > band = std::make_unique< QGraphicsPolygonItem >();
394 band->setBrush( Qt::NoBrush );
395 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
397 return band.release();
401 std::unique_ptr< QgsLayoutItemGuiMetadata > polylineMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
406 }, createRubberBand, QStringLiteral(
"nodes" ), true );
407 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPathItem*
409 std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
410 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
412 return band.release();
423 }, createRubberBand );
424 htmlItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
426 std::unique_ptr< QgsLayoutItemHtml > htmlMultiFrame = std::make_unique< QgsLayoutItemHtml >( layout );
429 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, html );
443 }, createRubberBand );
444 attributeTableItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
446 std::unique_ptr< QgsLayoutItemAttributeTable > tableMultiFrame = std::make_unique< QgsLayoutItemAttributeTable >( layout );
451 for (
auto it = layerMap.constBegin() ; it != layerMap.constEnd(); ++it )
453 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
462 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
463 if ( !defaultFontString.isEmpty() )
466 QFont f = format.
font();
467 f.setFamily( defaultFontString );
469 tableMultiFrame->setContentTextFormat( format );
472 tableMultiFrame->setHeaderTextFormat( format );
476 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );
490 }, createRubberBand );
491 manualTableItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
493 std::unique_ptr< QgsLayoutItemManualTable > tableMultiFrame = std::make_unique< QgsLayoutItemManualTable >( layout );
504 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
505 if ( !defaultFontString.isEmpty() )
508 QFont f = format.
font();
509 f.setFamily( defaultFontString );
511 tableMultiFrame->setContentTextFormat( format );
514 tableMultiFrame->setHeaderTextFormat( format );
519 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );
534 }, createRubberBand );
535 elevationProfileItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
537 std::unique_ptr< QgsLayoutItemElevationProfile > profileItem = std::make_unique< QgsLayoutItemElevationProfile >( layout );
541 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
542 if ( !defaultFontString.isEmpty() )
544 QgsTextFormat format = profileItem->plot()->xAxis().textFormat();
545 QFont f = format.
font();
546 f.setFamily( defaultFontString );
548 profileItem->plot()->xAxis().setTextFormat( format );
550 format = profileItem->plot()->yAxis().textFormat();
552 f.setFamily( defaultFontString );
554 profileItem->plot()->yAxis().setTextFormat( format );
556 return profileItem.release();
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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.