60 QList<QgsLayoutItemMap *> mapItems;
66 if ( map->isSelected() )
73 double largestZValue = std::numeric_limits< double >::lowest();
76 if ( map->collidesWithItem( referenceItem ) && map->zValue() > largestZValue )
79 largestZValue = map->zValue();
118 return new QgsLayoutMapWidget( qobject_cast< QgsLayoutItemMap * >( item ), mapCanvas );
119 }, createRubberBand );
120 mapItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
135 QList<QgsLayoutItemMap *> mapsList;
139 int counter = mapsList.size() + 1;
140 bool existing =
false;
146 if ( map == otherMap )
149 if ( otherMap->id() == QObject::tr(
"Map %1" ).arg( counter ) )
160 map->
setId( QObject::tr(
"Map %1" ).arg( counter ) );
170 }, createRubberBand ) );
179 }, createRubberBand );
180 labelItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & properties )
185 label->
setText( properties.value( QStringLiteral(
"expression" ) ).toString().isEmpty() ? QObject::tr(
"Lorem ipsum" ) : QStringLiteral(
"[% %1 %]" ).arg( properties.value( QStringLiteral(
"expression" ) ).toString() ) );
186 if ( QApplication::isRightToLeft() )
191 QSizeF currentSize = label->rect().size();
194 double labelWidth = std::max( minSize.width(), currentSize.width() );
195 double labelHeight = std::max( minSize.height(), currentSize.height() );
196 label->
attemptSetSceneRect( QRectF( label->pos().x(), label->pos().y(), labelWidth, labelHeight ) );
207 return new QgsLayoutLegendWidget( qobject_cast< QgsLayoutItemLegend * >( item ), mapCanvas );
208 }, createRubberBand );
209 legendItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
217 if ( QApplication::isRightToLeft() )
229 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
230 if ( !defaultFontString.isEmpty() )
249 }, createRubberBand );
250 scalebarItemMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
253 Q_ASSERT( scalebar );
267 std::unique_ptr< QgsLayoutItemGuiMetadata > northArrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
272 }, createRubberBand );
273 northArrowMetadata->setItemCreationFunction( [](
QgsLayout * layout )->QgsLayoutItem *
277 QList< QgsLayoutItemPicture * > pictureItems;
279 int northArrowCount = 0;
282 const QString defaultPath = settings.
value( QStringLiteral(
"LayoutDesigner/defaultNorthArrow" ), QStringLiteral(
":/images/north_arrows/layout_default_north_arrow.svg" ),
QgsSettings::Gui ).toString();
287 if ( p->picturePath() == defaultPath )
291 std::unique_ptr< QgsLayoutItemPicture > picture = std::make_unique< QgsLayoutItemPicture >( layout );
293 picture->setPicturePath( defaultPath );
295 picture->setId( northArrowCount > 0 ? QObject::tr(
"North Arrow %1" ).arg( northArrowCount + 1 ) : QObject::tr(
"North Arrow" ) );
296 return picture.release();
298 northArrowMetadata->setItemAddedToLayoutFunction( [ = ](
QgsLayoutItem * item,
const QVariantMap & )
303 QList<QgsLayoutItemMap *> mapItems;
313 auto createShapeWidget =
321 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
323 return shape.release();
327 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
329 return shape.release();
333 std::unique_ptr< QgsLayoutItemShape > shape = std::make_unique< QgsLayoutItemShape >( layout );
335 return shape.release();
346 std::unique_ptr< QgsLayoutItemGuiMetadata > arrowMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
351 }, createRubberBand, QString(), true );
352 arrowMetadata->setItemCreationFunction( [](
QgsLayout * layout )->QgsLayoutItem *
354 std::unique_ptr< QgsLayoutItemPolyline > arrow = std::make_unique< QgsLayoutItemPolyline >( layout );
356 return arrow.release();
358 arrowMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPathItem*
360 std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
361 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
363 return band.release();
369 std::unique_ptr< QgsLayoutItemGuiMetadata > polygonMetadata = std::make_unique< QgsLayoutItemGuiMetadata >(
374 }, createRubberBand, QStringLiteral(
"nodes" ), true );
375 polygonMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPolygonItem*
377 std::unique_ptr< QGraphicsPolygonItem > band = std::make_unique< QGraphicsPolygonItem >();
378 band->setBrush( Qt::NoBrush );
379 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
381 return band.release();
385 std::unique_ptr< QgsLayoutItemGuiMetadata > polylineMetadata = std::make_unique< QgsLayoutItemGuiMetadata>(
390 }, createRubberBand, QStringLiteral(
"nodes" ), true );
391 polylineMetadata->setNodeRubberBandCreationFunction( [](
QgsLayoutView * )->QGraphicsPathItem*
393 std::unique_ptr< QGraphicsPathItem > band = std::make_unique< QGraphicsPathItem >();
394 band->setPen( QPen( QBrush( QColor( 227, 22, 22, 200 ) ), 0 ) );
396 return band.release();
407 }, createRubberBand );
408 htmlItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
410 std::unique_ptr< QgsLayoutItemHtml > htmlMultiFrame = std::make_unique< QgsLayoutItemHtml >( layout );
413 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, html );
426 }, createRubberBand );
427 attributeTableItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
429 std::unique_ptr< QgsLayoutItemAttributeTable > tableMultiFrame = std::make_unique< QgsLayoutItemAttributeTable >( layout );
434 for (
auto it = layerMap.constBegin() ; it != layerMap.constEnd(); ++it )
436 if (
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( it.value() ) )
445 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
446 if ( !defaultFontString.isEmpty() )
449 QFont f = format.
font();
450 f.setFamily( defaultFontString );
452 tableMultiFrame->setContentTextFormat( format );
455 tableMultiFrame->setHeaderTextFormat( format );
459 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );
472 }, createRubberBand );
473 manualTableItemMetadata->setItemCreationFunction( [ = ](
QgsLayout * layout )->QgsLayoutItem *
475 std::unique_ptr< QgsLayoutItemManualTable > tableMultiFrame = std::make_unique< QgsLayoutItemManualTable >( layout );
486 const QString defaultFontString = settings.
value( QStringLiteral(
"LayoutDesigner/defaultFont" ), QVariant(),
QgsSettings::Gui ).toString();
487 if ( !defaultFontString.isEmpty() )
490 QFont f = format.
font();
491 f.setFamily( defaultFontString );
493 tableMultiFrame->setContentTextFormat( format );
496 tableMultiFrame->setHeaderTextFormat( format );
501 std::unique_ptr< QgsLayoutFrame > frame = std::make_unique< QgsLayoutFrame >( layout, table );
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.
@ 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.
QgsUnitTypes::DistanceUnit guessUnits() const
Attempts to guess the most reasonable unit choice for the scalebar, given the current linked map's sc...
void applyDefaultSize(QgsUnitTypes::DistanceUnit units=QgsUnitTypes::DistanceMeters)
Applies the default size to the scale bar (scale bar 1/5 of map item width)
void setLinkedMap(QgsLayoutItemMap *map)
Sets the map item linked to the scalebar.
@ 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.
@ Group
Legend group title.
@ Subgroup
Legend subgroup title.
@ SymbolLabel
Symbol label (excluding icon)
QFont & rfont()
Returns a modifiable reference to the component's font.
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.